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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
14#define ZEPHYR_INCLUDE_DRIVERS_CELLULAR_H_
15
23#include <zephyr/types.h>
24#include <zephyr/device.h>
25#include <errno.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
42
55
62
78
87
93
94/* Opaque bit-mask large enough for all current & future events */
96
101
114typedef void (*cellular_event_cb_t)(const struct device *dev, enum cellular_event event,
115 const void *payload, void *user_data);
116
118typedef int (*cellular_api_configure_networks)(const struct device *dev,
119 const struct cellular_network *networks,
120 uint8_t size);
121
123typedef int (*cellular_api_get_supported_networks)(const struct device *dev,
124 const struct cellular_network **networks,
125 uint8_t *size);
126
128typedef int (*cellular_api_get_signal)(const struct device *dev,
129 const enum cellular_signal_type type, int16_t *value);
130
132typedef int (*cellular_api_get_modem_info)(const struct device *dev,
133 const enum cellular_modem_info_type type, char *info,
134 size_t size);
135
137typedef int (*cellular_api_get_registration_status)(const struct device *dev,
139 enum cellular_registration_status *status);
140
142typedef int (*cellular_api_set_apn)(const struct device *dev, const char *apn);
143
145typedef int (*cellular_api_set_callback)(const struct device *dev, cellular_event_mask_t mask,
146 cellular_event_cb_t cb, void *user_data);
147
158
180static inline int cellular_configure_networks(const struct device *dev,
181 const struct cellular_network *networks, uint8_t size)
182{
183 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
184
185 if (api->configure_networks == NULL) {
186 return -ENOSYS;
187 }
188
189 return api->configure_networks(dev, networks, size);
190}
191
203static inline int cellular_get_supported_networks(const struct device *dev,
204 const struct cellular_network **networks,
205 uint8_t *size)
206{
207 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
208
209 if (api->get_supported_networks == NULL) {
210 return -ENOSYS;
211 }
212
213 return api->get_supported_networks(dev, networks, size);
214}
215
228static inline int cellular_get_signal(const struct device *dev,
229 const enum cellular_signal_type type, int16_t *value)
230{
231 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
232
233 if (api->get_signal == NULL) {
234 return -ENOSYS;
235 }
236
237 return api->get_signal(dev, type, value);
238}
239
253static inline int cellular_get_modem_info(const struct device *dev,
254 const enum cellular_modem_info_type type, char *info,
255 size_t size)
256{
257 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
258
259 if (api->get_modem_info == NULL) {
260 return -ENOSYS;
261 }
262
263 return api->get_modem_info(dev, type, info, size);
264}
265
278static inline int cellular_get_registration_status(const struct device *dev,
280 enum cellular_registration_status *status)
281{
282 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
283
284 if (api->get_registration_status == NULL) {
285 return -ENOSYS;
286 }
287
288 return api->get_registration_status(dev, tech, status);
289}
290
307static inline int cellular_set_apn(const struct device *dev, const char *apn)
308{
309 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
310
311 if (api->set_apn == NULL) {
312 return -ENOSYS;
313 }
314
315 return api->set_apn(dev, apn);
316}
317
332static inline int cellular_set_callback(const struct device *dev, cellular_event_mask_t mask,
333 cellular_event_cb_t cb, void *user_data)
334{
335 const struct cellular_driver_api *api = (const struct cellular_driver_api *)dev->api;
336
337 if (api->set_callback == NULL) {
338 return -ENOSYS;
339 }
340
341 return api->set_callback(dev, mask, cb, user_data);
342}
343
344#ifdef __cplusplus
345}
346#endif
347
352#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:228
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:132
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:137
cellular_access_technology
Cellular access technologies.
Definition cellular.h:32
cellular_event
Events emitted asynchronously by a cellular driver.
Definition cellular.h:89
static int cellular_set_apn(const struct device *dev, const char *apn)
Set the APN used for PDP context.
Definition cellular.h:307
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:123
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:203
int(* cellular_api_configure_networks)(const struct device *dev, const struct cellular_network *networks, uint8_t size)
API for configuring networks.
Definition cellular.h:118
cellular_registration_status
Definition cellular.h:79
cellular_signal_type
Cellular signal type.
Definition cellular.h:57
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:253
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:128
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:332
uint32_t cellular_event_mask_t
Definition cellular.h:95
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:180
int(* cellular_api_set_apn)(const struct device *dev, const char *apn)
API for programming APN.
Definition cellular.h:142
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:114
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:145
cellular_modem_info_type
Cellular modem info type.
Definition cellular.h:64
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:278
@ CELLULAR_ACCESS_TECHNOLOGY_LTE
Definition cellular.h:37
@ CELLULAR_ACCESS_TECHNOLOGY_UMTS
Definition cellular.h:35
@ CELLULAR_ACCESS_TECHNOLOGY_NB_IOT
Definition cellular.h:40
@ CELLULAR_ACCESS_TECHNOLOGY_GPRS
Definition cellular.h:34
@ CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M2
Definition cellular.h:39
@ CELLULAR_ACCESS_TECHNOLOGY_GSM
Definition cellular.h:33
@ CELLULAR_ACCESS_TECHNOLOGY_EDGE
Definition cellular.h:36
@ CELLULAR_ACCESS_TECHNOLOGY_LTE_CAT_M1
Definition cellular.h:38
@ CELLULAR_EVENT_MODEM_INFO_CHANGED
One or more modem-info field changed (e.g.
Definition cellular.h:91
@ CELLULAR_REGISTRATION_UNKNOWN
Definition cellular.h:84
@ CELLULAR_REGISTRATION_SEARCHING
Definition cellular.h:82
@ CELLULAR_REGISTRATION_DENIED
Definition cellular.h:83
@ CELLULAR_REGISTRATION_REGISTERED_HOME
Definition cellular.h:81
@ CELLULAR_REGISTRATION_NOT_REGISTERED
Definition cellular.h:80
@ CELLULAR_REGISTRATION_REGISTERED_ROAMING
Definition cellular.h:85
@ CELLULAR_SIGNAL_RSRQ
Definition cellular.h:60
@ CELLULAR_SIGNAL_RSRP
Definition cellular.h:59
@ CELLULAR_SIGNAL_RSSI
Definition cellular.h:58
@ CELLULAR_MODEM_INFO_SIM_IMSI
International Mobile Subscriber Identity.
Definition cellular.h:74
@ CELLULAR_MODEM_INFO_MANUFACTURER
Modem manufacturer.
Definition cellular.h:70
@ CELLULAR_MODEM_INFO_MODEL_ID
Modem model ID.
Definition cellular.h:68
@ CELLULAR_MODEM_INFO_SIM_ICCID
Integrated Circuit Card Identification Number (SIM)
Definition cellular.h:76
@ CELLULAR_MODEM_INFO_FW_VERSION
Modem fw version.
Definition cellular.h:72
@ CELLULAR_MODEM_INFO_IMEI
International Mobile Equipment Identity.
Definition cellular.h:66
#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:149
cellular_api_get_supported_networks get_supported_networks
Definition cellular.h:151
cellular_api_set_apn set_apn
Definition cellular.h:155
cellular_api_set_callback set_callback
Definition cellular.h:156
cellular_api_get_registration_status get_registration_status
Definition cellular.h:154
cellular_api_get_signal get_signal
Definition cellular.h:152
cellular_api_get_modem_info get_modem_info
Definition cellular.h:153
cellular_api_configure_networks configure_networks
Definition cellular.h:150
Payload for CELLULAR_EVENT_MODEM_INFO_CHANGED.
Definition cellular.h:98
enum cellular_modem_info_type field
Which field changed.
Definition cellular.h:99
Cellular network structure.
Definition cellular.h:44
uint16_t * bands
List of bands, as defined by the specified cellular access technology, to enables.
Definition cellular.h:51
uint16_t size
Size of bands.
Definition cellular.h:53
enum cellular_access_technology technology
Cellular access technology.
Definition cellular.h:46
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