netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Phonet: back-end for autoconfigured addresses
@ 2009-09-09 10:00 Rémi Denis-Courmont
  2009-09-09 10:00 ` [PATCH 2/2] cdc-phonet: autoconfigure Phonet address Rémi Denis-Courmont
  2009-09-11 19:38 ` [PATCH 1/2] Phonet: back-end for autoconfigured addresses David Miller
  0 siblings, 2 replies; 8+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-09 10:00 UTC (permalink / raw)
  To: netdev; +Cc: Rémi Denis-Courmont

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

In some cases, the network device driver knows what layer-3 address the
device should have. This adds support for the Phonet stack to
automatically request from the driver and add that address to the
network device.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/linux/phonet.h |   17 +++++++++++++++++
 net/phonet/pn_dev.c    |   26 +++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletions(-)

diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index ee5e3c9..82b45d1 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 5ae4c01..2f65dca 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -28,6 +28,7 @@
 #include <linux/netdevice.h>
 #include <linux/phonet.h>
 #include <linux/proc_fs.h>
+#include <linux/if_arp.h>
 #include <net/sock.h>
 #include <net/netns/generic.h>
 #include <net/phonet/pn_dev.h>
@@ -195,14 +196,37 @@ found:
 	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;
 
 }
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-09 10:00 [PATCH 1/2] Phonet: back-end for autoconfigured addresses Rémi Denis-Courmont
@ 2009-09-09 10:00 ` Rémi Denis-Courmont
  2009-09-09 10:24   ` Marcel Holtmann
  2009-09-11 19:38   ` David Miller
  2009-09-11 19:38 ` [PATCH 1/2] Phonet: back-end for autoconfigured addresses David Miller
  1 sibling, 2 replies; 8+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-09 10:00 UTC (permalink / raw)
  To: netdev; +Cc: Rémi Denis-Courmont

From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 drivers/net/usb/cdc-phonet.c |   15 +++++++++++++++
 include/linux/phonet.h       |    3 +++
 2 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/drivers/net/usb/cdc-phonet.c b/drivers/net/usb/cdc-phonet.c
index 0ca5916..97e54d9 100644
--- a/drivers/net/usb/cdc-phonet.c
+++ b/drivers/net/usb/cdc-phonet.c
@@ -27,6 +27,7 @@
 #include <linux/netdevice.h>
 #include <linux/if_arp.h>
 #include <linux/if_phonet.h>
+#include <linux/phonet.h>
 
 #define PN_MEDIA_USB	0x1B
 
@@ -256,6 +257,19 @@ static int usbpn_close(struct net_device *dev)
 	return usb_set_interface(pnd->usb, num, !pnd->active_setting);
 }
 
