Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to define new ioctl commands for a Network Controller?



Hello,

I have a need to define driver-dependant ioctl commands for an IOKit
ethernet driver I am developing, but the IOKit interface doesn't seem
to propagate unknown ioctl commands down to the driver. The problem
(as I see it) is that the IONetworkInterface::performCommand() method
only passes certain recognized commands down to the driver, and returns
EOPNOTSUPP for all others. Here is the code:

SInt32 IONetworkInterface::performCommand(IONetworkController * ctr,
UInt32 cmd,
void * arg0,
void * arg1)
{
struct ifreq * ifr = (struct ifreq *) arg1;
SInt32 ret = EOPNOTSUPP;

if ( (ifr == 0) || (ctr == 0) )
return EINVAL;

switch ( cmd )
{
// Get interface MTU.

case SIOCGIFMTU:
ifr->ifr_mtu = getMaxTransferUnit();
ret = 0; // no error
break;

// Get interface media type and status.

case SIOCGIFMEDIA:
ret = syncSIOCGIFMEDIA(ctr, ifr);
break;

case SIOCSIFMTU:
case SIOCSIFMEDIA:
case SIOCSIFLLADDR:
ret = (int) ctr->executeCommand(
this, /* client */
(IONetworkController::Action)
&IONetworkInterface::performGatedCommand,
this, /* target */
ctr, /* param0 */
(void *) cmd, /* param1 */
arg0, /* param2 */
arg1 ); /* param3 */
break;

default:
// DLOG(%s: command not handled (%08lx), getName(), cmd);
break;
}

return ret;
}

I have overridden the executeCommand() method in my driver, and I've verified
that it does get called for these recognized commands. However, when I try to
pass one of my newly defined ioctl commands to the driver, my application gets
the "ioctl: : Operation not supported" error.

According to the darwin-drivers archives, a very similar question was asked by
hlkari@dachb0den in January of 2002, but he didn't get his question resolved.

I hope I'm just missing something here, but if that is not the case, then my
workaround might be to define an EthernetInterface subclass for the sole purpose
of overriding its performCommand() method so that it will pass unknown ioctl
commands down to the driver (the default method in EthernetInterface calls its
NetworkController superclass). I will try this workaround.

However, it seems to me that the IOKit scheme should be extended to allow a
network driver to receive custom ioctl commands. I suggest that the following
changes be considered:

1) Add a new 'bool customIoctls' instance variable to IONetworkInterface, which
defaults to false.

2) Add a new 'void allowCustomIoctls(bool active)' instance method to
IONetworkInterface, to set or clear the new customIoctls variable.
A NetworkController driver which defined its own custom ioctl commands would
call this method from its start method with active set to true.

3) Modify the default clause in the IONetworkInterface::performCommand() method
to pass unrecognized ioctl commands to the driver if customIoctls is set, as
follows:

default:
+ if (customIoctls) {
+ ret = (int) ctr->executeCommand(
+ this, /* client */
+ (IONetworkController::Action)
+ &IONetworkInterface::performGatedCommand,
+ this, /* target */
+ ctr, /* param0 */
+ (void *) cmd, /* param1 */
+ arg0, /* param2 */
+ arg1 ); /* param3 */
+ }
// DLOG(%s: command not handled (%08lx), getName(), cmd);
break;

The new IONetworkInterface::allowCustomIoctls() method should be documented to
require drivers which enable custom ioctls to return EOPNOTSUPP when their
executeCommand() method is called with an unrecognized ioctl command code.

Comments?

Jim Hunter
Small Tree Communications
_______________________________________________
darwin-drivers mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-drivers
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.