Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetUsageValue.c, revision 1.1.1.1

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:           HIDGetUsageValue.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:                (BWS)   Brent Schorsch
                     42: 
                     43:        Change History (most recent first):
                     44: 
                     45:          <USB3>         11/1/99        BWS             [2405720]  We need a better check for 'bit padding' items,
                     46:                                                                        rather than just is constant. We will check to make sure the
                     47:                                                                        item is constant, and has no usage, or zero usage. This means we
                     48:                                                                        need to pass an additional parameter to some internal functions
                     49:          <USB2>          4/7/99        BWS             Add support for reversed report items
                     50:          <USB1>          3/5/99        BWS             first checked in
                     51: */
                     52: 
                     53: #include "HIDLib.h"
                     54: 
                     55: /*
                     56:  *------------------------------------------------------------------------------
                     57:  *
                     58:  * HIDGetUsageValue - Get the value for a usage
                     59:  *
                     60:  *      Input:
                     61:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
                     62:  *                       usagePage                        - Page Criteria or zero
                     63:  *                       iCollection                   - Collection Criteria or zero
                     64:  *                       usage                            - The usage to get the value for
                     65:  *                       piUsageValue                  - User-supplied place to put value
                     66:  *                       ptPreparsedData               - Pre-Parsed Data
                     67:  *                       psReport                              - An HID Report
                     68:  *                       iReportLength                 - The length of the Report
                     69:  *      Output:
                     70:  *                       piValue                               - Pointer to usage Value
                     71:  *      Returns:
                     72:  *
                     73:  *------------------------------------------------------------------------------
                     74: */
                     75: OSStatus HIDGetUsageValue
                     76:                  (HIDReportType                        reportType,
                     77:                   HIDUsage                                     usagePage,
                     78:                   UInt32                                       iCollection,
                     79:                   HIDUsage                                     usage,
                     80:                   SInt32 *                                     piUsageValue,
                     81:                   HIDPreparsedDataRef          preparsedDataRef,
                     82:                   void *                                       psReport,
                     83:                   ByteCount                            iReportLength)
                     84: {
                     85:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                     86:        HIDCollection *ptCollection;
                     87:        HIDReportItem *ptReportItem;
                     88:        OSStatus iStatus;
                     89:        int iR;
                     90:        SInt32 iValue;
                     91:        int iStart;
                     92:        int iReportItem;
                     93:        UInt32 iUsageIndex;
                     94:        Boolean bIncompatibleReport = false;
                     95: /*
                     96:  *     Disallow Null Pointers
                     97: */
                     98:        if ((ptPreparsedData == NULL)
                     99:         || (piUsageValue == NULL)
                    100:         || (psReport == NULL))
                    101:                return kHIDNullPointerErr;
                    102:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
                    103:                return kHIDInvalidPreparsedDataErr;
                    104: /*
                    105:  *     The Collection must be in range
                    106: */
                    107:        if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
                    108:                return kHIDBadParameterErr;
                    109: /*
                    110:  *     Search only the scope of the Collection specified
                    111:  *     Go through the ReportItems
                    112:  *     Filter on ReportType and usagePage
                    113: */
                    114:        ptCollection = &ptPreparsedData->collections[iCollection];
                    115:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
                    116:        {
                    117:                iReportItem = ptCollection->firstReportItem + iR;
                    118:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
                    119:                if (HIDIsVariable(ptReportItem, preparsedDataRef)
                    120:                 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
                    121:                {
                    122: /*
                    123:  *                     This may be the proper data to get
                    124:  *                     Let's check for the proper Report ID, Type, and Length
                    125: */
                    126:                        iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
                    127:                                                                           psReport,iReportLength);
                    128: /*
                    129:  *                     The Report ID or Type may not match.
                    130:  *                     This may not be an error (yet)
                    131: */
                    132:                        if (iStatus == kHIDIncompatibleReportErr)
                    133:                                bIncompatibleReport = true;
                    134:                        else if (iStatus != kHIDSuccess)
                    135:                                return iStatus;
                    136:                        else
                    137:                        {
                    138: /*
                    139:  *                             Pick up the data
                    140: */
                    141:                                iStart = ptReportItem->startBit
                    142:                                           + (ptReportItem->globals.reportSize * iUsageIndex);
                    143:                                iStatus = HIDGetData(psReport, iReportLength, iStart,
                    144:                                                                           ptReportItem->globals.reportSize, &iValue,
                    145:                                                                           ((ptReportItem->globals.logicalMinimum < 0)
                    146:                                                                          ||(ptReportItem->globals.logicalMaximum < 0)));
                    147:                                if (!iStatus)
                    148:                                        iStatus = HIDPostProcessRIValue (ptReportItem, &iValue);
                    149:                                *piUsageValue = iValue;
                    150:                                return iStatus;
                    151:                        }
                    152:                }
                    153:        }
                    154:        if (bIncompatibleReport)
                    155:                return kHIDIncompatibleReportErr;
                    156:        return kHIDUsageNotFoundErr;
                    157: }
                    158: 
                    159: /*
                    160:  *------------------------------------------------------------------------------
                    161:  *
                    162:  * HIDGetScaledUsageValue - Get the value for a usage
                    163:  *
                    164:  *      Input:
                    165:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
                    166:  *                       usagePage                        - Page Criteria or zero
                    167:  *                       iCollection                   - Collection Criteria or zero
                    168:  *                       usage                            - usage Criteria or zero
                    169:  *                       piValue                               - Pointer to usage Value
                    170:  *                       ptPreparsedData               - Pre-Parsed Data
                    171:  *                       psReport                              - An HID Report
                    172:  *                       iReportLength                 - The length of the Report
                    173:  *      Output:
                    174:  *                       piValue                               - Pointer to usage Value
                    175:  *      Returns:
                    176:  *
                    177:  *------------------------------------------------------------------------------
                    178: */
                    179: OSStatus HIDGetScaledUsageValue(HIDReportType reportType,
                    180:                                                                         HIDUsage usagePage,
                    181:                                                                         UInt32 iCollection,
                    182:                                                                         HIDUsage usage,
                    183:                                                                         SInt32 *piUsageValue,
                    184:                                                                         HIDPreparsedDataRef preparsedDataRef,
                    185:                                                                         void *psReport,
                    186:                                                                         ByteCount iReportLength)
                    187: {
                    188:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
                    189:        HIDCollection *ptCollection;
                    190:        HIDReportItem *ptReportItem;
                    191:        OSStatus iStatus;
                    192:        int iR;
                    193:        long iValue;
                    194:        int iStart;
                    195:        int iReportItem;
                    196:        UInt32 iUsageIndex;
                    197:        Boolean bIncompatibleReport = false;
                    198: /*
                    199:  *     Disallow Null Pointers
                    200: */
                    201:        if ((ptPreparsedData == NULL)
                    202:         || (piUsageValue == NULL)
                    203:         || (psReport == NULL))
                    204:                return kHIDNullPointerErr;
                    205:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
                    206:                return kHIDInvalidPreparsedDataErr;
                    207: /*
                    208:  *     The Collection must be in range
                    209: */
                    210:        if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
                    211:                return kHIDBadParameterErr;
                    212: /*
                    213:  *     Search only the scope of the Collection specified
                    214:  *     Go through the ReportItems
                    215:  *     Filter on ReportType and usagePage
                    216: */
                    217:        ptCollection = &ptPreparsedData->collections[iCollection];
                    218:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
                    219:        {
                    220:                iReportItem = ptCollection->firstReportItem + iR;
                    221:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
                    222:                if (HIDIsVariable(ptReportItem, preparsedDataRef)
                    223:                 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,NULL))
                    224:                {
                    225: /*
                    226:  *                     This may be the proper data to get
                    227:  *                     Let's check for the proper Report ID, Type, and Length
                    228: */
                    229:                        iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
                    230:                                                                           psReport,iReportLength);
                    231: /*
                    232:  *                     The Report ID or Type may not match.
                    233:  *                     This may not be an error (yet)
                    234: */
                    235:                        if (iStatus == kHIDIncompatibleReportErr)
                    236:                                bIncompatibleReport = true;
                    237:                        else if (iStatus != kHIDSuccess)
                    238:                                return iStatus;
                    239:                        else
                    240:                        {
                    241: /*
                    242:  *                             Pick up the data
                    243: */
                    244:                                iStart = ptReportItem->startBit
                    245:                                           + (ptReportItem->globals.reportSize * iUsageIndex);
                    246:                                iStatus = HIDGetData(psReport, iReportLength, iStart,
                    247:                                                                           ptReportItem->globals.reportSize, &iValue,
                    248:                                                                           ((ptReportItem->globals.logicalMinimum < 0)
                    249:                                                                          ||(ptReportItem->globals.logicalMaximum < 0)));
                    250:                                if (!iStatus)
                    251:                                        iStatus = HIDPostProcessRIValue (ptReportItem, &iValue);
                    252:                                if (iStatus != kHIDSuccess)
                    253:                                        return iStatus;
                    254: /*
                    255:  *                             Try to scale the data
                    256: */
                    257:                                 iStatus = HIDScaleUsageValueIn(ptReportItem,iValue,&iValue);
                    258:                                *piUsageValue = iValue;
                    259:                                return iStatus;
                    260:                        }
                    261:                }
                    262:        }
                    263:        if (bIncompatibleReport)
                    264:                return kHIDIncompatibleReportErr;
                    265:        return kHIDUsageNotFoundErr;
                    266: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.