Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 7b2c17c in mainline


Ignore:
Timestamp:
2011-07-02T20:42:14Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
d2fac08c
Parents:
239e7e10
Message:

Structure for SCSI standard inquiry data. Also fixes decoding of product and revision string in usbmast.

Location:
uspace
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/bus/usb/usbmast/inquiry.c

    r239e7e10 r7b2c17c  
    5252        ((type)( (number) & (BITS_GET_MID_MASK(type, bitcount, offset)) ) >> (offset))
    5353
    54 #define INQUIRY_RESPONSE_LENGTH 36
    55 
    5654/** Get string representation for SCSI peripheral device type.
    5755 *
     
    8987    usb_massstor_inquiry_result_t *inquiry_result)
    9088{
     89        scsi_std_inquiry_data_t inq_data;
     90        size_t response_len;
    9191        scsi_cdb_inquiry_t inquiry = {
    9292                .op_code = SCSI_CMD_INQUIRY,
    9393                .evpd = 0,
    9494                .page_code = 0,
    95                 .alloc_len = host2uint16_t_be(INQUIRY_RESPONSE_LENGTH),
     95                .alloc_len = host2uint16_t_be(sizeof(inq_data)),
    9696                .control = 0
    9797        };
    98         size_t response_len;
    99         uint8_t response[INQUIRY_RESPONSE_LENGTH];
    10098
    10199        int rc;
     
    103101        rc = usb_massstor_data_in(dev, bulk_in_idx, bulk_out_idx,
    104102            0xDEADBEEF, 0, (uint8_t *) &inquiry, sizeof(inquiry),
    105             response, INQUIRY_RESPONSE_LENGTH, &response_len);
     103            &inq_data, sizeof(inq_data), &response_len);
    106104
    107105        if (rc != EOK) {
     
    111109        }
    112110
    113         if (response_len < 8) {
    114                 usb_log_error("The SCSI response is too short.\n");
    115                 return ERANGE;
     111        if (response_len < SCSI_STD_INQUIRY_DATA_MIN_SIZE) {
     112                usb_log_error("The SCSI inquiry response is too short.\n");
     113                return EIO;
    116114        }
    117115
    118116        /*
    119          * This is an ugly part of the code. We will parse the returned
    120          * data by hand and try to get as many useful data as possible.
     117         * Parse inquiry data and fill in the result structure.
    121118         */
     119
    122120        bzero(inquiry_result, sizeof(*inquiry_result));
    123121
    124         /* This shall be returned by all devices. */
    125         inquiry_result->peripheral_device_type
    126             = BITS_GET(uint8_t, response[0], 5, 0);
    127         inquiry_result->removable = BITS_GET(uint8_t, response[1], 1, 7);
     122        inquiry_result->device_type =
     123            BITS_GET(uint8_t, inq_data.pqual_devtype, 5, 0);
     124        inquiry_result->removable =
     125            BITS_GET(uint8_t, inq_data.rmb, 1, 7);
    128126
    129         if (response_len < 32) {
    130                 return EOK;
    131         }
     127        str_ncpy(inquiry_result->vendor, 9,
     128            (const char *) &inq_data.vendor, 8);
     129        trim_trailing_spaces(inquiry_result->vendor);
    132130
    133         str_ncpy(inquiry_result->vendor_id, 9,
    134             (const char *) &response[8], 8);
    135         trim_trailing_spaces(inquiry_result->vendor_id);
     131        str_ncpy(inquiry_result->product, 17,
     132            (const char *) &inq_data.product, 16);
     133        trim_trailing_spaces(inquiry_result->product);
    136134
    137         str_ncpy(inquiry_result->product_and_revision, 12,
    138             (const char *) &response[16], 11);
    139         trim_trailing_spaces(inquiry_result->product_and_revision);
     135        str_ncpy(inquiry_result->revision, 5,
     136            (const char *) &inq_data.revision, 4);
     137        trim_trailing_spaces(inquiry_result->revision);
    140138
    141139        return EOK;
  • uspace/drv/bus/usb/usbmast/main.c

    r239e7e10 r7b2c17c  
    119119
    120120        usb_log_info("Mass storage `%s': " \
    121             "`%s' by `%s' is %s (%s), %zu LUN(s).\n",
     121            "%s by %s rev. %s is %s (%s), %zu LUN(s).\n",
    122122            dev->ddf_dev->name,
    123             inquiry.product_and_revision, inquiry.vendor_id,
    124             usb_str_masstor_scsi_peripheral_device_type(inquiry.peripheral_device_type),
     123            inquiry.product,
     124            inquiry.vendor,
     125            inquiry.revision,
     126            usb_str_masstor_scsi_peripheral_device_type(inquiry.device_type),
    125127            inquiry.removable ? "removable" : "non-removable",
    126128            lun_count);
  • uspace/drv/bus/usb/usbmast/mast.h

    r239e7e10 r7b2c17c  
    4747 */
    4848typedef struct {
    49         /** SCSI peripheral device type. */
    50         int peripheral_device_type;
    51         /** Whether the device is removable. */
     49        /** SCSI peripheral device type */
     50        unsigned device_type;
     51        /** Whether the device is removable */
    5252        bool removable;
    53         /** Vendor ID string. */
    54         char vendor_id[9];
    55         /** Product ID and product revision string. */
    56         char product_and_revision[12];
     53        /** Vendor ID string */
     54        char vendor[9];
     55        /** Product ID string */
     56        char product[17];
     57        /** Revision string */
     58        char revision[17];
    5759} usb_massstor_inquiry_result_t;
    5860
  • uspace/lib/scsi/include/scsi/spc.h

    r239e7e10 r7b2c17c  
    5858} __attribute__((packed)) scsi_cdb_inquiry_t;
    5959
     60/** Minimum size of inquiry data required since SCSI-2 */
     61#define SCSI_STD_INQUIRY_DATA_MIN_SIZE 36
     62
     63/** Standard inquiry data.
     64 *
     65 * Returned for Inquiry command with evpd bit cleared.
     66 */
     67typedef struct {
     68        /** Peripheral qualifier, Peripheral device type */
     69        uint8_t pqual_devtype;
     70        /** RMB, reserved */
     71        uint8_t rmb;
     72        /** Version */
     73        uint8_t version;
     74        /** Obsolete, NormACA, HiSup, Response Data Format */
     75        uint8_t aca_hisup_rdf;
     76        /** Additional Length */
     77        uint8_t additional_len;
     78        /** SCCS, ACC, TPGS, 3PC, Reserved, Protect */
     79        uint8_t cap1;
     80        /** Obsolete, EncServ, VS, MuliP, Obsolete, Addr16 */
     81        uint8_t cap2;
     82        /** Obsolete, WBus16, Sync, Obsolete, CmdQue, VS */
     83        uint8_t cap3;
     84
     85        /** Vendor string */
     86        uint8_t vendor[8];
     87        /** Product string */
     88        uint8_t product[16];
     89        /** Revision string */
     90        uint8_t revision[4];
     91
     92        /* End of required data */
     93} scsi_std_inquiry_data_t;
     94
    6095/** SCSI peripheral device type */
    6196enum scsi_device_type {
Note: See TracChangeset for help on using the changeset viewer.