Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,21 @@ cc_binary(
# breaks the device registration
# features = ["-thin_lto"],
)

load("@hedron_compile_commands//:refresh_compile_commands.bzl", "refresh_compile_commands")

refresh_compile_commands(
name = "refresh_compile_commands",

# Specify the targets of interest.
# For example, specify a dict of targets and any flags required to build.
targets = {
"//:rootcanal": "",
},
# No need to add flags already in .bazelrc. They're automatically picked up.
# If you don't need flags, a list of targets is also okay, as is a single target string.
# Wildcard patterns, like //... for everything, *are* allowed here, just like a build.
# As are additional targets (+) and subtractions (-), like in bazel query https://docs.bazel.build/versions/main/query.html#expressions
# And if you're working on a header-only library, specify a test or binary target that compiles it.
exclude_external_sources = True,
)
9 changes: 9 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,12 @@ crate.spec(package = "bytes", version = "1.0.1")

crate.from_specs()
use_repo(crate, "crates")

bazel_dep(name = "hedron_compile_commands", dev_dependency = True)
git_override(
module_name = "hedron_compile_commands",
remote = "https://github.com/hedronvision/bazel-compile-commands-extractor.git",
commit = "4f28899228fb3ad0126897876f147ca15026151e",
# Replace the commit hash (above) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main).
# Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
)
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ git submodule update --init
bazel run :rootcanal
```

### Creating compile_commands.json for IDE support

`bazel run :refresh_compile_commands`

### Python instructions

```
Expand Down
4 changes: 2 additions & 2 deletions desktop/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ void TestEnvironment::SetUpTestChannel() {
return false;
});

test_channel_.AddPhy({"BR_EDR"});
test_channel_.AddPhy({"LOW_ENERGY"});
test_channel_.AddPhy({"BR_EDR", "IDEAL"});
test_channel_.AddPhy({"LOW_ENERGY", "IDEAL"});
test_channel_.AddDevice({"beacon", "be:ac:01:55:00:01", "1000"});
test_channel_.AddDeviceToPhy({"0", "1"});
test_channel_.AddDevice({"beacon", "be:ac:01:55:00:02", "1000"});
Expand Down
5 changes: 5 additions & 0 deletions include/phy.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Phy {
LOW_ENERGY,
BR_EDR,
};

