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.
25 * IOEthernetController.cpp
27 * Abstract Ethernet controller superclass.
31 * Dec 3, 1998 jliu - C++ conversion.
34 #include <IOKit/assert.h>
35 #include <IOKit/network/IOEthernetController.h>
36 #include <IOKit/network/IOEthernetInterface.h>
39 #include <sys/socket.h>
41 #include <net/etherdefs.h>
44 //---------------------------------------------------------------------------
46 #define super IONetworkController
48 OSDefineMetaClassAndAbstractStructors( IOEthernetController
, IONetworkController
)
49 OSMetaClassDefineReservedUnused( IOEthernetController
, 0);
50 OSMetaClassDefineReservedUnused( IOEthernetController
, 1);
51 OSMetaClassDefineReservedUnused( IOEthernetController
, 2);
52 OSMetaClassDefineReservedUnused( IOEthernetController
, 3);
53 OSMetaClassDefineReservedUnused( IOEthernetController
, 4);
54 OSMetaClassDefineReservedUnused( IOEthernetController
, 5);
55 OSMetaClassDefineReservedUnused( IOEthernetController
, 6);
56 OSMetaClassDefineReservedUnused( IOEthernetController
, 7);
57 OSMetaClassDefineReservedUnused( IOEthernetController
, 8);
58 OSMetaClassDefineReservedUnused( IOEthernetController
, 9);
59 OSMetaClassDefineReservedUnused( IOEthernetController
, 10);
60 OSMetaClassDefineReservedUnused( IOEthernetController
, 11);
61 OSMetaClassDefineReservedUnused( IOEthernetController
, 12);
62 OSMetaClassDefineReservedUnused( IOEthernetController
, 13);
63 OSMetaClassDefineReservedUnused( IOEthernetController
, 14);
64 OSMetaClassDefineReservedUnused( IOEthernetController
, 15);
65 OSMetaClassDefineReservedUnused( IOEthernetController
, 16);
66 OSMetaClassDefineReservedUnused( IOEthernetController
, 17);
67 OSMetaClassDefineReservedUnused( IOEthernetController
, 18);
68 OSMetaClassDefineReservedUnused( IOEthernetController
, 19);
69 OSMetaClassDefineReservedUnused( IOEthernetController
, 20);
70 OSMetaClassDefineReservedUnused( IOEthernetController
, 21);
71 OSMetaClassDefineReservedUnused( IOEthernetController
, 22);
72 OSMetaClassDefineReservedUnused( IOEthernetController
, 23);
73 OSMetaClassDefineReservedUnused( IOEthernetController
, 24);
74 OSMetaClassDefineReservedUnused( IOEthernetController
, 25);
75 OSMetaClassDefineReservedUnused( IOEthernetController
, 26);
76 OSMetaClassDefineReservedUnused( IOEthernetController
, 27);
77 OSMetaClassDefineReservedUnused( IOEthernetController
, 28);
78 OSMetaClassDefineReservedUnused( IOEthernetController
, 29);
79 OSMetaClassDefineReservedUnused( IOEthernetController
, 30);
80 OSMetaClassDefineReservedUnused( IOEthernetController
, 31);
82 //-------------------------------------------------------------------------
86 #define DLOG(fmt, args...) IOLog(fmt, ## args)
88 #define DLOG(fmt, args...)
91 //---------------------------------------------------------------------------
92 // IOEthernetController class initializer.
94 void IOEthernetController::initialize()
98 //---------------------------------------------------------------------------
99 // Initialize an IOEthernetController instance.
101 bool IOEthernetController::init(OSDictionary
* properties
)
103 if (!super::init(properties
))
105 DLOG("IOEthernetController: super::init() failed\n");
112 //---------------------------------------------------------------------------
113 // Free the IOEthernetController instance.
115 void IOEthernetController::free()
117 // Any allocated resources should be released here.
122 //---------------------------------------------------------------------------
123 // Publish Ethernet controller capabilites and properties.
125 bool IOEthernetController::publishProperties()
128 IOEthernetAddress addr
;
132 // Let the superclass publish properties first.
134 if (super::publishProperties() == false)
137 // Publish the controller's Ethernet address.
139 if ( (getHardwareAddress(&addr
) != kIOReturnSuccess
) ||
140 (setProperty(kIOMACAddress
, (void *) &addr
,
141 kIOEthernetAddressSize
) == false) )
146 // Publish Ethernet defined packet filters.
148 dict
= OSDynamicCast(OSDictionary
, getProperty(kIOPacketFilters
));
154 if ( getPacketFilters(gIOEthernetWakeOnLANFilterGroup
,
155 &filters
) != kIOReturnSuccess
)
160 num
= OSNumber::withNumber(filters
, sizeof(filters
) * 8);
164 ret
= dict
->setObject(gIOEthernetWakeOnLANFilterGroup
, num
);
173 //---------------------------------------------------------------------------
174 // Set or change the station address used by the Ethernet controller.
177 IOEthernetController::setHardwareAddress(const IOEthernetAddress
* addr
)
179 return kIOReturnUnsupported
;
182 //---------------------------------------------------------------------------
183 // Enable or disable multicast mode.
185 IOReturn
IOEthernetController::setMulticastMode(bool active
)
187 return kIOReturnUnsupported
;
190 //---------------------------------------------------------------------------
191 // Enable or disable promiscuous mode.
193 IOReturn
IOEthernetController::setPromiscuousMode(bool active
)
195 return kIOReturnUnsupported
;
198 //---------------------------------------------------------------------------
199 // Enable or disable the wake on Magic Packet support.
201 IOReturn
IOEthernetController::setWakeOnMagicPacket(bool active
)
203 return kIOReturnUnsupported
;
206 //---------------------------------------------------------------------------
207 // Set the list of multicast addresses that the multicast filter should use
208 // to match against the destination address of an incoming frame. The frame
209 // should be accepted when a match occurs.
211 IOReturn
IOEthernetController::setMulticastList(IOEthernetAddress
* /*addrs*/,
214 return kIOReturnUnsupported
;
217 //---------------------------------------------------------------------------
218 // Allocate and return a new IOEthernetInterface instance.
220 IONetworkInterface
* IOEthernetController::createInterface()
222 IOEthernetInterface
* netif
= new IOEthernetInterface
;
224 if ( netif
&& ( netif
->init( this ) == false ) )
232 //---------------------------------------------------------------------------
233 // Returns all the packet filters supported by the Ethernet controller.
234 // This method will perform a bitwise OR of:
236 // kIOPacketFilterUnicast
237 // kIOPacketFilterBroadcast
238 // kIOPacketFilterMulticast
239 // kIOPacketFilterPromiscuous
241 // and write it to the argument provided if the group specified is
242 // gIONetworkFilterGroup, otherwise 0 is returned. Drivers that support
243 // a different set of filters should override this method.
245 // Returns kIOReturnSuccess. Drivers that override this method must return
246 // kIOReturnSuccess to indicate success, or an error code otherwise.
249 IOEthernetController::getPacketFilters(const OSSymbol
* group
,
250 UInt32
* filters
) const
254 if ( group
== gIONetworkFilterGroup
)
256 return getPacketFilters(filters
);
260 return kIOReturnSuccess
;
264 IOReturn
IOEthernetController::getPacketFilters(UInt32
* filters
) const
266 *filters
= ( kIOPacketFilterUnicast
|
267 kIOPacketFilterBroadcast
|
268 kIOPacketFilterMulticast
|
269 kIOPacketFilterPromiscuous
);
271 return kIOReturnSuccess
;
274 //---------------------------------------------------------------------------
275 // Enable a filter from the specified group.
277 #define UCAST_BCAST_MASK \
278 ( kIOPacketFilterUnicast | kIOPacketFilterBroadcast )
280 IOReturn
IOEthernetController::enablePacketFilter(
281 const OSSymbol
* group
,
283 UInt32 enabledFilters
,
284 IOOptionBits options
= 0)
286 IOReturn ret
= kIOReturnUnsupported
;
287 UInt32 newFilters
= enabledFilters
| aFilter
;
289 if ( group
== gIONetworkFilterGroup
)
291 // The default action is to call setMulticastMode() or
292 // setPromiscuousMode() to handle multicast or promiscuous
295 if ( aFilter
== kIOPacketFilterMulticast
)
297 ret
= setMulticastMode(true);
299 else if ( aFilter
== kIOPacketFilterPromiscuous
)
301 ret
= setPromiscuousMode(true);
303 else if ( (newFilters
^ enabledFilters
) & UCAST_BCAST_MASK
)
305 ret
= kIOReturnSuccess
;
308 else if ( group
== gIOEthernetWakeOnLANFilterGroup
)
310 if ( aFilter
== kIOEthernetWakeOnMagicPacket
)
312 ret
= setWakeOnMagicPacket(true);
319 //---------------------------------------------------------------------------
320 // Disable a filter from the specifed filter group.
322 IOReturn
IOEthernetController::disablePacketFilter(
323 const OSSymbol
* group
,
325 UInt32 enabledFilters
,
326 IOOptionBits options
= 0)
328 IOReturn ret
= kIOReturnUnsupported
;
329 UInt32 newFilters
= enabledFilters
& ~aFilter
;
331 if ( group
== gIONetworkFilterGroup
)
333 // The default action is to call setMulticastMode() or
334 // setPromiscuousMode() to handle multicast or promiscuous
337 if ( aFilter
== kIOPacketFilterMulticast
)
339 ret
= setMulticastMode(false);
341 else if ( aFilter
== kIOPacketFilterPromiscuous
)
343 ret
= setPromiscuousMode(false);
345 else if ( (newFilters
^ enabledFilters
) & UCAST_BCAST_MASK
)
347 ret
= kIOReturnSuccess
;
350 else if ( group
== gIOEthernetWakeOnLANFilterGroup
)
352 if ( aFilter
== kIOEthernetWakeOnMagicPacket
)
354 ret
= setWakeOnMagicPacket(false);
361 //---------------------------------------------------------------------------
362 // Get the Ethernet controller's station address.
363 // Call the Ethernet specific (overloaded) form.
366 IOEthernetController::getHardwareAddress(void * addr
,
367 UInt32
* inOutAddrBytes
)
371 if (inOutAddrBytes
== 0)
372 return kIOReturnBadArgument
;
374 // Cache the size of the caller's buffer, and replace it with the
375 // number of bytes required.
377 bufBytes
= *inOutAddrBytes
;
378 *inOutAddrBytes
= kIOEthernetAddressSize
;
380 // Make sure the buffer is large enough for a single Ethernet
383 if ((addr
== 0) || (bufBytes
< kIOEthernetAddressSize
))
384 return kIOReturnNoSpace
;
386 return getHardwareAddress((IOEthernetAddress
*) addr
);
389 //---------------------------------------------------------------------------
390 // Set or change the station address used by the Ethernet controller.
391 // Call the Ethernet specific (overloaded) version of this method.
394 IOEthernetController::setHardwareAddress(const void * addr
,
397 if ((addr
== 0) || (addrBytes
!= kIOEthernetAddressSize
))
398 return kIOReturnBadArgument
;
400 return setHardwareAddress((const IOEthernetAddress
*) addr
);
403 //---------------------------------------------------------------------------
404 // Report the max/min packet sizes, including the frame header and FCS bytes.
406 IOReturn
IOEthernetController::getMaxPacketSize(UInt32
* maxSize
) const
408 *maxSize
= kIOEthernetMaxPacketSize
;
409 return kIOReturnSuccess
;
412 IOReturn
IOEthernetController::getMinPacketSize(UInt32
* minSize
) const
414 *minSize
= kIOEthernetMinPacketSize
;
415 return kIOReturnSuccess
;