+ uint16_t traceLen = resp.arg[1];\r
+ len = resp.arg[2];\r
+\r
+ if (res == 0) return 0; // we are done\r
+\r
+ if (res == 1) { // there is (more) data to be transferred\r
+ if (pckNum == 0) { // first packet, (re)allocate necessary buffer\r
+ if (traceLen > bufsize) {\r
+ uint8_t *p;\r
+ if (buf == NULL) { // not yet allocated\r
+ p = malloc(traceLen);\r
+ } else { // need more memory\r
+ p = realloc(buf, traceLen);\r
+ }\r
+ if (p == NULL) {\r
+ PrintAndLog("Cannot allocate memory for trace");\r
+ free(buf);\r
+ return 2;\r
+ }\r
+ buf = p;\r
+ }\r