forked from evilpan/Airkiss
-
Notifications
You must be signed in to change notification settings - Fork 1
/
osdep.c
244 lines (203 loc) · 4.66 KB
/
osdep.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
/*
* Copyright (c) 2007, 2008, Andrea Bittau <[email protected]>
*
* OS dependent API.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "osdep.h"
int wi_read(struct wif *wi, unsigned char *h80211, int len, struct rx_info *ri)
{
assert(wi->wi_read);
return wi->wi_read(wi, h80211, len, ri);
}
int wi_write(struct wif *wi, unsigned char *h80211, int len,
struct tx_info *ti)
{
assert(wi->wi_write);
return wi->wi_write(wi, h80211, len, ti);
}
int wi_set_channel(struct wif *wi, int chan)
{
assert(wi->wi_set_channel);
return wi->wi_set_channel(wi, chan);
}
int wi_get_channel(struct wif *wi)
{
assert(wi->wi_get_channel);
return wi->wi_get_channel(wi);
}
int wi_set_freq(struct wif *wi, int freq)
{
assert(wi->wi_set_freq);
return wi->wi_set_freq(wi, freq);
}
int wi_get_freq(struct wif *wi)
{
assert(wi->wi_get_freq);
return wi->wi_get_freq(wi);
}
int wi_get_monitor(struct wif *wi)
{
assert(wi->wi_get_monitor);
return wi->wi_get_monitor(wi);
}
char *wi_get_ifname(struct wif *wi)
{
return wi->wi_interface;
}
void wi_close(struct wif *wi)
{
assert(wi->wi_close);
wi->wi_close(wi);
}
int wi_fd(struct wif *wi)
{
assert(wi->wi_fd);
return wi->wi_fd(wi);
}
struct wif *wi_alloc(int sz)
{
struct wif *wi;
void *priv;
/* Allocate wif & private state */
wi = malloc(sizeof(*wi));
if (!wi)
return NULL;
memset(wi, 0, sizeof(*wi));
priv = malloc(sz);
if (!priv) {
free(wi);
return NULL;
}
memset(priv, 0, sz);
wi->wi_priv = priv;
return wi;
}
void *wi_priv(struct wif *wi)
{
return wi->wi_priv;
}
int wi_get_mac(struct wif *wi, unsigned char *mac)
{
assert(wi->wi_get_mac);
return wi->wi_get_mac(wi, mac);
}
int wi_set_mac(struct wif *wi, unsigned char *mac)
{
assert(wi->wi_set_mac);
return wi->wi_set_mac(wi, mac);
}
int wi_get_rate(struct wif *wi)
{
assert(wi->wi_get_rate);
return wi->wi_get_rate(wi);
}
int wi_set_rate(struct wif *wi, int rate)
{
assert(wi->wi_set_rate);
return wi->wi_set_rate(wi, rate);
}
int wi_get_mtu(struct wif *wi)
{
assert(wi->wi_get_mtu);
return wi->wi_get_mtu(wi);
}
int wi_set_mtu(struct wif *wi, int mtu)
{
assert(wi->wi_set_mtu);
return wi->wi_set_mtu(wi, mtu);
}
struct wif *wi_open(char *iface)
{
struct wif *wi;
wi = wi_open_osdep(iface);
if (!wi)
return NULL;
strncpy(wi->wi_interface, iface, sizeof(wi->wi_interface)-1);
wi->wi_interface[sizeof(wi->wi_interface)-1] = 0;
return wi;
}
/* tap stuff */
char *ti_name(struct tif *ti)
{
assert(ti->ti_name);
return ti->ti_name(ti);
}
int ti_set_mtu(struct tif *ti, int mtu)
{
assert(ti->ti_set_mtu);
return ti->ti_set_mtu(ti, mtu);
}
int ti_get_mtu(struct tif *ti)
{
assert(ti->ti_get_mtu);
return ti->ti_get_mtu(ti);
}
void ti_close(struct tif *ti)
{
assert(ti->ti_close);
ti->ti_close(ti);
}
int ti_fd(struct tif *ti)
{
assert(ti->ti_fd);
return ti->ti_fd(ti);
}
int ti_read(struct tif *ti, void *buf, int len)
{
assert(ti->ti_read);
return ti->ti_read(ti, buf, len);
}
int ti_write(struct tif *ti, void *buf, int len)
{
assert(ti->ti_write);
return ti->ti_write(ti, buf, len);
}
int ti_set_mac(struct tif *ti, unsigned char *mac)
{
assert(ti->ti_set_mac);
return ti->ti_set_mac(ti, mac);
}
int ti_set_ip(struct tif *ti, struct in_addr *ip)
{
assert(ti->ti_set_ip);
return ti->ti_set_ip(ti, ip);
}
struct tif *ti_alloc(int sz)
{
struct tif *ti;
void *priv;
/* Allocate tif & private state */
ti = malloc(sizeof(*ti));
if (!ti)
return NULL;
memset(ti, 0, sizeof(*ti));
priv = malloc(sz);
if (!priv) {
free(ti);
return NULL;
}
memset(priv, 0, sz);
ti->ti_priv = priv;
return ti;
}
void *ti_priv(struct tif *ti)
{
return ti->ti_priv;
}