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