Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src-draft/trunk]: src/sys/net80211 Initial attempt at converting iwm to phil...



details:   https://anonhg.NetBSD.org/src-all/rev/bda7c20d3cb4
branches:  trunk
changeset: 375529:bda7c20d3cb4
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Fri Aug 14 02:27:56 2020 +1000

description:
Initial attempt at converting iwm to phill wifi.

Note this is incompete and does not compiles as yet.

Based on conversion of iwn.

diffstat:

 sys/dev/pci/if_iwm.c                 |  635 ++++++++++++++++++++++++++++------
 sys/dev/pci/if_iwn.c                 |   12 +-
 sys/dev/usb/if_urtwn.c               |    4 +-
 sys/net80211/ieee80211_crypto_ccmp.c |    8 +-
 4 files changed, 536 insertions(+), 123 deletions(-)

diffs (truncated from 955 to 300 lines):

diff -r 474e3eefd8ed -r bda7c20d3cb4 sys/dev/pci/if_iwm.c
--- a/sys/dev/pci/if_iwm.c      Fri Aug 14 02:26:26 2020 +1000
+++ b/sys/dev/pci/if_iwm.c      Fri Aug 14 02:27:56 2020 +1000
@@ -312,6 +312,21 @@ static int iwm_nvm_read_section(struct i
                    uint16_t *, size_t);
 static void    iwm_init_channel_map(struct iwm_softc *, const uint16_t * const,
                    const uint8_t *, size_t);
+static void    iwm_init_channels(struct ieee80211com *);
+static struct ieee80211vap *
+               iwm_vap_create(struct ieee80211com *,
+                   const char [IFNAMSIZ], int, enum ieee80211_opmode, int,
+                   const uint8_t [IEEE80211_ADDR_LEN],
+                   const uint8_t [IEEE80211_ADDR_LEN]);
+static void    iwm_vap_delete(struct ieee80211vap *);
+static void    iwm_parent(struct ieee80211com *);
+static void    iwm_scan_start(struct ieee80211com *);
+static void    iwm_scan_end(struct ieee80211com *);
+static void    iwm_set_channel(struct ieee80211com *);
+static void    iwm_scan_curchan(struct ieee80211_scan_state *, unsigned long);
+static int     iwm_transmit(struct ieee80211com *, struct mbuf *);
+static int     iwm_raw_xmit(struct ieee80211_node *, struct mbuf *,
+                   const struct ieee80211_bpf_params *);
 #ifndef IEEE80211_NO_HT
 static void    iwm_setup_ht_rates(struct iwm_softc *);
 static void    iwm_htprot_task(void *);
