. NET mobile phone software development (5)--obex Introduction

Source: Internet
Author: User
Tags 0xc0 auth bit set empty file size header connect object model
(i) Obex introduction

One, what is Obex, what is its use?

Obex is all called object Exchange, the Chinese object exchange, so it is called a barter protocol. It has a core position in this software, and file transfer and IRMC synchronization will use it.

The OBEX protocol is built on top of the IrDA architecture.

The OBEX protocol enables easy and efficient exchange of information between different devices and different platforms by simply using the "put" and "get" commands. supports a wide range of devices, such as PC,PDA, telephones, cameras, automatic answering machines, calculators, data collectors, watches, and more.

The OBEX protocol defines a flexible concept of--objects. is also the object. These objects can include files, diagnostic information, E-commerce cards, bank deposits, and so on. Objects has no advanced technical implications here, it depends on your application.

The OBEX protocol is small to be used for "command and control" functions, such as the operation of televisions, VCRs, etc. The avenue can do complex operations, such as transaction processing and synchronization of databases.

Obex can have the following characteristics:

1, the friendly application--can realize the rapid development.

2. Austerity-available on small devices with limited resources.

3. Cross platform

4, flexible data support.

5, convenient as the other Internet Transport protocol upper layer protocol.

6, scalability-Provides extended support for future requirements without impacting the existence of implementations. For example, scalable security, data compression, and so on.

7, can test can be debugged.

For more specific information on Obex, please refer to the Irobex agreement.

Second, Obex object model

About headers

The object model answers how objects are described in the OBEX protocol. This model must include the transmitted object and the description of the object. To do this, OBEX defines the concept of headers.

A header reflects an aspect of an object, such as the name, length, description text, or object itself. For example, a file object Demo.txt will contain its name, a type labeled "Text", and the length and the file itself.

Composition of the headers

Headers is simply made up of
Hi is made up of a byte that indicates what the header contains and how it is formatted. HV contains one or more bytes, and its structure is determined by hi.

All headers are optional, depending on the type of device and the kind of transaction. You can use all headers, or some, or none. IDs can cause headers to be resolvable and to be independent of the transport order, or they can cause unsupported headers to be ignored.

Hi can also be divided into two parts, high 2-bit and low 6-bit. The high 2-bit determines how HI is encoded (see table II), and the low 6 bits determine the meaning of hi (see table III). All two tables are excerpts from the Irobex and part of the translation.

Table II

Hi the 8th and 7th places
Significance

(0x00)
A Unicode literal that ends with null (0x00). A 2-byte unsigned integer length prefix.

(0x40)
BYTE block, 2-byte unsigned integer prefix.

Ten (0x80)
1Byte capacity.

One (0XC0)
4Byte capacity, high order first transmission as the principle.


Table III

Hi
Header Name
Describe

0xc0
Count
The number of objects to be named in the connection.

0x01
Name
The name of the object. Typically a filename.

0x42
Type
The type of the object. such as Text,html,binary,manufacture specific

0x44

0xc4
Time
Time stamp. ISO 8601 version
Time stamp. 4Byte version (for compatibility)

0x05
Description
Textual description of the object

0x46
Target
The purpose service name of the operation

0x47
HTTP
A http1.x head.

0x48
Body
Part of an object

0x49
End of the body
The last part of the object

0x4a
W.H.O.
OBEX application identification, used to indicate whether it is the same application.

0xCB
Connection ID
Identification for OBEX multiple connections

0x4c
App.parameters
Extended application-level request and response information

0x4d
Auth.challenge
Authentication Digest-challenge

0x4e
Auth.response
Authentication Digest-response

0x4f
Object Class
object's Obex object class

0x10 to 0x2f
Reserved
Keep

0x30 to 0x3F
User defined
User-defined.




For more detailed explanations of commonly used headers, please refer to Irobex for more information

1, Name
Name is a header that describes the name of an object, consisting of a Unicode string ending with null (0x00). For example: DEMO.TXT

2, Length
Length describes the size of the object, consisting of 4 bytes. If length is known beforehand, this header should be used. This allows the recipient to quickly know how much space needs to be allocated to make the process more rapid. But this is also not necessary, in some cases the length can not be confirmed, but the device can through the End-body header know when the end.

3, Time

Time describes when the object was last modified. Use the ISO8601 format.

local time format: YYYYMMDDTHHMMSS

UTC time Format: yyyymmddthhmmssz

The T in the format can easily distinguish between date and time. UTC time uses z as a mark. It is recommended to use UTC time.
4, Body, end-of-body

The body header is described by Hi, a 2Byte-length description, and the entire object itself. The composition of the end-of-body is the same as the body, but it identifies the last part of the object. If the object is already small, use end-of-body directly.



Iii. requests (Request) and Responses (Response)

Obex use request and response as the most basic operation. Each request requested must have a response, or you can assume that it failed.

The request consists of one or more packet (packages), each of which is structured in the following table

Request Packet Structure

Byte 0
Byte 1,2
Byte 3 to N

Operation code (OpCode)
Packet Length (packet lengths)
Headers or request information




