RFCOMM

group rfcomm_api_functions

The RFCOMM protocol provides emulation of serial ports over the L2CAP protocol.

The protocol is based on the ETSI standard GSM 7.1.0. RFCOMM is a simple transport protocol, with additional provisions for emulating the nine circuits of RS-232 (ITU-T V.24) serial ports. The RFCOMM protocol supports up to 60 simultaneous connections between two Bluetooth devices. The number of connections that may be used simultaneously in a Bluetooth device is implementation-specific.

Defines

PORT_MASK_ALL

RFCOMM Port Mask to enable all.

Typedefs

typedef int wiced_bt_rfcomm_result_t

RFCOMM result code (see wiced_bt_rfcomm_result_e)

typedef uint8_t wiced_bt_rfcomm_signal_t

RFCOMM Signals (see wiced_bt_rfcomm_signal_e)

void() wiced_bt_port_mgmt_cback_t (wiced_bt_rfcomm_result_t code, uint16_t port_handle)

Port management callback.

Parameters
void() wiced_bt_port_event_cback_t (wiced_bt_rfcomm_port_event_t event, uint16_t port_handle)

Port event callback.

Parameters
void() wiced_bt_port_tx_cback_t (uint16_t port_handle, void *p_data)

Port TX Complete callback.

Parameters

Enums

enum wiced_bt_rfcomm_port_event_t

wiced_bt_rfcomm_port_event_t: RFCOMM Port Event Masks.

Values:

enumerator PORT_EV_NONE

No event.

enumerator PORT_EV_RXCHAR

Any Character received.

enumerator PORT_EV_RXFLAG

Received certain character.

enumerator PORT_EV_TXEMPTY

Transmitt Queue Empty.

enumerator PORT_EV_CTS

CTS changed state.

enumerator PORT_EV_DSR

DSR changed state.

enumerator PORT_EV_RLSD

RLSD changed state.

enumerator PORT_EV_BREAK

BREAK received.

enumerator PORT_EV_ERR

Line status error occurred.

enumerator PORT_EV_RING

Ring signal detected.

enumerator PORT_EV_CTSS

CTS state.

enumerator PORT_EV_DSRS

DSR state.

enumerator PORT_EV_RLSDS

RLSD state.

enumerator PORT_EV_OVERRUN

receiver buffer overrun

enumerator PORT_EV_CONNECTED

RFCOMM connection established.

enumerator PORT_EV_CONNECT_ERR

Was not able to establish connection or disconnected.

enumerator PORT_EV_FC

data flow enabled flag changed by remote

enumerator PORT_EV_FCS

data flow enable status true = enabled

enum wiced_bt_rfcomm_result_e

wiced_bt_rfcomm_result_e: RFCOMM Result Codes.

Values:

enumerator WICED_BT_RFCOMM_SUCCESS

Success.

enumerator WICED_BT_RFCOMM_ERROR

Error.

enumerator WICED_BT_RFCOMM_ALREADY_OPENED

Already Opened.

enumerator WICED_BT_RFCOMM_CMD_PENDING

Command Pending.

enumerator WICED_BT_RFCOMM_APP_NOT_REGISTERED

App Not Registered.

enumerator WICED_BT_RFCOMM_NO_MEM

No Memory.

enumerator WICED_BT_RFCOMM_NO_RESOURCES

No Resources.

enumerator WICED_BT_RFCOMM_BAD_BD_ADDR

Bad BD Address.

enumerator WICED_BT_RFCOMM_INVALID_MTU

Invalid MTU.

enumerator WICED_BT_RFCOMM_BAD_HANDLE

Bad Handle.

enumerator WICED_BT_RFCOMM_NOT_OPENED

Not Opened.

enumerator WICED_BT_RFCOMM_LINE_ERR

Line Error.

enumerator WICED_BT_RFCOMM_START_FAILED

Start Failed.

enumerator WICED_BT_RFCOMM_PAR_NEG_FAILED

DLC parameter negotiation failed.

enumerator WICED_BT_RFCOMM_RFCOMM_NEG_FAILED

Remote port negotiation failed.

enumerator WICED_BT_RFCOMM_PEER_CONNECTION_FAILED

Peer Connection Failed.

enumerator WICED_BT_RFCOMM_PEER_FAILED

Peer Failed.

enumerator WICED_BT_RFCOMM_PEER_TIMEOUT

Peer Timeout.

enumerator WICED_BT_RFCOMM_CLOSED

Closed.

enumerator WICED_BT_RFCOMM_TX_FULL

No space to transmit the packet.

enumerator WICED_BT_RFCOMM_LOCAL_CLOSED

Local Closed.

enumerator WICED_BT_RFCOMM_LOCAL_TIMEOUT

Local Timeout.

enumerator WICED_BT_RFCOMM_TX_QUEUE_DISABLED

Transmit queue disabled.