enum class Model {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PathLossModel ?

PSEUDORANDOM,
IDEAL,
};
};

} // namespace rootcanal
64 changes: 37 additions & 27 deletions model/controller/controller_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ static std::array<uint8_t, 64> SupportedCommands() {
// OpCodeIndex::REMOTE_NAME_REQUEST_CANCEL,
OpCodeIndex::READ_REMOTE_SUPPORTED_FEATURES, OpCodeIndex::READ_REMOTE_EXTENDED_FEATURES,
OpCodeIndex::READ_REMOTE_VERSION_INFORMATION, OpCodeIndex::READ_CLOCK_OFFSET,
OpCodeIndex::READ_LMP_HANDLE, OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION,
// OpCodeIndex::READ_LMP_HANDLE, OpCodeIndex::SETUP_SYNCHRONOUS_CONNECTION,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Careful, SETUP_SYNCHRONOUS_CONNECTION is implemented.

OpCodeIndex::ACCEPT_SYNCHRONOUS_CONNECTION, OpCodeIndex::REJECT_SYNCHRONOUS_CONNECTION,
OpCodeIndex::IO_CAPABILITY_REQUEST_REPLY, OpCodeIndex::USER_CONFIRMATION_REQUEST_REPLY,
OpCodeIndex::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY,
Expand Down Expand Up @@ -171,7 +171,7 @@ static std::array<uint8_t, 64> SupportedCommands() {

// CONTROLLER_AND_BASEBAND
OpCodeIndex::SET_EVENT_MASK, OpCodeIndex::RESET, OpCodeIndex::SET_EVENT_FILTER,
OpCodeIndex::FLUSH,
// OpCodeIndex::FLUSH,
// OpCodeIndex::READ_PIN_TYPE,
// OpCodeIndex::WRITE_PIN_TYPE,
// OpCodeIndex::READ_STORED_LINK_KEY,
Expand All @@ -185,34 +185,41 @@ static std::array<uint8_t, 64> SupportedCommands() {
OpCodeIndex::WRITE_INQUIRY_SCAN_ACTIVITY, OpCodeIndex::READ_AUTHENTICATION_ENABLE,
OpCodeIndex::WRITE_AUTHENTICATION_ENABLE, OpCodeIndex::READ_CLASS_OF_DEVICE,
OpCodeIndex::WRITE_CLASS_OF_DEVICE, OpCodeIndex::READ_VOICE_SETTING,
OpCodeIndex::WRITE_VOICE_SETTING, OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT,
OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT,
OpCodeIndex::WRITE_VOICE_SETTING,
// OpCodeIndex::READ_AUTOMATIC_FLUSH_TIMEOUT,
// OpCodeIndex::WRITE_AUTOMATIC_FLUSH_TIMEOUT,
// OpCodeIndex::READ_NUM_BROADCAST_RETRANSMITS,
// OpCodeIndex::WRITE_NUM_BROADCAST_RETRANSMITS,
OpCodeIndex::READ_HOLD_MODE_ACTIVITY, OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY,
// OpCodeIndex::READ_HOLD_MODE_ACTIVITY, OpCodeIndex::WRITE_HOLD_MODE_ACTIVITY,
OpCodeIndex::READ_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
OpCodeIndex::WRITE_SYNCHRONOUS_FLOW_CONTROL_ENABLE,
OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL, OpCodeIndex::HOST_BUFFER_SIZE,
OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS, OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT,
// OpCodeIndex::SET_CONTROLLER_TO_HOST_FLOW_CONTROL,
OpCodeIndex::HOST_BUFFER_SIZE,
// OpCodeIndex::HOST_NUMBER_OF_COMPLETED_PACKETS, OpCodeIndex::READ_LINK_SUPERVISION_TIMEOUT,
OpCodeIndex::WRITE_LINK_SUPERVISION_TIMEOUT, OpCodeIndex::READ_NUMBER_OF_SUPPORTED_IAC,
OpCodeIndex::READ_CURRENT_IAC_LAP, OpCodeIndex::WRITE_CURRENT_IAC_LAP,
OpCodeIndex::SET_AFH_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::READ_INQUIRY_SCAN_TYPE,
// OpCodeIndex::SET_AFH_HOST_CHANNEL_CLASSIFICATION,
OpCodeIndex::READ_INQUIRY_SCAN_TYPE,
OpCodeIndex::WRITE_INQUIRY_SCAN_TYPE, OpCodeIndex::READ_INQUIRY_MODE,
OpCodeIndex::WRITE_INQUIRY_MODE, OpCodeIndex::READ_PAGE_SCAN_TYPE,
OpCodeIndex::WRITE_PAGE_SCAN_TYPE, OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE,
OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE,
OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE, OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE,
OpCodeIndex::REFRESH_ENCRYPTION_KEY, OpCodeIndex::READ_SIMPLE_PAIRING_MODE,
OpCodeIndex::WRITE_PAGE_SCAN_TYPE,
// OpCodeIndex::READ_AFH_CHANNEL_ASSESSMENT_MODE,
// OpCodeIndex::WRITE_AFH_CHANNEL_ASSESSMENT_MODE,
// OpCodeIndex::READ_EXTENDED_INQUIRY_RESPONSE,
OpCodeIndex::WRITE_EXTENDED_INQUIRY_RESPONSE,
OpCodeIndex::REFRESH_ENCRYPTION_KEY,
// OpCodeIndex::READ_SIMPLE_PAIRING_MODE,
OpCodeIndex::WRITE_SIMPLE_PAIRING_MODE, OpCodeIndex::READ_LOCAL_OOB_DATA,
OpCodeIndex::READ_INQUIRY_RESPONSE_TRANSMIT_POWER_LEVEL,
OpCodeIndex::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL,
// OpCodeIndex::WRITE_INQUIRY_TRANSMIT_POWER_LEVEL,
// OpCodeIndex::READ_DEFAULT_ERRONEOUS_DATA_REPORTING,
// OpCodeIndex::WRITE_DEFAULT_ERRONEOUS_DATA_REPORTING,
OpCodeIndex::ENHANCED_FLUSH, OpCodeIndex::SEND_KEYPRESS_NOTIFICATION,
OpCodeIndex::SET_EVENT_MASK_PAGE_2,
// OpCodeIndex::READ_FLOW_CONTROL_MODE,
// OpCodeIndex::WRITE_FLOW_CONTROL_MODE,
OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL, OpCodeIndex::READ_LE_HOST_SUPPORT,
OpCodeIndex::READ_ENHANCED_TRANSMIT_POWER_LEVEL,
// OpCodeIndex::READ_LE_HOST_SUPPORT,
OpCodeIndex::WRITE_LE_HOST_SUPPORT,
// OpCodeIndex::SET_MWS_CHANNEL_PARAMETERS,
// OpCodeIndex::SET_EXTERNAL_FRAME_CONFIGURATION,
Expand All @@ -225,18 +232,18 @@ static std::array<uint8_t, 64> SupportedCommands() {
// OpCodeIndex::SET_CONNECTIONLESS_PERIPHERAL_BROADCAST_DATA,
// OpCodeIndex::READ_SYNCHRONIZATION_TRAIN_PARAMETERS,
// OpCodeIndex::WRITE_SYNCHRONIZATION_TRAIN_PARAMETERS,
OpCodeIndex::READ_SECURE_CONNECTIONS_HOST_SUPPORT,
// OpCodeIndex::READ_SECURE_CONNECTIONS_HOST_SUPPORT,
OpCodeIndex::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT,
OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT,
OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT,
// OpCodeIndex::READ_AUTHENTICATED_PAYLOAD_TIMEOUT,
// OpCodeIndex::WRITE_AUTHENTICATED_PAYLOAD_TIMEOUT,
OpCodeIndex::READ_LOCAL_OOB_EXTENDED_DATA,
// OpCodeIndex::READ_EXTENDED_PAGE_TIMEOUT,
// OpCodeIndex::WRITE_EXTENDED_PAGE_TIMEOUT,
// OpCodeIndex::READ_EXTENDED_INQUIRY_LENGTH,
// OpCodeIndex::WRITE_EXTENDED_INQUIRY_LENGTH,
// OpCodeIndex::SET_ECOSYSTEM_BASE_INTERVAL,
// OpCodeIndex::CONFIGURE_DATA_PATH,
// OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE,
OpCodeIndex::SET_MIN_ENCRYPTION_KEY_SIZE,

// INFORMATIONAL_PARAMETERS
OpCodeIndex::READ_LOCAL_VERSION_INFORMATION, OpCodeIndex::READ_LOCAL_SUPPORTED_FEATURES,
Expand All @@ -252,17 +259,18 @@ static std::array<uint8_t, 64> SupportedCommands() {
// STATUS_PARAMETERS
OpCodeIndex::READ_FAILED_CONTACT_COUNTER, OpCodeIndex::RESET_FAILED_CONTACT_COUNTER,
// OpCodeIndex::READ_LINK_QUALITY,
OpCodeIndex::READ_RSSI, OpCodeIndex::READ_AFH_CHANNEL_MAP,
OpCodeIndex::READ_RSSI,
// OpCodeIndex::READ_AFH_CHANNEL_MAP,
// OpCodeIndex::READ_CLOCK,
OpCodeIndex::READ_ENCRYPTION_KEY_SIZE,
// OpCodeIndex::GET_MWS_TRANSPORT_LAYER_CONFIGURATION,
// OpCodeIndex::SET_TRIGGERED_CLOCK_CAPTURE,

// TESTING
OpCodeIndex::READ_LOOPBACK_MODE, OpCodeIndex::WRITE_LOOPBACK_MODE,
OpCodeIndex::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE,
OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE,
OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE,
// OpCodeIndex::ENABLE_IMPLEMENTATION_UNDER_TEST_MODE,
// OpCodeIndex::WRITE_SIMPLE_PAIRING_DEBUG_MODE,
// OpCodeIndex::WRITE_SECURE_CONNECTIONS_TEST_MODE,

// LE_CONTROLLER
OpCodeIndex::LE_SET_EVENT_MASK, OpCodeIndex::LE_READ_BUFFER_SIZE_V1,
Expand All @@ -276,13 +284,14 @@ static std::array<uint8_t, 64> SupportedCommands() {
OpCodeIndex::LE_CLEAR_FILTER_ACCEPT_LIST,
OpCodeIndex::LE_ADD_DEVICE_TO_FILTER_ACCEPT_LIST,
OpCodeIndex::LE_REMOVE_DEVICE_FROM_FILTER_ACCEPT_LIST, OpCodeIndex::LE_CONNECTION_UPDATE,
OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_READ_CHANNEL_MAP,
// OpCodeIndex::LE_SET_HOST_CHANNEL_CLASSIFICATION, OpCodeIndex::LE_READ_CHANNEL_MAP,
OpCodeIndex::LE_READ_REMOTE_FEATURES_PAGE_0, OpCodeIndex::LE_ENCRYPT,
OpCodeIndex::LE_RAND, OpCodeIndex::LE_START_ENCRYPTION,
OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_REPLY,
OpCodeIndex::LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY,
OpCodeIndex::LE_READ_SUPPORTED_STATES, OpCodeIndex::LE_RECEIVER_TEST_V1,
OpCodeIndex::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TEST_END,
OpCodeIndex::LE_READ_SUPPORTED_STATES,
// OpCodeIndex::LE_RECEIVER_TEST_V1,
// OpCodeIndex::LE_TRANSMITTER_TEST_V1, OpCodeIndex::LE_TEST_END,
OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_REPLY,
OpCodeIndex::LE_REMOTE_CONNECTION_PARAMETER_REQUEST_NEGATIVE_REPLY,
OpCodeIndex::LE_SET_DATA_LENGTH,
Expand Down Expand Up @@ -321,8 +330,9 @@ static std::array<uint8_t, 64> SupportedCommands() {
OpCodeIndex::LE_CLEAR_PERIODIC_ADVERTISER_LIST,
OpCodeIndex::LE_READ_PERIODIC_ADVERTISER_LIST_SIZE,
// OpCodeIndex::LE_READ_TRANSMIT_POWER,
OpCodeIndex::LE_READ_RF_PATH_COMPENSATION_POWER,
OpCodeIndex::LE_WRITE_RF_PATH_COMPENSATION_POWER, OpCodeIndex::LE_SET_PRIVACY_MODE,
// OpCodeIndex::LE_READ_RF_PATH_COMPENSATION_POWER,
// OpCodeIndex::LE_WRITE_RF_PATH_COMPENSATION_POWER,
OpCodeIndex::LE_SET_PRIVACY_MODE,
// OpCodeIndex::LE_RECEIVER_TEST_V3,
// OpCodeIndex::LE_TRANSMITTER_TEST_V3,
// OpCodeIndex::LE_SET_CONNECTIONLESS_CTE_TRANSMIT_PARAMETERS,
Expand Down
28 changes: 23 additions & 5 deletions model/setup/test_command_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,31 @@ void TestCommandHandler::RemoveDevice(const vector<std::string>& args) {
}

void TestCommandHandler::AddPhy(const vector<std::string>& args) {
if (args.size() != 1) {
response_string_ = "TestCommandHandler 'add_phy' takes one argument";
} else if (args[0] == "LOW_ENERGY") {
model_.AddPhy(Phy::Type::LOW_ENERGY);
if (args.size() < 1) {
response_string_ = "TestCommandHandler 'add_phy' takes at least one argument: type, and optional model";
send_response_(response_string_);
return;
}

Phy::Model phy_model = Phy::Model::PSEUDORANDOM;

if (args.size() > 1) {
if (args[1] == "IDEAL") {
phy_model = Phy::Model::IDEAL;
} else if (args[1] == "PSEUDORANDOM") {
phy_model = Phy::Model::PSEUDORANDOM;
} else {
response_string_ = "TestCommandHandler 'add_phy' unrecognized model " + args[1];
send_response_(response_string_);
return;
}
}

if (args[0] == "LOW_ENERGY") {
model_.AddPhy(Phy::Type::LOW_ENERGY, phy_model);
response_string_ = "TestCommandHandler 'add_phy' called with LOW_ENERGY";
} else if (args[0] == "BR_EDR") {
model_.AddPhy(Phy::Type::BR_EDR);
model_.AddPhy(Phy::Type::BR_EDR, phy_model);
response_string_ = "TestCommandHandler 'add_phy' called with BR_EDR";
} else {
response_string_ = "TestCommandHandler 'add_phy' with unrecognized type " + args[0];
Expand Down
24 changes: 20 additions & 4 deletions model/setup/test_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,24 @@ void TestModel::StopTimer() {
timer_tick_task_ = kInvalidTaskId;
}

std::unique_ptr<PhyLayer> TestModel::CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type) {
return std::make_unique<PhyLayer>(id, type);
class IdealPhyLayer : public PhyLayer {
public:
IdealPhyLayer(PhyLayer::Identifier id, Phy::Type type) : PhyLayer(id, type) {}

int8_t ComputeRssi(PhyDevice::Identifier sender_id, PhyDevice::Identifier receiver_id, int8_t tx_power) {
return -30;
}
};

std::unique_ptr<PhyLayer> TestModel::CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type, Phy::Model model) {
if (model == Phy::Model::IDEAL) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a switch case preferably ?

return std::make_unique<IdealPhyLayer>(id, type);
} else if (model == Phy::Model::PSEUDORANDOM) {
return std::make_unique<PhyLayer>(id, type);
} else {
ERROR("Unknown PHY model: {}, using pseudorandom", static_cast<std::underlying_type_t<Phy::Model>>(model));
return std::make_unique<PhyLayer>(id, type);
}
}

std::shared_ptr<PhyDevice> TestModel::CreatePhyDevice(std::string type,
Expand Down Expand Up @@ -133,9 +149,9 @@ void TestModel::RemoveDevice(PhyDevice::Identifier device_id) {
}

// Add a phy to the test model.
PhyLayer::Identifier TestModel::AddPhy(Phy::Type type) {
PhyLayer::Identifier TestModel::AddPhy(Phy::Type type, Phy::Model model) {
static PhyLayer::Identifier next_id = 0;
std::shared_ptr<PhyLayer> phy_layer = CreatePhyLayer(next_id++, type);
std::shared_ptr<PhyLayer> phy_layer = CreatePhyLayer(next_id++, type, model);
phy_layers_[phy_layer->id] = phy_layer;
return phy_layer->id;
}
Expand Down
4 changes: 2 additions & 2 deletions model/setup/test_model.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class TestModel {
}

// Allow derived classes to use custom phy layer.
virtual std::unique_ptr<PhyLayer> CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type);
virtual std::unique_ptr<PhyLayer> CreatePhyLayer(PhyLayer::Identifier id, Phy::Type type, Phy::Model model);

// Allow derived classes to use custom phy devices.
virtual std::shared_ptr<PhyDevice> CreatePhyDevice(std::string type,
Expand All @@ -70,7 +70,7 @@ class TestModel {

PhyDevice::Identifier AddDevice(std::shared_ptr<Device> device);
void RemoveDevice(PhyDevice::Identifier id);
PhyLayer::Identifier AddPhy(Phy::Type type);
PhyLayer::Identifier AddPhy(Phy::Type type, Phy::Model model);
void RemovePhy(PhyLayer::Identifier id);
void AddDeviceToPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id);
void RemoveDeviceFromPhy(PhyDevice::Identifier device_id, PhyLayer::Identifier phy_id);
Expand Down