mirror of
https://github.com/drasko/open-ameba.git
synced 2024-11-24 23:14:17 +00:00
update
This commit is contained in:
parent
f8449c5ae3
commit
01d402f038
16 changed files with 2552 additions and 2324 deletions
|
@ -161,6 +161,7 @@
|
|||
extern void *pvPortMalloc( size_t xWantedSize );
|
||||
extern void vPortFree( void *pv );
|
||||
#define malloc pvPortMalloc
|
||||
#define zalloc pvPortZalloc
|
||||
#define free vPortFree
|
||||
#endif
|
||||
#elif defined (CONFIG_PLATFORM_8711B)
|
||||
|
|
|
@ -69,7 +69,7 @@ extern struct netif xnetif[NET_IF_NUM];
|
|||
/******************************************************
|
||||
* Variables Definitions
|
||||
******************************************************/
|
||||
static internal_scan_handler_t scan_result_handler_ptr = {
|
||||
internal_scan_handler_t scan_result_handler_ptr = {
|
||||
0, 0, 0, RTW_FALSE, 0, 0, 0, 0, 0 };
|
||||
static internal_join_result_t* join_user_data;
|
||||
rtw_mode_t wifi_mode = RTW_MODE_NONE;
|
||||
|
@ -1260,8 +1260,7 @@ int wifi_start_ap_with_hidden_ssid(char *ssid, rtw_security_t security_type,
|
|||
}
|
||||
*/
|
||||
|
||||
void wifi_scan_each_report_hdl(char* buf, int buf_len, int flags,
|
||||
void* userdata) {
|
||||
void wifi_scan_each_report_hdl(char* buf, int buf_len, int flags, void* userdata) {
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
int insert_pos = 0;
|
||||
|
|
|
@ -449,7 +449,9 @@ int wext_get_rssi(const char *ifname, int *rssi) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config,
|
||||
int wext_set_pscan_channel(const char *ifname,
|
||||
__u8 *ch,
|
||||
__u8 *pscan_config,
|
||||
__u8 length) {
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
|
@ -480,6 +482,7 @@ int wext_set_pscan_channel(const char *ifname, __u8 *ch, __u8 *pscan_config,
|
|||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wext_set_channel(const char *ifname, __u8 ch) {
|
||||
struct iwreq iwr;
|
||||
memset(&iwr, 0, sizeof(iwr));
|
||||
|
|
|
@ -605,8 +605,8 @@ unsigned char *tab_txt_rtw_secyrity[] = {
|
|||
"WEP SHARED", //2 WEP Security with shared authentication
|
||||
"WPA TKIP", //3 WPA Security with TKIP
|
||||
"WPA AES", //4 WPA Security with AES
|
||||
"WPA2 AES", //5 WPA2 Security with TKIP
|
||||
"WPA2 TKIP", //6 WPA2 Security with AES
|
||||
"WPA2 TKIP", //5 WPA2 Security with TKIP
|
||||
"WPA2 AES", //6 WPA2 Security with AES
|
||||
"WPA2 Mixed", //7 WPA2 Security with AES & TKIP
|
||||
"WPA/WPA2 AES", //8 WPA/WPA2 Security
|
||||
"Unknown" //9
|
||||
|
@ -625,6 +625,7 @@ unsigned int tab_code_rtw_secyrity[] = {
|
|||
RTW_SECURITY_UNKNOWN //9
|
||||
};
|
||||
|
||||
/*
|
||||
unsigned char *tab_txt_rtw_eccryption[] = {
|
||||
"Unknown",
|
||||
"OPEN",
|
||||
|
@ -638,19 +639,18 @@ unsigned char *tab_txt_rtw_eccryption[] = {
|
|||
"WEP104",
|
||||
"Udef" // 0xff
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
rtw_security_t idx_to_rtw_security(unsigned char idx)
|
||||
{
|
||||
if(idx > 8) idx = 5;
|
||||
if(idx > 8) idx = 5; // RTW_SECURITY_WPA2_MIXED_PSK
|
||||
return (rtw_security_t)tab_code_rtw_secyrity[idx];
|
||||
}
|
||||
|
||||
unsigned char rtw_security_to_idx(rtw_security_t rtw_sec_type)
|
||||
{
|
||||
unsigned char i = 0;
|
||||
for(; rtw_sec_type != tab_code_rtw_secyrity[i] && tab_code_rtw_secyrity[i] != RTW_SECURITY_UNKNOWN; i++);
|
||||
i++;
|
||||
while(rtw_sec_type != tab_code_rtw_secyrity[i] && tab_code_rtw_secyrity[i] != RTW_SECURITY_UNKNOWN) i++;
|
||||
return i;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,8 @@ extern char str_rom_57ch3Dch0A[]; // "==========================================
|
|||
#define BID_ST_DHCP_CFG (1 << 3)
|
||||
#define BID_WIFI_CFG (1 << 4)
|
||||
|
||||
#define BID_ALL_WIFI_CFG (BID_WIFI_AP_CFG|BID_WIFI_ST_CFG|BID_AP_DHCP_CFG|BID_ST_DHCP_CFG)
|
||||
|
||||
#define WLAN_ST_NETIF_NUM wlan_st_netifn
|
||||
#define WLAN_AP_NETIF_NUM wlan_ap_netifn
|
||||
//==== FEEP_ID ===========================
|
||||
|
@ -122,7 +124,6 @@ uint32 write_wifi_cfg(uint32 flg);
|
|||
int wifi_run(rtw_mode_t mode);
|
||||
void wifi_init(void);
|
||||
|
||||
extern unsigned char *tab_txt_rtw_eccryption[];
|
||||
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);
|
||||
|
|
224
RTL00_SDKV35a/component/common/api/wifi_api_scan.c
Normal file
224
RTL00_SDKV35a/component/common/api/wifi_api_scan.c
Normal file
|
@ -0,0 +1,224 @@
|
|||
/*
|
||||
* wifi_api_scan.c
|
||||
*
|
||||
* Created on: 23/04/2017
|
||||
* Author: pvvx
|
||||
*/
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include <autoconf.h>
|
||||
#include "main.h"
|
||||
|
||||
#include <platform_opts.h>
|
||||
|
||||
#if CONFIG_EXAMPLE_WLAN_FAST_CONNECT
|
||||
#error "Udnef CONFIG_EXAMPLE_WLAN_FAST_CONNECT!"
|
||||
#endif
|
||||
#ifndef USE_FLASH_EEP
|
||||
#error "Define USE_FLASH_EEP!"
|
||||
#endif
|
||||
|
||||
#include "task.h"
|
||||
#include <platform/platform_stdlib.h>
|
||||
#include <wifi/wifi_conf.h>
|
||||
#include "flash_api.h"
|
||||
#include <lwip_netconf.h>
|
||||
#include "dhcp/dhcps.h"
|
||||
#include "ethernetif.h"
|
||||
#if CONFIG_ETHERNET
|
||||
#include "ethernet_mii/ethernet_mii.h"
|
||||
#endif
|
||||
|
||||
#include "wlan_lib.h"
|
||||
|
||||
#include "flash_eep.h"
|
||||
#include "feep_config.h"
|
||||
|
||||
#include "wifi_api.h"
|
||||
#include "main.h"
|
||||
#include "wifi_user_set.h"
|
||||
|
||||
/******************************************************
|
||||
* Constants
|
||||
******************************************************/
|
||||
#define SCAN_USE_SEMAPHORE 0
|
||||
#define MAX_AP_SIZE 64
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
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 ------------------------------- */
|
||||
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*));
|
||||
if (pscan_rec->ap_details != NULL) {
|
||||
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) {
|
||||
return RTW_SUCCESS;
|
||||
};
|
||||
rtw_free((u8*)pscan_rec->ap_details);
|
||||
};
|
||||
rtw_memset((void *) pscan_rec, 0, sizeof(internal_scan_handler_t));
|
||||
return RTW_ERROR;
|
||||
}
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
#define scan_channels 14
|
||||
/* -------- WiFi Scan ------------------------------- */
|
||||
LOCAL int wext_set_pscan_channels(void) {
|
||||
struct iwreq iwr;
|
||||
int ret = -1;
|
||||
__u8 *para;
|
||||
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.pointer = para;
|
||||
if (para != NULL) {
|
||||
//Cmd
|
||||
rtw_memcpy((char*) para, "PartialScan", 12);
|
||||
//length
|
||||
*(para + 12) = scan_channels;
|
||||
for (i = 0; i < scan_channels; i++) {
|
||||
*(para + 13 + i) = i + 1;
|
||||
*((__u16 *) (para + 13 + scan_channels + i)) = PSCAN_ENABLE;
|
||||
}
|
||||
|
||||
ret = iw_ioctl(WLAN0_NAME, SIOCDEVPRIVATE, &iwr);
|
||||
vPortFree(para);
|
||||
}
|
||||
#if CONFIG_DEBUG_LOG > 3
|
||||
else {
|
||||
error_printf("%s: Can't malloc memory!\n", __func__);
|
||||
}
|
||||
#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 )
|
||||
{
|
||||
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 {
|
||||
int i = 300;
|
||||
while(i-- && scan_end) {
|
||||
vTaskDelay(10);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -119,15 +119,15 @@ typedef enum
|
|||
* AP mode support OPEN and WPA2.
|
||||
*/
|
||||
typedef enum {
|
||||
RTW_SECURITY_OPEN = 0, /**< Open security */
|
||||
RTW_SECURITY_WEP_PSK = WEP_ENABLED, /**< WEP Security with open authentication */
|
||||
RTW_SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /**< WEP Security with shared authentication */
|
||||
RTW_SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /**< WPA Security with TKIP */
|
||||
RTW_SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /**< WPA Security with AES */
|
||||
RTW_SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /**< WPA2 Security with AES */
|
||||
RTW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /**< WPA2 Security with TKIP */
|
||||
RTW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /**< WPA2 Security with AES & TKIP */
|
||||
RTW_SECURITY_WPA_WPA2_MIXED = ( WPA_SECURITY | WPA2_SECURITY ), /**< WPA/WPA2 Security */
|
||||
RTW_SECURITY_OPEN = 0, /*0*< Open security */
|
||||
RTW_SECURITY_WEP_PSK = WEP_ENABLED, /*1*< WEP Security with open authentication */
|
||||
RTW_SECURITY_WEP_SHARED = ( WEP_ENABLED | SHARED_ENABLED ), /*2*< WEP Security with shared authentication */
|
||||
RTW_SECURITY_WPA_TKIP_PSK = ( WPA_SECURITY | TKIP_ENABLED ), /*3*< WPA Security with TKIP */
|
||||
RTW_SECURITY_WPA_AES_PSK = ( WPA_SECURITY | AES_ENABLED ), /*4*< WPA Security with AES */
|
||||
RTW_SECURITY_WPA2_AES_PSK = ( WPA2_SECURITY | AES_ENABLED ), /*5*< WPA2 Security with AES */
|
||||
RTW_SECURITY_WPA2_TKIP_PSK = ( WPA2_SECURITY | TKIP_ENABLED ), /*6*< WPA2 Security with TKIP */
|
||||
RTW_SECURITY_WPA2_MIXED_PSK = ( WPA2_SECURITY | AES_ENABLED | TKIP_ENABLED ), /*7*< WPA2 Security with AES & TKIP */
|
||||
RTW_SECURITY_WPA_WPA2_MIXED = ( WPA_SECURITY | WPA2_SECURITY ), /*8*< WPA/WPA2 Security */
|
||||
|
||||
RTW_SECURITY_WPS_OPEN = WPS_ENABLED, /**< WPS with open security */
|
||||
RTW_SECURITY_WPS_SECURE = (WPS_ENABLED | AES_ENABLED), /**< WPS with AES security */
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4556
build/obj/build.nmap
4556
build/obj/build.nmap
File diff suppressed because it is too large
Load diff
|
@ -10,13 +10,13 @@
|
|||
|
||||
//=========================================
|
||||
//==== Wlan Config ========================
|
||||
#define DEF_WIFI_MODE RTW_MODE_STA // RTW_MODE_STA_AP, RTW_MODE_AP, RTW_MODE_STA
|
||||
#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_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_BGN RTW_NETWORK_BGN // rtw_network_mode_t
|
||||
#define DEF_WIFI_ST_SLEEP 0 // 0 - none, 1 - on
|
||||
//#define USE_NETBIOS 3 // 0 - off, 1 - ST, 2 - AP, 3 - AP+ST
|
||||
|
||||
#define DEF_LOAD_CFG ( 0 \
|
||||
| BID_WIFI_AP_CFG \
|
||||
| BID_WIFI_ST_CFG \
|
||||
|
|
Loading…
Reference in a new issue