2 * Wireless network adapter utilities
4 * Copyright 2004, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
18 #include <sys/ioctl.h>
25 wl_ioctl(char *name
, int cmd
, void *buf
, int len
)
32 /* open socket to kernel */
33 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
42 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
43 ifr
.ifr_data
= (caddr_t
) &ioc
;
44 if ((ret
= ioctl(s
, SIOCDEVPRIVATE
, &ifr
)) < 0)
45 if (cmd
!= WLC_GET_MAGIC
)
54 wl_hwaddr(char *name
, unsigned char *hwaddr
)
60 /* open socket to kernel */
61 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
67 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
68 if ((ret
= ioctl(s
, SIOCGIFHWADDR
, &ifr
)) == 0)
69 memcpy(hwaddr
, ifr
.ifr_hwaddr
.sa_data
, ETHER_ADDR_LEN
);
82 if ((ret
= wl_ioctl(name
, WLC_GET_MAGIC
, &val
, sizeof(val
))))
84 if (val
!= WLC_IOCTL_MAGIC
)
86 if ((ret
= wl_ioctl(name
, WLC_GET_VERSION
, &val
, sizeof(val
))))
88 if (val
> WLC_IOCTL_VERSION
)
95 wl_set_val(char *name
, char *var
, void *val
, int len
)
100 /* check for overflow */
101 if ((buf_len
= strlen(var
)) + 1 + len
> sizeof(buf
))
107 /* append int value onto the end of the name string */
108 memcpy(&buf
[buf_len
], val
, len
);
111 return wl_ioctl(name
, WLC_SET_VAR
, buf
, buf_len
);
115 wl_get_val(char *name
, char *var
, void *val
, int len
)
120 /* check for overflow */
121 if (strlen(var
) + 1 > sizeof(buf
) || len
> sizeof(buf
))
125 if ((ret
= wl_ioctl(name
, WLC_GET_VAR
, buf
, sizeof(buf
))))
128 memcpy(val
, buf
, len
);
133 wl_set_int(char *name
, char *var
, int val
)
135 return wl_set_val(name
, var
, &val
, sizeof(val
));
139 wl_get_int(char *name
, char *var
, int *val
)
141 return wl_get_val(name
, var
, val
, sizeof(*val
));
144 /**************************************************************************
145 * The following code is from Broadcom (wl.c) *
146 **************************************************************************/
149 wl_iovar_getbuf(char *ifname
, char *iovar
, void *param
,
150 int paramlen
, void *bufptr
, int buflen
)
156 namelen
= strlen(iovar
) + 1; /* length of iovar name plus null */
157 iolen
= namelen
+ paramlen
;
159 /* check for overflow */
163 memcpy(bufptr
, iovar
, namelen
); /* copy iovar name including null */
164 memcpy((int8
*)bufptr
+ namelen
, param
, paramlen
);
166 err
= wl_ioctl(ifname
, WLC_GET_VAR
, bufptr
, buflen
);
172 wl_iovar_setbuf(char *ifname
, char *iovar
, void *param
,
173 int paramlen
, void *bufptr
, int buflen
)
178 namelen
= strlen(iovar
) + 1; /* length of iovar name plus null */
179 iolen
= namelen
+ paramlen
;
181 /* check for overflow */
185 memcpy(bufptr
, iovar
, namelen
); /* copy iovar name including null */
186 memcpy((int8
*)bufptr
+ namelen
, param
, paramlen
);
188 return wl_ioctl(ifname
, WLC_SET_VAR
, bufptr
, iolen
);
192 wl_iovar_set(char *ifname
, char *iovar
, void *param
, int paramlen
)
194 char smbuf
[WLC_IOCTL_SMLEN
];
196 return wl_iovar_setbuf(ifname
, iovar
, param
, paramlen
, smbuf
, sizeof(smbuf
));
200 wl_iovar_get(char *ifname
, char *iovar
, void *bufptr
, int buflen
)
202 char smbuf
[WLC_IOCTL_SMLEN
];
205 /* use the return buffer if it is bigger than what we have on the stack */
206 if (buflen
> sizeof(smbuf
)) {
207 ret
= wl_iovar_getbuf(ifname
, iovar
, NULL
, 0, bufptr
, buflen
);
209 ret
= wl_iovar_getbuf(ifname
, iovar
, NULL
, 0, smbuf
, sizeof(smbuf
));
211 memcpy(bufptr
, smbuf
, buflen
);
218 * set named driver variable to int value
219 * calling example: wl_iovar_setint(ifname, "arate", rate)
222 wl_iovar_setint(char *ifname
, char *iovar
, int val
)
224 return wl_iovar_set(ifname
, iovar
, &val
, sizeof(val
));
228 * get named driver variable to int value and return error indication
229 * calling example: wl_iovar_getint(ifname, "arate", &rate)
232 wl_iovar_getint(char *ifname
, char *iovar
, int *val
)
234 return wl_iovar_get(ifname
, iovar
, val
, sizeof(int));
238 * format a bsscfg indexed iovar buffer
241 wl_bssiovar_mkbuf(char *iovar
, int bssidx
, void *param
,
242 int paramlen
, void *bufptr
, int buflen
, int *plen
)
244 char *prefix
= "bsscfg:";
250 prefixlen
= strlen(prefix
); /* length of bsscfg prefix */
251 namelen
= strlen(iovar
) + 1; /* length of iovar name + null */
252 iolen
= prefixlen
+ namelen
+ sizeof(int) + paramlen
;
254 /* check for overflow */
255 if (buflen
< 0 || iolen
> (uint
)buflen
) {
262 /* copy prefix, no null */
263 memcpy(p
, prefix
, prefixlen
);
266 /* copy iovar name including null */
267 memcpy(p
, iovar
, namelen
);
270 /* bss config index as first param */
271 memcpy(p
, &bssidx
, sizeof(int32
));
274 /* parameter buffer follows */
276 memcpy(p
, param
, paramlen
);
283 * set named & bss indexed driver variable to buffer value
286 wl_bssiovar_setbuf(char *ifname
, char *iovar
, int bssidx
, void *param
,
287 int paramlen
, void *bufptr
, int buflen
)
292 err
= wl_bssiovar_mkbuf(iovar
, bssidx
, param
, paramlen
, bufptr
, buflen
, &iolen
);
296 return wl_ioctl(ifname
, WLC_SET_VAR
, bufptr
, iolen
);
300 * get named & bss indexed driver variable buffer value
303 wl_bssiovar_getbuf(char *ifname
, char *iovar
, int bssidx
, void *param
,
304 int paramlen
, void *bufptr
, int buflen
)
309 err
= wl_bssiovar_mkbuf(iovar
, bssidx
, param
, paramlen
, bufptr
, buflen
, &iolen
);
313 return wl_ioctl(ifname
, WLC_GET_VAR
, bufptr
, buflen
);
317 * set named & bss indexed driver variable to buffer value
320 wl_bssiovar_set(char *ifname
, char *iovar
, int bssidx
, void *param
, int paramlen
)
322 char smbuf
[WLC_IOCTL_SMLEN
];
324 return wl_bssiovar_setbuf(ifname
, iovar
, bssidx
, param
, paramlen
, smbuf
, sizeof(smbuf
));
328 * get named & bss indexed driver variable buffer value
331 wl_bssiovar_get(char *ifname
, char *iovar
, int bssidx
, void *outbuf
, int len
)
333 char smbuf
[WLC_IOCTL_SMLEN
];
336 /* use the return buffer if it is bigger than what we have on the stack */
337 if (len
> (int)sizeof(smbuf
)) {
338 err
= wl_bssiovar_getbuf(ifname
, iovar
, bssidx
, NULL
, 0, outbuf
, len
);
340 memset(smbuf
, 0, sizeof(smbuf
));
341 err
= wl_bssiovar_getbuf(ifname
, iovar
, bssidx
, NULL
, 0, smbuf
, sizeof(smbuf
));
343 memcpy(outbuf
, smbuf
, len
);
350 * set named & bss indexed driver variable to int value
353 wl_bssiovar_setint(char *ifname
, char *iovar
, int bssidx
, int val
)
355 return wl_bssiovar_set(ifname
, iovar
, bssidx
, &val
, sizeof(int));
This page took 0.069421 seconds and 5 git commands to generate.