github.com/usbarmory/tamago@v0.0.0-20240508072735-8612bbe1e454/soc/nxp/usb/descriptor_ccid.go (about) 1 // CCID descriptor support 2 // https://github.com/usbarmory/tamago 3 // 4 // Copyright (c) WithSecure Corporation 5 // https://foundry.withsecure.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 // p16, Table 4.3-1, CCID Rev1.1 20 SMARTCARD_DEVICE_CLASS = 0x0b 21 22 // p17, Table 5.1-1, CCID Rev1.1 23 CCID_INTERFACE = 0x21 24 CCID_DESCRIPTOR_LENGTH = 54 25 ) 26 27 // CCIDDescriptor implements p17, Table 5.1-1, CCID Rev1.1 28 type CCIDDescriptor struct { 29 Length uint8 30 DescriptorType uint8 31 CCID uint16 32 MaxSlotIndex uint8 33 VoltageSupport uint8 34 Protocols uint32 35 DefaultClock uint32 36 MaximumClock uint32 37 NumClockSupported uint8 38 DataRate uint32 39 MaxDataRate uint32 40 NumDataRatesSupported uint8 41 MaxIFSD uint32 42 SynchProtocols uint32 43 Mechanical uint32 44 Features uint32 45 MaxCCIDMessageLength uint32 46 ClassGetResponse uint8 47 ClassEnvelope uint8 48 LcdLayout uint16 49 PINSupport uint8 50 MaxCCIDBusySlots uint8 51 } 52 53 // SetDefaults initializes default values for the USB Smart Card Device Class 54 // Descriptor. 55 func (d *CCIDDescriptor) SetDefaults() { 56 d.Length = CCID_DESCRIPTOR_LENGTH 57 d.DescriptorType = CCID_INTERFACE 58 d.CCID = 0x0110 59 } 60 61 // Bytes converts the descriptor structure to byte array format. 62 func (d *CCIDDescriptor) Bytes() []byte { 63 buf := new(bytes.Buffer) 64 binary.Write(buf, binary.LittleEndian, d) 65 return buf.Bytes() 66 }