+static int usbpn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
+{
+	struct if_phonet_req *req = (struct if_phonet_req *)ifr;
+
+	switch (cmd) {
+	case SIOCPNGAUTOCONF:
+		req->ifr_phonet_autoconf.device = PN_DEV_PC;
+		printk(KERN_CRIT"device is PN_DEV_PC\n");
+		return 0;
+	}
+	return -ENOIOCTLCMD;
+}
+
 static int usbpn_set_mtu(struct net_device *dev, int new_mtu)
 {
 	if ((new_mtu < PHONET_MIN_MTU) || (new_mtu > PHONET_MAX_MTU))
@@ -269,6 +283,7 @@ static const struct net_device_ops usbpn_ops = {
 	.ndo_open	= usbpn_open,
 	.ndo_stop	= usbpn_close,
 	.ndo_start_xmit = usbpn_xmit,
+	.ndo_do_ioctl	= usbpn_ioctl,
 	.ndo_change_mtu = usbpn_set_mtu,
 };
 
diff --git a/include/linux/phonet.h b/include/linux/phonet.h
index 82b45d1..1ef5a07 100644
--- a/include/linux/phonet.h
+++ b/include/linux/phonet.h
@@ -99,6 +99,9 @@ struct sockaddr_pn {
 	__u8 spn_zero[sizeof(struct sockaddr) - sizeof(sa_family_t) - 3];
 } __attribute__ ((packed));
 
+/* Well known address */
+#define PN_DEV_PC	0x10
+
 static inline __u16 pn_object(__u8 addr, __u16 port)
 {
 	return (addr << 8) | (port & 0x3ff);
-- 
1.6.0.4


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-09 10:00 ` [PATCH 2/2] cdc-phonet: autoconfigure Phonet address Rémi Denis-Courmont
@ 2009-09-09 10:24   ` Marcel Holtmann
  2009-09-09 10:28     ` Rémi Denis-Courmont
  2009-09-11 19:38   ` David Miller
  1 sibling, 1 reply; 8+ messages in thread
From: Marcel Holtmann @ 2009-09-09 10:24 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev, Rémi Denis-Courmont

Hi Remi,

>  drivers/net/usb/cdc-phonet.c |   15 +++++++++++++++
>  include/linux/phonet.h       |    3 +++
>  2 files changed, 18 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/net/usb/cdc-phonet.c b/drivers/net/usb/cdc-phonet.c
> index 0ca5916..97e54d9 100644
> --- a/drivers/net/usb/cdc-phonet.c
> +++ b/drivers/net/usb/cdc-phonet.c
> @@ -27,6 +27,7 @@
>  #include <linux/netdevice.h>
>  #include <linux/if_arp.h>
>  #include <linux/if_phonet.h>
> +#include <linux/phonet.h>
>  
>  #define PN_MEDIA_USB	0x1B
>  
> @@ -256,6 +257,19 @@ static int usbpn_close(struct net_device *dev)
>  	return usb_set_interface(pnd->usb, num, !pnd->active_setting);
>  }
>  
> +static int usbpn_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
> +{
> +	struct if_phonet_req *req = (struct if_phonet_req *)ifr;
> +
> +	switch (cmd) {
> +	case SIOCPNGAUTOCONF:
> +		req->ifr_phonet_autoconf.device = PN_DEV_PC;
> +		printk(KERN_CRIT"device is PN_DEV_PC\n");
> +		return 0;
> +	}
> +	return -ENOIOCTLCMD;
> +}
> +

am I understanding this correctly, that even for the USB ones we still
have to execute that ioctl() and can not just auto configure them all
the time? For the USB ones, I would expect to should plug them in and
they are getting configured right away.

Regards

Marcel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-09 10:24   ` Marcel Holtmann
@ 2009-09-09 10:28     ` Rémi Denis-Courmont
  2009-09-09 10:33       ` Marcel Holtmann
  0 siblings, 1 reply; 8+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-09 10:28 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: netdev


On Wed, 09 Sep 2009 12:24:10 +0200, Marcel Holtmann <marcel@holtmann.org>
wrote:
> am I understanding this correctly, that even for the USB ones we still
> have to execute that ioctl() and can not just auto configure them all
> the time? For the USB ones, I would expect to should plug them in and
> they are getting configured right away.

The other patch makes the stack use the ioctl() internally.
But now I see that I forgot some debug statement :(

Still, something needs to ifconfig up/ip link set up.

-- 
Rémi Denis-Courmont


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-09 10:28     ` Rémi Denis-Courmont
@ 2009-09-09 10:33       ` Marcel Holtmann
  0 siblings, 0 replies; 8+ messages in thread
From: Marcel Holtmann @ 2009-09-09 10:33 UTC (permalink / raw)
  To: Rémi Denis-Courmont; +Cc: netdev

Hi Remi,

> > am I understanding this correctly, that even for the USB ones we still
> > have to execute that ioctl() and can not just auto configure them all
> > the time? For the USB ones, I would expect to should plug them in and
> > they are getting configured right away.
> 
> The other patch makes the stack use the ioctl() internally.
> But now I see that I forgot some debug statement :(
> 
> Still, something needs to ifconfig up/ip link set up.

the ifup/ifdown is fine. And if the addresses get set when I plug the
device in, that looks good to me.

Regards

Marcel



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/2] Phonet: back-end for autoconfigured addresses
  2009-09-09 10:00 [PATCH 1/2] Phonet: back-end for autoconfigured addresses Rémi Denis-Courmont
  2009-09-09 10:00 ` [PATCH 2/2] cdc-phonet: autoconfigure Phonet address Rémi Denis-Courmont
@ 2009-09-11 19:38 ` David Miller
  1 sibling, 0 replies; 8+ messages in thread
From: David Miller @ 2009-09-11 19:38 UTC (permalink / raw)
  To: remi; +Cc: netdev, remi.denis-courmont

From: Rémi Denis-Courmont <remi@remlab.net>
Date: Wed,  9 Sep 2009 13:00:05 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> In some cases, the network device driver knows what layer-3 address the
> device should have. This adds support for the Phonet stack to
> automatically request from the driver and add that address to the
> network device.
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-09 10:00 ` [PATCH 2/2] cdc-phonet: autoconfigure Phonet address Rémi Denis-Courmont
  2009-09-09 10:24   ` Marcel Holtmann
@ 2009-09-11 19:38   ` David Miller
  2009-09-12  9:20     ` Rémi Denis-Courmont
  1 sibling, 1 reply; 8+ messages in thread
From: David Miller @ 2009-09-11 19:38 UTC (permalink / raw)
  To: remi; +Cc: netdev, remi.denis-courmont

From: Rémi Denis-Courmont <remi@remlab.net>
Date: Wed,  9 Sep 2009 13:00:06 +0300

> From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>

Applied.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/2] cdc-phonet: autoconfigure Phonet address
  2009-09-11 19:38   ` David Miller
@ 2009-09-12  9:20     ` Rémi Denis-Courmont
  0 siblings, 0 replies; 8+ messages in thread
From: Rémi Denis-Courmont @ 2009-09-12  9:20 UTC (permalink / raw)
  To: David Miller; +Cc: netdev

Le vendredi 11 septembre 2009 22:38:35 David Miller, vous avez écrit :
> From: Rémi Denis-Courmont <remi@remlab.net>
> Date: Wed,  9 Sep 2009 13:00:06 +0300
> 
> > From: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> >
> > Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
> 
> Applied.

THanks and oops, I just had an updated patch set coming. I guess I will rebase 
it then.

-- 
Rémi Denis-Courmont
http://www.remlab.net/

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2009-09-12  9:20 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-09 10:00 [PATCH 1/2] Phonet: back-end for autoconfigured addresses Rémi Denis-Courmont
2009-09-09 10:00 ` [PATCH 2/2] cdc-phonet: autoconfigure Phonet address Rémi Denis-Courmont
2009-09-09 10:24   ` Marcel Holtmann
2009-09-09 10:28     ` Rémi Denis-Courmont
2009-09-09 10:33       ` Marcel Holtmann
2009-09-11 19:38   ` David Miller
2009-09-12  9:20     ` Rémi Denis-Courmont
2009-09-11 19:38 ` [PATCH 1/2] Phonet: back-end for autoconfigured addresses David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).