void an_stop(struct ifnet *ifp, int disable) { struct an_softc *sc = ifp->if_softc; int i, s; if (!sc->sc_enabled) return; DPRINTF(("an_stop: disable %d\n", disable)); s = splnet(); ieee80211_new_state(&sc->sc_ic, IEEE80211_S_INIT, -1); if (!sc->sc_invalid) { an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0); CSR_WRITE_2(sc, AN_INT_EN, 0); an_cmd(sc, AN_CMD_DISABLE, 0); for (i = 0; i < AN_TX_RING_CNT; i++) an_cmd(sc, AN_CMD_DEALLOC_MEM, sc->sc_txd[i].d_fid); } sc->sc_tx_timer = 0; ifp->if_timer = 0; ifp->if_flags &= ~IFF_RUNNING; ifq_clr_oactive(&ifp->if_snd); if (disable) { if (sc->sc_disable) (*sc->sc_disable)(sc); sc->sc_enabled = 0; } splx(s); }
int an_alloc_nicmem(struct an_softc *sc, int len, int *idp) { int i; if (an_cmd(sc, AN_CMD_ALLOC_MEM, len)) { printf("%s: failed to allocate %d bytes on NIC\n", sc->sc_dev.dv_xname, len); return(ENOMEM); } for (i = 0; i < AN_TIMEOUT; i++) { if (CSR_READ_2(sc, AN_EVENT_STAT) & AN_EV_ALLOC) break; if (i == AN_TIMEOUT) { printf("%s: timeout in alloc\n", sc->sc_dev.dv_xname); return ETIMEDOUT; } DELAY(10); } *idp = CSR_READ_2(sc, AN_ALLOC_FID); CSR_WRITE_2(sc, AN_EVENT_ACK, AN_EV_ALLOC); return 0; }
int an_ioctl(struct ifnet *ifp, u_long command, caddr_t data) { struct an_softc *sc = ifp->if_softc; int s, error = 0; if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0) return ENXIO; s = splnet(); switch(command) { case SIOCSIFADDR: ifp->if_flags |= IFF_UP; error = an_init(ifp); break; case SIOCSIFFLAGS: if (ifp->if_flags & IFF_UP) { if (sc->sc_enabled) { /* * To avoid rescanning another access point, * do not call an_init() here. Instead, only * reflect promisc mode settings. */ error = an_cmd(sc, AN_CMD_SET_MODE, (ifp->if_flags & IFF_PROMISC) ? 0xffff : 0); } else error = an_init(ifp); } else if (sc->sc_enabled) an_stop(ifp, 1); break; case SIOCADDMULTI: case SIOCDELMULTI: /* The Aironet has no multicast filter. */ error = 0; break; case SIOCS80211NWKEY: error = an_set_nwkey(sc, (struct ieee80211_nwkey *)data); break; case SIOCG80211NWKEY: error = an_get_nwkey(sc, (struct ieee80211_nwkey *)data); break; default: error = ieee80211_ioctl(ifp, command, data); break; } if (error == ENETRESET) { if (sc->sc_enabled) error = an_init(ifp); else error = 0; } splx(s); return(error); }
int an_reset(struct an_softc *sc) { DPRINTF(("an_reset\n")); if (!sc->sc_enabled) return ENXIO; an_cmd(sc, AN_CMD_ENABLE, 0); an_cmd(sc, AN_CMD_FW_RESTART, 0); an_cmd(sc, AN_CMD_NOOP2, 0); if (an_cmd(sc, AN_CMD_FORCE_SYNCLOSS, 0) == ETIMEDOUT) { printf("%s: reset failed\n", sc->sc_dev.dv_xname); return ETIMEDOUT; } an_cmd(sc, AN_CMD_DISABLE, 0); return 0; }
int an_write_rid(struct an_softc *sc, int rid, void *buf, int buflen) { int error; u_int16_t len; /* length in byte, including length itself */ len = buflen + 2; error = an_write_bap(sc, rid, 0, &len, sizeof(len)); if (error) return error; error = an_write_bap(sc, rid, sizeof(len), buf, buflen); if (error) return error; return an_cmd(sc, AN_CMD_ACCESS | AN_ACCESS_WRITE, rid); }
int an_read_rid(struct an_softc *sc, int rid, void *buf, int *buflenp) { int error; u_int16_t len; /* Tell the NIC to enter record read mode. */ error = an_cmd(sc, AN_CMD_ACCESS | AN_ACCESS_READ, rid); if (error) return error; /* length in byte, including length itself */ error = an_read_bap(sc, rid, 0, &len, sizeof(len), sizeof(len)); if (error) return error; len -= 2; return an_read_bap(sc, rid, sizeof(len), buf, len, *buflenp); }
int an_init(struct ifnet *ifp) { struct an_softc *sc = ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; int i, error, fid; DPRINTF(("an_init: enabled %d\n", sc->sc_enabled)); if (!sc->sc_enabled) { if (sc->sc_enable) (*sc->sc_enable)(sc); an_wait(sc); sc->sc_enabled = 1; } else { an_stop(ifp, 0); if ((error = an_reset(sc)) != 0) { printf("%s: failed to reset\n", ifp->if_xname); an_stop(ifp, 1); return error; } } CSR_WRITE_2(sc, AN_SW0, AN_MAGIC); /* Allocate the TX buffers */ for (i = 0; i < AN_TX_RING_CNT; i++) { if ((error = an_alloc_nicmem(sc, AN_TX_MAX_LEN, &fid)) != 0) { printf("%s: failed to allocate nic memory\n", ifp->if_xname); an_stop(ifp, 1); return error; } DPRINTF2(("an_init: txbuf %d allocated %x\n", i, fid)); sc->sc_txd[i].d_fid = fid; sc->sc_txd[i].d_inuse = 0; } sc->sc_txcur = sc->sc_txnext = 0; IEEE80211_ADDR_COPY(sc->sc_config.an_macaddr, ic->ic_myaddr); an_swap16((u_int16_t *)&sc->sc_config.an_macaddr, 3); sc->sc_config.an_scanmode = AN_SCANMODE_ACTIVE; sc->sc_config.an_authtype = AN_AUTHTYPE_OPEN; /*XXX*/ if (ic->ic_flags & IEEE80211_F_WEPON) { sc->sc_config.an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE; } sc->sc_config.an_listen_interval = ic->ic_lintval; sc->sc_config.an_beacon_period = ic->ic_lintval; if (ic->ic_flags & IEEE80211_F_PMGTON) sc->sc_config.an_psave_mode = AN_PSAVE_PSP; else sc->sc_config.an_psave_mode = AN_PSAVE_CAM; sc->sc_config.an_ds_channel = ieee80211_chan2ieee(ic, ic->ic_ibss_chan); switch (ic->ic_opmode) { case IEEE80211_M_STA: sc->sc_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION; sc->sc_config.an_rxmode = AN_RXMODE_BC_MC_ADDR; break; #ifndef IEEE80211_STA_ONLY case IEEE80211_M_IBSS: sc->sc_config.an_opmode = AN_OPMODE_IBSS_ADHOC; sc->sc_config.an_rxmode = AN_RXMODE_BC_MC_ADDR; break; #endif case IEEE80211_M_MONITOR: sc->sc_config.an_opmode = AN_OPMODE_INFRASTRUCTURE_STATION; sc->sc_config.an_rxmode = AN_RXMODE_80211_MONITOR_ANYBSS; sc->sc_config.an_authtype = AN_AUTHTYPE_NONE; if (ic->ic_flags & IEEE80211_F_WEPON) sc->sc_config.an_authtype |= AN_AUTHTYPE_PRIVACY_IN_USE | AN_AUTHTYPE_ALLOW_UNENCRYPTED; break; default: printf("%s: bad opmode %d\n", ifp->if_xname, ic->ic_opmode); an_stop(ifp, 1); return EIO; } sc->sc_config.an_rxmode |= AN_RXMODE_NO_8023_HEADER; /* Set the ssid list */ memset(&sc->sc_buf, 0, sizeof(sc->sc_buf.sc_ssidlist)); sc->sc_buf.sc_ssidlist.an_entry[0].an_ssid_len = ic->ic_des_esslen; if (ic->ic_des_esslen) memcpy(sc->sc_buf.sc_ssidlist.an_entry[0].an_ssid, ic->ic_des_essid, ic->ic_des_esslen); an_swap16((u_int16_t *)&sc->sc_buf.sc_ssidlist.an_entry[0].an_ssid, 16); if ((error = an_write_rid(sc, AN_RID_SSIDLIST, &sc->sc_buf, sizeof(sc->sc_buf.sc_ssidlist)))) { printf("%s: failed to write ssid list\n", ifp->if_xname); an_stop(ifp, 1); return error; } /* Set the AP list */ memset(&sc->sc_buf, 0, sizeof(sc->sc_buf.sc_aplist)); (void)an_write_rid(sc, AN_RID_APLIST, &sc->sc_buf, sizeof(sc->sc_buf.sc_aplist)); /* Set the encapsulation */ for (i = 0; i < AN_ENCAP_NENTS; i++) { sc->sc_buf.sc_encap.an_entry[i].an_ethertype = 0; sc->sc_buf.sc_encap.an_entry[i].an_action = AN_RXENCAP_RFC1024 | AN_TXENCAP_RFC1024; } (void)an_write_rid(sc, AN_RID_ENCAP, &sc->sc_buf, sizeof(sc->sc_buf.sc_encap)); /* Set the WEP Keys */ if (ic->ic_flags & IEEE80211_F_WEPON) an_write_wepkey(sc, AN_RID_WEP_VOLATILE, sc->sc_wepkeys, sc->sc_tx_key); /* Set the configuration */ if ((error = an_write_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, sizeof(sc->sc_config)))) { printf("%s: failed to write config\n", ifp->if_xname); an_stop(ifp, 1); return error; } /* Enable the MAC */ if (an_cmd(sc, AN_CMD_ENABLE, 0)) { printf("%s: failed to enable MAC\n", sc->sc_dev.dv_xname); an_stop(ifp, 1); return ENXIO; } if (ifp->if_flags & IFF_PROMISC) an_cmd(sc, AN_CMD_SET_MODE, 0xffff); ifp->if_flags |= IFF_RUNNING; ifq_clr_oactive(&ifp->if_snd); ic->ic_state = IEEE80211_S_INIT; if (ic->ic_opmode == IEEE80211_M_MONITOR) ieee80211_new_state(ic, IEEE80211_S_RUN, -1); /* enable interrupts */ CSR_WRITE_2(sc, AN_INT_EN, AN_INTRS); return 0; }
int an_attach(struct an_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &ic->ic_if; int i; struct an_rid_wepkey *akey; int buflen, kid, rid; int chan, chan_min, chan_max; sc->sc_invalid = 0; /* disable interrupts */ CSR_WRITE_2(sc, AN_INT_EN, 0); CSR_WRITE_2(sc, AN_EVENT_ACK, 0xffff); // an_wait(sc); if (an_reset(sc) != 0) { sc->sc_invalid = 1; return 1; } /* Load factory config */ if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) { printf("%s: failed to load config data\n", sc->sc_dev.dv_xname); return (EIO); } /* Read the current configuration */ buflen = sizeof(sc->sc_config); if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) { printf("%s: read config failed\n", sc->sc_dev.dv_xname); return(EIO); } an_swap16((u_int16_t *)&sc->sc_config.an_macaddr, 3); /* Read the card capabilities */ buflen = sizeof(sc->sc_caps); if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) { printf("%s: read caps failed\n", sc->sc_dev.dv_xname); return(EIO); } an_swap16((u_int16_t *)&sc->sc_caps.an_oemaddr, 3); an_swap16((u_int16_t *)&sc->sc_caps.an_rates, 4); /* Read WEP settings from persistent memory */ akey = &sc->sc_buf.sc_wepkey; buflen = sizeof(struct an_rid_wepkey); rid = AN_RID_WEP_VOLATILE; /* first persistent key */ while (an_read_rid(sc, rid, akey, &buflen) == 0) { an_swap16((u_int16_t *)&akey->an_mac_addr, 3); an_swap16((u_int16_t *)&akey->an_key, 8); kid = akey->an_key_index; DPRINTF(("an_attach: wep rid=0x%x len=%d(%d) index=0x%04x " "mac[0]=%02x keylen=%d\n", rid, buflen, sizeof(*akey), kid, akey->an_mac_addr[0], akey->an_key_len)); if (kid == 0xffff) { sc->sc_tx_perskey = akey->an_mac_addr[0]; sc->sc_tx_key = -1; break; } if (kid >= IEEE80211_WEP_NKID) break; sc->sc_perskeylen[kid] = akey->an_key_len; sc->sc_wepkeys[kid].an_wep_keylen = -1; rid = AN_RID_WEP_PERSISTENT; /* for next key */ buflen = sizeof(struct an_rid_wepkey); } IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr); bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); printf("%s: Firmware %x.%02x.%02x, Radio: ", ifp->if_xname, sc->sc_caps.an_fwrev >> 8, sc->sc_caps.an_fwrev & 0xff, sc->sc_caps.an_fwsubrev); if (sc->sc_config.an_radiotype & AN_RADIOTYPE_80211_FH) printf("802.11 FH"); else if (sc->sc_config.an_radiotype & AN_RADIOTYPE_80211_DS) printf("802.11 DS"); else if (sc->sc_config.an_radiotype & AN_RADIOTYPE_LM2000_DS) printf("LM2000 DS"); else printf("unknown (%x)", sc->sc_config.an_radiotype); printf(", address %s\n", ether_sprintf(ic->ic_myaddr)); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; ifp->if_ioctl = an_ioctl; ifp->if_start = an_start; ifp->if_watchdog = an_watchdog; ic->ic_phytype = IEEE80211_T_DS; ic->ic_opmode = IEEE80211_M_STA; ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_PMGT | IEEE80211_C_MONITOR; #ifndef IEEE80211_STA_ONLY ic->ic_caps |= IEEE80211_C_IBSS; #endif ic->ic_state = IEEE80211_S_INIT; IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr); switch (sc->sc_caps.an_regdomain) { default: case AN_REGDOMAIN_USA: case AN_REGDOMAIN_CANADA: chan_min = 1; chan_max = 11; break; case AN_REGDOMAIN_EUROPE: case AN_REGDOMAIN_AUSTRALIA: chan_min = 1; chan_max = 13; break; case AN_REGDOMAIN_JAPAN: chan_min = 14; chan_max = 14; break; case AN_REGDOMAIN_SPAIN: chan_min = 10; chan_max = 11; break; case AN_REGDOMAIN_FRANCE: chan_min = 10; chan_max = 13; break; case AN_REGDOMAIN_JAPANWIDE: chan_min = 1; chan_max = 14; break; } for (chan = chan_min; chan <= chan_max; chan++) { ic->ic_channels[chan].ic_freq = ieee80211_ieee2mhz(chan, IEEE80211_CHAN_2GHZ); ic->ic_channels[chan].ic_flags = IEEE80211_CHAN_B; } ic->ic_ibss_chan = &ic->ic_channels[chan_min]; /* Find supported rate */ for (i = 0; i < sizeof(sc->sc_caps.an_rates); i++) { if (sc->sc_caps.an_rates[i] == 0) continue; ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[ ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates++] = sc->sc_caps.an_rates[i]; } /* * Call MI attach routine. */ if_attach(ifp); ieee80211_ifattach(ifp); sc->sc_newstate = ic->ic_newstate; ic->ic_newstate = an_newstate; ieee80211_media_init(ifp, an_media_change, an_media_status); #if NBPFILTER > 0 bzero(&sc->sc_rxtapu, sizeof(sc->sc_rxtapu)); sc->sc_rxtap.ar_ihdr.it_len = sizeof(sc->sc_rxtapu); sc->sc_rxtap.ar_ihdr.it_present = AN_RX_RADIOTAP_PRESENT; bzero(&sc->sc_txtapu, sizeof(sc->sc_txtapu)); sc->sc_txtap.at_ihdr.it_len = sizeof(sc->sc_txtapu); sc->sc_txtap.at_ihdr.it_present = AN_TX_RADIOTAP_PRESENT; bpfattach(&sc->sc_drvbpf, ifp, DLT_IEEE802_11_RADIO, sizeof(struct ieee80211_frame) + 64); #endif sc->sc_attached = 1; return(0); }
int an_set_nwkey_wep(struct an_softc *sc, struct ieee80211_nwkey *nwkey) { int i, txkey, anysetkey, needreset, error; struct an_wepkey keys[IEEE80211_WEP_NKID]; error = 0; memset(keys, 0, sizeof(keys)); anysetkey = needreset = 0; /* load argument and sanity check */ for (i = 0; i < IEEE80211_WEP_NKID; i++) { keys[i].an_wep_keylen = nwkey->i_key[i].i_keylen; if (keys[i].an_wep_keylen < 0) continue; if (keys[i].an_wep_keylen != 0 && keys[i].an_wep_keylen < IEEE80211_WEP_KEYLEN) return EINVAL; if (keys[i].an_wep_keylen > sizeof(keys[i].an_wep_key)) return EINVAL; if ((error = copyin(nwkey->i_key[i].i_keydat, keys[i].an_wep_key, keys[i].an_wep_keylen)) != 0) return error; anysetkey++; } txkey = nwkey->i_defkid - 1; if (txkey >= 0) { if (txkey >= IEEE80211_WEP_NKID) return EINVAL; /* default key must have a valid value */ if (keys[txkey].an_wep_keylen == 0 || (keys[txkey].an_wep_keylen < 0 && sc->sc_perskeylen[txkey] == 0)) return EINVAL; anysetkey++; } DPRINTF(("an_set_nwkey_wep: %s: %sold(%d:%d,%d,%d,%d) " "pers(%d:%d,%d,%d,%d) new(%d:%d,%d,%d,%d)\n", sc->sc_dev.dv_xname, ((nwkey->i_wepon & IEEE80211_NWKEY_PERSIST) ? "persist: " : ""), sc->sc_tx_key, sc->sc_wepkeys[0].an_wep_keylen, sc->sc_wepkeys[1].an_wep_keylen, sc->sc_wepkeys[2].an_wep_keylen, sc->sc_wepkeys[3].an_wep_keylen, sc->sc_tx_perskey, sc->sc_perskeylen[0], sc->sc_perskeylen[1], sc->sc_perskeylen[2], sc->sc_perskeylen[3], txkey, keys[0].an_wep_keylen, keys[1].an_wep_keylen, keys[2].an_wep_keylen, keys[3].an_wep_keylen)); if (!(nwkey->i_wepon & IEEE80211_NWKEY_PERSIST)) { /* set temporary keys */ sc->sc_tx_key = txkey; for (i = 0; i < IEEE80211_WEP_NKID; i++) { if (keys[i].an_wep_keylen < 0) continue; memcpy(&sc->sc_wepkeys[i], &keys[i], sizeof(keys[i])); } } else { /* set persist keys */ if (anysetkey) { /* prepare to write nvram */ if (!sc->sc_enabled) { if (sc->sc_enable) (*sc->sc_enable)(sc); an_wait(sc); sc->sc_enabled = 1; error = an_write_wepkey(sc, AN_RID_WEP_PERSISTENT, keys, txkey); if (sc->sc_disable) (*sc->sc_disable)(sc); sc->sc_enabled = 0; } else { an_cmd(sc, AN_CMD_DISABLE, 0); error = an_write_wepkey(sc, AN_RID_WEP_PERSISTENT, keys, txkey); an_cmd(sc, AN_CMD_ENABLE, 0); } if (error) return error; } if (txkey >= 0) sc->sc_tx_perskey = txkey; if (sc->sc_tx_key >= 0) { sc->sc_tx_key = -1; needreset++; } for (i = 0; i < IEEE80211_WEP_NKID; i++) { if (sc->sc_wepkeys[i].an_wep_keylen >= 0) { memset(&sc->sc_wepkeys[i].an_wep_key, 0, sizeof(sc->sc_wepkeys[i].an_wep_key)); sc->sc_wepkeys[i].an_wep_keylen = -1; needreset++; } if (keys[i].an_wep_keylen >= 0) sc->sc_perskeylen[i] = keys[i].an_wep_keylen; } } if (needreset) { /* firmware restart to reload persistent key */ an_reset(sc); } if (anysetkey || needreset) error = ENETRESET; return error; }
void an_start(struct ifnet *ifp) { struct an_softc *sc = (struct an_softc *)ifp->if_softc; struct ieee80211com *ic = &sc->sc_ic; struct ieee80211_node *ni; struct ieee80211_frame *wh; struct an_txframe frmhdr; struct mbuf *m; u_int16_t len; int cur, fid; if (!sc->sc_enabled || sc->sc_invalid) { DPRINTF(("an_start: noop: enabled %d invalid %d\n", sc->sc_enabled, sc->sc_invalid)); return; } memset(&frmhdr, 0, sizeof(frmhdr)); cur = sc->sc_txnext; for (;;) { if (ic->ic_state != IEEE80211_S_RUN) { DPRINTF(("an_start: not running %d\n", ic->ic_state)); break; } m = ifq_deq_begin(&ifp->if_snd); if (m == NULL) { DPRINTF2(("an_start: no pending mbuf\n")); break; } if (sc->sc_txd[cur].d_inuse) { ifq_deq_rollback(&ifp->if_snd, m); DPRINTF2(("an_start: %x/%d busy\n", sc->sc_txd[cur].d_fid, cur)); ifq_set_oactive(&ifp->if_snd); break; } ifq_deq_commit(&ifp->if_snd, m); ifp->if_opackets++; #if NBPFILTER > 0 if (ifp->if_bpf) bpf_mtap(ifp->if_bpf, m, BPF_DIRECTION_OUT); #endif if ((m = ieee80211_encap(ifp, m, &ni)) == NULL) { ifp->if_oerrors++; continue; } if (ni != NULL) ieee80211_release_node(ic, ni); #if NBPFILTER > 0 if (ic->ic_rawbpf) bpf_mtap(ic->ic_rawbpf, m, BPF_DIRECTION_OUT); #endif wh = mtod(m, struct ieee80211_frame *); if (ic->ic_flags & IEEE80211_F_WEPON) wh->i_fc[1] |= IEEE80211_FC1_WEP; m_copydata(m, 0, sizeof(struct ieee80211_frame), (caddr_t)&frmhdr.an_whdr); an_swap16((u_int16_t *)&frmhdr.an_whdr, sizeof(struct ieee80211_frame)/2); /* insert payload length in front of llc/snap */ len = htons(m->m_pkthdr.len - sizeof(struct ieee80211_frame)); m_adj(m, sizeof(struct ieee80211_frame) - sizeof(len)); if (mtod(m, u_long) & 0x01) memcpy(mtod(m, caddr_t), &len, sizeof(len)); else *mtod(m, u_int16_t *) = len; /* * XXX Aironet firmware apparently convert the packet * with longer than 1500 bytes in length into LLC/SNAP. * If we have 1500 bytes in ethernet payload, it is * 1508 bytes including LLC/SNAP and will be inserted * additional LLC/SNAP header with 1501-1508 in its * ethertype !! * So we skip LLC/SNAP header and force firmware to * convert it to LLC/SNAP again. */ m_adj(m, sizeof(struct llc)); frmhdr.an_tx_ctl = AN_TXCTL_80211; frmhdr.an_tx_payload_len = m->m_pkthdr.len; frmhdr.an_gaplen = AN_TXGAP_802_11; if (ic->ic_fixed_rate != -1) frmhdr.an_tx_rate = ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[ ic->ic_fixed_rate] & IEEE80211_RATE_VAL; else frmhdr.an_tx_rate = 0; if (sizeof(frmhdr) + AN_TXGAP_802_11 + sizeof(len) + m->m_pkthdr.len > AN_TX_MAX_LEN) { ifp->if_oerrors++; m_freem(m); continue; } #if NBPFILTER > 0 if (sc->sc_drvbpf) { struct mbuf mb; struct an_tx_radiotap_header *tap = &sc->sc_txtap; tap->at_rate = ic->ic_bss->ni_rates.rs_rates[ic->ic_bss->ni_txrate]; tap->at_chan_freq = ic->ic_bss->ni_chan->ic_freq; tap->at_chan_flags = ic->ic_bss->ni_chan->ic_flags; mb.m_data = (caddr_t)tap; mb.m_len = sizeof(sc->sc_txtapu); mb.m_next = m; mb.m_nextpkt = NULL; mb.m_type = 0; mb.m_flags = 0; bpf_mtap(sc->sc_drvbpf, m, BPF_DIRECTION_OUT); } #endif fid = sc->sc_txd[cur].d_fid; if (an_write_bap(sc, fid, 0, &frmhdr, sizeof(frmhdr)) != 0) { ifp->if_oerrors++; m_freem(m); continue; } /* dummy write to avoid seek. */ an_write_bap(sc, fid, -1, &frmhdr, AN_TXGAP_802_11); an_mwrite_bap(sc, fid, -1, m, m->m_pkthdr.len); m_freem(m); DPRINTF2(("an_start: send %d byte via %x/%d\n", ntohs(len) + sizeof(struct ieee80211_frame), fid, cur)); sc->sc_txd[cur].d_inuse = 1; if (an_cmd(sc, AN_CMD_TX, fid)) { printf("%s: xmit failed\n", ifp->if_xname); sc->sc_txd[cur].d_inuse = 0; continue; } sc->sc_tx_timer = 5; ifp->if_timer = 1; AN_INC(cur, AN_TX_RING_CNT); sc->sc_txnext = cur; } }
int an_attach(struct an_softc *sc) { struct ieee80211com *ic = &sc->sc_ic; struct ifnet *ifp = &sc->sc_if; int i, s; struct an_rid_wepkey *akey; int buflen, kid, rid; int chan, chan_min, chan_max; s = splnet(); sc->sc_invalid = 0; an_wait(sc); if (an_reset(sc) != 0) { sc->sc_invalid = 1; splx(s); return 1; } /* Load factory config */ if (an_cmd(sc, AN_CMD_READCFG, 0) != 0) { splx(s); aprint_error_dev(sc->sc_dev, "failed to load config data\n"); return 1; } /* Read the current configuration */ buflen = sizeof(sc->sc_config); if (an_read_rid(sc, AN_RID_GENCONFIG, &sc->sc_config, &buflen) != 0) { splx(s); aprint_error_dev(sc->sc_dev, "read config failed\n"); return 1; } /* Read the card capabilities */ buflen = sizeof(sc->sc_caps); if (an_read_rid(sc, AN_RID_CAPABILITIES, &sc->sc_caps, &buflen) != 0) { splx(s); aprint_error_dev(sc->sc_dev, "read caps failed\n"); return 1; } #ifdef AN_DEBUG if (an_debug) { static const int dumprid[] = { AN_RID_GENCONFIG, AN_RID_CAPABILITIES, AN_RID_SSIDLIST, AN_RID_APLIST, AN_RID_STATUS, AN_RID_ENCAP }; for (rid = 0; rid < sizeof(dumprid)/sizeof(dumprid[0]); rid++) { buflen = sizeof(sc->sc_buf); if (an_read_rid(sc, dumprid[rid], &sc->sc_buf, &buflen) != 0) continue; printf("%04x (%d):\n", dumprid[rid], buflen); for (i = 0; i < (buflen + 1) / 2; i++) printf(" %04x", sc->sc_buf.sc_val[i]); printf("\n"); } } #endif /* Read WEP settings from persistent memory */ akey = &sc->sc_buf.sc_wepkey; buflen = sizeof(struct an_rid_wepkey); rid = AN_RID_WEP_VOLATILE; /* first persistent key */ while (an_read_rid(sc, rid, akey, &buflen) == 0) { kid = le16toh(akey->an_key_index); DPRINTF(("an_attach: wep rid=0x%x len=%d(%zu) index=0x%04x " "mac[0]=%02x keylen=%d\n", rid, buflen, sizeof(*akey), kid, akey->an_mac_addr[0], le16toh(akey->an_key_len))); if (kid == 0xffff) { sc->sc_tx_perskey = akey->an_mac_addr[0]; sc->sc_tx_key = -1; break; } if (kid >= IEEE80211_WEP_NKID) break; sc->sc_perskeylen[kid] = le16toh(akey->an_key_len); sc->sc_wepkeys[kid].an_wep_keylen = -1; rid = AN_RID_WEP_PERSISTENT; /* for next key */ buflen = sizeof(struct an_rid_wepkey); } aprint_normal_dev(sc->sc_dev, "%s %s (firmware %s)\n", sc->sc_caps.an_manufname, sc->sc_caps.an_prodname, sc->sc_caps.an_prodvers); memcpy(ifp->if_xname, device_xname(sc->sc_dev), IFNAMSIZ); ifp->if_softc = sc; ifp->if_flags = IFF_BROADCAST | IFF_NOTRAILERS | IFF_SIMPLEX | IFF_MULTICAST | IFF_ALLMULTI; ifp->if_ioctl = an_ioctl; ifp->if_start = an_start; ifp->if_init = an_init; ifp->if_stop = an_stop; ifp->if_watchdog = an_watchdog; IFQ_SET_READY(&ifp->if_snd); ic->ic_ifp = ifp; ic->ic_phytype = IEEE80211_T_DS; ic->ic_opmode = IEEE80211_M_STA; ic->ic_caps = IEEE80211_C_WEP | IEEE80211_C_PMGT | IEEE80211_C_IBSS | IEEE80211_C_MONITOR; ic->ic_state = IEEE80211_S_INIT; IEEE80211_ADDR_COPY(ic->ic_myaddr, sc->sc_caps.an_oemaddr); switch (le16toh(sc->sc_caps.an_regdomain)) { default: case AN_REGDOMAIN_USA: case AN_REGDOMAIN_CANADA: chan_min = 1; chan_max = 11; break; case AN_REGDOMAIN_EUROPE: case AN_REGDOMAIN_AUSTRALIA: chan_min = 1; chan_max = 13; break; case AN_REGDOMAIN_JAPAN: chan_min = 14; chan_max = 14; break; case AN_REGDOMAIN_SPAIN: chan_min = 10; chan_max = 11; break; case AN_REGDOMAIN_FRANCE: chan_min = 10; chan_max = 13; break; case AN_REGDOMAIN_JAPANWIDE: chan_min = 1; chan_max = 14; break; } for (chan = chan_min; chan <= chan_max; chan++) { ic->ic_channels[chan].ic_freq = ieee80211_ieee2mhz(chan, IEEE80211_CHAN_2GHZ); ic->ic_channels[chan].ic_flags = IEEE80211_CHAN_B; } ic->ic_ibss_chan = &ic->ic_channels[chan_min]; aprint_normal("%s: 802.11 address: %s, channel: %d-%d\n", ifp->if_xname, ether_sprintf(ic->ic_myaddr), chan_min, chan_max); /* Find supported rate */ for (i = 0; i < sizeof(sc->sc_caps.an_rates); i++) { if (sc->sc_caps.an_rates[i] == 0) continue; ic->ic_sup_rates[IEEE80211_MODE_11B].rs_rates[ ic->ic_sup_rates[IEEE80211_MODE_11B].rs_nrates++] = sc->sc_caps.an_rates[i]; } /* * Call MI attach routine. */ if_attach(ifp); ieee80211_ifattach(ic); sc->sc_newstate = ic->ic_newstate; ic->ic_newstate = an_newstate; ieee80211_media_init(ic, an_media_change, an_media_status); /* * radiotap BPF device */ #if NBPFILTER > 0 bpfattach2(ifp, DLT_IEEE802_11_RADIO, sizeof(struct ieee80211_frame) + 64, &sc->sc_drvbpf); #endif memset(&sc->sc_rxtapu, 0, sizeof(sc->sc_rxtapu)); sc->sc_rxtap.ar_ihdr.it_len = htole16(sizeof(sc->sc_rxtapu)); sc->sc_rxtap.ar_ihdr.it_present = htole32(AN_RX_RADIOTAP_PRESENT); memset(&sc->sc_txtapu, 0, sizeof(sc->sc_txtapu)); sc->sc_txtap.at_ihdr.it_len = htole16(sizeof(sc->sc_txtapu)); sc->sc_txtap.at_ihdr.it_present = htole32(AN_TX_RADIOTAP_PRESENT); sc->sc_attached = 1; splx(s); ieee80211_announce(ic); return 0; }