Skip to content

Commit

Permalink
nfc: Fix handling 0 size data in nfc_platform
Browse files Browse the repository at this point in the history
Fix handling data with 0 size when issuing a callback.

Jira: NCSDK-25211

Signed-off-by: Dominik Chat <[email protected]>
  • Loading branch information
dchat-nordic authored and nordicjm committed Jan 10, 2024
1 parent 7e315b5 commit d1bbd45
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ Libraries for networking
Libraries for NFC
-----------------

|no_changes_yet_note|
* Fixed an issue with handling zero size data (when receiving empty I-blocks from poller) in the :file:`platform_internal_thread` file.

nRF Security
------------
Expand Down
1 change: 1 addition & 0 deletions subsys/nfc/lib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ config NFC_RING_SIZE
config NFC_LIB_CTX_MAX_SIZE
int "Maximum size of NFC library context in bytes"
default 16
range 16 255
help
Maximum size of the NFC library context in bytes.
The specified size should be divisible by 4.
Expand Down
12 changes: 8 additions & 4 deletions subsys/nfc/lib/platform_internal_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ LOG_MODULE_DECLARE(nfc_platform, CONFIG_NFC_PLATFORM_LOG_LEVEL);

#define NFC_LIB_CTX_SIZE CONFIG_NFC_LIB_CTX_MAX_SIZE

#define NFC_HDR_FLAG_COPY BIT(0)

struct nfc_item_header {
uint16_t ctx_size;
uint8_t ctx_size;
uint8_t flags;
uint16_t data_size;
};

Expand Down Expand Up @@ -118,7 +121,7 @@ static void cb_work(struct k_work *work)
goto error;
}

if (header.data_size == 0) {
if (!(header.flags & NFC_HDR_FLAG_COPY)) {
size = ring_buf_get(&nfc_cb_ring, (uint8_t *)&data, sizeof(data));
if (size != sizeof(data)) {
LOG_ERR("Tried to read data pointer: %d bytes, read %d.", sizeof(data),
Expand All @@ -136,7 +139,7 @@ static void cb_work(struct k_work *work)
__ASSERT(nfc_cb_resolve != NULL, "nfc_cb_resolve is not set");
nfc_cb_resolve(ctx, data);

if (header.data_size == 0) {
if (!(header.flags & NFC_HDR_FLAG_COPY)) {
work_resubmit(work, &nfc_cb_ring);
return;
}
Expand Down Expand Up @@ -224,7 +227,8 @@ void nfc_platform_cb_request(const void *ctx,
uint32_t exp_size;

header.ctx_size = ctx_len;
header.data_size = copy_data ? data_len : 0;
header.flags = copy_data ? NFC_HDR_FLAG_COPY : 0;
header.data_size = data_len;

size = ring_buf_put(&nfc_cb_ring, (uint8_t *)&header, sizeof(header));
if (size != sizeof(header)) {
Expand Down

0 comments on commit d1bbd45

Please sign in to comment.