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_supplicant.h"
17 #include "serial.h"
18 #include "wifi_hal_sta_interface.h"
19 #include "wifi_hal_define.h"
20
RpcStartSupplicant(RpcServer * server,Context * context)21 int RpcStartSupplicant(RpcServer *server, Context *context)
22 {
23 if (server == NULL || context == NULL) {
24 return HAL_FAILURE;
25 }
26 WifiErrorNo err = StartSupplicant();
27 WriteBegin(context, 0);
28 WriteInt(context, err);
29 WriteEnd(context);
30 return HAL_SUCCESS;
31 }
32
RpcStopSupplicant(RpcServer * server,Context * context)33 int RpcStopSupplicant(RpcServer *server, Context *context)
34 {
35 if (server == NULL || context == NULL) {
36 return HAL_FAILURE;
37 }
38 WifiErrorNo err = StopSupplicant();
39 WriteBegin(context, 0);
40 WriteInt(context, err);
41 WriteEnd(context);
42 return HAL_SUCCESS;
43 }
44
RpcConnectSupplicant(RpcServer * server,Context * context)45 int RpcConnectSupplicant(RpcServer *server, Context *context)
46 {
47 if (server == NULL || context == NULL) {
48 return HAL_FAILURE;
49 }
50 WifiErrorNo err = ConnectSupplicant();
51 WriteBegin(context, 0);
52 WriteInt(context, err);
53 WriteEnd(context);
54 return HAL_SUCCESS;
55 }
56
RpcDisconnectSupplicant(RpcServer * server,Context * context)57 int RpcDisconnectSupplicant(RpcServer *server, Context *context)
58 {
59 if (server == NULL || context == NULL) {
60 return HAL_FAILURE;
61 }
62 WifiErrorNo err = DisconnectSupplicant();
63 WriteBegin(context, 0);
64 WriteInt(context, err);
65 WriteEnd(context);
66 return HAL_SUCCESS;
67 }
68
RpcRequestToSupplicant(RpcServer * server,Context * context)69 int RpcRequestToSupplicant(RpcServer *server, Context *context)
70 {
71 if (server == NULL || context == NULL) {
72 return HAL_FAILURE;
73 }
74 int maxSize = 0;
75 if (ReadInt(context, &maxSize) < 0 || maxSize < 0) {
76 return HAL_FAILURE;
77 }
78 int len = maxSize + 1;
79 unsigned char *buf = (unsigned char *)calloc(len, sizeof(unsigned char));
80 if (buf == NULL) {
81 return HAL_FAILURE;
82 }
83 if (ReadUStr(context, buf, len) != 0) {
84 free(buf);
85 buf = NULL;
86 return HAL_FAILURE;
87 }
88 WifiErrorNo err = RequestToSupplicant(buf, maxSize);
89 WriteBegin(context, 0);
90 WriteInt(context, err);
91 WriteEnd(context);
92 free(buf);
93 buf = NULL;
94 return HAL_SUCCESS;
95 }
96
RpcSetPowerSave(RpcServer * server,Context * context)97 int RpcSetPowerSave(RpcServer *server, Context *context)
98 {
99 if (server == NULL || context == NULL) {
100 return HAL_FAILURE;
101 }
102 int mode = 0;
103 if (ReadInt(context, &mode) < 0) {
104 return HAL_FAILURE;
105 }
106
107 WifiErrorNo err = SetPowerSave(mode);
108 WriteBegin(context, 0);
109 WriteInt(context, err);
110 WriteEnd(context);
111 return HAL_SUCCESS;
112 }
113
RpcWpaSetCountryCode(RpcServer * server,Context * context)114 int RpcWpaSetCountryCode(RpcServer *server, Context *context)
115 {
116 if (server == NULL || context == NULL) {
117 return HAL_FAILURE;
118 }
119 char countryCode[WIFI_COUNTRY_CODE_MAXLEN + 1] = {0};
120 if (ReadStr(context, countryCode, sizeof(countryCode)) != 0) {
121 return HAL_FAILURE;
122 }
123 WifiErrorNo err = WpaSetCountryCode(countryCode);
124 WriteBegin(context, 0);
125 WriteInt(context, err);
126 WriteEnd(context);
127 return HAL_SUCCESS;
128 }
129
RpcWpaGetCountryCode(RpcServer * server,Context * context)130 int RpcWpaGetCountryCode(RpcServer *server, Context *context)
131 {
132 if (server == NULL || context == NULL) {
133 return HAL_FAILURE;
134 }
135 char countryCode[WIFI_COUNTRY_CODE_MAXLEN + 1] = {0};
136 WifiErrorNo err = WpaGetCountryCode(countryCode, WIFI_COUNTRY_CODE_MAXLEN + 1);
137 WriteBegin(context, 0);
138 WriteInt(context, err);
139 if (err == WIFI_HAL_SUCCESS) {
140 WriteStr(context, countryCode);
141 }
142 WriteEnd(context);
143 return HAL_SUCCESS;
144 }
145