wifimanager: update wifimanager to tina 3.06, version 18.10.31

This commit is contained in:
lijie02 2018-12-14 16:53:05 +08:00
parent ad9265045b
commit b4308f1987
69 changed files with 4894 additions and 6650 deletions

View File

@ -1,59 +1,76 @@
include $(TOPDIR)/rules.mk
include $(TINA_BUILD_TOP)/package/netease/Makefile.common
PKG_NAME:=wifimanager
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
include $(BUILD_DIR)/package.mk
define Package/wifimanager/Default
define Package/$(PKG_NAME)/Default
SECTION:=utils
CATEGORY:=Allwinner
TITLE:=Tina wifi manager
DEPENDS:=+libpthread +libstdcpp +liballwinner-base +libiconv-full $(MAKE_COMMON_DEPEND)
TITLE:=Tina wifimanager
DEPENDS:=+libpthread +libstdcpp +liballwinner-base $(MAKE_COMMON_DEPEND)
endef
define Package/wifimanager
define Package/$(PKG_NAME)
$(call Package/wifimanager/Default)
MENU:=1
DEFAULT:=1
endef
define Package/wifimanager-demo
define Package/$(PKG_NAME)-demo
$(call Package/wifimanager/Default)
TITLE:=Tina wifi app demo
DEPENDS := +wifimanager +libiconv-full
TITLE:=Tina wifimanager app demo
DEPENDS := wifimanager +wifimanager
endef
define Package/wifimanager-smartaudio
define Package/$(PKG_NAME)-daemon-demo
$(call Package/wifimanager/Default)
TITLE:=Tina wifimanager daemon demo
DEPENDS := wifimanager +wifimanager
endef
define Package/$(PKG_NAME)-smartaudio
$(call Package/wifimanager/Default)
TITLE:=netease smart audio
DEPENDS := +wifimanager +libiconv-full +rftest $(MAKE_COMMON_DEPEND)
endef
define Package/wifimanager/description
define Package/$(PKG_NAME)/description
Tina wifi manager
endef
define Package/wifimanager-demo/description
Tina wifi app demo
define Package/$(PKG_NAME)/config
config WIFIMANAGER_ENABLE_DAEMON
bool "Enable wifimanager daemon support"
depends on PACKAGE_wifimanager
default n
endef
define Package/$(PKG_NAME)-demo/description
Tina wifimanager app demo
endef
define Package/$(PKG_NAME)-daemon-demo/description
Tina wifimanager daemon demo
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) -r ./src $(PKG_BUILD_DIR)/
$(CP) -r ./demo $(PKG_BUILD_DIR)/
$(CP) -r ./daemon-demo $(PKG_BUILD_DIR)/
$(CP) -r ./smartaudio $(PKG_BUILD_DIR)/
endef
define Build/Configure
endef
define Build/Compile
define Build/Compile/$(PKG_NAME)
#libwifimg.so
$(MAKE) -C $(PKG_BUILD_DIR)/src/ \
$(MAKE) -C $(PKG_BUILD_DIR)/src/core/ \
ARCH="$(TARGET_ARCH)" \
AR="$(TARGET_AR)" \
CC="$(TARGET_CC)" \
@ -63,7 +80,21 @@ define Build/Compile
CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \
all
#wifitest
ifeq ($(CONFIG_WIFIMANAGER_ENABLE_DAEMON), y)
$(MAKE) -C $(PKG_BUILD_DIR)/src/daemon/ \
ARCH="$(TARGET_ARCH)" \
AR="$(TARGET_AR)" \
CC="$(TARGET_CC)" \
CXX="$(TARGET_CXX)" \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)" \
CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \
all
endif
endef
ifeq ($(CONFIG_PACKAGE_wifimanager-demo),y)
define Build/Compile/$(PKG_NAME)-demo
$(MAKE) -C $(PKG_BUILD_DIR)/demo/ \
ARCH="$(TARGET_ARCH)" \
AR="$(TARGET_AR)" \
@ -74,28 +105,64 @@ define Build/Compile
CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \
all
endef
endif
ifeq ($(CONFIG_PACKAGE_wifimanager-daemon-demo),y)
define Build/Compile/$(PKG_NAME)-daemon-demo
$(MAKE) -C $(PKG_BUILD_DIR)/daemon-demo/ \
ARCH="$(TARGET_ARCH)" \
AR="$(TARGET_AR)" \
CC="$(TARGET_CC)" \
CXX="$(TARGET_CXX)" \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS)" \
CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \
all
endef
endif
define Build/Compile
$(Build/Compile/$(PKG_NAME))
$(Build/Compile/$(PKG_NAME)-demo)
$(Build/Compile/$(PKG_NAME)-daemon-demo)
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/lib
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libwifimg.so $(1)/lib
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include
ifeq ($(CONFIG_WIFIMANAGER_ENABLE_DAEMON), y)
$(INSTALL_DIR) $(1)/bin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libwifid.so $(1)/lib
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_daemon $(1)/bin
$(INSTALL_BIN) ./files/wifi_daemon.init $(1)/etc/init.d/wifi_daemon
endif
endef
define Package/wifimanager/install
define Package/$(PKG_NAME)/install
$(INSTALL_DIR) $(1)/lib
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_DIR) $(1)/etc/wifi
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libwifimg.so $(1)/lib
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/include/*.h $(1)/usr/include
$(INSTALL_DATA) ./src/wpa_supplicant.conf $(1)/etc/wifi
$(INSTALL_DATA) ./src/wpa_supplicant_src.conf $(1)/etc/wifi
$(INSTALL_DATA) ./src/wpa_supplicant_overlay.conf $(1)/etc/wifi
$(INSTALL_BIN) ./wifi.init $(1)/etc/wifi/wifi
$(INSTALL_BIN) ./udhcpc_wlan0.init $(1)/etc/wifi/udhcpc_wlan0
$(INSTALL_DATA) ./files/wpa_supplicant.conf $(1)/etc/wifi
$(INSTALL_DATA) ./files/wpa_supplicant_src.conf $(1)/etc/wifi
$(INSTALL_DATA) ./files/wpa_supplicant_overlay.conf $(1)/etc/wifi
$(INSTALL_BIN) ./files/wifi.init $(1)/etc/wifi/wifi
$(INSTALL_BIN) ./files/udhcpc_wlan0.init $(1)/etc/wifi/udhcpc_wlan0
ifeq ($(CONFIG_WIFIMANAGER_ENABLE_DAEMON), y)
$(INSTALL_DIR) $(1)/bin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/lib/libwifid.so $(1)/lib
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_daemon $(1)/bin
$(INSTALL_BIN) ./files/wifi_daemon.init $(1)/etc/init.d/wifi_daemon
endif
endef
define Package/wifimanager-smartaudio/install
define Package/$(PKG_NAME)-smartaudio/install
$(MAKE) -C $(PKG_BUILD_DIR)/smartaudio/ \
ARCH="$(TARGET_ARCH)" \
@ -112,7 +179,7 @@ define Package/wifimanager-smartaudio/install
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/app_wifi_manager $(1)/bin
endef
define Package/wifimanager-demo/install
define Package/$(PKG_NAME)-demo/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_DIR) $(1)/etc/wifi
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_connect_ap_test $(1)/bin
@ -126,10 +193,13 @@ define Package/wifimanager-demo/install
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_add_network_test $(1)/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_longtime_test $(1)/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_remove_all_networks_test $(1)/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifi_stop_restart_scan_test $(1)/bin
$(INSTALL_BIN) ./wifitest.sh $(1)/etc/wifi
endef
$(eval $(call BuildPackage,wifimanager))
$(eval $(call BuildPackage,wifimanager-demo))
$(eval $(call BuildPackage,wifimanager-smartaudio))
define Package/$(PKG_NAME)-daemon-demo/install
$(INSTALL_DIR) $(1)/bin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/wifid $(1)/bin
endef
$(eval $(call BuildPackage,$(PKG_NAME)))
$(eval $(call BuildPackage,$(PKG_NAME)-demo))
$(eval $(call BuildPackage,$(PKG_NAME)-daemon-demo))
$(eval $(call BuildPackage,$(PKG_NAME)-smartaudio))

View File

@ -0,0 +1,72 @@
wifimanager 版本更新说明
----------------------------------------------------------------------------------------------------------
version: 18.11.05:
1. 添加log系统,打印可以重定向到文件,syslog,标准输出.
2. 提升联网时间,规范打印输出(部分接口,wifi事件有一些改变).基于该版本可快速按照如下方式合并.
(1)将之前wifi_event_handle函数替换为新版本的demo中wifi_state_handle.
(2)去掉 while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING)循环等待,修改为用
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)去判断是否连接上.
(3)去掉无关的变量定义.
(4)详情参考tina/package/allwinner/wifimanager/demo/wifi_connect_ap.cpp
3. 增加wifi daemon以及提供操作wifi daemon API接口.
在make menuconfig中使能以下选项.
Allwinner --->
-*- wifimanager............................................. Tina wifimanager --->
[*] Enable wifimanager daemon support --①
<*> wifimanager-daemon-demo..................... Tina wifimanager daemon demo --②
①:选上该选项后,编译后将生成wifi_daemon可以执行程序.
②:基于wifi daemon API编写,用于控制wifi_daemon的demo
(1) wifi_daemon:使能①后,每次开机将会自启动wifi_daemon,将会从/etc/wifi/wpa_supplicant.conf自动搜索可用网络
进行连接.网络连接成功后,如果中途异常断开,将会自动从配置文件中搜索其他网络进行连接,即维护网络自动重连及其他异
常问题,不需要用户关心.
(2) wifi daemon API:提供以下接口,可供用户编程控制wifi_daemon进行相关操作.
a. int aw_wifid_connect_ap(const char *ssid, const char *passwd,enum cn_event *ptrEvent);
连接网络,如果连接成功,将保存到/etc/wifi/wpa_supplicant.conf文件中,下次开机将会自动连接.
b. int aw_wifid_get_scan_results(char *results,int len);
扫描周围网络.
c. int aw_wifid_list_networks(char *reply, size_t len);
列出存放在/etc/wifi/wpa_supplicant.conf的网络信息.
d. int aw_wifid_get_status(struct wifi_status *sptr);
获取当前网络的状态(是否连接上网络,如果连接上,返回对应的ssid)
f. int aw_wifid_remove_networks(char *pssid,int len);
移除指定保存在网络配置文件中的网络信息.
g. void aw_wifid_open(void);
打开wifi daemon,一般情况wifi daemon是开机自启动的,该接口主要是配合aw_wifid_close使用.
h. void aw_wifid_close(void);
关闭wifi daemon,网络将会断开.
(3) wifid: 基于(2)编写的demo.
wifid 参数如下:
-h, --help print this help and exit
-c, --connect connect AP,-c <ssid> <password>
-s, --scan scan AP
-l, --list_network list network
-t, --status get wifi status
-r, --remove_net remove network in config,-r <ssid>
-o, --open open wifi daemon
-d, --close close wifi daemon
example:
连接网络 : wifid -c AW-TEST 12345678 或者 wifid --connect AW-TEST 12345678
扫描网络 : wifid -s 或者 wifid --scan
列出网络 : wifid -l 或者 wifid --list_network
获取网络状态 : wifid -t 或者 wifid --status
移除网络 : wifid -r AW-TEST 或者 wifid --remove_net AW-TEST
其他详细修改,请参考文档<Tina_Wifimanager_API>
----------------------------------------------------------------------------------------------------------

View File

@ -0,0 +1,19 @@
include $(TOPDIR)/rules.mk
include $(TINA_BUILD_TOP)/package/netease/Makefile.common
include $(TINA_BUILD_TOP)/build/nls.mk
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \
-I ../src/include
local_LDFLAGS := $(BUILD_COMMON_LIB)
install:
-@mkdir -p $(CONFIG_PREFIX)/usr/bin
wifid: wifid_cmd.c
$(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifid -lwifimg
@cp -f wifid $(CONFIG_PREFIX)/usr/bin
####################################################################
all: install wifid
clean:
rm -rf wifid

View File

@ -0,0 +1,123 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include "wmg_debug.h"
#include <uvdbus/log.h>
#include "wifid_cmd.h"
int main(int argc,char *argv[])
{
int opt;
const char *opts = "c:hslrtdo";
char scan_results[SCAN_MAX];
char list_net_results[LIST_NETWORK_MAX];
int debug_level = 0;
struct wifi_status status = {
.state = STATE_UNKNOWN,
.ssid = {'\0'},
};
int ret = -1;
enum cn_event event = DA_UNKNOWN;
struct option longopts[] = {
{"connect",required_argument,NULL,'c'},
{"scan",no_argument,NULL,'s'},
{"list_network",no_argument,NULL,'l'},
{"remove_network",no_argument,NULL,'r'},
{"status",no_argument,NULL,'t'},
{"help",no_argument,NULL,'h'},
{"close",no_argument,NULL,'d'},
{"open",no_argument,NULL,'o'},
{"debug",required_argument,NULL,1},
{ 0, 0, 0, 0 },
};
//wmg_set_debug_level(MSG_EXCESSIVE);
if(argc == 1)
goto usage;
while ((opt = getopt_long(argc, argv, opts, longopts, NULL)) != -1){
switch(opt){
case 1:
debug_level = atoi(optarg);
printf("debug log level :%d\n",debug_level);
wmg_set_debug_level(debug_level);
break;
case 'c'/* --commnad */:
if(argc < 4 || argc > 6){
printf(" -c, --connect\t\tconnect AP,-c <ssid> <password>\n");
return EXIT_SUCCESS;
}
printf("==============================================\n");
printf("connecting ssid:%s passward:%s\n",argv[optind-1],argv[optind]);
aw_wifid_connect_ap(argv[optind-1],argv[optind],&event);
if(event == DA_CONNECTED){
LOG_EX(LOG_Debug, "connected ap successful\n");
}else {
LOG_EX(LOG_Debug, "connected ap failed:%s\n",connect_event_txt(event));
}
printf("==============================================\n");
return EXIT_SUCCESS;
case 'h'/* --help */:
usage:
printf(" -h, --help\t\tprint this help and exit\n");
printf(" -c, --connect\t\tconnect AP,-c <ssid> <password>\n");
printf(" -s, --scan\t\tscan AP\n");
printf(" -l, --list_network\tlist network\n");
printf(" -t, --status\t\tget wifi status\n");
printf(" -r, --remove_net\tremove network in config,-r <ssid>\n");
printf(" -o, --open\t\topen wifi daemon\n");
printf(" -d, --close\t\tclose wifi daemon\n");
printf(" --debug, \t\tset debug log level,--debug <num>\n");
return EXIT_SUCCESS;
case 's'/*--scan*/:
ret = aw_wifid_get_scan_results(scan_results,SCAN_MAX);
if(ret != -1){
LOG_EX(LOG_Debug, "scan results:\n%s\n",scan_results);
}
return EXIT_SUCCESS;
case 'l'/*--list_network*/:
ret = aw_wifid_list_networks(list_net_results,LIST_NETWORK_MAX);
if(ret != -1){
LOG_EX(LOG_Debug, "list networks results:\n%s\n",list_net_results);
}
return EXIT_SUCCESS;
case 't'/*--disconnect*/:
ret = aw_wifid_get_status(&status);
if(ret >= 0) {
LOG_EX(LOG_Debug, "wifi state: %s\n",wmg_state_txt(status.state));
if(status.state == NETWORK_CONNECTED)
LOG_EX(LOG_Debug, "connected ssid:%s\n",status.ssid);
}
return EXIT_SUCCESS;
case 'r'/*--remove_net*/:
if(argc < 2){
printf(" -r, --remove_net\tremove network in config,-r <ssid>\n");
return EXIT_SUCCESS;
}
printf("removing ssid:%s\n",argv[optind]);
aw_wifid_remove_networks(argv[optind],strlen(argv[optind]));
return EXIT_SUCCESS;
case 'o'/*--remove_net*/:
aw_wifid_open();
return EXIT_SUCCESS;
case 'd'/*--remove_net*/:
aw_wifid_close();
return EXIT_SUCCESS;
default:
fprintf(stderr, "Try '%s --help' for more information.\n", argv[0]);
return EXIT_FAILURE;
}
if (optind == argc)
goto usage;
}
}

View File

