Apply mac addres for rndis mode 31/223931/8 accepted/tizen/unified/20200210.131800 submit/tizen/20200207.085206 submit/tizen/20200207.103010
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 5 Feb 2020 06:03:04 +0000 (15:03 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Fri, 7 Feb 2020 08:47:12 +0000 (08:47 +0000)
Change-Id: Ic3472d6b6da35b199704ca6150447cab05638a71
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
hw/usb_cfs_client_common.c

index b67d86d..e4572de 100644 (file)
@@ -26,6 +26,7 @@
 #include <sys/types.h>
 #include <sys/mount.h>
 #include <usbg/usbg.h>
+#include <usbg/function/net.h>
 #include <unistd.h>
 
 #include <libsyscommon/dbus-systemd.h>
@@ -658,6 +659,37 @@ umount_ffs:
        return ret;
 }
 
+static int cfs_set_rndis_mac_addr(usbg_gadget *gadget, usbg_function *func)
+{
+       int i, ret;
+       struct ether_addr ethaddr;
+       struct usbg_gadget_strs strs;
+       struct usbg_f_net *nf = usbg_to_net_function(func);
+
+       if (!nf)
+               return -EINVAL;
+
+       ret = usbg_get_gadget_strs(gadget, LANG_US_ENG, &strs);
+       if (ret != USBG_SUCCESS)
+               return ret;
+
+       for (i = 0; i < ETHER_ADDR_LEN; i++)
+               ethaddr.ether_addr_octet[i] = 0;
+
+       for (i = 0; (i < 256) && strs.serial[i]; i++) {
+               ethaddr.ether_addr_octet[i % (ETHER_ADDR_LEN - 1) + 1] ^= strs.serial[i];
+       }
+       ethaddr.ether_addr_octet[0] &= 0xfe;     /* clear multicast bit */
+       ethaddr.ether_addr_octet[0] |= 0x02;     /* set local assignment bit (IEEE802) */
+
+       usbg_free_gadget_strs(&strs);
+
+       /* host_addr changes mac address */
+       ret = usbg_f_net_set_host_addr(nf, &ethaddr);
+
+       return ret;
+}
+
 static int cfs_set_gadget_config(struct cfs_client *cfs_client,
                                    int config_id,
                                    struct usb_configuration *usb_config)
@@ -722,6 +754,12 @@ static int cfs_set_gadget_config(struct cfs_client *cfs_client,
                        if (ret)
                                return ret;
 
+                       /* Setting rndis mac address. This should be done at this point,
+                        * since the node host_addr changes to read only after the function
+                        * is added to config. */
+                       if (usbg_get_function_type(func) == USBG_F_RNDIS)
+                               (void)cfs_set_rndis_mac_addr(cfs_client->gadget, func); /* A random value is used if fails */
+
                        if (usb_func->ffs_service) {
                                ret = cfs_prep_ffs_service(usb_func->name,
                                                        usb_func->instance,