Skip to content

Commit

Permalink
usb: mass storage: use inquiry parameters from Kconfig
Browse files Browse the repository at this point in the history
support custom inquiry vendor id, product id and revision.

Signed-off-by: Jacob Siverskog <jacob@teenage.engineering>
  • Loading branch information
jsiverskog authored and nashif committed Feb 14, 2021
1 parent 6288af6 commit b4454f6
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 9 deletions.
24 changes: 24 additions & 0 deletions subsys/usb/class/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,30 @@ config MASS_STORAGE_DISK_NAME
help
Mass storage device disk or drive name

config MASS_STORAGE_INQ_VENDOR_ID
string "T10 assigned vendor ID for inquiry (must be 8 characters)"
depends on USB_MASS_STORAGE
default "ZEPHYR "
help
Vendor ID used for enquiry requests.
Spaces must be added to bring the string to 8 bytes.

config MASS_STORAGE_INQ_PRODUCT_ID
string "Product ID for inquiry (must be 16 characters)"
depends on USB_MASS_STORAGE
default "ZEPHYR USB DISK "
help
Product ID used for enquiry requests.
Spaces must be added to bring the string to 16 bytes.

config MASS_STORAGE_INQ_REVISION
string "Revision for inquiry (must be 4 characters)"
depends on USB_MASS_STORAGE
default "0.01"
help
Revision used for enquiry requests.
Spaces must be added to bring the string to 4 bytes.

config MASS_STORAGE_BULK_EP_MPS
int
depends on USB_MASS_STORAGE
Expand Down
37 changes: 28 additions & 9 deletions subsys/usb/class/mass_storage.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,33 @@ static uint8_t max_lun_count;
/*memory OK (after a memoryVerify)*/
static bool memOK;

#define INQ_VENDOR_ID_LEN 8
#define INQ_PRODUCT_ID_LEN 16
#define INQ_REVISION_LEN 4

struct dabc_inquiry_data {
uint8_t head[8];
uint8_t t10_vid[INQ_VENDOR_ID_LEN];
uint8_t product_id[INQ_PRODUCT_ID_LEN];
uint8_t product_rev[INQ_REVISION_LEN];
} __packed;

static const struct dabc_inquiry_data inq_rsp = {
.head = {0x00, 0x80, 0x00, 0x01, 36 - 4, 0x80, 0x00, 0x00},
.t10_vid = CONFIG_MASS_STORAGE_INQ_VENDOR_ID,
.product_id = CONFIG_MASS_STORAGE_INQ_PRODUCT_ID,
.product_rev = CONFIG_MASS_STORAGE_INQ_REVISION,
};

BUILD_ASSERT(sizeof(CONFIG_MASS_STORAGE_INQ_VENDOR_ID) == (INQ_VENDOR_ID_LEN + 1),
"CONFIG_MASS_STORAGE_INQ_VENDOR_ID must be 8 characters (pad with spaces)");

BUILD_ASSERT(sizeof(CONFIG_MASS_STORAGE_INQ_PRODUCT_ID) == (INQ_PRODUCT_ID_LEN + 1),
"CONFIG_MASS_STORAGE_INQ_PRODUCT_ID must be 16 characters (pad with spaces)");

BUILD_ASSERT(sizeof(CONFIG_MASS_STORAGE_INQ_REVISION) == (INQ_REVISION_LEN + 1),
"CONFIG_MASS_STORAGE_INQ_REVISION must be 4 characters (pad with spaces)");

static void msd_state_machine_reset(void)
{
stage = MSC_READ_CBW;
Expand Down Expand Up @@ -321,15 +348,7 @@ static bool requestSense(void)

static bool inquiryRequest(void)
{
uint8_t inquiry[] = { 0x00, 0x80, 0x00, 0x01,
36 - 4, 0x80, 0x00, 0x00,
'Z', 'E', 'P', 'H', 'Y', 'R', ' ', ' ',
'Z', 'E', 'P', 'H', 'Y', 'R', ' ', 'U', 'S', 'B', ' ',
'D', 'I', 'S', 'K', ' ',
'0', '.', '0', '1',
};

return write(inquiry, sizeof(inquiry));
return write((uint8_t *)&inq_rsp, sizeof(inq_rsp));
}

static bool modeSense6(void)
Expand Down

0 comments on commit b4454f6

Please sign in to comment.