• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ----------------------------------------------------------------------------
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <unistd.h>
23 
24 #include "los_config.h"
25 
26 #if defined(LOSCFG_SHELL) && defined(LOSCFG_DRIVERS_HI3881)
27 #include "los_typedef.h"
28 #include "shell.h"
29 #include "shcmd.h"
30 
31 
32 unsigned int wal_hipriv_entry(const char *pc_buffer, unsigned int count);
33 unsigned int at_cmd_process(const char *at_cmd_line);
34 
str_replace(char * s)35 static void str_replace(char *s)
36 {
37     while (*s != '\0') {
38         if (*s == '{' || *s == '}') {
39             *s = '\"';
40         }
41         s++;
42     }
43 }
44 
wifi_shell_cmd(int argc,char ** argv)45 static int wifi_shell_cmd(int argc, char **argv)
46 {
47     int i, ret;
48     char cmd[256] = { 0 };
49     int len = 0;
50     static int init = 0;
51 
52     if (init == 0) {
53         PRINTK("init at command\n");
54         init = 1;
55     }
56 
57     if (argc < 1) {
58         PRINT_ERR("no arguments\n");
59         return 0;
60     }
61 
62     if (!strncmp(argv[0], "AT", 2) && (strlen(argv[0]) > 3)) {
63         if (snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "%s", &argv[0][2]) == -1) {
64             return 0;
65         }
66         str_replace(cmd);
67         PRINTK("cmd:%s\n", cmd);
68     } else {
69         for (i = 0; i < argc; i++) {
70             ret = snprintf_s(&cmd[len], sizeof(cmd) - len, sizeof(cmd) - len - 1, " %s", argv[i]);
71             if (ret == -1) {
72                 return 0;
73             }
74             len += ret;
75         }
76         PRINTK("cmd:%s\n", cmd);
77         wal_hipriv_entry(cmd, len + 1);
78     }
79 
80     return 0;
81 }
82 
83 SHELLCMD_ENTRY(hi3881_shellcmd, CMD_TYPE_EX, "hi3881", XARGS, (CmdCallBackFunc)wifi_shell_cmd);
84 
85 #endif
86