Changeset 380e0364 in mainline


Ignore:
Timestamp:
2011-04-15T11:22:53Z (14 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
d7f08b0d, e1dbcbc
Parents:
92fd730e
Message:

Add generic function for data IN on mass storage

Also, more information is printed about device that is
plugged in.

Location:
uspace/drv/usbmast
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbmast/Makefile

    r92fd730e r380e0364  
    3333
    3434SOURCES = \
    35         main.c
     35        main.c \
     36        mast.c
    3637
    3738include $(USPACE_PREFIX)/Makefile.common
  • uspace/drv/usbmast/main.c

    r92fd730e r380e0364  
    4242#include "cmds.h"
    4343#include "scsi.h"
     44#include "mast.h"
    4445
    4546#define NAME "usbmast"
     
    7475};
    7576
     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
    7683#define INQUIRY_RESPONSE_LENGTH 35
    7784
    7885static void try_inquiry(usb_device_t *dev)
    7986{
    80         usb_massstor_cbw_t cbw;
    8187        scsi_cmd_inquiry_t inquiry = {
    8288                .op_code = 0x12,
     
    8894        size_t response_len;
    8995        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);
    9596
    9697        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
    99103        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));
    100106                return;
    101107        }
    102108
    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");
    109111                return;
    110112        }
    111113
    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);
    116120
     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);
    117136}
    118137
Note: See TracChangeset for help on using the changeset viewer.