USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
masstorage.h
Go to the documentation of this file.
1 #if !defined(__MASSTORAGE_H__)
2 #define __MASSTORAGE_H__
3 
4 // Cruft removal, makes driver smaller, faster.
5 #ifndef MS_WANT_PARSER
6 #define MS_WANT_PARSER 0
7 #endif
8 
9 #include "Usb.h"
10 
11 #define bmREQ_MASSOUT USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
12 #define bmREQ_MASSIN USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_CLASS|USB_SETUP_RECIPIENT_INTERFACE
13 
14 // Mass Storage Subclass Constants
15 #define MASS_SUBCLASS_SCSI_NOT_REPORTED 0x00 // De facto use
16 #define MASS_SUBCLASS_RBC 0x01
17 #define MASS_SUBCLASS_ATAPI 0x02 // MMC-5 (ATAPI)
18 #define MASS_SUBCLASS_OBSOLETE1 0x03 // Was QIC-157
19 #define MASS_SUBCLASS_UFI 0x04 // Specifies how to interface Floppy Disk Drives to USB
20 #define MASS_SUBCLASS_OBSOLETE2 0x05 // Was SFF-8070i
21 #define MASS_SUBCLASS_SCSI 0x06 // SCSI Transparent Command Set
22 #define MASS_SUBCLASS_LSDFS 0x07 // Specifies how host has to negotiate access before trying SCSI
23 #define MASS_SUBCLASS_IEEE1667 0x08
24 
25 // Mass Storage Class Protocols
26 #define MASS_PROTO_CBI 0x00 // CBI (with command completion interrupt)
27 #define MASS_PROTO_CBI_NO_INT 0x01 // CBI (without command completion interrupt)
28 #define MASS_PROTO_OBSOLETE 0x02
29 #define MASS_PROTO_BBB 0x50 // Bulk Only Transport
30 #define MASS_PROTO_UAS 0x62
31 
32 // Request Codes
33 #define MASS_REQ_ADSC 0x00
34 #define MASS_REQ_GET 0xFC
35 #define MASS_REQ_PUT 0xFD
36 #define MASS_REQ_GET_MAX_LUN 0xFE
37 #define MASS_REQ_BOMSR 0xFF // Bulk-Only Mass Storage Reset
38 
39 #define MASS_CBW_SIGNATURE 0x43425355
40 #define MASS_CSW_SIGNATURE 0x53425355
41 
42 #define MASS_CMD_DIR_OUT 0 // (0 << 7)
43 #define MASS_CMD_DIR_IN 0x80 //(1 << 7)
44 
45 /*
46  * Reference documents from T10 (http://www.t10.org)
47  * SCSI Primary Commands - 3 (SPC-3)
48  * SCSI Block Commands - 2 (SBC-2)
49  * Multi-Media Commands - 5 (MMC-5)
50  */
51 
52 /* Group 1 commands (CDB's here are should all be 6-bytes) */
53 #define SCSI_CMD_TEST_UNIT_READY 0x00
54 #define SCSI_CMD_REQUEST_SENSE 0x03
55 #define SCSI_CMD_FORMAT_UNIT 0x04
56 #define SCSI_CMD_READ_6 0x08
57 #define SCSI_CMD_WRITE_6 0x0A
58 #define SCSI_CMD_INQUIRY 0x12
59 #define SCSI_CMD_MODE_SELECT_6 0x15
60 #define SCSI_CMD_MODE_SENSE_6 0x1A
61 #define SCSI_CMD_START_STOP_UNIT 0x1B
62 #define SCSI_CMD_PREVENT_REMOVAL 0x1E
63 /* Group 2 Commands (CDB's here are 10-bytes) */
64 #define SCSI_CMD_READ_FORMAT_CAPACITIES 0x23
65 #define SCSI_CMD_READ_CAPACITY_10 0x25
66 #define SCSI_CMD_READ_10 0x28
67 #define SCSI_CMD_WRITE_10 0x2A
68 #define SCSI_CMD_SEEK_10 0x2B
69 #define SCSI_CMD_ERASE_10 0x2C
70 #define SCSI_CMD_WRITE_AND_VERIFY_10 0x2E
71 #define SCSI_CMD_VERIFY_10 0x2F
72 #define SCSI_CMD_SYNCHRONIZE_CACHE 0x35
73 #define SCSI_CMD_WRITE_BUFFER 0x3B
74 #define SCSI_CMD_READ_BUFFER 0x3C
75 #define SCSI_CMD_READ_SUBCHANNEL 0x42
76 #define SCSI_CMD_READ_TOC 0x43
77 #define SCSI_CMD_READ_HEADER 0x44
78 #define SCSI_CMD_PLAY_AUDIO_10 0x45
79 #define SCSI_CMD_GET_CONFIGURATION 0x46
80 #define SCSI_CMD_PLAY_AUDIO_MSF 0x47
81 #define SCSI_CMD_PLAY_AUDIO_TI 0x48
82 #define SCSI_CMD_PLAY_TRACK_REL_10 0x49
83 #define SCSI_CMD_GET_EVENT_STATUS 0x4A
84 #define SCSI_CMD_PAUSE_RESUME 0x4B
85 #define SCSI_CMD_READ_DISC_INFORMATION 0x51
86 #define SCSI_CMD_READ_TRACK_INFORMATION 0x52
87 #define SCSI_CMD_RESERVE_TRACK 0x53
88 #define SCSI_CMD_SEND_OPC_INFORMATION 0x54
89 #define SCSI_CMD_MODE_SELECT_10 0x55
90 #define SCSI_CMD_REPAIR_TRACK 0x58
91 #define SCSI_CMD_MODE_SENSE_10 0x5A
92 #define SCSI_CMD_CLOSE_TRACK_SESSION 0x5B
93 #define SCSI_CMD_READ_BUFFER_CAPACITY 0x5C
94 #define SCSI_CMD_SEND_CUE_SHEET 0x5D
95 /* Group 5 Commands (CDB's here are 12-bytes) */
96 #define SCSI_CMD_REPORT_LUNS 0xA0
97 #define SCSI_CMD_BLANK 0xA1
98 #define SCSI_CMD_SECURITY_PROTOCOL_IN 0xA2
99 #define SCSI_CMD_SEND_KEY 0xA3
100 #define SCSI_CMD_REPORT_KEY 0xA4
101 #define SCSI_CMD_PLAY_AUDIO_12 0xA5
102 #define SCSI_CMD_LOAD_UNLOAD 0xA6
103 #define SCSI_CMD_SET_READ_AHEAD 0xA7
104 #define SCSI_CMD_READ_12 0xA8
105 #define SCSI_CMD_PLAY_TRACK_REL_12 0xA9
106 #define SCSI_CMD_WRITE_12 0xAA
107 #define SCSI_CMD_READ_MEDIA_SERIAL_12 0xAB
108 #define SCSI_CMD_GET_PERFORMANCE 0xAC
109 #define SCSI_CMD_READ_DVD_STRUCTURE 0xAD
110 #define SCSI_CMD_SECURITY_PROTOCOL_OUT 0xB5
111 #define SCSI_CMD_SET_STREAMING 0xB6
112 #define SCSI_CMD_READ_MSF 0xB9
113 #define SCSI_CMD_SET_SPEED 0xBB
114 #define SCSI_CMD_MECHANISM_STATUS 0xBD
115 #define SCSI_CMD_READ_CD 0xBE
116 #define SCSI_CMD_SEND_DISC_STRUCTURE 0xBF
117 /* Vendor-unique Commands, included for completeness */
118 #define SCSI_CMD_CD_PLAYBACK_STATUS 0xC4 /* SONY unique */
119 #define SCSI_CMD_PLAYBACK_CONTROL 0xC9 /* SONY unique */
120 #define SCSI_CMD_READ_CDDA 0xD8 /* Vendor unique */
121 #define SCSI_CMD_READ_CDXA 0xDB /* Vendor unique */
122 #define SCSI_CMD_READ_ALL_SUBCODES 0xDF /* Vendor unique */
123 
124 /* SCSI error codes */
125 #define SCSI_S_NOT_READY 0x02
126 #define SCSI_S_MEDIUM_ERROR 0x03
127 #define SCSI_S_ILLEGAL_REQUEST 0x05
128 #define SCSI_S_UNIT_ATTENTION 0x06
129 #define SCSI_ASC_LBA_OUT_OF_RANGE 0x21
130 #define SCSI_ASC_MEDIA_CHANGED 0x28
131 #define SCSI_ASC_MEDIUM_NOT_PRESENT 0x3A
132 
133 /* USB error codes */
134 #define MASS_ERR_SUCCESS 0x00
135 #define MASS_ERR_PHASE_ERROR 0x02
136 #define MASS_ERR_UNIT_NOT_READY 0x03
137 #define MASS_ERR_UNIT_BUSY 0x04
138 #define MASS_ERR_STALL 0x05
139 #define MASS_ERR_CMD_NOT_SUPPORTED 0x06
140 #define MASS_ERR_INVALID_CSW 0x07
141 #define MASS_ERR_NO_MEDIA 0x08
142 #define MASS_ERR_BAD_LBA 0x09
143 #define MASS_ERR_MEDIA_CHANGED 0x0A
144 #define MASS_ERR_DEVICE_DISCONNECTED 0x11
145 #define MASS_ERR_UNABLE_TO_RECOVER 0x12 // Reset recovery error
146 #define MASS_ERR_INVALID_LUN 0x13
147 #define MASS_ERR_WRITE_STALL 0x14
148 #define MASS_ERR_READ_NAKS 0x15
149 #define MASS_ERR_WRITE_NAKS 0x16
150 #define MASS_ERR_WRITE_PROTECTED 0x17
151 #define MASS_ERR_NOT_IMPLEMENTED 0xFD
152 #define MASS_ERR_GENERAL_SCSI_ERROR 0xFE
153 #define MASS_ERR_GENERAL_USB_ERROR 0xFF
154 #define MASS_ERR_USER 0xA0 // For subclasses to define their own error codes
155 
156 #define MASS_TRANS_FLG_CALLBACK 0x01 // Callback is involved
157 #define MASS_TRANS_FLG_NO_STALL_CHECK 0x02 // STALL condition is not checked
158 #define MASS_TRANS_FLG_NO_PHASE_CHECK 0x04 // PHASE_ERROR is not checked
159 
160 #define MASS_MAX_ENDPOINTS 3
161 
162 struct Capacity {
163  uint8_t data[8];
164  //uint32_t dwBlockAddress;
165  //uint32_t dwBlockLength;
166 } __attribute__((packed));
167 
168 struct BASICCDB {
169  uint8_t Opcode;
170 
171  unsigned unused : 5;
172  unsigned LUN : 3;
173 
174  uint8_t info[12];
175 } __attribute__((packed));
176 
178 
179 struct CDB6 {
180  uint8_t Opcode;
181 
182  unsigned LBAMSB : 5;
183  unsigned LUN : 3;
184 
185  uint8_t LBAHB;
186  uint8_t LBALB;
188  uint8_t Control;
189 
190 public:
191 
192  CDB6(uint8_t _Opcode, uint8_t _LUN, uint32_t LBA, uint8_t _AllocationLength, uint8_t _Control) :
193  Opcode(_Opcode), LBAMSB(BGRAB2(LBA) & 0x1f), LUN(_LUN), LBAHB(BGRAB1(LBA)), LBALB(BGRAB0(LBA)),
194  AllocationLength(_AllocationLength), Control(_Control) {
195  }
196 
197  CDB6(uint8_t _Opcode, uint8_t _LUN, uint8_t _AllocationLength, uint8_t _Control) :
198  Opcode(_Opcode), LBAMSB(0), LUN(_LUN), LBAHB(0), LBALB(0),
199  AllocationLength(_AllocationLength), Control(_Control) {
200  }
201 } __attribute__((packed));
202 
203 typedef CDB6 CDB6_t;
204 
205 struct CDB10 {
206  uint8_t Opcode;
207 
208  unsigned Service_Action : 5;
209  unsigned LUN : 3;
210 
211  uint8_t LBA_L_M_MB;
212  uint8_t LBA_L_M_LB;
213  uint8_t LBA_L_L_MB;
214  uint8_t LBA_L_L_LB;
215 
216  uint8_t Misc2;
217 
218  uint8_t ALC_MB;
219  uint8_t ALC_LB;
220 
221  uint8_t Control;
222 public:
223 
224  CDB10(uint8_t _Opcode, uint8_t _LUN) :
225  Opcode(_Opcode), Service_Action(0), LUN(_LUN),
227  Misc2(0), ALC_MB(0), ALC_LB(0), Control(0) {
228  }
229 
230  CDB10(uint8_t _Opcode, uint8_t _LUN, uint16_t xflen, uint32_t _LBA) :
231  Opcode(_Opcode), Service_Action(0), LUN(_LUN),
232  LBA_L_M_MB(BGRAB3(_LBA)), LBA_L_M_LB(BGRAB2(_LBA)), LBA_L_L_MB(BGRAB1(_LBA)), LBA_L_L_LB(BGRAB0(_LBA)),
233  Misc2(0), ALC_MB(BGRAB1(xflen)), ALC_LB(BGRAB0(xflen)), Control(0) {
234  }
235 } __attribute__((packed));
236 
237 typedef CDB10 CDB10_t;
238 
239 struct CDB12 {
240  uint8_t Opcode;
241 
242  unsigned Service_Action : 5;
243  unsigned Misc : 3;
244 
245  uint8_t LBA_L_M_LB;
246  uint8_t LBA_L_L_MB;
247  uint8_t LBA_L_L_LB;
248 
249  uint8_t ALC_M_LB;
250  uint8_t ALC_L_MB;
251  uint8_t ALC_L_LB;
252  uint8_t Control;
253 } __attribute__((packed));
254 
255 typedef CDB12 CDB12_t;
256 
257 struct CDB_LBA32_16 {
258  uint8_t Opcode;
259 
260  unsigned Service_Action : 5;
261  unsigned Misc : 3;
262 
263  uint8_t LBA_L_M_MB;
264  uint8_t LBA_L_M_LB;
265  uint8_t LBA_L_L_MB;
266  uint8_t LBA_L_L_LB;
267 
268  uint8_t A_M_M_MB;
269  uint8_t A_M_M_LB;
270  uint8_t A_M_L_MB;
271  uint8_t A_M_L_LB;
272 
273  uint8_t ALC_M_MB;
274  uint8_t ALC_M_LB;
275  uint8_t ALC_L_MB;
276  uint8_t ALC_L_LB;
277 
278  uint8_t Misc2;
279  uint8_t Control;
280 } __attribute__((packed));
281 
282 struct CDB_LBA64_16 {
283  uint8_t Opcode;
284  uint8_t Misc;
285 
286  uint8_t LBA_M_M_MB;
287  uint8_t LBA_M_M_LB;
288  uint8_t LBA_M_L_MB;
289  uint8_t LBA_M_L_LB;
290 
291  uint8_t LBA_L_M_MB;
292  uint8_t LBA_L_M_LB;
293  uint8_t LBA_L_L_MB;
294  uint8_t LBA_L_L_LB;
295 
296  uint8_t ALC_M_MB;
297  uint8_t ALC_M_LB;
298  uint8_t ALC_L_MB;
299  uint8_t ALC_L_LB;
300 
301  uint8_t Misc2;
302  uint8_t Control;
303 } __attribute__((packed));
304 
306  uint8_t DeviceType : 5;
307  uint8_t PeripheralQualifier : 3;
308 
309  unsigned Reserved : 7;
310  unsigned Removable : 1;
311 
312  uint8_t Version;
313 
314  unsigned ResponseDataFormat : 4;
315  unsigned HISUP : 1;
316  unsigned NormACA : 1;
317  unsigned TrmTsk : 1;
318  unsigned AERC : 1;
319 
321  //uint8_t Reserved3[2];
322 
323  unsigned PROTECT : 1;
324  unsigned Res : 2;
325  unsigned ThreePC : 1;
326  unsigned TPGS : 2;
327  unsigned ACC : 1;
328  unsigned SCCS : 1;
329 
330  unsigned ADDR16 : 1;
331  unsigned R1 : 1;
332  unsigned R2 : 1;
333  unsigned MCHNGR : 1;
334  unsigned MULTIP : 1;
335  unsigned VS : 1;
336  unsigned ENCSERV : 1;
337  unsigned BQUE : 1;
338 
339  unsigned SoftReset : 1;
340  unsigned CmdQue : 1;
341  unsigned Reserved4 : 1;
342  unsigned Linked : 1;
343  unsigned Sync : 1;
344  unsigned WideBus16Bit : 1;
345  unsigned WideBus32Bit : 1;
346  unsigned RelAddr : 1;
347 
348  uint8_t VendorID[8];
349  uint8_t ProductID[16];
350  uint8_t RevisionID[4];
351 } __attribute__((packed));
352 
354  uint32_t dCBWSignature;
355  uint32_t dCBWTag;
357  uint8_t bmCBWFlags;
358 public:
359 
361  }
362 
363  CommandBlockWrapperBase(uint32_t tag, uint32_t xflen, uint8_t flgs) :
365  }
366 } __attribute__((packed));
367 
369 
370  struct {
371  uint8_t bmCBWLUN : 4;
372  uint8_t bmReserved1 : 4;
373  };
374 
375  struct {
376  uint8_t bmCBWCBLength : 4;
377  uint8_t bmReserved2 : 4;
378  };
379 
380  uint8_t CBWCB[16];
381 
382 public:
383  // All zeroed.
384 
387  for(int i = 0; i < 16; i++) CBWCB[i] = 0;
388  }
389 
390  // Generic Wrap, CDB zeroed.
391 
392  CommandBlockWrapper(uint32_t tag, uint32_t xflen, uint8_t flgs, uint8_t lu, uint8_t cmdlen, uint8_t cmd) :
393  CommandBlockWrapperBase(tag, xflen, flgs),
394  bmCBWLUN(lu), bmReserved1(0), bmCBWCBLength(cmdlen), bmReserved2(0) {
395  for(int i = 0; i < 16; i++) CBWCB[i] = 0;
396  // Type punning can cause optimization problems and bugs.
397  // Using reinterpret_cast to a dreinterpretifferent object is the proper way to do this.
398  //(((BASICCDB_t *) CBWCB)->LUN) = cmd;
399  BASICCDB_t *x = reinterpret_cast<BASICCDB_t *>(CBWCB);
400  x->LUN = cmd;
401  }
402 
403  // Wrap for CDB of 6
404 
405  CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB6_t *cdb, uint8_t dir) :
406  CommandBlockWrapperBase(tag, xflen, dir),
407  bmCBWLUN(cdb->LUN), bmReserved1(0), bmCBWCBLength(6), bmReserved2(0) {
408  memcpy(&CBWCB, cdb, 6);
409  }
410  // Wrap for CDB of 10
411 
412  CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB10_t *cdb, uint8_t dir) :
413  CommandBlockWrapperBase(tag, xflen, dir),
414  bmCBWLUN(cdb->LUN), bmReserved1(0), bmCBWCBLength(10), bmReserved2(0) {
415  memcpy(&CBWCB, cdb, 10);
416  }
417 } __attribute__((packed));
418 
420  uint32_t dCSWSignature;
421  uint32_t dCSWTag;
422  uint32_t dCSWDataResidue;
423  uint8_t bCSWStatus;
424 } __attribute__((packed));
425 
427  uint8_t bResponseCode;
428  uint8_t bSegmentNumber;
429 
430  uint8_t bmSenseKey : 4;
431  uint8_t bmReserved : 1;
432  uint8_t bmILI : 1;
433  uint8_t bmEOM : 1;
434  uint8_t bmFileMark : 1;
435 
436  uint8_t Information[4];
442  uint8_t SenseKeySpecific[3];
443 } __attribute__((packed));
444 
446 protected:
447  static const uint8_t epDataInIndex; // DataIn endpoint index
448  static const uint8_t epDataOutIndex; // DataOUT endpoint index
449  static const uint8_t epInterruptInIndex; // InterruptIN endpoint index
450 
452  uint8_t bAddress;
453  uint8_t bConfNum; // configuration number
454  uint8_t bIface; // interface value
455  uint8_t bNumEP; // total number of EP in the configuration
456  uint32_t qNextPollTime; // next poll time
457  bool bPollEnable; // poll enable flag
458 
460 
461  uint32_t dCBWTag; // Tag
462  //uint32_t dCBWDataTransferLength; // Data Transfer Length
463  uint8_t bLastUsbError; // Last USB error
464  uint8_t bMaxLUN; // Max LUN
465  uint8_t bTheLUN; // Active LUN
466  uint32_t CurrentCapacity[MASS_MAX_SUPPORTED_LUN]; // Total sectors
467  uint16_t CurrentSectorSize[MASS_MAX_SUPPORTED_LUN]; // Sector size, clipped to 16 bits
468  bool LUNOk[MASS_MAX_SUPPORTED_LUN]; // use this to check for media changes.
471 
472 
473  // Additional Initialization Method for Subclasses
474 
475  virtual uint8_t OnInit() {
476  return 0;
477  };
478 public:
479  BulkOnly(USB *p);
480 
481  uint8_t GetLastUsbError() {
482  return bLastUsbError;
483  };
484 
485  uint8_t GetbMaxLUN() {
486  return bMaxLUN; // Max LUN
487  }
488 
489  uint8_t GetbTheLUN() {
490  return bTheLUN; // Active LUN
491  }
492 
493  boolean WriteProtected(uint8_t lun);
494  uint8_t MediaCTL(uint8_t lun, uint8_t ctl);
495  uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf);
496  uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, USBReadParser *prs);
497  uint8_t Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t *buf);
498  uint8_t LockMedia(uint8_t lun, uint8_t lock);
499 
500  bool LUNIsGood(uint8_t lun);
501  uint32_t GetCapacity(uint8_t lun);
502  uint16_t GetSectorSize(uint8_t lun);
503 
504  // USBDeviceConfig implementation
505  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
506  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
507 
508  virtual uint8_t Release();
509  virtual uint8_t Poll();
510 
511  virtual uint8_t GetAddress() {
512  return bAddress;
513  };
514 
515  // UsbConfigXtracter implementation
516  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
517 
518  virtual boolean DEVCLASSOK(uint8_t klass) {
519  return (klass == USB_CLASS_MASS_STORAGE);
520  }
521 
522  uint8_t SCSITransaction6(CDB6_t *cdb, uint16_t buf_size, void *buf, uint8_t dir);
523  uint8_t SCSITransaction10(CDB10_t *cdb, uint16_t buf_size, void *buf, uint8_t dir);
524 
525 private:
526  uint8_t Inquiry(uint8_t lun, uint16_t size, uint8_t *buf);
527  uint8_t TestUnitReady(uint8_t lun);
528  uint8_t RequestSense(uint8_t lun, uint16_t size, uint8_t *buf);
529  uint8_t ModeSense6(uint8_t lun, uint8_t pc, uint8_t page, uint8_t subpage, uint8_t len, uint8_t *buf);
530  uint8_t GetMaxLUN(uint8_t *max_lun);
531  uint8_t SetCurLUN(uint8_t lun);
532  void Reset();
533  uint8_t ResetRecovery();
534  uint8_t ReadCapacity10(uint8_t lun, uint8_t *buf);
535  void ClearAllEP();
536  void CheckMedia();
537  boolean CheckLUN(uint8_t lun);
538  uint8_t Page3F(uint8_t lun);
539  bool IsValidCBW(uint8_t size, uint8_t *pcbw);
540  bool IsMeaningfulCBW(uint8_t size, uint8_t *pcbw);
541 
542  bool IsValidCSW(CommandStatusWrapper *pcsw, CommandBlockWrapperBase *pcbw);
543 
544  uint8_t ClearEpHalt(uint8_t index);
545 #if MS_WANT_PARSER
546  uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf, uint8_t flags);
547 #endif
548  uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf);
549  uint8_t HandleUsbError(uint8_t error, uint8_t index);
550  uint8_t HandleSCSIError(uint8_t status);
551 
552 };
553 
554 #endif // __MASSTORAGE_H__
unsigned BQUE
Definition: masstorage.h:337
uint8_t MediaCTL(uint8_t lun, uint8_t ctl)
Definition: masstorage.cpp:113
uint8_t Misc2
Definition: masstorage.h:216
CDB10(uint8_t _Opcode, uint8_t _LUN)
Definition: masstorage.h:224
uint8_t VendorID[8]
Definition: masstorage.h:348
static const uint8_t epDataOutIndex
Definition: masstorage.h:448
uint8_t LBA_L_L_MB
Definition: masstorage.h:246
unsigned HISUP
Definition: masstorage.h:315
unsigned RelAddr
Definition: masstorage.h:346
uint8_t Misc2
Definition: masstorage.h:278
unsigned Removable
Definition: masstorage.h:310
bool LUNOk[MASS_MAX_SUPPORTED_LUN]
Definition: masstorage.h:468
uint8_t LBALB
Definition: masstorage.h:186
unsigned LUN
Definition: masstorage.h:172
uint8_t CBWCB[16]
Definition: masstorage.h:380
uint8_t LBA_L_L_LB
Definition: masstorage.h:266
unsigned NormACA
Definition: masstorage.h:316
static const uint8_t epInterruptInIndex
Definition: masstorage.h:449
CDB10 CDB10_t
Definition: masstorage.h:237
uint8_t bAdditionalLength
Definition: masstorage.h:437
#define USB_CLASS_MASS_STORAGE
Definition: UsbCore.h:47
uint8_t ALC_LB
Definition: masstorage.h:219
uint32_t dCSWDataResidue
Definition: masstorage.h:422
CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB10_t *cdb, uint8_t dir)
Definition: masstorage.h:412
uint8_t LBA_L_M_LB
Definition: masstorage.h:212
uint8_t LBA_L_L_MB
Definition: masstorage.h:293
uint8_t bAddress
Definition: masstorage.h:452
uint8_t LBAHB
Definition: masstorage.h:185
unsigned Service_Action
Definition: masstorage.h:208
uint8_t LBA_L_M_LB
Definition: masstorage.h:264
uint8_t AllocationLength
Definition: masstorage.h:187
unsigned AERC
Definition: masstorage.h:318
uint32_t dCBWTag
Definition: masstorage.h:461
unsigned TPGS
Definition: masstorage.h:326
uint8_t bConfNum
Definition: masstorage.h:453
uint8_t Control
Definition: masstorage.h:188
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: masstorage.cpp:234
unsigned Service_Action
Definition: masstorage.h:242
#define BGRAB0(__usi__)
Definition: macros.h:39
unsigned CmdQue
Definition: masstorage.h:340
uint32_t CurrentCapacity[MASS_MAX_SUPPORTED_LUN]
Definition: masstorage.h:466
virtual uint8_t Poll()
Definition: masstorage.cpp:636
uint8_t LBA_L_L_LB
Definition: masstorage.h:294
uint8_t ProductID[16]
Definition: masstorage.h:349
bool WriteOk[MASS_MAX_SUPPORTED_LUN]
Definition: masstorage.h:469
#define MASS_MAX_SUPPORTED_LUN
Definition: settings.h:54
uint8_t LBA_M_L_LB
Definition: masstorage.h:289
uint8_t SCSITransaction10(CDB10_t *cdb, uint16_t buf_size, void *buf, uint8_t dir)
Definition: masstorage.cpp:82
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
virtual uint8_t Release()
Definition: masstorage.cpp:558
uint8_t Control
Definition: masstorage.h:279
uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf)
Definition: masstorage.cpp:137
unsigned Service_Action
Definition: masstorage.h:260
uint32_t dCBWDataTransferLength
Definition: masstorage.h:356
uint8_t SCSITransaction6(CDB6_t *cdb, uint16_t buf_size, void *buf, uint8_t dir)
Definition: masstorage.cpp:66
uint8_t AdditionalLength
Definition: masstorage.h:320
uint8_t RevisionID[4]
Definition: masstorage.h:350
uint8_t GetLastUsbError()
Definition: masstorage.h:481
uint32_t GetCapacity(uint8_t lun)
Definition: masstorage.cpp:19
CommandBlockWrapperBase(uint32_t tag, uint32_t xflen, uint8_t flgs)
Definition: masstorage.h:363
uint8_t Opcode
Definition: masstorage.h:169
unsigned ThreePC
Definition: masstorage.h:325
uint8_t LBA_L_L_LB
Definition: masstorage.h:214
uint8_t ALC_M_MB
Definition: masstorage.h:296
uint8_t ALC_M_LB
Definition: masstorage.h:274
CDB12 CDB12_t
Definition: masstorage.h:255
uint8_t bFieldReplaceableUnitCode
Definition: masstorage.h:441
uint8_t Control
Definition: masstorage.h:302
uint8_t bLastUsbError
Definition: masstorage.h:463
uint8_t ALC_M_MB
Definition: masstorage.h:273
unsigned ResponseDataFormat
Definition: masstorage.h:314
BASICCDB BASICCDB_t
Definition: masstorage.h:177
uint8_t GetbMaxLUN()
Definition: masstorage.h:485
static const uint8_t epDataInIndex
Definition: masstorage.h:447
uint8_t PeripheralQualifier
Definition: masstorage.h:307
uint16_t CurrentSectorSize[MASS_MAX_SUPPORTED_LUN]
Definition: masstorage.h:467
uint8_t Control
Definition: masstorage.h:252
unsigned LBAMSB
Definition: masstorage.h:182
#define MASS_MAX_ENDPOINTS
Definition: masstorage.h:160
uint8_t bAdditionalSenseCode
Definition: masstorage.h:439
unsigned Reserved4
Definition: masstorage.h:341
virtual uint8_t OnInit()
Definition: masstorage.h:475
uint32_t qNextPollTime
Definition: masstorage.h:456
bool LUNIsGood(uint8_t lun)
Definition: masstorage.cpp:43
uint8_t LBA_L_M_MB
Definition: masstorage.h:211
uint8_t LBA_M_M_LB
Definition: masstorage.h:287
uint8_t LBA_L_M_MB
Definition: masstorage.h:291
unsigned LUN
Definition: masstorage.h:183
unsigned unused
Definition: masstorage.h:171
virtual uint8_t GetAddress()
Definition: masstorage.h:511
Definition: address.h:32
unsigned Res
Definition: masstorage.h:324
uint8_t bAdditionalSenseQualifier
Definition: masstorage.h:440
uint16_t GetSectorSize(uint8_t lun)
Definition: masstorage.cpp:31
unsigned Linked
Definition: masstorage.h:342
uint8_t ALC_L_MB
Definition: masstorage.h:298
uint8_t ALC_L_MB
Definition: masstorage.h:250
uint8_t Information[4]
Definition: masstorage.h:436
uint8_t A_M_L_MB
Definition: masstorage.h:270
bool bPollEnable
Definition: masstorage.h:457
uint8_t A_M_L_LB
Definition: masstorage.h:271
uint8_t LockMedia(uint8_t lun, uint8_t lock)
Definition: masstorage.cpp:97
uint8_t ALC_M_LB
Definition: masstorage.h:297
uint8_t Opcode
Definition: masstorage.h:206
uint8_t ALC_MB
Definition: masstorage.h:218
uint8_t Misc
Definition: masstorage.h:284
CDB6 CDB6_t
Definition: masstorage.h:203
EpInfo epInfo[MASS_MAX_ENDPOINTS]
Definition: masstorage.h:459
uint8_t ALC_L_LB
Definition: masstorage.h:299
uint8_t LBA_L_M_MB
Definition: masstorage.h:263
unsigned LUN
Definition: masstorage.h:209
unsigned SCCS
Definition: masstorage.h:328
uint8_t LBA_L_L_MB
Definition: masstorage.h:213
uint8_t bTheLUN
Definition: masstorage.h:465
uint8_t CmdSpecificInformation[4]
Definition: masstorage.h:438
BulkOnly(USB *p)
Definition: masstorage.cpp:205
unsigned ENCSERV
Definition: masstorage.h:336
CDB6(uint8_t _Opcode, uint8_t _LUN, uint32_t LBA, uint8_t _AllocationLength, uint8_t _Control)
Definition: masstorage.h:192
uint8_t LBA_M_L_MB
Definition: masstorage.h:288
uint8_t ALC_M_LB
Definition: masstorage.h:249
CDB10(uint8_t _Opcode, uint8_t _LUN, uint16_t xflen, uint32_t _LBA)
Definition: masstorage.h:230
uint8_t ALC_L_LB
Definition: masstorage.h:276
uint8_t Opcode
Definition: masstorage.h:240
CommandBlockWrapper(uint32_t tag, uint32_t xflen, uint8_t flgs, uint8_t lu, uint8_t cmdlen, uint8_t cmd)
Definition: masstorage.h:392
uint8_t Misc2
Definition: masstorage.h:301
uint8_t DeviceType
Definition: masstorage.h:306
uint8_t bIface
Definition: masstorage.h:454
CommandBlockWrapper(uint32_t tag, uint32_t xflen, CDB6_t *cdb, uint8_t dir)
Definition: masstorage.h:405
unsigned PROTECT
Definition: masstorage.h:323
unsigned Sync
Definition: masstorage.h:343
uint8_t bMaxLUN
Definition: masstorage.h:464
uint8_t LBA_L_L_MB
Definition: masstorage.h:265
uint8_t Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t *buf)
Definition: masstorage.cpp:171
uint8_t ALC_L_LB
Definition: masstorage.h:251
unsigned ADDR16
Definition: masstorage.h:330
uint8_t A_M_M_LB
Definition: masstorage.h:269
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: masstorage.cpp:526
unsigned Reserved
Definition: masstorage.h:309
unsigned MCHNGR
Definition: masstorage.h:333
unsigned MULTIP
Definition: masstorage.h:334
uint8_t info[12]
Definition: masstorage.h:174
uint8_t LBA_M_M_MB
Definition: masstorage.h:286
#define BGRAB2(__usi__)
Definition: macros.h:41
uint8_t LBA_L_M_LB
Definition: masstorage.h:292
Definition: UsbCore.h:176
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: masstorage.cpp:309
unsigned Misc
Definition: masstorage.h:243
uint8_t SenseKeySpecific[3]
Definition: masstorage.h:442
uint8_t data[8]
Definition: masstorage.h:163
boolean WriteProtected(uint8_t lun)
Definition: masstorage.cpp:53
#define BGRAB3(__usi__)
Definition: macros.h:42
uint8_t A_M_M_MB
Definition: masstorage.h:268
uint32_t dCSWSignature
Definition: masstorage.h:420
uint8_t Control
Definition: masstorage.h:221
uint8_t Opcode
Definition: masstorage.h:180
unsigned Misc
Definition: masstorage.h:261
unsigned WideBus32Bit
Definition: masstorage.h:345
uint8_t Version
Definition: masstorage.h:312
#define MASS_CBW_SIGNATURE
Definition: masstorage.h:39
unsigned SoftReset
Definition: masstorage.h:339
virtual boolean DEVCLASSOK(uint8_t klass)
Definition: masstorage.h:518
CDB6(uint8_t _Opcode, uint8_t _LUN, uint8_t _AllocationLength, uint8_t _Control)
Definition: masstorage.h:197
unsigned TrmTsk
Definition: masstorage.h:317
#define BGRAB1(__usi__)
Definition: macros.h:40
uint8_t bNumEP
Definition: masstorage.h:455
USB * pUsb
Definition: masstorage.h:451
uint8_t LBA_L_M_LB
Definition: masstorage.h:245
uint8_t Opcode
Definition: masstorage.h:283
uint8_t ALC_L_MB
Definition: masstorage.h:275
unsigned WideBus16Bit
Definition: masstorage.h:344
uint8_t LBA_L_L_LB
Definition: masstorage.h:247
unsigned ACC
Definition: masstorage.h:327
uint8_t Opcode
Definition: masstorage.h:258
uint8_t GetbTheLUN()
Definition: masstorage.h:489