Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfc: Fix handling 0 size data in nfc_platform #13506

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we add a range for config NFC_LIB_CTX_MAX_SIZE?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

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
Loading