Permalink
Browse files

Adding sense code from Steve Evans

OS X really hates it when MSC doesn't report sense info
  • Loading branch information...
1 parent 914670f commit 3fb06d9d4c089df7ceb11411bb9dc6654c021551 @briand briand committed May 5, 2012
Showing with 50 additions and 24 deletions.
  1. +33 −23 src/libs/USBCDCMSC/USBCDCMSC.cpp
  2. +17 −1 src/libs/USBCDCMSC/USBCDCMSC.h
@@ -70,6 +70,20 @@ static uint8_t cdc_line_coding[7]= {0x80, 0x25, 0x00, 0x00, 0x00, 0x00, 0x08};
#define DEFAULT_CONFIGURATION (1)
+// Sense codes
+#define SENSE_NO_SENSE 0x00
+#define SENSE_RECOVERED_ERROR 0x01
+#define SENSE_NOT_READY 0x02
+#define SENSE_MEDIUM_ERROR 0x03
+#define SENSE_HARDWARE_ERROR 0x04
+#define SENSE_ILLEGAL_REQUEST 0x05
+#define SENSE_UNIT_ATTENTION 0x06
+#define SENSE_DATA_PROTECT 0x07
+#define SENSE_BLANK_CHECK 0x08
+#define SENSE_ABORTED_COMMAND 0x0B
+#define SENSE_VOLUME_OVERFLOW 0x0D
+#define SENSE_MISCOMPARE 0x0E
+
// max packet size
#define MAX_PACKET MAX_PACKET_SIZE_EPBULK
@@ -86,6 +100,7 @@ USBCDCMSC::USBCDCMSC(SDFileSystem *sd, uint16_t vendor_id, uint16_t product_id,
_status = NO_INIT;
connect();
// USBDevice::connect();
+ setSense(SENSE_NO_SENSE, 0x00, 0x00);
USBHAL::connect();
}
@@ -646,35 +661,27 @@ void USBCDCMSC::sendCSW() {
stage = WAIT_CSW;
}
-bool USBCDCMSC::requestSense (void) {
- uint8_t request_sense[] = {
- 0x70,
- 0x00,
- 0x05, // Sense Key: illegal request
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x0A,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x30,
- 0x01,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- };
+void USBCDCMSC::setSense (uint8_t sense_key, uint8_t asc, uint8_t ascq) {
+ sense.error = 0x70;
+ sense.sense_key = sense_key;
+ sense.additional_sense_length = 0x0a;
+ sense.asc = asc;
+ sense.ascq = ascq;
+}
- if (!msd_write(request_sense, sizeof(request_sense))) {
+bool USBCDCMSC::requestSense (void) {
+ if (!msd_write((uint8_t *)&sense, sizeof(sense))) {
return false;
}
-
+
return true;
}
+void USBCDCMSC::mediaRemoval() {
+ csw.Status = CSW_PASSED;
+ sendCSW();
+}
+
void USBCDCMSC::fail() {
csw.Status = CSW_FAILED;
sendCSW();
@@ -706,6 +713,9 @@ void USBCDCMSC::CBWDecode(uint8_t * buf, uint16_t size) {
case READ_FORMAT_CAPACITIES:
readFormatCapacity();
break;
+ case MEDIA_REMOVAL:
+ mediaRemoval();
+ break;
case READ_CAPACITY:
readCapacity();
break;
@@ -253,7 +253,18 @@ class USBCDCMSC: public USBDevice, public Module, public StreamOutput {
uint8_t Status;
} PACK_STRUCT_STRUCT CSW;
-
+ // sense
+ typedef PACK_STRUCT_BEGIN struct {
+ uint8_t error;
+ uint8_t resvd;
+ uint8_t sense_key;
+ uint8_t information[4];
+ uint8_t additional_sense_length;
+ uint8_t resvd2[4];
+ uint8_t asc;
+ uint8_t ascq;
+ uint8_t resvd3[4];
+ } PACK_STRUCT_STRUCT SENSE;
//state of the bulk-only state machine
Stage stage;
@@ -263,6 +274,9 @@ class USBCDCMSC: public USBDevice, public Module, public StreamOutput {
// CSW which will be sent
CSW csw;
+
+ // Current sense
+ SENSE sense;
// addr where will be read or written data
uint32_t addr;
@@ -294,8 +308,10 @@ class USBCDCMSC: public USBDevice, public Module, public StreamOutput {
bool modeSense6 (void);
void testUnitReady (void);
bool requestSense (void);
+ void setSense (uint8_t sense_key, uint8_t asc, uint8_t ascq);
void memoryVerify (uint8_t * buf, uint16_t size);
void memoryWrite (uint8_t * buf, uint16_t size);
+ void mediaRemoval(void);
void reset();
void fail();

0 comments on commit 3fb06d9

Please sign in to comment.