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

Commit 6b52b851 authored by Chienyuan's avatar Chienyuan Committed by android-build-merger
Browse files

Merge "GD: HCI Security interface" am: cc8823ce am: 75ab7f9f

am: 97f9ae2c

Change-Id: I2d5154583aae5f7c8d66ee7f6259b7a197137245
parents 7ea00415 97f9ae2c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ class GdDevice(GdDeviceBase):
        self.rootservice = facade_rootservice_pb2_grpc.RootFacadeStub(self.grpc_root_server_channel)
        self.hal = hal_facade_pb2_grpc.HciHalFacadeStub(self.grpc_channel)
        self.hci = hci_facade_pb2_grpc.AclManagerFacadeStub(self.grpc_channel)
        self.hci_classic_security = hci_facade_pb2_grpc.ClassicSecurityManagerFacadeStub(self.grpc_channel)
        self.l2cap = l2cap_facade_pb2_grpc.L2capModuleFacadeStub(self.grpc_channel)

        # Event streams
@@ -78,3 +79,4 @@ class GdDevice(GdDeviceBase):
        self.hci.disconnection_stream = EventStream(self.hci.FetchDisconnection)
        self.hci.connection_failed_stream = EventStream(self.hci.FetchConnectionFailed)
        self.hci.acl_stream = EventStream(self.hci.FetchAclData)
        self.hci_classic_security.command_complete_stream = EventStream(self.hci_classic_security.FetchCommandCompleteEvent)
+2 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ filegroup {
    srcs: [
        "address.cc",
        "class_of_device.cc",
        "link_key.cc",
    ],
}

@@ -14,5 +15,6 @@ filegroup {
        "class_of_device_unittest.cc",
        "bidi_queue_unittest.cc",
        "observer_registry_test.cc",
        "link_key_unittest.cc",
    ],
}
+57 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2019 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#include "link_key.h"

namespace bluetooth {
namespace common {

const LinkKey LinkKey::kExample{
    {0x4C, 0x68, 0x38, 0x41, 0x39, 0xf5, 0x74, 0xd8, 0x36, 0xbc, 0xf3, 0x4e, 0x9d, 0xfb, 0x01, 0xbf}};

LinkKey::LinkKey(const uint8_t (&data)[16]) {
  std::copy(data, data + kLength, link_key);
}

std::string LinkKey::ToString() const {
  char buffer[33] = "";
  for (int i = 0; i < 16; i++) {
    std::snprintf(&buffer[i * 2], 3, "%02x", link_key[i]);
  }
  std::string str(buffer);
  return str;
}

bool LinkKey::FromString(const std::string& from, bluetooth::common::LinkKey& to) {
  LinkKey new_link_key;

  if (from.length() != 32) {
    return false;
  }

  char* temp = nullptr;
  for (int i = 0; i < 16; i++) {
    new_link_key.link_key[i] = strtol(from.substr(i * 2, 2).c_str(), &temp, 16);
  }

  to = new_link_key;
  return true;
}

}  // namespace common
}  // namespace bluetooth
+41 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2019 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#pragma once

#include <string>

namespace bluetooth {
namespace common {

class LinkKey final {
 public:
  LinkKey() = default;
  LinkKey(const uint8_t (&data)[16]);

  static constexpr unsigned int kLength = 16;
  uint8_t link_key[kLength];

  std::string ToString() const;
  static bool FromString(const std::string& from, LinkKey& to);

  static const LinkKey kExample;
};

}  // namespace common
}  // namespace bluetooth
 No newline at end of file
+50 −0
Original line number Diff line number Diff line
/******************************************************************************
 *
 *  Copyright 2019 The Android Open Source Project
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

#include "common/link_key.h"
#include <gtest/gtest.h>
#include "os/log.h"

using bluetooth::common::LinkKey;

static const char* test_link_key = "4c68384139f574d836bcf34e9dfb01bf\0";

TEST(LinkKeyUnittest, test_constructor_array) {
  uint8_t data[LinkKey::kLength] = {0x4c, 0x87, 0x49, 0xe1, 0x2e, 0x55, 0x0f, 0x7f,
                                    0x60, 0x8b, 0x4f, 0x96, 0xd7, 0xc5, 0xbc, 0x2a};

  LinkKey link_key(data);

  for (int i = 0; i < LinkKey::kLength; i++) {
    ASSERT_EQ(data[i], link_key.link_key[i]);
  }
}

TEST(LinkKeyUnittest, test_from_str) {
  LinkKey link_key;
  LinkKey::FromString(test_link_key, link_key);

  for (int i = 0; i < LinkKey::kLength; i++) {
    ASSERT_EQ(LinkKey::kExample.link_key[i], link_key.link_key[i]);
  }
}

TEST(LinkKeyUnittest, test_to_str) {
  std::string str = LinkKey::kExample.ToString();
  ASSERT_STREQ(str.c_str(), test_link_key);
}
 No newline at end of file
Loading