Changeset 7b2c17c in mainline for uspace/drv/bus/usb/usbmast/inquiry.c


Ignore:
Timestamp:
2011-07-02T20:42:14Z (13 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d2fac08c
Parents:
239e7e10
Message:

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

File:
1 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;
Note: See TracChangeset for help on using the changeset viewer.