00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00036 #include <assert.h>
00037 #include <errno.h>
00038 #include <ddf/driver.h>
00039 #include <usbvirt/ipc.h>
00040 #include "conn.h"
00041
00042 static fibril_local uintptr_t plugged_device_handle = 0;
00043 #define PLUGGED_DEVICE_NAME_MAXLEN 256
00044 static fibril_local char plugged_device_name[PLUGGED_DEVICE_NAME_MAXLEN + 1] = "<unknown>";
00045
00052 static void receive_device_name(int phone)
00053 {
00054 aid_t opening_request = async_send_0(phone, IPC_M_USBVIRT_GET_NAME, NULL);
00055 if (opening_request == 0) {
00056 return;
00057 }
00058
00059
00060 ipc_call_t data_request_call;
00061 aid_t data_request = async_data_read(phone,
00062 plugged_device_name, PLUGGED_DEVICE_NAME_MAXLEN,
00063 &data_request_call);
00064
00065 if (data_request == 0) {
00066 async_wait_for(opening_request, NULL);
00067 return;
00068 }
00069
00070 sysarg_t data_request_rc;
00071 sysarg_t opening_request_rc;
00072 async_wait_for(data_request, &data_request_rc);
00073 async_wait_for(opening_request, &opening_request_rc);
00074
00075 if ((data_request_rc != EOK) || (opening_request_rc != EOK)) {
00076 return;
00077 }
00078
00079 size_t len = IPC_GET_ARG2(data_request_call);
00080 plugged_device_name[len] = 0;
00081 }
00082
00089 void default_connection_handler(ddf_fun_t *fun,
00090 ipc_callid_t icallid, ipc_call_t *icall)
00091 {
00092 vhc_data_t *vhc = fun->dev->driver_data;
00093 sysarg_t method = IPC_GET_IMETHOD(*icall);
00094
00095 if (method == IPC_M_CONNECT_TO_ME) {
00096 int callback = IPC_GET_ARG5(*icall);
00097 int rc = vhc_virtdev_plug(vhc, callback,
00098 &plugged_device_handle);
00099 if (rc != EOK) {
00100 async_answer_0(icallid, rc);
00101 async_hangup(callback);
00102 return;
00103 }
00104
00105 async_answer_0(icallid, EOK);
00106
00107 receive_device_name(callback);
00108
00109 usb_log_info("New virtual device `%s' (id: %" PRIxn ").\n",
00110 plugged_device_name, plugged_device_handle);
00111
00112 return;
00113 }
00114
00115 async_answer_0(icallid, EINVAL);
00116 }
00117
00124 void on_client_close(ddf_fun_t *fun)
00125 {
00126 vhc_data_t *vhc = fun->dev->driver_data;
00127
00128 if (plugged_device_handle != 0) {
00129 usb_log_info("Virtual device `%s' disconnected (id: %" PRIxn ").\n",
00130 plugged_device_name, plugged_device_handle);
00131 vhc_virtdev_unplug(vhc, plugged_device_handle);
00132 }
00133 }
00134
00135