From 444d211943b4813c07049865960f53042663c700 Mon Sep 17 00:00:00 2001 From: Alan Rosenthal Date: Thu, 5 Sep 2024 18:53:08 +0000 Subject: [PATCH] pw_bluetooth: Add SniffModeCommand MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: 364898905 Test: added tests, presubmit passes Change-Id: I092cf323adc3833ea994f451554f58956fa7ee13 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/233593 Reviewed-by: Josh Conner Commit-Queue: Alan Rosenthal Lint: Lint 🤖 Reviewed-by: David Rees --- pw_bluetooth/emboss_test.cc | 68 +++++++++++++++++++ .../public/pw_bluetooth/hci_commands.emb | 48 +++++++++++++ .../public/pw_bluetooth/hci_common.emb | 5 ++ 3 files changed, 121 insertions(+) diff --git a/pw_bluetooth/emboss_test.cc b/pw_bluetooth/emboss_test.cc index aaccb0d7de..baf8b81224 100644 --- a/pw_bluetooth/emboss_test.cc +++ b/pw_bluetooth/emboss_test.cc @@ -224,5 +224,73 @@ TEST(EmbossTest, ReadScoPayloadLength) { EXPECT_EQ(sco.data_total_length().Read(), 6); } +TEST(EmbossTest, WriteSniffMode) { + std::array buffer{}; + emboss::SniffModeCommandWriter writer = + emboss::MakeSniffModeCommandView(&buffer); + writer.header().opcode_enum().Write(emboss::OpCode::SNIFF_MODE); + writer.header().parameter_total_size().Write( + emboss::SniffModeCommandWriter::SizeInBytes() - + emboss::CommandHeaderWriter::SizeInBytes()); + writer.connection_handle().Write(0x0004); + writer.sniff_max_interval().Write(0x0330); + writer.sniff_min_interval().Write(0x0190); + writer.sniff_attempt().Write(0x0004); + writer.sniff_timeout().Write(0x0001); + std::array expected{ + // Opcode (LSB, MSB) + 0x03, + 0x08, + // Parameter Total Size + 0x0A, + // Connection Handle (LSB, MSB) + 0x04, + 0x00, + // Sniff Max Interval (LSB, MSB) + 0x30, + 0x03, + // Sniff Min Interval (LSB, MSB) + 0x90, + 0x01, + // Sniff Attempt (LSB, MSB) + 0x04, + 0x00, + // Sniff Timeout (LSB, MSB) + 0x01, + 0x00}; + EXPECT_EQ(buffer, expected); +} + +TEST(EmbossTest, ReadSniffMode) { + std::array buffer{ + // Opcode (LSB, MSB) + 0x03, + 0x08, + // Parameter Total Size + 0x0A, + // Connection Handle (LSB, MSB) + 0x04, + 0x00, + // Sniff Max Interval (LSB, MSB) + 0x30, + 0x03, + // Sniff Min Interval (LSB, MSB) + 0x90, + 0x01, + // Sniff Attempt (LSB, MSB) + 0x04, + 0x00, + // Sniff Timeout (LSB, MSB) + 0x01, + 0x00}; + emboss::SniffModeCommandView view = emboss::MakeSniffModeCommandView(&buffer); + EXPECT_EQ(view.header().opcode_enum().Read(), emboss::OpCode::SNIFF_MODE); + EXPECT_TRUE(view.header().IsComplete()); + EXPECT_EQ(view.connection_handle().Read(), 0x0004); + EXPECT_EQ(view.sniff_max_interval().Read(), 0x0330); + EXPECT_EQ(view.sniff_min_interval().Read(), 0x0190); + EXPECT_EQ(view.sniff_attempt().Read(), 0x0004); + EXPECT_EQ(view.sniff_timeout().Read(), 0x0001); +} } // namespace } // namespace pw::bluetooth diff --git a/pw_bluetooth/public/pw_bluetooth/hci_commands.emb b/pw_bluetooth/public/pw_bluetooth/hci_commands.emb index 031d837ac2..021a96a843 100644 --- a/pw_bluetooth/public/pw_bluetooth/hci_commands.emb +++ b/pw_bluetooth/public/pw_bluetooth/hci_commands.emb @@ -1067,6 +1067,54 @@ struct EnhancedAcceptSynchronousConnectionRequestCommand: # TODO: b/265052417 - Definition needs to be added +# ========== 7.2 Link Policy Commands ========== + + +struct SniffModeCommand: + -- 7.2.2 Sniff Mode command (v1.1) + -- HCI_Sniff_Mode + + let hdr_size = hci.CommandHeader.$size_in_bytes + + 0 [+hdr_size] hci.CommandHeader header + + $next [+2] UInt connection_handle + -- Connection_Handle (only the lower 12-bits are meaningful). + [requires: 0x0000 <= this <= 0x0EFF] + + $next [+2] UInt sniff_max_interval + -- Max interval + -- Range: 0x0002 to 0xFFFE; only even values are valid + -- Mandatory Range: 0x0006 to 0x0540 + -- Time = N × 0.625 ms + -- Time Range: 1.25 ms to 40.9 s + [requires: 0x0002 <= this <= 0xFFFE] + + $next [+2] UInt sniff_min_interval + -- Min interval + -- Range: 0x0002 to 0xFFFE; only even values are valid + -- Mandatory Range: 0x0006 to 0x0540 + -- Time = N × 0.625 ms + -- Time Range: 1.25 ms to 40.9 s + [requires: 0x0002 <= this <= 0xFFFE] + + $next [+2] UInt sniff_attempt + -- Number of Baseband receive slots for sniff attempt. + -- Length = N × 1.25 ms + -- Range: 0x0001 to 0x7FFF + -- Time Range: 1.25 ms to 40.9 s + -- Mandatory Range for Controller: 1 to Tsniff/2 + [requires: 0x0001 <= this <= 0x7FFF] + + $next [+2] UInt sniff_timeout + -- Number of Baseband receive slots for sniff timeout. + -- Length = N × 1.25 ms + -- Range: 0x0000 to 0x7FFF + -- Time Range: 0 ms to 40.9 s + -- Mandatory Range for Controller: 0 to 0x0028 + [requires: 0x0000 <= this <= 0x7FFF] + + # ========== 7.3 Controller & Baseband Commands ========== diff --git a/pw_bluetooth/public/pw_bluetooth/hci_common.emb b/pw_bluetooth/public/pw_bluetooth/hci_common.emb index 49a591b6a5..547b0f22ee 100644 --- a/pw_bluetooth/public/pw_bluetooth/hci_common.emb +++ b/pw_bluetooth/public/pw_bluetooth/hci_common.emb @@ -171,6 +171,11 @@ enum OpCode: IO_CAPABILITY_REQUEST_NEGATIVE_REPLY = 0x0434 -- IO Capability Request Negative Reply Command (v2.1 + EDR) (BR/EDR) + ### Link Policy Commands - Core Spec v5.4, Part E, Section 7.32 (OGF 0x02) + + SNIFF_MODE = 0x0803 + -- Sniff Mode Command + ### Controller & Baseband Commands - Core Spec v5.0 Vol 2, Part E, Section 7.3 (OGF 0x03) SET_EVENT_MASK = 0x0C01