Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset beee81a in mainline for uspace/lib/usbvirt/src/ipc_dev.c


Ignore:
Timestamp:
2011-05-07T09:35:15Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master
Children:
bc02b83, d38d830
Parents:
42e2172
Message:

Virtual USB refactoring

Changes include

  • add missing comments
  • add function for virtual device disconnect
  • fix memory leak
  • support for bulks
  • checking of input parameters
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbvirt/src/ipc_dev.c

    r42e2172 rbeee81a  
    4343#include <usb/debug.h>
    4444
     45/** Handle VHC request for device name.
     46 *
     47 * @param dev Target virtual device.
     48 * @param iid Caller id.
     49 * @param icall The call with the request.
     50 */
    4551static void ipc_get_name(usbvirt_device_t *dev,
    4652    ipc_callid_t iid, ipc_call_t *icall)
     
    6773}
    6874
     75/** Handle VHC request for control read from the device.
     76 *
     77 * @param dev Target virtual device.
     78 * @param iid Caller id.
     79 * @param icall The call with the request.
     80 */
    6981static void ipc_control_read(usbvirt_device_t *dev,
    7082    ipc_callid_t iid, ipc_call_t *icall)
    7183{
    72         //usb_endpoint_t endpoint = IPC_GET_ARG1(*icall);
    73 
    7484        int rc;
    7585
     
    118128}
    119129
     130/** Handle VHC request for control write to the device.
     131 *
     132 * @param dev Target virtual device.
     133 * @param iid Caller id.
     134 * @param icall The call with the request.
     135 */
    120136static void ipc_control_write(usbvirt_device_t *dev,
    121137    ipc_callid_t iid, ipc_call_t *icall)
    122138{
    123         size_t data_buffer_len = IPC_GET_ARG2(*icall);
     139        size_t data_buffer_len = IPC_GET_ARG1(*icall);
    124140        int rc;
    125141
     
    129145
    130146        rc = async_data_write_accept(&setup_packet, false,
    131             1, 1024, 0, &setup_packet_len);
     147            1, 0, 0, &setup_packet_len);
    132148        if (rc != EOK) {
    133149                async_answer_0(iid, rc);
     
    137153        if (data_buffer_len > 0) {
    138154                rc = async_data_write_accept(&data_buffer, false,
    139                     1, 1024, 0, &data_buffer_len);
     155                    1, 0, 0, &data_buffer_len);
    140156                if (rc != EOK) {
    141157                        async_answer_0(iid, rc);
     
    149165
    150166        async_answer_0(iid, rc);
    151 }
    152 
    153 static void ipc_interrupt_in(usbvirt_device_t *dev,
     167
     168        free(setup_packet);
     169        if (data_buffer != NULL) {
     170                free(data_buffer);
     171        }
     172}
     173
     174/** Handle VHC request for data read from the device (in transfer).
     175 *
     176 * @param dev Target virtual device.
     177 * @param iid Caller id.
     178 * @param icall The call with the request.
     179 */
     180static void ipc_data_in(usbvirt_device_t *dev,
     181    usb_transfer_type_t transfer_type,
    154182    ipc_callid_t iid, ipc_call_t *icall)
    155183{
    156184        usb_endpoint_t endpoint = IPC_GET_ARG1(*icall);
    157         usb_transfer_type_t transfer_type = IPC_GET_ARG2(*icall);
    158185
    159186        int rc;
     
    189216}
    190217
    191 static void ipc_interrupt_out(usbvirt_device_t *dev,
     218/** Handle VHC request for data write to the device (out transfer).
     219 *
     220 * @param dev Target virtual device.
     221 * @param iid Caller id.
     222 * @param icall The call with the request.
     223 */
     224static void ipc_data_out(usbvirt_device_t *dev,
     225    usb_transfer_type_t transfer_type,
    192226    ipc_callid_t iid, ipc_call_t *icall)
    193227{
    194228        usb_endpoint_t endpoint = IPC_GET_ARG1(*icall);
    195         usb_transfer_type_t transfer_type = IPC_GET_ARG2(*icall);
    196229
    197230        void *data_buffer = NULL;
     
    199232
    200233        int rc = async_data_write_accept(&data_buffer, false,
    201             1, 1024, 0, &data_buffer_size);
     234            1, 0, 0, &data_buffer_size);
    202235        if (rc != EOK) {
    203236                async_answer_0(iid, rc);
     
    213246}
    214247
    215 
     248/** Handle incoming IPC call for virtual USB device.
     249 *
     250 * @param dev Target USB device.
     251 * @param callid Caller id.
     252 * @param call Incoming call.
     253 * @return Whether the call was handled.
     254 */
    216255bool usbvirt_ipc_handle_call(usbvirt_device_t *dev,
    217256    ipc_callid_t callid, ipc_call_t *call)
    218257{
    219258        switch (IPC_GET_IMETHOD(*call)) {
    220                 case IPC_M_USBVIRT_GET_NAME:
    221                         ipc_get_name(dev, callid, call);
    222                         break;
    223 
    224                 case IPC_M_USBVIRT_CONTROL_READ:
    225                         ipc_control_read(dev, callid, call);
    226                         break;
    227 
    228                 case IPC_M_USBVIRT_CONTROL_WRITE:
    229                         ipc_control_write(dev, callid, call);
    230                         break;
    231 
    232                 case IPC_M_USBVIRT_INTERRUPT_IN:
    233                         ipc_interrupt_in(dev, callid, call);
    234                         break;
    235 
    236                 case IPC_M_USBVIRT_INTERRUPT_OUT:
    237                         ipc_interrupt_out(dev, callid, call);
    238                         break;
    239 
    240                 default:
    241                         return false;
     259        case IPC_M_USBVIRT_GET_NAME:
     260                ipc_get_name(dev, callid, call);
     261                break;
     262
     263        case IPC_M_USBVIRT_CONTROL_READ:
     264                ipc_control_read(dev, callid, call);
     265                break;
     266
     267        case IPC_M_USBVIRT_CONTROL_WRITE:
     268                ipc_control_write(dev, callid, call);
     269                break;
     270
     271        case IPC_M_USBVIRT_INTERRUPT_IN:
     272                ipc_data_in(dev, USB_TRANSFER_INTERRUPT, callid, call);
     273                break;
     274
     275        case IPC_M_USBVIRT_BULK_IN:
     276                ipc_data_in(dev, USB_TRANSFER_BULK, callid, call);
     277                break;
     278
     279        case IPC_M_USBVIRT_INTERRUPT_OUT:
     280                ipc_data_out(dev, USB_TRANSFER_INTERRUPT, callid, call);
     281                break;
     282
     283        case IPC_M_USBVIRT_BULK_OUT:
     284                ipc_data_out(dev, USB_TRANSFER_BULK, callid, call);
     285                break;
     286
     287
     288        default:
     289                return false;
    242290        }
    243291
Note: See TracChangeset for help on using the changeset viewer.