1bdc352b1SMatthias Ringwald /* 2bdc352b1SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3bdc352b1SMatthias Ringwald * 4bdc352b1SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5bdc352b1SMatthias Ringwald * modification, are permitted provided that the following conditions 6bdc352b1SMatthias Ringwald * are met: 7bdc352b1SMatthias Ringwald * 8bdc352b1SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9bdc352b1SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10bdc352b1SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11bdc352b1SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12bdc352b1SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13bdc352b1SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14bdc352b1SMatthias Ringwald * contributors may be used to endorse or promote products derived 15bdc352b1SMatthias Ringwald * from this software without specific prior written permission. 16bdc352b1SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17bdc352b1SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18bdc352b1SMatthias Ringwald * monetary gain. 19bdc352b1SMatthias Ringwald * 20bdc352b1SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21bdc352b1SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22bdc352b1SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25bdc352b1SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26bdc352b1SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27bdc352b1SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28bdc352b1SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29bdc352b1SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30bdc352b1SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31bdc352b1SMatthias Ringwald * SUCH DAMAGE. 32bdc352b1SMatthias Ringwald * 33bdc352b1SMatthias Ringwald * Please inquire about commercial licensing options at 34bdc352b1SMatthias Ringwald * [email protected] 35bdc352b1SMatthias Ringwald * 36bdc352b1SMatthias Ringwald */ 37bdc352b1SMatthias Ringwald 38bdc352b1SMatthias Ringwald #define BTSTACK_FILE__ "spp_and_gatt_counter.c" 39bdc352b1SMatthias Ringwald 40bdc352b1SMatthias Ringwald // ***************************************************************************** 41ec8ae085SMilanka Ringwald /* EXAMPLE_START(spp_and_le_counter): Dual Mode - SPP and LE Counter 42bdc352b1SMatthias Ringwald * 43bdc352b1SMatthias Ringwald * @text The SPP and LE Counter example combines the Bluetooth Classic SPP Counter 44bdc352b1SMatthias Ringwald * and the Bluetooth LE Counter into a single application. 45bdc352b1SMatthias Ringwald * 46bdc352b1SMatthias Ringwald * @text In this Section, we only point out the differences to the individual examples 47bdc352b1SMatthias Ringwald * and how the stack is configured. 48bdc352b1SMatthias Ringwald * 49bdc352b1SMatthias Ringwald * @text Note: To test, please run the example, and then: 50bdc352b1SMatthias Ringwald * - for SPP pair from a remote device, and open the Virtual Serial Port, 51bdc352b1SMatthias Ringwald * - for LE use some GATT Explorer, e.g. LightBlue, BLExplr, to enable notifications. 52bdc352b1SMatthias Ringwald */ 53bdc352b1SMatthias Ringwald // ***************************************************************************** 54bdc352b1SMatthias Ringwald 55bdc352b1SMatthias Ringwald #include <stdint.h> 56bdc352b1SMatthias Ringwald #include <stdio.h> 57bdc352b1SMatthias Ringwald #include <stdlib.h> 58bdc352b1SMatthias Ringwald #include <string.h> 59bdc352b1SMatthias Ringwald #include <inttypes.h> 60bdc352b1SMatthias Ringwald 61bdc352b1SMatthias Ringwald #include "btstack.h" 62bdc352b1SMatthias Ringwald #include "spp_and_gatt_counter.h" 63bdc352b1SMatthias Ringwald 64bdc352b1SMatthias Ringwald #define RFCOMM_SERVER_CHANNEL 1 65bdc352b1SMatthias Ringwald #define HEARTBEAT_PERIOD_MS 1000 66bdc352b1SMatthias Ringwald 67bdc352b1SMatthias Ringwald static uint16_t rfcomm_channel_id; 68bdc352b1SMatthias Ringwald static uint8_t spp_service_buffer[150]; 69bdc352b1SMatthias Ringwald static int le_notification_enabled; 70bdc352b1SMatthias Ringwald static hci_con_handle_t att_con_handle; 71bdc352b1SMatthias Ringwald 72bdc352b1SMatthias Ringwald // THE Couner 73bdc352b1SMatthias Ringwald static btstack_timer_source_t heartbeat; 74bdc352b1SMatthias Ringwald static int counter = 0; 75bdc352b1SMatthias Ringwald static char counter_string[30]; 76bdc352b1SMatthias Ringwald static int counter_string_len; 77bdc352b1SMatthias Ringwald 78bdc352b1SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 79bdc352b1SMatthias Ringwald 80bdc352b1SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 81bdc352b1SMatthias Ringwald static uint8_t gatt_service_buffer[70]; 82bdc352b1SMatthias Ringwald #endif 83bdc352b1SMatthias Ringwald 84bdc352b1SMatthias Ringwald /* 85bdc352b1SMatthias Ringwald * @section Advertisements 86bdc352b1SMatthias Ringwald * 87e06798b6SMatthias Ringwald * @text The Flags attribute in the Advertisement Data indicates if a device is dual-mode or le-only. 88bdc352b1SMatthias Ringwald */ 89e06798b6SMatthias Ringwald /* LISTING_START(advertisements): Advertisement data: Flag 0x02 indicates dual-mode device */ 90bdc352b1SMatthias Ringwald const uint8_t adv_data[] = { 91e06798b6SMatthias Ringwald // Flags general discoverable 92e06798b6SMatthias Ringwald 0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x02, 93bdc352b1SMatthias Ringwald // Name 94bdc352b1SMatthias Ringwald 0x0b, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'L', 'E', ' ', 'C', 'o', 'u', 'n', 't', 'e', 'r', 95bdc352b1SMatthias Ringwald // Incomplete List of 16-bit Service Class UUIDs -- FF10 - only valid for testing! 96bdc352b1SMatthias Ringwald 0x03, BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS, 0x10, 0xff, 97bdc352b1SMatthias Ringwald }; 98bdc352b1SMatthias Ringwald /* LISTING_END */ 99bdc352b1SMatthias Ringwald uint8_t adv_data_len = sizeof(adv_data); 100bdc352b1SMatthias Ringwald 101bdc352b1SMatthias Ringwald 102bdc352b1SMatthias Ringwald /* 103bdc352b1SMatthias Ringwald * @section Packet Handler 104bdc352b1SMatthias Ringwald * 105bdc352b1SMatthias Ringwald * @text The packet handler of the combined example is just the combination of the individual packet handlers. 106bdc352b1SMatthias Ringwald */ 107bdc352b1SMatthias Ringwald 108bdc352b1SMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 109bdc352b1SMatthias Ringwald UNUSED(channel); 110bdc352b1SMatthias Ringwald 111bdc352b1SMatthias Ringwald bd_addr_t event_addr; 112bdc352b1SMatthias Ringwald uint8_t rfcomm_channel_nr; 113bdc352b1SMatthias Ringwald uint16_t mtu; 114bdc352b1SMatthias Ringwald int i; 115bdc352b1SMatthias Ringwald 116bdc352b1SMatthias Ringwald switch (packet_type) { 117bdc352b1SMatthias Ringwald case HCI_EVENT_PACKET: 118bdc352b1SMatthias Ringwald switch (hci_event_packet_get_type(packet)) { 119bdc352b1SMatthias Ringwald case HCI_EVENT_PIN_CODE_REQUEST: 120bdc352b1SMatthias Ringwald // inform about pin code request 121bdc352b1SMatthias Ringwald printf("Pin code request - using '0000'\n"); 122bdc352b1SMatthias Ringwald hci_event_pin_code_request_get_bd_addr(packet, event_addr); 123bdc352b1SMatthias Ringwald gap_pin_code_response(event_addr, "0000"); 124bdc352b1SMatthias Ringwald break; 125bdc352b1SMatthias Ringwald 126bdc352b1SMatthias Ringwald case HCI_EVENT_USER_CONFIRMATION_REQUEST: 127bdc352b1SMatthias Ringwald // inform about user confirmation request 128bdc352b1SMatthias Ringwald printf("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", little_endian_read_32(packet, 8)); 129bdc352b1SMatthias Ringwald printf("SSP User Confirmation Auto accept\n"); 130bdc352b1SMatthias Ringwald break; 131bdc352b1SMatthias Ringwald 132bdc352b1SMatthias Ringwald case HCI_EVENT_DISCONNECTION_COMPLETE: 133bdc352b1SMatthias Ringwald le_notification_enabled = 0; 134bdc352b1SMatthias Ringwald break; 135bdc352b1SMatthias Ringwald 136bdc352b1SMatthias Ringwald case ATT_EVENT_CAN_SEND_NOW: 137bdc352b1SMatthias Ringwald att_server_notify(att_con_handle, ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE, (uint8_t*) counter_string, counter_string_len); 138bdc352b1SMatthias Ringwald break; 139bdc352b1SMatthias Ringwald 140bdc352b1SMatthias Ringwald case RFCOMM_EVENT_INCOMING_CONNECTION: 141bdc352b1SMatthias Ringwald // data: event (8), len(8), address(48), channel (8), rfcomm_cid (16) 142bdc352b1SMatthias Ringwald rfcomm_event_incoming_connection_get_bd_addr(packet, event_addr); 143bdc352b1SMatthias Ringwald rfcomm_channel_nr = rfcomm_event_incoming_connection_get_server_channel(packet); 144bdc352b1SMatthias Ringwald rfcomm_channel_id = rfcomm_event_incoming_connection_get_rfcomm_cid(packet); 145bdc352b1SMatthias Ringwald printf("RFCOMM channel %u requested for %s\n", rfcomm_channel_nr, bd_addr_to_str(event_addr)); 146bdc352b1SMatthias Ringwald rfcomm_accept_connection(rfcomm_channel_id); 147bdc352b1SMatthias Ringwald break; 148bdc352b1SMatthias Ringwald 149bdc352b1SMatthias Ringwald case RFCOMM_EVENT_CHANNEL_OPENED: 150bdc352b1SMatthias Ringwald // data: event(8), len(8), status (8), address (48), server channel(8), rfcomm_cid(16), max frame size(16) 151bdc352b1SMatthias Ringwald if (rfcomm_event_channel_opened_get_status(packet)) { 152bdc352b1SMatthias Ringwald printf("RFCOMM channel open failed, status %u\n", rfcomm_event_channel_opened_get_status(packet)); 153bdc352b1SMatthias Ringwald } else { 154bdc352b1SMatthias Ringwald rfcomm_channel_id = rfcomm_event_channel_opened_get_rfcomm_cid(packet); 155bdc352b1SMatthias Ringwald mtu = rfcomm_event_channel_opened_get_max_frame_size(packet); 156bdc352b1SMatthias Ringwald printf("RFCOMM channel open succeeded. New RFCOMM Channel ID %u, max frame size %u\n", rfcomm_channel_id, mtu); 157bdc352b1SMatthias Ringwald } 158bdc352b1SMatthias Ringwald break; 159bdc352b1SMatthias Ringwald 160bdc352b1SMatthias Ringwald case RFCOMM_EVENT_CAN_SEND_NOW: 161bdc352b1SMatthias Ringwald rfcomm_send(rfcomm_channel_id, (uint8_t*) counter_string, counter_string_len); 162bdc352b1SMatthias Ringwald break; 163bdc352b1SMatthias Ringwald 164bdc352b1SMatthias Ringwald case RFCOMM_EVENT_CHANNEL_CLOSED: 165bdc352b1SMatthias Ringwald printf("RFCOMM channel closed\n"); 166bdc352b1SMatthias Ringwald rfcomm_channel_id = 0; 167bdc352b1SMatthias Ringwald break; 168bdc352b1SMatthias Ringwald 169bdc352b1SMatthias Ringwald default: 170bdc352b1SMatthias Ringwald break; 171bdc352b1SMatthias Ringwald } 172bdc352b1SMatthias Ringwald break; 173bdc352b1SMatthias Ringwald 174bdc352b1SMatthias Ringwald case RFCOMM_DATA_PACKET: 175bdc352b1SMatthias Ringwald printf("RCV: '"); 176bdc352b1SMatthias Ringwald for (i=0;i<size;i++){ 177bdc352b1SMatthias Ringwald putchar(packet[i]); 178bdc352b1SMatthias Ringwald } 179bdc352b1SMatthias Ringwald printf("'\n"); 180bdc352b1SMatthias Ringwald break; 181bdc352b1SMatthias Ringwald 182bdc352b1SMatthias Ringwald default: 183bdc352b1SMatthias Ringwald break; 184bdc352b1SMatthias Ringwald } 185bdc352b1SMatthias Ringwald } 186bdc352b1SMatthias Ringwald 187bdc352b1SMatthias Ringwald // ATT Client Read Callback for Dynamic Data 188bdc352b1SMatthias Ringwald // - if buffer == NULL, don't copy data, just return size of value 189bdc352b1SMatthias Ringwald // - if buffer != NULL, copy data and return number bytes copied 190bdc352b1SMatthias Ringwald // @param offset defines start of attribute value 191bdc352b1SMatthias Ringwald static uint16_t att_read_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t offset, uint8_t * buffer, uint16_t buffer_size){ 192bdc352b1SMatthias Ringwald UNUSED(con_handle); 193bdc352b1SMatthias Ringwald 194bdc352b1SMatthias Ringwald if (att_handle == ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE){ 19534bd46a0SMatthias Ringwald return att_read_callback_handle_blob((const uint8_t *)counter_string, counter_string_len, offset, buffer, buffer_size); 196bdc352b1SMatthias Ringwald } 197bdc352b1SMatthias Ringwald return 0; 198bdc352b1SMatthias Ringwald } 199bdc352b1SMatthias Ringwald 200bdc352b1SMatthias Ringwald // write requests 201bdc352b1SMatthias Ringwald static int att_write_callback(hci_con_handle_t con_handle, uint16_t att_handle, uint16_t transaction_mode, uint16_t offset, uint8_t *buffer, uint16_t buffer_size){ 202bdc352b1SMatthias Ringwald // ignore cancel sent for new connections 203bdc352b1SMatthias Ringwald if (transaction_mode == ATT_TRANSACTION_MODE_CANCEL) return 0; 204bdc352b1SMatthias Ringwald // find characteristic for handle 205bdc352b1SMatthias Ringwald switch (att_handle){ 206bdc352b1SMatthias Ringwald case ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_CLIENT_CONFIGURATION_HANDLE: 207bdc352b1SMatthias Ringwald le_notification_enabled = little_endian_read_16(buffer, 0) == GATT_CLIENT_CHARACTERISTICS_CONFIGURATION_NOTIFICATION; 208bdc352b1SMatthias Ringwald att_con_handle = con_handle; 209bdc352b1SMatthias Ringwald return 0; 210bdc352b1SMatthias Ringwald case ATT_CHARACTERISTIC_0000FF11_0000_1000_8000_00805F9B34FB_01_VALUE_HANDLE: 211bdc352b1SMatthias Ringwald printf("Write on test characteristic: "); 212bdc352b1SMatthias Ringwald printf_hexdump(buffer, buffer_size); 213bdc352b1SMatthias Ringwald return 0; 214bdc352b1SMatthias Ringwald default: 215bdc352b1SMatthias Ringwald printf("WRITE Callback, handle %04x, mode %u, offset %u, data: ", con_handle, transaction_mode, offset); 216bdc352b1SMatthias Ringwald printf_hexdump(buffer, buffer_size); 217bdc352b1SMatthias Ringwald return 0; 218bdc352b1SMatthias Ringwald } 219bdc352b1SMatthias Ringwald } 220bdc352b1SMatthias Ringwald 221bdc352b1SMatthias Ringwald static void beat(void){ 222bdc352b1SMatthias Ringwald counter++; 223*db2353e5SMatthias Ringwald counter_string_len = snprintf(counter_string, sizeof(counter_string), "BTstack counter %04u", counter); 224bdc352b1SMatthias Ringwald puts(counter_string); 225bdc352b1SMatthias Ringwald } 226bdc352b1SMatthias Ringwald 227bdc352b1SMatthias Ringwald /* 228bdc352b1SMatthias Ringwald * @section Heartbeat Handler 229bdc352b1SMatthias Ringwald * 230bdc352b1SMatthias Ringwald * @text Similar to the packet handler, the heartbeat handler is the combination of the individual ones. 231bdc352b1SMatthias Ringwald * After updating the counter, it requests an ATT_EVENT_CAN_SEND_NOW and/or RFCOMM_EVENT_CAN_SEND_NOW 232bdc352b1SMatthias Ringwald */ 233bdc352b1SMatthias Ringwald 234bdc352b1SMatthias Ringwald /* LISTING_START(heartbeat): Combined Heartbeat handler */ 235bdc352b1SMatthias Ringwald static void heartbeat_handler(struct btstack_timer_source *ts){ 236bdc352b1SMatthias Ringwald 237bdc352b1SMatthias Ringwald if (rfcomm_channel_id || le_notification_enabled) { 238bdc352b1SMatthias Ringwald beat(); 239bdc352b1SMatthias Ringwald } 240bdc352b1SMatthias Ringwald 241bdc352b1SMatthias Ringwald if (rfcomm_channel_id){ 242bdc352b1SMatthias Ringwald rfcomm_request_can_send_now_event(rfcomm_channel_id); 243bdc352b1SMatthias Ringwald } 244bdc352b1SMatthias Ringwald 245bdc352b1SMatthias Ringwald if (le_notification_enabled) { 246bdc352b1SMatthias Ringwald att_server_request_can_send_now_event(att_con_handle); 247bdc352b1SMatthias Ringwald } 248bdc352b1SMatthias Ringwald 249bdc352b1SMatthias Ringwald btstack_run_loop_set_timer(ts, HEARTBEAT_PERIOD_MS); 250bdc352b1SMatthias Ringwald btstack_run_loop_add_timer(ts); 251bdc352b1SMatthias Ringwald } 252bdc352b1SMatthias Ringwald /* LISTING_END */ 253bdc352b1SMatthias Ringwald 254bdc352b1SMatthias Ringwald /* 255bdc352b1SMatthias Ringwald * @section Main Application Setup 256bdc352b1SMatthias Ringwald * 257bdc352b1SMatthias Ringwald * @text As with the packet and the heartbeat handlers, the combined app setup contains the code from the individual example setups. 258bdc352b1SMatthias Ringwald */ 259bdc352b1SMatthias Ringwald 260bdc352b1SMatthias Ringwald /* LISTING_START(MainConfiguration): Init L2CAP RFCOMM SDO SM ATT Server and start heartbeat timer */ 261bdc352b1SMatthias Ringwald int btstack_main(void); 262bdc352b1SMatthias Ringwald int btstack_main(void) 263bdc352b1SMatthias Ringwald { 264bdc352b1SMatthias Ringwald l2cap_init(); 265bdc352b1SMatthias Ringwald 266bdc352b1SMatthias Ringwald rfcomm_init(); 267bdc352b1SMatthias Ringwald rfcomm_register_service(packet_handler, RFCOMM_SERVER_CHANNEL, 0xffff); 268bdc352b1SMatthias Ringwald 269bdc352b1SMatthias Ringwald // init SDP, create record for SPP and register with SDP 270bdc352b1SMatthias Ringwald sdp_init(); 271bdc352b1SMatthias Ringwald memset(spp_service_buffer, 0, sizeof(spp_service_buffer)); 272bdc352b1SMatthias Ringwald spp_create_sdp_record(spp_service_buffer, 0x10001, RFCOMM_SERVER_CHANNEL, "SPP Counter"); 273bdc352b1SMatthias Ringwald sdp_register_service(spp_service_buffer); 274bdc352b1SMatthias Ringwald printf("SDP service record size: %u\n", de_get_len(spp_service_buffer)); 275bdc352b1SMatthias Ringwald 276bdc352b1SMatthias Ringwald #ifdef ENABLE_GATT_OVER_CLASSIC 277bdc352b1SMatthias Ringwald // init SDP, create record for GATT and register with SDP 278bdc352b1SMatthias Ringwald memset(gatt_service_buffer, 0, sizeof(gatt_service_buffer)); 279bdc352b1SMatthias Ringwald gatt_create_sdp_record(gatt_service_buffer, 0x10001, ATT_SERVICE_GATT_SERVICE_START_HANDLE, ATT_SERVICE_GATT_SERVICE_END_HANDLE); 280bdc352b1SMatthias Ringwald sdp_register_service(gatt_service_buffer); 281bdc352b1SMatthias Ringwald printf("SDP service record size: %u\n", de_get_len(gatt_service_buffer)); 282bdc352b1SMatthias Ringwald #endif 283bdc352b1SMatthias Ringwald 284bdc352b1SMatthias Ringwald gap_set_local_name("SPP and LE Counter 00:00:00:00:00:00"); 285bdc352b1SMatthias Ringwald gap_ssp_set_io_capability(SSP_IO_CAPABILITY_DISPLAY_YES_NO); 286bdc352b1SMatthias Ringwald gap_discoverable_control(1); 287bdc352b1SMatthias Ringwald 288bdc352b1SMatthias Ringwald // setup SM: Display only 289bdc352b1SMatthias Ringwald sm_init(); 290bdc352b1SMatthias Ringwald 291bdc352b1SMatthias Ringwald // setup ATT server 292bdc352b1SMatthias Ringwald att_server_init(profile_data, att_read_callback, att_write_callback); 293bdc352b1SMatthias Ringwald 294bdc352b1SMatthias Ringwald // register for HCI events 295bdc352b1SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 296bdc352b1SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 297bdc352b1SMatthias Ringwald 298bdc352b1SMatthias Ringwald // register for ATT events 299bdc352b1SMatthias Ringwald att_server_register_packet_handler(packet_handler); 300bdc352b1SMatthias Ringwald 301bdc352b1SMatthias Ringwald // setup advertisements 302bdc352b1SMatthias Ringwald uint16_t adv_int_min = 0x0030; 303bdc352b1SMatthias Ringwald uint16_t adv_int_max = 0x0030; 304bdc352b1SMatthias Ringwald uint8_t adv_type = 0; 305bdc352b1SMatthias Ringwald bd_addr_t null_addr; 306bdc352b1SMatthias Ringwald memset(null_addr, 0, 6); 307bdc352b1SMatthias Ringwald gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00); 308bdc352b1SMatthias Ringwald gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data); 309bdc352b1SMatthias Ringwald gap_advertisements_enable(1); 310bdc352b1SMatthias Ringwald 311bdc352b1SMatthias Ringwald // set one-shot timer 312bdc352b1SMatthias Ringwald heartbeat.process = &heartbeat_handler; 313bdc352b1SMatthias Ringwald btstack_run_loop_set_timer(&heartbeat, HEARTBEAT_PERIOD_MS); 314bdc352b1SMatthias Ringwald btstack_run_loop_add_timer(&heartbeat); 315bdc352b1SMatthias Ringwald 316bdc352b1SMatthias Ringwald // beat once 317bdc352b1SMatthias Ringwald beat(); 318bdc352b1SMatthias Ringwald 319bdc352b1SMatthias Ringwald // turn on! 320bdc352b1SMatthias Ringwald hci_power_control(HCI_POWER_ON); 321bdc352b1SMatthias Ringwald 322bdc352b1SMatthias Ringwald return 0; 323bdc352b1SMatthias Ringwald } 324bdc352b1SMatthias Ringwald /* LISTING_END */ 325bdc352b1SMatthias Ringwald /* EXAMPLE_END */ 326