Home | History | Annotate | Download | only in 1.1
      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_NETWORK_H
     11 #define WPA_SUPPLICANT_HIDL_STA_NETWORK_H
     12 
     13 #include <array>
     14 #include <vector>
     15 
     16 #include <android-base/macros.h>
     17 
     18 #include <android/hardware/wifi/supplicant/1.1/ISupplicantStaNetwork.h>
     19 #include <android/hardware/wifi/supplicant/1.0/ISupplicantStaNetworkCallback.h>
     20 
     21 extern "C" {
     22 #include "utils/common.h"
     23 #include "utils/includes.h"
     24 #include "config.h"
     25 #include "wpa_supplicant_i.h"
     26 #include "notify.h"
     27 #include "eapol_supp/eapol_supp_sm.h"
     28 #include "eap_peer/eap.h"
     29 #include "rsn_supp/wpa.h"
     30 }
     31 
     32 namespace android {
     33 namespace hardware {
     34 namespace wifi {
     35 namespace supplicant {
     36 namespace V1_1 {
     37 namespace implementation {
     38 using namespace android::hardware::wifi::supplicant::V1_0;
     39 
     40 /**
     41  * Implementation of StaNetwork hidl object. Each unique hidl
     42  * object is used for control operations on a specific network
     43  * controlled by wpa_supplicant.
     44  */
     45 class StaNetwork : public V1_1::ISupplicantStaNetwork
     46 {
     47 public:
     48 	StaNetwork(
     49 	    struct wpa_global* wpa_global, const char ifname[], int network_id);
     50 	~StaNetwork() override = default;
     51 	// Refer to |StaIface::invalidate()|.
     52 	void invalidate();
     53 	bool isValid();
     54 
     55 	// Hidl methods exposed.
     56 	Return<void> getId(getId_cb _hidl_cb) override;
     57 	Return<void> getInterfaceName(getInterfaceName_cb _hidl_cb) override;
     58 	Return<void> getType(getType_cb _hidl_cb) override;
     59 	Return<void> registerCallback(
     60 	    const sp<ISupplicantStaNetworkCallback>& callback,
     61 	    registerCallback_cb _hidl_cb) override;
     62 	Return<void> setSsid(
     63 	    const hidl_vec<uint8_t>& ssid, setSsid_cb _hidl_cb) override;
     64 	Return<void> setBssid(
     65 	    const hidl_array<uint8_t, 6>& bssid, setBssid_cb _hidl_cb) override;
     66 	Return<void> setScanSsid(bool enable, setScanSsid_cb _hidl_cb) override;
     67 	Return<void> setKeyMgmt(
     68 	    uint32_t key_mgmt_mask, setKeyMgmt_cb _hidl_cb) override;
     69 	Return<void> setProto(
     70 	    uint32_t proto_mask, setProto_cb _hidl_cb) override;
     71 	Return<void> setAuthAlg(
     72 	    uint32_t auth_alg_mask, setAuthAlg_cb _hidl_cb) override;
     73 	Return<void> setGroupCipher(
     74 	    uint32_t group_cipher_mask, setGroupCipher_cb _hidl_cb) override;
     75 	Return<void> setPairwiseCipher(
     76 	    uint32_t pairwise_cipher_mask,
     77 	    setPairwiseCipher_cb _hidl_cb) override;
     78 	Return<void> setPskPassphrase(
     79 	    const hidl_string& psk, setPskPassphrase_cb _hidl_cb) override;
     80 	Return<void> setPsk(
     81 	    const hidl_array<uint8_t, 32>& psk, setPsk_cb _hidl_cb) override;
     82 	Return<void> setWepKey(
     83 	    uint32_t key_idx, const hidl_vec<uint8_t>& wep_key,
     84 	    setWepKey_cb _hidl_cb) override;
     85 	Return<void> setWepTxKeyIdx(
     86 	    uint32_t key_idx, setWepTxKeyIdx_cb _hidl_cb) override;
     87 	Return<void> setRequirePmf(
     88 	    bool enable, setRequirePmf_cb _hidl_cb) override;
     89 	Return<void> setEapMethod(
     90 	    ISupplicantStaNetwork::EapMethod method,
     91 	    setEapMethod_cb _hidl_cb) override;
     92 	Return<void> setEapPhase2Method(
     93 	    ISupplicantStaNetwork::EapPhase2Method method,
     94 	    setEapPhase2Method_cb _hidl_cb) override;
     95 	Return<void> setEapIdentity(
     96 	    const hidl_vec<uint8_t>& identity,
     97 	    setEapIdentity_cb _hidl_cb) override;
     98 	Return<void> setEapAnonymousIdentity(
     99 	    const hidl_vec<uint8_t>& identity,
    100 	    setEapAnonymousIdentity_cb _hidl_cb) override;
    101 	Return<void> setEapPassword(
    102 	    const hidl_vec<uint8_t>& password,
    103 	    setEapPassword_cb _hidl_cb) override;
    104 	Return<void> setEapCACert(
    105 	    const hidl_string& path, setEapCACert_cb _hidl_cb) override;
    106 	Return<void> setEapCAPath(
    107 	    const hidl_string& path, setEapCAPath_cb _hidl_cb) override;
    108 	Return<void> setEapClientCert(
    109 	    const hidl_string& path, setEapClientCert_cb _hidl_cb) override;
    110 	Return<void> setEapPrivateKeyId(
    111 	    const hidl_string& id, setEapPrivateKeyId_cb _hidl_cb) override;
    112         Return<void> setEapEncryptedImsiIdentity(
    113             const EapSimEncryptedIdentity& identity,
    114             setEapEncryptedImsiIdentity_cb _hidl_cb) override;
    115 	Return<void> setEapSubjectMatch(
    116 	    const hidl_string& match, setEapSubjectMatch_cb _hidl_cb) override;
    117 	Return<void> setEapAltSubjectMatch(
    118 	    const hidl_string& match,
    119 	    setEapAltSubjectMatch_cb _hidl_cb) override;
    120 	Return<void> setEapEngine(
    121 	    bool enable, setEapEngine_cb _hidl_cb) override;
    122 	Return<void> setEapEngineID(
    123 	    const hidl_string& id, setEapEngineID_cb _hidl_cb) override;
    124 	Return<void> setEapDomainSuffixMatch(
    125 	    const hidl_string& match,
    126 	    setEapDomainSuffixMatch_cb _hidl_cb) override;
    127 	Return<void> setProactiveKeyCaching(
    128 	    bool enable, setProactiveKeyCaching_cb _hidl_cb) override;
    129 	Return<void> setIdStr(
    130 	    const hidl_string& id_str, setIdStr_cb _hidl_cb) override;
    131 	Return<void> setUpdateIdentifier(
    132 	    uint32_t id, setUpdateIdentifier_cb _hidl_cb) override;
    133 	Return<void> getSsid(getSsid_cb _hidl_cb) override;
    134 	Return<void> getBssid(getBssid_cb _hidl_cb) override;
    135 	Return<void> getScanSsid(getScanSsid_cb _hidl_cb) override;
    136 	Return<void> getKeyMgmt(getKeyMgmt_cb _hidl_cb) override;
    137 	Return<void> getProto(getProto_cb _hidl_cb) override;
    138 	Return<void> getAuthAlg(getAuthAlg_cb _hidl_cb) override;
    139 	Return<void> getGroupCipher(getGroupCipher_cb _hidl_cb) override;
    140 	Return<void> getPairwiseCipher(getPairwiseCipher_cb _hidl_cb) override;
    141 	Return<void> getPskPassphrase(getPskPassphrase_cb _hidl_cb) override;
    142 	Return<void> getPsk(getPsk_cb _hidl_cb) override;
    143 	Return<void> getWepKey(
    144 	    uint32_t key_idx, getWepKey_cb _hidl_cb) override;
    145 	Return<void> getWepTxKeyIdx(getWepTxKeyIdx_cb _hidl_cb) override;
    146 	Return<void> getRequirePmf(getRequirePmf_cb _hidl_cb) override;
    147 	Return<void> getEapMethod(getEapMethod_cb _hidl_cb) override;
    148 	Return<void> getEapPhase2Method(
    149 	    getEapPhase2Method_cb _hidl_cb) override;
    150 	Return<void> getEapIdentity(getEapIdentity_cb _hidl_cb) override;
    151 	Return<void> getEapAnonymousIdentity(
    152 	    getEapAnonymousIdentity_cb _hidl_cb) override;
    153 	Return<void> getEapPassword(getEapPassword_cb _hidl_cb) override;
    154 	Return<void> getEapCACert(getEapCACert_cb _hidl_cb) override;
    155 	Return<void> getEapCAPath(getEapCAPath_cb _hidl_cb) override;
    156 	Return<void> getEapClientCert(getEapClientCert_cb _hidl_cb) override;
    157 	Return<void> getEapPrivateKeyId(
    158 	    getEapPrivateKeyId_cb _hidl_cb) override;
    159 	Return<void> getEapSubjectMatch(
    160 	    getEapSubjectMatch_cb _hidl_cb) override;
    161 	Return<void> getEapAltSubjectMatch(
    162 	    getEapAltSubjectMatch_cb _hidl_cb) override;
    163 	Return<void> getEapEngine(getEapEngine_cb _hidl_cb) override;
    164 	Return<void> getEapEngineID(getEapEngineID_cb _hidl_cb) override;
    165 	Return<void> getEapDomainSuffixMatch(
    166 	    getEapDomainSuffixMatch_cb _hidl_cb) override;
    167 	Return<void> getIdStr(getIdStr_cb _hidl_cb) override;
    168 	Return<void> getWpsNfcConfigurationToken(
    169 	    getWpsNfcConfigurationToken_cb _hidl_cb) override;
    170 	Return<void> enable(bool no_connect, enable_cb _hidl_cb) override;
    171 	Return<void> disable(disable_cb _hidl_cb) override;
    172 	Return<void> select(select_cb _hidl_cb) override;
    173 	Return<void> sendNetworkEapSimGsmAuthResponse(
    174 	    const hidl_vec<
    175 		ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>&
    176 		vec_params,
    177 	    sendNetworkEapSimGsmAuthResponse_cb _hidl_cb) override;
    178 	Return<void> sendNetworkEapSimGsmAuthFailure(
    179 	    sendNetworkEapSimGsmAuthFailure_cb _hidl_cb) override;
    180 	Return<void> sendNetworkEapSimUmtsAuthResponse(
    181 	    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams&
    182 		params,
    183 	    sendNetworkEapSimUmtsAuthResponse_cb _hidl_cb) override;
    184 	Return<void> sendNetworkEapSimUmtsAutsResponse(
    185 	    const hidl_array<uint8_t, 14>& auts,
    186 	    sendNetworkEapSimUmtsAutsResponse_cb _hidl_cb) override;
    187 	Return<void> sendNetworkEapSimUmtsAuthFailure(
    188 	    sendNetworkEapSimUmtsAuthFailure_cb _hidl_cb) override;
    189 	Return<void> sendNetworkEapIdentityResponse(
    190 	    const hidl_vec<uint8_t>& identity,
    191 	    sendNetworkEapIdentityResponse_cb _hidl_cb) override;
    192 	Return<void> sendNetworkEapIdentityResponse_1_1(
    193 	    const EapSimIdentity& identity,
    194 	    const EapSimEncryptedIdentity& imsiIdentity,
    195 	    sendNetworkEapIdentityResponse_1_1_cb _hidl_cb) override;
    196 
    197 private:
    198 	// Corresponding worker functions for the HIDL methods.
    199 	std::pair<SupplicantStatus, uint32_t> getIdInternal();
    200 	std::pair<SupplicantStatus, std::string> getInterfaceNameInternal();
    201 	std::pair<SupplicantStatus, IfaceType> getTypeInternal();
    202 	SupplicantStatus registerCallbackInternal(
    203 	    const sp<ISupplicantStaNetworkCallback>& callback);
    204 	SupplicantStatus setSsidInternal(const std::vector<uint8_t>& ssid);
    205 	SupplicantStatus setBssidInternal(const std::array<uint8_t, 6>& bssid);
    206 	SupplicantStatus setScanSsidInternal(bool enable);
    207 	SupplicantStatus setKeyMgmtInternal(uint32_t key_mgmt_mask);
    208 	SupplicantStatus setProtoInternal(uint32_t proto_mask);
    209 	SupplicantStatus setAuthAlgInternal(uint32_t auth_alg_mask);
    210 	SupplicantStatus setGroupCipherInternal(uint32_t group_cipher_mask);
    211 	SupplicantStatus setPairwiseCipherInternal(
    212 	    uint32_t pairwise_cipher_mask);
    213 	SupplicantStatus setPskPassphraseInternal(const std::string& psk);
    214 	SupplicantStatus setPskInternal(const std::array<uint8_t, 32>& psk);
    215 	SupplicantStatus setWepKeyInternal(
    216 	    uint32_t key_idx, const std::vector<uint8_t>& wep_key);
    217 	SupplicantStatus setWepTxKeyIdxInternal(uint32_t key_idx);
    218 	SupplicantStatus setRequirePmfInternal(bool enable);
    219 	SupplicantStatus setEapMethodInternal(
    220 	    ISupplicantStaNetwork::EapMethod method);
    221 	SupplicantStatus setEapPhase2MethodInternal(
    222 	    ISupplicantStaNetwork::EapPhase2Method method);
    223 	SupplicantStatus setEapIdentityInternal(
    224 	    const std::vector<uint8_t>& identity);
    225         SupplicantStatus setEapEncryptedImsiIdentityInternal(
    226 	    const std::vector<uint8_t>& identity);
    227 	SupplicantStatus setEapAnonymousIdentityInternal(
    228 	    const std::vector<uint8_t>& identity);
    229 	SupplicantStatus setEapPasswordInternal(
    230 	    const std::vector<uint8_t>& password);
    231 	SupplicantStatus setEapCACertInternal(const std::string& path);
    232 	SupplicantStatus setEapCAPathInternal(const std::string& path);
    233 	SupplicantStatus setEapClientCertInternal(const std::string& path);
    234 	SupplicantStatus setEapPrivateKeyIdInternal(const std::string& id);
    235 	SupplicantStatus setEapSubjectMatchInternal(const std::string& match);
    236 	SupplicantStatus setEapAltSubjectMatchInternal(
    237 	    const std::string& match);
    238 	SupplicantStatus setEapEngineInternal(bool enable);
    239 	SupplicantStatus setEapEngineIDInternal(const std::string& id);
    240 	SupplicantStatus setEapDomainSuffixMatchInternal(
    241 	    const std::string& match);
    242 	SupplicantStatus setProactiveKeyCachingInternal(bool enable);
    243 	SupplicantStatus setIdStrInternal(const std::string& id_str);
    244 	SupplicantStatus setUpdateIdentifierInternal(uint32_t id);
    245 	std::pair<SupplicantStatus, std::vector<uint8_t>> getSsidInternal();
    246 	std::pair<SupplicantStatus, std::array<uint8_t, 6>> getBssidInternal();
    247 	std::pair<SupplicantStatus, bool> getScanSsidInternal();
    248 	std::pair<SupplicantStatus, uint32_t> getKeyMgmtInternal();
    249 	std::pair<SupplicantStatus, uint32_t> getProtoInternal();
    250 	std::pair<SupplicantStatus, uint32_t> getAuthAlgInternal();
    251 	std::pair<SupplicantStatus, uint32_t> getGroupCipherInternal();
    252 	std::pair<SupplicantStatus, uint32_t> getPairwiseCipherInternal();
    253 	std::pair<SupplicantStatus, std::string> getPskPassphraseInternal();
    254 	std::pair<SupplicantStatus, std::array<uint8_t, 32>> getPskInternal();
    255 	std::pair<SupplicantStatus, std::vector<uint8_t>> getWepKeyInternal(
    256 	    uint32_t key_idx);
    257 	std::pair<SupplicantStatus, uint32_t> getWepTxKeyIdxInternal();
    258 	std::pair<SupplicantStatus, bool> getRequirePmfInternal();
    259 	std::pair<SupplicantStatus, ISupplicantStaNetwork::EapMethod>
    260 	getEapMethodInternal();
    261 	std::pair<SupplicantStatus, ISupplicantStaNetwork::EapPhase2Method>
    262 	getEapPhase2MethodInternal();
    263 	std::pair<SupplicantStatus, std::vector<uint8_t>>
    264 	getEapIdentityInternal();
    265 	std::pair<SupplicantStatus, std::vector<uint8_t>>
    266 	getEapAnonymousIdentityInternal();
    267 	std::pair<SupplicantStatus, std::vector<uint8_t>>
    268 	getEapPasswordInternal();
    269 	std::pair<SupplicantStatus, std::string> getEapCACertInternal();
    270 	std::pair<SupplicantStatus, std::string> getEapCAPathInternal();
    271 	std::pair<SupplicantStatus, std::string> getEapClientCertInternal();
    272 	std::pair<SupplicantStatus, std::string> getEapPrivateKeyIdInternal();
    273 	std::pair<SupplicantStatus, std::string> getEapSubjectMatchInternal();
    274 	std::pair<SupplicantStatus, std::string>
    275 	getEapAltSubjectMatchInternal();
    276 	std::pair<SupplicantStatus, bool> getEapEngineInternal();
    277 	std::pair<SupplicantStatus, std::string> getEapEngineIDInternal();
    278 	std::pair<SupplicantStatus, std::string>
    279 	getEapDomainSuffixMatchInternal();
    280 	std::pair<SupplicantStatus, std::string> getIdStrInternal();
    281 	std::pair<SupplicantStatus, std::vector<uint8_t>>
    282 	getWpsNfcConfigurationTokenInternal();
    283 	SupplicantStatus enableInternal(bool no_connect);
    284 	SupplicantStatus disableInternal();
    285 	SupplicantStatus selectInternal();
    286 	SupplicantStatus sendNetworkEapSimGsmAuthResponseInternal(
    287 	    const std::vector<
    288 		ISupplicantStaNetwork::NetworkResponseEapSimGsmAuthParams>&
    289 		vec_params);
    290 	SupplicantStatus sendNetworkEapSimGsmAuthFailureInternal();
    291 	SupplicantStatus sendNetworkEapSimUmtsAuthResponseInternal(
    292 	    const ISupplicantStaNetwork::NetworkResponseEapSimUmtsAuthParams&
    293 		params);
    294 	SupplicantStatus sendNetworkEapSimUmtsAutsResponseInternal(
    295 	    const std::array<uint8_t, 14>& auts);
    296 	SupplicantStatus sendNetworkEapSimUmtsAuthFailureInternal();
    297 	SupplicantStatus sendNetworkEapIdentityResponseInternal(
    298 	    const std::vector<uint8_t>& identity);
    299 	SupplicantStatus sendNetworkEapIdentityResponseInternal_1_1(
    300 	    const std::vector<uint8_t>& identity,
    301 	    const std::vector<uint8_t>& imsi_identity);
    302 
    303 	struct wpa_ssid* retrieveNetworkPtr();
    304 	struct wpa_supplicant* retrieveIfacePtr();
    305 	int isPskPassphraseValid(const std::string& psk);
    306 	void resetInternalStateAfterParamsUpdate();
    307 	int setStringFieldAndResetState(
    308 	    const char* value, uint8_t** to_update_field,
    309 	    const char* hexdump_prefix);
    310 	int setStringFieldAndResetState(
    311 	    const char* value, char** to_update_field,
    312 	    const char* hexdump_prefix);
    313 	int setStringKeyFieldAndResetState(
    314 	    const char* value, char** to_update_field,
    315 	    const char* hexdump_prefix);
    316 	int setByteArrayFieldAndResetState(
    317 	    const uint8_t* value, const size_t value_len,
    318 	    uint8_t** to_update_field, size_t* to_update_field_len,
    319 	    const char* hexdump_prefix);
    320 	int setByteArrayKeyFieldAndResetState(
    321 	    const uint8_t* value, const size_t value_len,
    322 	    uint8_t** to_update_field, size_t* to_update_field_len,
    323 	    const char* hexdump_prefix);
    324 
    325 	// Reference to the global wpa_struct. This is assumed to be valid
    326 	// for the lifetime of the process.
    327 	struct wpa_global* wpa_global_;
    328 	// Name of the iface this network belongs to.
    329 	const std::string ifname_;
    330 	// Id of the network this hidl object controls.
    331 	const int network_id_;
    332 	bool is_valid_;
    333 
    334 	DISALLOW_COPY_AND_ASSIGN(StaNetwork);
    335 };
    336 
    337 }  // namespace implementation
    338 }  // namespace V1_1
    339 }  // namespace wifi
    340 }  // namespace supplicant
    341 }  // namespace hardware
    342 }  // namespace android
    343 
    344 #endif  // WPA_SUPPLICANT_HIDL_STA_NETWORK_H
    345