+ uint8_t first, second;
+ ComputeCrc14443(CRC_14443_A, data, datalen, &first, &second);
+ data[datalen++] = first;
+ data[datalen++] = second;
+ }
+
+ if(active || active_select)
+ {
+ c.arg[0] |= ISO14A_CONNECT;
+ if(active)
+ c.arg[0] |= ISO14A_NO_SELECT;
+ }
+ if(power)
+ c.arg[0] |= ISO14A_NO_DISCONNECT;
+ if(datalen>0)
+ c.arg[0] |= ISO14A_RAW;
+
+ c.arg[1] = datalen;
+ c.arg[2] = numbits;
+ memcpy(c.d.asBytes,data,datalen);
+
+ SendCommand(&c);
+
+ if (reply) {
+ if(active_select)
+ waitCmd(1);
+ if(datalen>0)
+ waitCmd(0);
+ } // if reply
+ return 0;
+}
+
+static void waitCmd(uint8_t iSelect)
+{
+ uint8_t *recv;
+ UsbCommand resp;
+ char *hexout;
+
+ if (WaitForResponseTimeout(CMD_ACK,&resp,1000)) {
+ recv = resp.d.asBytes;
+ uint8_t iLen = iSelect ? resp.arg[1] : resp.arg[0];
+ PrintAndLog("received %i octets",iLen);
+ if(!iLen)
+ return;
+ hexout = (char *)malloc(iLen * 3 + 1);
+ if (hexout != NULL) {
+ for (int i = 0; i < iLen; i++) { // data in hex
+ sprintf(&hexout[i * 3], "%02X ", recv[i]);
+ }
+ PrintAndLog("%s", hexout);
+ free(hexout);
+ } else {
+ PrintAndLog("malloc failed your client has low memory?");
+ }
+ } else {
+ PrintAndLog("timeout while waiting for reply.");