forked from vollero/openCAPWAP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WTPBcmDriverInteraction.c
349 lines (270 loc) · 9.65 KB
/
WTPBcmDriverInteraction.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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/*******************************************************************************************
* Copyright (c) 2006-7 Laboratorio di Sistemi di Elaborazione e Bioingegneria Informatica *
* Universita' Campus BioMedico - Italy *
* *
* 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. *
* *
* In addition, as a special exception, the copyright holders give permission to link the *
* code of portions of this program with the OpenSSL library under certain conditions as *
* described in each individual source file, and distribute linked combinations including *
* the two. You must obey the GNU General Public License in all respects for all of the *
* code used other than OpenSSL. If you modify file(s) with this exception, you may *
* extend this exception to your version of the file(s), but you are not obligated to do *
* so. If you do not wish to do so, delete this exception statement from your version. *
* If you delete this exception statement from all source files in the program, then also *
* delete it here. *
*
* --------------------------------------------------------------------------------------- *
* Project: Capwap *
* *
* Author : Ludovico Rossi (ludo@bluepixysw.com) *
* Del Moro Andrea (andrea_delmoro@libero.it) *
* Giovannini Federica (giovannini.federica@gmail.com) *
* Massimo Vellucci (m.vellucci@unicampus.it) *
* Mauro Bisson (mauro.bis@gmail.com) *
*******************************************************************************************/
#include "CWWTP.h"
#include "WTPBcmDriverInteraction.h"
static char interface[16] = "wl0";
static char wlbuf[WLC_IOCTL_MAXLEN];
#define BUFSIZE 8192
/*prototipi da includere in CWWTP.h*/
int set_rts_threshold(int value);
int get_rts_threshold(int* value);
int set_frag_threshold(int value);
int get_frag_threshold(int *value);
int set_maxassoc(int value);
int get_maxassoc(int *value);
/*--------------------------- RTS/CTS Threshold ---------------------------*/
int set_rts_threshold(int value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"rtsthresh");
if(wl_iovar_setint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nRTS/CTS threshold impostato a: %d\n",value);
return 1;
}
int get_rts_threshold(int *value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"rtsthresh");
if(wl_iovar_getint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nRTS/CTS threshold: %d\n", *value);
return 1;
}
/*--------------------------- Fragmentation Threshold ---------------------------*/
int set_frag_threshold(int value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"fragthresh");
if(wl_iovar_setint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nFragmentation threshold impostato a: %d\n",value);
return 1;
}
int get_frag_threshold(int *value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"fragthresh");
if(wl_iovar_getint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nFragmentation threshold: %d\n", *value);
return 1;
}
/*--------------------------- Max. number of associated clients ---------------------------*/
int set_maxassoc(int value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"maxassoc");
if(wl_iovar_setint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nMax. number of associated clients impostato a: %d\n",value);
return 1;
}
int get_maxassoc(int *value)
{
char *iov_type;
iov_type=malloc(20*sizeof(char));
strcpy(iov_type,"maxassoc");
if(wl_iovar_getint(interface, iov_type, value) < 0){
perror("Ioctl error");
return(0);
}
printf("\nMax. number of associated clients: %d\n", *value);
return 1;
}
/*---------- WME Extensions: cwmin,cwmax,aifsn for BE,BK,VI,VO queues ---------------------*/
/*the Broadcom's driver doesn't support GET command for wme.*/
/*set CWMIN*/
int set_wme_cwmin(int class,int value)
{
edcf_acparam_t params[AC_COUNT];
char *buf = wlbuf;
char *type;
type=malloc(20*sizeof(char));
strcpy(type,"wme_ac_ap");
memset(params, 0, sizeof(params));
wl_iovar_get(interface, type, params, sizeof(params));
strcpy(buf, type);
buf += strlen(buf) + 1;
params[class].ECW = (params[class].ECW & ~(0xf)) | (value & 0xf);
memcpy(buf, ¶ms[class], sizeof(edcf_acparam_t));
if( wl_ioctl(interface, WLC_SET_VAR, wlbuf, BUFSIZE) < 0)
{
perror("Ioctl error");
return(0);
}
printf("\nCWMIN impostato a: %d\n", value);
return 1;
}
/*set CWMAX*/
int set_wme_cwmax(int class,int value)
{
edcf_acparam_t params[AC_COUNT];
char *buf = wlbuf;
char *type;
type=malloc(20*sizeof(char));
strcpy(type,"wme_ac_ap");
memset(params, 0, sizeof(params));
wl_iovar_get(interface, type, params, sizeof(params));
strcpy(buf, type);
buf += strlen(buf) + 1;
params[class].ECW = (params[class].ECW & ~(0xf << 4)) | ((value & 0xf) << 4);
memcpy(buf, ¶ms[class], sizeof(edcf_acparam_t));
if( wl_ioctl(interface, WLC_SET_VAR, wlbuf, BUFSIZE) < 0)
{
perror("Ioctl error");
return(0);
}
printf("\nCWMAX impostato a: %d\n", value);
return 1;
}
/*set AIFSN*/
int set_wme_aifsn(int class,int value)
{
edcf_acparam_t params[AC_COUNT];
char *buf = wlbuf;
char *type;
type=malloc(20*sizeof(char));
strcpy(type,"wme_ac_ap");
memset(params, 0, sizeof(params));
wl_iovar_get(interface, type, params, sizeof(params));
strcpy(buf, type);
buf += strlen(buf) + 1;
params[class].ACI = (params[class].ACI & ~(0xf)) | (value & 0xf);
memcpy(buf, ¶ms[class], sizeof(edcf_acparam_t));
if( wl_ioctl(interface, WLC_SET_VAR, wlbuf, BUFSIZE) < 0)
{
perror("Ioctl error");
return(0);
}
printf("\nAIFSN impostato a: %d\n", value);
return 1;
}
/*@@@@@@@@ ioctl driver interaction's functions @@@@@@@@@@@@@*/
int
wl_ioctl(char *name, int cmd, void *buf, int len)
{
struct ifreq ifr;
wl_ioctl_t ioc;
int ret = 0;
int s;
/* open socket to kernel */
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return errno;
}
/* do it */
ioc.cmd = cmd;
ioc.buf = buf;
ioc.len = len;
strncpy(ifr.ifr_name, name, IFNAMSIZ);
ifr.ifr_data = (caddr_t) &ioc;
if ((ret = ioctl(s, SIOCDEVPRIVATE, &ifr)) < 0) {
perror("ioctl error");
close(s);
return -1;
}
/* cleanup */
close(s);
return ret;
}
static int
wl_iovar_getbuf(char *ifname, char *iovar, void *param, int paramlen, void *bufptr, int buflen)
{
int err;
uint namelen;
uint iolen;
namelen = strlen(iovar) + 1; /* length of iovar name plus null */
iolen = namelen + paramlen;
/* check for overflow */
if (iolen > buflen)
return (BCME_BUFTOOSHORT);
memcpy(bufptr, iovar, namelen); /* copy iovar name including null */
memcpy((int8*)bufptr + namelen, param, paramlen);
err = wl_ioctl(ifname, WLC_GET_VAR, bufptr, buflen);
return (err);
}
static int
wl_iovar_setbuf(char *ifname, char *iovar, void *param, int paramlen, void *bufptr, int buflen)
{
uint namelen;
uint iolen;
namelen = strlen(iovar) + 1; /* length of iovar name plus null */
iolen = namelen + paramlen;
/* check for overflow */
if (iolen > buflen)
return (BCME_BUFTOOSHORT);
memcpy(bufptr, iovar, namelen); /* copy iovar name including null */
memcpy((int8*)bufptr + namelen, param, paramlen);
return wl_ioctl(ifname, WLC_SET_VAR, bufptr, iolen);
}
int
wl_iovar_set(char *ifname, char *iovar, void *param, int paramlen)
{
char smbuf[WLC_IOCTL_SMLEN];
return wl_iovar_setbuf(ifname, iovar, param, paramlen, smbuf, sizeof(smbuf));
}
int
wl_iovar_get(char *ifname, char *iovar, void *bufptr, int buflen)
{
char smbuf[WLC_IOCTL_SMLEN];
int ret;
/* use the return buffer if it is bigger than what we have on the stack */
if (buflen > sizeof(smbuf)) {
ret = wl_iovar_getbuf(ifname, iovar, NULL, 0, bufptr, buflen);
} else {
ret = wl_iovar_getbuf(ifname, iovar, NULL, 0, smbuf, sizeof(smbuf));
if (ret == 0)
memcpy(bufptr, smbuf, buflen);
}
return ret;
}