Ignore:
File:
1 edited

Legend:

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

    r365e29e2 rb77931d  
    6868 * @return Whether the given descriptor is endpoint descriptor.
    6969 */
    70 static inline bool is_endpoint_descriptor(uint8_t *descriptor)
     70static inline bool is_endpoint_descriptor(const uint8_t *descriptor)
    7171{
    7272        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     
    8080 */
    8181static bool endpoint_fits_description(const usb_endpoint_description_t *wanted,
    82     usb_endpoint_description_t *found)
     82    const usb_endpoint_description_t *found)
    8383{
    8484#define _SAME(fieldname) ((wanted->fieldname) == (found->fieldname))
     
    120120static usb_endpoint_mapping_t *find_endpoint_mapping(
    121121    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    122     usb_endpoint_description_t *found_endpoint,
     122    const usb_endpoint_description_t *found_endpoint,
    123123    int interface_number, int interface_setting)
    124124{
     
    160160    usb_device_connection_t *wire)
    161161{
    162         usb_endpoint_description_t description;
    163162
    164163        /*
     
    167166
    168167        /* Actual endpoint number is in bits 0..3 */
    169         usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
    170 
    171         /* Endpoint direction is set by bit 7 */
    172         description.direction = (endpoint->endpoint_address & 128)
    173             ? USB_DIRECTION_IN : USB_DIRECTION_OUT;
    174         /* Transfer type is in bits 0..2 and the enum values corresponds 1:1 */
    175         description.transfer_type = endpoint->attributes & 3;
    176 
    177         /*
    178          * Get interface characteristics.
    179          */
    180         description.interface_class = interface->interface_class;
    181         description.interface_subclass = interface->interface_subclass;
    182         description.interface_protocol = interface->interface_protocol;
     168        const usb_endpoint_t ep_no = endpoint->endpoint_address & 0x0F;
     169
     170        const usb_endpoint_description_t description = {
     171                /* Endpoint direction is set by bit 7 */
     172                .direction = (endpoint->endpoint_address & 128)
     173                    ? USB_DIRECTION_IN : USB_DIRECTION_OUT,
     174                /* Transfer type is in bits 0..2 and
     175                 * the enum values corresponds 1:1 */
     176                .transfer_type = endpoint->attributes & 3,
     177
     178                /* Get interface characteristics. */
     179                .interface_class = interface->interface_class,
     180                .interface_subclass = interface->interface_subclass,
     181                .interface_protocol = interface->interface_protocol,
     182        };
    183183
    184184        /*
     
    192192        }
    193193
    194         if (ep_mapping->pipe == NULL) {
    195                 return EBADMEM;
    196         }
    197194        if (ep_mapping->present) {
    198195                return EEXISTS;
    199196        }
    200197
    201         int rc = usb_pipe_initialize(ep_mapping->pipe, wire,
     198        int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,
    202199            ep_no, description.transfer_type, endpoint->max_packet_size,
    203200            description.direction);
     
    224221static int process_interface(
    225222    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    226     usb_dp_parser_t *parser, usb_dp_parser_data_t *parser_data,
    227     uint8_t *interface_descriptor)
    228 {
    229         uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
     223    const usb_dp_parser_t *parser, const usb_dp_parser_data_t *parser_data,
     224    const uint8_t *interface_descriptor)
     225{
     226        const uint8_t *descriptor = usb_dp_get_nested_descriptor(parser,
    230227            parser_data, interface_descriptor);
    231228
     
    254251 *
    255252 * The mapping array is expected to conform to following rules:
    256  * - @c pipe must point to already allocated structure with uninitialized pipe
     253 * - @c pipe must be uninitialized pipe
    257254 * - @c description must point to prepared endpoint description
    258255 * - @c descriptor does not need to be initialized (will be overwritten)
     
    284281int usb_pipe_initialize_from_configuration(
    285282    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    286     uint8_t *configuration_descriptor, size_t configuration_descriptor_size,
     283    const uint8_t *config_descriptor, size_t config_descriptor_size,
    287284    usb_device_connection_t *connection)
    288285{
    289286        assert(connection);
    290287
    291         if (configuration_descriptor == NULL) {
     288        if (config_descriptor == NULL) {
    292289                return EBADMEM;
    293290        }
    294         if (configuration_descriptor_size
     291        if (config_descriptor_size
    295292            < sizeof(usb_standard_configuration_descriptor_t)) {
    296293                return ERANGE;
    297294        }
    298295
    299         /*
    300          * Go through the mapping and set all endpoints to not present.
    301          */
    302         size_t i;
    303         for (i = 0; i < mapping_count; i++) {
     296        /* Go through the mapping and set all endpoints to not present. */
     297        for (size_t i = 0; i < mapping_count; i++) {
    304298                mapping[i].present = false;
    305299                mapping[i].descriptor = NULL;
     
    307301        }
    308302
    309         /*
    310          * Prepare the descriptor parser.
    311          */
    312         usb_dp_parser_t dp_parser = {
     303        /* Prepare the descriptor parser. */
     304        const usb_dp_parser_t dp_parser = {
    313305                .nesting = descriptor_nesting
    314306        };
    315         usb_dp_parser_data_t dp_data = {
    316                 .data = configuration_descriptor,
    317                 .size = configuration_descriptor_size,
     307        const usb_dp_parser_data_t dp_data = {
     308                .data = config_descriptor,
     309                .size = config_descriptor_size,
    318310                .arg = connection
    319311        };
     
    322314         * Iterate through all interfaces.
    323315         */
    324         uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
    325             &dp_data, configuration_descriptor);
     316        const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
     317            &dp_data, config_descriptor);
    326318        if (interface == NULL) {
    327319                return ENOENT;
     
    329321        do {
    330322                (void) process_interface(mapping, mapping_count,
    331                     &dp_parser, &dp_data,
    332                     interface);
     323                    &dp_parser, &dp_data, interface);
    333324                interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    334                     configuration_descriptor, interface);
     325                    config_descriptor, interface);
    335326        } while (interface != NULL);
    336327
     
    455446 * @return Error code.
    456447 */
    457 int usb_pipe_register(usb_pipe_t *pipe,
    458     unsigned int interval,
    459     usb_hc_connection_t *hc_connection)
    460 {
    461         return usb_pipe_register_with_speed(pipe, USB_SPEED_MAX + 1,
    462             interval, hc_connection);
    463 }
    464 
    465 /** Register endpoint with a speed at the host controller.
    466  *
    467  * You will rarely need to use this function because it is needed only
    468  * if the registered endpoint is of address 0 and there is no other way
    469  * to tell speed of the device at address 0.
    470  *
    471  * @param pipe Pipe to be registered.
    472  * @param speed Speed of the device
    473  *      (invalid speed means use previously specified one).
    474  * @param interval Polling interval.
    475  * @param hc_connection Connection to the host controller (must be opened).
    476  * @return Error code.
    477  */
    478 int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed,
    479     unsigned int interval,
     448int usb_pipe_register(usb_pipe_t *pipe, unsigned interval,
    480449    usb_hc_connection_t *hc_connection)
    481450{
    482451        assert(pipe);
    483452        assert(hc_connection);
    484        
     453
    485454        if (!usb_hc_connection_is_opened(hc_connection))
    486455                return EBADF;
    487        
     456
    488457        const usb_target_t target =
    489458            {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    490 #define _PACK2(high, low) (((high) << 16) + (low))
    491 #define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low))
    492        
     459#define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
     460
    493461        async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess);
    494462        int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    495463            IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
    496             _PACK3(speed, pipe->transfer_type, pipe->direction),
     464            _PACK2(pipe->transfer_type, pipe->direction),
    497465            _PACK2(pipe->max_packet_size, interval));
    498466        async_exchange_end(exch);
    499        
     467
    500468#undef _PACK2
    501 #undef _PACK3
    502        
    503469        return rc;
    504470}
     
    514480{
    515481        assert(pipe);
     482        assert(pipe->wire);
    516483        assert(hc_connection);
    517484       
Note: See TracChangeset for help on using the changeset viewer.