Licenced on the terms of the GNU General Public Licence version 3
To build:
-
+
gcc -o cfe_gen_pass cfe_generate_password.c
Or:
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.
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
#include <stdarg.h>
#include <string.h>
-static const float VERSION = 1.0f;
-static const unsigned int TIMESTAMP_SIZE = 6;
-static const unsigned int SEED_SIZE = 12;
-static const unsigned int PASSWORD_SIZE = 8;
-static const unsigned int MESSAGE_SIZE = 128;
+static const float VERSION = 1.2f;
+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;
-void
+static void
pr_usage()
{
fprintf(stderr, "%s\n",
);
}
-void
+static void
pr_error_exit(unsigned int usage, const char *error, ...)
{
va_list args;
- char error_message[MESSAGE_SIZE];
+ char error_message[MESSAGE_SIZE + 1];
if (!error) return;
va_start(args, error);
- vsnprintf(error_message, MESSAGE_SIZE, error, args);
+ (void) vsnprintf(error_message, MESSAGE_SIZE + 1, error, args);
va_end(args);
fprintf(stderr, "Error: %s\n", error_message);
if (usage) pr_usage();
- exit(1);
+ exit(EXIT_FAILURE);
}
static const unsigned int passwords[8] = {
0xC621E14A
};
-unsigned int
+static unsigned int
generate_seed(char *mac, char *timestamp, char *seed)
{
unsigned int result = 0;
- if (mac && strlen(mac) == 17) {
- unsigned int i;
+ 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) {
+ 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 == '-')
}
result = 1;
} else
- pr_error_exit(0, "MAC-ADDR should be 17 characters, e.g: 00:01:02:03:04:05");
+ pr_error_exit(0, "MAC-ADDR should be %d characters, e.g: 00:01:02:03:04:05", MAC_ADDR_SIZE);
return result;
}
-unsigned int
+static unsigned int
generate_pass(char *seed, char *password)
{
unsigned int result = 0;
- if (seed && strlen(seed) == 12) {
- unsigned int timestamp = 0;
- unsigned byte = 0;
- sscanf(seed, "%06x", ×tamp);
- sscanf(&seed[10], "%02x", &byte);
- unsigned int key = byte & 0x07;
- unsigned int pass = (passwords[key] + timestamp) ^ timestamp;
+ if (seed && strlen(seed) == SEED_SIZE) {
+ unsigned int timestamp, byte, key, pass;
+ timestamp = byte = 0;
+ if(! sscanf(seed, "%06x", ×tamp))
+ pr_error_exit(1, "unable to parse seed's timestamp");
+ if (! sscanf(&seed[10], "%02x", &byte))
+ pr_error_exit(1, "unable to parse seed's MAC address");
+ key = byte & 0x07;
+ pass = (passwords[key] + timestamp) ^ timestamp;
snprintf(password, PASSWORD_SIZE + 1, "%08x", pass);
result = 1;
} else
else {
unsigned int arg;
char *MAC_ADDR = NULL;
- char *MODEL = NULL;
char timestamp[TIMESTAMP_SIZE + 1];
char seed[SEED_SIZE + 1];
char password[PASSWORD_SIZE + 1];
opt_seed = opt_pass = opt_ts = 0;
strncpy(timestamp, "000000", TIMESTAMP_SIZE);
- for (arg = 1; arg < argc; ++arg) {
+ for (arg = 1; arg < (unsigned) argc; ++arg) {
size_t arg_len = strlen(argv[arg]);
if (argv[arg][0] == '-') {
} 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) {
if (! generate_pass(seed, password))
pr_error_exit(0, "unable to generate password");
- printf("MAC address: %s Timestamp: %s Seed: %s Password: %s\n", MAC_ADDR, timestamp, seed, password);
+ if (opt_seed || opt_pass)
+ printf("MAC address: %s Timestamp: %s Seed: %s Password: %s\n", MAC_ADDR, timestamp, seed, password);
}
return result;