Ignore:
File:
1 edited

Legend:

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

    rfa0f53b r3954a63b  
    4949#include <assert.h>
    5050#include <usbhc_iface.h>
    51 #include <usb/request.h>
    52 #include "pipepriv.h"
    5351
    5452/** Request an in transfer, no checking of input parameters.
     
    8078        }
    8179
    82         /* Ensure serialization over the phone. */
    83         pipe_start_transaction(pipe);
    84 
    8580        /*
    8681         * Make call identifying target USB device and type of transfer.
    8782         */
    88         aid_t opening_request = async_send_3(pipe->hc_phone,
     83        aid_t opening_request = async_send_4(pipe->hc_phone,
    8984            DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    9085            pipe->wire->address, pipe->endpoint_no,
     86            pipe->max_packet_size,
    9187            NULL);
    9288        if (opening_request == 0) {
    93                 pipe_end_transaction(pipe);
    9489                return ENOMEM;
    9590        }
     
    10196        aid_t data_request = async_data_read(pipe->hc_phone, buffer, size,
    10297            &data_request_call);
    103 
    104         /*
    105          * Since now on, someone else might access the backing phone
    106          * without breaking the transfer IPC protocol.
    107          */
    108         pipe_end_transaction(pipe);
    10998
    11099        if (data_request == 0) {
     
    157146
    158147        if (buffer == NULL) {
    159                 return EINVAL;
     148                        return EINVAL;
    160149        }
    161150
     
    164153        }
    165154
     155        if (!usb_pipe_is_session_started(pipe)) {
     156                return EBADF;
     157        }
     158
    166159        if (pipe->direction != USB_DIRECTION_IN) {
    167160                return EBADF;
     
    172165        }
    173166
     167        size_t act_size = 0;
    174168        int rc;
    175         rc = pipe_add_ref(pipe);
    176         if (rc != EOK) {
    177                 return rc;
    178         }
    179 
    180 
    181         size_t act_size = 0;
    182169
    183170        rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
    184 
    185         pipe_drop_ref(pipe);
    186 
    187171        if (rc != EOK) {
    188172                return rc;
     
    226210        }
    227211
    228         /* Ensure serialization over the phone. */
    229         pipe_start_transaction(pipe);
    230 
    231212        /*
    232213         * Make call identifying target USB device and type of transfer.
    233214         */
    234         aid_t opening_request = async_send_3(pipe->hc_phone,
     215        aid_t opening_request = async_send_4(pipe->hc_phone,
    235216            DEV_IFACE_ID(USBHC_DEV_IFACE), ipc_method,
    236217            pipe->wire->address, pipe->endpoint_no,
     218            pipe->max_packet_size,
    237219            NULL);
    238220        if (opening_request == 0) {
    239                 pipe_end_transaction(pipe);
    240221                return ENOMEM;
    241222        }
     
    245226         */
    246227        int rc = async_data_write_start(pipe->hc_phone, buffer, size);
    247 
    248         /*
    249          * Since now on, someone else might access the backing phone
    250          * without breaking the transfer IPC protocol.
    251          */
    252         pipe_end_transaction(pipe);
    253 
    254228        if (rc != EOK) {
    255229                async_wait_for(opening_request, NULL);
     
    286260        }
    287261
     262        if (!usb_pipe_is_session_started(pipe)) {
     263                return EBADF;
     264        }
     265
    288266        if (pipe->direction != USB_DIRECTION_OUT) {
    289267                return EBADF;
     
    294272        }
    295273
    296         int rc;
    297 
    298         rc = pipe_add_ref(pipe);
    299         if (rc != EOK) {
    300                 return rc;
    301         }
    302 
    303         rc = usb_pipe_write_no_check(pipe, buffer, size);
    304 
    305         pipe_drop_ref(pipe);
     274        int rc = usb_pipe_write_no_check(pipe, buffer, size);
    306275
    307276        return rc;
    308 }
    309 
    310 /** Try to clear endpoint halt of default control pipe.
    311  *
    312  * @param pipe Pipe for control endpoint zero.
    313  */
    314 static void clear_self_endpoint_halt(usb_pipe_t *pipe)
    315 {
    316         assert(pipe != NULL);
    317 
    318         if (!pipe->auto_reset_halt || (pipe->endpoint_no != 0)) {
    319                 return;
    320         }
    321 
    322 
    323         /* Prevent indefinite recursion. */
    324         pipe->auto_reset_halt = false;
    325         usb_request_clear_endpoint_halt(pipe, 0);
    326         pipe->auto_reset_halt = true;
    327277}
    328278
     
    343293    void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    344294{
    345         /* Ensure serialization over the phone. */
    346         pipe_start_transaction(pipe);
    347 
    348295        /*
    349296         * Make call identifying target USB device and control transfer type.
    350297         */
    351         aid_t opening_request = async_send_3(pipe->hc_phone,
     298        aid_t opening_request = async_send_4(pipe->hc_phone,
    352299            DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_READ,
    353300            pipe->wire->address, pipe->endpoint_no,
     301            pipe->max_packet_size,
    354302            NULL);
    355303        if (opening_request == 0) {
     
    363311            setup_buffer, setup_buffer_size);
    364312        if (rc != EOK) {
    365                 pipe_end_transaction(pipe);
    366313                async_wait_for(opening_request, NULL);
    367314                return rc;
     
    375322            data_buffer, data_buffer_size,
    376323            &data_request_call);
    377 
    378         /*
    379          * Since now on, someone else might access the backing phone
    380          * without breaking the transfer IPC protocol.
    381          */
    382         pipe_end_transaction(pipe);
    383 
    384 
    385324        if (data_request == 0) {
    386325                async_wait_for(opening_request, NULL);
     
    440379        }
    441380
     381        if (!usb_pipe_is_session_started(pipe)) {
     382                return EBADF;
     383        }
     384
    442385        if ((pipe->direction != USB_DIRECTION_BOTH)
    443386            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    445388        }
    446389
    447         int rc;
    448 
    449         rc = pipe_add_ref(pipe);
    450         if (rc != EOK) {
    451                 return rc;
    452         }
    453 
    454390        size_t act_size = 0;
    455         rc = usb_pipe_control_read_no_check(pipe,
     391        int rc = usb_pipe_control_read_no_check(pipe,
    456392            setup_buffer, setup_buffer_size,
    457393            data_buffer, data_buffer_size, &act_size);
    458 
    459         if (rc == ESTALL) {
    460                 clear_self_endpoint_halt(pipe);
    461         }
    462 
    463         pipe_drop_ref(pipe);
    464394
    465395        if (rc != EOK) {
     
    488418    void *data_buffer, size_t data_buffer_size)
    489419{
    490         /* Ensure serialization over the phone. */
    491         pipe_start_transaction(pipe);
    492 
    493420        /*
    494421         * Make call identifying target USB device and control transfer type.
    495422         */
    496         aid_t opening_request = async_send_4(pipe->hc_phone,
     423        aid_t opening_request = async_send_5(pipe->hc_phone,
    497424            DEV_IFACE_ID(USBHC_DEV_IFACE), IPC_M_USBHC_CONTROL_WRITE,
    498425            pipe->wire->address, pipe->endpoint_no,
    499426            data_buffer_size,
     427            pipe->max_packet_size,
    500428            NULL);
    501429        if (opening_request == 0) {
    502                 pipe_end_transaction(pipe);
    503430                return ENOMEM;
    504431        }
     
    510437            setup_buffer, setup_buffer_size);
    511438        if (rc != EOK) {
    512                 pipe_end_transaction(pipe);
    513439                async_wait_for(opening_request, NULL);
    514440                return rc;
     
    521447                rc = async_data_write_start(pipe->hc_phone,
    522448                    data_buffer, data_buffer_size);
    523 
    524                 /* All data sent, pipe can be released. */
    525                 pipe_end_transaction(pipe);
    526 
    527449                if (rc != EOK) {
    528450                        async_wait_for(opening_request, NULL);
    529451                        return rc;
    530452                }
    531         } else {
    532                 /* No data to send, we can release the pipe for others. */
    533                 pipe_end_transaction(pipe);
    534453        }
    535454
     
    572491        }
    573492
     493        if (!usb_pipe_is_session_started(pipe)) {
     494                return EBADF;
     495        }
     496
    574497        if ((pipe->direction != USB_DIRECTION_BOTH)
    575498            || (pipe->transfer_type != USB_TRANSFER_CONTROL)) {
     
    577500        }
    578501
    579         int rc;
    580 
    581         rc = pipe_add_ref(pipe);
    582         if (rc != EOK) {
    583                 return rc;
    584         }
    585 
    586         rc = usb_pipe_control_write_no_check(pipe,
     502        int rc = usb_pipe_control_write_no_check(pipe,
    587503            setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
    588 
    589         if (rc == ESTALL) {
    590                 clear_self_endpoint_halt(pipe);
    591         }
    592 
    593         pipe_drop_ref(pipe);
    594504
    595505        return rc;
Note: See TracChangeset for help on using the changeset viewer.