Because each request may have multiple packet,opcode, the highest bit is called the final bit. If it is set to 1, then this is the last packet of the request. For example, when you send a large file with a put operation, there are several packet as a request. Then only the last packet Finalbit is set to 1.



Response is also composed of one or more packet, each of which is structured as follows table

Response Packet Structure

Byte 0
Byte 1,2
Byte 3 to N

Response Code (return value)
Response Length (response lengths)
ResponseData Response to Data




The same responsecode's highest position is also called Finalbit. ResponseData may contain objects and headers, or other information.

The following table lists the common opcode and responsecode, please refer to the Irobex 1.2 documentation for more details.

OpCode

Opcode (W/high bit set)
Defined
Significance

0x80 *
Connect
Connection

0X81 *
Disconnect
Disconnect

0x02 (0x82)
Put
Send an Object

0X03 (0x83)
Get
Get an Object

0x04 (0x84)
Reserved
Retained by

0X85 *
SetPath
Set path

0xFF *
Abort
Cancel the current operation

0x06 to 0x0f
Reserved
As extended retention

0x10 to 0x1f
User definable
User-defined


* Always set Finalbit



Responsecode

Responsecode
Defined

0x10 (0x90)
Continue (continued)

0x20 (0xa0)
Ok,success

0x40 (0XC0)
Bad Request (service side does not understand request)

0x41 (0xC1)
Unauthorized (Unauthorized)

0x43 (0XC3)
Fobidden (Forbidden--Server understands request, but refuses)

0x44 (0XC4)
Not Found (not found)




Iv. description.

1, connect (connection)

This action initializes the session and then sets the parameters. The request format is

Byte 0
Byte 1,2
Byte 3
Byte 4
Byte 5,6
Byte 7 to N

0x80
Package length
OBEX version
Sign
Maximum Obex package length
Optional header


Note: The OBEX version is now 1.0.

The response format is:

Byte 0
Byte 1,2
Byte 3
Byte 4
Byte 5,6
Byte 7 to N

Responsecode
Package length
OBEX version
Sign
Maximum Obex package length
Optional header


For more information on Connect please refer to Irobex

2. Disconnect (disconnect current session)

This operation disconnects the OBEX session. For example, disconnect the current folderlisting service, and then connect to the IRMC Sync Service using connect to achieve the functions of synchronous communication thin.

The Disconnect format is:

Byte 0
Bytes 1,2
Bytes 3 to N

0x81
Package length
Optional header


A successful fracture will return 0xa0, and the rejection will return 0XD3

3. Put operation

The put operation sends an object to the server from the client. Typically contains at least name and length two headers. There may also be a date/time Header for the file.

The format of the put operation is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

0x02 (when Finalbit is set to 0x82)
Packetlength Packet Length
A group header


The response format is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

Responsecode (required to continue for 0x90; success for 0xa0)
Package length
Optional header


More detailed usage of the put operation will be explained in the File Transfer section.

4, get operation

The get operation returns an object from the service side.

The format of the get operation is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

0x03
Package length
A group header


The response format is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

Response Code
Package length
Optional header


More detailed usage of the get operation will be explained in the File Transfer section.

5, abort operation

The abort operation interrupts a multiple-package operation (for example, sending a large file). The abort operation can contain description headers that describe the cause of the interruption.

The format of the abort operation is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

0xFF
Package length
Optional header


The abort corresponds to a successful operation (0XA0) indicating that the operation has been received and that the server has been synchronized with the client. If another value is returned, the client should disconnect.

6, SetPath

The SetPath action is used to toggle the other's path. You typically use a name header to specify the offset path name. If empty, returns the default directory, usually the root directory

The SetPath operation format is as follows:

Byte 0
Bytes 1,2
Byte 3
Byte 4
Bytes 5 to N

0x85
Package length
Flags
Constants (constant)
Optional header


Note: Flags can be set Bit0 and Bit1. Bit0 represents a return to the previous level directory; Bit1 indicates that a directory is created if the directory does not exist, otherwise an error is returned.

The response format is as follows:

Byte 0
Bytes 1,2
Bytes 3 to N

Responsecode
Package length
Optional response Header




V. Practical examples
Note: Data is obtained using Serialmonitor. The client is a PC and the service end is a Siemens M55 mobile phone.

1, Connect, Disconnect

Çconnect Request:

1 A (6B)?....-A-D. F.. K.ë1a.

One D4 9A DA 3F 1F. Ô?w.pú? G.

Èconnect Response:

A0 1F (a) 4 6B ........ Úë ..... J.. K

D4 9A DA 3F (1F). Ë1a.. Ô?w.pú? G.

Çdisconnect Request:

?.. Bayi

Èdisconnect Response:

A0 00 03.

The instance is first connected to the phone and then disconnected using disconnect.

Çconnect Request:

80:connect

1 A: Packet length 26 bytes

10:obex version 1.0

00: Always 0

40 06: Maximum packet length of 16390 bytes.

46:hi,target (target). The 0x40 begins with a length description followed by 2 bytes.

13:header length 19

6B ...: corresponding target

Èconnect Response:

