update wifimanager and firmware to newest version(PV1 commit 2e423e6f)

This commit is contained in:
lijie02 2018-09-26 15:28:14 +08:00
parent 4128d1e700
commit 9ae7983015
23 changed files with 2518 additions and 1042 deletions

View File

@ -3,7 +3,8 @@ include $(TINA_BUILD_TOP)/package/netease/Makefile.common
include $(TINA_BUILD_TOP)/build/nls.mk include $(TINA_BUILD_TOP)/build/nls.mk
target = wifi_connect_ap_test target = wifi_connect_ap_test
INCLUDES += -I$(CONFIG_PREFIX)/usr/include \ MK_PWD = ./
INCLUDES += -I$(CONFIG_PREFIX)/usr/include -I$(MK_PWD)/softap \
-I ../src/include -I ../src/include
CPP_SRCS = wifi_connect_ap.cpp CPP_SRCS = wifi_connect_ap.cpp

View File

@ -245,7 +245,7 @@ int main(int argv, char *argc[]){
} }
ret = p_wifi_interface->get_netid(argc[1], key_mgmt, net_id, &id_len); ret = p_wifi_interface->get_netid(argc[1], key_mgmt, net_id);
if(ret == 0){ if(ret == 0){
wmg_printf(MSG_INFO,"The netid of your network is %s\n",net_id); wmg_printf(MSG_INFO,"The netid of your network is %s\n",net_id);
wmg_printf(MSG_INFO,"The lenght of netid is %d\n",id_len); wmg_printf(MSG_INFO,"The lenght of netid is %d\n",id_len);

View File

@ -215,7 +215,7 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"********************************************\n"); wmg_printf(MSG_INFO,"********************************************\n");
wmg_printf(MSG_INFO,"==================stop scan================!\n"); wmg_printf(MSG_INFO,"==================stop scan================!\n");
wmg_printf(MSG_INFO,"********************************************\n"); wmg_printf(MSG_INFO,"********************************************\n");
p_wifi_interface->stop_scan(); //p_wifi_interface->stop_scan();
for(i=0;i<10;i++) for(i=0;i<10;i++)
{ {
usleep(2000000); usleep(2000000);
@ -223,7 +223,7 @@ int main(int argv, char *argc[]){
wmg_printf(MSG_INFO,"********************************************\n"); wmg_printf(MSG_INFO,"********************************************\n");
wmg_printf(MSG_INFO,"==================restart scan=============!\n"); wmg_printf(MSG_INFO,"==================restart scan=============!\n");
wmg_printf(MSG_INFO,"********************************************\n"); wmg_printf(MSG_INFO,"********************************************\n");
p_wifi_interface->restart_scan(); //p_wifi_interface->restart_scan();
} }
return 0; return 0;

View File

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

View File

@ -27,11 +27,12 @@
#include <algorithm> #include <algorithm>
#define PIPE_RET_SIZE 1024 #define PIPE_RET_SIZE 1024
#define WIFI_STATE_JS_KEY "wifi_state" #define WIFI_STATE_JS_KEY "wifi_state"
#define WIFI_STATE_RSSI_JS_KEY "wifi_rssi" #define WIFI_STATE_RSSI_JS_KEY "wifi_rssi"
#define WIFI_STATE_SSID_JS_KEY "wifi_ssid"
#define WIFI_STATE_MAC_JS_KEY "wifi_mac"
#define WIFI_STATE_EVT_JS_KEY "wifi_evt" #define WIFI_STATE_EVT_JS_KEY "wifi_evt"
@ -42,6 +43,8 @@
#define WLAN_CONFIG_CMD_STR "iwconfig" #define WLAN_CONFIG_CMD_STR "iwconfig"
#define WLAN_RSSI_STR_RRE "Signal level=" #define WLAN_RSSI_STR_RRE "Signal level="
#define WLAN_BSSID_STR_RRE "Access Point: "
#define WLAN_ESSID_STR_RRE "ESSID:\""
#define WIFI_CONF_EVT_TAG 0xf000 #define WIFI_CONF_EVT_TAG 0xf000
@ -66,6 +69,8 @@ typedef enum
{ {
WIFI_STATE_KEY_STATE =0, WIFI_STATE_KEY_STATE =0,
WIFI_STATE_KEY_RSSI, WIFI_STATE_KEY_RSSI,
WIFI_STATE_KEY_SSID,
WIFI_STATE_KEY_MAC,
WIFI_STATE_KEY_CNT, WIFI_STATE_KEY_CNT,
}sWifiStateKeysEnum; }sWifiStateKeysEnum;
@ -74,6 +79,8 @@ typedef enum
{ {
WIFI_EVT_KEY_EVT =0, WIFI_EVT_KEY_EVT =0,
WIFI_EVT_KEY_RSSI, WIFI_EVT_KEY_RSSI,
WIFI_EVT_KEY_SSID,
WIFI_EVT_KEY_MAC,
WIFI_EVT_KEY_CNT, WIFI_EVT_KEY_CNT,
}sWifiEvtKeysEnum; }sWifiEvtKeysEnum;
@ -117,8 +124,9 @@ typedef enum
int api_wifi_state_notify(int state); int api_wifi_state_notify(int state);
static char * wifiStateKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_JS_KEY,WIFI_STATE_RSSI_JS_KEY};
static char * wifiEvtKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_EVT_JS_KEY,WIFI_STATE_RSSI_JS_KEY}; static char * wifiStateKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_JS_KEY,WIFI_STATE_RSSI_JS_KEY,WIFI_STATE_SSID_JS_KEY,WIFI_STATE_MAC_JS_KEY};
static char * wifiEvtKeys[WIFI_STATE_KEY_CNT] ={WIFI_STATE_EVT_JS_KEY,WIFI_STATE_RSSI_JS_KEY,WIFI_STATE_SSID_JS_KEY,WIFI_STATE_MAC_JS_KEY};
@ -178,14 +186,16 @@ int pipeExcute(const char * cmd,std::vector<std::string> & recVec )
return 0; return 0;
} }
int get_connected_ap_rssi() int get_connected_ap_info(int *rssi, std::string &ssid, std::string &mac)
{ {
std::string shellCmd = WLAN_CONFIG_CMD_STR; std::string shellCmd = WLAN_CONFIG_CMD_STR;
std::vector<std::string> vectorRes; std::vector<std::string> vectorRes;
int status =0; int status =0;
int rssi = RSSI_INVALID_NUM;
std::string out; std::string out;
if (rssi == NULL)
return -1;
status =pipeExcute(shellCmd.c_str(),vectorRes); status =pipeExcute(shellCmd.c_str(),vectorRes);
if(0 == status) if(0 == status)
{ {
@ -196,24 +206,49 @@ int get_connected_ap_rssi()
if(pos == std::string::npos) if(pos == std::string::npos)
{ {
LOG_EX(LOG_Debug, "warm: no rssi\r\n"); LOG_EX(LOG_Debug, "warn: no rssi\r\n");
status = -1; *rssi = RSSI_INVALID_NUM;
}else }else
{ {
std::string rssiStr = out.substr(pos+strlen(WLAN_RSSI_STR_RRE),4); std::string rssiStr = out.substr(pos+strlen(WLAN_RSSI_STR_RRE),4);
LOG_EX(LOG_Debug, "---info: rssiStr is %s \r\n",rssiStr.c_str()); LOG_EX(LOG_Debug, "---info: rssiStr is %s\r\n",rssiStr.c_str());
rssi = std::stoi(rssiStr); *rssi = std::stoi(rssiStr);
}
pos = out.find(WLAN_BSSID_STR_RRE);
if(pos == std::string::npos)
{
LOG_EX(LOG_Debug, "warn: no bssid\r\n");
mac = "";
}else
{
mac = out.substr(pos+strlen(WLAN_BSSID_STR_RRE),17);
LOG_EX(LOG_Debug, "---info: macStr is %s\r\n", mac.c_str());
}
pos = out.find(WLAN_ESSID_STR_RRE);
if(pos == std::string::npos)
{
LOG_EX(LOG_Debug, "warn: no essid\r\n");
ssid = "";
}else
{
std::string ssidStr = out.substr(pos+strlen(WLAN_ESSID_STR_RRE));
std::size_t pos_end = ssidStr.find("\n");
ssid = ssidStr.substr(0,pos_end-3);
LOG_EX(LOG_Debug, "---info: essidStr is %s\r\n", ssid.c_str());
} }
}else }else
{ {
LOG_EX(LOG_Debug, "error: pipe excute error\r\n"); LOG_EX(LOG_Debug, "error: pipe excute error\r\n");
status = -1; return -1;
} }
return 0;
return (0 == status)?rssi:RSSI_INVALID_NUM;
} }
@ -309,20 +344,19 @@ char * api_wifi_state_json_get(char * p_key,int res)
return p; return p;
} }
char * api_wifi_state_json_get(char * p_key[],int res[],int size) char * api_wifi_state_json_get(int state, int rssi, std::string ssid, std::string mac)
{ {
cJSON* pRoot = NULL; cJSON* pRoot = NULL;
char * p=NULL; char * p=NULL;
pRoot=cJSON_CreateObject(); pRoot=cJSON_CreateObject();
if(NULL == pRoot) return NULL; if(NULL == pRoot)
return NULL;
cJSON_AddNumberToObject(pRoot,wifiStateKeys[WIFI_STATE_KEY_STATE],state);
cJSON_AddNumberToObject(pRoot,wifiStateKeys[WIFI_STATE_KEY_RSSI],rssi);
for(int i=0;i<size;i++) cJSON_AddStringToObject(pRoot,wifiStateKeys[WIFI_STATE_KEY_SSID],ssid.c_str());
{ cJSON_AddStringToObject(pRoot,wifiStateKeys[WIFI_STATE_KEY_MAC],mac.c_str());
cJSON_AddNumberToObject(pRoot,p_key[i],res[i]);
}
p = cJSON_Print(pRoot); p = cJSON_Print(pRoot);
@ -338,6 +372,32 @@ char * api_wifi_state_json_get(char * p_key[],int res[],int size)
} }
char * api_wifi_evt_json_get(int state, int rssi, std::string ssid, std::string mac)
{
cJSON* pRoot = NULL;
char * p=NULL;
pRoot=cJSON_CreateObject();
if(NULL == pRoot)
return NULL;
cJSON_AddNumberToObject(pRoot,wifiEvtKeys[WIFI_EVT_KEY_EVT],state);
cJSON_AddNumberToObject(pRoot,wifiEvtKeys[WIFI_EVT_KEY_RSSI],rssi);
cJSON_AddStringToObject(pRoot,wifiEvtKeys[WIFI_EVT_KEY_SSID],ssid.c_str());
cJSON_AddStringToObject(pRoot,wifiEvtKeys[WIFI_EVT_KEY_MAC],mac.c_str());
p = cJSON_Print(pRoot);
if(NULL == p)
{
cJSON_Delete(pRoot);
return NULL;
}
cJSON_Delete(pRoot);
return p;
}
int api_wifi_state_notify(int state) int api_wifi_state_notify(int state)
@ -379,19 +439,13 @@ int api_wifi_state_notify(int state)
int api_wifi_state_notify(int state,int rssi) int api_wifi_state_notify(int state,int rssi, std::string ssid, std::string mac)
{ {
char * pEvtJson = NULL; char * pEvtJson = NULL;
int status = 0; int status = 0;
int evtVal[WIFI_STATE_KEY_CNT] ={0};
evtVal[WIFI_EVT_KEY_EVT] = state;
evtVal[WIFI_EVT_KEY_RSSI] = rssi;
pEvtJson = api_wifi_state_json_get(wifiEvtKeys,evtVal,WIFI_STATE_KEY_CNT); pEvtJson = api_wifi_evt_json_get(state, rssi, ssid, mac);
if(NULL != pEvtJson) if(NULL != pEvtJson)
{ {
//status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_STATE_NTF, pStateJson); //status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_STATE_NTF, pStateJson);
@ -423,7 +477,9 @@ int api_wifi_state_notify(int state,int rssi)
static int ret_flag =0; static int ret_flag =0;
static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label) static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label)
{ {
int rssi =0; int rssi = 0;
std::string ssid = "";
std::string mac = "";
LOG_EX(LOG_Debug, "app_wifi_manager event_label 0x%x,event 0x%x\n", event_label,wifi_event); LOG_EX(LOG_Debug, "app_wifi_manager event_label 0x%x,event 0x%x\n", event_label,wifi_event);
@ -462,9 +518,9 @@ static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label
LOG_EX(LOG_Debug, "++++++WiFi connected ap!\n"); LOG_EX(LOG_Debug, "++++++WiFi connected ap!\n");
event = WIFIMG_NETWORK_CONNECTED; event = WIFIMG_NETWORK_CONNECTED;
rssi = get_connected_ap_rssi(); get_connected_ap_info(&rssi, ssid, mac);
if( 0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED,rssi)) if( 0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED, rssi, ssid, mac))
{ {
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
} }
@ -477,7 +533,7 @@ static void wifi_event_handle(tWIFI_EVENT wifi_event, void *buf, int event_label
LOG_EX(LOG_Debug, "++++++WiFi disconnected!\n"); LOG_EX(LOG_Debug, "++++++WiFi disconnected!\n");
event = WIFIMG_NETWORK_DISCONNECTED; event = WIFIMG_NETWORK_DISCONNECTED;
system("ifconfig wlan0 0.0.0.0"); system("ifconfig wlan0 0.0.0.0");
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_DISCONNECT,RSSI_INVALID_NUM)) if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_DISCONNECT, RSSI_INVALID_NUM, ssid, mac))
{ {
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
} }
@ -651,6 +707,7 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,
PDBUS_MSG_PACK pMsg) { PDBUS_MSG_PACK pMsg) {
int event_label = 0;; int event_label = 0;;
static const aw_wifi_interface_t *p_wifi_interface = NULL; static const aw_wifi_interface_t *p_wifi_interface = NULL;
static int wifi_off_mode = 0;
//cJSON * root = NULL; //cJSON * root = NULL;
int status =0; int status =0;
uint8_t * pResJson = NULL; uint8_t * pResJson = NULL;
@ -685,7 +742,7 @@ PDBUS_MSG_PACK DBusOnMessage(uv_loop_t *pLoop, DBusConnection *pConn,
case CMD_WIFI_CONF: case CMD_WIFI_CONF:
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_CONF==========================\r\n"); LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_CONF==========================\r\n");
LOG_EX(LOG_Debug, "wifi module get cfg msg is %s\r\n",pMsg->pMsg); LOG_EX(LOG_Debug, "wifi module get cfg msg is %s\r\n",pMsg->pMsg);
if(0 == busy_conf) if(0 == busy_conf || 1 == wifi_off_mode)
{ {
busy_conf =1; busy_conf =1;
status = api_wifi_get_cfg_value(pMsg->pMsg,&p_ssid,&p_passwd); status = api_wifi_get_cfg_value(pMsg->pMsg,&p_ssid,&p_passwd);
@ -877,9 +934,8 @@ END_DO:
break; break;
case CMD_WIFI_AUTO_CONN: case CMD_WIFI_AUTO_CONN:
{ {
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_AUTO_CONN==========================\r\n"); LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_AUTO_CONN==========================\r\n");
if(1== busy_conf) if(1== busy_conf || 1 == wifi_off_mode)
{ {
audo_code = APP_WIFI_AUTO_BT_CONF_COLLISION; audo_code = APP_WIFI_AUTO_BT_CONF_COLLISION;
} }
@ -956,7 +1012,9 @@ END_DO:
if(WIFIMG_WIFI_CONNECTED !=aw_wifi_get_wifi_state() ) if(WIFIMG_WIFI_CONNECTED !=aw_wifi_get_wifi_state() )
{ {
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTING,RSSI_INVALID_NUM)) std::string ssid = "";
std::string mac = "";
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTING, RSSI_INVALID_NUM, ssid, mac))
{ {
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
} }
@ -964,8 +1022,11 @@ END_DO:
}else }else
{ {
int rssi = get_connected_ap_rssi(); int rssi = 0;
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED,rssi)) std::string ssid = "";
std::string mac = "";
get_connected_ap_info(&rssi, ssid, mac);
if(0 != api_wifi_state_notify(APP_WIFI_EVT_NTF_CONNECTED, rssi, ssid, mac))
{ {
LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n"); LOG_EX(LOG_Debug, "Notify the wifi state error!!\r\n");
} }
@ -990,23 +1051,19 @@ END_DO:
} }
case CMD_WIFI_STATE_REQ: case CMD_WIFI_STATE_REQ:
{ {
int stateVal[WIFI_STATE_KEY_CNT] ={0}; int rssi = 0;
int rssi =0; std::string ssid = "";
std::string mac = "";
LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_STATE_REQ==========================\r\n"); LOG_EX(LOG_Debug, "====================Get cmd CMD_WIFI_STATE_REQ==========================\r\n");
wifi_state = aw_wifi_get_wifi_state(); wifi_state = aw_wifi_get_wifi_state();
if(WIFIMG_WIFI_CONNECTED == wifi_state) if(WIFIMG_WIFI_CONNECTED == wifi_state)
{ {
rssi = get_connected_ap_rssi(); get_connected_ap_info(&rssi, ssid, mac);
LOG_EX(LOG_Debug, "---info: rssi is %d\r\n",rssi);
} }
stateVal[WIFI_STATE_KEY_STATE] = wifi_state;
stateVal[WIFI_STATE_KEY_RSSI] = rssi;
pStateJson = (uint8_t *)api_wifi_state_json_get(wifiStateKeys,stateVal,WIFI_STATE_KEY_CNT); pStateJson = (uint8_t *)api_wifi_state_json_get(wifi_state, rssi, ssid, mac);
if(NULL != pStateJson) if(NULL != pStateJson)
{ {
status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_STATE_RESP,(const char *) pStateJson); status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_STATE_RESP,(const char *) pStateJson);
@ -1108,6 +1165,116 @@ END_DO:
LOG_EX(LOG_Debug, "remove_all_networks L%d \r\n", __LINE__); LOG_EX(LOG_Debug, "remove_all_networks L%d \r\n", __LINE__);
} }
break; break;
case CMD_WIFI_ON:
status = APP_WIFI_CFG_SUCCESS;
if (wifi_off_mode == 0)
{
LOG_EX(LOG_Error, "Wifi interface already on, turn on wifi failed!\n");
status = APP_WIFI_CFG_SYS_ERR;
}
else
{
p_wifi_interface = aw_wifi_on(wifi_event_handle, WIFI_CONF_EVT_TAG);
if(p_wifi_interface == NULL){
LOG_EX(LOG_Error, "Turn on wifi failed!\n");
status = APP_WIFI_CFG_SYS_ERR;
}
else
{
wifi_off_mode = 0;
LOG_EX(LOG_Error, "Turn on wifi succeed!\n");
}
}
pResJson = (uint8_t *)api_wifi_res_json_get(status);
if(NULL != pResJson)
{
status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_ON_RESP,(const char *)pResJson);
if(0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to control er:%d\r\n",status);
}else
{
LOG_EX(LOG_Debug, "Wifi module is send wifi_auto msg : 0x%x to control module\r\n",rsp_code);
}
}else
{
LOG_EX(LOG_Debug, "Wifi module get res json err\r\n");
}
if(NULL != pResJson)
{
free(pResJson);
pResJson = NULL;
}
break;
case CMD_WIFI_OFF:
status = APP_WIFI_CFG_SUCCESS;
if (p_wifi_interface == NULL || wifi_off_mode == 1)
{
LOG_EX(LOG_Error, "Wifi interface not on, turn off wifi failed!\n");
status = APP_WIFI_CFG_SYS_ERR;
}
else
{
if(WIFIMG_WIFI_CONNECTED == aw_wifi_get_wifi_state())
{
status = p_wifi_interface->disconnect_ap(WIFI_CONF_EVT_TAG);
if(0 != status)
{
LOG_EX(LOG_Error, "ERROR:wifi disconnect event 0x%x\n", event);
status = APP_WIFI_CFG_SYS_ERR;
}else
{
LOG_EX(LOG_Debug, "Disconnect the wifi connected ap\r\n");
status = APP_WIFI_CFG_SUCCESS;
}
}
/* turn off wifi */
status = aw_wifi_off(p_wifi_interface);
if(status < 0)
{
LOG_EX(LOG_Error, "Turn off wifi failed!\n");
status = APP_WIFI_CFG_SYS_ERR;
}
else
{
LOG_EX(LOG_Error, "Turn off wifi succeed!\n");
wifi_off_mode = 1;
p_wifi_interface = NULL;
status = APP_WIFI_CFG_SUCCESS;
}
}
pResJson = (uint8_t *)api_wifi_res_json_get(status);
if(NULL != pResJson)
{
status = api_wifi_module_cmd_send((1<<MODULE_CONTROLLER),CMD_WIFI_OFF_RESP,(const char *)pResJson);
if(0 != status)
{
LOG_EX(LOG_Debug, "Wifi module send dbus msg to control er:%d\r\n",status);
}else
{
LOG_EX(LOG_Debug, "Wifi module is send wifi_auto msg : 0x%x to control module\r\n",rsp_code);
}
}else
{
LOG_EX(LOG_Debug, "Wifi module get res json err\r\n");
}
if(NULL != pResJson)
{
free(pResJson);
pResJson = NULL;
}
break;
case CMD_WIFI_BL_CONF:
case CMD_WIFI_BL_CONF_ABORT:
case CMD_WIFI_BL_CLOUD_CHALLENGE_SIGNATURE:
case CMD_WIFI_BL_CLOUD_SHAREDKEY:
case CMD_WIFI_BL_DEV_TOKEN_BOUND:
bl_event_handle(pMsg->busCmd, pMsg->pMsg);
break;
default: default:
break; break;
} }
@ -1141,8 +1308,6 @@ int main(int argv, char *argc[]){
g_pDBusInterfaceName = g_pModInfoTable[MODULE_WIFI].modAliase; g_pDBusInterfaceName = g_pModInfoTable[MODULE_WIFI].modAliase;
LOG_EX(LOG_Debug, "Start the wifi communication\n");
//pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, DBusOnMessage, NULL, NULL, &ret); //pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, DBusOnMessage, NULL, NULL, &ret);
pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, NULL, NULL, NULL, &ret); pBus = DBusWithLibuvInit(pLoop, g_pDBusInterfaceName, NULL, NULL, NULL, &ret);
@ -1152,12 +1317,13 @@ int main(int argv, char *argc[]){
fprintf(stderr, "%s(%d): DBusWithLibuvInit Error: %d\n", g_pDBusInterfaceName, MODULE_PLAYER, ret); fprintf(stderr, "%s(%d): DBusWithLibuvInit Error: %d\n", g_pDBusInterfaceName, MODULE_PLAYER, ret);
return 0; return 0;
} }
/* init a uv timer to report cur position */ /* init a uv timer to report cur position */
uv_timer_init(pLoop, &timerCurPosMsg); uv_timer_init(pLoop, &timerCurPosMsg);
pthread_mutex_init(&ctrl_mutex, NULL); pthread_mutex_init(&ctrl_mutex, NULL);
LOG_EX(LOG_Debug, "Start the wifi communication\n");
uv_thread_t uvSyncThread; uv_thread_t uvSyncThread;
uv_thread_create(&uvSyncThread, DBusMsgHandleLoop, NULL); uv_thread_create(&uvSyncThread, DBusMsgHandleLoop, NULL);