@ -4,14 +4,14 @@ include $(TINA_BUILD_TOP)/build/nls.mk
target = wifi_connect_ap_test
MK_PWD = ./
INCLUDES += -I$(CONFIG_PREFIX)/usr/include -I$(MK_PWD)/softap \
-I ../src/include
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \
-I ../src/core/include
CPP_SRCS = wifi_connect_ap.cpp
CPP_OBJS := $(CPP_SRCS:.cpp=.o)
LIB_OBJS = $(CPP_OBJS)
local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv
local_LDFLAGS := $(BUILD_COMMON_LIB)
install:
-@mkdir -p $(CONFIG_PREFIX)/usr/bin
@ -61,11 +61,6 @@ wifi_longtime_test: wifi_longtime_test.c
$(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg
@cp -f wifi_longtime_test $(CONFIG_PREFIX)/usr/bin
#wifi_stop_restart_scan_test
wifi_stop_restart_scan_test: wifi_stop_restart_scan_test.c
$(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg
@cp -f wifi_stop_restart_scan_test $(CONFIG_PREFIX)/usr/bin
#wifi_connect_ap_test
$(CPP_OBJS): %.o: %.cpp
$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
@ -79,6 +74,6 @@ wifi_remove_all_networks_test: wifi_remove_all_networks.c
@cp -f wifi_remove_all_networks_test $(CONFIG_PREFIX)/usr/bin
####################################################################
all: install $(target) wifi_on_off_test wifi_connect_chinese_ap_test wifi_scan_results_test wifi_list_networks_test wifi_remove_network_test wifi_connect_ap_with_netid_test wifi_get_netid_test wifi_add_network_test wifi_longtime_test wifi_remove_all_networks_test wifi_stop_restart_scan_test
all: install $(target) wifi_on_off_test wifi_connect_chinese_ap_test wifi_scan_results_test wifi_list_networks_test wifi_remove_network_test wifi_connect_ap_with_netid_test wifi_get_netid_test wifi_add_network_test wifi_longtime_test wifi_remove_all_networks_test
clean:
rm -rf $(target) wifi_on_off_test wifi_connect_chinese_ap_test wifi_scan_results_test wifi_list_networks_test wifi_remove_network_test wifi_connect_ap_with_netid_test wifi_get_netid_test wifi_add_network_test wifi_longtime_test wifi_remove_all_networks_test wifi_stop_restart_scan_test $(LIB_OBJS)
rm -rf $(target) wifi_on_off_test wifi_connect_chinese_ap_test wifi_scan_results_test wifi_list_networks_test wifi_remove_network_test wifi_connect_ap_with_netid_test wifi_get_netid_test wifi_add_network_test wifi_longtime_test wifi_remove_all_networks_test $(LIB_OBJS)

View File

@ -6,121 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "scan.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_INFO,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -129,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -184,9 +106,9 @@ void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
}
int check_params(int num, char *str[]){
int check_paras(int num, char *str[]){
if(num < 4 || num >5){
wmg_printf(MSG_ERROR,"ERROR: params more or less!\n");
wmg_printf(MSG_ERROR,"ERROR: paras more or less!\n");
return -1;
}
int mgmt = atoi(str[3]);
@ -227,7 +149,6 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0, switch_int = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
tKEY_MGMT key_mgmt = WIFIMG_NONE;
@ -236,12 +157,13 @@ int main(int argv, char *argc[]){
return -1;
}
if(check_params(argv, argc)){
if(check_paras(argv, argc)){
print_help();
return -1;
}
if(set_log_level(argv, argc))
return -1;
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi connect ap test\n");
wmg_printf(MSG_INFO,"***ssid :%s\n",argc[1]);
@ -249,45 +171,36 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"*********************************\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
event_label++;
event_label++;
switch_int= atoi(argc[3]);
wmg_printf(MSG_DEBUG,"The switch_int is %d\n",switch_int);
wmg_printf(MSG_DEBUG,"The switch_int is %d\n",switch_int);
switch(switch_int)
{
switch(switch_int)
{
case 0: key_mgmt = WIFIMG_NONE; break;
case 1: key_mgmt = WIFIMG_WPA_PSK; break;
case 2: key_mgmt = WIFIMG_WPA2_PSK; break;
case 3: key_mgmt = WIFIMG_WEP; break;
default: ; break;
}
p_wifi_interface->add_network(argc[1], key_mgmt, argc[2], event_label);
default: ; break;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
p_wifi_interface->add_network(argc[1], key_mgmt, argc[2], event_label);
wmg_printf(MSG_INFO,"\n******************************\n");
if(aw_wifi_get_wifi_state()== WIFIMG_WIFI_CONNECTED){
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)
wmg_printf(MSG_INFO,"Wifi connect ap : Success!\n");
}
else{
else
wmg_printf(MSG_ERROR,"Wifi connect ap : Failure!\n");
}
wmg_printf(MSG_INFO,"******************************\n");
return 0;
wmg_printf(MSG_INFO,"==================================\n");
return 0;
}

View File

@ -6,136 +6,44 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
char scan_results[4096];
int len = 0;
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
}
void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
wmg_printf(MSG_INFO,"NAME:\n\twifi_connect_ap_test\n");
@ -153,9 +61,9 @@ void print_help(){
}
int check_params(int num, char *str[]){
int check_paras(int num, char *str[]){
if(num <3 || num >4){
wmg_printf(MSG_ERROR,"ERROR: params more or less!\n");
wmg_printf(MSG_ERROR,"ERROR: paras more or less!\n");
return -1;
}
@ -187,7 +95,6 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
@ -195,48 +102,37 @@ int main(int argv, char *argc[]){
return -1;
}
if(check_params(argv, argc)){
if(check_paras(argv, argc)){
print_help();
return -1;
}
if(set_log_level(argv, argc) == -1)
return -1;
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi connect ap test\n");
wmg_printf(MSG_INFO,"***ssid :%s\n",argc[1]);
wmg_printf(MSG_INFO,"***password:%s\n",argc[2]);
wmg_printf(MSG_INFO,"*********************************\n");
wmg_printf(MSG_DEBUG,"\n*********************************\n");
wmg_printf(MSG_DEBUG,"***Start wifi connect ap test\n");
wmg_printf(MSG_DEBUG,"***ssid :%s\n",argc[1]);
wmg_printf(MSG_DEBUG,"***password:%s\n",argc[2]);
wmg_printf(MSG_DEBUG,"*********************************\n");
wmg_printf(MSG_INFO,"==================================\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
event_label++;
p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
wmg_printf(MSG_INFO,"\n******************************\n");
if(aw_wifi_get_wifi_state()== WIFIMG_WIFI_CONNECTED){
p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)
wmg_printf(MSG_INFO,"Wifi connect ap : Success!\n");
}
else{
else
wmg_printf(MSG_ERROR,"Wifi connect ap : Failure!\n");
}
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"==================================\n");
return 0;
}

View File

@ -6,121 +6,47 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_INFO,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -129,8 +55,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -151,9 +75,9 @@ void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
}
int check_params(int num, char *str[]){
int check_paras(int num, char *str[]){
if(num < 2 || num >3){
wmg_printf(MSG_ERROR,"ERROR: params more or less!\n");
wmg_printf(MSG_ERROR,"ERROR: paras more or less!\n");
return -1;
}
return 0;
@ -184,17 +108,15 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0, i = 0;
int times = 0, event_label = 0;
char ssid[256] = {0}, scan_results[4096] = {0}, reply[4069]= {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
print_help();
return -1;
}
if(check_params(argv, argc)){
if(check_paras(argv, argc)){
print_help();
return -1;
}
@ -207,59 +129,31 @@ int main(int argv, char *argc[]){
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
event_label++;
/* p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
ret = p_wifi_interface->connect_ap_with_netid(argc[1], event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
printf("wifi state busing,waiting\n");
usleep(2000000);
}
printf("******************************\n");
printf("Wifi connect ap test: Success!\n");
printf("******************************\n");
for(i=0;i<10;i++)
{
usleep(2000000);
}
*/
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi connect ap with netid test!***\n");
wmg_printf(MSG_INFO,"*********************************\n");
ret = (p_wifi_interface->connect_ap_with_netid(argc[1], event_label));
wmg_printf(MSG_DEBUG,"ret is %d", ret);
if(ret==0)
{
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi connect ap with netid test: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
}
else
{
wmg_printf(MSG_ERROR,"Wifi connect ap with netid test failed!\n");
}
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)
wmg_printf(MSG_INFO,"Wifi connect ap with netid test: Success!!\n");
else
wmg_printf(MSG_ERROR,"Wifi connect ap with netid test failed!!\n");
wmg_printf(MSG_INFO,"==================================\n");
return 0;
}

View File

@ -6,122 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_INFO,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -130,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -179,7 +100,6 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
@ -188,7 +108,7 @@ int main(int argv, char *argc[]){
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR: No need other params!\n");
wmg_printf(MSG_ERROR,"ERROR: No need other paras!\n");
print_help();
return -1;
}
@ -199,20 +119,17 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"*********************************\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
/* scan test */
event_label++;
p_wifi_interface->start_scan(event_label);
len = 4096;
p_wifi_interface->get_scan_results(scan_results, &len);
wmg_printf(MSG_INFO,"scan results: \n");
@ -233,19 +150,11 @@ int main(int argv, char *argc[]){
ssid[9] = '\0';
p_wifi_interface->connect_ap(ssid, "12345678", event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
wmg_printf(MSG_INFO,"\n******************************\n");
if(aw_wifi_get_wifi_state()== WIFIMG_WIFI_CONNECTED){
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)
wmg_printf(MSG_INFO,"Wifi connect ap : Success!\n");
}
else{
else
wmg_printf(MSG_ERROR,"Wifi connect ap : Failure!\n");
}
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"==================================\n");
return 0;
}

View File

@ -6,122 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_INFO,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -130,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -158,9 +79,9 @@ void print_help(){
}
int check_params(int num, char *str[]){
int check_paras(int num, char *str[]){
if(num < 3 || num >4){
wmg_printf(MSG_ERROR,"ERROR: params more or less!\n");
wmg_printf(MSG_ERROR,"ERROR: paras more or less!\n");
return -1;
}
@ -208,7 +129,7 @@ int main(int argv, char *argc[]){
return -1;
}
if(check_params(argv, argc)){
if(check_paras(argv, argc)){
print_help();
return -1;
}
@ -217,16 +138,17 @@ int main(int argv, char *argc[]){
return -1;
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed \n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi get netid test!***\n");
@ -245,7 +167,7 @@ int main(int argv, char *argc[]){
}
ret = p_wifi_interface->get_netid(argc[1], key_mgmt, net_id);
ret = p_wifi_interface->get_netid(argc[1], key_mgmt, net_id, &id_len);
if(ret == 0){
wmg_printf(MSG_INFO,"The netid of your network is %s\n",net_id);
wmg_printf(MSG_INFO,"The lenght of netid is %d\n",id_len);

View File

@ -6,122 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_INFO,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -130,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -177,7 +98,6 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0, i = 0;
int times = 0, event_label = 0;
char ssid[256] = {0}, scan_results[4096] = {0}, reply[4069]= {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
@ -186,7 +106,7 @@ int main(int argv, char *argc[]){
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR: No need other params!\n");
wmg_printf(MSG_ERROR,"ERROR: No need other paras!\n");
print_help();
return -1;
}
@ -194,61 +114,39 @@ int main(int argv, char *argc[]){
return -1;
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
event_label++;
/* p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
printf("wifi state busing,waiting\n");
usleep(2000000);
}
printf("******************************\n");
printf("Wifi connect ap test: Success!\n");
printf("******************************\n");
for(i=0;i<10;i++)
{
usleep(2000000);
}
*/
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi list networks test!***\n");
wmg_printf(MSG_INFO,"*********************************\n");
ret=( p_wifi_interface->list_networks(reply, sizeof(reply), event_label));
wmg_printf(MSG_DEBUG,"ret is %d\n", ret);
wmg_printf(MSG_DEBUG,"ret is %d\n", ret);
if(ret==0)
{
wmg_printf(MSG_INFO,"%s\n",reply);
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi list networks test: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"%s\n",reply);
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi list networks test: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
}
else
{
wmg_printf(MSG_ERROR,"list_networks failed!\n");
wmg_printf(MSG_ERROR,"list_networks failed!\n");
}
return 0;
}

View File

@ -8,141 +8,46 @@
#include <sys/time.h>
#include <signal.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
#define TEST_TIMES 1001
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static int terminate_flag = 0;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
int terminate_flag = 0;
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
char scan_results[4096];
int len = 0;
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
}
void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
wmg_printf(MSG_INFO,"NAME:\n\twifi_longtime_test\n");
@ -193,12 +98,12 @@ int main(int argv, char *argc[]){
int i = 0, ret = 0, len = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
unsigned long long int total_con_sec = 0, total_con_microsec = 0;
unsigned long long int con_sec = 0, con_microsec = 0;
unsigned long long int total_disc_sec = 0, total_disc_microsec = 0;
unsigned long long int discon_sec = 0, discon_microsec = 0;
int flag = 0;
struct timeval tv1;
struct timeval tv2;
int success_times = 0, fail_times = 0, timeout_times = 0;
@ -211,8 +116,6 @@ int main(int argv, char *argc[]){
}
if(NULL == argc[1]){
//printf("Usage:wifi_long_test <ssid> <psk> [test_times]!\n");
//printf("default test times: %d\n",TEST_TIMES);
print_help();
return -1;
}
@ -222,6 +125,7 @@ int main(int argv, char *argc[]){
ttest_times = atoi(argc[3]);
if(set_log_level(argv,argc))
return -1;
wmg_debug_open_file("/etc/wifi_long_time_test.log");
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start wifi long test!***\n");
@ -235,72 +139,77 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_ERROR,"signal(SIGINT) error\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
for(i=0;i<ttest_times;i++){
event_label++;
gettimeofday(&tv1, NULL);
p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
gettimeofday(&tv1, NULL);
event_label++;
if(flag == 0){
p_wifi_interface->connect_ap("AWTest", "1qaz@WSX", event_label);
flag = 1;
}else {
p_wifi_interface->connect_ap("AW-TEST-BU1-PSW", "Aa123456", event_label);
flag = 0;
}
#if 0
p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
#endif
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED){
wmg_printf(MSG_INFO,"Wifi connect ap : Success!\n");
success_times ++;
}
else{
fail_times ++ ;
wmg_printf(MSG_ERROR,"Wifi connect ap : Failure!\n");
}
wmg_printf(MSG_INFO,"==================================\n");
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(event == WIFIMG_NETWORK_CONNECTED || event == WIFIMG_CONNECT_TIMEOUT)
{
success_times++;
if(event == WIFIMG_CONNECT_TIMEOUT)
timeout_times++;
}
else
{
fail_times++;
}
gettimeofday(&tv2, NULL);
con_microsec = (tv2.tv_sec*1000000 + tv2.tv_usec)-(tv1.tv_sec*1000000 + tv1.tv_usec);
con_sec = con_microsec/1000000;
con_microsec = con_microsec%1000000;
total_con_sec += con_sec;
total_con_microsec += con_microsec;
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"Test Times: %d\nSuccess Times: %d\nFailed Times: %d\n",i+1,success_times,fail_times);
wmg_printf(MSG_INFO,"Connecting time: %llu.%-llu seconds\n", con_sec, con_microsec);
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"Test Times: %d\nSuccess Times: %d\nFailed Times: %d\n",i+1,success_times,fail_times);
wmg_printf(MSG_INFO,"Connecting time: %llu.%-llu seconds\n", con_sec, con_microsec);
wmg_printf(MSG_INFO,"==========================================\n");
sleep(1);
event_label++;
event_label++;
gettimeofday(&tv1, NULL);
p_wifi_interface->disconnect_ap(event_label);
p_wifi_interface->disconnect_ap(event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
gettimeofday(&tv2, NULL);
discon_microsec = (tv2.tv_sec*1000000 + tv2.tv_usec)-(tv1.tv_sec*1000000 + tv1.tv_usec);
discon_sec = discon_microsec/1000000;
discon_microsec = discon_microsec%1000000;
total_disc_sec += discon_sec;
total_disc_microsec += discon_microsec;
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"Disconnecting time: %llu.%-llu seconds\n", discon_sec, discon_microsec);
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"==========================================\n");
wmg_printf(MSG_INFO,"Disconnecting time: %llu.%-llu seconds\n", discon_sec, discon_microsec);
wmg_printf(MSG_INFO,"==========================================\n");
sleep(1);
if(1 == terminate_flag)
exit(-1);
break;
}
total_con_microsec = total_con_sec*1000000+total_con_microsec;
@ -323,6 +232,7 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi connect ap test: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
wmg_debug_close_file();
return 0;
}

View File

@ -6,127 +6,51 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
#define WIFI_ON_OFF_TEST_CNTS 1000
#define WIFI_ON_OFF_TEST_CNTS 10
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
wmg_printf(MSG_INFO,"NAME:\n\twifi_on_off_test\n");
wmg_printf(MSG_INFO,"DESCRIPTION:\n\ttest the stability of wifi module(do wifi on and wifi off 1000 times)\n");
wmg_printf(MSG_INFO,"DESCRIPTION:\n\ttest the stability of wifi module(do wifi on and wifi off 10 times)\n");
wmg_printf(MSG_INFO,"USAGE:\n\twifi_on_off_test\n");
wmg_printf(MSG_INFO,"--------------------------------------MORE---------------------------------------\n");
wmg_printf(MSG_INFO,"The way to get help information:\n");
@ -139,11 +63,11 @@ void print_help(){
*/
static int set_log_level(int argv, char *argc[])
{
if(argv >=2 && !strncmp(argc[1],"d",1)){
char *debug = argc[1];
if(strlen(debug) >=2 && debug[1] >= '0' &&
debug[1] <= '5'){
wmg_set_debug_level(debug[1] - '0');
if(argv >=2 && !strncmp(argc[2],"d",1)){
char *debug = argc[2];
if(strlen(debug) >=2 && debug[2] >= '0' &&
debug[2] <= '5'){
wmg_set_debug_level(debug[2] - '0');
return 0;
}else{
printf("Illegal level\n");
@ -157,23 +81,30 @@ static int set_log_level(int argv, char *argc[])
int main(int argv, char *argc[]){
int ret = 0;
int i = 0, event_label = 0;
int onOffTestCnt = WIFI_ON_OFF_TEST_CNTS;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
if(argv == 3 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
print_help();
return -1;
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR:No need other params\n");
if(argv < 1 || argv >3){
wmg_printf(MSG_ERROR,"ERROR:No need other paras\n");
print_help();
return -1;
}
if(set_log_level(argv,argc))
return -1;
if(NULL == argc[1])
onOffTestCnt = WIFI_ON_OFF_TEST_CNTS;
else
onOffTestCnt = atoi(argc[1]);
event_label=rand();
for(i=0; i<WIFI_ON_OFF_TEST_CNTS;i++)
wmg_printf(MSG_INFO,"on off test %d times\n",onOffTestCnt);
for(i=0; i<onOffTestCnt;i++)
{
wmg_printf(MSG_INFO,"\n***************************\n");
wmg_printf(MSG_INFO,"Do wifi on off test %d times\n", i);
@ -181,10 +112,10 @@ int main(int argv, char *argc[]){
event_label++;
/* turn on wifi */
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL)
{
wmg_printf(MSG_ERROR,"Test failed: wifi on failed with event 0x%x\n", event);
wmg_printf(MSG_ERROR,"Test failed: wifi on failed \n");
return -1;
}
@ -198,12 +129,6 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_ERROR,"Test failed: wifi off error!\n");
return -1;
}
/* wait event */
while(event != WIFIMG_WIFI_OFF_SUCCESS)
{
usleep(200);
}
}
wmg_printf(MSG_INFO,"********************************\n");

View File

@ -6,118 +6,42 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
@ -129,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -173,7 +95,6 @@ static int set_log_level(int argv, char *argc[])
int main(int argv, char *argc[]){
int ret = 0;
int times = 0, event_label = 0;
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
@ -182,7 +103,7 @@ int main(int argv, char *argc[]){
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR:No need other params\n");
wmg_printf(MSG_ERROR,"ERROR:No need other paras\n");
print_help();
return -1;
}
@ -193,38 +114,26 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"*********************************\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
event_label++;
ret = (p_wifi_interface->disconnect_ap(event_label));
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
while(aw_wifi_get_wifi_state() != WIFIMG_WIFI_DISCONNECTED && times < 5){
wmg_printf(MSG_INFO,"wifi state is not disconnected\n");
times++;
usleep(2000000);
}
if(times >= 5){
wmg_printf(MSG_ERROR,"wifi state can not change to disconnected,remove all networks failed\n");
return -1;
}
if(aw_wifi_get_wifi_state() == DISCONNECTED){
wmg_printf(MSG_INFO,"wifi state is disconnected\n");
}
event_label++;
ret = (p_wifi_interface->remove_all_networks());
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(ret == 0)
{

View File

@ -6,122 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -130,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -158,9 +79,9 @@ void print_help(){
}
int check_params(int num, char *str[]){
int check_paras(int num, char *str[]){
if(num != 3){
wmg_printf(MSG_ERROR,"ERROR: params more or less!\n");
wmg_printf(MSG_ERROR,"ERROR: paras more or less!\n");
return -1;
}
@ -199,7 +120,6 @@ int main(int argv, char *argc[]){
int ret = 0, switch_int = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
tKEY_MGMT key_mgmt = WIFIMG_NONE;
@ -208,7 +128,7 @@ int main(int argv, char *argc[]){
return -1;
}
if(check_params(argv, argc)){
if(check_paras(argv, argc)){
print_help();
return -1;
}
@ -219,22 +139,23 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"*********************************\n");
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed event\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
event_label++;
wmg_printf(MSG_INFO,"The input string is %s\n",argc[2]);
wmg_printf(MSG_INFO,"The input string is %s\n",argc[2]);
switch_int= atoi(argc[2]);
wmg_printf(MSG_INFO,"The switch_int is %d\n",switch_int);
@ -249,10 +170,6 @@ int main(int argv, char *argc[]){
ret = (p_wifi_interface->remove_network(argc[1], key_mgmt));
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
if(ret == 0)
{
wmg_printf(MSG_INFO,"******************************\n");

View File

@ -6,122 +6,45 @@
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
#include "wifi_udhcpc.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
static void wifi_state_handle(struct Manager *w, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
switch(w->StaEvt.state)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case CONNECTING:
{
wmg_printf(MSG_INFO,"Connecting to the network......\n");
break;
}
case CONNECTED:
{
wmg_printf(MSG_INFO,"Connected to the AP\n");
start_udhcpc();
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case OBTAINING_IP:
{
wmg_printf(MSG_INFO,"Getting ip address......\n");
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
case NETWORK_CONNECTED:
{
wmg_printf(MSG_DEBUG,"Successful network connection\n");
break;
}
case DISCONNECTED:
{
wmg_printf(MSG_ERROR,"Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
@ -130,8 +53,6 @@ void *app_scan_task(void *args)
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
@ -177,7 +98,6 @@ int main(int argv, char *argc[]){
int ret = 0, len = 0, i = 0;
int times = 0, event_label = 0;
char ssid[256] = {0}, scan_results[4096] = {0}, reply[4069]= {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
@ -186,7 +106,7 @@ int main(int argv, char *argc[]){
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR: No need other params!\n");
wmg_printf(MSG_ERROR,"ERROR: No need other paras!\n");
print_help();
return -1;
}
@ -194,77 +114,34 @@ int main(int argv, char *argc[]){
return -1;
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
wmg_printf(MSG_ERROR,"wifi on failed\n");
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
//pthread_create(&app_scan_tid, NULL, &app_scan_task,(void *)p_wifi_interface);
if(aw_wifi_get_wifi_state() == CONNECTED){
wmg_printf(MSG_INFO,"auto connected Successful !!!!\n");
wmg_printf(MSG_INFO,"==================================\n");
}
event_label++;
/* p_wifi_interface->connect_ap(argc[1], argc[2], event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
printf("wifi state busing,waiting\n");
usleep(2000000);
}
printf("******************************\n");
printf("Wifi connect ap test: Success!\n");
printf("******************************\n");
for(i=0;i<10;i++)
{
usleep(2000000);
}
*/
wmg_printf(MSG_INFO,"\n*********************************\n");
wmg_printf(MSG_INFO,"***Start scan!***\n");
wmg_printf(MSG_INFO,"*********************************\n");
ret=( p_wifi_interface->start_scan(event_label));
wmg_printf(MSG_DEBUG,"ret of scan is %d\n", ret);
if(ret==0)
{
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi scan: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
}
else
{
wmg_printf(MSG_ERROR,"start scan failed!\n");
}
len = 4096;
ret=( p_wifi_interface->get_scan_results(scan_results, &len));
wmg_printf(MSG_DEBUG,"ret of get_scan_results is %d\n", ret);
ret=( p_wifi_interface->get_scan_results(scan_results, &len));
wmg_printf(MSG_DEBUG,"ret of get_scan_results is %d\n", ret);
if(ret==0)
{
wmg_printf(MSG_INFO,"%s\n",scan_results);
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi get_scan_results: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
}
else
{
wmg_printf(MSG_ERROR,"Get_scan_results failed!\n");
wmg_printf(MSG_INFO,"%s\n",scan_results);
wmg_printf(MSG_INFO,"******************************\n");
wmg_printf(MSG_INFO,"Wifi get_scan_results: Success!\n");
wmg_printf(MSG_INFO,"******************************\n");
}else{
wmg_printf(MSG_ERROR,"Get_scan_results failed!\n");
}

View File

@ -1,230 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <wifi_intf.h>
#include <pthread.h>
#include "wmg_debug.h"
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
{
wmg_printf(MSG_DEBUG,"event_label 0x%x\n", event_label);
switch(wifi_event)
{
case WIFIMG_WIFI_ON_SUCCESS:
{
wmg_printf(MSG_INFO,"WiFi on success!\n");
event = WIFIMG_WIFI_ON_SUCCESS;
break;
}
case WIFIMG_WIFI_ON_FAILED:
{
wmg_printf(MSG_ERROR,"WiFi on failed!\n");
event = WIFIMG_WIFI_ON_FAILED;
break;
}
case WIFIMG_WIFI_OFF_FAILED:
{
wmg_printf(MSG_ERROR,"wifi off failed!\n");
event = WIFIMG_WIFI_OFF_FAILED;
break;
}
case WIFIMG_WIFI_OFF_SUCCESS:
{
wmg_printf(MSG_INFO,"wifi off success!\n");
event = WIFIMG_WIFI_OFF_SUCCESS;
break;
}
case WIFIMG_NETWORK_CONNECTED:
{
wmg_printf(MSG_INFO,"WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED;
break;
}
case WIFIMG_NETWORK_DISCONNECTED:
{
wmg_printf(MSG_INFO,"WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED;
break;
}
case WIFIMG_PASSWORD_FAILED:
{
wmg_printf(MSG_ERROR,"Password authentication failed!\n");
event = WIFIMG_PASSWORD_FAILED;
break;
}
case WIFIMG_CONNECT_TIMEOUT:
{
wmg_printf(MSG_ERROR,"Connected timeout!\n");
event = WIFIMG_CONNECT_TIMEOUT;
break;
}
case WIFIMG_NO_NETWORK_CONNECTING:
{
wmg_printf(MSG_INFO,"It has no wifi auto connect when wifi on!\n");
event = WIFIMG_NO_NETWORK_CONNECTING;
break;
}
case WIFIMG_CMD_OR_PARAMS_ERROR:
{
wmg_printf(MSG_ERROR,"cmd or params error!\n");
event = WIFIMG_CMD_OR_PARAMS_ERROR;
break;
}
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
{
wmg_printf(MSG_ERROR,"key mgmt is not supported!\n");
event = WIFIMG_KEY_MGMT_NOT_SUPPORT;
break;
}
case WIFIMG_OPT_NO_USE_EVENT:
{
wmg_printf(MSG_INFO,"operation no use!\n");
event = WIFIMG_OPT_NO_USE_EVENT;
break;
}
case WIFIMG_NETWORK_NOT_EXIST:
{
wmg_printf(MSG_ERROR,"network not exist!\n");
event = WIFIMG_NETWORK_NOT_EXIST;
break;
}
case WIFIMG_DEV_BUSING_EVENT:
{
wmg_printf(MSG_INFO,"wifi device busing!\n");
event = WIFIMG_DEV_BUSING_EVENT;
break;
}
default:
{
wmg_printf(MSG_DEBUG,"Other event, no care!\n");
}
}
}
void *app_scan_task(void *args)
{
const aw_wifi_interface_t *p_wifi = (aw_wifi_interface_t *)args;
char scan_results[4096];
int len = 0;
int event_label = 0;
while(1){
event_label++;
p_wifi->start_scan(event_label);
len = 4096;
p_wifi->get_scan_results(scan_results, &len);
}
}
void print_help(){
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
wmg_printf(MSG_INFO,"NAME:\n\twifi_list_networks_test\n");
wmg_printf(MSG_INFO,"DESCRIPTION:\n\tlist all the networks in Wpa_supplicant.conf\n");
wmg_printf(MSG_INFO,"\nUSAGE:\n\twifi_list_networks_test\n");
wmg_printf(MSG_INFO,"--------------------------------------MORE---------------------------------------\n");
wmg_printf(MSG_INFO,"The way to get help information:\n");
wmg_printf(MSG_INFO,"\twifi_list_networks_test --help\n");
wmg_printf(MSG_INFO,"\twifi_list_networks_test -h\n");
wmg_printf(MSG_INFO,"\twifi_list_networks_test -H\n");
wmg_printf(MSG_INFO,"---------------------------------------------------------------------------------\n");
}
static int set_log_level(int argv, char *argc[])
{
if(argv >=2 && !strncmp(argc[1],"d",1)){
char *debug = argc[1];
if(strlen(debug) >=2 && debug[1] >= '0' &&
debug[1] <= '5'){
wmg_set_debug_level(debug[1] - '0');
return 0;
}else{
printf("Illegal level\n");
printf("Level range 0~5\n");
return -1;
}
}
return 0;
}
/*
*argc[1] ap ssid
*argc[2] ap passwd
*/
int main(int argv, char *argc[]){
int ret = 0, len = 0, i = 0;
int times = 0, event_label = 0;
char ssid[256] = {0}, scan_results[4096] = {0}, reply[4069]= {0};
int wifi_state = WIFIMG_WIFI_DISABLED;
const aw_wifi_interface_t *p_wifi_interface = NULL;
if(argv == 2 && (!strcmp(argc[1],"--help") || !strcmp(argc[1], "-h") || !strcmp(argc[1], "-H"))){
print_help();
return -1;
}
if(argv < 1 || argv >2){
wmg_printf(MSG_ERROR,"ERROR: No need other params!\n");
print_help();
return -1;
}
if(set_log_level(argv,argc) == -1)
return -1;
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
if(p_wifi_interface == NULL){
wmg_printf(MSG_ERROR,"wifi on failed event 0x%x\n", event);
return -1;
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
wmg_printf(MSG_INFO,"wifi state busing,waiting\n");
usleep(2000000);
}
while(1)
{
for(i=0;i<10;i++)
{
usleep(2000000);
}
wmg_printf(MSG_INFO,"********************************************\n");
wmg_printf(MSG_INFO,"==================stop scan================!\n");
wmg_printf(MSG_INFO,"********************************************\n");
//p_wifi_interface->stop_scan();
for(i=0;i<10;i++)
{
usleep(2000000);
}
wmg_printf(MSG_INFO,"********************************************\n");
wmg_printf(MSG_INFO,"==================restart scan=============!\n");
wmg_printf(MSG_INFO,"********************************************\n");
//p_wifi_interface->restart_scan();
}
return 0;
}

View File

@ -34,4 +34,4 @@ stop_service(){
restart(){
stop "$@"
start "$@"
}
}

View File

@ -16,10 +16,11 @@ CTR_INTERFACE=/mnt/UDISK/wifi/sockets
start_service() {
procd_open_instance
if ps | grep [w]pa_supplicant ; then
killall -q -KILL wpa_supplicant
sleep 2
fi
wpa=`ps | grep wpa_supplicant | grep -v grep`
[ -n "$wpa" ] && {
killall wpa_supplicant
sleep 1
}
ifconfig wlan0 up
procd_set_param oom_adj $OOM_ADJ
procd_set_param command $PROG -iwlan0 -Dnl80211 -c$CFG_FILE -I$CFG_FILE_ADD -O$CTR_INTERFACE
@ -28,9 +29,11 @@ start_service() {
stop_service() {
procd_open_instance
if ps | grep [w]pa_supplicant ; then
killall -q -KILL wpa_supplicant
fi
wpa=`ps | grep wpa_supplicant | grep -v grep`
[ -n "$wpa" ] && {
killall wpa_supplicant
sleep 1
}
ifconfig wlan0 down
procd_close_instance
}

View File

@ -0,0 +1,29 @@
#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=88
STOP=99
DEPEND=boot
USE_PROCD=1
PROG=/bin/wifi_daemon
OOM_ADJ=-17
start_service() {
procd_open_instance
procd_set_param command $PROG
procd_close_instance
}
stop_service() {
da=`ps | grep wifi_daemon | grep -v grep`
[ -n "$da" ] && {
killall wifi_daemon
sleep 1
}
wpa=`ps | grep wpa_supplicant | grep -v grep`
[ -n "$wpa" ] && {
killall wpa_supplicant
sleep 1
}
ifconfig wlan0 down
}

View File

@ -4,7 +4,7 @@ include $(TINA_BUILD_TOP)/build/nls.mk
target = app_wifi_manager
MK_PWD = ./
INCLUDES += -I$(CONFIG_PREFIX)/usr/include -I$(MK_PWD)/softap -I$(MK_PWD)/../src/include
INCLUDES += -I$(CONFIG_PREFIX)/usr/include -I$(MK_PWD)/softap -I$(MK_PWD)/../src/core/include
CPP_SRCS = app_wifi_manager.cpp
CPP_OBJS := $(CPP_SRCS:.cpp=.o)

View File

@ -53,8 +53,8 @@
static pthread_t app_scan_tid;
static int event = WIFIMG_NETWORK_DISCONNECTED;
extern pthread_mutex_t ctrl_mutex;
/* TO BE FIXED */
//extern pthread_mutex_t ctrl_mutex;
#define APP_WIFI_SUCCES 0
@ -253,7 +253,7 @@ int get_connected_ap_info(int *rssi, std::string &ssid, std::string &mac)
}
#if 0
void *app_scan_task(void *args)
{
@ -269,6 +269,7 @@ void *app_scan_task(void *args)
p_wifi->get_scan_results(scan_results, &len);
}
}
#endif
/*
*argc[1] ap ssid
@ -473,9 +474,59 @@ int api_wifi_state_notify(int state,int rssi, std::string ssid, std::string mac)
}
static void wifi_state_handle(struct Manager *w, int event_label)
{
int rssi = 0;
std::string ssid = "";
std::string mac = "";
static int ret_flag =0;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
LOG_EX(LOG_Debug, "app_wifi_manager event_label 0x%x, event 0x%x, state 0x%x\n", event_label, w->StaEvt.event, w->StaEvt.state);
switch(w->StaEvt.state)
{
case CONNECTING:
{
LOG_EX(LOG_Debug, "Connecting to the network......\n");
break;
}
case CONNECTED:
{
LOG_EX(LOG_Debug, "Connected to the AP\n");
start_udhcpc();
break;
}
case OBTAINING_IP:
{
LOG_EX(LOG_Debug, "Getting ip address......\n");
break;
}
case NETWORK_CONNECTED:
{
LOG_EX(LOG_Debug, "Successful network connection\n");
get_connected_ap_info(&rssi, ssid, mac);
if( 0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED, rssi, ssid, mac))
{
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
}
break;
}
case DISCONNECTED:
{
LOG_EX(LOG_Error, "Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
system("ifconfig wlan0 0.0.0.0");
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_DISCONNECT, RSSI_INVALID_NUM, ssid, mac))
{
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
}
break;
}
}
}
/*static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
{
int rssi = 0;
std::string ssid = "";
@ -612,8 +663,7 @@ static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label
}
}
}
}*/
@ -728,9 +778,9 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,
int audo_code =0;
static int busy_conf =0;
static int busy_auto =0;
int wifi_state = WIFIMG_WIFI_DISCONNECTED;
int mask =0;
static int wifi_connet_cnt =0;
enum wmgEvent wmg_event;
LOG_EX(LOG_Debug, "GetDbusCmd:0x%x\r\n",pMsg->busCmd);
@ -812,21 +862,21 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", event);
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", aw_wifi_get_wifi_event());
goto END_DO;
}
}
if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state())
if(NETWORK_CONNECTED == aw_wifi_get_wifi_state())
{
status = p_wifi_interface->disconnect_ap(event_label);
if(0 != status)
{
LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x\n", event);
LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x\n", aw_wifi_get_wifi_event());
goto END_DO;
}else
@ -834,52 +884,53 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,
LOG_EX(LOG_Debug, "Disconnect the wifi connected ap\r\n");
}
}
ret_flag =0;
event_label++;
LOG_EX(LOG_Debug, "INFO: ---- Now connecting ap\r\n");
status = p_wifi_interface->connect_ap(p_ssid,p_passwd, event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP){
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(400000);
}
}
LOG_EX(LOG_Debug, "wifi module final event 0x%x.\r\n", event);
switch(event)
{
case WIFIMG_NETWORK_CONNECTED:
rsp_code = APP_WIFI_CFG_SUCCESS;
break;
case WIFIMG_DEV_BUSING_EVENT:
rsp_code = APP_WIFI_CFG_BUSY;
break;
case WIFIMG_NO_NETWORK_CONNECTING:
case WIFIMG_CMD_OR_PARAMS_ERROR:
rsp_code = APP_WIFI_CFG_PARAMS_ERR;
break;
case WIFIMG_KEY_MGMT_NOT_SUPPORT:
rsp_code = APP_WIFI_CFG_CODEC_ERR;
break;
case WIFIMG_NETWORK_NOT_EXIST:
rsp_code = APP_WIFI_CFG_SSID_NO_EXIT;
break;
case WIFIMG_PASSWORD_FAILED:
rsp_code = APP_WIFI_CFG_PWD_INVALID;
break;
case WIFIMG_NETWORK_DISCONNECTED:
case WIFIMG_CONNECT_TIMEOUT:
rsp_code = APP_WIFI_CFG_TIMEOUT;
break;
default:
rsp_code = APP_WIFI_CFG_OTHER;
break;
}
wmg_event = aw_wifi_get_wifi_event();
LOG_EX(LOG_Debug, "wifi module final event 0x%x.\r\n", wmg_event_txt(wmg_event));
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED)
{
rsp_code = APP_WIFI_CFG_SUCCESS;
}
else
{
switch(wmg_event)
{
case WSE_DEV_BUSING:
rsp_code = APP_WIFI_CFG_BUSY;
break;
case WSE_CMD_OR_PARAMS_ERROR:
rsp_code = APP_WIFI_CFG_PARAMS_ERR;
break;
case WSE_KEYMT_NO_SUPPORT:
rsp_code = APP_WIFI_CFG_CODEC_ERR;
break;
case WSE_NETWORK_NOT_EXIST:
rsp_code = APP_WIFI_CFG_SSID_NO_EXIT;
break;
case WSE_PASSWORD_INCORRECT:
rsp_code = APP_WIFI_CFG_PWD_INVALID;
break;
case WSE_CONNECTED_TIMEOUT:
case WSE_OBTAINED_IP_TIMEOUT:
rsp_code = APP_WIFI_CFG_TIMEOUT;
break;
default:
rsp_code = APP_WIFI_CFG_OTHER;
break;
}
}
busy_conf =0;
}else
@ -976,9 +1027,9 @@ END_DO:
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", event);
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", aw_wifi_get_wifi_event());
busy_auto =0;
break;
}
@ -991,26 +1042,26 @@ END_DO:
break;
}
#endif
if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state())
if(CONNECTED == aw_wifi_get_wifi_state())
status = p_wifi_interface->disconnect_ap(event_label);
}
if(WIFIMG_WIFI_CONNECTED != aw_wifi_get_wifi_state())
if(CONNECTED != aw_wifi_get_wifi_state())
{
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP){
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
}
status = p_wifi_interface->connect_ap_auto(event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING)
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP)
{
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
}
if(WIFIMG_WIFI_CONNECTED !=aw_wifi_get_wifi_state() )
if(NETWORK_CONNECTED !=aw_wifi_get_wifi_state() )
{
std::string ssid = "";
std::string mac = "";
@ -1020,8 +1071,9 @@ END_DO:
}
}
}else
{
}
else
{
int rssi = 0;
std::string ssid = "";
std::string mac = "";
@ -1054,11 +1106,10 @@ END_DO:
int rssi = 0;
std::string ssid = "";
std::string mac = "";
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_STATE_REQ==========================\r\n");
wifi_state = aw_wifi_get_wifi_state();
int wifi_state = aw_wifi_get_wifi_state();
if(WIFIMG_WIFI_CONNECTED == wifi_state)
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_STATE_REQ==========================\r\n");
if(NETWORK_CONNECTED == wifi_state)
{
get_connected_ap_info(&rssi, ssid, mac);
}
@ -1102,20 +1153,20 @@ END_DO:
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", event);
LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", aw_wifi_get_wifi_event());
busy_auto =0;
break;
}
}
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP){
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
}
status = p_wifi_interface->change_ap(event_label);
while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING)
while(aw_wifi_get_wifi_state() == CONNECTING || aw_wifi_get_wifi_state() == OBTAINING_IP)
{
LOG_EX(LOG_Debug, "wifi state busing,waiting\n");
usleep(2000000);
@ -1135,19 +1186,19 @@ END_DO:
LOG_EX(LOG_Debug, "recv DBUS MSG: CMD_WIFI_UNBIND_ACCOUNT\r\n");
if(NULL == p_wifi_interface)
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label);
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Debug, "wifi on failed event L%d 0x%x\n", event, __LINE__);
LOG_EX(LOG_Debug, "wifi on failed event L%d 0x%x\n", aw_wifi_get_wifi_event(), __LINE__);
break;
}
}
if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state())
if(NETWORK_CONNECTED == aw_wifi_get_wifi_state())
{
status = p_wifi_interface->disconnect_ap(event_label);
if(0 != status)
{
LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x L%d\n", event, __LINE__);
LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x L%d\n", aw_wifi_get_wifi_event(), __LINE__);
}
else
{
@ -1158,7 +1209,7 @@ END_DO:
status = p_wifi_interface->remove_all_networks();
if(0 != status)
{
LOG_EX(LOG_Debug, "ERROR:remove_all_networks event 0x%x L%d\n", event, __LINE__);
LOG_EX(LOG_Debug, "ERROR:remove_all_networks event 0x%x L%d\n", aw_wifi_get_wifi_event(), __LINE__);
}
else
{
@ -1174,7 +1225,7 @@ END_DO:
}
else
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, WIFI_CONF_EVT_TAG);
p_wifi_interface = aw_wifi_on(wifi_state_handle, WIFI_CONF_EVT_TAG);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Error, "Turn on wifi failed!\n");
status = APP_WIFI_CFG_SYS_ERR;
@ -1217,12 +1268,12 @@ END_DO:
}
else
{
if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state())
if(NETWORK_CONNECTED == aw_wifi_get_wifi_state())
{
status = p_wifi_interface->disconnect_ap(WIFI_CONF_EVT_TAG);
if(0 != status)
{
LOG_EX(LOG_Error, "ERROR:wifi disconnect event 0x%x\n", event);
LOG_EX(LOG_Error, "ERROR:wifi disconnect event 0x%x\n", aw_wifi_get_wifi_event());
status = APP_WIFI_CFG_SYS_ERR;
}else
{
@ -1268,6 +1319,7 @@ END_DO:
pResJson = NULL;
}
break;
#if 0
case CMD_WIFI_BL_CONF:
case CMD_WIFI_BL_CONF_ABORT:
case CMD_WIFI_BL_CLOUD_CHALLENGE_SIGNATURE:
@ -1275,6 +1327,7 @@ END_DO:
case CMD_WIFI_BL_DEV_TOKEN_BOUND:
bl_event_handle(pMsg->busCmd, pMsg->pMsg);
break;
#endif
default:
break;
}
@ -1321,7 +1374,8 @@ int main(int argv, char *argc[]){
/* init a uv timer to report cur position */
uv_timer_init(pLoop, &timerCurPosMsg);
pthread_mutex_init(&ctrl_mutex, NULL);
/* TO BE FIXED */
//pthread_mutex_init(&ctrl_mutex, NULL);
LOG_EX(LOG_Debug, "Start the wifi communication\n");
uv_thread_t uvSyncThread;

View File

@ -1,890 +0,0 @@
#ifndef PLATFORM_CPU
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <uthash/utlist.h>
#include <sys/socket.h>
#include <linux/netlink.h>
#if defined(PLATFORM_R16) || defined (PLATFORM_CPU)
#include "log.h"
#include "libuv_dbus.h"
//#include "boardlink_iot.h"
#else
#include <uvdbus/log.h>
#include <uvdbus/libuv_dbus.h>
//#include <uvdbus/boardlink_iot.h>
#endif
#include <stdarg.h>
#include <wifi_intf.h>
#include "broadlink.h"
#include "sdk.h"
#include "sdk_errno.h"
#define BL_IOT_PROTO (30)
#define BL_MSG_BUF_MAX (1024 * 4)
static int g_nlSock = -1;
static unsigned char g_MsgSendBuf[BL_MSG_BUF_MAX];
WL_INFO g_WlInfo;
void bl_recv_msg_thread(void *pParam)
{
unsigned char msgBuf[BL_MSG_BUF_MAX];
unsigned char *pProbeReqPayload = NULL;
struct iovec iov = {msgBuf, BL_MSG_BUF_MAX};
struct nlmsghdr *pMsgHdr;
struct sockaddr_nl fromAddr;
struct msghdr msgHdr = {&fromAddr, sizeof(fromAddr), &iov, 1, NULL, 0, 0};
int ret;
int i;
memset(&fromAddr, 0, sizeof(fromAddr));
fromAddr.nl_family = AF_NETLINK;
fromAddr.nl_pid = 0;
fromAddr.nl_groups = 0;
if(0 != bl_create_socket())
{
LOG_EX(LOG_Error, "Create netlink socket error\n");
return ;
}
while(TRUE)
{
int len = recvmsg(g_nlSock, &msgHdr, 0);
if(len > 0)
{
for(pMsgHdr = (struct nlmsghdr *)msgBuf;
NLMSG_OK(pMsgHdr, len);
pMsgHdr = NLMSG_NEXT(pMsgHdr, len))
{
if(pMsgHdr->nlmsg_type == NLMSG_DONE)
{
continue;
}
else if(pMsgHdr->nlmsg_type == NLMSG_ERROR)
{
continue;
}
else
{
PBL_IOT_MSG pMsg = (PBL_IOT_MSG)NLMSG_DATA(pMsgHdr);
//LOG_EX(LOG_Debug, "Recv netlink msg type %d\n", pMsg->msgType);
if (MSG_GET_WLAN_INFO == pMsg->msgType)
{
WL_INFO *wlInfo = NULL;
wlInfo = (WL_INFO *)pMsg->msgData;
bl_set_wlan_info(wlInfo);
LOG_EX(LOG_Debug, "SSID %s, Channel %d, dev mac %x:%x:%x:%x:%x:%x, bssid mac %x:%x:%x:%x:%x:%x\n",
wlInfo->ssid, wlInfo->channel,
wlInfo->dev_mac[0], wlInfo->dev_mac[1], wlInfo->dev_mac[2], wlInfo->dev_mac[3], wlInfo->dev_mac[4], wlInfo->dev_mac[5],
wlInfo->bssid[0], wlInfo->bssid[1],wlInfo->bssid[2],wlInfo->bssid[3],wlInfo->bssid[4],wlInfo->bssid[5]);
}
else if (MSG_BYPASS_MODE == pMsg->msgType)
{
LOG_EX(LOG_Debug, "Recv BROADLINK Probe Request! Len %d\n", pMsg->msglen);
sdk_pkt_process(pMsg->msgData, pMsg->msglen);
}
}
}
}
usleep(1000);
}
//pthread_detach(pthread_self());
}
int bl_create_socket(void)
{
struct sockaddr_nl srcAddr;
g_nlSock = socket(AF_NETLINK, SOCK_RAW, BL_IOT_PROTO);
if(g_nlSock == -1)
{
LOG_EX(LOG_Error, "Create netlink socker error: %s\n", strerror(errno));
return -ERR_CREATE_SOCKET;
}
memset(&srcAddr, 0, sizeof(srcAddr));
srcAddr.nl_family = AF_NETLINK;
srcAddr.nl_pid = getpid();
srcAddr.nl_groups = 0;
if(bind(g_nlSock, (struct sockaddr*)&srcAddr, sizeof(srcAddr)) < 0)
{
LOG_EX(LOG_Error, "Bind netlink socket failed: %s", strerror(errno));
close(g_nlSock);
return -ERR_BIND_SOCKET;
}
return 0;
}
static int __bl_send_netlink_msg(unsigned char* pData, unsigned int len)
{
struct iovec iov;
struct sockaddr_nl dstAddr;
struct nlmsghdr* pMsgHdr = (struct nlmsghdr*)g_MsgSendBuf;
struct msghdr msgHdr = {&dstAddr, sizeof(dstAddr), &iov, 1, NULL, 0, 0};
memset(&dstAddr, 0, sizeof(struct sockaddr_nl));
dstAddr.nl_family = AF_NETLINK;
dstAddr.nl_pid = 0;
dstAddr.nl_groups = 0;
memset(pMsgHdr, 0, BL_MSG_BUF_MAX);
pMsgHdr->nlmsg_len = len;
pMsgHdr->nlmsg_pid = getpid();
pMsgHdr->nlmsg_flags = 0;
memcpy(NLMSG_DATA(pMsgHdr), pData, len);
iov.iov_base = pMsgHdr;
iov.iov_len = NLMSG_SPACE(BL_MSG_BUF_MAX);
return sendmsg(g_nlSock, &msgHdr, 0);
}
int bl_send_msg(BL_IOT_MSG_TYPE msgType, unsigned char* pData, unsigned int len)
{
BL_IOT_MSG blMsg;
memset(&blMsg, 0, sizeof(BL_IOT_MSG));
blMsg.msgType = msgType;
blMsg.msglen = len;
strcpy(blMsg.msgTags, BL_IOT_MSG_TAGS);
if(pData && len > 0)
{
memcpy(blMsg.msgData, pData, len);
}
return __bl_send_netlink_msg((unsigned char*)&blMsg, BL_IOT_MSG_LEN(len));
}
/**
* __bl_binary_to_string - Transfer binary array to string.
* For example, {0x11,0x22,0x33,0x44} will be transfered to "11223344".
* @binary: Pointer to the binary array.
* @binary_len: Length of the binary array.
* @return: Pointer to the result string.
*
* Remember to free the string space after using the string!!
*/
static char *__bl_binary_to_string(const uint8 *binary, uint16 binary_len)
{
char *str = NULL;
int str_len = binary_len * 2 + 1;
int i;
if (NULL == binary || 0 == binary_len)
return NULL;
str = malloc(str_len);
if (NULL == str)
{
LOG_EX(LOG_Error, "Malloc error!\n");
return NULL;
}
memset(str, 0, str_len);
/* Transfer from binary to string */
for (i=0; i<binary_len; ++i)
{
sprintf(str+2*i, "%02x", binary[i]);
}
return str;
}
/**
* __bl_string_to_binary - Transfer string to binary array. The length
* of the string should be multiples of 2, and the string should only
* only include '0'~'9' or 'a'~'f'.
* For example, "11223344" will be transfered to {0x11,0x22,0x33,0x44}.
* @string: Pointer to the string.
* @array: Pointer to the pointer of the array.
* @array_len: Pointer to the length of the array.
* @return: Result of the transfer. 0 ok, -1 error.
*
* Remember to free the binary array space after using the binary array!!
*/
static int __bl_string_to_binary(const uint8 *string, uint8 **array, uint16 *array_len)
{
int i, tmp;
if (NULL == string || 0 == strlen(string) || 0 != strlen(string)% 2)
return -1;
LOG_EX(LOG_Debug, "string: %s\n", string);
*array_len = strlen(string) / 2;
*array = malloc(*array_len);
if (NULL == *array)
{
LOG_EX(LOG_Error, "Malloc error!\n");
return -1;
}
memset(*array, 0, *array_len);
/* Transfer from string to binary */
for (i=0; i<*array_len; i++)
{
if (string[i*2] >= '0' && string[i*2] <= '9')
(*array)[i] = (string[i*2] - '0') * 0x10;
else if (string[i*2] >= 'a' && string[i*2] <= 'f')
(*array)[i] = (string[i*2] - 'a' + 10) * 0x10;
else
{
free(*array);
*array = NULL;
LOG_EX(LOG_Debug, "Unable to recognize charactor!\n");
return -1;
}
if (string[i*2+1] >= '0' && string[i*2+1] <= '9')
(*array)[i] += string[i*2+1] - '0';
else if (string[i*2+1] >= 'a' && string[i*2+1] <= 'f')
(*array)[i] += string[i*2+1] - 'a' + 10;
else
{
free(*array);
*array = NULL;
LOG_EX(LOG_Debug, "Unable to recognize charactor!\n");
return -1;
}
}
return 0;
}
static int __bl_dbus_cmd_send(int mask, uint32_t cmd, const char* pContext)
{
int status =0;
status = DBusBoardcastCommand(NULL, mask, cmd, pContext);
if(0 != status )
{
LOG_EX(LOG_Debug, "nevsps bl send module cmd err is %d\r\n",status);
}
return status;
}
static int __bl_get_challenge_signature(char * p_txt, uint8 **pp_challenge, uint16 *challenge_len, uint8 **pp_signature, uint16 *signature_len)
{
cJSON *p_root =NULL;
cJSON *p_challenge_item = NULL;
cJSON *p_signature_item = NULL;
char *p_tmp = NULL;
int ret = 0;
p_root=cJSON_Parse(p_txt);
if(NULL == p_root)
goto fail;
/* Get cloud challenge value. */
p_challenge_item = cJSON_GetObjectItem(p_root, "challenge");
if(NULL == p_challenge_item)
goto fail;
p_tmp = p_challenge_item->valuestring;
if(NULL == p_tmp)
goto fail;
ret = __bl_string_to_binary(p_tmp, pp_challenge, challenge_len);
if (ret)
{
LOG_EX(LOG_Error, "Transfer cloud challenge error!\n");
goto fail;
}
/* Get cloud signature value. */
p_signature_item = cJSON_GetObjectItem(p_root, "signature");
if(NULL == p_signature_item)
goto fail;
p_tmp = p_signature_item->valuestring;
if(NULL == p_tmp)
goto fail;
ret = __bl_string_to_binary(p_tmp, pp_signature, signature_len);
if (ret)
{
LOG_EX(LOG_Error, "Transfer cloud signature error!\n");
goto fail;
}
cJSON_Delete(p_root);
return 0;
fail:
if (*pp_challenge)
{
free(*pp_challenge);
*pp_challenge = NULL;
*challenge_len = 0;
}
if (*pp_signature)
{
free(*pp_signature);
*pp_signature = NULL;
*signature_len = 0;
}
if (p_root)
cJSON_Delete(p_root);
return -1;
}
static int __bl_get_shared_key(char * p_txt, uint8 **pp_shared_key, uint16 *shared_key_len)
{
cJSON *p_root =NULL;
cJSON *p_shared_key_item = NULL;
char *p_tmp = NULL;
int ret = 0;
p_root=cJSON_Parse(p_txt);
if(NULL == p_root)
goto fail;
/* Get shared key value. */
p_shared_key_item = cJSON_GetObjectItem(p_root, "shareKey");
if(NULL == p_shared_key_item)
goto fail;
p_tmp = p_shared_key_item->valuestring;
if(NULL == p_tmp)
goto fail;
ret = __bl_string_to_binary(p_tmp, pp_shared_key, shared_key_len);
if (ret)
{
LOG_EX(LOG_Error, "Transfer shared key error!\n");
goto fail;
}
cJSON_Delete(p_root);
return 0;
fail:
if (*pp_shared_key)
{
free(*pp_shared_key);
*pp_shared_key = NULL;
*shared_key_len = 0;
}
if (p_root)
cJSON_Delete(p_root);
return -1;
}
int32 bl_printf(const char* format, ...)
{
//LOG_EX(level, format, args...)
va_list args;
va_start(args, format);
//vprintf(fmt, args);
IHW_LOG(LOG_Debug, format, args);
va_end(args);
return 0;
}
int32 bl_found_device(sdk_product_info_t *product_info)
{
LOG_EX(LOG_Debug, "Found Broadlink device!\n");
LOG_EX(LOG_Debug, "verdor id %d!\n", product_info->vendor_id);
LOG_EX(LOG_Debug, "product id %d!\n", product_info->product_id);
LOG_EX(LOG_Debug, "mac %x:%x:%x:%x:%x:%x!\n", product_info->mac[0], product_info->mac[1], product_info->mac[2], product_info->mac[3], product_info->mac[4], product_info->mac[5]);
if (0 != sdk_user_auth_to_start_config())
{
LOG_EX(LOG_Debug, "sdk_user_auth_to_start_config failed!\n");
}
else
{
LOG_EX(LOG_Debug, "sdk_user_auth_to_start_config succeed!\n");
}
return 0;
}
int32 bl_challenge_post(sdk_product_info_t *product_info, uint8 *challenge, uint16 challenge_len)
{
cJSON* pRoot = NULL;
char *pInfoJson = NULL;
char *dev_info = NULL;
char *dev_id = NULL;
char *challenge_str = NULL;
LOG_EX(LOG_Debug, "Begin device challenge!\n");
pRoot = cJSON_CreateObject();
if(NULL == pRoot)
{
LOG_EX(LOG_Error, "cJSON_CreateObject error!\n");
return -1;
}
/* Add device_info string to json */
dev_info = __bl_binary_to_string(product_info->device_info, product_info->device_info_len);
if (NULL == dev_info)
{
LOG_EX(LOG_Error, "Transfer device_info error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_info string %s\n", dev_info);
cJSON_AddStringToObject(pRoot, "deviceInfo", dev_info);
free(dev_info);
/* Add device_id string to json */
dev_id = __bl_binary_to_string(product_info->device_id, product_info->device_id_len);
if (NULL == dev_id)
{
LOG_EX(LOG_Error, "Transfer device_id error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_id string %s\n", dev_id);
cJSON_AddStringToObject(pRoot, "deviceId", dev_id);
free(dev_id);
/* Add device challenge string to json */
challenge_str = __bl_binary_to_string(challenge, challenge_len);
if (NULL == challenge_str)
{
LOG_EX(LOG_Error, "Transfer device challenge error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add challenge string %s\n", challenge_str);
cJSON_AddStringToObject(pRoot, "challenge", challenge_str);
free(challenge_str);
pInfoJson = cJSON_Print(pRoot);
if(NULL == pInfoJson)
{
cJSON_Delete(pRoot);
return -1;
}
cJSON_Delete(pRoot);
LOG_EX(LOG_Debug, "Send device info %s\n", pInfoJson);
__bl_dbus_cmd_send(1<<MODULE_WIFI, CMD_WIFI_BL_DEV_INFO_NTF, pInfoJson);
if (NULL != pInfoJson)
{
free(pInfoJson);
pInfoJson = NULL;
}
/* For Broadlink debug mode */
#if 0
uint8 cloud_challenge[16] = {0};
uint16 cloud_challenge_len = 16;
uint8 cloud_signature[16] = {0};
uint16 cloud_signature_len = 16;
if (0 != sdk_challenge_and_signature_set(cloud_challenge, cloud_challenge_len, cloud_signature, cloud_signature_len))
{
LOG_EX(LOG_Debug, "sdk_challenge_and_signature_set failed!\n");
}
else
{
LOG_EX(LOG_Debug, "sdk_challenge_and_signature_set succeed!\n");
}
#endif
return 0;
}
int32 bl_signature_post(sdk_product_info_t *product_info, uint8 *signature, uint16 signature_len)
{
cJSON* pRoot = NULL;
char *dev_info = NULL;
char *dev_id = NULL;
char *pSignatureJson = NULL;
char *signature_str = NULL;
LOG_EX(LOG_Debug, "Begin device signature post!\n");
pRoot = cJSON_CreateObject();
if(NULL == pRoot)
{
LOG_EX(LOG_Error, "cJSON_CreateObject error!\n");
return -1;
}
/* Add device_info string to json */
dev_info = __bl_binary_to_string(product_info->device_info, product_info->device_info_len);
if (NULL == dev_info)
{
LOG_EX(LOG_Error, "Transfer device_info error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_info string %s\n", dev_info);
cJSON_AddStringToObject(pRoot, "deviceInfo", dev_info);
free(dev_info);
/* Add device_id string to json */
dev_id = __bl_binary_to_string(product_info->device_id, product_info->device_id_len);
if (NULL == dev_id)
{
LOG_EX(LOG_Error, "Transfer device_id error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_id string %s\n", dev_id);
cJSON_AddStringToObject(pRoot, "deviceId", dev_id);
free(dev_id);
/* Add device signature string to json */
signature_str = __bl_binary_to_string(signature, signature_len);
if (NULL == signature_str)
{
LOG_EX(LOG_Error, "Transfer device signature error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add signature string %s\n", signature_str);
cJSON_AddStringToObject(pRoot, "signature", signature_str);
free(signature_str);
pSignatureJson = cJSON_Print(pRoot);
if(NULL == pSignatureJson)
{
cJSON_Delete(pRoot);
return -1;
}
cJSON_Delete(pRoot);
LOG_EX(LOG_Debug, "Send device signature %s\n", pSignatureJson);
__bl_dbus_cmd_send(1<<MODULE_WIFI, CMD_WIFI_BL_DEV_SIGNATURE, pSignatureJson);
if (NULL != pSignatureJson)
{
free(pSignatureJson);
pSignatureJson = NULL;
}
/* For Broadlink debug mode */
#if 0
uint8 sharedkey[SDK_SHAREDKEY_LEN];
uint8 ssid[SSID_MAX_LEN] = {0};
uint8 key_mgmt[KEY_MGMT_LEN] = {0};
uint8 password[PASSWORD_MAX_LEN] = {0};
int ret;
int priority;
memset(sharedkey, 0, SDK_SHAREDKEY_LEN);
wpa_conf_get_apinfo_connected(key_mgmt, &priority);
strncpy(ssid, g_WlInfo.ssid, strlen(g_WlInfo.ssid));
LOG_EX(LOG_Debug, "AP ssid %s, priority %d, key_mgmt %s!\n", ssid, priority, key_mgmt);
if (!strcmp(key_mgmt, "WPA-PSK"))
{
/* Get already connected AP's password from wpa_supplicant.conf */
wpa_conf_get_appwd_connected(priority, password);
LOG_EX(LOG_Debug, "AP password %s!\n", password);
ret = sdk_wlan_params_set(sharedkey, ssid, strlen(ssid), password, strlen(password));
}
else
ret = sdk_wlan_params_set(sharedkey, ssid, strlen(ssid), NULL, 0);
if (ret)
LOG_EX(LOG_Debug, "sdk_wlan_params_set failed, error code %d!\n", ret);
else
LOG_EX(LOG_Debug, "sdk_wlan_params_set succeed!\n");
#endif
return 0;
}
int32 bl_device_token_post(sdk_product_info_t *product_info, uint8 *token, uint16 token_len)
{
cJSON* pRoot = NULL;
char *pTokenJson = NULL;
char *dev_info = NULL;
char *dev_id = NULL;
char *token_str = NULL;
pRoot = cJSON_CreateObject();
if(NULL == pRoot)
{
LOG_EX(LOG_Error, "cJSON_CreateObject error!\n");
return -1;
}
/* Add device_info string to json */
dev_info = __bl_binary_to_string(product_info->device_info, product_info->device_info_len);
if (NULL == dev_info)
{
LOG_EX(LOG_Error, "Transfer device_info error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_info string %s\n", dev_info);
cJSON_AddStringToObject(pRoot, "deviceInfo", dev_info);
free(dev_info);
/* Add device_id string to json */
dev_id = __bl_binary_to_string(product_info->device_id, product_info->device_id_len);
if (NULL == dev_id)
{
LOG_EX(LOG_Error, "Transfer device_id error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add device_id string %s\n", dev_id);
cJSON_AddStringToObject(pRoot, "deviceId", dev_id);
free(dev_id);
/* Add device token string to json */
token_str = __bl_binary_to_string(token, token_len);
if (NULL == token_str)
{
LOG_EX(LOG_Error, "Transfer device token error!\n");
return -1;
}
LOG_EX(LOG_Debug, "add token string %s\n", token_str);
cJSON_AddStringToObject(pRoot, "tokenInfo", token_str);
free(token_str);
pTokenJson = cJSON_Print(pRoot);
if(NULL == pTokenJson)
{
cJSON_Delete(pRoot);
return -1;
}
cJSON_Delete(pRoot);
LOG_EX(LOG_Debug, "Send device token %s\n", pTokenJson);
__bl_dbus_cmd_send(1<<MODULE_WIFI, CMD_WIFI_BL_DEV_TOKEN, pTokenJson);
if (NULL != pTokenJson)
{
free(pTokenJson);
pTokenJson = NULL;
}
/* For Broadlink debug mode */
#if 0
int ret;
ret = sdk_device_token_bind_success();
if (ret)
{
LOG_EX(LOG_Debug, "sdk_device_token_bind_success failed, error code %d!\n", ret);
}
else
{
LOG_EX(LOG_Debug, "sdk_device_token_bind_success succeed!\n");
}
#endif
return 0;
}
int32 bl_config_result_post(sdk_product_info_t *product_info, int8 result)
{
LOG_EX(LOG_Debug, "Broadlink device config failed, fail code %hd!\n", result);
__bl_dbus_cmd_send(1<<MODULE_WIFI, CMD_WIFI_BL_CONF_FAILED, NULL);
return 0;
}
int32 bl_raw_pkt_send(uint8 * frame, uint16 frame_len)
{
return bl_send_msg(MSG_BYPASS_MODE, frame, frame_len);
}
int bl_enable_discovery_mode()
{
int ret;
ret = bl_send_msg(MSG_IN_DISCOVERY_MODE, NULL, 0);
if (ret <= 0)
{
LOG_EX(LOG_Error, "Send netlink msg error\n");
return -1;
}
LOG_EX(LOG_Debug, "Enable IOT discovery mode succeed!\n");
return 0;
}
int bl_disable_discovery_mode()
{
int ret;
ret = bl_send_msg(MSG_OUT_DISCOVERY_MODE, NULL, 0);
if (ret <= 0)
{
LOG_EX(LOG_Error, "Send netlink msg error\n");
return -1;
}
LOG_EX(LOG_Debug, "Disable IOT discovery mode succeed!\n");
return 0;
}
int bl_set_wlan_info(WL_INFO *wlInfo)
{
if (wlInfo == NULL)
{
LOG_EX(LOG_Error, "wlan info empty!\n");
return -1;
}
memcpy(&g_WlInfo, wlInfo, sizeof(WL_INFO));
return 0;
}
int bl_get_wlan_info(sdk_user_init_t *usrInit)
{
int ret;
ret = bl_send_msg(MSG_GET_WLAN_INFO, NULL, 0);
if (ret <= 0)
{
LOG_EX(LOG_Error, "Send netlink msg error\n");
return -1;
}
/* TO BE FIXED */
sleep(1);
usrInit->channel = g_WlInfo.channel;
memcpy(usrInit->device_mac, g_WlInfo.dev_mac, ETH_ALEN);
memcpy(usrInit->bssid, g_WlInfo.bssid, ETH_ALEN);
return 0;
}
int bl_sdk_init()
{
sdk_user_init_t usrInit;
int ret = 0;
memset(&usrInit, 0, sizeof(sdk_user_init_t));
if (0 != bl_get_wlan_info(&usrInit))
{
LOG_EX(LOG_Error, "Get wlan info error\n");
return -1;
}
usrInit.send_wlan_type = BL_IOT_MGMT_FRAME_TYPE_ACTION;
usrInit.fastcon_master_id[0]=BL_MASTER_ID_FOR_NETEASE;
usrInit.fastcon_master_id[1]=0;
usrInit.fastcon_master_id[2]=0;
usrInit.fastcon_master_id[3]=0;
usrInit.sdk_config.memset = memset;
usrInit.sdk_config.memcpy = memcpy;
usrInit.sdk_config.memcmp = memcmp;
usrInit.sdk_config.printf = bl_printf;
usrInit.sdk_config.found_device = bl_found_device;
usrInit.sdk_config.challenge_post = bl_challenge_post;
usrInit.sdk_config.signature_post = bl_signature_post;
usrInit.sdk_config.device_token_post = bl_device_token_post;
usrInit.sdk_config.config_result_post = bl_config_result_post;
usrInit.sdk_config.send_raw_pkt = bl_raw_pkt_send;
if (0 != (ret = sdk_init(&usrInit)))
{
LOG_EX(LOG_Error, "Broadlink sdk init error code %d!\n", ret);
return -1;
}
LOG_EX(LOG_Debug, "Broadlink sdk init OK!\n");
return 0;
}
int bl_event_handle(unsigned int cmd, const char* msg)
{
uint8 *cloud_challenge = NULL;
uint16 cloud_challenge_len = 0;
uint8 *cloud_signature = NULL;
uint16 cloud_signature_len = 0;
uint8 *shared_key = NULL;
uint16 shared_key_len = 0;
uint8 ssid[SSID_MAX_LEN] = {0};
uint8 key_mgmt[KEY_MGMT_LEN] = {0};
uint8 password[PASSWORD_MAX_LEN] = {0};
int priority;
int ret = 0;
switch(cmd)
{
case CMD_WIFI_BL_CONF:
bl_enable_discovery_mode();
bl_sdk_init();
break;
case CMD_WIFI_BL_CLOUD_CHALLENGE_SIGNATURE:
ret = __bl_get_challenge_signature(msg, &cloud_challenge, &cloud_challenge_len, &cloud_signature, &cloud_signature_len);
if (ret)
{
LOG_EX(LOG_Debug, "__bl_get_challenge_signature failed!\n");
return -1;
}
ret = sdk_challenge_and_signature_set(cloud_challenge, cloud_challenge_len, cloud_signature, cloud_signature_len);
if (ret)
LOG_EX(LOG_Error, "sdk_challenge_and_signature_set failed, error code %d!\n", ret);
else
LOG_EX(LOG_Debug, "sdk_challenge_and_signature_set succeed!\n");
if (cloud_challenge)
free(cloud_challenge);
if (cloud_signature)
free(cloud_signature);
break;
case CMD_WIFI_BL_CLOUD_SHAREDKEY:
ret = __bl_get_shared_key(msg, &shared_key, &shared_key_len);
if (ret)
{
LOG_EX(LOG_Error, "__bl_get_shared_key failed!\n");
return -1;
}
/* Get already connected AP's key_mgmt and ssid. */
wpa_conf_get_apinfo_connected(key_mgmt, &priority);
strncpy(ssid, g_WlInfo.ssid, strlen(g_WlInfo.ssid));
if (!strcmp(key_mgmt, "WPA-PSK"))
{
/* Get already connected AP's password from wpa_supplicant.conf */
wpa_conf_get_appwd_connected(priority, password);
}
else
{
// TO BE FIXED
password[0] = '\0';
}
ret = sdk_wlan_params_set(shared_key, ssid, strlen(ssid), password, strlen(password));
if (ret)
LOG_EX(LOG_Debug, "sdk_wlan_params_set failed, error code %d!\n", ret);
else
LOG_EX(LOG_Debug, "sdk_wlan_params_set succeed!\n");
if (shared_key)
free(shared_key);
break;
case CMD_WIFI_BL_DEV_TOKEN_BOUND:
ret = sdk_device_token_bind_success();
if (ret)
{
LOG_EX(LOG_Debug, "sdk_device_token_bind_success failed, error code %d!\n", ret);
}
else
{
LOG_EX(LOG_Debug, "sdk_device_token_bind_success succeed!\n");
}
break;
case CMD_WIFI_BL_CONF_ABORT:
bl_disable_discovery_mode();
break;
default:
break;
}
return ret;
}
#endif

View File

@ -6,11 +6,11 @@ include $(BUILD_DIR)/package.mk
target = libwifimg.so
INCLUDES += -I. -I./include
LIBS += -lpthread -ldl -lrt -liconv
local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv
LIBS += -lpthread -ldl -lrt
local_LDFLAGS := $(BUILD_COMMON_LIB)
SRCS =wifimanager.c wifi_event.c wifi_state_machine.c network_manager.c \
wifi.c wpa_supplicant_conf.c udhcpc_thread.c tool.c wmg_debug.c broadlink.c
SRCS =wifimanager.c wifi_event.c scan.c \
wifi.c wpa_supplicant_conf.c wifi_udhcpc.c tool.c wmg_debug.c status_info.c
install:
-@mkdir -p $(CONFIG_PREFIX)/usr/lib
@ -19,12 +19,12 @@ install:
#libwifimg.so
ifeq ($(CONFIG_ARCH), "aarch64")
SRCS += libwpa_client_64.a libfastcon.a
SRCS += libwpa_client_64.a
else
ifeq ($(CONFIG_SOFT_FLOAT), y)
SRCS += libwpa_client_softft.a libfastcon.a
SRCS += libwpa_client_softft.a
else
SRCS += libwpa_client.a libfastcon.a
SRCS += libwpa_client.a
endif
endif
$(target): $(SRCS)

View File

@ -1,5 +1,6 @@
#ifndef __NETWORK_MANAGER_H
#define __NETWORK_MANAGER_H
#include "tool.h"
#if __cplusplus
extern "C" {
@ -9,14 +10,19 @@ extern "C" {
#define KEY_NONE_INDEX 0
#define KEY_WPA_PSK_INDEX 1
#define KEY_WEP_INDEX 2
#define KEY_UNKOWN 3
void start_wifi_scan_thread(void *args);
void stop_wifi_scan_thread();
void pause_wifi_scan_thread();
void resume_wifi_scan_thread();
int update_scan_results();
int get_scan_results_inner(char *results, int *len);
struct net_scan {
/* store scan results */
char results[SCAN_BUF_LEN];
unsigned int results_len;
unsigned int try_scan_count;
bool enable;
};
int direct_get_scan_results_inner(char *results,int *len);
int get_key_mgmt(const char *ssid, int key_mgmt_info[]);
int isScanEnable();
#if __cplusplus
}; // extern "C"

View File

@ -0,0 +1,47 @@
#ifndef __STATUS_INFO_H
#define __STATUS_INFO_H
#include "tool.h"
#if __cplusplus
extern "C" {
#endif
#define WPA_STA_MAX_SSID 32
#define WPA_STA_MAX_BSSID 18
#define WPA_STA_MAX_IP_ADDR 16
#define WPA_STA_MAX_KEY_MGMT 16
#define WPA_STA_MAX_MAC_ADDR 18
enum wpa_states {
WPA_UNKNOWN = 1024,
WPA_COMPLETED,
WPA_DISCONNECTED,
WPA_INTERFACE_DISABLED,
WPA_INACTIVE,
WPA_SCANNING,
WPA_AUTHENTICATING,
WPA_ASSOCIATING,
WPA_ASSOCIATED,
WPA_4WAY_HANDSHAKE,
WPA_GROUP_HANDSHAKE,
};
struct wpa_status{
int id;
char bssid[WPA_STA_MAX_BSSID];
int freq;
char ssid[WPA_STA_MAX_SSID];
enum wpa_states wpa_state;
char ip_address[WPA_STA_MAX_IP_ADDR];
char key_mgmt[WPA_STA_MAX_KEY_MGMT];
char mac_address[WPA_STA_MAX_MAC_ADDR];
};
struct wpa_status *get_wpa_status_info();
void print_wpa_status();
void wpa_status_info_free();
#if __cplusplus
}; // extern "C"
#endif
#endif /* __STATUS_INFO_H */

View File

@ -4,6 +4,9 @@
#include <sys/wait.h>
#include <stdint.h>
#include "wmg_debug.h"
#include <uvdbus/log.h>
#include <stdbool.h>
#if __cplusplus
extern "C" {
#endif

View File

@ -0,0 +1,68 @@
#ifndef __WIFI_EVENT_H
#define __WIFI_EVENT_H
#include "wifi_intf.h"
#define EVENT_BUF_SIZE 2048
#if __cplusplus
extern "C" {
#endif
#define MAX_ASSOC_REJECT_COUNT 5
#define MAX_RETRIES_ON_AUTHENTICATION_FAILURE 1
enum wpaEvent{
WPAE_CONNECTED = 1,
WPAE_DISCONNECTED,
WPAE_STATE_CHANGE,
WPAE_SCAN_FAILED,
WPAE_SCAN_RESULTS,
WPAE_LINK_SPEED,
WPAE_TERMINATING,
WPAE_DRIVER_STATE,
WPAE_EAP_FAILURE,
WPAE_ASSOC_REJECT,
WPAE_NETWORK_NOT_FOUND,
WPAE_PASSWORD_INCORRECT,
WPAE_UNKNOWN,
};
#define NET_ID_LEN 10
struct wpaManager{
enum wpaEvent evt;
int evtFd[2];
bool EvtSocketEnable;
pthread_t evtThreadId;
unsigned int assocRejectCnt;
unsigned int netNotFoundCnt;
unsigned int authFailCnt;
int label;
char netIdConnecting[NET_ID_LEN + 1];
};
extern struct wpaManager *a;
void wifi_event_loop(tWifi_state_callback pcb);
void start_wifi_on_check_connect_timeout();
void start_check_connect_timeout();
void set_scan_start_flag();
int get_scan_status();
int add_wifi_state_callback_inner(tWifi_state_callback pcb);
int call_state_callback_function(struct Manager *w, int state_label);
int reset_wifi_state_callback();
void reset_assoc_reject_count();
void rest_network_not_found_count();
void rest_entication_fail_count();
int evtSocketInit();
void evtSockeExit();
int clearEvtSocket();
int evtSend(enum wpaEvent event);
int evtRead(enum wpaEvent *event);
#if __cplusplus
}; // extern "C"
#endif
#endif /*__WIFI_EVENT_H*/

View File

@ -0,0 +1,108 @@
#ifndef __WIFI_INTF_H
#define __WIFI_INTF_H
#include <stdbool.h>
#include "wifi_udhcpc.h"
#include "status_info.h"
#if __cplusplus
extern "C" {
#endif
#define MAX_CALLBCAKS_COUNT 1024
typedef enum {
WIFIMG_NONE = 0,
WIFIMG_WPA_PSK,
WIFIMG_WPA2_PSK,
WIFIMG_WEP,
}tKEY_MGMT;
enum wmgState {
NETWORK_CONNECTED = 0x01,
CONNECTING,
OBTAINING_IP,
DISCONNECTED,
CONNECTED,
STATE_UNKNOWN,
};
enum wmgEvent{
WSE_UNKNOWN = 0x20,
WSE_STARTUP_AUTO_CONNECT,
WSE_AUTO_CONNECTED,
WSE_ACTIVE_CONNECT,
WSE_ACTIVE_OBTAINED_IP,
WSE_AUTO_DISCONNECTED,
WSE_ACTIVE_DISCONNECT,
WSE_KEYMT_NO_SUPPORT,
WSE_CMD_OR_PARAMS_ERROR,
WSE_DEV_BUSING,
WSE_CONNECTED_TIMEOUT,
WSE_OBTAINED_IP_TIMEOUT,
WSE_WPA_TERMINATING,
WSE_AP_ASSOC_REJECT,
WSE_NETWORK_NOT_EXIST,
WSE_PASSWORD_INCORRECT,
};
#define SSID_MAX 32
#define PWD 48
struct WmgStaEvt {
enum wmgState state;
enum wmgEvent event;
};
struct wifi_status {
enum wmgState state;
char ssid[SSID_MAX];
};
struct Manager {
struct WmgStaEvt StaEvt;
bool enable;
};
extern struct Manager *w;
typedef void (*tWifi_state_callback)(struct Manager *wmg,int state_label);
typedef struct{
int (*add_state_callback)(tWifi_state_callback pcb);
int (*ssid_is_connected_ap)(char *ssid);
int (*is_ap_connected)(char *ssid, int *len);
int (*get_scan_results)(char *result, int *len);
int (*connect_ap)(const char *ssid, const char *passwd, int event_label);
int (*connect_ap_key_mgmt)(const char *ssid, tKEY_MGMT key_mgnt, const char *passwd, int event_label);
int (*connect_ap_auto)(int event_label);
int (*connect_ap_with_netid)(const char *net_id, int event_label);
int (*add_network)(const char *ssid, tKEY_MGMT key_mgnt, const char *passwd, int event_label);
int (*change_ap)(int event_label);
int (*disconnect_ap)(int event_label);
int (*remove_network)(char *ssid, tKEY_MGMT key_mgmt);
int (*remove_all_networks)(void);
int (*list_networks)(char *reply, size_t reply_len, int event_label);
int (*get_netid)(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *length);
int (*get_status)(struct wifi_status *s);
int (*clear_network)(const char *ssid);
}aw_wifi_interface_t;
const aw_wifi_interface_t * aw_wifi_on(tWifi_state_callback pcb,int event_label);
int aw_wifi_off(const aw_wifi_interface_t *p_wifi_interface_t);
int state_event_change(int event_label);
const char *wmg_event_txt(enum wmgEvent event);
const char *wmg_state_txt(enum wmgState state);
void start_udhcpc_thread(void *args);
enum wmgState aw_wifi_get_wifi_state();
enum wmgEvent aw_wifi_get_wifi_event();
#if __cplusplus
}; // extern "C"
#endif
#endif

View File

@ -0,0 +1,15 @@
#ifndef __WIFI_UDHCPC_H
#define __WIFI_UDHCPC_H
#if __cplusplus
extern "C" {
#endif
void start_udhcpc();
int is_ip_exist();
#if __cplusplus
}; // extern "C"
#endif
#endif

View File

@ -32,7 +32,7 @@ int wmg_debug_open_file(const char *path);
void wmg_debug_close_file(void);
void wmg_debug_open_syslog(void);
void wmg_debug_close_syslog(void);
int wmg_set_debug_level(int level);
void wmg_set_debug_level(int level);
int wmg_get_debug_level();

View File

@ -9,7 +9,7 @@ extern "C" {
#define CMD_LEN 255
#define REPLY_BUF_SIZE 4096 // wpa_supplicant's maximum size.
#define NET_ID_LEN 10
int wpa_conf_network_info_exist();
int wpa_conf_is_ap_exist(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len);
@ -20,8 +20,6 @@ int wpa_conf_get_netid_connected(char *net_id, int *len);
int wpa_conf_get_ap_connected(char *netid, int *len);
int wpa_conf_enable_all_networks();
int wpa_conf_remove_all_networks();
int wpa_conf_standardize_priority();
int wpa_conf_disable_network(char * netId);
int wpa_conf_add_on_priority_list_hdr(char * netId);
#if __cplusplus

View File

@ -0,0 +1,267 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<errno.h>
#include "wifi_event.h"
#include "scan.h"
#include "wifi_intf.h"
#include "wifi.h"
#include "wmg_debug.h"
#include <uvdbus/log.h>
#include "tool.h"
#define WAITING_CLK_COUNTS 50
#define SSID_LEN 512
#define TRY_SAN_MAX 6
static struct net_scan scan = {
.results_len = 0,
.try_scan_count = 0,
.enable = 0,
};
int remove_slash_from_scan_results()
{
char *ptr = NULL;
char *ptr_s = NULL;
char *ftr = NULL;
ptr_s = scan.results;
while(1)
{
ptr = strchr(ptr_s,'\"');
if(ptr == NULL)
break;
ptr_s = ptr;
if((*(ptr-1)) == '\\')
{
ftr = ptr;
ptr -= 1;
while(*ftr != '\0')
*(ptr++) = *(ftr++);
*ptr = '\0';
continue; //restart new search at ptr_s after removing slash
}
else
ptr_s++; //restart new search at ptr_s++
}
ptr_s = scan.results;
while(1)
{
ptr = strchr(ptr_s,'\\');
if(ptr == NULL)
break;
ptr_s = ptr;
if((*(ptr-1)) == '\\')
{
ftr = ptr;
ptr -= 1;
while(*ftr != '\0')
*(ptr++) = *(ftr++);
*ptr = '\0';
continue; //restart new search at ptr_s after removing slash
}
else
ptr_s++; //restart new search at ptr_s++
}
return 0;
}
int isScanEnable()
{
if(scan.enable)
return 1;
else
return 0;
}
int direct_get_scan_results_inner(char *results,int *len)
{
char cmd[16] = {0};
char reply[16] = {0};
int ret = 0;
int i = 0;
char *ptr = NULL;
int index;
int flags;
enum wpaEvent event;
while(1) {
/* clear scan.sockets data before sending scan command*/
clearEvtSocket();
scan.enable = true;
strncpy(cmd,"SCAN",15);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret) {
LOG_EX(LOG_Debug, "wifimanger send scan error:%s\n",reply);
if(strncmp(reply,"FAIL-BUSY",10) == 0) {
LOG_EX(LOG_Debug, "wpa_supplicant is scanning internally\n");
event = WPAE_SCAN_RESULTS;
/*Wpa_supplicant is scanning internally ,so get he scan results directly*/
goto scan_resluts;
} else {
return -1;
}
}
ret = evtRead(&event);
/*send scan command failed ,try again.*/
if(event == WPAE_SCAN_FAILED) {
LOG_EX(LOG_Debug, "scan again......\n");
scan.try_scan_count ++;
if(scan.try_scan_count > TRY_SAN_MAX){
LOG_EX(LOG_Debug, "send scan cmd failed\n");
return -1;
}
sleep(1);
continue;
}
scan_resluts:
remove_slash_from_scan_results();
if(event == WPAE_SCAN_RESULTS){
strncpy(cmd,"SCAN_RESULTS",15);
cmd[15]= '\0';
ret = wifi_command(cmd,scan.results,sizeof(scan.results));
if(ret) {
LOG_EX(LOG_Error, "do scan results error!\n");
return -1;
}
scan.results_len = strlen(scan.results);
} else {
LOG_EX(LOG_Error, "read scan data is failed\n");
return -1;
}
scan.enable = false;
if(NULL == results || NULL == len)
return 0;
if(*len <= scan.results_len) {
LOG_EX(LOG_Debug, "Scan result overflow,%d < %d\n",*len,scan.results_len);
strncpy(results, scan.results, *len-1);
index = *len -1;
results[index] = '\0';
ptr=strrchr(results, '\n');
if(ptr != NULL) {
*ptr = '\0';
}
} else {
strncpy(results, scan.results, scan.results_len);
results[scan.results_len] = '\0';
}
break;
}
return 0;
}
int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt)
{
int ret = 0, i = 0, key[4] = {0};
for(i=0; i<4; i++){
key[i]=0;
}
get_key_mgmt(ssid, key);
if(key_mgmt == WIFIMG_NONE){
if(key[0] == 1){
ret = 1;
}
}else if(key_mgmt == WIFIMG_WPA_PSK || key_mgmt == WIFIMG_WPA2_PSK){
if(key[1] == 1){
ret = 1;
}
}else if(key_mgmt == WIFIMG_WEP){
if(key[2] == 1){
ret = 1;
}
}else{
;
}
return ret;
}
int get_key_mgmt(const char *ssid, int key_mgmt_info[])
{
char *ptr = NULL, *pssid_start = NULL, *pssid_end = NULL;
char *pst = NULL, *pend = NULL;
char *pflag = NULL;
char flag[128], pssid[SSID_LEN + 1];
int len = 0, i = 0;
LOG_EX(LOG_Debug, "enter get_key_mgmt, ssid %s\n", ssid);
key_mgmt_info[KEY_NONE_INDEX] = 0;
key_mgmt_info[KEY_WEP_INDEX] = 0;
key_mgmt_info[KEY_WPA_PSK_INDEX] = 0;
key_mgmt_info[KEY_UNKOWN] = 0;
/* first line end */
if(direct_get_scan_results_inner(NULL,NULL) != 0) {
LOG_EX(LOG_Debug, "get scan result is null\n");
return 0;
}
ptr = strchr(scan.results, '\n');
ptr ++;
while(1){
/* line end */
pend = strchr(ptr, '\n');
if (pend != NULL){
*pend = '\0';
}
/* line start */
pst = ptr;
/* abstract ssid */
pssid_start = strrchr(pst, '\t') + 1;
strncpy(pssid, pssid_start, SSID_LEN);
pssid[SSID_LEN] = '\0';
/* find ssid in scan results */
if(strcmp(pssid, ssid) == 0){
pflag = pst;
for(i=0; i<3; i++){
pflag = strchr(pflag, '\t');
pflag++;
}
len = pssid_start - pflag;
len = len - 1;
strncpy(flag, pflag, len);
flag[len] = '\0';
LOG_EX(LOG_Debug, "ssid %s, flag %s\n", ssid, flag);
if((strstr(flag, "WPA-PSK-") != NULL)
|| (strstr(flag, "WPA2-PSK-") != NULL)){
key_mgmt_info[KEY_WPA_PSK_INDEX] = 1;
}else if(strstr(flag, "WEP") != NULL){
key_mgmt_info[KEY_WEP_INDEX] = 1;
}else if((strcmp(flag, "[ESS]") == 0) || (strcmp(flag, "[WPS][ESS]") == 0)){
key_mgmt_info[KEY_NONE_INDEX] = 1;
}else{
key_mgmt_info[KEY_UNKOWN] = 1;
}
}
if(pend != NULL){
*pend = '\n';
//point next line
ptr = pend+1;
}else{
break;
}
}
return 0;
}

View File

@ -0,0 +1,230 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include "status_info.h"
#include "wifi_intf.h"
#include "wmg_debug.h"
#include <uvdbus/libuv_dbus.h>
#include "tool.h"
#include "wifi.h"
static struct wpa_status *ptrStaInfo;
enum wpa_states wpa_supplicant_state_convert(char *str)
{
if(!strncmp(str,"DISCONNECTED",16)){
return WPA_DISCONNECTED;
}
if(!strncmp(str,"INTERFACE_DISABLED",22)){
return WPA_INTERFACE_DISABLED;
}
if(!strncmp(str,"INACTIVE",12)){
return WPA_INACTIVE;
}
if(!strncmp(str,"SCANNING",12)){
return WPA_SCANNING;
}
if(!strncmp(str,"AUTHENTICATING",18)){
return WPA_AUTHENTICATING;
}
if(!strncmp(str,"ASSOCIATED",14)){
return WPA_ASSOCIATED;
}
if(!strncmp(str,"4WAY_HANDSHAKE",19)){
return WPA_4WAY_HANDSHAKE;
}
if(!strncmp(str,"GROUP_HANDSHAKE",19)){
return WPA_GROUP_HANDSHAKE;
}
if(!strncmp(str,"COMPLETED",13)){
return WPA_COMPLETED;
}
if(!strncmp(str,"DISCONNECTED",16)){
return WPA_DISCONNECTED;
}
return WPA_UNKNOWN;
}
static const char * wpa_supplicant_state_txt(enum wpa_states state)
{
switch (state) {
case WPA_DISCONNECTED:
return "DISCONNECTED";
case WPA_INACTIVE:
return "INACTIVE";
case WPA_INTERFACE_DISABLED:
return "INTERFACE_DISABLED";
case WPA_SCANNING:
return "SCANNING";
case WPA_AUTHENTICATING:
return "AUTHENTICATING";
case WPA_ASSOCIATING:
return "ASSOCIATING";
case WPA_ASSOCIATED:
return "ASSOCIATED";
case WPA_4WAY_HANDSHAKE:
return "4WAY_HANDSHAKE";
case WPA_GROUP_HANDSHAKE:
return "GROUP_HANDSHAKE";
case WPA_COMPLETED:
return "COMPLETED";
default:
return "UNKNOWN";
}
}
void print_wpa_status()
{
LOG_EX(LOG_Debug, "obtained wpa_supplicant status,as follow:\n");
LOG_EX(LOG_Debug, "==============================\n");
if(ptrStaInfo->id >= 0)
LOG_EX(LOG_Debug, "id:%d\n",ptrStaInfo->id);
if(ptrStaInfo->bssid)
LOG_EX(LOG_Debug, "bssid:%s\n",ptrStaInfo->bssid);
if(ptrStaInfo->freq >=0)
LOG_EX(LOG_Debug, "freq:%d\n",ptrStaInfo->freq);
if(ptrStaInfo->ssid)
LOG_EX(LOG_Debug, "ssid:%s\n",ptrStaInfo->ssid);
if(ptrStaInfo->wpa_state)
LOG_EX(LOG_Debug, "wpa_state:%s\n",wpa_supplicant_state_txt(ptrStaInfo->wpa_state));
if(ptrStaInfo->ip_address)
LOG_EX(LOG_Debug, "ip_address:%s\n",ptrStaInfo->ip_address);
if(ptrStaInfo->key_mgmt)
LOG_EX(LOG_Debug, "key_mgmt:%s\n",ptrStaInfo->key_mgmt);
if(ptrStaInfo->mac_address)
LOG_EX(LOG_Debug, "mac_address:%s\n",ptrStaInfo->mac_address);
LOG_EX(LOG_Debug, "==============================\n");
}
static char *strstr_wpa(const char *src,const char *obj,
const char pre_str[2],int pst_len)
{
const char *p=src;
int length;
int i=0;
if(src == NULL || obj == NULL || pre_str ==NULL){
LOG_EX(LOG_Debug, "src or obj or pre_str is NULL");
return NULL;
}
if(pst_len > strlen(pre_str)){
LOG_EX(LOG_Error, "pst_len length is illegal");
return NULL;
}
length = strlen(obj);
for(;;p++,i++){
p=strchr(p,*obj);
if(p == NULL){
LOG_EX(LOG_Debug, "%s is not exist\n",obj);
return NULL;
}
if(strncmp(p,obj,length) == 0){
if(i > 1 && *(p-1) != pre_str[0] && *(p-1) != pre_str[1]){
return (char*)p;
}
}
}
}
static int search_wpa_string(const char *src,const char *obj,int max,char *get_str)
{
int i=0;
const char *sptr = NULL;
const char *pnext = NULL;
if(obj == NULL || src == NULL){
LOG_EX(LOG_Debug, "src or obj is NULL");
return 0;
}
if(!strncmp("id=",obj,3)){
sptr = strstr_wpa(src,obj,"su",2);
}else if(!strncmp("ssid=",obj,5)){
sptr = strstr_wpa(src,obj,"bb",2);
}else if(!strncmp("address=",obj,8)){
sptr = strstr_wpa(src,obj,"__",2);
}else{
sptr = strstr(src, obj);
}
if(sptr !=NULL){
pnext=sptr+strlen(obj);
i=0;
while(1){
i++;
if(i >max ){
LOG_EX(LOG_Error, "Data overflow");
break;
}
pnext++;
if(*pnext == '\n')
break;
}
strncpy(get_str,sptr+strlen(obj),i);
get_str[i]='\0';
return 1;
}
return -1;
}
static int clear_wpa_status_info()
{
int i;
if(ptrStaInfo == NULL)
ptrStaInfo = (struct wpa_status *)wgos_zalloc(sizeof(struct wpa_status));
if(ptrStaInfo == NULL){
LOG_EX(LOG_Debug, "malloc status failed!\n");
return -1;
}
ptrStaInfo->id = -1;
ptrStaInfo->freq = -1;
for(i = 0;i< WPA_STA_MAX_SSID;i++){
ptrStaInfo->ssid[i] = '\0';
if(i < WPA_STA_MAX_BSSID)
ptrStaInfo->bssid[i] = '\0';
if(i < WPA_STA_MAX_IP_ADDR)
ptrStaInfo->ip_address[i] = '\0';
if(i < WPA_STA_MAX_KEY_MGMT)
ptrStaInfo->key_mgmt[i]='\0';
if(i < WPA_STA_MAX_MAC_ADDR)
ptrStaInfo->mac_address[i]='\0';
}
ptrStaInfo->wpa_state = WPA_UNKNOWN;
return 0;
}
void wpa_status_info_free()
{
if(ptrStaInfo !=NULL){
free(ptrStaInfo);
ptrStaInfo = NULL;
}
}
struct wpa_status *get_wpa_status_info()
{
char reply[4096] = {0};
char wpa_result[32];
clear_wpa_status_info();
wifi_command("STATUS", reply, sizeof(reply));
if(reply !=NULL){
LOG_EX(LOG_Debug, "status info:\n%s\n",reply);
if(search_wpa_string(reply,"wpa_state=",32,wpa_result) >0)
ptrStaInfo->wpa_state = wpa_supplicant_state_convert(wpa_result);
if(search_wpa_string(reply,"ssid=",32,wpa_result) >0)
strncpy(ptrStaInfo->ssid,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"id=",4,wpa_result) >0)
ptrStaInfo->id = atoi(wpa_result);
if(search_wpa_string(reply,"freq=",6,wpa_result) >0)
ptrStaInfo->freq = atoi(wpa_result);
if(search_wpa_string(reply,"bssid=",18,wpa_result) >0)
strncpy(ptrStaInfo->bssid,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"key_mgmt=",16,wpa_result) >0)
strncpy(ptrStaInfo->key_mgmt,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"address=",18,wpa_result) >0)
strncpy(ptrStaInfo->mac_address,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"ip_address=",16,wpa_result) >0)
strncpy(ptrStaInfo->ip_address,wpa_result,strlen(wpa_result));
}else{
LOG_EX(LOG_Debug, "send STATUS,reply is NULL\n");
}
if(wmg_get_debug_level() >= MSG_MSGDUMP){
print_wpa_status();
}
return ptrStaInfo;
}

View File

@ -24,7 +24,7 @@ int get_process_state(const char *process_name,int length){
char cmd[60];
FILE *stream;
if(length > 20){
wmg_printf(MSG_ERROR,"process name is too long!\n");
LOG_EX(LOG_Error, "process name is too long!\n");
return -1;
}
sprintf(cmd,"ps | grep %s | grep -v grep",process_name);
@ -33,10 +33,10 @@ int get_process_state(const char *process_name,int length){
bytes = fread( buf, sizeof(char), sizeof(buf), stream);
pclose(stream);
if(bytes > 0){
wmg_printf(MSG_DEBUG,"%s :process exist\n",process_name);
LOG_EX(LOG_Debug, "%s :process exist\n",process_name);
return 1;
}else {
wmg_printf(MSG_DEBUG,"%s :process not exist\n",process_name);
LOG_EX(LOG_Debug, "%s :process not exist\n",process_name);
return -1;
}
}

View File

@ -8,17 +8,17 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <poll.h>
#include<pthread.h>
#include "wpa_ctrl.h"
#include "wifi.h"
#include <unistd.h>
#include <uvdbus/log.h>
#include "tool.h"
#define IFACE_VALUE_MAX 32
static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *monitor_conn;
pthread_mutex_t ctrl_mutex;
static pthread_mutex_t wifi_command_mutex;
/* socket pair used to exit from a blocking read */
static int exit_sockets[2];
@ -472,7 +472,6 @@ int wifi_start_supplicant(int p2p_supported)
LOG_EX(LOG_Debug, "Wi-Fi entropy file was not created\n");
}
/* Clear out any stale socket files that might be left over. */
//wpa_ctrl_cleanup();
@ -480,12 +479,10 @@ int wifi_start_supplicant(int p2p_supported)
exit_sockets[0] = exit_sockets[1] = -1;
/* start wpa_supplicant */
strncpy(cmd, "/etc/wifi/wifi restart", 511);
strncpy(cmd, "/etc/wifi/wifi start", 511);
cmd[511] = '\0';
system(cmd);
return 0;
}
@ -495,7 +492,7 @@ int wifi_stop_supplicant(int p2p_supported)
return 0;
}
#define SUPPLICANT_TIMEOUT 4000000 // microseconds
#define SUPPLICANT_TIMEOUT 3000000 // microseconds
#define SUPPLICANT_TIMEOUT_STEP 100000 // microseconds
int wifi_connect_on_socket_path(const char *path)
{
@ -539,7 +536,8 @@ int wifi_connect_on_socket_path(const char *path)
int wifi_connect_to_supplicant()
{
static char path[PATH_MAX];
if(get_process_state("wpa_supplicant",14) == -1)
return -1;
strncpy(primary_iface, "wlan0", IFACE_VALUE_MAX);
if (access(IFACE_DIR, F_OK) == 0) {
snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
@ -564,7 +562,7 @@ int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
if (ret == -2) {
LOG_EX(LOG_Debug, "'%s' command timed out.\n", cmd);
/* unblocks the monitor receive socket for termination */
//TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1));
TEMP_FAILURE_RETRY(write(exit_sockets[0], "T", 1));
return -2;
} else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
return -1;
@ -608,7 +606,6 @@ int wifi_wait_on_socket(char *buf, size_t buflen)
char *match, *match2;
if (monitor_conn == NULL) {
sleep(2);
return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed");
}
@ -710,63 +707,24 @@ void wifi_close_supplicant_connection()
}
}
void wifi_restart_supplicant()
{
int i;
int ret;
wifi_event_loop_stop();
wifi_close_supplicant_connection();
wifi_start_supplicant(0);
do{
usleep(300000);
ret = wifi_connect_to_supplicant();
if(!ret){
LOG_EX(LOG_Debug, "Connected to wpa_supplicant!\n");
break;
}
i++;
}while(ret && i<10);
wifi_event_loop_restart();
}
void wifi_clear()
{
system("ifconfig wlan0 down");
usleep(200000);
system("ifconfig wlan0 up");
}
int wifi_command(char const *cmd, char *reply, size_t reply_len)
{
int ret =0;
if(!cmd || !cmd[0]){
return -1;
}
if(!cmd || !cmd[0]){
return -1;
}
pthread_mutex_lock(&ctrl_mutex);
LOG_EX(LOG_Debug, "do cmd %s\n", cmd);
--reply_len; // Ensure we have room to add NUL termination.
if ((ret =wifi_send_command(cmd, reply, &reply_len)) != 0) {
--reply_len; // Ensure we have room to add NUL termination.
if (wifi_send_command(cmd, reply, &reply_len) != 0) {
return -1;
}
LOG_EX(LOG_Debug, "wifi_send_command ret is %d %s\r\n",ret, reply);
if (-2 == ret)
wifi_restart_supplicant();
else
wifi_clear();
pthread_mutex_unlock(&ctrl_mutex);
return -1;
}
pthread_mutex_unlock(&ctrl_mutex);
// Strip off trailing newline.
if (reply_len > 0 && reply[reply_len-1] == '\n') {
reply[reply_len-1] = '\0';
} else {
reply[reply_len] = '\0';
}
return 0;
// Strip off trailing newline.
if (reply_len > 0 && reply[reply_len-1] == '\n') {
reply[reply_len-1] = '\0';
} else {
reply[reply_len] = '\0';
}
return 0;
}

View File

@ -0,0 +1,373 @@
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<uvdbus/log.h>
#include<errno.h>
#include<fcntl.h>
#include<poll.h>
#include<sys/types.h>
#include<sys/socket.h>
#include "wifi.h"
#include "wifi_event.h"
#include "wifi_intf.h"
#include "wpa_supplicant_conf.h"
#include "wmg_debug.h"
#include "scan.h"
struct wpaManager wpa = {
.evt = WPA_UNKNOWN,
.assocRejectCnt = 0,
.netNotFoundCnt = 0,
.authFailCnt = 0,
.evtFd = {-1,-1},
};
struct wpaManager *a = &wpa;
#define NETNOTFOUNDCNT 3
tWifi_state_callback wifi_state_callback[MAX_CALLBCAKS_COUNT] = {NULL};
int wifi_state_callback_index = 0;
void evtSockeExit()
{
if(a->EvtSocketEnable){
clearEvtSocket();
if(a->evtFd[0] >= 0) {
a->evtFd[0] = -1;
}
if(a->evtFd[1] >= 0) {
a->evtFd[1] = -1;
}
}
}
int evtSocketInit()
{
int ret;
if(a->evtFd[0] >=0 || a->evtFd[1] >= 0){
evtSockeExit();
}
a->evtFd[0] = a->evtFd[1] = -1;
ret = socketpair(AF_UNIX,SOCK_STREAM,0,a->evtFd);
if(ret == -1) {
LOG_EX(LOG_Error, "scan socketpair init error\n");
return ret;
}
a->EvtSocketEnable = true;
return 0;
}
int clearEvtSocket()
{
int ret = -1;
char c;
int flags;
if(! a->EvtSocketEnable){
LOG_EX(LOG_Error, "event socket is closed\n");
return ret;
}
/* clear scan.sockets data before sending scan command*/
if(flags = fcntl(a->evtFd[1],F_GETFL,0) < 0){
LOG_EX(LOG_Error, "fcntl getfl error\n");
return -1;
}
flags |= O_NONBLOCK;
if(fcntl(a->evtFd[1],F_SETFL,flags) < 0){
LOG_EX(LOG_Error, "fcntl setfl error\n");
return -1;
}
while ((ret= TEMP_FAILURE_RETRY(read(a->evtFd[1],&c,1))) > 0){
LOG_EX(LOG_Debug, "clear data %d\n",c);
}
}
int evtSend(enum wpaEvent event)
{
int ret = -1;
char data;
if(! a->EvtSocketEnable){
LOG_EX(LOG_Error, "event socket is closed\n");
return ret;
}
data = (char)event;
ret = TEMP_FAILURE_RETRY(write(a->evtFd[0],&data, 1));
return ret;
}
int evtRead(enum wpaEvent *event)
{
int ret = -1;
struct pollfd rfds;
char c;
if(! a->EvtSocketEnable){
LOG_EX(LOG_Error, "event socket is closed\n");
return ret;
}
memset(&rfds,0,sizeof(struct pollfd));
rfds.fd = a->evtFd[1];
rfds.events |= POLLIN;
/*wait event.*/
ret = TEMP_FAILURE_RETRY(poll(&rfds, 1, 30000));
if (ret < 0) {
LOG_EX(LOG_Error, "Error poll = %d\n", ret);
return ret;
}
if(ret == 0) {
LOG_EX(LOG_Error, "poll time out!\n");
return ret;
}
if (rfds.revents & POLLIN) {
ret = TEMP_FAILURE_RETRY(read(a->evtFd[1],&c,1));
*event = (enum wpaEvent)c;
LOG_EX(LOG_Debug, "read event %d\n",c);
}
return ret;
}
static void handle_event(int event, char * remainder) {
char netid_connected[NET_ID_LEN+1] = {0};
char cmd[255] = {0}, reply[16]={0};
int len = NET_ID_LEN+1;
switch (event){
case WPAE_DISCONNECTED:
if(w->StaEvt.state == CONNECTED ||
w->StaEvt.state == NETWORK_CONNECTED){
LOG_EX(LOG_Debug, "Network disconnected!\n");
evtSend(WPA_DISCONNECTED);
w->StaEvt.state = DISCONNECTED;
w->StaEvt.event = WSE_AUTO_DISCONNECTED;
state_event_change(a->label);
}
break;
case WPAE_CONNECTED:
if(w->StaEvt.state == CONNECTING){
#if 0
if(a->netIdConnecting[0] != '\0'){
/* get already connected netid */
wpa_conf_get_ap_connected(netid_connected, &len);
LOG_EX(LOG_Debug, "connecting id %s, connected id %s\n", a->netIdConnecting, netid_connected);
if(strcmp(netid_connected,a->netIdConnecting) != 0){
LOG_EX(LOG_Debug, "*****connecting id %s != cennected id %s***\n", a->netIdConnecting, netid_connected);
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
break;
}
}
#endif
evtSend(WPAE_CONNECTED);
}else {
w->StaEvt.state = CONNECTED;
w->StaEvt.event = WSE_AUTO_CONNECTED;
state_event_change(a->label);
}
break;
case WPAE_SCAN_FAILED:
case WPAE_SCAN_RESULTS:
if(isScanEnable())
evtSend(event);
break;
case WPAE_NETWORK_NOT_FOUND:
a->netNotFoundCnt ++;
LOG_EX(LOG_Debug, "NETWORK NOT FOUND %d times!\n",a->netNotFoundCnt);
if((a->netNotFoundCnt >= NETNOTFOUNDCNT) &&
w->StaEvt.state == CONNECTING){
evtSend(WPAE_NETWORK_NOT_FOUND);
}
break;
case WPAE_UNKNOWN:
break;
}
}
static int dispatch_event(const char *event_str, int nread)
{
int i = 0, event = 0;
char event_name[18];
char cmd[255] = {0}, reply[16]={0};
char *nae_start = NULL, *nae_end = NULL;
char *event_data = NULL;
if(!event_str || !event_str[0]){
LOG_EX(LOG_Debug, "event is NULL!\n");
return 0;
}
if(strncmp(event_str, "CTRL-EVENT-", 11)){
if (!strncmp(event_str, "WPA:", 4)){
if (strstr(event_str, "pre-shared key may be incorrect")){
a->authFailCnt ++;
LOG_EX(LOG_Debug, "pre-shared key may be incorrect %d times\n",a->authFailCnt);
if(a->authFailCnt >= MAX_RETRIES_ON_AUTHENTICATION_FAILURE){
evtSend(WPAE_PASSWORD_INCORRECT);
}
return 0;
}
}
return 0;
}
nae_start = (char *)((unsigned long)event_str+11);
nae_end = strchr(nae_start, ' ');
if(nae_end){
while((nae_start < nae_end) && (i < 18)){
event_name[i] = *nae_start++;
i++;
}
event_name[i] = '\0';
} else {
LOG_EX(LOG_Debug, "Received wpa_supplicant event with empty event nae!\n");
return 0;
}
/*
* Map event nae into event enum
*/
LOG_EX(LOG_Debug, "event name:%s\n",event_name);
if(!strcmp(event_name, "CONNECTED")){
event = WPAE_CONNECTED;
}else if(!strcmp(event_name, "DISCONNECTED")){
event = WPAE_DISCONNECTED;
}else if(!strcmp(event_name, "STATE-CHANGE")){
event = WPAE_STATE_CHANGE;
}else if(!strcmp(event_name,"SCAN-FAILED")){
event = WPAE_SCAN_FAILED;
}else if(!strcmp(event_name, "SCAN-RESULTS")){
event = WPAE_SCAN_RESULTS;
}else if(!strcmp(event_name, "LINK-SPEED")){
event = WPAE_LINK_SPEED;
}else if(!strcmp(event_name, "TERMINATING")){
event = WPAE_TERMINATING;
}else if(!strcmp(event_name, "DRIVER-STATE")){
event = WPAE_DRIVER_STATE;
}else if(!strcmp(event_name, "EAP-FAILURE")){
event = WPAE_EAP_FAILURE;
}else if(!strcmp(event_name, "NETWORK-NOT-FOUND")){
event = WPAE_NETWORK_NOT_FOUND;
}else if(!strcmp(event_name, "ASSOC-REJECT")){
event = WPAE_ASSOC_REJECT;
}else{
event = WPAE_UNKNOWN;
}
event_data = (char *)((unsigned long)event_str);
if(event == WPAE_DRIVER_STATE || event == WPAE_LINK_SPEED){
return 0;
}else if(event == WPAE_STATE_CHANGE || event == WPAE_EAP_FAILURE){
event_data = strchr(event_str, ' ');
if(event_data){
event_data++;
}
}else{
event_data = strstr(event_str, " - ");
if (event_data) {
event_data += 3;
}
}
if(event == WPAE_STATE_CHANGE){
LOG_EX(LOG_Debug, "STATE_CHANGE, no care!\n");
return 0;
} else if(event == WPAE_DRIVER_STATE){
LOG_EX(LOG_Debug, "DRIVER_STATE, no care!\n");
return 0;
}else if(event == WPAE_TERMINATING){
LOG_EX(LOG_Error, "Wpa supplicant terminated!\n");
evtSend(WPAE_TERMINATING);
w->enable = false;
w->StaEvt.state = DISCONNECTED;
w->StaEvt.event = WSE_WPA_TERMINATING;
state_event_change(a->label);
return 1;
}else if(event == WPAE_EAP_FAILURE){
LOG_EX(LOG_Error, "EAP FAILURE!\n");
return 0;
}else if(event == WPAE_ASSOC_REJECT){
a->assocRejectCnt ++;
if(a->assocRejectCnt >= MAX_ASSOC_REJECT_COUNT){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
evtSend(WPAE_ASSOC_REJECT);
LOG_EX(LOG_Error, "ASSOC REJECT!\n");
}
LOG_EX(LOG_Error, "ASSOC REJECT!\n");
return 0;
}else{
handle_event(event, event_data);
}
return 0;
}
void *event_handle_thread(void* args)
{
char buf[EVENT_BUF_SIZE] = {0};
int nread = 0, ret = 0;
for(;;){
nread = wifi_wait_for_event(buf, sizeof(buf));
if (nread > 0) {
ret = dispatch_event(buf, nread);
if(ret == 1){
break; // wpa_supplicant terminated
}
} else {
continue;
}
}
pthread_exit(NULL);
}
void wifi_event_loop(tWifi_state_callback pcb)
{
/* initial */
pthread_create(&a->evtThreadId, NULL, event_handle_thread, NULL);
}
int add_wifi_state_callback_inner(tWifi_state_callback pcb)
{
if(wifi_state_callback_index >= MAX_CALLBCAKS_COUNT){
return -1;
}
wifi_state_callback[wifi_state_callback_index]=pcb;
wifi_state_callback_index++;
return 0;
}
int reset_wifi_state_callback()
{
int i=0;
for(i=0; i<wifi_state_callback_index; i++){
wifi_state_callback[i]=NULL;
}
return 0;
}
int call_state_callback_function(struct Manager *w, int state_label)
{
int i=0;
for(i=0; i<wifi_state_callback_index; i++){
if(wifi_state_callback[i] != NULL){
wifi_state_callback[i](w, state_label);
}
}
return 0;
}

View File

@ -8,15 +8,11 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <uvdbus/log.h>
#include "wifi_event.h"
#include "wifi_state_machine.h"
#include "wifi.h"
extern int disconnecting;
extern int connecting_ap_event_label;
extern int disconnect_ap_event_label;
#include "wmg_debug.h"
#include <uvdbus/log.h>
static int get_net_ip(const char *if_name, char *ip, int *len, int *vflag)
{
@ -27,14 +23,14 @@ static int get_net_ip(const char *if_name, char *ip, int *len, int *vflag)
getifaddrs(&ifAddrStruct);
pifaddr = ifAddrStruct;
while (pifaddr!=NULL) {
if (pifaddr->ifa_addr->sa_family==AF_INET) { // check it is IP4
if (pifaddr->ifa_addr->sa_family==AF_INET) { // check it is IP4
tmpAddrPtr=&((struct sockaddr_in *)pifaddr->ifa_addr)->sin_addr;
if(strcmp(pifaddr->ifa_name, if_name) == 0){
inet_ntop(AF_INET, tmpAddrPtr, ip, INET_ADDRSTRLEN);
*vflag = 4;
break;
}
} else if (pifaddr->ifa_addr->sa_family==AF_INET6) { // check it is IP6
} else if (pifaddr->ifa_addr->sa_family==AF_INET6) { // check it is IP6
// is a valid IP6 Address
tmpAddrPtr=&((struct sockaddr_in *)pifaddr->ifa_addr)->sin_addr;
if(strcmp(pifaddr->ifa_name, if_name) == 0){
@ -42,8 +38,8 @@ static int get_net_ip(const char *if_name, char *ip, int *len, int *vflag)
*vflag=6;
break;
}
}
pifaddr=pifaddr->ifa_next;
}
pifaddr=pifaddr->ifa_next;
}
if(ifAddrStruct != NULL){
@ -61,58 +57,43 @@ int is_ip_exist()
return vflag;
}
void *udhcpc_thread(void *args)
void start_udhcpc()
{
int len = 0, vflag = 0, times = 0;
char ipaddr[INET6_ADDRSTRLEN];
char cmd[256] = {0}, reply[8] = {0};
/* restart udhcpc */
system("/etc/wifi/udhcpc_wlan0 restart");
system("/etc/wifi/udhcpc_wlan0 restart >/dev/null");
/* check ip exist */
len = INET6_ADDRSTRLEN;
w->StaEvt.event = WSE_ACTIVE_OBTAINED_IP;
w->StaEvt.state = OBTAINING_IP;
state_event_change(a->label);
times = 0;
do{
usleep(100000);
if(disconnecting == 1){
system("/etc/wifi/udhcpc_wlan0 stop");
break;
}
usleep(300000);
get_net_ip("wlan0", ipaddr, &len, &vflag);
times++;
}while((vflag == 0) && (times < 310));
}while((vflag == 0) && (times < 120));
LOG_EX(LOG_Debug, "vflag= %d\n",vflag);
if(vflag != 0){
set_wifi_machine_state(CONNECTED_STATE);
set_cur_wifi_event(AP_CONNECTED);
call_event_callback_function(WIFIMG_NETWORK_CONNECTED, NULL, connecting_ap_event_label);
w->StaEvt.state = NETWORK_CONNECTED;
state_event_change(a->label);
}else{
LOG_EX(LOG_Debug, "udhcpc wlan0 timeout, pid %d!\n",pthread_self());
LOG_EX(LOG_Error, "udhcpc wlan0 timeout\n");
/* stop dhcpc thread */
system("/etc/wifi/udhcpc_wlan0 stop");
system("/etc/wifi/udhcpc_wlan0 stop >/dev/null");
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(OBTAINING_IP_TIMEOUT);
call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label);
if(w->StaEvt.state != CONNECTED){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
w->StaEvt.state = DISCONNECTED;
w->StaEvt.event = WSE_OBTAINED_IP_TIMEOUT;
state_event_change(a->label);
}
}
pthread_exit(NULL);
}
void start_udhcpc_thread(void *args)
{
pthread_t thread_id;
pthread_attr_t attr;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&thread_id, &attr, &udhcpc_thread, args);
}

File diff suppressed because it is too large Load Diff

View File

@ -19,7 +19,7 @@ int wmg_debug_timestamp = 0;
static FILE *out_file = NULL;
int wmg_set_debug_level(int level)
void wmg_set_debug_level(int level)
{
wmg_debug_level = level;
}

View File

@ -5,14 +5,9 @@
#include "wpa_supplicant_conf.h"
#include "wifi.h"
#define WPA_DIASBLE_NETWORK_CMD "DISABLE_NETWORK"
#define WPA_INTERNET_RECONNECT_SAVE 1
static const char SUPP_CONFIG_FILE[] = "/mnt/UDISK/wifi/wpa_supplicant.conf";
extern int is_ip_exist();
#include "wmg_debug.h"
#include "wifi_event.h"
#include "wifi_udhcpc.h"
int wpa_conf_network_info_exist()
{
@ -46,7 +41,7 @@ int wpa_conf_is_ap_exist(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int
int flag = 0;
if(!ssid || !ssid[0]){
LOG_EX(LOG_Debug, "Error: ssid is NULL!\n");
LOG_EX(LOG_Error, "Error: ssid is NULL!\n");
return -1;
}
@ -61,7 +56,7 @@ int wpa_conf_is_ap_exist(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int
cmd[255] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -110,7 +105,7 @@ int wpa_conf_is_ap_exist(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int
cmd[255] = '\0';
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
if(ret){
LOG_EX(LOG_Debug, "do get network %s key_mgmt error!\n", net_id);
LOG_EX(LOG_Error, "do get network %s key_mgmt error!\n", net_id);
return -1;
}
@ -157,7 +152,7 @@ int wpa_conf_ssid2netid(char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len)
cmd[15] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -190,11 +185,11 @@ int wpa_conf_ssid2netid(char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len)
p_t = strchr(p_s, '\t');
if(p_t){
int tmp = 0;
int tmp = 0;
tmp = p_t - p_s;
if(tmp <= NET_ID_LEN){
strncpy(net_id, p_s, tmp);
net_id[tmp] = '\0';
strncpy(net_id, p_s, tmp);
net_id[tmp] = '\0';
}
}
@ -203,7 +198,7 @@ int wpa_conf_ssid2netid(char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len)
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
if(ret){
LOG_EX(LOG_Debug, "do get network %s key_mgmt error!\n", net_id);
LOG_EX(LOG_Error, "do get network %s key_mgmt error!\n", net_id);
return -1;
}
@ -244,7 +239,7 @@ int wpa_conf_get_max_priority()
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -262,7 +257,7 @@ int wpa_conf_get_max_priority()
sprintf(cmd, "GET_NETWORK %s priority", net_id);
ret = wifi_command(cmd, priority, sizeof(priority));
if(ret){
LOG_EX(LOG_Debug, "do get network priority error!\n");
LOG_EX(LOG_Error, "do get network priority error!\n");
return -1;
}
@ -277,189 +272,6 @@ int wpa_conf_get_max_priority()
return max_val;
}
int wpa_conf_standardize_priority()
{
int ret = -1;
int val = -1,len = 0;
char cmd[CMD_LEN + 1] = {0}, reply[REPLY_BUF_SIZE] = {0}, priority[32] = {0};
char net_id[NET_ID_LEN+1];
char *p_n = NULL, *p_t = NULL;
/* list ap in wpa_supplicant.conf */
strncpy(cmd, "LIST_NETWORKS", CMD_LEN);
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
return -1;
}
p_n = strchr(reply, '\n');
while(p_n != NULL){
p_n++;
if((p_t = strchr(p_n, '\t')) != NULL){
len = p_t - p_n;
if(len <= NET_ID_LEN){
strncpy(net_id, p_n, len);
net_id[len] = '\0';
}
}
sprintf(cmd, "GET_NETWORK %s priority", net_id);
ret = wifi_command(cmd, priority, sizeof(priority));
if(ret){
LOG_EX(LOG_Debug, "do get network priority error!\n");
return -1;
}
if(atoi(priority) != atoi(net_id))
{
sprintf(cmd,"SET_NETWORK %s priority %s", net_id, net_id);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do set priority error!\n");
}
}
p_n = strchr(p_n, '\n');
}
return 0;
}
int wpa_conf_refresh_list(int maxLevel)
{
int ret = -1;
int val = -1,len = 0;
char cmd[CMD_LEN + 1] = {0}, reply[REPLY_BUF_SIZE] = {0}, replyNets[REPLY_BUF_SIZE] = {0},priority[32] = {0};
char net_id[NET_ID_LEN+1];
char *p_n = NULL, *p_t = NULL;
int maxId =0;
int thisId =0;
/* list ap in wpa_supplicant.conf */
strncpy(cmd, "LIST_NETWORKS", CMD_LEN);
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, replyNets, sizeof(replyNets));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
return -1;
}
p_n = strchr(replyNets, '\n');
while(p_n != NULL){
p_n++;
if((p_t = strchr(p_n, '\t')) != NULL){
len = p_t - p_n;
if(len <= NET_ID_LEN){
strncpy(net_id, p_n, len);
net_id[len] = '\0';
}
}
p_n = strchr(p_n, '\n');
if(NULL == p_n)
{
maxId = atoi(net_id);
}
}
//repointer the netid
p_n = strchr(replyNets, '\n');
if(maxId >= maxLevel)
{
while(p_n != NULL){
p_n++;
if((p_t = strchr(p_n, '\t')) != NULL){
len = p_t - p_n;
if(len <= NET_ID_LEN){
strncpy(net_id, p_n, len);
net_id[len] = '\0';
}
}
thisId = atoi(net_id);
if(thisId <= (maxId - maxLevel))
{
/* cancel saved in wpa_supplicant.conf */
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do enable network %s error!\n", net_id);
return -1;
}
}else{
sprintf(cmd, "GET_NETWORK %s priority", net_id);
ret = wifi_command(cmd, priority, sizeof(priority));
if(ret){
LOG_EX(LOG_Debug, "do get network priority error!\n");
return -1;
}
if(atoi(priority) != (thisId -maxId + maxLevel))
{
sprintf(cmd,"SET_NETWORK %s priority %d", net_id, (thisId -maxId + maxLevel));
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do set priority error!\n");
}
}
}
p_n = strchr(p_n, '\n');
}
}else
{
while(p_n != NULL){
p_n++;
if((p_t = strchr(p_n, '\t')) != NULL){
len = p_t - p_n;
if(len <= NET_ID_LEN){
strncpy(net_id, p_n, len);
net_id[len] = '\0';
}
}
sprintf(cmd, "GET_NETWORK %s priority", net_id);
ret = wifi_command(cmd, priority, sizeof(priority));
if(ret){
LOG_EX(LOG_Debug, "do get network priority error!\n");
return -1;
}
if(atoi(priority) != atoi(net_id))
{
sprintf(cmd,"SET_NETWORK %s priority %s", net_id, net_id);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do set priority error!\n");
}
}
p_n = strchr(p_n, '\n');
}
}
return 0;
}
int wpa_conf_add_on_priority_list_hdr(char * netId)
{
int ret = -1;
@ -546,35 +358,40 @@ int wpa_conf_add_on_priority_list_hdr(char * netId)
}
int wpa_conf_is_ap_connected(char *ssid, int *len)
{
int ret = -1;
char cmd[CMD_LEN+1] = {0};
char reply[REPLY_BUF_SIZE] = {0};
char *p_c=NULL;
char *p_c=NULL, *p_str = NULL;
char *p_s=NULL, *p_e=NULL, *p=NULL;
int is_ap_connected = 0;
strncpy(cmd, "LIST_NETWORKS", CMD_LEN);
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
LOG_EX(LOG_Debug, "----list network:%s\r\n",reply);
p_str = (char *)reply;
while((p_c=strstr(p_str, "[CURRENT]")) != NULL){
if(*(p_c + 9) != '\n' && *(p_c + 9) != '\0')
{
p_str = p_c+9;
continue;
}
if ((p_c=strstr(reply, "CURRENT")) != NULL){
char *p_s=NULL, *p_e=NULL, *p=NULL;
p_e = strchr(p_c, '\n');
if(p_e){
*p_e = '\0';
}
p_s = strrchr(reply, '\n');
p_s = strrchr(p_str, '\n');
p_s++;
p = strtok(p_s, "\t");
p = strtok(NULL, "\t");
@ -583,18 +400,19 @@ int wpa_conf_is_ap_connected(char *ssid, int *len)
strncpy(ssid, p, *len-1);
ssid[*len-1] = '\0';
*len = strlen(ssid);
is_ap_connected = 1;
break;
}
}
/* check ip exist */
ret = is_ip_exist();
if(ret > 0){
return 1;
}
}
return 0;
} else {
return 0;
/* check ip exist */
ret = is_ip_exist();
if(ret > 0 && is_ap_connected == 1){
return ret;
}else{
return is_ap_connected;
}
}
@ -609,7 +427,7 @@ int wpa_conf_get_netid_connected(char *net_id, int *len)
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -655,7 +473,7 @@ int wpa_conf_get_ap_connected(char *netid, int *len)
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
LOG_EX(LOG_Debug, "%s\n", reply);
@ -677,112 +495,15 @@ int wpa_conf_get_ap_connected(char *netid, int *len)
*len = strlen(netid);
}
}
LOG_EX(LOG_Debug, "net id %s\n",netid);
return 1;
} else {
LOG_EX(LOG_Debug, "no CURRENT\n");
return 0;
}
}
int wpa_conf_get_apinfo_connected(char *key_mgmt, int *priority)
{
int ret = 0;
char cmd[CMD_LEN+1] = {0};
char reply[REPLY_BUF_SIZE] = {0};
char netid[NET_ID_LEN+1] = {0};
int len = NET_ID_LEN+1;
if (netid == NULL || key_mgmt == NULL || priority == NULL)
return -1;
if (1 != wpa_conf_get_ap_connected(netid, &len))
return -1;
/* Get key_mgmt */
sprintf(cmd, "GET_NETWORK %s key_mgmt", netid);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Error, "Get network key_mgmt error!\n");
return -1;
}
strcpy(key_mgmt, reply);
LOG_EX(LOG_Debug, "Get network key_mgmt %s\n", key_mgmt);
/* Get priority */
sprintf(cmd, "GET_NETWORK %s priority", netid);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Error, "Get network priority error!\n");
return -1;
}
*priority = atoi(reply);
LOG_EX(LOG_Debug, "Get network priority %d\n", *priority);
return 0;
}
int wpa_conf_get_appwd_connected(int priority, char *pwd)
{
int ret = 0;
int i;
FILE *fp = NULL;
char line[128] = {0};
char *p_tmp = NULL;
int prio_tmp = 0;
char pwd_tmp[128] = {0};
if (pwd == NULL)
return -1;
fp = fopen(SUPP_CONFIG_FILE, "r");
if (!fp) {
LOG_EX(LOG_Debug, "Failed to fopen file: %s\n", SUPP_CONFIG_FILE);
return -1;
}
while (fgets(line, sizeof(line), fp) != NULL)
{
if (!strncmp(line, "network={", 9))
{
/* If priority does not exist, default to 0. */
prio_tmp = 0;
while (fgets(line, sizeof(line), fp) != NULL
&& strncmp(line, "}", 1))
{
if ((p_tmp = strstr(line, "priority=")) != NULL)
{
p_tmp += 9;
sscanf(p_tmp, "%d\n", &prio_tmp);
}
if ((p_tmp = strstr(line, "psk=\"")) != NULL)
{
p_tmp += 5;
strncpy(pwd_tmp, p_tmp, strlen(p_tmp));
}
}
if (prio_tmp == priority)
{
i=0;
while(pwd_tmp[i+1] != '\n')
{
pwd[i] = pwd_tmp[i];
i++;
}
pwd[i] = '\0';
LOG_EX(LOG_Debug, "Get network(priority %d) password succeed %s\n", priority, pwd);
fclose(fp);
return 0;
}
}
}
LOG_EX(LOG_Debug, "Get network(priority %d) password failed!\n", priority);
fclose(fp);
return -1;
}
int wpa_conf_enable_all_networks()
{
int ret = -1, len = 0;
@ -796,7 +517,7 @@ int wpa_conf_enable_all_networks()
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -815,7 +536,7 @@ int wpa_conf_enable_all_networks()
sprintf(cmd, "ENABLE_NETWORK %s", net_id);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do enable network %s error!\n", net_id);
LOG_EX(LOG_Error, "do enable network %s error!\n", net_id);
return -1;
}
@ -826,38 +547,13 @@ int wpa_conf_enable_all_networks()
sprintf(cmd, "%s", "SAVE_CONFIG");
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do save config error!\n");
LOG_EX(LOG_Error, "do save config error!\n");
return -1;
}
return 0;
}
int wpa_conf_disable_network(char * netId)
{
int ret = -1;
char cmd[CMD_LEN+1] = {0};
char reply[REPLY_BUF_SIZE] = {0};
/* cancel saved in wpa_supplicant.conf */
sprintf(cmd, "%s %s",WPA_DIASBLE_NETWORK_CMD,netId);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do disable network %s error!\n", netId);
return -1;
}
/* save config */
sprintf(cmd, "%s", "SAVE_CONFIG");
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do save config error!\n");
return -1;
}
return 0;
}
int wpa_conf_remove_all_networks()
{
int ret = -1, len = 0;
@ -871,7 +567,7 @@ int wpa_conf_remove_all_networks()
cmd[CMD_LEN] = '\0';
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do list networks error!\n");
LOG_EX(LOG_Error, "do list networks error!\n");
return -1;
}
@ -890,7 +586,7 @@ int wpa_conf_remove_all_networks()
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do remove network %s error!\n", net_id);
LOG_EX(LOG_Error, "do remove network %s error!\n", net_id);
return -1;
}
@ -901,7 +597,7 @@ int wpa_conf_remove_all_networks()
sprintf(cmd, "%s", "SAVE_CONFIG");
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Debug, "do save config error!\n");
LOG_EX(LOG_Error, "do save config error!\n");
return -1;
}

