1 /*
2  * hidl interface for wpa_supplicant daemon
3  * Copyright (c) 2004-2016, Jouni Malinen <j@w1.fi>
4  * Copyright (c) 2004-2016, Roshan Pius <rpius@google.com>
5  *
6  * This software may be distributed under the terms of the BSD license.
7  * See README for more details.
8  */
9 
10 #ifndef WPA_SUPPLICANT_HIDL_STA_NETWORK_H
11 #define WPA_SUPPLICANT_HIDL_STA_NETWORK_H
12 
13 #include <array>
14 #include <vector>
15 
16 #include <android-base/macros.h>
17 
18 #include <android/hardware/wifi/supplicant/1.2/ISupplicantStaNetwork.h>
19 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h>
20 
21 extern "C"
22 {
23 #include "utils/common.h"
24 #include "utils/includes.h"
25 #include "config.h"
26 #include "wpa_supplicant_i.h"
27 #include "notify.h"
28 #include "eapol_supp/eapol_supp_sm.h"
29 #include "eap_peer/eap.h"
30 #include "rsn_supp/wpa.h"
31 }
32 
33 namespace android {
34 namespace hardware {
35 namespace wifi {
36 namespace supplicant {
37 namespace V1_2 {
38 namespace implementation {
39 using namespace android::hardware::wifi::supplicant::V1_0;
40 using namespace android::hardware::wifi::supplicant::V1_1;
41 
42 /**
43  * Implementation of StaNetwork hidl object. Each unique hidl
44  * object is used for control operations on a specific network
45  * controlled by wpa_supplicant.
46  */
47 class StaNetwork : public V1_2::ISupplicantStaNetwork
48 {
49 public:
50 	StaNetwork(
51 	    struct wpa_global* wpa_global, const char ifname[], int network_id);
52 	~StaNetwork() override = default;
53 	// Refer to |StaIface::invalidate()|.
54 	void invalidate();
55 	bool isValid();
56 
57 	// Hidl methods exposed.
58 	Return<void> getId(getId_cb _hidl_cb) override;
59 	Return<void> getInterfaceName(getInterfaceName_cb _hidl_cb) override;
60 	Return<void> getType(getType_cb _hidl_cb) override;
61 	Return<void> registerCallback(
62 	    const sp<ISupplicantStaNetworkCallback>& callback,
63 	    registerCallback_cb _hidl_cb) override;
64 	Return<void> setSsid(
65 	    const hidl_vec<uint8_t>& ssid, setSsid_cb _hidl_cb) override;
66 	Return<void> setBssid(
67 	    const hidl_array<uint8_t, 6>& bssid, setBssid_cb _hidl_cb) override;
68 	Return<void> setScanSsid(bool enable, setScanSsid_cb _hidl_cb) override;
69 	Return<void> setKeyMgmt(
70 	    uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb) override;
71 	Return<void> setProto(
72 	    uint32_t proto_mask, setProto_cb _hidl_cb) override;
73 	Return<void> setAuthAlg(
74 	    uint32_t auth_alg_mask, setAuthAlg_cb _hidl_cb) override;
75 	Return<void> setGroupCipher(
76 	    uint32_t group_cipher_mask, setGroupCipher_cb _hidl_cb) override;
77 	Return<void> setPairwiseCipher(
78 	    uint32_t pairwise_cipher_mask,
79 	    setPairwiseCipher_cb _hidl_cb) override;
80 	Return<void> setPskPassphrase(
81 	    const hidl_string& psk, setPskPassphrase_cb _hidl_cb) override;
82 	Return<void> setPsk(
83 	    const hidl_array<uint8_t, 32>& psk, setPsk_cb _hidl_cb) override;
84 	Return<void> setWepKey(
85 	    uint32_t key_idx, const hidl_vec<uint8_t>& wep_key,
86 	    setWepKey_cb _hidl_cb) override;
87 	Return<void> setWepTxKeyIdx(
88 	    uint32_t key_idx, setWepTxKeyIdx_cb _hidl_cb) override;
89 	Return<void> setRequirePmf(
90 	    bool enable, setRequirePmf_cb _hidl_cb) override;
91 	Return<void> setEapMethod(
92 	    ISupplicantStaNetwork::EapMethod method,
93 	    setEapMethod_cb _hidl_cb) override;
94 	Return<void> setEapPhase2Method(
95 	    ISupplicantStaNetwork::EapPhase2Method method,
96 	    setEapPhase2Method_cb _hidl_cb) override;
97 	Return<void> setEapIdentity(
98 	    const hidl_vec<uint8_t>& identity,
99 	    setEapIdentity_cb _hidl_cb) override;
100 	Return<void> setEapAnonymousIdentity(
101 	    const hidl_vec<uint8_t>& identity,
102 	    setEapAnonymousIdentity_cb _hidl_cb) override;
103 	Return<void> setEapPassword(
104 	    const hidl_vec<uint8_t>& password,
105 	    setEapPassword_cb _hidl_cb) override;
106 	Return<void> setEapCACert(
107 	    const hidl_string& path, setEapCACert_cb _hidl_cb) override;
108 	Return<void> setEapCAPath(
109 	    const hidl_string& path, setEapCAPath_cb _hidl_cb) override;
110 	Return<void> setEapClientCert(
111 	    const hidl_string& path, setEapClientCert_cb _hidl_cb) override;
112 	Return<void> setEapPrivateKeyId(
113 	    const hidl_string& id, setEapPrivateKeyId_cb _hidl_cb) override;
114 	Return<void> setEapEncryptedImsiIdentity(
115 	    const EapSimEncryptedIdentity& identity,
116 	    setEapEncryptedImsiIdentity_cb _hidl_cb) override;
117 	Return<void> setEapSubjectMatch(
118 	    const hidl_string& match, setEapSubjectMatch_cb _hidl_cb) override;
119 	Return<void> setEapAltSubjectMatch(
120 	    const hidl_string& match,
121 	    setEapAltSubjectMatch_cb _hidl_cb) override;
122 	Return<void> setEapEngine(
123 	    bool enable, setEapEngine_cb _hidl_cb) override;
124 	Return<void> setEapEngineID(
125 	    const hidl_string& id, setEapEngineID_cb _hidl_cb) override;
126 	Return<void> setEapDomainSuffixMatch(
127 	    const hidl_string& match,
128 	    setEapDomainSuffixMatch_cb _hidl_cb) override;
129 	Return<void> setProactiveKeyCaching(
130 	    bool enable, setProactiveKeyCaching_cb _hidl_cb) override;
131 	Return<void> setIdStr(
132 	    const hidl_string& id_str, setIdStr_cb _hidl_cb) override;
133 	Return<void> setUpdateIdentifier(
134 	    uint32_t id, setUpdateIdentifier_cb _hidl_cb) override;
135 	Return<void> getSsid(getSsid_cb _hidl_cb) override;
136 	Return<void> getBssid(getBssid_cb _hidl_cb) override;
137 	Return<void> getScanSsid(getScanSsid_cb _hidl_cb) override;
138 	Return<void> getKeyMgmt(getKeyMgmt_cb _hidl_cb) override;
139 	Return<void> getProto(getProto_cb _hidl_cb) override;
140 	Return<void> getAuthAlg(getAuthAlg_cb _hidl_cb) override;
141 	Return<void> getGroupCipher(getGroupCipher_cb _hidl_cb) override;
142 	Return<void> getPairwiseCipher(getPairwiseCipher_cb _hidl_cb) override;
143 	Return<void> getPskPassphrase(getPskPassphrase_cb _hidl_cb) override;
144 	Return<void> getPsk(getPsk_cb _hidl_cb) override;
145 	Return<void> getSaePassword(getSaePassword_cb _hidl_cb) override;
146 	Return<void> getSaePasswordId(getSaePasswordId_cb _hidl_cb) override;
147 	Return<void> getWepKey(
148 	    uint32_t key_idx, getWepKey_cb _hidl_cb) override;
149 	Return<void> getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb) override;
150 	Return<void> getRequirePmf(getRequirePmf_cb _hidl_cb) override;
151 	Return<void> getEapMethod(getEapMethod_cb _hidl_cb) override;
152 	Return<void> getEapPhase2Method(
153 	    getEapPhase2Method_cb _hidl_cb) override;
154 	Return<void> getEapIdentity(getEapIdentity_cb _hidl_cb) override;
155 	Return<void> getEapAnonymousIdentity(
156 	    getEapAnonymousIdentity_cb _hidl_cb) override;
157 	Return<void> getEapPassword(getEapPassword_cb _hidl_cb) override;
158 	Return<void> getEapCACert(getEapCACert_cb _hidl_cb) override;
159 	Return<void> getEapCAPath(getEapCAPath_cb _hidl_cb) override;
160 	Return<void> getEapClientCert(getEapClientCert_cb _hidl_cb) override;
161 	Return<void> getEapPrivateKeyId(
162 	    getEapPrivateKeyId_cb _hidl_cb) override;
163 	Return<void> getEapSubjectMatch(
164 	    getEapSubjectMatch_cb _hidl_cb) override;
165 	Return<void> getEapAltSubjectMatch(
166 	    getEapAltSubjectMatch_cb _hidl_cb) override;
167 	Return<void> getEapEngine(getEapEngine_cb _hidl_cb) override;
168 	Return<void> getEapEngineID(getEapEngineID_cb _hidl_cb) override;
169 	Return<void> getEapDomainSuffixMatch(
170 	    getEapDomainSuffixMatch_cb _hidl_cb) override;
171 	Return<void> getIdStr(getIdStr_cb _hidl_cb) override;
172 	Return<void> getWpsNfcConfigurationToken(
173 	    getWpsNfcConfigurationToken_cb _hidl_cb) override;
174 	Return<void> enable(bool no_connect, enable_cb _hidl_cb) override;
175 	Return<void> disable(disable_cb _hidl_cb) override;
176 	Return<void> select(select_cb _hidl_cb) override;
177 	Return<void> sendNetworkEapSimGsmAuthResponse(
178 	    const hidl_vec<
179 		ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>&
180 		vec_params,
181 	    sendNetworkEapSimGsmAuthResponse_cb _hidl_cb) override;
182 	Return<void> sendNetworkEapSimGsmAuthFailure(
183 	    sendNetworkEapSimGsmAuthFailure_cb _hidl_cb) override;
184 	Return<void> sendNetworkEapSimUmtsAuthResponse(
185 	    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams&
186 		params,
187 	    sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb) override;
188 	Return<void> sendNetworkEapSimUmtsAutsResponse(
189 	    const hidl_array<uint8_t, 14>& auts,
190 	    sendNetworkEapSimUmtsAutsResponse_cb _hidl_cb) override;
191 	Return<void> sendNetworkEapSimUmtsAuthFailure(
192 	    sendNetworkEapSimUmtsAuthFailure_cb _hidl_cb) override;
193 	Return<void> sendNetworkEapIdentityResponse(
194 	    const hidl_vec<uint8_t>& identity,
195 	    sendNetworkEapIdentityResponse_cb _hidl_cb) override;
196 	Return<void> sendNetworkEapIdentityResponse_1_1(
197 	    const EapSimIdentity& identity,
198 	    const EapSimEncryptedIdentity& imsiIdentity,
199 	    sendNetworkEapIdentityResponse_1_1_cb _hidl_cb) override;
200 	Return<void> setKeyMgmt_1_2(
201 	    uint32_t key_mgmt_mask, setKeyMgmt_1_2_cb _hidl_cb) override;
202 	Return<void> getKeyMgmt_1_2(getKeyMgmt_1_2_cb _hidl_cb) override;
203 	Return<void> setPairwiseCipher_1_2(
204 	    uint32_t pairwise_cipher_mask,
205 	    setPairwiseCipher_1_2_cb _hidl_cb) override;
206 	Return<void> getPairwiseCipher_1_2(
207 	    getPairwiseCipher_1_2_cb _hidl_cb) override;
208 	Return<void> setGroupCipher_1_2(
209 	    uint32_t group_cipher_mask,
210 	    setGroupCipher_1_2_cb _hidl_cb) override;
211 	Return<void> getGroupCipher_1_2(
212 	    getGroupCipher_1_2_cb _hidl_cb) override;
213 	Return<void> setGroupMgmtCipher(
214 	    uint32_t group_mgmt_cipher_mask,
215 	    setGroupMgmtCipher_cb _hidl_cb) override;
216 	Return<void> getGroupMgmtCipher(
217 	    getGroupMgmtCipher_cb _hidl_cb) override;
218 	Return<void> enableTlsSuiteBEapPhase1Param(
219 	    bool enable, enableTlsSuiteBEapPhase1Param_cb _hidl_cb) override;
220 	Return<void> enableSuiteBEapOpenSslCiphers(
221 	    enableSuiteBEapOpenSslCiphers_cb _hidl_cb) override;
222 	Return<void> setSaePassword(
223 	    const hidl_string& sae_password,
224 	    setSaePassword_cb _hidl_cb) override;
225 	Return<void> setSaePasswordId(
226 	    const hidl_string& sae_password_id,
227 	    setSaePasswordId_cb _hidl_cb) override;
228 
229 private:
230 	// Corresponding worker functions for the HIDL methods.
231 	std::pair<SupplicantStatus, uint32_t> getIdInternal();
232 	std::pair<SupplicantStatus, std::string> getInterfaceNameInternal();
233 	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
234 	SupplicantStatus registerCallbackInternal(
235 	    const sp<ISupplicantStaNetworkCallback>& callback);
236 	SupplicantStatus setSsidInternal(const std::vector<uint8_t>& ssid);
237 	SupplicantStatus setBssidInternal(const std::array<uint8_t, 6>& bssid);
238 	SupplicantStatus setScanSsidInternal(bool enable);
239 	SupplicantStatus setKeyMgmtInternal(uint32_t key_mgmt_mask);
240 	SupplicantStatus setProtoInternal(uint32_t proto_mask);
241 	SupplicantStatus setAuthAlgInternal(uint32_t auth_alg_mask);
242 	SupplicantStatus setGroupCipherInternal(uint32_t group_cipher_mask);
243 	SupplicantStatus setPairwiseCipherInternal(
244 	    uint32_t pairwise_cipher_mask);
245 	SupplicantStatus setPskPassphraseInternal(const std::string& psk);
246 	SupplicantStatus setPskInternal(const std::array<uint8_t, 32>& psk);
247 	SupplicantStatus setWepKeyInternal(
248 	    uint32_t key_idx, const std::vector<uint8_t>& wep_key);
249 	SupplicantStatus setWepTxKeyIdxInternal(uint32_t key_idx);
250 	SupplicantStatus setRequirePmfInternal(bool enable);
251 	SupplicantStatus setEapMethodInternal(
252 	    ISupplicantStaNetwork::EapMethod method);
253 	SupplicantStatus setEapPhase2MethodInternal(
254 	    ISupplicantStaNetwork::EapPhase2Method method);
255 	SupplicantStatus setEapIdentityInternal(
256 	    const std::vector<uint8_t>& identity);
257 	SupplicantStatus setEapEncryptedImsiIdentityInternal(
258 	    const std::vector<uint8_t>& identity);
259 	SupplicantStatus setEapAnonymousIdentityInternal(
260 	    const std::vector<uint8_t>& identity);
261 	SupplicantStatus setEapPasswordInternal(
262 	    const std::vector<uint8_t>& password);
263 	SupplicantStatus setEapCACertInternal(const std::string& path);
264 	SupplicantStatus setEapCAPathInternal(const std::string& path);
265 	SupplicantStatus setEapClientCertInternal(const std::string& path);
266 	SupplicantStatus setEapPrivateKeyIdInternal(const std::string& id);
267 	SupplicantStatus setEapSubjectMatchInternal(const std::string& match);
268 	SupplicantStatus setEapAltSubjectMatchInternal(
269 	    const std::string& match);
270 	SupplicantStatus setEapEngineInternal(bool enable);
271 	SupplicantStatus setEapEngineIDInternal(const std::string& id);
272 	SupplicantStatus setEapDomainSuffixMatchInternal(
273 	    const std::string& match);
274 	SupplicantStatus setProactiveKeyCachingInternal(bool enable);
275 	SupplicantStatus setIdStrInternal(const std::string& id_str);
276 	SupplicantStatus setUpdateIdentifierInternal(uint32_t id);
277 	std::pair<SupplicantStatus, std::vector<uint8_t>> getSsidInternal();
278 	std::pair<SupplicantStatus, std::array<uint8_t, 6>> getBssidInternal();
279 	std::pair<SupplicantStatus, bool> getScanSsidInternal();
280 	std::pair<SupplicantStatus, uint32_t> getKeyMgmtInternal();
281 	std::pair<SupplicantStatus, uint32_t> getProtoInternal();
282 	std::pair<SupplicantStatus, uint32_t> getAuthAlgInternal();
283 	std::pair<SupplicantStatus, uint32_t> getGroupCipherInternal();
284 	std::pair<SupplicantStatus, uint32_t> getPairwiseCipherInternal();
285 	std::pair<SupplicantStatus, std::string> getPskPassphraseInternal();
286 	std::pair<SupplicantStatus, std::array<uint8_t, 32>> getPskInternal();
287 	std::pair<SupplicantStatus, std::string> getSaePasswordInternal();
288 	std::pair<SupplicantStatus, std::string> getSaePasswordIdInternal();
289 	std::pair<SupplicantStatus, std::vector<uint8_t>> getWepKeyInternal(
290 	    uint32_t key_idx);
291 	std::pair<SupplicantStatus, uint32_t> getWepTxKeyIdxInternal();
292 	std::pair<SupplicantStatus, bool> getRequirePmfInternal();
293 	std::pair<SupplicantStatus, ISupplicantStaNetwork::EapMethod>
294 	getEapMethodInternal();
295 	std::pair<SupplicantStatus, ISupplicantStaNetwork::EapPhase2Method>
296 	getEapPhase2MethodInternal();
297 	std::pair<SupplicantStatus, std::vector<uint8_t>>
298 	getEapIdentityInternal();
299 	std::pair<SupplicantStatus, std::vector<uint8_t>>
300 	getEapAnonymousIdentityInternal();
301 	std::pair<SupplicantStatus, std::vector<uint8_t>>
302 	getEapPasswordInternal();
303 	std::pair<SupplicantStatus, std::string> getEapCACertInternal();
304 	std::pair<SupplicantStatus, std::string> getEapCAPathInternal();
305 	std::pair<SupplicantStatus, std::string> getEapClientCertInternal();
306 	std::pair<SupplicantStatus, std::string> getEapPrivateKeyIdInternal();
307 	std::pair<SupplicantStatus, std::string> getEapSubjectMatchInternal();
308 	std::pair<SupplicantStatus, std::string>
309 	getEapAltSubjectMatchInternal();
310 	std::pair<SupplicantStatus, bool> getEapEngineInternal();
311 	std::pair<SupplicantStatus, std::string> getEapEngineIDInternal();
312 	std::pair<SupplicantStatus, std::string>
313 	getEapDomainSuffixMatchInternal();
314 	std::pair<SupplicantStatus, std::string> getIdStrInternal();
315 	std::pair<SupplicantStatus, std::vector<uint8_t>>
316 	getWpsNfcConfigurationTokenInternal();
317 	SupplicantStatus enableInternal(bool no_connect);
318 	SupplicantStatus disableInternal();
319 	SupplicantStatus selectInternal();
320 	SupplicantStatus sendNetworkEapSimGsmAuthResponseInternal(
321 	    const std::vector<
322 		ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>&
323 		vec_params);
324 	SupplicantStatus sendNetworkEapSimGsmAuthFailureInternal();
325 	SupplicantStatus sendNetworkEapSimUmtsAuthResponseInternal(
326 	    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams&
327 		params);
328 	SupplicantStatus sendNetworkEapSimUmtsAutsResponseInternal(
329 	    const std::array<uint8_t, 14>& auts);
330 	SupplicantStatus sendNetworkEapSimUmtsAuthFailureInternal();
331 	SupplicantStatus sendNetworkEapIdentityResponseInternal(
332 	    const std::vector<uint8_t>& identity);
333 	SupplicantStatus sendNetworkEapIdentityResponseInternal_1_1(
334 	    const std::vector<uint8_t>& identity,
335 	    const std::vector<uint8_t>& imsi_identity);
336 	SupplicantStatus enableTlsSuiteBEapPhase1ParamInternal(bool enable);
337 	SupplicantStatus enableSuiteBEapOpenSslCiphersInternal();
338 	SupplicantStatus setSaePasswordInternal(
339 	    const std::string& sae_password);
340 	SupplicantStatus setSaePasswordIdInternal(
341 	    const std::string& sae_password_id);
342 	SupplicantStatus setGroupMgmtCipherInternal(uint32_t group_mgmt_cipher_mask);
343 	std::pair<SupplicantStatus, uint32_t> getGroupMgmtCipherInternal();
344 
345 	struct wpa_ssid* retrieveNetworkPtr();
346 	struct wpa_supplicant* retrieveIfacePtr();
347 	int isPskPassphraseValid(const std::string& psk);
348 	void resetInternalStateAfterParamsUpdate();
349 	int setStringFieldAndResetState(
350 	    const char* value, uint8_t** to_update_field,
351 	    const char* hexdump_prefix);
352 	int setStringFieldAndResetState(
353 	    const char* value, char** to_update_field,
354 	    const char* hexdump_prefix);
355 	int setStringKeyFieldAndResetState(
356 	    const char* value, char** to_update_field,
357 	    const char* hexdump_prefix);
358 	int setByteArrayFieldAndResetState(
359 	    const uint8_t* value, const size_t value_len,
360 	    uint8_t** to_update_field, size_t* to_update_field_len,
361 	    const char* hexdump_prefix);
362 	int setByteArrayKeyFieldAndResetState(
363 	    const uint8_t* value, const size_t value_len,
364 	    uint8_t** to_update_field, size_t* to_update_field_len,
365 	    const char* hexdump_prefix);
366 	void setFastTransitionKeyMgmt(uint32_t &key_mgmt_mask);
367 	void resetFastTransitionKeyMgmt(uint32_t &key_mgmt_mask);
368 
369 	// Reference to the global wpa_struct. This is assumed to be valid
370 	// for the lifetime of the process.
371 	struct wpa_global* wpa_global_;
372 	// Name of the iface this network belongs to.
373 	const std::string ifname_;
374 	// Id of the network this hidl object controls.
375 	const int network_id_;
376 	bool is_valid_;
377 
378 	DISALLOW_COPY_AND_ASSIGN(StaNetwork);
379 };
380 
381 }  // namespace implementation
382 }  // namespace V1_2
383 }  // namespace supplicant
384 }  // namespace wifi
385 }  // namespace hardware
386 }  // namespace android
387 
388 #endif  // WPA_SUPPLICANT_HIDL_STA_NETWORK_H
389