def run_internal(self):
        """
        The actual method runs the sequence.
        Subclasses should override this method to run their own sequence.

        """
        mbim_errors.log_and_raise(NotImplementedError)
Beispiel #2
0
    def run_once(self, subtest_name, **kwargs):
        """
        Method invoked by autotest framework to start a test from the
        corresponding control file.

        @param subtest_name: Name of the compliance test to be invoked.
                The test has to be in the same folder as the control file and
                should have file_name and class_name as |subtest_name|.
        @param kwargs: Optional arguments which are passed to the actual test
                being run.

        """
        module_name = os.path.join(self._TEST_AREA_FOLDER,
                                   subtest_name + ".py")
        try:
            test_module = imp.load_source(subtest_name, module_name)
        except ImportError:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceFrameworkError,
                                      'Test module %s not found', module_name)
        try:
            test_class = getattr(test_module, subtest_name)
        except AttributeError:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceFrameworkError,
                                      'Test class %s not found', subtest_name)
        test = test_class()
        test.run_test(**kwargs)
Beispiel #3
0
    def bidirectional_transaction(self, *args):
        """
        Execute a synchronous bidirectional transaction.

        @param *args: Fragments of a single MBIM transaction. An MBIM
                transaction may consist of multiple fragments - each fragment is
                the payload for a USB control message. It should be an
                |array.array| object.  It is your responsibility (and choice) to
                keep the fragments in-order, and to send all the fragments.
                For more details, see "Fragmentation of messages" in the MBIM
                spec.
        @returns: A list of fragments in the same order as received that
                correspond to the given transaction. If we receive less
                fragments than claimed, we will return what we get. If we
                receive non-contiguous / out-of-order fragments, we'll complain.
        @raises: MBIMComplianceChannelError if received fragments are
                out-of-order or non-contigouos.

        """
        self._verify_endpoint_open()
        if not args:
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceChannelError,
                'No data given to |bidirectional_transaction|.')

        transaction_id, _, _ = self._fragment_metadata(args[0])
        for fragment in args:
            self._request_queue.put_nowait(fragment)
        return self._get_response_fragments(transaction_id)
    def run_internal(self, ntb_format):
        """
        Run DTS_05/DTS_11 test.

        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)

        """
        # Precondition
        _, _, _ = self.run_precondition(ntb_format)

        # Step 1
        loopback = loopback_sequence.LoopbackSequence(self.device_context)
        nth_1, _, _, _ = loopback.run(ntb_format=ntb_format)

        # Step 2
        nth_2, _, _, _ = loopback.run(ntb_format=ntb_format)

        # Step 3
        if ntb_format == mbim_constants.NTB_FORMAT_16:
            if nth_2.sequence_number != nth_1.sequence_number + 1:
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'ncm1.0:3.2.1#4')
        else:
            if nth_2.sequence_number != nth_1.sequence_number + 1:
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'ncm1.0:3.2.2#4')
Beispiel #5
0
    def run_internal(self):
        """ Run the MBIM Close Sequence. """
        # Step 1
        # Send MBIM_CLOSE_MSG to the device.
        close_message = mbim_message_request.MBIMClose()
        device_context = self.device_context
        descriptor_cache = device_context.descriptor_cache
        packets = mbim_message_request.generate_request_packets(
            close_message, device_context.max_control_transfer_size)
        channel = mbim_channel.MBIMChannel(
            device_context._device,
            descriptor_cache.mbim_communication_interface.bInterfaceNumber,
            descriptor_cache.interrupt_endpoint.bEndpointAddress,
            device_context.max_control_transfer_size)

        # Step 2
        response_packets = channel.bidirectional_transaction(*packets)
        channel.close()

        response_message = mbim_message_response.parse_response_packets(
            response_packets)

        # Step 3
        if response_message.transaction_id != close_message.transaction_id:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.4.2#1')

        if response_message.status_codes != mbim_constants.MBIM_STATUS_SUCCESS:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.4.2#2')

        return close_message, response_message
