blob: 75b87b003dade56ddd449a728d138f1d47449280 [file] [log] [blame]
Myles Watsone22dde22019-01-18 11:42:33 -08001/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Myles Watsone22dde22019-01-18 11:42:33 -080017#include "dual_mode_controller.h"
18
19#include <memory>
20
21#include <base/files/file_util.h>
22#include <base/json/json_reader.h>
Myles Watsone22dde22019-01-18 11:42:33 -080023#include <base/values.h>
24
Myles Watson1a0a0da2019-10-17 11:36:33 -070025#include "os/log.h"
Chienyuan3d8a8032019-11-01 18:04:07 +080026#include "packet/raw_builder.h"
Myles Watsone22dde22019-01-18 11:42:33 -080027
28#include "hci.h"
Myles Watsone22dde22019-01-18 11:42:33 -080029#include "packets/hci/command_packet_view.h"
Chienyuan85db6ee2019-11-21 22:07:09 +080030#include "packets/packet_view.h"
Myles Watsone22dde22019-01-18 11:42:33 -080031
32using std::vector;
33using test_vendor_lib::hci::EventCode;
34using test_vendor_lib::hci::OpCode;
35
36namespace {
37
38size_t LastNonZero(test_vendor_lib::packets::PacketView<true> view) {
39 for (size_t i = view.size() - 1; i > 0; i--) {
40 if (view[i] != 0) {
41 return i;
42 }
43 }
44 return 0;
45}
46
47} // namespace
48
49namespace test_vendor_lib {
50constexpr char DualModeController::kControllerPropertiesFile[];
51constexpr uint16_t DualModeController::kSecurityManagerNumKeys;
Chienyuanc27da092019-11-20 19:29:43 +080052constexpr uint16_t kNumCommandPackets = 0x01;
Myles Watsone22dde22019-01-18 11:42:33 -080053
54// Device methods.
55void DualModeController::Initialize(const std::vector<std::string>& args) {
56 if (args.size() < 2) return;
57
58 Address addr;
Hansong Zhang106fc602019-06-19 16:53:15 -070059 if (Address::FromString(args[1], addr)) {
60 properties_.SetAddress(addr);
61 } else {
Myles Watson1a0a0da2019-10-17 11:36:33 -070062 LOG_ALWAYS_FATAL("Invalid address: %s", args[1].c_str());
Hansong Zhang106fc602019-06-19 16:53:15 -070063 }
Myles Watsone22dde22019-01-18 11:42:33 -080064};
65
66std::string DualModeController::GetTypeString() const {
67 return "Simulated Bluetooth Controller";
68}
69
Chienyuandb55f312019-10-31 14:01:28 +080070void DualModeController::IncomingPacket(
71 model::packets::LinkLayerPacketView incoming) {
Myles Watsone22dde22019-01-18 11:42:33 -080072 link_layer_controller_.IncomingPacket(incoming);
73}
74
75void DualModeController::TimerTick() {
76 link_layer_controller_.TimerTick();
77}
78
Myles Watsone22dde22019-01-18 11:42:33 -080079void DualModeController::SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const {
Chienyuan3d8a8032019-11-01 18:04:07 +080080 std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
81 std::make_unique<bluetooth::packet::RawBuilder>();
Chienyuanc27da092019-11-20 19:29:43 +080082 raw_builder_ptr->AddOctets1(kNumCommandPackets);
Chienyuan3d8a8032019-11-01 18:04:07 +080083 raw_builder_ptr->AddOctets2(command_opcode);
84 raw_builder_ptr->AddOctets1(
85 static_cast<uint8_t>(bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND));
86
87 auto packet = bluetooth::hci::EventPacketBuilder::Create(
88 bluetooth::hci::EventCode::COMMAND_COMPLETE, std::move(raw_builder_ptr));
89 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -080090}
91
Myles Watsone22dde22019-01-18 11:42:33 -080092DualModeController::DualModeController(const std::string& properties_filename, uint16_t num_keys)
93 : Device(properties_filename), security_manager_(num_keys) {
94 loopback_mode_ = hci::LoopbackMode::NO;
95
96 Address public_address;
Myles Watson1a0a0da2019-10-17 11:36:33 -070097 ASSERT(Address::FromString("3C:5A:B4:04:05:06", public_address));
Myles Watsone22dde22019-01-18 11:42:33 -080098 properties_.SetAddress(public_address);
99
100 link_layer_controller_.RegisterRemoteChannel(
Chienyuandb55f312019-10-31 14:01:28 +0800101 [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet,
102 Phy::Type phy_type) {
Myles Watsone22dde22019-01-18 11:42:33 -0800103 DualModeController::SendLinkLayerPacket(packet, phy_type);
104 });
105
106#define SET_HANDLER(opcode, method) \
107 active_hci_commands_[static_cast<uint16_t>(opcode)] = [this](packets::PacketView<true> param) { method(param); };
108 SET_HANDLER(OpCode::RESET, HciReset);
109 SET_HANDLER(OpCode::READ_BUFFER_SIZE, HciReadBufferSize);
110 SET_HANDLER(OpCode::HOST_BUFFER_SIZE, HciHostBufferSize);
111 SET_HANDLER(OpCode::SNIFF_SUBRATING, HciSniffSubrating);
Calvin Huang63a08962019-10-31 19:12:25 -0700112 SET_HANDLER(OpCode::READ_ENCRYPTION_KEY_SIZE, HciReadEncryptionKeySize);
Myles Watsone22dde22019-01-18 11:42:33 -0800113 SET_HANDLER(OpCode::READ_LOCAL_VERSION_INFORMATION, HciReadLocalVersionInformation);
114 SET_HANDLER(OpCode::READ_BD_ADDR, HciReadBdAddr);
115 SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_COMMANDS, HciReadLocalSupportedCommands);
Myles Watson1a0a0da2019-10-17 11:36:33 -0700116 SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_FEATURES, HciReadLocalSupportedFeatures);
Myles Watsone22dde22019-01-18 11:42:33 -0800117 SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_CODECS, HciReadLocalSupportedCodecs);
118 SET_HANDLER(OpCode::READ_LOCAL_EXTENDED_FEATURES, HciReadLocalExtendedFeatures);
119 SET_HANDLER(OpCode::READ_REMOTE_EXTENDED_FEATURES, HciReadRemoteExtendedFeatures);
Chienyuan9145e7a2019-10-02 15:18:55 +0800120 SET_HANDLER(OpCode::SWITCH_ROLE, HciSwitchRole);
Myles Watsone22dde22019-01-18 11:42:33 -0800121 SET_HANDLER(OpCode::READ_REMOTE_SUPPORTED_FEATURES, HciReadRemoteSupportedFeatures);
122 SET_HANDLER(OpCode::READ_CLOCK_OFFSET, HciReadClockOffset);
123 SET_HANDLER(OpCode::IO_CAPABILITY_REQUEST_REPLY, HciIoCapabilityRequestReply);
124 SET_HANDLER(OpCode::USER_CONFIRMATION_REQUEST_REPLY, HciUserConfirmationRequestReply);
125 SET_HANDLER(OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, HciUserConfirmationRequestNegativeReply);
126 SET_HANDLER(OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, HciIoCapabilityRequestNegativeReply);
127 SET_HANDLER(OpCode::WRITE_SIMPLE_PAIRING_MODE, HciWriteSimplePairingMode);
128 SET_HANDLER(OpCode::WRITE_LE_HOST_SUPPORT, HciWriteLeHostSupport);
Calvin Huang63a08962019-10-31 19:12:25 -0700129 SET_HANDLER(OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT,
Chienyuanc27da092019-11-20 19:29:43 +0800130 HciWriteSecureConnectionsHostSupport);
Myles Watsone22dde22019-01-18 11:42:33 -0800131 SET_HANDLER(OpCode::SET_EVENT_MASK, HciSetEventMask);
132 SET_HANDLER(OpCode::WRITE_INQUIRY_MODE, HciWriteInquiryMode);
133 SET_HANDLER(OpCode::WRITE_PAGE_SCAN_TYPE, HciWritePageScanType);
134 SET_HANDLER(OpCode::WRITE_INQUIRY_SCAN_TYPE, HciWriteInquiryScanType);
135 SET_HANDLER(OpCode::AUTHENTICATION_REQUESTED, HciAuthenticationRequested);
136 SET_HANDLER(OpCode::SET_CONNECTION_ENCRYPTION, HciSetConnectionEncryption);
Chienyuanad340b02019-09-25 19:23:21 +0800137 SET_HANDLER(OpCode::CHANGE_CONNECTION_LINK_KEY, HciChangeConnectionLinkKey);
Chienyuan9145e7a2019-10-02 15:18:55 +0800138 SET_HANDLER(OpCode::MASTER_LINK_KEY, HciMasterLinkKey);
Myles Watsone22dde22019-01-18 11:42:33 -0800139 SET_HANDLER(OpCode::WRITE_AUTHENTICATION_ENABLE, HciWriteAuthenticationEnable);
140 SET_HANDLER(OpCode::READ_AUTHENTICATION_ENABLE, HciReadAuthenticationEnable);
141 SET_HANDLER(OpCode::WRITE_CLASS_OF_DEVICE, HciWriteClassOfDevice);
142 SET_HANDLER(OpCode::WRITE_PAGE_TIMEOUT, HciWritePageTimeout);
143 SET_HANDLER(OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, HciWriteLinkSupervisionTimeout);
Chienyuanad340b02019-09-25 19:23:21 +0800144 SET_HANDLER(OpCode::HOLD_MODE, HciHoldMode);
145 SET_HANDLER(OpCode::SNIFF_MODE, HciSniffMode);
146 SET_HANDLER(OpCode::EXIT_SNIFF_MODE, HciExitSniffMode);
147 SET_HANDLER(OpCode::QOS_SETUP, HciQosSetup);
Myles Watsone22dde22019-01-18 11:42:33 -0800148 SET_HANDLER(OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS, HciWriteDefaultLinkPolicySettings);
Chienyuanad340b02019-09-25 19:23:21 +0800149 SET_HANDLER(OpCode::FLOW_SPECIFICATION, HciFlowSpecification);
Myles Watsone22dde22019-01-18 11:42:33 -0800150 SET_HANDLER(OpCode::WRITE_LINK_POLICY_SETTINGS, HciWriteLinkPolicySettings);
151 SET_HANDLER(OpCode::CHANGE_CONNECTION_PACKET_TYPE, HciChangeConnectionPacketType);
152 SET_HANDLER(OpCode::WRITE_LOCAL_NAME, HciWriteLocalName);
153 SET_HANDLER(OpCode::READ_LOCAL_NAME, HciReadLocalName);
154 SET_HANDLER(OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, HciWriteExtendedInquiryResponse);
Myles Watsonb293d732019-08-19 12:35:36 -0700155 SET_HANDLER(OpCode::REFRESH_ENCRYPTION_KEY, HciRefreshEncryptionKey);
Myles Watsone22dde22019-01-18 11:42:33 -0800156 SET_HANDLER(OpCode::WRITE_VOICE_SETTING, HciWriteVoiceSetting);
157 SET_HANDLER(OpCode::WRITE_CURRENT_IAC_LAP, HciWriteCurrentIacLap);
158 SET_HANDLER(OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, HciWriteInquiryScanActivity);
159 SET_HANDLER(OpCode::WRITE_SCAN_ENABLE, HciWriteScanEnable);
160 SET_HANDLER(OpCode::SET_EVENT_FILTER, HciSetEventFilter);
161 SET_HANDLER(OpCode::INQUIRY, HciInquiry);
162 SET_HANDLER(OpCode::INQUIRY_CANCEL, HciInquiryCancel);
163 SET_HANDLER(OpCode::ACCEPT_CONNECTION_REQUEST, HciAcceptConnectionRequest);
164 SET_HANDLER(OpCode::REJECT_CONNECTION_REQUEST, HciRejectConnectionRequest);
165 SET_HANDLER(OpCode::LINK_KEY_REQUEST_REPLY, HciLinkKeyRequestReply);
166 SET_HANDLER(OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, HciLinkKeyRequestNegativeReply);
167 SET_HANDLER(OpCode::DELETE_STORED_LINK_KEY, HciDeleteStoredLinkKey);
168 SET_HANDLER(OpCode::REMOTE_NAME_REQUEST, HciRemoteNameRequest);
169 SET_HANDLER(OpCode::LE_SET_EVENT_MASK, HciLeSetEventMask);
170 SET_HANDLER(OpCode::LE_READ_BUFFER_SIZE, HciLeReadBufferSize);
171 SET_HANDLER(OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES, HciLeReadLocalSupportedFeatures);
172 SET_HANDLER(OpCode::LE_SET_RANDOM_ADDRESS, HciLeSetRandomAddress);
Myles Watsone22dde22019-01-18 11:42:33 -0800173 SET_HANDLER(OpCode::LE_SET_ADVERTISING_PARAMETERS, HciLeSetAdvertisingParameters);
Myles Watson99aea892019-09-02 15:54:08 -0700174 SET_HANDLER(OpCode::LE_SET_ADVERTISING_DATA, HciLeSetAdvertisingData);
175 SET_HANDLER(OpCode::LE_SET_SCAN_RESPONSE_DATA, HciLeSetScanResponseData);
176 SET_HANDLER(OpCode::LE_SET_ADVERTISING_ENABLE, HciLeSetAdvertisingEnable);
Myles Watsone22dde22019-01-18 11:42:33 -0800177 SET_HANDLER(OpCode::LE_SET_SCAN_PARAMETERS, HciLeSetScanParameters);
178 SET_HANDLER(OpCode::LE_SET_SCAN_ENABLE, HciLeSetScanEnable);
179 SET_HANDLER(OpCode::LE_CREATE_CONNECTION, HciLeCreateConnection);
180 SET_HANDLER(OpCode::CREATE_CONNECTION, HciCreateConnection);
181 SET_HANDLER(OpCode::DISCONNECT, HciDisconnect);
182 SET_HANDLER(OpCode::LE_CREATE_CONNECTION_CANCEL, HciLeConnectionCancel);
183 SET_HANDLER(OpCode::LE_READ_WHITE_LIST_SIZE, HciLeReadWhiteListSize);
184 SET_HANDLER(OpCode::LE_CLEAR_WHITE_LIST, HciLeClearWhiteList);
185 SET_HANDLER(OpCode::LE_ADD_DEVICE_TO_WHITE_LIST, HciLeAddDeviceToWhiteList);
186 SET_HANDLER(OpCode::LE_REMOVE_DEVICE_FROM_WHITE_LIST, HciLeRemoveDeviceFromWhiteList);
187 SET_HANDLER(OpCode::LE_RAND, HciLeRand);
188 SET_HANDLER(OpCode::LE_READ_SUPPORTED_STATES, HciLeReadSupportedStates);
189 SET_HANDLER(OpCode::LE_GET_VENDOR_CAPABILITIES, HciLeVendorCap);
190 SET_HANDLER(OpCode::LE_MULTI_ADVT, HciLeVendorMultiAdv);
191 SET_HANDLER(OpCode::LE_ADV_FILTER, HciLeAdvertisingFilter);
192 SET_HANDLER(OpCode::LE_ENERGY_INFO, HciLeEnergyInfo);
193 SET_HANDLER(OpCode::LE_EXTENDED_SCAN_PARAMS, HciLeExtendedScanParams);
194 SET_HANDLER(OpCode::LE_READ_REMOTE_FEATURES, HciLeReadRemoteFeatures);
195 SET_HANDLER(OpCode::READ_REMOTE_VERSION_INFORMATION, HciReadRemoteVersionInformation);
196 SET_HANDLER(OpCode::LE_CONNECTION_UPDATE, HciLeConnectionUpdate);
197 SET_HANDLER(OpCode::LE_START_ENCRYPTION, HciLeStartEncryption);
Calvin Huangee1980c2019-11-01 16:35:55 -0700198 SET_HANDLER(OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST,
199 HciLeAddDeviceToResolvingList);
200 SET_HANDLER(OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST,
201 HciLeRemoveDeviceFromResolvingList);
202 SET_HANDLER(OpCode::LE_CLEAR_RESOLVING_LIST, HciLeClearResolvingList);
203 SET_HANDLER(OpCode::LE_SET_PRIVACY_MODE, HciLeSetPrivacyMode);
Myles Watsone22dde22019-01-18 11:42:33 -0800204 // Testing Commands
205 SET_HANDLER(OpCode::READ_LOOPBACK_MODE, HciReadLoopbackMode);
206 SET_HANDLER(OpCode::WRITE_LOOPBACK_MODE, HciWriteLoopbackMode);
207#undef SET_HANDLER
208}
209
210void DualModeController::HciSniffSubrating(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700211 ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800212
213 uint16_t handle = args.begin().extract<uint16_t>();
214
Chienyuan3d8a8032019-11-01 18:04:07 +0800215 auto packet = bluetooth::hci::SniffSubratingCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800216 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle);
Chienyuan3d8a8032019-11-01 18:04:07 +0800217 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800218}
219
220void DualModeController::RegisterTaskScheduler(
221 std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> oneshot_scheduler) {
222 link_layer_controller_.RegisterTaskScheduler(oneshot_scheduler);
223}
224
225void DualModeController::RegisterPeriodicTaskScheduler(
226 std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)>
227 periodic_scheduler) {
228 link_layer_controller_.RegisterPeriodicTaskScheduler(periodic_scheduler);
229}
230
231void DualModeController::RegisterTaskCancel(std::function<void(AsyncTaskId)> task_cancel) {
232 link_layer_controller_.RegisterTaskCancel(task_cancel);
233}
234
235void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) {
Chienyuan85db6ee2019-11-21 22:07:09 +0800236 bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet);
237 auto acl_packet = bluetooth::hci::AclPacketView::Create(raw_packet);
238 ASSERT(acl_packet.IsValid());
Myles Watsone22dde22019-01-18 11:42:33 -0800239 if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
240 uint16_t handle = acl_packet.GetHandle();
Chienyuan3d8a8032019-11-01 18:04:07 +0800241
Chienyuanc27da092019-11-20 19:29:43 +0800242 std::vector<bluetooth::hci::CompletedPackets> completed_packets;
243 bluetooth::hci::CompletedPackets cp;
244 cp.connection_handle_ = handle;
245 cp.host_num_of_completed_packets_ = kNumCommandPackets;
246 completed_packets.push_back(cp);
247 auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
248 completed_packets);
Chienyuan3d8a8032019-11-01 18:04:07 +0800249 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800250 return;
251 }
252
253 link_layer_controller_.SendAclToRemote(acl_packet);
254}
255
256void DualModeController::HandleSco(std::shared_ptr<std::vector<uint8_t>> packet) {
Chienyuan85db6ee2019-11-21 22:07:09 +0800257 bluetooth::hci::PacketView<bluetooth::hci::kLittleEndian> raw_packet(packet);
258 auto sco_packet = bluetooth::hci::ScoPacketView::Create(raw_packet);
Myles Watsone22dde22019-01-18 11:42:33 -0800259 if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
260 uint16_t handle = sco_packet.GetHandle();
261 send_sco_(packet);
Chienyuanc27da092019-11-20 19:29:43 +0800262 std::vector<bluetooth::hci::CompletedPackets> completed_packets;
263 bluetooth::hci::CompletedPackets cp;
264 cp.connection_handle_ = handle;
265 cp.host_num_of_completed_packets_ = kNumCommandPackets;
266 completed_packets.push_back(cp);
267 auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create(
268 completed_packets);
Chienyuan3d8a8032019-11-01 18:04:07 +0800269 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800270 return;
271 }
272}
273
Jakub Pawlowskide6c0132019-11-12 16:14:32 +0100274void DualModeController::HandleIso(
275 std::shared_ptr<std::vector<uint8_t>> /* packet */) {
276 // TODO: implement handling similar to HandleSco
277}
278
Myles Watsone22dde22019-01-18 11:42:33 -0800279void DualModeController::HandleCommand(std::shared_ptr<std::vector<uint8_t>> packet) {
280 auto command_packet = packets::CommandPacketView::Create(packet);
281 uint16_t opcode = command_packet.GetOpcode();
282 hci::OpCode op = static_cast<hci::OpCode>(opcode);
283
284 if (loopback_mode_ == hci::LoopbackMode::LOCAL &&
285 // Loopback exceptions.
286 op != OpCode::RESET && op != OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL && op != OpCode::HOST_BUFFER_SIZE &&
287 op != OpCode::HOST_NUM_COMPLETED_PACKETS && op != OpCode::READ_BUFFER_SIZE && op != OpCode::READ_LOOPBACK_MODE &&
288 op != OpCode::WRITE_LOOPBACK_MODE) {
Chienyuan3d8a8032019-11-01 18:04:07 +0800289 std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
290 std::make_unique<bluetooth::packet::RawBuilder>();
291 raw_builder_ptr->AddOctets(*packet);
292 auto packet = bluetooth::hci::LoopbackCommandBuilder::Create(
293 std::move(raw_builder_ptr));
294 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800295 } else if (active_hci_commands_.count(opcode) > 0) {
296 active_hci_commands_[opcode](command_packet.GetPayload());
297 } else {
298 SendCommandCompleteUnknownOpCodeEvent(opcode);
Chienyuan3d8a8032019-11-01 18:04:07 +0800299 LOG_INFO("Unknown command, opcode: 0x%04X, OGF: 0x%04X, OCF: 0x%04X",
300 opcode, (opcode & 0xFC00) >> 10, opcode & 0x03FF);
Myles Watsone22dde22019-01-18 11:42:33 -0800301 }
302}
303
304void DualModeController::RegisterEventChannel(
305 const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) {
Chienyuan3d8a8032019-11-01 18:04:07 +0800306 send_event_ =
307 [callback](std::shared_ptr<bluetooth::hci::EventPacketBuilder> event) {
308 auto bytes = std::make_shared<std::vector<uint8_t>>();
309 bluetooth::packet::BitInserter bit_inserter(*bytes);
310 bytes->reserve(event->size());
311 event->Serialize(bit_inserter);
312 callback(std::move(bytes));
313 };
314 link_layer_controller_.RegisterEventChannel(send_event_);
Myles Watsone22dde22019-01-18 11:42:33 -0800315}
316
317void DualModeController::RegisterAclChannel(
318 const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) {
Chienyuan85db6ee2019-11-21 22:07:09 +0800319 send_acl_ =
320 [callback](std::shared_ptr<bluetooth::hci::AclPacketBuilder> acl_data) {
321 auto bytes = std::make_shared<std::vector<uint8_t>>();
322 bluetooth::packet::BitInserter bit_inserter(*bytes);
323 bytes->reserve(acl_data->size());
324 acl_data->Serialize(bit_inserter);
325 callback(std::move(bytes));
326 };
327 link_layer_controller_.RegisterAclChannel(send_acl_);
Myles Watsone22dde22019-01-18 11:42:33 -0800328}
329
330void DualModeController::RegisterScoChannel(
331 const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) {
332 link_layer_controller_.RegisterScoChannel(callback);
333 send_sco_ = callback;
334}
335
Jakub Pawlowskide6c0132019-11-12 16:14:32 +0100336void DualModeController::RegisterIsoChannel(
337 const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>&
338 callback) {
339 link_layer_controller_.RegisterIsoChannel(callback);
340 send_iso_ = callback;
341}
342
Myles Watsone22dde22019-01-18 11:42:33 -0800343void DualModeController::HciReset(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700344 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800345 link_layer_controller_.Reset();
Hansong Zhang843271b2019-04-30 10:51:27 -0700346 if (loopback_mode_ == hci::LoopbackMode::LOCAL) {
347 loopback_mode_ = hci::LoopbackMode::NO;
348 }
Myles Watsone22dde22019-01-18 11:42:33 -0800349
Myles Watsone066df42019-11-13 14:39:18 -0800350 send_event_(bluetooth::hci::ResetCompleteBuilder::Create(
351 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS));
Myles Watsone22dde22019-01-18 11:42:33 -0800352}
353
354void DualModeController::HciReadBufferSize(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700355 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800356
Chienyuan3d8a8032019-11-01 18:04:07 +0800357 auto packet = bluetooth::hci::ReadBufferSizeCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800358 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +0800359 properties_.GetAclDataPacketSize(),
360 properties_.GetSynchronousDataPacketSize(),
361 properties_.GetTotalNumAclDataPackets(),
362 properties_.GetTotalNumSynchronousDataPackets());
363 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800364}
365
Calvin Huang63a08962019-10-31 19:12:25 -0700366void DualModeController::HciReadEncryptionKeySize(
367 packets::PacketView<true> args) {
368 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
369
370 uint16_t handle = args.begin().extract<uint16_t>();
371
Chienyuan3d8a8032019-11-01 18:04:07 +0800372 auto packet = bluetooth::hci::ReadEncryptionKeySizeCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800373 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle,
Chienyuan3d8a8032019-11-01 18:04:07 +0800374 properties_.GetEncryptionKeySize());
375 send_event_(std::move(packet));
Calvin Huang63a08962019-10-31 19:12:25 -0700376}
377
Myles Watsone22dde22019-01-18 11:42:33 -0800378void DualModeController::HciHostBufferSize(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700379 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800380 auto packet = bluetooth::hci::HostBufferSizeCompleteBuilder::Create(
381 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
382 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800383}
384
385void DualModeController::HciReadLocalVersionInformation(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700386 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800387
Chienyuanc27da092019-11-20 19:29:43 +0800388 bluetooth::hci::LocalVersionInformation local_version_information;
389 local_version_information.hci_version_ =
390 static_cast<bluetooth::hci::HciVersion>(properties_.GetVersion());
391 local_version_information.hci_revision_ = properties_.GetRevision();
392 local_version_information.lmp_version_ =
393 static_cast<bluetooth::hci::LmpVersion>(properties_.GetLmpPalVersion());
394 local_version_information.manufacturer_name_ =
395 properties_.GetManufacturerName();
396 local_version_information.lmp_subversion_ = properties_.GetLmpPalSubversion();
397 auto packet =
398 bluetooth::hci::ReadLocalVersionInformationCompleteBuilder::Create(
399 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
400 local_version_information);
Chienyuan3d8a8032019-11-01 18:04:07 +0800401 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800402}
403
404void DualModeController::HciReadRemoteVersionInformation(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700405 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800406
407 uint16_t handle = args.begin().extract<uint16_t>();
408
Chienyuan3d8a8032019-11-01 18:04:07 +0800409 auto status = link_layer_controller_.SendCommandToRemoteByHandle(
410 bluetooth::hci::OpCode::READ_REMOTE_VERSION_INFORMATION, args, handle);
Myles Watsone22dde22019-01-18 11:42:33 -0800411
Chienyuanc27da092019-11-20 19:29:43 +0800412 auto packet =
413 bluetooth::hci::ReadRemoteVersionInformationStatusBuilder::Create(
414 status, kNumCommandPackets);
415 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800416}
417
418void DualModeController::HciReadBdAddr(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700419 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800420 auto packet = bluetooth::hci::ReadBdAddrCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800421 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
422 properties_.GetAddress());
Chienyuan3d8a8032019-11-01 18:04:07 +0800423 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800424}
425
426void DualModeController::HciReadLocalSupportedCommands(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700427 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800428
429 std::array<uint8_t, 64> supported_commands;
430 supported_commands.fill(0x00);
431 size_t len = properties_.GetSupportedCommands().size();
432 if (len > 64) {
433 len = 64;
434 }
435 std::copy_n(properties_.GetSupportedCommands().begin(), len,
436 supported_commands.begin());
437
438 auto packet =
439 bluetooth::hci::ReadLocalSupportedCommandsCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800440 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
441 supported_commands);
Chienyuan3d8a8032019-11-01 18:04:07 +0800442 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800443}
444
Myles Watson1a0a0da2019-10-17 11:36:33 -0700445void DualModeController::HciReadLocalSupportedFeatures(packets::PacketView<true> args) {
446 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800447 auto packet =
448 bluetooth::hci::ReadLocalSupportedFeaturesCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800449 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +0800450 properties_.GetSupportedFeatures());
451 send_event_(std::move(packet));
Myles Watson14d56862019-08-19 13:03:46 -0700452}
453
Myles Watsone22dde22019-01-18 11:42:33 -0800454void DualModeController::HciReadLocalSupportedCodecs(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700455 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800456 auto packet = bluetooth::hci::ReadLocalSupportedCodecsCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800457 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +0800458 properties_.GetSupportedCodecs(), properties_.GetVendorSpecificCodecs());
459 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800460}
461
462void DualModeController::HciReadLocalExtendedFeatures(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700463 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800464 uint8_t page_number = args.begin().extract<uint8_t>();
Chienyuan3d8a8032019-11-01 18:04:07 +0800465
466 auto pakcet =
467 bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800468 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, page_number,
Chienyuan3d8a8032019-11-01 18:04:07 +0800469 properties_.GetExtendedFeaturesMaximumPageNumber(),
470 properties_.GetExtendedFeatures(page_number));
471 send_event_(std::move(pakcet));
Myles Watsone22dde22019-01-18 11:42:33 -0800472}
473
474void DualModeController::HciReadRemoteExtendedFeatures(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700475 ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800476
477 uint16_t handle = args.begin().extract<uint16_t>();
478
Chienyuan3d8a8032019-11-01 18:04:07 +0800479 auto status = link_layer_controller_.SendCommandToRemoteByHandle(
480 bluetooth::hci::OpCode::READ_REMOTE_EXTENDED_FEATURES, args, handle);
Myles Watsone22dde22019-01-18 11:42:33 -0800481
Chienyuanc27da092019-11-20 19:29:43 +0800482 auto packet = bluetooth::hci::ReadRemoteExtendedFeaturesStatusBuilder::Create(
483 status, kNumCommandPackets);
484 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800485}
486
Chienyuan9145e7a2019-10-02 15:18:55 +0800487void DualModeController::HciSwitchRole(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700488 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Chienyuan9145e7a2019-10-02 15:18:55 +0800489
490 Address address = args.begin().extract<Address>();
491 uint8_t role = args.begin().extract<uint8_t>();
492
Chienyuan3d8a8032019-11-01 18:04:07 +0800493 auto status = link_layer_controller_.SwitchRole(address, role);
Chienyuan9145e7a2019-10-02 15:18:55 +0800494
Chienyuanc27da092019-11-20 19:29:43 +0800495 auto packet = bluetooth::hci::SwitchRoleStatusBuilder::Create(
496 status, kNumCommandPackets);
497 send_event_(std::move(packet));
Chienyuan9145e7a2019-10-02 15:18:55 +0800498}
499
Myles Watsone22dde22019-01-18 11:42:33 -0800500void DualModeController::HciReadRemoteSupportedFeatures(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700501 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800502
503 uint16_t handle = args.begin().extract<uint16_t>();
504
Chienyuan3d8a8032019-11-01 18:04:07 +0800505 auto status = link_layer_controller_.SendCommandToRemoteByHandle(
506 bluetooth::hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES, args, handle);
Myles Watsone22dde22019-01-18 11:42:33 -0800507
Chienyuanc27da092019-11-20 19:29:43 +0800508 auto packet =
509 bluetooth::hci::ReadRemoteSupportedFeaturesStatusBuilder::Create(
510 status, kNumCommandPackets);
511 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800512}
513
514void DualModeController::HciReadClockOffset(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700515 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800516
517 uint16_t handle = args.begin().extract<uint16_t>();
518
Chienyuan3d8a8032019-11-01 18:04:07 +0800519 auto status = link_layer_controller_.SendCommandToRemoteByHandle(
520 bluetooth::hci::OpCode::READ_CLOCK_OFFSET, args, handle);
Myles Watsone22dde22019-01-18 11:42:33 -0800521
Chienyuanc27da092019-11-20 19:29:43 +0800522 auto packet = bluetooth::hci::ReadClockOffsetStatusBuilder::Create(
523 status, kNumCommandPackets);
524 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800525}
526
527void DualModeController::HciIoCapabilityRequestReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700528 ASSERT_LOG(args.size() == 9, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800529
530 auto args_itr = args.begin();
531 Address peer = args_itr.extract<Address>();
532 uint8_t io_capability = args_itr.extract<uint8_t>();
533 uint8_t oob_data_present_flag = args_itr.extract<uint8_t>();
534 uint8_t authentication_requirements = args_itr.extract<uint8_t>();
535
Chienyuan3d8a8032019-11-01 18:04:07 +0800536 auto status = link_layer_controller_.IoCapabilityRequestReply(
537 peer, io_capability, oob_data_present_flag, authentication_requirements);
538 auto packet = bluetooth::hci::IoCapabilityRequestReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800539 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800540
Chienyuan3d8a8032019-11-01 18:04:07 +0800541 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800542}
543
544void DualModeController::HciUserConfirmationRequestReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700545 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800546
547 Address peer = args.begin().extract<Address>();
548
Chienyuan3d8a8032019-11-01 18:04:07 +0800549 auto status = link_layer_controller_.UserConfirmationRequestReply(peer);
550 auto packet =
551 bluetooth::hci::UserConfirmationRequestReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800552 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800553
Chienyuan3d8a8032019-11-01 18:04:07 +0800554 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800555}
556
557void DualModeController::HciUserConfirmationRequestNegativeReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700558 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800559
560 Address peer = args.begin().extract<Address>();
561
Chienyuan3d8a8032019-11-01 18:04:07 +0800562 auto status =
563 link_layer_controller_.UserConfirmationRequestNegativeReply(peer);
564 auto packet =
565 bluetooth::hci::UserConfirmationRequestNegativeReplyCompleteBuilder::
Chienyuanc27da092019-11-20 19:29:43 +0800566 Create(kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800567
Chienyuan3d8a8032019-11-01 18:04:07 +0800568 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800569}
570
571void DualModeController::HciUserPasskeyRequestReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700572 ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800573
574 auto args_itr = args.begin();
575 Address peer = args_itr.extract<Address>();
576 uint32_t numeric_value = args_itr.extract<uint32_t>();
577
Chienyuan3d8a8032019-11-01 18:04:07 +0800578 auto status =
579 link_layer_controller_.UserPasskeyRequestReply(peer, numeric_value);
580 auto packet = bluetooth::hci::UserPasskeyRequestReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800581 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800582
Chienyuan3d8a8032019-11-01 18:04:07 +0800583 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800584}
585
586void DualModeController::HciUserPasskeyRequestNegativeReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700587 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800588
589 Address peer = args.begin().extract<Address>();
590
Chienyuan3d8a8032019-11-01 18:04:07 +0800591 auto status = link_layer_controller_.UserPasskeyRequestNegativeReply(peer);
592 auto packet =
593 bluetooth::hci::UserPasskeyRequestNegativeReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800594 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800595
Chienyuan3d8a8032019-11-01 18:04:07 +0800596 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800597}
598
599void DualModeController::HciRemoteOobDataRequestReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700600 ASSERT_LOG(args.size() == 38, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800601
602 auto args_itr = args.begin();
603 Address peer = args_itr.extract<Address>();
604 std::vector<uint8_t> c;
605 std::vector<uint8_t> r;
606 for (size_t i = 0; i < 16; i++) {
607 c.push_back(args_itr.extract<uint8_t>());
608 }
609 for (size_t i = 0; i < 16; i++) {
610 r.push_back(args_itr.extract<uint8_t>());
611 }
Chienyuan3d8a8032019-11-01 18:04:07 +0800612 auto status = link_layer_controller_.RemoteOobDataRequestReply(peer, c, r);
613 auto packet =
614 bluetooth::hci::RemoteOobDataRequestReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800615 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800616
Chienyuan3d8a8032019-11-01 18:04:07 +0800617 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800618}
619
620void DualModeController::HciRemoteOobDataRequestNegativeReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700621 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800622
623 Address peer = args.begin().extract<Address>();
624
Chienyuan3d8a8032019-11-01 18:04:07 +0800625 auto status = link_layer_controller_.RemoteOobDataRequestNegativeReply(peer);
626 auto packet =
627 bluetooth::hci::RemoteOobDataRequestNegativeReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800628 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800629
Chienyuan3d8a8032019-11-01 18:04:07 +0800630 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800631}
632
633void DualModeController::HciIoCapabilityRequestNegativeReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700634 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800635
636 auto args_itr = args.begin();
637 Address peer = args_itr.extract<Address>();
638 hci::Status reason = args_itr.extract<hci::Status>();
639
Chienyuan3d8a8032019-11-01 18:04:07 +0800640 auto status =
641 link_layer_controller_.IoCapabilityRequestNegativeReply(peer, reason);
642 auto packet =
643 bluetooth::hci::IoCapabilityRequestNegativeReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800644 kNumCommandPackets, status, peer);
Myles Watsone22dde22019-01-18 11:42:33 -0800645
Chienyuan3d8a8032019-11-01 18:04:07 +0800646 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800647}
648
649void DualModeController::HciWriteSimplePairingMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700650 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
651 ASSERT(args[0] == 1 || args[0] == 0);
Myles Watsone22dde22019-01-18 11:42:33 -0800652 link_layer_controller_.WriteSimplePairingMode(args[0] == 1);
Chienyuanc27da092019-11-20 19:29:43 +0800653 auto packet = bluetooth::hci::WriteSimplePairingModeCompleteBuilder::Create(
654 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
655 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800656}
657
658void DualModeController::HciChangeConnectionPacketType(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700659 ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800660 auto args_itr = args.begin();
661 uint16_t handle = args_itr.extract<uint16_t>();
662 uint16_t packet_type = args_itr.extract<uint16_t>();
663
Chienyuan3d8a8032019-11-01 18:04:07 +0800664 auto status =
665 link_layer_controller_.ChangeConnectionPacketType(handle, packet_type);
Myles Watsone22dde22019-01-18 11:42:33 -0800666
Chienyuanc27da092019-11-20 19:29:43 +0800667 auto packet = bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create(
668 status, kNumCommandPackets);
669 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800670}
671
672void DualModeController::HciWriteLeHostSupport(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700673 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800674 auto packet = bluetooth::hci::WriteLeHostSupportCompleteBuilder::Create(
675 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
676 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800677}
678
Chienyuanc27da092019-11-20 19:29:43 +0800679void DualModeController::HciWriteSecureConnectionsHostSupport(
Calvin Huang63a08962019-10-31 19:12:25 -0700680 packets::PacketView<true> args) {
681 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watson171ccb22019-11-13 09:37:29 -0800682 properties_.SetExtendedFeatures(properties_.GetExtendedFeatures(1) | 0x8, 1);
Chienyuanc27da092019-11-20 19:29:43 +0800683 auto packet =
684 bluetooth::hci::WriteSecureConnectionsHostSupportCompleteBuilder::Create(
685 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
686 send_event_(std::move(packet));
Calvin Huang63a08962019-10-31 19:12:25 -0700687}
688
Myles Watsone22dde22019-01-18 11:42:33 -0800689void DualModeController::HciSetEventMask(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700690 ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800691 auto packet = bluetooth::hci::SetEventMaskCompleteBuilder::Create(
692 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
693 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800694}
695
696void DualModeController::HciWriteInquiryMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700697 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800698 link_layer_controller_.SetInquiryMode(args[0]);
Chienyuanc27da092019-11-20 19:29:43 +0800699 auto packet = bluetooth::hci::WriteInquiryModeCompleteBuilder::Create(
700 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
701 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800702}
703
704void DualModeController::HciWritePageScanType(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700705 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800706 auto packet = bluetooth::hci::WritePageScanTypeCompleteBuilder::Create(
707 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
708 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800709}
710
711void DualModeController::HciWriteInquiryScanType(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700712 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800713 auto packet = bluetooth::hci::WriteInquiryScanTypeCompleteBuilder::Create(
714 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
715 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800716}
717
718void DualModeController::HciAuthenticationRequested(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700719 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800720 uint16_t handle = args.begin().extract<uint16_t>();
Chienyuan3d8a8032019-11-01 18:04:07 +0800721 auto status = link_layer_controller_.AuthenticationRequested(handle);
Myles Watsone22dde22019-01-18 11:42:33 -0800722
Chienyuanc27da092019-11-20 19:29:43 +0800723 auto packet = bluetooth::hci::AuthenticationRequestedStatusBuilder::Create(
724 status, kNumCommandPackets);
725 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800726}
727
728void DualModeController::HciSetConnectionEncryption(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700729 ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800730 auto args_itr = args.begin();
731 uint16_t handle = args_itr.extract<uint16_t>();
732 uint8_t encryption_enable = args_itr.extract<uint8_t>();
Chienyuan3d8a8032019-11-01 18:04:07 +0800733 auto status =
734 link_layer_controller_.SetConnectionEncryption(handle, encryption_enable);
Myles Watsone22dde22019-01-18 11:42:33 -0800735
Chienyuanc27da092019-11-20 19:29:43 +0800736 auto packet = bluetooth::hci::SetConnectionEncryptionStatusBuilder::Create(
737 status, kNumCommandPackets);
738 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800739}
740
Myles Watson1a0a0da2019-10-17 11:36:33 -0700741void DualModeController::HciChangeConnectionLinkKey(packets::PacketView<true> args) {
742 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800743 auto args_itr = args.begin();
744 uint16_t handle = args_itr.extract<uint16_t>();
745
Chienyuan3d8a8032019-11-01 18:04:07 +0800746 auto status = link_layer_controller_.ChangeConnectionLinkKey(handle);
Chienyuanad340b02019-09-25 19:23:21 +0800747
Chienyuanc27da092019-11-20 19:29:43 +0800748 auto packet = bluetooth::hci::ChangeConnectionLinkKeyStatusBuilder::Create(
749 status, kNumCommandPackets);
750 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800751}
752
Chienyuan9145e7a2019-10-02 15:18:55 +0800753void DualModeController::HciMasterLinkKey(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700754 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Chienyuan9145e7a2019-10-02 15:18:55 +0800755 auto args_itr = args.begin();
756 uint8_t key_flag = args_itr.extract<uint8_t>();
757
Chienyuan3d8a8032019-11-01 18:04:07 +0800758 auto status = link_layer_controller_.MasterLinkKey(key_flag);
Chienyuan9145e7a2019-10-02 15:18:55 +0800759
Chienyuanc27da092019-11-20 19:29:43 +0800760 auto packet = bluetooth::hci::MasterLinkKeyStatusBuilder::Create(
761 status, kNumCommandPackets);
762 send_event_(std::move(packet));
Chienyuan9145e7a2019-10-02 15:18:55 +0800763}
764
Myles Watsone22dde22019-01-18 11:42:33 -0800765void DualModeController::HciWriteAuthenticationEnable(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700766 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800767 properties_.SetAuthenticationEnable(args[0]);
Chienyuanc27da092019-11-20 19:29:43 +0800768 auto packet =
769 bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create(
770 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
771 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800772}
773
774void DualModeController::HciReadAuthenticationEnable(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700775 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800776 auto packet = bluetooth::hci::ReadAuthenticationEnableCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800777 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +0800778 static_cast<bluetooth::hci::AuthenticationEnable>(
779 properties_.GetAuthenticationEnable()));
780 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800781}
782
783void DualModeController::HciWriteClassOfDevice(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700784 ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800785 properties_.SetClassOfDevice(args[0], args[1], args[2]);
Chienyuanc27da092019-11-20 19:29:43 +0800786 auto packet = bluetooth::hci::WriteClassOfDeviceCompleteBuilder::Create(
787 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
788 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800789}
790
791void DualModeController::HciWritePageTimeout(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700792 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800793 auto packet = bluetooth::hci::WritePageTimeoutCompleteBuilder::Create(
794 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
795 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800796}
797
Chienyuanad340b02019-09-25 19:23:21 +0800798void DualModeController::HciHoldMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700799 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800800 auto args_itr = args.begin();
801 uint16_t handle = args_itr.extract<uint16_t>();
802 uint16_t hold_mode_max_interval = args_itr.extract<uint16_t>();
803 uint16_t hold_mode_min_interval = args_itr.extract<uint16_t>();
804
Chienyuan3d8a8032019-11-01 18:04:07 +0800805 auto status = link_layer_controller_.HoldMode(handle, hold_mode_max_interval,
806 hold_mode_min_interval);
Chienyuanad340b02019-09-25 19:23:21 +0800807
Chienyuanc27da092019-11-20 19:29:43 +0800808 auto packet =
809 bluetooth::hci::HoldModeStatusBuilder::Create(status, kNumCommandPackets);
810 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800811}
812
813void DualModeController::HciSniffMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700814 ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800815 auto args_itr = args.begin();
816 uint16_t handle = args_itr.extract<uint16_t>();
817 uint16_t sniff_max_interval = args_itr.extract<uint16_t>();
818 uint16_t sniff_min_interval = args_itr.extract<uint16_t>();
819 uint16_t sniff_attempt = args_itr.extract<uint16_t>();
820 uint16_t sniff_timeout = args_itr.extract<uint16_t>();
821
Chienyuan3d8a8032019-11-01 18:04:07 +0800822 auto status = link_layer_controller_.SniffMode(handle, sniff_max_interval,
823 sniff_min_interval,
824 sniff_attempt, sniff_timeout);
Chienyuanad340b02019-09-25 19:23:21 +0800825
Chienyuanc27da092019-11-20 19:29:43 +0800826 auto packet = bluetooth::hci::SniffModeStatusBuilder::Create(
827 status, kNumCommandPackets);
828 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800829}
830
831void DualModeController::HciExitSniffMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700832 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800833 auto args_itr = args.begin();
834 uint16_t handle = args_itr.extract<uint16_t>();
835
Chienyuan3d8a8032019-11-01 18:04:07 +0800836 auto status = link_layer_controller_.ExitSniffMode(handle);
Chienyuanad340b02019-09-25 19:23:21 +0800837
Chienyuanc27da092019-11-20 19:29:43 +0800838 auto packet = bluetooth::hci::ExitSniffModeStatusBuilder::Create(
839 status, kNumCommandPackets);
840 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800841}
842
843void DualModeController::HciQosSetup(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700844 ASSERT_LOG(args.size() == 20, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800845 auto args_itr = args.begin();
846 uint16_t handle = args_itr.extract<uint16_t>();
847 args_itr.extract<uint8_t>(); // unused
848 uint8_t service_type = args_itr.extract<uint8_t>();
849 uint32_t token_rate = args_itr.extract<uint32_t>();
850 uint32_t peak_bandwidth = args_itr.extract<uint32_t>();
851 uint32_t latency = args_itr.extract<uint32_t>();
852 uint32_t delay_variation = args_itr.extract<uint32_t>();
853
Chienyuan3d8a8032019-11-01 18:04:07 +0800854 auto status =
855 link_layer_controller_.QosSetup(handle, service_type, token_rate,
856 peak_bandwidth, latency, delay_variation);
Chienyuanad340b02019-09-25 19:23:21 +0800857
Chienyuanc27da092019-11-20 19:29:43 +0800858 auto packet =
859 bluetooth::hci::QosSetupStatusBuilder::Create(status, kNumCommandPackets);
860 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800861}
862
Myles Watsone22dde22019-01-18 11:42:33 -0800863void DualModeController::HciWriteDefaultLinkPolicySettings(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700864 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800865 auto packet =
866 bluetooth::hci::WriteDefaultLinkPolicySettingsCompleteBuilder::Create(
867 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
868 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800869}
870
Chienyuanad340b02019-09-25 19:23:21 +0800871void DualModeController::HciFlowSpecification(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700872 ASSERT_LOG(args.size() == 21, "%s size=%zu", __func__, args.size());
Chienyuanad340b02019-09-25 19:23:21 +0800873 auto args_itr = args.begin();
874 uint16_t handle = args_itr.extract<uint16_t>();
875 args_itr.extract<uint8_t>(); // unused
876 uint8_t flow_direction = args_itr.extract<uint8_t>();
877 uint8_t service_type = args_itr.extract<uint8_t>();
878 uint32_t token_rate = args_itr.extract<uint32_t>();
879 uint32_t token_bucket_size = args_itr.extract<uint32_t>();
880 uint32_t peak_bandwidth = args_itr.extract<uint32_t>();
881 uint32_t access_latency = args_itr.extract<uint32_t>();
882
Chienyuan3d8a8032019-11-01 18:04:07 +0800883 auto status = link_layer_controller_.FlowSpecification(
884 handle, flow_direction, service_type, token_rate, token_bucket_size,
885 peak_bandwidth, access_latency);
Chienyuanad340b02019-09-25 19:23:21 +0800886
Chienyuanc27da092019-11-20 19:29:43 +0800887 auto packet = bluetooth::hci::FlowSpecificationStatusBuilder::Create(
888 status, kNumCommandPackets);
889 send_event_(std::move(packet));
Chienyuanad340b02019-09-25 19:23:21 +0800890}
891
Myles Watsone22dde22019-01-18 11:42:33 -0800892void DualModeController::HciWriteLinkPolicySettings(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700893 ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800894
895 auto args_itr = args.begin();
896 uint16_t handle = args_itr.extract<uint16_t>();
897 uint16_t settings = args_itr.extract<uint16_t>();
898
Chienyuan3d8a8032019-11-01 18:04:07 +0800899 auto status =
900 link_layer_controller_.WriteLinkPolicySettings(handle, settings);
Myles Watsone22dde22019-01-18 11:42:33 -0800901
Chienyuan3d8a8032019-11-01 18:04:07 +0800902 auto packet = bluetooth::hci::WriteLinkPolicySettingsCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800903 kNumCommandPackets, status, handle);
Chienyuan3d8a8032019-11-01 18:04:07 +0800904 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800905}
906
907void DualModeController::HciWriteLinkSupervisionTimeout(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700908 ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800909
910 auto args_itr = args.begin();
911 uint16_t handle = args_itr.extract<uint16_t>();
912 uint16_t timeout = args_itr.extract<uint16_t>();
913
Chienyuan3d8a8032019-11-01 18:04:07 +0800914 auto status =
915 link_layer_controller_.WriteLinkSupervisionTimeout(handle, timeout);
916 auto packet =
917 bluetooth::hci::WriteLinkSupervisionTimeoutCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800918 kNumCommandPackets, status, handle);
Chienyuan3d8a8032019-11-01 18:04:07 +0800919 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800920}
921
922void DualModeController::HciReadLocalName(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700923 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +0800924
925 std::array<uint8_t, 248> local_name;
926 local_name.fill(0x00);
927 size_t len = properties_.GetName().size();
928 if (len > 247) {
929 len = 247; // one byte for NULL octet (0x00)
930 }
931 std::copy_n(properties_.GetName().begin(), len, local_name.begin());
932
933 auto packet = bluetooth::hci::ReadLocalNameCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +0800934 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, local_name);
Chienyuan3d8a8032019-11-01 18:04:07 +0800935 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800936}
937
938void DualModeController::HciWriteLocalName(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700939 ASSERT_LOG(args.size() == 248, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800940 std::vector<uint8_t> clipped(args.begin(), args.begin() + LastNonZero(args) + 1);
941 properties_.SetName(clipped);
Chienyuanc27da092019-11-20 19:29:43 +0800942 auto packet = bluetooth::hci::WriteLocalNameCompleteBuilder::Create(
943 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
944 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800945}
946
947void DualModeController::HciWriteExtendedInquiryResponse(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700948 ASSERT_LOG(args.size() == 241, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800949 // Strip FEC byte and trailing zeros
950 std::vector<uint8_t> clipped(args.begin() + 1, args.begin() + LastNonZero(args) + 1);
951 properties_.SetExtendedInquiryData(clipped);
Chienyuanc27da092019-11-20 19:29:43 +0800952 auto packet =
953 bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create(
954 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
955 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800956}
957
Myles Watson1a0a0da2019-10-17 11:36:33 -0700958void DualModeController::HciRefreshEncryptionKey(packets::PacketView<true> args) {
959 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsonb293d732019-08-19 12:35:36 -0700960 auto args_itr = args.begin();
961 uint16_t handle = args_itr.extract<uint16_t>();
Chienyuanc27da092019-11-20 19:29:43 +0800962 auto status_packet =
963 bluetooth::hci::RefreshEncryptionKeyStatusBuilder::Create(
964 bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
965 send_event_(std::move(status_packet));
Myles Watsonb293d732019-08-19 12:35:36 -0700966 // TODO: Support this in the link layer
Chienyuanc27da092019-11-20 19:29:43 +0800967 auto complete_packet =
968 bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create(
969 bluetooth::hci::ErrorCode::SUCCESS, handle);
970 send_event_(std::move(complete_packet));
Myles Watsonb293d732019-08-19 12:35:36 -0700971}
972
Myles Watsone22dde22019-01-18 11:42:33 -0800973void DualModeController::HciWriteVoiceSetting(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700974 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800975 auto packet = bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create(
976 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
977 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800978}
979
980void DualModeController::HciWriteCurrentIacLap(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700981 ASSERT(args.size() > 0);
982 ASSERT(args.size() == 1 + (3 * args[0])); // count + 3-byte IACs
Chienyuanc27da092019-11-20 19:29:43 +0800983 auto packet = bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create(
984 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
985 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800986}
987
988void DualModeController::HciWriteInquiryScanActivity(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700989 ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size());
Chienyuanc27da092019-11-20 19:29:43 +0800990 auto packet = bluetooth::hci::WriteInquiryScanActivityCompleteBuilder::Create(
991 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
992 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -0800993}
994
995void DualModeController::HciWriteScanEnable(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -0700996 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -0800997 link_layer_controller_.SetInquiryScanEnable(args[0] & 0x1);
998 link_layer_controller_.SetPageScanEnable(args[0] & 0x2);
Chienyuanc27da092019-11-20 19:29:43 +0800999 auto packet = bluetooth::hci::WriteScanEnableCompleteBuilder::Create(
1000 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1001 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001002}
1003
1004void DualModeController::HciSetEventFilter(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001005 ASSERT(args.size() > 0);
Chienyuanc27da092019-11-20 19:29:43 +08001006 auto packet = bluetooth::hci::SetEventFilterCompleteBuilder::Create(
1007 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1008 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001009}
1010
1011void DualModeController::HciInquiry(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001012 ASSERT_LOG(args.size() == 5, "%s size=%zu", __func__, args.size());
1013 link_layer_controller_.SetInquiryLAP(args[0] | (args[1], 8) | (args[2], 16));
Myles Watsone22dde22019-01-18 11:42:33 -08001014 link_layer_controller_.SetInquiryMaxResponses(args[4]);
1015 link_layer_controller_.StartInquiry(std::chrono::milliseconds(args[3] * 1280));
1016
Chienyuanc27da092019-11-20 19:29:43 +08001017 auto packet = bluetooth::hci::InquiryStatusBuilder::Create(
1018 bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
1019 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001020}
1021
1022void DualModeController::HciInquiryCancel(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001023 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001024 link_layer_controller_.InquiryCancel();
Chienyuanc27da092019-11-20 19:29:43 +08001025 auto packet = bluetooth::hci::InquiryCancelCompleteBuilder::Create(
1026 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1027 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001028}
1029
1030void DualModeController::HciAcceptConnectionRequest(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001031 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001032 Address addr = args.begin().extract<Address>();
1033 bool try_role_switch = args[6] == 0;
Chienyuan3d8a8032019-11-01 18:04:07 +08001034 auto status =
1035 link_layer_controller_.AcceptConnectionRequest(addr, try_role_switch);
Chienyuanc27da092019-11-20 19:29:43 +08001036 auto packet = bluetooth::hci::AcceptConnectionRequestStatusBuilder::Create(
1037 status, kNumCommandPackets);
1038 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001039}
1040
1041void DualModeController::HciRejectConnectionRequest(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001042 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001043 auto args_itr = args.begin();
1044 Address addr = args_itr.extract<Address>();
1045 uint8_t reason = args_itr.extract<uint8_t>();
Chienyuan3d8a8032019-11-01 18:04:07 +08001046 auto status = link_layer_controller_.RejectConnectionRequest(addr, reason);
Chienyuanc27da092019-11-20 19:29:43 +08001047 auto packet = bluetooth::hci::RejectConnectionRequestStatusBuilder::Create(
1048 status, kNumCommandPackets);
1049 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001050}
1051
1052void DualModeController::HciLinkKeyRequestReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001053 ASSERT_LOG(args.size() == 22, "%s size=%zu", __func__, args.size());
Myles Watsone066df42019-11-13 14:39:18 -08001054 auto args_it = args.begin();
1055 Address addr = args_it.extract<Address>();
1056 auto key = args.begin().extract<std::array<uint8_t, 16>>();
Chienyuan3d8a8032019-11-01 18:04:07 +08001057 auto status = link_layer_controller_.LinkKeyRequestReply(addr, key);
Chienyuanc27da092019-11-20 19:29:43 +08001058 auto packet = bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create(
1059 kNumCommandPackets, status);
Chienyuan3d8a8032019-11-01 18:04:07 +08001060 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001061}
1062
1063void DualModeController::HciLinkKeyRequestNegativeReply(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001064 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001065 Address addr = args.begin().extract<Address>();
Chienyuan3d8a8032019-11-01 18:04:07 +08001066 auto status = link_layer_controller_.LinkKeyRequestNegativeReply(addr);
1067 auto packet =
1068 bluetooth::hci::LinkKeyRequestNegativeReplyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001069 kNumCommandPackets, status, addr);
Chienyuan3d8a8032019-11-01 18:04:07 +08001070 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001071}
1072
1073void DualModeController::HciDeleteStoredLinkKey(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001074 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001075
1076 uint16_t deleted_keys = 0;
1077
1078 if (args[6] == 0) {
1079 Address addr = args.begin().extract<Address>();
1080 deleted_keys = security_manager_.DeleteKey(addr);
1081 }
1082
1083 if (args[6] == 1) {
1084 security_manager_.DeleteAllKeys();
1085 }
1086
Chienyuan3d8a8032019-11-01 18:04:07 +08001087 auto packet = bluetooth::hci::DeleteStoredLinkKeyCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001088 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, deleted_keys);
Chienyuan3d8a8032019-11-01 18:04:07 +08001089
1090 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001091}
1092
1093void DualModeController::HciRemoteNameRequest(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001094 ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001095
1096 Address remote_addr = args.begin().extract<Address>();
1097
Chienyuan3d8a8032019-11-01 18:04:07 +08001098 auto status = link_layer_controller_.SendCommandToRemoteByAddress(
Myles Watsone066df42019-11-13 14:39:18 -08001099 bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr);
Myles Watsone22dde22019-01-18 11:42:33 -08001100
Chienyuanc27da092019-11-20 19:29:43 +08001101 auto packet = bluetooth::hci::RemoteNameRequestStatusBuilder::Create(
1102 status, kNumCommandPackets);
1103 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001104}
1105
1106void DualModeController::HciLeSetEventMask(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001107 ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001108 /*
1109 uint64_t mask = args.begin().extract<uint64_t>();
1110 link_layer_controller_.SetLeEventMask(mask);
1111 */
Chienyuanc27da092019-11-20 19:29:43 +08001112 auto packet = bluetooth::hci::LeSetEventMaskCompleteBuilder::Create(
1113 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1114 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001115}
1116
1117void DualModeController::HciLeReadBufferSize(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001118 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001119
Chienyuanc27da092019-11-20 19:29:43 +08001120 bluetooth::hci::LeBufferSize le_buffer_size;
1121 le_buffer_size.le_data_packet_length_ = properties_.GetLeDataPacketLength();
1122 le_buffer_size.total_num_le_packets_ = properties_.GetTotalNumLeDataPackets();
Chienyuan3d8a8032019-11-01 18:04:07 +08001123
Chienyuanc27da092019-11-20 19:29:43 +08001124 auto packet = bluetooth::hci::LeReadBufferSizeCompleteBuilder::Create(
1125 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, le_buffer_size);
Chienyuan3d8a8032019-11-01 18:04:07 +08001126 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001127}
1128
1129void DualModeController::HciLeReadLocalSupportedFeatures(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001130 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001131 auto packet =
1132 bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001133 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +08001134 properties_.GetLeSupportedFeatures());
1135 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001136}
1137
1138void DualModeController::HciLeSetRandomAddress(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001139 ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001140 properties_.SetLeAddress(args.begin().extract<Address>());
Chienyuanc27da092019-11-20 19:29:43 +08001141 auto packet = bluetooth::hci::LeSetRandomAddressCompleteBuilder::Create(
1142 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1143 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001144}
1145
1146void DualModeController::HciLeSetAdvertisingParameters(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001147 ASSERT_LOG(args.size() == 15, "%s size=%zu", __func__, args.size());
Myles Watson99aea892019-09-02 15:54:08 -07001148 auto args_itr = args.begin();
1149 properties_.SetLeAdvertisingParameters(
1150 args_itr.extract<uint16_t>() /* AdverisingIntervalMin */,
1151 args_itr.extract<uint16_t>() /* AdverisingIntervalMax */, args_itr.extract<uint8_t>() /* AdverisingType */,
1152 args_itr.extract<uint8_t>() /* OwnAddressType */, args_itr.extract<uint8_t>() /* PeerAddressType */,
1153 args_itr.extract<Address>() /* PeerAddress */, args_itr.extract<uint8_t>() /* AdvertisingChannelMap */,
1154 args_itr.extract<uint8_t>() /* AdvertisingFilterPolicy */
1155 );
Myles Watsone22dde22019-01-18 11:42:33 -08001156
Chienyuanc27da092019-11-20 19:29:43 +08001157 auto packet =
1158 bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create(
1159 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1160 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001161}
1162
1163void DualModeController::HciLeSetAdvertisingData(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001164 ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size());
Myles Watson99aea892019-09-02 15:54:08 -07001165 properties_.SetLeAdvertisement(std::vector<uint8_t>(args.begin() + 1, args.end()));
Chienyuanc27da092019-11-20 19:29:43 +08001166 auto packet = bluetooth::hci::LeSetAdvertisingDataCompleteBuilder::Create(
1167 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1168 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001169}
1170
Myles Watson99aea892019-09-02 15:54:08 -07001171void DualModeController::HciLeSetScanResponseData(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001172 ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size());
Myles Watson99aea892019-09-02 15:54:08 -07001173 properties_.SetLeScanResponse(std::vector<uint8_t>(args.begin() + 1, args.end()));
Chienyuanc27da092019-11-20 19:29:43 +08001174 auto packet = bluetooth::hci::LeSetScanResponseDataCompleteBuilder::Create(
1175 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1176 send_event_(std::move(packet));
Myles Watson99aea892019-09-02 15:54:08 -07001177}
1178
1179void DualModeController::HciLeSetAdvertisingEnable(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001180 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001181 auto status = link_layer_controller_.SetLeAdvertisingEnable(
1182 args.begin().extract<uint8_t>());
Chienyuanc27da092019-11-20 19:29:43 +08001183 auto packet = bluetooth::hci::LeSetAdvertisingEnableCompleteBuilder::Create(
1184 kNumCommandPackets, status);
1185 send_event_(std::move(packet));
Myles Watson99aea892019-09-02 15:54:08 -07001186}
1187
Myles Watsone22dde22019-01-18 11:42:33 -08001188void DualModeController::HciLeSetScanParameters(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001189 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001190 link_layer_controller_.SetLeScanType(args[0]);
Myles Watson1a0a0da2019-10-17 11:36:33 -07001191 link_layer_controller_.SetLeScanInterval(args[1] | (args[2], 8));
1192 link_layer_controller_.SetLeScanWindow(args[3] | (args[4], 8));
Myles Watsone22dde22019-01-18 11:42:33 -08001193 link_layer_controller_.SetLeAddressType(args[5]);
1194 link_layer_controller_.SetLeScanFilterPolicy(args[6]);
Chienyuanc27da092019-11-20 19:29:43 +08001195 auto packet = bluetooth::hci::LeSetScanParametersCompleteBuilder::Create(
1196 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1197 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001198}
1199
1200void DualModeController::HciLeSetScanEnable(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001201 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001202 link_layer_controller_.SetLeScanEnable(args[0]);
1203 link_layer_controller_.SetLeFilterDuplicates(args[1]);
Chienyuanc27da092019-11-20 19:29:43 +08001204 auto packet = bluetooth::hci::LeSetScanEnableCompleteBuilder::Create(
1205 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1206 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001207}
1208
1209void DualModeController::HciLeCreateConnection(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001210 ASSERT_LOG(args.size() == 25, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001211 auto args_itr = args.begin();
1212 link_layer_controller_.SetLeScanInterval(args_itr.extract<uint16_t>());
1213 link_layer_controller_.SetLeScanWindow(args_itr.extract<uint16_t>());
1214 uint8_t initiator_filter_policy = args_itr.extract<uint8_t>();
1215 link_layer_controller_.SetLeInitiatorFilterPolicy(initiator_filter_policy);
1216
1217 if (initiator_filter_policy == 0) { // White list not used
1218 uint8_t peer_address_type = args_itr.extract<uint8_t>();
1219 Address peer_address = args_itr.extract<Address>();
1220 link_layer_controller_.SetLePeerAddressType(peer_address_type);
1221 link_layer_controller_.SetLePeerAddress(peer_address);
1222 }
1223 link_layer_controller_.SetLeAddressType(args_itr.extract<uint8_t>());
1224 link_layer_controller_.SetLeConnectionIntervalMin(args_itr.extract<uint16_t>());
1225 link_layer_controller_.SetLeConnectionIntervalMax(args_itr.extract<uint16_t>());
1226 link_layer_controller_.SetLeConnectionLatency(args_itr.extract<uint16_t>());
1227 link_layer_controller_.SetLeSupervisionTimeout(args_itr.extract<uint16_t>());
1228 link_layer_controller_.SetLeMinimumCeLength(args_itr.extract<uint16_t>());
1229 link_layer_controller_.SetLeMaximumCeLength(args_itr.extract<uint16_t>());
1230
Chienyuan3d8a8032019-11-01 18:04:07 +08001231 auto status = link_layer_controller_.SetLeConnect(true);
Myles Watsone22dde22019-01-18 11:42:33 -08001232
Chienyuanc27da092019-11-20 19:29:43 +08001233 auto packet = bluetooth::hci::LeCreateConnectionStatusBuilder::Create(
1234 status, kNumCommandPackets);
1235 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001236}
1237
1238void DualModeController::HciLeConnectionUpdate(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001239 ASSERT_LOG(args.size() == 14, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001240
Chienyuanc27da092019-11-20 19:29:43 +08001241 auto status_packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create(
Chienyuan3d8a8032019-11-01 18:04:07 +08001242 bluetooth::hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR,
Chienyuanc27da092019-11-20 19:29:43 +08001243 kNumCommandPackets);
1244 send_event_(std::move(status_packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001245
Chienyuanc27da092019-11-20 19:29:43 +08001246 auto complete_packet =
1247 bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create(
1248 bluetooth::hci::ErrorCode::SUCCESS, 0x0002, 0x0006, 0x0000, 0x01f4);
1249 send_event_(std::move(complete_packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001250}
1251
1252void DualModeController::HciCreateConnection(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001253 ASSERT_LOG(args.size() == 13, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001254
1255 auto args_itr = args.begin();
1256 Address address = args_itr.extract<Address>();
1257 uint16_t packet_type = args_itr.extract<uint16_t>();
1258 uint8_t page_scan_mode = args_itr.extract<uint8_t>();
1259 uint16_t clock_offset = args_itr.extract<uint16_t>();
1260 uint8_t allow_role_switch = args_itr.extract<uint8_t>();
1261
Chienyuan3d8a8032019-11-01 18:04:07 +08001262 auto status = link_layer_controller_.CreateConnection(
1263 address, packet_type, page_scan_mode, clock_offset, allow_role_switch);
Myles Watsone22dde22019-01-18 11:42:33 -08001264
Chienyuanc27da092019-11-20 19:29:43 +08001265 auto packet = bluetooth::hci::CreateConnectionStatusBuilder::Create(
1266 status, kNumCommandPackets);
1267 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001268}
1269
1270void DualModeController::HciDisconnect(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001271 ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001272
1273 auto args_itr = args.begin();
1274 uint16_t handle = args_itr.extract<uint16_t>();
1275 uint8_t reason = args_itr.extract<uint8_t>();
1276
Chienyuan3d8a8032019-11-01 18:04:07 +08001277 auto status = link_layer_controller_.Disconnect(handle, reason);
Myles Watsone22dde22019-01-18 11:42:33 -08001278
Chienyuanc27da092019-11-20 19:29:43 +08001279 auto packet = bluetooth::hci::DisconnectStatusBuilder::Create(
1280 status, kNumCommandPackets);
1281 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001282}
1283
1284void DualModeController::HciLeConnectionCancel(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001285 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001286 link_layer_controller_.SetLeConnect(false);
Chienyuanc27da092019-11-20 19:29:43 +08001287 auto packet = bluetooth::hci::LeCreateConnectionCancelStatusBuilder::Create(
1288 bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
1289 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001290 /* For testing Jakub's patch: Figure out a neat way to call this without
1291 recompiling. I'm thinking about a bad device. */
1292 /*
1293 SendCommandCompleteOnlyStatus(OpCode::LE_CREATE_CONNECTION_CANCEL,
Chienyuan3d8a8032019-11-01 18:04:07 +08001294 bluetooth::hci::ErrorCode::COMMAND_DISALLOWED);
Myles Watsone22dde22019-01-18 11:42:33 -08001295 */
1296}
1297
1298void DualModeController::HciLeReadWhiteListSize(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001299 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001300 auto packet = bluetooth::hci::LeReadWhiteListSizeCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001301 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +08001302 properties_.GetLeWhiteListSize());
1303 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001304}
1305
1306void DualModeController::HciLeClearWhiteList(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001307 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001308 link_layer_controller_.LeWhiteListClear();
Chienyuanc27da092019-11-20 19:29:43 +08001309 auto packet = bluetooth::hci::LeClearWhiteListCompleteBuilder::Create(
1310 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1311 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001312}
1313
1314void DualModeController::HciLeAddDeviceToWhiteList(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001315 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001316
1317 if (link_layer_controller_.LeWhiteListFull()) {
Chienyuanc27da092019-11-20 19:29:43 +08001318 auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create(
1319 kNumCommandPackets,
Chienyuan3d8a8032019-11-01 18:04:07 +08001320 bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED);
Chienyuanc27da092019-11-20 19:29:43 +08001321 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001322 return;
1323 }
1324 auto args_itr = args.begin();
1325 uint8_t addr_type = args_itr.extract<uint8_t>();
1326 Address address = args_itr.extract<Address>();
1327 link_layer_controller_.LeWhiteListAddDevice(address, addr_type);
Chienyuanc27da092019-11-20 19:29:43 +08001328 auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create(
1329 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1330 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001331}
1332
1333void DualModeController::HciLeRemoveDeviceFromWhiteList(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001334 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001335
1336 auto args_itr = args.begin();
1337 uint8_t addr_type = args_itr.extract<uint8_t>();
1338 Address address = args_itr.extract<Address>();
1339 link_layer_controller_.LeWhiteListRemoveDevice(address, addr_type);
Chienyuanc27da092019-11-20 19:29:43 +08001340 auto packet =
1341 bluetooth::hci::LeRemoveDeviceFromWhiteListCompleteBuilder::Create(
1342 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1343 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001344}
1345
Calvin Huangee1980c2019-11-01 16:35:55 -07001346void DualModeController::HciLeClearResolvingList(
1347 packets::PacketView<true> args) {
1348 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
1349 link_layer_controller_.LeResolvingListClear();
Chienyuanc27da092019-11-20 19:29:43 +08001350 auto packet = bluetooth::hci::LeClearResolvingListCompleteBuilder::Create(
1351 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1352 send_event_(std::move(packet));
Calvin Huangee1980c2019-11-01 16:35:55 -07001353}
1354
1355void DualModeController::HciLeAddDeviceToResolvingList(
1356 packets::PacketView<true> args) {
1357 ASSERT_LOG(args.size() == 39, "%s size=%zu", __func__, args.size());
1358
1359 if (link_layer_controller_.LeResolvingListFull()) {
Chienyuanc27da092019-11-20 19:29:43 +08001360 auto packet =
1361 bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create(
1362 kNumCommandPackets,
1363 bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED);
1364 send_event_(std::move(packet));
Calvin Huangee1980c2019-11-01 16:35:55 -07001365 return;
1366 }
1367 auto args_itr = args.begin();
1368 uint8_t addr_type = args_itr.extract<uint8_t>();
1369 Address address = args_itr.extract<Address>();
1370 std::array<uint8_t, LinkLayerController::kIrk_size> peerIrk;
1371 std::array<uint8_t, LinkLayerController::kIrk_size> localIrk;
1372 for (size_t irk_ind = 0; irk_ind < LinkLayerController::kIrk_size;
1373 irk_ind++) {
1374 peerIrk[irk_ind] = args_itr.extract<uint8_t>();
1375 }
1376
1377 for (size_t irk_ind = 0; irk_ind < LinkLayerController::kIrk_size;
1378 irk_ind++) {
1379 localIrk[irk_ind] = args_itr.extract<uint8_t>();
1380 }
1381
1382 link_layer_controller_.LeResolvingListAddDevice(address, addr_type, peerIrk,
1383 localIrk);
Chienyuanc27da092019-11-20 19:29:43 +08001384 auto packet =
1385 bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create(
1386 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1387 send_event_(std::move(packet));
Calvin Huangee1980c2019-11-01 16:35:55 -07001388}
1389
1390void DualModeController::HciLeRemoveDeviceFromResolvingList(
1391 packets::PacketView<true> args) {
1392 ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size());
1393
1394 auto args_itr = args.begin();
1395 uint8_t addr_type = args_itr.extract<uint8_t>();
1396 Address address = args_itr.extract<Address>();
1397 link_layer_controller_.LeResolvingListRemoveDevice(address, addr_type);
Chienyuanc27da092019-11-20 19:29:43 +08001398 auto packet =
1399 bluetooth::hci::LeRemoveDeviceFromResolvingListCompleteBuilder::Create(
1400 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1401 send_event_(std::move(packet));
Calvin Huangee1980c2019-11-01 16:35:55 -07001402}
1403
1404void DualModeController::HciLeSetPrivacyMode(packets::PacketView<true> args) {
1405 ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size());
1406
1407 auto args_itr = args.begin();
1408 uint8_t peer_identity_address_type = args_itr.extract<uint8_t>();
1409 Address peer_identity_address = args_itr.extract<Address>();
1410 uint8_t privacy_mode = args_itr.extract<uint8_t>();
1411
1412 if (link_layer_controller_.LeResolvingListContainsDevice(
1413 peer_identity_address, peer_identity_address_type)) {
1414 link_layer_controller_.LeSetPrivacyMode(
1415 peer_identity_address_type, peer_identity_address, privacy_mode);
1416 }
1417
Chienyuanc27da092019-11-20 19:29:43 +08001418 auto packet = bluetooth::hci::LeSetPrivacyModeCompleteBuilder::Create(
1419 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1420 send_event_(std::move(packet));
Calvin Huangee1980c2019-11-01 16:35:55 -07001421}
1422
Myles Watsone22dde22019-01-18 11:42:33 -08001423void DualModeController::HciLeReadRemoteFeatures(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001424 ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001425
1426 uint16_t handle = args.begin().extract<uint16_t>();
1427
Chienyuan3d8a8032019-11-01 18:04:07 +08001428 auto status = link_layer_controller_.SendCommandToRemoteByHandle(
1429 bluetooth::hci::OpCode::LE_READ_REMOTE_FEATURES, args, handle);
Myles Watsone22dde22019-01-18 11:42:33 -08001430
Chienyuanc27da092019-11-20 19:29:43 +08001431 auto packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create(
1432 status, kNumCommandPackets);
1433 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001434}
1435
1436void DualModeController::HciLeRand(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001437 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001438 uint64_t random_val = 0;
1439 for (size_t rand_bytes = 0; rand_bytes < sizeof(uint64_t); rand_bytes += sizeof(RAND_MAX)) {
1440 random_val = (random_val << (8 * sizeof(RAND_MAX))) | random();
1441 }
Chienyuan3d8a8032019-11-01 18:04:07 +08001442
1443 auto packet = bluetooth::hci::LeRandCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001444 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, random_val);
Chienyuan3d8a8032019-11-01 18:04:07 +08001445 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001446}
1447
1448void DualModeController::HciLeReadSupportedStates(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001449 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001450 auto packet = bluetooth::hci::LeReadSupportedStatesCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001451 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +08001452 properties_.GetLeSupportedStates());
1453 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001454}
1455
1456void DualModeController::HciLeVendorCap(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001457 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001458 vector<uint8_t> caps = properties_.GetLeVendorCap();
1459 if (caps.size() == 0) {
Chienyuanc27da092019-11-20 19:29:43 +08001460 SendCommandCompleteUnknownOpCodeEvent(static_cast<uint16_t>(
1461 bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES));
Myles Watsone22dde22019-01-18 11:42:33 -08001462 return;
1463 }
1464
Chienyuan3d8a8032019-11-01 18:04:07 +08001465 std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr =
1466 std::make_unique<bluetooth::packet::RawBuilder>();
1467 raw_builder_ptr->AddOctets1(
1468 static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS));
1469 raw_builder_ptr->AddOctets(properties_.GetLeVendorCap());
1470
1471 auto packet = bluetooth::hci::CommandCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001472 kNumCommandPackets, bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES,
Chienyuan3d8a8032019-11-01 18:04:07 +08001473 std::move(raw_builder_ptr));
1474 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001475}
1476
1477void DualModeController::HciLeVendorMultiAdv(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001478 ASSERT(args.size() > 0);
Chienyuanc27da092019-11-20 19:29:43 +08001479 SendCommandCompleteUnknownOpCodeEvent(
1480 static_cast<uint16_t>(bluetooth::hci::OpCode::LE_MULTI_ADVT));
Myles Watsone22dde22019-01-18 11:42:33 -08001481}
1482
1483void DualModeController::HciLeAdvertisingFilter(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001484 ASSERT(args.size() > 0);
Chienyuanc27da092019-11-20 19:29:43 +08001485 SendCommandCompleteUnknownOpCodeEvent(
1486 static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ADV_FILTER));
Myles Watsone22dde22019-01-18 11:42:33 -08001487}
1488
1489void DualModeController::HciLeEnergyInfo(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001490 ASSERT(args.size() > 0);
Chienyuanc27da092019-11-20 19:29:43 +08001491 SendCommandCompleteUnknownOpCodeEvent(
1492 static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ENERGY_INFO));
Myles Watsone22dde22019-01-18 11:42:33 -08001493}
1494
1495void DualModeController::HciLeExtendedScanParams(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001496 ASSERT(args.size() > 0);
Chienyuanc27da092019-11-20 19:29:43 +08001497 SendCommandCompleteUnknownOpCodeEvent(
1498 static_cast<uint16_t>(bluetooth::hci::OpCode::LE_EXTENDED_SCAN_PARAMS));
Myles Watsone22dde22019-01-18 11:42:33 -08001499}
1500
1501void DualModeController::HciLeStartEncryption(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001502 ASSERT_LOG(args.size() == 28, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001503
1504 auto args_itr = args.begin();
1505 uint16_t handle = args_itr.extract<uint16_t>();
1506 // uint64_t random_number = args_itr.extract<uint64_t>();
1507 // uint16_t encrypted_diversifier = args_itr.extract<uint16_t>();
1508 // std::vector<uint8_t> long_term_key;
1509 // for (size_t i = 0; i < 16; i++) {
1510 // long_term_key.push_back(args_itr.extract<uint18_t>();
1511 // }
Chienyuanc27da092019-11-20 19:29:43 +08001512 auto status_packet = bluetooth::hci::LeStartEncryptionStatusBuilder::Create(
1513 bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets);
1514 send_event_(std::move(status_packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001515
Chienyuanc27da092019-11-20 19:29:43 +08001516 auto complete_packet = bluetooth::hci::EncryptionChangeBuilder::Create(
Chienyuan3d8a8032019-11-01 18:04:07 +08001517 bluetooth::hci::ErrorCode::SUCCESS, handle,
1518 bluetooth::hci::EncryptionEnabled::OFF);
Chienyuanc27da092019-11-20 19:29:43 +08001519 send_event_(std::move(complete_packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001520#if 0
1521
1522 std::shared_ptr<packets::AclPacketBuilder> encryption_information =
1523 std::make_shared<packets::AclPacketBuilder>(
1524 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT,
1525 std::vector<uint8_t>({}));
1526
1527 encryption_information->AddPayloadOctets2(0x0011);
1528 encryption_information->AddPayloadOctets2(0x0006);
1529 encryption_information->AddPayloadOctets1(0x06);
1530 encryption_information->AddPayloadOctets8(0x0706050403020100);
1531 encryption_information->AddPayloadOctets8(0x0F0E0D0C0B0A0908);
1532
1533 send_acl_(encryption_information);
1534
1535 encryption_information = std::make_shared<packets::AclPacketBuilder>(
1536 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT,
1537 std::vector<uint8_t>({}));
1538
1539 encryption_information->AddPayloadOctets2(0x000B);
1540 encryption_information->AddPayloadOctets2(0x0006);
1541 encryption_information->AddPayloadOctets1(0x07);
1542 encryption_information->AddPayloadOctets2(0xBEEF);
1543 encryption_information->AddPayloadOctets8(0x0706050403020100);
1544
1545 send_acl_(encryption_information);
1546
1547 encryption_information = std::make_shared<packets::AclPacketBuilder>(
1548 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT,
1549 std::vector<uint8_t>({}));
1550
1551 encryption_information->AddPayloadOctets2(0x0011);
1552 encryption_information->AddPayloadOctets2(0x0006);
1553 encryption_information->AddPayloadOctets1(0x08);
1554 encryption_information->AddPayloadOctets8(0x0F0E0D0C0B0A0908);
1555 encryption_information->AddPayloadOctets8(0x0706050403020100);
1556
1557 send_acl_(encryption_information);
1558
1559 encryption_information = std::make_shared<packets::AclPacketBuilder>(
1560 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT,
1561 std::vector<uint8_t>({}));
1562
1563 encryption_information->AddPayloadOctets2(0x0008);
1564 encryption_information->AddPayloadOctets2(0x0006);
1565 encryption_information->AddPayloadOctets1(0x09);
1566 encryption_information->AddPayloadOctets1(0x01);
1567 encryption_information->AddPayloadOctets6(0xDEADBEEFF00D);
1568 send_acl_(encryption_information);
1569 // send_event_(packets::EventPacketBuilder::CreateLeStartEncryption()->ToVector());
1570
1571#endif
1572}
1573
1574void DualModeController::HciReadLoopbackMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001575 ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size());
Chienyuan3d8a8032019-11-01 18:04:07 +08001576 auto packet = bluetooth::hci::ReadLoopbackModeCompleteBuilder::Create(
Chienyuanc27da092019-11-20 19:29:43 +08001577 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS,
Chienyuan3d8a8032019-11-01 18:04:07 +08001578 static_cast<bluetooth::hci::LoopbackMode>(loopback_mode_));
1579 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001580}
1581
1582void DualModeController::HciWriteLoopbackMode(packets::PacketView<true> args) {
Myles Watson1a0a0da2019-10-17 11:36:33 -07001583 ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size());
Myles Watsone22dde22019-01-18 11:42:33 -08001584 loopback_mode_ = static_cast<hci::LoopbackMode>(args[0]);
1585 // ACL channel
1586 uint16_t acl_handle = 0x123;
Chienyuan3d8a8032019-11-01 18:04:07 +08001587 auto packet_acl = bluetooth::hci::ConnectionCompleteBuilder::Create(
1588 bluetooth::hci::ErrorCode::SUCCESS, acl_handle, properties_.GetAddress(),
1589 bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED);
1590 send_event_(std::move(packet_acl));
Myles Watsone22dde22019-01-18 11:42:33 -08001591 // SCO channel
1592 uint16_t sco_handle = 0x345;
Chienyuan3d8a8032019-11-01 18:04:07 +08001593 auto packet_sco = bluetooth::hci::ConnectionCompleteBuilder::Create(
1594 bluetooth::hci::ErrorCode::SUCCESS, sco_handle, properties_.GetAddress(),
1595 bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED);
1596 send_event_(std::move(packet_sco));
Chienyuanc27da092019-11-20 19:29:43 +08001597 auto packet = bluetooth::hci::WriteLoopbackModeCompleteBuilder::Create(
1598 kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS);
1599 send_event_(std::move(packet));
Myles Watsone22dde22019-01-18 11:42:33 -08001600}
1601
Myles Watson205c32e2019-11-12 13:16:32 -08001602void DualModeController::SetAddress(Address address) {
1603 properties_.SetAddress(address);
1604}
1605
Myles Watsone22dde22019-01-18 11:42:33 -08001606} // namespace test_vendor_lib