1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Mar 2006
3 // Edits by Gerhard de Koning Gans, Sep 2007 (##)
5 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
6 // at your option, any later version. See the LICENSE.txt file for the text of
8 //-----------------------------------------------------------------------------
9 // The main application code. This is the first thing called after start.c
11 //-----------------------------------------------------------------------------
21 //=============================================================================
22 // Debug print functions, to go out over USB, to the usual PC-side client.
23 //=============================================================================
25 void DbpStringEx(uint32_t flags
, const char *src
, size_t srclen
) {
29 uint8_t buf
[PM3_CMD_DATA_SIZE
- sizeof(uint16_t)];
32 uint16_t len
= MIN(srclen
, sizeof(data
.buf
));
33 memcpy(data
.buf
, src
, len
);
34 reply_ng(CMD_DEBUG_PRINT_STRING
, PM3_SUCCESS
, (uint8_t *)&data
, sizeof(data
.flag
) + len
);
38 void DbpString(const char *str
) {
40 DbpStringEx(FLAG_LOG
, str
, strlen(str
));
44 void DbprintfEx(uint32_t flags
, const char *fmt
, ...) {
46 // should probably limit size here; oh well, let's just use a big buffer
47 char s
[PM3_CMD_DATA_SIZE
] = {0x00};
50 kvsprintf(fmt
, s
, 10, ap
);
53 DbpStringEx(flags
, s
, strlen(s
));
57 void Dbprintf(const char *fmt
, ...) {
59 // should probably limit size here; oh well, let's just use a big buffer
60 char output_string
[PM3_CMD_DATA_SIZE
] = {0x00};
64 kvsprintf(fmt
, output_string
, 10, ap
);
67 DbpString(output_string
);
72 void Dbhexdump(int len
, uint8_t *d
, bool bAsci
) {
78 int l
= (len
> 8) ? 8 : len
;
84 for (int i
= 0; i
< l
; i
++) {
85 if (ascii
[i
] < 32 || ascii
[i
] > 126) {
91 Dbprintf("%-8s %*D", ascii
, l
, d
, " ");
93 Dbprintf("%*D", l
, d
, " ");
101 void print_result(const char *name
, uint8_t *buf
, size_t len
) {
104 uint16_t tmp
= len
& 0xFFF0;
106 for (; p
- buf
< tmp
; p
+= 16) {
107 Dbprintf("[%s: %02d/%02d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
111 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]
117 for (; p
- buf
< len
; p
++) {
118 sprintf(sp
, "%02x ", p
[0]);
121 Dbprintf("[%s: %02d/%02d] %s", name
, p
- buf
, len
, s
);
125 /* useful when debugging new protocol implementations like FeliCa
126 void PrintToSendBuffer(void) {
127 DbpString("Printing ToSendBuffer:");
128 Dbhexdump(ToSendMax, ToSend, 0);