diff --git a/wifi/frameworks/js/napi/inc/wifi_napi_device.h b/wifi/frameworks/js/napi/inc/wifi_napi_device.h index 611330273ac52d83081fef4d2e30fde71a4eb730..59386087d1df65b246f71ddbe2065ff2160840eb 100644 --- a/wifi/frameworks/js/napi/inc/wifi_napi_device.h +++ b/wifi/frameworks/js/napi/inc/wifi_napi_device.h @@ -65,6 +65,15 @@ enum class ConnStateJs { UNKNOWN /* Failed to set up the Wi-Fi connection */ }; +enum class IpTypeJs { + /** Use statically configured IP settings */ + IP_TYPE_STATIC, + /** Use dynamically configured IP settings */ + IP_TYPE_DHCP, + /** No IP details are assigned */ + IP_TYPE_UNKNOWN, +}; + class ScanInfoAsyncContext : public AsyncContext { public: std::vector vecScanInfos; diff --git a/wifi/frameworks/js/napi/src/wifi_napi_device.cpp b/wifi/frameworks/js/napi/src/wifi_napi_device.cpp index ea724350ef3b2e7d9d29386059083624221eb4ab..83d782ad927e82e00c0431fa624fa596148546d2 100644 --- a/wifi/frameworks/js/napi/src/wifi_napi_device.cpp +++ b/wifi/frameworks/js/napi/src/wifi_napi_device.cpp @@ -311,9 +311,10 @@ static void JsObjToDeviceConfig(const napi_env& env, const napi_value& object, W /* "randomMacAddr" is not supported currently */ int ipType = static_cast(AssignIpMethod::UNASSIGNED); JsObjectToInt(env, object, "ipType", ipType); - if (AssignIpMethod(ipType) == AssignIpMethod::DHCP) { + WIFI_LOGI("JsObjToDeviceConfig, ipType: %{public}d.", ipType); + if (IpTypeJs(ipType) == IpTypeJs::IP_TYPE_DHCP) { cppConfig.wifiIpConfig.assignMethod = AssignIpMethod::DHCP; - } else if (AssignIpMethod(ipType) == AssignIpMethod::STATIC) { + } else if (IpTypeJs(ipType) == IpTypeJs::IP_TYPE_STATIC) { cppConfig.wifiIpConfig.assignMethod = AssignIpMethod::STATIC; ConfigStaticIp(env, object, cppConfig); } @@ -966,8 +967,13 @@ static void DeviceConfigToJsArray(const napi_env& env, std::vector(AssignIpMethod::DHCP), result); + if (vecDeviceConfigs[idx].wifiIpConfig.assignMethod == AssignIpMethod::STATIC) { + SetValueInt32(env, "ipType", static_cast(IpTypeJs::IP_TYPE_STATIC), result); + } else { + SetValueInt32(env, "ipType", static_cast(IpTypeJs::IP_TYPE_DHCP), result); + } + WIFI_LOGI("DeviceConfigToJsArray, idx:%{public}d, assignMethod:%{public}x!", + idx, static_cast(vecDeviceConfigs[idx].wifiIpConfig.assignMethod)); napi_value ipCfgObj; napi_create_object(env, &ipCfgObj); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp index 32fd33f2e9e5661b8b16a8a6aca5bfa47b533456..5fc474d56182e94f84ad85444349f8fbcab36e34 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp @@ -503,6 +503,11 @@ int StateMachineHandler::MoveSequenceToStateVector() void StateMachineHandler::SwitchState(State *targetState) { + if (targetState != nullptr) { + LOGE("targetState is null."); + return; + } + LOGE("SwitchState, Switch to targetState: %{public}s.", targetState->GetStateName().c_str()); pTargetState = static_cast(targetState); } @@ -535,8 +540,10 @@ void StateMachineHandler::PerformSwitchState(State *msgProcessedState, InternalM State *targetState = pTargetState; if (targetState != nullptr) { - LOGD("StateMachineHandler::PerformSwitchState targetState name is: %{public}s", - targetState->GetStateName().c_str()); + if (pFirstState != nullptr) { + LOGI("StateMachineHandler::PerformSwitchState, Switch %{public}s -->> %{public}s", + pFirstState->GetStateName().c_str(), targetState->GetStateName().c_str()); + } while (true) { StateInfo *commonStateInfo = BuildSequenceStateVector(targetState); mSwitchingStateFlag = true; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi.c b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi.c index 4d2601fe5fe96a1cb013594fa3f4147c52c7b4b0..f81e5d8e02b3e4cfb391781607ceafc54257a92b 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi.c +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi.c @@ -239,6 +239,22 @@ static void IdlCbkConnectChanged(Context *context) return; } +static void IdlCbkBssidChanged(Context *context) +{ + char reason[WIFI_REASON_LENGTH] = {0}; + char bssid[WIFI_BSSID_LENGTH] = {0}; + if (ReadStr(context, reason, sizeof(reason)) != 0 || + ReadStr(context, bssid, sizeof(bssid)) != 0) { + LOGE("Read event info error!"); + return; + } + IWifiEventCallback *callback = GetWifiEventCallback(); + if (callback != NULL && callback->onBssidChanged != NULL) { + callback->onBssidChanged(reason, bssid); + } + return; +} + static void IdlCbkApStateChange(Context *context, int event) { int id = 0; @@ -305,6 +321,9 @@ static int IdlDealStaApEvent(Context *context, int event) case WIFI_IDL_CBK_CMD_CONNECT_CHANGED: IdlCbkConnectChanged(context); break; + case WIFI_IDL_CBK_CMD_BSSID_CHANGED: + IdlCbkBssidChanged(context); + break; case WIFI_IDL_CBK_CMD_AP_ENABLE: case WIFI_IDL_CBK_CMD_AP_DISABLE: IdlCbkApStateChange(context, event); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_event_callback.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_event_callback.h index 8eb496c6ba6956d6b881d9b2794685e22e2c985d..4166b1b3820fe206497028087df5a3075de8d639 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_event_callback.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_event_callback.h @@ -27,6 +27,7 @@ typedef struct IWifiEventCallback { void (*onStopped)(void); void (*onFailure)(WifiErrorNo errCode); void (*onConnectChanged)(int status, int networkId, const char *bssid); + void (*onBssidChanged)(const char *reason, const char *bssid); void (*onWpaStateChanged)(int status); void (*onSsidWrongkey)(int status); void (*onWpsOverlap)(int status); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_sta_iface.c b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_sta_iface.c index f298a29d87273ea2ffa58fa5b5ac223d6a2f57d4..49df2ebcebab76970eeef327bbbdbc721433ca4f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_sta_iface.c +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_sta_iface.c @@ -579,6 +579,7 @@ static int CheckRegisterEvent(int *events, int size) WIFI_IDL_CBK_CMD_STARTED, WIFI_IDL_CBK_CMD_STOPED, WIFI_IDL_CBK_CMD_CONNECT_CHANGED, + WIFI_IDL_CBK_CMD_BSSID_CHANGED, WIFI_IDL_CBK_CMD_WPA_STATE_CHANGEM, WIFI_IDL_CBK_CMD_SSID_WRONG_KEY, WIFI_IDL_CBK_CMD_WPS_OVERLAP, diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_struct.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_struct.h index bb8474f878d2d0fdbc6de16767c6600ad66b81db..4416f47e5ccd3e199b04ee4f6265324f091342c7 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_struct.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/idl_interface/i_wifi_struct.h @@ -22,6 +22,7 @@ extern "C" { #endif #define WIFI_SSID_LENGTH 132 #define WIFI_BSSID_LENGTH 18 +#define WIFI_REASON_LENGTH 32 #define WIFI_NETWORK_FLAGS_LENGTH 64 #define WIFI_SCAN_INFO_CAPABILITIES_LENGTH 256 #define WIFI_NETWORK_CONFIG_NAME_LENGTH 64 diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_event_callback.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_event_callback.h index 213fe48a0f9952042c12e13e3cf0a6691c718e26..935dadf8d6b24768c55243b0ccc1085eecfb9012 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_event_callback.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_event_callback.h @@ -22,6 +22,7 @@ namespace OHOS { namespace Wifi { struct WifiEventCallback { std::function onConnectChanged; + std::function onBssidChanged; std::function onWpaStateChanged; std::function onWpaSsidWrongKey; std::function onWpsOverlap; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.cpp index c37babfa12ab5852919e93a12f016f3cc3c7c24b..ca86e747945409ca13d345b656ff65ba98f9fed6 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.cpp @@ -470,7 +470,7 @@ int WifiIdlClient::PushDeviceConfigAuthAlgorithm( } } if (alg & 0x2) { - if (strcat_s(pConfig->cfgValue, sizeof(pConfig->cfgValue), "SHARED ") != EOK) { + if (strcat_s(pConfig->cfgValue, sizeof(pConfig->cfgValue), "OPEN SHARED ") != EOK) { return 0; } } @@ -542,6 +542,19 @@ WifiErrorNo WifiIdlClient::SetDeviceConfig(int networkId, const WifiIdlDeviceCon return SetNetwork(networkId, conf, num); } +WifiErrorNo WifiIdlClient::SetWpsBssid(int networkId, const std::string &bssid) +{ + CHECK_CLIENT_NOT_NULL; + SetNetworkConfig conf; + int num = PushDeviceConfigString(&conf, DEVICE_CONFIG_BSSID, bssid); + if (num == 0) { + LOGE("SetWpsBssid, PushDeviceConfigString return error!"); + return WIFI_IDL_OPT_OK; + } + + return SetNetwork(networkId, &conf, num); +} + WifiErrorNo WifiIdlClient::SaveDeviceConfig(void) { CHECK_CLIENT_NOT_NULL; @@ -557,6 +570,7 @@ WifiErrorNo WifiIdlClient::ReqRegisterStaEventCallback(const WifiEventCallback & } if (callback.onConnectChanged != nullptr) { cEventCallback.onConnectChanged = OnConnectChanged; + cEventCallback.onBssidChanged = OnBssidChanged; cEventCallback.onWpaStateChanged = OnWpaStateChanged; cEventCallback.onSsidWrongkey = OnWpaSsidWrongKey; cEventCallback.onWpsOverlap = OnWpsOverlap; diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.h index 89481a5fcbb8918ffc7d6a615f425df4a89ad521..5787752a038d0e45cc376d0175c2c98eeaadbe6f 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_client.h @@ -268,6 +268,15 @@ public: */ WifiErrorNo SetDeviceConfig(int networkId, const WifiIdlDeviceConfig &config); + /** + * @Description Set bssid to supplicant. + * + * @param networkId + * @param bssid + * @return WifiErrorNo + */ + WifiErrorNo SetWpsBssid(int networkId, const std::string &bssid); + /** * @Description Save the network. * diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_define.h index 27261635a776313b7da6648951cd8437f9dd3a64..bba8361ee45a965b62eb21005f1baef81e01079d 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_define.h @@ -30,6 +30,7 @@ typedef enum WifiIdlEvent { /* SupplicantEventCallback */ WIFI_IDL_CBK_CMD_SCAN_INFO_NOTIFY, /* SCAN Scan Result Notification */ WIFI_IDL_CBK_CMD_CONNECT_CHANGED, /* Connection status change notification */ + WIFI_IDL_CBK_CMD_BSSID_CHANGED, /* bssid change notification */ WIFI_IDL_CBK_CMD_AP_ENABLE, /* AP enabling notification */ WIFI_IDL_CBK_CMD_AP_DISABLE, /* AP closure notification */ WIFI_IDL_CBK_CMD_WPA_STATE_CHANGEM, /* WPA status change notification */ diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.cpp index c61c33dfe339906c151eadc6397d0e27930c89c3..d72834940b5272b126df7cbbd071e1ea9dfe9c38 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.cpp @@ -70,6 +70,17 @@ void OnConnectChanged(int status, int networkId, const char *mac) } } +void OnBssidChanged(const char *reason, const char *bssid) +{ + if (reason == nullptr || bssid == nullptr) { + return; + } + const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); + if (cbk.onBssidChanged) { + cbk.onBssidChanged(reason, bssid); + } +} + void OnWpaStateChanged(int status) { const OHOS::Wifi::WifiEventCallback &cbk = OHOS::Wifi::WifiStaHalInterface::GetInstance().GetCallbackInst(); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.h index b066123597663663caab72408e7f5387c94c3543..e319e29e71312311a619fb6725d056b0ab3b7259 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_idl_inner_interface.h @@ -48,6 +48,7 @@ RpcClient *GetChipRpcClient(void); RpcClient *GetStaRpcClient(void); void OnConnectChanged(int status, int networkId, const char *mac); +void OnBssidChanged(const char *reason, const char *bssid); void OnWpaStateChanged(int status); void OnWpaSsidWrongKey(int status); void OnWpsOverlap(int status); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.cpp index ee0b4ebfcc850a4db4a3d88fb80fb14544c8a7aa..0a82f06a331690df104a15209a718d582c198f39 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.cpp @@ -242,6 +242,12 @@ WifiErrorNo WifiStaHalInterface::GetRoamingCapabilities(WifiIdlRoamCapability &c return mIdlClient->ReqGetRoamingCapabilities(capability); } +WifiErrorNo WifiStaHalInterface::SetWpsBssid(int networkId, const std::string &bssid) +{ + CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED); + return mIdlClient->SetWpsBssid(networkId, bssid); +} + WifiErrorNo WifiStaHalInterface::SetRoamConfig(const WifiIdlRoamConfig &config) { CHECK_NULL_AND_RETURN(mIdlClient, WIFI_IDL_OPT_FAILED); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.h index 9d035d35efc7f10a16a70d1e27e3e18d758bc85d..e66cc9aa51aca61c4e86abcd320ddbe17e7963e3 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/idl_client/wifi_sta_hal_interface.h @@ -286,6 +286,15 @@ public: */ WifiErrorNo GetRoamingCapabilities(WifiIdlRoamCapability &capability); + /** + * @Description Set bssid to supplicant. + * + * @param networkId + * @param bssid + * @return WifiErrorNo + */ + WifiErrorNo SetWpsBssid(int networkId, const std::string &bssid); + /** * @Description Setting Roaming Configurations. * diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index fd437f4b11c6fab27413f03cec40405ef58167bc..5f97b179ae5b62ea085edbf5a04eb06b031b5f06 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -303,7 +303,7 @@ InitStatus WifiManager::GetInitStatus() void WifiManager::CloseStaService(void) { - WIFI_LOGD("close sta service"); + WIFI_LOGI("close sta service"); WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_STA); WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::CLOSED); WifiConfigCenter::GetInstance().SetWifiStaCloseTime(); @@ -313,7 +313,7 @@ void WifiManager::CloseStaService(void) #ifdef FEATURE_AP_SUPPORT void WifiManager::CloseApService(int id) { - WIFI_LOGD("close %{public}d ap service", id); + WIFI_LOGI("close %{public}d ap service", id); WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_AP, id); WifiConfigCenter::GetInstance().SetApMidState(WifiOprMidState::CLOSED, id); WifiSettings::GetInstance().SetHotspotState(static_cast(ApState::AP_STATE_CLOSED), id); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp index 84b6b0e08eccef6f2a55b50d0510cecfda22debf..2828a2697a5f1e15e31516e6e0e9acbc01073f3b 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -24,7 +24,7 @@ namespace Wifi { StaAutoConnectService::StaAutoConnectService(StaStateMachine *staStateMachine) : pStaStateMachine(staStateMachine), pSavedDeviceAppraisal(nullptr), - firmwareRoamFlag(false), + firmwareRoamFlag(true), maxBlockedBssidNum(BLOCKLIST_INVALID_SIZE), selectDeviceLastTime(0), pAppraisals {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr} diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h index 73cf0f6f10babcaa64cf6233dc372ac664505a81..f1b90c927c45ebcb5e6450565f038f081cd1c0fa 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h @@ -60,6 +60,8 @@ namespace Wifi { #define WIFI_SVR_CMD_STA_WPA_PASSWD_WRONG_EVENT 0x3017 #define WIFI_SVR_CMD_STA_WPA_FULL_CONNECT_EVENT 0x3018 #define WIFI_SVR_CMD_STA_WPA_ASSOC_REJECT_EVENT 0x3019 +#define WIFI_SVR_CMD_STA_BSSID_CHANGED_EVENT 0x301A +#define WIFI_SVR_CMD_STA_DHCP_RESULT_NOTIFY_EVENT 0x301B #define WPA_BLOCK_LIST_CLEAR_EVENT 0x4001 diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp index 70f2204acb99e83c4842c783acaed50f4603ff99..8ad1dc4f3be79f02dcdd37a84d521ab930581932 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp @@ -37,6 +37,7 @@ ErrCode StaMonitor::InitStaMonitor() using namespace std::placeholders; WifiEventCallback callBack = { std::bind(&StaMonitor::OnConnectChangedCallBack, this, _1, _2, _3), + std::bind(&StaMonitor::OnBssidChangedCallBack, this, _1, _2), std::bind(&StaMonitor::OnWpaStateChangedCallBack, this, _1), std::bind(&StaMonitor::OnWpaSsidWrongKeyCallBack, this, _1), std::bind(&StaMonitor::OnWpsPbcOverlapCallBack, this, _1), @@ -87,8 +88,10 @@ void StaMonitor::OnConnectChangedCallBack(int status, int networkId, const std:: WifiLinkedInfo linkedInfo; pStaStateMachine->GetLinkedInfo(linkedInfo); /* P2P affects STA, causing problems or incorrect data updates */ - if ((linkedInfo.connState == ConnState::CONNECTED) && (linkedInfo.bssid != bssid)) { - WIFI_LOGI("Sta ignored the event for bssid is mismatch!"); + if ((linkedInfo.connState == ConnState::CONNECTED) && + (linkedInfo.bssid != bssid) && (!pStaStateMachine->IsRoaming())) { + WIFI_LOGI("Sta ignored the event for bssid is mismatch, isRoam:%{public}d.", + pStaStateMachine->IsRoaming()); return; } switch (status) { @@ -105,6 +108,30 @@ void StaMonitor::OnConnectChangedCallBack(int status, int networkId, const std:: } } +void StaMonitor::OnBssidChangedCallBack(const std::string &reason, const std::string &bssid) +{ + WIFI_LOGI("OnBssidChangedCallBack() reason:%{public}s,bssid=%{private}s", + reason.c_str(), + bssid.c_str()); + if (pStaStateMachine == nullptr) { + WIFI_LOGE("The statemachine pointer is null."); + return; + } + + WifiLinkedInfo linkedInfo; + pStaStateMachine->GetLinkedInfo(linkedInfo); + if (linkedInfo.connState != ConnState::CONNECTED) { + WIFI_LOGW("Sta ignored the event for NOT in connected status!, connState: %{public}d", + linkedInfo.connState); + return; + } + if (linkedInfo.bssid == bssid) { + WIFI_LOGW("Sta ignored the event for bssid is the same."); + return; + } + pStaStateMachine->OnBssidChangedEvent(reason, bssid); +} + void StaMonitor::OnWpaStateChangedCallBack(int status) { WIFI_LOGI("OnWpaStateChangedCallBack() status:%{public}d\n", status); diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h index d6b06670db43cc8f435c0c33edabc947e3c5ba0a..e011bd2ba8a136da4695d4dd70a102cc2a4a3f35 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h @@ -62,6 +62,14 @@ public: */ void OnConnectChangedCallBack(int status, int networkId,const std::string &bssid); + /** + * @Description : Callback of the connection state change event. + * + * @param reason : reason for bssid change [in] + * @param bssid: bssid of the network [in] + */ + void OnBssidChangedCallBack(const std::string &reason, const std::string &bssid); + /** * @Description : Callback of the wpa state change event. * diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp index 28d4e1db6a7aeef2a068b39848eaf32d520ad09b..0c12f32d4a42a3e66260a79c66e1acfae5e7f1f8 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp @@ -165,7 +165,7 @@ ErrCode StaStateMachine::InitStaStates() tmpErrNumber += JudgmentEmpty(pWpsState); pGetIpState = new (std::nothrow)GetIpState(this); tmpErrNumber += JudgmentEmpty(pGetIpState); - pLinkedState = new (std::nothrow)LinkedState(); + pLinkedState = new (std::nothrow)LinkedState(this); tmpErrNumber += JudgmentEmpty(pLinkedState); pApRoamingState = new (std::nothrow)ApRoamingState(this); tmpErrNumber += JudgmentEmpty(pApRoamingState); @@ -339,6 +339,11 @@ ErrCode StaStateMachine::ConvertDeviceCfg(const WifiDeviceConfig &config) const idlConfig.privateKey = config.wifiEapConfig.privateKey; idlConfig.phase2Method = static_cast(config.wifiEapConfig.phase2Method); idlConfig.wepKeyIdx = config.wepTxKeyIndex; + if (strcmp(config.keyMgmt.c_str(), "WEP") == 0) { + /* for wep */ + idlConfig.authAlgorithms = 0x02; + } + for (int i = 0; i < MAX_WEPKEYS_SIZE; i++) { idlConfig.wepKeys[i] = config.wepKeys[i]; } @@ -505,9 +510,11 @@ void StaStateMachine::WpaStartedState::GoOutState() bool StaStateMachine::WpaStartedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { + LOGI("msg is nullptr"); return false; } + WIFI_LOGI("WpaStartedState ExecuteStateMsg-msgCode:%{public}d.\n", msg->GetMessageName()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_DISABLE_WIFI: { @@ -856,11 +863,12 @@ void StaStateMachine::DealConnectionEvent(InternalMessage *msg) void StaStateMachine::DealDisconnectEvent(InternalMessage *msg) { - LOGD("Enter DealDisconnectEvent.\n"); + LOGI("Enter DealDisconnectEvent.\n"); if (msg == nullptr) { WIFI_LOGE("msg is null\n"); } if (wpsState != SetupMethod::INVALID) { + WIFI_LOGE("wpsState is INVALID\n"); return; } #ifndef OHOS_ARCH_LITE @@ -1320,10 +1328,16 @@ void StaStateMachine::StartRoamToNetwork(std::string bssid) SendMessage(msg); } +bool StaStateMachine::IsRoaming(void) +{ + return isRoam; +} + void StaStateMachine::OnNetworkConnectionEvent(int networkId, std::string bssid) { InternalMessage *msg = CreateMessage(); if (msg == nullptr) { + LOGE("msg is nullptr.\n"); return; } @@ -1333,6 +1347,33 @@ void StaStateMachine::OnNetworkConnectionEvent(int networkId, std::string bssid) SendMessage(msg); } +void StaStateMachine::OnBssidChangedEvent(std::string reason, std::string bssid) +{ + InternalMessage *msg = CreateMessage(); + if (msg == nullptr) { + LOGE("msg is nullptr.\n"); + return; + } + + msg->SetMessageName(WIFI_SVR_CMD_STA_BSSID_CHANGED_EVENT); + msg->AddStringMessageBody(reason); + msg->AddStringMessageBody(bssid); + SendMessage(msg); +} + +void StaStateMachine::OnDhcpResultNotifyEvent(bool result) +{ + InternalMessage *msg = CreateMessage(); + if (msg == nullptr) { + LOGE("msg is nullptr.\n"); + return; + } + + msg->SetMessageName(WIFI_SVR_CMD_STA_DHCP_RESULT_NOTIFY_EVENT); + msg->SetParam1(result); + SendMessage(msg); +} + /* --------------------------- state machine Separating State ------------------------------ */ StaStateMachine::SeparatingState::SeparatingState() : State("SeparatingState") {} @@ -1388,6 +1429,7 @@ bool StaStateMachine::SeparatedState::ExecuteStateMsg(InternalMessage *msg) return false; } + WIFI_LOGI("SeparatedState-msgCode=%{public}d received.\n", msg->GetMessageName()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_NETWORK_DISCONNECTION_EVENT: @@ -1434,6 +1476,7 @@ bool StaStateMachine::ApLinkedState::ExecuteStateMsg(InternalMessage *msg) return false; } + WIFI_LOGI("ApLinkedState-msgCode=%{public}d received.\n", msg->GetMessageName()); bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { /* The current state of StaStateMachine transfers to SeparatingState when @@ -1463,6 +1506,7 @@ bool StaStateMachine::ApLinkedState::ExecuteStateMsg(InternalMessage *msg) void StaStateMachine::DisConnectProcess() { + WIFI_LOGI("Enter DisConnectProcess!"); staCallback.OnStaConnChanged(OperateResState::DISCONNECT_DISCONNECTING, linkedInfo); if (WifiStaHalInterface::GetInstance().Disconnect() == WIFI_IDL_OPT_OK) { WIFI_LOGI("Disconnect() succeed!"); @@ -1617,13 +1661,14 @@ StaStateMachine::GetIpState::~GetIpState() void StaStateMachine::GetIpState::GoInState() { + WIFI_LOGI("GetIpState GoInState function."); #ifdef WIFI_DHCP_DISABLED SaveLinkstate(ConnState::CONNECTED, DetailedState::WORKING); staCallback.OnStaConnChanged(OperateResState::CONNECT_NETWORK_ENABLED, linkedInfo); SwitchState(pLinkedState); return; #endif - WIFI_LOGI("GetIpState GoInState function."); + pStaStateMachine->getIpSucNum = 0; WifiDeviceConfig config; AssignIpMethod assignMethod = AssignIpMethod::DHCP; int ret = WifiSettings::GetInstance().GetDeviceConfig(pStaStateMachine->linkedInfo.networkId, config); @@ -1686,7 +1731,20 @@ bool StaStateMachine::GetIpState::ExecuteStateMsg(InternalMessage *msg) } bool ret = NOT_EXECUTED; - WIFI_LOGI("GetIpState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + bool result = false; + WIFI_LOGI("GetIpState-msgCode=%{public}d received.\n", msg->GetMessageName()); + switch (msg->GetMessageName()) { + case WIFI_SVR_CMD_STA_DHCP_RESULT_NOTIFY_EVENT: { + ret = EXECUTED; + result = msg->GetParam1(); + WIFI_LOGI("GetIpState, get ip result:%{public}d.\n", result); + pStaStateMachine->SwitchState(pStaStateMachine->pLinkedState); + break; + } + default: + break; + } + return ret; } @@ -1743,9 +1801,9 @@ bool StaStateMachine::ConfigStaticIpAddress(StaticIpAddress &staticIpAddress) void StaStateMachine::HandleNetCheckResult(StaNetState netState, const std::string portalUrl) { - WIFI_LOGI("Enter HandleNetCheckResult"); - if (linkedInfo.connState == ConnState::DISCONNECTED) { - WIFI_LOGE("Network disconnected\n"); + WIFI_LOGI("Enter HandleNetCheckResult, netState:%{public}d.", netState); + if (linkedInfo.connState != ConnState::CONNECTED) { + WIFI_LOGE("connState is NOT in connected state, connState:%{public}d\n", linkedInfo.connState); return; } @@ -1754,8 +1812,6 @@ void StaStateMachine::HandleNetCheckResult(StaNetState netState, const std::stri /* Save connection information to WifiSettings. */ SaveLinkstate(ConnState::CONNECTED, DetailedState::WORKING); staCallback.OnStaConnChanged(OperateResState::CONNECT_NETWORK_ENABLED, linkedInfo); - /* The current state of StaStateMachine transfers to LinkedState. */ - SwitchState(pLinkedState); } else if (netState == StaNetState::NETWORK_CHECK_PORTAL) { linkedInfo.portalUrl = portalUrl; SaveLinkstate(ConnState::CONNECTED, DetailedState::CAPTIVE_PORTAL_CHECK); @@ -1768,8 +1824,8 @@ void StaStateMachine::HandleNetCheckResult(StaNetState netState, const std::stri } /* --------------------------- state machine Connected State ------------------------------ */ -StaStateMachine::LinkedState::LinkedState() - : State("LinkedState") +StaStateMachine::LinkedState::LinkedState(StaStateMachine *staStateMachine) + : State("LinkedState"), pStaStateMachine(staStateMachine) {} StaStateMachine::LinkedState::~LinkedState() @@ -1790,11 +1846,39 @@ void StaStateMachine::LinkedState::GoOutState() bool StaStateMachine::LinkedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { + WIFI_LOGI("msg is nullptr."); return false; } - WIFI_LOGI("LinkedState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); - return NOT_EXECUTED; + WIFI_LOGI("LinkedState, reveived msgCode=%{public}d msg.\n", msg->GetMessageName()); + bool ret = NOT_EXECUTED; + switch (msg->GetMessageName()) { + case WIFI_SVR_CMD_STA_BSSID_CHANGED_EVENT: { + ret = EXECUTED; + std::string reason = msg->GetStringFromMessage(); + std::string bssid = msg->GetStringFromMessage(); + WIFI_LOGI("reveived bssid changed event, reason:%{public}s,bssid:%{private}s.\n", + reason.c_str(), bssid.c_str()); + if (strcmp(reason.c_str(), "ASSOC_COMPLETE") != 0) { + WIFI_LOGE("Bssid change not for ASSOC_COMPLETE, do nothing."); + return false; + } + if (WifiStaHalInterface::GetInstance().SetWpsBssid(pStaStateMachine->linkedInfo.networkId, + bssid) != WIFI_IDL_OPT_OK) { + WIFI_LOGE("SetWpsBssid return fail."); + return false; + } + pStaStateMachine->isRoam = true; + /* The current state of StaStateMachine transfers to pApRoamingState. */ + pStaStateMachine->SwitchState(pStaStateMachine->pApRoamingState); + break; + } + default: + WIFI_LOGE("NOT handle this event!"); + break; + } + + return ret; } /* --------------------------- state machine Roaming State ------------------------------ */ @@ -1825,6 +1909,12 @@ bool StaStateMachine::ApRoamingState::ExecuteStateMsg(InternalMessage *msg) ret = EXECUTED; pStaStateMachine->isRoam = true; pStaStateMachine->StopTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT)); + /* Save linkedInfo */ + pStaStateMachine->linkedInfo.networkId = msg->GetParam1(); + pStaStateMachine->linkedInfo.bssid = msg->GetStringFromMessage(); + WIFI_LOGI("ApRoamingState, receive connection event, networkId:%{public}d, bssid:%{public}s.", + pStaStateMachine->linkedInfo.networkId, pStaStateMachine->linkedInfo.bssid.c_str()); + WifiSettings::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo); pStaStateMachine->staCallback.OnStaConnChanged( OperateResState::CONNECT_ASSOCIATED, pStaStateMachine->linkedInfo); pStaStateMachine->ConnectToNetworkProcess(msg); @@ -1969,7 +2059,7 @@ void StaStateMachine::DhcpResultNotify::OnSuccess(int status, const std::string return; } WIFI_LOGD("iptype=%{public}d, ip=%{private}s, gateway=%{private}s, \ - subnet=%{private}s, serverAddress=%{private}s, leaseDuration=%d", + subnet=%{private}s, serverAddress=%{private}s, leaseDuration=%{public}d", result.iptype, result.strYourCli.c_str(), result.strRouter1.c_str(), @@ -2017,6 +2107,7 @@ void StaStateMachine::DhcpResultNotify::OnSuccess(int status, const std::string WIFI_LOGI("DhcpResultNotify::OnSuccess, getIpSucNum=%{public}d, isRoam=%{public}d", pStaStateMachine->getIpSucNum, pStaStateMachine->isRoam); + pStaStateMachine->OnDhcpResultNotifyEvent(true); if (pStaStateMachine->getIpSucNum == 0 || pStaStateMachine->isRoam) { pStaStateMachine->SaveLinkstate(ConnState::CONNECTED, DetailedState::CONNECTED); pStaStateMachine->staCallback.OnStaConnChanged( @@ -2027,6 +2118,15 @@ void StaStateMachine::DhcpResultNotify::OnSuccess(int status, const std::string pStaStateMachine->pNetcheck->SignalNetCheckThread(); } pStaStateMachine->getIpSucNum++; + + WIFI_LOGI("DhcpResultNotify::OnSuccess, stop dhcp client"); + if (pStaStateMachine->pDhcpService != nullptr) { + if (pStaStateMachine->currentTpType == IPTYPE_IPV6) { + pStaStateMachine->pDhcpService->StopDhcpClient(IF_NAME, true); + } else { + pStaStateMachine->pDhcpService->StopDhcpClient(IF_NAME, false); + } + } return; } diff --git a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h index 7c93d8182aaa76ff519928976de5e7719322522b..449610dc5c47db67dfd2e572e5d3e1ec3b5d1b6c 100644 --- a/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h +++ b/wifi/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h @@ -105,7 +105,7 @@ public: */ class InitState : public State { public: - explicit InitState(StaStateMachine *pStaStateMachine); + explicit InitState(StaStateMachine *staStateMachine); ~InitState() override; void GoInState() override; void GoOutState() override; @@ -253,11 +253,14 @@ public: */ class LinkedState : public State { public: - explicit LinkedState(); + explicit LinkedState(StaStateMachine *staStateMachine); ~LinkedState() override; void GoInState() override; void GoOutState() override; bool ExecuteStateMsg(InternalMessage *msg) override; + + private: + StaStateMachine *pStaStateMachine; }; /** * @Description Definition of member function of ApRoamingState class in StaStateMachine. @@ -330,6 +333,10 @@ public: * @param bssid - the mac address of network(in) */ void StartRoamToNetwork(std::string bssid); + /** + * @Description if it is roaming now. + */ + bool IsRoaming(void); /** * @Description Connecting events * @@ -337,7 +344,19 @@ public: * @param bssid - bssid - the mac address of wifi(in) */ void OnNetworkConnectionEvent(int networkId, std::string bssid); - + /** + * @Description Bssid change events + * + * @param reason: the reason of bssid changed(in) + * @param bssid: the mac address of wifi(in) + */ + void OnBssidChangedEvent(std::string reason, std::string bssid); + /** + * @Description dhcp result notify events + * + * @param result: true-success, false-fail(in) + */ + void OnDhcpResultNotifyEvent(bool result); /** * @Description Register sta callback function * diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.c index c18fb3906f2b7c8079627c4505bf6a39d9a102fb..5c63794ab855f414b7196b16dbdda79553b1781e 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.c @@ -79,6 +79,31 @@ void WifiHalCbNotifyConnectChanged(int status, int networkId, const char *pos) return; } +void WifiHalCbNotifyBssidChanged(const char *reasonPos, const char *bssidPos) +{ + char reason[WIFI_REASON_LENGTH] = {0}; + if (reasonPos == NULL || bssidPos == NULL) { + LOGE("reasonPos or bssidPos is NULL"); + return; + } + char *reasonEnd = strchr(reasonPos, ' '); + if (reasonEnd != NULL) { + int reasonLen = reasonEnd - reasonPos; + reasonLen = reasonLen > WIFI_REASON_LENGTH ? WIFI_REASON_LENGTH : reasonLen; + (void)memcpy_s(reason, sizeof(reason), reasonPos, reasonLen); + } + + LOGI("bssid changed event, reason: %{public}s, bssid = %{private}s", reason, bssidPos); + WifiHalEventCallbackMsg *pCbkMsg = (WifiHalEventCallbackMsg *)calloc(1, sizeof(WifiHalEventCallbackMsg)); + if (pCbkMsg == NULL) { + LOGE("create callback message failed!"); + return; + } + (void)memcpy_s(pCbkMsg->msg.bssidChangedMsg.reason, WIFI_REASON_LENGTH, reason, WIFI_REASON_LENGTH); + (void)memcpy_s(pCbkMsg->msg.bssidChangedMsg.bssid, WIFI_MAC_LENGTH + 1, bssidPos, WIFI_MAC_LENGTH + 1); + EmitEventCallbackMsg(pCbkMsg, WIFI_BSSID_CHANGED_NOTIFY_EVENT); +} + void WifiHalCbNotifyWpaStateChange(int status) { LOGI("wpa state changed, state: %{public}d, and begin push notify message", status); diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.h index 9cff116138247ff6e2e8f0e8daa1c13d5c93666b..0dc4331e4041438a9b585d883c3f346211028548 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_callback.h @@ -27,7 +27,6 @@ extern "C" { * @param status */ void WifiHalCbNotifyScanEnd(int status); - /** * @Description Wi-Fi Hal callback notification of the connection change. * @@ -37,11 +36,18 @@ void WifiHalCbNotifyScanEnd(int status); */ void WifiHalCbNotifyConnectChanged(int status, int networkId, const char *pos); /** - * @Description The Wi-Fi Hal module notifies the WPA module of the status change. + * @Description Wi-Fi Hal module notifies the WPA module of the status change. * * @param status */ void WifiHalCbNotifyWpaStateChange(int status); +/** + * @Description Wi-Fi Hal module notifies the bssid change. + * + * @param reasonPos: reason in the return string + * @param bssidPos: bssid in the return string + */ +void WifiHalCbNotifyBssidChanged(const char *reasonPos, const char *bssidPos); /** * @Description Wi-Fi Hal callback notification error key. * diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c index 3120430f5ac6f43ac06a9481b13bc1fee707d32c..bb92a46aee2270ca9f339027d9fe52a52119c3fc 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c @@ -483,6 +483,16 @@ static void DealConnectionChangedCbk(int event, Context *context) return; } +static void DealBssidChangedCbk(int event, Context *context) +{ + WifiHalEventCallbackMsg *cbmsg = FrontCallbackMsg(event); + if (cbmsg != NULL) { + WriteStr(context, cbmsg->msg.bssidChangedMsg.reason); + WriteStr(context, cbmsg->msg.bssidChangedMsg.bssid); + } + return; +} + static void DealConnectWpsResultCbk(int event, Context *context) { WifiHalEventCallbackMsg *cbmsg = FrontCallbackMsg(event); @@ -516,7 +526,11 @@ static void DealStaApCallback(int event, Context *context) case WIFI_CONNECT_CHANGED_NOTIFY_EVENT: DealConnectionChangedCbk(event, context); break; + case WIFI_BSSID_CHANGED_NOTIFY_EVENT: + DealBssidChangedCbk(event, context); + break; default: + LOGE("DealStaApCallback, Invalid event: %{public}d", event); break; } return; diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.h index 606b93402df14378dcf6c6b28780381c64c66c99..ce95cc47c3331927c33df3778ce6b74feba6468d 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.h @@ -81,6 +81,11 @@ typedef struct WifiHalConnectMsg { char bssid[WIFI_MAC_LENGTH + 1]; } WifiHalConnectMsg; +typedef struct WifiHalBssidChangedMsg { + char reason[WIFI_REASON_LENGTH]; + char bssid[WIFI_MAC_LENGTH + 1]; +} WifiHalBssidChangedMsg; + typedef union WifiHalCallbackMsg { int scanStatus; WifiHalConnectMsg connMsg; @@ -90,6 +95,7 @@ typedef union WifiHalCallbackMsg { P2pInvitationInfo invitaInfo; P2pServDiscRespInfo serverInfo; P2pServDiscReqInfo serDiscReqInfo; + WifiHalBssidChangedMsg bssidChangedMsg; } WifiHalCallbackMsg; typedef struct WifiHalEventCallbackMsg { diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h index d2c5c44376dc8c7f6c56c2918c64271af8001743..177b086076f5a0ecf78b57887696ff6a0936fce5 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_define.h @@ -81,6 +81,7 @@ typedef enum WifiHalEvent { WIFI_STA_LEAVE_EVENT, /* STA disconnection notification in AP mode. */ WIFI_SCAN_INFO_NOTIFY_EVENT, /* Scan info notification. */ WIFI_CONNECT_CHANGED_NOTIFY_EVENT, /* Connection status change notification. */ + WIFI_BSSID_CHANGED_NOTIFY_EVENT, /* Bssid change notification. */ WIFI_AP_ENABLE_EVENT, /* AP enabling notification. */ WIFI_AP_DISABLE_EVENT, /* AP closure notification. */ WIFI_WPA_STATE_EVENT, /* WPA status change. */ @@ -123,6 +124,7 @@ typedef enum WifiHalEvent { #define WIFI_NETWORK_CONFIG_VALUE_LENGTH 256 #define WIFI_P2P_GROUP_CONFIG_VALUE_LENGTH 256 #define WIFI_MAC_LENGTH 17 +#define WIFI_REASON_LENGTH 32 #define WIFI_AP_PASSWORD_LENGTH 64 #define WIFI_PIN_CODE_LENGTH 8 diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wifi_wpa_hal.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wifi_wpa_hal.c index 773caaf4fe932fe92fb51560bf45ce3b4db61b93..0e5fc2adc0ee04f9b62356881bcae7072c8f197c 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wifi_wpa_hal.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wifi_wpa_hal.c @@ -46,6 +46,7 @@ #define WPA_CB_CONNECTED 1 #define WPA_CB_DISCONNECTED 2 #define WPS_EVENT_PBC_OVERLAP "WPS-OVERLAP-DETECTED PBC session overlap" +#define WPA_EVENT_BSSID_CHANGED "WPA-EVENT-BSSID-CHANGED " #define REPLY_BUF_LENGTH 4096 #define CONNECTION_FULL_STATUS 17 #define CONNECTION_REJECT_STATUS 37 @@ -606,6 +607,22 @@ static void WpaCallBackFunc(const char *p) } pBssid += strlen("bssid="); WifiHalCbNotifyConnectChanged(WPA_CB_DISCONNECTED, -1, pBssid); + /* bssid changed event */ + } else if (strncmp(p, WPA_EVENT_BSSID_CHANGED, strlen(WPA_EVENT_BSSID_CHANGED)) == 0) { + LOGI("Reveive WPA_EVENT_BSSID_CHANGED notify event"); + char *pBssid = strstr(p, "BSSID="); + if (pBssid == NULL) { + LOGE("NO bssid find!"); + return; + } + pBssid += strlen("BSSID="); + char *pReason = strstr(p, "REASON="); + if (pReason == NULL) { + LOGE("NO reason find!"); + return; + } + pReason += strlen("REASON="); + WifiHalCbNotifyBssidChanged(pReason, pBssid); } else { WpaCallBackFuncTwo(p); } diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c index 0c837d667ba903fbc41e0de738c2f9e365c6ea99..07ec383b584b2c0d6b7f41211181cdcce9e5ec40 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c @@ -481,6 +481,20 @@ static int WpaCliCmdPowerSave(WifiWpaStaInterface *this, int enable) return WpaCliCmd(cmd, buf, sizeof(buf)); } +static int WpaCliCmdSetRoamConfig(WifiWpaStaInterface *this, const char *bssid) +{ + if (this == NULL || bssid == NULL) { + return -1; + } + char buf[REPLY_BUF_SMALL_LENGTH] = {0}; + char cmd[CMD_BUFFER_SIZE] = {0}; + if (snprintf_s(cmd, sizeof(cmd), sizeof(cmd) - 1, "IFNAME=%s SET bssid %s", this->ifname, bssid) < 0) { + LOGE("snprintf err"); + return -1; + } + return WpaCliCmd(cmd, buf, sizeof(buf)); +} + static int WpaCliCmdSetCountryCode(WifiWpaStaInterface *this, const char *countryCode) { if (this == NULL || countryCode == NULL) { @@ -1253,6 +1267,7 @@ WifiWpaStaInterface *GetWifiStaInterface(int staNo) p->wpaCliCmdWpsPin = WpaCliCmdWpsPin; p->wpaCliCmdWpsCancel = WpaCliCmdWpsCancel; p->wpaCliCmdPowerSave = WpaCliCmdPowerSave; + p->wpaCliCmdSetRoamConfig = WpaCliCmdSetRoamConfig; p->wpaCliCmdSetCountryCode = WpaCliCmdSetCountryCode; p->wpaCliCmdGetCountryCode = WpaCliCmdGetCountryCode; p->wpaCliCmdSetAutoConnect = WpaCliCmdSetAutoConnect; diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h index 39a2078ec9ef9968575e41600007353c80a14db0..ef550032a755714e643fe9565a565f817fb85a2f 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h @@ -92,6 +92,7 @@ struct WifiWpaStaInterface { int (*wpaCliCmdWpsPin)(WifiWpaStaInterface *p, const struct WpaWpsPinArgv *wpspin, int *pincode); int (*wpaCliCmdWpsCancel)(WifiWpaStaInterface *p); int (*wpaCliCmdPowerSave)(WifiWpaStaInterface *p, int enable); + int (*wpaCliCmdSetRoamConfig)(WifiWpaStaInterface *p, const char *bssid); int (*wpaCliCmdSetCountryCode)(WifiWpaStaInterface *p, const char *countryCode); int (*wpaCliCmdGetCountryCode)(WifiWpaStaInterface *p, char *countryCode, int codeSize); int (*wpaCliCmdSetAutoConnect)(WifiWpaStaInterface *p, int enable); diff --git a/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c b/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c index 00321d7ba31f65b8981a0405851f15b56d79356f..a0952ceb818ed813589b548c35cc2e74f7d844dc 100644 --- a/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c +++ b/wifi/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c @@ -686,7 +686,7 @@ WifiErrorNo StopWps(void) WifiErrorNo GetRoamingCapabilities(WifiRoamCapability *capability) { - LOGD("GetRoamingCapabilities"); + LOGI("GetRoamingCapabilities"); if (capability == NULL) { return WIFI_HAL_FAILED; } @@ -695,8 +695,22 @@ WifiErrorNo GetRoamingCapabilities(WifiRoamCapability *capability) WifiErrorNo SetRoamConfig(char **blocklist, int blocksize, char **trustlist, int trustsize) { - LOGD("SetRoamConfig block size %{public}d, trust size %{public}d", blocksize, trustsize); - if (blocklist == NULL || trustlist == NULL) { + LOGI("SetRoamConfig, blocksize:%{public}d, trustsize:%{public}d", blocksize, trustsize); + if (trustlist != NULL && trustsize > 0) { + WifiWpaStaInterface *pStaIfc = GetWifiStaInterface(0); + if (pStaIfc == NULL) { + return WIFI_HAL_SUPPLICANT_NOT_INIT; + } + for (int i = 0; i < trustsize; i++) { + int ret = pStaIfc->wpaCliCmdSetRoamConfig(pStaIfc, trustlist[i]); + if (ret < 0) { + LOGE("wpaCliCmdSetRoamConfig failed! ret=%{public}d", ret); + return WIFI_HAL_FAILED; + } + } + } + + if (blocklist == NULL || blocksize <= 0) { return WIFI_HAL_SUCCESS; } return WIFI_HAL_SUCCESS;