Skip to content

Commit

Permalink
Latest Release RM0804-1555-0.88.1-ab80f82 on PATREON
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed Aug 4, 2023
1 parent f3c89d4 commit 396e9f0
Show file tree
Hide file tree
Showing 11 changed files with 268 additions and 171 deletions.
3 changes: 2 additions & 1 deletion ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ This software is for experimental purposes only and is not meant for any illegal
- Updated: [Ext Power Amp Code (Changes By Sil333033)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/63084d5e7687858065f4cd84a7217659ccf7910f)
- [Main Menu Lefty Mode Fixes (By Willy-JL)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/f66ee9181015a95375648c78b6ec74a8b368e37c)
- Added: [Chronometer (By nmrr)](https://github.com/nmrr/flipperzero-chronometer)
- Updated: [USB Mass Storage (By nminaylov)](https://github.com/flipperdevices/flipperzero-good-faps/tree/nm/usb_mass_storage_app/mass_storage) [(Changed By Willy-JL)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/e21b41a6f2b181794ce7ff0e35a6bbffdd0f0610)
- [Fixed Apps link in Main Menu & Games Menu Order (By RogueMaster)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/43d3483cc7a448063484e8a58effd25b037bbdbd)
- Updated: [NFC Seader v1.1 (By bettse)](https://github.com/bettse/seader)
- Updated: [SD Card Assets: Includes NFC Assets: 86 RM Pro Trained Level 50 Sm@sh Amiib0 (By RogueMaster) (19 More Added)](https://www.patreon.com/RogueMaster/membership)
- [Evil Portal Assets: Google Realistic (By JMcrafter26)](https://github.com/bigbrodude6119/flipper-zero-evil-portal/pull/60)
- [Evil Portal Assets: Google Realistic V2 (By JMcrafter26)](https://github.com/bigbrodude6119/flipper-zero-evil-portal/pull/60)
- Updated: [u-blox GPS (By liamhays)](https://github.com/liamhays/ublox)
- Updated: [Authenticator/TOTP v3.2 (By akopachov)](https://github.com/akopachov/flipper-zero_authenticator)
- Updated: [USB Mass Storage (By nminaylov)](https://github.com/flipperdevices/flipperzero-good-faps/tree/nm/usb_mass_storage_app/mass_storage) [(Changed By Willy-JL)]


<a name="release">

Expand Down
112 changes: 78 additions & 34 deletions applications/external/mass_storage/helpers/mass_storage_scsi.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#define SCSI_TEST_UNIT_READY (0x00)
#define SCSI_REQUEST_SENSE (0x03)
#define SCSI_INQUIRY (0x12)
#define SCSI_READ_CAPACITY_6 (0x25)
#define SCSI_READ_FORMAT_CAPACITIES (0x23)
#define SCSI_READ_CAPACITY_10 (0x25)
#define SCSI_MODE_SENSE_6 (0x1A)
#define SCSI_READ_10 (0x28)
#define SCSI_PREVENT_MEDIUM_REMOVAL (0x1E)
Expand All @@ -20,7 +21,7 @@ bool scsi_cmd_start(SCSISession* scsi, uint8_t* cmd, uint8_t len) {
scsi->asc = SCSI_ASC_INVALID_COMMAND_OPERATION_CODE;
return false;
}
// FURI_LOG_I(TAG, "START %02x", cmd[0]);
FURI_LOG_T(TAG, "START %02X", cmd[0]);
scsi->cmd = cmd;
scsi->cmd_len = len;
scsi->rx_done = false;
Expand All @@ -30,22 +31,22 @@ bool scsi_cmd_start(SCSISession* scsi, uint8_t* cmd, uint8_t len) {
if(len < 10) return false;
scsi->write_10.lba = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
scsi->write_10.count = cmd[7] << 8 | cmd[8];
FURI_LOG_I(TAG, "SCSI_WRITE_10 %08lx %04x", scsi->write_10.lba, scsi->write_10.count);
FURI_LOG_D(TAG, "SCSI_WRITE_10 %08lX %04X", scsi->write_10.lba, scsi->write_10.count);
return true;
}; break;
case SCSI_READ_10: {
if(len < 10) return false;
scsi->read_10.lba = cmd[2] << 24 | cmd[3] << 16 | cmd[4] << 8 | cmd[5];
scsi->read_10.count = cmd[7] << 8 | cmd[8];
FURI_LOG_I(TAG, "SCSI_READ_10 %08lx %04x", scsi->read_10.lba, scsi->read_10.count);
FURI_LOG_D(TAG, "SCSI_READ_10 %08lX %04X", scsi->read_10.lba, scsi->read_10.count);
return true;
}; break;
}
return true;
}

bool scsi_cmd_rx_data(SCSISession* scsi, uint8_t* data, uint32_t len) {
// FURI_LOG_I(TAG, "RX %02x len %d", scsi->cmd[0], len);
FURI_LOG_T(TAG, "RX %02X len %lu", scsi->cmd[0], len);
if(scsi->rx_done) return false;
switch(scsi->cmd[0]) {
case SCSI_WRITE_10: {
Expand All @@ -61,7 +62,7 @@ bool scsi_cmd_rx_data(SCSISession* scsi, uint8_t* data, uint32_t len) {
return result;
}; break;
default: {
FURI_LOG_W(TAG, "unexpected scsi rx data cmd=%02x", scsi->cmd[0]);
FURI_LOG_W(TAG, "unexpected scsi rx data cmd=%02X", scsi->cmd[0]);
scsi->sk = SCSI_SK_ILLEGAL_REQUEST;
scsi->asc = SCSI_ASC_INVALID_COMMAND_OPERATION_CODE;
return false;
Expand All @@ -70,11 +71,11 @@ bool scsi_cmd_rx_data(SCSISession* scsi, uint8_t* data, uint32_t len) {
}

bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t cap) {
// FURI_LOG_I(TAG, "TX %02x cap %d", scsi->cmd[0], cap);
FURI_LOG_T(TAG, "TX %02X cap %lu", scsi->cmd[0], cap);
if(scsi->tx_done) return false;
switch(scsi->cmd[0]) {
case SCSI_REQUEST_SENSE: {
FURI_LOG_I(TAG, "SCSI_REQUEST_SENSE");
FURI_LOG_D(TAG, "SCSI_REQUEST_SENSE");
if(cap < 18) return false;
memset(data, 0, cap);
data[0] = 0x70; // fixed format sense data
Expand Down Expand Up @@ -102,31 +103,73 @@ bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t
return true;
}; break;
case SCSI_INQUIRY: {
FURI_LOG_I(TAG, "SCSI_INQUIRY");
FURI_LOG_D(TAG, "SCSI_INQUIRY");
if(scsi->cmd_len < 5) return false;

if(cap < 36) return false;

bool evpd = scsi->cmd[1] & 1;
uint8_t page_code = scsi->cmd[2];
// uint16_t alloc_len = scsi->cmd[3] << 8 | scsi->cmd[4];
if(evpd) return false;
if(page_code) return false;
data[0] = 0x00; // device type: direct access block device
data[1] = 0x80; // removable: true
data[2] = 0x04; // version
data[3] = 0x02; // response data format
data[4] = 31; // additional length (len - 5)
data[5] = 0; // flags
data[6] = 0; // flags
data[7] = 0; // flags
memcpy(data + 8, "Flipper ", 8); // vendor id
memcpy(data + 16, "Mass Storage ", 16); // product id
memcpy(data + 32, "0001", 4); // product revision level
*len = 36;
if(evpd == 0) {
if(page_code != 0) return false;

data[0] = 0x00; // device type: direct access block device
data[1] = 0x80; // removable: true
data[2] = 0x04; // version
data[3] = 0x02; // response data format
data[4] = 31; // additional length (len - 5)
data[5] = 0; // flags
data[6] = 0; // flags
data[7] = 0; // flags
memcpy(data + 8, "Flipper ", 8); // vendor id
memcpy(data + 16, "Mass Storage ", 16); // product id
memcpy(data + 32, "0001", 4); // product revision level
*len = 36;
scsi->tx_done = true;
return true;
} else {
if(page_code != 0x80) {
FURI_LOG_W(TAG, "Unsupported VPD code %02X", page_code);
return false;
}
data[0] = 0x00;
data[1] = 0x80;
data[2] = 0x00;
data[3] = 0x01; // Serial len
data[4] = '0';
*len = 5;
scsi->tx_done = true;
return true;
}
}; break;
case SCSI_READ_FORMAT_CAPACITIES: {
FURI_LOG_D(TAG, "SCSI_READ_FORMAT_CAPACITIES");
if(cap < 12) {
return false;
}
uint32_t n_blocks = scsi->fn.num_blocks(scsi->fn.ctx);
uint32_t block_size = SCSI_BLOCK_SIZE;
// Capacity List Header
data[0] = 0;
data[1] = 0;
data[2] = 0;
data[3] = 8;

// Capacity Descriptor
data[4] = (n_blocks - 1) >> 24;
data[5] = (n_blocks - 1) >> 16;
data[6] = (n_blocks - 1) >> 8;
data[7] = (n_blocks - 1) & 0xFF;
data[8] = 0x02; // Formatted media
data[9] = block_size >> 16;
data[10] = block_size >> 8;
data[11] = block_size & 0xFF;
*len = 12;
scsi->tx_done = true;
return true;
}; break;
case SCSI_READ_CAPACITY_6: {
FURI_LOG_I(TAG, "SCSI_READ_CAPACITY_6");
case SCSI_READ_CAPACITY_10: {
FURI_LOG_D(TAG, "SCSI_READ_CAPACITY_10");
if(cap < 8) return false;
uint32_t n_blocks = scsi->fn.num_blocks(scsi->fn.ctx);
uint32_t block_size = SCSI_BLOCK_SIZE;
Expand All @@ -143,7 +186,7 @@ bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t
return true;
}; break;
case SCSI_MODE_SENSE_6: {
FURI_LOG_I(TAG, "SCSI_MODE_SENSE_6 %lu", cap);
FURI_LOG_D(TAG, "SCSI_MODE_SENSE_6 %lu", cap);
if(cap < 4) return false;
data[0] = 3; // mode data length (len - 1)
data[1] = 0; // medium type
Expand All @@ -167,7 +210,7 @@ bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t
return result;
}; break;
default: {
FURI_LOG_W(TAG, "unexpected scsi tx data cmd=%02x", scsi->cmd[0]);
FURI_LOG_W(TAG, "unexpected scsi tx data cmd=%02X", scsi->cmd[0]);
scsi->sk = SCSI_SK_ILLEGAL_REQUEST;
scsi->asc = SCSI_ASC_INVALID_COMMAND_OPERATION_CODE;
return false;
Expand All @@ -176,7 +219,7 @@ bool scsi_cmd_tx_data(SCSISession* scsi, uint8_t* data, uint32_t* len, uint32_t
}

bool scsi_cmd_end(SCSISession* scsi) {
// FURI_LOG_I(TAG, "END %02x", scsi->cmd[0]);
FURI_LOG_T(TAG, "END %02X", scsi->cmd[0]);
uint8_t* cmd = scsi->cmd;
uint8_t len = scsi->cmd_len;
scsi->cmd = NULL;
Expand All @@ -187,33 +230,34 @@ bool scsi_cmd_end(SCSISession* scsi) {

case SCSI_REQUEST_SENSE:
case SCSI_INQUIRY:
case SCSI_READ_CAPACITY_6:
case SCSI_READ_FORMAT_CAPACITIES:
case SCSI_READ_CAPACITY_10:
case SCSI_MODE_SENSE_6:
case SCSI_READ_10:
return scsi->tx_done;

case SCSI_TEST_UNIT_READY: {
FURI_LOG_I(TAG, "SCSI_TEST_UNIT_READY");
FURI_LOG_D(TAG, "SCSI_TEST_UNIT_READY");
return true;
}; break;
case SCSI_PREVENT_MEDIUM_REMOVAL: {
if(len < 6) return false;
bool prevent = cmd[5];
FURI_LOG_I(TAG, "SCSI_PREVENT_MEDIUM_REMOVAL prevent=%d", prevent);
FURI_LOG_D(TAG, "SCSI_PREVENT_MEDIUM_REMOVAL prevent=%d", prevent);
return !prevent;
}; break;
case SCSI_START_STOP_UNIT: {
if(len < 6) return false;
bool eject = (cmd[4] & 2) != 0;
bool start = (cmd[4] & 1) != 0;
FURI_LOG_I(TAG, "SCSI_START_STOP_UNIT eject=%d start=%d", eject, start);
FURI_LOG_D(TAG, "SCSI_START_STOP_UNIT eject=%d start=%d", eject, start);
if(eject) {
scsi->fn.eject(scsi->fn.ctx);
}
return true;
}; break;
default: {
FURI_LOG_W(TAG, "unexpected scsi cmd=%02x", cmd[0]);
FURI_LOG_W(TAG, "unexpected scsi cmd=%02X", cmd[0]);
scsi->sk = SCSI_SK_ILLEGAL_REQUEST;
scsi->asc = SCSI_ASC_INVALID_COMMAND_OPERATION_CODE;
return false;
Expand Down
29 changes: 15 additions & 14 deletions applications/external/mass_storage/helpers/mass_storage_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef struct {
uint8_t cmd_len;
uint8_t cmd[16];
} __attribute__((packed)) CBW;

typedef struct {
uint32_t sig;
uint32_t tag;
Expand Down Expand Up @@ -80,11 +81,11 @@ static int32_t mass_thread_worker(void* context) {
while(true) {
uint32_t flags = furi_thread_flags_wait(EventAll, FuriFlagWaitAny, FuriWaitForever);
if(flags & EventExit) {
FURI_LOG_I(TAG, "exit");
FURI_LOG_D(TAG, "exit");
break;
}
if(flags & EventReset) {
FURI_LOG_I(TAG, "reset");
FURI_LOG_D(TAG, "reset");
scsi.sk = 0;
scsi.asc = 0;
memset(&cbw, 0, sizeof(cbw));
Expand All @@ -99,10 +100,10 @@ static int32_t mass_thread_worker(void* context) {
if(flags & EventRxTx) do {
switch(state) {
case StateReadCBW: {
// FURI_LOG_I(TAG, "StateReadCBW");
FURI_LOG_T(TAG, "StateReadCBW");
int32_t len = usbd_ep_read(dev, USB_MSC_RX_EP, &cbw, sizeof(cbw));
if(len <= 0) {
// FURI_LOG_I(TAG, "cbw not ready");
FURI_LOG_T(TAG, "cbw not ready");
break;
}
if(len != sizeof(cbw) || cbw.sig != CBW_SIG) {
Expand Down Expand Up @@ -131,14 +132,14 @@ static int32_t mass_thread_worker(void* context) {
continue;
}; break;
case StateReadData: {
// FURI_LOG_I(TAG, "StateReadData %d/%d", buf_len, cbw.len);
FURI_LOG_T(TAG, "StateReadData %lu/%lu", buf_len, cbw.len);
if(!cbw.len) {
state = StateBuildCSW;
continue;
}
uint32_t buf_clamp = MIN(cbw.len, USB_MSC_BUF_MAX);
if(buf_clamp > buf_cap) {
FURI_LOG_I(TAG, "growing buf %lu -> %lu", buf_cap, buf_clamp);
FURI_LOG_T(TAG, "growing buf %lu -> %lu", buf_cap, buf_clamp);
if(buf) {
free(buf);
}
Expand All @@ -149,10 +150,10 @@ static int32_t mass_thread_worker(void* context) {
int32_t len =
usbd_ep_read(dev, USB_MSC_RX_EP, buf + buf_len, buf_clamp - buf_len);
if(len < 0) {
// FURI_LOG_I(TAG, "rx not ready %d", len);
FURI_LOG_T(TAG, "rx not ready %ld", len);
break;
}
// FURI_LOG_I(TAG, "clamp %ld len %d", buf_clamp, len);
FURI_LOG_T(TAG, "clamp %lu len %ld", buf_clamp, len);
buf_len += len;
}
if(buf_len == buf_clamp) {
Expand All @@ -172,14 +173,14 @@ static int32_t mass_thread_worker(void* context) {
continue;
}; break;
case StateWriteData: {
// FURI_LOG_I(TAG, "StateWriteData %d", cbw.len);
FURI_LOG_T(TAG, "StateWriteData %lu", cbw.len);
if(!cbw.len) {
state = StateBuildCSW;
continue;
}
uint32_t buf_clamp = MIN(cbw.len, USB_MSC_BUF_MAX);
if(buf_clamp > buf_cap) {
FURI_LOG_I(TAG, "growing buf %lu -> %lu", buf_cap, buf_clamp);
FURI_LOG_T(TAG, "growing buf %lu -> %lu", buf_cap, buf_clamp);
if(buf) {
free(buf);
}
Expand All @@ -198,7 +199,7 @@ static int32_t mass_thread_worker(void* context) {
buf + buf_sent,
MIN(USB_MSC_TX_EP_SIZE, buf_len - buf_sent));
if(len < 0) {
// FURI_LOG_I(TAG, "tx not ready %d", len);
FURI_LOG_T(TAG, "tx not ready %ld", len);
break;
}
buf_sent += len;
Expand All @@ -210,7 +211,7 @@ static int32_t mass_thread_worker(void* context) {
continue;
}; break;
case StateBuildCSW: {
// FURI_LOG_I(TAG, "StateBuildCSW");
FURI_LOG_T(TAG, "StateBuildCSW");
csw.sig = CSW_SIG;
csw.tag = cbw.tag;
if(scsi_cmd_end(&scsi)) {
Expand All @@ -223,7 +224,7 @@ static int32_t mass_thread_worker(void* context) {
continue;
}; break;
case StateWriteCSW: {
// FURI_LOG_I(TAG, "StateWriteCSW");
FURI_LOG_T(TAG, "StateWriteCSW");
if(csw.status) {
FURI_LOG_W(
TAG,
Expand All @@ -235,7 +236,7 @@ static int32_t mass_thread_worker(void* context) {
}
int32_t len = usbd_ep_write(dev, USB_MSC_TX_EP, &csw, sizeof(csw));
if(len < 0) {
// FURI_LOG_I(TAG, "csw not ready");
FURI_LOG_T(TAG, "csw not ready");
break;
}
if(len != sizeof(csw)) {
Expand Down
Loading

0 comments on commit 396e9f0

Please sign in to comment.