View File

@ -10,7 +10,7 @@ LIBS += -lpthread -ldl -lrt -liconv
local_LDFLAGS := $(BUILD_COMMON_LIB) $(ICONV_LDFLAGS) -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 broadlink.c
install: install:
-@mkdir -p $(CONFIG_PREFIX)/usr/lib -@mkdir -p $(CONFIG_PREFIX)/usr/lib
@ -19,12 +19,12 @@ install:
#libwifimg.so #libwifimg.so
ifeq ($(CONFIG_ARCH), "aarch64") ifeq ($(CONFIG_ARCH), "aarch64")
SRCS += libwpa_client_64.a SRCS += libwpa_client_64.a libfastcon.a
else else
ifeq ($(CONFIG_SOFT_FLOAT), y) ifeq ($(CONFIG_SOFT_FLOAT), y)
SRCS += libwpa_client_softft.a SRCS += libwpa_client_softft.a libfastcon.a
else else
SRCS += libwpa_client.a SRCS += libwpa_client.a libfastcon.a
endif endif
endif endif
$(target): $(SRCS) $(target): $(SRCS)

View File

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

View File

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

View File

@ -1,6 +1,5 @@
#ifndef __NETWORK_MANAGER_H #ifndef __NETWORK_MANAGER_H
#define __NETWORK_MANAGER_H #define __NETWORK_MANAGER_H
#include "tool.h"
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
@ -11,39 +10,6 @@ extern "C" {
#define KEY_WPA_PSK_INDEX 1 #define KEY_WPA_PSK_INDEX 1
#define KEY_WEP_INDEX 2 #define KEY_WEP_INDEX 2
enum wpa_states {
WPA_UNKNOWN = 1024,
WPA_DISCONNECTED,
WPA_INTERFACE_DISABLED,
WPA_INACTIVE,
WPA_SCANNING,
WPA_AUTHENTICATING,
WPA_ASSOCIATING,
WPA_ASSOCIATED,
WPA_4WAY_HANDSHAKE,
WPA_GROUP_HANDSHAKE,
WPA_COMPLETED,
};
#define WPA_STA_MAX_SSID 32
#define WPA_STA_MAX_BSSID 18
#define WPA_STA_MAX_IP_ADDR 16
#define WPA_STA_MAX_KEY_MGMT 16
#define WPA_STA_MAX_MAC_ADDR 18
struct wpa_status{
u32 id;
u8 bssid[WPA_STA_MAX_BSSID];
u32 freq;
u8 ssid[WPA_STA_MAX_SSID];
enum wpa_states wpa_state;
u8 ip_address[WPA_STA_MAX_IP_ADDR];
u8 key_mgmt[WPA_STA_MAX_KEY_MGMT];
u8 mac_address[WPA_STA_MAX_MAC_ADDR];
};
void shutdown_wifi_scan_thread();
void restart_wifi_scan_thread();
void start_wifi_scan_thread(void *args); void start_wifi_scan_thread(void *args);
void stop_wifi_scan_thread(); void stop_wifi_scan_thread();
void pause_wifi_scan_thread(); void pause_wifi_scan_thread();
@ -51,9 +17,7 @@ void resume_wifi_scan_thread();
int update_scan_results(); int update_scan_results();
int get_scan_results_inner(char *results, int *len); int get_scan_results_inner(char *results, int *len);
int get_key_mgmt(const char *ssid, int key_mgmt_info[]); int get_key_mgmt(const char *ssid, int key_mgmt_info[]);
struct wpa_status * get_wpa_status();
void print_wpa_status(struct wpa_status *wpa_sta);
void wpa_status_free();
#if __cplusplus #if __cplusplus
}; // extern "C" }; // extern "C"
#endif #endif

