Mirror of the official iwinfo project repository by OpenWrt https://git.openwrt.org/project/iwinfo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

958 lines
22 KiB

  1. /*
  2. * iwinfo - Wireless Information Library - Lua Bindings
  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. #include "iwinfo/lua.h"
  19. /* Determine type */
  20. static int iwinfo_L_type(lua_State *L)
  21. {
  22. const char *ifname = luaL_checkstring(L, 1);
  23. const char *type = iwinfo_type(ifname);
  24. if (type)
  25. lua_pushstring(L, type);
  26. else
  27. lua_pushnil(L);
  28. return 1;
  29. }
  30. /* Shutdown backends */
  31. static int iwinfo_L__gc(lua_State *L)
  32. {
  33. iwinfo_finish();
  34. return 0;
  35. }
  36. /*
  37. * Build a short textual description of the crypto info
  38. */
  39. static char * iwinfo_crypto_print_ciphers(int ciphers)
  40. {
  41. static char str[128] = { 0 };
  42. char *pos = str;
  43. if (ciphers & IWINFO_CIPHER_WEP40)
  44. pos += sprintf(pos, "WEP-40, ");
  45. if (ciphers & IWINFO_CIPHER_WEP104)
  46. pos += sprintf(pos, "WEP-104, ");
  47. if (ciphers & IWINFO_CIPHER_TKIP)
  48. pos += sprintf(pos, "TKIP, ");
  49. if (ciphers & IWINFO_CIPHER_CCMP)
  50. pos += sprintf(pos, "CCMP, ");
  51. if (ciphers & IWINFO_CIPHER_WRAP)
  52. pos += sprintf(pos, "WRAP, ");
  53. if (ciphers & IWINFO_CIPHER_AESOCB)
  54. pos += sprintf(pos, "AES-OCB, ");
  55. if (ciphers & IWINFO_CIPHER_CKIP)
  56. pos += sprintf(pos, "CKIP, ");
  57. if (!ciphers || (ciphers & IWINFO_CIPHER_NONE))
  58. pos += sprintf(pos, "NONE, ");
  59. *(pos - 2) = 0;
  60. return str;
  61. }
  62. static char * iwinfo_crypto_print_suites(int suites)
  63. {
  64. static char str[64] = { 0 };
  65. char *pos = str;
  66. if (suites & IWINFO_KMGMT_PSK)
  67. pos += sprintf(pos, "PSK/");
  68. if (suites & IWINFO_KMGMT_8021x)
  69. pos += sprintf(pos, "802.1X/");
  70. if (suites & IWINFO_KMGMT_SAE)
  71. pos += sprintf(pos, "SAE/");
  72. if (suites & IWINFO_KMGMT_OWE)
  73. pos += sprintf(pos, "OWE/");
  74. if (!suites || (suites & IWINFO_KMGMT_NONE))
  75. pos += sprintf(pos, "NONE/");
  76. *(pos - 1) = 0;
  77. return str;
  78. }
  79. static char * iwinfo_crypto_desc(struct iwinfo_crypto_entry *c)
  80. {
  81. static char desc[512] = { 0 };
  82. char *pos = desc;
  83. int i, n;
  84. if (c)
  85. {
  86. if (c->enabled)
  87. {
  88. /* WEP */
  89. if (c->auth_algs && !c->wpa_version)
  90. {
  91. if ((c->auth_algs & IWINFO_AUTH_OPEN) &&
  92. (c->auth_algs & IWINFO_AUTH_SHARED))
  93. {
  94. sprintf(desc, "WEP Open/Shared (%s)",
  95. iwinfo_crypto_print_ciphers(c->pair_ciphers));
  96. }
  97. else if (c->auth_algs & IWINFO_AUTH_OPEN)
  98. {
  99. sprintf(desc, "WEP Open System (%s)",
  100. iwinfo_crypto_print_ciphers(c->pair_ciphers));
  101. }
  102. else if (c->auth_algs & IWINFO_AUTH_SHARED)
  103. {
  104. sprintf(desc, "WEP Shared Auth (%s)",
  105. iwinfo_crypto_print_ciphers(c->pair_ciphers));
  106. }
  107. }
  108. /* WPA */
  109. else if (c->wpa_version)
  110. {
  111. for (i = 0, n = 0; i < 3; i++)
  112. if (c->wpa_version & (1 << i))
  113. n++;
  114. if (n > 1)
  115. pos += sprintf(pos, "mixed ");
  116. for (i = 0; i < 3; i++)
  117. if (c->wpa_version & (1 << i))
  118. if (i)
  119. pos += sprintf(pos, "WPA%d/", i + 1);
  120. else
  121. pos += sprintf(pos, "WPA/");
  122. pos--;
  123. sprintf(pos, " %s (%s)",
  124. iwinfo_crypto_print_suites(c->auth_suites),
  125. iwinfo_crypto_print_ciphers(
  126. c->pair_ciphers | c->group_ciphers));
  127. }
  128. else
  129. {
  130. sprintf(desc, "None");
  131. }
  132. }
  133. else
  134. {
  135. sprintf(desc, "None");
  136. }
  137. }
  138. else
  139. {
  140. sprintf(desc, "Unknown");
  141. }
  142. return desc;
  143. }
  144. /* Build Lua table from crypto data */
  145. static void iwinfo_L_cryptotable(lua_State *L, struct iwinfo_crypto_entry *c)
  146. {
  147. int i, j;
  148. lua_newtable(L);
  149. lua_pushboolean(L, c->enabled);
  150. lua_setfield(L, -2, "enabled");
  151. lua_pushstring(L, iwinfo_crypto_desc(c));
  152. lua_setfield(L, -2, "description");
  153. lua_pushboolean(L, (c->enabled && !c->wpa_version));
  154. lua_setfield(L, -2, "wep");
  155. lua_pushinteger(L, c->wpa_version);
  156. lua_setfield(L, -2, "wpa");
  157. lua_newtable(L);
  158. for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_CIPHER_NAMES); i++)
  159. {
  160. if (c->pair_ciphers & (1 << i))
  161. {
  162. lua_pushstring(L, IWINFO_CIPHER_NAMES[i]);
  163. lua_rawseti(L, -2, j++);
  164. }
  165. }
  166. lua_setfield(L, -2, "pair_ciphers");
  167. lua_newtable(L);
  168. for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_CIPHER_NAMES); i++)
  169. {
  170. if (c->group_ciphers & (1 << i))
  171. {
  172. lua_pushstring(L, IWINFO_CIPHER_NAMES[i]);
  173. lua_rawseti(L, -2, j++);
  174. }
  175. }
  176. lua_setfield(L, -2, "group_ciphers");
  177. lua_newtable(L);
  178. for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_KMGMT_NAMES); i++)
  179. {
  180. if (c->auth_suites & (1 << i))
  181. {
  182. lua_pushstring(L, IWINFO_KMGMT_NAMES[i]);
  183. lua_rawseti(L, -2, j++);
  184. }
  185. }
  186. lua_setfield(L, -2, "auth_suites");
  187. lua_newtable(L);
  188. for (i = 0, j = 1; i < ARRAY_SIZE(IWINFO_AUTH_NAMES); i++)
  189. {
  190. if (c->auth_algs & (1 << i))
  191. {
  192. lua_pushstring(L, IWINFO_AUTH_NAMES[i]);
  193. lua_rawseti(L, -2, j++);
  194. }
  195. }
  196. lua_setfield(L, -2, "auth_algs");
  197. }
  198. /* Wrapper for mode */
  199. static int iwinfo_L_mode(lua_State *L, int (*func)(const char *, int *))
  200. {
  201. int mode;
  202. const char *ifname = luaL_checkstring(L, 1);
  203. if ((*func)(ifname, &mode))
  204. mode = IWINFO_OPMODE_UNKNOWN;
  205. lua_pushstring(L, IWINFO_OPMODE_NAMES[mode]);
  206. return 1;
  207. }
  208. static void set_rateinfo(lua_State *L, struct iwinfo_rate_entry *r, bool rx)
  209. {
  210. lua_pushnumber(L, r->rate);
  211. lua_setfield(L, -2, rx ? "rx_rate" : "tx_rate");
  212. lua_pushboolean(L, r->is_ht);
  213. lua_setfield(L, -2, rx ? "rx_ht" : "tx_ht");
  214. lua_pushboolean(L, r->is_vht);
  215. lua_setfield(L, -2, rx ? "rx_vht" : "tx_vht");
  216. lua_pushnumber(L, r->mhz);
  217. lua_setfield(L, -2, rx ? "rx_mhz" : "tx_mhz");
  218. if (r->is_ht)
  219. {
  220. lua_pushboolean(L, r->is_40mhz);
  221. lua_setfield(L, -2, rx ? "rx_40mhz" : "tx_40mhz");
  222. lua_pushnumber(L, r->mcs);
  223. lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
  224. lua_pushboolean(L, r->is_short_gi);
  225. lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
  226. }
  227. else if (r->is_vht)
  228. {
  229. lua_pushnumber(L, r->mcs);
  230. lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
  231. lua_pushnumber(L, r->nss);
  232. lua_setfield(L, -2, rx ? "rx_nss" : "tx_nss");
  233. lua_pushboolean(L, r->is_short_gi);
  234. lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
  235. }
  236. }
  237. /* Wrapper for assoclist */
  238. static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
  239. {
  240. int i, len;
  241. char rv[IWINFO_BUFSIZE];
  242. char macstr[18];
  243. const char *ifname = luaL_checkstring(L, 1);
  244. struct iwinfo_assoclist_entry *e;
  245. lua_newtable(L);
  246. memset(rv, 0, sizeof(rv));
  247. if (!(*func)(ifname, rv, &len))
  248. {
  249. for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
  250. {
  251. e = (struct iwinfo_assoclist_entry *) &rv[i];
  252. sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
  253. e->mac[0], e->mac[1], e->mac[2],
  254. e->mac[3], e->mac[4], e->mac[5]);
  255. lua_newtable(L);
  256. lua_pushnumber(L, e->signal);
  257. lua_setfield(L, -2, "signal");
  258. lua_pushnumber(L, e->noise);
  259. lua_setfield(L, -2, "noise");
  260. lua_pushnumber(L, e->inactive);
  261. lua_setfield(L, -2, "inactive");
  262. lua_pushnumber(L, e->rx_packets);
  263. lua_setfield(L, -2, "rx_packets");
  264. lua_pushnumber(L, e->tx_packets);
  265. lua_setfield(L, -2, "tx_packets");
  266. set_rateinfo(L, &e->rx_rate, true);
  267. set_rateinfo(L, &e->tx_rate, false);
  268. if (e->thr) {
  269. lua_pushnumber(L, e->thr);
  270. lua_setfield(L, -2, "expected_throughput");
  271. }
  272. lua_setfield(L, -2, macstr);
  273. }
  274. }
  275. return 1;
  276. }
  277. /* Wrapper for tx power list */
  278. static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, int *))
  279. {
  280. int i, x, len;
  281. char rv[IWINFO_BUFSIZE];
  282. const char *ifname = luaL_checkstring(L, 1);
  283. struct iwinfo_txpwrlist_entry *e;
  284. memset(rv, 0, sizeof(rv));
  285. if (!(*func)(ifname, rv, &len))
  286. {
  287. lua_newtable(L);
  288. for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_txpwrlist_entry), x++)
  289. {
  290. e = (struct iwinfo_txpwrlist_entry *) &rv[i];
  291. lua_newtable(L);
  292. lua_pushnumber(L, e->mw);
  293. lua_setfield(L, -2, "mw");
  294. lua_pushnumber(L, e->dbm);
  295. lua_setfield(L, -2, "dbm");
  296. lua_rawseti(L, -2, x);
  297. }
  298. return 1;
  299. }
  300. return 0;
  301. }
  302. /* Wrapper for scan list */
  303. static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *))
  304. {
  305. int i, x, len = 0;
  306. char rv[IWINFO_BUFSIZE];
  307. char macstr[18];
  308. const char *ifname = luaL_checkstring(L, 1);
  309. struct iwinfo_scanlist_entry *e;
  310. lua_newtable(L);
  311. memset(rv, 0, sizeof(rv));
  312. if (!(*func)(ifname, rv, &len))
  313. {
  314. for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
  315. {
  316. e = (struct iwinfo_scanlist_entry *) &rv[i];
  317. lua_newtable(L);
  318. /* BSSID */
  319. sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
  320. e->mac[0], e->mac[1], e->mac[2],
  321. e->mac[3], e->mac[4], e->mac[5]);
  322. lua_pushstring(L, macstr);
  323. lua_setfield(L, -2, "bssid");
  324. /* ESSID */
  325. if (e->ssid[0])
  326. {
  327. lua_pushstring(L, (char *) e->ssid);
  328. lua_setfield(L, -2, "ssid");
  329. }
  330. /* Channel */
  331. lua_pushinteger(L, e->channel);
  332. lua_setfield(L, -2, "channel");
  333. /* Mode */
  334. lua_pushstring(L, IWINFO_OPMODE_NAMES[e->mode]);
  335. lua_setfield(L, -2, "mode");
  336. /* Quality, Signal */
  337. lua_pushinteger(L, e->quality);
  338. lua_setfield(L, -2, "quality");
  339. lua_pushinteger(L, e->quality_max);
  340. lua_setfield(L, -2, "quality_max");
  341. lua_pushnumber(L, (e->signal - 0x100));
  342. lua_setfield(L, -2, "signal");
  343. /* Crypto */
  344. iwinfo_L_cryptotable(L, &e->crypto);
  345. lua_setfield(L, -2, "encryption");
  346. lua_rawseti(L, -2, x);
  347. }
  348. }
  349. return 1;
  350. }
  351. /* Wrapper for frequency list */
  352. static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
  353. {
  354. int i, x, len;
  355. char rv[IWINFO_BUFSIZE];
  356. const char *ifname = luaL_checkstring(L, 1);
  357. struct iwinfo_freqlist_entry *e;
  358. lua_newtable(L);
  359. memset(rv, 0, sizeof(rv));
  360. if (!(*func)(ifname, rv, &len))
  361. {
  362. for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++)
  363. {
  364. e = (struct iwinfo_freqlist_entry *) &rv[i];
  365. lua_newtable(L);
  366. /* MHz */
  367. lua_pushinteger(L, e->mhz);
  368. lua_setfield(L, -2, "mhz");
  369. /* Channel */
  370. lua_pushinteger(L, e->channel);
  371. lua_setfield(L, -2, "channel");
  372. /* Restricted (DFS/TPC/Radar) */
  373. lua_pushboolean(L, e->restricted);
  374. lua_setfield(L, -2, "restricted");
  375. lua_rawseti(L, -2, x);
  376. }
  377. }
  378. return 1;
  379. }
  380. /* Wrapper for crypto settings */
  381. static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
  382. {
  383. const char *ifname = luaL_checkstring(L, 1);
  384. struct iwinfo_crypto_entry c = { 0 };
  385. if (!(*func)(ifname, (char *)&c))
  386. {
  387. iwinfo_L_cryptotable(L, &c);
  388. return 1;
  389. }
  390. lua_pushnil(L);
  391. return 1;
  392. }
  393. /* Wrapper for hwmode list */
  394. static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
  395. {
  396. const char *ifname = luaL_checkstring(L, 1);
  397. int hwmodes = 0;
  398. if (!(*func)(ifname, &hwmodes))
  399. {
  400. lua_newtable(L);
  401. lua_pushboolean(L, hwmodes & IWINFO_80211_A);
  402. lua_setfield(L, -2, "a");
  403. lua_pushboolean(L, hwmodes & IWINFO_80211_B);
  404. lua_setfield(L, -2, "b");
  405. lua_pushboolean(L, hwmodes & IWINFO_80211_G);
  406. lua_setfield(L, -2, "g");
  407. lua_pushboolean(L, hwmodes & IWINFO_80211_N);
  408. lua_setfield(L, -2, "n");
  409. lua_pushboolean(L, hwmodes & IWINFO_80211_AC);
  410. lua_setfield(L, -2, "ac");
  411. lua_pushboolean(L, hwmodes & IWINFO_80211_AD);
  412. lua_setfield(L, -2, "ad");
  413. return 1;
  414. }
  415. lua_pushnil(L);
  416. return 1;
  417. }
  418. /* Wrapper for htmode list */
  419. static int iwinfo_L_htmodelist(lua_State *L, int (*func)(const char *, int *))
  420. {
  421. const char *ifname = luaL_checkstring(L, 1);
  422. int i, htmodes = 0;
  423. if (!(*func)(ifname, &htmodes))
  424. {
  425. lua_newtable(L);
  426. for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
  427. {
  428. lua_pushboolean(L, htmodes & (1 << i));
  429. lua_setfield(L, -2, IWINFO_HTMODE_NAMES[i]);
  430. }
  431. return 1;
  432. }
  433. lua_pushnil(L);
  434. return 1;
  435. }
  436. /* Wrapper for mbssid_support */
  437. static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
  438. {
  439. const char *ifname = luaL_checkstring(L, 1);
  440. int support = 0;
  441. if (!(*func)(ifname, &support))
  442. {
  443. lua_pushboolean(L, support);
  444. return 1;
  445. }
  446. lua_pushnil(L);
  447. return 1;
  448. }
  449. /* Wrapper for hardware_id */
  450. static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
  451. {
  452. const char *ifname = luaL_checkstring(L, 1);
  453. struct iwinfo_hardware_id ids;
  454. if (!(*func)(ifname, (char *)&ids))
  455. {
  456. lua_newtable(L);
  457. lua_pushnumber(L, ids.vendor_id);
  458. lua_setfield(L, -2, "vendor_id");
  459. lua_pushnumber(L, ids.device_id);
  460. lua_setfield(L, -2, "device_id");
  461. lua_pushnumber(L, ids.subsystem_vendor_id);
  462. lua_setfield(L, -2, "subsystem_vendor_id");
  463. lua_pushnumber(L, ids.subsystem_device_id);
  464. lua_setfield(L, -2, "subsystem_device_id");
  465. }
  466. else
  467. {
  468. lua_pushnil(L);
  469. }
  470. return 1;
  471. }
  472. /* Wrapper for country list */
  473. static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
  474. {
  475. int i;
  476. struct iwinfo_country_entry *c;
  477. for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
  478. {
  479. c = (struct iwinfo_country_entry *) &buf[i];
  480. if (c->iso3166 == iso3166)
  481. return c->ccode;
  482. }
  483. return NULL;
  484. }
  485. static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
  486. {
  487. int len, i;
  488. char rv[IWINFO_BUFSIZE], alpha2[3];
  489. char *ccode;
  490. const char *ifname = luaL_checkstring(L, 1);
  491. const struct iwinfo_iso3166_label *l;
  492. lua_newtable(L);
  493. memset(rv, 0, sizeof(rv));
  494. if (!(*func)(ifname, rv, &len))
  495. {
  496. for (l = IWINFO_ISO3166_NAMES, i = 1; l->iso3166; l++)
  497. {
  498. if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
  499. {
  500. sprintf(alpha2, "%c%c",
  501. (l->iso3166 / 256), (l->iso3166 % 256));
  502. lua_newtable(L);
  503. lua_pushstring(L, alpha2);
  504. lua_setfield(L, -2, "alpha2");
  505. lua_pushstring(L, ccode);
  506. lua_setfield(L, -2, "ccode");
  507. lua_pushstring(L, l->name);
  508. lua_setfield(L, -2, "name");
  509. lua_rawseti(L, -2, i++);
  510. }
  511. }
  512. }
  513. return 1;
  514. }
  515. #ifdef USE_WL
  516. /* Broadcom */
  517. LUA_WRAP_INT_OP(wl,channel)
  518. LUA_WRAP_INT_OP(wl,frequency)
  519. LUA_WRAP_INT_OP(wl,frequency_offset)
  520. LUA_WRAP_INT_OP(wl,txpower)
  521. LUA_WRAP_INT_OP(wl,txpower_offset)
  522. LUA_WRAP_INT_OP(wl,bitrate)
  523. LUA_WRAP_INT_OP(wl,signal)
  524. LUA_WRAP_INT_OP(wl,noise)
  525. LUA_WRAP_INT_OP(wl,quality)
  526. LUA_WRAP_INT_OP(wl,quality_max)
  527. LUA_WRAP_STRING_OP(wl,ssid)
  528. LUA_WRAP_STRING_OP(wl,bssid)
  529. LUA_WRAP_STRING_OP(wl,country)
  530. LUA_WRAP_STRING_OP(wl,hardware_name)
  531. LUA_WRAP_STRING_OP(wl,phyname)
  532. LUA_WRAP_STRUCT_OP(wl,mode)
  533. LUA_WRAP_STRUCT_OP(wl,assoclist)
  534. LUA_WRAP_STRUCT_OP(wl,txpwrlist)
  535. LUA_WRAP_STRUCT_OP(wl,scanlist)
  536. LUA_WRAP_STRUCT_OP(wl,freqlist)
  537. LUA_WRAP_STRUCT_OP(wl,countrylist)
  538. LUA_WRAP_STRUCT_OP(wl,hwmodelist)
  539. LUA_WRAP_STRUCT_OP(wl,htmodelist)
  540. LUA_WRAP_STRUCT_OP(wl,encryption)
  541. LUA_WRAP_STRUCT_OP(wl,mbssid_support)
  542. LUA_WRAP_STRUCT_OP(wl,hardware_id)
  543. #endif
  544. #ifdef USE_MADWIFI
  545. /* Madwifi */
  546. LUA_WRAP_INT_OP(madwifi,channel)
  547. LUA_WRAP_INT_OP(madwifi,frequency)
  548. LUA_WRAP_INT_OP(madwifi,frequency_offset)
  549. LUA_WRAP_INT_OP(madwifi,txpower)
  550. LUA_WRAP_INT_OP(madwifi,txpower_offset)
  551. LUA_WRAP_INT_OP(madwifi,bitrate)
  552. LUA_WRAP_INT_OP(madwifi,signal)
  553. LUA_WRAP_INT_OP(madwifi,noise)
  554. LUA_WRAP_INT_OP(madwifi,quality)
  555. LUA_WRAP_INT_OP(madwifi,quality_max)
  556. LUA_WRAP_STRING_OP(madwifi,ssid)
  557. LUA_WRAP_STRING_OP(madwifi,bssid)
  558. LUA_WRAP_STRING_OP(madwifi,country)
  559. LUA_WRAP_STRING_OP(madwifi,hardware_name)
  560. LUA_WRAP_STRING_OP(madwifi,phyname)
  561. LUA_WRAP_STRUCT_OP(madwifi,mode)
  562. LUA_WRAP_STRUCT_OP(madwifi,assoclist)
  563. LUA_WRAP_STRUCT_OP(madwifi,txpwrlist)
  564. LUA_WRAP_STRUCT_OP(madwifi,scanlist)
  565. LUA_WRAP_STRUCT_OP(madwifi,freqlist)
  566. LUA_WRAP_STRUCT_OP(madwifi,countrylist)
  567. LUA_WRAP_STRUCT_OP(madwifi,hwmodelist)
  568. LUA_WRAP_STRUCT_OP(madwifi,htmodelist)
  569. LUA_WRAP_STRUCT_OP(madwifi,encryption)
  570. LUA_WRAP_STRUCT_OP(madwifi,mbssid_support)
  571. LUA_WRAP_STRUCT_OP(madwifi,hardware_id)
  572. #endif
  573. #ifdef USE_NL80211
  574. /* NL80211 */
  575. LUA_WRAP_INT_OP(nl80211,channel)
  576. LUA_WRAP_INT_OP(nl80211,frequency)
  577. LUA_WRAP_INT_OP(nl80211,frequency_offset)
  578. LUA_WRAP_INT_OP(nl80211,txpower)
  579. LUA_WRAP_INT_OP(nl80211,txpower_offset)
  580. LUA_WRAP_INT_OP(nl80211,bitrate)
  581. LUA_WRAP_INT_OP(nl80211,signal)
  582. LUA_WRAP_INT_OP(nl80211,noise)
  583. LUA_WRAP_INT_OP(nl80211,quality)
  584. LUA_WRAP_INT_OP(nl80211,quality_max)
  585. LUA_WRAP_STRING_OP(nl80211,ssid)
  586. LUA_WRAP_STRING_OP(nl80211,bssid)
  587. LUA_WRAP_STRING_OP(nl80211,country)
  588. LUA_WRAP_STRING_OP(nl80211,hardware_name)
  589. LUA_WRAP_STRING_OP(nl80211,phyname)
  590. LUA_WRAP_STRUCT_OP(nl80211,mode)
  591. LUA_WRAP_STRUCT_OP(nl80211,assoclist)
  592. LUA_WRAP_STRUCT_OP(nl80211,txpwrlist)
  593. LUA_WRAP_STRUCT_OP(nl80211,scanlist)
  594. LUA_WRAP_STRUCT_OP(nl80211,freqlist)
  595. LUA_WRAP_STRUCT_OP(nl80211,countrylist)
  596. LUA_WRAP_STRUCT_OP(nl80211,hwmodelist)
  597. LUA_WRAP_STRUCT_OP(nl80211,htmodelist)
  598. LUA_WRAP_STRUCT_OP(nl80211,encryption)
  599. LUA_WRAP_STRUCT_OP(nl80211,mbssid_support)
  600. LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
  601. #endif
  602. /* Wext */
  603. LUA_WRAP_INT_OP(wext,channel)
  604. LUA_WRAP_INT_OP(wext,frequency)
  605. LUA_WRAP_INT_OP(wext,frequency_offset)
  606. LUA_WRAP_INT_OP(wext,txpower)
  607. LUA_WRAP_INT_OP(wext,txpower_offset)
  608. LUA_WRAP_INT_OP(wext,bitrate)
  609. LUA_WRAP_INT_OP(wext,signal)
  610. LUA_WRAP_INT_OP(wext,noise)
  611. LUA_WRAP_INT_OP(wext,quality)
  612. LUA_WRAP_INT_OP(wext,quality_max)
  613. LUA_WRAP_STRING_OP(wext,ssid)
  614. LUA_WRAP_STRING_OP(wext,bssid)
  615. LUA_WRAP_STRING_OP(wext,country)
  616. LUA_WRAP_STRING_OP(wext,hardware_name)
  617. LUA_WRAP_STRING_OP(wext,phyname)
  618. LUA_WRAP_STRUCT_OP(wext,mode)
  619. LUA_WRAP_STRUCT_OP(wext,assoclist)
  620. LUA_WRAP_STRUCT_OP(wext,txpwrlist)
  621. LUA_WRAP_STRUCT_OP(wext,scanlist)
  622. LUA_WRAP_STRUCT_OP(wext,freqlist)
  623. LUA_WRAP_STRUCT_OP(wext,countrylist)
  624. LUA_WRAP_STRUCT_OP(wext,hwmodelist)
  625. LUA_WRAP_STRUCT_OP(wext,htmodelist)
  626. LUA_WRAP_STRUCT_OP(wext,encryption)
  627. LUA_WRAP_STRUCT_OP(wext,mbssid_support)
  628. LUA_WRAP_STRUCT_OP(wext,hardware_id)
  629. #ifdef USE_WL
  630. /* Broadcom table */
  631. static const luaL_reg R_wl[] = {
  632. LUA_REG(wl,channel),
  633. LUA_REG(wl,frequency),
  634. LUA_REG(wl,frequency_offset),
  635. LUA_REG(wl,txpower),
  636. LUA_REG(wl,txpower_offset),
  637. LUA_REG(wl,bitrate),
  638. LUA_REG(wl,signal),
  639. LUA_REG(wl,noise),
  640. LUA_REG(wl,quality),
  641. LUA_REG(wl,quality_max),
  642. LUA_REG(wl,mode),
  643. LUA_REG(wl,ssid),
  644. LUA_REG(wl,bssid),
  645. LUA_REG(wl,country),
  646. LUA_REG(wl,assoclist),
  647. LUA_REG(wl,txpwrlist),
  648. LUA_REG(wl,scanlist),
  649. LUA_REG(wl,freqlist),
  650. LUA_REG(wl,countrylist),
  651. LUA_REG(wl,hwmodelist),
  652. LUA_REG(wl,htmodelist),
  653. LUA_REG(wl,encryption),
  654. LUA_REG(wl,mbssid_support),
  655. LUA_REG(wl,hardware_id),
  656. LUA_REG(wl,hardware_name),
  657. LUA_REG(wl,phyname),
  658. { NULL, NULL }
  659. };
  660. #endif
  661. #ifdef USE_MADWIFI
  662. /* Madwifi table */
  663. static const luaL_reg R_madwifi[] = {
  664. LUA_REG(madwifi,channel),
  665. LUA_REG(madwifi,frequency),
  666. LUA_REG(madwifi,frequency_offset),
  667. LUA_REG(madwifi,txpower),
  668. LUA_REG(madwifi,txpower_offset),
  669. LUA_REG(madwifi,bitrate),
  670. LUA_REG(madwifi,signal),
  671. LUA_REG(madwifi,noise),
  672. LUA_REG(madwifi,quality),
  673. LUA_REG(madwifi,quality_max),
  674. LUA_REG(madwifi,mode),
  675. LUA_REG(madwifi,ssid),
  676. LUA_REG(madwifi,bssid),
  677. LUA_REG(madwifi,country),
  678. LUA_REG(madwifi,assoclist),
  679. LUA_REG(madwifi,txpwrlist),
  680. LUA_REG(madwifi,scanlist),
  681. LUA_REG(madwifi,freqlist),
  682. LUA_REG(madwifi,countrylist),
  683. LUA_REG(madwifi,hwmodelist),
  684. LUA_REG(madwifi,htmodelist),
  685. LUA_REG(madwifi,encryption),
  686. LUA_REG(madwifi,mbssid_support),
  687. LUA_REG(madwifi,hardware_id),
  688. LUA_REG(madwifi,hardware_name),
  689. LUA_REG(madwifi,phyname),
  690. { NULL, NULL }
  691. };
  692. #endif
  693. #ifdef USE_NL80211
  694. /* NL80211 table */
  695. static const luaL_reg R_nl80211[] = {
  696. LUA_REG(nl80211,channel),
  697. LUA_REG(nl80211,frequency),
  698. LUA_REG(nl80211,frequency_offset),
  699. LUA_REG(nl80211,txpower),
  700. LUA_REG(nl80211,txpower_offset),
  701. LUA_REG(nl80211,bitrate),
  702. LUA_REG(nl80211,signal),
  703. LUA_REG(nl80211,noise),
  704. LUA_REG(nl80211,quality),
  705. LUA_REG(nl80211,quality_max),
  706. LUA_REG(nl80211,mode),
  707. LUA_REG(nl80211,ssid),
  708. LUA_REG(nl80211,bssid),
  709. LUA_REG(nl80211,country),
  710. LUA_REG(nl80211,assoclist),
  711. LUA_REG(nl80211,txpwrlist),
  712. LUA_REG(nl80211,scanlist),
  713. LUA_REG(nl80211,freqlist),
  714. LUA_REG(nl80211,countrylist),
  715. LUA_REG(nl80211,hwmodelist),
  716. LUA_REG(nl80211,htmodelist),
  717. LUA_REG(nl80211,encryption),
  718. LUA_REG(nl80211,mbssid_support),
  719. LUA_REG(nl80211,hardware_id),
  720. LUA_REG(nl80211,hardware_name),
  721. LUA_REG(nl80211,phyname),
  722. { NULL, NULL }
  723. };
  724. #endif
  725. /* Wext table */
  726. static const luaL_reg R_wext[] = {
  727. LUA_REG(wext,channel),
  728. LUA_REG(wext,frequency),
  729. LUA_REG(wext,frequency_offset),
  730. LUA_REG(wext,txpower),
  731. LUA_REG(wext,txpower_offset),
  732. LUA_REG(wext,bitrate),
  733. LUA_REG(wext,signal),
  734. LUA_REG(wext,noise),
  735. LUA_REG(wext,quality),
  736. LUA_REG(wext,quality_max),
  737. LUA_REG(wext,mode),
  738. LUA_REG(wext,ssid),
  739. LUA_REG(wext,bssid),
  740. LUA_REG(wext,country),
  741. LUA_REG(wext,assoclist),
  742. LUA_REG(wext,txpwrlist),
  743. LUA_REG(wext,scanlist),
  744. LUA_REG(wext,freqlist),
  745. LUA_REG(wext,countrylist),
  746. LUA_REG(wext,hwmodelist),
  747. LUA_REG(wext,htmodelist),
  748. LUA_REG(wext,encryption),
  749. LUA_REG(wext,mbssid_support),
  750. LUA_REG(wext,hardware_id),
  751. LUA_REG(wext,hardware_name),
  752. LUA_REG(wext,phyname),
  753. { NULL, NULL }
  754. };
  755. /* Common */
  756. static const luaL_reg R_common[] = {
  757. { "type", iwinfo_L_type },
  758. { "__gc", iwinfo_L__gc },
  759. { NULL, NULL }
  760. };
  761. LUALIB_API int luaopen_iwinfo(lua_State *L) {
  762. luaL_register(L, IWINFO_META, R_common);
  763. #ifdef USE_WL
  764. luaL_newmetatable(L, IWINFO_WL_META);
  765. luaL_register(L, NULL, R_common);
  766. luaL_register(L, NULL, R_wl);
  767. lua_pushvalue(L, -1);
  768. lua_setfield(L, -2, "__index");
  769. lua_setfield(L, -2, "wl");
  770. #endif
  771. #ifdef USE_MADWIFI
  772. luaL_newmetatable(L, IWINFO_MADWIFI_META);
  773. luaL_register(L, NULL, R_common);
  774. luaL_register(L, NULL, R_madwifi);
  775. lua_pushvalue(L, -1);
  776. lua_setfield(L, -2, "__index");
  777. lua_setfield(L, -2, "madwifi");
  778. #endif
  779. #ifdef USE_NL80211
  780. luaL_newmetatable(L, IWINFO_NL80211_META);
  781. luaL_register(L, NULL, R_common);
  782. luaL_register(L, NULL, R_nl80211);
  783. lua_pushvalue(L, -1);
  784. lua_setfield(L, -2, "__index");
  785. lua_setfield(L, -2, "nl80211");
  786. #endif
  787. luaL_newmetatable(L, IWINFO_WEXT_META);
  788. luaL_register(L, NULL, R_common);
  789. luaL_register(L, NULL, R_wext);
  790. lua_pushvalue(L, -1);
  791. lua_setfield(L, -2, "__index");
  792. lua_setfield(L, -2, "wext");
  793. return 1;
  794. }