Changeset b4292e7 in mainline


Ignore:
Timestamp:
2011-11-26T13:17:48Z (13 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8969f46
Parents:
272f46f8
Message:

libusbdev: Merge implementations of control and non-control _no_check read/write.

Location:
uspace/lib/usbdev
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/usbdev/include/usb/dev/pipes.h

    r272f46f8 rb4292e7  
    179179
    180180int usb_pipe_read(usb_pipe_t *, void *, size_t, size_t *);
    181 int usb_pipe_write(usb_pipe_t *, void *, size_t);
     181int usb_pipe_write(usb_pipe_t *, const void *, size_t);
    182182
    183183int usb_pipe_control_read(usb_pipe_t *, const void *, size_t,
  • uspace/lib/usbdev/src/pipesio.c

    r272f46f8 rb4292e7  
    6262 * @return Error code.
    6363 */
    64 static int usb_pipe_read_no_checks(usb_pipe_t *pipe,
     64static int usb_pipe_read_no_check(usb_pipe_t *pipe, uint64_t setup,
    6565    void *buffer, size_t size, size_t *size_transfered)
    6666{
    6767        /* Only interrupt and bulk transfers are supported */
    6868        if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    69             pipe->transfer_type != USB_TRANSFER_BULK)
     69            pipe->transfer_type != USB_TRANSFER_BULK &&
     70            pipe->transfer_type != USB_TRANSFER_CONTROL)
    7071            return ENOTSUP;
    7172
     
    7980
    8081        const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no,
    81             0, buffer, size, size_transfered);
     82            setup, buffer, size, size_transfered);
    8283        async_exchange_end(exch);
    8384        pipe_end_transaction(pipe);
     
    8586}
    8687
    87 
    8888/** Request a read (in) transfer on an endpoint pipe.
    8989 *
     
    124124        size_t act_size = 0;
    125125
    126         rc = usb_pipe_read_no_checks(pipe, buffer, size, &act_size);
     126        rc = usb_pipe_read_no_check(pipe, 0, buffer, size, &act_size);
    127127
    128128        pipe_drop_ref(pipe);
     
    139139}
    140140
    141 
    142 
    143 
    144141/** Request an out transfer, no checking of input parameters.
    145142 *
     
    149146 * @return Error code.
    150147 */
    151 static int usb_pipe_write_no_check(usb_pipe_t *pipe,
    152     void *buffer, size_t size)
     148static int usb_pipe_write_no_check(usb_pipe_t *pipe, uint64_t setup,
     149    const void *buffer, size_t size)
    153150{
    154151        /* Only interrupt and bulk transfers are supported */
    155152        if (pipe->transfer_type != USB_TRANSFER_INTERRUPT &&
    156             pipe->transfer_type != USB_TRANSFER_BULK)
     153            pipe->transfer_type != USB_TRANSFER_BULK &&
     154            pipe->transfer_type != USB_TRANSFER_CONTROL)
    157155            return ENOTSUP;
    158156
     
    166164        const int ret =
    167165            usbhc_write(exch, pipe->wire->address, pipe->endpoint_no,
    168             0, buffer, size);
     166            setup, buffer, size);
    169167        async_exchange_end(exch);
    170168        pipe_end_transaction(pipe);
     
    179177 * @return Error code.
    180178 */
    181 int usb_pipe_write(usb_pipe_t *pipe,
    182     void *buffer, size_t size)
     179int usb_pipe_write(usb_pipe_t *pipe, const void *buffer, size_t size)
    183180{
    184181        assert(pipe);
    185182
    186         if (buffer == NULL) {
    187                 return EINVAL;
    188         }
    189 
    190         if (size == 0) {
     183        if (buffer == NULL || size == 0) {
    191184                return EINVAL;
    192185        }
     
    201194
    202195        int rc;
    203 
    204196        rc = pipe_add_ref(pipe, false);
    205197        if (rc != EOK) {
     
    207199        }
    208200
    209         rc = usb_pipe_write_no_check(pipe, buffer, size);
     201        rc = usb_pipe_write_no_check(pipe, 0, buffer, size);
    210202
    211203        pipe_drop_ref(pipe);
     
    227219
    228220
    229         /* Prevent indefinite recursion. */
     221        /* Prevent infinite recursion. */
    230222        pipe->auto_reset_halt = false;
    231223        usb_request_clear_endpoint_halt(pipe, 0);
     
    233225}
    234226
    235 
    236 /** Request a control read transfer, no checking of input parameters.
     227/** Request a control read transfer on an endpoint pipe.
     228 *
     229 * This function encapsulates all three stages of a control transfer.
    237230 *
    238231 * @param[in] pipe Pipe used for the transfer.
     
    245238 * @return Error code.
    246239 */
    247 static int usb_pipe_control_read_no_check(usb_pipe_t *pipe,
    248     const void *setup_buffer, size_t setup_buffer_size,
    249     void *data_buffer, size_t data_buffer_size, size_t *data_transfered_size)
    250 {
    251         /* Ensure serialization over the phone. */
    252         pipe_start_transaction(pipe);
    253 
    254         assert(setup_buffer_size == 8);
    255         uint64_t setup_packet;
    256         memcpy(&setup_packet, setup_buffer, 8);
    257 
    258         async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    259         if (!exch) {
    260                 pipe_end_transaction(pipe);
    261                 return ENOMEM;
    262         }
    263 
    264         const int ret = usbhc_read(exch, pipe->wire->address, pipe->endpoint_no,
    265             setup_packet, data_buffer, data_buffer_size, data_transfered_size);
    266         async_exchange_end(exch);
    267         pipe_end_transaction(pipe);
    268         return ret;
    269 }
    270 
    271 /** Request a control read transfer on an endpoint pipe.
    272  *
    273  * This function encapsulates all three stages of a control transfer.
    274  *
    275  * @param[in] pipe Pipe used for the transfer.
    276  * @param[in] setup_buffer Buffer with the setup packet.
    277  * @param[in] setup_buffer_size Size of the setup packet (in bytes).
    278  * @param[out] data_buffer Buffer for incoming data.
    279  * @param[in] data_buffer_size Size of the buffer for incoming data (in bytes).
    280  * @param[out] data_transfered_size Number of bytes that were actually
    281  *                                  transfered during the DATA stage.
    282  * @return Error code.
    283  */
    284240int usb_pipe_control_read(usb_pipe_t *pipe,
    285241    const void *setup_buffer, size_t setup_buffer_size,
     
    288244        assert(pipe);
    289245
    290         if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {
     246        if ((setup_buffer == NULL) || (setup_buffer_size != 8)) {
    291247                return EINVAL;
    292248        }
     
    301257        }
    302258
     259        uint64_t setup_packet;
     260        memcpy(&setup_packet, setup_buffer, 8);
     261
    303262        int rc;
    304263
     
    309268
    310269        size_t act_size = 0;
    311         rc = usb_pipe_control_read_no_check(pipe,
    312             setup_buffer, setup_buffer_size,
     270        rc = usb_pipe_read_no_check(pipe, setup_packet,
    313271            data_buffer, data_buffer_size, &act_size);
    314272
     
    330288}
    331289
    332 
    333 /** Request a control write transfer, no checking of input parameters.
     290/** Request a control write transfer on an endpoint pipe.
     291 *
     292 * This function encapsulates all three stages of a control transfer.
    334293 *
    335294 * @param[in] pipe Pipe used for the transfer.
     
    340299 * @return Error code.
    341300 */
    342 static int usb_pipe_control_write_no_check(usb_pipe_t *pipe,
    343     const void *setup_buffer, size_t setup_buffer_size,
    344     const void *data_buffer, size_t data_buffer_size)
    345 {
    346         /* Ensure serialization over the phone. */
    347         pipe_start_transaction(pipe);
    348 
    349         assert(setup_buffer_size == 8);
    350         uint64_t setup_packet;
    351         memcpy(&setup_packet, setup_buffer, 8);
    352 
    353         /* Make call identifying target USB device and control transfer type. */
    354         async_exch_t *exch = async_exchange_begin(pipe->hc_sess);
    355         if (!exch) {
    356                 pipe_end_transaction(pipe);
    357                 return ENOMEM;
    358         }
    359         const int ret =
    360             usbhc_write(exch, pipe->wire->address, pipe->endpoint_no,
    361             setup_packet, data_buffer, data_buffer_size);
    362         async_exchange_end(exch);
    363         pipe_end_transaction(pipe);
    364         return ret;
    365 }
    366 
    367 /** Request a control write transfer on an endpoint pipe.
    368  *
    369  * This function encapsulates all three stages of a control transfer.
    370  *
    371  * @param[in] pipe Pipe used for the transfer.
    372  * @param[in] setup_buffer Buffer with the setup packet.
    373  * @param[in] setup_buffer_size Size of the setup packet (in bytes).
    374  * @param[in] data_buffer Buffer with data to be sent.
    375  * @param[in] data_buffer_size Size of the buffer with outgoing data (in bytes).
    376  * @return Error code.
    377  */
    378301int usb_pipe_control_write(usb_pipe_t *pipe,
    379302    const void *setup_buffer, size_t setup_buffer_size,
     
    382305        assert(pipe);
    383306
    384         if ((setup_buffer == NULL) || (setup_buffer_size == 0)) {
     307        if ((setup_buffer == NULL) || (setup_buffer_size != 8)) {
    385308                return EINVAL;
    386309        }
     
    399322        }
    400323
     324        uint64_t setup_packet;
     325        memcpy(&setup_packet, setup_buffer, 8);
     326
    401327        int rc;
    402 
    403328        rc = pipe_add_ref(pipe, false);
    404329        if (rc != EOK) {
     
    406331        }
    407332
    408         rc = usb_pipe_control_write_no_check(pipe,
    409             setup_buffer, setup_buffer_size, data_buffer, data_buffer_size);
     333        rc = usb_pipe_write_no_check(pipe, setup_packet,
     334            data_buffer, data_buffer_size);
    410335
    411336        if (rc == ESTALL) {
Note: See TracChangeset for help on using the changeset viewer.