Beispiel #6
0
    def _get_response_fragments(self, transaction_id):
        """
        Get response for the given |transaction_id|.

        @returns: A list of fragments.
        @raises: MBIMComplianceChannelError if response is not recieved.

        """
        def _poll_response():
            packet = self._get_packet_fragments()
            if not packet:
                return False
            first_fragment = packet[0]
            response_id, _, _ = self._fragment_metadata(first_fragment)
            if response_id == transaction_id:
                self._last_response = packet
                return True
            self._outstanding_packets.append(packet)
            return False

        try:
            utils.poll_for_condition(_poll_response,
                                     timeout=self.TRANSACTION_TIMEOUT_S)
        except utils.TimeoutError:
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceChannelError,
                'Did not receive timely reply to transaction %d' %
                transaction_id)
        return self._last_response
Beispiel #7
0
    def run_internal(self, ntb_format):
        """
        Run DTS_15/DTS_21 test.

        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)

        """
        # Precondition
        _, _, _ = self.run_precondition(ntb_format)

        # Step 1
        loopback = loopback_sequence.LoopbackSequence(self.device_context)
        _, ndp, _, _ = loopback.run(ntb_format=ntb_format)

        # Step 2
        if ntb_format == mbim_constants.NTB_FORMAT_16:
            if (ndp.length < 16) or (ndp.length % 4 != 0):
                mbim_errors.log_and_raise(
                        mbim_errors.MBIMComplianceAssertionError,
                        'ncm1.0:3.3.1#1')
        else:
            if (ndp.length < 32) or (ndp.length % 8 != 0):
                mbim_errors.log_and_raise(
                        mbim_errors.MBIMComplianceAssertionError,
                        'ncm1.0:3.3.2#1')
    def run_internal(self):
        """ Run the MBIM_CID_DEVICE_CAPS Sequence. """
        # Step 1
        # Send MBIM_COMMAND_MSG.
        device_context = self.device_context
        descriptor_cache = device_context.descriptor_cache
        command_message = mbim_command_message.MBIMDeviceCapsQuery()
        packets = mbim_message_request.generate_request_packets(
            command_message, device_context.max_control_transfer_size)
        channel = mbim_channel.MBIMChannel(
            device_context._device,
            descriptor_cache.mbim_communication_interface.bInterfaceNumber,
            descriptor_cache.interrupt_endpoint.bEndpointAddress,
            device_context.max_control_transfer_size)
        response_packets = channel.bidirectional_transaction(*packets)
        channel.close()

        # Step 2
        response_message = mbim_message_response.parse_response_packets(
            response_packets)

        # Step 3
        is_message_valid = isinstance(response_message,
                                      mbim_command_message.MBIMDeviceCapsInfo)
        if ((not is_message_valid) or
            (response_message.message_type != mbim_constants.MBIM_COMMAND_DONE)
                or (response_message.status_codes !=
                    mbim_constants.MBIM_STATUS_SUCCESS)):
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.4.3')

        return command_message, response_message
Beispiel #9
0
 def _verify_endpoint_open(self):
     if not self._endpoint_process.is_alive():
         mbim_errors.log_and_raise(
             mbim_errors.MBIMComplianceChannelError,
             'MBIMChannelEndpoint died unexpectedly. '
             'The actual exception can be found in log entries from the '
             'subprocess.')
