usb_request.c (250204) | usb_request.c (250207) |
---|---|
1/* $FreeBSD: head/sys/dev/usb/usb_request.c 250204 2013-05-03 09:23:06Z hselasky $ */ | 1/* $FreeBSD: head/sys/dev/usb/usb_request.c 250207 2013-05-03 11:10:04Z hselasky $ */ |
2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 1245 unchanged lines hidden (view full) --- 1255 if (UGETW(d->wTotalLength) < (uint16_t)sizeof(*d)) { 1256 err = USB_ERR_INVAL; 1257 } 1258done: 1259 return (err); 1260} 1261 1262/*------------------------------------------------------------------------* | 2/*- 3 * Copyright (c) 1998 The NetBSD Foundation, Inc. All rights reserved. 4 * Copyright (c) 1998 Lennart Augustsson. All rights reserved. 5 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: --- 1245 unchanged lines hidden (view full) --- 1255 if (UGETW(d->wTotalLength) < (uint16_t)sizeof(*d)) { 1256 err = USB_ERR_INVAL; 1257 } 1258done: 1259 return (err); 1260} 1261 1262/*------------------------------------------------------------------------* |
1263 * usbd_alloc_config_desc 1264 * 1265 * This function is used to allocate a zeroed configuration 1266 * descriptor. 1267 * 1268 * Returns: 1269 * NULL: Failure 1270 * Else: Success 1271 *------------------------------------------------------------------------*/ 1272void * 1273usbd_alloc_config_desc(struct usb_device *udev, uint32_t size) 1274{ 1275 if (size > USB_CONFIG_MAX) { 1276 DPRINTF("Configuration descriptor too big\n"); 1277 return (NULL); 1278 } 1279#if (USB_HAVE_FIXED_CONFIG == 0) 1280 return (malloc(size, M_USBDEV, M_ZERO | M_WAITOK)); 1281#else 1282 memset(udev->config_data, 0, sizeof(udev->config_data)); 1283 return (udev->config_data); 1284#endif 1285} 1286 1287/*------------------------------------------------------------------------* 1288 * usbd_alloc_config_desc 1289 * 1290 * This function is used to free a configuration descriptor. 1291 *------------------------------------------------------------------------*/ 1292void 1293usbd_free_config_desc(struct usb_device *udev, void *ptr) 1294{ 1295#if (USB_HAVE_FIXED_CONFIG == 0) 1296 free(ptr, M_USBDEV); 1297#endif 1298} 1299 1300/*------------------------------------------------------------------------* |
|
1263 * usbd_req_get_config_desc_full 1264 * 1265 * This function gets the complete USB configuration descriptor and | 1301 * usbd_req_get_config_desc_full 1302 * 1303 * This function gets the complete USB configuration descriptor and |
1266 * ensures that "wTotalLength" is correct. | 1304 * ensures that "wTotalLength" is correct. The returned configuration 1305 * descriptor is freed by calling "usbd_free_config_desc()". |
1267 * 1268 * Returns: 1269 * 0: Success 1270 * Else: Failure 1271 *------------------------------------------------------------------------*/ 1272usb_error_t 1273usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx, | 1306 * 1307 * Returns: 1308 * 0: Success 1309 * Else: Failure 1310 *------------------------------------------------------------------------*/ 1311usb_error_t 1312usbd_req_get_config_desc_full(struct usb_device *udev, struct mtx *mtx, |
1274 struct usb_config_descriptor **ppcd, struct malloc_type *mtype, 1275 uint8_t index) | 1313 struct usb_config_descriptor **ppcd, uint8_t index) |
1276{ 1277 struct usb_config_descriptor cd; 1278 struct usb_config_descriptor *cdesc; 1279 uint32_t len; 1280 usb_error_t err; 1281 1282 DPRINTFN(4, "index=%d\n", index); 1283 --- 7 unchanged lines hidden (view full) --- 1291 len = UGETW(cd.wTotalLength); 1292 if (len < (uint32_t)sizeof(*cdesc)) { 1293 /* corrupt descriptor */ 1294 return (USB_ERR_INVAL); 1295 } else if (len > USB_CONFIG_MAX) { 1296 DPRINTF("Configuration descriptor was truncated\n"); 1297 len = USB_CONFIG_MAX; 1298 } | 1314{ 1315 struct usb_config_descriptor cd; 1316 struct usb_config_descriptor *cdesc; 1317 uint32_t len; 1318 usb_error_t err; 1319 1320 DPRINTFN(4, "index=%d\n", index); 1321 --- 7 unchanged lines hidden (view full) --- 1329 len = UGETW(cd.wTotalLength); 1330 if (len < (uint32_t)sizeof(*cdesc)) { 1331 /* corrupt descriptor */ 1332 return (USB_ERR_INVAL); 1333 } else if (len > USB_CONFIG_MAX) { 1334 DPRINTF("Configuration descriptor was truncated\n"); 1335 len = USB_CONFIG_MAX; 1336 } |
1299 cdesc = malloc(len, mtype, M_WAITOK); | 1337 cdesc = usbd_alloc_config_desc(udev, len); |
1300 if (cdesc == NULL) 1301 return (USB_ERR_NOMEM); 1302 err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0, 1303 UDESC_CONFIG, index, 3); 1304 if (err) { | 1338 if (cdesc == NULL) 1339 return (USB_ERR_NOMEM); 1340 err = usbd_req_get_desc(udev, mtx, NULL, cdesc, len, len, 0, 1341 UDESC_CONFIG, index, 3); 1342 if (err) { |
1305 free(cdesc, mtype); | 1343 usbd_free_config_desc(udev, cdesc); |
1306 return (err); 1307 } 1308 /* make sure that the device is not fooling us: */ 1309 USETW(cdesc->wTotalLength, len); 1310 1311 *ppcd = cdesc; 1312 1313 return (0); /* success */ --- 920 unchanged lines hidden --- | 1344 return (err); 1345 } 1346 /* make sure that the device is not fooling us: */ 1347 USETW(cdesc->wTotalLength, len); 1348 1349 *ppcd = cdesc; 1350 1351 return (0); /* success */ --- 920 unchanged lines hidden --- |