@@ -47,6 +47,9 @@ BLEPeripheral::BLEPeripheral(void) :
47
47
_state(BLE_PERIPH_STATE_NOT_READY),
48
48
_advertise_service_uuid(NULL ),
49
49
_local_name(NULL ),
50
+ _service_data_uuid(NULL ),
51
+ _service_data(NULL ),
52
+ _service_data_length(0 ),
50
53
_appearance(0 ),
51
54
_min_conn_interval(DEFAULT_MIN_CONN_INTERVAL),
52
55
_max_conn_interval(DEFAULT_MAX_CONN_INTERVAL),
@@ -136,6 +139,18 @@ BLEPeripheral::end()
136
139
_stop ();
137
140
}
138
141
142
+ uint8_t
143
+ BLEPeripheral::getAdvertisingLength ()
144
+ {
145
+ return _adv_data_len;
146
+ }
147
+
148
+ uint8_t *
149
+ BLEPeripheral::getAdvertising ()
150
+ {
151
+ return _adv_data;
152
+ }
153
+
139
154
void
140
155
BLEPeripheral::setAdvertisedServiceUuid (const char * advertisedServiceUuid)
141
156
{
@@ -148,6 +163,14 @@ BLEPeripheral::setLocalName(const char* localName)
148
163
_local_name = localName;
149
164
}
150
165
166
+ void
167
+ BLEPeripheral::setAdvertisedServiceData (const char * serviceDataUuid, uint8_t * serviceData, uint8_t serviceDataLength)
168
+ {
169
+ _service_data_uuid = serviceDataUuid;
170
+ _service_data = serviceData;
171
+ _service_data_length = serviceDataLength;
172
+ }
173
+
151
174
void
152
175
BLEPeripheral::setDeviceName (const char deviceName[])
153
176
{
@@ -294,7 +317,7 @@ BLEPeripheral::_advDataInit(void)
294
317
if (BT_UUID16 == uuid.type ) {
295
318
uint8_t *adv_tmp = &_adv_data[_adv_data_len];
296
319
*adv_tmp++ = (1 + sizeof (uint16_t )); /* Segment data length */
297
- *adv_tmp++ = BLE_ADV_TYPE_INC_16_UUID;
320
+ *adv_tmp++ = BLE_ADV_TYPE_COMP_16_UUID; /* Needed for Eddystone */
298
321
UINT16_TO_LESTREAM (adv_tmp, uuid.uuid16 );
299
322
_adv_data_len += (2 + sizeof (uint16_t ));
300
323
} else if (BT_UUID128 == uuid.type ) {
@@ -324,6 +347,34 @@ BLEPeripheral::_advDataInit(void)
324
347
memcpy (adv_tmp, _local_name, calculated_len);
325
348
_adv_data_len += calculated_len + 2 ;
326
349
}
350
+
351
+ if (_service_data) {
352
+ /* Add Service Data (if it will fit) */
353
+
354
+ BLEUuid bleUuid = BLEUuid (_service_data_uuid);
355
+ struct bt_uuid uuid = bleUuid.uuid ();
356
+
357
+ /* A 128-bit Service Data UUID won't fit in an Advertising packet */
358
+ if (BT_UUID16 != uuid.type ) {
359
+ return ; /* We support service data only for 16-bit service UUID */
360
+ }
361
+
362
+ uint8_t block_len = 1 + sizeof (uint16_t ) + _service_data_length;
363
+ if (_adv_data_len + 1 + block_len > BLE_MAX_ADV_SIZE) {
364
+ return ; // Service data block is too large.
365
+ }
366
+
367
+ adv_tmp = &_adv_data[_adv_data_len];
368
+
369
+ *adv_tmp++ = block_len;
370
+ _adv_data_len++;
371
+
372
+ *adv_tmp++ = BLE_ADV_TYPE_SERVICE_DATA_16_UUID;
373
+ UINT16_TO_LESTREAM (adv_tmp, uuid.uuid16 );
374
+ memcpy (adv_tmp, _service_data, _service_data_length);
375
+
376
+ _adv_data_len += block_len;
377
+ }
327
378
}
328
379
329
380
BleStatus
0 commit comments