View File

@ -0,0 +1,27 @@
include $(TOPDIR)/rules.mk
include $(TINA_BUILD_TOP)/package/netease/Makefile.common
include $(TINA_BUILD_TOP)/build/nls.mk
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \
-I ../core/include \
-I .
local_LDFLAGS := $(BUILD_COMMON_LIB)
install:
-@mkdir -p $(CONFIG_PREFIX)/usr/bin
-@mkdir -p $(CONFIG_PREFIX)/usr/lib
-@mkdir -p $(CONFIG_PREFIX)/usr/include
@cp wifid_cmd.h $(CONFIG_PREFIX)/usr/include
#wifi_longtime_test
wifi_daemon: wifi_daemon.c wifid_ctrl.c
$(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg
@cp -f wifi_daemon $(CONFIG_PREFIX)/usr/bin
libwifid.so: wifid_cmd_handle.c wifid_cmd_iface.c
$(CC) -fPIC -shared $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) $^ -o $@ $(LIBS)
@cp $@ $(CONFIG_PREFIX)/usr/lib
####################################################################
all: install wifi_daemon libwifid.so
clean:
rm -rf wifi_daemon wifi

View File

@ -0,0 +1,142 @@
/*
* Copyright (c) 2018 Allwinner Technology. All Rights Reserved.
* Filename wifi_daemon.c
* Author laumy
* Version 0.0.1
* Date 2018.11.05
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <wifi_intf.h>
#include <pthread.h>
#include <getopt.h>
#include "wmg_debug.h"
#include <uvdbus/log.h>
#include "wifid_ctrl.h"
#include "wifi_udhcpc.h"
static void wifi_state_handle(struct Manager *w, int event_label)
{
LOG_EX(LOG_Debug, "event_label 0x%x\n", event_label);
switch(w->StaEvt.state)
{
case CONNECTING:
{
LOG_EX(LOG_Debug, "Connecting to the network......\n");
break;
}
case CONNECTED:
{
LOG_EX(LOG_Debug, "Connected to the AP\n");
start_udhcpc();
break;
}
case OBTAINING_IP:
{
LOG_EX(LOG_Debug, "Getting ip address......\n");
break;
}
case NETWORK_CONNECTED:
{
LOG_EX(LOG_Debug, "Successful network connection\n");
break;
}
case DISCONNECTED:
{
LOG_EX(LOG_Error, "Disconnected,the reason:%s\n",wmg_event_txt(w->StaEvt.event));
break;
}
}
}
static void ctl_loop_stop(int sig) {
/* Call to this handler restores the default action, so on the
* second call the program will be forcefully terminated. */
struct sigaction sigact = { .sa_handler = SIG_DFL };
sigaction(sig, &sigact, NULL);
da_ctl_free();
}
static void usage()
{
printf(" -s = log output to syslog instead of stdout\n");
printf(" -f = log output to debug file instead of stdout\n");
printf(" -d = increase debugging verbosity (-dd even more)\n");
printf(" -h = show this help text\n");
}
int main(int argc, char *argv[]){
int ret = 0, len = 0;
int times = 0, event_label = 0;;
char ssid[256] = {0}, scan_results[4096] = {0};
int debug_syslog = 0;
const char *debug_file_path = NULL;
int debug_level = 0;
int c;
const aw_wifi_interface_t *p_wifi_interface = NULL;
for (;;) {
c = getopt(argc, argv,"hf:sd");
if(c < 0)
break;
switch(c){
case 'h':
usage();
return 0;
case 'f':
debug_file_path = optarg;
break;
case 's':
debug_syslog ++;
break;
case 'd':
debug_level ++;
break;
default:
usage();
return 0;
}
}
if (NULL != debug_file_path) {
printf("debug output file:%s\n",debug_file_path);
wmg_debug_open_file(debug_file_path);
}
if (debug_syslog)
wmg_debug_open_syslog();
printf("debug levle:%d\n",MSG_INFO+debug_level);
wmg_set_debug_level(MSG_INFO+debug_level);
if(wifi_daemon_ctl_init() < 0){
LOG_EX(LOG_Error, "Failed to start wifi daemon.\n");
return 0;
}
event_label = rand();
p_wifi_interface = aw_wifi_on(wifi_state_handle, event_label);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Error, "wifi on failed\n");
return -1;
}
/* In order to receive EPIPE while writing to the pipe whose reading end
* is closed, the SIGPIPE signal has to be handled. For more information
* see the msg_pipe_write() function. */
struct sigaction sigact = { .sa_handler = SIG_IGN };
sigaction(SIGPIPE, &sigact, NULL);
/* free ctl resource */
sigact.sa_handler = ctl_loop_stop;
sigaction(SIGTERM, &sigact, NULL);
sigaction(SIGINT, &sigact, NULL);
ctl_loop(p_wifi_interface);
LOG_EX(LOG_Debug, "Exiting ctl loop\n");
return 0;
}

