xref: /btstack/src/classic/goep_client.h (revision b29e92f97ffd81bc8a1057634c8d1552fc963a6a)
1 /*
2  * Copyright (C) 2014 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  * @title GOEP Client
40  *
41  * Communicate with remote OBEX server - General Object Exchange
42  *
43  */
44 
45 #ifndef GOEP_CLIENT_H
46 #define GOEP_CLIENT_H
47 
48 #if defined __cplusplus
49 extern "C" {
50 #endif
51 
52 #include <stdlib.h>
53 #include <string.h>
54 
55 #include "btstack_defines.h"
56 
57 /* API_START */
58 
59 // remote does not expose PBAP features in SDP record
60 #define PBAP_FEATURES_NOT_PRESENT ((uint32_t) -1)
61 
62 /**
63  * Setup GOEP Client
64  */
65 void goep_client_init(void);
66 
67 /*
68  * @brief Create GOEP connection to a GEOP server with specified UUID on a remote deivce.
69  * @param handler
70  * @param addr
71  * @param uuid
72  * @param out_cid to use for further commands
73  * @result status
74 */
75 uint8_t goep_client_create_connection(btstack_packet_handler_t handler, bd_addr_t addr, uint16_t uuid, uint16_t * out_cid);
76 
77 /**
78  * @brief Disconnects GOEP connection with given identifier.
79  * @param goep_cid
80  * @return status
81  */
82 uint8_t goep_client_disconnect(uint16_t goep_cid);
83 
84 /**
85  * @brief Request emission of GOEP_SUBEVENT_CAN_SEND_NOW as soon as possible
86  * @note GOEP_SUBEVENT_CAN_SEND_NOW might be emitted during call to this function
87  *       so packet handler should be ready to handle it
88  * @param goep_cid
89  */
90 void goep_client_request_can_send_now(uint16_t goep_cid);
91 
92 /**
93  * @brief Get Opcode from last created request, needed for parsing of OBEX response packet
94  * @param goep_cid
95  * @return opcode
96  */
97 uint8_t goep_client_get_request_opcode(uint16_t goep_cid);
98 
99 /**
100  * @brief Get PBAP Supported Features found in SDP record during connect
101  */
102 uint32_t goep_client_get_pbap_supported_features(uint16_t goep_cid);
103 
104 /**
105  * @brief Check if GOEP 2.0 or higher features can be used
106  * @return true if GOEP Version 2.0 or higher
107  */
108 bool goep_client_version_20_or_higher(uint16_t goep_cid);
109 
110 /**
111  * @brief Set Connection ID used for newly created requests
112  * @param goep_cid
113  */
114 void goep_client_set_connection_id(uint16_t goep_cid, uint32_t connection_id);
115 
116 /**
117  * @brief Start Connect request
118  * @param goep_cid
119  * @param obex_version_number
120  * @param flags
121  * @param maximum_obex_packet_length
122  */
123 void goep_client_request_create_connect(uint16_t goep_cid, uint8_t obex_version_number, uint8_t flags, uint16_t maximum_obex_packet_length);
124 
125 /**
126  * @brief Start Disconnect request
127  * @param goep_cid
128  */
129 void goep_client_request_create_disconnect(uint16_t goep_cid);
130 
131 /**
132  * @brief Create Get request
133  * @param goep_cid
134  */
135 void goep_client_request_create_get(uint16_t goep_cid);
136 
137 /**
138  * @brief Create Abort request
139  * @param goep_cid
140  */
141 void goep_client_request_create_abort(uint16_t goep_cid);
142 
143 /**
144  * @brief Start Set Path request
145  * @param goep_cid
146  */
147 void goep_client_request_create_set_path(uint16_t goep_cid, uint8_t flags);
148 
149 /**
150  * @brief Create Put request
151  * @param goep_cid
152  */
153 void goep_client_request_create_put(uint16_t goep_cid);
154 
155 /**
156  * @brief Get max size of body data that can be added to current response with goep_client_body_add_static
157  * @param goep_cid
158  * @param data
159  * @param length
160  * @return size in bytes or 0
161  */
162 uint16_t goep_client_request_get_max_body_size(uint16_t goep_cid);
163 
164 /**
165  * @brief Add SRM Enable
166  * @param goep_cid
167  */
168 void goep_client_header_add_srm_enable(uint16_t goep_cid);
169 
170 /**
171  * @brief Add header with single byte value (8 bit)
172  * @param goep_cid
173  * @param header_type
174  * @param value
175  */
176 void goep_client_header_add_byte(uint16_t goep_cid, uint8_t header_type, uint8_t value);
177 
178 /**
179  * @brief Add header with word value (32 bit)
180  * @param goep_cid
181  * @param header_type
182  * @param value
183  */
184 void goep_client_header_add_word(uint16_t goep_cid, uint8_t header_type, uint32_t value);
185 
186 /**
187  * @brief Add header with variable size
188  * @param goep_cid
189  * @param header_type
190  * @param header_data
191  * @param header_data_length
192  */
193 void goep_client_header_add_variable(uint16_t goep_cid, uint8_t header_type, const uint8_t * header_data, uint16_t header_data_length);
194 
195 /**
196  * @brief Add name header to current request
197  * @param goep_cid
198  * @param name
199  */
200 void goep_client_header_add_name(uint16_t goep_cid, const char * name);
201 
202 /**
203  * @brief Add name header to current request
204  * @param goep_cid
205  * @param name
206  * @param name_len
207  */
208 void goep_client_header_add_name_prefix(uint16_t goep_cid, const char * name, uint16_t name_len);
209 
210 /**
211  * @brief Add target header to current request
212  * @param goep_cid
213  * @param target
214  * @param length of target
215  */
216 void goep_client_header_add_target(uint16_t goep_cid, const uint8_t * target, uint16_t length);
217 
218 /**
219  * @brief Add type header to current request
220  * @param goep_cid
221  * @param type
222  */
223 void goep_client_header_add_type(uint16_t goep_cid, const char * type);
224 
225 /**
226  * @brief Add count header to current request
227  * @param goep_cid
228  * @param count
229  */
230 void goep_client_header_add_count(uint16_t goep_cid, uint32_t count);
231 
232 /**
233  * @brief Add application parameters header to current request
234  * @param goep_cid
235  * @param data
236  * @param lenght of application parameters
237  */
238 void goep_client_header_add_application_parameters(uint16_t goep_cid, const uint8_t * data, uint16_t length);
239 
240 /**
241  * @brief Add application parameters header to current request
242  * @param goep_cid
243  * @param data
244  * @param lenght of challenge response
245  */
246 void goep_client_header_add_challenge_response(uint16_t goep_cid, const uint8_t * data, uint16_t length);
247 
248 /**
249  * @brief Add body
250  * @param goep_cid
251  * @param data
252  * @param lenght
253  */
254 void goep_client_body_add_static(uint16_t goep_cid, const uint8_t * data, uint32_t length);
255 
256 /**
257  * @brief Execute prepared request
258  * @param goep_cid
259  * @param daa
260  */
261 int goep_client_execute(uint16_t goep_cid);
262 
263 /**
264  * @brief De-Init GOEP Client
265  */
266 void goep_client_deinit(void);
267 
268 /* API_END */
269 
270 // int goep_client_body_add_dynamic(uint16_t goep_cid, uint32_t length, void (*data_callback)(uint32_t offset, uint8_t * buffer, uint32_t len));
271 
272 #if defined __cplusplus
273 }
274 #endif
275 #endif
276 
277