2 * iwinfo - Wireless Information Library - Madwifi Backend
4 * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
6 * The iwinfo library is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version 2
8 * as published by the Free Software Foundation.
10 * The iwinfo library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with the iwinfo library. If not, see http://www.gnu.org/licenses/.
18 * The signal handling code is derived from the official madwifi tools,
19 * wlanconfig.c in particular. The encryption property handling was
20 * inspired by the hostapd madwifi driver.
23 #include "iwinfo/madwifi.h"
24 #include "iwinfo/wext.h"
28 * Madwifi ISO 3166 to Country/Region Code mapping.
31 static struct ISO3166_to_CCode
36 { 0x3030 /* 00 */, 0 }, /* World */
37 { 0x4145 /* AE */, 784 }, /* U.A.E. */
38 { 0x414C /* AL */, 8 }, /* Albania */
39 { 0x414D /* AM */, 51 }, /* Armenia */
40 { 0x4152 /* AR */, 32 }, /* Argentina */
41 { 0x4154 /* AT */, 40 }, /* Austria */
42 { 0x4155 /* AU */, 36 }, /* Australia */
43 { 0x415A /* AZ */, 31 }, /* Azerbaijan */
44 { 0x4245 /* BE */, 56 }, /* Belgium */
45 { 0x4247 /* BG */, 100 }, /* Bulgaria */
46 { 0x4248 /* BH */, 48 }, /* Bahrain */
47 { 0x424E /* BN */, 96 }, /* Brunei Darussalam */
48 { 0x424F /* BO */, 68 }, /* Bolivia */
49 { 0x4252 /* BR */, 76 }, /* Brazil */
50 { 0x4259 /* BY */, 112 }, /* Belarus */
51 { 0x425A /* BZ */, 84 }, /* Belize */
52 { 0x4341 /* CA */, 124 }, /* Canada */
53 { 0x4348 /* CH */, 756 }, /* Switzerland */
54 { 0x434C /* CL */, 152 }, /* Chile */
55 { 0x434E /* CN */, 156 }, /* People's Republic of China */
56 { 0x434F /* CO */, 170 }, /* Colombia */
57 { 0x4352 /* CR */, 188 }, /* Costa Rica */
58 { 0x4359 /* CY */, 196 }, /* Cyprus */
59 { 0x435A /* CZ */, 203 }, /* Czech Republic */
60 { 0x4445 /* DE */, 276 }, /* Germany */
61 { 0x444B /* DK */, 208 }, /* Denmark */
62 { 0x444F /* DO */, 214 }, /* Dominican Republic */
63 { 0x445A /* DZ */, 12 }, /* Algeria */
64 { 0x4543 /* EC */, 218 }, /* Ecuador */
65 { 0x4545 /* EE */, 233 }, /* Estonia */
66 { 0x4547 /* EG */, 818 }, /* Egypt */
67 { 0x4553 /* ES */, 724 }, /* Spain */
68 { 0x4649 /* FI */, 246 }, /* Finland */
69 { 0x464F /* FO */, 234 }, /* Faeroe Islands */
70 { 0x4652 /* FR */, 250 }, /* France */
71 { 0x4652 /* FR */, 255 }, /* France2 */
72 { 0x4742 /* GB */, 826 }, /* United Kingdom */
73 { 0x4745 /* GE */, 268 }, /* Georgia */
74 { 0x4752 /* GR */, 300 }, /* Greece */
75 { 0x4754 /* GT */, 320 }, /* Guatemala */
76 { 0x484B /* HK */, 344 }, /* Hong Kong S.A.R., P.R.C. */
77 { 0x484E /* HN */, 340 }, /* Honduras */
78 { 0x4852 /* HR */, 191 }, /* Croatia */
79 { 0x4855 /* HU */, 348 }, /* Hungary */
80 { 0x4944 /* ID */, 360 }, /* Indonesia */
81 { 0x4945 /* IE */, 372 }, /* Ireland */
82 { 0x494C /* IL */, 376 }, /* Israel */
83 { 0x494E /* IN */, 356 }, /* India */
84 { 0x4951 /* IQ */, 368 }, /* Iraq */
85 { 0x4952 /* IR */, 364 }, /* Iran */
86 { 0x4953 /* IS */, 352 }, /* Iceland */
87 { 0x4954 /* IT */, 380 }, /* Italy */
88 { 0x4A4D /* JM */, 388 }, /* Jamaica */
89 { 0x4A4F /* JO */, 400 }, /* Jordan */
90 { 0x4A50 /* JP */, 392 }, /* Japan */
91 { 0x4A50 /* JP */, 393 }, /* Japan (JP1) */
92 { 0x4A50 /* JP */, 394 }, /* Japan (JP0) */
93 { 0x4A50 /* JP */, 395 }, /* Japan (JP1-1) */
94 { 0x4A50 /* JP */, 396 }, /* Japan (JE1) */
95 { 0x4A50 /* JP */, 397 }, /* Japan (JE2) */
96 { 0x4A50 /* JP */, 399 }, /* Japan (JP6) */
97 { 0x4A50 /* JP */, 900 }, /* Japan */
98 { 0x4A50 /* JP */, 901 }, /* Japan */
99 { 0x4A50 /* JP */, 902 }, /* Japan */
100 { 0x4A50 /* JP */, 903 }, /* Japan */
101 { 0x4A50 /* JP */, 904 }, /* Japan */
102 { 0x4A50 /* JP */, 905 }, /* Japan */
103 { 0x4A50 /* JP */, 906 }, /* Japan */
104 { 0x4A50 /* JP */, 907 }, /* Japan */
105 { 0x4A50 /* JP */, 908 }, /* Japan */
106 { 0x4A50 /* JP */, 909 }, /* Japan */
107 { 0x4A50 /* JP */, 910 }, /* Japan */
108 { 0x4A50 /* JP */, 911 }, /* Japan */
109 { 0x4A50 /* JP */, 912 }, /* Japan */
110 { 0x4A50 /* JP */, 913 }, /* Japan */
111 { 0x4A50 /* JP */, 914 }, /* Japan */
112 { 0x4A50 /* JP */, 915 }, /* Japan */
113 { 0x4A50 /* JP */, 916 }, /* Japan */
114 { 0x4A50 /* JP */, 917 }, /* Japan */
115 { 0x4A50 /* JP */, 918 }, /* Japan */
116 { 0x4A50 /* JP */, 919 }, /* Japan */
117 { 0x4A50 /* JP */, 920 }, /* Japan */
118 { 0x4A50 /* JP */, 921 }, /* Japan */
119 { 0x4A50 /* JP */, 922 }, /* Japan */
120 { 0x4A50 /* JP */, 923 }, /* Japan */
121 { 0x4A50 /* JP */, 924 }, /* Japan */
122 { 0x4A50 /* JP */, 925 }, /* Japan */
123 { 0x4A50 /* JP */, 926 }, /* Japan */
124 { 0x4A50 /* JP */, 927 }, /* Japan */
125 { 0x4A50 /* JP */, 928 }, /* Japan */
126 { 0x4A50 /* JP */, 929 }, /* Japan */
127 { 0x4A50 /* JP */, 930 }, /* Japan */
128 { 0x4A50 /* JP */, 931 }, /* Japan */
129 { 0x4A50 /* JP */, 932 }, /* Japan */
130 { 0x4A50 /* JP */, 933 }, /* Japan */
131 { 0x4A50 /* JP */, 934 }, /* Japan */
132 { 0x4A50 /* JP */, 935 }, /* Japan */
133 { 0x4A50 /* JP */, 936 }, /* Japan */
134 { 0x4A50 /* JP */, 937 }, /* Japan */
135 { 0x4A50 /* JP */, 938 }, /* Japan */
136 { 0x4A50 /* JP */, 939 }, /* Japan */
137 { 0x4A50 /* JP */, 940 }, /* Japan */
138 { 0x4A50 /* JP */, 941 }, /* Japan */
139 { 0x4B45 /* KE */, 404 }, /* Kenya */
140 { 0x4B50 /* KP */, 408 }, /* North Korea */
141 { 0x4B52 /* KR */, 410 }, /* South Korea */
142 { 0x4B52 /* KR */, 411 }, /* South Korea */
143 { 0x4B57 /* KW */, 414 }, /* Kuwait */
144 { 0x4B5A /* KZ */, 398 }, /* Kazakhstan */
145 { 0x4C42 /* LB */, 422 }, /* Lebanon */
146 { 0x4C49 /* LI */, 438 }, /* Liechtenstein */
147 { 0x4C54 /* LT */, 440 }, /* Lithuania */
148 { 0x4C55 /* LU */, 442 }, /* Luxembourg */
149 { 0x4C56 /* LV */, 428 }, /* Latvia */
150 { 0x4C59 /* LY */, 434 }, /* Libya */
151 { 0x4D41 /* MA */, 504 }, /* Morocco */
152 { 0x4D43 /* MC */, 492 }, /* Principality of Monaco */
153 { 0x4D4B /* MK */, 807 }, /* the Former Yugoslav Republic of Macedonia */
154 { 0x4D4F /* MO */, 446 }, /* Macau */
155 { 0x4D58 /* MX */, 484 }, /* Mexico */
156 { 0x4D59 /* MY */, 458 }, /* Malaysia */
157 { 0x4E49 /* NI */, 558 }, /* Nicaragua */
158 { 0x4E4C /* NL */, 528 }, /* Netherlands */
159 { 0x4E4F /* NO */, 578 }, /* Norway */
160 { 0x4E5A /* NZ */, 554 }, /* New Zealand */
161 { 0x4F4D /* OM */, 512 }, /* Oman */
162 { 0x5041 /* PA */, 591 }, /* Panama */
163 { 0x5045 /* PE */, 604 }, /* Peru */
164 { 0x5048 /* PH */, 608 }, /* Republic of the Philippines */
165 { 0x504B /* PK */, 586 }, /* Islamic Republic of Pakistan */
166 { 0x504C /* PL */, 616 }, /* Poland */
167 { 0x5052 /* PR */, 630 }, /* Puerto Rico */
168 { 0x5054 /* PT */, 620 }, /* Portugal */
169 { 0x5059 /* PY */, 600 }, /* Paraguay */
170 { 0x5141 /* QA */, 634 }, /* Qatar */
171 { 0x524F /* RO */, 642 }, /* Romania */
172 { 0x5255 /* RU */, 643 }, /* Russia */
173 { 0x5341 /* SA */, 682 }, /* Saudi Arabia */
174 { 0x5345 /* SE */, 752 }, /* Sweden */
175 { 0x5347 /* SG */, 702 }, /* Singapore */
176 { 0x5349 /* SI */, 705 }, /* Slovenia */
177 { 0x534B /* SK */, 703 }, /* Slovak Republic */
178 { 0x5356 /* SV */, 222 }, /* El Salvador */
179 { 0x5359 /* SY */, 760 }, /* Syria */
180 { 0x5448 /* TH */, 764 }, /* Thailand */
181 { 0x544E /* TN */, 788 }, /* Tunisia */
182 { 0x5452 /* TR */, 792 }, /* Turkey */
183 { 0x5454 /* TT */, 780 }, /* Trinidad y Tobago */
184 { 0x5457 /* TW */, 158 }, /* Taiwan */
185 { 0x5541 /* UA */, 804 }, /* Ukraine */
186 { 0x554B /* UK */, 826 }, /* United Kingdom */
187 { 0x5553 /* US */, 840 }, /* United States */
188 { 0x5553 /* US */, 842 }, /* United States (Public Safety)*/
189 { 0x5559 /* UY */, 858 }, /* Uruguay */
190 { 0x555A /* UZ */, 860 }, /* Uzbekistan */
191 { 0x5645 /* VE */, 862 }, /* Venezuela */
192 { 0x564E /* VN */, 704 }, /* Viet Nam */
193 { 0x5945 /* YE */, 887 }, /* Yemen */
194 { 0x5A41 /* ZA */, 710 }, /* South Africa */
195 { 0x5A57 /* ZW */, 716 }, /* Zimbabwe */
199 static const char * madwifi_phyname(const char *ifname)
201 static char phyname[IFNAMSIZ];
203 if (strlen(ifname) > 5 && !strncmp(ifname, "radio", 5))
204 snprintf(phyname, sizeof(phyname), "wifi%s", ifname + 5);
206 snprintf(phyname, sizeof(phyname), "%s", ifname);
208 return (const char *)phyname;
211 static int madwifi_wrq(struct iwreq *wrq, const char *ifname, int cmd, void *data, size_t len)
213 strncpy(wrq->ifr_name, ifname, IFNAMSIZ);
219 memcpy(wrq->u.name, data, len);
223 wrq->u.data.pointer = data;
224 wrq->u.data.length = len;
228 return iwinfo_ioctl(cmd, wrq);
231 static int get80211priv(const char *ifname, int op, void *data, size_t len)
235 if( madwifi_wrq(&iwr, ifname, op, data, len) < 0 )
238 return iwr.u.data.length;
241 static char * madwifi_isvap(const char *ifname, const char *wifiname)
246 static char name[IFNAMSIZ];
248 if( strlen(ifname) <= 9 )
250 sprintf(path, "/proc/sys/net/%s/%%parent", ifname);
252 if( (fd = open(path, O_RDONLY)) > -1 )
254 if( wifiname != NULL )
256 if( read(fd, name, strlen(wifiname)) == strlen(wifiname) )
257 ret = strncmp(name, wifiname, strlen(wifiname))
260 else if( (ln = read(fd, name, IFNAMSIZ)) >= 4 )
273 static int madwifi_iswifi(const char *ifname)
281 phy = madwifi_phyname(ifname);
283 if( strlen(phy) <= 7 )
285 sprintf(path, "/proc/sys/dev/%s/diversity", phy);
287 if( ! stat(path, &s) )
288 ret = (s.st_mode & S_IFREG);
294 static char * madwifi_ifadd(const char *ifname)
296 const char *wifidev = NULL;
297 struct ifreq ifr = { 0 };
298 struct ieee80211_clone_params cp = { 0 };
299 static char nif[IFNAMSIZ] = { 0 };
301 if( !(wifidev = madwifi_isvap(ifname, NULL)) && madwifi_iswifi(ifname) )
302 wifidev = madwifi_phyname(ifname);
306 snprintf(nif, sizeof(nif), "tmp.%s", ifname);
308 strncpy(cp.icp_name, nif, IFNAMSIZ);
309 cp.icp_opmode = IEEE80211_M_STA;
310 cp.icp_flags = IEEE80211_CLONE_BSSID;
312 strncpy(ifr.ifr_name, wifidev, IFNAMSIZ);
313 ifr.ifr_data = (void *)&cp;
315 if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
321 cp.icp_opmode = IEEE80211_M_MONITOR;
323 if( !iwinfo_ioctl(SIOC80211IFCREATE, &ifr) )
331 static void madwifi_ifdel(const char *ifname)
333 struct ifreq ifr = { 0 };
335 strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
336 iwinfo_ioctl(SIOC80211IFDESTROY, &ifr);
340 int madwifi_probe(const char *ifname)
342 return ( !!madwifi_isvap(ifname, NULL) || madwifi_iswifi(ifname) );
345 void madwifi_close(void)
350 int madwifi_get_mode(const char *ifname, int *buf)
352 return wext_get_mode(ifname, buf);
355 int madwifi_get_ssid(const char *ifname, char *buf)
357 return wext_get_ssid(ifname, buf);
360 int madwifi_get_bssid(const char *ifname, char *buf)
362 return wext_get_bssid(ifname, buf);
365 int madwifi_get_channel(const char *ifname, int *buf)
370 struct ieee80211req_chaninfo chans;
372 if( madwifi_wrq(&wrq, ifname, SIOCGIWFREQ, NULL, 0) >= 0 )
374 /* Madwifi returns a Hz frequency, get it's freq list to find channel index */
375 freq = (uint16_t)(wrq.u.freq.m / 100000);
377 if( get80211priv(ifname, IEEE80211_IOCTL_GETCHANINFO, &chans, sizeof(chans)) >= 0 )
381 for( i = 0; i < chans.ic_nchans; i++ )
383 if( freq == chans.ic_chans[i].ic_freq )
385 *buf = chans.ic_chans[i].ic_ieee;
397 int madwifi_get_frequency(const char *ifname, int *buf)
401 if( madwifi_wrq(&wrq, ifname, SIOCGIWFREQ, NULL, 0) >= 0 )
403 *buf = (uint16_t)(wrq.u.freq.m / 100000);
410 int madwifi_get_txpower(const char *ifname, int *buf)
412 return wext_get_txpower(ifname, buf);
415 int madwifi_get_bitrate(const char *ifname, int *buf)
417 unsigned int mode, len, rate, rate_count;
418 uint8_t tmp[24*1024];
421 struct ieee80211req_sta_info *si;
423 if( madwifi_wrq(&wrq, ifname, SIOCGIWMODE, NULL, 0) >= 0 )
427 /* Calculate bitrate average from associated stations in ad-hoc mode */
430 rate = rate_count = 0;
432 if( (len = get80211priv(ifname, IEEE80211_IOCTL_STA_INFO, tmp, 24*1024)) > 0 )
437 si = (struct ieee80211req_sta_info *) cp;
439 if( si->isi_rssi > 0 )
442 rate += ((si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL) / 2);
447 } while (len >= sizeof(struct ieee80211req_sta_info));
450 *buf = (rate == 0 || rate_count == 0) ? 0 : (rate / rate_count) * 1000;
454 /* Return whatever wext tells us ... */
455 return wext_get_bitrate(ifname, buf);
461 int madwifi_get_signal(const char *ifname, int *buf)
463 unsigned int mode, len, rssi, rssi_count;
464 uint8_t tmp[24*1024];
467 struct ieee80211req_sta_info *si;
469 if( madwifi_wrq(&wrq, ifname, SIOCGIWMODE, NULL, 0) >= 0 )
473 /* Calculate signal average from associated stations in ap or ad-hoc mode */
476 rssi = rssi_count = 0;
478 if( (len = get80211priv(ifname, IEEE80211_IOCTL_STA_INFO, tmp, 24*1024)) > 0 )
483 si = (struct ieee80211req_sta_info *) cp;
485 if( si->isi_rssi > 0 )
488 rssi -= (si->isi_rssi - 95);
493 } while (len >= sizeof(struct ieee80211req_sta_info));
496 *buf = (rssi == 0 || rssi_count == 0) ? 1 : -(rssi / rssi_count);
500 /* Return whatever wext tells us ... */
501 return wext_get_signal(ifname, buf);
507 int madwifi_get_noise(const char *ifname, int *buf)
509 return wext_get_noise(ifname, buf);
512 int madwifi_get_quality(const char *ifname, int *buf)
514 unsigned int mode, len, quality, quality_count;
515 uint8_t tmp[24*1024];
518 struct ieee80211req_sta_info *si;
520 if( madwifi_wrq(&wrq, ifname, SIOCGIWMODE, NULL, 0) >= 0 )
524 /* Calculate signal average from associated stations in ad-hoc mode */
527 quality = quality_count = 0;
529 if( (len = get80211priv(ifname, IEEE80211_IOCTL_STA_INFO, tmp, 24*1024)) > 0 )
534 si = (struct ieee80211req_sta_info *) cp;
536 if( si->isi_rssi > 0 )
539 quality += si->isi_rssi;
544 } while (len >= sizeof(struct ieee80211req_sta_info));
547 *buf = (quality == 0 || quality_count == 0) ? 0 : (quality / quality_count);
551 /* Return whatever wext tells us ... */
552 return wext_get_quality(ifname, buf);
558 int madwifi_get_quality_max(const char *ifname, int *buf)
560 return wext_get_quality_max(ifname, buf);
563 int madwifi_get_encryption(const char *ifname, char *buf)
565 int ciphers = 0, key_len = 0;
566 char keybuf[IW_ENCODING_TOKEN_MAX];
567 struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf;
569 struct ieee80211req_key wk;
571 memset(&wrq, 0, sizeof(wrq));
573 /* Obtain key info */
574 if( madwifi_wrq(&wrq, ifname, SIOCGIWENCODE, keybuf, sizeof(keybuf)) < 0 )
578 /* Have any encryption? */
579 if( (wrq.u.data.flags & IW_ENCODE_DISABLED) || (wrq.u.data.length == 0) )
584 key_len = wrq.u.data.length;
586 /* Get wpa protocol version */
587 wrq.u.mode = IEEE80211_PARAM_WPA;
588 if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
589 c->wpa_version = wrq.u.mode;
591 /* Get authentication suites */
592 wrq.u.mode = IEEE80211_PARAM_AUTHMODE;
593 if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
596 case IEEE80211_AUTH_8021X:
597 c->auth_suites |= IWINFO_KMGMT_8021x;
600 case IEEE80211_AUTH_WPA:
601 c->auth_suites |= IWINFO_KMGMT_PSK;
604 case IEEE80211_AUTH_OPEN:
605 c->auth_algs |= IWINFO_AUTH_OPEN;
608 case IEEE80211_AUTH_SHARED:
609 c->auth_algs |= IWINFO_AUTH_SHARED;
613 c->auth_suites |= IWINFO_KMGMT_NONE;
618 memset(&wk, 0, sizeof(wk));
619 memset(wk.ik_macaddr, 0xff, IEEE80211_ADDR_LEN);
621 /* Get key information */
622 if( get80211priv(ifname, IEEE80211_IOCTL_GETKEY, &wk, sizeof(wk)) >= 0 )
625 if( (wk.ik_type == 0) && (c->auth_algs == 0) )
626 c->auth_algs = (IWINFO_AUTH_OPEN | IWINFO_AUTH_SHARED);
629 /* Get used pairwise ciphers */
630 wrq.u.mode = IEEE80211_PARAM_UCASTCIPHERS;
631 if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
633 ciphers = wrq.u.mode;
635 if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_TKIP) )
636 c->pair_ciphers |= IWINFO_CIPHER_TKIP;
638 if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_AES_CCM) )
639 c->pair_ciphers |= IWINFO_CIPHER_CCMP;
641 if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_AES_OCB) )
642 c->pair_ciphers |= IWINFO_CIPHER_AESOCB;
644 if( c->wpa_version && ciphers & (1 << IEEE80211_CIPHER_CKIP) )
645 c->pair_ciphers |= IWINFO_CIPHER_CKIP;
647 if( !c->pair_ciphers && ciphers & (1 << IEEE80211_CIPHER_WEP) )
651 c->pair_ciphers |= IWINFO_CIPHER_WEP104;
655 c->pair_ciphers |= IWINFO_CIPHER_WEP40;
662 c->pair_ciphers = IWINFO_CIPHER_WEP40 |
663 IWINFO_CIPHER_WEP104;
668 if( ciphers & (1 << IEEE80211_CIPHER_NONE) )
669 c->pair_ciphers |= IWINFO_CIPHER_NONE;
672 /* Get used group cipher */
673 wrq.u.mode = IEEE80211_PARAM_MCASTCIPHER;
674 if( madwifi_wrq(&wrq, ifname, IEEE80211_IOCTL_GETPARAM, NULL, 0) >= 0 )
676 ciphers = c->wpa_version ? wrq.u.mode : IEEE80211_CIPHER_WEP;
679 case IEEE80211_CIPHER_TKIP:
680 c->group_ciphers |= IWINFO_CIPHER_TKIP;
683 case IEEE80211_CIPHER_AES_CCM:
684 c->group_ciphers |= IWINFO_CIPHER_CCMP;
687 case IEEE80211_CIPHER_AES_OCB:
688 c->group_ciphers |= IWINFO_CIPHER_AESOCB;
691 case IEEE80211_CIPHER_CKIP:
692 c->group_ciphers |= IWINFO_CIPHER_CKIP;
695 case IEEE80211_CIPHER_WEP:
698 c->group_ciphers |= IWINFO_CIPHER_WEP104;
702 c->group_ciphers |= IWINFO_CIPHER_WEP40;
710 case IEEE80211_CIPHER_NONE:
711 c->group_ciphers |= IWINFO_CIPHER_NONE;
719 c->enabled = (c->wpa_version || (c->auth_algs && c->pair_ciphers)) ? 1 : 0;
724 int madwifi_get_assoclist(const char *ifname, char *buf, int *len)
728 uint8_t tmp[24*1024];
729 struct ieee80211req_sta_info *si;
730 struct iwinfo_assoclist_entry entry;
732 if( (tl = get80211priv(ifname, IEEE80211_IOCTL_STA_INFO, tmp, 24*1024)) > 0 )
737 if( madwifi_get_noise(ifname, &noise) )
741 si = (struct ieee80211req_sta_info *) cp;
743 memset(&entry, 0, sizeof(entry));
745 entry.signal = (si->isi_rssi - 95);
747 memcpy(entry.mac, &si->isi_macaddr, 6);
749 entry.inactive = si->isi_inact * 1000;
751 entry.tx_packets = (si->isi_txseqs[0] & IEEE80211_SEQ_SEQ_MASK)
752 >> IEEE80211_SEQ_SEQ_SHIFT;
754 entry.rx_packets = (si->isi_rxseqs[0] & IEEE80211_SEQ_SEQ_MASK)
755 >> IEEE80211_SEQ_SEQ_SHIFT;
758 (si->isi_rates[si->isi_txrate] & IEEE80211_RATE_VAL) * 500;
760 /* XXX: this is just a guess */
761 entry.rx_rate.rate = entry.tx_rate.rate;
763 entry.rx_rate.mcs = -1;
764 entry.tx_rate.mcs = -1;
766 memcpy(&buf[bl], &entry, sizeof(struct iwinfo_assoclist_entry));
768 bl += sizeof(struct iwinfo_assoclist_entry);
771 } while (tl >= sizeof(struct ieee80211req_sta_info));
780 int madwifi_get_txpwrlist(const char *ifname, char *buf, int *len)
785 /* A wifiX device? */
786 if( madwifi_iswifi(ifname) )
788 if( (res = madwifi_ifadd(ifname)) != NULL )
790 rc = wext_get_txpwrlist(res, buf, len);
795 /* Its an athX ... */
796 else if( !!madwifi_isvap(ifname, NULL) )
798 rc = wext_get_txpwrlist(ifname, buf, len);
804 int madwifi_get_scanlist(const char *ifname, char *buf, int *len)
813 /* We got a wifiX device passed, try to lookup a vap on it */
814 if( madwifi_iswifi(ifname) )
816 if( (proc = opendir("/proc/sys/net/")) != NULL )
818 while( (e = readdir(proc)) != NULL )
820 if( !!madwifi_isvap(e->d_name, ifname) )
822 if( iwinfo_ifup(e->d_name) )
824 ret = wext_get_scanlist(e->d_name, buf, len);
833 /* Still nothing found, try to create a vap */
836 if( (res = madwifi_ifadd(ifname)) != NULL )
838 if( iwinfo_ifup(res) )
840 wext_get_scanlist(res, buf, len);
843 wext_get_scanlist(res, buf, len);
846 ret = wext_get_scanlist(res, buf, len);
855 /* Got athX device? */
856 else if( !!madwifi_isvap(ifname, NULL) )
858 ret = wext_get_scanlist(ifname, buf, len);
864 int madwifi_get_freqlist(const char *ifname, char *buf, int *len)
869 struct ieee80211req_chaninfo chans;
870 struct iwinfo_freqlist_entry entry;
872 /* A wifiX device? */
873 if( madwifi_iswifi(ifname) )
875 if( (res = madwifi_ifadd(ifname)) != NULL )
877 rc = get80211priv(res, IEEE80211_IOCTL_GETCHANINFO,
878 &chans, sizeof(chans));
884 /* Its an athX ... */
885 else if( !!madwifi_isvap(ifname, NULL) )
887 rc = get80211priv(ifname, IEEE80211_IOCTL_GETCHANINFO,
888 &chans, sizeof(chans));
897 for( i = 0; i < chans.ic_nchans; i++ )
899 entry.mhz = chans.ic_chans[i].ic_freq;
900 entry.channel = chans.ic_chans[i].ic_ieee;
901 entry.restricted = 0;
903 memcpy(&buf[bl], &entry, sizeof(struct iwinfo_freqlist_entry));
904 bl += sizeof(struct iwinfo_freqlist_entry);
914 int madwifi_get_country(const char *ifname, char *buf)
916 int i, fd, ccode = -1;
918 char *wifi = madwifi_iswifi(ifname)
919 ? (char *)ifname : madwifi_isvap(ifname, NULL);
921 struct ISO3166_to_CCode *e;
925 snprintf(buffer, sizeof(buffer), "/proc/sys/dev/%s/countrycode", wifi);
927 if( (fd = open(buffer, O_RDONLY)) > -1 )
929 memset(buffer, 0, sizeof(buffer));
931 if( read(fd, buffer, sizeof(buffer)-1) > 0 )
932 ccode = atoi(buffer);
938 for( i = 0; i < (sizeof(CountryCodes)/sizeof(CountryCodes[0])); i++ )
940 e = &CountryCodes[i];
942 if( e->ccode == ccode )
944 sprintf(buf, "%c%c", e->iso3166 / 256, e->iso3166 % 256);
952 int madwifi_get_countrylist(const char *ifname, char *buf, int *len)
955 struct ISO3166_to_CCode *e, *p = NULL;
956 struct iwinfo_country_entry *c = (struct iwinfo_country_entry *)buf;
960 for( int i = 0; i < (sizeof(CountryCodes)/sizeof(CountryCodes[0])); i++ )
962 e = &CountryCodes[i];
964 if( !p || (e->iso3166 != p->iso3166) )
966 c->iso3166 = e->iso3166;
967 snprintf(c->ccode, sizeof(c->ccode), "%i", e->ccode);
976 *len = (count * sizeof(struct iwinfo_country_entry));
980 int madwifi_get_hwmodelist(const char *ifname, int *buf)
982 char chans[IWINFO_BUFSIZE] = { 0 };
983 struct iwinfo_freqlist_entry *e = NULL;
986 if( !madwifi_get_freqlist(ifname, chans, &len) )
988 for( e = (struct iwinfo_freqlist_entry *)chans; e->channel; e++ )
990 if( e->channel <= 14 )
992 *buf |= IWINFO_80211_B;
993 *buf |= IWINFO_80211_G;
997 *buf |= IWINFO_80211_A;
1007 int madwifi_get_mbssid_support(const char *ifname, int *buf)
1009 /* Test whether we can create another interface */
1010 char *nif = madwifi_ifadd(ifname);
1014 *buf = iwinfo_ifup(nif);
1025 int madwifi_get_hardware_id(const char *ifname, char *buf)
1029 struct iwinfo_hardware_id *ids;
1030 struct iwinfo_hardware_entry *e;
1031 const char *phy = madwifi_phyname(ifname);
1033 if (wext_get_hardware_id(phy, buf))
1034 return iwinfo_hardware_id_from_mtd((struct iwinfo_hardware_id *)buf);
1039 static const struct iwinfo_hardware_entry *
1040 madwifi_get_hardware_entry(const char *ifname)
1042 struct iwinfo_hardware_id id;
1044 if (madwifi_get_hardware_id(ifname, (char *)&id))
1047 return iwinfo_hardware(&id);
1050 int madwifi_get_hardware_name(const char *ifname, char *buf)
1052 const struct iwinfo_hardware_entry *hw;
1054 if (!(hw = madwifi_get_hardware_entry(ifname)))
1055 sprintf(buf, "Generic Atheros");
1057 sprintf(buf, "%s %s", hw->vendor_name, hw->device_name);
1062 int madwifi_get_txpower_offset(const char *ifname, int *buf)
1064 const struct iwinfo_hardware_entry *hw;
1066 if (!(hw = madwifi_get_hardware_entry(ifname)))
1069 *buf = hw->txpower_offset;
1073 int madwifi_get_frequency_offset(const char *ifname, int *buf)
1075 const struct iwinfo_hardware_entry *hw;
1077 if (!(hw = madwifi_get_hardware_entry(ifname)))
1080 *buf = hw->frequency_offset;