iwinfo_lua.c 20 KB

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