Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 8 Mar 2018 18:42:23 +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: r330666 - head/sys/dev/iwi
Message-ID:  <201803081842.w28IgNHX001800@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avos
Date: Thu Mar  8 18:42:23 2018
New Revision: 330666
URL: https://svnweb.freebsd.org/changeset/base/330666

Log:
  iwi(4): factor out rateset setup into iwi_set_rateset().
  
  No functional change intended.

Modified:
  head/sys/dev/iwi/if_iwi.c

Modified: head/sys/dev/iwi/if_iwi.c
==============================================================================
--- head/sys/dev/iwi/if_iwi.c	Thu Mar  8 17:23:18 2018	(r330665)
+++ head/sys/dev/iwi/if_iwi.c	Thu Mar  8 18:42:23 2018	(r330666)
@@ -2550,11 +2550,36 @@ iwi_setwepkeys(struct iwi_softc *sc, struct ieee80211v
 }
 
 static int
+iwi_set_rateset(struct iwi_softc *sc, const struct ieee80211_rateset *net_rs,
+    int mode, int type)
+{
+	struct iwi_rateset rs;
+	int i;
+
+	memset(&rs, 0, sizeof(rs));
+	rs.mode = mode;
+	rs.type = type;
+	rs.nrates = net_rs->rs_nrates;
+	if (rs.nrates > nitems(rs.rates)) {
+		DPRINTF(("Truncating negotiated rate set from %u\n",
+		    rs.nrates));
+		rs.nrates = nitems(rs.rates);
+	}
+	memcpy(rs.rates, net_rs->rs_rates, rs.nrates);
+	DPRINTF(("Setting .11%c%s %s rates (%u)\n",
+	    mode == IWI_MODE_11A ? 'a' : 'b',
+	    mode == IWI_MODE_11G ? "g" : "",
+	    type == IWI_RATESET_TYPE_SUPPORTED ? "supported" : "negotiated",
+	    rs.nrates));
+
+	return (iwi_cmd(sc, IWI_CMD_SET_RATES, &rs, sizeof(rs)));
+}
+
+static int
 iwi_config(struct iwi_softc *sc)
 {
 	struct ieee80211com *ic = &sc->sc_ic;
 	struct iwi_configuration config;
-	struct iwi_rateset rs;
 	struct iwi_txpower power;
 	uint32_t data;
 	int error, i;
@@ -2603,25 +2628,13 @@ iwi_config(struct iwi_softc *sc)
 			return error;
 	}
 
-	memset(&rs, 0, sizeof rs);
-	rs.mode = IWI_MODE_11G;
-	rs.type = IWI_RATESET_TYPE_SUPPORTED;
-	rs.nrates = ic->ic_sup_rates[IEEE80211_MODE_11G].rs_nrates;
-	memcpy(rs.rates, ic->ic_sup_rates[IEEE80211_MODE_11G].rs_rates,
-	    rs.nrates);
-	DPRINTF(("Setting .11bg supported rates (%u)\n", rs.nrates));
-	error = iwi_cmd(sc, IWI_CMD_SET_RATES, &rs, sizeof rs);
+	error = iwi_set_rateset(sc, &ic->ic_sup_rates[IEEE80211_MODE_11G],
+	    IWI_MODE_11G, IWI_RATESET_TYPE_SUPPORTED);
 	if (error != 0)
 		return error;
 
-	memset(&rs, 0, sizeof rs);
-	rs.mode = IWI_MODE_11A;
-	rs.type = IWI_RATESET_TYPE_SUPPORTED;
-	rs.nrates = ic->ic_sup_rates[IEEE80211_MODE_11A].rs_nrates;
-	memcpy(rs.rates, ic->ic_sup_rates[IEEE80211_MODE_11A].rs_rates,
-	    rs.nrates);
-	DPRINTF(("Setting .11a supported rates (%u)\n", rs.nrates));
-	error = iwi_cmd(sc, IWI_CMD_SET_RATES, &rs, sizeof rs);
+	error = iwi_set_rateset(sc, &ic->ic_sup_rates[IEEE80211_MODE_11A],
+	    IWI_MODE_11A, IWI_RATESET_TYPE_SUPPORTED);
 	if (error != 0)
 		return error;
 
@@ -2815,7 +2828,6 @@ iwi_auth_and_assoc(struct iwi_softc *sc, struct ieee80
 	struct ieee80211_node *ni;
 	struct iwi_configuration config;
 	struct iwi_associate *assoc = &sc->assoc;
-	struct iwi_rateset rs;
 	uint16_t capinfo;
 	uint32_t data;
 	int error, mode;
@@ -2885,18 +2897,8 @@ iwi_auth_and_assoc(struct iwi_softc *sc, struct ieee80
 		goto done;
 
 	/* the rate set has already been "negotiated" */
-	memset(&rs, 0, sizeof rs);
-	rs.mode = mode;
-	rs.type = IWI_RATESET_TYPE_NEGOTIATED;
-	rs.nrates = ni->ni_rates.rs_nrates;
-	if (rs.nrates > IWI_RATESET_SIZE) {
-		DPRINTF(("Truncating negotiated rate set from %u\n",
-		    rs.nrates));
-		rs.nrates = IWI_RATESET_SIZE;
-	}
-	memcpy(rs.rates, ni->ni_rates.rs_rates, rs.nrates);
-	DPRINTF(("Setting negotiated rates (%u)\n", rs.nrates));
-	error = iwi_cmd(sc, IWI_CMD_SET_RATES, &rs, sizeof rs);
+	error = iwi_set_rateset(sc, &ni->ni_rates, mode,
+	    IWI_RATESET_TYPE_NEGOTIATED);
 	if (error != 0)
 		goto done;
 



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