~aleteoryx/muditaos

ref: 37665c297143f9fe103f2880a79faab75cf82263 muditaos/module-services/service-cellular/requests/SupplementaryServicesRequest.cpp -rw-r--r-- 6.3 KiB
37665c29 — Mateusz Piesta [MOS-000] Fixed minor issue in db migration script 2 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <string>
#include <memory>

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

#include "service-cellular/requests/SupplementaryServicesRequest.hpp"
#include "service-cellular/requests/CallForwardingRequest.hpp"
#include "service-cellular/requests/ClipRequest.hpp"
#include "service-cellular/requests/ClirRequest.hpp"
#include "service-cellular/requests/ColpRequest.hpp"
#include "service-cellular/requests/CallWaitingRequest.hpp"
#include "service-cellular/requests/CallBarringRequest.hpp"
#include <map>

namespace
{
    const std::map<std::string, cellular::SupplementaryServicesRequest::ProcedureType> procedureTypeMap = {
        {"*", cellular::SupplementaryServicesRequest::ProcedureType::Activation},
        {"#", cellular::SupplementaryServicesRequest::ProcedureType::Deactivation},
        {"*#", cellular::SupplementaryServicesRequest::ProcedureType::Interrogation},
        {"**", cellular::SupplementaryServicesRequest::ProcedureType::Registration},
        {"##", cellular::SupplementaryServicesRequest::ProcedureType::Erasure},
    };
}

namespace cellular
{
    SupplementaryServicesRequest::SupplementaryServicesRequest(const std::string &data, GroupMatch matchGroups)
        : Request(data),
          serviceCode(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ServiceCode)]),
          supplementaryInfoA(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoA)]),
          supplementaryInfoB(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoB)]),
          supplementaryInfoC(matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::SupInfoC)])
    {
        static_assert(magic_enum::enum_count<SupplementaryServicesRegexGroups>() <= maxGroupsInRequest);

        auto &procedureTypeString =
            matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ProcedureType)];

        auto pType = procedureTypeMap.find(procedureTypeString);
        if (pType == procedureTypeMap.end()) {

            throw std::runtime_error(std::string(__FUNCTION__) + ": procedure type not covered by constructor.");
        }
        procedureType = pType->second;
    }

    auto SupplementaryServicesRequest::create(const std::string &data, GroupMatch matchGroups)
        -> std::unique_ptr<SupplementaryServicesRequest>
    {
        std::string serviceCode = matchGroups[magic_enum::enum_integer(SupplementaryServicesRegexGroups::ServiceCode)];

        auto factoryList = {
            CallForwardingRequest::create,
            CallWaitingRequest::create,
            CallBarringRequest::create,
            ClipRequest::create,
            ClirRequest::create,
            ColpRequest::create,
        };

        for (auto &createCb : factoryList) {
            if (auto req = createCb(serviceCode, data, matchGroups)) {
                return req;
            }
        }

        return nullptr;
    }

    auto SupplementaryServicesRequest::getCommandInformationClass(const std::string &basicServiceGroup) const
        -> std::optional<std::string>
    {
        int basicGroup       = 0;
        int informationClass = 0;

        if (basicServiceGroup.empty()) {
            // according to 3GPP TS 22.030 V16.0.0 Annex C
            informationClass = atInformationClassAllTele + atInformationClassAllBearer;
        }
        else {
            basicGroup   = utils::getNumericValue<int>(basicServiceGroup);
            auto service = magic_enum::enum_cast<TeleAndBearerService>(basicGroup);

            if (!service.has_value()) {
                return std::nullopt;
            }

            switch (service.value()) {
            // according to 3GPP TS 22.030 V16.0.0 Annex C
            case TeleAndBearerService::AllTeleServices:
                informationClass = atInformationClassAllTele;
                break;
            case TeleAndBearerService::Telephony:
                informationClass = atInformationClassVoice;
                break;
            case TeleAndBearerService::AllDataTeleServices:
                informationClass = atInformationClassAllDataTele;
                break;
            case TeleAndBearerService::FacsimileServices:
                informationClass = atInformationClassFax;
                break;
            case TeleAndBearerService::ShortMessageServices:
                informationClass = atInformationClassSms;
                break;
            case TeleAndBearerService::AllTeleServicesExceptSms:
                informationClass = atInformationClassAllTele - atInformationClassSms;
                break;
            case TeleAndBearerService::VoiceGroupCallService:
                LOG_INFO("Unsupported information class: 17 - Voice Group Call Service");
                break;
            case TeleAndBearerService::VoiceBroadcastService:
                LOG_INFO("Unsupported information class: 18 - Voice Broadcast Service");
                break;
            case TeleAndBearerService::AllBearerServices:
                informationClass = atInformationClassAllBearer;
                break;
            case TeleAndBearerService::AllAsyncServices:
                informationClass = atInformationClassDataAsync;
                break;
            case TeleAndBearerService::AllSyncServices:
                informationClass = atInformationClassDataSync;
                break;
            case TeleAndBearerService::AllDataCircuitSync:
                informationClass = atInformationClassDataSync;
                break;
            case TeleAndBearerService::AllDataCircuitAsync:
                informationClass = atInformationClassDataAsync;
                break;
            case TeleAndBearerService::AllGprsBearerServices:
                LOG_INFO("Unsupported information class: 99 - All Gprs Bearer Services");
                break;
            case TeleAndBearerService::TelephonyAndAllSyncServices:
                informationClass = atInformationClassVoice + atInformationClassDataSync;
                break;
            }
        }

        if (informationClass == 0) {
            return std::nullopt;
        }

        return utils::to_string(informationClass);
    }

    auto SupplementaryServicesRequest::getProcedureType() -> ProcedureType
    {
        return procedureType;
    }

}; // namespace cellular