iwinfo: add BSS load element to scan result
[oweals/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                         /* BSS load */
438                         if (e->has_bss_load) {
439                                 lua_pushnumber(L, e->station_count);
440                                 lua_setfield(L, -2, "station_count");
441
442                                 lua_pushnumber(L, e->channel_utilization);
443                                 lua_setfield(L, -2, "channel_utilization");
444
445                                 lua_pushnumber(L, e->admission_capacity);
446                                 lua_setfield(L, -2, "admission_capacity");
447                         }
448
449                         /* Crypto */
450                         iwinfo_L_cryptotable(L, &e->crypto);
451                         lua_setfield(L, -2, "encryption");
452
453                         lua_rawseti(L, -2, x);
454                 }
455         }
456
457         return 1;
458 }
459
460 /* Wrapper for frequency list */
461 static int iwinfo_L_freqlist(lua_State *L, int (*func)(const char *, char *, int *))
462 {
463         int i, x, len;
464         char rv[IWINFO_BUFSIZE];
465         const char *ifname = luaL_checkstring(L, 1);
466         struct iwinfo_freqlist_entry *e;
467
468         lua_newtable(L);
469         memset(rv, 0, sizeof(rv));
470
471         if (!(*func)(ifname, rv, &len))
472         {
473                 for (i = 0, x = 1; i < len; i += sizeof(struct iwinfo_freqlist_entry), x++)
474                 {
475                         e = (struct iwinfo_freqlist_entry *) &rv[i];
476
477                         lua_newtable(L);
478
479                         /* MHz */
480                         lua_pushinteger(L, e->mhz);
481                         lua_setfield(L, -2, "mhz");
482
483                         /* Channel */
484                         lua_pushinteger(L, e->channel);
485                         lua_setfield(L, -2, "channel");
486
487                         /* Restricted (DFS/TPC/Radar) */
488                         lua_pushboolean(L, e->restricted);
489                         lua_setfield(L, -2, "restricted");
490
491                         lua_rawseti(L, -2, x);
492                 }
493         }
494
495         return 1;
496 }
497
498 /* Wrapper for crypto settings */
499 static int iwinfo_L_encryption(lua_State *L, int (*func)(const char *, char *))
500 {
501         const char *ifname = luaL_checkstring(L, 1);
502         struct iwinfo_crypto_entry c = { 0 };
503
504         if (!(*func)(ifname, (char *)&c))
505         {
506                 iwinfo_L_cryptotable(L, &c);
507                 return 1;
508         }
509
510         lua_pushnil(L);
511         return 1;
512 }
513
514 /* Wrapper for hwmode list */
515 static int iwinfo_L_hwmodelist(lua_State *L, int (*func)(const char *, int *))
516 {
517         const char *ifname = luaL_checkstring(L, 1);
518         int hwmodes = 0;
519
520         if (!(*func)(ifname, &hwmodes))
521         {
522                 lua_newtable(L);
523
524                 lua_pushboolean(L, hwmodes & IWINFO_80211_A);
525                 lua_setfield(L, -2, "a");
526
527                 lua_pushboolean(L, hwmodes & IWINFO_80211_B);
528                 lua_setfield(L, -2, "b");
529
530                 lua_pushboolean(L, hwmodes & IWINFO_80211_G);
531                 lua_setfield(L, -2, "g");
532
533                 lua_pushboolean(L, hwmodes & IWINFO_80211_N);
534                 lua_setfield(L, -2, "n");
535
536                 lua_pushboolean(L, hwmodes & IWINFO_80211_AC);
537                 lua_setfield(L, -2, "ac");
538
539                 lua_pushboolean(L, hwmodes & IWINFO_80211_AD);
540                 lua_setfield(L, -2, "ad");
541
542                 return 1;
543         }
544
545         lua_pushnil(L);
546         return 1;
547 }
548
549 /* Wrapper for htmode list */
550 static int iwinfo_L_htmodelist(lua_State *L, int (*func)(const char *, int *))
551 {
552         const char *ifname = luaL_checkstring(L, 1);
553         int i, htmodes = 0;
554
555         if (!(*func)(ifname, &htmodes))
556         {
557                 lua_newtable(L);
558
559                 for (i = 0; i < ARRAY_SIZE(IWINFO_HTMODE_NAMES); i++)
560                 {
561                         lua_pushboolean(L, htmodes & (1 << i));
562                         lua_setfield(L, -2, IWINFO_HTMODE_NAMES[i]);
563                 }
564
565                 return 1;
566         }
567
568         lua_pushnil(L);
569         return 1;
570 }
571
572 /* Wrapper for mbssid_support */
573 static int iwinfo_L_mbssid_support(lua_State *L, int (*func)(const char *, int *))
574 {
575         const char *ifname = luaL_checkstring(L, 1);
576         int support = 0;
577
578         if (!(*func)(ifname, &support))
579         {
580                 lua_pushboolean(L, support);
581                 return 1;
582         }
583
584         lua_pushnil(L);
585         return 1;
586 }
587
588 /* Wrapper for hardware_id */
589 static int iwinfo_L_hardware_id(lua_State *L, int (*func)(const char *, char *))
590 {
591         const char *ifname = luaL_checkstring(L, 1);
592         struct iwinfo_hardware_id ids;
593
594         if (!(*func)(ifname, (char *)&ids))
595         {
596                 lua_newtable(L);
597
598                 lua_pushnumber(L, ids.vendor_id);
599                 lua_setfield(L, -2, "vendor_id");
600
601                 lua_pushnumber(L, ids.device_id);
602                 lua_setfield(L, -2, "device_id");
603
604                 lua_pushnumber(L, ids.subsystem_vendor_id);
605                 lua_setfield(L, -2, "subsystem_vendor_id");
606
607                 lua_pushnumber(L, ids.subsystem_device_id);
608                 lua_setfield(L, -2, "subsystem_device_id");
609         }
610         else
611         {
612                 lua_pushnil(L);
613         }
614
615         return 1;
616 }
617
618 /* Wrapper for country list */
619 static char * iwinfo_L_country_lookup(char *buf, int len, int iso3166)
620 {
621         int i;
622         struct iwinfo_country_entry *c;
623
624         for (i = 0; i < len; i += sizeof(struct iwinfo_country_entry))
625         {
626                 c = (struct iwinfo_country_entry *) &buf[i];
627
628                 if (c->iso3166 == iso3166)
629                         return c->ccode;
630         }
631
632         return NULL;
633 }
634
635 static int iwinfo_L_countrylist(lua_State *L, int (*func)(const char *, char *, int *))
636 {
637         int len, i;
638         char rv[IWINFO_BUFSIZE], alpha2[3];
639         char *ccode;
640         const char *ifname = luaL_checkstring(L, 1);
641         const struct iwinfo_iso3166_label *l;
642
643         lua_newtable(L);
644         memset(rv, 0, sizeof(rv));
645
646         if (!(*func)(ifname, rv, &len))
647         {
648                 for (l = IWINFO_ISO3166_NAMES, i = 1; l->iso3166; l++)
649                 {
650                         if ((ccode = iwinfo_L_country_lookup(rv, len, l->iso3166)) != NULL)
651                         {
652                                 sprintf(alpha2, "%c%c",
653                                         (l->iso3166 / 256), (l->iso3166 % 256));
654
655                                 lua_newtable(L);
656
657                                 lua_pushstring(L, alpha2);
658                                 lua_setfield(L, -2, "alpha2");
659
660                                 lua_pushstring(L, ccode);
661                                 lua_setfield(L, -2, "ccode");
662
663                                 lua_pushstring(L, l->name);
664                                 lua_setfield(L, -2, "name");
665
666                                 lua_rawseti(L, -2, i++);
667                         }
668                 }
669         }
670
671         return 1;
672 }
673
674
675 #ifdef USE_WL
676 /* Broadcom */
677 LUA_WRAP_INT_OP(wl,channel)
678 LUA_WRAP_INT_OP(wl,frequency)
679 LUA_WRAP_INT_OP(wl,frequency_offset)
680 LUA_WRAP_INT_OP(wl,txpower)
681 LUA_WRAP_INT_OP(wl,txpower_offset)
682 LUA_WRAP_INT_OP(wl,bitrate)
683 LUA_WRAP_INT_OP(wl,signal)
684 LUA_WRAP_INT_OP(wl,noise)
685 LUA_WRAP_INT_OP(wl,quality)
686 LUA_WRAP_INT_OP(wl,quality_max)
687 LUA_WRAP_STRING_OP(wl,ssid)
688 LUA_WRAP_STRING_OP(wl,bssid)
689 LUA_WRAP_STRING_OP(wl,country)
690 LUA_WRAP_STRING_OP(wl,hardware_name)
691 LUA_WRAP_STRING_OP(wl,phyname)
692 LUA_WRAP_STRUCT_OP(wl,mode)
693 LUA_WRAP_STRUCT_OP(wl,assoclist)
694 LUA_WRAP_STRUCT_OP(wl,txpwrlist)
695 LUA_WRAP_STRUCT_OP(wl,scanlist)
696 LUA_WRAP_STRUCT_OP(wl,freqlist)
697 LUA_WRAP_STRUCT_OP(wl,countrylist)
698 LUA_WRAP_STRUCT_OP(wl,hwmodelist)
699 LUA_WRAP_STRUCT_OP(wl,htmodelist)
700 LUA_WRAP_STRUCT_OP(wl,encryption)
701 LUA_WRAP_STRUCT_OP(wl,mbssid_support)
702 LUA_WRAP_STRUCT_OP(wl,hardware_id)
703 #endif
704
705 #ifdef USE_MADWIFI
706 /* Madwifi */
707 LUA_WRAP_INT_OP(madwifi,channel)
708 LUA_WRAP_INT_OP(madwifi,frequency)
709 LUA_WRAP_INT_OP(madwifi,frequency_offset)
710 LUA_WRAP_INT_OP(madwifi,txpower)
711 LUA_WRAP_INT_OP(madwifi,txpower_offset)
712 LUA_WRAP_INT_OP(madwifi,bitrate)
713 LUA_WRAP_INT_OP(madwifi,signal)
714 LUA_WRAP_INT_OP(madwifi,noise)
715 LUA_WRAP_INT_OP(madwifi,quality)
716 LUA_WRAP_INT_OP(madwifi,quality_max)
717 LUA_WRAP_STRING_OP(madwifi,ssid)
718 LUA_WRAP_STRING_OP(madwifi,bssid)
719 LUA_WRAP_STRING_OP(madwifi,country)
720 LUA_WRAP_STRING_OP(madwifi,hardware_name)
721 LUA_WRAP_STRING_OP(madwifi,phyname)
722 LUA_WRAP_STRUCT_OP(madwifi,mode)
723 LUA_WRAP_STRUCT_OP(madwifi,assoclist)
724 LUA_WRAP_STRUCT_OP(madwifi,txpwrlist)
725 LUA_WRAP_STRUCT_OP(madwifi,scanlist)
726 LUA_WRAP_STRUCT_OP(madwifi,freqlist)
727 LUA_WRAP_STRUCT_OP(madwifi,countrylist)
728 LUA_WRAP_STRUCT_OP(madwifi,hwmodelist)
729 LUA_WRAP_STRUCT_OP(madwifi,htmodelist)
730 LUA_WRAP_STRUCT_OP(madwifi,encryption)
731 LUA_WRAP_STRUCT_OP(madwifi,mbssid_support)
732 LUA_WRAP_STRUCT_OP(madwifi,hardware_id)
733 #endif
734
735 #ifdef USE_NL80211
736 /* NL80211 */
737 LUA_WRAP_INT_OP(nl80211,channel)
738 LUA_WRAP_INT_OP(nl80211,frequency)
739 LUA_WRAP_INT_OP(nl80211,frequency_offset)
740 LUA_WRAP_INT_OP(nl80211,txpower)
741 LUA_WRAP_INT_OP(nl80211,txpower_offset)
742 LUA_WRAP_INT_OP(nl80211,bitrate)
743 LUA_WRAP_INT_OP(nl80211,signal)
744 LUA_WRAP_INT_OP(nl80211,noise)
745 LUA_WRAP_INT_OP(nl80211,quality)
746 LUA_WRAP_INT_OP(nl80211,quality_max)
747 LUA_WRAP_STRING_OP(nl80211,ssid)
748 LUA_WRAP_STRING_OP(nl80211,bssid)
749 LUA_WRAP_STRING_OP(nl80211,country)
750 LUA_WRAP_STRING_OP(nl80211,hardware_name)
751 LUA_WRAP_STRING_OP(nl80211,phyname)
752 LUA_WRAP_STRUCT_OP(nl80211,mode)
753 LUA_WRAP_STRUCT_OP(nl80211,assoclist)
754 LUA_WRAP_STRUCT_OP(nl80211,txpwrlist)
755 LUA_WRAP_STRUCT_OP(nl80211,scanlist)
756 LUA_WRAP_STRUCT_OP(nl80211,freqlist)
757 LUA_WRAP_STRUCT_OP(nl80211,countrylist)
758 LUA_WRAP_STRUCT_OP(nl80211,hwmodelist)
759 LUA_WRAP_STRUCT_OP(nl80211,htmodelist)
760 LUA_WRAP_STRUCT_OP(nl80211,encryption)
761 LUA_WRAP_STRUCT_OP(nl80211,mbssid_support)
762 LUA_WRAP_STRUCT_OP(nl80211,hardware_id)
763 #endif
764
765 /* Wext */
766 LUA_WRAP_INT_OP(wext,channel)
767 LUA_WRAP_INT_OP(wext,frequency)
768 LUA_WRAP_INT_OP(wext,frequency_offset)
769 LUA_WRAP_INT_OP(wext,txpower)
770 LUA_WRAP_INT_OP(wext,txpower_offset)
771 LUA_WRAP_INT_OP(wext,bitrate)
772 LUA_WRAP_INT_OP(wext,signal)
773 LUA_WRAP_INT_OP(wext,noise)
774 LUA_WRAP_INT_OP(wext,quality)
775 LUA_WRAP_INT_OP(wext,quality_max)
776 LUA_WRAP_STRING_OP(wext,ssid)
777 LUA_WRAP_STRING_OP(wext,bssid)
778 LUA_WRAP_STRING_OP(wext,country)
779 LUA_WRAP_STRING_OP(wext,hardware_name)
780 LUA_WRAP_STRING_OP(wext,phyname)
781 LUA_WRAP_STRUCT_OP(wext,mode)
782 LUA_WRAP_STRUCT_OP(wext,assoclist)
783 LUA_WRAP_STRUCT_OP(wext,txpwrlist)
784 LUA_WRAP_STRUCT_OP(wext,scanlist)
785 LUA_WRAP_STRUCT_OP(wext,freqlist)
786 LUA_WRAP_STRUCT_OP(wext,countrylist)
787 LUA_WRAP_STRUCT_OP(wext,hwmodelist)
788 LUA_WRAP_STRUCT_OP(wext,htmodelist)
789 LUA_WRAP_STRUCT_OP(wext,encryption)
790 LUA_WRAP_STRUCT_OP(wext,mbssid_support)
791 LUA_WRAP_STRUCT_OP(wext,hardware_id)
792
793 #ifdef USE_WL
794 /* Broadcom table */
795 static const luaL_reg R_wl[] = {
796         LUA_REG(wl,channel),
797         LUA_REG(wl,frequency),
798         LUA_REG(wl,frequency_offset),
799         LUA_REG(wl,txpower),
800         LUA_REG(wl,txpower_offset),
801         LUA_REG(wl,bitrate),
802         LUA_REG(wl,signal),
803         LUA_REG(wl,noise),
804         LUA_REG(wl,quality),
805         LUA_REG(wl,quality_max),
806         LUA_REG(wl,mode),
807         LUA_REG(wl,ssid),
808         LUA_REG(wl,bssid),
809         LUA_REG(wl,country),
810         LUA_REG(wl,assoclist),
811         LUA_REG(wl,txpwrlist),
812         LUA_REG(wl,scanlist),
813         LUA_REG(wl,freqlist),
814         LUA_REG(wl,countrylist),
815         LUA_REG(wl,hwmodelist),
816         LUA_REG(wl,htmodelist),
817         LUA_REG(wl,encryption),
818         LUA_REG(wl,mbssid_support),
819         LUA_REG(wl,hardware_id),
820         LUA_REG(wl,hardware_name),
821         LUA_REG(wl,phyname),
822         { NULL, NULL }
823 };
824 #endif
825
826 #ifdef USE_MADWIFI
827 /* Madwifi table */
828 static const luaL_reg R_madwifi[] = {
829         LUA_REG(madwifi,channel),
830         LUA_REG(madwifi,frequency),
831         LUA_REG(madwifi,frequency_offset),
832         LUA_REG(madwifi,txpower),
833         LUA_REG(madwifi,txpower_offset),
834         LUA_REG(madwifi,bitrate),
835         LUA_REG(madwifi,signal),
836         LUA_REG(madwifi,noise),
837         LUA_REG(madwifi,quality),
838         LUA_REG(madwifi,quality_max),
839         LUA_REG(madwifi,mode),
840         LUA_REG(madwifi,ssid),
841         LUA_REG(madwifi,bssid),
842         LUA_REG(madwifi,country),
843         LUA_REG(madwifi,assoclist),
844         LUA_REG(madwifi,txpwrlist),
845         LUA_REG(madwifi,scanlist),
846         LUA_REG(madwifi,freqlist),
847         LUA_REG(madwifi,countrylist),
848         LUA_REG(madwifi,hwmodelist),
849         LUA_REG(madwifi,htmodelist),
850         LUA_REG(madwifi,encryption),
851         LUA_REG(madwifi,mbssid_support),
852         LUA_REG(madwifi,hardware_id),
853         LUA_REG(madwifi,hardware_name),
854         LUA_REG(madwifi,phyname),
855         { NULL, NULL }
856 };
857 #endif
858
859 #ifdef USE_NL80211
860 /* NL80211 table */
861 static const luaL_reg R_nl80211[] = {
862         LUA_REG(nl80211,channel),
863         LUA_REG(nl80211,frequency),
864         LUA_REG(nl80211,frequency_offset),
865         LUA_REG(nl80211,txpower),
866         LUA_REG(nl80211,txpower_offset),
867         LUA_REG(nl80211,bitrate),
868         LUA_REG(nl80211,signal),
869         LUA_REG(nl80211,noise),
870         LUA_REG(nl80211,quality),
871         LUA_REG(nl80211,quality_max),
872         LUA_REG(nl80211,mode),
873         LUA_REG(nl80211,ssid),
874         LUA_REG(nl80211,bssid),
875         LUA_REG(nl80211,country),
876         LUA_REG(nl80211,assoclist),
877         LUA_REG(nl80211,txpwrlist),
878         LUA_REG(nl80211,scanlist),
879         LUA_REG(nl80211,freqlist),
880         LUA_REG(nl80211,countrylist),
881         LUA_REG(nl80211,hwmodelist),
882         LUA_REG(nl80211,htmodelist),
883         LUA_REG(nl80211,encryption),
884         LUA_REG(nl80211,mbssid_support),
885         LUA_REG(nl80211,hardware_id),
886         LUA_REG(nl80211,hardware_name),
887         LUA_REG(nl80211,phyname),
888         { NULL, NULL }
889 };
890 #endif
891
892 /* Wext table */
893 static const luaL_reg R_wext[] = {
894         LUA_REG(wext,channel),
895         LUA_REG(wext,frequency),
896         LUA_REG(wext,frequency_offset),
897         LUA_REG(wext,txpower),
898         LUA_REG(wext,txpower_offset),
899         LUA_REG(wext,bitrate),
900         LUA_REG(wext,signal),
901         LUA_REG(wext,noise),
902         LUA_REG(wext,quality),
903         LUA_REG(wext,quality_max),
904         LUA_REG(wext,mode),
905         LUA_REG(wext,ssid),
906         LUA_REG(wext,bssid),
907         LUA_REG(wext,country),
908         LUA_REG(wext,assoclist),
909         LUA_REG(wext,txpwrlist),
910         LUA_REG(wext,scanlist),
911         LUA_REG(wext,freqlist),
912         LUA_REG(wext,countrylist),
913         LUA_REG(wext,hwmodelist),
914         LUA_REG(wext,htmodelist),
915         LUA_REG(wext,encryption),
916         LUA_REG(wext,mbssid_support),
917         LUA_REG(wext,hardware_id),
918         LUA_REG(wext,hardware_name),
919         LUA_REG(wext,phyname),
920         { NULL, NULL }
921 };
922
923 /* Common */
924 static const luaL_reg R_common[] = {
925         { "type", iwinfo_L_type },
926         { "__gc", iwinfo_L__gc  },
927         { NULL, NULL }
928 };
929
930
931 LUALIB_API int luaopen_iwinfo(lua_State *L) {
932         luaL_register(L, IWINFO_META, R_common);
933
934 #ifdef USE_WL
935         luaL_newmetatable(L, IWINFO_WL_META);
936         luaL_register(L, NULL, R_common);
937         luaL_register(L, NULL, R_wl);
938         lua_pushvalue(L, -1);
939         lua_setfield(L, -2, "__index");
940         lua_setfield(L, -2, "wl");
941 #endif
942
943 #ifdef USE_MADWIFI
944         luaL_newmetatable(L, IWINFO_MADWIFI_META);
945         luaL_register(L, NULL, R_common);
946         luaL_register(L, NULL, R_madwifi);
947         lua_pushvalue(L, -1);
948         lua_setfield(L, -2, "__index");
949         lua_setfield(L, -2, "madwifi");
950 #endif
951
952 #ifdef USE_NL80211
953         luaL_newmetatable(L, IWINFO_NL80211_META);
954         luaL_register(L, NULL, R_common);
955         luaL_register(L, NULL, R_nl80211);
956         lua_pushvalue(L, -1);
957         lua_setfield(L, -2, "__index");
958         lua_setfield(L, -2, "nl80211");
959 #endif
960
961         luaL_newmetatable(L, IWINFO_WEXT_META);
962         luaL_register(L, NULL, R_common);
963         luaL_register(L, NULL, R_wext);
964         lua_pushvalue(L, -1);
965         lua_setfield(L, -2, "__index");
966         lua_setfield(L, -2, "wext");
967
968         return 1;
969 }