1 //-----------------------------------------------------------------------------
2 // Copyright (C) Jonathan Westhues, Mar 2006
3 // Copyright (C) Gerhard de Koning Gans, Sep 2007
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // See LICENSE.txt for the text of the license.
16 //-----------------------------------------------------------------------------
26 //=============================================================================
27 // Debug print functions, to go out over USB, to the usual PC-side client.
28 //=============================================================================
30 void DbpStringEx(uint32_t flags
, const char *src
, size_t srclen
) {
34 uint8_t buf
[PM3_CMD_DATA_SIZE
- sizeof(uint16_t)];
37 uint16_t len
= MIN(srclen
, sizeof(data
.buf
));
38 memcpy(data
.buf
, src
, len
);
39 reply_ng(CMD_DEBUG_PRINT_STRING
, PM3_SUCCESS
, (uint8_t *)&data
, sizeof(data
.flag
) + len
);
43 void DbpString(const char *str
) {
45 DbpStringEx(FLAG_LOG
, str
, strlen(str
));
49 void DbprintfEx(uint32_t flags
, const char *fmt
, ...) {
51 // should probably limit size here; oh well, let's just use a big buffer
52 char s
[PM3_CMD_DATA_SIZE
] = {0x00};
55 kvsprintf(fmt
, s
, 10, ap
);
58 DbpStringEx(flags
, s
, strlen(s
));
62 void Dbprintf(const char *fmt
, ...) {
64 // should probably limit size here; oh well, let's just use a big buffer
65 char output_string
[PM3_CMD_DATA_SIZE
] = {0x00};
69 kvsprintf(fmt
, output_string
, 10, ap
);
72 DbpString(output_string
);
77 void Dbhexdump(int len
, uint8_t *d
, bool bAsci
) {
83 int l
= (len
> 8) ? 8 : len
;
89 for (int i
= 0; i
< l
; i
++) {
90 if (ascii
[i
] < 32 || ascii
[i
] > 126) {
96 Dbprintf("%-8s %*D", ascii
, l
, d
, " ");
98 Dbprintf("%*D", l
, d
, " ");
106 void print_result(const char *name
, uint8_t *buf
, size_t len
) {
109 uint16_t tmp
= len
& 0xFFF0;
111 for (; p
- buf
< tmp
; p
+= 16) {
112 Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
116 p
[0], p
[1], p
[2], p
[3], p
[4], p
[5], p
[6], p
[7], p
[8], p
[9], p
[10], p
[11], p
[12], p
[13], p
[14], p
[15]
122 for (; p
- buf
< len
; p
++) {
123 sprintf(sp
, "%02x ", p
[0]);
126 Dbprintf("[%s: %02d/%02d] %s", name
, p
- buf
, len
, s
);
130 /* useful when debugging new protocol implementations like FeliCa
131 void PrintToSendBuffer(void) {
132 DbpString("Printing ToSendBuffer:");
133 Dbhexdump(ToSendMax, ToSend, 0);