Beispiel #10
0
    def run_internal(self, ntb_format):
        """
        Run DTS_19/DTS_25 test.

        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)

        """
        # Precondition
        _, _, _ = self.run_precondition(ntb_format)

        # Step 1
        loopback = loopback_sequence.LoopbackSequence(self.device_context)
        _, _, ndp_entries, _ = loopback.run(ntb_format=ntb_format)

        # Step 2
        if ntb_format == mbim_constants.NTB_FORMAT_16:
            if ndp_entries[-1].datagram_length != 0:
                mbim_errors.log_and_raise(
                        mbim_errors.MBIMComplianceAssertionError,
                        'ncm1.0:3.3.1#5')
        else:
            if ndp_entries[-1].datagram_length != 0:
                mbim_errors.log_and_raise(
                        mbim_errors.MBIMComplianceAssertionError,
                        'ncm1.0:3.3.2#5')
    def _get_response_packets(self):
        """
        Condition method for |poll_for_condition| to check the retrieval of
        target packets.

        @returns True if both caps response packet and services response packet
                are received, False otherwise.

        """
        try:
            packets = self.channel.get_outstanding_packets()
        except mbim_errors.MBIMComplianceChannelError:
            logging.debug(
                "Error in receiving response fragments from the device")
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.5#1')
        self.caps_response = None
        self.services_response = None
        for packet in packets:
            try:
                message_response = mbim_message_response.parse_response_packets(
                    packet)
            except mbim_errors.MBIMComplianceControlMessageError:
                logging.debug(
                    "Error in parsing response fragments from the device")
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'mbim1.0:9.5#1')
            if message_response.transaction_id == self.caps_transaction_id:
                self.caps_response = message_response
            elif (message_response.transaction_id ==
                  self.services_transaction_id):
                self.services_response = message_response
            if self.caps_response and self.services_response:
                return True
        return False
    def send_ntb(self, ntb):
        """
        Send the specified payload down to the device using the bulk-out USB
        pipe.

        @param ntb: Byte array of complete MBIM NTB to be sent to the device.
        @raises MBIMComplianceDataTransferError if the complete |ntb| could not
                be sent.

        """
        ntb_length = len(ntb)
        written = self._device.write(endpoint=self._bulk_out_endpoint_address,
                                     data=ntb,
                                     timeout=self._WRITE_TIMEOUT_MS,
                                     interface=self._data_interface_number)
        numpy.set_printoptions(formatter={'int': lambda x: hex(int(x))},
                               linewidth=1000)
        logging.debug(
            'Data Channel: Sent %d bytes out of %d bytes requested. '
            'Payload: %s', written, ntb_length, numpy.array(ntb))
        if written < ntb_length:
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceDataTransferError,
                'Could not send the complete NTB (%d/%d bytes sent)' % written,
                ntb_length)
Beispiel #13
0
    def run_internal(self, ntb_format):
        """
        Run DTS_04/DTS_10 test.

        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)

        """
        # Precondition
        _, open_sequence, connect_sequence = self.run_precondition(ntb_format)

        # Step 1
        loopback = loopback_sequence.LoopbackSequence(self.device_context)
        _, _, _, _ = loopback.run(ntb_format=ntb_format)

        # Step 2
        open_sequence.run(ntb_format=ntb_format)
        connect_sequence.run()
        mbim_data_transfer.MBIMNtb.reset_sequence_number()

        # Step 3
        nth, _, _, _ = loopback.run(ntb_format=ntb_format)

        # Step 4
        if ntb_format == mbim_constants.NTB_FORMAT_16:
            if nth.sequence_number != 0:
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'ncm1.0:3.2.1#3')
        else:
            if nth.sequence_number != 0:
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'ncm1.0:3.2.2#3')
    def run_precondition(self, ntb_format):
        """
        Runs all the precondition sequences for data transfer tests.

        @param ntb_format: Whether to send/receive an NTB16 or NTB32 frame.
                Possible values: NTB_FORMAT_16, NTB_FORMAT_32 (mbim_constants)
        @returns tuple of (desc_sequence, open_sequence, connect_sequence) where,
                desc_sequence - Handle to run the get descriptor sequence.
                open_sequence - Handle to run the open sequence.
                connect_sequence - Handle to run the connect sequence.

        """
        desc_sequence = get_descriptors_sequence.GetDescriptorsSequence(
            self.device_context)
        descriptors = desc_sequence.run()
        self.device_context.update_descriptor_cache(descriptors)
        open_sequence = mbim_open_generic_sequence.MBIMOpenGenericSequence(
            self.device_context)
        open_sequence.run(ntb_format=ntb_format)
        connect_seq = connect_sequence.ConnectSequence(self.device_context)
        connect_seq.run()

        # Devices may not support SetNtbFormat(), so fail the NTB32 tests on
        # such devices.
        if ((ntb_format == mbim_constants.NTB_FORMAT_32)
                and (self.device_context.current_ntb_format != ntb_format)):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceFrameworkError,
                'Device does not support NTB 32 format.')

        return (desc_sequence, open_sequence, connect_seq)
