Changeset b8100da in mainline for uspace/lib
- Timestamp:
- 2010-10-10T17:01:40Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 6c1315b
- Parents:
- b371844
- Location:
- uspace/lib
- Files:
-
- 7 added
- 1 edited
- 2 moved
-
usb/Makefile (modified) (1 diff)
-
usb/devreq.h (moved) (moved from uspace/lib/usb/virtdev.h ) (1 diff)
-
usbvirt/Makefile (added)
-
usbvirt/ctrlpipe.c (added)
-
usbvirt/device.h (added)
-
usbvirt/hub.h (added)
-
usbvirt/ids.h (added)
-
usbvirt/incoming.c (added)
-
usbvirt/main.c (moved) (moved from uspace/lib/usb/virtdev.c ) (7 diffs)
-
usbvirt/private.h (added)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usb/Makefile
rb371844 rb8100da 31 31 32 32 SOURCES = \ 33 hcd.c \ 34 virtdev.c 33 hcd.c 35 34 36 35 include $(USPACE_PREFIX)/Makefile.common -
uspace/lib/usb/devreq.h
rb371844 rb8100da 31 31 */ 32 32 /** @file 33 * @brief Virtual USB device.33 * @brief Standard USB device requests. 34 34 */ 35 #ifndef LIBUSB_ VIRTDEV_H_36 #define LIBUSB_ VIRTDEV_H_35 #ifndef LIBUSB_DEVREQ_H_ 36 #define LIBUSB_DEVREQ_H_ 37 37 38 38 #include <ipc/ipc.h> 39 39 #include <async.h> 40 #include "hcd.h"41 40 42 #define USB_VIRTDEV_KEYBOARD_ID 1 43 #define USB_VIRTDEV_KEYBOARD_ADDRESS 1 41 /** Standard device request. */ 42 typedef enum { 43 USB_DEVREQ_GET_STATUS = 0, 44 USB_DEVREQ_CLEAR_FEATURE = 1, 45 USB_DEVREQ_SET_FEATURE = 3, 46 USB_DEVREQ_SET_ADDRESS = 5, 47 USB_DEVREQ_GET_DESCRIPTOR = 6, 48 USB_DEVREQ_SET_DESCRIPTOR = 7, 49 USB_DEVREQ_GET_CONFIGURATION = 8, 50 USB_DEVREQ_SET_CONFIGURATION = 9, 51 USB_DEVREQ_GET_INTERFACE = 10, 52 USB_DEVREQ_SET_INTERFACE = 11, 53 USB_DEVREQ_SYNCH_FRAME = 12 54 } usb_stddevreq_t; 44 55 45 typedef void (*usb_virtdev_on_data_from_host_t)(usb_endpoint_t, void *, size_t);46 56 47 int usb_virtdev_connect(const char *, int, usb_virtdev_on_data_from_host_t);48 int usb_virtdev_data_to_host(int, usb_endpoint_t,49 void *, size_t);50 51 typedef enum {52 IPC_M_USB_VIRTDEV_DATA_TO_DEVICE = IPC_FIRST_USER_METHOD,53 IPC_M_USB_VIRTDEV_DATA_FROM_DEVICE54 } usb_virtdev_method_t;55 57 56 58 #endif -
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.
