github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/soc/imx6/usb/descriptor_ccid.go (about) 1 // CCID descriptor support 2 // https://github.com/f-secure-foundry/tamago 3 // 4 // Copyright (c) F-Secure Corporation 5 // https://foundry.f-secure.com 6 // 7 // Use of this source code is governed by the license 8 // that can be found in the LICENSE file. 9 10 package usb 11 12 import ( 13 "bytes" 14 "encoding/binary" 15 ) 16 17 // CCID descriptor constants 18 const ( 19 // p17, Table 5.1-1, CCID Rev1.1 20 CCID_INTERFACE = 0x21 21 CCID_DESCRIPTOR_LENGTH = 54 22 ) 23 24 // CCIDDescriptor implements p17, Table 5.1-1, CCID Rev1.1 25 type CCIDDescriptor struct { 26 Length uint8 27 DescriptorType uint8 28 CCID uint16 29 MaxSlotIndex uint8 30 VoltageSupport uint8 31 Protocols uint32 32 DefaultClock uint32 33 MaximumClock uint32 34 NumClockSupported uint8 35 DataRate uint32 36 MaxDataRate uint32 37 NumDataRatesSupported uint8 38 MaxIFSD uint32 39 SynchProtocols uint32 40 Mechanical uint32 41 Features uint32 42 MaxCCIDMessageLength uint32 43 ClassGetResponse uint8 44 ClassEnvelope uint8 45 LcdLayout uint16 46 PINSupport uint8 47 MaxCCIDBusySlots uint8 48 } 49 50 // SetDefaults initializes default values for the USB Smart Card Device Class 51 // Descriptor. 52 func (d *CCIDDescriptor) SetDefaults() { 53 d.Length = CCID_DESCRIPTOR_LENGTH 54 d.DescriptorType = CCID_INTERFACE 55 d.CCID = 0x0110 56 // all voltages 57 d.VoltageSupport = 0x7 58 // T=1 59 d.Protocols = 0x2 60 d.DefaultClock = 0x4000 61 d.MaximumClock = 0x4000 62 d.DataRate = 0x4b000 63 d.MaxDataRate = 0x4b000 64 d.MaxIFSD = 0xfe 65 // Features: 66 // Auto configuration based on ATR 67 // Auto activation on insert 68 // Auto voltage selection 69 // Auto clock change 70 // Auto baud rate change 71 // Auto parameter negotiation made by CCID 72 // Short and extended APDU level exchange 73 d.Features = 0x400fe 74 d.MaxCCIDMessageLength = DTD_PAGES * DTD_PAGE_SIZE 75 // echo 76 d.ClassGetResponse = 0xff 77 d.ClassEnvelope = 0xff 78 d.MaxCCIDBusySlots = 1 79 } 80 81 // Bytes converts the descriptor structure to byte array format. 82 func (d *CCIDDescriptor) Bytes() []byte { 83 buf := new(bytes.Buffer) 84 binary.Write(buf, binary.LittleEndian, d) 85 return buf.Bytes() 86 }