1 /*
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
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 "at_hipriv.h"
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21
22 #include <hi_at.h>
23
24 #include "hi_wifi_mfg_test_if.h"
25 #include "hi_wifi_api.h"
26
27 #include "at.h"
28
29 #ifdef __cplusplus
30 #if __cplusplus
31 extern "C" {
32 #endif
33 #endif
at_hi_wifi_al_tx(hi_s32 argc,const hi_char * argv[])34 hi_u32 at_hi_wifi_al_tx(hi_s32 argc, const hi_char *argv[])
35 {
36 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
37 return HI_ERR_FAILURE;
38 }
39 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_AL_TX);
40 return ret;
41 }
42
at_hi_wifi_al_rx(hi_s32 argc,const hi_char * argv[])43 hi_u32 at_hi_wifi_al_rx(hi_s32 argc, const hi_char *argv[])
44 {
45 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
46 return HI_ERR_FAILURE;
47 }
48 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_AL_RX);
49 return ret;
50 }
51
at_hi_wifi_rx_info(hi_s32 argc,const hi_char * argv[])52 hi_u32 at_hi_wifi_rx_info(hi_s32 argc, const hi_char *argv[])
53 {
54 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_RX_INFO);
55 return ret;
56 }
57
at_hi_wifi_set_country(hi_s32 argc,const hi_char * argv[])58 hi_u32 at_hi_wifi_set_country(hi_s32 argc, const hi_char *argv[])
59 {
60 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
61 return HI_ERR_FAILURE;
62 }
63 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_SET_COUNTRY);
64 return ret;
65 }
66
at_hi_wifi_get_country(hi_s32 argc,const hi_char * argv[])67 hi_u32 at_hi_wifi_get_country(hi_s32 argc, const hi_char *argv[])
68 {
69 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_GET_COUNTRY);
70 return ret;
71 }
72
at_hi_wifi_set_tpc(hi_s32 argc,const hi_char * argv[])73 hi_u32 at_hi_wifi_set_tpc(hi_s32 argc, const hi_char *argv[])
74 {
75 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
76 return HI_ERR_FAILURE;
77 }
78 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_SET_TPC);
79 return ret;
80 }
81
at_hi_wifi_set_rate_power_sub(hi_s32 argc,const hi_char * argv[],hi_bool tuning)82 hi_u32 at_hi_wifi_set_rate_power_sub(hi_s32 argc, const hi_char *argv[], hi_bool tuning)
83 {
84 hi_u8 protol, rate;
85 hi_s32 val;
86 hi_u8 ofs = tuning ? 1 : 0;
87 hi_u8 protol_ofs = tuning ? 10 : 0; /* 10:Offset of the command */
88 hi_s32 low_limit = tuning ? -100 : -8; /* -100:Debug Command Lower Limit,-8:Lower Limit of Test Command */
89 hi_s32 up_limit = tuning ? 40 : 7; /* 40:Upper limit of debugging commands.,7:Upper Limit of Test Commands */
90
91 if ((at_param_null_check(argc, argv) == HI_ERR_FAILURE) || (argc != 3)) { /* Parameter verification, argc 3 */
92 return HI_ERR_FAILURE;
93 }
94
95 /* get protol */
96 if ((integer_check(argv[0]) != HI_ERR_SUCCESS) ||
97 (atoi(argv[0]) < HI_WIFI_PHY_MODE_11BGN) || (atoi(argv[0]) > HI_WIFI_PHY_MODE_11B)) {
98 return HI_ERR_FAILURE;
99 }
100 protol = (hi_u8)atoi(argv[0]);
101
102 /* get rate */
103 if (integer_check(argv[1]) != HI_ERR_SUCCESS) {
104 return HI_ERR_FAILURE;
105 }
106 if (((protol == HI_WIFI_PHY_MODE_11BGN) && ((atoi(argv[1]) < 0) || (atoi(argv[1]) > 7 + ofs))) || /* 0~7 */
107 ((protol == HI_WIFI_PHY_MODE_11BG) && ((atoi(argv[1]) < 0) || (atoi(argv[1]) > 7 + ofs))) || /* 0~7 */
108 ((protol == HI_WIFI_PHY_MODE_11B) && ((atoi(argv[1]) < 0) || (atoi(argv[1]) > 3 + ofs)))) { /* 0~3 */
109 return HI_ERR_FAILURE;
110 }
111 rate = (hi_u8)atoi(argv[1]);
112
113 /* get val */
114 if (argv[2][0] == '-') { /* 2 */
115 if (((argv[2][1] != '\0') && (integer_check(&argv[2][1]) != HI_ERR_SUCCESS)) || /* 2:array subscript */
116 (argv[2][1] == '\0')) { /* 2:array subscript */
117 return HI_ERR_FAILURE;
118 }
119 } else {
120 if (integer_check(argv[2]) != HI_ERR_SUCCESS) { /* 2:array subscript */
121 return HI_ERR_FAILURE;
122 }
123 }
124 if ((atoi(argv[2]) < low_limit) || (atoi(argv[2]) > up_limit)) { /* 2:array subscript */
125 return HI_ERR_FAILURE;
126 }
127 val = atoi(argv[2]); /* 2:array subscript */
128 protol += protol_ofs;
129
130 hi_u32 ret = wal_set_cal_rate_power(protol, rate, val);
131 if (ret == HI_ERR_SUCCESS) {
132 hi_at_printf("OK\r\n");
133 }
134
135 return ret;
136 }
137
at_hi_wifi_set_rate_power(hi_s32 argc,const hi_char * argv[])138 hi_u32 at_hi_wifi_set_rate_power(hi_s32 argc, const hi_char *argv[])
139 {
140 return at_hi_wifi_set_rate_power_sub(argc, argv, HI_TRUE);
141 }
142
at_hi_wifi_set_cal_freq(hi_s32 argc,const hi_char * argv[])143 hi_u32 at_hi_wifi_set_cal_freq(hi_s32 argc, const hi_char *argv[])
144 {
145 hi_s32 freq_offset;
146
147 if ((at_param_null_check(argc, argv) == HI_ERR_FAILURE) || (argc != 1)) { /* 1:Parameter verification */
148 return HI_ERR_FAILURE;
149 }
150
151 /* get freq offset */
152 if (argv[0][0] == '-') {
153 if (((argv[0][1] != '\0') && (integer_check(&argv[0][1]) != HI_ERR_SUCCESS)) ||
154 (argv[0][1] == '\0')) {
155 return HI_ERR_FAILURE;
156 }
157 } else {
158 if (integer_check(argv[0]) != HI_ERR_SUCCESS) {
159 return HI_ERR_FAILURE;
160 }
161 }
162 if ((atoi(argv[0]) < -128) || (atoi(argv[0]) > 127)) { /* Scope-128~127 */
163 return HI_ERR_FAILURE;
164 }
165 freq_offset = atoi(argv[0]);
166
167 hi_u32 ret = wal_set_cal_freq(freq_offset);
168 if (ret == HI_ERR_SUCCESS) {
169 hi_at_printf("OK\r\n");
170 }
171
172 return ret;
173 }
174
175 #ifdef CONFIG_FACTORY_TEST_MODE
at_hi_wifi_set_cal_band_power(hi_s32 argc,const hi_char * argv[])176 hi_u32 at_hi_wifi_set_cal_band_power(hi_s32 argc, const hi_char *argv[])
177 {
178 hi_u8 band_num;
179 hi_s32 offset;
180
181 if ((at_param_null_check(argc, argv) == HI_ERR_FAILURE) || (argc != 2)) { /* 2:Parameter verification */
182 return HI_ERR_FAILURE;
183 }
184
185 /* get band num */
186 if ((integer_check(argv[0]) != HI_ERR_SUCCESS) || (atoi(argv[0]) < 0) || (atoi(argv[0]) > 2)) { /* 0~2:subscript */
187 return HI_ERR_FAILURE;
188 }
189 band_num = (hi_u8)atoi(argv[0]);
190
191 /* get power offset */
192 if (argv[1][0] == '-') {
193 if (((argv[1][1] != '\0') && (integer_check(&argv[1][1]) != HI_ERR_SUCCESS)) ||
194 (argv[1][1] == '\0')) {
195 return HI_ERR_FAILURE;
196 }
197 } else {
198 if (integer_check(argv[1]) != HI_ERR_SUCCESS) {
199 return HI_ERR_FAILURE;
200 }
201 }
202 if ((atoi(argv[1]) < -60) || (atoi(argv[1]) > 60)) { /* Scope-60~60 */
203 return HI_ERR_FAILURE;
204 }
205 offset = atoi(argv[1]);
206
207 hi_u32 ret = wal_set_cal_band_power(band_num, offset);
208 if (ret == HI_ERR_SUCCESS) {
209 hi_at_printf("OK\r\n");
210 }
211
212 return ret;
213 }
214
at_hi_wifi_set_cal_rate_power(hi_s32 argc,const hi_char * argv[])215 hi_u32 at_hi_wifi_set_cal_rate_power(hi_s32 argc, const hi_char *argv[])
216 {
217 return at_hi_wifi_set_rate_power_sub(argc, argv, HI_FALSE);
218 }
219
at_hi_wifi_get_customer_mac(hi_s32 argc,const hi_char * argv[])220 hi_u32 at_hi_wifi_get_customer_mac(hi_s32 argc, const hi_char *argv[])
221 {
222 hi_unref_param(argc);
223 hi_unref_param(argv);
224
225 hi_u32 ret = wal_get_customer_mac();
226 if (ret != HI_ERR_SUCCESS) {
227 return HI_ERR_FAILURE;
228 }
229
230 return HI_ERR_SUCCESS;
231 }
232
at_hi_wifi_set_customer_mac(hi_s32 argc,const hi_char * argv[])233 hi_u32 at_hi_wifi_set_customer_mac(hi_s32 argc, const hi_char *argv[])
234 {
235 hi_uchar mac_addr[6]; /* 6:array subscript */
236 hi_u8 type = 0;
237 if ((argc < 1) || (argc > 2) || (at_param_null_check(argc, argv) == HI_ERR_FAILURE)) { /* 2 */
238 return HI_ERR_FAILURE;
239 }
240
241 if (strlen(argv[0]) != 17) { /* 17:MAC_ADDR_LEN */
242 return HI_ERR_FAILURE;
243 }
244
245 hi_u32 ret = cmd_strtoaddr(argv[0], mac_addr, 6); /* 6:lenth */
246 if (ret != HI_ERR_SUCCESS) {
247 return HI_ERR_FAILURE;
248 }
249 if (argc == 2) { /* 2:Parameter verification */
250 /* get type */
251 if (integer_check(argv[1]) != HI_ERR_SUCCESS) {
252 return HI_ERR_FAILURE;
253 }
254 type = (hi_u8)atoi(argv[1]);
255 if ((type != 0) && (type != 1)) { /* Parameter verification 0,1 */
256 return HI_ERR_FAILURE;
257 }
258 }
259 if (wal_set_customer_mac((hi_char*)mac_addr, type) != HI_ERR_SUCCESS) {
260 return HI_ERR_FAILURE;
261 }
262
263 return HI_ERR_SUCCESS;
264 }
265
at_hi_wifi_set_dataefuse(hi_s32 argc,const hi_char * argv[])266 hi_u32 at_hi_wifi_set_dataefuse(hi_s32 argc, const hi_char *argv[])
267 {
268 hi_u32 type = 0;
269
270 if ((argc == 1) && (at_param_null_check(argc, argv) == HI_ERR_FAILURE)) {
271 return HI_ERR_FAILURE;
272 }
273
274 if (argc == 1) {
275 /* get type */
276 if (integer_check(argv[0]) != HI_ERR_SUCCESS) {
277 return HI_ERR_FAILURE;
278 }
279 type = (hi_u32)atoi(argv[0]);
280 if ((type != 0) && (type != 1)) { /* Scope:0,1 */
281 return HI_ERR_FAILURE;
282 }
283 }
284
285 hi_u32 ret = wal_set_dataefuse(type);
286 if (ret != HI_ERR_SUCCESS) {
287 return HI_ERR_FAILURE;
288 }
289
290 return HI_ERR_SUCCESS;
291 }
292 #endif
293
at_hi_wifi_get_cal_data(hi_s32 argc,const hi_char * argv[])294 hi_u32 at_hi_wifi_get_cal_data(hi_s32 argc, const hi_char *argv[])
295 {
296 hi_unref_param(argc);
297 hi_unref_param(argv);
298
299 hi_u32 ret = wal_get_cal_data();
300 if (ret != HI_ERR_SUCCESS) {
301 return HI_ERR_FAILURE;
302 }
303
304 return HI_ERR_SUCCESS;
305 }
306
at_hi_wifi_set_trc(hi_s32 argc,const hi_char * argv[])307 hi_u32 at_hi_wifi_set_trc(hi_s32 argc, const hi_char *argv[])
308 {
309 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
310 return HI_ERR_FAILURE;
311 }
312 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_SET_TRC);
313 return ret;
314 }
315
at_hi_wifi_set_rate(hi_s32 argc,const hi_char * argv[])316 hi_u32 at_hi_wifi_set_rate(hi_s32 argc, const hi_char *argv[])
317 {
318 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
319 return HI_ERR_FAILURE;
320 }
321 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_SET_RATE);
322 return ret;
323 }
324
at_hi_wifi_set_arlog(hi_s32 argc,const hi_char * argv[])325 hi_u32 at_hi_wifi_set_arlog(hi_s32 argc, const hi_char *argv[])
326 {
327 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
328 return HI_ERR_FAILURE;
329 }
330 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_SET_ARLOG);
331 return ret;
332 }
333
at_hi_wifi_get_vap_info(hi_s32 argc,const hi_char * argv[])334 hi_u32 at_hi_wifi_get_vap_info(hi_s32 argc, const hi_char *argv[])
335 {
336 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
337 return HI_ERR_FAILURE;
338 }
339 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_GET_VAP_INFO);
340 return ret;
341 }
342
at_hi_wifi_get_usr_info(hi_s32 argc,const hi_char * argv[])343 hi_u32 at_hi_wifi_get_usr_info(hi_s32 argc, const hi_char *argv[])
344 {
345 if (at_param_null_check(argc, argv) == HI_ERR_FAILURE) {
346 return HI_ERR_FAILURE;
347 }
348 hi_u32 ret = hi_wifi_at_start(argc, argv, HISI_AT_GET_USR_INFO);
349 return ret;
350 }
351
352
353 const at_cmd_func g_at_hipriv_func_tbl[] = {
354 {"+RXINFO", 7, HI_NULL, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_rx_info},
355 {"+CC", 3, HI_NULL, (at_call_back_func)at_hi_wifi_get_country, (at_call_back_func)at_hi_wifi_set_country, HI_NULL},
356 #ifndef CONFIG_FACTORY_TEST_MODE
357 {"+TPC", 4, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_tpc, HI_NULL},
358 {"+TRC", 4, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_trc, HI_NULL},
359 {"+SETRATE", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_rate, HI_NULL},
360 {"+ARLOG", 6, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_arlog, HI_NULL},
361 {"+VAPINFO", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_get_vap_info, HI_NULL},
362 {"+USRINFO", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_get_usr_info, HI_NULL},
363 #endif
364 };
365
366 #define AT_HIPRIV_FUNC_NUM (sizeof(g_at_hipriv_func_tbl) / sizeof(g_at_hipriv_func_tbl[0]))
367
hi_at_hipriv_cmd_register(void)368 void hi_at_hipriv_cmd_register(void)
369 {
370 hi_at_register_cmd(g_at_hipriv_func_tbl, AT_HIPRIV_FUNC_NUM);
371 }
372
373 const at_cmd_func g_at_hipriv_factory_test_func_tbl[] = {
374 {"+ALTX", 5, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_al_tx, HI_NULL},
375 {"+ALRX", 5, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_al_rx, HI_NULL},
376 #ifdef CONFIG_FACTORY_TEST_MODE
377 {"+CALBPWR", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_cal_band_power, HI_NULL},
378 {"+CALRPWR", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_cal_rate_power, HI_NULL},
379 {"+EFUSEMAC", 9, HI_NULL, (at_call_back_func)at_hi_wifi_get_customer_mac,
380 (at_call_back_func)at_hi_wifi_set_customer_mac, HI_NULL},
381 {"+WCALDATA", 9, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_dataefuse,
382 (at_call_back_func)at_hi_wifi_set_dataefuse},
383 #endif
384 {"+CALFREQ", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_cal_freq, HI_NULL},
385 {"+SETRPWR", 8, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_set_rate_power, HI_NULL},
386 {"+RCALDATA", 9, HI_NULL, HI_NULL, HI_NULL, (at_call_back_func)at_hi_wifi_get_cal_data},
387 };
388 #define AT_HIPRIV_FACTORY_TEST_FUNC_NUM (sizeof(g_at_hipriv_factory_test_func_tbl) / \
389 sizeof(g_at_hipriv_factory_test_func_tbl[0]))
390
hi_at_hipriv_factory_test_cmd_register(void)391 void hi_at_hipriv_factory_test_cmd_register(void)
392 {
393 hi_at_register_cmd(g_at_hipriv_factory_test_func_tbl, AT_HIPRIV_FACTORY_TEST_FUNC_NUM);
394 }
395
396 #ifdef __cplusplus
397 #if __cplusplus
398 }
399 #endif
400 #endif
401
402