rfcomm: add remote flag to RFCOMM_EVENT_PORT_CONFIGURATION

This commit is contained in:
Matthias Ringwald 2021-09-05 11:09:50 +02:00
parent a61bcdffff
commit 7b350471dd
3 changed files with 24 additions and 15 deletions

View File

@ -954,6 +954,7 @@ typedef uint8_t sm_key_t[16];
/**
* note: port configuration not parsed by stack, getters provided by rfcomm.h
* param rfcomm_cid
* param remote - 0 for local port, 1 for remote port
* param baud_rate
* param data_bits
* param stop_bits

View File

@ -306,13 +306,14 @@ static void rfcomm_emit_remote_line_status(rfcomm_channel_t *channel, uint8_t li
(channel->packet_handler)(HCI_EVENT_PACKET, 0, event, sizeof(event));
}
static void rfcomm_emit_port_configuration(rfcomm_channel_t *channel){
static void rfcomm_emit_port_configuration(rfcomm_channel_t *channel, bool remote){
// notify client about new settings
uint8_t event[2+2+sizeof(rfcomm_rpn_data_t)];
uint8_t event[2+2+1+sizeof(rfcomm_rpn_data_t)];
event[0] = RFCOMM_EVENT_PORT_CONFIGURATION;
event[1] = sizeof(rfcomm_rpn_data_t);
event[1] = sizeof(event) - 2;
little_endian_store_16(event, 2, channel->rfcomm_cid);
(void)memcpy(&event[4], (uint8_t *)&channel->rpn_data, sizeof(rfcomm_rpn_data_t));
event[4] = remote ? 1 : 0;
(void)memcpy(&event[5], (uint8_t *)&channel->rpn_data, sizeof(rfcomm_rpn_data_t));
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
(channel->packet_handler)(HCI_EVENT_PACKET, channel->rfcomm_cid, event, sizeof(event));
}
@ -1395,7 +1396,7 @@ static void rfcomm_channel_opened(rfcomm_channel_t *rfChannel){
rfChannel->state = RFCOMM_CHANNEL_OPEN;
rfcomm_emit_channel_opened(rfChannel, 0);
rfcomm_emit_port_configuration(rfChannel);
rfcomm_emit_port_configuration(rfChannel, false);
// remove (potential) timer
rfcomm_multiplexer_t *multiplexer = rfChannel->multiplexer;
@ -1872,7 +1873,7 @@ static void rfcomm_channel_state_machine_with_channel(rfcomm_channel_t *channel,
rfcomm_rpn_data_update(&channel->rpn_data, &event_rpn->data);
rfcomm_channel_state_add(channel, RFCOMM_CHANNEL_STATE_VAR_SEND_RPN_RSP);
// notify client about new settings
rfcomm_emit_port_configuration(channel);
rfcomm_emit_port_configuration(channel, false);
return;
}

View File

@ -444,6 +444,15 @@ static inline uint16_t rfcomm_event_port_configuration_get_rfcomm_cid(const uint
return little_endian_read_16(event, 2);
}
/**
* @brief Get field local from event RFCOMM_EVENT_PORT_CONFIGURATION
* @param event packet
* @return remote - false for local port, true for remote port
*/
static inline bool rfcomm_event_port_configuration_get_remote(const uint8_t * event){
return event[4] != 0;
}
/**
* @brief Get field baud_rate from event RFCOMM_EVENT_PORT_CONFIGURATION
* @param event packet
@ -451,7 +460,7 @@ static inline uint16_t rfcomm_event_port_configuration_get_rfcomm_cid(const uint
*/
static inline rpn_baud_t rfcomm_event_port_configuration_get_baud_rate(const uint8_t * event){
return (rpn_baud_t) event[4];
return (rpn_baud_t) event[5];
}
/**
@ -461,26 +470,24 @@ static inline rpn_baud_t rfcomm_event_port_configuration_get_baud_rate(const uin
*/
static inline rpn_data_bits_t rfcomm_event_port_configuration_get_data_bits(const uint8_t * event){
return (rpn_data_bits_t) (event[5] & 3);
return (rpn_data_bits_t) (event[6] & 3);
}
/**
* @brief Get field stop_bits from event RFCOMM_EVENT_PORT_CONFIGURATION
* @param event packet
* @return stop_bits
* @note: btstack_type 1
*/
static inline rpn_stop_bits_t rfcomm_event_port_configuration_get_stop_bits(const uint8_t * event){
return (rpn_stop_bits_t) ((event[5] >> 2) & 1);
return (rpn_stop_bits_t) ((event[6] >> 2) & 1);
}
/**
* @brief Get field parity from event RFCOMM_EVENT_PORT_CONFIGURATION
* @param event packet
* @return parity
* @note: btstack_type 1
*/
static inline rpn_parity_t rfcomm_event_port_configuration_get_parity(const uint8_t * event){
return (rpn_parity_t) ((event[5] >> 3) & 7);
return (rpn_parity_t) ((event[6] >> 3) & 7);
}
/**
@ -490,7 +497,7 @@ static inline rpn_parity_t rfcomm_event_port_configuration_get_parity(const uint
*/
static inline uint8_t rfcomm_event_port_configuration_get_flow_control(const uint8_t * event){
return event[6] & 0x3f;
return event[7] & 0x3f;
}
/**
@ -499,7 +506,7 @@ static inline uint8_t rfcomm_event_port_configuration_get_flow_control(const uin
* @return xon
*/
static inline uint8_t rfcomm_event_port_configuration_get_xon(const uint8_t * event){
return event[7];
return event[8];
}
/**
@ -508,7 +515,7 @@ static inline uint8_t rfcomm_event_port_configuration_get_xon(const uint8_t * ev
* @return xoff
*/
static inline uint8_t rfcomm_event_port_configuration_get_xoff(const uint8_t * event){
return event[8];
return event[9];
}
/**