~aleteoryx/muditaos

dc676ef4901fdc92037121535efcc29c3d5e9302 — breichel 5 years ago 9d57c2a
Egd 4474 integration sim handling with gui (#1068)

[EGD-4474] Send meesages bloks added to drive gui and received from them response (like pin, puk). Basic flow.
M changelog.md => changelog.md +4 -0
@@ 1,5 1,9 @@
# MuditaOS changelog

### Added

* `[cellular]` Integration with basic flow for SIM card (cellular<>GUI)

## [0.48.1 2020-11-23]

### Added

M module-services/service-cellular/ServiceCellular.cpp => module-services/service-cellular/ServiceCellular.cpp +34 -3
@@ 63,6 63,7 @@
#include <service-evtmgr/Constants.hpp>
#include <service-evtmgr/EventManagerServiceAPI.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <service-appmgr/model/ApplicationManager.hpp>
#include <task.h>
#include <time/time_conversion.hpp>
#include <ucs2/UCS2.hpp>


@@ 937,6 938,9 @@ sys::MessagePointer ServiceCellular::DataReceivedHandler(sys::DataMessage *msgl,
        channel->cmd(at::AT::DISABLE_TIME_ZONE_REPORTING);
        channel->cmd(at::AT::DISABLE_TIME_ZONE_UPDATE);
    } break;
    case MessageType::CellularSimResponse: {
        responseMsg = std::make_shared<CellularResponseMessage>(handleSimResponse(msgl));
    } break;
    default:
        break;



@@ 998,30 1002,40 @@ std::optional<std::shared_ptr<CellularMessage>> ServiceCellular::identifyNotific

bool ServiceCellular::requestPin(unsigned int attempts, const std::string msg)
{
    auto message = std::make_shared<CellularSimRequestPinMessage>(Store::GSM::get()->selected, attempts, msg);
    sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
    LOG_DEBUG("REQUEST PIN");
    return true;
}

bool ServiceCellular::requestPuk(unsigned int attempts, const std::string msg)
{
    auto message = std::make_shared<CellularSimRequestPukMessage>(Store::GSM::get()->selected, attempts, msg);
    sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
    LOG_ERROR("REQUEST PUK");
    return true;
}

bool ServiceCellular::sendSimUnlocked()
{
    auto message = std::make_shared<CellularUnlockSimMessage>(Store::GSM::get()->selected);
    sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
    LOG_DEBUG("SIM UNLOCKED");
    return true;
}

bool ServiceCellular::sendSimBlocked()
{
    auto message = std::make_shared<CellularBlockSimMessage>(Store::GSM::get()->selected);
    sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
    LOG_ERROR("SIM BLOCKED");
    return true;
}

bool ServiceCellular::sendUnhandledCME(unsigned int cme_error)
{
    auto message = std::make_shared<CellularDisplayCMEMessage>(Store::GSM::get()->selected, cme_error);
    sys::Bus::SendUnicast(message, app::manager::ApplicationManager::ServiceName, this);
    LOG_ERROR("UNHANDLED CME %d", cme_error);
    return true;
}


@@ 1063,9 1077,9 @@ bool ServiceCellular::changePin(const std::string oldPin, const std::string newP

bool ServiceCellular::unlockSimPin(std::string pin)
{
    LOG_ERROR("Unlock pin %s", pin.c_str());
    SimCard simCard(*this);
    SimCardResult sime;
    LOG_DEBUG("PIN:  %s", pin.c_str());
    sime = simCard.supplyPin(pin);

    if (sime == SimCardResult::IncorrectPassword) {


@@ 1101,6 1115,23 @@ bool ServiceCellular::unlockSimPuk(std::string puk, std::string pin)
    return false;
}

bool ServiceCellular::handleSimResponse(sys::DataMessage *msgl)
{

    auto msgSimPin = dynamic_cast<CellularSimPinDataMessage *>(msgl);
    if (msgSimPin != nullptr) {
        LOG_DEBUG("Unclocking sim");
        return unlockSimPin(SimCard::pinToString(msgSimPin->getPin()));
    }

    auto msgSimPuk = dynamic_cast<CellularSimPukDataMessage *>(msgl);
    if (msgSimPuk != nullptr) {
        LOG_DEBUG("Unlocking puk");
        return unlockSimPuk(SimCard::pinToString(msgSimPuk->getPuk()), SimCard::pinToString(msgSimPuk->getNewPin()));
    }
    return false;
}

bool ServiceCellular::handleSimState(at::SimState state, const std::string message)
{



@@ 1273,8 1304,8 @@ bool ServiceCellular::receiveSMS(std::string messageNumber)

    channel->cmd(at::AT::SMS_UCSC2);

    auto cmd = at::factory(at::AT::QCMGR);
    auto ret = channel->cmd(cmd + messageNumber, cmd.timeout);
    auto cmd           = at::factory(at::AT::QCMGR);
    auto ret           = channel->cmd(cmd + messageNumber, cmd.timeout);
    bool messageParsed = false;

    std::string messageRawBody;

M module-services/service-cellular/SimCard.cpp => module-services/service-cellular/SimCard.cpp +7 -0
@@ 167,3 167,10 @@ std::optional<at::SimState> SimCard::simStateWithMessage(std::string &message) c
    }
    return at::SimState::Unknown;
}

std::string SimCard::pinToString(std::vector<unsigned int> v)
{
    std::string buf;
    std::transform(v.begin(), v.end(), std::back_inserter(buf), [](auto &&c) { return '0' + c; });
    return buf;
}

M module-services/service-cellular/SimCard.hpp => module-services/service-cellular/SimCard.hpp +2 -0
@@ 64,6 64,8 @@ class SimCard
    std::optional<at::SimState> simState() const;
    std::optional<at::SimState> simStateWithMessage(std::string &message) const;

    static std::string pinToString(std::vector<unsigned int> v);

  private:
    ServiceCellular &cellularService;


M module-services/service-cellular/service-cellular/ServiceCellular.hpp => module-services/service-cellular/service-cellular/ServiceCellular.hpp +1 -0
@@ 251,6 251,7 @@ class ServiceCellular : public sys::Service
    void handleUSSDTimer();

    bool handleSimState(at::SimState state, const std::string message);
    bool handleSimResponse(sys::DataMessage *msgl);

    friend class CellularUrcHandler;
    friend class SimCard;

M module-services/service-cellular/tests/CMakeLists.txt => module-services/service-cellular/tests/CMakeLists.txt +8 -0
@@ 9,3 9,11 @@ add_catch2_executable(
            module-cellular
)

add_catch2_executable(
        NAME
        cellular-simcard
        SRCS
        unittest_simcard.cpp
        LIBS
        module-cellular
)
\ No newline at end of file

A module-services/service-cellular/tests/unittest_simcard.cpp => module-services/service-cellular/tests/unittest_simcard.cpp +20 -0
@@ 0,0 1,20 @@
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#define CATCH_CONFIG_MAIN

#include <catch2/catch.hpp>
#include <service-cellular/SimCard.hpp>

using namespace cellular;

TEST_CASE("SimCard functionality test")
{
    SECTION("pinToString from vector")
    {
        std::vector<unsigned int> v{1, 2, 3, 4};
        std::vector<unsigned int> empty;
        REQUIRE(SimCard::pinToString(v) == "1234");
        REQUIRE(SimCard::pinToString(empty) == "");
    }
}