From a67de73672ae77d684a772d7db6dc4853f22cbd0 Mon Sep 17 00:00:00 2001 From: lijie02 Date: Tue, 17 Jul 2018 15:44:16 +0800 Subject: [PATCH] Add wifimanager modification --- package/allwinner/wifimanager/Makefile | 31 +- package/allwinner/wifimanager/demo/Makefile | 29 +- .../allwinner/wifimanager/smartaudio/Makefile | 27 + .../smartaudio/app_wifi_manager.cpp | 1173 +++++++++++++++++ package/allwinner/wifimanager/src/Makefile | 7 +- .../allwinner/wifimanager/src/include/wifi.h | 5 + .../wifimanager/src/include/wifi_event.h | 1 + .../wifimanager/src/include/wifi_intf.h | 3 + .../src/include/wpa_supplicant_conf.h | 3 + .../wifimanager/src/network_manager.c | 119 +- .../allwinner/wifimanager/src/udhcpc_thread.c | 17 +- package/allwinner/wifimanager/src/wifi.c | 200 ++- .../allwinner/wifimanager/src/wifi_event.c | 47 +- .../wifimanager/src/wifi_state_machine.c | 5 +- .../allwinner/wifimanager/src/wifimanager.c | 221 +++- .../wifimanager/src/wpa_supplicant_conf.c | 341 ++++- .../allwinner/wifimanager/udhcpc_wlan0.init | 8 +- package/allwinner/wifimanager/wifi.init | 8 +- target/allwinner/mandolin-perf1/defconfig | 5 +- 19 files changed, 2081 insertions(+), 169 deletions(-) create mode 100755 package/allwinner/wifimanager/smartaudio/Makefile create mode 100755 package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp diff --git a/package/allwinner/wifimanager/Makefile b/package/allwinner/wifimanager/Makefile index f21f92692..4161f4c12 100755 --- a/package/allwinner/wifimanager/Makefile +++ b/package/allwinner/wifimanager/Makefile @@ -1,4 +1,6 @@ include $(TOPDIR)/rules.mk +include $(TINA_BUILD_TOP)/package/netease/Makefile.common + PKG_NAME:=wifimanager PKG_VERSION:=0.0.1 @@ -10,7 +12,7 @@ define Package/wifimanager/Default SECTION:=utils CATEGORY:=Allwinner TITLE:=Tina wifi manager - DEPENDS:=+libpthread +libstdcpp +liballwinner-base + DEPENDS:=+libpthread +libstdcpp +liballwinner-base +libiconv-full $(MAKE_COMMON_DEPEND) endef define Package/wifimanager @@ -22,7 +24,13 @@ endef define Package/wifimanager-demo $(call Package/wifimanager/Default) TITLE:=Tina wifi app demo - DEPENDS := wifimanager +wifimanager + DEPENDS := +wifimanager +libiconv-full +endef + +define Package/wifimanager-smartaudio + $(call Package/wifimanager/Default) + TITLE:=netease smart audio + DEPENDS := +wifimanager +libiconv-full +rftest $(MAKE_COMMON_DEPEND) endef define Package/wifimanager/description @@ -37,6 +45,7 @@ define Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) -r ./src $(PKG_BUILD_DIR)/ $(CP) -r ./demo $(PKG_BUILD_DIR)/ + $(CP) -r ./smartaudio $(PKG_BUILD_DIR)/ endef define Build/Configure @@ -86,6 +95,23 @@ define Package/wifimanager/install $(INSTALL_BIN) ./udhcpc_wlan0.init $(1)/etc/wifi/udhcpc_wlan0 endef +define Package/wifimanager-smartaudio/install + + $(MAKE) -C $(PKG_BUILD_DIR)/smartaudio/ \ + ARCH="$(TARGET_ARCH)" \ + AR="$(TARGET_AR)" \ + CC="$(TARGET_CC)" \ + CXX="$(TARGET_CXX)" \ + CFLAGS="$(TARGET_CFLAGS)" \ + LDFLAGS="$(TARGET_LDFLAGS)" \ + CONFIG_PREFIX="$(PKG_INSTALL_DIR)" \ + all + + $(INSTALL_DIR) $(1)/bin + $(INSTALL_DIR) $(1)/etc/wifi + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/app_wifi_manager $(1)/bin +endef + define Package/wifimanager-demo/install $(INSTALL_DIR) $(1)/bin $(INSTALL_DIR) $(1)/etc/wifi @@ -106,3 +132,4 @@ endef $(eval $(call BuildPackage,wifimanager)) $(eval $(call BuildPackage,wifimanager-demo)) +$(eval $(call BuildPackage,wifimanager-smartaudio)) diff --git a/package/allwinner/wifimanager/demo/Makefile b/package/allwinner/wifimanager/demo/Makefile index 28361cc35..e984f97c8 100755 --- a/package/allwinner/wifimanager/demo/Makefile +++ b/package/allwinner/wifimanager/demo/Makefile @@ -1,3 +1,6 @@ +include $(TOPDIR)/rules.mk +include $(TINA_BUILD_TOP)/package/netease/Makefile.common +include $(TINA_BUILD_TOP)/build/nls.mk target = wifi_connect_ap_test INCLUDES += -I$(CONFIG_PREFIX)/usr/include \ @@ -7,69 +10,71 @@ CPP_SRCS = wifi_connect_ap.cpp CPP_OBJS := $(CPP_SRCS:.cpp=.o) LIB_OBJS = $(CPP_OBJS) +local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv + install: -@mkdir -p $(CONFIG_PREFIX)/usr/bin #wifi_on_off_test wifi_on_off_test: wifi_on_off_test.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_on_off_test $(CONFIG_PREFIX)/usr/bin #wifi_connect_chinese_ap_test wifi_connect_chinese_ap_test: wifi_connect_chinese_ap.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_connect_chinese_ap_test $(CONFIG_PREFIX)/usr/bin #wifi_scan_results_test wifi_scan_results_test: wifi_scan_results.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_scan_results_test $(CONFIG_PREFIX)/usr/bin #wifi_list_networks_test wifi_list_networks_test: wifi_list_networks.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_list_networks_test $(CONFIG_PREFIX)/usr/bin #wifi_remove_network_test wifi_remove_network_test: wifi_remove_network.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_remove_network_test $(CONFIG_PREFIX)/usr/bin #wifi_connect_ap_with_netid_test wifi_connect_ap_with_netid_test: wifi_connect_ap_with_netid.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_connect_ap_with_netid_test $(CONFIG_PREFIX)/usr/bin #wifi_get_netid_test wifi_get_netid_test: wifi_get_netid.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_get_netid_test $(CONFIG_PREFIX)/usr/bin #wifi_add_network_test wifi_add_network_test: wifi_add_network.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_add_network_test $(CONFIG_PREFIX)/usr/bin #wifi_longtime_test wifi_longtime_test: wifi_longtime_test.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(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) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(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 $@ $< $(target): $(LIB_OBJS) - $(CXX) -o $@ $^ $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg -lpthread + $(CXX) -o $@ $^ $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg -lpthread @cp -f $(target) $(CONFIG_PREFIX)/usr/bin #wifi_remove_all_networks_test wifi_remove_all_networks_test: wifi_remove_all_networks.c - $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + $(CC) -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg @cp -f wifi_remove_all_networks_test $(CONFIG_PREFIX)/usr/bin #################################################################### diff --git a/package/allwinner/wifimanager/smartaudio/Makefile b/package/allwinner/wifimanager/smartaudio/Makefile new file mode 100755 index 000000000..a795c14ca --- /dev/null +++ b/package/allwinner/wifimanager/smartaudio/Makefile @@ -0,0 +1,27 @@ +include $(TOPDIR)/rules.mk +include $(TINA_BUILD_TOP)/package/netease/Makefile.common +include $(TINA_BUILD_TOP)/build/nls.mk +target = app_wifi_manager + +MK_PWD = ./ +INCLUDES += -I$(CONFIG_PREFIX)/usr/include -I$(MK_PWD)/softap + +CPP_SRCS = app_wifi_manager.cpp +CPP_OBJS := $(CPP_SRCS:.cpp=.o) +LIB_OBJS = $(CPP_OBJS) + +local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv + +install: + -@mkdir -p $(CONFIG_PREFIX)/usr/bin + +#app_wifi_manager +app_wifi_manager: app_wifi_manager.cpp + $(CXX) -std=c++11 -o $@ $^ $(CFLAGS) $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) -L$(CONFIG_PREFIX)/usr/lib -lwifimg + @cp -f app_wifi_manager $(CONFIG_PREFIX)/usr/bin + + +#################################################################### +all: install $(target) app_wifi_manager +clean: + rm -rf $(target) app_wifi_manager$ (LIB_OBJS) diff --git a/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp b/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp new file mode 100755 index 000000000..99c7fcce3 --- /dev/null +++ b/package/allwinner/wifimanager/smartaudio/app_wifi_manager.cpp @@ -0,0 +1,1173 @@ +#define TAG "wifi" +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + + + +#define PIPE_RET_SIZE 1024 + +#define WIFI_STATE_JS_KEY "wifi_state" +#define WIFI_STATE_RSSI_JS_KEY "wifi_rssi" + +#define WIFI_STATE_EVT_JS_KEY "wifi_evt" + +#define RES_CODDE_STR "resCode" +#define SSID_JS_KEY "ssid" +#define PASSWD_JS_KEY "pwd" +#define PASSWD_ACCOUNT "account" + +#define WLAN_CONFIG_CMD_STR "iwconfig" +#define WLAN_RSSI_STR_RRE "Signal level=" + + +#define WIFI_CONF_EVT_TAG 0xf000 +#define WIFI_AUTO_EVT_TAG 0xf100 +#define WIFI_CHANGE_AP_EVT_TAG 0xf200 + + +static pthread_t app_scan_tid; +static int event = WIFIMG_NETWORK_DISCONNECTED; +extern pthread_mutex_t ctrl_mutex; + + +#define APP_WIFI_SUCCES 0 +#define APP_WIFI_NULL -1 +#define APP_WIFI_OVER -2 +#define APP_WIFI_JSON_INVALID -3 +#define RSSI_INVALID_NUM (-9999) + + + +typedef enum +{ + WIFI_STATE_KEY_STATE =0, + WIFI_STATE_KEY_RSSI, + WIFI_STATE_KEY_CNT, +}sWifiStateKeysEnum; + + +typedef enum +{ + WIFI_EVT_KEY_EVT =0, + WIFI_EVT_KEY_RSSI, + WIFI_EVT_KEY_CNT, +}sWifiEvtKeysEnum; + + +typedef enum +{ + APP_WIFI_CFG_SUCCESS =0, + APP_WIFI_CFG_SYS_ERR = 0xf001, + APP_WIFI_CFG_FMT_INVALID, + APP_WIFI_CFG_JSON_INVALID, + APP_WIFI_CFG_PARAMS_ERR, + APP_WIFI_CFG_SSID_NO_EXIT, + APP_WIFI_CFG_PWD_INVALID, + APP_WIFI_CFG_BUSY, + APP_WIFI_CFG_TIMEOUT, + APP_WIFI_CFG_WIFI_MD_ERR, + APP_WIFI_CFG_CODEC_ERR, + APP_WIFI_CFG_OTHER, + APP_WIFI_CFG_SYS_CFG_BUSY, + APP_WIFI_CFG_SERVER_ERR, + APP_WIFI_CFG_STATE_INVALID, +}app_wifi_cfg_code_edef; + + +typedef enum +{ + APP_WIFI_AUTO_SET_SUCCESS, + APP_WIFI_AUTO_SET_BUSY, + APP_WIFI_AUTO_BT_CONF_COLLISION, + APP_WIFI_AUTO_OTHER_INVALID, +}app_wifi_auto_resp_code_edef; + + +typedef enum +{ + APP_WIFI_EVT_NTF_CONNECTED =0, + APP_WIFI_EVT_NTF_DISCONNECT, + APP_WIFI_EVT_NTF_CONNECTING, + APP_WIFI_EVT_NTF_MAX, +}app_wifi_state_notify_edef; + +int api_wifi_state_notify(int state); + +static char * wifiStateKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_JS_KEY,WIFI_STATE_RSSI_JS_KEY}; +static char * wifiEvtKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_EVT_JS_KEY,WIFI_STATE_RSSI_JS_KEY}; + + + + +std::string VectorStrCompose(std::vector recVec) +{ + std::string ret; + + if(0 == recVec.size()) return ""; + + for(auto str = recVec.begin(); str !=recVec.end();str++) + { + ret+= *str; + } + + return ret; +} + + +int pipeExcute(const char * cmd,std::vector & recVec ) +{ + if(NULL == cmd) return -1; + recVec.clear(); + + FILE * pPipe = popen(cmd, "r"); + + LOG_EX(LOG_Debug, "INFO: cmd is %s\r\n",cmd); + + if (NULL==pPipe) { + return -1; + } + + char ret[PIPE_RET_SIZE]; + + memset(ret,0x00,PIPE_RET_SIZE); + + + while (fgets(ret, sizeof(ret), pPipe) != NULL) + { + + recVec.push_back(ret); + } + + if(0 != pclose(pPipe)) + { + recVec.push_back(strerror(errno)); + if(0 != errno) + { + LOG_EX(LOG_Debug, "ERROR: pipe close error = %d\r\n",errno); + } + + } + + LOG_EX(LOG_Debug, "info: cmd excute complete\r\n"); + + + return 0; +} + +int get_connected_ap_rssi() +{ + std::string shellCmd = WLAN_CONFIG_CMD_STR; + std::vector vectorRes; + int status =0; + int rssi = RSSI_INVALID_NUM; + std::string out; + + status =pipeExcute(shellCmd.c_str(),vectorRes); + if(0 == status) + { + out = VectorStrCompose(vectorRes); + LOG_EX(LOG_Debug, "info:cmd is %s, res is \r\n %s \r\n",shellCmd.c_str(),out.c_str()); + + std::size_t pos = out.find(WLAN_RSSI_STR_RRE); + + if(pos == std::string::npos) + { + LOG_EX(LOG_Debug, "warm: no rssi\r\n"); + status = -1; + }else + { + std::string rssiStr = out.substr(pos+strlen(WLAN_RSSI_STR_RRE),4); + LOG_EX(LOG_Debug, "---info: rssiStr is %s \r\n",rssiStr.c_str()); + + rssi = std::stoi(rssiStr); + } + + }else + { + LOG_EX(LOG_Debug, "error: pipe excute error\r\n"); + status = -1; + } + + + return (0 == status)?rssi:RSSI_INVALID_NUM; + +} + + + + +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); + } +} + +/* + *argc[1] ap ssid + *argc[2] ap passwd +*/ + +DBusConnection *pBus; +static const char* g_pDBusInterfaceName = NULL; +static uv_timer_t timerCurPosMsg; + + + +int api_wifi_module_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 send module cmd err is %d\r\n",status); + } + + + return status; +} + +char * api_wifi_res_json_get(int res) +{ + cJSON* pRoot = NULL; + char * p=NULL; + + pRoot=cJSON_CreateObject(); + if(NULL == pRoot) return NULL; + + cJSON_AddNumberToObject(pRoot,RES_CODDE_STR,res); + + p = cJSON_Print(pRoot); + + if(NULL == p) + { + cJSON_Delete(pRoot); + return NULL; + } + + cJSON_Delete(pRoot); + + return p; +} + +char * api_wifi_state_json_get(char * p_key,int res) +{ + cJSON* pRoot = NULL; + char * p=NULL; + + pRoot=cJSON_CreateObject(); + if(NULL == pRoot) return NULL; + + cJSON_AddNumberToObject(pRoot,p_key,res); + + p = cJSON_Print(pRoot); + + if(NULL == p) + { + cJSON_Delete(pRoot); + return NULL; + } + + cJSON_Delete(pRoot); + + return p; +} + +char * api_wifi_state_json_get(char * p_key[],int res[],int size) +{ + cJSON* pRoot = NULL; + char * p=NULL; + + pRoot=cJSON_CreateObject(); + if(NULL == pRoot) return NULL; + + + + for(int i=0;ibusCmd); + if (!pMsg || !pLoop || !pConn) { + return NULL; + } + + switch (pMsg->busCmd) { + case CMD_WIFI_CONF: + LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_CONF==========================\r\n"); + LOG_EX(LOG_Debug, "wifi module get cfg msg is %s\r\n",pMsg->pMsg); + if(0 == busy_conf) + { + busy_conf =1; + status = api_wifi_get_cfg_value(pMsg->pMsg,&p_ssid,&p_passwd); + if(APP_WIFI_JSON_INVALID == status) + { + rsp_code = APP_WIFI_CFG_JSON_INVALID; + }else if(APP_WIFI_NULL == status) + { + rsp_code = APP_WIFI_CFG_FMT_INVALID; + } + + if(APP_WIFI_CFG_SUCCESS== rsp_code) + { + LOG_EX(LOG_Debug, "+++++++Now wifi config cnt is %d\r\n",++wifi_connet_cnt); + LOG_EX(LOG_Debug, "ssid is %s,pd is %s\r\n",p_ssid,p_passwd); + + + status = api_wifi_get_str_raw(&p_ssid); + if(0 != status) + { + LOG_EX(LOG_Debug, "ERROR:get ssid str raw err"); + goto END_DO; + + } + + status = api_wifi_get_str_raw(&p_passwd); + if(0 != status) + { + LOG_EX(LOG_Debug, "get passwd str raw err"); + goto END_DO; + + } + +#if WIFI_INFO_BASE64 + pBaseSsid = (char *)EvpBase64DecodeNoAlignV2((const char *)p_ssid, &ssidSize); + if(0 == ssidSize || NULL == pBaseSsid) + { + LOG_EX(LOG_Debug, "ERROR: ssid base64 error\r\n"); + goto END_DO; + } + + pBasePwd = (char *)EvpBase64DecodeNoAlignV2((const char *)p_passwd, &pwdSize); + + LOG_EX(LOG_Debug, "INFO:pBasePwd is %d, pwdSize is %d\r\n",pBasePwd,pwdSize); + + if(0 == pwdSize && NULL == pBasePwd) + { + LOG_EX(LOG_Debug, "warm: pswd null!!!\r\n"); + } + + + free(p_ssid); + p_ssid = NULL; + free(p_passwd); + p_passwd = NULL; + + p_ssid = pBaseSsid; + p_passwd = pBasePwd; + + pBasePwd = NULL; + pBaseSsid = NULL; +#endif + + LOG_EX(LOG_Debug, "New ssid is %s,new pd is %s\r\n",p_ssid,p_passwd); + + event_label = WIFI_CONF_EVT_TAG; + + if(NULL == p_wifi_interface) + { + p_wifi_interface = aw_wifi_on(wifi_event_handle, event_label); + if(p_wifi_interface == NULL){ + LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", event); + goto END_DO; + + } + + } + + if(WIFIMG_WIFI_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); + goto END_DO; + + }else + { + 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){ + 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; + } + + busy_conf =0; + }else + { + rsp_code = APP_WIFI_CFG_SYS_CFG_BUSY; + LOG_EX(LOG_Debug, "wifi module cfg busy!!!!\r\n"); + } + + LOG_EX(LOG_Debug, "wifi module CMD_WIFI_CONF rsp_code 0x%x.\r\n", rsp_code); + pResJson = (uint8_t *)api_wifi_res_json_get(rsp_code); + if(NULL != pResJson) + { + if(0 == rsp_code)mask = 1<enable_all_network(); + if(0 != status) + { + LOG_EX(LOG_Debug, "wifi on failed event 0x%x\n", event); + busy_auto =0; + break; + } +#endif + if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state()) + status = p_wifi_interface->disconnect_ap(event_label); + } + + if(WIFIMG_WIFI_CONNECTED != aw_wifi_get_wifi_state()) + { + + while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING){ + 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) + { + LOG_EX(LOG_Debug, "wifi state busing,waiting\n"); + usleep(2000000); + } + + if(WIFIMG_WIFI_CONNECTED !=aw_wifi_get_wifi_state() ) + { + if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTING,RSSI_INVALID_NUM)) + { + LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); + } + } + + }else + { + int rssi = get_connected_ap_rssi(); + if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED,rssi)) + { + LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); + } + } + + busy_auto =0; + + + status = api_wifi_module_cmd_send((1<change_ap(event_label); + + while(aw_wifi_get_wifi_state() == WIFIMG_WIFI_BUSING) + { + LOG_EX(LOG_Debug, "wifi state busing,waiting\n"); + usleep(2000000); + } + + status = api_wifi_module_cmd_send((1<disconnect_ap(event_label); + if(0 != status) + { + LOG_EX(LOG_Debug, "ERROR:wifi disconnect event 0x%x L%d\n", event, __LINE__); + } + else + { + LOG_EX(LOG_Debug, "Disconnect the wifi connected ap L%d \r\n", __LINE__); + } + } + + 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__); + } + else + { + LOG_EX(LOG_Debug, "remove_all_networks L%d \r\n", __LINE__); + } + break; + default: + break; + } + + return NULL; +} + +static void DBusMsgHandleLoop(void* param){ + while(1) + { + PDBUS_MSG_PACK pMsg = DBusGetMessage(); + PLIBUV_DBUS_PARAMS pInfo = DBusLibuvGetRuntime(); + + if(pMsg && pInfo) + DBusOnMessage(pInfo->pLoop, pInfo->pBus, pMsg); + if(pMsg) + DBusMsgCleanup(pMsg); + + usleep(100); + } + + return; +} + +int main(int argv, char *argc[]){ + + int ret = 0; + DBusConnection* pBus = NULL; + uv_loop_t* pLoop = uv_default_loop(); + int fd; + + g_pDBusInterfaceName = g_pModInfoTable[MODULE_WIFI].modAliase; + + LOG_EX(LOG_Debug, "Start the wifi communication\n"); + + + //pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, DBusOnMessage, NULL, NULL, &ret); + pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, NULL, NULL, NULL, &ret); + + if(pBus == NULL) + { + fprintf(stderr, "%s(%d): DBusWithLibuvInit Error: %d\n", g_pDBusInterfaceName, MODULE_PLAYER, ret); + return 0; + } + + /* init a uv timer to report cur position */ + uv_timer_init(pLoop, &timerCurPosMsg); + + pthread_mutex_init(&ctrl_mutex, NULL); + + uv_thread_t uvSyncThread; + uv_thread_create(&uvSyncThread, DBusMsgHandleLoop, NULL); + + //uv_run(pLoop, UV_RUN_DEFAULT); + RunUVLoop(pLoop); + + /*while(TRUE) + { + usleep(1000); + }*/ + + return 0; +} diff --git a/package/allwinner/wifimanager/src/Makefile b/package/allwinner/wifimanager/src/Makefile index 55999dd83..13e4b8856 100755 --- a/package/allwinner/wifimanager/src/Makefile +++ b/package/allwinner/wifimanager/src/Makefile @@ -1,10 +1,13 @@ include $(TOPDIR)/rules.mk +include $(TINA_BUILD_TOP)/package/netease/Makefile.common +include $(TINA_BUILD_TOP)/build/nls.mk include $(BUILD_DIR)/package.mk target = libwifimg.so INCLUDES += -I. -I./include -LIBS += -lpthread -ldl -lrt +LIBS += -lpthread -ldl -lrt -liconv +local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv 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 @@ -25,7 +28,7 @@ else endif endif $(target): $(SRCS) - $(CC) -fPIC -shared $(INCLUDES) $(LDFLAGS) $^ -o $@ $(LIBS) + $(CC) -fPIC -shared $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) $^ -o $@ $(LIBS) @cp $@ $(CONFIG_PREFIX)/usr/lib #################################################################### diff --git a/package/allwinner/wifimanager/src/include/wifi.h b/package/allwinner/wifimanager/src/include/wifi.h index 8e519e72f..e2ce41c24 100755 --- a/package/allwinner/wifimanager/src/include/wifi.h +++ b/package/allwinner/wifimanager/src/include/wifi.h @@ -146,7 +146,12 @@ int wifi_change_fw_path(const char *fwpath); /** * Check and create if necessary initial entropy file */ + #if 0 #define WIFI_ENTROPY_FILE "/data/misc/wifi/entropy.bin" + +#else +#define WIFI_ENTROPY_FILE "/mnt/UDISK/wifi/entropy.bin" +#endif int ensure_entropy_file_exists(); /** diff --git a/package/allwinner/wifimanager/src/include/wifi_event.h b/package/allwinner/wifimanager/src/include/wifi_event.h index a1073121d..35c1c4134 100755 --- a/package/allwinner/wifimanager/src/include/wifi_event.h +++ b/package/allwinner/wifimanager/src/include/wifi_event.h @@ -46,6 +46,7 @@ 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 diff --git a/package/allwinner/wifimanager/src/include/wifi_intf.h b/package/allwinner/wifimanager/src/include/wifi_intf.h index b85fa7e13..7db2bbd9a 100755 --- a/package/allwinner/wifimanager/src/include/wifi_intf.h +++ b/package/allwinner/wifimanager/src/include/wifi_intf.h @@ -58,10 +58,13 @@ typedef struct{ 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 *length); int (*stop_scan)(); int (*restart_scan)(); + 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); diff --git a/package/allwinner/wifimanager/src/include/wpa_supplicant_conf.h b/package/allwinner/wifimanager/src/include/wpa_supplicant_conf.h index bb67ae66c..cd3c2caf7 100755 --- a/package/allwinner/wifimanager/src/include/wpa_supplicant_conf.h +++ b/package/allwinner/wifimanager/src/include/wpa_supplicant_conf.h @@ -20,6 +20,9 @@ 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 }; // extern "C" diff --git a/package/allwinner/wifimanager/src/network_manager.c b/package/allwinner/wifimanager/src/network_manager.c index d2e102761..1472dee8f 100755 --- a/package/allwinner/wifimanager/src/network_manager.c +++ b/package/allwinner/wifimanager/src/network_manager.c @@ -5,14 +5,20 @@ #include #include +#include + #include "wifi_event.h" #include "network_manager.h" #include "wifi_intf.h" #include "wifi.h" -#include "wmg_debug.h" #include "tool.h" #define WAITING_CLK_COUNTS 50 #define SSID_LEN 512 +#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 */ @@ -100,25 +106,25 @@ static const char * wpa_supplicant_state_txt(enum wpa_states state) } void print_wpa_status(struct wpa_status *wpa_sta) { - wmg_printf(MSG_DEBUG,"obtained wpa_supplicant status,as follow:\n"); - wmg_printf(MSG_DEBUG,"==============================\n"); + LOG_EX(LOG_Debug, "obtained wpa_supplicant status,as follow:\n"); + LOG_EX(LOG_Debug, "==============================\n"); if(wpa_sta->id >= 0) - wmg_printf(MSG_DEBUG,"id:%d\n",wpa_sta->id); + LOG_EX(LOG_Debug, "id:%d\n",wpa_sta->id); if(wpa_sta->bssid) - wmg_printf(MSG_DEBUG,"bssid:%s\n",wpa_sta->bssid); + LOG_EX(LOG_Debug, "bssid:%s\n",wpa_sta->bssid); if(wpa_sta->freq >=0) - wmg_printf(MSG_DEBUG,"freq:%d\n",wpa_sta->freq); + LOG_EX(LOG_Debug, "freq:%d\n",wpa_sta->freq); if(wpa_sta->ssid) - wmg_printf(MSG_DEBUG,"ssid:%s\n",wpa_sta->ssid); + LOG_EX(LOG_Debug, "ssid:%s\n",wpa_sta->ssid); if(wpa_sta->wpa_state) - wmg_printf(MSG_DEBUG,"wpa_state:%s\n",wpa_supplicant_state_txt(wpa_sta->wpa_state)); + LOG_EX(LOG_Debug, "wpa_state:%s\n",wpa_supplicant_state_txt(wpa_sta->wpa_state)); if(wpa_sta->ip_address) - wmg_printf(MSG_DEBUG,"ip_address:%s\n",wpa_sta->ip_address); + LOG_EX(LOG_Debug, "ip_address:%s\n",wpa_sta->ip_address); if(wpa_sta->key_mgmt) - wmg_printf(MSG_DEBUG,"key_mgmt:%s\n",wpa_sta->key_mgmt); + LOG_EX(LOG_Debug, "key_mgmt:%s\n",wpa_sta->key_mgmt); if(wpa_sta->mac_address) - wmg_printf(MSG_DEBUG,"mac_address:%s\n",wpa_sta->mac_address); - wmg_printf(MSG_DEBUG,"==============================\n"); + LOG_EX(LOG_Debug, "mac_address:%s\n",wpa_sta->mac_address); + LOG_EX(LOG_Debug, "==============================\n"); } static char *strstr_wpa(const char *src,const char *obj, @@ -128,18 +134,18 @@ static char *strstr_wpa(const char *src,const char *obj, int length; int i=0; if(src == NULL || obj == NULL || pre_str ==NULL){ - wmg_printf(MSG_DEBUG,"src or obj or pre_str is NULL"); + LOG_EX(LOG_Debug, "src or obj or pre_str is NULL"); return NULL; } if(pst_len > strlen(pre_str)){ - wmg_printf(MSG_ERROR,"pst_len length is illegal"); + LOG_EX(LOG_Debug, "pst_len length is illegal"); return NULL; } length = strlen(obj); for(;;p++,i++){ p=strchr(p,*obj); if(p == NULL){ - wmg_printf(MSG_MSGDUMP,"%s is not exist",obj); + LOG_EX(LOG_Debug, "%s is not exist",obj); return NULL; } if(strncmp(p,obj,length) == 0){ @@ -174,7 +180,7 @@ static int search_wpa_string(const char *src,const char *obj,int max,char *get_s while(1){ i++; if(i >max ){ - wmg_printf(MSG_ERROR,"Data overflow"); + LOG_EX(LOG_Debug, "Data overflow"); break; } pnext++; @@ -195,7 +201,7 @@ static struct wpa_status* wpa_status_init() if(gstatus == NULL) gstatus = (struct wpa_status *)wgos_zalloc(sizeof(struct wpa_status)); if(gstatus == NULL){ - wmg_printf(MSG_WARNING,"MALLOC STATUS STRUCT FAILED!\n"); + LOG_EX(LOG_Debug, "MALLOC STATUS STRUCT FAILED!\n"); return NULL; } gstatus->id = -1; @@ -254,7 +260,7 @@ int update_scan_results() { int i=0; - wmg_printf(MSG_INFO,"update scan results enter\n"); + LOG_EX(LOG_Debug, "update scan results enter\n"); pthread_mutex_lock(&thread_run_mutex); scan_completed = 0; @@ -383,6 +389,73 @@ int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt) 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; @@ -391,7 +464,7 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[]) char flag[128], pssid[SSID_LEN + 1]; int len = 0, i = 0; - wmg_printf(MSG_DEBUG,"enter get_key_mgmt, ssid %s\n", ssid); + 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; @@ -403,7 +476,7 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[]) ptr = strchr(scan_results, '\n'); if(!ptr){ pthread_mutex_unlock(&scan_mutex); - wmg_printf(MSG_DEBUG,"no ap scan, return\n"); + LOG_EX(LOG_Debug, "no ap scan, return\n"); return 0; } @@ -438,7 +511,7 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[]) len = len - 1; strncpy(flag, pflag, len); flag[len] = '\0'; - wmg_printf(MSG_DEBUG,"ssid %s, flag %s\n", ssid, flag); + 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; @@ -515,14 +588,14 @@ void *wifi_scan_thread(void *args) usleep(100*1000); } - wmg_printf(MSG_DEBUG,"scan stauts %d\n", get_scan_status()); + 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){ scan_error = 1; - wmg_printf(MSG_ERROR,"do scan results error!\n"); + LOG_EX(LOG_Debug, "do scan results error!\n"); pthread_mutex_unlock(&scan_mutex); continue; } diff --git a/package/allwinner/wifimanager/src/udhcpc_thread.c b/package/allwinner/wifimanager/src/udhcpc_thread.c index 8f1b94e9c..9857b3e8e 100755 --- a/package/allwinner/wifimanager/src/udhcpc_thread.c +++ b/package/allwinner/wifimanager/src/udhcpc_thread.c @@ -8,11 +8,11 @@ #include #include #include +#include #include "wifi_event.h" #include "wifi_state_machine.h" #include "wifi.h" -#include "wmg_debug.h" extern int disconnecting; extern int connecting_ap_event_label; @@ -83,13 +83,13 @@ void *udhcpc_thread(void *args) times++; }while((vflag == 0) && (times < 310)); - wmg_printf(MSG_DEBUG,"vflag= %d\n",vflag); + LOG_EX(LOG_Debug, "vflag= %d\n",vflag); if(vflag != 0){ set_wifi_machine_state(CONNECTED_STATE); - set_cur_wifi_event(AP_CONNECTED); + set_cur_wifi_event(AP_CONNECTED); call_event_callback_function(WIFIMG_NETWORK_CONNECTED, NULL, connecting_ap_event_label); }else{ - wmg_printf(MSG_ERROR,"udhcpc wlan0 timeout, pid %d!\n",pthread_self()); + LOG_EX(LOG_Debug, "udhcpc wlan0 timeout, pid %d!\n",pthread_self()); /* stop dhcpc thread */ system("/etc/wifi/udhcpc_wlan0 stop"); @@ -98,7 +98,7 @@ void *udhcpc_thread(void *args) sprintf(cmd, "%s", "DISCONNECT"); wifi_command(cmd, reply, sizeof(reply)); - set_wifi_machine_state(DISCONNECTED_STATE); + 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); } @@ -111,5 +111,10 @@ void *udhcpc_thread(void *args) void start_udhcpc_thread(void *args) { pthread_t thread_id; - pthread_create(&thread_id, NULL, &udhcpc_thread, args); + 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); } diff --git a/package/allwinner/wifimanager/src/wifi.c b/package/allwinner/wifimanager/src/wifi.c index a10b7fcfd..aded941d2 100755 --- a/package/allwinner/wifimanager/src/wifi.c +++ b/package/allwinner/wifimanager/src/wifi.c @@ -11,21 +11,41 @@ #include "wpa_ctrl.h" #include "wifi.h" #include +#include #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; /* socket pair used to exit from a blocking read */ static int exit_sockets[2]; //static const char IFACE_DIR[] = "/data/misc/wifi/sockets"; +#if 0 static const char IFACE_DIR[] = "/etc/wifi/sockets"; static char primary_iface[IFACE_VALUE_MAX]; -static const char SUPP_CONFIG_TEMPLATE[]= "/etc/wifi/wpa_supplicant_src.conf"; +static const char SUPP_CONFIG_TEMPLATE[]= "/rom/etc/wifi/wpa_supplicant.conf"; static const char SUPP_CONFIG_FILE[] = "/etc/wifi/wpa_supplicant.conf"; static const char CONTROL_IFACE_PATH[] = "/etc/wifi/sockets"; +#else + +static const char IFACE_DIR[] = "/mnt/UDISK/wifi/sockets"; +static char primary_iface[IFACE_VALUE_MAX]; +static const char SUPP_CONFIG_TEMPLATE[]= "/rom/etc/wifi/wpa_supplicant.conf"; +static const char SUPP_CONFIG_FILE[] = "/mnt/UDISK/wifi/wpa_supplicant.conf"; +static const char SUPP_CONFIG_ADD_TEMPLATE[]= "/rom/etc/wifi/wpa_supplicant_overlay.conf"; +static const char SUPP_CONFIG_ADD_FILE[] = "/mnt/UDISK/wifi/wpa_supplicant_overlay.conf"; +static const char SUPP_CONFIG_SRC_TEMPLATE[]= "/rom/etc/wifi/wpa_supplicant_src.conf"; +static const char SUPP_CONFIG_SRC_FILE[] = "/mnt/UDISK/wifi/wpa_supplicant_src.conf"; +static const char SUPP_CONFIG_DIR[] = "/mnt/UDISK/wifi/"; + + +static const char CONTROL_IFACE_PATH[] = "/mnt/UDISK/wifi/sockets"; + + +#endif static const char SUPP_ENTROPY_FILE[] = WIFI_ENTROPY_FILE; static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35, @@ -80,7 +100,7 @@ static int rmmod(const char *modname) } if (ret != 0) - printf("Unable to unload driver module \"%s\": %s\n", + LOG_EX(LOG_Debug, "Unable to unload driver module \"%s\": %s\n", modname, strerror(errno)); #else @@ -106,7 +126,7 @@ int wifi_load_driver(const char *path, const char *args) FILE *fp = NULL; if (!path) { - wmg_printf(MSG_ERROR,"driver path is NULL!\n"); + LOG_EX(LOG_Debug, "driver path is NULL!\n"); return -1; } @@ -123,10 +143,10 @@ int wifi_load_driver(const char *path, const char *args) p_s++; } name[i] = '\0'; - wmg_printf(MSG_DEBUG,"driver name %s\n", name); + LOG_EX(LOG_Debug, "driver name %s\n", name); if (insmod(path, args) < 0) { - wmg_printf(MSG_ERROR,"insmod %s %s firmware failed!\n", path, args); + LOG_EX(LOG_Debug, "insmod %s %s firmware failed!\n", path, args); rmmod(name);//it may be load driver already,try remove it. return -1; } @@ -134,17 +154,17 @@ int wifi_load_driver(const char *path, const char *args) do{ fp=fopen("/proc/net/wireless", "r"); if (!fp) { - wmg_printf(MSG_ERROR,"failed to fopen file: /proc/net/wireless\n"); + LOG_EX(LOG_Debug, "failed to fopen file: /proc/net/wireless\n"); rmmod(name); //try remove it. return -1; } ret = fread(tmp_buf, sizeof(tmp_buf), 1, fp); if (ret==0){ - wmg_printf(MSG_ERROR,"faied to read proc/net/wireless\n"); + LOG_EX(LOG_Debug, "faied to read proc/net/wireless\n"); } fclose(fp); - wmg_printf(MSG_DEBUG,"loading wifi driver...\n"); + LOG_EX(LOG_Debug, "loading wifi driver...\n"); p_strstr_wlan = strstr(tmp_buf, "wlan0"); if (p_strstr_wlan != NULL) { break; @@ -154,7 +174,7 @@ int wifi_load_driver(const char *path, const char *args) } while (count++ <= TIME_COUNT); if(count > TIME_COUNT) { - wmg_printf(MSG_ERROR,"timeout, register netdevice wlan0 failed.\n"); + LOG_EX(LOG_Debug, "timeout, register netdevice wlan0 failed.\n"); rmmod(name); return -1; } @@ -179,19 +199,19 @@ int ensure_entropy_file_exists() if ((ret == 0) || (errno == EACCES)) { if ((ret != 0) && (chmod(SUPP_ENTROPY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) { - wmg_printf(MSG_ERROR,"Cannot set RW to \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot set RW to \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); return -1; } return 0; } destfd = TEMP_FAILURE_RETRY(open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660)); if (destfd < 0) { - wmg_printf(MSG_DEBUG,"Cannot create \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot create \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); return -1; } if (TEMP_FAILURE_RETRY(write(destfd, dummy_key, sizeof(dummy_key))) != sizeof(dummy_key)) { - wmg_printf(MSG_ERROR,"Error writing \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); + LOG_EX(LOG_Debug, "Error writing \"%s\": %s\n", SUPP_ENTROPY_FILE, strerror(errno)); close(destfd); return -1; } @@ -199,7 +219,7 @@ int ensure_entropy_file_exists() /* chmod is needed because open() didn't set permisions properly */ if (chmod(SUPP_ENTROPY_FILE, 0660) < 0) { - wmg_printf(MSG_ERROR,"Error changing permissions of %s to 0660: %s\n", + LOG_EX(LOG_Debug, "Error changing permissions of %s to 0660: %s\n", SUPP_ENTROPY_FILE, strerror(errno)); unlink(SUPP_ENTROPY_FILE); return -1; @@ -226,14 +246,14 @@ int update_ctrl_interface(const char *config_file) { return 0; srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY)); if (srcfd < 0) { - wmg_printf(MSG_ERROR,"Cannot open \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot open \"%s\": %s\n", config_file, strerror(errno)); free(pbuf); return 0; } nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size)); close(srcfd); if (nread < 0) { - wmg_printf(MSG_ERROR,"Cannot read \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot read \"%s\": %s\n", config_file, strerror(errno)); free(pbuf); return 0; } @@ -261,7 +281,7 @@ int update_ctrl_interface(const char *config_file) { int mlen = strlen(ifc); int nwrite; if (strncmp(ifc, iptr, mlen) != 0) { - wmg_printf(MSG_ERROR,"ctrl_interface != %s\n", ifc); + LOG_EX(LOG_Debug, "ctrl_interface != %s\n", ifc); while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n')) ilen++; mlen = ((ilen >= mlen) ? ilen : mlen) + 1; @@ -270,7 +290,7 @@ int update_ctrl_interface(const char *config_file) { memcpy(iptr, ifc, strlen(ifc)); destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660)); if (destfd < 0) { - wmg_printf(MSG_ERROR,"Cannot update \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot update \"%s\": %s\n", config_file, strerror(errno)); free(pbuf); return -1; } @@ -295,7 +315,7 @@ int ensure_config_file_exists(const char *config_file) if ((ret == 0) || (errno == EACCES)) { if ((ret != 0) && (chmod(config_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 0)) { - wmg_printf(MSG_ERROR,"Cannot set RW to \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot set RW to \"%s\": %s\n", config_file, strerror(errno)); return -1; } /* return if we were able to update control interface properly */ @@ -307,26 +327,26 @@ int ensure_config_file_exists(const char *config_file) */ } } else if (errno != ENOENT) { - wmg_printf(MSG_ERROR,"Cannot access \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot access \"%s\": %s\n", config_file, strerror(errno)); return -1; } srcfd = TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY)); if (srcfd < 0) { - wmg_printf(MSG_ERROR,"Cannot open \"%s\": %s\n", SUPP_CONFIG_TEMPLATE, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot open \"%s\": %s\n", SUPP_CONFIG_TEMPLATE, strerror(errno)); return -1; } destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660)); if (destfd < 0) { close(srcfd); - wmg_printf(MSG_ERROR,"Cannot create \"%s\": %s\n", config_file, strerror(errno)); + LOG_EX(LOG_Debug, "Cannot create \"%s\": %s\n", config_file, strerror(errno)); return -1; } while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) { if (nread < 0) { - wmg_printf(MSG_ERROR,"Error reading \"%s\": %s\n", SUPP_CONFIG_TEMPLATE, strerror(errno)); + LOG_EX(LOG_Debug, "Error reading \"%s\": %s\n", SUPP_CONFIG_TEMPLATE, strerror(errno)); close(srcfd); close(destfd); unlink(config_file); @@ -340,7 +360,7 @@ int ensure_config_file_exists(const char *config_file) /* chmod is needed because open() didn't set permisions properly */ if (chmod(config_file, 0660) < 0) { - wmg_printf(MSG_ERROR,"Error changing permissions of %s to 0660: %s\n", + LOG_EX(LOG_Debug, "Error changing permissions of %s to 0660: %s\n", config_file, strerror(errno)); unlink(config_file); return -1; @@ -349,20 +369,109 @@ int ensure_config_file_exists(const char *config_file) return update_ctrl_interface(config_file); } + +int ensure_dir_exits(const char * dir) +{ + if(NULL == dir) return -1; + if(NULL == opendir(dir)) + { + return mkdir(dir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + } + + return 0; + +} + +int ensure_file_exists(const char *config_file,const char *temp_file) +{ + char buf[2048]; + int srcfd, destfd; + struct stat sb; + int nread; + int ret; + + ret = access(config_file, R_OK|W_OK); + if ((ret == 0) || (errno == EACCES)) { + return 0; + + } else if (errno != ENOENT) { + LOG_EX(LOG_Debug, "Cannot access \"%s\": %s\n", config_file, strerror(errno)); + return -1; + } + + srcfd = TEMP_FAILURE_RETRY(open(temp_file, O_RDONLY)); + if (srcfd < 0) { + LOG_EX(LOG_Debug, "Cannot open \"%s\": %s\n", temp_file, strerror(errno)); + return -1; + } + + destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660)); + if (destfd < 0) { + close(srcfd); + LOG_EX(LOG_Debug, "Cannot create \"%s\": %s\n", config_file, strerror(errno)); + return -1; + } + + while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) { + if (nread < 0) { + LOG_EX(LOG_Debug, "Error reading \"%s\": %s\n", temp_file, strerror(errno)); + close(srcfd); + close(destfd); + unlink(config_file); + return -1; + } + TEMP_FAILURE_RETRY(write(destfd, buf, nread)); + } + + close(destfd); + close(srcfd); + + /* chmod is needed because open() didn't set permisions properly */ + if (chmod(config_file, 0660) < 0) { + LOG_EX(LOG_Debug, "Error changing permissions of %s to 0660: %s\n", + config_file, strerror(errno)); + unlink(config_file); + return -1; + } + + return 0; +} + + int wifi_start_supplicant(int p2p_supported) { char cmd[512] = {0}; - /* Before starting the daemon, make sure its config file exists */ + + if(ensure_dir_exits(SUPP_CONFIG_DIR)) + { + LOG_EX(LOG_Debug, "Wi-Fi dir created fail\n"); + return -1; + } + if(ensure_file_exists(SUPP_CONFIG_ADD_FILE,SUPP_CONFIG_ADD_TEMPLATE)) + { + LOG_EX(LOG_Debug, "Wi-Fi additional file created error\n"); + return -1; + } + + if(ensure_file_exists(SUPP_CONFIG_SRC_FILE,SUPP_CONFIG_SRC_TEMPLATE)) + { + LOG_EX(LOG_Debug, "Wi-Fi src file created error\n"); + return -1; + } + + + /* Before starting the daemon, make sure its config file exists */ if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) { - wmg_printf(MSG_ERROR,"Wi-Fi will not be enabled\n"); + LOG_EX(LOG_Debug, "Wi-Fi will not be enabled\n"); return -1; } if (ensure_entropy_file_exists() < 0) { - wmg_printf(MSG_DEBUG,"Wi-Fi entropy file was not created\n"); + 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(); @@ -396,7 +505,7 @@ int wifi_connect_on_socket_path(const char *path) ctrl_conn = wpa_ctrl_open(path); } if (ctrl_conn == NULL) { - wmg_printf(MSG_ERROR,"Unable to open connection to supplicant on \"%s\": %s\n", + LOG_EX(LOG_Debug, "Unable to open connection to supplicant on \"%s\": %s\n", path, strerror(errno)); return -1; } @@ -442,13 +551,16 @@ int wifi_send_command(const char *cmd, char *reply, size_t *reply_len) { int ret; if (ctrl_conn == NULL) { - wmg_printf(MSG_ERROR,"Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd); + LOG_EX(LOG_Debug, "Not connected to wpa_supplicant - \"%s\" command dropped.\n", cmd); return -1; } ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL); + + LOG_EX(LOG_Debug, "cmd is %s,size is %d,reply len %d\r\n",cmd,strlen(cmd),*reply_len); + if (ret == -2) { - wmg_printf(MSG_ERROR,"'%s' command timed out.\n", cmd); + 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)); return -2; @@ -474,7 +586,7 @@ int wifi_ctrl_recv(char *reply, size_t *reply_len) rfds[1].events |= POLLIN; res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1)); if (res < 0) { - wmg_printf(MSG_ERROR,"Error poll = %d\n", res); + LOG_EX(LOG_Debug, "Error poll = %d\n", res); return res; } if (rfds[0].revents & POLLIN) { @@ -505,14 +617,14 @@ int wifi_wait_on_socket(char *buf, size_t buflen) } if (result < 0) { - wmg_printf(MSG_ERROR,"wifi_ctrl_recv failed: %s\n", strerror(errno)); + LOG_EX(LOG_Debug, "wifi_ctrl_recv failed: %s\n", strerror(errno)); return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - recv error"); } buf[nread] = '\0'; /* Check for EOF on the socket */ if (result == 0 && nread == 0) { /* Fabricate an event to pass up */ - wmg_printf(MSG_WARNING,"Received EOF on supplicant socket\n"); + LOG_EX(LOG_Debug, "Received EOF on supplicant socket\n"); return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - signal 0 received"); } /* @@ -545,11 +657,11 @@ int wifi_wait_on_socket(char *buf, size_t buflen) if (match != NULL) { nread -= (match + 1 - buf); memmove(buf, match + 1, nread + 1); - //printf("supplicant generated event without interface - %s\n", buf); + //LOG_EX(LOG_Debug, "supplicant generated event without interface - %s\n", buf); } } else { /* let the event go as is! */ - //printf("supplicant generated event without interface and without message level - %s\n", buf); + //LOG_EX(LOG_Debug, "supplicant generated event without interface and without message level - %s\n", buf); } return nread; @@ -595,18 +707,34 @@ void wifi_close_supplicant_connection() } } + +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; } - wmg_printf(MSG_DEBUG,"do cmd %s\n", cmd); + 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 (wifi_send_command(cmd, reply, &reply_len) != 0) { + if ((ret =wifi_send_command(cmd, reply, &reply_len)) != 0) { + + LOG_EX(LOG_Debug, "wifi_send_command ret is %d %s\r\n",ret, reply); + 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') { diff --git a/package/allwinner/wifimanager/src/wifi_event.c b/package/allwinner/wifimanager/src/wifi_event.c index 6a738f6f7..42b26efe6 100755 --- a/package/allwinner/wifimanager/src/wifi_event.c +++ b/package/allwinner/wifimanager/src/wifi_event.c @@ -3,13 +3,13 @@ #include #include #include +#include #include "wifi.h" #include "wifi_event.h" #include "wifi_state_machine.h" #include "wifi_intf.h" #include "wpa_supplicant_conf.h" -#include "wmg_debug.h" //tWIFI_STATE gwifi_state; tWIFI_STATE gwifi_state = WIFIMG_WIFI_DISABLED; @@ -40,7 +40,7 @@ static void handle_event(int event, char * remainder) { if((state == DISCONNECTING_STATE) //call disconnect || (state == L2CONNECTED_STATE) || (state == CONNECTED_STATE)) //auto disconnect(ap shutdown) { - wmg_printf(MSG_INFO,"Network disconnected!\n"); + 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); @@ -51,7 +51,7 @@ static void handle_event(int event, char * remainder) { if(netid_connecting[0] != '\0'){ /* get already connected netid */ wpa_conf_get_ap_connected(netid_connected, &len); - wmg_printf(MSG_DEBUG,"connecting id %s, connected id %s\n", netid_connecting, netid_connected); + 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"); @@ -73,7 +73,7 @@ static void handle_event(int event, char * remainder) { case NETWORK_NOT_FOUND: network_not_found_count++; - wmg_printf(MSG_ERROR,"NETWORK NOT FOUND %d times!\n",network_not_found_count); + LOG_EX(LOG_Debug,"NETWORK NOT FOUND %d times!\n",network_not_found_count); if(network_not_found_count >= 3){ sprintf(cmd, "%s", "DISCONNECT"); wifi_command(cmd, reply, sizeof(reply)); @@ -96,10 +96,11 @@ static int dispatch_event(const char *event_str, int nread) char *event_data = NULL; if(!event_str || !event_str[0]){ - wmg_printf(MSG_WARNING,"event is NULL!\n"); + 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")){ @@ -116,7 +117,7 @@ static int dispatch_event(const char *event_str, int nread) } } - //printf("EVENT, not care!\n"); + //LOG_EX(LOG_Debug, "EVENT, not care!\n"); return 0; } @@ -129,7 +130,7 @@ static int dispatch_event(const char *event_str, int nread) } event_name[i] = '\0'; } else { - wmg_printf(MSG_DEBUG,"Received wpa_supplicant event with empty event name!\n"); + LOG_EX(LOG_Debug, "Received wpa_supplicant event with empty event name!\n"); return 0; } @@ -162,6 +163,7 @@ static int dispatch_event(const char *event_str, int nread) 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, ' '); @@ -176,18 +178,18 @@ static int dispatch_event(const char *event_str, int nread) } if(event == STATE_CHANGE){ - wmg_printf(MSG_DEBUG,"STATE_CHANGE, no care!\n"); + LOG_EX(LOG_Debug, "STATE_CHANGE, no care!\n"); return 0; } else if(event == DRIVER_STATE){ - wmg_printf(MSG_DEBUG,"DRIVER_STATE, no care!\n"); + LOG_EX(LOG_Debug, "DRIVER_STATE, no care!\n"); return 0; }else if(event == TERMINATING){ - wmg_printf(MSG_ERROR,"Wpa supplicant terminated!\n"); + LOG_EX(LOG_Debug, "Wpa supplicant terminated!\n"); gwifi_state = WIFIMG_WIFI_DISABLED; call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0); return 1; }else if(event == EAP_FAILURE){ - wmg_printf(MSG_ERROR,"EAP FAILURE!\n"); + LOG_EX(LOG_Debug, "EAP FAILURE!\n"); return 0; }else if(event == ASSOC_REJECT){ assoc_reject_count++; @@ -196,7 +198,7 @@ static int dispatch_event(const char *event_str, int nread) sprintf(cmd, "%s", "DISCONNECT"); wifi_command(cmd, reply, sizeof(reply)); } - wmg_printf(MSG_ERROR,"ASSOC REJECT!\n"); + LOG_EX(LOG_Debug, "ASSOC REJECT!\n"); return 0; }else{ handle_event(event, event_data); @@ -259,13 +261,13 @@ void *check_connect_timeout(void *args) /* password incorrect */ if ((state == DISCONNECTED_STATE) && (event == PASSWORD_INCORRECT)){ - wmg_printf(MSG_ERROR,"check_connect_timeout exit: password failed!\n"); + 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){ - wmg_printf(MSG_ERROR,"associat reject over 3 times!\n"); + LOG_EX(LOG_Debug, "associat reject over 3 times!\n"); assoc_reject_count = 0; break; } @@ -291,7 +293,18 @@ void *check_connect_timeout(void *args) void start_check_connect_timeout(int first) { pthread_t check_timeout_id; - pthread_create(&check_timeout_id, NULL, check_connect_timeout, NULL); + 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) @@ -318,7 +331,7 @@ void *wifi_on_check_connect_timeout(void *args) wifi_command(cmd, reply, sizeof(reply)); set_wifi_machine_state(DISCONNECTED_STATE); - wmg_printf(MSG_ERROR,"call event NO_NETWORK_CONNECTING\n"); + LOG_EX(LOG_Debug, "call event NO_NETWORK_CONNECTING\n"); call_event_callback_function(WIFIMG_NO_NETWORK_CONNECTING, NULL, connecting_ap_event_label); } @@ -376,7 +389,7 @@ int call_event_callback_function(tWIFI_EVENT wifi_event, char *buf, int event_la { int i=0; - wmg_printf(MSG_DEBUG,"call event 0x%x\n", wifi_event); + LOG_EX(LOG_Debug, "call event 0x%x\n", wifi_event); for(i=0; i #include #include "wifi_state_machine.h" +#include static int gwifi_machine_state = DISCONNECTED_STATE; /* set wifi state */ int set_wifi_machine_state(tWIFI_MACHINE_STATE state) { - //printf("set_wifi_machine_state 0x%x\n", 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() { - //printf("wifi machine state 0x%x\n", gwifi_machine_state); + //LOG_EX(LOG_Debug, "wifi machine state 0x%x\n", gwifi_machine_state); return gwifi_machine_state; } diff --git a/package/allwinner/wifimanager/src/wifimanager.c b/package/allwinner/wifimanager/src/wifimanager.c index 40d7d5fde..f9a92e0e7 100755 --- a/package/allwinner/wifimanager/src/wifimanager.c +++ b/package/allwinner/wifimanager/src/wifimanager.c @@ -9,12 +9,23 @@ #include "network_manager.h" #include "wpa_supplicant_conf.h" #include "wifi_intf.h" -#include "wmg_debug.h" +//#include +#include +#define ENCODE_STYLE_UTF_8 "UTF-8" +#define ENCODE_STYLE_GB2312 "GB2312" #define WPA_SSID_LENTH 512 +#define APP_ERR_NULL -1 +#define APP_ERR_NOT_MATCH -2 +#define APP_ERR_INVALID_PARAMS -3 extern int is_ip_exist(); +typedef enum +{ + WIFI_SSID_UTF_8, + WIFI_SSID_GBK, +}wifi_ssid_encode_e; char netid_connecting[NET_ID_LEN+1] = {0}; int disconnecting = 0; int connecting_ap_event_label = 0; @@ -51,7 +62,7 @@ static int aw_wifi_is_ap_connected(char *ssid, int *len) wifi_machine_state = get_wifi_machine_state(); if(wifi_machine_state != CONNECTED_STATE && wifi_machine_state != DISCONNECTED_STATE){ - wmg_printf(MSG_INFO,"%s: wifi_busing, please try again later!\n", __func__); + LOG_EX(LOG_Debug, "%s: wifi_busing, please try again later!\n", __func__); return -1; } @@ -106,7 +117,7 @@ static int aw_wifi_get_scan_results(char *result, int *len) if(get_scan_results_inner(result, len) != 0) { - wmg_printf(MSG_ERROR,"%s: There is a scan or scan_results error, Please try scan again later!\n", __func__); + LOG_EX(LOG_Debug, "%s: There is a scan or scan_results error, Please try scan again later!\n", __func__); return -1; } else @@ -147,13 +158,13 @@ static int ssid_app_to_wpa_scan(const char *app_ssid, char *scan_ssid) if(!app_ssid || !app_ssid[0]) { - wmg_printf(MSG_ERROR,"Error: app ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: app ssid is NULL!\n"); return -1; } if(!scan_ssid) { - wmg_printf(MSG_ERROR,"Error: wpa ssid buf is NULL\n"); + LOG_EX(LOG_Debug, "Error: wpa ssid buf is NULL\n"); return -1; } @@ -204,13 +215,13 @@ static int ssid_app_to_wpa_conf(const char *app_ssid, char *conf_ssid) if(!app_ssid || !app_ssid[0]) { - wmg_printf(MSG_ERROR,"Error: app ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: app ssid is NULL!\n"); return -1; } if(!conf_ssid) { - wmg_printf(MSG_ERROR,"Error: wpa ssid buf is NULL\n"); + LOG_EX(LOG_Debug, "Error: wpa ssid buf is NULL\n"); return -1; } @@ -243,14 +254,14 @@ static int connect_command_handle(char *cmd,char *net_id) char reply[REPLY_BUF_SIZE] = {0}; ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"%s failed,Remove the information just connected!",cmd); + LOG_EX(LOG_Debug, "%s failed,Remove the information just connected!",cmd); sprintf(cmd, "REMOVE_NETWORK %s", net_id); wifi_command(cmd, reply, sizeof(reply)); sprintf(cmd, "%s", "SAVE_CONFIG"); wifi_command(cmd, reply, sizeof(reply)); ret = -1; }else{ - wmg_printf(MSG_EXCESSIVE,"%s: %s",cmd,reply); + LOG_EX(LOG_Debug, "%s: %s",cmd,reply); return 0; } } @@ -283,7 +294,7 @@ static int aw_wifi_add_network(const char *ssid, tKEY_MGMT key_mgmt, const char } if(!ssid || !ssid[0]){ - wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: ssid is NULL!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -337,7 +348,7 @@ static int aw_wifi_add_network(const char *ssid, tKEY_MGMT key_mgmt, const char cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, netid2, sizeof(netid2)); if(ret){ - wmg_printf(MSG_ERROR,"do add network results error!\n"); + LOG_EX(LOG_Debug, "do add network results error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -376,7 +387,7 @@ static int aw_wifi_add_network(const char *ssid, tKEY_MGMT key_mgmt, const char ret = check_wpa_passwd(passwd); if(ret == 0){ - wmg_printf(MSG_ERROR,"check wpa-psk passwd is error!\n"); + LOG_EX(LOG_Debug, "check wpa-psk passwd is error!\n"); cancel_saved_conf_handle(netid2); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; @@ -418,7 +429,7 @@ static int aw_wifi_add_network(const char *ssid, tKEY_MGMT key_mgmt, const char } } else { - wmg_printf(MSG_ERROR,"Error: key mgmt not support!\n"); + LOG_EX(LOG_Debug, "Error: key mgmt not support!\n"); /* cancel saved in wpa_supplicant.conf */ cancel_saved_conf_handle(netid2); ret = -1; @@ -477,14 +488,14 @@ static int aw_wifi_add_network(const char *ssid, tKEY_MGMT key_mgmt, const char event = get_cur_wifi_event(); /* password incorrect*/ if ((state == DISCONNECTED_STATE) && (event == PASSWORD_INCORRECT)){ - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: password failed!\n"); + LOG_EX(LOG_Debug, "wifi_connect_ap_inner: password failed!\n"); break; } if(event == CONNECT_AP_TIMEOUT) break; if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){ reset_assoc_reject_count(); - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); + LOG_EX(LOG_Debug, "aw_wifi_add_network: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); break; } @@ -566,6 +577,29 @@ end: return ret; } +static int aw_wifi_reconfig(void) +{ + int status =0; + char reply[REPLY_BUF_SIZE] = {0}; + + if(gwifi_state == WIFIMG_WIFI_DISABLED){ + return -1; + } + + status = wifi_command("RECONFIGURE", reply, sizeof(reply)); + if(0 != status) + { + LOG_EX(LOG_Debug, "wpa_reconfig err:%d\r\n",status); + return status; + }else + { + LOG_EX(LOG_Debug, "wpa_reconfig results:\r\n%s\r\n",reply); + } + + return 0; +} + + static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const char *passwd, int event_label) { int i=0, ret = -1, len = 0, max_prio = -1; @@ -593,7 +627,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, netid2, sizeof(netid2)); if(ret){ - wmg_printf(MSG_ERROR,"do add network results error!\n"); + LOG_EX(LOG_Debug, "do add network results error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -634,7 +668,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha ret = check_wpa_passwd(passwd); if(ret == 0){ - wmg_printf(MSG_ERROR,"check wpa-psk passwd is error!\n"); + LOG_EX(LOG_Debug, "check wpa-psk passwd is error!\n"); /* cancel saved in wpa_supplicant.conf */ sprintf(cmd, "REMOVE_NETWORK %s", netid2); @@ -679,7 +713,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha goto end; } } else { - wmg_printf(MSG_ERROR,"Error: key mgmt is not support!\n"); + LOG_EX(LOG_Debug, "Error: key mgmt is not support!\n"); /* cancel saved in wpa_supplicant.conf */ sprintf(cmd, "REMOVE_NETWORK %s", netid2); @@ -735,12 +769,12 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha event = get_cur_wifi_event(); /* password incorrect*/ if ((state == DISCONNECTED_STATE) && (event == PASSWORD_INCORRECT)){ - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: password failed!\n"); + LOG_EX(LOG_Debug, "wifi_connect_ap_inner: password failed!\n"); break; } if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){ reset_assoc_reject_count(); - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); + LOG_EX(LOG_Debug, "wifi_connect_ap_inner: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); break; } @@ -763,7 +797,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha ret = -1; - wmg_printf(MSG_DEBUG,"connect ap inner:still connecting!\n"); + LOG_EX(LOG_Debug, "connect ap inner:still connecting!\n"); event_code = WIFIMG_NETWORK_NOT_EXIST; goto end; }else if(state == DISCONNECTED_STATE){ /* Errot when connecting */ @@ -778,7 +812,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha ret = -1; event_code = WIFIMG_PASSWORD_FAILED; - wmg_printf(MSG_ERROR,"connect ap inner:passwd failed!\n"); + LOG_EX(LOG_Debug, "connect ap inner:passwd failed!\n"); goto end; }else if(event == OBTAINING_IP_TIMEOUT){ if(is_exist == 1 || is_exist == 3){ @@ -791,7 +825,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha /* save config */ sprintf(cmd, "%s", "SAVE_CONFIG"); wifi_command(cmd, reply, sizeof(reply)); - wmg_printf(MSG_WARNING,"connect ap inner:obtian IP time out!\n"); + LOG_EX(LOG_Debug, "connect ap inner:obtian IP time out!\n"); ret = 0; }else{ event_code = WIFIMG_NETWORK_NOT_EXIST; @@ -808,7 +842,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha /* save config */ sprintf(cmd, "%s", "SAVE_CONFIG"); wifi_command(cmd, reply, sizeof(reply)); - wmg_printf(MSG_DEBUG,"wifi connected in inner!\n"); + LOG_EX(LOG_Debug, "wifi connected in inner!\n"); ret = 0; }else{ event_code = WIFIMG_NETWORK_NOT_EXIST; @@ -840,7 +874,7 @@ static int aw_wifi_connect_ap_key_mgmt(const char *ssid, tKEY_MGMT key_mgmt, con } if(!ssid || !ssid[0]){ - wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: ssid is NULL!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -939,22 +973,22 @@ static int aw_wifi_connect_ap(const char *ssid, const char *passwd, int event_la const char *p_ssid = NULL; if(gwifi_state == WIFIMG_WIFI_DISABLED){ - wmg_printf(MSG_DEBUG,"aw wifi connect ap wifi disabled\n"); + LOG_EX(LOG_Debug, "aw wifi connect ap wifi disabled\n"); return -1; } if(!ssid || !ssid[0]){ - wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: ssid is NULL!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; } state = get_wifi_machine_state(); - wmg_printf(MSG_DEBUG,"aw wifi connect state 0x%x\n", state); + LOG_EX(LOG_Debug, "aw wifi connect state 0x%x\n", state); if(state != CONNECTED_STATE && state != DISCONNECTED_STATE){ ret = -1; - wmg_printf(MSG_INFO,"aw wifi connect ap dev busing\n"); + LOG_EX(LOG_Debug, "aw wifi connect ap dev busing\n"); event_code = WIFIMG_DEV_BUSING_EVENT; goto end; } @@ -1085,7 +1119,7 @@ disconnecting = 0; sprintf(cmd, "SELECT_NETWORK %s", net_id); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do selected network error!\n"); + LOG_EX(LOG_Debug, "do selected network error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -1099,7 +1133,7 @@ disconnecting = 0; cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do reconnect error!\n"); + LOG_EX(LOG_Debug, "do reconnect error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; } @@ -1116,13 +1150,13 @@ disconnecting = 0; event = get_cur_wifi_event(); /* password incorrect*/ if ((state == DISCONNECTED_STATE) && (event == PASSWORD_INCORRECT)){ - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: password failed!\n"); + LOG_EX(LOG_Debug, "wifi_connect_ap_inner: password failed!\n"); break; } if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){ reset_assoc_reject_count(); - wmg_printf(MSG_ERROR,"wifi_connect_ap_inner: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); + LOG_EX(LOG_Debug, "aw_wifi_connect_ap_with_netid: assoc reject %d times\n", MAX_ASSOC_REJECT_COUNT); break; } @@ -1190,7 +1224,7 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt) } if(!ssid || !ssid[0]){ - wmg_printf(MSG_ERROR,"Error: ssid is null!\n"); + LOG_EX(LOG_Debug, "Error: ssid is null!\n"); return -1; } @@ -1207,12 +1241,12 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt) len = NET_ID_LEN+1; ret = wpa_conf_ssid2netid(ssid, key_mgmt, net_id, &len); if(ret <= 0){ - wmg_printf(MSG_WARNING,"Warning: %s is not in wpa_supplicant.conf!\n", ssid); + LOG_EX(LOG_Debug, "Warning: %s is not in wpa_supplicant.conf!\n", ssid); return 0; } else if(!(ret & (0x01<<1) )) { - wmg_printf(MSG_WARNING,"Warning: %s exists in wpa_supplicant.conf, but the key_mgmt is not accordant!\n", ssid); + LOG_EX(LOG_Debug, "Warning: %s exists in wpa_supplicant.conf, but the key_mgmt is not accordant!\n", ssid); return 0; } @@ -1220,7 +1254,7 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt) sprintf(cmd, "REMOVE_NETWORK %s", net_id); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do remove network %s error!\n", net_id); + LOG_EX(LOG_Debug, "do remove network %s error!\n", net_id); return -1; } @@ -1228,7 +1262,7 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt) sprintf(cmd, "%s", "SAVE_CONFIG"); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do save config error!\n"); + LOG_EX(LOG_Debug, "do save config error!\n"); return -1; } @@ -1259,6 +1293,15 @@ static int aw_wifi_remove_all_networks() return ret; } +static int aw_wifi_enble_all_network() +{ + if(gwifi_state == WIFIMG_WIFI_DISABLED){ + return -1; + } + + wpa_conf_enable_all_networks(); +} + static int aw_wifi_connect_ap_auto(int event_label) { int i=0, ret = -1, len = 0; @@ -1358,7 +1401,7 @@ static int aw_wifi_disconnect_ap(int event_label) len = NET_ID_LEN+1; ret = wpa_conf_get_netid_connected(netid, &len); if(ret <= 0){ - wmg_printf(MSG_INFO,"This no connected AP!\n"); + LOG_EX(LOG_Debug, "This no connected AP!\n"); ret = -1; event_code = WIFIMG_OPT_NO_USE_EVENT; goto end; @@ -1374,7 +1417,7 @@ static int aw_wifi_disconnect_ap(int event_label) sprintf(cmd, "%s", "DISCONNECT"); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do disconnect network error!\n"); + LOG_EX(LOG_Debug, "do disconnect network error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; goto end; @@ -1438,11 +1481,11 @@ static int aw_wifi_list_networks(char *reply, size_t reply_len, int event_label) cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, reply, reply_len); if(ret){ - wmg_printf(MSG_ERROR,"do list_networks error!\n"); + LOG_EX(LOG_Debug, "do list_networks error!\n"); ret = -1; event_code = WIFIMG_CMD_OR_PARAMS_ERROR; } - wmg_printf(MSG_ERROR,"do list_networks finished!\n"); + LOG_EX(LOG_Debug, "do list_networks finished!\n"); end: if(ret != 0){ call_event_callback_function(event_code, NULL, event_label); @@ -1455,6 +1498,89 @@ end: } + +static aw_wifi_change_ap(int event_label) +{ + int i=0, ret = -1, len = 0; + char cmd[CMD_LEN+1] = {0}; + char reply[REPLY_BUF_SIZE] = {0}; + char connectedId[NET_ID_LEN]={0}; + int idSize =NET_ID_LEN; + tWIFI_MACHINE_STATE wifi_machine_state; + const char *p_ssid = NULL; + tWIFI_MACHINE_STATE state; + tWIFI_EVENT_INNER event; + + if(gwifi_state == WIFIMG_WIFI_DISABLED){ + return -1; + } + + /* pase scan thread */ + pause_wifi_scan_thread(); + + + wifi_machine_state = get_wifi_machine_state(); + if(wifi_machine_state != CONNECTED_STATE && wifi_machine_state != DISCONNECTED_STATE){ + ret = -1; + event_code = WIFIMG_DEV_BUSING_EVENT; + goto end; + } + + + /* check network exist in wpa_supplicant.conf */ + if(wpa_conf_network_info_exist() == 0){ + ret = -1; + event_code = WIFIMG_NO_NETWORK_CONNECTING; + goto end; + } + + /*disconnect*/ + wifi_machine_state = get_wifi_machine_state(); + if(wifi_machine_state == CONNECTED_STATE){ + ret = wpa_conf_get_ap_connected(connectedId, &idSize); + LOG_EX(LOG_Debug, "---Get connected ap code = %d,netId is %s\r\n",ret,connectedId); + if(0 <= ret) + { + ret = wpa_conf_add_on_priority_list_hdr(connectedId); + if(0 == ret) + { + aw_wifi_disconnect_ap(0x7fffffff); + } + } + } + + /* connecting */ + set_wifi_machine_state(CONNECTING_STATE); + + netid_connecting[0] = '\0'; + disconnecting = 0; + connecting_ap_event_label = event_label; + + + pause_wifi_scan_thread(); + + /* reconnected */ + sprintf(cmd, "%s", "RECONNECT"); + ret = wifi_command(cmd, reply, sizeof(reply)); + if(ret){ + LOG_EX(LOG_Debug, "do reconnect error!\n"); + ret = -1; + event_code = WIFIMG_CMD_OR_PARAMS_ERROR; + } + + /* check timeout */ + start_check_connect_timeout(0); +end: + if(ret != 0){ + call_event_callback_function(event_code, NULL, event_label); + } + + /* resume scan thread */ + if(0 != ret)resume_wifi_scan_thread(); + + return ret; +} + /* *Ap with certain key_mgmt exists in the .conf file:return is 0, get the *net_id as expectation; *else:return -1 @@ -1506,8 +1632,11 @@ static const aw_wifi_interface_t aw_wifi_interface = { aw_wifi_disconnect_ap, aw_wifi_remove_network, aw_wifi_remove_all_networks, + aw_wifi_reconfig, aw_wifi_list_networks, aw_wifi_get_netid, + aw_wifi_change_ap, + aw_wifi_enble_all_network, aw_wifi_stop_scan, aw_wifi_restart_scan }; @@ -1523,13 +1652,13 @@ const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label ret = wifi_connect_to_supplicant(); if(ret){ - wmg_printf(MSG_DEBUG,"wpa_suppplicant not running!\n"); + LOG_EX(LOG_Debug, "wpa_suppplicant not running!\n"); wifi_start_supplicant(0); do{ usleep(300000); ret = wifi_connect_to_supplicant(); if(!ret){ - wmg_printf(MSG_DEBUG,"Connected to wpa_supplicant!\n"); + LOG_EX(LOG_Debug, "Connected to wpa_supplicant!\n"); break; } i++; @@ -1537,7 +1666,7 @@ const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label if(ret < 0){ if(pcb != NULL){ pcb(WIFIMG_WIFI_ON_FAILED, NULL, event_label); - wmg_printf(MSG_ERROR,"connect wpa_supplicant failed,please check wifi driver!\n"); + LOG_EX(LOG_Debug, "connect wpa_supplicant failed,please check wifi driver!\n"); } return NULL; } @@ -1617,7 +1746,7 @@ int aw_wifi_get_wifi_state() /* check wifi already on by self process or other process */ ret = wifi_connect_to_supplicant(); if(ret){ - wmg_printf(MSG_ERROR,"WiFi not on\n"); + LOG_EX(LOG_Debug, "WiFi not on\n"); return WIFIMG_WIFI_DISABLED; } diff --git a/package/allwinner/wifimanager/src/wpa_supplicant_conf.c b/package/allwinner/wifimanager/src/wpa_supplicant_conf.c index 96986c903..4a0fba88b 100755 --- a/package/allwinner/wifimanager/src/wpa_supplicant_conf.c +++ b/package/allwinner/wifimanager/src/wpa_supplicant_conf.c @@ -1,10 +1,13 @@ #include #include #include +#include #include "wpa_supplicant_conf.h" #include "wifi.h" -#include "wmg_debug.h" + +#define WPA_DIASBLE_NETWORK_CMD "DISABLE_NETWORK" +#define WPA_INTERNET_RECONNECT_SAVE 1 extern int is_ip_exist(); @@ -40,7 +43,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]){ - wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n"); + LOG_EX(LOG_Debug, "Error: ssid is NULL!\n"); return -1; } @@ -55,10 +58,12 @@ 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){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } + //LOG_EX(LOG_Debug, "List network:%s\r\n",reply) + ptr = reply; while((pssid_start=strstr(ptr, ssid)) != NULL){ char *p_s=NULL, *p_e=NULL, *p=NULL; @@ -101,12 +106,12 @@ 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){ - wmg_printf(MSG_ERROR,"do get network %s key_mgmt error!\n", net_id); + LOG_EX(LOG_Debug, "do get network %s key_mgmt error!\n", net_id); return -1; } - wmg_printf(MSG_DEBUG,"GET_NETWORK %s key_mgmt reply %s\n", net_id, key_reply); - wmg_printf(MSG_DEBUG,"key type %s\n", key_type); + LOG_EX(LOG_Debug, "GET_NETWORK %s key_mgmt reply %s\n", net_id, key_reply); + LOG_EX(LOG_Debug, "key type %s\n", key_type); if(strcmp(key_reply, key_type) == 0){ flag += 1; @@ -148,7 +153,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){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -194,7 +199,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){ - wmg_printf(MSG_ERROR,"do get network %s key_mgmt error!\n", net_id); + LOG_EX(LOG_Debug, "do get network %s key_mgmt error!\n", net_id); return -1; } @@ -235,7 +240,7 @@ int wpa_conf_get_max_priority() cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -253,7 +258,7 @@ int wpa_conf_get_max_priority() sprintf(cmd, "GET_NETWORK %s priority", net_id); ret = wifi_command(cmd, priority, sizeof(priority)); if(ret){ - wmg_printf(MSG_ERROR,"do get network priority error!\n"); + LOG_EX(LOG_Debug, "do get network priority error!\n"); return -1; } @@ -268,6 +273,278 @@ 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; + 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 selectPri=0; + int thisPri=0; + + sprintf(cmd, "GET_NETWORK %s priority", netId); + ret = wifi_command(cmd, priority, sizeof(priority)); + if(ret){ + LOG_EX(LOG_Debug, "do get network priority error!\n"); + return -1; + } + + selectPri = atoi(priority); + LOG_EX(LOG_Debug, "--selcect netid= %s,priority = %d\r\n",netId,selectPri); + + /* 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'; + } + } + + 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(net_id) == atoi(netId)) + { + selectPri = atoi(priority); + sprintf(cmd,"SET_NETWORK %s priority 0",net_id); + ret = wifi_command(cmd, reply, sizeof(reply)); + if(ret){ + LOG_EX(LOG_Debug, "do set priority error!\n"); + } + }else + { + + thisPri = atoi(priority); + if(thisPri < selectPri) + { + thisPri++; + sprintf(cmd,"SET_NETWORK %s priority %d", net_id, thisPri); + ret = wifi_command(cmd, reply, sizeof(reply)); + if(ret){ + LOG_EX(LOG_Debug, "do set priority error!\n"); + } + } + } + p_n = strchr(p_n, '\n'); + } + +#if WPA_INTERNET_RECONNECT_SAVE + /* 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; + } +#endif + + return 0; +} + + + + + int wpa_conf_is_ap_connected(char *ssid, int *len) { int ret = -1; @@ -282,10 +559,11 @@ int wpa_conf_is_ap_connected(char *ssid, int *len) ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "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){ @@ -336,7 +614,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){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -382,7 +660,7 @@ int wpa_conf_get_ap_connected(char *netid, int *len) ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -424,7 +702,7 @@ int wpa_conf_enable_all_networks() cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -443,7 +721,7 @@ int wpa_conf_enable_all_networks() sprintf(cmd, "ENABLE_NETWORK %s", net_id); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do enable network %s error!\n", net_id); + LOG_EX(LOG_Debug, "do enable network %s error!\n", net_id); return -1; } @@ -454,13 +732,38 @@ int wpa_conf_enable_all_networks() sprintf(cmd, "%s", "SAVE_CONFIG"); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do save config error!\n"); + LOG_EX(LOG_Debug, "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; @@ -474,7 +777,7 @@ int wpa_conf_remove_all_networks() cmd[CMD_LEN] = '\0'; ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do list networks error!\n"); + LOG_EX(LOG_Debug, "do list networks error!\n"); return -1; } @@ -493,7 +796,7 @@ int wpa_conf_remove_all_networks() sprintf(cmd, "REMOVE_NETWORK %s", net_id); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do remove network %s error!\n", net_id); + LOG_EX(LOG_Debug, "do remove network %s error!\n", net_id); return -1; } @@ -504,7 +807,7 @@ int wpa_conf_remove_all_networks() sprintf(cmd, "%s", "SAVE_CONFIG"); ret = wifi_command(cmd, reply, sizeof(reply)); if(ret){ - wmg_printf(MSG_ERROR,"do save config error!\n"); + LOG_EX(LOG_Debug, "do save config error!\n"); return -1; } diff --git a/package/allwinner/wifimanager/udhcpc_wlan0.init b/package/allwinner/wifimanager/udhcpc_wlan0.init index ea650b481..ef308373c 100755 --- a/package/allwinner/wifimanager/udhcpc_wlan0.init +++ b/package/allwinner/wifimanager/udhcpc_wlan0.init @@ -12,7 +12,13 @@ start_service() { if ps | grep [u]dhcpc; then killall -q -KILL udhcpc fi - procd_set_param command $PROG -i wlan0 -h When_you_like_AW -S -T 10 + if [ -n "$1" ] + then + procd_set_param command $PROG -i wlan0 -h When_you_like_AW -S -T 1 + else +# host_name=`cat /mnt/UDISK/bt/bt_config.xml | grep local` + procd_set_param command $PROG -i wlan0 -h "SING-PV2" -S -T 1 + fi procd_close_instance } diff --git a/package/allwinner/wifimanager/wifi.init b/package/allwinner/wifimanager/wifi.init index eb7b30564..62596b82b 100755 --- a/package/allwinner/wifimanager/wifi.init +++ b/package/allwinner/wifimanager/wifi.init @@ -7,6 +7,12 @@ STOP=99 USE_PROCD=1 PROG=wpa_supplicant OOM_ADJ=-17 +#CFG_FILE=/etc/wifi/wpa_supplicant.conf +#CFG_FILE_ADD=/etc/wifi/wpa_supplicant_overlay.conf +#CTR_INTERFACE=/etc/wifi/sockets +CFG_FILE=/mnt/UDISK/wifi/wpa_supplicant.conf +CFG_FILE_ADD=/mnt/UDISK/wifi/wpa_supplicant_overlay.conf +CTR_INTERFACE=/mnt/UDISK/wifi/sockets start_service() { procd_open_instance @@ -16,7 +22,7 @@ start_service() { fi ifconfig wlan0 up procd_set_param oom_adj $OOM_ADJ - procd_set_param command $PROG -iwlan0 -Dnl80211 -c/etc/wifi/wpa_supplicant.conf -I/etc/wifi/wpa_supplicant_overlay.conf -O/etc/wifi/sockets + procd_set_param command $PROG -iwlan0 -Dnl80211 -c$CFG_FILE -I$CFG_FILE_ADD -O$CTR_INTERFACE procd_close_instance } diff --git a/target/allwinner/mandolin-perf1/defconfig b/target/allwinner/mandolin-perf1/defconfig index 2dee91d7b..6c0d30983 100644 --- a/target/allwinner/mandolin-perf1/defconfig +++ b/target/allwinner/mandolin-perf1/defconfig @@ -1334,7 +1334,7 @@ CONFIG_PACKAGE_ubusd=y CONFIG_PACKAGE_uci=y # CONFIG_PACKAGE_udev is not set # CONFIG_PACKAGE_usign is not set -# CONFIG_PACKAGE_wireless-tools is not set +CONFIG_PACKAGE_wireless-tools=y # CONFIG_PACKAGE_zram-swap is not set # @@ -1468,6 +1468,7 @@ CONFIG_PACKAGE_softap=y # CONFIG_PACKAGE_usb-gadget is not set CONFIG_PACKAGE_wifimanager=y CONFIG_PACKAGE_wifimanager-demo=y +CONFIG_PACKAGE_wifimanager-smartaudio=y # # avs @@ -3388,7 +3389,7 @@ CONFIG_PACKAGE_alsa-utils=y # CONFIG_PACKAGE_cpulimit-ng is not set # CONFIG_PACKAGE_cxdish is not set CONFIG_PACKAGE_dbus=y -# CONFIG_PACKAGE_dbus-utils is not set +CONFIG_PACKAGE_dbus-utils=y # CONFIG_PACKAGE_directfb-examples is not set # CONFIG_PACKAGE_dmesg is not set # CONFIG_PACKAGE_dropbearconvert is not set