source: mainline/uspace/drv/vhc/conndev.c@ 030937e

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

Virtual HC prints name of connected device

  • Property mode set to 100644
File size: 3.9 KB
RevLine 
[b371844]1/*
[6cb58e6]2 * Copyright (c) 2011 Vojtech Horky
[b371844]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
[bd8c753d]29/** @addtogroup drvusbvhc
[b371844]30 * @{
31 */
32/** @file
[6cb58e6]33 * Connection handling of calls from virtual device (implementation).
[b371844]34 */
35
36#include <assert.h>
37#include <errno.h>
[6cb58e6]38#include <ddf/driver.h>
[00b6c73]39#include <usbvirt/ipc.h>
[b371844]40#include "conn.h"
[ca07cd3]41
[6cb58e6]42static fibril_local uintptr_t plugged_device_handle = 0;
[00b6c73]43#define PLUGGED_DEVICE_NAME_MAXLEN 256
44static fibril_local char plugged_device_name[PLUGGED_DEVICE_NAME_MAXLEN + 1] = "<unknown>";
45
46/** Receive device name.
47 *
48 * @warning Errors are silently ignored.
49 *
50 * @param phone Phone to the virtual device.
51 */
52static void receive_device_name(int phone)
53{
54 aid_t opening_request = async_send_0(phone, IPC_M_USBVIRT_GET_NAME, NULL);
55 if (opening_request == 0) {
56 return;
57 }
58
59
60 ipc_call_t data_request_call;
61 aid_t data_request = async_data_read(phone,
62 plugged_device_name, PLUGGED_DEVICE_NAME_MAXLEN,
63 &data_request_call);
64
65 if (data_request == 0) {
66 async_wait_for(opening_request, NULL);
67 return;
68 }
69
70 sysarg_t data_request_rc;
71 sysarg_t opening_request_rc;
72 async_wait_for(data_request, &data_request_rc);
73 async_wait_for(opening_request, &opening_request_rc);
74
75 if ((data_request_rc != EOK) || (opening_request_rc != EOK)) {
76 return;
77 }
78
79 size_t len = IPC_GET_ARG2(data_request_call);
80 plugged_device_name[len] = 0;
81}
[ca07cd3]82
[e27595b]83/** Default handler for IPC methods not handled by DDF.
[355f7c2]84 *
[eb1a2f4]85 * @param fun Device handling the call.
[e27595b]86 * @param icallid Call id.
87 * @param icall Call data.
[b371844]88 */
[eb1a2f4]89void default_connection_handler(ddf_fun_t *fun,
[e27595b]90 ipc_callid_t icallid, ipc_call_t *icall)
[b371844]91{
[6cb58e6]92 vhc_data_t *vhc = fun->dev->driver_data;
[a9b6bec]93 sysarg_t method = IPC_GET_IMETHOD(*icall);
[e27595b]94
95 if (method == IPC_M_CONNECT_TO_ME) {
96 int callback = IPC_GET_ARG5(*icall);
[6cb58e6]97 int rc = vhc_virtdev_plug(vhc, callback,
98 &plugged_device_handle);
99 if (rc != EOK) {
100 async_answer_0(icallid, rc);
[17aca1c]101 async_hangup(callback);
[e27595b]102 return;
[b371844]103 }
[e27595b]104
[6cb58e6]105 async_answer_0(icallid, EOK);
[e27595b]106
[00b6c73]107 receive_device_name(callback);
108
109 usb_log_info("New virtual device `%s' (id: %" PRIxn ").\n",
110 plugged_device_name, plugged_device_handle);
[e27595b]111
112 return;
[b371844]113 }
[e27595b]114
[17aca1c]115 async_answer_0(icallid, EINVAL);
[b371844]116}
117
[6cb58e6]118/** Callback when client disconnects.
119 *
120 * Used to unplug virtual USB device.
[6967c14]121 *
[6cb58e6]122 * @param fun
[6967c14]123 */
[eb1a2f4]124void on_client_close(ddf_fun_t *fun)
[6967c14]125{
[6cb58e6]126 vhc_data_t *vhc = fun->dev->driver_data;
[6967c14]127
[6cb58e6]128 if (plugged_device_handle != 0) {
[00b6c73]129 usb_log_info("Virtual device `%s' disconnected (id: %" PRIxn ").\n",
130 plugged_device_name, plugged_device_handle);
[6cb58e6]131 vhc_virtdev_unplug(vhc, plugged_device_handle);
132 }
[6967c14]133}
134
[e27595b]135
[b371844]136/**
137 * @}
138 */
Note: See TracBrowser for help on using the repository browser.