Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1 | /* |
| 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 Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 17 | #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 Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 23 | #include <base/values.h> |
| 24 | |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 25 | #include "os/log.h" |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 26 | #include "packet/raw_builder.h" |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 27 | |
| 28 | #include "hci.h" |
| 29 | #include "packets/hci/acl_packet_view.h" |
| 30 | #include "packets/hci/command_packet_view.h" |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 31 | #include "packets/hci/sco_packet_view.h" |
| 32 | |
| 33 | using std::vector; |
| 34 | using test_vendor_lib::hci::EventCode; |
| 35 | using test_vendor_lib::hci::OpCode; |
| 36 | |
| 37 | namespace { |
| 38 | |
| 39 | size_t LastNonZero(test_vendor_lib::packets::PacketView<true> view) { |
| 40 | for (size_t i = view.size() - 1; i > 0; i--) { |
| 41 | if (view[i] != 0) { |
| 42 | return i; |
| 43 | } |
| 44 | } |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | |
| 50 | namespace test_vendor_lib { |
| 51 | constexpr char DualModeController::kControllerPropertiesFile[]; |
| 52 | constexpr uint16_t DualModeController::kSecurityManagerNumKeys; |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 53 | constexpr uint16_t kNumCommandPackets = 0x01; |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 54 | |
| 55 | // Device methods. |
| 56 | void DualModeController::Initialize(const std::vector<std::string>& args) { |
| 57 | if (args.size() < 2) return; |
| 58 | |
| 59 | Address addr; |
Hansong Zhang | 106fc60 | 2019-06-19 16:53:15 -0700 | [diff] [blame] | 60 | if (Address::FromString(args[1], addr)) { |
| 61 | properties_.SetAddress(addr); |
| 62 | } else { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 63 | LOG_ALWAYS_FATAL("Invalid address: %s", args[1].c_str()); |
Hansong Zhang | 106fc60 | 2019-06-19 16:53:15 -0700 | [diff] [blame] | 64 | } |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
| 67 | std::string DualModeController::GetTypeString() const { |
| 68 | return "Simulated Bluetooth Controller"; |
| 69 | } |
| 70 | |
Chienyuan | db55f31 | 2019-10-31 14:01:28 +0800 | [diff] [blame] | 71 | void DualModeController::IncomingPacket( |
| 72 | model::packets::LinkLayerPacketView incoming) { |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 73 | link_layer_controller_.IncomingPacket(incoming); |
| 74 | } |
| 75 | |
| 76 | void DualModeController::TimerTick() { |
| 77 | link_layer_controller_.TimerTick(); |
| 78 | } |
| 79 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 80 | void DualModeController::SendCommandCompleteUnknownOpCodeEvent(uint16_t command_opcode) const { |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 81 | std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr = |
| 82 | std::make_unique<bluetooth::packet::RawBuilder>(); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 83 | raw_builder_ptr->AddOctets1(kNumCommandPackets); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 84 | raw_builder_ptr->AddOctets2(command_opcode); |
| 85 | raw_builder_ptr->AddOctets1( |
| 86 | static_cast<uint8_t>(bluetooth::hci::ErrorCode::UNKNOWN_HCI_COMMAND)); |
| 87 | |
| 88 | auto packet = bluetooth::hci::EventPacketBuilder::Create( |
| 89 | bluetooth::hci::EventCode::COMMAND_COMPLETE, std::move(raw_builder_ptr)); |
| 90 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 93 | DualModeController::DualModeController(const std::string& properties_filename, uint16_t num_keys) |
| 94 | : Device(properties_filename), security_manager_(num_keys) { |
| 95 | loopback_mode_ = hci::LoopbackMode::NO; |
| 96 | |
| 97 | Address public_address; |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 98 | ASSERT(Address::FromString("3C:5A:B4:04:05:06", public_address)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 99 | properties_.SetAddress(public_address); |
| 100 | |
| 101 | link_layer_controller_.RegisterRemoteChannel( |
Chienyuan | db55f31 | 2019-10-31 14:01:28 +0800 | [diff] [blame] | 102 | [this](std::shared_ptr<model::packets::LinkLayerPacketBuilder> packet, |
| 103 | Phy::Type phy_type) { |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 104 | DualModeController::SendLinkLayerPacket(packet, phy_type); |
| 105 | }); |
| 106 | |
| 107 | #define SET_HANDLER(opcode, method) \ |
| 108 | active_hci_commands_[static_cast<uint16_t>(opcode)] = [this](packets::PacketView<true> param) { method(param); }; |
| 109 | SET_HANDLER(OpCode::RESET, HciReset); |
| 110 | SET_HANDLER(OpCode::READ_BUFFER_SIZE, HciReadBufferSize); |
| 111 | SET_HANDLER(OpCode::HOST_BUFFER_SIZE, HciHostBufferSize); |
| 112 | SET_HANDLER(OpCode::SNIFF_SUBRATING, HciSniffSubrating); |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 113 | SET_HANDLER(OpCode::READ_ENCRYPTION_KEY_SIZE, HciReadEncryptionKeySize); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 114 | SET_HANDLER(OpCode::READ_LOCAL_VERSION_INFORMATION, HciReadLocalVersionInformation); |
| 115 | SET_HANDLER(OpCode::READ_BD_ADDR, HciReadBdAddr); |
| 116 | SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_COMMANDS, HciReadLocalSupportedCommands); |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 117 | SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_FEATURES, HciReadLocalSupportedFeatures); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 118 | SET_HANDLER(OpCode::READ_LOCAL_SUPPORTED_CODECS, HciReadLocalSupportedCodecs); |
| 119 | SET_HANDLER(OpCode::READ_LOCAL_EXTENDED_FEATURES, HciReadLocalExtendedFeatures); |
| 120 | SET_HANDLER(OpCode::READ_REMOTE_EXTENDED_FEATURES, HciReadRemoteExtendedFeatures); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 121 | SET_HANDLER(OpCode::SWITCH_ROLE, HciSwitchRole); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 122 | SET_HANDLER(OpCode::READ_REMOTE_SUPPORTED_FEATURES, HciReadRemoteSupportedFeatures); |
| 123 | SET_HANDLER(OpCode::READ_CLOCK_OFFSET, HciReadClockOffset); |
| 124 | SET_HANDLER(OpCode::IO_CAPABILITY_REQUEST_REPLY, HciIoCapabilityRequestReply); |
| 125 | SET_HANDLER(OpCode::USER_CONFIRMATION_REQUEST_REPLY, HciUserConfirmationRequestReply); |
| 126 | SET_HANDLER(OpCode::USER_CONFIRMATION_REQUEST_NEGATIVE_REPLY, HciUserConfirmationRequestNegativeReply); |
| 127 | SET_HANDLER(OpCode::IO_CAPABILITY_REQUEST_NEGATIVE_REPLY, HciIoCapabilityRequestNegativeReply); |
| 128 | SET_HANDLER(OpCode::WRITE_SIMPLE_PAIRING_MODE, HciWriteSimplePairingMode); |
| 129 | SET_HANDLER(OpCode::WRITE_LE_HOST_SUPPORT, HciWriteLeHostSupport); |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 130 | SET_HANDLER(OpCode::WRITE_SECURE_CONNECTIONS_HOST_SUPPORT, |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 131 | HciWriteSecureConnectionsHostSupport); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 132 | SET_HANDLER(OpCode::SET_EVENT_MASK, HciSetEventMask); |
| 133 | SET_HANDLER(OpCode::WRITE_INQUIRY_MODE, HciWriteInquiryMode); |
| 134 | SET_HANDLER(OpCode::WRITE_PAGE_SCAN_TYPE, HciWritePageScanType); |
| 135 | SET_HANDLER(OpCode::WRITE_INQUIRY_SCAN_TYPE, HciWriteInquiryScanType); |
| 136 | SET_HANDLER(OpCode::AUTHENTICATION_REQUESTED, HciAuthenticationRequested); |
| 137 | SET_HANDLER(OpCode::SET_CONNECTION_ENCRYPTION, HciSetConnectionEncryption); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 138 | SET_HANDLER(OpCode::CHANGE_CONNECTION_LINK_KEY, HciChangeConnectionLinkKey); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 139 | SET_HANDLER(OpCode::MASTER_LINK_KEY, HciMasterLinkKey); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 140 | SET_HANDLER(OpCode::WRITE_AUTHENTICATION_ENABLE, HciWriteAuthenticationEnable); |
| 141 | SET_HANDLER(OpCode::READ_AUTHENTICATION_ENABLE, HciReadAuthenticationEnable); |
| 142 | SET_HANDLER(OpCode::WRITE_CLASS_OF_DEVICE, HciWriteClassOfDevice); |
| 143 | SET_HANDLER(OpCode::WRITE_PAGE_TIMEOUT, HciWritePageTimeout); |
| 144 | SET_HANDLER(OpCode::WRITE_LINK_SUPERVISION_TIMEOUT, HciWriteLinkSupervisionTimeout); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 145 | SET_HANDLER(OpCode::HOLD_MODE, HciHoldMode); |
| 146 | SET_HANDLER(OpCode::SNIFF_MODE, HciSniffMode); |
| 147 | SET_HANDLER(OpCode::EXIT_SNIFF_MODE, HciExitSniffMode); |
| 148 | SET_HANDLER(OpCode::QOS_SETUP, HciQosSetup); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 149 | SET_HANDLER(OpCode::WRITE_DEFAULT_LINK_POLICY_SETTINGS, HciWriteDefaultLinkPolicySettings); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 150 | SET_HANDLER(OpCode::FLOW_SPECIFICATION, HciFlowSpecification); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 151 | SET_HANDLER(OpCode::WRITE_LINK_POLICY_SETTINGS, HciWriteLinkPolicySettings); |
| 152 | SET_HANDLER(OpCode::CHANGE_CONNECTION_PACKET_TYPE, HciChangeConnectionPacketType); |
| 153 | SET_HANDLER(OpCode::WRITE_LOCAL_NAME, HciWriteLocalName); |
| 154 | SET_HANDLER(OpCode::READ_LOCAL_NAME, HciReadLocalName); |
| 155 | SET_HANDLER(OpCode::WRITE_EXTENDED_INQUIRY_RESPONSE, HciWriteExtendedInquiryResponse); |
Myles Watson | b293d73 | 2019-08-19 12:35:36 -0700 | [diff] [blame] | 156 | SET_HANDLER(OpCode::REFRESH_ENCRYPTION_KEY, HciRefreshEncryptionKey); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 157 | SET_HANDLER(OpCode::WRITE_VOICE_SETTING, HciWriteVoiceSetting); |
| 158 | SET_HANDLER(OpCode::WRITE_CURRENT_IAC_LAP, HciWriteCurrentIacLap); |
| 159 | SET_HANDLER(OpCode::WRITE_INQUIRY_SCAN_ACTIVITY, HciWriteInquiryScanActivity); |
| 160 | SET_HANDLER(OpCode::WRITE_SCAN_ENABLE, HciWriteScanEnable); |
| 161 | SET_HANDLER(OpCode::SET_EVENT_FILTER, HciSetEventFilter); |
| 162 | SET_HANDLER(OpCode::INQUIRY, HciInquiry); |
| 163 | SET_HANDLER(OpCode::INQUIRY_CANCEL, HciInquiryCancel); |
| 164 | SET_HANDLER(OpCode::ACCEPT_CONNECTION_REQUEST, HciAcceptConnectionRequest); |
| 165 | SET_HANDLER(OpCode::REJECT_CONNECTION_REQUEST, HciRejectConnectionRequest); |
| 166 | SET_HANDLER(OpCode::LINK_KEY_REQUEST_REPLY, HciLinkKeyRequestReply); |
| 167 | SET_HANDLER(OpCode::LINK_KEY_REQUEST_NEGATIVE_REPLY, HciLinkKeyRequestNegativeReply); |
| 168 | SET_HANDLER(OpCode::DELETE_STORED_LINK_KEY, HciDeleteStoredLinkKey); |
| 169 | SET_HANDLER(OpCode::REMOTE_NAME_REQUEST, HciRemoteNameRequest); |
| 170 | SET_HANDLER(OpCode::LE_SET_EVENT_MASK, HciLeSetEventMask); |
| 171 | SET_HANDLER(OpCode::LE_READ_BUFFER_SIZE, HciLeReadBufferSize); |
| 172 | SET_HANDLER(OpCode::LE_READ_LOCAL_SUPPORTED_FEATURES, HciLeReadLocalSupportedFeatures); |
| 173 | SET_HANDLER(OpCode::LE_SET_RANDOM_ADDRESS, HciLeSetRandomAddress); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 174 | SET_HANDLER(OpCode::LE_SET_ADVERTISING_PARAMETERS, HciLeSetAdvertisingParameters); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 175 | SET_HANDLER(OpCode::LE_SET_ADVERTISING_DATA, HciLeSetAdvertisingData); |
| 176 | SET_HANDLER(OpCode::LE_SET_SCAN_RESPONSE_DATA, HciLeSetScanResponseData); |
| 177 | SET_HANDLER(OpCode::LE_SET_ADVERTISING_ENABLE, HciLeSetAdvertisingEnable); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 178 | SET_HANDLER(OpCode::LE_SET_SCAN_PARAMETERS, HciLeSetScanParameters); |
| 179 | SET_HANDLER(OpCode::LE_SET_SCAN_ENABLE, HciLeSetScanEnable); |
| 180 | SET_HANDLER(OpCode::LE_CREATE_CONNECTION, HciLeCreateConnection); |
| 181 | SET_HANDLER(OpCode::CREATE_CONNECTION, HciCreateConnection); |
| 182 | SET_HANDLER(OpCode::DISCONNECT, HciDisconnect); |
| 183 | SET_HANDLER(OpCode::LE_CREATE_CONNECTION_CANCEL, HciLeConnectionCancel); |
| 184 | SET_HANDLER(OpCode::LE_READ_WHITE_LIST_SIZE, HciLeReadWhiteListSize); |
| 185 | SET_HANDLER(OpCode::LE_CLEAR_WHITE_LIST, HciLeClearWhiteList); |
| 186 | SET_HANDLER(OpCode::LE_ADD_DEVICE_TO_WHITE_LIST, HciLeAddDeviceToWhiteList); |
| 187 | SET_HANDLER(OpCode::LE_REMOVE_DEVICE_FROM_WHITE_LIST, HciLeRemoveDeviceFromWhiteList); |
| 188 | SET_HANDLER(OpCode::LE_RAND, HciLeRand); |
| 189 | SET_HANDLER(OpCode::LE_READ_SUPPORTED_STATES, HciLeReadSupportedStates); |
| 190 | SET_HANDLER(OpCode::LE_GET_VENDOR_CAPABILITIES, HciLeVendorCap); |
| 191 | SET_HANDLER(OpCode::LE_MULTI_ADVT, HciLeVendorMultiAdv); |
| 192 | SET_HANDLER(OpCode::LE_ADV_FILTER, HciLeAdvertisingFilter); |
| 193 | SET_HANDLER(OpCode::LE_ENERGY_INFO, HciLeEnergyInfo); |
| 194 | SET_HANDLER(OpCode::LE_EXTENDED_SCAN_PARAMS, HciLeExtendedScanParams); |
| 195 | SET_HANDLER(OpCode::LE_READ_REMOTE_FEATURES, HciLeReadRemoteFeatures); |
| 196 | SET_HANDLER(OpCode::READ_REMOTE_VERSION_INFORMATION, HciReadRemoteVersionInformation); |
| 197 | SET_HANDLER(OpCode::LE_CONNECTION_UPDATE, HciLeConnectionUpdate); |
| 198 | SET_HANDLER(OpCode::LE_START_ENCRYPTION, HciLeStartEncryption); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 199 | SET_HANDLER(OpCode::LE_ADD_DEVICE_TO_RESOLVING_LIST, |
| 200 | HciLeAddDeviceToResolvingList); |
| 201 | SET_HANDLER(OpCode::LE_REMOVE_DEVICE_FROM_RESOLVING_LIST, |
| 202 | HciLeRemoveDeviceFromResolvingList); |
| 203 | SET_HANDLER(OpCode::LE_CLEAR_RESOLVING_LIST, HciLeClearResolvingList); |
| 204 | SET_HANDLER(OpCode::LE_SET_PRIVACY_MODE, HciLeSetPrivacyMode); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 205 | // Testing Commands |
| 206 | SET_HANDLER(OpCode::READ_LOOPBACK_MODE, HciReadLoopbackMode); |
| 207 | SET_HANDLER(OpCode::WRITE_LOOPBACK_MODE, HciWriteLoopbackMode); |
| 208 | #undef SET_HANDLER |
| 209 | } |
| 210 | |
| 211 | void DualModeController::HciSniffSubrating(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 212 | ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 213 | |
| 214 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 215 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 216 | auto packet = bluetooth::hci::SniffSubratingCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 217 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 218 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | void DualModeController::RegisterTaskScheduler( |
| 222 | std::function<AsyncTaskId(std::chrono::milliseconds, const TaskCallback&)> oneshot_scheduler) { |
| 223 | link_layer_controller_.RegisterTaskScheduler(oneshot_scheduler); |
| 224 | } |
| 225 | |
| 226 | void DualModeController::RegisterPeriodicTaskScheduler( |
| 227 | std::function<AsyncTaskId(std::chrono::milliseconds, std::chrono::milliseconds, const TaskCallback&)> |
| 228 | periodic_scheduler) { |
| 229 | link_layer_controller_.RegisterPeriodicTaskScheduler(periodic_scheduler); |
| 230 | } |
| 231 | |
| 232 | void DualModeController::RegisterTaskCancel(std::function<void(AsyncTaskId)> task_cancel) { |
| 233 | link_layer_controller_.RegisterTaskCancel(task_cancel); |
| 234 | } |
| 235 | |
| 236 | void DualModeController::HandleAcl(std::shared_ptr<std::vector<uint8_t>> packet) { |
| 237 | auto acl_packet = packets::AclPacketView::Create(packet); |
| 238 | if (loopback_mode_ == hci::LoopbackMode::LOCAL) { |
| 239 | uint16_t handle = acl_packet.GetHandle(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 240 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 241 | std::vector<bluetooth::hci::CompletedPackets> completed_packets; |
| 242 | bluetooth::hci::CompletedPackets cp; |
| 243 | cp.connection_handle_ = handle; |
| 244 | cp.host_num_of_completed_packets_ = kNumCommandPackets; |
| 245 | completed_packets.push_back(cp); |
| 246 | auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create( |
| 247 | completed_packets); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 248 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 249 | return; |
| 250 | } |
| 251 | |
| 252 | link_layer_controller_.SendAclToRemote(acl_packet); |
| 253 | } |
| 254 | |
| 255 | void DualModeController::HandleSco(std::shared_ptr<std::vector<uint8_t>> packet) { |
| 256 | auto sco_packet = packets::ScoPacketView::Create(packet); |
| 257 | if (loopback_mode_ == hci::LoopbackMode::LOCAL) { |
| 258 | uint16_t handle = sco_packet.GetHandle(); |
| 259 | send_sco_(packet); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 260 | std::vector<bluetooth::hci::CompletedPackets> completed_packets; |
| 261 | bluetooth::hci::CompletedPackets cp; |
| 262 | cp.connection_handle_ = handle; |
| 263 | cp.host_num_of_completed_packets_ = kNumCommandPackets; |
| 264 | completed_packets.push_back(cp); |
| 265 | auto packet = bluetooth::hci::NumberOfCompletedPacketsBuilder::Create( |
| 266 | completed_packets); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 267 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 268 | return; |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | void DualModeController::HandleCommand(std::shared_ptr<std::vector<uint8_t>> packet) { |
| 273 | auto command_packet = packets::CommandPacketView::Create(packet); |
| 274 | uint16_t opcode = command_packet.GetOpcode(); |
| 275 | hci::OpCode op = static_cast<hci::OpCode>(opcode); |
| 276 | |
| 277 | if (loopback_mode_ == hci::LoopbackMode::LOCAL && |
| 278 | // Loopback exceptions. |
| 279 | op != OpCode::RESET && op != OpCode::SET_CONTROLLER_TO_HOST_FLOW_CONTROL && op != OpCode::HOST_BUFFER_SIZE && |
| 280 | op != OpCode::HOST_NUM_COMPLETED_PACKETS && op != OpCode::READ_BUFFER_SIZE && op != OpCode::READ_LOOPBACK_MODE && |
| 281 | op != OpCode::WRITE_LOOPBACK_MODE) { |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 282 | std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr = |
| 283 | std::make_unique<bluetooth::packet::RawBuilder>(); |
| 284 | raw_builder_ptr->AddOctets(*packet); |
| 285 | auto packet = bluetooth::hci::LoopbackCommandBuilder::Create( |
| 286 | std::move(raw_builder_ptr)); |
| 287 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 288 | } else if (active_hci_commands_.count(opcode) > 0) { |
| 289 | active_hci_commands_[opcode](command_packet.GetPayload()); |
| 290 | } else { |
| 291 | SendCommandCompleteUnknownOpCodeEvent(opcode); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 292 | LOG_INFO("Unknown command, opcode: 0x%04X, OGF: 0x%04X, OCF: 0x%04X", |
| 293 | opcode, (opcode & 0xFC00) >> 10, opcode & 0x03FF); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | void DualModeController::RegisterEventChannel( |
| 298 | const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 299 | send_event_ = |
| 300 | [callback](std::shared_ptr<bluetooth::hci::EventPacketBuilder> event) { |
| 301 | auto bytes = std::make_shared<std::vector<uint8_t>>(); |
| 302 | bluetooth::packet::BitInserter bit_inserter(*bytes); |
| 303 | bytes->reserve(event->size()); |
| 304 | event->Serialize(bit_inserter); |
| 305 | callback(std::move(bytes)); |
| 306 | }; |
| 307 | link_layer_controller_.RegisterEventChannel(send_event_); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void DualModeController::RegisterAclChannel( |
| 311 | const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { |
| 312 | link_layer_controller_.RegisterAclChannel(callback); |
| 313 | send_acl_ = callback; |
| 314 | } |
| 315 | |
| 316 | void DualModeController::RegisterScoChannel( |
| 317 | const std::function<void(std::shared_ptr<std::vector<uint8_t>>)>& callback) { |
| 318 | link_layer_controller_.RegisterScoChannel(callback); |
| 319 | send_sco_ = callback; |
| 320 | } |
| 321 | |
| 322 | void DualModeController::HciReset(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 323 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 324 | link_layer_controller_.Reset(); |
Hansong Zhang | 843271b | 2019-04-30 10:51:27 -0700 | [diff] [blame] | 325 | if (loopback_mode_ == hci::LoopbackMode::LOCAL) { |
| 326 | loopback_mode_ = hci::LoopbackMode::NO; |
| 327 | } |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 328 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 329 | auto packet = bluetooth::hci::ResetCompleteBuilder::Create( |
| 330 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 331 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | void DualModeController::HciReadBufferSize(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 335 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 336 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 337 | auto packet = bluetooth::hci::ReadBufferSizeCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 338 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 339 | properties_.GetAclDataPacketSize(), |
| 340 | properties_.GetSynchronousDataPacketSize(), |
| 341 | properties_.GetTotalNumAclDataPackets(), |
| 342 | properties_.GetTotalNumSynchronousDataPackets()); |
| 343 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 346 | void DualModeController::HciReadEncryptionKeySize( |
| 347 | packets::PacketView<true> args) { |
| 348 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
| 349 | |
| 350 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 351 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 352 | auto packet = bluetooth::hci::ReadEncryptionKeySizeCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 353 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, handle, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 354 | properties_.GetEncryptionKeySize()); |
| 355 | send_event_(std::move(packet)); |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 358 | void DualModeController::HciHostBufferSize(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 359 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 360 | auto packet = bluetooth::hci::HostBufferSizeCompleteBuilder::Create( |
| 361 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 362 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 363 | } |
| 364 | |
| 365 | void DualModeController::HciReadLocalVersionInformation(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 366 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 367 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 368 | bluetooth::hci::LocalVersionInformation local_version_information; |
| 369 | local_version_information.hci_version_ = |
| 370 | static_cast<bluetooth::hci::HciVersion>(properties_.GetVersion()); |
| 371 | local_version_information.hci_revision_ = properties_.GetRevision(); |
| 372 | local_version_information.lmp_version_ = |
| 373 | static_cast<bluetooth::hci::LmpVersion>(properties_.GetLmpPalVersion()); |
| 374 | local_version_information.manufacturer_name_ = |
| 375 | properties_.GetManufacturerName(); |
| 376 | local_version_information.lmp_subversion_ = properties_.GetLmpPalSubversion(); |
| 377 | auto packet = |
| 378 | bluetooth::hci::ReadLocalVersionInformationCompleteBuilder::Create( |
| 379 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
| 380 | local_version_information); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 381 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | void DualModeController::HciReadRemoteVersionInformation(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 385 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 386 | |
| 387 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 388 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 389 | auto status = link_layer_controller_.SendCommandToRemoteByHandle( |
| 390 | bluetooth::hci::OpCode::READ_REMOTE_VERSION_INFORMATION, args, handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 391 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 392 | auto packet = |
| 393 | bluetooth::hci::ReadRemoteVersionInformationStatusBuilder::Create( |
| 394 | status, kNumCommandPackets); |
| 395 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | void DualModeController::HciReadBdAddr(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 399 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 400 | auto packet = bluetooth::hci::ReadBdAddrCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 401 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
| 402 | properties_.GetAddress()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 403 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void DualModeController::HciReadLocalSupportedCommands(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 407 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 408 | |
| 409 | std::array<uint8_t, 64> supported_commands; |
| 410 | supported_commands.fill(0x00); |
| 411 | size_t len = properties_.GetSupportedCommands().size(); |
| 412 | if (len > 64) { |
| 413 | len = 64; |
| 414 | } |
| 415 | std::copy_n(properties_.GetSupportedCommands().begin(), len, |
| 416 | supported_commands.begin()); |
| 417 | |
| 418 | auto packet = |
| 419 | bluetooth::hci::ReadLocalSupportedCommandsCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 420 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
| 421 | supported_commands); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 422 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 423 | } |
| 424 | |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 425 | void DualModeController::HciReadLocalSupportedFeatures(packets::PacketView<true> args) { |
| 426 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 427 | auto packet = |
| 428 | bluetooth::hci::ReadLocalSupportedFeaturesCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 429 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 430 | properties_.GetSupportedFeatures()); |
| 431 | send_event_(std::move(packet)); |
Myles Watson | 14d5686 | 2019-08-19 13:03:46 -0700 | [diff] [blame] | 432 | } |
| 433 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 434 | void DualModeController::HciReadLocalSupportedCodecs(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 435 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 436 | auto packet = bluetooth::hci::ReadLocalSupportedCodecsCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 437 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 438 | properties_.GetSupportedCodecs(), properties_.GetVendorSpecificCodecs()); |
| 439 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | void DualModeController::HciReadLocalExtendedFeatures(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 443 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 444 | uint8_t page_number = args.begin().extract<uint8_t>(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 445 | |
| 446 | auto pakcet = |
| 447 | bluetooth::hci::ReadLocalExtendedFeaturesCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 448 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, page_number, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 449 | properties_.GetExtendedFeaturesMaximumPageNumber(), |
| 450 | properties_.GetExtendedFeatures(page_number)); |
| 451 | send_event_(std::move(pakcet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | void DualModeController::HciReadRemoteExtendedFeatures(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 455 | ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 456 | |
| 457 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 458 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 459 | auto status = link_layer_controller_.SendCommandToRemoteByHandle( |
| 460 | bluetooth::hci::OpCode::READ_REMOTE_EXTENDED_FEATURES, args, handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 461 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 462 | auto packet = bluetooth::hci::ReadRemoteExtendedFeaturesStatusBuilder::Create( |
| 463 | status, kNumCommandPackets); |
| 464 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 467 | void DualModeController::HciSwitchRole(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 468 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 469 | |
| 470 | Address address = args.begin().extract<Address>(); |
| 471 | uint8_t role = args.begin().extract<uint8_t>(); |
| 472 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 473 | auto status = link_layer_controller_.SwitchRole(address, role); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 474 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 475 | auto packet = bluetooth::hci::SwitchRoleStatusBuilder::Create( |
| 476 | status, kNumCommandPackets); |
| 477 | send_event_(std::move(packet)); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 478 | } |
| 479 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 480 | void DualModeController::HciReadRemoteSupportedFeatures(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 481 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 482 | |
| 483 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 484 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 485 | auto status = link_layer_controller_.SendCommandToRemoteByHandle( |
| 486 | bluetooth::hci::OpCode::READ_REMOTE_SUPPORTED_FEATURES, args, handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 487 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 488 | auto packet = |
| 489 | bluetooth::hci::ReadRemoteSupportedFeaturesStatusBuilder::Create( |
| 490 | status, kNumCommandPackets); |
| 491 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | void DualModeController::HciReadClockOffset(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 495 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 496 | |
| 497 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 498 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 499 | auto status = link_layer_controller_.SendCommandToRemoteByHandle( |
| 500 | bluetooth::hci::OpCode::READ_CLOCK_OFFSET, args, handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 501 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 502 | auto packet = bluetooth::hci::ReadClockOffsetStatusBuilder::Create( |
| 503 | status, kNumCommandPackets); |
| 504 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | void DualModeController::HciIoCapabilityRequestReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 508 | ASSERT_LOG(args.size() == 9, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 509 | |
| 510 | auto args_itr = args.begin(); |
| 511 | Address peer = args_itr.extract<Address>(); |
| 512 | uint8_t io_capability = args_itr.extract<uint8_t>(); |
| 513 | uint8_t oob_data_present_flag = args_itr.extract<uint8_t>(); |
| 514 | uint8_t authentication_requirements = args_itr.extract<uint8_t>(); |
| 515 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 516 | auto status = link_layer_controller_.IoCapabilityRequestReply( |
| 517 | peer, io_capability, oob_data_present_flag, authentication_requirements); |
| 518 | auto packet = bluetooth::hci::IoCapabilityRequestReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 519 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 520 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 521 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | void DualModeController::HciUserConfirmationRequestReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 525 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 526 | |
| 527 | Address peer = args.begin().extract<Address>(); |
| 528 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 529 | auto status = link_layer_controller_.UserConfirmationRequestReply(peer); |
| 530 | auto packet = |
| 531 | bluetooth::hci::UserConfirmationRequestReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 532 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 533 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 534 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | void DualModeController::HciUserConfirmationRequestNegativeReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 538 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 539 | |
| 540 | Address peer = args.begin().extract<Address>(); |
| 541 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 542 | auto status = |
| 543 | link_layer_controller_.UserConfirmationRequestNegativeReply(peer); |
| 544 | auto packet = |
| 545 | bluetooth::hci::UserConfirmationRequestNegativeReplyCompleteBuilder:: |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 546 | Create(kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 547 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 548 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | void DualModeController::HciUserPasskeyRequestReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 552 | ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 553 | |
| 554 | auto args_itr = args.begin(); |
| 555 | Address peer = args_itr.extract<Address>(); |
| 556 | uint32_t numeric_value = args_itr.extract<uint32_t>(); |
| 557 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 558 | auto status = |
| 559 | link_layer_controller_.UserPasskeyRequestReply(peer, numeric_value); |
| 560 | auto packet = bluetooth::hci::UserPasskeyRequestReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 561 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 562 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 563 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 564 | } |
| 565 | |
| 566 | void DualModeController::HciUserPasskeyRequestNegativeReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 567 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 568 | |
| 569 | Address peer = args.begin().extract<Address>(); |
| 570 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 571 | auto status = link_layer_controller_.UserPasskeyRequestNegativeReply(peer); |
| 572 | auto packet = |
| 573 | bluetooth::hci::UserPasskeyRequestNegativeReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 574 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 575 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 576 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | void DualModeController::HciRemoteOobDataRequestReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 580 | ASSERT_LOG(args.size() == 38, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 581 | |
| 582 | auto args_itr = args.begin(); |
| 583 | Address peer = args_itr.extract<Address>(); |
| 584 | std::vector<uint8_t> c; |
| 585 | std::vector<uint8_t> r; |
| 586 | for (size_t i = 0; i < 16; i++) { |
| 587 | c.push_back(args_itr.extract<uint8_t>()); |
| 588 | } |
| 589 | for (size_t i = 0; i < 16; i++) { |
| 590 | r.push_back(args_itr.extract<uint8_t>()); |
| 591 | } |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 592 | auto status = link_layer_controller_.RemoteOobDataRequestReply(peer, c, r); |
| 593 | auto packet = |
| 594 | bluetooth::hci::RemoteOobDataRequestReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 595 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 596 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 597 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | void DualModeController::HciRemoteOobDataRequestNegativeReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 601 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 602 | |
| 603 | Address peer = args.begin().extract<Address>(); |
| 604 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 605 | auto status = link_layer_controller_.RemoteOobDataRequestNegativeReply(peer); |
| 606 | auto packet = |
| 607 | bluetooth::hci::RemoteOobDataRequestNegativeReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 608 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 609 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 610 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | void DualModeController::HciIoCapabilityRequestNegativeReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 614 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 615 | |
| 616 | auto args_itr = args.begin(); |
| 617 | Address peer = args_itr.extract<Address>(); |
| 618 | hci::Status reason = args_itr.extract<hci::Status>(); |
| 619 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 620 | auto status = |
| 621 | link_layer_controller_.IoCapabilityRequestNegativeReply(peer, reason); |
| 622 | auto packet = |
| 623 | bluetooth::hci::IoCapabilityRequestNegativeReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 624 | kNumCommandPackets, status, peer); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 625 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 626 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | void DualModeController::HciWriteSimplePairingMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 630 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
| 631 | ASSERT(args[0] == 1 || args[0] == 0); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 632 | link_layer_controller_.WriteSimplePairingMode(args[0] == 1); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 633 | auto packet = bluetooth::hci::WriteSimplePairingModeCompleteBuilder::Create( |
| 634 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 635 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | void DualModeController::HciChangeConnectionPacketType(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 639 | ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 640 | auto args_itr = args.begin(); |
| 641 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 642 | uint16_t packet_type = args_itr.extract<uint16_t>(); |
| 643 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 644 | auto status = |
| 645 | link_layer_controller_.ChangeConnectionPacketType(handle, packet_type); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 646 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 647 | auto packet = bluetooth::hci::ChangeConnectionPacketTypeStatusBuilder::Create( |
| 648 | status, kNumCommandPackets); |
| 649 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void DualModeController::HciWriteLeHostSupport(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 653 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 654 | auto packet = bluetooth::hci::WriteLeHostSupportCompleteBuilder::Create( |
| 655 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 656 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 657 | } |
| 658 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 659 | void DualModeController::HciWriteSecureConnectionsHostSupport( |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 660 | packets::PacketView<true> args) { |
| 661 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | 171ccb2 | 2019-11-13 09:37:29 -0800 | [diff] [blame] | 662 | properties_.SetExtendedFeatures(properties_.GetExtendedFeatures(1) | 0x8, 1); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 663 | auto packet = |
| 664 | bluetooth::hci::WriteSecureConnectionsHostSupportCompleteBuilder::Create( |
| 665 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 666 | send_event_(std::move(packet)); |
Calvin Huang | 63a0896 | 2019-10-31 19:12:25 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 669 | void DualModeController::HciSetEventMask(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 670 | ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 671 | auto packet = bluetooth::hci::SetEventMaskCompleteBuilder::Create( |
| 672 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 673 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | void DualModeController::HciWriteInquiryMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 677 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 678 | link_layer_controller_.SetInquiryMode(args[0]); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 679 | auto packet = bluetooth::hci::WriteInquiryModeCompleteBuilder::Create( |
| 680 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 681 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | void DualModeController::HciWritePageScanType(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 685 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 686 | auto packet = bluetooth::hci::WritePageScanTypeCompleteBuilder::Create( |
| 687 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 688 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | void DualModeController::HciWriteInquiryScanType(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 692 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 693 | auto packet = bluetooth::hci::WriteInquiryScanTypeCompleteBuilder::Create( |
| 694 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 695 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void DualModeController::HciAuthenticationRequested(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 699 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 700 | uint16_t handle = args.begin().extract<uint16_t>(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 701 | auto status = link_layer_controller_.AuthenticationRequested(handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 702 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 703 | auto packet = bluetooth::hci::AuthenticationRequestedStatusBuilder::Create( |
| 704 | status, kNumCommandPackets); |
| 705 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | void DualModeController::HciSetConnectionEncryption(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 709 | ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 710 | auto args_itr = args.begin(); |
| 711 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 712 | uint8_t encryption_enable = args_itr.extract<uint8_t>(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 713 | auto status = |
| 714 | link_layer_controller_.SetConnectionEncryption(handle, encryption_enable); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 715 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 716 | auto packet = bluetooth::hci::SetConnectionEncryptionStatusBuilder::Create( |
| 717 | status, kNumCommandPackets); |
| 718 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 719 | } |
| 720 | |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 721 | void DualModeController::HciChangeConnectionLinkKey(packets::PacketView<true> args) { |
| 722 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 723 | auto args_itr = args.begin(); |
| 724 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 725 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 726 | auto status = link_layer_controller_.ChangeConnectionLinkKey(handle); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 727 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 728 | auto packet = bluetooth::hci::ChangeConnectionLinkKeyStatusBuilder::Create( |
| 729 | status, kNumCommandPackets); |
| 730 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 731 | } |
| 732 | |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 733 | void DualModeController::HciMasterLinkKey(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 734 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 735 | auto args_itr = args.begin(); |
| 736 | uint8_t key_flag = args_itr.extract<uint8_t>(); |
| 737 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 738 | auto status = link_layer_controller_.MasterLinkKey(key_flag); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 739 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 740 | auto packet = bluetooth::hci::MasterLinkKeyStatusBuilder::Create( |
| 741 | status, kNumCommandPackets); |
| 742 | send_event_(std::move(packet)); |
Chienyuan | 9145e7a | 2019-10-02 15:18:55 +0800 | [diff] [blame] | 743 | } |
| 744 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 745 | void DualModeController::HciWriteAuthenticationEnable(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 746 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 747 | properties_.SetAuthenticationEnable(args[0]); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 748 | auto packet = |
| 749 | bluetooth::hci::WriteAuthenticationEnableCompleteBuilder::Create( |
| 750 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 751 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | void DualModeController::HciReadAuthenticationEnable(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 755 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 756 | auto packet = bluetooth::hci::ReadAuthenticationEnableCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 757 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 758 | static_cast<bluetooth::hci::AuthenticationEnable>( |
| 759 | properties_.GetAuthenticationEnable())); |
| 760 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | void DualModeController::HciWriteClassOfDevice(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 764 | ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 765 | properties_.SetClassOfDevice(args[0], args[1], args[2]); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 766 | auto packet = bluetooth::hci::WriteClassOfDeviceCompleteBuilder::Create( |
| 767 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 768 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | void DualModeController::HciWritePageTimeout(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 772 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 773 | auto packet = bluetooth::hci::WritePageTimeoutCompleteBuilder::Create( |
| 774 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 775 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 776 | } |
| 777 | |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 778 | void DualModeController::HciHoldMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 779 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 780 | auto args_itr = args.begin(); |
| 781 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 782 | uint16_t hold_mode_max_interval = args_itr.extract<uint16_t>(); |
| 783 | uint16_t hold_mode_min_interval = args_itr.extract<uint16_t>(); |
| 784 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 785 | auto status = link_layer_controller_.HoldMode(handle, hold_mode_max_interval, |
| 786 | hold_mode_min_interval); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 787 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 788 | auto packet = |
| 789 | bluetooth::hci::HoldModeStatusBuilder::Create(status, kNumCommandPackets); |
| 790 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | void DualModeController::HciSniffMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 794 | ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 795 | auto args_itr = args.begin(); |
| 796 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 797 | uint16_t sniff_max_interval = args_itr.extract<uint16_t>(); |
| 798 | uint16_t sniff_min_interval = args_itr.extract<uint16_t>(); |
| 799 | uint16_t sniff_attempt = args_itr.extract<uint16_t>(); |
| 800 | uint16_t sniff_timeout = args_itr.extract<uint16_t>(); |
| 801 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 802 | auto status = link_layer_controller_.SniffMode(handle, sniff_max_interval, |
| 803 | sniff_min_interval, |
| 804 | sniff_attempt, sniff_timeout); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 805 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 806 | auto packet = bluetooth::hci::SniffModeStatusBuilder::Create( |
| 807 | status, kNumCommandPackets); |
| 808 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void DualModeController::HciExitSniffMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 812 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 813 | auto args_itr = args.begin(); |
| 814 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 815 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 816 | auto status = link_layer_controller_.ExitSniffMode(handle); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 817 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 818 | auto packet = bluetooth::hci::ExitSniffModeStatusBuilder::Create( |
| 819 | status, kNumCommandPackets); |
| 820 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | void DualModeController::HciQosSetup(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 824 | ASSERT_LOG(args.size() == 20, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 825 | auto args_itr = args.begin(); |
| 826 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 827 | args_itr.extract<uint8_t>(); // unused |
| 828 | uint8_t service_type = args_itr.extract<uint8_t>(); |
| 829 | uint32_t token_rate = args_itr.extract<uint32_t>(); |
| 830 | uint32_t peak_bandwidth = args_itr.extract<uint32_t>(); |
| 831 | uint32_t latency = args_itr.extract<uint32_t>(); |
| 832 | uint32_t delay_variation = args_itr.extract<uint32_t>(); |
| 833 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 834 | auto status = |
| 835 | link_layer_controller_.QosSetup(handle, service_type, token_rate, |
| 836 | peak_bandwidth, latency, delay_variation); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 837 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 838 | auto packet = |
| 839 | bluetooth::hci::QosSetupStatusBuilder::Create(status, kNumCommandPackets); |
| 840 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 841 | } |
| 842 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 843 | void DualModeController::HciWriteDefaultLinkPolicySettings(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 844 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 845 | auto packet = |
| 846 | bluetooth::hci::WriteDefaultLinkPolicySettingsCompleteBuilder::Create( |
| 847 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 848 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 849 | } |
| 850 | |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 851 | void DualModeController::HciFlowSpecification(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 852 | ASSERT_LOG(args.size() == 21, "%s size=%zu", __func__, args.size()); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 853 | auto args_itr = args.begin(); |
| 854 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 855 | args_itr.extract<uint8_t>(); // unused |
| 856 | uint8_t flow_direction = args_itr.extract<uint8_t>(); |
| 857 | uint8_t service_type = args_itr.extract<uint8_t>(); |
| 858 | uint32_t token_rate = args_itr.extract<uint32_t>(); |
| 859 | uint32_t token_bucket_size = args_itr.extract<uint32_t>(); |
| 860 | uint32_t peak_bandwidth = args_itr.extract<uint32_t>(); |
| 861 | uint32_t access_latency = args_itr.extract<uint32_t>(); |
| 862 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 863 | auto status = link_layer_controller_.FlowSpecification( |
| 864 | handle, flow_direction, service_type, token_rate, token_bucket_size, |
| 865 | peak_bandwidth, access_latency); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 866 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 867 | auto packet = bluetooth::hci::FlowSpecificationStatusBuilder::Create( |
| 868 | status, kNumCommandPackets); |
| 869 | send_event_(std::move(packet)); |
Chienyuan | ad340b0 | 2019-09-25 19:23:21 +0800 | [diff] [blame] | 870 | } |
| 871 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 872 | void DualModeController::HciWriteLinkPolicySettings(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 873 | ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 874 | |
| 875 | auto args_itr = args.begin(); |
| 876 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 877 | uint16_t settings = args_itr.extract<uint16_t>(); |
| 878 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 879 | auto status = |
| 880 | link_layer_controller_.WriteLinkPolicySettings(handle, settings); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 881 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 882 | auto packet = bluetooth::hci::WriteLinkPolicySettingsCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 883 | kNumCommandPackets, status, handle); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 884 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | void DualModeController::HciWriteLinkSupervisionTimeout(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 888 | ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 889 | |
| 890 | auto args_itr = args.begin(); |
| 891 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 892 | uint16_t timeout = args_itr.extract<uint16_t>(); |
| 893 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 894 | auto status = |
| 895 | link_layer_controller_.WriteLinkSupervisionTimeout(handle, timeout); |
| 896 | auto packet = |
| 897 | bluetooth::hci::WriteLinkSupervisionTimeoutCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 898 | kNumCommandPackets, status, handle); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 899 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 900 | } |
| 901 | |
| 902 | void DualModeController::HciReadLocalName(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 903 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 904 | |
| 905 | std::array<uint8_t, 248> local_name; |
| 906 | local_name.fill(0x00); |
| 907 | size_t len = properties_.GetName().size(); |
| 908 | if (len > 247) { |
| 909 | len = 247; // one byte for NULL octet (0x00) |
| 910 | } |
| 911 | std::copy_n(properties_.GetName().begin(), len, local_name.begin()); |
| 912 | |
| 913 | auto packet = bluetooth::hci::ReadLocalNameCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 914 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, local_name); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 915 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | void DualModeController::HciWriteLocalName(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 919 | ASSERT_LOG(args.size() == 248, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 920 | std::vector<uint8_t> clipped(args.begin(), args.begin() + LastNonZero(args) + 1); |
| 921 | properties_.SetName(clipped); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 922 | auto packet = bluetooth::hci::WriteLocalNameCompleteBuilder::Create( |
| 923 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 924 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | void DualModeController::HciWriteExtendedInquiryResponse(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 928 | ASSERT_LOG(args.size() == 241, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 929 | // Strip FEC byte and trailing zeros |
| 930 | std::vector<uint8_t> clipped(args.begin() + 1, args.begin() + LastNonZero(args) + 1); |
| 931 | properties_.SetExtendedInquiryData(clipped); |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 932 | LOG_WARN("Write EIR Inquiry - Size = %d (%d)", static_cast<int>(properties_.GetExtendedInquiryData().size()), |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 933 | static_cast<int>(clipped.size())); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 934 | auto packet = |
| 935 | bluetooth::hci::WriteExtendedInquiryResponseCompleteBuilder::Create( |
| 936 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 937 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 940 | void DualModeController::HciRefreshEncryptionKey(packets::PacketView<true> args) { |
| 941 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | b293d73 | 2019-08-19 12:35:36 -0700 | [diff] [blame] | 942 | auto args_itr = args.begin(); |
| 943 | uint16_t handle = args_itr.extract<uint16_t>(); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 944 | auto status_packet = |
| 945 | bluetooth::hci::RefreshEncryptionKeyStatusBuilder::Create( |
| 946 | bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets); |
| 947 | send_event_(std::move(status_packet)); |
Myles Watson | b293d73 | 2019-08-19 12:35:36 -0700 | [diff] [blame] | 948 | // TODO: Support this in the link layer |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 949 | auto complete_packet = |
| 950 | bluetooth::hci::EncryptionKeyRefreshCompleteBuilder::Create( |
| 951 | bluetooth::hci::ErrorCode::SUCCESS, handle); |
| 952 | send_event_(std::move(complete_packet)); |
Myles Watson | b293d73 | 2019-08-19 12:35:36 -0700 | [diff] [blame] | 953 | } |
| 954 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 955 | void DualModeController::HciWriteVoiceSetting(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 956 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 957 | auto packet = bluetooth::hci::WriteVoiceSettingCompleteBuilder::Create( |
| 958 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 959 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void DualModeController::HciWriteCurrentIacLap(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 963 | ASSERT(args.size() > 0); |
| 964 | ASSERT(args.size() == 1 + (3 * args[0])); // count + 3-byte IACs |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 965 | auto packet = bluetooth::hci::WriteCurrentIacLapCompleteBuilder::Create( |
| 966 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 967 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | void DualModeController::HciWriteInquiryScanActivity(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 971 | ASSERT_LOG(args.size() == 4, "%s size=%zu", __func__, args.size()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 972 | auto packet = bluetooth::hci::WriteInquiryScanActivityCompleteBuilder::Create( |
| 973 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 974 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | void DualModeController::HciWriteScanEnable(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 978 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 979 | link_layer_controller_.SetInquiryScanEnable(args[0] & 0x1); |
| 980 | link_layer_controller_.SetPageScanEnable(args[0] & 0x2); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 981 | auto packet = bluetooth::hci::WriteScanEnableCompleteBuilder::Create( |
| 982 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 983 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | void DualModeController::HciSetEventFilter(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 987 | ASSERT(args.size() > 0); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 988 | auto packet = bluetooth::hci::SetEventFilterCompleteBuilder::Create( |
| 989 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 990 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | void DualModeController::HciInquiry(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 994 | ASSERT_LOG(args.size() == 5, "%s size=%zu", __func__, args.size()); |
| 995 | link_layer_controller_.SetInquiryLAP(args[0] | (args[1], 8) | (args[2], 16)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 996 | link_layer_controller_.SetInquiryMaxResponses(args[4]); |
| 997 | link_layer_controller_.StartInquiry(std::chrono::milliseconds(args[3] * 1280)); |
| 998 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 999 | auto packet = bluetooth::hci::InquiryStatusBuilder::Create( |
| 1000 | bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets); |
| 1001 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | void DualModeController::HciInquiryCancel(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1005 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1006 | link_layer_controller_.InquiryCancel(); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1007 | auto packet = bluetooth::hci::InquiryCancelCompleteBuilder::Create( |
| 1008 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1009 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | void DualModeController::HciAcceptConnectionRequest(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1013 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1014 | Address addr = args.begin().extract<Address>(); |
| 1015 | bool try_role_switch = args[6] == 0; |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1016 | auto status = |
| 1017 | link_layer_controller_.AcceptConnectionRequest(addr, try_role_switch); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1018 | auto packet = bluetooth::hci::AcceptConnectionRequestStatusBuilder::Create( |
| 1019 | status, kNumCommandPackets); |
| 1020 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | void DualModeController::HciRejectConnectionRequest(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1024 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1025 | auto args_itr = args.begin(); |
| 1026 | Address addr = args_itr.extract<Address>(); |
| 1027 | uint8_t reason = args_itr.extract<uint8_t>(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1028 | auto status = link_layer_controller_.RejectConnectionRequest(addr, reason); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1029 | auto packet = bluetooth::hci::RejectConnectionRequestStatusBuilder::Create( |
| 1030 | status, kNumCommandPackets); |
| 1031 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | void DualModeController::HciLinkKeyRequestReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1035 | ASSERT_LOG(args.size() == 22, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1036 | Address addr = args.begin().extract<Address>(); |
| 1037 | packets::PacketView<true> key = args.SubViewLittleEndian(6, 22); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1038 | auto status = link_layer_controller_.LinkKeyRequestReply(addr, key); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1039 | auto packet = bluetooth::hci::LinkKeyRequestReplyCompleteBuilder::Create( |
| 1040 | kNumCommandPackets, status); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1041 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
| 1044 | void DualModeController::HciLinkKeyRequestNegativeReply(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1045 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1046 | Address addr = args.begin().extract<Address>(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1047 | auto status = link_layer_controller_.LinkKeyRequestNegativeReply(addr); |
| 1048 | auto packet = |
| 1049 | bluetooth::hci::LinkKeyRequestNegativeReplyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1050 | kNumCommandPackets, status, addr); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1051 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | void DualModeController::HciDeleteStoredLinkKey(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1055 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1056 | |
| 1057 | uint16_t deleted_keys = 0; |
| 1058 | |
| 1059 | if (args[6] == 0) { |
| 1060 | Address addr = args.begin().extract<Address>(); |
| 1061 | deleted_keys = security_manager_.DeleteKey(addr); |
| 1062 | } |
| 1063 | |
| 1064 | if (args[6] == 1) { |
| 1065 | security_manager_.DeleteAllKeys(); |
| 1066 | } |
| 1067 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1068 | auto packet = bluetooth::hci::DeleteStoredLinkKeyCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1069 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, deleted_keys); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1070 | |
| 1071 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | void DualModeController::HciRemoteNameRequest(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1075 | ASSERT_LOG(args.size() == 10, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1076 | |
| 1077 | Address remote_addr = args.begin().extract<Address>(); |
| 1078 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1079 | auto status = link_layer_controller_.SendCommandToRemoteByAddress( |
| 1080 | bluetooth::hci::OpCode::REMOTE_NAME_REQUEST, args, remote_addr, false); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1081 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1082 | auto packet = bluetooth::hci::RemoteNameRequestStatusBuilder::Create( |
| 1083 | status, kNumCommandPackets); |
| 1084 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | void DualModeController::HciLeSetEventMask(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1088 | ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1089 | /* |
| 1090 | uint64_t mask = args.begin().extract<uint64_t>(); |
| 1091 | link_layer_controller_.SetLeEventMask(mask); |
| 1092 | */ |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1093 | auto packet = bluetooth::hci::LeSetEventMaskCompleteBuilder::Create( |
| 1094 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1095 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | void DualModeController::HciLeReadBufferSize(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1099 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1100 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1101 | bluetooth::hci::LeBufferSize le_buffer_size; |
| 1102 | le_buffer_size.le_data_packet_length_ = properties_.GetLeDataPacketLength(); |
| 1103 | le_buffer_size.total_num_le_packets_ = properties_.GetTotalNumLeDataPackets(); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1104 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1105 | auto packet = bluetooth::hci::LeReadBufferSizeCompleteBuilder::Create( |
| 1106 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, le_buffer_size); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1107 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void DualModeController::HciLeReadLocalSupportedFeatures(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1111 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1112 | auto packet = |
| 1113 | bluetooth::hci::LeReadLocalSupportedFeaturesCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1114 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1115 | properties_.GetLeSupportedFeatures()); |
| 1116 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1117 | } |
| 1118 | |
| 1119 | void DualModeController::HciLeSetRandomAddress(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1120 | ASSERT_LOG(args.size() == 6, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1121 | properties_.SetLeAddress(args.begin().extract<Address>()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1122 | auto packet = bluetooth::hci::LeSetRandomAddressCompleteBuilder::Create( |
| 1123 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1124 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | void DualModeController::HciLeSetAdvertisingParameters(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1128 | ASSERT_LOG(args.size() == 15, "%s size=%zu", __func__, args.size()); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1129 | auto args_itr = args.begin(); |
| 1130 | properties_.SetLeAdvertisingParameters( |
| 1131 | args_itr.extract<uint16_t>() /* AdverisingIntervalMin */, |
| 1132 | args_itr.extract<uint16_t>() /* AdverisingIntervalMax */, args_itr.extract<uint8_t>() /* AdverisingType */, |
| 1133 | args_itr.extract<uint8_t>() /* OwnAddressType */, args_itr.extract<uint8_t>() /* PeerAddressType */, |
| 1134 | args_itr.extract<Address>() /* PeerAddress */, args_itr.extract<uint8_t>() /* AdvertisingChannelMap */, |
| 1135 | args_itr.extract<uint8_t>() /* AdvertisingFilterPolicy */ |
| 1136 | ); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1137 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1138 | auto packet = |
| 1139 | bluetooth::hci::LeSetAdvertisingParametersCompleteBuilder::Create( |
| 1140 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1141 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | void DualModeController::HciLeSetAdvertisingData(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1145 | ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size()); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1146 | properties_.SetLeAdvertisement(std::vector<uint8_t>(args.begin() + 1, args.end())); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1147 | auto packet = bluetooth::hci::LeSetAdvertisingDataCompleteBuilder::Create( |
| 1148 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1149 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1150 | } |
| 1151 | |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1152 | void DualModeController::HciLeSetScanResponseData(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1153 | ASSERT_LOG(args.size() == 32, "%s size=%zu", __func__, args.size()); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1154 | properties_.SetLeScanResponse(std::vector<uint8_t>(args.begin() + 1, args.end())); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1155 | auto packet = bluetooth::hci::LeSetScanResponseDataCompleteBuilder::Create( |
| 1156 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1157 | send_event_(std::move(packet)); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | void DualModeController::HciLeSetAdvertisingEnable(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1161 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1162 | auto status = link_layer_controller_.SetLeAdvertisingEnable( |
| 1163 | args.begin().extract<uint8_t>()); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1164 | auto packet = bluetooth::hci::LeSetAdvertisingEnableCompleteBuilder::Create( |
| 1165 | kNumCommandPackets, status); |
| 1166 | send_event_(std::move(packet)); |
Myles Watson | 99aea89 | 2019-09-02 15:54:08 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1169 | void DualModeController::HciLeSetScanParameters(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1170 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1171 | link_layer_controller_.SetLeScanType(args[0]); |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1172 | link_layer_controller_.SetLeScanInterval(args[1] | (args[2], 8)); |
| 1173 | link_layer_controller_.SetLeScanWindow(args[3] | (args[4], 8)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1174 | link_layer_controller_.SetLeAddressType(args[5]); |
| 1175 | link_layer_controller_.SetLeScanFilterPolicy(args[6]); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1176 | auto packet = bluetooth::hci::LeSetScanParametersCompleteBuilder::Create( |
| 1177 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1178 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void DualModeController::HciLeSetScanEnable(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1182 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
| 1183 | LOG_INFO("SetScanEnable: %d %d", args[0], args[1]); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1184 | link_layer_controller_.SetLeScanEnable(args[0]); |
| 1185 | link_layer_controller_.SetLeFilterDuplicates(args[1]); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1186 | auto packet = bluetooth::hci::LeSetScanEnableCompleteBuilder::Create( |
| 1187 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1188 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | void DualModeController::HciLeCreateConnection(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1192 | ASSERT_LOG(args.size() == 25, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1193 | auto args_itr = args.begin(); |
| 1194 | link_layer_controller_.SetLeScanInterval(args_itr.extract<uint16_t>()); |
| 1195 | link_layer_controller_.SetLeScanWindow(args_itr.extract<uint16_t>()); |
| 1196 | uint8_t initiator_filter_policy = args_itr.extract<uint8_t>(); |
| 1197 | link_layer_controller_.SetLeInitiatorFilterPolicy(initiator_filter_policy); |
| 1198 | |
| 1199 | if (initiator_filter_policy == 0) { // White list not used |
| 1200 | uint8_t peer_address_type = args_itr.extract<uint8_t>(); |
| 1201 | Address peer_address = args_itr.extract<Address>(); |
| 1202 | link_layer_controller_.SetLePeerAddressType(peer_address_type); |
| 1203 | link_layer_controller_.SetLePeerAddress(peer_address); |
| 1204 | } |
| 1205 | link_layer_controller_.SetLeAddressType(args_itr.extract<uint8_t>()); |
| 1206 | link_layer_controller_.SetLeConnectionIntervalMin(args_itr.extract<uint16_t>()); |
| 1207 | link_layer_controller_.SetLeConnectionIntervalMax(args_itr.extract<uint16_t>()); |
| 1208 | link_layer_controller_.SetLeConnectionLatency(args_itr.extract<uint16_t>()); |
| 1209 | link_layer_controller_.SetLeSupervisionTimeout(args_itr.extract<uint16_t>()); |
| 1210 | link_layer_controller_.SetLeMinimumCeLength(args_itr.extract<uint16_t>()); |
| 1211 | link_layer_controller_.SetLeMaximumCeLength(args_itr.extract<uint16_t>()); |
| 1212 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1213 | auto status = link_layer_controller_.SetLeConnect(true); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1214 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1215 | auto packet = bluetooth::hci::LeCreateConnectionStatusBuilder::Create( |
| 1216 | status, kNumCommandPackets); |
| 1217 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | void DualModeController::HciLeConnectionUpdate(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1221 | ASSERT_LOG(args.size() == 14, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1222 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1223 | auto status_packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create( |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1224 | bluetooth::hci::ErrorCode::CONNECTION_REJECTED_UNACCEPTABLE_BD_ADDR, |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1225 | kNumCommandPackets); |
| 1226 | send_event_(std::move(status_packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1227 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1228 | auto complete_packet = |
| 1229 | bluetooth::hci::LeConnectionUpdateCompleteBuilder::Create( |
| 1230 | bluetooth::hci::ErrorCode::SUCCESS, 0x0002, 0x0006, 0x0000, 0x01f4); |
| 1231 | send_event_(std::move(complete_packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
| 1234 | void DualModeController::HciCreateConnection(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1235 | ASSERT_LOG(args.size() == 13, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1236 | |
| 1237 | auto args_itr = args.begin(); |
| 1238 | Address address = args_itr.extract<Address>(); |
| 1239 | uint16_t packet_type = args_itr.extract<uint16_t>(); |
| 1240 | uint8_t page_scan_mode = args_itr.extract<uint8_t>(); |
| 1241 | uint16_t clock_offset = args_itr.extract<uint16_t>(); |
| 1242 | uint8_t allow_role_switch = args_itr.extract<uint8_t>(); |
| 1243 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1244 | auto status = link_layer_controller_.CreateConnection( |
| 1245 | address, packet_type, page_scan_mode, clock_offset, allow_role_switch); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1246 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1247 | auto packet = bluetooth::hci::CreateConnectionStatusBuilder::Create( |
| 1248 | status, kNumCommandPackets); |
| 1249 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1250 | } |
| 1251 | |
| 1252 | void DualModeController::HciDisconnect(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1253 | ASSERT_LOG(args.size() == 3, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1254 | |
| 1255 | auto args_itr = args.begin(); |
| 1256 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 1257 | uint8_t reason = args_itr.extract<uint8_t>(); |
| 1258 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1259 | auto status = link_layer_controller_.Disconnect(handle, reason); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1260 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1261 | auto packet = bluetooth::hci::DisconnectStatusBuilder::Create( |
| 1262 | status, kNumCommandPackets); |
| 1263 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | void DualModeController::HciLeConnectionCancel(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1267 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1268 | link_layer_controller_.SetLeConnect(false); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1269 | auto packet = bluetooth::hci::LeCreateConnectionCancelStatusBuilder::Create( |
| 1270 | bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets); |
| 1271 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1272 | /* For testing Jakub's patch: Figure out a neat way to call this without |
| 1273 | recompiling. I'm thinking about a bad device. */ |
| 1274 | /* |
| 1275 | SendCommandCompleteOnlyStatus(OpCode::LE_CREATE_CONNECTION_CANCEL, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1276 | bluetooth::hci::ErrorCode::COMMAND_DISALLOWED); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1277 | */ |
| 1278 | } |
| 1279 | |
| 1280 | void DualModeController::HciLeReadWhiteListSize(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1281 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1282 | auto packet = bluetooth::hci::LeReadWhiteListSizeCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1283 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1284 | properties_.GetLeWhiteListSize()); |
| 1285 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | void DualModeController::HciLeClearWhiteList(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1289 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1290 | link_layer_controller_.LeWhiteListClear(); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1291 | auto packet = bluetooth::hci::LeClearWhiteListCompleteBuilder::Create( |
| 1292 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1293 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | void DualModeController::HciLeAddDeviceToWhiteList(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1297 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1298 | |
| 1299 | if (link_layer_controller_.LeWhiteListFull()) { |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1300 | auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create( |
| 1301 | kNumCommandPackets, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1302 | bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1303 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1304 | return; |
| 1305 | } |
| 1306 | auto args_itr = args.begin(); |
| 1307 | uint8_t addr_type = args_itr.extract<uint8_t>(); |
| 1308 | Address address = args_itr.extract<Address>(); |
| 1309 | link_layer_controller_.LeWhiteListAddDevice(address, addr_type); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1310 | auto packet = bluetooth::hci::LeAddDeviceToWhiteListCompleteBuilder::Create( |
| 1311 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1312 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | void DualModeController::HciLeRemoveDeviceFromWhiteList(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1316 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1317 | |
| 1318 | auto args_itr = args.begin(); |
| 1319 | uint8_t addr_type = args_itr.extract<uint8_t>(); |
| 1320 | Address address = args_itr.extract<Address>(); |
| 1321 | link_layer_controller_.LeWhiteListRemoveDevice(address, addr_type); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1322 | auto packet = |
| 1323 | bluetooth::hci::LeRemoveDeviceFromWhiteListCompleteBuilder::Create( |
| 1324 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1325 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1326 | } |
| 1327 | |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1328 | void DualModeController::HciLeClearResolvingList( |
| 1329 | packets::PacketView<true> args) { |
| 1330 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
| 1331 | link_layer_controller_.LeResolvingListClear(); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1332 | auto packet = bluetooth::hci::LeClearResolvingListCompleteBuilder::Create( |
| 1333 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1334 | send_event_(std::move(packet)); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1335 | } |
| 1336 | |
| 1337 | void DualModeController::HciLeAddDeviceToResolvingList( |
| 1338 | packets::PacketView<true> args) { |
| 1339 | ASSERT_LOG(args.size() == 39, "%s size=%zu", __func__, args.size()); |
| 1340 | |
| 1341 | if (link_layer_controller_.LeResolvingListFull()) { |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1342 | auto packet = |
| 1343 | bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create( |
| 1344 | kNumCommandPackets, |
| 1345 | bluetooth::hci::ErrorCode::MEMORY_CAPACITY_EXCEEDED); |
| 1346 | send_event_(std::move(packet)); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1347 | return; |
| 1348 | } |
| 1349 | auto args_itr = args.begin(); |
| 1350 | uint8_t addr_type = args_itr.extract<uint8_t>(); |
| 1351 | Address address = args_itr.extract<Address>(); |
| 1352 | std::array<uint8_t, LinkLayerController::kIrk_size> peerIrk; |
| 1353 | std::array<uint8_t, LinkLayerController::kIrk_size> localIrk; |
| 1354 | for (size_t irk_ind = 0; irk_ind < LinkLayerController::kIrk_size; |
| 1355 | irk_ind++) { |
| 1356 | peerIrk[irk_ind] = args_itr.extract<uint8_t>(); |
| 1357 | } |
| 1358 | |
| 1359 | for (size_t irk_ind = 0; irk_ind < LinkLayerController::kIrk_size; |
| 1360 | irk_ind++) { |
| 1361 | localIrk[irk_ind] = args_itr.extract<uint8_t>(); |
| 1362 | } |
| 1363 | |
| 1364 | link_layer_controller_.LeResolvingListAddDevice(address, addr_type, peerIrk, |
| 1365 | localIrk); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1366 | auto packet = |
| 1367 | bluetooth::hci::LeAddDeviceToResolvingListCompleteBuilder::Create( |
| 1368 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1369 | send_event_(std::move(packet)); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1370 | } |
| 1371 | |
| 1372 | void DualModeController::HciLeRemoveDeviceFromResolvingList( |
| 1373 | packets::PacketView<true> args) { |
| 1374 | ASSERT_LOG(args.size() == 7, "%s size=%zu", __func__, args.size()); |
| 1375 | |
| 1376 | auto args_itr = args.begin(); |
| 1377 | uint8_t addr_type = args_itr.extract<uint8_t>(); |
| 1378 | Address address = args_itr.extract<Address>(); |
| 1379 | link_layer_controller_.LeResolvingListRemoveDevice(address, addr_type); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1380 | auto packet = |
| 1381 | bluetooth::hci::LeRemoveDeviceFromResolvingListCompleteBuilder::Create( |
| 1382 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1383 | send_event_(std::move(packet)); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
| 1386 | void DualModeController::HciLeSetPrivacyMode(packets::PacketView<true> args) { |
| 1387 | ASSERT_LOG(args.size() == 8, "%s size=%zu", __func__, args.size()); |
| 1388 | |
| 1389 | auto args_itr = args.begin(); |
| 1390 | uint8_t peer_identity_address_type = args_itr.extract<uint8_t>(); |
| 1391 | Address peer_identity_address = args_itr.extract<Address>(); |
| 1392 | uint8_t privacy_mode = args_itr.extract<uint8_t>(); |
| 1393 | |
| 1394 | if (link_layer_controller_.LeResolvingListContainsDevice( |
| 1395 | peer_identity_address, peer_identity_address_type)) { |
| 1396 | link_layer_controller_.LeSetPrivacyMode( |
| 1397 | peer_identity_address_type, peer_identity_address, privacy_mode); |
| 1398 | } |
| 1399 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1400 | auto packet = bluetooth::hci::LeSetPrivacyModeCompleteBuilder::Create( |
| 1401 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1402 | send_event_(std::move(packet)); |
Calvin Huang | ee1980c | 2019-11-01 16:35:55 -0700 | [diff] [blame] | 1403 | } |
| 1404 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1405 | void DualModeController::HciLeReadRemoteFeatures(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1406 | ASSERT_LOG(args.size() == 2, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1407 | |
| 1408 | uint16_t handle = args.begin().extract<uint16_t>(); |
| 1409 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1410 | auto status = link_layer_controller_.SendCommandToRemoteByHandle( |
| 1411 | bluetooth::hci::OpCode::LE_READ_REMOTE_FEATURES, args, handle); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1412 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1413 | auto packet = bluetooth::hci::LeConnectionUpdateStatusBuilder::Create( |
| 1414 | status, kNumCommandPackets); |
| 1415 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | void DualModeController::HciLeRand(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1419 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1420 | uint64_t random_val = 0; |
| 1421 | for (size_t rand_bytes = 0; rand_bytes < sizeof(uint64_t); rand_bytes += sizeof(RAND_MAX)) { |
| 1422 | random_val = (random_val << (8 * sizeof(RAND_MAX))) | random(); |
| 1423 | } |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1424 | |
| 1425 | auto packet = bluetooth::hci::LeRandCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1426 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, random_val); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1427 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
| 1430 | void DualModeController::HciLeReadSupportedStates(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1431 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1432 | auto packet = bluetooth::hci::LeReadSupportedStatesCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1433 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1434 | properties_.GetLeSupportedStates()); |
| 1435 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | void DualModeController::HciLeVendorCap(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1439 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1440 | vector<uint8_t> caps = properties_.GetLeVendorCap(); |
| 1441 | if (caps.size() == 0) { |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1442 | SendCommandCompleteUnknownOpCodeEvent(static_cast<uint16_t>( |
| 1443 | bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1444 | return; |
| 1445 | } |
| 1446 | |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1447 | std::unique_ptr<bluetooth::packet::RawBuilder> raw_builder_ptr = |
| 1448 | std::make_unique<bluetooth::packet::RawBuilder>(); |
| 1449 | raw_builder_ptr->AddOctets1( |
| 1450 | static_cast<uint8_t>(bluetooth::hci::ErrorCode::SUCCESS)); |
| 1451 | raw_builder_ptr->AddOctets(properties_.GetLeVendorCap()); |
| 1452 | |
| 1453 | auto packet = bluetooth::hci::CommandCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1454 | kNumCommandPackets, bluetooth::hci::OpCode::LE_GET_VENDOR_CAPABILITIES, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1455 | std::move(raw_builder_ptr)); |
| 1456 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1457 | } |
| 1458 | |
| 1459 | void DualModeController::HciLeVendorMultiAdv(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1460 | ASSERT(args.size() > 0); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1461 | SendCommandCompleteUnknownOpCodeEvent( |
| 1462 | static_cast<uint16_t>(bluetooth::hci::OpCode::LE_MULTI_ADVT)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | void DualModeController::HciLeAdvertisingFilter(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1466 | ASSERT(args.size() > 0); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1467 | SendCommandCompleteUnknownOpCodeEvent( |
| 1468 | static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ADV_FILTER)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | void DualModeController::HciLeEnergyInfo(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1472 | ASSERT(args.size() > 0); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1473 | SendCommandCompleteUnknownOpCodeEvent( |
| 1474 | static_cast<uint16_t>(bluetooth::hci::OpCode::LE_ENERGY_INFO)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1475 | } |
| 1476 | |
| 1477 | void DualModeController::HciLeExtendedScanParams(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1478 | ASSERT(args.size() > 0); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1479 | SendCommandCompleteUnknownOpCodeEvent( |
| 1480 | static_cast<uint16_t>(bluetooth::hci::OpCode::LE_EXTENDED_SCAN_PARAMS)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | void DualModeController::HciLeStartEncryption(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1484 | ASSERT_LOG(args.size() == 28, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1485 | |
| 1486 | auto args_itr = args.begin(); |
| 1487 | uint16_t handle = args_itr.extract<uint16_t>(); |
| 1488 | // uint64_t random_number = args_itr.extract<uint64_t>(); |
| 1489 | // uint16_t encrypted_diversifier = args_itr.extract<uint16_t>(); |
| 1490 | // std::vector<uint8_t> long_term_key; |
| 1491 | // for (size_t i = 0; i < 16; i++) { |
| 1492 | // long_term_key.push_back(args_itr.extract<uint18_t>(); |
| 1493 | // } |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1494 | auto status_packet = bluetooth::hci::LeStartEncryptionStatusBuilder::Create( |
| 1495 | bluetooth::hci::ErrorCode::SUCCESS, kNumCommandPackets); |
| 1496 | send_event_(std::move(status_packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1497 | |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1498 | auto complete_packet = bluetooth::hci::EncryptionChangeBuilder::Create( |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1499 | bluetooth::hci::ErrorCode::SUCCESS, handle, |
| 1500 | bluetooth::hci::EncryptionEnabled::OFF); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1501 | send_event_(std::move(complete_packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1502 | #if 0 |
| 1503 | |
| 1504 | std::shared_ptr<packets::AclPacketBuilder> encryption_information = |
| 1505 | std::make_shared<packets::AclPacketBuilder>( |
| 1506 | 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT, |
| 1507 | std::vector<uint8_t>({})); |
| 1508 | |
| 1509 | encryption_information->AddPayloadOctets2(0x0011); |
| 1510 | encryption_information->AddPayloadOctets2(0x0006); |
| 1511 | encryption_information->AddPayloadOctets1(0x06); |
| 1512 | encryption_information->AddPayloadOctets8(0x0706050403020100); |
| 1513 | encryption_information->AddPayloadOctets8(0x0F0E0D0C0B0A0908); |
| 1514 | |
| 1515 | send_acl_(encryption_information); |
| 1516 | |
| 1517 | encryption_information = std::make_shared<packets::AclPacketBuilder>( |
| 1518 | 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT, |
| 1519 | std::vector<uint8_t>({})); |
| 1520 | |
| 1521 | encryption_information->AddPayloadOctets2(0x000B); |
| 1522 | encryption_information->AddPayloadOctets2(0x0006); |
| 1523 | encryption_information->AddPayloadOctets1(0x07); |
| 1524 | encryption_information->AddPayloadOctets2(0xBEEF); |
| 1525 | encryption_information->AddPayloadOctets8(0x0706050403020100); |
| 1526 | |
| 1527 | send_acl_(encryption_information); |
| 1528 | |
| 1529 | encryption_information = std::make_shared<packets::AclPacketBuilder>( |
| 1530 | 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT, |
| 1531 | std::vector<uint8_t>({})); |
| 1532 | |
| 1533 | encryption_information->AddPayloadOctets2(0x0011); |
| 1534 | encryption_information->AddPayloadOctets2(0x0006); |
| 1535 | encryption_information->AddPayloadOctets1(0x08); |
| 1536 | encryption_information->AddPayloadOctets8(0x0F0E0D0C0B0A0908); |
| 1537 | encryption_information->AddPayloadOctets8(0x0706050403020100); |
| 1538 | |
| 1539 | send_acl_(encryption_information); |
| 1540 | |
| 1541 | encryption_information = std::make_shared<packets::AclPacketBuilder>( |
| 1542 | 0x0002, Acl::FIRST_AUTOMATICALLY_FLUSHABLE, Acl::POINT_TO_POINT, |
| 1543 | std::vector<uint8_t>({})); |
| 1544 | |
| 1545 | encryption_information->AddPayloadOctets2(0x0008); |
| 1546 | encryption_information->AddPayloadOctets2(0x0006); |
| 1547 | encryption_information->AddPayloadOctets1(0x09); |
| 1548 | encryption_information->AddPayloadOctets1(0x01); |
| 1549 | encryption_information->AddPayloadOctets6(0xDEADBEEFF00D); |
| 1550 | send_acl_(encryption_information); |
| 1551 | // send_event_(packets::EventPacketBuilder::CreateLeStartEncryption()->ToVector()); |
| 1552 | |
| 1553 | #endif |
| 1554 | } |
| 1555 | |
| 1556 | void DualModeController::HciReadLoopbackMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1557 | ASSERT_LOG(args.size() == 0, "%s size=%zu", __func__, args.size()); |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1558 | auto packet = bluetooth::hci::ReadLoopbackModeCompleteBuilder::Create( |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1559 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS, |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1560 | static_cast<bluetooth::hci::LoopbackMode>(loopback_mode_)); |
| 1561 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | void DualModeController::HciWriteLoopbackMode(packets::PacketView<true> args) { |
Myles Watson | 1a0a0da | 2019-10-17 11:36:33 -0700 | [diff] [blame] | 1565 | ASSERT_LOG(args.size() == 1, "%s size=%zu", __func__, args.size()); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1566 | loopback_mode_ = static_cast<hci::LoopbackMode>(args[0]); |
| 1567 | // ACL channel |
| 1568 | uint16_t acl_handle = 0x123; |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1569 | auto packet_acl = bluetooth::hci::ConnectionCompleteBuilder::Create( |
| 1570 | bluetooth::hci::ErrorCode::SUCCESS, acl_handle, properties_.GetAddress(), |
| 1571 | bluetooth::hci::LinkType::ACL, bluetooth::hci::Enable::DISABLED); |
| 1572 | send_event_(std::move(packet_acl)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1573 | // SCO channel |
| 1574 | uint16_t sco_handle = 0x345; |
Chienyuan | 3d8a803 | 2019-11-01 18:04:07 +0800 | [diff] [blame] | 1575 | auto packet_sco = bluetooth::hci::ConnectionCompleteBuilder::Create( |
| 1576 | bluetooth::hci::ErrorCode::SUCCESS, sco_handle, properties_.GetAddress(), |
| 1577 | bluetooth::hci::LinkType::SCO, bluetooth::hci::Enable::DISABLED); |
| 1578 | send_event_(std::move(packet_sco)); |
Chienyuan | c27da09 | 2019-11-20 19:29:43 +0800 | [diff] [blame^] | 1579 | auto packet = bluetooth::hci::WriteLoopbackModeCompleteBuilder::Create( |
| 1580 | kNumCommandPackets, bluetooth::hci::ErrorCode::SUCCESS); |
| 1581 | send_event_(std::move(packet)); |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1582 | } |
| 1583 | |
Myles Watson | 205c32e | 2019-11-12 13:16:32 -0800 | [diff] [blame] | 1584 | void DualModeController::SetAddress(Address address) { |
| 1585 | properties_.SetAddress(address); |
| 1586 | } |
| 1587 | |
Myles Watson | e22dde2 | 2019-01-18 11:42:33 -0800 | [diff] [blame] | 1588 | } // namespace test_vendor_lib |