2 * Wireless network adapter utilities
4 * Copyright 2006, 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.
17 #include <sys/ioctl.h>
19 #include <linux/types.h>
21 typedef u_int64_t u64
;
22 typedef u_int32_t u32
;
23 typedef u_int16_t u16
;
25 #include <linux/sockios.h>
26 #include <linux/ethtool.h>
34 wl_ioctl(char *name
, int cmd
, void *buf
, int len
)
41 /* open socket to kernel */
42 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
51 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
52 ifr
.ifr_data
= (caddr_t
) &ioc
;
53 if ((ret
= ioctl(s
, SIOCDEVPRIVATE
, &ifr
)) < 0)
61 wl_get_dev_type(char *name
, void *buf
, int len
)
66 struct ethtool_drvinfo info
;
68 /* open socket to kernel */
69 if ((s
= socket(AF_INET
, SOCK_DGRAM
, 0)) < 0) {
75 memset(&info
, 0, sizeof(info
));
76 info
.cmd
= ETHTOOL_GDRVINFO
;
77 ifr
.ifr_data
= (caddr_t
)&info
;
78 strncpy(ifr
.ifr_name
, name
, IFNAMSIZ
);
79 if ((ret
= ioctl(s
, SIOCETHTOOL
, &ifr
)) < 0) {
82 strncpy(buf
, info
.driver
, len
);
93 if ((ret
= wl_get_dev_type(name
, buf
, 3)) < 0)
96 if (strncmp(buf
, "wl", 2))
98 if ((ret
= wl_ioctl(name
, WLC_GET_VERSION
, &val
, sizeof(val
))))
100 if (val
> WLC_IOCTL_VERSION
)
107 wl_iovar_getbuf(char *ifname
, char *iovar
, void *param
, int paramlen
, void *bufptr
, int buflen
)
113 namelen
= strlen(iovar
) + 1; /* length of iovar name plus null */
114 iolen
= namelen
+ paramlen
;
116 /* check for overflow */
118 return (BCME_BUFTOOSHORT
);
120 memcpy(bufptr
, iovar
, namelen
); /* copy iovar name including null */
121 memcpy((int8
*)bufptr
+ namelen
, param
, paramlen
);
123 err
= wl_ioctl(ifname
, WLC_GET_VAR
, bufptr
, buflen
);
129 wl_iovar_setbuf(char *ifname
, char *iovar
, void *param
, int paramlen
, void *bufptr
, int buflen
)
134 namelen
= strlen(iovar
) + 1; /* length of iovar name plus null */
135 iolen
= namelen
+ paramlen
;
137 /* check for overflow */
139 return (BCME_BUFTOOSHORT
);
141 memcpy(bufptr
, iovar
, namelen
); /* copy iovar name including null */
142 memcpy((int8
*)bufptr
+ namelen
, param
, paramlen
);
144 return wl_ioctl(ifname
, WLC_SET_VAR
, bufptr
, iolen
);
148 wl_iovar_set(char *ifname
, char *iovar
, void *param
, int paramlen
)
150 char smbuf
[WLC_IOCTL_SMLEN
];
152 return wl_iovar_setbuf(ifname
, iovar
, param
, paramlen
, smbuf
, sizeof(smbuf
));
156 wl_iovar_get(char *ifname
, char *iovar
, void *bufptr
, int buflen
)
158 char smbuf
[WLC_IOCTL_SMLEN
];
161 /* use the return buffer if it is bigger than what we have on the stack */
162 if (buflen
> sizeof(smbuf
)) {
163 ret
= wl_iovar_getbuf(ifname
, iovar
, NULL
, 0, bufptr
, buflen
);
165 ret
= wl_iovar_getbuf(ifname
, iovar
, NULL
, 0, smbuf
, sizeof(smbuf
));
167 memcpy(bufptr
, smbuf
, buflen
);
175 * format a bsscfg indexed iovar buffer
178 wl_bssiovar_mkbuf(char *iovar
, int bssidx
, void *param
, int paramlen
, void *bufptr
, int buflen
,
181 char *prefix
= "bsscfg:";
187 prefixlen
= strlen(prefix
); /* length of bsscfg prefix */
188 namelen
= strlen(iovar
) + 1; /* length of iovar name + null */
189 iolen
= prefixlen
+ namelen
+ sizeof(int) + paramlen
;
191 /* check for overflow */
192 if (buflen
< 0 || iolen
> (uint
)buflen
) {
194 return BCME_BUFTOOSHORT
;
199 /* copy prefix, no null */
200 memcpy(p
, prefix
, prefixlen
);
203 /* copy iovar name including null */
204 memcpy(p
, iovar
, namelen
);
207 /* bss config index as first param */
208 memcpy(p
, &bssidx
, sizeof(int32
));
211 /* parameter buffer follows */
213 memcpy(p
, param
, paramlen
);
220 * set named & bss indexed driver variable to buffer value
223 wl_bssiovar_setbuf(char *ifname
, char *iovar
, int bssidx
, void *param
, int paramlen
, void *bufptr
,
229 err
= wl_bssiovar_mkbuf(iovar
, bssidx
, param
, paramlen
, bufptr
, buflen
, &iolen
);
233 return wl_ioctl(ifname
, WLC_SET_VAR
, bufptr
, iolen
);
237 * get named & bss indexed driver variable buffer value
240 wl_bssiovar_getbuf(char *ifname
, char *iovar
, int bssidx
, void *param
, int paramlen
, void *bufptr
,
246 err
= wl_bssiovar_mkbuf(iovar
, bssidx
, param
, paramlen
, bufptr
, buflen
, &iolen
);
250 return wl_ioctl(ifname
, WLC_GET_VAR
, bufptr
, buflen
);
254 * set named & bss indexed driver variable to buffer value
257 wl_bssiovar_set(char *ifname
, char *iovar
, int bssidx
, void *param
, int paramlen
)
259 char smbuf
[WLC_IOCTL_SMLEN
];
261 return wl_bssiovar_setbuf(ifname
, iovar
, bssidx
, param
, paramlen
, smbuf
, sizeof(smbuf
));
265 * get named & bss indexed driver variable buffer value
268 wl_bssiovar_get(char *ifname
, char *iovar
, int bssidx
, void *outbuf
, int len
)
270 char smbuf
[WLC_IOCTL_SMLEN
];
273 /* use the return buffer if it is bigger than what we have on the stack */
274 if (len
> (int)sizeof(smbuf
)) {
275 err
= wl_bssiovar_getbuf(ifname
, iovar
, bssidx
, NULL
, 0, outbuf
, len
);
277 memset(smbuf
, 0, sizeof(smbuf
));
278 err
= wl_bssiovar_getbuf(ifname
, iovar
, bssidx
, NULL
, 0, smbuf
, sizeof(smbuf
));
280 memcpy(outbuf
, smbuf
, len
);
287 wl_printlasterror(char *name
)
289 char err_buf
[WLC_IOCTL_SMLEN
];
290 strcpy(err_buf
, "bcmerrstr");
292 fprintf(stderr
, "Error: ");
293 if ( wl_ioctl(name
, WLC_GET_VAR
, err_buf
, sizeof (err_buf
)) != 0)
294 fprintf(stderr
, "Error getting the Errorstring from driver\n");
296 fprintf(stderr
, err_buf
);
This page took 0.05697 seconds and 5 git commands to generate.