Activate DEP communication with a target.

def activate(self, target=None, **options):
        """Activate DEP communication with a target."""
        log.debug("initiator options: {0}".format(options))

        self.did = options.get('did', None)
        self.nad = options.get('nad', None)
        self.gbi = options.get('gbi', '')[0:48]
        self.brs = min(max(0, options.get('brs', 2)), 2)
        self.lri = min(max(0, options.get('lri', 3)), 3)
        if self._acm is None or 'acm' in options:
            self._acm = bool(options.get('acm', True))

        assert self.did is None or 0 <= self.did <= 255
        assert self.nad is None or 0 <= self.nad <= 255

        ppi = (self.lri << 4) | (bool(self.gbi) << 1) | int(bool(self.nad))
        did = 0 if self.did is None else self.did
        atr_req = ATR_REQ(os.urandom(10), did, 0, 0, ppi, self.gbi)
        psl_req = PSL_REQ(did, (0, 9, 18)[self.brs], self.lri)
        atr_res = psl_res = None
        self.target = target

        if self.target is None and self.acm is True:
            log.debug("searching active communication mode target at 106A")
            tg = nfc.clf.RemoteTarget("106A", atr_req=atr_req.encode())
            try:
                self.target = self.clf.sense(tg, iterations=2, interval=0.1)
            except nfc.clf.UnsupportedTargetError:
                self._acm = False
            except nfc.clf.CommunicationError:
                pass
            else:
                if self.target:
                    atr_res = ATR_RES.decode(self.target.atr_res)
                else:
                    self._acm = None

        if self.target is None:
            log.debug("searching passive communication mode target at 106A")
            target = nfc.clf.RemoteTarget("106A")
            target = self.clf.sense(target, iterations=2, interval=0.1)
            if target and target.sel_res and bool(target.sel_res[0] & 0x40):
                self.target = target

        if self.target is None and self.brs > 0:
            log.debug("searching passive communication mode target at 212F")
            target = nfc.clf.RemoteTarget("212F", sensf_req=b'\0\xFF\xFF\0\0')
            target = self.clf.sense(target, iterations=2, interval=0.1)
            if target and target.sensf_res.startswith(b'\1\1\xFE'):
                atr_req.nfcid3 = target.sensf_res[1:9] + b'ST'
                self.target = target

        if self.target and self.target.atr_res is None:
            try:
                atr_res = self.send_req_recv_res(atr_req, 1.0)
            except nfc.clf.CommunicationError:
                pass
            if atr_res is None:
                log.debug("NFC-DEP Attribute Request failed")
                return None

        if self.target and atr_res:
            if self.brs > ('106A', '212F', '424F').index(self.target.brty):
                try:
                    psl_res = self.send_req_recv_res(psl_req, 0.1)
                except nfc.clf.CommunicationError:
                    pass
                if psl_res is None:
                    log.debug("NFC-DEP Parameter Selection failed")
                    return None
                self.target.brty = ('212F', '424F')[self.brs-1]

            self.rwt = (4096/13.56E6
                        * 2**(atr_res.wt if atr_res.wt < 15 else 14))
            self.miu = (atr_res.lr-3 - int(self.did is not None)
                        - int(self.nad is not None))
            self.gbt = atr_res.gb
            self.pni = 0

            log.info("running as " + str(self))
            return self.gbt