• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Winner Microelectronics 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 <string.h>
18 #include <ctype.h>
19 #include "wm_config.h"
20 #include "wm_cmdp.h"
21 #if (GCC_COMPILE == 1)
22 #include "wm_cmdp_hostif_gcc.h"
23 #else
24 #include "wm_cmdp_hostif.h"
25 #endif
26 #include "wm_mem.h"
27 #include "wm_params.h"
28 #include "wm_debug.h"
29 #include "wm_uart.h"
30 #include "wm_internal_flash.h"
31 #include "wm_netif.h"
32 #include "utils.h"
33 #include "wm_watchdog.h"
34 #include "wm_wifi.h"
35 #include "wm_sockets.h"
36 #include "wm_efuse.h"
37 #include "wm_dhcp_server.h"
38 
39 #define TWO 2
40 #define THREE 3
41 #define FOUR 4
42 #define SIX 6
43 #define TEN 10
44 #define FOURTEEN 14
45 #define TWENTY_FOUR 24
46 #define THIRTY_TWO 32
47 #define SIXTY_FOUR 64
48 #define ONE_THOUSAND_AND_TWENTY_FOUR 1024
49 #define TEN_THOUSAND 10000
50 
51 extern const char FirmWareVer[SIX];
52 extern const char HwVer[TEN];
53 tls_os_timer_t *RSTTIMER = NULL;
54 
55 u8 gfwupdatemode = 0;
tls_get_fwup_mode(void)56 u8 tls_get_fwup_mode(void)
57 {
58     return gfwupdatemode;
59 }
60 
tls_cmd_get_ver(struct tls_cmd_ver_t * ver)61 int tls_cmd_get_ver(struct tls_cmd_ver_t *ver)
62 {
63     MEMCPY(ver->hw_ver, HwVer, SIX);
64     MEMCPY(ver->fw_ver, FirmWareVer, FOUR);
65     if (tls_get_fwup_mode()) {
66         ver->fw_ver[0] = 'B';
67     }
68     return 0;
69 }
70 
tls_cmd_get_hw_ver(u8 * hwver)71 int tls_cmd_get_hw_ver(u8 *hwver)
72 {
73     return 0;
74 }
75 
tls_cmd_set_hw_ver(u8 * hwver)76 int tls_cmd_set_hw_ver(u8 *hwver)
77 {
78     return 0;
79 }
80 
81 #if TLS_CONFIG_HOSTIF
82 
83 struct tls_socket_cfg  socket_cfg;
84 static u8 net_up;
85 cmd_set_uart0_mode_callback set_uart0_mode_callback;
86 cmd_get_uart1_port_callback get_uart1_port_callback;
87 cmd_set_uart1_mode_callback set_uart1_mode_callback;
88 cmd_set_uart1_sock_param_callback set_uart1_sock_param_callback;
89 
tls_set_fwup_mode(u8 flag)90 void tls_set_fwup_mode(u8 flag)
91 {
92     gfwupdatemode = flag;
93 }
94 
tls_cmd_get_auto_mode(void)95 u8 tls_cmd_get_auto_mode(void)
96 {
97     u8 auto_mode_set;
98     tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode_set, FALSE);
99     return auto_mode_set;
100 }
101 
tls_cmd_get_socket_cfg(void)102 struct tls_socket_cfg *tls_cmd_get_socket_cfg(void)
103 {
104     return &socket_cfg;
105 }
106 
tls_cmd_set_net_up(u8 netup)107 void tls_cmd_set_net_up(u8 netup)
108 {
109     net_up = netup;
110 }
111 
tls_cmd_get_net_up(void)112 u8 tls_cmd_get_net_up(void)
113 {
114     return net_up;
115 }
116 
tls_cmd_init_socket_cfg(void)117 void tls_cmd_init_socket_cfg(void)
118 {
119     int timeout = 0, host_len;
120     struct tls_param_socket remote_socket_cfg;
121     tls_param_get(TLS_PARAM_ID_DEFSOCKET, &remote_socket_cfg, FALSE);
122     socket_cfg.proto = remote_socket_cfg.protocol;    /* read default socket params */
123     socket_cfg.client = remote_socket_cfg.client_or_server ? 0 : 1;
124     socket_cfg.port = remote_socket_cfg.port_num;
125     TLS_DBGPRT_INFO("socket_cfg.proto = %d, socket_cfg.client = %d, socket_cfg.port = %d\n",
126                     socket_cfg.proto, socket_cfg.client, socket_cfg.port);
127     host_len = strlen((char *)remote_socket_cfg.host);
128     if (socket_cfg.client) {
129         if (host_len) {        /* host name */
130             MEMCPY(socket_cfg.host, remote_socket_cfg.host, host_len);
131             string_to_ipaddr((char *)remote_socket_cfg.host, &socket_cfg.ip_addr[0]);
132         }
133     } else if (!socket_cfg.client && socket_cfg.proto == 0) {
134         if (strtodec(&timeout, (char *)remote_socket_cfg.host)<0) {
135             timeout = 0;
136         }
137 
138         socket_cfg.timeout = timeout;
139     } else
140         ;
141 }
142 
ResetTimerProc(void * ptmr,void * parg)143 static void ResetTimerProc(void *ptmr, void *parg)
144 {
145     tls_sys_reset();
146 }
147 
tls_cmd_reset_sys(void)148 void tls_cmd_reset_sys(void)
149 {
150     int err = 0;
151     if (RSTTIMER == NULL) {
152         err = tls_os_timer_create(&RSTTIMER,
153                                   ResetTimerProc,
154                                   NULL,
155                                   HZ/TEN,
156                                   FALSE,
157                                   NULL);
158         if (TLS_OS_SUCCESS == err) {
159             tls_os_timer_start(RSTTIMER);
160         }
161     }
162 }
163 
tls_cmd_pmtf(void)164 int tls_cmd_pmtf(void)
165 {
166     int err;
167     err = tls_param_to_flash(TLS_PARAM_ID_ALL);
168     return err;
169 }
170 
tls_cmd_reset_flash(void)171 int tls_cmd_reset_flash(void)
172 {
173     int err;
174     err = tls_param_to_default();
175     return err;
176 }
177 
tls_cmd_ps(struct tls_cmd_ps_t * ps)178 int tls_cmd_ps(struct tls_cmd_ps_t *ps)
179 {
180     return CMD_ERR_OK;
181 }
182 
tls_cmd_scan(enum tls_cmd_mode mode)183 int tls_cmd_scan(enum tls_cmd_mode mode)
184 {
185     int ret = 0;
186     struct tls_hostif *hif = tls_get_hostif();
187 
188     if (hif->last_scan)    /* scanning not finished */
189         return CMD_ERR_BUSY;
190 
191     hif->last_scan = 1;
192     hif->last_scan_cmd_mode = mode;
193 
194     tls_wifi_scan_result_cb_register(hostif_wscan_cmplt);    /* register scan complt callback */
195 
196     ret = tls_wifi_scan();    /* trigger the scan */
197     if (ret == WM_WIFI_SCANNING_BUSY) {
198         hif->last_scan = 0;
199         return CMD_ERR_BUSY;
200     } else if (ret == WM_FAILED) {
201         hif->last_scan = 0;
202         return CMD_ERR_MEM;
203     }
204 
205     return CMD_ERR_OK;
206 }
207 
tls_cmd_scan_by_param(enum tls_cmd_mode mode,u16 channellist,u32 times,u16 switchinterval)208 int tls_cmd_scan_by_param(enum tls_cmd_mode mode, u16 channellist, u32 times, u16 switchinterval)
209 {
210     int ret = 0;
211     struct tls_hostif *hif = tls_get_hostif();
212     struct tls_wifi_scan_param_t scan_param;
213 
214     if (hif->last_scan)    /* scanning not finished */
215         return CMD_ERR_BUSY;
216 
217     hif->last_scan = 1;
218     hif->last_scan_cmd_mode = mode;
219 
220     tls_wifi_scan_result_cb_register(hostif_wscan_cmplt);    /* register scan complt callback */
221 
222     scan_param.scan_chanlist = channellist;    /* trigger the scan */
223     scan_param.scan_chinterval = switchinterval;
224     scan_param.scan_times = times;
225     ret = tls_wifi_scan_by_param(&scan_param);
226     if (ret == WM_WIFI_SCANNING_BUSY) {
227         tls_wifi_scan_result_cb_register(NULL);
228         hif->last_scan = 0;
229         return CMD_ERR_BUSY;
230     } else if (ret == WM_FAILED) {
231         tls_wifi_scan_result_cb_register(NULL);
232         hif->last_scan = 0;
233         return CMD_ERR_MEM;
234     }
235 
236     return CMD_ERR_OK;
237 }
238 
239 
tls_cmd_join_net(void)240 int tls_cmd_join_net(void)
241 {
242     struct tls_cmd_ssid_t ssid;
243     struct tls_cmd_key_t  *key;
244     struct tls_cmd_bssid_t bssid;
245     int ret;
246 
247     key = tls_mem_alloc(sizeof(struct tls_cmd_key_t));
248     if (!key)
249         return -1;
250     memset(key, 0, sizeof(struct tls_cmd_key_t));
251 
252     tls_cmd_get_bssid(&bssid);
253     tls_cmd_get_ssid(&ssid);
254     tls_cmd_get_key(key);
255 
256     if (bssid.enable) {
257         if (ssid.ssid_len) {
258             ret = tls_wifi_connect_by_ssid_bssid(ssid.ssid, ssid.ssid_len, bssid.bssid, key->key, key->key_len);
259         } else {
260             ret = tls_wifi_connect_by_bssid(bssid.bssid, key->key, key->key_len);
261         }
262     } else {
263         ret = tls_wifi_connect(ssid.ssid, ssid.ssid_len, key->key, key->key_len);
264     }
265 
266     tls_mem_free(key);
267     return ret;
268 }
269 
tls_cmd_create_net(void)270 int tls_cmd_create_net(void)
271 {
272     int ret = CMD_ERR_UNSUPP;
273 #if TLS_CONFIG_AP
274     struct tls_softap_info_t* apinfo;
275     struct tls_ip_info_t* ipinfo;
276     struct tls_cmd_ssid_t ssid;
277     struct tls_cmd_ip_params_t ip_addr;
278 
279     apinfo = tls_mem_alloc(sizeof(struct tls_softap_info_t));
280     if (apinfo == NULL)
281         return CMD_ERR_MEM;
282     ipinfo = tls_mem_alloc(sizeof(struct tls_ip_info_t));
283     if (ipinfo == NULL) {
284         tls_mem_free(apinfo);
285         return CMD_ERR_MEM;
286     }
287 
288     tls_cmd_get_softap_ssid(&ssid);
289     MEMCPY(apinfo->ssid, ssid.ssid, ssid.ssid_len);
290     apinfo->ssid[ssid.ssid_len] = '\0';
291 
292     tls_cmd_get_softap_encrypt(&apinfo->encrypt);
293     tls_cmd_get_softap_channel(&apinfo->channel);
294     tls_cmd_get_softap_key((struct tls_cmd_key_t *)(&apinfo->keyinfo));
295     tls_cmd_get_softap_ip_info(&ip_addr);
296 
297     MEMCPY(ipinfo->ip_addr, ip_addr.ip_addr, FOUR);
298     MEMCPY(ipinfo->netmask, ip_addr.netmask, FOUR);
299     tls_cmd_get_dnsname(ipinfo->dnsname);
300 
301     ret = tls_wifi_softap_create(apinfo, ipinfo);
302 
303     tls_mem_free(apinfo);
304     tls_mem_free(ipinfo);
305 #endif
306 
307     return ret;
308 }
309 
tls_cmd_create_ibss_net(void)310 int tls_cmd_create_ibss_net(void)
311 {
312     int ret = CMD_ERR_UNSUPP;
313     return ret;
314 }
315 
tls_cmd_join(enum tls_cmd_mode mode,struct tls_cmd_connect_t * conn)316 int tls_cmd_join(enum tls_cmd_mode mode, struct tls_cmd_connect_t *conn)
317 {
318     return;
319 }
320 
tls_cmd_disconnect_network(u8 mode)321 int tls_cmd_disconnect_network(u8 mode)
322 {
323     struct tls_hostif *hif = tls_get_hostif();
324     u8 auto_reconnect = 0xff;
325     int ret;
326 
327     hif->last_join = 0;
328 
329     /* notify sys task */
330     tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_GET, &auto_reconnect);
331     if (auto_reconnect == WIFI_AUTO_CNT_ON) {
332         auto_reconnect = WIFI_AUTO_CNT_TMP_OFF;
333         ret = tls_wifi_auto_connect_flag(WIFI_AUTO_CNT_FLAG_SET, &auto_reconnect);
334         if (ret != WM_SUCCESS)
335             return ret;
336     }
337 #if TLS_CONFIG_AP
338     if (IEEE80211_MODE_AP & mode)
339         tls_wifi_softap_destroy();
340     if ((~IEEE80211_MODE_AP) & mode)
341 #endif
342     tls_wifi_disconnect();
343     return WM_SUCCESS;
344 }
345 
tls_cmd_get_link_status(struct tls_cmd_link_status_t * lks)346 int tls_cmd_get_link_status(struct tls_cmd_link_status_t *lks)
347 {
348     return 0;
349 }
350 
tls_cmd_wps_start(void)351 int tls_cmd_wps_start(void)
352 {
353     return -1;
354 }
355 
tls_cmd_set_wireless_mode(u8 mode,u8 update_flash)356 int tls_cmd_set_wireless_mode(u8 mode, u8 update_flash)
357 {
358     u8 wmode;
359 
360     switch (mode) {
361         case 0:
362             wmode = IEEE80211_MODE_INFRA;
363             break;
364         case 1:
365             wmode = IEEE80211_MODE_IBSS;
366             break;
367         case TWO:
368             wmode = IEEE80211_MODE_AP;
369             break;
370         case THREE:
371             wmode = IEEE80211_MODE_INFRA | IEEE80211_MODE_AP;
372             break;
373         default:
374             return -1;
375     }
376     tls_param_set(TLS_PARAM_ID_WPROTOCOL, (void *)&wmode, (bool)update_flash);
377     return 0;
378 }
379 
tls_cmd_get_wireless_mode(u8 * mode)380 int tls_cmd_get_wireless_mode(u8 *mode)
381 {
382     int err  = 0;
383     u8 wmode = 0;
384 
385     tls_param_get(TLS_PARAM_ID_WPROTOCOL, (void *)&wmode, TRUE);
386     /* set WPAS_MODE to do */
387     switch (wmode) {
388         case IEEE80211_MODE_INFRA:
389             *mode = 0;
390             break;
391         case IEEE80211_MODE_IBSS:
392             *mode = 1;
393             break;
394         case IEEE80211_MODE_AP:
395             *mode = TWO;
396             break;
397         case (IEEE80211_MODE_INFRA | IEEE80211_MODE_AP):
398             *mode = THREE;
399             break;
400         default:
401             err  = CMD_ERR_NOT_ALLOW;
402             break;
403     }
404     return err;
405 }
406 
tls_cmd_set_ssid(struct tls_cmd_ssid_t * ssid,u8 update_flash)407 int tls_cmd_set_ssid(struct tls_cmd_ssid_t *ssid, u8 update_flash)
408 {
409     struct tls_param_ssid params_ssid;
410 
411     if (ssid->ssid_len > THIRTY_TWO)
412         return -1;
413 
414     params_ssid.ssid_len = ssid->ssid_len;
415     MEMCPY(&params_ssid.ssid, ssid->ssid, ssid->ssid_len);
416 
417     tls_param_set(TLS_PARAM_ID_SSID, (void *)&params_ssid, (bool)update_flash);
418 
419     return 0;
420 }
421 
tls_cmd_get_ssid(struct tls_cmd_ssid_t * ssid)422 int tls_cmd_get_ssid(struct tls_cmd_ssid_t *ssid)
423 {
424     struct tls_param_ssid params_ssid;
425 
426     tls_param_get(TLS_PARAM_ID_SSID, (void *)&params_ssid, 0);
427     if (params_ssid.ssid_len > THIRTY_TWO) {
428         ssid->ssid_len = 0;
429         params_ssid.ssid[0] = '\0';
430     } else {
431         ssid->ssid_len = params_ssid.ssid_len;
432         MEMCPY(ssid->ssid, params_ssid.ssid, ssid->ssid_len);
433     }
434 
435     return 0;
436 }
437 
tls_cmd_set_key(struct tls_cmd_key_t * key,u8 update_flash)438 int tls_cmd_set_key(struct tls_cmd_key_t *key, u8 update_flash)
439 {
440     struct tls_param_key param_key;
441     struct tls_param_original_key* orig_key;
442     struct tls_param_sha1* sha1_key;
443 
444     MEMCPY(param_key.psk, key->key, SIXTY_FOUR);
445     param_key.key_format = key->format;
446     param_key.key_index = key->index;
447     param_key.key_length = key->key_len;
448     tls_param_set(TLS_PARAM_ID_KEY, (void *)&param_key, (bool)update_flash);
449 
450     orig_key = (struct tls_param_original_key*)&param_key;
451     MEMCPY(orig_key->psk, key->key, SIXTY_FOUR);
452     orig_key->key_length = key->key_len;
453     tls_param_set(TLS_PARAM_ID_ORIGIN_KEY, (void *)orig_key, (bool)update_flash);
454 
455     sha1_key = (struct tls_param_sha1*)&param_key;
456     memset((u8*)sha1_key, 0, sizeof(struct tls_param_sha1));
457     tls_param_set(TLS_PARAM_ID_SHA1, (void *)sha1_key, TRUE);
458 
459     return 0;
460 }
461 
tls_cmd_get_key(struct tls_cmd_key_t * key)462 int tls_cmd_get_key(struct tls_cmd_key_t *key)
463 {
464     struct tls_param_key *param_key;
465     struct tls_param_original_key* orig_key;
466 
467     param_key = tls_mem_alloc(sizeof(struct tls_cmd_key_t));
468     if (!param_key)
469         return -1;
470 
471     orig_key = tls_mem_alloc(sizeof(struct tls_param_original_key));
472     if (!orig_key) {
473         tls_mem_free(param_key);
474         return -1;
475     }
476 
477     memset(param_key, 0, sizeof(struct tls_cmd_key_t));
478     memset(orig_key, 0, sizeof(struct tls_param_original_key));
479 
480     tls_param_get(TLS_PARAM_ID_KEY, (void *)param_key, 1);
481     key->index = param_key->key_index;
482     key->format = param_key->key_format;
483 
484     tls_param_get(TLS_PARAM_ID_ORIGIN_KEY, (void *)orig_key, 1);
485     MEMCPY(key->key, orig_key->psk, SIXTY_FOUR);
486     key->key_len = orig_key->key_length;
487 
488     tls_mem_free(param_key);
489     tls_mem_free(orig_key);
490     return 0;
491 }
492 
tls_cmd_set_encrypt(u8 encrypt,u8 update_flash)493 int tls_cmd_set_encrypt(u8 encrypt, u8 update_flash)
494 {
495     struct tls_param_key param_key;
496 
497     if (encrypt == 0) {
498         memset(param_key.psk, 0, SIXTY_FOUR);
499         param_key.key_format = 0;
500         param_key.key_index = 0;
501         param_key.key_length = 0;
502         tls_param_set(TLS_PARAM_ID_KEY, (void *)&param_key, (bool)update_flash);
503     }
504 
505     tls_param_set(TLS_PARAM_ID_ENCRY, (void *)&encrypt, (bool)update_flash);
506     return 0;
507 }
508 
tls_cmd_get_encrypt(u8 * encrypt)509 int tls_cmd_get_encrypt(u8 *encrypt)
510 {
511     tls_param_get(TLS_PARAM_ID_ENCRY, (void *)encrypt, (bool)0);
512     return 0;
513 }
514 
tls_cmd_set_bssid(struct tls_cmd_bssid_t * bssid,u8 update_flash)515 int tls_cmd_set_bssid(struct tls_cmd_bssid_t *bssid, u8 update_flash)
516 {
517     struct tls_param_bssid param_bssid;
518     int err;
519 
520     err = is_zero_ether_addr(bssid->bssid);
521     if (err)
522         return -1;
523     param_bssid.bssid_enable = bssid->enable;
524     MEMCPY(param_bssid.bssid, bssid->bssid, ETH_ALEN);
525 
526     tls_param_set(TLS_PARAM_ID_BSSID, (void *)&param_bssid, (bool)update_flash);
527 
528     return 0;
529 }
530 
tls_cmd_get_bssid(struct tls_cmd_bssid_t * bssid)531 int tls_cmd_get_bssid(struct tls_cmd_bssid_t *bssid)
532 {
533     struct tls_param_bssid param_bssid;
534 
535     if (bssid) {
536         tls_param_get(TLS_PARAM_ID_BSSID, (void *)&param_bssid, (bool)0);
537         MEMCPY(bssid->bssid, param_bssid.bssid, SIX);
538         bssid->enable = param_bssid.bssid_enable;
539     }
540 
541     return 0;
542 }
543 
tls_cmd_get_original_ssid(struct tls_param_ssid * original_ssid)544 int tls_cmd_get_original_ssid(struct tls_param_ssid *original_ssid)
545 {
546     tls_param_get(TLS_PARAM_ID_ORIGIN_SSID, (void *)original_ssid, 1);
547     if (original_ssid->ssid_len > THIRTY_TWO) {
548             original_ssid->ssid_len = 0;
549             original_ssid->ssid[0] = '\0';
550     }
551 
552     return 0;
553 }
554 
tls_cmd_get_original_key(struct tls_param_original_key * original_key)555 int tls_cmd_get_original_key(struct tls_param_original_key *original_key)
556 {
557     tls_param_get(TLS_PARAM_ID_ORIGIN_KEY, (void *)original_key, 1);
558     return 0;
559 }
560 
tls_cmd_set_hide_ssid(u8 ssid_set,u8 update_flash)561 int tls_cmd_set_hide_ssid(u8 ssid_set, u8 update_flash)
562 {
563     tls_param_set(TLS_PARAM_ID_BRDSSID, (void *)&ssid_set, (bool)update_flash);
564     return 0;
565 }
566 
tls_cmd_get_hide_ssid(u8 * ssid_set)567 int tls_cmd_get_hide_ssid(u8 *ssid_set)
568 {
569     tls_param_get(TLS_PARAM_ID_BRDSSID, (void *)ssid_set, (bool)0);
570     return 0;
571 }
572 
tls_cmd_set_channel(u8 channel,u8 channel_en,u8 update_flash)573 int tls_cmd_set_channel(u8 channel, u8 channel_en, u8 update_flash)
574 {
575     if (channel > FOURTEEN)
576         return -1;
577 
578     tls_param_set(TLS_PARAM_ID_CHANNEL, (void *)&channel, (bool)update_flash);
579     tls_param_set(TLS_PARAM_ID_CHANNEL_EN, (void *)&channel_en, (bool)update_flash);
580 
581     return 0;
582 }
583 
tls_cmd_get_channel(u8 * channel,u8 * channel_en)584 int tls_cmd_get_channel(u8 *channel, u8 *channel_en)
585 {
586     tls_param_get(TLS_PARAM_ID_CHANNEL, (void *)channel, (bool)0);
587     tls_param_get(TLS_PARAM_ID_CHANNEL_EN, (void *)channel_en, (bool)0);
588 
589     /* if no channel is specified, channel 1 is selected by default */
590     if (*channel_en == 0) {
591         *channel = 1;
592     }
593 
594     return 0;
595 }
596 
tls_cmd_set_channellist(u16 channellist,u8 update_flash)597 int tls_cmd_set_channellist(u16 channellist, u8 update_flash)
598 {
599     tls_param_set(TLS_PARAM_ID_CHANNEL_LIST, (void *)&channellist, (bool)update_flash);
600     return 0;
601 }
602 
tls_cmd_get_channellist(u16 * channellist)603 int tls_cmd_get_channellist(u16 *channellist)
604 {
605     tls_param_get(TLS_PARAM_ID_CHANNEL_LIST, (void *)channellist, (bool)1);
606     return 0;
607 }
608 
tls_cmd_set_region(u16 region,u8 update_flash)609 int tls_cmd_set_region(u16 region, u8 update_flash)
610 {
611     tls_param_set(TLS_PARAM_ID_COUNTRY_REGION, (void *)&region, (bool)update_flash);
612     return 0;
613 }
614 
tls_cmd_get_region(u16 * region)615 int tls_cmd_get_region(u16 *region)
616 {
617     tls_param_get(TLS_PARAM_ID_COUNTRY_REGION, (void *)region, (bool)0);
618     return 0;
619 }
620 
621 /*
622 * 0: 11B/G
623 * 1: 11B
624 * 2: 11B/G/N
625 */
tls_cmd_set_hw_mode(struct tls_cmd_wl_hw_mode_t * hw_mode,u8 update_flash)626 int tls_cmd_set_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode, u8 update_flash)
627 {
628     struct tls_param_bgr bgr;
629 
630     if (hw_mode->hw_mode > TWO) /* wangm: bgn */
631         return -1;
632 
633     if ((hw_mode->hw_mode == 1) && (hw_mode->max_rate > THREE)) {
634         return -1;
635     }
636     bgr.bg = hw_mode->hw_mode;
637     bgr.max_rate = hw_mode->max_rate;
638     tls_param_set(TLS_PARAM_ID_WBGR, (void *)&bgr, (bool)update_flash);
639     return 0;
640 }
641 
tls_cmd_get_hw_mode(struct tls_cmd_wl_hw_mode_t * hw_mode)642 int tls_cmd_get_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode)
643 {
644     struct tls_param_bgr bgr;
645 
646     tls_param_get(TLS_PARAM_ID_WBGR, (void *)&bgr, (bool)0);
647     hw_mode->hw_mode = bgr.bg;
648     hw_mode->max_rate = bgr.max_rate;
649 
650     return 0;
651 }
652 
tls_cmd_set_adhoc_create_mode(u8 mode,u8 update_flash)653 int tls_cmd_set_adhoc_create_mode(u8 mode, u8 update_flash)
654 {
655     tls_param_set(TLS_PARAM_ID_ADHOC_AUTOCREATE, (void *)&mode, (bool)update_flash);
656     return 0;
657 }
658 
tls_cmd_get_adhoc_create_mode(u8 * mode)659 int tls_cmd_get_adhoc_create_mode(u8 *mode)
660 {
661     tls_param_get(TLS_PARAM_ID_ADHOC_AUTOCREATE, (void *)mode, (bool)0);
662     return 0;
663 }
664 
tls_cmd_set_wl_ps_mode(u8 enable,u8 update_flash)665 int tls_cmd_set_wl_ps_mode(u8 enable, u8 update_flash)
666 {
667     tls_param_set(TLS_PARAM_ID_PSM, (void *)&enable, (bool)update_flash);
668     return 0;
669 }
670 
tls_cmd_get_wl_ps_mode(u8 * enable)671 int tls_cmd_get_wl_ps_mode(u8 *enable)
672 {
673     tls_param_get(TLS_PARAM_ID_PSM, (void *)enable, (bool)1);
674     return 0;
675 }
676 
tls_cmd_set_roaming_mode(u8 enable,u8 update_flash)677 int tls_cmd_set_roaming_mode(u8 enable, u8 update_flash)
678 {
679     tls_param_set(TLS_PARAM_ID_ROAMING, (void *)&enable, (bool)update_flash);
680     return 0;
681 }
682 
tls_cmd_get_roaming_mode(u8 * enable)683 int tls_cmd_get_roaming_mode(u8 *enable)
684 {
685     tls_param_get(TLS_PARAM_ID_ROAMING, (void *)enable, (bool)0);
686     return 0;
687 }
688 
tls_cmd_set_wps_params(struct tls_cmd_wps_params_t * params,u8 update_flash)689 int tls_cmd_set_wps_params(struct tls_cmd_wps_params_t *params, u8 update_flash)
690 {
691 #if TLS_CONFIG_WPS
692     return 0;
693 #else
694     return -1;
695 #endif
696 }
697 
tls_cmd_get_wps_params(struct tls_cmd_wps_params_t * params)698 int tls_cmd_get_wps_params(struct tls_cmd_wps_params_t *params)
699 {
700 #if TLS_CONFIG_WPS
701     return 0;
702 #else
703     return -1;
704 #endif
705 }
706 
tls_cmd_get_ip_info(struct tls_cmd_ip_params_t * params)707 int tls_cmd_get_ip_info(struct tls_cmd_ip_params_t *params)
708 {
709     struct tls_param_ip ip_param;
710     tls_param_get(TLS_PARAM_ID_IP, &ip_param, FALSE);
711 
712     MEMCPY(params->ip_addr, (char *)ip_param.ip, FOUR);
713     MEMCPY(params->netmask, (char *)ip_param.netmask, FOUR);
714     MEMCPY(params->gateway, (char *)ip_param.gateway, FOUR);
715     MEMCPY(params->dns, (char *)ip_param.dns1, FOUR);
716     params->type = ip_param.dhcp_enable ? 0 : 1;
717     return 0;
718 }
719 
tls_cmd_set_ip_info(struct tls_cmd_ip_params_t * params,u8 update_flash)720 int tls_cmd_set_ip_info(struct tls_cmd_ip_params_t *params, u8 update_flash)
721 {
722     return 0;
723 }
724 
tls_cmd_set_work_mode(u8 mode,u8 update_flash)725 int tls_cmd_set_work_mode(u8 mode, u8 update_flash)
726 {
727     u8 auto_mode;
728 
729     switch (mode) {
730         case 0:
731             auto_mode= 1;
732             break;
733         case 1:
734             auto_mode= 0;
735             break;
736         default:
737             return -1;
738     }
739 
740     tls_param_set(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, (bool)update_flash);
741 
742     /* AUTOMODE: transmode, it must work with AUTO_RECONNECT together */
743     tls_param_set(TLS_PARAM_ID_AUTO_RECONNECT, (void *)&auto_mode, (bool)update_flash);
744     return 0;
745 }
746 
tls_cmd_get_work_mode(u8 * mode)747 int tls_cmd_get_work_mode(u8 *mode)
748 {
749     u8 auto_mode;
750 
751     tls_param_get(TLS_PARAM_ID_AUTOMODE, (void *)&auto_mode, 0);
752     if (auto_mode == 0)
753         *mode = 1;
754     else
755         *mode = 0;
756     return 0;
757 }
758 
tls_cmd_get_hostif_mode(u8 * mode)759 int tls_cmd_get_hostif_mode(u8 *mode)
760 {
761     tls_param_get(TLS_PARAM_ID_USRINTF, (void *)mode, TRUE);
762     return 0;
763 }
764 
tls_cmd_set_hostif_mode(u8 mode,u8 update_flash)765 int tls_cmd_set_hostif_mode(u8 mode, u8 update_flash)
766 {
767     tls_param_set(TLS_PARAM_ID_USRINTF, (void *)&mode, (bool)update_flash);
768     return 0;
769 }
770 
tls_cmd_set_default_socket_params(struct tls_cmd_socket_t * params,u8 update_flash)771 int tls_cmd_set_default_socket_params(struct tls_cmd_socket_t *params, u8 update_flash)
772 {
773     struct tls_socket_cfg *skt_cfg = &socket_cfg;
774     struct tls_param_socket param_socket_cfg;
775     if (tls_param_get_updp_mode() == 0) {
776         skt_cfg->proto = params->proto;
777         skt_cfg->client = params->client;
778         skt_cfg->port = params->port;
779         skt_cfg->host_len = params->host_len;
780         MEMCPY(skt_cfg->ip_addr, params->ip_addr, FOUR);
781         strcpy((char *)skt_cfg->host, params->host_name);
782         skt_cfg->timeout = params->timeout;
783     }
784     param_socket_cfg.client_or_server = params->client ? 0 : 1;
785     param_socket_cfg.protocol = params->proto;
786     param_socket_cfg.port_num = params->port;
787     strcpy((char *)param_socket_cfg.host, params->host_name);
788     tls_param_set(TLS_PARAM_ID_DEFSOCKET, (void *)&param_socket_cfg, (bool)update_flash);
789     return 0;
790 }
791 
tls_cmd_get_default_socket_params(struct tls_cmd_socket_t * params)792 int tls_cmd_get_default_socket_params(struct tls_cmd_socket_t *params)
793 {
794     struct tls_socket_cfg *skt_cfg = &socket_cfg;
795 
796     params->proto = skt_cfg->proto;
797     params->client = skt_cfg->client;
798     params->port = skt_cfg->port;
799     params->host_len = skt_cfg->host_len;
800     strcpy(params->host_name, (char *)skt_cfg->host);
801     MEMCPY(params->ip_addr, skt_cfg->ip_addr, FOUR);
802     params->timeout = skt_cfg->timeout;
803     return 0;
804 }
805 
tls_cmd_get_uart_params(struct tls_cmd_uart_params_t * params)806 int tls_cmd_get_uart_params(struct tls_cmd_uart_params_t *params)
807 {
808     struct tls_param_uart uart_params;
809 
810     tls_param_get(TLS_PARAM_ID_UART, (void *)&uart_params, 0);
811     params->baud_rate = uart_params.baudrate;
812     params->flow_ctrl = uart_params.flow;
813     params->parity = uart_params.parity;
814     switch (uart_params.stop_bits) {
815         case TLS_UART_ONE_STOPBITS:
816             params->stop_bit = 0;
817             break;
818         case TLS_UART_TWO_STOPBITS:
819             params->stop_bit = TWO;
820             break;
821         default:
822             params->stop_bit = 0;
823             break;
824     }
825     switch (uart_params.charsize) {
826         case TLS_UART_CHSIZE_8BIT:
827             params->charlength = 0;
828             break;
829         case TLS_UART_CHSIZE_7BIT:
830             params->charlength = 1;
831             break;
832         default:
833             params->charlength = 0;
834     }
835 
836     return 0;
837 }
838 
tls_cmd_set_uart_params(struct tls_cmd_uart_params_t * params,u8 update_flash)839 int tls_cmd_set_uart_params(struct tls_cmd_uart_params_t *params, u8 update_flash)
840 {
841     int err;
842     TLS_UART_STOPBITS_T stop_bit;
843     struct tls_param_uart uart_params;
844     TLS_UART_CHSIZE_T charsize;
845     struct tls_uart_port *uart1_port = NULL;
846     cmd_get_uart1_port_callback callback;
847 
848 #if TLS_CONFIG_UART
849     {
850         extern int tls_uart_check_baudrate(u32 baudrate);
851         err = tls_uart_check_baudrate(params->baud_rate);
852     }
853 #endif
854     if (err < 0)
855     return CMD_ERR_INV_PARAMS;
856 
857     switch (params->charlength) {
858         case 0:
859             charsize = TLS_UART_CHSIZE_8BIT;
860             break;
861         case 1:
862             charsize = TLS_UART_CHSIZE_7BIT;
863             break;
864         default:
865             return CMD_ERR_INV_PARAMS;
866     }
867     if (params->flow_ctrl > 1)
868         return CMD_ERR_INV_PARAMS;
869     if (params->parity > TWO)
870         return CMD_ERR_INV_PARAMS;
871     switch (params->stop_bit) {
872         case 0:
873             stop_bit = TLS_UART_ONE_STOPBITS;
874             break;
875         case TWO:
876             stop_bit = TLS_UART_TWO_STOPBITS;
877             break;
878         default:
879             return CMD_ERR_INV_PARAMS;
880     }
881     callback = tls_cmd_get_uart1_port();
882     if (callback != NULL)
883         callback(&uart1_port);
884     if (!uart1_port)
885         return CMD_ERR_NOT_ALLOW;
886     if (tls_param_get_updp_mode() == 0) {
887         uart1_port->opts.baudrate = params->baud_rate;
888         uart1_port->opts.paritytype= (TLS_UART_PMODE_T)params->parity;
889         uart1_port->opts.flow_ctrl = (TLS_UART_FLOW_CTRL_MODE_T)params->flow_ctrl;
890         uart1_port->opts.stopbits= stop_bit;
891         uart1_port->opts.charlength = charsize;
892     }
893     uart_params.baudrate = params->baud_rate;
894     uart_params.flow = params->flow_ctrl;
895     uart_params.parity = params->parity;
896     uart_params.stop_bits = stop_bit;
897     uart_params.charsize = charsize;
898 
899     err = tls_param_set(TLS_PARAM_ID_UART, (void *)&uart_params, (bool)update_flash);
900     if (err)
901         return CMD_ERR_FLASH;
902     return 0;
903 }
904 
tls_cmd_get_atlt(u16 * length)905 int tls_cmd_get_atlt(u16 *length)
906 {
907     struct tls_hostif *hif = tls_get_hostif();
908     *length = hif->uart_atlt;
909     return 0;
910 }
911 
tls_cmd_set_atlt(u16 length,u8 update_flash)912 int tls_cmd_set_atlt(u16 length, u8 update_flash)
913 {
914     struct tls_hostif *hif = tls_get_hostif();
915     if (length < THIRTY_TWO || length > ONE_THOUSAND_AND_TWENTY_FOUR)
916         return -1;
917     hif->uart_atlt = length;
918     tls_param_set(TLS_PARAM_ID_AUTO_TRIGGER_LENGTH, (void *)&length, (bool)update_flash);
919     return 0;
920 }
921 
tls_cmd_get_atpt(u16 * period)922 int tls_cmd_get_atpt(u16 *period)
923 {
924     struct tls_hostif *hif = tls_get_hostif();
925     tls_param_get(TLS_PARAM_ID_AUTO_TRIGGER_PERIOD, (void *)period, 0);
926     hif->uart_atpt = *period;
927     return 0;
928 }
929 
930 
tls_cmd_set_dnsname(u8 * dnsname,u8 update_flash)931 int tls_cmd_set_dnsname(u8 *dnsname, u8 update_flash)
932 {
933     if (dnsname == NULL)
934         return -1;
935     tls_param_set(TLS_PARAM_ID_DNSNAME, (void *)dnsname, (bool)update_flash);
936     return 0;
937 }
938 
tls_cmd_get_dnsname(u8 * dnsname)939 int tls_cmd_get_dnsname(u8 *dnsname)
940 {
941     tls_param_get(TLS_PARAM_ID_DNSNAME, dnsname, 0);
942     return 0;
943 }
944 
tls_cmd_set_atpt(u16 period,u8 update_flash)945 int tls_cmd_set_atpt(u16 period, u8 update_flash)
946 {
947     struct tls_hostif *hif = tls_get_hostif();
948     if (period > TEN_THOUSAND)
949         return -1;
950     hif->uart_atpt = period;
951     tls_param_set(TLS_PARAM_ID_AUTO_TRIGGER_PERIOD, (void *)&period, (bool)update_flash);
952     return 0;
953 }
954 
tls_cmd_get_espc(u8 * escapechar)955 int tls_cmd_get_espc(u8 *escapechar)
956 {
957     tls_param_get(TLS_PARAM_ID_ESCAPE_CHAR, (void *)escapechar, 0);
958     return 0;
959 }
960 
tls_cmd_set_espc(u8 escapechar,u8 update_flash)961 int tls_cmd_set_espc(u8 escapechar, u8 update_flash)
962 {
963     struct tls_hostif *hif = tls_get_hostif();
964     hif->escape_char = escapechar;
965     tls_param_set(TLS_PARAM_ID_ESCAPE_CHAR, (void *)&escapechar, (bool)update_flash);
966     return 0;
967 }
968 
tls_cmd_get_espt(u16 * escapeperiod)969 int tls_cmd_get_espt(u16 *escapeperiod)
970 {
971     tls_param_get(TLS_PARAM_ID_ESCAPE_PERIOD, (void *)escapeperiod, 0);
972     return 0;
973 }
974 
tls_cmd_set_espt(u16 escapeperiod,u8 update_flash)975 int tls_cmd_set_espt(u16 escapeperiod, u8 update_flash)
976 {
977     tls_param_set(TLS_PARAM_ID_ESCAPE_PERIOD, (void *)&escapeperiod, (bool)update_flash);
978     return 0;
979 }
980 
tls_cmd_get_iom(u8 * iomode)981 int tls_cmd_get_iom(u8 *iomode)
982 {
983     tls_param_get(TLS_PARAM_ID_IO_MODE, (void *)iomode, 0);
984     return 0;
985 }
986 
tls_cmd_set_iom(u8 iomode,u8 update_flash)987 int tls_cmd_set_iom(u8 iomode, u8 update_flash)
988 {
989     tls_param_set(TLS_PARAM_ID_IO_MODE, (void *)&iomode, (bool)update_flash);
990     return 0;
991 }
992 
tls_cmd_get_cmdm(u8 * cmdmode)993 int tls_cmd_get_cmdm(u8 *cmdmode)
994 {
995     tls_param_get(TLS_PARAM_ID_CMD_MODE, (void *)cmdmode, (bool)0);
996     return 0;
997 }
998 
tls_cmd_set_cmdm(u8 cmdmode,u8 update_flash)999 int tls_cmd_set_cmdm(u8 cmdmode, u8 update_flash)
1000 {
1001     tls_param_set(TLS_PARAM_ID_CMD_MODE, (void *)&cmdmode, (bool)update_flash);
1002     return 0;
1003 }
1004 
tls_cmd_set_oneshot(u8 oneshotflag,u8 update_flash)1005 int tls_cmd_set_oneshot(u8 oneshotflag, u8 update_flash)
1006 {
1007     return;
1008 }
1009 
tls_cmd_get_oneshot(u8 * oneshotflag)1010 int tls_cmd_get_oneshot(u8 *oneshotflag)
1011 {
1012     return 0;
1013 }
1014 
tls_cmd_set_sha1(u8 * psk,u8 update_flash)1015 int tls_cmd_set_sha1(u8* psk, u8 update_flash)
1016 {
1017     tls_param_set(TLS_PARAM_ID_SHA1, (void *)psk, (bool)update_flash);
1018     return 0;
1019 }
1020 
tls_cmd_get_sha1(u8 * psk)1021 int tls_cmd_get_sha1(u8 *psk)
1022 {
1023     tls_param_get(TLS_PARAM_ID_SHA1, (void *)psk, 1);
1024     return 0;
1025 }
1026 
1027 #if TLS_CONFIG_WPS
tls_cmd_set_wps_pin(struct tls_param_wps * wps,u8 update_flash)1028 int tls_cmd_set_wps_pin(struct tls_param_wps* wps, u8 update_flash)
1029 {
1030     tls_param_set(TLS_PARAM_ID_WPS, (void *)wps, (bool)update_flash);
1031     return 0;
1032 }
1033 
tls_cmd_get_wps_pin(struct tls_param_wps * wps)1034 int tls_cmd_get_wps_pin(struct tls_param_wps *wps)
1035 {
1036     tls_param_get(TLS_PARAM_ID_WPS, (void *)wps, 1);
1037     return 0;
1038 }
1039 #endif
1040 
tls_cmd_get_pass(u8 * password)1041 int tls_cmd_get_pass(u8 *password)
1042 {
1043     tls_param_get(TLS_PARAM_ID_PASSWORD, (void *)password, (bool)0);
1044     return 0;
1045 }
1046 
tls_cmd_set_pass(u8 * password,u8 update_flash)1047 int tls_cmd_set_pass(u8* password, u8 update_flash)
1048 {
1049     tls_param_set(TLS_PARAM_ID_PASSWORD, (void *)password, (bool)update_flash);
1050     return 0;
1051 }
1052 
tls_cmd_get_warc(u8 * autoretrycnt)1053 int tls_cmd_get_warc(u8 *autoretrycnt)
1054 {
1055     tls_param_get(TLS_PARAM_ID_AUTO_RETRY_CNT, (void *)autoretrycnt, (bool)1);
1056     return 0;
1057 }
1058 
tls_cmd_set_warc(u8 autoretrycnt,u8 update_flash)1059 int tls_cmd_set_warc(u8 autoretrycnt, u8 update_flash)
1060 {
1061     tls_param_set(TLS_PARAM_ID_AUTO_RETRY_CNT, (void *)&autoretrycnt, (bool)update_flash);
1062     return 0;
1063 }
1064 
tls_cmd_set_webs(struct tls_webs_cfg webcfg,u8 update_flash)1065 int tls_cmd_set_webs(struct tls_webs_cfg webcfg, u8 update_flash)
1066 {
1067     tls_param_set(TLS_PARAM_ID_WEBS_CONFIG, (void *)&webcfg, (bool)update_flash);
1068     return 0;
1069 }
1070 
tls_cmd_get_webs(struct tls_webs_cfg * webcfg)1071 int tls_cmd_get_webs(struct tls_webs_cfg *webcfg)
1072 {
1073     tls_param_get(TLS_PARAM_ID_WEBS_CONFIG, (void *)webcfg, 0);
1074     return 0;
1075 }
1076 
tls_cmd_set_dbg(u32 dbg)1077 int tls_cmd_set_dbg(u32 dbg)
1078 {
1079 #if TLS_CONFIG_LOG_PRINT
1080     if (dbg)
1081         tls_wifi_enable_log(true);
1082     else
1083         tls_wifi_enable_log(false);
1084 #endif
1085 
1086     return 0;
1087 }
1088 
tls_cmd_wr_flash(struct tls_cmd_flash_t * wr_flash)1089 int tls_cmd_wr_flash(struct tls_cmd_flash_t *wr_flash)
1090 {
1091     u8 data[TWENTY_FOUR];
1092     tls_fls_write(wr_flash->flash_addr, (u8 *)wr_flash->value,
1093                   sizeof(u32) * wr_flash->word_cnt);
1094 
1095     memset(data, 0, TWENTY_FOUR);
1096     tls_fls_read(wr_flash->flash_addr, data, TWENTY_FOUR);
1097     TLS_DBGPRT_DUMP((char *)data, TWENTY_FOUR);
1098 
1099     return 0;
1100 }
1101 
tls_cmd_register_get_uart1_port(cmd_get_uart1_port_callback callback)1102 void tls_cmd_register_get_uart1_port(cmd_get_uart1_port_callback callback)
1103 {
1104     get_uart1_port_callback = callback;
1105 }
1106 
tls_cmd_get_uart1_port(void)1107 cmd_get_uart1_port_callback tls_cmd_get_uart1_port(void)
1108 {
1109     return get_uart1_port_callback;
1110 }
1111 
tls_cmd_register_set_uart1_mode(cmd_set_uart1_mode_callback callback)1112 void tls_cmd_register_set_uart1_mode(cmd_set_uart1_mode_callback callback)
1113 {
1114     set_uart1_mode_callback = callback;
1115 }
1116 
tls_cmd_get_set_uart1_mode(void)1117 cmd_set_uart1_mode_callback tls_cmd_get_set_uart1_mode(void)
1118 {
1119     return set_uart1_mode_callback;
1120 }
1121 
tls_cmd_register_set_uart1_sock_param(cmd_set_uart1_sock_param_callback callback)1122 void tls_cmd_register_set_uart1_sock_param(cmd_set_uart1_sock_param_callback callback)
1123 {
1124     set_uart1_sock_param_callback = callback;
1125 }
1126 
tls_cmd_get_set_uart1_sock_param(void)1127 cmd_set_uart1_sock_param_callback tls_cmd_get_set_uart1_sock_param(void)
1128 {
1129     return set_uart1_sock_param_callback;
1130 }
1131 
tls_cmd_register_set_uart0_mode(cmd_set_uart0_mode_callback callback)1132 void tls_cmd_register_set_uart0_mode(cmd_set_uart0_mode_callback callback)
1133 {
1134     set_uart0_mode_callback = callback;
1135 }
1136 
tls_cmd_get_set_uart0_mode(void)1137 cmd_set_uart0_mode_callback tls_cmd_get_set_uart0_mode(void)
1138 {
1139     return set_uart0_mode_callback;
1140 }
1141 
1142 #if TLS_CONFIG_AP
tls_cmd_set_softap_ssid(struct tls_cmd_ssid_t * ssid,u8 update_flash)1143 int tls_cmd_set_softap_ssid(struct tls_cmd_ssid_t *ssid, u8 update_flash)
1144 {
1145     struct tls_param_ssid params_ssid;
1146     struct tls_param_sha1 apsta_psk;
1147 
1148     if (ssid->ssid_len > THIRTY_TWO)
1149         return -1;
1150 
1151     params_ssid.ssid_len = ssid->ssid_len;
1152     MEMCPY(&params_ssid.ssid, ssid->ssid, ssid->ssid_len);
1153     tls_param_set(TLS_PARAM_ID_SOFTAP_SSID, (void *)&params_ssid, (bool)update_flash);
1154 
1155     memset(&apsta_psk, 0, sizeof(apsta_psk));
1156     tls_param_set(TLS_PARAM_ID_SOFTAP_PSK, (void *)&apsta_psk, (bool)update_flash);
1157 
1158     return 0;
1159 }
1160 
tls_cmd_get_softap_ssid(struct tls_cmd_ssid_t * ssid)1161 int tls_cmd_get_softap_ssid(struct tls_cmd_ssid_t *ssid)
1162 {
1163     struct tls_param_ssid params_ssid;
1164 
1165     tls_param_get(TLS_PARAM_ID_SOFTAP_SSID, (void *)&params_ssid, 1);
1166     if (params_ssid.ssid_len > THIRTY_TWO) {
1167         ssid->ssid_len = 0;
1168         params_ssid.ssid[0] = '\0';
1169     } else {
1170         ssid->ssid_len = params_ssid.ssid_len;
1171         MEMCPY(ssid->ssid, params_ssid.ssid, ssid->ssid_len);
1172     }
1173     return 0;
1174 }
1175 
tls_cmd_set_softap_key(struct tls_cmd_key_t * key,u8 update_flash)1176 int tls_cmd_set_softap_key(struct tls_cmd_key_t *key, u8 update_flash)
1177 {
1178     struct tls_param_key param_key;
1179     struct tls_param_sha1* sha1_key;
1180 
1181     MEMCPY(param_key.psk, key->key, SIXTY_FOUR);
1182     param_key.key_format = key->format;
1183     param_key.key_index = key->index;
1184     param_key.key_length = key->key_len;
1185     tls_param_set(TLS_PARAM_ID_SOFTAP_KEY, (void *)&param_key, (bool)update_flash);
1186 
1187     sha1_key = (struct tls_param_sha1*)&param_key;
1188     memset((u8*)sha1_key, 0, sizeof(struct tls_param_sha1));
1189     tls_param_set(TLS_PARAM_ID_SOFTAP_PSK, (void *)sha1_key, TRUE);
1190 
1191     return 0;
1192 }
1193 
tls_cmd_get_softap_key(struct tls_cmd_key_t * key)1194 int tls_cmd_get_softap_key(struct tls_cmd_key_t *key)
1195 {
1196     struct tls_param_key *param_key;
1197 
1198     param_key = tls_mem_alloc(sizeof(struct tls_cmd_key_t));
1199     if (!param_key)
1200         return -1;
1201 
1202     memset(param_key, 0, sizeof(struct tls_cmd_key_t));
1203     tls_param_get(TLS_PARAM_ID_SOFTAP_KEY, (void *)param_key, 1);
1204 
1205     key->index = param_key->key_index;
1206     key->key_len = param_key->key_length;
1207     key->format = param_key->key_format;
1208     MEMCPY(key->key, param_key->psk, SIXTY_FOUR);
1209 
1210     tls_mem_free(param_key);
1211 
1212     return 0;
1213 }
1214 
tls_cmd_set_softap_encrypt(u8 encrypt,u8 update_flash)1215 int tls_cmd_set_softap_encrypt(u8 encrypt, u8 update_flash)
1216 {
1217     struct tls_param_key param_key;
1218 
1219     if (encrypt == 0) {
1220         memset(param_key.psk, 0, SIXTY_FOUR);
1221         param_key.key_format = 0;
1222         param_key.key_index = 0;
1223         param_key.key_length = 0;
1224         tls_param_set(TLS_PARAM_ID_SOFTAP_KEY, (void *)&param_key, (bool)update_flash);
1225     }
1226 
1227     tls_param_set(TLS_PARAM_ID_SOFTAP_ENCRY, (void *)&encrypt, (bool)update_flash);
1228     return 0;
1229 }
1230 
tls_cmd_get_softap_encrypt(u8 * encrypt)1231 int tls_cmd_get_softap_encrypt(u8 *encrypt)
1232 {
1233     tls_param_get(TLS_PARAM_ID_SOFTAP_ENCRY, (void *)encrypt, (bool)0);
1234     return 0;
1235 }
1236 
tls_cmd_get_softap_channel(u8 * channel)1237 int tls_cmd_get_softap_channel(u8 *channel)
1238 {
1239     tls_param_get(TLS_PARAM_ID_SOFTAP_CHANNEL, (void *)channel, (bool)0);
1240     return 0;
1241 }
1242 
tls_cmd_set_softap_channel(u8 channel,u8 update_flash)1243 int tls_cmd_set_softap_channel(u8 channel, u8 update_flash)
1244 {
1245     if (channel > FOURTEEN)
1246         return -1;
1247 
1248     tls_param_set(TLS_PARAM_ID_SOFTAP_CHANNEL, (void *)&channel, (bool)update_flash);
1249 
1250     return 0;
1251 }
1252 
1253 /*
1254 * 0: 11B/G
1255 * 1: 11B
1256 * 2: 11B/G/N
1257 */
tls_cmd_set_softap_hw_mode(struct tls_cmd_wl_hw_mode_t * hw_mode,u8 update_flash)1258 int tls_cmd_set_softap_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode, u8 update_flash)
1259 {
1260     struct tls_param_bgr bgr;
1261 
1262 #if TLS_CONFIG_SOFTAP_11N
1263     if (hw_mode->hw_mode > TWO)
1264 #else
1265     if (hw_mode->hw_mode > 1) /* wangm:  bg */
1266 #endif
1267         return -1;
1268 
1269     if ((hw_mode->hw_mode == 1) && (hw_mode->max_rate > THREE)) {
1270         return -1;
1271     }
1272 
1273     bgr.bg = hw_mode->hw_mode;
1274     bgr.max_rate = hw_mode->max_rate;
1275     tls_param_set(TLS_PARAM_ID_SOFTAP_WBGR, (void *)&bgr, (bool)update_flash);
1276 
1277     return 0;
1278 }
1279 
tls_cmd_get_softap_hw_mode(struct tls_cmd_wl_hw_mode_t * hw_mode)1280 int tls_cmd_get_softap_hw_mode(struct tls_cmd_wl_hw_mode_t *hw_mode)
1281 {
1282     struct tls_param_bgr bgr;
1283 
1284     tls_param_get(TLS_PARAM_ID_SOFTAP_WBGR, (void *)&bgr, (bool)0);
1285     hw_mode->hw_mode = bgr.bg;
1286     hw_mode->max_rate = bgr.max_rate;
1287 
1288     return 0;
1289 }
1290 
tls_cmd_get_softap_ip_info(struct tls_cmd_ip_params_t * params)1291 int tls_cmd_get_softap_ip_info(struct tls_cmd_ip_params_t *params)
1292 {
1293     struct tls_param_ip ip_param;
1294     tls_param_get(TLS_PARAM_ID_SOFTAP_IP, &ip_param, FALSE);
1295 
1296     MEMCPY(params->ip_addr, (char *)ip_param.ip, FOUR);
1297     MEMCPY(params->netmask, (char *)ip_param.netmask, FOUR);
1298     MEMCPY(params->gateway, (char *)ip_param.gateway, FOUR);
1299     MEMCPY(params->dns, (char *)ip_param.dns1, FOUR);
1300     params->type = ip_param.dhcp_enable;
1301 
1302     return 0;
1303 }
1304 
tls_cmd_set_softap_ip_info(struct tls_cmd_ip_params_t * params,u8 update_flash)1305 int tls_cmd_set_softap_ip_info(struct tls_cmd_ip_params_t *params, u8 update_flash)
1306 {
1307     struct tls_param_ip param_ip;
1308 
1309     /* update flash params */
1310     param_ip.dhcp_enable = params->type;
1311     MEMCPY((char *)param_ip.dns1, &params->dns, FOUR);
1312     MEMCPY((char *)param_ip.dns2, param_ip.dns2, FOUR);
1313     MEMCPY((char *)param_ip.gateway, &params->gateway, FOUR);
1314     MEMCPY((char *)param_ip.ip, &params->ip_addr, FOUR);
1315     MEMCPY((char *)param_ip.netmask, &params->netmask, FOUR);
1316     tls_param_set(TLS_PARAM_ID_SOFTAP_IP, (void *)&param_ip, (bool)update_flash);
1317 
1318     return 0;
1319 }
1320 
tls_cmd_get_softap_link_status(struct tls_cmd_link_status_t * lks)1321 int tls_cmd_get_softap_link_status(struct tls_cmd_link_status_t *lks)
1322 {
1323     return 0;
1324 }
1325 
tls_cmd_get_sta_detail(u32 * sta_num,u8 * buf)1326 int tls_cmd_get_sta_detail(u32 *sta_num, u8 *buf)
1327 {
1328     return 0;
1329 }
1330 #endif
1331 #endif /* TLS_CONFIG_HOSTIF */
1332