1# Lint as: python3 2# Copyright 2022 The Chromium OS Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import logging 7from autotest_lib.client.bin import test 8from autotest_lib.client.common_lib import error 9from autotest_lib.client.cros.bluetooth.hcitool import Hcitool 10from autotest_lib.client.common_lib.cros.bluetooth import chipinfo 11from autotest_lib.client.cros.multimedia import bluetooth_facade 12 13 14class bluetooth_AVLHCI(test.test): 15 """Test bluetooth avl HCI requirements.""" 16 version = 1 17 MIN_ACL_BUFFER_SIZE = 1021 18 ACL_DATA_PACKET_LENGTH_VALUE_INDEX = 1 19 MIN_ACL_PACKETS_NUMBER = 4 20 MIN_ACL_PACKETS_NUMBER_OPTIONAL = 6 21 TOTAL_NUM_ACL_DATA_PACKETS_VALUE_INDEX = 3 22 MIN_SCO_PACKETS_NUMBER = 6 23 TOTAL_NUM_SYNCHRONOUS_DATA_PACKETS_VALUE_INDEX = 4 24 NON_FLUSHABLE_PACKET_BOUNDARY_FEATURE = 'Non-flushable Packet Boundary Flag' 25 ERRONEOUS_DATA_REPORTING_FEATURE = 'Erroneous Data Reporting' 26 MAC_EVENT_FILTERS = [['1', '2', '00 17 C9 AA AA AA'], 27 ['1', '2', '00 17 9B AA AA AA'], 28 ['1', '2', '00 17 94 AA AA AA'], 29 ['1', '2', '00 17 95 AA AA AA'], 30 ['1', '2', '00 17 B0 AA AA AA'], 31 ['1', '2', '00 17 C0 AA AA AA'], 32 ['1', '2', '00 17 08 AA AA AA'], 33 ['1', '2', '00 16 EA AA AA AA']] 34 35 CONTROLLER_MEMORY_FULL_STATUS_VALUE = 7 36 CONTROLLER_SUCCESS_STATUS_VALUE = 0 37 SCO_BUFFER_SIZE_VALUE_INDEX = 2 38 MIN_SCO_BUFFER_SIZE = 60 39 LE_CONTROLLER_FEATURE = 'LE Supported (Controller)' 40 BR_EDR_NOT_SUPPORT_FEATURE = 'BR/EDR Not Supported' 41 LE_AND_BR_EDR_CONTROLLER_FEATURE = ( 42 'Simultaneous LE and BR/EDR to Same Device Capable (Controller)') 43 MIN_ACCEPT_LIST_SIZE_ENTRIES = 8 44 BR_SECURE_CONNECTION_FEATURE = 'Secure Connections (Controller Support)' 45 LE_DATA_PACKETS_LENGTH_EXTENSION_FEATURE = 'LE Data Packet Length Extension' 46 LE_LINK_LAYER_PRIVACY_FEATURE = 'LL Privacy' 47 MAX_PACKET_LENGTH = 251 48 MIN_RESOLVING_LIST_SIZE_ENTRIES = 8 49 LE_EXTENDED_ADVERTISING_FEATURE = 'LE Extended Advertising' 50 LE_TWO_MEGA_PHYSICAL_CHANNEL_FEATURE = 'LE 2M PHY' 51 MIN_ADVERTISEMENT_SETS_NUMBER = 10 52 LE_ISOCHRONOUS_CHANNELS_FEATURE = 'Isochronous Channels (Host Support)' 53 LE_POWER_CONTROL_REQUEST_FEATURE = 'LE Power Control Request' 54 LE_POWER_CHANGE_INDICATION_FEATURE = 'LE Power Change Indication' 55 GOOGLE_FEATURE_SPECIFICATION_VERSION = 98 56 LE_ADV_RSSI_MONITORING = 'RSSI Monitoring of LE advertisements' 57 LE_ADV_MONITORING = 'Advertising Monitoring of LE advertisements' 58 59 def initialize(self): 60 """Initializes Autotest.""" 61 self.hcitool = Hcitool() 62 self.facade = bluetooth_facade.BluezFacadeLocal() 63 64 def spec_legacy_test(self): 65 """Checks Bluetooth legacy specification.""" 66 logging.info('* Running Bluetooth spec_legacy_test:') 67 self.test_flushable_data_packets() 68 self.test_erroneous_data_reporting() 69 self.test_event_filter_size() 70 self.test_acl_min_buffer_number() 71 self.test_acl_min_buffer_number_optional() 72 self.test_acl_min_buffer_size() 73 self.test_sco_min_buffer_number() 74 self.test_sco_min_buffer_size() 75 76 def spec_4_0_test(self): 77 """Checks Bluetooth version 4.0 specification.""" 78 logging.info('* Running Bluetooth spec_4_0_test:') 79 self.test_low_energy_feature() 80 self.test_accept_list_size() 81 82 def spec_4_1_test(self): 83 """Checks Bluetooth version 4.1 specification.""" 84 logging.info('* Running Bluetooth spec_4_1_test:') 85 self.test_le_dual_mode_topology_feature() 86 self.test_br_edr_controller_secure_connection_feature() 87 88 def spec_4_2_test(self): 89 """Checks Bluetooth version 4.2 specification.""" 90 logging.info('* Running Bluetooth spec_4_2_test:') 91 self.test_le_data_packet_length_extension_feature() 92 self.test_packet_data_length() 93 self.test_le_link_layer_privacy_feature() 94 self.test_resolving_list_size() 95 96 def spec_5_0_test(self): 97 """Check Bluetooth version 5.0 specification.""" 98 logging.info('* Running Bluetooth spec_5_0_test:') 99 self.test_le_extended_advertising_feature() 100 self.test_advertisement_sets_number() 101 self.test_le_two_mega_physical_channel_feature() 102 103 def spec_5_2_test(self): 104 """Checks Bluetooth version 5.0 specification.""" 105 logging.info('* Running Bluetooth spec_5_2_test:') 106 self.test_le_isochronous_channels_feature() 107 self.test_le_power_control_feature() 108 109 def hci_ext_msft_test(self): 110 """Checks Microsoft Bluetooth HCI command execution.""" 111 logging.info('* Running Bluetooth hci_ext_msft_test:') 112 self.test_hci_vs_msft_read_supported_features() 113 114 def hci_ext_aosp_test(self): 115 """Checks Android Bluetooth HCI command execution.""" 116 logging.info('* Running Bluetooth hci_ext_aosp_test:') 117 self.test_aosp_quality_report() 118 self.test_le_apcf() 119 self.test_le_batch_scan_and_events() 120 self.test_le_extended_set_scan_parameters() 121 self.test_le_get_controller_activity_energy_info() 122 self.test_get_controller_debug_info_sub_event() 123 124 def assert_not_support(self, feature, supported_features): 125 """Verifies that the feature is not supported. 126 127 @param feature: The feature which should be unsupported. 128 @param supported_features: List of supported features. 129 130 @raise error.TestFail: If the feature is supported. 131 """ 132 if feature in supported_features: 133 raise error.TestFail(feature + ' should not be supported') 134 logging.info('%s is not supported as expected.', feature) 135 136 def assert_support(self, feature, supported_features): 137 """Verifies that the feature is supported. 138 139 @param feature: The feature which should be supported. 140 @param supported_features: List of supported features. 141 142 @raise error.TestFail: If the feature is unsupported. 143 """ 144 if feature not in supported_features: 145 raise error.TestFail(feature + ' should be supported') 146 logging.info('%s is supported.', feature) 147 148 def assert_equal(self, actual, expected, value_name): 149 """Verifies that actual value is equal to expected value. 150 151 @param actual: The value we got. 152 @param expected: The value we expected. 153 @param value_name: The name of the value. It is used for TestFail 154 message. 155 156 @raise error.TestFail: If the values are unequal. 157 """ 158 if actual != expected: 159 raise error.TestFail('%s: Got %s, expected %s' % 160 (value_name, actual, expected)) 161 logging.info('%s = %d, which is expected.' % (value_name, actual)) 162 163 def assert_greater_equal(self, value, threshold, value_name): 164 """Verifies that value is greater than or equal to threshold. 165 166 @param value: The value we got. 167 @param threshold: The threshold of the value. 168 @param value_name: The name of the value. It is used for TestFail 169 message. 170 171 @raise error.TestFail: If the value is less than threshold. 172 """ 173 if value < threshold: 174 raise error.TestFail('%s: %s is below the threshold %s' % 175 (value_name, value, threshold)) 176 logging.info('%s = %d, which is >= %d.' % 177 (value_name, value, threshold)) 178 179 def test_flushable_data_packets(self): 180 """Checks the Bluetooth controller must support flushable data packets. 181 182 Note: As long as the chips are verified by SIG, setting the 183 'Non-flushable Packet Boundary Flag' bit guarantees the related 184 functionalities. 185 """ 186 logging.info('** Running Bluetooth flushable data packets test:') 187 supported_features = self.hcitool.read_local_supported_features()[1] 188 self.assert_support(self.NON_FLUSHABLE_PACKET_BOUNDARY_FEATURE, 189 supported_features) 190 191 def test_erroneous_data_reporting(self): 192 """Checks the Bluetooth controller supports Erroneous Data Reporting.""" 193 logging.info('** Running Bluetooth erroneous data reporting test:') 194 supported_features = self.hcitool.read_local_supported_features()[1] 195 self.assert_support(self.ERRONEOUS_DATA_REPORTING_FEATURE, 196 supported_features) 197 198 def test_event_filter_size(self): 199 """Checks the Bluetooth controller event filter entries count. 200 201 Checks the Bluetooth controller event filter has at least 8 entries. 202 """ 203 logging.info('** Running Bluetooth event filter size test:') 204 number_of_added_filters = 0 205 for event_filter in self.MAC_EVENT_FILTERS: 206 set_filter_result = self.hcitool.set_event_filter( 207 event_filter[0], event_filter[1], event_filter[2])[0] 208 if set_filter_result == self.CONTROLLER_MEMORY_FULL_STATUS_VALUE: 209 self.facade.reset_on() 210 raise error.TestFail('Filter ' + ''.join(event_filter) + 211 ' failed to apply. Only ' + 212 str(number_of_added_filters) + 213 ' filters were added') 214 215 elif set_filter_result != self.CONTROLLER_SUCCESS_STATUS_VALUE: 216 self.facade.reset_on() 217 raise error.TestError( 218 'Failed to apply filter, status code is ' + 219 set_filter_result) 220 number_of_added_filters += 1 221 logging.info( 222 'All 8 event filters were set successfully with values %s', 223 self.MAC_EVENT_FILTERS) 224 # Reset filter after done with test 225 if not self.hcitool.set_event_filter('0', '0', '0'): 226 logging.error('Unable to clear filter, reset bluetooth') 227 self.facade.reset_on() 228 else: 229 logging.debug('Filter cleared') 230 231 def test_acl_min_buffer_number(self): 232 """Checks if ACL minimum buffers count(number of data packets) >=4.""" 233 logging.info('** Running Bluetooth acl min buffer number test:') 234 acl_buffers_count = self.hcitool.read_buffer_size()[ 235 self.TOTAL_NUM_ACL_DATA_PACKETS_VALUE_INDEX] 236 self.assert_greater_equal(acl_buffers_count, 237 self.MIN_ACL_PACKETS_NUMBER, 238 'ACL buffers count') 239 240 def test_acl_min_buffer_number_optional(self): 241 """Checks if ACL minimum buffers count(number of data packets) >=6.""" 242 logging.info( 243 '** Running Bluetooth acl min buffer number test (optional)":') 244 acl_buffers_count = self.hcitool.read_buffer_size()[ 245 self.TOTAL_NUM_ACL_DATA_PACKETS_VALUE_INDEX] 246 if acl_buffers_count < self.MIN_ACL_PACKETS_NUMBER_OPTIONAL: 247 raise error.TestWarn( 248 'ACL buffers count: %d is below the optional threshold %d' 249 % 250 (acl_buffers_count, self.MIN_ACL_PACKETS_NUMBER_OPTIONAL)) 251 logging.info('ACL buffers count = %d, which is >= %d.' % 252 (acl_buffers_count, self.MIN_ACL_PACKETS_NUMBER_OPTIONAL)) 253 254 def test_acl_min_buffer_size(self): 255 """Checks if ACL minimum buffers size >=1021.""" 256 logging.info('** Running Bluetooth acl min buffer size test:') 257 acl_buffer_size = self.hcitool.read_buffer_size()[ 258 self.ACL_DATA_PACKET_LENGTH_VALUE_INDEX] 259 self.assert_greater_equal(acl_buffer_size, self.MIN_ACL_BUFFER_SIZE, 260 'ACL buffer size') 261 262 def test_sco_min_buffer_number(self): 263 """Checks if SCO minimum buffer size(number of data packets) >=6.""" 264 logging.info('** Running Bluetooth sco min buffer number test:') 265 sco_buffers_count = self.hcitool.read_buffer_size()[ 266 self.TOTAL_NUM_SYNCHRONOUS_DATA_PACKETS_VALUE_INDEX] 267 self.assert_greater_equal(sco_buffers_count, 268 self.MIN_SCO_PACKETS_NUMBER, 269 'SCO buffers count') 270 271 def test_sco_min_buffer_size(self): 272 """Checks if SCO minimum buffer size >=60.""" 273 logging.info('** Running Bluetooth SCO min buffer size test:') 274 sco_buffer_size = self.hcitool.read_buffer_size()[ 275 self.SCO_BUFFER_SIZE_VALUE_INDEX] 276 self.assert_greater_equal(sco_buffer_size, self.MIN_SCO_BUFFER_SIZE, 277 'SCO buffer size') 278 279 def test_low_energy_feature(self): 280 """Checks if Bluetooth controller must use support 281 Bluetooth Low Energy (BLE).""" 282 logging.info( 283 '** Running support Bluetooth Low Energy (BLE) feature test:') 284 supported_features = self.hcitool.read_local_supported_features()[1] 285 self.assert_support(self.LE_CONTROLLER_FEATURE, supported_features) 286 287 def test_accept_list_size(self): 288 """Checks if accept list size >= 8 entries.""" 289 logging.info('** Running accept list size test:') 290 accept_list_entries_count = self.hcitool.le_read_accept_list_size()[1] 291 self.assert_greater_equal(accept_list_entries_count, 292 self.MIN_ACCEPT_LIST_SIZE_ENTRIES, 293 'Accept list size') 294 295 def test_le_dual_mode_topology_feature(self): 296 """Checks if Bluetooth controller supports LE dual mode topology.""" 297 logging.info('** Running LE dual mode topology feature test:') 298 supported_features = self.hcitool.read_local_supported_features()[1] 299 self.assert_not_support(self.BR_EDR_NOT_SUPPORT_FEATURE, 300 supported_features) 301 self.assert_support(self.LE_CONTROLLER_FEATURE, supported_features) 302 self.assert_support(self.LE_AND_BR_EDR_CONTROLLER_FEATURE, 303 supported_features) 304 305 def test_br_edr_controller_secure_connection_feature(self): 306 """Checks if Bluetooth controller supports BR/EDR secure connections.""" 307 logging.info('** Running BR/EDR controller secure connection feature ' 308 'test:') 309 supported_features = self.hcitool.read_local_extended_features(2)[3] 310 self.assert_support(self.BR_SECURE_CONNECTION_FEATURE, 311 supported_features) 312 313 def test_le_data_packet_length_extension_feature(self): 314 """Checks LE data packet length extension support.""" 315 logging.info('** Running LE data packet length extension test:') 316 supported_features = self.hcitool.read_le_local_supported_features()[1] 317 self.assert_support(self.LE_DATA_PACKETS_LENGTH_EXTENSION_FEATURE, 318 supported_features) 319 320 def test_packet_data_length(self): 321 """Checks if data packet length <= 251.""" 322 logging.info('** Running packet data length test:') 323 packet_data_length = self.hcitool.le_read_maximum_data_length()[1] 324 self.assert_equal(packet_data_length, self.MAX_PACKET_LENGTH, 325 'Packet data length') 326 327 def test_le_link_layer_privacy_feature(self): 328 """Checks if Bluetooth controller supports link layer privacy.""" 329 logging.info('** Running link layer privacy test:') 330 supported_features = self.hcitool.read_le_local_supported_features()[1] 331 self.assert_support(self.LE_LINK_LAYER_PRIVACY_FEATURE, 332 supported_features) 333 334 def test_resolving_list_size(self): 335 """Checks if resolving list size >= 8 entries.""" 336 logging.info('** Running resolving list size test:') 337 resolving_list_entries_count = self.hcitool.le_read_resolving_list_size( 338 )[1] 339 self.assert_greater_equal(resolving_list_entries_count, 340 self.MIN_RESOLVING_LIST_SIZE_ENTRIES, 341 'Resolving list size') 342 343 def test_le_extended_advertising_feature(self): 344 """Checks if Bluetooth controller supports LE advertising extension.""" 345 logging.info('** Running LE extended advertising feature test:') 346 supported_features = self.hcitool.read_le_local_supported_features()[1] 347 self.assert_support(self.LE_EXTENDED_ADVERTISING_FEATURE, 348 supported_features) 349 350 def test_advertisement_sets_number(self): 351 """Checks if number of advertisement sets >= 10.""" 352 logging.info('** Running advertisement sets number feature test:') 353 advertisement_sets_number = ( 354 self.hcitool.le_read_number_of_supported_advertising_sets()[1]) 355 self.assert_greater_equal(advertisement_sets_number, 356 self.MIN_ADVERTISEMENT_SETS_NUMBER, 357 'Advertisement sets number') 358 359 def test_le_two_mega_physical_channel_feature(self): 360 """Checks if Bluetooth controller supports 2 Msym/s PHY for LE.""" 361 logging.info('** Running LE two mega physical channel feature test:') 362 supported_features = self.hcitool.read_le_local_supported_features()[1] 363 self.assert_support(self.LE_TWO_MEGA_PHYSICAL_CHANNEL_FEATURE, 364 supported_features) 365 366 def test_le_isochronous_channels_feature(self): 367 """Checks if ISO channels feature is supported.""" 368 logging.info('** Running LE isochronous channels feature test:') 369 supported_features = self.hcitool.read_le_local_supported_features()[1] 370 self.assert_support(self.LE_ISOCHRONOUS_CHANNELS_FEATURE, 371 supported_features) 372 373 def test_le_power_control_feature(self): 374 """Checks if Bluetooth controller supports LE power control.""" 375 logging.info('** Running LE power control feature test:') 376 supported_features = self.hcitool.read_le_local_supported_features()[1] 377 self.assert_support(self.LE_POWER_CONTROL_REQUEST_FEATURE, 378 supported_features) 379 self.assert_support(self.LE_POWER_CHANGE_INDICATION_FEATURE, 380 supported_features) 381 382 def test_hci_vs_msft_read_supported_features(self): 383 """Checks if Bluetooth controller supports VS MSFT features.""" 384 logging.info('** Running hci VS MSFT read supported features:') 385 chipset_name = self.facade.get_chipset_name() 386 chip_info = chipinfo.query(chipset_name) 387 if not chip_info.msft_support: 388 raise error.TestNAError('Chipset ' + chipset_name + 389 ' does not support MSFT HCI extensions') 390 vs_msft_supported_features = ( 391 self.hcitool.vs_msft_read_supported_features( 392 chip_info.msft_ocf)[2]) 393 self.assert_support(self.LE_ADV_RSSI_MONITORING, 394 vs_msft_supported_features) 395 self.assert_support(self.LE_ADV_MONITORING, vs_msft_supported_features) 396 397 def assert_aosp_hci(self): 398 """Checks if a chipset supports AOSP HCI extensions.""" 399 chipset_name = self.facade.get_chipset_name() 400 chip_info = chipinfo.query(chipset_name) 401 if not chip_info.aosp_support: 402 raise error.TestNAError('Chipset ' + chipset_name + 403 ' does not support AOSP HCI extensions') 404 405 def test_aosp_quality_report(self): 406 """Checks if Bluetooth controller supports AOSP quality report.""" 407 logging.info('** Running aosp quality report test:') 408 self.assert_aosp_hci() 409 version_supported = self.hcitool.le_get_vendor_capabilities_command( 410 )[8] 411 if version_supported < self.GOOGLE_FEATURE_SPECIFICATION_VERSION: 412 raise error.TestFail('Version supported = ' + version_supported + 413 ' but expected >=' + 414 self.GOOGLE_FEATURE_SPECIFICATION_VERSION) 415 bluetooth_quality_report_support = ( 416 self.hcitool.le_get_vendor_capabilities_command()[14]) 417 if not bluetooth_quality_report_support: 418 raise error.TestFail('AOSP Quality Report is not supported') 419 logging.info( 420 'With bluetooth_quality_report_support =%d and ' 421 'version_supported >=%s, the controller supports the ' 422 'Android HCI Extension Bluetooth Quality Report.', 423 bluetooth_quality_report_support, version_supported) 424 425 def test_le_apcf(self): 426 """Checks if APCF filtering feature is supported.""" 427 logging.info('** Running LE APCF test:') 428 self.assert_aosp_hci() 429 filtering_support = self.hcitool.le_get_vendor_capabilities_command( 430 )[5] 431 if not filtering_support: 432 raise error.TestFail('LE APCF feature is not supported') 433 logging.info('LE APCF feature is supported.') 434 435 def test_le_batch_scan_and_events(self): 436 """Checks if LE batch scan and events feature is supported.""" 437 logging.info('** Running LE batch scan and events test:') 438 self.assert_aosp_hci() 439 total_scan_result_storage = ( 440 self.hcitool.le_get_vendor_capabilities_command()[3]) 441 if total_scan_result_storage == 0: 442 raise error.TestFail( 443 'LE batch scan and events feature is not supported') 444 logging.info('LE batch scan and events feature is supported.') 445 446 def test_le_extended_set_scan_parameters(self): 447 """Checks if LE extended set scan parameters feature is supported.""" 448 logging.info('** Running LE extended set scan parameters test:') 449 self.assert_aosp_hci() 450 extended_scan_support = self.hcitool.le_get_vendor_capabilities_command( 451 )[10] 452 if not extended_scan_support: 453 raise error.TestFail( 454 'LE extended set scan parameters feature is not supported') 455 logging.info('LE extended set scan parameters feature is supported.') 456 457 def test_le_get_controller_activity_energy_info(self): 458 """Checks if LE get controller activity energy info feature is 459 supported. """ 460 logging.info('** Running LE get controller activity energy info test:') 461 self.assert_aosp_hci() 462 activity_energy_info_support = ( 463 self.hcitool.le_get_vendor_capabilities_command()[7]) 464 if not activity_energy_info_support: 465 raise error.TestFail( 466 'LE get controller activity energy info feature is ' 467 'not supported') 468 logging.info( 469 'LE get controller activity energy info feature is supported.') 470 471 def test_get_controller_debug_info_sub_event(self): 472 """Checks if get controller debug info and sub-event features is 473 supported. """ 474 logging.info('** Running get controller debug info sub-event test:') 475 self.assert_aosp_hci() 476 debug_logging_support = self.hcitool.le_get_vendor_capabilities_command( 477 )[11] 478 if not debug_logging_support: 479 raise error.TestFail( 480 'Get controller debug info and sub-event features is not ' 481 'supported') 482 logging.info( 483 'Get controller debug info and sub-event features is supported.' 484 ) 485 486 def avl_hci_batch_run(self, test_name=None): 487 """Runs bluetooth_AVLHCI test batch (all test). 488 489 @param test_name: test name as string from control file. 490 """ 491 if test_name is None: 492 self.spec_legacy_test() 493 self.spec_4_0_test() 494 self.spec_4_1_test() 495 self.spec_4_2_test() 496 self.spec_5_0_test() 497 self.spec_5_2_test() 498 self.hci_ext_msft_test() 499 self.hci_ext_aosp_test() 500 else: 501 getattr(self, test_name)() 502 503 def run_once(self, test_name=None): 504 """Runs bluetooth_AVLHCI. 505 506 @param test_name: test name as string from control file. 507 """ 508 self.facade.reset_on() 509 self.avl_hci_batch_run(test_name) 510 self.facade.reset_on() 511