source: mainline/uspace/drv/vhc/connhost.c@ 84439d7

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 84439d7 was ce687bbe, checked in by Vojtech Horky <vojtechhorky@…>, 15 years ago

Virtual HC can bind address and resolve them

  • Property mode set to 100644
File size: 6.9 KB
Line 
1/*
2 * Copyright (c) 2010 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 usb
30 * @{
31 */
32/** @file
33 * @brief Connection handling of calls from host (implementation).
34 */
35#include <assert.h>
36#include <errno.h>
37#include <usb/usb.h>
38
39#include "vhcd.h"
40#include "conn.h"
41#include "hc.h"
42
43typedef struct {
44 usb_direction_t direction;
45 usbhc_iface_transfer_out_callback_t out_callback;
46 usbhc_iface_transfer_in_callback_t in_callback;
47 device_t *dev;
48 void *arg;
49} transfer_info_t;
50
51static void universal_callback(void *buffer, size_t size,
52 usb_transaction_outcome_t outcome, void *arg)
53{
54 transfer_info_t *transfer = (transfer_info_t *) arg;
55
56 switch (transfer->direction) {
57 case USB_DIRECTION_IN:
58 transfer->in_callback(transfer->dev,
59 size, outcome,
60 transfer->arg);
61 break;
62 case USB_DIRECTION_OUT:
63 transfer->out_callback(transfer->dev,
64 outcome,
65 transfer->arg);
66 break;
67 default:
68 assert(false && "unreachable");
69 break;
70 }
71
72 free(transfer);
73}
74
75static transfer_info_t *create_transfer_info(device_t *dev,
76 usb_direction_t direction, void *arg)
77{
78 transfer_info_t *transfer = malloc(sizeof(transfer_info_t));
79
80 transfer->direction = direction;
81 transfer->in_callback = NULL;
82 transfer->out_callback = NULL;
83 transfer->arg = arg;
84 transfer->dev = dev;
85
86 return transfer;
87}
88
89static int enqueue_transfer_out(device_t *dev,
90 usb_target_t target, usb_transfer_type_t transfer_type,
91 void *buffer, size_t size,
92 usbhc_iface_transfer_out_callback_t callback, void *arg)
93{
94 printf(NAME ": transfer OUT [%d.%d (%s); %u]\n",
95 target.address, target.endpoint,
96 usb_str_transfer_type(transfer_type),
97 size);
98
99 transfer_info_t *transfer
100 = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
101 transfer->out_callback = callback;
102
103 hc_add_transaction_to_device(false, target, buffer, size,
104 universal_callback, transfer);
105
106 return EOK;
107}
108
109static int enqueue_transfer_setup(device_t *dev,
110 usb_target_t target, usb_transfer_type_t transfer_type,
111 void *buffer, size_t size,
112 usbhc_iface_transfer_out_callback_t callback, void *arg)
113{
114 printf(NAME ": transfer SETUP [%d.%d (%s); %u]\n",
115 target.address, target.endpoint,
116 usb_str_transfer_type(transfer_type),
117 size);
118
119 transfer_info_t *transfer
120 = create_transfer_info(dev, USB_DIRECTION_OUT, arg);
121 transfer->out_callback = callback;
122
123 hc_add_transaction_to_device(true, target, buffer, size,
124 universal_callback, transfer);
125
126 return EOK;
127}
128
129static int enqueue_transfer_in(device_t *dev,
130 usb_target_t target, usb_transfer_type_t transfer_type,
131 void *buffer, size_t size,
132 usbhc_iface_transfer_in_callback_t callback, void *arg)
133{
134 printf(NAME ": transfer IN [%d.%d (%s); %u]\n",
135 target.address, target.endpoint,
136 usb_str_transfer_type(transfer_type),
137 size);
138
139 transfer_info_t *transfer
140 = create_transfer_info(dev, USB_DIRECTION_IN, arg);
141 transfer->in_callback = callback;
142
143 hc_add_transaction_from_device(target, buffer, size,
144 universal_callback, transfer);
145
146 return EOK;
147}
148
149
150static int interrupt_out(device_t *dev, usb_target_t target,
151 void *data, size_t size,
152 usbhc_iface_transfer_out_callback_t callback, void *arg)
153{
154 return enqueue_transfer_out(dev, target, USB_TRANSFER_INTERRUPT,
155 data, size,
156 callback, arg);
157}
158
159static int interrupt_in(device_t *dev, usb_target_t target,
160 void *data, size_t size,
161 usbhc_iface_transfer_in_callback_t callback, void *arg)
162{
163 return enqueue_transfer_in(dev, target, USB_TRANSFER_INTERRUPT,
164 data, size,
165 callback, arg);
166}
167
168static int control_write_setup(device_t *dev, usb_target_t target,
169 void *data, size_t size,
170 usbhc_iface_transfer_out_callback_t callback, void *arg)
171{
172 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
173 data, size,
174 callback, arg);
175}
176
177static int control_write_data(device_t *dev, usb_target_t target,
178 void *data, size_t size,
179 usbhc_iface_transfer_out_callback_t callback, void *arg)
180{
181 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
182 data, size,
183 callback, arg);
184}
185
186static int control_write_status(device_t *dev, usb_target_t target,
187 usbhc_iface_transfer_in_callback_t callback, void *arg)
188{
189 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
190 NULL, 0,
191 callback, arg);
192}
193
194static int control_read_setup(device_t *dev, usb_target_t target,
195 void *data, size_t size,
196 usbhc_iface_transfer_out_callback_t callback, void *arg)
197{
198 return enqueue_transfer_setup(dev, target, USB_TRANSFER_CONTROL,
199 data, size,
200 callback, arg);
201}
202
203static int control_read_data(device_t *dev, usb_target_t target,
204 void *data, size_t size,
205 usbhc_iface_transfer_in_callback_t callback, void *arg)
206{
207 return enqueue_transfer_in(dev, target, USB_TRANSFER_CONTROL,
208 data, size,
209 callback, arg);
210}
211
212static int control_read_status(device_t *dev, usb_target_t target,
213 usbhc_iface_transfer_out_callback_t callback, void *arg)
214{
215 return enqueue_transfer_out(dev, target, USB_TRANSFER_CONTROL,
216 NULL, 0,
217 callback, arg);
218}
219
220
221usbhc_iface_t vhc_iface = {
222 .tell_address = tell_address,
223
224 .reserve_default_address = reserve_default_address,
225 .release_default_address = release_default_address,
226 .request_address = request_address,
227 .bind_address = bind_address,
228 .release_address = release_address,
229
230 .interrupt_out = interrupt_out,
231 .interrupt_in = interrupt_in,
232
233 .control_write_setup = control_write_setup,
234 .control_write_data = control_write_data,
235 .control_write_status = control_write_status,
236
237 .control_read_setup = control_read_setup,
238 .control_read_data = control_read_data,
239 .control_read_status = control_read_status
240};
241
242/**
243 * @}
244 */
Note: See TracBrowser for help on using the repository browser.