RFCOMM API
#include "src/classic/rfcomm.h"
rfcomm_init
void rfcomm_init(void);
Set up RFCOMM.
rfcomm_set_required_security_level
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.
@deprecated: use gap_set_security_level instead
rfcomm_create_channel
uint8_t rfcomm_create_channel(btstack_packet_handler_t packet_handler, bd_addr_t addr, uint8_t server_channel, uint16_t * out_cid);
Set security level required for incoming connections, need to be called before registering services.
@deprecated: use gap_set_security_level instead / void rfcomm_set_required_security_level(gap_security_level_t security_level);
/*
Create RFCOMM connection to a given server channel on a remote deivce. This channel will automatically provide enough credits to the remote side.
Parameters
- packet_handler: non-NULL handler for channel events and data
- addr: non-NULL remote address
- server_channel
- out_cid
Returns
- uint8_t: status
rfcomm_create_channel_with_initial_credits
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);
Set security level required for incoming connections, need to be called before registering services.
@deprecated: use gap_set_security_level instead / void rfcomm_set_required_security_level(gap_security_level_t security_level);
/*
Create RFCOMM connection to a given server channel on a remote deivce. This channel will automatically provide enough credits to the remote side.
Create RFCOMM connection to a given server channel on a remote deivce. This channel will use explicit credit management. During channel establishment, an initial amount of credits is provided.
Parameters
- packet_handler: non-NULL handler for channel events and data
- addr: non-NULL remote address
- server_channel
- out_cid
- packet_handler: non-NULL handler for channel events and data
- addr: non-NULL remote address
- server_channel
- initial_credits
- out_cid
Returns
- uint8_t: status / uint8_t rfcomm_create_channel(btstack_packet_handler_t packet_handler, bd_addr_t addr, uint8_t server_channel, uint16_t * out_cid); /* status
rfcomm_disconnect
uint8_t rfcomm_disconnect(uint16_t rfcomm_cid);
Disconnects RFCOMM channel with given identifier.
Returns
- uint8_t: status
rfcomm_register_service
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
- packet_handler: non-NULL handler for all channels of this service
- channel
- max_frame_size
Returns
- uint8_t: status ERROR_CODE_SUCCESS if successful, otherwise L2CAP_SERVICE_ALREADY_REGISTERED or BTSTACK_MEMORY_ALLOC_FAILED
rfcomm_register_service_with_initial_credits
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
- packet_handler: non-NULL handler for all channels of this service
- channel
- max_frame_size
- initial_credits
Returns
- uint8_t: status ERROR_CODE_SUCCESS if successful, otherwise L2CAP_SERVICE_ALREADY_REGISTERED or BTSTACK_MEMORY_ALLOC_FAILED
rfcomm_unregister_service
void rfcomm_unregister_service(uint8_t service_channel);
Unregister RFCOMM service.
rfcomm_accept_connection
uint8_t rfcomm_accept_connection(uint16_t rfcomm_cid);
Accepts incoming RFCOMM connection.
Returns
- uint8_t: status
rfcomm_decline_connection
uint8_t rfcomm_decline_connection(uint16_t rfcomm_cid);
Deny incoming RFCOMM connection.
Returns
- uint8_t: status
rfcomm_grant_credits
uint8_t rfcomm_grant_credits(uint16_t rfcomm_cid, uint8_t credits);
Grant more incoming credits to the remote side for the given RFCOMM channel identifier.
Returns
- uint8_t: status
rfcomm_can_send_packet_now
bool rfcomm_can_send_packet_now(uint16_t rfcomm_cid);
Checks if RFCOMM can send packet.
Parameters
- rfcomm_cid
Returns
- bool: true if can send now
rfcomm_request_can_send_now_event
uint8_t 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
@prarm: status
Parameters
- rfcomm_cid
Returns
- uint8_t
rfcomm_send
uint8_t rfcomm_send(uint16_t rfcomm_cid, const uint8_t *data, uint16_t len);
Sends RFCOMM data packet to the RFCOMM channel with given identifier.
Parameters
- rfcomm_cid
- data: non-NULL if len is nonzero
- len: number of payload bytes
Returns
- uint8_t: status
rfcomm_send_local_line_status
uint8_t 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
Returns
- uint8_t: status
rfcomm_send_modem_status
uint8_t rfcomm_send_modem_status(uint16_t rfcomm_cid, uint8_t modem_status);
Send local modem status. see MODEM_STAUS_..
Parameters
- rfcomm_cid
- modem_status
Returns
- uint8_t: status
rfcomm_send_port_configuration
uint8_t 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, uint8_t flow_control);
Configure remote port
Parameters
- rfcomm_cid
- baud_rate
- data_bits
- stop_bits
- parity
- flow_control
Returns
- uint8_t: status
rfcomm_query_port_configuration
uint8_t rfcomm_query_port_configuration(uint16_t rfcomm_cid);
Query remote port
Parameters
- rfcomm_cid
Returns
- uint8_t: status
rfcomm_get_max_frame_size
uint16_t rfcomm_get_max_frame_size(uint16_t rfcomm_cid);
Query max frame size
Parameters
- rfcomm_cid
Returns
- uint16_t: max frame size
rfcomm_reserve_packet_buffer
void rfcomm_reserve_packet_buffer(void);
Reserve packet buffer to allow to create RFCOMM packet in place
Note: Must only be called after a 'can send now' check or event
Note: Asserts if packet buffer is already reserved
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) }
rfcomm_get_outgoing_buffer
uint8_t * rfcomm_get_outgoing_buffer(void);
Get outgoing buffer
Returns
- uint8_t *: pointer to outgoing rfcomm buffer
rfcomm_send_prepared
uint8_t rfcomm_send_prepared(uint16_t rfcomm_cid, uint16_t len);
Send packet prepared in outgoing buffer
Note: This releases the outgoing rfcomm buffer
Parameters
- rfcomm_cid
- len
Returns
- uint8_t: status
rfcomm_release_packet_buffer
void rfcomm_release_packet_buffer(void);
Release outgoing buffer in case rfcomm_send_prepared was not called
rfcomm_enable_l2cap_ertm
void rfcomm_enable_l2cap_ertm(void request_callback(rfcomm_ertm_request_t * request), void released_callback(uint16_t ertm_id));
Enable L2CAP ERTM mode for RFCOMM. request callback is used to provide ERTM buffer. released callback returns buffer
Note: on request_callback, the app must set the ertm_config, buffer, size fields to enable ERTM for the current connection
Note: if buffer is not set, BASIC mode will be used instead
Note: released_callback provides ertm_id from earlier request to match request and release
Parameters
- request_callback
- released_callback
// Event getters for RFCOMM_EVENT_PORT_CONFIGURATION
rfcomm_event_port_configuration_get_rfcomm_cid
static inline uint16_t rfcomm_event_port_configuration_get_rfcomm_cid(const uint8_t * event);
Get field rfcomm_cid from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- uint16_t: rfcomm_cid
rfcomm_event_port_configuration_get_remote
static inline bool rfcomm_event_port_configuration_get_remote(const uint8_t * event);
Get field local from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- bool: remote - false for local port, true for remote port
rfcomm_event_port_configuration_get_baud_rate
static inline rpn_baud_t rfcomm_event_port_configuration_get_baud_rate(const uint8_t * event);
Get field baud_rate from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- rpn_baud_t: baud_rate
rfcomm_event_port_configuration_get_data_bits
static inline rpn_data_bits_t rfcomm_event_port_configuration_get_data_bits(const uint8_t * event);
Get field data_bits from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- rpn_data_bits_t: data_bits
rfcomm_event_port_configuration_get_stop_bits
static inline rpn_stop_bits_t rfcomm_event_port_configuration_get_stop_bits(const uint8_t * event);
Get field stop_bits from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- rpn_stop_bits_t: stop_bits
rfcomm_event_port_configuration_get_parity
static inline rpn_parity_t rfcomm_event_port_configuration_get_parity(const uint8_t * event);
Get field parity from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- rpn_parity_t: parity
rfcomm_event_port_configuration_get_flow_control
static inline uint8_t rfcomm_event_port_configuration_get_flow_control(const uint8_t * event);
Get field flow_control from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- uint8_t: flow_control
rfcomm_event_port_configuration_get_xon
static inline uint8_t rfcomm_event_port_configuration_get_xon(const uint8_t * event);
Get field xon from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- uint8_t: xon
rfcomm_event_port_configuration_get_xoff
static inline uint8_t rfcomm_event_port_configuration_get_xoff(const uint8_t * event);
Get field xoff from event RFCOMM_EVENT_PORT_CONFIGURATION
Parameters
- event: packet
Returns
- uint8_t: xoff
rfcomm_deinit
void rfcomm_deinit(void);
De-Init RFCOMM