source: mainline/uspace/drv/bus/usb/usbmast/main.c@ b361bdd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b361bdd was ec62681, checked in by Jiri Svoboda <jiri@…>, 14 years ago

Remove redundant arguments.

  • Property mode set to 100644
File size: 4.5 KB
Line 
1/*
2 * Copyright (c) 2011 Vojtech Horky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup drvusbmast
30 * @{
31 */
32/**
33 * @file
34 * Main routines of USB mass storage driver.
35 */
36#include <usb/dev/driver.h>
37#include <usb/debug.h>
38#include <usb/classes/classes.h>
39#include <usb/classes/massstor.h>
40#include <errno.h>
41#include <str_error.h>
42#include "cmds.h"
43#include "mast.h"
44
45#define NAME "usbmast"
46
47#define GET_BULK_IN(dev) ((dev)->pipes[BULK_IN_EP].pipe)
48#define GET_BULK_OUT(dev) ((dev)->pipes[BULK_OUT_EP].pipe)
49
50static usb_endpoint_description_t bulk_in_ep = {
51 .transfer_type = USB_TRANSFER_BULK,
52 .direction = USB_DIRECTION_IN,
53 .interface_class = USB_CLASS_MASS_STORAGE,
54 .interface_subclass = USB_MASSSTOR_SUBCLASS_SCSI,
55 .interface_protocol = USB_MASSSTOR_PROTOCOL_BBB,
56 .flags = 0
57};
58static usb_endpoint_description_t bulk_out_ep = {
59 .transfer_type = USB_TRANSFER_BULK,
60 .direction = USB_DIRECTION_OUT,
61 .interface_class = USB_CLASS_MASS_STORAGE,
62 .interface_subclass = USB_MASSSTOR_SUBCLASS_SCSI,
63 .interface_protocol = USB_MASSSTOR_PROTOCOL_BBB,
64 .flags = 0
65};
66
67usb_endpoint_description_t *mast_endpoints[] = {
68 &bulk_in_ep,
69 &bulk_out_ep,
70 NULL
71};
72
73/** Callback when new device is attached and recognized as a mass storage.
74 *
75 * @param dev Representation of a the USB device.
76 * @return Error code.
77 */
78static int usbmast_add_device(usb_device_t *dev)
79{
80 int rc;
81 const char *fun_name = "ctl";
82
83 ddf_fun_t *ctl_fun = ddf_fun_create(dev->ddf_dev, fun_exposed,
84 fun_name);
85 if (ctl_fun == NULL) {
86 usb_log_error("Failed to create control function.\n");
87 return ENOMEM;
88 }
89 rc = ddf_fun_bind(ctl_fun);
90 if (rc != EOK) {
91 usb_log_error("Failed to bind control function: %s.\n",
92 str_error(rc));
93 return rc;
94 }
95
96 usb_log_info("Pretending to control mass storage `%s'.\n",
97 dev->ddf_dev->name);
98 usb_log_debug(" Bulk in endpoint: %d [%zuB].\n",
99 dev->pipes[BULK_IN_EP].pipe->endpoint_no,
100 (size_t) dev->pipes[BULK_IN_EP].descriptor->max_packet_size);
101 usb_log_debug("Bulk out endpoint: %d [%zuB].\n",
102 dev->pipes[BULK_OUT_EP].pipe->endpoint_no,
103 (size_t) dev->pipes[BULK_OUT_EP].descriptor->max_packet_size);
104
105 usb_log_debug("Get LUN count...\n");
106 size_t lun_count = usb_masstor_get_lun_count(dev);
107
108 usb_log_debug("Inquire...\n");
109 usb_massstor_inquiry_result_t inquiry;
110 rc = usb_massstor_inquiry(dev, &inquiry);
111 if (rc != EOK) {
112 usb_log_warning("Failed to inquire device `%s': %s.\n",
113 dev->ddf_dev->name, str_error(rc));
114 return EOK;
115 }
116
117 usb_log_info("Mass storage `%s': " \
118 "%s by %s rev. %s is %s (%s), %zu LUN(s).\n",
119 dev->ddf_dev->name,
120 inquiry.product,
121 inquiry.vendor,
122 inquiry.revision,
123 usb_str_masstor_scsi_peripheral_device_type(inquiry.device_type),
124 inquiry.removable ? "removable" : "non-removable",
125 lun_count);
126
127 return EOK;
128}
129
130/** USB mass storage driver ops. */
131static usb_driver_ops_t usbmast_driver_ops = {
132 .add_device = usbmast_add_device,
133};
134
135/** USB mass storage driver. */
136static usb_driver_t usbmast_driver = {
137 .name = NAME,
138 .ops = &usbmast_driver_ops,
139 .endpoints = mast_endpoints
140};
141
142int main(int argc, char *argv[])
143{
144 usb_log_enable(USB_LOG_LEVEL_DEFAULT, NAME);
145
146 return usb_driver_main(&usbmast_driver);
147}
148
149/**
150 * @}
151 */
Note: See TracBrowser for help on using the repository browser.