Changes in uspace/drv/vhc/devices.c [774afaae:daec5e04] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/drv/vhc/devices.c
r774afaae rdaec5e04 27 27 */ 28 28 29 /** @addtogroup usb29 /** @addtogroup drvusbvhc 30 30 * @{ 31 31 */ … … 34 34 */ 35 35 36 #include <ipc/ipc.h>37 36 #include <adt/list.h> 38 37 #include <bool.h> … … 58 57 /** Create virtual device. 59 58 * 60 * @param address USB address.61 59 * @param phone Callback phone. 60 * @param id Device id. 62 61 * @return New device. 63 * @retval NULL Out of memory or address already occupied.64 */ 65 virtdev_connection_t *virtdev_add_device(int phone )62 * @retval NULL Out of memory. 63 */ 64 virtdev_connection_t *virtdev_add_device(int phone, sysarg_t id) 66 65 { 67 66 virtdev_connection_t *dev = (virtdev_connection_t *) 68 67 malloc(sizeof(virtdev_connection_t)); 68 if (dev == NULL) { 69 return NULL; 70 } 71 69 72 dev->phone = phone; 73 dev->id = id; 70 74 list_append(&dev->link, &devices); 71 75 … … 75 79 } 76 80 77 /** Destroy virtual device. 78 */ 79 void virtdev_destroy_device(virtdev_connection_t *dev) 80 { 81 virthub_disconnect_device(&virtual_hub_device, dev); 82 list_remove(&dev->link); 83 free(dev); 84 } 85 86 /** Send data to all connected devices. 87 * 88 * @param transaction Transaction to be sent over the bus. 89 */ 90 usb_transaction_outcome_t virtdev_send_to_all(transaction_t *transaction) 81 /** Find virtual device by id. 82 * 83 * @param id Device id. 84 * @return Device with given id. 85 * @retval NULL No such device. 86 */ 87 virtdev_connection_t *virtdev_find(sysarg_t id) 91 88 { 92 89 link_t *pos; … … 94 91 virtdev_connection_t *dev 95 92 = list_get_instance(pos, virtdev_connection_t, link); 93 if (dev->id == id) { 94 return dev; 95 } 96 } 97 98 return NULL; 99 } 100 101 /** Destroy virtual device. 102 */ 103 void virtdev_destroy_device(virtdev_connection_t *dev) 104 { 105 virthub_disconnect_device(&virtual_hub_device, dev); 106 list_remove(&dev->link); 107 free(dev); 108 } 109 110 /** Send data to all connected devices. 111 * 112 * @param transaction Transaction to be sent over the bus. 113 */ 114 int virtdev_send_to_all(transaction_t *transaction) 115 { 116 /* For easier debugging. */ 117 switch (transaction->type) { 118 case USBVIRT_TRANSACTION_SETUP: 119 case USBVIRT_TRANSACTION_OUT: 120 transaction->actual_len = transaction->len; 121 break; 122 case USBVIRT_TRANSACTION_IN: 123 transaction->actual_len = 0; 124 break; 125 default: 126 assert(false && "unreachable branch in switch()"); 127 } 128 int outcome = EBADCHECKSUM; 129 130 link_t *pos; 131 list_foreach(pos, &devices) { 132 virtdev_connection_t *dev 133 = list_get_instance(pos, virtdev_connection_t, link); 96 134 97 135 if (!virthub_is_device_enabled(&virtual_hub_device, dev)) { … … 100 138 101 139 ipc_call_t answer_data; 102 ipcarg_t answer_rc;140 sysarg_t answer_rc; 103 141 aid_t req; 104 142 int rc = EOK; … … 138 176 } else { 139 177 async_wait_for(req, &answer_rc); 178 transaction->actual_len = IPC_GET_ARG1(answer_data); 140 179 rc = (int)answer_rc; 180 } 181 182 /* 183 * If at least one device was able to accept this 184 * transaction and process it, we can announce success. 185 */ 186 if (rc == EOK) { 187 outcome = EOK; 141 188 } 142 189 } … … 148 195 if (virtual_hub_device.address == transaction->target.address) { 149 196 size_t tmp; 150 dprintf(1, "sending `%s' transaction to hub",197 usb_log_debug2("Sending `%s' transaction to hub.\n", 151 198 usbvirt_str_transaction_type(transaction->type)); 152 199 switch (transaction->type) { … … 164 211 transaction->buffer, transaction->len, 165 212 &tmp); 166 if (tmp < transaction->len) { 167 transaction->len = tmp; 168 } 213 transaction->actual_len = tmp; 169 214 break; 170 215 … … 176 221 break; 177 222 } 178 dprintf(4, "transaction on hub processed...");223 outcome = EOK; 179 224 } 180 225 … … 183 228 * real-life image. 184 229 */ 185 return USB_OUTCOME_OK;230 return outcome; 186 231 } 187 232
Note:
See TracChangeset
for help on using the changeset viewer.