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