mirror of
https://github.com/pvvx/RTL00MP3.git
synced 2025-07-31 12:41:06 +00:00
update
This commit is contained in:
parent
01d402f038
commit
b1d891c21e
30 changed files with 3219 additions and 3085 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue