1 /* 2 * Copyright (C) 2020 BlueKitchen GmbH 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the copyright holders nor the names of 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 4. Any redistribution, use, or modification is done solely for 17 * personal benefit and not for any commercial purpose or for 18 * monetary gain. 19 * 20 * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 24 * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 27 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 28 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 29 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 30 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * Please inquire about commercial licensing options at 34 * [email protected] 35 * 36 */ 37 38 /* 39 * hci_event.h 40 */ 41 42 #ifndef HCI_EVENT_H 43 #define HCI_EVENT_H 44 45 #include "bluetooth.h" 46 47 #include <stdint.h> 48 #include <stdarg.h> 49 50 #if defined __cplusplus 51 extern "C" { 52 #endif 53 54 /** 55 * compact HCI Event packet description 56 * no subevent_code field -> subevnt_code == 0 57 */ 58 typedef struct { 59 uint8_t event_code; 60 uint8_t subevent_code; 61 const char *format; 62 } hci_event_t; 63 64 /** 65 * construct HCI Event based on template 66 * 67 * Format: 68 * 1,2,3,4: one to four byte value 69 * H: HCI connection handle 70 * B: Bluetooth Baseband Address (BD_ADDR) 71 * D: 8 byte data block 72 * P: 16 byte data block. 73 * Q: 32 byte data block, e.g. for X and Y coordinates of P-256 public key 74 * J: 1-byte length of following variable-length data blob 'V', length is included in packet 75 * K: 1-byte length of following variable-length data blob 'V', length is not included in packet 76 * V: variable-length data blob of len provided in 'J' field 77 */ 78 uint16_t hci_event_create_from_template_and_arglist(uint8_t *hci_buffer, uint16_t buffer_size, const hci_event_t *event, va_list argptr); 79 80 81 uint16_t hci_event_create_from_template_and_arguments(uint8_t *hci_buffer, uint16_t buffer_size, const hci_event_t *event, ...); 82 83 /* LE Events */ 84 extern const hci_event_t hci_event_hardware_error; 85 extern const hci_event_t hci_event_command_complete; 86 extern const hci_event_t hci_event_disconnection_complete; 87 extern const hci_event_t hci_event_number_of_completed_packets_1; 88 extern const hci_event_t hci_event_transport_packet_sent; 89 90 /* LE Subevents */ 91 extern const hci_event_t hci_subevent_le_connection_complete; 92 93 94 #if defined __cplusplus 95 } 96 #endif 97 98 #endif // HCI_EVENT_H 99