summaryrefslogtreecommitdiff
path: root/include/device_proto.h
diff options
context:
space:
mode:
authorSzczepan Zalega <szczepan@nitrokey.com>2016-10-31 19:03:30 +0100
committerSzczepan Zalega <szczepan@nitrokey.com>2016-11-26 18:56:27 +0100
commitc346ff180244de682e78f49783eab9b296c79de6 (patch)
treee4375ac47275e7181d9a3fc1ba111e3c2ec25601 /include/device_proto.h
parentca130e790ecc4e4502eb39e1ab550348eae9bc54 (diff)
downloadlibnitrokey-c346ff180244de682e78f49783eab9b296c79de6.tar.gz
libnitrokey-c346ff180244de682e78f49783eab9b296c79de6.tar.bz2
Code refactoring - named magic numbers (2)
Signed-off-by: Szczepan Zalega <szczepan@nitrokey.com>
Diffstat (limited to 'include/device_proto.h')
-rw-r--r--include/device_proto.h19
1 files changed, 13 insertions, 6 deletions
diff --git a/include/device_proto.h b/include/device_proto.h
index 6bcbcb0..187d25c 100644
--- a/include/device_proto.h
+++ b/include/device_proto.h
@@ -90,12 +90,19 @@ namespace nitrokey {
* command_id member in incoming HIDReport structure carries the command
* type last used.
*/
- template<CommandID cmd_id, typename ResponsePayload>
- struct DeviceResponse {
- static constexpr auto storage_status_absolute_address = 21; //magic number from firmware
+ namespace DeviceResponseConstants{
+ //magic numbers from firmware
+ static constexpr auto storage_status_absolute_address = 21;
+ static constexpr auto storage_data_absolute_address = storage_status_absolute_address + 5;
static constexpr auto header_size = 8; //from _zero to last_command_status inclusive
static constexpr auto footer_size = 4; //crc
- static constexpr auto boiler_size = header_size + footer_size;
+ static constexpr auto wrapping_size = header_size + footer_size;
+ }
+
+ template<CommandID cmd_id, typename ResponsePayload>
+ struct DeviceResponse {
+ static constexpr auto storage_status_padding_size =
+ DeviceResponseConstants::storage_status_absolute_address - DeviceResponseConstants::header_size;
uint8_t _zero;
uint8_t device_status;
@@ -104,10 +111,10 @@ namespace nitrokey {
uint8_t last_command_status;
union {
- uint8_t _padding[HID_REPORT_SIZE - boiler_size];
+ uint8_t _padding[HID_REPORT_SIZE - DeviceResponseConstants::wrapping_size];
ResponsePayload payload;
struct {
- uint8_t _storage_status_padding[storage_status_absolute_address - header_size];
+ uint8_t _storage_status_padding[storage_status_padding_size];
uint8_t command_counter;
uint8_t command_id;
uint8_t device_status; //@see stick20::device_status