open-ameba/RTL00_SDKV35a/component/common/api/wifi/wifi_conf.c

2000 lines
56 KiB
C
Raw Normal View History

2016-11-09 00:56:41 +00:00
//----------------------------------------------------------------------------//
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
#include <lwip_netconf.h>
#include "main.h"
#include <dhcp/dhcps.h>
#include <platform/platform_stdlib.h>
#include <wifi/wifi_conf.h>
#include <wifi/wifi_util.h>
#include <wifi/wifi_ind.h>
#include "tcpip.h"
#include <osdep_service.h>
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
#include "wlan_fast_connect/example_wlan_fast_connect.h"
#endif
#if CONFIG_EXAMPLE_UART_ATCMD
#include "at_cmd/atcmd_wifi.h"
#endif
#if CONFIG_INIC_EN
extern int inic_start(void);
extern int inic_stop(void);
#endif
2017-04-10 12:32:02 +00:00
#include "wifi_api.h"
2017-02-01 11:57:01 +00:00
#include "wlan_lib.h"
2016-11-09 00:56:41 +00:00
#if CONFIG_DEBUG_LOG > 0
2017-03-02 08:46:28 +00:00
#undef printf
#define printf(...) rtl_printf(__VA_ARGS__)
2016-11-09 00:56:41 +00:00
#else
2017-03-02 08:46:28 +00:00
#undef printf
#define printf(...)
2016-11-09 00:56:41 +00:00
#endif
2017-03-05 23:22:35 +00:00
//#define sscanf _sscanf
2017-03-04 10:24:48 +00:00
2017-03-13 03:32:42 +00:00
#define SHOW_PRIVATE_OUT 0 // =0 - off, = 1 On
2016-11-09 00:56:41 +00:00
/******************************************************
* Constants
******************************************************/
#define SCAN_USE_SEMAPHORE 0
#define RTW_JOIN_TIMEOUT 15000
#define JOIN_ASSOCIATED (uint32_t)(1 << 0)
#define JOIN_AUTHENTICATED (uint32_t)(1 << 1)
#define JOIN_LINK_READY (uint32_t)(1 << 2)
#define JOIN_SECURITY_COMPLETE (uint32_t)(1 << 3)
#define JOIN_COMPLETE (uint32_t)(1 << 4)
#define JOIN_NO_NETWORKS (uint32_t)(1 << 5)
#define JOIN_WRONG_SECURITY (uint32_t)(1 << 6)
#define JOIN_HANDSHAKE_DONE (uint32_t)(1 << 7)
#define JOIN_SIMPLE_CONFIG (uint32_t)(1 << 8)
#define JOIN_AIRKISS (uint32_t)(1 << 9)
/******************************************************
* Type Definitions
******************************************************/
/******************************************************
* Variables Declarations
******************************************************/
2017-03-05 23:22:35 +00:00
2016-11-09 00:56:41 +00:00
extern struct netif xnetif[NET_IF_NUM];
/******************************************************
* Variables Definitions
******************************************************/
2017-03-02 08:46:28 +00:00
static internal_scan_handler_t scan_result_handler_ptr = { 0, 0, 0, RTW_FALSE,
0, 0, 0, 0, 0 };
2016-11-09 00:56:41 +00:00
static internal_join_result_t* join_user_data;
2017-03-05 23:22:35 +00:00
rtw_mode_t wifi_mode = RTW_MODE_NONE;
//extern rtw_mode_t wifi_mode;
2016-11-09 00:56:41 +00:00
int error_flag = RTW_UNKNOWN;
uint32_t rtw_join_status;
#if ATCMD_VER == ATVER_2
extern unsigned char dhcp_mode_sta;
#endif
/******************************************************
* Variables Definitions
******************************************************/
#ifndef WLAN0_NAME
2017-03-02 08:46:28 +00:00
#define WLAN0_NAME "wlan0"
2016-11-09 00:56:41 +00:00
#endif
#ifndef WLAN1_NAME
2017-03-02 08:46:28 +00:00
#define WLAN1_NAME "wlan1"
2016-11-09 00:56:41 +00:00
#endif
/* Give default value if not defined */
#ifndef NET_IF_NUM
#ifdef CONFIG_CONCURRENT_MODE
#define NET_IF_NUM 2
#else
#define NET_IF_NUM 1
#endif
#endif
/*Static IP ADDRESS*/
#ifndef IP_ADDR0
#define IP_ADDR0 192
#define IP_ADDR1 168
#define IP_ADDR2 1
#define IP_ADDR3 80
#endif
/*NETMASK*/
#ifndef NETMASK_ADDR0
#define NETMASK_ADDR0 255
#define NETMASK_ADDR1 255
#define NETMASK_ADDR2 255
#define NETMASK_ADDR3 0
#endif
/*Gateway Address*/
#ifndef GW_ADDR0
#define GW_ADDR0 192
#define GW_ADDR1 168
#define GW_ADDR2 1
#define GW_ADDR3 1
#endif
/*Static IP ADDRESS*/
#ifndef AP_IP_ADDR0
#define AP_IP_ADDR0 192
#define AP_IP_ADDR1 168
#define AP_IP_ADDR2 43
#define AP_IP_ADDR3 1
#endif
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
/*NETMASK*/
#ifndef AP_NETMASK_ADDR0
#define AP_NETMASK_ADDR0 255
#define AP_NETMASK_ADDR1 255
#define AP_NETMASK_ADDR2 255
#define AP_NETMASK_ADDR3 0
#endif
/*Gateway Address*/
#ifndef AP_GW_ADDR0
#define AP_GW_ADDR0 192
#define AP_GW_ADDR1 168
#define AP_GW_ADDR2 43
#define AP_GW_ADDR3 1
#endif
/******************************************************
* Function Definitions
******************************************************/
#if CONFIG_WLAN
#define DD_WIFI_CONN 0 // pvvx
//----------------------------------------------------------------------start-patch//
#include "freertos/wrapper.h"
#include "skbuff.h"
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
//------------------------------------------------------------------------end-patch//
2017-03-02 08:46:28 +00:00
static int wifi_connect_local(rtw_network_info_t *pWifi) {
2016-11-09 00:56:41 +00:00
int ret = 0;
2017-03-02 08:46:28 +00:00
if (is_promisc_enabled())
2016-11-09 00:56:41 +00:00
promisc_set(0, NULL, 0);
2017-03-02 08:46:28 +00:00
if (!pWifi)
return -1;
switch (pWifi->security_type) {
case RTW_SECURITY_OPEN:
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0,
NULL, 0);
break;
case RTW_SECURITY_WEP_PSK:
case RTW_SECURITY_WEP_SHARED:
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_SHARED_KEY);
if (ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL,
pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password,
pWifi->password_len);
break;
case RTW_SECURITY_WPA_TKIP_PSK:
case RTW_SECURITY_WPA2_TKIP_PSK:
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_OPEN_SYSTEM);
if (ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0,
0, 0, NULL, 0);
if (ret == 0)
ret = wext_set_passphrase(WLAN0_NAME, pWifi->password,
pWifi->password_len);
break;
case RTW_SECURITY_WPA_AES_PSK:
case RTW_SECURITY_WPA2_AES_PSK:
case RTW_SECURITY_WPA2_MIXED_PSK:
case RTW_SECURITY_WPA_WPA2_MIXED:
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_OPEN_SYSTEM);
if (ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0,
0, 0, NULL, 0);
if (ret == 0)
ret = wext_set_passphrase(WLAN0_NAME, pWifi->password,
pWifi->password_len);
break;
default:
ret = -1;
error_printf("%s: security type(0x%x) is not supported!\n",
pWifi->security_type, __func__);
break;
2016-11-09 00:56:41 +00:00
}
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
if(ret == 0)
2017-03-02 08:46:28 +00:00
ret = wext_set_ssid(WLAN0_NAME, pWifi->ssid.val, pWifi->ssid.len);
2016-11-09 00:56:41 +00:00
#endif
return ret;
}
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
static int wifi_connect_bssid_local(rtw_network_info_t *pWifi)
{
int ret = 0;
u8 bssid[12] = {0};
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
if(is_promisc_enabled())
2017-03-02 08:46:28 +00:00
promisc_set(0, NULL, 0);
2016-11-09 00:56:41 +00:00
if(!pWifi) return -1;
2017-03-02 08:46:28 +00:00
switch(pWifi->security_type) {
2016-11-09 00:56:41 +00:00
case RTW_SECURITY_OPEN:
2017-03-02 08:46:28 +00:00
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_NONE, NULL, 0, 0, 0, 0, NULL, 0);
break;
2016-11-09 00:56:41 +00:00
case RTW_SECURITY_WEP_PSK:
case RTW_SECURITY_WEP_SHARED:
2017-03-02 08:46:28 +00:00
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_SHARED_KEY);
if(ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_WEP, NULL, pWifi->key_id, 1 /* set tx key */, 0, 0, pWifi->password, pWifi->password_len);
break;
2016-11-09 00:56:41 +00:00
case RTW_SECURITY_WPA_TKIP_PSK:
case RTW_SECURITY_WPA2_TKIP_PSK:
2017-03-02 08:46:28 +00:00
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
if(ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_TKIP, NULL, 0, 0, 0, 0, NULL, 0);
if(ret == 0)
ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
break;
2016-11-09 00:56:41 +00:00
case RTW_SECURITY_WPA_AES_PSK:
case RTW_SECURITY_WPA2_AES_PSK:
case RTW_SECURITY_WPA2_MIXED_PSK:
2017-03-02 08:46:28 +00:00
ret = wext_set_auth_param(WLAN0_NAME, IW_AUTH_80211_AUTH_ALG, IW_AUTH_ALG_OPEN_SYSTEM);
if(ret == 0)
ret = wext_set_key_ext(WLAN0_NAME, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0, NULL, 0);
if(ret == 0)
ret = wext_set_passphrase(WLAN0_NAME, pWifi->password, pWifi->password_len);
break;
2016-11-09 00:56:41 +00:00
default:
2017-03-02 08:46:28 +00:00
ret = -1;
printf("WIFICONF: security type(0x%x) is not supported.\n", pWifi->security_type);
break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if(ret == 0) {
2016-11-09 00:56:41 +00:00
memcpy(bssid, pWifi->bssid.octet, ETH_ALEN);
2017-03-02 08:46:28 +00:00
if(pWifi->ssid.len) {
2016-11-09 00:56:41 +00:00
bssid[ETH_ALEN] = '#';
bssid[ETH_ALEN + 1] = '@';
memcpy(bssid + ETH_ALEN + 2, &pWifi, sizeof(pWifi));
}
ret = wext_set_bssid(WLAN0_NAME, bssid);
}
return ret;
}
#endif
2017-03-02 08:46:28 +00:00
void wifi_rx_beacon_hdl(char* buf, int buf_len, int flags, void* userdata) {
2016-11-09 00:56:41 +00:00
//printf("Beacon!\n");
}
2017-03-02 08:46:28 +00:00
static void wifi_no_network_hdl(char* buf, int buf_len, int flags,
void* userdata) {
if (join_user_data != NULL)
rtw_join_status = JOIN_NO_NETWORKS;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
static void wifi_connected_hdl(char* buf, int buf_len, int flags,
void* userdata) {
2016-11-09 00:56:41 +00:00
#ifdef CONFIG_ENABLE_EAP
2017-03-02 08:46:28 +00:00
if(get_eap_phase()) {
2016-11-09 00:56:41 +00:00
rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
return;
}
#endif /* CONFIG_ENABLE_EAP */
2017-03-02 08:46:28 +00:00
if ((join_user_data != NULL)
&& ((join_user_data->network_info.security_type == RTW_SECURITY_OPEN)
|| (join_user_data->network_info.security_type
== RTW_SECURITY_WEP_PSK))) {
rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE
| JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
2016-11-09 00:56:41 +00:00
rtw_up_sema(&join_user_data->join_sema);
2017-03-02 08:46:28 +00:00
} else if ((join_user_data != NULL)
&& ((join_user_data->network_info.security_type
== RTW_SECURITY_WPA2_AES_PSK))) {
rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE
| JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY;
2016-11-09 00:56:41 +00:00
}
}
2017-03-02 08:46:28 +00:00
static void wifi_handshake_done_hdl(char* buf, int buf_len, int flags,
void* userdata) {
rtw_join_status = JOIN_COMPLETE | JOIN_SECURITY_COMPLETE | JOIN_ASSOCIATED
| JOIN_AUTHENTICATED | JOIN_LINK_READY | JOIN_HANDSHAKE_DONE;
if (join_user_data != NULL)
2016-11-09 00:56:41 +00:00
rtw_up_sema(&join_user_data->join_sema);
}
2017-03-02 08:46:28 +00:00
static void wifi_disconn_hdl(char* buf, int buf_len, int flags, void* userdata) {
if (join_user_data != NULL) {
if (join_user_data->network_info.security_type == RTW_SECURITY_OPEN) {
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (rtw_join_status == JOIN_NO_NETWORKS)
2016-11-09 00:56:41 +00:00
error_flag = RTW_NONE_NETWORK;
2017-03-02 08:46:28 +00:00
} else if (join_user_data->network_info.security_type
== RTW_SECURITY_WEP_PSK) {
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (rtw_join_status == JOIN_NO_NETWORKS)
2016-11-09 00:56:41 +00:00
error_flag = RTW_NONE_NETWORK;
2017-03-02 08:46:28 +00:00
else if (rtw_join_status == 0)
error_flag = RTW_CONNECT_FAIL;
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
} else if (join_user_data->network_info.security_type
== RTW_SECURITY_WPA2_AES_PSK) {
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (rtw_join_status == JOIN_NO_NETWORKS)
2016-11-09 00:56:41 +00:00
error_flag = RTW_NONE_NETWORK;
2017-03-02 08:46:28 +00:00
else if (rtw_join_status == 0)
error_flag = RTW_CONNECT_FAIL;
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
else if (rtw_join_status == JOIN_COMPLETE | JOIN_SECURITY_COMPLETE
| JOIN_ASSOCIATED | JOIN_AUTHENTICATED | JOIN_LINK_READY)
error_flag = RTW_WRONG_PASSWORD;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
} else {
if (error_flag == RTW_NO_ERROR) //wifi_disconn_hdl will be dispatched one more time after join_user_data = NULL add by frankie
2016-11-09 00:56:41 +00:00
error_flag = RTW_UNKNOWN;
}
2017-03-02 08:46:28 +00:00
if (join_user_data != NULL)
2016-11-09 00:56:41 +00:00
rtw_up_sema(&join_user_data->join_sema);
2017-03-02 08:46:28 +00:00
#if CONFIG_DEBUG_LOG > 4
info_printf("%s: Error flag is %d!\n", __func__, error_flag);
#endif
2016-11-09 00:56:41 +00:00
}
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
#define WLAN0_NAME "wlan0" // ?????
2017-03-02 08:46:28 +00:00
void restore_wifi_info_to_flash() {
2016-11-09 00:56:41 +00:00
struct wlan_fast_reconnect * data_to_flash;
u32 channel = 0;
u8 index = 0;
2017-03-02 08:46:28 +00:00
u8 *ifname[1] = { WLAN0_NAME };
2016-11-09 00:56:41 +00:00
rtw_wifi_setting_t setting;
//struct security_priv *psecuritypriv = &padapter->securitypriv;
//WLAN_BSSID_EX *pcur_bss = pmlmepriv->cur_network.network;
2017-03-02 08:46:28 +00:00
data_to_flash = (struct wlan_fast_reconnect *) rtw_zmalloc(
sizeof(struct wlan_fast_reconnect));
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (data_to_flash && p_write_reconnect_ptr) {
if (wifi_get_setting((const char*) ifname[0], &setting)
|| setting.mode == RTW_MODE_AP) {
2016-11-09 00:56:41 +00:00
printf(" %s():wifi_get_setting fail or ap mode\n", __func__);
return;
}
channel = setting.channel;
rtw_memset(psk_essid[index], 0, sizeof(psk_essid[index]));
strncpy(psk_essid[index], setting.ssid, strlen(setting.ssid));
2017-03-02 08:46:28 +00:00
switch (setting.security_type) {
case RTW_SECURITY_OPEN:
rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
data_to_flash->security_type = RTW_SECURITY_OPEN;
break;
case RTW_SECURITY_WEP_PSK:
channel |= (setting.key_idx) << 28;
rtw_memset(psk_passphrase[index], 0, sizeof(psk_passphrase[index]));
rtw_memset(wpa_global_PSK[index], 0, sizeof(wpa_global_PSK[index]));
rtw_memcpy(psk_passphrase[index], setting.password,
sizeof(psk_passphrase[index]));
data_to_flash->security_type = RTW_SECURITY_WEP_PSK;
break;
case RTW_SECURITY_WPA_TKIP_PSK:
data_to_flash->security_type = RTW_SECURITY_WPA_TKIP_PSK;
break;
case RTW_SECURITY_WPA2_AES_PSK:
data_to_flash->security_type = RTW_SECURITY_WPA2_AES_PSK;
break;
default:
break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
memcpy(data_to_flash->psk_essid, psk_essid[index],
sizeof(data_to_flash->psk_essid));
2016-11-09 00:56:41 +00:00
if (strlen(psk_passphrase64) == 64) {
2017-03-02 08:46:28 +00:00
memcpy(data_to_flash->psk_passphrase, psk_passphrase64,
sizeof(data_to_flash->psk_passphrase));
2016-11-09 00:56:41 +00:00
} else {
2017-03-02 08:46:28 +00:00
memcpy(data_to_flash->psk_passphrase, psk_passphrase[index],
sizeof(data_to_flash->psk_passphrase));
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
memcpy(data_to_flash->wpa_global_PSK, wpa_global_PSK[index],
sizeof(data_to_flash->wpa_global_PSK));
2016-11-09 00:56:41 +00:00
memcpy(&(data_to_flash->channel), &channel, 4);
//call callback function in user program
2017-03-02 08:46:28 +00:00
p_write_reconnect_ptr((u8 *) data_to_flash,
sizeof(struct wlan_fast_reconnect));
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (data_to_flash)
2016-11-09 00:56:41 +00:00
rtw_free(data_to_flash);
}
#endif
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_connect(char *ssid, rtw_security_t security_type, char *password,
int ssid_len, int password_len, int key_id, void *semaphore) {
2016-11-09 00:56:41 +00:00
xSemaphoreHandle join_semaphore;
rtw_result_t result = RTW_SUCCESS;
u8 wep_hex = 0;
2017-03-02 08:46:28 +00:00
u8 wep_pwd[14] = { 0 };
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if ((rtw_join_status & JOIN_SIMPLE_CONFIG )
|| (rtw_join_status & JOIN_AIRKISS )) {
2016-11-09 00:56:41 +00:00
return RTW_ERROR;
}
2017-03-02 08:46:28 +00:00
rtw_join_status = 0; //clear for last connect status
error_flag = RTW_UNKNOWN; //clear for last connect status
if ((((password_len > RTW_MAX_PSK_LEN) || (password_len < RTW_MIN_PSK_LEN))
&& ((security_type == RTW_SECURITY_WPA_TKIP_PSK)
|| (security_type == RTW_SECURITY_WPA_AES_PSK)
|| (security_type == RTW_SECURITY_WPA2_AES_PSK)
|| (security_type == RTW_SECURITY_WPA2_TKIP_PSK)
|| (security_type == RTW_SECURITY_WPA2_MIXED_PSK)))) {
error_flag = RTW_WRONG_PASSWORD;
2016-11-09 00:56:41 +00:00
return RTW_INVALID_KEY;
}
2017-03-02 08:46:28 +00:00
if ((security_type == RTW_SECURITY_WEP_PSK)
|| (security_type == RTW_SECURITY_WEP_SHARED)) {
if ((password_len != 5) && (password_len != 13) && (password_len != 10)
&& (password_len != 26)) {
error_flag = RTW_WRONG_PASSWORD;
2016-11-09 00:56:41 +00:00
return RTW_INVALID_KEY;
} else {
2017-03-02 08:46:28 +00:00
if (password_len == 10) {
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
u32 p[5] = { 0 };
u8 i = 0;
sscanf((const char*) password, "%02x%02x%02x%02x%02x", &p[0],
&p[1], &p[2], &p[3], &p[4]);
for (i = 0; i < 5; i++)
wep_pwd[i] = (u8) p[i];
2016-11-09 00:56:41 +00:00
wep_pwd[5] = '\0';
password_len = 5;
wep_hex = 1;
} else if (password_len == 26) {
2017-03-02 08:46:28 +00:00
u32 p[13] = { 0 };
2016-11-09 00:56:41 +00:00
u8 i = 0;
2017-03-02 08:46:28 +00:00
sscanf((const char*) password, "%02x%02x%02x%02x%02x%02x%02x"
"%02x%02x%02x%02x%02x%02x", &p[0], &p[1], &p[2], &p[3],
&p[4], &p[5], &p[6], &p[7], &p[8], &p[9], &p[10],
&p[11], &p[12]);
for (i = 0; i < 13; i++)
wep_pwd[i] = (u8) p[i];
2016-11-09 00:56:41 +00:00
wep_pwd[13] = '\0';
password_len = 13;
wep_hex = 1;
}
}
}
2017-03-02 08:46:28 +00:00
internal_join_result_t *join_result =
(internal_join_result_t *) rtw_zmalloc(
sizeof(internal_join_result_t));
if (!join_result) {
#if CONFIG_DEBUG_LOG > 3
error_printf("%s: Can't malloc memory!\n", __func__);
#endif
2016-11-09 00:56:41 +00:00
return RTW_NOMEM;
}
join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len;
rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len);
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
join_result->network_info.password_len = password_len;
2017-03-02 08:46:28 +00:00
if (password_len) {
2016-11-09 00:56:41 +00:00
/* add \0 to the end */
join_result->network_info.password = rtw_zmalloc(password_len + 1);
2017-03-02 08:46:28 +00:00
if (!join_result->network_info.password) {
2016-11-09 00:56:41 +00:00
result = RTW_NOMEM;
2017-03-02 08:46:28 +00:00
#if CONFIG_DEBUG_LOG > 3
error_printf("%s: Can't malloc memory!\n", __func__);
#endif
2016-11-09 00:56:41 +00:00
goto error;
}
if (0 == wep_hex)
2017-03-02 08:46:28 +00:00
rtw_memcpy(join_result->network_info.password, password,
password_len);
2016-11-09 00:56:41 +00:00
else
2017-03-02 08:46:28 +00:00
rtw_memcpy(join_result->network_info.password, wep_pwd,
password_len);
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
join_result->network_info.security_type = security_type;
join_result->network_info.key_id = key_id;
2017-03-02 08:46:28 +00:00
if (semaphore == NULL) {
rtw_init_sema(&join_result->join_sema, 0);
if (!join_result->join_sema) {
2016-11-09 00:56:41 +00:00
result = RTW_NORESOURCE;
goto error;
}
join_semaphore = join_result->join_sema;
} else {
join_result->join_sema = semaphore;
}
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK, wifi_no_network_hdl, NULL);
2016-11-09 00:56:41 +00:00
wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL);
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
wifi_handshake_done_hdl, NULL);
2016-11-09 00:56:41 +00:00
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
wifi_connect_local(&join_result->network_info);
#else
2017-03-02 08:46:28 +00:00
if (wifi_connect_local(&join_result->network_info) == 0)
wext_set_ssid(WLAN0_NAME, join_result->network_info.ssid.val,
join_result->network_info.ssid.len);
2016-11-09 00:56:41 +00:00
#endif
join_user_data = join_result;
2017-03-02 08:46:28 +00:00
if (semaphore == NULL) {
2016-11-09 00:56:41 +00:00
// for eap connection, timeout should be longer (default value in wpa_supplicant: 60s)
#ifdef CONFIG_ENABLE_EAP
2017-03-02 08:46:28 +00:00
if(get_eap_phase()) {
2016-11-09 00:56:41 +00:00
if(rtw_down_timeout_sema( &join_result->join_sema, 60000 ) == RTW_FALSE) {
printf("RTW API: Join bss timeout\n");
if(password_len) {
rtw_free(join_result->network_info.password);
}
result = RTW_TIMEOUT;
goto error;
} else {
if(wifi_is_connected_to_ap( ) != RTW_SUCCESS) {
result = RTW_ERROR;
goto error;
}
}
}
else
#endif
2017-03-02 08:46:28 +00:00
if (rtw_down_timeout_sema(&join_result->join_sema, RTW_JOIN_TIMEOUT)
== RTW_FALSE) {
2016-11-09 00:56:41 +00:00
printf("RTW API: Join bss timeout\n");
2017-03-02 08:46:28 +00:00
if (password_len) {
2016-11-09 00:56:41 +00:00
rtw_free(join_result->network_info.password);
}
result = RTW_TIMEOUT;
goto error;
} else {
2017-03-02 08:46:28 +00:00
if (join_result->network_info.password_len) {
2016-11-09 00:56:41 +00:00
rtw_free(join_result->network_info.password);
}
2017-03-02 08:46:28 +00:00
if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
2016-11-09 00:56:41 +00:00
result = RTW_ERROR;
goto error;
}
}
}
result = RTW_SUCCESS;
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
restore_wifi_info_to_flash();
#endif
2017-03-02 08:46:28 +00:00
error: if (semaphore == NULL) {
rtw_free_sema(&join_semaphore);
2016-11-09 00:56:41 +00:00
}
join_user_data = NULL;
rtw_free((u8*)join_result);
wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl);
2017-03-02 08:46:28 +00:00
wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK, wifi_no_network_hdl);
wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
wifi_handshake_done_hdl);
2016-11-09 00:56:41 +00:00
return result;
}
2017-03-02 08:46:28 +00:00
int wifi_connect_bssid(unsigned char bssid[ETH_ALEN], char *ssid,
rtw_security_t security_type, char *password, int bssid_len,
int ssid_len, int password_len, int key_id, void *semaphore) {
2016-11-09 00:56:41 +00:00
xSemaphoreHandle join_semaphore;
rtw_result_t result = RTW_SUCCESS;
2017-03-02 08:46:28 +00:00
if ((rtw_join_status & JOIN_SIMPLE_CONFIG )
|| (rtw_join_status & JOIN_AIRKISS )) {
return RTW_ERROR;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
rtw_join_status = 0; //clear for last connect status
error_flag = RTW_UNKNOWN; //clear for last connect status
internal_join_result_t *join_result =
(internal_join_result_t *) rtw_zmalloc(
sizeof(internal_join_result_t));
if (!join_result) {
2016-11-09 00:56:41 +00:00
return RTW_NOMEM;
}
2017-03-02 08:46:28 +00:00
if (ssid_len && ssid) {
2016-11-09 00:56:41 +00:00
join_result->network_info.ssid.len = ssid_len > 32 ? 32 : ssid_len;
rtw_memcpy(join_result->network_info.ssid.val, ssid, ssid_len);
}
rtw_memcpy(join_result->network_info.bssid.octet, bssid, bssid_len);
2017-03-02 08:46:28 +00:00
if ((((password_len > RTW_MAX_PSK_LEN) || (password_len < RTW_MIN_PSK_LEN))
&& ((security_type == RTW_SECURITY_WPA_TKIP_PSK)
|| (security_type == RTW_SECURITY_WPA_AES_PSK)
|| (security_type == RTW_SECURITY_WPA2_AES_PSK)
|| (security_type == RTW_SECURITY_WPA2_TKIP_PSK)
|| (security_type == RTW_SECURITY_WPA2_MIXED_PSK)))
|| (((password_len != 5) && (password_len != 13))
&& ((security_type == RTW_SECURITY_WEP_PSK)
|| (security_type == RTW_SECURITY_WEP_SHARED)))) {
2016-11-09 00:56:41 +00:00
return RTW_INVALID_KEY;
}
join_result->network_info.password_len = password_len;
2017-03-02 08:46:28 +00:00
if (password_len) {
2016-11-09 00:56:41 +00:00
/* add \0 to the end */
join_result->network_info.password = rtw_zmalloc(password_len + 1);
2017-03-02 08:46:28 +00:00
if (!join_result->network_info.password) {
2016-11-09 00:56:41 +00:00
return RTW_NOMEM;
}
rtw_memcpy(join_result->network_info.password, password, password_len);
}
2017-03-02 08:46:28 +00:00
join_result->network_info.security_type = security_type;
join_result->network_info.key_id = key_id;
if (semaphore == NULL) {
rtw_init_sema(&join_result->join_sema, 0);
if (!join_result->join_sema) {
return RTW_NORESOURCE;
2016-11-09 00:56:41 +00:00
}
join_semaphore = join_result->join_sema;
} else {
join_result->join_sema = semaphore;
}
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK, wifi_no_network_hdl, NULL);
2016-11-09 00:56:41 +00:00
wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL);
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
wifi_handshake_done_hdl, NULL);
2016-11-09 00:56:41 +00:00
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
wifi_connect_bssid_local(&join_result->network_info);
#else
rtw_network_info_t *pWifi = &join_result->network_info;
2017-03-02 08:46:28 +00:00
if (wifi_connect_local(pWifi) == 0) {
struct {
2016-11-09 00:56:41 +00:00
u8 bssid[ETH_ALEN + 2];
void * p;
2017-03-02 08:46:28 +00:00
} bs = { 0 };
2016-11-09 00:56:41 +00:00
memcpy(bs.bssid, pWifi->bssid.octet, ETH_ALEN);
2017-03-02 08:46:28 +00:00
if (pWifi->ssid.len) {
2016-11-09 00:56:41 +00:00
bs.bssid[ETH_ALEN] = '#';
bs.bssid[ETH_ALEN + 1] = '@';
bs.p = pWifi;
}
wext_set_bssid(WLAN0_NAME, bssid);
}
#endif
join_user_data = join_result;
2017-03-02 08:46:28 +00:00
if (semaphore == NULL) {
if (rtw_down_timeout_sema(&join_result->join_sema, RTW_JOIN_TIMEOUT)
== RTW_FALSE) {
2016-11-09 00:56:41 +00:00
printf("RTW API: Join bss timeout\n");
2017-03-02 08:46:28 +00:00
if (password_len) {
2016-11-09 00:56:41 +00:00
rtw_free(join_result->network_info.password);
}
rtw_free((u8*)join_result);
2017-03-02 08:46:28 +00:00
rtw_free_sema(&join_semaphore);
2016-11-09 00:56:41 +00:00
result = RTW_TIMEOUT;
goto error;
} else {
2017-03-02 08:46:28 +00:00
rtw_free_sema(&join_semaphore);
if (join_result->network_info.password_len) {
2016-11-09 00:56:41 +00:00
rtw_free(join_result->network_info.password);
}
rtw_free((u8*)join_result);
2017-03-02 08:46:28 +00:00
if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
2016-11-09 00:56:41 +00:00
result = RTW_ERROR;
goto error;
}
}
}
result = RTW_SUCCESS;
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
restore_wifi_info_to_flash();
#endif
2017-03-02 08:46:28 +00:00
error: join_user_data = NULL;
2016-11-09 00:56:41 +00:00
wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl);
2017-03-02 08:46:28 +00:00
wifi_unreg_event_handler(WIFI_EVENT_NO_NETWORK, wifi_no_network_hdl);
wifi_unreg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
wifi_handshake_done_hdl);
2016-11-09 00:56:41 +00:00
return result;
}
2017-03-02 08:46:28 +00:00
int wifi_disconnect(void) {
2016-11-09 00:56:41 +00:00
int ret = 0;
//set MAC address last byte to 1 since driver will filter the mac with all 0x00 or 0xff
//add extra 2 zero byte for check of #@ in wext_set_bssid()
2017-03-02 08:46:28 +00:00
const __u8 null_bssid[ETH_ALEN + 2] = { 0, 0, 0, 0, 0, 1, 0, 0 };
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (wext_set_bssid(WLAN0_NAME, null_bssid) < 0) {
error_printf("WEXT: Failed to set bogus BSSID to disconnect\n");
2016-11-09 00:56:41 +00:00
ret = -1;
}
return ret;
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_is_connected_to_ap(void) {
2016-11-09 00:56:41 +00:00
return rltk_wlan_is_connected_to_ap();
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_is_up(rtw_interface_t interface) {
if (interface == RTW_AP_INTERFACE && wifi_mode == RTW_MODE_STA_AP)
return rltk_wlan_running(WLAN1_IDX);
2016-11-09 00:56:41 +00:00
return rltk_wlan_running(WLAN0_IDX);
}
2017-03-02 08:46:28 +00:00
int wifi_is_ready_to_transceive(rtw_interface_t interface) {
switch (interface) {
case RTW_AP_INTERFACE:
return (wifi_is_up(interface) == RTW_TRUE) ? RTW_SUCCESS : RTW_ERROR;
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
case RTW_STA_INTERFACE:
if (error_flag == RTW_NO_ERROR)
return RTW_SUCCESS;
break;
}
return RTW_ERROR;
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_mac_address(char * mac) {
char buf[13 + 17 + 1];
2016-11-09 00:56:41 +00:00
rtw_memset(buf, 0, sizeof(buf));
2017-03-02 08:46:28 +00:00
snprintf(buf, 13 + 17, "write_mac %s", mac);
2016-11-09 00:56:41 +00:00
return wext_private_command(WLAN0_NAME, buf, SHOW_PRIVATE_OUT);
}
2017-03-02 08:46:28 +00:00
int wifi_get_mac_address(char * mac) {
2016-11-09 00:56:41 +00:00
int ret = 0;
char buf[32];
rtw_memset(buf, 0, sizeof(buf));
rtw_memcpy(buf, "read_mac", 8);
ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, 32);
#if SHOW_PRIVATE_OUT
rtl_printf("%s\n", buf);
#endif
strcpy(mac, buf);
return ret;
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_enable_powersave(void) {
2016-11-09 00:56:41 +00:00
return wext_enable_powersave(WLAN0_NAME, 1, 1);
}
2017-03-02 08:46:28 +00:00
int wifi_disable_powersave(void) {
2016-11-09 00:56:41 +00:00
return wext_disable_powersave(WLAN0_NAME);
}
2017-03-13 03:32:42 +00:00
#if 0 //Not ready
2016-11-09 00:56:41 +00:00
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_get_txpower(int *poweridx) {
2016-11-09 00:56:41 +00:00
int ret;
2017-03-13 03:32:42 +00:00
// char buf[11];
char buf[64];
2016-11-09 00:56:41 +00:00
rtw_memset(buf, 0, sizeof(buf));
rtw_memcpy(buf, "txpower", 11);
2017-03-13 03:32:42 +00:00
ret = wext_private_command_with_retval(WLAN0_NAME, buf, buf, sizeof(buf));
2016-11-09 00:56:41 +00:00
#if SHOW_PRIVATE_OUT
rtl_printf("%s\n", buf);
#endif
sscanf(buf, "%d", poweridx);
return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_set_txpower(int poweridx) {
2016-11-09 00:56:41 +00:00
int ret;
char buf[24];
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
rtw_memset(buf, 0, sizeof(buf));
snprintf(buf, 24, "txpower patha=%d,pathb=%d", poweridx, poweridx); // patha=%d,pathb=%d ?
ret = wext_private_command(WLAN0_NAME, buf, SHOW_PRIVATE_OUT);
return ret;
}
#endif
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_get_associated_client_list(void * client_list_buffer,
uint16_t buffer_length) {
2016-11-09 00:56:41 +00:00
const char * ifname = WLAN0_NAME;
int ret = 0;
char buf[25];
2017-03-02 08:46:28 +00:00
if (wifi_mode == RTW_MODE_STA_AP) {
2016-11-09 00:56:41 +00:00
ifname = WLAN1_NAME;
}
rtw_memset(buf, 0, sizeof(buf));
snprintf(buf, 25, "get_client_list %x", client_list_buffer);
ret = wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
return ret;
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_get_ap_info(rtw_bss_info_t * ap_info, rtw_security_t* security) {
2016-11-09 00:56:41 +00:00
const char * ifname = WLAN0_NAME;
int ret = 0;
char buf[24];
2017-03-02 08:46:28 +00:00
if (wifi_mode == RTW_MODE_STA_AP) {
2016-11-09 00:56:41 +00:00
ifname = WLAN1_NAME;
}
rtw_memset(buf, 0, sizeof(buf));
snprintf(buf, 24, "get_ap_info %x", ap_info);
ret = wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
snprintf(buf, 24, "get_security");
ret = wext_private_command_with_retval(ifname, buf, buf, 24);
#if SHOW_PRIVATE_OUT
rtl_printf("%s\n", buf);
#endif
sscanf(buf, "%d", security);
return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_get_drv_ability(uint32_t *ability) {
2016-11-09 00:56:41 +00:00
return wext_get_drv_ability(WLAN0_NAME, ability);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_country(rtw_country_code_t country_code) {
2017-04-10 12:32:02 +00:00
return wext_set_country(WLAN0_NAME, country_code);
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_channel_plan(uint8_t channel_plan) {
2016-11-09 00:56:41 +00:00
const char * ifname = WLAN0_NAME;
char buf[24];
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
rtw_memset(buf, 0, sizeof(buf));
snprintf(buf, 24, "set_ch_plan %x", channel_plan);
2017-04-10 12:32:02 +00:00
return wext_private_command(ifname, buf, SHOW_PRIVATE_OUT);
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_get_rssi(int *pRSSI) {
2016-11-09 00:56:41 +00:00
return wext_get_rssi(WLAN0_NAME, pRSSI);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_channel(int channel) {
2016-11-09 00:56:41 +00:00
return wext_set_channel(WLAN0_NAME, channel);
}
2017-03-02 08:46:28 +00:00
int wifi_get_channel(int *channel) {
return wext_get_channel(WLAN0_NAME, (u8*) channel);
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_register_multicast_address(rtw_mac_t *mac) {
2016-11-09 00:56:41 +00:00
return wext_register_multicast_address(WLAN0_NAME, mac);
}
2017-03-02 08:46:28 +00:00
int wifi_unregister_multicast_address(rtw_mac_t *mac) {
2016-11-09 00:56:41 +00:00
return wext_unregister_multicast_address(WLAN0_NAME, mac);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
void wifi_set_mib(void) {
2016-11-09 00:56:41 +00:00
// adaptivity
wext_set_adaptivity(RTW_ADAPTIVITY_DISABLE);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_rf_on(void) {
2017-04-10 12:32:02 +00:00
return rltk_wlan_rf_on();
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_rf_off(void) {
2017-04-10 12:32:02 +00:00
return rltk_wlan_rf_off();
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_on(rtw_mode_t mode) {
2016-11-22 04:48:09 +00:00
int ret = 0;
2017-02-28 07:40:07 +00:00
//pvvx int timeout = 20; // 20 sec ?!
2017-03-02 08:46:28 +00:00
int timeout = wifi_test_timeout_ms / wifi_test_timeout_step_ms;
2016-11-09 00:56:41 +00:00
int idx;
int devnum = 1;
static int event_init = 0;
2017-03-02 08:46:28 +00:00
if (rltk_wlan_running(WLAN0_IDX)) {
2016-11-09 00:56:41 +00:00
printf("WIFI is already running\n");
2016-11-22 04:48:09 +00:00
return 0;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (event_init == 0) {
2016-11-09 00:56:41 +00:00
init_event_callback_list();
event_init = 1;
}
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
wifi_mode = mode;
2017-03-02 08:46:28 +00:00
if (mode == RTW_MODE_STA_AP)
2016-11-09 00:56:41 +00:00
devnum = 2;
// set wifi mib
wifi_set_mib();
printf("Initializing WIFI ...\n");
2017-03-02 08:46:28 +00:00
for (idx = 0; idx < devnum; idx++) {
2016-11-09 00:56:41 +00:00
ret = rltk_wlan_init(idx, mode);
2017-03-02 08:46:28 +00:00
if (ret < 0)
2016-11-09 00:56:41 +00:00
return ret;
}
2017-03-02 08:46:28 +00:00
for (idx = 0; idx < devnum; idx++)
2016-11-09 00:56:41 +00:00
rltk_wlan_start(idx);
2017-03-02 08:46:28 +00:00
while (1) {
if (rltk_wlan_running(devnum - 1)) {
2016-11-09 00:56:41 +00:00
printf("WIFI initialized\n");
/*
2017-03-02 08:46:28 +00:00
* printf("set country code here\n");
* wifi_set_country(RTW_COUNTRY_US);
*/
2016-11-09 00:56:41 +00:00
break;
}
2017-03-02 08:46:28 +00:00
if (timeout == 0) {
2016-11-09 00:56:41 +00:00
printf("ERROR: Init WIFI timeout!\n");
break;
}
// vTaskDelay(1 * configTICK_RATE_HZ);
2017-03-02 08:46:28 +00:00
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
timeout--;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
#if CONFIG_INIC_EN
inic_start();
#endif
return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_off(void) {
2016-11-22 04:48:09 +00:00
// int ret = 0;
2017-02-28 07:40:07 +00:00
//pvvx int timeout = 20; // 20 sec ?!
2017-03-09 08:23:37 +00:00
uint32 timeout = xTaskGetTickCount();
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if ((rltk_wlan_running(WLAN0_IDX) == 0)
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
info_printf("WIFI is not running\n");
2016-11-09 00:56:41 +00:00
return 0;
}
#if CONFIG_LWIP_LAYER
dhcps_deinit();
LwIP_DHCP(0, DHCP_STOP);
#endif
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
2017-03-02 08:46:28 +00:00
if ((wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP))
wpas_wps_deinit();
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
info_printf("Deinitializing WIFI ...\n");
2017-03-03 17:16:46 +00:00
rltk_wlan_deinit();
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
while (1) {
if ((rltk_wlan_running(WLAN0_IDX) == 0)
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
2017-03-09 08:23:37 +00:00
// info_printf("WIFI deinitialized\n");
info_printf("WIFI deinitialized (%d ms)\n", xTaskGetTickCount() - timeout);
2016-11-09 00:56:41 +00:00
break;
}
2017-03-09 08:23:37 +00:00
if(xTaskGetTickCount() - timeout > wifi_test_timeout_ms/portTICK_RATE_MS) {
error_printf("WIFI deinitialized timeout!\n");
2016-11-09 00:56:41 +00:00
break;
}
2017-03-02 08:46:28 +00:00
vTaskDelay(10 / portTICK_RATE_MS);
2016-11-09 00:56:41 +00:00
}
wifi_mode = RTW_MODE_NONE;
#if CONFIG_INIC_EN
inic_stop();
#endif
2016-11-22 04:48:09 +00:00
return 1;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
int wifi_set_power_mode(unsigned char ips_mode, unsigned char lps_mode) {
2016-11-09 00:56:41 +00:00
return wext_enable_powersave(WLAN0_NAME, ips_mode, lps_mode);
}
2017-03-02 08:46:28 +00:00
int wifi_set_tdma_param(unsigned char slot_period,
unsigned char rfon_period_len_1, unsigned char rfon_period_len_2,
unsigned char rfon_period_len_3) {
return wext_set_tdma_param(WLAN0_NAME, slot_period, rfon_period_len_1,
rfon_period_len_2, rfon_period_len_3);
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
int wifi_set_lps_dtim(unsigned char dtim) {
2016-11-09 00:56:41 +00:00
return wext_set_lps_dtim(WLAN0_NAME, dtim);
}
2017-03-02 08:46:28 +00:00
int wifi_get_lps_dtim(unsigned char *dtim) {
2016-11-09 00:56:41 +00:00
return wext_get_lps_dtim(WLAN0_NAME, dtim);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
static void wifi_ap_sta_assoc_hdl(char* buf, int buf_len, int flags,
void* userdata) {
2016-11-09 00:56:41 +00:00
//USER TODO
}
2017-03-02 08:46:28 +00:00
static void wifi_ap_sta_disassoc_hdl(char* buf, int buf_len, int flags,
void* userdata) {
2016-11-09 00:56:41 +00:00
//USER TODO
}
2017-03-02 08:46:28 +00:00
int wifi_get_last_error(void) {
return error_flag;
2016-11-09 00:56:41 +00:00
}
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
int wpas_wps_init(const char* ifname);
#endif
2017-04-10 12:32:02 +00:00
int wifi_start_ap_s(PSOFTAP_CONFIG p) {
const char *ifname = WLAN0_NAME;
int ret = 0;
if (wifi_mode == RTW_MODE_STA_AP) {
ifname = WLAN1_NAME;
}
if (is_promisc_enabled())
promisc_set(0, NULL, 0);
wifi_reg_event_handler(WIFI_EVENT_STA_ASSOC, wifi_ap_sta_assoc_hdl, NULL);
wifi_reg_event_handler(WIFI_EVENT_STA_DISASSOC, wifi_ap_sta_disassoc_hdl,
NULL);
ret = wext_set_mode(ifname, IW_MODE_MASTER);
if (ret < 0)
goto exit;
ret = wext_set_channel(ifname, p->channel); //Set channel before starting ap
if (ret < 0)
goto exit;
switch (p->security_type) {
case RTW_SECURITY_OPEN:
break;
case RTW_SECURITY_WPA2_AES_PSK:
ret = wext_set_auth_param(ifname, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_OPEN_SYSTEM);
if (ret == 0)
ret = wext_set_key_ext(ifname, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0,
NULL, 0);
if (ret == 0)
ret = wext_set_passphrase(ifname, (u8*) p->password, strlen(p->password));
break;
default:
ret = -1;
printf("WIFICONF: security type is not supported\n");
break;
}
if (ret < 0)
goto exit;
if(p->ssid_hidden) {
ret = set_hidden_ssid(ifname, 1);
if (ret < 0)
goto exit;
}
ret = wext_set_ap_ssid(ifname, (u8*) p->ssid, strlen(p->ssid));
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
wpas_wps_init(ifname);
#endif
exit: return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_start_ap(char *ssid, rtw_security_t security_type, char *password,
int ssid_len, int password_len, int channel) {
2016-11-09 00:56:41 +00:00
const char *ifname = WLAN0_NAME;
int ret = 0;
2017-03-02 08:46:28 +00:00
if (wifi_mode == RTW_MODE_STA_AP) {
2016-11-09 00:56:41 +00:00
ifname = WLAN1_NAME;
}
2017-03-02 08:46:28 +00:00
if (is_promisc_enabled())
2016-11-09 00:56:41 +00:00
promisc_set(0, NULL, 0);
wifi_reg_event_handler(WIFI_EVENT_STA_ASSOC, wifi_ap_sta_assoc_hdl, NULL);
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_STA_DISASSOC, wifi_ap_sta_disassoc_hdl,
NULL);
2016-11-09 00:56:41 +00:00
ret = wext_set_mode(ifname, IW_MODE_MASTER);
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
2016-11-09 00:56:41 +00:00
ret = wext_set_channel(ifname, channel); //Set channel before starting ap
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
switch (security_type) {
case RTW_SECURITY_OPEN:
break;
case RTW_SECURITY_WPA2_AES_PSK:
ret = wext_set_auth_param(ifname, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_OPEN_SYSTEM);
if (ret == 0)
ret = wext_set_key_ext(ifname, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0,
NULL, 0);
if (ret == 0)
ret = wext_set_passphrase(ifname, (u8*) password, password_len);
break;
default:
ret = -1;
printf("WIFICONF: security type is not supported\n");
break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
ret = wext_set_ap_ssid(ifname, (u8*) ssid, ssid_len);
2016-11-09 00:56:41 +00:00
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
wpas_wps_init(ifname);
#endif
2017-03-02 08:46:28 +00:00
exit: return ret;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
int wifi_start_ap_with_hidden_ssid(char *ssid, rtw_security_t security_type,
char *password, int ssid_len, int password_len, int channel) {
2016-11-09 00:56:41 +00:00
const char *ifname = WLAN0_NAME;
int ret = 0;
2017-03-02 08:46:28 +00:00
if (wifi_mode == RTW_MODE_STA_AP) {
2016-11-09 00:56:41 +00:00
ifname = WLAN1_NAME;
}
2017-03-02 08:46:28 +00:00
if (is_promisc_enabled())
2016-11-09 00:56:41 +00:00
promisc_set(0, NULL, 0);
wifi_reg_event_handler(WIFI_EVENT_STA_ASSOC, wifi_ap_sta_assoc_hdl, NULL);
2017-03-02 08:46:28 +00:00
wifi_reg_event_handler(WIFI_EVENT_STA_DISASSOC, wifi_ap_sta_disassoc_hdl,
NULL);
2016-11-09 00:56:41 +00:00
ret = wext_set_mode(ifname, IW_MODE_MASTER);
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
2016-11-09 00:56:41 +00:00
ret = wext_set_channel(ifname, channel); //Set channel before starting ap
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
switch (security_type) {
case RTW_SECURITY_OPEN:
break;
case RTW_SECURITY_WPA2_AES_PSK:
ret = wext_set_auth_param(ifname, IW_AUTH_80211_AUTH_ALG,
IW_AUTH_ALG_OPEN_SYSTEM);
if (ret == 0)
ret = wext_set_key_ext(ifname, IW_ENCODE_ALG_CCMP, NULL, 0, 0, 0, 0,
NULL, 0);
if (ret == 0)
ret = wext_set_passphrase(ifname, (u8*) password, password_len);
break;
default:
ret = -1;
printf("WIFICONF: security type is not supported\n");
break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
2016-11-09 00:56:41 +00:00
ret = set_hidden_ssid(ifname, 1);
2017-03-02 08:46:28 +00:00
if (ret < 0)
goto exit;
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
ret = wext_set_ap_ssid(ifname, (u8*) ssid, ssid_len);
2016-11-09 00:56:41 +00:00
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
wpas_wps_init(ifname);
#endif
2017-03-02 08:46:28 +00:00
exit: return ret;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
void wifi_scan_each_report_hdl(char* buf, int buf_len, int flags,
void* userdata) {
int i = 0;
int j = 0;
2016-11-09 00:56:41 +00:00
int insert_pos = 0;
2017-03-02 08:46:28 +00:00
rtw_scan_result_t** result_ptr = (rtw_scan_result_t**) buf;
2016-11-09 00:56:41 +00:00
rtw_scan_result_t* temp = NULL;
2017-03-02 08:46:28 +00:00
for (i = 0; i < scan_result_handler_ptr.scan_cnt; i++) {
if (CMP_MAC(scan_result_handler_ptr.pap_details[i]->BSSID.octet,
(*result_ptr)->BSSID.octet)) {
if ((*result_ptr)->signal_strength
> scan_result_handler_ptr.pap_details[i]->signal_strength) {
temp = scan_result_handler_ptr.pap_details[i];
for (j = i - 1; j >= 0; j--) {
if (scan_result_handler_ptr.pap_details[j]->signal_strength
>= (*result_ptr)->signal_strength)
break;
2016-11-09 00:56:41 +00:00
else
2017-03-02 08:46:28 +00:00
scan_result_handler_ptr.pap_details[j + 1] =
scan_result_handler_ptr.pap_details[j];
}
scan_result_handler_ptr.pap_details[j + 1] = temp;
scan_result_handler_ptr.pap_details[j + 1]->signal_strength =
(*result_ptr)->signal_strength;
2016-11-09 00:56:41 +00:00
}
memset(*result_ptr, 0, sizeof(rtw_scan_result_t));
return;
}
}
scan_result_handler_ptr.scan_cnt++;
2017-03-02 08:46:28 +00:00
if (scan_result_handler_ptr.scan_cnt
> scan_result_handler_ptr.max_ap_size) {
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.scan_cnt = scan_result_handler_ptr.max_ap_size;
2017-03-02 08:46:28 +00:00
if ((*result_ptr)->signal_strength
> scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size
- 1]->signal_strength) {
rtw_memcpy(
scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size
- 1], *result_ptr, sizeof(rtw_scan_result_t));
temp =
scan_result_handler_ptr.pap_details[scan_result_handler_ptr.max_ap_size
- 1];
} else
2016-11-09 00:56:41 +00:00
return;
2017-03-02 08:46:28 +00:00
} else {
rtw_memcpy(
&scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt
- 1], *result_ptr, sizeof(rtw_scan_result_t));
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
for (i = 0; i < scan_result_handler_ptr.scan_cnt - 1; i++) {
if ((*result_ptr)->signal_strength
> scan_result_handler_ptr.pap_details[i]->signal_strength)
2016-11-09 00:56:41 +00:00
break;
}
insert_pos = i;
2017-03-02 08:46:28 +00:00
for (i = scan_result_handler_ptr.scan_cnt - 1; i > insert_pos; i--)
scan_result_handler_ptr.pap_details[i] =
scan_result_handler_ptr.pap_details[i - 1];
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
if (temp != NULL)
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.pap_details[insert_pos] = temp;
else
2017-03-02 08:46:28 +00:00
scan_result_handler_ptr.pap_details[insert_pos] =
&scan_result_handler_ptr.ap_details[scan_result_handler_ptr.scan_cnt
- 1];
2016-11-09 00:56:41 +00:00
rtw_memset(*result_ptr, 0, sizeof(rtw_scan_result_t));
}
2017-03-02 08:46:28 +00:00
void wifi_scan_done_hdl(char* buf, int buf_len, int flags, void* userdata) {
2016-11-09 00:56:41 +00:00
int i = 0;
rtw_scan_handler_result_t scan_result_report;
2017-03-02 08:46:28 +00:00
for (i = 0; i < scan_result_handler_ptr.scan_cnt; i++) {
rtw_memcpy(&scan_result_report.ap_details,
scan_result_handler_ptr.pap_details[i],
sizeof(rtw_scan_result_t));
scan_result_report.scan_complete =
scan_result_handler_ptr.scan_complete;
2016-11-09 00:56:41 +00:00
scan_result_report.user_data = scan_result_handler_ptr.user_data;
(*scan_result_handler_ptr.gscan_result_handler)(&scan_result_report);
}
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.scan_complete = RTW_TRUE;
scan_result_report.scan_complete = RTW_TRUE;
(*scan_result_handler_ptr.gscan_result_handler)(&scan_result_report);
rtw_free(scan_result_handler_ptr.ap_details);
rtw_free(scan_result_handler_ptr.pap_details);
#if SCAN_USE_SEMAPHORE
rtw_up_sema(&scan_result_handler_ptr.scan_semaphore);
#else
scan_result_handler_ptr.scan_running = 0;
#endif
2017-03-02 08:46:28 +00:00
wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT,
wifi_scan_each_report_hdl);
2016-11-09 00:56:41 +00:00
wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl);
return;
}
//int rtk_wifi_scan(char *buf, int buf_len, xSemaphoreHandle * semaphore)
2017-03-02 08:46:28 +00:00
int wifi_scan(rtw_scan_type_t scan_type, rtw_bss_type_t bss_type,
void* result_ptr) {
2016-11-09 00:56:41 +00:00
int ret;
scan_buf_arg * pscan_buf;
u16 flags = scan_type | (bss_type << 8);
2017-03-02 08:46:28 +00:00
if (result_ptr != NULL) {
pscan_buf = (scan_buf_arg *) result_ptr;
ret = wext_set_scan(WLAN0_NAME, (char*) pscan_buf->buf,
pscan_buf->buf_len, flags);
} else {
wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT,
wifi_scan_each_report_hdl, NULL);
2016-11-09 00:56:41 +00:00
wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, wifi_scan_done_hdl, NULL);
ret = wext_set_scan(WLAN0_NAME, NULL, 0, flags);
}
2017-03-02 08:46:28 +00:00
if (ret == 0) {
if (result_ptr != NULL) {
2016-11-09 00:56:41 +00:00
ret = wext_get_scan(WLAN0_NAME, pscan_buf->buf, pscan_buf->buf_len);
}
}
return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_scan_networks_with_ssid(
int (results_handler)(char*buf, int buflen, char *ssid, void *user_data),
OUT void* user_data, IN int scan_buflen, IN char* ssid, IN int ssid_len) {
2016-11-09 00:56:41 +00:00
int scan_cnt = 0, add_cnt = 0;
scan_buf_arg scan_buf;
int ret;
scan_buf.buf_len = scan_buflen;
2017-03-02 08:46:28 +00:00
scan_buf.buf = (char*) pvPortMalloc(scan_buf.buf_len);
if (!scan_buf.buf) {
2016-11-09 00:56:41 +00:00
printf("ERROR: Can't malloc memory(%d)\n", scan_buf.buf_len);
return RTW_NOMEM;
}
//set ssid
memset(scan_buf.buf, 0, scan_buf.buf_len);
memcpy(scan_buf.buf, &ssid_len, sizeof(int));
2017-03-02 08:46:28 +00:00
memcpy(scan_buf.buf + sizeof(int), ssid, ssid_len);
2016-11-09 00:56:41 +00:00
//Scan channel
2017-03-02 08:46:28 +00:00
if ((scan_cnt = (wifi_scan(RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY,
&scan_buf))) < 0) {
2016-11-09 00:56:41 +00:00
printf("ERROR: wifi scan failed\n");
ret = RTW_ERROR;
2017-03-02 08:46:28 +00:00
} else {
if (NULL == results_handler) {
2016-11-09 00:56:41 +00:00
int plen = 0;
2017-03-02 08:46:28 +00:00
while (plen < scan_buf.buf_len) {
2016-11-09 00:56:41 +00:00
int len, rssi, ssid_len, i, security_mode;
int wps_password_id;
char *mac, *ssid;
//u8 *security_mode;
printf("\n");
// len
2017-03-02 08:46:28 +00:00
len = (int) *(scan_buf.buf + plen);
2016-11-09 00:56:41 +00:00
printf("len = %d,\t", len);
// check end
2017-03-02 08:46:28 +00:00
if (len == 0)
break;
2016-11-09 00:56:41 +00:00
// mac
mac = scan_buf.buf + plen + 1;
printf("mac = ");
2017-03-02 08:46:28 +00:00
for (i = 0; i < 6; i++)
2016-11-09 00:56:41 +00:00
printf("%02x ", (u8)*(mac+i));
printf(",\t");
// rssi
2017-03-02 08:46:28 +00:00
rssi = *(int*) (scan_buf.buf + plen + 1 + 6);
2016-11-09 00:56:41 +00:00
printf(" rssi = %d,\t", rssi);
// security_mode
2017-03-02 08:46:28 +00:00
security_mode = (int) *(scan_buf.buf + plen + 1 + 6 + 4);
2016-11-09 00:56:41 +00:00
switch (security_mode) {
2017-03-02 08:46:28 +00:00
case IW_ENCODE_ALG_NONE:
printf("sec = open ,\t");
break;
case IW_ENCODE_ALG_WEP:
printf("sec = wep ,\t");
break;
case IW_ENCODE_ALG_CCMP:
printf("sec = wpa/wpa2,\t");
break;
2016-11-09 00:56:41 +00:00
}
// password id
2017-03-02 08:46:28 +00:00
wps_password_id = (int) *(scan_buf.buf + plen + 1 + 6 + 4 + 1);
2016-11-09 00:56:41 +00:00
printf("wps password id = %d,\t", wps_password_id);
2017-03-02 08:46:28 +00:00
printf("channel = %d,\t",
*(scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1));
2016-11-09 00:56:41 +00:00
// ssid
ssid_len = len - 1 - 6 - 4 - 1 - 1 - 1;
ssid = scan_buf.buf + plen + 1 + 6 + 4 + 1 + 1 + 1;
printf("ssid = ");
2017-03-02 08:46:28 +00:00
for (i = 0; i < ssid_len; i++)
printf("%c", *(ssid + i));
2016-11-09 00:56:41 +00:00
plen += len;
add_cnt++;
}
2017-03-02 08:46:28 +00:00
printf("\nwifi_scan: add count = %d, scan count = %d\n", add_cnt,
scan_cnt);
2016-11-09 00:56:41 +00:00
}
ret = RTW_SUCCESS;
}
2017-03-02 08:46:28 +00:00
if (results_handler)
2016-11-09 00:56:41 +00:00
results_handler(scan_buf.buf, scan_buf.buf_len, ssid, user_data);
2017-03-02 08:46:28 +00:00
if (scan_buf.buf)
2016-11-09 00:56:41 +00:00
vPortFree(scan_buf.buf);
return ret;
}
2017-03-02 08:46:28 +00:00
int wifi_scan_networks(rtw_scan_result_handler_t results_handler,
void* user_data) {
2016-11-09 00:56:41 +00:00
unsigned int max_ap_size = 64;
#if SCAN_USE_SEMAPHORE
rtw_bool_t result;
if(NULL == scan_result_handler_ptr.scan_semaphore)
2017-03-02 08:46:28 +00:00
rtw_init_sema(&scan_result_handler_ptr.scan_semaphore, 1);
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
/* Initialise the semaphore that will prevent simultaneous access - cannot be a mutex, since
2017-03-02 08:46:28 +00:00
* we don't want to allow the same thread to start a new scan */
2016-11-09 00:56:41 +00:00
result = (rtw_bool_t)rtw_down_timeout_sema(&scan_result_handler_ptr.scan_semaphore, SCAN_LONGEST_WAIT_TIME);
if ( result != RTW_TRUE )
{
/* Return error result, but set the semaphore to work the next time */
rtw_up_sema(&scan_result_handler_ptr.scan_semaphore);
return RTW_TIMEOUT;
}
#else
2017-03-02 08:46:28 +00:00
if (scan_result_handler_ptr.scan_running) {
2016-11-09 00:56:41 +00:00
int count = 100;
2017-03-02 08:46:28 +00:00
while (scan_result_handler_ptr.scan_running && count > 0) {
2016-11-09 00:56:41 +00:00
rtw_msleep_os(20);
2017-03-02 08:46:28 +00:00
count--;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (count == 0) {
printf("[%d]WiFi: Scan is running. Wait 2s timeout.\n",
rtw_get_current_time());
2016-11-09 00:56:41 +00:00
return RTW_TIMEOUT;
}
}
scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
scan_result_handler_ptr.scan_running = 1;
#endif
scan_result_handler_ptr.gscan_result_handler = results_handler;
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.max_ap_size = max_ap_size;
2017-03-02 08:46:28 +00:00
scan_result_handler_ptr.ap_details = (rtw_scan_result_t*) rtw_zmalloc(
max_ap_size * sizeof(rtw_scan_result_t));
if (scan_result_handler_ptr.ap_details == NULL) {
2016-11-09 00:56:41 +00:00
goto err_exit;
}
2017-03-02 08:46:28 +00:00
rtw_memset(scan_result_handler_ptr.ap_details, 0,
max_ap_size * sizeof(rtw_scan_result_t));
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
scan_result_handler_ptr.pap_details = (rtw_scan_result_t**) rtw_zmalloc(
max_ap_size * sizeof(rtw_scan_result_t*));
if (scan_result_handler_ptr.pap_details == NULL)
2016-11-09 00:56:41 +00:00
goto error2_with_result_ptr;
rtw_memset(scan_result_handler_ptr.pap_details, 0, max_ap_size);
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
scan_result_handler_ptr.scan_cnt = 0;
scan_result_handler_ptr.scan_complete = RTW_FALSE;
scan_result_handler_ptr.user_data = user_data;
2017-03-02 08:46:28 +00:00
if (wifi_scan(RTW_SCAN_COMMAMD << 4 | RTW_SCAN_TYPE_ACTIVE,
RTW_BSS_TYPE_ANY, NULL) != RTW_SUCCESS) {
2016-11-09 00:56:41 +00:00
goto error1_with_result_ptr;
}
return RTW_SUCCESS;
2017-03-30 02:05:27 +00:00
error1_with_result_ptr:
2016-11-09 00:56:41 +00:00
rtw_free((u8*)scan_result_handler_ptr.pap_details);
scan_result_handler_ptr.pap_details = NULL;
2017-03-02 08:46:28 +00:00
2017-03-30 02:05:27 +00:00
error2_with_result_ptr:
2016-11-09 00:56:41 +00:00
rtw_free((u8*)scan_result_handler_ptr.ap_details);
scan_result_handler_ptr.ap_details = NULL;
2017-03-30 02:05:27 +00:00
err_exit:
rtw_memset((void *) &scan_result_handler_ptr, 0,
2017-03-02 08:46:28 +00:00
sizeof(scan_result_handler_ptr));
2016-11-09 00:56:41 +00:00
return RTW_ERROR;
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_pscan_chan(__u8 * channel_list, __u8 * pscan_config, __u8 length) {
if (channel_list)
return wext_set_pscan_channel(WLAN0_NAME, channel_list, pscan_config,
length);
2016-11-09 00:56:41 +00:00
else
2017-03-02 08:46:28 +00:00
return -1;
2016-11-09 00:56:41 +00:00
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting) {
2016-11-09 00:56:41 +00:00
int ret = 0;
int mode = 0;
unsigned short security = 0;
memset(pSetting, 0, sizeof(rtw_wifi_setting_t));
2017-03-02 08:46:28 +00:00
if (wext_get_mode(ifname, &mode) < 0)
2016-11-09 00:56:41 +00:00
ret = -1;
2017-03-02 08:46:28 +00:00
switch (mode) {
case IW_MODE_MASTER:
pSetting->mode = RTW_MODE_AP;
break;
case IW_MODE_INFRA:
default:
pSetting->mode = RTW_MODE_STA;
break;
2016-11-09 00:56:41 +00:00
//default:
2017-03-02 08:46:28 +00:00
//printf("\r\n%s(): Unknown mode %d\n", __func__, mode);
//break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (wext_get_ssid(ifname, pSetting->ssid) < 0)
2016-11-09 00:56:41 +00:00
ret = -1;
2017-03-02 08:46:28 +00:00
if (wext_get_channel(ifname, &pSetting->channel) < 0)
2016-11-09 00:56:41 +00:00
ret = -1;
2017-03-02 08:46:28 +00:00
if (wext_get_enc_ext(ifname, &security, &pSetting->key_idx,
pSetting->password) < 0)
2016-11-09 00:56:41 +00:00
ret = -1;
2017-03-02 08:46:28 +00:00
switch (security) {
case IW_ENCODE_ALG_NONE:
pSetting->security_type = RTW_SECURITY_OPEN;
break;
case IW_ENCODE_ALG_WEP:
pSetting->security_type = RTW_SECURITY_WEP_PSK;
break;
case IW_ENCODE_ALG_TKIP:
pSetting->security_type = RTW_SECURITY_WPA_TKIP_PSK;
break;
case IW_ENCODE_ALG_CCMP:
pSetting->security_type = RTW_SECURITY_WPA2_AES_PSK;
break;
default:
break;
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
if (security == IW_ENCODE_ALG_TKIP || security == IW_ENCODE_ALG_CCMP)
if (wext_get_passphrase(ifname, pSetting->password) < 0)
2016-11-09 00:56:41 +00:00
ret = -1;
return ret;
}
//----------------------------------------------------------------------------//
2017-03-09 08:23:37 +00:00
extern char str_rom_57ch3Dch0A[]; // "=========================================================\n" 57 шт
2017-03-02 08:46:28 +00:00
int wifi_show_setting(const char *ifname, rtw_wifi_setting_t *pSetting) {
2016-11-09 00:56:41 +00:00
int ret = 0;
2017-03-09 08:23:37 +00:00
printf("\nWIFI '%s' Setting:\n", ifname);
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
2016-11-09 00:56:41 +00:00
2017-03-02 08:46:28 +00:00
switch (pSetting->mode) {
case RTW_MODE_AP:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("AP,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tMODE => AP\n");
break;
case RTW_MODE_STA:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("STA,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tMODE => STATION\n");
break;
default:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("UNKNOWN,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tMODE => UNKNOWN\n");
2016-11-09 00:56:41 +00:00
}
#if CONFIG_EXAMPLE_UART_ATCMD
at_printf("%s,%d,", pSetting->ssid, pSetting->channel);
#endif
printf("\tSSID => %s\n", pSetting->ssid);
printf("\tCHANNEL => %d\n", pSetting->channel);
2017-03-02 08:46:28 +00:00
switch (pSetting->security_type) {
case RTW_SECURITY_OPEN:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("OPEN,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tSECURITY => OPEN\n");
break;
case RTW_SECURITY_WEP_PSK:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("WEP,%d,", pSetting->key_idx);
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tSECURITY => WEP\n");
printf("\tKEY INDEX => %d\n", pSetting->key_idx);
break;
case RTW_SECURITY_WPA_TKIP_PSK:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("TKIP,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tSECURITY => TKIP\n");
break;
case RTW_SECURITY_WPA2_AES_PSK:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("AES,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tSECURITY => AES\n");
break;
default:
2016-11-09 00:56:41 +00:00
#if CONFIG_EXAMPLE_UART_ATCMD
2017-03-02 08:46:28 +00:00
at_printf("UNKNOWN,");
2016-11-09 00:56:41 +00:00
#endif
2017-03-02 08:46:28 +00:00
printf("\tSECURITY => UNKNOWN\n");
2016-11-09 00:56:41 +00:00
}
#if CONFIG_EXAMPLE_UART_ATCMD
at_printf("%s,", pSetting->password);
#endif
printf("\tPASSWORD => %s\n", pSetting->password);
// printf("\n");
return ret;
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_network_mode(rtw_network_mode_t mode) {
if ((mode == RTW_NETWORK_B) || (mode == RTW_NETWORK_BG)
|| (mode == RTW_NETWORK_BGN))
2016-11-09 00:56:41 +00:00
return rltk_wlan_wireless_mode((unsigned char) mode);
return -1;
}
2017-03-02 08:46:28 +00:00
int wifi_set_wps_phase(unsigned char is_trigger_wps) {
2016-11-09 00:56:41 +00:00
return rltk_wlan_set_wps_phase(is_trigger_wps);
}
//----------------------------------------------------------------------------//
2017-03-02 08:46:28 +00:00
int wifi_set_promisc(rtw_rcr_level_t enabled,
void (*callback)(unsigned char*, unsigned int, void*),
unsigned char len_used) {
2016-11-09 00:56:41 +00:00
return promisc_set(enabled, callback, len_used);
}
2017-03-02 08:46:28 +00:00
void wifi_enter_promisc_mode() {
2016-11-09 00:56:41 +00:00
int mode = 0;
unsigned char ssid[33];
2017-03-02 08:46:28 +00:00
if (wifi_mode == RTW_MODE_STA_AP) {
2016-11-09 00:56:41 +00:00
wifi_off();
2017-03-02 08:46:28 +00:00
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
2016-11-09 00:56:41 +00:00
wifi_on(RTW_MODE_PROMISC);
2017-03-02 08:46:28 +00:00
} else {
2016-11-09 00:56:41 +00:00
wext_get_mode(WLAN0_NAME, &mode);
2017-03-02 08:46:28 +00:00
switch (mode) {
case IW_MODE_MASTER: //In AP mode
//rltk_wlan_deinit();
wifi_off(); //modified by Chris Yang for iNIC
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
//rltk_wlan_init(0, RTW_MODE_PROMISC);
//rltk_wlan_start(0);
wifi_on(RTW_MODE_PROMISC);
break;
case IW_MODE_INFRA: //In STA mode
if (wext_get_ssid(WLAN0_NAME, ssid) > 0)
wifi_disconnect();
2016-11-09 00:56:41 +00:00
}
}
}
2017-03-02 08:46:28 +00:00
int wifi_restart_ap(unsigned char *ssid, rtw_security_t security_type,
unsigned char *password, int ssid_len, int password_len, int channel) {
2016-11-09 00:56:41 +00:00
unsigned char idx = 0;
struct ip_addr ipaddr;
struct ip_addr netmask;
struct ip_addr gw;
struct netif * pnetif = &xnetif[0];
#ifdef CONFIG_CONCURRENT_MODE
rtw_wifi_setting_t setting;
int sta_linked = 0;
#endif
2017-03-02 08:46:28 +00:00
if (rltk_wlan_running(WLAN1_IDX)) {
2016-11-09 00:56:41 +00:00
idx = 1;
}
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
// stop dhcp server
dhcps_deinit();
#ifdef CONFIG_CONCURRENT_MODE
2017-03-02 08:46:28 +00:00
if (idx > 0) {
2016-11-09 00:56:41 +00:00
sta_linked = wifi_get_setting(WLAN0_NAME, &setting);
wifi_off();
2017-03-02 08:46:28 +00:00
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
2016-11-09 00:56:41 +00:00
wifi_on(RTW_MODE_STA_AP);
2017-03-02 08:46:28 +00:00
} else
2016-11-09 00:56:41 +00:00
#endif
{
IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
2017-03-02 08:46:28 +00:00
IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1, NETMASK_ADDR2,
NETMASK_ADDR3);
2016-11-09 00:56:41 +00:00
IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
2017-03-02 08:46:28 +00:00
netif_set_addr(pnetif, &ipaddr, &netmask, &gw);
2016-11-09 00:56:41 +00:00
wifi_off();
2017-03-02 08:46:28 +00:00
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
wifi_on(RTW_MODE_AP);
2016-11-09 00:56:41 +00:00
}
// start ap
2017-03-02 08:46:28 +00:00
if (wifi_start_ap((char*) ssid, security_type, (char*) password, ssid_len,
password_len, channel) < 0) {
2016-11-09 00:56:41 +00:00
printf("ERROR: Operation failed!\n");
return -1;
}
#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
printf("WebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
#endif
#ifdef CONFIG_CONCURRENT_MODE
// connect to ap if wlan0 was linked with ap
2017-03-02 08:46:28 +00:00
if (idx > 0 && sta_linked == 0) {
2016-11-09 00:56:41 +00:00
int ret;
2017-03-02 08:46:28 +00:00
printf("AP: ssid=%s\n", (char* )setting.ssid);
2016-11-09 00:56:41 +00:00
printf("AP: security_type=%d\n", setting.security_type);
2017-03-02 08:46:28 +00:00
printf("AP: password=%s\n", (char* )setting.password);
2016-11-09 00:56:41 +00:00
printf("AP: key_idx =%d\n", setting.key_idx);
2017-03-02 08:46:28 +00:00
ret = wifi_connect((char*) setting.ssid, setting.security_type,
(char*) setting.password, strlen((char* )setting.ssid),
strlen((char* )setting.password), setting.key_idx,
NULL);
if (ret == RTW_SUCCESS) {
2016-11-09 00:56:41 +00:00
#if CONFIG_DHCP_CLIENT
/* Start DHCPClient */
LwIP_DHCP(0, DHCP_START);
#endif
#if CONFIG_WLAN_CONNECT_CB
extern void connect_start(void);
connect_start();
#endif
}
}
#endif
#if (INCLUDE_uxTaskGetStackHighWaterMark == 1)
printf("WebServer Thread: High Water Mark is %ld\n", uxTaskGetStackHighWaterMark(NULL));
#endif
// start dhcp server
dhcps_init(&xnetif[idx]);
return 0;
}
#if CONFIG_AUTO_RECONNECT
2017-03-02 08:46:28 +00:00
extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int,
int);
2016-11-09 00:56:41 +00:00
struct wifi_autoreconnect_param {
rtw_security_t security_type;
char *ssid;
int ssid_len;
char *password;
int password_len;
int key_id;
};
2017-03-02 08:46:28 +00:00
static void wifi_autoreconnect_thread(void *param) {
2016-11-09 00:56:41 +00:00
int ret = RTW_ERROR;
2017-03-02 08:46:28 +00:00
struct wifi_autoreconnect_param *reconnect_param =
(struct wifi_autoreconnect_param *) param;
2016-11-09 00:56:41 +00:00
printf("auto reconnect ...\n");
2017-03-02 08:46:28 +00:00
ret = wifi_connect(reconnect_param->ssid, reconnect_param->security_type,
reconnect_param->password, reconnect_param->ssid_len,
reconnect_param->password_len, reconnect_param->key_id, NULL);
if (ret == RTW_SUCCESS) {
2016-11-09 00:56:41 +00:00
#if CONFIG_LWIP_LAYER
2017-03-02 08:46:28 +00:00
2016-11-09 00:56:41 +00:00
#if ATCMD_VER == ATVER_2
2017-03-02 08:46:28 +00:00
if (dhcp_mode_sta == 2) {
2016-11-09 00:56:41 +00:00
struct netif * pnetif = &xnetif[0];
LwIP_UseStaticIP(pnetif);
dhcps_init(pnetif);
}
else
#endif
{
LwIP_DHCP(0, DHCP_START);
#if LWIP_AUTOIP
uint8_t *ip = LwIP_GetIP(&xnetif[0]);
2017-03-02 08:46:28 +00:00
if ((ip[0] == 0) && (ip[1] == 0) && (ip[2] == 0) && (ip[3] == 0)) {
2016-11-09 00:56:41 +00:00
printf("IPv4 AUTOIP ...\n");
LwIP_AUTOIP(&xnetif[0]);
}
#endif
}
#endif //#if CONFIG_LWIP_LAYER
#if CONFIG_WLAN_CONNECT_CB
extern void connect_start(void);
connect_start();
#endif
}
vTaskDelete(NULL);
}
2017-03-02 08:46:28 +00:00
void wifi_autoreconnect_hdl(rtw_security_t security_type, char *ssid,
int ssid_len, char *password, int password_len, int key_id) {
2016-11-09 00:56:41 +00:00
static struct wifi_autoreconnect_param param;
param.security_type = security_type;
param.ssid = ssid;
param.ssid_len = ssid_len;
param.password = password;
param.password_len = password_len;
param.key_id = key_id;
2017-03-02 08:46:28 +00:00
xTaskCreate(wifi_autoreconnect_thread, (const char * )"st_recon", 400,
&param, tskIDLE_PRIORITY + 1, NULL);
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
int wifi_config_autoreconnect(__u8 mode, __u8 retyr_times, __u16 timeout) {
p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl;
return wext_set_autoreconnect(WLAN0_NAME, mode, retyr_times, timeout);
2016-11-09 00:56:41 +00:00
}
2017-03-02 08:46:28 +00:00
int wifi_set_autoreconnect(__u8 mode) {
2016-11-09 00:56:41 +00:00
p_wlan_autoreconnect_hdl = wifi_autoreconnect_hdl;
return wifi_config_autoreconnect(mode, 3, 5);//default retry 2 times(limit is 3), timeout 5 seconds
}
2017-03-02 08:46:28 +00:00
int wifi_get_autoreconnect(__u8 *mode) {
return wext_get_autoreconnect(WLAN0_NAME, mode);
2016-11-09 00:56:41 +00:00
}
#endif
#ifdef CONFIG_CUSTOM_IE
/*
* Example for custom ie
*
* u8 test_1[] = {221, 2, 2, 2};
* u8 test_2[] = {221, 2, 1, 1};
* cus_ie buf[2] = {{test_1, PROBE_REQ},
* {test_2, PROBE_RSP | BEACON}};
* u8 buf_test2[] = {221, 2, 1, 3} ;
* cus_ie buf_update = {buf_test2, PROBE_REQ};
*
* add ie list
* static void cmd_add_ie(int argc, char **argv)
* {
* wifi_add_custom_ie((void *)buf, 2);
* }
*
* update current ie
* static void cmd_update_ie(int argc, char **argv)
* {
* wifi_update_custom_ie(&buf_update, 2);
* }
*
* delete all ie
* static void cmd_del_ie(int argc, char **argv)
* {
* wifi_del_custom_ie();
* }
*/
2017-03-02 08:46:28 +00:00
int wifi_add_custom_ie(void *cus_ie, int ie_num) {
2016-11-09 00:56:41 +00:00
return wext_add_custom_ie(WLAN0_NAME, cus_ie, ie_num);
}
2017-03-02 08:46:28 +00:00
int wifi_update_custom_ie(void *cus_ie, int ie_index) {
2016-11-09 00:56:41 +00:00
return wext_update_custom_ie(WLAN0_NAME, cus_ie, ie_index);
}
2017-03-02 08:46:28 +00:00
int wifi_del_custom_ie() {
2016-11-09 00:56:41 +00:00
return wext_del_custom_ie(WLAN0_NAME);
}
#endif
#ifdef CONFIG_PROMISC
extern void promisc_init_packet_filter(void);
2017-03-02 08:46:28 +00:00
extern int promisc_add_packet_filter(u8 filter_id,
rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule);
2016-11-09 00:56:41 +00:00
extern int promisc_enable_packet_filter(u8 filter_id);
extern int promisc_disable_packet_filter(u8 filter_id);
extern int promisc_remove_packet_filter(u8 filter_id);
2017-03-02 08:46:28 +00:00
void wifi_init_packet_filter() {
2016-11-09 00:56:41 +00:00
promisc_init_packet_filter();
}
2017-03-02 08:46:28 +00:00
int wifi_add_packet_filter(unsigned char filter_id,
rtw_packet_filter_pattern_t *patt, rtw_packet_filter_rule_e rule) {
2016-11-09 00:56:41 +00:00
return promisc_add_packet_filter(filter_id, patt, rule);
}
2017-03-02 08:46:28 +00:00
int wifi_enable_packet_filter(unsigned char filter_id) {
2016-11-09 00:56:41 +00:00
return promisc_enable_packet_filter(filter_id);
}
2017-03-02 08:46:28 +00:00
int wifi_disable_packet_filter(unsigned char filter_id) {
2016-11-09 00:56:41 +00:00
return promisc_disable_packet_filter(filter_id);
}
2017-03-02 08:46:28 +00:00
int wifi_remove_packet_filter(unsigned char filter_id) {
2016-11-09 00:56:41 +00:00
return promisc_remove_packet_filter(filter_id);
}
#endif
#ifdef CONFIG_AP_MODE
2017-03-02 08:46:28 +00:00
int wifi_enable_forwarding(void) {
2016-11-09 00:56:41 +00:00
return wext_enable_forwarding(WLAN0_NAME);
}
2017-03-02 08:46:28 +00:00
int wifi_disable_forwarding(void) {
2016-11-09 00:56:41 +00:00
return wext_disable_forwarding(WLAN0_NAME);
}
#endif
/* API to set flag for concurrent mode wlan1 issue_deauth when channel switched by wlan0
* usage: wifi_set_ch_deauth(0) -> wlan0 wifi_connect -> wifi_set_ch_deauth(1)
*/
#ifdef CONFIG_CONCURRENT_MODE
2017-03-02 08:46:28 +00:00
int wifi_set_ch_deauth(__u8 enable) {
2016-11-09 00:56:41 +00:00
return wext_set_ch_deauth(WLAN1_NAME, enable);
}
#endif
//----------------------------------------------------------------------------//
#endif //#if CONFIG_WLAN
2017-03-02 08:46:28 +00:00
#if CONFIG_DEBUG_LOG > 4
extern void dump_bytes(uint32 addr, int size);
static void test_rtk() {
printf("rltk_wlan_info = %p\n", &rltk_wlan_info);
// dump_bytes((u32)&rltk_wlan_info, 16);
_adapter *ad = rltk_wlan_info[1].dev;
printf("adapter = %p\n", ad);
// dump_bytes((u32)ad, 16);
// printf("bSurpriseRemoved [%p] = %d, +%d\n", &ad->bSurpriseRemoved, ad->bSurpriseRemoved, (u32)&ad->bSurpriseRemoved - (u32)ad);
// dump_bytes((u32)&ad->bSurpriseRemoved, 32);
printf("mlmepriv +%d, mlmeextpriv +%d, cmdpriv +d%\n",
(u32)(&ad->mlmepriv) - (u32)(ad),
(u32)(&ad->mlmeextpriv) - (u32)(ad),
(u32)(&ad->cmdpriv) - (u32)(ad));
printf("xmitpriv +%d, recvpriv +%d, stapriv +%d\n",
(u32)(&ad->xmitpriv) - (u32)(ad), (u32)(&ad->recvpriv) - (u32)(ad),
(u32)(&ad->stapriv) - (u32)(ad));
printf("bDriverStopped %d, hw_init_completed %d, cmdThread %d\n",
(u32)(&ad->bDriverStopped) - (u32)(ad),
(u32)(&ad->hw_init_completed) - (u32)(ad),
(u32)(&ad->cmdThread) - (u32)(ad));
printf("intf_start %d, bup %d, pcodatapriv %d\n",
(u32)(&ad->intf_start) - (u32)(ad), (u32)(&ad->bup) - (u32)(ad),
(u32)(&ad->pcodatapriv) - (u32)(ad));
printf("Sizeof(adapter) = %d\n", sizeof(struct _ADAPTER));
if (sizeof(struct _ADAPTER) != 6088) {
printf("Error: Check aligned WiFi struct!\n");
}
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands_wifi[] = {
{ "RTK", 0, test_rtk, ": Test WiFi struct align"},
};
#endif