• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021-2022 Huawei Device Co., Ltd.
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 "wifi_hal_crpc_chip.h"
17 #include <securec.h>
18 #include "serial.h"
19 #include "wifi_hal_chip_interface.h"
20 #include "wifi_hal_define.h"
21 
RpcGetWifiChip(RpcServer * server,Context * context)22 int RpcGetWifiChip(RpcServer *server, Context *context)
23 {
24     if (server == NULL || context == NULL) {
25         return HAL_FAILURE;
26     }
27     int chipId = 0;
28     if (ReadInt(context, &chipId) < 0) {
29         return HAL_FAILURE;
30     }
31     WifiChip wifiChip;
32     if (memset_s(&wifiChip, sizeof(wifiChip), 0, sizeof(wifiChip)) != EOK) {
33         return HAL_FAILURE;
34     }
35     WifiErrorNo err = GetWifiChip(chipId, &wifiChip);
36     WriteBegin(context, 0);
37     WriteInt(context, err);
38     if (err == WIFI_HAL_SUCCESS) {
39         WriteInt(context, wifiChip.chip);
40     }
41     WriteEnd(context);
42     return HAL_SUCCESS;
43 }
44 
RpcGetWifiChipIds(RpcServer * server,Context * context)45 int RpcGetWifiChipIds(RpcServer *server, Context *context)
46 {
47     if (server == NULL || context == NULL) {
48         return HAL_FAILURE;
49     }
50     int maxSize = 0;
51     if (ReadInt(context, &maxSize) < 0) {
52         return HAL_FAILURE;
53     }
54     if (maxSize <= 0) {
55         return HAL_FAILURE;
56     }
57     uint8_t *chipIds = (uint8_t *)calloc(maxSize * sizeof(uint8_t), sizeof(uint8_t));
58     if (chipIds == NULL) {
59         return HAL_FAILURE;
60     }
61     WifiErrorNo err = GetWifiChipIds(chipIds, &maxSize);
62     WriteBegin(context, 0);
63     WriteInt(context, err);
64     if (err == WIFI_HAL_SUCCESS) {
65         WriteInt(context, maxSize);
66         for (int i = 0; i < maxSize; ++i) {
67             WriteInt(context, chipIds[i]);
68         }
69     }
70     WriteEnd(context);
71     free(chipIds);
72     chipIds = NULL;
73     return HAL_SUCCESS;
74 }
75 
RpcGetChipId(RpcServer * server,Context * context)76 int RpcGetChipId(RpcServer *server, Context *context)
77 {
78     if (server == NULL || context == NULL) {
79         return HAL_FAILURE;
80     }
81     int chipId = 0;
82     WifiErrorNo err = GetChipId(&chipId);
83     WriteBegin(context, 0);
84     WriteInt(context, err);
85     if (err == WIFI_HAL_SUCCESS) {
86         WriteInt(context, chipId);
87     }
88     WriteEnd(context);
89     return HAL_SUCCESS;
90 }
91 
RpcCreateIface(RpcServer * server,Context * context)92 int RpcCreateIface(RpcServer *server, Context *context)
93 {
94     if (server == NULL || context == NULL) {
95         return HAL_FAILURE;
96     }
97     int type = 0;
98     if (ReadInt(context, &type) < 0) {
99         return HAL_FAILURE;
100     }
101     WifiIface wifiIface;
102     if (memset_s(&wifiIface, sizeof(wifiIface), 0, sizeof(wifiIface)) != EOK) {
103         return HAL_FAILURE;
104     }
105     WifiErrorNo err = CreateIface(type, &wifiIface);
106     WriteBegin(context, 0);
107     WriteInt(context, err);
108     if (err == WIFI_HAL_SUCCESS) {
109         WriteInt(context, wifiIface.index);
110         WriteInt(context, wifiIface.type);
111         WriteStr(context, wifiIface.name);
112         WriteStr(context, wifiIface.macAddr);
113     }
114     WriteEnd(context);
115     return HAL_SUCCESS;
116 }
117 
RpcGetIface(RpcServer * server,Context * context)118 int RpcGetIface(RpcServer *server, Context *context)
119 {
120     if (server == NULL || context == NULL) {
121         return HAL_FAILURE;
122     }
123     WifiIface wifiIface;
124     if (memset_s(&wifiIface, sizeof(wifiIface), 0, sizeof(wifiIface)) != EOK) {
125         return HAL_FAILURE;
126     }
127     char ifname[WIFI_IFACE_NAME_MAXLEN] = {0};
128     char *pstr = NULL;
129     int ret = ReadStr(context, ifname, WIFI_IFACE_NAME_MAXLEN);
130     if (ret < 0) {
131         return HAL_FAILURE;
132     } else if (ret > 0) {
133         int len = ret + 1;
134         pstr = (char *)calloc(len, sizeof(char));
135         if (pstr == NULL) {
136             return HAL_FAILURE;
137         }
138         ReadStr(context, pstr, len);
139     }
140     WifiErrorNo err = GetIface((pstr == NULL) ? ifname : pstr, &wifiIface);
141     WriteBegin(context, 0);
142     WriteInt(context, err);
143     if (err == WIFI_HAL_SUCCESS) {
144         WriteInt(context, wifiIface.index);
145         WriteInt(context, wifiIface.type);
146         WriteStr(context, wifiIface.name);
147         WriteStr(context, wifiIface.macAddr);
148     }
149     WriteEnd(context);
150     if (pstr != NULL) {
151         free(pstr);
152         pstr = NULL;
153     }
154     return HAL_SUCCESS;
155 }
156 
RpcGetIfaceNames(RpcServer * server,Context * context)157 int RpcGetIfaceNames(RpcServer *server, Context *context)
158 {
159     if (server == NULL || context == NULL) {
160         return HAL_FAILURE;
161     }
162     int type = 0;
163     int size = 0;
164     if (ReadInt(context, &type) < 0 || ReadInt(context, &size) < 0 || size <= 0) {
165         return HAL_FAILURE;
166     }
167     char *ifname = (char *)calloc(size, sizeof(char));
168     if (ifname == NULL) {
169         return HAL_FAILURE;
170     }
171     WifiErrorNo err = GetIfaceNames(type, ifname, size);
172     WriteBegin(context, 0);
173     WriteInt(context, err);
174     if (err == WIFI_HAL_SUCCESS) {
175         WriteStr(context, ifname);
176     }
177     WriteEnd(context);
178     free(ifname);
179     ifname = NULL;
180     return HAL_SUCCESS;
181 }
182 
RpcRemoveIface(RpcServer * server,Context * context)183 int RpcRemoveIface(RpcServer *server, Context *context)
184 {
185     if (server == NULL || context == NULL) {
186         return HAL_FAILURE;
187     }
188     char ifname[WIFI_IFACE_NAME_MAXLEN] = {0};
189     char *pstr = NULL;
190     int ret = ReadStr(context, ifname, WIFI_IFACE_NAME_MAXLEN);
191     if (ret < 0) {
192         return HAL_FAILURE;
193     } else if (ret > 0) {
194         int len = ret + 1;
195         pstr = (char *)calloc(len, sizeof(char));
196         if (pstr == NULL) {
197             return HAL_FAILURE;
198         }
199         ReadStr(context, pstr, len);
200     }
201     WifiErrorNo err = RemoveIface((pstr == NULL) ? ifname : pstr);
202     WriteBegin(context, 0);
203     WriteInt(context, err);
204     WriteEnd(context);
205     if (pstr != NULL) {
206         free(pstr);
207         pstr = NULL;
208     }
209     return HAL_SUCCESS;
210 }
211 
RpcGetCapabilities(RpcServer * server,Context * context)212 int RpcGetCapabilities(RpcServer *server, Context *context)
213 {
214     if (server == NULL || context == NULL) {
215         return HAL_FAILURE;
216     }
217     uint32_t capabilities = 0;
218     WifiErrorNo err = GetCapabilities(&capabilities);
219     WriteBegin(context, 0);
220     WriteInt(context, err);
221     if (err == WIFI_HAL_SUCCESS) {
222         WriteInt(context, capabilities);
223     }
224     WriteEnd(context);
225     return HAL_SUCCESS;
226 }
227 
RpcGetSupportedComboModes(RpcServer * server,Context * context)228 int RpcGetSupportedComboModes(RpcServer *server, Context *context)
229 {
230     if (server == NULL || context == NULL) {
231         return HAL_FAILURE;
232     }
233     int maxSize = 0;
234     if (ReadInt(context, &maxSize) < 0 || maxSize <= 0) {
235         return HAL_FAILURE;
236     }
237     int *modes = (int *)calloc(maxSize, sizeof(int));
238     if (modes == NULL) {
239         return HAL_FAILURE;
240     }
241     WifiErrorNo err = GetSupportedComboModes(modes, &maxSize);
242     WriteBegin(context, 0);
243     WriteInt(context, err);
244     if (err == WIFI_HAL_SUCCESS) {
245         WriteInt(context, maxSize);
246         for (int i = 0; i < maxSize; ++i) {
247             WriteInt(context, modes[i]);
248         }
249     }
250     WriteEnd(context);
251     free(modes);
252     modes = NULL;
253     return HAL_SUCCESS;
254 }
255 
RpcConfigComboModes(RpcServer * server,Context * context)256 int RpcConfigComboModes(RpcServer *server, Context *context)
257 {
258     if (server == NULL || context == NULL) {
259         return HAL_FAILURE;
260     }
261     int mode = 0;
262     if (ReadInt(context, &mode) < 0) {
263         return HAL_FAILURE;
264     }
265     WifiErrorNo err = ConfigComboModes(mode);
266     WriteBegin(context, 0);
267     WriteInt(context, err);
268     WriteEnd(context);
269     return HAL_SUCCESS;
270 }
271 
RpcGetComboModes(RpcServer * server,Context * context)272 int RpcGetComboModes(RpcServer *server, Context *context)
273 {
274     if (server == NULL || context == NULL) {
275         return HAL_FAILURE;
276     }
277     int mode = 0;
278     WifiErrorNo err = GetComboModes(&mode);
279     WriteBegin(context, 0);
280     WriteInt(context, err);
281     if (err == WIFI_HAL_SUCCESS) {
282         WriteInt(context, mode);
283     }
284     WriteEnd(context);
285     return HAL_SUCCESS;
286 }
287 
RpcRequestFirmwareDebugDump(RpcServer * server,Context * context)288 int RpcRequestFirmwareDebugDump(RpcServer *server, Context *context)
289 {
290     if (server == NULL || context == NULL) {
291         return HAL_FAILURE;
292     }
293     int maxSize = 0;
294     if (ReadInt(context, &maxSize) < 0 || maxSize <= 0) {
295         return HAL_FAILURE;
296     }
297 
298     unsigned char *bytes = (unsigned char *)calloc(maxSize + 1, sizeof(unsigned char));
299     if (bytes == NULL) {
300         return HAL_FAILURE;
301     }
302 
303     WifiErrorNo err = RequestFirmwareDebugDump(bytes, &maxSize);
304     WriteBegin(context, 0);
305     WriteInt(context, err);
306     if (err == WIFI_HAL_SUCCESS) {
307         WriteInt(context, maxSize);
308         WriteUStr(context, bytes, maxSize);
309     }
310     WriteEnd(context);
311     free(bytes);
312     bytes = NULL;
313     return HAL_SUCCESS;
314 }
315 
RpcIsChipSupportDbdc(RpcServer * server,Context * context)316 int RpcIsChipSupportDbdc(RpcServer *server, Context *context)
317 {
318     if (server == NULL || context == NULL) {
319         return HAL_FAILURE;
320     }
321     int support = 0;
322     WifiErrorNo err = GetIsChipSupportDbdc(&support);
323     WriteBegin(context, 0);
324     WriteInt(context, err);
325     if (err == WIFI_HAL_SUCCESS) {
326         WriteInt(context, support);
327     }
328     WriteEnd(context);
329     return HAL_SUCCESS;
330 }
331 
RpcIsChipSupportCsa(RpcServer * server,Context * context)332 int RpcIsChipSupportCsa(RpcServer *server, Context *context)
333 {
334     if (server == NULL || context == NULL) {
335         return HAL_FAILURE;
336     }
337     int support = 0;
338     WifiErrorNo err = GetIsChipSupportCsa(&support);
339     WriteBegin(context, 0);
340     WriteInt(context, err);
341     if (err == WIFI_HAL_SUCCESS) {
342         WriteInt(context, support);
343     }
344     WriteEnd(context);
345     return HAL_SUCCESS;
346 }
347 
RpcIsChipSupportRadarDetect(RpcServer * server,Context * context)348 int RpcIsChipSupportRadarDetect(RpcServer *server, Context *context)
349 {
350     if (server == NULL || context == NULL) {
351         return HAL_FAILURE;
352     }
353     int support = 0;
354     WifiErrorNo err = GetIsChipSupportRadarDetect(&support);
355     WriteBegin(context, 0);
356     WriteInt(context, err);
357     if (err == WIFI_HAL_SUCCESS) {
358         WriteInt(context, support);
359     }
360     WriteEnd(context);
361     return HAL_SUCCESS;
362 }
363 
RpcIsChipSupportDfsChannel(RpcServer * server,Context * context)364 int RpcIsChipSupportDfsChannel(RpcServer *server, Context *context)
365 {
366     if (server == NULL || context == NULL) {
367         return HAL_FAILURE;
368     }
369     int support = 0;
370     WifiErrorNo err = GetIsChipSupportDfsChannel(&support);
371     WriteBegin(context, 0);
372     WriteInt(context, err);
373     if (err == WIFI_HAL_SUCCESS) {
374         WriteInt(context, support);
375     }
376     WriteEnd(context);
377     return HAL_SUCCESS;
378 }
379 
RpcIsChipSupportIndoorChannel(RpcServer * server,Context * context)380 int RpcIsChipSupportIndoorChannel(RpcServer *server, Context *context)
381 {
382     if (server == NULL || context == NULL) {
383         return HAL_FAILURE;
384     }
385     int support = 0;
386     WifiErrorNo err = GetIsChipSupportIndoorChannel(&support);
387     WriteBegin(context, 0);
388     WriteInt(context, err);
389     if (err == WIFI_HAL_SUCCESS) {
390         WriteInt(context, support);
391     }
392     WriteEnd(context);
393     return HAL_SUCCESS;
394 }