Merge "usb: gadget: Add snapshot of CCID function driver"

This commit is contained in:
qctecmdr Service 2018-09-03 07:57:02 -07:00 committed by Gerrit - the friendly Code Review server
commit 31e3957fc4
5 changed files with 1436 additions and 0 deletions

View file

@ -223,6 +223,9 @@ config USB_F_DIAG
config USB_F_CDEV
tristate
config USB_F_CCID
tristate
# this first set of drivers all depend on bulk-capable hardware.
config USB_CONFIGFS
@ -512,6 +515,18 @@ config USB_CONFIGFS_F_CDEV
asynchronous notification to the host. This driver is typically
used to support DUN/NMEA functions.
config USB_CONFIGFS_F_CCID
bool "USB CCID function"
select USB_F_CCID
depends on USB_CONFIGFS
help
The Chip Card Interface Device (CCID) function implements a USB
interface that exposes a standard CSCID class that consists of a
pair of bulk IN and OUT endpoints and a single interrupt IN
endpoint. This driver provides a character device interface
allowing a userspace component to be able to provide the
implementation necessary to interface with the smartcard.
choice
tristate "USB Gadget precomposed configurations"
default USB_ETH

View file

@ -54,3 +54,5 @@ usb_f_diag-y := f_diag.o
obj-$(CONFIG_USB_F_DIAG) += usb_f_diag.o
usb_f_cdev-y := f_cdev.o
obj-$(CONFIG_USB_F_CDEV) += usb_f_cdev.o
usb_f_ccid-y := f_ccid.o
obj-$(CONFIG_USB_F_CCID) += usb_f_ccid.o

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,75 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved.
*/
#ifndef __F_CCID_H
#define __F_CCID_H
#define PROTOCOL_TO 0x01
#define PROTOCOL_T1 0x02
#define ABDATA_SIZE 512
/* define for dwFeatures for Smart Card Device Class Descriptors */
/* No special characteristics */
#define CCID_FEATURES_NADA 0x00000000
/* Automatic parameter configuration based on ATR data */
#define CCID_FEATURES_AUTO_PCONF 0x00000002
/* Automatic activation of ICC on inserting */
#define CCID_FEATURES_AUTO_ACTIV 0x00000004
/* Automatic ICC voltage selection */
#define CCID_FEATURES_AUTO_VOLT 0x00000008
/* Automatic ICC clock frequency change */
#define CCID_FEATURES_AUTO_CLOCK 0x00000010
/* Automatic baud rate change */
#define CCID_FEATURES_AUTO_BAUD 0x00000020
/*Automatic parameters negotiation made by the CCID */
#define CCID_FEATURES_AUTO_PNEGO 0x00000040
/* Automatic PPS made by the CCID according to the active parameters */
#define CCID_FEATURES_AUTO_PPS 0x00000080
/* CCID can set ICC in clock stop mode */
#define CCID_FEATURES_ICCSTOP 0x00000100
/* NAD value other than 00 accepted (T=1 protocol in use) */
#define CCID_FEATURES_NAD 0x00000200
/* Automatic IFSD exchange as first exchange (T=1 protocol in use) */
#define CCID_FEATURES_AUTO_IFSD 0x00000400
/* TPDU level exchanges with CCID */
#define CCID_FEATURES_EXC_TPDU 0x00010000
/* Short APDU level exchange with CCID */
#define CCID_FEATURES_EXC_SAPDU 0x00020000
/* Short and Extended APDU level exchange with CCID */
#define CCID_FEATURES_EXC_APDU 0x00040000
/* USB Wake up signaling supported on card insertion and removal */
#define CCID_FEATURES_WAKEUP 0x00100000
#define CCID_NOTIFY_CARD _IOW('C', 1, struct usb_ccid_notification)
#define CCID_NOTIFY_HWERROR _IOW('C', 2, struct usb_ccid_notification)
#define CCID_READ_DTR _IOR('C', 3, int)
struct usb_ccid_notification {
__u8 buf[4];
} __packed;
struct ccid_bulk_in_header {
__u8 bMessageType;
__u32 wLength;
__u8 bSlot;
__u8 bSeq;
__u8 bStatus;
__u8 bError;
__u8 bSpecific;
__u8 abData[ABDATA_SIZE];
__u8 bSizeToSend;
} __packed;
struct ccid_bulk_out_header {
__u8 bMessageType;
__u32 wLength;
__u8 bSlot;
__u8 bSeq;
__u8 bSpecific_0;
__u8 bSpecific_1;
__u8 bSpecific_2;
__u8 APDU[ABDATA_SIZE];
} __packed;
#endif

View file

