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