5 * Copyright (C) 2009 Pawel Dziepak
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
35 class usb
: public bus
{
43 struct usb_setup_data
{
57 struct device_descriptor
{
71 u8 bNumConfigurations
;
72 } __attribute__((packed
));
74 struct configuration_descriptor
{
79 u8 bConfigurationValue
;
83 } __attribute__((packed
));
85 struct interface_descriptor
{
92 u8 bInterfaceSubClass
;
93 u8 bInterfaceProtocol
;
95 } __attribute__((packed
));
97 struct endpoint_descriptor
{
104 } __attribute__((packed
));
106 void device_connected(int);
107 string
get_dev_string(int, int);
109 // bool initialize();
110 // bool type_added(manes::type_name);
111 p
<usb_hc
> get_host() {
115 void set_conf(int, int);
119 bool init_bus(p
<device
>);
121 static void register_type();
124 class usb_did
: public did
{
127 virtual ~usb_did() {}
131 p
<usb::interface_descriptor
> intf
;
139 usb_did(p
<bus
> b
, int addr
, p
<usb::interface_descriptor
> i
) : did(b
), address(addr
), intf(i
) { }
141 virtual void set_endps(int c
, int r
, int w
) {
147 virtual void set_conf(int c
) {
151 virtual int get_class() const {
152 return intf
->bInterfaceClass
;
155 virtual int get_subclass() const {
156 return intf
->bInterfaceSubClass
;
159 virtual int get_protocol() const {
160 return intf
->bInterfaceProtocol
;
163 bus_id
.cast
<usb
>()->set_conf(address
, configuration
);
166 virtual void bulk_read(buffer
&buf
) {
167 bus_id
.cast
<usb
>()->get_host()->bulk_transfer(usb::pid_in
, buf
.get_address(), buf
.get_size(), address
, read_endp
);
170 virtual void bulk_write(const buffer
&buf
) {
171 bus_id
.cast
<usb
>()->get_host()->bulk_transfer(usb::pid_out
, buf
.get_address(), buf
.get_size(), address
, write_endp
);
174 virtual void control(const buffer
&buf
) {
175 bus_id
.cast
<usb
>()->get_host()->control_transfer(usb::pid_setup
, buf
.get_address(), buf
.get_size(), 0, address
);
178 virtual buffer
control(const buffer
&buf
, int size
) {
179 void *addr
= bus_id
.cast
<usb
>()->get_host()->control_transfer(usb::pid_setup
, buf
.get_address(), buf
.get_size(), size
, address
);
180 return buffer(addr
, size
);