Microchip® Advanced Software Framework

rfcomm.h File Reference
#include "btstack_util.h"
#include <stdint.h>
#include "btstack_run_loop.h"
#include "gap.h"

Data Structures

struct  rfcomm_channel_t
 
struct  rfcomm_multiplexer_t
 
struct  rfcomm_rpn_data
 
struct  rfcomm_service_t
 

Macros

#define RFCOMM_RLS_STATUS_INVALID   0xff
 
#define RFCOMM_TEST_DATA_MAX_LEN   4
 
#define UNLIMITED_INCOMING_CREDITS   0xff
 

Typedefs

typedef struct rfcomm_rpn_data rfcomm_rpn_data_t
 

Enumerations

enum  RFCOMM_CHANNEL_STATE {
  RFCOMM_CHANNEL_CLOSED = 1,
  RFCOMM_CHANNEL_W4_MULTIPLEXER,
  RFCOMM_CHANNEL_SEND_UIH_PN,
  RFCOMM_CHANNEL_W4_PN_RSP,
  RFCOMM_CHANNEL_SEND_SABM_W4_UA,
  RFCOMM_CHANNEL_W4_UA,
  RFCOMM_CHANNEL_INCOMING_SETUP,
  RFCOMM_CHANNEL_DLC_SETUP,
  RFCOMM_CHANNEL_OPEN,
  RFCOMM_CHANNEL_SEND_UA_AFTER_DISC,
  RFCOMM_CHANNEL_SEND_DISC,
  RFCOMM_CHANNEL_W4_UA_AFTER_UA,
  RFCOMM_CHANNEL_SEND_DM
}
 
enum  RFCOMM_CHANNEL_STATE_VAR {
  RFCOMM_CHANNEL_STATE_VAR_NONE = 0,
  RFCOMM_CHANNEL_STATE_VAR_CLIENT_ACCEPTED = 1 << 0,
  RFCOMM_CHANNEL_STATE_VAR_RCVD_PN = 1 << 1,
  RFCOMM_CHANNEL_STATE_VAR_RCVD_RPN = 1 << 2,
  RFCOMM_CHANNEL_STATE_VAR_RCVD_SABM = 1 << 3,
  RFCOMM_CHANNEL_STATE_VAR_RCVD_MSC_CMD = 1 << 4,
  RFCOMM_CHANNEL_STATE_VAR_RCVD_MSC_RSP = 1 << 5,
  RFCOMM_CHANNEL_STATE_VAR_SEND_PN_RSP = 1 << 6,
  RFCOMM_CHANNEL_STATE_VAR_SEND_RPN_INFO = 1 << 7,
  RFCOMM_CHANNEL_STATE_VAR_SEND_RPN_RSP = 1 << 8,
  RFCOMM_CHANNEL_STATE_VAR_SEND_UA = 1 << 9,
  RFCOMM_CHANNEL_STATE_VAR_SEND_MSC_CMD = 1 << 10,
  RFCOMM_CHANNEL_STATE_VAR_SEND_MSC_RSP = 1 << 11,
  RFCOMM_CHANNEL_STATE_VAR_SEND_CREDITS = 1 << 12,
  RFCOMM_CHANNEL_STATE_VAR_SENT_MSC_CMD = 1 << 13,
  RFCOMM_CHANNEL_STATE_VAR_SENT_MSC_RSP = 1 << 14,
  RFCOMM_CHANNEL_STATE_VAR_SENT_CREDITS = 1 << 15
}
 
enum  RFCOMM_MULTIPLEXER_EVENT { MULT_EV_READY_TO_SEND = 1 }
 
enum  RFCOMM_MULTIPLEXER_STATE {
  RFCOMM_MULTIPLEXER_CLOSED = 1,
  RFCOMM_MULTIPLEXER_W4_CONNECT,
  RFCOMM_MULTIPLEXER_SEND_SABM_0,
  RFCOMM_MULTIPLEXER_W4_UA_0,
  RFCOMM_MULTIPLEXER_W4_SABM_0,
  RFCOMM_MULTIPLEXER_SEND_UA_0,
  RFCOMM_MULTIPLEXER_OPEN,
  RFCOMM_MULTIPLEXER_SEND_UA_0_AND_DISC
}
 

Functions

void rfcomm_accept_connection (uint16_t rfcomm_cid)
 Accepts incoming RFCOMM connection. More...
 
int rfcomm_can_send_packet_now (uint16_t rfcomm_cid)
 Checks if RFCOMM can send packet. More...
 
uint8_t rfcomm_create_channel (btstack_packet_handler_t packet_handler, bd_addr_t addr, uint8_t server_channel, uint16_t *out_cid)
 
uint8_t rfcomm_create_channel_with_initial_credits (btstack_packet_handler_t packet_handler, bd_addr_t addr, uint8_t server_channel, uint8_t initial_credits, uint16_t *out_cid)
 
void rfcomm_decline_connection (uint16_t rfcomm_cid)
 Deny incoming RFCOMM connection. More...
 
void rfcomm_disconnect (uint16_t rfcomm_cid)
 Disconnects RFCOMM channel with given identifier. More...
 
