Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/src/pipesio.c

    rbbce2c2 r79ae36dd  
    6565    void *buffer, size_t size, size_t *size_transfered)
    6666{
    67         /* Only interrupt and bulk transfers are supported */
    68         if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    69             pipe->transfer_type != USB_TRANSFER_BULK)
    70             return ENOTSUP;
    71 
    72         const usb_target_t target =
    73             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
     67        /*
     68         * Get corresponding IPC method.
     69         * In future, replace with static array of mappings
     70         * transfer type -> method.
     71         */
     72        usbhc_iface_funcs_t ipc_method;
     73        switch (pipe->transfer_type) {
     74                case USB_TRANSFER_INTERRUPT:
     75                        ipc_method = IPC_M_USBHC_INTERRUPT_IN;
     76                        break;
     77                case USB_TRANSFER_BULK:
     78                        ipc_method = IPC_M_USBHC_BULK_IN;
     79                        break;
     80                default:
     81                        return ENOTSUP;
     82        }
    7483       
    7584        /* Ensure serialization over the phone. */
     
    8089         * Make call identifying target USB device and type of transfer.
    8190         */
    82         aid_t opening_request = async_send_2(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    83             IPC_M_USBHC_READ, target.packed, NULL);
     91        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     92            ipc_method, pipe->wire->address, pipe->endpoint_no, NULL);
    8493       
    8594        if (opening_request == 0) {
     
    204213    void *buffer, size_t size)
    205214{
    206         /* Only interrupt and bulk transfers are supported */
    207         if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    208             pipe->transfer_type != USB_TRANSFER_BULK)
    209             return ENOTSUP;
    210 
    211         const usb_target_t target =
    212             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
     215        /*
     216         * Get corresponding IPC method.
     217         * In future, replace with static array of mappings
     218         * transfer type -> method.
     219         */
     220        usbhc_iface_funcs_t ipc_method;
     221        switch (pipe->transfer_type) {
     222                case USB_TRANSFER_INTERRUPT:
     223                        ipc_method = IPC_M_USBHC_INTERRUPT_OUT;
     224                        break;
     225                case USB_TRANSFER_BULK:
     226                        ipc_method = IPC_M_USBHC_BULK_OUT;
     227                        break;
     228                default:
     229                        return ENOTSUP;
     230        }
    213231
    214232        /* Ensure serialization over the phone. */
     
    220238         */
    221239        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    222             IPC_M_USBHC_WRITE, target.packed, size, NULL);
     240            ipc_method, pipe->wire->address, pipe->endpoint_no, NULL);
    223241       
    224242        if (opening_request == 0) {
     
    334352        pipe_start_transaction(pipe);
    335353
    336         const usb_target_t target =
    337             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    338 
    339         assert(setup_buffer_size == 8);
    340         uint64_t setup_packet;
    341         memcpy(&setup_packet, setup_buffer, 8);
    342354        /*
    343355         * Make call identifying target USB device and control transfer type.
    344356         */
    345357        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    346         aid_t opening_request = async_send_4(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    347             IPC_M_USBHC_READ, target.packed,
    348             (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL);
    349 
     358        aid_t opening_request = async_send_3(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     359            IPC_M_USBHC_CONTROL_READ, pipe->wire->address, pipe->endpoint_no,
     360            NULL);
     361       
    350362        if (opening_request == 0) {
    351363                async_exchange_end(exch);
    352364                return ENOMEM;
    353365        }
    354 
     366       
     367        /*
     368         * Send the setup packet.
     369         */
     370        int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
     371        if (rc != EOK) {
     372                async_exchange_end(exch);
     373                pipe_end_transaction(pipe);
     374                async_wait_for(opening_request, NULL);
     375                return rc;
     376        }
     377       
    355378        /*
    356379         * Retrieve the data.
     
    475498        pipe_start_transaction(pipe);
    476499
    477         const usb_target_t target =
    478             {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    479         assert(setup_buffer_size == 8);
    480         uint64_t setup_packet;
    481         memcpy(&setup_packet, setup_buffer, 8);
    482 
    483500        /*
    484501         * Make call identifying target USB device and control transfer type.
    485502         */
    486503        async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    487         aid_t opening_request = async_send_5(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    488             IPC_M_USBHC_WRITE, target.packed, data_buffer_size,
    489             (setup_packet & UINT32_MAX), (setup_packet >> 32), NULL);
     504        aid_t opening_request = async_send_4(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
     505            IPC_M_USBHC_CONTROL_WRITE, pipe->wire->address, pipe->endpoint_no,
     506            data_buffer_size, NULL);
    490507       
    491508        if (opening_request == 0) {
     
    494511                return ENOMEM;
    495512        }
    496 
     513       
     514        /*
     515         * Send the setup packet.
     516         */
     517        int rc = async_data_write_start(exch, setup_buffer, setup_buffer_size);
     518        if (rc != EOK) {
     519                async_exchange_end(exch);
     520                pipe_end_transaction(pipe);
     521                async_wait_for(opening_request, NULL);
     522                return rc;
     523        }
     524       
    497525        /*
    498526         * Send the data (if any).
    499527         */
    500528        if (data_buffer_size > 0) {
    501                 int rc = async_data_write_start(exch, data_buffer, data_buffer_size);
     529                rc = async_data_write_start(exch, data_buffer, data_buffer_size);
    502530               
    503531                /* All data sent, pipe can be released. */
Note: See TracChangeset for help on using the changeset viewer.