View File

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

View File

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

View File

@ -22,7 +22,7 @@ enum WPA_EVENT{
DRIVER_STATE, DRIVER_STATE,
EAP_FAILURE, EAP_FAILURE,
ASSOC_REJECT, ASSOC_REJECT,
NETWORK_NOT_FOUND, SSID_TEMP_DISABLED,
UNKNOWN, UNKNOWN,
}; };
@ -35,11 +35,14 @@ typedef enum{
}tWIFI_EVENT_INNER; }tWIFI_EVENT_INNER;
void wifi_event_loop(tWifi_event_callback pcb); void wifi_event_loop(tWifi_event_callback pcb);
void wifi_event_loop_stop();
void wifi_event_loop_restart();
void start_wifi_on_check_connect_timeout(); void start_wifi_on_check_connect_timeout();
void start_check_connect_timeout(); void start_check_connect_timeout();
tWIFI_EVENT_INNER get_cur_wifi_event(); tWIFI_EVENT_INNER get_cur_wifi_event();
int set_cur_wifi_event(tWIFI_EVENT_INNER event); int set_cur_wifi_event(tWIFI_EVENT_INNER event);
void set_scan_start_flag(); void set_scan_start_flag();
void set_wifi_off_flag(int value);
int get_scan_status(); int get_scan_status();
void reset_assoc_reject_count(); void reset_assoc_reject_count();
int get_assoc_reject_count(); int get_assoc_reject_count();

View File

