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_STA_IFACE_H 11 #define WPA_SUPPLICANT_HIDL_STA_IFACE_H 12 13 #include <array> 14 #include <vector> 15 16 #include <android-base/macros.h> 17 18 #include <android/hardware/wifi/supplicant/1.4/ISupplicantStaIface.h> 19 #include <android/hardware/wifi/supplicant/1.4/ISupplicantStaIfaceCallback.h> 20 #include <android/hardware/wifi/supplicant/1.3/ISupplicantStaNetwork.h> 21 22 extern "C" 23 { 24 #include "utils/common.h" 25 #include "utils/includes.h" 26 #include "wpa_supplicant_i.h" 27 #include "config.h" 28 #include "driver_i.h" 29 #include "wpa.h" 30 } 31 32 namespace android { 33 namespace hardware { 34 namespace wifi { 35 namespace supplicant { 36 namespace V1_4 { 37 namespace implementation { 38 using V1_0::ISupplicantNetwork; 39 using android::hardware::wifi::supplicant::V1_2::DppAkm; 40 using android::hardware::wifi::supplicant::V1_2::DppNetRole; 41 42 /** 43 * Implementation of StaIface hidl object. Each unique hidl 44 * object is used for control operations on a specific interface 45 * controlled by wpa_supplicant. 46 */ 47 class StaIface : public V1_4::ISupplicantStaIface 48 { 49 public: 50 StaIface(struct wpa_global* wpa_global, const char ifname[]); 51 ~StaIface() override = default; 52 // HIDL does not provide a built-in mechanism to let the server 53 // invalidate a HIDL interface object after creation. If any client 54 // process holds onto a reference to the object in their context, 55 // any method calls on that reference will continue to be directed to 56 // the server. 57 // However Supplicant HAL needs to control the lifetime of these 58 // objects. So, add a public |invalidate| method to all |Iface| and 59 // |Network| objects. 60 // This will be used to mark an object invalid when the corresponding 61 // iface or network is removed. 62 // All HIDL method implementations should check if the object is still 63 // marked valid before processing them. 64 void invalidate(); 65 bool isValid(); 66 67 // Hidl methods exposed. 68 Return<void> getName(getName_cb _hidl_cb) override; 69 Return<void> getType(getType_cb _hidl_cb) override; 70 Return<void> addNetwork(addNetwork_cb _hidl_cb) override; 71 Return<void> removeNetwork( 72 SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override; 73 Return<void> filsHlpFlushRequest( 74 filsHlpFlushRequest_cb _hidl_cb) override; 75 Return<void> filsHlpAddRequest( 76 const hidl_array<uint8_t, 6>& dst_mac, const hidl_vec<uint8_t>& pkt, 77 filsHlpAddRequest_cb _hidl_cb) override; 78 Return<void> getNetwork( 79 SupplicantNetworkId id, getNetwork_cb _hidl_cb) override; 80 Return<void> listNetworks(listNetworks_cb _hidl_cb) override; 81 Return<void> registerCallback( 82 const sp<V1_0::ISupplicantStaIfaceCallback>& callback, 83 registerCallback_cb _hidl_cb) override; 84 Return<void> registerCallback_1_1( 85 const sp<V1_1::ISupplicantStaIfaceCallback>& callback, 86 registerCallback_cb _hidl_cb) override; 87 Return<void> registerCallback_1_2( 88 const sp<V1_2::ISupplicantStaIfaceCallback>& callback, 89 registerCallback_cb _hidl_cb) override; 90 Return<void> registerCallback_1_3( 91 const sp<V1_3::ISupplicantStaIfaceCallback>& callback, 92 registerCallback_cb _hidl_cb) override; 93 Return<void> registerCallback_1_4( 94 const sp<V1_4::ISupplicantStaIfaceCallback> &callback, 95 registerCallback_1_4_cb _hidl_cb) override; 96 Return<void> reassociate(reassociate_cb _hidl_cb) override; 97 Return<void> reconnect(reconnect_cb _hidl_cb) override; 98 Return<void> disconnect(disconnect_cb _hidl_cb) override; 99 Return<void> setPowerSave( 100 bool enable, setPowerSave_cb _hidl_cb) override; 101 Return<void> initiateTdlsDiscover( 102 const hidl_array<uint8_t, 6>& mac_address, 103 initiateTdlsDiscover_cb _hidl_cb) override; 104 Return<void> initiateTdlsSetup( 105 const hidl_array<uint8_t, 6>& mac_address, 106 initiateTdlsSetup_cb _hidl_cb) override; 107 Return<void> initiateTdlsTeardown( 108 const hidl_array<uint8_t, 6>& mac_address, 109 initiateTdlsTeardown_cb _hidl_cb) override; 110 Return<void> initiateAnqpQuery( 111 const hidl_array<uint8_t, 6>& mac_address, 112 const hidl_vec<V1_0::ISupplicantStaIface::AnqpInfoId>& info_elements, 113 const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes>& sub_types, 114 initiateAnqpQuery_cb _hidl_cb) override; 115 Return<void> initiateVenueUrlAnqpQuery( 116 const hidl_array<uint8_t, 6>& mac_address, 117 initiateVenueUrlAnqpQuery_cb _hidl_cb) override; 118 Return<void> initiateHs20IconQuery( 119 const hidl_array<uint8_t, 6>& mac_address, 120 const hidl_string& file_name, 121 initiateHs20IconQuery_cb _hidl_cb) override; 122 Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override; 123 Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override; 124 Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override; 125 Return<void> addRxFilter( 126 ISupplicantStaIface::RxFilterType type, 127 addRxFilter_cb _hidl_cb) override; 128 Return<void> removeRxFilter( 129 ISupplicantStaIface::RxFilterType type, 130 removeRxFilter_cb _hidl_cb) override; 131 Return<void> setBtCoexistenceMode( 132 ISupplicantStaIface::BtCoexistenceMode mode, 133 setBtCoexistenceMode_cb _hidl_cb) override; 134 Return<void> setBtCoexistenceScanModeEnabled( 135 bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override; 136 Return<void> setSuspendModeEnabled( 137 bool enable, setSuspendModeEnabled_cb _hidl_cb) override; 138 Return<void> setCountryCode( 139 const hidl_array<int8_t, 2>& code, 140 setCountryCode_cb _hidl_cb) override; 141 Return<void> startWpsRegistrar( 142 const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin, 143 startWpsRegistrar_cb _hidl_cb) override; 144 Return<void> startWpsPbc( 145 const hidl_array<uint8_t, 6>& bssid, 146 startWpsPbc_cb _hidl_cb) override; 147 Return<void> startWpsPinKeypad( 148 const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override; 149 Return<void> startWpsPinDisplay( 150 const hidl_array<uint8_t, 6>& bssid, 151 startWpsPinDisplay_cb _hidl_cb) override; 152 Return<void> cancelWps(cancelWps_cb _hidl_cb) override; 153 Return<void> setWpsDeviceName( 154 const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override; 155 Return<void> setWpsDeviceType( 156 const hidl_array<uint8_t, 8>& type, 157 setWpsDeviceType_cb _hidl_cb) override; 158 Return<void> setWpsManufacturer( 159 const hidl_string& manufacturer, 160 setWpsManufacturer_cb _hidl_cb) override; 161 Return<void> setWpsModelName( 162 const hidl_string& model_name, 163 setWpsModelName_cb _hidl_cb) override; 164 Return<void> setWpsModelNumber( 165 const hidl_string& model_number, 166 setWpsModelNumber_cb _hidl_cb) override; 167 Return<void> setWpsSerialNumber( 168 const hidl_string& serial_number, 169 setWpsSerialNumber_cb _hidl_cb) override; 170 Return<void> setWpsConfigMethods( 171 uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override; 172 Return<void> setExternalSim( 173 bool useExternalSim, setExternalSim_cb _hidl_cb) override; 174 Return<void> addExtRadioWork( 175 const hidl_string& name, uint32_t freq_in_mhz, 176 uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override; 177 Return<void> removeExtRadioWork( 178 uint32_t id, removeExtRadioWork_cb _hidl_cb) override; 179 Return<void> enableAutoReconnect( 180 bool enable, enableAutoReconnect_cb _hidl_cb) override; 181 Return<void> getKeyMgmtCapabilities( 182 getKeyMgmtCapabilities_cb _hidl_cb) override; 183 Return<void> addDppPeerUri(const hidl_string& uri, 184 addDppPeerUri_cb _hidl_cb) override; 185 Return<void> removeDppUri(uint32_t bootstrap_id, 186 removeDppUri_cb _hidl_cb) override; 187 Return<void> startDppConfiguratorInitiator(uint32_t peer_bootstrap_id, 188 uint32_t own_bootstrap_id, const hidl_string& ssid, 189 const hidl_string& password, const hidl_string& psk, 190 DppNetRole net_role, DppAkm security_akm, 191 startDppConfiguratorInitiator_cb _hidl_cb) override; 192 Return<void> startDppEnrolleeInitiator(uint32_t peer_bootstrap_id, 193 uint32_t own_bootstrap_id, 194 startDppConfiguratorInitiator_cb _hidl_cb) override; 195 Return<void> stopDppInitiator(stopDppInitiator_cb _hidl_cb) override; 196 Return<void> getConnectionCapabilities( 197 getConnectionCapabilities_cb _hidl_cb) override; 198 Return<void> getConnectionCapabilities_1_4( 199 getConnectionCapabilities_1_4_cb _hidl_cb) override; 200 Return<void> getWpaDriverCapabilities( 201 getWpaDriverCapabilities_cb _hidl_cb) override; 202 Return<void> setMboCellularDataStatus(bool available, 203 setMboCellularDataStatus_cb _hidl_cb) override; 204 Return<void> getKeyMgmtCapabilities_1_3( 205 getKeyMgmtCapabilities_1_3_cb _hidl_cb) override; 206 Return<void> getWpaDriverCapabilities_1_4( 207 getWpaDriverCapabilities_1_4_cb _hidl_cb) override; 208 Return<void> generateDppBootstrapInfoForResponder(const hidl_array<uint8_t, 6> &mac_address, 209 const hidl_string& device_info, DppCurve curve, 210 generateDppBootstrapInfoForResponder_cb _hidl_cb) override; 211 Return<void> startDppEnrolleeResponder(uint32_t listen_channel, 212 startDppEnrolleeResponder_cb _hidl_cb) override; 213 Return<void> stopDppResponder(uint32_t own_bootstrap_id, 214 stopDppResponder_cb _hidl_cb) override; 215 216 private: 217 // Corresponding worker functions for the HIDL methods. 218 std::pair<SupplicantStatus, std::string> getNameInternal(); 219 std::pair<SupplicantStatus, IfaceType> getTypeInternal(); 220 std::pair<SupplicantStatus, sp<ISupplicantNetwork>> 221 addNetworkInternal(); 222 SupplicantStatus filsHlpFlushRequestInternal(); 223 SupplicantStatus filsHlpAddRequestInternal( 224 const std::array<uint8_t, 6>& dst_mac, 225 const std::vector<uint8_t>& pkt); 226 SupplicantStatus removeNetworkInternal(SupplicantNetworkId id); 227 std::pair<SupplicantStatus, sp<ISupplicantNetwork>> getNetworkInternal( 228 SupplicantNetworkId id); 229 std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>> 230 listNetworksInternal(); 231 SupplicantStatus registerCallbackInternal( 232 const sp<V1_0::ISupplicantStaIfaceCallback>& callback); 233 SupplicantStatus registerCallbackInternal_1_1( 234 const sp<V1_1::ISupplicantStaIfaceCallback>& callback); 235 V1_4::SupplicantStatus registerCallbackInternal_1_4( 236 const sp<V1_4::ISupplicantStaIfaceCallback>& callback); 237 SupplicantStatus reassociateInternal(); 238 SupplicantStatus reconnectInternal(); 239 SupplicantStatus disconnectInternal(); 240 SupplicantStatus setPowerSaveInternal(bool enable); 241 SupplicantStatus initiateTdlsDiscoverInternal( 242 const std::array<uint8_t, 6>& mac_address); 243 SupplicantStatus initiateTdlsSetupInternal( 244 const std::array<uint8_t, 6>& mac_address); 245 SupplicantStatus initiateTdlsTeardownInternal( 246 const std::array<uint8_t, 6>& mac_address); 247 SupplicantStatus initiateAnqpQueryInternal( 248 const std::array<uint8_t, 6>& mac_address, 249 const std::vector<ISupplicantStaIface::AnqpInfoId>& info_elements, 250 const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes>& 251 sub_types); 252 V1_4::SupplicantStatus initiateVenueUrlAnqpQueryInternal( 253 const std::array<uint8_t, 6>& mac_address); 254 SupplicantStatus initiateHs20IconQueryInternal( 255 const std::array<uint8_t, 6>& mac_address, 256 const std::string& file_name); 257 std::pair<SupplicantStatus, std::array<uint8_t, 6>> 258 getMacAddressInternal(); 259 SupplicantStatus startRxFilterInternal(); 260 SupplicantStatus stopRxFilterInternal(); 261 SupplicantStatus addRxFilterInternal( 262 ISupplicantStaIface::RxFilterType type); 263 SupplicantStatus removeRxFilterInternal( 264 ISupplicantStaIface::RxFilterType type); 265 SupplicantStatus setBtCoexistenceModeInternal( 266 ISupplicantStaIface::BtCoexistenceMode mode); 267 SupplicantStatus setBtCoexistenceScanModeEnabledInternal(bool enable); 268 SupplicantStatus setSuspendModeEnabledInternal(bool enable); 269 SupplicantStatus setCountryCodeInternal( 270 const std::array<int8_t, 2>& code); 271 SupplicantStatus startWpsRegistrarInternal( 272 const std::array<uint8_t, 6>& bssid, const std::string& pin); 273 SupplicantStatus startWpsPbcInternal( 274 const std::array<uint8_t, 6>& bssid); 275 SupplicantStatus startWpsPinKeypadInternal(const std::string& pin); 276 std::pair<SupplicantStatus, std::string> startWpsPinDisplayInternal( 277 const std::array<uint8_t, 6>& bssid); 278 SupplicantStatus cancelWpsInternal(); 279 SupplicantStatus setWpsDeviceNameInternal(const std::string& name); 280 SupplicantStatus setWpsDeviceTypeInternal( 281 const std::array<uint8_t, 8>& type); 282 SupplicantStatus setWpsManufacturerInternal( 283 const std::string& manufacturer); 284 SupplicantStatus setWpsModelNameInternal(const std::string& model_name); 285 SupplicantStatus setWpsModelNumberInternal( 286 const std::string& model_number); 287 SupplicantStatus setWpsSerialNumberInternal( 288 const std::string& serial_number); 289 SupplicantStatus setWpsConfigMethodsInternal(uint16_t config_methods); 290 SupplicantStatus setExternalSimInternal(bool useExternalSim); 291 std::pair<SupplicantStatus, uint32_t> addExtRadioWorkInternal( 292 const std::string& name, uint32_t freq_in_mhz, 293 uint32_t timeout_in_sec); 294 SupplicantStatus removeExtRadioWorkInternal(uint32_t id); 295 SupplicantStatus enableAutoReconnectInternal(bool enable); 296 std::pair<SupplicantStatus, uint32_t> getKeyMgmtCapabilitiesInternal(); 297 std::pair<SupplicantStatus, uint32_t> addDppPeerUriInternal(const std::string& uri); 298 SupplicantStatus removeDppUriInternal(uint32_t bootstrap_id); 299 SupplicantStatus startDppConfiguratorInitiatorInternal(uint32_t peer_bootstrap_id, 300 uint32_t own_bootstrap_id, 301 const std::string& ssid, const std::string& password, 302 const std::string& psk, DppNetRole net_role, DppAkm security_akm); 303 SupplicantStatus startDppEnrolleeInitiatorInternal(uint32_t peer_bootstrap_id, 304 uint32_t own_bootstrap_id); 305 SupplicantStatus stopDppInitiatorInternal(); 306 std::pair<SupplicantStatus, V1_3::ConnectionCapabilities> getConnectionCapabilitiesInternal(); 307 std::pair<V1_4::SupplicantStatus, V1_4::ConnectionCapabilities> 308 getConnectionCapabilitiesInternal_1_4(); 309 std::pair<SupplicantStatus, uint32_t> getWpaDriverCapabilitiesInternal(); 310 SupplicantStatus setMboCellularDataStatusInternal(bool available); 311 std::pair<SupplicantStatus, uint32_t> getKeyMgmtCapabilitiesInternal_1_3(); 312 std::pair<V1_4::SupplicantStatus, uint32_t> getWpaDriverCapabilitiesInternal_1_4(); 313 std::pair<V1_4::SupplicantStatus, V1_4::DppResponderBootstrapInfo> 314 generateDppBootstrapInfoForResponderInternal( 315 const std::array<uint8_t, 6>& mac_address, const std::string& device_info, 316 DppCurve curve); 317 V1_4::SupplicantStatus startDppEnrolleeResponderInternal(uint32_t listen_channel); 318 V1_4::SupplicantStatus stopDppResponderInternal(uint32_t own_bootstrap_id); 319 320 struct wpa_supplicant* retrieveIfacePtr(); 321 322 // Reference to the global wpa_struct. This is assumed to be valid for 323 // the lifetime of the process. 324 struct wpa_global* wpa_global_; 325 // Name of the iface this hidl object controls 326 const std::string ifname_; 327 bool is_valid_; 328 329 DISALLOW_COPY_AND_ASSIGN(StaIface); 330 }; 331 332 } // namespace implementation 333 } // namespace V1_4 334 } // namespace supplicant 335 } // namespace wifi 336 } // namespace hardware 337 } // namespace android 338 339 #endif // WPA_SUPPLICANT_HIDL_STA_IFACE_H 340