l2cap: provide incoming flag for L2CAP and RFCOMM opened events

This commit is contained in:
Matthias Ringwald 2016-10-23 22:08:44 +02:00
parent e70923579b
commit bab5f4f00b
4 changed files with 29 additions and 6 deletions

View File

@ -369,7 +369,7 @@ typedef uint8_t sm_key_t[16];
// L2CAP EVENTS
/**
* @format 1BH222222
* @format 1BH2222221
* @param status
* @param address
* @param handle
@ -379,6 +379,7 @@ typedef uint8_t sm_key_t[16];
* @param local_mtu
* @param remote_mtu
* @param flush_timeout
* @param incoming
*/
#define L2CAP_EVENT_CHANNEL_OPENED 0x70
@ -477,13 +478,14 @@ typedef uint8_t sm_key_t[16];
// RFCOMM EVENTS
/**
* @format 1B2122
* @format 1B21221
* @param status
* @param bd_addr
* @param con_handle
* @param server_channel
* @param rfcomm_cid
* @param max_frame_size
* @param incoming
*/
#define RFCOMM_EVENT_CHANNEL_OPENED 0x80

View File

@ -1034,6 +1034,15 @@ static inline uint16_t l2cap_event_channel_opened_get_remote_mtu(const uint8_t *
static inline uint16_t l2cap_event_channel_opened_get_flush_timeout(const uint8_t * event){
return little_endian_read_16(event, 21);
}
/**
* @brief Get field incoming from event L2CAP_EVENT_CHANNEL_OPENED
* @param event packet
* @return incoming
* @note: btstack_type 1
*/
static inline uint8_t l2cap_event_channel_opened_get_incoming(const uint8_t * event){
return event[23];
}
/**
* @brief Get field local_cid from event L2CAP_EVENT_CHANNEL_CLOSED
@ -1396,6 +1405,15 @@ static inline uint16_t rfcomm_event_channel_opened_get_rfcomm_cid(const uint8_t
static inline uint16_t rfcomm_event_channel_opened_get_max_frame_size(const uint8_t * event){
return little_endian_read_16(event, 14);
}
/**
* @brief Get field incoming from event RFCOMM_EVENT_CHANNEL_OPENED
* @param event packet
* @return incoming
* @note: btstack_type 1
*/
static inline uint8_t rfcomm_event_channel_opened_get_incoming(const uint8_t * event){
return event[16];
}
/**
* @brief Get field rfcomm_cid from event RFCOMM_EVENT_CHANNEL_CLOSED

View File

@ -164,7 +164,7 @@ static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status
log_info("RFCOMM_EVENT_CHANNEL_OPENED status 0x%x addr %s handle 0x%x channel #%u cid 0x%02x mtu %u",
status, bd_addr_to_str(channel->multiplexer->remote_addr), channel->multiplexer->con_handle,
channel->dlci>>1, channel->rfcomm_cid, channel->max_frame_size);
uint8_t event[16];
uint8_t event[18];
uint8_t pos = 0;
event[pos++] = RFCOMM_EVENT_CHANNEL_OPENED; // 0
event[pos++] = sizeof(event) - 2; // 1
@ -174,6 +174,7 @@ static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status
event[pos++] = channel->dlci >> 1; // 11
little_endian_store_16(event, pos, channel->rfcomm_cid); pos += 2; // 12 - channel ID
little_endian_store_16(event, pos, channel->max_frame_size); pos += 2; // max frame size
event[pos++] = channel->service ? 1 : 0; // linked to service -> incoming
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
(channel->packet_handler)(HCI_EVENT_PACKET, 0, event, pos);

View File

@ -297,7 +297,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
log_info("L2CAP_EVENT_CHANNEL_OPENED status 0x%x addr %s handle 0x%x psm 0x%x local_cid 0x%x remote_cid 0x%x local_mtu %u, remote_mtu %u, flush_timeout %u",
status, bd_addr_to_str(channel->address), channel->con_handle, channel->psm,
channel->local_cid, channel->remote_cid, channel->local_mtu, channel->remote_mtu, channel->flush_timeout);
uint8_t event[23];
uint8_t event[24];
event[0] = L2CAP_EVENT_CHANNEL_OPENED;
event[1] = sizeof(event) - 2;
event[2] = status;
@ -309,6 +309,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
little_endian_store_16(event, 17, channel->local_mtu);
little_endian_store_16(event, 19, channel->remote_mtu);
little_endian_store_16(event, 21, channel->flush_timeout);
event[23] = channel->state_var & L2CAP_CHANNEL_STATE_VAR_INCOMING ? 1 : 0;
hci_dump_packet( HCI_EVENT_PACKET, 0, event, sizeof(event));
l2cap_dispatch_to_channel(channel, HCI_EVENT_PACKET, event, sizeof(event));
}
@ -1275,8 +1276,9 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig
}
// set initial state
channel->state = L2CAP_STATE_WAIT_INCOMING_SECURITY_LEVEL_UPDATE;
channel->state_var = L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND;
channel->state = L2CAP_STATE_WAIT_INCOMING_SECURITY_LEVEL_UPDATE;
channel->state_var = L2CAP_CHANNEL_STATE_VAR_SEND_CONN_RESP_PEND;
channel->state_var |= L2CAP_CHANNEL_STATE_VAR_INCOMING;
// add to connections list
btstack_linked_list_add(&l2cap_channels, (btstack_linked_item_t *) channel);