Skip to content

Commit 6b2a476

Browse files
sophiekovalevskycarlescufi
authored andcommitted
lorawan: add callback for descriptor changes
allow the application to decide whether to keep going with the fuota process by setting a callback that exposes the descriptor field whenever `FragSessionSetupReq` is sent to the device. Signed-off-by: Kiara Navarro <[email protected]>
1 parent ac3355a commit 6b2a476

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

include/zephyr/lorawan/lorawan.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ typedef uint8_t (*lorawan_battery_level_cb_t)(void);
217217
*/
218218
typedef void (*lorawan_dr_changed_cb_t)(enum lorawan_datarate dr);
219219

220+
/**
221+
* @brief Defines the user's descriptor callback handler function signature.
222+
*
223+
* The use of this callback is optional. When Fragmented Data Block Transport
224+
* is enabled, the application will be notified with the descriptor field present on
225+
* the FragSessionSetupReq command.
226+
*
227+
* @param descriptor Descriptor value given on the FragSessionSetupReq command.
228+
*
229+
* The meaning of Descriptor is application dependent. When doing a FUOTA
230+
* with a binary image, it may represent the version of the firmware
231+
* transported.
232+
*
233+
* @return 0 if successful. This represents, in the case that the descriptor is the firmware
234+
* version, that the end-device is able to receive binary firmware. Otherwise, a negative error code
235+
* (errno.h) indicating the reason for failure. Any negative error code will result in setting
236+
* the Wrong Descriptor status bit mask when sending FragSessionSetupAns to the Network Server.
237+
*
238+
*/
239+
typedef int (*transport_descriptor_cb)(uint32_t descriptor);
240+
220241
/**
221242
* @brief Register a battery level callback function.
222243
*
@@ -439,6 +460,17 @@ int lorawan_clock_sync_get(uint32_t *gps_time);
439460

440461
#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT
441462

463+
/**
464+
* @brief Register a handle descriptor callback function.
465+
*
466+
* Provide to the fragmentation transport service a function to be called
467+
* whenever a FragSessionSetupReq is received and Descriptor field should be
468+
* handled.
469+
*
470+
* @param transport_descriptor_cb Callback for notification.
471+
*/
472+
void lorawan_frag_transport_register_descriptor_callback(transport_descriptor_cb cb);
473+
442474
/**
443475
* @brief Run Fragmented Data Block Transport service
444476
*

subsys/lorawan/services/frag_transport.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ static struct frag_transport_context ctx;
101101
/* Callback for notification of finished firmware transfer */
102102
static void (*finished_cb)(void);
103103

104+
/* Callback to handle descriptor field */
105+
static transport_descriptor_cb descriptor_cb;
106+
104107
static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr,
105108
uint8_t len, const uint8_t *rx_buf)
106109
{
@@ -207,7 +210,14 @@ static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t
207210
}
208211
#endif
209212

210-
/* Descriptor not used: Ignore Wrong Descriptor error */
213+
if (descriptor_cb != NULL) {
214+
int rc = descriptor_cb(ctx.descriptor);
215+
216+
if (rc < 0) {
217+
/* Wrong Descriptor */
218+
status |= BIT(3);
219+
}
220+
}
211221

212222
if ((status & 0x1F) == 0) {
213223
#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT_DECODER_SEMTECH
@@ -314,6 +324,11 @@ static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t
314324
}
315325
}
316326

327+
void lorawan_frag_transport_register_descriptor_callback(transport_descriptor_cb cb)
328+
{
329+
descriptor_cb = cb;
330+
}
331+
317332
static struct lorawan_downlink_cb downlink_cb = {
318333
.port = (uint8_t)LORAWAN_PORT_FRAG_TRANSPORT,
319334
.cb = frag_transport_package_callback,

0 commit comments

Comments
 (0)