mirror of
https://github.com/drasko/open-ameba.git
synced 2024-11-21 13:34:17 +00:00
update
This commit is contained in:
parent
01d402f038
commit
b1d891c21e
30 changed files with 3219 additions and 3085 deletions
|
@ -1310,7 +1310,13 @@ void fATST(void *arg) {
|
|||
}
|
||||
|
||||
#if 0
|
||||
#include "wlan_lib.h"
|
||||
#if 1
|
||||
#include "drv_types.h" // or #include "wlan_lib.h"
|
||||
#else
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
#include "wlan_lib.h" // or #include "drv_types.h"
|
||||
#endif
|
||||
#include "hal_com_reg.h"
|
||||
// extern Rltk_wlan_t rltk_wlan_info[2];
|
||||
void fATXT(void *arg)
|
||||
|
|
|
@ -103,8 +103,8 @@ struct netif xnetif[NET_IF_NUM]; /* network interface structure */
|
|||
* @retval None
|
||||
*/
|
||||
#if CONFIG_WLAN
|
||||
extern int error_flag;
|
||||
extern rtw_mode_t wifi_mode;
|
||||
extern char error_flag;
|
||||
extern unsigned char wifi_mode; // rtw_mode_t
|
||||
#endif
|
||||
|
||||
int lwip_init_done = 0;
|
||||
|
@ -204,7 +204,7 @@ uint8_t LwIP_DHCP(uint8_t idx, uint8_t dhcp_state) {
|
|||
}
|
||||
|
||||
for (;;) {
|
||||
//printf("\n\r ========DHCP_state:%d============\n\r",DHCP_state);
|
||||
//info_printf("\n\r ========DHCP_state:%d============\n\r",DHCP_state);
|
||||
switch (DHCP_state) {
|
||||
case DHCP_START: {
|
||||
#if CONFIG_WLAN
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
//----------------------------------------------------------------------------//
|
||||
#include <wireless.h>
|
||||
#include <wlan_intf.h>
|
||||
#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 <wifi_api.h>
|
||||
#include "tcpip.h"
|
||||
#if 1
|
||||
#include "drv_types.h" // or #include "wlan_lib.h"
|
||||
#else
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
//#include "wlan_lib.h" // or #include "drv_types.h"
|
||||
#endif
|
||||
#include <lwip_netconf.h>
|
||||
#include <osdep_service.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
|
@ -23,7 +27,6 @@
|
|||
extern int inic_start(void);
|
||||
extern int inic_stop(void);
|
||||
#endif
|
||||
#include "wlan_lib.h"
|
||||
|
||||
#if CONFIG_DEBUG_LOG > 0
|
||||
#undef printf
|
||||
|
@ -40,8 +43,6 @@ extern int inic_stop(void);
|
|||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
#define SCAN_USE_SEMAPHORE 0
|
||||
|
||||
#define RTW_JOIN_TIMEOUT 15000
|
||||
|
||||
#define JOIN_ASSOCIATED (uint32_t)(1 << 0)
|
||||
|
@ -69,12 +70,11 @@ extern struct netif xnetif[NET_IF_NUM];
|
|||
/******************************************************
|
||||
* Variables Definitions
|
||||
******************************************************/
|
||||
internal_scan_handler_t scan_result_handler_ptr = {
|
||||
0, 0, 0, RTW_FALSE, 0, 0, 0, 0, 0 };
|
||||
internal_scan_handler_t scan_result_handler_ptr;
|
||||
static internal_join_result_t* join_user_data;
|
||||
rtw_mode_t wifi_mode = RTW_MODE_NONE;
|
||||
unsigned char wifi_mode = RTW_MODE_NONE; // rtw_mode_t
|
||||
//extern rtw_mode_t wifi_mode;
|
||||
int error_flag = RTW_UNKNOWN;
|
||||
char error_flag = RTW_UNKNOWN;
|
||||
uint32_t rtw_join_status;
|
||||
#if ATCMD_VER == ATVER_2
|
||||
extern unsigned char dhcp_mode_sta;
|
||||
|
@ -210,68 +210,9 @@ static int wifi_connect_local(rtw_network_info_t *pWifi) {
|
|||
pWifi->security_type, __func__);
|
||||
break;
|
||||
}
|
||||
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
|
||||
if(ret == 0)
|
||||
ret = wext_set_ssid(WLAN0_NAME, pWifi->ssid.val, pWifi->ssid.len);
|
||||
#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};
|
||||
|
||||
if(is_promisc_enabled())
|
||||
promisc_set(0, NULL, 0);
|
||||
|
||||
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:
|
||||
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;
|
||||
printf("WIFICONF: security type(0x%x) is not supported.\n", pWifi->security_type);
|
||||
break;
|
||||
}
|
||||
if(ret == 0) {
|
||||
memcpy(bssid, pWifi->bssid.octet, ETH_ALEN);
|
||||
if(pWifi->ssid.len) {
|
||||
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
|
||||
|
||||
void wifi_rx_beacon_hdl(char* buf, int buf_len, int flags, void* userdata) {
|
||||
//printf("Beacon!\n");
|
||||
}
|
||||
|
@ -563,9 +504,7 @@ int wifi_connect(
|
|||
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
|
||||
wifi_handshake_done_hdl, NULL);
|
||||
#if DD_WIFI_CONN // дублирование с wifi_connect_bssid_local()
|
||||
wifi_connect_local(&join_result->network_info);
|
||||
#else
|
||||
|
||||
rtw_network_info_t *pWifi = &join_result->network_info;
|
||||
|
||||
if (wifi_connect_local(pWifi) == 0) {
|
||||
|
@ -593,7 +532,6 @@ int wifi_connect(
|
|||
join_result->network_info.ssid.len);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
join_user_data = join_result;
|
||||
|
||||
if (semaphore == NULL) {
|
||||
|
@ -618,7 +556,7 @@ int wifi_connect(
|
|||
#endif
|
||||
if (rtw_down_timeout_sema(&join_result->join_sema, RTW_JOIN_TIMEOUT)
|
||||
== RTW_FALSE) {
|
||||
printf("RTW API: Join bss timeout\n");
|
||||
warning_printf("RTW API: Join bss timeout\n");
|
||||
if (password_len) {
|
||||
rtw_free(join_result->network_info.password);
|
||||
}
|
||||
|
@ -652,137 +590,6 @@ int wifi_connect(
|
|||
wifi_handshake_done_hdl);
|
||||
return result;
|
||||
}
|
||||
/*
|
||||
|
||||
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) {
|
||||
xSemaphoreHandle join_semaphore;
|
||||
rtw_result_t result = RTW_SUCCESS;
|
||||
|
||||
if ((rtw_join_status & JOIN_SIMPLE_CONFIG )
|
||||
|| (rtw_join_status & JOIN_AIRKISS )) {
|
||||
return RTW_ERROR;
|
||||
}
|
||||
|
||||
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) {
|
||||
return RTW_NOMEM;
|
||||
}
|
||||
if (ssid_len && ssid) {
|
||||
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);
|
||||
|
||||
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)))) {
|
||||
return RTW_INVALID_KEY;
|
||||
}
|
||||
join_result->network_info.password_len = password_len;
|
||||
if (password_len) {
|
||||
// add \0 to the end
|
||||
join_result->network_info.password = rtw_zmalloc(password_len + 1);
|
||||
if (!join_result->network_info.password) {
|
||||
return RTW_NOMEM;
|
||||
}
|
||||
rtw_memcpy(join_result->network_info.password, password, password_len);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
join_semaphore = join_result->join_sema;
|
||||
} else {
|
||||
join_result->join_sema = semaphore;
|
||||
}
|
||||
wifi_reg_event_handler(WIFI_EVENT_NO_NETWORK, wifi_no_network_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_DISCONNECT, wifi_disconn_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_FOURWAY_HANDSHAKE_DONE,
|
||||
wifi_handshake_done_hdl, NULL);
|
||||
#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;
|
||||
if (wifi_connect_local(pWifi) == 0) {
|
||||
struct {
|
||||
u8 bssid[ETH_ALEN + 2];
|
||||
void * p;
|
||||
} bs = { 0 };
|
||||
memcpy(bs.bssid, pWifi->bssid.octet, ETH_ALEN);
|
||||
if (pWifi->ssid.len) {
|
||||
bs.bssid[ETH_ALEN] = '#';
|
||||
bs.bssid[ETH_ALEN + 1] = '@';
|
||||
bs.p = pWifi;
|
||||
}
|
||||
wext_set_bssid(WLAN0_NAME, bssid);
|
||||
}
|
||||
#endif
|
||||
|
||||
join_user_data = join_result;
|
||||
|
||||
if (semaphore == NULL) {
|
||||
if (rtw_down_timeout_sema(&join_result->join_sema, RTW_JOIN_TIMEOUT)
|
||||
== RTW_FALSE) {
|
||||
printf("RTW API: Join bss timeout\n");
|
||||
if (password_len) {
|
||||
rtw_free(join_result->network_info.password);
|
||||
}
|
||||
rtw_free((u8*)join_result);
|
||||
rtw_free_sema(&join_semaphore);
|
||||
result = RTW_TIMEOUT;
|
||||
goto error;
|
||||
} else {
|
||||
rtw_free_sema(&join_semaphore);
|
||||
if (join_result->network_info.password_len) {
|
||||
rtw_free(join_result->network_info.password);
|
||||
}
|
||||
rtw_free((u8*)join_result);
|
||||
if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
|
||||
result = RTW_ERROR;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
result = RTW_SUCCESS;
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
restore_wifi_info_to_flash();
|
||||
#endif
|
||||
|
||||
error: join_user_data = NULL;
|
||||
wifi_unreg_event_handler(WIFI_EVENT_CONNECT, wifi_connected_hdl);
|
||||
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);
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
int wifi_disconnect(void) {
|
||||
int ret = 0;
|
||||
|
@ -995,14 +802,13 @@ int wifi_rf_off(void) {
|
|||
//----------------------------------------------------------------------------//
|
||||
int wifi_on(rtw_mode_t mode) {
|
||||
int ret = 0;
|
||||
//pvvx int timeout = 20; // 20 sec ?!
|
||||
int timeout = wifi_test_timeout_ms / wifi_test_timeout_step_ms;
|
||||
int idx;
|
||||
int devnum = 1;
|
||||
static int event_init = 0;
|
||||
|
||||
if (rltk_wlan_running(WLAN0_IDX)) {
|
||||
printf("WIFI is already running\n");
|
||||
warning_printf("WIFI is already running\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1057,24 +863,25 @@ int wifi_on(rtw_mode_t mode) {
|
|||
|
||||
int wifi_off(void) {
|
||||
// int ret = 0;
|
||||
//pvvx int timeout = 20; // 20 sec ?!
|
||||
|
||||
uint32 timeout = xTaskGetTickCount();
|
||||
|
||||
if ((rltk_wlan_running(WLAN0_IDX) == 0)
|
||||
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
|
||||
info_printf("WIFI is not running\n");
|
||||
return 0;
|
||||
}
|
||||
#if CONFIG_LWIP_LAYER
|
||||
dhcps_deinit();
|
||||
LwIP_DHCP(0, DHCP_STOP);
|
||||
LwIP_DHCP(1, DHCP_STOP);
|
||||
#endif
|
||||
if ((rltk_wlan_running(WLAN0_IDX) == 0)
|
||||
&& (rltk_wlan_running(WLAN1_IDX) == 0)) {
|
||||
info_printf("WIFI is not running\n");
|
||||
return 0;
|
||||
}
|
||||
info_printf("Deinitializing WIFI ...\n");
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
if ((wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP))
|
||||
// @todo
|
||||
wpas_wps_deinit();
|
||||
#endif
|
||||
info_printf("Deinitializing WIFI ...\n");
|
||||
rltk_wlan_deinit();
|
||||
|
||||
while (1) {
|
||||
|
@ -1119,20 +926,24 @@ int wifi_get_lps_dtim(unsigned char *dtim) {
|
|||
return wext_get_lps_dtim(WLAN0_NAME, dtim);
|
||||
}
|
||||
//----------------------------------------------------------------------------//
|
||||
/*
|
||||
static void wifi_ap_sta_assoc_hdl(char* buf, int buf_len, int flags,
|
||||
void* userdata) {
|
||||
//USER TODO
|
||||
|
||||
debug_printf("ap_sta_assoc\n");
|
||||
}
|
||||
static void wifi_ap_sta_disassoc_hdl(char* buf, int buf_len, int flags,
|
||||
void* userdata) {
|
||||
//USER TODO
|
||||
debug_printf("ap_sta_disassoc\n");
|
||||
}
|
||||
*/
|
||||
|
||||
int wifi_get_last_error(void) {
|
||||
return error_flag;
|
||||
}
|
||||
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
int wpas_wps_init(const char* ifname);
|
||||
#endif
|
||||
|
@ -1159,23 +970,22 @@ int wifi_start_ap(char *ssid, rtw_security_t security_type, char *password, int
|
|||
|
||||
if (is_promisc_enabled())
|
||||
promisc_set(0, NULL, 0);
|
||||
|
||||
/*
|
||||
wifi_unreg_event_handler(WIFI_EVENT_STA_ASSOC, wifi_ap_sta_assoc_hdl);
|
||||
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);
|
||||
|
||||
wifi_unreg_event_handler(WIFI_EVENT_STA_DISASSOC, wifi_ap_sta_disassoc_hdl);
|
||||
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;
|
||||
// if(!channel) channel = 1;
|
||||
if(channel < 1 || channel > 14) channel = 1;
|
||||
ret = wext_set_channel(ifname, channel); //Set channel before starting ap
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
|
||||
switch (security_type) {
|
||||
case RTW_SECURITY_OPEN:
|
||||
break;
|
||||
case RTW_SECURITY_WPA2_AES_PSK:
|
||||
if(security_type != RTW_SECURITY_OPEN) { // case RTW_SECURITY_WPA2_AES_PSK:
|
||||
security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
ret = wext_set_auth_param(ifname, IW_AUTH_80211_AUTH_ALG,
|
||||
IW_AUTH_ALG_OPEN_SYSTEM);
|
||||
if (ret == 0)
|
||||
|
@ -1183,11 +993,6 @@ int wifi_start_ap(char *ssid, rtw_security_t security_type, char *password, int
|
|||
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;
|
||||
}
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
|
@ -1204,61 +1009,6 @@ int wifi_start_ap(char *ssid, rtw_security_t security_type, char *password, int
|
|||
#endif
|
||||
exit: return ret;
|
||||
}
|
||||
/*
|
||||
int wifi_start_ap_with_hidden_ssid(char *ssid, rtw_security_t security_type,
|
||||
char *password, int ssid_len, int password_len, int channel) {
|
||||
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, channel); //Set channel before starting ap
|
||||
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;
|
||||
}
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
|
||||
ret = set_hidden_ssid(ifname, 1);
|
||||
if (ret < 0)
|
||||
goto exit;
|
||||
|
||||
ret = wext_set_ap_ssid(ifname, (u8*) ssid, ssid_len);
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
wpas_wps_init(ifname);
|
||||
#endif
|
||||
exit: return ret;
|
||||
}
|
||||
*/
|
||||
|
||||
void wifi_scan_each_report_hdl(char* buf, int buf_len, int flags, void* userdata) {
|
||||
int i = 0;
|
||||
|
@ -1484,9 +1234,9 @@ int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_dat
|
|||
#if SCAN_USE_SEMAPHORE
|
||||
rtw_bool_t result;
|
||||
if(NULL == scan_result_handler_ptr.scan_semaphore)
|
||||
rtw_init_sema(&scan_result_handler_ptr.scan_semaphore, 1);
|
||||
rtw_init_sema(&scan_result_handler_ptr.scan_semaphore, 1);
|
||||
|
||||
scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
|
||||
// scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
|
||||
/* Initialise the semaphore that will prevent simultaneous access - cannot be a mutex, since
|
||||
* we don't want to allow the same thread to start a new scan */
|
||||
result = (rtw_bool_t)rtw_down_timeout_sema(&scan_result_handler_ptr.scan_semaphore, SCAN_LONGEST_WAIT_TIME);
|
||||
|
@ -1504,12 +1254,11 @@ int wifi_scan_networks(rtw_scan_result_handler_t results_handler, void* user_dat
|
|||
count--;
|
||||
}
|
||||
if (count == 0) {
|
||||
printf("[%d]WiFi: Scan is running. Wait 2s timeout.\n",
|
||||
rtw_get_current_time());
|
||||
printf("WiFi: Scan is running. Wait 2s timeout.\n");
|
||||
return RTW_TIMEOUT;
|
||||
}
|
||||
}
|
||||
scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
|
||||
// scan_result_handler_ptr.scan_start_time = rtw_get_current_time();
|
||||
scan_result_handler_ptr.scan_running = 1;
|
||||
#endif
|
||||
|
||||
|
@ -1997,38 +1746,3 @@ int wifi_set_ch_deauth(__u8 enable) {
|
|||
|
||||
//----------------------------------------------------------------------------//
|
||||
#endif //#if CONFIG_WLAN
|
||||
#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
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include "wifi_util.h"
|
||||
#include "wifi_ind.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include "wifi_api.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -72,20 +72,21 @@ typedef struct {
|
|||
/******************************************************
|
||||
* Structures
|
||||
******************************************************/
|
||||
#define SCAN_USE_SEMAPHORE 0
|
||||
|
||||
typedef struct internal_scan_handler{
|
||||
rtw_scan_result_t** pap_details;
|
||||
rtw_scan_result_t * ap_details;
|
||||
int scan_cnt;
|
||||
rtw_bool_t scan_complete;
|
||||
unsigned char max_ap_size;
|
||||
rtw_scan_result_handler_t gscan_result_handler;
|
||||
#if SCAN_USE_SEMAPHORE
|
||||
void * scan_semaphore;
|
||||
#else
|
||||
int scan_running;
|
||||
#endif
|
||||
// unsigned int scan_start_time;
|
||||
void * user_data;
|
||||
unsigned int scan_start_time;
|
||||
unsigned char scan_cnt;
|
||||
unsigned char max_ap_size;
|
||||
volatile unsigned char scan_complete;
|
||||
volatile unsigned char scan_running;
|
||||
} internal_scan_handler_t;
|
||||
|
||||
typedef struct {
|
||||
|
@ -569,7 +570,7 @@ int wifi_set_pscan_chan(__u8 * channel_list,__u8 * pscan_config, __u8 length);
|
|||
*
|
||||
* @return RTW_SUCCESS or RTW_ERROR
|
||||
*/
|
||||
int wifi_get_setting(const char *ifname,rtw_wifi_setting_t *pSetting);
|
||||
int wifi_get_setting(const char *ifname, rtw_wifi_setting_t *pSetting);
|
||||
|
||||
/** Show the network information
|
||||
*
|
||||
|
|
|
@ -4,8 +4,17 @@
|
|||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include <wifi/wifi_ind.h>
|
||||
#if 1
|
||||
#include "drv_types.h" // or #include "wlan_lib.h"
|
||||
#else
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
#include "wlan_lib.h" // or #include "drv_types.h"
|
||||
#endif
|
||||
#include <osdep_service.h>
|
||||
|
||||
#define USE_WIFI_ADAPTER 1 // использовать прямое обращение в тело драйвера WiFi
|
||||
|
||||
int iw_ioctl(const char * ifname, unsigned long request, struct iwreq * pwrq) {
|
||||
memcpy(pwrq->ifr_name, ifname, 5);
|
||||
int ret = rltk_wlan_control(request, (void *) pwrq);
|
||||
|
@ -23,8 +32,35 @@ int iw_ioctl(const char * ifname, unsigned long request, struct iwreq * pwrq) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
extern Rltk_wlan_t rltk_wlan_info[2]; // in wrapper.h
|
||||
LOCAL _adapter * get_padapter(const char *ifname) {
|
||||
if(ifname[4] == '0') {
|
||||
return *(_adapter **)((rltk_wlan_info[0].dev)->priv);
|
||||
} else {
|
||||
return *(_adapter **)((rltk_wlan_info[1].dev)->priv);
|
||||
}
|
||||
return NULL;
|
||||
};
|
||||
#endif
|
||||
|
||||
/* ssid = NULL -> not connected */
|
||||
int wext_get_ssid(const char *ifname, __u8 *ssid) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad != NULL && (pad->mlmepriv.fw_state & 0x41) != 0) {
|
||||
int len = pad->mlmepriv.cur_network.network.Ssid.SsidLength;
|
||||
if(len > 32) rtw_memcpy(ssid, pad->mlmepriv.cur_network.network.Ssid.Ssid, 32);
|
||||
else {
|
||||
rtw_memcpy(ssid, &pad->mlmepriv.cur_network.network.Ssid.Ssid, len);
|
||||
ssid[len] = '\0';
|
||||
debug_printf("s=[%s]\n", ssid);
|
||||
}
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.essid.pointer = ssid;
|
||||
|
@ -43,6 +79,7 @@ int wext_get_ssid(const char *ifname, __u8 *ssid) {
|
|||
ssid[ret] = '\0';
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len) {
|
||||
|
@ -164,6 +201,20 @@ int wext_set_passphrase(const char *ifname, const __u8 *passphrase,
|
|||
}
|
||||
|
||||
int wext_get_passphrase(const char *ifname, __u8 *passphrase) {
|
||||
#if USE_WIFI_ADAPTER
|
||||
extern int rtw_wx_get_passphrase(struct net_device *dev, struct iw_request_info *a, union iwreq_data *wrqu, char *extra);
|
||||
struct net_device * pdev = rltk_wlan_info[0].dev;
|
||||
if(ifname[4] != '0')
|
||||
pdev = rltk_wlan_info[1].dev;
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pdev) {
|
||||
uint16 len[4];
|
||||
ret = rtw_wx_get_passphrase(pdev, 0, &len, passphrase);
|
||||
if(ret == RTW_SUCCESS) passphrase[len[2]] = '\0';
|
||||
debug_printf("pas[%d]-<%s>\n", len[2], passphrase);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.passphrase.pointer = (void *) passphrase;
|
||||
|
@ -173,6 +224,7 @@ int wext_get_passphrase(const char *ifname, __u8 *passphrase) {
|
|||
passphrase[ret] = '\0';
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if 0
|
||||
|
@ -198,6 +250,18 @@ int wext_get_mac_address(const char *ifname, char * mac)
|
|||
#endif
|
||||
|
||||
int wext_enable_powersave(const char *ifname, __u8 ips_mode, __u8 lps_mode) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
ret = rtw_pm_set_ips(pad, ips_mode); // 2 режима 1,2 !
|
||||
if(ret == RTW_SUCCESS) {
|
||||
LeaveAllPowerSaveMode(pad);
|
||||
ret = rtw_pm_set_lps(pad, lps_mode);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
__u16 pindex = 7;
|
||||
__u8 para[16]; // 7 + (1+1+1) + (1+1+1)
|
||||
|
@ -214,8 +278,9 @@ int wext_enable_powersave(const char *ifname, __u8 ips_mode, __u8 lps_mode) {
|
|||
iwr.u.data.pointer = ¶[0];
|
||||
iwr.u.data.length = pindex;
|
||||
return iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
int wext_disable_powersave(const char *ifname) {
|
||||
struct iwreq iwr;
|
||||
__u16 pindex = 7;
|
||||
|
@ -234,9 +299,22 @@ int wext_disable_powersave(const char *ifname) {
|
|||
iwr.u.data.length = pindex;
|
||||
return iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr);
|
||||
}
|
||||
*/
|
||||
|
||||
int wext_set_tdma_param(const char *ifname, __u8 slot_period,
|
||||
__u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
ret = rtw_pm_set_tdma_param(pad,
|
||||
slot_period,
|
||||
rfon_period_len_1,
|
||||
rfon_period_len_2,
|
||||
rfon_period_len_3);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
__u16 pindex = 7;
|
||||
|
@ -254,9 +332,18 @@ int wext_set_tdma_param(const char *ifname, __u8 slot_period,
|
|||
iwr.u.data.pointer = para;
|
||||
iwr.u.data.length = pindex;
|
||||
return iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr);
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
ret = rtw_pm_set_lps_dtim(pad, lps_dtim);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
__u16 pindex = 7;
|
||||
|
@ -274,10 +361,19 @@ int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim) {
|
|||
iwr.u.data.length = pindex;
|
||||
ret = iw_ioctl(ifname, SIOCDEVPRIVATE, &iwr);
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim) {
|
||||
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
*lps_dtim = rtw_pm_get_lps_dtim(pad);
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
__u16 pindex = 7;
|
||||
|
@ -303,6 +399,7 @@ int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim) {
|
|||
ret = -1;
|
||||
}
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_tos_value(const char *ifname, __u8 *tos_value) {
|
||||
|
@ -416,21 +513,49 @@ int wext_set_mode(const char *ifname, int mode) {
|
|||
}
|
||||
|
||||
int wext_get_mode(const char *ifname, int *mode) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
uint16 f = pad->mlmepriv.fw_state;
|
||||
if(f & 8) *mode = 2;
|
||||
else if(f & 0x60) *mode = 1;
|
||||
else if(!(f & 0x10)) *mode = 0;
|
||||
else *mode = 3;
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
int ret = iw_ioctl(ifname, SIOCGIWMODE, &iwr);
|
||||
if (ret >= 0)
|
||||
*mode = iwr.u.mode;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_ap_ssid(const char *ifname, const __u8 *ssid, __u16 ssid_len) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
struct net_device * pdev = rltk_wlan_info[0].dev;
|
||||
if(ifname[4] != '0')
|
||||
pdev = rltk_wlan_info[1].dev;
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pdev) {
|
||||
uint16 len[2];
|
||||
len[0] = ssid_len;
|
||||
len[1] = (ssid_len != 0);
|
||||
ret = rtw_wx_set_ap_essid(pdev, 0, &len, ssid);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.essid.pointer = (void *) ssid;
|
||||
iwr.u.essid.length = ssid_len;
|
||||
iwr.u.essid.flags = (ssid_len != 0);
|
||||
return iw_ioctl(ifname, SIOCSIWPRIVAPESSID, &iwr);
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_country(const char *ifname, rtw_country_code_t country_code) {
|
||||
|
@ -441,12 +566,25 @@ int wext_set_country(const char *ifname, rtw_country_code_t country_code) {
|
|||
}
|
||||
|
||||
int wext_get_rssi(const char *ifname, int *rssi) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
if(pad->mlmepriv.fw_state & 1) {
|
||||
*rssi = pad->recvpriv.rssi; // +2932
|
||||
}
|
||||
else *rssi = 0;
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
int ret = iw_ioctl(ifname, SIOCGIWSENS, &iwr);
|
||||
if (ret >= 0)
|
||||
*rssi = 0 - iwr.u.sens.value;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_set_pscan_channel(const char *ifname,
|
||||
|
@ -483,22 +621,50 @@ int wext_set_pscan_channel(const char *ifname,
|
|||
return ret;
|
||||
}
|
||||
|
||||
//extern int rtw_wx_set_freq(struct net_device *dev, struct iw_request_info *info, union iwreq_data *wrqu, char *extra);
|
||||
|
||||
int wext_set_channel(const char *ifname, __u8 ch) {
|
||||
#if 0 //def USE_WIFI_ADAPTER
|
||||
struct net_device * pdev = rltk_wlan_info[0].dev;
|
||||
if(ifname[4] != '0')
|
||||
pdev = rltk_wlan_info[1].dev;
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pdev) {
|
||||
ret = rtw_wx_set_freq(pdev, ch, NULL, NULL);
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
iwr.u.freq.m = 0;
|
||||
iwr.u.freq.e = 0;
|
||||
iwr.u.freq.i = ch;
|
||||
return iw_ioctl(ifname, SIOCSIWFREQ, &iwr);
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_get_channel(const char *ifname, __u8 *ch) {
|
||||
#ifdef USE_WIFI_ADAPTER
|
||||
_adapter * pad = get_padapter(ifname);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
if(pad->mlmepriv.fw_state & 1) {
|
||||
*ch = pad->mlmepriv.cur_network.network.Configuration.DSConfig;// .Reserved[1]; //.PhyInfo.Optimum_antenna; //
|
||||
}
|
||||
else {
|
||||
*ch = pad->mlmeextpriv.cur_channel; //
|
||||
}
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
#else
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
int ret = iw_ioctl(ifname, SIOCGIWFREQ, &iwr);
|
||||
if (ret >= 0)
|
||||
*ch = iwr.u.freq.i;
|
||||
return ret;
|
||||
#endif
|
||||
}
|
||||
|
||||
int wext_register_multicast_address(const char *ifname, rtw_mac_t *mac) {
|
||||
|
|
|
@ -32,6 +32,7 @@ int wext_set_mac_address(const char *ifname, char * mac);
|
|||
int wext_get_mac_address(const char *ifname, char * mac);
|
||||
int wext_enable_powersave(const char *ifname, __u8 lps_mode, __u8 ips_mode);
|
||||
int wext_disable_powersave(const char *ifname);
|
||||
#define wext_disable_powersave(n) wext_enable_powersave(n, 0, 0)
|
||||
int wext_set_tdma_param(const char *ifname, __u8 slot_period, __u8 rfon_period_len_1, __u8 rfon_period_len_2, __u8 rfon_period_len_3);
|
||||
int wext_set_lps_dtim(const char *ifname, __u8 lps_dtim);
|
||||
int wext_get_lps_dtim(const char *ifname, __u8 *lps_dtim);
|
||||
|
|
|
@ -4,11 +4,20 @@
|
|||
* Created on: 01/11/2017
|
||||
* Author: pvvx
|
||||
*/
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
#include "main.h"
|
||||
|
||||
#include "user_config.h"
|
||||
#include <platform_opts.h>
|
||||
#include "rtl8195a.h"
|
||||
#include "drv_types.h"
|
||||
#include <autoconf.h>
|
||||
#include "FreeRTOS.h"
|
||||
#if 1
|
||||
#include "drv_types.h" // or #include "wlan_lib.h"
|
||||
#else
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
//#include "wlan_lib.h" // or #include "drv_types.h"
|
||||
#endif
|
||||
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#error "Udnef CONFIG_EXAMPLE_WLAN_FAST_CONNECT!"
|
||||
|
@ -28,8 +37,6 @@
|
|||
#include "ethernet_mii/ethernet_mii.h"
|
||||
#endif
|
||||
|
||||
#include "wlan_lib.h"
|
||||
|
||||
#include "flash_eep.h"
|
||||
#include "feep_config.h"
|
||||
|
||||
|
@ -37,6 +44,17 @@
|
|||
#include "main.h"
|
||||
#include "wifi_user_set.h"
|
||||
|
||||
#if 0
|
||||
#undef debug_printf
|
||||
#define debug_printf(fmt, ...) rtl_printf(fmt, ##__VA_ARGS__)
|
||||
#undef info_printf
|
||||
#define info_printf(fmt, ...) rtl_printf(fmt, ##__VA_ARGS__)
|
||||
#undef warning_printf
|
||||
#define warning_printf(fmt, ...) rtl_printf(fmt, ##__VA_ARGS__)
|
||||
#undef error_printf
|
||||
#define error_printf(fmt, ...) rtl_printf(fmt, ##__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
extern void cmd_ap_wps(int argc, char **argv);
|
||||
extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
|
||||
|
@ -46,7 +64,7 @@ extern int wpas_wps_dev_config(u8 *dev_addr, u8 bregistrar);
|
|||
//--- Wlan Config Init-------------------
|
||||
WIFI_CONFIG wifi_cfg = {
|
||||
.mode = DEF_WIFI_MODE, // rtw_mode_t
|
||||
.sleep = DEF_WIFI_ST_SLEEP,
|
||||
.adaptivity = DEF_WIFI_ADAPTIVITY, // rtw_adaptivity_mode_t
|
||||
.country_code = DEF_WIFI_COUNTRY,// rtw_country_code_t
|
||||
.tx_pwr = DEF_WIFI_TX_PWR, // rtw_tx_pwr_percentage_t
|
||||
.bgn = DEF_WIFI_BGN, // rtw_network_mode_t
|
||||
|
@ -57,7 +75,7 @@ WIFI_CONFIG wifi_cfg = {
|
|||
SOFTAP_CONFIG wifi_ap_cfg = {
|
||||
.ssid = DEF_AP_SSID,
|
||||
.password = DEF_AP_PASSWORD,
|
||||
.security_type = DEF_AP_SECURITY, // RTW_SECURITY_WPA2_AES_PSK or RTW_SECURITY_OPEN
|
||||
.security = DEF_AP_SECURITY, // RTW_SECURITY_WPA2_AES_PSK or RTW_SECURITY_OPEN
|
||||
.beacon_interval = DEF_AP_BEACON,
|
||||
.channel = DEF_AP_CHANNEL,
|
||||
.ssid_hidden = 0,
|
||||
|
@ -75,9 +93,11 @@ STATION_CONFIG wifi_st_cfg = {
|
|||
.password = DEF_ST_PASSWORD,
|
||||
.bssid = DEF_ST_BSSID,
|
||||
.flg = DEF_ST_BSSID,
|
||||
.security_type = DEF_ST_SECURITY,
|
||||
.security = DEF_ST_SECURITY,
|
||||
.autoreconnect = DEF_ST_AUTORECONNECT,
|
||||
.reconnect_pause = DEF_ST_RECONNECT_PAUSE
|
||||
.reconnect_pause = DEF_ST_RECONNECT_PAUSE,
|
||||
.sleep = DEF_ST_SLEEP,
|
||||
.dtim = DEF_ST_LPS_DTIM
|
||||
};
|
||||
DHCP_CONFIG wifi_st_dhcp = {
|
||||
.ip = DEF_ST_IP,
|
||||
|
@ -86,10 +106,20 @@ DHCP_CONFIG wifi_st_dhcp = {
|
|||
.mode = 1
|
||||
};
|
||||
|
||||
rtw_mode_t wifi_run_mode = RTW_MODE_NONE;
|
||||
unsigned char wifi_run_mode = RTW_MODE_NONE; // rtw_mode_t
|
||||
unsigned char wifi_st_status;
|
||||
|
||||
extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int,
|
||||
int);
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
//Function
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int, int);
|
||||
#endif
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
//extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
extern uint8_t rtw_power_percentage_idx;
|
||||
extern Rltk_wlan_t rltk_wlan_info[2]; // in wrapper.h
|
||||
|
||||
#define PARM_RECONNECT 1
|
||||
|
||||
|
@ -121,7 +151,8 @@ FEEP_ELEMENT feep_tab[] = {
|
|||
{ FEEP_ID_AP_DHCP_CFG, sizeof(wifi_ap_dhcp), &wifi_ap_dhcp }, // Bit2 BID_AP_DHCP_CFG
|
||||
{ FEEP_ID_ST_DHCP_CFG, sizeof(wifi_st_dhcp), &wifi_st_dhcp }, // Bit3 BID_ST_DHCP_CFG
|
||||
{ FEEP_ID_WIFI_CFG, sizeof(wifi_cfg), &wifi_cfg }, // Bit4 BID_WIFI_CFG
|
||||
// { FEEP_ID_LWIP_CFG, sizeof(lwip_conn_info), &lwip_conn_info }, // Bit5
|
||||
{ FEEP_ID_AP_HOSTNAME, LWIP_NETIF_HOSTNAME_SIZE, &lwip_host_name[1] }, // Bit5 BID_AP_HOSTNAME
|
||||
{ FEEP_ID_ST_HOSTNAME, LWIP_NETIF_HOSTNAME_SIZE, &lwip_host_name[0] }, // Bit5 BID_ST_HOSTNAME
|
||||
{ 0, 0, NULL }
|
||||
};
|
||||
|
||||
|
@ -152,17 +183,7 @@ uint32 write_wifi_cfg(uint32 flg)
|
|||
return ret;
|
||||
}
|
||||
|
||||
typedef int (*wlan_init_done_ptr)(void);
|
||||
typedef int (*write_reconnect_ptr)(uint8_t *data, uint32_t len);
|
||||
//Function
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
extern void (*p_wlan_autoreconnect_hdl)(rtw_security_t, char*, int, char*, int,
|
||||
int);
|
||||
#endif
|
||||
extern wlan_init_done_ptr p_wlan_init_done_callback;
|
||||
//extern write_reconnect_ptr p_write_reconnect_ptr;
|
||||
extern struct netif xnetif[NET_IF_NUM];
|
||||
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
_WEAK void connect_start(void)
|
||||
{
|
||||
info_printf("\%s: Time at start %d ms.\n", __func__, xTaskGetTickCount());
|
||||
|
@ -172,18 +193,42 @@ _WEAK void connect_close(void)
|
|||
{
|
||||
info_printf("\%s: Time at start %d ms.\n", __func__, xTaskGetTickCount());
|
||||
}
|
||||
#endif
|
||||
|
||||
int wlan_init_done_callback(void) {
|
||||
info_printf("WiFi Init after %d ms\n", xTaskGetTickCount());
|
||||
#ifdef NOT_USE_CALLS
|
||||
LOCAL int wlan_init_done_callback(void) {
|
||||
printf("WiFi Init after %d ms\n", xTaskGetTickCount());
|
||||
return 0;
|
||||
}
|
||||
#endif // #ifdef NOT_USE_CALLS
|
||||
|
||||
//char wlan_st_name[] = WLAN0_NAME;
|
||||
char wlan_st_name[] = WLAN0_NAME;
|
||||
char wlan_ap_name[] = WLAN1_NAME;
|
||||
char wlan_st_netifn = 0;
|
||||
char wlan_ap_netifn = 1;
|
||||
extern rtw_mode_t wifi_mode; // новый режим работы
|
||||
|
||||
|
||||
uint32 get_new_ip(void)
|
||||
{
|
||||
if(!(wifi_cfg.mode ^ wifi_run_mode)) {
|
||||
return current_netif->ip_addr.addr;
|
||||
} else if(wifi_cfg.mode == RTW_MODE_AP) {
|
||||
return wifi_ap_dhcp.ip;
|
||||
} else if(wifi_st_dhcp.mode == 2) {
|
||||
return wifi_st_dhcp.ip;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint8 * get_new_hostname(void)
|
||||
{
|
||||
if(!(wifi_cfg.mode ^ wifi_run_mode)) {
|
||||
return current_netif->hostname;
|
||||
} else if(wifi_cfg.mode == RTW_MODE_AP) {
|
||||
return lwip_host_name[1];
|
||||
};
|
||||
return lwip_host_name[0];
|
||||
}
|
||||
|
||||
LOCAL uint8 chk_ap_netif_num(void)
|
||||
{
|
||||
|
@ -202,13 +247,95 @@ LOCAL uint8 chk_ap_netif_num(void)
|
|||
return wlan_ap_netifn;
|
||||
}
|
||||
|
||||
rtw_result_t wifi_run_ap(void) {
|
||||
chk_ap_netif_num();
|
||||
extern Rltk_wlan_t rltk_wlan_info[2]; // in wrapper.h
|
||||
|
||||
/*LOCAL _adapter * get_padapter(int num) {
|
||||
if(rltk_wlan_info[num].enable) {
|
||||
return *(_adapter **)((rltk_wlan_info[0].dev)->priv);
|
||||
}
|
||||
return NULL;
|
||||
};*/
|
||||
#define get_padapter(num) (*(_adapter **)((rltk_wlan_info[num].dev)->priv));
|
||||
|
||||
LOCAL rtw_result_t _wext_set_lps_dtim(int adapter_num, uint8 lps_dtim ) {
|
||||
_adapter * pad = get_padapter(adapter_num);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
ret = rtw_pm_set_lps_dtim(pad, lps_dtim);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOCAL rtw_result_t _wext_enable_powersave(int adapter_num, uint8 ips_mode, uint8 lps_mode) {
|
||||
_adapter * pad = get_padapter(adapter_num);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
ret = rtw_pm_set_ips(pad, ips_mode); // 2 режима 1,2 !
|
||||
if(ret == RTW_SUCCESS) {
|
||||
LeaveAllPowerSaveMode(pad);
|
||||
ret = rtw_pm_set_lps(pad, lps_mode);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOCAL int _wext_cmp_ssid(int adapter_num, uint8 *ssid)
|
||||
{
|
||||
_adapter * pad = get_padapter(adapter_num);
|
||||
int ret = 0;
|
||||
if((pad != NULL) && (pad->mlmepriv.fw_state & 0x41) != 0) {
|
||||
int len = pad->mlmepriv.cur_network.network.Ssid.SsidLength;
|
||||
if(len < 32) len++;
|
||||
else len = 32;
|
||||
ret = (rtl_memcmp(ssid, &pad->mlmepriv.cur_network.network.Ssid.Ssid, len) == 0);
|
||||
debug_printf("%d s[%d]'%s'\n", pad->mlmepriv.fw_state, len, ssid);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef NOT_USE_CALLS
|
||||
|
||||
LOCAL rtw_result_t _wext_get_mode(int adapter_num, int *mode) {
|
||||
_adapter * pad = get_padapter(adapter_num);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
uint16 f = pad->mlmepriv.fw_state;
|
||||
if(f & 8) *mode = 2;
|
||||
else if(f & 0x60) *mode = 1;
|
||||
else if(!(f & 0x10)) *mode = 0;
|
||||
else *mode = 3;
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
LOCAL rtw_result_t _wext_get_channel(int adapter_num, uint8 *ch)
|
||||
{
|
||||
_adapter * pad = get_padapter(adapter_num);
|
||||
rtw_result_t ret = RTW_ERROR;
|
||||
if(pad) {
|
||||
if(pad->mlmepriv.fw_state & 1) {
|
||||
*ch = pad->mlmepriv.htpriv.ch_offset;
|
||||
}
|
||||
else {
|
||||
*ch = pad->mlmeextpriv.cur_channel;
|
||||
}
|
||||
ret = RTW_SUCCESS;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif // #ifdef NOT_USE_CALLS
|
||||
|
||||
|
||||
LOCAL rtw_result_t wifi_run_ap(void) {
|
||||
rtw_result_t ret = RTW_NOTAP;
|
||||
if( (wifi_mode == RTW_MODE_AP) || (wifi_mode == RTW_MODE_STA_AP) ){
|
||||
info_printf("Starting AP (%s, netif%d)...\n", wlan_ap_name, wlan_ap_netifn);
|
||||
/*
|
||||
netif_set_addr(&xnetif[WLAN_AP_NETIF_NUM], &wifi_ap_dhcp.ip,
|
||||
&wifi_ap_dhcp.mask, &wifi_ap_dhcp.gw);
|
||||
*/
|
||||
if(wext_set_sta_num(wifi_ap_cfg.max_sta) != 0) { // Max number of STAs, should be 1..3, default is 3
|
||||
error_printf("AP not set max connections %d!\n", wifi_ap_cfg.max_sta);
|
||||
};
|
||||
|
@ -220,47 +347,57 @@ rtw_result_t wifi_run_ap(void) {
|
|||
wifi_ap_cfg.channel = 1;
|
||||
}
|
||||
ret = wifi_start_ap(wifi_ap_cfg.ssid, //char *ssid,
|
||||
wifi_ap_cfg.security_type, //rtw_security_t ecurity_type,
|
||||
wifi_ap_cfg.security, //rtw_security_t ecurity_type,
|
||||
wifi_ap_cfg.password, //char *password,
|
||||
wifi_ap_cfg.channel, //int channel
|
||||
wifi_ap_cfg.ssid_hidden); //
|
||||
wifi_run_mode |= RTW_MODE_AP;
|
||||
// wifi_run_mode |= RTW_MODE_AP;
|
||||
if (ret != RTW_SUCCESS) {
|
||||
error_printf("Error(%d): Start AP failed!\n\n", ret);;
|
||||
} else {
|
||||
int timeout = 10000 / 200;
|
||||
int timeout = wifi_test_timeout_ms / wifi_test_timeout_step_ms;
|
||||
while (1) {
|
||||
#if 1
|
||||
if (_wext_cmp_ssid(WLAN_AP_NETIF_NUM, &wifi_ap_cfg.ssid )) {
|
||||
#else
|
||||
char essid[33];
|
||||
if (wext_get_ssid(wlan_ap_name, (unsigned char *) essid) > 0) {
|
||||
if (strcmp((const char * ) essid,
|
||||
(const char * )wifi_ap_cfg.ssid)
|
||||
== 0) {
|
||||
if ((wext_get_ssid(wlan_ap_name, (unsigned char *) essid) > 0)
|
||||
&&(strcmp((const char * ) essid, (const char * )wifi_ap_cfg.ssid) == 0)) {
|
||||
#endif
|
||||
#ifdef CONFIG_DONT_CARE_TP
|
||||
pnetiff->flags |= NETIF_FLAG_IPSWITCH;
|
||||
#endif
|
||||
dhcps_ip4addr_pool_start = DEF_AP_DHCP_START;
|
||||
dhcps_ip4addr_pool_end = DEF_AP_DHCP_STOP;
|
||||
dhcps_init(&xnetif[WLAN_AP_NETIF_NUM]);
|
||||
if(wifi_ap_dhcp.mode) {
|
||||
#if defined(DEF_AP_DHCP_START) && defined(DEF_AP_DHCP_STOP)
|
||||
dhcps_ip4addr_pool_start = DEF_AP_DHCP_START;
|
||||
dhcps_ip4addr_pool_end = DEF_AP_DHCP_STOP;
|
||||
#endif
|
||||
dhcps_init(&xnetif[WLAN_AP_NETIF_NUM]);
|
||||
};
|
||||
info_printf("AP '%s' started after %d ms\n",
|
||||
wifi_ap_cfg.ssid, xTaskGetTickCount());
|
||||
show_wifi_ap_ip();
|
||||
if(wifi_cfg.save_flg & (BID_WIFI_AP_CFG | BID_AP_DHCP_CFG))
|
||||
write_wifi_cfg(wifi_cfg.save_flg & (BID_WIFI_AP_CFG | BID_AP_DHCP_CFG));
|
||||
ret = RTW_SUCCESS;
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// extern void connect_start(void);
|
||||
connect_start();
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (timeout == 0) {
|
||||
error_printf("Start AP timeout!\n");
|
||||
ret = RTW_TIMEOUT;
|
||||
break;
|
||||
}
|
||||
vTaskDelay(200 / portTICK_RATE_MS);
|
||||
vTaskDelay(wifi_test_timeout_step_ms / portTICK_RATE_MS);
|
||||
timeout--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
LOCAL rtw_result_t StartStDHCPClient(void)
|
||||
|
@ -300,14 +437,23 @@ LOCAL rtw_result_t StartStDHCPClient(void)
|
|||
ret = RTW_ERROR;
|
||||
}
|
||||
}
|
||||
if(ret == RTW_SUCCESS) {
|
||||
show_wifi_st_ip();
|
||||
wifi_st_status = WIFI_STA_CONNECTED;
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// extern void connect_start(void);
|
||||
connect_start();
|
||||
#endif
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void wifi_autoreconnect_thread_(void *param) {
|
||||
LOCAL void wifi_autoreconnect_thread_(void *param) {
|
||||
int ret = RTW_ERROR;
|
||||
struct wifi_autoreconnect_param *reconnect_param =
|
||||
(struct wifi_autoreconnect_param *) param;
|
||||
printf("auto reconnect ...\n");
|
||||
wifi_st_status = WIFI_STA_RECONNECT;
|
||||
ret = wifi_connect(
|
||||
wifi_st_cfg.bssid,
|
||||
wifi_st_cfg.flg,
|
||||
|
@ -326,14 +472,7 @@ static void wifi_autoreconnect_thread_(void *param) {
|
|||
if(wifi_cfg.save_flg & BID_WIFI_ST_CFG)
|
||||
write_wifi_cfg(BID_WIFI_ST_CFG);
|
||||
// Start DHCPClient
|
||||
ret = StartStDHCPClient();
|
||||
if(ret == RTW_SUCCESS) {
|
||||
show_wifi_st_ip();
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// extern void connect_start(void);
|
||||
connect_start();
|
||||
#endif
|
||||
}
|
||||
StartStDHCPClient();
|
||||
}
|
||||
vTaskDelete(NULL);
|
||||
}
|
||||
|
@ -363,17 +502,17 @@ LOCAL void st_set_autoreconnect(uint8 mode, uint8 count, uint16 timeout) {
|
|||
ad->mlmeextpriv.auto_reconnect = (mode != 0);
|
||||
}
|
||||
|
||||
rtw_result_t wifi_run_st(void) {
|
||||
LOCAL rtw_result_t wifi_run_st(void) {
|
||||
rtw_result_t ret = RTW_SUCCESS;
|
||||
chk_ap_netif_num();
|
||||
// chk_ap_netif_num();
|
||||
if((wifi_mode == RTW_MODE_STA) || (wifi_mode == RTW_MODE_STA_AP)) {
|
||||
#if CONFIG_AUTO_RECONNECT
|
||||
// p_wlan_autoreconnect_hdl = NULL;
|
||||
if (wifi_st_cfg.autoreconnect) {
|
||||
st_set_autoreconnect(1, wifi_st_cfg.autoreconnect, wifi_st_cfg.reconnect_pause);
|
||||
// ret = wext_set_autoreconnect(WLAN0_NAME, 1, wifi_st_cfg.autoreconnect, wifi_st_cfg.reconnect_pause);
|
||||
// if (ret != RTW_SUCCESS)
|
||||
// warning_printf("ERROR: Operation failed! Error=%d\n", ret);
|
||||
ret = wext_set_autoreconnect(WLAN0_NAME, 1, wifi_st_cfg.autoreconnect, wifi_st_cfg.reconnect_pause);
|
||||
if (ret != RTW_SUCCESS)
|
||||
warning_printf("ERROR: Operation failed! Error=%d\n", ret);
|
||||
}
|
||||
#endif
|
||||
info_printf("Connected to AP (%s, netif%d)...\n", wlan_st_name, wlan_st_netifn);
|
||||
|
@ -381,71 +520,60 @@ rtw_result_t wifi_run_st(void) {
|
|||
wifi_st_cfg.bssid,
|
||||
wifi_st_cfg.flg,
|
||||
wifi_st_cfg.ssid,
|
||||
wifi_st_cfg.security_type,
|
||||
idx_to_rtw_security(wifi_st_cfg.security),
|
||||
wifi_st_cfg.password,
|
||||
-1,
|
||||
NULL);
|
||||
wifi_run_mode |= RTW_MODE_STA;
|
||||
wifi_st_status = WIFI_STA_START;
|
||||
// wifi_run_mode |= RTW_MODE_STA;
|
||||
if (ret != RTW_SUCCESS) {
|
||||
error_printf("%s: Operation failed! Error(%d)\n", __func__, ret);
|
||||
} else {
|
||||
if(wifi_cfg.save_flg & BID_WIFI_ST_CFG)
|
||||
write_wifi_cfg(BID_WIFI_ST_CFG);
|
||||
// Start DHCPClient
|
||||
ret = StartStDHCPClient();
|
||||
if(ret == RTW_SUCCESS) {
|
||||
show_wifi_st_ip();
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// extern void connect_start(void);
|
||||
connect_start();
|
||||
#endif
|
||||
}
|
||||
StartStDHCPClient();
|
||||
}
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
|
||||
int _wifi_on(rtw_mode_t mode) {
|
||||
LOCAL int _wifi_on(rtw_mode_t mode) {
|
||||
int ret = 0;
|
||||
uint32 timeout = xTaskGetTickCount();
|
||||
uint8 devnum;
|
||||
|
||||
if (rltk_wlan_running(WLAN0_IDX)) {
|
||||
/*
|
||||
if (!((rltk_wlan_running(WLAN0_IDX) == 0) && (rltk_wlan_running(WLAN1_IDX) == 0))) {
|
||||
warning_printf("WIFI is already running\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int event_init = 0;
|
||||
if (event_init == 0) {
|
||||
init_event_callback_list();
|
||||
event_init = 1;
|
||||
}
|
||||
wifi_mode = mode;
|
||||
*/
|
||||
info_printf("Initializing WIFI...\n");
|
||||
|
||||
uint8 devnum = (mode == RTW_MODE_STA_AP); // flag = 1 -> 2 netif
|
||||
wifi_mode = mode;
|
||||
chk_ap_netif_num();
|
||||
|
||||
// set wifi mib
|
||||
// adaptivity
|
||||
wext_set_adaptivity(RTW_ADAPTIVITY_DISABLE);
|
||||
// wext_set_adaptivity(RTW_ADAPTIVITY_NORMAL);
|
||||
// wext_set_adaptivity(RTW_ADAPTIVITY_CARRIER_SENSE);
|
||||
wext_set_adaptivity(wifi_cfg.adaptivity & 3); // rtw_adaptivity_mode_t
|
||||
|
||||
devnum = (mode == RTW_MODE_STA_AP); // flag use 2 netif
|
||||
ret = rltk_wlan_init(WLAN0_IDX, mode);
|
||||
|
||||
ret = rltk_wlan_init(0, mode);
|
||||
netif_set_up(&xnetif[0]);
|
||||
if (ret < 0) return ret;
|
||||
if(devnum) {
|
||||
netif_set_up(&xnetif[1]);
|
||||
ret = rltk_wlan_init(1, mode);
|
||||
ret = rltk_wlan_init(WLAN1_IDX, mode);
|
||||
if (ret < 0) return ret;
|
||||
netif_set_up(&xnetif[1]);
|
||||
}
|
||||
else {
|
||||
netif_set_down(&xnetif[1]);
|
||||
}
|
||||
rltk_wlan_start(0);
|
||||
if(devnum) rltk_wlan_start(1);
|
||||
|
||||
uint32 timeout = xTaskGetTickCount();
|
||||
rltk_wlan_start(WLAN0_IDX);
|
||||
if(devnum) rltk_wlan_start(WLAN1_IDX);
|
||||
while (1) {
|
||||
if (rltk_wlan_running(0) &&
|
||||
rltk_wlan_running(devnum) ) {
|
||||
if (rltk_wlan_running(WLAN0_IDX)
|
||||
&& rltk_wlan_running(devnum) ) {
|
||||
#if CONFIG_DEBUG_LOG > 2
|
||||
printf("WIFI initialized (%d ms)\n", xTaskGetTickCount() - timeout);
|
||||
#endif
|
||||
|
@ -462,7 +590,7 @@ int _wifi_on(rtw_mode_t mode) {
|
|||
|
||||
extern int lwip_init_done;
|
||||
|
||||
void _LwIP_Init(void)
|
||||
LOCAL void _LwIP_Init(void)
|
||||
{
|
||||
if(!lwip_init_done) {
|
||||
int idx;
|
||||
|
@ -470,14 +598,14 @@ void _LwIP_Init(void)
|
|||
/* Create tcp_ip stack thread */
|
||||
tcpip_init( NULL, NULL );
|
||||
|
||||
chk_ap_netif_num(); // Исполняется после _wifi_on()
|
||||
// chk_ap_netif_num(); // Исполняется после _wifi_on()
|
||||
for(idx = 0; idx < NET_IF_NUM; idx++) {
|
||||
xnetif[idx].name[0] = 'r';
|
||||
xnetif[idx].name[1] = '0' + idx;
|
||||
}
|
||||
netif_add(&xnetif[WLAN_ST_NETIF_NUM], (struct netif *)&wifi_st_dhcp.ip, (struct netif *)&wifi_st_dhcp.mask, (struct netif *)&wifi_st_dhcp.gw, NULL, ðernetif_init, &tcpip_input);
|
||||
netif_add(&xnetif[WLAN_AP_NETIF_NUM], (struct netif *)&wifi_ap_dhcp.ip, (struct netif *)&wifi_ap_dhcp.mask, (struct netif *)&wifi_ap_dhcp.gw, NULL, ðernetif_init, &tcpip_input);
|
||||
#if CONFIG_ETHERNET // && NET_IF_NUM > 2
|
||||
#if CONFIG_ETHERNET // && NET_IF_NUM > 2
|
||||
{
|
||||
struct ip_addr ipaddr;
|
||||
struct ip_addr netmask;
|
||||
|
@ -487,7 +615,7 @@ void _LwIP_Init(void)
|
|||
gw.addr = DEF_EH_GW;
|
||||
netif_add(&xnetif[2], &ipaddr, &netmask, &gw, NULL, ðernetif_mii_init, &tcpip_input);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
/* Registers the default network interface. */
|
||||
netif_set_default(&xnetif[0]);
|
||||
/* When the netif is fully configured this function must be called.*/
|
||||
|
@ -496,8 +624,8 @@ void _LwIP_Init(void)
|
|||
}
|
||||
info_printf("interface %d is initialized\n", idx);
|
||||
lwip_init_done = 1;
|
||||
// для отслеживания первого старта ?
|
||||
// wifi_mode = RTW_MODE_NONE;
|
||||
|
||||
init_event_callback_list();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -505,28 +633,23 @@ int wifi_run(rtw_mode_t mode) {
|
|||
int ret = 0;
|
||||
#if CONFIG_DEBUG_LOG > 4
|
||||
debug_printf("\n%s(%d), %d\n", __func__, mode, wifi_run_mode);
|
||||
debug_printf("old mode = %d, new mode = %d\n", wifi_run_mode, mode);
|
||||
#endif
|
||||
if(wifi_run_mode != mode) {
|
||||
if(wifi_run_mode & RTW_MODE_AP) {
|
||||
#if CONFIG_DEBUG_LOG > 4
|
||||
debug_printf("dhcps_deinit()\n");
|
||||
#endif
|
||||
dhcps_deinit();
|
||||
}
|
||||
if(wifi_mode) { // != mode) {
|
||||
info_printf("Deinitializing WIFI ...\n");
|
||||
wifi_off();
|
||||
wifi_run_mode = RTW_MODE_NONE;
|
||||
wifi_st_status = WIFI_STA_OFF;
|
||||
// wifi_run_mode = RTW_MODE_NONE;
|
||||
vTaskDelay(30);
|
||||
}
|
||||
if (mode != RTW_MODE_NONE) {
|
||||
if (_wifi_on(mode) < 0) {
|
||||
error_printf("Wifi On failed!\n");
|
||||
goto error_end;
|
||||
};
|
||||
};
|
||||
if (mode != RTW_MODE_NONE) {
|
||||
if(wifi_set_country(wifi_cfg.country_code) != RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set tx country_code (%d)!", wifi_cfg.country_code);
|
||||
};
|
||||
// extern uint8_t rtw_power_percentage_idx;
|
||||
if(rtw_power_percentage_idx != wifi_cfg.tx_pwr) {
|
||||
if(rltk_set_tx_power_percentage(wifi_cfg.tx_pwr) != RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set tx power (%d)!", wifi_cfg.tx_pwr);
|
||||
|
@ -535,50 +658,83 @@ int wifi_run(rtw_mode_t mode) {
|
|||
if(wifi_set_network_mode(wifi_cfg.bgn) != RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set network mode (%d)!", wifi_cfg.bgn);
|
||||
}
|
||||
debug_printf("mode == wifi_mode? (%d == %d?)\n", mode, wifi_mode);
|
||||
switch(wifi_mode) {
|
||||
debug_printf("mode=%d, wifi_mode=%d, old_mоde=%d\n", mode, wifi_mode, wifi_run_mode);
|
||||
|
||||
if(mode <= RTW_MODE_STA_AP) {
|
||||
struct netif * pnif = &xnetif[WLAN_ST_NETIF_NUM];
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
// @todo ethernetif_init()...
|
||||
pnif->hostname = lwip_host_name[0];
|
||||
#ifdef USE_NETBIOS
|
||||
netbios_set_name(WLAN_ST_NETIF_NUM, lwip_host_name[0]);
|
||||
#endif
|
||||
#endif
|
||||
netif_set_addr(&xnetif[WLAN_ST_NETIF_NUM], &wifi_st_dhcp.ip,
|
||||
&wifi_st_dhcp.mask, &wifi_st_dhcp.gw);
|
||||
pnif = &xnetif[WLAN_AP_NETIF_NUM];
|
||||
#if LWIP_NETIF_HOSTNAME
|
||||
// @todo ethernetif_init()...
|
||||
pnif->hostname = lwip_host_name[1];
|
||||
#ifdef USE_NETBIOS
|
||||
netbios_set_name(WLAN_AP_NETIF_NUM, lwip_host_name[1]);
|
||||
#endif
|
||||
#endif
|
||||
netif_set_addr(&xnetif[WLAN_AP_NETIF_NUM], &wifi_ap_dhcp.ip,
|
||||
&wifi_ap_dhcp.mask, &wifi_ap_dhcp.gw);
|
||||
|
||||
}
|
||||
switch(mode) {
|
||||
case RTW_MODE_STA_AP:
|
||||
wifi_run_ap();
|
||||
wifi_run_st();
|
||||
break;
|
||||
ret = wifi_run_ap() | wifi_run_st();
|
||||
// _wext_enable_powersave(0, 0, 0);
|
||||
// _wext_set_lps_dtim(0, 0);
|
||||
break;
|
||||
case RTW_MODE_STA:
|
||||
wifi_run_st();
|
||||
break;
|
||||
ret = wifi_run_st();
|
||||
if(_wext_set_lps_dtim(0, wifi_st_cfg.dtim)!= RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set DTIM(%d)!", wifi_st_cfg.dtim);
|
||||
};
|
||||
if(_wext_enable_powersave(0, wifi_st_cfg.sleep & 1, (wifi_st_cfg.sleep >> 1) & 1) != RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set powersave mode!");
|
||||
};
|
||||
break;
|
||||
case RTW_MODE_AP:
|
||||
wifi_run_ap();
|
||||
ret = wifi_run_ap();
|
||||
// _wext_enable_powersave(WLAN0_NAME, 0, 0);
|
||||
break;
|
||||
#if 0// CONFIG_ENABLE_??
|
||||
case RTW_MODE_PROMISC:
|
||||
// @todo
|
||||
break;
|
||||
#endif
|
||||
#if CONFIG_ENABLE_P2P
|
||||
case RTW_MODE_P2P:
|
||||
// @todo
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = 1;
|
||||
error_printf("WiFi: Error mode(%d)\n", wifi_mode);
|
||||
}
|
||||
#if CONFIG_INTERACTIVE_MODE
|
||||
/* Initial uart rx swmaphore*/
|
||||
vSemaphoreCreateBinary(uart_rx_interrupt_sema);
|
||||
xSemaphoreTake(uart_rx_interrupt_sema, 1/portTICK_RATE_MS);
|
||||
start_interactive_mode();
|
||||
#endif
|
||||
if(wifi_cfg.sleep) {
|
||||
if(wext_enable_powersave(WLAN0_NAME, 1, 1) != RTW_SUCCESS) {
|
||||
error_printf("WiFi: Error set powersave mode!");
|
||||
};
|
||||
}
|
||||
ret = 1;
|
||||
};
|
||||
wifi_run_mode = mode;
|
||||
if(ret == 0 && (wifi_cfg.save_flg & BID_WIFI_CFG)) {
|
||||
wifi_cfg.mode = mode;
|
||||
write_wifi_cfg(BID_WIFI_CFG);
|
||||
};
|
||||
} else {
|
||||
ret = 1;
|
||||
ret = 0;
|
||||
error_end:
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_close();
|
||||
#endif
|
||||
if(wifi_run_mode) {
|
||||
wifi_disconnect();
|
||||
};
|
||||
wifi_off();
|
||||
wifi_st_status = WIFI_STA_OFF;
|
||||
wifi_run_mode = RTW_MODE_NONE;
|
||||
chk_ap_netif_num();
|
||||
};
|
||||
chk_ap_netif_num();
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -587,7 +743,7 @@ void wifi_init(void) {
|
|||
debug_printf("\nLoad Config\n");
|
||||
read_wifi_cfg(wifi_cfg.load_flg); // DEF_LOAD_CFG
|
||||
// Call back from wlan driver after wlan init done
|
||||
p_wlan_init_done_callback = wlan_init_done_callback;
|
||||
// p_wlan_init_done_callback = wlan_init_done_callback;
|
||||
// Call back from application layer after wifi_connection success
|
||||
// p_write_reconnect_ptr = wlan_write_reconnect_data_to_flash;
|
||||
p_wlan_autoreconnect_hdl = NULL;
|
||||
|
@ -643,7 +799,7 @@ unsigned char *tab_txt_rtw_eccryption[] = {
|
|||
|
||||
rtw_security_t idx_to_rtw_security(unsigned char idx)
|
||||
{
|
||||
if(idx > 8) idx = 5; // RTW_SECURITY_WPA2_MIXED_PSK
|
||||
if(idx > IDX_SECURITY_UNKNOWN - 1) idx = IDX_SECURITY_WPA2_AES_PSK;
|
||||
return (rtw_security_t)tab_code_rtw_secyrity[idx];
|
||||
}
|
||||
|
||||
|
@ -654,6 +810,12 @@ unsigned char rtw_security_to_idx(rtw_security_t rtw_sec_type)
|
|||
return i;
|
||||
}
|
||||
|
||||
unsigned char * idx_security_to_str(unsigned char idx)
|
||||
{
|
||||
if(idx > IDX_SECURITY_UNKNOWN) idx = IDX_SECURITY_UNKNOWN;
|
||||
return tab_txt_rtw_secyrity[idx];
|
||||
}
|
||||
|
||||
unsigned char * rtw_security_to_str(rtw_security_t rtw_sec_type)
|
||||
{
|
||||
return tab_txt_rtw_secyrity[rtw_security_to_idx(rtw_sec_type)];
|
||||
|
@ -673,16 +835,18 @@ void show_wifi_MAC(void) {
|
|||
void show_wifi_st_cfg(void) {
|
||||
printf("\tSSID: '%s'\n", wifi_st_cfg.ssid);
|
||||
printf("\tPassword: '%s'\n", wifi_st_cfg.password);
|
||||
printf("\tSecurity type: %p\n", wifi_st_cfg.security_type);
|
||||
printf("\tSecurity type: %s\n", idx_security_to_str(wifi_st_cfg.security));
|
||||
printf("\tAuto-reconnect: %d\n", wifi_st_cfg.autoreconnect);
|
||||
printf("\tReconnect pause: %d\n", wifi_st_cfg.reconnect_pause);
|
||||
printf("\tSleep mode: %p\n", wifi_st_cfg.sleep);
|
||||
printf("\tDTIM: %d\n", wifi_st_cfg.dtim);
|
||||
}
|
||||
|
||||
void show_wifi_ap_cfg(void) {
|
||||
printf("\tSSID: '%s'\n", wifi_ap_cfg.ssid);
|
||||
printf("\tSSID hidden: %d\n", wifi_ap_cfg.ssid_hidden);
|
||||
printf("\tPassword: '%s'\n", wifi_ap_cfg.password);
|
||||
printf("\tSecurity type: %p\n", wifi_ap_cfg.security_type);
|
||||
printf("\tSecurity type: %s\n", (wifi_ap_cfg.security)? tab_txt_rtw_secyrity[IDX_SECURITY_WPA2_AES_PSK] : tab_txt_rtw_secyrity[IDX_SECURITY_OPEN]);
|
||||
printf("\tChannel: %d\n", wifi_ap_cfg.channel);
|
||||
printf("\tBeacon interval: %d ms\n", wifi_ap_cfg.beacon_interval);
|
||||
printf("\tMax connections: %d\n", wifi_ap_cfg.max_sta);
|
||||
|
@ -691,9 +855,9 @@ void show_wifi_ap_cfg(void) {
|
|||
void show_wifi_cfg(void) {
|
||||
printf("\tStart mode: %p\n", wifi_cfg.mode);
|
||||
printf("\tCountry code: %d\n", wifi_cfg.country_code);
|
||||
printf("\tSleep mode: %p\n", wifi_cfg.sleep);
|
||||
printf("\tNetwork mode: %d\n", wifi_cfg.bgn);
|
||||
printf("\tTx power: %d\n", wifi_cfg.tx_pwr);
|
||||
printf("\tAdaptivity: %d\n", wifi_cfg.adaptivity);
|
||||
printf("\tLoad flags: %p\n", wifi_cfg.load_flg);
|
||||
printf("\tSave flags: %p\n", wifi_cfg.save_flg);
|
||||
}
|
||||
|
|
|
@ -29,8 +29,10 @@ extern char str_rom_57ch3Dch0A[]; // "==========================================
|
|||
#define BID_AP_DHCP_CFG (1 << 2)
|
||||
#define BID_ST_DHCP_CFG (1 << 3)
|
||||
#define BID_WIFI_CFG (1 << 4)
|
||||
#define BID_AP_HOSTNAME (1 << 5)
|
||||
#define BID_ST_HOSTNAME (1 << 6)
|
||||
|
||||
#define BID_ALL_WIFI_CFG (BID_WIFI_AP_CFG|BID_WIFI_ST_CFG|BID_AP_DHCP_CFG|BID_ST_DHCP_CFG)
|
||||
#define BID_ALL_WIFI_CFG (BID_WIFI_AP_CFG|BID_WIFI_ST_CFG|BID_AP_DHCP_CFG|BID_ST_DHCP_CFG|BID_AP_HOSTNAME|BID_ST_HOSTNAME)
|
||||
|
||||
#define WLAN_ST_NETIF_NUM wlan_st_netifn
|
||||
#define WLAN_AP_NETIF_NUM wlan_ap_netifn
|
||||
|
@ -40,9 +42,11 @@ extern char str_rom_57ch3Dch0A[]; // "==========================================
|
|||
#define FEEP_ID_WIFI_ST_CFG 0x5453 // id:'ST'
|
||||
#define FEEP_ID_AP_DHCP_CFG 0x4144 // id:'DA'
|
||||
#define FEEP_ID_ST_DHCP_CFG 0x5344 // id:'DS'
|
||||
#define FEEP_ID_UART_CFG 0x5530 // id:'0U', type: UART_LOG_CONF
|
||||
#define FEEP_ID_LWIP_CFG 0x4C30 // id:'0L', type: struct atcmd_lwip_conf
|
||||
#define FEEP_ID_DHCP_CFG 0x4430 // id:'0D', type: struct
|
||||
#define FEEP_ID_AP_HOSTNAME 0x4148 // id:'HA'
|
||||
#define FEEP_ID_ST_HOSTNAME 0x5348 // id:'HP'
|
||||
//#define FEEP_ID_UART_CFG 0x5530 // id:'0U', type: UART_LOG_CONF
|
||||
//#define FEEP_ID_LWIP_CFG 0x4C30 // id:'0L', type: struct atcmd_lwip_conf
|
||||
//#define FEEP_ID_DHCP_CFG 0x4430 // id:'0D', type: struct
|
||||
//=========================================
|
||||
#define IW_PASSPHRASE_MAX_SIZE 64
|
||||
#define NDIS_802_11_LENGTH_SSID 32
|
||||
|
@ -54,32 +58,34 @@ extern char str_rom_57ch3Dch0A[]; // "==========================================
|
|||
//--- Wlan Config struct-------------------
|
||||
typedef struct _wifi_config {
|
||||
unsigned char mode; // rtw_mode_t
|
||||
unsigned char sleep;
|
||||
unsigned char adaptivity; // rtw_adaptivity_mode_t
|
||||
unsigned char country_code; // rtw_country_code_t
|
||||
unsigned char tx_pwr; // rtw_tx_pwr_percentage_t
|
||||
unsigned char bgn; // 802.11 rtw_network_mode_t
|
||||
unsigned char load_flg;
|
||||
unsigned char load_flg; // см. BID_WIFI_CFG..
|
||||
unsigned char save_flg;
|
||||
} WIFI_CONFIG, *PWIFI_CONFIG;
|
||||
//---- Interface 0 - wlan0 - AP - struct --
|
||||
typedef struct _softap_config {
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE];
|
||||
rtw_security_t security_type; // RTW_SECURITY_WPA2_AES_PSK or RTW_SECURITY_OPEN
|
||||
uint16 beacon_interval; // Note: support 100 ~ 60000 ms, default 100
|
||||
unsigned char channel; // 1..14
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID+1];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE+1];
|
||||
unsigned short beacon_interval; // Note: support 100 ~ 60000 ms, default 100
|
||||
unsigned char ssid_hidden; // Note: default 0
|
||||
unsigned char security; // 0 = RTW_SECURITY_OPEN, 1 = RTW_SECURITY_WPA2_AES_PSK
|
||||
unsigned char channel; // 1..14
|
||||
unsigned char max_sta; // 1..3
|
||||
} SOFTAP_CONFIG, *PSOFTAP_CONFIG;
|
||||
//---- Interface 1 - wlan1 - ST - struct -
|
||||
typedef struct _station_config {
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE];
|
||||
rtw_security_t security_type;
|
||||
unsigned char ssid[NDIS_802_11_LENGTH_SSID+1];
|
||||
unsigned char password[IW_PASSPHRASE_MAX_SIZE+1];
|
||||
unsigned char bssid[6]; // Note: If bssid set is not ff.ff.ff.ff.ff.ff || 00:00:00:00:00:00
|
||||
unsigned char flg; // station will connect to the router with both ssid[], else if set flg - bssid[] matched.
|
||||
unsigned char security; // IDX_SECURITY
|
||||
unsigned char autoreconnect; // 0 - none, 1..254 - count, 255 - all
|
||||
unsigned char reconnect_pause; // in sec
|
||||
unsigned char flg; // station will connect to the router with both ssid[], else if set flg - bssid[] matched.
|
||||
unsigned char sleep; // 0 - Off, 1 - IPS, 2 - LPS, 3 - IPS/LPS mode
|
||||
unsigned char dtim; // LPS DTIM (2..)
|
||||
// rtw_adaptivity_mode_t
|
||||
} STATION_CONFIG, *PSTATION_CONFIG;
|
||||
//--- LwIP Config -------------------------
|
||||
|
@ -106,13 +112,39 @@ extern SOFTAP_CONFIG wifi_ap_cfg;
|
|||
extern DHCP_CONFIG wifi_ap_dhcp;
|
||||
extern STATION_CONFIG wifi_st_cfg;
|
||||
extern DHCP_CONFIG wifi_st_dhcp;
|
||||
extern rtw_mode_t wifi_run_mode;
|
||||
extern rtw_mode_t wifi_mode;
|
||||
extern unsigned char wifi_run_mode; // rtw_mode_t
|
||||
extern unsigned char wifi_mode; // rtw_mode_t
|
||||
extern unsigned char wifi_st_status; // WIFI_STA_ENUM
|
||||
extern char wlan_st_name[];
|
||||
extern char wlan_ap_name[];
|
||||
extern char wlan_st_netifn;
|
||||
extern char wlan_ap_netifn;
|
||||
|
||||
/* WiFi Station & scan security */
|
||||
typedef enum {
|
||||
IDX_SECURITY_OPEN = 0, //0 Open security
|
||||
IDX_SECURITY_WEP_PSK, //1 WEP Security with open authentication
|
||||
IDX_SECURITY_WEP_SHARED, //2 WEP Security with shared authentication
|
||||
IDX_SECURITY_WPA_TKIP_PSK, //3 WPA Security with TKIP
|
||||
IDX_SECURITY_WPA_AES_PSK, //4 WPA Security with AES
|
||||
IDX_SECURITY_WPA2_TKIP_PSK, //5 WPA2 Security with TKIP
|
||||
IDX_SECURITY_WPA2_AES_PSK, //6 WPA2 Security with AES
|
||||
IDX_SECURITY_WPA2_MIXED_PSK, //7 WPA2 Security with AES & TKIP
|
||||
IDX_SECURITY_WPA_WPA2_MIXED, //8 WPA/WPA2 Security
|
||||
IDX_SECURITY_UNKNOWN //9
|
||||
} IDX_SECURITY;
|
||||
|
||||
/* wifi_st_status */
|
||||
typedef enum {
|
||||
WIFI_STA_OFF,
|
||||
WIFI_STA_START,
|
||||
WIFI_STA_RECONNECT,
|
||||
WIFI_STA_CONNECTED
|
||||
} WIFI_STA_ENUM;
|
||||
|
||||
|
||||
uint8 * get_new_hostname(void);
|
||||
uint32 get_new_ip(void);
|
||||
|
||||
void show_wifi_ap_ip(void);
|
||||
void show_wifi_st_ip(void);
|
||||
|
@ -127,7 +159,27 @@ void wifi_init(void);
|
|||
rtw_security_t idx_to_rtw_security(unsigned char idx);
|
||||
unsigned char rtw_security_to_idx(rtw_security_t rtw_sec_type);
|
||||
unsigned char * rtw_security_to_str(rtw_security_t rtw_sec_type);
|
||||
unsigned char * idx_security_to_str(unsigned char idx);
|
||||
|
||||
/* -------- Api WiFi Scan ------------------------------- */
|
||||
#include "wifi_conf.h"
|
||||
#include "timers.h"
|
||||
|
||||
#define SCAN_CHANNELS 14
|
||||
#define MAX_AP_SIZE 32
|
||||
|
||||
typedef struct web_scan_handler{
|
||||
TimerHandle_t timer;
|
||||
rtw_scan_result_t * ap_details;
|
||||
unsigned char ap_count;
|
||||
unsigned char start_show;
|
||||
unsigned char used_data;
|
||||
volatile unsigned char flg;
|
||||
} web_scan_handler_t;
|
||||
extern web_scan_handler_t web_scan_handler_ptr;
|
||||
typedef rtw_result_t (*api_scan_result_handler_t)(internal_scan_handler_t * ap_scan_result);
|
||||
rtw_result_t api_wifi_scan(api_scan_result_handler_t scan_result_cb);
|
||||
void wifi_close_scan(void);
|
||||
|
||||
void _LwIP_Init(void);
|
||||
|
||||
#endif // _WIFI_API_H_
|
||||
|
|
|
@ -29,7 +29,13 @@
|
|||
#include "ethernet_mii/ethernet_mii.h"
|
||||
#endif
|
||||
|
||||
#include "wlan_lib.h"
|
||||
#if 1
|
||||
#include "drv_types.h" // or #include "wlan_lib.h"
|
||||
#else
|
||||
#include "wifi_constants.h"
|
||||
#include "wifi_structures.h"
|
||||
#include "wlan_lib.h" // or #include "drv_types.h"
|
||||
#endif
|
||||
|
||||
#include "flash_eep.h"
|
||||
#include "feep_config.h"
|
||||
|
@ -39,93 +45,78 @@
|
|||
#include "wifi_user_set.h"
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
*
|
||||
******************************************************/
|
||||
#define SCAN_USE_SEMAPHORE 0
|
||||
#define MAX_AP_SIZE 64
|
||||
|
||||
web_scan_handler_t web_scan_handler_ptr;
|
||||
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
volatile uint8_t scan_end;
|
||||
|
||||
extern internal_scan_handler_t scan_result_handler_ptr;
|
||||
void wifi_scan_each_report_hdl(char* buf, int buf_len, int flags, void* userdata);
|
||||
/*
|
||||
xQueueWiFiScan = xQueueCreate(25, sizeof(rtw_scan_result_t)); // Create a queue...
|
||||
if(xQueueWebSrv) {
|
||||
*/
|
||||
|
||||
LOCAL void _wifi_scan_done_hdl(char* buf, int buf_len, int flags, void* userdata) {
|
||||
int i = 0;
|
||||
internal_scan_handler_t * pscan_rec = &scan_result_handler_ptr;
|
||||
rtw_scan_handler_result_t scan_result_report;
|
||||
LOCAL void _wifi_scan_done_hdl(char* buf, int buf_len, int flags, void* userdata);
|
||||
|
||||
for (i = 0; i < pscan_rec->scan_cnt; i++) {
|
||||
rtw_memcpy(&scan_result_report.ap_details,
|
||||
pscan_rec->pap_details[i],
|
||||
sizeof(rtw_scan_result_t));
|
||||
scan_result_report.scan_complete = pscan_rec->scan_complete;
|
||||
scan_result_report.user_data = pscan_rec->user_data;
|
||||
(*pscan_rec->gscan_result_handler)(&scan_result_report);
|
||||
void wifi_set_timer_scan(int ms) {
|
||||
if(web_scan_handler_ptr.flg) {
|
||||
if(xTimerChangePeriod(web_scan_handler_ptr.timer, ms, portMAX_DELAY) != pdPASS) {
|
||||
error_printf("Error xTimerChangePeriod\n");
|
||||
}
|
||||
}
|
||||
|
||||
pscan_rec->scan_complete = RTW_TRUE;
|
||||
scan_result_report.scan_complete = RTW_TRUE;
|
||||
(*pscan_rec->gscan_result_handler)(&scan_result_report);
|
||||
|
||||
rtw_free(pscan_rec->ap_details);
|
||||
rtw_free(pscan_rec->pap_details);
|
||||
#if SCAN_USE_SEMAPHORE
|
||||
rtw_up_sema(&pscan_rec->scan_semaphore);
|
||||
#else
|
||||
pscan_rec->scan_running = 0;
|
||||
#endif
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, _wifi_scan_done_hdl);
|
||||
}
|
||||
/* -------- WiFi Scan Close ------------------------- */
|
||||
void wifi_close_scan(void)
|
||||
{
|
||||
internal_scan_handler_t * pscan_rec = &scan_result_handler_ptr;
|
||||
web_scan_handler_t * pwscn_rec = &web_scan_handler_ptr;
|
||||
printf("Close scan rec\n");
|
||||
if(pscan_rec->scan_running) {
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, _wifi_scan_done_hdl);
|
||||
if(pscan_rec->ap_details) rtw_free(pscan_rec->ap_details);
|
||||
rtw_memset((void *) pscan_rec, 0, sizeof(internal_scan_handler_t));
|
||||
}
|
||||
if(pwscn_rec->flg) {
|
||||
if(pwscn_rec->timer) xTimerDelete(pwscn_rec->timer, portMAX_DELAY);
|
||||
if(pwscn_rec->ap_details) rtw_free(pwscn_rec->ap_details);
|
||||
rtw_memset(pwscn_rec, 0, sizeof(web_scan_handler_t));
|
||||
}
|
||||
// pscan_rec->scan_complete = 1;
|
||||
}
|
||||
/* -------- WiFi Scan Done ------------------------- */
|
||||
LOCAL void _wifi_scan_done_hdl(char* buf, int buf_len, int flags, void* userdata) {
|
||||
internal_scan_handler_t * pscan_rec = &scan_result_handler_ptr;
|
||||
web_scan_handler_t * pwscn_rec = &web_scan_handler_ptr;
|
||||
if(pscan_rec->gscan_result_handler) {
|
||||
// сторонний вывод
|
||||
(*pscan_rec->gscan_result_handler)(pscan_rec);
|
||||
}
|
||||
else {
|
||||
// оставить структуру pscan_rec->pap_details[i] для вывода в web scan на 5 сек
|
||||
if(pwscn_rec->flg && pscan_rec->scan_cnt) {
|
||||
debug_printf("\nScan done, wait read rec\n");
|
||||
if(xTimerChangePeriod(pwscn_rec->timer, 5000, portMAX_DELAY) != pdPASS) {
|
||||
// error_printf("Error xTimerChangePeriod\n");
|
||||
} else {
|
||||
if(pwscn_rec->ap_details) rtw_free(pwscn_rec->ap_details);
|
||||
pwscn_rec->ap_details = pscan_rec->ap_details;
|
||||
pwscn_rec->ap_count = pscan_rec->scan_cnt;
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl);
|
||||
wifi_unreg_event_handler(WIFI_EVENT_SCAN_DONE, _wifi_scan_done_hdl);
|
||||
rtw_memset((void *) pscan_rec, 0, sizeof(internal_scan_handler_t));
|
||||
pwscn_rec->flg = 2;
|
||||
}
|
||||
return;
|
||||
};
|
||||
}
|
||||
wifi_close_scan();
|
||||
return;
|
||||
}
|
||||
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
LOCAL int _wifi_scan(rtw_scan_type_t scan_type, rtw_bss_type_t bss_type) {
|
||||
int ret;
|
||||
scan_buf_arg * pscan_buf;
|
||||
u16 flags = scan_type | (bss_type << 8);
|
||||
wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, _wifi_scan_done_hdl, NULL);
|
||||
return wext_set_scan(WLAN0_NAME, NULL, 0, flags);
|
||||
}
|
||||
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
/* -------- WiFi Scan Start ------------------------- */
|
||||
LOCAL int _wifi_scan_networks(rtw_scan_result_handler_t results_handler) {
|
||||
internal_scan_handler_t * pscan_rec = &scan_result_handler_ptr;
|
||||
#if SCAN_USE_SEMAPHORE
|
||||
rtw_bool_t result;
|
||||
if(NULL == pscan_rec->scan_semaphore)
|
||||
rtw_init_sema(&pscan_rec->scan_semaphore, 1);
|
||||
|
||||
pscan_rec->scan_start_time = rtw_get_current_time();
|
||||
/* Initialise the semaphore that will prevent simultaneous access - cannot be a mutex, since
|
||||
* we don't want to allow the same thread to start a new scan */
|
||||
result = (rtw_bool_t)rtw_down_timeout_sema(&pscan_rec->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(&pscan_rec->scan_semaphore);
|
||||
return RTW_TIMEOUT;
|
||||
}
|
||||
#else
|
||||
if (pscan_rec->scan_running) {
|
||||
int count = 100;
|
||||
while (pscan_rec->scan_running && count > 0) {
|
||||
rtw_msleep_os(20);
|
||||
count--;
|
||||
}
|
||||
if (count == 0) {
|
||||
printf("[%d]WiFi: Scan is running. Wait 2s timeout.\n",
|
||||
rtw_get_current_time());
|
||||
return RTW_TIMEOUT;
|
||||
}
|
||||
}
|
||||
pscan_rec->scan_start_time = rtw_get_current_time();
|
||||
pscan_rec->scan_running = 1;
|
||||
#endif
|
||||
|
||||
pscan_rec->gscan_result_handler = results_handler;
|
||||
pscan_rec->max_ap_size = MAX_AP_SIZE;
|
||||
pscan_rec->ap_details = (rtw_scan_result_t*) rtw_zmalloc(MAX_AP_SIZE * sizeof(rtw_scan_result_t) + MAX_AP_SIZE * sizeof(rtw_scan_result_t*));
|
||||
|
@ -133,19 +124,19 @@ LOCAL int _wifi_scan_networks(rtw_scan_result_handler_t results_handler) {
|
|||
pscan_rec->pap_details = (rtw_scan_result_t**) (&pscan_rec->ap_details[MAX_AP_SIZE]);
|
||||
pscan_rec->scan_cnt = 0;
|
||||
pscan_rec->scan_complete = RTW_FALSE;
|
||||
pscan_rec->user_data = NULL; // ?????????
|
||||
|
||||
if (_wifi_scan(RTW_SCAN_COMMAMD << 4 | RTW_SCAN_TYPE_ACTIVE, RTW_BSS_TYPE_ANY) == RTW_SUCCESS) {
|
||||
pscan_rec->user_data = NULL;
|
||||
wifi_reg_event_handler(WIFI_EVENT_SCAN_RESULT_REPORT, wifi_scan_each_report_hdl, NULL);
|
||||
wifi_reg_event_handler(WIFI_EVENT_SCAN_DONE, _wifi_scan_done_hdl, NULL);
|
||||
if(wext_set_scan(WLAN0_NAME, NULL, 0, RTW_SCAN_TYPE_ACTIVE | (RTW_SCAN_COMMAMD << 4) | (RTW_BSS_TYPE_ANY << 8)) == RTW_SUCCESS) {
|
||||
return RTW_SUCCESS;
|
||||
};
|
||||
rtw_free((u8*)pscan_rec->ap_details);
|
||||
}
|
||||
};
|
||||
rtw_memset((void *) pscan_rec, 0, sizeof(internal_scan_handler_t));
|
||||
wifi_close_scan();
|
||||
return RTW_ERROR;
|
||||
}
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
#define scan_channels 14
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
|
||||
/* -------- wext_set_pscan_channels ----------------- */
|
||||
|
||||
LOCAL int wext_set_pscan_channels(void) {
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
|
@ -153,21 +144,18 @@ LOCAL int wext_set_pscan_channels(void) {
|
|||
int i = 0;
|
||||
rtw_memset(&iwr, 0, sizeof(iwr));
|
||||
//Format of para:function_name num_channel chan1... pscan_config1 ...
|
||||
iwr.u.data.length = (scan_channels + scan_channels + 1) + 12;
|
||||
para = pvPortMalloc((scan_channels + scan_channels + 1) + 12); //size:num_chan + num_time + length + function_name
|
||||
iwr.u.data.length = (SCAN_CHANNELS + SCAN_CHANNELS + 1) + 12;
|
||||
para = rtw_malloc(iwr.u.data.length); //size:num_chan + num_time + length + function_name
|
||||
iwr.u.data.pointer = para;
|
||||
if (para != NULL) {
|
||||
//Cmd
|
||||
rtw_memcpy((char*) para, "PartialScan", 12);
|
||||
//length
|
||||
*(para + 12) = scan_channels;
|
||||
for (i = 0; i < scan_channels; i++) {
|
||||
rtw_memcpy((char*) para, "PartialScan", 12); //Cmd
|
||||
*(para + 12) = SCAN_CHANNELS; // length
|
||||
for (i = 0; i < SCAN_CHANNELS; i++) {
|
||||
*(para + 13 + i) = i + 1;
|
||||
*((__u16 *) (para + 13 + scan_channels + i)) = PSCAN_ENABLE;
|
||||
*((__u16 *) (para + 13 + SCAN_CHANNELS + i)) = PSCAN_ENABLE;
|
||||
}
|
||||
|
||||
ret = iw_ioctl(WLAN0_NAME, SIOCDEVPRIVATE, &iwr);
|
||||
vPortFree(para);
|
||||
rtw_free(para);
|
||||
}
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
else {
|
||||
|
@ -176,49 +164,38 @@ LOCAL int wext_set_pscan_channels(void) {
|
|||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
LOCAL volatile uint8_t scan_end;
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
LOCAL rtw_result_t _scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
rtw_result_t api_wifi_scan(api_scan_result_handler_t scan_result_cb)
|
||||
{
|
||||
if (malloced_scan_result->scan_complete != RTW_TRUE) {
|
||||
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
|
||||
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
|
||||
if(scan_end == 1) {
|
||||
printf("\nScan networks:\n\n");
|
||||
printf("N\tType\tMAC\t\t\tSignal\tCh\tWPS\tSecyrity\tSSID\n\n");
|
||||
};
|
||||
printf("%d\t", scan_end++);
|
||||
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
|
||||
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
|
||||
printf("\t%d\t", record->signal_strength);
|
||||
printf("%d\t", record->channel);
|
||||
printf("%d\t", record->wps_type);
|
||||
{
|
||||
uint8 * s = rtw_security_to_str(record->security);
|
||||
printf("%s\t", s);
|
||||
if(strlen(s) < 8) printf("\t");
|
||||
}
|
||||
printf("%s\n", record->SSID.val);
|
||||
} else {
|
||||
scan_end = 0;
|
||||
printf("\n");
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
void api_wifi_scan(void)
|
||||
{
|
||||
scan_end = 1;
|
||||
if(wext_set_pscan_channels() < 0){
|
||||
error_printf("ERROR: wifi set partial scan channel fail\n");
|
||||
} else if(_wifi_scan_networks(_scan_result_handler) != RTW_SUCCESS){
|
||||
error_printf("ERROR: wifi scan failed\n");
|
||||
} else {
|
||||
internal_scan_handler_t * pscan_rec = &scan_result_handler_ptr;
|
||||
web_scan_handler_t * pwscn_rec = &web_scan_handler_ptr;
|
||||
if ((!pscan_rec->scan_running)
|
||||
&& (!pwscn_rec->flg)) {
|
||||
pscan_rec->scan_running = 1;
|
||||
rtw_memset(pwscn_rec, 0, sizeof(web_scan_handler_t));
|
||||
pwscn_rec->flg = 1;
|
||||
debug_printf("\nStart scan...\n");
|
||||
pwscn_rec->timer = xTimerCreate("webscan", 2500, pdFALSE, NULL, (TimerCallbackFunction_t)wifi_close_scan);
|
||||
if(!pwscn_rec->timer) {
|
||||
// error_printf("Error xTimerCreate\n");
|
||||
} else if(xTimerStart(pwscn_rec->timer, portMAX_DELAY) != pdPASS) {
|
||||
// error_printf("Error xTimerStart\n");
|
||||
} else if(wext_set_pscan_channels() < 0) {
|
||||
// error_printf("ERROR: wifi set partial scan channel fail\n");
|
||||
} else if(_wifi_scan_networks(scan_result_cb) != RTW_SUCCESS) {
|
||||
// error_printf("ERROR: wifi scan failed\n");
|
||||
} else if(scan_result_cb) {
|
||||
int i = 300;
|
||||
while(i-- && scan_end) {
|
||||
while(i-- && pscan_rec->scan_running) {
|
||||
vTaskDelay(10);
|
||||
};
|
||||
};
|
||||
return RTW_SUCCESS;
|
||||
} else
|
||||
return RTW_SUCCESS;
|
||||
wifi_close_scan();
|
||||
return RTW_ERROR;
|
||||
};
|
||||
return RTW_TIMEOUT;
|
||||
}
|
||||
|
||||
|
|
|
@ -234,7 +234,7 @@ struct hal_ops {
|
|||
void (*disable_interrupt)(_adapter *padapter);
|
||||
|
||||
s32 (*interrupt_handler)(_adapter *padapter);
|
||||
void (*clear_interrupt)(_adapter *padapter);
|
||||
//pvvx void (*clear_interrupt)(_adapter *padapter); // нету в SDK !
|
||||
|
||||
#ifdef CONFIG_WOWLAN
|
||||
void (*disable_interrupt_but_cpwm2)(_adapter *padapter);
|
||||
|
|
|
@ -480,16 +480,16 @@ typedef struct _RT_CHANNEL_INFO
|
|||
|
||||
extern int rtw_is_channel_set_contains_channel(RT_CHANNEL_INFO *channel_set, const u32 channel_num, int *pchannel_idx);
|
||||
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
#ifndef _CUS_IE_
|
||||
#define _CUS_IE_
|
||||
typedef struct _cus_ie
|
||||
//#ifdef CONFIG_CUSTOM_IE
|
||||
//#ifndef _CUS_IE_
|
||||
//#define _CUS_IE_
|
||||
typedef struct __cus_ie
|
||||
{
|
||||
u8 *ie;
|
||||
u8 type;
|
||||
}rtw_custom_ie_t, *p_rtw_custom_ie_t;
|
||||
#endif /* _CUS_IE_ */
|
||||
#endif
|
||||
}_rtw_custom_ie_t, *_p_rtw_custom_ie_t;
|
||||
//#endif /* _CUS_IE_ */
|
||||
//#endif
|
||||
|
||||
struct mlme_ext_priv
|
||||
{
|
||||
|
@ -563,7 +563,7 @@ struct mlme_ext_priv
|
|||
#endif
|
||||
u8 partial_scan;
|
||||
#ifdef CONFIG_CUSTOM_IE
|
||||
p_rtw_custom_ie_t cus_ven_ie;
|
||||
_p_rtw_custom_ie_t cus_ven_ie;
|
||||
u8 ie_num;
|
||||
#endif
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ typedef int (*iw_handler)(struct net_device *, struct iw_request_info *,
|
|||
union iwreq_data *, char *);
|
||||
|
||||
struct _NDIS_802_11_SSID {
|
||||
uint32_t SsidLength;
|
||||
uint32_t SsidLength; //+164
|
||||
uint8_t Ssid[36];
|
||||
};
|
||||
typedef struct _NDIS_802_11_SSID NDIS_802_11_SSID;
|
||||
|
@ -422,7 +422,7 @@ struct _WLAN_BSSID_EX {
|
|||
uint32_t Length;
|
||||
NDIS_802_11_MAC_ADDRESS MacAddress;
|
||||
uint8_t Reserved[2];
|
||||
NDIS_802_11_SSID Ssid;
|
||||
NDIS_802_11_SSID Ssid; // +164
|
||||
uint32_t Privacy;
|
||||
NDIS_802_11_RSSI Rssi;
|
||||
NDIS_802_11_NETWORK_TYPE NetworkTypeInUse;
|
||||
|
@ -514,21 +514,21 @@ enum _RT_SCAN_TYPE //: sint32_t
|
|||
typedef enum _RT_SCAN_TYPE RT_SCAN_TYPE;
|
||||
|
||||
struct mlme_priv {
|
||||
_lock lock;
|
||||
sint fw_state;
|
||||
uint8_t bScanInProcess;
|
||||
uint8_t to_join;
|
||||
uint8_t *nic_hdl;
|
||||
_list *pscanned;
|
||||
_queue free_bss_pool;
|
||||
_queue scanned_queue;
|
||||
uint8_t *free_bss_buf;
|
||||
uint16_t num_of_scanned;
|
||||
uint8_t *scan_buf;
|
||||
uint32_t scan_buf_len;
|
||||
uint16_t scan_cnt;
|
||||
uint16_t scan_type;
|
||||
NDIS_802_11_SSID assoc_ssid;
|
||||
_lock lock; //+12
|
||||
sint fw_state; //+16
|
||||
uint8_t bScanInProcess; //+20
|
||||
uint8_t to_join; //+21
|
||||
uint8_t *nic_hdl; //+24
|
||||
_list *pscanned; //+28
|
||||
_queue free_bss_pool; //+32
|
||||
_queue scanned_queue; //+44
|
||||
uint8_t *free_bss_buf; //+56
|
||||
uint16_t num_of_scanned; //+60
|
||||
uint8_t *scan_buf; //+64
|
||||
uint32_t scan_buf_len; //+68
|
||||
uint16_t scan_cnt; //+72
|
||||
uint16_t scan_type; //+74
|
||||
NDIS_802_11_SSID assoc_ssid; //+76
|
||||
uint8_t assoc_bssid[6];
|
||||
struct wlan_network cur_network;
|
||||
uint32_t scan_interval;
|
||||
|
@ -687,7 +687,7 @@ struct mlme_ext_priv { //__attribute__((packed))?
|
|||
uint8_t mlmeext_init;
|
||||
struct atomic_t event_seq;
|
||||
uint16_t mgnt_seq;
|
||||
uint8_t cur_channel;
|
||||
uint8_t cur_channel; // padapter+1270
|
||||
uint8_t cur_bwmode;
|
||||
uint8_t cur_ch_offset;
|
||||
uint8_t cur_wireless_mode;
|
||||
|
@ -845,7 +845,7 @@ struct _atr_aligned8_ recv_priv {
|
|||
uint16_t rxbuffersize;
|
||||
uint8_t is_signal_dbg;
|
||||
uint8_t signal_strength_dbg;
|
||||
int8_t rssi;
|
||||
int8_t rssi; // +2932
|
||||
int8_t rxpwdb;
|
||||
uint8_t signal_strength;
|
||||
uint8_t signal_qual;
|
||||
|
@ -1980,7 +1980,7 @@ struct hal_ops {
|
|||
struct _atr_aligned4_ _ADAPTER {
|
||||
uint16_t HardwareType;
|
||||
uint16_t interface_type; //+2
|
||||
uint32_t work_mode;
|
||||
uint32_t work_mode; //+4
|
||||
struct dvobj_priv *dvobj; //+8
|
||||
struct mlme_priv mlmepriv; //+12 [1244]
|
||||
struct mlme_ext_priv mlmeextpriv; //+1256 [912]
|
||||
|
|
|
@ -125,7 +125,7 @@ typedef struct rtw_scan_handler_result {
|
|||
* @brief The structure is used to store the WIFI setting gotten from WIFI driver.
|
||||
*/
|
||||
typedef struct rtw_wifi_setting {
|
||||
rtw_mode_t mode;
|
||||
rtw_mode_t mode;
|
||||
unsigned char ssid[33];
|
||||
unsigned char channel;
|
||||
rtw_security_t security_type;
|
||||
|
|
|
@ -617,7 +617,7 @@ typedef struct _WLAN_BSSID_EX
|
|||
u8 Reserved[1]; //[0]: IS beacon frame
|
||||
u8 bP2pNetwork;
|
||||
#else
|
||||
u8 Reserved[2]; //[0]: IS beacon frame
|
||||
u8 Reserved[2]; //[0]: IS beacon frame (padapter+163)
|
||||
#endif
|
||||
NDIS_802_11_SSID Ssid;
|
||||
u32 Privacy;
|
||||
|
|
|
@ -254,7 +254,7 @@ extern struct sk_buff *rltk_wlan_alloc_skb(unsigned int total_len);
|
|||
extern void rltk_wlan_send_skb(int idx, struct sk_buff *skb);
|
||||
extern void rltk_netif_rx(struct sk_buff *skb);
|
||||
extern int rltk_del_station(const char *ifname, u8 *hwaddr);
|
||||
extern int rltk_get_auto_chl(const char *ifname, u8 *channel_set, int channel_num, int a4);
|
||||
extern int rltk_get_auto_chl(const char *ifname, u8 *channel_set, int channel_num);
|
||||
extern int rltk_set_tx_power_percentage(rtw_tx_pwr_percentage_t power_percentage_idx);
|
||||
extern int rltk_wlan_control(unsigned long cmd, void *data);
|
||||
extern unsigned char rltk_wlan_running(unsigned char idx);
|
||||
|
|
|
@ -512,13 +512,13 @@ typedef long long __i64;
|
|||
#define IW_QUAL_QUAL_UPDATED 0x01 /* Value was updated since last read */
|
||||
#define IW_QUAL_LEVEL_UPDATED 0x02
|
||||
#define IW_QUAL_NOISE_UPDATED 0x04
|
||||
#define IW_QUAL_ALL_UPDATED 0x07
|
||||
#define IW_QUAL_DBM 0x08 /* Level + Noise are dBm */
|
||||
#define IW_QUAL_ALL_UPDATED 0x07
|
||||
#define IW_QUAL_DBM 0x08 /* Level + Noise are dBm */
|
||||
#define IW_QUAL_QUAL_INVALID 0x10 /* Driver doesn't provide value */
|
||||
#define IW_QUAL_LEVEL_INVALID 0x20
|
||||
#define IW_QUAL_NOISE_INVALID 0x40
|
||||
#define IW_QUAL_RCPI 0x80 /* Level + Noise are 802.11k RCPI */
|
||||
#define IW_QUAL_ALL_INVALID 0x70
|
||||
#define IW_QUAL_RCPI 0x80 /* Level + Noise are 802.11k RCPI */
|
||||
#define IW_QUAL_ALL_INVALID 0x70
|
||||
|
||||
/* Frequency flags */
|
||||
#define IW_FREQ_AUTO 0x00 /* Let the driver decides */
|
||||
|
@ -567,7 +567,7 @@ typedef long long __i64;
|
|||
#define IW_TXPOW_RANGE 0x1000 /* Range of value between min/max */
|
||||
|
||||
/* Retry limits and lifetime flags available */
|
||||
#define IW_RETRY_ON 0x0000 /* No details... */
|
||||
#define IW_RETRY_ON 0x0000 /* No details... */
|
||||
#define IW_RETRY_TYPE 0xF000 /* Type of parameter */
|
||||
#define IW_RETRY_LIMIT 0x1000 /* Maximum number of retries*/
|
||||
#define IW_RETRY_LIFETIME 0x2000 /* Maximum duration of retries in us */
|
||||
|
@ -631,10 +631,10 @@ typedef long long __i64;
|
|||
#define IW_AUTH_WPA_VERSION_WPA2 0x00000004
|
||||
|
||||
/* IW_AUTH_PAIRWISE_CIPHER and IW_AUTH_GROUP_CIPHER values (bit field) */
|
||||
#define IW_AUTH_CIPHER_NONE 0x00000001
|
||||
#define IW_AUTH_CIPHER_NONE 0x00000001
|
||||
#define IW_AUTH_CIPHER_WEP40 0x00000002
|
||||
#define IW_AUTH_CIPHER_TKIP 0x00000004
|
||||
#define IW_AUTH_CIPHER_CCMP 0x00000008
|
||||
#define IW_AUTH_CIPHER_TKIP 0x00000004
|
||||
#define IW_AUTH_CIPHER_CCMP 0x00000008
|
||||
#define IW_AUTH_CIPHER_WEP104 0x00000010
|
||||
|
||||
/* IW_AUTH_KEY_MGMT values (bit field) */
|
||||
|
@ -644,7 +644,7 @@ typedef long long __i64;
|
|||
/* IW_AUTH_80211_AUTH_ALG values (bit field) */
|
||||
#define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001
|
||||
#define IW_AUTH_ALG_SHARED_KEY 0x00000002
|
||||
#define IW_AUTH_ALG_LEAP 0x00000004
|
||||
#define IW_AUTH_ALG_LEAP 0x00000004
|
||||
|
||||
/* IW_AUTH_ROAMING_CONTROL values */
|
||||
#define IW_AUTH_ROAMING_ENABLE 0 /* driver/firmware based roaming */
|
||||
|
@ -666,15 +666,15 @@ typedef long long __i64;
|
|||
|
||||
/* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */
|
||||
#define IW_MICFAILURE_KEY_ID 0x00000003 /* Key ID 0..3 */
|
||||
#define IW_MICFAILURE_GROUP 0x00000004
|
||||
#define IW_MICFAILURE_GROUP 0x00000004
|
||||
#define IW_MICFAILURE_PAIRWISE 0x00000008
|
||||
#define IW_MICFAILURE_STAKEY 0x00000010
|
||||
#define IW_MICFAILURE_COUNT 0x00000060 /* 1 or 2 (0 = count not supported)
|
||||
#define IW_MICFAILURE_COUNT 0x00000060 /* 1 or 2 (0 = count not supported)
|
||||
*/
|
||||
|
||||
/* Bit field values for enc_capa in struct iw_range */
|
||||
#define IW_ENC_CAPA_WPA 0x00000001
|
||||
#define IW_ENC_CAPA_WPA2 0x00000002
|
||||
#define IW_ENC_CAPA_WPA 0x00000001
|
||||
#define IW_ENC_CAPA_WPA2 0x00000002
|
||||
#define IW_ENC_CAPA_CIPHER_TKIP 0x00000004
|
||||
#define IW_ENC_CAPA_CIPHER_CCMP 0x00000008
|
||||
|
||||
|
@ -698,8 +698,8 @@ typedef long long __i64;
|
|||
|
||||
/* Modulations bitmasks */
|
||||
#define IW_MODUL_ALL 0x00000000 /* Everything supported */
|
||||
#define IW_MODUL_FH 0x00000001 /* Frequency Hopping */
|
||||
#define IW_MODUL_DS 0x00000002 /* Original Direct Sequence */
|
||||
#define IW_MODUL_FH 0x00000001 /* Frequency Hopping */
|
||||
#define IW_MODUL_DS 0x00000002 /* Original Direct Sequence */
|
||||
#define IW_MODUL_CCK 0x00000004 /* 802.11b : 5.5 + 11 Mb/s */
|
||||
#define IW_MODUL_11B (IW_MODUL_DS | IW_MODUL_CCK)
|
||||
#define IW_MODUL_PBCC 0x00000008 /* TI : 5.5 + 11 + 22 Mb/s */
|
||||
|
@ -714,8 +714,8 @@ typedef long long __i64;
|
|||
#define IW_MODUL_CUSTOM 0x40000000 /* Driver specific */
|
||||
|
||||
/* Bitrate flags available */
|
||||
#define IW_BITRATE_TYPE 0x00FF /* Type of value */
|
||||
#define IW_BITRATE_UNICAST 0x0001 /* Maximum/Fixed unicast bitrate */
|
||||
#define IW_BITRATE_TYPE 0x00FF /* Type of value */
|
||||
#define IW_BITRATE_UNICAST 0x0001 /* Maximum/Fixed unicast bitrate */
|
||||
#define IW_BITRATE_BROADCAST 0x0002 /* Fixed broadcast bitrate */
|
||||
|
||||
/****************************** TYPES ******************************/
|
||||
|
@ -772,7 +772,7 @@ struct iw_freq
|
|||
struct iw_quality
|
||||
{
|
||||
__u8 qual; /* link quality (%retries, SNR,
|
||||
%missed beacons or better...) */
|
||||
%missed beacons or better...) */
|
||||
__u8 level; /* signal level (dBm) */
|
||||
__u8 noise; /* noise level (dBm) */
|
||||
__u8 updated; /* Flags to know if updated */
|
||||
|
@ -988,7 +988,7 @@ union iwreq_data
|
|||
struct iw_param txpower; /* default transmit power */
|
||||
struct iw_param rts; /* RTS threshold threshold */
|
||||
struct iw_param frag; /* Fragmentation threshold */
|
||||
__u32 mode; /* Operation mode */
|
||||
__u32 mode; /* Operation mode */
|
||||
struct iw_param retry; /* Retry limits & lifetime */
|
||||
|
||||
struct iw_point encoding; /* Encoding stuff : tokens */
|
||||
|
|
|
@ -31,9 +31,9 @@ extern "C" {
|
|||
enum eFMEMORY_ERRORS {
|
||||
FMEM_NOT_FOUND = -1, // -1 - не найден
|
||||
FMEM_FLASH_ERR = -2, // -2 - flash rd/wr/erase error
|
||||
FMEM_ERROR = -3, // -3 - error
|
||||
FMEM_OVR_ERR = -4, // -4 - переполнение FMEMORY_SCFG_BANK_SIZE
|
||||
FMEM_MEM_ERR = -5 // -5 - heap alloc error
|
||||
FMEM_ERROR = -3, // -3 - error
|
||||
FMEM_OVR_ERR = -4, // -4 - переполнение FMEMORY_SCFG_BANK_SIZE
|
||||
FMEM_MEM_ERR = -5 // -5 - heap alloc error
|
||||
};
|
||||
//-----------------------------------------------------------------------------
|
||||
// extern QueueHandle_t flash_mutex;
|
||||
|
|
|
@ -521,7 +521,7 @@ void dhcps_init(struct netif * pnetif)
|
|||
|
||||
memset(&ip_table, 0, sizeof(struct table));
|
||||
if((dhcps_ip4addr_pool_end | dhcps_ip4addr_pool_start) == 0) {
|
||||
dhcps_ip4addr_pool_start = 1;
|
||||
dhcps_ip4addr_pool_start = 2;
|
||||
dhcps_ip4addr_pool_end = 255;
|
||||
}
|
||||
|
||||
|
|
|
@ -622,12 +622,14 @@ _timerHandle _freertos_timerCreate( const signed char *pcTimerName,
|
|||
if(xTimerPeriodInTicks == TIMER_MAX_DELAY) {
|
||||
xTimerPeriodInTicks = portMAX_DELAY;
|
||||
}
|
||||
// printf("xTimerCreate: %s, %u, %u, %p\n", pcTimerName, xTimerPeriodInTicks, uxAutoReload, pxCallbackFunction);
|
||||
return xTimerCreate((const char *)pcTimerName, xTimerPeriodInTicks, uxAutoReload, pvTimerID, pxCallbackFunction);
|
||||
}
|
||||
|
||||
u32 _freertos_timerDelete( _timerHandle xTimer,
|
||||
osdepTickType xBlockTime )
|
||||
{
|
||||
// printf("xTimerDelete: %p\n", xTimer);
|
||||
return (u32)xTimerDelete(xTimer, xBlockTime);
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4579
build/obj/build.nmap
4579
build/obj/build.nmap
File diff suppressed because it is too large
Load diff
|
@ -167,7 +167,7 @@ flashimage2p:
|
|||
flashwebfs:
|
||||
@$(OPENOCD) -f interface/$(FLASHER).cfg -c "transport select swd" -f $(FLASHER_PATH)rtl8710.ocd -c "init" -c "adapter_khz $(FLASHER_SPEED)" -c "reset halt" \
|
||||
-c "rtl8710_flash_auto_erase 1" -c "rtl8710_flash_auto_verify 1" \
|
||||
-c "rtl8710_flash_write $(BIN_DIR)/webpages.espfs 0xd0000" \
|
||||
-c "rtl8710_flash_write $(BIN_DIR)/ 0xd0000" \
|
||||
-c "rtl8710_reboot" -c "reset run" -c shutdown
|
||||
|
||||
|
||||
|
|
9
project/inc/user_config.h
Normal file
9
project/inc/user_config.h
Normal file
|
@ -0,0 +1,9 @@
|
|||
#ifndef _user_config_h_
|
||||
#define _user_config_h_
|
||||
|
||||
#define SYS_VERSION "1.0.0"
|
||||
#define SDK_VERSION "3.5.3"
|
||||
|
||||
#endif // _user_config_h_
|
||||
|
||||
|
|
@ -10,55 +10,60 @@
|
|||
|
||||
//=========================================
|
||||
//==== Wlan Config ========================
|
||||
#define DEF_WIFI_MODE RTW_MODE_STA // Стартовый режим WiFi: RTW_MODE_STA_AP, RTW_MODE_AP, RTW_MODE_STA, RTW_MODE_NONE
|
||||
#define DEF_WIFI_AP_STATIONS 3 // Max number of STAs, should be 1..3, default is 3
|
||||
#define DEF_WIFI_COUNTRY RTW_COUNTRY_RU // Страна для установки органичений каналов и прочего...
|
||||
#define DEF_WIFI_TX_PWR RTW_TX_PWR_PERCENTAGE_50 // RTW_TX_PWR_PERCENTAGE_75 // RTW_TX_PWR_PERCENTAGE_100
|
||||
#define DEF_WIFI_MODE RTW_MODE_STA_AP // Стартовый режим WiFi: RTW_MODE_STA_AP, RTW_MODE_AP, RTW_MODE_STA, RTW_MODE_NONE
|
||||
#define DEF_WIFI_AP_STATIONS 3 // Max number of STAs, should be 1..3, default is 3
|
||||
#define DEF_WIFI_COUNTRY RTW_COUNTRY_RU // Регион использования WiFi...
|
||||
#define DEF_WIFI_TX_PWR RTW_TX_PWR_PERCENTAGE_25 // RTW_TX_PWR_PERCENTAGE_75 // RTW_TX_PWR_PERCENTAGE_100
|
||||
#define DEF_WIFI_BGN RTW_NETWORK_BGN // rtw_network_mode_t
|
||||
#define DEF_WIFI_ST_SLEEP 0 // 0 - none, 1 - on
|
||||
#define DEF_WIFI_ADAPTIVITY RTW_ADAPTIVITY_NORMAL // RTW_ADAPTIVITY_DISABLE/RTW_ADAPTIVITY_NORMAL/RTW_ADAPTIVITY_CARRIER_SENSE
|
||||
|
||||
#define DEF_LOAD_CFG ( 0 \
|
||||
| BID_WIFI_AP_CFG \
|
||||
| BID_WIFI_ST_CFG \
|
||||
| BID_AP_DHCP_CFG \
|
||||
| BID_ST_DHCP_CFG \
|
||||
)// | BID_WIFI_CFG \
|
||||
/* Опции загрузки конфигов по старту */
|
||||
//#define DEF_LOAD_CFG 0 // старт в назначенном режиме по умолчанию
|
||||
//#define DEF_LOAD_CFG BID_ALL_WIFI_CFG // старт в назначенном общем режиме по умолчанию, с загрузками последних конфигураций ST и AP
|
||||
#define DEF_LOAD_CFG (BID_ALL_WIFI_CFG | BID_WIFI_CFG) // старт в записанном режиме
|
||||
|
||||
#define DEF_SAVE_CFG ( 0 \
|
||||
| BID_WIFI_AP_CFG \
|
||||
| BID_WIFI_ST_CFG \
|
||||
| BID_AP_DHCP_CFG \
|
||||
| BID_ST_DHCP_CFG \
|
||||
| BID_WIFI_CFG \
|
||||
)
|
||||
/* Опции разрешения записи конфигов по упсешному соединению или выполнению операции установок режимов WiFi без ошибок */
|
||||
#define DEF_SAVE_CFG (BID_ALL_WIFI_CFG | BID_WIFI_CFG) // сохранение по успешному соединению/выполненю для всех конфигов:
|
||||
// (для ST или AP пишутся раздельно) с проверкой на изменения
|
||||
//==== Interface 0 - wlan0 = AP ===========
|
||||
#define DEF_AP_SSID "RTL871X"
|
||||
#define DEF_AP_PASSWORD "0123456789"
|
||||
#define DEF_AP_SECURITY RTW_SECURITY_WPA2_AES_PSK // RTW_SECURITY_OPEN, RTW_SECURITY_WEP_PSK
|
||||
#define DEF_AP_BEACON 100 // 100...6000 ms
|
||||
#define DEF_AP_CHANNEL 1 // 1..14
|
||||
#define DEF_AP_CHANNEL 1 // 1..14
|
||||
#define DEF_AP_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
|
||||
/* Варианты типов Security для AP:
|
||||
RTW_SECURITY_OPEN - Open Security
|
||||
RTW_SECURITY_WPA_TKIP_PSK - WPA Security
|
||||
RTW_SECURITY_WPA2_AES_PSK - WPA2 Security using AES cipher
|
||||
RTW_SECURITY_WPA2_MIXED_PSK - WPA2 Security using AES and/or TKIP ciphers */
|
||||
#define DEF_AP_SECURITY RTW_SECURITY_WPA2_AES_PSK // WEP security is NOT IMPLEMENTED. It is NOT SECURE!
|
||||
#define DEF_AP_BEACON 100 // 100...6000 ms
|
||||
#define DEF_AP_CHANNEL 1 // 1..14
|
||||
#define DEF_AP_CHANNEL 1 // 1..14
|
||||
#define DEF_AP_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
|
||||
#define DEF_AP_IP IP4ADDR(192,168,4,1)
|
||||
#define DEF_AP_MSK IP4ADDR(255,255,255,0)
|
||||
#define DEF_AP_GW IP4ADDR(192,168,4,1)
|
||||
#define DEF_AP_DHCP_START 2
|
||||
#define DEF_AP_DHCP_STOP 15
|
||||
// if not defined DHCP_START && DHCP_STOP -> 2..255
|
||||
//#define DEF_AP_DHCP_START 2 // DHCP ip start xx.xx.xx.2
|
||||
//#define DEF_AP_DHCP_STOP 15 // DHCP ip stop xx.xx.xx.15
|
||||
//==== Interface 1 - wlan1 = STA ==========
|
||||
#define DEF_ST_SSID "HOMEAP"
|
||||
#define DEF_ST_PASSWORD "0123456789"
|
||||
#define DEF_ST_SECURITY RTW_SECURITY_WPA_WPA2_MIXED
|
||||
#define DEF_ST_SSID "HOMEAP" // Имя SSID AP (роутера) для присоединения по умолчанию (первый старт)
|
||||
#define DEF_ST_PASSWORD "0123456789" // Пароль AP (роутера) для присоединения по умолчанию (первый старт)
|
||||
#define DEF_ST_SECURITY RTW_SECURITY_WPA_WPA2_MIXED // Тип Security
|
||||
#define DEF_ST_BSSID { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff } // If bssid set is not ff.ff.ff.ff.ff.ff,
|
||||
// station will connect to the router with both ssid[] and bssid[] matched.
|
||||
#define DEF_ST_CHANNEL 1 // 1..14
|
||||
#define DEF_ST_AUTORECONNECT 3 // 0 - none, 1..254 - count, 255 - all
|
||||
#define DEF_ST_RECONNECT_PAUSE 1 // 1 sec
|
||||
#define DEF_ST_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on, =2 Static ip, =3 - auto
|
||||
#define DEF_ST_USE_BSSID 0 // station will connect to the router with both ssid[] and bssid[] matched.
|
||||
#define DEF_ST_CHANNEL 1 // 1..14
|
||||
#define DEF_ST_AUTORECONNECT 1 // 0 - none, 1..254 - count, 255 - all
|
||||
#define DEF_ST_RECONNECT_PAUSE 1 // 5 sec
|
||||
#define DEF_ST_SLEEP 3 // 0 - Off, 1 - IPS, 2 - LPS, 3 - IPS/LPS mode
|
||||
#define DEF_ST_LPS_DTIM 0 // LPS DTIM
|
||||
#define DEF_ST_DHCP_MODE 1 // =0 dhcp off,
|
||||
// =1 - dhcp on, - динамический ip
|
||||
// =2 Static ip, - fixed ip
|
||||
// =3 - auto fix - старт в режиме "dhcp on", после получения ip - фиксация и переключение в режим рестартов со "Static ip"
|
||||
#define DEF_ST_IP IP4ADDR(192,168,1,100)
|
||||
#define DEF_ST_MSK IP4ADDR(255,255,255,0)
|
||||
#define DEF_ST_GW IP4ADDR(192,168,1,1)
|
||||
//==== Interface 2 - eth0 =================
|
||||
#define DEF_EH_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
|
||||
#define DEF_EH_DHCP_MODE 1 // =0 dhcp off, =1 - dhcp on
|
||||
#define DEF_EH_IP IP4ADDR(192,168,7,200)
|
||||
#define DEF_EH_MSK IP4ADDR(255,255,255,0)
|
||||
#define DEF_EH_GW IP4ADDR(192,168,7,1)
|
||||
|
|
|
@ -22,6 +22,7 @@ extern struct netif xnetif[NET_IF_NUM];
|
|||
|
||||
//==========================================================
|
||||
//--- CONSOLE --------------------------
|
||||
|
||||
// ATPN=<SSID>[,password[,encryption[,auto reconnect[,reconnect pause]]]: WIFI Connect to AP
|
||||
LOCAL void fATPN(int argc, char *argv[]){
|
||||
if(argc > 1) {
|
||||
|
@ -35,28 +36,28 @@ LOCAL void fATPN(int argc, char *argv[]){
|
|||
pswlen = strlen(wifi_st_cfg.password);
|
||||
strncpy(wifi_st_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
|
||||
if(pswlen > 7) {
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
wifi_st_cfg.security = IDX_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
else if(!pswlen) {
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_st_cfg.security = IDX_SECURITY_OPEN;
|
||||
}
|
||||
else {
|
||||
printf("password len < 8!\n");
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_st_cfg.security = IDX_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// default
|
||||
wifi_st_cfg.password[0] = 0;
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_st_cfg.security = IDX_SECURITY_OPEN;
|
||||
}
|
||||
if(argc > 3) {
|
||||
if(pswlen > 7) {
|
||||
wifi_st_cfg.security_type = idx_to_rtw_security(atoi(argv[3]));
|
||||
wifi_st_cfg.security = atoi(argv[3]);
|
||||
}
|
||||
else {
|
||||
printf("password len < 8!\n");
|
||||
wifi_st_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_st_cfg.security = IDX_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
if(argc > 4) {
|
||||
|
@ -68,6 +69,9 @@ LOCAL void fATPN(int argc, char *argv[]){
|
|||
}
|
||||
else wifi_st_cfg.reconnect_pause = 5;
|
||||
show_wifi_st_cfg();
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_close();
|
||||
#endif
|
||||
wifi_run(wifi_run_mode | RTW_MODE_STA);
|
||||
}
|
||||
}
|
||||
|
@ -85,22 +89,22 @@ LOCAL void fATPA(int argc, char *argv[]){
|
|||
strncpy(wifi_ap_cfg.password, argv[2], NDIS_802_11_LENGTH_SSID);
|
||||
int i = strlen(wifi_ap_cfg.password);
|
||||
if(i > 7) {
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_WPA2_AES_PSK;
|
||||
wifi_ap_cfg.security = 1; // IDX_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
else if(i == 0) {
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
|
||||
}
|
||||
else {
|
||||
printf("password len < 8!\n");
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
|
||||
}
|
||||
}
|
||||
else {
|
||||
wifi_ap_cfg.password[0] = 0;
|
||||
wifi_ap_cfg.security_type = RTW_SECURITY_OPEN;
|
||||
wifi_ap_cfg.security = 0; // IDX_SECURITY_OPEN;
|
||||
}
|
||||
if(argc > 3) {
|
||||
wifi_ap_cfg.security_type = (argv[3][0] == '0')? RTW_SECURITY_OPEN : RTW_SECURITY_WPA2_AES_PSK;
|
||||
wifi_ap_cfg.security = (argv[3][0] == '0')? 0 : 1; //RTW_SECURITY_OPEN : RTW_SECURITY_WPA2_AES_PSK;
|
||||
}
|
||||
if(argc > 4) {
|
||||
wifi_ap_cfg.channel = atoi(argv[4]);
|
||||
|
@ -117,6 +121,9 @@ LOCAL void fATPA(int argc, char *argv[]){
|
|||
else wifi_ap_cfg.max_sta = 3;
|
||||
|
||||
show_wifi_ap_cfg();
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_close();
|
||||
#endif
|
||||
wifi_run(wifi_run_mode | RTW_MODE_AP);
|
||||
}
|
||||
}
|
||||
|
@ -126,9 +133,13 @@ LOCAL void fATPA(int argc, char *argv[]){
|
|||
LOCAL void fATWR(int argc, char *argv[]){
|
||||
rtw_mode_t mode = RTW_MODE_NONE;
|
||||
if(argc > 1) mode = atoi(argv[1]);
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
connect_close();
|
||||
#endif
|
||||
wifi_run(mode);
|
||||
}
|
||||
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
// Close connections
|
||||
LOCAL void fATOF(int argc, char *argv[]){
|
||||
connect_close();
|
||||
|
@ -138,8 +149,25 @@ LOCAL void fATOF(int argc, char *argv[]){
|
|||
LOCAL void fATON(int argc, char *argv[]){
|
||||
connect_start();
|
||||
}
|
||||
#endif
|
||||
|
||||
LOCAL void fATWI(int argc, char *argv[]) {
|
||||
#if 1
|
||||
if(argc > 2) {
|
||||
uint8_t c = argv[1][0] | 0x20;
|
||||
if(c == 's') {
|
||||
int i = atoi(argv[2]);
|
||||
printf("Save configs(%d)..\n", i);
|
||||
write_wifi_cfg(atoi(argv[2]));
|
||||
}
|
||||
else if(c == 'l') {
|
||||
wifi_cfg.load_flg = atoi(argv[2]);
|
||||
}
|
||||
else if(c == 'm') {
|
||||
wifi_cfg.mode = atoi(argv[2]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
rtw_wifi_setting_t Setting;
|
||||
if((wifi_run_mode & RTW_MODE_AP)
|
||||
&& wifi_get_setting(wlan_ap_name, &Setting) == 0) {
|
||||
|
@ -163,22 +191,6 @@ LOCAL void fATWI(int argc, char *argv[]) {
|
|||
printf(&str_rom_57ch3Dch0A[25]); // "================================\n"
|
||||
show_wifi_st_cfg();
|
||||
printf("\n");
|
||||
#if 1
|
||||
if(argc > 2) {
|
||||
uint8_t c = argv[1][0] | 0x20;
|
||||
if(c == 's') {
|
||||
int i = atoi(argv[2]);
|
||||
printf("Save configs(%d)..\n", i);
|
||||
write_wifi_cfg(atoi(argv[2]));
|
||||
}
|
||||
else if(c == 'l') {
|
||||
wifi_cfg.load_flg = atoi(argv[2]);
|
||||
}
|
||||
else if(c == 'm') {
|
||||
wifi_cfg.mode = atoi(argv[2]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
extern uint8_t rtw_power_percentage_idx;
|
||||
|
@ -212,77 +224,100 @@ LOCAL void fATSF(int argc, char *argv[])
|
|||
printf("\nTSF: %08x%08x\n", (uint32_t)(tsf>>32), (uint32_t)(tsf));
|
||||
}
|
||||
|
||||
LOCAL void fATWP(int argc, char *argv[]) {
|
||||
if(argc > 1) {
|
||||
release_wakelock(0xffff);
|
||||
wifi_set_power_mode(1, 1);
|
||||
wifi_set_lps_dtim(atoi(argv[1]));
|
||||
}
|
||||
else {
|
||||
unsigned char x;
|
||||
if(wifi_get_lps_dtim(&x) >= 0) {
|
||||
printf("DTIM: %d\n", x);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
volatile uint8_t scan_end;
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
LOCAL rtw_result_t _scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
LOCAL void scan_result_handler(internal_scan_handler_t* ap_scan_result)
|
||||
{
|
||||
if (malloced_scan_result->scan_complete != RTW_TRUE) {
|
||||
rtw_scan_result_t* record = &malloced_scan_result->ap_details;
|
||||
record->SSID.val[record->SSID.len] = 0; /* Ensure the SSID is null terminated */
|
||||
if(scan_end == 1) {
|
||||
if (ap_scan_result) {
|
||||
if(ap_scan_result->scan_cnt) {
|
||||
printf("\nScan networks:\n\n");
|
||||
printf("N\tType\tMAC\t\t\tSignal\tCh\tWPS\tSecyrity\tSSID\n\n");
|
||||
};
|
||||
printf("%d\t", scan_end++);
|
||||
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
|
||||
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
|
||||
printf("\t%d\t", record->signal_strength);
|
||||
printf("%d\t", record->channel);
|
||||
printf("%d\t", record->wps_type);
|
||||
{
|
||||
uint8 * s = rtw_security_to_str(record->security);
|
||||
printf("%s\t", s);
|
||||
if(strlen(s) < 8) printf("\t");
|
||||
}
|
||||
printf("%s\n", record->SSID.val);
|
||||
for(int i = 0 ; i < ap_scan_result->scan_cnt; i++) {
|
||||
rtw_scan_result_t* record = &ap_scan_result->ap_details[i];
|
||||
printf("%d\t", i+1);
|
||||
printf("%s\t", (record->bss_type == RTW_BSS_TYPE_ADHOC)? "Adhoc": "Infra");
|
||||
printf(MAC_FMT, MAC_ARG(record->BSSID.octet));
|
||||
printf("\t%d\t", record->signal_strength);
|
||||
printf("%d\t", record->channel);
|
||||
printf("%d\t", record->wps_type);
|
||||
{
|
||||
uint8 * s = rtw_security_to_str(record->security);
|
||||
printf("%s\t", s);
|
||||
if(strlen(s) < 8) printf("\t");
|
||||
}
|
||||
record->SSID.val[record->SSID.len] = '\0';
|
||||
printf("%s\n", record->SSID.val);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
scan_end = 0;
|
||||
printf("\n");
|
||||
printf("Scan networks: None!\n");
|
||||
}
|
||||
return RTW_SUCCESS;
|
||||
}
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
#define scan_channels 14
|
||||
LOCAL void fATSN(int argc, char *argv[])
|
||||
{
|
||||
int i;
|
||||
u8 *channel_list = (u8*)pvPortMalloc(scan_channels*2);
|
||||
if(channel_list) {
|
||||
scan_end = 1;
|
||||
u8 * pscan_config = &channel_list[scan_channels];
|
||||
//parse command channel list
|
||||
for(i = 1; i <= scan_channels; i++){
|
||||
*(channel_list + i - 1) = i;
|
||||
*(pscan_config + i - 1) = PSCAN_ENABLE;
|
||||
};
|
||||
if(wifi_set_pscan_chan(channel_list, pscan_config, scan_channels) < 0){
|
||||
printf("ERROR: wifi set partial scan channel fail\n");
|
||||
} else if(wifi_scan_networks(_scan_result_handler, NULL ) != RTW_SUCCESS){
|
||||
printf("ERROR: wifi scan failed\n");
|
||||
} else {
|
||||
i = 300;
|
||||
while(i-- && scan_end) {
|
||||
vTaskDelay(10);
|
||||
};
|
||||
};
|
||||
vPortFree(channel_list);
|
||||
} else {
|
||||
printf("ERROR: Can't malloc memory for channel list\n");
|
||||
};
|
||||
api_wifi_scan(scan_result_handler);
|
||||
}
|
||||
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
extern void cmd_ap_wps(int argc, char **argv);
|
||||
extern void cmd_wps(int argc, char **argv);
|
||||
//extern void cmd_wifi_on(int argc, char **argv);
|
||||
#endif
|
||||
#if CONFIG_ENABLE_P2P
|
||||
extern void cmd_wifi_p2p_start(int argc, char **argv);
|
||||
extern void cmd_wifi_p2p_stop(int argc, char **argv);
|
||||
extern void cmd_p2p_listen(int argc, char **argv);
|
||||
extern void cmd_p2p_find(int argc, char **argv);
|
||||
extern void cmd_p2p_peers(int argc, char **argv);
|
||||
extern void cmd_p2p_info(int argc, char **argv);
|
||||
extern void cmd_p2p_disconnect(int argc, char **argv);
|
||||
extern void cmd_p2p_connect(int argc, char **argv);
|
||||
extern void cmd_wifi_p2p_auto_go_start(int argc, char **argv);
|
||||
extern void cmd_p2p_peers(int argc, char **argv);
|
||||
#endif //CONFIG_ENABLE_P2P
|
||||
|
||||
MON_RAM_TAB_SECTION COMMAND_TABLE console_cmd_wifi_api[] = {
|
||||
{"ATPN", 1, fATPN, "=<SSID>[,password[,encryption[,auto-reconnect[,reconnect pause]]]: WIFI Connect to AP"},
|
||||
{"ATPA", 1, fATPA, "=<SSID>[,password[,encryption[,channel[,hidden[,max connections]]]]]: Start WIFI AP"},
|
||||
#if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP
|
||||
{"WPS_AP", 1, cmd_ap_wps, "=<pbc/pin>[,pin]: WiFi AP WPS"},
|
||||
{"WPS_ST", 1, cmd_wps, "=<pbc/pin>[,pin]: WiFi Station WPS"},
|
||||
#endif
|
||||
#if CONFIG_ENABLE_P2P
|
||||
{"P2P_START", 0, cmd_wifi_p2p_start, ": p2p start" },
|
||||
{"P2P_ASTART", 0, cmd_wifi_p2p_auto_go_start, ": p2p auto go start" },
|
||||
{"P2P_STOP", 0, cmd_wifi_p2p_stop, ": p2p stop"},
|
||||
{"P2P_PEERS", 0, cmd_p2p_peers, ": p2p peers" },
|
||||
{"P2P_FIND", 0, cmd_p2p_find, ": p2p find"},
|
||||
{"P2P_INFO", 0, cmd_p2p_info, ": p2p info"},
|
||||
{"P2P_DISCCONNECT", 0, cmd_p2p_disconnect, ": p2p disconnect"},
|
||||
{"P2P_CONNECT", 0, cmd_p2p_connect, ": p2p connect"},
|
||||
#endif
|
||||
{"ATWR", 0, fATWR, ": WIFI Connect, Disconnect"},
|
||||
#if CONFIG_WLAN_CONNECT_CB
|
||||
{"ATON", 0, fATON, ": Open connections"},
|
||||
{"ATOF", 0, fATOF, ": Close connections"},
|
||||
{"ATOFF", 0, fATOF, ": Close connections"},
|
||||
#endif
|
||||
{"ATWI", 0, fATWI, ": WiFi Info"},
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
{"ATWT", 1, fATWT, "=<tx_power>: WiFi tx power: 0 - 100%, 1 - 75%, 2 - 50%, 3 - 25%, 4 - 12.5%"},
|
||||
{"ATSF", 0, fATSF, ": Test TSF value"},
|
||||
#endif
|
||||
{"ATWP", 0, fATWP, ": WiFi power"},
|
||||
{"ATSN", 0, fATSN, ": Scan networks"}
|
||||
};
|
||||
|
||||
|
|
|
@ -114,6 +114,8 @@ SRC_C += sdk/component/common/api/wifi/wifi_promisc.c
|
|||
SRC_C += sdk/component/common/api/wifi/wifi_simple_config.c
|
||||
SRC_C += sdk/component/common/api/wifi/wifi_util.c
|
||||
SRC_C += sdk/component/common/api/lwip_netconf.c
|
||||
SRC_C += sdk/component/common/api/wifi_api.c
|
||||
SRC_C += sdk/component/common/api/wifi_api_scan.c
|
||||
|
||||
#network - app
|
||||
#SRC_C += sdk/component/common/utilities/ssl_client.c
|
||||
|
@ -387,7 +389,6 @@ ADD_SRC_C += sdk/component/soc/realtek/8195a/misc/rtl_std_lib/lib_rtlstd/ram_pvv
|
|||
#ADD_SRC_C += sdk/component/common/drivers/sdio/realtek/sdio_host/src/sdio_host.c
|
||||
#ADD_SRC_C += sdk/component/soc/realtek/8195a/fwlib/src/hal_sdio_host.c
|
||||
#ADD_SRC_C += sdk/component/common/file_system/fatfs/disk_if/src/sdcard.c
|
||||
ADD_SRC_C += sdk/component/common/api/wifi_api.c
|
||||
#=============================================
|
||||
# PROGECT
|
||||
#=============================================
|
||||
|
|
Loading…
Reference in a new issue