1 /* 2 * WPA Supplicant - Sta network Aidl interface 3 * Copyright (c) 2021, Google Inc. All rights reserved. 4 * 5 * This software may be distributed under the terms of the BSD license. 6 * See README for more details. 7 */ 8 9 #ifndef WPA_SUPPLICANT_AIDL_STA_NETWORK_H 10 #define WPA_SUPPLICANT_AIDL_STA_NETWORK_H 11 12 #include <array> 13 #include <vector> 14 15 #include <android-base/macros.h> 16 17 #include <aidl/android/hardware/wifi/supplicant/BnSupplicantStaNetwork.h> 18 #include <aidl/android/hardware/wifi/supplicant/EapMethod.h> 19 #include <aidl/android/hardware/wifi/supplicant/EapPhase2Method.h> 20 #include <aidl/android/hardware/wifi/supplicant/ISupplicantStaNetworkCallback.h> 21 #include <aidl/android/hardware/wifi/supplicant/NetworkRequestEapSimUmtsAuthParams.h> 22 #include <aidl/android/hardware/wifi/supplicant/NetworkResponseEapSimUmtsAuthParams.h> 23 #include <aidl/android/hardware/wifi/supplicant/SaeH2eMode.h> 24 #include <aidl/android/hardware/wifi/supplicant/DppConnectionKeys.h> 25 #include <aidl/android/hardware/wifi/supplicant/TlsVersion.h> 26 27 extern "C" 28 { 29 #include "utils/common.h" 30 #include "utils/includes.h" 31 #include "config.h" 32 #include "wpa_supplicant_i.h" 33 #include "notify.h" 34 #include "eapol_supp/eapol_supp_sm.h" 35 #include "eap_peer/eap.h" 36 #include "rsn_supp/wpa.h" 37 } 38 39 namespace aidl { 40 namespace android { 41 namespace hardware { 42 namespace wifi { 43 namespace supplicant { 44 45 /** 46 * Implementation of StaNetwork aidl object. Each unique aidl 47 * object is used for control operations on a specific network 48 * controlled by wpa_supplicant. 49 */ 50 class StaNetwork : public BnSupplicantStaNetwork 51 { 52 public: 53 StaNetwork( 54 struct wpa_global* wpa_global, const char ifname[], int network_id); 55 ~StaNetwork() override = default; 56 // Refer to |StaIface::invalidate()|. 57 void invalidate(); 58 bool isValid(); 59 60 // Aidl methods exposed. 61 ::ndk::ScopedAStatus getId(int32_t* _aidl_return) override; 62 ::ndk::ScopedAStatus getInterfaceName(std::string* _aidl_return) override; 63 ::ndk::ScopedAStatus getType(IfaceType* _aidl_return) override; 64 ::ndk::ScopedAStatus registerCallback( 65 const std::shared_ptr<ISupplicantStaNetworkCallback>& in_callback) override; 66 ::ndk::ScopedAStatus setSsid(const std::vector<uint8_t>& in_ssid) override; 67 ::ndk::ScopedAStatus setBssid(const std::vector<uint8_t>& in_bssid) override; 68 ::ndk::ScopedAStatus setDppKeys(const DppConnectionKeys& in_keys) override; 69 ::ndk::ScopedAStatus setScanSsid(bool in_enable) override; 70 ::ndk::ScopedAStatus setKeyMgmt(KeyMgmtMask in_keyMgmtMask) override; 71 ::ndk::ScopedAStatus setProto(ProtoMask in_protoMask) override; 72 ::ndk::ScopedAStatus setAuthAlg(AuthAlgMask in_authAlgMask) override; 73 ::ndk::ScopedAStatus setGroupCipher(GroupCipherMask in_groupCipherMask) override; 74 ::ndk::ScopedAStatus setPairwiseCipher( 75 PairwiseCipherMask in_pairwiseCipherMask) override; 76 ::ndk::ScopedAStatus setPskPassphrase(const std::string& in_psk) override; 77 ::ndk::ScopedAStatus setPsk(const std::vector<uint8_t>& in_psk) override; 78 ::ndk::ScopedAStatus setWepKey( 79 int32_t in_keyIdx, const std::vector<uint8_t>& in_wepKey) override; 80 ::ndk::ScopedAStatus setWepTxKeyIdx(int32_t in_keyIdx) override; 81 ::ndk::ScopedAStatus setRequirePmf(bool in_enable) override; 82 ::ndk::ScopedAStatus setEapMethod(EapMethod in_method) override; 83 ::ndk::ScopedAStatus setEapPhase2Method(EapPhase2Method in_method) override; 84 ::ndk::ScopedAStatus setEapIdentity( 85 const std::vector<uint8_t>& in_identity) override; 86 ::ndk::ScopedAStatus setEapEncryptedImsiIdentity( 87 const std::vector<uint8_t>& in_identity) override; 88 ::ndk::ScopedAStatus setStrictConservativePeerMode( 89 bool in_enable) override; 90 ::ndk::ScopedAStatus setEapAnonymousIdentity( 91 const std::vector<uint8_t>& in_identity) override; 92 ::ndk::ScopedAStatus setEapPassword( 93 const std::vector<uint8_t>& in_password) override; 94 ::ndk::ScopedAStatus setEapCACert(const std::string& in_path) override; 95 ::ndk::ScopedAStatus setEapCAPath(const std::string& in_path) override; 96 ::ndk::ScopedAStatus setEapClientCert(const std::string& in_path) override; 97 ::ndk::ScopedAStatus setEapPrivateKeyId(const std::string& in_id) override; 98 ::ndk::ScopedAStatus setEapSubjectMatch(const std::string& in_match) override; 99 ::ndk::ScopedAStatus setEapAltSubjectMatch(const std::string& in_match) override; 100 ::ndk::ScopedAStatus setEapEngine(bool in_enable) override; 101 ::ndk::ScopedAStatus setEapEngineID(const std::string& in_id) override; 102 ::ndk::ScopedAStatus setEapDomainSuffixMatch( 103 const std::string& in_match) override; 104 ::ndk::ScopedAStatus setProactiveKeyCaching(bool in_enable) override; 105 ::ndk::ScopedAStatus setIdStr(const std::string& in_idStr) override; 106 ::ndk::ScopedAStatus setUpdateIdentifier(int32_t in_id) override; 107 ::ndk::ScopedAStatus setEdmg(bool in_enable) override; 108 ::ndk::ScopedAStatus getSsid(std::vector<uint8_t>* _aidl_return) override; 109 ::ndk::ScopedAStatus getBssid(std::vector<uint8_t>* _aidl_return) override; 110 ::ndk::ScopedAStatus getScanSsid(bool* _aidl_return) override; 111 ::ndk::ScopedAStatus getKeyMgmt(KeyMgmtMask* _aidl_return) override; 112 ::ndk::ScopedAStatus getProto(ProtoMask* _aidl_return) override; 113 ::ndk::ScopedAStatus getAuthAlg(AuthAlgMask* _aidl_return) override; 114 ::ndk::ScopedAStatus getGroupCipher(GroupCipherMask* _aidl_return) override; 115 ::ndk::ScopedAStatus getPairwiseCipher(PairwiseCipherMask* _aidl_return) override; 116 ::ndk::ScopedAStatus getPskPassphrase(std::string* _aidl_return) override; 117 ::ndk::ScopedAStatus getPsk(std::vector<uint8_t>* _aidl_return) override; 118 ::ndk::ScopedAStatus getSaePassword(std::string* _aidl_return) override; 119 ::ndk::ScopedAStatus getSaePasswordId(std::string* _aidl_return) override; 120 ::ndk::ScopedAStatus getWepKey( 121 int32_t in_keyIdx, std::vector<uint8_t>* _aidl_return) override; 122 ::ndk::ScopedAStatus getWepTxKeyIdx(int32_t* _aidl_return) override; 123 ::ndk::ScopedAStatus getRequirePmf(bool* _aidl_return) override; 124 ::ndk::ScopedAStatus getEapMethod(EapMethod* _aidl_return) override; 125 ::ndk::ScopedAStatus getEapPhase2Method(EapPhase2Method* _aidl_return) override; 126 ::ndk::ScopedAStatus getEapIdentity(std::vector<uint8_t>* _aidl_return) override; 127 ::ndk::ScopedAStatus getEapAnonymousIdentity( 128 std::vector<uint8_t>* _aidl_return) override; 129 ::ndk::ScopedAStatus getEapPassword(std::vector<uint8_t>* _aidl_return) override; 130 ::ndk::ScopedAStatus getEapCACert(std::string* _aidl_return) override; 131 ::ndk::ScopedAStatus getEapCAPath(std::string* _aidl_return) override; 132 ::ndk::ScopedAStatus getEapClientCert(std::string* _aidl_return) override; 133 ::ndk::ScopedAStatus getEapPrivateKeyId(std::string* _aidl_return) override; 134 ::ndk::ScopedAStatus getEapSubjectMatch(std::string* _aidl_return) override; 135 ::ndk::ScopedAStatus getEapAltSubjectMatch(std::string* _aidl_return) override; 136 ::ndk::ScopedAStatus getEapEngine(bool* _aidl_return) override; 137 ::ndk::ScopedAStatus getEapEngineId(std::string* _aidl_return) override; 138 ::ndk::ScopedAStatus getEapDomainSuffixMatch(std::string* _aidl_return) override; 139 ::ndk::ScopedAStatus getIdStr(std::string* _aidl_return) override; 140 ::ndk::ScopedAStatus getWpsNfcConfigurationToken( 141 std::vector<uint8_t>* _aidl_return) override; 142 ::ndk::ScopedAStatus getEdmg(bool* _aidl_return) override; 143 ::ndk::ScopedAStatus enable(bool in_noConnect) override; 144 ::ndk::ScopedAStatus disable() override; 145 ::ndk::ScopedAStatus select() override; 146 ::ndk::ScopedAStatus sendNetworkEapSimGsmAuthResponse( 147 const std::vector<NetworkResponseEapSimGsmAuthParams>& in_params) override; 148 ::ndk::ScopedAStatus sendNetworkEapSimGsmAuthFailure() override; 149 ::ndk::ScopedAStatus sendNetworkEapSimUmtsAuthResponse( 150 const NetworkResponseEapSimUmtsAuthParams& in_params) override; 151 ::ndk::ScopedAStatus sendNetworkEapSimUmtsAutsResponse( 152 const std::vector<uint8_t>& in_auts) override; 153 ::ndk::ScopedAStatus sendNetworkEapSimUmtsAuthFailure() override; 154 ::ndk::ScopedAStatus sendNetworkEapIdentityResponse( 155 const std::vector<uint8_t>& in_identity, 156 const std::vector<uint8_t>& in_encryptedIdentity) override; 157 ::ndk::ScopedAStatus setGroupMgmtCipher( 158 GroupMgmtCipherMask in_groupMgmtCipherMask) override; 159 ::ndk::ScopedAStatus getGroupMgmtCipher( 160 GroupMgmtCipherMask* _aidl_return) override; 161 ::ndk::ScopedAStatus enableTlsSuiteBEapPhase1Param( 162 bool in_enable) override; 163 ::ndk::ScopedAStatus enableSuiteBEapOpenSslCiphers() override; 164 ::ndk::ScopedAStatus setSaePassword( 165 const std::string& in_saePassword) override; 166 ::ndk::ScopedAStatus setSaePasswordId( 167 const std::string& in_saePasswordId) override; 168 ::ndk::ScopedAStatus setOcsp(OcspType in_ocspType) override; 169 ::ndk::ScopedAStatus getOcsp(OcspType* _aidl_return) override; 170 ::ndk::ScopedAStatus setPmkCache( 171 const std::vector<uint8_t>& in_serializedEntry) override; 172 ::ndk::ScopedAStatus setWapiCertSuite(const std::string& in_suite) override; 173 ::ndk::ScopedAStatus getWapiCertSuite(std::string* _aidl_return) override; 174 ::ndk::ScopedAStatus setEapErp(bool in_enable) override; 175 ::ndk::ScopedAStatus setSaeH2eMode(SaeH2eMode in_mode) override; 176 ::ndk::ScopedAStatus enableSaePkOnlyMode(bool in_enable) override; 177 ::ndk::ScopedAStatus setRoamingConsortiumSelection( 178 const std::vector<uint8_t>& in_selectedRcoi) override; 179 ::ndk::ScopedAStatus setMinimumTlsVersionEapPhase1Param( 180 TlsVersion in_tlsVersion) override; 181 ::ndk::ScopedAStatus disableEht() override; 182 ::ndk::ScopedAStatus setVendorData( 183 const std::vector<common::OuiKeyedData>& in_vendorData) override; 184 185 private: 186 // Corresponding worker functions for the AIDL methods. 187 std::pair<uint32_t, ndk::ScopedAStatus> getIdInternal(); 188 std::pair<std::string, ndk::ScopedAStatus> getInterfaceNameInternal(); 189 std::pair<IfaceType, ndk::ScopedAStatus> getTypeInternal(); 190 ndk::ScopedAStatus registerCallbackInternal( 191 const std::shared_ptr<ISupplicantStaNetworkCallback>& callback); 192 ndk::ScopedAStatus setSsidInternal(const std::vector<uint8_t>& ssid); 193 ndk::ScopedAStatus setBssidInternal(const std::vector<uint8_t>& bssid); 194 ndk::ScopedAStatus setDppKeysInternal(const DppConnectionKeys& keys); 195 ndk::ScopedAStatus setScanSsidInternal(bool enable); 196 ndk::ScopedAStatus setKeyMgmtInternal( 197 KeyMgmtMask mask); 198 ndk::ScopedAStatus setProtoInternal( 199 ProtoMask mask); 200 ndk::ScopedAStatus setAuthAlgInternal( 201 AuthAlgMask mask); 202 ndk::ScopedAStatus setGroupCipherInternal( 203 GroupCipherMask mask); 204 ndk::ScopedAStatus setPairwiseCipherInternal( 205 PairwiseCipherMask mask); 206 ndk::ScopedAStatus setPskPassphraseInternal(const std::string& psk); 207 ndk::ScopedAStatus setPskInternal(const std::vector<uint8_t>& psk); 208 ndk::ScopedAStatus setWepKeyInternal( 209 uint32_t key_idx, const std::vector<uint8_t>& wep_key); 210 ndk::ScopedAStatus setWepTxKeyIdxInternal(uint32_t key_idx); 211 ndk::ScopedAStatus setRequirePmfInternal(bool enable); 212 ndk::ScopedAStatus setEapMethodInternal( 213 EapMethod method); 214 ndk::ScopedAStatus setEapPhase2MethodInternal( 215 EapPhase2Method method); 216 ndk::ScopedAStatus setEapIdentityInternal( 217 const std::vector<uint8_t>& identity); 218 ndk::ScopedAStatus setEapEncryptedImsiIdentityInternal( 219 const std::vector<uint8_t>& identity); 220 ndk::ScopedAStatus setStrictConservativePeerModeInternal( 221 bool enable); 222 ndk::ScopedAStatus setEapAnonymousIdentityInternal( 223 const std::vector<uint8_t>& identity); 224 ndk::ScopedAStatus setEapPasswordInternal( 225 const std::vector<uint8_t>& password); 226 ndk::ScopedAStatus setEapCACertInternal(const std::string& path); 227 ndk::ScopedAStatus setEapCAPathInternal(const std::string& path); 228 ndk::ScopedAStatus setEapClientCertInternal(const std::string& path); 229 ndk::ScopedAStatus setEapPrivateKeyIdInternal(const std::string& id); 230 ndk::ScopedAStatus setEapSubjectMatchInternal(const std::string& match); 231 ndk::ScopedAStatus setEapAltSubjectMatchInternal( 232 const std::string& match); 233 ndk::ScopedAStatus setEapEngineInternal(bool enable); 234 ndk::ScopedAStatus setEapEngineIDInternal(const std::string& id); 235 ndk::ScopedAStatus setEapDomainSuffixMatchInternal( 236 const std::string& match); 237 ndk::ScopedAStatus setProactiveKeyCachingInternal(bool enable); 238 ndk::ScopedAStatus setIdStrInternal(const std::string& id_str); 239 ndk::ScopedAStatus setUpdateIdentifierInternal(uint32_t id); 240 ndk::ScopedAStatus setEdmgInternal(bool enable); 241 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getSsidInternal(); 242 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getBssidInternal(); 243 std::pair<bool, ndk::ScopedAStatus> getScanSsidInternal(); 244 std::pair<KeyMgmtMask, ndk::ScopedAStatus> getKeyMgmtInternal(); 245 std::pair<ProtoMask, ndk::ScopedAStatus> getProtoInternal(); 246 std::pair<AuthAlgMask, ndk::ScopedAStatus> getAuthAlgInternal(); 247 std::pair<GroupCipherMask, ndk::ScopedAStatus> getGroupCipherInternal(); 248 std::pair<PairwiseCipherMask, ndk::ScopedAStatus> getPairwiseCipherInternal(); 249 std::pair<std::string, ndk::ScopedAStatus> getPskPassphraseInternal(); 250 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getPskInternal(); 251 std::pair<std::string, ndk::ScopedAStatus> getSaePasswordInternal(); 252 std::pair<std::string, ndk::ScopedAStatus> getSaePasswordIdInternal(); 253 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getWepKeyInternal( 254 uint32_t key_idx); 255 std::pair<uint32_t, ndk::ScopedAStatus> getWepTxKeyIdxInternal(); 256 std::pair<bool, ndk::ScopedAStatus> getRequirePmfInternal(); 257 std::pair<EapMethod, ndk::ScopedAStatus> getEapMethodInternal(); 258 std::pair<EapPhase2Method, ndk::ScopedAStatus> 259 getEapPhase2MethodInternal(); 260 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 261 getEapIdentityInternal(); 262 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 263 getEapAnonymousIdentityInternal(); 264 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 265 getEapPasswordInternal(); 266 std::pair<std::string, ndk::ScopedAStatus> getEapCACertInternal(); 267 std::pair<std::string, ndk::ScopedAStatus> getEapCAPathInternal(); 268 std::pair<std::string, ndk::ScopedAStatus> getEapClientCertInternal(); 269 std::pair<std::string, ndk::ScopedAStatus> getEapPrivateKeyIdInternal(); 270 std::pair<std::string, ndk::ScopedAStatus> getEapSubjectMatchInternal(); 271 std::pair<std::string, ndk::ScopedAStatus> getEapAltSubjectMatchInternal(); 272 std::pair<bool, ndk::ScopedAStatus> getEapEngineInternal(); 273 std::pair<std::string, ndk::ScopedAStatus> getEapEngineIdInternal(); 274 std::pair<std::string, ndk::ScopedAStatus> getEapDomainSuffixMatchInternal(); 275 std::pair<std::string, ndk::ScopedAStatus> getIdStrInternal(); 276 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> 277 getWpsNfcConfigurationTokenInternal(); 278 std::pair<bool, ndk::ScopedAStatus> getEdmgInternal(); 279 ndk::ScopedAStatus enableInternal(bool no_connect); 280 ndk::ScopedAStatus disableInternal(); 281 ndk::ScopedAStatus selectInternal(); 282 ndk::ScopedAStatus sendNetworkEapSimGsmAuthResponseInternal( 283 const std::vector<NetworkResponseEapSimGsmAuthParams>& 284 vec_params); 285 ndk::ScopedAStatus sendNetworkEapSimGsmAuthFailureInternal(); 286 ndk::ScopedAStatus sendNetworkEapSimUmtsAuthResponseInternal( 287 const NetworkResponseEapSimUmtsAuthParams& params); 288 ndk::ScopedAStatus sendNetworkEapSimUmtsAutsResponseInternal( 289 const std::vector<uint8_t>& auts); 290 ndk::ScopedAStatus sendNetworkEapSimUmtsAuthFailureInternal(); 291 ndk::ScopedAStatus sendNetworkEapIdentityResponseInternal( 292 const std::vector<uint8_t>& identity, 293 const std::vector<uint8_t>& imsi_identity); 294 ndk::ScopedAStatus enableTlsSuiteBEapPhase1ParamInternal(bool enable); 295 ndk::ScopedAStatus enableSuiteBEapOpenSslCiphersInternal(); 296 ndk::ScopedAStatus setSaePasswordInternal( 297 const std::string& sae_password); 298 ndk::ScopedAStatus setSaePasswordIdInternal( 299 const std::string& sae_password_id); 300 ndk::ScopedAStatus setGroupMgmtCipherInternal( 301 GroupMgmtCipherMask mask); 302 std::pair<GroupMgmtCipherMask, ndk::ScopedAStatus> 303 getGroupMgmtCipherInternal(); 304 ndk::ScopedAStatus setOcspInternal(OcspType ocspType); 305 std::pair<OcspType, ndk::ScopedAStatus> getOcspInternal(); 306 ndk::ScopedAStatus setPmkCacheInternal(const std::vector<uint8_t>& serializedEntry); 307 ndk::ScopedAStatus setWapiCertSuiteInternal(const std::string& suite); 308 std::pair<std::string, ndk::ScopedAStatus> getWapiCertSuiteInternal(); 309 ndk::ScopedAStatus setWapiPskInternal(const std::vector<uint8_t>& psk); 310 std::pair<std::vector<uint8_t>, ndk::ScopedAStatus> getWapiPskInternal(); 311 ndk::ScopedAStatus setSaeH2eModeInternal(SaeH2eMode mode); 312 ndk::ScopedAStatus enableSaePkOnlyModeInternal(bool enable); 313 ndk::ScopedAStatus setRoamingConsortiumSelectionInternal( 314 const std::vector<uint8_t>& selectedRcoi); 315 ndk::ScopedAStatus setMinimumTlsVersionEapPhase1ParamInternal(TlsVersion tlsVersion); 316 ndk::ScopedAStatus disableEhtInternal(); 317 ndk::ScopedAStatus setVendorDataInternal( 318 const std::vector<common::OuiKeyedData>& vendorData); 319 320 struct wpa_ssid* retrieveNetworkPtr(); 321 struct wpa_supplicant* retrieveIfacePtr(); 322 int isPskPassphraseValid(const std::string& psk); 323 void resetInternalStateAfterParamsUpdate(); 324 int setStringFieldAndResetState( 325 const char* value, uint8_t** to_update_field, 326 const char* hexdump_prefix); 327 int setStringFieldAndResetState( 328 const char* value, char** to_update_field, 329 const char* hexdump_prefix); 330 int setStringKeyFieldAndResetState( 331 const char* value, char** to_update_field, 332 const char* hexdump_prefix); 333 int setByteArrayFieldAndResetState( 334 const uint8_t* value, const size_t value_len, 335 uint8_t** to_update_field, size_t* to_update_field_len, 336 const char* hexdump_prefix); 337 int setByteArrayKeyFieldAndResetState( 338 const uint8_t* value, const size_t value_len, 339 uint8_t** to_update_field, size_t* to_update_field_len, 340 const char* hexdump_prefix); 341 void setFastTransitionKeyMgmt(uint32_t &key_mgmt_mask); 342 void resetFastTransitionKeyMgmt(uint32_t &key_mgmt_mask); 343 ndk::ScopedAStatus setEapErpInternal(bool enable); 344 int setByteArrayField( 345 const uint8_t* value, const size_t value_len, 346 uint8_t** to_update_field, size_t* to_update_field_len, 347 const char* hexdump_prefix, bool resetState); 348 void setTlsFlagsFor192BitMode(bool); 349 void generateTlsParams(); 350 351 // Reference to the global wpa_struct. This is assumed to be valid 352 // for the lifetime of the process. 353 struct wpa_global* wpa_global_; 354 // Name of the iface this network belongs to. 355 const std::string ifname_; 356 // Id of the network this aidl object controls. 357 const int network_id_; 358 bool is_valid_; 359 int tlsFlags; 360 361 DISALLOW_COPY_AND_ASSIGN(StaNetwork); 362 }; 363 364 } // namespace supplicant 365 } // namespace wifi 366 } // namespace hardware 367 } // namespace android 368 } // namespace aidl 369 370 #endif // WPA_SUPPLICANT_AIDL_STA_NETWORK_H 371