Zephyr Project API 4.2.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
14#ifndef ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
15#define ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
16
24#include <zephyr/types.h>
25#include <zephyr/device.h>
26#include <errno.h>
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
43
56
63
79
88
94
95/* Opaque bit-mask large enough for all current & future events */
97
102
115typedef void (*cellular_event_cb_t)(const struct device *dev, enum cellular_event event,
116 const void *payload, void *user_data);
117
119typedef int (*cellular_api_configure_networks)(const struct device *dev,
120 const struct cellular_network *networks,
121 uint8_t size);
122
124typedef int (*cellular_api_get_supported_networks)(const struct device *dev,
125 const struct cellular_network **networks,
126 uint8_t *size);
127
129typedef int (*cellular_api_get_signal)(const struct device *dev,
130 const enum cellular_signal_type type, int16_t *value);
131
133typedef int (*cellular_api_get_modem_info)(const struct device *dev,
134 const enum cellular_modem_info_type type, char *info,
135 size_t size);
136
138typedef int (*cellular_api_get_registration_status)(const struct device *dev,
140 enum cellular_registration_status *status);
141
143typedef int (*cellular_api_set_apn)(const struct device *dev, const char *apn);
144
146typedef int (*cellular_api_set_callback)(const struct device *dev, cellular_event_mask_t mask,
147 cellular_event_cb_t cb, void *user_data);
148
159
181static inline int cellular_configure_networks(const struct device *dev,
182 const struct cellular_network *networks, uint8_t size)
183{
184 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
185
186 if (api->configure_networks == NULL) {
187 return -ENOSYS;
188 }
189
190 return api->configure_networks(dev, networks, size);
191}
192
204static inline int cellular_get_supported_networks(const struct device *dev,
205 const struct cellular_network **networks,
206 uint8_t *size)
207{
208 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
209
210 if (api->get_supported_networks == NULL) {
211 return -ENOSYS;
212 }
213
214 return api->get_supported_networks(dev, networks, size);
215}
216
229static inline int cellular_get_signal(const struct device *dev,
230 const enum cellular_signal_type type, int16_t *value)
231{
232 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
233
234 if (api->get_signal == NULL) {
235 return -ENOSYS;
236 }
237
238 return api->get_signal(dev, type, value);
239}
240
254static inline int cellular_get_modem_info(const struct device *dev,
255 const enum cellular_modem_info_type type, char *info,
256 size_t size)
257{
258 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
259
260 if (api->get_modem_info == NULL) {
261 return -ENOSYS;
262 }
263
264 return api->get_modem_info(dev, type, info, size);
265}
266
279static inline int cellular_get_registration_status(const struct device *dev,
281 enum cellular_registration_status *status)
282{
283 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
284
285 if (api->get_registration_status == NULL) {
286 return -ENOSYS;
287 }
288
289 return api->get_registration_status(dev, tech, status);
290}
291
308static inline int cellular_set_apn(const struct device *dev, const char *apn)
309{
310 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
311
312 if (api->set_apn == NULL) {
313 return -ENOSYS;
314 }
315
316 return api->set_apn(dev, apn);
317}
318
333static inline int cellular_set_callback(const struct device *dev, cellular_event_mask_t mask,
334 cellular_event_cb_t cb, void *user_data)
335{
336 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
337
338 if (api->set_callback == NULL) {
339 return -ENOSYS;
340 }
341
342 return api->set_callback(dev, mask, cb, user_data);
343}
344
345#ifdef __cplusplus
346}
347#endif
348
353#endif /* ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_ */
System error numbers.
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:229
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:133
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:138
cellular_access_technology
Cellular access technologies.
Definition cellular.h:33
cellular_event
Events emitted asynchronously by a cellular driver.
Definition cellular.h:90
static int cellular_set_apn(const struct device *dev, const char *apn)
Set the APN used for PDP context.
Definition cellular.h:308
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:124
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:204
int(* cellular_api_configure_networks)(const struct device *dev, const struct cellular_network *networks, uint8_t size)
API for configuring networks.
Definition cellular.h:119
cellular_registration_status
Definition cellular.h:80
cellular_signal_type
Cellular signal type.
Definition cellular.h:58
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:254
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:129
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:333
uint32_t cellular_event_mask_t
Definition cellular.h:96
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:181
int(* cellular_api_set_apn)(const struct device *dev, const char *apn)
API for programming APN.
Definition cellular.h:143
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:115
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:146
cellular_modem_info_type
Cellular modem info type.
Definition cellular.h:65
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:279
@ CELLULAR_ACCESS_TECHNOLOGY_LTE
Definition cellular.h:38
@ CELLULAR_ACCESS_TECHNOLOGY_UMTS
Definition cellular.h:36
@ CELLULAR_ACCESS_TECHNOLOGY_NB_IOT
Definition cellular.h:41
@ CELLULAR_ACCESS_TECHNOLOGY_GPRS
Definition cellular.h:35
@ CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M2
Definition cellular.h:40
@ CELLULAR_ACCESS_TECHNOLOGY_GSM
Definition cellular.h:34
@ CELLULAR_ACCESS_TECHNOLOGY_EDGE
Definition cellular.h:37
@ CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M1
Definition cellular.h:39
@ CELLULAR_EVENT_MODEM_INFO_CHANGED
One or more modem-info field changed (e.g.
Definition cellular.h:92
@ CELLULAR_REGISTRATION_UNKNOWN
Definition cellular.h:85
@ CELLULAR_REGISTRATION_SEARCHING
Definition cellular.h:83
@ CELLULAR_REGISTRATION_DENIED
Definition cellular.h:84
@ CELLULAR_REGISTRATION_REGISTERED_HOME
Definition cellular.h:82
@ CELLULAR_REGISTRATION_NOT_REGISTERED
Definition cellular.h:81
@ CELLULAR_REGISTRATION_REGISTERED_ROAMING
Definition cellular.h:86
@ CELLULAR_SIGNAL_RSRQ
Definition cellular.h:61
@ CELLULAR_SIGNAL_RSRP
Definition cellular.h:60
@ CELLULAR_SIGNAL_RSSI
Definition cellular.h:59
@ CELLULAR_MODEM_INFO_SIM_IMSI
International Mobile Subscriber Identity.
Definition cellular.h:75
@ CELLULAR_MODEM_INFO_MANUFACTURER
Modem manufacturer.
Definition cellular.h:71
@ CELLULAR_MODEM_INFO_MODEL_ID
Modem model ID.
Definition cellular.h:69
@ CELLULAR_MODEM_INFO_SIM_ICCID
Integrated Circuit Card Identification Number (SIM)
Definition cellular.h:77
@ CELLULAR_MODEM_INFO_FW_VERSION
Modem fw version.
Definition cellular.h:73
@ CELLULAR_MODEM_INFO_IMEI
International Mobile Equipment Identity.
Definition cellular.h:67
#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:82
#define NULL
Definition iar_missing_defs.h:20
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Cellular driver API.
Definition cellular.h:150
cellular_api_get_supported_networks get_supported_networks
Definition cellular.h:152
cellular_api_set_apn set_apn
Definition cellular.h:156
cellular_api_set_callback set_callback
Definition cellular.h:157
cellular_api_get_registration_status get_registration_status
Definition cellular.h:155
cellular_api_get_signal get_signal
Definition cellular.h:153
cellular_api_get_modem_info get_modem_info
Definition cellular.h:154
cellular_api_configure_networks configure_networks
Definition cellular.h:151
Payload for CELLULAR_EVENT_MODEM_INFO_CHANGED.
Definition cellular.h:99
enum cellular_modem_info_type field
Which field changed.
Definition cellular.h:100
Cellular network structure.
Definition cellular.h:45
uint16_t * bands
List of bands, as defined by the specified cellular access technology, to enables.
Definition cellular.h:52
uint16_t size
Size of bands.
Definition cellular.h:54
enum cellular_access_technology technology
Cellular access technology.
Definition cellular.h:47
Runtime device structure (in ROM) per driver instance.
Definition device.h:510
const void * api
Address of the API structure exposed by the device instance.
Definition device.h:516