1*fbf7b2f3SMatthias Ringwald /* 2*fbf7b2f3SMatthias Ringwald * Copyright (C) 2017 BlueKitchen GmbH 3*fbf7b2f3SMatthias Ringwald * 4*fbf7b2f3SMatthias Ringwald * Redistribution and use in source and binary forms, with or without 5*fbf7b2f3SMatthias Ringwald * modification, are permitted provided that the following conditions 6*fbf7b2f3SMatthias Ringwald * are met: 7*fbf7b2f3SMatthias Ringwald * 8*fbf7b2f3SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 9*fbf7b2f3SMatthias Ringwald * notice, this list of conditions and the following disclaimer. 10*fbf7b2f3SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 11*fbf7b2f3SMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 12*fbf7b2f3SMatthias Ringwald * documentation and/or other materials provided with the distribution. 13*fbf7b2f3SMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 14*fbf7b2f3SMatthias Ringwald * contributors may be used to endorse or promote products derived 15*fbf7b2f3SMatthias Ringwald * from this software without specific prior written permission. 16*fbf7b2f3SMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 17*fbf7b2f3SMatthias Ringwald * personal benefit and not for any commercial purpose or for 18*fbf7b2f3SMatthias Ringwald * monetary gain. 19*fbf7b2f3SMatthias Ringwald * 20*fbf7b2f3SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21*fbf7b2f3SMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22*fbf7b2f3SMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23*fbf7b2f3SMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 24*fbf7b2f3SMatthias Ringwald * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25*fbf7b2f3SMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26*fbf7b2f3SMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27*fbf7b2f3SMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28*fbf7b2f3SMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29*fbf7b2f3SMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30*fbf7b2f3SMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31*fbf7b2f3SMatthias Ringwald * SUCH DAMAGE. 32*fbf7b2f3SMatthias Ringwald * 33*fbf7b2f3SMatthias Ringwald * Please inquire about commercial licensing options at 34*fbf7b2f3SMatthias Ringwald * [email protected] 35*fbf7b2f3SMatthias Ringwald * 36*fbf7b2f3SMatthias Ringwald */ 37*fbf7b2f3SMatthias Ringwald 38*fbf7b2f3SMatthias Ringwald #define __BTSTACK_FILE__ "hog_mouse_demo.c" 39*fbf7b2f3SMatthias Ringwald 40*fbf7b2f3SMatthias Ringwald // ***************************************************************************** 41*fbf7b2f3SMatthias Ringwald /* EXAMPLE_START(hog_mouse_demo): HID-over-GATT Mouse 42*fbf7b2f3SMatthias Ringwald */ 43*fbf7b2f3SMatthias Ringwald // ***************************************************************************** 44*fbf7b2f3SMatthias Ringwald 45*fbf7b2f3SMatthias Ringwald #include <stdint.h> 46*fbf7b2f3SMatthias Ringwald #include <stdio.h> 47*fbf7b2f3SMatthias Ringwald #include <stdlib.h> 48*fbf7b2f3SMatthias Ringwald #include <string.h> 49*fbf7b2f3SMatthias Ringwald #include <inttypes.h> 50*fbf7b2f3SMatthias Ringwald 51*fbf7b2f3SMatthias Ringwald #include "hog_mouse_demo.h" 52*fbf7b2f3SMatthias Ringwald 53*fbf7b2f3SMatthias Ringwald #include "btstack.h" 54*fbf7b2f3SMatthias Ringwald 55*fbf7b2f3SMatthias Ringwald #include "ble/gatt-service/battery_service_server.h" 56*fbf7b2f3SMatthias Ringwald #include "ble/gatt-service/device_information_service_server.h" 57*fbf7b2f3SMatthias Ringwald #include "ble/gatt-service/hids_device.h" 58*fbf7b2f3SMatthias Ringwald 59*fbf7b2f3SMatthias Ringwald // from USB HID Specification 1.1, Appendix B.2 60*fbf7b2f3SMatthias Ringwald const uint8_t hid_descriptor_mouse_boot_mode[] = { 61*fbf7b2f3SMatthias Ringwald 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 62*fbf7b2f3SMatthias Ringwald 0x09, 0x02, // USAGE (Mouse) 63*fbf7b2f3SMatthias Ringwald 0xa1, 0x01, // COLLECTION (Application) 64*fbf7b2f3SMatthias Ringwald 65*fbf7b2f3SMatthias Ringwald 0x85, 0x01, // Report ID 1 66*fbf7b2f3SMatthias Ringwald 67*fbf7b2f3SMatthias Ringwald 0x09, 0x01, // USAGE (Pointer) 68*fbf7b2f3SMatthias Ringwald 69*fbf7b2f3SMatthias Ringwald 0xa1, 0x00, // COLLECTION (Physical) 70*fbf7b2f3SMatthias Ringwald 71*fbf7b2f3SMatthias Ringwald #if 1 72*fbf7b2f3SMatthias Ringwald 0x05, 0x09, // USAGE_PAGE (Button) 73*fbf7b2f3SMatthias Ringwald 0x19, 0x01, // USAGE_MINIMUM (Button 1) 74*fbf7b2f3SMatthias Ringwald 0x29, 0x03, // USAGE_MAXIMUM (Button 3) 75*fbf7b2f3SMatthias Ringwald 0x15, 0x00, // LOGICAL_MINIMUM (0) 76*fbf7b2f3SMatthias Ringwald 0x25, 0x01, // LOGICAL_MAXIMUM (1) 77*fbf7b2f3SMatthias Ringwald 0x95, 0x03, // REPORT_COUNT (3) 78*fbf7b2f3SMatthias Ringwald 0x75, 0x01, // REPORT_SIZE (1) 79*fbf7b2f3SMatthias Ringwald 0x81, 0x02, // INPUT (Data,Var,Abs) 80*fbf7b2f3SMatthias Ringwald 0x95, 0x01, // REPORT_COUNT (1) 81*fbf7b2f3SMatthias Ringwald 0x75, 0x05, // REPORT_SIZE (5) 82*fbf7b2f3SMatthias Ringwald 0x81, 0x03, // INPUT (Cnst,Var,Abs) 83*fbf7b2f3SMatthias Ringwald #endif 84*fbf7b2f3SMatthias Ringwald 85*fbf7b2f3SMatthias Ringwald #if 1 86*fbf7b2f3SMatthias Ringwald 0x05, 0x01, // USAGE_PAGE (Generic Desktop) 87*fbf7b2f3SMatthias Ringwald 0x09, 0x30, // USAGE (X) 88*fbf7b2f3SMatthias Ringwald 0x09, 0x31, // USAGE (Y) 89*fbf7b2f3SMatthias Ringwald 0x15, 0x81, // LOGICAL_MINIMUM (-127) 90*fbf7b2f3SMatthias Ringwald 0x25, 0x7f, // LOGICAL_MAXIMUM (127) 91*fbf7b2f3SMatthias Ringwald 0x75, 0x08, // REPORT_SIZE (8) 92*fbf7b2f3SMatthias Ringwald 0x95, 0x02, // REPORT_COUNT (2) 93*fbf7b2f3SMatthias Ringwald 0x81, 0x06, // INPUT (Data,Var,Rel) 94*fbf7b2f3SMatthias Ringwald #endif 95*fbf7b2f3SMatthias Ringwald 96*fbf7b2f3SMatthias Ringwald 0xc0, // END_COLLECTION 97*fbf7b2f3SMatthias Ringwald 0xc0 // END_COLLECTION 98*fbf7b2f3SMatthias Ringwald }; 99*fbf7b2f3SMatthias Ringwald 100*fbf7b2f3SMatthias Ringwald static btstack_packet_callback_registration_t hci_event_callback_registration; 101*fbf7b2f3SMatthias Ringwald static btstack_packet_callback_registration_t sm_event_callback_registration; 102*fbf7b2f3SMatthias Ringwald static uint8_t battery = 100; 103*fbf7b2f3SMatthias Ringwald static hci_con_handle_t con_handle = HCI_CON_HANDLE_INVALID; 104*fbf7b2f3SMatthias Ringwald 105*fbf7b2f3SMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); 106*fbf7b2f3SMatthias Ringwald 107*fbf7b2f3SMatthias Ringwald const uint8_t adv_data[] = { 108*fbf7b2f3SMatthias Ringwald // Flags general discoverable, BR/EDR not supported 109*fbf7b2f3SMatthias Ringwald 0x02, BLUETOOTH_DATA_TYPE_FLAGS, 0x06, 110*fbf7b2f3SMatthias Ringwald // Name 111*fbf7b2f3SMatthias Ringwald 0x0a, BLUETOOTH_DATA_TYPE_COMPLETE_LOCAL_NAME, 'H', 'I', 'D', ' ', 'M', 'o', 'u', 's', 'e', 112*fbf7b2f3SMatthias Ringwald // 16-bit Service UUIDs 113*fbf7b2f3SMatthias Ringwald 0x03, BLUETOOTH_DATA_TYPE_COMPLETE_LIST_OF_16_BIT_SERVICE_CLASS_UUIDS, ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE & 0xff, ORG_BLUETOOTH_SERVICE_HUMAN_INTERFACE_DEVICE >> 8, 114*fbf7b2f3SMatthias Ringwald }; 115*fbf7b2f3SMatthias Ringwald const uint8_t adv_data_len = sizeof(adv_data); 116*fbf7b2f3SMatthias Ringwald 117*fbf7b2f3SMatthias Ringwald static void hog_mouse_setup(void){ 118*fbf7b2f3SMatthias Ringwald 119*fbf7b2f3SMatthias Ringwald // register for HCI events 120*fbf7b2f3SMatthias Ringwald hci_event_callback_registration.callback = &packet_handler; 121*fbf7b2f3SMatthias Ringwald hci_add_event_handler(&hci_event_callback_registration); 122*fbf7b2f3SMatthias Ringwald 123*fbf7b2f3SMatthias Ringwald l2cap_init(); 124*fbf7b2f3SMatthias Ringwald 125*fbf7b2f3SMatthias Ringwald // setup le device db 126*fbf7b2f3SMatthias Ringwald le_device_db_init(); 127*fbf7b2f3SMatthias Ringwald 128*fbf7b2f3SMatthias Ringwald // setup SM: Display only 129*fbf7b2f3SMatthias Ringwald sm_init(); 130*fbf7b2f3SMatthias Ringwald sm_event_callback_registration.callback = &packet_handler; 131*fbf7b2f3SMatthias Ringwald sm_add_event_handler(&sm_event_callback_registration); 132*fbf7b2f3SMatthias Ringwald sm_set_io_capabilities(IO_CAPABILITY_DISPLAY_ONLY); 133*fbf7b2f3SMatthias Ringwald // sm_set_authentication_requirements(SM_AUTHREQ_SECURE_CONNECTION | SM_AUTHREQ_BONDING); 134*fbf7b2f3SMatthias Ringwald sm_set_authentication_requirements(SM_AUTHREQ_BONDING); 135*fbf7b2f3SMatthias Ringwald 136*fbf7b2f3SMatthias Ringwald // setup ATT server 137*fbf7b2f3SMatthias Ringwald att_server_init(profile_data, NULL, NULL); 138*fbf7b2f3SMatthias Ringwald 139*fbf7b2f3SMatthias Ringwald // setup battery service 140*fbf7b2f3SMatthias Ringwald battery_service_server_init(battery); 141*fbf7b2f3SMatthias Ringwald 142*fbf7b2f3SMatthias Ringwald // setup device information service 143*fbf7b2f3SMatthias Ringwald device_information_service_server_init(); 144*fbf7b2f3SMatthias Ringwald 145*fbf7b2f3SMatthias Ringwald // setup HID Device service 146*fbf7b2f3SMatthias Ringwald hids_device_init(0, hid_descriptor_mouse_boot_mode, sizeof(hid_descriptor_mouse_boot_mode)); 147*fbf7b2f3SMatthias Ringwald hids_device_register_packet_handler(packet_handler); 148*fbf7b2f3SMatthias Ringwald 149*fbf7b2f3SMatthias Ringwald // setup advertisements 150*fbf7b2f3SMatthias Ringwald uint16_t adv_int_min = 0x0030; 151*fbf7b2f3SMatthias Ringwald uint16_t adv_int_max = 0x0030; 152*fbf7b2f3SMatthias Ringwald uint8_t adv_type = 0; 153*fbf7b2f3SMatthias Ringwald bd_addr_t null_addr; 154*fbf7b2f3SMatthias Ringwald memset(null_addr, 0, 6); 155*fbf7b2f3SMatthias Ringwald gap_advertisements_set_params(adv_int_min, adv_int_max, adv_type, 0, null_addr, 0x07, 0x00); 156*fbf7b2f3SMatthias Ringwald gap_advertisements_set_data(adv_data_len, (uint8_t*) adv_data); 157*fbf7b2f3SMatthias Ringwald gap_advertisements_enable(1); 158*fbf7b2f3SMatthias Ringwald } 159*fbf7b2f3SMatthias Ringwald 160*fbf7b2f3SMatthias Ringwald // HID Report sending 161*fbf7b2f3SMatthias Ringwald static void send_report(uint8_t buttons, int8_t dx, int8_t dy){ 162*fbf7b2f3SMatthias Ringwald // uint8_t report[] = { (uint8_t) dx, (uint8_t) dy, buttons}; 163*fbf7b2f3SMatthias Ringwald uint8_t report[] = { buttons, (uint8_t) dx, (uint8_t) dy}; 164*fbf7b2f3SMatthias Ringwald hids_device_send_input_report(con_handle, report, sizeof(report)); 165*fbf7b2f3SMatthias Ringwald printf("Mouse: %d/%d - buttons: %02x\n", dx, dy, buttons); 166*fbf7b2f3SMatthias Ringwald } 167*fbf7b2f3SMatthias Ringwald 168*fbf7b2f3SMatthias Ringwald static int dx; 169*fbf7b2f3SMatthias Ringwald static int dy; 170*fbf7b2f3SMatthias Ringwald static uint8_t buttons; 171*fbf7b2f3SMatthias Ringwald 172*fbf7b2f3SMatthias Ringwald static void mousing_can_send_now(void){ 173*fbf7b2f3SMatthias Ringwald send_report(buttons, dx, dy); 174*fbf7b2f3SMatthias Ringwald // reset 175*fbf7b2f3SMatthias Ringwald dx = 0; 176*fbf7b2f3SMatthias Ringwald dy = 0; 177*fbf7b2f3SMatthias Ringwald if (buttons){ 178*fbf7b2f3SMatthias Ringwald buttons = 0; 179*fbf7b2f3SMatthias Ringwald hids_device_request_can_send_now_event(con_handle); 180*fbf7b2f3SMatthias Ringwald } 181*fbf7b2f3SMatthias Ringwald } 182*fbf7b2f3SMatthias Ringwald 183*fbf7b2f3SMatthias Ringwald // Demo Application 184*fbf7b2f3SMatthias Ringwald 185*fbf7b2f3SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 186*fbf7b2f3SMatthias Ringwald 187*fbf7b2f3SMatthias Ringwald static const int MOUSE_SPEED = 30; 188*fbf7b2f3SMatthias Ringwald 189*fbf7b2f3SMatthias Ringwald // On systems with STDIN, we can directly type on the console 190*fbf7b2f3SMatthias Ringwald 191*fbf7b2f3SMatthias Ringwald static void stdin_process(char character){ 192*fbf7b2f3SMatthias Ringwald 193*fbf7b2f3SMatthias Ringwald if (con_handle == HCI_CON_HANDLE_INVALID) { 194*fbf7b2f3SMatthias Ringwald printf("Mouse not connected, ignoring '%c'\n", character); 195*fbf7b2f3SMatthias Ringwald return; 196*fbf7b2f3SMatthias Ringwald } 197*fbf7b2f3SMatthias Ringwald 198*fbf7b2f3SMatthias Ringwald switch (character){ 199*fbf7b2f3SMatthias Ringwald case 'a': 200*fbf7b2f3SMatthias Ringwald dx -= MOUSE_SPEED; 201*fbf7b2f3SMatthias Ringwald break; 202*fbf7b2f3SMatthias Ringwald case 's': 203*fbf7b2f3SMatthias Ringwald dy += MOUSE_SPEED; 204*fbf7b2f3SMatthias Ringwald break; 205*fbf7b2f3SMatthias Ringwald case 'd': 206*fbf7b2f3SMatthias Ringwald dx += MOUSE_SPEED; 207*fbf7b2f3SMatthias Ringwald break; 208*fbf7b2f3SMatthias Ringwald case 'w': 209*fbf7b2f3SMatthias Ringwald dy -= MOUSE_SPEED; 210*fbf7b2f3SMatthias Ringwald break; 211*fbf7b2f3SMatthias Ringwald case 'l': 212*fbf7b2f3SMatthias Ringwald buttons |= 1; 213*fbf7b2f3SMatthias Ringwald break; 214*fbf7b2f3SMatthias Ringwald case 'r': 215*fbf7b2f3SMatthias Ringwald buttons |= 2; 216*fbf7b2f3SMatthias Ringwald break; 217*fbf7b2f3SMatthias Ringwald default: 218*fbf7b2f3SMatthias Ringwald return; 219*fbf7b2f3SMatthias Ringwald } 220*fbf7b2f3SMatthias Ringwald hids_device_request_can_send_now_event(con_handle); 221*fbf7b2f3SMatthias Ringwald } 222*fbf7b2f3SMatthias Ringwald 223*fbf7b2f3SMatthias Ringwald #else 224*fbf7b2f3SMatthias Ringwald 225*fbf7b2f3SMatthias Ringwald // On embedded systems, simulate clicking on 4 corners of a square 226*fbf7b2f3SMatthias Ringwald 227*fbf7b2f3SMatthias Ringwald #define MOUSE_PERIOD_MS 15 228*fbf7b2f3SMatthias Ringwald 229*fbf7b2f3SMatthias Ringwald static int step; 230*fbf7b2f3SMatthias Ringwald static const int STEPS_PER_DIRECTION = 50; 231*fbf7b2f3SMatthias Ringwald static const int MOUSE_SPEED = 10; 232*fbf7b2f3SMatthias Ringwald 233*fbf7b2f3SMatthias Ringwald static struct { 234*fbf7b2f3SMatthias Ringwald int dx; 235*fbf7b2f3SMatthias Ringwald int dy; 236*fbf7b2f3SMatthias Ringwald } directions[] = { 237*fbf7b2f3SMatthias Ringwald { 1, 0 }, 238*fbf7b2f3SMatthias Ringwald { 0, 1 }, 239*fbf7b2f3SMatthias Ringwald { -1, 0 }, 240*fbf7b2f3SMatthias Ringwald { 0, -1 }, 241*fbf7b2f3SMatthias Ringwald }; 242*fbf7b2f3SMatthias Ringwald 243*fbf7b2f3SMatthias Ringwald static btstack_timer_source_t mousing_timer; 244*fbf7b2f3SMatthias Ringwald 245*fbf7b2f3SMatthias Ringwald static void mousing_timer_handler(btstack_timer_source_t * ts){ 246*fbf7b2f3SMatthias Ringwald 247*fbf7b2f3SMatthias Ringwald if (con_handle == HCI_CON_HANDLE_INVALID) return; 248*fbf7b2f3SMatthias Ringwald 249*fbf7b2f3SMatthias Ringwald // simulate left click when corner reached 250*fbf7b2f3SMatthias Ringwald if (step % STEPS_PER_DIRECTION == 0){ 251*fbf7b2f3SMatthias Ringwald buttons |= 1; 252*fbf7b2f3SMatthias Ringwald } 253*fbf7b2f3SMatthias Ringwald // simulate move 254*fbf7b2f3SMatthias Ringwald int direction_index = step / STEPS_PER_DIRECTION; 255*fbf7b2f3SMatthias Ringwald dx += directions[direction_index].dx * MOUSE_SPEED; 256*fbf7b2f3SMatthias Ringwald dy += directions[direction_index].dy * MOUSE_SPEED; 257*fbf7b2f3SMatthias Ringwald 258*fbf7b2f3SMatthias Ringwald // next 259*fbf7b2f3SMatthias Ringwald step++; 260*fbf7b2f3SMatthias Ringwald if (step >= STEPS_PER_DIRECTION * 4) { 261*fbf7b2f3SMatthias Ringwald step = 0; 262*fbf7b2f3SMatthias Ringwald } 263*fbf7b2f3SMatthias Ringwald 264*fbf7b2f3SMatthias Ringwald // trigger send 265*fbf7b2f3SMatthias Ringwald hids_device_request_can_send_now_event(con_handle); 266*fbf7b2f3SMatthias Ringwald 267*fbf7b2f3SMatthias Ringwald // set next timer 268*fbf7b2f3SMatthias Ringwald btstack_run_loop_set_timer(ts, MOUSE_PERIOD_MS); 269*fbf7b2f3SMatthias Ringwald btstack_run_loop_add_timer(ts); 270*fbf7b2f3SMatthias Ringwald } 271*fbf7b2f3SMatthias Ringwald 272*fbf7b2f3SMatthias Ringwald static void hid_embedded_start_mousing(void){ 273*fbf7b2f3SMatthias Ringwald printf("Start mousing..\n"); 274*fbf7b2f3SMatthias Ringwald 275*fbf7b2f3SMatthias Ringwald step = 0; 276*fbf7b2f3SMatthias Ringwald 277*fbf7b2f3SMatthias Ringwald // set one-shot timer 278*fbf7b2f3SMatthias Ringwald mousing_timer.process = &mousing_timer_handler; 279*fbf7b2f3SMatthias Ringwald btstack_run_loop_set_timer(&mousing_timer, MOUSE_PERIOD_MS); 280*fbf7b2f3SMatthias Ringwald btstack_run_loop_add_timer(&mousing_timer); 281*fbf7b2f3SMatthias Ringwald } 282*fbf7b2f3SMatthias Ringwald 283*fbf7b2f3SMatthias Ringwald #endif 284*fbf7b2f3SMatthias Ringwald 285*fbf7b2f3SMatthias Ringwald static void packet_handler (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size){ 286*fbf7b2f3SMatthias Ringwald UNUSED(channel); 287*fbf7b2f3SMatthias Ringwald UNUSED(size); 288*fbf7b2f3SMatthias Ringwald 289*fbf7b2f3SMatthias Ringwald switch (packet_type) { 290*fbf7b2f3SMatthias Ringwald case HCI_EVENT_PACKET: 291*fbf7b2f3SMatthias Ringwald switch (hci_event_packet_get_type(packet)) { 292*fbf7b2f3SMatthias Ringwald case HCI_EVENT_DISCONNECTION_COMPLETE: 293*fbf7b2f3SMatthias Ringwald printf("Disconnected\n"); 294*fbf7b2f3SMatthias Ringwald break; 295*fbf7b2f3SMatthias Ringwald case SM_EVENT_JUST_WORKS_REQUEST: 296*fbf7b2f3SMatthias Ringwald printf("Just Works requested\n"); 297*fbf7b2f3SMatthias Ringwald sm_just_works_confirm(sm_event_just_works_request_get_handle(packet)); 298*fbf7b2f3SMatthias Ringwald break; 299*fbf7b2f3SMatthias Ringwald case SM_EVENT_NUMERIC_COMPARISON_REQUEST: 300*fbf7b2f3SMatthias Ringwald printf("Confirming numeric comparison: %"PRIu32"\n", sm_event_numeric_comparison_request_get_passkey(packet)); 301*fbf7b2f3SMatthias Ringwald sm_numeric_comparison_confirm(sm_event_passkey_display_number_get_handle(packet)); 302*fbf7b2f3SMatthias Ringwald break; 303*fbf7b2f3SMatthias Ringwald case SM_EVENT_PASSKEY_DISPLAY_NUMBER: 304*fbf7b2f3SMatthias Ringwald printf("Display Passkey: %"PRIu32"\n", sm_event_passkey_display_number_get_passkey(packet)); 305*fbf7b2f3SMatthias Ringwald break; 306*fbf7b2f3SMatthias Ringwald case HCI_EVENT_HIDS_META: 307*fbf7b2f3SMatthias Ringwald switch (hci_event_hids_meta_get_subevent_code(packet)){ 308*fbf7b2f3SMatthias Ringwald case HIDS_SUBEVENT_INPUT_REPORT_ENABLE: 309*fbf7b2f3SMatthias Ringwald con_handle = hids_subevent_input_report_enable_get_con_handle(packet); 310*fbf7b2f3SMatthias Ringwald printf("Report Characteristic Subscribed %u\n", hids_subevent_input_report_enable_get_enable(packet)); 311*fbf7b2f3SMatthias Ringwald #ifndef HAVE_BTSTACK_STDIN 312*fbf7b2f3SMatthias Ringwald hid_embedded_start_mousing(); 313*fbf7b2f3SMatthias Ringwald #endif 314*fbf7b2f3SMatthias Ringwald break; 315*fbf7b2f3SMatthias Ringwald case HIDS_SUBEVENT_BOOT_KEYBOARD_INPUT_REPORT_ENABLE: 316*fbf7b2f3SMatthias Ringwald con_handle = hids_subevent_input_report_enable_get_con_handle(packet); 317*fbf7b2f3SMatthias Ringwald printf("Boot Keyboard Characteristic Subscribed %u\n", hids_subevent_boot_keyboard_input_report_enable_get_enable(packet)); 318*fbf7b2f3SMatthias Ringwald break; 319*fbf7b2f3SMatthias Ringwald case HIDS_SUBEVENT_BOOT_MOUSE_INPUT_REPORT_ENABLE: 320*fbf7b2f3SMatthias Ringwald con_handle = hids_subevent_input_report_enable_get_con_handle(packet); 321*fbf7b2f3SMatthias Ringwald printf("Boot Mouse Characteristic Subscribed %u\n", hids_subevent_boot_mouse_input_report_enable_get_enable(packet)); 322*fbf7b2f3SMatthias Ringwald break; 323*fbf7b2f3SMatthias Ringwald case HIDS_SUBEVENT_PROTOCOL_MODE: 324*fbf7b2f3SMatthias Ringwald printf("Protocol Mode: %s mode\n", hids_subevent_protocol_mode_get_protocol_mode(packet) ? "Report" : "Boot"); 325*fbf7b2f3SMatthias Ringwald break; 326*fbf7b2f3SMatthias Ringwald case HIDS_SUBEVENT_CAN_SEND_NOW: 327*fbf7b2f3SMatthias Ringwald mousing_can_send_now(); 328*fbf7b2f3SMatthias Ringwald break; 329*fbf7b2f3SMatthias Ringwald default: 330*fbf7b2f3SMatthias Ringwald break; 331*fbf7b2f3SMatthias Ringwald } 332*fbf7b2f3SMatthias Ringwald } 333*fbf7b2f3SMatthias Ringwald break; 334*fbf7b2f3SMatthias Ringwald } 335*fbf7b2f3SMatthias Ringwald } 336*fbf7b2f3SMatthias Ringwald 337*fbf7b2f3SMatthias Ringwald int btstack_main(void); 338*fbf7b2f3SMatthias Ringwald int btstack_main(void) 339*fbf7b2f3SMatthias Ringwald { 340*fbf7b2f3SMatthias Ringwald hog_mouse_setup(); 341*fbf7b2f3SMatthias Ringwald 342*fbf7b2f3SMatthias Ringwald #ifdef HAVE_BTSTACK_STDIN 343*fbf7b2f3SMatthias Ringwald btstack_stdin_setup(stdin_process); 344*fbf7b2f3SMatthias Ringwald #endif 345*fbf7b2f3SMatthias Ringwald 346*fbf7b2f3SMatthias Ringwald // turn on! 347*fbf7b2f3SMatthias Ringwald hci_power_control(HCI_POWER_ON); 348*fbf7b2f3SMatthias Ringwald 349*fbf7b2f3SMatthias Ringwald return 0; 350*fbf7b2f3SMatthias Ringwald } 351