Skip to contentSkip to conversation

Staging: Add new driver ipheth

PATCH New L. Alberto Giménez 9 participants 34 messages Mar 30, 2010 – Apr 22, 2010

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Staging: Add new driver ipheth

Hi,

I'm submitting this new driver to the staging tree so it can be reviewed. I didn't write it by myself, but I've tested it and it works just fine (at least with a 3G iPhone). The original maintainers are not very responsive and the codebase has not been updated (apart from minor fixes) since January.

Anyway, before submitting it I've fixed (most) checkpatch issues. Only two over-80-characters lines issues are standing, but looking at the code it did make sense for me letting those 3-4 characters to overflow to keep the code readable.

More than that, I have no real experience with kernel programming (read LDD, articles, files inside Documentation/ directory and so), so if you see obvious bugs or something that should be fixed, please let me know with a pointer to the documentation that may help me to undertand why it's wrong and how should I fix it.

L. Alberto Giménez (1):
Staging: Add new driver ipheth

 drivers/staging/Kconfig         |    2 +
 drivers/staging/Makefile        |    1 +
 drivers/staging/ipheth/Kconfig  |   11 +
 drivers/staging/ipheth/Makefile |    1 +
 drivers/staging/ipheth/ipheth.c |  573 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 588 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ipheth/Kconfig
 create mode 100644 drivers/staging/ipheth/Makefile
 create mode 100644 drivers/staging/ipheth/ipheth.c
#1 lore raw

PATCH 1/1 Staging: Add new driver ipheth

Add new driver to use tethering with an iPhone device to the staging tree.

---
 drivers/staging/Kconfig         |    2 +
 drivers/staging/Makefile        |    1 +
 drivers/staging/ipheth/Kconfig  |   11 +
 drivers/staging/ipheth/Makefile |    1 +
 drivers/staging/ipheth/ipheth.c |  573 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 588 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/ipheth/Kconfig
 create mode 100644 drivers/staging/ipheth/Makefile
 create mode 100644 drivers/staging/ipheth/ipheth.c
drivers/staging/Kconfig +2 -0
index 7696a66..28e2191 100644
@@ -139,5 +139,7 @@ source "drivers/staging/dt3155/Kconfig"
 
 source "drivers/staging/crystalhd/Kconfig"
 
+source "drivers/staging/ipheth/Kconfig"
+
 endif # !STAGING_EXCLUDE_BUILD
 endif # STAGING
drivers/staging/Makefile +1 -0
index ea2e70e..87800f4 100644
@@ -51,3 +51,4 @@ obj-$(CONFIG_PCMCIA_NETWAVE)	+= netwave/
 obj-$(CONFIG_FB_SM7XX)		+= sm7xx/
 obj-$(CONFIG_DT3155)		+= dt3155/
 obj-$(CONFIG_CRYSTALHD)		+= crystalhd/
+obj-$(CONFIG_IPHETH)		+= ipheth/
drivers/staging/ipheth/Kconfig new file +11 -0
new file mode 100644
index 0000000..6a67c40
@@ -0,0 +1,11 @@
+config IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	depends on USB && m
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
drivers/staging/ipheth/Makefile new file +1 -0
new file mode 100644
index 0000000..f6a7ce5
@@ -0,0 +1 @@
+obj-m += ipheth.o
drivers/staging/ipheth/ipheth.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
1.7.0
#2 lore raw
Quoted 1 line · L. Alberto Gim??nez

Add new driver to use tethering with an iPhone device to the staging tree.

Why the staging tree?

What is wrong with the driver that it needs to go there and not to the main kernel tree?

Any driver added to the staging tree needs a TODO file describing what needs to be fixed with it, and who to send the patches to.

Did you write this driver? If not, please put a "From:" line that shows who did write it.

thanks,

greg k-h

#3 lore raw
Quoted 8 lines · Greg KH
Quoted 1 line · L. Alberto Gim??nez

Add new driver to use tethering with an iPhone device to the staging tree.

Why the staging tree?

What is wrong with the driver that it needs to go there and not to the main kernel tree?

Sorry, I thought that the first step was getting into staging. I ignored the fact that it needed a TODO file. I'm not either sure about where should it go since it uses the USB interface but in fact is used as a network device (drivers/net? drivers/usb?). My guess is drivers/net, but I'm pretty sure I'm wrong :)

Quoted 2 lines

Did you write this driver? If not, please put a "From:" line that shows who did write it.

Should I just add a "From: " email-like header in the patch, in the commit or in the body? I'm not sure how to do it.

Regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#4 lore raw
Quoted 11 lines · L. Alberto Gim?nez
Quoted 8 lines · Greg KH
Quoted 1 line · L. Alberto Gim??nez

Add new driver to use tethering with an iPhone device to the staging tree.

Why the staging tree?

What is wrong with the driver that it needs to go there and not to the main kernel tree?

Sorry, I thought that the first step was getting into staging.

For the majority of the drivers out there, no, this is not the first step. Especially ones as clean as this one. Staging is only for the "crap" code out there :)

Quoted 4 lines

I ignored the fact that it needed a TODO file. I'm not either sure about where should it go since it uses the USB interface but in fact is used as a network device (drivers/net? drivers/usb?). My guess is drivers/net, but I'm pretty sure I'm wrong :)

drivers/net/usb/ would be the proper place for it.

Quoted 5 lines
Quoted 2 lines

Did you write this driver? If not, please put a "From:" line that shows who did write it.

Should I just add a "From: " email-like header in the patch, in the commit or in the body? I'm not sure how to do it.

Put it as the first line of the changelog comment in the email body, and then when git applies it, the proper author will be credited.

care to try it again?

thanks,

greg k-h

#5 lore raw
In reply to L. Alberto Giménez
Quoted 3 lines · L. Alberto Gim?nez
Quoted 2 lines · Greg KH
Quoted 1 line · L. Alberto Gim??nez

Add new driver to use tethering with an iPhone device to the staging tree.

Does it work out of the box, or is it some kind of driver for jailbroken iphones?

Quoted 11 lines
Quoted 5 lines

Why the staging tree?

What is wrong with the driver that it needs to go there and not to the main kernel tree?

Sorry, I thought that the first step was getting into staging. I ignored the fact that it needed a TODO file. I'm not either sure about where should it go since it uses the USB interface but in fact is used as a network device (drivers/net? drivers/usb?). My guess is drivers/net, but I'm pretty sure I'm wrong :)

drivers/net/usb seems like a place.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#6 lore raw
Quoted 2 lines · Pavel Machek

Does it work out of the box, or is it some kind of driver for jailbroken iphones?

Works out of the box.

Signature · 1 line
Matthew Garrett | [email protected]
#7 lore raw
In reply to Pavel Machek
Quoted 7 lines · Pavel Machek
Quoted 3 lines · L. Alberto Gim?nez
Quoted 2 lines · Greg KH
Quoted 1 line · L. Alberto Gim??nez

Add new driver to use tethering with an iPhone device to the staging tree.

Does it work out of the box, or is it some kind of driver for jailbroken iphones?

Hi Pavel, it works out of the box. You need some userspace tools used also to access jailbroken devices, but this one does not need specifically that your iPhone is jailbroken (mine is not, and it works perfectly).

Regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#8 lore raw

PATCH 1/1 drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: Diego Giagio <[email protected]>

Add new driver to use tethering with an iPhone device to the staging tree.

---
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  573 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 586 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/ipheth.c
drivers/net/usb/Kconfig +12 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET
 	  cellular modem, as found on most Nokia handsets with the
 	  "PC suite" USB profile.
 
+config USB_IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	default n
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+
 endmenu
drivers/net/usb/Makefile +1 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 
drivers/net/usb/ipheth.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
1.7.0
#9 lore raw

Re: [PATCH] drivers/net/usb: Add new driver ipheth

On Wed, Mar 31, 2010 at 01:01:38AM +0200, L. Alberto Gim??nez wrote:

Patches sent to drivers/net/usb/ need to be sent to the correct people.

