|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /*
26: File: USB.h
27:
28: Contains: Public API for USB Services Library (and associated components)
29:
30: Version:
31:
32: DRI: Craig Keithley
33:
34: Copyright: � 1998 by Apple Computer, Inc., all rights reserved.
35:
36: Warning: *** APPLE INTERNAL USE ONLY ***
37: This file may contain unreleased API's
38:
39: BuildInfo: Built by: Naga Pappireddi
40: With Interfacer: 3.0d9 (PowerPC native)
41: From: USB.i
42: Revision: 71
43: Dated: 10/29/98
44: Last change by: TC
45: Last comment: [2280793] Add constant kUSBDeviceDescriptorLength.
46:
47: Bugs: Report bugs to Radar component "System Interfaces", "Latest"
48: List the version information (from above) in the Problem Description.
49:
50: */
51: #ifndef __USB__
52: #define __USB__
53:
54: #ifndef __MACTYPES__
55: #include "mactypes.h"
56: #endif
57: #ifndef __NAMEREGISTRY__
58: //#include <NameRegistry.h>
59: #endif
60: #ifndef __CODEFRAGMENTS__
61: //#include <CodeFragments.h>
62: #endif
63: #ifndef __DEVICES__
64: //#include <Devices.h>
65: #endif
66:
67:
68:
69: #if PRAGMA_ONCE
70: #pragma once
71: #endif
72:
73: #ifdef __cplusplus
74: extern "C" {
75: #endif
76:
77: #if PRAGMA_IMPORT
78: #pragma import on
79: #endif
80:
81: #if PRAGMA_STRUCT_ALIGN
82: #pragma options align=mac68k
83: #elif PRAGMA_STRUCT_PACKPUSH
84: #pragma pack(push, 2)
85: #elif PRAGMA_STRUCT_PACK
86: #pragma pack(2)
87: #endif
88:
89: /* ************* Constants ************* */
90:
91: enum {
92: kUSBNoErr = 0,
93: kUSBNoTran = 0,
94: kUSBNoDelay = 0,
95: kUSBPending = 1, /* */
96: /* USB assigned error numbers in range -6900 .. -6999 */
97: kUSBBaseError = -7000, /* */
98: /* USB Services Errors */
99: kUSBInternalErr = -6999, /* Internal error */
100: kUSBUnknownDeviceErr = -6998, /* device ref not recognised */
101: kUSBUnknownPipeErr = -6997, /* Pipe ref not recognised */
102: kUSBTooManyPipesErr = -6996, /* Too many pipes */
103: kUSBIncorrectTypeErr = -6995, /* Incorrect type */
104: kUSBRqErr = -6994, /* Request error */
105: kUSBUnknownRequestErr = -6993, /* Unknown request */
106: kUSBTooManyTransactionsErr = -6992, /* Too many transactions */
107: kUSBAlreadyOpenErr = -6991, /* Already open */
108: kUSBNoDeviceErr = -6990, /* No device */
109: kUSBDeviceErr = -6989, /* Device error */
110: kUSBOutOfMemoryErr = -6988, /* Out of memory */
111: kUSBNotFound = -6987, /* Not found */
112: kUSBPBVersionError = -6986, /* Wrong pbVersion */
113: kUSBPBLengthError = -6985, /* pbLength too small */
114: kUSBCompletionError = -6984, /* no completion routine specified */
115: kUSBFlagsError = -6983, /* Unused flags not zeroed */
116: kUSBAbortedError = -6982, /* Pipe aborted */
117: kUSBNoBandwidthError = -6981, /* Not enough bandwidth available */
118: kUSBPipeIdleError = -6980, /* Pipe is Idle, it will not accept transactions */
119: kUSBPipeStalledError = -6979, /* Pipe has stalled, error needs to be cleared */
120: kUSBUnknownInterfaceErr = -6978, /* Interface ref not recognised */
121: kUSBDeviceBusy = -6977, /* Device is already being configured */
122: kUSBDevicePowerProblem = -6976, /* Device has a power problem */
123: /* */
124: /* USB Manager Errors */
125: kUSBBadDispatchTable = -6950, /* Improper driver dispatch table */
126: kUSBUnknownNotification = -6949, /* Notification type not defined */
127: kUSBQueueFull = -6948, /* Internal queue maxxed */
128: /* */
129: /* Hardware Errors */
130: /* Note pipe stalls are communication */
131: /* errors. The affected pipe can not */
132: /* be used until USBClearPipeStallByReference */
133: /* is used */
134: /* kUSBEndpointStallErr is returned in */
135: /* response to a stall handshake */
136: /* from a device. The device has to be */
137: /* cleared before a USBClearPipeStallByReference */
138: /* can be used */
139: kUSBLinkErr = -6916,
140: kUSBCRCErr = -6915, /* Pipe stall, bad CRC */
141: kUSBBitstufErr = -6914, /* Pipe stall, bitstuffing */
142: kUSBDataToggleErr = -6913, /* Pipe stall, Bad data toggle */
143: kUSBEndpointStallErr = -6912, /* Device didn't understand */
144: kUSBNotRespondingErr = -6911, /* Pipe stall, No device, device hung */
145: kUSBPIDCheckErr = -6910, /* Pipe stall, PID CRC error */
146: kUSBWrongPIDErr = -6909, /* Pipe stall, Bad or wrong PID */
147: kUSBOverRunErr = -6908, /* Packet too large or more data than buffer */
148: kUSBUnderRunErr = -6907, /* Less data than buffer */
149: kUSBRes1Err = -6906,
150: kUSBRes2Err = -6905,
151: kUSBBufOvrRunErr = -6904, /* Host hardware failure on data in, PCI busy? */
152: kUSBBufUnderRunErr = -6903, /* Host hardware failure on data out, PCI busy? */
153: kUSBNotSent1Err = -6902, /* Transaction not sent */
154: kUSBNotSent2Err = -6901 /* Transaction not sent */
155: };
156:
157:
158: enum {
159: /* Flags */
160: kUSBTaskTimeFlag = 1,
161: kUSBHubPower = 2,
162: kUSBPowerReset = 4,
163: kUSBHubReaddress = 8,
164: kUSBAddressRequest = 16
165: };
166:
167:
168: enum {
169: /* Hub messages */
170: kUSBHubPortResetRequest = 1
171: };
172:
173: /* ************* types ************* */
174:
175: typedef SInt32 USBReference;
176: typedef USBReference USBDeviceRef;
177: typedef USBReference USBInterfaceRef;
178: typedef USBReference USBPipeRef;
179: typedef USBReference USBBusRef;
180: typedef UInt32 USBPipeState;
181: typedef UInt32 USBCount;
182: typedef UInt32 USBFlags;
183: typedef UInt8 USBRequest;
184: typedef UInt8 USBDirection;
185: typedef UInt8 USBRqRecipient;
186: typedef UInt8 USBRqType;
187: typedef UInt16 USBRqIndex;
188: typedef UInt16 USBRqValue;
189:
190:
191:
192: struct usbControlBits {
193: UInt8 BMRequestType;
194: UInt8 BRequest;
195: USBRqValue WValue;
196: USBRqIndex WIndex;
197: UInt16 reserved4;
198: };
199: typedef struct usbControlBits usbControlBits;
200:
201: struct USBIsocFrame {
202: OSStatus frStatus;
203: UInt16 frReqCount;
204: UInt16 frActCount;
205: };
206: typedef struct USBIsocFrame USBIsocFrame;
207:
208: struct usbIsocBits {
209: USBIsocFrame * FrameList;
210: UInt32 NumFrames;
211: };
212: typedef struct usbIsocBits usbIsocBits;
213:
214: struct usbHubBits {
215: UInt32 Request;
216: UInt32 Spare;
217: };
218: typedef struct usbHubBits usbHubBits;
219: typedef struct USBPB USBPB;
220: typedef CALLBACK_API_C( void , USBCompletion )(USBPB *pb);
221:
222: struct USBPB {
223:
224: void * qlink;
225: UInt16 qType;
226: UInt16 pbLength;
227: UInt16 pbVersion;
228: UInt16 reserved1;
229: UInt32 reserved2;
230:
231: OSStatus usbStatus;
232: USBCompletion usbCompletion;
233: UInt32 usbRefcon;
234:
235: USBReference usbReference;
236:
237: void * usbBuffer;
238: USBCount usbReqCount;
239: USBCount usbActCount;
240:
241: USBFlags usbFlags;
242:
243: union{
244:
245: usbControlBits cntl;
246:
247:
248: usbIsocBits isoc;
249:
250: usbHubBits hub;
251:
252: }usb;
253:
254: UInt32 usbFrame;
255:
256: UInt8 usbClassType;
257: UInt8 usbSubclass;
258: UInt8 usbProtocol;
259: UInt8 usbOther;
260:
261: UInt32 reserved6;
262: UInt16 reserved7;
263: UInt16 reserved8;
264:
265: };
266:
267: #if !defined(OLDUSBNAMES)
268: #define OLDUSBNAMES 0
269: #endif
270:
271: //naga#if OLDUSBNAMES
272: #define usbBMRequestType usb.cntl.BMRequestType
273: #define usbBRequest usb.cntl.BRequest
274: #define usbWValue usb.cntl.WValue
275: #define usbWIndex usb.cntl.WIndex
276: //naga#endif
277: //naga
278: typedef int CFragConnectionID;
279:
280:
281: struct uslReq {
282: USBDirection usbDirection;
283: USBRqType usbType;
284: USBRqRecipient usbRecipient;
285: USBRequest usbRequest;
286: };
287: typedef struct uslReq uslReq;
288:
289:
290: enum {
291: /* BT 19Aug98, bump up to v1.10 for Isoc*/
292: kUSBCurrentPBVersion = 0x0100, /* v1.00*/
293: kUSBIsocPBVersion = 0x0109, /* v1.10*/
294: kUSBCurrentHubPB = kUSBIsocPBVersion
295: };
296:
297:
298:
299:
300: #define kUSBNoCallBack ((void *)-1L)
301:
302:
303: typedef UInt8 bcdUSB;
304:
305: enum {
306: kUSBControl = 0,
307: kUSBIsoc = 1,
308: kUSBBulk = 2,
309: kUSBInterrupt = 3,
310: kUSBAnyType = 0xFF
311: };
312:
313: /* endpoint type */
314:
315: enum {
316: kUSBOut = 0,
317: kUSBIn = 1,
318: kUSBNone = 2,
319: kUSBAnyDirn = 3
320: };
321:
322: /*USBDirection*/
323:
324: enum {
325: kUSBStandard = 0,
326: kUSBClass = 1,
327: kUSBVendor = 2
328: };
329:
330: /*USBRqType*/
331:
332: enum {
333: kUSBDevice = 0,
334: kUSBInterface = 1,
335: kUSBEndpoint = 2,
336: kUSBOther = 3
337: };
338:
339: /*USBRqRecipient*/
340:
341: enum {
342: kUSBRqGetStatus = 0,
343: kUSBRqClearFeature = 1,
344: kUSBRqReserved1 = 2,
345: kUSBRqSetFeature = 3,
346: kUSBRqReserved2 = 4,
347: kUSBRqSetAddress = 5,
348: kUSBRqGetDescriptor = 6,
349: kUSBRqSetDescriptor = 7,
350: kUSBRqGetConfig = 8,
351: kUSBRqSetConfig = 9,
352: kUSBRqGetInterface = 10,
353: kUSBRqSetInterface = 11,
354: kUSBRqSyncFrame = 12
355: };
356:
357: /*USBRequest*/
358:
359:
360: enum {
361: kUSBDeviceDesc = 1,
362: kUSBConfDesc = 2,
363: kUSBStringDesc = 3,
364: kUSBInterfaceDesc = 4,
365: kUSBEndpointDesc = 5,
366: kUSBHIDDesc = 0x21,
367: kUSBReportDesc = 0x22,
368: kUSBPhysicalDesc = 0x23,
369: kUSBHUBDesc = 0x29
370: };
371:
372: /* descriptorType */
373:
374: enum {
375: kUSBActive = 0, /* Pipe can accept new transactions*/
376: kUSBIdle = 1, /* Pipe will not accept new transactions*/
377: kUSBStalled = 2 /* An error occured on the pipe*/
378: };
379:
380:
381: enum {
382: kUSB100mAAvailable = 50,
383: kUSB500mAAvailable = 250,
384: kUSB100mA = 50,
385: kUSBAtrBusPowered = 0x80,
386: kUSBAtrSelfPowered = 0x40,
387: kUSBAtrRemoteWakeup = 0x20
388: };
389:
390:
391: enum {
392: kUSBRel10 = 0x0100
393: };
394:
395: #define USB_CONSTANT16(x) ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8))
396:
397: enum {
398: kUSBDeviceDescriptorLength = 0x12
399: };
400:
401:
402: struct USBDeviceDescriptor {
403: UInt8 length;
404: UInt8 descType;
405: UInt16 usbRel;
406: UInt8 deviceClass;
407: UInt8 deviceSubClass;
408: UInt8 protocol;
409: UInt8 maxPacketSize;
410: UInt16 vendor;
411: UInt16 product;
412: UInt16 devRel;
413: UInt8 manuIdx;
414: UInt8 prodIdx;
415: UInt8 serialIdx;
416: UInt8 numConf;
417: UInt16 descEnd; /* was "end", but this is reserved in some languages*/
418: };
419: typedef struct USBDeviceDescriptor USBDeviceDescriptor;
420: #ifndef OLDCLASSNAMES
421: #ifndef __cplusplus
422: #define class deviceClass
423: #define subClass deviceSubClass
424: #endif
425: #endif
426: typedef USBDeviceDescriptor * USBDeviceDescriptorPtr;
427:
428: struct USBDescriptorHeader {
429: UInt8 length;
430: UInt8 descriptorType;
431: };
432: typedef struct USBDescriptorHeader USBDescriptorHeader;
433: typedef USBDescriptorHeader * USBDescriptorHeaderPtr;
434:
435: struct USBConfigurationDescriptor {
436: UInt8 length;
437: UInt8 descriptorType;
438: UInt16 totalLength;
439: UInt8 numInterfaces;
440: UInt8 configValue;
441: UInt8 configStrIndex;
442: UInt8 attributes;
443: UInt8 maxPower;
444: };
445: typedef struct USBConfigurationDescriptor USBConfigurationDescriptor;
446: typedef USBConfigurationDescriptor * USBConfigurationDescriptorPtr;
447:
448: struct USBInterfaceDescriptor {
449: UInt8 length;
450: UInt8 descriptorType;
451: UInt8 interfaceNumber;
452: UInt8 alternateSetting;
453: UInt8 numEndpoints;
454: UInt8 interfaceClass;
455: UInt8 interfaceSubClass;
456: UInt8 interfaceProtocol;
457: UInt8 interfaceStrIndex;
458: };
459: typedef struct USBInterfaceDescriptor USBInterfaceDescriptor;
460: typedef USBInterfaceDescriptor * USBInterfaceDescriptorPtr;
461:
462: struct USBEndPointDescriptor {
463: UInt8 length;
464: UInt8 descriptorType;
465: UInt8 endpointAddress;
466: UInt8 attributes;
467: UInt16 maxPacketSize;
468: UInt8 interval;
469: };
470: typedef struct USBEndPointDescriptor USBEndPointDescriptor;
471: typedef USBEndPointDescriptor * USBEndPointDescriptorPtr;
472:
473: struct USBHIDDescriptor {
474: UInt8 descLen;
475: UInt8 descType;
476: UInt16 descVersNum;
477: UInt8 hidCountryCode;
478: UInt8 hidNumDescriptors;
479: UInt8 hidDescriptorType;
480: UInt8 hidDescriptorLengthLo; /* can't make this a single 16bit value or the compiler will add a filler byte*/
481: UInt8 hidDescriptorLengthHi;
482: };
483: typedef struct USBHIDDescriptor USBHIDDescriptor;
484: typedef USBHIDDescriptor * USBHIDDescriptorPtr;
485:
486: struct USBHIDReportDesc {
487: UInt8 hidDescriptorType;
488: UInt8 hidDescriptorLengthLo; /* can't make this a single 16bit value or the compiler will add a filler byte*/
489: UInt8 hidDescriptorLengthHi;
490: };
491: typedef struct USBHIDReportDesc USBHIDReportDesc;
492: typedef USBHIDReportDesc * USBHIDReportDescPtr;
493:
494: struct USBHubPortStatus {
495: UInt16 portFlags; /* Port status flags */
496: UInt16 portChangeFlags; /* Port changed flags */
497: };
498: typedef struct USBHubPortStatus USBHubPortStatus;
499: typedef USBHubPortStatus * USBHubPortStatusPtr;
500: /* ********* ProtoTypes *************** */
501: /* For dealing with endianisms */
502: EXTERN_API_C( UInt16 )
503: HostToUSBWord (UInt16 value);
504:
505: EXTERN_API_C( UInt16 )
506: USBToHostWord (UInt16 value);
507:
508: EXTERN_API_C( UInt32 )
509: HostToUSBLong (UInt32 value);
510:
511: EXTERN_API_C( UInt32 )
512: USBToHostLong (UInt32 value);
513:
514: /* Main prototypes */
515: /* Transfer commands */
516: EXTERN_API_C( OSStatus )
517: USBDeviceRequest (USBPB * pb);
518:
519: EXTERN_API_C( OSStatus )
520: USBOpenPipe (USBPB * pb);
521:
522: EXTERN_API_C( OSStatus )
523: USBClosePipe (USBPB * pb);
524:
525: EXTERN_API_C( OSStatus )
526: USBBulkWrite (USBPB * pb);
527:
528: EXTERN_API_C( OSStatus )
529: USBBulkRead (USBPB * pb);
530:
531: EXTERN_API_C( OSStatus )
532: USBIntRead (USBPB * pb);
533:
534: EXTERN_API_C( OSStatus )
535: USBIsocRead (USBPB * pb);
536:
537: EXTERN_API_C( OSStatus )
538: USBIsocWrite (USBPB * pb);
539:
540: /* Pipe state control */
541: EXTERN_API_C( OSStatus )
542: USBClearPipeStallByReference (USBPipeRef ref);
543:
544: EXTERN_API_C( OSStatus )
545: USBAbortPipeByReference (USBReference ref);
546:
547: EXTERN_API_C( OSStatus )
548: USBResetPipeByReference (USBReference ref);
549:
550: EXTERN_API_C( OSStatus )
551: USBSetPipeIdleByReference (USBPipeRef ref);
552:
553: EXTERN_API_C( OSStatus )
554: USBSetPipeActiveByReference (USBPipeRef ref);
555:
556: EXTERN_API_C( OSStatus )
557: USBClosePipeByReference (USBPipeRef ref);
558:
559: EXTERN_API_C( OSStatus )
560: USBGetPipeStatusByReference (USBReference ref,
561: USBPipeState * state);
562:
563:
564: /* Configuration services */
565: EXTERN_API_C( OSStatus )
566: USBFindNextInterface (USBPB * pb);
567:
568: EXTERN_API_C( OSStatus )
569: USBOpenDevice (USBPB * pb);
570:
571: EXTERN_API_C( OSStatus )
572: USBNewInterfaceRef (USBPB * pb);
573:
574: EXTERN_API_C( OSStatus )
575: USBDisposeInterfaceRef (USBPB * pb);
576:
577: EXTERN_API_C( OSStatus )
578: USBConfigureInterface (USBPB * pb);
579:
580: EXTERN_API_C( OSStatus )
581: USBFindNextPipe (USBPB * pb);
582:
583:
584: /* Dealing with descriptors. */
585: /* Note most of this is temprorary */
586: EXTERN_API_C( OSStatus )
587: USBGetConfigurationDescriptor (USBPB * pb);
588:
589: EXTERN_API_C( OSStatus )
590: USBGetFullConfigurationDescriptor (USBPB * pb);
591:
592: EXTERN_API_C( OSStatus )
593: USBFindNextEndpointDescriptorImmediate (USBPB * pb);
594:
595: EXTERN_API_C( OSStatus )
596: USBFindNextInterfaceDescriptorImmediate (USBPB * pb);
597:
598: EXTERN_API_C( OSStatus )
599: USBFindNextAssociatedDescriptor (USBPB * pb);
600:
601:
602:
603: /* Utility functions */
604: EXTERN_API_C( OSStatus )
605: USBResetDevice (USBPB * pb);
606:
607: EXTERN_API_C( OSStatus )
608: USBGetFrameNumberImmediate (USBPB * pb);
609:
610: EXTERN_API_C( OSStatus )
611: USBDelay (USBPB * pb);
612:
613: EXTERN_API_C( OSStatus )
614: USBAllocMem (USBPB * pb);
615:
616: EXTERN_API_C( OSStatus )
617: USBDeallocMem (USBPB * pb);
618:
619: /* Expert interface functions */
620: EXTERN_API_C( OSStatus )
621: USBExpertInstallInterfaceDriver (USBDeviceRef ref,
622: USBDeviceDescriptorPtr desc,
623: USBInterfaceDescriptorPtr interfacePtr,
624: USBReference hubRef,
625: UInt32 busPowerAvailable);
626:
627: EXTERN_API_C( OSStatus )
628: USBExpertRemoveInterfaceDriver (USBDeviceRef ref);
629:
630: EXTERN_API_C( OSStatus )
631: USBExpertInstallDeviceDriver (USBDeviceRef ref,
632: USBDeviceDescriptorPtr desc,
633: USBReference hubRef,
634: UInt32 port,
635: UInt32 busPowerAvailable);
636:
637: EXTERN_API_C( OSStatus )
638: USBExpertRemoveDeviceDriver (USBDeviceRef ref);
639:
640: EXTERN_API_C( OSStatus )
641: USBExpertStatus (USBDeviceRef ref,
642: void * pointer,
643: UInt32 value);
644:
645: EXTERN_API_C( OSStatus )
646: USBExpertFatalError (USBDeviceRef ref,
647: OSStatus status,
648: void * pointer,
649: UInt32 value);
650:
651: EXTERN_API_C( OSStatus )
652: USBExpertNotify (void * note);
653:
654: EXTERN_API_C( OSStatus )
655: USBExpertSetDevicePowerStatus (USBDeviceRef ref,
656: UInt32 reserved1,
657: UInt32 reserved2,
658: UInt32 powerStatus,
659: UInt32 busPowerAvailable,
660: UInt32 busPowerNeeded);
661:
662:
663: enum {
664: kUSBDevicePower_PowerOK = 0,
665: kUSBDevicePower_BusPowerInsufficient = 1,
666: kUSBDevicePower_BusPowerNotAllFeatures = 2,
667: kUSBDevicePower_SelfPowerInsufficient = 3,
668: kUSBDevicePower_SelfPowerNotAllFeatures = 4,
669: kUSBDevicePower_HubPortOk = 5,
670: kUSBDevicePower_HubPortOverCurrent = 6,
671: kUSBDevicePower_BusPoweredHubOnLowPowerPort = 7,
672: kUSBDevicePower_BusPoweredHubToBusPoweredHub = 8,
673: kUSBDevicePower_Reserved3 = 9,
674: kUSBDevicePower_Reserved4 = 10
675: };
676:
677:
678: /* For hubs only */
679: EXTERN_API_C( OSStatus )
680: USBHubAddDevice (USBPB * pb);
681:
682: EXTERN_API_C( OSStatus )
683: USBHubConfigurePipeZero (USBPB * pb);
684:
685: EXTERN_API_C( OSStatus )
686: USBHubSetAddress (USBPB * pb);
687:
688: EXTERN_API_C( OSStatus )
689: USBHubDeviceRemoved (USBPB * pb);
690:
691:
692: EXTERN_API_C( UInt8 )
693: USBMakeBMRequestType (UInt8 direction,
694: UInt8 reqtype,
695: UInt8 recipient);
696:
697: /* This not implemented until someone shows me a test case */
698: /*OSStatus USBControlRequest(USBPB *pb);*/
699:
700: typedef UInt32 USBLocationID;
701:
702: enum {
703: kUSBLocationNibbleFormat = 0 /* Other values are reserved for future types (like when we have more than 16 ports per hub)*/
704: };
705:
706:
707:
708: enum {
709: kNoDeviceRef = -1
710: };
711:
712: /* Expert Notification Types*/
713: typedef UInt8 USBNotificationType;
714: typedef UInt8 USBDriverMessage;
715:
716: enum {
717: kNotifyAddDevice = 0x00,
718: kNotifyRemoveDevice = 0x01,
719: kNotifyAddInterface = 0x02,
720: kNotifyRemoveInterface = 0x03,
721: kNotifyGetDeviceDescriptor = 0x04,
722: kNotifyGetInterfaceDescriptor = 0x05,
723: kNotifyGetNextDeviceByClass = 0x06,
724: kNotifyGetDriverConnectionID = 0x07,
725: kNotifyInstallDeviceNotification = 0x08,
726: kNotifyRemoveDeviceNotification = 0x09,
727: kNotifyDeviceRefToBusRef = 0x0A,
728: kNotifyDriverNotify = 0x0C,
729: kNotifyParentNotify = 0x0D,
730: kNotifyAddDriverForReference = 0x0E,
731: kNotifyAnyEvent = 0xFF,
732: kNotifyPowerState = 0x17,
733: kNotifyStatus = 0x18,
734: kNotifyFatalError = 0x19
735: };
736:
737: /*
738: USB Manager wildcard constants for USBGetNextDeviceByClass
739: and USBInstallDeviceNotification.
740: */
741: typedef UInt16 USBManagerWildcard;
742:
743: enum {
744: kUSBAnyClass = 0xFFFF,
745: kUSBAnySubClass = 0xFFFF,
746: kUSBAnyProtocol = 0xFFFF,
747: kUSBAnyVendor = 0xFFFF,
748: kUSBAnyProduct = 0xFFFF
749: };
750:
751:
752:
753:
754: struct ExpertNotificationData {
755: USBNotificationType notification;
756: UInt8 filler[1]; /* unused due to 2-byte 68k alignment*/
757: USBDeviceRef * deviceRef;
758: UInt32 busPowerAvailable;
759: void * data;
760: UInt32 info1;
761: UInt32 info2;
762: };
763: typedef struct ExpertNotificationData ExpertNotificationData;
764: typedef ExpertNotificationData * ExpertNotificationDataPtr;
765: /* Definition of function pointer passed in ExpertEntryProc*/
766: typedef CALLBACK_API_C( OSStatus , ExpertNotificationProcPtr )(ExpertNotificationDataPtr pNotificationData);
767: /* Definition of expert's callback installation function*/
768: typedef CALLBACK_API_C( OSStatus , ExpertEntryProcPtr )(ExpertNotificationProcPtr pExpertNotify);
769: /* Device Notification Callback Routine*/
770: typedef CALLBACK_API_C( void , USBDeviceNotificationCallbackProcPtr )(void *pb);
771: /* Device Notification Parameter Block*/
772:
773: struct USBDeviceNotificationParameterBlock {
774: UInt16 pbLength;
775: UInt16 pbVersion;
776: USBNotificationType usbDeviceNotification;
777: UInt8 reserved1[1]; /* needed because of 2-byte 68k alignment*/
778: USBDeviceRef usbDeviceRef;
779: UInt16 usbClass;
780: UInt16 usbSubClass;
781: UInt16 usbProtocol;
782: UInt16 usbVendor;
783: UInt16 usbProduct;
784: OSStatus result;
785: UInt32 token;
786: USBDeviceNotificationCallbackProcPtr callback;
787: UInt32 refcon;
788: };
789: typedef struct USBDeviceNotificationParameterBlock USBDeviceNotificationParameterBlock;
790: /* Forward declaration*/
791: typedef USBDeviceNotificationParameterBlock * USBDeviceNotificationParameterBlockPtr;
792: /* Definition of USBDriverNotificationCallback Routine*/
793: typedef CALLBACK_API_C( void , USBDriverNotificationCallbackPtr )(OSStatus status, UInt32 refcon);
794: /* Public Functions*/
795: EXTERN_API_C( OSStatus )
796: USBGetNextDeviceByClass (USBDeviceRef * deviceRef,
797: CFragConnectionID * connID,
798: UInt16 theClass,
799: UInt16 theSubClass,
800: UInt16 theProtocol);
801:
802: EXTERN_API_C( OSStatus )
803: USBGetDeviceDescriptor (USBDeviceRef * deviceRef,
804: USBDeviceDescriptor * deviceDescriptor,
805: UInt32 size);
806:
807: EXTERN_API_C( OSStatus )
808: USBGetInterfaceDescriptor (USBInterfaceRef * interfaceRef,
809: USBInterfaceDescriptor * interfaceDescriptor,
810: UInt32 size);
811:
812: EXTERN_API_C( OSStatus )
813: USBGetDriverConnectionID (USBDeviceRef * deviceRef,
814: CFragConnectionID * connID);
815:
816: EXTERN_API_C( void )
817: USBInstallDeviceNotification (USBDeviceNotificationParameterBlock * pb);
818:
819: EXTERN_API_C( OSStatus )
820: USBRemoveDeviceNotification (UInt32 token);
821:
822: EXTERN_API_C( OSStatus )
823: USBDeviceRefToBusRef (USBDeviceRef * deviceRef,
824: USBBusRef * busRef);
825:
826: EXTERN_API_C( OSStatus )
827: USBDriverNotify (USBReference reference,
828: USBDriverMessage mesg,
829: UInt32 refcon,
830: USBDriverNotificationCallbackPtr callback);
831:
832: EXTERN_API_C( OSStatus )
833: USBExpertNotifyParent (USBReference reference,
834: void * pointer);
835:
836: EXTERN_API_C( OSStatus )
837: USBAddDriverForReference (USBReference reference);
838:
839: typedef CALLBACK_API_C( void , HIDInterruptProcPtr )(UInt32 refcon, void *theData);
840: /* HID Install Interrupt prototype*/
841: typedef CALLBACK_API_C( OSStatus , USBHIDInstallInterruptProcPtr )(HIDInterruptProcPtr pInterruptProc, UInt32 refcon);
842: /* HID Poll Device prototype*/
843: typedef CALLBACK_API_C( OSStatus , USBHIDPollDeviceProcPtr )(void );
844: /* HID Control Device prototype*/
845: typedef CALLBACK_API_C( OSStatus , USBHIDControlDeviceProcPtr )(UInt32 theControlSelector, void *theControlData);
846: /* HID Get Device Info prototype*/
847: typedef CALLBACK_API_C( OSStatus , USBHIDGetDeviceInfoProcPtr )(UInt32 theInfoSelector, void *theInfo);
848: /* HID Enter Polled Mode prototype*/
849: typedef CALLBACK_API_C( OSStatus , USBHIDEnterPolledModeProcPtr )(void );
850: /* HID Exit Polled Mode prototype*/
851: typedef CALLBACK_API_C( OSStatus , USBHIDExitPolledModeProcPtr )(void );
852:
853: struct USBHIDModuleDispatchTable {
854: UInt32 hidDispatchVersion;
855: USBHIDInstallInterruptProcPtr pUSBHIDInstallInterrupt;
856: USBHIDPollDeviceProcPtr pUSBHIDPollDevice;
857: USBHIDControlDeviceProcPtr pUSBHIDControlDevice;
858: USBHIDGetDeviceInfoProcPtr pUSBHIDGetDeviceInfo;
859: USBHIDEnterPolledModeProcPtr pUSBHIDEnterPolledMode;
860: USBHIDExitPolledModeProcPtr pUSBHIDExitPolledMode;
861: };
862: typedef struct USBHIDModuleDispatchTable USBHIDModuleDispatchTable;
863: typedef USBHIDModuleDispatchTable * USBHIDModuleDispatchTablePtr;
864: /* Prototypes Tue, Mar 17, 1998 4:54:30 PM */
865: EXTERN_API_C( OSStatus )
866: USBHIDInstallInterrupt (HIDInterruptProcPtr HIDInterruptFunction,
867: UInt32 refcon);
868:
869: EXTERN_API_C( OSStatus )
870: USBHIDPollDevice (void);
871:
872: EXTERN_API_C( OSStatus )
873: USBHIDControlDevice (UInt32 theControlSelector,
874: void * theControlData);
875:
876: EXTERN_API_C( OSStatus )
877: USBHIDGetDeviceInfo (UInt32 theInfoSelector,
878: void * theInfo);
879:
880: EXTERN_API_C( OSStatus )
881: USBHIDEnterPolledMode (void);
882:
883: EXTERN_API_C( OSStatus )
884: USBHIDExitPolledMode (void);
885:
886: EXTERN_API_C( void )
887: HIDNotification (UInt32 devicetype,
888: UInt8 NewHIDData[],
889: UInt8 OldHIDData[]);
890:
891:
892: enum {
893: kHIDRqGetReport = 1,
894: kHIDRqGetIdle = 2,
895: kHIDRqGetProtocol = 3,
896: kHIDRqSetReport = 9,
897: kHIDRqSetIdle = 10,
898: kHIDRqSetProtocol = 11
899: };
900:
901:
902: enum {
903: kHIDRtInputReport = 1,
904: kHIDRtOutputReport = 2,
905: kHIDRtFeatureReport = 3
906: };
907:
908:
909: enum {
910: kHIDBootProtocolValue = 0,
911: kHIDReportProtocolValue = 1
912: };
913:
914:
915: enum {
916: kHIDKeyboardInterfaceProtocol = 1,
917: kHIDMouseInterfaceProtocol = 2
918: };
919:
920:
921: enum {
922: kHIDSetLEDStateByBits = 1,
923: kHIDSetLEDStateByBitMask = 1,
924: kHIDSetLEDStateByIDNumber = 2,
925: kHIDRemoveInterruptHandler = 3,
926: kHIDEnableDemoMode = 4,
927: kHIDDisableDemoMode = 5
928: };
929:
930:
931: enum {
932: kHIDGetLEDStateByBits = 1, /* not supported in 1.0 of keyboard module*/
933: kHIDGetLEDStateByBitMask = 1, /* not supported in 1.0 of keyboard module*/
934: kHIDGetLEDStateByIDNumber = 2,
935: kHIDGetDeviceCountryCode = 3, /* not supported in 1.0 HID modules*/
936: kHIDGetDeviceUnitsPerInch = 4, /* only supported in mouse HID module*/
937: kHIDGetInterruptHandler = 5,
938: kHIDGetCurrentKeys = 6, /* only supported in keyboard HID module*/
939: kHIDGetInterruptRefcon = 7,
940: kHIDGetVendorID = 8,
941: kHIDGetProductID = 9
942: };
943:
944:
945:
946: enum {
947: kNumLockLED = 0,
948: kCapsLockLED = 1,
949: kScrollLockLED = 2,
950: kComposeLED = 3,
951: kKanaLED = 4
952: };
953:
954:
955: enum {
956: kNumLockLEDMask = 1 << kNumLockLED,
957: kCapsLockLEDMask = 1 << kCapsLockLED,
958: kScrollLockLEDMask = 1 << kScrollLockLED,
959: kComposeLEDMask = 1 << kComposeLED,
960: kKanaLEDMask = 1 << kKanaLED
961: };
962:
963:
964: enum {
965: kUSBCapsLockKey = 0x39,
966: kUSBNumLockKey = 0x53,
967: kUSBScrollLockKey = 0x47
968: };
969:
970:
971: struct USBMouseData {
972: UInt16 buttons;
973: SInt16 XDelta;
974: SInt16 YDelta;
975: };
976: typedef struct USBMouseData USBMouseData;
977: typedef USBMouseData * USBMouseDataPtr;
978:
979: struct USBKeyboardData {
980: UInt16 keycount;
981: UInt16 usbkeycode[32];
982: };
983: typedef struct USBKeyboardData USBKeyboardData;
984: typedef USBKeyboardData * USBKeyboardDataPtr;
985:
986: union USBHIDData {
987: USBKeyboardData kbd;
988: USBMouseData mouse;
989: };
990: typedef union USBHIDData USBHIDData;
991: typedef USBHIDData * USBHIDDataPtr;
992: EXTERN_API_C( void )
993: StartCompoundClassDriver (USBDeviceRef device,
994: UInt16 classID,
995: UInt16 subClass);
996:
997:
998: enum {
999: kUSBCompositeClass = 0,
1000: kUSBAudioClass = 1,
1001: kUSBCommClass = 2,
1002: kUSBHIDClass = 3,
1003: kUSBDisplayClass = 4,
1004: kUSBPrintingClass = 7,
1005: kUSBMassStorageClass = 8,
1006: kUSBHubClass = 9,
1007: kUSBDataClass = 10,
1008: kUSBVendorSpecificClass = 0xFF
1009: };
1010:
1011:
1012: enum {
1013: kUSBCompositeSubClass = 0,
1014: kUSBHubSubClass = 1
1015: };
1016:
1017:
1018: enum {
1019: kUSBHIDInterfaceClass = 0x03
1020: };
1021:
1022:
1023: enum {
1024: kUSBNoInterfaceSubClass = 0x00,
1025: kUSBBootInterfaceSubClass = 0x01
1026: };
1027:
1028:
1029: enum {
1030: kUSBNoInterfaceProtocol = 0x00,
1031: kUSBKeyboardInterfaceProtocol = 0x01,
1032: kUSBMouseInterfaceProtocol = 0x02
1033: };
1034:
1035:
1036:
1037:
1038: enum {
1039: kServiceCategoryUSB = FOUR_CHAR_CODE('usb ') /* USB*/
1040: };
1041:
1042: /* SOMETHING NEEDS TO BE DONE WITH THIS - */
1043:
1044: enum {
1045: kUSBTypeIsHub = FOUR_CHAR_CODE('hubd'), /* Hub*/
1046: kUSBTypeIsHID = FOUR_CHAR_CODE('HIDd'), /* Human Interface Device*/
1047: kUSBTypeIsDisplay = FOUR_CHAR_CODE('disp'), /* Display */
1048: kUSBTypeIsModem = FOUR_CHAR_CODE('modm') /* Modem*/
1049: };
1050:
1051:
1052: enum {
1053: kUSBDriverFileType = FOUR_CHAR_CODE('ndrv'),
1054: kUSBDriverRsrcType = FOUR_CHAR_CODE('usbd'),
1055: kUSBShimRsrcType = FOUR_CHAR_CODE('usbs')
1056: };
1057:
1058:
1059: enum {
1060: kTheUSBDriverDescriptionSignature = FOUR_CHAR_CODE('usbd')
1061: };
1062:
1063:
1064: enum {
1065: kInitialUSBDriverDescriptor = 0
1066: };
1067:
1068:
1069:
1070: typedef UInt32 USBDriverDescVersion;
1071: /* Driver Loading Options*/
1072: typedef UInt32 USBDriverLoadingOptions;
1073:
1074: enum {
1075: kUSBDoNotMatchGenericDevice = 0x00000001, /* Driver's VendorID must match Device's VendorID*/
1076: kUSBDoNotMatchInterface = 0x00000002, /* Do not load this driver as an interface driver.*/
1077: kUSBProtocolMustMatch = 0x00000004, /* Do not load this driver if protocol field doesn't match.*/
1078: kUSBInterfaceMatchOnly = 0x00000008 /* Only load this driver as an interface driver.*/
1079: };
1080:
1081:
1082: enum {
1083: kClassDriverPluginVersion = 0x00001100
1084: };
1085:
1086:
1087:
1088:
1089: struct USBDeviceInfo {
1090: UInt16 usbVendorID; /* USB Vendor ID*/
1091: UInt16 usbProductID; /* USB Product ID.*/
1092: UInt16 usbDeviceReleaseNumber; /* Release Number of Device*/
1093: UInt16 usbDeviceProtocol; /* Protocol Info.*/
1094: };
1095: typedef struct USBDeviceInfo USBDeviceInfo;
1096: typedef USBDeviceInfo * USBDeviceInfoPtr;
1097:
1098: struct USBInterfaceInfo {
1099: UInt8 usbConfigValue; /* Configuration Value*/
1100: UInt8 usbInterfaceNum; /* Interface Number*/
1101: UInt8 usbInterfaceClass; /* Interface Class*/
1102: UInt8 usbInterfaceSubClass; /* Interface SubClass*/
1103: UInt8 usbInterfaceProtocol; /* Interface Protocol*/
1104: };
1105: typedef struct USBInterfaceInfo USBInterfaceInfo;
1106: typedef USBInterfaceInfo * USBInterfaceInfoPtr;
1107:
1108: struct USBDriverType {
1109: Str31 nameInfoStr; /* Driver's name when loading into the Name Registry.*/
1110: UInt8 usbDriverClass; /* USB Class this driver belongs to.*/
1111: UInt8 usbDriverSubClass; /* Module type*/
1112: NumVersion usbDriverVersion; /* Class driver version number.*/
1113: };
1114: typedef struct USBDriverType USBDriverType;
1115: typedef USBDriverType * USBDriverTypePtr;
1116:
1117: struct USBDriverDescription {
1118: OSType usbDriverDescSignature; /* Signature field of this structure.*/
1119: USBDriverDescVersion usbDriverDescVersion; /* Version of this data structure.*/
1120: USBDeviceInfo usbDeviceInfo; /* Product & Vendor Info*/
1121: USBInterfaceInfo usbInterfaceInfo; /* Interface info*/
1122: USBDriverType usbDriverType; /* Driver Info.*/
1123: USBDriverLoadingOptions usbDriverLoadingOptions; /* Options for class driver loading.*/
1124: };
1125: typedef struct USBDriverDescription USBDriverDescription;
1126: typedef USBDriverDescription * USBDriverDescriptionPtr;
1127: /*
1128: Dispatch Table
1129: Definition of class driver's HW Validation proc.
1130: */
1131: typedef CALLBACK_API_C( OSStatus , USBDValidateHWProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
1132: /*
1133: Definition of class driver's device initialization proc.
1134: Called if the driver is being loaded for a device
1135: */
1136: typedef CALLBACK_API_C( OSStatus , USBDInitializeDeviceProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
1137: /* Definition of class driver's interface initialization proc.*/
1138: typedef CALLBACK_API_C( OSStatus , USBDInitializeInterfaceProcPtr )(UInt32 interfaceNum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDevice, USBInterfaceRef interfaceRef);
1139: /* Definition of class driver's finalization proc.*/
1140: typedef CALLBACK_API_C( OSStatus , USBDFinalizeProcPtr )(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
1141:
1142: typedef UInt32 USBDriverNotification;
1143:
1144: enum {
1145: kNotifySystemSleepRequest = 0x00000001,
1146: kNotifySystemSleepDemand = 0x00000002,
1147: kNotifyHubEnumQuery = 0x00000006,
1148: kNotifyChildMessage = 0x00000007,
1149: kNotifyDriverBeingRemoved = 0x0000000B
1150: };
1151:
1152: /*
1153: Definition of driver's notificatipn proc.
1154: Added refcon for 1.1 version of dispatch table
1155: */
1156: typedef CALLBACK_API_C( OSStatus , USBDDriverNotifyProcPtr )(USBDriverNotification notification, void *pointer, UInt32 refcon);
1157:
1158: struct USBClassDriverPluginDispatchTable {
1159: UInt32 pluginVersion;
1160: USBDValidateHWProcPtr validateHWProc; /* Proc for driver to verify proper HW*/
1161: USBDInitializeDeviceProcPtr initializeDeviceProc; /* Proc that initializes the class driver.*/
1162: USBDInitializeInterfaceProcPtr initializeInterfaceProc; /* Proc that initializes a particular interface in the class driver.*/
1163: USBDFinalizeProcPtr finalizeProc; /* Proc that finalizes the class driver.*/
1164: USBDDriverNotifyProcPtr notificationProc; /* Proc to pass notifications to the driver.*/
1165: };
1166: typedef struct USBClassDriverPluginDispatchTable USBClassDriverPluginDispatchTable;
1167: typedef USBClassDriverPluginDispatchTable * USBClassDriverPluginDispatchTablePtr;
1168: /* Hub defines*/
1169:
1170:
1171:
1172: enum {
1173: kUSBHubDescriptorType = 0x29
1174: };
1175:
1176:
1177: enum {
1178: /* Hub features */
1179: kUSBHubLocalPowerChangeFeature = 0,
1180: kUSBHubOverCurrentChangeFeature = 1, /* port features */
1181: kUSBHubPortConnectionFeature = 0,
1182: kUSBHubPortEnablenFeature = 1,
1183: kUSBHubPortSuspecdFeature = 2,
1184: kUSBHubPortOverCurrentFeature = 3,
1185: kUSBHubPortResetFeature = 4,
1186: kUSBHubPortPowerFeature = 8,
1187: kUSBHubPortLowSpeedFeature = 9,
1188: kUSBHubPortConnectionChangeFeature = 16,
1189: kUSBHubPortEnableChangeFeature = 17,
1190: kUSBHubPortSuspendChangeFeature = 18,
1191: kUSBHubPortOverCurrentChangeFeature = 19,
1192: kUSBHubPortResetChangeFeature = 20
1193: };
1194:
1195:
1196:
1197: enum {
1198: kHubPortConnection = 1,
1199: kHubPortEnabled = 2,
1200: kHubPortSuspend = 4,
1201: kHubPortOverCurrent = 8,
1202: kHubPortBeingReset = 16,
1203: kHubPortPower = 0x0100,
1204: kHubPortSpeed = 0x0200
1205: };
1206:
1207:
1208: enum {
1209: kHubLocalPowerStatus = 1,
1210: kHubOverCurrentIndicator = 2,
1211: kHubLocalPowerStatusChange = 1,
1212: kHubOverCurrentIndicatorChange = 2
1213: };
1214:
1215:
1216: enum {
1217: off = false,
1218: on = true
1219: };
1220:
1221:
1222:
1223: struct hubDescriptor {
1224: /* See usbDoc pg 250?? */
1225: UInt8 dummy; /* to align charcteristics */
1226:
1227: UInt8 length;
1228: UInt8 hubType;
1229: UInt8 numPorts;
1230:
1231: UInt16 characteristics;
1232: UInt8 powerOnToGood; /* Port settling time, in 2ms */
1233: UInt8 hubCurrent;
1234:
1235: /* These are received packed, will have to be unpacked */
1236: UInt8 removablePortFlags[8];
1237: UInt8 pwrCtlPortFlags[8];
1238: };
1239: typedef struct hubDescriptor hubDescriptor;
1240:
1241:
1242:
1243: #if PRAGMA_STRUCT_ALIGN
1244: #pragma options align=reset
1245: #elif PRAGMA_STRUCT_PACKPUSH
1246: #pragma pack(pop)
1247: #elif PRAGMA_STRUCT_PACK
1248: #pragma pack()
1249: #endif
1250:
1251: #ifdef PRAGMA_IMPORT_OFF
1252: #pragma import off
1253: #elif PRAGMA_IMPORT
1254: #pragma import reset
1255: #endif
1256:
1257: #ifdef __cplusplus
1258: }
1259: #endif
1260:
1261: #endif /* __USB__ */
1262: #define kprintf usb_donone
1263: #define printf usb_donone
1264: void usb_donone(char *x,...);
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.