iwinfo_wl.c 16 KB

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