Run scripts/get_maintainer.pl to determine who that is (and the proper list to send them to.)

thanks,

greg k-h

#10 lore raw

PATCH v3 1/1 drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: Diego Giagio <[email protected]>

Add new driver to use tethering with an iPhone device.

---
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  573 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 586 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/ipheth.c
drivers/net/usb/Kconfig +12 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET
 	  cellular modem, as found on most Nokia handsets with the
 	  "PC suite" USB profile.
 
+config USB_IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	default n
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+
 endmenu
drivers/net/usb/Makefile +1 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 
drivers/net/usb/ipheth.c new file +573 -0

573 lines not on this page · raw message

Signature · 1 line
1.7.0
#11 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Am Mittwoch, 31. März 2010 21:42:07 schrieb L. Alberto Giménez:

Hi,

a few comments below.

Regards
Oliver

drivers/net/usb/ipheth.c line 85

Quoted 5 lines
drivers/net/usb/ipheth.c new file +5 -0
+
+static struct usb_device_id ipheth_table[] = {
+	{ USB_DEVICE(USB_VENDOR_APPLE, USB_PRODUCT_IPHETH) },
+	{ USB_DEVICE(USB_VENDOR_APPLE, USB_PRODUCT_IPHETH_3G) },
+	{ USB_DEVICE(USB_VENDOR_APPLE, USB_PRODUCT_IPHETH_3GS) },

Please use the macros specifying the interface.

drivers/net/usb/ipheth.c

Quoted 6 lines
drivers/net/usb/ipheth.c new file +4 -0
+	{ }
+};
+MODULE_DEVICE_TABLE(usb, ipheth_table);
 
 
+static void ipheth_unlink_urbs(struct ipheth_device *dev)

The naming might be misleading.

Quoted 12 lines
drivers/net/usb/ipheth.c new file +11 -0
+{
+	usb_kill_urb(dev->tx_urb);
+	usb_kill_urb(dev->rx_urb);
+}
 
+
+static void ipheth_sndbulk_callback(struct urb *urb)
+{
+	struct ipheth_device *dev;
+
+	dev = urb->context;
+	if (dev == NULL)

drivers/net/usb/ipheth.c line 232

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+		return;
+
+	if (urb->status != 0 &&
+	    urb->status != -ENOENT &&
+	    urb->status != -ECONNRESET &&
+	    urb->status != -ESHUTDOWN)
+		err("%s: urb status: %d", __func__, urb->status);
+
+	netif_wake_queue(dev->net);
+	dev_kfree_skb_irq(dev->tx_skb);

Race condition. You must free the skb before you wake the queue.

drivers/net/usb/ipheth.c line 325

Quoted 12 lines
drivers/net/usb/ipheth.c new file +11 -0
+}
 
+
+static int ipheth_open(struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
+	struct usb_device *udev = dev->udev;
+	int retval = 0;
+
+	usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
+	usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->bulk_in));
+	usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->bulk_out));

Is this really needed? If so, please add a comment.

drivers/net/usb/ipheth.c line 335

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+
+	retval = ipheth_carrier_set(dev);
+	if (retval)
+		goto error;
+
+	retval = ipheth_rx_submit(dev, GFP_KERNEL);
+	if (retval)
+		goto error;
+
+	schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);

Does it make sense to start rx while you have no carrier?

Quoted 11 lines
drivers/net/usb/ipheth.c new file +10 -0
+	netif_start_queue(net);
+error:
+	return retval;
+}
 
+static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
+	struct usb_device *udev = dev->udev;
+	int retval;
+

drivers/net/usb/ipheth.c line 365

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+	/* Paranoid */
+	if (skb->len > IPHETH_BUF_SIZE) {
+		err("%s: skb too large: %d bytes", __func__, skb->len);
+		dev->stats.tx_dropped++;
+		dev_kfree_skb_irq(skb);
+		goto exit;
+	}
+
+	memset(dev->tx_buf, 0, IPHETH_BUF_SIZE);
+	memcpy(dev->tx_buf, skb->data, skb->len);

a bit wasteful

Quoted 5 lines
drivers/net/usb/ipheth.c new file +5 -0
+static int ipheth_probe(struct usb_interface *intf,
+			 const struct usb_device_id *id)
+{
+	struct usb_device *udev = interface_to_usbdev(intf);
+	struct usb_host_interface *hintf;

drivers/net/usb/ipheth.c line 440

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+	struct usb_endpoint_descriptor *endp;
+	struct ipheth_device *dev;
+	struct net_device *netdev;
+	int i;
+	int retval;
+
+	/* Ensure we are probing the right interface */
+	if (intf->cur_altsetting->desc.bInterfaceClass != IPHETH_USBINTF_CLASS ||
+	    intf->cur_altsetting->desc.bInterfaceSubClass != IPHETH_USBINTF_SUBCLASS)
+		return -ENODEV;

Please use the correct macro to specify the interface you are interested in

drivers/net/usb/ipheth.c line 532

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static void ipheth_disconnect(struct usb_interface *intf)
+{
+	struct ipheth_device *dev;
+
+	dev = usb_get_intfdata(intf);
+	if (dev != NULL) {

is this check needed?

drivers/net/usb/ipheth.c line 548

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static struct usb_driver ipheth_driver = {
+	.name =		"ipheth",
+	.probe =	ipheth_probe,
+	.disconnect =	ipheth_disconnect,
+	.id_table =	ipheth_table,
+	.supports_autosuspend = 0,

redundant

#12 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 5 lines · Oliver Neukum

Am Mittwoch, 31. März 2010 21:42:07 schrieb L. Alberto Giménez:

Hi,

a few comments below.

Hi Oliver,

I'll try to fix all the problems that you spotted as soon as I know how to do that (documentation pointers more than the obvious ones are welcome). In the meantime, please be patient :)

Regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#13 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

In reply to Oliver Neukum
Quoted 1 line · Oliver Neukum

Am Mittwoch, 31. März 2010 21:42:07 schrieb L. Alberto Giménez:

Hi Oliver,

Just like with Ben's comments I still have a couple of doubts about your comments.

Quoted 4 lines
Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+
+static int ipheth_open(struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
Quoted 8 lines

drivers/net/usb/ipheth.c line 325

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+	struct usb_device *udev = dev->udev;
+	int retval = 0;
+
+	usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
+	usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->bulk_in));
+	usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->bulk_out));

Is this really needed? If so, please add a comment.

I understand that usb_clear_halt is only needed when the device has transmitted data, and as it is "open" time, we can assume that no transmissions ere made, so we don't need to clear anything (aka: remove both lines), am I right?

Quoted 4 lines
Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+
+	retval = ipheth_carrier_set(dev);
+	if (retval)
+		goto error;
Quoted 8 lines

drivers/net/usb/ipheth.c line 335

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+
+	retval = ipheth_rx_submit(dev, GFP_KERNEL);
+	if (retval)
+		goto error;
+
+	schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);

Does it make sense to start rx while you have no carrier?

Well, I have no clue about this one. I think that upstream developers should take a look into this (Dario, Daniel, could you?) since I don't have the knowledge to decide what to do about it.

But I assume that as with the previous one, we have just opened the device and we aren't (yet) doing anything with it, so we shouldn't start rx?

Quoted 8 lines

drivers/net/usb/ipheth.c line 532

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static void ipheth_disconnect(struct usb_interface *intf)
+{
+	struct ipheth_device *dev;
+
+	dev = usb_get_intfdata(intf);
+	if (dev != NULL) {

is this check needed?

Does usb_get_infdata always return not NULL? I haven't found anything about it (just manual pages for the function, but can't spot if it cannot return NULL). We disconnected the device, but I understand that the kernel still has the information and the allocated memory, so the cleanup code is still needed, isn't it?

Quoted 9 lines

drivers/net/usb/ipheth.c line 548

Quoted 7 lines
drivers/net/usb/ipheth.c new file +6 -0
+static struct usb_driver ipheth_driver = {
+	.name =		"ipheth",
+	.probe =	ipheth_probe,
+	.disconnect =	ipheth_disconnect,
+	.id_table =	ipheth_table,
+	.supports_autosuspend = 0,

redundant

Why?

Thanks a lot in advance.

Best regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#14 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Am Freitag, 2. April 2010 20:23:21 schrieb L. Alberto Giménez:

Quoted 22 lines · Oliver Neukum
Quoted 1 line

Am Mittwoch, 31. März 2010 21:42:07 schrieb L. Alberto Giménez:

Hi Oliver,

Just like with Ben's comments I still have a couple of doubts about your comments.

Quoted 4 lines
Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+
+static int ipheth_open(struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
Quoted 8 lines

drivers/net/usb/ipheth.c line 325

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+	struct usb_device *udev = dev->udev;
+	int retval = 0;
+
+	usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
+	usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->bulk_in));
+	usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->bulk_out));

