nRF Connect SDK API 0.1.0
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 (4 + (LWM2M_OS_MAX_WORK_QS * 4))
34
36typedef int lwm2m_os_timer_t;
37
41#define LWM2M_OS_MAX_SEM_COUNT (6 + (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
69 uint8_t length;
70};
71
73 bool present;
74 uint16_t dest_port;
75 uint16_t src_port;
76};
77
81};
82
85};
86
94 char *payload;
95};
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
135};
136
142 const int *sec_tag_list;
149};
150
154typedef int (*lwm2m_os_download_callback_t)(const struct lwm2m_os_download_evt *event);
155
164};
165
176 (uint8_t cid, enum lwm2m_os_pdn_event event, int reason);
177
191
201int lwm2m_os_pdn_ctx_configure(uint8_t cid, const char *apn, enum lwm2m_os_pdn_fam family);
202
211
223int lwm2m_os_pdn_activate(uint8_t cid, int *esm, enum lwm2m_os_pdn_fam *family);
224
232int lwm2m_os_pdn_deactivate(uint8_t cid);
233
243int lwm2m_os_pdn_id_get(uint8_t cid);
244
251
255void *lwm2m_os_malloc(size_t size);
256
260void lwm2m_os_free(void *ptr);
261
272int lwm2m_os_sem_init(lwm2m_os_sem_t **sem, unsigned int initial_count, unsigned int limit);
273
285int lwm2m_os_sem_take(lwm2m_os_sem_t *sem, int timeout);
286
293
300
305
309int64_t lwm2m_os_uptime_delta(int64_t *ref);
310
316int lwm2m_os_sleep(int ms);
317
322
326uint32_t lwm2m_os_rand_get(void);
327
331int lwm2m_os_storage_delete(uint16_t id);
332
336int lwm2m_os_storage_read(uint16_t id, void *data, size_t len);
337
341int lwm2m_os_storage_write(uint16_t id, const void *data, size_t len);
342
351lwm2m_os_work_q_t *lwm2m_os_work_q_start(int index, const char *name);
352
360
365
375int lwm2m_os_timer_start(lwm2m_os_timer_t *timer, int64_t delay);
376
388
396
405
414
422
430
435
441int lwm2m_os_download_get(const char *host, const struct lwm2m_os_download_cfg *cfg, size_t from);
442
449
456
465
475size_t lwm2m_os_lte_modes_get(int32_t *modes);
476
484void lwm2m_os_lte_mode_request(int32_t prefer);
485
490
495#define LWM2M_OS_DFU_IMG_TYPE_NONE 0
499#define LWM2M_OS_DFU_IMG_TYPE_APPLICATION 1
503#define LWM2M_OS_DFU_IMG_TYPE_MODEM_DELTA 2
507#define LWM2M_OS_DFU_IMG_TYPE_APPLICATION_FILE 3
510struct __attribute__((__packed__)) lwm2m_os_dfu_header {
511 /* Number of the image file in the sequence. */
512 uint8_t number;
513 /* Flag indicating if the image file is the last in the sequence. */
514 uint8_t is_last;
515 /* Offset within the whole image in bytes. */
516 uint32_t offset;
517 /* Null-terminated image version. */
518 char version[32];
519};
520
521#define LWM2M_OS_DFU_HEADER_MAGIC 0x424ad2dc
522#define LWM2M_OS_DFU_HEADER_MAGIC_LEN sizeof(uint32_t)
523#define LWM2M_OS_DFU_HEADER_LEN (LWM2M_OS_DFU_HEADER_MAGIC_LEN + sizeof(struct lwm2m_os_dfu_header))
524
536int lwm2m_os_dfu_img_type(const void *const buf, size_t len, struct lwm2m_os_dfu_header **header);
537
555int lwm2m_os_dfu_start(int img_type, size_t max_file_size, bool crc_validate);
556
571int lwm2m_os_dfu_fragment(const char *buf, size_t len, uint32_t crc32);
572
585int lwm2m_os_dfu_done(bool successful, uint32_t crc32);
586
595
602
607
614
615#ifdef __cplusplus
616}
617#endif
618
621#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(lwm2m_os_timer_t *timer, int64_t delay)
Start a timer on system work queue.
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_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.
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:176
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_ACTIVATED
Definition: lwm2m_os.h:159
@ LWM2M_OS_PDN_EVENT_IPV6_DOWN
Definition: lwm2m_os.h:162
@ LWM2M_OS_PDN_EVENT_IPV6_UP
Definition: lwm2m_os.h:161
@ 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:516
uint8_t number
Definition: lwm2m_os.h:512
uint8_t is_last
Definition: lwm2m_os.h:514
Definition: lwm2m_os.h:510
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
struct lwm2m_os_download_evt::@146::lwm2m_os_fragment fragment
const void * buf
Definition: lwm2m_os.h:123
size_t len
Definition: lwm2m_os.h:124
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