@@ -47,6 +47,9 @@ BLEPeripheral::BLEPeripheral(void) :
4747 _state(BLE_PERIPH_STATE_NOT_READY),
4848 _advertise_service_uuid(NULL ),
4949 _local_name(NULL ),
50+ _service_data_uuid(NULL ),
51+ _service_data(NULL ),
52+ _service_data_length(0 ),
5053 _appearance(0 ),
5154 _min_conn_interval(DEFAULT_MIN_CONN_INTERVAL),
5255 _max_conn_interval(DEFAULT_MAX_CONN_INTERVAL),
@@ -136,6 +139,18 @@ BLEPeripheral::end()
136139 _stop ();
137140}
138141
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+
139154void
140155BLEPeripheral::setAdvertisedServiceUuid (const char * advertisedServiceUuid)
141156{
@@ -148,6 +163,14 @@ BLEPeripheral::setLocalName(const char* localName)
148163 _local_name = localName;
149164}
150165
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+
151174void
152175BLEPeripheral::setDeviceName (const char deviceName[])
153176{
@@ -294,7 +317,7 @@ BLEPeripheral::_advDataInit(void)
294317 if (BT_UUID16 == uuid.type ) {
295318 uint8_t *adv_tmp = &_adv_data[_adv_data_len];
296319 *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 */
298321 UINT16_TO_LESTREAM (adv_tmp, uuid.uuid16 );
299322 _adv_data_len += (2 + sizeof (uint16_t ));
300323 } else if (BT_UUID128 == uuid.type ) {
@@ -324,6 +347,34 @@ BLEPeripheral::_advDataInit(void)
324347 memcpy (adv_tmp, _local_name, calculated_len);
325348 _adv_data_len += calculated_len + 2 ;
326349 }
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+ }
327378}
328379
329380BleStatus
0 commit comments