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