Changeset f401312 in mainline for uspace/lib/usb/src/recognise.c


Ignore:
Timestamp:
2011-01-14T12:34:42Z (13 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
45019865
Parents:
b2a6fcfe (diff), 6610565b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merged development into lelian/hidd

File:
1 edited

Legend:

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

    rb2a6fcfe rf401312  
    129129}
    130130
     131/** Create DDF match ids from USB device descriptor.
     132 *
     133 * @param matches List of match ids to extend.
     134 * @param device_descriptor Device descriptor returned by given device.
     135 * @return Error code.
     136 */
     137int usb_drv_create_match_ids_from_device_descriptor(
     138    match_id_list_t *matches,
     139    const usb_standard_device_descriptor_t *device_descriptor)
     140{
     141        int rc;
     142       
     143        /*
     144         * Unless the vendor id is 0, the pair idVendor-idProduct
     145         * quite uniquely describes the device.
     146         */
     147        if (device_descriptor->vendor_id != 0) {
     148                /* First, with release number. */
     149                rc = usb_add_match_id(matches, 100,
     150                    "usb&vendor=%d&product=%d&release=" BCD_FMT,
     151                    (int) device_descriptor->vendor_id,
     152                    (int) device_descriptor->product_id,
     153                    BCD_ARGS(device_descriptor->device_version));
     154                if (rc != EOK) {
     155                        return rc;
     156                }
     157               
     158                /* Next, without release number. */
     159                rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",
     160                    (int) device_descriptor->vendor_id,
     161                    (int) device_descriptor->product_id);
     162                if (rc != EOK) {
     163                        return rc;
     164                }
     165        }       
     166
     167        /*
     168         * If the device class points to interface we skip adding
     169         * class directly.
     170         */
     171        if (device_descriptor->device_class != USB_CLASS_USE_INTERFACE) {
     172                rc = usb_add_match_id(matches, 50, "usb&class=%s",
     173                    usb_str_class(device_descriptor->device_class));
     174                if (rc != EOK) {
     175                        return rc;
     176                }
     177        }
     178       
     179        return EOK;
     180}
     181
     182/** Create DDF match ids from USB configuration descriptor.
     183 * The configuration descriptor is expected to be in the complete form,
     184 * i.e. including interface, endpoint etc. descriptors.
     185 *
     186 * @param matches List of match ids to extend.
     187 * @param config_descriptor Configuration descriptor returned by given device.
     188 * @param total_size Size of the @p config_descriptor.
     189 * @return Error code.
     190 */
     191int usb_drv_create_match_ids_from_configuration_descriptor(
     192    match_id_list_t *matches,
     193    const void *config_descriptor, size_t total_size)
     194{
     195        /*
     196         * Iterate through config descriptor to find the interface
     197         * descriptors.
     198         */
     199        size_t position = sizeof(usb_standard_configuration_descriptor_t);
     200        while (position + 1 < total_size) {
     201                uint8_t *current_descriptor
     202                    = ((uint8_t *) config_descriptor) + position;
     203                uint8_t cur_descr_len = current_descriptor[0];
     204                uint8_t cur_descr_type = current_descriptor[1];
     205               
     206                position += cur_descr_len;
     207               
     208                if (cur_descr_type != USB_DESCTYPE_INTERFACE) {
     209                        continue;
     210                }
     211               
     212                /*
     213                 * Finally, we found an interface descriptor.
     214                 */
     215                usb_standard_interface_descriptor_t *interface
     216                    = (usb_standard_interface_descriptor_t *)
     217                    current_descriptor;
     218               
     219                int rc = usb_add_match_id(matches, 50,
     220                    "usb&interface&class=%s",
     221                    usb_str_class(interface->interface_class));
     222                if (rc != EOK) {
     223                        return rc;
     224                }
     225        }
     226       
     227        return EOK;
     228}
     229
    131230/** Add match ids based on configuration descriptor.
    132231 *
     
    169268                        continue;
    170269                }
    171 
    172                 /*
    173                  * Iterate through config descriptor to find the interface
    174                  * descriptors.
    175                  */
    176                 size_t position = sizeof(config_descriptor);
    177                 while (position + 1 < full_config_descriptor_size) {
    178                         uint8_t *current_descriptor
    179                             = ((uint8_t *) full_config_descriptor) + position;
    180                         uint8_t cur_descr_len = current_descriptor[0];
    181                         uint8_t cur_descr_type = current_descriptor[1];
    182                        
    183                         position += cur_descr_len;
    184                        
    185                         if (cur_descr_type != USB_DESCTYPE_INTERFACE) {
    186                                 continue;
    187                         }
    188                         /*
    189                          * Finally, we found an interface descriptor.
    190                          */
    191                         usb_standard_interface_descriptor_t *interface
    192                             = (usb_standard_interface_descriptor_t *)
    193                             current_descriptor;
    194                        
    195                         rc = usb_add_match_id(matches, 50,
    196                             "usb&interface&class=%s",
    197                             usb_str_class(interface->interface_class));
    198                         if (rc != EOK) {
    199                                 final_rc = rc;
    200                                 break;
    201                         }
    202                 }
     270               
     271                rc = usb_drv_create_match_ids_from_configuration_descriptor(
     272                    matches,
     273                    full_config_descriptor, full_config_descriptor_size);
     274                if (rc != EOK) {
     275                        final_rc = rc;
     276                        continue;
     277                }
     278               
    203279        }
    204280       
     
    220296{
    221297        int rc;
     298       
     299        /*
     300         * Retrieve device descriptor and add matches from it.
     301         */
    222302        usb_standard_device_descriptor_t device_descriptor;
    223303
     
    227307                return rc;
    228308        }
    229 
    230         /*
    231          * Unless the vendor id is 0, the pair idVendor-idProduct
    232          * quite uniquely describes the device.
    233          */
    234         if (device_descriptor.vendor_id != 0) {
    235                 /* First, with release number. */
    236                 rc = usb_add_match_id(matches, 100,
    237                     "usb&vendor=%d&product=%d&release=" BCD_FMT,
    238                     (int) device_descriptor.vendor_id,
    239                     (int) device_descriptor.product_id,
    240                     BCD_ARGS(device_descriptor.device_version));
    241                 if (rc != EOK) {
    242                         return rc;
    243                 }
    244                
    245                 /* Next, without release number. */
    246                 rc = usb_add_match_id(matches, 90, "usb&vendor=%d&product=%d",
    247                     (int) device_descriptor.vendor_id,
    248                     (int) device_descriptor.product_id);
    249                 if (rc != EOK) {
    250                         return rc;
    251                 }
    252 
    253         }       
    254 
    255         /*
    256          * If the device class points to interface we skip adding
    257          * class directly.
    258          */
    259         if (device_descriptor.device_class != USB_CLASS_USE_INTERFACE) {
    260                 rc = usb_add_match_id(matches, 50, "usb&class=%s",
    261                     usb_str_class(device_descriptor.device_class));
    262                 if (rc != EOK) {
    263                         return rc;
    264                 }
    265         }
     309       
     310        rc = usb_drv_create_match_ids_from_device_descriptor(matches,
     311            &device_descriptor);
     312        if (rc != EOK) {
     313                return rc;
     314        }
     315       
    266316        /*
    267317         * Go through all configurations and add matches
Note: See TracChangeset for help on using the changeset viewer.