BOOST_FIXTURE_TEST_CASE( should_find_the_device_name_characteristic, request_with_reponse< small_temperature_service > ) { l2cap_input( { 0x02, 0x68, 0x00 } ); expected_result( { 0x03, 0x17, 0x00 } ); l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x00, 0x2a } ); BOOST_REQUIRE( response_size > 0 ); BOOST_CHECK_EQUAL( response[ 0 ], 0x09 ); }
BOOST_FIXTURE_TEST_CASE( write_queue_used_by_other_client, large_fixture ) { connection_data con1( 23 ); connection_data con2( 23 ); l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 }, con1 ); expected_result( { 0x17, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 } ); l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 }, con2 ); expected_result( { 0x01, 0x16, 0x03, 0x00, 0x09 } ); }
BOOST_FIXTURE_TEST_CASE( prepare_3_writes, test::request_with_reponse< three_apes_server > ) { l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 } ); expected_result( { 0x17, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 } ); l2cap_input( { 0x16, 0x05, 0x00, 0x00, 0x00, 0x00, 0x02 } ); expected_result( { 0x17, 0x05, 0x00, 0x00, 0x00, 0x00, 0x02 } ); l2cap_input( { 0x16, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03 } ); expected_result( { 0x17, 0x07, 0x00, 0x00, 0x00, 0x00, 0x03 } ); }
BOOST_FIXTURE_TEST_CASE( queue_can_be_used_after_beeing_released, test::request_with_reponse< three_apes_server > ) { connection_data con1( 23 ); connection_data con2( 23 ); l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 }, con1 ); l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 }, con2 ); expected_result( { 0x01, 0x16, 0x03, 0x00, 0x09 } ); this->client_disconnected( con1 ); l2cap_input( { 0x16, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 }, con2 ); expected_result( { 0x17, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01 } ); }
static void hci_acl_received(u8* input, u16 isize) { u8 handle; u8 flags; hci_dumphex("ACLI", input, isize); /* acl format bits 0-11 handle bits 12-13 pb flag bits 14-15 bc flag bits 16-31 input total length */ handle = bt_read_u16(input) & 0xFFF; flags = input[1] >> 4; //acl_len = bt_read_u16(input +2); if ((hci.le.hconn != handle) #if !DISABLE_BT_CLASSICAL && (hci.edr.hconn != handle) #endif ) return; if (l2cap_input(input + 4, isize - 4, flags)) { hci_write_later(BT_ACL_OUT_CHANNEL); } }
BOOST_FIXTURE_TEST_CASE( read_multiple_attributes, request_with_reponse_three_apes_service_100 ) { l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x03, 0x28 } ); static const std::uint8_t expected_result[] = { 0x09, 0x15, // response code, size = 2 for handle and 19 for attribute value (Properties, Value Handle + UUID) 0x02, 0x00, // attribute handle 0x0A, // Characteristic Properties (read + write) 0x03, 0x00, // Characteristic Value Handle 0xAA, 0x3C, 0xC7, 0x5B, // Characteristic UUID 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C, 0x04, 0x00, // attribute handle 0x0A, // Characteristic Properties (read + write) 0x05, 0x00, // Characteristic Value Handle 0xAB, 0x3C, 0xC7, 0x5B, // Characteristic UUID 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C, 0x06, 0x00, // attribute handle 0x0A, // Characteristic Properties (read + write) 0x07, 0x00, // Characteristic Value Handle 0xAC, 0x3C, 0xC7, 0x5B, // Characteristic UUID 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( do_i_have_to_wear_a_jacket_today, test::small_temperature_service_with_response<> ) { l2cap_input( { 0x0A, 0x03, 0x00 } ); static const std::uint8_t expected_result[] = { 0x0B, 0x04, 0x01 }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( configured_appearance_is_used, test::request_with_reponse< location_and_navigation_display_device_server > ) { // Read by Type Request, 0x0001, 0xffff, 0x2A01 l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x01, 0x2A } ); expected_result( { 0x09, 0x04, 0x08, 0x00, 0x42, 0x14 } ); }
BOOST_FIXTURE_TEST_CASE( appearance_is_mandatory, test::request_with_reponse< nupsy_service > ) { // Read by Type Request, 0x0001, 0xffff, 0x2A01 l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x01, 0x2A } ); expected_result( { 0x09, 0x04, 0x08, 0x00, 0x00, 0x00 } ); }
// service is discoverable and contains at least two characteristics BOOST_FIXTURE_TEST_CASE( service_is_discoverable_by_default, test::request_with_reponse< nupsy_service > ) { // Find By Type Value Request, 1, 0xffff, <<primary service>>, <<gap service>> l2cap_input( { 0x06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0x00, 0x18 } ); expected_result( { 0x07, 0x04, 0x00, 0x08, 0x00 } ); }
BOOST_FIXTURE_TEST_CASE( device_name_is_mandatory, test::request_with_reponse< nupsy_service > ) { // Read by Type Request, 0x0001, 0xffff, 0x2A00 l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x00, 0x2A } ); expected_result( { 0x09, 0x0e, 0x06, 0x00, // length + handle // "Nupsy-Server" 'N', 'u', 'p', 's', 'y', '-', 'S', 'e', 'r', 'v', 'e', 'r' } ); }
BOOST_FIXTURE_TEST_CASE( default_name, test::request_with_reponse< no_name_service > ) { // Read by Type Request, 0x0001, 0xffff, 0x2A00 l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x00, 0x2A } ); expected_result( { 0x09, 0x10, 0x06, 0x00, // length + handle // "Bluetoe-Server" 'B', 'l', 'u', 'e', 't', 'o', 'e', '-', 'S', 'e', 'r', 'v', 'e', 'r' } ); }
BOOST_FIXTURE_TEST_CASE( read_16bit_uuid_in_gap, request_with_reponse< server_with_16bit_characteristics_in_the_middle > ) { l2cap_input( { 0x10, 0x04, 0x00, 0xff, 0xff, 0x00, 0x28 } ); static const std::uint8_t expected_result[] = { 0x11, 0x06, // response code, size 0x04, 0x00, 0x08, 0x00, // handle 0x0001 - 0x0003 0x16, 0x18 // service_uuid cycling_speed_and_cadence_service }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( read_first_part_of_blob, test::request_with_reponse< blob_server > ) { l2cap_input( { 0x0A, 0x03, 0x00 } ); static const std::uint8_t expected_result[] = { 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( output_to_small_for_more_than_one_service, request_with_reponse_server_with_3_characteristics_41 ) { l2cap_input( { 0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28 } ); static const std::uint8_t expected_result[] = { 0x11, 0x14, // response code, size 0x01, 0x00, 0x03, 0x00, // handle 0x0001 - 0x0003 0x2A, 0xD9, 0x91, 0x11, // service_uuid global_temperature_service 0xAB, 0x5B, 0x58, 0xB0, 0x3B, 0x4F, 0x50, 0x44, 0x52, 0x6E, 0x42, 0xF0 }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( single_service, small_temperature_service_with_response<> ) { l2cap_input( { 0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28 } ); static const std::uint8_t expected_result[] = { 0x11, 0x14, // response code, size 0x01, 0x00, 0x03, 0x00, // 0x0001 - 0x0003 0xA9, 0x3C, 0xC7, 0x5B, // 128 bit UUID 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( output_to_small_to_read_all_services, request_with_reponse< server_with_4_bicycles > ) { l2cap_input( { 0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28 } ); static const std::uint8_t expected_result[] = { 0x11, 0x06, // response code, size 0x01, 0x00, 0x05, 0x00, 0x16, 0x18, 0x06, 0x00, 0x0A, 0x00, 0x16, 0x18, 0x0B, 0x00, 0x0F, 0x00, 0x16, 0x18 }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( read_a_single_attribute, small_temperature_service_with_response<> ) { l2cap_input( { 0x08, 0x01, 0x00, 0xff, 0xff, 0x03, 0x28 } ); static const std::uint8_t expected_result[] = { 0x09, 0x15, // response code, size = 2 for handle and 19 for attribute value (Properties, Value Handle + UUID) 0x02, 0x00, // attribute handle 0x02, // Characteristic Properties (read) 0x03, 0x00, // Characteristic Value Handle 0xAA, 0x3C, 0xC7, 0x5B, // Characteristic UUID 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }
BOOST_FIXTURE_TEST_CASE( different_attribute_data_size, request_with_reponse_server_with_3_characteristics_100 ) { l2cap_input( { 0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28 } ); static const std::uint8_t expected_result[] = { 0x11, 0x14, // response code, size 0x01, 0x00, 0x03, 0x00, // handle 0x0001 - 0x0003 0x2A, 0xD9, 0x91, 0x11, // service_uuid global_temperature_service 0xAB, 0x5B, 0x58, 0xB0, 0x3B, 0x4F, 0x50, 0x44, 0x52, 0x6E, 0x42, 0xF0, 0x04, 0x00, 0x0A, 0x00, // handle 0x0004 - 0x000A 0xA9, 0x3C, 0xC7, 0x5B, 0xED, 0x4E, 0x8A, 0xA2, 0x9F, 0x49, 0xE2, 0x0D, 0x94, 0x40, 0x8B, 0x8C }; BOOST_CHECK_EQUAL_COLLECTIONS( &response[ 0 ], &response[ response_size ], std::begin( expected_result ), std::end( expected_result ) ); }