1# Copyright (c) 2015 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""" 6MBIM Close Sequence 7 8Reference: 9 [1] Universal Serial Bus Communication Class MBIM Compliance Testing: 20 10 http://www.usb.org/developers/docs/devclass_docs/MBIM-Compliance-1.0.pdf 11 12""" 13import common 14 15from autotest_lib.client.cros.cellular.mbim_compliance import mbim_channel 16from autotest_lib.client.cros.cellular.mbim_compliance import mbim_constants 17from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors 18from autotest_lib.client.cros.cellular.mbim_compliance \ 19 import mbim_message_request 20from autotest_lib.client.cros.cellular.mbim_compliance \ 21 import mbim_message_response 22from autotest_lib.client.cros.cellular.mbim_compliance.sequences \ 23 import sequence 24 25 26class MBIMCloseSequence(sequence.Sequence): 27 """ 28 Implement the MBIM Close Sequence. 29 In this sequence, a |MBIM_CLOSE_MSG| is sent to the modem in order to 30 terminate the session between the host and the modem. The modem should send 31 a |MBIM_CLOSE_DONE| as the response to |MBIM_CLOSE_MSG|. 32 """ 33 34 def run_internal(self): 35 """ Run the MBIM Close Sequence. """ 36 # Step 1 37 # Send MBIM_CLOSE_MSG to the device. 38 close_message = mbim_message_request.MBIMClose() 39 device_context = self.device_context 40 descriptor_cache = device_context.descriptor_cache 41 packets = mbim_message_request.generate_request_packets( 42 close_message, 43 device_context.max_control_transfer_size) 44 channel = mbim_channel.MBIMChannel( 45 device_context._device, 46 descriptor_cache.mbim_communication_interface.bInterfaceNumber, 47 descriptor_cache.interrupt_endpoint.bEndpointAddress, 48 device_context.max_control_transfer_size) 49 50 # Step 2 51 response_packets = channel.bidirectional_transaction(*packets) 52 channel.close() 53 54 response_message = mbim_message_response.parse_response_packets( 55 response_packets) 56 57 # Step 3 58 if response_message.transaction_id != close_message.transaction_id: 59 mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError, 60 'mbim1.0:9.4.2#1') 61 62 if response_message.status_codes != mbim_constants.MBIM_STATUS_SUCCESS: 63 mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError, 64 'mbim1.0:9.4.2#2') 65 66 return close_message, response_message 67