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