From 126714286cca7bd039a8a5d67536d95c50dabb97 Mon Sep 17 00:00:00 2001 From: fanoush Date: Fri, 25 Aug 2023 22:34:41 +0200 Subject: [PATCH 1/4] allow NDEF records with length over 254 bytes - use 3 byte length in NDEF TLV block when over 254 bytes - store 16bit url payload length -add maximum lenght checking (type 2 tag data is up to 992 bytes) --- libs/bluetooth/bluetooth.h | 44 +++++++++++++-------- libs/bluetooth/jswrap_bluetooth.c | 63 +++++++++++++++++++++++-------- 2 files changed, 76 insertions(+), 31 deletions(-) diff --git a/libs/bluetooth/bluetooth.h b/libs/bluetooth/bluetooth.h index 3bb531787b..cc54c8dc96 100644 --- a/libs/bluetooth/bluetooth.h +++ b/libs/bluetooth/bluetooth.h @@ -316,27 +316,39 @@ void jsble_setup_advdata(ble_advdata_t *advdata); #define TAG_HEADER_LEN 0x0A -#define NDEF_HEADER "\x00\x00\x00\x00" /* | UID/BCC | TT = Tag Type */ \ - "\x00\x00\x00\x00" /* | UID/BCC | ML = NDEF Message Length */ \ - "\x00\x00\xFF\xFF" /* | UID/BCC | LOCK | TF = TNF and Flags */ \ - "\xE1\x11\x7C\x0F" /* | Cap. Container | TL = Type Legnth */ \ - "\x03\x00\xC1\x01" /* | TT | ML | TF | TL | RT = Record Type */ \ - "\x00\x00\x00\x00" /* | Payload Length | IC = URI Identifier Code */ \ - "\x55\x00" /* | RT | IC | Payload | 0x00: No prepending */ - -#define NDEF_FULL_RAW_HEADER_LEN 0x12 /* full header until ML */ -#define NDEF_FULL_URL_HEADER_LEN 0x1A /* full header until IC */ - -#define NDEF_RECORD_HEADER_LEN 0x08 /* record header (TF, TL, PL, RT, IC ) */ -#define NDEF_IC_OFFSET 0x19 +/* +TT = Tag Type +ML = NDEF Message Length +RT = Record Type +TF = TNF and Flags +TL = Type Legnth +IC = URI Identifier Code +*/ + +#define NDEF_HEADER "\x00\x00\x00\x00" /* | UID/BCC | */ \ + "\x00\x00\x00\x00" /* | UID/BCC | */ \ + "\x00\x00\xFF\xFF" /* | UID/BCC | LOCK | */ \ + "\xE1\x11\x7C\x0F" /* | Cap. Container | */ \ + "\x03\x00\x00\x00" /* | TT | ML (1 or 3 bytes)| */ + +#define NDEF_HEADER_LEN_SHORT 0x12 /* with 1 byte length */ +#define NDEF_HEADER_LEN_LONG 0x14 /* with 3 byte length */ +#define NDEF_HEADER_MSG_LEN_OFFSET 0x11 + +#define NDEF_URL_RECORD_HEADER \ + "\xC1\x01" /* | TF | TL | */ \ + "\x00\x00\x00\x00" /* | Payload Length | */ \ + "\x55\x00" /* | RT | IC | 0x00: No prepending */ + +#define NDEF_URL_RECORD_HEADER_LEN 0x08 /* record header (TF, TL, PL, RT, IC ) */ #define NDEF_IC_LEN 0x01 -#define NDEF_MSG_LEN_OFFSET 0x11 -#define NDEF_PL_LEN_LSB_OFFSET 0x17 /* we support pl < 256 */ +#define NDEF_MSG_IC_OFFSET 7 +#define NDEF_MSG_PL_LEN_MSB_OFFSET 4 #define NDEF_TERM_TLV 0xfe /* last TLV block / byte */ #define NDEF_TERM_TLV_LEN 0x01 - +#define NDEF_TAG2_VALUE_MAXLEN (992 - 4 - NDEF_TERM_TLV_LEN) /* max type 2 tag value size */ void jsble_nfc_stop(); void jsble_nfc_start(const uint8_t *data, size_t len); void jsble_nfc_get_internal(uint8_t *data, size_t *max_len); diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 70a5ab9d77..85292cee4b 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -2437,10 +2437,17 @@ void jswrap_nfc_URL(JsVar *url) { uriType = NFC_URI_HTTPS; } + uint16_t msgLen = NDEF_URL_RECORD_HEADER_LEN + urlLen; + if (msgLen>NDEF_TAG2_VALUE_MAXLEN) + return jsExceptionHere(JSET_ERROR, "URL too long"); + /* Encode NDEF message into a flat string - we need this to store the * data so it hangs around. Avoid having a static var so we have RAM * available if not using NFC. NFC data is read by nfc_callback */ - JsVar *flatStr = jsvNewFlatStringOfLength(NDEF_FULL_URL_HEADER_LEN + urlLen + NDEF_TERM_TLV_LEN); + + bool isLongMsg = msgLen > 254; + size_t nfcDataLen = msgLen + NDEF_TERM_TLV_LEN + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + JsVar *flatStr = jsvNewFlatStringOfLength(nfcDataLen); if (!flatStr) return jsExceptionHere(JSET_ERROR, "Unable to create string with URI data in"); jsvObjectSetChild(execInfo.hiddenRoot, "NfcData", flatStr); @@ -2448,16 +2455,29 @@ void jswrap_nfc_URL(JsVar *url) { jsvUnLock(flatStr); /* assemble NDEF Message */ - memcpy(flatStrPtr, NDEF_HEADER, NDEF_FULL_URL_HEADER_LEN); /* fill header */ - flatStrPtr[NDEF_IC_OFFSET] = uriType; /* set URI Identifier Code */ - memcpy(flatStrPtr+NDEF_FULL_URL_HEADER_LEN, urlPtr, urlLen); /* add payload */ + memcpy(flatStrPtr, NDEF_HEADER, NDEF_HEADER_LEN_LONG); /* fill header */ + /* inject tag2 message length into header */ + if (isLongMsg){ + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = 255; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+1] = msgLen >> 8; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+2] = msgLen & 255; + } else { + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = msgLen; + } + + /* add NDEF message record header after NDEF header */ + uint8_t *ndefMsgPtr = flatStrPtr + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + memcpy(ndefMsgPtr, NDEF_URL_RECORD_HEADER, NDEF_URL_RECORD_HEADER_LEN); /* fill header */ + + ndefMsgPtr[NDEF_MSG_IC_OFFSET] = uriType; /* set URI Identifier Code */ + memcpy(ndefMsgPtr+NDEF_URL_RECORD_HEADER_LEN, urlPtr, urlLen); /* add payload */ - /* inject length fields into header */ - flatStrPtr[NDEF_MSG_LEN_OFFSET] = NDEF_RECORD_HEADER_LEN + urlLen; - flatStrPtr[NDEF_PL_LEN_LSB_OFFSET] = NDEF_IC_LEN + urlLen; + /* put 16 bit (big endian) payload length into record header */ + ndefMsgPtr[NDEF_MSG_PL_LEN_MSB_OFFSET] = (NDEF_IC_LEN + urlLen)>>8; + ndefMsgPtr[NDEF_MSG_PL_LEN_MSB_OFFSET+1] = (NDEF_IC_LEN + urlLen)&255; /* write terminator TLV block */ - flatStrPtr[NDEF_FULL_URL_HEADER_LEN + urlLen] = NDEF_TERM_TLV; + flatStrPtr[nfcDataLen - NDEF_TERM_TLV_LEN] = NDEF_TERM_TLV; /* start nfc peripheral */ JsVar* uid = jswrap_nfc_start(NULL); @@ -2617,13 +2637,17 @@ void jswrap_nfc_raw(JsVar *payload) { } JSV_GET_AS_CHAR_ARRAY(dataPtr, dataLen, payload); - if (!dataPtr || !dataLen) + if (!dataPtr || !dataLen || dataLen>NDEF_TAG2_VALUE_MAXLEN) return jsExceptionHere(JSET_ERROR, "Unable to get NFC data"); /* Create a flat string - we need this to store the NFC data so it hangs around. * Avoid having a static var so we have RAM available if not using NFC. * NFC data is read by nfc_callback in bluetooth.c */ - JsVar *flatStr = jsvNewFlatStringOfLength(NDEF_FULL_RAW_HEADER_LEN + dataLen + NDEF_TERM_TLV_LEN); + bool isLongMsg = dataLen > 254; + size_t nfcDataLen = dataLen + NDEF_TERM_TLV_LEN + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + + + JsVar *flatStr = jsvNewFlatStringOfLength(nfcDataLen); if (!flatStr) return jsExceptionHere(JSET_ERROR, "Unable to create string with NFC data in"); jsvObjectSetChild(execInfo.hiddenRoot, "NfcData", flatStr); @@ -2631,14 +2655,23 @@ void jswrap_nfc_raw(JsVar *payload) { jsvUnLock(flatStr); /* assemble NDEF Message */ - memcpy(flatStrPtr, NDEF_HEADER, NDEF_FULL_RAW_HEADER_LEN); /* fill header */ - memcpy(flatStrPtr+NDEF_FULL_RAW_HEADER_LEN, dataPtr, dataLen); /* add payload */ + memcpy(flatStrPtr, NDEF_HEADER, NDEF_HEADER_LEN_LONG); /* fill header */ + /* inject tag2 message length into header */ + if (isLongMsg){ + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = 255; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+1] = dataLen >> 8; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+2] = dataLen & 255; + } else { + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = dataLen; + } + + /* add NDEF message record header after NDEF header */ + uint8_t *ndefMsgPtr = flatStrPtr + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + memcpy(ndefMsgPtr, dataPtr, dataLen); /* add payload */ - /* inject length fields into header */ - flatStrPtr[NDEF_MSG_LEN_OFFSET] = dataLen; /* write terminator TLV block */ - flatStrPtr[NDEF_FULL_RAW_HEADER_LEN + dataLen] = NDEF_TERM_TLV; + flatStrPtr[nfcDataLen - NDEF_TERM_TLV_LEN] = NDEF_TERM_TLV; /* start nfc peripheral */ JsVar* uid = jswrap_nfc_start(NULL); From f4398ce28cb017798e7dc38c433d02b9baae2fdb Mon Sep 17 00:00:00 2001 From: fanoush Date: Tue, 29 Aug 2023 00:13:21 +0200 Subject: [PATCH 2/4] remove duplicated code from NRF.nfcXXXX methods - move common code from jswrap_nfc_raw into nfc_raw_data_start and reuse it in all NRF.nfc methods - also avoid creating one extra flat string copy of the payload --- libs/bluetooth/bluetooth.h | 2 +- libs/bluetooth/jswrap_bluetooth.c | 72 +++++-------------------------- 2 files changed, 12 insertions(+), 62 deletions(-) diff --git a/libs/bluetooth/bluetooth.h b/libs/bluetooth/bluetooth.h index cc54c8dc96..2042481dcf 100644 --- a/libs/bluetooth/bluetooth.h +++ b/libs/bluetooth/bluetooth.h @@ -348,7 +348,7 @@ IC = URI Identifier Code #define NDEF_TERM_TLV 0xfe /* last TLV block / byte */ #define NDEF_TERM_TLV_LEN 0x01 -#define NDEF_TAG2_VALUE_MAXLEN (992 - 4 - NDEF_TERM_TLV_LEN) /* max type 2 tag value size */ +#define NDEF_TAG2_VALUE_MAXLEN (992 - 4 - NDEF_TERM_TLV_LEN) /* max NDEF data size for 0x7C size in cap. container (*8=992)*/ void jsble_nfc_stop(); void jsble_nfc_start(const uint8_t *data, size_t len); void jsble_nfc_get_internal(uint8_t *data, size_t *max_len); diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 85292cee4b..2a7d057530 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -2391,7 +2391,7 @@ void jswrap_ble_setLowPowerConnection(bool lowPower) { } } - +static void nfc_raw_data_start(uint8_t *dataPtr,size_t dataLen); /*JSON{ "type" : "staticmethod", "class" : "NRF", @@ -2441,32 +2441,7 @@ void jswrap_nfc_URL(JsVar *url) { if (msgLen>NDEF_TAG2_VALUE_MAXLEN) return jsExceptionHere(JSET_ERROR, "URL too long"); - /* Encode NDEF message into a flat string - we need this to store the - * data so it hangs around. Avoid having a static var so we have RAM - * available if not using NFC. NFC data is read by nfc_callback */ - - bool isLongMsg = msgLen > 254; - size_t nfcDataLen = msgLen + NDEF_TERM_TLV_LEN + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); - JsVar *flatStr = jsvNewFlatStringOfLength(nfcDataLen); - if (!flatStr) - return jsExceptionHere(JSET_ERROR, "Unable to create string with URI data in"); - jsvObjectSetChild(execInfo.hiddenRoot, "NfcData", flatStr); - uint8_t *flatStrPtr = (uint8_t*)jsvGetFlatStringPointer(flatStr); - jsvUnLock(flatStr); - - /* assemble NDEF Message */ - memcpy(flatStrPtr, NDEF_HEADER, NDEF_HEADER_LEN_LONG); /* fill header */ - /* inject tag2 message length into header */ - if (isLongMsg){ - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = 255; - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+1] = msgLen >> 8; - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+2] = msgLen & 255; - } else { - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = msgLen; - } - - /* add NDEF message record header after NDEF header */ - uint8_t *ndefMsgPtr = flatStrPtr + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + uint8_t *ndefMsgPtr = alloca(urlLen+NDEF_URL_RECORD_HEADER_LEN); memcpy(ndefMsgPtr, NDEF_URL_RECORD_HEADER, NDEF_URL_RECORD_HEADER_LEN); /* fill header */ ndefMsgPtr[NDEF_MSG_IC_OFFSET] = uriType; /* set URI Identifier Code */ @@ -2476,17 +2451,7 @@ void jswrap_nfc_URL(JsVar *url) { ndefMsgPtr[NDEF_MSG_PL_LEN_MSB_OFFSET] = (NDEF_IC_LEN + urlLen)>>8; ndefMsgPtr[NDEF_MSG_PL_LEN_MSB_OFFSET+1] = (NDEF_IC_LEN + urlLen)&255; - /* write terminator TLV block */ - flatStrPtr[nfcDataLen - NDEF_TERM_TLV_LEN] = NDEF_TERM_TLV; - - /* start nfc peripheral */ - JsVar* uid = jswrap_nfc_start(NULL); - - /* inject UID/BCC */ - size_t len; - char *uidPtr = jsvGetDataPointer(uid, &len); - if(uidPtr) memcpy(flatStrPtr, uidPtr, TAG_HEADER_LEN); - jsvUnLock(uid); + nfc_raw_data_start(ndefMsgPtr, urlLen+NDEF_URL_RECORD_HEADER_LEN); #endif } @@ -2536,18 +2501,8 @@ void jswrap_nfc_pair(JsVar *key) { &ndef_msg_len); if (jsble_check_error(err_code)) return; - /* Encode NDEF message into a flat string - we need this to store the - * data so it hangs around. Avoid having a static var so we have RAM - * available if not using NFC. NFC data is read by nfc_callback */ - - JsVar *flatStr = jsvNewFlatStringOfLength(ndef_msg_len); - if (!flatStr) - return jsExceptionHere(JSET_ERROR, "Unable to create string with pairing data in"); - uint8_t *flatStrPtr = (uint8_t*)jsvGetFlatStringPointer(flatStr); - memcpy(flatStrPtr, buf, ndef_msg_len); + nfc_raw_data_start(buf, ndef_msg_len); - jswrap_nfc_raw(flatStr); - jsvUnLock(flatStr); #endif } @@ -2595,18 +2550,7 @@ void jswrap_nfc_androidApp(JsVar *appName) { &ndef_msg_len); if (jsble_check_error(err_code)) return; - /* Encode NDEF message into a flat string - we need this to store the - * data so it hangs around. Avoid having a static var so we have RAM - * available if not using NFC. NFC data is read by nfc_callback */ - - JsVar *flatStr = jsvNewFlatStringOfLength(ndef_msg_len); - if (!flatStr) - return jsExceptionHere(JSET_ERROR, "Unable to create string with pairing data in"); - uint8_t *flatStrPtr = (uint8_t*)jsvGetFlatStringPointer(flatStr); - memcpy(flatStrPtr, buf, ndef_msg_len); - - jswrap_nfc_raw(flatStr); - jsvUnLock(flatStr); + nfc_raw_data_start(buf, ndef_msg_len); #endif } @@ -2640,6 +2584,12 @@ void jswrap_nfc_raw(JsVar *payload) { if (!dataPtr || !dataLen || dataLen>NDEF_TAG2_VALUE_MAXLEN) return jsExceptionHere(JSET_ERROR, "Unable to get NFC data"); + nfc_raw_data_start((uint8_t*)dataPtr, dataLen); +#endif +} + +#ifdef USE_NFC +static void nfc_raw_data_start(uint8_t *dataPtr, size_t dataLen){ /* Create a flat string - we need this to store the NFC data so it hangs around. * Avoid having a static var so we have RAM available if not using NFC. * NFC data is read by nfc_callback in bluetooth.c */ From 365748f825cee2845e81cdf2dafd3e45958b3414 Mon Sep 17 00:00:00 2001 From: fanoush Date: Tue, 29 Aug 2023 00:24:50 +0200 Subject: [PATCH 3/4] fix non nfc build --- libs/bluetooth/jswrap_bluetooth.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index 2a7d057530..e76415ddb3 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -2631,9 +2631,8 @@ static void nfc_raw_data_start(uint8_t *dataPtr, size_t dataLen){ char *uidPtr = jsvGetDataPointer(uid, &len); if(uidPtr) memcpy(flatStrPtr, uidPtr, TAG_HEADER_LEN); jsvUnLock(uid); -#endif } - +#endif /*JSON{ "type" : "staticmethod", From c73ab40ca65ffb6fb4638dfcb17c08eaaa467ba4 Mon Sep 17 00:00:00 2001 From: fanoush Date: Tue, 29 Aug 2023 19:02:35 +0200 Subject: [PATCH 4/4] cleanup - move nfc_raw_data_start --- libs/bluetooth/jswrap_bluetooth.c | 93 +++++++++++++++---------------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/libs/bluetooth/jswrap_bluetooth.c b/libs/bluetooth/jswrap_bluetooth.c index e76415ddb3..7958758141 100644 --- a/libs/bluetooth/jswrap_bluetooth.c +++ b/libs/bluetooth/jswrap_bluetooth.c @@ -2391,7 +2391,52 @@ void jswrap_ble_setLowPowerConnection(bool lowPower) { } } -static void nfc_raw_data_start(uint8_t *dataPtr,size_t dataLen); +#ifdef USE_NFC +static void nfc_raw_data_start(uint8_t *dataPtr, size_t dataLen){ + /* Create a flat string - we need this to store the NFC data so it hangs around. + * Avoid having a static var so we have RAM available if not using NFC. + * NFC data is read by nfc_callback in bluetooth.c */ + bool isLongMsg = dataLen > 254; + size_t nfcDataLen = dataLen + NDEF_TERM_TLV_LEN + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + + + JsVar *flatStr = jsvNewFlatStringOfLength(nfcDataLen); + if (!flatStr) + return jsExceptionHere(JSET_ERROR, "Unable to create string with NFC data in"); + jsvObjectSetChild(execInfo.hiddenRoot, "NfcData", flatStr); + uint8_t *flatStrPtr = (uint8_t*)jsvGetFlatStringPointer(flatStr); + jsvUnLock(flatStr); + +/* assemble NDEF Message */ + memcpy(flatStrPtr, NDEF_HEADER, NDEF_HEADER_LEN_LONG); /* fill header */ + /* inject tag2 message length into header */ + if (isLongMsg){ + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = 255; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+1] = dataLen >> 8; + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+2] = dataLen & 255; + } else { + flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = dataLen; + } + + /* add NDEF message record header after NDEF header */ + uint8_t *ndefMsgPtr = flatStrPtr + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); + memcpy(ndefMsgPtr, dataPtr, dataLen); /* add payload */ + + + /* write terminator TLV block */ + flatStrPtr[nfcDataLen - NDEF_TERM_TLV_LEN] = NDEF_TERM_TLV; + + /* start nfc peripheral */ + JsVar* uid = jswrap_nfc_start(NULL); + + /* inject UID/BCC */ + size_t len; + char *uidPtr = jsvGetDataPointer(uid, &len); + if(uidPtr) memcpy(flatStrPtr, uidPtr, TAG_HEADER_LEN); + jsvUnLock(uid); +} +#endif + /*JSON{ "type" : "staticmethod", "class" : "NRF", @@ -2588,52 +2633,6 @@ void jswrap_nfc_raw(JsVar *payload) { #endif } -#ifdef USE_NFC -static void nfc_raw_data_start(uint8_t *dataPtr, size_t dataLen){ - /* Create a flat string - we need this to store the NFC data so it hangs around. - * Avoid having a static var so we have RAM available if not using NFC. - * NFC data is read by nfc_callback in bluetooth.c */ - bool isLongMsg = dataLen > 254; - size_t nfcDataLen = dataLen + NDEF_TERM_TLV_LEN + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); - - - JsVar *flatStr = jsvNewFlatStringOfLength(nfcDataLen); - if (!flatStr) - return jsExceptionHere(JSET_ERROR, "Unable to create string with NFC data in"); - jsvObjectSetChild(execInfo.hiddenRoot, "NfcData", flatStr); - uint8_t *flatStrPtr = (uint8_t*)jsvGetFlatStringPointer(flatStr); - jsvUnLock(flatStr); - - /* assemble NDEF Message */ - memcpy(flatStrPtr, NDEF_HEADER, NDEF_HEADER_LEN_LONG); /* fill header */ - /* inject tag2 message length into header */ - if (isLongMsg){ - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = 255; - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+1] = dataLen >> 8; - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET+2] = dataLen & 255; - } else { - flatStrPtr[NDEF_HEADER_MSG_LEN_OFFSET] = dataLen; - } - - /* add NDEF message record header after NDEF header */ - uint8_t *ndefMsgPtr = flatStrPtr + (isLongMsg ? NDEF_HEADER_LEN_LONG : NDEF_HEADER_LEN_SHORT); - memcpy(ndefMsgPtr, dataPtr, dataLen); /* add payload */ - - - /* write terminator TLV block */ - flatStrPtr[nfcDataLen - NDEF_TERM_TLV_LEN] = NDEF_TERM_TLV; - - /* start nfc peripheral */ - JsVar* uid = jswrap_nfc_start(NULL); - - /* inject UID/BCC */ - size_t len; - char *uidPtr = jsvGetDataPointer(uid, &len); - if(uidPtr) memcpy(flatStrPtr, uidPtr, TAG_HEADER_LEN); - jsvUnLock(uid); -} -#endif - /*JSON{ "type" : "staticmethod", "class" : "NRF",