move args to device_init

This commit is contained in:
Conor Patrick 2019-04-23 21:12:40 -04:00
parent 494e856198
commit 8fc0da7934
3 changed files with 43 additions and 42 deletions

View File

@ -21,58 +21,25 @@
#if !defined(TEST) #if !defined(TEST)
bool use_udp = true;
void usage(const char * cmd)
{
fprintf(stderr, "Usage: %s [-b udp|hidg]\n", cmd);
fprintf(stderr, " -b backing implementation: udp(default) or hidg\n");
exit(1);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
uint8_t hidmsg[64]; uint8_t hidmsg[64];
uint32_t t1 = 0; uint32_t t1 = 0;
int opt;
while ((opt = getopt(argc, argv, "b:")) != -1)
{
switch (opt)
{
case 'b':
if (strcmp("udp", optarg) == 0)
{
use_udp = true;
}
else if (strcmp("hidg", optarg) == 0)
{
use_udp = false;
}
else
{
usage(argv[0]);
}
break;
default:
usage(argv[0]);
break;
}
}
set_logging_mask( set_logging_mask(
/*0*/ /*0*/
//TAG_GEN| //TAG_GEN|
//TAG_MC | //TAG_MC |
//TAG_GA | //TAG_GA |
//TAG_WALLET | TAG_WALLET |
TAG_STOR | TAG_STOR |
//TAG_NFC_APDU | //TAG_NFC_APDU |
TAG_NFC | TAG_NFC |
//TAG_CP | //TAG_CP |
//TAG_CTAP| //TAG_CTAP|
//TAG_HID| //TAG_HID|
//TAG_U2F| TAG_U2F|
//TAG_PARSE | //TAG_PARSE |
//TAG_TIME| //TAG_TIME|
//TAG_DUMP| //TAG_DUMP|
@ -81,14 +48,10 @@ int main(int argc, char *argv[])
TAG_ERR TAG_ERR
); );
device_init(); device_init(argc, argv);
memset(hidmsg,0,sizeof(hidmsg)); memset(hidmsg,0,sizeof(hidmsg));
// printf1(TAG_GEN,"recv'ing hid msg \n");
while(1) while(1)
{ {

View File

@ -25,6 +25,8 @@
#define RK_NUM 50 #define RK_NUM 50
bool use_udp = true;
struct ResidentKeyStore { struct ResidentKeyStore {
CTAP_residentKey rks[RK_NUM]; CTAP_residentKey rks[RK_NUM];
} RK_STORE; } RK_STORE;
@ -211,8 +213,44 @@ void int_handler(int i)
exit(0); exit(0);
} }
void device_init()
void usage(const char * cmd)
{ {
fprintf(stderr, "Usage: %s [-b udp|hidg]\n", cmd);
fprintf(stderr, " -b backing implementation: udp(default) or hidg\n");
exit(1);
}
void device_init(int argc, char *argv[])
{
int opt;
while ((opt = getopt(argc, argv, "b:")) != -1)
{
switch (opt)
{
case 'b':
if (strcmp("udp", optarg) == 0)
{
use_udp = true;
}
else if (strcmp("hidg", optarg) == 0)
{
use_udp = false;
}
else
{
usage(argv[0]);
}
break;
default:
usage(argv[0]);
break;
}
}
signal(SIGINT, int_handler); signal(SIGINT, int_handler);
printf1(TAG_GREEN, "Using %s backing\n", use_udp ? "UDP" : "hidg"); printf1(TAG_GREEN, "Using %s backing\n", use_udp ? "UDP" : "hidg");

View File

@ -107,7 +107,7 @@ void device_reboot()
NVIC_SystemReset(); NVIC_SystemReset();
} }
void device_init() void device_init(int argc, char *argv[])
{ {
hw_init(LOW_FREQUENCY); hw_init(LOW_FREQUENCY);