#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>
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)
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,