Changeset b8100da in mainline
- 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
- Location:
- uspace
- Files:
-
- 7 added
- 9 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
uspace/Makefile
rb371844 rb8100da 142 142 LIBS += lib/pci 143 143 LIBS += lib/usb 144 LIBS += lib/usbvirt 144 145 endif 145 146 … … 147 148 LIBS += lib/pci 148 149 LIBS += lib/usb 150 LIBS += lib/usbvirt 149 151 endif 150 152 -
uspace/Makefile.common
rb371844 rb8100da 88 88 LIBPCI_PREFIX = $(LIB_PREFIX)/pci 89 89 LIBUSB_PREFIX = $(LIB_PREFIX)/usb 90 LIBUSBVIRT_PREFIX = $(LIB_PREFIX)/usbvirt 90 91 91 92 LIBSOCKET_PREFIX = $(LIB_PREFIX)/socket -
uspace/app/virtusbkbd/Makefile
rb371844 rb8100da 31 31 # (it is really annoying to write long names) 32 32 BINARY = vuk 33 LIBS = $(LIBUSB_PREFIX)/libusb.a 33 34 LIBS = $(LIBUSB_PREFIX)/libusb.a $(LIBUSBVIRT_PREFIX)/libusbvirt.a 34 35 EXTRA_CFLAGS = -I$(LIB_PREFIX) 36 35 37 SOURCES = \ 36 38 virtusbkbd.c -
uspace/app/virtusbkbd/virtusbkbd.c
rb371844 rb8100da 46 46 47 47 #include <usb/hcd.h> 48 #include <usb/virtdev.h> 48 #include <usbvirt/device.h> 49 #include <usbvirt/hub.h> 50 #include <usbvirt/ids.h> 49 51 50 52 #define LOOPS 5 … … 59 61 (printf("%s: %s" fmt "\n", NAME, _QUOTEME(cmd), __VA_ARGS__), cmd(__VA_ARGS__)) 60 62 63 static int on_incoming_data(struct usbvirt_device *dev, 64 usb_endpoint_t endpoint, void *buffer, size_t size) 65 { 66 printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint); 67 68 return EOK; 69 } 70 71 /** Keyboard callbacks. 72 * We abuse the fact that static variables are zero-filled. 73 */ 74 static usbvirt_device_ops_t keyboard_ops = { 75 .on_data = on_incoming_data 76 }; 77 78 /** Keyboard device. 79 * Rest of the items will be initialized later. 80 */ 81 static usbvirt_device_t keyboard_dev = { 82 .ops = &keyboard_ops, 83 .device_id_ = USBVIRT_DEV_KEYBOARD_ID 84 }; 85 86 61 87 static void fibril_sleep(size_t sec) 62 88 { … … 66 92 } 67 93 68 static void on_data_from_host(usb_endpoint_t endpoint, void *buffer, size_t len)69 {70 printf("%s: ignoring incomming data to endpoint %d\n", NAME, endpoint);71 }72 94 73 95 int main(int argc, char * argv[]) 74 96 { 75 int vhcd_phone = usb_virtdev_connect(DEV_HCD_NAME, 76 USB_VIRTDEV_KEYBOARD_ID, on_data_from_host); 77 78 if (vhcd_phone < 0) { 97 int rc = usbvirt_connect(&keyboard_dev, DEV_HCD_NAME); 98 if (rc != EOK) { 79 99 printf("%s: Unable to start comunication with VHCD at usb://%s (%s).\n", 80 NAME, DEV_HCD_NAME, str_error( vhcd_phone));81 return vhcd_phone;100 NAME, DEV_HCD_NAME, str_error(rc)); 101 return rc; 82 102 } 83 84 85 103 86 104 size_t i; … … 94 112 95 113 printf("%s: Will send data to VHCD...\n", NAME); 96 int rc = usb_virtdev_data_to_host(vhcd_phone, 0, data, size);114 int rc = keyboard_dev.send_data(&keyboard_dev, 0, data, size); 97 115 printf("%s: ...data sent (%s).\n", NAME, str_error(rc)); 98 116 } … … 101 119 printf("%s: Terminating...\n", NAME); 102 120 103 ipc_hangup(vhcd_phone);121 usbvirt_disconnect(); 104 122 105 123 return 0; -
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 /** -
uspace/srv/hw/bus/usb/hcd/virtual/conndev.c
rb371844 rb8100da 36 36 #include <assert.h> 37 37 #include <errno.h> 38 #include <usb /virtdev.h>38 #include <usbvirt/hub.h> 39 39 40 40 #include "conn.h" … … 101 101 break; 102 102 103 case IPC_M_USB _VIRTDEV_DATA_FROM_DEVICE:103 case IPC_M_USBVIRT_DATA_FROM_DEVICE: 104 104 handle_data_from_device(callid, call, dev); 105 105 break; -
uspace/srv/hw/bus/usb/hcd/virtual/devices.c
rb371844 rb8100da 43 43 #include <str_error.h> 44 44 45 #include <usb /virtdev.h>45 #include <usbvirt/ids.h> 46 46 47 47 #include "devices.h" … … 62 62 virtdev_connection_t * dev = NULL; 63 63 switch (id) { 64 case USB _VIRTDEV_KEYBOARD_ID:64 case USBVIRT_DEV_KEYBOARD_ID: 65 65 dev = virtdev_add_device( 66 USB _VIRTDEV_KEYBOARD_ADDRESS, phone);66 USBVIRT_DEV_KEYBOARD_ADDRESS, phone); 67 67 break; 68 68 default: -
uspace/srv/hw/bus/usb/hcd/virtual/hc.c
rb371844 rb8100da 43 43 #include <str_error.h> 44 44 45 #include <usb /virtdev.h>45 #include <usbvirt/hub.h> 46 46 47 47 #include "vhcd.h" … … 155 155 156 156 req = async_send_2(dev->phone, 157 IPC_M_USB _VIRTDEV_DATA_TO_DEVICE,157 IPC_M_USBVIRT_DATA_TO_DEVICE, 158 158 transaction->target.endpoint, 159 159 transaction->type, -
uspace/srv/hw/bus/usb/hcd/virtual/hcd.c
rb371844 rb8100da 45 45 46 46 #include <usb/hcd.h> 47 #include <usb/virtdev.h>48 47 #include "vhcd.h" 49 48 #include "hc.h"
Note:
See TracChangeset
for help on using the changeset viewer.