Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 11476d37 authored by Manu Gautam's avatar Manu Gautam
Browse files

usb: f_gsi: Allow user to specify MAC address for RNDIS/ECM



Driver currently uses random MAC address which gets changed
across composition switches or reboots. Allow user to specify
MAC address using module parameter to fix this.

Change-Id: I96710b3419ff7c016b931195a80ce77cd8c9038c
Signed-off-by: default avatarManu Gautam <mgautam@codeaurora.org>
parent 7425049a
Loading
Loading
Loading
Loading
+46 −8
Original line number Diff line number Diff line
@@ -24,6 +24,16 @@ static bool qti_packet_debug;
module_param(qti_packet_debug, bool, 0644);
MODULE_PARM_DESC(qti_packet_debug, "Print QTI Packet's Raw Data");

/* initial value, changed by "ifconfig usb0 hw ether xx:xx:xx:xx:xx:xx" */
static char *gsi_dev_addr;
module_param(gsi_dev_addr, charp, 0644);
MODULE_PARM_DESC(gsi_dev_addr, "QC Device Ethernet Address");

/* this address is invisible to ifconfig */
static char *gsi_host_addr;
module_param(gsi_host_addr, charp, 0644);
MODULE_PARM_DESC(gsi_host_addr, "QC Host Ethernet Address");

static struct workqueue_struct *ipa_usb_wq;
static struct f_gsi *__gsi[USB_PROT_MAX];
static void *ipc_log_ctxt;
@@ -2814,6 +2824,26 @@ static void ipa_ready_callback(void *user_data)
	wake_up_interruptible(&gsi->d_port.wait_for_ipa_ready);
}

static void gsi_get_ether_addr(const char *str, u8 *dev_addr)
{
	if (str) {
		unsigned int i;

		for (i = 0; i < ETH_ALEN; i++) {
			unsigned char num;

			if ((*str == '.') || (*str == ':'))
				str++;
			num = hex_to_bin(*str++) << 4;
			num |= hex_to_bin(*str++);
			dev_addr[i] = num;
		}
		if (is_valid_ether_addr(dev_addr))
			return;
	}
	random_ether_addr(dev_addr);
}

static int gsi_bind(struct usb_configuration *c, struct usb_function *f)
{
	struct usb_composite_dev *cdev = c->cdev;
@@ -2886,8 +2916,12 @@ static int gsi_bind(struct usb_configuration *c, struct usb_function *f)
		rndis_set_param_medium(gsi->params, RNDIS_MEDIUM_802_3, 0);

		/* export host's Ethernet address in CDC format */
		random_ether_addr(gsi->d_port.ipa_init_params.device_ethaddr);
		random_ether_addr(gsi->d_port.ipa_init_params.host_ethaddr);
		gsi_get_ether_addr(gsi_dev_addr,
				   gsi->d_port.ipa_init_params.device_ethaddr);

		gsi_get_ether_addr(gsi_host_addr,
				   gsi->d_port.ipa_init_params.host_ethaddr);

		log_event_dbg("setting host_ethaddr=%pM, device_ethaddr = %pM",
				gsi->d_port.ipa_init_params.host_ethaddr,
				gsi->d_port.ipa_init_params.device_ethaddr);
@@ -3099,8 +3133,12 @@ static int gsi_bind(struct usb_configuration *c, struct usb_function *f)
		info.notify_buf_len = GSI_CTRL_NOTIFY_BUFF_LEN;

		/* export host's Ethernet address in CDC format */
		random_ether_addr(gsi->d_port.ipa_init_params.device_ethaddr);
		random_ether_addr(gsi->d_port.ipa_init_params.host_ethaddr);
		gsi_get_ether_addr(gsi_dev_addr,
				   gsi->d_port.ipa_init_params.device_ethaddr);

		gsi_get_ether_addr(gsi_host_addr,
				   gsi->d_port.ipa_init_params.host_ethaddr);

		log_event_dbg("setting host_ethaddr=%pM, device_ethaddr = %pM",
				gsi->d_port.ipa_init_params.host_ethaddr,
				gsi->d_port.ipa_init_params.device_ethaddr);