View File

@ -0,0 +1,40 @@
#ifndef __WIFID_CMD_H_
#define __WIFID_CMD_H_
#if __cplusplus
extern "C" {
#endif
#include <wifi_intf.h>
enum cn_event {
DA_CONNECTED,
DA_PASSWORD_INCORRECT,
DA_NETWORK_NOT_FOUND,
DA_CONNECTED_TIMEOUT,
DA_AP_ASSOC_REJECT,
DA_OBTAINED_IP_TIMEOUT,
DA_DEV_BUSING,
DA_CMD_OR_PARAMS_ERROR,
DA_KEYMT_NO_SUPPORT,
DA_UNKNOWN,
};
#define SCAN_MAX 4096
#define LIST_NETWORK_MAX 4096
int aw_wifid_connect_ap(const char *ssid, const char *passwd,enum cn_event *ptrEvent);
int aw_wifid_get_scan_results(char *results,int len);
int aw_wifid_list_networks(char *reply, size_t len);
int aw_wifid_get_status(struct wifi_status *sptr);
int aw_wifid_remove_networks(char *pssid,int len);
const char* connect_event_txt(enum cn_event event);
void aw_wifid_open(void);
void aw_wifid_close(void);
#if __cplusplus
};
#endif
#endif

View File

@ -0,0 +1,178 @@
/*
* Copyright (c) 2018 Allwinner Technology. All Rights Reserved.
* Filename wifid_cmd_handle.c
* Author laumy <liumingyuan@allwinnertech.com>
* Version 0.0.1
* Date 2018.11.05
*
*/
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "wifid_ctrl.h"
#include "wifid_cmd.h"
#include "wifid_cmd_iface.h"
#include "tool.h"
const char* connect_event_txt(enum cn_event event)
{
switch (event) {
case DA_CONNECTED:
return "connected";
case DA_PASSWORD_INCORRECT:
return "password error";
case DA_NETWORK_NOT_FOUND:
return "network not found";
case DA_CONNECTED_TIMEOUT:
return "connected timeout";
case DA_AP_ASSOC_REJECT:
return "ap assoc reject";
case DA_OBTAINED_IP_TIMEOUT:
return "obtained ip timeout";
case DA_DEV_BUSING:
return "device busing";
case DA_CMD_OR_PARAMS_ERROR:
return "command or params error";
case DA_KEYMT_NO_SUPPORT:
return "keymt no support";
default:
return "unknown";
}
}
int aw_wifid_get_scan_results(char *results,int len)
{
struct da_requst req = {
.command = DA_COMMAND_SCAN,
.ssid = {0},
.pwd = {0},
};
struct client cli = {
.enable_pipe = true,
};
int ret = -1;
if(handle_command(&req,&cli) < 0)
return -1;
if(cli.enable_pipe)
ret = read_command_message(cli.pipe_fd,results,len);
handle_command_free(&cli);
return ret ;
}
int aw_wifid_get_status(struct wifi_status *sptr)
{
struct da_requst req = {
.command = DA_COMMAND_NET_STATUS,
.ssid = {0},
.pwd = {0},
};
struct client cli = {
.enable_pipe = true,
};
int ret = -1;
if(handle_command(&req,&cli) < 0)
return -1;
if(cli.enable_pipe){
ret = read_command_message(cli.pipe_fd,(char*)sptr,sizeof(struct wifi_status));
}
handle_command_free(&cli);
return ret ;
}
int aw_wifid_connect_ap(const char *ssid, const char *passwd,enum cn_event *ptrEvent)
{
struct da_requst req = {
.command = DA_COMMAND_CONNECT,
.ssid = {0},
.pwd = {0},
};
struct client cli = {
.enable_pipe = true,
};
int ret = -1;
if (NULL != ssid){
strncpy(req.ssid,ssid,strlen(ssid));
}
if (NULL != passwd){
strncpy(req.pwd,passwd,strlen(passwd));
}
if(handle_command(&req,&cli) < 0)
return -1;
if(cli.enable_pipe){
ret = read_command_message(cli.pipe_fd,(char*)ptrEvent,sizeof(enum cn_event));
}
handle_command_free(&cli);
return ret;
}
int aw_wifid_remove_networks(char *pssid,int len)
{
struct da_requst req = {
.command = DA_COMMAND_REMOVE_NET,
.ssid = {0},
.pwd = {0},
};
struct client cli = {
.enable_pipe = false,
};
if (NULL != pssid){
strncpy(req.ssid,pssid,len);
}
if(handle_command(&req,&cli) < 0)
return -1;
handle_command_free(&cli);
return 0 ;
}
int aw_wifid_list_networks(char *reply, size_t len)
{
struct da_requst req = {
.command = DA_COMMAND_LIST_NETWOTK,
.ssid = {0},
.pwd = {0},
};
struct client cli = {
.enable_pipe = true,
};
int ret = -1;
if(handle_command(&req,&cli) < 0)
return -1;
ret = read_command_message(cli.pipe_fd,reply,len);
handle_command_free(&cli);
return ret ;
}
void aw_wifid_open(void)
{
if (get_process_state("wifi_daemon",11) == -1){
LOG_EX(LOG_Debug, "opening wifi daemon......\n");
system("/etc/init.d/wifi_daemon start");
sleep(2);
} else {
LOG_EX(LOG_Debug, "Wifi daemon is already open\n");
}
}
void aw_wifid_close(void)
{
LOG_EX(LOG_Debug, "closing wifi daemon......\n");
system("/etc/init.d/wifi_daemon stop");
sleep(1);
}

