CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ccid.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>

Go to the source code of this file.

Macros

#define USB_CLASS_CCID   0x0B
#define CCID_USB_VID   0x08e6
#define CCID_USB_PID   0x4433
#define CCID_PC_TO_RDR_ICC_POWER_ON   0x62
#define CCID_PC_TO_RDR_ICC_POWER_OFF   0x63
#define CCID_PC_TO_RDR_GET_SLOT_STATUS   0x65
#define CCID_PC_TO_RDR_XFR_BLOCK   0x6F
#define CCID_PC_TO_RDR_GET_PARAMETERS   0x6C
#define CCID_PC_TO_RDR_RESET_PARAMETERS   0x6D
#define CCID_PC_TO_RDR_SET_PARAMETERS   0x61
#define CCID_PC_TO_RDR_SECURE   0x69
#define CCID_RDR_TO_PC_DATA_BLOCK   0x80
#define CCID_RDR_TO_PC_SLOT_STATUS   0x81
#define CCID_RDR_TO_PC_PARAMETERS   0x82
#define CCID_ICC_PRESENT_ACTIVE   0x00
#define CCID_ICC_PRESENT_INACTIVE   0x01
#define CCID_ICC_NOT_PRESENT   0x02
#define CCID_CMD_STATUS_OK   0x00
#define CCID_CMD_STATUS_FAILED   0x40
#define CCID_CMD_STATUS_TIME_EXT   0x80
#define CCID_ERROR_CMD_ABORTED   0xFF
#define CCID_ERROR_ICC_MUTE   0xFE
#define CCID_ERROR_XFR_PARITY_ERROR   0xFD
#define CCID_ERROR_XFR_OVERRUN   0xFC
#define CCID_ERROR_HW_ERROR   0xFB
#define CCID_ERROR_CMD_NOT_SUPPORTED   0x00
#define CCID_MAX_MSG_SIZE   2048
#define CCID_HEADER_SIZE   10

Functions

struct __attribute__ ((packed))
bool ccid_init (void)
int ccid_process_message (const uint8_t *msg, size_t msg_len, uint8_t *resp, size_t resp_max)
 Processes one incoming CCID message and writes corresponding response.
const uint8_t * ccid_get_atr (size_t *len)
 Returns pointer and length of ATR bytes.
bool ccid_card_present (void)
 Returns whether virtual CCID card is available.

Variables

 ccid_header_t
const uint8_t CCID_DESCRIPTOR []
 CCID functional descriptor (54 bytes) per OpenPGP 3.4.1 profile.
const size_t CCID_DESCRIPTOR_LEN

Macro Definition Documentation

◆ CCID_CMD_STATUS_FAILED

#define CCID_CMD_STATUS_FAILED   0x40

Definition at line 49 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_CMD_STATUS_OK

#define CCID_CMD_STATUS_OK   0x00

Definition at line 48 of file ccid.h.

◆ CCID_CMD_STATUS_TIME_EXT

#define CCID_CMD_STATUS_TIME_EXT   0x80

Definition at line 50 of file ccid.h.

◆ CCID_ERROR_CMD_ABORTED

#define CCID_ERROR_CMD_ABORTED   0xFF

Definition at line 53 of file ccid.h.

◆ CCID_ERROR_CMD_NOT_SUPPORTED

#define CCID_ERROR_CMD_NOT_SUPPORTED   0x00

Definition at line 58 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_ERROR_HW_ERROR

#define CCID_ERROR_HW_ERROR   0xFB

Definition at line 57 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_ERROR_ICC_MUTE

#define CCID_ERROR_ICC_MUTE   0xFE

Definition at line 54 of file ccid.h.

◆ CCID_ERROR_XFR_OVERRUN

#define CCID_ERROR_XFR_OVERRUN   0xFC

Definition at line 56 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_ERROR_XFR_PARITY_ERROR

#define CCID_ERROR_XFR_PARITY_ERROR   0xFD

Definition at line 55 of file ccid.h.

◆ CCID_HEADER_SIZE

#define CCID_HEADER_SIZE   10

Definition at line 62 of file ccid.h.

Referenced by ccid_driver_xfer_cb(), and ccid_process_message().

◆ CCID_ICC_NOT_PRESENT

#define CCID_ICC_NOT_PRESENT   0x02

Definition at line 45 of file ccid.h.

◆ CCID_ICC_PRESENT_ACTIVE

#define CCID_ICC_PRESENT_ACTIVE   0x00

Definition at line 43 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_ICC_PRESENT_INACTIVE

#define CCID_ICC_PRESENT_INACTIVE   0x01

Definition at line 44 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_MAX_MSG_SIZE

#define CCID_MAX_MSG_SIZE   2048

Definition at line 61 of file ccid.h.

◆ CCID_PC_TO_RDR_GET_PARAMETERS

#define CCID_PC_TO_RDR_GET_PARAMETERS   0x6C

Definition at line 32 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_PC_TO_RDR_GET_SLOT_STATUS

#define CCID_PC_TO_RDR_GET_SLOT_STATUS   0x65

