Changeset 4d73d71 in mainline


Ignore:
Timestamp:
2011-02-04T23:51:54Z (14 years ago)
Author:
Jan Vesely <jano.vesely@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4192d3d6
Parents:
474afc9
Message:

add some basic packet checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/uhci-hcd/uhci.c

    r474afc9 r4d73d71  
    4242static int uhci_clean_finished(void *arg);
    4343static int uhci_debug_checker(void *arg);
     44static bool allowed_usb_packet(
     45        bool low_speed, usb_transfer_type_t, size_t size);
    4446
    4547int uhci_init(uhci_t *instance, void *regs, size_t reg_size)
     
    160162  void *arg)
    161163{
     164        if (!allowed_usb_packet(low_speed, transfer_type, size)) {
     165                usb_log_warning("Invalid USB packet specified %s SPEED %d %zu.\n",
     166                        low_speed ? "LOW" : "FULL" , transfer_type, size);
     167                return ENOTSUP;
     168        }
     169
    162170        // TODO: Add support for isochronous transfers
    163171        if (transfer_type == USB_TRANSFER_ISOCHRONOUS) {
     
    166174        }
    167175
    168         if (transfer_type == USB_TRANSFER_INTERRUPT
    169           && size >= 64) {
    170                 usb_log_warning("Interrupt transfer too big %zu.\n", size);
    171                 return ENOTSUP;
    172         }
    173 
    174         if (size >= 1024) {
    175                 usb_log_warning("Transfer too big.\n");
    176                 return ENOTSUP;
    177         }
    178176        transfer_list_t *list = instance->transfers[low_speed][transfer_type];
    179         if (!list) {
    180                 usb_log_warning("UNSUPPORTED transfer %d-%d.\n", low_speed, transfer_type);
    181                 return ENOTSUP;
    182         }
     177        assert(list);
    183178
    184179        transfer_descriptor_t *td = NULL;
     
    206201
    207202        td->callback = job;
    208 
    209203
    210204        usb_log_debug("Appending a new transfer to queue %s.\n", list->name);
     
    311305        return 0;
    312306}
     307/*----------------------------------------------------------------------------*/
     308bool allowed_usb_packet(
     309        bool low_speed, usb_transfer_type_t transfer, size_t size)
     310{
     311        /* see USB specification chapter 5.5-5.8 for magic numbers used here */
     312        switch(transfer) {
     313                case USB_TRANSFER_ISOCHRONOUS:
     314                        return (!low_speed && size < 1024);
     315                case USB_TRANSFER_INTERRUPT:
     316                        return size <= (low_speed ? 8 :64);
     317                case USB_TRANSFER_CONTROL: /* device specifies its own max size */
     318                        return (size <= (low_speed ? 8 : 64));
     319                case USB_TRANSFER_BULK: /* device specifies its own max size */
     320                        return (!low_speed && size <= 64);
     321        }
     322        return false;
     323}
    313324/**
    314325 * @}
Note: See TracChangeset for help on using the changeset viewer.