2011 Embedded Systems Software Training Center BluRapport SDK.

18
2011 Embedded Systems Software Training Center BluRapport SDK

Transcript of 2011 Embedded Systems Software Training Center BluRapport SDK.

Page 1: 2011 Embedded Systems Software Training Center BluRapport SDK.

2011

Embedded Systems Software Training Center

BluRapport SDK

Page 2: 2011 Embedded Systems Software Training Center BluRapport SDK.

Agenda

lIntroduce to Low Level socket based layer of RXBT

Page 3: 2011 Embedded Systems Software Training Center BluRapport SDK.

Questions

lWhat difference between protocol and profile?lWhy we need to use profiles?

Page 4: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket based layer

Sockets overviewA RXBT socket is an endpoint of an inter-process communication flow across a Bluetooth network. Most communication between devices is based on the Bluetooth protocol stack.A socket API is an application programming interface (API), provided by RXBT SDK, that allows application programs to control and use bluetooth sockets.A socket address is the combination of an BDA address and type of protocol, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, RXBT sockets deliver incoming data packets to the appropriate application process or thread

Communicating local and remote sockets are called socket pairs. Each socket pair is described by a unique 6-tuple consisting of source and destination BDA addresses and port numbers, i.e. of local and remote socket addresses.

Page 5: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:rx_socket_t rx_socket(rx_socktype_t type, rx_sockproto_t protocol) - Create new socket- type - socket type (either stream or seqpacket)- protocol - Bluetooth protocol (it can be: RX_PF_HCI, RX_PF_L2CAP, RX_PF_RFCOMM, RX_PF_OBEX, RX_PF_SDP

and etc.)returns socket ID (>= 0) if ok, error code (< 0) in case of error.rx_ret_t rx_close(rx_socket_t sock) – Close socket- sock - socket created by rx_socket() calltypedef struct rx_sockaddr_s (more information about type of addresses and type of protocols see in rx_sdk.h){ rx_sockproto_t proto; union __protocol_u { rx_sockaddr_hci_t hci; rx_sockaddr_l2cap_t l2cap; rx_sockaddr_rfcomm_t rfcomm; rx_sockaddr_sdp_t sdp; rx_sockaddr_sco_t sco; rx_sockaddr_bnep_t bnep; } protocol;}rx_sockaddr_t;

Page 6: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_bind(rx_socket_t sock, rx_sockaddr_t *my_addr) - Bind local socket to some address- sock - socket to bind- my_addr – address

NOTE:Bind local socket to some address. For different socket types different address components are used. In general, BDA will be ignored but PSM or channel # will be taken into account. If PSM or channel # is busy, RET_ALREADY_EXISTS is returned. It is strictly necessary to call rx_bind before rx_listen, but not before rx_connect.

Page 7: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_listen(rx_socket_t sock, int backlog) - Register socket as waiting for connections.- sock - socket to listen on.- backlog - incoming connections queue size (currently ignored)

NOTE:The socket must not be used for other i/o before.rx_bind must be called before rx_listen.It is impossible to call rx_listen on HCI socket.

Page 8: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_socket_t rx_accept(rx_socket_t sock, rx_sockaddr_t *addr) - Accept incoming connection.- sock - socket listening on.- addr - peer's addressReturns new socket ID (>= 0) or error code (< 0).

NOTE:Block if no ready incoming connections on this socket.rx_listen must be run once before rx_accept.It is impossible to call rx_accept on HCI socket.

