2018-09-13 21:58:34 +00:00
|
|
|
/*
|
|
|
|
Copyright 2018 Conor Patrick
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
of the Software, and to permit persons to whom the Software is furnished to do
|
|
|
|
so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
2018-04-28 17:40:28 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include "cbor.h"
|
2018-06-02 18:44:12 +00:00
|
|
|
#include "device.h"
|
2018-04-29 01:40:13 +00:00
|
|
|
#include "ctaphid.h"
|
2018-07-06 03:20:33 +00:00
|
|
|
//#include "bsp.h"
|
2018-04-28 17:40:28 +00:00
|
|
|
#include "util.h"
|
2018-05-18 15:40:17 +00:00
|
|
|
#include "log.h"
|
2018-05-17 02:44:31 +00:00
|
|
|
#include "ctap.h"
|
2018-07-23 03:40:27 +00:00
|
|
|
#include "app.h"
|
2018-04-28 17:40:28 +00:00
|
|
|
|
2018-06-04 23:39:52 +00:00
|
|
|
#if !defined(TEST)
|
2018-06-02 18:44:12 +00:00
|
|
|
|
2018-04-28 17:40:28 +00:00
|
|
|
int main(int argc, char * argv[])
|
|
|
|
{
|
2018-06-02 19:48:29 +00:00
|
|
|
int count = 0;
|
2018-07-06 03:20:33 +00:00
|
|
|
uint32_t t1 = 0;
|
|
|
|
uint32_t t2 = 0;
|
|
|
|
uint32_t accum = 0;
|
|
|
|
uint32_t dt = 0;
|
2018-06-02 18:44:12 +00:00
|
|
|
uint8_t hidmsg[64];
|
|
|
|
|
2018-05-18 15:40:17 +00:00
|
|
|
set_logging_mask(
|
2018-06-04 23:35:34 +00:00
|
|
|
/*0*/
|
2018-07-14 19:55:57 +00:00
|
|
|
TAG_GEN|
|
2018-06-02 22:30:59 +00:00
|
|
|
/*TAG_MC |*/
|
|
|
|
/*TAG_GA |*/
|
2018-07-14 19:55:57 +00:00
|
|
|
TAG_WALLET |
|
2018-07-12 01:55:20 +00:00
|
|
|
TAG_STOR |
|
2018-06-02 22:30:59 +00:00
|
|
|
/*TAG_CP |*/
|
2018-09-05 02:11:21 +00:00
|
|
|
TAG_CTAP|
|
2018-07-06 03:20:33 +00:00
|
|
|
// TAG_HID|
|
2018-06-02 22:30:59 +00:00
|
|
|
/*TAG_U2F|*/
|
|
|
|
/*TAG_PARSE |*/
|
2018-07-07 21:11:13 +00:00
|
|
|
// TAG_TIME|
|
2018-07-14 00:29:14 +00:00
|
|
|
/*TAG_DUMP|*/
|
2018-06-02 22:30:59 +00:00
|
|
|
/*TAG_GREEN|*/
|
|
|
|
/*TAG_RED|*/
|
2018-06-03 04:50:46 +00:00
|
|
|
TAG_ERR
|
2018-05-18 15:40:17 +00:00
|
|
|
);
|
|
|
|
|
2018-06-02 18:44:12 +00:00
|
|
|
device_init();
|
2018-06-28 01:39:19 +00:00
|
|
|
printf1(TAG_GEN,"init device\n");
|
2018-06-02 18:44:12 +00:00
|
|
|
|
2018-06-04 23:35:34 +00:00
|
|
|
printf1(TAG_GEN,"init ctaphid\n");
|
2018-04-29 01:40:13 +00:00
|
|
|
ctaphid_init();
|
2018-06-02 18:44:12 +00:00
|
|
|
|
2018-06-04 23:35:34 +00:00
|
|
|
printf1(TAG_GEN,"init ctap\n");
|
|
|
|
ctap_init();
|
|
|
|
|
|
|
|
memset(hidmsg,0,sizeof(hidmsg));
|
|
|
|
|
|
|
|
printf1(TAG_GEN,"recv'ing hid msg \n");
|
|
|
|
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if (millis() - t1 > 100)
|
|
|
|
{
|
|
|
|
/*printf("heartbeat %ld\n", beat++);*/
|
|
|
|
heartbeat();
|
|
|
|
t1 = millis();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (usbhid_recv(hidmsg) > 0)
|
|
|
|
{
|
|
|
|
printf1(TAG_DUMP,"%d>> ",count++); dump_hex1(TAG_DUMP, hidmsg,sizeof(hidmsg));
|
|
|
|
t2 = millis();
|
|
|
|
ctaphid_handle_packet(hidmsg);
|
|
|
|
accum += millis() - t2;
|
2018-07-06 03:20:33 +00:00
|
|
|
printf1(TAG_TIME,"accum: %d\n", (uint32_t)accum);
|
|
|
|
printf1(TAG_TIME,"dt: %d\n", t2 - dt);
|
|
|
|
dt = t2;
|
2018-06-04 23:35:34 +00:00
|
|
|
memset(hidmsg, 0, sizeof(hidmsg));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/*main_loop_delay();*/
|
|
|
|
}
|
|
|
|
ctaphid_check_timeouts();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Should never get here
|
|
|
|
usbhid_close();
|
|
|
|
printf("done\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|