Changeset bc9a629 in mainline for uspace/srv/hw/bus/usb/hcd/virtual/hcd.c
- Timestamp:
- 2010-10-10T09:00:53Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b371844
- Parents:
- 4bc309b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/hw/bus/usb/hcd/virtual/hcd.c
r4bc309b rbc9a629 45 45 46 46 #include <usb/hcd.h> 47 #include <usb/virtdev.h> 47 48 #include "vhcd.h" 48 49 #include "hc.h" 50 #include "devices.h" 49 51 50 52 static usb_transaction_handle_t g_handle_seed = 1; … … 61 63 static void out_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg) 62 64 { 65 dprintf("out_callback(buffer, %u, %d, %p)", len, outcome, arg); 63 66 (void)len; 64 67 transaction_details_t * trans = (transaction_details_t *)arg; … … 72 75 static void in_callback(void * buffer, size_t len, usb_transaction_outcome_t outcome, void * arg) 73 76 { 77 dprintf("in_callback(buffer, %u, %d, %p)", len, outcome, arg); 74 78 transaction_details_t * trans = (transaction_details_t *)arg; 75 79 … … 140 144 141 145 dprintf("adding transaction to HC", NAME); 142 hc_add_ out_transaction(transf_type, target,146 hc_add_transaction_to_device(transf_type, target, 143 147 buffer, len, 144 148 out_callback, trans); … … 176 180 177 181 dprintf("adding transaction to HC", NAME); 178 hc_add_ in_transaction(transf_type, target,182 hc_add_transaction_from_device(transf_type, target, 179 183 buffer, len, 180 184 in_callback, trans); … … 184 188 } 185 189 190 static void handle_data_from_device(ipc_callid_t iid, ipc_call_t icall, virtdev_connection_t *dev) 191 { 192 usb_endpoint_t endpoint = IPC_GET_ARG1(icall); 193 usb_target_t target = { 194 .address = dev->address, 195 .endpoint = endpoint 196 }; 197 size_t len; 198 void * buffer; 199 int rc = async_data_write_accept(&buffer, false, 200 1, USB_MAX_PAYLOAD_SIZE, 201 0, &len); 202 203 if (rc != EOK) { 204 ipc_answer_0(iid, rc); 205 return; 206 } 207 208 rc = hc_fillin_transaction_from_device(USB_TRANSFER_INTERRUPT, target, buffer, len); 209 210 ipc_answer_0(iid, rc); 211 } 212 213 static virtdev_connection_t *recognise_device(int id, int callback_phone) 214 { 215 switch (id) { 216 case USB_VIRTDEV_KEYBOARD_ID: 217 return virtdev_add_device( 218 USB_VIRTDEV_KEYBOARD_ADDRESS, callback_phone); 219 default: 220 return NULL; 221 } 222 } 223 224 static void device_client_connection(int callback_phone, int device_id) 225 { 226 virtdev_connection_t *dev = recognise_device(device_id, callback_phone); 227 if (!dev) { 228 if (callback_phone != -1) { 229 ipc_hangup(callback_phone); 230 } 231 return; 232 } 233 dprintf("device %d connected", device_id); 234 while (true) { 235 ipc_callid_t callid; 236 ipc_call_t call; 237 238 callid = async_get_call(&call); 239 240 switch (IPC_GET_METHOD(call)) { 241 case IPC_M_PHONE_HUNGUP: 242 if (callback_phone != -1) { 243 ipc_hangup(callback_phone); 244 } 245 ipc_answer_0(callid, EOK); 246 dprintf("hung-up on device %d", device_id); 247 virtdev_destroy_device(dev); 248 return; 249 case IPC_M_CONNECT_TO_ME: 250 ipc_answer_0(callid, ELIMIT); 251 break; 252 case IPC_M_USB_VIRTDEV_DATA_FROM_DEVICE: 253 dprintf("data from device %d", device_id); 254 handle_data_from_device(callid, call, dev); 255 break; 256 default: 257 ipc_answer_0(callid, EINVAL); 258 break; 259 } 260 } 261 } 186 262 187 263 static void client_connection(ipc_callid_t iid, ipc_call_t *icall) … … 216 292 ipc_answer_0(callid, EOK); 217 293 } 294 if (IPC_GET_ARG1(call) == 1) { 295 /* Virtual device was just connected 296 * to us. This is handled elsewhere. 297 */ 298 device_client_connection(callback_phone, 299 IPC_GET_ARG2(call)); 300 return; 301 } 218 302 break; 219 303
Note:
See TracChangeset
for help on using the changeset viewer.