From: Youngjae Cho Date: Wed, 5 Feb 2020 06:03:04 +0000 (+0900) Subject: Apply mac addres for rndis mode X-Git-Tag: submit/tizen_5.5/20200207.085239^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4a9e04e4da8ec8173b259c9cd0ab213c5cd4f5e8;p=platform%2Fcore%2Fsystem%2Flibdevice-node.git Apply mac addres for rndis mode Change-Id: Ic3472d6b6da35b199704ca6150447cab05638a71 Signed-off-by: Youngjae Cho (cherry picked from commit afc9e97d20d06918ade6e6cc555226bc30131889) --- diff --git a/hw/usb_cfs_client_common.c b/hw/usb_cfs_client_common.c index b67d86d..e4572de 100644 --- a/hw/usb_cfs_client_common.c +++ b/hw/usb_cfs_client_common.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -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, ðaddr); + + 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,