OSDN Git Service

gd: Refactor LE advertising config
authorChienyuan <chienyuanhuang@google.com>
Tue, 3 Nov 2020 12:56:56 +0000 (20:56 +0800)
committerChienyuan <chienyuanhuang@google.com>
Thu, 5 Nov 2020 08:07:54 +0000 (16:07 +0800)
Tag: #gd-refactor
Bug: 169125803
Test: cert/run --host
Test: atest --host bluetooth_test_gd
Change-Id: I06ef138d9325c404bdc1c57fed2149ae36964e36

15 files changed:
gd/facade/common.proto
gd/hci/cert/le_acl_manager_test.py
gd/hci/cert/le_advertising_manager_test.py
gd/hci/cert/le_scanning_manager_test.py
gd/hci/cert/le_scanning_with_security_test.py
gd/hci/facade/le_advertising_manager_facade.cc
gd/hci/facade/le_advertising_manager_facade.proto
gd/hci/hci_packets.pdl
gd/hci/le_advertising_manager.cc
gd/hci/le_advertising_manager.h
gd/hci/le_advertising_manager_test.cc
gd/l2cap/le/cert/dual_l2cap_test.py
gd/l2cap/le/cert/le_l2cap_test.py
gd/security/cert/le_security_test.py
main/shim/le_advertising_manager.cc

index b1176a4..92bddb5 100644 (file)
@@ -13,6 +13,13 @@ enum BluetoothAddressTypeEnum {
   RANDOM_IDENTITY_ADDRESS = 0x3;
 }
 
