Added resumable loading, along with signal handling.
This version can store state after receiving SIGINT. This is achieved by polling FIFO read state;
This commit is contained in:
67
monitor.cpp
67
monitor.cpp
@@ -1,60 +1,35 @@
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <array>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include "u2f.hpp"
|
||||
#include "Constants.hpp"
|
||||
#include "U2FMessage.hpp"
|
||||
#include "U2F_CMD.hpp"
|
||||
#include "Storage.hpp"
|
||||
#include "U2F_Init_CMD.hpp"
|
||||
#include "U2F_Init_Response.hpp"
|
||||
#include "U2F_Msg_CMD.hpp"
|
||||
#include "Controller.hpp"
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
void signalCallback(int signum);
|
||||
|
||||
volatile bool contProc = true;
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, signalCallback);
|
||||
Storage::init();
|
||||
|
||||
auto initFrame = U2F_Init_CMD::get();
|
||||
Controller ch{ 0xF1D00000 };
|
||||
|
||||
U2F_Init_Response resp{};
|
||||
|
||||
resp.cid = 0xF1D0F1D0;
|
||||
resp.nonce = initFrame.nonce;
|
||||
resp.protocolVer = 2;
|
||||
resp.majorDevVer = 1;
|
||||
resp.minorDevVer = 0;
|
||||
resp.buildDevVer = 1;
|
||||
resp.capabilities = CAPFLAG_WINK;
|
||||
|
||||
resp.write();
|
||||
|
||||
size_t msgCount = (argc == 2 ? stoul(argv[1]) : 3u);
|
||||
|
||||
for (size_t i = 0; i < msgCount; i++)
|
||||
while (contProc)
|
||||
{
|
||||
auto reg = U2F_Msg_CMD::get();
|
||||
|
||||
cout << "U2F CMD ins: " << static_cast<uint32_t>(reg->ins) << endl;
|
||||
|
||||
reg->respond();
|
||||
|
||||
clog << "Fully responded" << endl;
|
||||
ch.handleTransaction();
|
||||
usleep(10000);
|
||||
}
|
||||
|
||||
/*auto m = U2FMessage::read();
|
||||
|
||||
cout << "U2F CMD: " << static_cast<uint32_t>(m.cmd) << endl;
|
||||
|
||||
for (const auto d : m.data)
|
||||
clog << static_cast<uint16_t>(d) << endl;*/
|
||||
|
||||
Storage::save();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void signalCallback(int signum)
|
||||
{
|
||||
contProc = false;
|
||||
clog << "Caught SIGINT signal" << endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user