mirror of
https://github.com/felis/USB_Host_Shield_2.0.git
synced 2024-03-22 11:31:26 +01:00
Honor Write protect
This commit is contained in:
parent
1cc3036eac
commit
bf8aedf382
2 changed files with 27 additions and 17 deletions
|
@ -183,23 +183,34 @@ Fail:
|
||||||
return rcode;
|
return rcode;
|
||||||
};
|
};
|
||||||
|
|
||||||
// This will be used to check for write protect.
|
boolean BulkOnly::WriteProtected(uint8_t lun) {
|
||||||
|
return WriteOk[lun];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check for write protect.
|
||||||
uint8_t BulkOnly::Page3F(uint8_t lun) {
|
uint8_t BulkOnly::Page3F(uint8_t lun) {
|
||||||
uint8_t buf[192];
|
uint8_t buf[192];
|
||||||
for (int i = 0; i < 192; i++) {
|
for (int i = 0; i < 192; i++) {
|
||||||
buf[i] = 0x00;
|
buf[i] = 0x00;
|
||||||
}
|
}
|
||||||
|
WriteOk[lun] = true;
|
||||||
uint8_t rc = ModeSense(lun, 0, 0x3f, 0, 192, buf);
|
uint8_t rc = ModeSense(lun, 0, 0x3f, 0, 192, buf);
|
||||||
//if (rc) rc = ModeSense(lun, 0, 0x00, 0, 4, buf);
|
//if (rc) rc = ModeSense(lun, 0, 0x00, 0, 4, buf);
|
||||||
//if (rc) rc = ModeSense(lun, 0, 0x3f, 0, 192, buf);
|
//if (rc) rc = ModeSense(lun, 0, 0x3f, 0, 192, buf);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
// write_protect = ((buf[2] & 0x80) != 0);
|
WriteOk[lun] = ((buf[2] & 0x80) == 0);
|
||||||
Notify(PSTR("Mode Sense: "), 0x80);
|
Notify(PSTR("Mode Sense: "), 0x80);
|
||||||
for (int i = 0; i < 4; i++) {
|
for (int i = 0; i < 4; i++) {
|
||||||
PrintHex<uint8_t > (buf[i], 0x80);
|
PrintHex<uint8_t > (buf[i], 0x80);
|
||||||
Notify(PSTR(" "), 0x80);
|
Notify(PSTR(" "), 0x80);
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
|
if(WriteOk[lun]) {
|
||||||
|
Notify(PSTR(" Writes Allowed"), 0x80);
|
||||||
|
} else {
|
||||||
|
Notify(PSTR(" Writes Denied"), 0x80);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Notify(PSTR("\r\n"), 0x80);
|
Notify(PSTR("\r\n"), 0x80);
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -808,7 +819,7 @@ uint8_t BulkOnly::Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t block
|
||||||
|
|
||||||
uint8_t BulkOnly::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) {
|
uint8_t BulkOnly::Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t * buf) {
|
||||||
if (!LUNOk[lun]) return MASS_ERR_NO_MEDIA;
|
if (!LUNOk[lun]) return MASS_ERR_NO_MEDIA;
|
||||||
//Poll();
|
if(!WriteOk[lun]) return MASS_ERR_WRITE_PROTECTED;
|
||||||
Notify(PSTR("\r\nWrite LUN:\t"), 0x80);
|
Notify(PSTR("\r\nWrite LUN:\t"), 0x80);
|
||||||
PrintHex<uint8_t > (lun, 0x90);
|
PrintHex<uint8_t > (lun, 0x90);
|
||||||
//printf("LUN=%i LBA=%8.8X BLOCKS=%i SIZE=%i\r\n", lun, addr, blocks, bsize);
|
//printf("LUN=%i LBA=%8.8X BLOCKS=%i SIZE=%i\r\n", lun, addr, blocks, bsize);
|
||||||
|
|
27
masstorage.h
27
masstorage.h
|
@ -106,6 +106,7 @@
|
||||||
#define MASS_ERR_WRITE_STALL 0x14
|
#define MASS_ERR_WRITE_STALL 0x14
|
||||||
#define MASS_ERR_READ_NAKS 0x15
|
#define MASS_ERR_READ_NAKS 0x15
|
||||||
#define MASS_ERR_WRITE_NAKS 0x16
|
#define MASS_ERR_WRITE_NAKS 0x16
|
||||||
|
#define MASS_ERR_WRITE_PROTECTED 0x17
|
||||||
#define MASS_ERR_GENERAL_SCSI_ERROR 0xFE
|
#define MASS_ERR_GENERAL_SCSI_ERROR 0xFE
|
||||||
#define MASS_ERR_GENERAL_USB_ERROR 0xFF
|
#define MASS_ERR_GENERAL_USB_ERROR 0xFF
|
||||||
#define MASS_ERR_USER 0xA0 // For subclasses to define their own error codes
|
#define MASS_ERR_USER 0xA0 // For subclasses to define their own error codes
|
||||||
|
@ -226,18 +227,9 @@ protected:
|
||||||
uint32_t CurrentCapacity[MASS_MAX_SUPPORTED_LUN]; // Total sectors
|
uint32_t CurrentCapacity[MASS_MAX_SUPPORTED_LUN]; // Total sectors
|
||||||
uint16_t CurrentSectorSize[MASS_MAX_SUPPORTED_LUN]; // Sector size, clipped to 16 bits
|
uint16_t CurrentSectorSize[MASS_MAX_SUPPORTED_LUN]; // Sector size, clipped to 16 bits
|
||||||
bool LUNOk[MASS_MAX_SUPPORTED_LUN]; // use this to check for media changes.
|
bool LUNOk[MASS_MAX_SUPPORTED_LUN]; // use this to check for media changes.
|
||||||
|
bool WriteOk[MASS_MAX_SUPPORTED_LUN];
|
||||||
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
|
||||||
|
|
||||||
bool IsValidCBW(uint8_t size, uint8_t *pcbw);
|
|
||||||
bool IsMeaningfulCBW(uint8_t size, uint8_t *pcbw);
|
|
||||||
|
|
||||||
bool IsValidCSW(CommandStatusWrapper *pcsw, CommandBlockWrapperBase *pcbw);
|
|
||||||
|
|
||||||
uint8_t ClearEpHalt(uint8_t index);
|
|
||||||
uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf, uint8_t flags);
|
|
||||||
uint8_t HandleUsbError(uint8_t error, uint8_t index);
|
|
||||||
uint8_t HandleSCSIError(uint8_t status);
|
|
||||||
|
|
||||||
// Additional Initialization Method for Subclasses
|
// Additional Initialization Method for Subclasses
|
||||||
|
|
||||||
|
@ -247,8 +239,6 @@ protected:
|
||||||
public:
|
public:
|
||||||
BulkOnly(USB *p);
|
BulkOnly(USB *p);
|
||||||
|
|
||||||
// Some of these should NOT be public.
|
|
||||||
|
|
||||||
uint8_t GetLastUsbError() {
|
uint8_t GetLastUsbError() {
|
||||||
return bLastUsbError;
|
return bLastUsbError;
|
||||||
};
|
};
|
||||||
|
@ -261,11 +251,12 @@ public:
|
||||||
return bTheLUN; // Active LUN
|
return bTheLUN; // Active LUN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean WriteProtected(uint8_t lun);
|
||||||
uint8_t MediaCTL(uint8_t lun, uint8_t ctl);
|
uint8_t MediaCTL(uint8_t lun, uint8_t ctl);
|
||||||
uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf);
|
uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, uint8_t *buf);
|
||||||
uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, USBReadParser *prs);
|
uint8_t Read(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, USBReadParser *prs);
|
||||||
uint8_t Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t *buf);
|
uint8_t Write(uint8_t lun, uint32_t addr, uint16_t bsize, uint8_t blocks, const uint8_t *buf);
|
||||||
|
uint8_t LockMedia(uint8_t lun, uint8_t lock);
|
||||||
|
|
||||||
bool LUNIsGood(uint8_t lun);
|
bool LUNIsGood(uint8_t lun);
|
||||||
uint32_t GetCapacity(uint8_t lun);
|
uint32_t GetCapacity(uint8_t lun);
|
||||||
|
@ -299,7 +290,15 @@ private:
|
||||||
void CheckMedia();
|
void CheckMedia();
|
||||||
boolean CheckLUN(uint8_t lun);
|
boolean CheckLUN(uint8_t lun);
|
||||||
uint8_t Page3F(uint8_t lun);
|
uint8_t Page3F(uint8_t lun);
|
||||||
uint8_t LockMedia(uint8_t lun, uint8_t lock);
|
bool IsValidCBW(uint8_t size, uint8_t *pcbw);
|
||||||
|
bool IsMeaningfulCBW(uint8_t size, uint8_t *pcbw);
|
||||||
|
|
||||||
|
bool IsValidCSW(CommandStatusWrapper *pcsw, CommandBlockWrapperBase *pcbw);
|
||||||
|
|
||||||
|
uint8_t ClearEpHalt(uint8_t index);
|
||||||
|
uint8_t Transaction(CommandBlockWrapper *cbw, uint16_t bsize, void *buf, uint8_t flags);
|
||||||
|
uint8_t HandleUsbError(uint8_t error, uint8_t index);
|
||||||
|
uint8_t HandleSCSIError(uint8_t status);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue