Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 Apr 2019 08:17:56 +0000 (UTC)
From:      Andriy Voskoboinyk <avos@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r346073 - in head/sys/dev: iwi otus usb/wlan
Message-ID:  <201904100817.x3A8HuQL060450@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avos
Date: Wed Apr 10 08:17:56 2019
New Revision: 346073
URL: https://svnweb.freebsd.org/changeset/base/346073

Log:
  urtw(4), otus(4), iwi(4): allow to set non-default MAC address via ifconfig(8)
  
  Tested with Netgear WG111 v3 (RTL8187B, urtw(4)), STA mode.
  
  MFC after:	1 week

Modified:
  head/sys/dev/iwi/if_iwi.c
  head/sys/dev/otus/if_otus.c
  head/sys/dev/usb/wlan/if_urtw.c

Modified: head/sys/dev/iwi/if_iwi.c
==============================================================================
--- head/sys/dev/iwi/if_iwi.c	Wed Apr 10 07:51:13 2019	(r346072)
+++ head/sys/dev/iwi/if_iwi.c	Wed Apr 10 08:17:56 2019	(r346073)
@@ -2576,15 +2576,18 @@ static int
 iwi_config(struct iwi_softc *sc)
 {
 	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
 	struct iwi_configuration config;
 	struct iwi_txpower power;
+	uint8_t *macaddr;
 	uint32_t data;
 	int error, i;
 
 	IWI_LOCK_ASSERT(sc);
 
-	DPRINTF(("Setting MAC address to %6D\n", ic->ic_macaddr, ":"));
-	error = iwi_cmd(sc, IWI_CMD_SET_MAC_ADDRESS, ic->ic_macaddr,
+	macaddr = vap ? vap->iv_myaddr : ic->ic_macaddr;
+	DPRINTF(("Setting MAC address to %6D\n", macaddr, ":"));
+	error = iwi_cmd(sc, IWI_CMD_SET_MAC_ADDRESS, macaddr,
 	    IEEE80211_ADDR_LEN);
 	if (error != 0)
 		return error;

Modified: head/sys/dev/otus/if_otus.c
==============================================================================
--- head/sys/dev/otus/if_otus.c	Wed Apr 10 07:51:13 2019	(r346072)
+++ head/sys/dev/otus/if_otus.c	Wed Apr 10 08:17:56 2019	(r346073)
@@ -3108,7 +3108,7 @@ otus_set_operating_mode(struct otus_softc *sc)
 	 */
 	IEEE80211_ADDR_COPY(bssid, zero_macaddr);
 	vap = TAILQ_FIRST(&ic->ic_vaps);
-	macaddr = ic->ic_macaddr;
+	macaddr = vap ? vap->iv_myaddr : ic->ic_macaddr;
 
 	switch (ic->ic_opmode) {
 	case IEEE80211_M_STA:

Modified: head/sys/dev/usb/wlan/if_urtw.c
==============================================================================
--- head/sys/dev/usb/wlan/if_urtw.c	Wed Apr 10 07:51:13 2019	(r346072)
+++ head/sys/dev/usb/wlan/if_urtw.c	Wed Apr 10 08:17:56 2019	(r346073)
@@ -752,6 +752,7 @@ static void		urtw_free_tx_data_list(struct urtw_softc 
 static void		urtw_free_rx_data_list(struct urtw_softc *);
 static void		urtw_free_data_list(struct urtw_softc *,
 			    struct urtw_data data[], int, int);
+static usb_error_t	urtw_set_macaddr(struct urtw_softc *, const uint8_t *);
 static usb_error_t	urtw_adapter_start(struct urtw_softc *);
 static usb_error_t	urtw_adapter_start_b(struct urtw_softc *);
 static usb_error_t	urtw_set_mode(struct urtw_softc *, uint32_t);
@@ -1187,9 +1188,23 @@ fail:
 }
 
 static usb_error_t
+urtw_set_macaddr(struct urtw_softc *sc, const uint8_t *macaddr)
+{
+	usb_error_t error;
+
+	urtw_write32_m(sc, URTW_MAC0, ((const uint32_t *)macaddr)[0]);
+	urtw_write16_m(sc, URTW_MAC4, ((const uint32_t *)macaddr)[1] & 0xffff);
+
+fail:
+	return (error);
+}
+
+static usb_error_t
 urtw_adapter_start(struct urtw_softc *sc)
 {
 	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+	const uint8_t *macaddr;
 	usb_error_t error;
 
 	error = urtw_reset(sc);
@@ -1209,8 +1224,11 @@ urtw_adapter_start(struct urtw_softc *sc)
 	if (error)
 		goto fail;
 	/* applying MAC address again.  */
-	urtw_write32_m(sc, URTW_MAC0, ((uint32_t *)ic->ic_macaddr)[0]);
-	urtw_write16_m(sc, URTW_MAC4, ((uint32_t *)ic->ic_macaddr)[1] & 0xffff);
+	macaddr = vap ? vap->iv_myaddr : ic->ic_macaddr;
+	urtw_set_macaddr(sc, macaddr);
+	if (error)
+		goto fail;
+
 	error = urtw_set_mode(sc, URTW_EPROM_CMD_NORMAL);
 	if (error)
 		goto fail;
@@ -3180,6 +3198,8 @@ static usb_error_t
 urtw_8225v2b_rf_init(struct urtw_softc *sc)
 {
 	struct ieee80211com *ic = &sc->sc_ic;
+	struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+	const uint8_t *macaddr;
 	unsigned int i;
 	uint8_t data8;
 	usb_error_t error;
@@ -3227,8 +3247,10 @@ urtw_8225v2b_rf_init(struct urtw_softc *sc)
 	urtw_write8_m(sc, URTW_CONFIG1, data8);
 
 	/* applying MAC address again.  */
-	urtw_write32_m(sc, URTW_MAC0, ((uint32_t *)ic->ic_macaddr)[0]);
-	urtw_write16_m(sc, URTW_MAC4, ((uint32_t *)ic->ic_macaddr)[1] & 0xffff);
+	macaddr = vap ? vap->iv_myaddr : ic->ic_macaddr;
+	error = urtw_set_macaddr(sc, macaddr);
+	if (error)
+		goto fail;
 
 	error = urtw_set_mode(sc, URTW_EPROM_CMD_NORMAL);
 	if (error)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201904100817.x3A8HuQL060450>