1aa29f587SMatthias Ringwald /* 2aa29f587SMatthias Ringwald * Copyright (C) 2014 BlueKitchen GmbH 3aa29f587SMatthias Ringwald * 4aa29f587SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5aa29f587SMatthias Ringwald * modification, are permitted provided that the following conditions 6aa29f587SMatthias Ringwald * are met: 7aa29f587SMatthias Ringwald * 8aa29f587SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9aa29f587SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10aa29f587SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11aa29f587SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12aa29f587SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13aa29f587SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14aa29f587SMatthias Ringwald * contributors may be used to endorse or promote products derived 15aa29f587SMatthias Ringwald * from this software without specific prior written permission. 16aa29f587SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17aa29f587SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18aa29f587SMatthias Ringwald * monetary gain. 19aa29f587SMatthias Ringwald * 20aa29f587SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21aa29f587SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22aa29f587SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 232fca4dadSMilanka Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 242fca4dadSMilanka Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25aa29f587SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26aa29f587SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27aa29f587SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28aa29f587SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29aa29f587SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30aa29f587SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31aa29f587SMatthias Ringwald * SUCH DAMAGE. 32aa29f587SMatthias Ringwald * 33aa29f587SMatthias Ringwald * Please inquire about commercial licensing options at 34aa29f587SMatthias Ringwald * [email protected] 35aa29f587SMatthias Ringwald * 36aa29f587SMatthias Ringwald */ 37aa29f587SMatthias Ringwald 38e501bae0SMatthias Ringwald #define BTSTACK_FILE__ "hid_mouse_demo.c" 39aa29f587SMatthias Ringwald 40aa29f587SMatthias Ringwald // ***************************************************************************** 41ec8ae085SMilanka Ringwald /* EXAMPLE_START(hid_mouse_demo): HID Mouse Classic 42aa29f587SMatthias Ringwald * 43aa29f587SMatthias Ringwald * @text This HID Device example demonstrates how to implement 44aa29f587SMatthias Ringwald * an HID keyboard. Without a HAVE_BTSTACK_STDIN, a fixed demo text is sent 45aa29f587SMatthias Ringwald * If HAVE_BTSTACK_STDIN is defined, you can type from the terminal 46aa29f587SMatthias Ringwald */ 47aa29f587SMatthias Ringwald // ***************************************************************************** 48aa29f587SMatthias Ringwald 49aa29f587SMatthias Ringwald 50aa29f587SMatthias Ringwald #include <stdint.h> 51aa29f587SMatthias Ringwald #include <stdio.h> 52aa29f587SMatthias Ringwald #include <stdlib.h> 53aa29f587SMatthias Ringwald #include <string.h> 54aa29f587SMatthias Ringwald #include <inttypes.h> 55aa29f587SMatthias Ringwald 56aa29f587SMatthias Ringwald #include "btstack.h" 57aa29f587SMatthias Ringwald 58aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 59aa29f587SMatthias Ringwald #include "btstack_stdin.h" 60aa29f587SMatthias Ringwald #endif 61aa29f587SMatthias Ringwald 62aa29f587SMatthias Ringwald // to enable demo text on POSIX systems 63aa29f587SMatthias Ringwald // #undef HAVE_BTSTACK_STDIN 64aa29f587SMatthias Ringwald 65*762141afSMatthias Ringwald static uint8_t hid_service_buffer[270]; 66*762141afSMatthias Ringwald static uint8_t device_id_sdp_service_buffer[100]; 67aa29f587SMatthias Ringwald static const char hid_device_name[] = "BTstack HID Mouse"; 68aa29f587SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 69aa29f587SMatthias Ringwald static uint16_t hid_cid; 70aa29f587SMatthias Ringwald 71aa29f587SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.2 72aa29f587SMatthias Ringwald const uint8_t hid_descriptor_mouse_boot_mode[] = { 73aa29f587SMatthias Ringwald 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 74aa29f587SMatthias Ringwald 0x09, 0x02, // USAGE (Mouse) 75aa29f587SMatthias Ringwald 0xa1, 0x01, // COLLECTION (Application) 76aa29f587SMatthias Ringwald 77aa29f587SMatthias Ringwald 0x09, 0x01, // USAGE (Pointer) 78aa29f587SMatthias Ringwald 0xa1, 0x00, // COLLECTION (Physical) 79aa29f587SMatthias Ringwald 80aa29f587SMatthias Ringwald 0x05, 0x09, // USAGE_PAGE (Button) 81aa29f587SMatthias Ringwald 0x19, 0x01, // USAGE_MINIMUM (Button 1) 82aa29f587SMatthias Ringwald 0x29, 0x03, // USAGE_MAXIMUM (Button 3) 83aa29f587SMatthias Ringwald 0x15, 0x00, // LOGICAL_MINIMUM (0) 84aa29f587SMatthias Ringwald 0x25, 0x01, // LOGICAL_MAXIMUM (1) 85aa29f587SMatthias Ringwald 0x95, 0x03, // REPORT_COUNT (3) 86aa29f587SMatthias Ringwald 0x75, 0x01, // REPORT_SIZE (1) 87aa29f587SMatthias Ringwald 0x81, 0x02, // INPUT (Data,Var,Abs) 88aa29f587SMatthias Ringwald 0x95, 0x01, // REPORT_COUNT (1) 89aa29f587SMatthias Ringwald 0x75, 0x05, // REPORT_SIZE (5) 90aa29f587SMatthias Ringwald 0x81, 0x03, // INPUT (Cnst,Var,Abs) 91aa29f587SMatthias Ringwald 92aa29f587SMatthias Ringwald 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 93aa29f587SMatthias Ringwald 0x09, 0x30, // USAGE (X) 94aa29f587SMatthias Ringwald 0x09, 0x31, // USAGE (Y) 95aa29f587SMatthias Ringwald 0x15, 0x81, // LOGICAL_MINIMUM (-127) 96aa29f587SMatthias Ringwald 0x25, 0x7f, // LOGICAL_MAXIMUM (127) 97aa29f587SMatthias Ringwald 0x75, 0x08, // REPORT_SIZE (8) 98aa29f587SMatthias Ringwald 0x95, 0x02, // REPORT_COUNT (2) 99aa29f587SMatthias Ringwald 0x81, 0x06, // INPUT (Data,Var,Rel) 100aa29f587SMatthias Ringwald 101aa29f587SMatthias Ringwald 0xc0, // END_COLLECTION 102aa29f587SMatthias Ringwald 0xc0 // END_COLLECTION 103aa29f587SMatthias Ringwald }; 104aa29f587SMatthias Ringwald 105aa29f587SMatthias Ringwald // HID Report sending 106aa29f587SMatthias Ringwald static void send_report(uint8_t buttons, int8_t dx, int8_t dy){ 107aa29f587SMatthias Ringwald uint8_t report[] = { 0xa1, buttons, (uint8_t) dx, (uint8_t) dy}; 108aa29f587SMatthias Ringwald hid_device_send_interrupt_message(hid_cid, &report[0], sizeof(report)); 109aa29f587SMatthias Ringwald printf("Mouse: %d/%d - buttons: %02x\n", dx, dy, buttons); 110aa29f587SMatthias Ringwald } 111aa29f587SMatthias Ringwald 112aa29f587SMatthias Ringwald static int dx; 113aa29f587SMatthias Ringwald static int dy; 114aa29f587SMatthias Ringwald static uint8_t buttons; 115b274c7b3SMilanka Ringwald static int hid_boot_device = 0; 116aa29f587SMatthias Ringwald 117aa29f587SMatthias Ringwald static void mousing_can_send_now(void){ 118aa29f587SMatthias Ringwald send_report(buttons, dx, dy); 119aa29f587SMatthias Ringwald // reset 120aa29f587SMatthias Ringwald dx = 0; 121aa29f587SMatthias Ringwald dy = 0; 122aa29f587SMatthias Ringwald if (buttons){ 123aa29f587SMatthias Ringwald buttons = 0; 124aa29f587SMatthias Ringwald hid_device_request_can_send_now_event(hid_cid); 125aa29f587SMatthias Ringwald } 126aa29f587SMatthias Ringwald } 127aa29f587SMatthias Ringwald 128aa29f587SMatthias Ringwald // Demo Application 129aa29f587SMatthias Ringwald 130aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 131aa29f587SMatthias Ringwald 132aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 30; 133aa29f587SMatthias Ringwald 134aa29f587SMatthias Ringwald // On systems with STDIN, we can directly type on the console 135aa29f587SMatthias Ringwald 136aa29f587SMatthias Ringwald static void stdin_process(char character){ 137aa29f587SMatthias Ringwald 138aa29f587SMatthias Ringwald if (!hid_cid) { 139aa29f587SMatthias Ringwald printf("Mouse not connected, ignoring '%c'\n", character); 140aa29f587SMatthias Ringwald return; 141aa29f587SMatthias Ringwald } 142aa29f587SMatthias Ringwald 143aa29f587SMatthias Ringwald switch (character){ 144aa29f587SMatthias Ringwald case 'a': 145aa29f587SMatthias Ringwald dx -= MOUSE_SPEED; 146aa29f587SMatthias Ringwald break; 147aa29f587SMatthias Ringwald case 's': 148aa29f587SMatthias Ringwald dy += MOUSE_SPEED; 149aa29f587SMatthias Ringwald break; 150aa29f587SMatthias Ringwald case 'd': 151aa29f587SMatthias Ringwald dx += MOUSE_SPEED; 152aa29f587SMatthias Ringwald break; 153aa29f587SMatthias Ringwald case 'w': 154aa29f587SMatthias Ringwald dy -= MOUSE_SPEED; 155aa29f587SMatthias Ringwald break; 156aa29f587SMatthias Ringwald case 'l': 157aa29f587SMatthias Ringwald buttons |= 1; 158aa29f587SMatthias Ringwald break; 159aa29f587SMatthias Ringwald case 'r': 160aa29f587SMatthias Ringwald buttons |= 2; 161aa29f587SMatthias Ringwald break; 162aa29f587SMatthias Ringwald default: 163aa29f587SMatthias Ringwald return; 164aa29f587SMatthias Ringwald } 165aa29f587SMatthias Ringwald hid_device_request_can_send_now_event(hid_cid); 166aa29f587SMatthias Ringwald } 167aa29f587SMatthias Ringwald 168aa29f587SMatthias Ringwald #else 169aa29f587SMatthias Ringwald 170aa29f587SMatthias Ringwald // On embedded systems, simulate clicking on 4 corners of a square 171aa29f587SMatthias Ringwald 172aa29f587SMatthias Ringwald #define MOUSE_PERIOD_MS 15 173aa29f587SMatthias Ringwald 174aa29f587SMatthias Ringwald static int step; 175aa29f587SMatthias Ringwald static const int STEPS_PER_DIRECTION = 50; 176aa29f587SMatthias Ringwald static const int MOUSE_SPEED = 10; 177aa29f587SMatthias Ringwald 178aa29f587SMatthias Ringwald static struct { 179aa29f587SMatthias Ringwald int dx; 180aa29f587SMatthias Ringwald int dy; 181aa29f587SMatthias Ringwald } directions[] = { 182aa29f587SMatthias Ringwald { 1, 0 }, 183aa29f587SMatthias Ringwald { 0, 1 }, 184aa29f587SMatthias Ringwald { -1, 0 }, 185aa29f587SMatthias Ringwald { 0, -1 }, 186aa29f587SMatthias Ringwald }; 187aa29f587SMatthias Ringwald 188aa29f587SMatthias Ringwald static btstack_timer_source_t mousing_timer; 189aa29f587SMatthias Ringwald 190aa29f587SMatthias Ringwald static void mousing_timer_handler(btstack_timer_source_t * ts){ 191aa29f587SMatthias Ringwald 192173fff9bSMatthias Ringwald if (!hid_cid) return; 193aa29f587SMatthias Ringwald 194aa29f587SMatthias Ringwald // simulate left click when corner reached 195aa29f587SMatthias Ringwald if (step % STEPS_PER_DIRECTION == 0){ 196aa29f587SMatthias Ringwald buttons |= 1; 197aa29f587SMatthias Ringwald } 198aa29f587SMatthias Ringwald // simulate move 199aa29f587SMatthias Ringwald int direction_index = step / STEPS_PER_DIRECTION; 200aa29f587SMatthias Ringwald dx += directions[direction_index].dx * MOUSE_SPEED; 201aa29f587SMatthias Ringwald dy += directions[direction_index].dy * MOUSE_SPEED; 202aa29f587SMatthias Ringwald 203aa29f587SMatthias Ringwald // next 204aa29f587SMatthias Ringwald step++; 205aa29f587SMatthias Ringwald if (step >= STEPS_PER_DIRECTION * 4) { 206aa29f587SMatthias Ringwald step = 0; 207aa29f587SMatthias Ringwald } 208aa29f587SMatthias Ringwald 209aa29f587SMatthias Ringwald // trigger send 210173fff9bSMatthias Ringwald hid_device_request_can_send_now_event(hid_cid); 211aa29f587SMatthias Ringwald 212aa29f587SMatthias Ringwald // set next timer 213aa29f587SMatthias Ringwald btstack_run_loop_set_timer(ts, MOUSE_PERIOD_MS); 214aa29f587SMatthias Ringwald btstack_run_loop_add_timer(ts); 215aa29f587SMatthias Ringwald } 216aa29f587SMatthias Ringwald 217aa29f587SMatthias Ringwald static void hid_embedded_start_mousing(void){ 218aa29f587SMatthias Ringwald printf("Start mousing..\n"); 219aa29f587SMatthias Ringwald 220aa29f587SMatthias Ringwald step = 0; 221aa29f587SMatthias Ringwald 222aa29f587SMatthias Ringwald // set one-shot timer 223aa29f587SMatthias Ringwald mousing_timer.process = &mousing_timer_handler; 224aa29f587SMatthias Ringwald btstack_run_loop_set_timer(&mousing_timer, MOUSE_PERIOD_MS); 225aa29f587SMatthias Ringwald btstack_run_loop_add_timer(&mousing_timer); 226aa29f587SMatthias Ringwald } 227aa29f587SMatthias Ringwald #endif 228aa29f587SMatthias Ringwald 229aa29f587SMatthias Ringwald static void packet_handler(uint8_t packet_type, uint16_t channel, uint8_t * packet, uint16_t packet_size){ 230aa29f587SMatthias Ringwald UNUSED(channel); 231aa29f587SMatthias Ringwald UNUSED(packet_size); 232aa29f587SMatthias Ringwald switch (packet_type){ 233aa29f587SMatthias Ringwald case HCI_EVENT_PACKET: 2346058cb0dSMatthias Ringwald switch (hci_event_packet_get_type(packet)){ 235aa29f587SMatthias Ringwald case HCI_EVENT_USER_CONFIRMATION_REQUEST: 236aa29f587SMatthias Ringwald // ssp: inform about user confirmation request 237aa29f587SMatthias Ringwald log_info("SSP User Confirmation Request with numeric value '%06"PRIu32"'\n", hci_event_user_confirmation_request_get_numeric_value(packet)); 238aa29f587SMatthias Ringwald log_info("SSP User Confirmation Auto accept\n"); 239aa29f587SMatthias Ringwald break; 240aa29f587SMatthias Ringwald 241aa29f587SMatthias Ringwald case HCI_EVENT_HID_META: 242aa29f587SMatthias Ringwald switch (hci_event_hid_meta_get_subevent_code(packet)){ 243aa29f587SMatthias Ringwald case HID_SUBEVENT_CONNECTION_OPENED: 2446058cb0dSMatthias Ringwald if (hid_subevent_connection_opened_get_status(packet) != ERROR_CODE_SUCCESS) return; 245aa29f587SMatthias Ringwald hid_cid = hid_subevent_connection_opened_get_hid_cid(packet); 246aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 247aa29f587SMatthias Ringwald printf("HID Connected, control mouse using 'a','s',''d', 'w' keys for movement and 'l' and 'r' for buttons...\n"); 248aa29f587SMatthias Ringwald #else 249aa29f587SMatthias Ringwald printf("HID Connected, simulating mouse movements...\n"); 250173fff9bSMatthias Ringwald hid_embedded_start_mousing(); 251aa29f587SMatthias Ringwald #endif 252aa29f587SMatthias Ringwald break; 253aa29f587SMatthias Ringwald case HID_SUBEVENT_CONNECTION_CLOSED: 254aa29f587SMatthias Ringwald printf("HID Disconnected\n"); 255aa29f587SMatthias Ringwald hid_cid = 0; 256aa29f587SMatthias Ringwald break; 257aa29f587SMatthias Ringwald case HID_SUBEVENT_CAN_SEND_NOW: 258aa29f587SMatthias Ringwald mousing_can_send_now(); 259aa29f587SMatthias Ringwald break; 260aa29f587SMatthias Ringwald default: 261aa29f587SMatthias Ringwald break; 262aa29f587SMatthias Ringwald } 263aa29f587SMatthias Ringwald break; 264aa29f587SMatthias Ringwald default: 265aa29f587SMatthias Ringwald break; 266aa29f587SMatthias Ringwald } 267aa29f587SMatthias Ringwald break; 268aa29f587SMatthias Ringwald default: 269aa29f587SMatthias Ringwald break; 270aa29f587SMatthias Ringwald } 271aa29f587SMatthias Ringwald } 272aa29f587SMatthias Ringwald 273aa29f587SMatthias Ringwald /* @section Main Application Setup 274aa29f587SMatthias Ringwald * 275aa29f587SMatthias Ringwald * @text Listing MainConfiguration shows main application code. 276aa29f587SMatthias Ringwald * To run a HID Device service you need to initialize the SDP, and to create and register HID Device record with it. 277aa29f587SMatthias Ringwald * At the end the Bluetooth stack is started. 278aa29f587SMatthias Ringwald */ 279aa29f587SMatthias Ringwald 280aa29f587SMatthias Ringwald /* LISTING_START(MainConfiguration): Setup HID Device */ 281aa29f587SMatthias Ringwald 282aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]); 283aa29f587SMatthias Ringwald int btstack_main(int argc, const char * argv[]){ 284aa29f587SMatthias Ringwald (void)argc; 285aa29f587SMatthias Ringwald (void)argv; 286aa29f587SMatthias Ringwald 28745a92abaSMatthias Ringwald // allow to get found by inquiry 288aa29f587SMatthias Ringwald gap_discoverable_control(1); 28945a92abaSMatthias Ringwald // use Limited Discoverable Mode; Peripheral; Pointing Device as CoD 29045a92abaSMatthias Ringwald gap_set_class_of_device(0x2580); 29145a92abaSMatthias Ringwald // set local name to be identified - zeroes will be replaced by actual BD ADDR 292aa29f587SMatthias Ringwald gap_set_local_name("HID Mouse Demo 00:00:00:00:00:00"); 29345a92abaSMatthias Ringwald // allow for role switch in general and sniff mode 29445a92abaSMatthias Ringwald gap_set_default_link_policy_settings( LM_LINK_POLICY_ENABLE_ROLE_SWITCH | LM_LINK_POLICY_ENABLE_SNIFF_MODE ); 29545a92abaSMatthias Ringwald // allow for role switch on outgoing connections - this allow HID Host to become master when we re-connect to it 29645a92abaSMatthias Ringwald gap_set_allow_role_switch(true); 297aa29f587SMatthias Ringwald 298aa29f587SMatthias Ringwald // L2CAP 299aa29f587SMatthias Ringwald l2cap_init(); 300aa29f587SMatthias Ringwald 3018c9bb29eSMatthias Ringwald #ifdef ENABLE_BLE 3028c9bb29eSMatthias Ringwald // Initialize LE Security Manager. Needed for cross-transport key derivation 3038c9bb29eSMatthias Ringwald sm_init(); 3048c9bb29eSMatthias Ringwald #endif 3058c9bb29eSMatthias Ringwald 306aa29f587SMatthias Ringwald // SDP Server 307aa29f587SMatthias Ringwald sdp_init(); 3081ad99f3bSMilanka Ringwald 3091ad99f3bSMilanka Ringwald uint8_t hid_virtual_cable = 0; 3101ad99f3bSMilanka Ringwald uint8_t hid_remote_wake = 1; 3111ad99f3bSMilanka Ringwald uint8_t hid_reconnect_initiate = 1; 312ffe3f1a1SMilanka Ringwald uint8_t hid_normally_connectable = 1; 3131ad99f3bSMilanka Ringwald 31480d9d5d4SMilanka Ringwald hid_sdp_record_t hid_params = { 31580d9d5d4SMilanka Ringwald // hid sevice subclass 2580 Mouse, hid counntry code 33 US 31680d9d5d4SMilanka Ringwald 0x2580, 33, 31780d9d5d4SMilanka Ringwald hid_virtual_cable, hid_remote_wake, 31880d9d5d4SMilanka Ringwald hid_reconnect_initiate, hid_normally_connectable, 31980d9d5d4SMilanka Ringwald hid_boot_device, 32080d9d5d4SMilanka Ringwald 0xFFFF, 0xFFFF, 3200, 32180d9d5d4SMilanka Ringwald hid_descriptor_mouse_boot_mode, 32280d9d5d4SMilanka Ringwald sizeof(hid_descriptor_mouse_boot_mode), 32380d9d5d4SMilanka Ringwald hid_device_name 32480d9d5d4SMilanka Ringwald }; 32580d9d5d4SMilanka Ringwald 326*762141afSMatthias Ringwald memset(hid_service_buffer, 0, sizeof(hid_service_buffer)); 327*762141afSMatthias Ringwald hid_create_sdp_record(hid_service_buffer, sdp_create_service_record_handle(), &hid_params); 328*762141afSMatthias Ringwald btstack_assert(de_get_len( hid_service_buffer) <= sizeof(hid_service_buffer)); 329aa29f587SMatthias Ringwald sdp_register_service(hid_service_buffer); 330aa29f587SMatthias Ringwald 331*762141afSMatthias Ringwald // See https://www.bluetooth.com/specifications/assigned-numbers/company-identifiers if you don't have a USB Vendor ID and need a Bluetooth Vendor ID 332*762141afSMatthias Ringwald // device info: BlueKitchen GmbH, product 2, version 1 333*762141afSMatthias Ringwald device_id_create_sdp_record(device_id_sdp_service_buffer, sdp_create_service_record_handle(), DEVICE_ID_VENDOR_ID_SOURCE_BLUETOOTH, BLUETOOTH_COMPANY_ID_BLUEKITCHEN_GMBH, 2, 1); 334*762141afSMatthias Ringwald btstack_assert(de_get_len( device_id_sdp_service_buffer) <= sizeof(device_id_sdp_service_buffer)); 335*762141afSMatthias Ringwald sdp_register_service(device_id_sdp_service_buffer); 336*762141afSMatthias Ringwald 337aa29f587SMatthias Ringwald // HID Device 338a796c06fSMilanka Ringwald hid_device_init(hid_boot_device, sizeof(hid_descriptor_mouse_boot_mode), hid_descriptor_mouse_boot_mode); 339a4fe6467SMatthias Ringwald // register for HCI events 340a4fe6467SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 341a4fe6467SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 342a4fe6467SMatthias Ringwald 343a4fe6467SMatthias Ringwald // register for HID 344aa29f587SMatthias Ringwald hid_device_register_packet_handler(&packet_handler); 345aa29f587SMatthias Ringwald 346aa29f587SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 347aa29f587SMatthias Ringwald btstack_stdin_setup(stdin_process); 348aa29f587SMatthias Ringwald #endif 349aa29f587SMatthias Ringwald // turn on! 350aa29f587SMatthias Ringwald hci_power_control(HCI_POWER_ON); 351aa29f587SMatthias Ringwald return 0; 352aa29f587SMatthias Ringwald } 353aa29f587SMatthias Ringwald /* LISTING_END */ 354aa29f587SMatthias Ringwald /* EXAMPLE_END */ 355