Changeset 70c12d6 in mainline for uspace/drv/usbmast/main.c
- Timestamp:
- 2011-05-11T19:20:06Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- cf002dbf
- Parents:
- 19387b61
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmast/main.c
r19387b61 r70c12d6 75 75 }; 76 76 77 #define BITS_GET_MASK(type, bitcount) (((type)(1 << (bitcount)))-1)78 #define BITS_GET_MID_MASK(type, bitcount, offset) \79 ((type)( BITS_GET_MASK(type, (bitcount) + (offset)) - BITS_GET_MASK(type, bitcount) ))80 #define BITS_GET(type, number, bitcount, offset) \81 ((type)( (number) & (BITS_GET_MID_MASK(type, bitcount, offset)) ) >> (offset))82 83 #define INQUIRY_RESPONSE_LENGTH 3584 85 static void try_inquiry(usb_device_t *dev)86 {87 scsi_cmd_inquiry_t inquiry = {88 .op_code = 0x12,89 .lun_evpd = 0,90 .page_code = 0,91 .alloc_length = INQUIRY_RESPONSE_LENGTH,92 .ctrl = 093 };94 size_t response_len;95 uint8_t response[INQUIRY_RESPONSE_LENGTH];96 97 int rc;98 99 rc = usb_massstor_data_in(GET_BULK_IN(dev), GET_BULK_OUT(dev),100 0xDEADBEEF, 0, (uint8_t *) &inquiry, sizeof(inquiry),101 response, INQUIRY_RESPONSE_LENGTH, &response_len);102 103 if (rc != EOK) {104 usb_log_error("Failed to probe device %s using %s: %s.\n",105 dev->ddf_dev->name, "SCSI:INQUIRY", str_error(rc));106 return;107 }108 109 if (response_len < 8) {110 usb_log_error("The SCSI response is too short.\n");111 return;112 }113 114 /*115 * This is an ugly part of the code. We will parse the returned116 * data by hand and try to get as many useful data as possible.117 */118 int device_type = BITS_GET(uint8_t, response[0], 5, 0);119 int removable = BITS_GET(uint8_t, response[1], 1, 7);120 121 usb_log_info("SCSI information for device `%s':\n", dev->ddf_dev->name);122 usb_log_info(" - peripheral device type: %d\n", device_type);123 usb_log_info(" - removable: %s\n", removable ? "yes" : "no");124 125 if (response_len < 32) {126 return;127 }128 129 char dev_vendor[9];130 str_ncpy(dev_vendor, 9, (const char *) &response[8], 8);131 usb_log_info(" - vendor: '%s'\n", dev_vendor);132 133 char dev_product[9];134 str_ncpy(dev_product, 9, (const char *) &response[16], 8);135 usb_log_info(" - product: '%s'\n", dev_vendor);136 }137 138 77 /** Callback when new device is attached and recognized as a mass storage. 139 78 * … … 168 107 (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size); 169 108 170 try_inquiry(dev); 109 int lun_count = usb_massstor_get_max_lun(dev); 110 /* Return value: 111 * rc < 0 => device does not know this request, only single LUN 112 * could be present 113 * rc >= 0 - the rc is the maximum LUN, thus count is +1 114 */ 115 if (lun_count < 0) { 116 lun_count = 1; 117 } else { 118 lun_count++; 119 } 120 121 usb_massstor_inquiry_result_t inquiry; 122 rc = usb_massstor_inquiry(dev, BULK_IN_EP, BULK_OUT_EP, &inquiry); 123 if (rc != EOK) { 124 usb_log_warning("Failed to inquiry device `%s': %s.\n", 125 dev->ddf_dev->name, str_error(rc)); 126 return EOK; 127 } 128 129 usb_log_info("Mass storage `%s': `%s' by `%s' is %s (%s), %d LUN(s).\n", 130 dev->ddf_dev->name, 131 inquiry.product_and_revision, inquiry.vendor_id, 132 usb_str_masstor_scsi_peripheral_device_type(inquiry.peripheral_device_type), 133 inquiry.removable ? "removable" : "non-removable", 134 lun_count); 171 135 172 136 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.