hci.c (0ca847af67112a6b02c33ad5237a43dbcf2e6fdd) hci.c (23a77e1a6f85bdec52c8169960e87d6f16dbd58c)
1/*
2 * Copyright (C) 2009-2012 by Matthias Ringwald
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 584 unchanged lines hidden (view full) ---

593 // reset recombination buffer
594 conn->acl_recombination_length = 0;
595 conn->acl_recombination_pos = 0;
596 }
597 break;
598
599 case 0x02: { // first fragment
600
1/*
2 * Copyright (C) 2009-2012 by Matthias Ringwald
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 584 unchanged lines hidden (view full) ---

593 // reset recombination buffer
594 conn->acl_recombination_length = 0;
595 conn->acl_recombination_pos = 0;
596 }
597 break;
598
599 case 0x02: { // first fragment
600
601 // sanity check
602 if (conn->acl_recombination_pos) {
603 log_error( "ACL First Fragment but data in buffer for handle 0x%02x, dropping stale fragments", con_handle);
604 conn->acl_recombination_pos = 0;
605 }
606
601 // peek into L2CAP packet!
602 uint16_t l2cap_length = READ_L2CAP_LENGTH( packet );
603
604 // log_info( "ACL First Fragment: acl_len %u, l2cap_len %u", acl_length, l2cap_length);
605
606 // compare fragment size to L2CAP packet size
607 if (acl_length >= l2cap_length + 4){
608
609 // forward fragment as L2CAP packet
610 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, acl_length + 4);
611
612 } else {
613
607 // peek into L2CAP packet!
608 uint16_t l2cap_length = READ_L2CAP_LENGTH( packet );
609
610 // log_info( "ACL First Fragment: acl_len %u, l2cap_len %u", acl_length, l2cap_length);
611
612 // compare fragment size to L2CAP packet size
613 if (acl_length >= l2cap_length + 4){
614
615 // forward fragment as L2CAP packet
616 hci_stack->packet_handler(HCI_ACL_DATA_PACKET, packet, acl_length + 4);
617
618 } else {
619
614 // sanity check
615 if (conn->acl_recombination_pos) {
616 log_error( "ACL First Fragment but data in buffer for handle 0x%02x", con_handle);
617 return;
618 }
619 if (acl_length > HCI_ACL_BUFFER_SIZE){
620 log_error( "ACL First Fragment to large: fragment %u > buffer size %u for handle 0x%02x",
621 4 + acl_length, 4 + HCI_ACL_BUFFER_SIZE, con_handle);
622 return;
623 }
624
625 // store first fragment and tweak acl length for complete package
626 memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], packet, acl_length + 4);

--- 2053 unchanged lines hidden ---
620 if (acl_length > HCI_ACL_BUFFER_SIZE){
621 log_error( "ACL First Fragment to large: fragment %u > buffer size %u for handle 0x%02x",
622 4 + acl_length, 4 + HCI_ACL_BUFFER_SIZE, con_handle);
623 return;
624 }
625
626 // store first fragment and tweak acl length for complete package
627 memcpy(&conn->acl_recombination_buffer[HCI_INCOMING_PRE_BUFFER_SIZE], packet, acl_length + 4);

--- 2053 unchanged lines hidden ---