Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

574 lines
19KB

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