Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QCA7000 support for pskey #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 29 additions & 12 deletions pib/pskey.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
*
* Contributor(s):
* Charles Maier <[email protected]>
* Stefan Wahren <[email protected]>
*
*--------------------------------------------------------------------*/

Expand All @@ -72,6 +73,7 @@
#include "../key/HPAVKey.h"
#include "../key/SHA256.h"
#include "../pib/pib.h"
#include "../plc/plc.h"

/*====================================================================*
* custom source files;
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down