@ -0,0 +1,104 @@
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved.
*/
#ifndef __LINUX_USB_CCID_DESC_H
#define __LINUX_USB_CCID_DESC_H
/*CCID specification version 1.10*/
#define CCID1_10 0x0110
#define SMART_CARD_DEVICE_CLASS 0x0B
/* Smart Card Device Class Descriptor Type */
#define CCID_DECRIPTOR_TYPE 0x21
/* Table 5.3-1 Summary of CCID Class Specific Request */
#define CCIDGENERICREQ_ABORT 0x01
#define CCIDGENERICREQ_GET_CLOCK_FREQUENCIES 0x02
#define CCIDGENERICREQ_GET_DATA_RATES 0x03
/* 6.1 Command Pipe, Bulk-OUT Messages */
#define PC_TO_RDR_ICCPOWERON 0x62
#define PC_TO_RDR_ICCPOWEROFF 0x63
#define PC_TO_RDR_GETSLOTSTATUS 0x65
#define PC_TO_RDR_XFRBLOCK 0x6F
#define PC_TO_RDR_GETPARAMETERS 0x6C
#define PC_TO_RDR_RESETPARAMETERS 0x6D
#define PC_TO_RDR_SETPARAMETERS 0x61
#define PC_TO_RDR_ESCAPE 0x6B
#define PC_TO_RDR_ICCCLOCK 0x6E
#define PC_TO_RDR_T0APDU 0x6A
#define PC_TO_RDR_SECURE 0x69
#define PC_TO_RDR_MECHANICAL 0x71
#define PC_TO_RDR_ABORT 0x72
#define PC_TO_RDR_SETDATARATEANDCLOCKFREQUENCY 0x73
/* 6.2 Response Pipe, Bulk-IN Messages */
#define RDR_TO_PC_DATABLOCK 0x80
#define RDR_TO_PC_SLOTSTATUS 0x81
#define RDR_TO_PC_PARAMETERS 0x82
#define RDR_TO_PC_ESCAPE 0x83
#define RDR_TO_PC_DATARATEANDCLOCKFREQUENCY 0x84
/* 6.3 Interrupt-IN Messages */
#define RDR_TO_PC_NOTIFYSLOTCHANGE 0x50
#define RDR_TO_PC_HARDWAREERROR 0x51
/* Table 6.2-2 Slot error register when bmCommandStatus = 1 */
#define CMD_ABORTED 0xFF
#define ICC_MUTE 0xFE
#define XFR_PARITY_ERROR 0xFD
#define XFR_OVERRUN 0xFC
#define HW_ERROR 0xFB
#define BAD_ATR_TS 0xF8
#define BAD_ATR_TCK 0xF7
#define ICC_PROTOCOL_NOT_SUPPORTED 0xF6
#define ICC_CLASS_NOT_SUPPORTED 0xF5
#define PROCEDURE_BYTE_CONFLICT 0xF4
#define DEACTIVATED_PROTOCOL 0xF3
#define BUSY_WITH_AUTO_SEQUENCE 0xF2
#define PIN_TIMEOUT 0xF0
#define PIN_CANCELLED 0xEF
#define CMD_SLOT_BUSY 0xE0
/* CCID rev 1.1, p.27 */
#define VOLTS_AUTO 0x00
#define VOLTS_5_0 0x01
#define VOLTS_3_0 0x02
#define VOLTS_1_8 0x03
/* 6.3.1 RDR_to_PC_NotifySlotChange */
#define ICC_NOT_PRESENT 0x00
#define ICC_PRESENT 0x01
#define ICC_CHANGE 0x02
#define ICC_INSERTED_EVENT (ICC_PRESENT+ICC_CHANGE)
/* Identifies the length of type of subordinate descriptors of a CCID device
* Table 5.1-1 Smart Card Device Class descriptors
*/
struct usb_ccid_class_descriptor {
__u8 bLength;
__u8 bDescriptorType;
__u16 bcdCCID;
__u8 bMaxSlotIndex;
__u8 bVoltageSupport;
__u32 dwProtocols;
__u32 dwDefaultClock;
__u32 dwMaximumClock;
__u8 bNumClockSupported;
__u32 dwDataRate;
__u32 dwMaxDataRate;
__u8 bNumDataRatesSupported;
__u32 dwMaxIFSD;
__u32 dwSynchProtocols;
__u32 dwMechanical;
__u32 dwFeatures;
__u32 dwMaxCCIDMessageLength;
__u8 bClassGetResponse;
__u8 bClassEnvelope;
__u16 wLcdLayout;
__u8 bPINSupport;
__u8 bMaxCCIDBusySlots;
} __packed;
#endif