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