X-Git-Url: https://iam.tj/gitweb/gitweb.cgi?p=cfe_generate_password.git;a=blobdiff_plain;f=cfe_generate_password.c;h=967543ba07b1841b485ce850403174cf3f867145;hp=47a4ba8ffa27d91b31fbbc84e2d9e67251ffa7e1;hb=db32317f1b24a5ab72dcf5facfacc9816fc36dc7;hpb=ed0120009fcdc809c1e1e6c81385d7009b3e9006 diff --git a/cfe_generate_password.c b/cfe_generate_password.c index 47a4ba8..967543b 100644 --- a/cfe_generate_password.c +++ b/cfe_generate_password.c @@ -5,7 +5,7 @@ Licenced on the terms of the GNU General Public Licence version 3 To build: - + gcc -o cfe_gen_pass cfe_generate_password.c Or: @@ -20,7 +20,7 @@ Broadcom Common Firmware Environment (CFE) bootbase which has a debug mode that is enabled using the "ATEN 1 XXXXXXXX" command, where XXXXXXXX is an eight digit hexadecimal 'password'. - + It is NOT necessary to have the device generate a 'seed' using "ATSE [MODEL-ID]" because this tool can generate the seed from the device's first (base) MAC address *provided* the "ATSE" command has NOT been executed since the device last booted. @@ -60,11 +60,12 @@ #include #include -static const float VERSION = 1.0f; +static const float VERSION = 1.1f; static const size_t TIMESTAMP_SIZE = 6; static const size_t SEED_SIZE = 12; static const size_t PASSWORD_SIZE = 8; static const size_t MESSAGE_SIZE = 128; +static const size_t MAC_ADDR_SIZE = 17; static void pr_usage() @@ -96,7 +97,7 @@ pr_error_exit(unsigned int usage, const char *error, ...) if (usage) pr_usage(); - exit(EXIT_FAILURE); + exit(EXIT_FAILURE); } static const unsigned int passwords[8] = { @@ -114,13 +115,13 @@ static unsigned int generate_seed(char *mac, char *timestamp, char *seed) { unsigned int result = 0; - if (mac && strlen(mac) == 17) { + if (mac && strlen(mac) == MAC_ADDR_SIZE) { size_t i; char *mac_ptr = mac + 9; size_t ts_len = strlen(timestamp); for (i = 0; i <= SEED_SIZE; ++i) { /* if no timestamp assume CFE get_time() returned 0 and CFE g_pw_timestamp == 0x00000000 */ - if (i < 6) + if (i < 6) seed[i] = ts_len ? timestamp[i] : '0'; else { if (*mac_ptr == ':' || *mac_ptr == '-') @@ -140,7 +141,7 @@ generate_pass(char *seed, char *password) { unsigned int result = 0; - if (seed && strlen(seed) == 12) { + if (seed && strlen(seed) == SEED_SIZE) { unsigned int timestamp, byte, key, pass; timestamp = byte = 0; if(! sscanf(seed, "%06x", ×tamp)) @@ -200,7 +201,7 @@ main(int argc, char **argv, char **env) } else if (opt_pass == 1 && opt_seed == 0) { if (arg_len != SEED_SIZE) pr_error_exit(1, "seed length must be %d characters", SEED_SIZE); - + strncpy(seed, argv[arg], SEED_SIZE); ++opt_pass; } else if (opt_ts == 1) {