Home | History | Annotate | Download | only in cellular_MbimComplianceControlRequest
      1 # Copyright 2014 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import array
      6 import struct
      7 
      8 import common
      9 from autotest_lib.client.cros.cellular.mbim_compliance import mbim_channel
     10 from autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants
     11 from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
     12 from autotest_lib.client.cros.cellular.mbim_compliance \
     13         import mbim_message_request
     14 from autotest_lib.client.cros.cellular.mbim_compliance \
     15         import mbim_message_response
     16 from autotest_lib.client.cros.cellular.mbim_compliance \
     17         import mbim_test_base
     18 from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
     19         import get_descriptors_sequence
     20 from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
     21         import mbim_open_generic_sequence
     22 
     23 
     24 class cellular_MbimComplianceCM08(mbim_test_base.MbimTestBase):
     25     """
     26     CM_08 Validation of InformationBuffer in case of a failure in
     27     MBIM_COMMAND_MSG.
     28 
     29     This test verifies that in case of a command failure the buffer in the
     30     MBIM_COMMAND_DONE response is empty.
     31 
     32     Reference:
     33         [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 40
     34         http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
     35     """
     36     version = 1
     37 
     38     def run_internal(self):
     39         """ Run CM_08 test. """
     40         # Precondition
     41         descriptors = get_descriptors_sequence.GetDescriptorsSequence(
     42                 self.device_context).run()
     43         self.device_context.update_descriptor_cache(descriptors)
     44         mbim_open_generic_sequence.MBIMOpenGenericSequence(
     45                 self.device_context).run()
     46 
     47         # Step 1
     48         device_context = self.device_context
     49         descriptor_cache = device_context.descriptor_cache
     50         command_message = mbim_message_request.MBIMCommand(
     51                 device_service_id=mbim_constants.UUID_BASIC_CONNECT.bytes,
     52                 cid=mbim_constants.MBIM_CID_RADIO_STATE,
     53                 command_type=mbim_constants.COMMAND_TYPE_SET,
     54                 information_buffer_length=4,
     55                 payload_buffer=array.array('B', struct.pack('I', 2)))
     56         packets = mbim_message_request.generate_request_packets(
     57                 command_message,
     58                 device_context.max_control_transfer_size)
     59         channel = mbim_channel.MBIMChannel(
     60                 device_context._device,
     61                 descriptor_cache.mbim_communication_interface.bInterfaceNumber,
     62                 descriptor_cache.interrupt_endpoint.bEndpointAddress,
     63                 device_context.max_control_transfer_size)
     64         response_packets = channel.bidirectional_transaction(*packets)
     65         channel.close()
     66 
     67         # Step 2
     68         response_message = mbim_message_response.parse_response_packets(
     69                 response_packets)
     70 
     71         # Step 3
     72         if ((response_message.message_type !=
     73              mbim_constants.MBIM_COMMAND_DONE) or
     74             (response_message.status_codes ==
     75              mbim_constants.MBIM_STATUS_SUCCESS) or
     76             response_message.information_buffer_length != 0):
     77             mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
     78                                       'mbim1.0:9.4.5#3')
     79