luci-0.10: merge r8034
[project/luci.git] / contrib / package / iwinfo / src / iwinfo_lualib.h
1 /*
2 * iwinfo - Wireless Information Library - Lua Headers
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 #ifndef __IWINFO_LUALUB_H_
20 #define __IWINFO_LUALIB_H_
21
22 #include <lua.h>
23 #include <lualib.h>
24 #include <lauxlib.h>
25
26 #include "iwinfo.h"
27 #include "iwinfo_wext_scan.h"
28
29
30 const char *IWINFO_CIPHER_NAMES[] = {
31 "NONE",
32 "WEP40",
33 "TKIP",
34 "WRAP",
35 "CCMP",
36 "WEP104",
37 "AES-OCB",
38 "CKIP",
39 };
40
41 const char *IWINFO_KMGMT_NAMES[] = {
42 "NONE",
43 "802.1X",
44 "PSK",
45 };
46
47 const char *IWINFO_AUTH_NAMES[] = {
48 "OPEN",
49 "SHARED",
50 };
51
52
53 #define IWINFO_META "iwinfo"
54 #define IWINFO_WEXT_META "iwinfo.wext"
55
56 #ifdef USE_WL
57 #define IWINFO_WL_META "iwinfo.wl"
58 #endif
59
60 #ifdef USE_MADWIFI
61 #define IWINFO_MADWIFI_META "iwinfo.madwifi"
62 #endif
63
64 #ifdef USE_NL80211
65 #define IWINFO_NL80211_META "iwinfo.nl80211"
66 #endif
67
68
69 #define LUA_REG(type,op) \
70 { #op, iwinfo_L_##type##_##op }
71
72 #define LUA_WRAP_INT(type,op) \
73 static int iwinfo_L_##type##_##op(lua_State *L) \
74 { \
75 const char *ifname = luaL_checkstring(L, 1); \
76 int rv; \
77 if( !type##_get_##op(ifname, &rv) ) \
78 lua_pushnumber(L, rv); \
79 else \
80 lua_pushnil(L); \
81 return 1; \
82 }
83
84 #define LUA_WRAP_STRING(type,op) \
85 static int iwinfo_L_##type##_##op(lua_State *L) \
86 { \
87 const char *ifname = luaL_checkstring(L, 1); \
88 char rv[IWINFO_BUFSIZE]; \
89 memset(rv, 0, IWINFO_BUFSIZE); \
90 if( !type##_get_##op(ifname, rv) ) \
91 lua_pushstring(L, rv); \
92 else \
93 lua_pushnil(L); \
94 return 1; \
95 }
96
97 #define LUA_WRAP_LIST(type,op) \
98 static int iwinfo_L_##type##_##op(lua_State *L) \
99 { \
100 return iwinfo_L_##op(L, type##_get_##op); \
101 }
102
103 #endif
104