|
|
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: * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24: *
25: * HISTORY
26: *
27: */
28:
29: #include <libkern/OSByteOrder.h>
30:
31: #include "IOUSBRootHubDevice.h"
32:
33: #define super IOUSBDevice
34: #define self this
35: #define DEBUGGING_LEVEL 0
36: #define DEBUGLOG kprintf
37:
38: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39:
40: OSDefineMetaClassAndStructors( IOUSBRootHubDevice, IOUSBDevice )
41:
42: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43:
44:
45: // intercept regular hub requests since the controller simulates the root hub
46: IOReturn IOUSBRootHubDevice::deviceRequest(IOUSBDevRequest *request,
47: IOUSBCompletion *completion = 0)
48: {
49: IOReturn err = 0;
50: UInt16 theRequest;
51: UInt16 wIndex;
52: UInt16 wValue;
53: UInt16 wLength;
54: UInt8 dType, dIndex;
55:
56:
57: if (!request)
58: return(kIOReturnBadArgument);
59:
60: wValue = OSReadLittleInt16(&request->wValue, 0);
61: wIndex = OSReadLittleInt16(&request->wIndex, 0);
62: wLength = OSReadLittleInt16(&request->wLength, 0);
63:
64: #if (DEBUGGING_LEVEL > 0)
65: DEBUGLOG("%s: deviceRequest([%x,%s,%x,%x],[%x,%x],[%x,%lx])", getName(),
66: request->bRequest,
67: request->rqDirection?"in":"out",
68: request->rqType, request->rqRecipient,
69: wValue, wIndex, wLength, (UInt32)request->pData);
70: #endif
71:
72: theRequest = EncodeRequest(request->bRequest, request->rqDirection,
73: request->rqType, request->rqRecipient);
74: switch (theRequest)
75: {
76: // Standard Requests
77: case kClearDeviceFeature:
78: #if (DEBUGGING_LEVEL > 0)
79: DEBUGLOG("\tkClearDeviceFeature\n");
80: #endif
81: if (wIndex == 0)
82: err = _controller->clearRootHubFeature(wValue);
83: else
84: err = kIOReturnBadArgument;
85: break;
86:
87: case kGetDescriptor:
88: #if (DEBUGGING_LEVEL > 0)
89: DEBUGLOG("\tkGetDescriptor\n");
90: #endif
91: dType = wValue >> 8;
92: dIndex = wValue & 0x00FF;
93: switch (dType) {
94: case kUSBDeviceDesc:
95: err = _controller->getRootHubDeviceDescriptor(
96: (IOUSBDeviceDescriptor*)request->pData);
97: break;
98:
99: case kUSBConfDesc:
100: {
101: OSData *fullDesc = OSData::withCapacity(1024); // FIXME
102: UInt16 newLength;
103:
104: err = _controller->getRootHubConfDescriptor(fullDesc);
105: newLength = fullDesc->getLength();
106: if (newLength < wLength)
107: wLength = newLength;
108: bcopy(fullDesc->getBytesNoCopy(),
109: (char *)request->pData,
110: wLength);
111: request->wLenDone = wLength;
112: fullDesc->free();
113: break;
114: }
115:
116: case kUSBStringDesc:
117: default:
118: err = kIOReturnInvalid;
119: }
120: break;
121:
122: case kGetDeviceStatus:
123: #if (DEBUGGING_LEVEL > 0)
124: DEBUGLOG("\tkGetDeviceStatus\n");
125: #endif
126: if (wValue == 0 && wIndex == 0 && request->pData != 0)
127: *(UInt16*)(request->pData) = HostToUSBWord(1); // self-powered
128: else
129: err = kIOReturnBadArgument;
130: break;
131:
132: case kSetAddress:
133: #if (DEBUGGING_LEVEL > 0)
134: DEBUGLOG("\tkSetAddress\n");
135: #endif
136: if (wIndex == 0)
137: err = _controller->setHubAddress(wValue);
138: else
139: err = kIOReturnBadArgument;
140: break;
141:
142: case kSetConfiguration:
143: #if (DEBUGGING_LEVEL > 0)
144: DEBUGLOG("\tkSetConfiguration\n");
145: #endif
146: if (wIndex == 0)
147: configuration = wValue;
148: else
149: err = kIOReturnBadArgument;
150: break;
151:
152: case kSetDeviceFeature:
153: #if (DEBUGGING_LEVEL > 0)
154: DEBUGLOG("\tkSetDeviceFeature\n");
155: #endif
156: if (wIndex == 0)
157: err = _controller->setRootHubFeature(wValue);
158: else
159: err = kIOReturnBadArgument;
160: break;
161:
162: case kGetConfiguration:
163: #if (DEBUGGING_LEVEL > 0)
164: DEBUGLOG("\tkGetConfiguration\n");
165: #endif
166: if (wIndex == 0 && request->pData != 0)
167: *(UInt8*)(request->pData) = configuration;
168: else
169: err = kIOReturnBadArgument;
170: break;
171:
172: case kClearInterfaceFeature:
173: case kClearEndpointFeature:
174: case kGetInterface:
175: case kGetInterfaceStatus:
176: case kGetEndpointStatus:
177: case kSetInterfaceFeature:
178: case kSetEndpointFeature:
179: case kSetDescriptor:
180: case kSetInterface:
181: case kSyncFrame:
182: #if (DEBUGGING_LEVEL > 0)
183: DEBUGLOG("\tUNIMPLEMENTED request\n");
184: #endif
185: err = kIOReturnUnsupported;
186: break;
187:
188: // Class Requests
189: case kClearHubFeature:
190: #if (DEBUGGING_LEVEL > 0)
191: DEBUGLOG("\tkClearHubFeature\n");
192: #endif
193: if (wIndex == 0)
194: err = _controller->clearRootHubFeature(wValue);
195: else
196: err = kIOReturnBadArgument;
197: break;
198:
199: case kClearPortFeature:
200: #if (DEBUGGING_LEVEL > 0)
201: DEBUGLOG("\tkClearPortFeature\n");
202: #endif
203: err = _controller->clearRootHubPortFeature(wValue, wIndex);
204: break;
205:
206: case kGetPortState:
207: #if (DEBUGGING_LEVEL > 0)
208: DEBUGLOG("\tkGetPortState\n");
209: #endif
210: if (wValue == 0 && request->pData != 0)
211: err = _controller->getRootHubPortState((UInt8 *)request->pData,
212: wIndex);
213: else
214: err = kIOReturnBadArgument;
215: break;
216:
217: case kGetHubDescriptor:
218: #if (DEBUGGING_LEVEL > 0)
219: DEBUGLOG("\tkGetHubDescriptor\n");
220: #endif
221: if (wValue == kUSBHubDescriptorType && request->pData != 0)
222: err = _controller->getRootHubDescriptor(
223: (IOUSBHubDescriptor *)request->pData);
224: else
225: err = kIOReturnBadArgument;
226: break;
227:
228: case kGetHubStatus:
229: #if (DEBUGGING_LEVEL > 0)
230: DEBUGLOG("\tkGetHubStatus\n");
231: #endif
232: if (wValue == 0 && wIndex == 0 && request->pData != 0)
233: err = _controller->getRootHubStatus(
234: (IOUSBHubStatus *)request->pData);
235: else
236: err = kIOReturnBadArgument;
237: break;
238:
239: case kGetPortStatus:
240: #if (DEBUGGING_LEVEL > 0)
241: DEBUGLOG("\tkGetPortStatus\n");
242: #endif
243: if (wValue == 0 && request->pData != 0)
244: err = _controller->getRootHubPortStatus(
245: (IOUSBHubPortStatus *)request->pData, wIndex);
246: else
247: err = kIOReturnBadArgument;
248: break;
249:
250: case kSetHubDescriptor:
251: #if (DEBUGGING_LEVEL > 0)
252: DEBUGLOG("\tkSetHubDescriptor\n");
253: #endif
254: if (request->pData != 0)
255: err = _controller->setRootHubDescriptor(
256: (OSData *)request->pData);
257: else
258: err = kIOReturnBadArgument;
259: break;
260:
261: case kSetHubFeature:
262: #if (DEBUGGING_LEVEL > 0)
263: DEBUGLOG("\tkSetHubFeature\n");
264: #endif
265: if (wIndex == 0)
266: err = _controller->setRootHubFeature(wValue);
267: else
268: err = kIOReturnBadArgument;
269: break;
270:
271: case kSetPortFeature:
272: #if (DEBUGGING_LEVEL > 0)
273: DEBUGLOG("\tkSetPortFeature\n");
274: #endif
275: err = _controller->setRootHubPortFeature(wValue, wIndex);
276: break;
277:
278: default:
279: #if (DEBUGGING_LEVEL > 0)
280: DEBUGLOG("\tINVALID request\n");
281: #endif
282: err = kIOReturnInvalid;
283:
284: }
285: return(err);
286: }
287:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.