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