summaryrefslogtreecommitdiff
path: root/src/class/msc/msc_device.c
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-09-17 22:37:45 +0200
committerHiFiPhile <[email protected]>2025-09-17 22:48:59 +0200
commit369a1ff5153a472327d2847c7bc7386309486b34 (patch)
tree7b8e6403bb1017e14fa224865eb73f4e10a3ba18 /src/class/msc/msc_device.c
parentd9ad09a8dce9e54cbd23062f8dec6c4fd49dc906 (diff)
Update weak callbacks to new syntax
Signed-off-by: HiFiPhile <[email protected]>
Diffstat (limited to 'src/class/msc/msc_device.c')
-rw-r--r--src/class/msc/msc_device.c111
1 files changed, 68 insertions, 43 deletions
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index a32014c2d..b0eafd5da 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -224,6 +224,53 @@ static bool proc_stage_status(mscd_interface_t *p_msc) {
}
//--------------------------------------------------------------------+
+// Weak stubs: invoked if no strong implementation is available
+//--------------------------------------------------------------------+
+TU_ATTR_WEAK void tud_msc_read10_complete_cb(uint8_t lun) {
+ (void) lun;
+}
+
+TU_ATTR_WEAK void tud_msc_write10_complete_cb(uint8_t lun) {
+ (void) lun;
+}
+
+TU_ATTR_WEAK void tud_msc_scsi_complete_cb(uint8_t lun, uint8_t const scsi_cmd[16]) {
+ (void) lun;
+ (void) scsi_cmd;
+}
+
+TU_ATTR_WEAK uint8_t tud_msc_get_maxlun_cb(void) {
+ return 1;
+}
+
+TU_ATTR_WEAK bool tud_msc_start_stop_cb(uint8_t lun, uint8_t power_condition, bool start, bool load_eject) {
+ (void) lun;
+ (void) power_condition;
+ (void) start;
+ (void) load_eject;
+ return true;
+}
+
+TU_ATTR_WEAK bool tud_msc_prevent_allow_medium_removal_cb(uint8_t lun, uint8_t prohibit_removal, uint8_t control) {
+ (void) lun;
+ (void) prohibit_removal;
+ (void) control;
+ return true;
+}
+
+TU_ATTR_WEAK int32_t tud_msc_request_sense_cb(uint8_t lun, void* buffer, uint16_t bufsize) {
+ (void) lun;
+ (void) buffer;
+ (void) bufsize;
+ return sizeof(scsi_sense_fixed_resp_t);
+}
+
+TU_ATTR_WEAK bool tud_msc_is_writable_cb(uint8_t lun) {
+ (void) lun;
+ return true;
+}
+
+//--------------------------------------------------------------------+
// Debug
//--------------------------------------------------------------------+
#if CFG_TUSB_DEBUG >= CFG_TUD_MSC_LOG_LEVEL
@@ -403,10 +450,7 @@ bool mscd_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_request_t
TU_LOG_DRV(" MSC Get Max Lun\r\n");
TU_VERIFY(request->wValue == 0 && request->wLength == 1);
- uint8_t maxlun = 1;
- if (tud_msc_get_maxlun_cb) {
- maxlun = tud_msc_get_maxlun_cb();
- }
+ uint8_t maxlun = tud_msc_get_maxlun_cb();
TU_VERIFY(maxlun);
maxlun--; // MAX LUN is minus 1 by specs
tud_control_xfer(rhport, request, &maxlun, 1);
@@ -584,21 +628,15 @@ bool mscd_xfer_cb(uint8_t rhport, uint8_t ep_addr, xfer_result_t event, uint32_t
// if complete_cb() is invoked after queuing the status.
switch (p_cbw->command[0]) {
case SCSI_CMD_READ_10:
- if (tud_msc_read10_complete_cb) {
- tud_msc_read10_complete_cb(p_cbw->lun);
- }
+ tud_msc_read10_complete_cb(p_cbw->lun);
break;
case SCSI_CMD_WRITE_10:
- if (tud_msc_write10_complete_cb) {
- tud_msc_write10_complete_cb(p_cbw->lun);
- }
+ tud_msc_write10_complete_cb(p_cbw->lun);
break;
default:
- if (tud_msc_scsi_complete_cb) {
- tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
- }
+ tud_msc_scsi_complete_cb(p_cbw->lun, p_cbw->command);
break;
}
@@ -648,16 +686,14 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
case SCSI_CMD_START_STOP_UNIT:
resplen = 0;
- if (tud_msc_start_stop_cb) {
- scsi_start_stop_unit_t const* start_stop = (scsi_start_stop_unit_t const*)scsi_cmd;
- if (!tud_msc_start_stop_cb(lun, start_stop->power_condition, start_stop->start, start_stop->load_eject)) {
- // Failed status response
- resplen = -1;
+ scsi_start_stop_unit_t const* start_stop = (scsi_start_stop_unit_t const*)scsi_cmd;
+ if (!tud_msc_start_stop_cb(lun, start_stop->power_condition, start_stop->start, start_stop->load_eject)) {
+ // Failed status response
+ resplen = -1;
- // set default sense if not set by callback
- if (p_msc->sense_key == 0) {
- set_sense_medium_not_present(lun);
- }
+ // set default sense if not set by callback
+ if (p_msc->sense_key == 0) {
+ set_sense_medium_not_present(lun);
}
}
break;
@@ -665,16 +701,14 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
case SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL:
resplen = 0;
- if (tud_msc_prevent_allow_medium_removal_cb) {
- scsi_prevent_allow_medium_removal_t const* prevent_allow = (scsi_prevent_allow_medium_removal_t const*)scsi_cmd;
- if (!tud_msc_prevent_allow_medium_removal_cb(lun, prevent_allow->prohibit_removal, prevent_allow->control)) {
- // Failed status response
- resplen = -1;
+ scsi_prevent_allow_medium_removal_t const* prevent_allow = (scsi_prevent_allow_medium_removal_t const*)scsi_cmd;
+ if (!tud_msc_prevent_allow_medium_removal_cb(lun, prevent_allow->prohibit_removal, prevent_allow->control)) {
+ // Failed status response
+ resplen = -1;
- // set default sense if not set by callback
- if (p_msc->sense_key == 0) {
- set_sense_medium_not_present(lun);
- }
+ // set default sense if not set by callback
+ if (p_msc->sense_key == 0) {
+ set_sense_medium_not_present(lun);
}
}
break;
@@ -767,10 +801,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
.block_descriptor_len = 0 // no block descriptor are included
};
- bool writable = true;
- if (tud_msc_is_writable_cb) {
- writable = tud_msc_is_writable_cb(lun);
- }
+ bool writable = tud_msc_is_writable_cb(lun);
mode_resp.write_protected = !writable;
@@ -794,9 +825,7 @@ static int32_t proc_builtin_scsi(uint8_t lun, uint8_t const scsi_cmd[16], uint8_
TU_VERIFY(0 == tu_memcpy_s(buffer, bufsize, &sense_rsp, (size_t) resplen));
// request sense callback could overwrite the sense data
- if (tud_msc_request_sense_cb) {
- resplen = tud_msc_request_sense_cb(lun, buffer, (uint16_t)bufsize);
- }
+ resplen = tud_msc_request_sense_cb(lun, buffer, (uint16_t)bufsize);
// Clear sense data after copy
tud_msc_set_sense(lun, 0, 0, 0);
@@ -854,11 +883,7 @@ static void proc_read_io_data(mscd_interface_t* p_msc, int32_t nbytes) {
static void proc_write10_cmd(mscd_interface_t* p_msc) {
msc_cbw_t const* p_cbw = &p_msc->cbw;
- bool writable = true;
-
- if (tud_msc_is_writable_cb) {
- writable = tud_msc_is_writable_cb(p_cbw->lun);
- }
+ bool writable = tud_msc_is_writable_cb(p_cbw->lun);
if (!writable) {
// Not writable, complete this SCSI op with error