iwinfo: add basic IEEE 802.11ax support
[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 lua_pushboolean(L, hwmodes & IWINFO_80211_AX);
534 lua_setfield(L, -2, "ax");
535
536 return 1;
537 }
538
539 lua_pushnil(L);
540 return 1;
541 }
542
543 /* Wrapper for htmode list */
544 static int iwinfo_L_htmodelist(lua_State *L, int (*func)(const char *, int *))
545 {
546 const char *ifname = luaL_checkstring(L, 1);
547 int i, htmodes = 0;
548
549 if (!(*func)(ifname, &htmodes))
550 {
551 lua_newtable(L);
552
553 for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
554 {
555 lua_pushboolean(L, htmodes & (1 << i));
556 lua_setfield(L, -2, IWINFO_HTMODE_NAMES[i]);
557 }
558
559 return 1;
560 }
561
562 lua_pushnil(L);
563 return 1;
564 }
565
566 /* Wrapper for mbssid_support */
567 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
568 {
569 const char *ifname = luaL_checkstring(L, 1);
570 int support = 0;
571
572 if (!(*func)(ifname, &support))
573 {
574 lua_pushboolean(L, support);
575 return 1;
576 }
577
578 lua_pushnil(L);
579 return 1;
580 }
581
582 /* Wrapper for hardware_id */
583 static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
584 {
585 const char *ifname = luaL_checkstring(L, 1);
586 struct iwinfo_hardware_id ids;
587
588 if (!(*func)(ifname, (char *)&ids))
589 {
590 lua_newtable(L);
591
592 lua_pushnumber(L, ids.vendor_id);
593 lua_setfield(L, -2, "vendor_id");
594
595 lua_pushnumber(L, ids.device_id);
596 lua_setfield(L, -2, "device_id");
597
598 lua_pushnumber(L, ids.subsystem_vendor_id);
599 lua_setfield(L, -2, "subsystem_vendor_id");
600
601 lua_pushnumber(L, ids.subsystem_device_id);
602 lua_setfield(L, -2, "subsystem_device_id");
603 }
604 else
605 {
606 lua_pushnil(L);
607 }
608
609 return 1;
610 }
611
612 /* Wrapper for country list */
613 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
614 {
615 int i;
616 struct iwinfo_country_entry *c;
617
618 for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
619 {
620 c = (struct iwinfo_country_entry *) &buf[i];
621
622 if (c->iso3166 == iso3166)
623 return c->ccode;
624 }
625
626 return NULL;
627 }
628
629 static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
630 {
631 int len, i;
632 char rv[IWINFO_BUFSIZE], alpha2[3];
633 char *ccode;
634 const char *ifname = luaL_checkstring(L, 1);
635 const struct iwinfo_iso3166_label *l;
636
637 lua_newtable(L);
638 memset(rv, 0, sizeof(rv));
639
640 if (!(*func)(ifname, rv, &len))
641 {
642 for (l = IWINFO_ISO3166_NAMES, i = 1; l->iso3166; l++)
643 {
644 if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
645 {
646 sprintf(alpha2, "%c%c",
647 (l->iso3166 / 256), (l->iso3166 % 256));
648
649 lua_newtable(L);
650
651 lua_pushstring(L, alpha2);
652 lua_setfield(L, -2, "alpha2");
653
654 lua_pushstring(L, ccode);
655 lua_setfield(L, -2, "ccode");
656
657 lua_pushstring(L, l->name);
658 lua_setfield(L, -2, "name");
659
660 lua_rawseti(L, -2, i++);
661 }
662 }
663 }
664
665 return 1;
666 }
667
668
669 #ifdef USE_WL
670 /* Broadcom */
671 LUA_WRAP_INT_OP(wl,channel)
672 LUA_WRAP_INT_OP(wl,frequency)
673 LUA_WRAP_INT_OP(wl,frequency_offset)
674 LUA_WRAP_INT_OP(wl,txpower)
675 LUA_WRAP_INT_OP(wl,txpower_offset)
676 LUA_WRAP_INT_OP(wl,bitrate)
677 LUA_WRAP_INT_OP(wl,signal)
678 LUA_WRAP_INT_OP(wl,noise)
679 LUA_WRAP_INT_OP(wl,quality)
680 LUA_WRAP_INT_OP(wl,quality_max)
681 LUA_WRAP_STRING_OP(wl,ssid)
682 LUA_WRAP_STRING_OP(wl,bssid)
683 LUA_WRAP_STRING_OP(wl,country)
684 LUA_WRAP_STRING_OP(wl,hardware_name)
685 LUA_WRAP_STRING_OP(wl,phyname)
686 LUA_WRAP_STRUCT_OP(wl,mode)
687 LUA_WRAP_STRUCT_OP(wl,assoclist)
688 LUA_WRAP_STRUCT_OP(wl,txpwrlist)
689 LUA_WRAP_STRUCT_OP(wl,scanlist)
690 LUA_WRAP_STRUCT_OP(wl,freqlist)
691 LUA_WRAP_STRUCT_OP(wl,countrylist)
692 LUA_WRAP_STRUCT_OP(wl,hwmodelist)
693 LUA_WRAP_STRUCT_OP(wl,htmodelist)
694 LUA_WRAP_STRUCT_OP(wl,encryption)
695 LUA_WRAP_STRUCT_OP(wl,mbssid_support)
696 LUA_WRAP_STRUCT_OP(wl,hardware_id)
697 #endif
698
699 #ifdef USE_MADWIFI
700 /* Madwifi */
701 LUA_WRAP_INT_OP(madwifi,channel)
702 LUA_WRAP_INT_OP(madwifi,frequency)
703 LUA_WRAP_INT_OP(madwifi,frequency_offset)
704 LUA_WRAP_INT_OP(madwifi,txpower)
705 LUA_WRAP_INT_OP(madwifi,txpower_offset)
706 LUA_WRAP_INT_OP(madwifi,bitrate)
707 LUA_WRAP_INT_OP(madwifi,signal)
708 LUA_WRAP_INT_OP(madwifi,noise)
709 LUA_WRAP_INT_OP(madwifi,quality)
710 LUA_WRAP_INT_OP(madwifi,quality_max)
711 LUA_WRAP_STRING_OP(madwifi,ssid)
712 LUA_WRAP_STRING_OP(madwifi,bssid)
713 LUA_WRAP_STRING_OP(madwifi,country)
714 LUA_WRAP_STRING_OP(madwifi,hardware_name)
715 LUA_WRAP_STRING_OP(madwifi,phyname)
716 LUA_WRAP_STRUCT_OP(madwifi,mode)
717 LUA_WRAP_STRUCT_OP(madwifi,assoclist)
718 LUA_WRAP_STRUCT_OP(madwifi,txpwrlist)
719 LUA_WRAP_STRUCT_OP(madwifi,scanlist)
720 LUA_WRAP_STRUCT_OP(madwifi,freqlist)
721 LUA_WRAP_STRUCT_OP(madwifi,countrylist)
722 LUA_WRAP_STRUCT_OP(madwifi,hwmodelist)
723 LUA_WRAP_STRUCT_OP(madwifi,htmodelist)
724 LUA_WRAP_STRUCT_OP(madwifi,encryption)
725 LUA_WRAP_STRUCT_OP(madwifi,mbssid_support)
726 LUA_WRAP_STRUCT_OP(madwifi,hardware_id)
727 #endif
728
729 #ifdef USE_NL80211
730 /* NL80211 */
731 LUA_WRAP_INT_OP(nl80211,channel)
732 LUA_WRAP_INT_OP(nl80211,frequency)
733 LUA_WRAP_INT_OP(nl80211,frequency_offset)
734 LUA_WRAP_INT_OP(nl80211,txpower)
735 LUA_WRAP_INT_OP(nl80211,txpower_offset)
736 LUA_WRAP_INT_OP(nl80211,bitrate)
737 LUA_WRAP_INT_OP(nl80211,signal)
738 LUA_WRAP_INT_OP(nl80211,noise)
739 LUA_WRAP_INT_OP(nl80211,quality)
740 LUA_WRAP_INT_OP(nl80211,quality_max)
741 LUA_WRAP_STRING_OP(nl80211,ssid)
742 LUA_WRAP_STRING_OP(nl80211,bssid)
743 LUA_WRAP_STRING_OP(nl80211,country)
744 LUA_WRAP_STRING_OP(nl80211,hardware_name)
745 LUA_WRAP_STRING_OP(nl80211,phyname)
746 LUA_WRAP_STRUCT_OP(nl80211,mode)
747 LUA_WRAP_STRUCT_OP(nl80211,assoclist)
748 LUA_WRAP_STRUCT_OP(nl80211,txpwrlist)
749 LUA_WRAP_STRUCT_OP(nl80211,scanlist)
750 LUA_WRAP_STRUCT_OP(nl80211,freqlist)
751 LUA_WRAP_STRUCT_OP(nl80211,countrylist)
752 LUA_WRAP_STRUCT_OP(nl80211,hwmodelist)
753 LUA_WRAP_STRUCT_OP(nl80211,htmodelist)
754 LUA_WRAP_STRUCT_OP(nl80211,encryption)
755 LUA_WRAP_STRUCT_OP(nl80211,mbssid_support)
756 LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
757 #endif
758
759 /* Wext */
760 LUA_WRAP_INT_OP(wext,channel)
761 LUA_WRAP_INT_OP(wext,frequency)
762 LUA_WRAP_INT_OP(wext,frequency_offset)
763 LUA_WRAP_INT_OP(wext,txpower)
764 LUA_WRAP_INT_OP(wext,txpower_offset)
765 LUA_WRAP_INT_OP(wext,bitrate)
766 LUA_WRAP_INT_OP(wext,signal)
767 LUA_WRAP_INT_OP(wext,noise)
768 LUA_WRAP_INT_OP(wext,quality)
769 LUA_WRAP_INT_OP(wext,quality_max)
770 LUA_WRAP_STRING_OP(wext,ssid)
771 LUA_WRAP_STRING_OP(wext,bssid)
772 LUA_WRAP_STRING_OP(wext,country)
773 LUA_WRAP_STRING_OP(wext,hardware_name)
774 LUA_WRAP_STRING_OP(wext,phyname)
775 LUA_WRAP_STRUCT_OP(wext,mode)
776 LUA_WRAP_STRUCT_OP(wext,assoclist)
777 LUA_WRAP_STRUCT_OP(wext,txpwrlist)
778 LUA_WRAP_STRUCT_OP(wext,scanlist)
779 LUA_WRAP_STRUCT_OP(wext,freqlist)
780 LUA_WRAP_STRUCT_OP(wext,countrylist)
781 LUA_WRAP_STRUCT_OP(wext,hwmodelist)
782 LUA_WRAP_STRUCT_OP(wext,htmodelist)
783 LUA_WRAP_STRUCT_OP(wext,encryption)
784 LUA_WRAP_STRUCT_OP(wext,mbssid_support)
785 LUA_WRAP_STRUCT_OP(wext,hardware_id)
786
787 #ifdef USE_WL
788 /* Broadcom table */
789 static const luaL_reg R_wl[] = {
790 LUA_REG(wl,channel),
791 LUA_REG(wl,frequency),
792 LUA_REG(wl,frequency_offset),
793 LUA_REG(wl,txpower),
794 LUA_REG(wl,txpower_offset),
795 LUA_REG(wl,bitrate),
796 LUA_REG(wl,signal),
797 LUA_REG(wl,noise),
798 LUA_REG(wl,quality),
799 LUA_REG(wl,quality_max),
800 LUA_REG(wl,mode),
801 LUA_REG(wl,ssid),
802 LUA_REG(wl,bssid),
803 LUA_REG(wl,country),
804 LUA_REG(wl,assoclist),
805 LUA_REG(wl,txpwrlist),
806 LUA_REG(wl,scanlist),
807 LUA_REG(wl,freqlist),
808 LUA_REG(wl,countrylist),
809 LUA_REG(wl,hwmodelist),
810 LUA_REG(wl,htmodelist),
811 LUA_REG(wl,encryption),
812 LUA_REG(wl,mbssid_support),
813 LUA_REG(wl,hardware_id),
814 LUA_REG(wl,hardware_name),
815 LUA_REG(wl,phyname),
816 { NULL, NULL }
817 };
818 #endif
819
820 #ifdef USE_MADWIFI
821 /* Madwifi table */
822 static const luaL_reg R_madwifi[] = {
823 LUA_REG(madwifi,channel),
824 LUA_REG(madwifi,frequency),
825 LUA_REG(madwifi,frequency_offset),
826 LUA_REG(madwifi,txpower),
827 LUA_REG(madwifi,txpower_offset),
828 LUA_REG(madwifi,bitrate),
829 LUA_REG(madwifi,signal),
830 LUA_REG(madwifi,noise),
831 LUA_REG(madwifi,quality),
832 LUA_REG(madwifi,quality_max),
833 LUA_REG(madwifi,mode),
834 LUA_REG(madwifi,ssid),
835 LUA_REG(madwifi,bssid),
836 LUA_REG(madwifi,country),
837 LUA_REG(madwifi,assoclist),
838 LUA_REG(madwifi,txpwrlist),
839 LUA_REG(madwifi,scanlist),
840 LUA_REG(madwifi,freqlist),
841 LUA_REG(madwifi,countrylist),
842 LUA_REG(madwifi,hwmodelist),
843 LUA_REG(madwifi,htmodelist),
844 LUA_REG(madwifi,encryption),
845 LUA_REG(madwifi,mbssid_support),
846 LUA_REG(madwifi,hardware_id),
847 LUA_REG(madwifi,hardware_name),
848 LUA_REG(madwifi,phyname),
849 { NULL, NULL }
850 };
851 #endif
852
853 #ifdef USE_NL80211
854 /* NL80211 table */
855 static const luaL_reg R_nl80211[] = {
856 LUA_REG(nl80211,channel),
857 LUA_REG(nl80211,frequency),
858 LUA_REG(nl80211,frequency_offset),
859 LUA_REG(nl80211,txpower),
860 LUA_REG(nl80211,txpower_offset),
861 LUA_REG(nl80211,bitrate),
862 LUA_REG(nl80211,signal),
863 LUA_REG(nl80211,noise),
864 LUA_REG(nl80211,quality),
865 LUA_REG(nl80211,quality_max),
866 LUA_REG(nl80211,mode),
867 LUA_REG(nl80211,ssid),
868 LUA_REG(nl80211,bssid),
869 LUA_REG(nl80211,country),
870 LUA_REG(nl80211,assoclist),
871 LUA_REG(nl80211,txpwrlist),
872 LUA_REG(nl80211,scanlist),
873 LUA_REG(nl80211,freqlist),
874 LUA_REG(nl80211,countrylist),
875 LUA_REG(nl80211,hwmodelist),
876 LUA_REG(nl80211,htmodelist),
877 LUA_REG(nl80211,encryption),
878 LUA_REG(nl80211,mbssid_support),
879 LUA_REG(nl80211,hardware_id),
880 LUA_REG(nl80211,hardware_name),
881 LUA_REG(nl80211,phyname),
882 { NULL, NULL }
883 };
884 #endif
885
886 /* Wext table */
887 static const luaL_reg R_wext[] = {
888 LUA_REG(wext,channel),
889 LUA_REG(wext,frequency),
890 LUA_REG(wext,frequency_offset),
891 LUA_REG(wext,txpower),
892 LUA_REG(wext,txpower_offset),
893 LUA_REG(wext,bitrate),
894 LUA_REG(wext,signal),
895 LUA_REG(wext,noise),
896 LUA_REG(wext,quality),
897 LUA_REG(wext,quality_max),
898 LUA_REG(wext,mode),
899 LUA_REG(wext,ssid),
900 LUA_REG(wext,bssid),
901 LUA_REG(wext,country),
902 LUA_REG(wext,assoclist),
903 LUA_REG(wext,txpwrlist),
904 LUA_REG(wext,scanlist),
905 LUA_REG(wext,freqlist),
906 LUA_REG(wext,countrylist),
907 LUA_REG(wext,hwmodelist),
908 LUA_REG(wext,htmodelist),
909 LUA_REG(wext,encryption),
910 LUA_REG(wext,mbssid_support),
911 LUA_REG(wext,hardware_id),
912 LUA_REG(wext,hardware_name),
913 LUA_REG(wext,phyname),
914 { NULL, NULL }
915 };
916
917 /* Common */
918 static const luaL_reg R_common[] = {
919 { "type", iwinfo_L_type },
920 { "__gc", iwinfo_L__gc },
921 { NULL, NULL }
922 };
923
924
925 LUALIB_API int luaopen_iwinfo(lua_State *L) {
926 luaL_register(L, IWINFO_META, R_common);
927
928 #ifdef USE_WL
929 luaL_newmetatable(L, IWINFO_WL_META);
930 luaL_register(L, NULL, R_common);
931 luaL_register(L, NULL, R_wl);
932 lua_pushvalue(L, -1);
933 lua_setfield(L, -2, "__index");
934 lua_setfield(L, -2, "wl");
935 #endif
936
937 #ifdef USE_MADWIFI
938 luaL_newmetatable(L, IWINFO_MADWIFI_META);
939 luaL_register(L, NULL, R_common);
940 luaL_register(L, NULL, R_madwifi);
941 lua_pushvalue(L, -1);
942 lua_setfield(L, -2, "__index");
943 lua_setfield(L, -2, "madwifi");
944 #endif
945
946 #ifdef USE_NL80211
947 luaL_newmetatable(L, IWINFO_NL80211_META);
948 luaL_register(L, NULL, R_common);
949 luaL_register(L, NULL, R_nl80211);
950 lua_pushvalue(L, -1);
951 lua_setfield(L, -2, "__index");
952 lua_setfield(L, -2, "nl80211");
953 #endif
954
955 luaL_newmetatable(L, IWINFO_WEXT_META);
956 luaL_register(L, NULL, R_common);
957 luaL_register(L, NULL, R_wext);
958 lua_pushvalue(L, -1);
959 lua_setfield(L, -2, "__index");
960 lua_setfield(L, -2, "wext");
961
962 return 1;
963 }