source: mainline/uspace/drv/vhc/conndev.c@ 79ae36dd

lfn serial ticket/834-toolchain-update topic/fix-logger-deadlock topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 79ae36dd was 79ae36dd, checked in by Martin Decky <martin@…>, 15 years ago

new async framework with integrated exchange tracking

  • strict isolation between low-level IPC and high-level async framework with integrated exchange tracking
    • each IPC connection is represented by an async_sess_t structure
    • each IPC exchange is represented by an async_exch_t structure
    • exchange management is either based on atomic messages (EXCHANGE_ATOMIC), locking (EXCHANGE_SERIALIZE) or connection cloning (EXCHANGE_CLONE)
  • async_obsolete: temporary compatibility layer to keep old async clients working (several pieces of code are currently broken, but only non-essential functionality)
  • IPC_M_PHONE_HANGUP is now method no. 0 (for elegant boolean evaluation)
  • IPC_M_DEBUG_ALL has been renamed to IPC_M_DEBUG
  • IPC_M_PING has been removed (VFS protocol now has VFS_IN_PING)
  • console routines in libc have been rewritten for better abstraction
  • additional use for libc-private header files (FILE structure opaque to the client)
  • various cstyle changes (typos, indentation, missing externs in header files, improved comments, etc.)
  • Property mode set to 100644
File size: 4.1 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>
[79ae36dd]40#include <async.h>
[b371844]41#include "conn.h"
[ca07cd3]42
[6cb58e6]43static fibril_local uintptr_t plugged_device_handle = 0;
[00b6c73]44#define PLUGGED_DEVICE_NAME_MAXLEN 256
45static fibril_local char plugged_device_name[PLUGGED_DEVICE_NAME_MAXLEN + 1] = "<unknown>";
46
[79ae36dd]47#if 0
[00b6c73]48/** Receive device name.
49 *
50 * @warning Errors are silently ignored.
51 *
[79ae36dd]52 * @param sess Session to the virtual device.
53 *
[00b6c73]54 */
[79ae36dd]55static void receive_device_name(async_sess_t *sess)
[00b6c73]56{
[79ae36dd]57 async_exch_t *exch = async_exchange_begin(sess);
58
59 aid_t opening_request = async_send_0(exch, IPC_M_USBVIRT_GET_NAME, NULL);
[00b6c73]60 if (opening_request == 0) {
[79ae36dd]61 async_exchange_end(exch);
[00b6c73]62 return;
63 }
[79ae36dd]64
[00b6c73]65 ipc_call_t data_request_call;
[79ae36dd]66 aid_t data_request = async_data_read(exch, plugged_device_name,
67 PLUGGED_DEVICE_NAME_MAXLEN, &data_request_call);
68
69 async_exchange_end(exch);
70
[00b6c73]71 if (data_request == 0) {
72 async_wait_for(opening_request, NULL);
73 return;
74 }
[79ae36dd]75
[00b6c73]76 sysarg_t data_request_rc;
77 sysarg_t opening_request_rc;
78 async_wait_for(data_request, &data_request_rc);
79 async_wait_for(opening_request, &opening_request_rc);
[79ae36dd]80
81 if ((data_request_rc != EOK) || (opening_request_rc != EOK))
[00b6c73]82 return;
[79ae36dd]83
[00b6c73]84 size_t len = IPC_GET_ARG2(data_request_call);
85 plugged_device_name[len] = 0;
86}
[79ae36dd]87#endif
[ca07cd3]88
[e27595b]89/** Default handler for IPC methods not handled by DDF.
[355f7c2]90 *
[eb1a2f4]91 * @param fun Device handling the call.
[e27595b]92 * @param icallid Call id.
93 * @param icall Call data.
[b371844]94 */
[eb1a2f4]95void default_connection_handler(ddf_fun_t *fun,
[e27595b]96 ipc_callid_t icallid, ipc_call_t *icall)
[b371844]97{
[79ae36dd]98// FIXME:
99// This code needs to be refactored since the async
100// framework does not support automatic callback connections
101// yet.
102
103#if 0
[6cb58e6]104 vhc_data_t *vhc = fun->dev->driver_data;
[a9b6bec]105 sysarg_t method = IPC_GET_IMETHOD(*icall);
[e27595b]106
107 if (method == IPC_M_CONNECT_TO_ME) {
108 int callback = IPC_GET_ARG5(*icall);
[6cb58e6]109 int rc = vhc_virtdev_plug(vhc, callback,
110 &plugged_device_handle);
111 if (rc != EOK) {
112 async_answer_0(icallid, rc);
[17aca1c]113 async_hangup(callback);
[e27595b]114 return;
[b371844]115 }
[e27595b]116
[6cb58e6]117 async_answer_0(icallid, EOK);
[e27595b]118
[00b6c73]119 receive_device_name(callback);
120
121 usb_log_info("New virtual device `%s' (id: %" PRIxn ").\n",
122 plugged_device_name, plugged_device_handle);
[e27595b]123
124 return;
[b371844]125 }
[79ae36dd]126#endif
[e27595b]127
[17aca1c]128 async_answer_0(icallid, EINVAL);
[b371844]129}
130
[6cb58e6]131/** Callback when client disconnects.
132 *
133 * Used to unplug virtual USB device.
[6967c14]134 *
[6cb58e6]135 * @param fun
[6967c14]136 */
[eb1a2f4]137void on_client_close(ddf_fun_t *fun)
[6967c14]138{
[6cb58e6]139 vhc_data_t *vhc = fun->dev->driver_data;
[6967c14]140
[6cb58e6]141 if (plugged_device_handle != 0) {
[00b6c73]142 usb_log_info("Virtual device `%s' disconnected (id: %" PRIxn ").\n",
143 plugged_device_name, plugged_device_handle);
[6cb58e6]144 vhc_virtdev_unplug(vhc, plugged_device_handle);
145 }
[6967c14]146}
147
[e27595b]148
[b371844]149/**
150 * @}
151 */
Note: See TracBrowser for help on using the repository browser.