Improved debugging capabilities.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
deleteme
|
deleteme
|
||||||
SOut.txt
|
SOut.txt
|
||||||
|
comdev.txt
|
||||||
|
comhost.txt
|
||||||
|
|||||||
84
monitor.cpp
84
monitor.cpp
@@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
const constexpr uint16_t packetSize = 32;
|
const constexpr uint16_t packetSize = 64;
|
||||||
|
|
||||||
struct Packet
|
struct Packet
|
||||||
{
|
{
|
||||||
@@ -41,7 +41,7 @@ struct InitPacket : Packet
|
|||||||
struct ContPacket : Packet
|
struct ContPacket : Packet
|
||||||
{
|
{
|
||||||
uint8_t seq;
|
uint8_t seq;
|
||||||
array<uint8_t, packetSize - 7> data{};
|
array<uint8_t, packetSize - 5> data{};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContPacket() = default;
|
ContPacket() = default;
|
||||||
@@ -49,7 +49,7 @@ struct ContPacket : Packet
|
|||||||
void writePacket() override;
|
void writePacket() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
shared_ptr<FILE> getStream()
|
shared_ptr<FILE> getHostStream()
|
||||||
{
|
{
|
||||||
static shared_ptr<FILE> stream{ fopen("/dev/hidg0", "ab+"), [](FILE *f){
|
static shared_ptr<FILE> stream{ fopen("/dev/hidg0", "ab+"), [](FILE *f){
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -61,6 +61,32 @@ shared_ptr<FILE> getStream()
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shared_ptr<FILE> getComHostStream()
|
||||||
|
{
|
||||||
|
static shared_ptr<FILE> stream{ fopen("comhost.txt", "wb"), [](FILE *f){
|
||||||
|
clog << "Closing comhost stream" << endl;
|
||||||
|
fclose(f);
|
||||||
|
} };
|
||||||
|
|
||||||
|
if (!stream)
|
||||||
|
clog << "Stream is unavailable" << endl;
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<FILE> getComDevStream()
|
||||||
|
{
|
||||||
|
static shared_ptr<FILE> stream{ fopen("comdev.txt", "wb"), [](FILE *f){
|
||||||
|
clog << "Closing comdev stream" << endl;
|
||||||
|
fclose(f);
|
||||||
|
} };
|
||||||
|
|
||||||
|
if (!stream)
|
||||||
|
clog << "Stream is unavailable" << endl;
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
vector<uint8_t> readBytes(const size_t count)
|
vector<uint8_t> readBytes(const size_t count)
|
||||||
{
|
{
|
||||||
vector<uint8_t> bytes(count);
|
vector<uint8_t> bytes(count);
|
||||||
@@ -69,7 +95,8 @@ vector<uint8_t> readBytes(const size_t count)
|
|||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
readByteCount = fread(bytes.data(), 1, count, getStream().get());
|
readByteCount = fread(bytes.data(), 1, count, getHostStream().get());
|
||||||
|
fwrite(bytes.data(), 1, bytes.size(), getComHostStream().get());
|
||||||
} while (readByteCount == 0);
|
} while (readByteCount == 0);
|
||||||
|
|
||||||
clog << "Read " << readByteCount << " bytes" << endl;
|
clog << "Read " << readByteCount << " bytes" << endl;
|
||||||
@@ -87,10 +114,6 @@ shared_ptr<InitPacket> InitPacket::getPacket(const uint32_t rCID, const uint8_t
|
|||||||
p->cmd = rCMD;
|
p->cmd = rCMD;
|
||||||
p->bcnth = readBytes(1)[0];
|
p->bcnth = readBytes(1)[0];
|
||||||
p->bcntl = readBytes(1)[0];
|
p->bcntl = readBytes(1)[0];
|
||||||
/*uint16_t pLen = p->bcnth;
|
|
||||||
p->bcnth <<= 8;
|
|
||||||
p->bcnth += p->bcntl;
|
|
||||||
*/
|
|
||||||
|
|
||||||
const auto dataBytes = readBytes(p->data.size());
|
const auto dataBytes = readBytes(p->data.size());
|
||||||
copy(dataBytes.begin(), dataBytes.end(), p->data.data());
|
copy(dataBytes.begin(), dataBytes.end(), p->data.data());
|
||||||
@@ -133,34 +156,46 @@ shared_ptr<Packet> Packet::getPacket()
|
|||||||
|
|
||||||
void Packet::writePacket()
|
void Packet::writePacket()
|
||||||
{
|
{
|
||||||
//auto stream = getStream().get();
|
const uint8_t reportID = FIDO_USAGE_DATA_OUT;
|
||||||
auto stream = stdout;
|
auto hostStream = getHostStream().get();
|
||||||
fwrite(&cid, 4, 1, stream);
|
auto devStream = getComDevStream().get();
|
||||||
|
|
||||||
|
fwrite(&reportID, 1, 1, hostStream);
|
||||||
|
fwrite(&cid, 4, 1, hostStream);
|
||||||
|
fwrite(&cid, 4, 1, devStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InitPacket::writePacket()
|
void InitPacket::writePacket()
|
||||||
{
|
{
|
||||||
Packet::writePacket();
|
Packet::writePacket();
|
||||||
//auto stream = getStream().get();
|
auto hostStream = getHostStream().get();
|
||||||
auto stream = stdout;
|
auto devStream = getComDevStream().get();
|
||||||
|
|
||||||
fwrite(&cmd, 1, 1, stream);
|
fwrite(&cmd, 1, 1, hostStream);
|
||||||
fwrite(&bcnth, 1, 1, stream);
|
fwrite(&bcnth, 1, 1, hostStream);
|
||||||
fwrite(&bcntl, 1, 1, stream);
|
fwrite(&bcntl, 1, 1, hostStream);
|
||||||
fwrite(data.data(), data.size(), 1, stream);
|
fwrite(data.data(), 1, data.size(), hostStream);
|
||||||
|
fwrite(&cmd, 1, 1, devStream);
|
||||||
|
fwrite(&bcnth, 1, 1, devStream);
|
||||||
|
fwrite(&bcntl, 1, 1, devStream);
|
||||||
|
fwrite(data.data(), 1, data.size(), devStream);
|
||||||
|
|
||||||
|
perror(nullptr);
|
||||||
clog << "Fully wrote init packet" << endl;
|
clog << "Fully wrote init packet" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContPacket::writePacket()
|
void ContPacket::writePacket()
|
||||||
{
|
{
|
||||||
Packet::writePacket();
|
Packet::writePacket();
|
||||||
//auto stream = getStream().get();
|
auto hostStream = getHostStream().get();
|
||||||
auto stream = stdout;
|
auto devStream = getComDevStream().get();
|
||||||
|
|
||||||
fwrite(&seq, 1, 1, stream);
|
fwrite(&seq, 1, 1, hostStream);
|
||||||
fwrite(data.data(), data.size(), 1, stream);
|
fwrite(data.data(), 1, data.size(), hostStream);
|
||||||
|
fwrite(&seq, 1, 1, devStream);
|
||||||
|
fwrite(data.data(), 1, data.size(), devStream);
|
||||||
|
|
||||||
|
perror(nullptr);
|
||||||
clog << "Fully wrote cont packet" << endl;
|
clog << "Fully wrote cont packet" << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,6 +244,7 @@ struct U2FMessage
|
|||||||
|
|
||||||
void write()
|
void write()
|
||||||
{
|
{
|
||||||
|
fflush(getHostStream().get());
|
||||||
const uint16_t bytesToWrite = this->data.size();
|
const uint16_t bytesToWrite = this->data.size();
|
||||||
uint16_t bytesWritten = 0;
|
uint16_t bytesWritten = 0;
|
||||||
|
|
||||||
@@ -244,7 +280,7 @@ struct U2FMessage
|
|||||||
seq++;
|
seq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto stream = getStream().get();
|
auto stream = getHostStream().get();
|
||||||
fflush(stream);
|
fflush(stream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -325,8 +361,8 @@ int main()
|
|||||||
|
|
||||||
resp.write();
|
resp.write();
|
||||||
|
|
||||||
U2FMessage m = m.read();
|
/*U2FMessage m = m.read();
|
||||||
|
|
||||||
for (const auto d : m.data)
|
for (const auto d : m.data)
|
||||||
clog << static_cast<uint16_t>(d) << endl;
|
clog << static_cast<uint16_t>(d) << endl;*/
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user