|
|
1.1 root 1: /*
2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: File: HIDNextItem.c
24:
25: Contains: xxx put contents here xxx
26:
27: Version: xxx put version here xxx
28:
29: Copyright: � 1999 by Apple Computer, Inc., all rights reserved.
30:
31: File Ownership:
32:
33: DRI: xxx put dri here xxx
34:
35: Other Contact: xxx put other contact here xxx
36:
37: Technology: xxx put technology here xxx
38:
39: Writers:
40:
41: (DF) David Ferguson
42: (JRH) Rhoads Hollowell
43: (BWS) Brent Schorsch
44:
45: Change History (most recent first):
46:
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
53: */
54:
55: #include "HIDLib.h"
56:
57: /*
58: *-----------------------------------------------------------------------------
59: *
60: * HIDNextItem - Get the Next Item
61: *
62: * Input:
63: * ptDescriptor - Descriptor Structure
64: * Output:
65: * ptItem - Caller-provided Item Structure
66: * Returns:
67: * kHIDSuccess - Success
68: * kHIDEndOfDescriptorErr - End of the HID Report Descriptor
69: *
70: *-----------------------------------------------------------------------------
71: */
72: OSStatus HIDNextItem(HIDReportDescriptor *ptDescriptor)
73: {
74: HIDItem *ptItem;
75: unsigned char iHeader;
76: unsigned char *psD;
77: int i;
78: int iLength;
79: UInt32 *piX;
80: int iSize;
81: int iByte = 0;
82: /*
83: * Disallow Null Pointers
84: */
85: if (ptDescriptor==NULL)
86: return kHIDNullPointerErr;
87: /*
88: * Use local pointers
89: */
90: ptItem = &ptDescriptor->item;
91: psD = ptDescriptor->descriptor;
92: piX = &ptDescriptor->index;
93: iLength = ptDescriptor->descriptorLength;
94: /*
95: * Don't go past the end of the buffer
96: */
97: if (*piX >= iLength)
98: return kHIDEndOfDescriptorErr;
99: /*
100: * Get the header byte
101: */
102: iHeader = psD[(*piX)++];
103: /*
104: * Don't go past the end of the buffer
105: */
106: if (*piX > iLength)
107: return kHIDEndOfDescriptorErr;
108: ptItem->itemType = iHeader;
109: ptItem->itemType &= kHIDItemTypeMask;
110: ptItem->itemType >>= kHIDItemTypeShift;
111: /*
112: * Long Item Header
113: * Skip Long Items!
114: */
115: if (iHeader==kHIDLongItemHeader)
116: {
117: iSize = psD[(*piX)++];
118: ptItem->tag = *piX++;
119: }
120: /*
121: * Short Item Header
122: */
123: else
124: {
125: iSize = iHeader;
126: iSize &= kHIDItemSizeMask;
127: if (iSize==3)
128: iSize = 4;
129: ptItem->byteCount = iSize;
130: ptItem->tag = iHeader;
131: ptItem->tag &= kHIDItemTagMask;
132: ptItem->tag >>= kHIDItemTagShift;
133: }
134: /*
135: * Don't go past the end of the buffer
136: */
137: if ((*piX + iSize) > iLength)
138: return kHIDEndOfDescriptorErr;
139: /*
140: * Pick up the data
141: */
142: ptItem->unsignedValue = 0;
143: if (iSize==0)
144: {
145: ptItem->signedValue = 0;
146: return kHIDSuccess;
147: }
148: /*
149: * Get the data bytes
150: */
151: for (i = 0; i < iSize; i++)
152: {
153: iByte = psD[(*piX)++];
154: ptItem->unsignedValue |= (iByte << (i*8));
155: }
156: /*
157: * Keep one value unsigned
158: */
159: ptItem->signedValue = ptItem->unsignedValue;
160: /*
161: * Sign extend one value
162: */
163: if ((iByte & 0x80) != 0)
164: {
165: while (i < sizeof(int))
166: ptItem->signedValue |= (0xFF << ((i++)*8));
167: }
168: return kHIDSuccess;
169: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.