# Copyright 2015 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import logging import multiprocessing import Queue import struct import time import common from autotest_lib.client.bin import utils from autotest_lib.client.cros.cellular.mbim_compliance \ import mbim_channel_endpoint from autotest_lib.client.cros.cellular.mbim_compliance import mbim_errors class MBIMChannel(object): """ Provide synchronous access to the modem with MBIM command level interaction. This object should simplify your interaction over the MBIM channel as follows: - Use |bidirectional_transaction| to send MBIM packets that are part of a transaction. This function will block until the transaction completes and return the MBIM packets received in response. - |bidirectional_transaction| will filter out packets that do not correspond to your transaction. This way, you don't have to worry about unsolicited notifications and/or stale packets when interacting with the modem. - All filtered out packets can be grabbed using the |get_outstanding_packets| function. Use this function to receive error notifications, status notifications, etc. - Use |unidirectional_transaction| to send MBIM packets for which you don't expect a response. - Use |flush| to clean out all pipes before starting a new transaction. Note that "MBIM packets" here really means MBIM fragments. This object does not (de)fragment packets for you. Out of necessity, it does check that received fragments are contiguous and in-order. So, this object houses the minimum information necessary about the MBIM fragments to provide you a comfortable synchronous packet level channel. """ ENDPOINT_JOIN_TIMEOUT_S = 5 FRAGMENT_TIMEOUT_S = 3 # TODO(pprabhu) Consider allowing each transaction to specify its own # timeout. TRANSACTION_TIMEOUT_S = 5 MESSAGE_HEADER_FORMAT = '