Loading system/hci/Android.bp +0 −11 Original line number Diff line number Diff line Loading @@ -15,9 +15,6 @@ cc_library_static { "src/buffer_allocator.cc", "src/packet_fragmenter.cc", ], generated_headers: [ "BluetoothGeneratedDumpsysDataSchema_h", ], local_include_dirs: [ "include", ], Loading Loading @@ -54,24 +51,17 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/osi/test", "packages/modules/Bluetooth/system/stack/include", "system/libhwbinder/include", ], srcs: [ "test/packet_fragmenter_test.cc", ], shared_libs: [ "android.hardware.bluetooth.audio@2.0", "android.hardware.bluetooth.audio@2.1", "libbase", "libdl", "liblog", ], static_libs: [ "libbluetooth-for-tests", "libbluetooth-types", "libbt-hci", "libbtcore", "libchrome", "libosi", ], Loading @@ -80,5 +70,4 @@ cc_test { cfi: true, misc_undefined: ["bounds"], }, cflags: ["-Wno-unused-parameter"], } system/hci/include/hci_layer.h +1 −3 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ #include <base/functional/callback.h> #include <base/location.h> #include "osi/include/future.h" #include "osi/include/osi.h" // INVALID_FD #include "stack/include/bt_hdr.h" #include "stack/include/bt_types.h" Loading Loading @@ -63,7 +61,7 @@ typedef struct hci_t { command_status_cb status_cb, void* context); // Send some data downward through the HCI layer void (*transmit_downward)(uint16_t type, void* data); void (*transmit_downward)(void* data, uint16_t iso_buffer_size); } hci_t; const hci_t* hci_layer_get_interface(); Loading system/hci/include/packet_fragmenter.h +1 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ #pragma once #include "device/include/controller.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" Loading @@ -43,7 +42,7 @@ typedef struct packet_fragmenter_t { // Fragments |packet| if necessary and hands off everything to the fragmented // callback. void (*fragment_and_dispatch)(BT_HDR* packet); void (*fragment_and_dispatch)(BT_HDR* packet, uint16_t iso_buffer_size); // If |packet| is a complete packet, forwards to the reassembled callback. // Otherwise holds onto it until all fragments arrive, at which point the // reassembled callback is called with the reassembled data. Loading @@ -51,7 +50,3 @@ typedef struct packet_fragmenter_t { } packet_fragmenter_t; const packet_fragmenter_t* packet_fragmenter_get_interface(); const packet_fragmenter_t* packet_fragmenter_get_test_interface( const controller_t* controller_interface, const allocator_t* buffer_allocator_interface); system/hci/src/packet_fragmenter.cc +2 −14 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ #include <unordered_map> #include "device/include/controller.h" #include "hci/include/buffer_allocator.h" #include "hci/include/hci_layer.h" #include "internal_include/bt_target.h" Loading Loading @@ -78,7 +77,6 @@ // Our interface and callbacks static const allocator_t* buffer_allocator; static const controller_t* controller; static const packet_fragmenter_callbacks_t* callbacks; static std::unordered_map<uint16_t /* handle */, BT_HDR*> partial_iso_packets; Loading @@ -89,7 +87,7 @@ static void init(const packet_fragmenter_callbacks_t* result_callbacks) { static void cleanup() { partial_iso_packets.clear(); } static void fragment_and_dispatch(BT_HDR* packet) { static void fragment_and_dispatch(BT_HDR* packet, uint16_t max_data_size) { CHECK(packet != NULL); uint16_t event = packet->event & MSG_EVT_MASK; Loading @@ -97,7 +95,6 @@ static void fragment_and_dispatch(BT_HDR* packet) { CHECK(event == MSG_STACK_TO_HC_HCI_ISO); uint8_t* stream = packet->data + packet->offset; uint16_t max_data_size = controller->get_iso_data_size(); uint16_t max_packet_size = max_data_size + HCI_ISO_PREAMBLE_SIZE; uint16_t remaining_length = packet->len; Loading Loading @@ -141,7 +138,7 @@ static void fragment_and_dispatch(BT_HDR* packet) { callbacks->fragmented(packet, true); } static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR* packet) { static void reassemble_and_dispatch(BT_HDR* packet) { uint8_t* stream = packet->data; uint16_t handle; uint16_t iso_length; Loading Loading @@ -331,15 +328,6 @@ static const packet_fragmenter_t interface = {init, cleanup, reassemble_and_dispatch}; const packet_fragmenter_t* packet_fragmenter_get_interface() { controller = controller_get_interface(); buffer_allocator = buffer_allocator_get_interface(); return &interface; } const packet_fragmenter_t* packet_fragmenter_get_test_interface( const controller_t* controller_interface, const allocator_t* buffer_allocator_interface) { controller = controller_interface; buffer_allocator = buffer_allocator_interface; return &interface; } system/hci/test/packet_fragmenter_test.cc +7 −62 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ #include <gtest/gtest.h> #include <stdint.h> #include "device/include/controller.h" #include "hci/include/hci_layer.h" #include "internal_include/bt_target.h" #include "osi/include/allocator.h" Loading @@ -33,11 +32,8 @@ #define HCI_ISO_PREAMBLE_SIZE 4 #endif DECLARE_TEST_MODES(init, set_data_sizes, no_fragmentation, fragmentation, ble_no_fragmentation, ble_fragmentation, non_acl_passthrough_fragmentation, no_reassembly, reassembly, non_acl_passthrough_reassembly, iso_no_reassembly, iso_reassembly, iso_fragmentation, iso_no_fragmentation); DECLARE_TEST_MODES(init, iso_no_reassembly, iso_reassembly, iso_fragmentation, iso_no_fragmentation); #define LOCAL_BLE_CONTROLLER_ID 1 Loading Loading @@ -284,19 +280,6 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, } } static void expect_packet_reassembled(uint16_t event, BT_HDR* packet, const char* expected_data) { uint16_t expected_data_length = strlen(expected_data); uint8_t* data = packet->data + packet->offset; for (int i = 0; i < expected_data_length; i++) { EXPECT_EQ(expected_data[i], data[i]); data_size_sum++; } osi_free(packet); } static void expect_packet_reassembled_iso(uint16_t event, BT_HDR* packet, const char* expected_data, uint32_t expected_timestamp, Loading Loading @@ -359,12 +342,6 @@ DURING(iso_no_fragmentation) { return; } DURING(non_acl_passthrough_fragmentation) AT_CALL(0) { expect_packet_fragmented(MSG_STACK_TO_HC_HCI_CMD, 10, packet, sample_data, send_complete); return; } UNEXPECTED_CALL; } Loading @@ -382,30 +359,7 @@ DURING(iso_no_reassembly) AT_CALL(0) { return; } DURING(non_acl_passthrough_reassembly) AT_CALL(0) { expect_packet_reassembled(MSG_HC_TO_STACK_HCI_EVT, packet, sample_data); return; } UNEXPECTED_CALL; } STUB_FUNCTION(uint16_t, get_acl_data_size_classic, (void)) DURING(no_fragmentation, non_acl_passthrough_fragmentation, no_reassembly) return 42; DURING(fragmentation) return 10; DURING(no_reassembly) return 1337; UNEXPECTED_CALL; return 0; } STUB_FUNCTION(uint16_t, get_acl_data_size_ble, (void)) DURING(ble_no_fragmentation) return 42; DURING(ble_fragmentation) return 10; UNEXPECTED_CALL; return 0; } STUB_FUNCTION(uint16_t, get_iso_data_size, (void)) Loading @@ -419,34 +373,25 @@ return 0; static void reset_for(TEST_MODES_T next) { RESET_CALL_COUNT(fragmented_callback); RESET_CALL_COUNT(reassembled_callback); RESET_CALL_COUNT(get_acl_data_size_classic); RESET_CALL_COUNT(get_acl_data_size_ble); RESET_CALL_COUNT(get_iso_data_size); CURRENT_TEST_MODE = next; } class PacketFragmenterTest : public ::testing::Test { protected: void SetUp() override { fragmenter = packet_fragmenter_get_test_interface(&controller, &allocator_malloc); fragmenter = packet_fragmenter_get_interface(); packet_index = 0; data_size_sum = 0; callbacks.fragmented = fragmented_callback; callbacks.reassembled = reassembled_callback; controller.get_acl_data_size_classic = get_acl_data_size_classic; controller.get_acl_data_size_ble = get_acl_data_size_ble; controller.get_iso_data_size = get_iso_data_size; reset_for(init); fragmenter->init(&callbacks); } void TearDown() override { fragmenter->cleanup(); } controller_t controller; packet_fragmenter_callbacks_t callbacks; }; Loading @@ -457,7 +402,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(sample_data), data_size_sum); } Loading @@ -469,7 +414,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, small_sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(small_sample_data), data_size_sum); } Loading @@ -480,7 +425,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary_no_ts) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(sample_data), data_size_sum); } Loading @@ -491,7 +436,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary_no_ts) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, small_sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(small_sample_data), data_size_sum); } Loading Loading
system/hci/Android.bp +0 −11 Original line number Diff line number Diff line Loading @@ -15,9 +15,6 @@ cc_library_static { "src/buffer_allocator.cc", "src/packet_fragmenter.cc", ], generated_headers: [ "BluetoothGeneratedDumpsysDataSchema_h", ], local_include_dirs: [ "include", ], Loading Loading @@ -54,24 +51,17 @@ cc_test { "packages/modules/Bluetooth/system/gd", "packages/modules/Bluetooth/system/include", "packages/modules/Bluetooth/system/osi/test", "packages/modules/Bluetooth/system/stack/include", "system/libhwbinder/include", ], srcs: [ "test/packet_fragmenter_test.cc", ], shared_libs: [ "android.hardware.bluetooth.audio@2.0", "android.hardware.bluetooth.audio@2.1", "libbase", "libdl", "liblog", ], static_libs: [ "libbluetooth-for-tests", "libbluetooth-types", "libbt-hci", "libbtcore", "libchrome", "libosi", ], Loading @@ -80,5 +70,4 @@ cc_test { cfi: true, misc_undefined: ["bounds"], }, cflags: ["-Wno-unused-parameter"], }
system/hci/include/hci_layer.h +1 −3 Original line number Diff line number Diff line Loading @@ -21,8 +21,6 @@ #include <base/functional/callback.h> #include <base/location.h> #include "osi/include/future.h" #include "osi/include/osi.h" // INVALID_FD #include "stack/include/bt_hdr.h" #include "stack/include/bt_types.h" Loading Loading @@ -63,7 +61,7 @@ typedef struct hci_t { command_status_cb status_cb, void* context); // Send some data downward through the HCI layer void (*transmit_downward)(uint16_t type, void* data); void (*transmit_downward)(void* data, uint16_t iso_buffer_size); } hci_t; const hci_t* hci_layer_get_interface(); Loading
system/hci/include/packet_fragmenter.h +1 −6 Original line number Diff line number Diff line Loading @@ -18,7 +18,6 @@ #pragma once #include "device/include/controller.h" #include "osi/include/allocator.h" #include "stack/include/bt_hdr.h" Loading @@ -43,7 +42,7 @@ typedef struct packet_fragmenter_t { // Fragments |packet| if necessary and hands off everything to the fragmented // callback. void (*fragment_and_dispatch)(BT_HDR* packet); void (*fragment_and_dispatch)(BT_HDR* packet, uint16_t iso_buffer_size); // If |packet| is a complete packet, forwards to the reassembled callback. // Otherwise holds onto it until all fragments arrive, at which point the // reassembled callback is called with the reassembled data. Loading @@ -51,7 +50,3 @@ typedef struct packet_fragmenter_t { } packet_fragmenter_t; const packet_fragmenter_t* packet_fragmenter_get_interface(); const packet_fragmenter_t* packet_fragmenter_get_test_interface( const controller_t* controller_interface, const allocator_t* buffer_allocator_interface);
system/hci/src/packet_fragmenter.cc +2 −14 Original line number Diff line number Diff line Loading @@ -25,7 +25,6 @@ #include <unordered_map> #include "device/include/controller.h" #include "hci/include/buffer_allocator.h" #include "hci/include/hci_layer.h" #include "internal_include/bt_target.h" Loading Loading @@ -78,7 +77,6 @@ // Our interface and callbacks static const allocator_t* buffer_allocator; static const controller_t* controller; static const packet_fragmenter_callbacks_t* callbacks; static std::unordered_map<uint16_t /* handle */, BT_HDR*> partial_iso_packets; Loading @@ -89,7 +87,7 @@ static void init(const packet_fragmenter_callbacks_t* result_callbacks) { static void cleanup() { partial_iso_packets.clear(); } static void fragment_and_dispatch(BT_HDR* packet) { static void fragment_and_dispatch(BT_HDR* packet, uint16_t max_data_size) { CHECK(packet != NULL); uint16_t event = packet->event & MSG_EVT_MASK; Loading @@ -97,7 +95,6 @@ static void fragment_and_dispatch(BT_HDR* packet) { CHECK(event == MSG_STACK_TO_HC_HCI_ISO); uint8_t* stream = packet->data + packet->offset; uint16_t max_data_size = controller->get_iso_data_size(); uint16_t max_packet_size = max_data_size + HCI_ISO_PREAMBLE_SIZE; uint16_t remaining_length = packet->len; Loading Loading @@ -141,7 +138,7 @@ static void fragment_and_dispatch(BT_HDR* packet) { callbacks->fragmented(packet, true); } static void reassemble_and_dispatch(UNUSED_ATTR BT_HDR* packet) { static void reassemble_and_dispatch(BT_HDR* packet) { uint8_t* stream = packet->data; uint16_t handle; uint16_t iso_length; Loading Loading @@ -331,15 +328,6 @@ static const packet_fragmenter_t interface = {init, cleanup, reassemble_and_dispatch}; const packet_fragmenter_t* packet_fragmenter_get_interface() { controller = controller_get_interface(); buffer_allocator = buffer_allocator_get_interface(); return &interface; } const packet_fragmenter_t* packet_fragmenter_get_test_interface( const controller_t* controller_interface, const allocator_t* buffer_allocator_interface) { controller = controller_interface; buffer_allocator = buffer_allocator_interface; return &interface; }
system/hci/test/packet_fragmenter_test.cc +7 −62 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ #include <gtest/gtest.h> #include <stdint.h> #include "device/include/controller.h" #include "hci/include/hci_layer.h" #include "internal_include/bt_target.h" #include "osi/include/allocator.h" Loading @@ -33,11 +32,8 @@ #define HCI_ISO_PREAMBLE_SIZE 4 #endif DECLARE_TEST_MODES(init, set_data_sizes, no_fragmentation, fragmentation, ble_no_fragmentation, ble_fragmentation, non_acl_passthrough_fragmentation, no_reassembly, reassembly, non_acl_passthrough_reassembly, iso_no_reassembly, iso_reassembly, iso_fragmentation, iso_no_fragmentation); DECLARE_TEST_MODES(init, iso_no_reassembly, iso_reassembly, iso_fragmentation, iso_no_fragmentation); #define LOCAL_BLE_CONTROLLER_ID 1 Loading Loading @@ -284,19 +280,6 @@ static void manufacture_packet_and_then_reassemble(uint16_t event, } } static void expect_packet_reassembled(uint16_t event, BT_HDR* packet, const char* expected_data) { uint16_t expected_data_length = strlen(expected_data); uint8_t* data = packet->data + packet->offset; for (int i = 0; i < expected_data_length; i++) { EXPECT_EQ(expected_data[i], data[i]); data_size_sum++; } osi_free(packet); } static void expect_packet_reassembled_iso(uint16_t event, BT_HDR* packet, const char* expected_data, uint32_t expected_timestamp, Loading Loading @@ -359,12 +342,6 @@ DURING(iso_no_fragmentation) { return; } DURING(non_acl_passthrough_fragmentation) AT_CALL(0) { expect_packet_fragmented(MSG_STACK_TO_HC_HCI_CMD, 10, packet, sample_data, send_complete); return; } UNEXPECTED_CALL; } Loading @@ -382,30 +359,7 @@ DURING(iso_no_reassembly) AT_CALL(0) { return; } DURING(non_acl_passthrough_reassembly) AT_CALL(0) { expect_packet_reassembled(MSG_HC_TO_STACK_HCI_EVT, packet, sample_data); return; } UNEXPECTED_CALL; } STUB_FUNCTION(uint16_t, get_acl_data_size_classic, (void)) DURING(no_fragmentation, non_acl_passthrough_fragmentation, no_reassembly) return 42; DURING(fragmentation) return 10; DURING(no_reassembly) return 1337; UNEXPECTED_CALL; return 0; } STUB_FUNCTION(uint16_t, get_acl_data_size_ble, (void)) DURING(ble_no_fragmentation) return 42; DURING(ble_fragmentation) return 10; UNEXPECTED_CALL; return 0; } STUB_FUNCTION(uint16_t, get_iso_data_size, (void)) Loading @@ -419,34 +373,25 @@ return 0; static void reset_for(TEST_MODES_T next) { RESET_CALL_COUNT(fragmented_callback); RESET_CALL_COUNT(reassembled_callback); RESET_CALL_COUNT(get_acl_data_size_classic); RESET_CALL_COUNT(get_acl_data_size_ble); RESET_CALL_COUNT(get_iso_data_size); CURRENT_TEST_MODE = next; } class PacketFragmenterTest : public ::testing::Test { protected: void SetUp() override { fragmenter = packet_fragmenter_get_test_interface(&controller, &allocator_malloc); fragmenter = packet_fragmenter_get_interface(); packet_index = 0; data_size_sum = 0; callbacks.fragmented = fragmented_callback; callbacks.reassembled = reassembled_callback; controller.get_acl_data_size_classic = get_acl_data_size_classic; controller.get_acl_data_size_ble = get_acl_data_size_ble; controller.get_iso_data_size = get_iso_data_size; reset_for(init); fragmenter->init(&callbacks); } void TearDown() override { fragmenter->cleanup(); } controller_t controller; packet_fragmenter_callbacks_t callbacks; }; Loading @@ -457,7 +402,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(sample_data), data_size_sum); } Loading @@ -469,7 +414,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, small_sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(small_sample_data), data_size_sum); } Loading @@ -480,7 +425,7 @@ TEST_F(PacketFragmenterTest, test_iso_fragment_necessary_no_ts) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(sample_data), data_size_sum); } Loading @@ -491,7 +436,7 @@ TEST_F(PacketFragmenterTest, test_iso_no_fragment_necessary_no_ts) { BT_HDR* packet = manufacture_packet_for_fragmentation(MSG_STACK_TO_HC_HCI_ISO, small_sample_data); packet->event |= LOCAL_BLE_CONTROLLER_ID; fragmenter->fragment_and_dispatch(packet); fragmenter->fragment_and_dispatch(packet, get_iso_data_size()); ASSERT_EQ(strlen(small_sample_data), data_size_sum); } Loading