uint16_t rfcomm_get_max_frame_size (uint16_t rfcomm_cid)
 Query max frame size. More...
 
uint8_t * rfcomm_get_outgoing_buffer (void)
 
void rfcomm_grant_credits (uint16_t rfcomm_cid, uint8_t credits)
 Grant more incoming credits to the remote side for the given RFCOMM channel identifier. More...
 
void rfcomm_init (void)
 Set up RFCOMM. More...
 
int rfcomm_query_port_configuration (uint16_t rfcomm_cid)
 Query remote port. More...
 
uint8_t rfcomm_register_service (btstack_packet_handler_t packet_handler, uint8_t channel, uint16_t max_frame_size)
 Registers RFCOMM service for a server channel and a maximum frame size, and assigns a packet handler. More...
 
uint8_t rfcomm_register_service_with_initial_credits (btstack_packet_handler_t packet_handler, uint8_t channel, uint16_t max_frame_size, uint8_t initial_credits)
 Registers RFCOMM service for a server channel and a maximum frame size, and assigns a packet handler. More...
 
void rfcomm_release_packet_buffer (void)
 
void rfcomm_request_can_send_now_event (uint16_t rfcomm_cid)
 Request emission of RFCOMM_EVENT_CAN_SEND_NOW as soon as possible. More...
 
int rfcomm_reserve_packet_buffer (void)
 Allow to create RFCOMM packet in outgoing buffer. More...
 
int rfcomm_send (uint16_t rfcomm_cid, uint8_t *data, uint16_t len)
 Sends RFCOMM data packet to the RFCOMM channel with given identifier. More...
 
int rfcomm_send_local_line_status (uint16_t rfcomm_cid, uint8_t line_status)
 Sends Local Line Status, see LINE_STATUS_. More...
 
int rfcomm_send_modem_status (uint16_t rfcomm_cid, uint8_t modem_status)
 Send local modem status. More...
 
int rfcomm_send_port_configuration (uint16_t rfcomm_cid, rpn_baud_t baud_rate, rpn_data_bits_t data_bits, rpn_stop_bits_t stop_bits, rpn_parity_t parity, rpn_flow_control_t flow_control)
 Configure remote port. More...
 
int rfcomm_send_prepared (uint16_t rfcomm_cid, uint16_t len)
 
void rfcomm_set_required_security_level (gap_security_level_t security_level)
 Set security level required for incoming connections, need to be called before registering services. More...
 
void rfcomm_unregister_service (uint8_t service_channel)
 Unregister RFCOMM service. More...
 

#define RFCOMM_RLS_STATUS_INVALID   0xff
#define RFCOMM_TEST_DATA_MAX_LEN   4
#define UNLIMITED_INCOMING_CREDITS   0xff

Enumerator
RFCOMM_CHANNEL_CLOSED 
RFCOMM_CHANNEL_W4_MULTIPLEXER 
RFCOMM_CHANNEL_SEND_UIH_PN 
RFCOMM_CHANNEL_W4_PN_RSP 
RFCOMM_CHANNEL_SEND_SABM_W4_UA 
RFCOMM_CHANNEL_W4_UA 
RFCOMM_CHANNEL_INCOMING_SETUP 
RFCOMM_CHANNEL_DLC_SETUP 
RFCOMM_CHANNEL_OPEN 
RFCOMM_CHANNEL_SEND_UA_AFTER_DISC 
RFCOMM_CHANNEL_SEND_DISC 
RFCOMM_CHANNEL_W4_UA_AFTER_UA 
RFCOMM_CHANNEL_SEND_DM 
Enumerator
RFCOMM_CHANNEL_STATE_VAR_NONE 
RFCOMM_CHANNEL_STATE_VAR_CLIENT_ACCEPTED 
RFCOMM_CHANNEL_STATE_VAR_RCVD_PN 
RFCOMM_CHANNEL_STATE_VAR_RCVD_RPN 
RFCOMM_CHANNEL_STATE_VAR_RCVD_SABM 
RFCOMM_CHANNEL_STATE_VAR_RCVD_MSC_CMD 
RFCOMM_CHANNEL_STATE_VAR_RCVD_MSC_RSP 
RFCOMM_CHANNEL_STATE_VAR_SEND_PN_RSP 
RFCOMM_CHANNEL_STATE_VAR_SEND_RPN_INFO 
RFCOMM_CHANNEL_STATE_VAR_SEND_RPN_RSP 
RFCOMM_CHANNEL_STATE_VAR_SEND_UA 
RFCOMM_CHANNEL_STATE_VAR_SEND_MSC_CMD 
RFCOMM_CHANNEL_STATE_VAR_SEND_MSC_RSP 
RFCOMM_CHANNEL_STATE_VAR_SEND_CREDITS 
RFCOMM_CHANNEL_STATE_VAR_SENT_MSC_CMD 
RFCOMM_CHANNEL_STATE_VAR_SENT_MSC_RSP 
RFCOMM_CHANNEL_STATE_VAR_SENT_CREDITS 
Enumerator
MULT_EV_READY_TO_SEND 
Enumerator
RFCOMM_MULTIPLEXER_CLOSED 
RFCOMM_MULTIPLEXER_W4_CONNECT 
RFCOMM_MULTIPLEXER_SEND_SABM_0 
RFCOMM_MULTIPLEXER_W4_UA_0 
RFCOMM_MULTIPLEXER_W4_SABM_0 
RFCOMM_MULTIPLEXER_SEND_UA_0 
RFCOMM_MULTIPLEXER_OPEN 
RFCOMM_MULTIPLEXER_SEND_UA_0_AND_DISC 

