Merge branch 'master' of ssh://g.hz.netease.com:22222/IoT/PV2/SmartAudioPV2
This commit is contained in:
commit
8e260d9fb8
|
@ -1,4 +1,6 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
include $(TINA_BUILD_TOP)/package/netease/Makefile.common
|
||||||
|
|
||||||
|
|
||||||
PKG_NAME:=wifimanager
|
PKG_NAME:=wifimanager
|
||||||
PKG_VERSION:=0.0.1
|
PKG_VERSION:=0.0.1
|
||||||
|
@ -10,7 +12,7 @@ define Package/wifimanager/Default
|
||||||
SECTION:=utils
|
SECTION:=utils
|
||||||
CATEGORY:=Allwinner
|
CATEGORY:=Allwinner
|
||||||
TITLE:=Tina wifi manager
|
TITLE:=Tina wifi manager
|
||||||
DEPENDS:=+libpthread +libstdcpp +liballwinner-base
|
DEPENDS:=+libpthread +libstdcpp +liballwinner-base +libiconv-full $(MAKE_COMMON_DEPEND)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Package/wifimanager
|
define Package/wifimanager
|
||||||
|
@ -22,7 +24,13 @@ endef
|
||||||
define Package/wifimanager-demo
|
define Package/wifimanager-demo
|
||||||
$(call Package/wifimanager/Default)
|
$(call Package/wifimanager/Default)
|
||||||
TITLE:=Tina wifi app demo
|
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
|
endef
|
||||||
|
|
||||||
define Package/wifimanager/description
|
define Package/wifimanager/description
|
||||||
|
@ -37,6 +45,7 @@ define Build/Prepare
|
||||||
mkdir -p $(PKG_BUILD_DIR)
|
mkdir -p $(PKG_BUILD_DIR)
|
||||||
$(CP) -r ./src $(PKG_BUILD_DIR)/
|
$(CP) -r ./src $(PKG_BUILD_DIR)/
|
||||||
$(CP) -r ./demo $(PKG_BUILD_DIR)/
|
$(CP) -r ./demo $(PKG_BUILD_DIR)/
|
||||||
|
$(CP) -r ./smartaudio $(PKG_BUILD_DIR)/
|
||||||
endef
|
endef
|
||||||
|
|
||||||
define Build/Configure
|
define Build/Configure
|
||||||
|
@ -86,6 +95,23 @@ define Package/wifimanager/install
|
||||||
$(INSTALL_BIN) ./udhcpc_wlan0.init $(1)/etc/wifi/udhcpc_wlan0
|
$(INSTALL_BIN) ./udhcpc_wlan0.init $(1)/etc/wifi/udhcpc_wlan0
|
||||||
endef
|
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
|
define Package/wifimanager-demo/install
|
||||||
$(INSTALL_DIR) $(1)/bin
|
$(INSTALL_DIR) $(1)/bin
|
||||||
$(INSTALL_DIR) $(1)/etc/wifi
|
$(INSTALL_DIR) $(1)/etc/wifi
|
||||||
|
@ -106,3 +132,4 @@ endef
|
||||||
|
|
||||||
$(eval $(call BuildPackage,wifimanager))
|
$(eval $(call BuildPackage,wifimanager))
|
||||||
$(eval $(call BuildPackage,wifimanager-demo))
|
$(eval $(call BuildPackage,wifimanager-demo))
|
||||||
|
$(eval $(call BuildPackage,wifimanager-smartaudio))
|
||||||
|
|
|
@ -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
|
target = wifi_connect_ap_test
|
||||||
|
|
||||||
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \
|
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \
|
||||||
|
@ -7,69 +10,71 @@ CPP_SRCS = wifi_connect_ap.cpp
|
||||||
CPP_OBJS := $(CPP_SRCS:.cpp=.o)
|
CPP_OBJS := $(CPP_SRCS:.cpp=.o)
|
||||||
LIB_OBJS = $(CPP_OBJS)
|
LIB_OBJS = $(CPP_OBJS)
|
||||||
|
|
||||||
|
local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -liconv
|
||||||
|
|
||||||
install:
|
install:
|
||||||
-@mkdir -p $(CONFIG_PREFIX)/usr/bin
|
-@mkdir -p $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_on_off_test
|
#wifi_on_off_test
|
||||||
wifi_on_off_test: wifi_on_off_test.c
|
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
|
@cp -f wifi_on_off_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_connect_chinese_ap_test
|
#wifi_connect_chinese_ap_test
|
||||||
wifi_connect_chinese_ap_test: wifi_connect_chinese_ap.c
|
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
|
@cp -f wifi_connect_chinese_ap_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_scan_results_test
|
#wifi_scan_results_test
|
||||||
wifi_scan_results_test: wifi_scan_results.c
|
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
|
@cp -f wifi_scan_results_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_list_networks_test
|
#wifi_list_networks_test
|
||||||
wifi_list_networks_test: wifi_list_networks.c
|
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
|
@cp -f wifi_list_networks_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_remove_network_test
|
#wifi_remove_network_test
|
||||||
wifi_remove_network_test: wifi_remove_network.c
|
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
|
@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_test: wifi_connect_ap_with_netid.c
|
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
|
@cp -f wifi_connect_ap_with_netid_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_get_netid_test
|
#wifi_get_netid_test
|
||||||
wifi_get_netid_test: wifi_get_netid.c
|
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
|
@cp -f wifi_get_netid_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_add_network_test
|
#wifi_add_network_test
|
||||||
wifi_add_network_test: wifi_add_network.c
|
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
|
@cp -f wifi_add_network_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_longtime_test
|
#wifi_longtime_test
|
||||||
wifi_longtime_test: wifi_longtime_test.c
|
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
|
@cp -f wifi_longtime_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_stop_restart_scan_test
|
#wifi_stop_restart_scan_test
|
||||||
wifi_stop_restart_scan_test: wifi_stop_restart_scan_test.c
|
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
|
@cp -f wifi_stop_restart_scan_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_connect_ap_test
|
#wifi_connect_ap_test
|
||||||
$(CPP_OBJS): %.o: %.cpp
|
$(CPP_OBJS): %.o: %.cpp
|
||||||
$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
$(CXX) $(CFLAGS) $(INCLUDES) -c -o $@ $<
|
||||||
$(target): $(LIB_OBJS)
|
$(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
|
@cp -f $(target) $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
#wifi_remove_all_networks_test
|
#wifi_remove_all_networks_test
|
||||||
wifi_remove_all_networks_test: wifi_remove_all_networks.c
|
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
|
@cp -f wifi_remove_all_networks_test $(CONFIG_PREFIX)/usr/bin
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
|
@ -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)
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,13 @@
|
||||||
include $(TOPDIR)/rules.mk
|
include $(TOPDIR)/rules.mk
|
||||||
|
include $(TINA_BUILD_TOP)/package/netease/Makefile.common
|
||||||
|
include $(TINA_BUILD_TOP)/build/nls.mk
|
||||||
include $(BUILD_DIR)/package.mk
|
include $(BUILD_DIR)/package.mk
|
||||||
|
|
||||||
target = libwifimg.so
|
target = libwifimg.so
|
||||||
|
|
||||||
INCLUDES += -I. -I./include
|
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 \
|
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
|
wifi.c wpa_supplicant_conf.c udhcpc_thread.c tool.c wmg_debug.c
|
||||||
|
@ -25,7 +28,7 @@ else
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
$(target): $(SRCS)
|
$(target): $(SRCS)
|
||||||
$(CC) -fPIC -shared $(INCLUDES) $(LDFLAGS) $^ -o $@ $(LIBS)
|
$(CC) -fPIC -shared $(INCLUDES) $(LDFLAGS) $(local_LDFLAGS) $^ -o $@ $(LIBS)
|
||||||
@cp $@ $(CONFIG_PREFIX)/usr/lib
|
@cp $@ $(CONFIG_PREFIX)/usr/lib
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
|
|
|
@ -146,7 +146,12 @@ int wifi_change_fw_path(const char *fwpath);
|
||||||
/**
|
/**
|
||||||
* Check and create if necessary initial entropy file
|
* Check and create if necessary initial entropy file
|
||||||
*/
|
*/
|
||||||
|
#if 0
|
||||||
#define WIFI_ENTROPY_FILE "/data/misc/wifi/entropy.bin"
|
#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();
|
int ensure_entropy_file_exists();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -46,6 +46,7 @@ int get_assoc_reject_count();
|
||||||
int add_wifi_event_callback_inner(tWifi_event_callback pcb);
|
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 call_event_callback_function(tWIFI_EVENT wifi_event, char *buf, int event_label);
|
||||||
int reset_wifi_event_callback();
|
int reset_wifi_event_callback();
|
||||||
|
void stop_connecting();
|
||||||
#if __cplusplus
|
#if __cplusplus
|
||||||
}; // extern "C"
|
}; // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,10 +58,13 @@ typedef struct{
|
||||||
int (*disconnect_ap)(int event_label);
|
int (*disconnect_ap)(int event_label);
|
||||||
int (*remove_network)(char *ssid, tKEY_MGMT key_mgmt);
|
int (*remove_network)(char *ssid, tKEY_MGMT key_mgmt);
|
||||||
int (*remove_all_networks)(void);
|
int (*remove_all_networks)(void);
|
||||||
|
int (*re_config)(void);
|
||||||
int (*list_networks)(char *reply, size_t reply_len, int event_label);
|
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_netid)(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *length);
|
||||||
int (*stop_scan)();
|
int (*stop_scan)();
|
||||||
int (*restart_scan)();
|
int (*restart_scan)();
|
||||||
|
int (*change_ap)(int event_label );
|
||||||
|
int (*enable_all_network)(void);
|
||||||
}aw_wifi_interface_t;
|
}aw_wifi_interface_t;
|
||||||
|
|
||||||
const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label);
|
const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label);
|
||||||
|
|
|
@ -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_get_ap_connected(char *netid, int *len);
|
||||||
int wpa_conf_enable_all_networks();
|
int wpa_conf_enable_all_networks();
|
||||||
int wpa_conf_remove_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
|
#if __cplusplus
|
||||||
}; // extern "C"
|
}; // extern "C"
|
||||||
|
|
|
@ -5,14 +5,20 @@
|
||||||
#include<pthread.h>
|
#include<pthread.h>
|
||||||
#include<sys/time.h>
|
#include<sys/time.h>
|
||||||
|
|
||||||
|
#include <uvdbus/log.h>
|
||||||
|
|
||||||
#include "wifi_event.h"
|
#include "wifi_event.h"
|
||||||
#include "network_manager.h"
|
#include "network_manager.h"
|
||||||
#include "wifi_intf.h"
|
#include "wifi_intf.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "wmg_debug.h"
|
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
#define WAITING_CLK_COUNTS 50
|
#define WAITING_CLK_COUNTS 50
|
||||||
#define SSID_LEN 512
|
#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 */
|
/* 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)
|
void print_wpa_status(struct wpa_status *wpa_sta)
|
||||||
{
|
{
|
||||||
wmg_printf(MSG_DEBUG,"obtained wpa_supplicant status,as follow:\n");
|
LOG_EX(LOG_Debug, "obtained wpa_supplicant status,as follow:\n");
|
||||||
wmg_printf(MSG_DEBUG,"==============================\n");
|
LOG_EX(LOG_Debug, "==============================\n");
|
||||||
if(wpa_sta->id >= 0)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
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)
|
if(wpa_sta->mac_address)
|
||||||
wmg_printf(MSG_DEBUG,"mac_address:%s\n",wpa_sta->mac_address);
|
LOG_EX(LOG_Debug, "mac_address:%s\n",wpa_sta->mac_address);
|
||||||
wmg_printf(MSG_DEBUG,"==============================\n");
|
LOG_EX(LOG_Debug, "==============================\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *strstr_wpa(const char *src,const char *obj,
|
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 length;
|
||||||
int i=0;
|
int i=0;
|
||||||
if(src == NULL || obj == NULL || pre_str ==NULL){
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(pst_len > strlen(pre_str)){
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
length = strlen(obj);
|
length = strlen(obj);
|
||||||
for(;;p++,i++){
|
for(;;p++,i++){
|
||||||
p=strchr(p,*obj);
|
p=strchr(p,*obj);
|
||||||
if(p == NULL){
|
if(p == NULL){
|
||||||
wmg_printf(MSG_MSGDUMP,"%s is not exist",obj);
|
LOG_EX(LOG_Debug, "%s is not exist",obj);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if(strncmp(p,obj,length) == 0){
|
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){
|
while(1){
|
||||||
i++;
|
i++;
|
||||||
if(i >max ){
|
if(i >max ){
|
||||||
wmg_printf(MSG_ERROR,"Data overflow");
|
LOG_EX(LOG_Debug, "Data overflow");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
pnext++;
|
pnext++;
|
||||||
|
@ -195,7 +201,7 @@ static struct wpa_status* wpa_status_init()
|
||||||
if(gstatus == NULL)
|
if(gstatus == NULL)
|
||||||
gstatus = (struct wpa_status *)wgos_zalloc(sizeof(struct wpa_status));
|
gstatus = (struct wpa_status *)wgos_zalloc(sizeof(struct wpa_status));
|
||||||
if(gstatus == NULL){
|
if(gstatus == NULL){
|
||||||
wmg_printf(MSG_WARNING,"MALLOC STATUS STRUCT FAILED!\n");
|
LOG_EX(LOG_Debug, "MALLOC STATUS STRUCT FAILED!\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
gstatus->id = -1;
|
gstatus->id = -1;
|
||||||
|
@ -254,7 +260,7 @@ int update_scan_results()
|
||||||
{
|
{
|
||||||
int i=0;
|
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);
|
pthread_mutex_lock(&thread_run_mutex);
|
||||||
scan_completed = 0;
|
scan_completed = 0;
|
||||||
|
@ -383,6 +389,73 @@ int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt)
|
||||||
return ret;
|
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[])
|
int get_key_mgmt(const char *ssid, int key_mgmt_info[])
|
||||||
{
|
{
|
||||||
char *ptr = NULL, *pssid_start = NULL, *pssid_end = NULL;
|
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];
|
char flag[128], pssid[SSID_LEN + 1];
|
||||||
int len = 0, i = 0;
|
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_NONE_INDEX] = 0;
|
||||||
key_mgmt_info[KEY_WEP_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');
|
ptr = strchr(scan_results, '\n');
|
||||||
if(!ptr){
|
if(!ptr){
|
||||||
pthread_mutex_unlock(&scan_mutex);
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +511,7 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[])
|
||||||
len = len - 1;
|
len = len - 1;
|
||||||
strncpy(flag, pflag, len);
|
strncpy(flag, pflag, len);
|
||||||
flag[len] = '\0';
|
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)
|
if((strstr(flag, "WPA-PSK-") != NULL)
|
||||||
|| (strstr(flag, "WPA2-PSK-") != NULL)){
|
|| (strstr(flag, "WPA2-PSK-") != NULL)){
|
||||||
key_mgmt_info[KEY_WPA_PSK_INDEX] = 1;
|
key_mgmt_info[KEY_WPA_PSK_INDEX] = 1;
|
||||||
|
@ -515,14 +588,14 @@ void *wifi_scan_thread(void *args)
|
||||||
usleep(100*1000);
|
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){
|
if(get_scan_status() == 1){
|
||||||
strncpy(cmd, "SCAN_RESULTS", 15);
|
strncpy(cmd, "SCAN_RESULTS", 15);
|
||||||
cmd[15] = '\0';
|
cmd[15] = '\0';
|
||||||
ret = wifi_command(cmd, scan_results, sizeof(scan_results));
|
ret = wifi_command(cmd, scan_results, sizeof(scan_results));
|
||||||
if(ret){
|
if(ret){
|
||||||
scan_error = 1;
|
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);
|
pthread_mutex_unlock(&scan_mutex);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <arpa/inet.h>
|
#include <arpa/inet.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <uvdbus/log.h>
|
||||||
|
|
||||||
#include "wifi_event.h"
|
#include "wifi_event.h"
|
||||||
#include "wifi_state_machine.h"
|
#include "wifi_state_machine.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "wmg_debug.h"
|
|
||||||
|
|
||||||
extern int disconnecting;
|
extern int disconnecting;
|
||||||
extern int connecting_ap_event_label;
|
extern int connecting_ap_event_label;
|
||||||
|
@ -83,13 +83,13 @@ void *udhcpc_thread(void *args)
|
||||||
times++;
|
times++;
|
||||||
}while((vflag == 0) && (times < 310));
|
}while((vflag == 0) && (times < 310));
|
||||||
|
|
||||||
wmg_printf(MSG_DEBUG,"vflag= %d\n",vflag);
|
LOG_EX(LOG_Debug, "vflag= %d\n",vflag);
|
||||||
if(vflag != 0){
|
if(vflag != 0){
|
||||||
set_wifi_machine_state(CONNECTED_STATE);
|
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);
|
call_event_callback_function(WIFIMG_NETWORK_CONNECTED, NULL, connecting_ap_event_label);
|
||||||
}else{
|
}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 */
|
/* stop dhcpc thread */
|
||||||
system("/etc/wifi/udhcpc_wlan0 stop");
|
system("/etc/wifi/udhcpc_wlan0 stop");
|
||||||
|
|
||||||
|
@ -111,5 +111,10 @@ void *udhcpc_thread(void *args)
|
||||||
void start_udhcpc_thread(void *args)
|
void start_udhcpc_thread(void *args)
|
||||||
{
|
{
|
||||||
pthread_t thread_id;
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,21 +11,41 @@
|
||||||
#include "wpa_ctrl.h"
|
#include "wpa_ctrl.h"
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <uvdbus/log.h>
|
||||||
#include "tool.h"
|
#include "tool.h"
|
||||||
#define IFACE_VALUE_MAX 32
|
#define IFACE_VALUE_MAX 32
|
||||||
|
|
||||||
static struct wpa_ctrl *ctrl_conn;
|
static struct wpa_ctrl *ctrl_conn;
|
||||||
static struct wpa_ctrl *monitor_conn;
|
static struct wpa_ctrl *monitor_conn;
|
||||||
|
pthread_mutex_t ctrl_mutex;
|
||||||
|
|
||||||
/* socket pair used to exit from a blocking read */
|
/* socket pair used to exit from a blocking read */
|
||||||
static int exit_sockets[2];
|
static int exit_sockets[2];
|
||||||
|
|
||||||
//static const char IFACE_DIR[] = "/data/misc/wifi/sockets";
|
//static const char IFACE_DIR[] = "/data/misc/wifi/sockets";
|
||||||
|
#if 0
|
||||||
static const char IFACE_DIR[] = "/etc/wifi/sockets";
|
static const char IFACE_DIR[] = "/etc/wifi/sockets";
|
||||||
static char primary_iface[IFACE_VALUE_MAX];
|
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 SUPP_CONFIG_FILE[] = "/etc/wifi/wpa_supplicant.conf";
|
||||||
static const char CONTROL_IFACE_PATH[] = "/etc/wifi/sockets";
|
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 const char SUPP_ENTROPY_FILE[] = WIFI_ENTROPY_FILE;
|
||||||
static unsigned char dummy_key[21] = { 0x02, 0x11, 0xbe, 0x33, 0x43, 0x35,
|
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)
|
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));
|
modname, strerror(errno));
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -106,7 +126,7 @@ int wifi_load_driver(const char *path, const char *args)
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
|
|
||||||
if (!path) {
|
if (!path) {
|
||||||
wmg_printf(MSG_ERROR,"driver path is NULL!\n");
|
LOG_EX(LOG_Debug, "driver path is NULL!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,10 +143,10 @@ int wifi_load_driver(const char *path, const char *args)
|
||||||
p_s++;
|
p_s++;
|
||||||
}
|
}
|
||||||
name[i] = '\0';
|
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) {
|
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.
|
rmmod(name);//it may be load driver already,try remove it.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -134,17 +154,17 @@ int wifi_load_driver(const char *path, const char *args)
|
||||||
do{
|
do{
|
||||||
fp=fopen("/proc/net/wireless", "r");
|
fp=fopen("/proc/net/wireless", "r");
|
||||||
if (!fp) {
|
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.
|
rmmod(name); //try remove it.
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
ret = fread(tmp_buf, sizeof(tmp_buf), 1, fp);
|
ret = fread(tmp_buf, sizeof(tmp_buf), 1, fp);
|
||||||
if (ret==0){
|
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);
|
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");
|
p_strstr_wlan = strstr(tmp_buf, "wlan0");
|
||||||
if (p_strstr_wlan != NULL) {
|
if (p_strstr_wlan != NULL) {
|
||||||
break;
|
break;
|
||||||
|
@ -154,7 +174,7 @@ int wifi_load_driver(const char *path, const char *args)
|
||||||
} while (count++ <= TIME_COUNT);
|
} while (count++ <= TIME_COUNT);
|
||||||
|
|
||||||
if(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);
|
rmmod(name);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -179,19 +199,19 @@ int ensure_entropy_file_exists()
|
||||||
if ((ret == 0) || (errno == EACCES)) {
|
if ((ret == 0) || (errno == EACCES)) {
|
||||||
if ((ret != 0) &&
|
if ((ret != 0) &&
|
||||||
(chmod(SUPP_ENTROPY_FILE, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 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 -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
destfd = TEMP_FAILURE_RETRY(open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660));
|
destfd = TEMP_FAILURE_RETRY(open(SUPP_ENTROPY_FILE, O_CREAT|O_RDWR, 0660));
|
||||||
if (destfd < 0) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TEMP_FAILURE_RETRY(write(destfd, dummy_key, sizeof(dummy_key))) != sizeof(dummy_key)) {
|
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);
|
close(destfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -199,7 +219,7 @@ int ensure_entropy_file_exists()
|
||||||
|
|
||||||
/* chmod is needed because open() didn't set permisions properly */
|
/* chmod is needed because open() didn't set permisions properly */
|
||||||
if (chmod(SUPP_ENTROPY_FILE, 0660) < 0) {
|
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));
|
SUPP_ENTROPY_FILE, strerror(errno));
|
||||||
unlink(SUPP_ENTROPY_FILE);
|
unlink(SUPP_ENTROPY_FILE);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -226,14 +246,14 @@ int update_ctrl_interface(const char *config_file) {
|
||||||
return 0;
|
return 0;
|
||||||
srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
|
srcfd = TEMP_FAILURE_RETRY(open(config_file, O_RDONLY));
|
||||||
if (srcfd < 0) {
|
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);
|
free(pbuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
|
nread = TEMP_FAILURE_RETRY(read(srcfd, pbuf, sb.st_size));
|
||||||
close(srcfd);
|
close(srcfd);
|
||||||
if (nread < 0) {
|
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);
|
free(pbuf);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -261,7 +281,7 @@ int update_ctrl_interface(const char *config_file) {
|
||||||
int mlen = strlen(ifc);
|
int mlen = strlen(ifc);
|
||||||
int nwrite;
|
int nwrite;
|
||||||
if (strncmp(ifc, iptr, mlen) != 0) {
|
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'))
|
while (((ilen + (iptr - pbuf)) < nread) && (iptr[ilen] != '\n'))
|
||||||
ilen++;
|
ilen++;
|
||||||
mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
|
mlen = ((ilen >= mlen) ? ilen : mlen) + 1;
|
||||||
|
@ -270,7 +290,7 @@ int update_ctrl_interface(const char *config_file) {
|
||||||
memcpy(iptr, ifc, strlen(ifc));
|
memcpy(iptr, ifc, strlen(ifc));
|
||||||
destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
|
destfd = TEMP_FAILURE_RETRY(open(config_file, O_RDWR, 0660));
|
||||||
if (destfd < 0) {
|
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);
|
free(pbuf);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -295,7 +315,7 @@ int ensure_config_file_exists(const char *config_file)
|
||||||
if ((ret == 0) || (errno == EACCES)) {
|
if ((ret == 0) || (errno == EACCES)) {
|
||||||
if ((ret != 0) &&
|
if ((ret != 0) &&
|
||||||
(chmod(config_file, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP) != 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 -1;
|
||||||
}
|
}
|
||||||
/* return if we were able to update control interface properly */
|
/* 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) {
|
} 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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
srcfd = TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY));
|
srcfd = TEMP_FAILURE_RETRY(open(SUPP_CONFIG_TEMPLATE, O_RDONLY));
|
||||||
if (srcfd < 0) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660));
|
destfd = TEMP_FAILURE_RETRY(open(config_file, O_CREAT|O_RDWR, 0660));
|
||||||
if (destfd < 0) {
|
if (destfd < 0) {
|
||||||
close(srcfd);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) {
|
while ((nread = TEMP_FAILURE_RETRY(read(srcfd, buf, sizeof(buf)))) != 0) {
|
||||||
if (nread < 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(srcfd);
|
||||||
close(destfd);
|
close(destfd);
|
||||||
unlink(config_file);
|
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 */
|
/* chmod is needed because open() didn't set permisions properly */
|
||||||
if (chmod(config_file, 0660) < 0) {
|
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));
|
config_file, strerror(errno));
|
||||||
unlink(config_file);
|
unlink(config_file);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -349,20 +369,109 @@ int ensure_config_file_exists(const char *config_file)
|
||||||
return update_ctrl_interface(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)
|
int wifi_start_supplicant(int p2p_supported)
|
||||||
{
|
{
|
||||||
char cmd[512] = {0};
|
char cmd[512] = {0};
|
||||||
|
|
||||||
|
|
||||||
|
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 */
|
/* Before starting the daemon, make sure its config file exists */
|
||||||
if (ensure_config_file_exists(SUPP_CONFIG_FILE) < 0) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ensure_entropy_file_exists() < 0) {
|
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. */
|
/* Clear out any stale socket files that might be left over. */
|
||||||
//wpa_ctrl_cleanup();
|
//wpa_ctrl_cleanup();
|
||||||
|
|
||||||
|
@ -396,7 +505,7 @@ int wifi_connect_on_socket_path(const char *path)
|
||||||
ctrl_conn = wpa_ctrl_open(path);
|
ctrl_conn = wpa_ctrl_open(path);
|
||||||
}
|
}
|
||||||
if (ctrl_conn == NULL) {
|
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));
|
path, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -442,13 +551,16 @@ int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
if (ctrl_conn == NULL) {
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = wpa_ctrl_request(ctrl_conn, cmd, strlen(cmd), reply, reply_len, NULL);
|
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) {
|
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 */
|
/* 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;
|
return -2;
|
||||||
|
@ -474,7 +586,7 @@ int wifi_ctrl_recv(char *reply, size_t *reply_len)
|
||||||
rfds[1].events |= POLLIN;
|
rfds[1].events |= POLLIN;
|
||||||
res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1));
|
res = TEMP_FAILURE_RETRY(poll(rfds, 2, -1));
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
wmg_printf(MSG_ERROR,"Error poll = %d\n", res);
|
LOG_EX(LOG_Debug, "Error poll = %d\n", res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
if (rfds[0].revents & POLLIN) {
|
if (rfds[0].revents & POLLIN) {
|
||||||
|
@ -505,14 +617,14 @@ int wifi_wait_on_socket(char *buf, size_t buflen)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (result < 0) {
|
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");
|
return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - recv error");
|
||||||
}
|
}
|
||||||
buf[nread] = '\0';
|
buf[nread] = '\0';
|
||||||
/* Check for EOF on the socket */
|
/* Check for EOF on the socket */
|
||||||
if (result == 0 && nread == 0) {
|
if (result == 0 && nread == 0) {
|
||||||
/* Fabricate an event to pass up */
|
/* 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");
|
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) {
|
if (match != NULL) {
|
||||||
nread -= (match + 1 - buf);
|
nread -= (match + 1 - buf);
|
||||||
memmove(buf, match + 1, nread + 1);
|
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 {
|
} else {
|
||||||
/* let the event go as is! */
|
/* 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;
|
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 wifi_command(char const *cmd, char *reply, size_t reply_len)
|
||||||
{
|
{
|
||||||
|
int ret =0;
|
||||||
if(!cmd || !cmd[0]){
|
if(!cmd || !cmd[0]){
|
||||||
return -1;
|
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.
|
--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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
pthread_mutex_unlock(&ctrl_mutex);
|
||||||
|
|
||||||
// Strip off trailing newline.
|
// Strip off trailing newline.
|
||||||
if (reply_len > 0 && reply[reply_len-1] == '\n') {
|
if (reply_len > 0 && reply[reply_len-1] == '\n') {
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
#include<unistd.h>
|
#include<unistd.h>
|
||||||
|
#include<uvdbus/log.h>
|
||||||
|
|
||||||
#include "wifi.h"
|
#include "wifi.h"
|
||||||
#include "wifi_event.h"
|
#include "wifi_event.h"
|
||||||
#include "wifi_state_machine.h"
|
#include "wifi_state_machine.h"
|
||||||
#include "wifi_intf.h"
|
#include "wifi_intf.h"
|
||||||
#include "wpa_supplicant_conf.h"
|
#include "wpa_supplicant_conf.h"
|
||||||
#include "wmg_debug.h"
|
|
||||||
|
|
||||||
//tWIFI_STATE gwifi_state;
|
//tWIFI_STATE gwifi_state;
|
||||||
tWIFI_STATE gwifi_state = WIFIMG_WIFI_DISABLED;
|
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
|
if((state == DISCONNECTING_STATE) //call disconnect
|
||||||
|| (state == L2CONNECTED_STATE) || (state == CONNECTED_STATE)) //auto disconnect(ap shutdown)
|
|| (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_wifi_machine_state(DISCONNECTED_STATE);
|
||||||
set_cur_wifi_event(AP_DISCONNECTED);
|
set_cur_wifi_event(AP_DISCONNECTED);
|
||||||
call_event_callback_function(WIFIMG_NETWORK_DISCONNECTED, NULL, disconnect_ap_event_label);
|
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'){
|
if(netid_connecting[0] != '\0'){
|
||||||
/* get already connected netid */
|
/* get already connected netid */
|
||||||
wpa_conf_get_ap_connected(netid_connected, &len);
|
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){
|
if(strcmp(netid_connected,netid_connecting) != 0){
|
||||||
/* send disconnect */
|
/* send disconnect */
|
||||||
sprintf(cmd, "%s", "DISCONNECT");
|
sprintf(cmd, "%s", "DISCONNECT");
|
||||||
|
@ -73,7 +73,7 @@ static void handle_event(int event, char * remainder) {
|
||||||
|
|
||||||
case NETWORK_NOT_FOUND:
|
case NETWORK_NOT_FOUND:
|
||||||
network_not_found_count++;
|
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){
|
if(network_not_found_count >= 3){
|
||||||
sprintf(cmd, "%s", "DISCONNECT");
|
sprintf(cmd, "%s", "DISCONNECT");
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
wifi_command(cmd, reply, sizeof(reply));
|
||||||
|
@ -96,10 +96,11 @@ static int dispatch_event(const char *event_str, int nread)
|
||||||
char *event_data = NULL;
|
char *event_data = NULL;
|
||||||
|
|
||||||
if(!event_str || !event_str[0]){
|
if(!event_str || !event_str[0]){
|
||||||
wmg_printf(MSG_WARNING,"event is NULL!\n");
|
LOG_EX(LOG_Debug, "event is NULL!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_EX(LOG_Debug, "event_str %s!!!!\n", event_str);
|
||||||
if(strncmp(event_str, "CTRL-EVENT-", 11)){
|
if(strncmp(event_str, "CTRL-EVENT-", 11)){
|
||||||
if (!strncmp(event_str, "WPA:", 4)){
|
if (!strncmp(event_str, "WPA:", 4)){
|
||||||
if (strstr(event_str, "pre-shared key may be incorrect")){
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ static int dispatch_event(const char *event_str, int nread)
|
||||||
}
|
}
|
||||||
event_name[i] = '\0';
|
event_name[i] = '\0';
|
||||||
} else {
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,6 +163,7 @@ static int dispatch_event(const char *event_str, int nread)
|
||||||
|
|
||||||
event_data = (char *)((unsigned long)event_str);
|
event_data = (char *)((unsigned long)event_str);
|
||||||
if(event == DRIVER_STATE || event == LINK_SPEED){
|
if(event == DRIVER_STATE || event == LINK_SPEED){
|
||||||
|
LOG_EX(LOG_Debug, "DRIVER_STATE or LINK_SPEED, not handle\n");
|
||||||
return 0;
|
return 0;
|
||||||
}else if(event == STATE_CHANGE || event == EAP_FAILURE){
|
}else if(event == STATE_CHANGE || event == EAP_FAILURE){
|
||||||
event_data = strchr(event_str, ' ');
|
event_data = strchr(event_str, ' ');
|
||||||
|
@ -176,18 +178,18 @@ static int dispatch_event(const char *event_str, int nread)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(event == STATE_CHANGE){
|
if(event == STATE_CHANGE){
|
||||||
wmg_printf(MSG_DEBUG,"STATE_CHANGE, no care!\n");
|
LOG_EX(LOG_Debug, "STATE_CHANGE, no care!\n");
|
||||||
return 0;
|
return 0;
|
||||||
} else if(event == DRIVER_STATE){
|
} 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;
|
return 0;
|
||||||
}else if(event == TERMINATING){
|
}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;
|
gwifi_state = WIFIMG_WIFI_DISABLED;
|
||||||
call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0);
|
call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0);
|
||||||
return 1;
|
return 1;
|
||||||
}else if(event == EAP_FAILURE){
|
}else if(event == EAP_FAILURE){
|
||||||
wmg_printf(MSG_ERROR,"EAP FAILURE!\n");
|
LOG_EX(LOG_Debug, "EAP FAILURE!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}else if(event == ASSOC_REJECT){
|
}else if(event == ASSOC_REJECT){
|
||||||
assoc_reject_count++;
|
assoc_reject_count++;
|
||||||
|
@ -196,7 +198,7 @@ static int dispatch_event(const char *event_str, int nread)
|
||||||
sprintf(cmd, "%s", "DISCONNECT");
|
sprintf(cmd, "%s", "DISCONNECT");
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
wifi_command(cmd, reply, sizeof(reply));
|
||||||
}
|
}
|
||||||
wmg_printf(MSG_ERROR,"ASSOC REJECT!\n");
|
LOG_EX(LOG_Debug, "ASSOC REJECT!\n");
|
||||||
return 0;
|
return 0;
|
||||||
}else{
|
}else{
|
||||||
handle_event(event, event_data);
|
handle_event(event, event_data);
|
||||||
|
@ -259,13 +261,13 @@ void *check_connect_timeout(void *args)
|
||||||
|
|
||||||
/* password incorrect */
|
/* password incorrect */
|
||||||
if ((state == DISCONNECTED_STATE) && (event == 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);
|
call_event_callback_function(WIFIMG_PASSWORD_FAILED, NULL, connecting_ap_event_label);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(assoc_reject_count >= MAX_ASSOC_REJECT_COUNT){
|
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;
|
assoc_reject_count = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +293,18 @@ void *check_connect_timeout(void *args)
|
||||||
void start_check_connect_timeout(int first)
|
void start_check_connect_timeout(int first)
|
||||||
{
|
{
|
||||||
pthread_t check_timeout_id;
|
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)
|
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));
|
wifi_command(cmd, reply, sizeof(reply));
|
||||||
|
|
||||||
set_wifi_machine_state(DISCONNECTED_STATE);
|
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);
|
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;
|
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<wifi_event_callback_index; i++){
|
for(i=0; i<wifi_event_callback_index; i++){
|
||||||
if(wifi_event_callback[i] != NULL){
|
if(wifi_event_callback[i] != NULL){
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "wifi_state_machine.h"
|
#include "wifi_state_machine.h"
|
||||||
|
#include <uvdbus/log.h>
|
||||||
|
|
||||||
static int gwifi_machine_state = DISCONNECTED_STATE;
|
static int gwifi_machine_state = DISCONNECTED_STATE;
|
||||||
|
|
||||||
/* set wifi state */
|
/* set wifi state */
|
||||||
int set_wifi_machine_state(tWIFI_MACHINE_STATE 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;
|
gwifi_machine_state = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* get wifi state */
|
/* get wifi state */
|
||||||
tWIFI_MACHINE_STATE get_wifi_machine_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;
|
return gwifi_machine_state;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,23 @@
|
||||||
#include "network_manager.h"
|
#include "network_manager.h"
|
||||||
#include "wpa_supplicant_conf.h"
|
#include "wpa_supplicant_conf.h"
|
||||||
#include "wifi_intf.h"
|
#include "wifi_intf.h"
|
||||||
#include "wmg_debug.h"
|
//#include <libiconv-full/iconv.h>
|
||||||
|
#include <uvdbus/log.h>
|
||||||
|
|
||||||
|
#define ENCODE_STYLE_UTF_8 "UTF-8"
|
||||||
|
#define ENCODE_STYLE_GB2312 "GB2312"
|
||||||
#define WPA_SSID_LENTH 512
|
#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();
|
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};
|
char netid_connecting[NET_ID_LEN+1] = {0};
|
||||||
int disconnecting = 0;
|
int disconnecting = 0;
|
||||||
int connecting_ap_event_label = 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();
|
wifi_machine_state = get_wifi_machine_state();
|
||||||
if(wifi_machine_state != CONNECTED_STATE && wifi_machine_state != DISCONNECTED_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;
|
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)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
else
|
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])
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!scan_ssid)
|
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;
|
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])
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!conf_ssid)
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,14 +254,14 @@ static int connect_command_handle(char *cmd,char *net_id)
|
||||||
char reply[REPLY_BUF_SIZE] = {0};
|
char reply[REPLY_BUF_SIZE] = {0};
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
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);
|
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
wifi_command(cmd, reply, sizeof(reply));
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
wifi_command(cmd, reply, sizeof(reply));
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}else{
|
}else{
|
||||||
wmg_printf(MSG_EXCESSIVE,"%s: %s",cmd,reply);
|
LOG_EX(LOG_Debug, "%s: %s",cmd,reply);
|
||||||
return 0;
|
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]){
|
if(!ssid || !ssid[0]){
|
||||||
wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n");
|
LOG_EX(LOG_Debug, "Error: ssid is NULL!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
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';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, netid2, sizeof(netid2));
|
ret = wifi_command(cmd, netid2, sizeof(netid2));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do add network results error!\n");
|
LOG_EX(LOG_Debug, "do add network results error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
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);
|
ret = check_wpa_passwd(passwd);
|
||||||
if(ret == 0){
|
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);
|
cancel_saved_conf_handle(netid2);
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
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 {
|
} 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 in wpa_supplicant.conf */
|
||||||
cancel_saved_conf_handle(netid2);
|
cancel_saved_conf_handle(netid2);
|
||||||
ret = -1;
|
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();
|
event = get_cur_wifi_event();
|
||||||
/* password incorrect*/
|
/* password incorrect*/
|
||||||
if ((state == DISCONNECTED_STATE) && (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;
|
break;
|
||||||
}
|
}
|
||||||
if(event == CONNECT_AP_TIMEOUT)
|
if(event == CONNECT_AP_TIMEOUT)
|
||||||
break;
|
break;
|
||||||
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
||||||
reset_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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,6 +577,29 @@ end:
|
||||||
return ret;
|
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)
|
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;
|
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';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, netid2, sizeof(netid2));
|
ret = wifi_command(cmd, netid2, sizeof(netid2));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do add network results error!\n");
|
LOG_EX(LOG_Debug, "do add network results error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
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);
|
ret = check_wpa_passwd(passwd);
|
||||||
if(ret == 0){
|
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 */
|
/* cancel saved in wpa_supplicant.conf */
|
||||||
sprintf(cmd, "REMOVE_NETWORK %s", netid2);
|
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;
|
goto end;
|
||||||
}
|
}
|
||||||
} else {
|
} 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 */
|
/* cancel saved in wpa_supplicant.conf */
|
||||||
sprintf(cmd, "REMOVE_NETWORK %s", netid2);
|
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();
|
event = get_cur_wifi_event();
|
||||||
/* password incorrect*/
|
/* password incorrect*/
|
||||||
if ((state == DISCONNECTED_STATE) && (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;
|
break;
|
||||||
}
|
}
|
||||||
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
||||||
reset_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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,7 +797,7 @@ static int wifi_connect_ap_inner(const char *ssid, tKEY_MGMT key_mgmt, const cha
|
||||||
|
|
||||||
|
|
||||||
ret = -1;
|
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;
|
event_code = WIFIMG_NETWORK_NOT_EXIST;
|
||||||
goto end;
|
goto end;
|
||||||
}else if(state == DISCONNECTED_STATE){ /* Errot when connecting */
|
}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;
|
ret = -1;
|
||||||
event_code = WIFIMG_PASSWORD_FAILED;
|
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;
|
goto end;
|
||||||
}else if(event == OBTAINING_IP_TIMEOUT){
|
}else if(event == OBTAINING_IP_TIMEOUT){
|
||||||
if(is_exist == 1 || is_exist == 3){
|
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 */
|
/* save config */
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
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;
|
ret = 0;
|
||||||
}else{
|
}else{
|
||||||
event_code = WIFIMG_NETWORK_NOT_EXIST;
|
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 */
|
/* save config */
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
wifi_command(cmd, reply, sizeof(reply));
|
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;
|
ret = 0;
|
||||||
}else{
|
}else{
|
||||||
event_code = WIFIMG_NETWORK_NOT_EXIST;
|
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]){
|
if(!ssid || !ssid[0]){
|
||||||
wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n");
|
LOG_EX(LOG_Debug, "Error: ssid is NULL!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
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;
|
const char *p_ssid = NULL;
|
||||||
|
|
||||||
if(gwifi_state == WIFIMG_WIFI_DISABLED){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ssid || !ssid[0]){
|
if(!ssid || !ssid[0]){
|
||||||
wmg_printf(MSG_ERROR,"Error: ssid is NULL!\n");
|
LOG_EX(LOG_Debug, "Error: ssid is NULL!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = get_wifi_machine_state();
|
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){
|
if(state != CONNECTED_STATE && state != DISCONNECTED_STATE){
|
||||||
ret = -1;
|
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;
|
event_code = WIFIMG_DEV_BUSING_EVENT;
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -1085,7 +1119,7 @@ disconnecting = 0;
|
||||||
sprintf(cmd, "SELECT_NETWORK %s", net_id);
|
sprintf(cmd, "SELECT_NETWORK %s", net_id);
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do selected network error!\n");
|
LOG_EX(LOG_Debug, "do selected network error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1099,7 +1133,7 @@ disconnecting = 0;
|
||||||
cmd[CMD_LEN] = '\0';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do reconnect error!\n");
|
LOG_EX(LOG_Debug, "do reconnect error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -1116,13 +1150,13 @@ disconnecting = 0;
|
||||||
event = get_cur_wifi_event();
|
event = get_cur_wifi_event();
|
||||||
/* password incorrect*/
|
/* password incorrect*/
|
||||||
if ((state == DISCONNECTED_STATE) && (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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
if(get_assoc_reject_count() >= MAX_ASSOC_REJECT_COUNT){
|
||||||
reset_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;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1190,7 +1224,7 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!ssid || !ssid[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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1207,12 +1241,12 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt)
|
||||||
len = NET_ID_LEN+1;
|
len = NET_ID_LEN+1;
|
||||||
ret = wpa_conf_ssid2netid(ssid, key_mgmt, net_id, &len);
|
ret = wpa_conf_ssid2netid(ssid, key_mgmt, net_id, &len);
|
||||||
if(ret <= 0){
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
else if(!(ret & (0x01<<1) ))
|
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;
|
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);
|
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1228,7 +1262,7 @@ static int aw_wifi_remove_network(char *ssid, tKEY_MGMT key_mgmt)
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do save config error!\n");
|
LOG_EX(LOG_Debug, "do save config error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,6 +1293,15 @@ static int aw_wifi_remove_all_networks()
|
||||||
return ret;
|
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)
|
static int aw_wifi_connect_ap_auto(int event_label)
|
||||||
{
|
{
|
||||||
int i=0, ret = -1, len = 0;
|
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;
|
len = NET_ID_LEN+1;
|
||||||
ret = wpa_conf_get_netid_connected(netid, &len);
|
ret = wpa_conf_get_netid_connected(netid, &len);
|
||||||
if(ret <= 0){
|
if(ret <= 0){
|
||||||
wmg_printf(MSG_INFO,"This no connected AP!\n");
|
LOG_EX(LOG_Debug, "This no connected AP!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_OPT_NO_USE_EVENT;
|
event_code = WIFIMG_OPT_NO_USE_EVENT;
|
||||||
goto end;
|
goto end;
|
||||||
|
@ -1374,7 +1417,7 @@ static int aw_wifi_disconnect_ap(int event_label)
|
||||||
sprintf(cmd, "%s", "DISCONNECT");
|
sprintf(cmd, "%s", "DISCONNECT");
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do disconnect network error!\n");
|
LOG_EX(LOG_Debug, "do disconnect network error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
||||||
goto end;
|
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';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, reply_len);
|
ret = wifi_command(cmd, reply, reply_len);
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list_networks error!\n");
|
LOG_EX(LOG_Debug, "do list_networks error!\n");
|
||||||
ret = -1;
|
ret = -1;
|
||||||
event_code = WIFIMG_CMD_OR_PARAMS_ERROR;
|
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:
|
end:
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
call_event_callback_function(event_code, NULL, event_label);
|
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;
|
*Ap with certain key_mgmt exists in the .conf file:return is 0, get the *net_id as expectation;
|
||||||
*else:return -1
|
*else:return -1
|
||||||
|
@ -1506,8 +1632,11 @@ static const aw_wifi_interface_t aw_wifi_interface = {
|
||||||
aw_wifi_disconnect_ap,
|
aw_wifi_disconnect_ap,
|
||||||
aw_wifi_remove_network,
|
aw_wifi_remove_network,
|
||||||
aw_wifi_remove_all_networks,
|
aw_wifi_remove_all_networks,
|
||||||
|
aw_wifi_reconfig,
|
||||||
aw_wifi_list_networks,
|
aw_wifi_list_networks,
|
||||||
aw_wifi_get_netid,
|
aw_wifi_get_netid,
|
||||||
|
aw_wifi_change_ap,
|
||||||
|
aw_wifi_enble_all_network,
|
||||||
aw_wifi_stop_scan,
|
aw_wifi_stop_scan,
|
||||||
aw_wifi_restart_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();
|
ret = wifi_connect_to_supplicant();
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_DEBUG,"wpa_suppplicant not running!\n");
|
LOG_EX(LOG_Debug, "wpa_suppplicant not running!\n");
|
||||||
wifi_start_supplicant(0);
|
wifi_start_supplicant(0);
|
||||||
do{
|
do{
|
||||||
usleep(300000);
|
usleep(300000);
|
||||||
ret = wifi_connect_to_supplicant();
|
ret = wifi_connect_to_supplicant();
|
||||||
if(!ret){
|
if(!ret){
|
||||||
wmg_printf(MSG_DEBUG,"Connected to wpa_supplicant!\n");
|
LOG_EX(LOG_Debug, "Connected to wpa_supplicant!\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
@ -1537,7 +1666,7 @@ const aw_wifi_interface_t * aw_wifi_on(tWifi_event_callback pcb, int event_label
|
||||||
if(ret < 0){
|
if(ret < 0){
|
||||||
if(pcb != NULL){
|
if(pcb != NULL){
|
||||||
pcb(WIFIMG_WIFI_ON_FAILED, NULL, event_label);
|
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;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1617,7 +1746,7 @@ int aw_wifi_get_wifi_state()
|
||||||
/* check wifi already on by self process or other process */
|
/* check wifi already on by self process or other process */
|
||||||
ret = wifi_connect_to_supplicant();
|
ret = wifi_connect_to_supplicant();
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"WiFi not on\n");
|
LOG_EX(LOG_Debug, "WiFi not on\n");
|
||||||
return WIFIMG_WIFI_DISABLED;
|
return WIFIMG_WIFI_DISABLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
#include<string.h>
|
#include<string.h>
|
||||||
|
#include <uvdbus/log.h>
|
||||||
|
|
||||||
#include "wpa_supplicant_conf.h"
|
#include "wpa_supplicant_conf.h"
|
||||||
#include "wifi.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();
|
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;
|
int flag = 0;
|
||||||
|
|
||||||
if(!ssid || !ssid[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;
|
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';
|
cmd[255] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//LOG_EX(LOG_Debug, "List network:%s\r\n",reply)
|
||||||
|
|
||||||
ptr = reply;
|
ptr = reply;
|
||||||
while((pssid_start=strstr(ptr, ssid)) != NULL){
|
while((pssid_start=strstr(ptr, ssid)) != NULL){
|
||||||
char *p_s=NULL, *p_e=NULL, *p=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';
|
cmd[255] = '\0';
|
||||||
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
|
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
|
||||||
if(ret){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
wmg_printf(MSG_DEBUG,"GET_NETWORK %s key_mgmt reply %s\n", net_id, key_reply);
|
LOG_EX(LOG_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, "key type %s\n", key_type);
|
||||||
|
|
||||||
if(strcmp(key_reply, key_type) == 0){
|
if(strcmp(key_reply, key_type) == 0){
|
||||||
flag += 1;
|
flag += 1;
|
||||||
|
@ -148,7 +153,7 @@ int wpa_conf_ssid2netid(char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len)
|
||||||
cmd[15] = '\0';
|
cmd[15] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
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';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
|
ret = wifi_command(cmd, key_reply, sizeof(key_reply));
|
||||||
if(ret){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +240,7 @@ int wpa_conf_get_max_priority()
|
||||||
cmd[CMD_LEN] = '\0';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -253,7 +258,7 @@ int wpa_conf_get_max_priority()
|
||||||
sprintf(cmd, "GET_NETWORK %s priority", net_id);
|
sprintf(cmd, "GET_NETWORK %s priority", net_id);
|
||||||
ret = wifi_command(cmd, priority, sizeof(priority));
|
ret = wifi_command(cmd, priority, sizeof(priority));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do get network priority error!\n");
|
LOG_EX(LOG_Debug, "do get network priority error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -268,6 +273,278 @@ int wpa_conf_get_max_priority()
|
||||||
return max_val;
|
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 wpa_conf_is_ap_connected(char *ssid, int *len)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
@ -282,10 +559,11 @@ int wpa_conf_is_ap_connected(char *ssid, int *len)
|
||||||
|
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG_EX(LOG_Debug, "----list network:%s\r\n",reply);
|
||||||
p_str = (char *)reply;
|
p_str = (char *)reply;
|
||||||
while((p_c=strstr(p_str, "[CURRENT]")) != NULL){
|
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';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +660,7 @@ int wpa_conf_get_ap_connected(char *netid, int *len)
|
||||||
|
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +702,7 @@ int wpa_conf_enable_all_networks()
|
||||||
cmd[CMD_LEN] = '\0';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +721,7 @@ int wpa_conf_enable_all_networks()
|
||||||
sprintf(cmd, "ENABLE_NETWORK %s", net_id);
|
sprintf(cmd, "ENABLE_NETWORK %s", net_id);
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -454,7 +732,32 @@ int wpa_conf_enable_all_networks()
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
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 -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -474,7 +777,7 @@ int wpa_conf_remove_all_networks()
|
||||||
cmd[CMD_LEN] = '\0';
|
cmd[CMD_LEN] = '\0';
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do list networks error!\n");
|
LOG_EX(LOG_Debug, "do list networks error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +796,7 @@ int wpa_conf_remove_all_networks()
|
||||||
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
|
sprintf(cmd, "REMOVE_NETWORK %s", net_id);
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -504,7 +807,7 @@ int wpa_conf_remove_all_networks()
|
||||||
sprintf(cmd, "%s", "SAVE_CONFIG");
|
sprintf(cmd, "%s", "SAVE_CONFIG");
|
||||||
ret = wifi_command(cmd, reply, sizeof(reply));
|
ret = wifi_command(cmd, reply, sizeof(reply));
|
||||||
if(ret){
|
if(ret){
|
||||||
wmg_printf(MSG_ERROR,"do save config error!\n");
|
LOG_EX(LOG_Debug, "do save config error!\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,13 @@ start_service() {
|
||||||
if ps | grep [u]dhcpc; then
|
if ps | grep [u]dhcpc; then
|
||||||
killall -q -KILL udhcpc
|
killall -q -KILL udhcpc
|
||||||
fi
|
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
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,12 @@ STOP=99
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
PROG=wpa_supplicant
|
PROG=wpa_supplicant
|
||||||
OOM_ADJ=-17
|
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() {
|
start_service() {
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
|
@ -16,7 +22,7 @@ start_service() {
|
||||||
fi
|
fi
|
||||||
ifconfig wlan0 up
|
ifconfig wlan0 up
|
||||||
procd_set_param oom_adj $OOM_ADJ
|
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
|
procd_close_instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1334,7 +1334,7 @@ CONFIG_PACKAGE_ubusd=y
|
||||||
CONFIG_PACKAGE_uci=y
|
CONFIG_PACKAGE_uci=y
|
||||||
# CONFIG_PACKAGE_udev is not set
|
# CONFIG_PACKAGE_udev is not set
|
||||||
# CONFIG_PACKAGE_usign 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
|
# CONFIG_PACKAGE_zram-swap is not set
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -1468,6 +1468,7 @@ CONFIG_PACKAGE_softap=y
|
||||||
# CONFIG_PACKAGE_usb-gadget is not set
|
# CONFIG_PACKAGE_usb-gadget is not set
|
||||||
CONFIG_PACKAGE_wifimanager=y
|
CONFIG_PACKAGE_wifimanager=y
|
||||||
CONFIG_PACKAGE_wifimanager-demo=y
|
CONFIG_PACKAGE_wifimanager-demo=y
|
||||||
|
CONFIG_PACKAGE_wifimanager-smartaudio=y
|
||||||
|
|
||||||
#
|
#
|
||||||
# avs
|
# avs
|
||||||
|
|
Loading…
Reference in New Issue