Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDGetValueCaps.c, revision 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:           HIDGetValueCaps.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:          <USB6>         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:          <USB5>          5/3/99        BWS             Fix typo
        !            50:          <USB4>          5/3/99        BWS             We were not setting isStringRange, isDesignatorRange, and
        !            51:                                                                        isAbsolute
        !            52:          <USB3>          3/7/99        BWS             When range/notRange were made a union, we missed this case where
        !            53:                                                                        they were both being set indescriminately
        !            54:          <USB2>          3/7/99        BWS             [2311411]  Had added missing fields to caps structure, but they
        !            55:                                                                        were not being filled in
        !            56:          <USB1>          3/5/99        BWS             first checked in
        !            57: */
        !            58: 
        !            59: #include "HIDLib.h"
        !            60: 
        !            61: /*
        !            62:  *------------------------------------------------------------------------------
        !            63:  *
        !            64:  * HIDGetSpecificValueCaps - Get the binary values for a report type
        !            65:  *
        !            66:  *      Input:
        !            67:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
        !            68:  *                       usagePage                        - Page Criteria or zero
        !            69:  *                       iCollection                   - Collection Criteria or zero
        !            70:  *                       usage                            - usage Criteria or zero
        !            71:  *                       valueCaps                      - ValueCaps Array
        !            72:  *                       piValueCapsLength        - Maximum Entries
        !            73:  *                       ptPreparsedData               - Pre-Parsed Data
        !            74:  *      Output:
        !            75:  *                       piValueCapsLength        - Entries Populated
        !            76:  *      Returns:
        !            77:  *
        !            78:  *------------------------------------------------------------------------------
        !            79: */
        !            80: OSStatus HIDGetSpecificValueCaps(HIDReportType reportType,
        !            81:                                                                          HIDUsage usagePage,
        !            82:                                                                          UInt32 iCollection,
        !            83:                                                                          HIDUsage usage,
        !            84:                                                                          HIDValueCapsPtr valueCaps,
        !            85:                                                                          UInt32 *piValueCapsLength,
        !            86:                                                                          HIDPreparsedDataRef preparsedDataRef)
        !            87: {
        !            88:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
        !            89:        HIDCollection *ptCollection;
        !            90:        HIDCollection *ptParent;
        !            91:        HIDReportItem *ptReportItem;
        !            92:        HIDP_UsageItem *ptUsageItem;
        !            93:        HIDStringItem *ptStringItem;
        !            94:        HIDDesignatorItem *ptDesignatorItem;
        !            95:        HIDP_UsageItem *ptFirstCollectionUsageItem;
        !            96:        HIDValueCaps *ptCapability;
        !            97:        int iR, iU;
        !            98:        int parent;
        !            99:        int iReportItem, iUsageItem;
        !           100:        int iMaxCaps;
        !           101:        UInt32 iCount;
        !           102:         UInt32 startBit;       // Added esb 9-29-99
        !           103: /*
        !           104:  *     Disallow Null Pointers
        !           105: */
        !           106:        if ((valueCaps == NULL)
        !           107:         || (piValueCapsLength == NULL)
        !           108:         || (ptPreparsedData == NULL))
        !           109:                return kHIDNullPointerErr;
        !           110:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
        !           111:                return kHIDInvalidPreparsedDataErr;
        !           112: /*
        !           113:  *     Save the buffer size
        !           114: */
        !           115:        iMaxCaps = *piValueCapsLength;
        !           116:        *piValueCapsLength = 0;
        !           117: /*
        !           118:  *     The Collection must be in range
        !           119: */
        !           120:        if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
        !           121:                return kHIDBadParameterErr;
        !           122: /*
        !           123:  *     Search only the scope of the Collection specified
        !           124: */
        !           125:        ptCollection = &ptPreparsedData->collections[iCollection];
        !           126:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
        !           127:        {
        !           128:                iReportItem = ptCollection->firstReportItem + iR;
        !           129:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
        !           130: /*
        !           131:  *             Search only reports of the proper type
        !           132: */
        !           133:                if ((ptReportItem->reportType == reportType)
        !           134:                 && ((ptReportItem->globals.usagePage == usagePage)
        !           135:                  || (usagePage == 0))
        !           136:                 && HIDIsVariable(ptReportItem, preparsedDataRef))
        !           137:                {
        !           138:                         startBit = ptReportItem->startBit;     // Added esb 9-28-99
        !           139: /*
        !           140:  *                     Search the usages
        !           141: */
        !           142:                          for (iU=0; iU<ptReportItem->usageItemCount; iU++)
        !           143:                          {
        !           144: /*
        !           145:  *                               Copy all usages if the usage above is zero
        !           146:  *                                     or copy all that "match"
        !           147: */
        !           148:                                  iUsageItem = ptReportItem->firstUsageItem + iU;
        !           149:                                  ptUsageItem = &ptPreparsedData->usageItems[iUsageItem];
        !           150:                                  
        !           151:                                  // �� we assume there is a 1-1 corresponence between usage items, string items, and designator items
        !           152:                                  // ���this is not necessarily the case, but its better than nothing
        !           153:                                  ptStringItem = &ptPreparsedData->stringItems[ptReportItem->firstStringItem + iU];
        !           154:                                  ptDesignatorItem = &ptPreparsedData->desigItems[ptReportItem->firstDesigItem + iU];
        !           155: 
        !           156:                                  if (HIDUsageInRange(ptUsageItem,usagePage,usage))
        !           157:                                  {
        !           158: /*
        !           159:  *                                       Only copy if there's room
        !           160: */
        !           161:                                          if (*piValueCapsLength >= iMaxCaps)
        !           162:                                                  return kHIDBufferTooSmallErr;
        !           163:                                          ptCapability = &valueCaps[(*piValueCapsLength)++];
        !           164: 
        !           165: 
        !           166: 
        !           167: /*
        !           168:  *                                       Populate the Capability Structure
        !           169: */
        !           170:                                          parent = ptReportItem->parent;
        !           171:                                          ptParent = &ptPreparsedData->collections[parent];
        !           172:                                          ptFirstCollectionUsageItem = &ptPreparsedData->usageItems[ptParent->firstUsageItem];
        !           173:                                          ptCapability->collection = parent;
        !           174:                                          ptCapability->collectionUsagePage = ptParent->usagePage;
        !           175:                                          ptCapability->collectionUsage = ptFirstCollectionUsageItem->usage;
        !           176:                                          ptCapability->bitField =      ptReportItem->dataModes;
        !           177:                                          ptCapability->reportID = ptReportItem->globals.reportID;
        !           178:                                          ptCapability->usagePage = ptUsageItem->usagePage;
        !           179:                                        
        !           180:                                          ptCapability->isAbsolute = !(ptReportItem->dataModes & kHIDDataRelative);
        !           181: 
        !           182:                                          ptCapability->isRange = ptUsageItem->isRange;
        !           183:                                          if (ptUsageItem->isRange)
        !           184:                                          {
        !           185:                                                ptCapability->u.range.usageMin = ptUsageItem->usageMinimum;
        !           186:                                                ptCapability->u.range.usageMax = ptUsageItem->usageMaximum;
        !           187:                                          }
        !           188:                                          else
        !           189:                                                ptCapability->u.notRange.usage = ptUsageItem->usage;
        !           190: 
        !           191:                                          // if there really are that many items
        !           192:                                          if (iU < ptReportItem->stringItemCount)
        !           193:                                          {
        !           194:                                                  ptCapability->isStringRange = ptStringItem->isRange;
        !           195:                                                  
        !           196:                                                  if (ptStringItem->isRange)
        !           197:                                                  {
        !           198:                                                        ptCapability->u.range.stringMin = ptStringItem->minimum;
        !           199:                                                        ptCapability->u.range.stringMax = ptStringItem->maximum;
        !           200:                                                  }
        !           201:                                                  else
        !           202:                                                        ptCapability->u.notRange.stringIndex = ptStringItem->index;
        !           203:                                          }
        !           204:                                          // default, clear it
        !           205:                                          else
        !           206:                                          {
        !           207:                                                ptCapability->isStringRange = false;
        !           208:                                                ptCapability->u.notRange.stringIndex = 0;
        !           209:                                          }
        !           210: 
        !           211:                                          // if there really are that many items
        !           212:                                          if (iU < ptReportItem->desigItemCount)
        !           213:                                          {
        !           214:                                                  ptCapability->isDesignatorRange = ptDesignatorItem->isRange;
        !           215:                                                  
        !           216:                                                  if (ptDesignatorItem->isRange)
        !           217:                                                  {
        !           218:                                                        ptCapability->u.range.designatorMin = ptDesignatorItem->minimum;
        !           219:                                                        ptCapability->u.range.designatorMax = ptDesignatorItem->maximum;
        !           220:                                                  }
        !           221:                                                  else
        !           222:                                                        ptCapability->u.notRange.designatorIndex = ptDesignatorItem->index;
        !           223:                                          }
        !           224:                                          // default, clear it
        !           225:                                          else
        !           226:                                          {
        !           227:                                                ptCapability->isDesignatorRange = false;
        !           228:                                                ptCapability->u.notRange.designatorIndex = 0;
        !           229:                                          }
        !           230: 
        !           231:                                          ptCapability->bitSize = ptReportItem->globals.reportSize;
        !           232: 
        !           233:                                          ptCapability->logicalMin = ptReportItem->globals.logicalMinimum;
        !           234:                                          ptCapability->logicalMax = ptReportItem->globals.logicalMaximum;
        !           235:                                          ptCapability->physicalMin = ptReportItem->globals.physicalMinimum;
        !           236:                                          ptCapability->physicalMax = ptReportItem->globals.physicalMaximum;
        !           237: 
        !           238:                                          if (ptUsageItem->isRange)
        !           239:                                          {
        !           240:                                                  iCount = ptUsageItem->usageMaximum - ptUsageItem->usageMinimum;
        !           241:                                                  if (iCount < 0)
        !           242:                                                          iCount = -iCount;
        !           243:                                          }
        !           244:                                          else
        !           245:                                                  HIDHasUsage(preparsedDataRef,ptReportItem,
        !           246:                                                                                ptUsageItem->usagePage,ptUsageItem->usage,
        !           247:                                                                                NULL,&iCount);
        !           248:                                          ptCapability->reportCount = iCount;
        !           249:                                           ptCapability->startBit = startBit;
        !           250:                                           startBit += (ptCapability->bitSize * ptCapability->reportCount);
        !           251:                                  }
        !           252:                          }
        !           253:                }
        !           254:        }
        !           255:        return kHIDSuccess;
        !           256: }
        !           257: 
        !           258: /*
        !           259:  *------------------------------------------------------------------------------
        !           260:  *
        !           261:  * HIDGetValueCaps - Get the binary values for a report type
        !           262:  *
        !           263:  *      Input:
        !           264:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
        !           265:  *                       valueCaps                      - ValueCaps Array
        !           266:  *                       piValueCapsLength        - Maximum Entries
        !           267:  *                       ptPreparsedData               - Pre-Parsed Data
        !           268:  *      Output:
        !           269:  *                       piValueCapsLength        - Entries Populated
        !           270:  *      Returns:
        !           271:  *
        !           272:  *------------------------------------------------------------------------------
        !           273: */
        !           274: OSStatus HIDGetValueCaps(HIDReportType reportType,
        !           275:                                                           HIDValueCapsPtr valueCaps,
        !           276:                                                           UInt32 *piValueCapsLength,
        !           277:                                                           HIDPreparsedDataRef preparsedDataRef)
        !           278: {
        !           279:        return HIDGetSpecificValueCaps(reportType,0,0,0,valueCaps,
        !           280:                                                                         piValueCapsLength,preparsedDataRef);
        !           281: }

unix.superglobalmegacorp.com

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