aboutsummaryrefslogtreecommitdiff
path: root/wpa_supplicant/aidl/p2p_iface.h
blob: c4f036c8228ca9840cc9960de567650d3c5dc07e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
/*
 * WPA Supplicant - P2P Iface Aidl interface
 * Copyright (c) 2021, Google Inc. All rights reserved.
 *
 * This software may be distributed under the terms of the BSD license.
 * See README for more details.
 */

#ifndef WPA_SUPPLICANT_AIDL_P2P_IFACE_H
#define WPA_SUPPLICANT_AIDL_P2P_IFACE_H

#include <array>
#include <vector>

#include <android-base/macros.h>

#include <aidl/android/hardware/wifi/supplicant/BnSupplicantP2pIface.h>
#include <aidl/android/hardware/wifi/supplicant/FreqRange.h>
#include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.h>
#include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pNetwork.h>
#include <aidl/android/hardware/wifi/supplicant/MiracastMode.h>
#include <aidl/android/hardware/wifi/supplicant/WpsProvisionMethod.h>

extern "C"
{
#include "utils/common.h"
#include "utils/includes.h"
#include "p2p/p2p.h"
#include "p2p/p2p_i.h"
#include "p2p_supplicant.h"
#include "p2p_supplicant.h"
#include "config.h"
}

#define P2P_MGMT_DEVICE_PREFIX	   "p2p-dev-"

namespace aidl {
namespace android {
namespace hardware {
namespace wifi {
namespace supplicant {

/**
 * Implementation of P2pIface aidl object. Each unique aidl
 * object is used for control operations on a specific interface
 * controlled by wpa_supplicant.
 */
class P2pIface : public BnSupplicantP2pIface
{
public:
	P2pIface(struct wpa_global* wpa_global, const char ifname[]);
	~P2pIface() override = default;
	// Refer to |StaIface::invalidate()|.
	void invalidate();
	bool isValid();

