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