Skip to content

Commit 764d20b

Browse files
committed
Sync with aosp main
Synchronized to packages/modules/Bluetooth commit e3576fd8610d11b072e3d8e26d463c4ef085b1f3 Changelist: - Remove pending LE-ACL connection handling from AclConnectionHandler - Fix SEND_HCI_FUNC, SEND_LL_FUNC - Add LE_SET_HOST_FEATURE_V2 and fix LE_CS_REMOVE_CONFIG opcode - Add closure parameter to FFI callbacks - Add invalid_packet_handler callback to FFI interface - Fix SIOF causing SIGSEV in tests on exit - Migrate to new PDL rust generator - Fix -Wdeprecated-literal-operator. - Clippy lint fixes for rustc 1.86.0 - Update the implementation of generateP256Key for openSSL 3.0 - Add serde feature to rust crate - Remove unused HCI packet declarations
1 parent 91d5dac commit 764d20b

23 files changed

+1630
-1964
lines changed

model/controller/dual_mode_controller.cc

Lines changed: 1039 additions & 1040 deletions
Large diffs are not rendered by default.

model/controller/dual_mode_controller.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,14 +598,16 @@ class DualModeController : public Device {
598598

599599
// Map command opcodes to the corresponding bit index in the
600600
// supported command mask.
601-
static const std::unordered_map<OpCode, OpCodeIndex> hci_command_op_code_to_index_;
601+
static const std::unordered_map<OpCode, OpCodeIndex>& GetOpCodeToIndex();
602602

603603
// Map all implemented opcodes to the function implementing the handler
604604
// for the associated command. The map should be a subset of the
605605
// supported_command field in the properties_ object. Commands
606606
// that are supported but not implemented will raise a fatal assert.
607607
using CommandHandler = std::function<void(DualModeController*, bluetooth::hci::CommandView)>;
608-
static const std::unordered_map<OpCode, CommandHandler> hci_command_handlers_;
608+
609+
// Getter for the command handlers map
610+
static const std::unordered_map<OpCode, CommandHandler>& GetHciCommandHandlers();
609611
};
610612

611613
} // namespace rootcanal

