nRF Connect SDK API 2.8.99
Loading...
Searching...
No Matches
lwm2m_os.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019-2022 Nordic Semiconductor ASA
3 *
4 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5 */
6
7#ifndef LWM2M_OS_H__
8#define LWM2M_OS_H__
9
17#include <stddef.h>
18#include <stdint.h>
19#include <stdbool.h>
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
28#define LWM2M_OS_MAX_WORK_QS 2
29
33#define LWM2M_OS_MAX_TIMER_COUNT (6 + (LWM2M_OS_MAX_WORK_QS * 4))
34
36typedef int lwm2m_os_timer_t;
37
41#define LWM2M_OS_MAX_SEM_COUNT (8 + (LWM2M_OS_MAX_WORK_QS * 1))
42
43typedef int lwm2m_os_sem_t;
44
45#define LWM2M_OS_LTE_MODE_NONE -1
46/* LTE Rel-13 Cat-M1 HD-FDD == E-UTRAN == LTE-M */
47#define LWM2M_OS_LTE_MODE_CAT_M1 6
48/* LTE Rel-13 Cat-NB1 HD-FDD || LTE Rel-14 Cat-NB1 and Cat-NB2 HD-FDD == E-UTRAN NB-S1 == NB-IoT */
49#define LWM2M_OS_LTE_MODE_CAT_NB1 7
50
54#define LWM2M_OS_STORAGE_BASE 0xCA00
55#define LWM2M_OS_STORAGE_END 0xCAFF
56
60typedef void (*lwm2m_os_at_handler_callback_t)(const char *notif);
61
66
71
73 bool present;
74 uint16_t dest_port;
75 uint16_t src_port;
76};
77
82
86
96
100typedef void (*lwm2m_os_sms_callback_t)(struct lwm2m_os_sms_data *const data, void *context);
101
106#define LWM2M_OS_DOWNLOAD_EVT_FRAGMENT 0
107#define LWM2M_OS_DOWNLOAD_EVT_ERROR 1
108#define LWM2M_OS_DOWNLOAD_EVT_DONE 2
109#define LWM2M_OS_DOWNLOAD_EVT_CLOSED 3
117 int id;
118 union {
120 int error;
122 struct lwm2m_os_fragment {
123 const void *buf;
124 size_t len;
126 };
127};
128
136
150
154typedef int (*lwm2m_os_download_callback_t)(const struct lwm2m_os_download_evt *event);
155
168
179 (uint8_t cid, enum lwm2m_os_pdn_event event, int reason);
180
194
204int lwm2m_os_pdn_ctx_configure(uint8_t cid, const char *apn, enum lwm2m_os_pdn_fam family);
205
214
226int lwm2m_os_pdn_activate(uint8_t cid, int *esm, enum lwm2m_os_pdn_fam *family);
227
235int lwm2m_os_pdn_deactivate(uint8_t cid);
236
246int lwm2m_os_pdn_id_get(uint8_t cid);
247
254
258void *lwm2m_os_malloc(size_t size);
259
263void lwm2m_os_free(void *ptr);
264
275int lwm2m_os_sem_init(lwm2m_os_sem_t **sem, unsigned int initial_count, unsigned int limit);
276
288int lwm2m_os_sem_take(lwm2m_os_sem_t *sem, int timeout);
289
296
303
308
312int64_t lwm2m_os_uptime_delta(int64_t *ref);
313
319int lwm2m_os_sleep(int ms);
320
325
329uint32_t lwm2m_os_rand_get(void);
330
334int lwm2m_os_storage_delete(uint16_t id);
335
339int lwm2m_os_storage_read(uint16_t id, void *data, size_t len);
340
344int lwm2m_os_storage_write(uint16_t id, const void *data, size_t len);
345
354lwm2m_os_work_q_t *lwm2m_os_work_q_start(int index, const char *name);
355
363
368
380
388
397
406
414
422
427
433int lwm2m_os_download_get(const char *host, const struct lwm2m_os_download_cfg *cfg, size_t from);
434
441
448
457
465
474int lwm2m_os_uicc_bootstrap_read(uint8_t *p_buffer, int buffer_size);
475
485size_t lwm2m_os_lte_modes_get(int32_t *modes);
486
494void lwm2m_os_lte_mode_request(int32_t prefer);
495
500
505#define LWM2M_OS_DFU_IMG_TYPE_NONE 0
509#define LWM2M_OS_DFU_IMG_TYPE_APPLICATION 1
513#define LWM2M_OS_DFU_IMG_TYPE_MODEM_DELTA 2
517#define LWM2M_OS_DFU_IMG_TYPE_APPLICATION_FILE 3
520struct __attribute__((__packed__)) lwm2m_os_dfu_header {
521 /* Number of the image file in the sequence. */
522 uint8_t number;
523 /* Flag indicating if the image file is the last in the sequence. */
524 uint8_t is_last;
525 /* Offset within the whole image in bytes. */
526 uint32_t offset;
527 /* Null-terminated image version. */
528 char version[32];
529};
530
531#define LWM2M_OS_DFU_HEADER_MAGIC 0x424ad2dc
532#define LWM2M_OS_DFU_HEADER_MAGIC_LEN sizeof(uint32_t)
533#define LWM2M_OS_DFU_HEADER_LEN (LWM2M_OS_DFU_HEADER_MAGIC_LEN + sizeof(struct lwm2m_os_dfu_header))
534
546int lwm2m_os_dfu_img_type(const void *const buf, size_t len, struct lwm2m_os_dfu_header **header);
547
565int lwm2m_os_dfu_start(int img_type, size_t max_file_size, bool crc_validate);
566
581int lwm2m_os_dfu_fragment(const char *buf, size_t len, uint32_t crc32);
582
595int lwm2m_os_dfu_done(bool successful, uint32_t crc32);
596
605
612
617
624
625#ifdef __cplusplus
626}
627#endif
628
631#endif /* LWM2M_OS_H__ */
static const struct event_proxy_config cfg
Definition event_proxy_def.h:28
int lwm2m_os_work_q_t
Definition lwm2m_os.h:35
int lwm2m_os_download_file_size_get(size_t *size)
Retrieve size of file being downloaded.
int lwm2m_os_download_disconnect(void)
Disconnect from the server.
int lwm2m_os_at_init(lwm2m_os_at_handler_callback_t callback)
Initialize AT command driver.
int lwm2m_os_timer_start_on_q(lwm2m_os_work_q_t *work_q, lwm2m_os_timer_t *timer, int64_t delay)
Start a timer on a specific queue.
int lwm2m_os_sem_init(lwm2m_os_sem_t **sem, unsigned int initial_count, unsigned int limit)
Initialize a semaphore.
int lwm2m_os_storage_delete(uint16_t id)
Delete a non-volatile storage entry.
void(* lwm2m_os_at_handler_callback_t)(const char *notif)
AT command error handler callback function.
Definition lwm2m_os.h:60
void(* lwm2m_os_timer_handler_t)(lwm2m_os_timer_t *timer)
Timer callback function.
Definition lwm2m_os.h:65
int lwm2m_os_sem_t
Definition lwm2m_os.h:43
bool lwm2m_os_timer_is_pending(lwm2m_os_timer_t *timer)
Check if a timer task is pending.
void lwm2m_os_sms_client_deregister(int handle)
degister as an SMS client/listener.
void lwm2m_os_lte_mode_request(int32_t prefer)
set preferred bearer in modem.
int lwm2m_os_dfu_done(bool successful, uint32_t crc32)
Finalize the current firmware upgrade and CRC-validate the image if required.
int(* lwm2m_os_download_callback_t)(const struct lwm2m_os_download_evt *event)
Download client asynchronous event handler.
Definition lwm2m_os.h:154
int lwm2m_os_storage_read(uint16_t id, void *data, size_t len)
Read an entry from non-volatile storage.
int64_t lwm2m_os_uptime_get(void)
Get uptime, in milliseconds.
bool lwm2m_os_dfu_application_update_validate(void)
Validate the application image update.
int lwm2m_os_pdn_ctx_configure(uint8_t cid, const char *apn, enum lwm2m_os_pdn_fam family)
Configure a Packet Data Protocol context.
int lwm2m_os_pdn_default_callback_set(lwm2m_os_pdn_event_handler_t cb)
Set a callback for events pertaining to the default PDP context (zero).
int lwm2m_os_uicc_bootstrap_read(uint8_t *p_buffer, int buffer_size)
Read UICC LwM2M bootstrap record.
int lwm2m_os_dfu_img_type(const void *const buf, size_t len, struct lwm2m_os_dfu_header **header)
Find the image type for the buffer of bytes received.
int lwm2m_os_pdn_ctx_create(uint8_t *cid, lwm2m_os_pdn_event_handler_t cb)
Create a Packet Data Protocol (PDP) context.
void lwm2m_os_free(void *ptr)
Free memory.
int lwm2m_os_nrf_errno(void)
Translate the error number.
void lwm2m_os_timer_get(lwm2m_os_timer_handler_t handler, lwm2m_os_timer_t **timer)
Reserve a timer task from the OS.
int lwm2m_os_sms_client_register(lwm2m_os_sms_callback_t lib_callback, void *context)
Register as an SMS client/listener.
bool lwm2m_os_uicc_bootstrap_is_enabled(void)
Check if UICC LwM2M bootstrap is enabled.
int64_t lwm2m_os_timer_remaining(lwm2m_os_timer_t *timer)
Obtain the time remaining on a timer.
void(* lwm2m_os_pdn_event_handler_t)(uint8_t cid, enum lwm2m_os_pdn_event event, int reason)
PDN event handler.
Definition lwm2m_os.h:179
uint32_t lwm2m_os_rand_get(void)
Get a random value.
int lwm2m_os_sleep(int ms)
Put a thread to a sleep.
lwm2m_os_pdn_event
PDN event.
Definition lwm2m_os.h:157
@ LWM2M_OS_PDN_EVENT_CTX_DESTROYED
Definition lwm2m_os.h:166
@ LWM2M_OS_PDN_EVENT_ACTIVATED
Definition lwm2m_os.h:159
@ LWM2M_OS_PDN_EVENT_IPV6_DOWN
Definition lwm2m_os.h:162
@ LWM2M_OS_PDN_EVENT_APN_RATE_CONTROL_ON
Definition lwm2m_os.h:164
@ LWM2M_OS_PDN_EVENT_IPV6_UP
Definition lwm2m_os.h:161
@ LWM2M_OS_PDN_EVENT_APN_RATE_CONTROL_OFF
Definition lwm2m_os.h:165
@ LWM2M_OS_PDN_EVENT_NETWORK_DETACHED
Definition lwm2m_os.h:163
@ LWM2M_OS_PDN_EVENT_DEACTIVATED
Definition lwm2m_os.h:160
@ LWM2M_OS_PDN_EVENT_CNEC_ESM
Definition lwm2m_os.h:158
int lwm2m_os_dfu_start(int img_type, size_t max_file_size, bool crc_validate)
Start a firmware upgrade.
void lwm2m_os_sem_give(lwm2m_os_sem_t *sem)
Give a semaphore.
void * lwm2m_os_malloc(size_t size)
Allocate memory.
int lwm2m_os_storage_write(uint16_t id, const void *data, size_t len)
Write an entry to non-volatile storage.
int lwm2m_os_timer_t
Definition lwm2m_os.h:36
void lwm2m_os_dfu_reset(void)
Reset the current DFU target.
int lwm2m_os_pdn_deactivate(uint8_t cid)
Deactivate a Packet Data Network (PDN) connection.
int lwm2m_os_pdn_ctx_destroy(uint8_t cid)
Destroy a Packet Data Protocol context.
lwm2m_os_work_q_t * lwm2m_os_work_q_start(int index, const char *name)
Start a workqueue.
lwm2m_os_pdn_fam
PDN family.
Definition lwm2m_os.h:130
@ LWM2M_OS_PDN_FAM_IPV4
Definition lwm2m_os.h:131
@ LWM2M_OS_PDN_FAM_NONIP
Definition lwm2m_os.h:134
@ LWM2M_OS_PDN_FAM_IPV4V6
Definition lwm2m_os.h:133
@ LWM2M_OS_PDN_FAM_IPV6
Definition lwm2m_os.h:132
void lwm2m_os_timer_cancel(lwm2m_os_timer_t *timer, bool sync)
Cancel a timer run.
int lwm2m_os_sem_take(lwm2m_os_sem_t *sem, int timeout)
Take a semaphore.
int64_t lwm2m_os_uptime_delta(int64_t *ref)
Get uptime delta, in milliseconds.
void lwm2m_os_sys_reset(void)
Reboot system.
int lwm2m_os_dfu_pause(void)
Pause the DFU process and release the resources temporarily.
int lwm2m_os_dfu_schedule_update(void)
Schedule update for uploaded image.
void lwm2m_os_timer_release(lwm2m_os_timer_t *timer)
Release a timer task.
int lwm2m_os_pdn_id_get(uint8_t cid)
Retrieve the PDN ID for a given PDP Context.
void lwm2m_os_sem_reset(lwm2m_os_sem_t *sem)
Reset a semaphore.
void(* lwm2m_os_sms_callback_t)(struct lwm2m_os_sms_data *const data, void *context)
SMS subscriber callback function.
Definition lwm2m_os.h:100
int lwm2m_os_pdn_activate(uint8_t cid, int *esm, enum lwm2m_os_pdn_fam *family)
Activate a Packet Data Network (PDN) connection.
int lwm2m_os_dfu_fragment(const char *buf, size_t len, uint32_t crc32)
Receive a firmware image fragment and validate its CRC if required.
int lwm2m_os_download_get(const char *host, const struct lwm2m_os_download_cfg *cfg, size_t from)
Establish a connection with the server and download a file.
int lwm2m_os_download_init(lwm2m_os_download_callback_t lib_callback)
Initialize the download client.
size_t lwm2m_os_lte_modes_get(int32_t *modes)
get enabled system modes from modem.
uint32_t offset
Definition lwm2m_os.h:526
uint8_t number
Definition lwm2m_os.h:522
uint8_t is_last
Definition lwm2m_os.h:524
Definition lwm2m_os.h:520
uint8_t sec_tag_count
Definition lwm2m_os.h:144
enum lwm2m_os_pdn_fam family
Definition lwm2m_os.h:148
int pdn_id
Definition lwm2m_os.h:146
const int * sec_tag_list
Definition lwm2m_os.h:142
Download client configuration options.
Definition lwm2m_os.h:140
int id
Definition lwm2m_os.h:117
int error
Definition lwm2m_os.h:120
const void * buf
Definition lwm2m_os.h:123
size_t len
Definition lwm2m_os.h:124
struct lwm2m_os_download_evt::@149::lwm2m_os_fragment fragment
Download client event.
Definition lwm2m_os.h:115
union lwm2m_os_sms_header header
Definition lwm2m_os.h:90
int payload_len
Definition lwm2m_os.h:92
char * payload
Definition lwm2m_os.h:94
SMS PDU data.
Definition lwm2m_os.h:88
char * address_str
Definition lwm2m_os.h:68
uint8_t length
Definition lwm2m_os.h:69
Definition lwm2m_os.h:67
struct lwm2m_os_sms_deliver_address originating_address
Definition lwm2m_os.h:79
struct lwm2m_os_sms_udh_app_port app_port
Definition lwm2m_os.h:80
Definition lwm2m_os.h:78
bool present
Definition lwm2m_os.h:73
uint16_t src_port
Definition lwm2m_os.h:75
uint16_t dest_port
Definition lwm2m_os.h:74
Definition lwm2m_os.h:72
struct lwm2m_os_sms_deliver_header deliver
Definition lwm2m_os.h:84
Definition lwm2m_os.h:83