Changes in uspace/drv/usbmast/main.c [5f0fe4e9:380e0364] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmast/main.c
r5f0fe4e9 r380e0364 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 35 84 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 = 0 93 }; 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 returned 116 * 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 77 138 /** Callback when new device is attached and recognized as a mass storage. 78 139 * … … 107 168 (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size); 108 169 109 size_t lun_count = usb_masstor_get_lun_count(dev); 110 111 usb_massstor_inquiry_result_t inquiry; 112 rc = usb_massstor_inquiry(dev, BULK_IN_EP, BULK_OUT_EP, &inquiry); 113 if (rc != EOK) { 114 usb_log_warning("Failed to inquiry device `%s': %s.\n", 115 dev->ddf_dev->name, str_error(rc)); 116 return EOK; 117 } 118 119 usb_log_info("Mass storage `%s': " \ 120 "`%s' by `%s' is %s (%s), %zu LUN(s).\n", 121 dev->ddf_dev->name, 122 inquiry.product_and_revision, inquiry.vendor_id, 123 usb_str_masstor_scsi_peripheral_device_type(inquiry.peripheral_device_type), 124 inquiry.removable ? "removable" : "non-removable", 125 lun_count); 170 try_inquiry(dev); 126 171 127 172 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.