summaryrefslogtreecommitdiff
path: root/include/mts/MTS_IO_TelitRadio.h
blob: 621bfb4705ff9ffd0b9dc6d521fbe7b9a5c068da (plain)
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
/*
 * Copyright (C) 2015 by Multi-Tech Systems
 *
 * This file is part of libmts-io.
 *
 * libmts-io is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * libmts-io is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with libmts-io.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef MTS_IO_TELITRADIO_H_
#define MTS_IO_TELITRADIO_H_

#include <string>
#include <vector>

#include <json/json.h>

#include <mts/MTS_IO_CellularRadio.h>
#include <mts/MTS_IO_SerialConnection.h>
#include <mts/MTS_NonCopyable.h>
#include <mts/MTS_AutoPtr.h>
#include <mts/MTS_Stdint.h>

namespace MTS {
    namespace IO {
        class TelitRadio : public CellularRadio {

            public:
                virtual ~TelitRadio();

                virtual bool initialize(uint32_t iTimeoutMillis = 5000);
                virtual bool resetRadio(uint32_t iTimeoutMillis = 5000);
                virtual bool resetConnection(uint32_t iTimeoutMillis = 5000);
                virtual void shutdown();

                const std::string& getName() const;

                virtual CODE getModel(std::string& sModel);

                virtual CODE getFirmware(std::string& sFirmware);
                virtual CODE getFirmwareBuild(std::string& sFirmwareBuild);
                virtual CODE getHardware(std::string& sHardware);
                virtual CODE getManufacturer(std::string& sManufacturer);
                virtual CODE getImei(std::string& sImei);
                virtual CODE getMeid(std::string& sMeid);
                virtual CODE getImsi(std::string& sImsi);
                virtual CODE getSimStatus(std::string& sSimStatus);
                virtual CODE getIccid(std::string& sIccid);
                virtual CODE getService(std::string& sService);
                virtual CODE getLac(std::string& sLac);
                virtual CODE getMdn(std::string& sMdn);
                virtual CODE getMsid(std::string& sMsid);
                virtual CODE getType(std::string& sType);
                virtual CODE getCarrier(std::string& sCarrier);
                virtual CODE getNetwork(std::string& sNetwork);
                virtual CODE getTower(std::string& sTower);
                virtual CODE getTime(std::string& sDate, std::string& sTime, std::string& sTimeZone);
                virtual CODE getRoaming(bool& bRoaming);

                virtual CODE getSignalStrength(int32_t& iRssi);
                virtual CODE getModemLocation(std::string& sLocation);
                virtual CODE convertSignalStrengthTodBm(const int32_t& iRssi, int32_t& dBm);
                virtual CODE convertdBmToSignalStrength(const int32_t& dBm, int32_t& iRssi);

                virtual CODE getRegistration(REGISTRATION& eRegistration);
                virtual CODE convertRegistrationToString(REGISTRATION eRegistration, std::string& sRegistration);

                //! Gather details of the radio's Mobile IP Profile
                /*!
                 \param Json::Value object that will be populated with MIP data
                 \return Returns result code of gathering MIP
                 */
                virtual CODE getMipProfile(Json::Value& jMipProfile);

                /*
                 * jArgs = {
                 *     "msl" : "Master Subsidy Lock (Aeris, Sprint): STRING"
                 * }
                 */
                virtual CODE validateMsl(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "mdn" : "Mobile Directory Number : STRING",
                 *     "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING"
                 * }
                 */
                virtual CODE setMdn(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "msid" : "Mobil Station ID (MSID) aka MIN aka MSIN : STRING",
                 *     "msl" : "[OPTIONAL] Master Subsidy Lock (Aeris, Sprint): STRING"
                 * }
                 */
                virtual CODE setMsid(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "activeProfile" : "Set active profile: STRING"
                 * }
                 */
                virtual CODE setMipActiveProfile(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "nai" : "Network Access Identifier : STRING"
                 * }
                 */
                virtual CODE setMipNai(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "homeIp" : "Home Address : STRING"
                 * }
                 */
                virtual CODE setMipHomeIp(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "primaryHa" : "Primary Home Agent : STRING"
                 * }
                 */
                virtual CODE setMipPrimaryHa(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "secondaryHa" : "Secondary Home Agent : STRING"
                 * }
                 */
                virtual CODE setMipSecondaryHa(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "mnAaaSpi" : "Mobile Node Authentication, Authorization, and Accounting Server Security Parameter Index : STRING"
                 * }
                 */
                virtual CODE setMipMnAaaSpi(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "mnHaSpi" : "Mobile Node Home Agent Security Server Parameter Index : STRING"
                 * }
                 */
                virtual CODE setMipMnHaSpi(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "revTun" : "[DESCRIPTION] : STRING"
                 * }
                 */
                virtual CODE setMipRevTun(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "mnAaaSs" : "Mobile Node Authentication, Authorization, and Accounting Server Shared Secret : STRING"
                 * }
                 */
                virtual CODE setMipMnAaaSs(const Json::Value& jArgs);

                /*
                 * jArgs = {
                 *     "mnHaSs" : "Mobile Node Home Agent Shared Secret : STRING"
                 * }
                 */
                virtual CODE setMipMnHaSs(const Json::Value& jArgs);

                /*
                 * jArgs = null
                 */
                virtual CODE updateDc(const Json::Value& jArgs, UpdateCb& stepCb);

                /*
                 * jArgs = null
                 */
                virtual CODE updatePrl(const Json::Value& jArgs, UpdateCb& stepCb);

                /*
                 * jArgs = null
                 */
                virtual CODE updateFumo(const Json::Value& jArgs, UpdateCb& stepCb);

                /*
                 * jArgs = {
                 *     "msl" : "Master Subsidy Lock (Sprint): STRING"
                 * }
                 */
                virtual CODE resetHfa(const Json::Value& jArgs, UpdateCb& stepCb);

                /*
                 * jArgs = {
                 *     "mdn" : "Mobile Directory Number (Aeris): STRING"
                 *     "msid" : "Mobile Station ID (Aeris): STRING"
                 * }
                 */
                virtual CODE activate(const Json::Value& jArgs, UpdateCb& stepCb);

                /*
                 * jArgs = {
                 *     "enabled" : "RX Diversity Enabled ("0" or "1"): STRING"
                 * }
                 */
                virtual CODE setRxDiversity(const Json::Value& jArgs)=0;
                /*
                 * jArgs = {
                 *     "fwid" : "Firmware Image To Be Enabled: STRING"
                 * }
                 */
                virtual CODE setActiveFirmware(const Json::Value& jArgs);
                virtual CODE getActiveFirmware(std::string& sFwId);

                virtual CODE getEcho(bool& bEnabled);
                virtual CODE setEcho(bool bEnabled = true);

                virtual CODE getStaticInformation(Json::Value& jData);
                virtual CODE getNetworkStatus(Json::Value& jData);

                virtual CODE sendBasicCommand(const std::string& sCmd, int32_t timeoutMillis = 100, const char& ESC = CR);

                virtual std::string sendCommand(const std::string& sCmd,
                                                const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS,
                                                int32_t timeoutMillis = 100,
                                                const char& ESC = CR);


                static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo,
                                               const std::string& sCmd,
                                               const std::vector<std::string>& vBail = DEFAULT_BAIL_STRINGS,
                                               int32_t timeoutMillis = 100,
                                               const char& ESC = CR);

                virtual std::string sendCommand(const std::string& sCmd,
                                                IsNeedMoreData& isNeedMoreData,
                                                int32_t timeoutMillis = 100,
                                                const char& ESC = CR);

                static std::string sendCommand(MTS::AutoPtr<MTS::IO::Connection>& apIo,
                                               const std::string& sCmd,
                                               IsNeedMoreData& isNeedMoreData,
                                               int32_t timeoutMillis = 100,
                                               const char& ESC = CR);

                static CODE test(MTS::AutoPtr<MTS::IO::Connection>& apIo, uint32_t timeoutSeconds = 30);

                static std::string extractModelFromResult(const std::string& sResult);
                static std::string getCodeAsString(CODE code);

            protected:

                TelitRadio(const std::string& sName, const std::string& sRadioPort);

                virtual bool getCarrierFromFirmware(const std::string& sFirmware, std::string& sCarrier);
                virtual bool getHardwareVersionFromFirmware(const std::string& sFirmware, std::string& sHardware);

                virtual void getCommonNetworkStats(Json::Value& jData);

                void initMipProfile(Json::Value& jData);

                bool splitAndAssign(const std::string& sLine, const std::string& sKey, Json::Value& jParent, const std::string& sJsonKey, Json::ValueType eType = Json::ValueType::stringValue);



            private:
                class RadioBandMap : public MTS::NonCopyable {
                    public:
                    	RadioBandMap()
                    	{
                            m_sChannel = TelitRadio::VALUE_UNKNOWN;
                            m_iChannel = 0;
                            m_sRadioType = TelitRadio::VALUE_UNKNOWN;
                    	}

                        RadioBandMap(const std::string &channel, const std::string &radioType) :
                            m_sChannel(channel),
                            m_sRadioType(radioType)
                        {
                        	m_iChannel = strtol(m_sChannel.c_str(), NULL, 10);
                        }

                        virtual ~RadioBandMap() {}

                        const char *getRadioBandName();
                        const char *getRadioBandName(const std::string &channel, const std::string &radioType);

                    private:

                        const char *getLTEBand(const int channel);
                        const char *getCDMABand(const int channel);
                        const char *getGSMBand(const int channel);

                        std::string    m_sChannel;
                        int            m_iChannel;
                        std::string    m_sRadioType;
                };

                std::string m_sName;
                std::string m_sRadioPort;
                std::string m_sFirmware;
                std::string m_sCarrier;
                MTS::AutoPtr<MTS::IO::Connection> m_apIo;

                bool m_bEchoEnabled;
                bool m_bEnableEchoOnClose;

                std::string queryLteLac();
                std::string queryCGREGstring();
                void setCGREG(std::string value);
        };
    }
}



#endif