From b2ca227fd5d78c988a111189eae8cadfdb79e5f8 Mon Sep 17 00:00:00 2001 From: "Wiktor S. Ovalle Correa" Date: Mon, 17 May 2021 15:46:37 +0200 Subject: [PATCH] [EGD-6746] Use new SimCard implementation Switch to SimCard implementation provided by previous commit --- .../ApplicationDesktop.cpp | 99 ++-- .../ApplicationSettings.cpp | 38 +- .../windows/PINSettingsWindow.cpp | 5 +- .../ApplicationSettings.cpp | 5 +- module-apps/locks/handlers/PinLockHandler.cpp | 62 +- module-apps/locks/handlers/PinLockHandler.hpp | 23 +- .../service-antenna/ServiceAntenna.cpp | 2 +- .../model/ApplicationManager.cpp | 82 ++- .../model/ApplicationManager.hpp | 6 + .../service-cellular/CMakeLists.txt | 3 +- .../service-cellular/CellularServiceAPI.cpp | 34 +- .../service-cellular/CellularUrcHandler.cpp | 3 +- .../service-cellular/CellularUrcHandler.hpp | 4 +- .../service-cellular/PacketData.cpp | 3 + .../service-cellular/PacketData.hpp | 6 +- .../service-cellular/QMBNManager.cpp | 1 + .../service-cellular/QMBNManager.hpp | 3 +- .../service-cellular/RequestFactory.cpp | 12 +- .../service-cellular/ServiceCellular.cpp | 538 +++--------------- module-services/service-cellular/SimCard.cpp | 178 ------ module-services/service-cellular/SimCard.hpp | 77 --- .../service-cellular/{state.hpp => State.hpp} | 0 .../include/service-cellular/api/common.hpp | 4 +- .../service-cellular/api/request/sim.hpp | 24 +- .../service-cellular/CellularMessage.hpp | 364 +----------- .../service-cellular/CellularServiceAPI.hpp | 12 +- .../service-cellular/RequestFactory.hpp | 14 +- .../service-cellular/ServiceCellular.hpp | 95 +--- .../service-cellular/SimCardResult.hpp | 33 -- .../service-cellular/State.hpp | 59 -- .../src/ServiceCellularPriv.hpp | 4 +- .../service-cellular/src/SimCard.cpp | 2 +- .../service-cellular/src/SimCard.hpp | 2 +- .../src/{state.cpp => State.cpp} | 4 +- .../tests/unittest_datatransfer.cpp | 2 - .../service-cellular/tests/unittest_qmbn.cpp | 2 - .../tests/unittest_request_factory.cpp | 12 +- .../tests/unittest_simcard.cpp | 2 +- .../developerMode/DeveloperModeHelper.cpp | 13 +- module-services/service-fota/ServiceFota.cpp | 4 +- module-sys/SystemManager/SystemManager.cpp | 8 +- module-utils/common_data/EventStore.hpp | 5 +- 42 files changed, 396 insertions(+), 1453 deletions(-) delete mode 100644 module-services/service-cellular/SimCard.cpp delete mode 100644 module-services/service-cellular/SimCard.hpp rename module-services/service-cellular/include/service-cellular/{state.hpp => State.hpp} (100%) delete mode 100644 module-services/service-cellular/service-cellular/SimCardResult.hpp delete mode 100644 module-services/service-cellular/service-cellular/State.hpp rename module-services/service-cellular/src/{state.cpp => State.cpp} (94%) diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 85150c2548445426a44d4a01fc5f1d00a5db90c9..9f44d92e11a5c1771b07bbbab9d7e4d3e738e5fb 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -73,13 +74,13 @@ namespace app addActionReceiver(app::manager::actions::RequestPinDisable, [this](auto &&data) { lockHandler.handlePinEnableRequest(std::forward(data), - CellularSimCardLockDataMessage::SimCardLock::Unlocked); + cellular::api::SimLockState::Disabled); return actionHandled(); }); addActionReceiver(app::manager::actions::RequestPinEnable, [this](auto &&data) { lockHandler.handlePinEnableRequest(std::forward(data), - CellularSimCardLockDataMessage::SimCardLock::Locked); + cellular::api::SimLockState::Enabled); return actionHandled(); }); @@ -214,7 +215,7 @@ namespace app auto ApplicationDesktop::handle(cellular::StateChange *msg) -> bool { assert(msg); - if (msg->request == cellular::State::ST::URCReady) { + if (msg->request == cellular::service::State::ST::URCReady) { if (need_sim_select && !lockHandler.isScreenLocked()) { manager::Controller::sendAction(this, manager::actions::SelectSimCard); return true; @@ -223,7 +224,7 @@ namespace app bus.sendUnicast(std::make_shared(), ServiceCellular::serviceName); } } - if (msg->request == cellular::State::ST::ModemFatalFailure) { + if (msg->request == cellular::service::State::ST::ModemFatalFailure) { switchWindow(app::window::name::desktop_reboot); } return false; @@ -277,48 +278,54 @@ namespace app }}); }; - connect(typeid(CellularSimNewPinResponseMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto response = dynamic_cast(request); - if (response->retCode) { - auto metaData = createPinChangedSuccessfullyDialog(this); - switchWindow(gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); - } - else { - lockHandler.handlePinChangeRequestFailed(); - } - return sys::MessageNone{}; - }); - - connect(typeid(CellularSimPukResponseMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto response = dynamic_cast(request); - if (response->retCode) { - auto metaData = createPinChangedSuccessfullyDialog(this); - switchWindow(gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); - } - return sys::MessageNone{}; - }); - - connect(typeid(CellularSimCardLockResponseMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto response = dynamic_cast(request); - if (response->retCode) { - auto metaData = std::make_unique(gui::DialogMetadata{ - "", - "success_icon_W_G", - response->getSimCardLock() == CellularSimCardLockDataMessage::SimCardLock::Unlocked - ? utils::translate("app_desktop_sim_card_unlocked") - : utils::translate("app_desktop_sim_card_locked"), - "", - [this]() { - switchWindow(app::window::name::desktop_main_window); - return true; - }}); - switchWindow(gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); - } - else { - lockHandler.handlePinEnableRequestFailed(response->getSimCardLock()); - } - return sys::MessageNone{}; - }); + connect(typeid(cellular::msg::request::sim::ChangePin::Response), + [&](sys::Message *request) -> sys::MessagePointer { + auto response = dynamic_cast(request); + if (response->retCode) { + auto metaData = createPinChangedSuccessfullyDialog(this); + switchWindow( + gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); + } + else { + lockHandler.handlePinChangeRequestFailed(); + } + return sys::MessageNone{}; + }); + + connect(typeid(cellular::msg::request::sim::UnblockWithPuk::Response), + [&](sys::Message *request) -> sys::MessagePointer { + auto response = dynamic_cast(request); + if (response->retCode) { + auto metaData = createPinChangedSuccessfullyDialog(this); + switchWindow( + gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); + } + return sys::MessageNone{}; + }); + + connect(typeid(cellular::msg::request::sim::SetPinLock::Response), + [&](sys::Message *request) -> sys::MessagePointer { + auto response = dynamic_cast(request); + if (response->retCode) { + auto metaData = std::make_unique( + gui::DialogMetadata{"", + "success_icon_W_G", + response->lock == cellular::api::SimLockState::Disabled + ? utils::translate("app_desktop_sim_card_unlocked") + : utils::translate("app_desktop_sim_card_locked"), + "", + [this]() { + switchWindow(app::window::name::desktop_main_window); + return true; + }}); + switchWindow( + gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData)); + } + else { + lockHandler.handlePinEnableRequestFailed(response->lock); + } + return sys::MessageNone{}; + }); connect(typeid(db::NotificationMessage), [&](sys::Message *request) { auto notificationMessage = static_cast(request); diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index d66ea2c602e8719985437c9b425fd585c029e9b3..020e7f38d8a80246e90897d93b4e996eb7294d29 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -58,6 +58,7 @@ #include #include +#include #include #include #include @@ -121,13 +122,6 @@ namespace app } if (auto phoneMsg = dynamic_cast(msgl); nullptr != phoneMsg) { - selectedSim = Store::GSM::get()->selected; - if (CellularNotificationMessage::Content::SIM_READY == phoneMsg->content) { - CellularServiceAPI::RequestForOwnNumber(this); - } - else if (CellularNotificationMessage::Content::SIM_NOT_READY == phoneMsg->content) { - selectedSimNumber = {}; - } auto currentWindow = getCurrentWindow(); if (gui::window::name::network == currentWindow->getName()) { updateWindow(gui::window::name::network, nullptr); @@ -153,6 +147,21 @@ namespace app if (ret != sys::ReturnCodes::Success) { return ret; } + connect(typeid(cellular::msg::notification::SimReady), [&](sys::Message *msg) { + auto simReadyMsg = static_cast(msg); + selectedSim = Store::GSM::get()->selected; + if (simReadyMsg->ready) { + CellularServiceAPI::RequestForOwnNumber(this); + } + else { + selectedSimNumber = {}; + } + auto currentWindow = getCurrentWindow(); + if (gui::window::name::network == currentWindow->getName()) { + updateWindow(gui::window::name::network, nullptr); + } + return sys::MessageNone{}; + }); connect(typeid(::message::bluetooth::ResponseStatus), [&](sys::Message *msg) { auto responseStatusMsg = static_cast<::message::bluetooth::ResponseStatus *>(msg); @@ -271,13 +280,11 @@ namespace app return sys::MessageNone{}; }); - connect(typeid(CellularSimCardPinLockStateResponseDataMessage), [&](sys::Message *msg) { - auto simCardPinLockState = dynamic_cast(msg); - if (simCardPinLockState != nullptr) { - auto pinSettingsLockStateData = - std::make_unique(simCardPinLockState->getSimCardPinLockState()); - updateWindow(gui::window::name::pin_settings, std::move(pinSettingsLockStateData)); - } + connect(typeid(cellular::msg::request::sim::GetLockState::Response), [&](sys::Message *msg) { + auto simCardPinLockState = static_cast(msg); + auto pinSettingsLockStateData = + std::make_unique(simCardPinLockState->locked); + updateWindow(gui::window::name::pin_settings, std::move(pinSettingsLockStateData)); return sys::MessageNone{}; }); @@ -509,7 +516,8 @@ namespace app void ApplicationSettingsNew::setSim(Store::GSM::SIM sim) { - CellularServiceAPI::SetSimCard(this, sim); + auto arg = (sim == Store::GSM::SIM::SIM2) ? cellular::api::SimSlot::SIM2 : cellular::api::SimSlot::SIM1; + bus.sendUnicast(arg); } Store::GSM::SIM ApplicationSettingsNew::getSim() diff --git a/module-apps/application-settings-new/windows/PINSettingsWindow.cpp b/module-apps/application-settings-new/windows/PINSettingsWindow.cpp index c662b2c0515de99656ec68ac4e174d601faafabc..fe25716506471e86d172e246f235b03ffb6c4950 100644 --- a/module-apps/application-settings-new/windows/PINSettingsWindow.cpp +++ b/module-apps/application-settings-new/windows/PINSettingsWindow.cpp @@ -8,13 +8,14 @@ #include "OptionSetting.hpp" #include -#include "service-cellular/CellularServiceAPI.hpp" +#include +#include namespace gui { PINSettingsWindow::PINSettingsWindow(app::Application *app) : BaseSettingsWindow(app, window::name::pin_settings) { - CellularServiceAPI::RequestSimCardPinLockState(app); + app->bus.sendUnicast(); } void PINSettingsWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data) diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index 7e43fc0697083a127d175e883c9c47b06e0a2295..fa45bd8f213154085babaea59c1dea4f08107df5 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -21,7 +21,7 @@ #include "ApplicationSettings.hpp" #include "service-cellular/ServiceCellular.hpp" -#include +#include #include "windows/SettingsMainWindow.hpp" #include "windows/SimSelectWindow.hpp" #include "windows/CellularPassthroughWindow.hpp" @@ -164,7 +164,8 @@ namespace app void ApplicationSettings::setSim(Store::GSM::SIM sim) { - CellularServiceAPI::SetSimCard(this, sim); + auto arg = (sim == Store::GSM::SIM::SIM2) ? cellular::api::SimSlot::SIM2 : cellular::api::SimSlot::SIM1; + bus.sendUnicast(arg); } void ApplicationSettings::timeDateChanged(std::string value) diff --git a/module-apps/locks/handlers/PinLockHandler.cpp b/module-apps/locks/handlers/PinLockHandler.cpp index d748f227085d9991ea3c6bd24e6819046da80271..271f30d757ed920655097c802845d0b5fc859981 100644 --- a/module-apps/locks/handlers/PinLockHandler.cpp +++ b/module-apps/locks/handlers/PinLockHandler.cpp @@ -10,6 +10,9 @@ #include #include +#include +#include + namespace gui { namespace @@ -67,27 +70,27 @@ namespace gui LOG_DEBUG("Handling RequestPinChange action"); handlePasscodeParams(Lock::LockType::SimPin, Lock::LockState::InputRequired, std::move(data)); promptSimLockWindow = true; - auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this](Lock::LockType type, const cellular::api::SimCode &data) { handlePasscodeChange(data); }; switchToPinLockWindow(onActivatedCallback); } void PinLockHandler::handlePinEnableRequest(app::manager::actions::ActionParamsPtr &&data, - CellularSimCardLockDataMessage::SimCardLock simCardLock) + cellular::api::SimLockState simCardLock) { + using namespace cellular::msg; + using namespace cellular::api; LOG_DEBUG("Handling PinEnableRequest action, simCardLock = %d", static_cast(simCardLock)); handlePasscodeParams(Lock::LockType::SimPin, Lock::LockState::InputRequired, std::move(data)); promptSimLockWindow = true; - auto onActivatedCallback = [this, simCardLock](Lock::LockType type, const std::vector &data) { - app->bus.sendUnicast( - std::make_shared(Store::GSM::get()->selected, simCardLock, data), - serviceCellular); + auto onActivatedCallback = [this, simCardLock](Lock::LockType, const cellular::api::SimCode &data) { + app->bus.sendUnicast(simCardLock, data); }; switchToPinLockWindow(onActivatedCallback); } - void PinLockHandler::handlePinEnableRequestFailed(CellularSimCardLockDataMessage::SimCardLock simCardLock) + void PinLockHandler::handlePinEnableRequestFailed(cellular::api::SimLockState simCardLock) { LOG_DEBUG("Handling PinEnableRequestFailed action, simCardLock = %d, simLock.value = %u", static_cast(simCardLock), @@ -101,7 +104,7 @@ namespace gui } if (simLock.attemptsLeft > 0) { simLock.lockState = Lock::LockState::InputInvalid; - auto onActivatedCallback = [this, simCardLock](Lock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this, simCardLock](Lock::LockType type, const cellular::api::SimCode &data) { auto params = std::make_unique( Store::GSM::get()->selected, simLock.attemptsLeft, PasscodeParams::pinName); handlePinEnableRequest(std::move(params), simCardLock); @@ -127,7 +130,7 @@ namespace gui } if (simLock.attemptsLeft > 0) { simLock.lockState = Lock::LockState::InputInvalid; - auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this](Lock::LockType type, const cellular::api::SimCode &data) { auto params = std::make_unique( Store::GSM::get()->selected, simLock.attemptsLeft, PasscodeParams::pinName); handlePinChangeRequest(std::move(params)); @@ -169,7 +172,7 @@ namespace gui auto params = static_cast(data.get()); auto lock = std::make_unique( params->getSim(), Lock::LockState::ErrorOccurred, Lock::LockType::SimPin, params->getCMECode()); - lock->onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { + lock->onActivatedCallback = [this](Lock::LockType type, const cellular::api::SimCode &data) { app->switchWindow(app::window::name::desktop_main_window); }; app->switchWindow( @@ -177,18 +180,18 @@ namespace gui } void PinLockHandler::switchToPinLockWindow( - std::function &)> onLockActivatedCallback) + std::function onLockActivatedCallback) { auto lock = std::make_unique(getStrongestLock()); if (lock->isState(Lock::LockState::InputInvalid)) { getStrongestLock().consumeState(); lock->onActivatedCallback = [this, onLockActivatedCallback](Lock::LockType, - const std::vector &) { + const cellular::api::SimCode &) { switchToPinLockWindow(onLockActivatedCallback); }; } else if (lock->isState(gui::Lock::LockState::Blocked)) { - lock->onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { + lock->onActivatedCallback = [this](Lock::LockType type, const cellular::api::SimCode &data) { setSimLockHandled(); app->switchWindow(app::window::name::desktop_main_window); }; @@ -207,7 +210,7 @@ namespace gui void PinLockHandler::switchToPinLockWindow( Lock::LockState state, - std::function &)> onLockActivatedCallback) + std::function onLockActivatedCallback) { auto lock = std::make_unique(getStrongestLock()); lock->lockState = state; @@ -216,30 +219,30 @@ namespace gui app::window::name::desktop_pin_lock, gui::ShowMode::GUI_SHOW_INIT, std::make_unique(*lock)); } - void PinLockHandler::handlePasscode(Lock::LockType type, const std::vector passcode) + void PinLockHandler::handlePasscode(Lock::LockType type, const cellular::api::SimCode &passcode) { if (type == Lock::LockType::SimPin) { setSimLockHandled(); - app->bus.sendUnicast(std::make_shared(simLock.sim, passcode), serviceCellular); + app->bus.sendUnicast(passcode); } else if (type == Lock::LockType::SimPuk) { handlePasscodeChange(passcode); } } - void PinLockHandler::handlePasscodeChange(const std::vector passcode) + void PinLockHandler::handlePasscodeChange(const cellular::api::SimCode &passcode) { - auto onActivatedCallback = [this, passcode](Lock::LockType, const std::vector &pin) { + auto onActivatedCallback = [this, passcode](Lock::LockType, const cellular::api::SimCode &pin) { handleNewPasscodeUnconfirmed(passcode, pin); }; switchToPinLockWindow(Lock::LockState::NewInputRequired, onActivatedCallback); } - void PinLockHandler::handleNewPasscodeUnconfirmed(const std::vector &passcode, - const std::vector &pin) + void PinLockHandler::handleNewPasscodeUnconfirmed(const cellular::api::SimCode &passcode, + const cellular::api::SimCode &pin) { auto onActivatedCallback = [this, passcode, pin](Lock::LockType type, - const std::vector &pinConfirmed) { + const cellular::api::SimCode &pinConfirmed) { if (pin == pinConfirmed) { handleNewPasscodeConfirmed(type, passcode, pin); } @@ -251,29 +254,28 @@ namespace gui } void PinLockHandler::handleNewPasscodeConfirmed(Lock::LockType type, - const std::vector &passcode, - const std::vector &pin) + const cellular::api::SimCode &passcode, + const cellular::api::SimCode &pin) { + using namespace cellular::msg; if (type == Lock::LockType::SimPin) { - app->bus.sendUnicast(std::make_shared(simLock.sim, passcode, pin), - serviceCellular); + app->bus.sendUnicast(passcode, pin); } else if (type == Lock::LockType::SimPuk) { - app->bus.sendUnicast(std::make_shared(simLock.sim, passcode, pin), - serviceCellular); + app->bus.sendUnicast(passcode, pin); } } - void PinLockHandler::handleNewPasscodeInvalid(const std::vector &passcode) + void PinLockHandler::handleNewPasscodeInvalid(const cellular::api::SimCode &passcode) { - auto onActivatedCallback = [this, passcode](Lock::LockType type, const std::vector &pin) { + auto onActivatedCallback = [this, passcode](Lock::LockType type, const cellular::api::SimCode &pin) { handlePasscodeChange(passcode); }; switchToPinLockWindow(Lock::LockState::NewInputInvalid, onActivatedCallback); } void PinLockHandler::unlock() { - auto onActivatedCallback = [this](Lock::LockType type, const std::vector &data) { + auto onActivatedCallback = [this](Lock::LockType type, const cellular::api::SimCode &data) { handlePasscode(type, data); }; switchToPinLockWindow(onActivatedCallback); diff --git a/module-apps/locks/handlers/PinLockHandler.hpp b/module-apps/locks/handlers/PinLockHandler.hpp index 38f83d4ec0e8c57b58dfa2d949e4cd2979afbe9b..0efbf1b6d88db771e9dbd1ed70b16b5b63097f06 100644 --- a/module-apps/locks/handlers/PinLockHandler.hpp +++ b/module-apps/locks/handlers/PinLockHandler.hpp @@ -7,7 +7,7 @@ #include #include -#include +#include namespace app { @@ -25,22 +25,21 @@ namespace gui Lock simLock; bool promptSimLockWindow = true; - void handlePasscode(Lock::LockType type, const std::vector passcode); - void handlePasscodeChange(const std::vector passcode); - void handleNewPasscodeUnconfirmed(const std::vector &passcode, - const std::vector &pin); + void handlePasscode(Lock::LockType type, const cellular::api::SimCode &passcode); + void handlePasscodeChange(const cellular::api::SimCode &passcode); + void handleNewPasscodeUnconfirmed(const cellular::api::SimCode &passcode, const cellular::api::SimCode &pin); void handleNewPasscodeConfirmed(Lock::LockType type, - const std::vector &passcode, - const std::vector &pin); - void handleNewPasscodeInvalid(const std::vector &passcode); + const cellular::api::SimCode &passcode, + const cellular::api::SimCode &pin); + void handleNewPasscodeInvalid(const cellular::api::SimCode &passcode); void handlePasscodeParams(Lock::LockType type, Lock::LockState state, app::manager::actions::ActionParamsPtr &&data); void switchToPinLockWindow( - std::function &)> onLockActivatedCallback); + std::function onLockActivatedCallback); void switchToPinLockWindow( Lock::LockState type, - std::function &)> onLockActivatedCallback); + std::function onLockActivatedCallback); auto getStrongestLock() noexcept -> gui::Lock &; void unlock(); @@ -52,8 +51,8 @@ namespace gui void handlePasscodeRequest(Lock::LockType type, app::manager::actions::ActionParamsPtr &&data); void handlePinChangeRequest(app::manager::actions::ActionParamsPtr &&data); void handlePinEnableRequest(app::manager::actions::ActionParamsPtr &&data, - CellularSimCardLockDataMessage::SimCardLock simCardLock); - void handlePinEnableRequestFailed(CellularSimCardLockDataMessage::SimCardLock simCardLock); + cellular::api::SimLockState simCardLock); + void handlePinEnableRequestFailed(cellular::api::SimLockState simCardLock); void handleSimBlocked(app::manager::actions::ActionParamsPtr &&data); void handleUnlockSim(app::manager::actions::ActionParamsPtr &&data); void handleCMEError(app::manager::actions::ActionParamsPtr &&data) const; diff --git a/module-services/service-antenna/ServiceAntenna.cpp b/module-services/service-antenna/ServiceAntenna.cpp index ccb796af6a376014f8dda5a33ebeb0ed638dcea9..5976c21a93b337f6889a455667e798a81b1d6643 100644 --- a/module-services/service-antenna/ServiceAntenna.cpp +++ b/module-services/service-antenna/ServiceAntenna.cpp @@ -122,7 +122,7 @@ sys::MessagePointer ServiceAntenna::DataReceivedHandler(sys::DataMessage *msgl, case CellularMessage::Type::StateRequest: { auto msg = dynamic_cast(msgl); if (msg != nullptr) { - if (msg->request == cellular::State::ST::Ready) { + if (msg->request == cellular::service::State::ST::Ready) { state->set(antenna::State::init); } } diff --git a/module-services/service-appmgr/model/ApplicationManager.cpp b/module-services/service-appmgr/model/ApplicationManager.cpp index d4706aed0fd515775b65a84f995bcbbf28405c95..6939a5a5e3e4566d38412fc16c55689085da0452 100644 --- a/module-services/service-appmgr/model/ApplicationManager.cpp +++ b/module-services/service-appmgr/model/ApplicationManager.cpp @@ -144,6 +144,7 @@ namespace app::manager bus.channels.push_back(sys::BusChannel::PhoneModeChanges); bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications); bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); + bus.channels.push_back(sys::BusChannel::ServiceCellularNotifications); registerMessageHandlers(); } @@ -453,11 +454,6 @@ namespace app::manager connect(typeid(app::manager::DOMRequest), [&](sys::Message *request) { return handleDOMRequest(request); }); auto convertibleToActionHandler = [this](sys::Message *request) { return handleMessageAsAction(request); }; - connect(typeid(CellularSimRequestPinMessage), convertibleToActionHandler); - connect(typeid(CellularSimRequestPukMessage), convertibleToActionHandler); - connect(typeid(CellularUnlockSimMessage), convertibleToActionHandler); - connect(typeid(CellularBlockSimMessage), convertibleToActionHandler); - connect(typeid(CellularDisplayCMEMessage), convertibleToActionHandler); connect(typeid(CellularMMIResultMessage), convertibleToActionHandler); connect(typeid(CellularMMIResponseMessage), convertibleToActionHandler); connect(typeid(CellularMMIPushMessage), convertibleToActionHandler); @@ -471,6 +467,33 @@ namespace app::manager connect(typeid(sys::TetheringQuestionAbort), convertibleToActionHandler); connect(typeid(sys::TetheringPhoneModeChangeProhibitedMessage), convertibleToActionHandler); connect(typeid(VolumeChanged), convertibleToActionHandler); + + /* Notifications from sys::BusChannel::ServiceCellularNotifications */ + connect(typeid(cellular::msg::notification::SimReady), [&](sys::Message *request) { + auto msg = static_cast(request); + handleSimReady(msg); + return sys::MessageNone{}; + }); + connect(typeid(cellular::msg::notification::SimNeedPin), [&](sys::Message *request) { + auto msg = static_cast(request); + handleSimNeedPin(msg); + return sys::MessageNone{}; + }); + connect(typeid(cellular::msg::notification::SimNeedPuk), [&](sys::Message *request) { + auto msg = static_cast(request); + handleSimNeedPuk(msg); + return sys::MessageNone{}; + }); + connect(typeid(cellular::msg::notification::SimBlocked), [&](sys::Message *request) { + auto msg = static_cast(request); + handleSimBlocked(msg); + return sys::MessageNone{}; + }); + connect(typeid(cellular::msg::notification::UnhandledCME), [&](sys::Message *request) { + auto msg = static_cast(request); + handleUnhandledCME(msg); + return sys::MessageNone{}; + }); } sys::ReturnCodes ApplicationManager::SwitchPowerModeHandler(const sys::ServicePowerMode mode) @@ -618,6 +641,55 @@ namespace app::manager actionsRegistry.enqueue(std::move(entry)); } + void ApplicationManager::handleSimReady(cellular::msg::notification::SimReady *msg) + { + if (msg->ready) { + auto action = std::make_unique( + msg->sender, + app::manager::actions::UnlockSim, + std::make_unique(Store::GSM::get()->selected)); + handleActionRequest(action.get()); + } + } + + void ApplicationManager::handleSimNeedPin(cellular::msg::notification::SimNeedPin *msg) + { + auto action = std::make_unique( + msg->sender, + app::manager::actions::RequestPin, + std::make_unique( + Store::GSM::get()->selected, msg->attempts, std::string())); + handleActionRequest(action.get()); + } + + void ApplicationManager::handleSimNeedPuk(cellular::msg::notification::SimNeedPuk *msg) + { + auto action = std::make_unique( + msg->sender, + app::manager::actions::RequestPuk, + std::make_unique( + Store::GSM::get()->selected, msg->attempts, std::string())); + handleActionRequest(action.get()); + } + + void ApplicationManager::handleSimBlocked(cellular::msg::notification::SimBlocked *msg) + { + auto action = std::make_unique( + msg->sender, + app::manager::actions::BlockSim, + std::make_unique(Store::GSM::get()->selected)); + handleActionRequest(action.get()); + } + + void ApplicationManager::handleUnhandledCME(cellular::msg::notification::UnhandledCME *msg) + { + auto action = std::make_unique( + msg->sender, + app::manager::actions::DisplayCMEError, + std::make_unique(Store::GSM::get()->selected, msg->code)); + handleActionRequest(action.get()); + } + void ApplicationManager::handlePhoneModeChanged(sys::phone_modes::PhoneMode phoneMode) { for (const auto app : getRunningApplications()) { diff --git a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp index 3c00a132b3dad7f7fba0d1938564f7f0492b8d1c..80d1b5a31fb077b969b8ace0162ec49ea9e5c97a 100644 --- a/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +++ b/module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp @@ -32,6 +32,7 @@ #include #include +#include namespace app { @@ -148,6 +149,11 @@ namespace app::manager auto handleDBResponse(db::QueryResponse *msg) -> bool; auto handlePowerSavingModeInit() -> bool; auto handleMessageAsAction(sys::Message *request) -> std::shared_ptr; + void handleSimReady(cellular::msg::notification::SimReady *msg); + void handleSimNeedPin(cellular::msg::notification::SimNeedPin *msg); + void handleSimNeedPuk(cellular::msg::notification::SimNeedPuk *msg); + void handleSimBlocked(cellular::msg::notification::SimBlocked *msg); + void handleUnhandledCME(cellular::msg::notification::UnhandledCME *msg); auto handleDeveloperModeRequest(sys::Message *request) -> sys::MessagePointer; /// handles dom request by passing this request to application which should provide the dom auto handleDOMRequest(sys::Message *request) -> std::shared_ptr; diff --git a/module-services/service-cellular/CMakeLists.txt b/module-services/service-cellular/CMakeLists.txt index e9ddc398b4cc27d888003b9f781ddfbc6309fb0b..586c54dfad306e0b2f43e95b3e38697301c44e4c 100644 --- a/module-services/service-cellular/CMakeLists.txt +++ b/module-services/service-cellular/CMakeLists.txt @@ -3,7 +3,7 @@ message( "${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}" ) set(SOURCES src/ServiceCellularPriv.cpp - src/state.cpp + src/State.cpp src/SimCard.cpp CellularCall.cpp @@ -12,7 +12,6 @@ set(SOURCES checkSmsCenter.cpp ServiceCellular.cpp SignalStrength.cpp - SimCard.cpp NetworkSettings.cpp PacketData.cpp QMBNManager.cpp diff --git a/module-services/service-cellular/CellularServiceAPI.cpp b/module-services/service-cellular/CellularServiceAPI.cpp index 1a46e1a0ab2abdae8566784ebef98a5429908020..bdbf7c9a4331ba40547147c761691cdda01fff52 100644 --- a/module-services/service-cellular/CellularServiceAPI.cpp +++ b/module-services/service-cellular/CellularServiceAPI.cpp @@ -29,8 +29,7 @@ bool CellularServiceAPI::DialNumber(sys::Service *serv, const utils::PhoneNumber bool CellularServiceAPI::DialEmergencyNumber(sys::Service *serv, const utils::PhoneNumber &number) { - auto msg = std::make_shared(number.getView(), - CellularCallRequestMessage::RequestMode::Emergency); + auto msg = std::make_shared(number.getView(), cellular::api::CallMode::Emergency); return serv->bus.sendUnicast(msg, ServiceCellular::serviceName); } @@ -264,35 +263,6 @@ bool CellularServiceAPI::USSDRequest(sys::Service *serv, CellularUSSDMessage::Re ; } -bool CellularServiceAPI::ChangeSimPin(sys::Service *serv, - Store::GSM::SIM sim, - const std::vector &passcode, - const std::vector &pin) -{ - return serv->bus.sendUnicast(std::make_shared(sim, passcode, pin), - ServiceCellular::serviceName); -} - -bool CellularServiceAPI::RequestSimCardPinLockState(sys::Service *serv) -{ - return serv->bus.sendUnicast(std::make_shared(), - ServiceCellular::serviceName); -} - -bool CellularServiceAPI::SetSimCardLock(sys::Service *serv, - Store::GSM::SIM sim, - CellularSimCardLockDataMessage::SimCardLock lock, - const std::vector &pin) -{ - return serv->bus.sendUnicast(std::make_shared(sim, lock, pin), - ServiceCellular::serviceName); -} - -bool CellularServiceAPI::SetSimCard(sys::Service *serv, Store::GSM::SIM sim) -{ - return serv->bus.sendUnicast(std::make_shared(sim), ServiceCellular::serviceName); -} - bool CellularServiceAPI::GetAPN(sys::Service *serv) { return serv->bus.sendUnicast(std::make_shared(), ServiceCellular::serviceName); @@ -342,7 +312,7 @@ bool CellularServiceAPI::SetVoLTE(sys::Service *serv, bool voLTE) return serv->bus.sendUnicast(std::make_shared(voLTE), ServiceCellular::serviceName); } -bool CellularServiceAPI::ChangeModulePowerState(sys::Service *serv, cellular::State::PowerState newState) +bool CellularServiceAPI::ChangeModulePowerState(sys::Service *serv, cellular::service::State::PowerState newState) { return serv->bus.sendUnicast(std::make_shared(newState), ServiceCellular::serviceName); } diff --git a/module-services/service-cellular/CellularUrcHandler.cpp b/module-services/service-cellular/CellularUrcHandler.cpp index 8cd1056e2e51c39f8a954c2dc1ee2d43abfbce3c..a11ea99fceebb8d7afc535121705070c85fac20c 100644 --- a/module-services/service-cellular/CellularUrcHandler.cpp +++ b/module-services/service-cellular/CellularUrcHandler.cpp @@ -4,6 +4,7 @@ #include "CellularUrcHandler.hpp" #include "service-cellular/CellularMessage.hpp" +#include "messages.hpp" #include "service-cellular/CellularServiceAPI.hpp" #include @@ -152,7 +153,7 @@ void CellularUrcHandler::Handle(Cpin &urc) LOG_INFO("Invalid cpin - ignore"); } else { - response = std::make_unique(*state, *urc.getMessage()); + response = std::make_unique(*state); urc.setHandled(true); } } diff --git a/module-services/service-cellular/CellularUrcHandler.hpp b/module-services/service-cellular/CellularUrcHandler.hpp index 3e6fb405dbbb4b4bef65f8076ef1f25ac012fc81..47e87cff8e743c7727d371f7085634b9c3d5edd9 100644 --- a/module-services/service-cellular/CellularUrcHandler.hpp +++ b/module-services/service-cellular/CellularUrcHandler.hpp @@ -44,12 +44,12 @@ class CellularUrcHandler : public at::urc::UrcHandler * Gets the response that should be returned after handling Urc * @return */ - std::optional> getResponse() + std::optional> getResponse() { return std::move(response); }; private: ServiceCellular &cellularService; - std::optional> response; + std::optional> response; }; diff --git a/module-services/service-cellular/PacketData.cpp b/module-services/service-cellular/PacketData.cpp index a2ab7711f6095033734fa3e78578905d46e1445b..1e11b5d9f09fa925cc101d28fc834c8a01ddc2ae 100644 --- a/module-services/service-cellular/PacketData.cpp +++ b/module-services/service-cellular/PacketData.cpp @@ -3,12 +3,15 @@ #include "PacketData.hpp" +#include + #include #include #include #include #include #include + namespace at { namespace response diff --git a/module-services/service-cellular/PacketData.hpp b/module-services/service-cellular/PacketData.hpp index 6ae845540c7dd554604978121a1e771e625fff8c..d4f94097cea67ee14a583a14c3bc2522ae470102 100644 --- a/module-services/service-cellular/PacketData.hpp +++ b/module-services/service-cellular/PacketData.hpp @@ -7,7 +7,11 @@ #include #include "service-cellular/PacketDataTypes.hpp" -#include "service-cellular/ServiceCellular.hpp" + +#include + +class ServiceCellular; +class DLCChannel; namespace at { diff --git a/module-services/service-cellular/QMBNManager.cpp b/module-services/service-cellular/QMBNManager.cpp index a59e958e1ddcb7ef5ac774e9289b79fc769b4afa..b65cb52b2a64f5f1aedb23e7f4a379b4149952dd 100644 --- a/module-services/service-cellular/QMBNManager.cpp +++ b/module-services/service-cellular/QMBNManager.cpp @@ -5,6 +5,7 @@ #include "Utils.hpp" #include "response.hpp" #include +#include namespace at { diff --git a/module-services/service-cellular/QMBNManager.hpp b/module-services/service-cellular/QMBNManager.hpp index 899afb37d9ad5a86096f078b857da003898167e3..144ac9b54077d952374fa971b107079b18404724 100644 --- a/module-services/service-cellular/QMBNManager.hpp +++ b/module-services/service-cellular/QMBNManager.hpp @@ -4,7 +4,8 @@ #pragma once #include "Result.hpp" -#include "service-cellular/ServiceCellular.hpp" + +class DLCChannel; namespace nv_paths { diff --git a/module-services/service-cellular/RequestFactory.cpp b/module-services/service-cellular/RequestFactory.cpp index ee2b91a514584461c66740a832369125b7c7a59a..ef96332429659af019a321e96e3866e4297d096e 100644 --- a/module-services/service-cellular/RequestFactory.cpp +++ b/module-services/service-cellular/RequestFactory.cpp @@ -23,9 +23,9 @@ namespace cellular { RequestFactory::RequestFactory(const std::string &data, at::BaseChannel &channel, - CellularCallRequestMessage::RequestMode requestMode, - SimStatus simCardStatus) - : request(data), channel(channel), requestMode(requestMode), simStatus(simCardStatus) + cellular::api::CallMode callMode, + bool simInserted) + : request(data), channel(channel), callMode(callMode), simInserted(simInserted) { registerRequest(ImeiRegex, ImeiRequest::create); registerRequest(PasswordRegistrationRegex, PasswordRegistrationRequest::create); @@ -54,14 +54,14 @@ namespace cellular qeccnumResponse.eccNumbersNoSim.end(); if (isSimEmergency || isNoSimEmergency) { - if (simStatus == SimStatus::SimInsterted || isNoSimEmergency) { + if (simInserted || isNoSimEmergency) { return std::make_unique(request); } else { return std::make_unique(RejectRequest::RejectReason::NoSim, request); } } - else if (requestMode == CellularCallRequestMessage::RequestMode::Emergency) { + else if (callMode == cellular::api::CallMode::Emergency) { return std::make_unique(RejectRequest::RejectReason::NotAnEmergencyNumber, request); } return nullptr; @@ -116,7 +116,7 @@ namespace cellular } } - if (simStatus == SimStatus::SimSlotEmpty) { + if (!simInserted) { return std::make_unique(RejectRequest::RejectReason::NoSim, request); } return std::make_unique(request); diff --git a/module-services/service-cellular/ServiceCellular.cpp b/module-services/service-cellular/ServiceCellular.cpp index 4a1bc705ab97e8a3590a669acb87a7311223434e..8a5334c6262bd7062aeeb3c43746b3c0aa341197 100644 --- a/module-services/service-cellular/ServiceCellular.cpp +++ b/module-services/service-cellular/ServiceCellular.cpp @@ -95,83 +95,22 @@ #include #include -const char *ServiceCellular::serviceName = "ServiceCellular"; +#include "ServiceCellularPriv.hpp" +#include +#include + +const char *ServiceCellular::serviceName = cellular::service::name; inline constexpr auto cellularStack = 8000; using namespace cellular; - -const char *State::c_str(State::ST state) -{ - switch (state) { - case ST::Idle: - return "Idle"; - case ST::WaitForStartPermission: - return "WaitForStartPermission"; - case ST::PowerUpRequest: - return "PowerUpRequest"; - case ST::StatusCheck: - return "StatusCheck"; - case ST::PowerUpInProgress: - return "PowerUpInProgress"; - case ST::PowerUpProcedure: - return "PowerUpProcedure"; - case ST::BaudDetect: - return "BaudDetect"; - case ST::AudioConfigurationProcedure: - return "AudioConfigurationProcedure"; - case ST::APNConfProcedure: - return "APNConfProcedure"; - case ST::ModemOn: - return "ModemOn"; - case ST::URCReady: - return "URCReady"; - case ST::SimSelect: - return "SimSelect"; - case ST::Failed: - return "Failed"; - case ST::SanityCheck: - return "SanityCheck"; - case ST::SimInit: - return "SimInit"; - case ST::ModemFatalFailure: - return "ModemFatalFailure"; - case ST::CellularConfProcedure: - return "CellularStartConfProcedure"; - case ST::Ready: - return "Ready"; - case ST::PowerDownStarted: - return "PowerDownStarted"; - case ST::PowerDownWaiting: - return "PowerDownWaiting"; - case ST::PowerDown: - return "PowerDown"; - } - return ""; -} - -const char *State::c_str() -{ - return State::c_str(state); -} - -void State::set(ServiceCellular *owner, ST state) -{ - assert(owner); - LOG_DEBUG("GSM state: (%s) -> (%s)", c_str(this->state), c_str(state)); - this->state = state; - auto msg = std::make_shared(state); - owner->bus.sendMulticast(msg, sys::BusChannel::ServiceCellularNotifications); -} - -State::ST State::get() const -{ - return this->state; -} +using namespace cellular::msg; +using cellular::service::State; ServiceCellular::ServiceCellular() : sys::Service(serviceName, "", cellularStack, sys::ServicePriority::Idle), - phoneModeObserver{std::make_unique()} + phoneModeObserver{std::make_unique()}, + priv{std::make_unique(this)} { LOG_INFO("[ServiceCellular] Initializing"); @@ -258,7 +197,7 @@ void ServiceCellular::SleepTimerHandler() ? currentTime - lastCommunicationTimestamp : std::numeric_limits::max() - lastCommunicationTimestamp + currentTime; - if (!ongoingCall.isValid() && state.get() == cellular::State::ST::Ready && + if (!ongoingCall.isValid() && priv->state->get() == State::ST::Ready && timeOfInactivity >= constants::enterSleepModeTime.count()) { cmux->enterSleepMode(); cpuSentinel->ReleaseMinimumFrequency(); @@ -277,7 +216,7 @@ sys::ReturnCodes ServiceCellular::InitHandler() board = EventManagerServiceAPI::GetBoard(this); settings = std::make_unique(); - settings->init(service::ServiceProxy(shared_from_this())); + settings->init(::service::ServiceProxy(shared_from_this())); connectionManager = std::make_unique( utils::getNumericValue( @@ -286,7 +225,7 @@ sys::ReturnCodes ServiceCellular::InitHandler() settings->getValue(settings::Offline::connectionFrequency, settings::SettingsScope::Global)))), std::make_shared(*this)); - state.set(this, State::ST::WaitForStartPermission); + priv->state->set(State::ST::WaitForStartPermission); settings->registerValueChange( settings::Cellular::volte_on, [this](const std::string &value) { volteChanged(value); }, @@ -300,7 +239,7 @@ sys::ReturnCodes ServiceCellular::InitHandler() ongoingCall.setCpuSentinel(cpuSentinel); auto sentinelRegistrationMsg = std::make_shared(cpuSentinel); - bus.sendUnicast(sentinelRegistrationMsg, service::name::system_manager); + bus.sendUnicast(sentinelRegistrationMsg, ::service::name::system_manager); cmux->registerCellularDevice(); @@ -335,9 +274,6 @@ sys::ReturnCodes ServiceCellular::SwitchPowerModeHandler(const sys::ServicePower return sys::ReturnCodes::Success; } -void handleCellularSimNewPinDataMessage(CellularSimNewPinDataMessage *msg) -{} - void ServiceCellular::registerMessageHandlers() { phoneModeObserver->connect(this); @@ -350,32 +286,7 @@ void ServiceCellular::registerMessageHandlers() : PassthroughState::DISABLED); }); - connect(typeid(CellularSimCardPinLockStateRequestDataMessage), - [&](sys::Message * /*request*/) -> sys::MessagePointer { - return std::make_shared(isPinLocked()); - }); - - connect(typeid(CellularSimNewPinDataMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto msg = static_cast(request); - return std::make_shared( - changePin(SimCard::pinToString(msg->getOldPin()), SimCard::pinToString(msg->getNewPin()))); - }); - - connect(typeid(CellularSimCardLockDataMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto msg = static_cast(request); - return std::make_shared( - setPinLock(msg->getLock() == CellularSimCardLockDataMessage::SimCardLock::Locked, - SimCard::pinToString(msg->getPin())), - msg->getLock()); - }); - - connect(typeid(CellularChangeSimDataMessage), [&](sys::Message *request) -> sys::MessagePointer { - auto msg = static_cast(request); - Store::GSM::get()->selected = msg->getSim(); - bsp::cellular::sim::simSelect(); - bsp::cellular::sim::hotSwapTrigger(); - return std::make_shared(true); - }); + priv->connectSimCard(); connect(typeid(CellularStartOperatorsScanMessage), [&](sys::Message *request) -> sys::MessagePointer { auto msg = static_cast(request); @@ -450,8 +361,8 @@ void ServiceCellular::registerMessageHandlers() }); connect(typeid(CellularPowerStateChange), [&](sys::Message *request) -> sys::MessagePointer { - auto msg = static_cast(request); - nextPowerState = msg->getNewState(); + auto msg = static_cast(request); + priv->nextPowerState = msg->getNewState(); handle_power_state_change(); return sys::MessageNone{}; }); @@ -459,20 +370,21 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(sdesktop::developerMode::DeveloperModeRequest), [&](sys::Message *request) -> sys::MessagePointer { auto msg = static_cast(request); if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::CellularHotStartEvent)) { + priv->simCard->setChannel(nullptr); cmux->closeChannels(); ///> change state - simulate hot start handle_power_up_request(); } if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::CellularStateInfoRequestEvent)) { - auto event = std::make_unique(state.c_str()); + auto event = std::make_unique(priv->state->c_str()); auto message = std::make_shared(std::move(event)); - bus.sendUnicast(std::move(message), service::name::service_desktop); + bus.sendUnicast(std::move(message), ::service::name::service_desktop); } if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::CellularSleepModeInfoRequestEvent)) { auto event = std::make_unique( cmux->isCellularInSleepMode()); auto message = std::make_shared(std::move(event)); - bus.sendUnicast(std::move(message), service::name::service_desktop); + bus.sendUnicast(std::move(message), ::service::name::service_desktop); } if (typeid(*msg->event.get()) == typeid(sdesktop::developerMode::ATResponseEvent)) { auto channel = cmux->get(CellularMux::Channel::Commands); @@ -585,15 +497,6 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(CellularUSSDMessage), [&](sys::Message *request) -> sys::MessagePointer { return handleCellularUSSDMessage(request); }); - connect(typeid(CellularSimStateMessage), - [&](sys::Message *request) -> sys::MessagePointer { return handleSimStateMessage(request); }); - - connect(typeid(CellularSimPinDataMessage), - [&](sys::Message *request) -> sys::MessagePointer { return handleSimPinMessage(request); }); - - connect(typeid(CellularSimPukDataMessage), - [&](sys::Message *request) -> sys::MessagePointer { return handleSimPukMessage(request); }); - connect(typeid(cellular::StateChange), [&](sys::Message *request) -> sys::MessagePointer { return handleStateRequestMessage(request); }); @@ -618,9 +521,6 @@ void ServiceCellular::registerMessageHandlers() connect(typeid(CellularNewIncomingSMSNotification), [&](sys::Message *request) -> sys::MessagePointer { return handleNewIncomingSMSNotification(request); }); - connect(typeid(CellularSimReadyNotification), - [&](sys::Message *request) -> sys::MessagePointer { return handleSimReadyNotification(request); }); - connect(typeid(CellularSmsDoneNotification), [&](sys::Message *request) -> sys::MessagePointer { return handleSmsDoneNotification(request); }); @@ -632,9 +532,6 @@ void ServiceCellular::registerMessageHandlers() return handleNetworkStatusUpdateNotification(request); }); - connect(typeid(CellularSimNotReadyNotification), - [&](sys::Message *request) -> sys::MessagePointer { return handleSimNotReadyNotification(request); }); - connect(typeid(CellularUrcIncomingNotification), [&](sys::Message *request) -> sys::MessagePointer { return handleUrcIncomingNotification(request); }); @@ -771,7 +668,7 @@ bool ServiceCellular::handle_idle() bool ServiceCellular::handle_wait_for_start_permission() { auto msg = std::make_shared(); - bus.sendUnicast(msg, service::name::system_manager); + bus.sendUnicast(msg, ::service::name::system_manager); return true; } @@ -781,13 +678,13 @@ bool ServiceCellular::handle_power_up_request() cmux->selectAntenna(bsp::cellular::antenna::lowBand); switch (board) { case bsp::Board::T4: - state.set(this, State::ST::StatusCheck); + priv->state->set(State::ST::StatusCheck); break; case bsp::Board::T3: - state.set(this, State::ST::PowerUpProcedure); + priv->state->set(State::ST::PowerUpProcedure); break; case bsp::Board::Linux: - state.set(this, State::ST::PowerUpProcedure); + priv->state->set(State::ST::PowerUpProcedure); break; case bsp::Board::none: return false; @@ -811,7 +708,7 @@ bool ServiceCellular::handle_power_up_procedure() if (ret == CellularMux::ConfState::Success) { // it's on aka hot start. LOG_DEBUG("T3 - hot start"); - state.set(this, State::ST::CellularConfProcedure); + priv->state->set(State::ST::CellularConfProcedure); break; } else { @@ -820,7 +717,7 @@ bool ServiceCellular::handle_power_up_procedure() cmux->turnOnModem(); // if it's T3, then wait for status pin to become active, to align its starting position with T4 vTaskDelay(pdMS_TO_TICKS(8000)); - state.set(this, State::ST::PowerUpInProgress); + priv->state->set(State::ST::PowerUpInProgress); break; } } @@ -831,7 +728,7 @@ bool ServiceCellular::handle_power_up_procedure() if (ret == CellularMux::ConfState::Success) { // it's on aka hot start. LOG_DEBUG("Linux - hot start"); - state.set(this, State::ST::CellularConfProcedure); + priv->state->set(State::ST::CellularConfProcedure); break; } else { @@ -841,7 +738,7 @@ bool ServiceCellular::handle_power_up_procedure() vTaskDelay(pdMS_TO_TICKS(2000)); // give some 2 secs more for user input // if it's Linux (T3), then wait for status pin to become active, to align its starting position with T4 vTaskDelay(pdMS_TO_TICKS(8000)); - state.set(this, State::ST::PowerUpInProgress); + priv->state->set(State::ST::PowerUpInProgress); break; } } @@ -862,7 +759,7 @@ bool ServiceCellular::handle_power_up_in_progress_procedure(void) isAfterForceReboot = false; } - state.set(this, cellular::State::ST::BaudDetect); + priv->state->set(State::ST::BaudDetect); return true; } @@ -870,11 +767,11 @@ bool ServiceCellular::handle_baud_detect() { auto ret = cmux->baudDetectProcedure(); if (ret == CellularMux::ConfState::Success) { - state.set(this, cellular::State::ST::CellularConfProcedure); + priv->state->set(State::ST::CellularConfProcedure); return true; } else { - state.set(this, cellular::State::ST::ModemFatalFailure); + priv->state->set(State::ST::ModemFatalFailure); return false; } } @@ -895,7 +792,7 @@ bool ServiceCellular::handle_power_down_waiting() case bsp::Board::T3: // if it's T3, then wait for status pin to become inactive, to align with T4 vTaskDelay(pdMS_TO_TICKS(17000)); // according to docs this shouldn't be needed, but better be safe than Quectel - state.set(this, cellular::State::ST::PowerDown); + priv->state->set(State::ST::PowerDown); break; default: LOG_ERROR("Powering 'down an unknown device not handled"); @@ -920,10 +817,10 @@ bool ServiceCellular::handle_start_conf_procedure() // Start configuration procedure, if it's first run modem will be restarted auto confRet = cmux->confProcedure(); if (confRet == CellularMux::ConfState::Success) { - state.set(this, State::ST::AudioConfigurationProcedure); + priv->state->set(State::ST::AudioConfigurationProcedure); return true; } - state.set(this, State::ST::Failed); + priv->state->set(State::ST::Failed); return false; } @@ -935,7 +832,7 @@ bool ServiceCellular::handle_audio_conf_procedure() LOG_DEBUG("Setting baudrate %i baud", ATPortSpeeds_text[cmux->getStartParams().PortSpeed]); if (!cmux->getParser()->cmd(cmd)) { LOG_ERROR("Baudrate setup error"); - state.set(this, State::ST::Failed); + priv->state->set(State::ST::Failed); return false; } cmux->getCellular()->setSpeed(ATPortSpeeds_text[cmux->getStartParams().PortSpeed]); @@ -945,6 +842,8 @@ bool ServiceCellular::handle_audio_conf_procedure() LOG_DEBUG("[ServiceCellular] Modem is fully operational"); + priv->simCard->setChannel(cmux->get(CellularMux::Channel::Commands)); + // open channel - notifications DLCChannel *notificationsChannel = cmux->get(CellularMux::Channel::Notifications); if (notificationsChannel != nullptr) { @@ -962,26 +861,26 @@ bool ServiceCellular::handle_audio_conf_procedure() connectionManager->setInterval(std::chrono::minutes{interval}); } if (!connectionManager->onPhoneModeChange(phoneModeObserver->getCurrentPhoneMode())) { - state.set(this, State::ST::Failed); + priv->state->set(State::ST::Failed); LOG_ERROR("Failed to handle phone mode"); return false; } - state.set(this, State::ST::APNConfProcedure); + priv->state->set(State::ST::APNConfProcedure); return true; } else { - state.set(this, State::ST::Failed); + priv->state->set(State::ST::Failed); return false; } } else if (audioRet == CellularMux::ConfState::Failure) { /// restart - state.set(this, State::ST::AudioConfigurationProcedure); + priv->state->set(State::ST::AudioConfigurationProcedure); return true; } // Reset procedure started, do nothing here - state.set(this, State::ST::Idle); + priv->state->set(State::ST::Idle); return true; } @@ -1020,7 +919,7 @@ auto ServiceCellular::handle(db::query::SMSSearchByTypeResult *response) -> bool * any AT commands is not allowed here (also in URC handlers and other functions called from here) * @return */ -std::optional> ServiceCellular::identifyNotification(const std::string &data) +std::optional> ServiceCellular::identifyNotification(const std::string &data) { CellularUrcHandler urcHandler(*this); @@ -1040,257 +939,6 @@ std::optional> ServiceCellular::identifyNotific return urcHandler.getResponse(); } -bool ServiceCellular::requestPin(unsigned int attempts, const std::string msg) -{ - auto message = std::make_shared(Store::GSM::get()->selected, attempts, msg); - bus.sendUnicast(message, app::manager::ApplicationManager::ServiceName); - LOG_DEBUG("REQUEST PIN"); - return true; -} - -bool ServiceCellular::requestPuk(unsigned int attempts, const std::string msg) -{ - auto message = std::make_shared(Store::GSM::get()->selected, attempts, msg); - bus.sendUnicast(message, app::manager::ApplicationManager::ServiceName); - LOG_DEBUG("REQUEST PUK"); - return true; -} - -bool ServiceCellular::sendSimUnlocked() -{ - auto message = std::make_shared(Store::GSM::get()->selected); - bus.sendUnicast(message, app::manager::ApplicationManager::ServiceName); - LOG_DEBUG("SIM UNLOCKED"); - return true; -} - -bool ServiceCellular::sendSimBlocked() -{ - auto message = std::make_shared(Store::GSM::get()->selected); - bus.sendUnicast(message, app::manager::ApplicationManager::ServiceName); - LOG_ERROR("SIM BLOCKED"); - return true; -} - -bool ServiceCellular::sendUnhandledCME(unsigned int cme_error) -{ - auto message = std::make_shared(Store::GSM::get()->selected, cme_error); - bus.sendUnicast(message, app::manager::ApplicationManager::ServiceName); - LOG_ERROR("UNHANDLED CME %d", cme_error); - return true; -} - -bool ServiceCellular::sendBadPin() -{ - LOG_DEBUG("SEND BAD PIN"); - SimCard simCard(*this); - std::string msg; - if (auto state = simCard.simStateWithMessage(msg); state) { - return handleSimState(*state, msg); - } - return false; -} - -bool ServiceCellular::sendBadPuk() -{ - LOG_DEBUG("SEND BAD PUK"); - SimCard simCard(*this); - std::string msg; - if (auto state = simCard.simStateWithMessage(msg); state) { - return handleSimState(*state, msg); - } - return false; -} - -bool ServiceCellular::sendChangePinResult(SimCardResult res) -{ - LOG_DEBUG("SEND CHANGE PIN RESULT"); - return true; -} - -bool ServiceCellular::isPinLocked() -{ - SimCard simCard(*this); - return simCard.isPinLocked(); -} - -bool ServiceCellular::changePin(const std::string oldPin, const std::string newPin) -{ - SimCard simCard(*this); - auto result = simCard.changePin(oldPin, newPin); - sendChangePinResult(result); - return result == SimCardResult::OK; -} - -bool ServiceCellular::setPinLock(bool lock, const std::string pin) -{ - SimCard simCard(*this); - auto result = simCard.setPinLock(lock, pin); - return result == SimCardResult::OK; -} - -bool ServiceCellular::unlockSimPin(std::string pin) -{ - LOG_ERROR("Unlock pin %s", pin.c_str()); - SimCard simCard(*this); - SimCardResult sime; - sime = simCard.supplyPin(pin); - - if (sime == SimCardResult::IncorrectPassword) { - sendBadPin(); - return false; - } - - if (sime == SimCardResult::OK) { - return true; - } - else { - sendUnhandledCME(static_cast(sime)); - return false; - } -} - -bool ServiceCellular::unlockSimPuk(std::string puk, std::string pin) -{ - SimCard simCard(*this); - SimCardResult sime; - LOG_DEBUG("PUK: %s %s", puk.c_str(), pin.c_str()); - sime = simCard.supplyPuk(puk, pin); - - if (sime == SimCardResult::IncorrectPassword) { - sendBadPuk(); - return false; - } - - if (sime == SimCardResult::OK) { - return true; - } - sendUnhandledCME(static_cast(sime)); - return false; -} - -auto ServiceCellular::handleSimPinMessage(sys::Message *msgl) -> std::shared_ptr -{ - - auto msgSimPin = dynamic_cast(msgl); - if (msgSimPin != nullptr) { - LOG_DEBUG("Unlocking sim"); - return std::make_shared(unlockSimPin(SimCard::pinToString(msgSimPin->getPin()))); - } - LOG_ERROR("Request message is not CellularSimPinDataMessage!"); - return std::make_shared(false); -} - -auto ServiceCellular::handleSimPukMessage(sys::Message *msgl) -> std::shared_ptr -{ - auto msgSimPuk = dynamic_cast(msgl); - if (msgSimPuk != nullptr) { - LOG_DEBUG("Unlocking puk"); - return std::make_shared( - unlockSimPuk(SimCard::pinToString(msgSimPuk->getPuk()), SimCard::pinToString(msgSimPuk->getNewPin()))); - } - LOG_ERROR("Request message is not CellularSimPukDataMessage!"); - return std::make_shared(false); -} - -bool ServiceCellular::handleSimState(at::SimState state, const std::string message) -{ - - std::shared_ptr response; - switch (state) { - case at::SimState::Ready: - Store::GSM::get()->sim = Store::GSM::get()->selected; - settings->setValue(settings::SystemProperties::activeSim, - utils::enumToString(Store::GSM::get()->selected), - settings::SettingsScope::Global); - // SIM causes SIM INIT, only on ready - response = std::move(std::make_unique()); - bus.sendMulticast(response, sys::BusChannel::ServiceCellularNotifications); - sendSimUnlocked(); - break; - case at::SimState::NotReady: - LOG_DEBUG("Not ready"); - Store::GSM::get()->sim = Store::GSM::SIM::SIM_FAIL; - response = std::move(std::make_unique()); - bus.sendMulticast(response, sys::BusChannel::ServiceCellularNotifications); - break; - case at::SimState::SimPin: { - SimCard simCard(*this); - if (auto pc = simCard.getAttemptsCounters(); pc) { - if (pc.value().PukCounter != 0) { - requestPin(pc.value().PinCounter, message); - break; - } - } - sendSimBlocked(); - break; - } - case at::SimState::SimPuk: { - SimCard simCard(*this); - if (auto pc = simCard.getAttemptsCounters(); pc) { - if (pc.value().PukCounter != 0) { - requestPuk(pc.value().PukCounter, message); - break; - } - } - sendSimBlocked(); - break; - } - case at::SimState::SimPin2: { - SimCard simCard(*this); - if (auto pc = simCard.getAttemptsCounters(SimPinType::SimPin2); pc) { - if (pc.value().PukCounter != 0) { - requestPin(pc.value().PinCounter, message); - break; - } - } - sendSimBlocked(); - break; - } - case at::SimState::SimPuk2: { - SimCard simCard(*this); - if (auto pc = simCard.getAttemptsCounters(SimPinType::SimPin2); pc) { - if (pc.value().PukCounter != 0) { - requestPuk(pc.value().PukCounter, message); - break; - } - } - sendSimBlocked(); - break; - } - case at::SimState::PhNetPin: - [[fallthrough]]; - case at::SimState::PhNetPuk: - [[fallthrough]]; - case at::SimState::PhNetSPin: - [[fallthrough]]; - case at::SimState::PhNetSPuk: - [[fallthrough]]; - case at::SimState::PhSpPin: - [[fallthrough]]; - case at::SimState::PhSpPuk: - [[fallthrough]]; - case at::SimState::PhCorpPin: - [[fallthrough]]; - case at::SimState::PhCorpPuk: - Store::GSM::get()->sim = Store::GSM::SIM::SIM_UNKNOWN; - LOG_ERROR("SimState not supported"); - break; - case at::SimState::Locked: - Store::GSM::get()->sim = Store::GSM::SIM::SIM_FAIL; - sendSimBlocked(); - break; - case at::SimState::Unknown: - LOG_ERROR("SimState not supported"); - Store::GSM::get()->sim = Store::GSM::SIM::SIM_UNKNOWN; - break; - } - auto simMessage = std::make_shared(); - bus.sendUnicast(simMessage, service::name::evt_manager); - - return true; -} - auto ServiceCellular::sendSMS(SMSRecord record) -> bool { LOG_INFO("Trying to send SMS"); @@ -1713,12 +1361,12 @@ bool ServiceCellular::handle_sim_sanity_check() { auto ret = sim_check_hot_swap(cmux->get(CellularMux::Channel::Commands)); if (ret) { - state.set(this, State::ST::ModemOn); + priv->state->set(State::ST::ModemOn); bsp::cellular::sim::simSelect(); } else { LOG_ERROR("Sanity check failure - user will be promped about full shutdown"); - state.set(this, State::ST::ModemFatalFailure); + priv->state->set(State::ST::ModemFatalFailure); } return ret; } @@ -1743,7 +1391,7 @@ bool ServiceCellular::handle_select_sim() // NO SIM IN Store::GSM::get()->sim = Store::GSM::SIM::SIM_FAIL; } - bus.sendUnicast(std::make_shared(), service::name::evt_manager); + bus.sendUnicast(std::make_shared(), ::service::name::evt_manager); bool ready = false; while (!ready) { auto response = channel->cmd("AT+CPIN?"); @@ -1753,7 +1401,7 @@ bool ServiceCellular::handle_select_sim() } } } - state.set(this, cellular::State::ST::SimInit); + priv->state->set(State::ST::SimInit); } #endif return true; @@ -1765,7 +1413,7 @@ bool ServiceCellular::handle_modem_on() channel->cmd("AT+CCLK?"); // inform host ap ready cmux->informModemHostWakeup(); - state.set(this, State::ST::URCReady); + priv->state->set(State::ST::URCReady); LOG_DEBUG("AP ready"); return true; } @@ -1780,7 +1428,7 @@ bool ServiceCellular::handle_URCReady() } ret = ret && channel->cmd(at::AT::ENABLE_NETWORK_REGISTRATION_URC); - LOG_DEBUG("%s", state.c_str()); + LOG_DEBUG("%s", priv->state->c_str()); return ret; } @@ -1789,7 +1437,7 @@ bool ServiceCellular::handle_sim_init() auto channel = cmux->get(CellularMux::Channel::Commands); if (channel == nullptr) { LOG_ERROR("Cant configure sim! no Commands channel!"); - state.set(this, State::ST::Failed); + priv->state->set(State::ST::Failed); return false; } bool success = true; @@ -1802,7 +1450,7 @@ bool ServiceCellular::handle_sim_init() } } - state.set(this, State::ST::Ready); + priv->state->set(State::ST::Ready); return success; } @@ -1896,7 +1544,7 @@ bool ServiceCellular::receiveAllMessages() bool ServiceCellular::handle_failure() { - state.set(this, State::ST::Idle); + priv->state->set(State::ST::Idle); return true; } @@ -1911,7 +1559,7 @@ bool ServiceCellular::handle_fatal_failure() bool ServiceCellular::handle_ready() { - LOG_DEBUG("%s", state.c_str()); + LOG_DEBUG("%s", priv->state->c_str()); sleepTimer.start(); return true; } @@ -1986,10 +1634,10 @@ bool ServiceCellular::handle_status_check(void) // modem is already turned on, call configutarion procedure LOG_INFO("Modem is already turned on."); LOG_DEBUG("T4 - hot start"); - state.set(this, cellular::State::ST::PowerUpInProgress); + priv->state->set(State::ST::PowerUpInProgress); } else { - state.set(this, cellular::State::ST::PowerUpProcedure); + priv->state->set(State::ST::PowerUpProcedure); } return true; } @@ -2011,8 +1659,8 @@ void ServiceCellular::handleStateTimer(void) stateTimeout--; if (stateTimeout == 0) { stopStateTimer(); - LOG_FATAL("State %s timeout occured!", state.c_str(state.get())); - state.set(this, cellular::State::ST::ModemFatalFailure); + LOG_FATAL("State %s timeout occured!", priv->state->c_str()); + priv->state->set(State::ST::ModemFatalFailure); } } @@ -2021,41 +1669,43 @@ void ServiceCellular::handle_power_state_change() nextPowerStateChangeAwaiting = false; auto modemActive = cmux->isModemActive(); - if (nextPowerState == State::PowerState::On) { - if (state.get() == State::ST::PowerDownWaiting) { + if (priv->nextPowerState == State::PowerState::On) { + if (priv->state->get() == State::ST::PowerDownWaiting) { LOG_DEBUG("Powerdown in progress. Powerup request queued."); nextPowerStateChangeAwaiting = true; } - else if (state.get() == State::ST::PowerUpProcedure || state.get() == State::ST::PowerUpInProgress) { + else if (priv->state->get() == State::ST::PowerUpProcedure || + priv->state->get() == State::ST::PowerUpInProgress) { LOG_DEBUG("Powerup already in progress"); } - else if (state.get() == State::ST::PowerDown || state.get() == State::ST::WaitForStartPermission) { + else if (priv->state->get() == State::ST::PowerDown || + priv->state->get() == State::ST::WaitForStartPermission) { LOG_INFO("Modem Power UP."); - state.set(this, State::ST::PowerUpRequest); + priv->state->set(State::ST::PowerUpRequest); } else { LOG_DEBUG("Modem already powered up."); } } else { - if (state.get() == State::ST::PowerUpProcedure || state.get() == State::ST::PowerUpInProgress) { + if (priv->state->get() == State::ST::PowerUpProcedure || priv->state->get() == State::ST::PowerUpInProgress) { LOG_DEBUG("Powerup in progress. Powerdown request queued."); nextPowerStateChangeAwaiting = true; } - else if (state.get() == State::ST::PowerDownWaiting) { + else if (priv->state->get() == State::ST::PowerDownWaiting) { LOG_DEBUG("Powerdown already in progress."); } - else if (state.get() == State::ST::PowerDown) { + else if (priv->state->get() == State::ST::PowerDown) { LOG_DEBUG("Modem already powered down."); } - else if (state.get() == State::ST::WaitForStartPermission && !modemActive) { + else if (priv->state->get() == State::ST::WaitForStartPermission && !modemActive) { LOG_DEBUG("Modem already powered down."); - state.set(this, State::ST::PowerDown); + priv->state->set(State::ST::PowerDown); } else { LOG_INFO("Modem Power DOWN."); cmux->turnOffModem(); - state.set(this, State::ST::PowerDownWaiting); + priv->state->set(State::ST::PowerDownWaiting); } } } @@ -2145,7 +1795,7 @@ bool ServiceCellular::handle_apn_conf_procedure() { LOG_DEBUG("APN on modem configuration"); packetData->setupAPNSettings(); - state.set(this, State::ST::SanityCheck); + priv->state->set(State::ST::SanityCheck); return true; } @@ -2287,11 +1937,8 @@ auto ServiceCellular::handleCellularCallRequestMessage(CellularCallRequestMessag return std::make_shared(false); } - cellular::RequestFactory factory(msg->number.getEntered(), - *channel, - msg->requestMode, - Store::GSM::get()->simCardInserted() ? RequestFactory::SimStatus::SimInsterted - : RequestFactory::SimStatus::SimSlotEmpty); + cellular::RequestFactory factory( + msg->number.getEntered(), *channel, msg->callMode, Store::GSM::get()->simCardInserted()); auto request = factory.create(); @@ -2404,7 +2051,7 @@ auto ServiceCellular::handleCellularCallerIdMessage(sys::Message *msg) -> std::s auto ServiceCellular::handleCellularSimProcedureMessage(sys::Message *msg) -> std::shared_ptr { - state.set(this, State::ST::SimSelect); + priv->state->set(State::ST::SimSelect); return std::make_shared(true); } @@ -2489,17 +2136,17 @@ auto ServiceCellular::handleEVMStatusMessage(sys::Message *msg) -> std::shared_p if (board == bsp::Board::T4) { auto status_pin = message->state; if (status_pin == value::ACTIVE) { - if (state.get() == State::ST::PowerUpProcedure) { - state.set(this, State::ST::PowerUpInProgress); // and go to baud detect as usual + if (priv->state->get() == State::ST::PowerUpProcedure) { + priv->state->set(State::ST::PowerUpInProgress); // and go to baud detect as usual } else { // asynchronous power toggle should fall back to PowerDown regardless the state - state.set(this, State::ST::PowerDown); + priv->state->set(State::ST::PowerDown); } } else if (status_pin == value::INACTIVE) { - if (isAfterForceReboot == true || state.get() == State::ST::PowerDownWaiting) { - state.set(this, State::ST::PowerDown); + if (isAfterForceReboot == true || priv->state->get() == State::ST::PowerDownWaiting) { + priv->state->set(State::ST::PowerDown); } } } @@ -2559,12 +2206,6 @@ auto ServiceCellular::handleCellularUSSDMessage(sys::Message *msg) -> std::share return std::make_shared(handleUSSDRequest(message->type, message->data)); } -auto ServiceCellular::handleSimStateMessage(sys::Message *msg) -> std::shared_ptr -{ - auto message = static_cast(msg); - return std::make_shared(handleSimState(message->getState(), message->getMessage())); -} - auto ServiceCellular::handleStateRequestMessage(sys::Message *msg) -> std::shared_ptr { change_state(dynamic_cast(msg)); @@ -2585,15 +2226,15 @@ auto ServiceCellular::handlePowerUpProcedureCompleteNotification(sys::Message *m -> std::shared_ptr { if (board == bsp::Board::T3 || board == bsp::Board::Linux) { - state.set(this, State::ST::CellularConfProcedure); + priv->state->set(State::ST::CellularConfProcedure); } return std::make_shared(true); } auto ServiceCellular::handlePowerDownDeregisteringNotification(sys::Message *msg) -> std::shared_ptr { - if (state.get() != State::ST::PowerDownWaiting) { - state.set(this, State::ST::PowerDownStarted); + if (priv->state->get() != State::ST::PowerDownWaiting) { + priv->state->set(State::ST::PowerDownStarted); return std::make_shared(true); } return std::make_shared(false); @@ -2601,7 +2242,7 @@ auto ServiceCellular::handlePowerDownDeregisteringNotification(sys::Message *msg auto ServiceCellular::handlePowerDownDeregisteredNotification(sys::Message *msg) -> std::shared_ptr { - state.set(this, State::ST::PowerDownWaiting); + priv->state->set(State::ST::PowerDownWaiting); return std::make_shared(true); } auto ServiceCellular::handleNewIncomingSMSNotification(sys::Message *msg) -> std::shared_ptr @@ -2612,14 +2253,6 @@ auto ServiceCellular::handleNewIncomingSMSNotification(sys::Message *msg) -> std return std::make_shared(true); } -auto ServiceCellular::handleSimReadyNotification(sys::Message *msg) -> std::shared_ptr -{ - if (Store::GSM::get()->tray == Store::GSM::Tray::IN) { - state.set(this, cellular::State::ST::SimInit); - } - return std::make_shared(true); -} - auto ServiceCellular::handleSmsDoneNotification(sys::Message *msg) -> std::shared_ptr { auto resp = handleTextMessagesInit(); @@ -2634,11 +2267,6 @@ auto ServiceCellular::handleNetworkStatusUpdateNotification(sys::Message *msg) - return std::make_shared(false); } -auto ServiceCellular::handleSimNotReadyNotification(sys::Message *msg) -> std::shared_ptr -{ - return std::make_shared(false); -} - auto ServiceCellular::handleUrcIncomingNotification(sys::Message *msg) -> std::shared_ptr { // when handling URC, the CPU frequency does not go below a certain level diff --git a/module-services/service-cellular/SimCard.cpp b/module-services/service-cellular/SimCard.cpp deleted file mode 100644 index fea40eebda9ac59d4d860fbc64c525393384c787..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/SimCard.cpp +++ /dev/null @@ -1,178 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "SimCard.hpp" -#include -#include -#include "Result.hpp" -#include "UrcCpin.hpp" //for Cpin parseState -#include "UrcFactory.hpp" -#include -#include - -SimCardResult SimCard::convertErrorFromATResult(const at::Result atres) const -{ - if (std::holds_alternative(atres.errorCode)) { - - auto cerr = static_cast(std::get(atres.errorCode)); - if ((cerr > static_cast(SimCardResult::AT_ERROR_Begin)) && - (cerr < static_cast(SimCardResult::AT_ERROR_End))) { - return static_cast(cerr); - } - } - return SimCardResult::Unknown; -} - -std::optional SimCard::getAttemptsCounters(const std::string &type) const -{ - auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); - if (channel) { - auto resp = channel->cmd(at::factory(at::AT::QPINC) + "\"" + type + "\""); - at::response::qpinc::AttemptsCounters ret; - if (at::response::parseQPINC(resp, ret)) { - return ret; - } - } - - return std::nullopt; -} - -SimCardResult SimCard::supplyPin(const std::string pin) const -{ - if (auto pc = getAttemptsCounters(); pc) { - if (pc.value().PinCounter > 0) { - if (auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); channel) { - auto resp = channel->cmd(at::factory(at::AT::CPIN) + "\"" + pin + "\""); - - if (resp.code == at::Result::Code::OK) { - return SimCardResult::OK; - } - else { - return convertErrorFromATResult(resp); - } - } - } - else { - if (pc.value().PukCounter > 0) { - return SimCardResult::SIM_PUKRequired; - } - else { - return SimCardResult::Locked; - } - } - } - return SimCardResult::Unknown; -} - -SimCardResult SimCard::supplyPuk(const std::string puk, const std::string pin) const -{ - if (auto pc = getAttemptsCounters(); pc) { - if (pc.value().PukCounter != 0) { - if (auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); channel) { - auto resp = channel->cmd(at::factory(at::AT::CPIN) + "\"" + puk + "\"" + ",\"" + pin + "\""); - if (resp.code == at::Result::Code::OK) { - return SimCardResult::OK; - } - else { - return convertErrorFromATResult(resp); - } - } - } - else { - return SimCardResult::Locked; - } - } - - return SimCardResult::Unknown; -} - -bool SimCard::isPinLocked() const -{ - if (auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); channel) { - auto resp = channel->cmd(at::factory(at::AT::CLCK) + "\"SC\",2\r"); - int val = 0; - if (at::response::parseCLCK(resp, val)) { - return val != 0; - } - } - return true; -} - -SimCardResult SimCard::setPinLock(bool lock, const std::string &pin) const -{ - if (auto pc = getAttemptsCounters(); pc) { - if (pc.value().PukCounter != 0) { - auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); - if (channel) { - auto resp = - channel->cmd(at::factory(at::AT::CLCK) + "\"SC\"," + (lock ? "1" : "0") + ",\"" + pin + "\""); - if (resp.code == at::Result::Code::OK) { - return SimCardResult::OK; - } - else { - return convertErrorFromATResult(resp); - } - } - } - else { - return SimCardResult::Locked; - } - } - - return SimCardResult::Unknown; -} - -SimCardResult SimCard::changePin(const std::string oldPin, const std::string newPin) const -{ - if (auto pc = getAttemptsCounters(); pc) { - if (pc.value().PukCounter != 0) { - auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); - if (channel) { - auto resp = channel->cmd(at::factory(at::AT::CPWD) + "\"SC\", \"" + oldPin + "\",\"" + newPin + "\""); - if (resp.code == at::Result::Code::OK) { - return SimCardResult::OK; - } - else { - return convertErrorFromATResult(resp); - } - } - } - else { - return SimCardResult::Locked; - } - } - - return SimCardResult::Unknown; -} - -std::optional SimCard::simState() const -{ - std::string buf; - return simStateWithMessage(buf); -} - -std::optional SimCard::simStateWithMessage(std::string &message) const -{ - if (auto channel = cellularService.cmux->get(CellularMux::Channel::Commands); channel) { - auto resp = channel->cmd(at::factory(at::AT::GET_CPIN)); - if (resp.code == at::Result::Code::OK) { - if (resp.response.size()) { - for (auto el : resp.response) { - auto urc = at::urc::UrcFactory::Create(el); - auto cpin = std::unique_ptr{static_cast(urc.release())}; - if (cpin) { - return cpin->getState(); - } - } - } - } - } - return at::SimState::Unknown; -} - -std::string SimCard::pinToString(std::vector v) -{ - std::string buf; - std::transform(v.begin(), v.end(), std::back_inserter(buf), [](auto &&c) { return '0' + c; }); - return buf; -} diff --git a/module-services/service-cellular/SimCard.hpp b/module-services/service-cellular/SimCard.hpp deleted file mode 100644 index 5edf3c5c9690a03f6fef42e46e35bd71e777e0fa..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/SimCard.hpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include - -#include - -#include "service-cellular/SimCardResult.hpp" -#include "service-cellular/CellularMessage.hpp" -#include "service-cellular/CellularServiceAPI.hpp" -#include "service-cellular/ServiceCellular.hpp" -#include "response.hpp" - -class SimCard -{ - public: - explicit SimCard(ServiceCellular &cellularService) : cellularService(cellularService) - {} - - /** Get information about attempts of PIN and PUK for standard sim card (eg. not PIN2) - * @return As optional SimCard::AttemptsCounters, in case of error nullopt. Should be noted that in some case could - * return SIMFailure which could mean 0 attempts (happen if lock during session, on modem/sim reboot again return - * 0,0); - */ - std::optional getAttemptsCounters( - const std::string &type = SimPinType::SimPin) const; - - /** Supply pin for modem - * \param pin digits as a string from 4-8 digits - * \return return OK on success in other case see details in SimCardResult - */ - SimCardResult supplyPin(const std::string pin) const; - - /** Supply pin for modem - * \param puk puk as standard 8 digits - * \param pin, new pin digits as a string from 4-8 digits - * \return return OK on success in other case see details in SimCardResult - */ - SimCardResult supplyPuk(const std::string puk, const std::string pin) const; - - /** return whether the pin needs to be provided, only for standard pin. - * \return true if need pin to unlock SIM card functionality - */ - bool isPinLocked() const; - - /** Set whether to provide pin. Always need to provide actual pin for sim card, only for standard PIN - * \param lock true for lock SIM card - * \param pin actual pin for SIM card - * \return - */ - SimCardResult setPinLock(bool lock, const std::string &pin) const; - - /** Change pin, only for standard pin. To get effect of change pin, SIM cart or modem should be restarted - * simplest solution is to call AT+CFUN=0/1 - * \param oldPin - * \param newPin - * \return return OK on success, else see SimCardResult - */ - SimCardResult changePin(const std::string oldPin, const std::string newPin) const; - - /** Return SIM state based on CPIN AT commands - */ - std::optional simState() const; - std::optional simStateWithMessage(std::string &message) const; - - static std::string pinToString(std::vector v); - - private: - ServiceCellular &cellularService; - - /** Helper function to convert from one enum to another (only with part of them). Base on continuous range of sim - * errors in AT. - */ - SimCardResult convertErrorFromATResult(const at::Result) const; -}; diff --git a/module-services/service-cellular/include/service-cellular/state.hpp b/module-services/service-cellular/include/service-cellular/State.hpp similarity index 100% rename from module-services/service-cellular/include/service-cellular/state.hpp rename to module-services/service-cellular/include/service-cellular/State.hpp diff --git a/module-services/service-cellular/include/service-cellular/api/common.hpp b/module-services/service-cellular/include/service-cellular/api/common.hpp index 31c8dccd4c0745b5b19ae8a9ecb46fe3377c05ea..6b494b5c410912139261ece167966c1504087914 100644 --- a/module-services/service-cellular/include/service-cellular/api/common.hpp +++ b/module-services/service-cellular/include/service-cellular/api/common.hpp @@ -22,8 +22,8 @@ namespace cellular enum class SimLockState { - Locked, - Unlocked + Enabled, + Disabled }; enum class SimSlot diff --git a/module-services/service-cellular/include/service-cellular/api/request/sim.hpp b/module-services/service-cellular/include/service-cellular/api/request/sim.hpp index 97f7445f7d9530f4f80802bf39978f5287f3f66e..0833e0ba5c96f2fa11401b889dc8014ce0d27f71 100644 --- a/module-services/service-cellular/include/service-cellular/api/request/sim.hpp +++ b/module-services/service-cellular/include/service-cellular/api/request/sim.hpp @@ -15,7 +15,11 @@ namespace cellular::msg::request::sim {} const api::SimSlot sim; - using Response = msg::Response; + struct Response : msg::Response + { + explicit Response(bool retCode) : msg::Response(retCode) + {} + }; }; /** Get current state of PIN lock @@ -38,7 +42,11 @@ namespace cellular::msg::request::sim {} const api::SimCode pin; - using Response = msg::Response; + struct Response : msg::Response + { + explicit Response(bool retCode) : msg::Response(retCode) + {} + }; }; /** Change current PIN @@ -50,7 +58,11 @@ namespace cellular::msg::request::sim const api::SimCode oldPin; const api::SimCode pin; - using Response = msg::Response; + struct Response : msg::Response + { + explicit Response(bool retCode) : msg::Response(retCode) + {} + }; }; /** Reset PIN using PUK @@ -62,7 +74,11 @@ namespace cellular::msg::request::sim const api::SimCode puk; const api::SimCode pin; - using Response = msg::Response; + struct Response : msg::Response + { + explicit Response(bool retCode) : msg::Response(retCode) + {} + }; }; /** Enable or disable PIN lock on SIM diff --git a/module-services/service-cellular/service-cellular/CellularMessage.hpp b/module-services/service-cellular/service-cellular/CellularMessage.hpp index a0a0591a6bd633443f5593ae79b1d3974657d24b..fa2cea55b2922de1ce12b5c9df9c2b9eb336f5eb 100644 --- a/module-services/service-cellular/service-cellular/CellularMessage.hpp +++ b/module-services/service-cellular/service-cellular/CellularMessage.hpp @@ -4,9 +4,8 @@ #pragma once #include "SignalStrength.hpp" -#include "State.hpp" +#include -#include #include #include #include @@ -24,6 +23,8 @@ #include #include +#include + class CellularMessage : public sys::DataMessage { public: @@ -41,9 +42,8 @@ class CellularMessage : public sys::DataMessage PowerStateChange, ///< Change power state of the module ListCurrentCalls, - SimProcedure, // Broadcast on sim state changed - SimResponse, // Send to PIN window (show, error state, hide) - SimVerifyPinRequest, // Send from PIN window with PIN, PUK, ... number + SimProcedure, // Broadcast on sim state changed + SimResponse, // Send to PIN window (show, error state, hide) SetVoLTE, SetFlightMode, @@ -139,8 +139,6 @@ class CellularNotificationMessage : public CellularMessage NetworkStatusUpdate, // update of the status of the network PowerUpProcedureComplete, // modem without cmux on initialization complete (cold start || reset modem -> and // cold start) - SIM_READY, // change on SIM from URC - SIM_NOT_READY, // change to not existing/not valid SIM PowerDownDeregistering, // modem informed it has started to disconnect from network PowerDownDeregistered, // modem informed it has disconnected from network SMSDone, // SMS initialization finished @@ -217,17 +215,17 @@ class CellularSetOperatorMessage : public sys::DataMessage class CellularPowerStateChange : public CellularMessage { public: - explicit CellularPowerStateChange(cellular::State::PowerState new_state) + explicit CellularPowerStateChange(cellular::service::State::PowerState new_state) : CellularMessage(Type::PowerStateChange), newState(new_state) {} - cellular::State::PowerState getNewState() const noexcept + cellular::service::State::PowerState getNewState() const noexcept { return newState; } private: - cellular::State::PowerState newState; + cellular::service::State::PowerState newState; }; class CellularStartOperatorsScanMessage : public CellularMessage @@ -245,28 +243,6 @@ class CellularStartOperatorsScanMessage : public CellularMessage } }; -class CellularSimStateMessage : public CellularMessage -{ - private: - at::SimState state; - std::string message; - - public: - explicit CellularSimStateMessage(at::SimState state, std::string message) - : CellularMessage(Type::SimState), state(state), message(std::move(message)) - {} - - at::SimState getState() const noexcept - { - return state; - } - - std::string getMessage() const - { - return message; - } -}; - class CellularTimeNotificationMessage : public CellularMessage { private: @@ -354,17 +330,12 @@ class CellularAntennaRequestMessage : public CellularMessage class CellularCallRequestMessage : public CellularMessage { public: - enum class RequestMode - { - Normal, - Emergency - }; - - CellularCallRequestMessage(const utils::PhoneNumber::View &number, RequestMode requestMode = RequestMode::Normal) - : CellularMessage(Type::CallRequest), number(number), requestMode(requestMode) + CellularCallRequestMessage(const utils::PhoneNumber::View &number, + cellular::api::CallMode callMode = cellular::api::CallMode::Regular) + : CellularMessage(Type::CallRequest), number(number), callMode(callMode) {} utils::PhoneNumber::View number; - RequestMode requestMode = RequestMode::Normal; + cellular::api::CallMode callMode = cellular::api::CallMode::Regular; }; class CellularSmsNoSimRequestMessage : public CellularMessage, public app::manager::actions::ConvertibleToAction @@ -380,267 +351,6 @@ class CellularSmsNoSimRequestMessage : public CellularMessage, public app::manag } }; -class CellularSimMessage : public CellularMessage -{ - public: - CellularSimMessage(Type type, Store::GSM::SIM sim) : CellularMessage(type), sim(sim) - {} - virtual ~CellularSimMessage() = default; - Store::GSM::SIM getSimCard() const noexcept - { - return sim; - } - - private: - Store::GSM::SIM sim = defaultSimCard; - static const Store::GSM::SIM defaultSimCard = Store::GSM::SIM::SIM1; -}; - -/// Message use only for mockup GUI purposes -class CellularSimVerifyPinRequestMessage : public CellularSimMessage -{ - public: - CellularSimVerifyPinRequestMessage(Store::GSM::SIM sim, std::vector pinValue) - : CellularSimMessage(Type::SimVerifyPinRequest, sim), pinValue(std::move(pinValue)) - {} - CellularSimVerifyPinRequestMessage(Store::GSM::SIM sim, - std::vector pinValue, - std::vector pukValue) - : CellularSimMessage(Type::SimVerifyPinRequest, sim), pinValue(std::move(pinValue)), - pukValue(std::move(pukValue)) - {} - - std::vector getPinValue() const - { - return pinValue; - } - std::vector getPukValue() const - { - return pukValue; - } - - private: - std::vector pinValue; - std::vector pukValue; -}; - -class CellularSimPasscodeRequest : public CellularMessage -{ - protected: - app::manager::actions::PasscodeParams params; - - CellularSimPasscodeRequest(Store::GSM::SIM _sim, unsigned int _attempts, std::string _passcodeName) - : CellularMessage(Type::SimResponse), params(_sim, _attempts, std::move(_passcodeName)) - {} -}; - -class CellularSimRequestPinMessage : public CellularSimPasscodeRequest, - public app::manager::actions::ConvertibleToAction -{ - public: - CellularSimRequestPinMessage(Store::GSM::SIM _sim, unsigned int _attempts, std::string _passcodeName) - : CellularSimPasscodeRequest(_sim, _attempts, std::move(_passcodeName)) - {} - - [[nodiscard]] auto toAction() const -> std::unique_ptr - { - return std::make_unique( - sender, app::manager::actions::RequestPin, std::make_unique(params)); - } -}; - -class CellularSimRequestPukMessage : public CellularSimPasscodeRequest, - public app::manager::actions::ConvertibleToAction -{ - public: - CellularSimRequestPukMessage(Store::GSM::SIM _sim, unsigned int _attempts, std::string _passcodeName) - : CellularSimPasscodeRequest(_sim, _attempts, std::move(_passcodeName)) - {} - - [[nodiscard]] auto toAction() const -> std::unique_ptr - { - return std::make_unique( - sender, app::manager::actions::RequestPuk, std::make_unique(params)); - } -}; - -class CellularUnlockSimMessage : public CellularMessage, public app::manager::actions::ConvertibleToAction -{ - app::manager::actions::SimStateParams params; - - public: - CellularUnlockSimMessage(Store::GSM::SIM _sim) : CellularMessage(Type::SimResponse), params(_sim) - {} - - [[nodiscard]] auto toAction() const -> std::unique_ptr - { - return std::make_unique( - sender, app::manager::actions::UnlockSim, std::make_unique(params)); - } -}; - -class CellularBlockSimMessage : public CellularMessage, public app::manager::actions::ConvertibleToAction -{ - app::manager::actions::SimStateParams params; - - public: - explicit CellularBlockSimMessage(Store::GSM::SIM _sim) : CellularMessage(Type::SimResponse), params(_sim) - {} - - [[nodiscard]] auto toAction() const -> std::unique_ptr - { - return std::make_unique( - sender, app::manager::actions::BlockSim, std::make_unique(params)); - } -}; - -class CellularDisplayCMEMessage : public CellularMessage, public app::manager::actions::ConvertibleToAction -{ - app::manager::actions::UnhandledCMEParams params; - - public: - CellularDisplayCMEMessage(Store::GSM::SIM _sim, unsigned int _cmeCode) - : CellularMessage(Type::SimResponse), params(_sim, _cmeCode) - {} - - [[nodiscard]] auto toAction() const -> std::unique_ptr - { - return std::make_unique( - sender, - app::manager::actions::DisplayCMEError, - std::make_unique(params)); - } -}; - -class CellularSimDataMessage : public CellularMessage -{ - Store::GSM::SIM sim = Store::GSM::SIM::NONE; - - public: - explicit CellularSimDataMessage(Store::GSM::SIM _sim) : CellularMessage{Type::SimResponse}, sim{_sim} - {} - [[nodiscard]] Store::GSM::SIM getSim() const noexcept - { - return sim; - } -}; - -class CellularChangeSimDataMessage : public CellularSimDataMessage -{ - public: - CellularChangeSimDataMessage(Store::GSM::SIM _sim) : CellularSimDataMessage{_sim} - {} -}; - -class CellularSimPinDataMessage : public CellularSimDataMessage -{ - std::vector pinValue; - - public: - CellularSimPinDataMessage(Store::GSM::SIM _sim, std::vector _pinValue) - : CellularSimDataMessage{_sim}, pinValue{std::move(_pinValue)} - {} - - [[nodiscard]] const std::vector &getPin() const noexcept - { - return pinValue; - } -}; - -class CellularSimNewPinDataMessage : public CellularSimDataMessage -{ - std::vector oldPin; - std::vector newPin; - - public: - CellularSimNewPinDataMessage(Store::GSM::SIM _sim, - std::vector _oldPin, - std::vector _newPin) - : CellularSimDataMessage{_sim}, oldPin{std::move(_oldPin)}, newPin{std::move(_newPin)} - {} - - [[nodiscard]] const std::vector &getOldPin() const noexcept - { - return oldPin; - } - [[nodiscard]] const std::vector &getNewPin() const noexcept - { - return newPin; - } -}; - -class CellularSimCardPinLockStateRequestDataMessage : public sys::DataMessage -{}; - -class CellularSimCardPinLockStateResponseDataMessage : public sys::DataMessage -{ - public: - explicit CellularSimCardPinLockStateResponseDataMessage(bool state) : simCardPinLockState(state) - {} - - [[nodiscard]] bool getSimCardPinLockState() const noexcept - { - return simCardPinLockState; - } - - private: - const bool simCardPinLockState; -}; - -class CellularSimCardLockDataMessage : public CellularSimDataMessage -{ - - public: - enum class SimCardLock - { - Locked, - Unlocked - }; - CellularSimCardLockDataMessage(Store::GSM::SIM _sim, SimCardLock _simCardLock, std::vector _pin) - : CellularSimDataMessage{_sim}, simCardLock{_simCardLock}, pin{std::move(_pin)} - {} - - [[nodiscard]] SimCardLock getLock() const noexcept - { - return simCardLock; - } - [[nodiscard]] const std::vector &getPin() const noexcept - { - return pin; - } - - private: - SimCardLock simCardLock; - std::vector pin; -}; - -class CellularSimPukDataMessage : public CellularSimDataMessage -{ - std::vector puk; - std::vector newPin; - - public: - CellularSimPukDataMessage(Store::GSM::SIM _sim, std::vector _puk, std::vector _newPin) - : CellularSimDataMessage{_sim}, puk{std::move(_puk)}, newPin{std::move(_newPin)} - {} - - [[nodiscard]] const std::vector &getPuk() const noexcept - { - return puk; - } - [[nodiscard]] const std::vector &getNewPin() const noexcept - { - return newPin; - } -}; - -class CellularSimAbortMessage : public CellularSimDataMessage -{ - public: - explicit CellularSimAbortMessage(Store::GSM::SIM _sim) : CellularSimDataMessage{_sim} - {} -}; - class CellularGetChannelMessage : public CellularMessage { public: @@ -677,35 +387,6 @@ class CellularResponseMessage : public sys::ResponseMessage CellularMessage::Type cellResponse; }; -class CellularSimNewPinResponseMessage : public CellularResponseMessage -{ - public: - explicit CellularSimNewPinResponseMessage(bool retCode) : CellularResponseMessage(retCode) - {} -}; - -class CellularSimPukResponseMessage : public CellularResponseMessage -{ - public: - explicit CellularSimPukResponseMessage(bool retCode) : CellularResponseMessage(retCode) - {} -}; - -class CellularSimCardLockResponseMessage : public CellularResponseMessage -{ - CellularSimCardLockDataMessage::SimCardLock cardLock; - - public: - CellularSimCardLockResponseMessage(bool retCode, CellularSimCardLockDataMessage::SimCardLock cardLock) - : CellularResponseMessage(retCode), cardLock(cardLock) - {} - - [[nodiscard]] auto getSimCardLock() const noexcept -> CellularSimCardLockDataMessage::SimCardLock - { - return cardLock; - } -}; - class CellularGetOwnNumberResponseMessage : public CellularResponseMessage { public: @@ -1040,14 +721,6 @@ class CellularNewIncomingSMSNotification : public CellularNotificationMessage {} }; -class CellularSimReadyNotification : public CellularNotificationMessage -{ - public: - explicit CellularSimReadyNotification(const std::string &data = "") - : CellularNotificationMessage(CellularNotificationMessage::Content::SIM_READY, data) - {} -}; - class CellularSmsDoneNotification : public CellularNotificationMessage { public: @@ -1072,14 +745,6 @@ class CellularNetworkStatusUpdateNotification : public CellularNotificationMessa {} }; -class CellularSimNotReadyNotification : public CellularNotificationMessage -{ - public: - explicit CellularSimNotReadyNotification(const std::string &data = "") - : CellularNotificationMessage(CellularNotificationMessage::Content::SIM_NOT_READY, data) - {} -}; - class CellularUrcIncomingNotification : public CellularNotificationMessage { public: @@ -1190,8 +855,9 @@ namespace cellular class StateChange : public CellularMessage { public: - const State::ST request; - StateChange(const State::ST request = State::ST::Failed) : CellularMessage(Type::StateRequest), request(request) + const service::State::ST request; + StateChange(const service::State::ST request = service::State::ST::Failed) + : CellularMessage(Type::StateRequest), request(request) {} }; diff --git a/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp b/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp index b5bbbc2d9d2ff2c4036b1c37b9d929175de68daf..8741bff51f12b87f716fb3bdd4db96186209cb38 100644 --- a/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp +++ b/module-services/service-cellular/service-cellular/CellularServiceAPI.hpp @@ -92,16 +92,6 @@ namespace CellularServiceAPI bool USSDRequest(sys::Service *serv, CellularUSSDMessage::RequestType type, std::string data = ""); - bool ChangeSimPin(sys::Service *serv, - Store::GSM::SIM sim, - const std::vector &passcode, - const std::vector &pin); - bool RequestSimCardPinLockState(sys::Service *serv); - bool SetSimCardLock(sys::Service *serv, - Store::GSM::SIM sim, - CellularSimCardLockDataMessage::SimCardLock lock, - const std::vector &pin); - bool SetSimCard(sys::Service *serv, Store::GSM::SIM sim); /** * @brief get all APNs from phone configuration */ @@ -144,7 +134,7 @@ namespace CellularServiceAPI bool GetDataTransfer(sys::Service *serv); bool SetVoLTE(sys::Service *serv, bool value); - bool ChangeModulePowerState(sys::Service *serv, cellular::State::PowerState newState); + bool ChangeModulePowerState(sys::Service *serv, cellular::service::State::PowerState newState); bool SetFlightMode(sys::Service *serv, bool flightModeOn); diff --git a/module-services/service-cellular/service-cellular/RequestFactory.hpp b/module-services/service-cellular/service-cellular/RequestFactory.hpp index 71433f30ecc5f7ecf861213fecc07eea2f1b936b..a71e67d45c144605a316fef5b5864a59c1901239 100644 --- a/module-services/service-cellular/service-cellular/RequestFactory.hpp +++ b/module-services/service-cellular/service-cellular/RequestFactory.hpp @@ -21,16 +21,10 @@ namespace cellular class RequestFactory { public: - enum class SimStatus - { - SimInsterted, - SimSlotEmpty - }; - RequestFactory(const std::string &data, at::BaseChannel &channel, - CellularCallRequestMessage::RequestMode requestMode, - SimStatus simCardStatus); + cellular::api::CallMode callMode, + bool simInserted); std::unique_ptr create(); private: @@ -41,7 +35,7 @@ namespace cellular std::vector> requestMap; at::BaseChannel &channel; - const CellularCallRequestMessage::RequestMode requestMode; - const SimStatus simStatus; + const cellular::api::CallMode callMode; + const bool simInserted; }; } // namespace cellular diff --git a/module-services/service-cellular/service-cellular/ServiceCellular.hpp b/module-services/service-cellular/service-cellular/ServiceCellular.hpp index 386cad370d0b5be1e33bfb7f9738b293c7b9ab0d..cc599507e0a020aa4d799c735570403badde59fe 100644 --- a/module-services/service-cellular/service-cellular/ServiceCellular.hpp +++ b/module-services/service-cellular/service-cellular/ServiceCellular.hpp @@ -3,11 +3,8 @@ #pragma once -#include "SimCardResult.hpp" - #include "CellularCall.hpp" #include "CellularMessage.hpp" -#include "State.hpp" #include "USSD.hpp" #include "PacketData.hpp" #include "PacketDataCellularMessage.hpp" @@ -37,7 +34,6 @@ #include // for vector #include - namespace db { namespace query @@ -61,6 +57,11 @@ namespace constants class ConnectionManager; +namespace cellular::internal +{ + class ServiceCellularPriv; +} + class ServiceCellular : public sys::Service { @@ -104,75 +105,6 @@ class ServiceCellular : public sys::Service bool getIMSI(std::string &destination, bool fullNumber = false); std::vector getNetworkInfo(); - /** group of action/messages send "outside" eg. GUI - * requestPin is call anytime modem need pin, here should be called any action - * which allow user input (or mockup) pin. Then send appropriate action to notify the modem - * \param attempts Attempts counter for current action - * \param msg Literal name of action eg. SIM PIN - * \return - */ - bool requestPin(unsigned int attempts, const std::string msg); - - /** requestPuk is call anytime modem need puk, here should be called any action - * which allow user input (or mockup) puk and new pin. Then send appropriate action to notify the modem - * \param attempts Attempts counter for current action - * \param msg Literal name of action eg. SIM PUK - * \return - */ - bool requestPuk(unsigned int attempts, const std::string msg); - - /** Call in case of SIM card unlocked, MT ready. Place for sending message/action inform rest - * \return - */ - bool sendSimUnlocked(); - - /** Call in case of SIM card locked (card fail, eg. to many bad PUK). Place for sending message/action inform rest - * \return - */ - bool sendSimBlocked(); - - /** From this point should be send message/action call interaction in other layers eg. GUI - * \param cme_error - * \return - */ - bool sendUnhandledCME(unsigned int cme_error); - - /** Similar to sendBadPin - * \return - */ - bool sendBadPin(); - - /** Message send, when modem return incorrect password for PIN message. - * Probably modem firmware depend. On current version last bad message (attempts=1) return PUK request - * and generate PUK URC, so finally action on puk request will be call. This implementation allow to - * rethrow URC (so achive similar behavior in all cases). - * \return - */ - bool sendBadPuk(); - - /** Place to send action notifying eg. GUI - * \param res - * \return - */ - bool sendChangePinResult(SimCardResult res); - - /// sim functionality - - /** Function checks if sim pin is locked (enabled) - * @return True if sim pin is locked, False if it's not - */ - bool isPinLocked(); - - /** Function ready for change pin action send to Service Cellular form eg. GUI - * \param oldPin - * \param newPin - * \return - */ - bool changePin(const std::string oldPin, const std::string newPin); - bool unlockSimPin(std::string pin); - bool unlockSimPuk(std::string puk, std::string pin); - bool setPinLock(bool lock, const std::string pin); - private: at::ATURCStream atURCStream; std::unique_ptr cmux = std::make_unique(PortSpeed_e::PS460800, this); @@ -198,11 +130,10 @@ class ServiceCellular : public sys::Service std::unique_ptr packetData; std::unique_ptr phoneModeObserver; std::unique_ptr connectionManager; - cellular::State state; bsp::Board board = bsp::Board::none; /// URC GSM notification handler - std::optional> identifyNotification(const std::string &data); + std::optional> identifyNotification(const std::string &data); std::vector messageParts; @@ -218,9 +149,8 @@ class ServiceCellular : public sys::Service }; bool resetCellularModule(ResetType type); - bool isAfterForceReboot = false; - bool nextPowerStateChangeAwaiting = false; - cellular::State::PowerState nextPowerState = cellular::State::PowerState::Off; + bool isAfterForceReboot = false; + bool nextPowerStateChangeAwaiting = false; /// one point of state change handling void change_state(cellular::StateChange *msg); @@ -305,10 +235,6 @@ class ServiceCellular : public sys::Service bool handleUSSDURC(); void handleUSSDTimer(); - bool handleSimState(at::SimState state, const std::string message); - auto handleSimPinMessage(sys::Message *msgl) -> std::shared_ptr; - auto handleSimPukMessage(sys::Message *msgl) -> std::shared_ptr; - std::shared_ptr handleCellularStartOperatorsScan( CellularStartOperatorsScanMessage *msg); @@ -376,11 +302,9 @@ class ServiceCellular : public sys::Service auto handlePowerDownDeregisteredNotification(sys::Message *msg) -> std::shared_ptr; auto handleNewIncomingSMSNotification(sys::Message *msg) -> std::shared_ptr; auto handleRawCommandNotification(sys::Message *msg) -> std::shared_ptr; - auto handleSimReadyNotification(sys::Message *msg) -> std::shared_ptr; auto handleSmsDoneNotification(sys::Message *msg) -> std::shared_ptr; auto handleSignalStrengthUpdateNotification(sys::Message *msg) -> std::shared_ptr; auto handleNetworkStatusUpdateNotification(sys::Message *msg) -> std::shared_ptr; - auto handleSimNotReadyNotification(sys::Message *msg) -> std::shared_ptr; auto handleUrcIncomingNotification(sys::Message *msg) -> std::shared_ptr; auto handleCellularSetFlightModeMessage(sys::Message *msg) -> std::shared_ptr; auto handleCellularSetRadioOnOffMessage(sys::Message *msg) -> std::shared_ptr; @@ -392,6 +316,9 @@ class ServiceCellular : public sys::Service auto isIncommingCallAllowed() -> bool; auto hangUpCall() -> bool; + + private: + std::unique_ptr priv; }; namespace sys diff --git a/module-services/service-cellular/service-cellular/SimCardResult.hpp b/module-services/service-cellular/service-cellular/SimCardResult.hpp deleted file mode 100644 index 97ec3affd41b764a02d4f0a43f0fe591fd9f5b40..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/service-cellular/SimCardResult.hpp +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once -class SimPinType -{ - public: - static constexpr auto SimPin = "SC"; - static constexpr auto SimPin2 = "P2"; -}; -enum class SimCardResult -{ - OK = 0, - Ready = 1, - Locked = 2, /*!< In case of attempt counters set to 0 */ - - AT_ERROR_Begin = - 9, /*!< this is only for separate AT SIM errors from new one added, AT errors list end with AT_ERROR_End */ - - SIMNotInserted = 10, - SIM_PIN_required = 11, - SIM_PUKRequired = 12, - Failure = 13, - Busy = 14, - Wrong = 15, - IncorrectPassword = 16, - - AT_ERROR_End = 17, - - Unknown = 0xFF /*!< Unknown, any reason (not only AT), in some case AT commends return just error, eg. twice - supply good pin, second AT commend return ERROR */ - -}; diff --git a/module-services/service-cellular/service-cellular/State.hpp b/module-services/service-cellular/service-cellular/State.hpp deleted file mode 100644 index 9476acc7cc4ae44f6bee3e9c781852a69defc883..0000000000000000000000000000000000000000 --- a/module-services/service-cellular/service-cellular/State.hpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -class ServiceCellular; - -namespace cellular -{ - class State - { - public: - enum class ST - { - Idle, /// does nothing - WaitForStartPermission, /// waiting for permission to start the module - PowerUpRequest, /// process request of power up - StatusCheck, /// set on service start - check for modem status - skipped on T3 board - PowerUpProcedure, /// due to lack of Status pin on T3, we don't know whether is on or off - PowerUpInProgress, /// waiting for modem powered up by polling various bauds - BaudDetect, /// baud detection procedure - CellularConfProcedure, /// configuration procedure - AudioConfigurationProcedure, /// audio configuration for modem (could be in ModemConfiguration) - APNConfProcedure, /// Configure APN set by user, check if modem have similar - SanityCheck, /// prior to ModemOn last sanity checks for one time configurations etc - ModemOn, /// modem ready - indicates that modem is fully configured, ( **SIM is not yet configured** ) - URCReady, /// State indicates that URC handling is enabled - SimInit, /// initialize sim card - SimSelect, /// triggers hw SIM selection (! state now will be **changed on URC** ) - ModemFatalFailure, /// modem full shutdown need - Failed, - Ready, /// Service is fully initialized - PowerDownStarted, /// modem is disconnecting from network. It might take a while if poor coverage - PowerDownWaiting, /// modem has deregistered and is now approaching low power state - PowerDown, /// modem is known to be turned off - }; - - enum class PowerState - { - Off, - On - }; - - private: - enum ST state = ST::Idle; - - public: - [[nodiscard]] static const char *c_str(ST state); - [[nodiscard]] const char *c_str(); - - /// 1. sets state of ServiceCellular - /// 2. sends Multicast notification of ServiceCellular state - /// - /// \note This is for service cellular only it could be private and friend - void set(ServiceCellular *owner, ST state); - - ST get() const; - }; -} // namespace cellular diff --git a/module-services/service-cellular/src/ServiceCellularPriv.hpp b/module-services/service-cellular/src/ServiceCellularPriv.hpp index db0e79658b13417162cef49f70b7f254915fe830..3a2a085ba632e3083defada97bdebaca0171a459 100644 --- a/module-services/service-cellular/src/ServiceCellularPriv.hpp +++ b/module-services/service-cellular/src/ServiceCellularPriv.hpp @@ -4,7 +4,7 @@ #pragma once #include -#include +#include #include "SimCard.hpp" @@ -29,5 +29,7 @@ namespace cellular::internal private: void initSimCard(); + + friend class ::ServiceCellular; }; } // namespace cellular::internal diff --git a/module-services/service-cellular/src/SimCard.cpp b/module-services/service-cellular/src/SimCard.cpp index 8e7a7b922385fc406ed752997c20ff590aaef6da..f59ae4e3fc17f2dcdcf280ea4f30f0a520372d68 100644 --- a/module-services/service-cellular/src/SimCard.cpp +++ b/module-services/service-cellular/src/SimCard.cpp @@ -80,7 +80,7 @@ namespace cellular bool SimCard::handleSetPinLock(const api::SimCode &pin, api::SimLockState lock) { const auto _pin = internal::simCodeToString(pin); - return processPinResult(setPinLock(_pin, lock == cellular::api::SimLockState::Locked)); + return processPinResult(setPinLock(_pin, lock == cellular::api::SimLockState::Enabled)); } bool SimCard::handlePinUnlock(const api::SimCode &pin) diff --git a/module-services/service-cellular/src/SimCard.hpp b/module-services/service-cellular/src/SimCard.hpp index d1af37cb9169c7eb56f66036c43411f3021e6c39..2dc5c645557bfd27a41b570586ea66474489eb59 100644 --- a/module-services/service-cellular/src/SimCard.hpp +++ b/module-services/service-cellular/src/SimCard.hpp @@ -71,7 +71,7 @@ namespace cellular::service /** Set cmd channel * \param channel channel (or nullptr to block communication) */ - void setChannel(at::BaseChannel *channel = nullptr); + void setChannel(at::BaseChannel *channel); /** * Request message handlers diff --git a/module-services/service-cellular/src/state.cpp b/module-services/service-cellular/src/State.cpp similarity index 94% rename from module-services/service-cellular/src/state.cpp rename to module-services/service-cellular/src/State.cpp index 0044474ea3334c9f43ecc9d30500aaa82aa4518e..fa3313aea1107c662a7e2f07a2ce02a44e733ee7 100644 --- a/module-services/service-cellular/src/state.cpp +++ b/module-services/service-cellular/src/State.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include +#include #include #include @@ -68,7 +68,7 @@ namespace cellular::service { LOG_DEBUG("GSM state: (%s) -> (%s)", c_str(this->state), c_str(state)); this->state = state; - auto msg = std::make_shared(static_cast(state)); + auto msg = std::make_shared(state); owner->bus.sendMulticast(msg, sys::BusChannel::ServiceCellularNotifications); } diff --git a/module-services/service-cellular/tests/unittest_datatransfer.cpp b/module-services/service-cellular/tests/unittest_datatransfer.cpp index 1510d8bc9da347c5b93a1c3b6328e9c19d75e8e9..d8fd5fbd706dd78ce4c57c3d9e257ccd806665e6 100644 --- a/module-services/service-cellular/tests/unittest_datatransfer.cpp +++ b/module-services/service-cellular/tests/unittest_datatransfer.cpp @@ -8,8 +8,6 @@ #include "Result.hpp" #include -using namespace cellular; - TEST_CASE("Quectel AT DataTransfer commands") { SECTION("QIACT") diff --git a/module-services/service-cellular/tests/unittest_qmbn.cpp b/module-services/service-cellular/tests/unittest_qmbn.cpp index a8aab01451e97bb2dc18d0e088378ba09ae0b75d..a47ac2788cb5a9adb7367c78f18c168a8c0f448c 100644 --- a/module-services/service-cellular/tests/unittest_qmbn.cpp +++ b/module-services/service-cellular/tests/unittest_qmbn.cpp @@ -6,8 +6,6 @@ #include #include -using namespace cellular; - TEST_CASE("Quectel MBN test") { SECTION("Parse list of MBN") diff --git a/module-services/service-cellular/tests/unittest_request_factory.cpp b/module-services/service-cellular/tests/unittest_request_factory.cpp index 69b0c001047c48a75c9d910593cb6a15a45c7443..27ee4f2e99c406434b583ce2eeaa26fc0ea23f43 100644 --- a/module-services/service-cellular/tests/unittest_request_factory.cpp +++ b/module-services/service-cellular/tests/unittest_request_factory.cpp @@ -111,10 +111,9 @@ TEST_CASE("Emergency handling") RequestFactory requestFactory(test.number, dummyChannel, - test.isEmergencyRequest ? CellularCallRequestMessage::RequestMode::Emergency - : CellularCallRequestMessage::RequestMode::Normal, - test.insertSim ? RequestFactory::SimStatus::SimInsterted - : RequestFactory::SimStatus::SimSlotEmpty); + test.isEmergencyRequest ? cellular::api::CallMode::Emergency + : cellular::api::CallMode::Regular, + test.insertSim); std::shared_ptr request = requestFactory.create(); INFO("Failed test case idx: " + std::to_string(idx)); @@ -445,10 +444,7 @@ TEST_CASE("MMI requests") for (auto &testCase : testCases) { auto mockChannel = at::GenericChannel(at::Result::Code::OK, {}); - RequestFactory requestFactory(testCase.requestString, - mockChannel, - CellularCallRequestMessage::RequestMode::Normal, - RequestFactory::SimStatus::SimInsterted); + RequestFactory requestFactory(testCase.requestString, mockChannel, cellular::api::CallMode::Regular, true); auto request = requestFactory.create(); auto requestCommand = request->command(); diff --git a/module-services/service-cellular/tests/unittest_simcard.cpp b/module-services/service-cellular/tests/unittest_simcard.cpp index 2ca8e60535d8718a8b16dbd28b74ecf6aa61803c..edab2007ffe000036b0a9b92668f9d7ad612ca8a 100644 --- a/module-services/service-cellular/tests/unittest_simcard.cpp +++ b/module-services/service-cellular/tests/unittest_simcard.cpp @@ -43,7 +43,7 @@ namespace at TEST_CASE("SimCard functionality test") { - SECTION("pinToString from vector") + SECTION("simCodeToString()") { cellular::api::SimCode v{1, 2, 3, 4}; cellular::api::SimCode empty; diff --git a/module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp b/module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp index 5906514ce975a141d62356140fc8b51a0195b37e..f950ceddfa6b43ad2e23ec731fc50e15c05d6e02 100644 --- a/module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp +++ b/module-services/service-desktop/endpoints/developerMode/DeveloperModeHelper.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -254,21 +255,19 @@ bool DeveloperModeHelper::sendKeypress(bsp::KeyCodes keyCode, gui::InputEvent::S void DeveloperModeHelper::requestSimChange(const int simSelected) { - Store::GSM::SIM sim = Store::GSM::SIM::SIM1; - if (simSelected == static_cast(Store::GSM::SIM::SIM2)) { - sim = Store::GSM::SIM::SIM2; - } - CellularServiceAPI::SetSimCard(owner, sim); + auto arg = (simSelected == static_cast(cellular::api::SimSlot::SIM2)) ? cellular::api::SimSlot::SIM2 + : cellular::api::SimSlot::SIM1; + owner->bus.sendUnicast(arg); } bool DeveloperModeHelper::requestCellularPowerStateChange(const int cellularState) { bool res = false; if (cellularState == 1) { - res = CellularServiceAPI::ChangeModulePowerState(owner, cellular::State::PowerState::Off); + res = CellularServiceAPI::ChangeModulePowerState(owner, cellular::service::State::PowerState::Off); } else if (cellularState == 2) { - res = CellularServiceAPI::ChangeModulePowerState(owner, cellular::State::PowerState::On); + res = CellularServiceAPI::ChangeModulePowerState(owner, cellular::service::State::PowerState::On); } else if (cellularState == 3) { auto event = std::make_unique(); diff --git a/module-services/service-fota/ServiceFota.cpp b/module-services/service-fota/ServiceFota.cpp index ac720a124eaed0f3923f0252358957924b984e3c..9b3ed96ed28dfffa198e7de3b08f44bdae46756b 100644 --- a/module-services/service-fota/ServiceFota.cpp +++ b/module-services/service-fota/ServiceFota.cpp @@ -105,8 +105,8 @@ namespace FotaService sys::MessagePointer Service::handleServiceCellularNotifications(sys::Message *req) { if (auto msg = dynamic_cast(req)) { - LOG_DEBUG("cellular::StageChange: %s", cellular::State::c_str(msg->request)); - if (msg->request == cellular::State::ST::Ready) { + LOG_DEBUG("cellular::StageChange: %s", cellular::service::State::c_str(msg->request)); + if (msg->request == cellular::service::State::ST::Ready) { LOG_DEBUG("Modem is \"Ready\""); if (dataChannel == nullptr) { LOG_DEBUG("Requesting channel"); diff --git a/module-sys/SystemManager/SystemManager.cpp b/module-sys/SystemManager/SystemManager.cpp index c13c0727097df3b4a47cb7e289b5a82d7ca51645..d85cd0962c171fc85e2834d42213617f2432ff5e 100644 --- a/module-sys/SystemManager/SystemManager.cpp +++ b/module-sys/SystemManager/SystemManager.cpp @@ -436,7 +436,7 @@ namespace sys void SystemManager::batteryCriticalLevelAction(bool charging) { LOG_INFO("Battery Critical Level reached!"); - CellularServiceAPI::ChangeModulePowerState(this, cellular::State::PowerState::Off); + CellularServiceAPI::ChangeModulePowerState(this, cellular::service::State::PowerState::Off); auto msg = std::make_shared(true, charging); bus.sendUnicast(std::move(msg), app::manager::ApplicationManager::ServiceName); } @@ -450,7 +450,7 @@ namespace sys void SystemManager::batteryNormalLevelAction() { LOG_INFO("Battery level normal."); - CellularServiceAPI::ChangeModulePowerState(this, cellular::State::PowerState::On); + CellularServiceAPI::ChangeModulePowerState(this, cellular::service::State::PowerState::On); auto battNormalMsg = std::make_shared(false); bus.sendUnicast(std::move(battNormalMsg), app::manager::ApplicationManager::ServiceName); } @@ -535,12 +535,12 @@ namespace sys connect(CellularCheckIfStartAllowedMessage(), [&](Message *) { switch (Store::Battery::get().levelState) { case Store::Battery::LevelState::Normal: - CellularServiceAPI::ChangeModulePowerState(this, cellular::State::PowerState::On); + CellularServiceAPI::ChangeModulePowerState(this, cellular::service::State::PowerState::On); break; case Store::Battery::LevelState::CriticalCharging: [[fallthrough]]; case Store::Battery::LevelState::CriticalNotCharging: - CellularServiceAPI::ChangeModulePowerState(this, cellular::State::PowerState::Off); + CellularServiceAPI::ChangeModulePowerState(this, cellular::service::State::PowerState::Off); break; case Store::Battery::LevelState::Shutdown: break; diff --git a/module-utils/common_data/EventStore.hpp b/module-utils/common_data/EventStore.hpp index 81d628cccea833d37eddbc32d34e7553a6f2ed14..261c9354101c0c7f00fd55f1bbd4dd30a87173b3 100644 --- a/module-utils/common_data/EventStore.hpp +++ b/module-utils/common_data/EventStore.hpp @@ -10,6 +10,7 @@ // it's not meant to serve as polling interface - rather to serve data #include +#include namespace cpp_freertos { @@ -107,8 +108,8 @@ namespace Store /// selected - tray selection settings settable sim tray enum class SIM { - SIM1, - SIM2, + SIM1 = static_cast(cellular::api::SimSlot::SIM1), + SIM2 = static_cast(cellular::api::SimSlot::SIM2), SIM_FAIL, SIM_UNKNOWN, NONE,