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