diff --git a/include/linux/phonet.h b/include/linux/phonet.h index ee5e3c9e2bcaf0006b6b03f659cc6d323c15f3bb..82b45d16e50cdce64c76b7a699ad30994b553caf 100644 --- a/include/linux/phonet.h +++ b/include/linux/phonet.h @@ -170,4 +170,21 @@ static inline __u8 pn_sockaddr_get_resource(const struct sockaddr_pn *spn) return spn->spn_resource; } +/* Phonet device ioctl requests */ +#ifdef __KERNEL__ +#define SIOCPNGAUTOCONF (SIOCDEVPRIVATE + 0) + +struct if_phonet_autoconf { + uint8_t device; +}; + +struct if_phonet_req { + char ifr_phonet_name[16]; + union { + struct if_phonet_autoconf ifru_phonet_autoconf; + } ifr_ifru; +}; +#define ifr_phonet_autoconf ifr_ifru.ifru_phonet_autoconf +#endif /* __KERNEL__ */ + #endif diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c index 5ae4c01e8388d5db0ab7d0322857cf9dd86ed319..2f65dcaed2fb072056ee2b3a11a89fa7033dc903 100644 --- a/net/phonet/pn_dev.c +++ b/net/phonet/pn_dev.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -195,14 +196,37 @@ int phonet_address_lookup(struct net *net, u8 addr) return err; } +/* automatically configure a Phonet device, if supported */ +static int phonet_device_autoconf(struct net_device *dev) +{ + struct if_phonet_req req; + int ret; + + if (!dev->netdev_ops->ndo_do_ioctl) + return -EOPNOTSUPP; + + ret = dev->netdev_ops->ndo_do_ioctl(dev, (struct ifreq *)&req, + SIOCPNGAUTOCONF); + if (ret < 0) + return ret; + return phonet_address_add(dev, req.ifr_phonet_autoconf.device); +} + /* notify Phonet of device events */ static int phonet_device_notify(struct notifier_block *me, unsigned long what, void *arg) { struct net_device *dev = arg; - if (what == NETDEV_UNREGISTER) + switch (what) { + case NETDEV_REGISTER: + if (dev->type == ARPHRD_PHONET) + phonet_device_autoconf(dev); + break; + case NETDEV_UNREGISTER: phonet_device_destroy(dev); + break; + } return 0; }