diff options
author | Mateusz Zalega <mateusz@appliedsourcery.com> | 2015-10-22 23:07:23 +0200 |
---|---|---|
committer | Mateusz Zalega <mateusz@appliedsourcery.com> | 2015-10-26 20:49:55 +0100 |
commit | 9b8ebc6ed1a1fdc15c404774bf102c883a34d990 (patch) | |
tree | fce9205359704dcce84a1f770878901fbc9c2b3e /include/dissect.h | |
parent | c4aec144256e3f27fedd8f8de03e10cc08eecab8 (diff) | |
download | libnitrokey-9b8ebc6ed1a1fdc15c404774bf102c883a34d990.tar.gz libnitrokey-9b8ebc6ed1a1fdc15c404774bf102c883a34d990.tar.bz2 |
Minor fixes, working version
Diffstat (limited to 'include/dissect.h')
-rw-r--r-- | include/dissect.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/include/dissect.h b/include/dissect.h new file mode 100644 index 0000000..db3186b --- /dev/null +++ b/include/dissect.h @@ -0,0 +1,60 @@ +/* + * Protocol packet dissection + */ +#ifndef DISSECT_H +#define DISSECT_H +#include <string> +#include <sstream> +#include "misc.h" +#include "cxx_semantics.h" +#include "command_id.h" +#include "device_proto.h" + +namespace nitrokey { +namespace proto { + +template <CommandID id, class HIDPacket> +class QueryDissector : semantics::non_constructible { +public: + static std::string dissect(const HIDPacket &pod) { + std::stringstream out; + + out << "Raw HID packet:" << std::endl; + out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + + out << "Contents:" << std::endl; + out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) << std::endl; + out << "CRC:\t" << pod.crc << std::endl; + + out << "Payload:" << std::endl; + out << pod.payload.dissect(); + return out.str(); + } +}; + +template <CommandID id, class HIDPacket> +class ResponseDissector : semantics::non_constructible { +public: + static std::string dissect(const HIDPacket &pod) { + std::stringstream out; + + out << "Raw HID packet:" << std::endl; + out << ::nitrokey::misc::hexdump((const char *)(&pod), sizeof pod); + + out << "Device status:\t" << pod.device_status << std::endl; + out << "Command ID:\t" << commandid_to_string((CommandID)(pod.command_id)) << std::endl; + out << "Last command CRC:\t" << pod.last_command_crc << std::endl; + out << "Last command status:\t" << pod.last_command_status << std::endl; + out << "CRC:\t" << pod.crc << std::endl; + + out << "Payload:" << std::endl; + out << pod.payload.dissect(); + return out.str(); + } +}; + + +} +} + +#endif |