libusb20_desc.c (184610) | libusb20_desc.c (185087) |
---|---|
1/* $FreeBSD: head/lib/libusb20/libusb20_desc.c 184610 2008-11-04 02:31:03Z alfred $ */ | 1/* $FreeBSD: head/lib/libusb20/libusb20_desc.c 185087 2008-11-19 08:56:35Z alfred $ */ |
2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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. --- 69 unchanged lines hidden (view full) --- 79 nendpoint = 0; 80 niface = 0; 81 iface_no = 0 - 1; 82 ptr = NULL; 83 84 /* get "wTotalLength" and setup "pcdesc" */ 85 pcdesc.ptr = LIBUSB20_ADD_BYTES(config_desc, 0); 86 pcdesc.len = | 2/*- 3 * Copyright (c) 2008 Hans Petter Selasky. 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. --- 69 unchanged lines hidden (view full) --- 79 nendpoint = 0; 80 niface = 0; 81 iface_no = 0 - 1; 82 ptr = NULL; 83 84 /* get "wTotalLength" and setup "pcdesc" */ 85 pcdesc.ptr = LIBUSB20_ADD_BYTES(config_desc, 0); 86 pcdesc.len = |
87 ((uint8_t *)config_desc)[2] | 88 (((uint8_t *)config_desc)[3] << 8); | 87 ((const uint8_t *)config_desc)[2] | 88 (((const uint8_t *)config_desc)[3] << 8); |
89 pcdesc.type = LIBUSB20_ME_IS_RAW; 90 91 /* descriptor pre-scan */ 92 while ((ptr = libusb20_desc_foreach(&pcdesc, ptr))) { 93 if (ptr[1] == LIBUSB20_DT_ENDPOINT) { 94 nendpoint++; 95 } else if ((ptr[1] == LIBUSB20_DT_INTERFACE) && (ptr[0] >= 4)) { 96 niface++; --- 136 unchanged lines hidden (view full) --- 233 * Return values: 234 * NULL: End of descriptors 235 * Else: Pointer to next descriptor 236 *------------------------------------------------------------------------*/ 237const uint8_t * 238libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, 239 const uint8_t *psubdesc) 240{ | 89 pcdesc.type = LIBUSB20_ME_IS_RAW; 90 91 /* descriptor pre-scan */ 92 while ((ptr = libusb20_desc_foreach(&pcdesc, ptr))) { 93 if (ptr[1] == LIBUSB20_DT_ENDPOINT) { 94 nendpoint++; 95 } else if ((ptr[1] == LIBUSB20_DT_INTERFACE) && (ptr[0] >= 4)) { 96 niface++; --- 136 unchanged lines hidden (view full) --- 233 * Return values: 234 * NULL: End of descriptors 235 * Else: Pointer to next descriptor 236 *------------------------------------------------------------------------*/ 237const uint8_t * 238libusb20_desc_foreach(const struct libusb20_me_struct *pdesc, 239 const uint8_t *psubdesc) 240{ |
241 void *end; | 241 const void *end; |
242 243 if (pdesc == NULL) { 244 return (NULL); 245 } 246 end = LIBUSB20_ADD_BYTES(pdesc->ptr, pdesc->len); 247 248 if (psubdesc == NULL) { 249 psubdesc = LIBUSB20_ADD_BYTES(pdesc->ptr, 0); 250 } else { 251 psubdesc = LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]); 252 } | 242 243 if (pdesc == NULL) { 244 return (NULL); 245 } 246 end = LIBUSB20_ADD_BYTES(pdesc->ptr, pdesc->len); 247 248 if (psubdesc == NULL) { 249 psubdesc = LIBUSB20_ADD_BYTES(pdesc->ptr, 0); 250 } else { 251 psubdesc = LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]); 252 } |
253 return (((((void *)psubdesc) >= ((void *)(pdesc->ptr))) && 254 (((void *)psubdesc) < end) && | 253 return (((((const void *)psubdesc) >= ((void *)(pdesc->ptr))) && 254 (((const void *)psubdesc) < end) && |
255 (LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) >= ((void *)(pdesc->ptr))) && 256 (LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) <= end) && 257 (psubdesc[0] >= 3)) ? psubdesc : NULL); 258} 259 260/*------------------------------------------------------------------------* 261 * libusb20_me_get_1 - safety wrapper to read out one byte 262 *------------------------------------------------------------------------*/ --- 38 unchanged lines hidden (view full) --- 301 uint16_t pd_count; /* decoded element count */ 302 uint8_t me; /* message element */ 303 304 /* initialise */ 305 306 len_old = len; 307 buf = ptr; 308 pd_offset = sizeof(void *); | 255 (LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) >= ((void *)(pdesc->ptr))) && 256 (LIBUSB20_ADD_BYTES(psubdesc, psubdesc[0]) <= end) && 257 (psubdesc[0] >= 3)) ? psubdesc : NULL); 258} 259 260/*------------------------------------------------------------------------* 261 * libusb20_me_get_1 - safety wrapper to read out one byte 262 *------------------------------------------------------------------------*/ --- 38 unchanged lines hidden (view full) --- 301 uint16_t pd_count; /* decoded element count */ 302 uint8_t me; /* message element */ 303 304 /* initialise */ 305 306 len_old = len; 307 buf = ptr; 308 pd_offset = sizeof(void *); |
309 pf = (*((struct libusb20_me_format **)pd))->format; | 309 pf = (*((struct libusb20_me_format *const *)pd))->format; |
310 311 /* scan */ 312 313 while (1) { 314 315 /* get information element */ 316 317 me = (pf[0]) & LIBUSB20_ME_MASK; --- 454 unchanged lines hidden --- | 310 311 /* scan */ 312 313 while (1) { 314 315 /* get information element */ 316 317 me = (pf[0]) & LIBUSB20_ME_MASK; --- 454 unchanged lines hidden --- |