1ebdf3c68SMilanka Ringwald /* 2ebdf3c68SMilanka Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3ebdf3c68SMilanka Ringwald * 4ebdf3c68SMilanka Ringwald * Redistribution and use in source and binary forms, with or without 5ebdf3c68SMilanka Ringwald * modification, are permitted provided that the following conditions 6ebdf3c68SMilanka Ringwald * are met: 7ebdf3c68SMilanka Ringwald * 8ebdf3c68SMilanka Ringwald * 1. Redistributions of source code must retain the above copyright 9ebdf3c68SMilanka Ringwald * notice, this list of conditions and the following disclaimer. 10ebdf3c68SMilanka Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11ebdf3c68SMilanka Ringwald * notice, this list of conditions and the following disclaimer in the 12ebdf3c68SMilanka Ringwald * documentation and/or other materials provided with the distribution. 13ebdf3c68SMilanka Ringwald * 3. Neither the name of the copyright holders nor the names of 14ebdf3c68SMilanka Ringwald * contributors may be used to endorse or promote products derived 15ebdf3c68SMilanka Ringwald * from this software without specific prior written permission. 16ebdf3c68SMilanka Ringwald * 4. Any redistribution, use, or modification is done solely for 17ebdf3c68SMilanka Ringwald * personal benefit and not for any commercial purpose or for 18ebdf3c68SMilanka Ringwald * monetary gain. 19ebdf3c68SMilanka Ringwald * 20ebdf3c68SMilanka Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21ebdf3c68SMilanka Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22ebdf3c68SMilanka Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23ebdf3c68SMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24ebdf3c68SMilanka Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25ebdf3c68SMilanka Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26ebdf3c68SMilanka Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27ebdf3c68SMilanka Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28ebdf3c68SMilanka Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29ebdf3c68SMilanka Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30ebdf3c68SMilanka Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31ebdf3c68SMilanka Ringwald * SUCH DAMAGE. 32ebdf3c68SMilanka Ringwald * 33ebdf3c68SMilanka Ringwald * Please inquire about commercial licensing options at 34ebdf3c68SMilanka Ringwald * [email protected] 35ebdf3c68SMilanka Ringwald * 36ebdf3c68SMilanka Ringwald */ 37ebdf3c68SMilanka Ringwald 38ebdf3c68SMilanka Ringwald #define __BTSTACK_FILE__ "nordic_spp_le_streamer.c" 39ebdf3c68SMilanka Ringwald 40ebdf3c68SMilanka Ringwald // ***************************************************************************** 41ebdf3c68SMilanka Ringwald /* EXAMPLE_START(nordic_spp_le_streamer): LE Streamer - Stream data over GATT. 42ebdf3c68SMilanka Ringwald * 43ebdf3c68SMilanka Ringwald * @text All newer operating systems provide GATT Client functionality. 44ebdf3c68SMilanka Ringwald * This example shows how to get a maximal throughput via BLE: 45ebdf3c68SMilanka Ringwald * - send whenever possible, 46ebdf3c68SMilanka Ringwald * - use the max ATT MTU. 47ebdf3c68SMilanka Ringwald * 48ebdf3c68SMilanka Ringwald * @text In theory, we should also update the connection parameters, but we already get 49ebdf3c68SMilanka Ringwald * a connection interval of 30 ms and there's no public way to use a shorter 50ebdf3c68SMilanka Ringwald * interval with iOS (if we're not implementing an HID device). 51ebdf3c68SMilanka Ringwald * 52ebdf3c68SMilanka Ringwald * @text Note: To start the streaming, run the example. 53ebdf3c68SMilanka Ringwald * On remote device use some GATT Explorer, e.g. LightBlue, BLExplr to enable notifications. 54ebdf3c68SMilanka Ringwald */ 55ebdf3c68SMilanka Ringwald // ***************************************************************************** 56ebdf3c68SMilanka Ringwald 57ebdf3c68SMilanka Ringwald #include <inttypes.h> 58ebdf3c68SMilanka Ringwald #include <stdint.h> 59ebdf3c68SMilanka Ringwald #include <stdio.h> 60ebdf3c68SMilanka Ringwald #include <stdlib.h> 61ebdf3c68SMilanka Ringwald #include <string.h> 62ebdf3c68SMilanka Ringwald 63ebdf3c68SMilanka Ringwald #include "btstack.h" 64ebdf3c68SMilanka Ringwald #include "nordic_spp_le_streamer.h" 65ebdf3c68SMilanka Ringwald #include "ble/gatt-service/nordic_spp_service_server.h" 66ebdf3c68SMilanka Ringwald 67ebdf3c68SMilanka Ringwald #define REPORT_INTERVAL_MS 3000 68ebdf3c68SMilanka Ringwald #define MAX_NR_CONNECTIONS 3 69ebdf3c68SMilanka Ringwald 70ebdf3c68SMilanka Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 71ebdf3c68SMilanka Ringwald 72ebdf3c68SMilanka Ringwald const uint8_t adv_data[] = { 73ebdf3c68SMilanka Ringwald // Flags general discoverable, BR/EDR not supported 74ebdf3c68SMilanka Ringwald 2, BLUETOOTH_DATA_TYPE_FLAGS, 0x06, 75ebdf3c68SMilanka Ringwald // Name 76*ba7944beSMilanka Ringwald 8, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'n', 'R', 'F',' ', 'S', 'P', 'P', 77ebdf3c68SMilanka Ringwald // UUID ... 78ebdf3c68SMilanka Ringwald 17, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS, 0x6e, 0x40, 0x0, 0x1, 0xc3, 0x52, 0x11, 0xe5, 0x95, 0x3d, 0x0, 0x2, 0xa5, 0xd5, 0xc5, 0x1b, 79ebdf3c68SMilanka Ringwald }; 80ebdf3c68SMilanka Ringwald const uint8_t adv_data_len = sizeof(adv_data); 81ebdf3c68SMilanka Ringwald 82ebdf3c68SMilanka Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 83ebdf3c68SMilanka Ringwald 84ebdf3c68SMilanka Ringwald // support for multiple clients 85ebdf3c68SMilanka Ringwald typedef struct { 86ebdf3c68SMilanka Ringwald char name; 87ebdf3c68SMilanka Ringwald int le_notification_enabled; 88ebdf3c68SMilanka Ringwald hci_con_handle_t connection_handle; 89ebdf3c68SMilanka Ringwald int counter; 90ebdf3c68SMilanka Ringwald char test_data[200]; 91ebdf3c68SMilanka Ringwald int test_data_len; 92ebdf3c68SMilanka Ringwald uint32_t test_data_sent; 93ebdf3c68SMilanka Ringwald uint32_t test_data_start; 94ebdf3c68SMilanka Ringwald btstack_context_callback_registration_t send_request; 95ebdf3c68SMilanka Ringwald } nordic_spp_le_streamer_connection_t; 96ebdf3c68SMilanka Ringwald 97ebdf3c68SMilanka Ringwald static nordic_spp_le_streamer_connection_t nordic_spp_le_streamer_connections[MAX_NR_CONNECTIONS]; 98ebdf3c68SMilanka Ringwald 99ebdf3c68SMilanka Ringwald // round robin sending 100ebdf3c68SMilanka Ringwald static int connection_index; 101ebdf3c68SMilanka Ringwald 102ebdf3c68SMilanka Ringwald static void init_connections(void){ 103ebdf3c68SMilanka Ringwald // track connections 104ebdf3c68SMilanka Ringwald int i; 105ebdf3c68SMilanka Ringwald for (i=0;i<MAX_NR_CONNECTIONS;i++){ 106ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connections[i].connection_handle = HCI_CON_HANDLE_INVALID; 107ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connections[i].name = 'A' + i; 108ebdf3c68SMilanka Ringwald } 109ebdf3c68SMilanka Ringwald } 110ebdf3c68SMilanka Ringwald 111ebdf3c68SMilanka Ringwald static nordic_spp_le_streamer_connection_t * connection_for_conn_handle(hci_con_handle_t conn_handle){ 112ebdf3c68SMilanka Ringwald int i; 113ebdf3c68SMilanka Ringwald for (i=0;i<MAX_NR_CONNECTIONS;i++){ 114ebdf3c68SMilanka Ringwald if (nordic_spp_le_streamer_connections[i].connection_handle == conn_handle) return &nordic_spp_le_streamer_connections[i]; 115ebdf3c68SMilanka Ringwald } 116ebdf3c68SMilanka Ringwald return NULL; 117ebdf3c68SMilanka Ringwald } 118ebdf3c68SMilanka Ringwald 119ebdf3c68SMilanka Ringwald static void next_connection_index(void){ 120ebdf3c68SMilanka Ringwald connection_index++; 121ebdf3c68SMilanka Ringwald if (connection_index == MAX_NR_CONNECTIONS){ 122ebdf3c68SMilanka Ringwald connection_index = 0; 123ebdf3c68SMilanka Ringwald } 124ebdf3c68SMilanka Ringwald } 125ebdf3c68SMilanka Ringwald 126ebdf3c68SMilanka Ringwald /* 127ebdf3c68SMilanka Ringwald * @section Track throughput 128ebdf3c68SMilanka Ringwald * @text We calculate the throughput by setting a start time and measuring the amount of 129ebdf3c68SMilanka Ringwald * data sent. After a configurable REPORT_INTERVAL_MS, we print the throughput in kB/s 130ebdf3c68SMilanka Ringwald * and reset the counter and start time. 131ebdf3c68SMilanka Ringwald */ 132ebdf3c68SMilanka Ringwald 133ebdf3c68SMilanka Ringwald /* LISTING_START(tracking): Tracking throughput */ 134ebdf3c68SMilanka Ringwald 135ebdf3c68SMilanka Ringwald static void test_reset(nordic_spp_le_streamer_connection_t * context){ 136ebdf3c68SMilanka Ringwald context->test_data_start = btstack_run_loop_get_time_ms(); 137ebdf3c68SMilanka Ringwald context->test_data_sent = 0; 138ebdf3c68SMilanka Ringwald } 139ebdf3c68SMilanka Ringwald 140ebdf3c68SMilanka Ringwald static void test_track_sent(nordic_spp_le_streamer_connection_t * context, int bytes_sent){ 141ebdf3c68SMilanka Ringwald context->test_data_sent += bytes_sent; 142ebdf3c68SMilanka Ringwald // evaluate 143ebdf3c68SMilanka Ringwald uint32_t now = btstack_run_loop_get_time_ms(); 144ebdf3c68SMilanka Ringwald uint32_t time_passed = now - context->test_data_start; 145ebdf3c68SMilanka Ringwald if (time_passed < REPORT_INTERVAL_MS) return; 146ebdf3c68SMilanka Ringwald // print speed 147ebdf3c68SMilanka Ringwald int bytes_per_second = context->test_data_sent * 1000 / time_passed; 148ebdf3c68SMilanka Ringwald printf("%c: %"PRIu32" bytes sent-> %u.%03u kB/s\n", context->name, context->test_data_sent, bytes_per_second / 1000, bytes_per_second % 1000); 149ebdf3c68SMilanka Ringwald 150ebdf3c68SMilanka Ringwald // restart 151ebdf3c68SMilanka Ringwald context->test_data_start = now; 152ebdf3c68SMilanka Ringwald context->test_data_sent = 0; 153ebdf3c68SMilanka Ringwald } 154ebdf3c68SMilanka Ringwald /* LISTING_END(tracking): Tracking throughput */ 155ebdf3c68SMilanka Ringwald 156ebdf3c68SMilanka Ringwald /* 157ebdf3c68SMilanka Ringwald * @section Packet Handler 158ebdf3c68SMilanka Ringwald * 159ebdf3c68SMilanka Ringwald * @text The packet handler is used to stop the notifications and reset the MTU on connect 160ebdf3c68SMilanka Ringwald * It would also be a good place to request the connection parameter update as indicated 161ebdf3c68SMilanka Ringwald * in the commented code block. 162ebdf3c68SMilanka Ringwald */ 163ebdf3c68SMilanka Ringwald 164ebdf3c68SMilanka Ringwald /* LISTING_START(packetHandler): Packet Handler */ 165ebdf3c68SMilanka Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 166ebdf3c68SMilanka Ringwald UNUSED(channel); 167ebdf3c68SMilanka Ringwald UNUSED(size); 168ebdf3c68SMilanka Ringwald 169ebdf3c68SMilanka Ringwald int mtu; 170ebdf3c68SMilanka Ringwald uint16_t conn_interval; 171ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context; 172ebdf3c68SMilanka Ringwald switch (packet_type) { 173ebdf3c68SMilanka Ringwald case HCI_EVENT_PACKET: 174ebdf3c68SMilanka Ringwald switch (hci_event_packet_get_type(packet)) { 175ebdf3c68SMilanka Ringwald case BTSTACK_EVENT_STATE: 176ebdf3c68SMilanka Ringwald // BTstack activated, get started 177ebdf3c68SMilanka Ringwald if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) { 178ebdf3c68SMilanka Ringwald printf("To start the streaming, please run the AMB2621 Toolbox to connect.\n"); 179ebdf3c68SMilanka Ringwald } 180ebdf3c68SMilanka Ringwald break; 181ebdf3c68SMilanka Ringwald case HCI_EVENT_DISCONNECTION_COMPLETE: 182ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(hci_event_disconnection_complete_get_connection_handle(packet)); 183ebdf3c68SMilanka Ringwald if (!context) break; 184ebdf3c68SMilanka Ringwald // free connection 185ebdf3c68SMilanka Ringwald printf("%c: Disconnect, reason %02x\n", context->name, hci_event_disconnection_complete_get_reason(packet)); 186ebdf3c68SMilanka Ringwald context->le_notification_enabled = 0; 187ebdf3c68SMilanka Ringwald context->connection_handle = HCI_CON_HANDLE_INVALID; 188ebdf3c68SMilanka Ringwald break; 189ebdf3c68SMilanka Ringwald case HCI_EVENT_LE_META: 190ebdf3c68SMilanka Ringwald switch (hci_event_le_meta_get_subevent_code(packet)) { 191ebdf3c68SMilanka Ringwald case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: 192ebdf3c68SMilanka Ringwald // setup new 193ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(HCI_CON_HANDLE_INVALID); 194ebdf3c68SMilanka Ringwald if (!context) break; 195ebdf3c68SMilanka Ringwald context->counter = 'A'; 196ebdf3c68SMilanka Ringwald context->test_data_len = ATT_DEFAULT_MTU - 4; // -1 for nordic 0x01 packet type 197ebdf3c68SMilanka Ringwald context->connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet); 198ebdf3c68SMilanka Ringwald // print connection parameters (without using float operations) 199ebdf3c68SMilanka Ringwald conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet); 200ebdf3c68SMilanka Ringwald printf("%c: Connection Interval: %u.%02u ms\n", context->name, conn_interval * 125 / 100, 25 * (conn_interval & 3)); 201ebdf3c68SMilanka Ringwald printf("%c: Connection Latency: %u\n", context->name, hci_subevent_le_connection_complete_get_conn_latency(packet)); 202ebdf3c68SMilanka Ringwald break; 203ebdf3c68SMilanka Ringwald } 204ebdf3c68SMilanka Ringwald break; 205ebdf3c68SMilanka Ringwald case ATT_EVENT_MTU_EXCHANGE_COMPLETE: 206ebdf3c68SMilanka Ringwald mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3; 207ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(att_event_mtu_exchange_complete_get_handle(packet)); 208ebdf3c68SMilanka Ringwald if (!context) break; 209ebdf3c68SMilanka Ringwald context->test_data_len = btstack_min(mtu - 3, sizeof(context->test_data)); 210ebdf3c68SMilanka Ringwald printf("%c: ATT MTU = %u => use test data of len %u\n", context->name, mtu, context->test_data_len); 211ebdf3c68SMilanka Ringwald break; 212ebdf3c68SMilanka Ringwald default: 213ebdf3c68SMilanka Ringwald break; 214ebdf3c68SMilanka Ringwald } 215ebdf3c68SMilanka Ringwald } 216ebdf3c68SMilanka Ringwald } 217ebdf3c68SMilanka Ringwald 218ebdf3c68SMilanka Ringwald /* LISTING_END */ 219ebdf3c68SMilanka Ringwald /* 220ebdf3c68SMilanka Ringwald * @section Streamer 221ebdf3c68SMilanka Ringwald * 222ebdf3c68SMilanka Ringwald * @text The streamer function checks if notifications are enabled and if a notification can be sent now. 223ebdf3c68SMilanka Ringwald * It creates some test data - a single letter that gets increased every time - and tracks the data sent. 224ebdf3c68SMilanka Ringwald */ 225ebdf3c68SMilanka Ringwald 226ebdf3c68SMilanka Ringwald /* LISTING_START(streamer): Streaming code */ 227ebdf3c68SMilanka Ringwald static void nordic_can_send(void * some_context){ 228ebdf3c68SMilanka Ringwald UNUSED(some_context); 229ebdf3c68SMilanka Ringwald 230ebdf3c68SMilanka Ringwald // find next active streaming connection 231ebdf3c68SMilanka Ringwald int old_connection_index = connection_index; 232ebdf3c68SMilanka Ringwald while (1){ 233ebdf3c68SMilanka Ringwald // active found? 234ebdf3c68SMilanka Ringwald if ((nordic_spp_le_streamer_connections[connection_index].connection_handle != HCI_CON_HANDLE_INVALID) && 235ebdf3c68SMilanka Ringwald (nordic_spp_le_streamer_connections[connection_index].le_notification_enabled)) break; 236ebdf3c68SMilanka Ringwald 237ebdf3c68SMilanka Ringwald // check next 238ebdf3c68SMilanka Ringwald next_connection_index(); 239ebdf3c68SMilanka Ringwald 240ebdf3c68SMilanka Ringwald // none found 241ebdf3c68SMilanka Ringwald if (connection_index == old_connection_index) return; 242ebdf3c68SMilanka Ringwald } 243ebdf3c68SMilanka Ringwald 244ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context = &nordic_spp_le_streamer_connections[connection_index]; 245ebdf3c68SMilanka Ringwald 246ebdf3c68SMilanka Ringwald // create test data 247ebdf3c68SMilanka Ringwald context->counter++; 248ebdf3c68SMilanka Ringwald if (context->counter > 'Z') context->counter = 'A'; 249ebdf3c68SMilanka Ringwald memset(context->test_data, context->counter, context->test_data_len); 250ebdf3c68SMilanka Ringwald 251ebdf3c68SMilanka Ringwald // send 252ebdf3c68SMilanka Ringwald nordic_spp_service_server_send(context->connection_handle, (uint8_t*) context->test_data, context->test_data_len); 253ebdf3c68SMilanka Ringwald 254ebdf3c68SMilanka Ringwald // track 255ebdf3c68SMilanka Ringwald test_track_sent(context, context->test_data_len); 256ebdf3c68SMilanka Ringwald 257ebdf3c68SMilanka Ringwald // request next send event 258ebdf3c68SMilanka Ringwald nordic_spp_service_server_request_can_send_now(&context->send_request, context->connection_handle); 259ebdf3c68SMilanka Ringwald 260ebdf3c68SMilanka Ringwald // check next 261ebdf3c68SMilanka Ringwald next_connection_index(); 262ebdf3c68SMilanka Ringwald } 263ebdf3c68SMilanka Ringwald /* LISTING_END */ 264ebdf3c68SMilanka Ringwald 265ebdf3c68SMilanka Ringwald static void nordic_data_received(hci_con_handle_t tx_con_handle, const uint8_t * data, uint16_t size){ 266ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context = connection_for_conn_handle(tx_con_handle); 267ebdf3c68SMilanka Ringwald 268ebdf3c68SMilanka Ringwald if (!context) return; 269ebdf3c68SMilanka Ringwald 270ebdf3c68SMilanka Ringwald if (size == 0 && context->le_notification_enabled == 0){ 271ebdf3c68SMilanka Ringwald context->le_notification_enabled = 1; 272ebdf3c68SMilanka Ringwald test_reset(context); 273ebdf3c68SMilanka Ringwald context->send_request.callback = &nordic_can_send; 274ebdf3c68SMilanka Ringwald nordic_spp_service_server_request_can_send_now(&context->send_request, context->connection_handle); 275ebdf3c68SMilanka Ringwald } else { 276ebdf3c68SMilanka Ringwald printf("RECV: "); 277ebdf3c68SMilanka Ringwald printf_hexdump(data, size); 278ebdf3c68SMilanka Ringwald test_track_sent(context, size); 279ebdf3c68SMilanka Ringwald } 280ebdf3c68SMilanka Ringwald } 281ebdf3c68SMilanka Ringwald 282ebdf3c68SMilanka Ringwald int btstack_main(void); 283*ba7944beSMilanka Ringwald int btstack_main(void){ 284ebdf3c68SMilanka Ringwald // register for HCI events 285ebdf3c68SMilanka Ringwald hci_event_callback_registration.callback = &packet_handler; 286ebdf3c68SMilanka Ringwald hci_add_event_handler(&hci_event_callback_registration); 287ebdf3c68SMilanka Ringwald 288ebdf3c68SMilanka Ringwald l2cap_init(); 289ebdf3c68SMilanka Ringwald 290ebdf3c68SMilanka Ringwald // setup LE device DB 291ebdf3c68SMilanka Ringwald le_device_db_init(); 292ebdf3c68SMilanka Ringwald 293ebdf3c68SMilanka Ringwald // setup SM: Display only 294ebdf3c68SMilanka Ringwald sm_init(); 295ebdf3c68SMilanka Ringwald 296ebdf3c68SMilanka Ringwald // setup ATT server 297ebdf3c68SMilanka Ringwald att_server_init(profile_data, NULL, NULL); 298ebdf3c68SMilanka Ringwald 299ebdf3c68SMilanka Ringwald // setup Nordic SPP service 300ebdf3c68SMilanka Ringwald nordic_spp_service_server_init(&nordic_data_received); 301ebdf3c68SMilanka Ringwald 302ebdf3c68SMilanka Ringwald // setup advertisements 303ebdf3c68SMilanka Ringwald uint16_t adv_int_min = 0x0030; 304ebdf3c68SMilanka Ringwald uint16_t adv_int_max = 0x0030; 305ebdf3c68SMilanka Ringwald uint8_t adv_type = 0; 306ebdf3c68SMilanka Ringwald bd_addr_t null_addr; 307ebdf3c68SMilanka Ringwald memset(null_addr, 0, 6); 308ebdf3c68SMilanka Ringwald gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00); 309ebdf3c68SMilanka Ringwald gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data); 310ebdf3c68SMilanka Ringwald gap_advertisements_enable(1); 311ebdf3c68SMilanka Ringwald 312ebdf3c68SMilanka Ringwald // init client state 313ebdf3c68SMilanka Ringwald init_connections(); 314ebdf3c68SMilanka Ringwald 315ebdf3c68SMilanka Ringwald // turn on! 316ebdf3c68SMilanka Ringwald hci_power_control(HCI_POWER_ON); 317ebdf3c68SMilanka Ringwald 318ebdf3c68SMilanka Ringwald return 0; 319ebdf3c68SMilanka Ringwald } 320ebdf3c68SMilanka Ringwald /* EXAMPLE_END */ 321