Zephyr API Documentation 4.3.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
hl78xx_apis.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Netfeasa Ltd.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#ifndef ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_
7#define ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_
8
9#include <zephyr/types.h>
10#include <zephyr/device.h>
11#include <errno.h>
12#include <stddef.h>
13#include <zephyr/modem/chat.h>
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20/* Magic constants */
21#define CSQ_RSSI_UNKNOWN (99)
22#define CESQ_RSRP_UNKNOWN (255)
23#define CESQ_RSRQ_UNKNOWN (255)
24/* Magic numbers to units conversions */
25#define CSQ_RSSI_TO_DB(v) (-113 + (2 * (v)))
26#define CESQ_RSRP_TO_DB(v) (-140 + (v))
27#define CESQ_RSRQ_TO_DB(v) (-20 + ((v) / 2))
29#define PAUSED 1
31#define ACTIVE 0
32#define MDM_MANUFACTURER_LENGTH 20
33#define MDM_MODEL_LENGTH 32
34#define MDM_REVISION_LENGTH 64
35#define MDM_IMEI_LENGTH 16
36#define MDM_IMSI_LENGTH 23
37#define MDM_ICCID_LENGTH 22
38#define MDM_APN_MAX_LENGTH 64
39#define MDM_MAX_CERT_LENGTH 4096
40#define MDM_MAX_HOSTNAME_LEN 128
41#define MDM_SERIAL_NUMBER_LENGTH 32
42
51#define HL78XX_EVT_MONITOR(name, _handler, ...) \
52 static STRUCT_SECTION_ITERABLE(hl78xx_evt_monitor_entry, name) = { \
53 .handler = _handler, \
54 .next = NULL, \
55 .flags.direct = false, \
56 COND_CODE_1(__VA_ARGS__, (.flags.paused = __VA_ARGS__,), ()) }
57
62#ifdef CONFIG_MODEM_HL78XX_12
63 HL78XX_RAT_GSM,
64#ifdef CONFIG_MODEM_HL78XX_12_FW_R6
65 HL78XX_RAT_NBNTN,
66#endif
67#endif
68#ifdef CONFIG_MODEM_HL78XX_AUTORAT
69 HL78XX_RAT_MODE_AUTO,
70#endif
73};
74
81
98
101 /* <APN> Access Point Name */
103 /* <Current RAT> */
105 /* <Network Operator> */
107 /* <Serial Number> */
109 /* Current Baud Rate */
111};
112
125
133#ifdef CONFIG_MODEM_HL78XX_AIRVANTAGE
137enum wdsi_indication {
139 WDSI_BOOTSTRAP_CREDENTIALS_PRESENT = 0,
141 WDSI_USER_AGREEMENT_REQUEST = 1,
143 WDSI_FIRMWARE_DOWNLOAD_REQUEST = 2,
145 WDSI_FIRMWARE_INSTALL_REQUEST = 3,
147 WDSI_AUTHENTICATION_START = 4,
149 WDSI_AUTHENTICATION_FAILED = 5,
151 WDSI_AUTHENTICATION_SUCCESS = 6,
153 WDSI_CONNECTION_DENIED = 7,
155 WDSI_DM_SESSION_CLOSED = 8,
157 WDSI_FIRMWARE_AVAILABLE = 9,
159 WDSI_FIRMWARE_DOWNLOADED = 10,
161 WDSI_FIRMWARE_DOWNLOAD_ISSUE = 11,
163 WDSI_PACKAGE_VERIFIED_CERTIFIED = 12,
165 WDSI_PACKAGE_VERIFIED_NOT_CERTIFIED = 13,
167 WDSI_FIRMWARE_UPDATE_START = 14,
169 WDSI_FIRMWARE_UPDATE_FAILED = 15,
171 WDSI_FIRMWARE_UPDATE_SUCCESS = 16,
173 WDSI_DOWNLOAD_IN_PROGRESS = 18,
176 WDSI_SESSION_STARTED = 23
177};
178#endif /* CONFIG_MODEM_HL78XX_AIRVANTAGE */
179
182
183 union {
186#ifdef CONFIG_MODEM_HL78XX_AIRVANTAGE
187 enum wdsi_indication wdsi_indication;
188#endif /* CONFIG_MODEM_HL78XX_AIRVANTAGE */
189 bool status;
190 int value;
192};
193
194typedef int (*hl78xx_api_configure_networks)(const struct device *dev,
195 const struct hl78xx_network *networks, uint8_t size);
196
198typedef int (*hl78xx_api_get_supported_networks)(const struct device *dev,
199 const struct hl78xx_network **networks,
200 uint8_t *size);
201
203typedef int (*hl78xx_api_get_signal)(const struct device *dev, const enum cellular_signal_type type,
204 int16_t *value);
205
207typedef int (*hl78xx_api_get_modem_info)(const struct device *dev,
208 const enum cellular_modem_info_type type, char *info,
209 size_t size);
210
212typedef int (*hl78xx_api_get_registration_status)(const struct device *dev,
214 enum cellular_registration_status *status);
215
217typedef int (*hl78xx_api_set_apn)(const struct device *dev, const char *apn, uint16_t size);
218
220typedef int (*hl78xx_api_set_phone_functionality)(const struct device *dev,
221 enum hl78xx_phone_functionality functionality,
222 bool reset);
223
225typedef int (*hl78xx_api_get_phone_functionality)(const struct device *dev,
226 enum hl78xx_phone_functionality *functionality);
227
229typedef int (*hl78xx_api_send_at_cmd)(const struct device *dev, const char *cmd, uint16_t cmd_size,
230 const struct modem_chat_match *response_matches,
231 uint16_t matches_size);
232
234struct hl78xx_evt_monitor_entry; /* forward declaration */
235/* Event monitor dispatcher */
236typedef void (*hl78xx_evt_monitor_dispatcher_t)(struct hl78xx_evt *notif);
237/* Event monitor handler */
238typedef void (*hl78xx_evt_monitor_handler_t)(struct hl78xx_evt *notif,
239 struct hl78xx_evt_monitor_entry *mon);
240
244 /* link for runtime list */
246 struct {
247 uint8_t paused: 1; /* Monitor is paused. */
248 uint8_t direct: 1; /* Dispatch in ISR. */
250};
251
259 enum hl78xx_phone_functionality functionality,
260 bool reset);
268 enum hl78xx_phone_functionality *functionality);
276int hl78xx_api_func_get_signal(const struct device *dev, const enum cellular_signal_type type,
277 int16_t *value);
287 enum hl78xx_modem_info_type type, void *info,
288 size_t size);
298int hl78xx_api_func_modem_dynamic_cmd_send(const struct device *dev, const char *cmd,
299 uint16_t cmd_size,
300 const struct modem_chat_match *response_matches,
301 uint16_t matches_size);
315static inline int hl78xx_get_modem_info(const struct device *dev,
316 const enum hl78xx_modem_info_type type, void *info,
317 size_t size)
318{
319 return hl78xx_api_func_get_modem_info_vendor(dev, type, info, size);
320}
321
336static inline int hl78xx_set_phone_functionality(const struct device *dev,
337 enum hl78xx_phone_functionality functionality,
338 bool reset)
339{
340 return hl78xx_api_func_set_phone_functionality(dev, functionality, reset);
341}
342
356static inline int hl78xx_get_phone_functionality(const struct device *dev,
357 enum hl78xx_phone_functionality *functionality)
358{
359 return hl78xx_api_func_get_phone_functionality(dev, functionality);
360}
361
379static inline int hl78xx_modem_cmd_send(const struct device *dev, const char *cmd,
380 uint16_t cmd_size,
381 const struct modem_chat_match *response_matches,
382 uint16_t matches_size)
383{
384
385 return hl78xx_api_func_modem_dynamic_cmd_send(dev, cmd, cmd_size, response_matches,
386 matches_size);
387}
388
400static inline int hl78xx_parse_rssi(uint8_t rssi, int16_t *value)
401{
402 /* AT+CSQ returns a response +CSQ: <rssi>,<ber> where:
403 * - rssi is a integer from 0 to 31 whose values describes a signal strength
404 * between -113 dBm for 0 and -51dbM for 31 or unknown for 99
405 * - ber is an integer from 0 to 7 that describes the error rate, it can also
406 * be 99 for an unknown error rate
407 */
408 if (rssi == CSQ_RSSI_UNKNOWN) {
409 return -EINVAL;
410 }
411
412 *value = (int16_t)CSQ_RSSI_TO_DB(rssi);
413 return 0;
414}
415
428static inline int hl78xx_parse_rsrp(uint8_t rsrp, int16_t *value)
429{
430 /* AT+CESQ returns a response
431 * +CESQ: <rxlev>,<ber>,<rscp>,<ecn0>,<rsrq>,<rsrp> where:
432 * rsrq is a integer from 0 to 34 whose values describes the Reference
433 * Signal Receive Quality between -20 dB for 0 and -3 dB for 34
434 * (0.5 dB steps), or unknown for 255
435 * rsrp is an integer from 0 to 97 that describes the Reference Signal
436 * Receive Power between -140 dBm for 0 and -44 dBm for 97 (1 dBm steps),
437 * or unknown for 255
438 */
439 if (rsrp == CESQ_RSRP_UNKNOWN) {
440 return -EINVAL;
441 }
442
443 *value = (int16_t)CESQ_RSRP_TO_DB(rsrp);
444 return 0;
445}
446
459static inline int hl78xx_parse_rsrq(uint8_t rsrq, int16_t *value)
460{
461 if (rsrq == CESQ_RSRQ_UNKNOWN) {
462 return -EINVAL;
463 }
464
465 *value = (int16_t)CESQ_RSRQ_TO_DB(rsrq);
466 return 0;
467}
468
476{
477 mon->flags.paused = true;
478}
479
487{
488 mon->flags.paused = false;
489}
490
516#ifdef CONFIG_MODEM_HL78XX_AIRVANTAGE
518int hl78xx_start_airvantage_dm_session(const struct device *dev);
520int hl78xx_stop_airvantage_dm_session(const struct device *dev);
521#endif /* CONFIG_MODEM_HL78XX_AIRVANTAGE */
522#ifdef __cplusplus
523}
524#endif
525
526#endif /* ZEPHYR_INCLUDE_DRIVERS_HL78XX_APIS_H_ */
Main header file for cellular modem driver API.
System error numbers.
cellular_access_technology
Cellular access technologies (3GPP TS 27.007 AcT).
Definition cellular.h:33
cellular_registration_status
Cellular registration status (3GPP TS 27.007).
Definition cellular.h:109
cellular_signal_type
Cellular signal type.
Definition cellular.h:86
cellular_modem_info_type
Cellular modem info type.
Definition cellular.h:93
static void cmd(uint32_t command)
Execute a display list command by co-processor engine.
Definition ft8xx_reference_api.h:153
#define EINVAL
Invalid argument.
Definition errno.h:60
int(* hl78xx_api_configure_networks)(const struct device *dev, const struct hl78xx_network *networks, uint8_t size)
API for configuring networks.
Definition hl78xx_apis.h:194
#define CESQ_RSRP_UNKNOWN
Definition hl78xx_apis.h:22
static int hl78xx_parse_rsrq(uint8_t rsrq, int16_t *value)
Convert raw RSRQ value from the modem to dB.
Definition hl78xx_apis.h:459
hl78xx_cell_rat_mode
Cellular radio access technologies.
Definition hl78xx_apis.h:59
@ HL78XX_RAT_MODE_NONE
Definition hl78xx_apis.h:71
@ HL78XX_RAT_COUNT
Definition hl78xx_apis.h:72
@ HL78XX_RAT_NB1
Definition hl78xx_apis.h:61
@ HL78XX_RAT_CAT_M1
Definition hl78xx_apis.h:60
#define CESQ_RSRP_TO_DB(v)
Definition hl78xx_apis.h:26
hl78xx_phone_functionality
Phone functionality modes.
Definition hl78xx_apis.h:76
@ HL78XX_SIM_POWER_OFF
Definition hl78xx_apis.h:77
@ HL78XX_AIRPLANE
Definition hl78xx_apis.h:79
@ HL78XX_FULLY_FUNCTIONAL
Definition hl78xx_apis.h:78
#define CESQ_RSRQ_TO_DB(v)
Definition hl78xx_apis.h:27
int(* hl78xx_api_get_registration_status)(const struct device *dev, enum cellular_access_technology tech, enum cellular_registration_status *status)
API for getting registration status.
Definition hl78xx_apis.h:212
int hl78xx_evt_monitor_register(struct hl78xx_evt_monitor_entry *mon)
Register an event monitor to receive HL78xx modem event notifications.
int(* hl78xx_api_get_supported_networks)(const struct device *dev, const struct hl78xx_network **networks, uint8_t *size)
API for getting supported networks.
Definition hl78xx_apis.h:198
#define CSQ_RSSI_TO_DB(v)
Definition hl78xx_apis.h:25
int(* hl78xx_api_get_signal)(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
API for getting network signal strength.
Definition hl78xx_apis.h:203
int(* hl78xx_api_set_phone_functionality)(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
API for set phone functionality.
Definition hl78xx_apis.h:220
int(* hl78xx_api_send_at_cmd)(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
API for get phone functionality.
Definition hl78xx_apis.h:229
int hl78xx_evt_notif_handler_set(hl78xx_evt_monitor_dispatcher_t handler)
Set the event notification handler for HL78xx modem events.
hl78xx_evt_type
Definition hl78xx_apis.h:126
@ HL78XX_LTE_REGISTRATION_STAT_UPDATE
Definition hl78xx_apis.h:128
@ HL78XX_LTE_RAT_UPDATE
Definition hl78xx_apis.h:127
@ HL78XX_LTE_FOTA_UPDATE_STATUS
Definition hl78xx_apis.h:131
@ HL78XX_LTE_MODEM_STARTUP
Definition hl78xx_apis.h:130
@ HL78XX_LTE_SIM_REGISTRATION
Definition hl78xx_apis.h:129
static int hl78xx_parse_rsrp(uint8_t rsrp, int16_t *value)
Convert raw RSRP value from the modem to dBm.
Definition hl78xx_apis.h:428
#define CSQ_RSSI_UNKNOWN
Definition hl78xx_apis.h:21
#define CESQ_RSRQ_UNKNOWN
Definition hl78xx_apis.h:23
static int hl78xx_parse_rssi(uint8_t rssi, int16_t *value)
Convert raw RSSI value from the modem to dBm.
Definition hl78xx_apis.h:400
void(* hl78xx_evt_monitor_handler_t)(struct hl78xx_evt *notif, struct hl78xx_evt_monitor_entry *mon)
Definition hl78xx_apis.h:238
int(* hl78xx_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 hl78xx_apis.h:207
int hl78xx_api_func_set_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
hl78xx_api_func_set_phone_functionality
int(* hl78xx_api_set_apn)(const struct device *dev, const char *apn, uint16_t size)
API for setting apn.
Definition hl78xx_apis.h:217
hl78xx_modem_info_type
Cellular modem info type.
Definition hl78xx_apis.h:100
@ HL78XX_MODEM_INFO_CURRENT_BAUD_RATE
Definition hl78xx_apis.h:110
@ HL78XX_MODEM_INFO_SERIAL_NUMBER
Definition hl78xx_apis.h:108
@ HL78XX_MODEM_INFO_APN
Definition hl78xx_apis.h:102
@ HL78XX_MODEM_INFO_CURRENT_RAT
Definition hl78xx_apis.h:104
@ HL78XX_MODEM_INFO_NETWORK_OPERATOR
Definition hl78xx_apis.h:106
static void hl78xx_evt_monitor_resume(struct hl78xx_evt_monitor_entry *mon)
Resume monitor.
Definition hl78xx_apis.h:486
int(* hl78xx_api_get_phone_functionality)(const struct device *dev, enum hl78xx_phone_functionality *functionality)
API for get phone functionality.
Definition hl78xx_apis.h:225
hl78xx_module_status
Module status codes.
Definition hl78xx_apis.h:82
@ HL78XX_MODULE_SIM_NOT_PRESENT
SIM card is not present.
Definition hl78xx_apis.h:88
@ HL78XX_MODULE_READY
Module is ready to receive commands for the TE.
Definition hl78xx_apis.h:84
@ HL78XX_MODULE_UNRECOVERABLE_ERROR
Unrecoverable error.
Definition hl78xx_apis.h:92
@ HL78XX_MODULE_INACTIVE_SIM
Inactive SIM.
Definition hl78xx_apis.h:96
@ HL78XX_MODULE_WAITING_FOR_ACCESS_CODE
Module is waiting for an access code.
Definition hl78xx_apis.h:86
@ HL78XX_MODULE_UNKNOWN_STATE
Unknown state.
Definition hl78xx_apis.h:94
@ HL78XX_MODULE_SIMLOCK
Module is in “SIMlock” state.
Definition hl78xx_apis.h:90
static int hl78xx_get_modem_info(const struct device *dev, const enum hl78xx_modem_info_type type, void *info, size_t size)
Get modem info for the device.
Definition hl78xx_apis.h:315
int hl78xx_api_func_get_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality *functionality)
hl78xx_api_func_get_phone_functionality
int hl78xx_api_func_get_modem_info_vendor(const struct device *dev, enum hl78xx_modem_info_type type, void *info, size_t size)
hl78xx_api_func_get_modem_info_vendor - Brief description of the function.
void(* hl78xx_evt_monitor_dispatcher_t)(struct hl78xx_evt *notif)
Definition hl78xx_apis.h:236
static void hl78xx_evt_monitor_pause(struct hl78xx_evt_monitor_entry *mon)
Pause monitor.
Definition hl78xx_apis.h:475
int hl78xx_api_func_modem_dynamic_cmd_send(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
hl78xx_api_func_modem_dynamic_cmd_send - Brief description of the function.
int hl78xx_api_func_get_signal(const struct device *dev, const enum cellular_signal_type type, int16_t *value)
hl78xx_api_func_get_signal - Brief description of the function.
static int hl78xx_modem_cmd_send(const struct device *dev, const char *cmd, uint16_t cmd_size, const struct modem_chat_match *response_matches, uint16_t matches_size)
Send an AT command to the modem and wait for a matched response.
Definition hl78xx_apis.h:379
static int hl78xx_set_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality functionality, bool reset)
Set the modem phone functionality mode.
Definition hl78xx_apis.h:336
int hl78xx_evt_monitor_unregister(struct hl78xx_evt_monitor_entry *mon)
Unregister an event monitor from receiving HL78xx modem event notifications.
static int hl78xx_get_phone_functionality(const struct device *dev, enum hl78xx_phone_functionality *functionality)
Get the current phone functionality mode of the modem.
Definition hl78xx_apis.h:356
enum cellular_access_technology hl78xx_rat_to_access_tech(enum hl78xx_cell_rat_mode rat_mode)
Convert HL78xx RAT mode to standard cellular API.
flags
Definition parser.h:97
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
__INT16_TYPE__ int16_t
Definition stdint.h:73
Runtime device structure (in ROM) per driver instance.
Definition device.h:513
Definition hl78xx_apis.h:241
uint8_t direct
Definition hl78xx_apis.h:248
uint8_t paused
Definition hl78xx_apis.h:247
struct hl78xx_evt_monitor_entry * next
Definition hl78xx_apis.h:245
struct hl78xx_evt_monitor_entry::@123314375256277045305202074155231060013037303316 flags
const hl78xx_evt_monitor_handler_t handler
Monitor callback.
Definition hl78xx_apis.h:243
Definition hl78xx_apis.h:180
enum hl78xx_evt_type type
Definition hl78xx_apis.h:181
bool status
Definition hl78xx_apis.h:189
union hl78xx_evt::@245116247166211205273371261316135324040054344202 content
int value
Definition hl78xx_apis.h:190
enum hl78xx_cell_rat_mode rat_mode
Definition hl78xx_apis.h:185
enum cellular_registration_status reg_status
Definition hl78xx_apis.h:184
Cellular network structure.
Definition hl78xx_apis.h:114
enum hl78xx_cell_rat_mode technology
Cellular access technology.
Definition hl78xx_apis.h:116
uint16_t * bands
List of bands, as defined by the specified cellular access technology, to enables.
Definition hl78xx_apis.h:121
uint16_t size
Size of bands.
Definition hl78xx_apis.h:123
Modem chat match.
Definition chat.h:47