Ignore:
File:
1 edited

Legend:

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

    rb77931d r365e29e2  
    6868 * @return Whether the given descriptor is endpoint descriptor.
    6969 */
    70 static inline bool is_endpoint_descriptor(const uint8_t *descriptor)
     70static inline bool is_endpoint_descriptor(uint8_t *descriptor)
    7171{
    7272        return descriptor[1] == USB_DESCTYPE_ENDPOINT;
     
    8080 */
    8181static bool endpoint_fits_description(const usb_endpoint_description_t *wanted,
    82     const usb_endpoint_description_t *found)
     82    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     const usb_endpoint_description_t *found_endpoint,
     122    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;
    162163
    163164        /*
     
    166167
    167168        /* Actual endpoint number is in bits 0..3 */
    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         };
     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;
    183183
    184184        /*
     
    192192        }
    193193
     194        if (ep_mapping->pipe == NULL) {
     195                return EBADMEM;
     196        }
    194197        if (ep_mapping->present) {
    195198                return EEXISTS;
    196199        }
    197200
    198         int rc = usb_pipe_initialize(&ep_mapping->pipe, wire,
     201        int rc = usb_pipe_initialize(ep_mapping->pipe, wire,
    199202            ep_no, description.transfer_type, endpoint->max_packet_size,
    200203            description.direction);
     
    221224static int process_interface(
    222225    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    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,
     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,
    227230            parser_data, interface_descriptor);
    228231
     
    251254 *
    252255 * The mapping array is expected to conform to following rules:
    253  * - @c pipe must be uninitialized pipe
     256 * - @c pipe must point to already allocated structure with uninitialized pipe
    254257 * - @c description must point to prepared endpoint description
    255258 * - @c descriptor does not need to be initialized (will be overwritten)
     
    281284int usb_pipe_initialize_from_configuration(
    282285    usb_endpoint_mapping_t *mapping, size_t mapping_count,
    283     const uint8_t *config_descriptor, size_t config_descriptor_size,
     286    uint8_t *configuration_descriptor, size_t configuration_descriptor_size,
    284287    usb_device_connection_t *connection)
    285288{
    286289        assert(connection);
    287290
    288         if (config_descriptor == NULL) {
     291        if (configuration_descriptor == NULL) {
    289292                return EBADMEM;
    290293        }
    291         if (config_descriptor_size
     294        if (configuration_descriptor_size
    292295            < sizeof(usb_standard_configuration_descriptor_t)) {
    293296                return ERANGE;
    294297        }
    295298
    296         /* Go through the mapping and set all endpoints to not present. */
    297         for (size_t i = 0; i < mapping_count; i++) {
     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++) {
    298304                mapping[i].present = false;
    299305                mapping[i].descriptor = NULL;
     
    301307        }
    302308
    303         /* Prepare the descriptor parser. */
    304         const usb_dp_parser_t dp_parser = {
     309        /*
     310         * Prepare the descriptor parser.
     311         */
     312        usb_dp_parser_t dp_parser = {
    305313                .nesting = descriptor_nesting
    306314        };
    307         const usb_dp_parser_data_t dp_data = {
    308                 .data = config_descriptor,
    309                 .size = config_descriptor_size,
     315        usb_dp_parser_data_t dp_data = {
     316                .data = configuration_descriptor,
     317                .size = configuration_descriptor_size,
    310318                .arg = connection
    311319        };
     
    314322         * Iterate through all interfaces.
    315323         */
    316         const uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
    317             &dp_data, config_descriptor);
     324        uint8_t *interface = usb_dp_get_nested_descriptor(&dp_parser,
     325            &dp_data, configuration_descriptor);
    318326        if (interface == NULL) {
    319327                return ENOENT;
     
    321329        do {
    322330                (void) process_interface(mapping, mapping_count,
    323                     &dp_parser, &dp_data, interface);
     331                    &dp_parser, &dp_data,
     332                    interface);
    324333                interface = usb_dp_get_sibling_descriptor(&dp_parser, &dp_data,
    325                     config_descriptor, interface);
     334                    configuration_descriptor, interface);
    326335        } while (interface != NULL);
    327336
     
    446455 * @return Error code.
    447456 */
    448 int usb_pipe_register(usb_pipe_t *pipe, unsigned interval,
     457int 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 */
     478int usb_pipe_register_with_speed(usb_pipe_t *pipe, usb_speed_t speed,
     479    unsigned int interval,
    449480    usb_hc_connection_t *hc_connection)
    450481{
    451482        assert(pipe);
    452483        assert(hc_connection);
    453 
     484       
    454485        if (!usb_hc_connection_is_opened(hc_connection))
    455486                return EBADF;
    456 
     487       
    457488        const usb_target_t target =
    458489            {{ .address = pipe->wire->address, .endpoint = pipe->endpoint_no }};
    459 #define _PACK2(high, low) (((high & 0xffff) << 16) | (low & 0xffff))
    460 
     490#define _PACK2(high, low) (((high) << 16) + (low))
     491#define _PACK3(high, middle, low) (((((high) << 8) + (middle)) << 8) + (low))
     492       
    461493        async_exch_t *exch = async_exchange_begin(hc_connection->hc_sess);
    462494        int rc = async_req_4_0(exch, DEV_IFACE_ID(USBHC_DEV_IFACE),
    463495            IPC_M_USBHC_REGISTER_ENDPOINT, target.packed,
    464             _PACK2(pipe->transfer_type, pipe->direction),
     496            _PACK3(speed, pipe->transfer_type, pipe->direction),
    465497            _PACK2(pipe->max_packet_size, interval));
    466498        async_exchange_end(exch);
    467 
     499       
    468500#undef _PACK2
     501#undef _PACK3
     502       
    469503        return rc;
    470504}
     
    480514{
    481515        assert(pipe);
    482         assert(pipe->wire);
    483516        assert(hc_connection);
    484517       
Note: See TracChangeset for help on using the changeset viewer.