+enum BluetoothOwnAddressTypeEnum {
+  USE_PUBLIC_DEVICE_ADDRESS = 0x0;
+  USE_RANDOM_DEVICE_ADDRESS = 0x1;
+  RESOLVABLE_OR_PUBLIC_ADDRESS = 0x2;
+  RESOLVABLE_OR_RANDOM_ADDRESS = 0x3;
+}
+
 message BluetoothAddressWithType {
   BluetoothAddress address = 1;
   BluetoothAddressTypeEnum type = 2;
index 6c2befb..31905e4 100644 (file)
@@ -224,8 +224,8 @@ class LeAclManagerTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=common.RANDOM_DEVICE_ADDRESS,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
             peer_address_type=common.PUBLIC_DEVICE_OR_IDENTITY_ADDRESS,
             peer_address=common.BluetoothAddress(address=bytes(b'A6:A5:A4:A3:A2:A1')),
             channel_map=7,
index bbdf717..030a860 100644 (file)
@@ -78,8 +78,8 @@ class LeAdvertisingManagerTest(GdBaseTestClass):
                 advertisement=[gap_data],
                 interval_min=512,
                 interval_max=768,
-                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-                address_type=common.RANDOM_DEVICE_ADDRESS,
+                advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+                own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
                 channel_map=7,
                 filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
             request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index 4ea9b99..45be8a6 100644 (file)
@@ -83,8 +83,8 @@ class LeScanningManagerTest(GdBaseTestClass):
                 advertisement=[gap_data],
                 interval_min=512,
                 interval_max=768,
-                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-                address_type=common.RANDOM_DEVICE_ADDRESS,
+                advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+                own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
                 channel_map=7,
                 filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
             request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index 9ca61e2..242ded9 100644 (file)
@@ -72,8 +72,8 @@ class LeScanningWithSecurityTest(GdBaseTestClass):
                 advertisement=[gap_data],
                 interval_min=512,
                 interval_max=768,
-                event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-                address_type=common.RANDOM_DEVICE_ADDRESS,
+                advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+                own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
                 channel_map=7,
                 filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
             request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index 12afdd2..2be2e9e 100644 (file)
@@ -71,9 +71,9 @@ bool AdvertisingConfigFromProto(const AdvertisingConfig& config_proto, hci::Adve
   }
   config->interval_max = static_cast<uint16_t>(config_proto.interval_max());
 
-  config->event_type = static_cast<hci::AdvertisingType>(config_proto.event_type());
+  config->advertising_type = static_cast<hci::AdvertisingType>(config_proto.advertising_type());
 
-  config->address_type = static_cast<::bluetooth::hci::AddressType>(config_proto.address_type());
+  config->own_address_type = static_cast<::bluetooth::hci::OwnAddressType>(config_proto.own_address_type());
 
   config->peer_address_type = static_cast<::bluetooth::hci::PeerAddressType>(config_proto.peer_address_type());
 
index 25e5cbf..edb70cf 100644 (file)
@@ -38,8 +38,8 @@ message AdvertisingConfig {
   int32 interval_min = 4;
   // Unit: number of Bluetooth slots in 0.125 ms increment
   int32 interval_max = 5;
-  AdvertisingEventType event_type = 6;
-  bluetooth.facade.BluetoothAddressTypeEnum address_type = 7;
+  AdvertisingEventType advertising_type = 6;
+  bluetooth.facade.BluetoothOwnAddressTypeEnum own_address_type = 7;
   bluetooth.facade.BluetoothPeerAddressTypeEnum peer_address_type = 8;
   bluetooth.facade.BluetoothAddress peer_address = 9;
   int32 channel_map = 10;
index 1f2e139..58cf8a7 100644 (file)
@@ -2478,11 +2478,18 @@ enum AddressType : 8 {
   RANDOM_IDENTITY_ADDRESS = 0x03,
 }
 
+enum OwnAddressType : 8 {
+  PUBLIC_DEVICE_ADDRESS = 0x00,
+  RANDOM_DEVICE_ADDRESS = 0x01,
+  RESOLVABLE_OR_PUBLIC_ADDRESS = 0x02,
+  RESOLVABLE_OR_RANDOM_ADDRESS = 0x03,
+}
+
 packet LeSetAdvertisingParameters : LeAdvertisingCommand (op_code = LE_SET_ADVERTISING_PARAMETERS) {
   interval_min : 16,
   interval_max : 16,
   type : AdvertisingType,
-  own_address_type : AddressType,
+  own_address_type : OwnAddressType,
   peer_address_type : PeerAddressType,
   peer_address : Address,
   channel_map : 8,
@@ -2542,13 +2549,6 @@ enum LeScanningFilterPolicy : 8 {
   CONNECT_LIST_AND_INITIATORS_IDENTITY = 0x03,
 }
 
-enum OwnAddressType : 8 {
-  PUBLIC_DEVICE_ADDRESS = 0x00,
-  RANDOM_DEVICE_ADDRESS = 0x01,
-  RESOLVABLE_OR_PUBLIC_ADDRESS = 0x02,
-  RESOLVABLE_OR_RANDOM_ADDRESS = 0x03,
-}
-
 packet LeSetScanParameters : LeScanningCommand (op_code = LE_SET_SCAN_PARAMETERS) {
   le_scan_type : LeScanType,
   le_scan_interval : 16, // 0x0004-0x4000 Default 0x10 (10ms)
@@ -3753,7 +3753,7 @@ packet LeMultiAdvtParam : LeMultiAdvt (sub_cmd = SET_PARAM) {
   interval_min : 16,
   interval_max : 16,
   type : AdvertisingType,
-  own_address_type : AddressType,
+  own_address_type : OwnAddressType,
   peer_address_type : PeerAddressType,
   peer_address : Address,
   channel_map : 8,
index 2c8885b..f66048b 100644 (file)
@@ -47,7 +47,7 @@ struct Advertiser {
 };
 
 ExtendedAdvertisingConfig::ExtendedAdvertisingConfig(const AdvertisingConfig& config) : AdvertisingConfig(config) {
-  switch (config.event_type) {
+  switch (config.advertising_type) {
     case AdvertisingType::ADV_IND:
       connectable = true;
       scannable = true;
@@ -70,13 +70,6 @@ ExtendedAdvertisingConfig::ExtendedAdvertisingConfig(const AdvertisingConfig& co
       LOG_WARN("Unknown event type");
       break;
   }
-  if (config.address_type == AddressType::PUBLIC_DEVICE_ADDRESS) {
-    own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
-  } else if (config.address_type == AddressType::RANDOM_DEVICE_ADDRESS) {
-    own_address_type = OwnAddressType::RANDOM_DEVICE_ADDRESS;
-  }
-  // TODO(b/149221472): Support fragmentation
-  operation = Operation::COMPLETE_ADVERTISEMENT;
 }
 
 struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallback {
@@ -211,8 +204,8 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
             hci::LeSetAdvertisingParametersBuilder::Create(
                 config.interval_min,
                 config.interval_max,
-                config.event_type,
-                config.address_type,
+                config.advertising_type,
+                config.own_address_type,
                 config.peer_address_type,
                 config.peer_address,
                 config.channel_map,
@@ -245,8 +238,8 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
             hci::LeMultiAdvtParamBuilder::Create(
                 config.interval_min,
                 config.interval_max,
-                config.event_type,
-                config.address_type,
+                config.advertising_type,
+                config.own_address_type,
                 config.peer_address_type,
                 config.peer_address,
                 config.channel_map,
@@ -387,15 +380,17 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
       advertising_sets_[id].current_address =
           AddressWithType(controller_->GetMacAddress(), AddressType::PUBLIC_DEVICE_ADDRESS);
     }
+
+    // TODO(b/149221472): Support fragmentation
+    auto operation = Operation::COMPLETE_ADVERTISEMENT;
     if (!config.scan_response.empty()) {
       le_advertising_interface_->EnqueueCommand(
-          hci::LeSetExtendedAdvertisingScanResponseBuilder::Create(id, config.operation, config.fragment_preference,
-                                                                   config.scan_response),
+          hci::LeSetExtendedAdvertisingScanResponseBuilder::Create(
+              id, operation, kFragment_preference, config.scan_response),
           module_handler_->BindOnce(impl::check_status<LeSetExtendedAdvertisingScanResponseCompleteView>));
     }
     le_advertising_interface_->EnqueueCommand(
-        hci::LeSetExtendedAdvertisingDataBuilder::Create(id, config.operation, config.fragment_preference,
-                                                         config.advertisement),
+        hci::LeSetExtendedAdvertisingDataBuilder::Create(id, operation, kFragment_preference, config.advertisement),
         module_handler_->BindOnce(impl::check_status<LeSetExtendedAdvertisingDataCompleteView>));
 
     EnabledSet curr_set;
@@ -548,17 +543,16 @@ struct LeAdvertisingManager::impl : public bluetooth::hci::LeAddressManagerCallb
       case (AdvertisingApiType::EXTENDED): {
         // TODO(b/149221472): Support fragmentation
         auto operation = Operation::COMPLETE_ADVERTISEMENT;
-        auto fragment_preference = FragmentPreference::CONTROLLER_SHOULD_NOT;
 
         if (set_scan_rsp) {
           le_advertising_interface_->EnqueueCommand(
               hci::LeSetExtendedAdvertisingScanResponseBuilder::Create(
-                  advertiser_id, operation, fragment_preference, data),
+                  advertiser_id, operation, kFragment_preference, data),
               module_handler_->BindOnceOn(
                   this, &impl::check_status_with_id<LeSetExtendedAdvertisingScanResponseCompleteView>, advertiser_id));
         } else {
           le_advertising_interface_->EnqueueCommand(
-              hci::LeSetExtendedAdvertisingDataBuilder::Create(advertiser_id, operation, fragment_preference, data),
+              hci::LeSetExtendedAdvertisingDataBuilder::Create(advertiser_id, operation, kFragment_preference, data),
               module_handler_->BindOnceOn(
                   this, &impl::check_status_with_id<LeSetExtendedAdvertisingDataCompleteView>, advertiser_id));
         }
@@ -931,13 +925,13 @@ AdvertiserId LeAdvertisingManager::CreateAdvertiser(
     const AdvertisingConfig& config, const common::Callback<void(Address, AddressType)>& scan_callback,
     const common::Callback<void(ErrorCode, uint8_t, uint8_t)>& set_terminated_callback, os::Handler* handler) {
   if (config.peer_address == Address::kEmpty) {
-    if (config.address_type == hci::AddressType::PUBLIC_IDENTITY_ADDRESS ||
-        config.address_type == hci::AddressType::RANDOM_IDENTITY_ADDRESS) {
+    if (config.own_address_type == hci::OwnAddressType::RESOLVABLE_OR_PUBLIC_ADDRESS ||
+        config.own_address_type == hci::OwnAddressType::RESOLVABLE_OR_RANDOM_ADDRESS) {
       LOG_WARN("Peer address can not be empty");
       return kInvalidId;
     }
-    if (config.event_type == hci::AdvertisingType::ADV_DIRECT_IND ||
-        config.event_type == hci::AdvertisingType::ADV_DIRECT_IND_LOW) {
+    if (config.advertising_type == hci::AdvertisingType::ADV_DIRECT_IND ||
+        config.advertising_type == hci::AdvertisingType::ADV_DIRECT_IND_LOW) {
       LOG_WARN("Peer address can not be empty for directed advertising");
       return kInvalidId;
     }
index d17890f..e3e20e5 100644 (file)
@@ -31,8 +31,8 @@ class AdvertisingConfig {
   std::vector<GapData> scan_response;
   uint16_t interval_min;
   uint16_t interval_max;
-  AdvertisingType event_type;
-  AddressType address_type;
+  AdvertisingType advertising_type;
+  OwnAddressType own_address_type;
   PeerAddressType peer_address_type;
   Address peer_address;
   uint8_t channel_map;
@@ -54,9 +54,6 @@ class ExtendedAdvertisingConfig : public AdvertisingConfig {
   SecondaryPhyType secondary_advertising_phy;
   uint8_t sid = 0x00;
   Enable enable_scan_request_notifications = Enable::DISABLED;
-  OwnAddressType own_address_type;
-  Operation operation;  // TODO(b/149221472): Support fragmentation
-  FragmentPreference fragment_preference = FragmentPreference::CONTROLLER_SHOULD_NOT;
   ExtendedAdvertisingConfig() = default;
   ExtendedAdvertisingConfig(const AdvertisingConfig& config);
 };
@@ -100,6 +97,7 @@ class LeAdvertisingManager : public bluetooth::Module {
   static constexpr AdvertiserId kInvalidId = 0xFF;
   static constexpr uint8_t kInvalidHandle = 0xFF;
   static constexpr uint8_t kAdvertisingSetIdMask = 0x0F;
+  static constexpr FragmentPreference kFragment_preference = FragmentPreference::CONTROLLER_SHOULD_NOT;
   LeAdvertisingManager();
 
   size_t GetNumberOfAdvertisingInstances() const;
index cc2c0fa..a11af81 100644 (file)
@@ -375,8 +375,8 @@ class LeExtendedAdvertisingAPITest : public LeExtendedAdvertisingManagerTest {
 
     // start advertising set
     ExtendedAdvertisingConfig advertising_config{};
-    advertising_config.event_type = AdvertisingType::ADV_IND;
-    advertising_config.address_type = AddressType::PUBLIC_DEVICE_ADDRESS;
+    advertising_config.advertising_type = AdvertisingType::ADV_IND;
+    advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
     std::vector<GapData> gap_data{};
     GapData data_item{};
     data_item.data_type_ = GapDataType::FLAGS;
@@ -432,8 +432,8 @@ TEST_F(LeExtendedAdvertisingManagerTest, startup_teardown) {}
 
 TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
   AdvertisingConfig advertising_config{};
-  advertising_config.event_type = AdvertisingType::ADV_IND;
-  advertising_config.address_type = AddressType::PUBLIC_DEVICE_ADDRESS;
+  advertising_config.advertising_type = AdvertisingType::ADV_IND;
+  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
   std::vector<GapData> gap_data{};
   GapData data_item{};
   data_item.data_type_ = GapDataType::FLAGS;
@@ -480,8 +480,8 @@ TEST_F(LeAdvertisingManagerTest, create_advertiser_test) {
 
 TEST_F(LeAndroidHciAdvertisingManagerTest, create_advertiser_test) {
   AdvertisingConfig advertising_config{};
-  advertising_config.event_type = AdvertisingType::ADV_IND;
-  advertising_config.address_type = AddressType::PUBLIC_DEVICE_ADDRESS;
+  advertising_config.advertising_type = AdvertisingType::ADV_IND;
+  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
   std::vector<GapData> gap_data{};
   GapData data_item{};
   data_item.data_type_ = GapDataType::FLAGS;
@@ -521,8 +521,8 @@ TEST_F(LeAndroidHciAdvertisingManagerTest, create_advertiser_test) {
 
 TEST_F(LeExtendedAdvertisingManagerTest, create_advertiser_test) {
   ExtendedAdvertisingConfig advertising_config{};
-  advertising_config.event_type = AdvertisingType::ADV_IND;
-  advertising_config.address_type = AddressType::PUBLIC_DEVICE_ADDRESS;
+  advertising_config.advertising_type = AdvertisingType::ADV_IND;
+  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
   std::vector<GapData> gap_data{};
   GapData data_item{};
   data_item.data_type_ = GapDataType::FLAGS;
@@ -578,8 +578,8 @@ TEST_F(LeExtendedAdvertisingAPITest, startup_teardown) {}
 
 TEST_F(LeExtendedAdvertisingAPITest, set_parameter) {
   ExtendedAdvertisingConfig advertising_config{};
-  advertising_config.event_type = AdvertisingType::ADV_IND;
-  advertising_config.address_type = AddressType::PUBLIC_DEVICE_ADDRESS;
+  advertising_config.advertising_type = AdvertisingType::ADV_IND;
+  advertising_config.own_address_type = OwnAddressType::PUBLIC_DEVICE_ADDRESS;
   std::vector<GapData> gap_data{};
   GapData data_item{};
   data_item.data_type_ = GapDataType::COMPLETE_LOCAL_NAME;
index c8bde93..00e6392 100644 (file)
@@ -89,8 +89,8 @@ class DualL2capTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=common.RANDOM_DEVICE_ADDRESS,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
             channel_map=7,
             filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
         request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index 623ca3d..80f3aed 100644 (file)
@@ -77,8 +77,8 @@ class LeL2capTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=common.RANDOM_DEVICE_ADDRESS,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
             channel_map=7,
             filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
         request = le_advertising_facade.CreateAdvertiserRequest(config=config)
@@ -101,8 +101,8 @@ class LeL2capTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=common.RANDOM_DEVICE_ADDRESS,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_RANDOM_DEVICE_ADDRESS,
             channel_map=7,
             filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
         request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index 36ea8bd..a61cb3d 100644 (file)
@@ -109,8 +109,8 @@ class LeSecurityTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=self.cert_address.type,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_PUBLIC_DEVICE_ADDRESS,
             channel_map=7,
             filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
         request = le_advertising_facade.CreateAdvertiserRequest(config=config)
@@ -126,8 +126,8 @@ class LeSecurityTest(GdBaseTestClass):
             advertisement=[gap_data],
             interval_min=512,
             interval_max=768,
-            event_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
-            address_type=self.dut_address.type,
+            advertising_type=le_advertising_facade.AdvertisingEventType.ADV_IND,
+            own_address_type=common.USE_PUBLIC_DEVICE_ADDRESS,
             channel_map=7,
             filter_policy=le_advertising_facade.AdvertisingFilterPolicy.ALL_DEVICES)
         request = le_advertising_facade.CreateAdvertiserRequest(config=config)
index c4000d9..5f42e45 100644 (file)
@@ -169,8 +169,6 @@ class BleAdvertiserInterfaceImpl : public BleAdvertiserInterface,
       offset += len + 1;  // 1 byte for len
     }
 
-    config.operation = bluetooth::hci::Operation::COMPLETE_ADVERTISEMENT;
-
     bluetooth::hci::AdvertiserId id =
         bluetooth::shim::GetAdvertising()->ExtendedCreateAdvertiser(
             reg_id, config, scan_callback, set_terminated_callback,