]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDNextItem.c
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
25 Contains: xxx put contents here xxx
27 Version: xxx put version here xxx
29 Copyright: © 1999 by Apple Computer, Inc., all rights reserved.
33 DRI: xxx put dri here xxx
35 Other Contact: xxx put other contact here xxx
37 Technology: xxx put technology here xxx
42 (JRH) Rhoads Hollowell
45 Change History (most recent first):
47 <USB4> 11/3/99 DF And now I get to add the code to actually fix the checkin below.
48 <USB3> 11/1/99 BWS Fix long item calc error, fix by Dave Ferguson
49 <USB2> 6/1/99 JRH Get rid of an uninitialized variable warning. It turns out that
50 with the code flow it was never being used before being
51 initialized, but the compiler was complaining.
52 <USB1> 3/5/99 BWS first checked in
58 *-----------------------------------------------------------------------------
60 * HIDNextItem - Get the Next Item
63 * ptDescriptor - Descriptor Structure
65 * ptItem - Caller-provided Item Structure
67 * kHIDSuccess - Success
68 * kHIDEndOfDescriptorErr - End of the HID Report Descriptor
70 *-----------------------------------------------------------------------------
72 OSStatus
HIDNextItem(HIDReportDescriptor
*ptDescriptor
)
75 unsigned char iHeader
;
83 * Disallow Null Pointers
85 if (ptDescriptor
==NULL
)
86 return kHIDNullPointerErr
;
90 ptItem
= &ptDescriptor
->item
;
91 psD
= ptDescriptor
->descriptor
;
92 piX
= &ptDescriptor
->index
;
93 iLength
= ptDescriptor
->descriptorLength
;
95 * Don't go past the end of the buffer
98 return kHIDEndOfDescriptorErr
;
100 * Get the header byte
102 iHeader
= psD
[(*piX
)++];
104 * Don't go past the end of the buffer
107 return kHIDEndOfDescriptorErr
;
108 ptItem
->itemType
= iHeader
;
109 ptItem
->itemType
&= kHIDItemTypeMask
;
110 ptItem
->itemType
>>= kHIDItemTypeShift
;
115 if (iHeader
==kHIDLongItemHeader
)
117 iSize
= psD
[(*piX
)++];
118 ptItem
->tag
= *piX
++;
126 iSize
&= kHIDItemSizeMask
;
129 ptItem
->byteCount
= iSize
;
130 ptItem
->tag
= iHeader
;
131 ptItem
->tag
&= kHIDItemTagMask
;
132 ptItem
->tag
>>= kHIDItemTagShift
;
135 * Don't go past the end of the buffer
137 if ((*piX
+ iSize
) > iLength
)
138 return kHIDEndOfDescriptorErr
;
142 ptItem
->unsignedValue
= 0;
145 ptItem
->signedValue
= 0;
151 for (i
= 0; i
< iSize
; i
++)
153 iByte
= psD
[(*piX
)++];
154 ptItem
->unsignedValue
|= (iByte
<< (i
*8));
157 * Keep one value unsigned
159 ptItem
->signedValue
= ptItem
->unsignedValue
;
161 * Sign extend one value
163 if ((iByte
& 0x80) != 0)
165 while (i
< sizeof(int))
166 ptItem
->signedValue
|= (0xFF << ((i
++)*8));