component/bt: merge the HCI packet reassemble logic modification
This commit is contained in:
parent
17696bc679
commit
6cb9985e5d
2 changed files with 13 additions and 14 deletions
|
@ -366,7 +366,8 @@ static void fragmenter_transmit_finished(BT_HDR *packet, bool all_fragments_sent
|
||||||
// This is kind of a weird case, since we're dispatching a partially sent packet
|
// This is kind of a weird case, since we're dispatching a partially sent packet
|
||||||
// up to a higher layer.
|
// up to a higher layer.
|
||||||
// TODO(zachoverflow): rework upper layer so this isn't necessary.
|
// TODO(zachoverflow): rework upper layer so this isn't necessary.
|
||||||
dispatch_reassembled(packet);
|
buffer_allocator->free(packet);
|
||||||
|
//dispatch_reassembled(packet);
|
||||||
//data_dispatcher_dispatch(interface.event_dispatcher, packet->event & MSG_EVT_MASK, packet);
|
//data_dispatcher_dispatch(interface.event_dispatcher, packet->event & MSG_EVT_MASK, packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,13 +125,13 @@ static void fragment_and_dispatch(BT_HDR *packet)
|
||||||
|
|
||||||
static void reassemble_and_dispatch(BT_HDR *packet)
|
static void reassemble_and_dispatch(BT_HDR *packet)
|
||||||
{
|
{
|
||||||
|
LOG_DEBUG("reassemble_and_dispatch\n");
|
||||||
|
|
||||||
if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
|
if ((packet->event & MSG_EVT_MASK) == MSG_HC_TO_STACK_HCI_ACL) {
|
||||||
uint8_t *stream = packet->data + packet->offset;
|
uint8_t *stream = packet->data + packet->offset;
|
||||||
uint16_t handle;
|
uint16_t handle;
|
||||||
uint16_t l2cap_length;
|
uint16_t l2cap_length;
|
||||||
uint16_t acl_length;
|
uint16_t acl_length;
|
||||||
uint8_t boundary_flag;
|
|
||||||
BT_HDR *partial_packet;
|
|
||||||
|
|
||||||
STREAM_TO_UINT16(handle, stream);
|
STREAM_TO_UINT16(handle, stream);
|
||||||
STREAM_TO_UINT16(acl_length, stream);
|
STREAM_TO_UINT16(acl_length, stream);
|
||||||
|
@ -139,23 +139,22 @@ static void reassemble_and_dispatch(BT_HDR *packet)
|
||||||
|
|
||||||
assert(acl_length == packet->len - HCI_ACL_PREAMBLE_SIZE);
|
assert(acl_length == packet->len - HCI_ACL_PREAMBLE_SIZE);
|
||||||
|
|
||||||
boundary_flag = GET_BOUNDARY_FLAG(handle);
|
uint8_t boundary_flag = GET_BOUNDARY_FLAG(handle);
|
||||||
handle = handle & HANDLE_MASK;
|
handle = handle & HANDLE_MASK;
|
||||||
|
|
||||||
partial_packet = (BT_HDR *)hash_map_get(partial_packets, (void *)(uintptr_t)handle);
|
BT_HDR *partial_packet = (BT_HDR *)hash_map_get(partial_packets, (void *)(uintptr_t)handle);
|
||||||
|
|
||||||
if (boundary_flag == START_PACKET_BOUNDARY) {
|
if (boundary_flag == START_PACKET_BOUNDARY) {
|
||||||
uint16_t full_length;
|
|
||||||
if (partial_packet) {
|
if (partial_packet) {
|
||||||
LOG_WARN("%s found unfinished packet for handle with start packet. Dropping old.", __func__);
|
LOG_WARN("%s found unfinished packet for handle with start packet. Dropping old.\n", __func__);
|
||||||
hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
|
hash_map_erase(partial_packets, (void *)(uintptr_t)handle);
|
||||||
buffer_allocator->free(partial_packet);
|
buffer_allocator->free(partial_packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
|
uint16_t full_length = l2cap_length + L2CAP_HEADER_SIZE + HCI_ACL_PREAMBLE_SIZE;
|
||||||
if (full_length <= packet->len) {
|
if (full_length <= packet->len) {
|
||||||
if (full_length < packet->len) {
|
if (full_length < packet->len) {
|
||||||
LOG_WARN("%s found l2cap full length %d less than the hci length %d.", __func__, l2cap_length, packet->len);
|
LOG_WARN("%s found l2cap full length %d less than the hci length %d.\n", __func__, l2cap_length, packet->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
callbacks->reassembled(packet);
|
callbacks->reassembled(packet);
|
||||||
|
@ -178,19 +177,17 @@ static void reassemble_and_dispatch(BT_HDR *packet)
|
||||||
// Free the old packet buffer, since we don't need it anymore
|
// Free the old packet buffer, since we don't need it anymore
|
||||||
buffer_allocator->free(packet);
|
buffer_allocator->free(packet);
|
||||||
} else {
|
} else {
|
||||||
uint16_t projected_offset;
|
|
||||||
if (!partial_packet) {
|
if (!partial_packet) {
|
||||||
LOG_WARN("%s got continuation for unknown packet. Dropping it.", __func__);
|
LOG_ERROR("%s got continuation for unknown packet. Dropping it.\n", __func__);
|
||||||
buffer_allocator->free(packet);
|
buffer_allocator->free(packet);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
packet->offset += HCI_ACL_PREAMBLE_SIZE; // skip ACL preamble
|
packet->offset += HCI_ACL_PREAMBLE_SIZE; // skip ACL preamble
|
||||||
packet->len -= HCI_ACL_PREAMBLE_SIZE;
|
packet->len -= HCI_ACL_PREAMBLE_SIZE;
|
||||||
|
uint16_t projected_offset = partial_packet->offset + packet->len;
|
||||||
projected_offset = partial_packet->offset + packet->len;
|
|
||||||
if (projected_offset > partial_packet->len) { // len stores the expected length
|
if (projected_offset > partial_packet->len) { // len stores the expected length
|
||||||
LOG_WARN("%s got packet which would exceed expected length of %d. Truncating.", __func__, partial_packet->len);
|
LOG_ERROR("%s got packet which would exceed expected length of %d. Truncating.\n", __func__, partial_packet->len);
|
||||||
packet->len = partial_packet->len - partial_packet->offset;
|
packet->len = partial_packet->len - partial_packet->offset;
|
||||||
projected_offset = partial_packet->len;
|
projected_offset = partial_packet->len;
|
||||||
}
|
}
|
||||||
|
@ -200,6 +197,7 @@ static void reassemble_and_dispatch(BT_HDR *packet)
|
||||||
packet->data + packet->offset,
|
packet->data + packet->offset,
|
||||||
packet->len
|
packet->len
|
||||||
);
|
);
|
||||||
|
|
||||||
// Free the old packet buffer, since we don't need it anymore
|
// Free the old packet buffer, since we don't need it anymore
|
||||||
buffer_allocator->free(packet);
|
buffer_allocator->free(packet);
|
||||||
partial_packet->offset = projected_offset;
|
partial_packet->offset = projected_offset;
|
||||||
|
|
Loading…
Reference in a new issue