150e8757dSMatthias Ringwald /* 250e8757dSMatthias Ringwald * Copyright (C) 2024 BlueKitchen GmbH 350e8757dSMatthias Ringwald * 450e8757dSMatthias Ringwald * Redistribution and use in source and binary forms, with or without 550e8757dSMatthias Ringwald * modification, are permitted provided that the following conditions 650e8757dSMatthias Ringwald * are met: 750e8757dSMatthias Ringwald * 850e8757dSMatthias Ringwald * 1. Redistributions of source code must retain the above copyright 950e8757dSMatthias Ringwald * notice, this list of conditions and the following disclaimer. 1050e8757dSMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright 1150e8757dSMatthias Ringwald * notice, this list of conditions and the following disclaimer in the 1250e8757dSMatthias Ringwald * documentation and/or other materials provided with the distribution. 1350e8757dSMatthias Ringwald * 3. Neither the name of the copyright holders nor the names of 1450e8757dSMatthias Ringwald * contributors may be used to endorse or promote products derived 1550e8757dSMatthias Ringwald * from this software without specific prior written permission. 1650e8757dSMatthias Ringwald * 4. Any redistribution, use, or modification is done solely for 1750e8757dSMatthias Ringwald * personal benefit and not for any commercial purpose or for 1850e8757dSMatthias Ringwald * monetary gain. 1950e8757dSMatthias Ringwald * 2050e8757dSMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS 2150e8757dSMatthias Ringwald * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2250e8757dSMatthias Ringwald * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 2350e8757dSMatthias Ringwald * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BLUEKITCHEN 2450e8757dSMatthias Ringwald * GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 2550e8757dSMatthias Ringwald * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 2650e8757dSMatthias Ringwald * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 2750e8757dSMatthias Ringwald * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 2850e8757dSMatthias Ringwald * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 2950e8757dSMatthias Ringwald * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 3050e8757dSMatthias Ringwald * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3150e8757dSMatthias Ringwald * SUCH DAMAGE. 3250e8757dSMatthias Ringwald * 3350e8757dSMatthias Ringwald * Please inquire about commercial licensing options at 3450e8757dSMatthias Ringwald * [email protected] 3550e8757dSMatthias Ringwald * 3650e8757dSMatthias Ringwald */ 3750e8757dSMatthias Ringwald 3850e8757dSMatthias Ringwald /** 3950e8757dSMatthias Ringwald * @brief TODO 4050e8757dSMatthias Ringwald */ 4150e8757dSMatthias Ringwald 4250e8757dSMatthias Ringwald #ifndef BTSTACK_TLV_BUILDER_H 4350e8757dSMatthias Ringwald #define BTSTACK_TLV_BUILDER_H 4450e8757dSMatthias Ringwald 4550e8757dSMatthias Ringwald #include <stdint.h> 4650e8757dSMatthias Ringwald 4750e8757dSMatthias Ringwald #if defined __cplusplus 4850e8757dSMatthias Ringwald extern "C" { 4950e8757dSMatthias Ringwald #endif 5050e8757dSMatthias Ringwald 5150e8757dSMatthias Ringwald 5250e8757dSMatthias Ringwald /* API_START */ 5350e8757dSMatthias Ringwald 5450e8757dSMatthias Ringwald typedef struct { 5550e8757dSMatthias Ringwald uint8_t * buffer; 5650e8757dSMatthias Ringwald uint16_t size; 5750e8757dSMatthias Ringwald uint16_t len_pos; 5850e8757dSMatthias Ringwald uint16_t write_pos; 5950e8757dSMatthias Ringwald } btstack_tlv_builder_context_t; 6050e8757dSMatthias Ringwald 6150e8757dSMatthias Ringwald /** 6250e8757dSMatthias Ringwald * @brief Initialize Length/Tag/Value builder with buffer and size for 8-bit tag and length fields 6350e8757dSMatthias Ringwald * 6450e8757dSMatthias Ringwald * @param context 6550e8757dSMatthias Ringwald * @param buffer 6650e8757dSMatthias Ringwald * @param size 6750e8757dSMatthias Ringwald */ 68*d44a2fefSMatthias Ringwald void btstack_tlv_builder_init(btstack_tlv_builder_context_t * context, uint8_t * buffer, uint16_t size); 6950e8757dSMatthias Ringwald 7050e8757dSMatthias Ringwald /** 7150e8757dSMatthias Ringwald * @brief Query remaining space in buffer 7250e8757dSMatthias Ringwald * 7350e8757dSMatthias Ringwald * @param context 7450e8757dSMatthias Ringwald * @return number of bytes that can be added 7550e8757dSMatthias Ringwald */ 76*d44a2fefSMatthias Ringwald uint16_t btstack_tlv_builder_remaining_space(btstack_tlv_builder_context_t * context); 7750e8757dSMatthias Ringwald 7850e8757dSMatthias Ringwald /** 7950e8757dSMatthias Ringwald * @brief Get constructed event length 8050e8757dSMatthias Ringwald * @param context 8150e8757dSMatthias Ringwald * @return number of bytes in event 8250e8757dSMatthias Ringwald */ 83*d44a2fefSMatthias Ringwald uint16_t btstack_tlv_builder_get_length(btstack_tlv_builder_context_t * context); 8450e8757dSMatthias Ringwald 8550e8757dSMatthias Ringwald /** 8650e8757dSMatthias Ringwald * @brief Add tag 8750e8757dSMatthias Ringwald * @param context 8850e8757dSMatthias Ringwald * @return number of bytes in event 8950e8757dSMatthias Ringwald */ 90*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_tag(btstack_tlv_builder_context_t * context, uint8_t tag); 9150e8757dSMatthias Ringwald 9250e8757dSMatthias Ringwald /** 9350e8757dSMatthias Ringwald * @bbrief Add uint8_t to current tag 9450e8757dSMatthias Ringwald * @param context 9550e8757dSMatthias Ringwald * @param value 9650e8757dSMatthias Ringwald */ 97*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_08(btstack_tlv_builder_context_t * context, uint8_t value); 9850e8757dSMatthias Ringwald 9950e8757dSMatthias Ringwald /** 10050e8757dSMatthias Ringwald * @bbrief Add uint16_t value to current tag 10150e8757dSMatthias Ringwald * @param context 10250e8757dSMatthias Ringwald * @param value 10350e8757dSMatthias Ringwald */ 104*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_big_endian_16(btstack_tlv_builder_context_t * context, uint16_t value); 10550e8757dSMatthias Ringwald 10650e8757dSMatthias Ringwald /** 10750e8757dSMatthias Ringwald * @bbrief Add 24 bit from uint32_t byte to current tag 10850e8757dSMatthias Ringwald * @param context 10950e8757dSMatthias Ringwald * @param value 11050e8757dSMatthias Ringwald */ 111*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_big_endian_24(btstack_tlv_builder_context_t * context, uint32_t value); 11250e8757dSMatthias Ringwald 11350e8757dSMatthias Ringwald /** 11450e8757dSMatthias Ringwald * @bbrief Add uint32_t to current tag 11550e8757dSMatthias Ringwald * @param context 11650e8757dSMatthias Ringwald * @param value 11750e8757dSMatthias Ringwald */ 118*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_big_endian_32(btstack_tlv_builder_context_t * context, uint32_t value); 11950e8757dSMatthias Ringwald 12050e8757dSMatthias Ringwald /** 12150e8757dSMatthias Ringwald * @bbrief Add byte sequence to current tag 12250e8757dSMatthias Ringwald * @param context 12350e8757dSMatthias Ringwald * @param value 12450e8757dSMatthias Ringwald */ 125*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_bytes(btstack_tlv_builder_context_t * context, const uint8_t * data, uint16_t length); 12650e8757dSMatthias Ringwald 12750e8757dSMatthias Ringwald /** 12850e8757dSMatthias Ringwald * @bbrief Add string to current tag 12950e8757dSMatthias Ringwald * @param context 13050e8757dSMatthias Ringwald * @param value 13150e8757dSMatthias Ringwald */ 132*d44a2fefSMatthias Ringwald void btstack_tlv_builder_add_string(btstack_tlv_builder_context_t * context, const char * text); 13350e8757dSMatthias Ringwald 13450e8757dSMatthias Ringwald #if defined __cplusplus 13550e8757dSMatthias Ringwald } 13650e8757dSMatthias Ringwald #endif 13750e8757dSMatthias Ringwald #endif // BTSTACK_TLV_BUILDER_H 138