RFCOMM API

#include "src/classic/rfcomm.h"

rfcomm_init

void rfcomm_init(void);

Set up RFCOMM.

Source


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

Source


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

Returns

Source


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

Returns

Source


rfcomm_disconnect

uint8_t rfcomm_disconnect(uint16_t rfcomm_cid);

Disconnects RFCOMM channel with given identifier.

Returns

Source


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

Returns

Source


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

Returns

Source


rfcomm_unregister_service

void rfcomm_unregister_service(uint8_t service_channel);

Unregister RFCOMM service.

Source


rfcomm_accept_connection

uint8_t rfcomm_accept_connection(uint16_t rfcomm_cid);

Accepts incoming RFCOMM connection.

Returns

Source


rfcomm_decline_connection

uint8_t rfcomm_decline_connection(uint16_t rfcomm_cid);

Deny incoming RFCOMM connection.

Returns

Source


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

Source


rfcomm_can_send_packet_now

bool rfcomm_can_send_packet_now(uint16_t rfcomm_cid);

Checks if RFCOMM can send packet.

Parameters

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


rfcomm_query_port_configuration

uint8_t rfcomm_query_port_configuration(uint16_t rfcomm_cid);

Query remote port

Parameters

Returns

Source


rfcomm_get_max_frame_size

uint16_t rfcomm_get_max_frame_size(uint16_t rfcomm_cid);

Query max frame size

Parameters

Returns

Source


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) }

Source


rfcomm_get_outgoing_buffer

uint8_t * rfcomm_get_outgoing_buffer(void);

Get outgoing buffer

Returns

Source


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

Returns

Source


rfcomm_release_packet_buffer

void rfcomm_release_packet_buffer(void);

Release outgoing buffer in case rfcomm_send_prepared was not called

Source


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

Source


// 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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


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

Returns

Source


rfcomm_deinit

void rfcomm_deinit(void);

De-Init RFCOMM

Source