Definition at line 30 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_PC_TO_RDR_ICC_POWER_OFF

#define CCID_PC_TO_RDR_ICC_POWER_OFF   0x63

Definition at line 29 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_PC_TO_RDR_ICC_POWER_ON

#define CCID_PC_TO_RDR_ICC_POWER_ON   0x62

Definition at line 28 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_PC_TO_RDR_RESET_PARAMETERS

#define CCID_PC_TO_RDR_RESET_PARAMETERS   0x6D

Definition at line 33 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_PC_TO_RDR_SECURE

#define CCID_PC_TO_RDR_SECURE   0x69

Definition at line 35 of file ccid.h.

◆ CCID_PC_TO_RDR_SET_PARAMETERS

#define CCID_PC_TO_RDR_SET_PARAMETERS   0x61

Definition at line 34 of file ccid.h.

◆ CCID_PC_TO_RDR_XFR_BLOCK

#define CCID_PC_TO_RDR_XFR_BLOCK   0x6F

Definition at line 31 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_RDR_TO_PC_DATA_BLOCK

#define CCID_RDR_TO_PC_DATA_BLOCK   0x80

Definition at line 38 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_RDR_TO_PC_PARAMETERS

#define CCID_RDR_TO_PC_PARAMETERS   0x82

Definition at line 40 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_RDR_TO_PC_SLOT_STATUS

#define CCID_RDR_TO_PC_SLOT_STATUS   0x81

Definition at line 39 of file ccid.h.

Referenced by ccid_process_message().

◆ CCID_USB_PID

#define CCID_USB_PID   0x4433

Definition at line 25 of file ccid.h.

◆ CCID_USB_VID

#define CCID_USB_VID   0x08e6

Definition at line 24 of file ccid.h.

◆ USB_CLASS_CCID

#define USB_CLASS_CCID   0x0B

Definition at line 21 of file ccid.h.

Function Documentation

◆ __attribute__()

struct __attribute__ ( (packed) )

Definition at line 1 of file ccid.h.

◆ ccid_card_present()

bool ccid_card_present ( void )

Returns whether virtual CCID card is available.

Returns
true if CCID/OpenPGP stack is initialized.

Definition at line 112 of file ccid.cpp.

References initialized.

◆ ccid_get_atr()

const uint8_t * ccid_get_atr ( size_t * len)

Returns pointer and length of ATR bytes.

Parameters
lenOptional output receiving ATR length.
Returns
Pointer to static ATR buffer.

Definition at line 101 of file ccid.cpp.

References ATR.

Referenced by ccid_process_message().

◆ ccid_init()

bool ccid_init ( void )

Definition at line 83 of file ccid.cpp.

References ccid_driver_link_anchor(), initialized, LOG_E, LOG_I, openpgp_init(), and TAG.

Referenced by cdc::mod_gpg::GpgModule::start().

◆ ccid_process_message()

int ccid_process_message ( const uint8_t * msg,
size_t msg_len,
uint8_t * resp,
size_t resp_max )

Processes one incoming CCID message and writes corresponding response.

Parameters
Message transfer (badge-to-badge)Incoming CCID message bytes.
msg_lenIncoming message length.
respOutput response buffer.
resp_maxOutput buffer capacity.
Returns
Response length in bytes, or negative value on fatal parameter errors.

Definition at line 148 of file ccid.cpp.

References ccid_build_header(), CCID_CMD_STATUS_FAILED, CCID_ERROR_CMD_NOT_SUPPORTED, CCID_ERROR_HW_ERROR, CCID_ERROR_XFR_OVERRUN, ccid_get_atr(), CCID_HEADER_SIZE, ccid_header_t, CCID_ICC_PRESENT_ACTIVE, CCID_ICC_PRESENT_INACTIVE, CCID_PC_TO_RDR_GET_PARAMETERS, CCID_PC_TO_RDR_GET_SLOT_STATUS, CCID_PC_TO_RDR_ICC_POWER_OFF, CCID_PC_TO_RDR_ICC_POWER_ON, CCID_PC_TO_RDR_RESET_PARAMETERS, CCID_PC_TO_RDR_XFR_BLOCK, CCID_RDR_TO_PC_DATA_BLOCK, CCID_RDR_TO_PC_PARAMETERS, CCID_RDR_TO_PC_SLOT_STATUS, current_seq, current_slot, LOG_E, LOG_I, LOG_W, openpgp_process_apdu(), and TAG.

Referenced by ccid_driver_xfer_cb().

Variable Documentation

◆ CCID_DESCRIPTOR

const uint8_t CCID_DESCRIPTOR[]
extern

CCID functional descriptor (54 bytes) per OpenPGP 3.4.1 profile.

Definition at line 20 of file ccid.cpp.

◆ CCID_DESCRIPTOR_LEN

const size_t CCID_DESCRIPTOR_LEN
extern

Definition at line 50 of file ccid.cpp.

◆ ccid_header_t

ccid_header_t

Definition at line 71 of file ccid.h.

Referenced by ccid_process_message().