Changeset 54d71e1 in mainline for uspace/drv/vhc/conndev.c


Ignore:
Timestamp:
2011-04-29T07:05:30Z (13 years ago)
Author:
Matus Dekanek <smekideki@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
361fcec
Parents:
9014dcd (diff), cd4ae1e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge with development

File:
1 edited

Legend:

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

    r9014dcd r54d71e1  
    11/*
    2  * Copyright (c) 2010 Vojtech Horky
     2 * Copyright (c) 2011 Vojtech Horky
    33 * All rights reserved.
    44 *
     
    3131 */
    3232/** @file
    33  * @brief Connection handling of calls from virtual device (implementation).
     33 * Connection handling of calls from virtual device (implementation).
    3434 */
    3535
    3636#include <assert.h>
    3737#include <errno.h>
    38 #include <usbvirt/hub.h>
     38#include <ddf/driver.h>
     39#include "conn.h"
    3940
    40 #include "conn.h"
    41 #include "hc.h"
    42 #include "hub.h"
    43 
    44 #define DEVICE_NAME_MAXLENGTH 32
    45 
    46 static 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 }
     41static fibril_local uintptr_t plugged_device_handle = 0;
    7542
    7643/** Default handler for IPC methods not handled by DDF.
     
    8350    ipc_callid_t icallid, ipc_call_t *icall)
    8451{
     52        vhc_data_t *vhc = fun->dev->driver_data;
    8553        sysarg_t method = IPC_GET_IMETHOD(*icall);
    8654
    8755        if (method == IPC_M_CONNECT_TO_ME) {
    8856                int callback = IPC_GET_ARG5(*icall);
    89                 virtdev_connection_t *dev
    90                     = virtdev_add_device(callback, (sysarg_t)fibril_get_id());
    91                 if (!dev) {
    92                         async_answer_0(icallid, EEXISTS);
     57                int rc = vhc_virtdev_plug(vhc, callback,
     58                    &plugged_device_handle);
     59                if (rc != EOK) {
     60                        async_answer_0(icallid, rc);
    9361                        async_hangup(callback);
    9462                        return;
    9563                }
     64
    9665                async_answer_0(icallid, EOK);
    9766
    98                 char devname[DEVICE_NAME_MAXLENGTH + 1];
    99                 int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
    100 
    10167                usb_log_info("New virtual device `%s' (id = %" PRIxn ").\n",
    102                     rc == EOK ? devname : "<unknown>", dev->id);
     68                    rc == EOK ? "XXX" : "<unknown>", plugged_device_handle);
    10369
    10470                return;
     
    10874}
    10975
    110 /** Callback for DDF when client disconnects.
     76/** Callback when client disconnects.
    11177 *
    112  * @param fun Device function the client was connected to.
     78 * Used to unplug virtual USB device.
     79 *
     80 * @param fun
    11381 */
    11482void on_client_close(ddf_fun_t *fun)
    11583{
    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;
     84        vhc_data_t *vhc = fun->dev->driver_data;
     85
     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);
    12290        }
    123 
    124         usb_log_info("Virtual device disconnected (id = %" PRIxn ").\n",
    125             dev->id);
    126         virtdev_destroy_device(dev);
    12791}
    12892
Note: See TracChangeset for help on using the changeset viewer.