View File

@ -0,0 +1,181 @@
/*
* Copyright (c) 2018 Allwinner Technology. All Rights Reserved.
* Filename wifid_cmd_iface.c
* Author laumy <liumingyuan@allwinnertech.com>
* Version 0.0.1
* Date 2018.11.05
*
*/
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include <netinet/in.h>
#include "tool.h"
#include "wifid_cmd.h"
#include "wifid_ctrl.h"
#include "wifid_cmd_iface.h"
#define CLT_CLIENT_VERSION "181025"
static int wifid_cmd_status(const enum cmd_status status) {
switch (status) {
case DA_CMD_SUCCESS:
LOG_EX(LOG_Debug, "daemon reply code success\n");
return 0;
case DA_CODE_FAILED:
LOG_EX(LOG_Debug, "daemon reply code error unkown\n");
return -1;
case DA_CMD_ERROR:
default:
LOG_EX(LOG_Debug, "daemon reply code failed\n");
return -1;
}
}
static int wifid_send_request(int fd, const struct da_requst *req_ptr) {
enum cmd_status status = { 0xAB };
if (send(fd,req_ptr, sizeof(struct da_requst), MSG_NOSIGNAL) == -1){
LOG_EX(LOG_Error, "send command %d error:%s\n",req_ptr->command,strerror(errno));
return -1;
}
if (read(fd, &status, sizeof(status)) == -1){
LOG_EX(LOG_Error, "read command %d error:%s\n",req_ptr->command,strerror(errno));
return -1;
}
return wifid_cmd_status(status);
}
static int get_cmd_msg_transport(int fd)
{
const struct da_requst req = {
.command = DA_COMMAND_MSG_TRANSPORT,
.ssid = {0},
.pwd = {0},
};
char buf[256] = "";
int msg_fd = -1;
enum cmd_status status = { 0xAB };
struct iovec io = {
.iov_base = &status,
.iov_len = sizeof(status),
};
struct msghdr msg = {
.msg_iov = &io,
.msg_iovlen = 1,
.msg_control = buf,
.msg_controllen = sizeof(buf),
};
ssize_t len;
if(fd <= 0){
LOG_EX(LOG_Error, "damon socket fd is illegal\n");
return -1;
}
LOG_EX(LOG_Debug, "get command message reply fd\n");
if (send(fd,&req, sizeof(req), MSG_NOSIGNAL) == -1){
LOG_EX(LOG_Error, "send command error:%s\n",strerror(errno));
return -1;
}
if ((len = recvmsg(fd, &msg, MSG_CMSG_CLOEXEC)) == -1)
return -1;
struct cmsghdr *cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == NULL ||
cmsg->cmsg_level == IPPROTO_IP ||
cmsg->cmsg_type == IP_TTL) {
/* in case of error, status message is returned */
LOG_EX(LOG_Error, "cmsg error\n");
return -1;
}
if (read(fd, &status, sizeof(status)) == -1){
LOG_EX(LOG_Error, "read command error:%s\n",strerror(errno));
return -1;
}
if(wifid_cmd_status(status) != 0)
return -1;
msg_fd = *((int *)CMSG_DATA(cmsg));
LOG_EX(LOG_Debug, "get message reply fd:%d\n",msg_fd);
return msg_fd;
}
static int wifi_connect_daemon(const char *interface,struct client *c)
{
int fd, err;
struct sockaddr_un saddr = { .sun_family = AF_UNIX };
snprintf(saddr.sun_path, sizeof(saddr.sun_path) - 1,
WIFIDAEMOIN_RUN_STATE_DIR "/%s", interface);
if ((fd = socket(PF_UNIX, SOCK_SEQPACKET | SOCK_CLOEXEC, 0)) == -1)
return -1;
LOG_EX(LOG_Debug, "Connecting to socket: %s\n", saddr.sun_path);
if (connect(fd, (struct sockaddr *)(&saddr), sizeof(saddr)) == -1) {
err = errno;
close(fd);
errno = err;
LOG_EX(LOG_Error, "wifi daemon has been closed,Please open wifi daemon first.\n", saddr.sun_path);
return -1;
}
LOG_EX(LOG_Debug, "client fd :%d\n",fd);
c->da_fd = fd;
if(c->enable_pipe){
c->pipe_fd = get_cmd_msg_transport(fd);
if(c->pipe_fd < 0){
LOG_EX(LOG_Debug, "get message pipe fd failed\n");
return -1;
}
}
return 0;
}
void handle_command_free(struct client *c)
{
if(c->da_fd != -1)
close(c->da_fd);
if(c->enable_pipe && c->pipe_fd != -1)
close(c->pipe_fd);
LOG_EX(LOG_Debug, "disconnect from daemon\n");
}
int handle_command(struct da_requst *ptr_req,struct client *c)
{
if(wifi_connect_daemon(CLT_CLIENT_VERSION,c) < 0)
return -1;
if(wifid_send_request(c->da_fd,ptr_req) < 0)
return -1;
}
int read_command_message(int fd,char *buffer,int len)
{
int ret = -1;
while ((ret = read(fd, buffer,len)) == -1 && errno == EINTR)
continue;
if(ret == 0) {
LOG_EX(LOG_Debug, "message FIFO has been closed:%d\n",fd);
}
if(errno == EBADF)
ret = 0;
return ret;
}

