OpenWrt – Rev 4

Subversion Repositories:
Rev:
--- a/drivers/net/usb/ipheth.c  2018-08-16 00:14:55.000000000 +0800
+++ b/drivers/net/usb/ipheth.c  2019-02-26 15:21:16.600320776 +0800
@@ -87,7 +87,7 @@
 #define IPHETH_CARRIER_CHECK_TIMEOUT round_jiffies_relative(1 * HZ)
 #define IPHETH_CARRIER_ON       0x04
 
-static struct usb_device_id ipheth_table[] = {
+static const struct usb_device_id ipheth_table[] = {
        { USB_DEVICE_AND_INTERFACE_INFO(
                USB_VENDOR_APPLE, USB_PRODUCT_IPHONE,
                IPHETH_USBINTF_CLASS, IPHETH_USBINTF_SUBCLASS,
@@ -149,6 +149,7 @@ struct ipheth_device {
        u8 bulk_in;
        u8 bulk_out;
        struct delayed_work carrier_work;
+       bool confirmed_pairing;
 };
 
 static int ipheth_rx_submit(struct ipheth_device *dev, gfp_t mem_flags);
@@ -253,13 +254,13 @@ static void ipheth_rcvbulk_callback(stru
                return;
        }
 
-       memcpy(skb_put(skb, len), buf, len);
+       __skb_put_data(skb, buf, len);
        skb->dev = dev->net;
        skb->protocol = eth_type_trans(skb, dev->net);
 
        dev->net->stats.rx_packets++;
        dev->net->stats.rx_bytes += len;
-
+       dev->confirmed_pairing = true;
        netif_rx(skb);
        ipheth_rx_submit(dev, GFP_ATOMIC);
 }
@@ -281,14 +282,24 @@ static void ipheth_sndbulk_callback(stru
                __func__, status);
 
        dev_kfree_skb_irq(dev->tx_skb);
-       netif_wake_queue(dev->net);
+       if (status == 0)
+               netif_wake_queue(dev->net);
+       else
+               // on URB error, trigger immediate poll
+               schedule_delayed_work(&dev->carrier_work, 0);
 }
 
 static int ipheth_carrier_set(struct ipheth_device *dev)
 {
-       struct usb_device *udev = dev->udev;
+       struct usb_device *udev;
        int retval;
 
+       if (!dev)
+               return 0;
+       if (!dev->confirmed_pairing)
+               return 0;
+
+       udev = dev->udev;
        retval = usb_control_msg(udev,
                        usb_rcvctrlpipe(udev, IPHETH_CTRL_ENDP),
                        IPHETH_CMD_CARRIER_CHECK, /* request */
@@ -303,11 +314,14 @@ static int ipheth_carrier_set(struct iph
                return retval;
        }
 
-       if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON)
+       if (dev->ctrl_buf[0] == IPHETH_CARRIER_ON) {
                netif_carrier_on(dev->net);
-       else
+               if (dev->tx_urb->status != -EINPROGRESS)
+                       netif_wake_queue(dev->net);
+       } else {
                netif_carrier_off(dev->net);
-
+               netif_stop_queue(dev->net);
+       }
        return 0;
 }
 
@@ -387,7 +401,6 @@ static int ipheth_open(struct net_device
                return retval;
 
        schedule_delayed_work(&dev->carrier_work, IPHETH_CARRIER_CHECK_TIMEOUT);
-       netif_start_queue(net);
        return retval;
 }
 
@@ -491,7 +504,7 @@ static int ipheth_probe(struct usb_inter
        dev->udev = udev;
        dev->net = netdev;
        dev->intf = intf;
-
+       dev->confirmed_pairing = false;
        /* Set up endpoints */
        hintf = usb_altnum_to_altsetting(intf, IPHETH_ALT_INTFNUM);
        if (hintf == NULL) {
@@ -542,7 +555,9 @@ static int ipheth_probe(struct usb_inter
                retval = -EIO;
                goto err_register_netdev;
        }
-
+       // carrier down and transmit queues stopped until packet from device
+       netif_carrier_off(netdev);
+       netif_tx_stop_all_queues(netdev);
        dev_info(&intf->dev, "Apple iPhone USB Ethernet device attached\n");
        return 0;
 
@@ -585,4 +600,4 @@ module_usb_driver(ipheth_driver);
 
 MODULE_AUTHOR("Diego Giagio <diego@giagio.com>");
 MODULE_DESCRIPTION("Apple iPhone USB Ethernet driver");
-MODULE_LICENSE("Dual BSD/GPL");
+MODULE_LICENSE("Dual BSD/GPL");
--- a/include/linux/skbuff.h    2019-02-26 16:00:21.771797316 +0800
+++ b/include/linux/skbuff.h    2019-02-26 16:01:22.288908959 +0800
@@ -1922,6 +1922,15 @@ static inline unsigned char *__skb_put(s
        return tmp;
 }
 
+static inline void *__skb_put_data(struct sk_buff *skb, const void *data,
+                                  unsigned int len)
+{
+       void *tmp = __skb_put(skb, len);
+
+       memcpy(tmp, data, len);
+       return tmp;
+}
+
 unsigned char *skb_push(struct sk_buff *skb, unsigned int len);
 static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
 {