Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d5de1787 authored by Hemant Kumar's avatar Hemant Kumar Committed by Jack Pham
Browse files

usb: gadget: Add snapshot of CCID function driver



This snapshot is taken as of msm-3.18 commit:
bf10764e3d1 (Merge "ARM: dts: msm: Update APC MEM ACC settings for
msm8920")

This USB CCID function driver will be a transport layer between
the userspace CCID component and the Windows Host. Data and control
commands from the Windows Host will be sent to the userspace
component and vice-versa.

Change-Id: Ie5eeda1550ac30cac47fd3799021598eac550652
Signed-off-by: default avatarHemant Kumar <hemantk@codeaurora.org>
[jackp@codeaurora.org: fixed checkpatch warnings]
Signed-off-by: default avatarJack Pham <jackp@codeaurora.org>
parent 89b9003c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -227,6 +227,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
@@ -528,6 +531,14 @@ config USB_CONFIGFS_F_CDEV
	help
	  Generic USB serial character function driver to support DUN/NMEA.

config USB_CONFIGFS_F_CCID
	bool "USB CCID function"
	select USB_F_CCID
	depends on USB_CONFIGFS
	help
	  USB CCID function driver creates transport layer between the
	  userspace CCID component and the Windows Host.

choice
	tristate "USB Gadget Drivers"
	default USB_ETH
+2 −0
Original line number Diff line number Diff line
@@ -58,3 +58,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
+999 −0

File added.

Preview size limit exceeded, changes collapsed.

+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved.

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details
 */

#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 {
	unsigned char buf[4];
} __packed;

struct ccid_bulk_in_header {
	unsigned char bMessageType;
	unsigned long wLength;
	unsigned char bSlot;
	unsigned char bSeq;
	unsigned char bStatus;
	unsigned char bError;
	unsigned char bSpecific;
	unsigned char abData[ABDATA_SIZE];
	unsigned char bSizeToSend;
} __packed;

struct ccid_bulk_out_header {
	unsigned char bMessageType;
	unsigned long wLength;
	unsigned char bSlot;
	unsigned char bSeq;
	unsigned char bSpecific_0;
	unsigned char bSpecific_1;
	unsigned char bSpecific_2;
	unsigned char APDU[ABDATA_SIZE];
} __packed;
#endif
+112 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2011, 2017 The Linux Foundation. All rights reserved.

 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details
 */

#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 {
	unsigned char  bLength;
	unsigned char  bDescriptorType;
	unsigned short bcdCCID;
	unsigned char  bMaxSlotIndex;
	unsigned char  bVoltageSupport;
	unsigned long  dwProtocols;
	unsigned long  dwDefaultClock;
	unsigned long  dwMaximumClock;
	unsigned char  bNumClockSupported;
	unsigned long  dwDataRate;
	unsigned long  dwMaxDataRate;
	unsigned char  bNumDataRatesSupported;
	unsigned long  dwMaxIFSD;
	unsigned long  dwSynchProtocols;
	unsigned long  dwMechanical;
	unsigned long  dwFeatures;
	unsigned long  dwMaxCCIDMessageLength;
	unsigned char  bClassGetResponse;
	unsigned char  bClassEnvelope;
	unsigned short wLcdLayout;
	unsigned char  bPINSupport;
	unsigned char  bMaxCCIDBusySlots;
} __packed;
#endif