iwinfo: add 802.11ax HE rate information
[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_pushboolean(L, r->is_he);
272 lua_setfield(L, -2, rx ? "rx_he" : "tx_he");
273
274 lua_pushnumber(L, r->mhz);
275 lua_setfield(L, -2, rx ? "rx_mhz" : "tx_mhz");
276
277 if (r->is_ht)
278 {
279 lua_pushboolean(L, r->is_40mhz);
280 lua_setfield(L, -2, rx ? "rx_40mhz" : "tx_40mhz");
281
282 lua_pushnumber(L, r->mcs);
283 lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
284
285 lua_pushboolean(L, r->is_short_gi);
286 lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
287 }
288 else if (r->is_vht || r->is_he)
289 {
290 lua_pushnumber(L, r->mcs);
291 lua_setfield(L, -2, rx ? "rx_mcs" : "tx_mcs");
292
293 lua_pushnumber(L, r->nss);
294 lua_setfield(L, -2, rx ? "rx_nss" : "tx_nss");
295
296 if (r->is_he) {
297 lua_pushnumber(L, r->he_gi);
298 lua_setfield(L, -2, rx ? "rx_he_gi" : "tx_he_gi");
299
300 lua_pushnumber(L, r->he_dcm);
301 lua_setfield(L, -2, rx ? "rx_he_dcm" : "tx_he_dcm");
302 }
303
304 if (r->is_vht) {
305 lua_pushboolean(L, r->is_short_gi);
306 lua_setfield(L, -2, rx ? "rx_short_gi" : "tx_short_gi");
307 }
308 }
309 }
310
311 /* Wrapper for assoclist */
312 static int iwinfo_L_assoclist(lua_State *L, int (*func)(const char *, char *, int *))
313 {
314 int i, len;
315 char rv[IWINFO_BUFSIZE];
316 char macstr[18];
317 const char *ifname = luaL_checkstring(L, 1);
318 struct iwinfo_assoclist_entry *e;
319
320 lua_newtable(L);
321 memset(rv, 0, sizeof(rv));
322
323 if (!(*func)(ifname, rv, &len))
324 {
325 for (i = 0; i < len; i += sizeof(struct iwinfo_assoclist_entry))
326 {
327 e = (struct iwinfo_assoclist_entry *) &rv[i];
328
329 sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
330 e->mac[0], e->mac[1], e->mac[2],
331 e->mac[3], e->mac[4], e->mac[5]);
332
333 lua_newtable(L);
334
335 lua_pushnumber(L, e->signal);
336 lua_setfield(L, -2, "signal");
337
338 lua_pushnumber(L, e->noise);
339 lua_setfield(L, -2, "noise");
340
341 lua_pushnumber(L, e->inactive);
342 lua_setfield(L, -2, "inactive");
343
344 lua_pushnumber(L, e->rx_packets);
345 lua_setfield(L, -2, "rx_packets");
346
347 lua_pushnumber(L, e->tx_packets);
348 lua_setfield(L, -2, "tx_packets");
349
350 set_rateinfo(L, &e->rx_rate, true);
351 set_rateinfo(L, &e->tx_rate, false);
352
353 if (e->thr) {
354 lua_pushnumber(L, e->thr);
355 lua_setfield(L, -2, "expected_throughput");
356 }
357
358 lua_setfield(L, -2, macstr);
359 }
360 }
361
362 return 1;
363 }
364
365 /* Wrapper for tx power list */
366 static int iwinfo_L_txpwrlist(lua_State *L, int (*func)(const char *, char *, int *))
367 {
368 int i, x, len;
369 char rv[IWINFO_BUFSIZE];
370 const char *ifname = luaL_checkstring(L, 1);
371 struct iwinfo_txpwrlist_entry *e;
372
373 memset(rv, 0, sizeof(rv));
374
375 if (!(*func)(ifname, rv, &len))
376 {
377 lua_newtable(L);
378
379 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_txpwrlist_entry), x++)
380 {
381 e = (struct iwinfo_txpwrlist_entry *) &rv[i];
382
383 lua_newtable(L);
384
385 lua_pushnumber(L, e->mw);
386 lua_setfield(L, -2, "mw");
387
388 lua_pushnumber(L, e->dbm);
389 lua_setfield(L, -2, "dbm");
390
391 lua_rawseti(L, -2, x);
392 }
393
394 return 1;
395 }
396
397 return 0;
398 }
399
400 /* Wrapper for scan list */
401 static int iwinfo_L_scanlist(lua_State *L, int (*func)(const char *, char *, int *))
402 {
403 int i, x, len = 0;
404 char rv[IWINFO_BUFSIZE];
405 char macstr[18];
406 const char *ifname = luaL_checkstring(L, 1);
407 struct iwinfo_scanlist_entry *e;
408
409 lua_newtable(L);
410 memset(rv, 0, sizeof(rv));
411
412 if (!(*func)(ifname, rv, &len))
413 {
414 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_scanlist_entry), x++)
415 {
416 e = (struct iwinfo_scanlist_entry *) &rv[i];
417
418 lua_newtable(L);
419
420 /* BSSID */
421 sprintf(macstr, "%02X:%02X:%02X:%02X:%02X:%02X",
422 e->mac[0], e->mac[1], e->mac[2],
423 e->mac[3], e->mac[4], e->mac[5]);
424
425 lua_pushstring(L, macstr);
426 lua_setfield(L, -2, "bssid");
427
428 /* ESSID */
429 if (e->ssid[0])
430 {
431 lua_pushstring(L, (char *) e->ssid);
432 lua_setfield(L, -2, "ssid");
433 }
434
435 /* Channel */
436 lua_pushinteger(L, e->channel);
437 lua_setfield(L, -2, "channel");
438
439 /* Mode */
440 lua_pushstring(L, IWINFO_OPMODE_NAMES[e->mode]);
441 lua_setfield(L, -2, "mode");
442
443 /* Quality, Signal */
444 lua_pushinteger(L, e->quality);
445 lua_setfield(L, -2, "quality");
446
447 lua_pushinteger(L, e->quality_max);
448 lua_setfield(L, -2, "quality_max");
449
450 lua_pushnumber(L, (e->signal - 0x100));
451 lua_setfield(L, -2, "signal");
452
453 /* Crypto */
454 iwinfo_L_cryptotable(L, &e->crypto);
455 lua_setfield(L, -2, "encryption");
456
457 lua_rawseti(L, -2, x);
458 }
459 }
460
461 return 1;
462 }
463
464 /* Wrapper for frequency list */
465 static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
466 {
467 int i, x, len;
468 char rv[IWINFO_BUFSIZE];
469 const char *ifname = luaL_checkstring(L, 1);
470 struct iwinfo_freqlist_entry *e;
471
472 lua_newtable(L);
473 memset(rv, 0, sizeof(rv));
474
475 if (!(*func)(ifname, rv, &len))
476 {
477 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++)
478 {
479 e = (struct iwinfo_freqlist_entry *) &rv[i];
480
481 lua_newtable(L);
482
483 /* MHz */
484 lua_pushinteger(L, e->mhz);
485 lua_setfield(L, -2, "mhz");
486
487 /* Channel */
488 lua_pushinteger(L, e->channel);
489 lua_setfield(L, -2, "channel");
490
491 /* Restricted (DFS/TPC/Radar) */
492 lua_pushboolean(L, e->restricted);
493 lua_setfield(L, -2, "restricted");
494
495 lua_rawseti(L, -2, x);
496 }
497 }
498
499 return 1;
500 }
501
502 /* Wrapper for crypto settings */
503 static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
504 {
505 const char *ifname = luaL_checkstring(L, 1);
506 struct iwinfo_crypto_entry c = { 0 };
507
508 if (!(*func)(ifname, (char *)&c))
509 {
510 iwinfo_L_cryptotable(L, &c);
511 return 1;
512 }
513
514 lua_pushnil(L);
515 return 1;
516 }
517
518 /* Wrapper for hwmode list */
519 static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
520 {
521 const char *ifname = luaL_checkstring(L, 1);
522 int hwmodes = 0;
523
524 if (!(*func)(ifname, &hwmodes))
525 {
526 lua_newtable(L);
527
528 lua_pushboolean(L, hwmodes & IWINFO_80211_A);
529 lua_setfield(L, -2, "a");
530
531 lua_pushboolean(L, hwmodes & IWINFO_80211_B);
532 lua_setfield(L, -2, "b");
533
534 lua_pushboolean(L, hwmodes & IWINFO_80211_G);
535 lua_setfield(L, -2, "g");
536
537 lua_pushboolean(L, hwmodes & IWINFO_80211_N);
538 lua_setfield(L, -2, "n");
539
540 lua_pushboolean(L, hwmodes & IWINFO_80211_AC);
541 lua_setfield(L, -2, "ac");
542
543 lua_pushboolean(L, hwmodes & IWINFO_80211_AD);
544 lua_setfield(L, -2, "ad");
545
546 lua_pushboolean(L, hwmodes & IWINFO_80211_AX);
547 lua_setfield(L, -2, "ax");
548
549 return 1;
550 }
551
552 lua_pushnil(L);
553 return 1;
554 }
555
556 /* Wrapper for htmode list */
557 static int iwinfo_L_htmodelist(lua_State *L, int (*func)(const char *, int *))
558 {
559 const char *ifname = luaL_checkstring(L, 1);
560 int i, htmodes = 0;
561
562 if (!(*func)(ifname, &htmodes))
563 {
564 lua_newtable(L);
565
566 for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
567 {
568 lua_pushboolean(L, htmodes & (1 << i));
569 lua_setfield(L, -2, IWINFO_HTMODE_NAMES[i]);
570 }
571
572 return 1;
573 }
574
575 lua_pushnil(L);
576 return 1;
577 }
578
579 /* Wrapper for mbssid_support */
580 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
581 {
582 const char *ifname = luaL_checkstring(L, 1);
583 int support = 0;
584
585 if (!(*func)(ifname, &support))
586 {
587 lua_pushboolean(L, support);
588 return 1;
589 }
590
591 lua_pushnil(L);
592 return 1;
593 }
594
595 /* Wrapper for hardware_id */
596 static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
597 {
598 const char *ifname = luaL_checkstring(L, 1);
599 struct iwinfo_hardware_id ids;
600
601 if (!(*func)(ifname, (char *)&ids))
602 {
603 lua_newtable(L);
604
605 lua_pushnumber(L, ids.vendor_id);
606 lua_setfield(L, -2, "vendor_id");
607
608 lua_pushnumber(L, ids.device_id);
609 lua_setfield(L, -2, "device_id");
610
611 lua_pushnumber(L, ids.subsystem_vendor_id);
612 lua_setfield(L, -2, "subsystem_vendor_id");
613
614 lua_pushnumber(L, ids.subsystem_device_id);
615 lua_setfield(L, -2, "subsystem_device_id");
616 }
617 else
618 {
619 lua_pushnil(L);
620 }
621
622 return 1;
623 }
624
625 /* Wrapper for country list */
626 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
627 {
628 int i;
629 struct iwinfo_country_entry *c;
630
631 for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
632 {
633 c = (struct iwinfo_country_entry *) &buf[i];
634
635 if (c->iso3166 == iso3166)
636 return c->ccode;
637 }
638
639 return NULL;
640 }
641
642 static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
643 {
644 int len, i;
645 char rv[IWINFO_BUFSIZE], alpha2[3];
646 char *ccode;
647 const char *ifname = luaL_checkstring(L, 1);
648 const struct iwinfo_iso3166_label *l;
649
650 lua_newtable(L);
651 memset(rv, 0, sizeof(rv));
652
653 if (!(*func)(ifname, rv, &len))
654 {
655 for (l = IWINFO_ISO3166_NAMES, i = 1; l->iso3166; l++)
656 {
657 if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
658 {
659 sprintf(alpha2, "%c%c",
660 (l->iso3166 / 256), (l->iso3166 % 256));
661
662 lua_newtable(L);
663
664 lua_pushstring(L, alpha2);
665 lua_setfield(L, -2, "alpha2");
666
667 lua_pushstring(L, ccode);
668 lua_setfield(L, -2, "ccode");
669
670 lua_pushstring(L, l->name);
671 lua_setfield(L, -2, "name");
672
673 lua_rawseti(L, -2, i++);
674 }
675 }
676 }
677
678 return 1;
679 }
680
681
682 #ifdef USE_WL
683 /* Broadcom */
684 LUA_WRAP_INT_OP(wl,channel)
685 LUA_WRAP_INT_OP(wl,frequency)
686 LUA_WRAP_INT_OP(wl,frequency_offset)
687 LUA_WRAP_INT_OP(wl,txpower)
688 LUA_WRAP_INT_OP(wl,txpower_offset)
689 LUA_WRAP_INT_OP(wl,bitrate)
690 LUA_WRAP_INT_OP(wl,signal)
691 LUA_WRAP_INT_OP(wl,noise)
692 LUA_WRAP_INT_OP(wl,quality)
693 LUA_WRAP_INT_OP(wl,quality_max)
694 LUA_WRAP_STRING_OP(wl,ssid)
695 LUA_WRAP_STRING_OP(wl,bssid)
696 LUA_WRAP_STRING_OP(wl,country)
697 LUA_WRAP_STRING_OP(wl,hardware_name)
698 LUA_WRAP_STRING_OP(wl,phyname)
699 LUA_WRAP_STRUCT_OP(wl,mode)
700 LUA_WRAP_STRUCT_OP(wl,assoclist)
701 LUA_WRAP_STRUCT_OP(wl,txpwrlist)
702 LUA_WRAP_STRUCT_OP(wl,scanlist)
703 LUA_WRAP_STRUCT_OP(wl,freqlist)
704 LUA_WRAP_STRUCT_OP(wl,countrylist)
705 LUA_WRAP_STRUCT_OP(wl,hwmodelist)
706 LUA_WRAP_STRUCT_OP(wl,htmodelist)
707 LUA_WRAP_STRUCT_OP(wl,encryption)
708 LUA_WRAP_STRUCT_OP(wl,mbssid_support)
709 LUA_WRAP_STRUCT_OP(wl,hardware_id)
710 #endif
711
712 #ifdef USE_MADWIFI
713 /* Madwifi */
714 LUA_WRAP_INT_OP(madwifi,channel)
715 LUA_WRAP_INT_OP(madwifi,frequency)
716 LUA_WRAP_INT_OP(madwifi,frequency_offset)
717 LUA_WRAP_INT_OP(madwifi,txpower)
718 LUA_WRAP_INT_OP(madwifi,txpower_offset)
719 LUA_WRAP_INT_OP(madwifi,bitrate)
720 LUA_WRAP_INT_OP(madwifi,signal)
721 LUA_WRAP_INT_OP(madwifi,noise)
722 LUA_WRAP_INT_OP(madwifi,quality)
723 LUA_WRAP_INT_OP(madwifi,quality_max)
724 LUA_WRAP_STRING_OP(madwifi,ssid)
725 LUA_WRAP_STRING_OP(madwifi,bssid)
726 LUA_WRAP_STRING_OP(madwifi,country)
727 LUA_WRAP_STRING_OP(madwifi,hardware_name)
728 LUA_WRAP_STRING_OP(madwifi,phyname)
729 LUA_WRAP_STRUCT_OP(madwifi,mode)
730 LUA_WRAP_STRUCT_OP(madwifi,assoclist)
731 LUA_WRAP_STRUCT_OP(madwifi,txpwrlist)
732 LUA_WRAP_STRUCT_OP(madwifi,scanlist)
733 LUA_WRAP_STRUCT_OP(madwifi,freqlist)
734 LUA_WRAP_STRUCT_OP(madwifi,countrylist)
735 LUA_WRAP_STRUCT_OP(madwifi,hwmodelist)
736 LUA_WRAP_STRUCT_OP(madwifi,htmodelist)
737 LUA_WRAP_STRUCT_OP(madwifi,encryption)
738 LUA_WRAP_STRUCT_OP(madwifi,mbssid_support)
739 LUA_WRAP_STRUCT_OP(madwifi,hardware_id)
740 #endif
741
742 #ifdef USE_NL80211
743 /* NL80211 */
744 LUA_WRAP_INT_OP(nl80211,channel)
745 LUA_WRAP_INT_OP(nl80211,frequency)
746 LUA_WRAP_INT_OP(nl80211,frequency_offset)
747 LUA_WRAP_INT_OP(nl80211,txpower)
748 LUA_WRAP_INT_OP(nl80211,txpower_offset)
749 LUA_WRAP_INT_OP(nl80211,bitrate)
750 LUA_WRAP_INT_OP(nl80211,signal)
751 LUA_WRAP_INT_OP(nl80211,noise)
752 LUA_WRAP_INT_OP(nl80211,quality)
753 LUA_WRAP_INT_OP(nl80211,quality_max)
754 LUA_WRAP_STRING_OP(nl80211,ssid)
755 LUA_WRAP_STRING_OP(nl80211,bssid)
756 LUA_WRAP_STRING_OP(nl80211,country)
757 LUA_WRAP_STRING_OP(nl80211,hardware_name)
758 LUA_WRAP_STRING_OP(nl80211,phyname)
759 LUA_WRAP_STRUCT_OP(nl80211,mode)
760 LUA_WRAP_STRUCT_OP(nl80211,assoclist)
761 LUA_WRAP_STRUCT_OP(nl80211,txpwrlist)
762 LUA_WRAP_STRUCT_OP(nl80211,scanlist)
763 LUA_WRAP_STRUCT_OP(nl80211,freqlist)
764 LUA_WRAP_STRUCT_OP(nl80211,countrylist)
765 LUA_WRAP_STRUCT_OP(nl80211,hwmodelist)
766 LUA_WRAP_STRUCT_OP(nl80211,htmodelist)
767 LUA_WRAP_STRUCT_OP(nl80211,encryption)
768 LUA_WRAP_STRUCT_OP(nl80211,mbssid_support)
769 LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
770 #endif
771
772 /* Wext */
773 LUA_WRAP_INT_OP(wext,channel)
774 LUA_WRAP_INT_OP(wext,frequency)
775 LUA_WRAP_INT_OP(wext,frequency_offset)
776 LUA_WRAP_INT_OP(wext,txpower)
777 LUA_WRAP_INT_OP(wext,txpower_offset)
778 LUA_WRAP_INT_OP(wext,bitrate)
779 LUA_WRAP_INT_OP(wext,signal)
780 LUA_WRAP_INT_OP(wext,noise)
781 LUA_WRAP_INT_OP(wext,quality)
782 LUA_WRAP_INT_OP(wext,quality_max)
783 LUA_WRAP_STRING_OP(wext,ssid)
784 LUA_WRAP_STRING_OP(wext,bssid)
785 LUA_WRAP_STRING_OP(wext,country)
786 LUA_WRAP_STRING_OP(wext,hardware_name)
787 LUA_WRAP_STRING_OP(wext,phyname)
788 LUA_WRAP_STRUCT_OP(wext,mode)
789 LUA_WRAP_STRUCT_OP(wext,assoclist)
790 LUA_WRAP_STRUCT_OP(wext,txpwrlist)
791 LUA_WRAP_STRUCT_OP(wext,scanlist)
792 LUA_WRAP_STRUCT_OP(wext,freqlist)
793 LUA_WRAP_STRUCT_OP(wext,countrylist)
794 LUA_WRAP_STRUCT_OP(wext,hwmodelist)
795 LUA_WRAP_STRUCT_OP(wext,htmodelist)
796 LUA_WRAP_STRUCT_OP(wext,encryption)
797 LUA_WRAP_STRUCT_OP(wext,mbssid_support)
798 LUA_WRAP_STRUCT_OP(wext,hardware_id)
799
800 #ifdef USE_WL
801 /* Broadcom table */
802 static const luaL_reg R_wl[] = {
803 LUA_REG(wl,channel),
804 LUA_REG(wl,frequency),
805 LUA_REG(wl,frequency_offset),
806 LUA_REG(wl,txpower),
807 LUA_REG(wl,txpower_offset),
808 LUA_REG(wl,bitrate),
809 LUA_REG(wl,signal),
810 LUA_REG(wl,noise),
811 LUA_REG(wl,quality),
812 LUA_REG(wl,quality_max),
813 LUA_REG(wl,mode),
814 LUA_REG(wl,ssid),
815 LUA_REG(wl,bssid),
816 LUA_REG(wl,country),
817 LUA_REG(wl,assoclist),
818 LUA_REG(wl,txpwrlist),
819 LUA_REG(wl,scanlist),
820 LUA_REG(wl,freqlist),
821 LUA_REG(wl,countrylist),
822 LUA_REG(wl,hwmodelist),
823 LUA_REG(wl,htmodelist),
824 LUA_REG(wl,encryption),
825 LUA_REG(wl,mbssid_support),
826 LUA_REG(wl,hardware_id),
827 LUA_REG(wl,hardware_name),
828 LUA_REG(wl,phyname),
829 { NULL, NULL }
830 };
831 #endif
832
833 #ifdef USE_MADWIFI
834 /* Madwifi table */
835 static const luaL_reg R_madwifi[] = {
836 LUA_REG(madwifi,channel),
837 LUA_REG(madwifi,frequency),
838 LUA_REG(madwifi,frequency_offset),
839 LUA_REG(madwifi,txpower),
840 LUA_REG(madwifi,txpower_offset),
841 LUA_REG(madwifi,bitrate),
842 LUA_REG(madwifi,signal),
843 LUA_REG(madwifi,noise),
844 LUA_REG(madwifi,quality),
845 LUA_REG(madwifi,quality_max),
846 LUA_REG(madwifi,mode),
847 LUA_REG(madwifi,ssid),
848 LUA_REG(madwifi,bssid),
849 LUA_REG(madwifi,country),
850 LUA_REG(madwifi,assoclist),
851 LUA_REG(madwifi,txpwrlist),
852 LUA_REG(madwifi,scanlist),
853 LUA_REG(madwifi,freqlist),
854 LUA_REG(madwifi,countrylist),
855 LUA_REG(madwifi,hwmodelist),
856 LUA_REG(madwifi,htmodelist),
857 LUA_REG(madwifi,encryption),
858 LUA_REG(madwifi,mbssid_support),
859 LUA_REG(madwifi,hardware_id),
860 LUA_REG(madwifi,hardware_name),
861 LUA_REG(madwifi,phyname),
862 { NULL, NULL }
863 };
864 #endif
865
866 #ifdef USE_NL80211
867 /* NL80211 table */
868 static const luaL_reg R_nl80211[] = {
869 LUA_REG(nl80211,channel),
870 LUA_REG(nl80211,frequency),
871 LUA_REG(nl80211,frequency_offset),
872 LUA_REG(nl80211,txpower),
873 LUA_REG(nl80211,txpower_offset),
874 LUA_REG(nl80211,bitrate),
875 LUA_REG(nl80211,signal),
876 LUA_REG(nl80211,noise),
877 LUA_REG(nl80211,quality),
878 LUA_REG(nl80211,quality_max),
879 LUA_REG(nl80211,mode),
880 LUA_REG(nl80211,ssid),
881 LUA_REG(nl80211,bssid),
882 LUA_REG(nl80211,country),
883 LUA_REG(nl80211,assoclist),
884 LUA_REG(nl80211,txpwrlist),
885 LUA_REG(nl80211,scanlist),
886 LUA_REG(nl80211,freqlist),
887 LUA_REG(nl80211,countrylist),
888 LUA_REG(nl80211,hwmodelist),
889 LUA_REG(nl80211,htmodelist),
890 LUA_REG(nl80211,encryption),
891 LUA_REG(nl80211,mbssid_support),
892 LUA_REG(nl80211,hardware_id),
893 LUA_REG(nl80211,hardware_name),
894 LUA_REG(nl80211,phyname),
895 { NULL, NULL }
896 };
897 #endif
898
899 /* Wext table */
900 static const luaL_reg R_wext[] = {
901 LUA_REG(wext,channel),
902 LUA_REG(wext,frequency),
903 LUA_REG(wext,frequency_offset),
904 LUA_REG(wext,txpower),
905 LUA_REG(wext,txpower_offset),
906 LUA_REG(wext,bitrate),
907 LUA_REG(wext,signal),
908 LUA_REG(wext,noise),
909 LUA_REG(wext,quality),
910 LUA_REG(wext,quality_max),
911 LUA_REG(wext,mode),
912 LUA_REG(wext,ssid),
913 LUA_REG(wext,bssid),
914 LUA_REG(wext,country),
915 LUA_REG(wext,assoclist),
916 LUA_REG(wext,txpwrlist),
917 LUA_REG(wext,scanlist),
918 LUA_REG(wext,freqlist),
919 LUA_REG(wext,countrylist),
920 LUA_REG(wext,hwmodelist),
921 LUA_REG(wext,htmodelist),
922 LUA_REG(wext,encryption),
923 LUA_REG(wext,mbssid_support),
924 LUA_REG(wext,hardware_id),
925 LUA_REG(wext,hardware_name),
926 LUA_REG(wext,phyname),
927 { NULL, NULL }
928 };
929
930 /* Common */
931 static const luaL_reg R_common[] = {
932 { "type", iwinfo_L_type },
933 { "__gc", iwinfo_L__gc },
934 { NULL, NULL }
935 };
936
937
938 LUALIB_API int luaopen_iwinfo(lua_State *L) {
939 luaL_register(L, IWINFO_META, R_common);
940
941 #ifdef USE_WL
942 luaL_newmetatable(L, IWINFO_WL_META);
943 luaL_register(L, NULL, R_common);
944 luaL_register(L, NULL, R_wl);
945 lua_pushvalue(L, -1);
946 lua_setfield(L, -2, "__index");
947 lua_setfield(L, -2, "wl");
948 #endif
949
950 #ifdef USE_MADWIFI
951 luaL_newmetatable(L, IWINFO_MADWIFI_META);
952 luaL_register(L, NULL, R_common);
953 luaL_register(L, NULL, R_madwifi);
954 lua_pushvalue(L, -1);
955 lua_setfield(L, -2, "__index");
956 lua_setfield(L, -2, "madwifi");
957 #endif
958
959 #ifdef USE_NL80211
960 luaL_newmetatable(L, IWINFO_NL80211_META);
961 luaL_register(L, NULL, R_common);
962 luaL_register(L, NULL, R_nl80211);
963 lua_pushvalue(L, -1);
964 lua_setfield(L, -2, "__index");
965 lua_setfield(L, -2, "nl80211");
966 #endif
967
968 luaL_newmetatable(L, IWINFO_WEXT_META);
969 luaL_register(L, NULL, R_common);
970 luaL_register(L, NULL, R_wext);
971 lua_pushvalue(L, -1);
972 lua_setfield(L, -2, "__index");
973 lua_setfield(L, -2, "wext");
974
975 return 1;
976 }