Received: from [140.186.70.92] (port=59507 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PMe1S-00052T-30 for qemu-devel@nongnu.org; Sun, 28 Nov 2010 04:58:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PMe1P-0000KZ-Oe for qemu-devel@nongnu.org; Sun, 28 Nov 2010 04:58:17 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34503) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PMe1P-0000KV-7j for qemu-devel@nongnu.org; Sun, 28 Nov 2010 04:58:15 -0500 Date: Sun, 28 Nov 2010 11:58:06 +0200 From: Alon Levy Subject: Re: [Qemu-devel] [PATCH 1/6] usb-ccid: add CCID bus Message-ID: <20101128095806.GB6599@playa.tlv.redhat.com> References: <1290702170-3775-1-git-send-email-alevy@redhat.com> <1290702170-3775-2-git-send-email-alevy@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org On Fri, Nov 26, 2010 at 07:05:02PM +0000, Blue Swirl wrote: > On Thu, Nov 25, 2010 at 4:22 PM, Alon Levy wrote: ... > > +/* 6.2.6 RDR_to_PC_SlotStatus definitions */ > > +enum { > > + =A0 =A0CLOCK_STATUS_RUNNING =3D 0, > > + =A0 =A0/* 0 - Clock Running, 1 - Clock stopped in State L, 2 - H, > > + =A0 =A0 =A0 3 - unkonwn state. rest are RFU > > + =A0 =A0 */ > > +}; > > + > > +typedef struct __attribute__ ((__packed__)) { >=20 > Please don't use anonymous structs. >=20 ok, fixing for v8. > > + =A0 =A0uint8_t =A0 =A0 bMessageType; >=20 > Why aHungarian nNotation? It's not QEMU style. >=20 These names are taken directly from the spec (http://www.usb.org/develope= rs/devclass_docs/DWG_Smart-Card_CCID_Rev110.pdf). I did it to make search= ing in the spec easier for anyone reading the source. > > + =A0 =A0uint32_t =A0 =A0dwLength; > > + =A0 =A0uint8_t =A0 =A0 bSlot; > > + =A0 =A0uint8_t =A0 =A0 bSeq; > > +} CCID_Header; >=20 > Packed structure with unaligned fields. Will this work? >=20 Works for x86, same situation for the endianess issue. I'll change it to= unpacked and change the writing to the guest to explicitly copy individu= al structs (I'll have to do that for endianess anyway). Should the USB de= vice be little endian always? so I need to convert any field written to t= he guest to little endian, and read from the guest to host endianess? > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_Header hdr; > > + =A0 =A0uint8_t =A0 =A0 bStatus; =A0 =A0 =A0 =A0/* Only used in BULK= _IN */ > > + =A0 =A0uint8_t =A0 =A0 bError; =A0 =A0 =A0 =A0 /* Only used in BULK= _IN */ > > +} CCID_BULK_IN; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_BULK_IN b; > > + =A0 =A0uint8_t =A0 =A0 bClockStatus; > > +} CCID_SlotStatus; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_BULK_IN b; > > + =A0 =A0uint8_t =A0 =A0 bProtocolNum; > > + =A0 =A0uint8_t =A0 =A0 abProtocolDataStructure[0]; > > +} CCID_Parameter; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_BULK_IN b; > > + =A0 =A0uint8_t =A0 =A0 =A0bChainParameter; > > + =A0 =A0uint8_t =A0 =A0 =A0abData[0]; > > +} CCID_DataBlock; > > + > > +/* 6.1.4 PC_to_RDR_XfrBlock */ > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_Header =A0hdr; > > + =A0 =A0uint8_t =A0 =A0 =A0bBWI; /* Block Waiting Timeout */ > > + =A0 =A0uint16_t =A0 =A0 wLevelParameter; > > + =A0 =A0uint8_t =A0 =A0 =A0abData[0]; > > +} CCID_XferBlock; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_Header hdr; > > + =A0 =A0uint8_t =A0 =A0 bPowerSelect; > > + =A0 =A0uint16_t =A0 =A0abRFU; > > +} CCID_IccPowerOn; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_Header hdr; > > + =A0 =A0uint16_t =A0 =A0abRFU; > > +} CCID_IccPowerOff; > > + > > +typedef struct __attribute__ ((__packed__)) { > > + =A0 =A0CCID_Header hdr; > > + =A0 =A0uint8_t =A0 =A0 bProtocolNum; > > + =A0 =A0uint8_t =A0 =A0abProtocolDataStructure[0]; > > +} CCID_SetParameter; > > + > > +typedef struct { > > + =A0 =A0uint8_t =A0 =A0 bMessageType; /* CCID_MESSAGE_TYPE_RDR_to_PC= _NotifySlotChange */ > > + =A0 =A0uint8_t =A0 =A0 bmSlotICCState; > > +} CCID_Notify_Slot_Change; > > + > > +/* used for DataBlock response to XferBlock */ > > +typedef struct answer_t { > > + =A0 =A0uint8_t slot; > > + =A0 =A0uint8_t seq; > > +} answer_t; > > + >=20 > answer_t is not in line with CODING_STYLE. >=20 > > +/* pending BULK_IN messages */ > > +typedef struct bulk_in_t { > > + =A0 =A0uint8_t =A0data[BULK_IN_BUF_SIZE]; > > + =A0 =A0uint32_t len; > > + =A0 =A0uint32_t pos; > > +} bulk_in_t; >=20 > Neither is this. >=20 Fixing both for v8. > > + > > +enum { > > + =A0 =A0MIGRATION_NONE, > > + =A0 =A0MIGRATION_MIGRATED, > > +}; > > + > > +typedef struct CCIDBus CCIDBus; > > +typedef struct USBCCIDState USBCCIDState; > > + > > +#define MAX_PROTOCOL_SIZE =A0 7 > > + > > +/** > > + * powered - defaults to true, changed by PowerOn/PowerOff messages > > + */ > > +struct USBCCIDState { > > + =A0 =A0USBDevice dev; > > + =A0 =A0CCIDBus *bus; > > + =A0 =A0CCIDCardState *card; > > + =A0 =A0CCIDCardInfo *cardinfo; /* caching the info pointer */ > > + =A0 =A0uint8_t =A0debug; > > + =A0 =A0uint8_t =A0auto_attach; > > + =A0 =A0bulk_in_t bulk_in_pending[BULK_IN_PENDING_NUM]; /* circular = */ > > + =A0 =A0uint32_t bulk_in_pending_start; > > + =A0 =A0uint32_t bulk_in_pending_end; /* first free */ > > + =A0 =A0uint32_t bulk_in_pending_num; > > + =A0 =A0bulk_in_t *current_bulk_in; > > + =A0 =A0uint8_t =A0bulk_out_data[BULK_OUT_DATA_SIZE]; > > + =A0 =A0uint32_t bulk_out_pos; > > + =A0 =A0uint8_t =A0bmSlotICCState; > > + =A0 =A0uint8_t =A0powered; > > + =A0 =A0uint8_t =A0notify_slot_change; > > + =A0 =A0uint64_t last_answer_error; > > + =A0 =A0answer_t pending_answers[PENDING_ANSWERS_NUM]; > > + =A0 =A0uint32_t pending_answers_start; > > + =A0 =A0uint32_t pending_answers_end; > > + =A0 =A0uint32_t pending_answers_num; > > + =A0 =A0uint8_t =A0bError; > > + =A0 =A0uint8_t =A0bmCommandStatus; > > + =A0 =A0uint8_t =A0bProtocolNum; > > + =A0 =A0uint8_t =A0abProtocolDataStructure[MAX_PROTOCOL_SIZE]; > > + =A0 =A0uint32_t ulProtocolDataStructureSize; > > + =A0 =A0uint8_t =A0attached_vmstate; > > + =A0 =A0uint32_t state_vmstate; > > + =A0 =A0uint8_t =A0migration_state; > > + =A0 =A0uint32_t migration_target_ip; > > + =A0 =A0uint16_t migration_target_port; > > +}; > > + > > +/* Slot specific variables. We emulate a single slot card reader. > > + */ > > + > > + > > +/* CCID Spec chapter 4: CCID uses a standard device descriptor per C= hapter 9, > > + * "USB Device Framework", section 9.6.1, in the Universal Serial Bu= s > > + * Specification. > > + * > > + * This device implemented based on the spec and with an Athena Smar= t Card > > + * Reader as reference: > > + * =A0 0dc3:1004 Athena Smartcard Solutions, Inc. > > + */ > > + > > +static const uint8_t qemu_ccid_dev_descriptor[] =3D { > > + =A0 =A0 =A0 =A00x12, =A0 =A0 =A0 /* =A0u8 bLength; */ > > + =A0 =A0 =A0 =A0USB_DT_DEVICE, /* =A0u8 bDescriptorType; Device */ > > + =A0 =A0 =A0 =A00x10, 0x01, /* =A0u16 bcdUSB; v1.1 */ > > + > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0bDeviceClass; */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0bDeviceSubClass; */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0bDeviceProtocol; [ low= /full speeds only ] */ > > + =A0 =A0 =A0 =A00x40, =A0 =A0 =A0 /* =A0u8 =A0bMaxPacketSize0; 8 Byt= es (valid: 8,16,32,64) */ > > + > > + =A0 =A0 =A0 =A0/* Vendor and product id are arbitrary. =A0*/ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u16 idVendor =A0*/ > > + =A0 =A0 =A0 =A0CCID_VENDOR_ID & 0xff, CCID_VENDOR_ID >> 8, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u16 idProduct */ > > + =A0 =A0 =A0 =A0CCID_PRODUCT_ID & 0xff, CCID_PRODUCT_ID >> 8, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u16 bcdDevice */ > > + =A0 =A0 =A0 =A0CCID_DEVICE_VERSION & 0xff, CCID_DEVICE_VERSION >> 8= , > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0iManufacturer; */ > > + =A0 =A0 =A0 =A00x02, =A0 =A0 =A0 /* =A0u8 =A0iProduct; */ > > + =A0 =A0 =A0 =A00x03, =A0 =A0 =A0 /* =A0u8 =A0iSerialNumber; */ > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0bNumConfigurations; */ > > +}; > > + > > +static const uint8_t qemu_ccid_config_descriptor[] =3D { > > + > > + =A0 =A0 =A0 =A0/* one configuration */ > > + =A0 =A0 =A0 =A00x09, =A0 =A0 =A0 /* =A0u8 =A0bLength; */ > > + =A0 =A0 =A0 =A0USB_DT_CONFIG, /* =A0u8 =A0bDescriptorType; Configur= ation */ > > + =A0 =A0 =A0 =A00x5d, 0x00, /* =A0u16 wTotalLength; 9+9+54+7+7+7 */ > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0bNumInterfaces; (1) */ > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0bConfigurationValue; *= / > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0iConfiguration; */ > > + =A0 =A0 =A0 =A00xe0, =A0 =A0 =A0 /* =A0u8 =A0bmAttributes; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Bit= 7: must be set, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 6: Self-powered, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 5: Remote wakeup, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 4..0: resvd */ > > + =A0 =A0 =A0 =A0100/2, =A0 =A0 =A0/* =A0u8 =A0MaxPower; 50 =3D=3D 10= 0mA */ > > + > > + =A0 =A0 =A0 =A0/* one interface */ > > + =A0 =A0 =A0 =A00x09, =A0 =A0 =A0 /* =A0u8 =A0if_bLength; */ > > + =A0 =A0 =A0 =A0USB_DT_INTERFACE, /* =A0u8 =A0if_bDescriptorType; In= terface */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0if_bInterfaceNumber; *= / > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0if_bAlternateSetting; = */ > > + =A0 =A0 =A0 =A00x03, =A0 =A0 =A0 /* =A0u8 =A0if_bNumEndpoints; */ > > + =A0 =A0 =A0 =A00x0b, =A0 =A0 =A0 /* =A0u8 =A0if_bInterfaceClass; Sm= art Card Device Class */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0if_bInterfaceSubClass;= Subclass code */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0if_bInterfaceProtocol;= Protocol code */ > > + =A0 =A0 =A0 =A00x04, =A0 =A0 =A0 /* =A0u8 =A0if_iInterface; Index o= f string descriptor */ > > + > > + =A0 =A0 =A0 =A0/* Smart Card Device Class Descriptor */ > > + =A0 =A0 =A0 =A00x36, =A0 =A0 =A0 /* =A0u8 =A0bLength; */ > > + =A0 =A0 =A0 =A00x21, =A0 =A0 =A0 /* =A0u8 =A0bDescriptorType; Funct= ional */ > > + =A0 =A0 =A0 =A00x10, 0x01, /* =A0u16 bcdCCID; CCID Specification Re= lease Number. */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0bMaxSlotIndex; The ind= ex of the highest available > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0slot on this device.= All slots are consecutive starting > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0at 00h. */ > > + =A0 =A0 =A0 =A00x07, =A0 =A0 =A0 /* =A0u8 =A0bVoltageSupport; 01h -= 5.0v, 02h - 3.0, 03 - 1.8 */ > > + > > + =A0 =A0 =A0 =A00x03, 0x00, /* =A0u32 dwProtocols; RRRR PPPP. RRRR =3D= 0000h.*/ > > + =A0 =A0 =A0 =A00x00, 0x00, /* =A0PPPP: 0001h =3D Protocol T=3D0, 00= 02h =3D Protocol T=3D1 */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwDefaultClock; in= kHZ (0x0fa0 is 4 MHz) */ > > + =A0 =A0 =A0 =A00xa0, 0x0f, 0x00, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwMaximumClock; */ > > + =A0 =A0 =A0 =A00x00, 0x00, 0x01, 0x00, > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 bNumClockSupported; 0 mea= ns just the default and max. */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwDataRate ;bps. 9= 600 =3D=3D 00002580h */ > > + =A0 =A0 =A0 =A00x80, 0x25, 0x00, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwMaxDataRate ; 11= 520 bps =3D=3D 0001C200h */ > > + =A0 =A0 =A0 =A00x00, 0xC2, 0x01, 0x00, > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0bNumDataRatesSupported= ; 00 means all rates between > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0 =A0 =A0default and ma= x */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwMaxIFSD; maximum= IFSD supported by CCID for protocol > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0 =A0 =A0T=3D1 (Maximum= seen from various cards) */ > > + =A0 =A0 =A0 =A00xfe, 0x00, 0x00, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwSyncProtocols; 1= - 2-wire, 2 - 3-wire, 4 - I2C */ > > + =A0 =A0 =A0 =A00x00, 0x00, 0x00, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwMechanical; =A00= - no special characteristics. */ > > + =A0 =A0 =A0 =A00x00, 0x00, 0x00, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwFeatures; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A00 - No special charact= eristics > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 2 Automatic paramete= r configuration based on ATR data > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 4 Automatic activati= on of ICC on inserting > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 8 Automatic ICC volt= age selection > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 10 Automatic ICC clo= ck frequency change > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 20 Automatic baud ra= te change > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 40 Automatic paramet= ers negotiation made by the CCID > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 80 automatic PPS mad= e by the CCID > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0100 CCID can set ICC i= n clock stop mode > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0200 NAD value other th= en 00 accepted (T=3D1 protocol) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 400 Automatic IFSD e= xchange as first exchange (T=3D1) > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0One of the following o= nly: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 10000 TPDU level exc= hanges with CCID > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A020000 Short APDU level= exchange with CCID > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A040000 Short and Extend= ed APDU level exchange with CCID > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0+ 100000 USB Wake up s= ignaling supported on card insertion > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0and removal. Must set = bit 5 in bmAttributes in Configuration > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0descriptor if 100000 i= s set.*/ > > + =A0 =A0 =A0 =A00xfe, 0x04, 0x11, 0x00, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u32 dwMaxCCIDMessageLe= ngth; For extended APDU in [261 + 10 > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0, 65544 + 10]. Otherwi= se the minimum is wMaxPacketSize of > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0the Bulk-OUT endpoint = */ > > + =A0 =A0 =A0 =A00x12, 0x00, 0x01, 0x00, > > + =A0 =A0 =A0 =A00xFF, =A0 =A0 =A0 /* =A0u8 =A0bClassGetResponse; Sig= nificant only for CCID that > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0offers an APDU level f= or exchanges. Indicates the default > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0class value used by th= e CCID when it sends a Get Response > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0command to perform the= transportation of an APDU by T=3D0 > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0protocol > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0FFh indicates that the= CCID echos the class of the APDU. > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 */ > > + =A0 =A0 =A0 =A00xFF, =A0 =A0 =A0 /* =A0u8 =A0bClassEnvelope; EAPDU = only. Envelope command for T=3D0 */ > > + =A0 =A0 =A0 =A00x00, 0x00, /* =A0u16 wLcdLayout; XXYY Number of lin= es (XX) and chars per > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0line for LCD display u= sed for PIN entry. 0000 - no LCD */ > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0bPINSupport; 01h PIN V= erification, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 * =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 02h PIN Modification */ > > + =A0 =A0 =A0 =A00x01, =A0 =A0 =A0 /* =A0u8 =A0bMaxCCIDBusySlots; */ > > + > > + =A0 =A0 =A0 =A0/* Interrupt-IN endpoint */ > > + =A0 =A0 =A0 =A00x07, =A0 =A0 =A0 /* =A0u8 =A0ep_bLength; */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bDescriptorTy= pe; Endpoint */ > > + =A0 =A0 =A0 =A0USB_DT_ENDPOINT, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bEndpointAddr= ess; IN Endpoint 1 */ > > + =A0 =A0 =A0 =A00x80 | CCID_INT_IN_EP, > > + =A0 =A0 =A0 =A00x03, =A0 =A0 =A0 /* =A0u8 =A0ep_bmAttributes; Inter= rupt */ > > + =A0 =A0 =A0 =A00x40, 0x00, /* =A0u16 ep_wMaxPacketSize; */ > > + =A0 =A0 =A0 =A00xff, =A0 =A0 =A0 /* =A0u8 =A0ep_bInterval; */ > > + > > + =A0 =A0 =A0 =A0/* Bulk-In endpoint */ > > + =A0 =A0 =A0 =A00x07, =A0 =A0 =A0 /* =A0u8 =A0ep_bLength; */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bDescriptorTy= pe; Endpoint */ > > + =A0 =A0 =A0 =A0USB_DT_ENDPOINT, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bEndpointAddr= ess; IN Endpoint 2 */ > > + =A0 =A0 =A0 =A00x80 | CCID_BULK_IN_EP, > > + =A0 =A0 =A0 =A00x02, =A0 =A0 =A0 /* =A0u8 =A0ep_bmAttributes; Bulk = */ > > + =A0 =A0 =A0 =A00x40, 0x00, /* =A0u16 ep_wMaxPacketSize; */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0ep_bInterval; */ > > + > > + =A0 =A0 =A0 =A0/* Bulk-Out endpoint */ > > + =A0 =A0 =A0 =A00x07, =A0 =A0 =A0 /* =A0u8 =A0ep_bLength; */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bDescriptorTy= pe; Endpoint */ > > + =A0 =A0 =A0 =A0USB_DT_ENDPOINT, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* =A0u8 =A0ep_bEndpointAddr= ess; OUT Endpoint 3 */ > > + =A0 =A0 =A0 =A0CCID_BULK_OUT_EP, > > + =A0 =A0 =A0 =A00x02, =A0 =A0 =A0 /* =A0u8 =A0ep_bmAttributes; Bulk = */ > > + =A0 =A0 =A0 =A00x40, 0x00, /* =A0u16 ep_wMaxPacketSize; */ > > + =A0 =A0 =A0 =A00x00, =A0 =A0 =A0 /* =A0u8 =A0ep_bInterval; */ > > + > > +}; > > + > > +static bool ccid_has_pending_answers(USBCCIDState *s) > > +{ > > + =A0 =A0return s->pending_answers_num > 0; > > +} > > + > > +static void ccid_clear_pending_answers(USBCCIDState *s) > > +{ > > + =A0 =A0s->pending_answers_num =3D 0; > > + =A0 =A0s->pending_answers_start =3D 0; > > + =A0 =A0s->pending_answers_end =3D 0; > > +} > > + > > +static void ccid_print_pending_answers(USBCCIDState *s) > > +{ > > +#ifdef DEBUG_CCID > > + =A0 =A0answer_t *answer; > > + =A0 =A0int i, count; > > + > > + =A0 =A0printf("usb-ccid: pending answers:"); > > + =A0 =A0if (!ccid_has_pending_answers(s)) { > > + =A0 =A0 =A0 =A0printf(" empty\n"); > > + =A0 =A0 =A0 =A0return; > > + =A0 =A0} > > + =A0 =A0for (i =3D s->pending_answers_start, count=3Ds->pending_answ= ers_num ; > > + =A0 =A0 =A0 =A0 count > 0; count--, i++) { > > + =A0 =A0 =A0 =A0answer =3D &s->pending_answers[i % PENDING_ANSWERS_N= UM]; > > + =A0 =A0 =A0 =A0if (count =3D=3D 1) { > > + =A0 =A0 =A0 =A0 =A0 =A0printf("%d:%d\n", answer->slot, answer->seq)= ; > > + =A0 =A0 =A0 =A0} else { > > + =A0 =A0 =A0 =A0 =A0 =A0printf("%d:%d,", answer->slot, answer->seq); > > + =A0 =A0 =A0 =A0} > > + =A0 =A0} > > +#endif > > +} > > + > > +static void ccid_add_pending_answer(USBCCIDState *s, CCID_Header *hd= r) > > +{ > > + =A0 =A0answer_t* answer; > > + > > + =A0 =A0assert(s->pending_answers_num++ < PENDING_ANSWERS_NUM); > > + =A0 =A0answer =3D &s->pending_answers[(s->pending_answers_end++) % = PENDING_ANSWERS_NUM]; > > + =A0 =A0answer->slot =3D hdr->bSlot; > > + =A0 =A0answer->seq =3D hdr->bSeq; > > + =A0 =A0ccid_print_pending_answers(s); > > +} > > + > > +static void ccid_remove_pending_answer(USBCCIDState *s, > > + =A0 =A0uint8_t *slot, uint8_t *seq) > > +{ > > + =A0 =A0answer_t *answer; > > + > > + =A0 =A0assert(s->pending_answers_num-- > 0); > > + =A0 =A0answer =3D &s->pending_answers[(s->pending_answers_start++) = % PENDING_ANSWERS_NUM]; > > + =A0 =A0*slot =3D answer->slot; > > + =A0 =A0*seq =3D answer->seq; > > + =A0 =A0ccid_print_pending_answers(s); > > +} > > + > > +static void ccid_bulk_in_clear(USBCCIDState *s) > > +{ > > + =A0 =A0s->bulk_in_pending_start =3D 0; > > + =A0 =A0s->bulk_in_pending_end =3D 0; > > + =A0 =A0s->bulk_in_pending_num =3D 0; > > +} > > + > > +static void ccid_bulk_in_release(USBCCIDState *s) > > +{ > > + =A0 =A0assert(s->current_bulk_in !=3D NULL); > > + =A0 =A0s->current_bulk_in->pos =3D 0; > > + =A0 =A0s->current_bulk_in =3D NULL; > > +} > > + > > +static void ccid_bulk_in_get(USBCCIDState *s) > > +{ > > + =A0 =A0if (s->current_bulk_in !=3D NULL || s->bulk_in_pending_num =3D= =3D 0) { > > + =A0 =A0 =A0 =A0return; > > + =A0 =A0} > > + =A0 =A0assert(s->bulk_in_pending_num > 0); > > + =A0 =A0s->bulk_in_pending_num--; > > + =A0 =A0s->current_bulk_in =3D &s->bulk_in_pending[ > > + =A0 =A0 =A0 =A0(s->bulk_in_pending_start++) % BULK_IN_PENDING_NUM]; > > +} > > + > > +static void* ccid_reserve_recv_buf(USBCCIDState* s, uint16_t len) > > +{ > > + =A0 =A0bulk_in_t* bulk_in; > > + > > + =A0 =A0DPRINTF(s, 4, "%s: QUEUE: reserve %d bytes\n", __func__, len= ); > > + > > + =A0 =A0/* look for an existing element */ > > + =A0 =A0if (len > BULK_IN_BUF_SIZE) { > > + =A0 =A0 =A0 =A0printf("usb-ccid.c: %s: len larger then max (%d>%d).= discarding message.\n", > > + =A0 =A0 =A0 =A0 =A0 =A0__func__, len, BULK_IN_BUF_SIZE); > > + =A0 =A0 =A0 =A0return NULL; > > + =A0 =A0} > > + =A0 =A0if (s->bulk_in_pending_num >=3D BULK_IN_PENDING_NUM) { > > + =A0 =A0 =A0 =A0printf("usb-ccid.c: %s: No free bulk_in buffers. dis= carding message.\n", > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0__func__); > > + =A0 =A0 =A0 =A0return NULL; > > + =A0 =A0} > > + =A0 =A0bulk_in =3D &s->bulk_in_pending[(s->bulk_in_pending_end++) %= BULK_IN_PENDING_NUM]; > > + =A0 =A0s->bulk_in_pending_num++; > > + =A0 =A0bulk_in->len =3D len; > > + =A0 =A0return bulk_in->data; > > +} > > + > > +static void ccid_reset(USBCCIDState *s) > > +{ > > + =A0 =A0ccid_bulk_in_clear(s); > > + =A0 =A0ccid_clear_pending_answers(s); > > +} > > + > > +static void ccid_detach(USBCCIDState *s) > > +{ > > + =A0 =A0ccid_reset(s); > > + =A0 =A0if (s->auto_attach =3D=3D 0 && s->dev.attached) { > > + =A0 =A0 =A0 =A0usb_device_detach(&s->dev); > > + =A0 =A0} > > +} > > + > > +static void ccid_handle_reset(USBDevice *dev) > > +{ > > + =A0 =A0USBCCIDState *s =3D DO_UPCAST(USBCCIDState, dev, dev); > > + > > + =A0 =A0DPRINTF(s, 1, "Reset\n"); > > + > > + =A0 =A0ccid_reset(s); > > +} > > + > > +static int ccid_handle_control(USBDevice *dev, int request, int valu= e, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= int index, int length, uint8_t *data) > > +{ > > + =A0 =A0USBCCIDState *s =3D DO_UPCAST(USBCCIDState, dev, dev); > > + =A0 =A0int ret =3D 0; > > + > > + =A0 =A0DPRINTF(s, 1, "got control %x, value %x\n",request, value); > > + =A0 =A0switch (request) { > > + =A0 =A0case DeviceRequest | USB_REQ_GET_STATUS: > > + =A0 =A0 =A0 =A0data[0] =3D (0 << USB_DEVICE_SELF_POWERED) | > > + =A0 =A0 =A0 =A0 =A0 =A0(dev->remote_wakeup << USB_DEVICE_REMOTE_WAK= EUP); > > + =A0 =A0 =A0 =A0data[1] =3D 0x00; > > + =A0 =A0 =A0 =A0ret =3D 2; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceOutRequest | USB_REQ_CLEAR_FEATURE: > > + =A0 =A0 =A0 =A0if (value =3D=3D USB_DEVICE_REMOTE_WAKEUP) { > > + =A0 =A0 =A0 =A0 =A0 =A0dev->remote_wakeup =3D 0; > > + =A0 =A0 =A0 =A0} else { > > + =A0 =A0 =A0 =A0 =A0 =A0goto fail; > > + =A0 =A0 =A0 =A0} > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceOutRequest | USB_REQ_SET_FEATURE: > > + =A0 =A0 =A0 =A0if (value =3D=3D USB_DEVICE_REMOTE_WAKEUP) { > > + =A0 =A0 =A0 =A0 =A0 =A0dev->remote_wakeup =3D 1; > > + =A0 =A0 =A0 =A0} else { > > + =A0 =A0 =A0 =A0 =A0 =A0goto fail; > > + =A0 =A0 =A0 =A0} > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceOutRequest | USB_REQ_SET_ADDRESS: > > + =A0 =A0 =A0 =A0dev->addr =3D value; > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceRequest | USB_REQ_GET_DESCRIPTOR: > > + =A0 =A0 =A0 =A0switch(value >> 8) { > > + =A0 =A0 =A0 =A0case USB_DT_DEVICE: > > + =A0 =A0 =A0 =A0 =A0 =A0memcpy(data, qemu_ccid_dev_descriptor, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sizeof(qemu_ccid_dev_descriptor= )); > > + =A0 =A0 =A0 =A0 =A0 =A0ret =3D sizeof(qemu_ccid_dev_descriptor); > > + =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0case USB_DT_CONFIG: > > + =A0 =A0 =A0 =A0 =A0 =A0memcpy(data, qemu_ccid_config_descriptor, > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 sizeof(qemu_ccid_config_descrip= tor)); > > + =A0 =A0 =A0 =A0 =A0 =A0ret =3D sizeof(qemu_ccid_config_descriptor); > > + =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0case USB_DT_STRING: > > + =A0 =A0 =A0 =A0 =A0 =A0switch(value & 0xff) { > > + =A0 =A0 =A0 =A0 =A0 =A0case 0: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* language ids */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0data[0] =3D 4; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0data[1] =3D 3; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0data[2] =3D 0x09; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0data[3] =3D 0x04; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D 4; > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0case 1: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* vendor description */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D set_usb_string(data, CCID_VE= NDOR_DESCRIPTION); > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0case 2: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* product description */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D set_usb_string(data, CCID_PR= ODUCT_DESCRIPTION); > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0case 3: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* serial number */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D set_usb_string(data, CCID_SE= RIAL_NUMBER_STRING); > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0case 4: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* interface name */ > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ret =3D set_usb_string(data, CCID_IN= TERFACE_NAME); > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0 =A0 =A0default: > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0goto fail; > > + =A0 =A0 =A0 =A0 =A0 =A0} > > + =A0 =A0 =A0 =A0 =A0 =A0break; > > + =A0 =A0 =A0 =A0default: > > + =A0 =A0 =A0 =A0 =A0 =A0goto fail; > > + =A0 =A0 =A0 =A0} > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceRequest | USB_REQ_GET_CONFIGURATION: > > + =A0 =A0 =A0 =A0data[0] =3D 1; > > + =A0 =A0 =A0 =A0ret =3D 1; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceOutRequest | USB_REQ_SET_CONFIGURATION: > > + =A0 =A0 =A0 =A0/* Only one configuration - we just ignore the reque= st */ > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case DeviceRequest | USB_REQ_GET_INTERFACE: > > + =A0 =A0 =A0 =A0data[0] =3D 0; > > + =A0 =A0 =A0 =A0ret =3D 1; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case InterfaceOutRequest | USB_REQ_SET_INTERFACE: > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case EndpointOutRequest | USB_REQ_CLEAR_FEATURE: > > + =A0 =A0 =A0 =A0ret =3D 0; > > + =A0 =A0 =A0 =A0break; > > + > > + =A0 =A0 =A0 =A0/* Class specific requests. =A0*/ > > + =A0 =A0case InterfaceOutClass | CCID_CONTROL_ABORT: > > + =A0 =A0 =A0 =A0DPRINTF(s, 1, "ccid_control abort UNIMPLEMENTED\n"); > > + =A0 =A0 =A0 =A0ret =3D USB_RET_STALL; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case InterfaceInClass | CCID_CONTROL_GET_CLOCK_FREQUENCIES: > > + =A0 =A0 =A0 =A0DPRINTF(s, 1, "ccid_control get clock frequencies UN= IMPLEMENTED\n"); > > + =A0 =A0 =A0 =A0ret =3D USB_RET_STALL; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0case InterfaceInClass | CCID_CONTROL_GET_DATA_RATES: > > + =A0 =A0 =A0 =A0DPRINTF(s, 1, "ccid_control get data rates UNIMPLEME= NTED\n"); > > + =A0 =A0 =A0 =A0ret =3D USB_RET_STALL; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0default: > > + =A0 =A0fail: > > + =A0 =A0 =A0 =A0DPRINTF(s, 1, "got unsupported/bogus control %x, val= ue %x\n", request, value); > > + =A0 =A0 =A0 =A0ret =3D USB_RET_STALL; > > + =A0 =A0 =A0 =A0break; > > + =A0 =A0} > > + =A0 =A0return ret; > > +} > > + > > +static bool ccid_card_inserted(USBCCIDState *s) > > +{ > > + =A0 =A0return s->bmSlotICCState & SLOT_0_STATE_MASK; > > +} > > + > > +static uint8_t ccid_card_status(USBCCIDState *s) > > +{ > > + =A0 =A0return ccid_card_inserted(s) > > + =A0 =A0 =A0 =A0 =A0 =A0? (s->powered ? > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0ICC_STATUS_PRESENT_ACTIVE > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0: ICC_STATUS_PRESENT_INACTIVE > > + =A0 =A0 =A0 =A0 =A0 =A0 =A0) > > + =A0 =A0 =A0 =A0 =A0 =A0: ICC_STATUS_NOT_PRESENT; > > +} > > + > > +static uint8_t ccid_calc_status(USBCCIDState *s) > > +{ > > + =A0 =A0/* page 55, 6.2.6, calculation of bStatus from bmICCStatus a= nd > > + =A0 =A0 =A0 bmCommandStatus > > + =A0 =A0 */ > > + =A0 =A0uint8_t ret =3D ccid_card_status(s) | (s->bmCommandStatus <<= 6); > > + =A0 =A0DPRINTF(s, 4, "status =3D %d\n", ret); > > + =A0 =A0return ret; > > +} > > + > > +static void ccid_reset_error_status(USBCCIDState* s) > > +{ > > + =A0 =A0s->bError =3D ERROR_CMD_NOT_SUPPORTED; > > + =A0 =A0s->bmCommandStatus =3D COMMAND_STATUS_NO_ERROR; > > +} > > + > > +static void ccid_write_slot_status(USBCCIDState* s, CCID_Header* rec= v) > > +{ > > + =A0 =A0CCID_SlotStatus *h =3D ccid_reserve_recv_buf(s, sizeof(CCID_= SlotStatus)); > > + =A0 =A0if (h =3D=3D NULL) { > > + =A0 =A0 =A0 =A0return; > > + =A0 =A0} > > + =A0 =A0h->b.hdr.bMessageType =3D CCID_MESSAGE_TYPE_RDR_to_PC_SlotSt= atus; > > + =A0 =A0h->b.hdr.dwLength =3D 0; > > + =A0 =A0h->b.hdr.bSlot =3D recv->bSlot; > > + =A0 =A0h->b.hdr.bSeq =3D recv->bSeq; > > + =A0 =A0h->b.bStatus =3D ccid_calc_status(s); > > + =A0 =A0h->b.bError =3D s->bError; > > + =A0 =A0h->bClockStatus =3D CLOCK_STATUS_RUNNING; > > + =A0 =A0ccid_reset_error_status(s); > > +} > > + > > +static void ccid_write_parameters(USBCCIDState* s, CCID_Header* recv= ) > > +{ > > + =A0 =A0CCID_Parameter *h; > > + =A0 =A0uint32_t len =3D s->ulProtocolDataStructureSize; > > + > > + =A0 =A0h =3D ccid_reserve_recv_buf(s, sizeof(CCID_Parameter) + len)= ; > > + =A0 =A0if (h =3D=3D NULL) { > > + =A0 =A0 =A0 =A0return; > > + =A0 =A0} > > + =A0 =A0h->b.hdr.bMessageType =3D CCID_MESSAGE_TYPE_RDR_to_PC_Parame= ters; > > + =A0 =A0h->b.hdr.dwLength =3D 0; > > + =A0 =A0h->b.hdr.bSlot =3D recv->bSlot; > > + =A0 =A0h->b.hdr.bSeq =3D recv->bSeq; > > + =A0 =A0h->b.bStatus =3D ccid_calc_status(s); > > + =A0 =A0h->b.bError =3D s->bError; > > + =A0 =A0h->bProtocolNum =3D s->bProtocolNum; > > + =A0 =A0memcpy(h->abProtocolDataStructure, s->abProtocolDataStructur= e, len); > > + =A0 =A0ccid_reset_error_status(s); > > +} > > + > > +static void ccid_write_data_block( > > + =A0 =A0USBCCIDState* s, uint8_t slot, uint8_t seq, > > + =A0 =A0const uint8_t* data, uint32_t len) > > +{ > > + =A0 =A0CCID_DataBlock *p =3D ccid_reserve_recv_buf(s, sizeof(*p) + = len); > > + > > + =A0 =A0if (p =3D=3D NULL) { > > + =A0 =A0 =A0 =A0return; > > + =A0 =A0} > > + =A0 =A0p->b.hdr.bMessageType =3D CCID_MESSAGE_TYPE_RDR_to_PC_DataBl= ock; > > + =A0 =A0p->b.hdr.dwLength =3D len; >=20 > This assumes that host endianess happens to match what USB uses. Answered (with a question) above.