From 6f5f0540f1557c87349d9f3378a90979c175ed1d Mon Sep 17 00:00:00 2001 From: Dennis Cheng Date: Thu, 20 Aug 2015 20:32:01 -0700 Subject: [PATCH] test_vendor_lib: Clean up controller documentation and address style issues This upload cleans up the command documentation in the controller's header file and also fixes a few logical errors related to command status event packets. Some style fixes are also included, such as removing braces for single line conditionals to conform to remain consistent with the rest of the project. Bug: 21586676 Change-Id: Ife5e608e43c3030e76eff8ea79ce6cad0b2c10a3 --- .../test_vendor_lib/include/command_packet.h | 6 +- .../test_vendor_lib/include/dual_mode_controller.h | 357 +++++++-------------- vendor_libs/test_vendor_lib/include/event_packet.h | 37 ++- vendor_libs/test_vendor_lib/include/packet.h | 16 +- .../test_vendor_lib/include/packet_stream.h | 6 +- vendor_libs/test_vendor_lib/src/bt_vendor.cc | 5 +- .../test_vendor_lib/src/dual_mode_controller.cc | 117 ++++--- vendor_libs/test_vendor_lib/src/event_packet.cc | 31 +- vendor_libs/test_vendor_lib/src/hci_transport.cc | 3 +- vendor_libs/test_vendor_lib/src/packet.cc | 3 +- vendor_libs/test_vendor_lib/src/packet_stream.cc | 6 +- .../test_vendor_lib/src/test_channel_transport.cc | 3 +- vendor_libs/test_vendor_lib/src/vendor_manager.cc | 6 +- .../test_vendor_lib/test/packet_stream_unittest.cc | 9 +- 14 files changed, 250 insertions(+), 355 deletions(-) diff --git a/vendor_libs/test_vendor_lib/include/command_packet.h b/vendor_libs/test_vendor_lib/include/command_packet.h index f6308c0c2..a3ff6645f 100644 --- a/vendor_libs/test_vendor_lib/include/command_packet.h +++ b/vendor_libs/test_vendor_lib/include/command_packet.h @@ -50,7 +50,7 @@ class CommandPacket : public Packet { // See the Bluetooth Core Specification Version 4.2, Volume 2, Part E, // Section 7 for more information about each HCI commands and for a listing // of their specific opcodes/OGF and OCF values. - std::uint16_t GetOpcode() const; + uint16_t GetOpcode() const; // Returns the 6 bit opcode group field that specifies the general category of // the command. The OGF can be one of seven values: @@ -62,11 +62,11 @@ class CommandPacket : public Packet { // - 0x06: Testing commands // - 0x08: Low energy controller commands // The upper 2 bits will be zero filled. - std::uint8_t GetOGF() const; + uint8_t GetOGF() const; // Returns the 10 bit opcode command field that specifies an exact command // within an opcode group field. The upper 6 bits will be zero filled. - std::uint16_t GetOCF() const; + uint16_t GetOCF() const; // Size in octets of a command packet header, which consists of a 2 octet // opcode and a 1 octet payload size. diff --git a/vendor_libs/test_vendor_lib/include/dual_mode_controller.h b/vendor_libs/test_vendor_lib/include/dual_mode_controller.h index c6fed6ac4..c2c7aa59e 100644 --- a/vendor_libs/test_vendor_lib/include/dual_mode_controller.h +++ b/vendor_libs/test_vendor_lib/include/dual_mode_controller.h @@ -36,7 +36,7 @@ namespace test_vendor_lib { // commands sent by the HCI. These methods will be registered as callbacks from // a controller instance with the HciHandler. To implement a new Bluetooth // command, simply add the method declaration below, with return type void and a -// single const std::vector& argument. After implementing the +// single const std::vector& argument. After implementing the // method, simply register it with the HciHandler using the SET_HANDLER macro in // the controller's default constructor. Be sure to name your method after the // corresponding Bluetooth command in the Core Specification with the prefix @@ -50,46 +50,57 @@ class DualModeController { // provided. Properties(const std::string& file_name); + // Aggregates and returns the result for the Read Local Extended Features + // command. This result contains the |maximum_page_number_| property (among + // other things not in the Properties object). See the Bluetooth Core + // Specification Version 4.2, Volume 2, Part E, Section 7.4.4 (page 792). + const std::vector GetBdAddress(); + // Aggregates and returns the result for the Read Buffer Size command. This // result consists of the |acl_data_packet_size_|, |sco_data_packet_size_|, // |num_acl_data_packets_|, and |num_sco_data_packets_| properties. See the // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.5 // (page 794). - const std::vector GetBufferSize(); + const std::vector GetBufferSize(); + + // Returns the result for the Read BD_ADDR command. This result is the + // |bd_address_| property. See the Bluetooth Core Specification Version + // 4.2, Volume 2, Part E, Section 7.4.6 (page 796). + const std::vector GetLocalExtendedFeatures(uint8_t page_number); + + // Returns the result for the Read Local Name command. See the Bluetooth + // Core Specification Version 4.2, Volume 2, Part E, Section 7.3.12 + // (page 664). + const std::vector GetLocalName(); + + // Returns the result for the Read Local Supported Commands command. See the + // Bluetooth Core Specification Version 4.2, Volume 2, Part E, Section 7.4.2 + // (page 790). + const std::vector GetLocalSupportedCommands(); // Aggregates and returns the Read Local Version Information result. This // consists of the |version_|, |revision_|, |lmp_pal_version_|, // |manufacturer_name_|, and |lmp_pal_subversion_|. See the Bluetooth Core // Specification Version 4.2, Volume 2, Part E, Section 7.4.1 (page 788). - const std::vector GetLocalVersionInformation(); - - // Aggregates and returns the result for the Read Local Extended Features - // command. This result contains the |maximum_page_number_| property (among - // other things not in the Properties object). See the Bluetooth Core - // Specification Version 4.2, Volume 2, Part E, Section 7.4.4 (page 792). - const std::vector GetBdAddress(); - - // Returns the result for the Read BD_ADDR command. This result is the - // |bd_address_| property. See the Bluetooth Core Specification Version - // 4.2, Volume 2, Part E, Section 7.4.6 (page 796). - const std::vector GetLocalExtendedFeatures( - std::uint8_t page_number); + const std::vector GetLocalVersionInformation(); static void RegisterJSONConverter( base::JSONValueConverter* converter); private: - std::uint16_t acl_data_packet_size_; - std::uint8_t sco_data_packet_size_; - std::uint16_t num_acl_data_packets_; - std::uint16_t num_sco_data_packets_; - std::uint8_t version_; - std::uint16_t revision_; - std::uint8_t lmp_pal_version_; - std::uint16_t manufacturer_name_; - std::uint16_t lmp_pal_subversion_; - std::uint8_t maximum_page_number_; - std::vector bd_address_; + uint16_t acl_data_packet_size_; + uint8_t sco_data_packet_size_; + uint16_t num_acl_data_packets_; + uint16_t num_sco_data_packets_; + uint8_t version_; + uint16_t revision_; + uint8_t lmp_pal_version_; + uint16_t manufacturer_name_; + uint16_t lmp_pal_subversion_; + uint8_t maximum_page_number_; + uint8_t local_supported_commands_size_; + uint8_t local_name_size_; + std::vector bd_address_; }; // Sets all of the methods to be used as callbacks in the HciHandler. @@ -129,267 +140,145 @@ class DualModeController { // Controller commands. For error codes, see the Bluetooth Core Specification, // Version 4.2, Volume 2, Part D (page 370). - // 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) - // 0x00: Success. - // 0x01-0xFF: Failed. Check error codes. - void HciReset(const std::vector& 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. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.2 + void HciReset(const std::vector& args); + // OGF: 0x0004 // OGF: 0x0005 - // Command parameters: none. - void HciReadBufferSize(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4.5 + void HciReadBufferSize(const std::vector& 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& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.39 + void HciHostBufferSize(const std::vector& args); - // Gives the host the controller's version information. // OGF: 0x0004 // OCF: 0x0001 - // Command parameters: none. - void HciReadLocalVersionInformation(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4.1 + void HciReadLocalVersionInformation(const std::vector& 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& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4.6 + void HciReadBdAddr(const std::vector& args); - // Reads the list of HCI commands the controller supports. // OGF: 0x0004 // OCF: 0x0002 - // Command parameters: none. - void HciReadLocalSupportedCommands(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4.2 + void HciReadLocalSupportedCommands(const std::vector& 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& args); - - // Toggles simple pairing mode. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.4.4 + void HciReadLocalExtendedFeatures(const std::vector& args); + // 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& args); - - // Used to set the LE Supported and Simultaneous LE and BREDR to Same Device - // Capable Link Manager Protocol feature bits. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.59 + void HciWriteSimplePairingMode(const std::vector& args); + // 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& args); - - // Used to control which events are generated by the HCI for the host. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.79 + void HciWriteLeHostSupport(const std::vector& args); + // 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& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.1 + void HciSetEventMask(const std::vector& 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& args); - - // Writes the Page Scan Type configuration parameter of the local controller. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.50 + void HciWriteInquiryMode(const std::vector& args); + // 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& args); - - // Writes the Inquiry Scan Type configuration parameter of the local - // controller. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.52 + void HciWritePageScanType(const std::vector& args); + // OGF: 0x0003 // OCF: 0x0043 - // Command parameters: - // Scan Type (1 octet) - // 0x00: Standard scan. - // 0x01: Interlaced scan. - // 0x02-0xFF: Reserved. - void HciWriteInquiryScanType(const std::vector& args); - - // Write the value for the class of device parameter. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.48 + void HciWriteInquiryScanType(const std::vector& args); + // OGF: 0x0003 // OCF: 0x0024 - // Command parameters: - // Class of Device (3 octets) - void HciWriteClassOfDevice(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.26 + void HciWriteClassOfDevice(const std::vector& 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& args); - - // Writes the default link policy configuration value which determines the - // initial value of the link policy settings for all new BR/EDR connections. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.16 + void HciWritePageTimeout(const std::vector& args); + // 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& args); - - // Reads the stored user-friendly name for the controller. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.2.12 + void HciWriteDefaultLinkPolicySettings(const std::vector& args); + // OGF: 0x0003 // OCF: 0x0014 - // Command parameters: none. - void HciReadLocalName(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.12 + void HciReadLocalName(const std::vector& 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& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.11 + void HciWriteLocalName(const std::vector& 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& args); - - // Writes the values for the voice setting configuration paramter. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.56 + void HciWriteExtendedInquiryResponse(const std::vector& args); + // OGF: 0x0003 // OCF: 0x0026 - // Command parameters: - // Voice setting (2 octets, 10 bits meaningful) - // See Section 6.12 (page 482). - void HciWriteVoiceSetting(const std::vector& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.28 + void HciWriteVoiceSetting(const std::vector& 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& args); - - // Writes the values for the inquiry scan interval and inquiry scan window - // configuration parameters. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.45 + void HciWriteCurrentIacLap(const std::vector& args); + // 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& args); - - // Writes the value for the scan enable configuration parameter. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.22 + void HciWriteInquiryScanActivity(const std::vector& args); + // 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& args); - - // Used by the host to specify different event filters. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.18 + void HciWriteScanEnable(const std::vector& args); + // 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& args); - - // Causes the BREDR Controller to enter inquiry mode where other nearby - // controllers can be discovered. + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.3 + void HciSetEventFilter(const std::vector& args); + // 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& args); + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.1.1 + void HciInquiry(const std::vector& args); + + // OGF: 0x0001 + // OCF: 0x0002 + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.1.2 + void HciInquiryCancel(const std::vector& args); + + // OGF: 0x0003 + // OCF: 0x0012 + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.3.10 + void HciDeleteStoredLinkKey(const std::vector& args); + + // OGF: 0x0001 + // OCF: 0x0019 + // Bluetooth Core Specification Version 4.2 Volume 2 Part E 7.1.19 + void HciRemoteNameRequest(const std::vector& args); // Test Channel commands: @@ -412,10 +301,7 @@ class DualModeController { // Current link layer state of the controller. enum State { kStandby, // Not receiving/transmitting any packets from/to other devices. - kAdvertising, // Transmitting advertising packets. - kScanning, // Listening for advertising packets. - kInitiating, // Listening for advertising packets from a specific device. - kConnection, // In a connection. + kInquiry, // The controller is discovering other nearby devices. }; enum TestChannelState { @@ -433,7 +319,7 @@ class DualModeController { void SendCommandCompleteSuccess(uint16_t command_opcode) const; // Creates a command status event and sends it back to the HCI. - void SendCommandStatus(uint16_t command_opcode) const; + void SendCommandStatus(uint8_t status, uint16_t command_opcode) const; // Sends a command status event with default event parameters. void SendCommandStatusSuccess(uint16_t command_opcode) const; @@ -445,7 +331,7 @@ class DualModeController { void SendExtendedInquiryResult(const std::string& name, const std::string& address) const; - void SetEventDelay(std::int64_t delay); + void SetEventDelay(int64_t delay); // Callback provided to send events from the controller back to the HCI. std::function)> send_event_; @@ -456,8 +342,7 @@ class DualModeController { // Maintains the commands to be registered and used in the HciHandler object. // Keys are command opcodes and values are the callbacks to handle each // command. - std::unordered_map&)>> + std::unordered_map&)>> active_hci_commands_; std::unordered_map CreateCommandCompleteEvent( - std::uint8_t num_hci_command_packets, std::uint16_t command_opcode, - const std::vector& event_return_parameters); + uint8_t num_hci_command_packets, uint16_t command_opcode, + const std::vector& 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) @@ -82,7 +82,7 @@ class EventPacket : public Packet { // |command_opcode| // The opcode of the command that caused this event. static std::unique_ptr CreateCommandStatusEvent( - std::uint8_t num_hci_command_packets, std::uint16_t command_opcode); + uint8_t status, uint8_t num_hci_command_packets, 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) @@ -107,12 +107,12 @@ class EventPacket : public Packet { // Bits 14-0: Bits 16-2 of CLKNslave-CLK. // Bits 15: Reserved. static std::unique_ptr CreateInquiryResultEvent( - std::uint8_t num_responses, const std::vector& bd_addresses, - const std::vector& page_scan_repetition_mode, - const std::vector& page_scan_period_mode, - const std::vector& page_scan_mode, - const std::vector& class_of_device, - const std::vector& clock_offset); + uint8_t num_responses, const std::vector& bd_addresses, + const std::vector& page_scan_repetition_mode, + const std::vector& page_scan_period_mode, + const std::vector& page_scan_mode, + const std::vector& class_of_device, + const std::vector& 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) @@ -140,13 +140,13 @@ class EventPacket : public Packet { // 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 CreateExtendedInquiryResultEvent( - const std::vector& bd_address, - const std::vector& page_scan_repetition_mode, - const std::vector& page_scan_period_mode, - const std::vector& class_of_device, - const std::vector& clock_offset, - const std::vector& rssi, - const std::vector& extended_inquiry_response); + const std::vector& bd_address, + const std::vector& page_scan_repetition_mode, + const std::vector& page_scan_period_mode, + const std::vector& class_of_device, + const std::vector& clock_offset, + const std::vector& rssi, + const std::vector& 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. @@ -155,8 +155,7 @@ class EventPacket : public Packet { private: // Takes in the event parameters in |payload|. These parameters vary by event // and are detailed in the Bluetooth Core Specification. - EventPacket(std::uint8_t event_code, - const std::vector& payload); + EventPacket(uint8_t event_code, const std::vector& payload); }; } // namespace test_vendor_lib diff --git a/vendor_libs/test_vendor_lib/include/packet.h b/vendor_libs/test_vendor_lib/include/packet.h index bd3be7478..9b3978ca0 100644 --- a/vendor_libs/test_vendor_lib/include/packet.h +++ b/vendor_libs/test_vendor_lib/include/packet.h @@ -36,13 +36,13 @@ class Packet { // octet, the header, and the payload. size_t GetPacketSize() const; - const std::vector& GetPayload() const; + const std::vector& GetPayload() const; - std::uint8_t GetPayloadSize() const; + uint8_t GetPayloadSize() const; - const std::vector& GetHeader() const; + const std::vector& GetHeader() const; - std::uint8_t GetHeaderSize() const; + uint8_t GetHeaderSize() const; serial_data_type_t GetType() const; @@ -53,8 +53,8 @@ class Packet { // contents of |header| and |payload| are guaranteed to be preserved. The // packet object will assume ownership of the copied data for its entire // lifetime. - bool Encode(const std::vector& header, - const std::vector& payload); + bool Encode(const std::vector& header, + const std::vector& payload); protected: // Constructs an empty packet of type |type|. A call to Encode() shall be made @@ -66,9 +66,9 @@ class Packet { // packet header and the packet payload. Data is copied into the vectors // during the constructor and becomes accessible (read only) to children // through GetHeader() and GetPayload(). - std::vector header_; + std::vector header_; - std::vector payload_; + std::vector payload_; // The packet type is one of DATA_TYPE_ACL, DATA_TYPE_COMMAND, // DATA_TYPE_EVENT, or DATA_TYPE_SCO. diff --git a/vendor_libs/test_vendor_lib/include/packet_stream.h b/vendor_libs/test_vendor_lib/include/packet_stream.h index eedf768fc..de0d57017 100644 --- a/vendor_libs/test_vendor_lib/include/packet_stream.h +++ b/vendor_libs/test_vendor_lib/include/packet_stream.h @@ -54,13 +54,13 @@ class PacketStream { // Attempts to receive |num_octets_to_receive| into |destination| from |fd|, // returning false if an error occurs. - bool ReceiveAll(std::vector& destination, + bool ReceiveAll(std::vector& destination, size_t num_octets_to_receive, int fd) const; // Attempts to send |num_octets_to_send| from |source| to |fd|, returning // false if an error occurs. - bool SendAll(const std::vector& source, - size_t num_octets_to_send, int fd) const; + bool SendAll(const std::vector& source, size_t num_octets_to_send, + int fd) const; }; } // namespace test_vendor_lib diff --git a/vendor_libs/test_vendor_lib/src/bt_vendor.cc b/vendor_libs/test_vendor_lib/src/bt_vendor.cc index 6dcd8b623..81538acfe 100644 --- a/vendor_libs/test_vendor_lib/src/bt_vendor.cc +++ b/vendor_libs/test_vendor_lib/src/bt_vendor.cc @@ -55,11 +55,10 @@ static int TestVendorOp(bt_vendor_opcode_t opcode, void* param) { case BT_VND_OP_POWER_CTRL: { LOG_INFO(LOG_TAG, "Doing op: BT_VND_OP_POWER_CTRL"); int* state = static_cast(param); - if (*state == BT_VND_PWR_OFF) { + if (*state == BT_VND_PWR_OFF) LOG_INFO(LOG_TAG, "Turning Bluetooth off."); - } else if (*state == BT_VND_PWR_ON) { + else if (*state == BT_VND_PWR_ON) LOG_INFO(LOG_TAG, "Turning Bluetooth on."); - } return 0; } diff --git a/vendor_libs/test_vendor_lib/src/dual_mode_controller.cc b/vendor_libs/test_vendor_lib/src/dual_mode_controller.cc index aa1654e9f..c21d9a504 100644 --- a/vendor_libs/test_vendor_lib/src/dual_mode_controller.cc +++ b/vendor_libs/test_vendor_lib/src/dual_mode_controller.cc @@ -32,9 +32,9 @@ extern "C" { namespace { -// Included in certain events to indicate the successful completion of the -// associated command. -const uint8_t kReturnStatusSuccess = 0; +// Included in certain events to indicate success (specific to the event +// context). +const uint8_t kSuccessStatus = 0; // The default number encoded in event packets to indicate to the HCI how many // command packets it can send to the controller. @@ -77,9 +77,8 @@ bool ParseUint16t(const base::StringPiece& value, uint16_t* field) { bool ParseUint8tVector(const base::StringPiece& value, std::vector* field) { - for (char& c : value.as_string()) { + for (char& c : value.as_string()) field->push_back(c - '0'); - } return true; } @@ -98,19 +97,20 @@ void DualModeController::SendCommandComplete( void DualModeController::SendCommandCompleteSuccess( uint16_t command_opcode) const { - SendCommandComplete(command_opcode, {kReturnStatusSuccess}); + SendCommandComplete(command_opcode, {kSuccessStatus}); } -void DualModeController::SendCommandStatus(uint16_t command_opcode) const { +void DualModeController::SendCommandStatus(uint8_t status, + uint16_t command_opcode) const { std::unique_ptr command_status = - EventPacket::CreateCommandStatusEvent(kNumHciCommandPackets, + EventPacket::CreateCommandStatusEvent(status, kNumHciCommandPackets, command_opcode); send_event_(std::move(command_status)); } void DualModeController::SendCommandStatusSuccess( uint16_t command_opcode) const { - SendCommandComplete(command_opcode, {kReturnStatusSuccess}); + SendCommandStatus(kSuccessStatus, command_opcode); } void DualModeController::SendInquiryResult() const { @@ -171,6 +171,9 @@ DualModeController::DualModeController() SET_HANDLER(HCI_WRITE_SCAN_ENABLE, HciWriteScanEnable); SET_HANDLER(HCI_SET_EVENT_FILTER, HciSetEventFilter); SET_HANDLER(HCI_INQUIRY, HciInquiry); + SET_HANDLER(HCI_INQUIRY_CANCEL, HciInquiryCancel); + SET_HANDLER(HCI_DELETE_STORED_LINK_KEY, HciDeleteStoredLinkKey); + SET_HANDLER(HCI_RMT_NAME_REQUEST, HciRemoteNameRequest); #undef SET_HANDLER #define SET_TEST_HANDLER(command_name, method) \ @@ -199,9 +202,8 @@ void DualModeController::RegisterHandlersWithTestChannelTransport( void DualModeController::HandleTestChannelCommand( const std::string& name, const std::vector& args) { - if (active_test_channel_commands_.count(name) == 0) { + if (active_test_channel_commands_.count(name) == 0) return; - } active_test_channel_commands_[name](args); } @@ -213,12 +215,10 @@ void DualModeController::HandleCommand( // The command hasn't been registered with the handler yet. There is nothing // to do. - if (active_hci_commands_.count(opcode) == 0) { + if (active_hci_commands_.count(opcode) == 0) return; - } - if (test_channel_state_ == kTimeoutAll) { + else if (test_channel_state_ == kTimeoutAll) return; - } active_hci_commands_[opcode](command_packet->GetPayload()); } @@ -235,9 +235,8 @@ void DualModeController::RegisterDelayedEventChannel( } void DualModeController::SetEventDelay(int64_t delay) { - if (delay < 0) { + if (delay < 0) delay = 0; - } send_event_ = std::bind(send_delayed_event_, std::placeholders::_1, base::TimeDelta::FromMilliseconds(delay)); } @@ -252,9 +251,8 @@ void DualModeController::TestChannelClear( void DualModeController::TestChannelDiscover( const std::vector& args) { LogCommand("TestChannel Discover"); - for (size_t i = 0; i < args.size()-1; i+=2) { + for (size_t i = 0; i < args.size()-1; i+=2) SendExtendedInquiryResult(args[i], args[i+1]); - } } void DualModeController::TestChannelTimeoutAll( @@ -277,9 +275,6 @@ void DualModeController::TestChannelClearEventDelay( SetEventDelay(0); } -// TODO(dennischeng): Store relevant arguments from commands as attributes of -// the controller. - void DualModeController::HciReset(const std::vector& /* args */) { LogCommand("Reset"); state_ = kStandby; @@ -309,20 +304,15 @@ void DualModeController::HciReadBdAddr(const std::vector& /* args */) { LogCommand("Read Bd Addr"); std::vector bd_address_with_status = properties_.GetBdAddress(); bd_address_with_status.insert(bd_address_with_status.begin(), - kReturnStatusSuccess); + kSuccessStatus); SendCommandComplete(HCI_READ_BD_ADDR, bd_address_with_status); } void DualModeController::HciReadLocalSupportedCommands( const std::vector& /* args */) { LogCommand("Read Local Supported Commands"); - std::vector 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); + SendCommandComplete(HCI_READ_LOCAL_SUPPORTED_CMDS, + properties_.GetLocalSupportedCommands()); } void DualModeController::HciReadLocalExtendedFeatures( @@ -390,13 +380,7 @@ void DualModeController::HciWriteDefaultLinkPolicySettings( void DualModeController::HciReadLocalName( const std::vector& /* args */) { LogCommand("Get Local Name"); - std::vector 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); + SendCommandComplete(HCI_READ_LOCAL_NAME, properties_.GetLocalName()); } void DualModeController::HciWriteLocalName( @@ -432,7 +416,6 @@ void DualModeController::HciWriteInquiryScanActivity( void DualModeController::HciWriteScanEnable( const std::vector& /* args */) { LogCommand("Write Scan Enable"); - state_ = kScanning; SendCommandCompleteSuccess(HCI_WRITE_SCAN_ENABLE); } @@ -444,6 +427,7 @@ void DualModeController::HciSetEventFilter( void DualModeController::HciInquiry(const std::vector& /* args */) { LogCommand("Inquiry"); + state_ = kInquiry; SendCommandStatusSuccess(HCI_INQUIRY); switch (inquiry_mode_) { case (kStandardInquiry): @@ -460,40 +444,60 @@ void DualModeController::HciInquiry(const std::vector& /* args */) { } } -DualModeController::Properties::Properties(const std::string& file_name) { +void DualModeController::HciInquiryCancel( + const std::vector& /* args */) { + LogCommand("Inquiry Cancel"); + CHECK(state_ == kInquiry); + state_ = kStandby; + SendCommandCompleteSuccess(HCI_INQUIRY_CANCEL); +} + +void DualModeController::HciDeleteStoredLinkKey( + const std::vector& args) { + LogCommand("Delete Stored Link Key"); + /* Check the last octect in |args|. If it is 0, delete only the link key for + * the given BD_ADDR. If is is 1, delete all stored link keys. */ + SendCommandComplete(HCI_DELETE_STORED_LINK_KEY, {1}); +} + +void DualModeController::HciRemoteNameRequest( + const std::vector& args) { + LogCommand("Remote Name Request"); + SendCommandStatusSuccess(HCI_RMT_NAME_REQUEST); +} + +DualModeController::Properties::Properties(const std::string& file_name) + : local_supported_commands_size_(64), local_name_size_(248) { std::string properties_raw; - if (!base::ReadFileToString(base::FilePath(file_name), &properties_raw)) { + if (!base::ReadFileToString(base::FilePath(file_name), &properties_raw)) LOG_INFO(LOG_TAG, "Error reading controller properties from file."); - } scoped_ptr properties_value_ptr = base::JSONReader::Read(properties_raw); - if (properties_value_ptr.get() == nullptr) { + if (properties_value_ptr.get() == nullptr) LOG_INFO(LOG_TAG, "Error controller properties may consist of ill-formed JSON."); - } // Get the underlying base::Value object, which is of type // base::Value::TYPE_DICTIONARY, and read it into member variables. base::Value& properties_dictionary = *(properties_value_ptr.get()); base::JSONValueConverter converter; - if (!converter.Convert(properties_dictionary, this)) { + if (!converter.Convert(properties_dictionary, this)) LOG_INFO(LOG_TAG, "Error converting JSON properties into Properties object."); - } } const std::vector DualModeController::Properties::GetBufferSize() { return std::vector( - {kReturnStatusSuccess, acl_data_packet_size_, acl_data_packet_size_ >> 8, + {kSuccessStatus, acl_data_packet_size_, acl_data_packet_size_ >> 8, sco_data_packet_size_, num_acl_data_packets_, num_acl_data_packets_ >> 8, num_sco_data_packets_, num_sco_data_packets_ >> 8}); } const std::vector DualModeController::Properties::GetLocalVersionInformation() { - return std::vector({kReturnStatusSuccess, version_, revision_, + return std::vector({kSuccessStatus, version_, revision_, revision_ >> 8, lmp_pal_version_, manufacturer_name_, manufacturer_name_ >> 8, lmp_pal_subversion_, lmp_pal_subversion_ >> 8}); @@ -505,11 +509,28 @@ const std::vector DualModeController::Properties::GetBdAddress() { const std::vector DualModeController::Properties::GetLocalExtendedFeatures(uint8_t page_number) { - return std::vector({kReturnStatusSuccess, page_number, + return std::vector({kSuccessStatus, page_number, maximum_page_number_, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}); } +const std::vector +DualModeController::Properties::GetLocalSupportedCommands() { + std::vector local_supported_commands; + local_supported_commands.push_back(kSuccessStatus); + for (uint8_t i = 0; i < local_supported_commands_size_; ++i) + local_supported_commands.push_back(0xFF); + return local_supported_commands; +} + +const std::vector DualModeController::Properties::GetLocalName() { + std::vector local_name; + local_name.push_back(kSuccessStatus); + for (uint8_t i = 0; i < local_name_size_; ++i) + local_name.push_back(0xFF); + return local_name; +} + // static void DualModeController::Properties::RegisterJSONConverter( base::JSONValueConverter* converter) { diff --git a/vendor_libs/test_vendor_lib/src/event_packet.cc b/vendor_libs/test_vendor_lib/src/event_packet.cc index 75a1f46ea..d003bb10a 100644 --- a/vendor_libs/test_vendor_lib/src/event_packet.cc +++ b/vendor_libs/test_vendor_lib/src/event_packet.cc @@ -58,12 +58,13 @@ std::unique_ptr EventPacket::CreateCommandCompleteEvent( // static std::unique_ptr EventPacket::CreateCommandStatusEvent( - std::uint8_t num_hci_command_packets, std::uint16_t command_opcode) { + uint8_t status, uint8_t num_hci_command_packets, uint16_t command_opcode) { size_t payload_size = - sizeof(num_hci_command_packets) + sizeof(command_opcode); + sizeof(status) + sizeof(num_hci_command_packets) + sizeof(command_opcode); std::vector payload; payload.reserve(payload_size); + payload.push_back(status); payload.push_back(num_hci_command_packets); payload.push_back(command_opcode); payload.push_back(command_opcode >> 8); @@ -74,12 +75,12 @@ std::unique_ptr EventPacket::CreateCommandStatusEvent( //static std::unique_ptr EventPacket::CreateInquiryResultEvent( - std::uint8_t num_responses, const std::vector& bd_addresses, - const std::vector& page_scan_repetition_mode, - const std::vector& page_scan_period_mode, - const std::vector& page_scan_mode, - const std::vector& class_of_device, - const std::vector& clock_offset) { + uint8_t num_responses, const std::vector& bd_addresses, + const std::vector& page_scan_repetition_mode, + const std::vector& page_scan_period_mode, + const std::vector& page_scan_mode, + const std::vector& class_of_device, + const std::vector& 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() + @@ -100,13 +101,13 @@ std::unique_ptr EventPacket::CreateInquiryResultEvent( //static std::unique_ptr EventPacket::CreateExtendedInquiryResultEvent( - const std::vector& bd_address, - const std::vector& page_scan_repetition_mode, - const std::vector& page_scan_period_mode, - const std::vector& class_of_device, - const std::vector& clock_offset, - const std::vector& rssi, - const std::vector& extended_inquiry_response) { + const std::vector& bd_address, + const std::vector& page_scan_repetition_mode, + const std::vector& page_scan_period_mode, + const std::vector& class_of_device, + const std::vector& clock_offset, + const std::vector& rssi, + const std::vector& 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() + diff --git a/vendor_libs/test_vendor_lib/src/hci_transport.cc b/vendor_libs/test_vendor_lib/src/hci_transport.cc index eaaaed1d8..8e64f71ef 100644 --- a/vendor_libs/test_vendor_lib/src/hci_transport.cc +++ b/vendor_libs/test_vendor_lib/src/hci_transport.cc @@ -53,9 +53,8 @@ bool HciTransport::SetUp() { int socketpair_fds[2]; // TODO(dennischeng): Use SOCK_SEQPACKET here. const int success = socketpair(AF_LOCAL, SOCK_STREAM, 0, socketpair_fds); - if (success < 0) { + if (success < 0) return false; - } hci_fd_.reset(new base::ScopedFD(socketpair_fds[0])); vendor_fd_.reset(new base::ScopedFD(socketpair_fds[1])); return true; diff --git a/vendor_libs/test_vendor_lib/src/packet.cc b/vendor_libs/test_vendor_lib/src/packet.cc index b07b01cef..4c273013f 100644 --- a/vendor_libs/test_vendor_lib/src/packet.cc +++ b/vendor_libs/test_vendor_lib/src/packet.cc @@ -32,9 +32,8 @@ Packet::Packet(serial_data_type_t type) : type_(type) {} bool Packet::Encode(const std::vector& header, const std::vector& payload) { - if (header.back() != payload.size()) { + if (header.back() != payload.size()) return false; - } header_ = header; payload_ = payload; return true; diff --git a/vendor_libs/test_vendor_lib/src/packet_stream.cc b/vendor_libs/test_vendor_lib/src/packet_stream.cc index 5c527f7e3..0eb768f5f 100644 --- a/vendor_libs/test_vendor_lib/src/packet_stream.cc +++ b/vendor_libs/test_vendor_lib/src/packet_stream.cc @@ -110,9 +110,8 @@ bool PacketStream::ReceiveAll(std::vector& destination, const int num_octets_received = read(fd, &destination[num_octets_to_receive - octets_remaining], octets_remaining); - if (num_octets_received < 0) { + if (num_octets_received < 0) return false; - } octets_remaining -= num_octets_received; } return true; @@ -125,9 +124,8 @@ bool PacketStream::SendAll(const std::vector& source, while (octets_remaining > 0) { const int num_octets_sent = write( fd, &source[num_octets_to_send - octets_remaining], octets_remaining); - if (num_octets_sent < 0) { + if (num_octets_sent < 0) return false; - } octets_remaining -= num_octets_sent; } return true; diff --git a/vendor_libs/test_vendor_lib/src/test_channel_transport.cc b/vendor_libs/test_vendor_lib/src/test_channel_transport.cc index 29203f505..0b4971164 100644 --- a/vendor_libs/test_vendor_lib/src/test_channel_transport.cc +++ b/vendor_libs/test_vendor_lib/src/test_channel_transport.cc @@ -117,9 +117,8 @@ void TestChannelTransport::OnFileCanReadWithoutBlocking(int fd) { args.push_back(std::string(arg.begin(), arg.end())); } - for (size_t i = 0; i < args.size(); ++i) { + for (size_t i = 0; i < args.size(); ++i) LOG_INFO(LOG_TAG, "Command argument %d: %s", i, args[i].data()); - } command_handler_(command_name, args); } diff --git a/vendor_libs/test_vendor_lib/src/vendor_manager.cc b/vendor_libs/test_vendor_lib/src/vendor_manager.cc index f8715fa8b..f7e640a6c 100644 --- a/vendor_libs/test_vendor_lib/src/vendor_manager.cc +++ b/vendor_libs/test_vendor_lib/src/vendor_manager.cc @@ -113,14 +113,12 @@ void VendorManager::StartWatchingOnThread() { return; } - if (test_channel_transport_.IsEnabled()) { + if (test_channel_transport_.IsEnabled()) if (!base::MessageLoopForIO::current()->WatchFileDescriptor( test_channel_transport_.GetFd(), true, base::MessageLoopForIO::WATCH_READ, &test_channel_watcher_, - &test_channel_transport_)) { + &test_channel_transport_)) LOG_ERROR(LOG_TAG, "Error watching test channel fd."); - } - } } bool VendorManager::PostTask(const base::Closure& task) { diff --git a/vendor_libs/test_vendor_lib/test/packet_stream_unittest.cc b/vendor_libs/test_vendor_lib/test/packet_stream_unittest.cc index a6c497edc..3d70ad8fb 100644 --- a/vendor_libs/test_vendor_lib/test/packet_stream_unittest.cc +++ b/vendor_libs/test_vendor_lib/test/packet_stream_unittest.cc @@ -64,9 +64,8 @@ class PacketStreamTest : public ::testing::Test { packet.push_back(payload_size); // Set the packet's payload. - for (int i = 0; i < payload_size; ++i) { + for (int i = 0; i < payload_size; ++i) packet.push_back(payload[i]); - } // Send the packet to |packet_stream_|. write(socketpair_fds_[1], &packet[1], packet.size()); @@ -83,9 +82,8 @@ class PacketStreamTest : public ::testing::Test { EXPECT_EQ(DATA_TYPE_COMMAND, command->GetType()); EXPECT_EQ(opcode, command->GetOpcode()); EXPECT_EQ(payload_size, command->GetPayloadSize()); - for (int i = 0; i < payload_size; ++i) { + for (int i = 0; i < payload_size; ++i) EXPECT_EQ(packet[4 + i], received_payload[i]); - } } void CheckedSendEvent(std::unique_ptr event) { @@ -108,9 +106,8 @@ class PacketStreamTest : public ::testing::Test { EXPECT_EQ(DATA_TYPE_EVENT, event_header[0]); EXPECT_EQ(event->GetEventCode(), event_header[1]); EXPECT_EQ(event->GetPayloadSize(), return_parameters_size); - for (int i = 0; i < return_parameters_size; ++i) { + for (int i = 0; i < return_parameters_size; ++i) EXPECT_EQ(expected_payload[i], return_parameters[i]); - } } protected: -- 2.11.0