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.0/ISupplicantStaIface.h> 19 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaIfaceCallback.h> 20 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetwork.h> 21 22 extern "C" { 23 #include "utils/common.h" 24 #include "utils/includes.h" 25 #include "wpa_supplicant_i.h" 26 #include "config.h" 27 #include "driver_i.h" 28 #include "wpa.h" 29 } 30 31 namespace android { 32 namespace hardware { 33 namespace wifi { 34 namespace supplicant { 35 namespace V1_0 { 36 namespace implementation { 37 38 /** 39 * Implementation of StaIface hidl object. Each unique hidl 40 * object is used for control operations on a specific interface 41 * controlled by wpa_supplicant. 42 */ 43 class StaIface 44 : public android::hardware::wifi::supplicant::V1_0::ISupplicantStaIface 45 { 46 public: 47 StaIface(struct wpa_global* wpa_global, const char ifname[]); 48 ~StaIface() override = default; 49 // HIDL does not provide a built-in mechanism to let the server 50 // invalidate a HIDL interface object after creation. If any client 51 // process holds onto a reference to the object in their context, 52 // any method calls on that reference will continue to be directed to 53 // the server. 54 // However Supplicant HAL needs to control the lifetime of these 55 // objects. So, add a public |invalidate| method to all |Iface| and 56 // |Network| objects. 57 // This will be used to mark an object invalid when the corresponding 58 // iface or network is removed. 59 // All HIDL method implementations should check if the object is still 60 // marked valid before processing them. 61 void invalidate(); 62 bool isValid(); 63 64 // Hidl methods exposed. 65 Return<void> getName(getName_cb _hidl_cb) override; 66 Return<void> getType(getType_cb _hidl_cb) override; 67 Return<void> addNetwork(addNetwork_cb _hidl_cb) override; 68 Return<void> removeNetwork( 69 SupplicantNetworkId id, removeNetwork_cb _hidl_cb) override; 70 Return<void> getNetwork( 71 SupplicantNetworkId id, getNetwork_cb _hidl_cb) override; 72 Return<void> listNetworks(listNetworks_cb _hidl_cb) override; 73 Return<void> registerCallback( 74 const sp<ISupplicantStaIfaceCallback>& callback, 75 registerCallback_cb _hidl_cb) override; 76 Return<void> reassociate(reassociate_cb _hidl_cb) override; 77 Return<void> reconnect(reconnect_cb _hidl_cb) override; 78 Return<void> disconnect(disconnect_cb _hidl_cb) override; 79 Return<void> setPowerSave( 80 bool enable, setPowerSave_cb _hidl_cb) override; 81 Return<void> initiateTdlsDiscover( 82 const hidl_array<uint8_t, 6>& mac_address, 83 initiateTdlsDiscover_cb _hidl_cb) override; 84 Return<void> initiateTdlsSetup( 85 const hidl_array<uint8_t, 6>& mac_address, 86 initiateTdlsSetup_cb _hidl_cb) override; 87 Return<void> initiateTdlsTeardown( 88 const hidl_array<uint8_t, 6>& mac_address, 89 initiateTdlsTeardown_cb _hidl_cb) override; 90 Return<void> initiateAnqpQuery( 91 const hidl_array<uint8_t, 6>& mac_address, 92 const hidl_vec<ISupplicantStaIface::AnqpInfoId>& info_elements, 93 const hidl_vec<ISupplicantStaIface::Hs20AnqpSubtypes>& sub_types, 94 initiateAnqpQuery_cb _hidl_cb) override; 95 Return<void> initiateHs20IconQuery( 96 const hidl_array<uint8_t, 6>& mac_address, 97 const hidl_string& file_name, 98 initiateHs20IconQuery_cb _hidl_cb) override; 99 Return<void> getMacAddress(getMacAddress_cb _hidl_cb) override; 100 Return<void> startRxFilter(startRxFilter_cb _hidl_cb) override; 101 Return<void> stopRxFilter(stopRxFilter_cb _hidl_cb) override; 102 Return<void> addRxFilter( 103 ISupplicantStaIface::RxFilterType type, 104 addRxFilter_cb _hidl_cb) override; 105 Return<void> removeRxFilter( 106 ISupplicantStaIface::RxFilterType type, 107 removeRxFilter_cb _hidl_cb) override; 108 Return<void> setBtCoexistenceMode( 109 ISupplicantStaIface::BtCoexistenceMode mode, 110 setBtCoexistenceMode_cb _hidl_cb) override; 111 Return<void> setBtCoexistenceScanModeEnabled( 112 bool enable, setBtCoexistenceScanModeEnabled_cb _hidl_cb) override; 113 Return<void> setSuspendModeEnabled( 114 bool enable, setSuspendModeEnabled_cb _hidl_cb) override; 115 Return<void> setCountryCode( 116 const hidl_array<int8_t, 2>& code, 117 setCountryCode_cb _hidl_cb) override; 118 Return<void> startWpsRegistrar( 119 const hidl_array<uint8_t, 6>& bssid, const hidl_string& pin, 120 startWpsRegistrar_cb _hidl_cb) override; 121 Return<void> startWpsPbc( 122 const hidl_array<uint8_t, 6>& bssid, 123 startWpsPbc_cb _hidl_cb) override; 124 Return<void> startWpsPinKeypad( 125 const hidl_string& pin, startWpsPinKeypad_cb _hidl_cb) override; 126 Return<void> startWpsPinDisplay( 127 const hidl_array<uint8_t, 6>& bssid, 128 startWpsPinDisplay_cb _hidl_cb) override; 129 Return<void> cancelWps(cancelWps_cb _hidl_cb) override; 130 Return<void> setWpsDeviceName( 131 const hidl_string& name, setWpsDeviceName_cb _hidl_cb) override; 132 Return<void> setWpsDeviceType( 133 const hidl_array<uint8_t, 8>& type, 134 setWpsDeviceType_cb _hidl_cb) override; 135 Return<void> setWpsManufacturer( 136 const hidl_string& manufacturer, 137 setWpsManufacturer_cb _hidl_cb) override; 138 Return<void> setWpsModelName( 139 const hidl_string& model_name, 140 setWpsModelName_cb _hidl_cb) override; 141 Return<void> setWpsModelNumber( 142 const hidl_string& model_number, 143 setWpsModelNumber_cb _hidl_cb) override; 144 Return<void> setWpsSerialNumber( 145 const hidl_string& serial_number, 146 setWpsSerialNumber_cb _hidl_cb) override; 147 Return<void> setWpsConfigMethods( 148 uint16_t config_methods, setWpsConfigMethods_cb _hidl_cb) override; 149 Return<void> setExternalSim( 150 bool useExternalSim, setExternalSim_cb _hidl_cb) override; 151 Return<void> addExtRadioWork( 152 const hidl_string& name, uint32_t freq_in_mhz, 153 uint32_t timeout_in_sec, addExtRadioWork_cb _hidl_cb) override; 154 Return<void> removeExtRadioWork( 155 uint32_t id, removeExtRadioWork_cb _hidl_cb) override; 156 Return<void> enableAutoReconnect( 157 bool enable, enableAutoReconnect_cb _hidl_cb) override; 158 159 private: 160 // Corresponding worker functions for the HIDL methods. 161 std::pair<SupplicantStatus, std::string> getNameInternal(); 162 std::pair<SupplicantStatus, IfaceType> getTypeInternal(); 163 std::pair<SupplicantStatus, sp<ISupplicantNetwork>> 164 addNetworkInternal(); 165 SupplicantStatus removeNetworkInternal(SupplicantNetworkId id); 166 std::pair<SupplicantStatus, sp<ISupplicantNetwork>> getNetworkInternal( 167 SupplicantNetworkId id); 168 std::pair<SupplicantStatus, std::vector<SupplicantNetworkId>> 169 listNetworksInternal(); 170 SupplicantStatus registerCallbackInternal( 171 const sp<ISupplicantStaIfaceCallback>& callback); 172 SupplicantStatus reassociateInternal(); 173 SupplicantStatus reconnectInternal(); 174 SupplicantStatus disconnectInternal(); 175 SupplicantStatus setPowerSaveInternal(bool enable); 176 SupplicantStatus initiateTdlsDiscoverInternal( 177 const std::array<uint8_t, 6>& mac_address); 178 SupplicantStatus initiateTdlsSetupInternal( 179 const std::array<uint8_t, 6>& mac_address); 180 SupplicantStatus initiateTdlsTeardownInternal( 181 const std::array<uint8_t, 6>& mac_address); 182 SupplicantStatus initiateAnqpQueryInternal( 183 const std::array<uint8_t, 6>& mac_address, 184 const std::vector<ISupplicantStaIface::AnqpInfoId>& info_elements, 185 const std::vector<ISupplicantStaIface::Hs20AnqpSubtypes>& 186 sub_types); 187 SupplicantStatus initiateHs20IconQueryInternal( 188 const std::array<uint8_t, 6>& mac_address, 189 const std::string& file_name); 190 std::pair<SupplicantStatus, std::array<uint8_t, 6>> 191 getMacAddressInternal(); 192 SupplicantStatus startRxFilterInternal(); 193 SupplicantStatus stopRxFilterInternal(); 194 SupplicantStatus addRxFilterInternal( 195 ISupplicantStaIface::RxFilterType type); 196 SupplicantStatus removeRxFilterInternal( 197 ISupplicantStaIface::RxFilterType type); 198 SupplicantStatus setBtCoexistenceModeInternal( 199 ISupplicantStaIface::BtCoexistenceMode mode); 200 SupplicantStatus setBtCoexistenceScanModeEnabledInternal(bool enable); 201 SupplicantStatus setSuspendModeEnabledInternal(bool enable); 202 SupplicantStatus setCountryCodeInternal( 203 const std::array<int8_t, 2>& code); 204 SupplicantStatus startWpsRegistrarInternal( 205 const std::array<uint8_t, 6>& bssid, const std::string& pin); 206 SupplicantStatus startWpsPbcInternal( 207 const std::array<uint8_t, 6>& bssid); 208 SupplicantStatus startWpsPinKeypadInternal(const std::string& pin); 209 std::pair<SupplicantStatus, std::string> startWpsPinDisplayInternal( 210 const std::array<uint8_t, 6>& bssid); 211 SupplicantStatus cancelWpsInternal(); 212 SupplicantStatus setWpsDeviceNameInternal(const std::string& name); 213 SupplicantStatus setWpsDeviceTypeInternal( 214 const std::array<uint8_t, 8>& type); 215 SupplicantStatus setWpsManufacturerInternal( 216 const std::string& manufacturer); 217 SupplicantStatus setWpsModelNameInternal(const std::string& model_name); 218 SupplicantStatus setWpsModelNumberInternal( 219 const std::string& model_number); 220 SupplicantStatus setWpsSerialNumberInternal( 221 const std::string& serial_number); 222 SupplicantStatus setWpsConfigMethodsInternal(uint16_t config_methods); 223 SupplicantStatus setExternalSimInternal(bool useExternalSim); 224 std::pair<SupplicantStatus, uint32_t> addExtRadioWorkInternal( 225 const std::string& name, uint32_t freq_in_mhz, 226 uint32_t timeout_in_sec); 227 SupplicantStatus removeExtRadioWorkInternal(uint32_t id); 228 SupplicantStatus enableAutoReconnectInternal(bool enable); 229 230 struct wpa_supplicant* retrieveIfacePtr(); 231 232 // Reference to the global wpa_struct. This is assumed to be valid for 233 // the lifetime of the process. 234 struct wpa_global* wpa_global_; 235 // Name of the iface this hidl object controls 236 const std::string ifname_; 237 bool is_valid_; 238 239 DISALLOW_COPY_AND_ASSIGN(StaIface); 240 }; 241 242 } // namespace implementation 243 } // namespace V1_0 244 } // namespace wifi 245 } // namespace supplicant 246 } // namespace hardware 247 } // namespace android 248 249 #endif // WPA_SUPPLICANT_HIDL_STA_IFACE_H 250