~aleteoryx/muditaos

ref: 65a8cc18592d99c90405b3b07ca393eeccce9855 muditaos/module-services/service-cellular/requests/PasswordRegistrationRequest.cpp -rw-r--r-- 3.0 KiB
65a8cc18 — Marcin Smoczyński changelog: update changelog for v0.47.1 (#1056) 5 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>

#include <at/Commands.hpp>
#include <Utils.hpp>

#include "service-cellular/requests/PasswordRegistrationRequest.hpp"

namespace
{
    // according to EC25&EC21_AT_Commands_Manual_V1.3
    const std::map<std::string, std::string> barringServiceToFacilityMap = {{
        {"33", "AO"},  // BAOC (Bar All Outgoing Calls)
        {"331", "OI"}, // BOIC (Bar Outgoing International Calls)
        {"332", "OX"}, // BOIC-exHC (Bar Outgoing International Calls except to home country)
        {"35", "AI"},  // BAIC (Bar All Incoming Calls)
        {"351", "IR"}, // BIC-Roam (Bar Incoming Calls when Roaming outside the home country)
        {"330", "AB"}, // All barring services
        {"333", "AG"}, // All outgoing barring services
        {"353", "AC"}, // All incoming barring services
        {"", "AB"},    // All incoming barring services (According to 3GPP TS 22.030 V16.0.0 )
    }};
} // namespace

namespace
{
    constexpr inline std::string_view changeNetworkPasswordServiceCode = "03";
}

namespace cellular
{

    std::unique_ptr<PasswordRegistrationRequest> PasswordRegistrationRequest::create(const std::string &data,
                                                                                     GroupMatch matchGroups)
    {
        return std::make_unique<PasswordRegistrationRequest>(data, matchGroups);
    }

    auto PasswordRegistrationRequest::command() -> std::string
    {
        std::array<std::function<std::string()>, 3> commandParts = {
            [this]() { return this->getCommandFacility(); },
            [this]() { return "," + this->getOldPassword(); },
            [this]() { return "," + this->getNewPassword(); },
        };

        std::string cmd(at::factory(at::AT::CPWD));
        for (auto &cmdPart : commandParts) {
            cmd.append(cmdPart());
        }

        return cmd;
    }

    auto PasswordRegistrationRequest::getCommandFacility() const noexcept -> std::string
    {
        if (auto it = barringServiceToFacilityMap.find(requestBarringService);
            it != barringServiceToFacilityMap.end()) {
            return "\"" + it->second + "\"";
        }
        return std::string();
    }

    auto PasswordRegistrationRequest::getOldPassword() const noexcept -> std::string
    {
        return "\"" + requestOldPassword + "\"";
    }

    auto PasswordRegistrationRequest::getNewPassword() const noexcept -> std::string
    {
        return "\"" + requestNewPassword + "\"";
    }

    void PasswordRegistrationRequest::handle(RequestHandler &h, at::Result &result)
    {
        h.handle(*this, result);
    }

    auto PasswordRegistrationRequest::isValid() const noexcept -> bool
    {
        return requestNewPassword == requestNewPasswordRepeat && !requestNewPasswordRepeat.empty() &&
               !requestNewPassword.empty() && !requestOldPassword.empty();
    }
} // namespace cellular