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 "ble/gatt-service/nordic_spp_service_server.h" 65ebdf3c68SMilanka Ringwald 66*a63a688aSMatthias Ringwald // nordic_spp_le_streamer.gatt contains the declaration of the provided GATT Services + Characteristics 67*a63a688aSMatthias Ringwald // nordic_spp_le_streamer.h contains the binary representation of nordic_spp_le_streamer.gatt 68*a63a688aSMatthias Ringwald // it is generated by the build system by calling: $BTSTACK_ROOT/tool/compile_gatt.py nordic_spp_le_streamer.gatt nordic_spp_le_streamer.h 69*a63a688aSMatthias Ringwald // it needs to be regenerated when the GATT Database declared in nordic_spp_le_streamer.gatt file is modified 70*a63a688aSMatthias Ringwald #include "nordic_spp_le_streamer.h" 71*a63a688aSMatthias Ringwald 72ebdf3c68SMilanka Ringwald #define REPORT_INTERVAL_MS 3000 73ebdf3c68SMilanka Ringwald #define MAX_NR_CONNECTIONS 3 74ebdf3c68SMilanka Ringwald 75ebdf3c68SMilanka Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 76ebdf3c68SMilanka Ringwald 77ebdf3c68SMilanka Ringwald const uint8_t adv_data[] = { 78ebdf3c68SMilanka Ringwald // Flags general discoverable, BR/EDR not supported 79ebdf3c68SMilanka Ringwald 2, BLUETOOTH_DATA_TYPE_FLAGS, 0x06, 80ebdf3c68SMilanka Ringwald // Name 81ba7944beSMilanka Ringwald 8, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'n', 'R', 'F',' ', 'S', 'P', 'P', 82ebdf3c68SMilanka Ringwald // UUID ... 834163d2ebSMilanka Ringwald 17, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_128_BIT_SERVICE_CLASS_UUIDS, 0x9e, 0xca, 0xdc, 0x24, 0xe, 0xe5, 0xa9, 0xe0, 0x93, 0xf3, 0xa3, 0xb5, 0x1, 0x0, 0x40, 0x6e, 84ebdf3c68SMilanka Ringwald }; 85ebdf3c68SMilanka Ringwald const uint8_t adv_data_len = sizeof(adv_data); 86ebdf3c68SMilanka Ringwald 87ebdf3c68SMilanka Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 88ebdf3c68SMilanka Ringwald 89ebdf3c68SMilanka Ringwald // support for multiple clients 90ebdf3c68SMilanka Ringwald typedef struct { 91ebdf3c68SMilanka Ringwald char name; 92ebdf3c68SMilanka Ringwald int le_notification_enabled; 93ebdf3c68SMilanka Ringwald hci_con_handle_t connection_handle; 94ebdf3c68SMilanka Ringwald int counter; 95ebdf3c68SMilanka Ringwald char test_data[200]; 96ebdf3c68SMilanka Ringwald int test_data_len; 97ebdf3c68SMilanka Ringwald uint32_t test_data_sent; 98ebdf3c68SMilanka Ringwald uint32_t test_data_start; 99ebdf3c68SMilanka Ringwald btstack_context_callback_registration_t send_request; 100ebdf3c68SMilanka Ringwald } nordic_spp_le_streamer_connection_t; 101ebdf3c68SMilanka Ringwald 102ebdf3c68SMilanka Ringwald static nordic_spp_le_streamer_connection_t nordic_spp_le_streamer_connections[MAX_NR_CONNECTIONS]; 103ebdf3c68SMilanka Ringwald 104ebdf3c68SMilanka Ringwald // round robin sending 105ebdf3c68SMilanka Ringwald static int connection_index; 106ebdf3c68SMilanka Ringwald 107ebdf3c68SMilanka Ringwald static void init_connections(void){ 108ebdf3c68SMilanka Ringwald // track connections 109ebdf3c68SMilanka Ringwald int i; 110ebdf3c68SMilanka Ringwald for (i=0;i<MAX_NR_CONNECTIONS;i++){ 111ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connections[i].connection_handle = HCI_CON_HANDLE_INVALID; 112ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connections[i].name = 'A' + i; 113ebdf3c68SMilanka Ringwald } 114ebdf3c68SMilanka Ringwald } 115ebdf3c68SMilanka Ringwald 116ebdf3c68SMilanka Ringwald static nordic_spp_le_streamer_connection_t * connection_for_conn_handle(hci_con_handle_t conn_handle){ 117ebdf3c68SMilanka Ringwald int i; 118ebdf3c68SMilanka Ringwald for (i=0;i<MAX_NR_CONNECTIONS;i++){ 119ebdf3c68SMilanka Ringwald if (nordic_spp_le_streamer_connections[i].connection_handle == conn_handle) return &nordic_spp_le_streamer_connections[i]; 120ebdf3c68SMilanka Ringwald } 121ebdf3c68SMilanka Ringwald return NULL; 122ebdf3c68SMilanka Ringwald } 123ebdf3c68SMilanka Ringwald 124ebdf3c68SMilanka Ringwald static void next_connection_index(void){ 125ebdf3c68SMilanka Ringwald connection_index++; 126ebdf3c68SMilanka Ringwald if (connection_index == MAX_NR_CONNECTIONS){ 127ebdf3c68SMilanka Ringwald connection_index = 0; 128ebdf3c68SMilanka Ringwald } 129ebdf3c68SMilanka Ringwald } 130ebdf3c68SMilanka Ringwald 131ebdf3c68SMilanka Ringwald /* 132ebdf3c68SMilanka Ringwald * @section Track throughput 133ebdf3c68SMilanka Ringwald * @text We calculate the throughput by setting a start time and measuring the amount of 134ebdf3c68SMilanka Ringwald * data sent. After a configurable REPORT_INTERVAL_MS, we print the throughput in kB/s 135ebdf3c68SMilanka Ringwald * and reset the counter and start time. 136ebdf3c68SMilanka Ringwald */ 137ebdf3c68SMilanka Ringwald 138ebdf3c68SMilanka Ringwald /* LISTING_START(tracking): Tracking throughput */ 139ebdf3c68SMilanka Ringwald 140ebdf3c68SMilanka Ringwald static void test_reset(nordic_spp_le_streamer_connection_t * context){ 141ebdf3c68SMilanka Ringwald context->test_data_start = btstack_run_loop_get_time_ms(); 142ebdf3c68SMilanka Ringwald context->test_data_sent = 0; 143ebdf3c68SMilanka Ringwald } 144ebdf3c68SMilanka Ringwald 145ebdf3c68SMilanka Ringwald static void test_track_sent(nordic_spp_le_streamer_connection_t * context, int bytes_sent){ 146ebdf3c68SMilanka Ringwald context->test_data_sent += bytes_sent; 147ebdf3c68SMilanka Ringwald // evaluate 148ebdf3c68SMilanka Ringwald uint32_t now = btstack_run_loop_get_time_ms(); 149ebdf3c68SMilanka Ringwald uint32_t time_passed = now - context->test_data_start; 150ebdf3c68SMilanka Ringwald if (time_passed < REPORT_INTERVAL_MS) return; 151ebdf3c68SMilanka Ringwald // print speed 152ebdf3c68SMilanka Ringwald int bytes_per_second = context->test_data_sent * 1000 / time_passed; 153ebdf3c68SMilanka 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); 154ebdf3c68SMilanka Ringwald 155ebdf3c68SMilanka Ringwald // restart 156ebdf3c68SMilanka Ringwald context->test_data_start = now; 157ebdf3c68SMilanka Ringwald context->test_data_sent = 0; 158ebdf3c68SMilanka Ringwald } 159ebdf3c68SMilanka Ringwald /* LISTING_END(tracking): Tracking throughput */ 160ebdf3c68SMilanka Ringwald 161ebdf3c68SMilanka Ringwald /* 162ebdf3c68SMilanka Ringwald * @section Packet Handler 163ebdf3c68SMilanka Ringwald * 164ebdf3c68SMilanka Ringwald * @text The packet handler is used to stop the notifications and reset the MTU on connect 165ebdf3c68SMilanka Ringwald * It would also be a good place to request the connection parameter update as indicated 166ebdf3c68SMilanka Ringwald * in the commented code block. 167ebdf3c68SMilanka Ringwald */ 168ebdf3c68SMilanka Ringwald 169ebdf3c68SMilanka Ringwald /* LISTING_START(packetHandler): Packet Handler */ 170ebdf3c68SMilanka Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 171ebdf3c68SMilanka Ringwald UNUSED(channel); 172ebdf3c68SMilanka Ringwald UNUSED(size); 173ebdf3c68SMilanka Ringwald 174ebdf3c68SMilanka Ringwald int mtu; 175ebdf3c68SMilanka Ringwald uint16_t conn_interval; 176ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context; 177ebdf3c68SMilanka Ringwald switch (packet_type) { 178ebdf3c68SMilanka Ringwald case HCI_EVENT_PACKET: 179ebdf3c68SMilanka Ringwald switch (hci_event_packet_get_type(packet)) { 180ebdf3c68SMilanka Ringwald case BTSTACK_EVENT_STATE: 181ebdf3c68SMilanka Ringwald // BTstack activated, get started 182ebdf3c68SMilanka Ringwald if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING) { 183ebdf3c68SMilanka Ringwald printf("To start the streaming, please run the AMB2621 Toolbox to connect.\n"); 184ebdf3c68SMilanka Ringwald } 185ebdf3c68SMilanka Ringwald break; 186ebdf3c68SMilanka Ringwald case HCI_EVENT_DISCONNECTION_COMPLETE: 187ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(hci_event_disconnection_complete_get_connection_handle(packet)); 188ebdf3c68SMilanka Ringwald if (!context) break; 189ebdf3c68SMilanka Ringwald // free connection 190ebdf3c68SMilanka Ringwald printf("%c: Disconnect, reason %02x\n", context->name, hci_event_disconnection_complete_get_reason(packet)); 191ebdf3c68SMilanka Ringwald context->le_notification_enabled = 0; 192ebdf3c68SMilanka Ringwald context->connection_handle = HCI_CON_HANDLE_INVALID; 193ebdf3c68SMilanka Ringwald break; 194ebdf3c68SMilanka Ringwald case HCI_EVENT_LE_META: 195ebdf3c68SMilanka Ringwald switch (hci_event_le_meta_get_subevent_code(packet)) { 196ebdf3c68SMilanka Ringwald case HCI_SUBEVENT_LE_CONNECTION_COMPLETE: 197ebdf3c68SMilanka Ringwald // setup new 198ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(HCI_CON_HANDLE_INVALID); 199ebdf3c68SMilanka Ringwald if (!context) break; 200ebdf3c68SMilanka Ringwald context->counter = 'A'; 201ebdf3c68SMilanka Ringwald context->test_data_len = ATT_DEFAULT_MTU - 4; // -1 for nordic 0x01 packet type 202ebdf3c68SMilanka Ringwald context->connection_handle = hci_subevent_le_connection_complete_get_connection_handle(packet); 203ebdf3c68SMilanka Ringwald // print connection parameters (without using float operations) 204ebdf3c68SMilanka Ringwald conn_interval = hci_subevent_le_connection_complete_get_conn_interval(packet); 205ebdf3c68SMilanka Ringwald printf("%c: Connection Interval: %u.%02u ms\n", context->name, conn_interval * 125 / 100, 25 * (conn_interval & 3)); 206ebdf3c68SMilanka Ringwald printf("%c: Connection Latency: %u\n", context->name, hci_subevent_le_connection_complete_get_conn_latency(packet)); 207ebdf3c68SMilanka Ringwald break; 208ebdf3c68SMilanka Ringwald } 209ebdf3c68SMilanka Ringwald break; 210ebdf3c68SMilanka Ringwald case ATT_EVENT_MTU_EXCHANGE_COMPLETE: 211ebdf3c68SMilanka Ringwald mtu = att_event_mtu_exchange_complete_get_MTU(packet) - 3; 212ebdf3c68SMilanka Ringwald context = connection_for_conn_handle(att_event_mtu_exchange_complete_get_handle(packet)); 213ebdf3c68SMilanka Ringwald if (!context) break; 214ebdf3c68SMilanka Ringwald context->test_data_len = btstack_min(mtu - 3, sizeof(context->test_data)); 215ebdf3c68SMilanka Ringwald printf("%c: ATT MTU = %u => use test data of len %u\n", context->name, mtu, context->test_data_len); 216ebdf3c68SMilanka Ringwald break; 217ebdf3c68SMilanka Ringwald default: 218ebdf3c68SMilanka Ringwald break; 219ebdf3c68SMilanka Ringwald } 220ebdf3c68SMilanka Ringwald } 221ebdf3c68SMilanka Ringwald } 222ebdf3c68SMilanka Ringwald 223ebdf3c68SMilanka Ringwald /* LISTING_END */ 224ebdf3c68SMilanka Ringwald /* 225ebdf3c68SMilanka Ringwald * @section Streamer 226ebdf3c68SMilanka Ringwald * 227ebdf3c68SMilanka Ringwald * @text The streamer function checks if notifications are enabled and if a notification can be sent now. 228ebdf3c68SMilanka Ringwald * It creates some test data - a single letter that gets increased every time - and tracks the data sent. 229ebdf3c68SMilanka Ringwald */ 230ebdf3c68SMilanka Ringwald 231ebdf3c68SMilanka Ringwald /* LISTING_START(streamer): Streaming code */ 232ebdf3c68SMilanka Ringwald static void nordic_can_send(void * some_context){ 233ebdf3c68SMilanka Ringwald UNUSED(some_context); 234ebdf3c68SMilanka Ringwald 235ebdf3c68SMilanka Ringwald // find next active streaming connection 236ebdf3c68SMilanka Ringwald int old_connection_index = connection_index; 237ebdf3c68SMilanka Ringwald while (1){ 238ebdf3c68SMilanka Ringwald // active found? 239ebdf3c68SMilanka Ringwald if ((nordic_spp_le_streamer_connections[connection_index].connection_handle != HCI_CON_HANDLE_INVALID) && 240ebdf3c68SMilanka Ringwald (nordic_spp_le_streamer_connections[connection_index].le_notification_enabled)) break; 241ebdf3c68SMilanka Ringwald 242ebdf3c68SMilanka Ringwald // check next 243ebdf3c68SMilanka Ringwald next_connection_index(); 244ebdf3c68SMilanka Ringwald 245ebdf3c68SMilanka Ringwald // none found 246ebdf3c68SMilanka Ringwald if (connection_index == old_connection_index) return; 247ebdf3c68SMilanka Ringwald } 248ebdf3c68SMilanka Ringwald 249ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context = &nordic_spp_le_streamer_connections[connection_index]; 250ebdf3c68SMilanka Ringwald 251ebdf3c68SMilanka Ringwald // create test data 252ebdf3c68SMilanka Ringwald context->counter++; 253ebdf3c68SMilanka Ringwald if (context->counter > 'Z') context->counter = 'A'; 254ebdf3c68SMilanka Ringwald memset(context->test_data, context->counter, context->test_data_len); 255ebdf3c68SMilanka Ringwald 256ebdf3c68SMilanka Ringwald // send 257ebdf3c68SMilanka Ringwald nordic_spp_service_server_send(context->connection_handle, (uint8_t*) context->test_data, context->test_data_len); 258ebdf3c68SMilanka Ringwald 259ebdf3c68SMilanka Ringwald // track 260ebdf3c68SMilanka Ringwald test_track_sent(context, context->test_data_len); 261ebdf3c68SMilanka Ringwald 262ebdf3c68SMilanka Ringwald // request next send event 263ebdf3c68SMilanka Ringwald nordic_spp_service_server_request_can_send_now(&context->send_request, context->connection_handle); 264ebdf3c68SMilanka Ringwald 265ebdf3c68SMilanka Ringwald // check next 266ebdf3c68SMilanka Ringwald next_connection_index(); 267ebdf3c68SMilanka Ringwald } 268ebdf3c68SMilanka Ringwald /* LISTING_END */ 269ebdf3c68SMilanka Ringwald 270ebdf3c68SMilanka Ringwald static void nordic_data_received(hci_con_handle_t tx_con_handle, const uint8_t * data, uint16_t size){ 271ebdf3c68SMilanka Ringwald nordic_spp_le_streamer_connection_t * context = connection_for_conn_handle(tx_con_handle); 272ebdf3c68SMilanka Ringwald 273ebdf3c68SMilanka Ringwald if (!context) return; 274ebdf3c68SMilanka Ringwald 275ebdf3c68SMilanka Ringwald if (size == 0 && context->le_notification_enabled == 0){ 276ebdf3c68SMilanka Ringwald context->le_notification_enabled = 1; 277ebdf3c68SMilanka Ringwald test_reset(context); 278ebdf3c68SMilanka Ringwald context->send_request.callback = &nordic_can_send; 279ebdf3c68SMilanka Ringwald nordic_spp_service_server_request_can_send_now(&context->send_request, context->connection_handle); 280ebdf3c68SMilanka Ringwald } else { 281ebdf3c68SMilanka Ringwald printf("RECV: "); 282ebdf3c68SMilanka Ringwald printf_hexdump(data, size); 283ebdf3c68SMilanka Ringwald test_track_sent(context, size); 284ebdf3c68SMilanka Ringwald } 285ebdf3c68SMilanka Ringwald } 286ebdf3c68SMilanka Ringwald 287ebdf3c68SMilanka Ringwald int btstack_main(void); 288ba7944beSMilanka Ringwald int btstack_main(void){ 289ebdf3c68SMilanka Ringwald // register for HCI events 290ebdf3c68SMilanka Ringwald hci_event_callback_registration.callback = &packet_handler; 291ebdf3c68SMilanka Ringwald hci_add_event_handler(&hci_event_callback_registration); 292ebdf3c68SMilanka Ringwald 293ebdf3c68SMilanka Ringwald l2cap_init(); 294ebdf3c68SMilanka Ringwald 295ebdf3c68SMilanka Ringwald // setup LE device DB 296ebdf3c68SMilanka Ringwald le_device_db_init(); 297ebdf3c68SMilanka Ringwald 298ebdf3c68SMilanka Ringwald // setup SM: Display only 299ebdf3c68SMilanka Ringwald sm_init(); 300ebdf3c68SMilanka Ringwald 301ebdf3c68SMilanka Ringwald // setup ATT server 302ebdf3c68SMilanka Ringwald att_server_init(profile_data, NULL, NULL); 303ebdf3c68SMilanka Ringwald 304ebdf3c68SMilanka Ringwald // setup Nordic SPP service 305ebdf3c68SMilanka Ringwald nordic_spp_service_server_init(&nordic_data_received); 306ebdf3c68SMilanka Ringwald 307ebdf3c68SMilanka Ringwald // setup advertisements 308ebdf3c68SMilanka Ringwald uint16_t adv_int_min = 0x0030; 309ebdf3c68SMilanka Ringwald uint16_t adv_int_max = 0x0030; 310ebdf3c68SMilanka Ringwald uint8_t adv_type = 0; 311ebdf3c68SMilanka Ringwald bd_addr_t null_addr; 312ebdf3c68SMilanka Ringwald memset(null_addr, 0, 6); 313ebdf3c68SMilanka Ringwald gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00); 314ebdf3c68SMilanka Ringwald gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data); 315ebdf3c68SMilanka Ringwald gap_advertisements_enable(1); 316ebdf3c68SMilanka Ringwald 317ebdf3c68SMilanka Ringwald // init client state 318ebdf3c68SMilanka Ringwald init_connections(); 319ebdf3c68SMilanka Ringwald 320ebdf3c68SMilanka Ringwald // turn on! 321ebdf3c68SMilanka Ringwald hci_power_control(HCI_POWER_ON); 322ebdf3c68SMilanka Ringwald 323ebdf3c68SMilanka Ringwald return 0; 324ebdf3c68SMilanka Ringwald } 325ebdf3c68SMilanka Ringwald /* EXAMPLE_END */ 326