void rfcomm_accept_connection ( uint16_t  rfcomm_cid)

Accepts incoming RFCOMM connection.

int rfcomm_can_send_packet_now ( uint16_t  rfcomm_cid)

Checks if RFCOMM can send packet.

Parameters
rfcomm_cid
Returns
!= 0 if can send now
uint8_t rfcomm_create_channel ( btstack_packet_handler_t  packet_handler,
bd_addr_t  addr,
uint8_t  server_channel,
uint16_t *  out_cid 
)
uint8_t rfcomm_create_channel_with_initial_credits ( btstack_packet_handler_t  packet_handler,
bd_addr_t  addr,
uint8_t  server_channel,
uint8_t  initial_credits,
uint16_t *  out_cid 
)
void rfcomm_decline_connection ( uint16_t  rfcomm_cid)

Deny incoming RFCOMM connection.

void rfcomm_disconnect ( uint16_t  rfcomm_cid)

Disconnects RFCOMM channel with given identifier.

uint16_t rfcomm_get_max_frame_size ( uint16_t  rfcomm_cid)

Query max frame size.

Parameters
rfcomm_cid
uint8_t* rfcomm_get_outgoing_buffer ( void  )
void rfcomm_grant_credits ( uint16_t  rfcomm_cid,
uint8_t  credits 
)

Grant more incoming credits to the remote side for the given RFCOMM channel identifier.

void rfcomm_init ( void  )

Set up RFCOMM.

int rfcomm_query_port_configuration ( uint16_t  rfcomm_cid)

Query remote port.

Parameters
rfcomm_cid
uint8_t rfcomm_register_service ( btstack_packet_handler_t  packet_handler,
uint8_t  channel,
uint16_t  max_frame_size 
)

Registers RFCOMM service for a server channel and a maximum frame size, and assigns a packet handler.

This channel provides credits automatically to the remote side -> no flow control

Parameters
packethandler for all channels of this service
channel
max_frame_size
uint8_t rfcomm_register_service_with_initial_credits ( btstack_packet_handler_t  packet_handler,
uint8_t  channel,
uint16_t  max_frame_size,
uint8_t  initial_credits 
)

Registers RFCOMM service for a server channel and a maximum frame size, and assigns a packet handler.

This channel will use explicit credit management. During channel establishment, an initial amount of credits is provided.

Parameters
packethandler for all channels of this service
channel
max_frame_size
initial_credits
void rfcomm_release_packet_buffer ( void  )
void rfcomm_request_can_send_now_event ( uint16_t  rfcomm_cid)

Request emission of RFCOMM_EVENT_CAN_SEND_NOW as soon as possible.

Note
RFCOMM_EVENT_CAN_SEND_NOW might be emitted during call to this function so packet handler should be ready to handle it
Parameters
rfcomm_cid
int rfcomm_reserve_packet_buffer ( void  )

Allow to create RFCOMM packet in outgoing buffer.

if (rfcomm_can_send_packet_now(cid)){ rfcomm_reserve_packet_buffer(); uint8_t * buffer = rfcomm_get_outgoing_buffer(); uint16_t buffer_size = rfcomm_get_max_frame_size(cid); // .. setup data in buffer with len rfcomm_send_prepared(cid, len) }

int rfcomm_send ( uint16_t  rfcomm_cid,
uint8_t *  data,
uint16_t  len 
)

Sends RFCOMM data packet to the RFCOMM channel with given identifier.

Parameters
rfcomm_cid
int rfcomm_send_local_line_status ( uint16_t  rfcomm_cid,
uint8_t  line_status 
)

Sends Local Line Status, see LINE_STATUS_.

Parameters
rfcomm_cid
line_status
int rfcomm_send_modem_status ( uint16_t  rfcomm_cid,
uint8_t  modem_status 
)

Send local modem status.

see MODEM_STAUS_..

Parameters
rfcomm_cid
modem_status
int rfcomm_send_port_configuration ( uint16_t  rfcomm_cid,
rpn_baud_t  baud_rate,
rpn_data_bits_t  data_bits,
rpn_stop_bits_t  stop_bits,
rpn_parity_t  parity,
rpn_flow_control_t  flow_control 
)

Configure remote port.

Parameters
rfcomm_cid
baud_rate
data_bits
stop_bits
parity
flow_control
int rfcomm_send_prepared ( uint16_t  rfcomm_cid,
uint16_t  len 
)
void rfcomm_set_required_security_level ( gap_security_level_t  security_level)

Set security level required for incoming connections, need to be called before registering services.

void rfcomm_unregister_service ( uint8_t  service_channel)

Unregister RFCOMM service.