1 /* 2 * mass storage transport protocols and subclasses, 3 * from usb mass storage class specification overview rev 1.2 4 */ 5 6 typedef struct Umsc Umsc; 7 typedef struct Ums Ums; 8 typedef struct Cbw Cbw; /* command block wrapper */ 9 typedef struct Csw Csw; /* command status wrapper */ 10 11 enum 12 { 13 Protocbi = 0, /* control/bulk/interrupt; mainly floppies */ 14 Protocb = 1, /* " with no interrupt; mainly floppies */ 15 Protobulk = 0x50, /* bulk only */ 16 17 Subrbc = 1, /* reduced blk cmds */ 18 Subatapi = 2, /* cd/dvd using sff-8020i or mmc-2 cmd blks */ 19 Subqic = 3, /* QIC-157 tapes */ 20 Subufi = 4, /* floppy */ 21 Sub8070 = 5, /* removable media, atapi-like */ 22 Subscsi = 6, /* scsi transparent cmd set */ 23 Subisd200 = 7, /* ISD200 ATA */ 24 Subdev = 0xff, /* use device's value */ 25 26 Umsreset = 0xFF, 27 Getmaxlun = 0xFE, 28 29 // Maxlun = 256, 30 Maxlun = 32, 31 32 CMreset = 1, 33 34 Pcmd = 0, 35 Pdata, 36 Pstatus, 37 38 CbwLen = 31, 39 CbwDataIn = 0x80, 40 CbwDataOut = 0x00, 41 CswLen = 13, 42 CswOk = 0, 43 CswFailed = 1, 44 CswPhaseErr = 2, 45 }; 46 47 /* 48 * corresponds to a lun. 49 * these are ~600+Maxiosize bytes each; ScsiReq is not tiny. 50 */ 51 struct Umsc 52 { 53 ScsiReq; 54 uvlong blocks; 55 vlong capacity; 56 57 /* from setup */ 58 char *bufp; 59 long off; /* offset within a block */ 60 long nb; /* byte count */ 61 62 uchar rawcmd[16]; 63 uchar phase; 64 char *inq; 65 Ums *ums; 66 Usbfs fs; 67 char buf[Maxiosize]; 68 }; 69 70 struct Ums 71 { 72 QLock; 73 Dev *dev; 74 Dev *epin; 75 Dev *epout; 76 Umsc *lun; 77 uchar maxlun; 78 int seq; 79 int nerrs; 80 int wrongresidues; 81 }; 82 83 /* 84 * USB transparent SCSI devices 85 */ 86 struct Cbw 87 { 88 char signature[4]; /* "USBC" */ 89 long tag; 90 long datalen; 91 uchar flags; 92 uchar lun; 93 uchar len; 94 char command[16]; 95 }; 96 97 struct Csw 98 { 99 char signature[4]; /* "USBS" */ 100 long tag; 101 long dataresidue; 102 uchar status; 103 }; 104 105 106 int diskmain(Dev*, int, char**); 107