Annotation of XNU/iokit/IOKit/usb/USB.h, 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: #ifndef _USB_H
        !            23: #define _USB_H
        !            24: 
        !            25: #include <IOKit/IOTypes.h>
        !            26: 
        !            27: #if !defined(__USB__)
        !            28: #    include <IOKit/usb/USBSpec.h>
        !            29: #endif
        !            30: 
        !            31: #ifdef __cplusplus
        !            32: extern "C" {
        !            33: #endif
        !            34: 
        !            35: #define EndianSwap16(data16)                            \
        !            36: (                                                       \
        !            37:         ((((UInt16) data16) >> 8) & 0x00FF)     |       \
        !            38:         ((((UInt16) data16) << 8) & 0xFF00)             \
        !            39: )
        !            40: #define USBToHostWord EndianSwap16
        !            41: #define HostToUSBWord EndianSwap16
        !            42: 
        !            43: /*!
        !            44:     @typedef USBWord
        !            45:     A 16 bit value in little-endian format, best accessed using
        !            46:     the OSRead/WriteLittleInt16 functions
        !            47:     @field loByte least significant byte
        !            48:     @field hiByte most significant byte
        !            49: */
        !            50: typedef struct USBWord {
        !            51:     UInt8 loByte;
        !            52:     UInt8 hiByte;
        !            53: } USBWord;
        !            54: 
        !            55: enum {
        !            56:     kUSBDeviceIDShift = 7,
        !            57:     kUSBMaxDevices = 128,
        !            58:     kUSBMaxDevice = kUSBMaxDevices-1,
        !            59:     kUSBDeviceIDMask = 0x7f,
        !            60: 
        !            61:     kUSBPipeIDMask = 0xf,
        !            62:     kUSBMaxPipes = 32, // In and Out pipes can have same pipe number.
        !            63: 
        !            64:     kUSBInterfaceIDShift = 8,
        !            65:     kUSBMaxInterfaces = 1 << kUSBInterfaceIDShift,
        !            66:     kUSBInterfaceIDMask = kUSBMaxInterfaces-1,
        !            67: 
        !            68:     kUSBEndPtShift = 7,
        !            69:     kUSBDeviceMask = ((1 << kUSBEndPtShift) -1),
        !            70: 
        !            71:     kUSBNoPipeIdx = -1,
        !            72: };
        !            73: 
        !            74: enum {
        !            75:     kUSBRqDirnShift = 7,
        !            76:     kUSBRqDirnMask = 1,
        !            77: 
        !            78:     kUSBRqTypeShift = 5,
        !            79:     kUSBRqTypeMask = 3,
        !            80: 
        !            81:     kUSBRqRecipientMask = 0X1F
        !            82: };
        !            83: 
        !            84: enum {
        !            85:     kUSBHighSpeed = 0,
        !            86:     kUSBLowSpeed = 1
        !            87: };
        !            88: 
        !            89: enum {
        !            90:     kUSBMaxIsocFrameReqCount = 1023 // max size (bytes) of any one Isoc frame
        !            91: };
        !            92: 
        !            93: #define EncodeRequest(request, direction, type, recipient)             \
        !            94:     (((UInt16)request << 8) +                                          \
        !            95:               ((UInt16)recipient +                                     \
        !            96:                         ((UInt16)type << kUSBRqTypeShift) +            \
        !            97:                         ((UInt16)direction << kUSBRqDirnShift)))
        !            98: 
        !            99: 
        !           100: enum {
        !           101: /*
        !           102: Standard Requests
        !           103: 
        !           104: bmRequestType bRequest      wValue  wIndex    wLength Data
        !           105: 00000000B CLEAR_FEATURE     Feature Zero       Zero   None (device)
        !           106: 00000001B                   Feature Interface  Zero   None (Interface)
        !           107: 00000010B                   Feature Endpoint   Zero   None (Endpoint)
        !           108: 
        !           109: 10000000B GET_CONFIGURATION Zero    Zero       One    Configuration
        !           110: 10000000B GET_DESCRIPTOR    Type    LangID     Length Descriptor
        !           111: 10000001B GET_INTERFACE     Zero    Interface  One    Alternate
        !           112: 
        !           113: 10000000B GET_STATUS        Zero    Zero       Two    status (device)
        !           114: 10000001B                   Zero    Interface  Two    status (Interface)
        !           115: 10000010B                   Zero    Endpoint   Two    status (Endpoint)
        !           116: 
        !           117: 00000000B SET_ADDRESS       Address Zero       Zero   None
        !           118: 00000000B SET_CONFIGURATION Configuration Zero Zero   None
        !           119: 00000000B SET_DESCRIPTOR    Type   LangID      Length Descriptor
        !           120: 
        !           121: 00000000B SET_FEATURE       Feature Zero       Zero   None (device)
        !           122: 00000001B                   Feature Interface  Zero   None (Interface)
        !           123: 00000010B                   Feature Endpoint   Zero   None (Endpoint)
        !           124: 
        !           125: 00000001B SET_INTERFACE   Alternate Interface  Zero   None
        !           126: 10000010B SYNCH_FRAME       Zero    Endpoint   Two    Frame Number
        !           127: */
        !           128: kClearDeviceFeature
        !           129:     = EncodeRequest(kUSBRqClearFeature,  kUSBOut, kUSBStandard, kUSBDevice),
        !           130: kClearInterfaceFeature
        !           131:     = EncodeRequest(kUSBRqClearFeature,  kUSBOut, kUSBStandard, kUSBInterface),
        !           132: kClearEndpointFeature
        !           133:     = EncodeRequest(kUSBRqClearFeature,  kUSBOut, kUSBStandard, kUSBEndpoint),
        !           134: kGetConfiguration
        !           135:     = EncodeRequest(kUSBRqGetConfig,     kUSBIn,  kUSBStandard, kUSBDevice),
        !           136: kGetDescriptor
        !           137:     = EncodeRequest(kUSBRqGetDescriptor, kUSBIn,  kUSBStandard, kUSBDevice),
        !           138: kGetInterface
        !           139:     = EncodeRequest(kUSBRqGetInterface,  kUSBIn,  kUSBStandard, kUSBInterface),
        !           140: kGetDeviceStatus
        !           141:     = EncodeRequest(kUSBRqGetStatus,     kUSBIn,  kUSBStandard, kUSBDevice),
        !           142: kGetInterfaceStatus
        !           143:     = EncodeRequest(kUSBRqGetStatus,     kUSBIn,  kUSBStandard, kUSBInterface),
        !           144: kGetEndpointStatus
        !           145:     = EncodeRequest(kUSBRqGetStatus,     kUSBIn,  kUSBStandard, kUSBEndpoint),
        !           146: kSetAddress
        !           147:     = EncodeRequest(kUSBRqSetAddress,    kUSBOut, kUSBStandard, kUSBDevice),
        !           148: kSetConfiguration
        !           149:     = EncodeRequest(kUSBRqSetConfig,     kUSBOut, kUSBStandard, kUSBDevice),
        !           150: kSetDescriptor
        !           151:     = EncodeRequest(kUSBRqSetDescriptor, kUSBOut, kUSBStandard, kUSBDevice),
        !           152: kSetDeviceFeature
        !           153:     = EncodeRequest(kUSBRqSetFeature,    kUSBOut, kUSBStandard, kUSBDevice),
        !           154: kSetInterfaceFeature
        !           155:     = EncodeRequest(kUSBRqSetFeature,    kUSBOut, kUSBStandard, kUSBInterface),
        !           156: kSetEndpointFeature
        !           157:     = EncodeRequest(kUSBRqSetFeature,    kUSBOut, kUSBStandard, kUSBEndpoint),
        !           158: kSetInterface
        !           159:     = EncodeRequest(kUSBRqSetInterface,  kUSBOut, kUSBStandard, kUSBInterface),
        !           160: kSyncFrame
        !           161:     = EncodeRequest(kUSBRqSyncFrame,     kUSBIn,  kUSBStandard, kUSBEndpoint),
        !           162: 
        !           163: };
        !           164: 
        !           165: // TYPES
        !           166: 
        !           167: typedef struct IOUSBIsocFrame {
        !           168:     IOReturn                        frStatus;
        !           169:     UInt16                          frReqCount;
        !           170:     UInt16                          frActCount;
        !           171: } IOUSBIsocFrame;
        !           172: 
        !           173: typedef UInt16 USBDeviceAddress;
        !           174: 
        !           175: /*!
        !           176:     @typedef IOUSBCompletionAction
        !           177:     Function called when USB I/O completes
        !           178:     @param target The target specified in the IOUSBCompletion struct.
        !           179:     @param parameter The parameter specified in the IOUSBCompletion struct.
        !           180:     @param status Completion status
        !           181:     @param bufferSizeRemaining bytes left to be transferred
        !           182: */
        !           183: typedef void (*IOUSBCompletionAction)(
        !           184:                 void *                 target,
        !           185:                 void *                 parameter,
        !           186:                 IOReturn               status,
        !           187:                 UInt32                 bufferSizeRemaining);
        !           188: 
        !           189: typedef void (*IOUSBIsocCompletionAction)(
        !           190:                 void *                 target,
        !           191:                 void *                 parameter,
        !           192:                 IOReturn               status,
        !           193:                 IOUSBIsocFrame         *pFrames);
        !           194: 
        !           195: /*!
        !           196:     @typedef IOUSBCompletion
        !           197:     Struct spefifying action to perform when a USB I/O completes
        !           198:     @param target The target to pass to the action function.
        !           199:     @param action The function to call.
        !           200:     @param parameter The parameter to pass to the action function.
        !           201:     @param bufferSizeRemaining bytes left to be transferred
        !           202: */
        !           203: typedef struct IOUSBCompletion {
        !           204:     void *                     target;
        !           205:     IOUSBCompletionAction      action;
        !           206:     void *                     parameter;
        !           207: } IOUSBCompletion;
        !           208: 
        !           209: typedef struct IOUSBIsocCompletion {
        !           210:     void *                     target;
        !           211:     IOUSBIsocCompletionAction  action;
        !           212:     void *                     parameter;
        !           213: } IOUSBIsocCompletion;
        !           214: 
        !           215: /* ************* Constants ************* */
        !           216: 
        !           217: #define        iokit_usb_err(return) (sys_iokit|sub_iokit_usb|return)
        !           218: #define kIOUSBUnknownPipeErr   iokit_usb_err(97) /*  Pipe ref not recognised */
        !           219: #define kIOUSBTooManyPipesErr  iokit_usb_err(96) /*  Too many pipes */
        !           220: #define kIOUSBEndpointNotFound iokit_usb_err(87) /*  Not found */
        !           221: #define kIOUSBConfigNotFound   iokit_usb_err(86) /*  Not found */
        !           222: #define kIOUSBPipeStalled      iokit_usb_err(79) /*  Pipe has stalled, error needs to be cleared */
        !           223: #define kIOUSBInterfaceNotFound        iokit_usb_err(78) /*  Interface ref not recognised */
        !           224: 
        !           225: /* ************* types ************* */
        !           226: 
        !           227: struct IOUSBMouseData {
        !           228:     UInt16                             buttons;
        !           229:     SInt16                             XDelta;
        !           230:     SInt16                             YDelta;
        !           231: };
        !           232: typedef struct IOUSBMouseData          IOUSBMouseData;
        !           233: typedef IOUSBMouseData *               IOUSBMouseDataPtr;
        !           234: 
        !           235: struct IOUSBKeyboardData {
        !           236:     UInt16                             keycount;
        !           237:     UInt16                             usbkeycode[32];
        !           238: };
        !           239: typedef struct IOUSBKeyboardData       IOUSBKeyboardData;
        !           240: typedef IOUSBKeyboardData *            IOUSBKeyboardDataPtr;
        !           241: 
        !           242: union IOUSBHIDData {
        !           243:     IOUSBKeyboardData                  kbd;
        !           244:     IOUSBMouseData                     mouse;
        !           245: };
        !           246: typedef union IOUSBHIDData             IOUSBHIDData;
        !           247: typedef IOUSBHIDData *                 IOUSBHIDDataPtr;
        !           248: 
        !           249: struct IOUSBDeviceDescriptor {
        !           250:        UInt8                   length;
        !           251:        UInt8                   descType;
        !           252:        UInt16                  usbRel;
        !           253:        UInt8                   deviceClass;
        !           254:        UInt8                   deviceSubClass;
        !           255:        UInt8                   protocol;
        !           256:        UInt8                   maxPacketSize;
        !           257:        UInt16                  vendor;
        !           258:        UInt16                  product;
        !           259:        UInt16                  devRel;
        !           260:        UInt8                   manuIdx;
        !           261:        UInt8                   prodIdx;
        !           262:        UInt8                   serialIdx;
        !           263:        UInt8                   numConf;
        !           264: };
        !           265: typedef struct IOUSBDeviceDescriptor           IOUSBDeviceDescriptor;
        !           266: typedef IOUSBDeviceDescriptor *                        IOUSBDeviceDescriptorPtr;
        !           267: 
        !           268: struct IOUSBDescriptorHeader {
        !           269:        UInt8                   length;
        !           270:        UInt8                   descriptorType;
        !           271: };
        !           272: typedef struct IOUSBDescriptorHeader           IOUSBDescriptorHeader;
        !           273: typedef IOUSBDescriptorHeader *                        IOUSBDescriptorHeaderPtr;
        !           274: 
        !           275: struct IOUSBConfigurationDescriptor {
        !           276:        UInt8                   length;
        !           277:        UInt8                   descriptorType;
        !           278:        UInt16                  totalLength;
        !           279:        UInt8                   numInterfaces;
        !           280:        UInt8                   configValue;
        !           281:        UInt8                   configStrIndex;
        !           282:        UInt8                   attributes;
        !           283:        UInt8                   maxPower;
        !           284: };
        !           285: typedef struct IOUSBConfigurationDescriptor    IOUSBConfigurationDescriptor;
        !           286: typedef IOUSBConfigurationDescriptor *         IOUSBConfigurationDescriptorPtr;
        !           287: 
        !           288: struct IOUSBInterfaceDescriptor {
        !           289:        UInt8                   length;
        !           290:        UInt8                   descriptorType;
        !           291:        UInt8                   interfaceNumber;
        !           292:        UInt8                   alternateSetting;
        !           293:        UInt8                   numEndpoints;
        !           294:        UInt8                   interfaceClass;
        !           295:        UInt8                   interfaceSubClass;
        !           296:        UInt8                   interfaceProtocol;
        !           297:        UInt8                   interfaceStrIndex;
        !           298: };
        !           299: typedef struct IOUSBInterfaceDescriptor        IOUSBInterfaceDescriptor;
        !           300: typedef IOUSBInterfaceDescriptor *     IOUSBInterfaceDescriptorPtr;
        !           301: 
        !           302: struct IOUSBEndpointDescriptor {
        !           303:        UInt8                   length;
        !           304:        UInt8                   descriptorType;
        !           305:        UInt8                   endpointAddress;
        !           306:        UInt8                   attributes;
        !           307:        /* Split up maxPacketSize to avoid packing & alignment problems */
        !           308:        UInt8                   maxPacketSizeLo;        
        !           309:         UInt8                  maxPacketSizeHi;
        !           310:        UInt8                   interval;
        !           311: };
        !           312: typedef struct IOUSBEndpointDescriptor IOUSBEndpointDescriptor;
        !           313: typedef IOUSBEndpointDescriptor *      IOUSBEndpointDescriptorPtr;
        !           314: 
        !           315: struct IOUSBHIDDescriptor {
        !           316:        UInt8                   descLen;
        !           317:        UInt8                   descType;
        !           318:        UInt16                  descVersNum;
        !           319:        UInt8                   hidCountryCode;
        !           320:        UInt8                   hidNumDescriptors;
        !           321:        UInt8                   hidDescriptorType;
        !           322:         /* can't make this a single 16bit value or the compiler will add a filler byte*/
        !           323:        UInt8                   hidDescriptorLengthLo;
        !           324:        UInt8                   hidDescriptorLengthHi;
        !           325: };
        !           326: typedef struct IOUSBHIDDescriptor      IOUSBHIDDescriptor;
        !           327: typedef IOUSBHIDDescriptor *IOUSBHIDDescriptorPtr;
        !           328: 
        !           329: struct IOUSBHIDReportDesc {
        !           330:        UInt8                   hidDescriptorType;
        !           331:        /* can't make this a single 16bit value or the compiler will add a filler byte*/
        !           332:        UInt8                   hidDescriptorLengthLo;  
        !           333:        UInt8                   hidDescriptorLengthHi;
        !           334: };
        !           335: typedef struct IOUSBHIDReportDesc      IOUSBHIDReportDesc;
        !           336: typedef IOUSBHIDReportDesc *           IOUSBHIDReportDescPtr;
        !           337: 
        !           338: typedef UInt16                         USBStatus;
        !           339: typedef USBStatus *                    USBStatusPtr;
        !           340: 
        !           341: enum {
        !           342:     kIOUSBAnyClass     = 0xFFFF,
        !           343:     kIOUSBAnySubClass  = 0xFFFF,
        !           344:     kIOUSBAnyProtocol  = 0xFFFF,
        !           345:     kIOUSBAnyVendor    = 0xFFFF,
        !           346:     kIOUSBAnyProduct   = 0xFFFF
        !           347: };
        !           348: typedef struct IOUSBMatch {
        !           349:     UInt16     usbClass;
        !           350:     UInt16     usbSubClass;
        !           351:     UInt16     usbProtocol;
        !           352:     UInt16     usbVendor;
        !           353:     UInt16     usbProduct;
        !           354: } IOUSBMatch;
        !           355: 
        !           356: /*!
        !           357:     @typedef IOUSBFindEndpointRequest
        !           358:     Struct used to find endpoints of an interface
        !           359:     type and direction are used to match endpoints,
        !           360:     type, direction, maxPacketSize and interval are updated
        !           361:     with the properties of the found endpoint.
        !           362:     @field type Type of endpoint: kUSBControl, kUSBIsoc, kUSBBulk, kUSBInterrupt, kUSBAnyType
        !           363:     @field direction Direction of endpoint: kUSBOut, kUSBIn, kUSBAnyDirn
        !           364:     @field maxPacketSize maximum packet size of endpoint.
        !           365:     @field interval Polling interval in mSec for endpoint.
        !           366: */
        !           367: typedef struct {
        !           368:        UInt8 type;             // kUSBAnyType = don't care
        !           369:        UInt8 direction;        // kUSBAnyDirn = don't care
        !           370:         UInt16 maxPacketSize;
        !           371:         UInt8 interval;
        !           372: } IOUSBFindEndpointRequest;
        !           373: 
        !           374: /*
        !           375:  * Stuff for IOUserClient
        !           376:  */
        !           377: enum {
        !           378:     // for IOServiceOpen
        !           379:     kIOUSBDeviceConnectType    = 10
        !           380: };
        !           381: 
        !           382: enum {
        !           383:     kUSBSetConfig = 0,
        !           384:     kUSBGetConfig,
        !           385:     kUSBGetConfigDescriptor,
        !           386:     kUSBControlReqOut,
        !           387:     kUSBControlReqIn,
        !           388:     kUSBOpenPipe,
        !           389:     kUSBClosePipe,
        !           390:     kUSBReadPipe,
        !           391:     kUSBWritePipe,
        !           392:     kUSBGetPipeStatus,
        !           393:     kUSBAbortPipe,
        !           394:     kUSBResetPipe,
        !           395:     kUSBSetPipeIdle,
        !           396:     kUSBSetPipeActive,
        !           397:     kUSBClearPipeStall,
        !           398:     kUSBReadPipeOOL,
        !           399:     kUSBWritePipeOOL,
        !           400:     kUSBControlReqOutOOL,
        !           401:     kUSBControlReqInOOL,
        !           402:     kUSBResetDevice,
        !           403:     kNumUSBMethods
        !           404: };
        !           405: 
        !           406: // use a structure because there's a limit of 6 total arguments
        !           407: // to a user client method.
        !           408: typedef struct devReqOOL {
        !           409:     void *buf;
        !           410:     UInt32 pipe;
        !           411:     UInt32 sizeIn;
        !           412:     UInt16 wValue;
        !           413:     UInt16 wIndex;
        !           414:     UInt8 bmreqtype;
        !           415:     UInt8 request;
        !           416: } DevReqOOL;
        !           417: 
        !           418: #ifdef __cplusplus
        !           419: }       
        !           420: #endif
        !           421: 
        !           422: #endif /* _USB_H */

unix.superglobalmegacorp.com

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