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 virtual device (implementation).
|
---|
34 | */
|
---|
35 |
|
---|
36 | #include <assert.h>
|
---|
37 | #include <errno.h>
|
---|
38 | #include <usbvirt/hub.h>
|
---|
39 |
|
---|
40 | #include "conn.h"
|
---|
41 | #include "hc.h"
|
---|
42 |
|
---|
43 | /** Handle data from device to function.
|
---|
44 | */
|
---|
45 | static void handle_data_from_device(ipc_callid_t iid, ipc_call_t icall,
|
---|
46 | virtdev_connection_t *dev)
|
---|
47 | {
|
---|
48 | usb_target_t target = {
|
---|
49 | .address = IPC_GET_ARG1(icall),
|
---|
50 | .endpoint = IPC_GET_ARG2(icall)
|
---|
51 | };
|
---|
52 |
|
---|
53 | dprintf("data from device %d [%d.%d]", dev->id,
|
---|
54 | target.address, target.endpoint);
|
---|
55 |
|
---|
56 | size_t len;
|
---|
57 | void * buffer;
|
---|
58 | int rc = async_data_write_accept(&buffer, false,
|
---|
59 | 1, USB_MAX_PAYLOAD_SIZE,
|
---|
60 | 0, &len);
|
---|
61 |
|
---|
62 | if (rc != EOK) {
|
---|
63 | ipc_answer_0(iid, rc);
|
---|
64 | return;
|
---|
65 | }
|
---|
66 |
|
---|
67 | rc = hc_fillin_transaction_from_device(USB_TRANSFER_INTERRUPT, target, buffer, len);
|
---|
68 |
|
---|
69 | ipc_answer_0(iid, rc);
|
---|
70 | }
|
---|
71 |
|
---|
72 | /** Connection handler for communcation with virtual device.
|
---|
73 | *
|
---|
74 | * @param phone_hash Incoming phone hash.
|
---|
75 | * @param dev Virtual device handle.
|
---|
76 | */
|
---|
77 | void connection_handler_device(ipcarg_t phone_hash, virtdev_connection_t *dev)
|
---|
78 | {
|
---|
79 | assert(dev != NULL);
|
---|
80 |
|
---|
81 | dprintf("phone%#x: virtual device %d connected",
|
---|
82 | phone_hash, dev->id);
|
---|
83 |
|
---|
84 | while (true) {
|
---|
85 | ipc_callid_t callid;
|
---|
86 | ipc_call_t call;
|
---|
87 |
|
---|
88 | callid = async_get_call(&call);
|
---|
89 |
|
---|
90 | switch (IPC_GET_METHOD(call)) {
|
---|
91 | case IPC_M_PHONE_HUNGUP:
|
---|
92 | ipc_hangup(dev->phone);
|
---|
93 | ipc_answer_0(callid, EOK);
|
---|
94 | dprintf("phone%#x: device %d hang-up",
|
---|
95 | phone_hash, dev->id);
|
---|
96 | return;
|
---|
97 |
|
---|
98 | case IPC_M_CONNECT_TO_ME:
|
---|
99 | ipc_answer_0(callid, ELIMIT);
|
---|
100 | break;
|
---|
101 |
|
---|
102 | case IPC_M_USBVIRT_DATA_FROM_DEVICE:
|
---|
103 | handle_data_from_device(callid, call, dev);
|
---|
104 | break;
|
---|
105 |
|
---|
106 | default:
|
---|
107 | ipc_answer_0(callid, EINVAL);
|
---|
108 | break;
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | * @}
|
---|
115 | */
|
---|