From fcb61153f84a81e2a3682c9ddcbaf14e5f49f865 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 15 Sep 2026 18:00:09 +0200 Subject: [PATCH] usb: pack the CDC line coding struct to its 7 wire bytes uint32_t plus three uint8_t pads to 8, so sizeof(line) was 8 where CDC defines 7. Hosts asking for more than 7 got a byte of uninitialised static padding. The commented out SET_LINE_CODING loop already hardcodes i < 7, so the wire format was understood; the struct just did not match. No observable change for cdc_acm or usbser.sys, which both ask for exactly 7. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 1 + common_arm/usb/usb_cdc_at91.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dda0e9bba..ab49ebe84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed `GET_LINE_CODING` - the CDC line coding struct is now packed to the 7 bytes the spec defines (@iceman1001) - Fixed USB control transfers - a descriptor whose length is an exact multiple of the 8 byte control endpoint now ends with a zero length packet (@iceman1001) - Fixed USB WCID descriptors - the device advertised Microsoft OS descriptor support in string 0xEE but stalled the vendor request that follows (@iceman1001) - Added `hf mfdes sim` - answers GetDFNames and GetISOFileIDs, so a reader sees the ISO file ids and DF names of the simulated card (@iceman1001) diff --git a/common_arm/usb/usb_cdc_at91.c b/common_arm/usb/usb_cdc_at91.c index 95184cbde..e79cb310a 100644 --- a/common_arm/usb/usb_cdc_at91.c +++ b/common_arm/usb/usb_cdc_at91.c @@ -140,12 +140,14 @@ static const char *getStringDescriptor(uint8_t idx) { } +// CDC LineCoding is 7 bytes on the wire, so this must not pick up the padding +// byte that natural alignment would add after DataBits. typedef struct { uint32_t BitRate; uint8_t Format; uint8_t ParityType; uint8_t DataBits; -} AT91S_CDC_LINE_CODING, *AT91PS_CDC_LINE_CODING; +} PACKED AT91S_CDC_LINE_CODING, *AT91PS_CDC_LINE_CODING; static AT91S_CDC_LINE_CODING line = { // purely informative, actual values don't matter USART_BAUD_RATE, // baudrate