X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/22f4dca88cc008287b1ef01bb4da0d46cbcf76d1..e1778858ddc53a6a82e8ee24f02e6b673687f69a:/armsrc/util.c?ds=inline diff --git a/armsrc/util.c b/armsrc/util.c index 1716a113..6c3c06a3 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -7,31 +7,8 @@ //----------------------------------------------------------------------------- // Utility functions used in many places, not specific to any piece of code. //----------------------------------------------------------------------------- - #include "util.h" -void print_result(char *name, uint8_t *buf, size_t len) { - uint8_t *p = buf; - - if ( len % 16 == 0 ) { - for(; p-buf < len; p += 16) - Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x", - name, - p-buf, - len, - 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] - ); - } - else { - for(; p-buf < len; p += 8) - Dbprintf("[%s:%d/%d] %02x %02x %02x %02x %02x %02x %02x %02x", - name, - p-buf, - len, - p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); - } -} - size_t nbytes(size_t nbits) { return (nbits >> 3)+((nbits % 8) > 0); } @@ -97,6 +74,36 @@ int32_t le24toh (uint8_t data[3]) { return (data[2] << 16) | (data[1] << 8) | data[0]; } +//convert hex digit to integer +uint8_t hex2int(char hexchar){ + switch(hexchar){ + case '0': return 0; break; + case '1': return 1; break; + case '2': return 2; break; + case '3': return 3; break; + case '4': return 4; break; + case '5': return 5; break; + case '6': return 6; break; + case '7': return 7; break; + case '8': return 8; break; + case '9': return 9; break; + case 'a': + case 'A': return 10; break; + case 'b': + case 'B': return 11; break; + case 'c': + case 'C': return 12; break; + case 'd': + case 'D': return 13; break; + case 'e': + case 'E': return 14; break; + case 'f': + case 'F': return 15; break; + default: + return 0; + } +} + void LEDsoff() { LED_A_OFF(); LED_B_OFF();