Beispiel #15
0
    def flush(self):
        """
        Clean out all queues.

        This waits till all outgoing packets have been sent, and then waits some
        more to give the channel time to settle down.

        @raises: MBIMComplianceChannelError if things don't settle down fast
                enough.
        """
        self._verify_endpoint_open()
        num_remaining_fragments = self._request_queue.qsize()
        try:
            timeout = self.FRAGMENT_TIMEOUT_S * num_remaining_fragments
            utils.poll_for_condition(lambda: self._request_queue.empty(),
                                     timeout=timeout)
        except utils.TimeoutError:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceChannelError,
                                      'Could not flush request queue.')

        # Now wait for the response queue to settle down.
        # In the worst case, each request fragment that was remaining at the
        # time flush was called belonged to a different transaction, and each of
        # these transactions would serially timeout in |TRANSACTION_TIMEOUT_S|.
        # To avoid sleeping for long times, we cap this value arbitrarily to 5
        # transactions.
        num_remaining_transactions = min(5, num_remaining_fragments)
        time.sleep(num_remaining_fragments * self.TRANSACTION_TIMEOUT_S)
        extra_packets = self.get_outstanding_packets()
        for packet in extra_packets:
            logging.debug('flush: discarding packet: %s', packet)
Beispiel #16
0
    def _fragment_metadata(self, fragment):
        """ This function houses all the MBIM packet knowledge. """
        # All packets have a message header.
        if len(fragment) < struct.calcsize(self.MESSAGE_HEADER_FORMAT):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceChannelError,
                'Corrupted fragment |%s| does not have an MBIM header.' %
                fragment)

        message_type, _, transaction_id = struct.unpack_from(
            self.MESSAGE_HEADER_FORMAT, fragment)

        if message_type in self.MBIM_FRAGMENTED_MESSAGES:
            fragment = fragment[struct.calcsize(self.MESSAGE_HEADER_FORMAT):]
            if len(fragment) < struct.calcsize(self.FRAGMENT_HEADER_FORMAT):
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceChannelError,
                    'Corrupted fragment |%s| does not have a fragment '
                    'header. ' % fragment)

            total_fragments, current_fragment = struct.unpack_from(
                self.FRAGMENT_HEADER_FORMAT, fragment)
        else:
            # For other types, there is only one 'fragment'.
            total_fragments = 1
            current_fragment = 0

        return transaction_id, total_fragments, current_fragment
    def run_internal(self):
        """
        This method actually implements the core test logic.

        Subclasses should override this method to run their own test.

        """
        mbim_errors.log_and_raise(NotImplementedError)
Beispiel #18
0
    def run_internal(self):
        """ Run CM_05 test. """
        # Precondition
        mbim_open_generic_sequence.MBIMOpenGenericSequence(
            self.test_context).run()

        caps_command_message = mbim_control.MBIMCommandMessage(
            device_service_id=mbim_constants.UUID_BASIC_CONNECT.bytes,
            cid=mbim_constants.MBIM_CID_DEVICE_CAPS,
            command_type=mbim_constants.COMMAND_TYPE_QUERY,
            information_buffer_length=0)
        caps_packets = caps_command_message.generate_packets()
        services_command_message = mbim_control.MBIMCommandMessage(
            device_service_id=mbim_constants.UUID_BASIC_CONNECT.bytes,
            cid=mbim_constants.MBIM_CID_DEVICE_SERVICES,
            command_type=mbim_constants.COMMAND_TYPE_QUERY,
            information_buffer_length=0)
        services_packets = services_command_message.generate_packets()
        self.caps_transaction_id = caps_command_message.transaction_id
        self.services_transaction_id = services_command_message.transaction_id
        self.channel = mbim_channel.MBIMChannel(
            {
                'idVendor': self.test_context.id_vendor,
                'idProduct': self.test_context.id_product
            }, self.test_context.mbim_communication_interface.bInterfaceNumber,
            self.test_context.interrupt_endpoint.bEndpointAddress,
            self.test_context.mbim_functional.wMaxControlMessage)
        # Step 1
        self.channel.unidirectional_transaction(*caps_packets)
        # Step 2
        self.channel.unidirectional_transaction(*services_packets)

        utils.poll_for_condition(
            self._get_response_packets,
            timeout=5,
            exception=mbim_errors.MBIMComplianceChannelError(
                'Failed to retrieve the response packets to specific '
                'control messages.'))

        self.channel.close()
        caps_response_message = mbim_control.parse_response_packets(
            self.caps_response_packet)
        services_response_message = mbim_control.parse_response_packets(
            self.services_response_packet)

        # Step 3
        if not ((caps_response_message.transaction_id
                 == caps_command_message.transaction_id) and
                (caps_response_message.device_service_id
                 == caps_command_message.device_service_id)
                and caps_response_message.cid == caps_command_message.cid and
                (services_command_message.transaction_id
                 == services_response_message.transaction_id) and
                (services_command_message.device_service_id
                 == services_response_message.device_service_id) and
                services_command_message.cid == services_response_message.cid):
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:8.1.2#2')
Beispiel #19
0
    def run_internal(self):
        """ Run CM_02 test. """
        # Step 1
        open_message, response_message = (
            mbim_open_generic_sequence.MBIMOpenGenericSequence(
                self.test_context).run())

        # Validate message length of response to MBIM_OPEN_MESSAGE.
        if response_message.message_length < 0x0C:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.1#2')
    def __init__(self, *args):
        _, field_names = zip(*self._FIELDS)
        if len(args) != len(field_names):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceError,
                'Expected %d arguments for %s constructor, got %d.' %
                (len(field_names), self.__class__.__name__, len(args)))

        fields = zip(field_names, args)
        for field in fields:
            setattr(self, field[0], field[1])
    def run_internal(self):
        """ Run CM_06 test. """
        # Precondition
        mbim_open_generic_sequence.MBIMOpenGenericSequence(
            self.test_context).run()

        # Step 1
        command_message, response_message = (
            mbim_cid_device_caps_sequence.MBIMCIDDeviceCapsSequence(
                self.test_context).run())
        if response_message.status_codes != mbim_constants.MBIM_STATUS_SUCCESS:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.4.5#1')
