Browse Source

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 <sophiekovalevsky@fedoraproject.org>
pull/82776/merge
Kiara Navarro 9 months ago committed by Carles Cufí
parent
commit
6b2a476c66
  1. 32
      include/zephyr/lorawan/lorawan.h
  2. 17
      subsys/lorawan/services/frag_transport.c

32
include/zephyr/lorawan/lorawan.h

@ -217,6 +217,27 @@ typedef uint8_t (*lorawan_battery_level_cb_t)(void); @@ -217,6 +217,27 @@ typedef uint8_t (*lorawan_battery_level_cb_t)(void);
*/
typedef void (*lorawan_dr_changed_cb_t)(enum lorawan_datarate dr);
/**
* @brief Defines the user's descriptor callback handler function signature.
*
* The use of this callback is optional. When Fragmented Data Block Transport
* is enabled, the application will be notified with the descriptor field present on
* the FragSessionSetupReq command.
*
* @param descriptor Descriptor value given on the FragSessionSetupReq command.
*
* The meaning of Descriptor is application dependent. When doing a FUOTA
* with a binary image, it may represent the version of the firmware
* transported.
*
* @return 0 if successful. This represents, in the case that the descriptor is the firmware
* version, that the end-device is able to receive binary firmware. Otherwise, a negative error code
* (errno.h) indicating the reason for failure. Any negative error code will result in setting
* the Wrong Descriptor status bit mask when sending FragSessionSetupAns to the Network Server.
*
*/
typedef int (*transport_descriptor_cb)(uint32_t descriptor);
/**
* @brief Register a battery level callback function.
*
@ -439,6 +460,17 @@ int lorawan_clock_sync_get(uint32_t *gps_time); @@ -439,6 +460,17 @@ int lorawan_clock_sync_get(uint32_t *gps_time);
#ifdef CONFIG_LORAWAN_FRAG_TRANSPORT
/**
* @brief Register a handle descriptor callback function.
*
* Provide to the fragmentation transport service a function to be called
* whenever a FragSessionSetupReq is received and Descriptor field should be
* handled.
*
* @param transport_descriptor_cb Callback for notification.
*/
void lorawan_frag_transport_register_descriptor_callback(transport_descriptor_cb cb);
/**
* @brief Run Fragmented Data Block Transport service
*

17
subsys/lorawan/services/frag_transport.c

@ -101,6 +101,9 @@ static struct frag_transport_context ctx; @@ -101,6 +101,9 @@ static struct frag_transport_context ctx;
/* Callback for notification of finished firmware transfer */
static void (*finished_cb)(void);
/* Callback to handle descriptor field */
static transport_descriptor_cb descriptor_cb;
static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t rssi, int8_t snr,
uint8_t len, const uint8_t *rx_buf)
{
@ -207,7 +210,14 @@ static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t @@ -207,7 +210,14 @@ static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t
}
#endif
/* Descriptor not used: Ignore Wrong Descriptor error */
if (descriptor_cb != NULL) {
int rc = descriptor_cb(ctx.descriptor);
if (rc < 0) {
/* Wrong Descriptor */
status |= BIT(3);
}
}
if ((status & 0x1F) == 0) {
#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 @@ -314,6 +324,11 @@ static void frag_transport_package_callback(uint8_t port, uint8_t flags, int16_t
}
}
void lorawan_frag_transport_register_descriptor_callback(transport_descriptor_cb cb)
{
descriptor_cb = cb;
}
static struct lorawan_downlink_cb downlink_cb = {
.port = (uint8_t)LORAWAN_PORT_FRAG_TRANSPORT,
.cb = frag_transport_package_callback,

Loading…
Cancel
Save