Send an ISO/IEC 7816-4 APDU to the Type 4 Tag.

        The 4 byte APDU header (class, instruction, parameter 1 and 2)
        is constructed from the first four parameters (cla, ins, p1,
        p2) without interpretation. The byte string *data* argument
        represents the APDU command data field. It is encoded as a
        short or extended length field followed by the *data*
        bytes. The length field is not transmitted if *data* is None
        or an empty string. The maximum acceptable number of response
        data bytes is given with the max-response-length *mrl*
        argument. The value of *mrl* is transmitted as the 7816-4 APDU
        Le field after appropriate conversion.

        By default, the response is returned as a byte array not
        including the status word, a :exc:`Type4TagCommandError`
        exception is raised for any status word other than
        9000h. Response status verification can be disabled with
        *check_status* set to False, the byte array will then include
        the response status word at the last two positions.

        Transmission errors always raise a :exc:`Type4TagCommandError`
        exception.

def send_apdu(self, cla, ins, p1, p2, data=None, mrl=0, check_status=True):
        """Send an ISO/IEC 7816-4 APDU to the Type 4 Tag.

        The 4 byte APDU header (class, instruction, parameter 1 and 2)
        is constructed from the first four parameters (cla, ins, p1,
        p2) without interpretation. The byte string *data* argument
        represents the APDU command data field. It is encoded as a
        short or extended length field followed by the *data*
        bytes. The length field is not transmitted if *data* is None
        or an empty string. The maximum acceptable number of response
        data bytes is given with the max-response-length *mrl*
        argument. The value of *mrl* is transmitted as the 7816-4 APDU
        Le field after appropriate conversion.

        By default, the response is returned as a byte array not
        including the status word, a :exc:`Type4TagCommandError`
        exception is raised for any status word other than
        9000h. Response status verification can be disabled with
        *check_status* set to False, the byte array will then include
        the response status word at the last two positions.

        Transmission errors always raise a :exc:`Type4TagCommandError`
        exception.

        """
        apdu = bytearray([cla, ins, p1, p2])

        if not self._extended_length_support:
            if data and len(data) > 255:
                raise ValueError("unsupported command data length")
            if mrl and mrl > 256:
                raise ValueError("unsupported max response length")
            if data:
                apdu += pack('>B', len(data)) + data
            if mrl > 0:
                apdu += pack('>B', 0 if mrl == 256 else mrl)
        else:
            if data and len(data) > 65535:
                raise ValueError("invalid command data length")
            if mrl and mrl > 65536:
                raise ValueError("invalid max response length")
            if data:
                apdu += pack(">xH", len(data)) + data
            if mrl > 0:
                le = 0 if mrl == 65536 else mrl
                apdu += pack(">H", le) if data else pack(">xH", le)

        apdu = self.transceive(apdu)

        if not apdu or len(apdu) < 2:
            raise Type4TagCommandError(nfc.tag.PROTOCOL_ERROR)

        if check_status and apdu[-2:] != b"\x90\x00":
            raise Type4TagCommandError.from_status(apdu[-2:])

        return apdu[:-2] if check_status else apdu