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