Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
cellular.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Bjarki Arge Andreasen
3 * Copyright (c) 2023 Lucas Denefle
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 */
7
13
14#ifndef ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
15#define ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
16
29
30#include <zephyr/types.h>
31#include <zephyr/device.h>
32#include <errno.h>
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
77
90
97
115
143
157
158/* Opaque bit-mask large enough for all current & future events */
160
165
170
175
177#define CELLULAR_EUTRAN_CELL_ID_MAX 0xFFFFFFFU
179#define CELLULAR_EUTRAN_CELL_ID_INVALID UINT32_MAX
180
199
228
241typedef void (*cellular_event_cb_t)(const struct device *dev, enum cellular_event event,
242 const void *payload, void *user_data);
243
249
251typedef int (*cellular_api_configure_networks)(const struct device *dev,
252 const struct cellular_network *networks,
253 uint8_t size);
254
256typedef int (*cellular_api_get_supported_networks)(const struct device *dev,
257 const struct cellular_network **networks,
258 uint8_t *size);
259
261typedef int (*cellular_api_get_signal)(const struct device *dev,
262 const enum cellular_signal_type type, int16_t *value);
263
265typedef int (*cellular_api_get_modem_info)(const struct device *dev,
266 const enum cellular_modem_info_type type, char *info,
267 size_t size);
268
270typedef int (*cellular_api_get_registration_status)(const struct device *dev,
272 enum cellular_registration_status *status);
273
275typedef int (*cellular_api_get_network_status)(const struct device *dev,
277
279typedef int (*cellular_api_set_apn)(const struct device *dev, const char *apn);
280
282typedef int (*cellular_api_set_callback)(const struct device *dev, cellular_event_mask_t mask,
283 cellular_event_cb_t cb, void *user_data);
284
286typedef const struct cellular_stats *(*cellular_api_get_stats)(const struct device *dev);
287
311
313
334static inline int cellular_configure_networks(const struct device *dev,
335 const struct cellular_network *networks, uint8_t size)
336{
337 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
338
339 if (api->configure_networks == NULL) {
340 return -ENOSYS;
341 }
342
343 return api->configure_networks(dev, networks, size);
344}
345
356static inline int cellular_get_supported_networks(const struct device *dev,
357 const struct cellular_network **networks,
358 uint8_t *size)
359{
360 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
361
362 if (api->get_supported_networks == NULL) {
363 return -ENOSYS;
364 }
365
366 return api->get_supported_networks(dev, networks, size);
367}
368
380static inline int cellular_get_signal(const struct device *dev,
381 const enum cellular_signal_type type, int16_t *value)
382{
383 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
384
385 if (api->get_signal == NULL) {
386 return -ENOSYS;
387 }
388
389 return api->get_signal(dev, type, value);
390}
391
404static inline int cellular_get_modem_info(const struct device *dev,
405 const enum cellular_modem_info_type type, char *info,
406 size_t size)
407{
408 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
409
410 if (api->get_modem_info == NULL) {
411 return -ENOSYS;
412 }
413
414 return api->get_modem_info(dev, type, info, size);
415}
416
428static inline int cellular_get_registration_status(const struct device *dev,
430 enum cellular_registration_status *status)
431{
432 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
433
434 if (api->get_registration_status == NULL) {
435 return -ENOSYS;
436 }
437
438 return api->get_registration_status(dev, tech, status);
439}
440
456static inline int cellular_get_network_status(const struct device *dev,
457 struct cellular_evt_network_status *status)
458{
459 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
460
461 if (api->get_network_status == NULL) {
462 return -ENOSYS;
463 }
464
465 return api->get_network_status(dev, status);
466}
467
483static inline int cellular_set_apn(const struct device *dev, const char *apn)
484{
485 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
486
487 if (api->set_apn == NULL) {
488 return -ENOSYS;
489 }
490
491 return api->set_apn(dev, apn);
492}
493
507static inline int cellular_set_callback(const struct device *dev, cellular_event_mask_t mask,
508 cellular_event_cb_t cb, void *user_data)
509{
510 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
511
512 if (api->set_callback == NULL) {
513 return -ENOSYS;
514 }
515
516 return api->set_callback(dev, mask, cb, user_data);
517}
518
531static inline const struct cellular_stats *cellular_get_stats(const struct device *dev)
532{
533 const struct cellular_driver_api *api = DEVICE_API_GET(cellular, dev);
534
535 if (api->get_stats == NULL) {
536 return NULL;
537 }
538
539 return api->get_stats(dev);
540}
541
542#ifdef __cplusplus
543}
544#endif
545
549
550#endif /* ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ */
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1505
System error numbers.
int(* cellular_api_get_modem_info)(const struct device *dev, const enum cellular_modem_info_type type, char *info, size_t size)
API for getting modem information.
Definition cellular.h:265
int(* cellular_api_get_registration_status)(const struct device *dev, enum cellular_access_technology tech, enum cellular_registration_status *status)
API for getting registration status.
Definition cellular.h:270
int(* cellular_api_get_network_status)(const struct device *dev, struct cellular_evt_network_status *status)
API for getting the last reported network (serving cell) status.
Definition cellular.h:275
int(* cellular_api_get_supported_networks)(const struct device *dev, const struct cellular_network **networks, uint8_t *size)
API for getting supported networks.
Definition cellular.h:256
int(* cellular_api_configure_networks)(const struct device *dev, const struct cellular_network *networks, uint8_t size)
API for configuring networks.
Definition cellular.h:251
int(* cellular_api_get_signal)(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
API for getting network signal strength.
Definition cellular.h:261
const struct cellular_stats *(* cellular_api_get_stats)(const struct device *dev)
API for reading operational statistics.
Definition cellular.h:286
int(* cellular_api_set_apn)(const struct device *dev, const char *apn)
API for programming APN.
Definition cellular.h:279
int(* cellular_api_set_callback)(const struct device *dev, cellular_event_mask_t mask, cellular_event_cb_t cb, void *user_data)
API for registering an asynchronous callback.
Definition cellular.h:282
static int cellular_get_signal(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
Get signal for the device.
Definition cellular.h:380
static const struct cellular_stats * cellular_get_stats(const struct device *dev)
Read operational statistics from the cellular device.
Definition cellular.h:531
cellular_access_technology
Cellular access technologies (3GPP TS 27.007 AcT).
Definition cellular.h:39
cellular_event
Events emitted asynchronously by a cellular driver.
Definition cellular.h:145
static int cellular_set_apn(const struct device *dev, const char *apn)
Set the APN used for PDP context.
Definition cellular.h:483
static int cellular_get_supported_networks(const struct device *dev, const struct cellular_network **networks, uint8_t *size)
Get supported cellular networks for the device.
Definition cellular.h:356
cellular_registration_status
Cellular registration status (3GPP TS 27.007).
Definition cellular.h:117
cellular_signal_type
Cellular signal type.
Definition cellular.h:92
static int cellular_get_modem_info(const struct device *dev, const enum cellular_modem_info_type type, char *info, size_t size)
Get modem info for the device.
Definition cellular.h:404
static int cellular_set_callback(const struct device *dev, cellular_event_mask_t mask, cellular_event_cb_t cb, void *user_data)
Subscribe to asynchronous cellular events.
Definition cellular.h:507
uint32_t cellular_event_mask_t
Definition cellular.h:159
static int cellular_configure_networks(const struct device *dev, const struct cellular_network *networks, uint8_t size)
Configure cellular networks for the device.
Definition cellular.h:334
void(* cellular_event_cb_t)(const struct device *dev, enum cellular_event event, const void *payload, void *user_data)
Prototype for cellular event callbacks.
Definition cellular.h:241
static int cellular_get_network_status(const struct device *dev, struct cellular_evt_network_status *status)
Get the last reported network (serving cell) status.
Definition cellular.h:456
cellular_modem_info_type
Cellular modem info type.
Definition cellular.h:99
static int cellular_get_registration_status(const struct device *dev, enum cellular_access_technology tech, enum cellular_registration_status *status)
Get network registration status for the device.
Definition cellular.h:428
@ CELLULAR_ACCESS_TECHNOLOGY_EC_GSM_IOT
Extended Coverage GSM for IoT (2G, 3GPP Rel 13).
Definition cellular.h:57
@ CELLULAR_ACCESS_TECHNOLOGY_UTRAN
UMTS Terrestrial Radio Access Network (3G, 3GPP Rel 99).
Definition cellular.h:45
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRA_NR_DUAL
LTE/E-UTRA & NR dual connectivity (5G, 3GPP Rel 15).
Definition cellular.h:67
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRAN_NB_S1
EUTRAN Narrowband-IoT (4G, 3GPP Rel 13).
Definition cellular.h:59
@ CELLULAR_ACCESS_TECHNOLOGY_NG_RAN
Next Generation RAN (5G, 3GPP Rel 15).
Definition cellular.h:65
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRAN
Evolved UTRAN (4G, 3GPP Rel 8).
Definition cellular.h:55
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRAN_NB_S1_SAT
Narrowband-IoT over Satellite (4G, 3GPP Rel 17).
Definition cellular.h:69
@ CELLULAR_ACCESS_TECHNOLOGY_UTRAN_HSDPA_HSUPA
UTRAN with HSDPA and HSUDP (HSPA) (3.75G, 3GPP Rel 6).
Definition cellular.h:53
@ CELLULAR_ACCESS_TECHNOLOGY_UTRAN_HSUPA
UTRAN with High Speed Uplink Packet Access (3.75G, 3GPP Rel 6).
Definition cellular.h:51
@ CELLULAR_ACCESS_TECHNOLOGY_GSM
Global System for Mobile communications (2G, 3GPP Rel 99).
Definition cellular.h:41
@ CELLULAR_ACCESS_TECHNOLOGY_UNKNOWN
Unknown access technology.
Definition cellular.h:75
@ CELLULAR_ACCESS_TECHNOLOGY_GSM_EGPRS
GSM Enhanced General Packet Radio Service (2.5G, 3GPP Rel 99).
Definition cellular.h:47
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRAN_WB_S1_SAT
LTE (wideband) over Satellite (4G, 3GPP Rel 17).
Definition cellular.h:71
@ CELLULAR_ACCESS_TECHNOLOGY_NR_5G_CN
New Radio with 5G Core Network (5G, 3GPP Rel 15).
Definition cellular.h:63
@ CELLULAR_ACCESS_TECHNOLOGY_E_UTRA_5G_CN
LTE/E-UTRA connected to 5G Core Network (5G, 3GPP Rel 15).
Definition cellular.h:61
@ CELLULAR_ACCESS_TECHNOLOGY_NG_RAN_SAT
Next Generation RAN over Satellite (5G, 3GPP Rel 17).
Definition cellular.h:73
@ CELLULAR_ACCESS_TECHNOLOGY_GSM_COMPACT
Bandwidth & Spectrum limited variant of GSM (2G, 3GPP Rel 99).
Definition cellular.h:43
@ CELLULAR_ACCESS_TECHNOLOGY_UTRAN_HSDPA
UTRAN with High Speed Downlink Packet Access (3.5G, 3GPP Rel 5).
Definition cellular.h:49
@ CELLULAR_EVENT_MODEM_COMMS_CHECK_RESULT
Result of a communications link check to the modem.
Definition cellular.h:151
@ CELLULAR_EVENT_MODEM_SUSPENDED
Cellular modem suspension callback.
Definition cellular.h:155
@ CELLULAR_EVENT_MODEM_INFO_CHANGED
One or more modem-info field changed (e.g.
Definition cellular.h:147
@ CELLULAR_EVENT_REGISTRATION_STATUS_CHANGED
Cellular network registration status changed.
Definition cellular.h:149
@ CELLULAR_EVENT_NETWORK_STATUS_CHANGED
Cellular network status changed.
Definition cellular.h:153
@ CELLULAR_REGISTRATION_UNKNOWN
Unknown (e.g.
Definition cellular.h:127
@ CELLULAR_REGISTRATION_CSFB_NOT_PREFERRED_ROAMING
Registered for "CSFB not preferred", roaming network.
Definition cellular.h:139
@ CELLULAR_REGISTRATION_SEARCHING
Not registered, searching for an operator.
Definition cellular.h:123
@ CELLULAR_REGISTRATION_DENIED
Registration denied.
Definition cellular.h:125
@ CELLULAR_REGISTRATION_SMS_ONLY_HOME
Registered for "SMS only", home network.
Definition cellular.h:131
@ CELLULAR_REGISTRATION_SMS_ONLY_ROAMING
Registered for "SMS only", roaming network.
Definition cellular.h:133
@ CELLULAR_REGISTRATION_REGISTERED_HOME
Registered, home network.
Definition cellular.h:121
@ CELLULAR_REGISTRATION_NOT_REGISTERED
Not registered, not searching.
Definition cellular.h:119
@ CELLULAR_REGISTRATION_CSFB_NOT_PREFERRED_HOME
Registered for "CSFB not preferred", home network.
Definition cellular.h:137
@ CELLULAR_REGISTRATION_RLOS
Attached for access to "Restricted Local Operator Services".
Definition cellular.h:141
@ CELLULAR_REGISTRATION_EMERGENCY_ONLY
Attached for emergency bearer services only.
Definition cellular.h:135
@ CELLULAR_REGISTRATION_REGISTERED_ROAMING
Registered, roaming.
Definition cellular.h:129
@ CELLULAR_SIGNAL_RSRQ
Definition cellular.h:95
@ CELLULAR_SIGNAL_RSRP
Definition cellular.h:94
@ CELLULAR_SIGNAL_RSSI
Definition cellular.h:93
@ CELLULAR_MODEM_INFO_SIM_IMSI
International Mobile Subscriber Identity.
Definition cellular.h:109
@ CELLULAR_MODEM_INFO_MANUFACTURER
Modem manufacturer.
Definition cellular.h:105
@ CELLULAR_MODEM_INFO_MODEL_ID
Modem model ID.
Definition cellular.h:103
@ CELLULAR_MODEM_INFO_SERIAL_NUMBER
Modem Serial Number.
Definition cellular.h:113
@ CELLULAR_MODEM_INFO_SIM_ICCID
Integrated Circuit Card Identification Number (SIM).
Definition cellular.h:111
@ CELLULAR_MODEM_INFO_FW_VERSION
Modem fw version.
Definition cellular.h:107
@ CELLULAR_MODEM_INFO_IMEI
International Mobile Equipment Identity.
Definition cellular.h:101
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition util_macro.h:44
#define ENOSYS
Function not implemented.
Definition errno.h:83
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT8_TYPE__ int8_t
Definition stdint.h:72
__INT16_TYPE__ int16_t
Definition stdint.h:73
<span class="mlabel">Driver Operations</span> Cellular driver operations
Definition cellular.h:291
cellular_api_get_stats get_stats
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:309
cellular_api_get_network_status get_network_status
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:303
cellular_api_get_supported_networks get_supported_networks
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:295
cellular_api_set_apn set_apn
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:305
cellular_api_set_callback set_callback
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:307
cellular_api_get_registration_status get_registration_status
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:301
cellular_api_get_signal get_signal
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:297
cellular_api_get_modem_info get_modem_info
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:299
cellular_api_configure_networks configure_networks
<span class="op-badge op-opt" title="This operation MAY optionally be implemented by the driver....
Definition cellular.h:293
Payload for CELLULAR_EVENT_MODEM_COMMS_CHECK_RESULT.
Definition cellular.h:172
bool success
Communications to modem checked successfully.
Definition cellular.h:173
Payload for CELLULAR_EVENT_MODEM_INFO_CHANGED.
Definition cellular.h:162
enum cellular_modem_info_type field
Which field changed.
Definition cellular.h:163
Payload for CELLULAR_EVENT_NETWORK_STATUS_CHANGED.
Definition cellular.h:182
enum cellular_registration_status status
Registration status.
Definition cellular.h:183
uint16_t phys_cell_id
Physical cell ID.
Definition cellular.h:192
uint16_t mnc
Mobile Network Code.
Definition cellular.h:188
int8_t rsrq
Received signal quality (dB).
Definition cellular.h:195
struct cellular_evt_network_status::@150331017227312054123027032261144033315032011003::@303376020136156326235373225142223153065252167310 lte
LTE Cell information.
uint16_t band
Band number (from 3GPP TS 36.101).
Definition cellular.h:193
uint32_t tac
Tracking Area Code.
Definition cellular.h:189
uint32_t gci
E-UTRAN cell ID (0 - CELLULAR_EUTRAN_CELL_ID_MAX).
Definition cellular.h:191
enum cellular_access_technology access_tech
Access technology.
Definition cellular.h:184
int16_t rsrp
Received signal power (dBm).
Definition cellular.h:194
union cellular_evt_network_status::@150331017227312054123027032261144033315032011003 cell
Generic Cell information.
uint16_t mcc
Mobile Country Code.
Definition cellular.h:187
uint32_t earfcn
E-UTRAN assigned radio channel.
Definition cellular.h:190
Payload for CELLULAR_EVENT_REGISTRATION_STATUS_CHANGED.
Definition cellular.h:167
enum cellular_registration_status status
New registration status.
Definition cellular.h:168
Cellular network structure.
Definition cellular.h:79
uint16_t * bands
List of bands, as defined by the specified cellular access technology, to enables.
Definition cellular.h:86
uint16_t size
Size of bands.
Definition cellular.h:88
enum cellular_access_technology technology
Cellular access technology.
Definition cellular.h:81
Cellular link operational statistics.
Definition cellular.h:206
uint32_t cmux_rx_dropped_bytes
Received bytes dropped because a CMUX channel buffer was full.
Definition cellular.h:226
uint32_t command_errors_cme
+CME ERROR responses.
Definition cellular.h:216
uint32_t command_failures
Control-channel command failures.
Definition cellular.h:214
uint32_t outage_ms
Cumulative time the modem was not registered, in milliseconds.
Definition cellular.h:208
uint32_t uart_rx_dropped_bytes
Received bytes the UART backend dropped because its buffer was full.
Definition cellular.h:222
uint32_t cmux_disconnects
CMUX desync/disconnect events.
Definition cellular.h:220
uint32_t link_drops
Data-link carrier losses.
Definition cellular.h:212
uint32_t cmux_frames_dropped
Received CMUX frames dropped as malformed.
Definition cellular.h:224
uint32_t deregistrations
Registered to not-registered transitions.
Definition cellular.h:210
uint32_t recoveries
Recovery transitions entered.
Definition cellular.h:218
Runtime device structure (in ROM) per driver instance.
Definition device.h:543