@ -4,6 +4,10 @@
#if __cplusplus #if __cplusplus
extern "C" { extern "C" {
#endif #endif
#include <stdlib.h>
#include <stdio.h>
#define MAX_CALLBCAKS_COUNT 1024 #define MAX_CALLBCAKS_COUNT 1024
typedef enum { typedef enum {
@ -60,9 +64,7 @@ typedef struct{
int (*remove_all_networks)(void); int (*remove_all_networks)(void);
int (*re_config)(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 (*stop_scan)();
int (*restart_scan)();
int (*change_ap)(int event_label ); int (*change_ap)(int event_label );
int (*enable_all_network)(void); int (*enable_all_network)(void);
}aw_wifi_interface_t; }aw_wifi_interface_t;
@ -70,6 +72,9 @@ typedef struct{
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);
int aw_wifi_get_wifi_state(); int aw_wifi_get_wifi_state();
int aw_wifi_off(const aw_wifi_interface_t *p_wifi_interface_t); int aw_wifi_off(const aw_wifi_interface_t *p_wifi_interface_t);
int bl_sdk_init();
int bl_event_handle(unsigned int cmd, const char* msg);
#if __cplusplus #if __cplusplus
}; // extern "C" }; // extern "C"

Binary file not shown.

View File

@ -5,15 +5,22 @@
#include<pthread.h> #include<pthread.h>
#include<sys/time.h> #include<sys/time.h>
#include <netinet/ether.h>
#include <linux/wireless.h>
#include <sys/ioctl.h>
#include <uvdbus/log.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 "tool.h" #include "broadlink.h"
#define MAX_SCAN_FAIL_TIME 5
#define WAITING_CLK_COUNTS 50 #define WAITING_CLK_COUNTS 50
#define SSID_LEN 512
#define UTF8_BYTES_MAX 4096 #define UTF8_BYTES_MAX 4096
#define UTF8_MULTI_BYTES_MASK 0x80 #define UTF8_MULTI_BYTES_MASK 0x80
#define ESCAP_CHAR_ASCII '\\' #define ESCAP_CHAR_ASCII '\\'
@ -24,237 +31,23 @@
/* scan thread */ /* scan thread */
static pthread_t scan_thread_id; static pthread_t scan_thread_id;
static int scan_running = 0; static int scan_running = 0;
static int scan_terminating = 0;
static pthread_mutex_t scan_mutex; static pthread_mutex_t scan_mutex;
static pthread_cond_t scan_cond; static pthread_cond_t scan_cond;
static int scan_pause = 0; static int scan_pause = 0;
static int scan_error = 0;
static int do_scan_flag = 1;
/* run scan immediately */ /* run scan immediately */
static pthread_mutex_t thread_run_mutex; static pthread_mutex_t thread_run_mutex;
static pthread_cond_t thread_run_cond; static pthread_cond_t thread_run_cond;
/*stop restart scan*/
static pthread_mutex_t scan_stop_restart_mutex;
static pthread_cond_t scan_stop_restart_cond;
/* store scan results */ /* store scan results */
static char scan_results[SCAN_BUF_LEN]; static char scan_results[SCAN_BUF_LEN];
static int scan_results_len = 0; static int scan_results_len = 0;
static int scan_completed = 0; static int scan_completed = 0;
enum wpa_states wpa_supplicant_state_convert(char *str)
{
if(!strncmp(str,"DISCONNECTED",16)){
return WPA_DISCONNECTED;
}
if(!strncmp(str,"INTERFACE_DISABLED",22)){
return WPA_INTERFACE_DISABLED;
}
if(!strncmp(str,"INACTIVE",12)){
return WPA_INACTIVE;
}
if(!strncmp(str,"SCANNING",12)){
return WPA_SCANNING;
}
if(!strncmp(str,"AUTHENTICATING",18)){
return WPA_AUTHENTICATING;
}
if(!strncmp(str,"ASSOCIATED",14)){
return WPA_ASSOCIATED;
}
if(!strncmp(str,"4WAY_HANDSHAKE",19)){
return WPA_4WAY_HANDSHAKE;
}
if(!strncmp(str,"GROUP_HANDSHAKE",19)){
return WPA_GROUP_HANDSHAKE;
}
if(!strncmp(str,"COMPLETED",13)){
return WPA_COMPLETED;
}
if(!strncmp(str,"DISCONNECTED",16)){
return WPA_DISCONNECTED;
}
return WPA_UNKNOWN;
}
static const char * wpa_supplicant_state_txt(enum wpa_states state)
{
switch (state) {
case WPA_DISCONNECTED:
return "DISCONNECTED";
case WPA_INACTIVE:
return "INACTIVE";
case WPA_INTERFACE_DISABLED:
return "INTERFACE_DISABLED";
case WPA_SCANNING:
return "SCANNING";
case WPA_AUTHENTICATING:
return "AUTHENTICATING";
case WPA_ASSOCIATING:
return "ASSOCIATING";
case WPA_ASSOCIATED:
return "ASSOCIATED";
case WPA_4WAY_HANDSHAKE:
return "4WAY_HANDSHAKE";
case WPA_GROUP_HANDSHAKE:
return "GROUP_HANDSHAKE";
case WPA_COMPLETED:
return "COMPLETED";
default:
return "UNKNOWN";
}
}
void print_wpa_status(struct wpa_status *wpa_sta)
{
LOG_EX(LOG_Debug, "obtained wpa_supplicant status,as follow:\n");
LOG_EX(LOG_Debug, "==============================\n");
if(wpa_sta->id >= 0)
LOG_EX(LOG_Debug, "id:%d\n",wpa_sta->id);
if(wpa_sta->bssid)
LOG_EX(LOG_Debug, "bssid:%s\n",wpa_sta->bssid);
if(wpa_sta->freq >=0)
LOG_EX(LOG_Debug, "freq:%d\n",wpa_sta->freq);
if(wpa_sta->ssid)
LOG_EX(LOG_Debug, "ssid:%s\n",wpa_sta->ssid);
if(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)
LOG_EX(LOG_Debug, "ip_address:%s\n",wpa_sta->ip_address);
if(wpa_sta->key_mgmt)
LOG_EX(LOG_Debug, "key_mgmt:%s\n",wpa_sta->key_mgmt);
if(wpa_sta->mac_address)
LOG_EX(LOG_Debug, "mac_address:%s\n",wpa_sta->mac_address);
LOG_EX(LOG_Debug, "==============================\n");
}
static char *strstr_wpa(const char *src,const char *obj, /* broadlink thread */
const char pre_str[2],int pst_len) static pthread_t broadlink_thread_id;
{ static int broadlink_thread_running = 0;
const char *p=src;
int length;
int i=0;
if(src == NULL || obj == NULL || pre_str ==NULL){
LOG_EX(LOG_Debug, "src or obj or pre_str is NULL");
return NULL;
}
if(pst_len > strlen(pre_str)){
LOG_EX(LOG_Debug, "pst_len length is illegal");
return NULL;
}
length = strlen(obj);
for(;;p++,i++){
p=strchr(p,*obj);
if(p == NULL){
LOG_EX(LOG_Debug, "%s is not exist",obj);
return NULL;
}
if(strncmp(p,obj,length) == 0){
if(i > 1 && *(p-1) != pre_str[0] && *(p-1) != pre_str[1]){
return (char*)p;
}
}
}
}
static int search_wpa_string(const char *src,const char *obj,int max,char *get_str)
{
int i=0;
const char *sptr = NULL;
const char *pnext = NULL;
if(obj == NULL || src == NULL){
wmg_printf(MSG_DEBUG,"src or obj is NULL");
return 0;
}
if(!strncmp("id=",obj,3)){
sptr = strstr_wpa(src,obj,"su",2);
}else if(!strncmp("ssid=",obj,5)){
sptr = strstr_wpa(src,obj,"bb",2);
}else if(!strncmp("address=",obj,8)){
sptr = strstr_wpa(src,obj,"__",2);
}else{
sptr = strstr(src, obj);
}
if(sptr !=NULL){
pnext=sptr+strlen(obj);
i=0;
while(1){
i++;
if(i >max ){
LOG_EX(LOG_Debug, "Data overflow");
break;
}
pnext++;
if(*pnext == '\n')
break;
}
strncpy(get_str,sptr+strlen(obj),i);
get_str[i]='\0';
return 1;
}
return -1;
}
static struct wpa_status *gstatus;
static struct wpa_status* wpa_status_init()
{
int i;
if(gstatus == NULL)
gstatus = (struct wpa_status *)wgos_zalloc(sizeof(struct wpa_status));
if(gstatus == NULL){
LOG_EX(LOG_Debug, "MALLOC STATUS STRUCT FAILED!\n");
return NULL;
}
gstatus->id = -1;
gstatus->freq = -1;
for(i = 0;i< WPA_STA_MAX_SSID;i++){
gstatus->ssid[i] = '\0';
if(i < WPA_STA_MAX_BSSID)
gstatus->bssid[i] = '\0';
if(i < WPA_STA_MAX_IP_ADDR)
gstatus->ip_address[i] = '\0';
if(i < WPA_STA_MAX_KEY_MGMT)
gstatus->key_mgmt[i]='\0';
if(i < WPA_STA_MAX_MAC_ADDR)
gstatus->mac_address[i]='\0';
}
gstatus->wpa_state = WPA_UNKNOWN;
return gstatus;
}
void wpa_status_free()
{
if(gstatus !=NULL)
free(gstatus);
}
struct wpa_status * get_wpa_status()
{
char reply[4096] = {0};
char wpa_result[32];
struct wpa_status *wpa_sta;
wpa_sta = wpa_status_init();
wifi_command("STATUS", reply, sizeof(reply));
if(reply !=NULL){
if(search_wpa_string(reply,"ssid=",32,wpa_result) >0)
strncpy(wpa_sta->ssid,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"id=",4,wpa_result) >0)
wpa_sta->id = atoi(wpa_result);
if(search_wpa_string(reply,"freq=",6,wpa_result) >0)
wpa_sta->freq = atoi(wpa_result);
if(search_wpa_string(reply,"bssid=",18,wpa_result) >0)
strncpy(wpa_sta->bssid,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"key_mgmt=",16,wpa_result) >0)
strncpy(wpa_sta->key_mgmt,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"wpa_state=",32,wpa_result) >0)
wpa_sta->wpa_state = wpa_supplicant_state_convert(wpa_result);
if(search_wpa_string(reply,"address=",18,wpa_result) >0)
strncpy(wpa_sta->mac_address,wpa_result,strlen(wpa_result));
if(search_wpa_string(reply,"ip_address=",16,wpa_result) >0)
strncpy(wpa_sta->ip_address,wpa_result,strlen(wpa_result));
}
if(wmg_get_debug_level() >= MSG_DEBUG){
print_wpa_status(wpa_sta);
}
return wpa_sta;
}
int update_scan_results() int update_scan_results()
{ {
@ -277,72 +70,13 @@ int update_scan_results()
return 0; return 0;
} }
int remove_slash_from_scan_results()
{
char *ptr = NULL;
char *ptr_s = NULL;
char *ftr = NULL;
ptr_s = scan_results;
while(1)
{
ptr = strchr(ptr_s,'\"');
if(ptr == NULL)
break;
ptr_s = ptr;
if((*(ptr-1)) == '\\')
{
ftr = ptr;
ptr -= 1;
while(*ftr != '\0')
*(ptr++) = *(ftr++);
*ptr = '\0';
continue; //restart new search at ptr_s after removing slash
}
else
ptr_s++; //restart new search at ptr_s++
}
ptr_s = scan_results;
while(1)
{
ptr = strchr(ptr_s,'\\');
if(ptr == NULL)
break;
ptr_s = ptr;
if((*(ptr-1)) == '\\')
{
ftr = ptr;
ptr -= 1;
while(*ftr != '\0')
*(ptr++) = *(ftr++);
*ptr = '\0';
continue; //restart new search at ptr_s after removing slash
}
else
ptr_s++; //restart new search at ptr_s++
}
return 0;
}
int get_scan_results_inner(char *result, int *len) int get_scan_results_inner(char *result, int *len)
{ {
int index = 0; int index = 0;
char *ptr = NULL; char *ptr = NULL;
int ret = 0;
pthread_mutex_lock(&scan_mutex); pthread_mutex_lock(&scan_mutex);
if(0 != scan_error)
{
// prinf("%s: scan or scan_results ERROR in scan_thread!\n", __func__);
ret = -1;
}
remove_slash_from_scan_results();
if(*len <= scan_results_len){ if(*len <= scan_results_len){
strncpy(result, scan_results, *len-1); strncpy(result, scan_results, *len-1);
index = *len -1; index = *len -1;
@ -358,7 +92,7 @@ int get_scan_results_inner(char *result, int *len)
pthread_mutex_unlock(&scan_mutex); pthread_mutex_unlock(&scan_mutex);
return ret; return 0;
} }
int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt) int is_network_exist(const char *ssid, tKEY_MGMT key_mgmt)
@ -461,8 +195,10 @@ 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;
char *pst = NULL, *pend = NULL; char *pst = NULL, *pend = NULL;
char *pflag = NULL; char *pflag = NULL;
char flag[128], pssid[SSID_LEN + 1]; char flag[128];
int len = 0, i = 0; int len = 0, i = 0;
char * pSsidSearch = NULL;
int status=0;
LOG_EX(LOG_Debug, "enter get_key_mgmt, ssid %s\n", ssid); LOG_EX(LOG_Debug, "enter get_key_mgmt, ssid %s\n", ssid);
@ -481,47 +217,66 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[])
} }
//point second line of scan results //point second line of scan results
ptr++;
remove_slash_from_scan_results();
while(1){ status = utf8BytesExchangeEx(ssid,&pSsidSearch);
if(0 != status)
{
LOG_EX(LOG_Debug, "utf8 exchange err\r\n");
goto ToOut;
}
LOG_EX(LOG_Debug, "changed ssid is %s\r\n",pSsidSearch);
ptr++;
while((pssid_start=strstr(ptr, pSsidSearch)) != NULL){
pssid_end = pssid_start + strlen(pSsidSearch);
/* ssid is presuffix of searched network */
if((*pssid_end != '\n') && (*pssid_end != '\0')){
pend = strchr(pssid_start, '\n');
if(pend != NULL){
ptr = pend+1;
continue;
}else{
break;
}
}
/* network ssid is same of searched network */
/* line end */ /* line end */
pend = strchr(ptr, '\n'); pend = strchr(pssid_start, '\n');
if (pend != NULL){ if(pend != NULL){
*pend = '\0'; *pend = '\0';
} }
/* line start */ pst = strrchr(ptr, '\n');
pst = ptr; if(pst != NULL){
pst++;
}else{
pst = ptr;
}
/* abstract ssid */ pflag = pst;
pssid_start = strrchr(pst, '\t') + 1; for(i=0; i<3; i++){
strncpy(pssid, pssid_start, SSID_LEN); pflag = strchr(pflag, '\t');
pssid[SSID_LEN] = '\0'; pflag++;
}
/* find ssid in scan results */ len = pssid_start - pflag;
if(strcmp(pssid, ssid) == 0){ len = len - 1;
pflag = pst; strncpy(flag, pflag, len);
for(i=0; i<3; i++){ flag[len] = '\0';
pflag = strchr(pflag, '\t');
pflag++;
}
len = pssid_start - pflag;
len = len - 1;
strncpy(flag, pflag, len);
flag[len] = '\0';
LOG_EX(LOG_Debug, "ssid %s, flag %s\n", ssid, flag); LOG_EX(LOG_Debug, "ssid %s, flag %s\n", ssid, flag);
if((strstr(flag, "WPA-PSK-") != NULL)
|| (strstr(flag, "WPA2-PSK-") != NULL)){ if((strstr(flag, "WPA-PSK-") != NULL)
key_mgmt_info[KEY_WPA_PSK_INDEX] = 1; || (strstr(flag, "WPA2-PSK-") != NULL)){
}else if(strstr(flag, "WEP") != NULL){ key_mgmt_info[KEY_WPA_PSK_INDEX] = 1;
key_mgmt_info[KEY_WEP_INDEX] = 1; }else if(strstr(flag, "WEP") != NULL){
}else if((strcmp(flag, "[ESS]") == 0) || (strcmp(flag, "[WPS][ESS]") == 0)){ key_mgmt_info[KEY_WEP_INDEX] = 1;
key_mgmt_info[KEY_NONE_INDEX] = 1; }else if((strcmp(flag, "[ESS]") == 0) || (strcmp(flag, "[WPS][ESS]") == 0)){
}else{ key_mgmt_info[KEY_NONE_INDEX] = 1;
; }else{
} ;
} }
if(pend != NULL){ if(pend != NULL){
@ -533,6 +288,10 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[])
} }
} }
ToOut:
free(pSsidSearch);
pSsidSearch = NULL;
pthread_mutex_unlock(&scan_mutex); pthread_mutex_unlock(&scan_mutex);
return 0; return 0;
@ -540,46 +299,103 @@ int get_key_mgmt(const char *ssid, int key_mgmt_info[])
} }
double iw_freq2float(const struct iw_freq * in)
{
int i;
double res = (double)in->m;
for(i = 0; i < in->e; i++)
res *= 10;
return (res);
}
static inline int iw_get_ext(int skfd, const char *ifname, int request, struct iwreq * pwrq)
{
/* Set device name */
strncpy(pwrq->ifr_name, ifname, IFNAMSIZ);
/* Do the request */
return(ioctl(skfd, request, pwrq));
}
int api_wifi_get_wireless_info(const char *ifname)
{
int sock;
struct iwreq wrq;
char *mac = NULL;
memset((char *)&wrq, 0, sizeof(struct iwreq));
/* Create a channel to the NET kernel. */
sock = socket(AF_INET, SOCK_DGRAM, 0);
if (sock < 0)
{
LOG_EX(LOG_Debug, "Open sock error!\n");
return -1;
}
/* Get wireless name */
if(iw_get_ext(sock, ifname, SIOCGIWNAME, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless name error!\n");
return -1;
}
LOG_EX(LOG_Debug, "Wireless name %s\n", wrq.u.name);
/* Get frequency / channel */
if(iw_get_ext(sock, ifname, SIOCGIWFREQ, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless frequency error!\n");
return -1;
}
LOG_EX(LOG_Debug, "Wireless frequency %lf\n", iw_freq2float(&(wrq.u.freq)));
/* Get AP address */
if(iw_get_ext(sock, ifname, SIOCGIWAP, &wrq) < 0)
{
LOG_EX(LOG_Debug, "Get wireless ap mac error!\n");
return -1;
}
mac = (char *)(&(wrq.u.ap_addr));
LOG_EX(LOG_Debug, "Wireless ap mac %x:%x:%x:%x:%x:%x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
}
void *wifi_scan_thread(void *args) void *wifi_scan_thread(void *args)
{ {
int ret = -1, i = 0; int ret = -1, i = 0;
int scan_fail_cnt = 0;
char cmd[16] = {0}, reply[16] = {0}; char cmd[16] = {0}, reply[16] = {0};
struct timeval now; struct timeval now;
struct timespec outtime; struct timespec outtime;
while(scan_running){ while(scan_running){
pthread_mutex_lock(&scan_stop_restart_mutex);
while(do_scan_flag == 0){
pthread_cond_wait(&scan_stop_restart_cond, &scan_stop_restart_mutex);
}
if(scan_terminating)
{
pthread_mutex_unlock(&scan_stop_restart_mutex);
continue;
}
pthread_mutex_unlock(&scan_stop_restart_mutex);
pthread_mutex_lock(&scan_mutex); pthread_mutex_lock(&scan_mutex);
while(scan_pause == 1){ if(scan_pause == 1){
pthread_cond_wait(&scan_cond, &scan_mutex); pthread_cond_wait(&scan_cond, &scan_mutex);
} }
/* set scan start flag */ /* set scan start flag */
set_scan_start_flag(); set_scan_start_flag();
/* scan cmd */ /* scan cmd */
strncpy(cmd, "SCAN", 15); strncpy(cmd, "SCAN", 15);
ret = wifi_command(cmd, reply, sizeof(reply)); ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){ if(ret){
scan_error = 1;
pthread_mutex_unlock(&scan_mutex); pthread_mutex_unlock(&scan_mutex);
usleep(5000*1000); scan_fail_cnt++;
usleep(500*1000);
/* fix PV1-3216, do DISCONNECT to restore driver from continuiously restart */
if (scan_fail_cnt > MAX_SCAN_FAIL_TIME)
{
stop_connecting();
scan_fail_cnt = 0;
}
continue; continue;
} }
scan_fail_cnt = 0;
for(i=0;i<WAITING_CLK_COUNTS;i++){ for(i=0;i<WAITING_CLK_COUNTS;i++){
if(get_scan_status() == 1){ if(get_scan_status() == 1){
@ -594,17 +410,15 @@ void *wifi_scan_thread(void *args)
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;
LOG_EX(LOG_Debug, "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;
} }
scan_results_len = strlen(scan_results); scan_results_len = strlen(scan_results);
scan_error = 0; //LOG_EX(LOG_Debug, "scan wifi result:%s\r\n",scan_results);
//printf("scan results len2 %d\n", scan_results_len);
//printf("scan results2\n");
//printf("%s\n", scan_results);
} }
pthread_mutex_unlock(&scan_mutex); pthread_mutex_unlock(&scan_mutex);
//wait run singal or timeout 15s //wait run singal or timeout 15s
@ -616,35 +430,13 @@ void *wifi_scan_thread(void *args)
gettimeofday(&now, NULL); gettimeofday(&now, NULL);
outtime.tv_sec = now.tv_sec + 15; outtime.tv_sec = now.tv_sec + 15;
outtime.tv_nsec = now.tv_usec *1000; outtime.tv_nsec = now.tv_usec *1000;
if(!scan_terminating) pthread_cond_timedwait(&thread_run_cond, &thread_run_mutex, &outtime);
{
pthread_cond_timedwait(&thread_run_cond, &thread_run_mutex, &outtime);
scan_completed = 0;
}
pthread_mutex_unlock(&thread_run_mutex); pthread_mutex_unlock(&thread_run_mutex);
}//end of while scan running }
}
void shutdown_wifi_scan_thread()
{
pthread_mutex_lock(&scan_stop_restart_mutex);
do_scan_flag = 0;
pthread_mutex_unlock(&scan_stop_restart_mutex);
}
void restart_wifi_scan_thread()
{
pthread_mutex_lock(&scan_stop_restart_mutex);
do_scan_flag = 1;
pthread_mutex_unlock(&scan_stop_restart_mutex);
pthread_cond_signal(&scan_stop_restart_cond);
} }
void start_wifi_scan_thread(void *args) void start_wifi_scan_thread(void *args)
{ {
scan_terminating = 0;
pthread_mutex_init(&scan_stop_restart_mutex, NULL);
pthread_cond_init(&scan_stop_restart_cond, NULL);
pthread_mutex_init(&scan_mutex, NULL); pthread_mutex_init(&scan_mutex, NULL);
pthread_cond_init(&scan_cond, NULL); pthread_cond_init(&scan_cond, NULL);
pthread_mutex_init(&thread_run_mutex, NULL); pthread_mutex_init(&thread_run_mutex, NULL);
@ -670,20 +462,29 @@ void resume_wifi_scan_thread()
void stop_wifi_scan_thread() void stop_wifi_scan_thread()
{ {
scan_running = 0; scan_running = 0;
usleep(200*1000); usleep(200*1000);
pthread_mutex_lock(&thread_run_mutex); pthread_join(scan_thread_id, NULL);
scan_terminating = 1;
pthread_cond_signal(&thread_run_cond);
pthread_mutex_unlock(&thread_run_mutex);
restart_wifi_scan_thread();//if scan is stopped by the user, wake up the scan_thread pthread_cond_destroy(&thread_run_cond);
pthread_mutex_destroy(&thread_run_mutex);
pthread_join(scan_thread_id, NULL); pthread_cond_destroy(&scan_cond);
pthread_cond_destroy(&thread_run_cond); pthread_mutex_destroy(&scan_mutex);
pthread_mutex_destroy(&thread_run_mutex);
pthread_cond_destroy(&scan_cond);
pthread_mutex_destroy(&scan_mutex);
pthread_cond_destroy(&scan_stop_restart_cond);
pthread_mutex_destroy(&scan_stop_restart_mutex);
} }
void start_broadlink_thread(void *args)
{
pthread_attr_t attr;
if (broadlink_thread_running)
return;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
pthread_create(&broadlink_thread_id, &attr, &bl_recv_msg_thread, args);
broadlink_thread_running = 1;
}

View File

@ -93,15 +93,13 @@ void *udhcpc_thread(void *args)
/* stop dhcpc thread */ /* stop dhcpc thread */
system("/etc/wifi/udhcpc_wlan0 stop"); system("/etc/wifi/udhcpc_wlan0 stop");
if((get_wifi_machine_state()) != DISCONNECTED_STATE){ /* send disconnect */
/* send disconnect */ sprintf(cmd, "%s", "DISCONNECT");
sprintf(cmd, "%s", "DISCONNECT"); wifi_command(cmd, reply, sizeof(reply));
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE); set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(OBTAINING_IP_TIMEOUT); set_cur_wifi_event(OBTAINING_IP_TIMEOUT);
call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label); call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label);
}
} }
pthread_exit(NULL); pthread_exit(NULL);

View File

@ -12,13 +12,14 @@
#include "wifi.h" #include "wifi.h"
#include <unistd.h> #include <unistd.h>
#include <uvdbus/log.h> #include <uvdbus/log.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; 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];
@ -479,10 +480,12 @@ int wifi_start_supplicant(int p2p_supported)
exit_sockets[0] = exit_sockets[1] = -1; exit_sockets[0] = exit_sockets[1] = -1;
/* start wpa_supplicant */ /* start wpa_supplicant */
strncpy(cmd, "/etc/wifi/wifi start", 511); strncpy(cmd, "/etc/wifi/wifi restart", 511);
cmd[511] = '\0'; cmd[511] = '\0';
system(cmd); system(cmd);
return 0; return 0;
} }
@ -492,7 +495,7 @@ int wifi_stop_supplicant(int p2p_supported)
return 0; return 0;
} }
#define SUPPLICANT_TIMEOUT 3000000 // microseconds #define SUPPLICANT_TIMEOUT 4000000 // microseconds
#define SUPPLICANT_TIMEOUT_STEP 100000 // microseconds #define SUPPLICANT_TIMEOUT_STEP 100000 // microseconds
int wifi_connect_on_socket_path(const char *path) int wifi_connect_on_socket_path(const char *path)
{ {
@ -536,8 +539,7 @@ int wifi_connect_on_socket_path(const char *path)
int wifi_connect_to_supplicant() int wifi_connect_to_supplicant()
{ {
static char path[PATH_MAX]; static char path[PATH_MAX];
if(get_process_state("wpa_supplicant",14) == -1)
return -1;
strncpy(primary_iface, "wlan0", IFACE_VALUE_MAX); strncpy(primary_iface, "wlan0", IFACE_VALUE_MAX);
if (access(IFACE_DIR, F_OK) == 0) { if (access(IFACE_DIR, F_OK) == 0) {
snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface); snprintf(path, sizeof(path), "%s/%s", IFACE_DIR, primary_iface);
@ -558,11 +560,11 @@ int wifi_send_command(const char *cmd, char *reply, size_t *reply_len)
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); 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) {
LOG_EX(LOG_Debug, "'%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;
} else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) { } else if (ret < 0 || strncmp(reply, "FAIL", 4) == 0) {
return -1; return -1;
@ -606,6 +608,7 @@ int wifi_wait_on_socket(char *buf, size_t buflen)
char *match, *match2; char *match, *match2;
if (monitor_conn == NULL) { if (monitor_conn == NULL) {
sleep(2);
return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed"); return snprintf(buf, buflen, WPA_EVENT_TERMINATING " - connection closed");
} }
@ -707,6 +710,25 @@ void wifi_close_supplicant_connection()
} }
} }
void wifi_restart_supplicant()
{
int i;
int ret;
wifi_event_loop_stop();
wifi_close_supplicant_connection();
wifi_start_supplicant(0);
do{
usleep(300000);
ret = wifi_connect_to_supplicant();
if(!ret){
LOG_EX(LOG_Debug, "Connected to wpa_supplicant!\n");
break;
}
i++;
}while(ret && i<10);
wifi_event_loop_restart();
}
void wifi_clear() void wifi_clear()
{ {
@ -730,7 +752,11 @@ int wifi_command(char const *cmd, char *reply, size_t reply_len)
if ((ret =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); LOG_EX(LOG_Debug, "wifi_send_command ret is %d %s\r\n",ret, reply);
wifi_clear(); if (-2 == ret)
wifi_restart_supplicant();
else
wifi_clear();
pthread_mutex_unlock(&ctrl_mutex); pthread_mutex_unlock(&ctrl_mutex);
return -1; return -1;
} }

View File

@ -5,14 +5,14 @@
#include<unistd.h> #include<unistd.h>
#include<uvdbus/log.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"
//tWIFI_STATE gwifi_state; tWIFI_STATE gwifi_state;
tWIFI_STATE gwifi_state = WIFIMG_WIFI_DISABLED;
extern char netid_connecting[]; extern char netid_connecting[];
extern int connecting_ap_event_label; extern int connecting_ap_event_label;
extern int disconnect_ap_event_label; extern int disconnect_ap_event_label;
@ -22,8 +22,10 @@ tWifi_event_callback wifi_event_callback[MAX_CALLBCAKS_COUNT] = {NULL};
int wifi_event_callback_index = 0; int wifi_event_callback_index = 0;
static pthread_t event_thread_id; static pthread_t event_thread_id;
static int event_thread_running;
static int wifi_event_inner = AP_DISCONNECTED; static int wifi_event_inner = AP_DISCONNECTED;
static int scan_complete = 0; static int scan_complete = 0;
static int wifi_off_flag = 0;
static int assoc_reject_count = 0; static int assoc_reject_count = 0;
static int authentication_fail_count = 0; static int authentication_fail_count = 0;
@ -32,7 +34,6 @@ static void handle_event(int event, char * remainder) {
char cmd[255] = {0}, reply[16]={0}; char cmd[255] = {0}, reply[16]={0};
int len = NET_ID_LEN+1; int len = NET_ID_LEN+1;
tWIFI_MACHINE_STATE state; tWIFI_MACHINE_STATE state;
static int network_not_found_count = 0;
switch (event){ switch (event){
case DISCONNECTED: case DISCONNECTED:
@ -60,7 +61,7 @@ static void handle_event(int event, char * remainder) {
} }
} }
assoc_reject_count = 0; //assoc_reject_count = 0;
set_wifi_machine_state(L2CONNECTED_STATE); set_wifi_machine_state(L2CONNECTED_STATE);
/* start udhcpcd */ /* start udhcpcd */
@ -71,18 +72,8 @@ static void handle_event(int event, char * remainder) {
scan_complete = 1; scan_complete = 1;
break; break;
case NETWORK_NOT_FOUND:
network_not_found_count++;
LOG_EX(LOG_Debug,"NETWORK NOT FOUND %d times!\n",network_not_found_count);
if(network_not_found_count >= 3){
sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply));
set_wifi_machine_state(DISCONNECTED_STATE);
set_cur_wifi_event(CONNECT_AP_TIMEOUT);
}
break;
case UNKNOWN: case UNKNOWN:
//printf("unknown event!\n"); //LOG_EX(LOG_Debug, "unknown event!\n");
break; break;
} }
} }
@ -90,8 +81,12 @@ static void handle_event(int event, char * remainder) {
static int dispatch_event(const char *event_str, int nread) static int dispatch_event(const char *event_str, int nread)
{ {
int i = 0, event = 0; int i = 0, event = 0;
char event_name[18]; char event_name[32];
char cmd[255] = {0}, reply[16]={0}; char cmd[255] = {0}, reply[16]={0};
char network_id[NET_ID_LEN]={0};
static char recent_network_id[NET_ID_LEN]={0};
int network_id_tmp;
char buf_tmp[255];
char *name_start = NULL, *name_end = NULL; char *name_start = NULL, *name_end = NULL;
char *event_data = NULL; char *event_data = NULL;
@ -117,6 +112,11 @@ static int dispatch_event(const char *event_str, int nread)
} }
} }
if (!strncmp(event_str, "Selecting BSS network id ", 25)){
sscanf(event_str, "Selecting BSS network id %d!!!!", &network_id_tmp);
sprintf(recent_network_id, "%d", network_id_tmp);
}
//LOG_EX(LOG_Debug, "EVENT, not care!\n"); //LOG_EX(LOG_Debug, "EVENT, not care!\n");
return 0; return 0;
} }
@ -124,7 +124,7 @@ static int dispatch_event(const char *event_str, int nread)
name_start = (char *)((unsigned long)event_str+11); name_start = (char *)((unsigned long)event_str+11);
name_end = strchr(name_start, ' '); name_end = strchr(name_start, ' ');
if(name_end){ if(name_end){
while((name_start < name_end) && (i < 18)){ while((name_start < name_end) && (i < 31)){
event_name[i] = *name_start++; event_name[i] = *name_start++;
i++; i++;
} }
@ -153,10 +153,10 @@ static int dispatch_event(const char *event_str, int nread)
event = DRIVER_STATE; event = DRIVER_STATE;
}else if(!strcmp(event_name, "EAP-FAILURE")){ }else if(!strcmp(event_name, "EAP-FAILURE")){
event = EAP_FAILURE; event = EAP_FAILURE;
}else if(!strcmp(event_name, "NETWORK-NOT-FOUND")){
event = NETWORK_NOT_FOUND;
}else if(!strcmp(event_name, "ASSOC-REJECT")){ }else if(!strcmp(event_name, "ASSOC-REJECT")){
event = ASSOC_REJECT; event = ASSOC_REJECT;
}else if(!strcmp(event_name, "SSID-TEMP-DISABLED")){
event = SSID_TEMP_DISABLED;
}else{ }else{
event = UNKNOWN; event = UNKNOWN;
} }
@ -184,22 +184,40 @@ static int dispatch_event(const char *event_str, int nread)
LOG_EX(LOG_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){
LOG_EX(LOG_Debug, "Wpa supplicant terminated!\n"); if (get_wifi_off_flag())
gwifi_state = WIFIMG_WIFI_DISABLED; {
call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0); /* If we turn off wifi, we should update wifimanager status. */
return 1; LOG_EX(LOG_Debug, "Wpa supplicant terminated!\n");
gwifi_state = WIFIMG_WIFI_DISABLED;
call_event_callback_function(WIFIMG_WIFI_OFF_SUCCESS, NULL, 0);
set_wifi_off_flag(0);
return 1;
}
else
{
/* If we just restart wpa_supplicant, do nothing. */
return 0;
}
}else if(event == EAP_FAILURE){ }else if(event == EAP_FAILURE){
LOG_EX(LOG_Debug, "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++;
if(assoc_reject_count >= MAX_ASSOC_REJECT_COUNT){ if(assoc_reject_count >= MAX_ASSOC_REJECT_COUNT){
wpa_conf_add_on_priority_list_hdr(recent_network_id);
LOG_EX(LOG_Debug, "Current ap's priority lowered!\n");
/* send disconnect */ /* send disconnect */
sprintf(cmd, "%s", "DISCONNECT"); sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply)); wifi_command(cmd, reply, sizeof(reply));
} }
LOG_EX(LOG_Debug, "ASSOC REJECT!\n"); LOG_EX(LOG_Debug, "ASSOC REJECT!\n");
return 0; return 0;
}else if(event == SSID_TEMP_DISABLED){
sscanf(event_str, "CTRL-EVENT-SSID-TEMP-DISABLED id=%d %s", &network_id_tmp, buf_tmp);
sprintf(network_id, "%d", network_id_tmp);
wpa_conf_add_on_priority_list_hdr(network_id);
LOG_EX(LOG_Debug, "Current ap's priority lowered!\n");
return 0;
}else{ }else{
handle_event(event, event_data); handle_event(event, event_data);
} }
@ -212,8 +230,8 @@ void *event_handle_thread(void* args)
char buf[EVENT_BUF_SIZE] = {0}; char buf[EVENT_BUF_SIZE] = {0};
int nread = 0, ret = 0; int nread = 0, ret = 0;
for(;;){ while(event_thread_running){
nread = wifi_wait_for_event(buf, sizeof(buf)); nread = wifi_wait_for_event(buf, sizeof(buf));
if (nread > 0) { if (nread > 0) {
ret = dispatch_event(buf, nread); ret = dispatch_event(buf, nread);
if(ret == 1){ if(ret == 1){
@ -224,16 +242,43 @@ void *event_handle_thread(void* args)
} }
} }
LOG_EX(LOG_Debug, "Wifi event_handle_thread stopped!\n");
pthread_exit(NULL); pthread_exit(NULL);
} }
void wifi_event_loop(tWifi_event_callback pcb) void wifi_event_loop(tWifi_event_callback pcb)
{ {
pthread_attr_t attr;
/* initial */ /* initial */
wifi_event_inner = AP_DISCONNECTED; wifi_event_inner = AP_DISCONNECTED;
pthread_create(&event_thread_id, NULL, event_handle_thread, NULL);
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
event_thread_running = 1;
pthread_create(&event_thread_id, &attr, event_handle_thread, NULL);
} }
void wifi_event_loop_stop()
{
event_thread_running = 0;
usleep(200*1000);
}
void wifi_event_loop_restart()
{
pthread_attr_t attr;
/* Set thread attribute PTHREAD_CREATE_DETACHED, otherwise the resources
will not be reclaimed after thread exit. */
pthread_attr_init (&attr);
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
event_thread_running = 1;
pthread_create(&event_thread_id, &attr, event_handle_thread, NULL);
}
tWIFI_EVENT_INNER get_cur_wifi_event() tWIFI_EVENT_INNER get_cur_wifi_event()
{ {
return wifi_event_inner; return wifi_event_inner;
@ -286,7 +331,10 @@ void *check_connect_timeout(void *args)
call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label); call_event_callback_function(WIFIMG_CONNECT_TIMEOUT, NULL, connecting_ap_event_label);
} }
pthread_exit(NULL); /* resume scan thread */
resume_wifi_scan_thread();
pthread_exit(NULL);
} }
@ -323,9 +371,9 @@ void *wifi_on_check_connect_timeout(void *args)
event = get_cur_wifi_event(); event = get_cur_wifi_event();
i++; i++;
} while((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE) && (state != DISCONNECTED_STATE) && (i < 100)); } while((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE) && (i < 100));
if((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE) && (state != DISCONNECTED_STATE)){ if((state != L2CONNECTED_STATE) && (state != CONNECTED_STATE)){
/* send disconnect */ /* send disconnect */
sprintf(cmd, "%s", "DISCONNECT"); sprintf(cmd, "%s", "DISCONNECT");
wifi_command(cmd, reply, sizeof(reply)); wifi_command(cmd, reply, sizeof(reply));
@ -355,6 +403,17 @@ int get_scan_status()
return scan_complete; return scan_complete;
} }
void set_wifi_off_flag(int value)
{
wifi_off_flag = value;
}
int get_wifi_off_flag()
{
return wifi_off_flag;
}
void reset_assoc_reject_count() void reset_assoc_reject_count()
{ {
assoc_reject_count = 0; assoc_reject_count = 0;

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,9 @@
#define WPA_DIASBLE_NETWORK_CMD "DISABLE_NETWORK" #define WPA_DIASBLE_NETWORK_CMD "DISABLE_NETWORK"
#define WPA_INTERNET_RECONNECT_SAVE 1 #define WPA_INTERNET_RECONNECT_SAVE 1
static const char SUPP_CONFIG_FILE[] = "/mnt/UDISK/wifi/wpa_supplicant.conf";
extern int is_ip_exist(); extern int is_ip_exist();
int wpa_conf_network_info_exist() int wpa_conf_network_info_exist()
@ -62,7 +65,8 @@ int wpa_conf_is_ap_exist(const char *ssid, tKEY_MGMT key_mgmt, char *net_id, int
return -1; return -1;
} }
//LOG_EX(LOG_Debug, "List network:%s\r\n",reply) LOG_EX(LOG_Debug, "List network:%s\r\n",reply);
LOG_EX(LOG_Debug, "Ssid:%s\r\n",ssid);
ptr = reply; ptr = reply;
while((pssid_start=strstr(ptr, ssid)) != NULL){ while((pssid_start=strstr(ptr, ssid)) != NULL){
@ -186,11 +190,11 @@ int wpa_conf_ssid2netid(char *ssid, tKEY_MGMT key_mgmt, char *net_id, int *len)
p_t = strchr(p_s, '\t'); p_t = strchr(p_s, '\t');
if(p_t){ if(p_t){
int tmp = 0; int tmp = 0;
tmp = p_t - p_s; tmp = p_t - p_s;
if(tmp <= NET_ID_LEN){ if(tmp <= NET_ID_LEN){
strncpy(net_id, p_s, tmp); strncpy(net_id, p_s, tmp);
net_id[tmp] = '\0'; net_id[tmp] = '\0';
} }
} }
@ -550,9 +554,7 @@ int wpa_conf_is_ap_connected(char *ssid, int *len)
int ret = -1; int ret = -1;
char cmd[CMD_LEN+1] = {0}; char cmd[CMD_LEN+1] = {0};
char reply[REPLY_BUF_SIZE] = {0}; char reply[REPLY_BUF_SIZE] = {0};
char *p_c=NULL, *p_str = NULL; char *p_c=NULL;
char *p_s=NULL, *p_e=NULL, *p=NULL;
int is_ap_connected = 0;
strncpy(cmd, "LIST_NETWORKS", CMD_LEN); strncpy(cmd, "LIST_NETWORKS", CMD_LEN);
cmd[CMD_LEN] = '\0'; cmd[CMD_LEN] = '\0';
@ -564,21 +566,15 @@ int wpa_conf_is_ap_connected(char *ssid, int *len)
} }
LOG_EX(LOG_Debug, "----list network:%s\r\n",reply); LOG_EX(LOG_Debug, "----list network:%s\r\n",reply);
p_str = (char *)reply;
while((p_c=strstr(p_str, "[CURRENT]")) != NULL){
if(*(p_c + 9) != '\n' && *(p_c + 9) != '\0')
{
p_str = p_c+9;
continue;
}
if ((p_c=strstr(reply, "CURRENT")) != NULL){
char *p_s=NULL, *p_e=NULL, *p=NULL;
p_e = strchr(p_c, '\n'); p_e = strchr(p_c, '\n');
if(p_e){ if(p_e){
*p_e = '\0'; *p_e = '\0';
} }
p_s = strrchr(p_str, '\n'); p_s = strrchr(reply, '\n');
p_s++; p_s++;
p = strtok(p_s, "\t"); p = strtok(p_s, "\t");
p = strtok(NULL, "\t"); p = strtok(NULL, "\t");
@ -587,19 +583,18 @@ int wpa_conf_is_ap_connected(char *ssid, int *len)
strncpy(ssid, p, *len-1); strncpy(ssid, p, *len-1);
ssid[*len-1] = '\0'; ssid[*len-1] = '\0';
*len = strlen(ssid); *len = strlen(ssid);
is_ap_connected = 1;
break;
} }
} }
} /* check ip exist */
ret = is_ip_exist();
if(ret > 0){
return 1;
}
/* check ip exist */ return 0;
ret = is_ip_exist(); } else {
if(ret > 0 && is_ap_connected == 1){ return 0;
return ret;
}else{
return is_ap_connected;
} }
} }
@ -663,6 +658,7 @@ int wpa_conf_get_ap_connected(char *netid, int *len)
LOG_EX(LOG_Debug, "do list networks error!\n"); LOG_EX(LOG_Debug, "do list networks error!\n");
return -1; return -1;
} }
LOG_EX(LOG_Debug, "%s\n", reply);
if ((p_c=strstr(reply, "CURRENT")) != NULL){ if ((p_c=strstr(reply, "CURRENT")) != NULL){
char *p_s=NULL, *p_e=NULL, *p=NULL; char *p_s=NULL, *p_e=NULL, *p=NULL;
@ -689,6 +685,104 @@ int wpa_conf_get_ap_connected(char *netid, int *len)
} }
int wpa_conf_get_apinfo_connected(char *key_mgmt, int *priority)
{
int ret = 0;
char cmd[CMD_LEN+1] = {0};
char reply[REPLY_BUF_SIZE] = {0};
char netid[NET_ID_LEN+1] = {0};
int len = NET_ID_LEN+1;
if (netid == NULL || key_mgmt == NULL || priority == NULL)
return -1;
if (1 != wpa_conf_get_ap_connected(netid, &len))
return -1;
/* Get key_mgmt */
sprintf(cmd, "GET_NETWORK %s key_mgmt", netid);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Error, "Get network key_mgmt error!\n");
return -1;
}
strcpy(key_mgmt, reply);
LOG_EX(LOG_Debug, "Get network key_mgmt %s\n", key_mgmt);
/* Get priority */
sprintf(cmd, "GET_NETWORK %s priority", netid);
ret = wifi_command(cmd, reply, sizeof(reply));
if(ret){
LOG_EX(LOG_Error, "Get network priority error!\n");
return -1;
}
*priority = atoi(reply);
LOG_EX(LOG_Debug, "Get network priority %d\n", *priority);
return 0;
}
int wpa_conf_get_appwd_connected(int priority, char *pwd)
{
int ret = 0;
int i;
FILE *fp = NULL;
char line[128] = {0};
char *p_tmp = NULL;
int prio_tmp = 0;
char pwd_tmp[128] = {0};
if (pwd == NULL)
return -1;
fp = fopen(SUPP_CONFIG_FILE, "r");
if (!fp) {
LOG_EX(LOG_Debug, "Failed to fopen file: %s\n", SUPP_CONFIG_FILE);
return -1;
}
while (fgets(line, sizeof(line), fp) != NULL)
{
if (!strncmp(line, "network={", 9))
{
/* If priority does not exist, default to 0. */
prio_tmp = 0;
while (fgets(line, sizeof(line), fp) != NULL
&& strncmp(line, "}", 1))
{
if ((p_tmp = strstr(line, "priority=")) != NULL)
{
p_tmp += 9;
sscanf(p_tmp, "%d\n", &prio_tmp);
}
if ((p_tmp = strstr(line, "psk=\"")) != NULL)
{
p_tmp += 5;
strncpy(pwd_tmp, p_tmp, strlen(p_tmp));
}
}
if (prio_tmp == priority)
{
i=0;
while(pwd_tmp[i+1] != '\n')
{
pwd[i] = pwd_tmp[i];
i++;
}
pwd[i] = '\0';
LOG_EX(LOG_Debug, "Get network(priority %d) password succeed %s\n", priority, pwd);
fclose(fp);
return 0;
}
}
}
LOG_EX(LOG_Debug, "Get network(priority %d) password failed!\n", priority);
fclose(fp);
return -1;
}
int wpa_conf_enable_all_networks() int wpa_conf_enable_all_networks()
{ {
int ret = -1, len = 0; int ret = -1, len = 0;

View File

@ -16,8 +16,8 @@ start_service() {
then then
procd_set_param command $PROG -i wlan0 -h When_you_like_AW -S -T 1 procd_set_param command $PROG -i wlan0 -h When_you_like_AW -S -T 1
else else
# host_name=`cat /mnt/UDISK/bt/bt_config.xml | grep local` host_name=`cat /mnt/UDISK/bt/bt_config.xml | grep local`
procd_set_param command $PROG -i wlan0 -h "SING-PV2" -S -T 1 procd_set_param command $PROG -i wlan0 -h "SING-${host_name:32:4}" -S -T 1
fi fi
procd_close_instance procd_close_instance
} }

9
package/libs/libiconv-full/Makefile Normal file → Executable file
View File

@ -49,7 +49,8 @@ define Package/iconv
TITLE+= utility TITLE+= utility
endef endef
TARGET_CFLAGS += $(FPIC) -DUSE_DOS #TARGET_CFLAGS += $(FPIC) -DUSE_DOS
TARGET_CFLAGS += $(FPIC)
CONFIGURE_ARGS += \ CONFIGURE_ARGS += \
--enable-shared \ --enable-shared \
@ -66,11 +67,15 @@ endef
define Build/InstallDev define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/lib/libiconv-full/include $(INSTALL_DIR) $(1)/usr/lib/libiconv-full/include
$(INSTALL_DIR) $(1)/usr/include
$(INSTALL_DIR) $(1)/usr/include/libiconv-full
$(CP) $(PKG_INSTALL_DIR)/usr/include/iconv.h $(1)/usr/lib/libiconv-full/include/ $(CP) $(PKG_INSTALL_DIR)/usr/include/iconv.h $(1)/usr/lib/libiconv-full/include/
$(CP) $(PKG_INSTALL_DIR)/usr/include/iconv.h $(1)/usr/include/libiconv-full
$(INSTALL_DIR) $(1)/usr/lib/libiconv-full/lib $(INSTALL_DIR) $(1)/usr/lib/libiconv-full/lib
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libcharset.{a,so*} $(1)/usr/lib/libiconv-full/lib/ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libcharset.{a,so*} $(1)/usr/lib/libiconv-full/lib/
$(CP) $(PKG_INSTALL_DIR)/usr/lib/libiconv.{a,so*} $(1)/usr/lib/libiconv-full/lib/ $(CP) $(PKG_INSTALL_DIR)/usr/lib/libiconv.{a,so*} $(1)/usr/lib/libiconv-full/lib/
$(INSTALL_DIR) $(1)/usr/bin
$(CP) $(PKG_INSTALL_DIR)/usr/bin/iconv $(1)/usr/bin/
endef endef
define Package/libcharset/install define Package/libcharset/install