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