Changeset b8100da in mainline for uspace/lib/usbvirt/main.c
- Timestamp:
- 2010-10-10T17:01:40Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6c1315b
- Parents:
- b371844
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbvirt/main.c
rb371844 rb8100da 27 27 */ 28 28 29 /** @addtogroup libusb usb29 /** @addtogroup libusbvirt usb 30 30 * @{ 31 31 */ 32 32 /** @file 33 * @brief Virtual USB device (implementation).33 * @brief Main handler for virtual USB device. 34 34 */ 35 #include "virtdev.h"36 35 #include <devmap.h> 37 36 #include <fcntl.h> … … 40 39 #include <stdlib.h> 41 40 41 #include "hub.h" 42 #include "device.h" 43 #include "private.h" 44 42 45 #define NAMESPACE "usb" 43 46 44 static usb_virtdev_on_data_from_host_t on_data_from_host = NULL; 47 usbvirt_device_t *device = NULL; 48 45 49 46 50 static void handle_data_to_device(ipc_callid_t iid, ipc_call_t icall) … … 59 63 } 60 64 61 on_data_from_host(endpoint, buffer, len);65 handle_incoming_data(endpoint, buffer, len); 62 66 63 67 free(buffer); … … 80 84 return; 81 85 82 case IPC_M_USB _VIRTDEV_DATA_TO_DEVICE:86 case IPC_M_USBVIRT_DATA_TO_DEVICE: 83 87 handle_data_to_device(callid, call); 84 88 break; … … 89 93 } 90 94 } 95 } 96 97 int usbvirt_data_to_host(struct usbvirt_device *dev, 98 usb_endpoint_t endpoint, void *buffer, size_t size) 99 { 100 int phone = dev->vhcd_phone_; 101 102 if (phone < 0) { 103 return EINVAL; 104 } 105 if ((buffer == NULL) || (size == 0)) { 106 return EINVAL; 107 } 108 109 ipc_call_t answer_data; 110 ipcarg_t answer_rc; 111 aid_t req; 112 int rc; 113 114 req = async_send_1(phone, 115 IPC_M_USBVIRT_DATA_FROM_DEVICE, 116 endpoint, 117 &answer_data); 118 119 rc = async_data_write_start(phone, buffer, size); 120 if (rc != EOK) { 121 async_wait_for(req, NULL); 122 return rc; 123 } 124 125 async_wait_for(req, &answer_rc); 126 rc = (int)answer_rc; 127 if (rc != EOK) { 128 return rc; 129 } 130 131 return EOK; 91 132 } 92 133 … … 107 148 * @param device_id Internal device identification (used by HCD). 108 149 * @param callback Handler for callbacks from HCD. 109 * @return Phone for comunicating with HCDor error code from errno.h.150 * @return EOK on success or error code from errno.h. 110 151 */ 111 int usb_virtdev_connect(const char *hcd_path, int device_id, 112 usb_virtdev_on_data_from_host_t callback) 152 int usbvirt_connect(usbvirt_device_t *dev, const char *hcd_path) 113 153 { 114 154 char dev_path[DEVMAP_NAME_MAXLEN + 1]; … … 128 168 129 169 ipcarg_t phonehash; 130 int rc = ipc_connect_to_me(hcd_phone, 1, device_id, 0, &phonehash); 131 if (rc != EOK) { 132 return rc; 133 } 134 on_data_from_host = callback; 135 async_new_connection(phonehash, 0, NULL, callback_connection); 136 137 return hcd_phone; 138 } 139 140 int usb_virtdev_data_to_host(int phone, 141 usb_endpoint_t endpoint, 142 void * buffer, size_t size) 143 { 144 if (phone < 0) { 145 return EINVAL; 146 } 147 if ((buffer == NULL) || (size == 0)) { 148 return EINVAL; 149 } 150 151 ipc_call_t answer_data; 152 ipcarg_t answer_rc; 153 aid_t req; 154 int rc; 155 156 req = async_send_1(phone, 157 IPC_M_USB_VIRTDEV_DATA_FROM_DEVICE, 158 endpoint, 159 &answer_data); 160 161 rc = async_data_write_start(phone, buffer, size); 162 if (rc != EOK) { 163 async_wait_for(req, NULL); 164 return rc; 165 } 166 167 async_wait_for(req, &answer_rc); 168 rc = (int)answer_rc; 170 int rc = ipc_connect_to_me(hcd_phone, 1, dev->device_id_, 0, &phonehash); 169 171 if (rc != EOK) { 170 172 return rc; 171 173 } 172 174 175 dev->vhcd_phone_ = hcd_phone; 176 dev->send_data = usbvirt_data_to_host; 177 178 device = dev; 179 180 async_new_connection(phonehash, 0, NULL, callback_connection); 181 173 182 return EOK; 174 183 } 184 185 186 int usbvirt_disconnect(void) 187 { 188 ipc_hangup(device->vhcd_phone_); 189 190 device = NULL; 191 192 return EOK; 193 } 194 175 195 176 196 /**
Note:
See TracChangeset
for help on using the changeset viewer.