iwinfo_wl.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. /*
  2. * iwinfo - Wireless Information Library - Broadcom wl.o Backend
  3. *
  4. * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
  5. *
  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.
  9. *
  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.
  14. *
  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/.
  17. *
  18. * This code is based on the wlc.c utility published by OpenWrt.org .
  19. */
  20. #include <sys/types.h>
  21. #include <sys/stat.h>
  22. #include "iwinfo.h"
  23. #include "api/broadcom.h"
  24. static int wl_ioctl(const char *name, int cmd, void *buf, int len)
  25. {
  26. struct ifreq ifr;
  27. wl_ioctl_t ioc;
  28. /* do it */
  29. ioc.cmd = cmd;
  30. ioc.buf = buf;
  31. ioc.len = len;
  32. strncpy(ifr.ifr_name, name, IFNAMSIZ);
  33. ifr.ifr_data = (caddr_t) &ioc;
  34. return iwinfo_ioctl(SIOCDEVPRIVATE, &ifr);
  35. }
  36. static int wl_iovar(const char *name, const char *cmd, const char *arg,
  37. int arglen, void *buf, int buflen)
  38. {
  39. int cmdlen = strlen(cmd) + 1;
  40. memcpy(buf, cmd, cmdlen);
  41. if (arg && arglen > 0)
  42. memcpy(buf + cmdlen, arg, arglen);
  43. return wl_ioctl(name, WLC_GET_VAR, buf, buflen);
  44. }
  45. static struct wl_maclist * wl_read_assoclist(const char *ifname)
  46. {
  47. struct wl_maclist *macs;
  48. int maclen = 4 + WL_MAX_STA_COUNT * 6;
  49. if (strstr(ifname, "wds"))
  50. return NULL;
  51. if ((macs = (struct wl_maclist *) malloc(maclen)) != NULL)
  52. {
  53. memset(macs, 0, maclen);
  54. macs->count = WL_MAX_STA_COUNT;
  55. if (!wl_ioctl(ifname, WLC_GET_ASSOCLIST, macs, maclen))
  56. return macs;
  57. free(macs);
  58. }
  59. return NULL;
  60. }
  61. static int wl_probe(const char *ifname)
  62. {
  63. int magic;
  64. return (!wl_ioctl(ifname, WLC_GET_MAGIC, &magic, sizeof(magic)) &&
  65. (magic == WLC_IOCTL_MAGIC));
  66. }
  67. static void wl_close(void)
  68. {
  69. /* Nop */
  70. }
  71. static int wl_get_mode(const char *ifname, int *buf)
  72. {
  73. int ret = -1;
  74. int ap, infra, passive;
  75. if ((ret = wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap))))
  76. return ret;
  77. if ((ret = wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra))))
  78. return ret;
  79. if ((ret = wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive))))
  80. return ret;
  81. if (passive)
  82. *buf = IWINFO_OPMODE_MONITOR;
  83. else if (!infra)
  84. *buf = IWINFO_OPMODE_ADHOC;
  85. else if (ap)
  86. *buf = IWINFO_OPMODE_MASTER;
  87. else
  88. *buf = IWINFO_OPMODE_CLIENT;
  89. return 0;
  90. }
  91. static int wl_get_ssid(const char *ifname, char *buf)
  92. {
  93. int ret = -1;
  94. wlc_ssid_t ssid;
  95. if (!(ret = wl_ioctl(ifname, WLC_GET_SSID, &ssid, sizeof(ssid))))
  96. memcpy(buf, ssid.ssid, ssid.ssid_len);
  97. return ret;
  98. }
  99. static int wl_get_bssid(const char *ifname, char *buf)
  100. {
  101. int ret = -1;
  102. char bssid[6];
  103. if (!(ret = wl_ioctl(ifname, WLC_GET_BSSID, bssid, 6)))
  104. sprintf(buf, "%02X:%02X:%02X:%02X:%02X:%02X",
  105. (uint8_t)bssid[0], (uint8_t)bssid[1], (uint8_t)bssid[2],
  106. (uint8_t)bssid[3], (uint8_t)bssid[4], (uint8_t)bssid[5]
  107. );
  108. return ret;
  109. }
  110. static int wl_get_channel(const char *ifname, int *buf)
  111. {
  112. return wl_ioctl(ifname, WLC_GET_CHANNEL, buf, sizeof(buf));
  113. }
  114. static int wl_get_center_chan1(const char *ifname, int *buf)
  115. {
  116. /* Not Supported */
  117. return -1;
  118. }
  119. static int wl_get_center_chan2(const char *ifname, int *buf)
  120. {
  121. /* Not Supported */
  122. return -1;
  123. }
  124. static int wl_get_frequency(const char *ifname, int *buf)
  125. {
  126. return wext_ops.frequency(ifname, buf);
  127. }
  128. static int wl_get_txpower(const char *ifname, int *buf)
  129. {
  130. /* WLC_GET_VAR "qtxpower" */
  131. return wext_ops.txpower(ifname, buf);
  132. }
  133. static int wl_get_bitrate(const char *ifname, int *buf)
  134. {
  135. int ret = -1;
  136. int rate = 0;
  137. if( !(ret = wl_ioctl(ifname, WLC_GET_RATE, &rate, sizeof(rate))) && (rate > 0))
  138. *buf = ((rate / 2) * 1000) + ((rate & 1) ? 500 : 0);
  139. return ret;
  140. }
  141. static int wl_get_signal(const char *ifname, int *buf)
  142. {
  143. unsigned int ap, rssi, i, rssi_count;
  144. int ioctl_req_version = 0x2000;
  145. char tmp[WLC_IOCTL_MAXLEN];
  146. struct wl_maclist *macs = NULL;
  147. wl_sta_rssi_t starssi;
  148. memset(tmp, 0, WLC_IOCTL_MAXLEN);
  149. memcpy(tmp, &ioctl_req_version, sizeof(ioctl_req_version));
  150. wl_ioctl(ifname, WLC_GET_BSS_INFO, tmp, WLC_IOCTL_MAXLEN);
  151. if (!wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap)) && !ap)
  152. {
  153. *buf = tmp[WL_BSS_RSSI_OFFSET];
  154. }
  155. else
  156. {
  157. rssi = rssi_count = 0;
  158. /* Calculate average rssi from conntected stations */
  159. if ((macs = wl_read_assoclist(ifname)) != NULL)
  160. {
  161. for (i = 0; i < macs->count; i++)
  162. {
  163. memcpy(starssi.mac, &macs->ea[i], 6);
  164. if (!wl_ioctl(ifname, WLC_GET_RSSI, &starssi, 12))
  165. {
  166. rssi -= starssi.rssi;
  167. rssi_count++;
  168. }
  169. }
  170. free(macs);
  171. }
  172. *buf = (rssi == 0 || rssi_count == 0) ? 1 : -(rssi / rssi_count);
  173. }
  174. return 0;
  175. }
  176. static int wl_get_noise(const char *ifname, int *buf)
  177. {
  178. unsigned int ap, noise;
  179. int ioctl_req_version = 0x2000;
  180. char tmp[WLC_IOCTL_MAXLEN];
  181. memset(tmp, 0, WLC_IOCTL_MAXLEN);
  182. memcpy(tmp, &ioctl_req_version, sizeof(ioctl_req_version));
  183. wl_ioctl(ifname, WLC_GET_BSS_INFO, tmp, WLC_IOCTL_MAXLEN);
  184. if ((wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap)) < 0) || ap)
  185. {
  186. if (wl_ioctl(ifname, WLC_GET_PHY_NOISE, &noise, sizeof(noise)) < 0)
  187. noise = 0;
  188. }
  189. else
  190. {
  191. noise = tmp[WL_BSS_NOISE_OFFSET];
  192. }
  193. *buf = noise;
  194. return 0;
  195. }
  196. static int wl_get_quality(const char *ifname, int *buf)
  197. {
  198. return wext_ops.quality(ifname, buf);
  199. }
  200. static int wl_get_quality_max(const char *ifname, int *buf)
  201. {
  202. return wext_ops.quality_max(ifname, buf);
  203. }
  204. static int wl_get_encryption(const char *ifname, char *buf)
  205. {
  206. uint32_t wsec, wauth, wpa;
  207. struct iwinfo_crypto_entry *c = (struct iwinfo_crypto_entry *)buf;
  208. if( wl_ioctl(ifname, WLC_GET_WPA_AUTH, &wpa, sizeof(uint32_t)) ||
  209. wl_ioctl(ifname, WLC_GET_WSEC, &wsec, sizeof(uint32_t)) ||
  210. wl_ioctl(ifname, WLC_GET_AUTH, &wauth, sizeof(uint32_t)) )
  211. return -1;
  212. switch(wsec)
  213. {
  214. case 2:
  215. c->pair_ciphers |= IWINFO_CIPHER_TKIP;
  216. break;
  217. case 4:
  218. c->pair_ciphers |= IWINFO_CIPHER_CCMP;
  219. break;
  220. case 6:
  221. c->pair_ciphers |= IWINFO_CIPHER_TKIP;
  222. c->pair_ciphers |= IWINFO_CIPHER_CCMP;
  223. break;
  224. }
  225. switch(wpa)
  226. {
  227. case 0:
  228. if (wsec && !wauth)
  229. c->auth_algs |= IWINFO_AUTH_OPEN;
  230. else if (wsec && wauth)
  231. c->auth_algs |= IWINFO_AUTH_SHARED;
  232. /* ToDo: evaluate WEP key lengths */
  233. c->pair_ciphers = IWINFO_CIPHER_WEP40 | IWINFO_CIPHER_WEP104;
  234. c->auth_suites |= IWINFO_KMGMT_NONE;
  235. break;
  236. case 2:
  237. c->wpa_version = 1;
  238. c->auth_suites |= IWINFO_KMGMT_8021x;
  239. break;
  240. case 4:
  241. c->wpa_version = 1;
  242. c->auth_suites |= IWINFO_KMGMT_PSK;
  243. break;
  244. case 32:
  245. case 64:
  246. c->wpa_version = 2;
  247. c->auth_suites |= IWINFO_KMGMT_8021x;
  248. break;
  249. case 66:
  250. c->wpa_version = 3;
  251. c->auth_suites |= IWINFO_KMGMT_8021x;
  252. break;
  253. case 128:
  254. c->wpa_version = 2;
  255. c->auth_suites |= IWINFO_KMGMT_PSK;
  256. break;
  257. case 132:
  258. c->wpa_version = 3;
  259. c->auth_suites |= IWINFO_KMGMT_PSK;
  260. break;
  261. default:
  262. break;
  263. }
  264. c->enabled = (c->wpa_version || c->auth_algs) ? 1 : 0;
  265. c->group_ciphers = c->pair_ciphers;
  266. return 0;
  267. }
  268. static int wl_get_phyname(const char *ifname, char *buf)
  269. {
  270. char *p;
  271. strcpy(buf, ifname);
  272. if ((p = strchr(buf, '.')) != NULL)
  273. *p = 0;
  274. return 0;
  275. }
  276. static int wl_get_enctype(const char *ifname, char *buf)
  277. {
  278. uint32_t wsec, wpa;
  279. char algo[11];
  280. if( wl_ioctl(ifname, WLC_GET_WPA_AUTH, &wpa, sizeof(uint32_t)) ||
  281. wl_ioctl(ifname, WLC_GET_WSEC, &wsec, sizeof(uint32_t)) )
  282. return -1;
  283. switch(wsec)
  284. {
  285. case 2:
  286. sprintf(algo, "TKIP");
  287. break;
  288. case 4:
  289. sprintf(algo, "CCMP");
  290. break;
  291. case 6:
  292. sprintf(algo, "TKIP, CCMP");
  293. break;
  294. }
  295. switch(wpa)
  296. {
  297. case 0:
  298. sprintf(buf, "%s", wsec ? "WEP" : "None");
  299. break;
  300. case 2:
  301. sprintf(buf, "WPA 802.1X (%s)", algo);
  302. break;
  303. case 4:
  304. sprintf(buf, "WPA PSK (%s)", algo);
  305. break;
  306. case 32:
  307. sprintf(buf, "802.1X (%s)", algo);
  308. break;
  309. case 64:
  310. sprintf(buf, "WPA2 802.1X (%s)", algo);
  311. break;
  312. case 66:
  313. sprintf(buf, "mixed WPA/WPA2 802.1X (%s)", algo);
  314. break;
  315. case 128:
  316. sprintf(buf, "WPA2 PSK (%s)", algo);
  317. break;
  318. case 132:
  319. sprintf(buf, "mixed WPA/WPA2 PSK (%s)", algo);
  320. break;
  321. default:
  322. sprintf(buf, "Unknown");
  323. }
  324. return 0;
  325. }
  326. static void wl_get_assoclist_cb(const char *ifname,
  327. struct iwinfo_assoclist_entry *e)
  328. {
  329. wl_sta_info_t sta = { 0 };
  330. if (!wl_iovar(ifname, "sta_info", e->mac, 6, &sta, sizeof(sta)) &&
  331. (sta.ver >= 2))
  332. {
  333. e->inactive = sta.idle * 1000;
  334. e->rx_packets = sta.rx_ucast_pkts;
  335. e->tx_packets = sta.tx_pkts;
  336. e->rx_rate.rate = sta.rx_rate;
  337. e->tx_rate.rate = sta.tx_rate;
  338. /* ToDo: 11n */
  339. e->rx_rate.mcs = -1;
  340. e->tx_rate.mcs = -1;
  341. }
  342. }
  343. static int wl_get_assoclist(const char *ifname, char *buf, int *len)
  344. {
  345. int i, j, noise;
  346. int ap, infra, passive;
  347. char line[128];
  348. char macstr[18];
  349. char devstr[IFNAMSIZ];
  350. struct wl_maclist *macs;
  351. struct wl_sta_rssi rssi;
  352. struct iwinfo_assoclist_entry entry;
  353. FILE *arp;
  354. ap = infra = passive = 0;
  355. wl_ioctl(ifname, WLC_GET_AP, &ap, sizeof(ap));
  356. wl_ioctl(ifname, WLC_GET_INFRA, &infra, sizeof(infra));
  357. wl_ioctl(ifname, WLC_GET_PASSIVE, &passive, sizeof(passive));
  358. if (wl_get_noise(ifname, &noise))
  359. noise = 0;
  360. if ((ap || infra || passive) && ((macs = wl_read_assoclist(ifname)) != NULL))
  361. {
  362. for (i = 0, j = 0; i < macs->count; i++, j += sizeof(struct iwinfo_assoclist_entry))
  363. {
  364. memset(&entry, 0, sizeof(entry));
  365. memcpy(rssi.mac, &macs->ea[i], 6);
  366. if (!wl_ioctl(ifname, WLC_GET_RSSI, &rssi, sizeof(struct wl_sta_rssi)))
  367. entry.signal = (rssi.rssi - 0x100);
  368. else
  369. entry.signal = 0;
  370. entry.noise = noise;
  371. memcpy(entry.mac, &macs->ea[i], 6);
  372. wl_get_assoclist_cb(ifname, &entry);
  373. memcpy(&buf[j], &entry, sizeof(entry));
  374. }
  375. *len = j;
  376. free(macs);
  377. return 0;
  378. }
  379. else if ((arp = fopen("/proc/net/arp", "r")) != NULL)
  380. {
  381. j = 0;
  382. while (fgets(line, sizeof(line), arp) != NULL)
  383. {
  384. if (sscanf(line, "%*s 0x%*d 0x%*d %17s %*s %s", macstr, devstr) && !strcmp(devstr, ifname))
  385. {
  386. rssi.mac[0] = strtol(&macstr[0], NULL, 16);
  387. rssi.mac[1] = strtol(&macstr[3], NULL, 16);
  388. rssi.mac[2] = strtol(&macstr[6], NULL, 16);
  389. rssi.mac[3] = strtol(&macstr[9], NULL, 16);
  390. rssi.mac[4] = strtol(&macstr[12], NULL, 16);
  391. rssi.mac[5] = strtol(&macstr[15], NULL, 16);
  392. if (!wl_ioctl(ifname, WLC_GET_RSSI, &rssi, sizeof(struct wl_sta_rssi)))
  393. entry.signal = (rssi.rssi - 0x100);
  394. else
  395. entry.signal = 0;
  396. entry.noise = noise;
  397. memcpy(entry.mac, rssi.mac, 6);
  398. memcpy(&buf[j], &entry, sizeof(entry));
  399. j += sizeof(entry);
  400. }
  401. }
  402. *len = j;
  403. (void) fclose(arp);
  404. return 0;
  405. }
  406. return -1;
  407. }
  408. static int wl_get_txpwrlist(const char *ifname, char *buf, int *len)
  409. {
  410. struct iwinfo_txpwrlist_entry entry;
  411. uint8_t dbm[11] = { 0, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24 };
  412. uint8_t mw[11] = { 1, 3, 6, 10, 15, 25, 39, 63, 100, 158, 251 };
  413. int i;
  414. for (i = 0; i < 11; i++)
  415. {
  416. entry.dbm = dbm[i];
  417. entry.mw = mw[i];
  418. memcpy(&buf[i*sizeof(entry)], &entry, sizeof(entry));
  419. }
  420. *len = 11 * sizeof(entry);
  421. return 0;
  422. }
  423. static int wl_get_scanlist(const char *ifname, char *buf, int *len)
  424. {
  425. return wext_ops.scanlist(ifname, buf, len);
  426. }
  427. static int wl_get_freqlist(const char *ifname, char *buf, int *len)
  428. {
  429. return wext_ops.freqlist(ifname, buf, len);
  430. }
  431. static int wl_get_country(const char *ifname, char *buf)
  432. {
  433. char ccode[WLC_CNTRY_BUF_SZ];
  434. if (!wl_ioctl(ifname, WLC_GET_COUNTRY, ccode, WLC_CNTRY_BUF_SZ))
  435. {
  436. /* IL0 -> World */
  437. if (!strcmp(ccode, "IL0"))
  438. sprintf(buf, "00");
  439. /* YU -> RS */
  440. else if (!strcmp(ccode, "YU"))
  441. sprintf(buf, "RS");
  442. else
  443. memcpy(buf, ccode, 2);
  444. return 0;
  445. }
  446. return -1;
  447. }
  448. static int wl_get_countrylist(const char *ifname, char *buf, int *len)
  449. {
  450. int i, count;
  451. char cdata[WLC_IOCTL_MAXLEN];
  452. struct iwinfo_country_entry *c = (struct iwinfo_country_entry *)buf;
  453. wl_country_list_t *cl = (wl_country_list_t *)cdata;
  454. cl->buflen = sizeof(cdata);
  455. if (!wl_ioctl(ifname, WLC_GET_COUNTRY_LIST, cl, cl->buflen))
  456. {
  457. for (i = 0, count = 0; i < cl->count; i++, c++)
  458. {
  459. snprintf(c->ccode, sizeof(c->ccode), "%s", &cl->country_abbrev[i * WLC_CNTRY_BUF_SZ]);
  460. c->iso3166 = c->ccode[0] * 256 + c->ccode[1];
  461. /* IL0 -> World */
  462. if (!strcmp(c->ccode, "IL0"))
  463. c->iso3166 = 0x3030;
  464. /* YU -> RS */
  465. else if (!strcmp(c->ccode, "YU"))
  466. c->iso3166 = 0x5253;
  467. }
  468. *len = (i * sizeof(struct iwinfo_country_entry));
  469. return 0;
  470. }
  471. return -1;
  472. }
  473. static int wl_get_hwmodelist(const char *ifname, int *buf)
  474. {
  475. int phytype;
  476. uint i, band[WLC_BAND_ALL], bands;
  477. if (!wl_ioctl(ifname, WLC_GET_PHYTYPE, &phytype, sizeof(phytype)) &&
  478. !wl_ioctl(ifname, WLC_GET_BANDLIST, band, sizeof(band)))
  479. {
  480. *buf = 0;
  481. switch (phytype)
  482. {
  483. case WLC_PHY_TYPE_A:
  484. *buf = IWINFO_80211_A;
  485. break;
  486. case WLC_PHY_TYPE_B:
  487. *buf = IWINFO_80211_B;
  488. break;
  489. case WLC_PHY_TYPE_AC:
  490. *buf |= IWINFO_80211_AC;
  491. case WLC_PHY_TYPE_HT:
  492. case WLC_PHY_TYPE_N:
  493. *buf |= IWINFO_80211_N;
  494. case WLC_PHY_TYPE_LP:
  495. case WLC_PHY_TYPE_G:
  496. bands = 0;
  497. for (i = 1; i <= band[0]; i++)
  498. {
  499. bands |= band[i];
  500. }
  501. if (bands & WLC_BAND_5G)
  502. *buf |= IWINFO_80211_A;
  503. if (bands & WLC_BAND_2G)
  504. {
  505. *buf |= IWINFO_80211_B;
  506. *buf |= IWINFO_80211_G;
  507. }
  508. break;
  509. default:
  510. return -1;
  511. break;
  512. }
  513. return 0;
  514. }
  515. return -1;
  516. }
  517. static int wl_get_htmodelist(const char *ifname, int *buf)
  518. {
  519. int modes;
  520. if (!wl_get_hwmodelist(ifname, &modes))
  521. {
  522. *buf = 0;
  523. /* FIXME: determine real capabilities */
  524. if (modes & IWINFO_80211_N)
  525. *buf |= IWINFO_HTMODE_HT20 | IWINFO_HTMODE_HT40;
  526. if (modes & IWINFO_80211_AC)
  527. *buf |= IWINFO_HTMODE_VHT20 | IWINFO_HTMODE_VHT40 |
  528. IWINFO_HTMODE_VHT80;
  529. return 0;
  530. }
  531. return -1;
  532. }
  533. static int wl_get_mbssid_support(const char *ifname, int *buf)
  534. {
  535. wlc_rev_info_t revinfo;
  536. /* Multi bssid support only works on corerev >= 9 */
  537. if (!wl_ioctl(ifname, WLC_GET_REVINFO, &revinfo, sizeof(revinfo)))
  538. {
  539. if (revinfo.corerev >= 9)
  540. {
  541. *buf = 1;
  542. return 0;
  543. }
  544. }
  545. return -1;
  546. }
  547. static int wl_get_hardware_id(const char *ifname, char *buf)
  548. {
  549. wlc_rev_info_t revinfo;
  550. struct iwinfo_hardware_id *ids = (struct iwinfo_hardware_id *)buf;
  551. if (wl_ioctl(ifname, WLC_GET_REVINFO, &revinfo, sizeof(revinfo)))
  552. return -1;
  553. ids->vendor_id = revinfo.vendorid;
  554. ids->device_id = revinfo.deviceid;
  555. ids->subsystem_vendor_id = revinfo.boardvendor;
  556. ids->subsystem_device_id = revinfo.boardid;
  557. return 0;
  558. }
  559. static int wl_get_hardware_name(const char *ifname, char *buf)
  560. {
  561. struct iwinfo_hardware_id ids;
  562. if (wl_get_hardware_id(ifname, (char *)&ids))
  563. return -1;
  564. sprintf(buf, "Broadcom BCM%04X", ids.device_id);
  565. return 0;
  566. }
  567. static int wl_get_txpower_offset(const char *ifname, int *buf)
  568. {
  569. FILE *p;
  570. char off[8];
  571. struct stat s;
  572. *buf = 0;
  573. if (!stat("/usr/sbin/nvram", &s) && (s.st_mode & S_IXUSR))
  574. {
  575. if ((p = popen("/usr/sbin/nvram get opo", "r")) != NULL)
  576. {
  577. if (fread(off, 1, sizeof(off), p))
  578. *buf = strtoul(off, NULL, 16);
  579. pclose(p);
  580. }
  581. }
  582. return 0;
  583. }
  584. static int wl_get_frequency_offset(const char *ifname, int *buf)
  585. {
  586. /* Stub */
  587. *buf = 0;
  588. return -1;
  589. }
  590. const struct iwinfo_ops wl_ops = {
  591. .name = "wl",
  592. .probe = wl_probe,
  593. .channel = wl_get_channel,
  594. .center_chan1 = wl_get_center_chan1,
  595. .center_chan2 = wl_get_center_chan2,
  596. .frequency = wl_get_frequency,
  597. .frequency_offset = wl_get_frequency_offset,
  598. .txpower = wl_get_txpower,
  599. .txpower_offset = wl_get_txpower_offset,
  600. .bitrate = wl_get_bitrate,
  601. .signal = wl_get_signal,
  602. .noise = wl_get_noise,
  603. .quality = wl_get_quality,
  604. .quality_max = wl_get_quality_max,
  605. .mbssid_support = wl_get_mbssid_support,
  606. .hwmodelist = wl_get_hwmodelist,
  607. .htmodelist = wl_get_htmodelist,
  608. .mode = wl_get_mode,
  609. .ssid = wl_get_ssid,
  610. .bssid = wl_get_bssid,
  611. .country = wl_get_country,
  612. .hardware_id = wl_get_hardware_id,
  613. .hardware_name = wl_get_hardware_name,
  614. .encryption = wl_get_encryption,
  615. .phyname = wl_get_phyname,
  616. .assoclist = wl_get_assoclist,
  617. .txpwrlist = wl_get_txpwrlist,
  618. .scanlist = wl_get_scanlist,
  619. .freqlist = wl_get_freqlist,
  620. .countrylist = wl_get_countrylist,
  621. .close = wl_close
  622. };