From: "taeju.park" <taeju.park@xxxxxxx> On windows 7 platform, previously allocated ip address is maintained. However, Host MAC address of 'usb0' interface is changed when the tethering driver re-enumerated. Thus, the tethering network driver can't be allocated ip address from dhcp. It causes connection delay between host and phone for usb tethering. This patch prevents from changing Host MAC address of 'usb0' interface. In other words, this patch maintains the Host MAC address allocated when first tethering driver although the driver is re-enumerated. However, after reboot, the Host MAC address can be changed. Cc: Felipe Balbi <balbi@xxxxxxxxxx> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> Cc: Mike Looijmans <mike.looijmans@xxxxxxxx> Cc: Robert Baldyga <r.baldyga@xxxxxxxxxxx> Cc: Android Kernel Team <kernel-team@xxxxxxxxxxx> Cc: John Stultz <john.stultz@xxxxxxxxxx> Cc: Sumit Semwal <sumit.semwal@xxxxxxxxxx> Signed-off-by: Badhri Jagan Sridharan <Badhri@xxxxxxxxxx> [pundir: cherry-picked this patch from AOSP experimental/android-4.4 tree.] Signed-off-by: Amit Pundir <amit.pundir@xxxxxxxxxx> --- Cherry-picked this patch from AOSP common/experimental/android-4.4 tree. I could not find upstream submission history for this patch, so my apologies in advance if this has already been NACKed before. drivers/usb/gadget/function/u_ether.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/function/u_ether.c b/drivers/usb/gadget/function/u_ether.c index 637809e..9a69332 100644 --- a/drivers/usb/gadget/function/u_ether.c +++ b/drivers/usb/gadget/function/u_ether.c @@ -698,6 +698,8 @@ static int eth_stop(struct net_device *net) /*-------------------------------------------------------------------------*/ +static u8 host_ethaddr[ETH_ALEN]; + static int get_ether_addr(const char *str, u8 *dev_addr) { if (str) { @@ -728,6 +730,17 @@ static int get_ether_addr_str(u8 dev_addr[ETH_ALEN], char *str, int len) return 18; } +static int get_host_ether_addr(u8 *str, u8 *dev_addr) +{ + memcpy(dev_addr, str, ETH_ALEN); + if (is_valid_ether_addr(dev_addr)) + return 0; + + random_ether_addr(dev_addr); + memcpy(str, dev_addr, ETH_ALEN); + return 1; +} + static const struct net_device_ops eth_netdev_ops = { .ndo_open = eth_open, .ndo_stop = eth_stop, @@ -784,9 +797,12 @@ struct eth_dev *gether_setup_name(struct usb_gadget *g, if (get_ether_addr(dev_addr, net->dev_addr)) dev_warn(&g->dev, "using random %s ethernet address\n", "self"); - if (get_ether_addr(host_addr, dev->host_mac)) + + if (get_host_ether_addr(host_ethaddr, dev->host_mac)) + dev_warn(&g->dev, "using random %s ethernet address\n", "host"); + else dev_warn(&g->dev, - "using random %s ethernet address\n", "host"); + "using previous %s ethernet address\n", "host"); if (ethaddr) memcpy(ethaddr, dev->host_mac, ETH_ALEN); -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html