xref: /btstack/example/sm_pairing_peripheral.c (revision 7c4db9dc71fe83e63b4bbabcdbd4b0df5a485ff0)
1d7ee901aSMatthias Ringwald /*
2d7ee901aSMatthias Ringwald  * Copyright (C) 2014 BlueKitchen GmbH
3d7ee901aSMatthias Ringwald  *
4d7ee901aSMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
5d7ee901aSMatthias Ringwald  * modification, are permitted provided that the following conditions
6d7ee901aSMatthias Ringwald  * are met:
7d7ee901aSMatthias Ringwald  *
8d7ee901aSMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
9d7ee901aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
10d7ee901aSMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11d7ee901aSMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
12d7ee901aSMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
13d7ee901aSMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
14d7ee901aSMatthias Ringwald  *    contributors may be used to endorse or promote products derived
15d7ee901aSMatthias Ringwald  *    from this software without specific prior written permission.
16d7ee901aSMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
17d7ee901aSMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
18d7ee901aSMatthias Ringwald  *    monetary gain.
19d7ee901aSMatthias Ringwald  *
20d7ee901aSMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
21d7ee901aSMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22d7ee901aSMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23d7ee901aSMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24d7ee901aSMatthias Ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25d7ee901aSMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26d7ee901aSMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27d7ee901aSMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28d7ee901aSMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29d7ee901aSMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30d7ee901aSMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31d7ee901aSMatthias Ringwald  * SUCH DAMAGE.
32d7ee901aSMatthias Ringwald  *
33d7ee901aSMatthias Ringwald  * Please inquire about commercial licensing options at
34d7ee901aSMatthias Ringwald  * [email protected]
35d7ee901aSMatthias Ringwald  *
36d7ee901aSMatthias Ringwald  */
37d7ee901aSMatthias Ringwald 
38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "sm_pairing_peripheral.c"
39ab2c6ae4SMatthias Ringwald 
40d7ee901aSMatthias Ringwald // *****************************************************************************
41ec8ae085SMilanka Ringwald /* EXAMPLE_START(sm_pairing_peripheral): LE Peripheral - Test Pairing Methods
42d7ee901aSMatthias Ringwald  *
43d7ee901aSMatthias Ringwald  * @text Depending on the Authentication requiremens and IO Capabilities,
44d7ee901aSMatthias Ringwald  * the pairing process uses different short and long term key generation method.
45d7ee901aSMatthias Ringwald  * This example helps explore the different options incl. LE Secure Connections.
46d7ee901aSMatthias Ringwald  */
47d7ee901aSMatthias Ringwald  // *****************************************************************************
48d7ee901aSMatthias Ringwald 
49d7ee901aSMatthias Ringwald #include <stdint.h>
50d7ee901aSMatthias Ringwald #include <stdio.h>
51d7ee901aSMatthias Ringwald #include <stdlib.h>
52d7ee901aSMatthias Ringwald #include <string.h>
53bace42efSMatthias Ringwald #include <inttypes.h>
54d7ee901aSMatthias Ringwald 
55d7ee901aSMatthias Ringwald #include "sm_pairing_peripheral.h"
56d7ee901aSMatthias Ringwald #include "btstack.h"
57d7ee901aSMatthias Ringwald 
58d7ee901aSMatthias Ringwald /* @section Main Application Setup
59d7ee901aSMatthias Ringwald  *
60d7ee901aSMatthias Ringwald  * @text Listing MainConfiguration shows main application code.
61d7ee901aSMatthias Ringwald  * It initializes L2CAP, the Security Manager and configures the ATT Server with the pre-compiled
62d7ee901aSMatthias Ringwald  * ATT Database generated from $sm_pairing_peripheral.gatt$. Finally, it configures the advertisements
63d7ee901aSMatthias Ringwald  * and boots the Bluetooth stack.
6473704aa9SMatthias Ringwald  * In this example, the Advertisement contains the Flags attribute, the device name, and a 16-bit (test) service 0x1111
65d7ee901aSMatthias Ringwald  * The flag 0x06 indicates: LE General Discoverable Mode and BR/EDR not supported.
66d7ee901aSMatthias Ringwald  * Various examples for IO Capabilites and Authentication Requirements are given below.
67d7ee901aSMatthias Ringwald  */
68d7ee901aSMatthias Ringwald 
6973704aa9SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup stack to advertise */
70d7ee901aSMatthias Ringwald static btstack_packet_callback_registration_t sm_event_callback_registration;
71d7ee901aSMatthias Ringwald 
72d7ee901aSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size);
73d7ee901aSMatthias Ringwald 
74d7ee901aSMatthias Ringwald const uint8_t adv_data[] = {
75d7ee901aSMatthias Ringwald     // Flags general discoverable, BR/EDR not supported
76bf85c285SMatthias Ringwald     0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x06,
77d7ee901aSMatthias Ringwald     // Name
78bf85c285SMatthias Ringwald     0x0b, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'S', 'M', ' ', 'P', 'a', 'i', 'r', 'i', 'n', 'g',
79bde654efSMatthias Ringwald     // Incomplete List of 16-bit Service Class UUIDs -- 1111 - only valid for testing!
80bde654efSMatthias Ringwald     0x03, BLUETOOTH_DATA_TYPE_INCOMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS, 0x11, 0x11,
81d7ee901aSMatthias Ringwald };
82d7ee901aSMatthias Ringwald const uint8_t adv_data_len = sizeof(adv_data);
83d7ee901aSMatthias Ringwald 
84d7ee901aSMatthias Ringwald static void sm_peripheral_setup(void){
85d7ee901aSMatthias Ringwald 
86d7ee901aSMatthias Ringwald     l2cap_init();
87d7ee901aSMatthias Ringwald 
88d7ee901aSMatthias Ringwald     // setup le device db
89d7ee901aSMatthias Ringwald     le_device_db_init();
90d7ee901aSMatthias Ringwald 
91d7ee901aSMatthias Ringwald     // setup SM: Display only
92d7ee901aSMatthias Ringwald     sm_init();
93d7ee901aSMatthias Ringwald 
943c3e5a84SMatthias Ringwald     // setup ATT server
953c3e5a84SMatthias Ringwald     att_server_init(profile_data, NULL, NULL);
963c3e5a84SMatthias Ringwald 
973c3e5a84SMatthias Ringwald     // setup GATT Client
983c3e5a84SMatthias Ringwald     gatt_client_init();
993c3e5a84SMatthias Ringwald 
1003c3e5a84SMatthias Ringwald     // setup advertisements
1013c3e5a84SMatthias Ringwald     uint16_t adv_int_min = 0x0030;
1023c3e5a84SMatthias Ringwald     uint16_t adv_int_max = 0x0030;
1033c3e5a84SMatthias Ringwald     uint8_t adv_type = 0;
1043c3e5a84SMatthias Ringwald     bd_addr_t null_addr;
1053c3e5a84SMatthias Ringwald     memset(null_addr, 0, 6);
1063c3e5a84SMatthias Ringwald     gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00);
1073c3e5a84SMatthias Ringwald     gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data);
1083c3e5a84SMatthias Ringwald     gap_advertisements_enable(1);
1093c3e5a84SMatthias Ringwald 
1103c3e5a84SMatthias Ringwald     // register for SM events
1113c3e5a84SMatthias Ringwald     sm_event_callback_registration.callback = &packet_handler;
1123c3e5a84SMatthias Ringwald     sm_add_event_handler(&sm_event_callback_registration);
1133c3e5a84SMatthias Ringwald 
1143c3e5a84SMatthias Ringwald     // register for ATT
1153c3e5a84SMatthias Ringwald     att_server_register_packet_handler(packet_handler);
1163c3e5a84SMatthias Ringwald 
1173c3e5a84SMatthias Ringwald 
1183c3e5a84SMatthias Ringwald     // Configuration
1193c3e5a84SMatthias Ringwald 
1203c3e5a84SMatthias Ringwald     // Enable mandatory authentication for GATT Client
1213c3e5a84SMatthias Ringwald     // - if un-encrypted connections are not supported, e.g. when connecting to own device, this enforces authentication
1223c3e5a84SMatthias Ringwald     // gatt_client_set_required_security_level(LEVEL_2);
1233c3e5a84SMatthias Ringwald 
124d7ee901aSMatthias Ringwald     /**
125d7ee901aSMatthias Ringwald      * Choose ONE of the following configurations
1263cdbe9dbSMatthias Ringwald      * Bonding is disabled to allow for repeated testing. It can be enabled by or'ing
1273cdbe9dbSMatthias Ringwald      * SM_AUTHREQ_BONDING to the authentication requirements like this:
1283cdbe9dbSMatthias Ringwald      * sm_set_authentication_requirements( X | SM_AUTHREQ_BONDING)
129d7ee901aSMatthias Ringwald      */
130d7ee901aSMatthias Ringwald 
131d7ee901aSMatthias Ringwald     // LE Legacy Pairing, Just Works
1324b8c611fSMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
1333cdbe9dbSMatthias Ringwald     // sm_set_authentication_requirements(0);
134d7ee901aSMatthias Ringwald 
135d7ee901aSMatthias Ringwald     // LE Legacy Pairing, Passkey entry initiator enter, responder (us) displays
136d7ee901aSMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
137d7ee901aSMatthias Ringwald     // sm_set_authentication_requirements(SM_AUTHREQ_MITM_PROTECTION);
1384b8c611fSMatthias Ringwald     // sm_use_fixed_passkey_in_display_role(123456);
139d7ee901aSMatthias Ringwald 
140d7ee901aSMatthias Ringwald #ifdef ENABLE_LE_SECURE_CONNECTIONS
1413cdbe9dbSMatthias Ringwald 
1423cdbe9dbSMatthias Ringwald     // enable LE Secure Connections Only mode - disables Legacy pairing
14332112218SMatthias Ringwald     // sm_set_secure_connections_only_mode(true);
1443cdbe9dbSMatthias Ringwald 
1453cdbe9dbSMatthias Ringwald     // LE Secure Connections, Just Works
14699c44ab2SMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_NO_INPUT_NO_OUTPUT);
147d7ee901aSMatthias Ringwald     // sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION);
148d7ee901aSMatthias Ringwald 
149d7ee901aSMatthias Ringwald     // LE Secure Connections, Numeric Comparison
15099c44ab2SMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_YES_NO);
15199c44ab2SMatthias Ringwald     // sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
152d7ee901aSMatthias Ringwald 
15332112218SMatthias Ringwald     // LE Secure Pairing, Passkey entry initiator enter, responder (us) displays
154d7ee901aSMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY);
155d7ee901aSMatthias Ringwald     // sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
1564b8c611fSMatthias Ringwald     // sm_use_fixed_passkey_in_display_role(123456);
15732112218SMatthias Ringwald 
15832112218SMatthias Ringwald     // LE Secure Pairing, Passkey entry initiator displays, responder (us) enter
15932112218SMatthias Ringwald     // sm_set_io_capabilities(IO_CAPABILITY_KEYBOARD_ONLY);
16032112218SMatthias Ringwald     // sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION|SM_AUTHREQ_MITM_PROTECTION);
161d7ee901aSMatthias Ringwald #endif
162d7ee901aSMatthias Ringwald }
163d7ee901aSMatthias Ringwald 
164d7ee901aSMatthias Ringwald /* LISTING_END */
165d7ee901aSMatthias Ringwald 
166d7ee901aSMatthias Ringwald /*
167d7ee901aSMatthias Ringwald  * @section Packet Handler
168d7ee901aSMatthias Ringwald  *
169d7ee901aSMatthias Ringwald  * @text The packet handler is used to:
17073704aa9SMatthias Ringwald  *        - report connect/disconnect
17173704aa9SMatthias Ringwald  *        - handle Security Manager events
172d7ee901aSMatthias Ringwald  */
173d7ee901aSMatthias Ringwald 
174d7ee901aSMatthias Ringwald /* LISTING_START(packetHandler): Packet Handler */
175d7ee901aSMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){
1769ec2630cSMatthias Ringwald     UNUSED(channel);
1779ec2630cSMatthias Ringwald     UNUSED(size);
178414eb680SMatthias Ringwald 
1797bbeb3adSMilanka Ringwald     if (packet_type != HCI_EVENT_PACKET) return;
1807bbeb3adSMilanka Ringwald 
181a4fe6467SMatthias Ringwald     hci_con_handle_t con_handle;
1829c22b849SMatthias Ringwald     bd_addr_t addr;
1833c3e5a84SMatthias Ringwald     uint8_t status;
184414eb680SMatthias Ringwald 
185d7ee901aSMatthias Ringwald     switch (hci_event_packet_get_type(packet)) {
186a4fe6467SMatthias Ringwald         case HCI_EVENT_LE_META:
187a4fe6467SMatthias Ringwald             switch (hci_event_le_meta_get_subevent_code(packet)) {
188a4fe6467SMatthias Ringwald                 case HCI_SUBEVENT_LE_CONNECTION_COMPLETE:
18973704aa9SMatthias Ringwald                     printf("Connection complete\n");
1903c3e5a84SMatthias Ringwald                     con_handle = hci_subevent_le_connection_complete_get_connection_handle(packet);
191414eb680SMatthias Ringwald                     UNUSED(con_handle);
1923c3e5a84SMatthias Ringwald 
1933c3e5a84SMatthias Ringwald                     // for testing, choose one of the following actions
1943c3e5a84SMatthias Ringwald 
1953c3e5a84SMatthias Ringwald                     // manually start pairing
1963c3e5a84SMatthias Ringwald                     // sm_send_security_request(con_handle);
1973c3e5a84SMatthias Ringwald 
1983c3e5a84SMatthias Ringwald                     // gatt client request to authenticated characteristic in sm_pairing_central (short cut, uses hard-coded value handle)
1993c3e5a84SMatthias Ringwald                     // gatt_client_read_value_of_characteristic_using_value_handle(&packet_handler, con_handle, 0x0009);
2003c3e5a84SMatthias Ringwald 
2013c3e5a84SMatthias Ringwald                     // general gatt client request to trigger mandatory authentication
2023c3e5a84SMatthias Ringwald                     // gatt_client_discover_primary_services(&packet_handler, con_handle);
203a4fe6467SMatthias Ringwald                     break;
204a4fe6467SMatthias Ringwald                 default:
205a4fe6467SMatthias Ringwald                     break;
206a4fe6467SMatthias Ringwald             }
207a4fe6467SMatthias Ringwald             break;
208d7ee901aSMatthias Ringwald         case SM_EVENT_JUST_WORKS_REQUEST:
209d7ee901aSMatthias Ringwald             printf("Just Works requested\n");
210d7ee901aSMatthias Ringwald             sm_just_works_confirm(sm_event_just_works_request_get_handle(packet));
211d7ee901aSMatthias Ringwald             break;
212d7ee901aSMatthias Ringwald         case SM_EVENT_NUMERIC_COMPARISON_REQUEST:
213bace42efSMatthias Ringwald             printf("Confirming numeric comparison: %"PRIu32"\n", sm_event_numeric_comparison_request_get_passkey(packet));
214d7ee901aSMatthias Ringwald             sm_numeric_comparison_confirm(sm_event_passkey_display_number_get_handle(packet));
215d7ee901aSMatthias Ringwald             break;
216d7ee901aSMatthias Ringwald         case SM_EVENT_PASSKEY_DISPLAY_NUMBER:
217bace42efSMatthias Ringwald             printf("Display Passkey: %"PRIu32"\n", sm_event_passkey_display_number_get_passkey(packet));
218d7ee901aSMatthias Ringwald             break;
2199c22b849SMatthias Ringwald         case SM_EVENT_IDENTITY_CREATED:
2209c22b849SMatthias Ringwald             sm_event_identity_created_get_identity_address(packet, addr);
2219c22b849SMatthias Ringwald             printf("Identity created: type %u address %s\n", sm_event_identity_created_get_identity_addr_type(packet), bd_addr_to_str(addr));
2229c22b849SMatthias Ringwald             break;
2239c22b849SMatthias Ringwald         case SM_EVENT_IDENTITY_RESOLVING_SUCCEEDED:
2249c22b849SMatthias Ringwald             sm_event_identity_resolving_succeeded_get_identity_address(packet, addr);
2259c22b849SMatthias Ringwald             printf("Identity resolved: type %u address %s\n", sm_event_identity_resolving_succeeded_get_identity_addr_type(packet), bd_addr_to_str(addr));
2269c22b849SMatthias Ringwald             break;
2279c22b849SMatthias Ringwald         case SM_EVENT_IDENTITY_RESOLVING_FAILED:
2289c22b849SMatthias Ringwald             sm_event_identity_created_get_address(packet, addr);
2299c22b849SMatthias Ringwald             printf("Identity resolving failed\n");
2309c22b849SMatthias Ringwald             break;
231*7c4db9dcSMatthias Ringwald         case SM_EVENT_PAIRING_STARTED:
232*7c4db9dcSMatthias Ringwald             printf("Pairing started\n");
233*7c4db9dcSMatthias Ringwald             break;
2340614d679SMatthias Ringwald         case SM_EVENT_PAIRING_COMPLETE:
2350614d679SMatthias Ringwald             switch (sm_event_pairing_complete_get_status(packet)){
2360614d679SMatthias Ringwald                 case ERROR_CODE_SUCCESS:
2370614d679SMatthias Ringwald                     printf("Pairing complete, success\n");
2380614d679SMatthias Ringwald                     break;
2390614d679SMatthias Ringwald                 case ERROR_CODE_CONNECTION_TIMEOUT:
2400614d679SMatthias Ringwald                     printf("Pairing failed, timeout\n");
2410614d679SMatthias Ringwald                     break;
2420614d679SMatthias Ringwald                 case ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION:
2433cdbe9dbSMatthias Ringwald                     printf("Pairing failed, disconnected\n");
2440614d679SMatthias Ringwald                     break;
2450614d679SMatthias Ringwald                 case ERROR_CODE_AUTHENTICATION_FAILURE:
24639620ea5SMatthias Ringwald                     printf("Pairing failed, authentication failure with reason = %u\n", sm_event_pairing_complete_get_reason(packet));
2470614d679SMatthias Ringwald                     break;
2480614d679SMatthias Ringwald                 default:
2490614d679SMatthias Ringwald                     break;
2500614d679SMatthias Ringwald             }
2510614d679SMatthias Ringwald             break;
2527e65711bSMatthias Ringwald         case SM_EVENT_REENCRYPTION_STARTED:
2537e65711bSMatthias Ringwald             sm_event_reencryption_complete_get_address(packet, addr);
2547e65711bSMatthias Ringwald             printf("Bonding information exists for addr type %u, identity addr %s -> re-encryption started\n",
2557e65711bSMatthias Ringwald                    sm_event_reencryption_started_get_addr_type(packet), bd_addr_to_str(addr));
2567e65711bSMatthias Ringwald             break;
2577e65711bSMatthias Ringwald         case SM_EVENT_REENCRYPTION_COMPLETE:
2587e65711bSMatthias Ringwald             switch (sm_event_reencryption_complete_get_status(packet)){
2597e65711bSMatthias Ringwald                 case ERROR_CODE_SUCCESS:
2607e65711bSMatthias Ringwald                     printf("Re-encryption complete, success\n");
2617e65711bSMatthias Ringwald                     break;
2627e65711bSMatthias Ringwald                 case ERROR_CODE_CONNECTION_TIMEOUT:
2637e65711bSMatthias Ringwald                     printf("Re-encryption failed, timeout\n");
2647e65711bSMatthias Ringwald                     break;
2657e65711bSMatthias Ringwald                 case ERROR_CODE_REMOTE_USER_TERMINATED_CONNECTION:
2667e65711bSMatthias Ringwald                     printf("Re-encryption failed, disconnected\n");
2677e65711bSMatthias Ringwald                     break;
2687e65711bSMatthias Ringwald                 case ERROR_CODE_AUTHENTICATION_FAILURE:
2697e65711bSMatthias Ringwald                     printf("Re-encryption failed, authentication failure\n");
2707e65711bSMatthias Ringwald                     break;
2717e65711bSMatthias Ringwald                 default:
2727e65711bSMatthias Ringwald                     break;
2737e65711bSMatthias Ringwald             }
2747e65711bSMatthias Ringwald             break;
2753c3e5a84SMatthias Ringwald         case GATT_EVENT_QUERY_COMPLETE:
2763c3e5a84SMatthias Ringwald             status = gatt_event_query_complete_get_att_status(packet);
2773c3e5a84SMatthias Ringwald             switch (status){
2783c3e5a84SMatthias Ringwald                 case ATT_ERROR_INSUFFICIENT_ENCRYPTION:
2793c3e5a84SMatthias Ringwald                     printf("GATT Query result: Insufficient Encryption\n");
2803c3e5a84SMatthias Ringwald                     break;
2813c3e5a84SMatthias Ringwald                 case ATT_ERROR_INSUFFICIENT_AUTHENTICATION:
2823c3e5a84SMatthias Ringwald                     printf("GATT Query result: Insufficient Authentication\n");
2833c3e5a84SMatthias Ringwald                     break;
2843c3e5a84SMatthias Ringwald                 case ATT_ERROR_BONDING_INFORMATION_MISSING:
2853c3e5a84SMatthias Ringwald                     printf("GATT Query result: Bonding Information Missing\n");
2863c3e5a84SMatthias Ringwald                     break;
2873c3e5a84SMatthias Ringwald                 case ATT_ERROR_SUCCESS:
2883c3e5a84SMatthias Ringwald                     printf("GATT Query result: OK\n");
2893c3e5a84SMatthias Ringwald                     break;
2903c3e5a84SMatthias Ringwald                 default:
2913c3e5a84SMatthias Ringwald                     printf("GATT Query result: 0x%02x\n", gatt_event_query_complete_get_att_status(packet));
2923c3e5a84SMatthias Ringwald                     break;
2933c3e5a84SMatthias Ringwald             }
2943c3e5a84SMatthias Ringwald             break;
2950614d679SMatthias Ringwald         default:
2960614d679SMatthias Ringwald             break;
297d7ee901aSMatthias Ringwald     }
298d7ee901aSMatthias Ringwald }
299d7ee901aSMatthias Ringwald /* LISTING_END */
300d7ee901aSMatthias Ringwald 
301d7ee901aSMatthias Ringwald int btstack_main(void);
302d7ee901aSMatthias Ringwald int btstack_main(void)
303d7ee901aSMatthias Ringwald {
304d7ee901aSMatthias Ringwald     sm_peripheral_setup();
305d7ee901aSMatthias Ringwald 
306d7ee901aSMatthias Ringwald     // turn on!
307d7ee901aSMatthias Ringwald 	hci_power_control(HCI_POWER_ON);
308d7ee901aSMatthias Ringwald 
309d7ee901aSMatthias Ringwald     return 0;
310d7ee901aSMatthias Ringwald }
311d7ee901aSMatthias Ringwald /* EXAMPLE_END */
312