From 55aafc2f3b7fb754080999671a1d1ee3d3f9266b Mon Sep 17 00:00:00 2001 From: Sean Godinez Date: Wed, 11 Mar 2015 07:53:35 -0500 Subject: added uuid field (16 bytes) to eeprom --- src/eeprom_main.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/eeprom_main.c b/src/eeprom_main.c index dab3933..22b2bb5 100644 --- a/src/eeprom_main.c +++ b/src/eeprom_main.c @@ -42,6 +42,38 @@ static int eeprom_size = 512; static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom); static void mts_ap_eeprom_inspect(struct mts_ap_eeprom_layout *ap_eeprom); +//Returns 0 on success, 1 on failure +static unsigned int charToInt(char ch, unsigned int* i) { + if (ch >= '0' && ch <= '9') { + *i = ch - '0'; + } else if (ch >= 'a' && ch <= 'f') { + *i = ch - 'a' + 10; + } else if (ch >= 'A' && ch <= 'F') { + *i = ch - 'A' + 10; + } else { + return 1; + } + return 0; +} + +//Retuns number of bytes converted, -1 on error +static int asciiHexToBin(const char* asciiHex, char* bin) { + int count = 0; + unsigned int upper, lower; + while(asciiHex[0] && asciiHex[1]) + { + if(charToInt(asciiHex[0], &upper) == 0 && charToInt(asciiHex[1], &lower) == 0) { + *bin = (upper << 4) + lower; + bin++; + asciiHex += 2; + count++; + } else { + return -1; + } + } + return count; +} + static int hwaddr_aton(const char *str, uint8_t *buf, size_t len) { size_t count = 0; @@ -92,6 +124,9 @@ static int hwaddr_aton(const char *str, uint8_t *buf, size_t len) static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) { + int i; + char buf[64] = {0}; + char* ptr; FILE *file; if (!strcmp(name, "-")) { @@ -127,7 +162,7 @@ static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) fprintf(file, "capa-bluetooth: %s\n", DEVICE_CAPA(id_eeprom->capa, CAPA_BLUETOOTH) ? "true" : "false"); fprintf(file, "capa: \""); - int i; + for (i = 0; i < sizeof(id_eeprom->capa); i++) { fprintf(file, "\\x%02X", id_eeprom->capa[i]); } @@ -147,6 +182,11 @@ static int id_yaml_out(const char *name, struct mts_id_eeprom_layout *id_eeprom) id_eeprom->mac_wifi[3], id_eeprom->mac_wifi[4], id_eeprom->mac_wifi[5]); + ptr = (char*)buf; + for(i = 0; i < 16; i++) { + ptr += sprintf(ptr, "%02X", id_eeprom->uuid[i]); + } + fprintf(file, "uuid: \"%s\"\n", (char*)buf); fprintf(file, "...\n"); fclose(file); @@ -229,6 +269,10 @@ static int bin_out(const char *name, char *eeprom) static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom) { + int i; + char buf[64] = {0}; + char* ptr; + log_info("sizeof: %u", sizeof(struct mts_id_eeprom_layout)); log_info("vendor-id: %.32s", id_eeprom->vendor_id); log_info("product-id: %.32s", id_eeprom->product_id); @@ -263,6 +307,12 @@ static void mts_id_eeprom_inspect(struct mts_id_eeprom_layout *id_eeprom) id_eeprom->mac_wifi[3], id_eeprom->mac_wifi[4], id_eeprom->mac_wifi[5]); + + ptr = (char*)buf; + for(i = 0; i < 16; i++) { + ptr += sprintf(ptr, "%02X", id_eeprom->uuid[i]); + } + log_info("uuid: %s", (char*)buf); } static void mts_ap_eeprom_inspect(struct mts_ap_eeprom_layout *ap_eeprom) @@ -307,6 +357,7 @@ static void usage(FILE *out) { fprintf(out, " --vendor-id |\n"); fprintf(out, " --product-id |\n"); fprintf(out, " --device-id |\n"); + fprintf(out, " --uuid |\n"); fprintf(out, " --hw-version |\n"); fprintf(out, " --mac-addr |\n"); fprintf(out, " --mac-bluetooth |\n"); @@ -333,6 +384,7 @@ enum { CMD_OPT_VENDOR_ID, CMD_OPT_PRODUCT_ID, CMD_OPT_DEVICE_ID, + CMD_OPT_UUID, CMD_OPT_HW_VERSION, CMD_OPT_MAC_ADDR, CMD_OPT_MAC_BLUETOOTH, @@ -360,6 +412,7 @@ static struct option long_options[] = { {"vendor-id", 1, NULL, CMD_OPT_VENDOR_ID}, {"product-id", 1, NULL, CMD_OPT_PRODUCT_ID}, {"device-id", 1, NULL, CMD_OPT_DEVICE_ID}, + {"uuid", 1, NULL, CMD_OPT_UUID}, {"hw-version", 1, NULL, CMD_OPT_HW_VERSION}, {"mac-addr", 1, NULL, CMD_OPT_MAC_ADDR}, {"mac-bluetooth", 1, NULL, CMD_OPT_MAC_BLUETOOTH}, @@ -396,6 +449,7 @@ int main(int argc, char *argv[]) { char *vendor_id = NULL; char *product_id = NULL; char *device_id = NULL; + char *uuid = NULL; char *hw_version = NULL; char *mac_addr = NULL; char *eui = NULL; @@ -522,6 +576,19 @@ int main(int argc, char *argv[]) { device_id = optarg; break; + case CMD_OPT_UUID: + if (accessory_card) { + log_error("UUID not supported on accessory card eeprom"); + usage(stderr); + exit(1); + } + if(asciiHexToBin(optarg, id_eeprom.uuid) != sizeof(id_eeprom.uuid)) { + log_error("invalid uuid %s", optarg); + usage(stderr); + exit(1); + } + break; + case CMD_OPT_HW_VERSION: hw_version = optarg; break; -- cgit v1.2.3