Listen as Type A Target in 106 kbps.

        Restrictions:

        * It is not possible to send short frames that are required
          for ACK and NAK responses. This means that a Type 2 Tag
          emulation can only implement a single sector memory model.

        * It can not be avoided that the chipset responds to SENSF_REQ
          commands. The driver configures the SENSF_RES response to
          all zero and ignores all Type F communication but eventually
          it depends on the remote device whether Type A Target
          activation will still be attempted.

def listen_tta(self, target, timeout):
        """Listen as Type A Target in 106 kbps.

        Restrictions:

        * It is not possible to send short frames that are required
          for ACK and NAK responses. This means that a Type 2 Tag
          emulation can only implement a single sector memory model.

        * It can not be avoided that the chipset responds to SENSF_REQ
          commands. The driver configures the SENSF_RES response to
          all zero and ignores all Type F communication but eventually
          it depends on the remote device whether Type A Target
          activation will still be attempted.

        """
        if not target.brty == '106A':
            info = "unsupported target bitrate: %r" % target.brty
            raise nfc.clf.UnsupportedTargetError(info)

        if target.rid_res:
            info = "listening for type 1 tag activation is not supported"
            raise nfc.clf.UnsupportedTargetError(info)

        if target.sens_res is None:
            raise ValueError("sens_res is required")
        if target.sdd_res is None:
            raise ValueError("sdd_res is required")
        if target.sel_res is None:
            raise ValueError("sel_res is required")
        if len(target.sens_res) != 2:
            raise ValueError("sens_res must be 2 byte")
        if len(target.sdd_res) != 4:
            raise ValueError("sdd_res must be 4 byte")
        if len(target.sel_res) != 1:
            raise ValueError("sel_res must be 1 byte")
        if target.sdd_res[0] != 0x08:
            raise ValueError("sdd_res[0] must be 08h")

        nfca_params = target.sens_res + target.sdd_res[1:4] + target.sel_res
        log.debug("nfca_params %s", hexlify(nfca_params))

        self.chipset.tg_set_rf("106A")
        self.chipset.tg_set_protocol(self.chipset.tg_set_protocol_defaults)
        self.chipset.tg_set_protocol(rf_off_error=False)

        time_to_return = time.time() + timeout
        tg_comm_rf_args = {'mdaa': True, 'nfca_params': nfca_params}
        tg_comm_rf_args['recv_timeout'] = min(int(1000 * timeout), 0xFFFF)

        def listen_tta_tt2():
            recv_timeout = tg_comm_rf_args['recv_timeout']
            while recv_timeout > 0:
                log.debug("wait %d ms for Type 2 Tag activation", recv_timeout)
                try:
                    data = self.chipset.tg_comm_rf(**tg_comm_rf_args)
                except CommunicationError as error:
                    log.debug(error)
                else:
                    brty = ('106A', '212F', '424F')[data[0]-11]
                    log.debug("%s rcvd %s", brty, hexlify(buffer(data, 7)))
                    if brty == "106A" and data[2] & 0x03 == 3:
                        self.chipset.tg_set_protocol(rf_off_error=True)
                        return nfc.clf.LocalTarget(
                            "106A", sens_res=nfca_params[0:2],
                            sdd_res=b'\x08'+nfca_params[2:5],
                            sel_res=nfca_params[5:6], tt2_cmd=data[7:])
                    else:
                        log.debug("not a 106A Type 2 Tag command")
                finally:
                    recv_timeout = int(1000 * (time_to_return - time.time()))
                    tg_comm_rf_args['recv_timeout'] = recv_timeout

        def listen_tta_tt4():
            rats_cmd = rats_res = None
            recv_timeout = tg_comm_rf_args['recv_timeout']
            while recv_timeout > 0:
                log.debug("wait %d ms for 106A TT4 command", recv_timeout)
                try:
                    data = self.chipset.tg_comm_rf(**tg_comm_rf_args)
                    tg_comm_rf_args['transmit_data'] = None
                except CommunicationError as error:
                    tg_comm_rf_args['transmit_data'] = None
                    rats_cmd = rats_res = None
                    log.debug(error)
                else:
                    brty = ('106A', '212F', '424F')[data[0]-11]
                    log.debug("%s rcvd %s", brty, hexlify(buffer(data, 7)))
                    if brty == "106A" and data[2] == 3 and data[7] == 0xE0:
                        (rats_cmd, rats_res) = (data[7:], target.rats_res)
                        log.debug("rcvd RATS_CMD %s", hexlify(rats_cmd))
                        if rats_res is None:
                            rats_res = bytearray.fromhex("05 78 80 70 02")
                        log.debug("send RATS_RES %s", hexlify(rats_res))
                        tg_comm_rf_args['transmit_data'] = rats_res
                    elif brty == "106A" and data[7] != 0xF0 and rats_cmd:
                        did = rats_cmd[1] & 0x0F
                        cmd = data[7:]
                        ta_tb_tc = rats_res[2:]
                        ta = ta_tb_tc.pop(0) if rats_res[1] & 0x10 else None
                        tb = ta_tb_tc.pop(0) if rats_res[1] & 0x20 else None
                        tc = ta_tb_tc.pop(0) if rats_res[1] & 0x40 else None
                        if ta is not None:
                            log.debug("TA(1) = {:08b}".format(ta))
                        if tb is not None:
                            log.debug("TB(1) = {:08b}".format(tb))
                        if tc is not None:
                            log.debug("TC(1) = {:08b}".format(tc))
                        if ta_tb_tc:
                            log.debug("T({}) = {}".format(
                                len(ta_tb_tc), hexlify(ta_tb_tc)))
                        did_supported = tc is None or bool(tc & 0x02)
                        cmd_with_did = bool(cmd[0] & 0x08)
                        if (((cmd_with_did and did_supported and cmd[1] == did)
                             or (did == 0 and not cmd_with_did))):
                            if cmd[0] in (0xC2, 0xCA):
                                log.debug("rcvd S(DESELECT) %s", hexlify(cmd))
                                tg_comm_rf_args['transmit_data'] = cmd
                                log.debug("send S(DESELECT) %s", hexlify(cmd))
                                rats_cmd = rats_res = None
                            else:
                                log.debug("rcvd TT4_CMD %s", hexlify(cmd))
                                self.chipset.tg_set_protocol(rf_off_error=True)
                                return nfc.clf.LocalTarget(
                                    "106A", sens_res=nfca_params[0:2],
                                    sdd_res=b'\x08'+nfca_params[2:5],
                                    sel_res=nfca_params[5:6], tt4_cmd=cmd,
                                    rats_cmd=rats_cmd, rats_res=rats_res)
                        else:
                            log.debug("skip TT4_CMD %s (DID)", hexlify(cmd))
                    else:
                        log.debug("not a 106A TT4 command")
                finally:
                    recv_timeout = int(1000 * (time_to_return - time.time()))
                    tg_comm_rf_args['recv_timeout'] = recv_timeout

        if target.sel_res[0] & 0x60 == 0x00:
            return listen_tta_tt2()
        if target.sel_res[0] & 0x20 == 0x20:
            return listen_tta_tt4()

        reason = "sel_res does not indicate any tag target support"
        raise nfc.clf.UnsupportedTargetError(reason)