Page 9: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_connect(rx_socket_t sock, rx_sockaddr_t *dest_addr) - Connect to the destination.- sock - socket to use- dest_addr - destination address (BDA and PSM or channel # must be filled)

NOTE:Connect to the peer, blocking until connection complete.It is impossible to call rx_connect on HCI socket.

Page 10: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_read(rx_socket_t sock, void *buf, unsigned len) - Read data from the peer.- sock - socket ID- buf - user's buffer- len - buffer sizeRreturns number of bytes read (> 0), or 0 in case of connection break, or error code (< 0)

NOTE:- Blocking if no data ready.- If socket is in STREAM mode, can aither break or glue packets.- If socket is in SEQPACKET mode, return exactly packet size. If buffer length is less then packet size,

packet rest will be returned on the next rx_read or rx_recv call.- rx_read and rx_recv calls can be mixed, but only one thread can call rx_read/rx_recv at the same

time.- It is impossible to call rx_read on HCI socket.

Page 11: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_write(rx_socket_t sock, void *buf, unsigned len) - Send data to the peer.- sock - socket ID- buf - user buffer- len - data lengthReturns number of bytes written (> 0), or 0 in case of connection break, or error code (< 0)NOTE:- Try to send as much data as possible, but does not guarantee that all data will be send.

Page 12: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_getsockopt(rx_socket_t sock, int level, int optname, void *optval, unsigned *optlen) - Get either protocol or socket-level option.- sock - socket ID- [in] level - RX_SOL_SOCKET or RX_SOL_PROTO- [in] optname - either option from rx_sockopt_name_t or protocol-specific option.- [out] optval - user buffer;- [in,out] optlen - in: *optlen - buffer length; out: real number of bytes read.

NOTE:- This call can't block.- This call can't be called at the same time with rx_read call.

Page 13: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_setsockopt(rx_socket_t sock, int level, int optname, void *optval, unsigned optlen) - Set either protocol or socket-level option.- sock - socket ID- level - RX_SOL_SOCKET or RX_SOL_PROTO- optname - either option from rx_sockopt_name_t or protocol-specific option.- optval - user buffer;- optlen - optlen - buffer length.

NOTE:- This call can't block.- This call can't be called at the same time with rx_write call.

Page 14: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_getsockname(rx_socket_t sock, rx_sockaddr_t *addr) - Get local socket address.- sock - socket ID- addr - addressNOTE:- Valid after rx_bind(), rx_listen(), rx_connect() calls.- Never blocks.

rx_ret_t rx_getpeername(rx_socket_t sock, rx_sockaddr_t *addr) - Get remote address.- sock - socket ID- addr - addressNOTE:- Valid after rx_accept(), rx_connect() calls.- Never blocks.

Page 15: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

rx_ret_t rx_ioctl(rx_socket_t sock, int name, void *arg_val, unsigned arg_size, void *ret_val, unsigned ret_buf_size, unsigned *ret_len) - Do protocol-specific action.- sock - socket ID- name - protocol-specific call ID- arg_val - IN argument value- arg_size - IN argument size- ret_val - result value- ret_buf_size - result buffer size- ret_len - real result lengthReturns a Error codeNOTE:- This is low-level function used to to some protocol-specific thing.- It can block.- Only one rx_ioctl can be callse on the same socket an the same time..

Page 16: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

Example of using IOCTLrx_ret_t rx_rfcomm_sent_fcoff(rx_socket_t sock, rx_bool_t fcoff){ rx_ret_t ret = RET_OK; if (fcoff) { ret = rx_ioctl(sock, RFCOMM_IOCTL_SENT_FCOFF, 0,0,0,0,0); } else { ret = rx_ioctl(sock, RFCOMM_IOCTL_SENT_FCON, 0,0,0,0,0); } return ret;}

Page 17: 2011 Embedded Systems Software Training Center BluRapport SDK.

Socket SDK

Main Functions that are used to work with Low Level socket API:

Example of using IOCTLrx_ret_t rx_rfcomm_sent_test(rx_socket_t sock){ rx_ret_t ret = RET_OK; ret = rx_ioctl(sock, RFCOMM_IOCTL_SENT_TEST, 0,0, 0,0,0); return ret;}

Page 18: 2011 Embedded Systems Software Training Center BluRapport SDK.

THANK YOU