github.com/f-secure-foundry/tamago@v0.0.0-20220307101044-d73fcdd7f11b/soc/imx6/usb/descriptor_ums.go (about) 1 // https://github.com/f-secure-foundry/tamago 2 // 3 // Copyright (c) F-Secure Corporation 4 // https://foundry.f-secure.com 5 // 6 // Use of this source code is governed by the license 7 // that can be found in the LICENSE file. 8 9 package usb 10 11 import ( 12 "bytes" 13 "encoding/binary" 14 ) 15 16 // Mass Storage constants 17 const ( 18 CBW_LENGTH = 31 19 CBW_CB_MAX_LENGTH = 16 20 21 CBW_SIGNATURE = 0x43425355 22 CSW_SIGNATURE = 0x53425355 23 24 // p15, Table 5.3 - Command Block Status Values, USB Mass Storage Class 1.0 25 CSW_STATUS_COMMAND_PASSED = 0x00 26 CSW_STATUS_COMMAND_FAILED = 0x01 27 CSW_STATUS_PHASE_ERROR = 0x02 28 29 // p7, 3.1 - 3.2, USB Mass Storage Class 1.0 30 BULK_ONLY_MASS_STORAGE_RESET = 0xff 31 GET_MAX_LUN = 0xfe 32 ) 33 34 // CBW implements p13, 5.1 Command Block Wrapper (CBW), USB Mass Storage Class 1.0 35 type CBW struct { 36 Signature uint32 37 Tag uint32 38 DataTransferLength uint32 39 Flags uint8 40 LUN uint8 41 Length uint8 42 CommandBlock [16]byte 43 } 44 45 // SetDefaults initializes default values for the CBW descriptor. 46 func (d *CBW) SetDefaults() { 47 d.Signature = CBW_SIGNATURE 48 } 49 50 // Bytes converts the descriptor structure to byte array format. 51 func (d *CBW) Bytes() []byte { 52 buf := new(bytes.Buffer) 53 binary.Write(buf, binary.LittleEndian, d) 54 return buf.Bytes() 55 } 56 57 // CSW implements p14, 5.2 Command Status Wrapper (CSW), USB Mass Storage Class 1.0 58 type CSW struct { 59 Signature uint32 60 Tag uint32 61 DataResidue uint32 62 Status uint8 63 } 64 65 // SetDefaults initializes default values for the CSW descriptor. 66 func (d *CSW) SetDefaults() { 67 d.Signature = CSW_SIGNATURE 68 d.Status = CSW_STATUS_COMMAND_PASSED 69 } 70 71 // Bytes converts the descriptor structure to byte array format. 72 func (d *CSW) Bytes() []byte { 73 buf := new(bytes.Buffer) 74 binary.Write(buf, binary.LittleEndian, d) 75 return buf.Bytes() 76 }