#if !defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) // #include "FreeRTOS.h" // #include "task.h" // #include "semphr.h" #include #include "main.h" // #include #include #include "lwip/tcpip.h" // #include // #include #include #endif // #include #include #include #include // #include #ifndef CONFIG_INTERACTIVE_EXT #define CONFIG_INTERACTIVE_EXT 0 #endif #ifndef CONFIG_SSL_CLIENT #define CONFIG_SSL_CLIENT 0 #endif #ifndef CONFIG_GOOGLENEST #define CONFIG_GOOGLENEST 0 #endif #if CONFIG_LWIP_LAYER #ifndef CONFIG_WEBSERVER #define CONFIG_WEBSERVER 0 #endif #endif #ifndef CONFIG_OTA_UPDATE #define CONFIG_OTA_UPDATE 0 #endif #ifndef CONFIG_BSD_TCP #define CONFIG_BSD_TCP 0 #endif #ifndef CONFIG_ENABLE_P2P #define CONFIG_ENABLE_P2P 0 #endif #define SCAN_WITH_SSID 1 #if CONFIG_WPS #define STACKSIZE 1280 #else #define STACKSIZE 1024 #endif #ifndef WLAN0_NAME #define WLAN0_NAME "wlan0" #endif #ifndef WLAN1_NAME #define WLAN1_NAME "wlan1" #endif /* Give default value if not defined */ #ifndef NET_IF_NUM #if CONFIG_CONCURRENT_MODE #define NET_IF_NUM 2 #else #define NET_IF_NUM 1 #endif #endif /*Static IP ADDRESS*/ #ifndef IP_ADDR0 #define IP_ADDR0 192 #define IP_ADDR1 168 #define IP_ADDR2 1 #define IP_ADDR3 80 #endif /*NETMASK*/ #ifndef NETMASK_ADDR0 #define NETMASK_ADDR0 255 #define NETMASK_ADDR1 255 #define NETMASK_ADDR2 255 #define NETMASK_ADDR3 0 #endif /*Gateway Address*/ #ifndef GW_ADDR0 #define GW_ADDR0 192 #define GW_ADDR1 168 #define GW_ADDR2 1 #define GW_ADDR3 1 #endif /*Static IP ADDRESS*/ #ifndef AP_IP_ADDR0 #define AP_IP_ADDR0 192 #define AP_IP_ADDR1 168 #define AP_IP_ADDR2 43 #define AP_IP_ADDR3 1 #endif /*NETMASK*/ #ifndef AP_NETMASK_ADDR0 #define AP_NETMASK_ADDR0 255 #define AP_NETMASK_ADDR1 255 #define AP_NETMASK_ADDR2 255 #define AP_NETMASK_ADDR3 0 #endif /*Gateway Address*/ #ifndef AP_GW_ADDR0 #define AP_GW_ADDR0 192 #define AP_GW_ADDR1 168 #define AP_GW_ADDR2 43 #define AP_GW_ADDR3 1 #endif static void cmd_help(int argc, char **argv); #if CONFIG_SSL_CLIENT extern void cmd_ssl_client(int argc, char **argv); #endif #if CONFIG_GOOGLENEST extern void cmd_googlenest(int argc, char **argv); #endif #if CONFIG_BSD_TCP extern void cmd_tcp(int argc, char **argv); extern void cmd_udp(int argc, char **argv); #endif #if CONFIG_WLAN static void cmd_wifi_on(int argc, char **argv); static void cmd_wifi_off(int argc, char **argv); static void cmd_wifi_disconnect(int argc, char **argv); extern void cmd_promisc(int argc, char **argv); extern void cmd_simple_config(int argc, char **argv); #if CONFIG_OTA_UPDATE extern void cmd_update(int argc, char **argv); #endif #if CONFIG_WEBSERVER extern void start_web_server(void); extern void stop_web_server(void); #endif extern void cmd_app(int argc, char **argv); #if CONFIG_ENABLE_WPS extern void cmd_wps(int argc, char **argv); #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); #endif //CONFIG_ENABLE_WPS_AP #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_wifi_p2p_auto_go_start(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); #endif //CONFIG_ENABLE_P2P #if defined(CONFIG_RTL8195A) || defined(CONFIG_RTL8711B) || defined(CONFIG_RTL8721D) extern u32 CmdDumpWord(IN u16 argc, IN u8 *argv[]); extern u32 CmdWriteWord(IN u16 argc, IN u8 *argv[]); #endif #if CONFIG_LWIP_LAYER extern struct netif xnetif[NET_IF_NUM]; #endif #if CONFIG_CONCURRENT_MODE static void cmd_wifi_sta_and_ap(int argc, char **argv) { int timeout = 20;//, mode; #if CONFIG_LWIP_LAYER #if !defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) struct netif * pnetiff = (struct netif *)&xnetif[1]; #endif #endif int channel; if((argc != 3) && (argc != 4)) { pr_info("Usage: wifi_ap SSID CHANNEL [PASSWORD]"); return; } if(atoi((const char *)argv[2]) > 14){ pr_info("bad channel!Usage: wifi_ap SSID CHANNEL [PASSWORD]"); return; } if(strlen((const char *)argv[1]) > 32){ pr_info("Usage: wifi_ap SSID length can't exceed 32\n\r"); return; } #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else dhcps_deinit(); #endif #endif #if 0 //Check mode wext_get_mode(WLAN0_NAME, &mode); switch(mode) { case IW_MODE_MASTER: //In AP mode cmd_wifi_off(0, NULL); cmd_wifi_on(0, NULL); break; case IW_MODE_INFRA: //In STA mode if(wext_get_ssid(WLAN0_NAME, ssid) > 0) cmd_wifi_disconnect(0, NULL); } #endif wifi_off(); rtw_mdelay_os(20); if (wifi_on(RTW_MODE_STA_AP) < 0){ pr_info("ERROR: Wifi on failed!"); return; } pr_info("Starting AP ..."); channel = atoi((const char *)argv[2]); if(channel > 13){ pr_info("Channel is from 1 to 13. Set channel 1 as default!\n"); channel = 1; } if(argc == 4) { if(wifi_start_ap(argv[1], RTW_SECURITY_WPA2_AES_PSK, argv[3], strlen((const char *)argv[1]), strlen((const char *)argv[3]), channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } else { if(wifi_start_ap(argv[1], RTW_SECURITY_OPEN, NULL, strlen((const char *)argv[1]), 0, channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } while(1) { char essid[33]; if(wext_get_ssid(WLAN1_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)argv[1]) == 0) { pr_info("%s started", argv[1]); break; } } if(timeout == 0) { pr_info("ERROR: Start AP timeout!"); break; } rtw_mdelay_os(1000); timeout --; } #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else LwIP_UseStaticIP(&xnetif[1]); dhcps_init(pnetiff); #endif #endif } #endif static void cmd_wifi_ap(int argc, char **argv) { int timeout = 20; #if CONFIG_LWIP_LAYER #if !defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) struct ip_addr ipaddr; struct ip_addr netmask; struct ip_addr gw; struct netif * pnetif = &xnetif[0]; #endif #endif int channel; #if CONFIG_IEEE80211W if((argc != 3) && (argc != 4) && (argc != 5)) { pr_info("Usage: wifi_ap SSID CHANNEL [PASSWORD] [MFP_SUPPORT]"); return; } #else if((argc != 3) && (argc != 4)) { pr_info("Usage: wifi_ap SSID CHANNEL [PASSWORD]"); return; } #endif if(strlen((const char *)argv[1]) > 32){ pr_info("Usage: wifi_ap SSID length can't exceed 32\n\r"); return; } #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else dhcps_deinit(); #if LWIP_VERSION_MAJOR >= 2 IP4_ADDR(ip_2_ip4(&ipaddr), GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(ip_2_ip4(&netmask), NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(ip_2_ip4(&gw), GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(pnetif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask),ip_2_ip4(&gw)); #else IP4_ADDR(&ipaddr, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3); IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3); netif_set_addr(pnetif, &ipaddr, &netmask,&gw); #endif #endif #endif #if 0 //Check mode wext_get_mode(WLAN0_NAME, &mode); switch(mode) { case IW_MODE_MASTER: //In AP mode wifi_off(); wifi_on(1); break; case IW_MODE_INFRA: //In STA mode if(wext_get_ssid(WLAN0_NAME, ssid) > 0) cmd_wifi_disconnect(0, NULL); } #else wifi_off(); rtw_mdelay_os(20); if (wifi_on(RTW_MODE_AP) < 0){ pr_info("ERROR: Wifi on failed!"); return; } #endif pr_info("Starting AP ..."); channel = atoi((const char *)argv[2]); pr_info("Set Channel is %d\n", channel); #if NOT_SUPPORT_5G if(channel > 13){ pr_info("Channel is from 1 to 13. Set channel 1 as default!\n"); channel = 1; } #endif #if defined(CONFIG_ENABLE_WPS_AP) && CONFIG_ENABLE_WPS_AP wpas_wps_dev_config(pnetif->hwaddr, 1); #endif if(argc == 4) { if(wifi_start_ap(argv[1], RTW_SECURITY_WPA2_AES_PSK, argv[3], strlen((const char *)argv[1]), strlen((const char *)argv[3]), channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } #if CONFIG_IEEE80211W else if(argc == 5) { rtw_security_t alg = RTW_SECURITY_WPA2_AES_CMAC; u8 mfp = atoi((const char *)argv[4]); if (mfp == 0 || mfp > 2) {// not support alg = RTW_SECURITY_WPA2_AES_PSK; mfp = 0; } wifi_set_mfp_support(mfp); if (wifi_start_ap(argv[1], alg, argv[3], strlen((const char *)argv[1]), strlen((const char *)argv[3]), channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } #endif else { if(wifi_start_ap(argv[1], RTW_SECURITY_OPEN, NULL, strlen((const char *)argv[1]), 0, channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } while(1) { char essid[33]; if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)argv[1]) == 0) { pr_info("%s started\n", argv[1]); break; } } if(timeout == 0) { pr_info("ERROR: Start AP timeout!"); break; } rtw_mdelay_os(1000); timeout --; } #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else //LwIP_UseStaticIP(pnetif); dhcps_init(pnetif); #endif #endif } static void cmd_wifi_connect(int argc, char **argv) { int ret = RTW_ERROR; unsigned long tick1 = rt_tick_get(); unsigned long tick2, tick3; int mode; char *ssid; rtw_security_t security_type; char *password; int ssid_len; int password_len; int key_id; void *semaphore; if((argc != 2) && (argc != 3) && (argc != 4)) { pr_info("Usage: wifi_connect SSID [WPA PASSWORD / (5 or 13) ASCII WEP KEY] [WEP KEY ID 0/1/2/3]"); return; } //Check if in AP mode wext_get_mode(WLAN0_NAME, &mode); if(mode == IW_MODE_MASTER) { #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else dhcps_deinit(); #endif #endif wifi_off(); rt_thread_delay(20); if (wifi_on(RTW_MODE_STA) < 0){ pr_info("ERROR: Wifi on failed!"); return; } } ssid = argv[1]; if(argc == 2){ security_type = RTW_SECURITY_OPEN; password = NULL; ssid_len = strlen((const char *)argv[1]); password_len = 0; key_id = 0; semaphore = NULL; }else if(argc ==3){ security_type = RTW_SECURITY_WPA2_AES_PSK; password = argv[2]; ssid_len = strlen((const char *)argv[1]); password_len = strlen((const char *)argv[2]); key_id = 0; semaphore = NULL; }else{ security_type = RTW_SECURITY_WEP_PSK; password = argv[2]; ssid_len = strlen((const char *)argv[1]); password_len = strlen((const char *)argv[2]); key_id = atoi(argv[3]); if(( password_len != 5) && (password_len != 13)&&( password_len != 10) && (password_len != 26)) { pr_info("Wrong WEP key length. Must be 5 or 13 ASCII characters or 10 or 26 hex."); return; } if((key_id < 0) || (key_id > 3)) { pr_info("Wrong WEP key id. Must be one of 0,1,2, or 3."); return; } semaphore = NULL; } ret = wifi_connect(ssid, security_type, password, ssid_len, password_len, key_id, semaphore); if(ret != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } else { tick2 = rt_tick_get(); pr_info("Connected after %dms.\n", (tick2-tick1)); #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else /* Start DHCPClient */ LwIP_DHCP(0, DHCP_START); #endif #endif } tick3 = rt_tick_get(); pr_info("Got IP after %dms.\n", (tick3-tick1)); } static void cmd_wifi_connect_bssid(int argc, char **argv) { int ret = RTW_ERROR; unsigned long tick1 = rt_tick_get(); unsigned long tick2, tick3; int mode; unsigned char bssid[ETH_ALEN]; char *ssid = NULL; rtw_security_t security_type; char *password; int bssid_len; int ssid_len = 0; int password_len; int key_id; void *semaphore; u32 mac[ETH_ALEN]; u32 i; u32 index = 0; if((argc != 3) && (argc != 4) && (argc != 5) && (argc != 6)) { pr_info("Usage: wifi_connect_bssid 0/1 [SSID] BSSID / xx:xx:xx:xx:xx:xx [WPA PASSWORD / (5 or 13) ASCII WEP KEY] [WEP KEY ID 0/1/2/3]"); return; } //Check if in AP mode wext_get_mode(WLAN0_NAME, &mode); if(mode == IW_MODE_MASTER) { #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else dhcps_deinit(); #endif #endif wifi_off(); rt_thread_delay(20); if (wifi_on(RTW_MODE_STA) < 0){ pr_info("ERROR: Wifi on failed!"); return; } } //check ssid if(memcmp(argv[1], "0", 1)){ index = 1; ssid_len = strlen((const char *)argv[2]); if((ssid_len <= 0) || (ssid_len > 32)) { pr_info("Wrong ssid. Length must be less than 32."); return; } ssid = argv[2]; } sscanf(argv[2 + index], MAC_FMT, mac, mac + 1, mac + 2, mac + 3, mac + 4, mac + 5); for(i=0; i 3)) { pr_info("Wrong WEP key id. Must be one of 0,1,2, or 3."); return; } semaphore = NULL; } ret = wifi_connect_bssid(bssid, ssid, security_type, password, bssid_len, ssid_len, password_len, key_id, semaphore); if(ret != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } else { tick2 = rt_tick_get(); pr_info("Connected after %dms.\n", (tick2-tick1)); #if CONFIG_LWIP_LAYER #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO #else /* Start DHCPClient */ LwIP_DHCP(0, DHCP_START); #endif #endif } tick3 = rt_tick_get(); pr_info("Got IP after %dms.\n", (tick3-tick1)); } static void cmd_wifi_disconnect(int argc, char **argv) { int timeout = 20; char essid[33]; pr_info("Deassociating AP ..."); if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { pr_info("WIFI disconnected"); return; } if(wifi_disconnect() < 0) { pr_info("ERROR: Operation failed!"); return; } while(1) { if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) < 0) { pr_info("WIFI disconnected"); break; } if(timeout == 0) { pr_info("ERROR: Deassoc timeout!"); break; } rtw_mdelay_os(1000); timeout --; } } extern void dump_drv_version(); static void cmd_wifi_info(int argc, char **argv) { int i = 0; #if CONFIG_LWIP_LAYER #if !defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) u8 *mac = LwIP_GetMAC(&xnetif[0]); u8 *ip = LwIP_GetIP(&xnetif[0]); u8 *gw = LwIP_GetGW(&xnetif[0]); #endif #endif char *ifname[2] = {WLAN0_NAME,WLAN1_NAME}; #ifdef CONFIG_MEM_MONITOR extern int min_free_heap_size; #endif dump_drv_version(); rtw_wifi_setting_t setting; for(i=0;i %02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]) ; pr_info("\tIP => %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); pr_info("\tGW => %d.%d.%d.%d\n\r", gw[0], gw[1], gw[2], gw[3]); #endif #endif if(setting.mode == RTW_MODE_AP || i == 1) { int client_number; struct { int count; rtw_mac_t mac_list[AP_STA_NUM]; } client_info; client_info.count = AP_STA_NUM; wifi_get_associated_client_list(&client_info, sizeof(client_info)); pr_info("Associated Client List:"); pr_info("=============================="); if(client_info.count == 0) pr_info("Client Num: 0\n\r"); else { pr_info("Client Num: %d", client_info.count); for( client_number=0; client_number < client_info.count; client_number++ ) { pr_info("Client [%d]:", client_number); pr_info("\tMAC => "MAC_FMT"", MAC_ARG(client_info.mac_list[client_number].octet)); } pr_info(""); } } { int error = wifi_get_last_error(); pr_info("Last Link Error"); pr_info("=============================="); switch(error) { case RTW_NO_ERROR: pr_info("\tNo Error"); break; case RTW_NONE_NETWORK: pr_info("\tTarget AP Not Found"); break; case RTW_CONNECT_FAIL: pr_info("\tAssociation Failed"); break; case RTW_WRONG_PASSWORD: pr_info("\tWrong Password"); break; case RTW_DHCP_FAIL: pr_info("\tDHCP Failed"); break; default: pr_info("\tUnknown Error(%d)", error); } pr_info(""); } } } #if defined(configUSE_TRACE_FACILITY) && (configUSE_TRACE_FACILITY == 1) { signed char pcWriteBuffer[1024]; vTaskList((char*)pcWriteBuffer); pr_info("Task List: \n%s", pcWriteBuffer); } #endif #ifdef CONFIG_MEM_MONITOR extern u32 rtt_GetFreeHeapSize(void); pr_info("Memory Usage"); pr_info("=============================="); pr_info("Min Free Heap Size: %d", min_free_heap_size); pr_info("Cur Free Heap Size: %d\n", rtt_GetFreeHeapSize()); #endif } static void cmd_wifi_on(int argc, char **argv) { if(wifi_on(RTW_MODE_STA)<0){ pr_info("ERROR: Wifi on failed!\n"); } } static void cmd_wifi_off(int argc, char **argv) { #if CONFIG_WEBSERVER stop_web_server(); #endif #if CONFIG_ENABLE_P2P cmd_wifi_p2p_stop(0, NULL); #else wifi_off(); #endif } static void print_scan_result( rtw_scan_result_t* record ) { printf( "%s\t ", ( record->bss_type == RTW_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ); printf( MAC_FMT, MAC_ARG(record->BSSID.octet) ); printf( " %d\t ", record->signal_strength ); printf( " %d\t ", record->channel ); printf( " %ld\t ", record->wps_type ); printf( "%s\t\t ", ( record->security == RTW_SECURITY_OPEN ) ? "Open" : ( record->security == RTW_SECURITY_WEP_PSK ) ? "WEP" : ( record->security == RTW_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP PSK" : ( record->security == RTW_SECURITY_WPA_TKIP_8021X ) ? "WPA TKIP 8021X" : ( record->security == RTW_SECURITY_WPA_AES_PSK ) ? "WPA AES PSK" : ( record->security == RTW_SECURITY_WPA_AES_8021X ) ? "WPA AES 8021X" : ( record->security == RTW_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES PSK" : ( record->security == RTW_SECURITY_WPA2_AES_8021X ) ? "WPA2 AES 8021X" : ( record->security == RTW_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP PSK" : ( record->security == RTW_SECURITY_WPA2_TKIP_8021X ) ? "WPA2 TKIP 8021X" : ( record->security == RTW_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed PSK" : ( record->security == RTW_SECURITY_WPA_WPA2_MIXED_PSK ) ? "WPA/WPA2 PSK" : ( record->security == RTW_SECURITY_WPA_WPA2_MIXED_8021X ) ? "WPA/WPA2 8021X" : #if CONFIG_SAE_SUPPORT ( record->security == RTW_SECURITY_WPA3_AES_PSK) ? "WP3-SAE AES" : #endif "Unknown" ); printf( " %s \n", record->SSID.val ); } static rtw_result_t app_scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result ) { static int ApNum = 0; 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 */ printf( "\r\n%d\t ", ++ApNum ); print_scan_result(record); } else{ ApNum = 0; } return RTW_SUCCESS; } #if SCAN_WITH_SSID static void cmd_wifi_scan_with_multiple_ssid(int argc,char **argv) { int num_ssid,scan_buflen,i; scan_ssid Ssid[3]; if(argc < 2||argc>4){ pr_info("For Scan all channel Usage: wifi_scan_with_multissid ssid... (num<=3!)"); return ; } for(i = 1;i 32)) { pr_info("Wrong ssid. Length must be less than 32."); goto exit; } scan_buf_len = atoi(argv[2]); if(scan_buf_len < 36){ pr_info("BUFFER_LENGTH too short\n\r"); goto exit; } }else if(argc > 3){ int i = 0; int num_channel = atoi(argv[2]); ssid = argv[1]; ssid_len = strlen((const char *)argv[1]); if((ssid_len <= 0) || (ssid_len > 32)) { pr_info("Wrong ssid. Length must be less than 32."); goto exit; } channel_list = (u8*)rt_malloc(num_channel); if(!channel_list){ pr_info("ERROR: Can't malloc memory for channel list"); goto exit; } pscan_config = (u8*)rt_malloc(num_channel); if(!pscan_config){ pr_info("ERROR: Can't malloc memory for pscan_config"); goto exit; } //parse command channel list for(i = 3; i <= argc -1 ; i++){ *(channel_list + i - 3) = (u8)atoi(argv[i]); *(pscan_config + i - 3) = PSCAN_ENABLE; } if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){ pr_info("ERROR: wifi set partial scan channel fail"); goto exit; } } else { pr_info("For Scan all channel Usage: wifi_scan_with_ssid ssid BUFFER_LENGTH"); pr_info("For Scan partial channel Usage: wifi_scan_with_ssid ssid num_channels channel_num1 ..."); return; } if(wifi_scan_networks_with_ssid(NULL, NULL, scan_buf_len, ssid, ssid_len) != RTW_SUCCESS){ pr_info("ERROR: wifi scan failed"); goto exit; } exit: if(argc > 2 && channel_list) rt_free(channel_list); if(argc > 2 && pscan_config) rt_free(pscan_config); } #endif void cmd_wifi_scan(int argc, char **argv) { u8 *channel_list = NULL; u8 *pscan_config = NULL; if(argc > 2){ int i = 0; int num_channel = atoi(argv[1]); channel_list = (u8*)rt_malloc(num_channel); if(!channel_list){ pr_info("ERROR: Can't malloc memory for channel list"); goto exit; } pscan_config = (u8*)rt_malloc(num_channel); if(!pscan_config){ pr_info("ERROR: Can't malloc memory for pscan_config"); goto exit; } //parse command channel list for(i = 2; i <= argc -1 ; i++){ *(channel_list + i - 2) = (u8)atoi(argv[i]); *(pscan_config + i - 2) = PSCAN_ENABLE; } if(wifi_set_pscan_chan(channel_list, pscan_config, num_channel) < 0){ pr_info("ERROR: wifi set partial scan channel fail"); goto exit; } } if(wifi_scan_networks(app_scan_result_handler, NULL ) != RTW_SUCCESS){ pr_info("ERROR: wifi scan failed"); goto exit; } exit: if(argc > 2 && channel_list) rt_free(channel_list); if(argc > 2 && pscan_config) rt_free(pscan_config); } extern int wifi_set_scan_reorderchan(__u8 * channel_list, __u8 length); void cmd_wifi_reorder_scan(int argc, char **argv) { u8 *channel_list = NULL; int i = 0; int num_channel = 13; char channel_reorder[]= {1,3,5,7,9,2,4,6,8,10,11,12,13};//set channel order channel_list = (u8*)rt_malloc(num_channel); if(!channel_list){ pr_info("ERROR: Can't malloc memory for channel_list"); goto exit; } for(i=0;i 32){ pr_info("Usage: wifi_ap SSID length can't exceed 32\n\r"); return; } pr_info("Resume AP ...\n"); channel = atoi((const char *)argv[2]); pr_info("Set Channel is %d\n", channel); #if NOT_SUPPORT_5G if(channel > 13){ pr_info("Channel is from 1 to 13. Set channel 1 as default!\n"); channel = 1; } #endif if(argc == 4) { if(wifi_start_ap(argv[1], RTW_SECURITY_WPA2_AES_PSK, argv[3], strlen((const char *)argv[1]), strlen((const char *)argv[3]), channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } else { if(wifi_start_ap(argv[1], RTW_SECURITY_OPEN, NULL, strlen((const char *)argv[1]), 0, channel ) != RTW_SUCCESS) { pr_info("ERROR: Operation failed!"); return; } } while(1) { char essid[33]; if(wext_get_ssid(WLAN0_NAME, (unsigned char *) essid) > 0) { if(strcmp((const char *) essid, (const char *)argv[1]) == 0) { pr_info("%s Restarted\n", argv[1]); break; } } if(timeout == 0) { pr_info("ERROR: Resume AP timeout!"); break; } rtw_mdelay_os(1000); timeout --; } } #endif static void cmd_get_auto_chl(int argc, char **argv) { unsigned char channel_set[7]; int auto_chl = 0; channel_set[0] = 36; channel_set[1] = 52; channel_set[2] = 40; channel_set[3] = 44; channel_set[4] = 56; channel_set[5] = 48; channel_set[6] = 153; //channel_set[7] = 56; auto_chl = wext_get_auto_chl("wlan0", channel_set, sizeof(channel_set)/sizeof(channel_set[0])); pr_info("auto_chl = %d!",auto_chl); } #ifdef CONFIG_CMW500_TEST static void cmd_testcmw500_enable(int argc, char **argv) { int i = 0; u8 fix_rate = 0; u8 txpower = 0; u8 pwrtrack_en = 2;//default open, 0:disable 1:enable pr_info("start test for CMW500!\r\n"); if((1 != argc)&&(3 != argc)&&(5 != argc)&&(7 != argc)) { pr_info("Usage: open_test_cmw500 -r fixrate -t txpower -p pwrtrack_en[0/1]\r\n"); return; } for(i=1;i #endif static void cmd_help(int argc, char **argv) { int i; pr_info("COMMAND LIST:"); pr_info("=============================="); for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) pr_info(" %s", cmd_table[i].command); #if CONFIG_INTERACTIVE_EXT for(i = 0; i < sizeof(ext_cmd_table) / sizeof(ext_cmd_table[0]); i ++) pr_info(" %s", ext_cmd_table[i].command); #endif } #define MAX_ARGC 10 #if !defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) static int parse_cmd(char *buf, char **argv) { int argc = 0; memset(argv, 0, sizeof(argv)*MAX_ARGC); while((argc < MAX_ARGC) && (*buf != '\0')) { argv[argc] = buf; argc ++; buf ++; while((*buf != ' ') && (*buf != '\0')) buf ++; while(*buf == ' ') { *buf = '\0'; buf ++; } // Don't replace space if(argc == 1){ if(strcmp(argv[0], "iwpriv") == 0){ if(*buf != '\0'){ argv[1] = buf; argc ++; } break; } } } return argc; } #endif char uart_buf[100]; void interactive_mode(void *param) { __attribute__ ((unused)) int i, argc; __attribute__ ((unused)) char *argv[MAX_ARGC]; __attribute__ ((unused)) char temp_uart_buf[100]; #if defined(CONFIG_PLATFOMR_CUSTOMER_RTOS) //TODO //Get content from uart #else extern xSemaphoreHandle uart_rx_interrupt_sema; pr_info("Enter INTERACTIVE MODE\n\r"); pr_info("# "); while(1){ while(rtw_down_sema((_sema *)&uart_rx_interrupt_sema) != _TRUE); rtw_memcpy(temp_uart_buf,uart_buf,100); if((argc = parse_cmd(temp_uart_buf, argv)) > 0) { int found = 0; for(i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i ++) { if(strcmp((const char *)argv[0], (const char *)(cmd_table[i].command)) == 0) { cmd_table[i].function(argc, argv); found = 1; break; } } #if CONFIG_INTERACTIVE_EXT if(!found) { for(i = 0; i < sizeof(ext_cmd_table) / sizeof(ext_cmd_table[0]); i ++) { if(strcmp(argv[0], ext_cmd_table[i].command) == 0) { ext_cmd_table[i].function(argc, argv); found = 1; break; } } } #endif if(!found) pr_info("unknown command '%s'", argv[0]); pr_info("[MEM] After do cmd, available heap %d\n\r", xPortGetFreeHeapSize()); } pr_info("\r\n\n# "); uart_buf[0] = '\0'; temp_uart_buf[0] = '\0'; } #endif } void start_interactive_mode(void) { #ifdef SERIAL_DEBUG_RX struct task_struct interactive_mode_task; interactive_mode_task.task = NULL; //if(xTaskCreate(interactive_mode, (char const *)"interactive_mode", STACKSIZE, NULL, tskIDLE_PRIORITY + 4, NULL) != pdPASS) if(rtw_create_task(&interactive_mode_task, (char const *)"interactive_mode", STACKSIZE, tskIDLE_PRIORITY + 5, interactive_mode, NULL) != pdPASS) pr_info("%s xTaskCreate failed", __FUNCTION__); #else pr_info("ERROR: No SERIAL_DEBUG_RX to support interactive mode!"); #endif } #include void wlan(int argc, char **argv) { int i = 0; for (i = 0; i < sizeof(cmd_table) / sizeof(cmd_table[0]); i++) { if (!strcmp(cmd_table[i].command, argv[1])) { cmd_table[i].function(argc-1, &argv[1]); break; } } } MSH_CMD_EXPORT(wlan, wlan "wifi_cmd" [para]);