• 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_ap.h"
17 #include <securec.h>
18 #include "serial.h"
19 #include "wifi_hdi_ap_impl.h"
20 #include "wifi_hal_ap_interface.h"
21 #include "wifi_hal_define.h"
22 
RpcStartSoftAp(RpcServer * server,Context * context)23 int RpcStartSoftAp(RpcServer *server, Context *context)
24 {
25     if (server == NULL || context == NULL) {
26         return HAL_FAILURE;
27     }
28     int id = 0;
29     if (ReadInt(context, &id) < 0 || id < 0) {
30         return HAL_FAILURE;
31     }
32 
33     WifiErrorNo err = StartSoftAp(id);
34     WriteBegin(context, 0);
35     WriteInt(context, err);
36     WriteEnd(context);
37     return HAL_SUCCESS;
38 }
39 
RpcStopSoftAp(RpcServer * server,Context * context)40 int RpcStopSoftAp(RpcServer *server, Context *context)
41 {
42     if (server == NULL || context == NULL) {
43         return HAL_FAILURE;
44     }
45     int id = 0;
46     if (ReadInt(context, &id) < 0 || id < 0) {
47         return HAL_FAILURE;
48     }
49 
50     WifiErrorNo err = StopSoftAp(id);
51     WriteBegin(context, 0);
52     WriteInt(context, err);
53     WriteEnd(context);
54     return HAL_SUCCESS;
55 }
56 
RpcSetHostapdConfig(RpcServer * server,Context * context)57 int RpcSetHostapdConfig(RpcServer *server, Context *context)
58 {
59     if (server == NULL || context == NULL) {
60         return HAL_FAILURE;
61     }
62     int id = 0;
63     HostapdConfig config;
64     if (memset_s(&config, sizeof(config), 0, sizeof(config)) != EOK) {
65         return HAL_FAILURE;
66     }
67 
68     if (ReadStr(context, config.ssid, sizeof(config.ssid)) != 0 || ReadInt(context, &config.ssidLen) < 0 ||
69         ReadStr(context, config.preSharedKey, sizeof(config.preSharedKey)) != 0 ||
70         ReadInt(context, &config.preSharedKeyLen) < 0 || ReadInt(context, &config.securityType) < 0 ||
71         ReadInt(context, &config.band) < 0 || ReadInt(context, &config.channel) < 0 ||
72         ReadInt(context, &config.maxConn) < 0 || ReadInt(context, &id) < 0 || id < 0) {
73         return HAL_FAILURE;
74     }
75     WifiErrorNo err = SetHostapdConfig(&config, id);
76     WriteBegin(context, 0);
77     WriteInt(context, err);
78     WriteEnd(context);
79     return HAL_SUCCESS;
80 }
81 
RpcGetStaInfos(RpcServer * server,Context * context)82 int RpcGetStaInfos(RpcServer *server, Context *context)
83 {
84     if (server == NULL || context == NULL) {
85         return HAL_FAILURE;
86     }
87     int maxSize = 0;
88     int id = 0;
89     if (ReadInt(context, &maxSize) < 0 || maxSize <= 0 || ReadInt(context, &id) < 0 || id < 0) {
90         return HAL_FAILURE;
91     }
92     char *infos = (char *)calloc(maxSize, sizeof(char));
93     if (infos == NULL) {
94         return HAL_FAILURE;
95     }
96     WifiErrorNo err = GetStaInfos(infos, &maxSize, id);
97     WriteBegin(context, 0);
98     WriteInt(context, err);
99     if (err == WIFI_HAL_SUCCESS) {
100         WriteInt(context, maxSize);
101         WriteStr(context, infos);
102     }
103     WriteEnd(context);
104     free(infos);
105     infos = NULL;
106     return HAL_SUCCESS;
107 }
108 
RpcSetCountryCode(RpcServer * server,Context * context)109 int RpcSetCountryCode(RpcServer *server, Context *context)
110 {
111     if (server == NULL || context == NULL) {
112         return HAL_FAILURE;
113     }
114     char countryCode[WIFI_COUNTRY_CODE_MAXLEN + 1] = {0};
115     int id = 0;
116     if (ReadStr(context, countryCode, sizeof(countryCode)) != 0 || ReadInt(context, &id) < 0 || id < 0) {
117         return HAL_FAILURE;
118     }
119     WifiErrorNo err = SetCountryCode(countryCode, id);
120     WriteBegin(context, 0);
121     WriteInt(context, err);
122     WriteEnd(context);
123     return HAL_SUCCESS;
124 }
125 
RpcSetMacFilter(RpcServer * server,Context * context)126 int RpcSetMacFilter(RpcServer *server, Context *context)
127 {
128     if (server == NULL || context == NULL) {
129         return HAL_FAILURE;
130     }
131     int lenMac = 0;
132     int id = 0;
133     if (ReadInt(context, &lenMac) < 0 || lenMac <= 0) {
134         return HAL_FAILURE;
135     }
136     int len = lenMac + 1;
137     unsigned char *mac = (unsigned char *)calloc(len, sizeof(unsigned char));
138     if (mac == NULL) {
139         return HAL_FAILURE;
140     }
141     if (ReadUStr(context, mac, len) != 0 || ReadInt(context, &id) < 0 || id < 0) {
142         free(mac);
143         mac = NULL;
144         return HAL_FAILURE;
145     }
146     WifiErrorNo err = SetMacFilter(mac, lenMac, id);
147     WriteBegin(context, 0);
148     WriteInt(context, err);
149     WriteEnd(context);
150     free(mac);
151     mac = NULL;
152     return HAL_SUCCESS;
153 }
154 
RpcDelMacFilter(RpcServer * server,Context * context)155 int RpcDelMacFilter(RpcServer *server, Context *context)
156 {
157     if (server == NULL || context == NULL) {
158         return HAL_FAILURE;
159     }
160     int lenMac = 0;
161     int id = 0;
162     if (ReadInt(context, &lenMac) < 0 || lenMac <= 0) {
163         return HAL_FAILURE;
164     }
165     int len = lenMac + 1;
166     unsigned char *mac = (unsigned char *)calloc(len, sizeof(unsigned char));
167     if (mac == NULL) {
168         return HAL_FAILURE;
169     }
170     if (ReadUStr(context, mac, len) != 0 || ReadInt(context, &id) < 0 || id < 0) {
171         free(mac);
172         mac = NULL;
173         return HAL_FAILURE;
174     }
175     WifiErrorNo err = DelMacFilter(mac, lenMac, id);
176     WriteBegin(context, 0);
177     WriteInt(context, err);
178     WriteEnd(context);
179     free(mac);
180     mac = NULL;
181     return HAL_SUCCESS;
182 }
183 
RpcDisassociateSta(RpcServer * server,Context * context)184 int RpcDisassociateSta(RpcServer *server, Context *context)
185 {
186     if (server == NULL || context == NULL) {
187         return HAL_FAILURE;
188     }
189     int lenMac = 0;
190     int id = 0;
191     if (ReadInt(context, &lenMac) < 0 || lenMac <= 0) {
192         return HAL_FAILURE;
193     }
194     int len = lenMac + 1;
195     unsigned char *mac = (unsigned char *)calloc(len, sizeof(unsigned char));
196     if (mac == NULL) {
197         return HAL_FAILURE;
198     }
199 
200     if (ReadUStr(context, mac, len) != 0 || ReadInt(context, &id) < 0 || id < 0) {
201         free(mac);
202         mac = NULL;
203         return HAL_FAILURE;
204     }
205     WifiErrorNo err = DisassociateSta(mac, lenMac, id);
206     WriteBegin(context, 0);
207     WriteInt(context, err);
208     WriteEnd(context);
209     free(mac);
210     mac = NULL;
211     return HAL_SUCCESS;
212 }
213 
RpcGetValidFrequenciesForBand(RpcServer * server,Context * context)214 int RpcGetValidFrequenciesForBand(RpcServer *server, Context *context)
215 {
216     if (server == NULL || context == NULL) {
217         return HAL_FAILURE;
218     }
219     int band = 0;
220     int size = 0;
221     int id = 0;
222     if (ReadInt(context, &band) < 0 || ReadInt(context, &size) < 0  ||
223         ReadInt(context, &id) < 0 || id < 0) {
224         return HAL_FAILURE;
225     }
226     if (size <= 0) {
227         return HAL_FAILURE;
228     }
229     int *frequencies = (int *)calloc(size, sizeof(int));
230     if (frequencies == NULL) {
231         return HAL_FAILURE;
232     }
233     WifiErrorNo err = GetValidFrequenciesForBand(band, frequencies, &size, id);
234     WriteBegin(context, 0);
235     WriteInt(context, err);
236     if (err == WIFI_HAL_SUCCESS) {
237         WriteInt(context, size);
238         for (int i = 0; i < size; ++i) {
239             WriteInt(context, frequencies[i]);
240         }
241     }
242     WriteEnd(context);
243     free(frequencies);
244     frequencies = NULL;
245     return HAL_SUCCESS;
246 }
247 
RpcSetPowerModel(RpcServer * server,Context * context)248 int RpcSetPowerModel(RpcServer *server, Context *context)
249 {
250     if (server == NULL || context == NULL) {
251         return HAL_FAILURE;
252     }
253     int mode = -1;
254     if (ReadInt(context, &mode) < 0) {
255         return HAL_FAILURE;
256     }
257     int id = 0;
258     if (ReadInt(context, &id) < 0) {
259         return HAL_FAILURE;
260     }
261     WifiErrorNo err = WifiSetPowerModel(mode, id);
262     WriteBegin(context, 0);
263     WriteInt(context, err);
264     WriteEnd(context);
265     return HAL_SUCCESS;
266 }
267 
RpcGetPowerModel(RpcServer * server,Context * context)268 int RpcGetPowerModel(RpcServer *server, Context *context)
269 {
270     if (server == NULL || context == NULL) {
271         return HAL_FAILURE;
272     }
273     int mode = -1;
274     int id = 0;
275     if (ReadInt(context, &id) < 0) {
276         return HAL_FAILURE;
277     }
278     WifiErrorNo err = WifiGetPowerModel(&mode, id);
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