1 /**
2 	\file openobex/obex_const.h
3 	OpenOBEX library - Free implementation of the Object Exchange protocol.
4 
5 	Copyright (C) 1999-2000  Dag Brattli <dagb@cs.uit.no>
6 	Copyright (C) 1999-2000  Pontus Fuchs <pontus.fuchs@tactel.se>
7 	Copyright (C) 2001-2002  Jean Tourrilhes <jt@hpl.hp.com>
8 	Copyright (C) 2002-2006  Marcel Holtmann <marcel@holtmann.org>
9 	Copyright (C) 2002-2008  Christian W. Zuckschwerdt <zany@triq.net>
10 	Copyright (C) 2002  Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
11 	Copyright (C) 2005  Herton Ronaldo Krzesinski <herton@conectiva.com.br>
12 	Copyright (C) 2005-2008  Alex Kanavin <ak@sensi.org>
13 	Copyright (C) 2006  Johan Hedberg <johan.hedberg@nokia.com>
14 	Copyright (C) 2007-2012  Hendrik Sattler <post@hendrik-sattler.de>
15 
16 	OpenOBEX is free software; you can redistribute it and/or modify
17 	it under the terms of the GNU Lesser General Public License as
18 	published by the Free Software Foundation; either version 2.1 of
19 	the License, or (at your option) any later version.
20 
21 	This program is distributed in the hope that it will be useful,
22 	but WITHOUT ANY WARRANTY; without even the implied warranty of
23 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 	GNU Lesser General Public License for more details.
25 
26 	You should have received a copy of the GNU Lesser General Public
27 	License along with OpenOBEX. If not, see <http://www.gnu.org/>.
28  */
29 
30 #ifndef __OBEX_CONST_H
31 #define __OBEX_CONST_H
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 #include <inttypes.h>
38 #include <openobex/version.h>
39 
40 /** OBEX object tag information
41  */
42 typedef union {
43 	/** use this when header type is #OBEX_HDR_TYPE_UINT32 */
44 	uint32_t bq4;
45 	/** use this when header type is #OBEX_HDR_TYPE_UINT8 */
46 	uint8_t bq1;
47 	/** use this when header type is #OBEX_HDR_TYPE_BYTES
48 	 * or #OBEX_HDR_TYPE_UNICODE
49 	 */
50 	const uint8_t *bs;
51 } obex_headerdata_t;
52 
53 /** Function definition for custom transports
54  */
55 typedef struct {
56 	/** connect to a server (client-only) */
57 	int (*connect)(obex_t *handle, void *customdata);
58 	/** disconnect (server/client) */
59 	int (*disconnect)(obex_t *handle, void *customdata);
60 	/** listen to incoming connections (server-only) */
61 	int (*listen)(obex_t *handle, void *customdata);
62 	/** remote connection input
63 	 * This function is optional as it is an alternative to providing the
64 	 * data with #OBEX_CustomDataFeed(). The memory that 'buf' points to has
65 	 * enough room for RX MTU bytes. The minimum number of bytes needed to
66 	 * go on is specified by 'size'.*/
67 	int (*read)(obex_t *handle, void *customdata, uint8_t *buf, int size);
68 	/** remote connection output */
69 	int (*write)(obex_t *handle, void *customdata, uint8_t *buf, int len);
70 	/** directly called by #OBEX_HandleInput */
71 	int (*handleinput)(obex_t *handle, void *customdata, int timeout);
72 	void *customdata;
73 } obex_ctrans_t;
74 
75 /** USB-specific OBEX service information
76  * provided by optional Service Identification Functional Descriptor
77  * (CDC WMC specification section 6.5.2.5)
78  */
79 typedef struct {
80 	/** Role bit mask: bit 0 is set if client, unset if server */
81 	uint8_t role;
82 	/** Service UUID */
83 	uint8_t uuid[16];
84 	/** Service version */
85 	uint16_t version;
86 	/** Set if the service provides/expects
87 	 *  an OBEX Default Server (spec section 6.5.2.5.2) */
88 	int is_default_uuid;
89 } obex_usb_intf_service_t;
90 
91 /** USB-specific OBEX interface information */
92 typedef struct {
93 	/** Manufacturer, e.g. Nokia */
94 	char *manufacturer;
95 	/** Product, e.g. Nokia 6680 */
96 	char *product;
97 	/** Product serial number */
98 	char *serial;
99 	/** USB device configuration description */
100 	char *configuration;
101 	/** Control interface description */
102 	char *control_interface;
103 	/** Idle data interface description, typically empty */
104 	char *data_interface_idle;
105 	/** Active data interface description, typically empty */
106 	char *data_interface_active;
107 	/** Service information descriptor, may be NULL if absent */
108 	obex_usb_intf_service_t *service;
109 	/** USB-IF vendor ID */
110 	unsigned int idVendor;
111 	/** USB-IF product ID */
112 	unsigned int idProduct;
113 	/** Bus number that a USB device is connected to */
114 	unsigned int bus_number;
115 	/** Device address on the bus */
116 	unsigned int device_address;
117 	/** USB device interface number */
118 	unsigned int interface_number;
119 	/** Internal information for the transport layer in the library */
120 	struct obex_usb_intf_transport_t *intf;
121 } obex_usb_intf_t;
122 
123 /** IrDA-specific OBEX interface information */
124 typedef struct {
125 	/** Address of local interface */
126 	uint32_t local;
127 	/** Address of remote device */
128 	uint32_t remote;
129 	/** Description */
130 	char *info;
131 	/** Charset used for description */
132 	uint8_t	charset;
133 	/** Hint bits */
134 	uint8_t	hints[2];
135 
136 	/** service selector, filled by application, "OBEX" if NULL */
137 	const char *service;
138 } obex_irda_intf_t;
139 
140 /** Generic OBEX interface information */
141 typedef union {
142 	/** IrDA-specific OBEX interface information */
143 	obex_irda_intf_t irda;
144 	/** USB-specific OBEX interface information */
145 	obex_usb_intf_t usb;
146 } obex_interface_t;
147 
148 /** Possible modes */
149 enum obex_mode {
150 	OBEX_MODE_CLIENT = 0, /**< client mode */
151 	OBEX_MODE_SERVER = 1, /**< server mode */
152 };
153 
154 /** Possible data direction */
155 enum obex_data_direction {
156 	OBEX_DATA_NONE = 0,
157 	OBEX_DATA_IN = 1,
158 	OBEX_DATA_OUT = 2,
159 };
160 
161 /** Possible events */
162 enum obex_event {
163 	/** Progress has been made */
164 	OBEX_EV_PROGRESS = 0,
165 	/** An incoming request is about to come */
166 	OBEX_EV_REQHINT = 1,
167 	/** An incoming request has arrived */
168 	OBEX_EV_REQ = 2,
169 	/** Request has finished */
170 	OBEX_EV_REQDONE = 3,
171 	/** Link has been disconnected */
172 	OBEX_EV_LINKERR = 4,
173 	/** Malformed data encountered */
174 	OBEX_EV_PARSEERR = 5,
175 	/** Connection accepted */
176 	OBEX_EV_ACCEPTHINT = 6,
177 	/** Request was aborted */
178 	OBEX_EV_ABORT = 7,
179 	/** Need to feed more data when sending a stream */
180 	OBEX_EV_STREAMEMPTY = 8,
181 	/** Time to pick up data when receiving a stream */
182 	OBEX_EV_STREAMAVAIL = 9,
183 	/** Unexpected data, not fatal */
184 	OBEX_EV_UNEXPECTED = 10,
185 	/** First packet of an incoming request has been parsed */
186 	OBEX_EV_REQCHECK = 11,
187 	/** A Continue response was received and a new request is about to be sent.
188 	 *  CancelRequest() can be used to stop the request processing.
189 	 */
190 	OBEX_EV_CONTINUE = 12,
191 };
192 
193 /* For OBEX_Init() */
194 #define OBEX_FL_KEEPSERVER      (1 <<  1) /**< Keep the server alive */
195 #define OBEX_FL_FILTERHINT      (1 <<  2) /**< Filter devices based on hint bit */
196 #define OBEX_FL_FILTERIAS       (1 <<  3) /**< Filter devices based on IAS entry */
197 #define OBEX_FL_CLOEXEC         (1 <<  4) /**< Set CLOEXEC flag on file descriptors */
198 #define OBEX_FL_NONBLOCK        (1 <<  5) /**< Set the NONBLOCK flag on file descriptors */
199 
200 /* For OBEX_ObjectAddHeader */
201 #define OBEX_FL_FIT_ONE_PACKET  (1 <<  0) /**< This header must fit in one packet */
202 #define OBEX_FL_STREAM_START    (1 <<  1) /**< Start of streaming body */
203 #define OBEX_FL_STREAM_DATA     (1 <<  2) /**< Set data for body stream */
204 #define OBEX_FL_STREAM_DATAEND  (1 <<  3) /**< Set data (or no data) for body stream and finish it */
205 #define OBEX_FL_SUSPEND         (1 <<  4) /**< Suspend after sending this header */
206 #define OBEX_FL_STREAM_CONTINUE (1 <<  5) /**< Continue body stream after all remaining headers */
207 
208 /** Possible transports */
209 enum obex_transport_type {
210 	OBEX_TRANS_IRDA = 1,      /**< Infrared */
211 	OBEX_TRANS_INET = 2,      /**< TCP over IPv4/v6 */
212 	OBEX_TRANS_CUSTOM = 3,    /**< Custom transport with callbacks */
213 	OBEX_TRANS_BLUETOOTH = 4, /**< Bluetooth RFCOMM */
214 	OBEX_TRANS_FD = 5,        /**< file descriptors */
215 	OBEX_TRANS_USB = 6,       /**< USB CDC OBEX */
216 };
217 
218 /* Standard headers */
219 #define OBEX_HDR_TYPE_SHIFT	6
220 #define OBEX_HDR_TYPE_MASK	0xc0
221 #define OBEX_HDR_ID_MASK	0x3f
222 
223 /** Type part of an obex header value */
224 enum obex_hdr_type {
225 	/** used as invalid return value */
226 	OBEX_HDR_TYPE_INVALID = -1,
227 	/** zero terminated unicode string (network byte order) */
228 	OBEX_HDR_TYPE_UNICODE = (0 << OBEX_HDR_TYPE_SHIFT),
229 	/** byte array */
230 	OBEX_HDR_TYPE_BYTES   = (1 << OBEX_HDR_TYPE_SHIFT),
231 	/** 8bit unsigned integer */
232 	OBEX_HDR_TYPE_UINT8   = (2 << OBEX_HDR_TYPE_SHIFT),
233 	/** 32bit unsigned integer */
234 	OBEX_HDR_TYPE_UINT32  = (3 << OBEX_HDR_TYPE_SHIFT),
235 };
236 
237 /** Identifier part of an obex header value */
238 enum obex_hdr_id {
239 	/** used as invalid return value */
240 	OBEX_HDR_ID_INVALID    = -1,
241 	/** Number of objects (used by connect) */
242 	OBEX_HDR_ID_COUNT        = 0,
243 	/** Name of the object */
244 	OBEX_HDR_ID_NAME         = 1,
245 	/** Type of the object */
246 	OBEX_HDR_ID_TYPE         = 2,
247 	/** Total length of object */
248 	OBEX_HDR_ID_LENGTH       = 3,
249 	/** Last modification time of (ISO8601) */
250 	OBEX_HDR_ID_TIME         = 4,
251 	/** Description of object */
252 	OBEX_HDR_ID_DESCRIPTION  = 5,
253 	/** Identifies the target for the object */
254 	OBEX_HDR_ID_TARGET       = 6,
255 	/** An HTTP 1.x header */
256 	OBEX_HDR_ID_HTTP         = 7,
257 	/** Data part of the object */
258 	OBEX_HDR_ID_BODY         = 8,
259 	/** Last data part of the object */
260 	OBEX_HDR_ID_BODY_END     = 9,
261 	/** Identifies the sender of the object */
262 	OBEX_HDR_ID_WHO          = 10,
263 	/** Connection identifier */
264 	OBEX_HDR_ID_CONNECTION   = 11,
265 	/** Application parameters */
266 	OBEX_HDR_ID_APPARAM      = 12,
267 	/** Authentication challenge */
268 	OBEX_HDR_ID_AUTHCHAL     = 13,
269 	/** Authentication response */
270 	OBEX_HDR_ID_AUTHRESP     = 14,
271 	/** indicates the creator of an object */
272 	OBEX_HDR_ID_CREATOR      = 15,
273 	/** uniquely identifies the network client (OBEX server) */
274 	OBEX_HDR_ID_WANUUID      = 16,
275 	/** OBEX Object class of object */
276 	OBEX_HDR_ID_OBJECTCLASS  = 17,
277 	/** Parameters used in session commands/responses */
278 	OBEX_HDR_ID_SESSIONPARAM = 18,
279 	/** Sequence number used in each OBEX packet for reliability */
280 	OBEX_HDR_ID_SESSIONSEQ   = 19,
281 	/** Specifies the action for the ACTION command */
282 	OBEX_HDR_ID_ACTION_ID    = 20,
283 	/** Destination object name */
284 	OBEX_HDR_ID_DESTNAME     = 21,
285 	/** bit mask for setting permissions */
286 	OBEX_HDR_ID_PERMISSIONS  = 22,
287 	/** response mode selection */
288 	OBEX_HDR_ID_SRM          = 23,
289 	/** flags for single response mode */
290 	OBEX_HDR_ID_SRM_FLAGS    = 24,
291 };
292 
293 #define OBEX_HDR_EMPTY		0x00	/* Empty header (buggy OBEX servers) */
294 #define OBEX_HDR_COUNT		(OBEX_HDR_ID_COUNT        | OBEX_HDR_TYPE_UINT32 )
295 #define OBEX_HDR_NAME		(OBEX_HDR_ID_NAME         | OBEX_HDR_TYPE_UNICODE)
296 #define OBEX_HDR_TYPE		(OBEX_HDR_ID_TYPE         | OBEX_HDR_TYPE_BYTES  )
297 #define OBEX_HDR_LENGTH		(OBEX_HDR_ID_LENGTH       | OBEX_HDR_TYPE_UINT32 )
298 #define OBEX_HDR_TIME		(OBEX_HDR_ID_TIME         | OBEX_HDR_TYPE_BYTES  ) /* Format: ISO 8601 */
299 #define OBEX_HDR_TIME2		(OBEX_HDR_ID_TIME         | OBEX_HDR_TYPE_UINT32 ) /* Deprecated use HDR_TIME instead */
300 #define OBEX_HDR_DESCRIPTION	(OBEX_HDR_ID_DESCRIPTION  | OBEX_HDR_TYPE_UNICODE)
301 #define OBEX_HDR_TARGET		(OBEX_HDR_ID_TARGET       | OBEX_HDR_TYPE_BYTES  )
302 #define OBEX_HDR_HTTP		(OBEX_HDR_ID_HTTP         | OBEX_HDR_TYPE_BYTES  )
303 #define OBEX_HDR_BODY		(OBEX_HDR_ID_BODY         | OBEX_HDR_TYPE_BYTES  )
304 #define OBEX_HDR_BODY_END	(OBEX_HDR_ID_BODY_END     | OBEX_HDR_TYPE_BYTES  )
305 #define OBEX_HDR_WHO		(OBEX_HDR_ID_WHO          | OBEX_HDR_TYPE_BYTES  )
306 #define OBEX_HDR_CONNECTION	(OBEX_HDR_ID_CONNECTION   | OBEX_HDR_TYPE_UINT32 )
307 #define OBEX_HDR_APPARAM	(OBEX_HDR_ID_APPARAM      | OBEX_HDR_TYPE_BYTES  )
308 #define OBEX_HDR_AUTHCHAL	(OBEX_HDR_ID_AUTHCHAL     | OBEX_HDR_TYPE_BYTES  )
309 #define OBEX_HDR_AUTHRESP	(OBEX_HDR_ID_AUTHRESP     | OBEX_HDR_TYPE_BYTES  )
310 #define OBEX_HDR_CREATOR	(OBEX_HDR_ID_CREATOR      | OBEX_HDR_TYPE_BYTES  )
311 #define OBEX_HDR_WANUUID	(OBEX_HDR_ID_WANUUID      | OBEX_HDR_TYPE_BYTES  )
312 #define OBEX_HDR_OBJECTCLASS	(OBEX_HDR_ID_OBJECTCLASS  | OBEX_HDR_TYPE_BYTES  )
313 #define OBEX_HDR_SESSIONPARAM	(OBEX_HDR_ID_SESSIONPARAM | OBEX_HDR_TYPE_BYTES  )
314 #define OBEX_HDR_SESSIONSEQ	(OBEX_HDR_ID_SESSIONSEQ   | OBEX_HDR_TYPE_UINT8  )
315 #define OBEX_HDR_ACTION_ID	(OBEX_HDR_ID_ACTION_ID    | OBEX_HDR_TYPE_UINT8  )
316 #define OBEX_HDR_DESTNAME	(OBEX_HDR_ID_DESTNAME     | OBEX_HDR_TYPE_UNICODE)
317 #define OBEX_HDR_PERMISSIONS	(OBEX_HDR_ID_PERMISSIONS  | OBEX_HDR_TYPE_UINT32 )
318 #define OBEX_HDR_SRM            (OBEX_HDR_ID_SRM          | OBEX_HDR_TYPE_UINT8  )
319 #define OBEX_HDR_SRM_FLAGS      (OBEX_HDR_ID_SRM_FLAGS    | OBEX_HDR_TYPE_UINT8  )
320 
321 /** Obex commands */
322 enum obex_cmd {
323 	OBEX_CMD_CONNECT	= 0x00,
324 	OBEX_CMD_DISCONNECT	= 0x01,
325 	OBEX_CMD_PUT		= 0x02,
326 	OBEX_CMD_GET		= 0x03,
327 	OBEX_CMD_SETPATH	= 0x05,
328 	OBEX_CMD_ACTION		= 0x06,
329 	OBEX_CMD_SESSION	= 0x07, /**< used for reliable session support */
330 	OBEX_CMD_ABORT		= 0x7f,
331 };
332 #define OBEX_FINAL		0x80
333 
334 /** Obex responses */
335 enum obex_rsp {
336 	OBEX_RSP_CONTINUE		= 0x10,
337 	OBEX_RSP_SWITCH_PRO		= 0x11,
338 	OBEX_RSP_SUCCESS		= 0x20,
339 	OBEX_RSP_CREATED		= 0x21,
340 	OBEX_RSP_ACCEPTED		= 0x22,
341 	OBEX_RSP_NON_AUTHORITATIVE	= 0x23,
342 	OBEX_RSP_NO_CONTENT		= 0x24,
343 	OBEX_RSP_RESET_CONTENT		= 0x25,
344 	OBEX_RSP_PARTIAL_CONTENT	= 0x26,
345 	OBEX_RSP_MULTIPLE_CHOICES	= 0x30,
346 	OBEX_RSP_MOVED_PERMANENTLY	= 0x31,
347 	OBEX_RSP_MOVED_TEMPORARILY	= 0x32,
348 	OBEX_RSP_SEE_OTHER		= 0x33,
349 	OBEX_RSP_NOT_MODIFIED		= 0x34,
350 	OBEX_RSP_USE_PROXY		= 0x35,
351 	OBEX_RSP_BAD_REQUEST		= 0x40,
352 	OBEX_RSP_UNAUTHORIZED		= 0x41,
353 	OBEX_RSP_PAYMENT_REQUIRED	= 0x42,
354 	OBEX_RSP_FORBIDDEN		= 0x43,
355 	OBEX_RSP_NOT_FOUND		= 0x44,
356 	OBEX_RSP_METHOD_NOT_ALLOWED	= 0x45,
357 	OBEX_RSP_NOT_ACCEPTABLE		= 0x46,
358 	OBEX_RSP_PROXY_AUTH_REQUIRED	= 0x47,
359 	OBEX_RSP_REQUEST_TIME_OUT	= 0x48,
360 	OBEX_RSP_CONFLICT		= 0x49,
361 	OBEX_RSP_GONE			= 0x4a,
362 	OBEX_RSP_LENGTH_REQUIRED	= 0x4b,
363 	OBEX_RSP_PRECONDITION_FAILED	= 0x4c,
364 	OBEX_RSP_REQ_ENTITY_TOO_LARGE	= 0x4d,
365 	OBEX_RSP_REQ_URL_TOO_LARGE	= 0x4e,
366 	OBEX_RSP_UNSUPPORTED_MEDIA_TYPE	= 0x4f,
367 	OBEX_RSP_INTERNAL_SERVER_ERROR	= 0x50,
368 	OBEX_RSP_NOT_IMPLEMENTED	= 0x51,
369 	OBEX_RSP_BAD_GATEWAY		= 0x52,
370 	OBEX_RSP_SERVICE_UNAVAILABLE	= 0x53,
371 	OBEX_RSP_GATEWAY_TIMEOUT	= 0x54,
372 	OBEX_RSP_VERSION_NOT_SUPPORTED	= 0x55,
373 	OBEX_RSP_DATABASE_FULL		= 0x60,
374 	OBEX_RSP_DATABASE_LOCKED	= 0x61,
375 };
376 
377 /** Obex response modes */
378 enum obex_rsp_mode {
379 	OBEX_RSP_MODE_NORMAL = 0, /**< normal response mode */
380 	OBEX_RSP_MODE_SINGLE = 1, /**< single response mode (SRM) */
381 };
382 
383 /* Min, Max and default transport MTU */
384 #define OBEX_DEFAULT_MTU	1024
385 #define OBEX_MINIMUM_MTU	255
386 #define OBEX_MAXIMUM_MTU	65535
387 
388 /** Optimum MTU for various transport (optimum for throughput).
389  * The user/application has to set them via OBEX_SetTransportMTU().
390  * If you are worried about safety or latency, stick with the current
391  * default... - Jean II */
392 #define OBEX_IRDA_OPT_MTU	(7 * 2039)	/* 7 IrLAP frames */
393 
394 #ifdef __cplusplus
395 }
396 #endif
397 
398 #endif /* __OBEX_CONST_H */
399