Skip to content

Commit

Permalink
pw_bluetooth: Add SniffModeCommand
Browse files Browse the repository at this point in the history
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 <[email protected]>
Commit-Queue: Alan Rosenthal <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: David Rees <[email protected]>
  • Loading branch information
AlanRosenthal authored and CQ Bot Account committed Sep 5, 2024
1 parent f56b3e7 commit 444d211
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 0 deletions.
68 changes: 68 additions & 0 deletions pw_bluetooth/emboss_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,5 +224,73 @@ TEST(EmbossTest, ReadScoPayloadLength) {
EXPECT_EQ(sco.data_total_length().Read(), 6);
}

TEST(EmbossTest, WriteSniffMode) {
std::array<uint8_t, emboss::SniffModeCommandWriter::SizeInBytes()> 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<uint8_t, emboss::SniffModeCommandView::SizeInBytes()> 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<uint8_t, emboss::SniffModeCommandView::SizeInBytes()> 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
48 changes: 48 additions & 0 deletions pw_bluetooth/public/pw_bluetooth/hci_commands.emb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ==========


Expand Down
5 changes: 5 additions & 0 deletions pw_bluetooth/public/pw_bluetooth/hci_common.emb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 444d211

Please sign in to comment.