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