• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * WPA Supplicant - Sta network Aidl interface
3  * Copyright (c) 2021, Google Inc. All rights reserved.
4  *
5  * This software may be distributed under the terms of the BSD license.
6  * See README for more details.
7  */
8 
9 #ifndef WPA_SUPPLICANT_AIDL_STA_NETWORK_H
10 #define WPA_SUPPLICANT_AIDL_STA_NETWORK_H
11 
12 #include <array>
13 #include <vector>
14 
15 #include <android-base/macros.h>
16 
17 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantStaNetwork.h>
18 #include <aidl/android/hardware/wifi/supplicant/EapMethod.h>
19 #include <aidl/android/hardware/wifi/supplicant/EapPhase2Method.h>
20 #include <aidl/android/hardware/wifi/supplicant/ISupplicantStaNetworkCallback.h>
21 #include <aidl/android/hardware/wifi/supplicant/NetworkRequestEapSimUmtsAuthParams.h>
22 #include <aidl/android/hardware/wifi/supplicant/NetworkResponseEapSimUmtsAuthParams.h>
23 #include <aidl/android/hardware/wifi/supplicant/SaeH2eMode.h>
24 #include <aidl/android/hardware/wifi/supplicant/DppConnectionKeys.h>
25 
26 extern "C"
27 {
28 #include "utils/common.h"
29 #include "utils/includes.h"
30 #include "config.h"
31 #include "wpa_supplicant_i.h"
32 #include "notify.h"
33 #include "eapol_supp/eapol_supp_sm.h"
34 #include "eap_peer/eap.h"
35 #include "rsn_supp/wpa.h"
36 }
37 
38 namespace aidl {
39 namespace android {
40 namespace hardware {
41 namespace wifi {
42 namespace supplicant {
43 
44 /**
45  * Implementation of StaNetwork aidl object. Each unique aidl
46  * object is used for control operations on a specific network
47  * controlled by wpa_supplicant.
48  */
49 class StaNetwork : public BnSupplicantStaNetwork
50 {
51 public:
52 	StaNetwork(
53 		struct wpa_global* wpa_global, const char ifname[], int network_id);
54 	~StaNetwork() override = default;
55 	// Refer to |StaIface::invalidate()|.
56 	void invalidate();
57 	bool isValid();
58 
59 	// Aidl methods exposed.
60   	::ndk::ScopedAStatus getId(int32_t* _aidl_return) override;
61 	::ndk::ScopedAStatus getInterfaceName(std::string* _aidl_return) override;
62 	::ndk::ScopedAStatus getType(IfaceType* _aidl_return) override;
63 	::ndk::ScopedAStatus registerCallback(
64 		const std::shared_ptr<ISupplicantStaNetworkCallback>& in_callback) override;
65 	::ndk::ScopedAStatus setSsid(const std::vector<uint8_t>& in_ssid) override;
66 	::ndk::ScopedAStatus setBssid(const std::vector<uint8_t>& in_bssid) override;
67 	::ndk::ScopedAStatus setDppKeys(const DppConnectionKeys& in_keys) override;
68 	::ndk::ScopedAStatus setScanSsid(bool in_enable) override;
69 	::ndk::ScopedAStatus setKeyMgmt(KeyMgmtMask in_keyMgmtMask) override;
70 	::ndk::ScopedAStatus setProto(ProtoMask in_protoMask) override;
71 	::ndk::ScopedAStatus setAuthAlg(AuthAlgMask in_authAlgMask) override;
72 	::ndk::ScopedAStatus setGroupCipher(GroupCipherMask in_groupCipherMask) override;
73 	::ndk::ScopedAStatus setPairwiseCipher(
74 		PairwiseCipherMask in_pairwiseCipherMask) override;
75 	::ndk::ScopedAStatus setPskPassphrase(const std::string& in_psk) override;
76 	::ndk::ScopedAStatus setPsk(const std::vector<uint8_t>& in_psk) override;
77 	::ndk::ScopedAStatus setWepKey(
78 		int32_t in_keyIdx, const std::vector<uint8_t>& in_wepKey) override;
79 	::ndk::ScopedAStatus setWepTxKeyIdx(int32_t in_keyIdx) override;
80 	::ndk::ScopedAStatus setRequirePmf(bool in_enable) override;
81 	::ndk::ScopedAStatus setEapMethod(EapMethod in_method) override;
82 	::ndk::ScopedAStatus setEapPhase2Method(EapPhase2Method in_method) override;
83 	::ndk::ScopedAStatus setEapIdentity(
84 		const std::vector<uint8_t>& in_identity) override;
85 	::ndk::ScopedAStatus setEapEncryptedImsiIdentity(
86 		const std::vector<uint8_t>& in_identity) override;
87 	::ndk::ScopedAStatus setEapAnonymousIdentity(
88 		const std::vector<uint8_t>& in_identity) override;
89 	::ndk::ScopedAStatus setEapPassword(
90 		const std::vector<uint8_t>& in_password) override;
91 	::ndk::ScopedAStatus setEapCACert(const std::string& in_path) override;
92 	::ndk::ScopedAStatus setEapCAPath(const std::string& in_path) override;
93 	::ndk::ScopedAStatus setEapClientCert(const std::string& in_path) override;
94 	::ndk::ScopedAStatus setEapPrivateKeyId(const std::string& in_id) override;
95 	::ndk::ScopedAStatus setEapSubjectMatch(const std::string& in_match) override;
96 	::ndk::ScopedAStatus setEapAltSubjectMatch(const std::string& in_match) override;
97 	::ndk::ScopedAStatus setEapEngine(bool in_enable) override;
98 	::ndk::ScopedAStatus setEapEngineID(const std::string& in_id) override;
99 	::ndk::ScopedAStatus setEapDomainSuffixMatch(
100 		const std::string& in_match) override;
101 	::ndk::ScopedAStatus setProactiveKeyCaching(bool in_enable) override;
102 	::ndk::ScopedAStatus setIdStr(const std::string& in_idStr) override;
103 	::ndk::ScopedAStatus setUpdateIdentifier(int32_t in_id) override;
104 	::ndk::ScopedAStatus setEdmg(bool in_enable) override;
105 	::ndk::ScopedAStatus getSsid(std::vector<uint8_t>* _aidl_return) override;
106 	::ndk::ScopedAStatus getBssid(std::vector<uint8_t>* _aidl_return) override;
107 	::ndk::ScopedAStatus getScanSsid(bool* _aidl_return) override;
108 	::ndk::ScopedAStatus getKeyMgmt(KeyMgmtMask* _aidl_return) override;
109 	::ndk::ScopedAStatus getProto(ProtoMask* _aidl_return) override;
110 	::ndk::ScopedAStatus getAuthAlg(AuthAlgMask* _aidl_return) override;
111 	::ndk::ScopedAStatus getGroupCipher(GroupCipherMask* _aidl_return) override;
112 	::ndk::ScopedAStatus getPairwiseCipher(PairwiseCipherMask* _aidl_return) override;
113 	::ndk::ScopedAStatus getPskPassphrase(std::string* _aidl_return) override;
114 	::ndk::ScopedAStatus getPsk(std::vector<uint8_t>* _aidl_return) override;
115 	::ndk::ScopedAStatus getSaePassword(std::string* _aidl_return) override;
116 	::ndk::ScopedAStatus getSaePasswordId(std::string* _aidl_return) override;
117 	::ndk::ScopedAStatus getWepKey(
118 		int32_t in_keyIdx, std::vector<uint8_t>* _aidl_return) override;
119 	::ndk::ScopedAStatus getWepTxKeyIdx(int32_t* _aidl_return) override;
120 	::ndk::ScopedAStatus getRequirePmf(bool* _aidl_return) override;
121 	::ndk::ScopedAStatus getEapMethod(EapMethod* _aidl_return) override;
122 	::ndk::ScopedAStatus getEapPhase2Method(EapPhase2Method* _aidl_return) override;
123 	::ndk::ScopedAStatus getEapIdentity(std::vector<uint8_t>* _aidl_return) override;
124 	::ndk::ScopedAStatus getEapAnonymousIdentity(
125 		std::vector<uint8_t>* _aidl_return) override;
126 	::ndk::ScopedAStatus getEapPassword(std::vector<uint8_t>* _aidl_return) override;
127 	::ndk::ScopedAStatus getEapCACert(std::string* _aidl_return) override;
128 	::ndk::ScopedAStatus getEapCAPath(std::string* _aidl_return) override;
129 	::ndk::ScopedAStatus getEapClientCert(std::string* _aidl_return) override;
130 	::ndk::ScopedAStatus getEapPrivateKeyId(std::string* _aidl_return) override;
131 	::ndk::ScopedAStatus getEapSubjectMatch(std::string* _aidl_return) override;
132 	::ndk::ScopedAStatus getEapAltSubjectMatch(std::string* _aidl_return) override;
133 	::ndk::ScopedAStatus getEapEngine(bool* _aidl_return) override;
134 	::ndk::ScopedAStatus getEapEngineId(std::string* _aidl_return) override;
135 	::ndk::ScopedAStatus getEapDomainSuffixMatch(std::string* _aidl_return) override;
136 	::ndk::ScopedAStatus getIdStr(std::string* _aidl_return) override;
137 	::ndk::ScopedAStatus getWpsNfcConfigurationToken(
138 		std::vector<uint8_t>* _aidl_return) override;
139 	::ndk::ScopedAStatus getEdmg(bool* _aidl_return) override;
140 	::ndk::ScopedAStatus enable(bool in_noConnect) override;
141 	::ndk::ScopedAStatus disable() override;
142 	::ndk::ScopedAStatus select() override;
143 	::ndk::ScopedAStatus sendNetworkEapSimGsmAuthResponse(
144 		const std::vector<NetworkResponseEapSimGsmAuthParams>& in_params) override;
145 	::ndk::ScopedAStatus sendNetworkEapSimGsmAuthFailure() override;
146 	::ndk::ScopedAStatus sendNetworkEapSimUmtsAuthResponse(
147 		const NetworkResponseEapSimUmtsAuthParams& in_params) override;
148 	::ndk::ScopedAStatus sendNetworkEapSimUmtsAutsResponse(
149 		const std::vector<uint8_t>& in_auts) override;
150 	::ndk::ScopedAStatus sendNetworkEapSimUmtsAuthFailure() override;
151 	::ndk::ScopedAStatus sendNetworkEapIdentityResponse(
152 		const std::vector<uint8_t>& in_identity,
153 		const std::vector<uint8_t>& in_encryptedIdentity) override;
154 	::ndk::ScopedAStatus setGroupMgmtCipher(
155 		GroupMgmtCipherMask in_groupMgmtCipherMask) override;
156 	::ndk::ScopedAStatus getGroupMgmtCipher(
157 		GroupMgmtCipherMask* _aidl_return) override;
158 	::ndk::ScopedAStatus enableTlsSuiteBEapPhase1Param(
159 		bool in_enable) override;
160 	::ndk::ScopedAStatus enableSuiteBEapOpenSslCiphers() override;
161 	::ndk::ScopedAStatus setSaePassword(
162 		const std::string& in_saePassword) override;
163 	::ndk::ScopedAStatus setSaePasswordId(
164 		const std::string& in_saePasswordId) override;
165 	::ndk::ScopedAStatus setOcsp(OcspType in_ocspType) override;
166 	::ndk::ScopedAStatus getOcsp(OcspType* _aidl_return) override;
167 	::ndk::ScopedAStatus setPmkCache(
168 		const std::vector<uint8_t>& in_serializedEntry) override;
169 	::ndk::ScopedAStatus setWapiCertSuite(const std::string& in_suite) override;
170 	::ndk::ScopedAStatus getWapiCertSuite(std::string* _aidl_return) override;
171 	::ndk::ScopedAStatus setEapErp(bool in_enable) override;
172 	::ndk::ScopedAStatus setSaeH2eMode(SaeH2eMode in_mode) override;
173 	::ndk::ScopedAStatus enableSaePkOnlyMode(bool in_enable) override;
174 	::ndk::ScopedAStatus setRoamingConsortiumSelection(
175 		const std::vector<uint8_t>& in_selectedRcoi) override;
176 
177 private:
178 	// Corresponding worker functions for the AIDL methods.
179 	std::pair<uint32_t, ndk::ScopedAStatus> getIdInternal();
180 	std::pair<std::string, ndk::ScopedAStatus> getInterfaceNameInternal();
181 	std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal();
182 	ndk::ScopedAStatus registerCallbackInternal(
183 		const std::shared_ptr<ISupplicantStaNetworkCallback>& callback);
184 	ndk::ScopedAStatus setSsidInternal(const std::vector<uint8_t>& ssid);
185 	ndk::ScopedAStatus setBssidInternal(const std::vector<uint8_t>& bssid);
186 	ndk::ScopedAStatus setDppKeysInternal(const DppConnectionKeys& keys);
187 	ndk::ScopedAStatus setScanSsidInternal(bool enable);
188 	ndk::ScopedAStatus setKeyMgmtInternal(
189 		KeyMgmtMask mask);
190 	ndk::ScopedAStatus setProtoInternal(
191 		ProtoMask mask);
192 	ndk::ScopedAStatus setAuthAlgInternal(
193 		AuthAlgMask mask);
194 	ndk::ScopedAStatus setGroupCipherInternal(
195 		GroupCipherMask mask);
196 	ndk::ScopedAStatus setPairwiseCipherInternal(
197 		PairwiseCipherMask mask);
198 	ndk::ScopedAStatus setPskPassphraseInternal(const std::string& psk);
199 	ndk::ScopedAStatus setPskInternal(const std::vector<uint8_t>& psk);
200 	ndk::ScopedAStatus setWepKeyInternal(
201 		uint32_t key_idx, const std::vector<uint8_t>& wep_key);
202 	ndk::ScopedAStatus setWepTxKeyIdxInternal(uint32_t key_idx);
203 	ndk::ScopedAStatus setRequirePmfInternal(bool enable);
204 	ndk::ScopedAStatus setEapMethodInternal(
205 		EapMethod method);
206 	ndk::ScopedAStatus setEapPhase2MethodInternal(
207 		EapPhase2Method method);
208 	ndk::ScopedAStatus setEapIdentityInternal(
209 		const std::vector<uint8_t>& identity);
210 	ndk::ScopedAStatus setEapEncryptedImsiIdentityInternal(
211 		const std::vector<uint8_t>& identity);
212 	ndk::ScopedAStatus setEapAnonymousIdentityInternal(
213 		const std::vector<uint8_t>& identity);
214 	ndk::ScopedAStatus setEapPasswordInternal(
215 		const std::vector<uint8_t>& password);
216 	ndk::ScopedAStatus setEapCACertInternal(const std::string& path);
217 	ndk::ScopedAStatus setEapCAPathInternal(const std::string& path);
218 	ndk::ScopedAStatus setEapClientCertInternal(const std::string& path);
219 	ndk::ScopedAStatus setEapPrivateKeyIdInternal(const std::string& id);
220 	ndk::ScopedAStatus setEapSubjectMatchInternal(const std::string& match);
221 	ndk::ScopedAStatus setEapAltSubjectMatchInternal(
222 		const std::string& match);
223 	ndk::ScopedAStatus setEapEngineInternal(bool enable);
224 	ndk::ScopedAStatus setEapEngineIDInternal(const std::string& id);
225 	ndk::ScopedAStatus setEapDomainSuffixMatchInternal(
226 		const std::string& match);
227 	ndk::ScopedAStatus setProactiveKeyCachingInternal(bool enable);
228 	ndk::ScopedAStatus setIdStrInternal(const std::string& id_str);
229 	ndk::ScopedAStatus setUpdateIdentifierInternal(uint32_t id);
230 	ndk::ScopedAStatus setEdmgInternal(bool enable);
231 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal();
232 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getBssidInternal();
233 	std::pair<bool, ndk::ScopedAStatus> getScanSsidInternal();
234 	std::pair<KeyMgmtMask, ndk::ScopedAStatus> getKeyMgmtInternal();
235 	std::pair<ProtoMask, ndk::ScopedAStatus> getProtoInternal();
236 	std::pair<AuthAlgMask, ndk::ScopedAStatus> getAuthAlgInternal();
237 	std::pair<GroupCipherMask, ndk::ScopedAStatus> getGroupCipherInternal();
238 	std::pair<PairwiseCipherMask, ndk::ScopedAStatus> getPairwiseCipherInternal();
239 	std::pair<std::string, ndk::ScopedAStatus> getPskPassphraseInternal();
240 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getPskInternal();
241 	std::pair<std::string, ndk::ScopedAStatus> getSaePasswordInternal();
242 	std::pair<std::string, ndk::ScopedAStatus> getSaePasswordIdInternal();
243 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getWepKeyInternal(
244 		uint32_t key_idx);
245 	std::pair<uint32_t, ndk::ScopedAStatus> getWepTxKeyIdxInternal();
246 	std::pair<bool, ndk::ScopedAStatus> getRequirePmfInternal();
247 	std::pair<EapMethod, ndk::ScopedAStatus> getEapMethodInternal();
248 	std::pair<EapPhase2Method, ndk::ScopedAStatus>
249 		getEapPhase2MethodInternal();
250 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
251 		getEapIdentityInternal();
252 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
253 		getEapAnonymousIdentityInternal();
254 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
255 		getEapPasswordInternal();
256 	std::pair<std::string, ndk::ScopedAStatus> getEapCACertInternal();
257 	std::pair<std::string, ndk::ScopedAStatus> getEapCAPathInternal();
258 	std::pair<std::string, ndk::ScopedAStatus> getEapClientCertInternal();
259 	std::pair<std::string, ndk::ScopedAStatus> getEapPrivateKeyIdInternal();
260 	std::pair<std::string, ndk::ScopedAStatus> getEapSubjectMatchInternal();
261 	std::pair<std::string, ndk::ScopedAStatus> getEapAltSubjectMatchInternal();
262 	std::pair<bool, ndk::ScopedAStatus> getEapEngineInternal();
263 	std::pair<std::string, ndk::ScopedAStatus> getEapEngineIdInternal();
264 	std::pair<std::string, ndk::ScopedAStatus> getEapDomainSuffixMatchInternal();
265 	std::pair<std::string, ndk::ScopedAStatus> getIdStrInternal();
266 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
267 		getWpsNfcConfigurationTokenInternal();
268 	std::pair<bool, ndk::ScopedAStatus> getEdmgInternal();
269 	ndk::ScopedAStatus enableInternal(bool no_connect);
270 	ndk::ScopedAStatus disableInternal();
271 	ndk::ScopedAStatus selectInternal();
272 	ndk::ScopedAStatus sendNetworkEapSimGsmAuthResponseInternal(
273 		const std::vector<NetworkResponseEapSimGsmAuthParams>&
274 		vec_params);
275 	ndk::ScopedAStatus sendNetworkEapSimGsmAuthFailureInternal();
276 	ndk::ScopedAStatus sendNetworkEapSimUmtsAuthResponseInternal(
277 		const NetworkResponseEapSimUmtsAuthParams& params);
278 	ndk::ScopedAStatus sendNetworkEapSimUmtsAutsResponseInternal(
279 		const std::vector<uint8_t>& auts);
280 	ndk::ScopedAStatus sendNetworkEapSimUmtsAuthFailureInternal();
281 	ndk::ScopedAStatus sendNetworkEapIdentityResponseInternal(
282 		const std::vector<uint8_t>& identity,
283 		const std::vector<uint8_t>& imsi_identity);
284 	ndk::ScopedAStatus enableTlsSuiteBEapPhase1ParamInternal(bool enable);
285 	ndk::ScopedAStatus enableSuiteBEapOpenSslCiphersInternal();
286 	ndk::ScopedAStatus setSaePasswordInternal(
287 		const std::string& sae_password);
288 	ndk::ScopedAStatus setSaePasswordIdInternal(
289 		const std::string& sae_password_id);
290 	ndk::ScopedAStatus setGroupMgmtCipherInternal(
291 		GroupMgmtCipherMask mask);
292 	std::pair<GroupMgmtCipherMask, ndk::ScopedAStatus>
293 		getGroupMgmtCipherInternal();
294 	ndk::ScopedAStatus setOcspInternal(OcspType ocspType);
295 	std::pair<OcspType, ndk::ScopedAStatus> getOcspInternal();
296 	ndk::ScopedAStatus setPmkCacheInternal(const std::vector<uint8_t>& serializedEntry);
297 	ndk::ScopedAStatus setWapiCertSuiteInternal(const std::string& suite);
298 	std::pair<std::string, ndk::ScopedAStatus> getWapiCertSuiteInternal();
299 	ndk::ScopedAStatus setWapiPskInternal(const std::vector<uint8_t>& psk);
300 	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getWapiPskInternal();
301 	ndk::ScopedAStatus setSaeH2eModeInternal(SaeH2eMode mode);
302 	ndk::ScopedAStatus enableSaePkOnlyModeInternal(bool enable);
303 	ndk::ScopedAStatus setRoamingConsortiumSelectionInternal(
304 		const std::vector<uint8_t>& selectedRcoi);
305 
306 	struct wpa_ssid* retrieveNetworkPtr();
307 	struct wpa_supplicant* retrieveIfacePtr();
308 	int isPskPassphraseValid(const std::string& psk);
309 	void resetInternalStateAfterParamsUpdate();
310 	int setStringFieldAndResetState(
311 		const char* value, uint8_t** to_update_field,
312 		const char* hexdump_prefix);
313 	int setStringFieldAndResetState(
314 		const char* value, char** to_update_field,
315 		const char* hexdump_prefix);
316 	int setStringKeyFieldAndResetState(
317 		const char* value, char** to_update_field,
318 		const char* hexdump_prefix);
319 	int setByteArrayFieldAndResetState(
320 		const uint8_t* value, const size_t value_len,
321 		uint8_t** to_update_field, size_t* to_update_field_len,
322 		const char* hexdump_prefix);
323 	int setByteArrayKeyFieldAndResetState(
324 		const uint8_t* value, const size_t value_len,
325 		uint8_t** to_update_field, size_t* to_update_field_len,
326 		const char* hexdump_prefix);
327 	void setFastTransitionKeyMgmt(uint32_t &key_mgmt_mask);
328 	void resetFastTransitionKeyMgmt(uint32_t &key_mgmt_mask);
329 	ndk::ScopedAStatus setEapErpInternal(bool enable);
330 	int setByteArrayField(
331 		const uint8_t* value, const size_t value_len,
332 		uint8_t** to_update_field, size_t* to_update_field_len,
333 		const char* hexdump_prefix, bool resetState);
334 
335 	// Reference to the global wpa_struct. This is assumed to be valid
336 	// for the lifetime of the process.
337 	struct wpa_global* wpa_global_;
338 	// Name of the iface this network belongs to.
339 	const std::string ifname_;
340 	// Id of the network this aidl object controls.
341 	const int network_id_;
342 	bool is_valid_;
343 
344 	DISALLOW_COPY_AND_ASSIGN(StaNetwork);
345 };
346 
347 }  // namespace supplicant
348 }  // namespace wifi
349 }  // namespace hardware
350 }  // namespace android
351 }  // namespace aidl
352 
353 #endif  // WPA_SUPPLICANT_AIDL_STA_NETWORK_H
354