Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/conndev.c

    r6cb58e6 rbc1c6fb  
    11/*
    2  * Copyright (c) 2011 Vojtech Horky
     2 * Copyright (c) 2010 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
    33  * Connection handling of calls from virtual device (implementation).
     33 * @brief Connection handling of calls from virtual device (implementation).
    3434 */
    3535
    3636#include <assert.h>
    3737#include <errno.h>
    38 #include <ddf/driver.h>
     38#include <usbvirt/hub.h>
     39
    3940#include "conn.h"
     41#include "hc.h"
     42#include "hub.h"
    4043
    41 static fibril_local uintptr_t plugged_device_handle = 0;
     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        sysarg_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}
    4275
    4376/** Default handler for IPC methods not handled by DDF.
     
    5083    ipc_callid_t icallid, ipc_call_t *icall)
    5184{
    52         vhc_data_t *vhc = fun->dev->driver_data;
    5385        sysarg_t method = IPC_GET_IMETHOD(*icall);
    5486
    5587        if (method == IPC_M_CONNECT_TO_ME) {
    5688                int callback = IPC_GET_ARG5(*icall);
    57                 int rc = vhc_virtdev_plug(vhc, callback,
    58                     &plugged_device_handle);
    59                 if (rc != EOK) {
    60                         async_answer_0(icallid, rc);
     89                virtdev_connection_t *dev
     90                    = virtdev_add_device(callback, (sysarg_t)fibril_get_id());
     91                if (!dev) {
     92                        async_answer_0(icallid, EEXISTS);
    6193                        async_hangup(callback);
    6294                        return;
    6395                }
    64 
    6596                async_answer_0(icallid, EOK);
    6697
    67                 usb_log_info("New virtual device `%s' (id = %" PRIxn ").\n",
    68                     rc == EOK ? "XXX" : "<unknown>", plugged_device_handle);
     98                char devname[DEVICE_NAME_MAXLENGTH + 1];
     99                int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
     100
     101                usb_log_info("New virtual device `%s' (id = %x).\n",
     102                    rc == EOK ? devname : "<unknown>", dev->id);
    69103
    70104                return;
     
    74108}
    75109
    76 /** Callback when client disconnects.
     110/** Callback for DDF when client disconnects.
    77111 *
    78  * Used to unplug virtual USB device.
    79  *
    80  * @param fun
     112 * @param fun Device function the client was connected to.
    81113 */
    82114void on_client_close(ddf_fun_t *fun)
    83115{
    84         vhc_data_t *vhc = fun->dev->driver_data;
     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        }
    85123
    86         if (plugged_device_handle != 0) {
    87                 usb_log_info("Virtual device disconnected (id = %" PRIxn ").\n",
    88                     plugged_device_handle);
    89                 vhc_virtdev_unplug(vhc, plugged_device_handle);
    90         }
     124        usb_log_info("Virtual device disconnected (id = %x).\n", dev->id);
     125        virtdev_destroy_device(dev);
    91126}
    92127
Note: See TracChangeset for help on using the changeset viewer.