// Resets the controller. For now, this just generates and sends a command
// complete event back to the HCI.
+ // OGF: 0x0003
+ // OCF: 0x0003
// Command parameters: none.
// Command response:
// Status (1 octet)
// 0x01-0xFF: Failed. Check error codes.
void HciReset(const std::vector<std::uint8_t>& args);
+ // Reads the max size of the payload for ACL/SCO data packets sent from the
+ // host to the controller. Also reads the number of ACL/SCO data packets
+ // that can be stored in the controller's data buffer.
+ // OGF: 0x0004
+ // OGF: 0x0005
+ // Command parameters: none.
+ void HciReadBufferSize(const std::vector<std::uint8_t>& args);
+
+ // Notifies the controller about the max payload size for ACL/SCO data
+ // packets sent from the controller to the host. Also notifies the controller
+ // about the number of ACL/SCO data packets that can be stored in the host's
+ // data buffers.
+ // OGF: 0x0003
+ // OCF: 0x0033
+ // Command parameters: none.
+ void HciHostBufferSize(const std::vector<std::uint8_t>& args);
+
+ // Gives the host the controller's version information.
+ // OGF: 0x0004
+ // OCF: 0x0001
+ // Command parameters: none.
+ void HciReadLocalVersionInformation(const std::vector<std::uint8_t>& args);
+
+ // Gives the host the controller's address. See the Bluetooth Core
+ // Specification, Version 4.2, Volume 2, Part B (page 58) for more details
+ // about how the address is used.
+ // OGF: 0x0004
+ // OCF: 0x0009
+ // Command parameters: none.
+ void HciReadBdAddr(const std::vector<std::uint8_t>& args);
+
+ // Reads the list of HCI commands the controller supports.
+ // OGF: 0x0004
+ // OCF: 0x0002
+ // Command parameters: none.
+ void HciReadLocalSupportedCommands(const std::vector<std::uint8_t>& args);
+
+ // Returns the requested page of extended LMP features.
+ // OGF: 0x0004
+ // OCF: 0x0004
+ // Command parameters:
+ // Page Number (1 octet)
+ // 0x00: Requests the normal LMP features as returned
+ // by HciReadLocalSupportedCommands().
+ // 0x01-0xFF: Returns the
+ // corresponding page of features.
+ void HciReadLocalExtendedFeatures(const std::vector<std::uint8_t>& args);
+
+ // Toggles simple pairing mode.
+ // OGF: 0x0003
+ // OCF: 0x0056
+ // Command parameters:
+ // Simple Pairing Mode (1 octet)
+ // 0x00: Disables simple pairing.
+ // 0x01: Enables simple pairing.
+ // 0x02-0xFF: Reserved.
+ void HciWriteSimplePairingMode(const std::vector<std::uint8_t>& args);
+
+ // Used to set the LE Supported and Simultaneous LE and BREDR to Same Device
+ // Capable Link Manager Protocol feature bits.
+ // OGF: 0x0003
+ // OCF: 0x006D
+ // Command parameters:
+ // LE supported host (1 octet)
+ // 0x00: LE Supported disabled.
+ // 0x01: LE Supported enabled.
+ // 0x02-0xFF: Reserved.
+ // Simultaneous LE Host (1 octet)
+ // 0x00: Simultaneous LE and BREDR to Same Device Capable disabled.
+ // 0x01-0xFF Reserved.
+ void HciWriteLeHostSupport(const std::vector<std::uint8_t>& args);
+
+ // Used to control which events are generated by the HCI for the host.
+ // OGF: 0x0003
+ // OCF: 0x0001
+ // Command parameters:
+ // Event Mask (8 octets)
+ // See the Bluetooth Core Specification, Version 4.2, Volume 2, Section
+ // 7.3.1 (page 642) for details about the event mask.
+ void HciSetEventMask(const std::vector<std::uint8_t>& args);
+
+ // Writes the inquiry mode configuration parameter of the local controller.
+ // OGF: 0x0003
+ // OCF: 0x0045
+ // Command parameters:
+ // Inquiry Mode (1 octet)
+ // 0x00: Standard inquiry result event format.
+ // 0x01: Inquiry result format with RSSI.
+ // 0x02: Inquiry result with RSSI format or extended inquiry result
+ // format.
+ // 0x03-0xFF: Reserved.
+ void HciWriteInquiryMode(const std::vector<std::uint8_t>& args);
+
+ // Writes the Page Scan Type configuration parameter of the local controller.
+ // OGF: 0x0003
+ // OCF: 0x0047
+ // Command parameters:
+ // Page Scan Type (1 octet)
+ // 0x00: Standard scan.
+ // 0x01: Interlaced scan.
+ // 0x02-0xFF: Reserved.
+ void HciWritePageScanType(const std::vector<std::uint8_t>& args);
+
+ // Writes the Inquiry Scan Type configuration parameter of the local
+ // controller.
+ // OGF: 0x0003
+ // OCF: 0x0043
+ // Command parameters:
+ // Scan Type (1 octet)
+ // 0x00: Standard scan.
+ // 0x01: Interlaced scan.
+ // 0x02-0xFF: Reserved.
+ void HciWriteInquiryScanType(const std::vector<std::uint8_t>& args);
+
+ // Write the value for the class of device parameter.
+ // OGF: 0x0003
+ // OCF: 0x0024
+ // Command parameters:
+ // Class of Device (3 octets)
+ void HciWriteClassOfDevice(const std::vector<std::uint8_t>& args);
+
+ // Writes the value that defines the maximum time the local link manager shall
+ // wait for a baseband page response from the remote device at a locally
+ // initiated connection attempt.
+ // OGF: 0x0003
+ // OCF: 0x0018
+ // Command parameters:
+ // Page Timeout (2 octets)
+ // 0: Illegal page timeout, must be larger than 0.
+ // 0xXXXX: Page timeout measured in number of baseband slots.
+ void HciWritePageTimeout(const std::vector<std::uint8_t>& args);
+
+ // Writes the default link policy configuration value which determines the
+ // initial value of the link policy settings for all new BR/EDR connections.
+ // OGF: 0x0002
+ // OCF: 0x000F
+ // Command parameters:
+ // Default Link Policy Settings (2 octets)
+ // 0x0000: Disable all LM modes default.
+ // 0x0001: Enable role switch.
+ // 0x0002: Enable hold mode.
+ // 0x0004: Enable sniff mode.
+ // 0x0008: Enable park state.
+ // 0x0010-0x8000: Reserved.
+ void HciWriteDefaultLinkPolicySettings(const std::vector<std::uint8_t>& args);
+
+ // Reads the stored user-friendly name for the controller.
+ // OGF: 0x0003
+ // OCF: 0x0014
+ // Command parameters: none.
+ void HciReadLocalName(const std::vector<std::uint8_t>& args);
+
+ // Reads the stored user-friendly name for the controller.
+ // OGF: 0x0003
+ // OCF: 0x0013
+ // Command parameters:
+ // Local Name (248 octets)
+ void HciWriteLocalName(const std::vector<std::uint8_t>& args);
+
+ // Writes the extended inquiry response to be sent during the extended inquiry
+ // ersponse procedure.
+ // OGF: 0x0003
+ // OCF: 0x0052
+ // Command parameters:
+ // FEC Required (1 octet)
+ // 0x00: FEC is not required.
+ // 0x01: FEC is required.
+ // 0x02-0xFF: Reserved.
+ void HciWriteExtendedInquiryResponse(const std::vector<std::uint8_t>& args);
+
+ // Writes the values for the voice setting configuration paramter.
+ // OGF: 0x0003
+ // OCF: 0x0026
+ // Command parameters:
+ // Voice setting (2 octets, 10 bits meaningful)
+ // See Section 6.12 (page 482).
+ void HciWriteVoiceSetting(const std::vector<std::uint8_t>& args);
+
+ // Writes the LAP(s) used to create the Inquiry Access Codes that the local
+ // controller is simultaneously scanning for during Inquiry Scans.
+ // OGF: 0x0003
+ // OCF: 0x003A
+ // Command parameters:
+ // Num Current IAC (1 octet)
+ // 0xXX: Specifies the number of IACs which are currently in use.
+ // IAC LAP (3 octets * Num Current IAC)
+ // 0xXXXXXX: LAP(s) used to create IAC. Ranges from 0x9E8B00-0x9E8B3F.
+ void HciWriteCurrentIacLap(const std::vector<std::uint8_t>& args);
+
+ // Writes the values for the inquiry scan interval and inquiry scan window
+ // configuration parameters.
+ // OGF: 0x0003
+ // OCF: 0x001E
+ // Command parameters:
+ // Inquiry Scan Interval (2 octets)
+ // See Section 6.2 (page 478).
+ // Inquiry Scan Window (2 octets)
+ // See Section 6.2 (page 479).
+ void HciWriteInquiryScanActivity(const std::vector<std::uint8_t>& args);
+
+ // Writes the value for the scan enable configuration parameter.
+ // OGF: 0x0003
+ // OCF: 0x001A
+ // Command parameters:
+ // Scan Enable (1 octet)
+ // 0x00: No scans enabled (default).
+ // 0x01: Inquiry scan enabled. Page scan disabled.
+ // 0x02: Inquiry scan disable. Page scan enabled.
+ // 0x03: Inquiry scan enabled. Page scan enabled.
+ // 0x04-0xFF: Reserved.
+ void HciWriteScanEnable(const std::vector<std::uint8_t>& args);
+
+ // Used by the host to specify different event filters.
+ // OGF: 0x0003
+ // OCF: 0x0005
+ // Command parameters:
+ // Filter Type (1 octet)
+ // 0x00: Clear all filters.
+ // 0x01: Inquiry result.
+ // 0x02: Connection setup.
+ // 0x03-0xFF: Reserved.
+ // Filter Condition Type (1 octet)
+ // 0x00: Return responses from all devices during the inquiry response.
+ // 0x01: A device with a specific class of device responded to the inquiry
+ // process.
+ // 0x02: A device with a specific BD Address responded to the inquiry
+ // process.
+ // 0x03-0xFF: Reserved.
+ // Condition (1 octet)
+ // 0x00: Allow connections from all devices.
+ // 0x01: Allow connections from a device with a specific class of device.
+ // 0x02: Allow connections from a device with a specific BD Address.
+ // 0x03-0xFF: Reserved.
+ void HciSetEventFilter(const std::vector<std::uint8_t>& args);
+
+ // Causes the BREDR Controller to enter inquiry mode where other nearby
+ // controllers can be discovered.
+ // OGF: 0x0001
+ // OCF: 0x0001
+ // Command parameters:
+ // LAP (3 octets)
+ // 0x9E8B00-0x9E8B3F: LAP from which the inquiry access code should be
+ // derived when the inquiry procedure is made.
+ // Inquiry Length (1 octet)
+ // 0xXX: Maximum amount of time specified before the inquiry is halted.
+ // Num Responses (1 octet)
+ // 0x00: Unlimited number of responses.
+ // 0xXX: Maximum number of responses from the inquiry before the inquiry
+ // is halted.
+ void HciInquiry(const std::vector<std::uint8_t>& args);
+
private:
// There will only be a single global instance of this class.
BREDRController();
// Disallow any copies of the singleton to be made.
DISALLOW_COPY_AND_ASSIGN(BREDRController);
+
+ // Specifies the format of Inquiry Result events to be returned during the
+ // Inquiry command.
+ // 0x00: Standard Inquiry Result event format (default).
+ // 0x01: Inquiry Result format with RSSI.
+ // 0x02 Inquiry Result with RSSI format or Extended Inquiry Result format.
+ // 0x03-0xFF: Reserved.
+ std::uint8_t inquiry_mode_;
};
} // namespace test_vendor_lib
// Creates and returns a command complete event packet. See the Bluetooth
// Core Specification Version 4.2, Volume 2, Part E, Section 7.7.14 (page 861)
// for more information about the command complete event.
- // |num_hci_command_packets| indicates the number of HCI command packets the
- // host can send to the controller. If |num_hci_command_packets| is 0, the
- // controller would like to stop receiving commands from the host (to indicate
- // readiness again, the controller sends a command complete event with
- // |command_opcode| to 0x0000 (no op) and |num_hci_command_packets| > 1).
- // |command_opcode| is the opcode of the command that caused this event.
- // |return_parameters| will contain any event specific parameters that should
- // be sent to the host.
+ // Event Parameters:
+ // |num_hci_command_packets|
+ // Indicates the number of HCI command packets the host can send to the
+ // controller. If |num_hci_command_packets| is 0, the controller would
+ // like to stop receiving commands from the host (to indicate
+ // readiness again, the controller sends a command complete event with
+ // |command_opcode| to 0x0000 (no op) and |num_hci_command_packets| > 1).
+ // |command_opcode|
+ // The opcode of the command that caused this event.
+ // |return_parameters|
+ // Contains any event specific parameters that should
+ // be sent to the host.
static std::unique_ptr<EventPacket> CreateCommandCompleteEvent(
std::uint8_t num_hci_command_packets, std::uint16_t command_opcode,
const std::vector<std::uint8_t>& event_return_parameters);
+ // Creates and returns a command complete event packet. See the Bluetooth
+ // Core Specification Version 4.2, Volume 2, Part E, Section 7.7.15 (page 862)
+ // for more information about the command complete event.
+ // Event Parameters:
+ // Status
+ // 0x00: Command currently in pending.
+ // 0x01-0xFF: Command failed.
+ // |num_hci_command_packets|
+ // Indicates the number of HCI command packets the host can send to the
+ // controller. If |num_hci_command_packets| is 0, the controller would
+ // like to stop receiving commands from the host (to indicate
+ // readiness again, the controller sends a command complete event with
+ // |command_opcode| to 0x0000 (no op) and |num_hci_command_packets| > 1).
+ // |command_opcode|
+ // The opcode of the command that caused this event.
+ static std::unique_ptr<EventPacket> CreateCommandStatusEvent(
+ std::uint8_t num_hci_command_packets, std::uint16_t command_opcode);
+
+ // Creates and returns an inquiry result event packet. See the Bluetooth
+ // Core Specification Version 4.2, Volume 2, Part E, Section 7.7.2 (page 844)
+ // for more information about the command complete event.
+ // Event Parameters:
+ // Num Responses (1 octet)
+ // 0xXX: Number of responses from the inquiry.
+ // Bd Addresses (6 octets * Num Responses)
+ // 0xXXXXXXXXXXX: Bd Address for each device which responded.
+ // Page Scan Repetition Mode (1 octet * Num Responses)
+ // 0x00: R0
+ // 0x01: R1
+ // 0x02: R2
+ // 0x03-0xFF: Reserved.
+ // Reserved 1 (1 octet * Num Responses)
+ // Originally Page Scan Period Mode parameter. No longer in use.
+ // Reserved 2 (1 octet * Num Responses)
+ // Originally Page Scan Mode parameter. No longer in use.
+ // Class of Device (3 octet * Num Responses)
+ // 0xXXXXXX: Class of device.
+ // Clock Offset (2 octet * Num Responses)
+ // Bits 14-0: Bits 16-2 of CLKNslave-CLK.
+ // Bits 15: Reserved.
+ static std::unique_ptr<EventPacket> CreateInquiryResultEvent(
+ std::uint8_t num_responses, const std::vector<std::uint8_t>& bd_addresses,
+ const std::vector<std::uint8_t>& page_scan_repetition_mode,
+ const std::vector<std::uint8_t>& page_scan_period_mode,
+ const std::vector<std::uint8_t>& page_scan_mode,
+ const std::vector<std::uint8_t>& class_of_device,
+ const std::vector<std::uint8_t>& clock_offset);
+
+ // Creates and returns an inquiry result event packet. See the Bluetooth
+ // Core Specification Version 4.2, Volume 2, Part E, Section 7.7.38 (page 896)
+ // for more information about the command complete event.
+ // Event Parameters:
+ // Num Responses (1 octet)
+ // 0x01: Always contains a single response.
+ // Bd Addresses (6 octets * Num Responses)
+ // 0xXXXXXXXXXXX: Bd Address for each device which responded.
+ // Page Scan Repetition Mode (1 octet * Num Responses)
+ // 0x00: R0
+ // 0x01: R1
+ // 0x02: R2
+ // 0x03-0xFF: Reserved.
+ // Reserved 1 (1 octet * Num Responses)
+ // Originally Page Scan Period Mode parameter. No longer in use.
+ // Class of Device (3 octet * Num Responses)
+ // 0xXXXXXX: Class of device.
+ // Clock Offset (2 octet * Num Responses)
+ // Bits 14-0: Bits 16-2 of CLKNslave-CLK.
+ // Bits 15: Reserved.
+ // RSSI (1 octet)
+ // 0xXX: Ranges from -127 to +20. Units are dBm.
+ // Extended Inquiry Response (240 octets)
+ // Defined in Volumne 2, Part C, Section 8. Also see the Supplement to the
+ // Bluetooth Core Specificiation for data type definitions and formats.
+ static std::unique_ptr<EventPacket> CreateExtendedInquiryResultEvent(
+ const std::vector<std::uint8_t>& bd_address,
+ const std::vector<std::uint8_t>& page_scan_repetition_mode,
+ const std::vector<std::uint8_t>& page_scan_period_mode,
+ const std::vector<std::uint8_t>& class_of_device,
+ const std::vector<std::uint8_t>& clock_offset,
+ const std::vector<std::uint8_t>& rssi,
+ const std::vector<std::uint8_t>& extended_inquiry_response);
+
// Size in octets of a data packet header, which consists of a 1 octet
// event code and a 1 octet payload size.
static const size_t kEventHeaderSize = 2;
//
// http://www.apache.org/licenses/LICENSE-2.0
//
-// Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS,
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// command packets it can send to the controller.
const uint8_t kNumHciCommandPackets = 1;
+// Command: Read Buffer Size (page 794).
+// Tells the host size information for data packets.
+// Opcode: HCI_READ_BUFFER_SIZE.
+// Maximum length in octets of the data portion of each HCI ACL/SCO data packet
+// that the controller can accept.
+const uint16_t kHciAclDataPacketSize = 1024;
+const uint8_t kHciScoDataPacketSize = 255;
+// Total number of HCI ACL/SCO data packets that can be stored in the data
+// buffers of the controller.
+const uint16_t kHciTotalNumAclDataPackets = 10;
+const uint16_t kHciTotalNumScoDataPackets = 10;
+const std::vector<uint8_t> kBufferSize = {kReturnStatusSuccess,
+ kHciAclDataPacketSize,
+ 0,
+ kHciScoDataPacketSize,
+ kHciTotalNumAclDataPackets,
+ 0,
+ kHciTotalNumScoDataPackets,
+ 0};
+
+// Command: Read Local Version Information (page 788).
+// The values for the version information for the controller.
+// Opcode: HCI_READ_LOCAL_VERSION_INFO.
+const uint8_t kHciVersion = 0;
+const uint16_t kHciRevision = 0;
+const uint8_t kLmpPalVersion = 0;
+const uint16_t kManufacturerName = 0;
+const uint16_t kLmpPalSubversion = 0;
+const std::vector<uint8_t> kLocalVersionInformation = {
+ kReturnStatusSuccess, kHciVersion, kHciRevision, 0, kLmpPalVersion,
+ kManufacturerName, 0, kLmpPalSubversion, 0};
+
+// Command: Read Local Extended Features (page 792).
+// The requested page of extended LMP features.
+// Opcode: HCI_READ_LOCAL_EXT_FEATURES.
+const uint8_t kPageNumber = 0;
+const uint8_t kMaximumPageNumber = 0;
+const std::vector<uint8_t> kLocalExtendedFeatures = {kReturnStatusSuccess,
+ kPageNumber,
+ kMaximumPageNumber,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF,
+ 0xFF};
+// Command: Read BR_ADDR (page 796).
+// The Bluetooth Controller address.
+// Opcode: HCI_READ_BD_ADDR.
+const std::vector<uint8_t> kBdAddress = {
+ kReturnStatusSuccess, 1, 2, 3, 4, 5, 6};
+
+// Inquiry modes for specifiying inquiry result formats.
+const uint8_t kStandardInquiry = 0x00;
+const uint8_t kRssiInquiry = 0x01;
+const uint8_t kExtendedOrRssiInquiry = 0x02;
+
+// The (fake) bd address of another device.
+const std::vector<uint8_t> kOtherDeviceBdAddress = {6, 5, 4, 3, 2, 1};
+
+// Fake inquiry response for a fake device.
+const std::vector<uint8_t> kPageScanRepetitionMode = {0};
+const std::vector<uint8_t> kPageScanPeriodMode = {0};
+const std::vector<uint8_t> kPageScanMode = {0};
+const std::vector<uint8_t> kClassOfDevice = {1, 2, 3};
+const std::vector<uint8_t> kClockOffset = {1, 2};
+
// Creates a command complete event and sends it back to the HCI.
void SendCommandComplete(uint16_t command_opcode,
const std::vector<uint8_t>& return_parameters) {
SendCommandComplete(command_opcode, {kReturnStatusSuccess});
}
+// Creates a command status event and sends it back to the HCI.
+void SendCommandStatus(uint16_t command_opcode) {
+ std::unique_ptr<test_vendor_lib::EventPacket> command_status =
+ test_vendor_lib::EventPacket::CreateCommandStatusEvent(
+ kNumHciCommandPackets, command_opcode);
+ // TODO(dennischeng): Should this dependency on HciTransport be removed?
+ test_vendor_lib::HciTransport::Get()->SendEvent(std::move(command_status));
+}
+
+void SendEmptySuccessCommandStatus(uint16_t command_opcode) {
+ SendCommandComplete(command_opcode, {kReturnStatusSuccess});
+}
+
+// Sends an inquiry response for a fake device.
+void SendInquiryResult() {
+ std::unique_ptr<test_vendor_lib::EventPacket> inquiry_result =
+ test_vendor_lib::EventPacket::CreateInquiryResultEvent(
+ 1, kOtherDeviceBdAddress, kPageScanRepetitionMode,
+ kPageScanPeriodMode, kPageScanMode, kClassOfDevice, kClockOffset);
+ // TODO(dennischeng): Should this dependency on HciTransport be removed?
+ test_vendor_lib::HciTransport::Get()->SendEvent(std::move(inquiry_result));
+}
+
+// Sends an extended inquiry response for a fake device.
+void SendExtendedInquiryResult() {
+ std::vector<uint8_t> rssi = {0};
+ std::vector<uint8_t> extended_inquiry_data = {7, 0x09,
+ 'F', 'o', 'o', 'B', 'a', 'r'};
+ // TODO(dennischeng): Use constants for parameter sizes, here and elsewhere.
+ while (extended_inquiry_data.size() < 240) {
+ extended_inquiry_data.push_back(0);
+ }
+ std::unique_ptr<test_vendor_lib::EventPacket> extended_inquiry_result =
+ test_vendor_lib::EventPacket::CreateExtendedInquiryResultEvent(
+ kOtherDeviceBdAddress, kPageScanRepetitionMode, kPageScanPeriodMode,
+ kClassOfDevice, kClockOffset, rssi, extended_inquiry_data);
+ // TODO(dennischeng): Should this dependency on HciTransport be removed?
+ test_vendor_lib::HciTransport::Get()->SendEvent(
+ std::move(extended_inquiry_result));
+}
+
+void LogCommand(const char* command) {
+ LOG_INFO(LOG_TAG, "Controller performing command: %s", command);
+}
+
} // namespace
namespace test_vendor_lib {
active_commands_[opcode] = \
std::bind(&BREDRController::command, this, std::placeholders::_1);
SET_HANDLER(HCI_RESET, HciReset);
+ SET_HANDLER(HCI_READ_BUFFER_SIZE, HciReadBufferSize);
+ SET_HANDLER(HCI_HOST_BUFFER_SIZE, HciHostBufferSize);
+ SET_HANDLER(HCI_READ_LOCAL_VERSION_INFO, HciReadLocalVersionInformation);
+ SET_HANDLER(HCI_READ_BD_ADDR, HciReadBdAddr);
+ SET_HANDLER(HCI_READ_LOCAL_SUPPORTED_CMDS, HciReadLocalSupportedCommands);
+ SET_HANDLER(HCI_READ_LOCAL_EXT_FEATURES, HciReadLocalExtendedFeatures);
+ SET_HANDLER(HCI_WRITE_SIMPLE_PAIRING_MODE, HciWriteSimplePairingMode);
+ SET_HANDLER(HCI_WRITE_LE_HOST_SUPPORT, HciWriteLeHostSupport);
+ SET_HANDLER(HCI_SET_EVENT_MASK, HciSetEventMask);
+ SET_HANDLER(HCI_WRITE_INQUIRY_MODE, HciWriteInquiryMode);
+ SET_HANDLER(HCI_WRITE_PAGESCAN_TYPE, HciWritePageScanType);
+ SET_HANDLER(HCI_WRITE_INQSCAN_TYPE, HciWriteInquiryScanType);
+ SET_HANDLER(HCI_WRITE_CLASS_OF_DEVICE, HciWriteClassOfDevice);
+ SET_HANDLER(HCI_WRITE_PAGE_TOUT, HciWritePageTimeout);
+ SET_HANDLER(HCI_WRITE_DEF_POLICY_SETTINGS, HciWriteDefaultLinkPolicySettings);
+ SET_HANDLER(HCI_READ_LOCAL_NAME, HciReadLocalName);
+ SET_HANDLER(HCI_CHANGE_LOCAL_NAME, HciWriteLocalName);
+ SET_HANDLER(HCI_WRITE_EXT_INQ_RESPONSE, HciWriteExtendedInquiryResponse);
+ SET_HANDLER(HCI_WRITE_VOICE_SETTINGS, HciWriteVoiceSetting);
+ SET_HANDLER(HCI_WRITE_CURRENT_IAC_LAP, HciWriteCurrentIacLap);
+ SET_HANDLER(HCI_WRITE_INQUIRYSCAN_CFG, HciWriteInquiryScanActivity);
+ SET_HANDLER(HCI_WRITE_SCAN_ENABLE, HciWriteScanEnable);
+ SET_HANDLER(HCI_SET_EVENT_FILTER, HciSetEventFilter);
+ SET_HANDLER(HCI_INQUIRY, HciInquiry);
#undef SET_HANDLER
}
}
}
+// TODO(dennischeng): Store relevant arguments from commands as attributes of
+// the controller.
+
void BREDRController::HciReset(const std::vector<uint8_t>& /* args */) {
- LOG_INFO(LOG_TAG, "Performing Reset command in controller.");
+ LogCommand("Reset");
SendEmptySuccessCommandComplete(HCI_RESET);
}
+void BREDRController::HciReadBufferSize(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Read Buffer Size");
+ SendCommandComplete(HCI_READ_BUFFER_SIZE, kBufferSize);
+}
+
+void BREDRController::HciHostBufferSize(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Host Buffer Size");
+ SendEmptySuccessCommandComplete(HCI_HOST_BUFFER_SIZE);
+}
+
+void BREDRController::HciReadLocalVersionInformation(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Read Local Version Information");
+ SendCommandComplete(HCI_READ_LOCAL_VERSION_INFO, kLocalVersionInformation);
+}
+
+void BREDRController::HciReadBdAddr(const std::vector<uint8_t>& /* args */) {
+ LogCommand("Read Bd Addr");
+ SendCommandComplete(HCI_READ_BD_ADDR, kBdAddress);
+}
+
+void BREDRController::HciReadLocalSupportedCommands(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Read Local Supported Commands");
+ std::vector<uint8_t> return_parameters;
+ return_parameters.reserve(65);
+ return_parameters.push_back(kReturnStatusSuccess);
+ for (int i = 0; i < 64; ++i) {
+ return_parameters.push_back(0xFF);
+ }
+ SendCommandComplete(HCI_READ_LOCAL_SUPPORTED_CMDS, return_parameters);
+}
+
+void BREDRController::HciReadLocalExtendedFeatures(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Read Local Extended Features");
+ SendCommandComplete(HCI_READ_LOCAL_EXT_FEATURES, kLocalExtendedFeatures);
+}
+
+void BREDRController::HciWriteSimplePairingMode(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Simple Pairing Mode");
+ SendEmptySuccessCommandComplete(HCI_WRITE_SIMPLE_PAIRING_MODE);
+}
+
+void BREDRController::HciWriteLeHostSupport(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Le Host Support");
+ SendEmptySuccessCommandComplete(HCI_WRITE_LE_HOST_SUPPORT);
+}
+
+void BREDRController::HciSetEventMask(const std::vector<uint8_t>& /* args */) {
+ LogCommand("Set Event Mask");
+ SendEmptySuccessCommandComplete(HCI_SET_EVENT_MASK);
+}
+
+void BREDRController::HciWriteInquiryMode(const std::vector<uint8_t>& args) {
+ LogCommand("Write Inquiry Mode");
+ assert(args.size() == 1);
+ inquiry_mode_ = args[0];
+ SendEmptySuccessCommandComplete(HCI_WRITE_INQUIRY_MODE);
+}
+
+void BREDRController::HciWritePageScanType(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Page Scan Type");
+ SendEmptySuccessCommandComplete(HCI_WRITE_PAGESCAN_TYPE);
+}
+
+void BREDRController::HciWriteInquiryScanType(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Inquiry Scan Type");
+ SendEmptySuccessCommandComplete(HCI_WRITE_INQSCAN_TYPE);
+}
+
+void BREDRController::HciWriteClassOfDevice(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Class Of Device");
+ SendEmptySuccessCommandComplete(HCI_WRITE_CLASS_OF_DEVICE);
+}
+
+void BREDRController::HciWritePageTimeout(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Page Timeout");
+ SendEmptySuccessCommandComplete(HCI_WRITE_PAGE_TOUT);
+}
+
+void BREDRController::HciWriteDefaultLinkPolicySettings(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Default Link Policy Settings");
+ SendEmptySuccessCommandComplete(HCI_WRITE_DEF_POLICY_SETTINGS);
+}
+
+void BREDRController::HciReadLocalName(const std::vector<uint8_t>& /* args */) {
+ LogCommand("Get Local Name");
+ std::vector<uint8_t> return_parameters;
+ return_parameters.reserve(249);
+ return_parameters.push_back(kReturnStatusSuccess);
+ for (int i = 0; i < 249; ++i) {
+ return_parameters.push_back(0xFF);
+ }
+ SendCommandComplete(HCI_READ_LOCAL_NAME, return_parameters);
+}
+
+void BREDRController::HciWriteLocalName(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Local Name");
+ SendEmptySuccessCommandComplete(HCI_CHANGE_LOCAL_NAME);
+}
+
+void BREDRController::HciWriteExtendedInquiryResponse(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Extended Inquiry Response");
+ SendEmptySuccessCommandComplete(HCI_WRITE_EXT_INQ_RESPONSE);
+}
+
+void BREDRController::HciWriteVoiceSetting(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Voice Setting");
+ SendEmptySuccessCommandComplete(HCI_WRITE_VOICE_SETTINGS);
+}
+
+void BREDRController::HciWriteCurrentIacLap(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Current IAC LAP");
+ SendEmptySuccessCommandComplete(HCI_WRITE_CURRENT_IAC_LAP);
+}
+
+void BREDRController::HciWriteInquiryScanActivity(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Inquiry Scan Activity");
+ SendEmptySuccessCommandComplete(HCI_WRITE_INQUIRYSCAN_CFG);
+}
+
+void BREDRController::HciWriteScanEnable(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Write Scan Enable");
+ SendEmptySuccessCommandComplete(HCI_WRITE_SCAN_ENABLE);
+}
+
+void BREDRController::HciSetEventFilter(
+ const std::vector<uint8_t>& /* args */) {
+ LogCommand("Set Event Filter");
+ SendEmptySuccessCommandComplete(HCI_SET_EVENT_FILTER);
+}
+
+void BREDRController::HciInquiry(const std::vector<uint8_t>& /* args */) {
+ LogCommand("Inquiry");
+ SendEmptySuccessCommandStatus(HCI_INQUIRY);
+ switch (inquiry_mode_) {
+ case (kStandardInquiry):
+ SendInquiryResult();
+ break;
+
+ case (kRssiInquiry):
+ LOG_INFO(LOG_TAG, "RSSI Inquiry Mode currently not supported.");
+ break;
+
+ case (kExtendedOrRssiInquiry):
+ SendExtendedInquiryResult();
+ break;
+ }
+}
+
} // namespace test_vendor_lib
#define LOG_TAG "event_packet"
+#define VECTOR_COPY_TO_END(source, destination) \
+ std::copy(source.begin(), source.end(), std::back_inserter(destination));
+
#include "vendor_libs/test_vendor_lib/include/event_packet.h"
extern "C" {
payload.push_back(num_hci_command_packets);
payload.push_back(command_opcode);
payload.push_back(command_opcode >> 8);
- std::copy(event_return_parameters.begin(), event_return_parameters.end(),
- std::back_inserter(payload));
+ VECTOR_COPY_TO_END(event_return_parameters, payload);
return std::unique_ptr<EventPacket>(
new EventPacket(HCI_COMMAND_COMPLETE_EVT, payload));
}
+// static
+std::unique_ptr<EventPacket> EventPacket::CreateCommandStatusEvent(
+ std::uint8_t num_hci_command_packets, std::uint16_t command_opcode) {
+ size_t payload_size =
+ sizeof(num_hci_command_packets) + sizeof(command_opcode);
+
+ std::vector<uint8_t> payload;
+ payload.reserve(payload_size);
+ payload.push_back(num_hci_command_packets);
+ payload.push_back(command_opcode);
+ payload.push_back(command_opcode >> 8);
+
+ return std::unique_ptr<EventPacket>(
+ new EventPacket(HCI_COMMAND_STATUS_EVT, payload));
+}
+
+//static
+std::unique_ptr<EventPacket> EventPacket::CreateInquiryResultEvent(
+ std::uint8_t num_responses, const std::vector<std::uint8_t>& bd_addresses,
+ const std::vector<std::uint8_t>& page_scan_repetition_mode,
+ const std::vector<std::uint8_t>& page_scan_period_mode,
+ const std::vector<std::uint8_t>& page_scan_mode,
+ const std::vector<std::uint8_t>& class_of_device,
+ const std::vector<std::uint8_t>& clock_offset) {
+ size_t payload_size = sizeof(num_responses) + bd_addresses.size() +
+ page_scan_repetition_mode.size() +
+ page_scan_period_mode.size() + page_scan_mode.size() +
+ class_of_device.size() + clock_offset.size();
+
+ std::vector<uint8_t> payload;
+ payload.reserve(payload_size);
+ payload.push_back(num_responses);
+ VECTOR_COPY_TO_END(bd_addresses, payload);
+ VECTOR_COPY_TO_END(page_scan_repetition_mode, payload);
+ VECTOR_COPY_TO_END(page_scan_mode, payload);
+ VECTOR_COPY_TO_END(class_of_device, payload);
+ VECTOR_COPY_TO_END(clock_offset, payload);
+
+ return std::unique_ptr<EventPacket>(
+ new EventPacket(HCI_INQUIRY_RESULT_EVT, payload));
+}
+
+//static
+std::unique_ptr<EventPacket> EventPacket::CreateExtendedInquiryResultEvent(
+ const std::vector<std::uint8_t>& bd_address,
+ const std::vector<std::uint8_t>& page_scan_repetition_mode,
+ const std::vector<std::uint8_t>& page_scan_period_mode,
+ const std::vector<std::uint8_t>& class_of_device,
+ const std::vector<std::uint8_t>& clock_offset,
+ const std::vector<std::uint8_t>& rssi,
+ const std::vector<std::uint8_t>& extended_inquiry_response) {
+ size_t payload_size =
+ 1 + bd_address.size() + page_scan_repetition_mode.size() +
+ page_scan_period_mode.size() + class_of_device.size() +
+ clock_offset.size() + rssi.size() + extended_inquiry_response.size();
+
+ std::vector<uint8_t> payload;
+ payload.reserve(payload_size);
+ payload.push_back(1); // Each extended inquiry result contains one device.
+ VECTOR_COPY_TO_END(bd_address, payload);
+ VECTOR_COPY_TO_END(page_scan_repetition_mode, payload);
+ VECTOR_COPY_TO_END(page_scan_period_mode, payload);
+ VECTOR_COPY_TO_END(class_of_device, payload);
+ VECTOR_COPY_TO_END(clock_offset, payload);
+ VECTOR_COPY_TO_END(rssi, payload);
+ VECTOR_COPY_TO_END(extended_inquiry_response, payload);
+
+ return std::unique_ptr<EventPacket>(
+ new EventPacket(HCI_EXTENDED_INQUIRY_RESULT_EVT, payload));
+}
+
} // namespace test_vendor_lib