• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_P2P_IFACE_H
11 #define WPA_SUPPLICANT_HIDL_P2P_IFACE_H
12 
13 #include <array>
14 #include <vector>
15 
16 #include <android-base/macros.h>
17 
18 #include <android/hardware/wifi/supplicant/1.4/ISupplicantP2pIface.h>
19 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pIfaceCallback.h>
20 #include <android/hardware/wifi/supplicant/1.0/ISupplicantP2pNetwork.h>
21 
22 extern "C"
23 {
24 #include "utils/common.h"
25 #include "utils/includes.h"
26 #include "p2p/p2p.h"
27 #include "p2p/p2p_i.h"
28 #include "p2p_supplicant.h"
29 #include "p2p_supplicant.h"
30 #include "config.h"
31 }
32 
33 #define P2P_MGMT_DEVICE_PREFIX       "p2p-dev-"
34 
35 namespace android {
36 namespace hardware {
37 namespace wifi {
38 namespace supplicant {
39 namespace V1_4 {
40 namespace implementation {
41 using V1_0::SupplicantNetworkId;
42 using V1_0::SupplicantStatus;
43 using V1_0::IfaceType;
44 using V1_0::ISupplicantP2pIfaceCallback;
45 using V1_0::ISupplicantP2pNetwork;
46 
47 /**
48  * Implementation of P2pIface hidl object. Each unique hidl
49  * object is used for control operations on a specific interface
50  * controlled by wpa_supplicant.
51  */
52 class P2pIface : public V1_4::ISupplicantP2pIface
53 {
54 public:
55 	P2pIface(struct wpa_global* wpa_global, const char ifname[]);
56 	~P2pIface() override = default;
57 	// Refer to |StaIface::invalidate()|.
58 	void invalidate();
59 	bool isValid();
60 
61 	// Hidl methods exposed.
62 	Return<void> getName(getName_cb _hidl_cb) override;
63 	Return<void> getType(getType_cb _hidl_cb) override;
64 	Return<void> addNetwork(addNetwork_cb _hidl_cb) override;
65 	Return<void> removeNetwork(
66 	    SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override;
67 	Return<void> getNetwork(
68 	    SupplicantNetworkId id, getNetwork_cb _hidl_cb) override;
69 	Return<void> listNetworks(listNetworks_cb _hidl_cb) override;
70 	Return<void> registerCallback(
71 	    const sp<ISupplicantP2pIfaceCallback>& callback,
72 	    registerCallback_cb _hidl_cb) override;
73 	Return<void> getDeviceAddress(getDeviceAddress_cb _hidl_cb) override;
74 	Return<void> setSsidPostfix(
75 	    const hidl_vec<uint8_t>& postfix,
76 	    setSsidPostfix_cb _hidl_cb) override;
77 	Return<void> setGroupIdle(
78 	    const hidl_string& group_ifname, uint32_t timeout_in_sec,
79 	    setGroupIdle_cb _hidl_cb) override;
80 	Return<void> setPowerSave(
81 	    const hidl_string& group_ifname, bool enable,
82 	    setPowerSave_cb _hidl_cb) override;
83 	Return<void> find(uint32_t timeout_in_sec, find_cb _hidl_cb) override;
84 	Return<void> stopFind(stopFind_cb _hidl_cb) override;
85 	Return<void> flush(flush_cb _hidl_cb) override;
86 	Return<void> connect(
87 	    const hidl_array<uint8_t, 6>& peer_address,
88 	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
89 	    const hidl_string& pre_selected_pin, bool join_existing_group,
90 	    bool persistent, uint32_t go_intent, connect_cb _hidl_cb) override;
91 	Return<void> cancelConnect(cancelConnect_cb _hidl_cb) override;
92 	Return<void> provisionDiscovery(
93 	    const hidl_array<uint8_t, 6>& peer_address,
94 	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
95 	    provisionDiscovery_cb _hidl_cb) override;
96 	Return<void> addGroup(
97 	    bool persistent, SupplicantNetworkId persistent_network_id,
98 	    addGroup_cb _hidl_cb) override;
99 	Return<void> removeGroup(
100 	    const hidl_string& group_ifname, removeGroup_cb _hidl_cb) override;
101 	Return<void> reject(
102 	    const hidl_array<uint8_t, 6>& peer_address,
103 	    reject_cb _hidl_cb) override;
104 	Return<void> invite(
105 	    const hidl_string& group_ifname,
106 	    const hidl_array<uint8_t, 6>& go_device_address,
107 	    const hidl_array<uint8_t, 6>& peer_address,
108 	    invite_cb _hidl_cb) override;
109 	Return<void> reinvoke(
110 	    SupplicantNetworkId persistent_network_id,
111 	    const hidl_array<uint8_t, 6>& peer_address,
112 	    reinvoke_cb _hidl_cb) override;
113 	Return<void> configureExtListen(
114 	    uint32_t period_in_millis, uint32_t interval_in_millis,
115 	    configureExtListen_cb _hidl_cb) override;
116 	Return<void> setListenChannel(
117 	    uint32_t channel, uint32_t operating_class,
118 	    setListenChannel_cb _hidl_cb) override;
119 	Return<void> setDisallowedFrequencies(
120 	    const hidl_vec<FreqRange>& ranges,
121 	    setDisallowedFrequencies_cb _hidl_cb) override;
122 	Return<void> getSsid(
123 	    const hidl_array<uint8_t, 6>& peer_address,
124 	    getSsid_cb _hidl_cb) override;
125 	Return<void> getGroupCapability(
126 	    const hidl_array<uint8_t, 6>& peer_address,
127 	    getGroupCapability_cb _hidl_cb) override;
128 	Return<void> addBonjourService(
129 	    const hidl_vec<uint8_t>& query, const hidl_vec<uint8_t>& response,
130 	    addBonjourService_cb _hidl_cb) override;
131 	Return<void> removeBonjourService(
132 	    const hidl_vec<uint8_t>& query,
133 	    removeBonjourService_cb _hidl_cb) override;
134 	Return<void> addUpnpService(
135 	    uint32_t version, const hidl_string& service_name,
136 	    addUpnpService_cb _hidl_cb) override;
137 	Return<void> removeUpnpService(
138 	    uint32_t version, const hidl_string& service_name,
139 	    removeUpnpService_cb _hidl_cb) override;
140 	Return<void> flushServices(flushServices_cb _hidl_cb) override;
141 	Return<void> requestServiceDiscovery(
142 	    const hidl_array<uint8_t, 6>& peer_address,
143 	    const hidl_vec<uint8_t>& query,
144 	    requestServiceDiscovery_cb _hidl_cb) override;
145 	Return<void> cancelServiceDiscovery(
146 	    uint64_t identifier, cancelServiceDiscovery_cb _hidl_cb) override;
147 	Return<void> setMiracastMode(
148 	    ISupplicantP2pIface::MiracastMode mode,
149 	    setMiracastMode_cb _hidl_cb) override;
150 	Return<void> startWpsPbc(
151 	    const hidl_string& groupIfName, const hidl_array<uint8_t, 6>& bssid,
152 	    startWpsPbc_cb _hidl_cb) override;
153 	Return<void> startWpsPinKeypad(
154 	    const hidl_string& groupIfName, const hidl_string& pin,
155 	    startWpsPinKeypad_cb _hidl_cb) override;
156 	Return<void> startWpsPinDisplay(
157 	    const hidl_string& groupIfName, const hidl_array<uint8_t, 6>& bssid,
158 	    startWpsPinDisplay_cb _hidl_cb) override;
159 	Return<void> cancelWps(
160 	    const hidl_string& groupIfName, cancelWps_cb _hidl_cb) override;
161 	Return<void> setWpsDeviceName(
162 	    const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override;
163 	Return<void> setWpsDeviceType(
164 	    const hidl_array<uint8_t, 8>& type,
165 	    setWpsDeviceType_cb _hidl_cb) override;
166 	Return<void> setWpsManufacturer(
167 	    const hidl_string& manufacturer,
168 	    setWpsManufacturer_cb _hidl_cb) override;
169 	Return<void> setWpsModelName(
170 	    const hidl_string& model_name,
171 	    setWpsModelName_cb _hidl_cb) override;
172 	Return<void> setWpsModelNumber(
173 	    const hidl_string& model_number,
174 	    setWpsModelNumber_cb _hidl_cb) override;
175 	Return<void> setWpsSerialNumber(
176 	    const hidl_string& serial_number,
177 	    setWpsSerialNumber_cb _hidl_cb) override;
178 	Return<void> setWpsConfigMethods(
179 	    uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override;
180 	Return<void> enableWfd(bool enable, enableWfd_cb _hidl_cb) override;
181 	Return<void> setWfdDeviceInfo(
182 	    const hidl_array<uint8_t, 6>& info,
183 	    setWfdDeviceInfo_cb _hidl_cb) override;
184 	Return<void> createNfcHandoverRequestMessage(
185 	    createNfcHandoverRequestMessage_cb _hidl_cb) override;
186 	Return<void> createNfcHandoverSelectMessage(
187 	    createNfcHandoverSelectMessage_cb _hidl_cb) override;
188 	Return<void> reportNfcHandoverResponse(
189 	    const hidl_vec<uint8_t>& request,
190 	    reportNfcHandoverResponse_cb _hidl_cb) override;
191 	Return<void> reportNfcHandoverInitiation(
192 	    const hidl_vec<uint8_t>& select,
193 	    reportNfcHandoverInitiation_cb _hidl_cb) override;
194 	Return<void> saveConfig(saveConfig_cb _hidl_cb) override;
195 	Return<void> addGroup_1_2(
196 	    const hidl_vec<uint8_t>& ssid, const hidl_string& passphrase,
197 	    bool persistent, uint32_t freq, const hidl_array<uint8_t, 6>& peer_address,
198 	    bool joinExistingGroup, addGroup_1_2_cb _hidl_cb) override;
199 	Return<void> setMacRandomization(
200 	    bool enable, setMacRandomization_cb _hidl_cb) override;
201 	Return<void> setEdmg(bool enable, setEdmg_cb _hidl_cb) override;
202 	Return<void> getEdmg(getEdmg_cb _hidl_cb) override;
203 	Return<void> registerCallback_1_4(
204 	    const sp<V1_4::ISupplicantP2pIfaceCallback>& callback,
205 	    registerCallback_1_4_cb _hidl_cb) override;
206 	Return<void> setWfdR2DeviceInfo(
207 	    const hidl_array<uint8_t, 4>& info,
208 	    setWfdR2DeviceInfo_cb _hidl_cb) override;
209 
210 private:
211 	// Corresponding worker functions for the HIDL methods.
212 	std::pair<SupplicantStatus, std::string> getNameInternal();
213 	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
214 	std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
215 	addNetworkInternal();
216 	SupplicantStatus removeNetworkInternal(SupplicantNetworkId id);
217 	std::pair<SupplicantStatus, sp<ISupplicantP2pNetwork>>
218 	getNetworkInternal(SupplicantNetworkId id);
219 	std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>>
220 	listNetworksInternal();
221 	SupplicantStatus registerCallbackInternal(
222 	    const sp<ISupplicantP2pIfaceCallback>& callback);
223 	std::pair<SupplicantStatus, std::array<uint8_t, 6>>
224 	getDeviceAddressInternal();
225 	SupplicantStatus setSsidPostfixInternal(
226 	    const std::vector<uint8_t>& postfix);
227 	SupplicantStatus setGroupIdleInternal(
228 	    const std::string& group_ifname, uint32_t timeout_in_sec);
229 	SupplicantStatus setPowerSaveInternal(
230 	    const std::string& group_ifname, bool enable);
231 	SupplicantStatus findInternal(uint32_t timeout_in_sec);
232 	SupplicantStatus stopFindInternal();
233 	SupplicantStatus flushInternal();
234 	std::pair<SupplicantStatus, std::string> connectInternal(
235 	    const std::array<uint8_t, 6>& peer_address,
236 	    ISupplicantP2pIface::WpsProvisionMethod provision_method,
237 	    const std::string& pre_selected_pin, bool join_existing_group,
238 	    bool persistent, uint32_t go_intent);
239 	SupplicantStatus cancelConnectInternal();
240 	SupplicantStatus provisionDiscoveryInternal(
241 	    const std::array<uint8_t, 6>& peer_address,
242 	    ISupplicantP2pIface::WpsProvisionMethod provision_method);
243 	SupplicantStatus addGroupInternal(
244 	    bool persistent, SupplicantNetworkId persistent_network_id);
245 	SupplicantStatus removeGroupInternal(const std::string& group_ifname);
246 	SupplicantStatus rejectInternal(
247 	    const std::array<uint8_t, 6>& peer_address);
248 	SupplicantStatus inviteInternal(
249 	    const std::string& group_ifname,
250 	    const std::array<uint8_t, 6>& go_device_address,
251 	    const std::array<uint8_t, 6>& peer_address);
252 	SupplicantStatus reinvokeInternal(
253 	    SupplicantNetworkId persistent_network_id,
254 	    const std::array<uint8_t, 6>& peer_address);
255 	SupplicantStatus configureExtListenInternal(
256 	    uint32_t period_in_millis, uint32_t interval_in_millis);
257 	SupplicantStatus setListenChannelInternal(
258 	    uint32_t channel, uint32_t operating_class);
259 	SupplicantStatus setDisallowedFrequenciesInternal(
260 	    const std::vector<FreqRange>& ranges);
261 	std::pair<SupplicantStatus, std::vector<uint8_t>> getSsidInternal(
262 	    const std::array<uint8_t, 6>& peer_address);
263 	std::pair<SupplicantStatus, uint32_t> getGroupCapabilityInternal(
264 	    const std::array<uint8_t, 6>& peer_address);
265 	SupplicantStatus addBonjourServiceInternal(
266 	    const std::vector<uint8_t>& query,
267 	    const std::vector<uint8_t>& response);
268 	SupplicantStatus removeBonjourServiceInternal(
269 	    const std::vector<uint8_t>& query);
270 	SupplicantStatus addUpnpServiceInternal(
271 	    uint32_t version, const std::string& service_name);
272 	SupplicantStatus removeUpnpServiceInternal(
273 	    uint32_t version, const std::string& service_name);
274 	SupplicantStatus flushServicesInternal();
275 	std::pair<SupplicantStatus, uint64_t> requestServiceDiscoveryInternal(
276 	    const std::array<uint8_t, 6>& peer_address,
277 	    const std::vector<uint8_t>& query);
278 	SupplicantStatus cancelServiceDiscoveryInternal(uint64_t identifier);
279 	SupplicantStatus setMiracastModeInternal(
280 	    ISupplicantP2pIface::MiracastMode mode);
281 	SupplicantStatus startWpsPbcInternal(
282 	    const std::string& group_ifname,
283 	    const std::array<uint8_t, 6>& bssid);
284 	SupplicantStatus startWpsPinKeypadInternal(
285 	    const std::string& group_ifname, const std::string& pin);
286 	std::pair<SupplicantStatus, std::string> startWpsPinDisplayInternal(
287 	    const std::string& group_ifname,
288 	    const std::array<uint8_t, 6>& bssid);
289 	SupplicantStatus cancelWpsInternal(const std::string& group_ifname);
290 	SupplicantStatus setWpsDeviceNameInternal(const std::string& name);
291 	SupplicantStatus setWpsDeviceTypeInternal(
292 	    const std::array<uint8_t, 8>& type);
293 	SupplicantStatus setWpsManufacturerInternal(
294 	    const std::string& manufacturer);
295 	SupplicantStatus setWpsModelNameInternal(const std::string& model_name);
296 	SupplicantStatus setWpsModelNumberInternal(
297 	    const std::string& model_number);
298 	SupplicantStatus setWpsSerialNumberInternal(
299 	    const std::string& serial_number);
300 	SupplicantStatus setWpsConfigMethodsInternal(uint16_t config_methods);
301 	SupplicantStatus enableWfdInternal(bool enable);
302 	SupplicantStatus setWfdDeviceInfoInternal(
303 	    const std::array<uint8_t, 6>& info);
304 	std::pair<SupplicantStatus, std::vector<uint8_t>>
305 	createNfcHandoverRequestMessageInternal();
306 	std::pair<SupplicantStatus, std::vector<uint8_t>>
307 	createNfcHandoverSelectMessageInternal();
308 	SupplicantStatus reportNfcHandoverResponseInternal(
309 	    const std::vector<uint8_t>& request);
310 	SupplicantStatus reportNfcHandoverInitiationInternal(
311 	    const std::vector<uint8_t>& select);
312 	SupplicantStatus saveConfigInternal();
313 	SupplicantStatus addGroup_1_2Internal(
314 	    const std::vector<uint8_t>& ssid, const std::string& passphrase,
315 	    bool persistent, uint32_t freq, const std::array<uint8_t, 6>& peer_address,
316 	    bool joinExistingGroup);
317 	SupplicantStatus setMacRandomizationInternal(bool enable);
318 	V1_4::SupplicantStatus setEdmgInternal(bool enable);
319 	std::pair<V1_4::SupplicantStatus, bool> getEdmgInternal();
320 	V1_4::SupplicantStatus registerCallback_1_4Internal(
321 	    const sp<V1_4::ISupplicantP2pIfaceCallback>& callback);
322 	V1_4::SupplicantStatus setWfdR2DeviceInfoInternal(
323 	    const std::array<uint8_t, 4>& info);
324 
325 	struct wpa_supplicant* retrieveIfacePtr();
326 	struct wpa_supplicant* retrieveGroupIfacePtr(
327 	    const std::string& group_ifname);
328 
329 	// Reference to the global wpa_struct. This is assumed to be valid for
330 	// the lifetime of the process.
331 	struct wpa_global* wpa_global_;
332 	// Name of the iface this hidl object controls
333 	const std::string ifname_;
334 	bool is_valid_;
335 
336 	DISALLOW_COPY_AND_ASSIGN(P2pIface);
337 };
338 
339 }  // namespace implementation
340 }  // namespace V1_4
341 }  // namespace supplicant
342 }  // namespace wifi
343 }  // namespace hardware
344 }  // namespace android
345 
346 #endif  // WPA_SUPPLICANT_HIDL_P2P_IFACE_H
347