Beispiel #22
0
    def parse_ntb(self, raw_ntb_frame):
        """
        This function parses an NTB frame and returns the NTH header, NDP header
        and the payload parsed which can be used to inspect the response
        from the device.

        @param raw_ntb_frame: Array of bytes of an MBIM NTB frame.
        @raises MBIMComplianceNtbError if there is an error in parsing.
        @returns tuple of (nth, ndp, ndp_entries, payload) where,
                nth - NTH header object received.
                ndp - NDP header object received.
                ndp_entries - Array of NDP entry header objects.
                payload - Array of packets where each packet is a byte array.

        """
        # Read the nth header to find the ndp header index
        self.nth = self._nth_class(raw_data=raw_ntb_frame)
        ndp_offset = self.nth.fp_index
        # Verify the total length field
        if len(raw_ntb_frame) != self.nth.block_length:
            mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceNtbError,
                    'NTB size mismatch Total length: %x Reported: %x bytes' % (
                            len(raw_ntb_frame), self.nth.block_length))

        # Read the NDP header to find the number of packets in the entry
        self.ndp = self._ndp_class(raw_data=raw_ntb_frame[ndp_offset:])
        num_ndp_entries = (
               (self.ndp.length - self._ndp_class.get_struct_len()) /
               self._ndp_entry_class.get_struct_len())
        ndp_entries_offset = ndp_offset + self._ndp_class.get_struct_len()
        self.payload = []
        self.ndp_entries = []
        for _ in range(0, num_ndp_entries):
            ndp_entry = self._ndp_entry_class(
                   raw_data=raw_ntb_frame[ndp_entries_offset:])
            ndp_entries_offset += self._ndp_entry_class.get_struct_len()
            packet_start_offset = ndp_entry.datagram_index
            packet_end_offset = (
                   ndp_entry.datagram_index + ndp_entry.datagram_length)
            # There is one extra ZLP NDP entry at the end, so account for it.
            if ndp_entry.datagram_index and ndp_entry.datagram_length:
                packet = array.array('B', raw_ntb_frame[packet_start_offset:
                                                        packet_end_offset])
                self.payload.append(packet)
            self.ndp_entries.append(ndp_entry)

        self.raw_ntb_frame = raw_ntb_frame

        return (self.nth, self.ndp, self.ndp_entries, self.payload)
