descr.c (205728) | descr.c (213920) |
---|---|
1/* $NetBSD: descr.c,v 1.9 2000/09/24 02:13:24 augustss Exp $ */ 2 3/* 4 * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> 5 * 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 --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> | 1/* $NetBSD: descr.c,v 1.9 2000/09/24 02:13:24 augustss Exp $ */ 2 3/* 4 * Copyright (c) 1999 Lennart Augustsson <augustss@netbsd.org> 5 * 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 --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/lib/libusbhid/descr.c 205728 2010-03-27 08:00:16Z kaiw $"); | 30__FBSDID("$FreeBSD: head/lib/libusbhid/descr.c 213920 2010-10-16 11:20:53Z hselasky $"); |
31 32#include <sys/types.h> 33 34#include <assert.h> 35#include <errno.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> --- 59 unchanged lines hidden (view full) --- 98{ 99 struct usb_gen_descriptor ugd; 100 report_desc_t rep; 101 void *data; 102 103 memset(&ugd, 0, sizeof(ugd)); 104 105 /* get actual length first */ | 31 32#include <sys/types.h> 33 34#include <assert.h> 35#include <errno.h> 36#include <stdlib.h> 37#include <string.h> 38#include <unistd.h> --- 59 unchanged lines hidden (view full) --- 98{ 99 struct usb_gen_descriptor ugd; 100 report_desc_t rep; 101 void *data; 102 103 memset(&ugd, 0, sizeof(ugd)); 104 105 /* get actual length first */ |
106 ugd.ugd_data = NULL; | 106 ugd.ugd_data = hid_pass_ptr(NULL); |
107 ugd.ugd_maxlen = 65535; 108 if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) { 109#ifdef HID_COMPAT7 110 /* could not read descriptor */ 111 /* try FreeBSD 7 compat code */ 112 return (hid_get_report_desc_compat7(fd)); 113#else 114 return (NULL); --- 4 unchanged lines hidden (view full) --- 119 * NOTE: The kernel will return a failure if 120 * "ugd_actlen" is zero. 121 */ 122 data = malloc(ugd.ugd_actlen); 123 if (data == NULL) 124 return (NULL); 125 126 /* fetch actual descriptor */ | 107 ugd.ugd_maxlen = 65535; 108 if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) { 109#ifdef HID_COMPAT7 110 /* could not read descriptor */ 111 /* try FreeBSD 7 compat code */ 112 return (hid_get_report_desc_compat7(fd)); 113#else 114 return (NULL); --- 4 unchanged lines hidden (view full) --- 119 * NOTE: The kernel will return a failure if 120 * "ugd_actlen" is zero. 121 */ 122 data = malloc(ugd.ugd_actlen); 123 if (data == NULL) 124 return (NULL); 125 126 /* fetch actual descriptor */ |
127 ugd.ugd_data = data; | 127 ugd.ugd_data = hid_pass_ptr(data); |
128 ugd.ugd_maxlen = ugd.ugd_actlen; 129 if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) { 130 /* could not read descriptor */ 131 free(data); 132 return (NULL); 133 } 134 | 128 ugd.ugd_maxlen = ugd.ugd_actlen; 129 if (ioctl(fd, USB_GET_REPORT_DESC, &ugd) < 0) { 130 /* could not read descriptor */ 131 free(data); 132 return (NULL); 133 } 134 |
135 /* sanity check */ 136 if (ugd.ugd_actlen < 1) { 137 /* invalid report descriptor */ 138 free(data); 139 return (NULL); 140 } 141 |
|
135 /* check END_COLLECTION */ | 142 /* check END_COLLECTION */ |
136 if (((unsigned char *)ugd.ugd_data)[ugd.ugd_actlen -1] != 0xC0) { | 143 if (((unsigned char *)data)[ugd.ugd_actlen -1] != 0xC0) { |
137 /* invalid end byte */ 138 free(data); 139 return (NULL); 140 } 141 142 rep = hid_use_report_desc(data, ugd.ugd_actlen); 143 144 free(data); --- 25 unchanged lines hidden --- | 144 /* invalid end byte */ 145 free(data); 146 return (NULL); 147 } 148 149 rep = hid_use_report_desc(data, ugd.ugd_actlen); 150 151 free(data); --- 25 unchanged lines hidden --- |