source: mainline/uspace/drv/vhc/conndev.c@ 138a7fd

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

Virtual USB devices can connect to VHC

Fixed and bypassed problems introduced by using DDF.

  • Property mode set to 100644
File size: 3.1 KB
RevLine 
[b371844]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>
[b8100da]38#include <usbvirt/hub.h>
[b371844]39
40#include "conn.h"
41#include "hc.h"
[b8507a1]42#include "hub.h"
[b371844]43
[ca07cd3]44#define DEVICE_NAME_MAXLENGTH 32
45
46static int get_device_name(int phone, char *buffer, size_t len)
47{
48 ipc_call_t answer_data;
49 ipcarg_t answer_rc;
50 aid_t req;
51 int rc;
52
53 req = async_send_0(phone,
54 IPC_M_USBVIRT_GET_NAME,
55 &answer_data);
56
57 rc = async_data_read_start(phone, buffer, len);
58 if (rc != EOK) {
59 async_wait_for(req, NULL);
60 return EINVAL;
61 }
62
63 async_wait_for(req, &answer_rc);
64 rc = (int)answer_rc;
65
66 if (IPC_GET_ARG1(answer_data) < len) {
67 len = IPC_GET_ARG1(answer_data);
68 } else {
69 len--;
70 }
71 buffer[len] = 0;
72
73 return rc;
74}
75
[e27595b]76/** Default handler for IPC methods not handled by DDF.
[355f7c2]77 *
[e27595b]78 * @param dev Device handling the call.
79 * @param icallid Call id.
80 * @param icall Call data.
[b371844]81 */
[e27595b]82void default_connection_handler(device_t *dev,
83 ipc_callid_t icallid, ipc_call_t *icall)
[b371844]84{
[e27595b]85 ipcarg_t method = IPC_GET_METHOD(*icall);
86
87 if (method == IPC_M_CONNECT_TO_ME) {
88 int callback = IPC_GET_ARG5(*icall);
89 virtdev_connection_t *dev
90 = virtdev_add_device(callback);
91 if (!dev) {
92 ipc_answer_0(icallid, EEXISTS);
93 ipc_hangup(callback);
94 return;
[b371844]95 }
[e27595b]96 ipc_answer_0(icallid, EOK);
97
98 char devname[DEVICE_NAME_MAXLENGTH + 1];
99 int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
100
101 dprintf(0, "virtual device connected (name: %s)",
102 rc == EOK ? devname : "<unknown>");
103
104 /* FIXME: destroy the device when the client disconnects. */
105
106 return;
[b371844]107 }
[e27595b]108
109 ipc_answer_0(icallid, EINVAL);
[b371844]110}
111
[e27595b]112
[b371844]113/**
114 * @}
115 */
Note: See TracBrowser for help on using the repository browser.