static int init_server(tConnect *pCon) { int ret =0; memset(pCon, 0, sizeof(tConnect)); ret = init_local_socket(&(pCon->local)); CHK_RET(ret); ret = wait_client_socket(pCon); CHK_RET(ret); return ret; }
/* mode,channel_arr,scantime */ static int l_start_scan(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); CHK_NUM(L, 4); CHK_TAB(L, 5); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_ext_scan_params_t st; st.scan_mode = lua_tointeger(L, 3); assert(st.scan_mode == 1 || st.scan_mode == 2); int i = 0; lua_pushnil(L); while (i < MAX_SCAN_CHAN_CNT && lua_next(L, -2)) { CHK_NUM(L, -1); st.scan_channel_list[i] = lua_tonumber(L, -1); lua_pop(L, 1); i++; } if (i == 0) { lua_pushboolean(L, 1); return 1; } st.channel_num = i; st.scan_per_channel_time = lua_tointeger(L, 4); int ret = start_scan(sock, lua_tostring(L, 2), &st); CHK_RET(ret, mode_ioctl); }
static int l_set_radio_info(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); int i; size_t len; const char *str, *band, *ifname; unsigned int tmp[6] = {0}; ifname = lua_tostring(L, 2); str = lua_tolstring(L, 3, &len); if (len != sizeof("00ffeeff00ff") - 1) { lua_pushnil(L); lua_pushfstring(L, "invalid str %s", str); return 2; } band = lua_tostring(L, 4); if (!(!strncmp(band, "2g", 2) || !strncmp(band, "5g", 2))) { lua_pushnil(L); lua_pushfstring(L, "invalid band %s", band); return 2; } ugw_ext_radio_info_t st; st.ap_devid = strtoull(str, NULL, 16); st.rf_type = (!strncmp(band, "2g", 2)) ? 0 : 1; int ret = set_radio_info(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }
static int set_str_int_int(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); CHK_NUM(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_i_i)(int, char *, int, int); m_s_i_i func = (m_s_i_i)mode_ioctl->ioctl_func; assert(func); int ret = func(sock, lua_tostring(L, 2), lua_tointeger(L, 3), lua_tointeger(L, 4)); CHK_RET(ret, mode_ioctl); }
static int set_str_str(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_s)(int, char *, char *); m_s_s func = (m_s_s)mode_ioctl->ioctl_func; assert(func); int ret = func(sock, lua_tostring(L, 2), lua_tostring(L, 3)); CHK_RET(ret, mode_ioctl); }
/* ifname, wlanid */ static int l_set_vap_info(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_ext_vap_info_t st; const char *ifname = lua_tostring(L, 2); st.wlan_id = (uint32_t)lua_tointeger(L, 3); int ret = set_vap_info(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }
int start_server(void) { int ret = DC_SUCCESS; tConnect con; SOCKET_START_UP(); CHK_RET(init_server(&con)); SOCKET_CLEAN_UP(); return ret; }
static int set_str_int_p(lua_State *L, void *param) { CHK_STR(L, 2); CHK_NUM(L, 3); CHK_STR(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); typedef int (*m_s_i_s_i)(int, char *, int, char *, int); m_s_i_s_i func = (m_s_i_s_i)mode_ioctl->ioctl_func; assert(func); size_t len; char *data; data = lua_tolstring(L, 4, &len); if (!data) { lua_pushnil(L); lua_pushfstring(L, "invalid param 4"); return 2; } int ret = func(sock, lua_tostring(L, 2), lua_tointeger(L, 3), data, len); CHK_RET(ret, mode_ioctl); }
/* ifname, wlanid */ static int l_vap_add_acl_mac(lua_State *L, void *param) { CHK_STR(L, 2); CHK_STR(L, 3); CHK_NUM(L, 4); mode_ioctl_st *mode_ioctl = (mode_ioctl_st *)param; assert(mode_ioctl && mode_ioctl->ioctl_func); ugw_sta_acl_mac_t st; const char *ifname = lua_tostring(L, 2); st.seconds = (uint32_t)lua_tointeger(L, 4); // TODO unsigned char ? const char *mac = lua_tostring(L, 3); int ret = sscanf(mac, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", \ &st.mac[0], &st.mac[1], &st.mac[2], &st.mac[3], &st.mac[4], &st.mac[5]); if (ret != 6) { lua_pushnil(L); lua_pushfstring(L, "invalid mac %s", mac); return 2; } ret = vap_add_acl_mac(sock, ifname, &st); CHK_RET(ret, mode_ioctl); }