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

Commit b439c051 authored by Myles Watson's avatar Myles Watson
Browse files

Rootcanal: Use PDL to parse incoming commands

Test: ./run_cert.sh
Change-Id: I83e8e7b4b958934bdd1d5d930fb966f6ddca1eb5
parent 6ab53eba
Loading
Loading
Loading
Loading
+722 −601

File changed.

Preview size limit exceeded, changes collapsed.

+105 −104
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@
namespace test_vendor_lib {

using ::bluetooth::hci::Address;
using ::bluetooth::packet::PacketView;
using ::bluetooth::hci::CommandPacketView;

// Emulates a dual mode BR/EDR + LE controller by maintaining the link layer
// state machine detailed in the Bluetooth Core Specification Version 4.2,
@@ -107,315 +107,315 @@ class DualModeController : public Device {
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.1

  // 7.1.1
  void HciInquiry(PacketView<true> args);
  void Inquiry(CommandPacketView args);

  // 7.1.2
  void HciInquiryCancel(PacketView<true> args);
  void InquiryCancel(CommandPacketView args);

  // 7.1.5
  void HciCreateConnection(PacketView<true> args);
  void CreateConnection(CommandPacketView args);

  // 7.1.6
  void HciDisconnect(PacketView<true> args);
  void Disconnect(CommandPacketView args);

  // 7.1.8
  void HciAcceptConnectionRequest(PacketView<true> args);
  void AcceptConnectionRequest(CommandPacketView args);

  // 7.1.9
  void HciRejectConnectionRequest(PacketView<true> args);
  void RejectConnectionRequest(CommandPacketView args);

  // 7.1.10
  void HciLinkKeyRequestReply(PacketView<true> args);
  void LinkKeyRequestReply(CommandPacketView args);

  // 7.1.11
  void HciLinkKeyRequestNegativeReply(PacketView<true> args);
  void LinkKeyRequestNegativeReply(CommandPacketView args);

  // 7.1.14
  void HciChangeConnectionPacketType(PacketView<true> args);
  void ChangeConnectionPacketType(CommandPacketView args);

  // 7.1.15
  void HciAuthenticationRequested(PacketView<true> args);
  void AuthenticationRequested(CommandPacketView args);

  // 7.1.16
  void HciSetConnectionEncryption(PacketView<true> args);
  void SetConnectionEncryption(CommandPacketView args);

  // 7.1.17
  void HciChangeConnectionLinkKey(PacketView<true> args);
  void ChangeConnectionLinkKey(CommandPacketView args);

  // 7.1.18
  void HciMasterLinkKey(PacketView<true> args);
  void MasterLinkKey(CommandPacketView args);

  // 7.1.19
  void HciRemoteNameRequest(PacketView<true> args);
  void RemoteNameRequest(CommandPacketView args);

  // 7.2.8
  void HciSwitchRole(PacketView<true> args);
  void SwitchRole(CommandPacketView args);

  // 7.1.21
  void HciReadRemoteSupportedFeatures(PacketView<true> args);
  void ReadRemoteSupportedFeatures(CommandPacketView args);

  // 7.1.22
  void HciReadRemoteExtendedFeatures(PacketView<true> args);
  void ReadRemoteExtendedFeatures(CommandPacketView args);

  // 7.1.23
  void HciReadRemoteVersionInformation(PacketView<true> args);
  void ReadRemoteVersionInformation(CommandPacketView args);

  // 7.1.24
  void HciReadClockOffset(PacketView<true> args);
  void ReadClockOffset(CommandPacketView args);

  // 7.1.29
  void HciIoCapabilityRequestReply(PacketView<true> args);
  void IoCapabilityRequestReply(CommandPacketView args);

  // 7.1.30
  void HciUserConfirmationRequestReply(PacketView<true> args);
  void UserConfirmationRequestReply(CommandPacketView args);

  // 7.1.31
  void HciUserConfirmationRequestNegativeReply(PacketView<true> args);
  void UserConfirmationRequestNegativeReply(CommandPacketView args);

  // 7.1.32
  void HciUserPasskeyRequestReply(PacketView<true> args);
  void UserPasskeyRequestReply(CommandPacketView args);

  // 7.1.33
  void HciUserPasskeyRequestNegativeReply(PacketView<true> args);
  void UserPasskeyRequestNegativeReply(CommandPacketView args);

  // 7.1.34
  void HciRemoteOobDataRequestReply(PacketView<true> args);
  void RemoteOobDataRequestReply(CommandPacketView args);

  // 7.1.35
  void HciRemoteOobDataRequestNegativeReply(PacketView<true> args);
  void RemoteOobDataRequestNegativeReply(CommandPacketView args);

  // 7.1.36
  void HciIoCapabilityRequestNegativeReply(PacketView<true> args);
  void IoCapabilityRequestNegativeReply(CommandPacketView args);

  // Link Policy Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.2

  // 7.2.1
  void HciHoldMode(PacketView<true> args);
  void HoldMode(CommandPacketView args);

  // 7.2.2
  void HciSniffMode(PacketView<true> args);
  void SniffMode(CommandPacketView args);

  // 7.2.3
  void HciExitSniffMode(PacketView<true> args);
  void ExitSniffMode(CommandPacketView args);

  // 7.2.6
  void HciQosSetup(PacketView<true> args);
  void QosSetup(CommandPacketView args);

  // 7.2.10
  void HciWriteLinkPolicySettings(PacketView<true> args);
  void WriteLinkPolicySettings(CommandPacketView args);

  // 7.2.12
  void HciWriteDefaultLinkPolicySettings(PacketView<true> args);
  void WriteDefaultLinkPolicySettings(CommandPacketView args);

  // 7.2.13
  void HciFlowSpecification(PacketView<true> args);
  void FlowSpecification(CommandPacketView args);

  // 7.2.14
  void HciSniffSubrating(PacketView<true> args);
  void SniffSubrating(CommandPacketView args);

  // Link Controller Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3

  // 7.3.1
  void HciSetEventMask(PacketView<true> args);
  void SetEventMask(CommandPacketView args);

  // 7.3.2
  void HciReset(PacketView<true> args);
  void Reset(CommandPacketView args);

  // 7.3.3
  void HciSetEventFilter(PacketView<true> args);
  void SetEventFilter(CommandPacketView args);

  // 7.3.10
  void HciDeleteStoredLinkKey(PacketView<true> args);
  void DeleteStoredLinkKey(CommandPacketView args);

  // 7.3.11
  void HciWriteLocalName(PacketView<true> args);
  void WriteLocalName(CommandPacketView args);

  // 7.3.12
  void HciReadLocalName(PacketView<true> args);
  void ReadLocalName(CommandPacketView args);

  // 7.3.16
  void HciWritePageTimeout(PacketView<true> args);
  void WritePageTimeout(CommandPacketView args);

  // 7.3.18
  void HciWriteScanEnable(PacketView<true> args);
  void WriteScanEnable(CommandPacketView args);

  // 7.3.22
  void HciWriteInquiryScanActivity(PacketView<true> args);
  void WriteInquiryScanActivity(CommandPacketView args);

  // 7.3.23
  void HciReadAuthenticationEnable(PacketView<true> args);
  void ReadAuthenticationEnable(CommandPacketView args);

  // 7.3.24
  void HciWriteAuthenticationEnable(PacketView<true> args);
  void WriteAuthenticationEnable(CommandPacketView args);

  // 7.3.26
  void HciWriteClassOfDevice(PacketView<true> args);
  void WriteClassOfDevice(CommandPacketView args);

  // 7.3.28
  void HciWriteVoiceSetting(PacketView<true> args);
  void WriteVoiceSetting(CommandPacketView args);

  // 7.3.39
  void HciHostBufferSize(PacketView<true> args);
  void HostBufferSize(CommandPacketView args);

  // 7.3.42
  void HciWriteLinkSupervisionTimeout(PacketView<true> args);
  void WriteLinkSupervisionTimeout(CommandPacketView args);

  // 7.3.45
  void HciWriteCurrentIacLap(PacketView<true> args);
  void WriteCurrentIacLap(CommandPacketView args);

  // 7.3.48
  void HciWriteInquiryScanType(PacketView<true> args);
  void WriteInquiryScanType(CommandPacketView args);

  // 7.3.50
  void HciWriteInquiryMode(PacketView<true> args);
  void WriteInquiryMode(CommandPacketView args);

  // 7.3.52
  void HciWritePageScanType(PacketView<true> args);
  void WritePageScanType(CommandPacketView args);

  // 7.3.56
  void HciWriteExtendedInquiryResponse(PacketView<true> args);
  void WriteExtendedInquiryResponse(CommandPacketView args);

  // 7.3.57
  void HciRefreshEncryptionKey(PacketView<true> args);
  void RefreshEncryptionKey(CommandPacketView args);

  // 7.3.59
  void HciWriteSimplePairingMode(PacketView<true> args);
  void WriteSimplePairingMode(CommandPacketView args);

  // 7.3.79
  void HciWriteLeHostSupport(PacketView<true> args);
  void WriteLeHostSupport(CommandPacketView args);

  // 7.3.92
  void HciWriteSecureConnectionsHostSupport(PacketView<true> args);
  void WriteSecureConnectionsHostSupport(CommandPacketView args);

  // Informational Parameters Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4

  // 7.4.5
  void HciReadBufferSize(PacketView<true> args);
  void ReadBufferSize(CommandPacketView args);

  // 7.4.1
  void HciReadLocalVersionInformation(PacketView<true> args);
  void ReadLocalVersionInformation(CommandPacketView args);

  // 7.4.6
  void HciReadBdAddr(PacketView<true> args);
  void ReadBdAddr(CommandPacketView args);

  // 7.4.2
  void HciReadLocalSupportedCommands(PacketView<true> args);
  void ReadLocalSupportedCommands(CommandPacketView args);

  // 7.4.3
  void HciReadLocalSupportedFeatures(PacketView<true> args);
  void ReadLocalSupportedFeatures(CommandPacketView args);

  // 7.4.4
  void HciReadLocalExtendedFeatures(PacketView<true> args);
  void ReadLocalExtendedFeatures(CommandPacketView args);

  // 7.4.8
  void HciReadLocalSupportedCodecs(PacketView<true> args);
  void ReadLocalSupportedCodecs(CommandPacketView args);

  // Status Parameters Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.5

  // 7.5.7
  void HciReadEncryptionKeySize(PacketView<true> args);
  void ReadEncryptionKeySize(CommandPacketView args);

  // Test Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.7

  // 7.7.1
  void HciReadLoopbackMode(PacketView<true> args);
  void ReadLoopbackMode(CommandPacketView args);

  // 7.7.2
  void HciWriteLoopbackMode(PacketView<true> args);
  void WriteLoopbackMode(CommandPacketView args);

  // LE Controller Commands
  // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.8

  // 7.8.1
  void HciLeSetEventMask(PacketView<true> args);
  void LeSetEventMask(CommandPacketView args);

  // 7.8.2
  void HciLeReadBufferSize(PacketView<true> args);
  void LeReadBufferSize(CommandPacketView args);

  // 7.8.3
  void HciLeReadLocalSupportedFeatures(PacketView<true> args);
  void LeReadLocalSupportedFeatures(CommandPacketView args);

  // 7.8.4
  void HciLeSetRandomAddress(PacketView<true> args);
  void LeSetRandomAddress(CommandPacketView args);

  // 7.8.5
  void HciLeSetAdvertisingParameters(PacketView<true> args);
  void LeSetAdvertisingParameters(CommandPacketView args);

  // 7.8.7
  void HciLeSetAdvertisingData(PacketView<true> args);
  void LeSetAdvertisingData(CommandPacketView args);

  // 7.8.8
  void HciLeSetScanResponseData(PacketView<true> args);
  void LeSetScanResponseData(CommandPacketView args);

  // 7.8.9
  void HciLeSetAdvertisingEnable(PacketView<true> args);
  void LeSetAdvertisingEnable(CommandPacketView args);

  // 7.8.10
  void HciLeSetScanParameters(PacketView<true> args);
  void LeSetScanParameters(CommandPacketView args);

  // 7.8.11
  void HciLeSetScanEnable(PacketView<true> args);
  void LeSetScanEnable(CommandPacketView args);

  // 7.8.12
  void HciLeCreateConnection(PacketView<true> args);
  void LeCreateConnection(CommandPacketView args);

  // 7.8.18
  void HciLeConnectionUpdate(PacketView<true> args);
  void LeConnectionUpdate(CommandPacketView args);

  // 7.8.13
  void HciLeConnectionCancel(PacketView<true> args);
  void LeConnectionCancel(CommandPacketView args);

  // 7.8.14
  void HciLeReadWhiteListSize(PacketView<true> args);
  void LeReadWhiteListSize(CommandPacketView args);

  // 7.8.15
  void HciLeClearWhiteList(PacketView<true> args);
  void LeClearWhiteList(CommandPacketView args);

  // 7.8.16
  void HciLeAddDeviceToWhiteList(PacketView<true> args);
  void LeAddDeviceToWhiteList(CommandPacketView args);

  // 7.8.17
  void HciLeRemoveDeviceFromWhiteList(PacketView<true> args);
  void LeRemoveDeviceFromWhiteList(CommandPacketView args);

  // 7.8.21
  void HciLeReadRemoteFeatures(PacketView<true> args);
  void LeReadRemoteFeatures(CommandPacketView args);

  // 7.8.23
  void HciLeRand(PacketView<true> args);
  void LeRand(CommandPacketView args);

  // 7.8.24
  void HciLeStartEncryption(PacketView<true> args);
  void LeStartEncryption(CommandPacketView args);

  // 7.8.27
  void HciLeReadSupportedStates(PacketView<true> args);
  void LeReadSupportedStates(CommandPacketView args);

  // 7.8.38
  void HciLeAddDeviceToResolvingList(PacketView<true> args);
  void LeAddDeviceToResolvingList(CommandPacketView args);

  // 7.8.39
  void HciLeRemoveDeviceFromResolvingList(PacketView<true> args);
  void LeRemoveDeviceFromResolvingList(CommandPacketView args);

  // 7.8.40
  void HciLeClearResolvingList(PacketView<true> args);
  void LeClearResolvingList(CommandPacketView args);

  // 7.8.77
  void HciLeSetPrivacyMode(PacketView<true> args);
  void LeSetPrivacyMode(CommandPacketView args);

  // Vendor-specific Commands

  void HciLeVendorSleepMode(PacketView<true> args);
  void HciLeVendorCap(PacketView<true> args);
  void HciLeVendorMultiAdv(PacketView<true> args);
  void HciLeVendor155(PacketView<true> args);
  void HciLeVendor157(PacketView<true> args);
  void HciLeEnergyInfo(PacketView<true> args);
  void HciLeAdvertisingFilter(PacketView<true> args);
  void HciLeExtendedScanParams(PacketView<true> args);
  void LeVendorSleepMode(CommandPacketView args);
  void LeVendorCap(CommandPacketView args);
  void LeVendorMultiAdv(CommandPacketView args);
  void LeVendor155(CommandPacketView args);
  void LeVendor157(CommandPacketView args);
  void LeEnergyInfo(CommandPacketView args);
  void LeAdvertisingFilter(CommandPacketView args);
  void LeExtendedScanParams(CommandPacketView args);

  void SetTimerPeriod(std::chrono::milliseconds new_period);
  void StartTimer();
@@ -443,7 +443,8 @@ class DualModeController : public Device {
  // Maintains the commands to be registered and used in the HciHandler object.
  // Keys are command opcodes and values are the callbacks to handle each
  // command.
  std::unordered_map<uint16_t, std::function<void(PacketView<true>)>>
  std::unordered_map<bluetooth::hci::OpCode,
                     std::function<void(bluetooth::hci::CommandPacketView)>>
      active_hci_commands_;

  bluetooth::hci::LoopbackMode loopback_mode_;