1bcf00d8fSMatthias Ringwald /* 2bcf00d8fSMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3bcf00d8fSMatthias Ringwald * 4bcf00d8fSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5bcf00d8fSMatthias Ringwald * modification, are permitted provided that the following conditions 6bcf00d8fSMatthias Ringwald * are met: 7bcf00d8fSMatthias Ringwald * 8bcf00d8fSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9bcf00d8fSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10bcf00d8fSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11bcf00d8fSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12bcf00d8fSMatthias Ringwald * documentation and/or other materials provided with the distribution. 13bcf00d8fSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14bcf00d8fSMatthias Ringwald * contributors may be used to endorse or promote products derived 15bcf00d8fSMatthias Ringwald * from this software without specific prior written permission. 16bcf00d8fSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17bcf00d8fSMatthias Ringwald * personal benefit and not for any commercial purpose or for 18bcf00d8fSMatthias Ringwald * monetary gain. 19bcf00d8fSMatthias Ringwald * 20bcf00d8fSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21bcf00d8fSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22bcf00d8fSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23bcf00d8fSMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24bcf00d8fSMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25bcf00d8fSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26bcf00d8fSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27bcf00d8fSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28bcf00d8fSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29bcf00d8fSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30bcf00d8fSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31bcf00d8fSMatthias Ringwald * SUCH DAMAGE. 32bcf00d8fSMatthias Ringwald * 33bcf00d8fSMatthias Ringwald * Please inquire about commercial licensing options at 34bcf00d8fSMatthias Ringwald * [email protected] 35bcf00d8fSMatthias Ringwald * 36bcf00d8fSMatthias Ringwald */ 37bcf00d8fSMatthias Ringwald 38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "gap_dedicated_bonding.c" 39ab2c6ae4SMatthias Ringwald 40bcf00d8fSMatthias Ringwald #include <stdint.h> 41bcf00d8fSMatthias Ringwald #include <stdio.h> 42bcf00d8fSMatthias Ringwald #include <stdlib.h> 43bcf00d8fSMatthias Ringwald #include <string.h> 44bcf00d8fSMatthias Ringwald 450e2df43fSMatthias Ringwald #include "btstack.h" 46bcf00d8fSMatthias Ringwald 47bcf00d8fSMatthias Ringwald static bd_addr_t remote = {0x84, 0x38, 0x35, 0x65, 0xD1, 0x15}; 48bcf00d8fSMatthias Ringwald 49bcf00d8fSMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 50bcf00d8fSMatthias Ringwald 51bcf00d8fSMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 529ec2630cSMatthias Ringwald UNUSED(channel); 539ec2630cSMatthias Ringwald UNUSED(size); 549ec2630cSMatthias Ringwald 55bcf00d8fSMatthias Ringwald if (packet_type != HCI_EVENT_PACKET) return; 56bcf00d8fSMatthias Ringwald 570e2df43fSMatthias Ringwald switch (hci_event_packet_get_type(packet)) { 58bcf00d8fSMatthias Ringwald case BTSTACK_EVENT_STATE: 59d356a6daSMatthias Ringwald // BTstack activated, get started 60fb42b6e5SMilanka Ringwald if (btstack_event_state_get_state(packet) == HCI_STATE_WORKING){ 61bcf00d8fSMatthias Ringwald gap_dedicated_bonding(remote, 1); 62bcf00d8fSMatthias Ringwald } 63bcf00d8fSMatthias Ringwald break; 64bcf00d8fSMatthias Ringwald case GAP_EVENT_DEDICATED_BONDING_COMPLETED: 65bcf00d8fSMatthias Ringwald printf("GAP Dedicated Bonding Complete, status %u\n", packet[2]); 66*6058cb0dSMatthias Ringwald break; 67bcf00d8fSMatthias Ringwald default: 68bcf00d8fSMatthias Ringwald break; 69bcf00d8fSMatthias Ringwald } 70bcf00d8fSMatthias Ringwald } 71bcf00d8fSMatthias Ringwald 72bcf00d8fSMatthias Ringwald int btstack_main(int argc, const char * argv[]); 73bcf00d8fSMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 749ec2630cSMatthias Ringwald (void)argc; 759ec2630cSMatthias Ringwald (void)argv; 76bcf00d8fSMatthias Ringwald 77bcf00d8fSMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 78bcf00d8fSMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 79bcf00d8fSMatthias Ringwald 80bcf00d8fSMatthias Ringwald // turn on! 81bcf00d8fSMatthias Ringwald hci_power_control(HCI_POWER_ON); 82bcf00d8fSMatthias Ringwald 83bcf00d8fSMatthias Ringwald return 0; 84bcf00d8fSMatthias Ringwald } 85