usb: add USB mass storage class support

This commit is contained in:
Michael Smith
2025-06-09 11:17:23 -04:00
committed by Ron Evans
parent ba274008d5
commit 87153e9a02
15 changed files with 1714 additions and 3 deletions
+45
View File
@@ -4,6 +4,17 @@ import (
"internal/binary"
)
/* Endpoint Descriptor
USB 2.0 Specification: 9.6.6 Endpoint
*/
const (
TransferTypeControl uint8 = iota
TransferTypeIsochronous
TransferTypeBulk
TransferTypeInterrupt
)
var endpointEP1IN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
@@ -74,6 +85,36 @@ var EndpointEP5OUT = EndpointType{
data: endpointEP5OUT[:],
}
// Mass Storage Class bulk in endpoint
var endpointMSCIN = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x86, // EndpointAddress
TransferTypeBulk, // Attributes
0x40, // MaxPacketSizeL (64 bytes)
0x00, // MaxPacketSizeH
0x00, // Interval
}
var EndpointMSCIN = EndpointType{
data: endpointMSCIN[:],
}
// Mass Storage Class bulk out endpoint
var endpointMSCOUT = [endpointTypeLen]byte{
endpointTypeLen,
TypeEndpoint,
0x07, // EndpointAddress
TransferTypeBulk, // Attributes
0x40, // MaxPacketSizeL (64 bytes)
0x00, // MaxPacketSizeH
0x00, // Interval
}
var EndpointMSCOUT = EndpointType{
data: endpointMSCOUT[:],
}
const (
endpointTypeLen = 7
)
@@ -109,3 +150,7 @@ func (d EndpointType) MaxPacketSize(v uint16) {
func (d EndpointType) Interval(v uint8) {
d.data[6] = byte(v)
}
func (d EndpointType) GetMaxPacketSize() uint16 {
return binary.LittleEndian.Uint16(d.data[4:6])
}
+75
View File
@@ -0,0 +1,75 @@
package descriptor
const (
interfaceClassMSC = 0x08
mscSubclassSCSI = 0x06
mscProtocolBOT = 0x50
)
var interfaceAssociationMSC = [interfaceAssociationTypeLen]byte{
interfaceAssociationTypeLen,
TypeInterfaceAssociation,
0x02, // FirstInterface
0x01, // InterfaceCount
interfaceClassMSC, // FunctionClass
mscSubclassSCSI, // FunctionSubClass
mscProtocolBOT, // FunctionProtocol
0x00, // Function
}
var InterfaceAssociationMSC = InterfaceAssociationType{
data: interfaceAssociationMSC[:],
}
var interfaceMSC = [interfaceTypeLen]byte{
interfaceTypeLen, // Length
TypeInterface, // DescriptorType
0x02, // InterfaceNumber
0x00, // AlternateSetting
0x02, // NumEndpoints
interfaceClassMSC, // InterfaceClass (Mass Storage)
mscSubclassSCSI, // InterfaceSubClass (SCSI Transparent)
mscProtocolBOT, // InterfaceProtocol (Bulk-Only Transport)
0x00, // Interface
}
var InterfaceMSC = InterfaceType{
data: interfaceMSC[:],
}
var configurationMSC = [configurationTypeLen]byte{
configurationTypeLen,
TypeConfiguration,
0x6a, 0x00, // wTotalLength
0x03, // number of interfaces (bNumInterfaces)
0x01, // configuration value (bConfigurationValue)
0x00, // index to string description (iConfiguration)
0xa0, // attributes (bmAttributes)
0x32, // maxpower (100 mA) (bMaxPower)
}
var ConfigurationMSC = ConfigurationType{
data: configurationMSC[:],
}
// Mass Storage Class
var MSC = Descriptor{
Device: DeviceCDC.Bytes(),
Configuration: Append([][]byte{
ConfigurationMSC.Bytes(),
InterfaceAssociationCDC.Bytes(),
InterfaceCDCControl.Bytes(),
ClassSpecificCDCHeader.Bytes(),
ClassSpecificCDCACM.Bytes(),
ClassSpecificCDCUnion.Bytes(),
ClassSpecificCDCCallManagement.Bytes(),
EndpointEP1IN.Bytes(),
InterfaceCDCData.Bytes(),
EndpointEP2OUT.Bytes(),
EndpointEP3IN.Bytes(),
InterfaceAssociationMSC.Bytes(),
InterfaceMSC.Bytes(),
EndpointMSCIN.Bytes(),
EndpointMSCOUT.Bytes(),
}),
}