source: mainline/uspace/drv/vhc/conndev.c@ 3b5d1535

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

Merge mainline changes (DDF refactoring)

This merge includes DDF refactoring that brought multifunctional devices
(i.e. ddf_dev_t and ddf_fun_t). Please, see ticket #295 at HelenOS
upstream Trac.

The conflicts themselves were easy to solve (merely several renamings).

Changes to USB subsystem:

  • drivers uses ddf_dev_t and ddf_fun_t
  • different signatures of many library functions
  • several hacks around communication with parent device (now the communication is clearer and somehow what we have now is hack about other hacks)
    • will repair and clean later
  • maybe added some extra debugging messages (the diff has about 240K, and I admit I have no energy to double check that)

WARNING:

  • the diff is VERY long, recommended is viewing partial diffs of the merge (i.e. merges in mainline branch that lead to the parent one)
  • merging with your branches might involve huge renamings, sorry, no other way is possible

BUGS:

  • hub driver will not work (no function created)

GOOD NEWS:

  • QEMU keyboard seems to work with QEMU 0.13 and 0.14
  • we are up-to-date with mainline again
  • Property mode set to 100644
File size: 3.5 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
[bd8c753d]29/** @addtogroup drvusbvhc
[b371844]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;
[a9b6bec]49 sysarg_t answer_rc;
[ca07cd3]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 *
[eb1a2f4]78 * @param fun Device handling the call.
[e27595b]79 * @param icallid Call id.
80 * @param icall Call data.
[b371844]81 */
[eb1a2f4]82void default_connection_handler(ddf_fun_t *fun,
[e27595b]83 ipc_callid_t icallid, ipc_call_t *icall)
[b371844]84{
[a9b6bec]85 sysarg_t method = IPC_GET_IMETHOD(*icall);
[e27595b]86
87 if (method == IPC_M_CONNECT_TO_ME) {
88 int callback = IPC_GET_ARG5(*icall);
89 virtdev_connection_t *dev
[6967c14]90 = virtdev_add_device(callback, (sysarg_t)fibril_get_id());
[e27595b]91 if (!dev) {
[17aca1c]92 async_answer_0(icallid, EEXISTS);
93 async_hangup(callback);
[e27595b]94 return;
[b371844]95 }
[17aca1c]96 async_answer_0(icallid, EOK);
[e27595b]97
98 char devname[DEVICE_NAME_MAXLENGTH + 1];
99 int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
100
[0b31409]101 usb_log_info("New virtual device `%s' (id = %x).\n",
[6967c14]102 rc == EOK ? devname : "<unknown>", dev->id);
[e27595b]103
104 return;
[b371844]105 }
[e27595b]106
[17aca1c]107 async_answer_0(icallid, EINVAL);
[b371844]108}
109
[6967c14]110/** Callback for DDF when client disconnects.
111 *
112 * @param d Device the client was connected to.
113 */
[eb1a2f4]114void on_client_close(ddf_fun_t *fun)
[6967c14]115{
116 /*
117 * Maybe a virtual device is being unplugged.
118 */
119 virtdev_connection_t *dev = virtdev_find((sysarg_t)fibril_get_id());
120 if (dev == NULL) {
121 return;
122 }
123
[0b31409]124 usb_log_info("Virtual device disconnected (id = %x).\n", dev->id);
[6967c14]125 virtdev_destroy_device(dev);
126}
127
[e27595b]128
[b371844]129/**
130 * @}
131 */
Note: See TracBrowser for help on using the repository browser.