blob: b8f5189c2134b5106e5c3b4712da2ce34b31c20c [file] [log] [blame]
#include "sta_cli.h"
#include "lynq_wifi.h"
#include <stdio.h>
#include <stdlib.h>
#define MAX_LEN 15
#define MAX_VALUE_LEN 512
#define ENABLE "enable"
#define DISABLE "disable"
#define MODE_SET "mode_set"
#define MODE_GET "mode_get"
#define AP_GET_STATUS "ap_get_status"
#define AP_ACL_SET "ap_acl_set"
#define AP_ACL_GET "ap_acl_get"
#define AP_SSID_SET "ap_ssid_set"
#define AP_SSID_GET "ap_ssid_get"
#define AP_SSID_HIDE_SET "ap_ssid_hide_set"
#define AP_SSID_HIDE_GET "ap_ssid_hide_get"
#define AP_MODE_SET "ap_mode_set"
#define AP_MODE_GET "ap_mode_get"
#define AP_BAND_SET "ap_band_set"
#define AP_BAND_GET "ap_band_get"
#define AP_CHANNEL_SET "ap_channel_set"
#define AP_CHANNEL_GET "ap_channel_get"
#define AP_AUTH_SET "ap_auth_set"
#define AP_AUTH_GET "ap_auth_get"
#define AP_auth_GET_S "ap_auth_get_s"
#define AP_MAX_STA_SET "ap_max_sta_set"
#define AP_MAX_STA_GET "ap_max_sta_get"
#define AP_LIST_GET "list_get"
#define AP_PKT_GET "ap_pkt_get"
#define AP_START "ap_start"
#define AP_STOP "ap_stop"
#define AP_RESTART "ap_restart"
#define AP_REG_HANDLE "reg_handle"
#define STA_PARAM_SET "sta_param_set"
#define STA_PARAM_GET "sta_param_get"
#define STA_START "sta_start"
#define STA_STOP "sta_stop"
#define STA_STATUS_GET "sta_status_get"
#define STA_PKT_GET "sta_pkt_get"
#define STA_SCAN "sta_scan"
void lynq_wifi_event_handle_sta_demo(lynq_wifi_sta_scan_list_t *event)
{
int i = 0;
for (i = 0; i < event->cnt; i++)
{
printf("[lynq-wifi-demo] %s : ap[%d]:%s,%d,%d,%d,%s,%d,%d,%d\n", __func__, i,
event->info[i].essid, event->info[i].auth,
event->info[i].cipher, event->info[i].channel, event->info[i].bssid,
event->info[i].signal_level,event->info[i].frequency,event->info[i].signal);
}
}
static void help()
{
printf("please read the define \n");
}
int main(int argc, char *argv[])
{
int test_int = 0;
char value[MAX_VALUE_LEN] = {0};
lynq_wifi_ap_auth_t auth_mode = {0};
lynq_lanhost_ts lanhost = {0};
lynq_wifi_pkt_stats_t pkt_stat = {0};
lynq_wifi_sta_param_t sta_param = {0};
lynq_wifi_sta_status_t sta_status = {0};
printf(">>>>>>>>>>>>>>>>>>>>>>>>Enter cmd:\n");
char cmd[MAX_VALUE_LEN];
while(1)
{
memset(cmd, 0, MAX_VALUE_LEN);
test_int = 0;
memset(value, 0, MAX_VALUE_LEN);
memset(&auth_mode, 0, sizeof(lynq_wifi_ap_auth_t));
memset(&lanhost, 0, sizeof(lynq_lanhost_ts));
memset(&pkt_stat, 0, sizeof(lynq_wifi_pkt_stats_t));
memset(&sta_param, 0, sizeof(lynq_wifi_sta_param_t));
memset(&sta_status, 0, sizeof(lynq_wifi_sta_status_t));
if(fgets(cmd, MAX_VALUE_LEN, stdin))
{
char *ptr = cmd + strlen(cmd) - 1;
while(ptr >= cmd && (*ptr == '\r' || *ptr == '\n'))
{
*ptr-- = '\0';
}
if(!strncasecmp(cmd, ENABLE, strlen(ENABLE)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_enable())
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, DISABLE, strlen(DISABLE)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_disable())
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, MODE_SET, strlen(MODE_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_work_mode_set(LYNQ_WIFI_WORK_MODE_AP0))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, MODE_GET, strlen(MODE_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_work_mode_get(&test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("mode:%d\n",test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_ACL_SET, strlen(AP_ACL_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_acl_set(LYNQ_WIFI_AP_INDEX_AP1,
LYNQ_WIFI_MAC_ACL_RULE_WHITE_LIST, "AA:BB:CC:DD:EE:01;AA:BB:CC:01:EE:00;AA:BB:01:DD:EE:00"))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_ACL_GET, strlen(AP_ACL_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_acl_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int, value))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%s\n",value);
printf("mode:%d\n",test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_SSID_SET, strlen(AP_SSID_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_set(LYNQ_WIFI_AP_INDEX_AP1, "testssid"))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_SSID_GET, strlen(AP_SSID_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_get(LYNQ_WIFI_AP_INDEX_AP1, value))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%s\n",value);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_SSID_HIDE_SET, strlen(AP_SSID_HIDE_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_hide_set(LYNQ_WIFI_AP_INDEX_AP1, 1))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_SSID_HIDE_GET, strlen(AP_SSID_HIDE_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_ssid_hide_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%d\n", test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_MODE_SET, strlen(AP_MODE_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_mode_set(LYNQ_WIFI_AP_INDEX_AP1, 1))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_MODE_GET, strlen(AP_MODE_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_mode_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%d\n", test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_BAND_SET, strlen(AP_BAND_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_bandwidth_set(LYNQ_WIFI_AP_INDEX_AP1, 2))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_BAND_GET, strlen(AP_BAND_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_bandwidth_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%d\n", test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_CHANNEL_SET, strlen(AP_CHANNEL_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_channel_set(LYNQ_WIFI_AP_INDEX_AP1, "CN", 35))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_CHANNEL_GET, strlen(AP_CHANNEL_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_channel_get(LYNQ_WIFI_AP_INDEX_AP1, value, &test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("country:%s, channel:%d\n", value, test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_AUTH_SET, strlen(AP_AUTH_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_set(LYNQ_WIFI_AP_INDEX_AP1, 1, "123456"))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_AUTH_GET, strlen(AP_AUTH_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int, value))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("value:%s\n", value);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_auth_GET_S, strlen(AP_auth_GET_S)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_auth_get_s(LYNQ_WIFI_AP_INDEX_AP1, &auth_mode))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("auth_mode:%s\n", auth_mode.passwd);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_MAX_STA_SET, strlen(AP_MAX_STA_SET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_max_sta_set(LYNQ_WIFI_AP_INDEX_AP1, 8))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_MAX_STA_GET, strlen(AP_MAX_STA_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_max_sta_get(LYNQ_WIFI_AP_INDEX_AP1, &test_int))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("max_sta:%d\n",test_int);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_LIST_GET, strlen(AP_LIST_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_lanhost_get_list(&lanhost))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_PKT_GET, strlen(AP_PKT_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_get_ap_pkt_stats(LYNQ_WIFI_AP_INDEX_AP1, &pkt_stat))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_START, strlen(AP_START)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_start(LYNQ_WIFI_AP_INDEX_AP1))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_STOP, strlen(AP_STOP)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_stop(LYNQ_WIFI_AP_INDEX_AP1))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_RESTART, strlen(AP_RESTART)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_ap_restart(LYNQ_WIFI_AP_INDEX_AP1))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, AP_REG_HANDLE, strlen(AP_REG_HANDLE)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_register_handle(NULL, lynq_wifi_event_handle_sta_demo, NULL))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_PARAM_SET, strlen(STA_PARAM_SET)))
{
strcpy(sta_param.ssid, "test");
strcpy(sta_param.passwd, "123456");
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_param_set(&sta_param))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_PARAM_GET, strlen(STA_PARAM_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_param_get(&sta_param))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("ssid:%s, passwd:%s\n", sta_param.ssid, sta_param.passwd);
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_START, strlen(STA_START)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_start())
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_STOP, strlen(STA_STOP)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_stop())
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_STATUS_GET, strlen(STA_STATUS_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_get_status(&sta_status))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_PKT_GET, strlen(STA_PKT_GET)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_get_sta_pkt_stats(&pkt_stat))
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strncasecmp(cmd, STA_SCAN, strlen(STA_SCAN)))
{
if(LYNQ_ERR_SUCCESS != qser_wifi_sta_start_scan())
{
printf("LYNQ_ERR_FAIL\n");
}
else
{
printf("LYNQ_ERR_SUCCESS\n");
}
}
else if(!strcasecmp(cmd, "h") || !strcasecmp(cmd, "help"))
{
help();
}
else if(!strcasecmp(cmd, "q"))
{
break;
}
else
{
printf("unknown command\n");
}
}
}
return 0;
}