Skip to content

Commit

Permalink
nfc: TNEP Tag Services in the ROM section
Browse files Browse the repository at this point in the history
TNEP Tag Services are now keeped in ROM section
instead of passing them to the TNEP API.

NCSDK-4934

Signed-off-by: Kamil Gawor <[email protected]>
  • Loading branch information
KAGA164 authored and anangl committed Aug 25, 2020
1 parent a0cd096 commit cbf5d22
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
28 changes: 18 additions & 10 deletions include/nfc/tnep/tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ struct nfc_tnep_tag_service {
_message_cb, \
_error_cb) \
\
BUILD_ASSERT(_t_wait <= NFC_TNEP_TAG_MAX_WAIT_TIME, \
BUILD_ASSERT(_t_wait <= NFC_TNEP_TAG_MAX_WAIT_TIME, \
"The Waiting time has to be equal or smaller than 63"); \
BUILD_ASSERT(_n_wait <= NFC_TNEP_TAG_MAX_WAIT_TIME, \
BUILD_ASSERT(_n_wait <= NFC_TNEP_TAG_MAX_WAIT_TIME, \
"The Waiting time extension count has to be equal or smaller then 15"); \
\
NFC_TNEP_SERIVCE_PARAM_RECORD_DESC_DEF(_name, NFC_TNEP_VERSION, \
Expand All @@ -138,7 +138,10 @@ struct nfc_tnep_tag_service {
.deselected = _deselect_cb, \
.message_received = _message_cb, \
.error_detected = _error_cb, \
}
}; \
\
const Z_STRUCT_SECTION_ITERABLE(nfc_tnep_tag_service, _name##_svc) = \
NFC_TNEP_TAG_SERVICE(_name)

/**
* @brief macro for accessing the TNEP Service.
Expand Down Expand Up @@ -203,12 +206,11 @@ int nfc_tnep_tag_init(struct k_poll_event *events, uint8_t event_cnt,
* @brief Create the Initial TNEP NDEF Message.
*
* This function creates the Initial TNEP message. Initial NDEF message
* has to contain at least one service parameters record. It can
* contain also optional NDEF Records which can be used by NFC Poller
* Device which does not support TNEP Protocol.
* has to contain at least one service parameters record defined
* using @ref NFC_TNEP_TAG_SERVICE_DEF. It can contain also optional NDEF
* Records which can be used by NFC Poller Device which does not support
* TNEP Protocol.
*
* @param[in] svc Pointer to the first service information structure.
* @param[in] svc_cnt Number of provided services for application.
* @param[in] max_record_cnt Maximum count of the optional NDEF Records
* @param[in] msg_encode_cb Callback function for encoding the
* Initial TNEP NDEF message. Can be set to NULL
Expand All @@ -219,8 +221,7 @@ int nfc_tnep_tag_init(struct k_poll_event *events, uint8_t event_cnt,
* @retval 0 If the operation was successful.
* Otherwise, a (negative) error code is returned.
*/
int nfc_tnep_tag_initial_msg_create(const struct nfc_tnep_tag_service *svc,
size_t svc_cnt, size_t max_record_cnt,
int nfc_tnep_tag_initial_msg_create(size_t max_record_cnt,
initial_msg_encode_t msg_encode_cb);

/**
Expand Down Expand Up @@ -315,6 +316,13 @@ int nfc_tnep_tag_tx_msg_no_app_data(void);
*/
void nfc_tnep_tag_on_selected(void);

/**
* @brief Get the NFC Tag TNEP service count.
*
* @return TNEP Tag Service count.
*/
size_t nfc_tnep_tag_svc_count_get(void);

/**
* @}
*/
Expand Down
9 changes: 1 addition & 8 deletions samples/nfc/tnep_tag/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ NFC_TNEP_TAG_SERVICE_DEF(svc_two, svc_two_uri, (ARRAY_SIZE(svc_two_uri) - 1),
tnep_svc_two_selected, tnep_svc_two_deselected,
tnep_svc_two_msg_received, tnep_svc_error);

static struct nfc_tnep_tag_service training_services[] = {
NFC_TNEP_TAG_SERVICE(svc_one),
NFC_TNEP_TAG_SERVICE(svc_two),
};

static void nfc_callback(void *context, enum nfc_t4t_event event,
const uint8_t *data, size_t data_length, uint32_t flags)
{
Expand Down Expand Up @@ -223,9 +218,7 @@ void main(void)
return;
}

err = nfc_tnep_tag_initial_msg_create(training_services,
ARRAY_SIZE(training_services),
TNEP_INITIAL_MSG_RECORD_COUNT,
err = nfc_tnep_tag_initial_msg_create(TNEP_INITIAL_MSG_RECORD_COUNT,
tnep_initial_msg_encode);
if (err) {
printk("Cannot create initial TNEP message, err: %d\n", err);
Expand Down
5 changes: 5 additions & 0 deletions subsys/nfc/tnep/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@
zephyr_library()
zephyr_library_sources_ifdef(CONFIG_NFC_TNEP_TAG tag.c)
zephyr_library_sources_ifdef(CONFIG_NFC_TNEP_POLLER poller.c)

zephyr_linker_sources_ifdef(CONFIG_NFC_TNEP_TAG
SECTIONS
tag.ld
)
44 changes: 26 additions & 18 deletions subsys/nfc/tnep/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ struct tnep_tag {
struct tnep_buffer tx;
struct tnep_rx_buffer rx;
const struct nfc_tnep_tag_service *svc_active;
const struct nfc_tnep_tag_service *svc;
size_t svc_cnt;
size_t max_records_cnt;
atomic_t app_data_expected;
Expand Down Expand Up @@ -199,9 +198,9 @@ static int tnep_tx_initial_msg_set(void)
return tnep.initial_msg_encode(&NFC_NDEF_MSG(initial_msg));
}

for (size_t i = 0; i < tnep.svc_cnt; i++) {
Z_STRUCT_SECTION_FOREACH(nfc_tnep_tag_service, tnep_svc) {
err = tnep_tx_msg_add_rec(&NFC_NDEF_MSG(initial_msg),
tnep.svc[i].ndef_record);
tnep_svc->ndef_record);
if (err) {
return err;
}
Expand All @@ -227,12 +226,11 @@ static bool ndef_check_rec_type(const struct nfc_ndef_record_desc *record,

static int tnep_svc_set_active(const uint8_t *uri_name, size_t uri_length)
{

for (size_t i = 0; i < tnep.svc_cnt; i++) {
if ((tnep.svc[i].parameters->uri_length == uri_length) &&
Z_STRUCT_SECTION_FOREACH(nfc_tnep_tag_service, tnep_svc) {
if ((tnep_svc->parameters->uri_length == uri_length) &&
!memcmp(uri_name,
tnep.svc[i].parameters->uri, uri_length)) {
tnep.svc_active = &tnep.svc[i];
tnep_svc->parameters->uri, uri_length)) {
tnep.svc_active = tnep_svc;

return TNEP_SVC_SELECTED;
}
Expand Down Expand Up @@ -509,6 +507,11 @@ void nfc_tnep_tag_rx_msg_indicate(const uint8_t *rx_buffer, size_t len)
int nfc_tnep_tag_init(struct k_poll_event *events, uint8_t event_cnt,
nfc_payload_set_t payload_set)
{
extern struct nfc_tnep_tag_service
_nfc_tnep_tag_service_list_start[];
extern struct nfc_tnep_tag_service
_nfc_tnep_tag_service_list_end[];

LOG_DBG("TNEP initialization");

if (!events) {
Expand Down Expand Up @@ -541,6 +544,8 @@ int nfc_tnep_tag_init(struct k_poll_event *events, uint8_t event_cnt,
tnep_ctrl.events = events;
tnep.current_buff = tnep.tx.data;
tnep.data_set = payload_set;
tnep.svc_cnt = _nfc_tnep_tag_service_list_end -
_nfc_tnep_tag_service_list_start;

LOG_DBG("k_pool signals initialization");

Expand All @@ -558,23 +563,21 @@ int nfc_tnep_tag_init(struct k_poll_event *events, uint8_t event_cnt,
return 0;
}

int nfc_tnep_tag_initial_msg_create(const struct nfc_tnep_tag_service *svc,
size_t svc_cnt, size_t max_record_cnt,
int nfc_tnep_tag_initial_msg_create(size_t max_record_cnt,
initial_msg_encode_t msg_encode_cb)
{
int err;

if (!svc || !svc_cnt) {
return -EINVAL;
}

if (max_record_cnt && !msg_encode_cb) {
LOG_ERR("No callback provides when maximum NDEF Record count id greater than 0");
return -EINVAL;
}

tnep.svc = svc;
tnep.svc_cnt = svc_cnt;
if (tnep.svc_cnt < 1) {
LOG_ERR("TNEP Tag services are not defined");
return -EFAULT;
}

tnep.max_records_cnt = max_record_cnt;
tnep.initial_msg_encode = msg_encode_cb;

Expand Down Expand Up @@ -619,9 +622,9 @@ int nfc_tnep_initial_msg_encode(struct nfc_ndef_msg_desc *msg,
}
}

for (size_t i = 0; i < tnep.svc_cnt; i++) {
Z_STRUCT_SECTION_FOREACH(nfc_tnep_tag_service, tnep_svc) {
err = tnep_tx_msg_add_rec(msg,
tnep.svc[i].ndef_record);
tnep_svc->ndef_record);
if (err) {
return err;
}
Expand Down Expand Up @@ -706,3 +709,8 @@ void nfc_tnep_tag_on_selected(void)
{
k_poll_signal_raise(&tnep_ctrl.msg_tx, TNEP_EVENT_TAG_SELECTED);
}

size_t nfc_tnep_tag_svc_count_get(void)
{
return tnep.svc_cnt;
}
1 change: 1 addition & 0 deletions subsys/nfc/tnep/tag.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Z_ITERABLE_SECTION_ROM(nfc_tnep_tag_service, 4)

0 comments on commit cbf5d22

Please sign in to comment.