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