xref: /btstack/src/hci_event_builder.h (revision 7d006440e74a3ae0f531f4b4ff7fcfa816f86f09)
12bef0250SMatthias Ringwald /*
22bef0250SMatthias Ringwald  * Copyright (C) 2024 BlueKitchen GmbH
32bef0250SMatthias Ringwald  *
42bef0250SMatthias Ringwald  * Redistribution and use in source and binary forms, with or without
52bef0250SMatthias Ringwald  * modification, are permitted provided that the following conditions
62bef0250SMatthias Ringwald  * are met:
72bef0250SMatthias Ringwald  *
82bef0250SMatthias Ringwald  * 1. Redistributions of source code must retain the above copyright
92bef0250SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer.
102bef0250SMatthias Ringwald  * 2. Redistributions in binary form must reproduce the above copyright
112bef0250SMatthias Ringwald  *    notice, this list of conditions and the following disclaimer in the
122bef0250SMatthias Ringwald  *    documentation and/or other materials provided with the distribution.
132bef0250SMatthias Ringwald  * 3. Neither the name of the copyright holders nor the names of
142bef0250SMatthias Ringwald  *    contributors may be used to endorse or promote products derived
152bef0250SMatthias Ringwald  *    from this software without specific prior written permission.
162bef0250SMatthias Ringwald  * 4. Any redistribution, use, or modification is done solely for
172bef0250SMatthias Ringwald  *    personal benefit and not for any commercial purpose or for
182bef0250SMatthias Ringwald  *    monetary gain.
192bef0250SMatthias Ringwald  *
202bef0250SMatthias Ringwald  * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
212bef0250SMatthias Ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
222bef0250SMatthias Ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
232bef0250SMatthias Ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN
242bef0250SMatthias Ringwald  * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
252bef0250SMatthias Ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
262bef0250SMatthias Ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
272bef0250SMatthias Ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
282bef0250SMatthias Ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
292bef0250SMatthias Ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
302bef0250SMatthias Ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
312bef0250SMatthias Ringwald  * SUCH DAMAGE.
322bef0250SMatthias Ringwald  *
332bef0250SMatthias Ringwald  * Please inquire about commercial licensing options at
342bef0250SMatthias Ringwald  * [email protected]
352bef0250SMatthias Ringwald  *
362bef0250SMatthias Ringwald  */
372bef0250SMatthias Ringwald 
382bef0250SMatthias Ringwald /**
392bef0250SMatthias Ringwald  *  @brief Builder for HCI Events
402bef0250SMatthias Ringwald  */
412bef0250SMatthias Ringwald 
422bef0250SMatthias Ringwald #ifndef HCI_EVENT_BUILDER_H
432bef0250SMatthias Ringwald #define HCI_EVENT_BUILDER_H
442bef0250SMatthias Ringwald 
452bef0250SMatthias Ringwald #include <stdint.h>
462bef0250SMatthias Ringwald 
472bef0250SMatthias Ringwald #include "bluetooth.h"
482bef0250SMatthias Ringwald 
492bef0250SMatthias Ringwald #if defined __cplusplus
502bef0250SMatthias Ringwald extern "C" {
512bef0250SMatthias Ringwald #endif
522bef0250SMatthias Ringwald 
532bef0250SMatthias Ringwald /* API_START */
542bef0250SMatthias Ringwald 
552bef0250SMatthias Ringwald typedef struct {
562bef0250SMatthias Ringwald     uint8_t * buffer;
572bef0250SMatthias Ringwald     uint16_t size;
582bef0250SMatthias Ringwald     uint16_t pos;
592bef0250SMatthias Ringwald } hci_event_builder_context_t;
602bef0250SMatthias Ringwald 
612bef0250SMatthias Ringwald /**
622bef0250SMatthias Ringwald  * @brief Initialize HCI Event Builder with buffer, event and subevent type
632bef0250SMatthias Ringwald  *
642bef0250SMatthias Ringwald  * @param context
652bef0250SMatthias Ringwald  * @param buffer
662bef0250SMatthias Ringwald  * @param size
672bef0250SMatthias Ringwald  * @param event_type
682bef0250SMatthias Ringwald  * @param subevent_type, use 0 for regular events
692bef0250SMatthias Ringwald  */
702bef0250SMatthias Ringwald void hci_event_builder_init(hci_event_builder_context_t * context, uint8_t * buffer, uint16_t size, uint8_t event_type, uint8_t subevent_type);
712bef0250SMatthias Ringwald 
722bef0250SMatthias Ringwald /**
732bef0250SMatthias Ringwald  * @brief Query remaining space in event buffer
742bef0250SMatthias Ringwald  *
752bef0250SMatthias Ringwald  * @param context
762bef0250SMatthias Ringwald  * @return number of bytes that can be added
772bef0250SMatthias Ringwald  */
782bef0250SMatthias Ringwald uint16_t hci_event_builder_remaining_space(hci_event_builder_context_t * context);
792bef0250SMatthias Ringwald 
802bef0250SMatthias Ringwald /**
812bef0250SMatthias Ringwald  * @brief Get constructed event length
822bef0250SMatthias Ringwald  * @param context
832bef0250SMatthias Ringwald  * @return number of bytes in event
842bef0250SMatthias Ringwald  */
852bef0250SMatthias Ringwald uint16_t hci_event_builder_get_length(hci_event_builder_context_t * context);
862bef0250SMatthias Ringwald 
872bef0250SMatthias Ringwald /**
882bef0250SMatthias Ringwald  * @bbrief Add uint8_t to event
892bef0250SMatthias Ringwald  * @param context
902bef0250SMatthias Ringwald  * @param value
912bef0250SMatthias Ringwald  */
922bef0250SMatthias Ringwald void hci_event_builder_add_08(hci_event_builder_context_t * context, uint8_t value);
932bef0250SMatthias Ringwald 
942bef0250SMatthias Ringwald /**
952bef0250SMatthias Ringwald  * @bbrief Add uint16_t value to event
962bef0250SMatthias Ringwald  * @param context
972bef0250SMatthias Ringwald  * @param value
982bef0250SMatthias Ringwald  */
992bef0250SMatthias Ringwald void hci_event_builder_add_16(hci_event_builder_context_t * context, uint16_t value);
1002bef0250SMatthias Ringwald 
1012bef0250SMatthias Ringwald /**
1022bef0250SMatthias Ringwald  * @bbrief Add 24 bit from uint32_t byte to event
1032bef0250SMatthias Ringwald  * @param context
1042bef0250SMatthias Ringwald  * @param value
1052bef0250SMatthias Ringwald  */
1062bef0250SMatthias Ringwald void hci_event_builder_add_24(hci_event_builder_context_t * context, uint32_t value);
1072bef0250SMatthias Ringwald 
1082bef0250SMatthias Ringwald /**
1092bef0250SMatthias Ringwald  * @bbrief Add uint32_t to event
1102bef0250SMatthias Ringwald  * @param context
1112bef0250SMatthias Ringwald  * @param value
1122bef0250SMatthias Ringwald  */
1132bef0250SMatthias Ringwald void hci_event_builder_add_32(hci_event_builder_context_t * context, uint32_t value);
1142bef0250SMatthias Ringwald 
1152bef0250SMatthias Ringwald /**
1167fc0aea0SMatthias Ringwald  * @bbrief Add uint8_t[8] in big_endian to event
1177fc0aea0SMatthias Ringwald  * @param context
1187fc0aea0SMatthias Ringwald  * @param value
1197fc0aea0SMatthias Ringwald  */
1207fc0aea0SMatthias Ringwald void hci_event_builder_add_64(hci_event_builder_context_t * context, const uint8_t * value);
1217fc0aea0SMatthias Ringwald 
1227fc0aea0SMatthias Ringwald /**
1237fc0aea0SMatthias Ringwald  * @bbrief Add uint8_t[16] in big_endian to event
1247fc0aea0SMatthias Ringwald  * @param context
1257fc0aea0SMatthias Ringwald  * @param value
1267fc0aea0SMatthias Ringwald  */
1277fc0aea0SMatthias Ringwald void hci_event_builder_add_128(hci_event_builder_context_t * context, const uint8_t * value);
1287fc0aea0SMatthias Ringwald 
1297fc0aea0SMatthias Ringwald /**
1302bef0250SMatthias Ringwald  * @bbrief Add Bluetooth address to event
1312bef0250SMatthias Ringwald  * @param context
1322bef0250SMatthias Ringwald  * @param value
1332bef0250SMatthias Ringwald  */
1342bef0250SMatthias Ringwald void hci_event_builder_add_bd_addr(hci_event_builder_context_t * context, bd_addr_t addr);
1352bef0250SMatthias Ringwald 
1362bef0250SMatthias Ringwald /**
1372bef0250SMatthias Ringwald  * @bbrief Add HCI Connection Handle to event
1382bef0250SMatthias Ringwald  * @param context
1392bef0250SMatthias Ringwald  * @param value
1402bef0250SMatthias Ringwald  */
1412bef0250SMatthias Ringwald void hci_event_builder_add_con_handle(hci_event_builder_context_t * context, hci_con_handle_t con_handle);
1422bef0250SMatthias Ringwald 
1432bef0250SMatthias Ringwald /**
144*7d006440SMatthias Ringwald  * @bbrief Add string to event using JV format: len, string, trailing zero
1452bef0250SMatthias Ringwald  * @param context
1462bef0250SMatthias Ringwald  * @param value
1472bef0250SMatthias Ringwald  */
1482bef0250SMatthias Ringwald void hci_event_builder_add_string(hci_event_builder_context_t * context, const char * text);
1492bef0250SMatthias Ringwald 
1502bef0250SMatthias Ringwald /**
1512bef0250SMatthias Ringwald  * @bbrief Add byte sequence to event
1522bef0250SMatthias Ringwald  * @param context
1532bef0250SMatthias Ringwald  * @param value
1542bef0250SMatthias Ringwald  */
1552bef0250SMatthias Ringwald void hci_event_builder_add_bytes(hci_event_builder_context_t * context, const uint8_t * data, uint16_t length);
1562bef0250SMatthias Ringwald 
1572bef0250SMatthias Ringwald /* API_END */
1582bef0250SMatthias Ringwald 
1592bef0250SMatthias Ringwald #if defined __cplusplus
1602bef0250SMatthias Ringwald }
1612bef0250SMatthias Ringwald #endif
1622bef0250SMatthias Ringwald #endif // HCI_EVENT_BUILDER_H
163