fwupd/plugins/nitrokey/fu-nitrokey-common.h
Szczepan Zalega f80bb89238 nitrokey: Correct Nitrokey Storage invalid firmware version read
Currently used structures were based on early libnitrokey definitions
(which were broken for some time). Corrected their sizes and elements,
and added tests.

Fixes #960

Signed-off-by: Richard Hughes <richard@hughsie.com>
2019-01-25 09:53:05 +00:00

70 lines
1.7 KiB
C

/*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#ifndef __FU_NITROKEY_COMMON_H
#define __FU_NITROKEY_COMMON_H
#include <glib.h>
G_BEGIN_DECLS
guint32 fu_nitrokey_perform_crc32 (const guint8 *data,
gsize size);
#define NITROKEY_TRANSACTION_TIMEOUT 100 /* ms */
#define NITROKEY_NR_RETRIES 5
#define NITROKEY_REQUEST_DATA_LENGTH 59
#define NITROKEY_REPLY_DATA_LENGTH 53
#define NITROKEY_CMD_GET_DEVICE_STATUS (0x20 + 14)
typedef struct __attribute__((packed)) {
guint8 command;
guint8 payload[NITROKEY_REQUEST_DATA_LENGTH];
guint32 crc;
} NitrokeyHidRequest;
typedef struct __attribute__((packed)) {
guint8 device_status;
guint8 command_id;
guint32 last_command_crc;
guint8 last_command_status;
guint8 payload[NITROKEY_REPLY_DATA_LENGTH];
guint32 crc;
} NitrokeyHidResponse;
/* based from libnitrokey/stick20_commands.h from libnitrokey v3.4.1 */
typedef struct __attribute__((packed)) {
guint8 _padding[18]; /* stick20_commands.h:132 // 26 - 8 = 18 */
guint8 SendCounter;
guint8 SendDataType;
guint8 FollowBytesFlag;
guint8 SendSize;
guint16 MagicNumber_StickConfig;
guint8 ReadWriteFlagUncryptedVolume;
guint8 ReadWriteFlagCryptedVolume;
guint8 VersionMajor;
guint8 VersionMinor;
guint8 VersionReservedByte;
guint8 VersionBuildIteration;
guint8 ReadWriteFlagHiddenVolume;
guint8 FirmwareLocked;
guint8 NewSDCardFound;
guint8 SDFillWithRandomChars;
guint32 ActiveSD_CardID;
guint8 VolumeActiceFlag;
guint8 NewSmartCardFound;
guint8 UserPwRetryCount;
guint8 AdminPwRetryCount;
guint32 ActiveSmartCardID;
guint8 StickKeysNotInitiated;
} NitrokeyGetDeviceStatusPayload;
G_END_DECLS
#endif /* __FU_NITROKEY_COMMON_H */