Deleted Added
sdiff udiff text old ( 185087 ) new ( 186730 )
full compact
1/* $FreeBSD: head/lib/libusb20/libusb20_desc.c 186730 2009-01-04 00:12:01Z 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.

--- 223 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 const uint8_t *start;
242 const uint8_t *end;
243 const uint8_t *desc_next;
244
245 /* be NULL safe */
246 if (pdesc == NULL)
247 return (NULL);
248
249 start = (const uint8_t *)pdesc->ptr;
250 end = LIBUSB20_ADD_BYTES(start, pdesc->len);
251
252 /* get start of next descriptor */
253 if (psubdesc == NULL)
254 psubdesc = start;
255 else
256 psubdesc = psubdesc + psubdesc[0];
257
258 /* check that the next USB descriptor is within the range */
259 if ((psubdesc < start) || (psubdesc >= end))
260 return (NULL); /* out of range, or EOD */
261
262 /* check start of the second next USB descriptor, if any */
263 desc_next = psubdesc + psubdesc[0];
264 if ((desc_next < start) || (desc_next > end))
265 return (NULL); /* out of range */
266
267 /* check minimum descriptor length */
268 if (psubdesc[0] < 3)
269 return (NULL); /* too short descriptor */
270
271 return (psubdesc); /* return start of next descriptor */
272}
273
274/*------------------------------------------------------------------------*
275 * libusb20_me_get_1 - safety wrapper to read out one byte
276 *------------------------------------------------------------------------*/
277uint8_t
278libusb20_me_get_1(const struct libusb20_me_struct *ie, uint16_t offset)
279{

--- 506 unchanged lines hidden ---