Changes in uspace/drv/vhc/conndev.c [6cb58e6:bc1c6fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/conndev.c
r6cb58e6 rbc1c6fb 1 1 /* 2 * Copyright (c) 201 1Vojtech Horky2 * Copyright (c) 2010 Vojtech Horky 3 3 * All rights reserved. 4 4 * … … 31 31 */ 32 32 /** @file 33 * Connection handling of calls from virtual device (implementation).33 * @brief Connection handling of calls from virtual device (implementation). 34 34 */ 35 35 36 36 #include <assert.h> 37 37 #include <errno.h> 38 #include <ddf/driver.h> 38 #include <usbvirt/hub.h> 39 39 40 #include "conn.h" 41 #include "hc.h" 42 #include "hub.h" 40 43 41 static fibril_local uintptr_t plugged_device_handle = 0; 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 } 42 75 43 76 /** Default handler for IPC methods not handled by DDF. … … 50 83 ipc_callid_t icallid, ipc_call_t *icall) 51 84 { 52 vhc_data_t *vhc = fun->dev->driver_data;53 85 sysarg_t method = IPC_GET_IMETHOD(*icall); 54 86 55 87 if (method == IPC_M_CONNECT_TO_ME) { 56 88 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); 61 93 async_hangup(callback); 62 94 return; 63 95 } 64 65 96 async_answer_0(icallid, EOK); 66 97 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); 69 103 70 104 return; … … 74 108 } 75 109 76 /** Callback when client disconnects.110 /** Callback for DDF when client disconnects. 77 111 * 78 * Used to unplug virtual USB device. 79 * 80 * @param fun 112 * @param fun Device function the client was connected to. 81 113 */ 82 114 void on_client_close(ddf_fun_t *fun) 83 115 { 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 } 85 123 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); 91 126 } 92 127
Note:
See TracChangeset
for help on using the changeset viewer.