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
5import common
6from autotest_lib.client.cros.cellular.mbim_compliance import mbim_channel
7from autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants
8from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors
9from autotest_lib.client.cros.cellular.mbim_compliance \
10        import mbim_message_request
11from autotest_lib.client.cros.cellular.mbim_compliance \
12        import mbim_message_response
13from autotest_lib.client.cros.cellular.mbim_compliance \
14        import mbim_test_base
15from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
16        import get_descriptors_sequence
17from autotest_lib.client.cros.cellular.mbim_compliance.sequences \
18        import mbim_open_generic_sequence
19
20
21class cellular_MbimComplianceCM07(mbim_test_base.MbimTestBase):
22    """
23    CM_07 Validation of status in case of an unsupported CID in MBIM_COMMAND_MSG.
24
25    This test verifies that the function returns MBIM_STATUS_NO_DEVICE_SUPPORT
26    in Status field of the MBIM_COMMAND_DONE response when a command is not
27    supported by the function.
28
29    Reference:
30        [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 40
31        http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf
32    """
33    version = 1
34
35    def run_internal(self):
36        """ Run CM_07 test. """
37        # Precondition
38        descriptors = get_descriptors_sequence.GetDescriptorsSequence(
39                self.device_context).run()
40        self.device_context.update_descriptor_cache(descriptors)
41        mbim_open_generic_sequence.MBIMOpenGenericSequence(
42                self.device_context).run()
43
44        # Step 1
45        # 255 is an unsupported CID.
46        device_context = self.device_context
47        descriptor_cache = device_context.descriptor_cache
48        command_message = mbim_message_request.MBIMCommand(
49                device_service_id=mbim_constants.UUID_BASIC_CONNECT.bytes,
50                cid=255,
51                command_type=mbim_constants.COMMAND_TYPE_QUERY,
52                information_buffer_length=0)
53        packets = mbim_message_request.generate_request_packets(
54                command_message,
55                device_context.max_control_transfer_size)
56        channel = mbim_channel.MBIMChannel(
57                device_context._device,
58                descriptor_cache.mbim_communication_interface.bInterfaceNumber,
59                descriptor_cache.interrupt_endpoint.bEndpointAddress,
60                device_context.max_control_transfer_size)
61        response_packets = channel.bidirectional_transaction(*packets)
62        channel.close()
63
64        # Step 2
65        response_message = mbim_message_response.parse_response_packets(
66                response_packets)
67
68        # Step 3
69        if (response_message.message_type != mbim_constants.MBIM_COMMAND_DONE or
70            (response_message.status_codes !=
71             mbim_constants.MBIM_STATUS_NO_DEVICE_SUPPORT)):
72            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
73                                      'mbim1.0:9.4.5#2')
74