Skip to content

Commit

Permalink
Add pinpad activate function
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Jan 12, 2024
1 parent 2185446 commit 3f49776
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ void Set_CSW (uint8_t CSW_Status, uint8_t Send_Permission);

void io_usb_ccid_set_card_inserted(unsigned int inserted);

void io_usb_ccid_configure_pinpad(uint8_t enabled);

#endif // HAVE_USB_CLASS_CCID

#endif /* __USBD_CCID_IF_H */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,11 +615,10 @@ void io_usb_ccid_set_card_inserted(unsigned int inserted) {
#endif // HAVE_CCID_INTERRUPT
}






void io_usb_ccid_configure_pinpad(uint8_t enabled) {
const volatile uint8_t *cfgDesc = USBD_GetPinPadOffset();
nvm_write((void *)cfgDesc, &enabled, 1);
}

#endif // HAVE_USB_CLASS_CCID

Expand Down
1 change: 1 addition & 0 deletions lib_stusb/usbd_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ typedef unsigned short uint16_t;
void *USBD_static_malloc(uint32_t size);
void USBD_static_free(void *p);

const volatile uint8_t *USBD_GetPinPadOffset(void);

void USB_power(unsigned char enabled);

Expand Down
56 changes: 51 additions & 5 deletions lib_stusb_impl/usbd_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,21 +353,34 @@ static uint8_t const HID_ReportDesc_fido[] = {

#define ARRAY_U2LE(l) (l)&0xFF, (l)>>8

#define CFG_HDR_LEN (0x9)
#define CFG_HIDGEN_LEN (0x9+0x9+0x7+0x7)
#define CFG_IO_U2F_LEN (0x9+0x9+0x7+0x7)
#define CFG_USB_CCID_LEN (0x9+0x36+0x7+0x7)
#define CFG_WEBUSB_LEN (0x9+0x7+0x7)

/* USB HID device Configuration Descriptor */
#ifdef HAVE_USB_CLASS_CCID
// Note: keeping const qualifier to ensure the good section is used by the linker.
// This table is mapped in NVRAM section and therefore it is correctly initialized,
// normal Read is possible and Write can be done through nvm_write() calls.
static __ALIGN_BEGIN uint8_t const N_USBD_CfgDesc[] __ALIGN_END =
#else
static __ALIGN_BEGIN uint8_t const USBD_CfgDesc[] __ALIGN_END =
#endif // HAVE_USB_CLASS_CCID
{
0x09, /* bLength: Configuration Descriptor size */
USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */
ARRAY_U2LE(0x9 /* wTotalLength: Bytes returned */
+0x9+0x9+0x7+0x7
ARRAY_U2LE(CFG_HDR_LEN /* wTotalLength: Bytes returned */
+CFG_HIDGEN_LEN
#ifdef HAVE_IO_U2F
+0x9+0x9+0x7+0x7
+CFG_IO_U2F_LEN
#endif // HAVE_IO_U2F
#ifdef HAVE_USB_CLASS_CCID
+0x9+0x36+0x7+0x7
+CFG_USB_CCID_LEN
#endif // HAVE_USB_CLASS_CCID
#ifdef HAVE_WEBUSB
+0x9+0x7+0x7
+CFG_WEBUSB_LEN
#endif // HAVE_WEBUSB
),
1
Expand Down Expand Up @@ -870,8 +883,13 @@ static uint8_t *USBD_GetDeviceQualifierDesc_impl(uint16_t *length)
*/
static uint8_t *USBD_GetCfgDesc_impl(uint16_t *length)
{
#ifdef HAVE_USB_CLASS_CCID
*length = sizeof(N_USBD_CfgDesc);
return (uint8_t *) N_USBD_CfgDesc;
#else
*length = sizeof(USBD_CfgDesc);
return (uint8_t *) USBD_CfgDesc;
#endif
}

uint8_t *USBD_HID_GetHidDescriptor_impl(uint16_t *len)
Expand Down Expand Up @@ -927,6 +945,34 @@ uint8_t *USBD_HID_GetReportDescriptor_impl(uint16_t *len)
return 0;
}

#ifdef HAVE_USB_CLASS_CCID
/**
* @brief Returns the pinpad value offset in the descriptor.
* @retval Offset
*/
const volatile uint8_t *USBD_GetPinPadOffset(void)
{
unsigned short length = 0;
uint8_t *cfgDesc = NULL;
unsigned short offset = 0;

cfgDesc = USBD_GetCfgDesc_impl(&length);

offset = CFG_HDR_LEN + CFG_HIDGEN_LEN;
#ifdef HAVE_IO_U2F
offset += CFG_IO_U2F_LEN;
#endif // HAVE_IO_U2F
// Offset of the parameter 'bPINSupport' inside the CCID interface structure in N_USBD_CfgDesc
offset += 61;

// Returns a const volatile pointer allowing callers to do
// - write operations through nvram_write
// - read operation without potential compilation optimization issue thanks to the volatile
// qualifier.
return (const volatile uint8_t *) (cfgDesc + offset);
}
#endif // HAVE_USB_CLASS_CCID

/**
* @}
*/
Expand Down

0 comments on commit 3f49776

Please sign in to comment.