171 lines
4.4 KiB
C
171 lines
4.4 KiB
C
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include "command/command.h"
|
|
#include "wm_include.h"
|
|
#include "FreeRTOS.h"
|
|
#include "task.h"
|
|
|
|
extern int shell_printf(const char *format, ...);
|
|
extern int wm_printf(const char *fmt,...);
|
|
|
|
void tls_wifi_client_event_cb(u8 *mac, enum tls_wifi_client_event_type event)
|
|
{
|
|
struct tls_sta_info_t *mac_addr = (struct tls_sta_info_t *)mac;
|
|
|
|
shell_printf("Client event(%d), MAC : %M\n", event, mac_addr);
|
|
}
|
|
|
|
void wifi_scan_result_cb(void)
|
|
{
|
|
u16 buffer_size = sizeof(struct tls_scan_bss_t) + sizeof(struct tls_bss_info_t) * 10;
|
|
u8 *buf = tls_mem_alloc(buffer_size);
|
|
if(buf == NULL)
|
|
{
|
|
shell_printf("Failed to allocate result buffer\n");
|
|
return;
|
|
}
|
|
struct tls_scan_bss_t *scan_result = (struct tls_scan_bss_t *)buf;
|
|
struct tls_bss_info_t *station_list = scan_result->bss;
|
|
|
|
tls_wifi_get_scan_rslt(buf, buffer_size);
|
|
shell_printf("Found %u nearby station(s) - info size(%u/%u)\n",
|
|
scan_result->count,
|
|
scan_result->length,
|
|
buffer_size);
|
|
|
|
for(u8 i = 0; i < scan_result->count; i++)
|
|
{
|
|
station_list[i].ssid[station_list[i].ssid_len] = '\0';
|
|
shell_printf("station %u :\nSSID : %s\n", i, (char *)station_list[i].ssid);
|
|
}
|
|
|
|
tls_mem_free(buf);
|
|
}
|
|
|
|
int _task_list(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
char *buf = NULL;
|
|
|
|
buf = tls_mem_alloc(1024);
|
|
if(NULL == buf)
|
|
return 0;
|
|
#if configUSE_TRACE_FACILITY
|
|
vTaskList((signed char *)buf);
|
|
#endif
|
|
shell_printf("\n%s\nbuf_len : %d\n", buf, strlen(buf));
|
|
tls_mem_free(buf);
|
|
buf = NULL;
|
|
return 0;
|
|
}
|
|
|
|
int _reset(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
tls_sys_reset();
|
|
return 0;
|
|
}
|
|
|
|
int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "state") == 0)
|
|
{
|
|
shell_printf("SOFT AP state : %u\n", tls_wifi_softap_get_state());
|
|
}
|
|
else if(strcmp(argv[1], "create") == 0)
|
|
{
|
|
struct tls_softap_info_t ap_info;
|
|
struct tls_ip_info_t ip_info;
|
|
|
|
tls_wifi_disconnect();
|
|
|
|
strncpy((char *)ap_info.ssid, argv[2], 32);
|
|
ap_info.ssid[32] = '\0';
|
|
ap_info.encrypt = IEEE80211_ENCRYT_TKIP_WPA2;
|
|
ap_info.channel = 5;
|
|
|
|
ap_info.keyinfo.format = 1;
|
|
ap_info.keyinfo.index = 1;
|
|
ap_info.keyinfo.key_len = strlen(argv[3]);
|
|
strncpy((char *)ap_info.keyinfo.key, argv[3], 63);
|
|
|
|
ip_info.ip_addr[0] = 192;
|
|
ip_info.ip_addr[1] = 168;
|
|
ip_info.ip_addr[2] = 1;
|
|
ip_info.ip_addr[3] = 1;
|
|
ip_info.netmask[0] = 255;
|
|
ip_info.netmask[1] = 255;
|
|
ip_info.netmask[2] = 255;
|
|
ip_info.netmask[3] = 0;
|
|
ip_info.dnsname[0] = '\0';
|
|
|
|
int result = tls_wifi_softap_create(&ap_info, &ip_info);
|
|
shell_printf("Create AP with SSID : %s, key(%d) : %s -> %d\n", ap_info.ssid, ap_info.keyinfo.key_len, ap_info.keyinfo.key, result);
|
|
|
|
shell_printf("Registering client event callback\n");
|
|
tls_wifi_softap_client_event_register(&(tls_wifi_client_event_cb));
|
|
}
|
|
else if(strcmp(argv[1], "destroy") == 0)
|
|
{
|
|
tls_wifi_softap_destroy();
|
|
shell_printf("Stopping SOFT AP\n");
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown soft_ap action\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of soft_ap actions :\nstate\ncreate <SSID> <PWD>\ndestroy\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
int _station(const shell_cmd_t *pcmd, int argc, char *const argv[])
|
|
{
|
|
if(argc > 1)
|
|
{
|
|
if(strcmp(argv[1], "scan") == 0)
|
|
{
|
|
tls_wifi_scan_result_cb_register(&(wifi_scan_result_cb));
|
|
|
|
if(tls_wifi_scan() == WM_SUCCESS)
|
|
{
|
|
shell_printf("Scanning nearby stations...\n");
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Failed to start wifi scan\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("Unknown station action\n");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
shell_printf("List of station actions :\nscan\n");
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
|
|
NANO_SHELL_ADD_CMD(task_list,
|
|
_task_list,
|
|
"List all tasks",
|
|
" Use this command to list all defined tasks\r\n");
|
|
NANO_SHELL_ADD_CMD(reset,
|
|
_reset,
|
|
"Reset the system",
|
|
" Use this command reset the system\r\n");
|
|
NANO_SHELL_ADD_CMD(soft_ap,
|
|
_soft_ap,
|
|
"Command to control SOFT AP",
|
|
" Use this command to control the SOFT AP subsystem\r\n");
|
|
NANO_SHELL_ADD_CMD(station,
|
|
_station,
|
|
"Command to control STATION mode",
|
|
" Use this command to connect to a WiFi access point\r\n");
|