1 /* 2 * WPA Supplicant - P2P Iface Aidl interface 3 * Copyright (c) 2021, Google Inc. All rights reserved. 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #ifndef WPA_SUPPLICANT_AIDL_P2P_IFACE_H 10 #define WPA_SUPPLICANT_AIDL_P2P_IFACE_H 11 12 #include <array> 13 #include <vector> 14 15 #include <android-base/macros.h> 16 17 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantP2pIface.h> 18 #include <aidl/android/hardware/wifi/supplicant/FreqRange.h> 19 #include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pIfaceCallback.h> 20 #include <aidl/android/hardware/wifi/supplicant/ISupplicantP2pNetwork.h> 21 #include <aidl/android/hardware/wifi/supplicant/MiracastMode.h> 22 #include <aidl/android/hardware/wifi/supplicant/WpsProvisionMethod.h> 23 24 extern "C" 25 { 26 #include "utils/common.h" 27 #include "utils/includes.h" 28 #include "p2p/p2p.h" 29 #include "p2p/p2p_i.h" 30 #include "p2p_supplicant.h" 31 #include "p2p_supplicant.h" 32 #include "config.h" 33 } 34 35 #define P2P_MGMT_DEVICE_PREFIX "p2p-dev-" 36 37 namespace aidl { 38 namespace android { 39 namespace hardware { 40 namespace wifi { 41 namespace supplicant { 42 43 /** 44 * Implementation of P2pIface aidl object. Each unique aidl 45 * object is used for control operations on a specific interface 46 * controlled by wpa_supplicant. 47 */ 48 class P2pIface : public BnSupplicantP2pIface 49 { 50 public: 51 P2pIface(struct wpa_global* wpa_global, const char ifname[]); 52 ~P2pIface() override = default; 53 // Refer to |StaIface::invalidate()|. 54 void invalidate(); 55 bool isValid(); 56 57 // Aidl methods exposed. 58 ::ndk::ScopedAStatus getName(std::string* _aidl_return) override; 59 ::ndk::ScopedAStatus getType(IfaceType* _aidl_return) override; 60 ::ndk::ScopedAStatus addNetwork( 61 std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override; 62 ::ndk::ScopedAStatus removeNetwork(int32_t in_id) override; 63 ::ndk::ScopedAStatus getNetwork( 64 int32_t in_id, std::shared_ptr<ISupplicantP2pNetwork>* _aidl_return) override; 65 ::ndk::ScopedAStatus listNetworks(std::vector<int32_t>* _aidl_return) override; 66 ::ndk::ScopedAStatus registerCallback( 67 const std::shared_ptr<ISupplicantP2pIfaceCallback>& in_callback) override; 68 ::ndk::ScopedAStatus getDeviceAddress(std::vector<uint8_t>* _aidl_return) override; 69 ::ndk::ScopedAStatus setSsidPostfix(const std::vector<uint8_t>& in_postfix) override; 70 ::ndk::ScopedAStatus setGroupIdle( 71 const std::string& in_groupIfName, int32_t in_timeoutInSec) override; 72 ::ndk::ScopedAStatus setPowerSave( 73 const std::string& in_groupIfName, bool in_enable) override; 74 ::ndk::ScopedAStatus find(int32_t in_timeoutInSec) override; 75 ::ndk::ScopedAStatus stopFind() override; 76 ::ndk::ScopedAStatus flush() override; 77 ::ndk::ScopedAStatus connect( 78 const std::vector<uint8_t>& in_peerAddress, WpsProvisionMethod in_provisionMethod, 79 const std::string& in_preSelectedPin, bool in_joinExistingGroup, 80 bool in_persistent, int32_t in_goIntent, std::string* _aidl_return) override; 81 ::ndk::ScopedAStatus cancelConnect() override; 82 ::ndk::ScopedAStatus provisionDiscovery( 83 const std::vector<uint8_t>& in_peerAddress, 84 WpsProvisionMethod in_provisionMethod) override; 85 ::ndk::ScopedAStatus addGroup(bool in_persistent, int32_t in_persistentNetworkId) override; 86 ::ndk::ScopedAStatus addGroupWithConfig( 87 const std::vector<uint8_t>& in_ssid, const std::string& in_pskPassphrase, 88 bool in_persistent, int32_t in_freq, const std::vector<uint8_t>& in_peerAddress, 89 bool in_joinExistingGroup) override; 90 ::ndk::ScopedAStatus removeGroup(const std::string& in_groupIfName) override; 91 ::ndk::ScopedAStatus reject(const std::vector<uint8_t>& in_peerAddress) override; 92 ::ndk::ScopedAStatus invite( 93 const std::string& in_groupIfName, 94 const std::vector<uint8_t>& in_goDeviceAddress, 95 const std::vector<uint8_t>& in_peerAddress) override; 96 ::ndk::ScopedAStatus reinvoke( 97 int32_t in_persistentNetworkId, 98 const std::vector<uint8_t>& in_peerAddress) override; 99 ::ndk::ScopedAStatus configureExtListen( 100 int32_t in_periodInMillis, int32_t in_intervalInMillis) override; 101 ::ndk::ScopedAStatus setListenChannel( 102 int32_t in_channel, int32_t in_operatingClass) override; 103 ::ndk::ScopedAStatus setDisallowedFrequencies( 104 const std::vector<FreqRange>& in_ranges) override; 105 ::ndk::ScopedAStatus getSsid( 106 const std::vector<uint8_t>& in_peerAddress, 107 std::vector<uint8_t>* _aidl_return) override; 108 ::ndk::ScopedAStatus getGroupCapability( 109 const std::vector<uint8_t>& in_peerAddress, 110 P2pGroupCapabilityMask* _aidl_return) override; 111 ::ndk::ScopedAStatus addBonjourService( 112 const std::vector<uint8_t>& in_query, 113 const std::vector<uint8_t>& in_response) override; 114 ::ndk::ScopedAStatus removeBonjourService( 115 const std::vector<uint8_t>& in_query) override; 116 ::ndk::ScopedAStatus addUpnpService( 117 int32_t in_version, const std::string& in_serviceName) override; 118 ::ndk::ScopedAStatus removeUpnpService( 119 int32_t in_version, const std::string& in_serviceName) override; 120 ::ndk::ScopedAStatus flushServices() override; 121 ::ndk::ScopedAStatus requestServiceDiscovery( 122 const std::vector<uint8_t>& in_peerAddress, 123 const std::vector<uint8_t>& in_query, int64_t* _aidl_return) override; 124 ::ndk::ScopedAStatus cancelServiceDiscovery(int64_t in_identifier) override; 125 ::ndk::ScopedAStatus setMiracastMode(MiracastMode in_mode) override; 126 ::ndk::ScopedAStatus startWpsPbc( 127 const std::string& in_groupIfName, 128 const std::vector<uint8_t>& in_bssid) override; 129 ::ndk::ScopedAStatus startWpsPinKeypad( 130 const std::string& in_groupIfName, const std::string& in_pin) override; 131 ::ndk::ScopedAStatus startWpsPinDisplay( 132 const std::string& in_groupIfName, 133 const std::vector<uint8_t>& in_bssid, 134 std::string* _aidl_return) override; 135 ::ndk::ScopedAStatus cancelWps(const std::string& in_groupIfName) override; 136 ::ndk::ScopedAStatus setWpsDeviceName( 137 const std::string& in_name) override; 138 ::ndk::ScopedAStatus setWpsDeviceType( 139 const std::vector<uint8_t>& in_type) override; 140 ::ndk::ScopedAStatus setWpsManufacturer( 141 const std::string& in_manufacturer) override; 142 ::ndk::ScopedAStatus setWpsModelName( 143 const std::string& in_modelName) override; 144 ::ndk::ScopedAStatus setWpsModelNumber( 145 const std::string& in_modelNumber) override; 146 ::ndk::ScopedAStatus setWpsSerialNumber( 147 const std::string& in_serialNumber) override; 148 ::ndk::ScopedAStatus setWpsConfigMethods( 149 WpsConfigMethods in_configMethods) override; 150 ::ndk::ScopedAStatus enableWfd(bool in_enable) override; 151 ::ndk::ScopedAStatus setWfdDeviceInfo( 152 const std::vector<uint8_t>& in_info) override; 153 ::ndk::ScopedAStatus createNfcHandoverRequestMessage( 154 std::vector<uint8_t>* _aidl_return) override; 155 ::ndk::ScopedAStatus createNfcHandoverSelectMessage( 156 std::vector<uint8_t>* _aidl_return) override; 157 ::ndk::ScopedAStatus reportNfcHandoverInitiation( 158 const std::vector<uint8_t>& in_select) override; 159 ::ndk::ScopedAStatus reportNfcHandoverResponse( 160 const std::vector<uint8_t>& in_request) override; 161 ::ndk::ScopedAStatus saveConfig() override; 162 ::ndk::ScopedAStatus setMacRandomization(bool in_enable) override; 163 ::ndk::ScopedAStatus setEdmg(bool in_enable) override; 164 ::ndk::ScopedAStatus getEdmg(bool* _aidl_return) override; 165 ::ndk::ScopedAStatus setWfdR2DeviceInfo( 166 const std::vector<uint8_t>& in_info) override; 167 ::ndk::ScopedAStatus removeClient( 168 const std::vector<uint8_t>& peer_address, bool isLegacyClient) override; 169 ::ndk::ScopedAStatus findOnSocialChannels(int32_t in_timeoutInSec) override; 170 ::ndk::ScopedAStatus findOnSpecificFrequency( 171 int32_t in_freq, int32_t in_timeoutInSec) override; 172 ::ndk::ScopedAStatus setVendorElements( 173 P2pFrameTypeMask in_frameTypeMask, 174 const std::vector<uint8_t>& in_vendorElemBytes) override; 175 176 private: 177 // Corresponding worker functions for the AIDL methods. 178 std::pair<std::string, ndk::ScopedAStatus> getNameInternal(); 179 std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal(); 180 std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus> 181 addNetworkInternal(); 182 ndk::ScopedAStatus removeNetworkInternal(int32_t id); 183 std::pair<std::shared_ptr<ISupplicantP2pNetwork>, ndk::ScopedAStatus> 184 getNetworkInternal(int32_t id); 185 std::pair<std::vector<int32_t>, ndk::ScopedAStatus> 186 listNetworksInternal(); 187 ndk::ScopedAStatus registerCallbackInternal( 188 const std::shared_ptr<ISupplicantP2pIfaceCallback>& callback); 189 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 190 getDeviceAddressInternal(); 191 ndk::ScopedAStatus setSsidPostfixInternal( 192 const std::vector<uint8_t>& postfix); 193 ndk::ScopedAStatus setGroupIdleInternal( 194 const std::string& group_ifname, uint32_t timeout_in_sec); 195 ndk::ScopedAStatus setPowerSaveInternal( 196 const std::string& group_ifname, bool enable); 197 ndk::ScopedAStatus findInternal(uint32_t timeout_in_sec); 198 ndk::ScopedAStatus stopFindInternal(); 199 ndk::ScopedAStatus flushInternal(); 200 std::pair<std::string, ndk::ScopedAStatus> connectInternal( 201 const std::vector<uint8_t>& peer_address, 202 WpsProvisionMethod provision_method, 203 const std::string& pre_selected_pin, bool join_existing_group, 204 bool persistent, uint32_t go_intent); 205 ndk::ScopedAStatus cancelConnectInternal(); 206 ndk::ScopedAStatus provisionDiscoveryInternal( 207 const std::vector<uint8_t>& peer_address, 208 WpsProvisionMethod provision_method); 209 ndk::ScopedAStatus addGroupInternal(bool in_persistent, int32_t in_persistentNetworkId); 210 ndk::ScopedAStatus addGroupWithConfigInternal( 211 const std::vector<uint8_t>& ssid, const std::string& passphrase, 212 bool persistent, uint32_t freq, const std::vector<uint8_t>& peer_address, 213 bool joinExistingGroup); 214 ndk::ScopedAStatus removeGroupInternal(const std::string& group_ifname); 215 ndk::ScopedAStatus rejectInternal( 216 const std::vector<uint8_t>& peer_address); 217 ndk::ScopedAStatus inviteInternal( 218 const std::string& group_ifname, 219 const std::vector<uint8_t>& go_device_address, 220 const std::vector<uint8_t>& peer_address); 221 ndk::ScopedAStatus reinvokeInternal( 222 int32_t persistent_network_id, 223 const std::vector<uint8_t>& peer_address); 224 ndk::ScopedAStatus configureExtListenInternal( 225 uint32_t period_in_millis, uint32_t interval_in_millis); 226 ndk::ScopedAStatus setListenChannelInternal( 227 uint32_t channel, uint32_t operating_class); 228 ndk::ScopedAStatus setDisallowedFrequenciesInternal( 229 const std::vector<FreqRange>& ranges); 230 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal( 231 const std::vector<uint8_t>& peer_address); 232 std::pair<P2pGroupCapabilityMask, ndk::ScopedAStatus> getGroupCapabilityInternal( 233 const std::vector<uint8_t>& peer_address); 234 ndk::ScopedAStatus addBonjourServiceInternal( 235 const std::vector<uint8_t>& query, 236 const std::vector<uint8_t>& response); 237 ndk::ScopedAStatus removeBonjourServiceInternal( 238 const std::vector<uint8_t>& query); 239 ndk::ScopedAStatus addUpnpServiceInternal( 240 uint32_t version, const std::string& service_name); 241 ndk::ScopedAStatus removeUpnpServiceInternal( 242 uint32_t version, const std::string& service_name); 243 ndk::ScopedAStatus flushServicesInternal(); 244 std::pair<uint64_t, ndk::ScopedAStatus> requestServiceDiscoveryInternal( 245 const std::vector<uint8_t>& peer_address, 246 const std::vector<uint8_t>& query); 247 ndk::ScopedAStatus cancelServiceDiscoveryInternal(uint64_t identifier); 248 ndk::ScopedAStatus setMiracastModeInternal( 249 MiracastMode mode); 250 ndk::ScopedAStatus startWpsPbcInternal( 251 const std::string& group_ifname, 252 const std::vector<uint8_t>& bssid); 253 ndk::ScopedAStatus startWpsPinKeypadInternal( 254 const std::string& group_ifname, const std::string& pin); 255 std::pair<std::string, ndk::ScopedAStatus> startWpsPinDisplayInternal( 256 const std::string& group_ifname, 257 const std::vector<uint8_t>& bssid); 258 ndk::ScopedAStatus cancelWpsInternal(const std::string& group_ifname); 259 ndk::ScopedAStatus setWpsDeviceNameInternal(const std::string& name); 260 ndk::ScopedAStatus setWpsDeviceTypeInternal( 261 const std::vector<uint8_t>& type); 262 ndk::ScopedAStatus setWpsManufacturerInternal( 263 const std::string& manufacturer); 264 ndk::ScopedAStatus setWpsModelNameInternal(const std::string& model_name); 265 ndk::ScopedAStatus setWpsModelNumberInternal( 266 const std::string& model_number); 267 ndk::ScopedAStatus setWpsSerialNumberInternal( 268 const std::string& serial_number); 269 ndk::ScopedAStatus setWpsConfigMethodsInternal(WpsConfigMethods config_methods); 270 ndk::ScopedAStatus enableWfdInternal(bool enable); 271 ndk::ScopedAStatus setWfdDeviceInfoInternal( 272 const std::vector<uint8_t>& info); 273 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 274 createNfcHandoverRequestMessageInternal(); 275 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 276 createNfcHandoverSelectMessageInternal(); 277 ndk::ScopedAStatus reportNfcHandoverResponseInternal( 278 const std::vector<uint8_t>& request); 279 ndk::ScopedAStatus reportNfcHandoverInitiationInternal( 280 const std::vector<uint8_t>& select); 281 ndk::ScopedAStatus saveConfigInternal(); 282 ndk::ScopedAStatus setMacRandomizationInternal(bool enable); 283 ndk::ScopedAStatus setEdmgInternal(bool enable); 284 std::pair<bool, ndk::ScopedAStatus> getEdmgInternal(); 285 ndk::ScopedAStatus setWfdR2DeviceInfoInternal( 286 const std::vector<uint8_t>& info); 287 ndk::ScopedAStatus removeClientInternal( 288 const std::vector<uint8_t>& peer_address, bool isLegacyClient); 289 ndk::ScopedAStatus findOnSocialChannelsInternal(uint32_t timeout_in_sec); 290 ndk::ScopedAStatus findOnSpecificFrequencyInternal( 291 uint32_t freq, uint32_t timeout_in_sec); 292 ndk::ScopedAStatus setVendorElementsInternal( 293 P2pFrameTypeMask frameTypeMask, 294 const std::vector<uint8_t>& vendorElemBytes); 295 296 struct wpa_supplicant* retrieveIfacePtr(); 297 struct wpa_supplicant* retrieveGroupIfacePtr( 298 const std::string& group_ifname); 299 300 // Reference to the global wpa_struct. This is assumed to be valid for 301 // the lifetime of the process. 302 struct wpa_global* wpa_global_; 303 // Name of the iface this aidl object controls 304 const std::string ifname_; 305 bool is_valid_; 306 307 DISALLOW_COPY_AND_ASSIGN(P2pIface); 308 }; 309 310 } // namespace supplicant 311 } // namespace wifi 312 } // namespace hardware 313 } // namespace android 314 } // namespace aidl 315 316 #endif // WPA_SUPPLICANT_AIDL_P2P_IFACE_H 317