From b4bfb6014672237a818eed8af770924499d32d63 Mon Sep 17 00:00:00 2001 From: Ravikumar Veeramally Date: Thu, 8 Dec 2011 11:52:27 +0200 Subject: [PATCH] ndef: API provided to prepare smartposter ndef record API provided to prepare smartposter ndef record with mandatory uri fields, which is useful to write ndef data on tags. --- include/ndef.h | 5 +++++ src/ndef.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/include/ndef.h b/include/ndef.h index 0cbe47b..6af47c9 100644 --- a/include/ndef.h +++ b/include/ndef.h @@ -40,4 +40,9 @@ struct near_ndef_message *near_ndef_prepare_text_record(char *encoding, struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier, uint32_t field_length, uint8_t *field); +struct near_ndef_message * +near_ndef_prepare_smartposter_record(uint8_t uri_identifier, + uint32_t uri_field_length, + uint8_t *uri_field); + #endif diff --git a/src/ndef.c b/src/ndef.c index 6b04a75..160a95e 100644 --- a/src/ndef.c +++ b/src/ndef.c @@ -1436,6 +1436,70 @@ fail: return NULL; } +/** + * @brief Prepare Smartposter ndef record with mandatory URI fields. + * + * Prepare smartposter ndef record with provided input data and + * return ndef message structure (length and byte stream) in success or + * NULL in failure case. + * + * @note : caller responsibility to free the input and output + * parameters memory. + * + * @param[in] uri_identfier + * @param[in] uri_field_length + * @param[in] uri_field + * + * @return struct near_ndef_message * - Success + * NULL - Failure + */ +struct near_ndef_message * +near_ndef_prepare_smartposter_record(uint8_t uri_identifier, + uint32_t uri_field_length, + uint8_t *uri_field) +{ + struct near_ndef_message *msg = NULL, *uri = NULL; + + /* URI is mandatory in Smartposter */ + uri = near_ndef_prepare_uri_record(uri_identifier, uri_field_length, + uri_field); + if (uri == NULL) + goto fail; + + /* URI record length is equal to payload length of Sp record */ + msg = ndef_message_alloc("Sp", uri->length); + if (msg == NULL) + goto fail; + + memcpy(msg->data + msg->offset, uri->data, uri->length); + msg->offset += uri->length; + + if (msg->offset > msg->length) + goto fail; + + if (uri != NULL) { + g_free(uri->data); + g_free(uri); + } + + return msg; + +fail: + near_error("smartposter record preparation failed"); + + if (uri != NULL) { + g_free(uri->data); + g_free(uri); + } + + if (msg != NULL) { + g_free(msg->data); + g_free(msg); + } + + return NULL; +} + int __near_ndef_init(void) { DBG(""); -- 2.7.4