1 /* 2 * Copyright (C) 2019 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 MATTHIAS 24 * RINGWALD 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 #ifndef OBEX_MESSAGE_BUILDER_H 39 #define OBEX_MESSAGE_BUILDER_H 40 41 #if defined __cplusplus 42 extern "C" { 43 #endif 44 45 #include <stdint.h> 46 #include <stdio.h> 47 #include <stdlib.h> 48 #include <string.h> 49 50 #include "btstack_defines.h" 51 52 //------------------------------------------------------------------------------------------------------------ 53 // obex_message_builder.h 54 // 55 // Functions to incrementaly construct an OBEX message. The current length of the message is stored at 56 // offset 1 in the buffer. All functions return status code ERROR_CODE_MEMORY_CAPACITY_EXCEEDED id the 57 // buffer is too small. 58 59 /* API_START */ 60 61 /** 62 * @brief Start Connect request 63 * @param buffer 64 * @param buffer_len 65 * @param obex_version_number 66 * @param flags 67 * @param maximum_obex_packet_length 68 * @return status 69 */ 70 uint8_t obex_message_builder_request_create_connect(uint8_t * buffer, uint16_t buffer_len, uint8_t obex_version_number, uint8_t flags, uint16_t maximum_obex_packet_length); 71 72 /** 73 * @brief Start Disconnect request 74 * @param buffer 75 * @param buffer_len 76 * @param connection_id 77 * @return status 78 */ 79 uint8_t obex_message_builder_request_create_disconnect(uint8_t * buffer, uint16_t buffer_len, uint32_t connection_id); 80 81 /** 82 * @brief Create Get request 83 * @param buffer 84 * @param buffer_len 85 * @param connection_id 86 * @return status 87 */ 88 uint8_t obex_message_builder_request_create_get(uint8_t * buffer, uint16_t buffer_len, uint32_t connection_id); 89 90 /** 91 * @brief Create Put request 92 * @param buffer 93 * @param buffer_len 94 * @param connection_id 95 * @return status 96 */ 97 uint8_t obex_message_builder_request_create_put(uint8_t * buffer, uint16_t buffer_len, uint32_t connection_id); 98 99 100 /** 101 * @brief Create Abort request 102 * @param buffer 103 * @param buffer_len 104 * @param connection_id 105 * @return status 106 */ 107 uint8_t obex_message_builder_request_create_abort(uint8_t * buffer, uint16_t buffer_len, uint32_t connection_id); 108 109 /** 110 * @brief Start Set Path request 111 * @param buffer 112 * @param buffer_len 113 * @param connection_id 114 * @return status 115 */ 116 uint8_t obex_message_builder_request_create_set_path(uint8_t * buffer, uint16_t buffer_len, uint8_t flags, uint32_t connection_id); 117 118 /** 119 * @brief Add SRM Enable 120 * @param buffer 121 * @param buffer_len 122 * @return status 123 */ 124 uint8_t obex_message_builder_header_add_srm_enable(uint8_t * buffer, uint16_t buffer_len); 125 126 /** 127 * @brief Add header with single byte value (8 bit) 128 * @param buffer 129 * @param buffer_len 130 * @param header_type 131 * @param value 132 * @return status 133 */ 134 uint8_t obex_message_builder_header_add_byte(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, uint8_t value); 135 136 /** 137 * @brief Add header with word value (32 bit) 138 * @param buffer 139 * @param buffer_len 140 * @param header_type 141 * @param value 142 * @return status 143 */ 144 uint8_t obex_message_builder_header_add_word(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, uint32_t value); 145 146 /** 147 * @brief Add header with variable size 148 * @param buffer 149 * @param buffer_len 150 * @param header_type 151 * @param header_data 152 * @param header_data_length 153 * @return status 154 */ 155 uint8_t obex_message_builder_header_add_variable(uint8_t * buffer, uint16_t buffer_len, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length); 156 157 /** 158 * @brief Add name header to current request 159 * @param buffer 160 * @param buffer_len 161 * @param name 162 * @return status 163 */ 164 uint8_t obex_message_builder_header_add_name(uint8_t * buffer, uint16_t buffer_len, const char * name); 165 166 /** 167 * @brief Add target header to current request 168 * @param buffer 169 * @param buffer_len 170 * @param target 171 * @param lenght of target 172 * @return status 173 */ 174 uint8_t obex_message_builder_header_add_target(uint8_t * buffer, uint16_t buffer_len, const uint8_t * target, uint16_t length); 175 176 /** 177 * @brief Add type header to current request 178 * @param buffer 179 * @param buffer_len 180 * @param type 181 * @return status 182 */ 183 uint8_t obex_message_builder_header_add_type(uint8_t * buffer, uint16_t buffer_len, const char * type); 184 185 /** 186 * @brief Add count header to current request 187 * @param buffer 188 * @param buffer_len 189 * @param count 190 * @return status 191 */ 192 uint8_t obex_message_builder_header_add_count(uint8_t * buffer, uint16_t buffer_len, uint32_t count); 193 194 /** 195 * @brief Add application parameters header to current request 196 * @param buffer 197 * @param buffer_len 198 * @param data 199 * @param lenght of application parameters 200 * @return status 201 */ 202 uint8_t obex_message_builder_header_add_application_parameters(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint16_t length); 203 204 /** 205 * @brief Add application parameters header to current request 206 * @param buffer 207 * @param buffer_len 208 * @param data 209 * @param lenght of challenge response 210 * @return status 211 */ 212 uint8_t obex_message_builder_header_add_challenge_response(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint16_t length); 213 214 /** 215 * @brief Add body 216 * @param buffer 217 * @param buffer_len 218 * @param data 219 * @param lenght 220 * @return status 221 */ 222 uint8_t obex_message_builder_body_add_static(uint8_t * buffer, uint16_t buffer_len, const uint8_t * data, uint32_t length); 223 224 /* API_END */ 225 226 // int obex_message_builder_body_add_dynamic(uint8_t * buffer, uint16_t buffer_len, uint32_t length, void (*data_callback)(uint32_t offset, uint8_t * buffer, uint32_t len)); 227 228 #if defined __cplusplus 229 } 230 #endif 231 #endif 232 233