source: mainline/uspace/srv/hw/bus/usb/hcd/virtual/conndev.c@ b8a3cda

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

VHCD handles new methods

Not completely, though. Will finish later.

  • Property mode set to 100644
File size: 3.3 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 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#include "hub.h"
43
44/** Handle data from device to host.
45 */
46static void handle_data_from_device(ipc_callid_t iid, ipc_call_t icall,
47 virtdev_connection_t *dev)
48{
49 usb_target_t target = {
50 .address = IPC_GET_ARG1(icall),
51 .endpoint = IPC_GET_ARG2(icall)
52 };
53 size_t len = IPC_GET_ARG3(icall);
54
55 if (!hub_can_device_signal(dev)) {
56 ipc_answer_0(iid, EREFUSED);
57 return;
58 }
59
60 dprintf("data from device %d [%d.%d]", dev->id,
61 target.address, target.endpoint);
62
63 int rc;
64
65 void * buffer = NULL;
66 if (len > 0) {
67 rc = async_data_write_accept(&buffer, false,
68 1, USB_MAX_PAYLOAD_SIZE,
69 0, &len);
70
71 if (rc != EOK) {
72 ipc_answer_0(iid, rc);
73 return;
74 }
75 }
76
77 rc = hc_fillin_transaction_from_device(target, buffer, len);
78
79 ipc_answer_0(iid, rc);
80}
81
82/** Connection handler for communcation with virtual device.
83 *
84 * @param phone_hash Incoming phone hash.
85 * @param dev Virtual device handle.
86 */
87void connection_handler_device(ipcarg_t phone_hash, virtdev_connection_t *dev)
88{
89 assert(dev != NULL);
90
91 dprintf("phone%#x: virtual device %d connected",
92 phone_hash, dev->id);
93
94 while (true) {
95 ipc_callid_t callid;
96 ipc_call_t call;
97
98 callid = async_get_call(&call);
99
100 switch (IPC_GET_METHOD(call)) {
101 case IPC_M_PHONE_HUNGUP:
102 ipc_hangup(dev->phone);
103 ipc_answer_0(callid, EOK);
104 dprintf("phone%#x: device %d hang-up",
105 phone_hash, dev->id);
106 return;
107
108 case IPC_M_CONNECT_TO_ME:
109 ipc_answer_0(callid, ELIMIT);
110 break;
111
112 case IPC_M_USBVIRT_DATA_FROM_DEVICE:
113 handle_data_from_device(callid, call, dev);
114 break;
115
116 default:
117 ipc_answer_0(callid, EINVAL);
118 break;
119 }
120 }
121}
122
123/**
124 * @}
125 */
Note: See TracBrowser for help on using the repository browser.