X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/5e6a0b23695a3c4677b1e84ffbc5cd5140e4a491..8a6aec16d8c21d3c57457e5ec00eb83f5242feba:/armsrc/util.c diff --git a/armsrc/util.c b/armsrc/util.c index 8a3da63a..650ba22b 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -52,6 +52,19 @@ int strlen(char *str) return l; } +char* strncat(char *dest, const char *src, unsigned int n) +{ + unsigned int dest_len = strlen(dest); + unsigned int i; + + for (i = 0 ; i < n && src[i] != '\0' ; i++) + dest[dest_len + i] = src[i]; + dest[dest_len + i] = '\0'; + + return dest; +} + + void LEDsoff() { LED_A_OFF(); @@ -222,3 +235,37 @@ void SpinDelay(int ms) // convert to uS and call microsecond delay function SpinDelayUs(ms*1000); } + +/* Similar to FpgaGatherVersion this formats stored version information + * into a string representation. It takes a pointer to the struct version_information, + * verifies the magic properties, then stores a formatted string, prefixed by + * prefix in dst. + */ +void FormatVersionInformation(char *dst, int len, const char *prefix, void *version_information) +{ + struct version_information *v = (struct version_information*)version_information; + dst[0] = 0; + strncat(dst, prefix, len); + if(v->magic != VERSION_INFORMATION_MAGIC) { + strncat(dst, "Missing/Invalid version information", len); + return; + } + if(v->versionversion != 1) { + strncat(dst, "Version information not understood", len); + return; + } + if(!v->present) { + strncat(dst, "Version information not available", len); + return; + } + + strncat(dst, v->svnversion, len); + if(v->clean == 0) { + strncat(dst, "-unclean", len); + } else if(v->clean == 2) { + strncat(dst, "-suspect", len); + } + + strncat(dst, " ", len); + strncat(dst, v->buildtime, len); +}