******************************************************************************* * Commented Example for the necessary commands and responses to copy a file * * from/to a mobile phone (Sony Ericcson K310i) to/from the disk of a computer * * using a irda connection and OBEX commands. * ******************************************************************************* (Chapter x.x means Chapter x.x in Obex13.pdf) 1. First we have to set the mobile to OBEX mode using a AT commnand: AT*EOBEX >>> out >>> 41 54 2A 45 4F 42 45 58 0D A T * E O B E X 2. We get 4 lines in response: <<< in <<<< 0D 0A 4F 4B 0D 0A O K 41 54 2A 45 4F 42 45 58 0D 0D 0A A T * E O B E X 43 4F 4E 4E 45 43 54 0D 0A C O N N E C T 3. Now we have CONNECT and can send the OBEX-Connect Command: 80 00 1A 10 00 FF DC 46 00 13 F9 EC 7B C4 95 3C 11 D2 98 4E 52 54 00 DC 9E 09 | | | | | | | | | | | | | | | - Target (UUID) just some 128 bit value which identifies us. | | | | | | - Lenght of Target ('00 13'x = 19) (starting from and including Header-ID) | | | | | - Header-ID ('46'x = Target : Byte 7 u 8 = 01 means: byte sequence, length prefixed with 2 byte unsigned integer | | | | - maximum OBEX packet length _we_ can handle ('FF DC'x = 65500) | | | - flags (Chapter 3.3.1.2) | | - OBEX Version (1.0) | - Length of the whole packet from '80'x to '09'x ('00 1A'x = 26 bytes) - Opcode ('80'x = Connect) 4. and now have to read the response from the mobile: A0 00 1F 10 00 10 00 CB 00 00 00 01 4A 00 13 F9 EC 7B C4 95 3C 11 D2 98 4E 52 54 00 DC 9E 09 | | | | | | | | | | | | | | | | | | | - UUID (128 bit value) | | | | | | | | - Length of Who-Header ('00 13' = 19) | | | | | | | - Header-ID '4A' = Who (Chapter 2.2.10) | | | | | | - Connection ID ('00 00 00 01'x = 1) | | | | | - Header-ID ('CB'x = Connection ID) | | | | - maximum OBEX packet length ('10 00'x = 4096) | | | - flags | | - OBEX Version (1.0) | - Length of the whole packet ('00 1F'x = 31) (including 'A0'x) - Opcode ('A0'x = Success) (Chapter 3.3.1.8) 5. The mobile tells us two things: - the maximal packet - length, the mobile can handle: '10 00'x (= 4096) - our connection ID: '00 00 00 01'x ( = 1) 6. Now we want to know which folders files we have on the mobile: Get Folderlisting Command 83 00 1C 42 00 19 78 2D 6F 62 65 78 2F 66 6F 6C 64 65 72 2D 6C 69 73 74 69 6E 67 00 | | | | x - o b e x / f o l d e r - l i s t i n g | | | | | | | | | - Data | | | - Length ab 42 ($0019 = 25) | | - Header ID ('42'x = Data) e.g. text, html, binary, manufacturer specific (Chapter 2.2.3) | - Length ('00 1C'x = 28) - Opcode ('83'x = Get) 7. We read the response: Get FolderListing Response: A0 01 67 CB 00 00 00 01 49 01 5F 3C 3F 78 6D 6C 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 20 65 6E 63 6F 64 69 6E 67 3D 22 55 54 46 2D 38 22 3F 3E 0D 0A 3C 21 44 4F 43 54 59 50 45 20 66 6F 6C 64 65 72 2D 6C 69 73 74 69 6E 67 20 53 59 53 54 45 4D 20 22 6F 62 65 78 2D 66 6F 6C 64 65 72 2D 6C 69 73 74 69 6E 67 2E 64 74 64 22 3E 0D 0A 3C 21 2D 2D 0D 0A 20 58 4D 4C 20 43 6F 64 65 72 2C 20 28 43 29 20 32 30 30 31 20 53 6F 6E 79 20 45 72 69 63 73 73 6F 6E 20 4D 6F 62 69 6C 65 20 43 6F 6D 6D 75 6E 69 63 61 74 69 6F 6E 73 20 41 42 20 0D 0A 2D 2D 3E 0D 0A 3C 66 6F 6C 64 65 72 2D 6C 69 73 74 69 6E 67 20 76 65 72 73 69 6F 6E 3D 22 31 2E 30 22 3E 3C 66 6F 6C 64 65 72 20 6E 61 6D 65 3D 22 42 69 6C 64 65 72 22 2F 3E 0D 0A ... 3C 66 6F 6C 64 65 72 20 6E 61 6D 65 3D 22 41 6E 64 65 72 65 22 2F 3E 0D 0A 3C 2F 66 6F 6C 64 65 72 2D 6C 69 73 74 69 6E 67 3E 0D 0A | | | | | | < ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? > < ! D O C T Y P E f o l d e r - l i s t i n g S Y S T E M " o b e x - f o l d e r - l i s t i n g . d t d " > < ! - - X M L C o d e r , ( C ) 2 0 0 1 S o n y E r i c s s o n M o b i l e C o m m u n i c a t i o n s A B - - > < f o l d e r - l i s t i n g v e r s i o n = " 1 . 0 " > < f o l d e r n a m e = " B i l d e r " / > < f o l d e r n a m e = " A n d e r e " / > < / f o l d e r - l i s t i n g > | | | | | | | | | | | | | | | | | | - Length ('01 5F'x = 351) | | | | - Header-ID ('49'x = End of Body) (Content of the file) (Chapter 2.2.9) | | | - Connection ID ('00 00 00 01'x = 1) | | - Header-ID ('CB'x = Connection ID) | - Lenght ('01 67'x = 359) - Opcode ('A0'x = Success) (Chapter 3.3.1.8) 8. The response was UTF-8 encoded xml style message. We recode the folder-name we are interested in to UTF-16 (network-byte-order!) and send a SetPath packet: SetPath Command: 85 00 16 02 00 01 00 11 00 42 00 69 00 6C 00 64 00 65 00 72 00 00 */ | | | | | | | B i l d e r | | | | | | | | | | | | | - Pathname encoded UTF-16 network-byte-order '00 00'x terminated | | | | | - Length of Name Header including '01'x ('00 11'x = 17) | | | | - HeaderID '01'x = Name (2.1) (Bit 7 u. 8 not set: null terminated Unicode text, length prefixed with 2 byte unsigned integer) (2.1) | | | - Constants (Chapter 3.3.6) | | - Flags (Bit 1 (starting fom 0) set: Don't create folder if it does not exist, return an error instead.) | - Length of the whole packet ('00 16'x = 22) (starting from and inclulding Opcode) - Opcode ('85'x = SetPath) 9. The mobile answers with 'A0' which means Success. If we would have made a mistake we would have gotten 'C3' or 'C4' SetPath Response: A0 00 03 | | | - Lenght ('00 03'x = 3) - Opcode ('A0'x = Success) 10. Again we want to get know which folders files we have on the mobile in the chosen folder: We send the Get Folderlisting Command (see above step 6. and step 7.) and get something like: ... 11. We chose 'DSC00017 (1).JPG' recode again from UTF-8 to UTF-16 and send the following packet: Get File Command: 83 00 28 01 00 25 00 44 00 53 00 43 00 30 00 30 00 30 00 31 00 37 00 20 00 28 00 31 00 29 00 2E 00 6A 00 70 00 67 00 00 | | | | | D S C 0 0 0 1 7 ( 1 ) . j p g | | | | | | | | | - Filename encoded UTF-16 network-byte-order '00 00'x terminated | | | - Length of Name Header including '01'x ('00 25' = 37) | | - HeaderID '01'x = Name (Bit 7 u. 8 not set: null terminated Unicode text, length prefixed with 2 byte unsigned integer) (Chapter 2.1) | -Length ('00 28'x = 40) - Opcode ('83'x = Get) 12. This is our response: Get Response: 1 2 3 4 5 6 7 8 9 10 11 12 1 2 3 4 5 6 7 8 9 90 10 00 CB 00 00 00 01 01 00 25 00 44 00 53 00 43 00 ... 2E 00 6A 00 70 00 67 00 00 C3 00 00 C6 27 48 0F CE FF D8 FF ... | | | | | | D S C ... . j p g | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Data (file content) first chunk (4043 bytes) | | | | | | | | | | - Length of the Body Part ('0F CE'x = 4046) | | | | | | | | | - Body (HI) (Content of the file) (Chapter 2.2.9) | | | | | | | | - Total length of file 4-byte unsigned ('00 00 C6 27'x = 50727 bytes) | | | | | | | - Header-ID ('C3' = Length (of the object in bytes) (Chapter 2.2.4) | | | | | | | | | | | | | - File name | | | | | - (HV) length ('00 25'x = 37) | | | | - HeaderID '01'x = Name (Bit 7 u. 8 not set: null terminated Unicode text, length prefixed with 2 byte unsigned integer) (Chapter 2.1) | | | - Connection ID ('00 00 00 01'x = 1) | | - Header-ID ('CB'x = Connection ID) | - Length ('10 00'x = 4096) - Opcode ('90'x = Continue (Chapter 3.3.4) 13. This response packet consists of several sub-packets: - Connection ID: We see the Connection-ID is 1, so it's our packet - The name of the file - the total length of the file: 50727 byte - and finally the first chunk (4043 bytes) of the file. and it starts with '90'x which means the contet of the file could not be transmitted in one chunk because it's larger than ~4K Byte. So we need several 'Get' Commands: 14. To get the next chunk we have to send a simple Get Command: Get Command to get the next chunk: 83 00 03 | | | - Lenght ('00 03'x = 3) - Opcode ('83'x = Get) 15. The next response packet(s) we get only has two sub-headers: - Connection ID (1) - and the next chunk of bytes for the file we want to copy from the mobile. Continue Response: 1 2 3 4 5 6 7 8 9 10 11 12 90 10 00 CB 00 00 00 01 48 0F F8 AD 3E E7 B9 5F 4C 2C 82 8A 28 AF 5D ... | | | | | | | | | | | | | - Data (bytes of the file, Part 2 .. Part n) (4089 - 3 = 4086 bytes) | | | | | - Length ('0F F8'x = 4089) | | | | - Header-ID '48'x = Body (Chapter 2.2.9) (Content of the file) | | | - Connection ID ('00 00 00 01'x = 1) | | - Header-ID ('CB'x = Connection ID) | - Length ('10 00'x = 4096) - Header-ID ('90'x = Continue) (Chapter 3.3.4) 16. We have to repeat step 14. and 15. until we get all the bytes and finaly a different response it's now 'A0'x Success and not '90'x Continue: Our last Continue Response: A0 00 0B CB 00 00 00 01 49 00 03 | | | | | | | | | | | - Length ('00 03'x = 3) | | | | - Header-ID ('49'x = End of Body) (Content of the file) (Chapter 2.2.9) | | | - Connection ID ('00 00 00 01'x = 1) | | - Header-ID ('CB'x = Connection ID) | - Length ('00 0B'x = 11) - Header-ID ('A0'x = Success) (Chapter 3.3.4) 17. The second header now changed from '48'x Body to '49'x End of body. Although it does contain 0 bytes of data it's a valid packet for 'End of body' 18. Upload (put) a big (bigger than one chunk) file to the mobile: 02 10 00 01 00 25 00 70 00 61 00 6E 00 ... 2E 00 6D 00 70 00 33 00 00 C3 00 06 5A 9E 48 0F D3 FF FB 90 ... | | | | | p a n ... . m p 3 | | | | | | | | | | | | | | | | | | | | | | | | - Data (file content) first chunk (4048 bytes) | | | | | | | | - Length of the Body Part ('0F D3'x = 4051) | | | | | | | - Body (HI) (Content of the file) (Chapter 2.2.9) | | | | | | - Total length of file 4-byte unsigned ('00 06 5A 9E'x = 416414 bytes) | | | | | - Header-ID ('C3' = Length (of the object in bytes) (Chapter 2.2.4) | | | | | | | | | - File name | | | - (HV) length ('00 25'x = 37) | | - HeaderID '01'x = Name (Bit 7 u. 8 not set: null terminated Unicode text, length prefixed with 2 byte unsigned integer) (Chapter 2.1) | - Length ('10 00'x = 4096) - Opcode ('02'x = Put final bit not set Continue response: 90 00 03 | | | - Lenght ('00 03'x = 3) - Header-ID ('90'x = Continue) (Chapter 3.3.4) 19. Send the second chunk to the mobile 02 10 00 48 0F FD 55 4C 41 4D ... | | | | | | | | | - Data (file content) second chunk (4090 bytes) | | | - Length of the Body Part ('0F FD'x = 4093) | | - Body (HI) (Content of the file) (Chapter 2.2.9) | - Length ('10 00'x = 4096) - Opcode ('02'x = Put final bit not set) Continue response again: 90 00 03 | | | - Lenght ('00 03'x = 3) - Header-ID ('90'x = Continue) (Chapter 3.3.4) ... and so on until the last chunk: 20.Send the final (last) chunk: 82 0D 2C 49 0D 29 8C 4F B5 ... | | | | | | | | | - Data (file content) second chunk (3366 bytes) | | | - Length of the Body Part ('0D 29'x = 3369) | | - End of Body (HI) (Content of the file) (Chapter 2.2.9) | - Length ('0D 2C'x = 3372) - Opcode ('82'x = Put final bit set) Response to the last chunk: A0 00 03 | | | - Lenght ('00 03'x = 3) - Opcode ('A0'x = Success) 21. Now we can leave OBEX-Mode: Disconnect Command: 81 00 03 | | | -Length ('00 03'x = 3) -Opcode ('81'x = Disconnect) Disconnect Response: A0 00 03 | | | - Lenght ('00 03'x = 3) - Opcode ('A0'x = Success) 25. Disconnect worked, we got 'success' :-) If we want to connect again, we have to start from the beginning with AT*EOBEX fbakan at gmx dot net, 12. February 2007