Changeset 380e0364 in mainline for uspace/drv/usbmast/main.c
- Timestamp:
- 2011-04-15T11:22:53Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- d7f08b0d, e1dbcbc
- Parents:
- 92fd730e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/usbmast/main.c
r92fd730e r380e0364 42 42 #include "cmds.h" 43 43 #include "scsi.h" 44 #include "mast.h" 44 45 45 46 #define NAME "usbmast" … … 74 75 }; 75 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 76 83 #define INQUIRY_RESPONSE_LENGTH 35 77 84 78 85 static void try_inquiry(usb_device_t *dev) 79 86 { 80 usb_massstor_cbw_t cbw;81 87 scsi_cmd_inquiry_t inquiry = { 82 88 .op_code = 0x12, … … 88 94 size_t response_len; 89 95 uint8_t response[INQUIRY_RESPONSE_LENGTH]; 90 usb_massstor_csw_t csw;91 size_t csw_len;92 93 usb_massstor_cbw_prepare(&cbw, 0xdeadbeef, INQUIRY_RESPONSE_LENGTH,94 USB_DIRECTION_IN, 0, sizeof(inquiry), (uint8_t *) &inquiry);95 96 96 97 int rc; 97 rc = usb_pipe_write(GET_BULK_OUT(dev), &cbw, sizeof(cbw)); 98 usb_log_debug("Wrote CBW: %s.\n", str_error(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 99 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)); 100 106 return; 101 107 } 102 108 103 rc = usb_pipe_read(GET_BULK_IN(dev), response, INQUIRY_RESPONSE_LENGTH, 104 &response_len); 105 usb_log_debug("Read response (%zuB): '%s' (%s).\n", response_len, 106 usb_debug_str_buffer(response, response_len, 0), 107 str_error(rc)); 108 if (rc != EOK) { 109 if (response_len < 8) { 110 usb_log_error("The SCSI response is too short.\n"); 109 111 return; 110 112 } 111 113 112 rc = usb_pipe_read(GET_BULK_IN(dev), &csw, sizeof(csw), &csw_len); 113 usb_log_debug("Read CSW (%zuB): '%s' (%s).\n", csw_len, 114 usb_debug_str_buffer((uint8_t *) &csw, csw_len, 0), 115 str_error(rc)); 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); 116 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); 117 136 } 118 137
Note:
See TracChangeset
for help on using the changeset viewer.