Changeset e27595b in mainline for uspace/drv/vhc


Ignore:
Timestamp:
2010-11-20T13:04:15Z (15 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0e126be7
Parents:
7034be15
Message:

Virtual USB devices can connect to VHC

Fixed and bypassed problems introduced by using DDF.

Location:
uspace/drv/vhc
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/vhc/conn.h

    r7034be15 re27595b  
    4242
    4343void connection_handler_host(ipcarg_t);
    44 void connection_handler_device(ipcarg_t, virtdev_connection_t *);
     44
    4545usb_hcd_transfer_ops_t vhc_transfer_ops;
     46
     47void default_connection_handler(device_t *, ipc_callid_t, ipc_call_t *);
     48
    4649
    4750#endif
  • uspace/drv/vhc/conndev.c

    r7034be15 re27595b  
    7474}
    7575
    76 /** Connection handler for communcation with virtual device.
     76/** Default handler for IPC methods not handled by DDF.
    7777 *
    78  * This function also takes care of proper phone hung-up.
    79  *
    80  * @param phone_hash Incoming phone hash.
    81  * @param dev Virtual device handle.
     78 * @param dev Device handling the call.
     79 * @param icallid Call id.
     80 * @param icall Call data.
    8281 */
    83 void connection_handler_device(ipcarg_t phone_hash, virtdev_connection_t *dev)
     82void default_connection_handler(device_t *dev,
     83    ipc_callid_t icallid, ipc_call_t *icall)
    8484{
    85         assert(dev != NULL);
    86        
    87         char devname[DEVICE_NAME_MAXLENGTH + 1];
    88         int rc = get_device_name(dev->phone, devname, DEVICE_NAME_MAXLENGTH);
    89        
    90         dprintf(0, "virtual device connected (phone: %#x, name: %s)",
    91             phone_hash, rc == EOK ? devname : "<unknown>");
    92        
    93        
    94         while (true) {
    95                 ipc_callid_t callid;
    96                 ipc_call_t call;
    97                
    98                 callid = async_get_call(&call);
    99                
    100                 switch (IPC_GET_METHOD(call)) {
    101                         case IPC_M_PHONE_HUNGUP:
    102                                 ipc_hangup(dev->phone);
    103                                 ipc_answer_0(callid, EOK);
    104                                 dprintf(0, "phone%#x: device hung-up",
    105                                     phone_hash);
    106                                 return;
    107                        
    108                         case IPC_M_CONNECT_TO_ME:
    109                                 ipc_answer_0(callid, ELIMIT);
    110                                 break;
    111                        
    112                         default:
    113                                 dprintf_inval_call(2, call, phone_hash);
    114                                 ipc_answer_0(callid, EINVAL);
    115                                 break;
     85        ipcarg_t method = IPC_GET_METHOD(*icall);
     86
     87        if (method == IPC_M_CONNECT_TO_ME) {
     88                int callback = IPC_GET_ARG5(*icall);
     89                virtdev_connection_t *dev
     90                    = virtdev_add_device(callback);
     91                if (!dev) {
     92                        ipc_answer_0(icallid, EEXISTS);
     93                        ipc_hangup(callback);
     94                        return;
    11695                }
     96                ipc_answer_0(icallid, EOK);
     97
     98                char devname[DEVICE_NAME_MAXLENGTH + 1];
     99                int rc = get_device_name(callback, devname, DEVICE_NAME_MAXLENGTH);
     100
     101                dprintf(0, "virtual device connected (name: %s)",
     102                    rc == EOK ? devname : "<unknown>");
     103
     104                /* FIXME: destroy the device when the client disconnects. */
     105
     106                return;
    117107        }
     108
     109        ipc_answer_0(icallid, EINVAL);
    118110}
     111
    119112
    120113/**
  • uspace/drv/vhc/devices.h

    r7034be15 re27595b  
    5050
    5151virtdev_connection_t *virtdev_add_device(int);
     52virtdev_connection_t *virtdev_get_mine(void);
    5253void virtdev_destroy_device(virtdev_connection_t *);
    5354usb_transaction_outcome_t virtdev_send_to_all(transaction_t *);
  • uspace/drv/vhc/hcd.c

    r7034be15 re27595b  
    5252#include "conn.h"
    5353
     54
    5455static int vhc_count = 0;
    5556static int vhc_add_device(usb_hc_device_t *dev)
    5657{
    57         printf("%s: new device registered.\n", NAME);
    5858        /*
    5959         * Currently, we know how to simulate only single HC.
     
    6666
    6767        dev->transfer_ops = &vhc_transfer_ops;
     68        dev->generic->ops->default_handler = default_connection_handler;
    6869
    6970        /*
     
    7172         */
    7273        usb_hcd_add_root_hub(dev);
     74
     75        printf("%s: virtual USB host controller ready.\n", NAME);
    7376
    7477        return EOK;
     
    8487        printf("%s: virtual USB host controller driver.\n", NAME);
    8588
     89        debug_level = 5;
     90
    8691        return usb_hcd_main(&vhc_driver);
    8792}
Note: See TracChangeset for help on using the changeset viewer.