Added a few new commands

This commit is contained in:
Th3maz1ng 2022-06-19 22:59:28 +02:00
parent 16d10ff115
commit 4f3da93a7d
2 changed files with 102 additions and 3 deletions

View File

@ -14,13 +14,57 @@
#include "wm_include.h"
#include "wm_gpio_afsel.h"
#include "nano_shell.h"
#include "lwip/netif.h"
extern s16 uart0_rx_callback(u16 len, void *user_data);
extern s16 uart1_rx_callback(u16 len, void *user_data);
extern int shell_printf(const char *format, ...);
#define NANO_SHELL_TASK_STK_SIZE 1024
#define STATUS_LED WM_IO_PB_18
void tls_netif_status_event_cb(u8 status)
{
struct netif *netif = tls_get_netif();
switch(status)
{
case NETIF_WIFI_JOIN_SUCCESS:
shell_printf("Evt : NETIF_WIFI_JOIN_SUCCESS\n");
break;
case NETIF_WIFI_JOIN_FAILED:
shell_printf("Evt : NETIF_WIFI_JOIN_FAILED\n");
break;
case NETIF_WIFI_DISCONNECTED:
shell_printf("Evt : NETIF_WIFI_DISCONNECTED\n");
break;
case NETIF_IP_NET_UP:
shell_printf("Evt : NETIF_IP_NET_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->ip_addr.addr,
netif->netmask.addr,
netif->gw.addr);
break;
case NETIF_WIFI_SOFTAP_SUCCESS:
shell_printf("Evt : NETIF_WIFI_SOFTAP_SUCCESS\n");
break;
case NETIF_WIFI_SOFTAP_FAILED:
shell_printf("Evt : NETIF_WIFI_SOFTAP_FAILED\n");
break;
case NETIF_WIFI_SOFTAP_CLOSED:
shell_printf("Evt : NETIF_WIFI_SOFTAP_CLOSED\n");
break;
case NETIF_IP_NET2_UP:
shell_printf("Evt : NETIF_IP_NET2_UP\nip addr : %v\nnetmask : %v\ngateway : %v\n", netif->next->ip_addr.addr,
netif->next->netmask.addr,
netif->next->gw.addr);
break;
case NETIF_IPV6_NET_UP:
shell_printf("Evt : NETIF_IPV6_NET_UP\n");
break;
default:
shell_printf("Evt : UNKNOWN\n");
break;
}
}
void user_main(void *param)
{
//We initialize input/output used by the app
@ -54,6 +98,9 @@ void user_main(void *param)
);
}
shell_printf("Registering netif callback.\n");
tls_netif_add_status_event(&(tls_netif_status_event_cb));
for(;;)
{
tls_gpio_write(STATUS_LED, !tls_gpio_read(STATUS_LED));

View File

@ -51,6 +51,17 @@ void wifi_scan_result_cb(void)
tls_mem_free(buf);
}
void tls_wifi_data_ext_recv_cb(u8* data, u32 data_len, struct tls_wifi_ext_t *ext)
{
shell_printf("recv packet :\nrssi : %d\nrate : %u\n", (s8)ext->rssi, ext->rx_rate);
for(u32 i = 0; i < data_len; i++)
{
shell_printf("%02X", data[i]);
if(i % 20 == 0)
shell_printf("\n");
}
}
int _task_list(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
char *buf = NULL;
@ -88,6 +99,9 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
tls_wifi_disconnect();
shell_printf("Registering client event callback\n");
tls_wifi_softap_client_event_register(&(tls_wifi_client_event_cb));
strncpy((char *)ap_info.ssid, argv[2], 32);
ap_info.ssid[32] = '\0';
ap_info.encrypt = IEEE80211_ENCRYT_TKIP_WPA2;
@ -110,9 +124,6 @@ int _soft_ap(const shell_cmd_t *pcmd, int argc, char *const argv[])
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)
{
@ -191,6 +202,43 @@ int _cpu_temp(const shell_cmd_t *pcmd, int argc, char *const argv[])
return 0;
}
int _wifi(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
if(argc > 1)
{
if(strcmp(argv[1], "off") == 0)
{
tls_wifi_softap_destroy();
tls_wifi_disconnect();
shell_printf("set one shot flg : %d\n",tls_wifi_set_oneshot_flag(0));
shell_printf("Stopping WIFI interface\n");
}
else if(strcmp(argv[1], "error") == 0)
{
shell_printf("Error : %s\n", tls_wifi_get_errinfo(tls_wifi_get_errno()));
}
else if(strcmp(argv[1], "promiscuous_on") == 0)
{
shell_printf("WiFi promiscuous on\n");
tls_wifi_data_ext_recv_cb_register(&(tls_wifi_data_ext_recv_cb));
}
else if(strcmp(argv[1], "promiscuous_off") == 0)
{
shell_printf("WiFi promiscuous off\n");
tls_wifi_data_ext_recv_cb_register(NULL);
}
else
{
shell_printf("Unknown wifi action\n");
}
}
else
{
shell_printf("List of wifi actions :\noff\nerror\npromiscuous_on\npromiscuous_off\n");
}
return 0;
}
int _wifi_sleep(const shell_cmd_t *pcmd, int argc, char *const argv[])
{
if(argc > 1)
@ -235,6 +283,10 @@ NANO_SHELL_ADD_CMD(station,
_station,
"Command to control STATION mode",
" Use this command to connect to a WiFi access point\r\n");
NANO_SHELL_ADD_CMD(wifi,
_wifi,
"Command to control WIFI interface",
" Use this command to control the WIFI interface\r\n");
NANO_SHELL_ADD_CMD(cpu_temp,
_cpu_temp,
"Command to read the CPU temperature",