A0:ok,success

1F: Packet length 31 bytes

10:obex version 1.0

00: Always 0

DA: Maximum packet length 474 bytes

Cb:connection id=0x100. The 0xc0 begins with a value that is followed by 4 bytes.

4 a 13:who Header. Length 0x13.

6B ... : Who header value.

2, Put,get,setpath

Example: How to download the mobile phone \sound directory inside the 21680.mid files. Size is 313 bytes.

The whole process is divided into:

Connect æ switch to root æ switch to sound directory æget (21680.mid)

Specific process:

...... (Connection part omitted)

c Switch to the root directory, the Name Header (0x01) content is empty

?....... in the

È response

A0 00 03.

C Switch to \sound directory. The Name Header (0x01) length 0x11.

All of the?........ 6E for each of the 6F S.o.u.n

D.s---

È response

A0 00 03.

Çget request. Name Header (0x01) specifies the filename

?...... (a) (1) (a) 2.1.6.8.0

2E 6D/M.i.d ......

È response
0X90 instructions need to continue.
0xc3 specified file length 00 00 01 39.
The 0x48 description is part of the file.

C3 (3C 4D .....)

Çget request. Continues to send a get because the server side returns 0X90

?..

È response. Success. The service-side send 0x49 description is the last part of the object.

A0 00 06 49 00 03. I...



Example two: Describes how to obtain a large file, mainly introduces the get part.

Get \pictures\102725.jpg, size 5314 bytes.

The whole process is divided into:

Connect æ switch to root æ switch to pictures directory Æget (102725.jpg) æget ....

Çget request. The Name header value is 102725.jpg

The?...... A-1C for all of them 1.0.2.7.2

The 5...J.P.G for the 2E 6A, ...

È returns a body. The client should continue to send the get

D3 C3 C2 CB FF D8 ff E0 00? Óã ... Âh. Ëÿøÿà.

4 A (+) (a) FF. JFIF ..... x.x.. Y

.....

Çget request.

?..

È returns the second body. The client continues to send the get

D7 D4 6A 1C A2-4C-BC? Xh.ôj '?. ¢tl?g¼

A9 AA CD 6B F4 BB DF 8B BC A4 dc©ª? Ík?? Ô»ß?¼x¤ü

......
...... (omitting several repeat procedures)

Çget request. Continues to send a get because the server side returns 0X90

?..

È response. Success. The service-side send 0x49 description is the last part of the object.

A0 00 06 49 00 03. I...



Example three: Send a file to \sound\1.mid. Size 313 bytes

The whole process is divided into:

Connect æ switch to root directory æ switch to sound directory æputæ ...

Specific process:

...... (Omit connection Toggle section)

Çput operation

0x82:put operation, finalbit settings

0x01:nameheader. FileName 1.mid

0xc3:length. File size

0X44: Date and time. This is February 14, 2005, 19:49:38. Use local time.

0x49:end-of-body. The last part of the file.

The 0F 2E 6D 00 69 00 64?. E.... 1...m.i.d

C3 00 00 01 39 44 00 12 32 30 30 35 30 32. Coal tar ... 9D.. 200502

The 3C 4D to the 14t194938i.<mthd of the same

È response

A0 00 03.



Example four: Send file to \pictures\102725.jpg, size 5314 bytes.

Process is divided into:

Connect æ switch to root directory æ switch to \pictures directory æputæ ...

Specific process:

...... (Omit connection Toggle section)

Çput operation

0x02:put operation, Fianlbit not set. Indicates that there are remaining parts to be sent.

0x01:nameheader. FileName 102725.jpg

0xc3:length. File size

0X44: Date and time. This is February 14, 2005, 19:57:52. Use local time.

0x48:body. Part of the file.

D0 01 00 19 00 31 00 30 00 32 00 37 00 32. D.... 1.0.2.7.2

The 5...j.p.g of the C3 for the 2E (6A). Coal tar ...

C2 44 00 12 32 30 30 35 30 32 31 34 54 31 35âd 39. 20050214t195

9D FF D8 FF E0 4 A (752H). Ÿøÿà.. JFIF

......

È response. Client continues to send

90 00 03

Çput operation

0x02:put operation, Fianlbit not set. Indicates that there are remaining parts to be sent.

0x48:body. Part of the file.

Note: You do not need to set an extra header.

D1 F3 C0 F1 2D 5A E9 D4 B1 1 B 71. Ôh. Ñóàñ-zé?±.q

5B BD 3C 7E 2B D7 AE (6B DF 2C) G? [E0½<~+x®?kß,b

B5 BA D3 6B B5 B8 DB 4F D4 db C6 4cµº! Ók.µ¸ûoô#û.æl

......

...... (omitting several repeat procedures)

Çput operation

0x82:put operation, finalbit settings. It means this is the last part.

0x49:end-of-body. The last part of the file.

1F F6 BF 3C (E4) 48?. " I... Öu¿.<. Ihäh

6F 3E FF 2D D8 CF D8/5F o>ÿ.-q%ï2ø9_%ø? D

.....

È response. Success

A0 00 03




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.