Beispiel #23
0
    def run_internal(self):
        """ Run CM_03 test. """
        # Precondition
        _, _ = mbim_open_generic_sequence.MBIMOpenGenericSequence(
            self.test_context).run()
        # Step 1
        open_message, response_message = (
            mbim_open_generic_sequence.MBIMOpenGenericSequence(
                self.test_context).run())

        # Validate function's behaviour for an unsynchronized MBIM_OPEN_MSG.
        if response_message.message_type == mbim_constants.MBIM_CLOSE_DONE:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.3.1#1')
Beispiel #24
0
    def run_internal(self):
        """ Run CM_04 test. """
        # Precondition
        mbim_open_generic_sequence.MBIMOpenGenericSequence(
                self.test_context).run()

        # Step 1
        command_message, response_message = (
                mbim_cid_device_caps_sequence.MBIMCIDDeviceCapsSequence(
                        self.test_context).run())
        # Validate |transaction_id| in the response to MBIM_COMMAND_MSG.
        if response_message.transaction_id != command_message.transaction_id:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.4.3')
Beispiel #25
0
    def run_internal(self):
        """ Run CM_09 test. """
        # Precondition
        mbim_open_generic_sequence.MBIMOpenGenericSequence(
            self.test_context).run()

        # Step 1
        _, _, notifications = (connect_sequence.ConnectSequence(
            self.test_context).run())

        # Step 2
        for notification in notifications:
            if notification.transaction_id != 0:
                mbim_errors.log_and_raise(
                    mbim_errors.MBIMComplianceAssertionError, 'mbim1.0:9.1#1')
    def get_payload_len(self):
        """
        Helper function to find the payload len field value in the given
        object.

        @returns Corresponding field value extracted from the object.

        """
        payload_len_fields = self._get_fields_of_type(FIELD_TYPE_PAYLOAD_LEN)
        if ((not payload_len_fields) or (len(payload_len_fields) > 1)):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceControlMessageError,
                "Erorr in finding payload len field in message: %s" %
                self.__class__.__name__)
        return payload_len_fields.values()[0]
Beispiel #27
0
    def run_internal(self):
        """ Run DTS_01 test. """
        # Precondition
        _, _, _ = self.run_precondition(mbim_constants.NTB_FORMAT_16)

        # Step 1
        loopback = loopback_sequence.LoopbackSequence(self.device_context)
        _, _, _, payload = loopback.run(
            ntb_format=mbim_constants.NTB_FORMAT_16)

        # Step 2
        # Let's check the first byte of the first received payload to verify
        # that it is an IPv4 packet
        if payload[0][0] != 0x45:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:3.2.1#5')
    def get_total_len(self):
        """
        Helper function to find the total len field value in the given
        object.

        @returns Corresponding field value extracted from the object.

        """
        total_len_fields = self._get_fields_of_type(FIELD_TYPE_TOTAL_LEN,
                                                    get_all=True)
        if ((not total_len_fields) or (len(total_len_fields) > 1)):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceControlMessageError,
                "Erorr in finding total len field in message: %s" %
                self.__class__.__name__)
        return total_len_fields.values()[0]
    def get_num_fragments(self):
        """
        Helper function to find the fragment num field value in the given
        object.

        @returns Corresponding field value extracted from the object.

        """
        num_fragment_fields = self._get_fields_of_type(
            FIELD_TYPE_NUM_FRAGMENTS)
        if ((not num_fragment_fields) or (len(num_fragment_fields) > 1)):
            mbim_errors.log_and_raise(
                mbim_errors.MBIMComplianceControlMessageError,
                "Erorr in finding num fragments field in message: %s" %
                self.__class__.__name__)
        return num_fragment_fields.values()[0]
    def run_internal(self):
        """ Run the CM_02 test. """
        # Precondition.
        descriptors = get_descriptors_sequence.GetDescriptorsSequence(
            self.device_context).run()
        self.device_context.update_descriptor_cache(descriptors)

        # Step 1
        _, response_message = (
            mbim_open_generic_sequence.MBIMOpenGenericSequence(
                self.device_context).run())

        # Validate message length of response to MBIM_OPEN_MESSAGE.
        if response_message.message_length < 0x0C:
            mbim_errors.log_and_raise(mbim_errors.MBIMComplianceAssertionError,
                                      'mbim1.0:9.1#2')