forked from PaulStoffregen/USBHost_t36
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMassStorageDriver.cpp
596 lines (548 loc) · 19.2 KB
/
MassStorageDriver.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
/* MSC Teensy36 USB Host Mass Storage library
* Copyright (c) 2017-2019 Warren Watson.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
//MassStorageDriver.cpp
#include <Arduino.h>
#include "USBHost_t36.h" // Read this header first for key info
#define print USBHost::print_
#define println USBHost::println_
// Uncomment this to display function usage and sequencing.
//#define DBGprint 1
// Big Endian/Little Endian
#define swap32(x) ((x >> 24) & 0xff) | \
((x << 8) & 0xff0000) | \
((x >> 8) & 0xff00) | \
((x << 24) & 0xff000000)
void msController::init()
{
contribute_Pipes(mypipes, sizeof(mypipes)/sizeof(Pipe_t));
contribute_Transfers(mytransfers, sizeof(mytransfers)/sizeof(Transfer_t));
contribute_String_Buffers(mystring_bufs, sizeof(mystring_bufs)/sizeof(strbuf_t));
driver_ready_for_device(this);
}
bool msController::claim(Device_t *dev, int type, const uint8_t *descriptors, uint32_t len)
{
println("msController claim this=", (uint32_t)this, HEX);
// only claim at interface level
if (type != 1) return false;
if (len < 9+7+7) return false; // Interface descriptor + 2 endpoint decriptors
print_hexbytes(descriptors, len);
uint32_t numendpoint = descriptors[4];
if (numendpoint < 1) return false;
if (descriptors[5] != 8) return false; // bInterfaceClass, 8 = MASS Storage class
if (descriptors[6] != 6) return false; // bInterfaceSubClass, 6 = SCSI transparent command set (SCSI Standards)
if (descriptors[7] != 80) return false; // bInterfaceProtocol, 80 = BULK-ONLY TRANSPORT
uint8_t desc_index = 9;
uint8_t in_index = 0xff, out_index = 0xff;
println("numendpoint=", numendpoint, HEX);
while (numendpoint--) {
if ((descriptors[desc_index] != 7) || (descriptors[desc_index+1] != 5)) return false; // not an end point
if (descriptors[desc_index+3] == 2) { // Bulk end point
if (descriptors[desc_index+2] & 0x80)
in_index = desc_index;
else
out_index = desc_index;
}
desc_index += 7; // point to next one...
}
if ((in_index == 0xff) || (out_index == 0xff)) return false; // did not find end point
endpointIn = descriptors[in_index+2]; // bulk-in descriptor 1 81h
endpointOut = descriptors[out_index+2]; // bulk-out descriptor 2 02h
println("endpointIn=", endpointIn, HEX);
println("endpointOut=", endpointOut, HEX);
uint32_t sizeIn = descriptors[in_index+4] | (descriptors[in_index+5] << 8);
println("packet size in (msController) = ", sizeIn);
uint32_t sizeOut = descriptors[out_index+4] | (descriptors[out_index+5] << 8);
println("packet size out (msController) = ", sizeOut);
packetSizeIn = sizeIn;
packetSizeOut = sizeOut;
uint32_t intervalIn = descriptors[in_index+6];
uint32_t intervalOut = descriptors[out_index+6];
println("polling intervalIn = ", intervalIn);
println("polling intervalOut = ", intervalOut);
datapipeIn = new_Pipe(dev, 2, endpointIn, 1, packetSizeIn, intervalIn);
datapipeOut = new_Pipe(dev, 2, endpointOut, 0, packetSizeOut, intervalOut);
datapipeIn->callback_function = callbackIn;
datapipeOut->callback_function = callbackOut;
idVendor = dev->idVendor;
idProduct = dev->idProduct;
hubNumber = dev->hub_address;
deviceAddress = dev->address;
hubPort = dev->hub_port; // Used for device ID with multiple drives.
msOutCompleted = false;
msInCompleted = false;
msControlCompleted = false;
deviceAvailable = true;
msDriveInfo.initialized = false;
msDriveInfo.connected = true;
#ifdef DBGprint
Serial.printf(" connected %d\n",msDriveInfo.connected);
Serial.printf(" initialized %d\n",msDriveInfo.initialized);
#endif
return true;
}
void msController::disconnect()
{
deviceAvailable = false;
println("Device Disconnected...");
msDriveInfo.connected = false;
msDriveInfo.initialized = false;
memset(&msDriveInfo, 0, sizeof(msDriveInfo_t));
#ifdef DBGprint
Serial.printf(" connected %d\n",msDriveInfo.connected);
Serial.printf(" initialized %d\n",msDriveInfo.initialized);
#endif
}
void msController::control(const Transfer_t *transfer)
{
println("control CallbackIn (msController)");
print_hexbytes(report, 8);
msControlCompleted = true;
}
void msController::callbackIn(const Transfer_t *transfer)
{
println("msController CallbackIn (static)");
if (transfer->driver) {
print("transfer->qtd.token = ");
println(transfer->qtd.token & 255);
((msController *)(transfer->driver))->new_dataIn(transfer);
}
}
void msController::callbackOut(const Transfer_t *transfer)
{
println("msController CallbackOut (static)");
if (transfer->driver) {
print("transfer->qtd.token = ");
println(transfer->qtd.token & 255);
((msController *)(transfer->driver))->new_dataOut(transfer);
}
}
void msController::new_dataOut(const Transfer_t *transfer)
{
uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);
println("msController dataOut (static)", len, DEC);
print_hexbytes((uint8_t*)transfer->buffer, (len < 32)? len : 32 );
msOutCompleted = true; // Last out transaction is completed.
}
void msController::new_dataIn(const Transfer_t *transfer)
{
uint32_t len = transfer->length - ((transfer->qtd.token >> 16) & 0x7FFF);
println("msController dataIn (static): ", len, DEC);
print_hexbytes((uint8_t*)transfer->buffer, (len < 32)? len : 32 );
msInCompleted = true; // Last in transaction is completed.
}
// Initialize Mass Storage Device
uint8_t msController::mscInit(void) {
#ifdef DBGprint
Serial.printf("mscIint()\n");
#endif
uint8_t msResult = MS_CBW_PASS;
CBWTag = 0;
uint32_t start = millis();
// Check if device is connected.
do {
if((millis() - start) >= MSC_CONNECT_TIMEOUT) {
return MS_NO_MEDIA_ERR; // Not connected Error.
}
yield();
} while(!available());
msReset();
delay(500);
maxLUN = msGetMaxLun();
// msResult = msReportLUNs(&maxLUN);
//Serial.printf("maxLUN = %d\n",maxLUN);
// delay(150);
//-------------------------------------------------------
// msResult = msStartStopUnit(1);
msResult = WaitMediaReady();
if(msResult)
return msResult;
// Retrieve drive information.
msDriveInfo.initialized = true;
msDriveInfo.hubNumber = getHubNumber(); // Which HUB.
msDriveInfo.hubPort = getHubPort(); // Which HUB port.
msDriveInfo.deviceAddress = getDeviceAddress(); // Device addreess.
msDriveInfo.idVendor = getIDVendor(); // USB Vendor ID.
msDriveInfo.idProduct = getIDProduct(); // USB Product ID.
msResult = msDeviceInquiry(&msInquiry); // Config Info.
if(msResult)
return msResult;
msResult = msReadDeviceCapacity(&msCapacity); // Size Info.
if(msResult)
return msResult;
memcpy(&msDriveInfo.inquiry, &msInquiry, sizeof(msInquiryResponse_t));
memcpy(&msDriveInfo.capacity, &msCapacity, sizeof(msSCSICapacity_t));
return msResult;
}
//---------------------------------------------------------------------------
// Perform Mass Storage Reset
void msController::msReset() {
#ifdef DBGprint
Serial.printf("msReset()\n");
#endif
mk_setup(setup, 0x21, 0xff, 0, 0, 0);
queue_Control_Transfer(device, &setup, NULL, this);
while (!msControlCompleted) yield();
msControlCompleted = false;
}
//---------------------------------------------------------------------------
// Get MAX LUN
uint8_t msController::msGetMaxLun() {
#ifdef DBGprint
Serial.printf("msGetMaxLun()\n");
#endif
report[0] = 0;
mk_setup(setup, 0xa1, 0xfe, 0, 0, 1);
queue_Control_Transfer(device, &setup, report, this);
while (!msControlCompleted) yield();
msControlCompleted = false;
maxLUN = report[0];
return maxLUN;
}
uint8_t msController::WaitMediaReady() {
uint8_t msResult;
uint32_t start = millis();
#ifdef DBGprint
Serial.printf("WaitMediaReady()\n");
#endif
do {
if((millis() - start) >= MEDIA_READY_TIMEOUT) {
return MS_UNIT_NOT_READY; // Not Ready Error.
}
msResult = msTestReady();
yield();
} while(msResult == 1);
return msResult;
}
// Check if drive is connected and Initialized.
uint8_t msController::checkConnectedInitialized(void) {
uint8_t msResult = MS_CBW_PASS;
#ifdef DBGprint
Serial.printf("checkConnectedInitialized()\n");
#endif
if(!msDriveInfo.connected) {
return MS_NO_MEDIA_ERR;
}
if(!msDriveInfo.initialized) {
msResult = mscInit();
if(msResult != MS_CBW_PASS) return MS_UNIT_NOT_READY; // Not Initialized
}
return MS_CBW_PASS;
}
//---------------------------------------------------------------------------
// Send SCSI Command
// Do a complete 3 stage transfer.
uint8_t msController::msDoCommand(msCommandBlockWrapper_t *CBW, void *buffer)
{
uint8_t CSWResult = 0;
mscTransferComplete = false;
#ifdef DBGprint
Serial.printf("msDoCommand():\n");
#endif
if(CBWTag == 0xFFFFFFFF) CBWTag = 1;
queue_Data_Transfer(datapipeOut, CBW, sizeof(msCommandBlockWrapper_t), this); // Command stage.
while(!msOutCompleted) yield();
msOutCompleted = false;
if((CBW->Flags == CMD_DIR_DATA_IN)) { // Data stage from device.
queue_Data_Transfer(datapipeIn, buffer, CBW->TransferLength, this);
while(!msInCompleted) yield();
msInCompleted = false;
} else { // Data stage to device.
queue_Data_Transfer(datapipeOut, buffer, CBW->TransferLength, this);
while(!msOutCompleted) yield();
msOutCompleted = false;
}
CSWResult = msGetCSW(); // Status stage.
// All stages of this transfer have completed.
//Check for special cases.
//If test for unit ready command is given then
// return the CSW status byte.
//Bit 0 == 1 == not ready else
//Bit 0 == 0 == ready.
//And the Start/Stop Unit command as well.
if((CBW->CommandData[0] == CMD_TEST_UNIT_READY) ||
(CBW->CommandData[0] == CMD_START_STOP_UNIT))
return CSWResult;
else // Process possible SCSI errors.
return msProcessError(CSWResult);
}
//---------------------------------------------------------------------------
// Get Command Status Wrapper
uint8_t msController::msGetCSW(void) {
#ifdef DBGprint
Serial.printf("msGetCSW()\n");
#endif
msCommandStatusWrapper_t StatusBlockWrapper = (msCommandStatusWrapper_t)
{
.Signature = CSW_SIGNATURE,
.Tag = 0,
.DataResidue = 0, // TODO: Proccess this if received.
.Status = 0
};
queue_Data_Transfer(datapipeIn, &StatusBlockWrapper, sizeof(StatusBlockWrapper), this);
while(!msInCompleted) yield();
msInCompleted = false;
mscTransferComplete = true;
if(StatusBlockWrapper.Signature != CSW_SIGNATURE) return msProcessError(MS_CSW_SIG_ERROR); // Signature error
if(StatusBlockWrapper.Tag != CBWTag) return msProcessError(MS_CSW_TAG_ERROR); // Tag mismatch error
return StatusBlockWrapper.Status;
}
//---------------------------------------------------------------------------
// Test Unit Ready
uint8_t msController::msTestReady() {
#ifdef DBGprint
Serial.printf("msTestReady()\n");
#endif
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = 0,
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 6,
.CommandData = {CMD_TEST_UNIT_READY, 0x00, 0x00, 0x00, 0x00, 0x00}
};
queue_Data_Transfer(datapipeOut, &CommandBlockWrapper, sizeof(CommandBlockWrapper), this);
while(!msOutCompleted) yield();
msOutCompleted = false;
return msGetCSW();
}
//---------------------------------------------------------------------------
// Start/Stop unit
uint8_t msController::msStartStopUnit(uint8_t mode) {
#ifdef DBGprint
Serial.printf("msStartStopUnit()\n");
#endif
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = 0,
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 6,
.CommandData = {CMD_START_STOP_UNIT, 0x01, 0x00, 0x00, mode, 0x00}
};
queue_Data_Transfer(datapipeOut, &CommandBlockWrapper, sizeof(CommandBlockWrapper), this);
while(!msOutCompleted) yield();
msOutCompleted = false;
return msGetCSW();
}
//---------------------------------------------------------------------------
// Read Mass Storage Device Capacity (Number of Blocks and Block Size)
uint8_t msController::msReadDeviceCapacity(msSCSICapacity_t * const Capacity) {
#ifdef DBGprint
Serial.printf("msReadDeviceCapacity()\n");
#endif
uint8_t result = 0;
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = sizeof(msSCSICapacity_t),
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 10,
.CommandData = {CMD_RD_CAPACITY_10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}
};
result = msDoCommand(&CommandBlockWrapper, Capacity);
Capacity->Blocks = swap32(Capacity->Blocks);
Capacity->BlockSize = swap32(Capacity->BlockSize);
return result;
}
//---------------------------------------------------------------------------
// Do Mass Storage Device Inquiry
uint8_t msController::msDeviceInquiry(msInquiryResponse_t * const Inquiry)
{
#ifdef DBGprint
Serial.printf("msDeviceInquiry()\n");
#endif
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = sizeof(msInquiryResponse_t),
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 6,
.CommandData = {CMD_INQUIRY,0x00,0x00,0x00,sizeof(msInquiryResponse_t),0x00}
};
return msDoCommand(&CommandBlockWrapper, Inquiry);
}
//---------------------------------------------------------------------------
// Request Sense Data
uint8_t msController::msRequestSense(msRequestSenseResponse_t * const Sense)
{
#ifdef DBGprint
Serial.printf("msRequestSense()\n");
#endif
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = sizeof(msRequestSenseResponse_t),
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 6,
.CommandData = {CMD_REQUEST_SENSE, 0x00, 0x00, 0x00, sizeof(msRequestSenseResponse_t), 0x00}
};
return msDoCommand(&CommandBlockWrapper, Sense);
}
//---------------------------------------------------------------------------
// Report LUNs
uint8_t msController::msReportLUNs(uint8_t *Buffer)
{
#ifdef DBGprint
Serial.printf("msReportLuns()\n");
#endif
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = MAXLUNS,
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 12,
.CommandData = {CMD_REPORT_LUNS, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, MAXLUNS, 0x00, 0x00}
};
return msDoCommand(&CommandBlockWrapper, Buffer);
}
//---------------------------------------------------------------------------
// Read Sectors (Multi Sector Capable)
uint8_t msController::msReadBlocks(
const uint32_t BlockAddress,
const uint16_t Blocks,
const uint16_t BlockSize,
void * sectorBuffer)
{
#ifdef DBGprint
Serial.printf("msReadBlocks()\n");
#endif
uint8_t BlockHi = (Blocks >> 8) & 0xFF;
uint8_t BlockLo = Blocks & 0xFF;
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = (uint32_t)(Blocks * BlockSize),
.Flags = CMD_DIR_DATA_IN,
.LUN = currentLUN,
.CommandLength = 10,
.CommandData = {CMD_RD_10, 0x00,
(uint8_t)(BlockAddress >> 24),
(uint8_t)(BlockAddress >> 16),
(uint8_t)(BlockAddress >> 8),
(uint8_t)(BlockAddress & 0xFF),
0x00, BlockHi, BlockLo, 0x00}
};
return msDoCommand(&CommandBlockWrapper, sectorBuffer);
}
//---------------------------------------------------------------------------
// Write Sectors (Multi Sector Capable)
uint8_t msController::msWriteBlocks(
const uint32_t BlockAddress,
const uint16_t Blocks,
const uint16_t BlockSize,
const void * sectorBuffer)
{
#ifdef DBGprint
Serial.printf("msWriteBlocks()\n");
#endif
uint8_t BlockHi = (Blocks >> 8) & 0xFF;
uint8_t BlockLo = Blocks & 0xFF;
msCommandBlockWrapper_t CommandBlockWrapper = (msCommandBlockWrapper_t)
{
.Signature = CBW_SIGNATURE,
.Tag = ++CBWTag,
.TransferLength = (uint32_t)(Blocks * BlockSize),
.Flags = CMD_DIR_DATA_OUT,
.LUN = currentLUN,
.CommandLength = 10,
.CommandData = {CMD_WR_10, 0x00,
(uint8_t)(BlockAddress >> 24),
(uint8_t)(BlockAddress >> 16),
(uint8_t)(BlockAddress >> 8),
(uint8_t)(BlockAddress & 0xFF),
0x00, BlockHi, BlockLo, 0x00}
};
return msDoCommand(&CommandBlockWrapper, (void *)sectorBuffer);
}
// Proccess Possible SCSI errors
uint8_t msController::msProcessError(uint8_t msStatus) {
#ifdef DBGprint
Serial.printf("msProcessError()\n");
#endif
uint8_t msResult = 0;
switch(msStatus) {
case MS_CBW_PASS:
return MS_CBW_PASS;
break;
case MS_CBW_PHASE_ERROR:
Serial.printf("SCSI Phase Error: %d\n",msStatus);
return MS_SCSI_ERROR;
break;
case MS_CSW_TAG_ERROR:
Serial.printf("CSW Tag Error: %d\n",MS_CSW_TAG_ERROR);
return MS_CSW_TAG_ERROR;
break;
case MS_CSW_SIG_ERROR:
Serial.printf("CSW Signature Error: %d\n",MS_CSW_SIG_ERROR);
return MS_CSW_SIG_ERROR;
break;
case MS_CBW_FAIL:
msResult = msRequestSense(&msSense);
if(msResult) return msResult;
switch(msSense.SenseKey) {
case MS_UNIT_ATTENTION:
switch(msSense.AdditionalSenseCode) {
case MS_MEDIA_CHANGED:
return MS_MEDIA_CHANGED_ERR;
break;
default:
msStatus = MS_UNIT_NOT_READY;
}
case MS_NOT_READY:
switch(msSense.AdditionalSenseCode) {
case MS_MEDIUM_NOT_PRESENT:
msStatus = MS_NO_MEDIA_ERR;
break;
default:
msStatus = MS_UNIT_NOT_READY;
}
case MS_ILLEGAL_REQUEST:
switch(msSense.AdditionalSenseCode) {
case MS_LBA_OUT_OF_RANGE:
msStatus = MS_BAD_LBA_ERR;
break;
default:
msStatus = MS_CMD_ERR;
}
default:
msStatus = MS_SCSI_ERROR;
}
default:
Serial.printf("SCSI Error: %d\n",msStatus);
return msStatus;
}
}