Mbed OS Reference
Loading...
Searching...
No Matches
CellularNetwork.h
1/* Copyright (c) 2017,2018 Arm Limited and affiliates.
2 * SPDX-License-Identifier: Apache-2.0
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef CELLULAR_NETWORK_H_
18#define CELLULAR_NETWORK_H_
19
20#include "CellularList.h"
21#include "Callback.h"
22#include "netsocket/nsapi_types.h"
23
24namespace mbed {
25
26/* Maximum length of IPV6 address in ipv4-like dotted format. More info in 3gpp 27007.*/
27const int MAX_IPV6_ADDR_IN_IPV4LIKE_DOTTED_FORMAT = 63;
28/* Maximum length of access point name */
29const int MAX_ACCESSPOINT_NAME_LENGTH = 100;
30const int MAX_OPERATOR_NAME_LONG = 16;
31const int MAX_OPERATOR_NAME_SHORT = 8;
32
33/**
34 * @addtogroup Cellular
35 * @{
36 */
37
38/// An abstract interface for connecting to a network and getting information from it.
40protected:
41 // friend of CellularDevice so that it's the only way to close/delete this class.
42 friend class CellularDevice;
43
44 virtual ~CellularNetwork() {}
45
46public:
47 /* Definition for Supported CIoT EPS optimizations type. */
48 enum CIoT_Supported_Opt {
49 CIOT_OPT_NO_SUPPORT = 0, /* No support. */
50 CIOT_OPT_CONTROL_PLANE, /* Support for control plane CIoT EPS optimization. */
51 CIOT_OPT_USER_PLANE, /* Support for user plane CIoT EPS optimization. */
52 CIOT_OPT_BOTH, /* Support for both control plane CIoT EPS optimization and user plane CIoT EPS
53 optimization. */
54 CIOT_OPT_MAX
55 };
56
57 /* Definition for Preferred CIoT EPS optimizations type. */
58 enum CIoT_Preferred_UE_Opt {
59 PREFERRED_UE_OPT_NO_PREFERENCE = 0, /* No preference. */
60 PREFERRED_UE_OPT_CONTROL_PLANE, /* Preference for control plane CIoT EPS optimization. */
61 PREFERRED_UE_OPT_USER_PLANE, /* Preference for user plane CIoT EPS optimization. */
62 PREFERRED_UE_OPT_MAX
63 };
64
65 /* Network registration status */
66 enum RegistrationStatus {
67 StatusNotAvailable = -1,
68 NotRegistered = 0,
69 RegisteredHomeNetwork,
70 SearchingNetwork,
71 RegistrationDenied,
72 Unknown,
73 RegisteredRoaming,
74 RegisteredSMSOnlyHome,
75 RegisteredSMSOnlyRoaming,
76 AttachedEmergencyOnly,
77 RegisteredCSFBNotPreferredHome,
78 RegisteredCSFBNotPreferredRoaming,
79 AlreadyRegistered = 11, // our definition when modem says that we are not registered but we have active PDP Context
80 RegistrationStatusMax
81 };
82
83 /* Network registration type */
84 enum RegistrationType {
85 C_EREG = 0,
86 C_GREG,
87 C_REG,
88 C_MAX
89 };
90
91 /* device attach status to network */
92 enum AttachStatus {
93 Detached = 0,
94 Attached,
95 };
96
97 enum RadioAccessTechnology {
98 RAT_GSM,
99 RAT_GSM_COMPACT,
100 RAT_UTRAN,
101 RAT_EGPRS,
102 RAT_HSDPA,
103 RAT_HSUPA,
104 RAT_HSDPA_HSUPA,
105 RAT_E_UTRAN,
106 RAT_CATM1,
107 RAT_NB1,
108 RAT_UNKNOWN,
109 RAT_MAX = 11 // to reserve string array
110 };
111
112 /// 3GPP TS 27.007 - 7.3 PLMN selection +COPS
113 struct operator_t {
114 enum Status {
115 Unknown,
116 Available,
117 Current,
118 Forbiden
119 };
120
121 Status op_status;
122 char op_long[MAX_OPERATOR_NAME_LONG + 1];
123 char op_short[MAX_OPERATOR_NAME_SHORT + 1];
124 char op_num[MAX_OPERATOR_NAME_SHORT + 1];
125 RadioAccessTechnology op_rat;
126 operator_t *next;
127
128 operator_t()
129 {
130 op_status = Unknown;
131 op_rat = RAT_UNKNOWN;
132 next = NULL;
133 op_long[0] = '\0';
134 op_short[0] = '\0';
135 op_num[0] = '\0';
136 }
137 };
138
140
141 /// Cellular operator names in numeric and alpha format
143 char numeric[MAX_OPERATOR_NAME_SHORT + 1];
144 char alpha[MAX_OPERATOR_NAME_LONG + 1];
145 operator_names_t *next;
147 {
148 numeric[0] = '\0';
149 alpha[0] = '\0';
150 next = NULL;
151 }
152 };
154
155 /// Network registering mode
157 NWModeAutomatic = 0, // automatic registering
158 NWModeManual, // manual registering with plmn
159 NWModeDeRegister, // deregister from network
160 NWModeSetOnly, // set only <format> (for read command +COPS?), do not attempt registration/deregistration
161 NWModeManualAutomatic // if manual fails, fallback to automatic
162 };
163
164 /// Operator name format
166 OperatorNameAlphaLong = 0, // alphanumeric long form
167 OperatorNameAlphaShort, // alphanumeric short form
168 OperatorNameNumeric // numeric digits
169 };
170
171 /// Network registration information
173 RegistrationType _type;
174 RegistrationStatus _status;
175 RadioAccessTechnology _act;
176 int _cell_id;
177 int _lac;
178 int _active_time;
179 int _periodic_tau;
180
182 {
183 _type = C_MAX;
184 _status = StatusNotAvailable;
185 _act = RAT_UNKNOWN;
186 _cell_id = -1;
187 _lac = -1;
188 _active_time = -1;
189 _periodic_tau = -1;
190 }
191 };
192
193 /** Request registering to network.
194 *
195 * @param plmn format is in numeric format or 0 for automatic network registration
196 * @return NSAPI_ERROR_OK on success
197 * NSAPI_ERROR_DEVICE_ERROR on failure
198 */
199 virtual nsapi_error_t set_registration(const char *plmn = 0) = 0;
200
201 /** Get the current network registering mode
202 *
203 * @param mode on success the current network registering mode, otherwise unchanged
204 * @return NSAPI_ERROR_OK on success
205 * NSAPI_ERROR_DEVICE_ERROR on failure
206 */
208
209 /** Activate/deactivate listening of network events for the given RegistrationType.
210 * This should be called after network class is created and ready to receive AT commands.
211 * After successful call network class starts to get information about network changes like
212 * registration statue, access technology, cell id...
213 *
214 * @param type RegistrationType to set urc on/off
215 * @param on Controls are urc active or not
216 * @return NSAPI_ERROR_OK on success
217 * NSAPI_ERROR_UNSUPPORTED if the modem does not support RegistrationType
218 * NSAPI_ERROR_DEVICE_ERROR on failure
219 */
220 virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on) = 0;
221
222
223 /** Request attach to network.
224 *
225 * @return NSAPI_ERROR_OK on success
226 * NSAPI_ERROR_DEVICE_ERROR on failure
227 */
229
230 /** Request attach status from network.
231 *
232 * @param status see AttachStatus values
233 * @return NSAPI_ERROR_OK on success
234 * NSAPI_ERROR_DEVICE_ERROR on failure
235 */
236 virtual nsapi_error_t get_attach(AttachStatus &status) = 0;
237
238 /** Request detach and deregister from a network.
239 *
240 * @return NSAPI_ERROR_OK on success
241 * NSAPI_ERROR_DEVICE_ERROR on failure
242 */
243 virtual nsapi_error_t detach() = 0;
244
245 /** Sets radio access technology.
246 *
247 * @param rat Radio access technology
248 * @return NSAPI_ERROR_OK on success
249 * NSAPI_ERROR_UNSUPPORTED if the given rat is RAT_UNKNOWN or inheriting target class
250 * has not implemented method set_access_technology_impl(...)
251 * OR return value of the inheriting target class set_access_technology_impl(...)
252 */
253 virtual nsapi_error_t set_access_technology(RadioAccessTechnology rat) = 0;
254
255 /** Scans for operators module can reach.
256 *
257 * @param operators Container of reachable operators and their access technologies
258 * @param ops_count Number of found operators
259 * @return NSAPI_ERROR_OK on success
260 * NSAPI_ERROR_NO_MEMORY on memory failure
261 * NSAPI_ERROR_DEVICE_ERROR on other failures
262 */
263 virtual nsapi_error_t scan_plmn(operList_t &operators, int &ops_count) = 0;
264
265 /** Set CIoT optimizations.
266 *
267 * @param supported_opt Supported CIoT EPS optimizations
268 * (the HW support can be checked with get_ciot_ue_optimization_config).
269 * @param preferred_opt Preferred CIoT EPS optimizations.
270 * @param network_support_cb This callback will be called when CIoT network optimization support is known
271 * @return NSAPI_ERROR_OK on success
272 * NSAPI_ERROR_DEVICE_ERROR on failure
273 */
274 virtual nsapi_error_t set_ciot_optimization_config(CIoT_Supported_Opt supported_opt,
275 CIoT_Preferred_UE_Opt preferred_opt,
276 Callback<void(CIoT_Supported_Opt)> network_support_cb) = 0;
277
278 /** Get UE CIoT optimizations.
279 *
280 * @param supported_opt Supported CIoT EPS optimizations.
281 * @param preferred_opt Preferred CIoT EPS optimizations.
282 * @return NSAPI_ERROR_OK on success
283 * NSAPI_ERROR_DEVICE_ERROR on failure
284 */
285 virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt,
286 CIoT_Preferred_UE_Opt &preferred_opt) = 0;
287
288 /** Get Network CIoT optimizations.
289 *
290 * @param supported_network_opt Supported CIoT EPS optimizations. CIOT_OPT_MAX will be returned,
291 * if the support is not known
292 * @return NSAPI_ERROR_OK on success
293 * NSAPI_ERROR_DEVICE_ERROR on failure
294 */
295 virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt) = 0;
296
297 enum SignalQuality {
298 SignalQualityUnknown = 99
299 };
300
301 /** Get signal quality parameters.
302 *
303 * @param rssi signal strength level as defined in 3GPP TS 27.007, range -113..-51 dBm or SignalQualityUnknown
304 * @param ber bit error rate as RXQUAL as defined in 3GPP TS 45.008, range 0..7 or SignalQualityUnknown
305 * @return NSAPI_ERROR_OK on success
306 * NSAPI_ERROR_DEVICE_ERROR on other failures
307 */
308 virtual nsapi_error_t get_signal_quality(int &rssi, int *ber = NULL) = 0;
309
310 /** Get the last 3GPP error code
311 * @return see 3GPP TS 27.007 error codes
312 */
313 virtual int get_3gpp_error() = 0;
314
315 /** Get the operator parameters.
316 *
317 * @param format format of the operator field
318 * @param operator_params applicable operator param fields filled
319 * @return NSAPI_ERROR_OK on success
320 * NSAPI_ERROR_DEVICE_ERROR on case of other failures
321 */
322 virtual nsapi_error_t get_operator_params(int &format, operator_t &operator_params) = 0;
323
324 /** Register callback for status reporting
325 *
326 * The specified status callback function will be called on status changes
327 * on the network. The parameters on the callback are the event type and
328 * event-type dependent reason parameter.
329 *
330 * @remark Application should not call attach if using CellularContext class. Call instead CellularContext::attach
331 * as CellularDevice is dependent of this attach if CellularContext/CellularDevice is used to get
332 * device/sim ready, registered, attached, connected.
333 *
334 * @param status_cb The callback for status changes
335 */
336 virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) = 0;
337
338 /** Read operator names
339 *
340 * @param op_names on successful return contains linked list of operator names.
341 * @return NSAPI_ERROR_OK on success
342 * NSAPI_ERROR_NO_MEMORY on memory failure
343 * NSAPI_ERROR_DEVICE_ERROR on other failures
344 */
346
347 /** Check if there is any PDP context active. If cid is given, then check is done only for that cid.
348 *
349 * @param number_of_active_contexts If given then in return contains the number of all active contexts
350 * @param cid If given then check if the context with this cid is active
351 *
352 * @return true if any (or the given cid) context is active, false otherwise or in case of error
353 */
354 virtual bool is_active_context(int *number_of_active_contexts = NULL, int cid = -1) = 0;
355
356 /** Gets the latest received registration parameters from the network:
357 * type, status, access technology, cell_id, lac, active_time, periodic_tau.
358 *
359 * @param reg_params see registration_params_t
360 * @return NSAPI_ERROR_OK on success
361 * NSAPI_ERROR_DEVICE_ERROR on failure
362 */
364
365 /** Gets the current network registration parameters from the network with type:
366 * status, access technology, cell_id, lac, active_time, periodic_tau.
367 *
368 * @param type see RegistrationType values
369 * @param reg_params see registration_params_t
370 * @return NSAPI_ERROR_OK on success
371 * NSAPI_ERROR_UNSUPPORTED if the modem does not support RegistrationType
372 * NSAPI_ERROR_DEVICE_ERROR on failure
373 */
374 virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t &reg_params) = 0;
375
376 enum EDRXAccessTechnology {
377 EDRXGSM_EC_GSM_IoT_mode = 1,
378 EDRXGSM_A_Gb_mode,
379 EDRXUTRAN_Iu_mode,
380 EDRXEUTRAN_WB_S1_mode,
381 EDRXEUTRAN_NB_S1_mode
382 };
383
384 /** Set discontinuous reception time on cellular device.
385 *
386 * @remark See 3GPP TS 27.007 eDRX for details.
387 *
388 * @param mode disable or enable the use of eDRX
389 * @param act_type type of access technology
390 * @param edrx_value requested edxr value. Extended DRX parameters information element.
391 *
392 * @return NSAPI_ERROR_OK on success
393 * NSAPI_ERROR_DEVICE_ERROR on failure
394 */
395 virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value) = 0;
396
397 /** Sets the packet domain network reporting. Useful for getting events when detached from the
398 * network. When detach event arrives it is propagated as NSAPI_STATUS_DISCONNECTED to callback set
399 * with attach(...).
400 *
401 * @param on true for enabling event reporting, false for disabling
402 * @return NSAPI_ERROR_OK on success
403 * NSAPI_ERROR_UNSUPPORTED is command is not supported by the modem
404 * NSAPI_ERROR_DEVICE_ERROR on failure
405 */
407 {
409 }
410};
411
412/**
413 * @}
414 */
415
416} // namespace mbed
417
418#endif // CELLULAR_NETWORK_H_
Callback class based on template specialization.
Definition: Callback.h:53
Class CellularDevice.
Class CellularList.
Definition: CellularList.h:30
An abstract interface for connecting to a network and getting information from it.
OperatorNameFormat
Operator name format.
NWRegisteringMode
Network registering mode.
virtual nsapi_error_t set_packet_domain_event_reporting(bool on)
Sets the packet domain network reporting.
virtual nsapi_error_t get_network_registering_mode(NWRegisteringMode &mode)=0
Get the current network registering mode.
virtual nsapi_error_t get_signal_quality(int &rssi, int *ber=NULL)=0
Get signal quality parameters.
virtual nsapi_error_t set_ciot_optimization_config(CIoT_Supported_Opt supported_opt, CIoT_Preferred_UE_Opt preferred_opt, Callback< void(CIoT_Supported_Opt)> network_support_cb)=0
Set CIoT optimizations.
virtual nsapi_error_t get_ciot_network_optimization_config(CIoT_Supported_Opt &supported_network_opt)=0
Get Network CIoT optimizations.
virtual nsapi_error_t get_attach(AttachStatus &status)=0
Request attach status from network.
virtual nsapi_error_t get_operator_names(operator_names_list &op_names)=0
Read operator names.
virtual nsapi_error_t get_ciot_ue_optimization_config(CIoT_Supported_Opt &supported_opt, CIoT_Preferred_UE_Opt &preferred_opt)=0
Get UE CIoT optimizations.
virtual nsapi_error_t set_receive_period(int mode, EDRXAccessTechnology act_type, uint8_t edrx_value)=0
Set discontinuous reception time on cellular device.
virtual nsapi_error_t set_registration_urc(RegistrationType type, bool on)=0
Activate/deactivate listening of network events for the given RegistrationType.
virtual nsapi_error_t set_attach()=0
Request attach to network.
virtual nsapi_error_t get_operator_params(int &format, operator_t&operator_params)=0
Get the operator parameters.
virtual nsapi_error_t set_access_technology(RadioAccessTechnology rat)=0
Sets radio access technology.
virtual bool is_active_context(int *number_of_active_contexts=NULL, int cid=-1)=0
Check if there is any PDP context active.
virtual nsapi_error_t get_registration_params(registration_params_t &reg_params)=0
Gets the latest received registration parameters from the network: type, status, access technology,...
virtual nsapi_error_t detach()=0
Request detach and deregister from a network.
virtual nsapi_error_t set_registration(const char *plmn=0)=0
Request registering to network.
virtual nsapi_error_t scan_plmn(operList_t &operators, int &ops_count)=0
Scans for operators module can reach.
virtual nsapi_error_t get_registration_params(RegistrationType type, registration_params_t &reg_params)=0
Gets the current network registration parameters from the network with type: status,...
virtual void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb)=0
Register callback for status reporting.
virtual int get_3gpp_error()=0
Get the last 3GPP error code.
signed int nsapi_error_t
Type used to represent error codes.
Definition: nsapi_types.h:142
@ NSAPI_ERROR_UNSUPPORTED
Definition: nsapi_types.h:87
Cellular operator names in numeric and alpha format.
3GPP TS 27.007 - 7.3 PLMN selection +COPS
Network registration information.