model/controller/ffi.cc

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,41 @@ enum Idc {
3838
extern "C" {
3939

4040
__attribute__((visibility("default"))) void* ffi_controller_new(
41-
uint8_t const address[6], void (*send_hci)(int idc, uint8_t const* data, size_t data_len),
42-
void (*send_ll)(uint8_t const* data, size_t data_len, int phy, int tx_power)) {
41+
uint8_t const address[6],
42+
void (*send_hci)(void* cookie, int idc, uint8_t const* data, size_t data_len),
43+
void (*send_ll)(void* cookie, uint8_t const* data, size_t data_len, int phy, int tx_power),
44+
void (*invalid_packet_handler)(void* cookie, int reason, char const* message,
45+
uint8_t const* data, size_t data_len),
46+
void* cookie) {
4347
DualModeController* controller = new DualModeController();
4448
controller->SetAddress(
4549
Address({address[0], address[1], address[2], address[3], address[4], address[5]}));
4650
controller->RegisterEventChannel([=](std::shared_ptr<std::vector<uint8_t>> data) {
47-
send_hci(hci::Idc::EVT, data->data(), data->size());
51+
send_hci(cookie, hci::Idc::EVT, data->data(), data->size());
4852
});
4953
controller->RegisterAclChannel([=](std::shared_ptr<std::vector<uint8_t>> data) {
50-
send_hci(hci::Idc::ACL, data->data(), data->size());
54+
send_hci(cookie, hci::Idc::ACL, data->data(), data->size());
5155
});
5256
controller->RegisterScoChannel([=](std::shared_ptr<std::vector<uint8_t>> data) {
53-
send_hci(hci::Idc::SCO, data->data(), data->size());
57+
send_hci(cookie, hci::Idc::SCO, data->data(), data->size());
5458
});
5559
controller->RegisterIsoChannel([=](std::shared_ptr<std::vector<uint8_t>> data) {
56-
send_hci(hci::Idc::ISO, data->data(), data->size());
60+
send_hci(cookie, hci::Idc::ISO, data->data(), data->size());
5761
});
5862
controller->RegisterLinkLayerChannel(
5963
[=](std::vector<uint8_t> const& data, Phy::Type phy, int8_t tx_power) {
60-
send_ll(data.data(), data.size(), static_cast<int>(phy), tx_power);
64+
send_ll(cookie, data.data(), data.size(), static_cast<int>(phy), tx_power);
6165
});
6266

67+
if (invalid_packet_handler) {
68+
controller->RegisterInvalidPacketHandler([=](uint32_t /*id*/, InvalidPacketReason reason,
69+
std::string message,
70+
std::vector<uint8_t> const& packet) {
71+
invalid_packet_handler(cookie, static_cast<int>(reason), message.c_str(), packet.data(),
72+
packet.size());
73+
});
74+
}
75+
6376
return controller;
6477
}
6578

model/controller/ffi.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@
1919

2020
extern "C" {
2121

22-
void* ffi_controller_new(uint8_t const address[6],
23-
void (*send_hci)(int idc, uint8_t const* data, size_t data_len),
24-
void (*send_ll)(uint8_t const* data, size_t data_len, int phy,
25-
int tx_power));
22+
void* ffi_controller_new(
23+
uint8_t const address[6],
24+
void (*send_hci)(void* cookie, int idc, uint8_t const* data, size_t data_len),
25+
void (*send_ll)(void* cookie, uint8_t const* data, size_t data_len, int phy, int tx_power),
26+
void (*invalid_packet_handler)(void* cookie, int reason, char const* message,
27+
uint8_t const* data, size_t data_len),
28+
void* cookie);
2629
void ffi_controller_delete(void* controller);
2730
void ffi_controller_receive_hci(void* controller, int idc, uint8_t const* data, size_t data_len);
2831
void ffi_controller_receive_ll(void* controller, uint8_t const* data, size_t data_len, int phy,

model/controller/le_advertiser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ using duration = std::chrono::steady_clock::duration;
4040
using time_point = std::chrono::steady_clock::time_point;
4141
}; // namespace chrono
4242

43-
slots operator"" _slots(unsigned long long count) { return slots(count); }
43+
slots operator""_slots(unsigned long long count) { return slots(count); }
4444

4545
// =============================================================================
4646
// Constants

model/controller/le_advertiser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace rootcanal {
3232
using slots = std::chrono::duration<unsigned long long, std::ratio<625, 1000000>>;
3333

3434
// User defined literal for slots, e.g. `0x800_slots`
35-
slots operator"" _slots(unsigned long long count);
35+
slots operator""_slots(unsigned long long count);
3636

3737
using namespace bluetooth::hci;
3838

packets/hci_packets.pdl

Lines changed: 3 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -384,12 +384,13 @@ enum OpCode : 16 {
384384
LE_CS_READ_REMOTE_FAE_TABLE = 0x208E,
385385
LE_CS_WRITE_CACHED_REMOTE_FAE_TABLE = 0x208F,
386386
LE_CS_CREATE_CONFIG = 0x2090,
387-
LE_CS_REMOVE_CONFIG = 0x0291,
387+
LE_CS_REMOVE_CONFIG = 0x2091,
388388
LE_CS_SET_CHANNEL_CLASSIFICATION = 0x2092,
389389
LE_CS_SET_PROCEDURE_PARAMETERS = 0x2093,
390390
LE_CS_PROCEDURE_ENABLE = 0x2094,
391391
LE_CS_TEST = 0x2095,
392392
LE_CS_TEST_END = 0x2096,
393+
LE_SET_HOST_FEATURE_V2 = 0x2097,
393394
LE_ADD_DEVICE_TO_MONITORED_ADVERTISERS_LIST = 0x2098,
394395
LE_REMOVE_DEVICE_FROM_MONITORED_ADVERTISERS_LIST = 0x2099,
395396
LE_CLEAR_MONITORED_ADVERTISERS_LIST = 0x209A,
@@ -4029,18 +4030,6 @@ struct EnabledSet {
40294030
max_extended_advertising_events : 8,
40304031
}
40314032

4032-
struct DisabledSet {
4033-
advertising_handle : 8,
4034-
_fixed_ = 0x00 : 16, // duration
4035-
_fixed_ = 0x00 : 8, // max_extended_advertising_events
4036-
}
4037-
4038-
packet LeSetExtendedAdvertisingDisable : Command (op_code = LE_SET_EXTENDED_ADVERTISING_ENABLE) {
4039-
_fixed_ = 0x00 : 8, // Enable::DISABLED
4040-
_count_(disabled_sets) : 8,
4041-
disabled_sets : DisabledSet[],
4042-
}
4043-
40444033
packet LeSetExtendedAdvertisingEnable : Command (op_code = LE_SET_EXTENDED_ADVERTISING_ENABLE) {
40454034
enable : Enable,
40464035
_count_(enabled_sets) : 8,
@@ -4051,7 +4040,7 @@ test LeSetExtendedAdvertisingEnable {
40514040
"\x39\x20\x06\x01\x01\x01\x00\x00\x00",
40524041
}
40534042

4054-
test LeSetExtendedAdvertisingDisable {
4043+
test LeSetExtendedAdvertisingEnable {
40554044
"\x39\x20\x06\x00\x01\x01\x00\x00\x00",
40564045
}
40574046

@@ -6530,12 +6519,6 @@ packet LeBatchScanReadResultParameters : LeBatchScan (batch_scan_opcode = READ_R
65306519
batch_scan_data_read : BatchScanDataRead,
65316520
}
65326521

6533-
packet LeBatchScanReadResultParametersCompleteRaw : LeBatchScanComplete (batch_scan_opcode = READ_RESULT_PARAMETERS) {
6534-
batch_scan_data_read : BatchScanDataRead,
6535-
num_of_records : 8,
6536-
raw_data : 8[],
6537-
}
6538-
65396522
packet LeBatchScanReadResultParametersComplete : LeBatchScanComplete (batch_scan_opcode = READ_RESULT_PARAMETERS) {
65406523
batch_scan_data_read : BatchScanDataRead,
65416524
_body_,
@@ -6888,186 +6871,3 @@ packet ControllerDebugInfoEvent : VendorSpecificEvent (subevent_code = CONTROLLE
68886871
_size_(debug_data) : 16,
68896872
debug_data : 8[],
68906873
}
6891-
6892-
// -----------------------------------------------------------------------------
6893-
// Microsoft Commands
6894-
// https://learn.microsoft.com/en-us/windows-hardware/drivers/bluetooth/microsoft-defined-bluetooth-hci-commands-and-events
6895-
// -----------------------------------------------------------------------------
6896-
6897-
enum MsftSubcommandOpcode : 8 {
6898-
MSFT_READ_SUPPORTED_FEATURES = 0x00,
6899-
MSFT_MONITOR_RSSI = 0x01,
6900-
MSFT_CANCEL_MONITOR_RSSI = 0x02,
6901-
MSFT_LE_MONITOR_ADV = 0x03,
6902-
MSFT_LE_CANCEL_MONITOR_ADV = 0x04,
6903-
MSFT_LE_SET_ADV_FILTER_ENABLE = 0x05,
6904-
MSFT_READ_ABSOLUTE_RSSI = 0x06,
6905-
}
6906-
6907-
// MSFT Commands do not have a constant opcode, so leave `op_code` undefined.
6908-
packet MsftCommand : Command {
6909-
subcommand_opcode: MsftSubcommandOpcode,
6910-
_payload_,
6911-
}
6912-
6913-
packet MsftReadSupportedFeatures : MsftCommand (subcommand_opcode = MSFT_READ_SUPPORTED_FEATURES) {}
6914-
6915-
enum MsftLeMonitorAdvConditionType : 8 {
6916-
MSFT_CONDITION_TYPE_PATTERNS = 0x01,
6917-
MSFT_CONDITION_TYPE_UUID = 0x02,
6918-
MSFT_CONDITION_TYPE_IRK_RESOLUTION = 0x03,
6919-
MSFT_CONDITION_TYPE_ADDRESS = 0x04,
6920-
}
6921-
6922-
enum MsftLeMonitorAdvConditionUuidType : 8 {
6923-
MSFT_CONDITION_UUID_TYPE_16_BIT = 0x01,
6924-
MSFT_CONDITION_UUID_TYPE_32_BIT = 0x02,
6925-
MSFT_CONDITION_UUID_TYPE_128_BIT = 0x03,
6926-
}
6927-
6928-
packet MsftLeMonitorAdv : MsftCommand (subcommand_opcode = MSFT_LE_MONITOR_ADV) {
6929-
rssi_threshold_high : 8,
6930-
rssi_threshold_low : 8,
6931-
rssi_threshold_low_time_interval : 8,
6932-
rssi_sampling_period : 8,
6933-
condition_type: MsftLeMonitorAdvConditionType,
6934-
_payload_,
6935-
}
6936-
6937-
struct MsftLeMonitorAdvConditionPattern {
6938-
_size_(pattern) : 8, // including one byte for ad_type and one byte for start_of_pattern
6939-
ad_type: 8,
6940-
start_of_pattern: 8,
6941-
pattern: 8[+2],
6942-
}
6943-
6944-
packet MsftLeMonitorAdvConditionPatterns : MsftLeMonitorAdv (condition_type = MSFT_CONDITION_TYPE_PATTERNS) {
6945-
_count_(patterns): 8,
6946-
patterns: MsftLeMonitorAdvConditionPattern[],
6947-
}
6948-
6949-
test MsftLeMonitorAdvConditionPatterns {
6950-
"\x1e\xfc\x0e\x03\x10\x05\x04\xaa\x01\x01\x06\x03\x00\x80\x81\x82\x83", // 1 pattern
6951-
"\x70\xfd\x13\x03\x15\x04\x02\xbb\x01\x02\x04\x03\x00\x80\x81\x06\x0f\x00\x90\x91\x92\x93", // 2 patterns
6952-
}
6953-
6954-
packet MsftLeMonitorAdvConditionUuid : MsftLeMonitorAdv (condition_type = MSFT_CONDITION_TYPE_UUID) {
6955-
uuid_type: MsftLeMonitorAdvConditionUuidType,
6956-
_payload_,
6957-
}
6958-
6959-
packet MsftLeMonitorAdvConditionUuid2 : MsftLeMonitorAdvConditionUuid (uuid_type = MSFT_CONDITION_UUID_TYPE_16_BIT) {
6960-
uuid2: 8[2],
6961-
}
6962-
6963-
test MsftLeMonitorAdvConditionUuid2 {
6964-
"\x1e\xfc\x09\x03\x10\x11\x12\x13\x02\x01\x70\x71", // opcode = fc1e for Intel
6965-
"\x70\xfd\x09\x03\x10\x11\x12\x13\x02\x01\x70\x71", // opcode = fd70 for Qualcomm
6966-
}
6967-
6968-
packet MsftLeMonitorAdvConditionUuid4 : MsftLeMonitorAdvConditionUuid (uuid_type = MSFT_CONDITION_UUID_TYPE_32_BIT) {
6969-
uuid4: 8[4],
6970-
}
6971-
6972-
test MsftLeMonitorAdvConditionUuid4 {
6973-
"\x1e\xfc\x0b\x03\x10\x11\x12\x13\x02\x02\x70\x71\x72\x73",
6974-
"\x70\xfd\x0b\x03\x10\x11\x12\x13\x02\x02\x70\x71\x72\x73",
6975-
}
6976-
6977-
packet MsftLeMonitorAdvConditionUuid16 : MsftLeMonitorAdvConditionUuid (uuid_type = MSFT_CONDITION_UUID_TYPE_128_BIT) {
6978-
uuid16: 8[16],
6979-
}
6980-
6981-
test MsftLeMonitorAdvConditionUuid16 {
6982-
"\x1e\xfc\x17\x03\x10\x11\x12\x13\x02\x03\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
6983-
"\x70\xfd\x17\x03\x10\x11\x12\x13\x02\x03\x70\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f",
6984-
}
6985-
6986-
packet MsftLeCancelMonitorAdv: MsftCommand (subcommand_opcode = MSFT_LE_CANCEL_MONITOR_ADV) {
6987-
monitor_handle: 8,
6988-
}
6989-
6990-
test MsftLeCancelMonitorAdv {
6991-
"\x1e\xfc\x02\x04\x01", // cancel handle 0x01
6992-
}
6993-
6994-
packet MsftLeSetAdvFilterEnable : MsftCommand (subcommand_opcode = MSFT_LE_SET_ADV_FILTER_ENABLE) {
6995-
enable: 8,
6996-
}
6997-
6998-
test MsftLeSetAdvFilterEnable {
6999-
"\x1e\xfc\x02\x05\x01", // disable
7000-
"\x70\xfd\x02\x05\x01", // enable
7001-
}
7002-
7003-
packet MsftCommandComplete : CommandComplete {
7004-
status: ErrorCode,
7005-
subcommand_opcode: MsftSubcommandOpcode,
7006-
_payload_,
7007-
}
7008-
7009-
packet MsftReadSupportedFeaturesCommandComplete : MsftCommandComplete (subcommand_opcode = MSFT_READ_SUPPORTED_FEATURES) {
7010-
supported_features: 64,
7011-
_size_(prefix) : 8,
7012-
prefix: 8[],
7013-
}
7014-
7015-
test MsftReadSupportedFeaturesCommandComplete {
7016-
"\x0e\x10\x01\x1e\xfc\x00\x00\x7f\x00\x00\x00\x00\x00\x00\x00\x02\x87\x80", // Msft opcode by Intel
7017-
"\x0e\x12\x01\x70\xfd\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x04\x4d\x53\x46\x54", // Msft opcode by Qualcomm
7018-
}
7019-
7020-
packet MsftLeMonitorAdvCommandComplete : MsftCommandComplete (subcommand_opcode = MSFT_LE_MONITOR_ADV) {
7021-
monitor_handle: 8,
7022-
}
7023-
7024-
test MsftLeMonitorAdvCommandComplete {
7025-
"\x0e\x06\x01\x1e\xfc\x00\x03\x05", // succeeded
7026-
"\x0e\x06\x01\x70\xfd\x01\x03\x06", // failed
7027-
}
7028-
7029-
packet MsftLeCancelMonitorAdvCommandComplete : MsftCommandComplete (subcommand_opcode = MSFT_LE_CANCEL_MONITOR_ADV) {}
7030-
7031-
packet MsftLeSetAdvFilterEnableCommandComplete : MsftCommandComplete (subcommand_opcode = MSFT_LE_SET_ADV_FILTER_ENABLE) {}
7032-
7033-
enum MsftEventCode : 8 {
7034-
MSFT_RSSI_EVENT = 0x01,
7035-
MSFT_LE_MONITOR_DEVICE_EVENT = 0x02,
7036-
}
7037-
7038-
enum MsftEventStatus : 8 {
7039-
MSFT_EVENT_STATUS_SUCCESS = 0x00,
7040-
MSFT_EVENT_STATUS_FAILURE = 0x01,
7041-
}
7042-
7043-
// It is not possible to define MSFT Event packet by deriving `Event` packet
7044-
// because it starts with variable-length event prefix which can only be determined
7045-
// at run-time (after receiving return of MSFT Read Supported Features).
7046-
// Therefore we only define the payload which is located after the event prefix.
7047-
packet MsftEventPayload {
7048-
msft_event_code : MsftEventCode,
7049-
_payload_,
7050-
}
7051-
7052-
packet MsftRssiEventPayload : MsftEventPayload (msft_event_code = MSFT_RSSI_EVENT) {
7053-
status: MsftEventStatus,
7054-
connection_handle: 16,
7055-
rssi: 8,
7056-
}
7057-
7058-
test MsftRssiEventPayload {
7059-
"\x01\x00\x01\x10\xf0", // MSFT_RSSI_EVENT succeeded
7060-
"\x01\x01\x02\x02\x08", // MSFT_RSSI_EVENT failed
7061-
}
7062-
7063-
packet MsftLeMonitorDeviceEventPayload : MsftEventPayload (msft_event_code = MSFT_LE_MONITOR_DEVICE_EVENT) {
7064-
address_type: 8,
7065-
bd_addr: Address,
7066-
monitor_handle: 8,
7067-
monitor_state: 8,
7068-
}
7069-
7070-
test MsftLeMonitorDeviceEventPayload {
7071-
"\x02\x01\x00\x01\x02\x03\x04\x05\x10\x00",
7072-
"\x02\x02\xf0\xf1\xf2\xf3\xf4\xf5\xaa\x02",
7073-
}

rust/Cargo.toml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,24 @@ version = "0.1.0"
1919
edition = "2018"
2020
build="build.rs"
2121

22+
[features]
23+
serde = []
24+
2225
[dependencies]
2326
bytes = "1.0.1"
2427
num-bigint = "0.4.3"
2528
num-derive = "0.3.3"
2629
num-integer = "0.1.45"
2730
num-traits = "0.2.14"
2831
paste = "1.0.4"
29-
pdl-runtime = "0.3.0"
32+
pdl-derive = "0.4.2"
33+
pdl-runtime = "0.4.2"
3034
pin-utils = "0.1.0"
31-
rand = "0.9.1"
35+
rand = "0.8.3"
3236
thiserror = "1.0.23"
3337

3438
[build-dependencies]
35-
pdl-compiler = "0.3.2"
39+
pdl-compiler = "0.4.2"
3640

3741
[lib]
3842
path="src/lib.rs"

rust/build.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ fn generate_module(in_file: &Path) {
4141
)
4242
.expect("PDL parse failed");
4343
let analyzed_file = pdl_compiler::analyzer::analyze(&parsed_file).expect("PDL analysis failed");
44-
let rust_source = pdl_compiler::backends::rust_legacy::generate(&sources, &analyzed_file);
45-
out_file
46-
.write_all(rust_source.as_bytes())
47-
.expect("Could not write to output file");
44+
let rust_source = pdl_compiler::backends::rust::generate(&sources, &analyzed_file, &[]);
45+
out_file.write_all(rust_source.as_bytes()).expect("Could not write to output file");
4846
}

0 commit comments

Comments
 (0)