~aleteoryx/muditaos

ref: fe546ae4657132ac281a7daaaec20303e454e9e0 muditaos/module-services/service-cellular/messages/CellularMessage.hpp -rw-r--r-- 10.6 KiB
fe546ae4 — PrzeBrudny Revert "[EGD-4168] passcodes for sim change to variable length (#924)" (#934) 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
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#ifndef PUREPHONE_CELLULARMESSAGE_HPP
#define PUREPHONE_CELLULARMESSAGE_HPP

#include "../SignalStrength.hpp"
#include <MessageType.hpp>
#include <Service/Message.hpp>
#include <utf8/UTF8.hpp>
#include <memory>
#include "../State.hpp"
#include <Modem/TS0710/TS0710.h>

#include <PhoneNumber.hpp>

#include <string>

#include "module-bsp/bsp/cellular/bsp_cellular.hpp"

class CellularMessage : public sys::DataMessage
{
  public:
    CellularMessage(MessageType messageType) : sys::DataMessage(messageType){};
    virtual ~CellularMessage(){};
};

class CellularCallMessage : public CellularMessage
{
  public:
    enum class Type
    {
        Ringing,      // user provided number to call to and service initialized calling procedure.
        IncomingCall, // device receives connection from other device.
    };

    CellularCallMessage() = delete;
    CellularCallMessage(Type type, const utils::PhoneNumber::View &number)
        : CellularMessage(MessageType::CellularCall), type(type), number(number)
    {}
    CellularCallMessage(Type type, const utils::PhoneNumber &number)
        : CellularMessage(MessageType::CellularCall), type(type), number(number.getView())
    {}
    CellularCallMessage(Type type, const std::string &e164number)
        : CellularMessage(MessageType::CellularCall), type(type), number(utils::PhoneNumber::parse(e164number))
    {}

    Type type;
    utils::PhoneNumber::View number;
};

class CellularNotificationMessage : public CellularMessage
{
  public:
    enum class Type
    {
        CallAborted, // user tried to call other device but receiving side dropped call or call unsuccessful
        CallActive,  // call is in progress both if call was initialized by user and when user received incoming call.
        NewIncomingSMS,           // device received new sms from network. (what about sms delivery reports?).
        SignalStrengthUpdate,     // update of the strength of the network's signal.
        NetworkStatusUpdate,      // update of the status of the network
        PowerUpProcedureComplete, // modem without cmux on initialization complete (cold start || reset modem -> and
                                  // cold start)
        SIM,                      // change on SIM from URC
        RawCommand,               // send raw command to modem -> returns raw, tokenised result
        PowerDownDeregistering,   // modem informed it has started to disconnect from network
        PowerDownDeregistered,    // modem informed it has disconnected from network
        NewIncomingUSSD,          // modem received new ussd code from network
    };

    // TODO check and fix all CellularNotificationMessage constructors

    CellularNotificationMessage() = delete;
    CellularNotificationMessage(Type type, const std::string &data = "")
        : CellularMessage(MessageType::CellularNotification), type(type), data(data)
    {}

    virtual ~CellularNotificationMessage() = default;

    Type type;
    std::string data;
};
class CellularTimeNotificationMessage : public CellularMessage
{
  private:
    std::optional<struct tm> time;
    std::optional<int> timeZoneGmtOff;
    std::optional<std::string> timeZoneString;

  public:
    CellularTimeNotificationMessage() = delete;
    explicit CellularTimeNotificationMessage(struct tm time, long int timeZoneGmtOff, std::string timeZoneString)
        : CellularMessage(MessageType::CellularTimeUpdated), time(time), timeZoneGmtOff(timeZoneGmtOff),
          timeZoneString(timeZoneString)
    {}

    explicit CellularTimeNotificationMessage(long int timeZoneGmtOff, std::string timeZoneString)
        : CellularMessage(MessageType::CellularTimeUpdated), timeZoneGmtOff(timeZoneGmtOff),
          timeZoneString(timeZoneString)
    {}

    explicit CellularTimeNotificationMessage(struct tm time)
        : CellularMessage(MessageType::CellularTimeUpdated), time(time)
    {}

    std::optional<struct tm> getTime(void)
    {
        return time;
    }

    std::optional<long int> getTimeZoneOffset(void)
    {
        return timeZoneGmtOff;
    }

    std::optional<const std::string> getTimeZoneString(void)
    {
        return timeZoneString;
    }
};
class CellularUSSDMessage : public CellularMessage
{
  public:
    enum class RequestType
    {
        pullSesionRequest,
        pushSesionRequest,
        abortSesion
    };
    CellularUSSDMessage() = delete;
    CellularUSSDMessage(RequestType requestType, const std::string &data = "")
        : CellularMessage(MessageType::CellularUSSDRequest), type(requestType), data(data)
    {}

    RequestType type;
    std::string data;
};
class CellularRequestMessage : public CellularMessage
{
  public:
    CellularRequestMessage(MessageType messageType, std::string data = "") : CellularMessage(messageType), data(data)
    {}
    ~CellularRequestMessage()
    {}

    std::string data;
};

class CellularDtmfRequestMessage : public CellularMessage
{
    uint32_t digit = 0;

  public:
    CellularDtmfRequestMessage(uint32_t digit) : CellularMessage(MessageType::CellularTransmitDtmfTones), digit(digit)
    {}

    uint32_t getDigit() const
    {
        return digit;
    }
};

class CellularAntennaRequestMessage : public CellularMessage
{
  public:
    CellularAntennaRequestMessage(MessageType messageType) : CellularMessage(messageType)
    {}

    bsp::cellular::antenna antenna;
};

class CellularCallRequestMessage : public CellularMessage
{
  public:
    CellularCallRequestMessage(const utils::PhoneNumber::View &number)
        : CellularMessage(MessageType::CellularCallRequest), number(number)
    {}
    utils::PhoneNumber::View number;
};

class CellularSimMessage : public CellularMessage
{
  public:
    enum class SimCard
    {
        SIM1,
        SIM2
    };

    CellularSimMessage(SimCard sim) : CellularMessage(MessageType::CellularSimProcedure), sim(sim)
    {}
    virtual ~CellularSimMessage() = default;
    SimCard getSimCard() const noexcept
    {
        return sim;
    }

  private:
    SimCard sim                         = defaultSimCard;
    static const SimCard defaultSimCard = SimCard::SIM1;
};

class CellularSimResponseMessage : public CellularSimMessage
{
  public:
    enum class SimState
    {
        SIMUnlocked,
        PINRequired,
        PINInvalidRetryPossible,
        PUKRequired,
        PUKInvalidRetryPossible,
        SIMBlocked
    };
    CellularSimResponseMessage(SimCard sim,
                               SimState state,
                               const utils::PhoneNumber::View &number,
                               unsigned int pinSize,
                               unsigned int attemptsLeft = defaultAttemptsLeft)
        : CellularSimMessage(sim), state(state), number(number), pinSize(pinSize), attemptsLeft(attemptsLeft)
    {}

    SimState getSimState() const noexcept
    {
        return state;
    }
    utils::PhoneNumber::View getPhoneNumber() const noexcept
    {
        return number;
    }
    unsigned int getPinSize() const noexcept
    {
        return pinSize;
    }
    unsigned int getAttemptsLeft() const noexcept
    {
        return attemptsLeft;
    }

  private:
    SimState state = defaultSimState;
    utils::PhoneNumber::View number;
    unsigned int pinSize = defaultPinSize;
    /// ignored if state is not one of { PINInvalidRetryPossible, PUKInvalidRetryPossible }
    unsigned int attemptsLeft = defaultAttemptsLeft;

    static const unsigned int defaultPinSize      = 4;
    static const unsigned int defaultAttemptsLeft = 4;
    static const SimState defaultSimState         = SimState::SIMUnlocked;
};

class CellularSimVerifyPinRequestMessage : public CellularSimMessage
{
  public:
    CellularSimVerifyPinRequestMessage(SimCard sim, std::vector<unsigned int> pinValue)
        : CellularSimMessage(sim), pinValue(std::move(pinValue))
    {}

    std::vector<unsigned int> gePinValue() const noexcept
    {
        return pinValue;
    }

  private:
    std::vector<unsigned int> pinValue;
};

class CellularGetChannelMessage : public sys::DataMessage
{
  public:
    CellularGetChannelMessage(TS0710::Channel dataChannel = TS0710::Channel::None)
        : sys::DataMessage(MessageType::CellularGetChannel), dataChannel(dataChannel)
    {}
    TS0710::Channel dataChannel;
};

class CellularGetChannelResponseMessage : public sys::DataMessage
{
  public:
    CellularGetChannelResponseMessage(DLC_channel *dataChannelPtr = nullptr)
        : sys::DataMessage(MessageType::CellularGetChannelResponse), dataChannelPtr(dataChannelPtr)
    {}
    DLC_channel *dataChannelPtr;
};

class CellularResponseMessage : public sys::ResponseMessage
{
  public:
    CellularResponseMessage(bool retCode,
                            std::string retdata    = std::string(),
                            MessageType responseTo = MessageType::MessageTypeUninitialized)
        : sys::ResponseMessage(sys::ReturnCodes::Success, responseTo), retCode(retCode), data(retdata){};
    CellularResponseMessage(bool retCode, MessageType responseTo)
        : sys::ResponseMessage(sys::ReturnCodes::Success, responseTo), retCode(retCode){};
    virtual ~CellularResponseMessage(){};

    bool retCode;
    std::string data;
};

class CellularAntennaResponseMessage : public sys::ResponseMessage
{
  public:
    CellularAntennaResponseMessage(bool retCode, bsp::cellular::antenna retAntenna, MessageType responseTo)
        : sys::ResponseMessage(sys::ReturnCodes::Success, responseTo), retCode(retCode)
    {
        antenna = retAntenna;
    };

    bool retCode;
    bsp::cellular::antenna antenna;
};
namespace cellular
{

    class StateChange : public CellularMessage
    {
      public:
        const State::ST request;
        StateChange(const State::ST request = State::ST::Failed)
            : CellularMessage(MessageType::CellularStateRequest), request(request)
        {}
    };

    class RawCommand : public CellularNotificationMessage
    {
      public:
        RawCommand() : CellularNotificationMessage(CellularNotificationMessage::Type::RawCommand){};
        virtual ~RawCommand() = default;
        std::string command;
        uint32_t timeout = 1000;
    };

    class RawCommandResp : public CellularResponseMessage
    {
      public:
        RawCommandResp(uint32_t retCode) : CellularResponseMessage(retCode){};
        virtual ~RawCommandResp() = default;
        std::vector<std::string> response;
    };

    class RawCommandRespAsync : public CellularMessage
    {
      public:
        RawCommandRespAsync(MessageType messageType) : CellularMessage(messageType){};
        virtual ~RawCommandRespAsync() = default;
        std::vector<std::string> data;
    };

} // namespace cellular

#endif // PUREPHONE_CELLULARMESSAGE_HPP