libusb10_desc.c (194676) | libusb10_desc.c (195560) |
---|---|
1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 194676 2009-06-23 01:04:58Z thompsa $ */ | 1/* $FreeBSD: head/lib/libusb/libusb10_desc.c 195560 2009-07-10 14:15:53Z thompsa $ */ |
2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 32 unchanged lines hidden (view full) --- 42 struct libusb_device_descriptor *desc) 43{ 44 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 45 struct libusb20_device *pdev; 46 libusb_context *ctx; 47 48 ctx = NULL; 49 GET_CONTEXT(ctx); | 2/*- 3 * Copyright (c) 2009 Sylvestre Gallon. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. --- 32 unchanged lines hidden (view full) --- 42 struct libusb_device_descriptor *desc) 43{ 44 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 45 struct libusb20_device *pdev; 46 libusb_context *ctx; 47 48 ctx = NULL; 49 GET_CONTEXT(ctx); |
50 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor enter"); | 50 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor enter"); |
51 52 if ((dev == NULL) || (desc == NULL)) 53 return (LIBUSB_ERROR_INVALID_PARAM); 54 55 pdev = dev->os_priv; 56 pdesc = libusb20_dev_get_device_desc(pdev); 57 58 desc->bLength = pdesc->bLength; --- 6 unchanged lines hidden (view full) --- 65 desc->idVendor = pdesc->idVendor; 66 desc->idProduct = pdesc->idProduct; 67 desc->bcdDevice = pdesc->bcdDevice; 68 desc->iManufacturer = pdesc->iManufacturer; 69 desc->iProduct = pdesc->iProduct; 70 desc->iSerialNumber = pdesc->iSerialNumber; 71 desc->bNumConfigurations = pdesc->bNumConfigurations; 72 | 51 52 if ((dev == NULL) || (desc == NULL)) 53 return (LIBUSB_ERROR_INVALID_PARAM); 54 55 pdev = dev->os_priv; 56 pdesc = libusb20_dev_get_device_desc(pdev); 57 58 desc->bLength = pdesc->bLength; --- 6 unchanged lines hidden (view full) --- 65 desc->idVendor = pdesc->idVendor; 66 desc->idProduct = pdesc->idProduct; 67 desc->bcdDevice = pdesc->bcdDevice; 68 desc->iManufacturer = pdesc->iManufacturer; 69 desc->iProduct = pdesc->iProduct; 70 desc->iSerialNumber = pdesc->iSerialNumber; 71 desc->bNumConfigurations = pdesc->bNumConfigurations; 72 |
73 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor leave"); | 73 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_device_descriptor leave"); |
74 return (0); 75} 76 77int 78libusb_get_active_config_descriptor(libusb_device * dev, 79 struct libusb_config_descriptor **config) 80{ 81 struct libusb20_device *pdev; 82 libusb_context *ctx; 83 uint8_t idx; 84 85 ctx = NULL; 86 GET_CONTEXT(ctx); | 74 return (0); 75} 76 77int 78libusb_get_active_config_descriptor(libusb_device * dev, 79 struct libusb_config_descriptor **config) 80{ 81 struct libusb20_device *pdev; 82 libusb_context *ctx; 83 uint8_t idx; 84 85 ctx = NULL; 86 GET_CONTEXT(ctx); |
87 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor enter"); | 87 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor enter"); |
88 89 pdev = dev->os_priv; 90 idx = libusb20_dev_get_config_index(pdev); 91 | 88 89 pdev = dev->os_priv; 90 idx = libusb20_dev_get_config_index(pdev); 91 |
92 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor leave"); | 92 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_active_config_descriptor leave"); |
93 return (libusb_get_config_descriptor(dev, idx, config)); 94} 95 96/* 97 * XXX Need to check if extra need a dup because 98 * XXX free pconf could free this char * 99 */ 100int --- 7 unchanged lines hidden (view full) --- 108 libusb_interface_descriptor *ifd; 109 libusb_endpoint_descriptor *endd; 110 libusb_context *ctx; 111 uint8_t nif, nend, nalt, i, j, k; 112 uint32_t if_idx, endp_idx; 113 114 ctx = NULL; 115 GET_CONTEXT(ctx); | 93 return (libusb_get_config_descriptor(dev, idx, config)); 94} 95 96/* 97 * XXX Need to check if extra need a dup because 98 * XXX free pconf could free this char * 99 */ 100int --- 7 unchanged lines hidden (view full) --- 108 libusb_interface_descriptor *ifd; 109 libusb_endpoint_descriptor *endd; 110 libusb_context *ctx; 111 uint8_t nif, nend, nalt, i, j, k; 112 uint32_t if_idx, endp_idx; 113 114 ctx = NULL; 115 GET_CONTEXT(ctx); |
116 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor enter"); | 116 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor enter"); |
117 118 if (dev == NULL || config == NULL) 119 return (LIBUSB_ERROR_INVALID_PARAM); 120 121 pdev = dev->os_priv; 122 pconf = libusb20_dev_alloc_config(pdev, config_index); 123 124 if (pconf == NULL) --- 95 unchanged lines hidden (view full) --- 220 endd->extra_length = pend->extra.len; 221 if (endd->extra_length != 0) 222 endd->extra = pend->extra.ptr; 223 } 224 } 225 } 226 227 free(pconf); | 117 118 if (dev == NULL || config == NULL) 119 return (LIBUSB_ERROR_INVALID_PARAM); 120 121 pdev = dev->os_priv; 122 pconf = libusb20_dev_alloc_config(pdev, config_index); 123 124 if (pconf == NULL) --- 95 unchanged lines hidden (view full) --- 220 endd->extra_length = pend->extra.len; 221 if (endd->extra_length != 0) 222 endd->extra = pend->extra.ptr; 223 } 224 } 225 } 226 227 free(pconf); |
228 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor leave"); | 228 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor leave"); |
229 return (0); 230} 231 232int 233libusb_get_config_descriptor_by_value(libusb_device * dev, 234 uint8_t bConfigurationValue, struct libusb_config_descriptor **config) 235{ 236 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 237 struct libusb20_device *pdev; 238 struct libusb20_config *pconf; 239 libusb_context *ctx; 240 int i; 241 242 ctx = NULL; 243 GET_CONTEXT(ctx); | 229 return (0); 230} 231 232int 233libusb_get_config_descriptor_by_value(libusb_device * dev, 234 uint8_t bConfigurationValue, struct libusb_config_descriptor **config) 235{ 236 struct LIBUSB20_DEVICE_DESC_DECODED *pdesc; 237 struct libusb20_device *pdev; 238 struct libusb20_config *pconf; 239 libusb_context *ctx; 240 int i; 241 242 ctx = NULL; 243 GET_CONTEXT(ctx); |
244 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value enter"); | 244 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value enter"); |
245 246 if (dev == NULL || config == NULL) 247 return (LIBUSB_ERROR_INVALID_PARAM); 248 249 pdev = dev->os_priv; 250 pdesc = libusb20_dev_get_device_desc(pdev); 251 252 for (i = 0 ; i < pdesc->bNumConfigurations ; i++) { 253 pconf = libusb20_dev_alloc_config(pdev, i); 254 if (pconf->desc.bConfigurationValue == bConfigurationValue) { 255 free(pconf); 256 return libusb_get_config_descriptor(dev, i, config); 257 258 } 259 free(pconf); 260 } 261 | 245 246 if (dev == NULL || config == NULL) 247 return (LIBUSB_ERROR_INVALID_PARAM); 248 249 pdev = dev->os_priv; 250 pdesc = libusb20_dev_get_device_desc(pdev); 251 252 for (i = 0 ; i < pdesc->bNumConfigurations ; i++) { 253 pconf = libusb20_dev_alloc_config(pdev, i); 254 if (pconf->desc.bConfigurationValue == bConfigurationValue) { 255 free(pconf); 256 return libusb_get_config_descriptor(dev, i, config); 257 258 } 259 free(pconf); 260 } 261 |
262 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value leave"); | 262 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_config_descriptor_by_value leave"); |
263 return (LIBUSB_ERROR_NOT_FOUND); 264} 265 266void 267libusb_free_config_descriptor(struct libusb_config_descriptor *config) 268{ 269 libusb_context *ctx; 270 271 ctx = NULL; 272 GET_CONTEXT(ctx); | 263 return (LIBUSB_ERROR_NOT_FOUND); 264} 265 266void 267libusb_free_config_descriptor(struct libusb_config_descriptor *config) 268{ 269 libusb_context *ctx; 270 271 ctx = NULL; 272 GET_CONTEXT(ctx); |
273 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor enter"); | 273 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor enter"); |
274 275 free(config); | 274 275 free(config); |
276 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor leave"); | 276 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_free_config_descriptor leave"); |
277} 278 279int 280libusb_get_string_descriptor_ascii(libusb_device_handle * dev, 281 uint8_t desc_index, unsigned char *data, int length) 282{ 283 struct libusb20_device *pdev; 284 libusb_context *ctx; | 277} 278 279int 280libusb_get_string_descriptor_ascii(libusb_device_handle * dev, 281 uint8_t desc_index, unsigned char *data, int length) 282{ 283 struct libusb20_device *pdev; 284 libusb_context *ctx; |
285 int ret; | |
286 287 ctx = NULL; 288 GET_CONTEXT(ctx); | 285 286 ctx = NULL; 287 GET_CONTEXT(ctx); |
289 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii enter"); | 288 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii enter"); |
290 291 if (dev == NULL || data == NULL) 292 return (LIBUSB20_ERROR_INVALID_PARAM); 293 294 pdev = dev->os_priv; | 289 290 if (dev == NULL || data == NULL) 291 return (LIBUSB20_ERROR_INVALID_PARAM); 292 293 pdev = dev->os_priv; |
295 dprintf(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii leave"); | 294 DPRINTF(ctx, LIBUSB_DEBUG_FUNCTION, "libusb_get_string_descriptor_ascii leave"); |
296 if (libusb20_dev_req_string_simple_sync(pdev, desc_index, 297 data, length) == 0) 298 return (strlen(data)); 299 300 return (LIBUSB_ERROR_OTHER); 301} | 295 if (libusb20_dev_req_string_simple_sync(pdev, desc_index, 296 data, length) == 0) 297 return (strlen(data)); 298 299 return (LIBUSB_ERROR_OTHER); 300} |