summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ndef.h3
-rw-r--r--src/ndef.c57
2 files changed, 60 insertions, 0 deletions
diff --git a/include/ndef.h b/include/ndef.h
index 559879d..0cbe47b 100644
--- a/include/ndef.h
+++ b/include/ndef.h
@@ -37,4 +37,7 @@ int near_ndef_parse(struct near_tag *tag, uint8_t *ndef_data, size_t ndef_length
struct near_ndef_message *near_ndef_prepare_text_record(char *encoding,
char *language_code, char *text);
+struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier,
+ uint32_t field_length, uint8_t *field);
+
#endif
diff --git a/src/ndef.c b/src/ndef.c
index 05a3dbe..5e406f5 100644
--- a/src/ndef.c
+++ b/src/ndef.c
@@ -1282,6 +1282,63 @@ fail:
return NULL;
}
+/**
+ * @brief Prepare URI ndef record
+ *
+ * Prepare uri 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] identifier URI Identifier
+ * @param[in] field_length URI field length
+ * @param[in] field URI field
+ *
+ * @return struct near_ndef_message * - Success
+ * NULL - Failure
+ */
+struct near_ndef_message *near_ndef_prepare_uri_record(uint8_t identifier,
+ uint32_t field_length, uint8_t *field)
+{
+ struct near_ndef_message *msg = NULL;
+ uint32_t payload_length;
+
+ DBG("");
+
+ /* Validate input parameters*/
+ if ((field_length == 0 && field != NULL) ||
+ (field_length != 0 && field == NULL)) {
+ return NULL;
+ }
+
+ payload_length = field_length + 1;
+
+ msg = ndef_message_alloc("U", payload_length);
+ if (msg == NULL)
+ return NULL;
+
+ msg->data[msg->offset++] = identifier;
+
+ if (field_length > 0) {
+ memcpy(msg->data + msg->offset, field, field_length);
+ msg->offset += field_length;
+ }
+
+ if (msg->offset > msg->length)
+ goto fail;
+
+ return msg;
+
+fail:
+ near_error("uri record preparation failed");
+ g_free(msg->data);
+ g_free(msg);
+
+ return NULL;
+}
+
int __near_ndef_init(void)
{
DBG("");