From 5f8c4d048e6db9768168358f449deed0f0a43aa9 Mon Sep 17 00:00:00 2001 From: chenjintao Date: Tue, 13 Oct 2026 16:18:00 +0800 Subject: [PATCH] feat(nfc): emit example.com URI for native phone reading --- .../threadx/interface/custom_app/nfc.c | 47 ++++--------------- 1 file changed, 9 insertions(+), 38 deletions(-) diff --git a/ql-application/threadx/interface/custom_app/nfc.c b/ql-application/threadx/interface/custom_app/nfc.c index 2fc0b50..16fc043 100644 --- a/ql-application/threadx/interface/custom_app/nfc.c +++ b/ql-application/threadx/interface/custom_app/nfc.c @@ -49,7 +49,6 @@ static volatile u32 g_nfc_tx_mode_deadline = 0; #define NFC_TYPE2_READ_SIZE 16 #define NFC_TYPE2_MEMORY_SIZE 160 #define NFC_TYPE2_NDEF_OFFSET 16 -#define NFC_IMEI_DIGITS 15 #define NFC_IRQ_TX 0x40 #define NFC_IRQ_RX 0x20 @@ -173,37 +172,11 @@ static u8 nfc_card_emulation_send_frame(const u8 *frame, u8 length) static void nfc_type2_build_ndef(void) { - char device_id[32] = {0}; - char serial_number[32] = {0}; - char imei[32] = {0}; - char json[128]; - int json_len; + static const char uri_suffix[] = "example.com/"; + size_t uri_len = sizeof(uri_suffix) - 1; u8 *ndef; u8 record_len; - if (hal_os_get_device_id(device_id) != 0) { - strcpy(device_id, "unknown"); - } - if (hal_os_get_device_sn(serial_number) != 0) { - strcpy(serial_number, "unknown"); - } - if (ql_dev_get_imei(imei, sizeof(imei)) != QL_DEV_SUCCESS || - imei[0] == '\0') { - strcpy(imei, "unknown"); - } else { - imei[NFC_IMEI_DIGITS] = '\0'; - } - - json_len = snprintf(json, sizeof(json), - "{\"device_id\":\"%s\",\"serial_number\":\"%s\"," - "\"imei\":\"%s\"}", - device_id, serial_number, imei); - if (json_len < 0) { - json_len = 0; - } else if (json_len >= (int)sizeof(json)) { - json_len = sizeof(json) - 1; - } - memset(nfc_type2_memory, 0, sizeof(nfc_type2_memory)); /* Static UID/manufacturer pages followed by a read-only Type 2 CC. */ @@ -217,20 +190,18 @@ static void nfc_type2_build_ndef(void) nfc_type2_memory[15] = 0x0F; /* Read-only access. */ ndef = &nfc_type2_memory[NFC_TYPE2_NDEF_OFFSET]; - record_len = (u8)(7 + json_len); + record_len = (u8)(5 + uri_len); ndef[0] = 0x03; /* NDEF Message TLV. */ ndef[1] = record_len; ndef[2] = 0xD1; /* MB, ME, SR, TNF well-known. */ ndef[3] = 0x01; /* Type length. */ - ndef[4] = (u8)(3 + json_len); /* Text status/lang plus JSON. */ - ndef[5] = 'T'; - ndef[6] = 0x02; /* UTF-8, language length 2. */ - ndef[7] = 'e'; - ndef[8] = 'n'; - memcpy(&ndef[9], json, json_len); - ndef[9 + json_len] = 0xFE; /* Terminator TLV. */ + ndef[4] = (u8)(1 + uri_len); /* URI prefix code plus suffix. */ + ndef[5] = 'U'; /* NFC Forum URI record. */ + ndef[6] = 0x04; /* URI prefix: https:// */ + memcpy(&ndef[7], uri_suffix, uri_len); + ndef[7 + uri_len] = 0xFE; /* Terminator TLV. */ - printf("NFC Type 2 NDEF: %s\r\n", json); + printf("NFC Type 2 NDEF URI: https://%s\r\n", uri_suffix); } static void nfc_type2_read_pages(u8 start_page, u8 *response)