Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5288893e authored by Myles Watson's avatar Myles Watson
Browse files

HCI: Use arrays and fixed-length structs

Test: build
Change-Id: I74a470b7d31a716824c7356cff7698451604a5ad
parent 13606c9e
Loading
Loading
Loading
Loading
+5 −11
Original line number Original line Diff line number Diff line
@@ -160,13 +160,8 @@ struct ClassicSecurityManager::impl {
                               common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_);
                               common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_);
  }
  }


  void write_stored_link_key(uint8_t num_keys_to_write, Address address, common::LinkKey link_key) {
  void write_stored_link_key(std::vector<KeyAndAddress> keys) {
    // TODO send multi link key
    std::unique_ptr<WriteStoredLinkKeyBuilder> packet = WriteStoredLinkKeyBuilder::Create(keys);
    std::array<uint8_t, 16> link_key_array;
    std::copy(std::begin(link_key.link_key), std::end(link_key.link_key), std::begin(link_key_array));

    std::unique_ptr<WriteStoredLinkKeyBuilder> packet =
        WriteStoredLinkKeyBuilder::Create(num_keys_to_write, address, link_key_array);
    hci_layer_->EnqueueCommand(std::move(packet),
    hci_layer_->EnqueueCommand(std::move(packet),
                               common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_);
                               common::BindOnce(&impl::on_command_complete, common::Unretained(this)), handler_);
  }
  }
@@ -330,9 +325,8 @@ void ClassicSecurityManager::ReadStoredLinkKey(Address address, ReadStoredLinkKe
  GetHandler()->Post(BindOnce(&impl::read_stored_link_key, common::Unretained(pimpl_.get()), address, read_all_flag));
  GetHandler()->Post(BindOnce(&impl::read_stored_link_key, common::Unretained(pimpl_.get()), address, read_all_flag));
}
}


void ClassicSecurityManager::WriteStoredLinkKey(uint8_t num_keys_to_write, Address address, common::LinkKey link_key) {
void ClassicSecurityManager::WriteStoredLinkKey(std::vector<KeyAndAddress> keys) {
  GetHandler()->Post(
  GetHandler()->Post(BindOnce(&impl::write_stored_link_key, common::Unretained(pimpl_.get()), keys));
      BindOnce(&impl::write_stored_link_key, common::Unretained(pimpl_.get()), num_keys_to_write, address, link_key));
}
}


void ClassicSecurityManager::DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) {
void ClassicSecurityManager::DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag) {
+1 −1
Original line number Original line Diff line number Diff line
@@ -51,7 +51,7 @@ class ClassicSecurityManager : public Module {
  void RemoteOobDataRequestReply(Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r);
  void RemoteOobDataRequestReply(Address address, std::array<uint8_t, 16> c, std::array<uint8_t, 16> r);
  void RemoteOobDataRequestNegativeReply(Address address);
  void RemoteOobDataRequestNegativeReply(Address address);
  void ReadStoredLinkKey(Address address, ReadStoredLinkKeyReadAllFlag read_all_flag);
  void ReadStoredLinkKey(Address address, ReadStoredLinkKeyReadAllFlag read_all_flag);
  void WriteStoredLinkKey(uint8_t num_keys_to_write, Address address, common::LinkKey link_key);
  void WriteStoredLinkKey(std::vector<KeyAndAddress> keys);
  void DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag);
  void DeleteStoredLinkKey(Address address, DeleteStoredLinkKeyDeleteAllFlag delete_all_flag);
  void RefreshEncryptionKey(uint16_t connection_handle);
  void RefreshEncryptionKey(uint16_t connection_handle);
  void ReadSimplePairingMode();
  void ReadSimplePairingMode();
+3 −3
Original line number Original line Diff line number Diff line
@@ -66,9 +66,9 @@ struct Controller::impl {
    ASSERT(acl_credits_handler_ != nullptr);
    ASSERT(acl_credits_handler_ != nullptr);
    auto complete_view = NumberOfCompletedPacketsView::Create(event);
    auto complete_view = NumberOfCompletedPacketsView::Create(event);
    ASSERT(complete_view.IsValid());
    ASSERT(complete_view.IsValid());
    for (auto completed_packets : complete_view.GetHandlesAndCompletedPackets()) {
    for (auto completed_packets : complete_view.GetCompletedPackets()) {
      uint16_t handle = completed_packets & 0x0fff;
      uint16_t handle = completed_packets.connection_handle_;
      uint16_t credits = (completed_packets & 0xffff0000) >> 16;
      uint16_t credits = completed_packets.host_num_of_completed_packets_;
      acl_credits_handler_->Post(Bind(acl_credits_callback_, handle, credits));
      acl_credits_handler_->Post(Bind(acl_credits_callback_, handle, credits));
    }
    }
  }
  }
+9 −4
Original line number Original line Diff line number Diff line
@@ -109,10 +109,15 @@ class TestHciLayer : public HciLayer {
  }
  }


  void IncomingCredit() {
  void IncomingCredit() {
    std::vector<uint32_t> handles_and_completed_packets;
    std::vector<CompletedPackets> completed_packets;
    handles_and_completed_packets.push_back(kCredits1 << 16 | kHandle1);
    CompletedPackets cp;
    handles_and_completed_packets.push_back(kCredits2 << 16 | kHandle2);
    cp.host_num_of_completed_packets_ = kCredits1;
    auto event_builder = NumberOfCompletedPacketsBuilder::Create(handles_and_completed_packets);
    cp.connection_handle_ = kHandle1;
    completed_packets.push_back(cp);
    cp.host_num_of_completed_packets_ = kCredits2;
    cp.connection_handle_ = kHandle2;
    completed_packets.push_back(cp);
    auto event_builder = NumberOfCompletedPacketsBuilder::Create(completed_packets);
    auto packet = GetPacketView(std::move(event_builder));
    auto packet = GetPacketView(std::move(event_builder));
    EventPacketView event = EventPacketView::Create(packet);
    EventPacketView event = EventPacketView::Create(packet);
    ASSERT(event.IsValid());
    ASSERT(event.IsValid());
+10 −5
Original line number Original line Diff line number Diff line
@@ -457,12 +457,17 @@ class ClassicSecurityManagerFacadeService : public ClassicSecurityManagerFacade:
                                    ::google::protobuf::Empty* response) {
                                    ::google::protobuf::Empty* response) {
    std::unique_lock<std::mutex> lock(mutex_);
    std::unique_lock<std::mutex> lock(mutex_);
    uint8_t num_keys_to_write = request->num_keys_to_write();
    uint8_t num_keys_to_write = request->num_keys_to_write();
    Address peer;
    std::vector<KeyAndAddress> keys;
    for (size_t i = 0; i < num_keys_to_write; i++) {
      KeyAndAddress key;
      common::LinkKey link_key;
      common::LinkKey link_key;
    ASSERT(Address::FromString(request->remote().address(), peer));
      ASSERT(Address::FromString(request->remote().address(), key.address_));
      ASSERT(common::LinkKey::FromString(request->link_keys(), link_key));
      ASSERT(common::LinkKey::FromString(request->link_keys(), link_key));
      std::copy(std::begin(link_key.link_key), std::end(link_key.link_key), std::begin(key.link_key_));
      keys.push_back(key);
    }


    classic_security_manager_->WriteStoredLinkKey(num_keys_to_write, peer, link_key);
    classic_security_manager_->WriteStoredLinkKey(keys);
    return ::grpc::Status::OK;
    return ::grpc::Status::OK;
  };
  };


Loading