Formatted code (#1007)

* Updated style

* Updated files

* fixed new line

* Updated spacing

* File fix WIP

* Updated to clang 13

* updated comment style

* Removed old comment code
This commit is contained in:
jLynx
2023-05-19 08:16:05 +12:00
committed by GitHub
parent 7aca7ce74d
commit 033c4e9a5b
599 changed files with 70746 additions and 66896 deletions

View File

@@ -42,7 +42,8 @@ void usb_send_bulk(void* const data, const uint32_t maximum_length) {
usb_bulk_block_cb,
NULL);
while (!usb_bulk_block_done);
while (!usb_bulk_block_done)
;
}
void usb_receive_bulk(void* const data, const uint32_t maximum_length) {
@@ -55,37 +56,36 @@ void usb_receive_bulk(void* const data, const uint32_t maximum_length) {
usb_bulk_block_cb,
NULL);
while (!usb_bulk_block_done);
while (!usb_bulk_block_done)
;
}
void usb_send_csw(msd_cbw_t *msd_cbw_data, uint8_t status) {
void usb_send_csw(msd_cbw_t* msd_cbw_data, uint8_t status) {
msd_csw_t csw = {
.signature = MSD_CSW_SIGNATURE,
.tag = msd_cbw_data->tag,
.data_residue = 0,
.status = status
};
.status = status};
memcpy(&usb_bulk_buffer[0], &csw, sizeof(msd_csw_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(msd_csw_t));
}
uint8_t handle_inquiry(msd_cbw_t *msd_cbw_data) {
uint8_t handle_inquiry(msd_cbw_t* msd_cbw_data) {
(void)msd_cbw_data;
scsi_inquiry_response_t ret = {
0x00, /* direct access block device */
0x80, /* removable */
0x00, //0x04, /* SPC-2 */
0x00, //0x02, /* response data format */
0x20, /* response has 0x20 + 4 bytes */
0x00, /* direct access block device */
0x80, /* removable */
0x00, // 0x04, /* SPC-2 */
0x00, // 0x02, /* response data format */
0x20, /* response has 0x20 + 4 bytes */
0x00,
0x00,
0x00,
"Mayhem",
"Portapack MSD",
{'v','1','.','6'}
};
{'v', '1', '.', '6'}};
memcpy(&usb_bulk_buffer[0], &ret, sizeof(scsi_inquiry_response_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(scsi_inquiry_response_t));
@@ -93,7 +93,7 @@ uint8_t handle_inquiry(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t handle_inquiry_serial_number(msd_cbw_t *msd_cbw_data) {
uint8_t handle_inquiry_serial_number(msd_cbw_t* msd_cbw_data) {
(void)msd_cbw_data;
scsi_unit_serial_number_inquiry_response_t ret = {
@@ -101,8 +101,7 @@ uint8_t handle_inquiry_serial_number(msd_cbw_t *msd_cbw_data) {
.page_code = 0x80,
.reserved = 0,
.page_length = 0x08,
.serialNumber = "Mayhem"
};
.serialNumber = "Mayhem"};
memcpy(&usb_bulk_buffer[0], &ret, sizeof(scsi_unit_serial_number_inquiry_response_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(scsi_unit_serial_number_inquiry_response_t));
@@ -110,8 +109,7 @@ uint8_t handle_inquiry_serial_number(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t read_format_capacities(msd_cbw_t *msd_cbw_data) {
uint8_t read_format_capacities(msd_cbw_t* msd_cbw_data) {
uint16_t len = msd_cbw_data->cmd_data[7] << 8 | msd_cbw_data->cmd_data[8];
if (len != 0) {
@@ -119,7 +117,7 @@ uint8_t read_format_capacities(msd_cbw_t *msd_cbw_data) {
scsi_read_format_capacities_response_t ret = {
.header = {0, 0, 0, 1 * 8 /* num_entries * 8 */},
.blocknum = {((num_blocks) >> 24)& 0xff, ((num_blocks) >> 16)& 0xff, ((num_blocks) >> 8)& 0xff, num_blocks & 0xff},
.blocknum = {((num_blocks) >> 24) & 0xff, ((num_blocks) >> 16) & 0xff, ((num_blocks) >> 8) & 0xff, num_blocks & 0xff},
.blocklen = {0b10 /* formated */, 0, (512) >> 8, 0},
};
@@ -130,15 +128,14 @@ uint8_t read_format_capacities(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t read_capacity10(msd_cbw_t *msd_cbw_data) {
uint8_t read_capacity10(msd_cbw_t* msd_cbw_data) {
(void)msd_cbw_data;
size_t num_blocks = get_capacity();
scsi_read_capacity10_response_t ret = {
.last_block_addr = cpu_to_be32(num_blocks - 1),
.block_size = cpu_to_be32(512)
};
.block_size = cpu_to_be32(512)};
memcpy(&usb_bulk_buffer[0], &ret, sizeof(scsi_read_capacity10_response_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(scsi_read_capacity10_response_t));
@@ -146,16 +143,15 @@ uint8_t read_capacity10(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t request_sense(msd_cbw_t *msd_cbw_data) {
uint8_t request_sense(msd_cbw_t* msd_cbw_data) {
(void)msd_cbw_data;
scsi_sense_response_t ret = {
.byte = { 0x70, 0, SCSI_SENSE_KEY_GOOD, 0,
0, 0, 0, 8,
0, 0 ,0 ,0,
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION, SCSI_ASENSEQ_NO_QUALIFIER, 0, 0,
0, 0 }
};
.byte = {0x70, 0, SCSI_SENSE_KEY_GOOD, 0,
0, 0, 0, 8,
0, 0, 0, 0,
SCSI_ASENSE_NO_ADDITIONAL_INFORMATION, SCSI_ASENSEQ_NO_QUALIFIER, 0, 0,
0, 0}};
memcpy(&usb_bulk_buffer[0], &ret, sizeof(scsi_sense_response_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(scsi_sense_response_t));
@@ -163,16 +159,15 @@ uint8_t request_sense(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t mode_sense6(msd_cbw_t *msd_cbw_data) {
(void)msd_cbw_data;
uint8_t mode_sense6(msd_cbw_t* msd_cbw_data) {
(void)msd_cbw_data;
scsi_mode_sense6_response_t ret = {
.byte = {
scsi_mode_sense6_response_t ret = {
.byte = {
sizeof(scsi_mode_sense6_response_t) - 1,
0,
0,
0 }
};
0}};
memcpy(&usb_bulk_buffer[0], &ret, sizeof(scsi_mode_sense6_response_t));
usb_send_bulk(&usb_bulk_buffer[0], sizeof(scsi_mode_sense6_response_t));
@@ -180,21 +175,21 @@ uint8_t mode_sense6(msd_cbw_t *msd_cbw_data) {
return 0;
}
static data_request_t decode_data_request(const uint8_t *cmd) {
data_request_t req;
uint32_t lba;
uint16_t blk;
static data_request_t decode_data_request(const uint8_t* cmd) {
data_request_t req;
uint32_t lba;
uint16_t blk;
memcpy(&lba, &cmd[2], sizeof(lba));
memcpy(&blk, &cmd[7], sizeof(blk));
memcpy(&lba, &cmd[2], sizeof(lba));
memcpy(&blk, &cmd[7], sizeof(blk));
req.first_lba = be32_to_cpu(lba);
req.blk_cnt = be16_to_cpu(blk);
req.first_lba = be32_to_cpu(lba);
req.blk_cnt = be16_to_cpu(blk);
return req;
return req;
}
uint8_t data_read10(msd_cbw_t *msd_cbw_data) {
uint8_t data_read10(msd_cbw_t* msd_cbw_data) {
data_request_t req = decode_data_request(msd_cbw_data->cmd_data);
for (size_t block_index = 0; block_index < req.blk_cnt; block_index++) {
@@ -205,7 +200,7 @@ uint8_t data_read10(msd_cbw_t *msd_cbw_data) {
return 0;
}
uint8_t data_write10(msd_cbw_t *msd_cbw_data) {
uint8_t data_write10(msd_cbw_t* msd_cbw_data) {
data_request_t req = decode_data_request(msd_cbw_data->cmd_data);
for (size_t block_index = 0; block_index < req.blk_cnt; block_index++) {
@@ -216,18 +211,16 @@ uint8_t data_write10(msd_cbw_t *msd_cbw_data) {
return 0;
}
void scsi_command(msd_cbw_t *msd_cbw_data) {
void scsi_command(msd_cbw_t* msd_cbw_data) {
uint8_t status = 1;
switch (msd_cbw_data->cmd_data[0]) {
case SCSI_CMD_INQUIRY:
if ((msd_cbw_data->cmd_data[1] & 0b1) && msd_cbw_data->cmd_data[2] == 0x80) {
status = handle_inquiry_serial_number(msd_cbw_data);
}
else if ((msd_cbw_data->cmd_data[1] & 0b11) || msd_cbw_data->cmd_data[2] != 0) {
} else if ((msd_cbw_data->cmd_data[1] & 0b11) || msd_cbw_data->cmd_data[2] != 0) {
status = 1;
}
else {
} else {
status = handle_inquiry(msd_cbw_data);
}
@@ -260,11 +253,11 @@ void scsi_command(msd_cbw_t *msd_cbw_data) {
case SCSI_CMD_MODE_SENSE_6:
status = mode_sense6(msd_cbw_data);
break;
case SCSI_CMD_READ_FORMAT_CAPACITIES:
status = read_format_capacities(msd_cbw_data);
break;
case SCSI_CMD_VERIFY_10:
status = 0;
break;