summaryrefslogtreecommitdiff
path: root/hw/usb_cfs_client_common.c
diff options
context:
space:
mode:
authorYoungjae Cho <y0.cho@samsung.com>2020-02-05 15:03:04 +0900
committerHyotaek Shim <hyotaek.shim@samsung.com>2020-02-07 08:47:22 +0000
commit4a9e04e4da8ec8173b259c9cd0ab213c5cd4f5e8 (patch)
tree4df5af47415ab8b300a54c3e70a37a9309ec5f9a /hw/usb_cfs_client_common.c
parente4dc7cd95d50c2bd6cd62085615f09160fbdeb87 (diff)
downloadlibdevice-node-4a9e04e4da8ec8173b259c9cd0ab213c5cd4f5e8.tar.gz
libdevice-node-4a9e04e4da8ec8173b259c9cd0ab213c5cd4f5e8.tar.bz2
libdevice-node-4a9e04e4da8ec8173b259c9cd0ab213c5cd4f5e8.zip
Change-Id: Ic3472d6b6da35b199704ca6150447cab05638a71 Signed-off-by: Youngjae Cho <y0.cho@samsung.com> (cherry picked from commit afc9e97d20d06918ade6e6cc555226bc30131889)
Diffstat (limited to 'hw/usb_cfs_client_common.c')
-rw-r--r--hw/usb_cfs_client_common.c38
1 files changed, 38 insertions, 0 deletions
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 <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,