	// Aidl methods exposed.
	::ndk::ScopedAStatus getName(std::string* _aidl_return) override;
	::ndk::ScopedAStatus getType(IfaceType* _aidl_return) override;
	::ndk::ScopedAStatus addNetwork(
		std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override;
	::ndk::ScopedAStatus removeNetwork(int32_t in_id) override;
	::ndk::ScopedAStatus getNetwork(
		int32_t in_id, std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override;
	::ndk::ScopedAStatus listNetworks(std::vector<int32_t>* _aidl_return) override;
	::ndk::ScopedAStatus registerCallback(
		const std::shared_ptr<ISupplicantP2pIfaceCallback>& in_callback) override;
	::ndk::ScopedAStatus getDeviceAddress(std::vector<uint8_t>* _aidl_return) override;
	::ndk::ScopedAStatus setSsidPostfix(const std::vector<uint8_t>& in_postfix) override;
	::ndk::ScopedAStatus setGroupIdle(
		const std::string& in_groupIfName, int32_t in_timeoutInSec) override;
	::ndk::ScopedAStatus setPowerSave(
		const std::string& in_groupIfName, bool in_enable) override;
	::ndk::ScopedAStatus find(int32_t in_timeoutInSec) override;
	::ndk::ScopedAStatus stopFind() override;
	::ndk::ScopedAStatus flush() override;
	::ndk::ScopedAStatus connect(
		const std::vector<uint8_t>& in_peerAddress, WpsProvisionMethod in_provisionMethod,
		const std::string& in_preSelectedPin, bool in_joinExistingGroup,
		bool in_persistent, int32_t in_goIntent, std::string* _aidl_return) override;
	::ndk::ScopedAStatus cancelConnect() override;
	::ndk::ScopedAStatus provisionDiscovery(
		const std::vector<uint8_t>& in_peerAddress,
		WpsProvisionMethod in_provisionMethod) override;
	::ndk::ScopedAStatus addGroup(bool in_persistent, int32_t in_persistentNetworkId) override;
	::ndk::ScopedAStatus addGroupWithConfig(
		const std::vector<uint8_t>& in_ssid, const std::string& in_pskPassphrase,
		bool in_persistent, int32_t in_freq, const std::vector<uint8_t>& in_peerAddress,
		bool in_joinExistingGroup) override;
	::ndk::ScopedAStatus removeGroup(const std::string& in_groupIfName) override;
	::ndk::ScopedAStatus reject(const std::vector<uint8_t>& in_peerAddress) override;
	::ndk::ScopedAStatus invite(
		const std::string& in_groupIfName,
		const std::vector<uint8_t>& in_goDeviceAddress,
		const std::vector<uint8_t>& in_peerAddress) override;
	::ndk::ScopedAStatus reinvoke(
		int32_t in_persistentNetworkId,
		const std::vector<uint8_t>& in_peerAddress) override;
	::ndk::ScopedAStatus configureExtListen(
		int32_t in_periodInMillis, int32_t in_intervalInMillis) override;
	::ndk::ScopedAStatus setListenChannel(
		int32_t in_channel, int32_t in_operatingClass) override;
	::ndk::ScopedAStatus setDisallowedFrequencies(
		const std::vector<FreqRange>& in_ranges) override;
	::ndk::ScopedAStatus getSsid(
		const std::vector<uint8_t>& in_peerAddress,
		std::vector<uint8_t>* _aidl_return) override;
	::ndk::ScopedAStatus getGroupCapability(
		const std::vector<uint8_t>& in_peerAddress,
		P2pGroupCapabilityMask* _aidl_return) override;
	::ndk::ScopedAStatus addBonjourService(
		const std::vector<uint8_t>& in_query,
		const std::vector<uint8_t>& in_response) override;
	::ndk::ScopedAStatus removeBonjourService(
		const std::vector<uint8_t>& in_query) override;
	::ndk::ScopedAStatus addUpnpService(
		int32_t in_version, const std::string& in_serviceName) override;
	::ndk::ScopedAStatus removeUpnpService(
		int32_t in_version, const std::string& in_serviceName) override;
	::ndk::ScopedAStatus flushServices() override;
	::ndk::ScopedAStatus requestServiceDiscovery(
		const std::vector<uint8_t>& in_peerAddress,
		const std::vector<uint8_t>& in_query, int64_t* _aidl_return) override;
	::ndk::ScopedAStatus cancelServiceDiscovery(int64_t in_identifier) override;
	::ndk::ScopedAStatus setMiracastMode(MiracastMode in_mode) override;
	::ndk::ScopedAStatus startWpsPbc(
		const std::string& in_groupIfName,
		const std::vector<uint8_t>& in_bssid) override;
	::ndk::ScopedAStatus startWpsPinKeypad(
		const std::string& in_groupIfName, const std::string& in_pin) override;
	::ndk::ScopedAStatus startWpsPinDisplay(
		const std::string& in_groupIfName,
		const std::vector<uint8_t>& in_bssid,
		std::string* _aidl_return) override;
	::ndk::ScopedAStatus cancelWps(const std::string& in_groupIfName) override;
	::ndk::ScopedAStatus setWpsDeviceName(
		const std::string& in_name) override;
	::ndk::ScopedAStatus setWpsDeviceType(
		const std::vector<uint8_t>& in_type) override;
	::ndk::ScopedAStatus setWpsManufacturer(
		const std::string& in_manufacturer) override;
	::ndk::ScopedAStatus setWpsModelName(
		const std::string& in_modelName) override;
	::ndk::ScopedAStatus setWpsModelNumber(
		const std::string& in_modelNumber) override;
	::ndk::ScopedAStatus setWpsSerialNumber(
		const std::string& in_serialNumber) override;
	::ndk::ScopedAStatus setWpsConfigMethods(
		WpsConfigMethods in_configMethods) override;
	::ndk::ScopedAStatus enableWfd(bool in_enable) override;
	::ndk::ScopedAStatus setWfdDeviceInfo(
		const std::vector<uint8_t>& in_info) override;
	::ndk::ScopedAStatus createNfcHandoverRequestMessage(
		std::vector<uint8_t>* _aidl_return) override;
	::ndk::ScopedAStatus createNfcHandoverSelectMessage(
		std::vector<uint8_t>* _aidl_return) override;
	::ndk::ScopedAStatus reportNfcHandoverInitiation(
		const std::vector<uint8_t>& in_select) override;
	::ndk::ScopedAStatus reportNfcHandoverResponse(
		const std::vector<uint8_t>& in_request) override;
	::ndk::ScopedAStatus saveConfig() override;
	::ndk::ScopedAStatus setMacRandomization(bool in_enable) override;
	::ndk::ScopedAStatus setEdmg(bool in_enable) override;
	::ndk::ScopedAStatus getEdmg(bool* _aidl_return) override;
	::ndk::ScopedAStatus setWfdR2DeviceInfo(
		const std::vector<uint8_t>& in_info) override;
	::ndk::ScopedAStatus removeClient(
		const std::vector<uint8_t>& peer_address, bool isLegacyClient) override;
	::ndk::ScopedAStatus findOnSocialChannels(int32_t in_timeoutInSec) override;
	::ndk::ScopedAStatus findOnSpecificFrequency(
		int32_t in_freq, int32_t in_timeoutInSec) override;
	::ndk::ScopedAStatus setVendorElements(
		P2pFrameTypeMask in_frameTypeMask,
		const std::vector<uint8_t>& in_vendorElemBytes) override;
	::ndk::ScopedAStatus configureEapolIpAddressAllocationParams(
		int32_t in_ipAddressGo, int32_t in_ipAddressMask,
		int32_t in_ipAddressStart, int32_t in_ipAddressEnd) override;
	::ndk::ScopedAStatus connectWithParams(
		const P2pConnectInfo& in_connectInfo, std::string* _aidl_return) override;
	::ndk::ScopedAStatus findWithParams(const P2pDiscoveryInfo& in_discoveryInfo) override;

private:
	// Corresponding worker functions for the AIDL methods.
	std::pair<std::string, ndk::ScopedAStatus> getNameInternal();
	std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal();
	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
		addNetworkInternal();
	ndk::ScopedAStatus removeNetworkInternal(int32_t id);
	std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus>
		getNetworkInternal(int32_t id);
	std::pair<std::vector<int32_t>, ndk::ScopedAStatus>
		listNetworksInternal();
	ndk::ScopedAStatus registerCallbackInternal(
		const std::shared_ptr<ISupplicantP2pIfaceCallback>& callback);
	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
		getDeviceAddressInternal();
	ndk::ScopedAStatus setSsidPostfixInternal(
		const std::vector<uint8_t>& postfix);
	ndk::ScopedAStatus setGroupIdleInternal(
		const std::string& group_ifname, uint32_t timeout_in_sec);
	ndk::ScopedAStatus setPowerSaveInternal(
		const std::string& group_ifname, bool enable);
	ndk::ScopedAStatus findInternal(uint32_t timeout_in_sec);
	ndk::ScopedAStatus stopFindInternal();
	ndk::ScopedAStatus flushInternal();
	std::pair<std::string, ndk::ScopedAStatus> connectInternal(
		const std::vector<uint8_t>& peer_address,
		WpsProvisionMethod provision_method,
		const std::string& pre_selected_pin, bool join_existing_group,
		bool persistent, uint32_t go_intent);
	ndk::ScopedAStatus cancelConnectInternal();
	ndk::ScopedAStatus provisionDiscoveryInternal(
		const std::vector<uint8_t>& peer_address,
		WpsProvisionMethod provision_method);
	ndk::ScopedAStatus addGroupInternal(bool in_persistent, int32_t in_persistentNetworkId);
	ndk::ScopedAStatus addGroupWithConfigInternal(
		const std::vector<uint8_t>& ssid, const std::string& passphrase,
		bool persistent, uint32_t freq, const std::vector<uint8_t>& peer_address,
		bool joinExistingGroup);
	ndk::ScopedAStatus removeGroupInternal(const std::string& group_ifname);
	ndk::ScopedAStatus rejectInternal(
		const std::vector<uint8_t>& peer_address);
	ndk::ScopedAStatus inviteInternal(
		const std::string& group_ifname,
		const std::vector<uint8_t>& go_device_address,
		const std::vector<uint8_t>& peer_address);
	ndk::ScopedAStatus reinvokeInternal(
		int32_t persistent_network_id,
		const std::vector<uint8_t>& peer_address);
	ndk::ScopedAStatus configureExtListenInternal(
		uint32_t period_in_millis, uint32_t interval_in_millis);
	ndk::ScopedAStatus setListenChannelInternal(
		uint32_t channel, uint32_t operating_class);
	ndk::ScopedAStatus setDisallowedFrequenciesInternal(
		const std::vector<FreqRange>& ranges);
	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal(
		const std::vector<uint8_t>& peer_address);
	std::pair<P2pGroupCapabilityMask, ndk::ScopedAStatus> getGroupCapabilityInternal(
		const std::vector<uint8_t>& peer_address);
	ndk::ScopedAStatus addBonjourServiceInternal(
		const std::vector<uint8_t>& query,
		const std::vector<uint8_t>& response);
	ndk::ScopedAStatus removeBonjourServiceInternal(
		const std::vector<uint8_t>& query);
	ndk::ScopedAStatus addUpnpServiceInternal(
		uint32_t version, const std::string& service_name);
	ndk::ScopedAStatus removeUpnpServiceInternal(
		uint32_t version, const std::string& service_name);
	ndk::ScopedAStatus flushServicesInternal();
	std::pair<uint64_t, ndk::ScopedAStatus> requestServiceDiscoveryInternal(
		const std::vector<uint8_t>& peer_address,
		const std::vector<uint8_t>& query);
	ndk::ScopedAStatus cancelServiceDiscoveryInternal(uint64_t identifier);
	ndk::ScopedAStatus setMiracastModeInternal(
		MiracastMode mode);
	ndk::ScopedAStatus startWpsPbcInternal(
		const std::string& group_ifname,
		const std::vector<uint8_t>& bssid);
	ndk::ScopedAStatus startWpsPinKeypadInternal(
		const std::string& group_ifname, const std::string& pin);
	std::pair<std::string, ndk::ScopedAStatus> startWpsPinDisplayInternal(
		const std::string& group_ifname,
		const std::vector<uint8_t>& bssid);
	ndk::ScopedAStatus cancelWpsInternal(const std::string& group_ifname);
	ndk::ScopedAStatus setWpsDeviceNameInternal(const std::string& name);
	ndk::ScopedAStatus setWpsDeviceTypeInternal(
		const std::vector<uint8_t>& type);
	ndk::ScopedAStatus setWpsManufacturerInternal(
		const std::string& manufacturer);
	ndk::ScopedAStatus setWpsModelNameInternal(const std::string& model_name);
	ndk::ScopedAStatus setWpsModelNumberInternal(
		const std::string& model_number);
	ndk::ScopedAStatus setWpsSerialNumberInternal(
		const std::string& serial_number);
	ndk::ScopedAStatus setWpsConfigMethodsInternal(WpsConfigMethods config_methods);
	ndk::ScopedAStatus enableWfdInternal(bool enable);
	ndk::ScopedAStatus setWfdDeviceInfoInternal(
		const std::vector<uint8_t>& info);
	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
		createNfcHandoverRequestMessageInternal();
	std::pair<std::vector<uint8_t>, ndk::ScopedAStatus>
		createNfcHandoverSelectMessageInternal();
	ndk::ScopedAStatus reportNfcHandoverResponseInternal(
		const std::vector<uint8_t>& request);
	ndk::ScopedAStatus reportNfcHandoverInitiationInternal(
		const std::vector<uint8_t>& select);
	ndk::ScopedAStatus saveConfigInternal();
	ndk::ScopedAStatus setMacRandomizationInternal(bool enable);
	ndk::ScopedAStatus setEdmgInternal(bool enable);
	std::pair<bool, ndk::ScopedAStatus> getEdmgInternal();
	ndk::ScopedAStatus setWfdR2DeviceInfoInternal(
		const std::vector<uint8_t>& info);
	ndk::ScopedAStatus removeClientInternal(
		const std::vector<uint8_t>& peer_address, bool isLegacyClient);
	ndk::ScopedAStatus findOnSocialChannelsInternal(uint32_t timeout_in_sec);
	ndk::ScopedAStatus findOnSpecificFrequencyInternal(
		uint32_t freq, uint32_t timeout_in_sec);
	ndk::ScopedAStatus setVendorElementsInternal(
		P2pFrameTypeMask frameTypeMask,
		const std::vector<uint8_t>& vendorElemBytes);
	::ndk::ScopedAStatus configureEapolIpAddressAllocationParamsInternal(
		uint32_t ipAddressGo, uint32_t ipAddressMask,
		uint32_t ipAddressStart, uint32_t ipAddressEnd);
	std::pair<std::string, ndk::ScopedAStatus> connectWithParamsInternal(
		const P2pConnectInfo& connectInfo);
	ndk::ScopedAStatus findWithParamsInternal(const P2pDiscoveryInfo& discoveryInfo);

	struct wpa_supplicant* retrieveIfacePtr();
	struct wpa_supplicant* retrieveGroupIfacePtr(
		const std::string& group_ifname);

	// Reference to the global wpa_struct. This is assumed to be valid for
	// the lifetime of the process.
	struct wpa_global* wpa_global_;
	// Name of the iface this aidl object controls
	const std::string ifname_;
	bool is_valid_;

	DISALLOW_COPY_AND_ASSIGN(P2pIface);
};

}  // namespace supplicant
}  // namespace wifi
}  // namespace hardware
}  // namespace android
}  // namespace aidl

#endif  // WPA_SUPPLICANT_AIDL_P2P_IFACE_H