enumerator WICED_BT_RFCOMM_PAGE_TIMEOUT

Page Timeout.

enumerator WICED_BT_RFCOMM_INVALID_SCN

Invalid SCN.

enum wiced_bt_rfcomm_signal_e

wiced_bt_rfcomm_signal_e: RFCOMM Signals.

Values:

enumerator PORT_SET_DTRDSR
enumerator PORT_CLR_DTRDSR

DTRDSR set.

enumerator PORT_SET_CTSRTS

DTRDSR clear.

enumerator PORT_CLR_CTSRTS

CTSRTS set.

enumerator PORT_SET_RI

CTSRTS clear.

enumerator PORT_CLR_RI

RI set (DCE only)

enumerator PORT_SET_DCD

RI clear (DCE only)

enumerator PORT_CLR_DCD

DCD set (DCE only)

enumerator PORT_BREAK

DCD clear (DCE only)

Functions

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_create_connection(uint16_t uuid, uint8_t scn, wiced_bool_t is_server, uint16_t mtu, wiced_bt_device_address_t bd_addr, uint16_t *p_handle, wiced_bt_port_mgmt_cback_t *p_mgmt_cb)

Establish serial port connection to the peer device, or allow RFCOMM to accept a connection from peer devices.

note

Server can call this function with the same scn parameter multiple times if it is ready to accept multiple simulteneous connections.

DLCI for the connection is (scn * 2 + 1) if client originates connection on existing none initiator multiplexer channel. Otherwise it is (scn * 2). For the server DLCI can be changed later if client will be calling it using (scn * 2 + 1) dlci.

Parameters
  • uuid[in] : The Universal Unique Identifier (UUID) of the Class ID of the service being opened

  • scn[in] : The Service Channel Number(SCN) as registered with the SDP (server) or obtained using SDP from the peer device (client)

  • is_server[in] : TRUE if requesting application is a server

  • mtu[in] : The maximum number of bytes transferred per frame If 0, a default size of L2CAP_MAX_BR_RX_MTU minus 5 bytes is used

  • bd_addr[in] : BD_ADDR of the peer (if client), NULL if server (see wiced_bt_device_address_t)

  • p_mgmt_cb[in] : Pointer to callback function to receive connection up/down events (see wiced_bt_port_mgmt_cback_t)

  • p_handle[out] : A pointer to the handle set by RFCOMM to be used in consecutive calls for this connection

Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_ALREADY_OPENED : If the client tries to establish a connection to the same BD_ADDR WICED_BT_RFCOMM_NO_RESOURCES : If there is not enough memory to allocate a control block structure

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_remove_connection(uint16_t handle, wiced_bool_t remove_server)

Close the specified connection.

Parameters
  • handle[in] : The connection handle returned by wiced_bt_rfcomm_create_connection.

  • remove_server[in] : (for server only) If TRUE, then also remove server; otherwise server remains enabled after connection is closed.

Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_set_event_callback(uint16_t port_handle, wiced_bt_port_event_cback_t *p_port_cb, wiced_bt_port_tx_cback_t *p_tx_cmpl_cb)

Set event callback the specified connection(neither of the callback can be NULL).

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_set_event_mask(uint16_t port_handle, wiced_bt_rfcomm_port_event_t mask)

Set events for which to be notified.

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_control(uint16_t handle, uint8_t signal)

Send control signal to the peer device.

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_flow_control(uint16_t handle, wiced_bool_t enable)

This function directs a specified connection to pass flow control message to the peer device.

Enable flag passed shows if port can accept more data.

Parameters
  • handle[in] : The connection handle returned by wiced_bt_rfcomm_create_connection

  • enable[in] : Flow control setting TRUE Enable data flow FALSE Disable data flow

Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_set_rx_fifo(uint16_t handle, char *p_mem, uint16_t size)

This function provides RFCOMM with a data area to receive peer’s data.

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_read_data(uint16_t handle, char *p_data, uint16_t max_len, uint16_t *p_len)

This function reads the received application data from the peer device.

Parameters
  • handle[in] : The connection handle returned by wiced_bt_rfcomm_create_connection

  • p_data[in] : Where to read the data into

  • max_len[in] : Maximum Byte count to read

  • p_len[out] : Bytes actually read

Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_write_data(uint16_t handle, char *p_data, uint16_t max_len)

This function sends the given application data to the peer device.

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_BAD_HANDLE : If the handle is out of range WICED_BT_RFCOMM_NOT_OPENED : If the connection is not opened

wiced_bt_rfcomm_result_t wiced_bt_rfcomm_check_connection(uint16_t handle, wiced_bt_device_address_t bd_addr, uint16_t *p_lcid)

This function checks connection referenced by handle is up and running.

Parameters
Returns

WICED_BT_RFCOMM_SUCCESS : If successful WICED_BT_RFCOMM_LINE_ERR : If connection is not up and running