• 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 #include "wm_mem.h"
16 #if (GCC_COMPILE == 1)
17 #include "wm_cmdp_hostif_gcc.h"
18 #endif
19 #include "wm_wl_task.h"
20 #include "wm_rmms.h"
21 
22 #define TWO 2
23 #define THREE 3
24 #define FOUR 4
25 #define FIVE 5
26 #define SIX 6
27 #define EIGHT 8
28 #define SIXTEEN 16
29 #define TWENTY_FOUR 24
30 #define FIVE_HUNDRED_AND_TWELVE 512
31 
32 #if TLS_CONFIG_RMMS
33 
34 #ifdef  RMMS_DEBUG
35 #define RMMS_PRINT printf
36 #else
37 #define RMMS_PRINT(s, ...)
38 #endif
39 
40 static const u8 SysSuperPass[] = "^$#^%&";  /* Shift <643657> */
41 static struct udp_pcb *rmms_pcb = NULL;
42 
tls_proc_rmms(struct rmms_msg * msg)43 static void tls_proc_rmms(struct rmms_msg *msg)
44 {
45     int err;
46     struct tls_hostif *hif = tls_get_hostif();
47 
48     if (hif->rmms_status == 0) {
49         hif->rmms_status = 1;
50         err = tls_hostif_cmd_handler(HOSTIF_RMMS_AT_CMD, (char *)msg,
51                                      SIX + strlen((char *)(msg->CmdStr)));
52         if (err != 0) {
53             tls_mem_free(msg);
54             hif->rmms_status = 0;
55         }
56     }
57 
58     return;
59 }
60 
rmms_recv(void * arg,struct udp_pcb * pcb,struct pbuf * p,const ip_addr_t * addr,u16 port)61 static void rmms_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, const ip_addr_t *addr, u16 port)
62 {
63     return;
64 }
65 
RMMS_SendHedAtRsp(struct rmms_msg * Msg)66 void RMMS_SendHedAtRsp(struct rmms_msg *Msg)
67 {
68     int DataLen = 0;
69     struct pbuf *p;
70     ip_addr_t addr;
71     u16 port;
72 
73     addr.addr = Msg->SrcAddr[0] + (Msg->SrcAddr[1] << EIGHT) + (Msg->SrcAddr[TWO] << SIXTEEN)
74     + (Msg->SrcAddr[THREE] << TWENTY_FOUR);
75 
76     port = Msg->SrcAddr[FOUR] + (Msg->SrcAddr[FIVE] << EIGHT);
77     DataLen = strlen((char *)(Msg->CmdStr)) + 1;
78     p = pbuf_alloc(PBUF_TRANSPORT, DataLen, PBUF_RAM);
79     if (p != NULL) {
80         pbuf_take(p, Msg->CmdStr, DataLen);
81         udp_sendto(rmms_pcb, p, &addr, port);
82         pbuf_free(p);
83     }
84 
85     tls_mem_free(Msg);
86 
87     RMMS_PRINT("At response is sent to %s:%hu, %s\n\r", ip_ntoa(&addr), port, Msg->CmdStr);
88 
89     return;
90 }
91 
RMMS_Init(const struct netif * Netif)92 s8 RMMS_Init(const struct netif *Netif)
93 {
94     return RMMS_ERR_SUCCESS;
95 }
96 
RMMS_Fini(void)97 void RMMS_Fini(void)
98 {
99     if (rmms_pcb != NULL) {
100         udp_remove(rmms_pcb);
101         rmms_pcb = NULL;
102     }
103 
104     return;
105 }
106 #endif
107 
108