def listen_ttf(self, target, timeout):
        """Listen as Type F Target is supported for either 212 or 424 kbps."""
        if target.brty not in ('212F', '424F'):
            info = "unsupported target bitrate: %r" % target.brty
            raise nfc.clf.UnsupportedTargetError(info)

        if target.sensf_res is None:
            raise ValueError("sensf_res is required")
        if len(target.sensf_res) != 19:
            raise ValueError("sensf_res must be 19 byte")

        self.chipset.tg_set_rf(target.brty)
        self.chipset.tg_set_protocol(self.chipset.tg_set_protocol_defaults)
        self.chipset.tg_set_protocol(rf_off_error=False)

        recv_timeout = min(int(1000 * timeout), 0xFFFF)
        time_to_return = time.time() + timeout
        transmit_data = sensf_req = sensf_res = None

        while recv_timeout > 0:
            if transmit_data:
                log.debug("%s send %s", target.brty, hexlify(transmit_data))
            log.debug("%s wait recv %d ms", target.brty, recv_timeout)
            try:
                data = self.chipset.tg_comm_rf(recv_timeout=recv_timeout,
                                               transmit_data=transmit_data)
            except CommunicationError as error:
                log.debug(error)
                continue
            finally:
                recv_timeout = int((time_to_return - time.time()) * 1E3)
                transmit_data = None

            assert target.brty == ('106A', '212F', '424F')[data[0]-11]
            log.debug("%s rcvd %s", target.brty, hexlify(buffer(data, 7)))

            if len(data) > 7 and len(data)-7 == data[7]:
                if sensf_req and data[9:17] == target.sensf_res[1:9]:
                    self.chipset.tg_set_protocol(rf_off_error=True)
                    target = nfc.clf.LocalTarget(target.brty)
                    target.sensf_req = sensf_req
                    target.sensf_res = sensf_res
                    target.tt3_cmd = data[8:]
                    return target

            if len(data) == 13 and data[7] == 6 and data[8] == 0:
                (sensf_req, sensf_res) = (data[8:], target.sensf_res[:])
                if (((sensf_req[1] == 255 or sensf_req[1] == sensf_res[17]) and
                     (sensf_req[2] == 255 or sensf_req[2] == sensf_res[18]))):
                    transmit_data = sensf_res[0:17]
                    if sensf_req[3] == 1:
                        transmit_data += sensf_res[17:19]
                    if sensf_req[3] == 2:
                        transmit_data += b"\x00"
                        transmit_data += chr(1 << (target.brty == "424F"))
                    transmit_data = chr(len(transmit_data)+1) + transmit_data
def listen_ttf ( self , target , timeout ) : if target . brty not in ( '212F' , '424F' ) : info = "unsupported target bitrate: %r" % target . brty raise nfc . clf . UnsupportedTargetError ( info ) if target . sensf_res is None : raise ValueError ( "sensf_res is required" ) if len ( target . sensf_res ) != 19 : raise ValueError ( "sensf_res must be 19 byte" ) self . chipset . tg_set_rf ( target . brty ) self . chipset . tg_set_protocol ( self . chipset . tg_set_protocol_defaults ) self . chipset . tg_set_protocol ( rf_off_error = False ) recv_timeout = min ( int ( 1000 * timeout ) , 0xFFFF ) time_to_return = time . time ( ) + timeout transmit_data = sensf_req = sensf_res = None while recv_timeout > 0 : if transmit_data : log . debug ( "%s send %s" , target . brty , hexlify ( transmit_data ) ) log . debug ( "%s wait recv %d ms" , target . brty , recv_timeout ) try : data = self . chipset . tg_comm_rf ( recv_timeout = recv_timeout , transmit_data = transmit_data ) except CommunicationError as error : log . debug ( error ) continue finally : recv_timeout = int ( ( time_to_return - time . time ( ) ) * 1E3 ) transmit_data = None assert target . brty == ( '106A' , '212F' , '424F' ) [ data [ 0 ] - 11 ] log . debug ( "%s rcvd %s" , target . brty , hexlify ( buffer ( data , 7 ) ) ) if len ( data ) > 7 and len ( data ) - 7 == data [ 7 ] : if sensf_req and data [ 9 : 17 ] == target . sensf_res [ 1 : 9 ] : self . chipset . tg_set_protocol ( rf_off_error = True ) target = nfc . clf . LocalTarget ( target . brty ) target . sensf_req = sensf_req target . sensf_res = sensf_res target . tt3_cmd = data [ 8 : ] return target if len ( data ) == 13 and data [ 7 ] == 6 and data [ 8 ] == 0 : ( sensf_req , sensf_res ) = ( data [ 8 : ] , target . sensf_res [ : ] ) if ( ( ( sensf_req [ 1 ] == 255 or sensf_req [ 1 ] == sensf_res [ 17 ] ) and ( sensf_req [ 2 ] == 255 or sensf_req [ 2 ] == sensf_res [ 18 ] ) ) ) : transmit_data = sensf_res [ 0 : 17 ] if sensf_req [ 3 ] == 1 : transmit_data += sensf_res [ 17 : 19 ] if sensf_req [ 3 ] == 2 : transmit_data += b"\x00" transmit_data += chr ( 1 << ( target . brty == "424F" ) ) transmit_data = chr ( len ( transmit_data ) + 1 ) + transmit_data
Listen as Type F Target is supported for either 212 or 424 kbps.