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

Commit 7c615ebc authored by Henri Chataing's avatar Henri Chataing Committed by Gerrit Code Review
Browse files

Merge "RootCanal: Implement HCI command LE Encrypt"

parents e725c9b2 efc89043
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@
#include <memory>
#include <random>

#include "crypto_toolbox/crypto_toolbox.h"
#include "os/log.h"
#include "packet/raw_builder.h"

@@ -231,6 +232,7 @@ DualModeController::DualModeController(const std::string& properties_filename, u
  SET_SUPPORTED(LE_ADD_DEVICE_TO_CONNECT_LIST, LeAddDeviceToConnectList);
  SET_SUPPORTED(LE_REMOVE_DEVICE_FROM_CONNECT_LIST,
                LeRemoveDeviceFromConnectList);
  SET_SUPPORTED(LE_ENCRYPT, LeEncrypt);
  SET_SUPPORTED(LE_RAND, LeRand);
  SET_SUPPORTED(LE_READ_SUPPORTED_STATES, LeReadSupportedStates);
  SET_HANDLER(LE_GET_VENDOR_CAPABILITIES, LeVendorCap);
@@ -2289,6 +2291,18 @@ void DualModeController::LeReadRemoteFeatures(CommandView command) {
      status, kNumCommandPackets));
}

void DualModeController::LeEncrypt(CommandView command) {
  auto command_view = gd_hci::LeEncryptView::Create(
      gd_hci::LeSecurityCommandView::Create(command));
  ASSERT(command_view.IsValid());

  auto encrypted_data = bluetooth::crypto_toolbox::aes_128(
      command_view.GetKey(),
      command_view.GetPlaintextData());

  send_event_(bluetooth::hci::LeEncryptCompleteBuilder::Create(
      kNumCommandPackets, ErrorCode::SUCCESS, encrypted_data));
}

static std::random_device rd{};
static std::mt19937_64 s_mt{rd()};
+3 −0
Original line number Diff line number Diff line
@@ -471,6 +471,9 @@ class DualModeController : public Device {
  // 7.8.21
  void LeReadRemoteFeatures(CommandView args);

  // 7.8.22
  void LeEncrypt(CommandView args);

  // 7.8.23
  void LeRand(CommandView args);