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
This commit is contained in:
avos 2019-04-10 08:17:56 +00:00
parent d2a873b062
commit 80646d8a6d
3 changed files with 32 additions and 7 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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);
@ -1186,10 +1187,24 @@ urtw_adapter_start_b(struct urtw_softc *sc)
return (error);
}
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)