@@ -398,7 +413,7 @@ static void iwm_update_sched(struct iwm_
 static const struct iwm_rate *
                iwm_tx_fill_cmd(struct iwm_softc *, struct iwm_node *,
                    struct ieee80211_frame *, struct iwm_tx_cmd *);
-static int     iwm_tx(struct iwm_softc *, struct mbuf *,
+static int     iwm_tx(struct ieee80211vap *, struct mbuf *,
                    struct ieee80211_node *, int);
 static void    iwm_led_enable(struct iwm_softc *);
 static void    iwm_led_disable(struct iwm_softc *);
@@ -482,6 +497,7 @@ static void iwm_softintr(void *);
 static int     iwm_preinit(struct iwm_softc *);
 static void    iwm_attach_hook(device_t);
 static void    iwm_attach(device_t, device_t, void *);
+static int     iwm_config_complete(device_t);
 #if 0
 static void    iwm_init_task(void *);
 static int     iwm_activate(device_t, enum devact);
@@ -552,7 +568,7 @@ iwm_firmload(struct iwm_softc *sc)
 /*
  * just maintaining status quo.
  */
-static void
+static void __unused
 iwm_fix_channel(struct iwm_softc *sc, struct mbuf *m)
 {
        struct ieee80211com *ic = &sc->sc_ic;
@@ -1903,6 +1919,79 @@ iwm_nic_rx_init(struct iwm_softc *sc)
 }
 
 static int
+iwm_raw_xmit(struct ieee80211_node *ni , struct mbuf *m,
+    const struct ieee80211_bpf_params *bpfp)
+{
+       struct ieee80211vap *vap = ni->ni_vap;
+       struct ieee80211com *ic = ni->ni_ic;
+       struct iwm_softc *sc = ic->ic_softc;
+       struct ifnet *ifp = vap->iv_ifp;
+       struct ether_header *eh;
+       int ac;
+
+       DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+       KASSERT(vap != NULL);   /*  NNN need these? */
+       KASSERT(ic != NULL);
+       KASSERT(sc != NULL);
+       KASSERT(m != NULL);
+
+       if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
+               return 0;
+
+       if (m->m_len < sizeof (*eh) &&
+           (m = m_pullup(m, sizeof (*eh))) == NULL) {
+               if_statinc(ifp, if_oerrors);
+                       return EIO;
+       }
+       eh = mtod(m, struct ether_header *);
+
+       /* No QoS encapsulation for EAPOL frames. */
+       ac = (eh->ether_type != htons(ETHERTYPE_PAE)) ?
+           M_WME_GETAC(m) : WME_AC_BE;
+
+        bpf_mtap3(vap->iv_rawbpf, m, BPF_D_OUT);
+
+       if (iwm_tx(vap, m, ni, ac) != 0) {
+               ieee80211_free_node(ni);
+               if_statinc(ifp, if_oerrors);
+                       return ENXIO;
+       }
+
+       sc->sc_tx_timer = 5;
+       ifp->if_timer = 1;
+
+       return 0;
+}
+
+static int
+iwm_transmit(struct ieee80211com *ic, struct mbuf *m)
+{
+       struct ieee80211vap *vap = TAILQ_FIRST(&ic->ic_vaps);
+       int s;
+
+       size_t pktlen = m->m_pkthdr.len;
+        bool mcast = (m->m_flags & M_MCAST) != 0;
+
+       DPRINTFN(DBG_FN, ("%s: %s\n",device_xname(sc->sc_dev), __func__));
+
+       s = splnet();
+
+       IF_ENQUEUE(&vap->iv_ifp->if_snd, m);
+        if_statadd(vap->iv_ifp, if_obytes, pktlen);
+        if (mcast)
+                if_statinc(vap->iv_ifp, if_omcasts);
+
+        if ((vap->iv_ifp->if_flags & IFF_OACTIVE) == 0)
+                if_start_lock(vap->iv_ifp);
+        splx(s);
+
+       iwm_start(vap->iv_ifp);
+
+        return 0;
+}
+
+static int
 iwm_nic_tx_init(struct iwm_softc *sc)
 {
        int qid;
@@ -2752,9 +2841,11 @@ iwm_sta_rx_agg(struct iwm_softc *sc, str
 static void
 iwm_htprot_task(void *arg)
 {
-       struct iwm_softc *sc = arg;
-       struct ieee80211com *ic = &sc->sc_ic;
-       struct iwm_node *in = (struct iwm_node *)ic->ic_bss;
+       struct ieee80211vap *vap = arg
+       struct ieee80211_node *in = vap->iv_bss;
+       struct ieee80211com *ic = vap->iv_ic;
+       struct iwm_softc *sc = ic->ic_softc;
+
        int err;
 
        /* This call updates HT protection based on in->in_ni.ni_htop1. */
@@ -3711,7 +3802,7 @@ iwm_run_init_mvm_ucode(struct iwm_softc 
                        return err;
                }
 
-               memcpy(&sc->sc_ic.ic_myaddr, &sc->sc_nvm.hw_addr,
+               memcpy(&sc->sc_ic.ic_macaddr, &sc->sc_nvm.hw_addr,
                    ETHER_ADDR_LEN);
                return 0;
        }
@@ -3903,7 +3994,6 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
        struct mbuf *m;
        struct iwm_rx_phy_info *phy_info;
        struct iwm_rx_mpdu_res_start *rx_res;
-       int device_timestamp;
        uint32_t len;
        uint32_t rx_pkt_status;
        int rssi;
@@ -3935,8 +4025,6 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
                return; /* drop */
        }
 
-       device_timestamp = le32toh(phy_info->system_timestamp);
-
        if (sc->sc_capaflags & IWM_UCODE_TLV_FLAGS_RX_ENERGY_API) {
                rssi = iwm_get_signal_strength(sc, phy_info);
        } else {
@@ -3944,8 +4032,10 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
        }
        rssi = -rssi;
 
-       if (ic->ic_state == IEEE80211_S_SCAN)
+#if 0
+       if (vap->iv_state == IEEE80211_S_SCAN)
                iwm_fix_channel(sc, m);
+#endif
 
        if (iwm_rx_addbuf(sc, IWM_RBUF_SIZE, sc->rxq.cur) != 0)
                return;
@@ -4005,9 +4095,24 @@ iwm_rx_rx_mpdu(struct iwm_softc *sc, str
 
                bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_rxtap_len, m, BPF_D_IN);
        }
-       ieee80211_input(ic, m, ni, rssi, device_timestamp);
-       ieee80211_free_node(ni);
-
+       if (ni != NULL) {
+               if (ni->ni_vap == NULL) {
+                       ieee80211_free_node(ni);
+                       splx(s);
+                       return;
+               }
+               /* push the frame up to the 802.11 stack */
+               /* NNN Convert rssi to -10 to 110 ? for 802.11 layer */
+               ieee80211_input(ni, m, rssi + 116, 0);
+
+               /* Node is no longer needed. */
+               ieee80211_free_node(ni);
+
+       } else {
+
+               /* No node found ... process differently. */
+               (void) ieee80211_input_all(ic, m, rssi + 116, 0);
+       }
        splx(s);
 }
 
@@ -4580,9 +4685,10 @@ iwm_tx_fill_cmd(struct iwm_softc *sc, st
 
 #define TB0_SIZE 16
 static int
-iwm_tx(struct iwm_softc *sc, struct mbuf *m, struct ieee80211_node *ni, int ac)
-{
-       struct ieee80211com *ic = &sc->sc_ic;
+iwm_tx(struct ieee80211vap *vap, struct mbuf *m, struct ieee80211_node *ni, int ac)
+{
+       struct ieee80211com *ic = vap->iv_ic;
+       struct iwm_softc *sc = ic->ic_softc;
        struct iwm_node *in = (struct iwm_node *)ni;
        struct iwm_tx_ring *ring;
        struct iwm_tx_data *data;
@@ -4637,15 +4743,15 @@ iwm_tx(struct iwm_softc *sc, struct mbuf
 #endif
                        tap->wt_rate = rinfo->rate;
                tap->wt_hwqueue = ac;
-               if (wh->i_fc[1] & IEEE80211_FC1_WEP)
+               if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED)
                        tap->wt_flags |= IEEE80211_RADIOTAP_F_WEP;
 
                bpf_mtap2(sc->sc_drvbpf, tap, sc->sc_txtap_len, m, BPF_D_OUT);
        }
 
        /* Encrypt the frame if need be. */
-       if (wh->i_fc[1] & IEEE80211_FC1_WEP) {
-               k = ieee80211_crypto_encap(ic, ni, m);
+       if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) {
+               k = ieee80211_crypto_encap(ni, m);
                if (k == NULL) {
                        m_freem(m);
                        return ENOBUFS;
@@ -5260,7 +5366,7 @@ iwm_fill_probe_req(struct iwm_softc *sc,
            IEEE80211_FC0_SUBTYPE_PROBE_REQ;
        wh->i_fc[1] = IEEE80211_FC1_DIR_NODS;
        IEEE80211_ADDR_COPY(wh->i_addr1, etherbroadcastaddr);
-       IEEE80211_ADDR_COPY(wh->i_addr2, ic->ic_myaddr);
+       IEEE80211_ADDR_COPY(wh->i_addr2, ic->ic_macaddr);
        IEEE80211_ADDR_COPY(wh->i_addr3, etherbroadcastaddr);
        *(uint16_t *)&wh->i_dur[0] = 0; /* filled by HW */
        *(uint16_t *)&wh->i_seq[0] = 0; /* filled by HW */
@@ -5471,7 +5577,7 @@ iwm_config_umac_scan(struct iwm_softc *s
        scan_config->out_of_channel_time = htole32(0);
        scan_config->suspend_time = htole32(0);
 
-       IEEE80211_ADDR_COPY(scan_config->mac_addr, sc->sc_ic.ic_myaddr);
+       IEEE80211_ADDR_COPY(scan_config->mac_addr, sc->sc_ic.ic_macaddr);
 
        scan_config->bcast_sta_id = IWM_AUX_STA_ID;
        scan_config->channel_flags = IWM_CHANNEL_FLAG_EBS |
@@ -5706,7 +5812,7 @@ iwm_mac_ctxt_cmd_common(struct iwm_softc
        cmd->mac_type = htole32(IWM_FW_MAC_TYPE_BSS_STA);
        cmd->tsf_id = htole32(IWM_TSF_ID_A);
 
-       IEEE80211_ADDR_COPY(cmd->node_addr, ic->ic_myaddr);
+       IEEE80211_ADDR_COPY(cmd->node_addr, ic->ic_macaddr);
        IEEE80211_ADDR_COPY(cmd->bssid_addr, ni->ni_bssid);
 
        iwm_ack_rates(sc, in, &cck_ack_rates, &ofdm_ack_rates);
@@ -6759,6 +6865,27 @@ iwm_allow_mcast(struct iwm_softc *sc)
        return err;
 }
 
+static void
+iwm_init_channels(struct ieee80211com *ic)
+{
+        uint8_t bands[IEEE80211_MODE_BYTES];
+
+        /*
+         * NNN Should be able to do something based on chip if
+         * a chip has more bands .... eg. N ... but for the future.
+         */
+
+        memset(bands, 0, sizeof(bands));
+        setbit(bands, IEEE80211_MODE_11A);
+        setbit(bands, IEEE80211_MODE_11B);
+        setbit(bands, IEEE80211_MODE_11G);
+#ifndef IEEE80211_NO_HT
+       setbit(bands, IEEE80211_MODE_11NG);
+       setbit(bands, IEEE80211_MODE_11NA);
+#endif
+        ieee80211_init_channels(ic, NULL, bands);
+}
+
 static int
 iwm_init(struct ifnet *ifp)
 {



Home | Main Index | Thread Index | Old Index