]>
Commit | Line | Data |
---|---|---|
1c79356b A |
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) 1999 Apple Computer, Inc. All rights reserved. | |
24 | * | |
25 | * HISTORY | |
26 | * | |
27 | * | |
28 | */ | |
29 | ||
30 | #include <IOKit/assert.h> | |
31 | #include <IOKit/network/IONetworkInterface.h> | |
32 | #include <IOKit/network/IONetworkUserClient.h> | |
33 | #include <IOKit/network/IONetworkData.h> | |
34 | ||
35 | //------------------------------------------------------------------------ | |
36 | ||
37 | #define super IOUserClient | |
38 | OSDefineMetaClassAndStructors( IONetworkUserClient, IOUserClient ) | |
39 | ||
40 | #ifdef DEBUG | |
41 | #define DLOG(fmt, args...) IOLog(fmt, ## args) | |
42 | #else | |
43 | #define DLOG(fmt, args...) | |
44 | #endif | |
45 | ||
46 | //--------------------------------------------------------------------------- | |
47 | // Factory method that performs allocation and initialization | |
48 | // of an IONetworkUserClient instance. | |
49 | ||
50 | IONetworkUserClient * IONetworkUserClient::withTask(task_t owningTask) | |
51 | { | |
52 | IONetworkUserClient * me; | |
53 | ||
54 | me = new IONetworkUserClient; | |
55 | if (me) | |
56 | { | |
57 | if (!me->init()) | |
58 | { | |
59 | me->release(); | |
60 | return 0; | |
61 | } | |
62 | me->_task = owningTask; | |
63 | } | |
64 | return me; | |
65 | } | |
66 | ||
67 | //--------------------------------------------------------------------------- | |
68 | // Start the IONetworkUserClient. | |
69 | ||
70 | bool IONetworkUserClient::start(IOService * provider) | |
71 | { | |
72 | UInt32 i; | |
73 | ||
74 | _owner = OSDynamicCast(IONetworkInterface, provider); | |
75 | assert(_owner); | |
76 | ||
77 | if (!super::start(_owner)) | |
78 | return false; | |
79 | ||
80 | if (!_owner->open(this)) | |
81 | return false; | |
82 | ||
83 | // Initialize the call structures. | |
84 | // | |
85 | i = kIONUCResetNetworkDataIndex; | |
86 | _methods[i].object = this; | |
87 | _methods[i].func = (IOMethod) &IONetworkUserClient::resetNetworkData; | |
88 | _methods[i].count0 = kIONUCResetNetworkDataInputs; | |
89 | _methods[i].count1 = kIONUCResetNetworkDataOutputs; | |
90 | _methods[i].flags = kIONUCResetNetworkDataFlags; | |
91 | ||
92 | i = kIONUCWriteNetworkDataIndex; | |
93 | _methods[i].object = this; | |
94 | _methods[i].func = (IOMethod) &IONetworkUserClient::writeNetworkData; | |
95 | _methods[i].count0 = kIONUCWriteNetworkDataInput0; | |
96 | _methods[i].count1 = kIONUCWriteNetworkDataInput1; | |
97 | _methods[i].flags = kIONUCWriteNetworkDataFlags; | |
98 | ||
99 | i = kIONUCReadNetworkDataIndex; | |
100 | _methods[i].object = this; | |
101 | _methods[i].func = (IOMethod) &IONetworkUserClient::readNetworkData; | |
102 | _methods[i].count0 = kIONUCReadNetworkDataInputs; | |
103 | _methods[i].count1 = kIONUCReadNetworkDataOutputs; | |
104 | _methods[i].flags = kIONUCReadNetworkDataFlags; | |
105 | ||
106 | i = kIONUCGetNetworkDataCapacityIndex; | |
107 | _methods[i].object = this; | |
108 | _methods[i].func = (IOMethod) | |
109 | &IONetworkUserClient::getNetworkDataCapacity; | |
110 | _methods[i].count0 = kIONUCGetNetworkDataCapacityInputs; | |
111 | _methods[i].count1 = kIONUCGetNetworkDataCapacityOutputs; | |
112 | _methods[i].flags = kIONUCGetNetworkDataCapacityFlags; | |
113 | ||
114 | i = kIONUCGetNetworkDataHandleIndex; | |
115 | _methods[i].object = this; | |
116 | _methods[i].func = (IOMethod) &IONetworkUserClient::getNetworkDataHandle; | |
117 | _methods[i].count0 = kIONUCGetNetworkDataHandleInputs; | |
118 | _methods[i].count1 = kIONUCGetNetworkDataHandleOutputs; | |
119 | _methods[i].flags = kIONUCGetNetworkDataHandleFlags; | |
120 | ||
121 | return true; | |
122 | } | |
123 | ||
124 | //--------------------------------------------------------------------------- | |
125 | // Free the IONetworkUserClient instance. | |
126 | ||
127 | void IONetworkUserClient::free() | |
128 | { | |
129 | super::free(); | |
130 | } | |
131 | ||
132 | //--------------------------------------------------------------------------- | |
133 | // Handle a client close. Close and detach from our owner (provider). | |
134 | ||
135 | IOReturn IONetworkUserClient::clientClose() | |
136 | { | |
137 | if (_owner) { | |
138 | _owner->close(this); | |
139 | detach(_owner); | |
140 | } | |
141 | ||
142 | return kIOReturnSuccess; | |
143 | } | |
144 | ||
145 | //--------------------------------------------------------------------------- | |
146 | // Handle client death. Close and detach from our owner (provider). | |
147 | ||
148 | IOReturn IONetworkUserClient::clientDied() | |
149 | { | |
150 | return clientClose(); | |
151 | } | |
152 | ||
153 | //--------------------------------------------------------------------------- | |
154 | // Look up an entry from the method array. | |
155 | ||
156 | IOExternalMethod * | |
157 | IONetworkUserClient::getExternalMethodForIndex(UInt32 index) | |
158 | { | |
159 | if (index >= kIONUCLastIndex) | |
160 | return 0; | |
161 | else | |
162 | return &_methods[index]; | |
163 | } | |
164 | ||
165 | //--------------------------------------------------------------------------- | |
166 | // Fill the data buffer in an IONetworkData object with zeroes. | |
167 | ||
168 | IOReturn IONetworkUserClient::resetNetworkData(OSSymbol * key) | |
169 | { | |
170 | IONetworkData * data; | |
171 | IOReturn ret; | |
172 | ||
173 | data = _owner->getNetworkData(key); | |
174 | ret = data ? data->reset() : kIOReturnBadArgument; | |
175 | ||
176 | return ret; | |
177 | } | |
178 | ||
179 | //--------------------------------------------------------------------------- | |
180 | // Write to the data buffer in an IONetworkData object with data from a | |
181 | // source buffer provided by the caller. | |
182 | ||
183 | IOReturn | |
184 | IONetworkUserClient::writeNetworkData(OSSymbol * key, | |
185 | void * srcBuffer, | |
186 | IOByteCount srcBufferSize) | |
187 | { | |
188 | IONetworkData * data; | |
189 | IOReturn ret; | |
190 | ||
191 | if (!srcBuffer || (srcBufferSize == 0)) | |
192 | return kIOReturnBadArgument; | |
193 | ||
194 | data = _owner->getNetworkData(key); | |
195 | ret = data ? data->write(srcBuffer, srcBufferSize) : kIOReturnBadArgument; | |
196 | ||
197 | return ret; | |
198 | } | |
199 | ||
200 | //--------------------------------------------------------------------------- | |
201 | // Read the data buffer in an IONetworkData object and copy | |
202 | // this data to a destination buffer provided by the caller. | |
203 | ||
204 | IOReturn | |
205 | IONetworkUserClient::readNetworkData(OSSymbol * key, | |
206 | void * dstBuffer, | |
207 | IOByteCount * dstBufferSize) | |
208 | { | |
209 | IONetworkData * data; | |
210 | IOReturn ret ; | |
211 | ||
212 | if (!dstBuffer || !dstBufferSize) | |
213 | return kIOReturnBadArgument; | |
214 | ||
215 | data = _owner->getNetworkData(key); | |
216 | ret = data ? data->read(dstBuffer, dstBufferSize) : | |
217 | kIOReturnBadArgument; | |
218 | ||
219 | return ret; | |
220 | } | |
221 | ||
222 | //--------------------------------------------------------------------------- | |
223 | // Get the capacity of an IONetworkData object. | |
224 | ||
225 | IOReturn | |
226 | IONetworkUserClient::getNetworkDataCapacity(OSSymbol * key, | |
227 | UInt32 * capacity) | |
228 | { | |
229 | IOReturn ret = kIOReturnBadArgument; | |
230 | IONetworkData * data; | |
231 | ||
232 | data = _owner->getNetworkData(key); | |
233 | ||
234 | if (data) { | |
235 | *capacity = data->getSize(); | |
236 | ret = kIOReturnSuccess; | |
237 | } | |
238 | ||
239 | return ret; | |
240 | } | |
241 | ||
242 | //--------------------------------------------------------------------------- | |
243 | // Called to obtain a handle that maps to an IONetworkData object. | |
244 | // This handle can be later passed to other methods in this class | |
245 | // to refer to the same object. | |
246 | ||
247 | IOReturn | |
248 | IONetworkUserClient::getNetworkDataHandle(char * name, | |
249 | OSSymbol ** handle, | |
250 | IOByteCount nameSize, | |
251 | IOByteCount * handleSizeP) | |
252 | { | |
253 | IOReturn ret = kIOReturnBadArgument; | |
254 | const OSSymbol * key; | |
255 | ||
256 | if (!name || !nameSize || (name[nameSize - 1] != '\0') || | |
257 | (*handleSizeP != sizeof(*handle))) | |
258 | return kIOReturnBadArgument; | |
259 | ||
260 | key = OSSymbol::withCStringNoCopy(name); | |
261 | if (!key) | |
262 | return kIOReturnNoMemory; | |
263 | ||
264 | if (_owner->getNetworkData(key)) | |
265 | { | |
266 | *handle = (OSSymbol *) key; | |
267 | ret = kIOReturnSuccess; | |
268 | } | |
269 | ||
270 | if (key) | |
271 | key->release(); | |
272 | ||
273 | return ret; | |
274 | } |