From a4ef2a4f803c251c017dedc8a3b5f6efa1e7fad6 Mon Sep 17 00:00:00 2001 From: 18629082792 Date: Fri, 11 Jun 2021 11:17:42 +0800 Subject: [PATCH] I3VAG7 add band and rssi --- .../wifi_framework/common/log/wifi_log_tags.h | 28 + .../wifi_manage/common/state_machine.cpp | 496 +++++------ .../wifi_manage/common/state_machine.h | 270 +++--- .../wifi_manage/wifi_ap/ap_idle_state.cpp | 23 +- .../wifi_manage/wifi_ap/ap_idle_state.h | 8 +- .../wifi_manage/wifi_ap/ap_interface.cpp | 4 +- .../wifi_manage/wifi_ap/ap_monitor.cpp | 19 +- .../wifi_manage/wifi_ap/ap_root_state.cpp | 21 +- .../wifi_manage/wifi_ap/ap_root_state.h | 8 +- .../wifi_manage/wifi_ap/ap_service.cpp | 17 +- .../wifi_manage/wifi_ap/ap_started_state.cpp | 103 ++- .../wifi_manage/wifi_ap/ap_started_state.h | 10 +- .../wifi_manage/wifi_ap/ap_state_machine.cpp | 41 +- .../wifi_manage/wifi_ap/ap_state_machine.h | 3 - .../wifi_ap/ap_stations_manager.cpp | 27 +- .../wifi_ap/wifi_ap_dhcp_interface.cpp | 95 ++- .../wifi_ap/wifi_ap_nat_manager.cpp | 26 +- .../wifi_manage/wifi_device_stub.cpp | 12 - .../wifi_hotspot_callback_proxy.cpp | 2 +- .../wifi_hotspot_death_recipient.cpp | 2 +- .../wifi_manage/wifi_hotspot_service_impl.cpp | 2 +- .../wifi_manage/wifi_hotspot_stub.cpp | 2 +- .../wifi_manage/wifi_manager.cpp | 58 +- .../wifi_manage/wifi_scan/scan_common.h | 15 +- .../wifi_manage/wifi_scan/scan_interface.cpp | 62 +- .../wifi_manage/wifi_scan/scan_monitor.cpp | 16 +- .../wifi_manage/wifi_scan/scan_service.cpp | 399 ++++----- .../wifi_manage/wifi_scan/scan_service.h | 4 +- .../wifi_scan/scan_state_machine.cpp | 529 ++++++------ .../wifi_scan/scan_state_machine.h | 70 +- .../wifi_manage/wifi_scan_callback_proxy.cpp | 2 +- .../wifi_manage/wifi_scan_death_recipient.cpp | 2 +- .../wifi_manage/wifi_scan_service_impl.cpp | 2 +- .../wifi_manage/wifi_scan_stub.cpp | 5 +- .../wifi_manage/wifi_service_manager.cpp | 25 +- .../wifi_sta/sta_auto_connect_service.cpp | 612 ++++++++++++++ .../wifi_sta/sta_auto_connect_service.h | 235 ++++++ .../wifi_manage/wifi_sta/sta_define.h | 4 +- .../wifi_sta/sta_device_appraisal.h | 40 + .../wifi_manage/wifi_sta/sta_dhcp_server.cpp | 45 +- .../wifi_manage/wifi_sta/sta_interface.cpp | 58 +- .../wifi_manage/wifi_sta/sta_interface.h | 4 +- .../wifi_manage/wifi_sta/sta_monitor.cpp | 44 +- .../wifi_manage/wifi_sta/sta_monitor.h | 3 - .../wifi_sta/sta_network_check.cpp | 28 +- .../wifi_sta/sta_network_speed.cpp | 12 +- .../wifi_sta/sta_saved_device_appraisal.cpp | 194 +++++ .../wifi_sta/sta_saved_device_appraisal.h | 81 ++ .../wifi_manage/wifi_sta/sta_service.cpp | 100 ++- .../wifi_manage/wifi_sta/sta_service.h | 8 +- .../wifi_sta/sta_state_machine.cpp | 771 +++++++++--------- .../wifi_manage/wifi_sta/sta_state_machine.h | 188 ++--- .../wifi_hal/etc/init/hostapd.conf | 20 + .../wifi_hal/etc/init/wpa_supplicant.conf | 17 + .../wifi_hal/wifi_hal_chip_interface.c | 9 +- .../wifi_hal/wifi_hal_chip_interface.h | 8 - .../wifi_hal/wifi_hal_crpc_chip.c | 19 +- .../wifi_hal/wifi_hal_crpc_chip.h | 10 - .../wifi_hal/wifi_hal_crpc_server.c | 8 - .../wifi_hal/wifi_hal_crpc_sta.c | 108 +-- .../wifi_hal/wifi_hal_crpc_sta.h | 70 -- .../wifi_standard/wifi_hal/wifi_hal_define.h | 5 +- .../hostapd_hal/wifi_hostapd_hal.c | 3 +- .../hostapd_hal/wifi_hostapd_hal.h | 11 +- .../wpa_sta_hal/wifi_supplicant_hal.c | 2 +- .../wpa_sta_hal/wifi_supplicant_hal.h | 5 +- .../wifi_hal/wifi_hal_module_manage.c | 2 +- .../wifi_hal/wifi_hal_sta_interface.c | 42 - .../wifi_hal/wifi_hal_sta_interface.h | 56 -- 69 files changed, 2975 insertions(+), 2255 deletions(-) create mode 100644 services/wifi_standard/wifi_framework/common/log/wifi_log_tags.h create mode 100644 services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp create mode 100644 services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h create mode 100644 services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_device_appraisal.h create mode 100644 services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp create mode 100644 services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.h create mode 100644 services/wifi_standard/wifi_hal/etc/init/hostapd.conf create mode 100644 services/wifi_standard/wifi_hal/etc/init/wpa_supplicant.conf mode change 100644 => 100755 services/wifi_standard/wifi_hal/wifi_hal_module_manage.c diff --git a/services/wifi_standard/wifi_framework/common/log/wifi_log_tags.h b/services/wifi_standard/wifi_framework/common/log/wifi_log_tags.h new file mode 100644 index 000000000..f10c5a001 --- /dev/null +++ b/services/wifi_standard/wifi_framework/common/log/wifi_log_tags.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_WIFI_LOG_TAGS_H +#define OHOS_WIFI_LOG_TAGS_H + +namespace OHOS { +namespace Wifi { +const unsigned int LOG_ID_WIFI = 0xD001560; +const unsigned int LOG_ID_WIFI_HOTSPOT = LOG_ID_WIFI | 0x01; +const unsigned int LOG_ID_WIFI_SCAN = LOG_ID_WIFI | 0x02; +const unsigned int LOG_ID_WIFI_P2P = LOG_ID_WIFI | 0x03; +const unsigned int LOG_ID_WIFI_AWARE = LOG_ID_WIFI | 0x04; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp b/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp index da48d7b90..541a13715 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.cpp @@ -20,52 +20,51 @@ namespace OHOS { namespace Wifi { -static const int SM_QUIT_CMD = -1; static const int SM_INIT_CMD = -2; -StateMachine::StateMachine(const std::string &name) : pSmHandler(nullptr), mStateName(name) +StateMachine::StateMachine(const std::string &name) : pStateMachineHandler(nullptr), mStateName(name) {} StateMachine::~StateMachine() { LOGD("StateMachine::~StateMachine"); - if (pSmHandler != nullptr) { - delete pSmHandler; + if (pStateMachineHandler != nullptr) { + delete pStateMachineHandler; } } bool StateMachine::InitialStateMachine() { - pSmHandler = new (std::nothrow) SmHandler(this); - if (pSmHandler == nullptr) { - LOGE("pSmHandler alloc failed.\n"); + pStateMachineHandler = new (std::nothrow) StateMachineHandler(this); + if (pStateMachineHandler == nullptr) { + LOGE("pStateMachineHandler alloc failed.\n"); return false; } - if (!pSmHandler->InitialSmHandler()) { - LOGE("InitialSmHandler failed.\n"); + if (!pStateMachineHandler->InitialSmHandler()) { + LOGE("InitialStateMachineHandler failed.\n"); return false; } return true; } -void StateMachine::Start() +void StateMachine::StartStateMachine() { - if (pSmHandler == nullptr) { - LOGE("Start StateMachine failed, smHandler is nullptr!"); + if (pStateMachineHandler == nullptr) { + LOGE("Start StateMachine failed, pStateMachineHandler is nullptr!"); return; } - pSmHandler->CompleteConstruction(); + pStateMachineHandler->BuildTreeComplete(); return; } -void StateMachine::SetHandler(SmHandler *smHandler) +void StateMachine::SetHandler(StateMachineHandler *handler) { - pSmHandler = smHandler; + pStateMachineHandler = handler; } -void StateMachine::UnhandledMessage(InternalMessage *msg) +void StateMachine::NotExecutedMessage(InternalMessage *msg) { if (msg == nullptr) { return; @@ -73,78 +72,79 @@ void StateMachine::UnhandledMessage(InternalMessage *msg) LOGD("msg not handled msg:%{public}d", msg->GetMessageName()); } -void StateMachine::AddState(State *state, State *parent) +void StateMachine::StatePlus(State *state, State *upper) { - pSmHandler->AddState(state, parent); + pStateMachineHandler->StatePlus(state, upper); } -void StateMachine::RemoveState(State *state) +void StateMachine::StateDelete(State *state) { - pSmHandler->RemoveState(state); + pStateMachineHandler->StateDelete(state); } -void StateMachine::SetInitialState(State *initialState) +void StateMachine::SetFirstState(State *firstState) { - pSmHandler->SetInitialState(initialState); + pStateMachineHandler->SetFirstState(firstState); } -void StateMachine::TransitionTo(State *destState) + +void StateMachine::SwitchState(State *targetState) { - pSmHandler->TransitionTo(destState); + pStateMachineHandler->SwitchState(targetState); } -void StateMachine::DeferMessage(InternalMessage *msg) +void StateMachine::DelayMessage(InternalMessage *msg) { - pSmHandler->DeferMessage(msg); + pStateMachineHandler->DelayMessage(msg); } void StateMachine::StopHandlerThread() { - pSmHandler->StopHandlerThread(); + pStateMachineHandler->StopHandlerThread(); } -InternalMessage *StateMachine::ObtainMessage() +InternalMessage *StateMachine::CreateMessage() { - return MessageManage::GetInstance().Obtain(); + return MessageManage::GetInstance().CreateMessage(); } -InternalMessage *StateMachine::ObtainMessage(InternalMessage *orig) +InternalMessage *StateMachine::CreateMessage(InternalMessage *orig) { if (orig == nullptr) { return nullptr; } - return MessageManage::GetInstance().Obtain(orig); + return MessageManage::GetInstance().CreateMessage(orig); } -InternalMessage *StateMachine::ObtainMessage(int what) +InternalMessage *StateMachine::CreateMessage(int msgName) { - return MessageManage::GetInstance().Obtain(what); + return MessageManage::GetInstance().CreateMessage(msgName); } -InternalMessage *StateMachine::ObtainMessage(int what, int arg1) +InternalMessage *StateMachine::CreateMessage(int msgName, int param1) { - return MessageManage::GetInstance().Obtain(what, arg1, 0); + return MessageManage::GetInstance().CreateMessage(msgName, param1, 0); } -InternalMessage *StateMachine::ObtainMessage(int what, int arg1, int arg2) +InternalMessage *StateMachine::CreateMessage(int msgName, int param1, int param2) { - return MessageManage::GetInstance().Obtain(what, arg1, arg2); + return MessageManage::GetInstance().CreateMessage(msgName, param1, param2); } -void StateMachine::SendMessage(int what) +void StateMachine::SendMessage(int msgName) { - pSmHandler->SendMessage(ObtainMessage(what)); + pStateMachineHandler->SendMessage(CreateMessage(msgName)); return; } -void StateMachine::SendMessage(int what, int arg1) +void StateMachine::SendMessage(int msgName, int param1) { - pSmHandler->SendMessage(ObtainMessage(what, arg1)); + pStateMachineHandler->SendMessage(CreateMessage(msgName, param1)); return; } -void StateMachine::SendMessage(int what, int arg1, int arg2) +void StateMachine::SendMessage(int msgName, int param1, int param2) { - pSmHandler->SendMessage(ObtainMessage(what, arg1, arg2)); + pStateMachineHandler->SendMessage(CreateMessage(msgName, param1, param2)); return; } @@ -153,129 +153,106 @@ void StateMachine::SendMessage(InternalMessage *msg) if (msg == nullptr) { return; } - pSmHandler->SendMessage(msg); + pStateMachineHandler->SendMessage(msg); return; } -void StateMachine::SendMessageDelayed(int what, long delayMillis) +void StateMachine::MessageExecutedLater(int msgName, int64_t delayTimeMs) { - pSmHandler->SendMessageDelayed(ObtainMessage(what), delayMillis); + pStateMachineHandler->MessageExecutedLater(CreateMessage(msgName), delayTimeMs); return; } -void StateMachine::SendMessageDelayed(int what, int arg1, long delayMillis) +void StateMachine::MessageExecutedLater(int msgName, int param1, int64_t delayTimeMs) { - pSmHandler->SendMessageDelayed(ObtainMessage(what, arg1), delayMillis); + pStateMachineHandler->MessageExecutedLater(CreateMessage(msgName, param1), delayTimeMs); return; } -void StateMachine::SendMessageDelayed(int what, int arg1, int arg2, long delayMillis) +void StateMachine::MessageExecutedLater(int msgName, int param1, int param2, int64_t delayTimeMs) { - pSmHandler->SendMessageDelayed(ObtainMessage(what, arg1, arg2), delayMillis); + pStateMachineHandler->MessageExecutedLater(CreateMessage(msgName, param1, param2), delayTimeMs); return; } -void StateMachine::SendMessageDelayed(InternalMessage *msg, long delayMillis) +void StateMachine::MessageExecutedLater(InternalMessage *msg, int64_t delayTimeMs) { - pSmHandler->SendMessageDelayed(msg, delayMillis); + pStateMachineHandler->MessageExecutedLater(msg, delayTimeMs); return; } -void StateMachine::StartTimer(int timerName, long interval) +void StateMachine::StartTimer(int timerName, int64_t interval) { - LOGD("Enter StateMachine::StartTimer, timerName is %{public}d, interval is %ld.", timerName, interval); - SendMessageDelayed(timerName, interval); + LOGD("Enter StateMachine::StartTimer, timerName is %{public}d, interval is %lld.", timerName, interval); + MessageExecutedLater(timerName, interval); return; } void StateMachine::StopTimer(int timerName) { LOGD("Enter StateMachine::StopTimer, timerName is %{public}d.", timerName); - pSmHandler->DeleteMessageFromQueue(timerName); + pStateMachineHandler->DeleteMessageFromQueue(timerName); return; } -SmHandler::SmHandler(StateMachine *pStateMgr) -{ - mStateInfo.clear(); - mStateList.clear(); - mStateListTopIndex = -1; - mSequenceStateList.clear(); - mSequenceStateListCount = 0; - mDeferredMessages.clear(); - pSM = pStateMgr; - pInitialState = nullptr; - pDestState = nullptr; - mHasQuit = false; - mIsConstructionCompleted = false; - mTransitionInProgress = false; +StateMachineHandler::StateMachineHandler(StateMachine *pStateMgr) +{ + mStateInfoMap.clear(); + mStateVector.clear(); + mStateVectorTopIndex = -1; + mSequenceStateVector.clear(); + mSequenceStateVectorCount = 0; + mDelayedMessages.clear(); + pStateMachine = pStateMgr; + pFirstState = nullptr; + pTargetState = nullptr; + mQuitFlag = false; + mBuildCompleteFlag = false; + mSwitchingStateFlag = false; pCurrentMsg = nullptr; - pQuittingState = nullptr; - pHaltingState = nullptr; } -SmHandler::~SmHandler() +StateMachineHandler::~StateMachineHandler() { - LOGD("SmHandler::~SmHandler"); - if (pQuittingState != nullptr) { - delete pQuittingState; - } - - if (pHaltingState != nullptr) { - delete pHaltingState; - } - + LOGD("StateMachineHandler::~StateMachineHandler"); StopHandlerThread(); - ReleaseDeferredMessages(); - CleanupAfterQuitting(); - + ReleaseDelayedMessages(); + ClearWhenQuit(); return; } -bool SmHandler::InitialSmHandler() +bool StateMachineHandler::InitialSmHandler() { if (!InitialHandler()) { return false; } - - pQuittingState = new (std::nothrow) QuittingState(); - if (pQuittingState == nullptr) { - LOGE("Failed to init quitting state!"); - return false; - } - - pHaltingState = new (std::nothrow) HaltingState(); - if (pHaltingState == nullptr) { - LOGE("Failed to init halting state!"); - return false; - } - return true; } -StateInfo *SmHandler::AddState(State *state, State *parent) +StateInfo *StateMachineHandler::StatePlus(State *state, State *upper) { - LOGD("SmHandler::AddState function."); + LOGD("StateMachineHandler::StatePlus function."); - StateInfo *parentStateInfo = nullptr; - StateInfoMap::iterator it = mStateInfo.begin(); - if (parent != nullptr) { - it = mStateInfo.find(parent->GetName()); - if (it != mStateInfo.end()) { - parentStateInfo = it->second; + StateInfo *upperStateInfo = nullptr; + StateInfoMap::iterator it = mStateInfoMap.begin(); + if (upper != nullptr) { + it = mStateInfoMap.find(upper->GetStateName()); + if (it != mStateInfoMap.end()) { + upperStateInfo = it->second; } - if (parentStateInfo == nullptr) { - LOGD("parentStateInfo is null, add parent first. parent->GetName():%{public}s", parent->GetName().c_str()); - /* Recursively add our parent as it's not been added yet. */ - AddState(parent, nullptr); + if (upperStateInfo == nullptr) { + LOGD("upperStateInfo is null, add upper first. upper->GetStateName():%{public}s", + upper->GetStateName().c_str()); + /* Recursively add our upper as it's not been added yet. */ + StatePlus(upper, nullptr); } else { - LOGD("parentStateInfo is not null, go on."); + LOGD("upperStateInfo is not null, go on."); } } StateInfo *stateInfo = nullptr; - it = mStateInfo.find(state->GetName()); - if (it != mStateInfo.end()) { + it = mStateInfoMap.find(state->GetStateName()); + if (it != mStateInfoMap.end()) { stateInfo = it->second; } if (stateInfo == nullptr) { @@ -284,16 +261,16 @@ StateInfo *SmHandler::AddState(State *state, State *parent) LOGE("failed to new StateInfo!"); return nullptr; } - mStateInfo.insert(StateInfoMap::value_type(state->GetName(), stateInfo)); + mStateInfoMap.insert(StateInfoMap::value_type(state->GetStateName(), stateInfo)); } /* Validate that we aren't adding the same state in two different hierarchies. */ - if (stateInfo->parentStateInfo != nullptr && stateInfo->parentStateInfo != parentStateInfo) { + if (stateInfo->upperStateInfo != nullptr && stateInfo->upperStateInfo != upperStateInfo) { LOGE("The same state cannot be added to two different hierarchies!"); } stateInfo->state = state; - stateInfo->parentStateInfo = parentStateInfo; + stateInfo->upperStateInfo = upperStateInfo; stateInfo->active = false; LOGD("successfully added a new state!"); @@ -301,49 +278,49 @@ StateInfo *SmHandler::AddState(State *state, State *parent) return stateInfo; } -void SmHandler::RemoveState(State *state) +void StateMachineHandler::StateDelete(State *state) { - StateInfoMap::iterator it = mStateInfo.find(state->GetName()); + StateInfoMap::iterator it = mStateInfoMap.find(state->GetStateName()); StateInfo *stateInfo = nullptr; - if (it != mStateInfo.end()) { + if (it != mStateInfoMap.end()) { stateInfo = it->second; } if (stateInfo == nullptr || stateInfo->active) { return; } - it = mStateInfo.begin(); - while (it != mStateInfo.end()) { - if (it->second->parentStateInfo == stateInfo) { + it = mStateInfoMap.begin(); + while (it != mStateInfoMap.end()) { + if (it->second->upperStateInfo == stateInfo) { return; } ++it; } - it = mStateInfo.find(state->GetName()); - if (it != mStateInfo.end()) { + it = mStateInfoMap.find(state->GetStateName()); + if (it != mStateInfoMap.end()) { delete it->second; it->second = nullptr; - mStateInfo.erase(it); + mStateInfoMap.erase(it); } } -void SmHandler::SetInitialState(State *initialState) +void StateMachineHandler::SetFirstState(State *firstState) { - pInitialState = initialState; + pFirstState = firstState; } -void SmHandler::CompleteConstruction() +void StateMachineHandler::BuildTreeComplete() { /* Determines the maximum depth of the state hierarchy. */ int maxDepth = 0; - StateInfoMap::iterator it = mStateInfo.begin(); - while (it != mStateInfo.end()) { + StateInfoMap::iterator it = mStateInfoMap.begin(); + while (it != mStateInfoMap.end()) { int depth = 0; StateInfo *tempStateInfo = it->second; while (tempStateInfo != nullptr) { depth++; - tempStateInfo = tempStateInfo->parentStateInfo; + tempStateInfo = tempStateInfo->upperStateInfo; } if (maxDepth < depth) { @@ -353,49 +330,45 @@ void SmHandler::CompleteConstruction() ++it; } - LOGD("SmHandler::CompleteConstruction, maxDepth:%{public}d", maxDepth); - mStateList.reserve(maxDepth); - mSequenceStateList.reserve(maxDepth); - - SetupInitialStateVector(); - - SendMessageAtTime(pSM->ObtainMessage(SM_INIT_CMD), 0); - + LOGD("StateMachineHandler::BuildTreeComplete, maxDepth:%{public}d", maxDepth); + mStateVector.reserve(maxDepth); + mSequenceStateVector.reserve(maxDepth); + BuildStateInitVector(); + MessageExecutedAtTime(pStateMachine->CreateMessage(SM_INIT_CMD), 0); return; } -void SmHandler::SetupInitialStateVector() +void StateMachineHandler::BuildStateInitVector() { - LOGD("SmHandler::SetupInitialStateVector"); + LOGD("StateMachineHandler::BuildStateInitVector"); - if (pInitialState == nullptr) { - LOGE("SmHandler::SetupInitialStateVector please set initial state first!"); + if (pFirstState == nullptr) { + LOGE("StateMachineHandler::BuildStateInitVector please set initial state first!"); return; } - StateInfoMap::iterator it = mStateInfo.find(pInitialState->GetName()); + StateInfoMap::iterator it = mStateInfoMap.find(pFirstState->GetStateName()); StateInfo *startStateInfo = nullptr; - if (it != mStateInfo.end()) { + if (it != mStateInfoMap.end()) { startStateInfo = it->second; } - for (mSequenceStateListCount = 0; startStateInfo != nullptr; mSequenceStateListCount++) { - mSequenceStateList[mSequenceStateListCount] = startStateInfo; - startStateInfo = startStateInfo->parentStateInfo; + for (mSequenceStateVectorCount = 0; startStateInfo != nullptr; mSequenceStateVectorCount++) { + mSequenceStateVector[mSequenceStateVectorCount] = startStateInfo; + startStateInfo = startStateInfo->upperStateInfo; } - /* Clearing the stateList. */ - mStateListTopIndex = -1; - - MoveSequenceStateListToStateList(); + /* Clearing the StateVector. */ + mStateVectorTopIndex = -1; + MoveSequenceToStateVector(); } -StateInfo *SmHandler::SetupTempStateStackWithStatesToEnter(State *destState) +StateInfo *StateMachineHandler::BuildSequenceStateVector(State *targetState) { - mSequenceStateListCount = 0; - StateInfoMap::iterator it = mStateInfo.find(destState->GetName()); + mSequenceStateVectorCount = 0; + StateInfoMap::iterator it = mStateInfoMap.find(targetState->GetStateName()); StateInfo *curStateInfo = nullptr; - if (it != mStateInfo.end()) { + if (it != mStateInfoMap.end()) { curStateInfo = it->second; } @@ -404,246 +377,227 @@ StateInfo *SmHandler::SetupTempStateStackWithStatesToEnter(State *destState) } do { - mSequenceStateList[mSequenceStateListCount++] = curStateInfo; - curStateInfo = curStateInfo->parentStateInfo; + mSequenceStateVector[mSequenceStateVectorCount++] = curStateInfo; + curStateInfo = curStateInfo->upperStateInfo; } while ((curStateInfo != nullptr) && (!curStateInfo->active)); return curStateInfo; } -void SmHandler::MoveDeferredMessageAtFrontOfQueue() +void StateMachineHandler::PlaceDelayedMsgQueueTop() { - LOGD("Enter SmHandler::MoveDeferredMessageAtFrontOfQueue."); + LOGD("Enter StateMachineHandler::PlaceDelayedMsgQueueTop."); - for (int i = mDeferredMessages.size() - 1; i >= 0; i--) { - InternalMessage *curMsg = mDeferredMessages[i]; + for (int i = mDelayedMessages.size() - 1; i >= 0; i--) { + InternalMessage *curMsg = mDelayedMessages[i]; if (curMsg == nullptr) { - LOGE("SmHandler::MoveDeferredMessageAtFrontOfQueue: curMsg is null."); + LOGE("StateMachineHandler::PlaceDelayedMsgQueueTop: curMsg is null."); continue; } - SendMessageAtFrontOfQueue(curMsg); + PlaceMessageTopOfQueue(curMsg); } - mDeferredMessages.clear(); + mDelayedMessages.clear(); return; } -void SmHandler::ReleaseDeferredMessages() +void StateMachineHandler::ReleaseDelayedMessages() { - for (int i = mDeferredMessages.size() - 1; i >= 0; i--) { - InternalMessage *curMsg = mDeferredMessages[i]; + for (int i = mDelayedMessages.size() - 1; i >= 0; i--) { + InternalMessage *curMsg = mDelayedMessages[i]; if (curMsg != nullptr) { delete curMsg; } } - mDeferredMessages.clear(); + mDelayedMessages.clear(); return; } -int SmHandler::MoveSequenceStateListToStateList() +int StateMachineHandler::MoveSequenceToStateVector() { - LOGD("SmHandler::MoveSequenceStateListToStateList mSequenceStateListCount:%{public}d", mSequenceStateListCount); + LOGD("StateMachineHandler::MoveSequenceToStateVector mSequenceStateVectorCount:%{public}d", + mSequenceStateVectorCount); - int newIndex = mStateListTopIndex + 1; - int i = mSequenceStateListCount - 1; + int newIndex = mStateVectorTopIndex + 1; + int i = mSequenceStateVectorCount - 1; int j = newIndex; while (i >= 0) { - mStateList[j] = mSequenceStateList[i]; + mStateVector[j] = mSequenceStateVector[i]; j += 1; i -= 1; } - mStateListTopIndex = j - 1; - + mStateVectorTopIndex = j - 1; return newIndex; } -void SmHandler::TransitionTo(State *destState) +void StateMachineHandler::SwitchState(State *targetState) { - pDestState = static_cast(destState); + pTargetState = static_cast(targetState); } -void SmHandler::CleanupAfterQuitting() +void StateMachineHandler::ClearWhenQuit() { - pSM->SetHandler(nullptr); - pSM = nullptr; + pStateMachine->SetHandler(nullptr); + pStateMachine = nullptr; pCurrentMsg = nullptr; - mStateList.clear(); - mSequenceStateList.clear(); - mDeferredMessages.clear(); - pInitialState = nullptr; - pDestState = nullptr; - mHasQuit = true; - - StateInfoMap::iterator it = mStateInfo.begin(); - while (it != mStateInfo.end()) { + mStateVector.clear(); + mSequenceStateVector.clear(); + mDelayedMessages.clear(); + pFirstState = nullptr; + pTargetState = nullptr; + mQuitFlag = true; + + StateInfoMap::iterator it = mStateInfoMap.begin(); + while (it != mStateInfoMap.end()) { delete it->second; it->second = nullptr; - it = mStateInfo.erase(it); + it = mStateInfoMap.erase(it); } - mStateInfo.clear(); + mStateInfoMap.clear(); } -void SmHandler::PerformTransitions(State *msgProcessedState, InternalMessage *msg) +void StateMachineHandler::PerformSwitchState(State *msgProcessedState, InternalMessage *msg) { if (msgProcessedState == nullptr || msg == nullptr) { LOGE("poniter is null."); } - State *destState = pDestState; - - if (destState != nullptr) { - LOGD("SmHandler::PerformTransitions destState name is: %{public}s", destState->GetName().c_str()); + State *targetState = pTargetState; + if (targetState != nullptr) { + LOGD("StateMachineHandler::PerformSwitchState targetState name is: %{public}s", + targetState->GetStateName().c_str()); while (true) { - StateInfo *commonStateInfo = SetupTempStateStackWithStatesToEnter(destState); - mTransitionInProgress = true; - InvokeExitMethods(commonStateInfo); + StateInfo *commonStateInfo = BuildSequenceStateVector(targetState); + mSwitchingStateFlag = true; + CallTreeStateExits(commonStateInfo); - int stateListEnteringIndex = MoveSequenceStateListToStateList(); - InvokeEnterMethods(stateListEnteringIndex); + int stateListEnteringIndex = MoveSequenceToStateVector(); + CallTreeStateEnters(stateListEnteringIndex); - MoveDeferredMessageAtFrontOfQueue(); + PlaceDelayedMsgQueueTop(); - if (destState != pDestState) { - destState = pDestState; + if (targetState != pTargetState) { + targetState = pTargetState; } else { break; } } - pDestState = nullptr; - } - - if (destState != nullptr) { - if (destState->GetName() == pQuittingState->GetName()) { - pSM->OnQuitting(); - CleanupAfterQuitting(); - } else if (destState->GetName() == pHaltingState->GetName()) { - pSM->OnHalting(); - } + pTargetState = nullptr; } return; } -void SmHandler::HandleMessage(InternalMessage *msg) +void StateMachineHandler::ExecuteMessage(InternalMessage *msg) { if (msg == nullptr) { return; } - if (!mHasQuit) { - if (pSM != nullptr && msg->GetMessageName() != SM_INIT_CMD && msg->GetMessageName() != SM_QUIT_CMD) { + if (!mQuitFlag) { + if (pStateMachine != nullptr && msg->GetMessageName() != SM_INIT_CMD) { } pCurrentMsg = msg; State *msgProcessedState = nullptr; - if (mIsConstructionCompleted) { - LOGD("SmHandler::HandleMessage ProcessMsg!"); - msgProcessedState = ProcessMsg(msg); - } else if (!mIsConstructionCompleted && msg->GetMessageName() == SM_INIT_CMD) { - LOGD("SmHandler::HandleMessage msg: SM_INIT_CMD"); - mIsConstructionCompleted = true; - InvokeEnterMethods(0); + if (mBuildCompleteFlag) { + LOGD("StateMachineHandler::ExecuteMessage ExecuteTreeStateMsg!"); + msgProcessedState = ExecuteTreeStateMsg(msg); + } else if (!mBuildCompleteFlag && msg->GetMessageName() == SM_INIT_CMD) { + LOGD("StateMachineHandler::ExecuteMessage msg: SM_INIT_CMD"); + mBuildCompleteFlag = true; + CallTreeStateEnters(0); } else { LOGE("The start method not called!"); } - if (pSM != nullptr) { - PerformTransitions(msgProcessedState, msg); + if (pStateMachine != nullptr) { + PerformSwitchState(msgProcessedState, msg); } else { LOGE("poniter is null."); } - if (pSM != nullptr && msg->GetMessageName() != SM_INIT_CMD && msg->GetMessageName() != SM_QUIT_CMD) { + if (pStateMachine != nullptr && msg->GetMessageName() != SM_INIT_CMD) { } } return; } -void SmHandler::DeferMessage(InternalMessage *msg) +void StateMachineHandler::DelayMessage(InternalMessage *msg) { + LOGD("Enter StateMachineHandler::DelayMessage."); if (msg == nullptr) { return; } - LOGD("Enter SmHandler::DeferMessage."); - InternalMessage *newMsg = pSM->ObtainMessage(msg); + InternalMessage *newMsg = pStateMachine->CreateMessage(msg); if (newMsg == nullptr) { - LOGE("SmHandler::DeferMessage: newMsg is null."); + LOGE("StateMachineHandler::DelayMessage: newMsg is null."); return; } - - mDeferredMessages.push_back(newMsg); + mDelayedMessages.push_back(newMsg); return; } -State *SmHandler::ProcessMsg(InternalMessage *msg) +State *StateMachineHandler::ExecuteTreeStateMsg(InternalMessage *msg) { + LOGD("StateMachineHandler::ExecuteTreeStateMsg mStateVectorTopIndex:%{public}d", mStateVectorTopIndex); if (msg == nullptr) { return nullptr; } - LOGD("SmHandler::ProcessMsg mStateListTopIndex:%{public}d", mStateListTopIndex); - StateInfo *curStateInfo = mStateList[mStateListTopIndex]; + + StateInfo *curStateInfo = mStateVector[mStateVectorTopIndex]; if (curStateInfo == nullptr) { LOGE("StateInfo is null."); return nullptr; } - if (IsQuit(msg)) { - TransitionTo(static_cast(pQuittingState)); - } else { - while (curStateInfo->state && (!curStateInfo->state->ProcessMessage(msg))) { - curStateInfo = curStateInfo->parentStateInfo; + while (curStateInfo->state && (!curStateInfo->state->ExecuteStateMsg(msg))) { + curStateInfo = curStateInfo->upperStateInfo; - if (curStateInfo == nullptr) { - pSM->UnhandledMessage(msg); - break; - } + if (curStateInfo == nullptr) { + pStateMachine->NotExecutedMessage(msg); + break; } } return (curStateInfo != nullptr) ? curStateInfo->state : nullptr; } -void SmHandler::InvokeExitMethods(StateInfo *commonStateInfo) +void StateMachineHandler::CallTreeStateExits(StateInfo *commonStateInfo) { - while ((mStateListTopIndex >= 0) && (mStateList[mStateListTopIndex] != commonStateInfo)) { - if (mStateList[mStateListTopIndex] != nullptr) { - State *curState = mStateList[mStateListTopIndex]->state; + while ((mStateVectorTopIndex >= 0) && (mStateVector[mStateVectorTopIndex] != commonStateInfo)) { + if (mStateVector[mStateVectorTopIndex] != nullptr) { + State *curState = mStateVector[mStateVectorTopIndex]->state; if (curState != nullptr) { - curState->Exit(); + curState->GoOutState(); } - mStateList[mStateListTopIndex]->active = false; + mStateVector[mStateVectorTopIndex]->active = false; } - mStateListTopIndex -= 1; + mStateVectorTopIndex -= 1; } } -void SmHandler::InvokeEnterMethods(int index) +void StateMachineHandler::CallTreeStateEnters(int index) { - for (int i = index; i <= mStateListTopIndex; i++) { - if (index == mStateListTopIndex) { + for (int i = index; i <= mStateVectorTopIndex; i++) { + if (index == mStateVectorTopIndex) { /* Last enter state for transition. */ - mTransitionInProgress = false; + mSwitchingStateFlag = false; } - LOGD("SmHandler::InvokeEnterMethods mStateListTopIndex:%{public}d, i: %{public}d", mStateListTopIndex, i); - if (mStateList[i] != nullptr && mStateList[i]->state != nullptr) { - mStateList[i]->state->Enter(); - mStateList[i]->active = true; + LOGD("StateMachineHandler::CallTreeStateEnters mStateVectorTopIndex:%{public}d, i: %{public}d", + mStateVectorTopIndex, + i); + if (mStateVector[i] != nullptr && mStateVector[i]->state != nullptr) { + mStateVector[i]->state->GoInState(); + mStateVector[i]->active = true; } } /* ensure flag set to false if no methods called. */ - mTransitionInProgress = false; -} - -bool SmHandler::IsQuit(InternalMessage *msg) -{ - if (msg == nullptr) { - return false; - } - return (msg->GetMessageName() == SM_QUIT_CMD); + mSwitchingStateFlag = false; } } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.h b/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.h index e36181d2f..00900cbad 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/common/state_machine.h @@ -27,15 +27,15 @@ namespace OHOS { namespace Wifi { #define CMD_SET_OPERATIONAL_MODE 1 /* Message Processed */ -static const bool HANDLED = true; +static const bool EXECUTED = true; /* The message is not processed. */ -static const bool NOT_HANDLED = false; +static const bool NOT_EXECUTED = false; -class SmHandler; +class StateMachineHandler; class StateMachine { public: /** - * @Description : SmHandler Initialization Function + * @Description : StateMachine Initialization Function * * @return true :success, false : failed. */ @@ -45,23 +45,21 @@ public: * @Description : Start StateMachine. * */ - void Start(); - virtual void OnQuitting() = 0; - virtual void OnHalting() = 0; + void StartStateMachine(); /** * @Description : Set Handler. * - * @param smHandler - SmHandler instance.[in] + * @param handler - StateMachineHandler instance.[in] */ - void SetHandler(SmHandler *smHandler); + void SetHandler(StateMachineHandler *handler); /** * @Description : The Message is not handled. * * @param msg - Message object.[in] */ - void UnhandledMessage(InternalMessage *msg); + void NotExecutedMessage(InternalMessage *msg); /** * @Description Stop Handler Thread. @@ -75,7 +73,7 @@ public: * @param timerName - Timer Name.[in] * @param interval - Timer duration, in milliseconds.[in] */ - void StartTimer(int timerName, long interval); + void StartTimer(int timerName, int64_t interval); /** * @Description : Stop the timer. @@ -89,7 +87,7 @@ public: * * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *ObtainMessage(); + InternalMessage *CreateMessage(); /** * @Description : Construct an information message based on @@ -98,61 +96,61 @@ public: * @param orig - Original message.[in] * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *ObtainMessage(InternalMessage *orig); + InternalMessage *CreateMessage(InternalMessage *orig); /** * @Description : Construct internal messages. * - * @param what - Message Name.[in] + * @param msgName - Message Name.[in] * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *ObtainMessage(int what); + InternalMessage *CreateMessage(int msgName); /** * @Description : Construct internal messages. * - * @param what - Message Name.[in] - * @param arg1 - Message parameters.[in] + * @param msgName - Message Name.[in] + * @param param1 - Message parameters.[in] * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *ObtainMessage(int what, int arg1); + InternalMessage *CreateMessage(int msgName, int param1); /** * @Description : Construct internal messages. * - * @param what - Message Name.[in] - * @param arg1 - Message parameters.[in] - * @param arg2 - Message parameters.[in] + * @param msgName - Message Name.[in] + * @param param1 - Message parameters.[in] + * @param param2 - Message parameters.[in] * @return InternalMessage* : Pointer to the constructed internal message. */ - InternalMessage *ObtainMessage(int what, int arg1, int arg2); + InternalMessage *CreateMessage(int msgName, int param1, int param2); /** * @Description : Constructs internal messages and places the * messages in the message queue of the state machine. * - * @param what - Message name.[in] + * @param msgName - Message name.[in] */ - void SendMessage(int what); + void SendMessage(int msgName); /** * @Description : Constructs internal messages and places the messages * in the message queue of the state machine. * - * @param what - Message name.[in] - * @param arg1 - Message parameter.[in] + * @param msgName - Message name.[in] + * @param param1 - Message parameter.[in] */ - void SendMessage(int what, int arg1); + void SendMessage(int msgName, int param1); /** * @Description : Constructs internal messages and places the messages * in the message queue of the state machine. * - * @param what - Message name.[in] - * @param arg1 - Message parameter.[in] - * @param arg2 - Message parameter.[in] + * @param msgName - Message name.[in] + * @param param1 - Message parameter.[in] + * @param param2 - Message parameter.[in] */ - void SendMessage(int what, int arg1, int arg2); + void SendMessage(int msgName, int param1, int param2); /** * @Description : Puts messages into the message queue of the state machine. @@ -166,33 +164,33 @@ public: * message queue of the state machine. The messages are processed * after the specified delay time. * - * @param what - Message Name.[in] - * @param delayMillis - Delay time, in milliseconds.[in] + * @param msgName - Message Name.[in] + * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void SendMessageDelayed(int what, long delayMillis); + void MessageExecutedLater(int msgName, int64_t delayTimeMs); /** * @Description : Constructs internal messages and places them in the * message queue of the state machine. The messages are processed * after the specified delay time. * - * @param what - Message Name.[in] - * @param arg1 - Message parameters.[in] - * @param delayMillis - Delay time, in milliseconds.[in] + * @param msgName - Message Name.[in] + * @param param1 - Message parameters.[in] + * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void SendMessageDelayed(int what, int arg1, long delayMillis); + void MessageExecutedLater(int msgName, int param1, int64_t delayTimeMs); /** * @Description : Constructs internal messages and places them in the * message queue of the state machine. The messages are processed * after the specified delay time. * - * @param what - Message Name.[in] - * @param arg1 - Message parameters.[in] - * @param arg2 - Message parameters.[in] - * @param delayMillis - Delay time, in milliseconds.[in] + * @param msgName - Message Name.[in] + * @param param1 - Message parameters.[in] + * @param param2 - Message parameters.[in] + * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void SendMessageDelayed(int what, int arg1, int arg2, long delayMillis); + void MessageExecutedLater(int msgName, int param1, int param2, int64_t delayTimeMs); /** * @Description : Constructs internal messages and places them in the @@ -200,9 +198,9 @@ public: * after the specified delay time. * * @param msg - Message to be sent.[in] - * @param delayMillis - Delay time, in milliseconds.[in] + * @param delayTimeMs - Delay time, in milliseconds.[in] */ - void SendMessageDelayed(InternalMessage *msg, long delayMillis); + void MessageExecutedLater(InternalMessage *msg, int64_t delayTimeMs); protected: /** @@ -222,104 +220,70 @@ protected: * @Description : Add state. * * @param state - state.[in] - * @param parent - parent state.[in] + * @param upper - upper state.[in] */ - void AddState(State *state, State *parent); + void StatePlus(State *state, State *upper); /** * @Description : Remove state. * * @param state - state.[in] */ - void RemoveState(State *state); + void StateDelete(State *state); /** * @Description : Set initial state. * - * @param initialState - Initial state.[in] + * @param firstState - Initial state.[in] */ - void SetInitialState(State *initialState); + void SetFirstState(State *firstState); /** * @Description : Transition to orther state. * - * @param destState - state.[in] + * @param targetState - state.[in] */ - void TransitionTo(State *destState); + void SwitchState(State *targetState); /** * @Description : Delay Message. * * @param msg - Message object.[in] */ - void DeferMessage(InternalMessage *msg); + void DelayMessage(InternalMessage *msg); private: - SmHandler *pSmHandler; + StateMachineHandler *pStateMachineHandler; std::string mStateName; }; typedef struct StateInfo { State *state; - StateInfo *parentStateInfo; + StateInfo *upperStateInfo; bool active; } StateInfo; -class SmHandler : public Handler { +class StateMachineHandler : public Handler { public: - class QuittingState : public State { - public: - QuittingState() : State("QuittingState") - {} - ~QuittingState() - {} - void Enter() - {} - void Exit() - {} - bool ProcessMessage(InternalMessage *msg) - { - if (msg == nullptr) { - return NOT_HANDLED; - } - return NOT_HANDLED; - } - }; - - class HaltingState : public State { - public: - HaltingState() : State("HaltingState") - {} - ~HaltingState() - {} - void Enter() - {} - void Exit() - {} - bool ProcessMessage(InternalMessage *msg) - { - if (msg == nullptr) { - return NOT_HANDLED; - } - return HANDLED; - } - }; + using StateInfoMap = std::map; + using StateVector = std::vector; + using DelayedMessage = std::vector; /** * @Description : Construct a new state machine Handler:: StateMachine Handler object. * * @param pStateMgr - Handler pointer.[in] */ - explicit SmHandler(StateMachine *pStateMgr); + explicit StateMachineHandler(StateMachine *pStateMgr); /** * @Description : Destroy the StateMachine Handler:: StateMachine Handler object. * */ - ~SmHandler(); + ~StateMachineHandler(); /** - * @Description : SmHandler Initialization Function. + * @Description : StateMachineHandler Initialization Function. * * @return true : success, false : failed. */ @@ -329,72 +293,72 @@ public: * @Description : Add a new state. * * @param state - State to be added.[in] - * @param parent - parent of state.[in] + * @param upper - upper of state.[in] * @return StateInfo* */ - StateInfo *AddState(State *state, State *parent); + StateInfo *StatePlus(State *state, State *upper); /** * @Description : Delete a state. * * @param state - State to be deleted.[in] */ - void RemoveState(State *state); + void StateDelete(State *state); /** * @Description : Sets the Initialization State. * - * @param initialState - Initialization State.[in] + * @param firstState - Initialization State.[in] */ - void SetInitialState(State *initialState); + void SetFirstState(State *firstState); /** * @Description : State transition function. * - * @param destState - Destination State.[in] + * @param targetState - Destination State.[in] */ - void TransitionTo(State *destState); + void SwitchState(State *targetState); /** * @Description : Delay Message Processing Function. * * @param msg - Message body pointer.[in] */ - void DeferMessage(InternalMessage *msg); + void DelayMessage(InternalMessage *msg); /** * @Description : The state machine is constructed. * */ - void CompleteConstruction(); + void BuildTreeComplete(); private: /** * @Description : Sets the initial state sequence. * */ - void SetupInitialStateVector(); + void BuildStateInitVector(); /** - * @Description : Writes the inactive parent states of destState - * and destState to the sequenceStateList list. + * @Description : Writes the inactive upper states of targetState + * and targetState to the sequenceStateVector list. * - * @param destState - Target State Machine.[in] + * @param targetState - Target State Machine.[in] * @return StateInfo* */ - StateInfo *SetupTempStateStackWithStatesToEnter(State *destState); + StateInfo *BuildSequenceStateVector(State *targetState); /** - * @Description : Move Deferred Message At Front Of Queue. + * @Description : Move Delayed Message At Front Of Queue. * */ - void MoveDeferredMessageAtFrontOfQueue(); + void PlaceDelayedMsgQueueTop(); /** - * @Description : Release all messages in deferred Messages. + * @Description : Release all messages in delayed Messages. * */ - void ReleaseDeferredMessages(); + void ReleaseDelayedMessages(); /** * @Description : Fill the status in the sequential status @@ -402,23 +366,23 @@ private: * * @return int */ - int MoveSequenceStateListToStateList(); + int MoveSequenceToStateVector(); /** - * @Description : Invoke the ProcessMessage interface of the current state + * @Description : Invoke the ExecuteStateMsg interface of the current state * to process messages sent to the state machine. The entry/exit of the * state machine is also called, and the delayed messagei s put back * into queue when transitioning to a new state. * * @param msg - Messages.[in] */ - void HandleMessage(InternalMessage *msg); + void ExecuteMessage(InternalMessage *msg) override; /** * @Description : Clean up After Quitting. * */ - void CleanupAfterQuitting(); + void ClearWhenQuit(); /** * @Description : Performing Status Transitions. @@ -426,81 +390,65 @@ private: * @param msgProcessedState - Message processing status.[in] * @param msg - Messages.[in] */ - void PerformTransitions(State *msgProcessedState, InternalMessage *msg); + void PerformSwitchState(State *msgProcessedState, InternalMessage *msg); /** * @Description : Process messages. If the current state doesnot process it, - * the parent state processing is called, and so on. If all parent states - * are not processed, invoke the UnhandledMessage method of the state machine. + * the upper state processing is called, and so on. If all upper states + * are not processed, invoke the NotExecutedMessage method of the state machine. * * @param msg - Message body pointer.[in] * @return State* */ - State *ProcessMsg(InternalMessage *msg); + State *ExecuteTreeStateMsg(InternalMessage *msg); /** - * @Description : Invoke Exit() for each state from the first - * state in the list to the public parent state. + * @Description : Invoke GoOutState() for each state from the first + * state in the list to the public upper state. * - * @param commonStateInfo - common parent state machine.[in] + * @param commonStateInfo - common upper state machine.[in] */ - void InvokeExitMethods(StateInfo *commonStateInfo); + void CallTreeStateExits(StateInfo *commonStateInfo); /** - * @Description : Call the Enter method from the start state + * @Description : Call the GoInState method from the start state * index to the top of the state stack. * * @param index - Start state index of the * state machine list. */ - void InvokeEnterMethods(int index); - - /** - * @Description : Is Quit or not - * - * @param msg - Message body pointer.[in] - * @return true : success, false: failed. - */ - bool IsQuit(InternalMessage *msg); + void CallTreeStateEnters(int index); private: - typedef std::map StateInfoMap; - typedef std::vector StateList; - typedef std::vector DeferredMessage; - /* All state mappings of the state machine */ - StateInfoMap mStateInfo; - /* From child state to parent state list */ - StateList mStateList; - /* Top index of mStateList */ - int mStateListTopIndex; - /* From parent state to child state list */ - StateList mSequenceStateList; - /* Top of mSequenceStateList */ - int mSequenceStateListCount; - /* Deferred Message Queue */ - DeferredMessage mDeferredMessages; + StateInfoMap mStateInfoMap; + /* From child state to upper state list */ + StateVector mStateVector; + /* Top index of mStateVector */ + int mStateVectorTopIndex; + /* From upper state to child state list */ + StateVector mSequenceStateVector; + /* Top of mSequenceStateVector */ + int mSequenceStateVectorCount; + /* Delayed Message Queue */ + DelayedMessage mDelayedMessages; /* State machine instance */ - StateMachine *pSM; + StateMachine *pStateMachine; /* Initial state */ - State *pInitialState; + State *pFirstState; /* Target Status */ - State *pDestState; + State *pTargetState; /* StateMachine exit or not */ - bool mHasQuit; + bool mQuitFlag; /* Whether the state machine has been built */ - bool mIsConstructionCompleted; + bool mBuildCompleteFlag; /* * All State exit/enter calls are true before the * last enter call in the target state. */ - bool mTransitionInProgress; + bool mSwitchingStateFlag; /* Current Message */ InternalMessage *pCurrentMsg; - /* Exit state */ - QuittingState *pQuittingState; - /* Pauses */ - HaltingState *pHaltingState; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.cpp index 467606c3f..707132883 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.cpp @@ -16,10 +16,9 @@ #include #include "ap_macro.h" #include "ap_state_machine.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApIdleState" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApIdleState"); namespace OHOS { namespace Wifi { ApIdleState::ApIdleState() : State("ApIdleState") @@ -28,20 +27,20 @@ ApIdleState::ApIdleState() : State("ApIdleState") ApIdleState::~ApIdleState() {} -void ApIdleState::Enter() +void ApIdleState::GoInState() { - LOGI("%{public}s Enter", GetName().c_str()); + WIFI_LOGI("%{public}s Enter", GetStateName().c_str()); } -void ApIdleState::Exit() +void ApIdleState::GoOutState() { - LOGI("%{public}s Exit", GetName().c_str()); + WIFI_LOGI("%{public}s Exit", GetStateName().c_str()); } -bool ApIdleState::ProcessMessage(InternalMessage *msg) +bool ApIdleState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return false; } @@ -49,18 +48,18 @@ bool ApIdleState::ProcessMessage(InternalMessage *msg) switch (static_cast(msgName)) { case ApStatemachineEvent::CMD_START_HOTSPOT: { - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApStartedState); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApStartedState); break; } case ApStatemachineEvent::CMD_UPDATE_HOTSPOTCONFIG_RESULT: { break; } default: - return NOT_HANDLED; + return NOT_EXECUTED; break; } - return HANDLED; + return EXECUTED; } } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.h index d5f8b50f6..aab2bd1c9 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_idle_state.h @@ -42,19 +42,19 @@ public: * @param None * @return None */ - virtual void Enter() override; + virtual void GoInState() override; /** * @Description realize pure base class method: called when exit state. * @param None * @return None */ - virtual void Exit() override; + virtual void GoOutState() override; /** * @Description realize pure base class method: process event in idle state. * @param msg - message to be processed - * @return HANDLED:Processed successfully NOT_HANDLED: Processed failed + * @return EXECUTED:Processed successfully NOT_EXECUTED: Processed failed */ - virtual bool ProcessMessage(InternalMessage *msg) override; + virtual bool ExecuteStateMsg(InternalMessage *msg) override; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_interface.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_interface.cpp index caafd832c..05be8ab7b 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_interface.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_interface.cpp @@ -18,10 +18,8 @@ #include "ap_service.h" #include "ap_state_machine.h" #include "wifi_ap_nat_manager.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApInterface" namespace OHOS { namespace Wifi { ApInterface::ApInterface() diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_monitor.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_monitor.cpp index a57a2e92d..9a0d071ee 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_monitor.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_monitor.cpp @@ -17,15 +17,14 @@ #include "ap_state_machine.h" #include "internal_message.h" #include "log_helper.h" -#include "wifi_log.h" +#include "wifi_logger.h" #include "wifi_settings.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApMonitor" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApMonitor"); extern "C" void OnStaJoinOrLeave(const CStationInfo *cinfo) { if (cinfo == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return; } OHOS::Wifi::StationInfo info; @@ -62,7 +61,7 @@ void ApMonitor::DeleteInstance() void ApMonitor::StationChangeEvent(StationInfo &staInfo, const int event) const { - LOGI("StationChangeEvent event: [%{public}d]", event); + WIFI_LOGI("StationChangeEvent event: [%{public}d]", event); if (event == WIFI_IDL_CBK_CMD_STA_JOIN) { ApStateMachine::GetInstance().StationJoin(staInfo); } @@ -73,13 +72,13 @@ void ApMonitor::StationChangeEvent(StationInfo &staInfo, const int event) const void ApMonitor::OnHotspotStateEvent(int state) const { - LOGI("update HotspotConfig result is [%{public}d]\n", state); + WIFI_LOGI("update HotspotConfig result is [%{public}d]\n", state); if (state == WIFI_IDL_CBK_CMD_AP_DISABLE) { ApStateMachine::GetInstance().UpdateHotspotConfigResult(false); } else if (state == WIFI_IDL_CBK_CMD_AP_ENABLE) { ApStateMachine::GetInstance().UpdateHotspotConfigResult(true); } else { - LOGE("Error: Incorrect status code [%{public}d]", state); + WIFI_LOGE("Error: Incorrect status code [%{public}d]", state); } } @@ -89,9 +88,9 @@ void ApMonitor::StartMonitor() wifiApEventCallback.onStaJoinOrLeave = OnStaJoinOrLeave; WifiApDhcpInterface::DhcpCallback callback = [](StationInfo &staInfo) { - LOGI("name = [%s]", staInfo.deviceName.c_str()); - LOGI("mac = [%s]", staInfo.bssid.c_str()); - LOGI("ip = [%s]", staInfo.ipAddr.c_str()); + WIFI_LOGI("name = [%s]", staInfo.deviceName.c_str()); + WIFI_LOGI("mac = [%s]", staInfo.bssid.c_str()); + WIFI_LOGI("ip = [%s]", staInfo.ipAddr.c_str()); ApStateMachine::GetInstance().StationJoin(staInfo); }; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.cpp index d407bd651..8c8828d04 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.cpp @@ -16,10 +16,9 @@ #include #include "ap_macro.h" #include "ap_state_machine.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApRootState" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApRootState"); namespace OHOS { namespace Wifi { ApRootState::ApRootState() : State("ApRootState") @@ -28,26 +27,26 @@ ApRootState::ApRootState() : State("ApRootState") ApRootState::~ApRootState() {} -void ApRootState::Enter() +void ApRootState::GoInState() { - LOGI("%{public}s Enter", GetName().c_str()); + WIFI_LOGI("%{public}s Enter", GetStateName().c_str()); } -void ApRootState::Exit() +void ApRootState::GoOutState() { - LOGI("%{public}s Exit", GetName().c_str()); + WIFI_LOGI("%{public}s Exit", GetStateName().c_str()); } -bool ApRootState::ProcessMessage(InternalMessage *msg) +bool ApRootState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return false; } int msgName = msg->GetMessageName(); - LOGI("msg = [%{public}dpublic}d] is not handled.", msgName); - return HANDLED; + WIFI_LOGI("msg = [%{public}dpublic}d] is not handled.", msgName); + return EXECUTED; } } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.h index bde8e2f48..f87b007cb 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_root_state.h @@ -40,20 +40,20 @@ public: * @param None * @return None */ - virtual void Enter() override; + virtual void GoInState() override; /** * @Description realize pure base class method: called when exit root state. * @param None * @return None */ - virtual void Exit() override; + virtual void GoOutState() override; /** * @Description realize pure base class method: Messages that cannot be processed in the sub-state are recorded in the root state. * @param msg - message to be processed - * @return HANDLED:Processed successfully + * @return EXECUTED:Processed successfully */ - virtual bool ProcessMessage(InternalMessage *msg) override; + virtual bool ExecuteStateMsg(InternalMessage *msg) override; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_service.cpp index 0ca7bb6df..726b82f91 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_service.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_service.cpp @@ -16,10 +16,9 @@ #include #include "ap_state_machine.h" #include "log_helper.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApService" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApService"); namespace OHOS { namespace Wifi { ApService &ApService::GetInstance() @@ -37,7 +36,7 @@ ApService::ApService() : mMsgQueueUp(nullptr) int ApService::Init(WifiMessageQueue *mqUp) { if (mqUp == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return -1; } mMsgQueueUp = mqUp; @@ -54,10 +53,10 @@ int ApService::UnInit(void) const int ApService::PushMsg(const WifiRequestMsgInfo *msg) const { if (msg == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return -1; } - LOGI("Receive a message from the ServiceManager. msgCode = [%{public}d]", msg->msgCode); + WIFI_LOGI("Receive a message from the ServiceManager. msgCode = [%{public}d]", msg->msgCode); switch (static_cast(msg->msgCode)) { case WifiInternalMsgCode::AP_ADD_BLOCK_LIST_REQ: { AddBlockList(msg->params.stationInfo); @@ -92,7 +91,7 @@ void ApService::BroadcastMsg(const WifiResponseMsgInfo &upMsg) const void ApService::OnApStateChange(const ApState &state) const { if (WifiSettings::GetInstance().SetHotspotState(static_cast(state))) { - LOGE("WifiSetting change state failed"); + WIFI_LOGE("WifiSetting change state failed"); } switch (state) { case ApState::AP_STATE_IDLE: { @@ -118,7 +117,7 @@ void ApService::OnHotspotStaJoin(const StationInfo &info) const WifiResponseMsgInfo msgInfo; msgInfo.params.staInfo = info; msgInfo.msgCode = AP_JOIN_RES; - LOGI("OnHotspotStaJoin:,%{public}d,%s,%s,%s", + WIFI_LOGI("OnHotspotStaJoin:,%{public}d,%s,%s,%s", msgInfo.msgCode, msgInfo.params.staInfo.bssid.c_str(), msgInfo.params.staInfo.deviceName.c_str(), @@ -131,7 +130,7 @@ void ApService::OnHotspotStaLeave(const StationInfo &info) const WifiResponseMsgInfo msgInfo; msgInfo.params.staInfo = info; msgInfo.msgCode = AP_LEAVE_RES; - LOGI("OnHotspotStaleave:,%{public}d,%s,%s,%s", + WIFI_LOGI("OnHotspotStaleave:,%{public}d,%s,%s,%s", msgInfo.msgCode, msgInfo.params.staInfo.bssid.c_str(), msgInfo.params.staInfo.deviceName.c_str(), diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp index 24082b5ba..fcf8ec448 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.cpp @@ -29,10 +29,9 @@ #include "wifi_ap_dhcp_interface.h" #include "wifi_ap_hal_interface.h" #include "wifi_ap_nat_manager.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApStartedState" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApStartedState"); namespace OHOS { namespace Wifi { ApStartedState::ApStartedState() : State("ApStartedState"), hotspotConfig(HotspotConfig()) @@ -43,56 +42,56 @@ ApStartedState::ApStartedState() : State("ApStartedState"), hotspotConfig(Hotspo ApStartedState::~ApStartedState() {} -void ApStartedState::Enter() +void ApStartedState::GoInState() { OnApStateChange(ApState::AP_STATE_STARTING); - LOGI("%{public}s Enter", GetName().c_str()); + WIFI_LOGI("%{public}s Enter", GetStateName().c_str()); StartMonitor(); if (StartAp() == false) { - LOGE("enter ApstartedState is failed."); - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + WIFI_LOGE("enter ApstartedState is failed."); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); return; } - LOGI("StartAP is ok"); + WIFI_LOGI("StartAP is ok"); if (ApConfigUse::GetInstance().ObtainValidChannels() == false) { - LOGE("ObtainValidChannels is error."); - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + WIFI_LOGE("ObtainValidChannels is error."); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); return; } if (SetConfig() == false) { - LOGE("wifi_settings.hotspotconfig is error."); - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + WIFI_LOGE("wifi_settings.hotspotconfig is error."); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); return; } if (!ApStateMachine::GetInstance().mApStationsManager.EnableAllBlockList()) { - LOGE("Set Blocklist failed"); + WIFI_LOGE("Set Blocklist failed"); } #ifndef AP_NOT_DIRECT_USE_DHCP if (StartDhcpServer() == false) { - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); return; } if (EnableInterfaceNat() == false) { - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); return; } #endif OnApStateChange(ApState::AP_STATE_STARTED); } -void ApStartedState::Exit() +void ApStartedState::GoOutState() { - LOGI("%{public}s Exit", GetName().c_str()); + WIFI_LOGI("%{public}s Exit", GetStateName().c_str()); OnApStateChange(ApState::AP_STATE_CLOSING); DisableInterfaceNat(); StopDhcpServer(); if (!StopAp()) { - LOGE("StopAp not going well!"); + WIFI_LOGE("StopAp not going well!"); } StopMonitor(); OnApStateChange(ApState::AP_STATE_IDLE); @@ -121,33 +120,33 @@ void ApStartedState::Init() std::make_pair(ApStatemachineEvent::CMD_DISCONNECT_STATION, &ApStartedState::ProcessCmdDisconnectStation)); } -bool ApStartedState::ProcessMessage(InternalMessage *msg) +bool ApStartedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { - LOGE("fatal error!"); + WIFI_LOGE("fatal error!"); return false; } int msgName = msg->GetMessageName(); - LOGI("ApStartedState Process msgName:%{public}d", msgName); + WIFI_LOGI("ApStartedState Process msgName:%{public}d", msgName); auto iter = mProcessFunMap.find(static_cast(msgName)); if (iter == mProcessFunMap.end()) { - return NOT_HANDLED; + return NOT_EXECUTED; } ((*this).*(iter->second))(*msg); - return HANDLED; + return EXECUTED; } bool ApStartedState::SetConfig() { if (WifiSettings::GetInstance().GetHotspotConfig(hotspotConfig)) { - LOGE("GetConfig failed!!!"); + WIFI_LOGE("GetConfig failed!!!"); return false; } ApConfigUse::GetInstance().CheckBandChannel(hotspotConfig); if (ApConfigUse::GetInstance().SetConfig(hotspotConfig) == false) { - LOGE("SetConfig failed!!!"); + WIFI_LOGE("SetConfig failed!!!"); return false; } return true; @@ -155,10 +154,10 @@ bool ApStartedState::SetConfig() bool ApStartedState::StartAp() const { - LOGI("enter startAp"); + WIFI_LOGI("enter startAp"); WifiErrorNo retCode = WifiApHalInterface::GetInstance().StartAp(); if (retCode != WifiErrorNo::WIFI_IDL_OPT_OK) { - LOGE("startAp is failed!"); + WIFI_LOGE("startAp is failed!"); return false; } return true; @@ -192,14 +191,14 @@ bool ApStartedState::StartDhcpServer() const { HotspotConfig hotspotCfg; if (WifiSettings::GetInstance().GetHotspotConfig(hotspotCfg)) { - LOGE("Failed to get the HotspotConfig from the WifiSettings."); + WIFI_LOGE("Failed to get the HotspotConfig from the WifiSettings."); hotspotCfg.SetMaxConn(0xFF); } std::vector vecIpv4Addr; std::vector vecIpv6Addr; if (!WifiApDhcpInterface::GetInstance().StartDhcpServer( ININTERFACE, hotspotCfg.GetMaxConn(), vecIpv4Addr, vecIpv6Addr, true)) { - LOGE("start dhcpd failed."); + WIFI_LOGE("start dhcpd failed."); return false; } return true; @@ -207,9 +206,9 @@ bool ApStartedState::StartDhcpServer() const bool ApStartedState::StopDhcpServer() const { - LOGI("Enter:StopDhcpServer"); + WIFI_LOGI("Enter:StopDhcpServer"); if (!WifiApDhcpInterface::GetInstance().StopDhcpServer()) { - LOGE("Close dhcpd failed."); + WIFI_LOGE("Close dhcpd failed."); } return true; } @@ -217,7 +216,7 @@ bool ApStartedState::StopDhcpServer() const bool ApStartedState::EnableInterfaceNat() const { if (!WifiApNatManager::GetInstance().EnableInterfaceNat(true, ININTERFACE, OUTINTERFACE)) { - LOGE("set nat failed."); + WIFI_LOGE("set nat failed."); return false; } return true; @@ -226,20 +225,20 @@ bool ApStartedState::EnableInterfaceNat() const bool ApStartedState::DisableInterfaceNat() const { if (!WifiApNatManager::GetInstance().EnableInterfaceNat(false, ININTERFACE, OUTINTERFACE)) { - LOGE("remove NAT config failed."); + WIFI_LOGE("remove NAT config failed."); } return true; } void ApStartedState::ProcessCmdFail(InternalMessage &msg) const { - LOGI("State Machine message: %{public}d.", msg.GetMessageName()); - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + WIFI_LOGI("State Machine message: %{public}d.", msg.GetMessageName()); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); } void ApStartedState::ProcessCmdStationJoin(InternalMessage &msg) const { - LOGI("New station join."); + WIFI_LOGI("New station join."); StationInfo staInfo; staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); @@ -249,7 +248,7 @@ void ApStartedState::ProcessCmdStationJoin(InternalMessage &msg) const void ApStartedState::ProcessCmdStationLeave(InternalMessage &msg) const { - LOGI("Old station leave."); + WIFI_LOGI("Old station leave."); StationInfo staInfo; staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); @@ -259,7 +258,7 @@ void ApStartedState::ProcessCmdStationLeave(InternalMessage &msg) const void ApStartedState::ProcessCmdSetHotspotConfig(InternalMessage &msg) { - LOGI("Set HotspotConfig."); + WIFI_LOGI("Set HotspotConfig."); hotspotConfig.SetSsid(msg.GetStringFromMessage()); hotspotConfig.SetPreSharedKey(msg.GetStringFromMessage()); @@ -268,7 +267,7 @@ void ApStartedState::ProcessCmdSetHotspotConfig(InternalMessage &msg) hotspotConfig.SetChannel(msg.GetIntFromMessage()); hotspotConfig.SetMaxConn(msg.GetIntFromMessage()); - LOGD("hotspotConfig: %s,%s,%{public}d,%{public}d,%{public}d,%{public}d", + WIFI_LOGD("hotspotConfig: %s,%s,%{public}d,%{public}d,%{public}d,%{public}d", hotspotConfig.GetSsid().c_str(), hotspotConfig.GetPreSharedKey().c_str(), static_cast(hotspotConfig.GetSecurityType()), @@ -277,55 +276,55 @@ void ApStartedState::ProcessCmdSetHotspotConfig(InternalMessage &msg) hotspotConfig.GetMaxConn()); if (ApConfigUse::GetInstance().SetConfig(hotspotConfig)) { - LOGI("SetSoftApConfig successfully"); + WIFI_LOGI("SetSoftApConfig successfully"); } else { - LOGE("SetSoftApConfig failed"); + WIFI_LOGE("SetSoftApConfig failed"); } } void ApStartedState::ProcessCmdUpdateConfigResult(InternalMessage &msg) const { - if (msg.GetArg1() == 1) { - LOGI("Hot update HotspotConfig succeeded."); + if (msg.GetParam1() == 1) { + WIFI_LOGI("Hot update HotspotConfig succeeded."); if (WifiSettings::GetInstance().SetHotspotConfig(hotspotConfig)) { - LOGE("set apConfig to settings failed."); + WIFI_LOGE("set apConfig to settings failed."); } } else { - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); } } void ApStartedState::ProcessCmdAddBlockList(InternalMessage &msg) const { - LOGI("Add block list."); + WIFI_LOGI("Add block list."); StationInfo staInfo; staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); staInfo.ipAddr = msg.GetStringFromMessage(); - LOGI("staInfo:%s, %s, %s", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); + WIFI_LOGI("staInfo:%s, %s, %s", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); ApStateMachine::GetInstance().mApStationsManager.AddBlockList(staInfo); } void ApStartedState::ProcessCmdDelBlockList(InternalMessage &msg) const { - LOGI("Delete block list"); + WIFI_LOGI("Delete block list"); StationInfo staInfo; staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); staInfo.ipAddr = msg.GetStringFromMessage(); - LOGI("staInfo:%s, %s, %s", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); + WIFI_LOGI("staInfo:%s, %s, %s", staInfo.deviceName.c_str(), staInfo.bssid.c_str(), staInfo.ipAddr.c_str()); ApStateMachine::GetInstance().mApStationsManager.DelBlockList(staInfo); } void ApStartedState::ProcessCmdStopHotspot(InternalMessage &msg) const { - LOGI("Disable hotspot: %{public}d.", msg.GetMessageName()); - ApStateMachine::GetInstance().TransitionTo(&ApStateMachine::GetInstance().mApIdleState); + WIFI_LOGI("Disable hotspot: %{public}d.", msg.GetMessageName()); + ApStateMachine::GetInstance().SwitchState(&ApStateMachine::GetInstance().mApIdleState); } void ApStartedState::ProcessCmdDisconnectStation(InternalMessage &msg) const { - LOGI("Disconnect station."); + WIFI_LOGI("Disconnect station."); StationInfo staInfo; staInfo.deviceName = msg.GetStringFromMessage(); staInfo.bssid = msg.GetStringFromMessage(); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.h index 1b5ddd702..ae2c46f10 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_started_state.h @@ -39,13 +39,13 @@ public: /** * @Description Implement pure base class methods:Called when entering the state,When receiving the start AP,Switch to the - current state by ApIdleState and call Enter to initialize + current state by ApIdleState and call GoInState to initialize hot spots(Start the wifi driver,Set hostapd to start hotspot mode,Set blocklist, etc.) * @param None * @return None */ - virtual void Enter() override; + virtual void GoInState() override; /** * @Description Implement pure base class methods:Called when exiting the state,Called when the hotspot is closed or the @@ -54,15 +54,15 @@ public: * @param None * @return None */ - virtual void Exit() override; + virtual void GoOutState() override; /** * @Description Implement pure base class methods:The CMD processed when the AP is in the running state (such as updating the blocklist to hostapd) * @param msg - processed message - * @return HANDLED:Processed successfully NOT_HANDLED: Processed failed + * @return EXECUTED:Processed successfully NOT_EXECUTED: Processed failed */ - virtual bool ProcessMessage(InternalMessage *msg) override; + virtual bool ExecuteStateMsg(InternalMessage *msg) override; private: /** diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.cpp index 7d4f42922..0fbd2b394 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.cpp @@ -16,10 +16,9 @@ #include #include "ipv4_address.h" #include "ipv6_address.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApStateMachine" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApStateMachine"); namespace OHOS { namespace Wifi { ApStateMachine *ApStateMachine::g_instance = nullptr; @@ -39,7 +38,7 @@ ApStateMachine &ApStateMachine::GetInstance() if (g_instance && g_instance->InitialStateMachine()) { g_instance->Init(); } else { - LOGE("init ApStateMachine error"); + WIFI_LOGE("init ApStateMachine error"); delete g_instance; g_instance = nullptr; } @@ -57,18 +56,18 @@ void ApStateMachine::DeleteInstance() void ApStateMachine::Init() { - LOGI("ApStateMachine::Init"); - AddState(&mApRootState, nullptr); - AddState(&mApIdleState, &mApRootState); - AddState(&mApStartedState, &mApRootState); + WIFI_LOGI("ApStateMachine::Init"); + StatePlus(&mApRootState, nullptr); + StatePlus(&mApIdleState, &mApRootState); + StatePlus(&mApStartedState, &mApRootState); - SetInitialState(&mApIdleState); - Start(); + SetFirstState(&mApIdleState); + StartStateMachine(); } void ApStateMachine::StationJoin(StationInfo &staInfo) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_STATION_JOIN)); msg->AddStringMessageBody(staInfo.deviceName); msg->AddStringMessageBody(staInfo.bssid); @@ -78,7 +77,7 @@ void ApStateMachine::StationJoin(StationInfo &staInfo) void ApStateMachine::StationLeave(StationInfo &staInfo) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_STATION_LEAVE)); msg->AddStringMessageBody(staInfo.deviceName); msg->AddStringMessageBody(staInfo.bssid); @@ -88,7 +87,7 @@ void ApStateMachine::StationLeave(StationInfo &staInfo) void ApStateMachine::SetHotspotConfig(const HotspotConfig &cfg) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_SET_HOTSPOT_CONFIG)); msg->AddStringMessageBody(cfg.GetSsid()); msg->AddStringMessageBody(cfg.GetPreSharedKey()); @@ -101,7 +100,7 @@ void ApStateMachine::SetHotspotConfig(const HotspotConfig &cfg) void ApStateMachine::AddBlockList(const StationInfo &staInfo) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_ADD_BLOCK_LIST)); msg->AddStringMessageBody(staInfo.deviceName); msg->AddStringMessageBody(staInfo.bssid); @@ -111,7 +110,7 @@ void ApStateMachine::AddBlockList(const StationInfo &staInfo) void ApStateMachine::DelBlockList(const StationInfo &staInfo) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_DEL_BLOCK_LIST)); msg->AddStringMessageBody(staInfo.deviceName); msg->AddStringMessageBody(staInfo.bssid); @@ -121,7 +120,7 @@ void ApStateMachine::DelBlockList(const StationInfo &staInfo) void ApStateMachine::DisconnetStation(const StationInfo &staInfo) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); msg->SetMessageName(static_cast(ApStatemachineEvent::CMD_DISCONNECT_STATION)); msg->AddStringMessageBody(staInfo.deviceName); msg->AddStringMessageBody(staInfo.bssid); @@ -133,15 +132,5 @@ void ApStateMachine::UpdateHotspotConfigResult(const bool result) { SendMessage(static_cast(ApStatemachineEvent::CMD_UPDATE_HOTSPOTCONFIG_RESULT), result ? 1 : 0); } - -void ApStateMachine::OnQuitting() -{ - LOGI("[ApStateMachine] OnQuitting"); -} - -void ApStateMachine::OnHalting() -{ - LOGI("[ApStateMachine] OnHalting"); -} } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.h index 8695f7660..2c4b37c97 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_state_machine.h @@ -89,9 +89,6 @@ private: ApStateMachine(); virtual ~ApStateMachine(); void Init(); - virtual void OnQuitting() override; - virtual void OnHalting() override; - DISALLOW_COPY_AND_ASSIGN(ApStateMachine); private: diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_stations_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_stations_manager.cpp index ed400a9d5..b856b4108 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_stations_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/ap_stations_manager.cpp @@ -16,10 +16,9 @@ #include "ap_service.h" #include "log_helper.h" #include "unistd.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_ApStationsManager" +DEFINE_WIFILOG_HOTSPOT_LABEL("ApStationsManager"); namespace OHOS { namespace Wifi { ApStationsManager::ApStationsManager() @@ -64,14 +63,14 @@ bool ApStationsManager::EnableAllBlockList() const { std::vector results; if (WifiSettings::GetInstance().GetBlockList(results)) { - LOGE("failed to get blocklist"); + WIFI_LOGE("failed to get blocklist"); return false; } std::string mac; bool ret = true; for (std::vector::iterator iter = results.begin(); iter != results.end(); iter++) { if (WifiApHalInterface::GetInstance().AddBlockByMac(iter->bssid) != WifiErrorNo::WIFI_IDL_OPT_OK) { - LOGE("error:Failed to add block mac:%s.", iter->bssid.c_str()); + WIFI_LOGE("error:Failed to add block mac:%s.", iter->bssid.c_str()); ret = false; } } @@ -80,11 +79,11 @@ bool ApStationsManager::EnableAllBlockList() const void ApStationsManager::StationLeave(const std::string &mac) const { - LOGI("StationLeave mac:%s", mac.c_str()); + WIFI_LOGI("StationLeave mac:%s", mac.c_str()); StationInfo staInfo; std::vector results; if (WifiSettings::GetInstance().GetStationList(results)) { - LOGE("failed to GetStationList"); + WIFI_LOGE("failed to GetStationList"); return; } auto it = results.begin(); @@ -92,7 +91,7 @@ void ApStationsManager::StationLeave(const std::string &mac) const if (it->bssid == mac) { staInfo = *it; if (!DelAssociationStation(staInfo)) { - LOGE("DelAssociationStation failed"); + WIFI_LOGE("DelAssociationStation failed"); return; } break; @@ -105,10 +104,10 @@ void ApStationsManager::StationLeave(const std::string &mac) const void ApStationsManager::StationJoin(const StationInfo &staInfo) const { StationInfo staInfoTemp = staInfo; - LOGI("enter ApStationManager::StationJoin"); + WIFI_LOGI("enter ApStationManager::StationJoin"); std::vector results; if (WifiSettings::GetInstance().GetStationList(results)) { - LOGE("failed to GetStationList"); + WIFI_LOGE("failed to GetStationList"); return; } auto it = results.begin(); @@ -122,7 +121,7 @@ void ApStationsManager::StationJoin(const StationInfo &staInfo) const } if (!AddAssociationStation(staInfoTemp)) { - LOGE("AddAssociationStation failed"); + WIFI_LOGE("AddAssociationStation failed"); return; } @@ -137,13 +136,13 @@ bool ApStationsManager::DisConnectStation(const StationInfo &staInfo) const std::string mac = staInfo.bssid; int ret = static_cast(WifiApHalInterface::GetInstance().DisconnectStaByMac(mac)); if (ret != WifiErrorNo::WIFI_IDL_OPT_OK) { - LOGE("failed to DisConnectStation staInfo bssid:%s, address:%s, name:%s. failed", + WIFI_LOGE("failed to DisConnectStation staInfo bssid:%s, address:%s, name:%s. failed", staInfo.bssid.c_str(), staInfo.ipAddr.c_str(), staInfo.deviceName.c_str()); return false; } - LOGI("DisConnectStation staInfo bssid:%s, address:%s, name:%s. ok", + WIFI_LOGI("DisConnectStation staInfo bssid:%s, address:%s, name:%s. ok", staInfo.bssid.c_str(), staInfo.ipAddr.c_str(), staInfo.deviceName.c_str()); @@ -155,7 +154,7 @@ std::vector ApStationsManager::GetAllConnectedStations() const std::vector staMacList; if (WifiApHalInterface::GetInstance().GetStationList(staMacList) == WifiErrorNo::WIFI_IDL_OPT_OK) { for (size_t i = 0; i < staMacList.size(); ++i) { - LOGI("staMacList[%zu]:%s", i, staMacList[i].c_str()); + WIFI_LOGI("staMacList[%{public}zu]:%{public}s", i, staMacList[i].c_str()); } } return staMacList; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_dhcp_interface.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_dhcp_interface.cpp index d6560099d..26745f7e5 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_dhcp_interface.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_dhcp_interface.cpp @@ -34,10 +34,9 @@ #include "network_interface.h" #include "ap_state_machine.h" #include "log_helper.h" -#include "wifi_log.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_WifiApDhcpInterface" +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiApDhcpInterface"); #define DHCP_USER "nobody" /* Receives the SIGCHLD signal of the DHCP server process. */ @@ -57,7 +56,7 @@ static void SigChld(int signo) */ childPid = waitpid(dhcpPid, &status, WUNTRACED | WNOHANG); if (childPid == dhcpPid) { - LOGE("DHCP server is dead. then stop hotspot."); + WIFI_LOGE("DHCP server is dead. then stop hotspot."); OHOS::Wifi::ApStateMachine::GetInstance().SendMessage( static_cast(OHOS::Wifi::ApStatemachineEvent::CMD_STOP_HOTSPOT)); } @@ -136,7 +135,7 @@ bool WifiApDhcpInterface::AssignIpAddr(Ipv4Address &ipv4, Ipv6Address &ipv6, if (isIpV4) { ipv4 = AssignIpAddrV4(vecIpv4Addr, IP_V4_MASK); if (ipv4 == Ipv4Address::INVALID_INET_ADDRESS) { - LOGE("Failed to allocate the IP address."); + WIFI_LOGE("Failed to allocate the IP address."); return false; } } else { /* ipv6 */ @@ -147,7 +146,7 @@ bool WifiApDhcpInterface::AssignIpAddr(Ipv4Address &ipv4, Ipv6Address &ipv6, /* ipv6-nat ip6tables must support IPv6-NAT. */ prefixIp = AssignIpAddrV6(vecIpv6Addr); if (!prefixIp.IsValid()) { - LOGE("Failed to allocate the IP address."); + WIFI_LOGE("Failed to allocate the IP address."); return false; } } else { @@ -157,13 +156,13 @@ bool WifiApDhcpInterface::AssignIpAddr(Ipv4Address &ipv4, Ipv6Address &ipv6, char hidePrefixIp[MAX_IP_LENGTH + 1] = {0}; EncryptLogMsg(prefixIp.GetPrefix().c_str(), hidePrefixIp, sizeof(hidePrefixIp)); - LOGI("prefixIp:%{public}s/%zu.", hidePrefixIp, prefixIp.GetAddressPrefixLength()); + WIFI_LOGI("prefixIp:%{public}s/%{public}zu.", hidePrefixIp, prefixIp.GetAddressPrefixLength()); MacAddress macAddr = MacAddress::Create(""); - LOGW("generate EUI64 addr failed and use rand addr."); + WIFI_LOGW("generate EUI64 addr failed and use rand addr."); ipv6 = Ipv6Address::Create( prefixIp.GetAddressWithString(), prefixIp.GetAddressPrefixLength(), 0); /* use Rnd address */ - LOGI("ifcIp:%s.", ipv6.GetAddressWithString().c_str()); + WIFI_LOGI("ifcIp:%s.", ipv6.GetAddressWithString().c_str()); } return true; } @@ -194,7 +193,7 @@ bool WifiApDhcpInterface::ForkExecProcess(const std::string hotspotInterface, co nullptr }; if (execv(args[0], const_cast(args))) { - LOGE("execv failed: [ %{public}s ] \n", DHCP_SERVER_FILE.c_str()); + WIFI_LOGE("execv failed: [ %{public}s ] \n", DHCP_SERVER_FILE.c_str()); } _exit(-1); return true; @@ -202,7 +201,7 @@ bool WifiApDhcpInterface::ForkExecProcess(const std::string hotspotInterface, co bool WifiApDhcpInterface::ForkParentProcess() { - LOGI("DHCP server pid is %{public}d.\n", mPidDhcp); + WIFI_LOGI("DHCP server pid is %{public}d.\n", mPidDhcp); RegisterSignal(); if (!CreateListen()) { StopDhcpServer(); @@ -219,7 +218,7 @@ bool WifiApDhcpInterface::StartDhcpServer(const std::string hotspotInterface, co std::string ipMask; if (mPidDhcp != 0) { - LOGI("%{public}s already started.", DHCP_SERVER_FILE.c_str()); + WIFI_LOGI("%{public}s already started.", DHCP_SERVER_FILE.c_str()); return true; } @@ -236,9 +235,9 @@ bool WifiApDhcpInterface::StartDhcpServer(const std::string hotspotInterface, co ipMask = Ipv4.GetMaskWithString(); /* IPV6 should send like FC::2 to the DHCP server. do not have /64. */ - LOGI("Starting [ %{public}s ].", DHCP_SERVER_FILE.c_str()); + WIFI_LOGI("Starting [ %{public}s ].", DHCP_SERVER_FILE.c_str()); if ((pid = fork()) < 0) { - LOGE("fork failed: %{public}s", strerror(errno)); + WIFI_LOGE("fork failed: %{public}s", strerror(errno)); return false; } mUseIfc.push_back(hotspotInterface); @@ -262,28 +261,28 @@ bool WifiApDhcpInterface::StopDhcpServer() } mUseIfc.clear(); if (mPidDhcp == 0) { - LOGI("[ %{public}s ] already stoppend.", DHCP_SERVER_FILE.c_str()); + WIFI_LOGI("[ %{public}s ] already stoppend.", DHCP_SERVER_FILE.c_str()); return true; } if (!DestroyListen()) { - LOGE("DestroyListen is failed."); + WIFI_LOGE("DestroyListen is failed."); /* Listening cannot be canceled, but the process still needs to be killed. */ } if (kill(mPidDhcp, SIGTERM) == -1) { if (ESRCH == errno) { /* Normal. The subprocess is dead. The SIGCHLD signal triggers the stop hotspot. */ - LOGI("Normal:DHCP PID is not exist."); + WIFI_LOGI("Normal:DHCP PID is not exist."); mPidDhcp = 0; return true; } - LOGE("kill [ %{public}s ] failed: %{public}s\n", DHCP_SERVER_FILE.c_str(), strerror(errno)); + WIFI_LOGE("kill [ %{public}s ] failed: %{public}s\n", DHCP_SERVER_FILE.c_str(), strerror(errno)); return false; } if (waitpid(mPidDhcp, nullptr, 0) == -1) { - LOGE("waitpid [ %{public}s ] failed:%{public}s\n", DHCP_SERVER_FILE.c_str(), strerror(errno)); + WIFI_LOGE("waitpid [ %{public}s ] failed:%{public}s\n", DHCP_SERVER_FILE.c_str(), strerror(errno)); return false; } @@ -296,11 +295,11 @@ void WifiApDhcpInterface::RegisterSignal() const struct sigaction newAction {}; if (sigfillset(&newAction.sa_mask) == -1) { - LOGE("sigfillset failed. %{public}s", strerror(errno)); + WIFI_LOGE("sigfillset failed. %{public}s", strerror(errno)); } if (sigdelset(&newAction.sa_mask, SIGCHLD) == -1) { - LOGE("sigdelset failed. %{public}s", strerror(errno)); + WIFI_LOGE("sigdelset failed. %{public}s", strerror(errno)); } newAction.sa_handler = SigChld; @@ -308,7 +307,7 @@ void WifiApDhcpInterface::RegisterSignal() const newAction.sa_restorer = nullptr; if (sigaction(SIGCHLD, &newAction, nullptr) == -1) { - LOGE("sigaction failed. %{public}s", strerror(errno)); + WIFI_LOGE("sigaction failed. %{public}s", strerror(errno)); } } @@ -317,7 +316,7 @@ void WifiApDhcpInterface::UnregisterSignal() const struct sigaction newAction {}; if (sigemptyset(&newAction.sa_mask) == -1) { - LOGE("sigfillset failed. %{public}s", strerror(errno)); + WIFI_LOGE("sigfillset failed. %{public}s", strerror(errno)); } newAction.sa_handler = SIG_DFL; @@ -325,7 +324,7 @@ void WifiApDhcpInterface::UnregisterSignal() const newAction.sa_restorer = nullptr; if (sigaction(SIGCHLD, &newAction, nullptr) == -1) { - LOGE("sigaction failed. %{public}s", strerror(errno)); + WIFI_LOGE("sigaction failed. %{public}s", strerror(errno)); } } @@ -333,12 +332,12 @@ bool WifiApDhcpInterface::CreateListen() { const int maxListenNum = 20; if (unlink(SOCKFD_PATH.c_str()) == -1) { - LOGE("Normal:Delete %{public}s failed. %{public}s", SOCKFD_PATH.c_str(), strerror(errno)); + WIFI_LOGE("Normal:Delete %{public}s failed. %{public}s", SOCKFD_PATH.c_str(), strerror(errno)); } mFdSocketListen = socket(AF_UNIX, SOCK_STREAM, 0); if (mFdSocketListen == -1) { - LOGE("create socket fd failed. %{public}s", strerror(errno)); + WIFI_LOGE("create socket fd failed. %{public}s", strerror(errno)); return false; } @@ -352,13 +351,13 @@ bool WifiApDhcpInterface::CreateListen() } if (bind(mFdSocketListen, reinterpret_cast(&serverAddr), sizeof(serverAddr)) == -1) { - LOGE("bind failed. %{public}s", strerror(errno)); + WIFI_LOGE("bind failed. %{public}s", strerror(errno)); close(mFdSocketListen); return false; } if (listen(mFdSocketListen, maxListenNum) < 0) { - LOGE("listen failed. %{public}s", strerror(errno)); + WIFI_LOGE("listen failed. %{public}s", strerror(errno)); close(mFdSocketListen); return false; } @@ -370,7 +369,7 @@ bool WifiApDhcpInterface::CreateListen() bool WifiApDhcpInterface::DestroyListen() { if (shutdown(mFdSocketListen, SHUT_RDWR) == -1) { - LOGE("shutdown listen socket fd failed: %{public}s \n", strerror(errno)); + WIFI_LOGE("shutdown listen socket fd failed: %{public}s \n", strerror(errno)); return false; } close(mFdSocketListen); @@ -392,12 +391,12 @@ void WifiApDhcpInterface::DealClientReport(ClientInfo *pClient) const return; } - LOGI("get client info from dhcp: \n len: %{public}d bytes \n check: %04x \n name: %{public}s \n", + WIFI_LOGI("get client info from dhcp: \n len: %{public}d bytes \n check: %04x \n name: %{public}s \n", pClient->len, pClient->check, pClient->name); - LOGI("mac: %s \n", pClient->macAddr); - LOGI("ip: %s \n ipType: %{public}d \n\n", pClient->ipAddr, pClient->ipType); + WIFI_LOGI("mac: %s \n", pClient->macAddr); + WIFI_LOGI("ip: %s \n ipType: %{public}d \n\n", pClient->ipAddr, pClient->ipType); /* The correct client information is obtained, which is accessed through * the p_client pointer. */ @@ -409,7 +408,7 @@ void WifiApDhcpInterface::DealClientReport(ClientInfo *pClient) const mDhcpCallback(staInfo); } else { - LOGE("Unregistered DHCP server callback."); + WIFI_LOGE("Unregistered DHCP server callback."); } } @@ -420,11 +419,11 @@ void WifiApDhcpInterface::DealReadHandle(int clientSockfd) const ssize_t tempLen2 = 0; tempLen2 = read(clientSockfd, reinterpret_cast(&tempLen), sizeof(tempLen)); if (tempLen2 == -1) { - LOGE("read length error: %{public}s \n", strerror(errno)); + WIFI_LOGE("read length error: %{public}s \n", strerror(errno)); break; } if (tempLen2 == 0) { - LOGI("read of EOF."); + WIFI_LOGI("read of EOF."); break; } @@ -435,13 +434,13 @@ void WifiApDhcpInterface::DealReadHandle(int clientSockfd) const unsigned int msgLen = tempLen + sizeof(tempLen); ClientInfo *pClient = (ClientInfo *)calloc(msgLen, sizeof(char)); if (pClient == nullptr) { - LOGE("calloc error: %{public}s \n", strerror(errno)); + WIFI_LOGE("calloc error: %{public}s \n", strerror(errno)); break; } pClient->len = tempLen; tempLen2 = read(clientSockfd, &pClient->check, tempLen); if (tempLen2 != tempLen) { - LOGE("read error \n"); + WIFI_LOGE("read error \n"); if (pClient != nullptr) { free(pClient); pClient = nullptr; @@ -467,13 +466,13 @@ void WifiApDhcpInterface::DealListen() const clientSockfd = accept(mFdSocketListen, reinterpret_cast(&clientAddr), &len); if (clientSockfd == -1) { if ((errno == EINVAL) || (errno == EBADF)) { /* WifiApDhcpInterface::DestroyListen invoking shutdown. */ - LOGE("Normal: Stop listening and shutdown the socket fd."); + WIFI_LOGE("Normal: Stop listening and shutdown the socket fd."); } else { - LOGE("accept failed: %{public}s.\n", strerror(errno)); + WIFI_LOGE("accept failed: %{public}s.\n", strerror(errno)); } break; } - LOGI("accept ok\n"); + WIFI_LOGI("accept ok\n"); DealReadHandle(clientSockfd); close(clientSockfd); @@ -499,7 +498,7 @@ bool WifiApDhcpInterface::CompareSubNet(const std::vector &vecIpAdd struct in_addr IpAddrSubNet_in_addr; if (inet_aton(IpAddr.GetAddressWithString().c_str(), &IpAddr_in_addr) < 0) { - LOGE("fatal error,base address construct error. %{public}s\n", strerror(errno)); + WIFI_LOGE("fatal error,base address construct error. %{public}s\n", strerror(errno)); return true; } @@ -518,14 +517,14 @@ Ipv4Address WifiApDhcpInterface::AssignIpAddrV4( std::string ifcIp = "127.0.0.1"; /* Mask */ if (inet_aton(mask.c_str(), &maskInAddr) < 0) { - LOGE("mask:inet_aton error: %{public}s\n", strerror(errno)); + WIFI_LOGE("mask:inet_aton error: %{public}s\n", strerror(errno)); return Ipv4Address::INVALID_INET_ADDRESS; } struct in_addr ifcIpInAddr {}; struct in_addr ifcSubNetInAddr {}; /* IfcIp */ if (inet_aton(ifcIp.c_str(), &ifcIpInAddr) < 0) { - LOGE("ifcIp:inet_aton error: %{public}s\n", strerror(errno)); + WIFI_LOGE("ifcIp:inet_aton error: %{public}s\n", strerror(errno)); return Ipv4Address::INVALID_INET_ADDRESS; } @@ -542,7 +541,7 @@ Ipv4Address WifiApDhcpInterface::AssignIpAddrV4( cSubnet++; if (cSubnet == 0xFF) { /* No valid value. */ - LOGE("No available IPv4 address is found.\n"); + WIFI_LOGE("No available IPv4 address is found.\n"); return Ipv4Address::INVALID_INET_ADDRESS; } else { ifcSubNetInAddr.s_addr = (ifcSubNetInAddr.s_addr & htonl(IN_CLASSB_NET)) | @@ -569,14 +568,14 @@ Ipv6Address WifiApDhcpInterface::AssignIpAddrV6(const std::vector & for (auto IpAddr : vecIpAddr) { struct in6_addr IpAddr_in6_addr; if (inet_pton(AF_INET6, IpAddr.GetAddressWithString().c_str(), &IpAddr_in6_addr) < 0) { - LOGI("IpAddr:bad ip:%s and inet_aton error: %{public}s", + WIFI_LOGI("IpAddr:bad ip:%s and inet_aton error: %{public}s", IpAddr.GetAddressWithString().c_str(), strerror(errno)); continue; } if (memcmp(&IpAddr_in6_addr, &ipPre, sizeof(ipPre)) == 0) { isValidSubNet = false; - LOGI("same IP: %x and %x", IpAddr_in6_addr.s6_addr32[0], IpAddr_in6_addr.s6_addr32[1]); + WIFI_LOGI("same IP: %x and %x", IpAddr_in6_addr.s6_addr32[0], IpAddr_in6_addr.s6_addr32[1]); break; } } @@ -587,13 +586,13 @@ Ipv6Address WifiApDhcpInterface::AssignIpAddrV6(const std::vector & EncryptLogMsg(retStr, hideRetStr, sizeof(hideRetStr)); return Ipv6Address::Create(std::string(retStr), GENE_V6_ADDR_LEN, 0); } else { - LOGE("inet_ntop error:%{public}s ", strerror(errno)); + WIFI_LOGE("inet_ntop error:%{public}s ", strerror(errno)); return Ipv6Address::INVALID_INET6_ADDRESS; } } loopNum--; } - LOGE("Fatal error,can not generate valid ULA addr!"); + WIFI_LOGE("Fatal error,can not generate valid ULA addr!"); return Ipv6Address::INVALID_INET6_ADDRESS; } } // namespace Wifi diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp index 385cceb44..1585719be 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_ap/wifi_ap_nat_manager.cpp @@ -22,11 +22,9 @@ #include #include #include "network_interface.h" -#include "wifi_log.h" +#include "wifi_logger.h" - -#undef LOG_TAG -#define LOG_TAG "OHWIFI_AP_WifiApNatManager" +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiApNatManager"); const std::string SYSTEM_COMMAND_IP = "/system/bin/ip"; const std::string SYSTEM_COMMAND_IPTABLES = "/system/bin/iptables"; @@ -57,7 +55,7 @@ void WifiApNatManager::DeleteInstance() bool WifiApNatManager::EnableInterfaceNat(bool enable, std::string inInterfaceName, std::string outInterfaceName) const { - LOGI("EnableInterfaceNat enable [%{public}s], inInterfaceName [%s] outInterfaceName " + WIFI_LOGI("EnableInterfaceNat enable [%{public}s], inInterfaceName [%s] outInterfaceName " "[%s]", enable ? "true" : "false", inInterfaceName.c_str(), @@ -65,27 +63,27 @@ bool WifiApNatManager::EnableInterfaceNat(bool enable, std::string inInterfaceNa if (!NetworkInterface::IsValidInterfaceName(inInterfaceName) || !NetworkInterface::IsValidInterfaceName(outInterfaceName)) { - LOGE("Invalid interface name."); + WIFI_LOGE("Invalid interface name."); return false; } if (inInterfaceName == outInterfaceName) { - LOGE("Duplicate interface name."); + WIFI_LOGE("Duplicate interface name."); return false; } if (!SetForwarding(enable)) { - LOGE("SetForwarding failed."); + WIFI_LOGE("SetForwarding failed."); return false; } if (!SetInterfaceRoute(enable)) { - LOGE("SetInterfaceRoute failed."); + WIFI_LOGE("SetInterfaceRoute failed."); return false; } if (!SetInterfaceNat(enable, outInterfaceName)) { - LOGE("SetInterfaceNat failed."); + WIFI_LOGE("SetInterfaceNat failed."); return false; } @@ -94,7 +92,7 @@ bool WifiApNatManager::EnableInterfaceNat(bool enable, std::string inInterfaceNa bool WifiApNatManager::SetForwarding(bool enable) const { - LOGI("SetForwarding enable = %{public}s.", enable ? "true" : "false"); + WIFI_LOGI("SetForwarding enable = %{public}s.", enable ? "true" : "false"); bool bResult = true; const std::string content = enable ? "1" : "0"; @@ -167,7 +165,7 @@ bool WifiApNatManager::WriteDataToFile(const std::string &fileName, const std::s { std::ofstream outf(fileName, std::ios::out); if (!outf) { - LOGE("write content [%s] to file [%s] failed. error: %{public}s.", + WIFI_LOGE("write content [%s] to file [%s] failed. error: %{public}s.", content.c_str(), fileName.c_str(), strerror(errno)); @@ -186,11 +184,11 @@ bool WifiApNatManager::ExecCommand(const std::vector &vecCommandArg command += " "; } - LOGE("exec cmd: [%s]", command.c_str()); + WIFI_LOGE("exec cmd: [%s]", command.c_str()); int ret = system(command.c_str()); if (ret == -1 || ret == SYSTEM_NOT_EXECUTED) { - LOGE("exec failed. cmd: %s, error:%{public}s", command.c_str(), strerror(errno)); + WIFI_LOGE("exec failed. cmd: %s, error:%{public}s", command.c_str(), strerror(errno)); return false; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp index 771e3291c..a46bd1781 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_device_stub.cpp @@ -136,12 +136,6 @@ void WifiDeviceStub::ReadWifiDeviceConfig(MessageParcel &data, WifiDeviceConfig config.wepTxKeyIndex = data.ReadInt32(); config.priority = data.ReadInt32(); config.hiddenSSID = data.ReadBool(); - config.isEnableWPAICertified = data.ReadBool(); - config.allowedKeyManagement = data.ReadInt32(); - config.allowedProtocols = data.ReadInt32(); - config.allowedAuthAlgorithms = data.ReadInt32(); - config.allowedPairwiseCiphers = data.ReadInt32(); - config.allowedGroupCiphers = data.ReadInt32(); config.wifiIpConfig.assignMethod = AssignIpMethod(data.ReadInt32()); ReadIpAddress(data, config.wifiIpConfig.staticIpAddress.ipAddress.address); config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength = data.ReadInt32(); @@ -195,12 +189,6 @@ void WifiDeviceStub::WriteWifiDeviceConfig(MessageParcel &reply, const WifiDevic reply.WriteInt32(config.wepTxKeyIndex); reply.WriteInt32(config.priority); reply.WriteBool(config.hiddenSSID); - reply.WriteBool(config.isEnableWPAICertified); - reply.WriteInt32(config.allowedKeyManagement); - reply.WriteInt32(config.allowedProtocols); - reply.WriteInt32(config.allowedAuthAlgorithms); - reply.WriteInt32(config.allowedPairwiseCiphers); - reply.WriteInt32(config.allowedGroupCiphers); reply.WriteInt32((int)config.wifiIpConfig.assignMethod); WriteIpAddress(reply, config.wifiIpConfig.staticIpAddress.ipAddress.address); reply.WriteInt32(config.wifiIpConfig.staticIpAddress.ipAddress.prefixLength); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_callback_proxy.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_callback_proxy.cpp index 07432a7d3..05060b82a 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_callback_proxy.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_callback_proxy.cpp @@ -16,7 +16,7 @@ #include "wifi_hotspot_callback_proxy.h" #include "wifi_logger.h" -DEFINE_WIFILOG_LABEL("WifiHotspotCallbackProxy"); +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspotCallbackProxy"); namespace OHOS { namespace Wifi { diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_death_recipient.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_death_recipient.cpp index 020acea20..e7bfd498f 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_death_recipient.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_death_recipient.cpp @@ -16,7 +16,7 @@ #include "wifi_hotspot_death_recipient.h" #include "wifi_logger.h" #include "wifi_event_broadcast.h" -DEFINE_WIFILOG_LABEL("WifiScanDeathRecipient"); +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiScanDeathRecipient"); namespace OHOS { namespace Wifi { void WifiHotspotDeathRecipient::OnRemoteDied(const wptr& remoteObject) diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_service_impl.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_service_impl.cpp index d40a4807b..35399badb 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_service_impl.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_service_impl.cpp @@ -25,7 +25,7 @@ #include "define.h" #include "wifi_logger.h" -DEFINE_WIFILOG_LABEL("WifiHotspotServiceImpl"); +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspotServiceImpl"); namespace OHOS { namespace Wifi { diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp index 3a0697996..6b570dbeb 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_hotspot_stub.cpp @@ -20,7 +20,7 @@ #include "wifi_errcode.h" #include "wifi_event_broadcast.h" #include "wifi_hotspot_death_recipient.h" -DEFINE_WIFILOG_LABEL("WifiHotspotStub"); +DEFINE_WIFILOG_HOTSPOT_LABEL("WifiHotspotStub"); namespace OHOS { namespace Wifi { diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp index efe3b0a77..032c359ea 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_manager.cpp @@ -15,7 +15,7 @@ #include "wifi_manager.h" #include "wifi_global_func.h" -#include "wifi_log.h" +#include "wifi_logger.h" #include "wifi_sta_hal_interface.h" #include "wifi_auth_center.h" #include "wifi_config_center.h" @@ -23,8 +23,7 @@ #include "wifi_service_manager.h" #include "wifi_settings.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_MANAGER_MANAGER" +DEFINE_WIFILOG_LABEL("WifiManager"); namespace OHOS { namespace Wifi { @@ -36,7 +35,7 @@ WifiManager &WifiManager::GetInstance() std::unique_lock lock(gInitMutex); if (gWifiManager.GetInitStatus() == INIT_UNKNOWN) { if (gWifiManager.Init() != 0) { - LOGE("Failed to `WifiManager::Init` !"); + WIFI_LOGE("Failed to `WifiManager::Init` !"); } } } @@ -53,22 +52,22 @@ WifiManager::~WifiManager() int WifiManager::Init() { if (WifiConfigCenter::GetInstance().Init() < 0) { - LOGE("WifiConfigCenter Init failed!"); + WIFI_LOGE("WifiConfigCenter Init failed!"); mInitStatus_ = CONFIG_CENTER_INIT_FAILED; return -1; } if (WifiAuthCenter::GetInstance().Init() < 0) { - LOGE("WifiAuthCenter Init failed!"); + WIFI_LOGE("WifiAuthCenter Init failed!"); mInitStatus_ = AUTH_CENTER_INIT_FAILED; return -1; } if (WifiServiceManager::GetInstance().Init() < 0) { - LOGE("WifiServiceManager Init failed!"); + WIFI_LOGE("WifiServiceManager Init failed!"); mInitStatus_ = SERVICE_MANAGER_INIT_FAILED; return -1; } if (WifiEventBroadcast::GetInstance().Init() < 0) { - LOGE("WifiEventBroadcast Init failed!"); + WIFI_LOGE("WifiEventBroadcast Init failed!"); mInitStatus_ = EVENT_BROADCAST_INIT_FAILED; return -1; } @@ -76,7 +75,7 @@ int WifiManager::Init() int ret = pthread_create(&mTid, nullptr, DealServiceUpMsg, this); if (ret != 0) { - LOGE("In WifiManager create message deal thread failed!"); + WIFI_LOGE("In WifiManager create message deal thread failed!"); mInitStatus_ = TASK_THREAD_INIT_FAILED; return -1; } @@ -102,10 +101,10 @@ void WifiManager::Exit() int WifiManager::PushMsg(const std::string &name, const WifiRequestMsgInfo &msg) { - LOGD("WifiManager::PushMsg name: %{public}s", name.c_str()); + WIFI_LOGD("WifiManager::PushMsg name: %{public}s", name.c_str()); BaseService *p = WifiServiceManager::GetInstance().GetServiceInst(name); if (p == nullptr) { - LOGE("Get Service %{public}s failed!", name.c_str()); + WIFI_LOGE("Get Service %{public}s failed!", name.c_str()); return -1; } p->PushMsg(const_cast(&msg)); @@ -119,15 +118,15 @@ WifiMessageQueue *WifiManager::GetMessageQueue() int WifiManager::AddDeviceConfig(const WifiDeviceConfig &config, int &networkId) { - LOGI("Enter WifiManager::AddDeviceConfig"); + WIFI_LOGI("Enter WifiManager::AddDeviceConfig"); WifiDeviceConfig tempDeviceConfig; if (WifiSettings::GetInstance().GetDeviceConfig(config.ssid, DEVICE_CONFIG_INDEX_SSID, tempDeviceConfig) == 0) { networkId = tempDeviceConfig.networkId; return 0; } else { - LOGD("Add a new device config, request wpa to create network id"); + WIFI_LOGD("Add a new device config, request wpa to create network id"); if (WifiStaHalInterface::GetInstance().GetNextNetworkId(networkId) != WIFI_IDL_OPT_OK) { - LOGE("Failed to GetNextNetworkId!"); + WIFI_LOGE("Failed to GetNextNetworkId!"); return -1; } tempDeviceConfig = config; @@ -147,14 +146,13 @@ int WifiManager::AddDeviceConfig(const WifiDeviceConfig &config, int &networkId) idlConfig.eap = config.wifiEapConfig.eap; idlConfig.identity = config.wifiEapConfig.identity; idlConfig.password = config.wifiEapConfig.password; - idlConfig.authAlgorithms = config.allowedAuthAlgorithms; idlConfig.wepKeyIdx = config.wepTxKeyIndex; for (int i = 0; i < MAX_WEPKEYS_SIZE; i++) { idlConfig.wepKeys[i] = config.wepKeys[i]; } if (WifiStaHalInterface::GetInstance().SetDeviceConfig(networkId, idlConfig) != WIFI_IDL_OPT_OK) { - LOGE("Failed to SetDeviceConfig"); + WIFI_LOGE("Failed to SetDeviceConfig"); } return 0; } @@ -174,9 +172,9 @@ void *WifiManager::DealServiceUpMsg(void *p) continue; } /* deal msg begin */ - LOGI("receive msgcode %{public}d", msg.msgCode); + WIFI_LOGI("receive msgcode %{public}d", msg.msgCode); if (msg.msgCode == WifiInternalMsgCode::MAIN_EXIT_CODE) { - LOGI("Receive thread exit msg!"); + WIFI_LOGI("Receive thread exit msg!"); return nullptr; } else if (msg.msgCode > WifiInternalMsgCode::STA_START_MSG_CODE && msg.msgCode < WifiInternalMsgCode::STA_END_MSG_CODE) { @@ -188,7 +186,7 @@ void *WifiManager::DealServiceUpMsg(void *p) msg.msgCode < WifiInternalMsgCode::SCAN_END_MSG_CODE) { DealScanUpMsg(msg); } else { - LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); + WIFI_LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); } } return nullptr; @@ -216,7 +214,7 @@ void WifiManager::DealStaUpMsg(WifiManager *pInstance, const WifiResponseMsgInfo break; } default: { - LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); + WIFI_LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); break; } } @@ -240,7 +238,7 @@ void WifiManager::DealApUpMsg(const WifiResponseMsgInfo &msg) break; } default: { - LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); + WIFI_LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); break; } } @@ -275,7 +273,7 @@ void WifiManager::DealScanUpMsg(const WifiResponseMsgInfo &msg) break; } default: { - LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); + WIFI_LOGI("not deal this msgcode %{public}d, ignore it!", msg.msgCode); break; } } @@ -284,7 +282,7 @@ void WifiManager::DealScanUpMsg(const WifiResponseMsgInfo &msg) void WifiManager::UploadOpenWifiFailedEvent() { - LOGD("DealStaOpenRes:upload wifi open failed event!"); + WIFI_LOGD("DealStaOpenRes:upload wifi open failed event!"); WifiEventCallbackMsg cbMsg; cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE; cbMsg.msgData = static_cast(WifiState::UNKNOWN); @@ -295,7 +293,7 @@ void WifiManager::UploadOpenWifiFailedEvent() void WifiManager::UploadOpenWifiSuccessfulEvent() { - LOGD("DealStaOpenRes:wifi open successfully!"); + WIFI_LOGD("DealStaOpenRes:wifi open successfully!"); WifiConfigCenter::GetInstance().SetWifiMidState(WifiOprMidState::OPENING, WifiOprMidState::RUNNING); WifiConfigCenter::GetInstance().SetStaLastRunState(true); @@ -311,7 +309,7 @@ void WifiManager::DealStaOpenRes(WifiManager *pInstance, const WifiResponseMsgIn if (msg.params.result == (int)OperateResState::OPEN_WIFI_FAILED) { UploadOpenWifiFailedEvent(); } else if (msg.params.result == (int)OperateResState::OPEN_WIFI_DISABLED) { - LOGD("DealStaOpenRes:wifi open failed,close wifi sta service!"); + WIFI_LOGD("DealStaOpenRes:wifi open failed,close wifi sta service!"); DealStaCloseRes(msg); } else { UploadOpenWifiSuccessfulEvent(); @@ -323,23 +321,23 @@ void WifiManager::DealStaOpenRes(WifiManager *pInstance, const WifiResponseMsgIn bool bflag = false; do { if (!WifiConfigCenter::GetInstance().SetScanMidState(scanState, WifiOprMidState::OPENING)) { - LOGD("set scan mid state opening failed! may be other activity has been operated"); + WIFI_LOGD("set scan mid state opening failed! may be other activity has been operated"); bflag = true; break; } if (WifiServiceManager::GetInstance().CheckAndEnforceService(WIFI_SERVICE_SCAN) < 0) { - LOGE("Load %{public}s service failed!", WIFI_SERVICE_SCAN); + WIFI_LOGE("Load %{public}s service failed!", WIFI_SERVICE_SCAN); break; } WifiMessageQueue *mqUp = pInstance->mMqUp.get(); auto srvInst = WifiServiceManager::GetInstance().GetServiceInst(WIFI_SERVICE_SCAN); if (srvInst == nullptr) { - LOGE("Failed to get service instance!"); + WIFI_LOGE("Failed to get service instance!"); break; } int ret = srvInst->Init(mqUp); if (ret < 0) { - LOGE("Init %{public}s service failed!", WIFI_SERVICE_SCAN); + WIFI_LOGE("Init %{public}s service failed!", WIFI_SERVICE_SCAN); WifiServiceManager::GetInstance().UnloadService(WIFI_SERVICE_SCAN); break; } @@ -356,7 +354,7 @@ void WifiManager::DealStaOpenRes(WifiManager *pInstance, const WifiResponseMsgIn void WifiManager::DealStaCloseRes(const WifiResponseMsgInfo &msg) { if (msg.params.result == (int)OperateResState::CLOSE_WIFI_FAILED) { - LOGD("DealStaCloseRes:upload wifi close failed event!"); + WIFI_LOGD("DealStaCloseRes:upload wifi close failed event!"); WifiEventCallbackMsg cbMsg; cbMsg.msgCode = WIFI_CBK_MSG_STATE_CHANGE; cbMsg.msgData = static_cast(WifiState::UNKNOWN); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h index 992d0774d..de062ed94 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_common.h @@ -19,6 +19,8 @@ #include #include +namespace OHOS { +namespace Wifi { static const int MIN_SYSTEM_SCAN_INTERVAL = 20; static const int MAX_SYSTEM_SCAN_INTERVAL = 160; static const int MAX_SCAN_CONFIG_STORE_INDEX = 10000; @@ -93,7 +95,7 @@ struct StoreScanConfig { std::string ssid; /* Specifies the SSID in parameter scanning. */ std::string bssid; /* Specifies the BSSID carried in parameter scanning. */ std::vector scanFreqs; /* Only APs with specified frequencies are scanned. */ - long scanTime; /* Scan Start Time */ + int64_t scanTime; /* Scan Start Time */ bool fullScanFlag; /* Flag of scan without specifying parameters */ bool externFlag; /* Flag indicating whether the request is an external scan. */ @@ -177,14 +179,16 @@ struct InterScanResult { * supported by the access point */ int frequency; /* Access point frequency */ - int level; /* signal strength */ - long timestamp; /* Timestamp of scanning */ + int rssi; /* signal strength */ + int64_t timestamp; /* Timestamp of scanning */ + int band; /* ap band: 0 - 2.4GHZ, 1 - 5GHZ */ InterScanResult() { frequency = 0; - level = 0; + rssi = 0; timestamp = 0; + band = -1; } }; @@ -211,5 +215,6 @@ struct ScanStatusReport { using ScanStatusReportHandler = std::function; using ScanResultHandler = std::function &scanResultList)>; using PnoScanResultHandler = std::function &pnoScanResultList)>; - +} // namespace Wifi +} // namespace OHOS #endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp index 46619ec91..a5aa56a64 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_interface.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ #include "scan_interface.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_SCAN_INTERFACE" +DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine"); namespace OHOS { namespace Wifi { @@ -24,7 +24,7 @@ ScanInterface::ScanInterface() : pScanService(nullptr) ScanInterface::~ScanInterface() { - LOGI("Enter ScanInterface::~ScanInterface."); + WIFI_LOGI("Enter ScanInterface::~ScanInterface."); if (pScanService != nullptr) { delete pScanService; pScanService = nullptr; @@ -33,21 +33,21 @@ ScanInterface::~ScanInterface() int ScanInterface::Init(WifiMessageQueue *mqUp) { - LOGI("Enter ScanInterface::Init."); + WIFI_LOGI("Enter ScanInterface::Init."); if (mqUp == nullptr) { - LOGE("mqUp is null."); + WIFI_LOGE("mqUp is null."); return -1; } pScanService = new (std::nothrow) ScanService(); if (pScanService == nullptr) { - LOGE("New ScanService failed."); + WIFI_LOGE("New ScanService failed."); return -1; } if (!(pScanService->InitScanService(mqUp))) { - LOGE("InitScanService failed."); + WIFI_LOGE("InitScanService failed."); delete pScanService; pScanService = nullptr; return -1; @@ -58,7 +58,7 @@ int ScanInterface::Init(WifiMessageQueue *mqUp) int ScanInterface::UnInit() { - LOGI("Enter ScanInterface::UnInit."); + WIFI_LOGI("Enter ScanInterface::UnInit."); if (pScanService != nullptr) { pScanService->UnInitScanService(); } @@ -67,10 +67,10 @@ int ScanInterface::UnInit() int ScanInterface::PushMsg(WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::PushMsg"); + WIFI_LOGI("Enter ScanInterface::PushMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return -1; } @@ -80,9 +80,9 @@ int ScanInterface::PushMsg(WifiRequestMsgInfo *requestMsg) void ScanInterface::HandleRequestMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::HandleRequestMsg"); + WIFI_LOGI("Enter ScanInterface::HandleRequestMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return; } @@ -121,55 +121,55 @@ void ScanInterface::HandleRequestMsg(const WifiRequestMsgInfo *requestMsg) break; default: - LOGE("requestMsg->msgCode is error."); + WIFI_LOGE("requestMsg->msgCode is error."); break; } } void ScanInterface::DealScanMsg() { - LOGI("Enter ScanInterface::DealScanMsg"); + WIFI_LOGI("Enter ScanInterface::DealScanMsg"); if (!(pScanService->Scan(true))) { - LOGE("pScanService->Scan failed."); + WIFI_LOGE("pScanService->Scan failed."); } return; } void ScanInterface::DealScanParamMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::DealScanParamMsg"); + WIFI_LOGI("Enter ScanInterface::DealScanParamMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return; } if (!(pScanService->Scan(requestMsg->params.wifiScanParams))) { - LOGE("pScanService->Scan failed."); + WIFI_LOGE("pScanService->Scan failed."); } return; } void ScanInterface::DealScanReconnectMsg() { - LOGI("Enter ScanInterface::DealScanReconnectMsg"); + WIFI_LOGI("Enter ScanInterface::DealScanReconnectMsg"); if (!(pScanService->Scan(false))) { - LOGE("pScanService->Scan failed."); + WIFI_LOGE("pScanService->Scan failed."); } return; } void ScanInterface::DealScreenChangeMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::DealScreenChangeMsg"); + WIFI_LOGI("Enter ScanInterface::DealScreenChangeMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is invalid."); + WIFI_LOGE("requestMsg is invalid."); return; } if (requestMsg->params.wifiMockState.type != MODE_STATE_SCREEN) { - LOGE("requestMsg->params->wifiMockState is invalid."); + WIFI_LOGE("requestMsg->params->wifiMockState is invalid."); return; } bool screenOn = true; @@ -182,9 +182,9 @@ void ScanInterface::DealScreenChangeMsg(const WifiRequestMsgInfo *requestMsg) void ScanInterface::DealStaNotifyScanMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::DealStaNotifyScanMsg"); + WIFI_LOGI("Enter ScanInterface::DealStaNotifyScanMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return; } @@ -195,14 +195,14 @@ void ScanInterface::DealStaNotifyScanMsg(const WifiRequestMsgInfo *requestMsg) void ScanInterface::DealAppModeChangeMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::DealAppModeChangeMsg"); + WIFI_LOGI("Enter ScanInterface::DealAppModeChangeMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return; } if (requestMsg->params.wifiMockState.type != MODE_STATE_APP_RUN) { - LOGE("requestMsg->params->wifiMockState is invalid."); + WIFI_LOGE("requestMsg->params->wifiMockState is invalid."); return; } pScanService->SetOperateAppMode(requestMsg->params.wifiMockState.state); @@ -211,14 +211,14 @@ void ScanInterface::DealAppModeChangeMsg(const WifiRequestMsgInfo *requestMsg) void ScanInterface::DealCustomSceneChangeMsg(const WifiRequestMsgInfo *requestMsg) { - LOGI("Enter ScanInterface::DealCustomSceneChangeMsg"); + WIFI_LOGI("Enter ScanInterface::DealCustomSceneChangeMsg"); if (requestMsg == nullptr) { - LOGE("requestMsg is null."); + WIFI_LOGE("requestMsg is null."); return; } if (requestMsg->params.wifiMockState.type < MODE_STATE_POWER_SAVING) { - LOGE("requestMsg->params->wifiMockState is invalid."); + WIFI_LOGE("requestMsg->params->wifiMockState is invalid."); return; } time_t now = time(0); diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_monitor.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_monitor.cpp index dc3559ade..f590b39bd 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_monitor.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_monitor.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ #include "scan_monitor.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_SCAN_MONITOR" +DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine"); namespace OHOS { namespace Wifi { @@ -29,13 +29,13 @@ ScanMonitor::~ScanMonitor() bool ScanMonitor::InitScanMonitor() { - LOGI("Enter ScanMonitor::InitScanMonitor.\n"); + WIFI_LOGI("Enter ScanMonitor::InitScanMonitor.\n"); SupplicantEventCallback eventCallback; eventCallback.onScanNotify = &(ScanMonitor::ReceiveScanEventFromIdl); eventCallback.pInstance = (void *)this; if (WifiSupplicantHalInterface::GetInstance().RigisterSupplicantEventCallback(eventCallback) != WIFI_IDL_OPT_OK) { - LOGE("RigisterSupplicantEventCallback failed.\n"); + WIFI_LOGE("RigisterSupplicantEventCallback failed.\n"); return false; } @@ -50,9 +50,9 @@ void ScanMonitor::SetScanStateMachine(ScanStateMachine *paraScanStateMachine) void ScanMonitor::ReceiveScanEventFromIdl(int result, void *pInstance) { - LOGI("Enter ScanMonitor::ReceiveScanEventFromIdl, result is %{public}d.\n", result); + WIFI_LOGI("Enter ScanMonitor::ReceiveScanEventFromIdl, result is %{public}d.\n", result); if (pInstance == nullptr) { - LOGE("pInstance is null.\n"); + WIFI_LOGE("pInstance is null.\n"); return; } @@ -63,7 +63,7 @@ void ScanMonitor::ReceiveScanEventFromIdl(int result, void *pInstance) void ScanMonitor::ProcessReceiveScanEvent(int result) { - LOGI("Enter ScanMonitor::ProcessReceiveScanEvent, result is %{public}d.\n", result); + WIFI_LOGI("Enter ScanMonitor::ProcessReceiveScanEvent, result is %{public}d.\n", result); switch (result) { case SINGLE_SCAN_OVER_OK: { @@ -79,7 +79,7 @@ void ScanMonitor::ProcessReceiveScanEvent(int result) break; } default: { - LOGE("result is error.\n"); + WIFI_LOGE("result is error.\n"); break; } } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp index 92bf2ac7e..51cc7022b 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.cpp @@ -14,9 +14,9 @@ */ #include "scan_service.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_SCAN_SERVICE" +DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine"); namespace OHOS { namespace Wifi { @@ -41,7 +41,7 @@ ScanService::ScanService() ScanService::~ScanService() { - LOGI("Enter ScanService::~ScanService.\n"); + WIFI_LOGI("Enter ScanService::~ScanService.\n"); if (pScanMonitor != nullptr) { delete pScanMonitor; @@ -54,38 +54,38 @@ ScanService::~ScanService() bool ScanService::InitScanService(WifiMessageQueue *messageQueueUp) { - LOGI("Enter ScanService::InitScanService.\n"); + WIFI_LOGI("Enter ScanService::InitScanService.\n"); if (messageQueueUp == nullptr) { - LOGE("messageQueueUp is null.\n"); + WIFI_LOGE("messageQueueUp is null.\n"); return false; } pMessageQueueUp = messageQueueUp; pScanStateMachine = new (std::nothrow) ScanStateMachine(); if (pScanStateMachine == nullptr) { - LOGE("Alloc pScanStateMachine failed.\n"); + WIFI_LOGE("Alloc pScanStateMachine failed.\n"); return false; } if (!pScanStateMachine->InitScanStateMachine()) { - LOGE("InitScanStateMachine failed.\n"); + WIFI_LOGE("InitScanStateMachine failed.\n"); return false; } if (!pScanStateMachine->EnrollScanStatusListener( std::bind(&ScanService::HandleScanStatusReport, this, std::placeholders::_1))) { - LOGE("ScanStateMachine_->EnrollScanStatusListener failed.\n"); + WIFI_LOGE("ScanStateMachine_->EnrollScanStatusListener failed.\n"); return false; } pScanMonitor = new (std::nothrow) ScanMonitor(); if (pScanMonitor == nullptr) { - LOGE("Alloc pScanMonitor failed.\n"); + WIFI_LOGE("Alloc pScanMonitor failed.\n"); return false; } if (!pScanMonitor->InitScanMonitor()) { - LOGE("InitScanMonitor failed.\n"); + WIFI_LOGE("InitScanMonitor failed.\n"); return false; } @@ -93,7 +93,7 @@ bool ScanService::InitScanService(WifiMessageQueue *message (WifiStaHalInterface::GetInstance().GetSupportFrequencies(SCAN_BAND_5_GHZ, freqs5G) != WIFI_IDL_OPT_OK) || (WifiStaHalInterface::GetInstance().GetSupportFrequencies(SCAN_BAND_5_GHZ_DFS_ONLY, freqsDfs) != WIFI_IDL_OPT_OK)) { - LOGE("GetSupportFrequencies failed.\n"); + WIFI_LOGE("GetSupportFrequencies failed.\n"); } GetScanControlInfo(); GetScreenState(); @@ -104,7 +104,7 @@ bool ScanService::InitScanService(WifiMessageQueue *message void ScanService::UnInitScanService() { - LOGI("Enter ScanService::UnInitScanService.\n"); + WIFI_LOGI("Enter ScanService::UnInitScanService.\n"); pScanStateMachine->SendMessage(static_cast(CMD_SCAN_FINISH)); scanStartedFlag = false; @@ -116,7 +116,7 @@ void ScanService::UnInitScanService() void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) { - LOGI("Enter ScanService::HandleScanStatusReport.\n"); + WIFI_LOGI("Enter ScanService::HandleScanStatusReport.\n"); switch (scanStatusReport.status) { case SCAN_STARTED_STATUS: { @@ -155,7 +155,7 @@ void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) break; } default: { - LOGI("HandleStatusReport: status is error.\n"); + WIFI_LOGI("HandleStatusReport: status is error.\n"); break; } } @@ -164,7 +164,7 @@ void ScanService::HandleScanStatusReport(ScanStatusReport &scanStatusReport) void ScanService::HandleInnerEventReport(ScanInnerEventType innerEvent) { - LOGI("Enter ScanService::HandleInnerEventReport.\n"); + WIFI_LOGI("Enter ScanService::HandleInnerEventReport.\n"); switch (innerEvent) { case SYSTEM_SCAN_TIMER: { @@ -187,7 +187,7 @@ void ScanService::HandleInnerEventReport(ScanInnerEventType innerEvent) void ScanService::NotifyScanServiceStatus(int msgCode) { - LOGI("Enter ScanService::NotifyScanServiceStatus.\n"); + WIFI_LOGI("Enter ScanService::NotifyScanServiceStatus.\n"); WifiResponseMsgInfo notifyScanMsg; notifyScanMsg.msgCode = msgCode; @@ -197,7 +197,7 @@ void ScanService::NotifyScanServiceStatus(int msgCode) void ScanService::NotifyScanResult(int msgCode, int result) { - LOGI("Enter ScanService::NotifyScanResult.\n"); + WIFI_LOGI("Enter ScanService::NotifyScanResult.\n"); WifiResponseMsgInfo notifyScanMsg; notifyScanMsg.msgCode = msgCode; @@ -208,17 +208,17 @@ void ScanService::NotifyScanResult(int msgCode, int result) bool ScanService::Scan(bool externFlag) { - LOGI("Enter ScanService::Scan.\n"); + WIFI_LOGI("Enter ScanService::Scan.\n"); if (!scanStartedFlag) { - LOGE("Scan service has not started.\n"); + WIFI_LOGE("Scan service has not started.\n"); return false; } if (externFlag) { int appId = 0; if (!AllowExternScan(appId)) { - LOGE("AllowExternScan return false.\n"); + WIFI_LOGE("AllowExternScan return false.\n"); return false; } } @@ -229,7 +229,7 @@ bool ScanService::Scan(bool externFlag) * hidden network list */ if (!GetHiddenNetworkSsidList(scanConfig.hiddenNetworkSsid)) { - LOGE("GetHiddenNetworkSsidList failed.\n"); + WIFI_LOGE("GetHiddenNetworkSsidList failed.\n"); } scanConfig.scanBand = SCAN_BAND_BOTH_WITH_DFS; @@ -237,7 +237,7 @@ bool ScanService::Scan(bool externFlag) scanConfig.externFlag = externFlag; scanConfig.scanStyle = SCAN_TYPE_HIGH_ACCURACY; if (!SingleScan(scanConfig)) { - LOGE("SingleScan failed.\n"); + WIFI_LOGE("SingleScan failed.\n"); return false; } @@ -246,28 +246,28 @@ bool ScanService::Scan(bool externFlag) bool ScanService::Scan(const WifiScanParams ¶ms) { - LOGI("Enter ScanService::Scan.\n"); + WIFI_LOGI("Enter ScanService::Scan.\n"); if (!scanStartedFlag) { - LOGE("Scan service has not started.\n"); + WIFI_LOGE("Scan service has not started.\n"); return false; } int appId = 0; if (!AllowExternScan(appId)) { - LOGE("AllowExternScan return false.\n"); + WIFI_LOGE("AllowExternScan return false.\n"); return false; } if ((params.band < static_cast(SCAN_BAND_UNSPECIFIED)) || (params.band > static_cast(SCAN_BAND_BOTH_WITH_DFS))) { - LOGE("params.band is error.\n"); + WIFI_LOGE("params.band is error.\n"); return false; } /* When the frequency is specified, the band must be SCAN_BAND_UNSPECIFIED */ if (params.freqs.empty() && (params.band == static_cast(SCAN_BAND_UNSPECIFIED))) { - LOGE("params is error.\n"); + WIFI_LOGE("params is error.\n"); return false; } @@ -284,7 +284,7 @@ bool ScanService::Scan(const WifiScanParams ¶ms) * hidden network list */ if (!GetHiddenNetworkSsidList(scanConfig.hiddenNetworkSsid)) { - LOGE("GetHiddenNetworkSsidList failed.\n"); + WIFI_LOGE("GetHiddenNetworkSsidList failed.\n"); } } @@ -296,7 +296,7 @@ bool ScanService::Scan(const WifiScanParams ¶ms) scanConfig.scanStyle = SCAN_TYPE_HIGH_ACCURACY; if (!SingleScan(scanConfig)) { - LOGE("SingleScan failed.\n"); + WIFI_LOGE("SingleScan failed.\n"); return false; } @@ -305,11 +305,11 @@ bool ScanService::Scan(const WifiScanParams ¶ms) bool ScanService::SingleScan(ScanConfig &scanConfig) { - LOGI("Enter ScanService::SingleScan.\n"); + WIFI_LOGI("Enter ScanService::SingleScan.\n"); GetAllowBandFreqsControlInfo(scanConfig.scanBand, scanConfig.scanFreqs); if ((scanConfig.scanBand == SCAN_BAND_UNSPECIFIED) && (scanConfig.scanFreqs.empty())) { - LOGE("Have no allowed band or freq.\n"); + WIFI_LOGE("Have no allowed band or freq.\n"); return false; } @@ -328,7 +328,7 @@ bool ScanService::SingleScan(ScanConfig &scanConfig) } else if (scanConfig.scanBand != SCAN_BAND_BOTH_WITH_DFS) { /* Converting frequency bands to frequencies */ if (!GetBandFreqs(scanConfig.scanBand, interConfig.scanFreqs)) { - LOGE("GetBandFreqs failed.\n"); + WIFI_LOGE("GetBandFreqs failed.\n"); return false; } } @@ -336,23 +336,23 @@ bool ScanService::SingleScan(ScanConfig &scanConfig) /* Save the configuration */ int requestIndex = StoreRequestScanConfig(scanConfig, interConfig); if (requestIndex == MAX_SCAN_CONFIG_STORE_INDEX) { - LOGE("StoreRequestScanConfig failed.\n"); + WIFI_LOGE("StoreRequestScanConfig failed.\n"); return false; } /* Construct a message */ InternalMessage *interMessage = - pScanStateMachine->ObtainMessage(static_cast(CMD_START_COMMON_SCAN), requestIndex); + pScanStateMachine->CreateMessage(static_cast(CMD_START_COMMON_SCAN), requestIndex); if (interMessage == nullptr) { scanConfigMap.erase(requestIndex); - LOGE("ObtainMessage failed.\n"); + WIFI_LOGE("CreateMessage failed.\n"); return false; } if (!AddScanMessageBody(interMessage, interConfig)) { scanConfigMap.erase(requestIndex); - MessageManage::GetInstance().Recycle(interMessage); - LOGE("AddScanMessageBody failed.\n"); + MessageManage::GetInstance().ReclaimMsg(interMessage); + WIFI_LOGE("AddScanMessageBody failed.\n"); return false; } @@ -362,7 +362,7 @@ bool ScanService::SingleScan(ScanConfig &scanConfig) bool ScanService::GetBandFreqs(ScanBandType band, std::vector &freqs) { - LOGI("Enter ScanService::GetBandFreqs.\n"); + WIFI_LOGI("Enter ScanService::GetBandFreqs.\n"); switch (band) { case SCAN_BAND_24_GHZ: { @@ -400,29 +400,29 @@ bool ScanService::GetBandFreqs(ScanBandType band, std::vector &freqs) } default: - LOGE("bandType(%{public}d) is error.\n", band); + WIFI_LOGE("bandType(%{public}d) is error.\n", band); return false; } } bool ScanService::AddScanMessageBody(InternalMessage *interMessage, const InterScanConfig &interConfig) { - LOGI("Enter ScanService::AddScanMessageBody.\n"); + WIFI_LOGI("Enter ScanService::AddScanMessageBody.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null.\n"); + WIFI_LOGE("interMessage is null.\n"); return false; } interMessage->AddIntMessageBody(interConfig.hiddenNetworkSsid.size()); std::vector::const_iterator iter = interConfig.hiddenNetworkSsid.begin(); - for (; iter != interConfig.hiddenNetworkSsid.end(); iter++) { + for (; iter != interConfig.hiddenNetworkSsid.end(); ++iter) { interMessage->AddStringMessageBody(*iter); } interMessage->AddIntMessageBody(interConfig.scanFreqs.size()); std::vector::const_iterator iterFreq = interConfig.scanFreqs.begin(); - for (; iterFreq != interConfig.scanFreqs.end(); iterFreq++) { + for (; iterFreq != interConfig.scanFreqs.end(); ++iterFreq) { interMessage->AddIntMessageBody(*iterFreq); } @@ -438,7 +438,7 @@ bool ScanService::AddScanMessageBody(InternalMessage *interMessage, const InterS int ScanService::StoreRequestScanConfig(const ScanConfig &scanConfig, const InterScanConfig &interConfig) { - LOGI("Enter ScanService::StoreRequestScanConfig.\n"); + WIFI_LOGI("Enter ScanService::StoreRequestScanConfig.\n"); int i = 0; for (i = 0; i < MAX_SCAN_CONFIG_STORE_INDEX; i++) { @@ -464,7 +464,8 @@ int ScanService::StoreRequestScanConfig(const ScanConfig &scanConfig, const Inte struct timespec times = {0, 0}; clock_gettime(CLOCK_MONOTONIC, ×); - storeScanConfig.scanTime = times.tv_sec * SECOND_TO_MICRO_SECOND + times.tv_nsec / SECOND_TO_MILLI_SECOND; + storeScanConfig.scanTime = + static_cast(times.tv_sec) * SECOND_TO_MICRO_SECOND + times.tv_nsec / SECOND_TO_MILLI_SECOND; storeScanConfig.fullScanFlag = scanConfig.fullScanFlag; storeScanConfig.externFlag = scanConfig.externFlag; @@ -475,9 +476,9 @@ int ScanService::StoreRequestScanConfig(const ScanConfig &scanConfig, const Inte void ScanService::HandleCommonScanFailed(std::vector &requestIndexList) { - LOGI("Enter ScanService::HandleCommonScanFailed.\n"); + WIFI_LOGI("Enter ScanService::HandleCommonScanFailed.\n"); - for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); reqIter++) { + for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); ++reqIter) { ScanConfigMap::iterator configIter = scanConfigMap.find(*reqIter); /* No configuration found. */ if (configIter == scanConfigMap.end()) { @@ -500,11 +501,11 @@ void ScanService::HandleCommonScanFailed(std::vector &requestIndexList) void ScanService::HandleCommonScanResult( std::vector &requestIndexList, std::vector &scanResultList) { - LOGI("Enter ScanService::HandleCommonScanResult.\n"); + WIFI_LOGI("Enter ScanService::HandleCommonScanResult.\n"); bool fullScanInclude = false; bool fullScanStored = false; - for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); reqIter++) { + for (std::vector::iterator reqIter = requestIndexList.begin(); reqIter != requestIndexList.end(); ++reqIter) { ScanConfigMap::iterator configIter = scanConfigMap.find(*reqIter); /* No configuration found. */ if (configIter == scanConfigMap.end()) { @@ -522,12 +523,12 @@ void ScanService::HandleCommonScanResult( fullScanStored = true; NotifyScanResult(SCAN_RES, static_cast(ScanResultState::SCAN_OK)); } else { - LOGE("StoreFullScanResult failed.\n"); + WIFI_LOGE("StoreFullScanResult failed.\n"); } /* Specify Scan Result */ } else { if (!StoreUserScanResult(configIter->second, scanResultList)) { - LOGE("StoreUserScanResult failed.\n"); + WIFI_LOGE("StoreUserScanResult failed.\n"); } NotifyScanResult(SCAN_PARAM_RES, static_cast(ScanResultState::SCAN_OK)); } @@ -537,7 +538,7 @@ void ScanService::HandleCommonScanResult( /* Send the scanning result to the module registered for listening */ ScanResultHandlerMap::iterator handleIter = scanResultHandlerMap.begin(); - for (; handleIter != scanResultHandlerMap.end(); handleIter++) { + for (; handleIter != scanResultHandlerMap.end(); ++handleIter) { if (handleIter->second) { handleIter->second(scanResultList); } @@ -552,14 +553,14 @@ void ScanService::HandleCommonScanResult( bool ScanService::StoreFullScanResult( const StoreScanConfig &scanConfig, const std::vector &scanResultList) { - LOGI("Enter ScanService::StoreFullScanResult.\n"); + WIFI_LOGI("Enter ScanService::StoreFullScanResult.\n"); /* Filtering result */ - LOGI("scanConfig.scanTime is %ld.\n", scanConfig.scanTime); - LOGI("Receive %{public}d scan results.\n", (int)(scanResultList.size())); + WIFI_LOGI("scanConfig.scanTime is %lld.\n", scanConfig.scanTime); + WIFI_LOGI("Receive %{public}d scan results.\n", (int)(scanResultList.size())); std::vector filterScanResult; std::vector::const_iterator iter = scanResultList.begin(); - for (; iter != scanResultList.end(); iter++) { + for (; iter != scanResultList.end(); ++iter) { char tmpBuf[128] = ""; EncryptLogMsg(iter->ssid.c_str(), tmpBuf, sizeof(tmpBuf)); WifiScanInfo scanInfo; @@ -567,14 +568,15 @@ bool ScanService::StoreFullScanResult( scanInfo.ssid = iter->ssid; scanInfo.capabilities = iter->capabilities; scanInfo.frequency = iter->frequency; - scanInfo.level = iter->level; + scanInfo.rssi = iter->rssi; scanInfo.timestamp = iter->timestamp; + scanInfo.band = iter->band; filterScanResult.push_back(scanInfo); } if (WifiSettings::GetInstance().SaveScanInfoList(filterScanResult) != 0) { - LOGE("WifiSettings::GetInstance().SaveScanInfoList failed.\n"); + WIFI_LOGE("WifiSettings::GetInstance().SaveScanInfoList failed.\n"); return false; } @@ -584,12 +586,12 @@ bool ScanService::StoreFullScanResult( bool ScanService::StoreUserScanResult( const StoreScanConfig &scanConfig, const std::vector &scanResultList) { - LOGI("Enter ScanService::StoreUserScanResult.\n"); + WIFI_LOGI("Enter ScanService::StoreUserScanResult.\n"); /* Filtering result */ std::vector filterScanResult; std::vector::const_iterator iter = scanResultList.begin(); - for (; iter != scanResultList.end(); iter++) { + for (; iter != scanResultList.end(); ++iter) { /* Timestamp filtering */ if ((iter->timestamp) <= scanConfig.scanTime) { continue; @@ -618,8 +620,9 @@ bool ScanService::StoreUserScanResult( scanInfo.ssid = iter->ssid; scanInfo.capabilities = iter->capabilities; scanInfo.frequency = iter->frequency; - scanInfo.level = iter->level; + scanInfo.rssi = iter->rssi; scanInfo.timestamp = iter->timestamp; + scanInfo.band = iter->band; filterScanResult.push_back(scanInfo); } @@ -633,7 +636,7 @@ bool ScanService::StoreUserScanResult( void ScanService::ReportScanResults(const std::vector &scanResultList) { - LOGI("Enter ScanService::ReportScanResults.\n"); + WIFI_LOGI("Enter ScanService::ReportScanResults.\n"); /* Filtering result */ std::vector scanInfoList; @@ -650,18 +653,19 @@ void ScanService::ReportScanResults(const std::vector &scanResu void ScanService::ConvertScanResults( const std::vector &scanResultList, std::vector &scanInfoList) { - LOGI("Enter ScanService::ConvertScanResults.\n"); + WIFI_LOGI("Enter ScanService::ConvertScanResults.\n"); /* Filtering result */ std::vector::const_iterator iter = scanResultList.begin(); - for (; iter != scanResultList.end(); iter++) { + for (; iter != scanResultList.end(); ++iter) { WifiScanInfo scanInfo; scanInfo.bssid = iter->bssid; scanInfo.ssid = iter->ssid; scanInfo.capabilities = iter->capabilities; scanInfo.frequency = iter->frequency; - scanInfo.level = iter->level; + scanInfo.rssi = iter->rssi; scanInfo.timestamp = iter->timestamp; + scanInfo.band = iter->band; scanInfoList.push_back(scanInfo); } @@ -674,30 +678,30 @@ void ScanService::ConvertScanResults( */ bool ScanService::BeginPnoScan() { - LOGI("Enter ScanService::BeginPnoScan.\n"); + WIFI_LOGI("Enter ScanService::BeginPnoScan.\n"); if (isPnoScanBegined) { - LOGI("PNO scan has started.\n"); + WIFI_LOGI("PNO scan has started.\n"); return false; } if (!AllowPnoScan()) { - LOGI("AllowPnoScan return false.\n"); + WIFI_LOGI("AllowPnoScan return false.\n"); return false; } PnoScanConfig pnoScanConfig; /* Obtain the network list from the configuration center. */ if (!GetSavedNetworkSsidList(pnoScanConfig.savedNetworkSsid)) { - LOGE("GetSavedNetworkSsidList failed.\n"); + WIFI_LOGE("GetSavedNetworkSsidList failed.\n"); return false; } if (pnoScanConfig.savedNetworkSsid.size() == 0) { - LOGE("Have no saved network, not need to start PNO scan.\n"); + WIFI_LOGE("Have no saved network, not need to start PNO scan.\n"); return false; } if (!GetHiddenNetworkSsidList(pnoScanConfig.hiddenNetworkSsid)) { - LOGE("GetHiddenNetworkSsidList failed.\n"); + WIFI_LOGE("GetHiddenNetworkSsidList failed.\n"); return false; } @@ -713,12 +717,12 @@ bool ScanService::BeginPnoScan() InterScanConfig interConfig; interConfig.fullScanFlag = true; if (!GetBandFreqs(SCAN_BAND_BOTH_WITH_DFS, interConfig.scanFreqs)) { - LOGE("GetBandFreqs failed.\n"); + WIFI_LOGE("GetBandFreqs failed.\n"); return false; } if (!PnoScan(pnoScanConfig, interConfig)) { - LOGE("PnoScan failed.\n"); + WIFI_LOGE("PnoScan failed.\n"); return false; } isPnoScanBegined = true; @@ -728,44 +732,45 @@ bool ScanService::BeginPnoScan() bool ScanService::PnoScan(const PnoScanConfig &pnoScanConfig, const InterScanConfig &interScanConfig) { - LOGI("Enter ScanService::PnoScan.\n"); + WIFI_LOGI("Enter ScanService::PnoScan.\n"); /* Construct a message. */ - InternalMessage *interMessage = pScanStateMachine->ObtainMessage(CMD_START_PNO_SCAN); + InternalMessage *interMessage = pScanStateMachine->CreateMessage(CMD_START_PNO_SCAN); if (interMessage == nullptr) { - LOGE("ObtainMessage failed.\n"); + WIFI_LOGE("CreateMessage failed.\n"); return false; } if (!AddPnoScanMessageBody(interMessage, pnoScanConfig)) { - MessageManage::GetInstance().Recycle(interMessage); - LOGE("AddPnoScanMessageBody failed.\n"); + MessageManage::GetInstance().ReclaimMsg(interMessage); + WIFI_LOGE("AddPnoScanMessageBody failed.\n"); return false; } if (!AddScanMessageBody(interMessage, interScanConfig)) { - MessageManage::GetInstance().Recycle(interMessage); - LOGE("AddScanMessageBody failed.\n"); + MessageManage::GetInstance().ReclaimMsg(interMessage); + WIFI_LOGE("AddScanMessageBody failed.\n"); return false; } - LOGI("Begin: send message."); + WIFI_LOGI("Begin: send message."); pScanStateMachine->SendMessage(interMessage); - LOGI("End: send message."); + WIFI_LOGI("End: send message."); struct timespec times = {0, 0}; clock_gettime(CLOCK_MONOTONIC, ×); - pnoScanStartTime = times.tv_sec * SECOND_TO_MILLI_SECOND + times.tv_nsec / SECOND_TO_MICRO_SECOND; + pnoScanStartTime = + static_cast(times.tv_sec) * SECOND_TO_MILLI_SECOND + times.tv_nsec / SECOND_TO_MICRO_SECOND; return true; } bool ScanService::AddPnoScanMessageBody(InternalMessage *interMessage, const PnoScanConfig &pnoScanConfig) { - LOGI("Enter ScanService::AddPnoScanMessageBody.\n"); + WIFI_LOGI("Enter ScanService::AddPnoScanMessageBody.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null.\n"); + WIFI_LOGE("interMessage is null.\n"); return false; } @@ -775,19 +780,19 @@ bool ScanService::AddPnoScanMessageBody(InternalMessage *interMessage, const Pno interMessage->AddIntMessageBody(pnoScanConfig.hiddenNetworkSsid.size()); std::vector::const_iterator iter = pnoScanConfig.hiddenNetworkSsid.begin(); - for (; iter != pnoScanConfig.hiddenNetworkSsid.end(); iter++) { + for (; iter != pnoScanConfig.hiddenNetworkSsid.end(); ++iter) { interMessage->AddStringMessageBody(*iter); } interMessage->AddIntMessageBody(pnoScanConfig.savedNetworkSsid.size()); std::vector::const_iterator iter2 = pnoScanConfig.savedNetworkSsid.begin(); - for (; iter2 != pnoScanConfig.savedNetworkSsid.end(); iter2++) { + for (; iter2 != pnoScanConfig.savedNetworkSsid.end(); ++iter2) { interMessage->AddStringMessageBody(*iter2); } interMessage->AddIntMessageBody(pnoScanConfig.freqs.size()); std::vector::const_iterator iter3 = pnoScanConfig.freqs.begin(); - for (; iter3 != pnoScanConfig.freqs.end(); iter3++) { + for (; iter3 != pnoScanConfig.freqs.end(); ++iter3) { interMessage->AddIntMessageBody(*iter3); } @@ -796,25 +801,25 @@ bool ScanService::AddPnoScanMessageBody(InternalMessage *interMessage, const Pno void ScanService::HandlePnoScanResult(std::vector &scanResultList) { - LOGI("Enter ScanService::HandlePnoScanResult.\n"); + WIFI_LOGI("Enter ScanService::HandlePnoScanResult.\n"); std::vector filterScanResult; std::vector::iterator iter = scanResultList.begin(); - for (; iter != scanResultList.end(); iter++) { + for (; iter != scanResultList.end(); ++iter) { if ((iter->timestamp / SECOND_TO_MILLI_SECOND) > pnoScanStartTime) { filterScanResult.push_back(*iter); - LOGI("InterScanResult.bssid is %s.\n", iter->bssid.c_str()); - LOGI("InterScanResult.ssid is %s.\n", iter->ssid.c_str()); - LOGI("InterScanResult.capabilities is %{public}s.\n", iter->capabilities.c_str()); - LOGI("InterScanResult.frequency is %{public}d.\n", iter->frequency); - LOGI("InterScanResult.level is %{public}d.\n", iter->level); - LOGI("InterScanResult.timestamp is %ld.\n", iter->timestamp); + WIFI_LOGI("InterScanResult.bssid is %s.\n", iter->bssid.c_str()); + WIFI_LOGI("InterScanResult.ssid is %s.\n", iter->ssid.c_str()); + WIFI_LOGI("InterScanResult.capabilities is %{public}s.\n", iter->capabilities.c_str()); + WIFI_LOGI("InterScanResult.frequency is %{public}d.\n", iter->frequency); + WIFI_LOGI("InterScanResult.rssi is %{public}d.\n", iter->rssi); + WIFI_LOGI("InterScanResult.timestamp is %lld.\n", iter->timestamp); } } /* Send the scanning result to the module registered for listening */ PnoScanResultHandlerMap::iterator handleIter = pnoScanResultHandlerMap.begin(); - for (; handleIter != pnoScanResultHandlerMap.end(); handleIter++) { + for (; handleIter != pnoScanResultHandlerMap.end(); ++handleIter) { if (handleIter->second) { handleIter->second(filterScanResult); } @@ -828,7 +833,7 @@ void ScanService::HandlePnoScanResult(std::vector &scanResultLi void ScanService::EndPnoScan() { - LOGI("Enter ScanService::EndPnoScan.\n"); + WIFI_LOGI("Enter ScanService::EndPnoScan.\n"); if (!isPnoScanBegined) { return; @@ -841,7 +846,7 @@ void ScanService::EndPnoScan() void ScanService::HandleScreenStatusChanged(bool screenOn) { - LOGI("Enter ScanService::HandleScreenStatusChanged."); + WIFI_LOGI("Enter ScanService::HandleScreenStatusChanged."); isScreenOn = screenOn; SystemScanProcess(false); @@ -850,7 +855,7 @@ void ScanService::HandleScreenStatusChanged(bool screenOn) void ScanService::HandleStaStatusChanged(int status) { - LOGI("Enter ScanService::HandleStaStatusChanged."); + WIFI_LOGI("Enter ScanService::HandleStaStatusChanged."); staStatus = status; switch (staStatus) { @@ -873,17 +878,17 @@ void ScanService::HandleStaStatusChanged(int status) void ScanService::SystemScanProcess(bool scanAtOnce) { - LOGI("Enter ScanService::SystemScanProcess."); + WIFI_LOGI("Enter ScanService::SystemScanProcess."); StopSystemScan(); - LOGD("isScreenOn is:%{public}d", isScreenOn); + WIFI_LOGD("isScreenOn is:%{public}d", isScreenOn); if (isScreenOn) { for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); - iter++) { + ++iter) { if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && iter->isSingle == false) { - LOGD("iter->intervalMode is:%{public}d", iter->intervalMode); - LOGD("iter->interval is:%{public}d", iter->interval); - LOGD("iter->count is:%{public}d", iter->count); + WIFI_LOGD("iter->intervalMode is:%{public}d", iter->intervalMode); + WIFI_LOGD("iter->interval is:%{public}d", iter->interval); + WIFI_LOGD("iter->count is:%{public}d", iter->count); systemScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; systemScanIntervalMode.scanIntervalMode.interval = iter->interval; systemScanIntervalMode.scanIntervalMode.count = iter->count; @@ -892,7 +897,7 @@ void ScanService::SystemScanProcess(bool scanAtOnce) StartSystemTimerScan(scanAtOnce); } else { if (!BeginPnoScan()) { - LOGE("BeginPnoScan failed."); + WIFI_LOGE("BeginPnoScan failed."); return; } } @@ -902,7 +907,7 @@ void ScanService::SystemScanProcess(bool scanAtOnce) void ScanService::StopSystemScan() { - LOGI("Enter ScanService::StopSystemScan."); + WIFI_LOGI("Enter ScanService::StopSystemScan."); pScanStateMachine->StopTimer(static_cast(SYSTEM_SCAN_TIMER)); EndPnoScan(); @@ -913,16 +918,17 @@ void ScanService::StopSystemScan() void ScanService::StartSystemTimerScan(bool scanAtOnce) { - LOGI("Enter ScanService::StartSystemTimerScan."); + WIFI_LOGI("Enter ScanService::StartSystemTimerScan."); if (!AllowSystemTimerScan()) { - LOGI("AllowSystemTimerScan return false."); + WIFI_LOGI("AllowSystemTimerScan return false."); return; } struct timespec times = {0, 0}; clock_gettime(CLOCK_MONOTONIC, ×); - long nowTime = times.tv_sec * SECOND_TO_MILLI_SECOND + times.tv_nsec / SECOND_TO_MICRO_SECOND; + int64_t nowTime = + static_cast(times.tv_sec) * SECOND_TO_MILLI_SECOND + times.tv_nsec / SECOND_TO_MICRO_SECOND; int sinceLastScan = 0; if (lastSystemScanTime != 0) { sinceLastScan = nowTime - lastSystemScanTime; @@ -933,20 +939,20 @@ void ScanService::StartSystemTimerScan(bool scanAtOnce) * or the time since the last scan is longer than the scan interval */ int scanTime = SYSTEM_SCAN_INIT_TIME; - LOGD("interval:%{public}d", systemScanIntervalMode.scanIntervalMode.interval); + WIFI_LOGD("interval:%{public}d", systemScanIntervalMode.scanIntervalMode.interval); if (systemScanIntervalMode.scanIntervalMode.interval > 0) { scanTime = systemScanIntervalMode.scanIntervalMode.interval; } if (scanAtOnce || (lastSystemScanTime == 0) || (sinceLastScan >= systemScanIntervalMode.scanIntervalMode.interval)) { if (!Scan(false)) { - LOGE("Scan failed."); + WIFI_LOGE("Scan failed."); } lastSystemScanTime = nowTime; } else { scanTime = systemScanIntervalMode.scanIntervalMode.interval - sinceLastScan; } - LOGD("scanTime: %{public}d, interval:%{public}d, count:%{public}d", + WIFI_LOGD("scanTime: %{public}d, interval:%{public}d, count:%{public}d", scanTime, systemScanIntervalMode.scanIntervalMode.interval, systemScanIntervalMode.scanIntervalMode.count); @@ -963,7 +969,7 @@ void ScanService::HandleSystemScanTimeout() void ScanService::DisconnectedTimerScan() { - LOGI("Enter ScanService::DisconnectedTimerScan.\n"); + WIFI_LOGI("Enter ScanService::DisconnectedTimerScan.\n"); pScanStateMachine->StartTimer(static_cast(DISCONNECTED_SCAN_TIMER), DISCONNECTED_SCAN_INTERVAL); return; @@ -971,14 +977,14 @@ void ScanService::DisconnectedTimerScan() void ScanService::HandleDisconnectedScanTimeout() { - LOGI("Enter ScanService::HandleDisconnectedScanTimeout.\n"); + WIFI_LOGI("Enter ScanService::HandleDisconnectedScanTimeout.\n"); if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED)) { return; } if (!Scan(false)) { - LOGE("Scan failed."); + WIFI_LOGE("Scan failed."); } pScanStateMachine->StartTimer(static_cast(DISCONNECTED_SCAN_TIMER), DISCONNECTED_SCAN_INTERVAL); @@ -987,15 +993,15 @@ void ScanService::HandleDisconnectedScanTimeout() void ScanService::RestartPnoScanTimeOut() { - LOGI("Enter ScanService::RestartPnoScanTimeOut.\n"); + WIFI_LOGI("Enter ScanService::RestartPnoScanTimeOut.\n"); pnoScanFailedNum++; if (pnoScanFailedNum > MAX_PNO_SCAN_FAILED_NUM) { - LOGE("Over max pno failed number."); + WIFI_LOGE("Over max pno failed number."); return; } if (!BeginPnoScan()) { - LOGE("BeginPnoScan failed."); + WIFI_LOGE("BeginPnoScan failed."); return; } @@ -1004,10 +1010,10 @@ void ScanService::RestartPnoScanTimeOut() void ScanService::GetScanControlInfo() { - LOGI("Enter ScanService::GetScanControlInfo.\n"); + WIFI_LOGI("Enter ScanService::GetScanControlInfo.\n"); if (WifiSettings::GetInstance().GetScanControlInfo(scanControlInfo) != 0) { - LOGE("WifiSettings::GetInstance().GetScanControlInfo failed"); + WIFI_LOGE("WifiSettings::GetInstance().GetScanControlInfo failed"); } return; @@ -1015,7 +1021,7 @@ void ScanService::GetScanControlInfo() void ScanService::GetScreenState() { - LOGI("Enter ScanService::GetScreenState.\n"); + WIFI_LOGI("Enter ScanService::GetScreenState.\n"); int screenState = WifiSettings::GetInstance().GetScreenState(); isScreenOn = true; if (screenState == SCREEN_CLOSED) { @@ -1027,7 +1033,7 @@ void ScanService::GetScreenState() void ScanService::SetOperateAppMode(int appMode) { - LOGI("Enter ScanService::SetOperateAppMode.\n"); + WIFI_LOGI("Enter ScanService::SetOperateAppMode.\n"); operateAppMode = appMode; return; @@ -1035,7 +1041,7 @@ void ScanService::SetOperateAppMode(int appMode) ScanMode ScanService::GetOperateAppMode() { - LOGI("Enter ScanService::GetOperateAppMode.\n"); + WIFI_LOGI("Enter ScanService::GetOperateAppMode.\n"); ScanMode scanMode = ScanMode::SYS_FOREGROUND_SCAN; switch (operateAppMode) { case APP_FOREGROUND_SCAN: @@ -1055,7 +1061,7 @@ ScanMode ScanService::GetOperateAppMode() break; default: - LOGE("operateAppMode %{public}d is invalid.", operateAppMode); + WIFI_LOGE("operateAppMode %{public}d is invalid.", operateAppMode); break; } @@ -1064,27 +1070,27 @@ ScanMode ScanService::GetOperateAppMode() bool ScanService::AllowExternScan(int appId) { - LOGI("Enter ScanService::AllowExternScan.\n"); + WIFI_LOGI("Enter ScanService::AllowExternScan.\n"); int staScene = GetStaScene(); ScanMode scanMode = GetOperateAppMode(); - LOGD("staScene is %{public}d, scanMode is %{public}d", staScene, (int)scanMode); + WIFI_LOGD("staScene is %{public}d, scanMode is %{public}d", staScene, (int)scanMode); if (!AllowExternScanByForbid(staScene, scanMode)) { - LOGD("extern scan not allow by forbid mode"); + WIFI_LOGD("extern scan not allow by forbid mode"); return false; } if (!AllowExternScanByInterval(appId, staScene, scanMode)) { - LOGD("extern scan not allow by interval mode"); + WIFI_LOGD("extern scan not allow by interval mode"); return false; } - LOGD("extern scan has allowed"); + WIFI_LOGD("extern scan has allowed"); return true; } bool ScanService::AllowSystemTimerScan() { - LOGI("Enter ScanService::AllowSystemTimerScan.\n"); + WIFI_LOGI("Enter ScanService::AllowSystemTimerScan.\n"); if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED) && staStatus != static_cast(OperateResState::CONNECT_AP_CONNECTED)) { @@ -1104,16 +1110,16 @@ bool ScanService::AllowSystemTimerScan() } if (!AllowScanDuringStaScene(staScene, ScanMode::SYSTEM_TIMER_SCAN)) { - LOGD("system timer scan not allowed, staScene is %{public}d", staScene); + WIFI_LOGD("system timer scan not allowed, staScene is %{public}d", staScene); return false; } if (!AllowScanDuringCustomScene(ScanMode::SYSTEM_TIMER_SCAN)) { - LOGD("system timer scan not allowed"); + WIFI_LOGD("system timer scan not allowed"); return false; } - for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); iter++) { + for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); ++iter) { if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::SYSTEM_TIMER_SCAN && iter->isSingle == false) { if (!SystemScanByInterval(systemScanIntervalMode.expScanCount, @@ -1124,13 +1130,13 @@ bool ScanService::AllowSystemTimerScan() } } - LOGD("allow system timer scan"); + WIFI_LOGD("allow system timer scan"); return true; } bool ScanService::AllowPnoScan() { - LOGI("Enter ScanService::AllowPnoScan.\n"); + WIFI_LOGI("Enter ScanService::AllowPnoScan.\n"); if (staStatus != static_cast(OperateResState::DISCONNECT_DISCONNECTED)) { return false; @@ -1141,15 +1147,15 @@ bool ScanService::AllowPnoScan() return false; } if (!AllowScanDuringStaScene(staScene, ScanMode::PNO_SCAN)) { - LOGD("pnoScan is not allowed for forbid map, staScene is %{public}d", staScene); + WIFI_LOGD("pnoScan is not allowed for forbid map, staScene is %{public}d", staScene); return false; } if (!AllowScanDuringCustomScene(ScanMode::PNO_SCAN)) { - LOGD("pnoScan is not allowed for forbid map"); + WIFI_LOGD("pnoScan is not allowed for forbid map"); return false; } - for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); iter++) { + for (auto iter = scanControlInfo.scanIntervalList.begin(); iter != scanControlInfo.scanIntervalList.end(); ++iter) { if (iter->scanScene == SCAN_SCENE_ALL && iter->scanMode == ScanMode::PNO_SCAN && iter->isSingle == false) { pnoScanIntervalMode.scanIntervalMode.intervalMode = iter->intervalMode; pnoScanIntervalMode.scanIntervalMode.interval = iter->interval; @@ -1158,18 +1164,18 @@ bool ScanService::AllowPnoScan() pnoScanIntervalMode.fixedCurrentTime, pnoScanIntervalMode.scanIntervalMode.interval, pnoScanIntervalMode.scanIntervalMode.count)) { - LOGD("pnoScan is not allowed for interval mode"); + WIFI_LOGD("pnoScan is not allowed for interval mode"); return false; } } } - LOGD("pno scan is allowed"); + WIFI_LOGD("pno scan is allowed"); return true; } bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode) { - LOGI("Enter ScanService::AllowExternScanByForbid.\n"); + WIFI_LOGI("Enter ScanService::AllowExternScanByForbid.\n"); if (IsExternScanning()) { if (!AllowScanDuringScanning(scanMode)) { @@ -1205,7 +1211,7 @@ bool ScanService::AllowExternScanByForbid(int staScene, ScanMode scanMode) bool ScanService::AllowExternScanByInterval(int appId, int staScene, ScanMode scanMode) { - LOGI("Enter ScanService::AllowExternScanByInterval.\n"); + WIFI_LOGI("Enter ScanService::AllowExternScanByInterval.\n"); if (!AllowExternScanByIntervalMode(appId, staScene, scanMode)) { return false; @@ -1230,7 +1236,7 @@ bool ScanService::AllowExternScanByInterval(int appId, int staScene, ScanMode sc int ScanService::GetStaScene() { - LOGI("Enter ScanService::GetStaScene.\n"); + WIFI_LOGI("Enter ScanService::GetStaScene.\n"); switch (staStatus) { case static_cast(OperateResState::CONNECT_AP_CONNECTED): @@ -1252,9 +1258,9 @@ int ScanService::GetStaScene() bool ScanService::IsExternScanning() { - LOGI("Enter ScanService::IsExternScanning.\n"); + WIFI_LOGI("Enter ScanService::IsExternScanning.\n"); - for (auto iter = scanConfigMap.begin(); iter != scanConfigMap.end(); iter++) { + for (auto iter = scanConfigMap.begin(); iter != scanConfigMap.end(); ++iter) { if (iter->second.externFlag) { return true; } @@ -1264,7 +1270,7 @@ bool ScanService::IsExternScanning() void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vector &freqs) { - LOGI("Enter ScanService::GetAllowBandFreqsControlInfo.\n"); + WIFI_LOGI("Enter ScanService::GetAllowBandFreqsControlInfo.\n"); int staScene = GetStaScene(); @@ -1284,7 +1290,7 @@ void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vect } auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_ALL); if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { + for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { if (iter->scanMode == ScanMode::BAND_24GHZ_SCAN) { allow24Ghz = false; } @@ -1295,7 +1301,7 @@ void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vect } if ((!allow24Ghz) && (!allow5Ghz)) { - LOGE("Both 2.4G and 5G are not allowed"); + WIFI_LOGE("Both 2.4G and 5G are not allowed"); scanBand = SCAN_BAND_UNSPECIFIED; freqs.clear(); return; @@ -1316,7 +1322,7 @@ void ScanService::GetAllowBandFreqsControlInfo(ScanBandType &scanBand, std::vect ScanBandType ScanService::ConvertBandNotAllow24G(ScanBandType scanBand) { - LOGI("Enter ScanService::ConvertBandNotAllow24G.\n"); + WIFI_LOGI("Enter ScanService::ConvertBandNotAllow24G.\n"); switch (scanBand) { case SCAN_BAND_24_GHZ: @@ -1340,7 +1346,7 @@ ScanBandType ScanService::ConvertBandNotAllow24G(ScanBandType scanBand) ScanBandType ScanService::ConvertBandNotAllow5G(ScanBandType scanBand) { - LOGI("Enter ScanService::ConvertBandNotAllow5G.\n"); + WIFI_LOGI("Enter ScanService::ConvertBandNotAllow5G.\n"); switch (scanBand) { case SCAN_BAND_24_GHZ: @@ -1358,14 +1364,14 @@ ScanBandType ScanService::ConvertBandNotAllow5G(ScanBandType scanBand) void ScanService::Delete24GhzFreqs(std::vector &freqs) { - LOGI("Enter ScanService::Delete24GhzFreqs.\n"); + WIFI_LOGI("Enter ScanService::Delete24GhzFreqs.\n"); auto iter = freqs.begin(); while (iter != freqs.end()) { if (*iter < FREQS_24G_MAX_VALUE) { freqs.erase(iter); } else { - iter++; + ++iter; } } @@ -1374,14 +1380,14 @@ void ScanService::Delete24GhzFreqs(std::vector &freqs) void ScanService::Delete5GhzFreqs(std::vector &freqs) { - LOGI("Enter ScanService::Delete24GhzFreqs.\n"); + WIFI_LOGI("Enter ScanService::Delete24GhzFreqs.\n"); auto iter = freqs.begin(); while (iter != freqs.end()) { if (*iter > FREQS_5G_MIN_VALUE) { freqs.erase(iter); } else { - iter++; + ++iter; } } @@ -1390,15 +1396,15 @@ void ScanService::Delete5GhzFreqs(std::vector &freqs) bool ScanService::GetSavedNetworkSsidList(std::vector &savedNetworkSsid) { - LOGI("Enter ScanService::GetSavedNetworkSsidList.\n"); + WIFI_LOGI("Enter ScanService::GetSavedNetworkSsidList.\n"); std::vector deviceConfigs; if (WifiSettings::GetInstance().GetDeviceConfig(deviceConfigs) != 0) { - LOGE("WifiSettings::GetInstance().GetDeviceConfig failed"); + WIFI_LOGE("WifiSettings::GetInstance().GetDeviceConfig failed"); return false; } - for (auto iter = deviceConfigs.begin(); iter != deviceConfigs.end(); iter++) { + for (auto iter = deviceConfigs.begin(); iter != deviceConfigs.end(); ++iter) { if ((iter->status == static_cast(WifiDeviceConfigStatus::ENABLED)) && (!(iter->isPasspoint)) && (!(iter->isEphemeral))) { savedNetworkSsid.push_back(iter->ssid); @@ -1410,15 +1416,15 @@ bool ScanService::GetSavedNetworkSsidList(std::vector &savedNetwork bool ScanService::GetHiddenNetworkSsidList(std::vector &hiddenNetworkSsid) { - LOGI("Enter ScanService::GetHiddenNetworkSsidList.\n"); + WIFI_LOGI("Enter ScanService::GetHiddenNetworkSsidList.\n"); std::vector deviceConfigs; if (WifiSettings::GetInstance().GetDeviceConfig(deviceConfigs) != 0) { - LOGE("WifiSettings::GetInstance().GetDeviceConfig failed"); + WIFI_LOGE("WifiSettings::GetInstance().GetDeviceConfig failed"); return false; } - for (auto iter = deviceConfigs.begin(); iter != deviceConfigs.end(); iter++) { + for (auto iter = deviceConfigs.begin(); iter != deviceConfigs.end(); ++iter) { if (iter->hiddenSSID) { hiddenNetworkSsid.push_back(iter->ssid); } @@ -1429,10 +1435,10 @@ bool ScanService::GetHiddenNetworkSsidList(std::vector &hiddenNetwo void ScanService::SetCustomScene(int scene, time_t currentTime) { - LOGI("Enter ScanService::SetCustomScene.\n"); + WIFI_LOGI("Enter ScanService::SetCustomScene.\n"); if (scene < static_cast(SCAN_SCENE_DEEP_SLEEP) || scene >= static_cast(SCAN_SCENE_ALL)) { - LOGE("invalid CustomScene status:%{public}d", scene); + WIFI_LOGE("invalid CustomScene status:%{public}d", scene); return; } customSceneTimeMap[scene] = currentTime; @@ -1442,7 +1448,7 @@ void ScanService::SetCustomScene(int scene, time_t currentTime) void ScanService::ClearScanControlValue() { - LOGI("Enter ScanService::ClearScanControlValue.\n"); + WIFI_LOGI("Enter ScanService::ClearScanControlValue.\n"); staCurrentTime = 0; customCurrentTime = 0; @@ -1454,7 +1460,7 @@ void ScanService::ClearScanControlValue() void ScanService::SetStaCurrentTime() { - LOGI("Enter ScanService::SetStaCurrentTime.\n"); + WIFI_LOGI("Enter ScanService::SetStaCurrentTime.\n"); time_t now = time(0); staCurrentTime = now; @@ -1463,11 +1469,11 @@ void ScanService::SetStaCurrentTime() bool ScanService::AllowScanDuringScanning(ScanMode scanMode) { - LOGI("Enter ScanService::AllowScanDuringScanning.\n"); + WIFI_LOGI("Enter ScanService::AllowScanDuringScanning.\n"); auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_SCANNING); if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { + for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { if (iter->scanMode == scanMode) { return false; } @@ -1478,11 +1484,11 @@ bool ScanService::AllowScanDuringScanning(ScanMode scanMode) bool ScanService::AllowScanDuringScreenOff(ScanMode scanMode) { - LOGI("Enter ScanService::AllowScanDuringScreenOff.\n"); + WIFI_LOGI("Enter ScanService::AllowScanDuringScreenOff.\n"); auto forbidIter = scanControlInfo.scanForbidMap.find(SCAN_SCENE_SCREEN_OFF); if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { + for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { if (iter->scanMode == scanMode) { return false; } @@ -1493,13 +1499,13 @@ bool ScanService::AllowScanDuringScreenOff(ScanMode scanMode) bool ScanService::AllowScanDuringStaScene(int staScene, ScanMode scanMode) { - LOGI("Enter ScanService::AllowScanDuringStaScene.\n"); + WIFI_LOGI("Enter ScanService::AllowScanDuringStaScene.\n"); time_t now = time(0); auto forbidIter = scanControlInfo.scanForbidMap.find(staScene); if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { + for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { /* forbid scan mode found in scan scene */ if (iter->scanMode == scanMode) { /* Unconditional scan control for forbidCount times */ @@ -1523,14 +1529,14 @@ bool ScanService::AllowScanDuringStaScene(int staScene, ScanMode scanMode) bool ScanService::AllowScanDuringCustomScene(ScanMode scanMode) { - LOGI("Enter ScanService::AllowScanDuringCustomScene.\n"); + WIFI_LOGI("Enter ScanService::AllowScanDuringCustomScene.\n"); time_t now = time(0); auto customIter = customSceneTimeMap.begin(); - for (; customIter != customSceneTimeMap.end(); customIter++) { + for (; customIter != customSceneTimeMap.end(); ++customIter) { auto forbidIter = scanControlInfo.scanForbidMap.find(customIter->first); if (forbidIter != scanControlInfo.scanForbidMap.end()) { - for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); iter++) { + for (auto iter = forbidIter->second.begin(); iter != forbidIter->second.end(); ++iter) { /* forbid scan mode found in scan scene */ if (iter->scanMode == scanMode) { /* Unconditional scan control for forbidCount times */ @@ -1555,12 +1561,13 @@ bool ScanService::AllowScanDuringCustomScene(ScanMode scanMode) bool ScanService::AllowExternScanByIntervalMode(int appId, int scanScene, ScanMode scanMode) { - LOGI("Enter ScanService::AllowExternScanByIntervalMode.\n"); + WIFI_LOGI("Enter ScanService::AllowExternScanByIntervalMode.\n"); for (auto intervalListIter = scanControlInfo.scanIntervalList.begin(); intervalListIter != scanControlInfo.scanIntervalList.end(); - intervalListIter++) { - LOGD("scanScene:%{public}d, scanMode:%{public}d", intervalListIter->scanScene, intervalListIter->scanMode); + ++intervalListIter) { + WIFI_LOGD( + "scanScene:%{public}d, scanMode:%{public}d", intervalListIter->scanScene, intervalListIter->scanMode); /* Determine whether control is required in the current scene and scan mode. */ if (intervalListIter->scanScene == scanScene && intervalListIter->scanMode == scanMode) { /* If a single application is distinguished */ @@ -1581,13 +1588,13 @@ bool ScanService::AllowExternScanByIntervalMode(int appId, int scanScene, ScanMo bool ScanService::AllowExternScanByCustomScene(int appId, ScanMode scanMode) { - LOGI("Enter ScanService::AllowExternScanByCustomScene.\n"); + WIFI_LOGI("Enter ScanService::AllowExternScanByCustomScene.\n"); auto customIter = customSceneTimeMap.begin(); - for (; customIter != customSceneTimeMap.end(); customIter++) { + for (; customIter != customSceneTimeMap.end(); ++customIter) { for (auto intervalListIter = scanControlInfo.scanIntervalList.begin(); intervalListIter != scanControlInfo.scanIntervalList.end(); - intervalListIter++) { + ++intervalListIter) { /* Determine whether control is required in the current scene and scan mode. */ if (intervalListIter->scanScene == customIter->first && intervalListIter->scanMode == scanMode) { /* If a single application is distinguished */ @@ -1609,10 +1616,10 @@ bool ScanService::AllowExternScanByCustomScene(int appId, ScanMode scanMode) bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) { - LOGI("Enter ScanService::AllowSingleAppScan.\n"); + WIFI_LOGI("Enter ScanService::AllowSingleAppScan.\n"); bool appIdExisted = false; - for (auto forbidListIter = appForbidList.begin(); forbidListIter != appForbidList.end(); forbidListIter++) { + for (auto forbidListIter = appForbidList.begin(); forbidListIter != appForbidList.end(); ++forbidListIter) { if (forbidListIter->appID == appId && forbidListIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && forbidListIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { @@ -1630,7 +1637,7 @@ bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanI singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; appForbidList.push_back(singleAppForbid); } - for (auto iter = appForbidList.begin(); iter != appForbidList.end(); iter++) { + for (auto iter = appForbidList.begin(); iter != appForbidList.end(); ++iter) { if (iter->appID == appId && iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { if (!ExternScanByInterval(appId, *iter)) { @@ -1643,11 +1650,11 @@ bool ScanService::AllowSingleAppScanByInterval(int appId, ScanIntervalMode scanI bool ScanService::AllowFullAppScanByInterval(int appId, ScanIntervalMode scanIntervalMode) { - LOGI("Enter ScanService::AllowFullAppScan.\n"); + WIFI_LOGI("Enter ScanService::AllowFullAppScan.\n"); bool fullAppExisted = false; for (auto fullAppForbidIter = fullAppForbidList.begin(); fullAppForbidIter != fullAppForbidList.end(); - fullAppForbidIter++) { + ++fullAppForbidIter) { if (fullAppForbidIter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && fullAppForbidIter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { fullAppExisted = true; @@ -1662,7 +1669,7 @@ bool ScanService::AllowFullAppScanByInterval(int appId, ScanIntervalMode scanInt singleAppForbid.scanIntervalMode.count = scanIntervalMode.count; fullAppForbidList.push_back(singleAppForbid); } - for (auto iter = fullAppForbidList.begin(); iter != fullAppForbidList.end(); iter++) { + for (auto iter = fullAppForbidList.begin(); iter != fullAppForbidList.end(); ++iter) { if (iter->scanIntervalMode.scanScene == scanIntervalMode.scanScene && iter->scanIntervalMode.scanMode == scanIntervalMode.scanMode) { if (!ExternScanByInterval(appId, *iter)) { @@ -1675,7 +1682,7 @@ bool ScanService::AllowFullAppScanByInterval(int appId, ScanIntervalMode scanInt bool ScanService::PnoScanByInterval(int &fixedScanCount, time_t &fixedScanTime, int &interval, int &count) { - LOGI("Enter ScanService::PnoScanByInterval.\n"); + WIFI_LOGI("Enter ScanService::PnoScanByInterval.\n"); time_t now = time(0); /* First scan */ @@ -1698,7 +1705,7 @@ bool ScanService::PnoScanByInterval(int &fixedScanCount, time_t &fixedScanTime, bool ScanService::SystemScanByInterval(int &expScanCount, int &interval, int &count) { - LOGI("Enter ScanService::SystemScanByInterval.\n"); + WIFI_LOGI("Enter ScanService::SystemScanByInterval.\n"); /* * Exponential interval. The value of interval is the initial value. * After the value is multiplied by 2, the last fixed interval is used. @@ -1713,7 +1720,7 @@ bool ScanService::SystemScanByInterval(int &expScanCount, int &interval, int &co bool ScanService::ExternScanByInterval(int appID, SingleAppForbid &singleAppForbid) { - LOGI("Enter ScanService::ExternScanByInterval.\n"); + WIFI_LOGI("Enter ScanService::ExternScanByInterval.\n"); switch (singleAppForbid.scanIntervalMode.intervalMode) { case IntervalMode::INTERVAL_FIXED: @@ -1747,7 +1754,7 @@ bool ScanService::ExternScanByInterval(int appID, SingleAppForbid &singleAppForb bool ScanService::AllowScanByIntervalFixed(int &fixedScanCount, time_t &fixedScanTime, int &interval, int &count) { - LOGI("Enter ScanService::AllowScanByIntervalFixed.\n"); + WIFI_LOGI("Enter ScanService::AllowScanByIntervalFixed.\n"); time_t now = time(0); /* First scan */ @@ -1775,7 +1782,7 @@ bool ScanService::AllowScanByIntervalFixed(int &fixedScanCount, time_t &fixedSca bool ScanService::AllowScanByIntervalExp(int &expScanCount, int &interval, int &count) { - LOGI("Enter ScanService::AllowScanByIntervalExp.\n"); + WIFI_LOGI("Enter ScanService::AllowScanByIntervalExp.\n"); /* * Exponential interval. The value of interval is the initial value. @@ -1792,9 +1799,9 @@ bool ScanService::AllowScanByIntervalExp(int &expScanCount, int &interval, int & bool ScanService::AllowScanByIntervalContinue( time_t &continueScanTime, int &lessThanIntervalNum, int &interval, int &count) { - LOGI("Enter ScanService::AllowScanByIntervalContinue.\n"); + WIFI_LOGI("Enter ScanService::AllowScanByIntervalContinue.\n"); - LOGD("lessThanIntervalNum:%d, interval:%d, count:%d", lessThanIntervalNum, interval, count); + WIFI_LOGD("lessThanIntervalNum:%d, interval:%d, count:%d", lessThanIntervalNum, interval, count); time_t now = time(0); /* First scan */ if (continueScanTime == 0) { @@ -1821,7 +1828,7 @@ bool ScanService::AllowScanByIntervalContinue( bool ScanService::AllowScanByIntervalBlocklist( int appId, time_t &blockListScanTime, int &lessThanIntervalNum, int &interval, int &count) { - LOGI("Enter ScanService::AllowScanByIntervalBlocklist.\n"); + WIFI_LOGI("Enter ScanService::AllowScanByIntervalBlocklist.\n"); time_t now = time(0); if (now - blockListScanTime >= interval) { @@ -1837,7 +1844,7 @@ bool ScanService::AllowScanByIntervalBlocklist( } /* If the app ID is in the blocklist, extern scan is forbidden. */ if (std::find(scanBlocklist.begin(), scanBlocklist.end(), appId) != scanBlocklist.end()) { - LOGD("extern scan not allowed by blocklist"); + WIFI_LOGD("extern scan not allowed by blocklist"); return false; } /* First scan */ diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h index f4de049d7..87d55cd41 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_service.h @@ -184,12 +184,12 @@ private: PnoScanResultHandlerMap pnoScanResultHandlerMap; /* Map of obtaining PNO scanning results */ ScanConfigMap scanConfigMap; /* Save Scan Configuration */ int scanConfigStoreIndex; /* Index for saving the scan configuration */ - long pnoScanStartTime; /* PNO scanning start time */ + int64_t pnoScanStartTime; /* PNO scanning start time */ bool isScreenOn; /* Screen state */ int staStatus; /* STA state */ bool isPnoScanBegined; /* The PNO scanning has been started */ bool autoNetworkSelection; /* Automatic network selection */ - long lastSystemScanTime; /* Last System Scan Time */ + int64_t lastSystemScanTime; /* Last System Scan Time */ int pnoScanFailedNum; /* Number of PNO Scan Failures */ ScanControlInfo scanControlInfo; /* Scan Control Policy */ int operateAppMode; /* Operation app type */ diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.cpp index 088020c89..959aea48f 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ #include "scan_state_machine.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_SCAN_STATE_MACHINE" +DEFINE_WIFILOG_SCAN_LABEL("ScanStateMachine"); namespace OHOS { namespace Wifi { @@ -43,7 +43,7 @@ ScanStateMachine::ScanStateMachine() ScanStateMachine::~ScanStateMachine() { - LOGI("Enter ScanStateMachine::~ScanStateMachine.\n"); + WIFI_LOGI("Enter ScanStateMachine::~ScanStateMachine.\n"); /* Stop the thread. Otherwise, a problem occurs */ StopHandlerThread(); @@ -96,13 +96,13 @@ ScanStateMachine::~ScanStateMachine() bool ScanStateMachine::InitScanStateMachine() { - LOGI("Enter InitScanStateMachine.\n"); + WIFI_LOGI("Enter InitScanStateMachine.\n"); /* init supportHwPnoFlag value */ supportHwPnoFlag = WifiSettings::GetInstance().GetSupportHwPnoFlag(); if (!InitialStateMachine()) { - LOGE("Initial StateMachine failed.\n"); + WIFI_LOGE("Initial StateMachine failed.\n"); return false; } @@ -115,17 +115,17 @@ bool ScanStateMachine::InitScanStateMachine() }; BuildScanStateTree(); - SetInitialState(initState); - Start(); + SetFirstState(initState); + StartStateMachine(); return true; } bool ScanStateMachine::EnrollScanStatusListener(ScanStatusReportHandler handler) { - LOGI("Enter ScanStateMachine::EnrollScanStatusListener.\n"); + WIFI_LOGI("Enter ScanStateMachine::EnrollScanStatusListener.\n"); if (!handler) { - LOGE("handler is null.\n"); + WIFI_LOGE("handler is null.\n"); return false; } @@ -141,30 +141,30 @@ ScanStateMachine::InitState::InitState(ScanStateMachine *paraScanStateMachine) : ScanStateMachine::InitState::~InitState() {} -void ScanStateMachine::InitState::Enter() +void ScanStateMachine::InitState::GoInState() { - LOGI("Enter ScanStateMachine::InitState::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::InitState::GoInState.\n"); pScanStateMachine->runningScans.clear(); pScanStateMachine->waitingScans.clear(); if (pScanStateMachine->quitFlag) { - LOGI("Notify finish ScanStateMachine.\n"); + WIFI_LOGI("Notify finish ScanStateMachine.\n"); pScanStateMachine->ReportStatusChange(SCAN_FINISHED_STATUS); } return; } -void ScanStateMachine::InitState::Exit() +void ScanStateMachine::InitState::GoOutState() { - LOGI("Enter ScanStateMachine::InitState::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::InitState::GoOutState.\n"); return; } -bool ScanStateMachine::InitState::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::InitState::ExecuteStateMsg(InternalMessage *msg) { - LOGI("Enter ScanStateMachine::InitState::ProcessMessage.\n"); + WIFI_LOGI("Enter ScanStateMachine::InitState::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -178,7 +178,7 @@ bool ScanStateMachine::InitState::ProcessMessage(InternalMessage *msg) return true; case CMD_START_COMMON_SCAN: - pScanStateMachine->ReportCommonScanFailed(msg->GetArg1()); + pScanStateMachine->ReportCommonScanFailed(msg->GetParam1()); return true; case CMD_START_PNO_SCAN: @@ -191,12 +191,12 @@ bool ScanStateMachine::InitState::ProcessMessage(InternalMessage *msg) return true; case HARDWARE_LOAD_EVENT: - pScanStateMachine->TransitionTo(pScanStateMachine->hardwareReadyState); + pScanStateMachine->SwitchState(pScanStateMachine->hardwareReadyState); pScanStateMachine->ReportStatusChange(SCAN_STARTED_STATUS); return true; case HARDWARE_UNLOAD_EVENT: - pScanStateMachine->TransitionTo(pScanStateMachine->initState); + pScanStateMachine->SwitchState(pScanStateMachine->initState); pScanStateMachine->quitFlag = true; return true; @@ -204,7 +204,7 @@ bool ScanStateMachine::InitState::ProcessMessage(InternalMessage *msg) case SCAN_RESULT_EVENT: case PNO_SCAN_RESULT_EVENT: case SCAN_FAILED_EVENT: - LOGE("ignored scan results event.\n"); + WIFI_LOGE("ignored scan results event.\n"); return true; case SYSTEM_SCAN_TIMER: @@ -226,23 +226,23 @@ ScanStateMachine::HardwareReady::HardwareReady(ScanStateMachine *paraScanStateMa ScanStateMachine::HardwareReady::~HardwareReady() {} -void ScanStateMachine::HardwareReady::Enter() +void ScanStateMachine::HardwareReady::GoInState() { - LOGI("Enter ScanStateMachine::HardwareReady::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::HardwareReady::GoInState.\n"); return; } -void ScanStateMachine::HardwareReady::Exit() +void ScanStateMachine::HardwareReady::GoOutState() { - LOGI("Enter ScanStateMachine::HardwareReady::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::HardwareReady::GoOutState.\n"); return; } -bool ScanStateMachine::HardwareReady::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::HardwareReady::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::HardwareReady::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::HardwareReady::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -268,30 +268,30 @@ ScanStateMachine::CommonScan::CommonScan(ScanStateMachine *paraScanStateMachine) ScanStateMachine::CommonScan::~CommonScan() {} -void ScanStateMachine::CommonScan::Enter() +void ScanStateMachine::CommonScan::GoInState() { - LOGI("Enter ScanStateMachine::CommonScan::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScan::GoInState.\n"); return; } -void ScanStateMachine::CommonScan::Exit() +void ScanStateMachine::CommonScan::GoOutState() { - LOGI("Enter ScanStateMachine::CommonScan::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScan::GoOutState.\n"); pScanStateMachine->ReportCommonScanFailedAndClear(false); return; } -bool ScanStateMachine::CommonScan::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::CommonScan::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::CommonScan::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::CommonScan::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } switch (msg->GetMessageName()) { case CMD_STOP_COMMON_SCAN: - pScanStateMachine->RemoveCommonScanRequest(msg->GetArg1()); + pScanStateMachine->RemoveCommonScanRequest(msg->GetParam1()); return true; default: @@ -308,24 +308,24 @@ ScanStateMachine::CommonScanUnworked::CommonScanUnworked(ScanStateMachine *paraS ScanStateMachine::CommonScanUnworked::~CommonScanUnworked() {} -void ScanStateMachine::CommonScanUnworked::Enter() +void ScanStateMachine::CommonScanUnworked::GoInState() { - LOGI("Enter ScanStateMachine::CommonScanUnworked::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanUnworked::GoInState.\n"); pScanStateMachine->StartNewCommonScan(); return; } -void ScanStateMachine::CommonScanUnworked::Exit() +void ScanStateMachine::CommonScanUnworked::GoOutState() { - LOGI("Enter ScanStateMachine::CommonScanUnworked::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanUnworked::GoOutState.\n"); return; } -bool ScanStateMachine::CommonScanUnworked::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::CommonScanUnworked::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::CommonScanUnworked::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::CommonScanUnworked::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -352,15 +352,15 @@ ScanStateMachine::CommonScanning::CommonScanning(ScanStateMachine *paraScanState ScanStateMachine::CommonScanning::~CommonScanning() {} -void ScanStateMachine::CommonScanning::Enter() +void ScanStateMachine::CommonScanning::GoInState() { - LOGI("Enter ScanStateMachine::CommonScanning::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanning::GoInState.\n"); return; } -void ScanStateMachine::CommonScanning::Exit() +void ScanStateMachine::CommonScanning::GoOutState() { - LOGI("Enter ScanStateMachine::CommonScanning::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanning::GoOutState.\n"); pScanStateMachine->ClearRunningScanSettings(); pScanStateMachine->ReportCommonScanFailedAndClear(true); pScanStateMachine->StopTimer(int(WAIT_SCAN_RESULT_TIMER)); @@ -372,11 +372,11 @@ void ScanStateMachine::CommonScanning::Exit() * @param msg - Internal message class, which is used to send messages to the state machine.[in] * @return success: true, failed: false */ -bool ScanStateMachine::CommonScanning::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::CommonScanning::ExecuteStateMsg(InternalMessage *msg) { - LOGI("Enter ScanStateMachine::CommonScanning::ProcessMessage.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanning::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -387,19 +387,19 @@ bool ScanStateMachine::CommonScanning::ProcessMessage(InternalMessage *msg) case SCAN_RESULT_EVENT: pScanStateMachine->CommonScanResultProcess(); - pScanStateMachine->TransitionTo(pScanStateMachine->commonScanUnworkedState); + pScanStateMachine->SwitchState(pScanStateMachine->commonScanUnworkedState); return true; case SCAN_FAILED_EVENT: - LOGE("scan failed."); + WIFI_LOGE("scan failed."); pScanStateMachine->ReportCommonScanFailedAndClear(true); - pScanStateMachine->TransitionTo(pScanStateMachine->commonScanUnworkedState); + pScanStateMachine->SwitchState(pScanStateMachine->commonScanUnworkedState); return true; case WAIT_SCAN_RESULT_TIMER: - LOGE("get scan result time out."); + WIFI_LOGE("get scan result time out."); pScanStateMachine->ReportCommonScanFailedAndClear(true); - pScanStateMachine->TransitionTo(pScanStateMachine->commonScanUnworkedState); + pScanStateMachine->SwitchState(pScanStateMachine->commonScanUnworkedState); return true; /* @@ -408,7 +408,7 @@ bool ScanStateMachine::CommonScanning::ProcessMessage(InternalMessage *msg) */ case CMD_START_PNO_SCAN: case CMD_RESTART_PNO_SCAN: - pScanStateMachine->DeferMessage(msg); + pScanStateMachine->DelayMessage(msg); return true; default: @@ -424,24 +424,24 @@ ScanStateMachine::PnoScan::PnoScan(ScanStateMachine *paraScanStateMachine) : Sta ScanStateMachine::PnoScan::~PnoScan() {} -void ScanStateMachine::PnoScan::Enter() +void ScanStateMachine::PnoScan::GoInState() { - LOGI("Enter ScanStateMachine::PnoScan::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScan::GoInState.\n"); return; } -void ScanStateMachine::PnoScan::Exit() +void ScanStateMachine::PnoScan::GoOutState() { - LOGI("Enter ScanStateMachine::PnoScan::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScan::GoOutState.\n"); pScanStateMachine->StopPnoScanHardware(); return; } -bool ScanStateMachine::PnoScan::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::PnoScan::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::PnoScan::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::PnoScan::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); } return false; } @@ -455,27 +455,27 @@ ScanStateMachine::PnoScanHardware::PnoScanHardware(ScanStateMachine *paraScanSta ScanStateMachine::PnoScanHardware::~PnoScanHardware() {} -void ScanStateMachine::PnoScanHardware::Enter() +void ScanStateMachine::PnoScanHardware::GoInState() { - LOGI("Enter ScanStateMachine::PnoScanHardware::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanHardware::GoInState.\n"); if (!pScanStateMachine->StartPnoScanHardware()) { - LOGE("StartPnoScanHardware failed."); + WIFI_LOGE("StartPnoScanHardware failed."); return; } return; } -void ScanStateMachine::PnoScanHardware::Exit() +void ScanStateMachine::PnoScanHardware::GoOutState() { - LOGI("Enter ScanStateMachine::PnoScanHardware::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanHardware::GoOutState.\n"); return; } -bool ScanStateMachine::PnoScanHardware::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::PnoScanHardware::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::PnoScanHardware::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::PnoScanHardware::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -499,8 +499,8 @@ bool ScanStateMachine::PnoScanHardware::ProcessMessage(InternalMessage *msg) return true; case CMD_START_COMMON_SCAN: - pScanStateMachine->DeferMessage(msg); - pScanStateMachine->TransitionTo(pScanStateMachine->hardwareReadyState); + pScanStateMachine->DelayMessage(msg); + pScanStateMachine->SwitchState(pScanStateMachine->hardwareReadyState); return true; default: @@ -518,16 +518,16 @@ ScanStateMachine::CommonScanAfterPno::CommonScanAfterPno(ScanStateMachine *paraS ScanStateMachine::CommonScanAfterPno::~CommonScanAfterPno() {} -void ScanStateMachine::CommonScanAfterPno::Enter() +void ScanStateMachine::CommonScanAfterPno::GoInState() { - LOGI("Enter ScanStateMachine::CommonScanAfterPno::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanAfterPno::GoInState.\n"); pScanStateMachine->CommonScanAfterPnoProcess(); return; } -void ScanStateMachine::CommonScanAfterPno::Exit() +void ScanStateMachine::CommonScanAfterPno::GoOutState() { - LOGI("Enter ScanStateMachine::CommonScanAfterPno::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanAfterPno::GoOutState.\n"); if (!pScanStateMachine->remainWaitResultTimer) { pScanStateMachine->StopTimer(static_cast(WAIT_SCAN_RESULT_TIMER)); } @@ -536,28 +536,28 @@ void ScanStateMachine::CommonScanAfterPno::Exit() return; } -bool ScanStateMachine::CommonScanAfterPno::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::CommonScanAfterPno::ExecuteStateMsg(InternalMessage *msg) { - LOGI("ScanStateMachine::CommonScanAfterPno::ProcessMessage.\n"); + WIFI_LOGI("ScanStateMachine::CommonScanAfterPno::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } switch (msg->GetMessageName()) { case SCAN_RESULT_EVENT: pScanStateMachine->CommonScanAfterPnoResult(); - pScanStateMachine->TransitionTo(pScanStateMachine->pnoScanHardwareState); + pScanStateMachine->SwitchState(pScanStateMachine->pnoScanHardwareState); return true; case SCAN_FAILED_EVENT: case WAIT_SCAN_RESULT_TIMER: - pScanStateMachine->TransitionTo(pScanStateMachine->pnoScanHardwareState); + pScanStateMachine->SwitchState(pScanStateMachine->pnoScanHardwareState); return true; case CMD_START_PNO_SCAN: case PNO_SCAN_RESULT_EVENT: - LOGE("Ignore the message.\n"); + WIFI_LOGE("Ignore the message.\n"); return true; /* @@ -566,8 +566,8 @@ bool ScanStateMachine::CommonScanAfterPno::ProcessMessage(InternalMessage *msg) * the status is changed */ case CMD_START_COMMON_SCAN: - pScanStateMachine->DeferMessage(msg); - pScanStateMachine->TransitionTo(pScanStateMachine->commonScanningState); + pScanStateMachine->DelayMessage(msg); + pScanStateMachine->SwitchState(pScanStateMachine->commonScanningState); pScanStateMachine->remainWaitResultTimer = true; return true; @@ -588,30 +588,30 @@ ScanStateMachine::PnoScanSoftware::PnoScanSoftware(ScanStateMachine *paraScanSta ScanStateMachine::PnoScanSoftware::~PnoScanSoftware() {} -void ScanStateMachine::PnoScanSoftware::Enter() +void ScanStateMachine::PnoScanSoftware::GoInState() { - LOGI("Enter ScanStateMachine::PnoScanSoftware::Enter.\n"); - LOGI("Start scan first!"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanSoftware::GoInState.\n"); + WIFI_LOGI("Start scan first!"); if (!pScanStateMachine->StartNewSoftwareScan()) { - LOGE("failed to start new softwareScan"); + WIFI_LOGE("failed to start new softwareScan"); } return; } -void ScanStateMachine::PnoScanSoftware::Exit() +void ScanStateMachine::PnoScanSoftware::GoOutState() { - LOGI("Enter ScanStateMachine::PnoScanSoftware::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanSoftware::GoOutState.\n"); pScanStateMachine->StopTimer(static_cast(SOFTWARE_PNO_SCAN_TIMER)); return; } -bool ScanStateMachine::PnoScanSoftware::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::PnoScanSoftware::ExecuteStateMsg(InternalMessage *msg) { - LOGI("Enter ScanStateMachine::PnoScanSoftware::ProcessMessage.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanSoftware::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -633,24 +633,24 @@ ScanStateMachine::PnoSwScanFree::PnoSwScanFree(ScanStateMachine *paraScanStateMa ScanStateMachine::PnoSwScanFree::~PnoSwScanFree() {} -void ScanStateMachine::PnoSwScanFree::Enter() +void ScanStateMachine::PnoSwScanFree::GoInState() { - LOGI("Enter ScanStateMachine::PnoSwScanFree::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanFree::GoInState.\n"); return; } -void ScanStateMachine::PnoSwScanFree::Exit() +void ScanStateMachine::PnoSwScanFree::GoOutState() { - LOGI("Enter ScanStateMachine::PnoSwScanFree::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanFree::GoOutState.\n"); return; } -bool ScanStateMachine::PnoSwScanFree::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::PnoSwScanFree::ExecuteStateMsg(InternalMessage *msg) { - LOGI("Enter ScanStateMachine::PnoSwScanFree::ProcessMessage.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanFree::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } @@ -663,14 +663,15 @@ bool ScanStateMachine::PnoSwScanFree::ProcessMessage(InternalMessage *msg) pScanStateMachine->PnoScanSoftwareProcess(msg); return true; case CMD_START_COMMON_SCAN: - pScanStateMachine->DeferMessage(msg); - pScanStateMachine->TransitionTo(pScanStateMachine->hardwareReadyState); + pScanStateMachine->DelayMessage(msg); + pScanStateMachine->SwitchState(pScanStateMachine->hardwareReadyState); return true; case SOFTWARE_PNO_SCAN_TIMER: - LOGI("softwarePno scanscanInterval is %{public}d.\n", pScanStateMachine->runningPnoScanConfig.scanInterval); + WIFI_LOGI( + "softwarePno scanscanInterval is %{public}d.\n", pScanStateMachine->runningPnoScanConfig.scanInterval); if (!pScanStateMachine->RepeatStartCommonScan()) { - LOGE("Failed to start scan"); + WIFI_LOGE("Failed to start scan"); } pScanStateMachine->StartTimer(static_cast(SOFTWARE_PNO_SCAN_TIMER), (pScanStateMachine->runningPnoScanConfig.scanInterval) * SECOND_TO_MILLI_SECOND); @@ -689,55 +690,55 @@ ScanStateMachine::PnoSwScanning::PnoSwScanning(ScanStateMachine *paraScanStateMa ScanStateMachine::PnoSwScanning::~PnoSwScanning() {} -void ScanStateMachine::PnoSwScanning::Enter() +void ScanStateMachine::PnoSwScanning::GoInState() { - LOGI("Enter ScanStateMachine::PnoSwScanning::Enter.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanning::GoInState.\n"); return; } -void ScanStateMachine::PnoSwScanning::Exit() +void ScanStateMachine::PnoSwScanning::GoOutState() { - LOGI("Enter ScanStateMachine::PnoSwScanning::Exit.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanning::GoOutState.\n"); pScanStateMachine->StopTimer(static_cast(WAIT_SCAN_RESULT_TIMER)); return; } -bool ScanStateMachine::PnoSwScanning::ProcessMessage(InternalMessage *msg) +bool ScanStateMachine::PnoSwScanning::ExecuteStateMsg(InternalMessage *msg) { - LOGI("Enter ScanStateMachine::PnoSwScanning::ProcessMessage.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoSwScanning::ExecuteStateMsg.\n"); if (msg == nullptr) { - LOGE("msg is null.\n"); + WIFI_LOGE("msg is null.\n"); return true; } switch (msg->GetMessageName()) { case SCAN_RESULT_EVENT: pScanStateMachine->SoftwareScanResultProcess(); - pScanStateMachine->TransitionTo(pScanStateMachine->pnoSwScanFreeState); + pScanStateMachine->SwitchState(pScanStateMachine->pnoSwScanFreeState); return true; case SCAN_FAILED_EVENT: - LOGE("scan failed"); - pScanStateMachine->TransitionTo(pScanStateMachine->pnoSwScanFreeState); + WIFI_LOGE("scan failed"); + pScanStateMachine->SwitchState(pScanStateMachine->pnoSwScanFreeState); return true; case WAIT_SCAN_RESULT_TIMER: - LOGE("get scan result timed out"); - pScanStateMachine->TransitionTo(pScanStateMachine->pnoSwScanFreeState); + WIFI_LOGE("get scan result timed out"); + pScanStateMachine->SwitchState(pScanStateMachine->pnoSwScanFreeState); return true; case CMD_START_PNO_SCAN: - LOGE("The SwPnoScan is in progress and cannot be performed repeatedly."); + WIFI_LOGE("The SwPnoScan is in progress and cannot be performed repeatedly."); pScanStateMachine->PnoScanFailedProcess(); return true; case CMD_RESTART_PNO_SCAN: case CMD_START_COMMON_SCAN: - pScanStateMachine->DeferMessage(msg); + pScanStateMachine->DelayMessage(msg); return true; case SOFTWARE_PNO_SCAN_TIMER: - LOGI("Scanning is in progress. Please wait for the scan result."); - pScanStateMachine->DeferMessage(msg); + WIFI_LOGI("Scanning is in progress. Please wait for the scan result."); + pScanStateMachine->DelayMessage(msg); return true; default: @@ -747,7 +748,7 @@ bool ScanStateMachine::PnoSwScanning::ProcessMessage(InternalMessage *msg) void ScanStateMachine::CommonScanRequestProcess(InternalMessage *interMessage) { - LOGI("ScanStateMachine::CommonScanRequestProcess.\n"); + WIFI_LOGI("ScanStateMachine::CommonScanRequestProcess.\n"); int requestIndex = 0; InterScanConfig scanConfig; @@ -756,7 +757,7 @@ void ScanStateMachine::CommonScanRequestProcess(InternalMessage *interMessage) return; } if (!VerifyScanStyle(scanConfig.scanStyle)) { - LOGE("invalid scan type"); + WIFI_LOGE("invalid scan type"); return; } waitingScans.insert(std::pair(requestIndex, scanConfig)); @@ -768,16 +769,16 @@ void ScanStateMachine::CommonScanRequestProcess(InternalMessage *interMessage) bool ScanStateMachine::GetCommonScanRequestInfo( InternalMessage *interMessage, int &requestIndex, InterScanConfig &scanConfig) { - LOGI("Enter ScanStateMachine::GetRequestMsgInfo.\n"); + WIFI_LOGI("Enter ScanStateMachine::GetRequestMsgInfo.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null."); + WIFI_LOGE("interMessage is null."); return false; } - requestIndex = interMessage->GetArg1(); + requestIndex = interMessage->GetParam1(); if (!GetCommonScanConfig(interMessage, scanConfig)) { - LOGE("GetCommonScanConfig failed."); + WIFI_LOGE("GetCommonScanConfig failed."); return false; } @@ -786,10 +787,10 @@ bool ScanStateMachine::GetCommonScanRequestInfo( bool ScanStateMachine::GetCommonScanConfig(InternalMessage *interMessage, InterScanConfig &scanConfig) { - LOGI("Enter ScanStateMachine::GetCommonScanConfig.\n"); + WIFI_LOGI("Enter ScanStateMachine::GetCommonScanConfig.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null."); + WIFI_LOGE("interMessage is null."); return false; } @@ -798,7 +799,7 @@ bool ScanStateMachine::GetCommonScanConfig(InternalMessage *interMessage, InterS for (int i = 0; i < hiddenSize; i++) { std::string hiddenSsid = interMessage->GetStringFromMessage(); if (hiddenSsid.empty()) { - LOGE("Message body is error."); + WIFI_LOGE("Message body is error."); return false; } scanConfig.hiddenNetworkSsid.push_back(hiddenSsid); @@ -809,7 +810,7 @@ bool ScanStateMachine::GetCommonScanConfig(InternalMessage *interMessage, InterS for (int i = 0; i < freqSize; i++) { int freq = interMessage->GetIntFromMessage(); if (freq == 0) { - LOGE("Message body is error."); + WIFI_LOGE("Message body is error."); return false; } scanConfig.scanFreqs.push_back(freq); @@ -827,7 +828,7 @@ bool ScanStateMachine::GetCommonScanConfig(InternalMessage *interMessage, InterS void ScanStateMachine::StartNewCommonScan() { - LOGI("Enter ScanStateMachine::StartNewCommonScan.\n"); + WIFI_LOGI("Enter ScanStateMachine::StartNewCommonScan.\n"); if (waitingScans.size() == 0) { ContinuePnoScanProcess(); @@ -838,12 +839,12 @@ void ScanStateMachine::StartNewCommonScan() bool hasFullScan = false; /* Traverse the request list and combine parameters */ std::map::iterator configIter = waitingScans.begin(); - for (; configIter != waitingScans.end(); configIter++) { + for (; configIter != waitingScans.end(); ++configIter) { runningScanSettings.scanStyle = MergeScanStyle(runningScanSettings.scanStyle, configIter->second.scanStyle); std::vector::iterator hiddenIter = configIter->second.hiddenNetworkSsid.begin(); /* Remove duplicate hidden list */ - for (; hiddenIter != configIter->second.hiddenNetworkSsid.end(); hiddenIter++) { + for (; hiddenIter != configIter->second.hiddenNetworkSsid.end(); ++hiddenIter) { if (std::find(runningScanSettings.hiddenNetworkSsid.begin(), runningScanSettings.hiddenNetworkSsid.end(), *hiddenIter) != runningScanSettings.hiddenNetworkSsid.end()) { @@ -861,7 +862,7 @@ void ScanStateMachine::StartNewCommonScan() } else { std::vector::iterator freqIter = configIter->second.scanFreqs.begin(); /* Repetitions are eliminated */ - for (; freqIter != configIter->second.scanFreqs.end(); freqIter++) { + for (; freqIter != configIter->second.scanFreqs.end(); ++freqIter) { if (std::find(runningScanSettings.scanFreqs.begin(), runningScanSettings.scanFreqs.end(), *freqIter) != runningScanSettings.scanFreqs.end()) { @@ -881,8 +882,8 @@ void ScanStateMachine::StartNewCommonScan() runningScans.swap(waitingScans); waitingScans.clear(); - TransitionTo(commonScanningState); - LOGI("StartNewCommonScan success.\n"); + SwitchState(commonScanningState); + WIFI_LOGI("StartNewCommonScan success.\n"); return; } @@ -897,24 +898,24 @@ void ScanStateMachine::ClearRunningScanSettings() bool ScanStateMachine::StartSingleCommonScan(WifiScanParam &scanParam) { - LOGI("Enter ScanStateMachine::StartSingleCommonScan.\n"); + WIFI_LOGI("Enter ScanStateMachine::StartSingleCommonScan.\n"); - for (auto freqIter = scanParam.scanFreqs.begin(); freqIter != scanParam.scanFreqs.end(); freqIter++) { - LOGI("freq is %{public}d.\n", *freqIter); + for (auto freqIter = scanParam.scanFreqs.begin(); freqIter != scanParam.scanFreqs.end(); ++freqIter) { + WIFI_LOGI("freq is %{public}d.\n", *freqIter); } for (auto hiddenIter = scanParam.hiddenNetworkSsid.begin(); hiddenIter != scanParam.hiddenNetworkSsid.end(); - hiddenIter++) { - LOGI("hidden ssid is %{public}s.\n", hiddenIter->c_str()); + ++hiddenIter) { + WIFI_LOGI("hidden ssid is %{public}s.\n", hiddenIter->c_str()); } - LOGI("Begin call Scan.\n"); + WIFI_LOGI("Begin call Scan.\n"); WifiErrorNo ret = WifiStaHalInterface::GetInstance().Scan(scanParam); if ((ret != WIFI_IDL_OPT_OK) && (ret != WIFI_IDL_OPT_SCAN_BUSY)) { - LOGE("WifiStaHalInterface::GetInstance().scan failed."); + WIFI_LOGE("WifiStaHalInterface::GetInstance().scan failed."); return false; } - LOGI("End call Scan.\n"); + WIFI_LOGI("End call Scan.\n"); /* * Start the timer. If no result is returned for a long time, the scanning @@ -927,7 +928,7 @@ bool ScanStateMachine::StartSingleCommonScan(WifiScanParam &scanParam) void ScanStateMachine::CommonScanWhenRunning(InternalMessage *interMessage) { - LOGI("Enter ScanStateMachine::CommonScanWhenRunning.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanWhenRunning.\n"); int requestIndex = MAX_SCAN_CONFIG_STORE_INDEX; InterScanConfig scanConfig; @@ -947,7 +948,7 @@ void ScanStateMachine::CommonScanWhenRunning(InternalMessage *interMessage) bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig) { - LOGI("Enter ScanStateMachine::ActiveCoverNewScan.\n"); + WIFI_LOGI("Enter ScanStateMachine::ActiveCoverNewScan.\n"); if (!ActiveScanStyle(interScanConfig.scanStyle)) { return false; @@ -964,7 +965,7 @@ bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig) } for (auto freqIter = interScanConfig.scanFreqs.begin(); freqIter != interScanConfig.scanFreqs.end(); - freqIter++) { + ++freqIter) { if (std::find(runningScanSettings.scanFreqs.begin(), runningScanSettings.scanFreqs.end(), *freqIter) == runningScanSettings.scanFreqs.end()) { return false; @@ -982,7 +983,7 @@ bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig) for (auto hiddenIter = interScanConfig.hiddenNetworkSsid.begin(); hiddenIter != interScanConfig.hiddenNetworkSsid.end(); - hiddenIter++) { + ++hiddenIter) { if (std::find(runningScanSettings.hiddenNetworkSsid.begin(), runningScanSettings.hiddenNetworkSsid.end(), *hiddenIter) == runningScanSettings.hiddenNetworkSsid.end()) { @@ -995,11 +996,11 @@ bool ScanStateMachine::ActiveCoverNewScan(InterScanConfig &interScanConfig) void ScanStateMachine::CommonScanResultProcess() { - LOGI("Enter ScanStateMachine::CommonScanResultProcess.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanResultProcess.\n"); ScanStatusReport scanStatusReport; if (!GetScanResults(scanStatusReport.scanResultList)) { - LOGE("GetScanResults failed."); + WIFI_LOGE("GetScanResults failed."); ReportCommonScanFailedAndClear(true); return; } @@ -1017,16 +1018,16 @@ void ScanStateMachine::CommonScanResultProcess() void ScanStateMachine::ConvertScanResults( std::vector &wifiScanResults, std::vector &scanResults) { - LOGI("Enter ScanStateMachine::ConvertScanResults.\n"); + WIFI_LOGI("Enter ScanStateMachine::ConvertScanResults.\n"); std::vector::iterator iter = wifiScanResults.begin(); - for (; iter != wifiScanResults.end(); iter++) { + for (; iter != wifiScanResults.end(); ++iter) { InterScanResult singleResult; singleResult.bssid = iter->bssid; singleResult.ssid = iter->ssid; singleResult.capabilities = iter->capability; singleResult.frequency = iter->frequency; - singleResult.level = iter->signalLevel; + singleResult.rssi = iter->signalLevel; singleResult.timestamp = iter->timestamp; scanResults.push_back(singleResult); @@ -1035,20 +1036,9 @@ void ScanStateMachine::ConvertScanResults( return; } -void ScanStateMachine::OnQuitting() -{ - LOGI("Enter ScanStateMachine::OnQuitting.\n"); - return; -} -void ScanStateMachine::OnHalting() -{ - LOGI("ScanStateMachine::OnQuitting.\n"); - return; -} - void ScanStateMachine::ReportStatusChange(ScanStatus status) { - LOGI("Enter ScanStateMachine::ReportStatusChange.\n"); + WIFI_LOGI("Enter ScanStateMachine::ReportStatusChange.\n"); ScanStatusReport scanStatusReport; scanStatusReport.status = status; @@ -1061,7 +1051,7 @@ void ScanStateMachine::ReportStatusChange(ScanStatus status) void ScanStateMachine::ReportScanInnerEvent(ScanInnerEventType innerEvent) { - LOGI("Enter ScanStateMachine::ReportScanInnerEvent, event is %{public}d.\n", innerEvent); + WIFI_LOGI("Enter ScanStateMachine::ReportScanInnerEvent, event is %{public}d.\n", innerEvent); ScanStatusReport scanStatusReport; scanStatusReport.status = SCAN_INNER_EVENT; @@ -1075,7 +1065,7 @@ void ScanStateMachine::ReportScanInnerEvent(ScanInnerEventType innerEvent) void ScanStateMachine::ReportCommonScanFailed(int requestIndex) { - LOGI("Enter ScanStateMachine::ReportCommonScanFailed.\n"); + WIFI_LOGI("Enter ScanStateMachine::ReportCommonScanFailed.\n"); if (requestIndex == MAX_SCAN_CONFIG_STORE_INDEX) { return; @@ -1093,7 +1083,7 @@ void ScanStateMachine::ReportCommonScanFailed(int requestIndex) void ScanStateMachine::ReportCommonScanFailedAndClear(bool runningFlag) { - LOGI("Enter ScanStateMachine::ReportCommonScanFailedAndClear.\n"); + WIFI_LOGI("Enter ScanStateMachine::ReportCommonScanFailedAndClear.\n"); ScanStatusReport scanStatusReport; if (runningFlag) { @@ -1119,7 +1109,7 @@ void ScanStateMachine::ReportCommonScanFailedAndClear(bool runningFlag) void ScanStateMachine::GetRunningIndexList(std::vector &runningIndexList) { std::map::iterator iter = runningScans.begin(); - for (; iter != runningScans.end(); iter++) { + for (; iter != runningScans.end(); ++iter) { runningIndexList.push_back(iter->first); } @@ -1129,7 +1119,7 @@ void ScanStateMachine::GetRunningIndexList(std::vector &runningIndexList) void ScanStateMachine::GetWaitingIndexList(std::vector &waitingIndexList) { std::map::iterator iter = waitingScans.begin(); - for (; iter != waitingScans.end(); iter++) { + for (; iter != waitingScans.end(); ++iter) { waitingIndexList.push_back(iter->first); } @@ -1151,7 +1141,7 @@ bool ScanStateMachine::ActiveScanStyle(int scanStyle) case SCAN_TYPE_HIGH_ACCURACY: return true; default: - LOGE("invalid scan style."); + WIFI_LOGE("invalid scan style."); return false; } } @@ -1165,14 +1155,14 @@ int ScanStateMachine::MergeScanStyle(int currentScanStyle, int newScanStyle) case SCAN_TYPE_HIGH_ACCURACY: return currentScanStyle; default: - LOGE("invalid scan style."); + WIFI_LOGE("invalid scan style."); return newScanStyle; } } void ScanStateMachine::RemoveCommonScanRequest(int requestIndex) { - LOGI("Enter ScanStateMachine::RemoveCommonScanRequest.\n"); + WIFI_LOGI("Enter ScanStateMachine::RemoveCommonScanRequest.\n"); if (runningScans.count(requestIndex) == 1) { runningScans.erase(requestIndex); @@ -1187,17 +1177,17 @@ void ScanStateMachine::RemoveCommonScanRequest(int requestIndex) void ScanStateMachine::PnoScanRequestProcess(InternalMessage *interMessage) { - LOGI("ScanStateMachine::PnoScanRequestProcess.\n"); + WIFI_LOGI("ScanStateMachine::PnoScanRequestProcess.\n"); if (!GetPnoScanRequestInfo(interMessage)) { - LOGE("GetPnoScanRequestInfo failed.\n"); + WIFI_LOGE("GetPnoScanRequestInfo failed.\n"); return; } if (supportHwPnoFlag) { - TransitionTo(pnoScanHardwareState); + SwitchState(pnoScanHardwareState); } else { - TransitionTo(pnoScanSoftwareState); + SwitchState(pnoScanSoftwareState); } return; @@ -1205,16 +1195,16 @@ void ScanStateMachine::PnoScanRequestProcess(InternalMessage *interMessage) void ScanStateMachine::ContinuePnoScanProcess() { - LOGI("ScanStateMachine::ContinuePnoScanProcess.\n"); + WIFI_LOGI("ScanStateMachine::ContinuePnoScanProcess.\n"); if (!pnoConfigStoredFlag) { return; } if (supportHwPnoFlag) { - TransitionTo(pnoScanHardwareState); + SwitchState(pnoScanHardwareState); } else { - TransitionTo(pnoScanSoftwareState); + SwitchState(pnoScanSoftwareState); } return; @@ -1222,19 +1212,19 @@ void ScanStateMachine::ContinuePnoScanProcess() void ScanStateMachine::PnoScanHardwareProcess(InternalMessage *interMessage) { - LOGI("ScanStateMachine::PnoScanHardwareProcess.\n"); + WIFI_LOGI("ScanStateMachine::PnoScanHardwareProcess.\n"); if (runningHwPnoFlag) { - LOGE("Hardware Pno scan is running."); + WIFI_LOGE("Hardware Pno scan is running."); return; } if (!GetPnoScanRequestInfo(interMessage)) { - LOGE("GetPnoScanRequestInfo failed."); + WIFI_LOGE("GetPnoScanRequestInfo failed."); return; } if (!StartPnoScanHardware()) { - LOGE("StartPnoScanHardware failed."); + WIFI_LOGE("StartPnoScanHardware failed."); return; } @@ -1243,14 +1233,14 @@ void ScanStateMachine::PnoScanHardwareProcess(InternalMessage *interMessage) bool ScanStateMachine::StartPnoScanHardware() { - LOGI("ScanStateMachine::StartPnoScanHardware.\n"); + WIFI_LOGI("ScanStateMachine::StartPnoScanHardware.\n"); if (runningHwPnoFlag) { - LOGE("Hardware Pno scan is running."); + WIFI_LOGE("Hardware Pno scan is running."); return true; } if (!pnoConfigStoredFlag) { - LOGE("Pno config has not stored."); + WIFI_LOGE("Pno config has not stored."); return true; } @@ -1264,10 +1254,10 @@ bool ScanStateMachine::StartPnoScanHardware() pnoScanParam.savedSsid.assign( runningPnoScanConfig.savedNetworkSsid.begin(), runningPnoScanConfig.savedNetworkSsid.end()); pnoScanParam.scanFreqs.assign(runningPnoScanConfig.freqs.begin(), runningPnoScanConfig.freqs.end()); - LOGI("pnoScanParam.scanInterval is %{public}d.\n", pnoScanParam.scanInterval); + WIFI_LOGI("pnoScanParam.scanInterval is %{public}d.\n", pnoScanParam.scanInterval); WifiErrorNo ret = WifiStaHalInterface::GetInstance().StartPnoScan(pnoScanParam); if ((ret != WIFI_IDL_OPT_OK) && (ret != WIFI_IDL_OPT_SCAN_BUSY)) { - LOGE("WifiStaHalInterface::GetInstance().StartPnoScan failed."); + WIFI_LOGE("WifiStaHalInterface::GetInstance().StartPnoScan failed."); PnoScanFailedProcess(); return false; } @@ -1278,18 +1268,18 @@ bool ScanStateMachine::StartPnoScanHardware() void ScanStateMachine::StopPnoScanHardware() { - LOGI("ScanStateMachine::StopPnoScanHardware.\n"); + WIFI_LOGI("ScanStateMachine::StopPnoScanHardware.\n"); if (!supportHwPnoFlag) { return; } if (!runningHwPnoFlag) { - LOGE("Hardware Pno scan is not running."); + WIFI_LOGE("Hardware Pno scan is not running."); } /* Invoke the IDL interface to stop PNO scanning */ if (WifiStaHalInterface::GetInstance().StopPnoScan() != WIFI_IDL_OPT_OK) { - LOGE("WifiStaHalInterface::GetInstance().StopPnoScan failed."); + WIFI_LOGE("WifiStaHalInterface::GetInstance().StopPnoScan failed."); } runningHwPnoFlag = false; @@ -1298,10 +1288,10 @@ void ScanStateMachine::StopPnoScanHardware() void ScanStateMachine::UpdatePnoScanRequest(InternalMessage *interMessage) { - LOGI("Enter ScanStateMachine::UpdatePnoScanRequest.\n"); + WIFI_LOGI("Enter ScanStateMachine::UpdatePnoScanRequest.\n"); if (!GetPnoScanRequestInfo(interMessage)) { - LOGE("GetPnoScanRequestInfo failed."); + WIFI_LOGE("GetPnoScanRequestInfo failed."); return; } @@ -1310,23 +1300,23 @@ void ScanStateMachine::UpdatePnoScanRequest(InternalMessage *interMessage) bool ScanStateMachine::GetPnoScanRequestInfo(InternalMessage *interMessage) { - LOGI("Enter ScanStateMachine::GetPnoScanRequestInfo.\n"); + WIFI_LOGI("Enter ScanStateMachine::GetPnoScanRequestInfo.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null."); + WIFI_LOGE("interMessage is null."); PnoScanFailedProcess(); return false; } ClearPnoScanConfig(); if (!GetPnoScanConfig(interMessage, runningPnoScanConfig)) { - LOGE("GetPnoScanConfig failed."); + WIFI_LOGE("GetPnoScanConfig failed."); PnoScanFailedProcess(); return false; } if (!GetCommonScanConfig(interMessage, runningScanConfigForPno)) { - LOGE("GetCommonScanConfig failed."); + WIFI_LOGE("GetCommonScanConfig failed."); PnoScanFailedProcess(); return false; } @@ -1343,10 +1333,10 @@ bool ScanStateMachine::GetPnoScanRequestInfo(InternalMessage *interMessage) bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanConfig &pnoScanConfig) { - LOGI("Enter ScanStateMachine::GetPnoScanConfig.\n"); + WIFI_LOGI("Enter ScanStateMachine::GetPnoScanConfig.\n"); if (interMessage == nullptr) { - LOGE("interMessage is null."); + WIFI_LOGE("interMessage is null."); return false; } @@ -1359,7 +1349,7 @@ bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanCo for (int i = 0; i < hiddenSize; i++) { std::string hiddenSsid = interMessage->GetStringFromMessage(); if (hiddenSsid.empty()) { - LOGE("Message body is error."); + WIFI_LOGE("Message body is error."); return false; } pnoScanConfig.hiddenNetworkSsid.push_back(hiddenSsid); @@ -1370,7 +1360,7 @@ bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanCo for (int i = 0; i < iSavedSize; i++) { std::string savedSizeStr = interMessage->GetStringFromMessage(); if (savedSizeStr.empty()) { - LOGE("Message body is error."); + WIFI_LOGE("Message body is error."); return false; } pnoScanConfig.savedNetworkSsid.push_back(savedSizeStr); @@ -1380,7 +1370,7 @@ bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanCo for (int i = 0; i < freqsSize; i++) { int freqs = interMessage->GetIntFromMessage(); if (freqs == 0) { - LOGE("Message body is error."); + WIFI_LOGE("Message body is error."); return false; } pnoScanConfig.freqs.push_back(freqs); @@ -1391,21 +1381,21 @@ bool ScanStateMachine::GetPnoScanConfig(InternalMessage *interMessage, PnoScanCo void ScanStateMachine::HwPnoScanResultProcess() { - LOGI("Enter ScanStateMachine::HwPnoScanResultProcess.\n"); + WIFI_LOGI("Enter ScanStateMachine::HwPnoScanResultProcess.\n"); if (!runningHwPnoFlag) { - LOGE("Hardware pno scan is not running."); + WIFI_LOGE("Hardware pno scan is not running."); return; } std::vector scanResults; if (!GetScanResults(scanResults)) { - LOGE("GetScanResults failed."); + WIFI_LOGE("GetScanResults failed."); return; } if (NeedCommonScanAfterPno(scanResults)) { - TransitionTo(commonScanAfterPnoState); + SwitchState(commonScanAfterPnoState); return; } @@ -1415,7 +1405,7 @@ void ScanStateMachine::HwPnoScanResultProcess() void ScanStateMachine::ReportPnoScanResults(std::vector &scanResults) { - LOGI("Enter ScanStateMachine::ReportPnoScanResults.\n"); + WIFI_LOGI("Enter ScanStateMachine::ReportPnoScanResults.\n"); ScanStatusReport scanStatusReport; scanStatusReport.status = PNO_SCAN_RESULT; @@ -1428,16 +1418,16 @@ void ScanStateMachine::ReportPnoScanResults(std::vector &scanRe bool ScanStateMachine::NeedCommonScanAfterPno(std::vector &scanResults) { - LOGI("Enter ScanStateMachine::NeedCommonScanAfterPno.\n"); + WIFI_LOGI("Enter ScanStateMachine::NeedCommonScanAfterPno.\n"); if (scanResults.size() > 0) { - LOGI("Enter UpdateNetworkScoreCache.[%{public}s]\n", scanResults[0].bssid.c_str()); + WIFI_LOGI("Enter UpdateNetworkScoreCache.[%{public}s]\n", scanResults[0].bssid.c_str()); } return false; } void ScanStateMachine::CommonScanAfterPnoProcess() { - LOGI("Enter ScanStateMachine::CommonScanAfterPnoProcess.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanAfterPnoProcess.\n"); StopPnoScanHardware(); WifiScanParam scanParam; @@ -1445,8 +1435,8 @@ void ScanStateMachine::CommonScanAfterPnoProcess() runningScanConfigForPno.hiddenNetworkSsid.begin(), runningScanConfigForPno.hiddenNetworkSsid.end()); scanParam.scanFreqs.assign(runningScanConfigForPno.scanFreqs.begin(), runningScanConfigForPno.scanFreqs.end()); if (!StartSingleCommonScan(scanParam)) { - LOGE("StartSingleCommonScan failed.\n"); - TransitionTo(pnoScanHardwareState); + WIFI_LOGE("StartSingleCommonScan failed.\n"); + SwitchState(pnoScanHardwareState); return; } @@ -1455,11 +1445,11 @@ void ScanStateMachine::CommonScanAfterPnoProcess() void ScanStateMachine::CommonScanAfterPnoResult() { - LOGI("Enter ScanStateMachine::CommonScanAfterPnoResult.\n"); + WIFI_LOGI("Enter ScanStateMachine::CommonScanAfterPnoResult.\n"); std::vector scanResults; if (!GetScanResults(scanResults)) { - LOGE("GetScanResults failed."); + WIFI_LOGE("GetScanResults failed."); return; } @@ -1469,7 +1459,7 @@ void ScanStateMachine::CommonScanAfterPnoResult() void ScanStateMachine::PnoScanFailedProcess() { - LOGI("Enter ScanStateMachine::PnoScanFailedProcess.\n"); + WIFI_LOGI("Enter ScanStateMachine::PnoScanFailedProcess.\n"); runningHwPnoFlag = false; runningSwPnoFlag = false; @@ -1502,26 +1492,35 @@ void ScanStateMachine::ClearPnoScanConfig() bool ScanStateMachine::GetScanResults(std::vector &scanResults) { - LOGI("Enter ScanStateMachine::GetScanResults.\n"); + WIFI_LOGI("Enter ScanStateMachine::GetScanResults.\n"); std::vector wifiScanResults; - LOGI("Begin: QueryScanResults."); + WIFI_LOGI("Begin: QueryScanResults."); if (WifiStaHalInterface::GetInstance().QueryScanResults(wifiScanResults) != WIFI_IDL_OPT_OK) { - LOGE("WifiStaHalInterface::GetInstance().QueryScanResults failed."); + WIFI_LOGE("WifiStaHalInterface::GetInstance().QueryScanResults failed."); return false; } - LOGI("End: QueryScanResults."); + WIFI_LOGI("End: QueryScanResults."); ConvertScanResults(wifiScanResults, scanResults); + for (auto iter = scanResults.begin(); iter != scanResults.end(); iter++) { + if (iter->frequency < SCAN_24GHZ_MAX_FREQUENCY) { + iter->band = 0; + } else if (iter->frequency > SCAN_5GHZ_MIN_FREQUENCY) { + iter->band = 1; + } else { + WIFI_LOGE("invalid frequency value: %d", iter->frequency); + } + } return true; } bool ScanStateMachine::StartNewSoftwareScan() { - LOGI("Enter ScanStateMachine::StartNewSoftwareScan.\n"); + WIFI_LOGI("Enter ScanStateMachine::StartNewSoftwareScan.\n"); if (!RepeatStartCommonScan()) { - LOGE("failed to start common single scan"); + WIFI_LOGE("failed to start common single scan"); return false; } StartTimer(int(SOFTWARE_PNO_SCAN_TIMER), (runningPnoScanConfig.scanInterval) * SECOND_TO_MILLI_SECOND); @@ -1531,10 +1530,10 @@ bool ScanStateMachine::StartNewSoftwareScan() bool ScanStateMachine::RepeatStartCommonScan() { - LOGI("Enter ScanStateMachine::RepeatStartCommonScan.\n"); + WIFI_LOGI("Enter ScanStateMachine::RepeatStartCommonScan.\n"); if (!pnoConfigStoredFlag) { - LOGE("Pno config has not stored."); + WIFI_LOGE("Pno config has not stored."); return false; } @@ -1549,17 +1548,17 @@ bool ScanStateMachine::RepeatStartCommonScan() } runningSwPnoFlag = true; - TransitionTo(pnoSwScanningState); + SwitchState(pnoSwScanningState); return true; } void ScanStateMachine::StopPnoScanSoftware() { - LOGI("ScanStateMachine::StopPnoScanSoftware.\n"); + WIFI_LOGI("ScanStateMachine::StopPnoScanSoftware.\n"); if (!runningSwPnoFlag) { - LOGE("Software Pno scan is not running."); + WIFI_LOGE("Software Pno scan is not running."); return; } @@ -1573,20 +1572,20 @@ void ScanStateMachine::StopPnoScanSoftware() void ScanStateMachine::PnoScanSoftwareProcess(InternalMessage *interMessage) { - LOGI("ScanStateMachine::PnoScanSoftwareProcess.\n"); + WIFI_LOGI("ScanStateMachine::PnoScanSoftwareProcess.\n"); if (runningSwPnoFlag) { - LOGE("Software Pno scan is running."); + WIFI_LOGE("Software Pno scan is running."); return; } if (!GetPnoScanRequestInfo(interMessage)) { - LOGE("GetPnoScanRequestInfo failed."); + WIFI_LOGE("GetPnoScanRequestInfo failed."); return; } if (!StartNewSoftwareScan()) { - LOGE("StartPnoScanSoftware failed."); + WIFI_LOGE("StartPnoScanSoftware failed."); return; } @@ -1595,11 +1594,11 @@ void ScanStateMachine::PnoScanSoftwareProcess(InternalMessage *interMessage) void ScanStateMachine::SoftwareScanResultProcess() { - LOGI("Enter ScanStateMachine::SoftwareScanResultProcess.\n"); + WIFI_LOGI("Enter ScanStateMachine::SoftwareScanResultProcess.\n"); std::vector scanResults; if (!GetScanResults(scanResults)) { - LOGE("GetScanResults failed."); + WIFI_LOGE("GetScanResults failed."); } ReportPnoScanResults(scanResults); @@ -1608,35 +1607,35 @@ void ScanStateMachine::SoftwareScanResultProcess() bool ScanStateMachine::InitCommonScanState() { - LOGI("Enter ScanStateMachine::InitCommonScanState.\n"); + WIFI_LOGI("Enter ScanStateMachine::InitCommonScanState.\n"); initState = new (std::nothrow) InitState(this); if (initState == nullptr) { - LOGE("Alloc initState failed.\n"); + WIFI_LOGE("Alloc initState failed.\n"); return false; } hardwareReadyState = new (std::nothrow) HardwareReady(this); if (hardwareReadyState == nullptr) { - LOGE("Alloc hardwareReadyState failed.\n"); + WIFI_LOGE("Alloc hardwareReadyState failed.\n"); return false; } commonScanState = new (std::nothrow) CommonScan(this); if (commonScanState == nullptr) { - LOGE("Alloc commonScanState failed.\n"); + WIFI_LOGE("Alloc commonScanState failed.\n"); return false; } commonScanUnworkedState = new (std::nothrow) CommonScanUnworked(this); if (commonScanUnworkedState == nullptr) { - LOGE("Alloc commonScanUnworkedState failed.\n"); + WIFI_LOGE("Alloc commonScanUnworkedState failed.\n"); return false; } commonScanningState = new (std::nothrow) CommonScanning(this); if (commonScanningState == nullptr) { - LOGE("Alloc commonScanningState failed.\n"); + WIFI_LOGE("Alloc commonScanningState failed.\n"); return false; } @@ -1645,41 +1644,41 @@ bool ScanStateMachine::InitCommonScanState() bool ScanStateMachine::InitPnoScanState() { - LOGI("Enter ScanStateMachine::InitPnoScanState.\n"); + WIFI_LOGI("Enter ScanStateMachine::InitPnoScanState.\n"); pnoScanState = new (std::nothrow) PnoScan(this); if (pnoScanState == nullptr) { - LOGE("Alloc pnoScanState failed.\n"); + WIFI_LOGE("Alloc pnoScanState failed.\n"); return false; } pnoScanHardwareState = new (std::nothrow) PnoScanHardware(this); if (pnoScanHardwareState == nullptr) { - LOGE("Alloc pnoScanHardwareState failed.\n"); + WIFI_LOGE("Alloc pnoScanHardwareState failed.\n"); return false; } commonScanAfterPnoState = new (std::nothrow) CommonScanAfterPno(this); if (commonScanAfterPnoState == nullptr) { - LOGE("Alloc commonScanAfterPnoState failed.\n"); + WIFI_LOGE("Alloc commonScanAfterPnoState failed.\n"); return false; } pnoScanSoftwareState = new (std::nothrow) PnoScanSoftware(this); if (pnoScanSoftwareState == nullptr) { - LOGE("Alloc pnoScanSoftwareState failed.\n"); + WIFI_LOGE("Alloc pnoScanSoftwareState failed.\n"); return false; } pnoSwScanFreeState = new (std::nothrow) PnoSwScanFree(this); if (pnoSwScanFreeState == nullptr) { - LOGE("Alloc pnoSwScanFreeState failed.\n"); + WIFI_LOGE("Alloc pnoSwScanFreeState failed.\n"); return false; } pnoSwScanningState = new (std::nothrow) PnoSwScanning(this); if (pnoSwScanningState == nullptr) { - LOGE("Alloc pnoSwScanningState failed.\n"); + WIFI_LOGE("Alloc pnoSwScanningState failed.\n"); return false; } @@ -1688,35 +1687,35 @@ bool ScanStateMachine::InitPnoScanState() void ScanStateMachine::BuildScanStateTree() { - LOGI("Enter ScanStateMachine::BuildScanStateTree.\n"); + WIFI_LOGI("Enter ScanStateMachine::BuildScanStateTree.\n"); - AddState(initState, nullptr); - AddState(hardwareReadyState, initState); - AddState(commonScanState, hardwareReadyState); - AddState(commonScanUnworkedState, commonScanState); - AddState(commonScanningState, commonScanState); - AddState(pnoScanState, hardwareReadyState); - AddState(pnoScanHardwareState, pnoScanState); - AddState(commonScanAfterPnoState, pnoScanHardwareState); - AddState(pnoScanSoftwareState, pnoScanState); - AddState(pnoSwScanFreeState, pnoScanSoftwareState); - AddState(pnoSwScanningState, pnoScanSoftwareState); + StatePlus(initState, nullptr); + StatePlus(hardwareReadyState, initState); + StatePlus(commonScanState, hardwareReadyState); + StatePlus(commonScanUnworkedState, commonScanState); + StatePlus(commonScanningState, commonScanState); + StatePlus(pnoScanState, hardwareReadyState); + StatePlus(pnoScanHardwareState, pnoScanState); + StatePlus(commonScanAfterPnoState, pnoScanHardwareState); + StatePlus(pnoScanSoftwareState, pnoScanState); + StatePlus(pnoSwScanFreeState, pnoScanSoftwareState); + StatePlus(pnoSwScanningState, pnoScanSoftwareState); } void ScanStateMachine::InitState::LoadDriver() { - LOGI("Enter ScanStateMachine::LoadDriver.\n"); - pScanStateMachine->TransitionTo(pScanStateMachine->hardwareReadyState); + WIFI_LOGI("Enter ScanStateMachine::LoadDriver.\n"); + pScanStateMachine->SwitchState(pScanStateMachine->hardwareReadyState); pScanStateMachine->ReportStatusChange(SCAN_STARTED_STATUS); - LOGI("Start Scan Service Success.\n"); + WIFI_LOGI("Start Scan Service Success.\n"); } void ScanStateMachine::InitState::UnLoadDriver() { - LOGI("Enter ScanStateMachine::UnLoadDriver.\n"); - pScanStateMachine->TransitionTo(pScanStateMachine->initState); + WIFI_LOGI("Enter ScanStateMachine::UnLoadDriver.\n"); + pScanStateMachine->SwitchState(pScanStateMachine->initState); pScanStateMachine->quitFlag = true; - LOGI("Stop Scan Service Success.\n"); + WIFI_LOGI("Stop Scan Service Success.\n"); } } // namespace Wifi } // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.h index 3a159bace..e08915b8a 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan/scan_state_machine.h @@ -38,6 +38,8 @@ const int SCAN_TYPE_LOW_POWER = 1; const int SCAN_TYPE_HIGH_ACCURACY = 2; const int SCAN_TYPE_INVALID = 0xFF; const int MAX_WAIT_SCAN_RESULT_TIME = 60 * 1000; +const int SCAN_24GHZ_MAX_FREQUENCY = 2500; +const int SCAN_5GHZ_MIN_FREQUENCY = 5000; class ScanStateMachine : public StateMachine { public: @@ -66,9 +68,9 @@ public: */ explicit InitState(ScanStateMachine *paraScanStateMachine); ~InitState(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -92,9 +94,9 @@ public: */ explicit HardwareReady(ScanStateMachine *paraScanStateMachine); ~HardwareReady(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -108,9 +110,9 @@ public: */ explicit CommonScan(ScanStateMachine *paraScanStateMachine); ~CommonScan(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -124,9 +126,9 @@ public: */ explicit CommonScanUnworked(ScanStateMachine *paraScanStateMachine); ~CommonScanUnworked(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -140,9 +142,9 @@ public: */ explicit CommonScanning(ScanStateMachine *paraScanStateMachine); ~CommonScanning(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -156,9 +158,9 @@ public: */ explicit PnoScan(ScanStateMachine *paraScanStateMachine); ~PnoScan(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -172,9 +174,9 @@ public: */ explicit PnoScanHardware(ScanStateMachine *paraScanStateMachine); ~PnoScanHardware(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -188,9 +190,9 @@ public: */ explicit CommonScanAfterPno(ScanStateMachine *paraScanStateMachine); ~CommonScanAfterPno(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -204,9 +206,9 @@ public: */ explicit PnoScanSoftware(ScanStateMachine *paraScanStateMachine); ~PnoScanSoftware(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -220,9 +222,9 @@ public: */ explicit PnoSwScanFree(ScanStateMachine *paraScanStateMachine); ~PnoSwScanFree(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -236,9 +238,9 @@ public: */ explicit PnoSwScanning(ScanStateMachine *paraScanStateMachine); ~PnoSwScanning(); - void Enter(); - void Exit(); - bool ProcessMessage(InternalMessage *msg); + void GoInState(); + void GoOutState(); + bool ExecuteStateMsg(InternalMessage *msg); private: ScanStateMachine *pScanStateMachine; @@ -352,8 +354,6 @@ private: * @param scanResults - Scan internal scan results[out] */ void ConvertScanResults(std::vector &wifiScanResults, std::vector &scanResults); - void OnQuitting(); - void OnHalting(); /** * @Description Reporting Status to ScanService. * diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_callback_proxy.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_callback_proxy.cpp index 802a30fcb..0b97d8c60 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_callback_proxy.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_callback_proxy.cpp @@ -18,7 +18,7 @@ #include "define.h" #include "wifi_event_broadcast.h" -DEFINE_WIFILOG_LABEL("WifiScanCallbackProxy"); +DEFINE_WIFILOG_SCAN_LABEL("WifiScanCallbackProxy"); namespace OHOS { namespace Wifi { diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_death_recipient.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_death_recipient.cpp index a3cc2403e..00705da26 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_death_recipient.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_death_recipient.cpp @@ -16,7 +16,7 @@ #include "wifi_scan_death_recipient.h" #include "wifi_logger.h" #include "wifi_event_broadcast.h" -DEFINE_WIFILOG_LABEL("WifiScanDeathRecipient"); +DEFINE_WIFILOG_SCAN_LABEL("WifiScanDeathRecipient"); namespace OHOS { namespace Wifi { void WifiScanDeathRecipient::OnRemoteDied(const wptr& remoteObject) diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_service_impl.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_service_impl.cpp index 6beb027ee..850aa9b38 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_service_impl.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_service_impl.cpp @@ -27,7 +27,7 @@ #include "define.h" #include "wifi_scan_callback_proxy.h" -DEFINE_WIFILOG_LABEL("WifiScanServiceImpl"); +DEFINE_WIFILOG_SCAN_LABEL("WifiScanServiceImpl"); namespace OHOS { namespace Wifi { std::mutex WifiScanServiceImpl::g_instanceLock; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp index 5ed3cd32d..dc9a71aa2 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_scan_stub.cpp @@ -23,7 +23,7 @@ namespace OHOS { namespace Wifi { -DEFINE_WIFILOG_LABEL("WifiScanStub"); +DEFINE_WIFILOG_SCAN_LABEL("WifiScanStub"); WifiScanStub::WifiScanStub() : callback_(nullptr), mSingleCallback(false) {} @@ -188,8 +188,9 @@ int WifiScanStub::OnGetScanInfoList(uint32_t code, MessageParcel &data, MessageP reply.WriteCString(result[i].ssid.c_str()); reply.WriteCString(result[i].capabilities.c_str()); reply.WriteInt32(result[i].frequency); - reply.WriteInt32(result[i].level); + reply.WriteInt32(result[i].rssi); reply.WriteInt32(result[i].timestamp); + reply.WriteInt32(result[i].band); } } return ret; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp index df9a2e8ff..dad91b204 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_service_manager.cpp @@ -18,8 +18,7 @@ #include "define.h" #include "wifi_settings.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_MANAGER_SERVICE_MANAGER" +DEFINE_WIFILOG_LABEL("WifiServiceManager"); namespace OHOS { namespace Wifi { @@ -71,32 +70,32 @@ int WifiServiceManager::CheckPreLoadService(void) int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCreate) { - LOGD("WifiServiceManager::CheckAndEnforceService name: %{public}s", name.c_str()); + WIFI_LOGD("WifiServiceManager::CheckAndEnforceService name: %{public}s", name.c_str()); std::string dlname; if (GetServiceDll(name, dlname) < 0) { - LOGE("%{public}s does not support", name.c_str()); + WIFI_LOGE("%{public}s does not support", name.c_str()); return -1; } - LOGD("WifiServiceManager::CheckAndEnforceService get dllname: %{public}s", dlname.c_str()); + WIFI_LOGD("WifiServiceManager::CheckAndEnforceService get dllname: %{public}s", dlname.c_str()); std::unique_lock lock(mMutex); if (mServiceHandleMap.find(name) == mServiceHandleMap.end()) { ServiceHandle tmp; tmp.handle = dlopen(dlname.c_str(), RTLD_LAZY); if (tmp.handle == nullptr) { - LOGE("dlopen %{public}s failed: %{public}s!", dlname.c_str(), dlerror()); + WIFI_LOGE("dlopen %{public}s failed: %{public}s!", dlname.c_str(), dlerror()); return -1; } tmp.create = (BaseService* (*)()) dlsym(tmp.handle, "Create"); tmp.destroy = (void *(*)(BaseService*))dlsym(tmp.handle, "Destroy"); if (tmp.create == nullptr || tmp.destroy == nullptr) { - LOGE("%{public}s dlsym Create or Destroy failed!", dlname.c_str()); + WIFI_LOGE("%{public}s dlsym Create or Destroy failed!", dlname.c_str()); dlclose(tmp.handle); return -1; } if (bCreate) { tmp.bs = tmp.create(); if (tmp.bs == nullptr) { - LOGE("create feature service is nullptr"); + WIFI_LOGE("create feature service is nullptr"); } } mServiceHandleMap.emplace(std::make_pair(name, tmp)); @@ -106,16 +105,16 @@ int WifiServiceManager::CheckAndEnforceService(const std::string &name, bool bCr BaseService *WifiServiceManager::GetServiceInst(const std::string &name) { - LOGD("WifiServiceManager::GetServiceInst name: %{public}s", name.c_str()); + WIFI_LOGD("WifiServiceManager::GetServiceInst name: %{public}s", name.c_str()); std::unique_lock lock(mMutex); auto iter = mServiceHandleMap.find(name); if (iter != mServiceHandleMap.end()) { if (iter->second.bs == nullptr) { - LOGD("WifiServiceManager::GetServiceInst start create feature service"); + WIFI_LOGD("WifiServiceManager::GetServiceInst start create feature service"); iter->second.bs = iter->second.create(); } if (iter->second.bs == nullptr) { - LOGE("WifiServiceManager::GetServiceInst feature service is nullptr"); + WIFI_LOGE("WifiServiceManager::GetServiceInst feature service is nullptr"); } return iter->second.bs; } @@ -125,7 +124,7 @@ BaseService *WifiServiceManager::GetServiceInst(const std::string &name) int WifiServiceManager::UnloadService(const std::string &name) { bool bPreLoad = WifiSettings::GetInstance().IsModulePreLoad(name); - LOGD("WifiServiceManager::UnloadService name: %{public}s", name.c_str()); + WIFI_LOGD("WifiServiceManager::UnloadService name: %{public}s", name.c_str()); std::unique_lock lock(mMutex); auto iter = mServiceHandleMap.find(name); if (iter != mServiceHandleMap.end()) { @@ -143,7 +142,7 @@ int WifiServiceManager::UnloadService(const std::string &name) void WifiServiceManager::UninstallAllService() { - LOGD("WifiServiceManager::UninstallAllService"); + WIFI_LOGD("WifiServiceManager::UninstallAllService"); std::unique_lock lock(mMutex); for (auto iter = mServiceHandleMap.begin(); iter != mServiceHandleMap.end(); ++iter) { ServiceHandle &tmp = iter->second; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp new file mode 100644 index 000000000..63ffdb7f7 --- /dev/null +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.cpp @@ -0,0 +1,612 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "sta_auto_connect_service.h" +#include "wifi_logger.h" + +DEFINE_WIFILOG_LABEL("StaAutoConnectService"); + +namespace OHOS { +namespace Wifi { +StaAutoConnectService::StaAutoConnectService(StaStateMachine *staStateMachine) + : pStaStateMachine(staStateMachine), + pSavedDeviceAppraisal(nullptr), + firmwareRoamFlag(false), + maxBlockedBssidNum(BLOCKLIST_INVALID_SIZE), + selectDeviceLastTime(0), + pAppraisals {nullptr, nullptr, nullptr, nullptr, nullptr, nullptr} +{} + +StaAutoConnectService::~StaAutoConnectService() +{ + WIFI_LOGI("Enter StaAutoConnectService::~StaAutoConnectService.\n"); + if (pSavedDeviceAppraisal != nullptr) { + delete pSavedDeviceAppraisal; + pSavedDeviceAppraisal = nullptr; + } +} + +ErrCode StaAutoConnectService::InitAutoConnectService() +{ + WIFI_LOGI("Enter StaAutoConnectService::InitAutoConnectService.\n"); + + if (ObtainRoamCapFromFirmware()) { + WIFI_LOGI("Succeeded in obtaining firmware roaming information.\n"); + } + SyncBlockedSsidFirmware(); + + pSavedDeviceAppraisal = new (std::nothrow) StaSavedDeviceAppraisal(firmwareRoamFlag); + if (pSavedDeviceAppraisal == nullptr) { + WIFI_LOGE("savedDeviceAppraisal is null\n"); + return WIFI_OPT_FAILED; + } + + int savedPriority = WifiSettings::GetInstance().GetsavedDeviceAppraisalPriority(); + if (RegisterDeviceAppraisal(pSavedDeviceAppraisal, savedPriority)) { + WIFI_LOGI("RegisterSavedDeviceAppraisal succeeded.\n"); + } + return WIFI_OPT_SUCCESS; +} + +void StaAutoConnectService::OnScanResultsReadyHandler(const std::vector &scanInfos) +{ + WIFI_LOGI("Enter StaAutoConnectService::OnScanResultsReadyHandler.\n"); + ClearOvertimeBlockedBssid(); /* Refreshing the BSSID Blocklist */ + + WifiLinkedInfo info; + WifiSettings::GetInstance().GetLinkedInfo(info); + if (info.supplicantState == SupplicantState::ASSOCIATING || + info.supplicantState == SupplicantState::AUTHENTICATING || + info.supplicantState == SupplicantState::FOUR_WAY_HANDSHAKE || + info.supplicantState == SupplicantState::GROUP_HANDSHAKE) { + WIFI_LOGE("Supplicant is under transient state.\n"); + return; + } + + std::vector blockedBssids; + GetBlockedBssids(blockedBssids); + + WifiDeviceConfig electedDevice; + if (AutoSelectDevice(electedDevice, scanInfos, blockedBssids, info) == WIFI_OPT_SUCCESS) { + WIFI_LOGI("AutoSelectDevice succeed.\n"); + ConnectElectedDevice(electedDevice); + } else { + WIFI_LOGI("Exit network selection.\n"); + return; + } +} + +bool StaAutoConnectService::EnableOrDisableBssid(std::string bssid, bool enable, int reason) +{ + WIFI_LOGI("Enter StaAutoConnectService::EnableOrDisableBssid.\n"); + if (bssid.empty()) { + WIFI_LOGI("bssid is empty.\n"); + return false; + } + + /* Updating the BSSID Blocklist */ + if (!AddOrDelBlockedBssids(bssid, enable, reason)) { + WIFI_LOGI("The blocklist is not updated.\n"); + return false; + } + + /* The blocklist has been updated, so update the firmware roaming */ + /* configuration */ + SyncBlockedSsidFirmware(); + return true; +} + +bool StaAutoConnectService::AddOrDelBlockedBssids(std::string bssid, bool enable, int reason) +{ + WIFI_LOGI("Enter StaAutoConnectService::AddOrDelBlockedBssids.\n"); + if (enable) { + if (blockedBssidMap.count(bssid) != 0) { + /* Removed the BSSID from the blocklist When the BSSID is enabled. */ + blockedBssidMap.erase(bssid); + return true; + } + return false; + } + + BlockedBssidInfo status; + auto iter = blockedBssidMap.find(bssid); + if (iter == blockedBssidMap.end()) { + blockedBssidMap.emplace(bssid, status); + } + auto iterator = blockedBssidMap.find(bssid); + if (iterator == blockedBssidMap.end()) { + return false; + } + iterator->second.count++; + time_t now = time(0); + iterator->second.blockedTime = (int)now; + if (!iterator->second.blockedFlag) { + if (iterator->second.count >= MAX_BSSID_BLOCKLIST_COUNT || + reason == AP_CANNOT_HANDLE_NEW_STA) { + iterator->second.blockedFlag = true; + return true; + } + } + return false; +} + +void StaAutoConnectService::GetBlockedBssids(std::vector &blockedBssids) +{ + WIFI_LOGI("Enter StaAutoConnectService::GetBlockedBssids.\n"); + + for (auto iter = blockedBssidMap.begin(); iter != blockedBssidMap.end(); ++iter) { + blockedBssids.push_back(iter->first); + } + return; +} + +void StaAutoConnectService::ClearOvertimeBlockedBssid() +{ + WIFI_LOGI("Enter StaAutoConnectService::ClearOvertimeBlockedBssid.\n"); + if (blockedBssidMap.empty()) { + return; + } + bool updated = false; + auto iter = blockedBssidMap.begin(); + while (iter != blockedBssidMap.end()) { + BlockedBssidInfo status = iter->second; + time_t now = time(0); + int currentTimeStap = (int)now; + if (status.blockedFlag && ((currentTimeStap - status.blockedTime) >= MAX_BSSID_BLOCKLIST_TIME)) { + blockedBssidMap.erase(iter++); + updated = true; + } else { + ++iter; + } + } + if (updated) { + SyncBlockedSsidFirmware(); + } + return; +} + +void StaAutoConnectService::ConnectElectedDevice(WifiDeviceConfig &electedDevice) +{ + WIFI_LOGI("Enter StaAutoConnectService::ConnectElectedDevice.\n"); + if (electedDevice.bssid.empty()) { + WIFI_LOGE("electedDevice is null.\n"); + return; + } + + WifiLinkedInfo currentConnectedNetwork; + WifiSettings::GetInstance().GetLinkedInfo(currentConnectedNetwork); + if (currentConnectedNetwork.connState == ConnState::CONNECTED && electedDevice.networkId == INVALID_NETWORK_ID && + currentConnectedNetwork.ssid == electedDevice.ssid && currentConnectedNetwork.bssid != electedDevice.bssid) { + /* Frameworks start roaming only when firmware is not supported */ + if (!firmwareRoamFlag) { + WIFI_LOGI("Roaming connectTo.\n"); + pStaStateMachine->StartRoamToNetwork(electedDevice.bssid); + WIFI_LOGI("connecTo network bssid is %s", electedDevice.bssid.c_str()); + } + } else if (currentConnectedNetwork.detailedState == DetailedState::DISCONNECTED) { + WIFI_LOGI("connecTo save network.\n"); + pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, + electedDevice.networkId, + NETWORK_SELECTED_FOR_CONNECTION_MANAGEMENT); + WIFI_LOGI("connecTo networkId is %{public}d", electedDevice.networkId); + WIFI_LOGI("connecTo bssid is %s", electedDevice.bssid.c_str()); + WIFI_LOGI("connecTo preShareKey is %s", electedDevice.preSharedKey.c_str()); + } else { + WIFI_LOGE("The current connection status is %{public}d.\n", currentConnectedNetwork.detailedState); + } + return; +} + +void StaAutoConnectService::SyncBlockedSsidFirmware() +{ + WIFI_LOGI("Enter StaAutoConnectService::SyncBlockedSsidFirmware.\n"); + if (!firmwareRoamFlag) { + return; + } + if (maxBlockedBssidNum <= 0) { + return; + } + std::vector blockedBssids; + GetBlockedBssids(blockedBssids); + + if (static_cast(blockedBssids.size()) > maxBlockedBssidNum) { + blockedBssids.resize(maxBlockedBssidNum); + } + + if (SetRoamBlockedBssidFirmware(blockedBssids)) { + WIFI_LOGE("Set firmware roaming configuration succeeded.\n"); + } else { + WIFI_LOGI("Set firmware roaming configuration failed.\n"); + } + return; +} + +bool StaAutoConnectService::ObtainRoamCapFromFirmware() +{ + WIFI_LOGI("Enter StaAutoConnectService::ObtainRoamCapFromFirmware.\n"); + + unsigned int capabilities; + if (WifiStaHalInterface::GetInstance().GetStaCapabilities(capabilities) == WIFI_IDL_OPT_OK) { + if ((capabilities & STA_CAP_ROAMING) == 0) { + WIFI_LOGE("Firmware roaming is not supported.\n"); + return false; + } + } + + WifiIdlRoamCapability capability; + if (WifiStaHalInterface::GetInstance().GetRoamingCapabilities(capability) == WIFI_IDL_OPT_OK) { + if (capability.maxBlocklistSize > 0) { + firmwareRoamFlag = true; + maxBlockedBssidNum = capability.maxBlocklistSize; + WIFI_LOGI("Get firmware roaming capabilities succeeded.\n"); + return true; + } + WIFI_LOGE("Invalid firmware roaming capabilities.\n"); + } + + WIFI_LOGE("Get firmware roaming capabilities failed.\n"); + return false; +} + +bool StaAutoConnectService::SetRoamBlockedBssidFirmware(const std::vector &blocklistBssids) const +{ + WIFI_LOGI("Enter StaAutoConnectService::SetRoamBlockedBssidFirmware.\n"); + if (!firmwareRoamFlag) { + return false; + } + + if (blocklistBssids.empty()) { + return false; + } + + if (static_cast(blocklistBssids.size()) > maxBlockedBssidNum) { + return false; + } + + WifiIdlRoamConfig capability; + capability.blocklistBssids = blocklistBssids; + if (WifiStaHalInterface::GetInstance().SetRoamConfig(capability) == WIFI_IDL_OPT_OK) { + return true; + } + return false; +} + +bool StaAutoConnectService::RegisterDeviceAppraisal(StaDeviceAppraisal *appraisal, int priority) +{ + WIFI_LOGI("Enter StaAutoConnectService::RegisterDeviceAppraisal.\n"); + if (priority < 0 || priority >= MIN_APPRAISAL_PRIORITY) { + WIFI_LOGE("Out of array range.\n"); + return false; + } + if (pAppraisals[priority] != nullptr) { + WIFI_LOGE("Appraisals is not empty.\n"); + return false; + } + pAppraisals[priority] = appraisal; + return true; +} + +ErrCode StaAutoConnectService::AutoSelectDevice(WifiDeviceConfig &electedDevice, + const std::vector &scanInfos, std::vector &blockedBssids, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaAutoConnectService::SelectNetwork.\n"); + if (scanInfos.empty()) { + WIFI_LOGE("No scanResult.\n"); + return WIFI_OPT_FAILED; + } + + /* Whether network selection handover is required */ + if (!AllowAutoSelectDevice(scanInfos, info)) { + WIFI_LOGE("Network switching is not required.\n"); + return WIFI_OPT_FAILED; + } + + /* Before initiating network selection, update all configured networks. */ + RefreshConfigDevice(); + + std::vector availableScanInfos; + /* Filter out unnecessary networks. */ + GetAvailableScanInfos(availableScanInfos, scanInfos, blockedBssids, info); + if (availableScanInfos.empty()) { + WIFI_LOGE("No scanResult available.\n"); + return WIFI_OPT_FAILED; + } + /* + * Check the registered network appraisal from highest priority to lowest + * priority until the selected network + */ + for (auto registeredAppraisal : pAppraisals) { + if (registeredAppraisal != nullptr) { + ErrCode code = registeredAppraisal->DeviceAppraisals(electedDevice, availableScanInfos, info); + if (code == WIFI_OPT_SUCCESS) { + time_t now = time(0); + selectDeviceLastTime = static_cast(now); + WIFI_LOGI("electedDevice generation.\n"); + return WIFI_OPT_SUCCESS; + } + } + } + + if (RoamingSelection(electedDevice, availableScanInfos, info)) { + WIFI_LOGI("Roaming network generation.\n"); + return WIFI_OPT_SUCCESS; + } + WIFI_LOGE("No electedDevice.\n"); + return WIFI_OPT_FAILED; +} + +bool StaAutoConnectService::RoamingSelection( + WifiDeviceConfig &electedDevice, std::vector &availableScanInfos, WifiLinkedInfo &info) +{ + for (auto scanInfo : availableScanInfos) { + if (info.connState == ConnState::CONNECTED && scanInfo.ssid == info.ssid && scanInfo.bssid != info.bssid) { + WIFI_LOGI("Discover roaming networks.\n"); + if (RoamingEncryptionModeCheck(electedDevice, scanInfo, info)) { + return true; + } + } + } + return false; +} + +bool StaAutoConnectService::RoamingEncryptionModeCheck( + WifiDeviceConfig &electedDevice, WifiScanInfo scanInfo, WifiLinkedInfo &info) +{ + WifiDeviceConfig network; + if (WifiSettings::GetInstance().GetDeviceConfig(scanInfo.ssid, DEVICE_CONFIG_INDEX_SSID, network) == 0) { + std::string mgmt = scanInfo.capabilities; + if (mgmt.find("WPA-PSK") != std::string::npos || mgmt.find("WPA2-PSK") != std::string::npos) { + mgmt = "WPA-PSK"; + } else if (mgmt.find("EAP") != std::string::npos) { + mgmt = "WPA-EAP"; + } else if (mgmt.find("SAE") != std::string::npos) { + mgmt = "SAE"; + } else { + if (mgmt.find("WEP") != std::string::npos && network.wepTxKeyIndex == 0) { + WIFI_LOGE("The roaming network is a WEP network, but the connected network is not a WEP network.\n"); + return false; + } else if (mgmt.find("WEP") == std::string::npos && network.wepTxKeyIndex != 0) { + WIFI_LOGE("The connected network is a WEP network, but the roaming network is not a WEP network.\n"); + return false; + } + mgmt = "NONE"; + } + if (mgmt == network.keyMgmt) { + WIFI_LOGI("The Current network bssid %s signal strength is %{public}d", info.bssid.c_str(), info.rssi); + WIFI_LOGI( + "The Roaming network bssid %s signal strength is %{public}d", scanInfo.bssid.c_str(), scanInfo.rssi); + int rssi = scanInfo.rssi - info.rssi; + if (rssi > MIN_ROAM_RSSI_DIFF) { + WIFI_LOGI("Roming network rssi - Current network rssi > 6."); + electedDevice.ssid = scanInfo.ssid; + electedDevice.bssid = scanInfo.bssid; + return true; + } else { + WIFI_LOGE("Roming network rssi - Current network rssi < 6."); + } + } else { + WIFI_LOGE("The encryption mode does not match.\n"); + } + } + return false; +} + +bool StaAutoConnectService::AllowAutoSelectDevice(const std::vector &scanInfos, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaAutoConnectService::AllowAutoSelectDevice.\n"); + if (scanInfos.empty()) { + WIFI_LOGE("No network,skip network selection.\n"); + return false; + } + + /* Connected to the network */ + if (info.detailedState == DetailedState::WORKING) { + WIFI_LOGI("The current connection status is Connected and working.\n"); + + /* Configure whether to automatically switch the network. */ + if (!WifiSettings::GetInstance().GetWhetherToAllowNetworkSwitchover()) { + WIFI_LOGE("Automatic network switching is not allowed in user " + "configuration.\n"); + return false; + } + /* + * Indicates whether the minimum interval is the minimum interval since the + * last network selection. + */ + if (selectDeviceLastTime != 0) { + int gap = static_cast(time(0)) - selectDeviceLastTime; + if (gap < MIN_SELECT_NETWORK_TIME) { + WIFI_LOGE("%ds time before we selected the network(30s).\n", gap); + return false; + } + } + + if (CurrentDeviceGoodEnough(scanInfos, info)) { + WIFI_LOGE("The current network is suffice.\n"); + return false; + } else { + WIFI_LOGI("The current network is insuffice.\n"); + return true; + } + } else if (info.detailedState == DetailedState::DISCONNECTED) { + WIFI_LOGI("The current connection status is Disconnected.\n"); + return true; + } else if (info.detailedState == DetailedState::NOTWORKING) { + WIFI_LOGI("The current network cannot access the Internet.\n"); + + /* Configure whether to automatically switch the network. */ + if (!WifiSettings::GetInstance().GetWhetherToAllowNetworkSwitchover()) { + WIFI_LOGE("Automatic network switching is not allowed in user " + "configuration.\n"); + return false; + } else { + return true; + } + } else { + WIFI_LOGE("The current connection status is %{public}d.\n", info.detailedState); + return false; + } +} + +bool StaAutoConnectService::CurrentDeviceGoodEnough(const std::vector &scanInfos, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaAutoConnectService::CurrentDeviceGoodEnough.\n"); + + WifiDeviceConfig network; + + /* The network is deleted */ + if (WifiSettings::GetInstance().GetDeviceConfig(info.networkId, network) == -1) { + WIFI_LOGE("The network is deleted.\n"); + return false; + } + + int userLastSelectedNetworkId = WifiSettings::GetInstance().GetUserLastSelectedNetworkId(); + if (userLastSelectedNetworkId != INVALID_NETWORK_ID && userLastSelectedNetworkId == network.networkId) { + time_t userLastSelectedNetworkTimeVal = WifiSettings::GetInstance().GetUserLastSelectedNetworkTimeVal(); + time_t now = time(0); + int interval = static_cast(now - userLastSelectedNetworkTimeVal); + if (interval <= TIME_FROM_LAST_SELECTION) { + WIFI_LOGI("(60s)Current user recent selections time is %ds.\n", interval); + return true; + } + } + + /* Temporary network unqualified */ + if (network.isEphemeral) { + WIFI_LOGE("The network is isEphemeral.\n"); + return false; + } + + if (network.keyMgmt == "NONE" || network.keyMgmt.size() == 0) { + WIFI_LOGE("This network No keyMgmt.\n"); + return false; + } + + /* The signal strength on the live network does not meet requirements. */ + if (info.rssi < RSSI_DELIMITING_VALUE) { + WIFI_LOGE("Signal strength insuffice %{public}d < -65.\n", info.rssi); + return false; + } + /* + * The network is a 2.4 GHz network and is not qualified when the 5G network + * is available. + */ + if (Whether24GDevice(info.frequency)) { + if (WhetherDevice5GAvailable(scanInfos)) { + WIFI_LOGE("5 GHz is available when the current frequency band is 2.4 GHz.\n"); + return false; + } + } + return true; +} + +bool StaAutoConnectService::WhetherDevice5GAvailable(const std::vector &scanInfos) +{ + WIFI_LOGI("Enter StaAutoConnectService::WhetherDevice5GAvailable.\n"); + for (auto scaninfo : scanInfos) { + if (Whether5GDevice(scaninfo.frequency)) { + return true; + } + } + return false; +} + +bool StaAutoConnectService::Whether24GDevice(int frequency) +{ + if (frequency > MIN_24_FREQUENCY && frequency < MAX_24_FREQUENCY) { + return true; + } else { + return false; + } +} + +bool StaAutoConnectService::Whether5GDevice(int frequency) +{ + if (frequency > MIN_5_FREQUENCY && frequency < MAX_5_FREQUENCY) { + return true; + } else { + return false; + } +} + +void StaAutoConnectService::RefreshConfigDevice() +{ + WIFI_LOGI("Enter StaAutoConnectService::RefreshConfigDevice.\n"); + std::vector configs; + WifiSettings::GetInstance().GetDeviceConfig(configs); + if (configs.empty()) { + WIFI_LOGE("No config networks.\n"); + return; + } + for (auto network : configs) { + if (network.status == 1) { + WIFI_LOGI("The network is disable.networkId is %{public}d.", network.networkId); + } + } + return; +} + +void StaAutoConnectService::GetAvailableScanInfos(std::vector &availableScanInfos, + const std::vector &scanInfos, std::vector &blockedBssids, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaAutoConnectService::GetAvailableScanInfos.\n"); + if (scanInfos.empty()) { + return; + } + bool scanResultsContainCurrentBssid = false; + + for (auto scanInfo : scanInfos) { + if (scanInfo.ssid.size() == 0) { + continue; + } + + /* Check whether the scanning result contains the current BSSID. */ + if (info.connState == ConnState::CONNECTED && scanInfo.bssid == info.bssid) { + scanResultsContainCurrentBssid = true; + } + + auto itr = find(blockedBssids.begin(), blockedBssids.end(), scanInfo.bssid); + if (itr != blockedBssids.end()) { /* Skip Blocklist Network */ + WIFI_LOGI("Skip blocklistedBssid network %s.\n", scanInfo.ssid.c_str()); + continue; + } + + /* Skipping networks with weak signals */ + if (scanInfo.frequency < MIN_5GHZ_BAND_FREQUENCY) { + if (scanInfo.rssi <= MIN_RSSI_VALUE_24G) { + WIFI_LOGI("Skip network %s with low 2.4G signals %{public}d.\n", scanInfo.ssid.c_str(), scanInfo.rssi); + continue; + } + } else { + if (scanInfo.rssi <= MIN_RSSI_VALUE_5G) { + WIFI_LOGI("Skip network %s with low 5G signals %{public}d.\n", scanInfo.ssid.c_str(), scanInfo.rssi); + continue; + } + } + availableScanInfos.push_back(scanInfo); + } + /* + * Some scan requests may not include channels for the currently connected + * network, so the currently connected network will not appear in the scan + * results. We will not act on these scans to avoid network switching that may + * trigger disconnections. + */ + if (info.connState == ConnState::CONNECTED && !scanResultsContainCurrentBssid) { + WIFI_LOGI("scanResult is be cleared.\n"); + availableScanInfos.clear(); + } + return; +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h new file mode 100644 index 000000000..92e50e568 --- /dev/null +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_auto_connect_service.h @@ -0,0 +1,235 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_WIFI_AUTO_CONNECT_SERVICE_H +#define OHOS_WIFI_AUTO_CONNECT_SERVICE_H + +#include +#include +#include +#include +#include "wifi_log.h" +#include "wifi_settings.h" +#include "wifi_errcode.h" +#include "wifi_msg.h" +#include "log_helper.h" +#include "sta_define.h" +#include "sta_state_machine.h" +#include "sta_saved_device_appraisal.h" + +namespace OHOS { +namespace Wifi { +static const int MAX_BSSID_BLOCKLIST_COUNT = 3; +static const int AP_CANNOT_HANDLE_NEW_STA = 17; +static const int MAX_BSSID_BLOCKLIST_TIME = 5 * 60; +static const int BLOCKLIST_INVALID_SIZE = -1; +static const int STA_CAP_ROAMING = 0x800000; +static const int MIN_APPRAISAL_PRIORITY = 6; +static const int MAX_APPRAISAL_NUM = 6; +static const int MIN_SELECT_NETWORK_TIME = 30; +static const int MIN_5GHZ_BAND_FREQUENCY = 5000; +static const int RSSI_DELIMITING_VALUE = -65; +static const int MIN_RSSI_VALUE_24G = -77; +static const int MIN_RSSI_VALUE_5G = -80; +static const int TIME_FROM_LAST_SELECTION = 60; +static const int MIN_ROAM_RSSI_DIFF = 6; +class StaAutoConnectService { +public: + explicit StaAutoConnectService(StaStateMachine *staStateMachine); + ~StaAutoConnectService(); + /** + * @Description Initialize StaAutoConnectService + * + */ + ErrCode InitAutoConnectService(); + /** + * @Description Processing scan results + * + * @param scanInfos - The list of scanning results(in) + */ + void OnScanResultsReadyHandler(const std::vector &scanInfos); + /** + * @Description Whether tracking should enable or disable scanned BSSIDs + * + * @param bssid - BSSID to be enabled/disabled(in) + * @param enable - true: Enable the BSSID. false: disable the BSSID.(in) + * @param reason - Enable/Disable reason code.(in) + * @Return success: true. failed: false. + */ + bool EnableOrDisableBssid(std::string bssid, bool enable, int reason); + /** + * @Description Select the best device from the range. + * + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @param blockedBssids - Blocklisted BSSID List(in) + * @param info - Current Connected Device(in) + * @param electedDevice - Elected Device(out) + * @Return success : WIFI_OPT_SUCCESS failed : WIFI_OPT_FAILED + */ + ErrCode AutoSelectDevice(WifiDeviceConfig &electedDevice, const std::vector &scanInfos, + std::vector &blockedBssids, WifiLinkedInfo &info); + /** + * @Description Registering the Device Appraisal + * + * @param appraisal - Device appraisal to be registered(in) + * @param priority - Value between 0 and (SCORER_MIN_PRIORITY – 1)(in) + * @Return success : true failed : false + */ + bool RegisterDeviceAppraisal(StaDeviceAppraisal *appraisal, int priority); + +private: + StaStateMachine *pStaStateMachine; + StaDeviceAppraisal *pSavedDeviceAppraisal; + bool firmwareRoamFlag; + int maxBlockedBssidNum; + int selectDeviceLastTime; + StaDeviceAppraisal *pAppraisals[MAX_APPRAISAL_NUM]; + class BlockedBssidInfo { + public: + int count; /* Number of times the BSSID is rejected. */ + bool blockedFlag; + int blockedTime; + BlockedBssidInfo() + { + count = 0; + blockedFlag = false; + blockedTime = 0; + } + ~BlockedBssidInfo(){} + }; + std::unordered_map blockedBssidMap; + /** + * @Description Refreshing the BSSID Blocklist + * + */ + void ClearOvertimeBlockedBssid(); + /** + * @Description Compiles and returns the hash set of the blocklist BSSID. + * + * @param blockedBssids - Blocklisted BSSID List(out) + */ + void GetBlockedBssids(std::vector &blockedBssids); + /** + * @Description Update the BSSID blocklist when the BSSID is enabled or disabled. + * + * @param bssid - BSSID to be enabled/disabled(in) + * @param enable - true: Enable the BSSID. false: disable the BSSID.(in) + * @param reasonCode - Enable/Disable reason code.(in) + * @Return: If the blocklist is updated, The value is true. Otherwise, the value is false. + */ + bool AddOrDelBlockedBssids(std::string bssid, bool enable, int reason); + /** + * @Description If the firmware roaming function is supported, + update the firmware roaming config. + * + */ + void SyncBlockedSsidFirmware(); + /** + * @Description Querying Firmware Information + * + * @Return: If the operation is successful, true is returned. + If firmware roaming is supported but the valid roaming + capability cannot be obtained, false is returned. + */ + bool ObtainRoamCapFromFirmware(); + /** + * @Description Write Firmware Roaming Configuration to Firmware + * + * @param blocklistBssids - List of BSSIDs to Be Added to the Blocklist(in) + * @Return: True if successful, false otherwise + */ + bool SetRoamBlockedBssidFirmware(const std::vector &blocklistBssids) const; + /** + * @Description Connect to a elected device + * + * @param electedDevice - Elected Device(in) + */ + void ConnectElectedDevice(WifiDeviceConfig &electedDevice); + /** + * @Description Get available device + * + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @param blockedBssids - Blocklisted BSSID List(in) + * @param info - Current Connected Device(in) + * @param availableScanInfos - Available Scan Result(out) + */ + void GetAvailableScanInfos(std::vector &availableScanInfos, + const std::vector &scanInfos, std::vector &blockedBssids, WifiLinkedInfo &info); + /** + * @Description Whether the device needs to be switched. + * + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @param info - Current Connected Device(in) + * @Return success : true failed : false + */ + bool AllowAutoSelectDevice(const std::vector &scanInfos, WifiLinkedInfo &info); + /** + * @Description Whether the device strength is sufficient. + * + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @param info - Current Connected Device(in) + * @Return success : true failed : false + */ + bool CurrentDeviceGoodEnough(const std::vector &scanInfos, WifiLinkedInfo &info); + /** + * @Description Whether 5G devices are available. + * + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @Return success : true failed : false + */ + bool WhetherDevice5GAvailable(const std::vector &scanInfos); + /** + * @Description Select Roaming Device. + * + * @param availableScanInfos - Available device(in) + * @param scanInfos - WifiScanInfo list of all APs in the range(in) + * @param info - Current Connected Device(in) + * @param electedDevice - Elected Device(out) + * @Return success : true failed : false + */ + bool RoamingSelection( + WifiDeviceConfig &electedDevice, std::vector &availableScanInfos, WifiLinkedInfo &info); + /** + * @Description Select Roaming Device. + * + * @param WifiScanInfo - A scan result(in) + * @param info - Current Connected Device(in) + * @param electedDevice - Elected Device(out) + * @Return success : true failed : false + */ + bool RoamingEncryptionModeCheck(WifiDeviceConfig &electedDevice, WifiScanInfo scanInfo, WifiLinkedInfo &info); + /** + * @Description Updating the Configuration Center Device. + * + */ + void RefreshConfigDevice(); + /** + * @Description Whether the device is a 2.4G device. + * + * @param frequency(in) + * @Return success : true failed : false + */ + bool Whether24GDevice(int frequency); + /** + * @Description Whether the device is a 5G device. + * + * @param frequency(in) + * @Return success : true failed : false + */ + bool Whether5GDevice(int frequency); +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h index 1149ad62b..71243031f 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_define.h @@ -62,8 +62,8 @@ namespace Wifi { #define BSSID_LEN 17 #define KEY_LEN 128 #define SSID_LEN 30 -#define MIN_RSSI -100 -#define MAX_RSSI -55 +#define VALUE_LIMIT_MIN_RSSI (-100) +#define VALUE_LIMIT_MAX_RSSI (-55) #define WPA_BLOCK_LIST_CLEAR_EVENT 0x4001 #define NETWORK_SELECTED_BY_THE_USER 1 #define NETWORK_SELECTED_FOR_CONNECTION_MANAGEMENT 0 diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_device_appraisal.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_device_appraisal.h new file mode 100644 index 000000000..fefd7193b --- /dev/null +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_device_appraisal.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef OHOS_WIFI_NETWORAPPRAISAL_H +#define OHOS_WIFI_NETWORAPPRAISAL_H + +#include +#include "wifi_errcode.h" +#include "wifi_msg.h" +#include "log_helper.h" +#include "sta_define.h" + +namespace OHOS { +namespace Wifi { +static const int MIN_24_FREQUENCY = 2400; +static const int MAX_24_FREQUENCY = 2500; +static const int MIN_5_FREQUENCY = 5000; +static const int MAX_5_FREQUENCY = 5900; +class StaDeviceAppraisal { +public: + virtual ~StaDeviceAppraisal() + {} + + virtual ErrCode DeviceAppraisals( + WifiDeviceConfig &electedDevice, std::vector &scanResults, WifiLinkedInfo &info) = 0; +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_dhcp_server.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_dhcp_server.cpp index 5a13475f9..9e4c373b5 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_dhcp_server.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_dhcp_server.cpp @@ -15,9 +15,8 @@ #include "sta_dhcp_server.h" #include "securec.h" #include "if_config.h" - -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_DHCP_SERVER" +#include "wifi_logger.h" +DEFINE_WIFILOG_LABEL("StaDhcpServer"); const std::string IPV4_DNS1 = "8.8.8.8"; const std::string IPV4_DNS2 = "8.8.4.4"; @@ -44,26 +43,26 @@ StaDhcpServer::StaDhcpServer(DhcpResultHandler handler) StaDhcpServer::~StaDhcpServer() { - LOGI("StaDhcpServer::~StaDhcpServer enter"); + WIFI_LOGI("StaDhcpServer::~StaDhcpServer enter"); ExitDhcpThread(); - LOGI("StaDhcpServer::~StaDhcpServer complete"); + WIFI_LOGI("StaDhcpServer::~StaDhcpServer complete"); } void StaDhcpServer::RunDhcpThreadFunc() { - LOGE("enter runDhcpThreadFunc\n"); + WIFI_LOGE("enter runDhcpThreadFunc\n"); if (StartDhcpServer() != 0) { - LOGE("startDhcpServer error\n"); + WIFI_LOGE("startDhcpServer error\n"); return; } while (1) { std::unique_lock lck(mMutex); while (!isWakeDhcp) { - LOGE("waiting for sigal\n"); + WIFI_LOGE("waiting for sigal\n"); mCondition.wait(lck); } - LOGE("unlock and start dhcp client\n"); + WIFI_LOGE("unlock and start dhcp client\n"); if (isExitDhcpThread) { break; } @@ -80,7 +79,7 @@ void StaDhcpServer::RunDhcpThreadFunc() close(serverSockfd); serverSockfd = -1; } - LOGI("dhcp thread over\n"); + WIFI_LOGI("dhcp thread over\n"); } void StaDhcpServer::SetDhcpParam() @@ -113,7 +112,7 @@ ErrCode StaDhcpServer::StartDhcpServer() } serverSockfd = socket(AF_UNIX, SOCK_STREAM, 0); if (serverSockfd < 0) { - LOGE("startDhcpServer: failed to create server socket!"); + WIFI_LOGE("startDhcpServer: failed to create server socket!"); return ErrCode::WIFI_OPT_FAILED; } bool bFlag = false; @@ -122,16 +121,16 @@ ErrCode StaDhcpServer::StartDhcpServer() timeout.tv_sec = DHCP_ACCEPT_DELAY; timeout.tv_usec = 0; if (setsockopt(serverSockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(struct timeval)) == -1) { - LOGE("startDhcpServer: failed to set accept timeout!"); + WIFI_LOGE("startDhcpServer: failed to set accept timeout!"); break; } if (bind(serverSockfd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)) < 0) { - LOGE("startDhcpServer: failed to bind dhcp server socket!"); + WIFI_LOGE("startDhcpServer: failed to bind dhcp server socket!"); break; } if (listen(serverSockfd, MAX_LISTEN) < 0) { - LOGE("startDhcpServer: failed to listen!"); + WIFI_LOGE("startDhcpServer: failed to listen!"); break; } bFlag = true; @@ -147,20 +146,20 @@ ErrCode StaDhcpServer::StartDhcpServer() ErrCode StaDhcpServer::CheckDhcpInfo(int &dhcpResultIndex) { if (mReceive.iptype > StaIpType::IPTYPE_IPV6) { - LOGE("CheckDhcpInfo ip type error\n"); + WIFI_LOGE("CheckDhcpInfo ip type error\n"); dhcpResultIndex = StaIpType::IPTYPE_IPV4; return ErrCode::WIFI_OPT_FAILED; } else if (mReceive.iptype == StaIpType::IPTYPE_IPV4) { - LOGE("CheckDhcpInfo ip type ipv4\n"); + WIFI_LOGE("CheckDhcpInfo ip type ipv4\n"); dhcpResultIndex = StaIpType::IPTYPE_IPV4; } else { - LOGE("CheckDhcpInfo ip type ipv6\n"); + WIFI_LOGE("CheckDhcpInfo ip type ipv6\n"); dhcpResultIndex = StaIpType::IPTYPE_IPV6; } if (mReceive.datasize != (sizeof(mReceive.iptype) + strlen(mReceive.ip) + strlen(mReceive.gateway) + strlen(mReceive.subnet) + strlen(mReceive.dns) + sizeof(mReceive.leasetime))) { - LOGE("CheckDhcpInfo datasize error\n"); + WIFI_LOGE("CheckDhcpInfo datasize error\n"); return ErrCode::WIFI_OPT_FAILED; } @@ -193,7 +192,7 @@ void StaDhcpServer::StartDhcpClient() /* The subprocess starts the DHCP_CLIENT_FILE process. */ if (execv(args[0], const_cast(args))) { - LOGE("execv %s failed!\n", args[0]); + WIFI_LOGE("execv %s failed!\n", args[0]); } _exit(-1); } @@ -207,7 +206,7 @@ void StaDhcpServer::CreateSocketServer() for (int index = 0; index < ipNumber; index++) { clientSockfd = accept(serverSockfd, (struct sockaddr *)&clientAddr, &clientLen); if (clientSockfd == -1) { - LOGE("startDhcpClient accept failed\n"); + WIFI_LOGE("startDhcpClient accept failed\n"); continue; } @@ -253,7 +252,7 @@ ErrCode StaDhcpServer::ForkForDhcp() { pid_t pid = fork(); if (pid < 0) { - LOGE("In StaDhcpServer fork failed."); + WIFI_LOGE("In StaDhcpServer fork failed."); return ErrCode::WIFI_OPT_FAILED; } else if (pid == 0) { StartDhcpClient(); @@ -267,7 +266,7 @@ void StaDhcpServer::KillDhcpClient() const { FILE *pp = popen("./dhcpc -x", "r"); if (pp == nullptr) { - LOGE("In StaDhcpServer openDhcpClient popen failed!\n"); + WIFI_LOGE("In StaDhcpServer openDhcpClient popen failed!\n"); return; } @@ -279,7 +278,7 @@ ErrCode StaDhcpServer::InitDhcpThread() { pDealDhcpThread = new (std::nothrow)std::thread(&StaDhcpServer::RunDhcpThreadFunc, this); if (pDealDhcpThread == nullptr) { - LOGE("In StaDhcpServer create message start Dhcp server thread failed!"); + WIFI_LOGE("In StaDhcpServer create message start Dhcp server thread failed!"); return ErrCode::WIFI_OPT_FAILED; } return ErrCode::WIFI_OPT_SUCCESS; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp index 9c445409b..dc51821d4 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.cpp @@ -15,9 +15,9 @@ #include "sta_interface.h" #include "wifi_log.h" #include "define.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_INTERFACE" +DEFINE_WIFILOG_LABEL("StaInterface"); namespace OHOS { namespace Wifi { @@ -26,7 +26,7 @@ StaInterface::StaInterface() : pStaService(nullptr) StaInterface::~StaInterface() { - LOGI("StaInterface::~StaInterface"); + WIFI_LOGI("StaInterface::~StaInterface"); if (pStaService != nullptr) { delete pStaService; } @@ -34,27 +34,27 @@ StaInterface::~StaInterface() int StaInterface::Init(WifiMessageQueue *mqUp) { - LOGD("Enter StaInterface::Init.\n"); + WIFI_LOGD("Enter StaInterface::Init.\n"); if (mqUp == nullptr) { - LOGE("mqUp is null.\n"); + WIFI_LOGE("mqUp is null.\n"); return -1; } pStaService = new (std::nothrow) StaService(); if (pStaService == nullptr) { - LOGE("New StaService failed.\n"); + WIFI_LOGE("New StaService failed.\n"); return -1; } if (pStaService->InitStaService(mqUp) != WIFI_OPT_SUCCESS) { - LOGE("InitStaService failed.\n"); + WIFI_LOGE("InitStaService failed.\n"); delete pStaService; pStaService = nullptr; return -1; } if (pStaService->EnableWifi() != WIFI_OPT_SUCCESS) { - LOGE("EnableWifi failed.\n"); + WIFI_LOGE("EnableWifi failed.\n"); UnInit(); return -1; } @@ -78,10 +78,10 @@ int StaInterface::InitStaHandleMap() int StaInterface::UnInit() { - LOGD("Enter StaInterface::UnInit.\n"); + WIFI_LOGD("Enter StaInterface::UnInit.\n"); int ret = 0; if (pStaService->DisableWifi() != WIFI_OPT_SUCCESS) { - LOGD("DisableWifi failed.\n"); + WIFI_LOGD("DisableWifi failed.\n"); return -1; } @@ -90,9 +90,9 @@ int StaInterface::UnInit() int StaInterface::PushMsg(WifiRequestMsgInfo *requestMsg) { - LOGD("Enter StaInterface::PushMsg\n"); + WIFI_LOGD("Enter StaInterface::PushMsg\n"); if (requestMsg == nullptr) { - LOGE("requestMsg is null.\n"); + WIFI_LOGE("requestMsg is null.\n"); return -1; } @@ -108,7 +108,7 @@ int StaInterface::PushMsg(WifiRequestMsgInfo *requestMsg) void StaInterface::WifiStaCmdConnectReq(const WifiRequestMsgInfo *requestMsg) { - LOGD("Enter StaInterface::WifiStaCmdConnectReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdConnectReq.\n"); if (requestMsg->params.argInt >= 0) { pStaService->ConnectTo(requestMsg->params.argInt); @@ -120,72 +120,72 @@ void StaInterface::WifiStaCmdConnectReq(const WifiRequestMsgInfo *requestMsg) void StaInterface::WifiStaCmdReconnectReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); } - LOGD("Enter StaInterface::WifiStaCmdReconnectReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdReconnectReq.\n"); pStaService->ReConnect(); } void StaInterface::WifiStaCmdReassociateReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); } - LOGD("Enter StaInterface::WifiStaCmdReassociateReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdReassociateReq.\n"); pStaService->ReAssociate(); } void StaInterface::WifiStaCmdDisconnectReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); } - LOGD("Enter StaInterface::WifiStaCmdDisconnectReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdDisconnectReq.\n"); pStaService->Disconnect(); } void StaInterface::WifiStaCmdRemoveDeviceReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); return; } - LOGD("Enter StaInterface::WifiStaCmdRemoveDeviceReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdRemoveDeviceReq.\n"); pStaService->RemoveDeviceConfig(requestMsg->params.argInt); } void StaInterface::WifiStaCmdStartWpsReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); return; } - LOGD("Enter StaInterface::WifiStaCmdStartWpsReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdStartWpsReq.\n"); pStaService->StartWps(requestMsg->params.wpsConfig); } void StaInterface::WifiStaCmdCancelWpsReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); } - LOGD("Enter StaInterface::WifiStaCmdCancelWpsReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdCancelWpsReq.\n"); pStaService->CancelWps(); } void StaInterface::WifiStaCmdConnectManagerReq(const WifiRequestMsgInfo *requestMsg) { - LOGI("Connection management information transferred successfully.\n"); + WIFI_LOGI("Connection management information transferred successfully.\n"); pStaService->SyncLinkInfo(requestMsg->params.scanResults); - pStaService->ConnectivityManager(requestMsg->params.scanResults); + pStaService->AutoConnectService(requestMsg->params.scanResults); } void StaInterface::WifiStaCmdSetCountryCodeReq(const WifiRequestMsgInfo *requestMsg) { if (requestMsg == nullptr) { - LOGE("requestMsg is null\n"); + WIFI_LOGE("requestMsg is null\n"); } - LOGD("Enter StaInterface::WifiStaCmdSetCountryCodeReq.\n"); + WIFI_LOGD("Enter StaInterface::WifiStaCmdSetCountryCodeReq.\n"); pStaService->SetCountryCode(); } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h index 65e7e9d2c..6cf6ee2da 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_interface.h @@ -99,8 +99,8 @@ private: */ void WifiStaCmdCancelWpsReq(const WifiRequestMsgInfo *requestMsg); /** - * @Description: Start the process of ConnectivityManager when - receive the opening ConnectivityManager request. + * @Description: Start the process of StaAutoConnectService when + receive the opening StaAutoConnectService request. * * @param requestMsg - request message */ diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp index f3c499fbe..be310ea34 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.cpp @@ -15,9 +15,9 @@ #include "sta_monitor.h" #include "wifi_idl_define.h" #include "sta_define.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_MONITOR" +DEFINE_WIFILOG_LABEL("StaMonitor"); namespace OHOS { namespace Wifi { @@ -26,12 +26,12 @@ StaMonitor::StaMonitor() : pStaStateMachine(nullptr) StaMonitor::~StaMonitor() { - LOGI("StaMonitor::~StaMonitor"); + WIFI_LOGI("StaMonitor::~StaMonitor"); } ErrCode StaMonitor::InitStaMonitor() { - LOGI("Enter StaMonitor::InitStaMonitor.\n"); + WIFI_LOGI("Enter StaMonitor::InitStaMonitor.\n"); WifiEventCallback callBack; callBack.onConnectChanged = &(StaMonitor::OnConnectChangedCallBack); @@ -41,7 +41,7 @@ ErrCode StaMonitor::InitStaMonitor() callBack.onWpsTimeOut = &(StaMonitor::OnWPsTimeOutCallBack); callBack.pInstance = static_cast(this); if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack) != WIFI_IDL_OPT_OK) { - LOGE("StaMonitor::InitStaMonitor RegisterStaEventCallback failed!"); + WIFI_LOGE("StaMonitor::InitStaMonitor RegisterStaEventCallback failed!"); return WIFI_OPT_FAILED; } return WIFI_OPT_SUCCESS; @@ -50,7 +50,7 @@ ErrCode StaMonitor::UnInitStaMonitor() const { WifiEventCallback callBack; if (WifiStaHalInterface::GetInstance().RegisterStaEventCallback(callBack) != WIFI_IDL_OPT_OK) { - LOGE("StaMonitor::~StaMonitor RegisterStaEventCallback failed!"); + WIFI_LOGE("StaMonitor::~StaMonitor RegisterStaEventCallback failed!"); } return WIFI_OPT_SUCCESS; } @@ -62,18 +62,18 @@ void StaMonitor::SetStateMachine(StaStateMachine *paraStaStateMachine) } void StaMonitor::OnConnectChangedCallBack(int status, int networkId, char *bssid, void *pInstance) { - LOGI("OnConnectChangedCallBack() status:%{public}d,networkId=%{public}d,bssid=%s\n", + WIFI_LOGI("OnConnectChangedCallBack() status:%{public}d,networkId=%{public}d,bssid=%s\n", status, networkId, bssid); if (pInstance == nullptr) { - LOGE("OnConnectChangedCallBack pInstance is null.\n"); + WIFI_LOGE("OnConnectChangedCallBack pInstance is null.\n"); return; } auto pStaMonitor = static_cast(pInstance); if (pStaMonitor->pStaStateMachine == nullptr) { - LOGE("OnConnectChangedCallBack pStaMonitor->pStaStateMachine is null.\n"); + WIFI_LOGE("OnConnectChangedCallBack pStaMonitor->pStaStateMachine is null.\n"); return; } switch (status) { @@ -92,15 +92,15 @@ void StaMonitor::OnConnectChangedCallBack(int status, int networkId, char *bssid void StaMonitor::OnWpaStateChangedCallBack(int status, void *pInstance) { - LOGI("OnWpaStateChangedCallBack() status:%{public}d\n", status); + WIFI_LOGI("OnWpaStateChangedCallBack() status:%{public}d\n", status); if (pInstance == nullptr) { - LOGE("OnWpaStateChangedCallBack pInstance is null.\n"); + WIFI_LOGE("OnWpaStateChangedCallBack pInstance is null.\n"); return; } auto pStaMonitor = static_cast(pInstance); if (pStaMonitor->pStaStateMachine == nullptr) { - LOGE("OnWpaStateChangedCallBack pStaMonitor->pStaStateMachine is null.\n"); + WIFI_LOGE("OnWpaStateChangedCallBack pStaMonitor->pStaStateMachine is null.\n"); return; } /* Notification state machine wpa state changed event. */ @@ -109,20 +109,20 @@ void StaMonitor::OnWpaStateChangedCallBack(int status, void *pInstance) void StaMonitor::OnWpaSsidWrongKeyCallBack(int status, void *pInstance) { - LOGI("OnWpaSsidWrongKeyCallBack() status:%{public}d\n", status); + WIFI_LOGI("OnWpaSsidWrongKeyCallBack() status:%{public}d\n", status); if (pInstance == nullptr) { - LOGE("OnWpaSsidWrongKeyCallBack pInstance is null.\n"); + WIFI_LOGE("OnWpaSsidWrongKeyCallBack pInstance is null.\n"); return; } auto pStaMonitor = static_cast(pInstance); if (pStaMonitor->pStaStateMachine == nullptr) { - LOGE("OnWpaSsidWrongKeyCallBack pStaMonitor->pStaStateMachine is null.\n"); + WIFI_LOGE("OnWpaSsidWrongKeyCallBack pStaMonitor->pStaStateMachine is null.\n"); return; } if (status != 1) { - LOGE("OnWpaSsidWrongKeyCallBack error"); + WIFI_LOGE("OnWpaSsidWrongKeyCallBack error"); return; } /* Notification state machine wpa password wrong event. */ @@ -130,15 +130,15 @@ void StaMonitor::OnWpaSsidWrongKeyCallBack(int status, void *pInstance) } void StaMonitor::OnWpsPbcOverlapCallBack(int status, void *pInstance) { - LOGI("OnWpsPbcOverlapCallBack() statue:%{public}d\n", status); + WIFI_LOGI("OnWpsPbcOverlapCallBack() statue:%{public}d\n", status); if (pInstance == nullptr) { - LOGE("OnWpsPbcOverlapCallBack pInstance is null.\n"); + WIFI_LOGE("OnWpsPbcOverlapCallBack pInstance is null.\n"); return; } auto pStaMonitor = static_cast(pInstance); if (pStaMonitor->pStaStateMachine == nullptr) { - LOGE("OnWpsPbcOverlapCallBack pStaMonitor->pStaStateMachine is null.\n"); + WIFI_LOGE("OnWpsPbcOverlapCallBack pStaMonitor->pStaStateMachine is null.\n"); return; } /* Notification state machine WPS overlap event. */ @@ -147,15 +147,15 @@ void StaMonitor::OnWpsPbcOverlapCallBack(int status, void *pInstance) void StaMonitor::OnWPsTimeOutCallBack(int status, void *pInstance) { - LOGI("OnWpsTimeOutCallBack() statue:%{public}d\n", status); + WIFI_LOGI("OnWpsTimeOutCallBack() statue:%{public}d\n", status); if (pInstance == nullptr) { - LOGE("OnWpsTimeOutCallBack pInstance is null.\n"); + WIFI_LOGE("OnWpsTimeOutCallBack pInstance is null.\n"); return; } auto pStaMonitor = static_cast(pInstance); if (pStaMonitor->pStaStateMachine == nullptr) { - LOGE("OnWpsTimeOutCallBack pStaMonitor->pStaStateMachine is null.\n"); + WIFI_LOGE("OnWpsTimeOutCallBack pStaMonitor->pStaStateMachine is null.\n"); return; } /* Notification state machine WPS timeout event */ diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h index ab213b1b1..e3ae25e55 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_monitor.h @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #ifndef OHOS_STA_MONITOR_H #define OHOS_STA_MONITOR_H @@ -21,8 +20,6 @@ namespace OHOS { namespace Wifi { -static const int MAX_DATA_SIZE = 10; - class StaMonitor { public: /** diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_check.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_check.cpp index ae809df3e..6ec421bff 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_check.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_check.cpp @@ -14,9 +14,9 @@ */ #include "sta_network_check.h" #include "if_config.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_NET_CHECK" +DEFINE_WIFILOG_LABEL("StaNetworkCheck"); namespace OHOS { namespace Wifi { @@ -32,14 +32,14 @@ StaNetworkCheck::StaNetworkCheck(NetStateHandler handle) StaNetworkCheck::~StaNetworkCheck() { - LOGI("StaNetworkCheck::~StaNetworkCheck enter\n"); + WIFI_LOGI("StaNetworkCheck::~StaNetworkCheck enter\n"); ExitNetCheckThread(); - LOGI("StaNetworkCheck::~StaNetworkCheck complete\n"); + WIFI_LOGI("StaNetworkCheck::~StaNetworkCheck complete\n"); } void StaNetworkCheck::HttpDetection() { - LOGI("Enter httpDetection"); + WIFI_LOGI("Enter httpDetection"); /* Detect portal hotspot and send message to InterfaceSeervice if result is yes. */ HttpRequest httpRequest; std::string httpReturn; @@ -47,7 +47,7 @@ void StaNetworkCheck::HttpDetection() if (httpRequest.HttpGet(httpMsg, httpReturn) == 0) { if (httpReturn.find("204") != std::string::npos) { - LOGE("This network is normal!"); + WIFI_LOGE("This network is normal!"); if ((lastNetState != NETWORK_STATE_WORKING) && (isExitNetCheckThread == false) && (isStopNetCheck == false)) { netStateHandler(StaNetState::NETWORK_STATE_WORKING); @@ -56,11 +56,11 @@ void StaNetworkCheck::HttpDetection() return; } else { /* Callback result to InterfaceService. */ - LOGI("This network is portal AP, need certification!"); + WIFI_LOGI("This network is portal AP, need certification!"); return; } } - LOGE("This network cant online!"); + WIFI_LOGE("This network cant online!"); if ((lastNetState != NETWORK_STATE_NOWORKING) && (isExitNetCheckThread == false) && (isStopNetCheck == false)) { netStateHandler(StaNetState::NETWORK_STATE_NOWORKING); } @@ -69,16 +69,16 @@ void StaNetworkCheck::HttpDetection() void StaNetworkCheck::RunNetCheckThreadFunc() { - LOGI("enter RunNetCheckThreadFunc!\n"); + WIFI_LOGI("enter RunNetCheckThreadFunc!\n"); for (;;) { std::unique_lock lck(mMutex); while (isStopNetCheck) { - LOGI("waiting for sigal\n"); + WIFI_LOGI("waiting for sigal\n"); mCondition.wait(lck); } if (isExitNetCheckThread) { - LOGI("break the loop\n"); + WIFI_LOGI("break the loop\n"); break; } lck.unlock(); @@ -91,7 +91,7 @@ ErrCode StaNetworkCheck::InitNetCheckThread() { pDealNetCheckThread = new (std::nothrow) std::thread(&StaNetworkCheck::RunNetCheckThreadFunc, this); if (pDealNetCheckThread == nullptr) { - LOGE("In StaNetworkCheck start NetCheck thread failed!\n"); + WIFI_LOGE("In StaNetworkCheck start NetCheck thread failed!\n"); return ErrCode::WIFI_OPT_FAILED; } return ErrCode::WIFI_OPT_SUCCESS; @@ -99,14 +99,14 @@ ErrCode StaNetworkCheck::InitNetCheckThread() void StaNetworkCheck::StopNetCheckThread() { - LOGI("enter StopNetCheckThread!\n"); + WIFI_LOGI("enter StopNetCheckThread!\n"); std::unique_lock lck(mMutex); isStopNetCheck = true; } void StaNetworkCheck::SignalNetCheckThread(int ipType) { - LOGI("enter SignalNetCheckThread!\n"); + WIFI_LOGI("enter SignalNetCheckThread!\n"); lastNetState = NETWORK_STATE_UNKNOW; currentIpType = ipType; isStopNetCheck = false; diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_speed.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_speed.cpp index 6081c3e95..6e14659be 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_speed.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_network_speed.cpp @@ -13,9 +13,9 @@ * limitations under the License. */ #include "sta_network_speed.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_NET_SPEED" +DEFINE_WIFILOG_LABEL("StaNetWorkSpeed"); namespace OHOS { namespace Wifi { @@ -24,12 +24,12 @@ StaNetWorkSpeed::StaNetWorkSpeed() StaNetWorkSpeed::~StaNetWorkSpeed() { - LOGI("StaNetWorkSpeed::~StaNetWorkSpeed enter"); + WIFI_LOGI("StaNetWorkSpeed::~StaNetWorkSpeed enter"); } void StaNetWorkSpeed::GetNetSpeed(std::string &strRx, std::string &strTx) { - LOGE("enter GetNetSpeed\n"); + WIFI_LOGE("enter GetNetSpeed\n"); long rxBytesPre = 0; long txBytesPre = 0; long rxBytesNext = 0; @@ -59,8 +59,8 @@ void StaNetWorkSpeed::GetNetSpeed(std::string &strRx, std::string &strTx) strTx = std::to_string((txBytesNext - txBytesPre) / MAXIMUM_BYTE); strTx += "KB/s"; } - LOGI("GetNetSpeed strRx = %{public}s\n", strRx.c_str()); - LOGI("GetNetSpeed strTx = %{public}s\n", strTx.c_str()); + WIFI_LOGI("GetNetSpeed strRx = %{public}s\n", strRx.c_str()); + WIFI_LOGI("GetNetSpeed strTx = %{public}s\n", strTx.c_str()); } std::vector StaNetWorkSpeed::SplitString(std::string source, const std::string delim) diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp new file mode 100644 index 000000000..8352badc7 --- /dev/null +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "sta_saved_device_appraisal.h" +#include "wifi_logger.h" + +DEFINE_WIFILOG_LABEL("StaSavedDeviceAppraisal"); + +#define BINARY_CODE 0001 +#define LAST_SELECTION_SCORE_DECAY_S 300 +#define MAX(A, B) (((A) >= (B)) ? (A) : (B)) +namespace OHOS { +namespace Wifi { +StaSavedDeviceAppraisal::StaSavedDeviceAppraisal(bool supportFmRoamingFlag) + : signalScorePerLevel(WifiSettings::GetInstance().GetscoretacticsScoreSlope()), + signalBaseScore(WifiSettings::GetInstance().GetscoretacticsInitScore()), + sameBssidScore(WifiSettings::GetInstance().GetscoretacticsSameBssidScore()), + sameDeviceScore(WifiSettings::GetInstance().GetscoretacticsSameNetworkScore()), + frequency5GHzScore(WifiSettings::GetInstance().GetscoretacticsFrequency5GHzScore()), + userSelectedDeviceScore(WifiSettings::GetInstance().GetscoretacticsLastSelectionScore()), + safetyDeviceScore(WifiSettings::GetInstance().GetscoretacticsSecurityScore()), + firmwareRoamFlag(supportFmRoamingFlag) +{} +StaSavedDeviceAppraisal::~StaSavedDeviceAppraisal() +{ + WIFI_LOGI("Enter StaSavedDeviceAppraisal::~StaSavedDeviceAppraisal.\n"); +} + +ErrCode StaSavedDeviceAppraisal::DeviceAppraisals( + WifiDeviceConfig &electedDevice, std::vector &scanInfos, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaSavedDeviceAppraisal::DeviceAppraisals.\n"); + int highestScore = 0; + int sign = 0; + WifiScanInfo scanResultCandidate; + scanResultCandidate.rssi = VALUE_LIMIT_MIN_RSSI; + + for (auto scanInfo : scanInfos) { + if (scanInfo.bssid.size() == 0) { + continue; + } + + WifiDeviceConfig device; + if (WifiSettings::GetInstance().GetDeviceConfig(scanInfo.bssid, DEVICE_CONFIG_INDEX_BSSID, device) == -1) { + WIFI_LOGI("Skip unsaved Network %s.", scanInfo.ssid.c_str()); /* Skipping Unsaved Networks */ + continue; + } + + if (!WhetherSkipDevice(device)) { + continue; + } + + int score = 0; + AppraiseDeviceQuality(score, scanInfo, device, info); + WIFI_LOGI( + "The device %s score is %{public}d.rssi is %{public}d.\n", scanInfo.ssid.c_str(), score, scanInfo.rssi); + + if (score > highestScore || (score == highestScore && scanInfo.rssi > scanResultCandidate.rssi)) { + highestScore = score; + scanResultCandidate.rssi = scanInfo.rssi; + electedDevice = device; + sign = 1; + } + } + if (sign == 1) { + if (info.connState == ConnState::CONNECTED && electedDevice.networkId == info.networkId) { + WifiDeviceConfig networkInfo; + electedDevice = networkInfo; + WIFI_LOGI("The electedDevice is the current connected device. Skip the device selection."); + return WIFI_OPT_FAILED; + } else { + WIFI_LOGI("The device is selected successfully.\n"); + return WIFI_OPT_SUCCESS; + } + } else { + WIFI_LOGI("Skip all scan results.\n"); + return WIFI_OPT_FAILED; + } +} + +bool StaSavedDeviceAppraisal::WhetherSkipDevice(WifiDeviceConfig &device) +{ + /* Skip this type of device and evaluate it by other appraisals */ + if (device.isPasspoint || device.isEphemeral) { + WIFI_LOGI("Skip isPasspoint or isEphemeral Network %s.", device.ssid.c_str()); + return false; + } + + if ((device.status != static_cast(WifiDeviceConfigStatus::ENABLED)) && + (device.status != static_cast(WifiDeviceConfigStatus::CURRENT))) { + WIFI_LOGI("Skip disable Network %s.NetworkId is %{public}d", device.ssid.c_str(), device.networkId); + return false; + } + return true; +} + +void StaSavedDeviceAppraisal::AppraiseDeviceQuality( + int &score, WifiScanInfo &scanInfo, WifiDeviceConfig &device, WifiLinkedInfo &info) +{ + WIFI_LOGI("Enter StaSavedDeviceAppraisal::AppraiseDeviceQuality.\n"); + int rssi = scanInfo.rssi; + /* Converts a signal to a grid number */ + int signalStrength = CalculateSignalBars(rssi, MAX_SIGNAL_BAR_NUM); + /* Signal strength score */ + score += signalBaseScore + signalStrength * signalScorePerLevel; + WIFI_LOGI("signalstrength score is %{public}d.\n", score); + + /* 5 GHz frequency band: bonus point */ + if (Whether5GDevice(scanInfo.frequency)) { + score += frequency5GHzScore; + WIFI_LOGI("5G score is %{public}d.\n", frequency5GHzScore); + } + + /* Bonus points for last user selection */ + int userLastSelectedNetworkId = WifiSettings::GetInstance().GetUserLastSelectedNetworkId(); + if (userLastSelectedNetworkId != INVALID_NETWORK_ID && userLastSelectedNetworkId == device.networkId) { + time_t userLastSelectedNetworkTimeVal = WifiSettings::GetInstance().GetUserLastSelectedNetworkTimeVal(); + time_t now = time(0); + time_t timeDifference = now - userLastSelectedNetworkTimeVal; + /* + * Basic score of the device selected by the user: 120. + * One point is deducted from every 5 points since the time when the user + * selects the device. + */ + if (timeDifference > 0) { + int decay = static_cast(timeDifference / LAST_SELECTION_SCORE_DECAY_S); + int bonus = MAX((userSelectedDeviceScore - decay), (0)); + score += bonus; + WIFI_LOGI("lastselected score is %{public}d.\n", bonus); + } + } + /* + * If the current device is the same as the elected device, bonus points + * are added. + */ + if (info.detailedState == DetailedState::WORKING && scanInfo.ssid == info.ssid) { + score += sameDeviceScore; + WIFI_LOGI("samenetwork score is %{public}d.\n", sameDeviceScore); + /* + * When firmware roaming is supported, the same BSSID is added to different + * BSSIDs. + */ + if (firmwareRoamFlag && scanInfo.bssid != info.bssid) { + score += sameBssidScore; + WIFI_LOGI("roamingsupport score is %{public}d.\n", sameBssidScore); + } + } + + if (info.detailedState == DetailedState::WORKING && info.bssid == scanInfo.bssid) { + score += sameBssidScore; + WIFI_LOGI("SameBssid score is %{public}d.\n", sameBssidScore); + } + + if (device.keyMgmt != "NONE" && device.keyMgmt.size() != 0) { + score += safetyDeviceScore; + WIFI_LOGI("security score is %{public}d.\n", safetyDeviceScore); + } +} + +bool StaSavedDeviceAppraisal::Whether5GDevice(int frequency) +{ + if (frequency > MIN_5_FREQUENCY && frequency < MAX_5_FREQUENCY) { + return true; + } else { + return false; + } +} + +int StaSavedDeviceAppraisal::CalculateSignalBars(int rssi, int signalBars) +{ + WIFI_LOGI("Enter StaSavedDeviceAppraisal CalculateSignalBars"); + if (rssi <= VALUE_LIMIT_MIN_RSSI) { + return 0; + } else if (rssi >= VALUE_LIMIT_MAX_RSSI) { + return signalBars - 1; + } else { + float inputRange = (VALUE_LIMIT_MAX_RSSI - VALUE_LIMIT_MIN_RSSI); + float outputRange = (signalBars - 1); + return static_cast(static_cast(rssi - VALUE_LIMIT_MIN_RSSI) * outputRange / inputRange); + } +} +} // namespace Wifi +} // namespace OHOS \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.h new file mode 100644 index 000000000..9ee8ecf14 --- /dev/null +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_saved_device_appraisal.h @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_WIFI_SAVEDDEVICEAPPRAISAL_H +#define OHOS_WIFI_SAVEDDEVICEAPPRAISAL_H + +#include "wifi_log.h" +#include "wifi_settings.h" +#include "sta_device_appraisal.h" + +namespace OHOS { +namespace Wifi { +class StaSavedDeviceAppraisal : public StaDeviceAppraisal { +public: + explicit StaSavedDeviceAppraisal(bool supportFmRoamingFlag); + ~StaSavedDeviceAppraisal() override; + /** + * @Description Evaluate the Saved device from the scanning result and + return the Wi-Fi configuration of the selected device. + * + * @param scanInfos - Scan details list constructed based on the scan result(in) + * @param Info - Current device(in) + * @param electedDevice - elected device(out) + * @Return: Configuration of the selected device; Null if no devices are available in this category + */ + ErrCode DeviceAppraisals( + WifiDeviceConfig &electedDevice, std::vector &scanInfos, WifiLinkedInfo &info) override; + +private: + static const int MAX_SIGNAL_BAR_NUM = 5; + int signalScorePerLevel; + int signalBaseScore; + int sameBssidScore; + int sameDeviceScore; + int frequency5GHzScore; + int userSelectedDeviceScore; + int safetyDeviceScore; + bool firmwareRoamFlag; + + /** + * @Description Scoring mechanism. + * + * @param scanInfo - Scan Information.(in) + * @param device - Saved device.(in) + * @param info - Connection information.(in) + * @param score - score points.(out) + */ + void AppraiseDeviceQuality(int &score, WifiScanInfo &scanInfo, WifiDeviceConfig &device, WifiLinkedInfo &info); + /** + * @Description Signal strength converted to grids. + * + * @param rssi - Signal strength(in) + * @param signalBars - Max Bars(in) + * @Return: signal Bars + */ + + bool WhetherSkipDevice(WifiDeviceConfig &device); + int CalculateSignalBars(int rssi, int signalBars); + /** + * @Description Whether the device is a 5G device. + * + * @param frequency(in) + * @Return success: true; failed: false + */ + bool Whether5GDevice(int frequency); +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp index 5fd4290a9..2bb833d32 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.cpp @@ -13,30 +13,29 @@ * limitations under the License. */ #include "sta_service.h" -#include "wifi_log.h" +#include "wifi_logger.h" #include "sta_define.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_SERVICE" +DEFINE_WIFILOG_LABEL("StaService"); namespace OHOS { namespace Wifi { StaService::StaService() - : pStaStateMachine(nullptr), pStaMonitor(nullptr), msgQueueUp(nullptr), pStaConnectivityManager(nullptr) + : pStaStateMachine(nullptr), pStaMonitor(nullptr), msgQueueUp(nullptr), pStaAutoConnectService(nullptr) {} StaService::~StaService() { - LOGI("StaService::~StaService"); + WIFI_LOGI("StaService::~StaService"); if (pStaMonitor != nullptr) { pStaMonitor->UnInitStaMonitor(); delete pStaMonitor; pStaMonitor = nullptr; } - if (pStaConnectivityManager != nullptr) { - delete pStaConnectivityManager; - pStaConnectivityManager = nullptr; + if (pStaAutoConnectService != nullptr) { + delete pStaAutoConnectService; + pStaAutoConnectService = nullptr; } if (pStaStateMachine != nullptr) { @@ -47,57 +46,57 @@ StaService::~StaService() ErrCode StaService::InitStaService(WifiMessageQueue *pMsgQueueUp) { - LOGI("Enter StaService::InitStaService.\n"); + WIFI_LOGI("Enter StaService::InitStaService.\n"); msgQueueUp = pMsgQueueUp; if (msgQueueUp == nullptr) { - LOGE("msgQueueUp is null.\n"); + WIFI_LOGE("msgQueueUp is null.\n"); return WIFI_OPT_FAILED; } pStaStateMachine = new (std::nothrow) StaStateMachine(); if (pStaStateMachine == nullptr) { - LOGE("Alloc pStaStateMachine failed.\n"); + WIFI_LOGE("Alloc pStaStateMachine failed.\n"); return WIFI_OPT_FAILED; } if (pStaStateMachine->InitStaStateMachine() != WIFI_OPT_SUCCESS) { - LOGE("InitStaStateMachine failed.\n"); + WIFI_LOGE("InitStaStateMachine failed.\n"); return WIFI_OPT_FAILED; } pStaStateMachine->SetResponseQueue(msgQueueUp); pStaMonitor = new (std::nothrow) StaMonitor(); if (pStaMonitor == nullptr) { - LOGE("Alloc pStaMonitor failed.\n"); + WIFI_LOGE("Alloc pStaMonitor failed.\n"); return WIFI_OPT_FAILED; } if (pStaMonitor->InitStaMonitor() != WIFI_OPT_SUCCESS) { - LOGE("InitStaMonitor failed.\n"); + WIFI_LOGE("InitStaMonitor failed.\n"); return WIFI_OPT_FAILED; } pStaMonitor->SetStateMachine(pStaStateMachine); - pStaConnectivityManager = new (std::nothrow) StaConnectivityManager(pStaStateMachine); - if (pStaConnectivityManager == nullptr) { - LOGE("Alloc pStaConnectivityManager failed.\n"); + pStaAutoConnectService = new (std::nothrow) StaAutoConnectService(pStaStateMachine); + if (pStaAutoConnectService == nullptr) { + WIFI_LOGE("Alloc pStaAutoConnectService failed.\n"); return WIFI_OPT_FAILED; } - if (pStaConnectivityManager->InitConnectivityManager() != WIFI_OPT_SUCCESS) { - LOGE("InitConnectivityManager failed.\n"); + if (pStaAutoConnectService->InitAutoConnectService() != WIFI_OPT_SUCCESS) { + WIFI_LOGE("InitAutoConnectService failed.\n"); return WIFI_OPT_FAILED; } - LOGI("Init staservice successfully.\n"); + WIFI_LOGI("Init staservice successfully.\n"); return WIFI_OPT_SUCCESS; } void StaService::NotifyResult(int msgCode) const { - LOGI("Enter StaService::NotifyResult.\n"); + WIFI_LOGI("Enter StaService::NotifyResult.\n"); WifiResponseMsgInfo notifyMsg; notifyMsg.msgCode = msgCode; msgQueueUp->Push(notifyMsg); @@ -106,36 +105,36 @@ void StaService::NotifyResult(int msgCode) const ErrCode StaService::EnableWifi() const { - LOGI("Enter StaService::EnableWifi.\n"); + WIFI_LOGI("Enter StaService::EnableWifi.\n"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_ENABLE_WIFI, STA_CONNECT_MODE); return WIFI_OPT_SUCCESS; } ErrCode StaService::DisableWifi() const { - LOGI("Enter StaService::DisableWifi.\n"); + WIFI_LOGI("Enter StaService::DisableWifi.\n"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_DISABLE_WIFI); return WIFI_OPT_SUCCESS; } ErrCode StaService::ConnectTo(const WifiDeviceConfig &config) const { - LOGI("Enter StaService::ConnectTo.\n"); + WIFI_LOGI("Enter StaService::ConnectTo.\n"); int networkId = -1; WifiDeviceConfig tempDeviceConfig; if (WifiSettings::GetInstance().GetDeviceConfig(config.ssid, DEVICE_CONFIG_INDEX_SSID, tempDeviceConfig) == 0) { - LOGD("A network with the same name already exists in the configuration center!\n"); + WIFI_LOGD("A network with the same name already exists in the configuration center!\n"); networkId = tempDeviceConfig.networkId; tempDeviceConfig = config; tempDeviceConfig.networkId = networkId; - pStaConnectivityManager->TrackBlockBssid(config.bssid, true, 0); + pStaAutoConnectService->EnableOrDisableBssid(config.bssid, true, 0); } else { - LOGD("Connect to a new network\n"); + WIFI_LOGD("Connect to a new network\n"); if (WifiStaHalInterface::GetInstance().GetNextNetworkId(networkId) != WIFI_IDL_OPT_OK) { - LOGE("StaService::ConnectTo GetNextNetworkId failed!"); + WIFI_LOGE("StaService::ConnectTo GetNextNetworkId failed!"); return WIFI_OPT_FAILED; } - LOGI("StaService::ConnectTo GetNextNetworkId succeed!"); + WIFI_LOGI("StaService::ConnectTo GetNextNetworkId succeed!"); tempDeviceConfig = config; tempDeviceConfig.networkId = networkId; } @@ -143,7 +142,7 @@ ErrCode StaService::ConnectTo(const WifiDeviceConfig &config) const /* Add the new network to WifiSettings. */ WifiSettings::GetInstance().AddDeviceConfig(tempDeviceConfig); WifiSettings::GetInstance().SyncDeviceConfig(); - LOGI("keyMgmt is %s", config.keyMgmt.c_str()); + WIFI_LOGI("keyMgmt is %s", config.keyMgmt.c_str()); /* Setting the network to wpa */ WifiIdlDeviceConfig idlConfig; idlConfig.networkId = networkId; @@ -156,33 +155,32 @@ ErrCode StaService::ConnectTo(const WifiDeviceConfig &config) const idlConfig.eap = config.wifiEapConfig.eap; idlConfig.identity = config.wifiEapConfig.identity; idlConfig.password = config.wifiEapConfig.password; - idlConfig.authAlgorithms = config.allowedAuthAlgorithms; idlConfig.wepKeyIdx = config.wepTxKeyIndex; for (int i = 0; i < MAX_WEPKEYS_SIZE; i++) { idlConfig.wepKeys[i] = config.wepKeys[i]; } if (WifiStaHalInterface::GetInstance().SetDeviceConfig(networkId, idlConfig) != WIFI_IDL_OPT_OK) { - LOGE("StaService::ConnectTo SetDeviceConfig failed!"); + WIFI_LOGE("StaService::ConnectTo SetDeviceConfig failed!"); return WIFI_OPT_FAILED; } - LOGI("StaService::ConnectTo SetDeviceConfig succeed!"); + WIFI_LOGI("StaService::ConnectTo SetDeviceConfig succeed!"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_NETWORK, networkId, NETWORK_SELECTED_BY_THE_USER); return WIFI_OPT_SUCCESS; } ErrCode StaService::ConnectTo(int networkId) const { - LOGI("Enter StaService::ConnectTo, networkId is %{public}d.\n", networkId); + WIFI_LOGI("Enter StaService::ConnectTo, networkId is %{public}d.\n", networkId); WifiDeviceConfig config; int ret = WifiSettings::GetInstance().GetDeviceConfig(networkId, config); if (ret != 0) { - LOGE("WifiDeviceConfig is null!"); + WIFI_LOGE("WifiDeviceConfig is null!"); return WIFI_OPT_FAILED; } - pStaConnectivityManager->TrackBlockBssid(config.bssid, true, 0); + pStaAutoConnectService->EnableOrDisableBssid(config.bssid, true, 0); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CONNECT_SAVED_NETWORK, networkId, NETWORK_SELECTED_BY_THE_USER); return WIFI_OPT_SUCCESS; @@ -190,31 +188,31 @@ ErrCode StaService::ConnectTo(int networkId) const ErrCode StaService::ReConnect() const { - LOGI("Enter StaService::ReConnect.\n"); + WIFI_LOGI("Enter StaService::ReConnect.\n"); return WIFI_OPT_SUCCESS; } ErrCode StaService::ReAssociate() const { - LOGI("Enter StaService::ReAssociate.\n"); + WIFI_LOGI("Enter StaService::ReAssociate.\n"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_REASSOCIATE_NETWORK); return WIFI_OPT_SUCCESS; } ErrCode StaService::RemoveDeviceConfig(int networkId) const { - LOGI("Enter StaService::RemoveDeviceConfig.\n"); + WIFI_LOGI("Enter StaService::RemoveDeviceConfig.\n"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_REMOVE_DEVICE_CONFIG, networkId); return WIFI_OPT_SUCCESS; } ErrCode StaService::Disconnect() const { - LOGI("Enter StaService::Disconnect.\n"); + WIFI_LOGI("Enter StaService::Disconnect.\n"); WifiLinkedInfo linkedInfo; WifiSettings::GetInstance().GetLinkedInfo(linkedInfo); - if (pStaConnectivityManager->TrackBlockBssid(linkedInfo.bssid, false, REASON_CODE_AP_UNABLE_TO_HANDLE_NEW_STA)) { - LOGI("The blocklist is updated.\n"); + if (pStaAutoConnectService->EnableOrDisableBssid(linkedInfo.bssid, false, AP_CANNOT_HANDLE_NEW_STA)) { + WIFI_LOGI("The blocklist is updated.\n"); } pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_DISCONNECT); return WIFI_OPT_SUCCESS; @@ -222,10 +220,10 @@ ErrCode StaService::Disconnect() const ErrCode StaService::StartWps(const WpsConfig &config) const { - LOGI("Enter StaService::StartWps.\n"); - InternalMessage *msg = pStaStateMachine->ObtainMessage(); + WIFI_LOGI("Enter StaService::StartWps.\n"); + InternalMessage *msg = pStaStateMachine->CreateMessage(); msg->SetMessageName(WIFI_SVR_CMD_STA_STARTWPS); - msg->SetArg1(static_cast(config.setup)); + msg->SetParam1(static_cast(config.setup)); msg->AddStringMessageBody(config.pin); msg->AddStringMessageBody(config.bssid); pStaStateMachine->SendMessage(msg); @@ -234,28 +232,28 @@ ErrCode StaService::StartWps(const WpsConfig &config) const ErrCode StaService::CancelWps() const { - LOGI("Enter StaService::CanceltWps.\n"); + WIFI_LOGI("Enter StaService::CanceltWps.\n"); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_CANCELWPS); return WIFI_OPT_SUCCESS; } ErrCode StaService::SetCountryCode() const { - LOGI("Enter StaService::SetCountryCode.\n"); + WIFI_LOGI("Enter StaService::SetCountryCode.\n"); pStaStateMachine->SetCountryCode(); return WIFI_OPT_SUCCESS; } -ErrCode StaService::ConnectivityManager(const std::vector &scanResults) +ErrCode StaService::AutoConnectService(const std::vector &scanResults) { - LOGI("Enter StaService::ConnectivityManager.\n"); - pStaConnectivityManager->OnScanResultsReadyHandler(scanResults); + WIFI_LOGI("Enter StaService::AutoConnectService.\n"); + pStaAutoConnectService->OnScanResultsReadyHandler(scanResults); return WIFI_OPT_SUCCESS; } ErrCode StaService::SyncLinkInfo(const std::vector &scanResults) { - LOGI("Enter StaService::SyncLinkInfo.\n"); + WIFI_LOGI("Enter StaService::SyncLinkInfo.\n"); pStaStateMachine->SyncLinkInfo(scanResults); return WIFI_OPT_SUCCESS; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h index d53341b22..ef89d8bce 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_service.h @@ -17,7 +17,7 @@ #define OHOS_WIFI_SERVICE_H #include "wifi_internal_msg.h" -#include "sta_connectivity_manager.h" +#include "sta_auto_connect_service.h" #include "sta_monitor.h" #include "sta_state_machine.h" @@ -131,21 +131,21 @@ public: */ ErrCode SetCountryCode() const; /** - * @Description ConnectivityManager process scan results. + * @Description StaAutoConnectService process scan results. * * @Output: Return operating results to Interface Service after enable wifi successfully through NotifyResult function instead of returning result immediately. * @Return success: WIFI_OPT_SUCCESS failed: WIFI_OPT_FAILED */ - ErrCode ConnectivityManager(const std::vector &scanResults); + ErrCode AutoConnectService(const std::vector &scanResults); ErrCode SyncLinkInfo(const std::vector &scanResults); private: StaStateMachine *pStaStateMachine; StaMonitor *pStaMonitor; WifiMessageQueue *msgQueueUp; - StaConnectivityManager *pStaConnectivityManager; + StaAutoConnectService *pStaAutoConnectService; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp index 3877019c7..118b5eab8 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.cpp @@ -19,9 +19,9 @@ #include "log_helper.h" #include "if_config.h" #include "sta_monitor.h" +#include "wifi_logger.h" -#undef LOG_TAG -#define LOG_TAG "OHWIFI_STA_STATE_MACHINE" +DEFINE_WIFILOG_LABEL("StaStateMachine"); #define PBC_ANY_BSSID "any" const int SLEEPTIME = 3; @@ -46,45 +46,45 @@ StaStateMachine::StaStateMachine() pinCode(0), wpsState(SetupMethod::INVALID), lastConnectToNetworkTimer(-1), - targetRoamBssid(SUPPLICANT_BSSID_ANY), + targetRoamBssid(WPA_BSSID_ANY), currentTpType(IPTYPE_IPV4), isWpsConnect(IsWpsConnected::WPS_INVALID), pDhcpServer(nullptr), pNetSpeed(nullptr), pNetcheck(nullptr), msgQueueUp(nullptr), - pDefaultState(nullptr), + pRootState(nullptr), pInitState(nullptr), pWpaStartingState(nullptr), pWpaStartedState(nullptr), pWpaStoppingState(nullptr), - pConnectState(nullptr), - pDisconnectingState(nullptr), - pDisconnectedState(nullptr), - pApConnectedState(nullptr), + pLinkState(nullptr), + pSeparatingState(nullptr), + pSeparatedState(nullptr), + pApLinkedState(nullptr), pWpsState(nullptr), - pObtainingIpState(nullptr), - pConnectedState(nullptr), - pRoamingState(nullptr) + pGetIpState(nullptr), + pLinkedState(nullptr), + pApRoamingState(nullptr) {} StaStateMachine::~StaStateMachine() { - LOGI("StaStateMachine::~StaStateMachine"); + WIFI_LOGI("StaStateMachine::~StaStateMachine"); StopHandlerThread(); - ParsePointer(pDefaultState); + ParsePointer(pRootState); ParsePointer(pInitState); ParsePointer(pWpaStartingState); ParsePointer(pWpaStartedState); ParsePointer(pWpaStoppingState); - ParsePointer(pConnectState); - ParsePointer(pDisconnectingState); - ParsePointer(pDisconnectedState); - ParsePointer(pApConnectedState); + ParsePointer(pLinkState); + ParsePointer(pSeparatingState); + ParsePointer(pSeparatedState); + ParsePointer(pApLinkedState); ParsePointer(pWpsState); - ParsePointer(pObtainingIpState); - ParsePointer(pConnectedState); - ParsePointer(pRoamingState); + ParsePointer(pGetIpState); + ParsePointer(pLinkedState); + ParsePointer(pApRoamingState); ParsePointer(pDhcpServer); ParsePointer(pNetSpeed); ParsePointer(pNetcheck); @@ -93,9 +93,9 @@ StaStateMachine::~StaStateMachine() /* ---------------------------Initialization functions------------------------------ */ ErrCode StaStateMachine::InitStaStateMachine() { - LOGD("Enter StaStateMachine::InitStaStateMachine.\n"); + WIFI_LOGD("Enter StaStateMachine::InitStaStateMachine.\n"); if (!InitialStateMachine()) { - LOGE("Initial StateMachine failed.\n"); + WIFI_LOGE("Initial StateMachine failed.\n"); return WIFI_OPT_FAILED; } @@ -103,14 +103,14 @@ ErrCode StaStateMachine::InitStaStateMachine() return WIFI_OPT_FAILED; } BuildStateTree(); - SetInitialState(pInitState); - Start(); + SetFirstState(pInitState); + StartStateMachine(); InitStaSMHandleMap(); pDhcpServer = new (std::nothrow) StaDhcpServer(std::bind(&StaStateMachine::HandleDhcpResult, this, std::placeholders::_1)); if (pDhcpServer == nullptr) { - LOGE("pDhcpServer is null\n"); + WIFI_LOGE("pDhcpServer is null\n"); return WIFI_OPT_FAILED; } pDhcpServer->InitDhcpThread(); @@ -118,7 +118,7 @@ ErrCode StaStateMachine::InitStaStateMachine() pNetcheck = new (std::nothrow) StaNetworkCheck(std::bind(&StaStateMachine::HandleNetCheckResult, this, std::placeholders::_1)); if (pNetcheck == nullptr) { - LOGE("pNetcheck is null\n"); + WIFI_LOGE("pNetcheck is null\n"); return WIFI_OPT_FAILED; } pNetcheck->InitNetCheckThread(); @@ -127,10 +127,10 @@ ErrCode StaStateMachine::InitStaStateMachine() ErrCode StaStateMachine::InitStaStates() { - LOGE("Enter InitStaStates\n"); + WIFI_LOGE("Enter InitStaStates\n"); int tmpErrNumber; - pDefaultState = new DefaultState(this); - tmpErrNumber = JudgmentEmpty(pDefaultState); + pRootState = new RootState(); + tmpErrNumber = JudgmentEmpty(pRootState); pInitState = new InitState(this); tmpErrNumber += JudgmentEmpty(pInitState); pWpaStartingState = new WpaStartingState(this); @@ -139,26 +139,26 @@ ErrCode StaStateMachine::InitStaStates() tmpErrNumber += JudgmentEmpty(pWpaStartedState); pWpaStoppingState = new WpaStoppingState(this); tmpErrNumber += JudgmentEmpty(pWpaStoppingState); - pConnectState = new ConnectState(this); - tmpErrNumber += JudgmentEmpty(pConnectState); - pDisconnectingState = new DisconnectingState(this); - tmpErrNumber += JudgmentEmpty(pDisconnectingState); - pDisconnectedState = new DisconnectedState(this); - tmpErrNumber += JudgmentEmpty(pDisconnectedState); - pApConnectedState = new ApConnectedState(this); - tmpErrNumber += JudgmentEmpty(pApConnectedState); - pWpsState = new WpsState(this); + pLinkState = new LinkState(this); + tmpErrNumber += JudgmentEmpty(pLinkState); + pSeparatingState = new SeparatingState(); + tmpErrNumber += JudgmentEmpty(pSeparatingState); + pSeparatedState = new SeparatedState(this); + tmpErrNumber += JudgmentEmpty(pSeparatedState); + pApLinkedState = new ApLinkedState(this); + tmpErrNumber += JudgmentEmpty(pApLinkedState); + pWpsState = new StaWpsState(this); tmpErrNumber += JudgmentEmpty(pWpsState); - pObtainingIpState = new ObtainingIpState(this); - tmpErrNumber += JudgmentEmpty(pObtainingIpState); - pConnectedState = new ConnectedState(this); - tmpErrNumber += JudgmentEmpty(pConnectedState); - pRoamingState = new RoamingState(this); - tmpErrNumber += JudgmentEmpty(pRoamingState); + pGetIpState = new GetIpState(this); + tmpErrNumber += JudgmentEmpty(pGetIpState); + pLinkedState = new LinkedState(); + tmpErrNumber += JudgmentEmpty(pLinkedState); + pApRoamingState = new ApRoamingState(this); + tmpErrNumber += JudgmentEmpty(pApRoamingState); pNetSpeed = new StaNetWorkSpeed(); tmpErrNumber += JudgmentEmpty(pNetSpeed); if (tmpErrNumber != 0) { - LOGE("InitStaStates some one state is null\n"); + WIFI_LOGE("InitStaStates some one state is null\n"); return WIFI_OPT_FAILED; } return WIFI_OPT_SUCCESS; @@ -208,88 +208,84 @@ void StaStateMachine::SetResponseQueue(WifiMessageQueue *pM void StaStateMachine::BuildStateTree() { - AddState(pDefaultState, nullptr); - AddState(pInitState, pDefaultState); - AddState(pWpaStartingState, pDefaultState); - AddState(pWpaStartedState, pDefaultState); - AddState(pConnectState, pWpaStartedState); - AddState(pDisconnectingState, pConnectState); - AddState(pDisconnectedState, pConnectState); - AddState(pApConnectedState, pConnectState); - AddState(pObtainingIpState, pApConnectedState); - AddState(pConnectedState, pApConnectedState); - AddState(pRoamingState, pApConnectedState); - AddState(pWpsState, pConnectState); - AddState(pWpaStoppingState, pDefaultState); -} - -/* --------------------------- state machine default state ------------------------------ */ -StaStateMachine::DefaultState::DefaultState(StaStateMachine *staStateMachine) : State("DefaultState") -{ - pStaStateMachine = staStateMachine; -} + StatePlus(pRootState, nullptr); + StatePlus(pInitState, pRootState); + StatePlus(pWpaStartingState, pRootState); + StatePlus(pWpaStartedState, pRootState); + StatePlus(pLinkState, pWpaStartedState); + StatePlus(pSeparatingState, pLinkState); + StatePlus(pSeparatedState, pLinkState); + StatePlus(pApLinkedState, pLinkState); + StatePlus(pGetIpState, pApLinkedState); + StatePlus(pLinkedState, pApLinkedState); + StatePlus(pApRoamingState, pApLinkedState); + StatePlus(pWpsState, pLinkState); + StatePlus(pWpaStoppingState, pRootState); +} + +/* --------------------------- state machine root state ------------------------------ */ +StaStateMachine::RootState::RootState() : State("RootState") +{} -StaStateMachine::DefaultState::~DefaultState() +StaStateMachine::RootState::~RootState() {} -void StaStateMachine::DefaultState::Enter() +void StaStateMachine::RootState::GoInState() { - LOGI("DefaultState Enter function."); + WIFI_LOGI("RootState GoInState function."); return; } -void StaStateMachine::DefaultState::Exit() +void StaStateMachine::RootState::GoOutState() { - LOGI("DefaultState Exit function."); + WIFI_LOGI("RootState GoOutState function."); return; } -bool StaStateMachine::DefaultState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::RootState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - LOGI("DefaultState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + WIFI_LOGI("RootState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); return true; } /* --------------------------- state machine Init State ------------------------------ */ -StaStateMachine::InitState::InitState(StaStateMachine *staStateMachine) : State("InitState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::InitState::InitState(StaStateMachine *staStateMachine) + : State("InitState"), pStaStateMachine(staStateMachine) +{} StaStateMachine::InitState::~InitState() {} -void StaStateMachine::InitState::Enter() +void StaStateMachine::InitState::GoInState() { - LOGI("InitState Enter function."); - CleanUp(); + WIFI_LOGI("InitState GoInState function."); return; } -void StaStateMachine::InitState::Exit() +void StaStateMachine::InitState::GoOutState() {} -bool StaStateMachine::InitState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::InitState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_START_SUPPLICANT: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->StartWifiProcess(); break; } case WIFI_SVR_CMD_STA_ENABLE_WIFI: { - ret = HANDLED; - pStaStateMachine->operationalMode = msg->GetArg1(); + ret = EXECUTED; + pStaStateMachine->operationalMode = msg->GetParam1(); pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_START_SUPPLICANT); break; } @@ -298,7 +294,7 @@ bool StaStateMachine::InitState::ProcessMessage(InternalMessage *msg) break; case WIFI_SVR_CMD_STA_REMOVE_DEVICE_CONFIG: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->RemoveDeviceConfigProcess(msg); break; } @@ -308,27 +304,24 @@ bool StaStateMachine::InitState::ProcessMessage(InternalMessage *msg) return ret; } -void StaStateMachine::InitState::CleanUp() -{} - void StaStateMachine::StartWifiProcess() { int res = WifiStaHalInterface::GetInstance().StartWifi(); if (res == static_cast(WIFI_IDL_OPT_OK)) { - LOGD("Start wifi successfully!"); + WIFI_LOGD("Start wifi successfully!"); if (WifiStaHalInterface::GetInstance().WpaAutoConnect(false) != WIFI_IDL_OPT_OK) { - LOGI("The automatic Wpa connection is disabled failed."); + WIFI_LOGI("The automatic Wpa connection is disabled failed."); } /* Reload wifi Configurations. */ if (WifiSettings::GetInstance().ReloadDeviceConfig() != 0) { - LOGE("ReloadDeviceConfig() failed!"); + WIFI_LOGE("ReloadDeviceConfig() failed!"); } /* Sets the MAC address of WifiSettings. */ std::string mac; if ((WifiStaHalInterface::GetInstance().GetStaDeviceMacAddress(mac)) != WIFI_IDL_OPT_OK) { - LOGI("GetStaDeviceMacAddress failed!"); + WIFI_LOGI("GetStaDeviceMacAddress failed!"); } else { WifiSettings::GetInstance().SetMacAddress(mac); } @@ -339,56 +332,56 @@ void StaStateMachine::StartWifiProcess() /* Notify the InterfaceService that wifi is enabled successfully. */ NotifyResult(WifiInternalMsgCode::STA_OPEN_RES, static_cast(OperateResState::OPEN_WIFI_SUCCEED)); - /* The current state of StaStateMachine transfers to DisconnectedState after + /* The current state of StaStateMachine transfers to SeparatedState after * enable supplicant. */ - TransitionTo(pDisconnectedState); + SwitchState(pSeparatedState); /* Set country code */ SetCountryCode(); } else { /* Notify the InterfaceService that wifi is failed to enable wifi. */ - LOGE("StartWifi failed, and errcode is %{public}d", res); + WIFI_LOGE("StartWifi failed, and errcode is %{public}d", res); NotifyResult(WifiInternalMsgCode::STA_OPEN_RES, static_cast(OperateResState::OPEN_WIFI_FAILED)); NotifyResult(WifiInternalMsgCode::STA_OPEN_RES, static_cast(OperateResState::OPEN_WIFI_DISABLED)); } } /* --------------------------- state machine WpaStarting State ------------------------------ */ -StaStateMachine::WpaStartingState::WpaStartingState(StaStateMachine *staStateMachine) : State("WpaStartingState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::WpaStartingState::WpaStartingState(StaStateMachine *staStateMachine) + : State("WpaStartingState"), pStaStateMachine(staStateMachine) +{} + StaStateMachine::WpaStartingState::~WpaStartingState() {} void StaStateMachine::WpaStartingState::InitWpsSettings() { - LOGI("WpaStartingState InitWpsSettings function."); + WIFI_LOGI("WpaStartingState InitWpsSettings function."); return; } -void StaStateMachine::WpaStartingState::Enter() +void StaStateMachine::WpaStartingState::GoInState() { - LOGI("WpaStartingState Enter function."); + WIFI_LOGI("WpaStartingState GoInState function."); return; } -void StaStateMachine::WpaStartingState::Exit() +void StaStateMachine::WpaStartingState::GoOutState() { return; } -bool StaStateMachine::WpaStartingState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::WpaStartingState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_SUP_CONNECTION_EVENT: { - ret = HANDLED; - pStaStateMachine->TransitionTo(pStaStateMachine->pWpaStartedState); + ret = EXECUTED; + pStaStateMachine->SwitchState(pStaStateMachine->pWpaStartedState); break; } default: @@ -398,53 +391,52 @@ bool StaStateMachine::WpaStartingState::ProcessMessage(InternalMessage *msg) } /* --------------------------- state machine WpaStarted State ------------------------------ */ -StaStateMachine::WpaStartedState::WpaStartedState(StaStateMachine *staStateMachine) : State("WpaStartedState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::WpaStartedState::WpaStartedState(StaStateMachine *staStateMachine) + : State("WpaStartedState"), pStaStateMachine(staStateMachine) +{} StaStateMachine::WpaStartedState::~WpaStartedState() {} -void StaStateMachine::WpaStartedState::Enter() +void StaStateMachine::WpaStartedState::GoInState() { - LOGD("WpaStartedState Enter function."); + WIFI_LOGD("WpaStartedState GoInState function."); if (pStaStateMachine->operationalMode == STA_CONNECT_MODE) { /* Update the wifi status. */ WifiSettings::GetInstance().SetWifiState(static_cast(WifiState::ENABLING)); - pStaStateMachine->TransitionTo(pStaStateMachine->pDisconnectedState); + pStaStateMachine->SwitchState(pStaStateMachine->pSeparatedState); } else if (pStaStateMachine->operationalMode == STA_DISABLED_MODE) { - pStaStateMachine->TransitionTo(pStaStateMachine->pWpaStoppingState); + pStaStateMachine->SwitchState(pStaStateMachine->pWpaStoppingState); } return; } -void StaStateMachine::WpaStartedState::Exit() +void StaStateMachine::WpaStartedState::GoOutState() { return; } -bool StaStateMachine::WpaStartedState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::WpaStartedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_STOP_SUPPLICANT: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->StopWifiProcess(); break; } case WIFI_SVR_CMD_STA_DISABLE_WIFI: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->SendMessage(WIFI_SVR_CMD_STA_STOP_SUPPLICANT); break; } case WIFI_SVR_CMD_STA_REMOVE_DEVICE_CONFIG: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->RemoveDeviceConfigProcess(msg); break; } @@ -457,20 +449,20 @@ bool StaStateMachine::WpaStartedState::ProcessMessage(InternalMessage *msg) void StaStateMachine::StopWifiProcess() { - LOGD("Enter StaStateMachine::StopWifiProcess.\n"); + WIFI_LOGD("Enter StaStateMachine::StopWifiProcess.\n"); if (lastNetworkId != INVALID_NETWORK_ID) { if (statusId == static_cast(WifiDeviceConfigStatus::DISABLED)) { - LOGD("The network status is DISABLED:1.\n"); + WIFI_LOGD("The network status is DISABLED:1.\n"); WifiSettings::GetInstance().SetDeviceState( lastNetworkId, static_cast(WifiDeviceConfigStatus::DISABLED)); } else if (statusId == static_cast(WifiDeviceConfigStatus::ENABLED)) { - LOGD("The network status is ENABLED:2.\n"); + WIFI_LOGD("The network status is ENABLED:2.\n"); WifiSettings::GetInstance().SetDeviceState( lastNetworkId, static_cast(WifiDeviceConfigStatus::ENABLED)); } WifiSettings::GetInstance().SyncDeviceConfig(); } - LOGD("linkedInfo network = %{public}d", linkedInfo.networkId); + WIFI_LOGD("linkedInfo network = %{public}d", linkedInfo.networkId); /* clear connection information. */ InitWifiLinkedInfo(); @@ -480,12 +472,12 @@ void StaStateMachine::StopWifiProcess() if (errorNo == WIFI_IDL_OPT_OK) { /* Notify result to InterfaceService. */ NotifyResult(WifiInternalMsgCode::STA_CLOSE_RES, static_cast(OperateResState::CLOSE_WIFI_SUCCEED)); - LOGD("Stop WifiProcess successfully!"); + WIFI_LOGD("Stop WifiProcess successfully!"); /* The current state of StaStateMachine transfers to InitState. */ - TransitionTo(pInitState); + SwitchState(pInitState); } else { - LOGE("StopWifiProcess failed,and errcode is %{public}d", errorNo); + WIFI_LOGE("StopWifiProcess failed,and errcode is %{public}d", errorNo); NotifyResult(WifiInternalMsgCode::STA_OPEN_RES, static_cast(OperateResState::CLOSE_WIFI_FAILED)); } } @@ -496,76 +488,74 @@ void StaStateMachine::RemoveDeviceConfigProcess(const InternalMessage *msg) return; } - LOGD("Enter StaStateMachine::RemoveDeviceConfigProcess.\n"); + WIFI_LOGD("Enter StaStateMachine::RemoveDeviceConfigProcess.\n"); /* Remove network configuration. */ - if (WifiStaHalInterface::GetInstance().RemoveDeviceConfig(msg->GetArg1()) == WIFI_IDL_OPT_OK) { - LOGD("Remove device config successfully!"); + if (WifiStaHalInterface::GetInstance().RemoveDeviceConfig(msg->GetParam1()) == WIFI_IDL_OPT_OK) { + WIFI_LOGD("Remove device config successfully!"); if (WifiStaHalInterface::GetInstance().SaveDeviceConfig() != WIFI_IDL_OPT_OK) { - LOGE("RemoveDeviceConfig:SaveDeviceConfig failed!"); + WIFI_LOGE("RemoveDeviceConfig:SaveDeviceConfig failed!"); } - LOGD("RemoveDeviceConfig-SaveDeviceConfig successfully!"); + WIFI_LOGD("RemoveDeviceConfig-SaveDeviceConfig successfully!"); } else { - LOGE("RemoveDeviceConfig failed!"); + WIFI_LOGE("RemoveDeviceConfig failed!"); } /* Remove network configuration directly without notification to InterfaceService. */ - WifiSettings::GetInstance().RemoveDeviceConfig(msg->GetArg1()); + WifiSettings::GetInstance().RemoveDeviceConfig(msg->GetParam1()); if (WifiSettings::GetInstance().SyncDeviceConfig() != 0) { - LOGE("RemoveDeviceConfigProcess-SyncDeviceConfig() failed!"); + WIFI_LOGE("RemoveDeviceConfigProcess-SyncDeviceConfig() failed!"); } } /* --------------------------- state machine WpaStopping State ------------------------------ */ -StaStateMachine::WpaStoppingState::WpaStoppingState(StaStateMachine *staStateMachine) : State("WpaStoppingState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::WpaStoppingState::WpaStoppingState(StaStateMachine *staStateMachine) + : State("WpaStoppingState"), pStaStateMachine(staStateMachine) +{} StaStateMachine::WpaStoppingState::~WpaStoppingState() {} -void StaStateMachine::WpaStoppingState::Enter() +void StaStateMachine::WpaStoppingState::GoInState() { - LOGE("WpaStoppingState Enter function."); - pStaStateMachine->TransitionTo(pStaStateMachine->pInitState); + WIFI_LOGE("WpaStoppingState GoInState function."); + pStaStateMachine->SwitchState(pStaStateMachine->pInitState); return; } -void StaStateMachine::WpaStoppingState::Exit() +void StaStateMachine::WpaStoppingState::GoOutState() {} -bool StaStateMachine::WpaStoppingState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::WpaStoppingState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; - LOGI("DefaultState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + bool ret = NOT_EXECUTED; + WIFI_LOGI("RootState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); return ret; } /* --------------------------- state machine Connect State ------------------------------ */ -StaStateMachine::ConnectState::ConnectState(StaStateMachine *staStateMachine) : State("ConnectState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::LinkState::LinkState(StaStateMachine *staStateMachine) + : State("LinkState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::ConnectState::~ConnectState() +StaStateMachine::LinkState::~LinkState() {} -void StaStateMachine::ConnectState::Enter() +void StaStateMachine::LinkState::GoInState() { - LOGI("ConnectState Enter function."); + WIFI_LOGI("LinkState GoInState function."); return; } -void StaStateMachine::ConnectState::Exit() +void StaStateMachine::LinkState::GoOutState() {} -bool StaStateMachine::ConnectState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::LinkState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; @@ -574,9 +564,9 @@ bool StaStateMachine::ConnectState::ProcessMessage(InternalMessage *msg) auto iter = pStaStateMachine->staSmHandleFuncMap.find(msg->GetMessageName()); if (iter != pStaStateMachine->staSmHandleFuncMap.end()) { (pStaStateMachine->*(iter->second))(msg); - return HANDLED; + return EXECUTED; } - return NOT_HANDLED; + return NOT_EXECUTED; } /* -- state machine Connect State Message processing function -- */ @@ -604,9 +594,9 @@ void StaStateMachine::DealConnectToUserSelectedNetwork(InternalMessage *msg) return; } - LOGI("enter ConnectToUserSelectedNetwork\n"); - int networkId = msg->GetArg1(); - bool forceReconnect = msg->GetArg2(); + WIFI_LOGI("enter ConnectToUserSelectedNetwork\n"); + int networkId = msg->GetParam1(); + bool forceReconnect = msg->GetParam2(); /* Sets network status. */ WifiSettings::GetInstance().EnableNetwork(networkId, forceReconnect); @@ -619,12 +609,11 @@ void StaStateMachine::DealConnectToSelectedNetCmd(InternalMessage *msg) return; } - LOGD("Enter StaStateMachine::DealConnectToSelectedNetCmd.\n"); + WIFI_LOGD("Enter StaStateMachine::DealConnectToSelectedNetCmd.\n"); WifiDeviceConfig config; - targetNetworkId = msg->GetArg1(); + targetNetworkId = msg->GetParam1(); SetRandomMac(targetNetworkId); - SetTargetBssid(config, config.bssid); /* Sets linkedinfo */ linkedInfo.networkId = targetNetworkId; @@ -635,20 +624,20 @@ void StaStateMachine::DealConnectToSelectedNetCmd(InternalMessage *msg) /* test */ std::string countryCode; if (WifiSupplicantHalInterface::GetInstance().WpaGetCountryCode(countryCode) != WIFI_IDL_OPT_OK) { - LOGE("WpaGetCountryCode() failed!"); + WIFI_LOGE("WpaGetCountryCode() failed!"); } - LOGD("WpaGetCountryCode() success countryCode=%{public}s!", countryCode.c_str()); + WIFI_LOGD("WpaGetCountryCode() success countryCode=%{public}s!", countryCode.c_str()); if (WifiStaHalInterface::GetInstance().EnableNetwork(targetNetworkId) == WIFI_IDL_OPT_OK) { - LOGD("EnableNetwork() succeed!"); + WIFI_LOGD("EnableNetwork() succeed!"); int connRes = WifiStaHalInterface::GetInstance().Connect(targetNetworkId); if (connRes == static_cast(WIFI_IDL_OPT_OK)) { - LOGD("Connect() succeed!"); + WIFI_LOGD("Connect() succeed!"); if (WifiStaHalInterface::GetInstance().SaveDeviceConfig() != WIFI_IDL_OPT_OK) { - LOGE("SaveDeviceConfig() failed!"); + WIFI_LOGE("SaveDeviceConfig() failed!"); } - LOGD("SaveDeviceConfig() succeed!"); + WIFI_LOGD("SaveDeviceConfig() succeed!"); /* Update wifi status. */ WifiSettings::GetInstance().SetWifiState(static_cast(WifiState::ENABLING)); @@ -660,21 +649,21 @@ void StaStateMachine::DealConnectToSelectedNetCmd(InternalMessage *msg) NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_CONNECTING)); StartTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT), STA_NETWORK_CONNECTTING_DELAY); } else { - LOGE("Connect failed!"); + WIFI_LOGE("Connect failed!"); NotifyResult( WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_SELECT_NETWORK_FAILED)); } } else { - LOGE("EnableNetwork() failed!"); + WIFI_LOGE("EnableNetwork() failed!"); } } void StaStateMachine::DealConnectTimeOutCmd(InternalMessage *msg) { if (msg == nullptr) { - LOGE("msg is nul\n"); + WIFI_LOGE("msg is nul\n"); } - LOGD("enter DealDisableOneNetCmd\n"); + WIFI_LOGD("enter DealDisableOneNetCmd\n"); DisableNetwork(linkedInfo.networkId); InitWifiLinkedInfo(); WifiSettings::GetInstance().SaveLinkedInfo(linkedInfo); @@ -687,7 +676,7 @@ void StaStateMachine::DealConnectionEvent(InternalMessage *msg) return; } - LOGD("enter DealConnectionEvent"); + WIFI_LOGD("enter DealConnectionEvent"); /* Stop clearing the Wpa_blocklist. */ StopTimer(static_cast(WPA_BLOCK_LIST_CLEAR_EVENT)); StopTimer(static_cast(CMD_NETWORK_CONNECT_TIMEOUT)); @@ -700,26 +689,26 @@ void StaStateMachine::DealConnectionEvent(InternalMessage *msg) /* Notify result to InterfaceService. */ NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_AP_CONNECTED)); - /* The current state of StaStateMachine transfers to ObtainingIpState. */ - TransitionTo(pObtainingIpState); + /* The current state of StaStateMachine transfers to GetIpState. */ + SwitchState(pGetIpState); } void StaStateMachine::DealDisconnectEvent(InternalMessage *msg) { if (msg == nullptr) { - LOGE("msg is null\n"); + WIFI_LOGE("msg is null\n"); } - LOGD("Enter DealDisconnectEvent.\n"); + WIFI_LOGD("Enter DealDisconnectEvent.\n"); pNetcheck->StopNetCheckThread(); if (statusId == static_cast(WifiDeviceConfigStatus::DISABLED)) { - LOGD("The network status is DISABLED:1.\n"); + WIFI_LOGD("The network status is DISABLED:1.\n"); WifiSettings::GetInstance().SetDeviceState(lastNetworkId, static_cast(WifiDeviceConfigStatus::DISABLED)); } else if (statusId == static_cast(WifiDeviceConfigStatus::ENABLED)) { - LOGD("The network status is ENABLED:2.\n"); + WIFI_LOGD("The network status is ENABLED:2.\n"); WifiSettings::GetInstance().SetDeviceState(lastNetworkId, static_cast(WifiDeviceConfigStatus::ENABLED)); } else { - LOGI("The network status is other:%{public}d.\n", statusId); + WIFI_LOGI("The network status is other:%{public}d.\n", statusId); } WifiSettings::GetInstance().SyncDeviceConfig(); @@ -737,15 +726,15 @@ void StaStateMachine::DealDisconnectEvent(InternalMessage *msg) } /* Notify result to InterfaceService. */ NotifyResult(WifiInternalMsgCode::STA_DISCONNECT_RES, static_cast(OperateResState::DISCONNECT_DISCONNECTED)); - TransitionTo(pDisconnectedState); + SwitchState(pSeparatedState); } void StaStateMachine::DealWpaWrongPskEvent(InternalMessage *msg) { if (msg == nullptr) { - LOGE("msg is null\n"); + WIFI_LOGE("msg is null\n"); } - LOGD("enter DealStartWpsCmd\n"); + WIFI_LOGD("enter DealStartWpsCmd\n"); InitWifiLinkedInfo(); WifiSettings::GetInstance().SaveLinkedInfo(linkedInfo); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_PASSWORD_WRONG)); @@ -754,21 +743,21 @@ void StaStateMachine::DealWpaWrongPskEvent(InternalMessage *msg) void StaStateMachine::DealReassociateCmd(InternalMessage *msg) { if (msg == nullptr) { - LOGE("msg is null\n"); + WIFI_LOGE("msg is null\n"); } - LOGD("enter DealStartWpsCmd\n"); + WIFI_LOGD("enter DealStartWpsCmd\n"); /* Obtains the current system time, assigns the timestamp of the last * connection attempt, and prohibits scanning requests within 10 seconds. */ lastConnectToNetworkTimer = static_cast(WifiSettings::GetInstance().GetUserLastSelectedNetworkTimeVal()); - LOGD("the last time connect to network is %{public}d", lastConnectToNetworkTimer); + WIFI_LOGD("the last time connect to network is %{public}d", lastConnectToNetworkTimer); if (WifiStaHalInterface::GetInstance().Reassociate() == WIFI_IDL_OPT_OK) { /* Notify result to InterfaceService */ NotifyResult(WifiInternalMsgCode::STA_REASSOCIATE_RES, static_cast(OperateResState::CONNECT_AP_CONNECTED)); - LOGD("StaStateMachine::ConnectState::ProcessMessage ReAssociate successfully!"); + WIFI_LOGD("StaStateMachine::LinkState::ExecuteStateMsg ReAssociate successfully!"); } else { - LOGE("ReAssociate failed!"); + WIFI_LOGE("ReAssociate failed!"); } } @@ -778,12 +767,12 @@ void StaStateMachine::DealStartWpsCmd(InternalMessage *msg) return; } - LOGD("enter DealStartWpsCmd\n"); + WIFI_LOGD("enter DealStartWpsCmd\n"); RemoveAllDeviceConfigs(); StartWpsMode(msg); if (wpsState == SetupMethod::DISPLAY) { - LOGD("Clear WPA block list every ten second!"); + WIFI_LOGD("Clear WPA block list every ten second!"); SendMessage(WPA_BLOCK_LIST_CLEAR_EVENT); } } @@ -797,7 +786,7 @@ void StaStateMachine::StartWpsMode(InternalMessage *msg) constexpr int multiAp = 0; WifiIdlWpsConfig wpsParam; WpsConfig wpsConfig; - wpsConfig.setup = static_cast(msg->GetArg1()); + wpsConfig.setup = static_cast(msg->GetParam1()); wpsConfig.pin = msg->GetStringFromMessage(); wpsConfig.bssid = msg->GetStringFromMessage(); if (wpsConfig.bssid.length() == 0 || wpsConfig.bssid == PBC_ANY_BSSID) { @@ -808,8 +797,8 @@ void StaStateMachine::StartWpsMode(InternalMessage *msg) wpsParam.bssid = wpsConfig.bssid; } wpsParam.multiAp = multiAp; - LOGI("wpsConfig setup = %{public}d", wpsConfig.setup); - LOGI("wpsParam.AnyFlag = %{public}d, wpsParam.mulitAp = %{public}d, wpsParam.bssid = %s", + WIFI_LOGI("wpsConfig setup = %{public}d", wpsConfig.setup); + WIFI_LOGI("wpsParam.AnyFlag = %{public}d, wpsParam.mulitAp = %{public}d, wpsParam.bssid = %s", wpsParam.anyFlag, wpsParam.multiAp, wpsParam.bssid.c_str()); @@ -817,12 +806,12 @@ void StaStateMachine::StartWpsMode(InternalMessage *msg) if (wpsConfig.setup == SetupMethod::PBC) { if (WifiStaHalInterface::GetInstance().StartWpsPbcMode(wpsParam) == WIFI_IDL_OPT_OK) { wpsState = wpsConfig.setup; - LOGD("StartWpsPbcMode() succeed!"); + WIFI_LOGD("StartWpsPbcMode() succeed!"); /* Notify result to InterfaceService. */ NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_PBC_SUCCEED)); - TransitionTo(pWpsState); + SwitchState(pWpsState); } else { - LOGE("StartWpsPbcMode() failed!"); + WIFI_LOGE("StartWpsPbcMode() failed!"); NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_PBC_FAILED)); } } else if (wpsConfig.setup == SetupMethod::DISPLAY) { @@ -830,14 +819,14 @@ void StaStateMachine::StartWpsMode(InternalMessage *msg) wpsState = wpsConfig.setup; /* Notify result to InterfaceService. */ NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_PIN_SUCCEED)); - LOGD("StartWpsPinMode() succeed! pincode: %d", pinCode); - TransitionTo(pWpsState); + WIFI_LOGD("StartWpsPinMode() succeed! pincode: %d", pinCode); + SwitchState(pWpsState); } else { - LOGE("StartWpsPinMode() failed!"); + WIFI_LOGE("StartWpsPinMode() failed!"); NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_PIN_FAILED)); } } else { - LOGE("Start Wps failed!"); + WIFI_LOGE("Start Wps failed!"); NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_WPS_FAILED)); } } @@ -846,24 +835,25 @@ void StaStateMachine::RemoveAllDeviceConfigs() { std::vector wpaNetworkList; WifiStaHalInterface::GetInstance().GetNetworkList(wpaNetworkList); - for (std::vector::iterator it = wpaNetworkList.begin(); it != wpaNetworkList.end(); it++) { - WifiStaHalInterface::GetInstance().RemoveDeviceConfig(it->id); + for (std::vector::iterator iter = wpaNetworkList.begin(); iter != wpaNetworkList.end(); + ++iter) { + WifiStaHalInterface::GetInstance().RemoveDeviceConfig(iter->id); } WifiStaHalInterface::GetInstance().SaveDeviceConfig(); - LOGD("Remove all device configurations completed!"); + WIFI_LOGD("Remove all device configurations completed!"); return; } void StaStateMachine::DealWpaBlockListClearEvent(InternalMessage *msg) { if (msg != nullptr) { - LOGD("enter DealWpaBlockListClearEvent\n"); + WIFI_LOGD("enter DealWpaBlockListClearEvent\n"); } if (WifiStaHalInterface::GetInstance().WpaBlocklistClear() != WIFI_IDL_OPT_OK) { - LOGE("Clearing the Wpa_blocklist failed\n"); + WIFI_LOGE("Clearing the Wpa_blocklist failed\n"); } StartTimer(static_cast(WPA_BLOCK_LIST_CLEAR_EVENT), BLOCK_LIST_CLEAR_TIMER); - LOGD("Clearing the Wpa_blocklist.\n"); + WIFI_LOGD("Clearing the Wpa_blocklist.\n"); } void StaStateMachine::DealWpsConnectTimeOutEvent(InternalMessage *msg) @@ -872,25 +862,25 @@ void StaStateMachine::DealWpsConnectTimeOutEvent(InternalMessage *msg) return; } - LOGD("enter DealWpsConnectTimeOutEvent\n"); - LOGD("Wps Time out!"); + WIFI_LOGD("enter DealWpsConnectTimeOutEvent\n"); + WIFI_LOGD("Wps Time out!"); DealCancelWpsCmd(msg); /* Notify InterfaceService that WPS time out. */ NotifyResult(WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::WPS_TIME_OUT)); - TransitionTo(pDisconnectedState); + SwitchState(pSeparatedState); } void StaStateMachine::DealCancelWpsCmd(InternalMessage *msg) { if (msg == nullptr) { - LOGE("msg is null\n"); + WIFI_LOGE("msg is null\n"); } StopTimer(static_cast(WPA_BLOCK_LIST_CLEAR_EVENT)); isWpsConnect = IsWpsConnected::WPS_INVALID; if (WifiStaHalInterface::GetInstance().StopWps() == WIFI_IDL_OPT_OK) { - LOGI("CancelWps succeed!"); + WIFI_LOGI("CancelWps succeed!"); /* Notify result to InterfaceService that stop Wps connection successfully. */ if (wpsState == SetupMethod::PBC) { NotifyResult(WifiInternalMsgCode::STA_CANCEL_WPS_RES, static_cast(WpsStartState::STOP_PBC_SUCCEED)); @@ -902,24 +892,24 @@ void StaStateMachine::DealCancelWpsCmd(InternalMessage *msg) SyncAllDeviceConfigs(); if (WifiStaHalInterface::GetInstance().EnableNetwork(lastNetworkId) == WIFI_IDL_OPT_OK) { - LOGI("EnableNetwork success! networkId is %{public}d", lastNetworkId); + WIFI_LOGI("EnableNetwork success! networkId is %{public}d", lastNetworkId); if (WifiStaHalInterface::GetInstance().SaveDeviceConfig() != WIFI_IDL_OPT_OK) { - LOGE("SaveDeviceConfig failed!"); + WIFI_LOGE("SaveDeviceConfig failed!"); } - LOGI("SaveDeviceConfig success!"); + WIFI_LOGI("SaveDeviceConfig success!"); } else { - LOGE("EnableNetwork failed"); + WIFI_LOGE("EnableNetwork failed"); } } } else { - LOGE("CancelWps failed!"); + WIFI_LOGE("CancelWps failed!"); if (wpsState == SetupMethod::PBC) { NotifyResult(WifiInternalMsgCode::STA_CANCEL_WPS_RES, static_cast(WpsStartState::STOP_PBC_FAILED)); } else if (wpsState == SetupMethod::DISPLAY) { NotifyResult(WifiInternalMsgCode::STA_CANCEL_WPS_RES, static_cast(WpsStartState::STOP_PIN_FAILED)); } } - TransitionTo(pDisconnectedState); + SwitchState(pSeparatedState); } void StaStateMachine::DealStartRoamCmd(InternalMessage *msg) @@ -928,7 +918,7 @@ void StaStateMachine::DealStartRoamCmd(InternalMessage *msg) return; } - LOGD("enter DealStartRoamCmd\n"); + WIFI_LOGD("enter DealStartRoamCmd\n"); std::string bssid = msg->GetStringFromMessage(); /* GetDeviceConfig from Configuration center. */ WifiDeviceConfig network; @@ -948,10 +938,10 @@ void StaStateMachine::DealStartRoamCmd(InternalMessage *msg) idlConfig.password = network.wifiEapConfig.password; if (WifiStaHalInterface::GetInstance().SetDeviceConfig(linkedInfo.networkId, idlConfig) != WIFI_IDL_OPT_OK) { - LOGE("DealStartRoamCmd SetDeviceConfig() failed!"); + WIFI_LOGE("DealStartRoamCmd SetDeviceConfig() failed!"); return; } - LOGD("DealStartRoamCmd SetDeviceConfig() succeed!"); + WIFI_LOGD("DealStartRoamCmd SetDeviceConfig() succeed!"); /* Save to Configuration center. */ network.bssid = bssid; @@ -963,28 +953,28 @@ void StaStateMachine::DealStartRoamCmd(InternalMessage *msg) WifiSettings::GetInstance().SaveLinkedInfo(linkedInfo); /* Start roaming */ - TransitionTo(pRoamingState); + SwitchState(pApRoamingState); if (WifiStaHalInterface::GetInstance().Reassociate() != WIFI_IDL_OPT_OK) { - LOGE("START_ROAM-ReAssociate() failed!"); + WIFI_LOGE("START_ROAM-ReAssociate() failed!"); } - LOGI("START_ROAM-ReAssociate() succeeded!"); + WIFI_LOGI("START_ROAM-ReAssociate() succeeded!"); } void StaStateMachine::StartConnectToNetwork(int networkId) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); if (msg == nullptr) { return; } msg->SetMessageName(CMD_START_CONNECT_SELECTED_NETWORK); - msg->SetArg1(networkId); + msg->SetParam1(networkId); SendMessage(msg); } void StaStateMachine::StartRoamToNetwork(std::string bssid) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); if (msg == nullptr) { return; } @@ -996,36 +986,36 @@ void StaStateMachine::StartRoamToNetwork(std::string bssid) void StaStateMachine::OnNetworkConnectionEvent(int networkId, std::string bssid) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); if (msg == nullptr) { return; } msg->SetMessageName(WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT); - msg->SetArg1(networkId); + msg->SetParam1(networkId); msg->AddStringMessageBody(bssid); SendMessage(msg); } void StaStateMachine::SyncLinkInfo(const std::vector &scanResults) { - LOGI("Enter StaStateMachine::SyncLinkInfo.\n"); + WIFI_LOGI("Enter StaStateMachine::SyncLinkInfo.\n"); if (scanResults.empty()) { return; } for (auto scanInfo : scanResults) { if ((scanInfo.ssid == linkedInfo.ssid) && (scanInfo.bssid == linkedInfo.bssid)) { - InternalMessage *msg = ObtainMessage(); + InternalMessage *msg = CreateMessage(); if (msg == nullptr) { break; } msg->SetMessageName(CMD_SYNC_LINKINFO); - msg->SetArg1(scanInfo.level); - msg->SetArg2(scanInfo.frequency); + msg->SetParam1(scanInfo.rssi); + msg->SetParam2(scanInfo.frequency); msg->AddStringMessageBody(scanInfo.capabilities); - LOGI("scanInfo.level == [%{public}d]\n", scanInfo.level); - LOGI("scanInfo.frequency == [%{public}d]\n", scanInfo.frequency); - LOGI("scanInfo.capabilities ==[%{public}s]\n", scanInfo.capabilities.c_str()); + WIFI_LOGI("scanInfo.rssi == [%{public}d]\n", scanInfo.rssi); + WIFI_LOGI("scanInfo.frequency == [%{public}d]\n", scanInfo.frequency); + WIFI_LOGI("scanInfo.capabilities ==[%{public}s]\n", scanInfo.capabilities.c_str()); SendMessage(msg); return; } @@ -1033,73 +1023,71 @@ void StaStateMachine::SyncLinkInfo(const std::vector &scanResults) } /* --------------------------- state machine Disconnecting State ------------------------------ */ -StaStateMachine::DisconnectingState::DisconnectingState(StaStateMachine *staStateMachine) : State("DisconnectingState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::SeparatingState::SeparatingState() + : State("SeparatingState") +{} -StaStateMachine::DisconnectingState::~DisconnectingState() +StaStateMachine::SeparatingState::~SeparatingState() {} -void StaStateMachine::DisconnectingState::Enter() +void StaStateMachine::SeparatingState::GoInState() { - LOGI("DisconnectingState Enter function."); + WIFI_LOGI("SeparatingState GoInState function."); return; } -void StaStateMachine::DisconnectingState::Exit() +void StaStateMachine::SeparatingState::GoOutState() {} -bool StaStateMachine::DisconnectingState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::SeparatingState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; - LOGI("DefaultState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + bool ret = NOT_EXECUTED; + WIFI_LOGI("RootState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); return ret; } /* --------------------------- state machine Disconnected State ------------------------------ */ -StaStateMachine::DisconnectedState::DisconnectedState(StaStateMachine *staStateMachine) : State("DisconnectedState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::SeparatedState::SeparatedState(StaStateMachine *staStateMachine) + : State("SeparatedState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::DisconnectedState::~DisconnectedState() +StaStateMachine::SeparatedState::~SeparatedState() {} -void StaStateMachine::DisconnectedState::Enter() +void StaStateMachine::SeparatedState::GoInState() { - LOGI("DisconnectedState Enter function."); + WIFI_LOGI("SeparatedState GoInState function."); return; } -void StaStateMachine::DisconnectedState::Exit() +void StaStateMachine::SeparatedState::GoOutState() {} -bool StaStateMachine::DisconnectedState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::SeparatedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_COM_STA_SET_COUNTRY_CODE: { - ret = HANDLED; + ret = EXECUTED; /* Get code from config center. */ std::string countryCode; WifiSettings::GetInstance().GetCountryCode(countryCode); - LOGI("WpaSetCountryCode() countryCode=%{public}s!", countryCode.c_str()); + WIFI_LOGI("WpaSetCountryCode() countryCode=%{public}s!", countryCode.c_str()); if (WifiSupplicantHalInterface::GetInstance().WpaSetCountryCode(countryCode) != WIFI_IDL_OPT_OK) { - LOGE("WpaSetCountryCode() failed!"); + WIFI_LOGE("WpaSetCountryCode() failed!"); } - LOGI("WpaSetCountryCode() succeed countryCode=%{public}s!", countryCode.c_str()); + WIFI_LOGI("WpaSetCountryCode() succeed countryCode=%{public}s!", countryCode.c_str()); break; } @@ -1107,8 +1095,8 @@ bool StaStateMachine::DisconnectedState::ProcessMessage(InternalMessage *msg) break; case WIFI_SVR_CMD_STA_ENABLE_WIFI: { - ret = HANDLED; - LOGE("Wifi has already started! start Wifi failed!"); + ret = EXECUTED; + WIFI_LOGE("Wifi has already started! start Wifi failed!"); /* Notify result to InterfaceService. */ pStaStateMachine->NotifyResult( WifiInternalMsgCode::STA_OPEN_RES, static_cast(OperateResState::OPEN_WIFI_OVERRIDE_OPEN_FAILED)); @@ -1128,43 +1116,42 @@ void StaStateMachine::SetCountryCode() } /* --------------------------- state machine ApConnected State ------------------------------ */ -StaStateMachine::ApConnectedState::ApConnectedState(StaStateMachine *staStateMachine) : State("ApConnectedState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::ApLinkedState::ApLinkedState(StaStateMachine *staStateMachine) + : State("ApLinkedState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::ApConnectedState::~ApConnectedState() +StaStateMachine::ApLinkedState::~ApLinkedState() {} -void StaStateMachine::ApConnectedState::Enter() +void StaStateMachine::ApLinkedState::GoInState() { - LOGI("ApConnectedState Enter function."); + WIFI_LOGI("ApLinkedState GoInState function."); return; } -void StaStateMachine::ApConnectedState::Exit() +void StaStateMachine::ApLinkedState::GoOutState() {} -bool StaStateMachine::ApConnectedState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::ApLinkedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { /* The current state of StaStateMachine transfers to DisConnectingState when * receive the disconnecting message. */ case WIFI_SVR_CMD_STA_DISCONNECT: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->DisConnectProcess(); break; } case CMD_SYNC_LINKINFO: { - ret = HANDLED; - pStaStateMachine->linkedInfo.rssi = msg->GetArg1(); - pStaStateMachine->linkedInfo.frequency = msg->GetArg2(); + ret = EXECUTED; + pStaStateMachine->linkedInfo.rssi = msg->GetParam1(); + pStaStateMachine->linkedInfo.frequency = msg->GetParam2(); pStaStateMachine->GetBandFromFreQuencies(pStaStateMachine->linkedInfo.frequency); WifiSettings::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo); std::string mgmt = msg->GetStringFromMessage(); @@ -1172,18 +1159,18 @@ bool StaStateMachine::ApConnectedState::ProcessMessage(InternalMessage *msg) break; } case WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->StopTimer(static_cast(WPA_BLOCK_LIST_CLEAR_EVENT)); - LOGI("Stop clearing wpa block list"); + WIFI_LOGI("Stop clearing wpa block list"); /* Save linkedinfo */ - pStaStateMachine->linkedInfo.networkId = msg->GetArg1(); + pStaStateMachine->linkedInfo.networkId = msg->GetParam1(); pStaStateMachine->linkedInfo.bssid = msg->GetStringFromMessage(); WifiSettings::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo); break; } case CMD_GET_NETWORK_SPEED: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->pNetSpeed->GetNetSpeed( pStaStateMachine->linkedInfo.rxLinkSpeed, pStaStateMachine->linkedInfo.txLinkSpeed); /* Obtains rate */ WifiSettings::GetInstance().SaveLinkedInfo(pStaStateMachine->linkedInfo); @@ -1200,7 +1187,7 @@ void StaStateMachine::SynchronousEncryptionModeAandBand(std::string mgmt) { WifiDeviceConfig config; if (WifiSettings::GetInstance().GetDeviceConfig(linkedInfo.networkId, config) != 0) { - LOGE("GetDeviceConfig failed!"); + WIFI_LOGE("GetDeviceConfig failed!"); } config.band = linkedInfo.band; if (mgmt.find("WPA-PSK") != std::string::npos || mgmt.find("WPA2-PSK") != std::string::npos) { @@ -1232,7 +1219,7 @@ void StaStateMachine::WepEncryptionModeIndex(WifiDeviceConfig &config) void StaStateMachine::DisConnectProcess() { if (WifiStaHalInterface::GetInstance().Disconnect() == WIFI_IDL_OPT_OK) { - LOGI("Disconnect() succeed!"); + WIFI_LOGI("Disconnect() succeed!"); /* Save connection information to WifiSettings. */ SaveLinkstate(ConnState::DISCONNECTED, DetailedState::DISCONNECTED); @@ -1242,12 +1229,12 @@ void StaStateMachine::DisConnectProcess() NotifyResult( WifiInternalMsgCode::STA_DISCONNECT_RES, static_cast(OperateResState::DISCONNECT_DISCONNECTING)); - /* The current state of StaStateMachine transfers to DisconnectedState. */ - TransitionTo(pDisconnectedState); + /* The current state of StaStateMachine transfers to SeparatedState. */ + SwitchState(pSeparatedState); } else { NotifyResult( WifiInternalMsgCode::STA_DISCONNECT_RES, static_cast(OperateResState::DISCONNECT_DISCONNECT_FAILED)); - LOGE("Disconnect() failed!"); + WIFI_LOGE("Disconnect() failed!"); } } @@ -1262,7 +1249,7 @@ void StaStateMachine::GetBandFromFreQuencies(const int &freQuency) return; } } else { - LOGE("GetSupportFrequencies 2.4Gband failed!\n"); + WIFI_LOGE("GetSupportFrequencies 2.4Gband failed!\n"); } if ((WifiStaHalInterface::GetInstance().GetSupportFrequencies(BAND_TWO, freqs5G) == WIFI_IDL_OPT_OK)) { @@ -1270,62 +1257,61 @@ void StaStateMachine::GetBandFromFreQuencies(const int &freQuency) if (it != freqs5G.end()) { linkedInfo.band = BAND_5_G; } else { - LOGE("frequency convert band failed!\n"); + WIFI_LOGE("frequency convert band failed!\n"); } } else { - LOGE("GetSupportFrequencies 5Gband failed!\n"); + WIFI_LOGE("GetSupportFrequencies 5Gband failed!\n"); } } /* --------------------------- state machine Wps State ------------------------------ */ -StaStateMachine::WpsState::WpsState(StaStateMachine *staStateMachine) : State("WpsState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::StaWpsState::StaWpsState(StaStateMachine *staStateMachine) + : State("StaWpsState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::WpsState::~WpsState() +StaStateMachine::StaWpsState::~StaWpsState() {} -void StaStateMachine::WpsState::Enter() +void StaStateMachine::StaWpsState::GoInState() { - LOGI("WpsState Enter function."); + WIFI_LOGI("WpsState GoInState function."); return; } -void StaStateMachine::WpsState::Exit() +void StaStateMachine::StaWpsState::GoOutState() {} -bool StaStateMachine::WpsState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::StaWpsState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_WPS_START_EVENT: { /* Wps starts successfully and Wait until the connection is complete. */ break; } case WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT: { - ret = HANDLED; + ret = EXECUTED; /* Stop clearing the Wpa_blocklist. */ pStaStateMachine->StopTimer(static_cast(WPA_BLOCK_LIST_CLEAR_EVENT)); - LOGI("WPS mode connect to a network!"); + WIFI_LOGI("WPS mode connect to a network!"); pStaStateMachine->ConnectToNetworkProcess(msg); pStaStateMachine->SyncAllDeviceConfigs(); /* Notify result to InterfaceService. */ pStaStateMachine->NotifyResult( WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_AP_CONNECTED)); - pStaStateMachine->TransitionTo(pStaStateMachine->pObtainingIpState); + pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); break; } case WIFI_SVR_CMD_STA_STARTWPS: { - ret = HANDLED; - auto setup = static_cast(msg->GetArg1()); + ret = EXECUTED; + auto setup = static_cast(msg->GetParam1()); /* Notify InterfaceService that wps has started successfully. */ - LOGE("WPS has already started, start wps failed!"); + WIFI_LOGE("WPS has already started, start wps failed!"); if (setup == SetupMethod::PBC) { pStaStateMachine->NotifyResult( WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::PBC_STARTED_ALREADY)); @@ -1336,16 +1322,16 @@ bool StaStateMachine::WpsState::ProcessMessage(InternalMessage *msg) break; } case WIFI_SVR_CMD_STA_WPS_OVERLAP_EVENT: { - ret = HANDLED; - LOGI("Wps PBC Overlap!"); + ret = EXECUTED; + WIFI_LOGI("Wps PBC Overlap!"); /* Notify InterfaceService that PBC is conflicting. */ pStaStateMachine->NotifyResult( WifiInternalMsgCode::STA_START_WPS_RES, static_cast(WpsStartState::START_PBC_FAILED_OVERLAP)); - pStaStateMachine->TransitionTo(pStaStateMachine->pDisconnectedState); + pStaStateMachine->SwitchState(pStaStateMachine->pSeparatedState); break; } case WIFI_SVR_CMD_STA_CANCELWPS: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->SyncAllDeviceConfigs(); pStaStateMachine->DealCancelWpsCmd(msg); break; @@ -1361,12 +1347,12 @@ void StaStateMachine::SyncAllDeviceConfigs() std::vector result; WifiIdlDeviceConfig idlConfig; if (WifiSettings::GetInstance().GetDeviceConfig(result) != -1) { - for (std::vector::iterator it = result.begin(); it != result.end(); it++) { + for (std::vector::iterator it = result.begin(); it != result.end(); ++it) { if (isWpsConnect == IsWpsConnected::WPS_CONNECTED && it->networkId == 0) { continue; } if (WifiStaHalInterface::GetInstance().GetNextNetworkId(it->networkId) == WIFI_IDL_OPT_OK) { - LOGI("GetNextNetworkId succeed"); + WIFI_LOGI("GetNextNetworkId succeed"); idlConfig.networkId = it->networkId; idlConfig.ssid = it->ssid; idlConfig.psk = it->preSharedKey; @@ -1377,33 +1363,32 @@ void StaStateMachine::SyncAllDeviceConfigs() idlConfig.identity = it->wifiEapConfig.identity; idlConfig.password = it->wifiEapConfig.password; if (WifiStaHalInterface::GetInstance().SetDeviceConfig(it->networkId, idlConfig) != WIFI_IDL_OPT_OK) { - LOGE("SetDeviceConfig failed!"); + WIFI_LOGE("SetDeviceConfig failed!"); } - LOGD("SetDeviceConfig succeed!"); + WIFI_LOGD("SetDeviceConfig succeed!"); } else { - LOGE("GetNextNetworkId failed!"); + WIFI_LOGE("GetNextNetworkId failed!"); } - LOGD("networkId = %{public}d", it->networkId); + WIFI_LOGD("networkId = %{public}d", it->networkId); WifiStaHalInterface::GetInstance().SaveDeviceConfig(); } - LOGD("Synchronizing network information!"); + WIFI_LOGD("Synchronizing network information!"); } else { - LOGE("The Device config in WifiSettings is empty!"); + WIFI_LOGE("The Device config in WifiSettings is empty!"); } } /* --------------------------- state machine ObtainingIp State ------------------------------ */ -StaStateMachine::ObtainingIpState::ObtainingIpState(StaStateMachine *staStateMachine) : State("ObtainingIpState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::GetIpState::GetIpState(StaStateMachine *staStateMachine) + : State("GetIpState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::ObtainingIpState::~ObtainingIpState() +StaStateMachine::GetIpState::~GetIpState() {} -void StaStateMachine::ObtainingIpState::Enter() +void StaStateMachine::GetIpState::GoInState() { - LOGI("ObtainingIpState Enter function."); + WIFI_LOGI("GetIpState GoInState function."); WifiDeviceConfig config; AssignIpMethod assignMethod = AssignIpMethod::DHCP; @@ -1424,7 +1409,7 @@ void StaStateMachine::ObtainingIpState::Enter() if (assignMethod == AssignIpMethod::STATIC) { pStaStateMachine->currentTpType = config.wifiIpConfig.staticIpAddress.ipAddress.address.family; if (!pStaStateMachine->ConfigStaticIpAddress(config.wifiIpConfig.staticIpAddress)) { - LOGE("ConfigStaticIpAddress failed!.\n"); + WIFI_LOGE("ConfigStaticIpAddress failed!.\n"); } } else { pStaStateMachine->currentTpType = static_cast(WifiSettings::GetInstance().GetDhcpIpType()); @@ -1434,24 +1419,24 @@ void StaStateMachine::ObtainingIpState::Enter() return; } -void StaStateMachine::ObtainingIpState::Exit() +void StaStateMachine::GetIpState::GoOutState() {} -bool StaStateMachine::ObtainingIpState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::GetIpState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; - LOGI("DefaultState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + bool ret = NOT_EXECUTED; + WIFI_LOGI("RootState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); return ret; } /* --- state machine ObtainingIp State functions ----- */ bool StaStateMachine::ConfigStaticIpAddress(StaticIpAddress &staticIpAddress) { - LOGI("Enter StaStateMachine::SetDhcpResultFromStatic."); + WIFI_LOGI("Enter StaStateMachine::SetDhcpResultFromStatic."); DhcpResult result; @@ -1508,13 +1493,13 @@ bool StaStateMachine::ConfigStaticIpAddress(StaticIpAddress &staticIpAddress) void StaStateMachine::HandleDhcpResult(const DhcpResult &dhcpResult) { - LOGI("Enter HandleDhcpResult"); + WIFI_LOGI("Enter HandleDhcpResult"); bool isGetIpSuc = false; bool isSetIpSuc = false; - /* number 2 is the number of ip_type。 */ + /* number 2 is the number of ip_typeã€? */ for (int index = 0; index < 2; index++) { - LOGI("HandleDhcpResult:isOptSuc=%{public}d, iptype=%{public}d, ip=%s, gateway=%s, " + WIFI_LOGI("HandleDhcpResult:isOptSuc=%{public}d, iptype=%{public}d, ip=%s, gateway=%s, " "subnet=%s", dhcpResult[index].isOptSuc, dhcpResult[index].iptype, @@ -1541,7 +1526,7 @@ void StaStateMachine::HandleDhcpResult(const DhcpResult &dhcpResult) SaveLinkstate(ConnState::CONNECTED, DetailedState::NOTWORKING); statusId = static_cast(WifiDeviceConfigStatus::DISABLED); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_NETWORK_DISABLED)); - LOGE("HandleDhcpResult get ip addr failed!"); + WIFI_LOGE("HandleDhcpResult get ip addr failed!"); return; } @@ -1549,10 +1534,10 @@ void StaStateMachine::HandleDhcpResult(const DhcpResult &dhcpResult) SaveLinkstate(ConnState::CONNECTED, DetailedState::NOTWORKING); statusId = static_cast(WifiDeviceConfigStatus::DISABLED); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_NETWORK_DISABLED)); - LOGE("HandleDhcpResult SetIfConfig failed!"); + WIFI_LOGE("HandleDhcpResult SetIfConfig failed!"); return; } else { - LOGI("HandleDhcpResult SetIfConfig succeed!"); + WIFI_LOGI("HandleDhcpResult SetIfConfig succeed!"); /* Update the uplink and downlink network rates periodically. */ StartTimer(static_cast(CMD_GET_NETWORK_SPEED), STA_NETWORK_SPEED_DELAY); } @@ -1568,22 +1553,22 @@ void StaStateMachine::HandleDhcpResult(const DhcpResult &dhcpResult) void StaStateMachine::HandleNetCheckResult(StaNetState netState) { - LOGI("Enter HandleNetCheckResult"); + WIFI_LOGI("Enter HandleNetCheckResult"); if (linkedInfo.connState == ConnState::DISCONNECTED) { - LOGE("Network disconnected\n"); + WIFI_LOGE("Network disconnected\n"); return; } if (netState == StaNetState::NETWORK_STATE_WORKING) { - LOGI("HandleNetCheckResult network state is working\n"); + WIFI_LOGI("HandleNetCheckResult network state is working\n"); /* Save connection information to WifiSettings. */ SaveLinkstate(ConnState::CONNECTED, DetailedState::WORKING); statusId = static_cast(WifiDeviceConfigStatus::ENABLED); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_NETWORK_ENABLED)); - /* The current state of StaStateMachine transfers to ConnectedState. */ - TransitionTo(pConnectedState); + /* The current state of StaStateMachine transfers to LinkedState. */ + SwitchState(pLinkedState); } else { - LOGI("HandleNetCheckResult network state is notworking\n"); + WIFI_LOGI("HandleNetCheckResult network state is notworking\n"); SaveLinkstate(ConnState::CONNECTED, DetailedState::NOTWORKING); statusId = static_cast(WifiDeviceConfigStatus::DISABLED); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_NETWORK_DISABLED)); @@ -1592,7 +1577,7 @@ void StaStateMachine::HandleNetCheckResult(StaNetState netState) int StaStateMachine::PortalHttpDetection() { - LOGI("EnterPortalHttpDetection"); + WIFI_LOGI("EnterPortalHttpDetection"); /* Detect portal hotspot and send message to InterfaceSeervice if result is yes. */ HttpRequest httpRequest; @@ -1601,92 +1586,90 @@ int StaStateMachine::PortalHttpDetection() if (httpRequest.HttpGet(httpMsg, httpReturn) == 0) { if (httpReturn.find("204") != std::string::npos) { - LOGE("This network is not Portal AP!"); + WIFI_LOGE("This network is not Portal AP!"); return WIFI_OPT_FAILED; } else { /* Notify result to InterfaceService. */ - LOGI("This network is portal AP,need certification!"); + WIFI_LOGI("This network is portal AP,need certification!"); NotifyResult(WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_CHECK_PORTAL)); return 0; } } - LOGE("Portal check failed!"); + WIFI_LOGE("Portal check failed!"); return WIFI_OPT_FAILED; } /* --------------------------- state machine Connected State ------------------------------ */ -StaStateMachine::ConnectedState::ConnectedState(StaStateMachine *staStateMachine) : State("ConnectedState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::LinkedState::LinkedState() + : State("LinkedState") +{} -StaStateMachine::ConnectedState::~ConnectedState() +StaStateMachine::LinkedState::~LinkedState() {} -void StaStateMachine::ConnectedState::Enter() +void StaStateMachine::LinkedState::GoInState() { - LOGI("ConnectedState Enter function."); + WIFI_LOGI("LinkedState GoInState function."); return; } -void StaStateMachine::ConnectedState::Exit() +void StaStateMachine::LinkedState::GoOutState() { - LOGI("ConnectedState Exit function."); + WIFI_LOGI("LinkedState GoOutState function."); } -bool StaStateMachine::ConnectedState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::LinkedState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = HANDLED; - LOGI("DefaultState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); + bool ret = NOT_EXECUTED; + WIFI_LOGI("RootState-msgCode=%{public}d not handled.\n", msg->GetMessageName()); return ret; } /* --------------------------- state machine Roaming State ------------------------------ */ -StaStateMachine::RoamingState::RoamingState(StaStateMachine *staStateMachine) : State("RoamingState") -{ - pStaStateMachine = staStateMachine; -} +StaStateMachine::ApRoamingState::ApRoamingState(StaStateMachine *staStateMachine) + : State("ApRoamingState"), pStaStateMachine(staStateMachine) +{} -StaStateMachine::RoamingState::~RoamingState() +StaStateMachine::ApRoamingState::~ApRoamingState() {} -void StaStateMachine::RoamingState::Enter() +void StaStateMachine::ApRoamingState::GoInState() { - LOGI("RoamingState Enter function."); + WIFI_LOGI("ApRoamingState GoInState function."); } -void StaStateMachine::RoamingState::Exit() +void StaStateMachine::ApRoamingState::GoOutState() {} -bool StaStateMachine::RoamingState::ProcessMessage(InternalMessage *msg) +bool StaStateMachine::ApRoamingState::ExecuteStateMsg(InternalMessage *msg) { if (msg == nullptr) { return false; } - bool ret = NOT_HANDLED; + bool ret = NOT_EXECUTED; switch (msg->GetMessageName()) { case WIFI_SVR_CMD_STA_NETWORK_CONNECTION_EVENT: { - ret = HANDLED; + ret = EXECUTED; pStaStateMachine->ConnectToNetworkProcess(msg); /* Notify result to InterfaceService. */ pStaStateMachine->NotifyResult( WifiInternalMsgCode::STA_CONNECT_RES, static_cast(OperateResState::CONNECT_AP_CONNECTED)); - /* The current state of StaStateMachine transfers to ObtainingIpState. */ - pStaStateMachine->TransitionTo(pStaStateMachine->pObtainingIpState); + /* The current state of StaStateMachine transfers to GetIpState. */ + pStaStateMachine->SwitchState(pStaStateMachine->pGetIpState); break; } default: break; } - return HANDLED; + return EXECUTED; } void StaStateMachine::ConnectToNetworkProcess(InternalMessage *msg) @@ -1695,14 +1678,14 @@ void StaStateMachine::ConnectToNetworkProcess(InternalMessage *msg) return; } - lastNetworkId = msg->GetArg1(); + lastNetworkId = msg->GetParam1(); std::string bssid = msg->GetStringFromMessage(); WifiDeviceConfig deviceConfig; int result = WifiSettings::GetInstance().GetDeviceConfig(lastNetworkId, deviceConfig); - LOGI("Device config networkId = %{public}d", deviceConfig.networkId); + WIFI_LOGI("Device config networkId = %{public}d", deviceConfig.networkId); - LOGI("Connected to AP[networkid=%{public}d], obtaining ip...", lastNetworkId); + WIFI_LOGI("Connected to AP[networkid=%{public}d], obtaining ip...", lastNetworkId); /* Update wifi status. */ WifiSettings::GetInstance().SetWifiState(static_cast(WifiState::ENABLED)); @@ -1711,11 +1694,11 @@ void StaStateMachine::ConnectToNetworkProcess(InternalMessage *msg) config.networkId = lastNetworkId; config.param = "ssid"; if (WifiStaHalInterface::GetInstance().GetDeviceConfig(config) != WIFI_IDL_OPT_OK) { - LOGE("GetDeviceConfig failed!"); + WIFI_LOGE("GetDeviceConfig failed!"); } if (result == 0 && deviceConfig.bssid == bssid) { - LOGI("Device config already exists."); + WIFI_LOGI("Device config already exists."); } else { deviceConfig.networkId = lastNetworkId; deviceConfig.bssid = bssid; @@ -1729,10 +1712,10 @@ void StaStateMachine::ConnectToNetworkProcess(InternalMessage *msg) WifiSettings::GetInstance().AddDeviceConfig(deviceConfig); } WifiSettings::GetInstance().SyncDeviceConfig(); - LOGD("Device ssid = %s", deviceConfig.ssid.c_str()); + WIFI_LOGD("Device ssid = %s", deviceConfig.ssid.c_str()); } WifiSettings::GetInstance().SetDeviceState(lastNetworkId, static_cast(WifiDeviceConfigStatus::CURRENT)); - LOGD("The network status is CURRENT:0."); + WIFI_LOGD("The network status is CURRENT:0."); linkedInfo.networkId = lastNetworkId; linkedInfo.bssid = bssid; linkedInfo.ssid = deviceConfig.ssid; @@ -1793,7 +1776,7 @@ void StaStateMachine::SetWifiLinkedInfo(int networkId) /* ------------------ state machine Comment function ----------------- */ void StaStateMachine::NotifyResult(int msgCode, int stateCode) { - LOGI("NotifyResult msgCode=%{public}d, stateCode=%{public}d.", msgCode, stateCode); + WIFI_LOGI("NotifyResult msgCode=%{public}d, stateCode=%{public}d.", msgCode, stateCode); WifiResponseMsgInfo notifyMsg; notifyMsg.msgCode = msgCode; @@ -1821,15 +1804,15 @@ void StaStateMachine::SaveLinkstate(ConnState state, DetailedState detailState) void StaStateMachine::DisableNetwork(int networkId) { if (WifiStaHalInterface::GetInstance().DisableNetwork(networkId) == WIFI_IDL_OPT_OK) { - LOGI("DisableNetwork() succeed, networkId=%{public}d", networkId); + WIFI_LOGI("DisableNetwork() succeed, networkId=%{public}d", networkId); if (WifiStaHalInterface::GetInstance().SaveDeviceConfig() == WIFI_IDL_OPT_OK) { - LOGI("DisableNetwork-SaveDeviceConfig() succeed!"); + WIFI_LOGI("DisableNetwork-SaveDeviceConfig() succeed!"); } else { - LOGE("DisableNetwork-SaveDeviceConfig() failed!"); + WIFI_LOGE("DisableNetwork-SaveDeviceConfig() failed!"); } } else { - LOGE("DisableNetwork() failed, networkId=%{public}d", networkId); + WIFI_LOGE("DisableNetwork() failed, networkId=%{public}d", networkId); } } @@ -1838,12 +1821,6 @@ void StaStateMachine::SetOperationalMode(int mode) SendMessage(WIFI_SVR_CMD_STA_OPERATIONAL_MODE, mode, 0); } -bool StaStateMachine::SetTargetBssid(const WifiDeviceConfig &config, std::string &bssid) -{ - LOGI("enter SetTargetBssid![%s]\n", bssid.c_str()); - return true; -} - void StaStateMachine::MacAddressGenerate(std::string &strMac) { char szMacStr[] = "0123456789abcdef"; @@ -1876,18 +1853,18 @@ bool StaStateMachine::SetRandomMac(const int networkId) } if (CheckMacFormat(strMac) == 0) { - LOGI("Check MacAddress successfully.\n"); + WIFI_LOGI("Check MacAddress successfully.\n"); if (WifiStaHalInterface::GetInstance().SetConnectMacAddr(strMac) != WIFI_IDL_OPT_OK) { - LOGE("wlan0 set Mac [%s] failed.\n", strMac.c_str()); + WIFI_LOGE("wlan0 set Mac [%s] failed.\n", strMac.c_str()); return false; } return true; } else { - LOGE("Check MacAddress error.\n"); + WIFI_LOGE("Check MacAddress error.\n"); return false; } } else { - LOGE("SetRandomMac GetDeviceConfig failed!"); + WIFI_LOGE("SetRandomMac GetDeviceConfig failed!"); return false; } } @@ -1914,7 +1891,7 @@ int StaStateMachine::CheckMacFormat(const std::string &mac) status = regexec(®, mac.c_str(), nmatch, pmatch, 0); if (status != 0) { regerror(status, ®, ebuf, sizeof(ebuf)); - LOGE("regexec failed."); + WIFI_LOGE("regexec failed."); regfree(®); return -1; } diff --git a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h index 7addc05c3..a2f15af3d 100644 --- a/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h +++ b/services/wifi_standard/wifi_framework/wifi_manage/wifi_sta/sta_state_machine.h @@ -57,7 +57,7 @@ static const int BLOCK_LIST_CLEAR_TIMER = 20 * 1000; /* Signal levels are classified into: 0 1 2 3 4 ,the max is 4. */ static const int MAX_LEVEL = 4; -const std::string SUPPLICANT_BSSID_ANY = "any"; +const std::string WPA_BSSID_ANY = "any"; class StaStateMachine : public StateMachine { public: @@ -69,16 +69,13 @@ public: * @Description Definition of member function of State base class in StaStateMachine. * */ - class DefaultState : public State { + class RootState : public State { public: - explicit DefaultState(StaStateMachine *pStaStateMachine); - ~DefaultState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; - - private: - StaStateMachine *pStaStateMachine; + explicit RootState(); + ~RootState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; }; /** * @Description : Definition of member function of InitState class in StaStateMachine. @@ -88,10 +85,9 @@ public: public: explicit InitState(StaStateMachine *pStaStateMachine); ~InitState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; - void CleanUp(); + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; @@ -105,9 +101,9 @@ public: explicit WpaStartingState(StaStateMachine *pStaStateMachine); ~WpaStartingState() override; void InitWpsSettings(); - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; @@ -120,9 +116,9 @@ public: public: explicit WpaStartedState(StaStateMachine *pStaStateMachine); ~WpaStartedState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; @@ -135,69 +131,66 @@ public: public: explicit WpaStoppingState(StaStateMachine *pStaStateMachine); ~WpaStoppingState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; }; /** - * @Description Definition of member function of ConnectState class in StaStateMachine. + * @Description Definition of member function of LinkState class in StaStateMachine. * */ - class ConnectState : public State { + class LinkState : public State { public: - explicit ConnectState(StaStateMachine *pStaStateMachine); - ~ConnectState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit LinkState(StaStateMachine *pStaStateMachine); + ~LinkState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; }; /** - * @Description Definition of member function of DisconnectingState class in StaStateMachine. + * @Description Definition of member function of SeparatingState class in StaStateMachine. * */ - class DisconnectingState : public State { + class SeparatingState : public State { public: - explicit DisconnectingState(StaStateMachine *pStaStateMachine); - ~DisconnectingState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; - - private: - StaStateMachine *pStaStateMachine; + explicit SeparatingState(); + ~SeparatingState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; }; /** - * @Description Definition of member function of DisconnectedState class in StaStateMachine. + * @Description Definition of member function of SeparatedState class in StaStateMachine. * */ - class DisconnectedState : public State { + class SeparatedState : public State { public: - explicit DisconnectedState(StaStateMachine *pStaStateMachine); - ~DisconnectedState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit SeparatedState(StaStateMachine *pStaStateMachine); + ~SeparatedState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; }; /** - * @Description Definition of member function of ApConnectedState class in StaStateMachine. + * @Description Definition of member function of ApLinkedState class in StaStateMachine. * */ - class ApConnectedState : public State { + class ApLinkedState : public State { public: - explicit ApConnectedState(StaStateMachine *pStaStateMachine); - ~ApConnectedState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit ApLinkedState(StaStateMachine *pStaStateMachine); + ~ApLinkedState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; @@ -206,58 +199,55 @@ public: * @Description Definition of member function of WpsState class in StaStateMachine. * */ - class WpsState : public State { + class StaWpsState : public State { public: - explicit WpsState(StaStateMachine *pStaStateMachine); - ~WpsState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit StaWpsState(StaStateMachine *pStaStateMachine); + ~StaWpsState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; }; /** - * @Description Definition of member function of ObtainingIpState class in StaStateMachine. + * @Description Definition of member function of GetIpState class in StaStateMachine. * */ - class ObtainingIpState : public State { + class GetIpState : public State { public: - explicit ObtainingIpState(StaStateMachine *pStaStateMachine); - ~ObtainingIpState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit GetIpState(StaStateMachine *pStaStateMachine); + ~GetIpState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; }; /** - * @Description Definition of member function of ConnectedState class in StaStateMachine. + * @Description Definition of member function of LinkedState class in StaStateMachine. * */ - class ConnectedState : public State { + class LinkedState : public State { public: - explicit ConnectedState(StaStateMachine *pStaStateMachine); - ~ConnectedState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; - - private: - StaStateMachine *pStaStateMachine; + explicit LinkedState(); + ~LinkedState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; }; /** - * @Description Definition of member function of RoamingState class in StaStateMachine. + * @Description Definition of member function of ApRoamingState class in StaStateMachine. * */ - class RoamingState : public State { + class ApRoamingState : public State { public: - explicit RoamingState(StaStateMachine *pStaStateMachine); - ~RoamingState() override; - void Enter() override; - void Exit() override; - bool ProcessMessage(InternalMessage *msg) override; + explicit ApRoamingState(StaStateMachine *pStaStateMachine); + ~ApRoamingState() override; + void GoInState() override; + void GoOutState() override; + bool ExecuteStateMsg(InternalMessage *msg) override; private: StaStateMachine *pStaStateMachine; @@ -282,10 +272,6 @@ public: * @param msgCode - operating results code.(in) */ void NotifyResult(int msgCode, int stateCode = 0); - void OnQuitting() - {} - void OnHalting() - {} /** * @Description Start roaming connection. * @@ -428,14 +414,6 @@ private: void SetOperationalMode(int mode); void SetSuspendMode(bool enabled); void SetPowerSave(bool enabled); - /** - * @Description Setting target Bssid - * - * @param config - Wifi device config(in) - * @param bssid - the mac address of wifi(in) - * @return success: true failed: false - */ - bool SetTargetBssid(const WifiDeviceConfig &config, std::string &bssid); /** * @Description Configure static ipaddress. * @@ -593,19 +571,19 @@ private: StaNetworkCheck *pNetcheck; WifiMessageQueue *msgQueueUp; /* Uplink message queue. */ - DefaultState *pDefaultState; + RootState *pRootState; InitState *pInitState; WpaStartingState *pWpaStartingState; /* Starting wpa_supplicant state. */ WpaStartedState *pWpaStartedState; /* Started wpa_supplicant state. */ WpaStoppingState *pWpaStoppingState; /* Stopping wpa_supplicant state. */ - ConnectState *pConnectState; - DisconnectingState *pDisconnectingState; - DisconnectedState *pDisconnectedState; - ApConnectedState *pApConnectedState; - WpsState *pWpsState; - ObtainingIpState *pObtainingIpState; - ConnectedState *pConnectedState; - RoamingState *pRoamingState; + LinkState *pLinkState; + SeparatingState *pSeparatingState; + SeparatedState *pSeparatedState; + ApLinkedState *pApLinkedState; + StaWpsState *pWpsState; + GetIpState *pGetIpState; + LinkedState *pLinkedState; + ApRoamingState *pApRoamingState; }; } // namespace Wifi } // namespace OHOS diff --git a/services/wifi_standard/wifi_hal/etc/init/hostapd.conf b/services/wifi_standard/wifi_hal/etc/init/hostapd.conf new file mode 100644 index 000000000..af6b38ae1 --- /dev/null +++ b/services/wifi_standard/wifi_hal/etc/init/hostapd.conf @@ -0,0 +1,20 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +interface=wlan0 +driver=hdf wifi +ctrl_interface=udp +ssid=testap +hw_mode=g +channel=1 +ignore_broadcast_ssid=0 \ No newline at end of file diff --git a/services/wifi_standard/wifi_hal/etc/init/wpa_supplicant.conf b/services/wifi_standard/wifi_hal/etc/init/wpa_supplicant.conf new file mode 100644 index 000000000..6839c178f --- /dev/null +++ b/services/wifi_standard/wifi_hal/etc/init/wpa_supplicant.conf @@ -0,0 +1,17 @@ +# Copyright (C) 2021 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +country=GB +ctrl_interface=udp +network={ +} diff --git a/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.c b/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.c index fbbe54ef5..e88549dd0 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.c @@ -237,11 +237,4 @@ WifiErrorNo SetPowerMode(uint8_t mode) { LOGI("SetPowerMode() %{public}u", mode); return WIFI_HAL_SUCCESS; -} - -WifiStatus SetLatencyMode(LatencyMode mode) -{ - LOGI("SetLatencyMode is not supported! mode %{public}u", mode); - struct WifiStatus status = {ERROR_NOT_SUPPORTED, "not supported"}; - return status; -} +} \ No newline at end of file diff --git a/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.h b/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.h index 48270f56a..b173818d0 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_chip_interface.h @@ -146,14 +146,6 @@ WifiErrorNo RequestFirmwareDebugDump(unsigned char *bytes, int32_t *size); */ WifiErrorNo SetPowerMode(uint8_t mode); -/** - * @Description API to set the wifi latency mode. - * - * @param mode - * @return WifiStatus - */ -WifiStatus SetLatencyMode(LatencyMode mode); - #ifdef __cplusplus } #endif diff --git a/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.c b/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.c index 123104230..4eb26e625 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.c @@ -331,21 +331,4 @@ int RpcSetPowerMode(RpcServer *server, Context *context) WriteInt(context, err); WriteEnd(context); return 0; -} - -int RpcSetLatencyMode(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int mode = 0; - if (ReadInt(context, &mode) < 0) { - return -1; - } - - struct WifiStatus status = SetLatencyMode(mode); - WriteBegin(context, 0); - WriteInt(context, (int)status.code); - WriteEnd(context); - return 0; -} +} \ No newline at end of file diff --git a/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.h b/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.h index 43d587103..c799c9f9a 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_crpc_chip.h @@ -147,14 +147,4 @@ int RpcRequestFirmwareDebugDump(RpcServer *server, Context *context); * @return int - 0 Success, -1 Failed. */ int RpcSetPowerMode(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * SetLatencyMode and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcSetLatencyMode(RpcServer *server, Context *context); #endif \ No newline at end of file diff --git a/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c b/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c index b2974e795..31d1ca7b7 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_crpc_server.c @@ -103,7 +103,6 @@ static int InitRpcFuncMapChip(void) ret += PushRpcFunc("GetComboModes", RpcGetComboModes); ret += PushRpcFunc("RequestFirmwareDebugDump", RpcRequestFirmwareDebugDump); ret += PushRpcFunc("SetPowerMode", RpcSetPowerMode); - ret += PushRpcFunc("SetLatencyMode", RpcSetLatencyMode); return ret; } @@ -134,13 +133,6 @@ static int InitRpcFuncMapSta(void) ret += PushRpcFunc("Reconnect", RpcReconnect); ret += PushRpcFunc("Reassociate", RpcReassociate); ret += PushRpcFunc("Disconnect", RpcDisconnect); - ret += PushRpcFunc("SetExternalSim", RpcSetExternalSim); - ret += PushRpcFunc("SetBluetoothCoexistenceScanMode", RpcSetBluetoothCoexistenceScanMode); - ret += PushRpcFunc("StopFilteringMulticastV4Packets", RpcStopFilteringMulticastV4Packets); - ret += PushRpcFunc("StopFilteringMulticastV6Packets", RpcStopFilteringMulticastV6Packets); - ret += PushRpcFunc("EnableStaAutoReconnect", RpcEnableStaAutoReconnect); - ret += PushRpcFunc("SetConcurrencyPriority", RpcSetConcurrencyPriority); - ret += PushRpcFunc("SetSuspendModeEnabled", RpcSetSuspendModeEnabled); ret += PushRpcFunc("GetStaCapabilities", RpcGetStaCapabilities); ret += PushRpcFunc("GetDeviceMacAddress", RpcGetDeviceMacAddress); ret += PushRpcFunc("GetFrequencies", RpcGetFrequencies); diff --git a/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.c b/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.c index 92088c2d6..9cac99b75 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.c @@ -122,8 +122,8 @@ int RpcGetScanResults(RpcServer *server, Context *context) WriteInt(context, results[i].siglv); WriteStr(context, results[i].flags); WriteStr(context, results[i].ssid); - long currTime = clockTime.tv_sec * secComplex * secComplex + clockTime.tv_nsec / secComplex; - WriteLong(context, currTime); + int64_t currTime = (int64_t)clockTime.tv_sec * secComplex * secComplex + clockTime.tv_nsec / secComplex; + WriteInt64(context, currTime); } } WriteEnd(context); @@ -268,110 +268,6 @@ int RpcDisconnect(RpcServer *server, Context *context) return 0; } -int RpcSetExternalSim(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int useExternalSim = 0; - if (ReadInt(context, &useExternalSim) < 0) { - return -1; - } - WifiErrorNo err = SetExternalSim(useExternalSim); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcSetBluetoothCoexistenceScanMode(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int mode = 0; - if (ReadInt(context, &mode) < 0) { - return -1; - } - WifiErrorNo err = SetBluetoothCoexistenceScanMode(mode); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcStopFilteringMulticastV4Packets(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - WifiErrorNo err = StopFilteringMulticastV4Packets(); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcStopFilteringMulticastV6Packets(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - WifiErrorNo err = StopFilteringMulticastV6Packets(); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcEnableStaAutoReconnect(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int enable = 0; - if (ReadInt(context, &enable) < 0) { - return -1; - } - WifiErrorNo err = EnableStaAutoReconnect(enable); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcSetConcurrencyPriority(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int isStaHigherPriority = 0; - if (ReadInt(context, &isStaHigherPriority) < 0) { - return -1; - } - WifiErrorNo err = SetConcurrencyPriority(isStaHigherPriority); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - -int RpcSetSuspendModeEnabled(RpcServer *server, Context *context) -{ - if (server == NULL || context == NULL) { - return -1; - } - int enable = 0; - if (ReadInt(context, &enable) < 0) { - return -1; - } - WifiErrorNo err = SetSuspendModeEnabled(enable); - WriteBegin(context, 0); - WriteInt(context, err); - WriteEnd(context); - return 0; -} - int RpcGetStaCapabilities(RpcServer *server, Context *context) { if (server == NULL || context == NULL) { diff --git a/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.h b/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.h index f66750689..9b6d47e17 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_crpc_sta.h @@ -118,76 +118,6 @@ int RpcReassociate(RpcServer *server, Context *context); */ int RpcDisconnect(RpcServer *server, Context *context); -/** - * @Description Parse the context to obtain data. Call the corresponding function - * SetExternalSim and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcSetExternalSim(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * SetBluetoothCoexistenceScanMode and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcSetBluetoothCoexistenceScanMode(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * StopFilteringMulticastV4Packets and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcStopFilteringMulticastV4Packets(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * StopFilteringMulticastV6Packets and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcStopFilteringMulticastV6Packets(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * EnableStaAutoReconnect and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcEnableStaAutoReconnect(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * SetConcurrencyPriority and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcSetConcurrencyPriority(RpcServer *server, Context *context); - -/** - * @Description Parse the context to obtain data. Call the corresponding function - * SetSuspendModeEnabled and assemble the function to obtain data. - * - * @param server - Pointer to the global structure of the communication server. - * @param context - Pointer to the global communication context structure of the server. - * @return int - 0 Success, -1 Failed. - */ -int RpcSetSuspendModeEnabled(RpcServer *server, Context *context); - /** * @Description Parse the context to obtain data. Call the corresponding function * GetStaCapabilities and assemble the function to obtain data. diff --git a/services/wifi_standard/wifi_hal/wifi_hal_define.h b/services/wifi_standard/wifi_hal/wifi_hal_define.h index e208c0c44..a17487862 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_define.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_define.h @@ -82,7 +82,7 @@ typedef enum WifiHalEvent { } WifiHalEvent; #define WIFI_BSSID_LENGTH 128 -#define WIFI_SSID_LENGTH 128 +#define WIFI_SSID_LENGTH 132 #define WIFI_SCAN_RESULT_CAPABILITY_LENGTH 256 #define WIFI_NETWORK_CONFIG_VALUE_LENGTH 128 #define WIFI_MAC_LENGTH 17 @@ -177,9 +177,6 @@ typedef enum SupplicantStatusCode { FAILURE_NETWORK_UNKNOWN } SupplicantStatusCode; -/* Low-latency mode */ -typedef enum LatencyMode { NORMAL = 0, LOW = 1 } LatencyMode; - /** * Enum values indicating the status of operation. */ diff --git a/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.c b/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.c index 9fb142a62..ad26d3172 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.c @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "wifi_hostapd_hal.h" #include #include @@ -27,7 +26,7 @@ #include "wifi_log.h" #undef LOG_TAG -#define LOG_TAG "WifiHostapdHal" +#define LOG_TAG "wifi_hostapd_hal" #define CONFIG_PATH_DIR "/data/misc/wifi/hostapd" diff --git a/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.h b/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.h index ca12df72e..3ede9dbdc 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_module/hostapd_hal/wifi_hostapd_hal.h @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef WIFI_HOSTAPD_CLI_HAL_H -#define WIFI_HOSTAPD_CLI_HAL_H +#ifndef WIFI_HOSTAPD_HAL_H +#define WIFI_HOSTAPD_HAL_H #include #include @@ -50,7 +49,6 @@ extern "C" { #define BUFFER_SIZE_32 32 #define BUFFER_SIZE_16 16 -/* *************** hostapd_cli struct ******************* */ typedef struct StStatusInfo { char state[BUFFER_SIZE_16]; char phy[BUFFER_SIZE_16]; @@ -90,8 +88,6 @@ typedef struct StDeviceInfo { int txBytes; } DeviceInfo; -/* ************** hostapd_cli struct end ***************** */ - /* Defines the HAL device structure. */ typedef struct StWifiHostapdHalDevice { struct wpa_ctrl *ctrlConn; @@ -123,6 +119,7 @@ typedef struct StWifiHostapdHalDevice { * @return WifiHostapdHalDevice* */ WifiHostapdHalDevice *GetWifiHostapdDev(void); + /** * @Description Release the Wifi Hostapd Dev object. * @@ -132,4 +129,4 @@ void ReleaseHostapdDev(void); #ifdef __cplusplus } #endif -#endif /* WIFI_HOSTAPD_CLI_HAL_H */ \ No newline at end of file +#endif /* WIFI_HOSTAPD_HAL_H */ \ No newline at end of file diff --git a/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c b/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c index f88a62d4f..a2e8ff055 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.c @@ -23,7 +23,7 @@ #include "wifi_hal_common_func.h" #undef LOG_TAG -#define LOG_TAG "WifiWpaStaHal" +#define LOG_TAG "wifi_supplicant_hal" /* * Network interface name, which is hardcoded temporarily and diff --git a/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h b/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h index c36945db3..718b22b8c 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_module/wpa_supplicant_hal/wpa_sta_hal/wifi_supplicant_hal.h @@ -12,9 +12,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - -#ifndef WIFI_WPA_CLI_HAL_H -#define WIFI_WPA_CLI_HAL_H +#ifndef WIFI_WPA_SUPPLICANT_HAL_H +#define WIFI_WPA_SUPPLICANT_HAL_H #include #include diff --git a/services/wifi_standard/wifi_hal/wifi_hal_module_manage.c b/services/wifi_standard/wifi_hal/wifi_hal_module_manage.c old mode 100644 new mode 100755 index 743cba222..5ecff0616 --- a/services/wifi_standard/wifi_hal/wifi_hal_module_manage.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_module_manage.c @@ -85,7 +85,7 @@ static void *WpaThreadMain(void *p) const char *startCmd = (const char *)p; struct StWpaMainParam param = {0}; SplitCmdString(startCmd, ¶m); - void *handleLibWpa = dlopen("/system/lib/libwpa.so", RTLD_NOW | RTLD_LOCAL); + void *handleLibWpa = dlopen("/system/lib/libwpa.z.so", RTLD_NOW | RTLD_LOCAL); if (handleLibWpa == NULL) { LOGE("dlopen libwpa failed."); return NULL; diff --git a/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c b/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c index ee0d7ae58..6a13f1b91 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c +++ b/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.c @@ -349,48 +349,6 @@ WifiErrorNo SetPowerSave(BOOL enable) return WIFI_HAL_SUCCESS; } -WifiErrorNo SetExternalSim(int useExternalSim) -{ - LOGD("SetExternalSim() %{public}d", useExternalSim); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo SetBluetoothCoexistenceScanMode(int mode) -{ - LOGD("SetBluetoothCoexistenceScanMode() %{public}d", mode); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo StopFilteringMulticastV4Packets(void) -{ - LOGD("StopFilteringMulticastV4Packets()"); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo StopFilteringMulticastV6Packets(void) -{ - LOGD("StopFilteringMulticastV6Packets()"); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo EnableStaAutoReconnect(int enable) -{ - LOGD("EnableStaAutoReconnect() %{public}d", enable); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo SetConcurrencyPriority(int isStaHigherPriority) -{ - LOGD("SetConcurrencyPriority() %{public}d", isStaHigherPriority); - return WIFI_HAL_SUCCESS; -} - -WifiErrorNo SetSuspendModeEnabled(int enable) -{ - LOGD("SetSuspendModeEnabled() %{public}d", enable); - return WIFI_HAL_SUCCESS; -} - WifiErrorNo GetStaCapabilities(int32_t *capabilities) { LOGD("GetStaCapabilities: This function is not supported currently."); diff --git a/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.h b/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.h index d77773701..6beaa93db 100644 --- a/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.h +++ b/services/wifi_standard/wifi_hal/wifi_hal_sta_interface.h @@ -157,62 +157,6 @@ WifiErrorNo Disconnect(void); */ WifiErrorNo SetPowerSave(BOOL enable); -/** - * @Description Use DFS (Whether to use an external SIM card to process SIM/USIM cards). - * - * @param useExternalSim - Bool value, whether to use. - * @return WifiErrorNo - */ -WifiErrorNo SetExternalSim(int useExternalSim); - -/** - * @Description Enable Bluetooth coexistence scanning mode. - * - * @param mode - Mode ID. - * @return WifiErrorNo - */ -WifiErrorNo SetBluetoothCoexistenceScanMode(int mode); - -/** - * @Description Filtering IPv4 Multicast Packets. - * - * @return WifiErrorNo - */ -WifiErrorNo StopFilteringMulticastV4Packets(void); - -/** - * @Description Filtering IPv6 Multicast Packets. - * - * @return WifiErrorNo - */ -WifiErrorNo StopFilteringMulticastV6Packets(void); - -/** - * @Description Set whether to enable automatic reconnection. - * - * @param enable - Bool value. - * @return WifiErrorNo - */ -WifiErrorNo EnableStaAutoReconnect(int enable); - -/** - * @Description Setting the Priority When STAs and P2P Services Coexist. - * - * @param isStaHigherPriority - Bool value Indicates whether the STA - * is preferentially selected. - * @return WifiErrorNo - */ -WifiErrorNo SetConcurrencyPriority(int isStaHigherPriority); - -/** - * @Description High-performance lock, which corresponds to disabling the - * suspend mode of wpa-supplicant. - * - * @param enable - Bool value. - * @return WifiErrorNo - */ -WifiErrorNo SetSuspendModeEnabled(int enable); - /** * @Description Obtaining the STA Support Capability. * -- Gitee