2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
23 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
30 #include <IOKit/assert.h>
31 #include <IOKit/network/IONetworkInterface.h>
32 #include <IOKit/network/IONetworkUserClient.h>
33 #include <IOKit/network/IONetworkData.h>
35 //------------------------------------------------------------------------
37 #define super IOUserClient
38 OSDefineMetaClassAndStructors( IONetworkUserClient
, IOUserClient
)
41 #define DLOG(fmt, args...) IOLog(fmt, ## args)
43 #define DLOG(fmt, args...)
46 //---------------------------------------------------------------------------
47 // Factory method that performs allocation and initialization
48 // of an IONetworkUserClient instance.
50 IONetworkUserClient
* IONetworkUserClient::withTask(task_t owningTask
)
52 IONetworkUserClient
* me
;
54 me
= new IONetworkUserClient
;
62 me
->_task
= owningTask
;
67 //---------------------------------------------------------------------------
68 // Start the IONetworkUserClient.
70 bool IONetworkUserClient::start(IOService
* provider
)
74 _owner
= OSDynamicCast(IONetworkInterface
, provider
);
77 if (!super::start(_owner
))
80 if (!_owner
->open(this))
83 // Initialize the call structures.
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
;
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
;
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
;
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
;
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
;
124 //---------------------------------------------------------------------------
125 // Free the IONetworkUserClient instance.
127 void IONetworkUserClient::free()
132 //---------------------------------------------------------------------------
133 // Handle a client close. Close and detach from our owner (provider).
135 IOReturn
IONetworkUserClient::clientClose()
142 return kIOReturnSuccess
;
145 //---------------------------------------------------------------------------
146 // Handle client death. Close and detach from our owner (provider).
148 IOReturn
IONetworkUserClient::clientDied()
150 return clientClose();
153 //---------------------------------------------------------------------------
154 // Look up an entry from the method array.
157 IONetworkUserClient::getExternalMethodForIndex(UInt32 index
)
159 if (index
>= kIONUCLastIndex
)
162 return &_methods
[index
];
165 //---------------------------------------------------------------------------
166 // Fill the data buffer in an IONetworkData object with zeroes.
168 IOReturn
IONetworkUserClient::resetNetworkData(OSSymbol
* key
)
170 IONetworkData
* data
;
173 data
= _owner
->getNetworkData(key
);
174 ret
= data
? data
->reset() : kIOReturnBadArgument
;
179 //---------------------------------------------------------------------------
180 // Write to the data buffer in an IONetworkData object with data from a
181 // source buffer provided by the caller.
184 IONetworkUserClient::writeNetworkData(OSSymbol
* key
,
186 IOByteCount srcBufferSize
)
188 IONetworkData
* data
;
191 if (!srcBuffer
|| (srcBufferSize
== 0))
192 return kIOReturnBadArgument
;
194 data
= _owner
->getNetworkData(key
);
195 ret
= data
? data
->write(srcBuffer
, srcBufferSize
) : kIOReturnBadArgument
;
200 //---------------------------------------------------------------------------
201 // Read the data buffer in an IONetworkData object and copy
202 // this data to a destination buffer provided by the caller.
205 IONetworkUserClient::readNetworkData(OSSymbol
* key
,
207 IOByteCount
* dstBufferSize
)
209 IONetworkData
* data
;
212 if (!dstBuffer
|| !dstBufferSize
)
213 return kIOReturnBadArgument
;
215 data
= _owner
->getNetworkData(key
);
216 ret
= data
? data
->read(dstBuffer
, dstBufferSize
) :
217 kIOReturnBadArgument
;
222 //---------------------------------------------------------------------------
223 // Get the capacity of an IONetworkData object.
226 IONetworkUserClient::getNetworkDataCapacity(OSSymbol
* key
,
229 IOReturn ret
= kIOReturnBadArgument
;
230 IONetworkData
* data
;
232 data
= _owner
->getNetworkData(key
);
235 *capacity
= data
->getSize();
236 ret
= kIOReturnSuccess
;
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.
248 IONetworkUserClient::getNetworkDataHandle(char * name
,
250 IOByteCount nameSize
,
251 IOByteCount
* handleSizeP
)
253 IOReturn ret
= kIOReturnBadArgument
;
254 const OSSymbol
* key
;
256 if (!name
|| !nameSize
|| (name
[nameSize
- 1] != '\0') ||
257 (*handleSizeP
!= sizeof(*handle
)))
258 return kIOReturnBadArgument
;
260 key
= OSSymbol::withCStringNoCopy(name
);
262 return kIOReturnNoMemory
;
264 if (_owner
->getNetworkData(key
))
266 *handle
= (OSSymbol
*) key
;
267 ret
= kIOReturnSuccess
;