English Translation
Title: Adapting NFC Functionality for QWRT on Xiaomi BE10000 Router
Analysis
After flashing the Xiaomi BE10000 with QWRT, the device's network potential is indeed greatly unleashed. Advanced features such as 2.5G optical modules and SFP+ interfaces work perfectly. The only drawback is that the factory NFC "tap to connect to Wi-Fi" feature no longer works. After researching, the NFC tag is essentially an EEPROM chip mounted on the motherboard. Using i2cdetect for scanning:
root@QWRT:~# i2cdetect -l
i2c-1 i2c QUP I2C adapter I2C adapter
i2c-2 i2c QUP I2C adapter I2C adapter
i2c-0 i2c QUP I2C adapter I2C adapter
root@QWRT:~# i2cdetect -y -r 0
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- 54 -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --
The scan results quickly pinpoint the device attached to I2C bus 0 at physical address 0x54.
NFC tap-to-connect-to-Wi-Fi uses standard NDEF format data (Ref: Wi-Fi Simple Configuration — ndeflib 0.3.2 documentation). Therefore, simply writing the data into the EEPROM according to the standard can restore the NFC tap-to-connect functionality.
Implementation
This article discusses only low-level hardware driver adaptation and NDEF standard protocol encapsulation for the OpenWrt/QWRT system. The hardware parameters mentioned are derived from public specification documents and generic I2C debugging tools. This project is for personal research interest and does not include or distribute any vendor-proprietary binary code. It is intended for technical exchange and learning only. Do not use for commercial purposes. Any risk of device damage resulting from attempts described herein shall be borne solely by the reader.
Extract Data and Construct NDEF Payload
To automatically update NFC data based on Wi-Fi credentials, we first need to obtain the current Wi-Fi SSID and password. On OpenWrt, these configurations are managed entirely by UCI (Unified Configuration Interface). Therefore, we only need to read the wireless configuration file from UCI.
To ensure compatibility with modern smartphones, early devices typically used a Device Password Token to trigger WPS negotiation, but modern Android/iOS systems have restricted this behavior. For broader compatibility, we must follow the Wi-Fi Simple Configuration (WSC) specification and package the configuration as a WLAN Configuration Token (credential configuration token). (Ref: Wi-Fi Simple Configuration — ndeflib 0.3.2 documentation)
Map OpenWrt's wireless encryption modes (e.g., WPA2, WPA3-SAE) precisely to the hex codes defined by the WSC specification:
0x1003: Authentication Type0x100F: Encryption Type0x1045: SSID0x1027: Network Key (password)
Through a script, we automatically traverse and select the primary AP bridged tolan(e.g.,wifi0), convert its attributes to hex strings, and produce a standard NDEF payload.
Write to NFC EEPROM
When the NFC EEPROM receives a long string of NDEF data, writing too quickly or in excessively large blocks per write can easily cause the chip's I2C state machine to lock up.
After testing, we chose to use the i2ctransfer tool for atomic fragmented writes. Two critical timing details:
- Due to communication limitations, each loop slices only 4 bytes, with auto-incrementing register addresses.
- Between each 4-byte block write, a 10 ms delay is enforced to allow sufficient internal erase/write time for the chip. Finally, any remaining data less than 4 bytes is padded with
0x00.
Automatically Trigger Writes on Wi-Fi Configuration Changes
To closely follow OpenWrt's architecture, we initially tried using hooks but found they often failed. Eventually, three fallback layers were added:
- LuCI frontend trigger: Register a hook under
/etc/uci-defaults/to bind the NFC sync script to the system'sucitrackmechanism. When a user modifies the Wi-Fi password in LuCI and clicks "Save & Apply", the system automatically updates the NFC data in the background. - Hotplug layer: Add a hotplug event listener in
/etc/hotplug.d/iface/70-nfc. When the router'slanorwifiinterface changes toifupstate, the system automatically triggers the sync. - Cron job: If none of the above triggers work, a cron job forces a check every 15 seconds to determine if an NFC update is needed.
Additionally, considering that the NFC EEPROM has limited write endurance, if the network interface restarts even once and triggers a full rewrite, the chip would soon wear out. Therefore, a simple hash check mechanism is introduced in the underlying nfc-sync script:
- When the script is awakened, it first extracts the current
wirelessconfiguration and calculates its MD5 hash. - It compares this hash with the old hash cached in
/var/run/nfc-wireless.md5. - Only when the MD5 value actually changes does it issue the I2C write command. Otherwise, the process terminates immediately. Combined with a concurrent file lock (
/var/lock/nfc-sync.lock), this logic ensures that the NFC hardware's lifespan is absolutely protected against any network flapping or multiple concurrent events.
After testing, automatic updating works as expected:
![[Pasted image 20260525230448.png]]
Code repository: KaguraiYoRoy/be10000-qwrt-nfc: NFC Userland Implementation of QWRT for Xiaomi BE10000 (RC01) Router
References:
Comments (0)