diff --git a/pib/Makefile b/pib/Makefile index 3af94c8c..87bda83f 100644 --- a/pib/Makefile +++ b/pib/Makefile @@ -70,7 +70,7 @@ setpib: setpib.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o ba setpib1: setpib1.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o basespec.o error.o todigit.o uintspec.o bytespec.o pibfile1.o checksum32.o fdchecksum32.o memencode.o setpib2: setpib2.o getoptv.o putoptv.o version.o hexpeek.o hexdump.o dataspec.o basespec.o error.o todigit.o uintspec.o bytespec.o pibfile1.o checksum32.o fdchecksum32.o memencode.o psin: psin.o getoptv.o putoptv.o version.o hexdecode.o hexstring.o todigit.o error.o pibfile1.o piblock.o pibscalers.o fdchecksum32.o -pskey: pskey.o getoptv.o putoptv.o version.o error.o hexdecode.o hexstring.o hexout.o pibfile1.o SHA256Reset.o SHA256Write.o SHA256Block.o SHA256Fetch.o keys.o fdchecksum32.o +pskey: pskey.o getoptv.o putoptv.o version.o error.o hexdecode.o hexstring.o hexout.o pibfile.o pibfile1.o pibfile2.o pibscalers.o SHA256Reset.o SHA256Write.o SHA256Block.o SHA256Fetch.o keys.o checksum32.o fdchecksum32.o psout: psout.o getoptv.o putoptv.o version.o error.o pibfile.o pibfile1.o pibfile2.o pibscalers.o checksum32.o fdchecksum32.o psnotch: psnotch.o getoptv.o putoptv.o version.o error.o todigit.o uintspec.o psgraph: psgraph.o getoptv.o putoptv.o version.o error.o todigit.o uintspec.o pibscalers.o diff --git a/pib/pskey.c b/pib/pskey.c index a39a3371..f84567a0 100644 --- a/pib/pskey.c +++ b/pib/pskey.c @@ -46,6 +46,7 @@ * * Contributor(s): * Charles Maier + * Stefan Wahren * *--------------------------------------------------------------------*/ @@ -72,6 +73,7 @@ #include "../key/HPAVKey.h" #include "../key/SHA256.h" #include "../pib/pib.h" +#include "../plc/plc.h" /*====================================================================* * custom source files; @@ -81,6 +83,7 @@ #include "../tools/getoptv.c" #include "../tools/putoptv.c" #include "../tools/version.c" +#include "../tools/checksum32.c" #include "../tools/fdchecksum32.c" #include "../tools/hexdecode.c" #include "../tools/hexstring.c" @@ -89,7 +92,10 @@ #endif #ifndef MAKEFILE +#include "../pib/pibfile.c" #include "../pib/pibfile1.c" +#include "../pib/pibfile2.c" +#include "../pib/pibscalers.c" #endif #ifndef MAKEFILE @@ -115,26 +121,37 @@ * the key with optional filename on stdout; the digest acts like * a fingerprint; * - * assume that offset and extent are for ar7400 and change to 6400 - * offset and extent when the PIB requires it; - * * *--------------------------------------------------------------------*/ -static signed pskey (struct _file_ * pib, off_t offset, void * memory, ssize_t extent, flag_t flags) +static signed pskey (struct _file_ * pib, void * memory, ssize_t extent, flag_t flags) { struct sha256 sha256; byte digest [SHA256_DIGEST_LENGTH]; struct pib_header pib_header; - if (read (pib->file, &pib_header, sizeof (pib_header)) != sizeof (pib_header)) - { - return (-1); - } - if (pib_header.FWVERSION < 0x05) + off_t offset; + unsigned scalers = pibscalers (pib); + switch (scalers) { + case PLC_CARRIERS: + offset = QCA_PRESCALER_OFFSET; + extent = QCA_PRESCALER_LENGTH; + break; + case AMP_CARRIERS: + offset = AMP_PRESCALER_OFFSET; + extent = AMP_PRESCALER_LENGTH; + break; + case INT_CARRIERS: offset = INT_PRESCALER_OFFSET; extent = INT_PRESCALER_LENGTH; + break; + default: + return (-1); + } + if (read (pib->file, &pib_header, sizeof (pib_header)) != sizeof (pib_header)) + { + return (-1); } if (lseek (pib->file, offset, SEEK_SET) != offset) { @@ -179,7 +196,7 @@ int main (int argc, char const * argv []) (char const *) (0) }; struct _file_ pib; - uint8_t buffer [INT_PRESCALER_LENGTH]; + uint8_t buffer [AMP_PRESCALER_LENGTH]; signed state = 0; flag_t flags = (flag_t) (0); signed c; @@ -209,12 +226,12 @@ int main (int argc, char const * argv []) state = 1; errno = 0; } - else if (pibfile1 (&pib)) + else if (pibfile (&pib)) { error (0, errno, "Bad PIB: %s", pib.name); state = 1; } - else if (pskey (&pib, INT_PRESCALER_OFFSET, buffer, sizeof (buffer), flags)) + else if (pskey (&pib, buffer, sizeof (buffer), flags)) { state = 1; }