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