add Scan WiFi

This commit is contained in:
pvvx 2017-03-30 05:05:27 +03:00
parent 8482fb4fda
commit d7bf8681b3
11 changed files with 2469 additions and 2284 deletions

View file

@ -1466,15 +1466,16 @@ int wifi_scan_networks(rtw_scan_result_handler_t results_handler,
return RTW_SUCCESS;
error1_with_result_ptr:
error1_with_result_ptr:
rtw_free((u8*)scan_result_handler_ptr.pap_details);
scan_result_handler_ptr.pap_details = NULL;
error2_with_result_ptr:
error2_with_result_ptr:
rtw_free((u8*)scan_result_handler_ptr.ap_details);
scan_result_handler_ptr.ap_details = NULL;
err_exit: rtw_memset((void *) &scan_result_handler_ptr, 0,
err_exit:
rtw_memset((void *) &scan_result_handler_ptr, 0,
sizeof(scan_result_handler_ptr));
return RTW_ERROR;
}

View file

@ -739,6 +739,88 @@ void fATSF(int argc, char *argv[])
printf("\nTSF: %08x%08x\n", (uint32_t)(tsf>>32), (uint32_t)(tsf));
}
/* -------- WiFi Scan ------------------------------- */
unsigned char *tab_txt_rtw_secyrity[] = {
"OPEN ",
"WEP ",
"WPA TKIP",
"WPA AES",
"WPA2 AES",
"WPA2 TKIP",
"WPA2 Mixed",
"WPA/WPA2 AES",
"Unknown"
};
unsigned int *tab_code_rtw_secyrity[] = {
RTW_SECURITY_OPEN,
RTW_SECURITY_WEP_PSK,
RTW_SECURITY_WPA_TKIP_PSK,
RTW_SECURITY_WPA_AES_PSK,
RTW_SECURITY_WPA2_AES_PSK,
RTW_SECURITY_WPA2_TKIP_PSK,
RTW_SECURITY_WPA2_MIXED_PSK,
RTW_SECURITY_WPA_WPA2_MIXED,
RTW_SECURITY_UNKNOWN
};
volatile uint8_t scan_end;
/* -------- WiFi Scan ------------------------------- */
static 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);
int i = 0;
for(; record->security != tab_code_rtw_secyrity[i] && tab_code_rtw_secyrity[i] != RTW_SECURITY_UNKNOWN; i++);
printf("%s \t", tab_txt_rtw_secyrity[i]);
printf("%s\n", record->SSID.val);
} else {
scan_end = 0;
printf("\n");
}
return RTW_SUCCESS;
}
/* -------- WiFi Scan ------------------------------- */
#define scan_channels 14
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");
};
}
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"},
@ -750,4 +832,5 @@ MON_RAM_TAB_SECTION COMMAND_TABLE console_cmd_wifi_api[] = {
{"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
{"ATSN", 0, fATSN, ": Scan networks"}
};

View file

@ -3433,5 +3433,68 @@ struct _TxPowerInfo24G {
typedef struct _TxPowerInfo24G TxPowerInfo24G;
typedef struct _TxPowerInfo24G *PTxPowerInfo24G;
/*
enum rtw_bss_type_t // __int32
{
RTW_BSS_TYPE_INFRASTRUCTURE = 0x0,
RTW_BSS_TYPE_ADHOC = 0x1,
RTW_BSS_TYPE_ANY = 0x2,
RTW_BSS_TYPE_UNKNOWN = 0xFFFFFFFF,
};
enum rtw_security_t // __int32
{
RTW_SECURITY_OPEN = 0x0,
RTW_SECURITY_WEP_PSK = 0x1,
RTW_SECURITY_WEP_SHARED = 0x8001,
RTW_SECURITY_WPA_TKIP_PSK = 0x200002,
RTW_SECURITY_WPA_AES_PSK = 0x200004,
RTW_SECURITY_WPA2_AES_PSK = 0x400004,
RTW_SECURITY_WPA2_TKIP_PSK = 0x400002,
RTW_SECURITY_WPA2_MIXED_PSK = 0x400006,
RTW_SECURITY_WPA_WPA2_MIXED = 0x600000,
RTW_SECURITY_WPS_OPEN = 0x10000000,
RTW_SECURITY_WPS_SECURE = 0x10000004,
RTW_SECURITY_UNKNOWN = 0xFFFFFFFF,
RTW_SECURITY_FORCE_32_BIT = 0x7FFFFFFF,
};
enum rtw_802_11_band_t // __int32
{
RTW_802_11_BAND_5GHZ = 0x0,
RTW_802_11_BAND_2_4GHZ = 0x1,
};
struct rtw_ssid
{
unsigned int8_t len;
unsigned int8_t val[33];
};
typedef rtw_ssid rtw_ssid_t;
struct rtw_mac
{
unsigned int8_t octet[6];
};
typedef rtw_mac rtw_mac_t;
struct rtw_scan_result
{
rtw_ssid_t SSID;
rtw_mac_t BSSID;
sint16_t signal_strength;
enum rtw_bss_type_t bss_type;
enum rtw_security_t security;
enum rtw_wps_type_t wps_type;
unsigned int channel;
enum rtw_802_11_band_t band;
};
*/
#endif // _WLAN_LIB_H

View file

@ -31,7 +31,7 @@ extern "C" {
#endif
#if defined(__IAR_SYSTEMS_ICC__)
#pragma pack(1)
//#pragma pack(1)
#endif
/**
@ -86,7 +86,7 @@ typedef struct rtw_network_info {
int key_id;
}rtw_network_info_t;
#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
#if defined(__IAR_SYSTEMS_ICC__)// || defined(__GNUC__)
#pragma pack(1)
#endif
@ -96,14 +96,14 @@ typedef struct rtw_network_info {
typedef struct rtw_scan_result {
rtw_ssid_t SSID; /**< Service Set Identification (i.e. Name of Access Point) */
rtw_mac_t BSSID; /**< Basic Service Set Identification (i.e. MAC address of Access Point) */
signed short signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
signed short signal_strength; /**< Receive Signal Strength Indication in dBm. <-90=Very poor, >-30=Excellent */
rtw_bss_type_t bss_type; /**< Network type */
rtw_security_t security; /**< Security type */
rtw_wps_type_t wps_type; /**< WPS type */
unsigned int channel; /**< Radio channel that the AP beacon was received on */
unsigned int channel; /**< Radio channel that the AP beacon was received on */
rtw_802_11_band_t band; /**< Radio band */
} rtw_scan_result_t;
#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
#if defined(__IAR_SYSTEMS_ICC__) //|| defined(__GNUC__)
#pragma pack()
#endif
@ -117,7 +117,7 @@ typedef struct rtw_scan_handler_result {
} rtw_scan_handler_result_t;
#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
#if defined(__IAR_SYSTEMS_ICC__) //|| defined(__GNUC__)
#pragma pack(1)
#endif
@ -125,14 +125,14 @@ 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;
unsigned char password[65];
unsigned char key_idx;
}rtw_wifi_setting_t;
#if defined(__IAR_SYSTEMS_ICC__) || defined(__GNUC__)
#if defined(__IAR_SYSTEMS_ICC__) //|| defined(__GNUC__)
#pragma pack()
#endif
@ -167,7 +167,7 @@ typedef struct {
unsigned int version; /**< version field */
unsigned int length; /**< byte length of data in this record, */
/* starting at version and including IEs */
rtw_mac_t BSSID;
rtw_mac_t BSSID;
unsigned short beacon_period; /**< units are Kusec */
unsigned short capability; /**< Capability information */
unsigned char SSID_len;

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load diff

View file

@ -294,6 +294,27 @@ void fATDS(int argc, char *argv[]) // Deep sleep
deepsleep_ex(DSLEEP_WAKEUP_BY_TIMER, sleep_ms);
#endif
}
/*------------------------------------------------------------------------------
* power saving mode
*----------------------------------------------------------------------------*/
void fATSP(int argc, char *argv[])
{
if(argc > 2) {
switch (argv[1][0]) {
case 'a': // acquire
{
acquire_wakelock(atoi(argv[2]));
break;
}
case 'r': // release
{
release_wakelock(atoi(argv[2]));
break;
}
}
}
printf("WakeLock Status %d\n", get_wakelock_status());
}
MON_RAM_TAB_SECTION COMMAND_TABLE console_commands1[] = {
{"ATST", 0, fATST, ": Memory info"},
@ -302,6 +323,7 @@ MON_RAM_TAB_SECTION COMMAND_TABLE console_commands1[] = {
{"ATSD", 1, fATSD, "=<ADDRES(hex)>[,COUNT(dec)]: Dump dword register"},
{"ATSW", 2, fATSW, "=<ADDRES(hex)>,<DATA(hex)>: Set register"},
{"ATDS", 0, fATDS, "=[TIME(ms)]: Deep sleep"},
{"ATSP", 0, fATSP, "=<a,r>,<wakelock_status:1|2|4|8>: Power"}
};
#endif //#ifdef CONFIG_AT_USR