Annotation of XNU/iokit/Families/IOHIDSystem/IOHIDDescriptorParser/HIDSetUsageValueArray.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:           HIDSetUsageValueArray.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:  * HIDSetUsageValueArray - Set the values for a usage
        !            59:  *
        !            60:  *      Input:
        !            61:  *                       reportType               - HIDP_Input, HIDP_Output, HIDP_Feature
        !            62:  *                       usagePage                        - Page Criteria
        !            63:  *                       iCollection                   - Collection Criteria or zero
        !            64:  *                       usage                            - usage Criteria
        !            65:  *                       psBuffer                              - Pointer to usage Buffer
        !            66:  *                       iByteLength                   - Length of usage Buffer
        !            67:  *                       ptPreparsedData               - Pre-Parsed Data
        !            68:  *                       psReport                              - An HID Report
        !            69:  *                       iReportLength                 - The length of the Report
        !            70:  *      Output:
        !            71:  *                       piValue                               - Pointer to usage Value
        !            72:  *      Returns:
        !            73:  *
        !            74:  *------------------------------------------------------------------------------
        !            75: */
        !            76: OSStatus HIDSetUsageValueArray(HIDReportType reportType,
        !            77:                                                                        HIDUsage usagePage,
        !            78:                                                                        UInt32 iCollection,
        !            79:                                                                        HIDUsage usage,
        !            80:                                                                        UInt8 *psUsageBuffer,
        !            81:                                                                        UInt32 iByteLength,
        !            82:                                                                        HIDPreparsedDataRef preparsedDataRef,
        !            83:                                                                        void *psReport,
        !            84:                                                                        UInt32 iReportLength)
        !            85: {
        !            86:        HIDPreparsedDataPtr ptPreparsedData = (HIDPreparsedDataPtr) preparsedDataRef;
        !            87:        HIDCollection *ptCollection;
        !            88:        HIDReportItem *ptReportItem;
        !            89:        OSStatus iStatus;
        !            90:        int i;
        !            91:        int iR;
        !            92:        long iValue;
        !            93:        int iStart;
        !            94:        int iReportItem;
        !            95:        UInt32 iUsageIndex;
        !            96:        UInt32 iCount;
        !            97:        int byteCount;
        !            98:        Boolean bIncompatibleReport = false;
        !            99: /*
        !           100:  *     Disallow Null Pointers
        !           101: */
        !           102:        if ((ptPreparsedData == NULL)
        !           103:         || (psUsageBuffer == NULL)
        !           104:         || (psReport == NULL))
        !           105:                return kHIDNullPointerErr;
        !           106:        if (ptPreparsedData->hidTypeIfValid != kHIDOSType)
        !           107:                return kHIDInvalidPreparsedDataErr;
        !           108: /*
        !           109:  *     The Collection must be in range
        !           110: */
        !           111:        if ((iCollection < 0) || (iCollection >= ptPreparsedData->collectionCount))
        !           112:                return kHIDBadParameterErr;
        !           113: /*
        !           114:  *     Search only the scope of the Collection specified
        !           115:  *     Go through the ReportItems
        !           116:  *     Filter on ReportType and usagePage
        !           117: */
        !           118:        ptCollection = &ptPreparsedData->collections[iCollection];
        !           119:        for (iR=0; iR<ptCollection->reportItemCount; iR++)
        !           120:        {
        !           121:                iReportItem = ptCollection->firstReportItem + iR;
        !           122:                ptReportItem = &ptPreparsedData->reportItems[iReportItem];
        !           123:                if (HIDIsVariable(ptReportItem, preparsedDataRef)
        !           124:                 && HIDHasUsage(preparsedDataRef,ptReportItem,usagePage,usage,&iUsageIndex,&iCount))
        !           125:                {
        !           126: /*
        !           127:  *                     This may be the proper place
        !           128:  *                     Let's check for the proper Report ID, Type, and Length
        !           129: */
        !           130:                        iStatus = HIDCheckReport(reportType,preparsedDataRef,ptReportItem,
        !           131:                                                                           psReport,iReportLength);
        !           132: /*
        !           133:  *                     The Report ID or Type may not match.
        !           134:  *                     This may not be an error (yet)
        !           135: */
        !           136:                        if (iStatus == kHIDIncompatibleReportErr)
        !           137:                                bIncompatibleReport = true;
        !           138:                        else if (iStatus != kHIDSuccess)
        !           139:                                return iStatus;
        !           140:                        else
        !           141:                        {
        !           142: /*
        !           143:  *                             Disallow single count variables
        !           144:  *                             Count is set by HasUsage
        !           145: */
        !           146:                                if (iCount <= 1)
        !           147:                                        return kHIDNotValueArrayErr;
        !           148: /*
        !           149:  *                             Write out the data
        !           150: */
        !           151:                                iStart = ptReportItem->startBit + (ptReportItem->globals.reportSize * iUsageIndex);
        !           152:                                byteCount = (ptReportItem->globals.reportSize * iCount + 7)/8;
        !           153:                                if (byteCount > iByteLength)
        !           154:                                        byteCount = iByteLength;
        !           155:                                for (i=0; i<byteCount; i++)
        !           156:                                {
        !           157:                                        iValue = *psUsageBuffer++;
        !           158:                                        iStatus = HIDPreProcessRIValue (ptReportItem, &iValue);
        !           159:                                        iStatus = HIDPutData(psReport, iReportLength, iStart, 8, iValue);
        !           160:                                        if (iStatus != kHIDSuccess)
        !           161:                                                return iStatus;
        !           162:                                        iStart += 8;
        !           163:                                }
        !           164:                                return kHIDSuccess;
        !           165:                        }
        !           166:                }
        !           167:        }
        !           168:        if (bIncompatibleReport)
        !           169:                return kHIDIncompatibleReportErr;
        !           170:        return kHIDUsageNotFoundErr;
        !           171: }

unix.superglobalmegacorp.com

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