obex.h

Go to the documentation of this file.
00001 /*
00002  Copyright (c) 2007, Forkbeard team
00003 
00004  All rights reserved.
00005 
00006  Licensed under BSD license. See License.txt
00007 */
00008 
00009 
00010 #ifndef __OBEX_H__
00011 #define __OBEX_H__
00012 
00083 #ifdef __cplusplus
00084 extern "C" {
00085 #endif
00086 
00087 
00100 typedef enum _ObexPacketHeader
00101 {
00102     OBEX_PACKET_HEADER_UNKNOWN      = 0,
00103 
00105     OBEX_PACKET_HEADER_NAME         = 0x01,
00106 
00108     OBEX_PACKET_HEADER_DESCRIPTION  = 0x05,
00109 
00111     OBEX_PACKET_HEADER_TYPE         = 0x42,
00112 
00113     /* Time in ISO 8601 format. Preferred time format. OPTIONAL */
00114     OBEX_PACKET_HEADER_TIME         = 0x44,
00115 
00116     /* Name of the service the operation is targeted to. Used with CONNECT, PUT.
00117        When used, must be the first header in the packet. Cannot be used together with CONNECTION_ID header in request, 
00118        but can be used together with CONNECTION_ID header in response. */
00119     OBEX_PACKET_HEADER_TARGET       = 0x46,
00120 
00122     OBEX_PACKET_HEADER_HTTP         = 0x47,
00123 
00126     OBEX_PACKET_HEADER_BODY         = 0x48,
00127     OBEX_PACKET_HEADER_EOF_BODY     = 0x49,
00128 
00130     OBEX_PACKET_HEADER_WHO          = 0x4A,
00131 
00133     OBEX_PACKET_HEADER_APP_PARAMS   = 0x4C,
00134 
00136     OBEX_PACKET_HEADER_AUTH_CHG     = 0x4D,
00137 
00139     OBEX_PACKET_HEADER_AUTH_RES     = 0x4E,
00140 
00142     OBEX_PACKET_HEADER_WAN_UUID     = 0x50,
00143 
00145     OBEX_PACKET_HEADER_CLASS        = 0x51,
00146 
00148     OBEX_PACKET_HEADER_SESSION_PARAM = 0x52,
00149 
00152     OBEX_PACKET_HEADER_SESSION_SEG  = 0x93,
00153 
00155     OBEX_PACKET_HEADER_COUNT        = 0xC0,
00156 
00159     OBEX_PACKET_HEADER_LENGTH       = 0xC3,
00160 
00162     OBEX_PACKET_HEADER_TIME2        = 0xC4,
00163 
00166     OBEX_PACKET_HEADER_CONNECTION_ID = 0xCB,
00167 
00169     OBEX_PACKET_HEADER_CREATOR       = 0xCF,
00170 
00171 } ObexPacketHeader;
00172 
00174 typedef enum _ObexPacketOperation
00175 {
00176     OBEX_PACKET_OPERATION_UNKNOWN       = 0,
00177 
00178     OBEX_PACKET_OPERATION_CONNECT       = 0x80,
00179     OBEX_PACKET_OPERATION_DISCONNECT    = 0x81,
00180 
00181     OBEX_PACKET_OPERATION_PUT           = 0x02,
00182     OBEX_PACKET_OPERATION_PUT_FINAL     = 0x82,
00183 
00184     OBEX_PACKET_OPERATION_GET           = 0x03,
00185     OBEX_PACKET_OPERATION_GET_FINAL     = 0x83,
00186 
00187     OBEX_PACKET_OPERATION_SET_PATH      = 0x85,
00188 
00189     OBEX_PACKET_OPERATION_SESSION       = 0x87,
00190 
00191     OBEX_PACKET_OPERATION_ABORT         = 0xFF,    
00192 } ObexPacketOperation;
00193 
00195 typedef enum _ObexResponseCode
00196 {
00197     OBEX_RESPONSE_CODE_UNKNOWN       = 0,
00198     OBEX_RESPONSE_CODE_CONTINUE      = 0x10,    
00199 
00200     OBEX_RESPONSE_CODE_SUCCESS       = 0x20,    
00201 
00202     OBEX_RESPONSE_CODE_BAD_REQUEST    = 0x40,    
00203     OBEX_RESPONSE_CODE_UNAUTHORIZED   = 0x41,    
00204     OBEX_RESPONSE_CODE_PAYREQ         = 0x42,    
00205     OBEX_RESPONSE_CODE_FORBIDDEN      = 0x43,    
00206     OBEX_RESPONSE_CODE_NOTFOUND       = 0x44,    
00207     OBEX_RESPONSE_CODE_BAD_METHOD     = 0x45,    
00208     OBEX_RESPONSE_CODE_UNACCEPTABLE   = 0x46,    
00209     OBEX_RESPONSE_CODE_PROXY_AUTH_REQ = 0x47,    
00210     OBEX_RESPONSE_CODE_REQ_TIMEOUT    = 0x48,    
00211     OBEX_RESPONSE_CODE_CONFLICT       = 0x49,    
00212     OBEX_RESPONSE_CODE_GONE           = 0x4A,    
00213     OBEX_RESPONSE_CODE_LENGTH_REQ     = 0x4B,    
00214     OBEX_RESPONSE_CODE_PRECON_FAILED  = 0x4C,    
00215     OBEX_RESPONSE_CODE_ENTITY_TOO_LARGE       = 0x4D,    
00216     OBEX_RESPONSE_CODE_URL_TOO_LARGE          = 0x4E,    
00217     OBEX_RESPONSE_CODE_UNSUPPORTED_MEDIA_TYPE = 0x4F,    
00218 
00219     OBEX_RESPONSE_CODE_INTERNAL_SERVER_ERROR    = 0x50,    
00220     OBEX_RESPONSE_CODE_NOT_IMPLEMENTED          = 0x51,    
00221     OBEX_RESPONSE_CODE_BAD_GATEWAY              = 0x52,    
00222     OBEX_RESPONSE_CODE_SERVICE_UNAVAILABLE      = 0x53,    
00223     OBEX_RESPONSE_CODE_GATEWAY_TIMEOUT          = 0x54,    
00224     OBEX_RESPONSE_CODE_HTTP_VERSION_UNSUPPORTED = 0x55,    
00225 
00226     OBEX_RESPONSE_CODE_DATABASE_FULL    = 0x60,     
00227     OBEX_RESPONSE_CODE_DATABASE_LOCKED  = 0x61,     
00228 
00229 } ObexResponseCode;
00230 
00232 typedef enum _ObexSessionFlags
00233 {
00234     OBEX_SESSION_FLAGS_UNKNOWN          = 0,
00235     OBEX_SESSION_FLAGS_AUTHENTICATE     = 1,    
00236 } ObexSessionFlags;
00237 
00238 /* Obex error codes. */
00239 #define OBEX_ERROR_SUCCESS                  0
00240 #define OBEX_ERROR_UNDEFINED                1
00241 #define OBEX_ERROR_AUTHENTICATION_FAILED    2
00242 #define OBEX_ERROR_INVALID_PARAMETER        3
00243 #define OBEX_ERROR_OUT_OF_MEMORY            4
00244 #define OBEX_ERROR_UNSUPPORTED              5
00245 #define OBEX_ERROR_PACKET_TOO_LARGE         6
00246 #define OBEX_ERROR_INVALID_PACKET           7
00247 
00249 #define OBEX_PACKET_MAXIMUM_SIZE         65535
00250 
00251 /* Obex structures. */
00252 
00253 /* Types. */
00254 typedef unsigned char   byte;
00255 typedef unsigned short  word;
00256 typedef unsigned int    dword;
00257 
00259 typedef struct _BTConnection        BTConnection;
00260 
00262 typedef struct _ObexPacket          ObexPacket;
00263 
00265 typedef struct _ObexSession         ObexSession;
00266 
00268 typedef struct _ObexTLVPacket       ObexTLVPacket;
00269 
00271 typedef struct _TagLengthValue
00272 {
00273     byte    tag;
00274     byte    length;
00275     byte    value[253];
00276 } TLV;
00277 
00279 typedef struct _BluetoothAddress
00280 {
00281     union 
00282     {
00283         unsigned __int64    address;
00284         unsigned char       bytes[6];
00285     };
00286 } BluetoothAddress;
00287 
00288 
00289 #ifndef INITGUID
00290 #define INITGUID
00291 #endif
00292 #include <guiddef.h>
00293 
00294 typedef GUID OBEX_UUID;
00295 
00296 #ifndef DEFINE_OBEX_UUID
00297 #define DEFINE_OBEX_UUID(name, l )    DEFINE_GUID( name, l, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB );
00298 #endif // DEFINE_OBEX_UUID
00299 
00300 DEFINE_OBEX_UUID  ( SERVICE_OBEX     , 0x00000008 )
00301 DEFINE_OBEX_UUID  ( SERVICE_OBEX_OPP , 0x00001105 )
00302 DEFINE_OBEX_UUID  ( SERVICE_OBEX_FTP , 0x00001106 )
00303 DEFINE_OBEX_UUID  ( SERVICE_OBEX_SYNC, 0x00001104 )
00304 
00305 /* Some targets for connect. */
00306 DEFINE_GUID  ( SERVICE_TARGET_FOLDER_BROWSING  , 0xF9EC7BC4, 0x953C, 0x11D2, 0x98, 0x4E, 0x52, 0x54, 0x00, 0xDC, 0x9E, 0x09 );
00307 DEFINE_GUID  ( SERVICE_TARGET_IRMC_SYNC        , 0x49524D43, 0x2D53, 0x594E, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 );
00308 DEFINE_GUID  ( SERVICE_TARGET_SYNCML_SYNC      , 0x53594e43, 0x4d4c, 0x2d53, 0x59, 0x4e, 0x43, 0x00, 0x00, 0x00, 0x00, 0x00 );
00309 
00310 
00311 /* Function prototypes for callbacks. */
00312 
00330 typedef int (*AuthenticationResponseFunc)( void* appData, byte* authResponse, word* authSize );
00331 
00332 
00333 /* Connection functions.  */
00334 
00335 
00356 int createBTConnection( BTConnection** connection, const BluetoothAddress* device, const BluetoothAddress* address, const OBEX_UUID* service, byte channel );
00357 
00367 int closeBTConnection( BTConnection* connection );
00368 
00379 int readBTConnection( BTConnection* connection, dword *size, void* data );
00380 
00391 int writeBTConnection( BTConnection* connection, dword *size, void* data );
00392 
00402 int peekBTConnection( BTConnection* connection, dword* available );
00403 
00404 
00405 /* Obex session functions.  */
00406 
00431 int obexSessionOpen( ObexSession** session, BTConnection* connection, ObexPacket* request, ObexPacket** response ,const OBEX_UUID* target,
00432                      AuthenticationResponseFunc authFunc, void* appData , ObexSessionFlags flags );
00433 
00444 int obexSessionClose( ObexSession* session );
00445 
00458 int obexSessionSend( ObexSession* session, ObexPacket* request, ObexPacket** response );
00459 
00468 word obexSessionGetMaximumRequestSize( ObexSession* session );
00469 
00479 dword obexSessionGetConnectionId( ObexSession* session );
00480 
00491 int obexSessionGetConnectionTarget( ObexSession* session , OBEX_UUID *uuid);
00492 
00493 /* Obex packet functions. */
00494 
00509 int obexPacketCreate( ObexPacket** packet, ObexPacketOperation operation, byte flags );
00510 
00539 int obexPacketAddHeader( ObexPacket* packet, ObexPacketHeader header, word size, void* data );
00540 
00548 int obexPacketDestroy( ObexPacket* packet );
00549 
00550 /* Packet query functions. */
00551 
00560 int  obexPacketHasHeader( ObexPacket* packet, ObexPacketHeader header, word* headerSize );
00561 
00570 byte obexPacketGetId( ObexPacket* packet );
00571 
00578 word obexPacketGetSize( ObexPacket* packet );
00579 
00593 int obexPacketGetHeaderData( ObexPacket* packet, ObexPacketHeader header, void* outData );
00594 
00607 int obexPacketClear( ObexPacket* packet, ObexPacketOperation operation, byte flags );
00608 
00620 word obexPacketGetSizeLeft( ObexSession* session, ObexPacket* packet );
00621 
00622 
00632 int obexPacketAddHeaderUnicode( ObexPacket* packet, ObexPacketHeader header, const wchar_t* string);
00633 
00643 int obexPacketAddHeaderAscii( ObexPacket* packet, ObexPacketHeader header, const char* string);
00644 
00655 int obexPacketAddHeaderTLV( ObexPacket* packet, ObexPacketHeader header, ObexTLVPacket* tlvPacket );
00656 
00666 int obexPacketAddHeaderInt( ObexPacket* packet, ObexPacketHeader header, dword value );
00667 
00677 int obexPacketAddHeaderByte( ObexPacket* packet, ObexPacketHeader header, byte value );
00678 
00688 int obexPacketAddHeaderUUID( ObexPacket* packet, ObexPacketHeader header, OBEX_UUID value );
00689 
00700 int obexPacketAddHeaderBin( ObexPacket* packet, ObexPacketHeader header, word size, byte* bytes );
00701 
00702 
00713 int obexPacketGetHeaderUnicode( ObexPacket* packet, ObexPacketHeader header, wchar_t* string, int size );
00714 
00725 int obexPacketGetHeaderAscii( ObexPacket* packet, ObexPacketHeader header, char* string, int size);
00726 
00737 int obexPacketGetHeaderTLV( ObexPacket* packet, ObexPacketHeader header, ObexTLVPacket** tlvPacket);
00738 
00748 int obexPacketGetHeaderInt( ObexPacket* packet, ObexPacketHeader header, dword* value );
00749 
00759 int obexPacketGetHeaderByte( ObexPacket* packet, ObexPacketHeader header, byte* value );
00760 
00770 int obexPacketGetHeaderUUID( ObexPacket* packet, ObexPacketHeader header, OBEX_UUID* value );
00771 
00782 int obexPacketGetHeaderBin( ObexPacket* packet, ObexPacketHeader header, word* size, byte* bytes );
00783 
00792 ObexResponseCode obexResponseCode( byte packetId, int* finalBitSet );
00793 
00794 
00795 /* tag-length-value triplet functions.  Currently not implemented and cause linker error if used. */
00796 
00805 int  obexTLVCreate( ObexTLVPacket** tlvPacket );
00806 
00814 int  obexTLVDestroy( ObexTLVPacket* tlvPacket );
00815 
00828 int  obexTLVAddValue( ObexTLVPacket* tlvPacket, TLV *tlv );
00829 
00836 byte obexTLVGetCount( ObexTLVPacket* tlvPacket );
00837 
00844 word obexTLVGetSize( ObexTLVPacket* tlvPacket );
00845 
00855 int  obexTLVGetValue( ObexTLVPacket* tlvPacket, byte index, TLV *tlv );
00856 
00857 
00858 #ifdef __cplusplus
00859 "}"
00860 #endif
00861 
00862 #endif /* __OBEX_H__  */
00863 
00864 // End of file  
00865 
footer
 SourceForge.net Logo