Linux Bluetooth programming (9) SDP layer Programming

Source: Internet
Author: User

The author's blog address: http://blog.sina.com.cn/samzhen1977
By Sam (zhufeng)
Sam_code@hotmail.com

 

 

Previous sections have talked about the SDP protocol. But there is no specific explanation of programming.

The sdp api provided by bluez is common as follows:

 

1.

Sdp_session_t * sdp_create (int sk, uint32_t
Flags)

Parameter 1: SK: Socket

Parameter 2: SDP flags. The values are as follows:

# Define sdp_retry_if_busy 0x01
# Define sdp_wait_on_close 0x02
# Define sdp_non_blocking 0x04

 

Create a new session for asynchronous search.

 

The session structure is as follows:

Typedef struct {
Int sock;
Int state;
Int local;
Int flags;
Uint16_t tid; // current
Transaction ID
Void * priv;
} Sdp_session_t;

Sdp_create
Simply create a space and return the session pointer. And pass SK and flags to the session
Value.

At the same time, a transaction is created and the pointer isPriv
.

Struct sdp_transaction {
Sdp_callback_t * CB;
Void
* Udata;
Uint8_t * reqbuf;
Sdp_buf_t rsp_concat_buf;
Uint32_t reqsize;
Int
Err;
};

 

2.

Static inline int sdp_is_local (const bdaddr_t
* Device)

Check whether the bdaddr parameter is a local bdaddr -- {0, 0, 0, 0xff, 0xff, 0xff}

If it is local, 1 is returned. Otherwise, 0 is returned.

 

3.

Static int sdp_connect_local (sdp_session_t
* Session)

Connect to the local device. And assign the socket to the corresponding data of the parameter session.

Create a socket as follows. Socket (pf_unix, sock_stream, 0)

SA. sun_family = af_unix;
Strcpy (SA. sun_path, sdp_unix_path );

And connect to it.

 

4.

Static int sdp_connect_l2cap (const bdaddr_t * SRC, const
Bdaddr_t * DST, sdp_session_t * session)

Parameter 1: SRC: Source bdaddr.

Parameter 2: DST: Destination bdaddr.

Parameter 3: Session: The session created by sdp_create.

Action:

Create an L2CAP socket and connect to it. At the same time, the PSM = 0x01 (SDP)

And store the socket into the session. The SDP information can be obtained only after the connection with the peer end.

 

5.

Sdp_session_t * sdp_connect (const bdaddr_t * SRC,
Const bdaddr_t * DST, uint32_t
Flags)

Parameter 1: SRC Source bdaddr.

Parameter 2: DST target bdaddr.

Parameter 3: The flags value is as follows:

# Define sdp_retry_if_busy 0x01
# Define sdp_wait_on_close 0x02
# Define sdp_non_blocking 0x04

Source: (http://blog.sina.com.cn/s/blog_602f87700100jaog.html
)
-Linux Bluetooth programming (9) SDP layer programming _ samzhen _ Sina Blog

Note: sdp_retry_if_busy and sdp_non_blocking are mutually exclusive.

 

This function creates a session and an L2CAP socket. The connection to the remote DST. PSM is 1 (SDP ).

 

 

6.

Uuid_t * sdp_uuid16_create (uuid_t * u, uint16_t
Val)

Copy parameter 2 Val to value. uuid16 of parameter 1.

 

 

7.

Sdp_list_t * sdp_list_append (sdp_list_t * P, void
* D)

Add parameter 2 to the linked list of parameter 1.

Parameter 1 is a one-way linked list. Add parameter 2 to this one-way linked list. If parameter 1 is null, a one-way linked list is created.

 

 

 

8.

Int sdp_service_search_attr_req (sdp_session_t * session,
Const sdp_list_t * search, sdp_attrreq_type_t reqtype, const
Sdp_list_t * attrids, sdp_list_t ** RSP)

This function is very important.

Parameter 1:Sdp_session_t * Session:
This session
The sock in is connected to SDP (L2CAP, PSM = 0x01 ).

Parameter 2:Const sdp_list_t * search:
Search is to search for SDP
The linked list of the record. Such as PNP and hid.

Parameter 3:Sdp_attrreq_type_t reqtype

Typedef Enum {
 
Sdp_attr_req_individual = 1,
 
Sdp_attr_req_range
} Sdp_attrreq_type_t;

Parameter 4:Const sdp_list_t * attrids. SDP specified in search
The feature linked list in the record. If you want to obtain all features in a record. Use 0x0000ffff to create a linked list for the content.

Parameter 5: sdp_list_t ** RSP: obtains the ATTR information.

 

This function is used by the client to send a request to the server. Get the service-compliant search
Attribute in the SDP record of pattern (parameter 2. For example, PNP and hid can be obtained.
Attribute in record. Such as vid, PID, and report.

 

This function sends sdp_servicesearchattributerequest (PDU
Id = 0x06), and put the features and attrids contained in the search into the parameter. Wait for sdp_servicesearchattributeresponse.
And add the returned information to parameter 5.

 

The specific resolution of parameter 5 depends on what search is. Query the documents of PNP. Hid-spec is checked.

 

 

 

9.

Int sdp_close (sdp_session_t * session)

Close session-> sock

 

 

 

 

 

Appendix 1:

PDU format: (protocol data unit format)

 

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.