View File

@ -0,0 +1,22 @@
#ifndef __WIFID_CMD_HANDLE_H_
#define __WIFID_CMD_HANDLE_H_
#if __cplusplus
extern "C" {
#endif
struct client {
int da_fd;
int pipe_fd;
bool enable_pipe;
};
int read_command_message(int fd,char *buffer,int len);
int handle_command(struct da_requst *ptr_req,struct client *c);
void handle_command_free(struct client *c);
#if __cplusplus
};
#endif
#endif

View File

@ -0,0 +1,403 @@
/*
* Copyright (c) 2018 Allwinner Technology. All Rights Reserved.
* Filename wifid_ctrl.c
* Author laumy <liumingyuan@allwinnertech.com>
* Version 0.0.1
* Date 2018.11.05
*
*/
#include <stdbool.h>
#include <errno.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/un.h>
#include "tool.h"
#include "wifid_cmd.h"
#include "wifid_ctrl.h"
#define CLT_VERSION "181025"
struct da_ctl ctl = {
.socket_created = false,
.msg_pipe_fd = {-1,-1},
.enable = false,
};
static int msg_pipe_close(void)
{
int ret = 0;
if(ctl.msg_pipe_fd[0] != -1) {
ret = close(ctl.msg_pipe_fd[0]);
if(ret != 0){
LOG_EX(LOG_Error, "close msg pipe 0:%s\n",strerror(errno));
}else {
ctl.msg_pipe_fd[0] = -1;
}
}
if(ctl.msg_pipe_fd[1] != -1) {
ret = close(ctl.msg_pipe_fd[1]);
if(ret != 0){
LOG_EX(LOG_Error, "close msg pipe 1:%s\n",strerror(errno));
}else {
ctl.msg_pipe_fd[1] = -1;
}
}
return ret ;
}
static int msg_pipe_write(const char *buffer,size_t len)
{
int ret = -1;
const uint8_t *head = (uint8_t *)buffer;
do {
ret = write(ctl.msg_pipe_fd[1],head,len);
if(ret == -1) {
if(errno == EINTR)
continue;
if(errno == EPIPE) {
LOG_EX(LOG_Error, "FIFO endpoint has been closed: %d\n",ctl.msg_pipe_fd[1]);
goto end;
}
}
head += ret;
len -= ret;
} while (len != 0);
end:
return ret;
}
static void wifid_msg_transport(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface,int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
LOG_EX(LOG_Debug, "ctl msg fd reply start -+- \n");
if (pipe(ctl.msg_pipe_fd) == -1) {
LOG_EX(LOG_Error, "Couldn't create FIFO: %s", strerror(errno));
status = DA_CODE_FAILED;
goto final;
}
LOG_EX(LOG_Debug, "created pipe fd[0]=%d,fd[1]=%d\n",ctl.msg_pipe_fd[0],ctl.msg_pipe_fd[1]);
union {
char buf[CMSG_SPACE(sizeof(int))];
struct cmsghdr _align;
} control_un;
struct iovec io = { .iov_base = "", .iov_len = 1};
struct msghdr msg = {
.msg_iov = &io,
.msg_iovlen = 1,
.msg_control = control_un.buf,
.msg_controllen = sizeof(control_un.buf),
};
struct cmsghdr *cmptr = CMSG_FIRSTHDR(&msg);
cmptr->cmsg_level = SOL_SOCKET;
cmptr->cmsg_type = SCM_RIGHTS;
cmptr->cmsg_len = CMSG_LEN(sizeof(int));
int *fdptr = (int *)CMSG_DATA(cmptr);
/*pipe fd[1] must write, pipe fd[0] must read*/
*fdptr = ctl.msg_pipe_fd[0];
if (sendmsg(fd,&msg,0) == -1)
goto fail;
/*client will read this fd,so close it */
close(*fdptr);
ctl.msg_pipe_fd[0] = -1;
goto final;
fail:
LOG_EX(LOG_Error, "send ctl cmd msg fd failed\n");
msg_pipe_close();
final:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl msg fd reply end -+- \n");
}
static void wifid_connect(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface,int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
enum cn_event event = DA_UNKNOWN;
enum wmgEvent wmg_event;
LOG_EX(LOG_Debug, "ctl command: connecet start -+- \n");
if(NULL == p_wifi_interface)
goto code_failed;
p_wifi_interface->connect_ap(r->ssid,r->pwd,fd);
if(aw_wifi_get_wifi_state() == NETWORK_CONNECTED){
event = DA_CONNECTED;
} else {
wmg_event = aw_wifi_get_wifi_event();
LOG_EX(LOG_Debug, "wifi manager event:%s\n",wmg_event_txt(wmg_event));
switch(wmg_event){
case WSE_CONNECTED_TIMEOUT:
event = DA_CONNECTED_TIMEOUT;
break;
case WSE_AP_ASSOC_REJECT:
event = DA_AP_ASSOC_REJECT;
break;
case WSE_NETWORK_NOT_EXIST:
event = DA_NETWORK_NOT_FOUND;
break;
case WSE_PASSWORD_INCORRECT:
event = DA_PASSWORD_INCORRECT;
break;
case WSE_OBTAINED_IP_TIMEOUT:
event = DA_OBTAINED_IP_TIMEOUT;
break;
case WSE_DEV_BUSING:
event = DA_DEV_BUSING;
break;
case WSE_CMD_OR_PARAMS_ERROR:
event = DA_CMD_OR_PARAMS_ERROR;
break;
case WSE_KEYMT_NO_SUPPORT:
event = DA_KEYMT_NO_SUPPORT;
break;
case WSE_WPA_TERMINATING:
default:
event = DA_UNKNOWN;
break;
}
}
if(msg_pipe_write((char*)&event,sizeof(event)) >= 0)
goto end;
code_failed:
status = DA_CODE_FAILED;
end:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl command: connecet end -+- \n");
}
static void wifid_net_status(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface,int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
struct wifi_status s = {
.state = STATE_UNKNOWN ,
.ssid = {'\0'},
};
LOG_EX(LOG_Debug, "ctl cmd: status start -+- \n");
if(NULL == p_wifi_interface)
goto code_failed;
if(p_wifi_interface->get_status(&s) < 0)
goto code_failed;
if(msg_pipe_write((char*)&s,sizeof(s)) >= 0)
goto end;
code_failed:
status = DA_CODE_FAILED;
end:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl cmd: status end -+- \n");
}
static void wifid_scan(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface,int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
char scan_results[SCAN_MAX] = {0};
int len = SCAN_MAX;
LOG_EX(LOG_Debug, "ctl cmd: scan start -+- \n");
if(NULL == p_wifi_interface)
goto code_failed;
if( p_wifi_interface->get_scan_results(scan_results,&len) < 0)
goto code_failed;
if(msg_pipe_write(scan_results,len) >= 0)
goto end;
code_failed:
status = DA_CODE_FAILED;
end:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl cmd: scan end -+- \n");
}
static void wifid_list_network(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface, int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
char list_network_results[LIST_NETWORK_MAX] = {0};
LOG_EX(LOG_Debug, "ctl cmd: list network start -+- \n");
if(NULL == p_wifi_interface)
goto code_failed;
if(p_wifi_interface->list_networks(list_network_results,LIST_NETWORK_MAX,fd) < 0)
goto code_failed;
if(msg_pipe_write(list_network_results,LIST_NETWORK_MAX) >= 0)
goto end;
code_failed:
status = DA_CODE_FAILED;
end:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl cmd: list network end -+- \n");
}
static void wifid_remove_net(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface, int fd)
{
enum cmd_status status = DA_CMD_SUCCESS;
struct WmgStaEvt StaEvt = {CONNECTED,WSE_UNKNOWN};
LOG_EX(LOG_Debug, "ctl command: disconnect start -+- \n");
if(NULL == p_wifi_interface)
goto code_failed;
if( p_wifi_interface->clear_network(r->ssid) >= 0)
goto end;
code_failed:
status = DA_CODE_FAILED;
end:
send(fd, &status, sizeof(status), MSG_NOSIGNAL);
LOG_EX(LOG_Debug, "ctl command: disconnect end -+- \n");
}
void da_ctl_free(void)
{
size_t i;
for (i = 0; i < ARRAYSIZE(ctl.pfds); i++)
if (ctl.pfds[i].fd != -1)
close(ctl.pfds[i].fd);
if (ctl.socket_created) {
char tmp[256] = WIFIDAEMOIN_RUN_STATE_DIR "/";
unlink(strcat(tmp, CLT_VERSION));
ctl.socket_created = false;
}
ctl.enable = false;
}
static void wifid_close(const struct da_requst *r, const aw_wifi_interface_t *p_wifi_interface, int fd)
{
da_ctl_free();
}
int wifi_daemon_ctl_init(void)
{
size_t i;
for (i = 0; i < ARRAYSIZE(ctl.pfds); i++) {
ctl.pfds[i].events = POLLIN;
ctl.pfds[i].fd = -1;
}
struct sockaddr_un saddr = { .sun_family = AF_UNIX };
snprintf(saddr.sun_path, sizeof(saddr.sun_path) - 1,
WIFIDAEMOIN_RUN_STATE_DIR "/%s", CLT_VERSION);
if (mkdir(WIFIDAEMOIN_RUN_STATE_DIR, 0755) == -1 && errno != EEXIST)
goto fail;
if ((ctl.pfds[CTL_IDX_SRV].fd = socket(PF_UNIX, SOCK_SEQPACKET, 0)) == -1)
goto fail;
if (bind(ctl.pfds[CTL_IDX_SRV].fd, (struct sockaddr *)(&saddr), sizeof(saddr)) == -1)
goto fail;
ctl.socket_created = true;
if (chmod(saddr.sun_path, 0660) == -1)
goto fail;
if (listen(ctl.pfds[CTL_IDX_SRV].fd, 2) == -1)
goto fail;
ctl.enable = true;
return 0;
fail:
da_ctl_free();
return -1;
}
void ctl_loop(const aw_wifi_interface_t *p_wifi_interface)
{
static void (*commands[__DA_COMMAND_MAX])(const struct da_requst *,const aw_wifi_interface_t * ,int) = {
[DA_COMMAND_CONNECT] = wifid_connect,
[DA_COMMAND_SCAN] = wifid_scan,
[DA_COMMAND_REMOVE_NET] = wifid_remove_net,
[DA_COMMAND_LIST_NETWOTK] = wifid_list_network,
[DA_COMMAND_MSG_TRANSPORT] = wifid_msg_transport,
[DA_COMMAND_NET_STATUS] = wifid_net_status,
};
LOG_EX(LOG_Debug, "Starting controller loop\n");
while(ctl.enable){
if (poll(ctl.pfds, ARRAYSIZE(ctl.pfds), -1) == -1) {
if (errno == EINTR)
continue;
LOG_EX(LOG_Error, "Controller poll error: %s", strerror(errno));
break;
}
struct pollfd *pfd = NULL;
size_t i;
/* handle data transmission with connected clients */
for (i = __CTL_IDX_MAX; i < __CTL_IDX_MAX + WIFI_MAX_CLIENTS; i++) {
const int fd = ctl.pfds[i].fd;
if(fd == -1) {
/*pointed to clt.pfds */
pfd = &ctl.pfds[i];
continue;
}
if (ctl.pfds[i].revents & POLLIN) {
struct da_requst request;
ssize_t len;
if ((len = recv(fd, &request, sizeof(request), MSG_DONTWAIT)) != sizeof(request)) {
/* if the request cannot be retrieved, release resources */
if (len == 0)
LOG_EX(LOG_Debug, "Client closed connection: %d\n", fd);
else
LOG_EX(LOG_Debug, "Invalid request length: %zd != %zd\n", len, sizeof(request));
close(fd);
ctl.pfds[i].fd = -1;
/*when client is closed,pipe closed*/
msg_pipe_close();
LOG_EX(LOG_Debug, "+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n\n");
continue;
}
/* validate and execute requested command */
if (request.command < __DA_COMMAND_MAX && commands[request.command] != NULL)
commands[request.command](&request, p_wifi_interface,fd);
else
LOG_EX(LOG_Debug, "Invalid command: %u\n", request.command);
}
}
/* process new connections to our controller */
if (ctl.pfds[CTL_IDX_SRV].revents & POLLIN && pfd != NULL) {
struct pollfd fd = { -1, POLLIN, 0 };
uint16_t ver = 0;
fd.fd = accept(ctl.pfds[CTL_IDX_SRV].fd, NULL, NULL);
LOG_EX(LOG_Debug, "+-+-+-+-+-+-+-+-+-+-+-+-+-+-\n");
LOG_EX(LOG_Debug, "Received new connection: %d\n", fd.fd);
//add poll waiting queue
pfd->fd = fd.fd;
}
}
}

