@@ -57,19 +57,43 @@ static const char* eddystone_url_encoding[14] = {
5757 ".gov"
5858 };
5959
60+ /****************** Eddystone-UID **************
61+ Byte offset Field Description
62+ 0 Frame Type Value = 0x00
63+ 1 Ranging Data Calibrated Tx power at 0 m
64+ 2 NID[0] 10-byte Namespace
65+ 3 NID[1]
66+ 4 NID[2]
67+ 5 NID[3]
68+ 6 NID[4]
69+ 7 NID[5]
70+ 8 NID[6]
71+ 9 NID[7]
72+ 10 NID[8]
73+ 11 NID[9]
74+ 12 BID[0] 6-byte Instance
75+ 13 BID[1]
76+ 14 BID[2]
77+ 15 BID[3]
78+ 16 BID[4]
79+ 17 BID[5]
80+ 18 RFU Reserved for future use, must be0x00
81+ 19 RFU Reserved for future use, must be0x00
82+ *********************************************/
6083/* decode and store received UID */
6184static esp_err_t esp_eddystone_uid_received (const uint8_t * buf , uint8_t len , esp_eddystone_result_t * res )
6285{
6386 uint8_t pos = 0 ;
64- if (len + 4 != EDDYSTONE_UID_FRAME_LEN ) {
87+ //1-byte Ranging Data + 10-byte Namespace + 6-byte Instance
88+ if ((len != EDDYSTONE_UID_DATA_LEN ) && (len != (EDDYSTONE_UID_RFU_LEN + EDDYSTONE_UID_DATA_LEN ))) {
6589 //ERROR:uid len wrong
6690 return -1 ;
6791 }
6892 res -> inform .uid .ranging_data = buf [pos ++ ];
69- for (int i = 0 ; i < 10 ; i ++ ) {
93+ for (int i = 0 ; i < EDDYSTONE_UID_NAMESPACE_LEN ; i ++ ) {
7094 res -> inform .uid .namespace_id [i ] = buf [pos ++ ];
7195 }
72- for (int i = 0 ; i < 6 ; i ++ ) {
96+ for (int i = 0 ; i < EDDYSTONE_UID_INSTANCE_LEN ; i ++ ) {
7397 res -> inform .uid .instance_id [i ] = buf [pos ++ ];
7498 }
7599 return 0 ;
@@ -94,26 +118,53 @@ static char* esp_eddystone_resolve_url_scheme(const uint8_t *url_start, const ui
94118 return url_buf ;
95119}
96120
121+ /************************** Eddystone-URL *************
122+ Frame Specification
123+ Byte offset Field Description
124+ 0 Frame Type Value = 0x10
125+ 1 TX Power Calibrated Tx power at 0 m
126+ 2 URL Scheme Encoded Scheme Prefix
127+ 3+ Encoded URL Length 1-17
128+ *******************************************************/
97129/* decode and store received URL, the pointer url_res points to the resolved url */
98130static esp_err_t esp_eddystone_url_received (const uint8_t * buf , uint8_t len , esp_eddystone_result_t * res )
99131{
100132 char * url_res = NULL ;
101133 uint8_t pos = 0 ;
102- if (len - 1 > EDDYSTONE_URL_MAX_LEN ) {
134+ if (len - EDDYSTONE_URL_TX_POWER_LEN > EDDYSTONE_URL_MAX_LEN ) {
103135 //ERROR:too long url
104136 return -1 ;
105137 }
106138 res -> inform .url .tx_power = buf [pos ++ ];
107139 url_res = esp_eddystone_resolve_url_scheme (buf + pos , buf + len - 1 );
108140 memcpy (& res -> inform .url .url , url_res , strlen (url_res ));
141+ res -> inform .url .url [strlen (url_res )] = '\0' ;
109142 return 0 ;
110143}
111144
145+ /****************** eddystone-tlm ***************
146+ * Unencrypted TLM Frame Specification
147+ Byte offset Field Description
148+ 0 Frame Type Value = 0x20
149+ 1 Version TLM version, value = 0x00
150+ 2 VBATT[0] Battery voltage, 1 mV/bit
151+ 3 VBATT[1]
152+ 4 TEMP[0] Beacon temperature
153+ 5 TEMP[1]
154+ 6 ADV_CNT[0] Advertising PDU count
155+ 7 ADV_CNT[1]
156+ 8 ADV_CNT[2]
157+ 9 ADV_CNT[3]
158+ 10 SEC_CNT[0] Time since power-on or reboot
159+ 11 SEC_CNT[1]
160+ 12 SEC_CNT[2]
161+ 13 SEC_CNT[3]
162+ ************************************************/
112163/* decode and store received TLM */
113164static esp_err_t esp_eddystone_tlm_received (const uint8_t * buf , uint8_t len , esp_eddystone_result_t * res )
114165{
115166 uint8_t pos = 0 ;
116- if (len + 4 > EDDYSTONE_TLM_FRAME_LEN ) {
167+ if (len > EDDYSTONE_TLM_DATA_LEN ) {
117168 //ERROR:TLM too long
118169 return -1 ;
119170 }
@@ -156,10 +207,16 @@ static esp_err_t esp_eddystone_get_inform(const uint8_t* buf, uint8_t len, esp_e
156207
157208esp_err_t esp_eddystone_decode (const uint8_t * buf , uint8_t len , esp_eddystone_result_t * res )
158209{
159- static uint8_t pos = 0 ;
210+ if (len == 0 || buf == NULL || res == NULL ) {
211+ return -1 ;
212+ }
213+ uint8_t pos = 0 ;
160214 while (res -> common .srv_data_type != EDDYSTONE_SERVICE_UUID )
161215 {
162216 pos ++ ;
217+ if (pos >= len ) {
218+ return -1 ;
219+ }
163220 uint8_t ad_type = buf [pos ++ ];
164221 switch (ad_type )
165222 {
0 commit comments