• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 ASR Microelectronics (Shanghai) Co., Ltd. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <math.h>
19 #include <string.h>
20 #include "at_api.h"
21 #ifdef ALIOS_SUPPORT
22 #include "aos/cli.h"
23 #endif
24 #include "lega_wlan_api.h"
25 
26 #ifdef CFG_MRFOTA_TEST
27 uint8_t rfota_wifi_open = 0x0;
28 extern uint8_t rfota_ble_open;
29 extern uint8_t rfota_wifi_test;
30 
lega_at_wlan_start(char * pwbuf,int blen,int argc,char ** argv)31 static void lega_at_wlan_start(char *pwbuf, int blen, int argc, char **argv)
32 {
33     uint8_t i = 0;
34     char *ssid = "CMW-AP";
35     lega_wlan_init_type_t conf = {0};
36     conf.wifi_mode = STA;
37     memset(conf.wifi_key, 0, sizeof(conf.wifi_key));
38 
39     if (rfota_ble_open > 0) {
40         printf("please close ble before wifi test!\n");
41         return;
42     }
43 
44     switch (argc) {
45         case 3:
46             if ((strlen(argv[2]) > 7) && (strlen(argv[2]) <= sizeof(conf.wifi_key))) {
47                 strcpy((char *)conf.wifi_key, (const char *)argv[2]);
48             } else if (strlen(argv[2]) < 8) {
49                 printf("pwr lenth err.");
50             }
51         case 2:
52             if (strlen((char *)argv[1]) > sizeof(conf.wifi_ssid)) {
53                 printf("ssid lenth err.");
54                 return;
55             }
56             strcpy((char *)conf.wifi_ssid, (const char *)argv[1]);
57             break;
58         default:
59             memcpy(conf.wifi_ssid, ssid, sizeof(conf.wifi_ssid));
60             break;
61     }
62 
63     lega_wlan_open(&conf);
64     rfota_wifi_open = 0x2;
65 
66 }
67 #ifdef ALIOS_SUPPORT
68 static struct cli_command rfota_wifi_start = {
69     .name     = "rfota_wifi_start",
70     .help     = "rfota_wifi_start [ssid] <pwd> for sta",
71     .function = lega_at_wlan_start,
72 };
73 #endif
lega_at_wlan_stop(char * pwbuf,int blen,int argc,char ** argv)74 static void lega_at_wlan_stop(char *pwbuf, int blen, int argc, char **argv)
75 {
76     if (rfota_wifi_open == 0) {
77         printf("rfota wifi not open,don't need close.\n");
78         return;
79     }
80     lega_wlan_close();
81 
82     rfota_wifi_open = 0x0;
83 }
84 #ifdef ALIOS_SUPPORT
85 static struct cli_command rfota_wifi_stop = {
86     .name     = "rfota_wifi_stop",
87     .help     = "rfota_wifi_stop for station",
88     .function = lega_at_wlan_stop,
89 };
90 #endif
lega_enable_rfota_wifi_test(char * pwbuf,int blen,int argc,char ** argv)91 static void lega_enable_rfota_wifi_test(char *pwbuf, int blen, int argc, char **argv)
92 {
93     int c = 1;
94     if (strcmp(argv[c], "on") == 0) {
95         rfota_wifi_test = 1;
96         printf("rfota wifi test begin\n");
97     } else if (strcmp(argv[c], "off") == 0) {
98         rfota_wifi_test = 0;
99         printf("rfota wifi test end\n");
100     }
101 }
102 #ifdef ALIOS_SUPPORT
103 static struct cli_command rfota_wifi_cmd = {
104     .name     = "rfota_wifi_test",
105     .help     = "rfota_wifi_test on/off",
106     .function = lega_enable_rfota_wifi_test,
107 };
108 
lega_rfota_wifi_test_at_init(void)109 void lega_rfota_wifi_test_at_init(void)
110 {
111     aos_cli_register_command(&rfota_wifi_cmd);
112     aos_cli_register_command(&rfota_wifi_start);
113     aos_cli_register_command(&rfota_wifi_stop);
114 }
115 #endif
116 #endif
117