View File

@ -0,0 +1,58 @@
#ifndef __WIFID_CTL_H_
#define __WIFID_CTL_H_
#if __cplusplus
extern "C" {
#endif
#include <poll.h>
#include <wifi_intf.h>
enum da_command {
DA_COMMAND_CONNECT,
DA_COMMAND_SCAN,
DA_COMMAND_REMOVE_NET,
DA_COMMAND_LIST_NETWOTK,
DA_COMMAND_MSG_TRANSPORT,
DA_COMMAND_NET_STATUS,
__DA_COMMAND_MAX
};
enum cmd_status {
DA_CMD_SUCCESS,
DA_CMD_ERROR,
DA_CODE_FAILED,
};
struct da_requst {
enum da_command command;
char ssid[48];
char pwd[48];
};
#define ARRAYSIZE(a) (sizeof(a) / sizeof(*(a)))
#define WIFIDAEMOIN_RUN_STATE_DIR "/var/run/wifidaemon"
/* Indexes of special file descriptors in the poll array. */
#define CTL_IDX_SRV 0
#define __CTL_IDX_MAX 1
#define WIFI_MAX_CLIENTS 1
struct da_ctl {
bool socket_created;
struct pollfd pfds[__CTL_IDX_MAX + WIFI_MAX_CLIENTS];
int msg_pipe_fd[2];
bool enable;
};
void da_ctl_free(void);
int wifi_daemon_ctl_init(void);
void ctl_loop(const aw_wifi_interface_t *p_wifi_interface);
#if __cplusplus
};
#endif
#endif

View File

@ -1,43 +0,0 @@
#ifndef BROADLINK_IOT_H
#define BROADLINK_IOT_H
#ifndef PLATFORM_CPU
#define BL_IOT_MSG_TAGS ("BLNLINK")
#define BL_IOT_MGMT_FRAME_TYPE_ACTION 2 /* Use action frame to respond to Broadlink device. */
#define BL_MASTER_ID_FOR_NETEASE 202
#define BL_MAX_MSG (1024)
#define ETH_ALEN (6)
typedef enum
{
MSG_IN_DISCOVERY_MODE = 0,
MSG_OUT_DISCOVERY_MODE,
MSG_GET_WLAN_INFO,
MSG_BYPASS_MODE,
} BL_IOT_MSG_TYPE;
#pragma pack (push)
#pragma pack (1)
typedef struct
{
unsigned char msgTags[8];
unsigned char dstMac[ETH_ALEN];
unsigned char msgType;
unsigned int msglen;
unsigned char msgData[BL_MAX_MSG];
} BL_IOT_MSG, *PBL_IOT_MSG;
typedef struct
{
unsigned char channel;
unsigned char dev_mac[ETH_ALEN];
unsigned char bssid[ETH_ALEN];
unsigned char ssid[32];
} WL_INFO, *PWL_INFO;
#pragma pack (pop)
#define BL_IOT_MSG_LEN(len) (sizeof(BL_IOT_MSG) - BL_MAX_MSG + len)
void bl_recv_msg_thread(void *pParam);
int bl_create_socket(void);
#endif
#endif

View File

@ -1,213 +0,0 @@
#ifndef __SDK_H
#define __SDK_H
/*
* 0. implement all callback's of this SDK
* 1. read wifi probe frame from driver
* 2. feed wifi probe frame to sdk_pkt_process
* 3. this sdk depends on no thirdparty libraries, and there is no internet connection with net.
*/
typedef unsigned char uint8;
typedef unsigned short int uint16;
typedef unsigned int uint32;
typedef char int8;
typedef short int int16;
typedef int int32;
#define SDK_SUCCESS (0)
#define SDK_FAIL (1)
#define SDK_NULL (0)
#define OUI_LEN (3)
#define OUI_TYPE (0)
#define OUI_TYPE_LEN (1)
#define MAC_LEN (6)
#define SSID_MAX_LEN (64)
#define PASSWORD_MAX_LEN (64)
#define KEY_MGMT_LEN (16)
#define SDK_SHAREDKEY_LEN (32)
#define SDK_FRAME_MAX_LEN (1460)
#define FASTCON_MASTER_ID_LEN (4)
#define SDK_PACKED __attribute__((packed))
typedef void* (*sdk_memset_t) (
void* ptr,
int32 value,
uint32 num);
typedef void* (*sdk_memcpy_t) (
void* dst,
const void* src,
uint32 num);
typedef int32 (*sdk_memcmp_t) (
const void* ptr1,
const void* ptr2,
uint32 num);
typedef int32 (*sdk_printf_t) (
const char* format,
...);
typedef struct sdk_device_info_t {
uint32 vendor_id;
uint32 product_id;
uint8 mac[MAC_LEN];
uint8 * device_info;
uint16 device_info_len;
uint8 * device_id;
uint16 device_id_len;
}sdk_product_info_t;
//发现设备
typedef int32 (*sdk_found_device_t) (sdk_product_info_t *product_info);
//对应2.1 云端身份校验接口请求
typedef int32 (*sdk_challenge_post_t)(
sdk_product_info_t *product_info,
uint8 * challenge,
uint16 challenge_len);
//对应2.2 设备身份声明接口请求
typedef int32 (*sdk_signature_post_t)(
sdk_product_info_t *product_info,
uint8 * signature,
uint16 signature_len);
//sdk将设备控制token传给上层
typedef int32 (*sdk_device_token_post_t)(
sdk_product_info_t *product_info,
uint8 * token,
uint16 token_len);
//上报配置结果
//目前只支持失败结果上报。
//成功的结果是由云端推送上线通知
//result 0:成功 -1:失败
typedef int32 (*sdk_config_result_post_t) (
sdk_product_info_t *product_info,
int8 result);
//发送802.11原始报文接口
typedef int32 (*sdk_raw_pkt_send_t)(
uint8 * frame,
uint16 frame_len);
typedef struct {
sdk_memset_t memset;
sdk_memcpy_t memcpy;
sdk_memcmp_t memcmp;
sdk_printf_t printf;
sdk_found_device_t found_device;
sdk_challenge_post_t challenge_post;
sdk_signature_post_t signature_post;
sdk_device_token_post_t device_token_post;
sdk_config_result_post_t config_result_post;
sdk_raw_pkt_send_t send_raw_pkt;
} sdk_config_t;
typedef struct {
//gateway信息
//包括当前路由器信道gateway macbssid
uint8 channel; //cur channel
//若mac地址为00-11-22-33-44-55则device_mac[] = {0x00,0x11,0x22,0x33,0x44,0x55};
uint8 device_mac[MAC_LEN];
//AP的mac地址格式等同device_mac
uint8 bssid[MAC_LEN];
//由dnakit后台分配用于区分不同平台固定4个字节
uint8 fastcon_master_id[FASTCON_MASTER_ID_LEN];
//0:probe req,1:probe rsp,2:action
//报文选择根据gateway 能力自行设置
uint8 send_wlan_type;
//回调接口注册
sdk_config_t sdk_config;
} SDK_PACKED sdk_user_init_t;
typedef enum {
SDK_STATE_PROBE_DEVICE,
SDK_STATE_LOCK_CHANNEL,
SDK_STATE_CONFIG,
SDK_STATE_CONNECTING,
SDK_STATE_DONE, //Finish
SDK_STATE_FAIL,
} sdk_state_e;
/**
* @brief sdk编译时间
* @return 0
* SDK_E_INIT_FAIL sdk未初始化
*/
extern int32 sdk_version(void);
/**
* @brief sdk
* @param init
* @return 0
* SDK_E_INIT_FAIL
*/
extern int32 sdk_init(sdk_user_init_t *init);
/**
* @brief 802.11
* @param frame 802.11
* @param frame_len
* @return sdk_state_e
SDK_E_INIT_FAIL
*/
extern int32 sdk_pkt_process(uint8 *frame, int16 frame_len);
/**
* @brief token bind成功报文
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_device_token_bind_success(void);
/**
* @brief ssid和password信息发送
* @param sharedkey
* @param ssid
* @param ssid_len
* @param password
* @param password_len
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
* @example ssid为"ssid"password为"password"
*
* @code
* uint8 ssid[] = "ssid";
* uint8 password[] = "password";
* sdk_wlan_params_set(sharedkey,ssid,strlen(ssid),password,strlen(password));
* @endcode
*/
extern int32 sdk_wlan_params_set(uint8 sharedkey[SDK_SHAREDKEY_LEN],uint8 *ssid,uint16 ssid_len,uint8 *password,uint16 password_len);
/**
* @brief challenge和signature信息发送
* @param challenge
* @param challenge_len
* @param signature
* @param signature_len
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_challenge_and_signature_set(uint8 *challenge,uint16 challenge_len, uint8 *signature, uint16 signature_len);
/**
* @brief
* @return 0
* SDK_E_INIT_FAIL
* SDK_E_STATE
*/
extern int32 sdk_user_auth_to_start_config(void);
/**
* @brief sdk状态
* @return 0
* SDK_E_INIT_FAIL
*/
extern int32 sdk_deinit(void);
#endif

View File

@ -1,19 +0,0 @@
#ifndef __SDK_ERRNO_H
#define __SDK_ERRNO_H
#define SDK_E_INIT_FAIL (-1) //SDK初始化失败
#define SDK_E_INVPARAMS (-2) //参数异常
#define SDK_E_STATE (-3) //sdk状态异常
//only use by sdk_config_result_post_t
#define SDK_E_CONNECT_AP_TIMEOUT (-101) //连接ap超时
#define SDK_E_PKT_SEND (-102) //发送数据包失败
#define SDK_E_OVER_RETRY_COUNT (-103) //超过最大重试次数
#define SDK_E_VERIFY_SIGNATURE (-104) //校验网关端身份失败
#define SDK_E_SSID_PWD (-105) //ssid和pwd解析异常
#define SDK_E_MSG_NOT_SUPPORT (-106) //接收到不支持的消息类型
#define SDK_E_CONFIG_TIMEOUT (-107) //配置超时超过10分钟配置时间
#endif

View File

@ -1,57 +0,0 @@
#ifndef __WIFI_EVENT_H
#define __WIFI_EVENT_H
#include "wifi_intf.h"
#define EVENT_BUF_SIZE 2048
#if __cplusplus
extern "C" {
#endif
#define MAX_ASSOC_REJECT_COUNT 3
#define MAX_RETRIES_ON_AUTHENTICATION_FAILURE 2
enum WPA_EVENT{
CONNECTED = 1,
DISCONNECTED,
STATE_CHANGE,
SCAN_RESULTS,
LINK_SPEED,
TERMINATING,
DRIVER_STATE,
EAP_FAILURE,
ASSOC_REJECT,
SSID_TEMP_DISABLED,
UNKNOWN,
};
typedef enum{
AP_DISCONNECTED,
AP_CONNECTED,
PASSWORD_INCORRECT,
CONNECT_AP_TIMEOUT,
OBTAINING_IP_TIMEOUT,
}tWIFI_EVENT_INNER;
void wifi_event_loop(tWifi_event_callback pcb);
void wifi_event_loop_stop();
void wifi_event_loop_restart();
void start_wifi_on_check_connect_timeout();
void start_check_connect_timeout();
tWIFI_EVENT_INNER get_cur_wifi_event();
int set_cur_wifi_event(tWIFI_EVENT_INNER event);
void set_scan_start_flag();
void set_wifi_off_flag(int value);
int get_scan_status();
void reset_assoc_reject_count();
int get_assoc_reject_count();
int add_wifi_event_callback_inner(tWifi_event_callback pcb);
int call_event_callback_function(tWIFI_EVENT wifi_event, char *buf, int event_label);
int reset_wifi_event_callback();
void stop_connecting();
#if __cplusplus
}; // extern "C"
#endif
#endif /*__WIFI_EVENT_H*/

View File