Is this really needed? If so, please add a comment.

Quoted 4 lines

I understand that usb_clear_halt is only needed when the device has transmitted data, and as it is "open" time, we can assume that no transmissions ere made, so we don't need to clear anything (aka: remove both lines), am I right?

Clearing a halt is necessary only when a device has stalled due to an error condition. Unless the device is buggy and produces errors for no good reason you don't need these lines.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+
+	retval = ipheth_carrier_set(dev);
+	if (retval)
+		goto error;
Quoted 8 lines

drivers/net/usb/ipheth.c line 335

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+
+	retval = ipheth_rx_submit(dev, GFP_KERNEL);
+	if (retval)
+		goto error;
+
+	schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);

Does it make sense to start rx while you have no carrier?

Quoted 6 lines

Well, I have no clue about this one. I think that upstream developers should take a look into this (Dario, Daniel, could you?) since I don't have the knowledge to decide what to do about it.

But I assume that as with the previous one, we have just opened the device and we aren't (yet) doing anything with it, so we shouldn't start rx?

Your code as is is correct, I just wondered whether it could be made more efficient.

Quoted 10 lines
Quoted 8 lines

drivers/net/usb/ipheth.c line 532

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static void ipheth_disconnect(struct usb_interface *intf)
+{
+	struct ipheth_device *dev;
+
+	dev = usb_get_intfdata(intf);
+	if (dev != NULL) {

is this check needed?

Does usb_get_infdata always return not NULL? I haven't found anything

It returns what you gave it with usb_set_intfdata().

Quoted 4 lines

about it (just manual pages for the function, but can't spot if it cannot return NULL). We disconnected the device, but I understand that the kernel still has the information and the allocated memory, so the cleanup code is still needed, isn't it?

It is definitely needed.

Quoted 10 lines
Quoted 8 lines

drivers/net/usb/ipheth.c line 548

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static struct usb_driver ipheth_driver = {
+	.name =		"ipheth",
+	.probe =	ipheth_probe,
+	.disconnect =	ipheth_disconnect,
+	.id_table =	ipheth_table,
+	.supports_autosuspend = 0,

redundant

Why?

0 is the default.

Regards
Oliver

#15 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 10 lines · Oliver Neukum

Am Freitag, 2. April 2010 20:23:21 schrieb L. Alberto Giménez:

Quoted 9 lines · Oliver Neukum
Quoted 8 lines

Am Mittwoch, 31. März 2010 21:42:07 schrieb L. Alberto Giménez:

drivers/net/usb/ipheth.c line 548

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+static struct usb_driver ipheth_driver = {
+	.name =		"ipheth",
+	.probe =	ipheth_probe,
+	.disconnect =	ipheth_disconnect,
+	.id_table =	ipheth_table,
+	.supports_autosuspend = 0,

redundant

Quoted 3 lines
Quoted 1 line

Why?

0 is the default.

Heh, I thought that you meant that the whole struct was redundant, and that puzzled me a little bit. Now everything is clear (my fault for not realizing the redundant initialization to 0).

Regards,

Signature · 7 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#16 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Giménez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

drivers/net/usb/ipheth.c line 54

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/uaccess.h>

I don't think you need this header.

drivers/net/usb/ipheth.c line 61

Quoted 7 lines
drivers/net/usb/ipheth.c new file +7 -0
+#include <linux/usb.h>
+#include <linux/workqueue.h>
+
+#define USB_VENDOR_APPLE        0x05ac
+#define USB_PRODUCT_IPHETH     0x1290
+#define USB_PRODUCT_IPHETH_3G   0x1292
+#define USB_PRODUCT_IPHETH_3GS  0x1294

Apple doesn't assign device ids to ipheth so either the names are incorrect or you should get proper device ids. I believe the Linux Foundation has a USB vendor id and could assign device ids under that.

drivers/net/usb/ipheth.c line 94

Quoted 5 lines
drivers/net/usb/ipheth.c new file +5 -0
+struct ipheth_device {
+	struct usb_device *udev;
+	struct usb_interface *intf;
+	struct net_device *net;
+	struct net_device_stats stats;

You can store stats in the net_device.

drivers/net/usb/ipheth.c line 102

Quoted 8 lines
drivers/net/usb/ipheth.c new file +8 -0
+	struct sk_buff *tx_skb;
+	struct urb *tx_urb;
+	struct urb *rx_urb;
+	unsigned char *tx_buf;
+	unsigned char *rx_buf;
+	unsigned char *ctrl_buf;
+	__u8 bulk_in;
+	__u8 bulk_out;

No need for the double-underscores; that's a convention for use in definitions shared with user-space.

Quoted 2 lines
drivers/net/usb/ipheth.c new file +2 -0
+	struct delayed_work carrier_work;
+};

[...]

Quoted 13 lines
drivers/net/usb/ipheth.c new file +13 -0
+static int ipheth_open(struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
+	struct usb_device *udev = dev->udev;
+	int retval = 0;
+
+	usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
+	usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->bulk_in));
+	usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->bulk_out));
+
+	retval = ipheth_carrier_set(dev);
+	if (retval)
+		goto error;

drivers/net/usb/ipheth.c line 339

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+
+	retval = ipheth_rx_submit(dev, GFP_KERNEL);
+	if (retval)
+		goto error;
+
+	schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
+	netif_start_queue(net);
+error:
+	return retval;
+}

There is no cleanup here (and none appears to be needed) so you could take out the label and replace the gotos with returns.

drivers/net/usb/ipheth.c line 362

Quoted 13 lines
drivers/net/usb/ipheth.c new file +13 -0
+static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
+{
+	struct ipheth_device *dev = netdev_priv(net);
+	struct usb_device *udev = dev->udev;
+	int retval;
+
+	/* Paranoid */
+	if (skb->len > IPHETH_BUF_SIZE) {
+		err("%s: skb too large: %d bytes", __func__, skb->len);
+		dev->stats.tx_dropped++;
+		dev_kfree_skb_irq(skb);
+		goto exit;
+	}

Use WARN here as this would indicate a bug.

Again the goto is unnecessary.

drivers/net/usb/ipheth.c line 365

Quoted 2 lines
drivers/net/usb/ipheth.c new file +2 -0
+	memset(dev->tx_buf, 0, IPHETH_BUF_SIZE);
+	memcpy(dev->tx_buf, skb->data, skb->len);

This is wasteful. If you really must pad the buffer then do so, but don't clear the area that is going to be filled with real data.

Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+	usb_fill_bulk_urb(dev->tx_urb, udev,
+			  usb_sndbulkpipe(udev, dev->bulk_out),
+			  dev->tx_buf, IPHETH_BUF_SIZE,
+			  ipheth_sndbulk_callback,

drivers/net/usb/ipheth.c line 380

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+			  dev);
+	dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
+	if (retval) {
+		err("%s: usb_submit_urb: %d", __func__, retval);
+		dev->stats.tx_errors++;
+		dev_kfree_skb_irq(skb);
+	} else {
+		net->trans_start = jiffies;

No longer needed.

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+		dev->tx_skb = skb;
+
+		dev->stats.tx_packets++;
+		dev->stats.tx_bytes += skb->len;
+		netif_stop_queue(net);
+	}
+exit:
+	return NETDEV_TX_OK;
+}

[...]

drivers/net/usb/ipheth.c line 424

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#ifdef HAVE_NET_DEVICE_OPS
+static const struct net_device_ops ipheth_netdev_ops = {
+       .ndo_open = &ipheth_open,
+       .ndo_stop = &ipheth_close,
+       .ndo_start_xmit = &ipheth_tx,
+       .ndo_tx_timeout = &ipheth_tx_timeout,
+       .ndo_get_stats = &ipheth_stats,
+};
+#endif

Remove the #ifdef, there is no question whether we have net_device_ops.

Quoted 3 lines
drivers/net/usb/ipheth.c new file +3 -0
+static int ipheth_probe(struct usb_interface *intf,
+			 const struct usb_device_id *id)
+{

[...]

drivers/net/usb/ipheth.c line 454

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#ifdef HAVE_NET_DEVICE_OPS
+	netdev->netdev_ops = &ipheth_netdev_ops;
+#else /* CONFIG_COMPAT_NET_DEV_OPS */
+	netdev->open = &ipheth_open;
+	netdev->stop = &ipheth_close;
+	netdev->hard_start_xmit = &ipheth_tx;
+	netdev->tx_timeout = &ipheth_tx_timeout;
+	netdev->get_stats = &ipheth_stats;
+#endif

[...]

Similarly here.

As a general point, you should now be using netdev_err(), netdev_info(), etc. for logging messages related to net devices.

I have no idea about USB so I haven't checked the USB API usage at all.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#17 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 17 lines · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Gim??nez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

drivers/net/usb/ipheth.c line 54

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/uaccess.h>

I don't think you need this header.

Quoted 11 lines

drivers/net/usb/ipheth.c line 61

Quoted 7 lines
drivers/net/usb/ipheth.c new file +7 -0
+#include <linux/usb.h>
+#include <linux/workqueue.h>
+
+#define USB_VENDOR_APPLE        0x05ac
+#define USB_PRODUCT_IPHETH     0x1290
+#define USB_PRODUCT_IPHETH_3G   0x1292
+#define USB_PRODUCT_IPHETH_3GS  0x1294

Apple doesn't assign device ids to ipheth so either the names are incorrect or you should get proper device ids. I believe the Linux Foundation has a USB vendor id and could assign device ids under that.

You mean there is an application on the iphone that sets the device id here? I thought this was the iphone device ids already assigned to apple.

If we need a linux-specific device id, I can assign them from the Linux foundations pool of device ids, but so far I've only done that for devices that either run Linux (usb gadgets), or for the usb root hubs. But hey, if it's controlable from software, let me know and I'll dole one out. In that case, why would you need 3 different device ids?

thanks,

greg k-h

#18 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 2 lines · Greg KH
Quoted 1 line · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Gim??nez wrote:

[...]

Quoted 12 lines
Quoted 11 lines

drivers/net/usb/ipheth.c line 61

Quoted 7 lines
drivers/net/usb/ipheth.c new file +7 -0
+#include <linux/usb.h>
+#include <linux/workqueue.h>
+
+#define USB_VENDOR_APPLE        0x05ac
+#define USB_PRODUCT_IPHETH     0x1290
+#define USB_PRODUCT_IPHETH_3G   0x1292
+#define USB_PRODUCT_IPHETH_3GS  0x1294

Apple doesn't assign device ids to ipheth so either the names are incorrect or you should get proper device ids. I believe the Linux Foundation has a USB vendor id and could assign device ids under that.

Quoted 3 lines

You mean there is an application on the iphone that sets the device id here? I thought this was the iphone device ids already assigned to apple.

[...]

That's why my first suggestion was that the names are incorrect; they should probably include IPHONE not IPHETH.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#19 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

In reply to Ben Hutchings
Quoted 5 lines · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Giménez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

Hi Ben,

Upstream has fixed several errors pointed out by you and Oliver (thanks for that), but some of them are still pending.

I will send patches on top of my last driver submission (if the proper way would be resubmit the whole code, please tell me. Anyway I need to clarify some doubts...

Quoted 8 lines
Quoted 8 lines
drivers/net/usb/ipheth.c new file +8 -0
+	usb_fill_bulk_urb(dev->tx_urb, udev,
+			  usb_sndbulkpipe(udev, dev->bulk_out),
+			  dev->tx_buf, IPHETH_BUF_SIZE,
+			  ipheth_sndbulk_callback,
+			  dev);
+	dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
Quoted 8 lines

drivers/net/usb/ipheth.c line 380

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+	if (retval) {
+		err("%s: usb_submit_urb: %d", __func__, retval);
+		dev->stats.tx_errors++;
+		dev_kfree_skb_irq(skb);
+	} else {
+		net->trans_start = jiffies;

No longer needed.

What is not longer needed? The assignment, the whole "else" branch? If the assignment is what is not needed, can I just remove that line, right?

Quoted 12 lines

[...]

drivers/net/usb/ipheth.c line 424

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#ifdef HAVE_NET_DEVICE_OPS
+static const struct net_device_ops ipheth_netdev_ops = {
+       .ndo_open = &ipheth_open,
+       .ndo_stop = &ipheth_close,
+       .ndo_start_xmit = &ipheth_tx,
+       .ndo_tx_timeout = &ipheth_tx_timeout,
+       .ndo_get_stats = &ipheth_stats,
+};
+#endif

Remove the #ifdef, there is no question whether we have net_device_ops.

Ok, I will just remove both #ifdefs, but why is that? Maybe in previous versions of the kernel the net_device_ops struct was introduced and now it's present no matter how you configure your kernel?

Quoted 1 line

I have no idea about USB so I haven't checked the USB API usage at all.

I think that Greg is the maintainer for the USB subsystem, so if he has no further commets, I will try to submit fixes for both your and Oliver's comments along with the upstream developers.

Thanks for your comments.

Best regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#20 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 7 lines · L. Alberto Giménez
Quoted 5 lines · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Giménez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

Quoted 8 lines

Hi Ben,

Upstream has fixed several errors pointed out by you and Oliver (thanks for that), but some of them are still pending.

I will send patches on top of my last driver submission (if the proper way would be resubmit the whole code, please tell me. Anyway I need to clarify some doubts...

Since David Miller has not merged your original patch, you should send a single new patch with the changes incorporated.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
drivers/net/usb/ipheth.c new file +8 -0
+	usb_fill_bulk_urb(dev->tx_urb, udev,
+			  usb_sndbulkpipe(udev, dev->bulk_out),
+			  dev->tx_buf, IPHETH_BUF_SIZE,
+			  ipheth_sndbulk_callback,
+			  dev);
+	dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
Quoted 8 lines

drivers/net/usb/ipheth.c line 380

Quoted 6 lines
drivers/net/usb/ipheth.c new file +6 -0
+	if (retval) {
+		err("%s: usb_submit_urb: %d", __func__, retval);
+		dev->stats.tx_errors++;
+		dev_kfree_skb_irq(skb);
+	} else {
+		net->trans_start = jiffies;

No longer needed.

Quoted 2 lines

What is not longer needed? The assignment, the whole "else" branch? If the assignment is what is not needed, can I just remove that line, right?

The assignment is not needed.

Quoted 13 lines
Quoted 12 lines

[...]

drivers/net/usb/ipheth.c line 424

Quoted 9 lines
drivers/net/usb/ipheth.c new file +9 -0
+#ifdef HAVE_NET_DEVICE_OPS
+static const struct net_device_ops ipheth_netdev_ops = {
+       .ndo_open = &ipheth_open,
+       .ndo_stop = &ipheth_close,
+       .ndo_start_xmit = &ipheth_tx,
+       .ndo_tx_timeout = &ipheth_tx_timeout,
+       .ndo_get_stats = &ipheth_stats,
+};
+#endif

Remove the #ifdef, there is no question whether we have net_device_ops.

Quoted 3 lines

Ok, I will just remove both #ifdefs, but why is that? Maybe in previous versions of the kernel the net_device_ops struct was introduced and now it's present no matter how you configure your kernel?

[...]

Correct, it is now mandatory.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#21 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 22 lines · Ben Hutchings
Quoted 21 lines · L. Alberto Giménez
Quoted 20 lines · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Giménez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+	usb_fill_bulk_urb(dev->tx_urb, udev,
+			  usb_sndbulkpipe(udev, dev->bulk_out),
+			  dev->tx_buf, IPHETH_BUF_SIZE,
+			  ipheth_sndbulk_callback,

drivers/net/usb/ipheth.c line 380

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+			  dev);
+	dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
+	if (retval) {
+		err("%s: usb_submit_urb: %d", __func__, retval);
+		dev->stats.tx_errors++;
+		dev_kfree_skb_irq(skb);
+	} else {
+		net->trans_start = jiffies;

No longer needed.

Quoted 4 lines
Quoted 2 lines

What is not longer needed? The assignment, the whole "else" branch? If the assignment is what is not needed, can I just remove that line, right?

The assignment is not needed.

Hi,

I've been looking into this and it seems that the net_device.trans_start field is now deprecated in favor of net_device.rx_queue.trans_start -rx_queue is a struct netdev_queue- (file include/linux/netdevice.h), as states the comment:

512 /*
513 * please use this field instead of dev->trans_start
514 */
515 unsigned long trans_start;

Reading LDD3 book, it says that the driver is reponsible for updating trans_start (as well as trans_rx, but we're not talking about that one).

So, I guess that the LDD book is outdated (again ;) ), but what I don't understand at all is wether the driver should keep updating the right field (dev->rx_queue.trans_start) or if the fact that it's inside a "queue" implies that the code that is responsible for that queue would update the trans_start field by itself?

Thanks in advance.

Best regards,

Signature · 3 lines
L. Alberto Giménez
JabberID [email protected]
GnuPG key ID 0x3BAABDE1
#22 lore raw

Re: [PATCHv3] drivers/net/usb: Add new driver ipheth

Quoted 26 lines · L. Alberto Giménez
Quoted 25 lines · Ben Hutchings
Quoted 23 lines · L. Alberto Giménez
Quoted 5 lines · Ben Hutchings

On Wed, 2010-03-31 at 21:42 +0200, L. Alberto Giménez wrote:
[...]

Quoted 2 lines
drivers/net/usb/ipheth.c new file +0 -0

[...]

Quoted 15 lines
Quoted 4 lines
drivers/net/usb/ipheth.c new file +4 -0
+	usb_fill_bulk_urb(dev->tx_urb, udev,
+			  usb_sndbulkpipe(udev, dev->bulk_out),
+			  dev->tx_buf, IPHETH_BUF_SIZE,
+			  ipheth_sndbulk_callback,

drivers/net/usb/ipheth.c line 380

Quoted 10 lines
drivers/net/usb/ipheth.c new file +10 -0
+			  dev);
+	dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+	retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
+	if (retval) {
+		err("%s: usb_submit_urb: %d", __func__, retval);
+		dev->stats.tx_errors++;
+		dev_kfree_skb_irq(skb);
+	} else {
+		net->trans_start = jiffies;

No longer needed.

What is not longer needed? The assignment, the whole "else" branch? If the assignment is what is not needed, can I just remove that line, right?

Quoted 6 lines
Quoted 1 line

The assignment is not needed.

Hi,

I've been looking into this and it seems that the net_device.trans_start field is now deprecated in favor of net_device.rx_queue.trans_start

[...]

The networking core updates netdev_queue::trans_start by calling txq_trans_update() where necessary. Drivers should not touch either net_device::trans_start or netdev_queue::trans_start any more.

Ben.

Signature · 8 lines
Ben Hutchings, Senior Software Engineer, Solarflare Communications
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#23 lore raw

PATCH 1/1 drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: [email protected]

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

---
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  562 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 575 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/ipheth.c
drivers/net/usb/Kconfig +12 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET
 	  cellular modem, as found on most Nokia handsets with the
 	  "PC suite" USB profile.
 
+config USB_IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	default n
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+
 endmenu
drivers/net/usb/Makefile +1 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 
drivers/net/usb/ipheth.c new file +562 -0

562 lines not on this page · raw message

Signature · 1 line
1.7.0
#24 lore raw

Re: [PATCH Resubmission] drivers/net/usb: Add new driver ipheth

These are a few of the cosmetic issues alluded to, and by no means merge blockers, but:

Review

Quoted 1 line
(quoted diff) +1 -0
+	schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);

Seems this might as well be round_jiffies_relative(IPHETH_CARRIER_CHECK_TIMEOUT) to avoid extra wakeups.

drivers/net/usb/ipheth.c line 440

Quoted 1 line
drivers/net/usb/ipheth.c new file +1 -0
+	netdev = alloc_etherdev(sizeof(struct ipheth_device));

This means that the interface will get an ethX name and look to networkmanager et al like an ethernet device. Seems we would maybe want to make this a "wwan" type device (cf drivers/net/usb/usbnet.c and how it handles FLAG_WWAN)?

- R.

Signature · 2 lines
Roland Dreier <[email protected]> || For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
#25 lore raw

Re: [PATCH Resubmission] drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

Am Donnerstag, 8. April 2010 00:11:20 schrieb L. Alberto Giménez:

Quoted 2 lines

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

Looks good to me.

Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#26 lore raw

Re: [PATCH Resubmission] drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: L. Alberto Giménez <[email protected]>
Date: Thu, 8 Apr 2010 00:11:20 +0200

Quoted 9 lines

From: [email protected]

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

I can't apply this.

Unless you add a rule to drivers/net/Makefile, the build won't actually get to your driver unless one of the other USB networking devices are configured.

Please fix this up and resubmit.

#27 lore raw

Re: [PATCH Resubmission] drivers/net/usb: Add new driver ipheth

Quoted 4 lines · David Miller

Unless you add a rule to drivers/net/Makefile, the build won't actually get to your driver unless one of the other USB networking devices are configured.

Hi David,

Thanks for the info. I didn't know that I had to add an entry on the upper level Makefile. I guess that something like obj-$(CONFIG_USB_IPHETH) += usb/ should be enough? (I got it from the other USB net drivers).

I won't be able to work on it today, I've been very busy today and can't look into this, but I've not given up :)

Quoted 1 line

Please fix this up and resubmit.

I have also in my queue a patch sent from upstream to fix the latest issues pointed out by Roland Dreier, and I need to test it a little bit more.

Thanks for your comments and patience!

Best regards,
L. Alberto Giménez

maintainer
#28 lore raw

Re: [PATCH Resubmission] drivers/net/usb: Add new driver ipheth

From: "L. Alberto Giménez" <[email protected]>
Date: Tue, 13 Apr 2010 21:03:25 +0200

Quoted 4 lines

Thanks for the info. I didn't know that I had to add an entry on the upper level Makefile. I guess that something like obj-$(CONFIG_USB_IPHETH) += usb/ should be enough? (I got it from the other USB net drivers).

Yes.

#29 lore raw

PATCH v2 1/1 drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: [email protected]

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

---
 drivers/net/Makefile     |    1 +
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  568 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 582 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/ipheth.c
drivers/net/Makefile +1 -0
index a583b50..12b280a 100644
@@ -273,6 +273,7 @@ obj-$(CONFIG_USB_RTL8150)       += usb/
 obj-$(CONFIG_USB_HSO)		+= usb/
 obj-$(CONFIG_USB_USBNET)        += usb/
 obj-$(CONFIG_USB_ZD1201)        += usb/
+obj-$(CONFIG_USB_IPHETH)        += usb/
 
 obj-y += wireless/
 obj-$(CONFIG_NET_TULIP) += tulip/
drivers/net/usb/Kconfig +12 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET
 	  cellular modem, as found on most Nokia handsets with the
 	  "PC suite" USB profile.
 
+config USB_IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	default n
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+
 endmenu
drivers/net/usb/Makefile +1 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 
drivers/net/usb/ipheth.c new file +568 -0

568 lines not on this page · raw message

Signature · 1 line
1.7.0
maintainer
#30 lore raw

Re: [PATCH Resubmission v2] drivers/net/usb: Add new driver ipheth

From: L. Alberto Giménez <[email protected]>
Date: Thu, 15 Apr 2010 21:46:29 +0200

Quoted 9 lines

From: [email protected]

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

I'm very confused about the authorship of this driver.

Who wrote it?

You added a "From: " line using specifying Daniel Borca (btw, when you add these "From: " lines you need to specify it in the form "From: NAME <EMAIL>" not just "From: EMAIL" so in this case we want to see "From: Daniel Borca <[email protected]>")

The code itself gives copyright to Diego Giagio <[email protected]> and he is also the one listed in the MODULE_AUTHOR().

And you're the one submitting the code, and also the only person actually giving a signoff in the commit message.

It's too confusing and ambiguous, and if there are any problems down the road the last thing we need is for the authorship to be ambiguous.

I would really appreciate it if the authorship was clearly stated, and the actual author of the code actually gives a "Signed-off-by: " line in the commit message for this inclusions of this driver.

Please fix this up and resubmit, thank you.

Thanks.

#31 lore raw

PATCH 1/1 drivers/net/usb: Add new driver ipheth

In reply to L. Alberto Giménez

From: Diego Giagio <[email protected]>

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

---
This time I've cleared the authorship as requested by David. Diego is the original author of the code, although Daniel Borca has contributed a lot of changes as well (I did the kernel-tree integration and fixed checkpatch issues as well as some of the problems pointed out in the list on previous submissions).

Diego and/or Daniel: please sign-off (specially Diego since he is the one who will be officially attributed as the driver author) this patch so the authorship and DCO is clear.

 drivers/net/Makefile     |    1 +
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  568 ++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 582 insertions(+), 0 deletions(-)
 create mode 100644 drivers/net/usb/ipheth.c
drivers/net/Makefile +1 -0
index a583b50..12b280a 100644
@@ -273,6 +273,7 @@ obj-$(CONFIG_USB_RTL8150)       += usb/
 obj-$(CONFIG_USB_HSO)		+= usb/
 obj-$(CONFIG_USB_USBNET)        += usb/
 obj-$(CONFIG_USB_ZD1201)        += usb/
+obj-$(CONFIG_USB_IPHETH)        += usb/
 
 obj-y += wireless/
 obj-$(CONFIG_NET_TULIP) += tulip/
drivers/net/usb/Kconfig +12 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET
 	  cellular modem, as found on most Nokia handsets with the
 	  "PC suite" USB profile.
 
+config USB_IPHETH
+	tristate "Apple iPhone USB Ethernet driver"
+	default n
+	---help---
+	  Module used to share Internet connection (tethering) from your
+	  iPhone (Original, 3G and 3GS) to your system.
+	  Note that you need userspace libraries and programs that are needed
+	  to pair your device with your system and that understand the iPhone
+	  protocol.
+
+	  For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+
 endmenu
drivers/net/usb/Makefile +1 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830)	+= mcs7830.o
 obj-$(CONFIG_USB_USBNET)	+= usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)	+= int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)	+= cdc-phonet.o
+obj-$(CONFIG_USB_IPHETH)	+= ipheth.o
 
drivers/net/usb/ipheth.c new file +568 -0

568 lines not on this page · raw message

Signature · 6 lines
1.7.0

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#32 lore raw

Re: [PATCH] drivers/net/usb: Add new driver ipheth

Quoted 8 lines · L. Alberto Giménez

From: Diego Giagio <[email protected]>

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

Quoted 629 lines

 drivers/net/Makefile     |    1 +
 drivers/net/usb/Kconfig  |   12 +
 drivers/net/usb/Makefile |    1 +
 drivers/net/usb/ipheth.c |  568 ++++++++++++++++++++++++++++++++++++++++++++++

 4 files changed, 582 insertions(+), 0 deletions(-)

 create mode 100644 drivers/net/usb/ipheth.c

drivers/net/Makefile +0 -0
index a583b50..12b280a 100644
@@ -273,6 +273,7 @@ obj-$(CONFIG_USB_RTL8150)       += usb/

 obj-$(CONFIG_USB_HSO)          += usb/
 obj-$(CONFIG_USB_USBNET)        += usb/
 obj-$(CONFIG_USB_ZD1201)        += usb/
+obj-$(CONFIG_USB_IPHETH)        += usb/

 obj-y += wireless/
 obj-$(CONFIG_NET_TULIP) += tulip/

drivers/net/usb/Kconfig +0 -0
index ba56ce4..63be4ca 100644
@@ -385,4 +385,16 @@ config USB_CDC_PHONET

         cellular modem, as found on most Nokia handsets with the "PC suite" USB profile.

drivers/net/usb/Kconfig +12 -0
+config USB_IPHETH
+       tristate "Apple iPhone USB Ethernet driver"
+       default n
+       ---help---
+         Module used to share Internet connection (tethering) from your
+         iPhone (Original, 3G and 3GS) to your system.
+         Note that you need userspace libraries and programs that are needed
+         to pair your device with your system and that understand the iPhone
+         protocol.
+
+         For more information: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+

 endmenu

drivers/net/usb/Makefile +0 -0
index 82ea629..edb09c0 100644
@@ -23,4 +23,5 @@ obj-$(CONFIG_USB_NET_MCS7830) += mcs7830.o

 obj-$(CONFIG_USB_USBNET)       += usbnet.o
 obj-$(CONFIG_USB_NET_INT51X1)  += int51x1.o
 obj-$(CONFIG_USB_CDC_PHONET)   += cdc-phonet.o

drivers/net/usb/Makefile +1 -0
+obj-$(CONFIG_USB_IPHETH)       += ipheth.o
drivers/net/usb/ipheth.c new file +568 -1
new file mode 100644
index 0000000..fd10331
@@ -0,0 +1,568 @@
+/*
+ * ipheth.c - Apple iPhone USB Ethernet driver
+ *
+ * Copyright (c) 2009 Diego Giagio <[email protected]>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of GIAGIO.COM nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * Alternatively, provided that this notice is retained in full, this
+ * software may be distributed under the terms of the GNU General
+ * Public License ("GPL") version 2, in which case the provisions of the
+ * GPL apply INSTEAD OF those given above.
+ *
+ * The provided data structures and external interfaces from this code
+ * are not restricted to be used by modules with a GPL compatible license.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
+ *
+ *
+ * Attention: iPhone device must be paired, otherwise it won't respond to our
+ * driver. For more info: http://giagio.com/wiki/moin.cgi/iPhoneEthernetDriver
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/errno.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/module.h>
+#include <linux/netdevice.h>
+#include <linux/etherdevice.h>
+#include <linux/ethtool.h>
+#include <linux/usb.h>
+#include <linux/workqueue.h>
+
+#define USB_VENDOR_APPLE        0x05ac
+#define USB_PRODUCT_IPHONE      0x1290
+#define USB_PRODUCT_IPHONE_3G   0x1292
+#define USB_PRODUCT_IPHONE_3GS  0x1294
+
+#define IPHETH_USBINTF_CLASS    255
+#define IPHETH_USBINTF_SUBCLASS 253
+#define IPHETH_USBINTF_PROTO    1
+
+#define IPHETH_BUF_SIZE         1516
+#define IPHETH_TX_TIMEOUT       (5 * HZ)
+
+#define IPHETH_INTFNUM          2
+#define IPHETH_ALT_INTFNUM      1
+
+#define IPHETH_CTRL_ENDP        0x00
+#define IPHETH_CTRL_BUF_SIZE    0x40
+#define IPHETH_CTRL_TIMEOUT     (5 * HZ)
+
+#define IPHETH_CMD_GET_MACADDR   0x00
+#define IPHETH_CMD_CARRIER_CHECK 0x45
+
+#define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
+#define IPHETH_CARRIER_ON       0x04
+
+static struct usb_device_id ipheth_table[] = {
+       { USB_DEVICE_AND_INTERFACE_INFO(
+               USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
+               IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
+               IPHETH_USBINTF_PROTO) },
+       { USB_DEVICE_AND_INTERFACE_INFO(
+               USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3G,
+               IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
+               IPHETH_USBINTF_PROTO) },
+       { USB_DEVICE_AND_INTERFACE_INFO(
+               USB_VENDOR_APPLE, USB_PRODUCT_IPHONE_3GS,
+               IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
+               IPHETH_USBINTF_PROTO) },
+       { }
+};
+MODULE_DEVICE_TABLE(usb, ipheth_table);
+
+struct ipheth_device {
+       struct usb_device *udev;
+       struct usb_interface *intf;
+       struct net_device *net;
+       struct sk_buff *tx_skb;
+       struct urb *tx_urb;
+       struct urb *rx_urb;
+       unsigned char *tx_buf;
+       unsigned char *rx_buf;
+       unsigned char *ctrl_buf;
+       u8 bulk_in;
+       u8 bulk_out;
+       struct delayed_work carrier_work;
+};
+
+static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
+
+static int ipheth_alloc_urbs(struct ipheth_device *iphone)
+{
+       struct urb *tx_urb = NULL;
+       struct urb *rx_urb = NULL;
+       u8 *tx_buf = NULL;
+       u8 *rx_buf = NULL;
+
+       tx_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (tx_urb == NULL)
+               goto error;
+
+       rx_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (rx_urb == NULL)
+               goto error;
+
+       tx_buf = usb_buffer_alloc(iphone->udev,
+                                 IPHETH_BUF_SIZE,
+                                 GFP_KERNEL,
+                                 &tx_urb->transfer_dma);
+       if (tx_buf == NULL)
+               goto error;
+
+       rx_buf = usb_buffer_alloc(iphone->udev,
+                                 IPHETH_BUF_SIZE,
+                                 GFP_KERNEL,
+                                 &rx_urb->transfer_dma);
+       if (rx_buf == NULL)
+               goto error;
+
+
+       iphone->tx_urb = tx_urb;
+       iphone->rx_urb = rx_urb;
+       iphone->tx_buf = tx_buf;
+       iphone->rx_buf = rx_buf;
+       return 0;
+
+error:
+       usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, rx_buf,
+                       rx_urb->transfer_dma);
+       usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, tx_buf,
+                       tx_urb->transfer_dma);
+       usb_free_urb(rx_urb);
+       usb_free_urb(tx_urb);
+       return -ENOMEM;
+}
+
+static void ipheth_free_urbs(struct ipheth_device *iphone)
+{
+       usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, iphone->rx_buf,
+                       iphone->rx_urb->transfer_dma);
+       usb_buffer_free(iphone->udev, IPHETH_BUF_SIZE, iphone->tx_buf,
+                       iphone->tx_urb->transfer_dma);
+       usb_free_urb(iphone->rx_urb);
+       usb_free_urb(iphone->tx_urb);
+}
+
+static void ipheth_kill_urbs(struct ipheth_device *dev)
+{
+       usb_kill_urb(dev->tx_urb);
+       usb_kill_urb(dev->rx_urb);
+}
+
+static void ipheth_rcvbulk_callback(struct urb *urb)
+{
+       struct ipheth_device *dev;
+       struct sk_buff *skb;
+       int status;
+       char *buf;
+       int len;
+
+       dev = urb->context;
+       if (dev == NULL)
+               return;
+
+       status = urb->status;
+       switch (status) {
+       case -ENOENT:
+       case -ECONNRESET:
+       case -ESHUTDOWN:
+               return;
+       case 0:
+               break;
+       default:
+               err("%s: urb status: %d", __func__, urb->status);
+               return;
+       }
+
+       len = urb->actual_length;
+       buf = urb->transfer_buffer;
+
+       skb = dev_alloc_skb(NET_IP_ALIGN + len);
+       if (!skb) {
+               err("%s: dev_alloc_skb: -ENOMEM", __func__);
+               dev->net->stats.rx_dropped++;
+               return;
+       }
+
+       skb_reserve(skb, NET_IP_ALIGN);
+       memcpy(skb_put(skb, len), buf + NET_IP_ALIGN, len - NET_IP_ALIGN);
+       skb->dev = dev->net;
+       skb->protocol = eth_type_trans(skb, dev->net);
+
+       dev->net->stats.rx_packets++;
+       dev->net->stats.rx_bytes += len;
+
+       netif_rx(skb);
+       ipheth_rx_submit(dev, GFP_ATOMIC);
+}
+
+static void ipheth_sndbulk_callback(struct urb *urb)
+{
+       struct ipheth_device *dev;
+
+       dev = urb->context;
+       if (dev == NULL)
+               return;
+
+       if (urb->status != 0 &&
+           urb->status != -ENOENT &&
+           urb->status != -ECONNRESET &&
+           urb->status != -ESHUTDOWN)
+               err("%s: urb status: %d", __func__, urb->status);
+
+       dev_kfree_skb_irq(dev->tx_skb);
+       netif_wake_queue(dev->net);
+}
+
+static int ipheth_carrier_set(struct ipheth_device *dev)
+{
+       struct usb_device *udev = dev->udev;
+       int retval;
+
+       retval = usb_control_msg(udev,
+                       usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
+                       IPHETH_CMD_CARRIER_CHECK, /* request */
+                       0xc0, /* request type */
+                       0x00, /* value */
+                       0x02, /* index */
+                       dev->ctrl_buf, IPHETH_CTRL_BUF_SIZE,
+                       IPHETH_CTRL_TIMEOUT);
+       if (retval < 0) {
+               err("%s: usb_control_msg: %d", __func__, retval);
+               return retval;
+       }
+
+       if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
+               netif_carrier_on(dev->net);
+       else
+               netif_carrier_off(dev->net);
+
+       return 0;
+}
+
+static void ipheth_carrier_check_work(struct work_struct *work)
+{
+       struct ipheth_device *dev = container_of(work, struct ipheth_device,
+                                                carrier_work.work);
+
+       ipheth_carrier_set(dev);
+       schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
+}
+
+static int ipheth_get_macaddr(struct ipheth_device *dev)
+{
+       struct usb_device *udev = dev->udev;
+       struct net_device *net = dev->net;
+       int retval;
+
+       retval = usb_control_msg(udev,
+                                usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
+                                IPHETH_CMD_GET_MACADDR, /* request */
+                                0xc0, /* request type */
+                                0x00, /* value */
+                                0x02, /* index */
+                                dev->ctrl_buf,
+                                IPHETH_CTRL_BUF_SIZE,
+                                IPHETH_CTRL_TIMEOUT);
+       if (retval < 0) {
+               err("%s: usb_control_msg: %d", __func__, retval);
+       } else if (retval < ETH_ALEN) {
+               err("%s: usb_control_msg: short packet: %d bytes",
+                       __func__, retval);
+               retval = -EINVAL;
+       } else {
+               memcpy(net->dev_addr, dev->ctrl_buf, ETH_ALEN);
+               retval = 0;
+       }
+
+       return retval;
+}
+
+static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags)
+{
+       struct usb_device *udev = dev->udev;
+       int retval;
+
+       usb_fill_bulk_urb(dev->rx_urb, udev,
+                         usb_rcvbulkpipe(udev, dev->bulk_in),
+                         dev->rx_buf, IPHETH_BUF_SIZE,
+                         ipheth_rcvbulk_callback,
+                         dev);
+       dev->rx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+       retval = usb_submit_urb(dev->rx_urb, mem_flags);
+       if (retval)
+               err("%s: usb_submit_urb: %d", __func__, retval);
+       return retval;
+}
+
+static int ipheth_open(struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+       struct usb_device *udev = dev->udev;
+       int retval = 0;
+
+       usb_set_interface(udev, IPHETH_INTFNUM, IPHETH_ALT_INTFNUM);
+
+       retval = ipheth_carrier_set(dev);
+       if (retval)
+               return retval;
+
+       retval = ipheth_rx_submit(dev, GFP_KERNEL);
+       if (retval)
+               return retval;
+
+       schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
+       netif_start_queue(net);
+       return retval;
+}
+
+static int ipheth_close(struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+
+       cancel_delayed_work_sync(&dev->carrier_work);
+       netif_stop_queue(net);
+       return 0;
+}
+
+static int ipheth_tx(struct sk_buff *skb, struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+       struct usb_device *udev = dev->udev;
+       int retval;
+
+       /* Paranoid */
+       if (skb->len > IPHETH_BUF_SIZE) {
+               WARN(1, "%s: skb too large: %d bytes", __func__, skb->len);
+               dev->net->stats.tx_dropped++;
+               dev_kfree_skb_irq(skb);
+               return NETDEV_TX_OK;
+       }
+
+       memcpy(dev->tx_buf, skb->data, skb->len);
+       if (skb->len < IPHETH_BUF_SIZE)
+               memset(dev->tx_buf + skb->len, 0, IPHETH_BUF_SIZE - skb->len);
+
+       usb_fill_bulk_urb(dev->tx_urb, udev,
+                         usb_sndbulkpipe(udev, dev->bulk_out),
+                         dev->tx_buf, IPHETH_BUF_SIZE,
+                         ipheth_sndbulk_callback,
+                         dev);
+       dev->tx_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
+
+       retval = usb_submit_urb(dev->tx_urb, GFP_ATOMIC);
+       if (retval) {
+               err("%s: usb_submit_urb: %d", __func__, retval);
+               dev->net->stats.tx_errors++;
+               dev_kfree_skb_irq(skb);
+       } else {
+               dev->tx_skb = skb;
+
+               dev->net->stats.tx_packets++;
+               dev->net->stats.tx_bytes += skb->len;
+               netif_stop_queue(net);
+       }
+
+       return NETDEV_TX_OK;
+}
+
+static void ipheth_tx_timeout(struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+
+       err("%s: TX timeout", __func__);
+       dev->net->stats.tx_errors++;
+       usb_unlink_urb(dev->tx_urb);
+}
+
+static struct net_device_stats *ipheth_stats(struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+       return &dev->net->stats;
+}
+
+static u32 ipheth_ethtool_op_get_link(struct net_device *net)
+{
+       struct ipheth_device *dev = netdev_priv(net);
+       return netif_carrier_ok(dev->net);
+}
+
+static struct ethtool_ops ops = {
+       .get_link = ipheth_ethtool_op_get_link
+};
+
+static const struct net_device_ops ipheth_netdev_ops = {
+       .ndo_open = &ipheth_open,
+       .ndo_stop = &ipheth_close,
+       .ndo_start_xmit = &ipheth_tx,
+       .ndo_tx_timeout = &ipheth_tx_timeout,
+       .ndo_get_stats = &ipheth_stats,
+};
+
+static struct device_type ipheth_type = {
+       .name   = "wwan",
+};
+
+static int ipheth_probe(struct usb_interface *intf,
+                       const struct usb_device_id *id)
+{
+       struct usb_device *udev = interface_to_usbdev(intf);
+       struct usb_host_interface *hintf;
+       struct usb_endpoint_descriptor *endp;
+       struct ipheth_device *dev;
+       struct net_device *netdev;
+       int i;
+       int retval;
+
+       netdev = alloc_etherdev(sizeof(struct ipheth_device));
+       if (!netdev)
+               return -ENOMEM;
+
+       netdev->netdev_ops = &ipheth_netdev_ops;
+       netdev->watchdog_timeo = IPHETH_TX_TIMEOUT;
+       strcpy(netdev->name, "wwan%d");
+
+       dev = netdev_priv(netdev);
+       dev->udev = udev;
+       dev->net = netdev;
+       dev->intf = intf;
+
+       /* Set up endpoints */
+       hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
+       if (hintf == NULL) {
+               retval = -ENODEV;
+               err("Unable to find alternate settings interface");
+               goto err_endpoints;
+       }
+
+       for (i = 0; i < hintf->desc.bNumEndpoints; i++) {
+               endp = &hintf->endpoint[i].desc;
+               if (usb_endpoint_is_bulk_in(endp))
+                       dev->bulk_in = endp->bEndpointAddress;
+               else if (usb_endpoint_is_bulk_out(endp))
+                       dev->bulk_out = endp->bEndpointAddress;
+       }
+       if (!(dev->bulk_in && dev->bulk_out)) {
+               retval = -ENODEV;
+               err("Unable to find endpoints");
+               goto err_endpoints;
+       }
+
+       dev->ctrl_buf = kmalloc(IPHETH_CTRL_BUF_SIZE, GFP_KERNEL);
+       if (dev->ctrl_buf == NULL) {
+               retval = -ENOMEM;
+               goto err_alloc_ctrl_buf;
+       }
+
+       retval = ipheth_get_macaddr(dev);
+       if (retval)
+               goto err_get_macaddr;
+
+       INIT_DELAYED_WORK(&dev->carrier_work, ipheth_carrier_check_work);
+
+       retval = ipheth_alloc_urbs(dev);
+       if (retval) {
+               err("error allocating urbs: %d", retval);
+               goto err_alloc_urbs;
+       }
+
+       usb_set_intfdata(intf, dev);
+
+       SET_NETDEV_DEV(netdev, &intf->dev);
+       SET_ETHTOOL_OPS(netdev, &ops);
+       SET_NETDEV_DEVTYPE(netdev, &ipheth_type);
+
+       retval = register_netdev(netdev);
+       if (retval) {
+               err("error registering netdev: %d", retval);
+               retval = -EIO;
+               goto err_register_netdev;
+       }
+
+       dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
+       return 0;
+
+err_register_netdev:
+       ipheth_free_urbs(dev);
+err_alloc_urbs:
+err_get_macaddr:
+err_alloc_ctrl_buf:
+       kfree(dev->ctrl_buf);
+err_endpoints:
+       free_netdev(netdev);
+       return retval;
+}
+
+static void ipheth_disconnect(struct usb_interface *intf)
+{
+       struct ipheth_device *dev;
+
+       dev = usb_get_intfdata(intf);
+       if (dev != NULL) {
+               unregister_netdev(dev->net);
+               ipheth_kill_urbs(dev);
+               ipheth_free_urbs(dev);
+               kfree(dev->ctrl_buf);
+               free_netdev(dev->net);
+       }
+       usb_set_intfdata(intf, NULL);
+       dev_info(&intf->dev, "Apple iPhone USB Ethernet now disconnected\n");
+}
+
+static struct usb_driver ipheth_driver = {
+       .name =         "ipheth",
+       .probe =        ipheth_probe,
+       .disconnect =   ipheth_disconnect,
+       .id_table =     ipheth_table,
+};
+
+static int __init ipheth_init(void)
+{
+       int retval;
+
+       retval = usb_register(&ipheth_driver);
+       if (retval) {
+               err("usb_register failed: %d", retval);
+               return retval;
+       }
+       return 0;
+}
+
+static void __exit ipheth_exit(void)
+{
+       usb_deregister(&ipheth_driver);
+}
+
+module_init(ipheth_init);
+module_exit(ipheth_exit);
+
+MODULE_AUTHOR("Diego Giagio <[email protected]>");
+MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
+MODULE_LICENSE("Dual BSD/GPL");
--

1.7.0

Signature · 2 lines
Diego Giagio
[email protected] / [email protected]
maintainer
#33 lore raw

Re: [PATCH] drivers/net/usb: Add new driver ipheth

From: Diego Giagio <[email protected]>
Date: Wed, 21 Apr 2010 11:15:15 -0300

Quoted 7 lines
Quoted 5 lines · L. Alberto Giménez

From: Diego Giagio <[email protected]>

Add new driver to use tethering with an iPhone device. After initial submission, apply fixes to fit the new driver into the kernel standards.

Quoted 6 lines
Quoted 3 lines

There are still a couple of minor (almost cosmetic-level) issues, but the driver is fully functional right now.

Cc Daniel Borca <dborca-/[email protected]>

Applied, thanks everyone.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html