@ -1,83 +0,0 @@
#ifndef __WIFI_INTF_H
#define __WIFI_INTF_H
#if __cplusplus
extern "C" {
#endif
#include <stdlib.h>
#include <stdio.h>
#define MAX_CALLBCAKS_COUNT 1024
typedef enum {
WIFIMG_NONE = 0,
WIFIMG_WPA_PSK,
WIFIMG_WPA2_PSK,
WIFIMG_WEP,
}tKEY_MGMT;
typedef enum{
WIFIMG_WIFI_ON_SUCCESS = 0xf000,
WIFIMG_WIFI_ON_FAILED,
WIFIMG_WIFI_OFF_SUCCESS,
WIFIMG_WIFI_OFF_FAILED,
WIFIMG_NO_NETWORK_CONNECTING,
WIFIMG_CMD_OR_PARAMS_ERROR,
WIFIMG_KEY_MGMT_NOT_SUPPORT,
WIFIMG_OPT_NO_USE_EVENT,
WIFIMG_NETWORK_NOT_EXIST,
WIFIMG_DEV_BUSING_EVENT,
WIFIMG_NETWORK_DISCONNECTED,
WIFIMG_NETWORK_CONNECTED,
WIFIMG_PASSWORD_FAILED,
WIFIMG_CONNECT_TIMEOUT,
}tWIFI_EVENT;
typedef enum{
WIFI_MANAGER_SUCCESS = 0,
WIFI_MANAGER_FAILED = -1,
}tRETURN_CODE;
typedef enum{
WIFIMG_WIFI_ENABLE = 0x1000,
WIFIMG_WIFI_DISCONNECTED,
WIFIMG_WIFI_BUSING,
WIFIMG_WIFI_CONNECTED,
WIFIMG_WIFI_DISABLED,
}tWIFI_STATE;
typedef void (*tWifi_event_callback)(tWIFI_EVENT wifi_event, void *buf, int event_lebal);
typedef struct{
int (*add_event_callback)(tWifi_event_callback pcb);
int (*is_ap_connected)(char *ssid, int *len);
int (*start_scan)(int event_label);
int (*get_scan_results)(char *result, int *len);
int (*connect_ap)(const char *ssid, const char *passwd, int event_label);
int (*connect_ap_key_mgmt)(const char *ssid, tKEY_MGMT key_mgnt, const char *passwd, int event_label);
int (*connect_ap_auto)(int event_label);
int (*connect_ap_with_netid)(const char *net_id, int event_label);
int (*add_network)(const char *ssid, tKEY_MGMT key_mgnt, const char *passwd, int event_label);
int (*disconnect_ap)(int event_label);
int (*remove_network)(char *ssid, tKEY_MGMT key_mgmt);
int (*remove_all_networks)(void);
int (*re_config)(void);
int (*list_networks)(char *reply, size_t reply_len, int event_label);
int (*get_netid)(const char *ssid, tKEY_MGMT key_mgmt, char *net_id);
int (*change_ap)(int event_label );
int (*enable_all_network)(void);
}aw_wifi_interface_t;
const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label);
int aw_wifi_get_wifi_state();
int aw_wifi_off(const aw_wifi_interface_t *p_wifi_interface_t);
int bl_sdk_init();
int bl_event_handle(unsigned int cmd, const char* msg);
#if __cplusplus
}; // extern "C"
#endif
#endif

View File

@ -1,23 +0,0 @@
#ifndef __WIFI_STATE_H
#define __WIFI_STATE_H
#if __cplusplus
extern "C" {
#endif
typedef enum{
DISCONNECTED_STATE = 0xf0,
CONNECTING_STATE,
L2CONNECTED_STATE,
CONNECTED_STATE,
DISCONNECTING_STATE,
}tWIFI_MACHINE_STATE;
int set_wifi_machine_state(tWIFI_MACHINE_STATE state);
tWIFI_MACHINE_STATE get_wifi_machine_state();
#if __cplusplus
}; // extern "C"
#endif
#endif /*__WIFI_STATE_H*/

View File

@ -1,490 +0,0 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<pthread.h>
#include<sys/time.h>
#include <netinet/ether.h>
#include <linux/wireless.h>
#include <sys/ioctl.h>
#include <uvdbus/log.h>
#include "wifi_event.h"
#include "network_manager.h"
#include "wifi_intf.h"
#include "wifi.h"
#include "broadlink.h"
#define MAX_SCAN_FAIL_TIME 5
#define WAITING_CLK_COUNTS 50
#define UTF8_BYTES_MAX 4096
#define UTF8_MULTI_BYTES_MASK 0x80
#define ESCAP_CHAR_ASCII '\\'
#define DQUOT_CHAR_ASCII '\"'
#define QUOT_CHAR_ASCII '\''
/* scan thread */
static pthread_t scan_thread_id;
static int scan_running = 0;
static pthread_mutex_t scan_mutex;
static pthread_cond_t scan_cond;
static int scan_pause = 0;
/* run scan immediately */
static pthread_mutex_t thread_run_mutex;
static pthread_cond_t thread_run_cond;
/* store scan results */
static char scan_results[SCAN_BUF_LEN];
static int scan_results_len = 0;
static int scan_completed = 0;
/* broadlink thread */
static pthread_t broadlink_thread_id;
static int broadlink_thread_running = 0;
int update_scan_results()
{
int i=0;
LOG_EX(LOG_Debug, "update scan results enter\n");
pthread_mutex_lock(&thread_run_mutex);
scan_completed = 0;
pthread_cond_signal(&thread_run_cond);
pthread_mutex_unlock(&thread_run_mutex);
while(i <= 15){
usleep(200*1000);
if(scan_completed == 1){
break;
}
i++;
}
return 0;
}
int get_scan_results_inner(char *result, int *len)
{
int index = 0;
char *ptr = NULL;
pthread_mutex_lock(&scan_mutex);
if(*len <= scan_results_len){
strncpy(result, scan_results, *len-1);
index = *len -1;
result[index] = '\0';
ptr=strrchr(result, '\n');
if(ptr != NULL){
*ptr = '\0';
}
}else{
strncpy(result, scan_results, scan_results_len);
result[scan_results_len] = '\0';
}
pthread_mutex_unlock(&scan_mutex);
return 0;
}
int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt)
{
int ret = 0, i = 0, key[4] = {0};
for(i=0; i<4; i++){
key[i]=0;
}
get_key_mgmt(ssid, key);
if(key_mgmt == WIFIMG_NONE){
if(key[0] == 1){
ret = 1;
}
}else if(key_mgmt == WIFIMG_WPA_PSK || key_mgmt == WIFIMG_WPA2_PSK){
if(key[1] == 1){
ret = 1;
}
}else if(key_mgmt == WIFIMG_WEP){
if(key[2] == 1){
ret = 1;
}
}else{
;
}
return ret;
}
char getHalfByteCharac(char val)
{
char ret =-1;
if(9 >= (val&0x0f)) ret = (val&0x0f)+'0';
else ret = (val&0x0f)-10+'a';
return ret;
}
int utf8BytesExchangeEx(char *pCharIn,char ** pCharOut)
{
int size =0;
char * p_data = NULL;
char buf[UTF8_BYTES_MAX]={0x00};
int index =0;
int cpPos=0;
if(NULL == pCharIn)
{
return -1;
}
size =strlen(pCharIn);
p_data = pCharIn;
while(index<= size)
{
if(0 != ( (*p_data)&UTF8_MULTI_BYTES_MASK))
{
buf[cpPos++]='\\';
buf[cpPos++]='x';
buf[cpPos++]= getHalfByteCharac((*p_data)>>4);
buf[cpPos++]= getHalfByteCharac((*p_data)&0xf);
}else if( (*p_data) == ESCAP_CHAR_ASCII)
{
buf[cpPos++] = ESCAP_CHAR_ASCII;
buf[cpPos++] = ESCAP_CHAR_ASCII;
}else if( (*p_data) == DQUOT_CHAR_ASCII)
{
buf[cpPos++] = ESCAP_CHAR_ASCII;
buf[cpPos++] = DQUOT_CHAR_ASCII;
}else if((*p_data) == QUOT_CHAR_ASCII)
{
buf[cpPos++] = QUOT_CHAR_ASCII;
}
else
{
buf[cpPos++] = *p_data;
}
index++;
p_data++;
}
* pCharOut = malloc(strlen(buf)+1);
if(NULL == * pCharOut) return -1;
memset(* pCharOut,0x00,strlen(buf)+1);
memcpy(* pCharOut,buf,strlen(buf));
return 0;
}
int get_key_mgmt(const char *ssid, int key_mgmt_info[])
{
char *ptr = NULL, *pssid_start = NULL, *pssid_end = NULL;
char *pst = NULL, *pend = NULL;
char *pflag = NULL;
char flag[128];
int len = 0, i = 0;
char * pSsidSearch = NULL;
int status=0;
LOG_EX(LOG_Debug, "enter get_key_mgmt, ssid %s\n", ssid);
key_mgmt_info[KEY_NONE_INDEX] = 0;
key_mgmt_info[KEY_WEP_INDEX] = 0;
key_mgmt_info[KEY_WPA_PSK_INDEX] = 0;
pthread_mutex_lock(&scan_mutex);
/* first line end */
ptr = strchr(scan_results, '\n');
if(!ptr){
pthread_mutex_unlock(&scan_mutex);
LOG_EX(LOG_Debug, "no ap scan, return\n");
return 0;
}
//point second line of scan results
status = utf8BytesExchangeEx(ssid,&pSsidSearch);
if(0 != status)
{
LOG_EX(LOG_Debug, "utf8 exchange err\r\n");
goto ToOut;
}
LOG_EX(LOG_Debug, "changed ssid is %s\r\n",pSsidSearch);
ptr++;
while((pssid_start=strstr(ptr, pSsidSearch)) != NULL){
pssid_end = pssid_start + strlen(pSsidSearch);
/* ssid is presuffix of searched network */
if((*pssid_end != '\n') && (*pssid_end != '\0')){
pend = strchr(pssid_start, '\n');
if(pend != NULL){
ptr = pend+1;
continue;
}else{
break;
}
}
/* network ssid is same of searched network */
/* line end */
pend = strchr(pssid_start, '\n');
if(pend != NULL){
*pend = '\0';
}
pst = strrchr(ptr, '\n');
if(pst != NULL){
pst++;
}else{
pst = ptr;
}
pflag = pst;
for(i=0; i<3; i++){
pflag = strchr(pflag, '\t');
pflag++;
}
len = pssid_start - pflag;
len = len - 1;
strncpy(flag, pflag, len);
flag[len] = '\0';
LOG_EX(LOG_Debug, "ssid %s, flag %s\n", ssid, flag);
if((strstr(flag, "WPA-PSK-") != NULL)
|| (strstr(flag, "WPA2-PSK-") != NULL)){
key_mgmt_info[KEY_WPA_PSK_INDEX] = 1;
}else if(strstr(flag, "WEP") != NULL){
key_mgmt_info[KEY_WEP_INDEX] = 1;
}else if((strcmp(flag, "[ESS]") == 0) || (strcmp(flag, "[WPS][ESS]") == 0)){
key_mgmt_info[KEY_NONE_INDEX] = 1;
}else{
;
}
if(pend != NULL){
*pend = '\n';
//point next line
ptr = pend+1;
}else{
break;
}
}
ToOut:
free(pSsidSearch);
pSsidSearch = NULL;
pthread_mutex_unlock(&scan_mutex);
return 0;
}
double iw_freq2float(const struct iw_freq * in)
{
int i;
double res = (double)in->m;
for(i = 0; i < in->e; i++)
res *= 10;
return (res);
}
static inline int iw_get_ext(int skfd, const char *ifname, int request, struct iwreq * pwrq)
{
/* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */
return(ioctl(skfd, request, pwrq));
}
int api_wifi_get_wireless_info(const char *ifname)
{
int sock;
struct iwreq wrq;
char *mac = NULL;
memset((char *)&wrq, 0, sizeof(struct iwreq));
/* Create a channel to the NET kernel. */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
LOG_EX(LOG_Debug, "Open sock error!\n");
return -1;
}
/* Get wireless name */
if(iw_get_ext(sock, ifname, SIOCGIWNAME, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless name error!\n");
return -1;
}
LOG_EX(LOG_Debug, "Wireless name %s\n", wrq.u.name);
/* Get frequency / channel */
if(iw_get_ext(sock, ifname, SIOCGIWFREQ, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless frequency error!\n");
return -1;
}
LOG_EX(LOG_Debug, "Wireless frequency %lf\n", iw_freq2float(&(wrq.u.freq)));
/* Get AP address */
if(iw_get_ext(sock, ifname, SIOCGIWAP, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless ap mac error!\n");
return -1;
}
mac = (char *)(&(wrq.u.ap_addr));
LOG_EX(LOG_Debug, "Wireless ap mac %x:%x:%x:%x:%x:%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
void *wifi_scan_thread(void *args)
{
int ret = -1, i = 0;
int scan_fail_cnt = 0;
char cmd[16] = {0}, reply[16] = {0};
struct timeval now;
struct timespec outtime;
while(scan_running){
pthread_mutex_lock(&scan_mutex);
if(scan_pause == 1){
pthread_cond_wait(&scan_cond, &scan_mutex);
}
/* set scan start flag */
set_scan_start_flag();
/* scan cmd */
strncpy(cmd, "SCAN", 15);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
pthread_mutex_unlock(&scan_mutex);
scan_fail_cnt++;
usleep(500*1000);
/* fix PV1-3216, do DISCONNECT to restore driver from continuiously restart */
if (scan_fail_cnt > MAX_SCAN_FAIL_TIME)
{
stop_connecting();
scan_fail_cnt = 0;
}
continue;
}
scan_fail_cnt = 0;
for(i=0;i<WAITING_CLK_COUNTS;i++){
if(get_scan_status() == 1){
break;
}
usleep(100*1000);
}
LOG_EX(LOG_Debug, "scan status %d\n", get_scan_status());
if(get_scan_status() == 1){
strncpy(cmd, "SCAN_RESULTS", 15);
cmd[15] = '\0';
ret = wifi_command(cmd, scan_results, sizeof(scan_results));
if(ret){
LOG_EX(LOG_Debug, "do scan results error!\n");
pthread_mutex_unlock(&scan_mutex);
continue;
}
scan_results_len = strlen(scan_results);
//LOG_EX(LOG_Debug, "scan wifi result:%s\r\n",scan_results);
}
pthread_mutex_unlock(&scan_mutex);
//wait run singal or timeout 15s
pthread_mutex_lock(&thread_run_mutex);
if(scan_completed == 0){
scan_completed = 1;
}
gettimeofday(&now, NULL);
outtime.tv_sec = now.tv_sec + 15;
outtime.tv_nsec = now.tv_usec *1000;
pthread_cond_timedwait(&thread_run_cond, &thread_run_mutex, &outtime);
pthread_mutex_unlock(&thread_run_mutex);
}
}
void start_wifi_scan_thread(void *args)
{
pthread_mutex_init(&scan_mutex, NULL);
pthread_cond_init(&scan_cond, NULL);
pthread_mutex_init(&thread_run_mutex, NULL);
pthread_cond_init(&thread_run_cond,NULL);
scan_running = 1;
pthread_create(&scan_thread_id, NULL, &wifi_scan_thread, args);
}
void pause_wifi_scan_thread()
{
pthread_mutex_lock(&scan_mutex);
scan_pause=1;
pthread_mutex_unlock(&scan_mutex);
}
void resume_wifi_scan_thread()
{
pthread_mutex_lock(&scan_mutex);
scan_pause=0;
pthread_mutex_unlock(&scan_mutex);
pthread_cond_signal(&scan_cond);
}
void stop_wifi_scan_thread()
{
scan_running = 0;
usleep(200*1000);
pthread_join(scan_thread_id, NULL);
pthread_cond_destroy(&thread_run_cond);
pthread_mutex_destroy(&thread_run_mutex);
pthread_cond_destroy(&scan_cond);
pthread_mutex_destroy(&scan_mutex);
}
void start_broadlink_thread(void *args)
{
pthread_attr_t attr;
if (broadlink_thread_running)
return;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&broadlink_thread_id, &attr, &bl_recv_msg_thread, args);
broadlink_thread_running = 1;
}

View File

@ -1,460 +0,0 @@
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<unistd.h>
#include<uvdbus/log.h>
#include "wifi.h"
#include "wifi_event.h"
#include "wifi_state_machine.h"
#include "wifi_intf.h"
#include "wpa_supplicant_conf.h"
tWIFI_STATE gwifi_state;
extern char netid_connecting[];
extern int connecting_ap_event_label;
extern int disconnect_ap_event_label;
extern void start_udhcpc_thread(void *args);
tWifi_event_callback wifi_event_callback[MAX_CALLBCAKS_COUNT] = {NULL};
int wifi_event_callback_index = 0;
static pthread_t event_thread_id;
static int event_thread_running;
static int wifi_event_inner = AP_DISCONNECTED;
static int scan_complete = 0;
static int wifi_off_flag = 0;
static int assoc_reject_count = 0;
static int authentication_fail_count = 0;
static void handle_event(int event, char * remainder) {
char netid_connected[NET_ID_LEN+1] = {0};
char cmd[255] = {0}, reply[16]={0};
int len = NET_ID_LEN+1;
tWIFI_MACHINE_STATE state;
switch (event){
case DISCONNECTED:
state = get_wifi_machine_state();
if((state == DISCONNECTING_STATE) //call disconnect
|| (state == L2CONNECTED_STATE) || (state == CONNECTED_STATE)) //auto disconnect(ap shutdown)
{
LOG_EX(LOG_Debug, "Network disconnected!\n");
set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(AP_DISCONNECTED);
call_event_callback_function(WIFIMG_NETWORK_DISCONNECTED, NULL, disconnect_ap_event_label);
}
break;
case CONNECTED:
if(netid_connecting[0] != '\0'){
/* get already connected netid */
wpa_conf_get_ap_connected(netid_connected, &len);
LOG_EX(LOG_Debug, "connecting id %s, connected id %s\n", netid_connecting, netid_connected);
if(strcmp(netid_connected,netid_connecting) != 0){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
break;
}
}
//assoc_reject_count = 0;
set_wifi_machine_state(L2CONNECTED_STATE);
/* start udhcpcd */
start_udhcpc_thread((void *)remainder);
break;
case SCAN_RESULTS:
scan_complete = 1;
break;
case UNKNOWN:
//LOG_EX(LOG_Debug, "unknown event!\n");
break;
}
}
static int dispatch_event(const char *event_str, int nread)
{
int i = 0, event = 0;
char event_name[32];
char cmd[255] = {0}, reply[16]={0};
char network_id[NET_ID_LEN]={0};
static char recent_network_id[NET_ID_LEN]={0};
int network_id_tmp;
char buf_tmp[255];
char *name_start = NULL, *name_end = NULL;
char *event_data = NULL;
if(!event_str || !event_str[0]){
LOG_EX(LOG_Debug, "event is NULL!\n");
return 0;
}
LOG_EX(LOG_Debug, "event_str %s!!!!\n", event_str);
if(strncmp(event_str, "CTRL-EVENT-", 11)){
if (!strncmp(event_str, "WPA:", 4)){
if (strstr(event_str, "pre-shared key may be incorrect")){
authentication_fail_count++;
if(authentication_fail_count >= MAX_RETRIES_ON_AUTHENTICATION_FAILURE){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(PASSWORD_INCORRECT);
}
return 0;
}
}
if (!strncmp(event_str, "Selecting BSS network id ", 25)){
sscanf(event_str, "Selecting BSS network id %d!!!!", &network_id_tmp);
sprintf(recent_network_id, "%d", network_id_tmp);
}
//LOG_EX(LOG_Debug, "EVENT, not care!\n");
return 0;
}
name_start = (char *)((unsigned long)event_str+11);
name_end = strchr(name_start, ' ');
if(name_end){
while((name_start < name_end) && (i < 31)){
event_name[i] = *name_start++;
i++;
}
event_name[i] = '\0';
} else {
LOG_EX(LOG_Debug, "Received wpa_supplicant event with empty event name!\n");
return 0;
}
/*
* Map event name into event enum
*/
if(!strcmp(event_name, "CONNECTED")){
event = CONNECTED;
}else if(!strcmp(event_name, "DISCONNECTED")){
event = DISCONNECTED;
}else if(!strcmp(event_name, "STATE-CHANGE")){
event = STATE_CHANGE;
}else if(!strcmp(event_name, "SCAN-RESULTS")){
event = SCAN_RESULTS;
}else if(!strcmp(event_name, "LINK-SPEED")){
event = LINK_SPEED;
}else if(!strcmp(event_name, "TERMINATING")){
event = TERMINATING;
}else if(!strcmp(event_name, "DRIVER-STATE")){
event = DRIVER_STATE;
}else if(!strcmp(event_name, "EAP-FAILURE")){
event = EAP_FAILURE;
}else if(!strcmp(event_name, "ASSOC-REJECT")){
event = ASSOC_REJECT;
}else if(!strcmp(event_name, "SSID-TEMP-DISABLED")){
event = SSID_TEMP_DISABLED;
}else{
event = UNKNOWN;
}
event_data = (char *)((unsigned long)event_str);
if(event == DRIVER_STATE || event == LINK_SPEED){
LOG_EX(LOG_Debug, "DRIVER_STATE or LINK_SPEED, not handle\n");
return 0;
}else if(event == STATE_CHANGE || event == EAP_FAILURE){
event_data = strchr(event_str, ' ');
if(event_data){
event_data++;
}
}else{
event_data = strstr(event_str, " - ");
if (event_data) {
event_data += 3;
}
}
if(event == STATE_CHANGE){
LOG_EX(LOG_Debug, "STATE_CHANGE, no care!\n");
return 0;
} else if(event == DRIVER_STATE){
LOG_EX(LOG_Debug, "DRIVER_STATE, no care!\n");
return 0;
}else if(event == TERMINATING){
if (get_wifi_off_flag())
{
/* If we turn off wifi, we should update wifimanager status. */
LOG_EX(LOG_Debug, "Wpa supplicant terminated!\n");
gwifi_state = WIFIMG_WIFI_DISABLED;
call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0);
set_wifi_off_flag(0);
return 1;
}
else
{
/* If we just restart wpa_supplicant, do nothing. */
return 0;
}
}else if(event == EAP_FAILURE){
LOG_EX(LOG_Debug, "EAP FAILURE!\n");
return 0;
}else if(event == ASSOC_REJECT){
assoc_reject_count++;
if(assoc_reject_count >= MAX_ASSOC_REJECT_COUNT){
wpa_conf_add_on_priority_list_hdr(recent_network_id);
LOG_EX(LOG_Debug, "Current ap's priority lowered!\n");
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
}
LOG_EX(LOG_Debug, "ASSOC REJECT!\n");
return 0;
}else if(event == SSID_TEMP_DISABLED){
sscanf(event_str, "CTRL-EVENT-SSID-TEMP-DISABLED id=%d %s", &network_id_tmp, buf_tmp);
sprintf(network_id, "%d", network_id_tmp);
wpa_conf_add_on_priority_list_hdr(network_id);
LOG_EX(LOG_Debug, "Current ap's priority lowered!\n");
return 0;
}else{
handle_event(event, event_data);
}
return 0;
}
void *event_handle_thread(void* args)
{
char buf[EVENT_BUF_SIZE] = {0};
int nread = 0, ret = 0;
while(event_thread_running){
nread = wifi_wait_for_event(buf, sizeof(buf));
if (nread > 0) {
ret = dispatch_event(buf, nread);
if(ret == 1){
break; // wpa_supplicant terminated
}
} else {
continue;
}
}
LOG_EX(LOG_Debug, "Wifi event_handle_thread stopped!\n");
pthread_exit(NULL);
}
void wifi_event_loop(tWifi_event_callback pcb)
{
pthread_attr_t attr;
/* initial */
wifi_event_inner = AP_DISCONNECTED;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
event_thread_running = 1;
pthread_create(&event_thread_id, &attr, event_handle_thread, NULL);
}
void wifi_event_loop_stop()
{
event_thread_running = 0;
usleep(200*1000);
}
void wifi_event_loop_restart()
{
pthread_attr_t attr;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
event_thread_running = 1;
pthread_create(&event_thread_id, &attr, event_handle_thread, NULL);
}
tWIFI_EVENT_INNER get_cur_wifi_event()
{
return wifi_event_inner;
}
int set_cur_wifi_event(tWIFI_EVENT_INNER event)
{
wifi_event_inner = event;
return 0;
}
void *check_connect_timeout(void *args)
{
int i = 0;
tWIFI_MACHINE_STATE state;
tWIFI_EVENT_INNER event;
char cmd[256] = {0}, reply[8] = {0};
i = 0;
do {
usleep(100000);
state = get_wifi_machine_state();
event = get_cur_wifi_event();
/* password incorrect */
if ((state == DISCONNECTED_STATE) && (event == PASSWORD_INCORRECT)){
LOG_EX(LOG_Debug, "check_connect_timeout exit: password failed!\n");
call_event_callback_function(WIFIMG_PASSWORD_FAILED, NULL, connecting_ap_event_label);
break;
}
if(assoc_reject_count >= MAX_ASSOC_REJECT_COUNT){
LOG_EX(LOG_Debug, "associat reject over 3 times!\n");
assoc_reject_count = 0;
break;
}
i++;
} while((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE) && (i < 450));
/* wifi not exist or can't connect */
if (get_wifi_machine_state() == CONNECTING_STATE){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(CONNECT_AP_TIMEOUT);
call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label);
}
/* resume scan thread */
resume_wifi_scan_thread();
pthread_exit(NULL);
}
void start_check_connect_timeout(int first)
{
pthread_t check_timeout_id;
pthread_attr_t attr;
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&check_timeout_id, &attr, check_connect_timeout, NULL);
}
void stop_connecting()
{
char cmd[255] = {0}, reply[16]={0};
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
}
void *wifi_on_check_connect_timeout(void *args)
{
int i = 0;
char cmd[255] = {0}, reply[16]={0};
tWIFI_MACHINE_STATE state;
tWIFI_EVENT_INNER event;
/* sync wpa_supplicant state */
i = 0;
do {
usleep(100000);
state = get_wifi_machine_state();
event = get_cur_wifi_event();
i++;
} while((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE) && (i < 100));
if((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE)){
/* send disconnect */
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE);
LOG_EX(LOG_Debug, "call event NO_NETWORK_CONNECTING\n");
call_event_callback_function(WIFIMG_NO_NETWORK_CONNECTING, NULL, connecting_ap_event_label);
}
pthread_exit(NULL);
}
void start_wifi_on_check_connect_timeout()
{
pthread_t wifi_on_check_timeout_id;
pthread_create(&wifi_on_check_timeout_id, NULL, wifi_on_check_connect_timeout, NULL);
}
void set_scan_start_flag()
{
scan_complete = 0;
}
int get_scan_status()
{
return scan_complete;
}
void set_wifi_off_flag(int value)
{
wifi_off_flag = value;
}
int get_wifi_off_flag()
{
return wifi_off_flag;
}
void reset_assoc_reject_count()
{
assoc_reject_count = 0;
}
int get_assoc_reject_count()
{
return assoc_reject_count;
}
int add_wifi_event_callback_inner(tWifi_event_callback pcb)
{
if(wifi_event_callback_index >= MAX_CALLBCAKS_COUNT){
return -1;
}
wifi_event_callback[wifi_event_callback_index]=pcb;
wifi_event_callback_index++;
return 0;
}
int reset_wifi_event_callback()
{
int i=0;
for(i=0; i<wifi_event_callback_index; i++){
wifi_event_callback[i]=NULL;
}
return 0;
}
int call_event_callback_function(tWIFI_EVENT wifi_event, char *buf, int event_label)
{
int i=0;
LOG_EX(LOG_Debug, "call event 0x%x\n", wifi_event);
for(i=0; i<wifi_event_callback_index; i++){
if(wifi_event_callback[i] != NULL){
wifi_event_callback[i](wifi_event, buf, event_label);
}
}
return 0;
}

View File

@ -1,20 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include "wifi_state_machine.h"
#include <uvdbus/log.h>
static int gwifi_machine_state = DISCONNECTED_STATE;
/* set wifi state */
int set_wifi_machine_state(tWIFI_MACHINE_STATE state)
{
LOG_EX(LOG_Debug, "set wifi machine state 0x%x\n", state);
gwifi_machine_state = state;
}
/* get wifi state */
tWIFI_MACHINE_STATE get_wifi_machine_state()
{
//LOG_EX(LOG_Debug, "wifi machine state 0x%x\n", gwifi_machine_state);
return gwifi_machine_state;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +0,0 @@
#!/bin/ash
wifi_connect_ap_test $1 $2
sleep 1
wifi_on_off_test
sleep 2