29#endif 30 31/* 32 * IEEE 802.11 IBSS mode support. 33 */ 34#include "opt_inet.h" 35#include "opt_wlan.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/mbuf.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42 43#include <sys/socket.h> 44#include <sys/sockio.h> 45#include <sys/endian.h> 46#include <sys/errno.h> 47#include <sys/proc.h> 48#include <sys/sysctl.h> 49 50#include <net/if.h> 51#include <net/if_var.h> 52#include <net/if_media.h> 53#include <net/if_llc.h> 54#include <net/ethernet.h> 55 56#include <net/bpf.h> 57 58#include <net80211/ieee80211_var.h> 59#include <net80211/ieee80211_adhoc.h> 60#include <net80211/ieee80211_input.h> 61#ifdef IEEE80211_SUPPORT_SUPERG 62#include <net80211/ieee80211_superg.h> 63#endif 64#ifdef IEEE80211_SUPPORT_TDMA 65#include <net80211/ieee80211_tdma.h> 66#endif 67#include <net80211/ieee80211_sta.h> 68 69#define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) 70 71static void adhoc_vattach(struct ieee80211vap *); 72static int adhoc_newstate(struct ieee80211vap *, enum ieee80211_state, int); 73static int adhoc_input(struct ieee80211_node *, struct mbuf *, int, int); 74static void adhoc_recv_mgmt(struct ieee80211_node *, struct mbuf *, 75 int subtype, int, int); 76static void ahdemo_recv_mgmt(struct ieee80211_node *, struct mbuf *, 77 int subtype, int, int); 78static void adhoc_recv_ctl(struct ieee80211_node *, struct mbuf *, int subtype); 79 80void 81ieee80211_adhoc_attach(struct ieee80211com *ic) 82{ 83 ic->ic_vattach[IEEE80211_M_IBSS] = adhoc_vattach; 84 ic->ic_vattach[IEEE80211_M_AHDEMO] = adhoc_vattach; 85} 86 87void 88ieee80211_adhoc_detach(struct ieee80211com *ic) 89{ 90} 91 92static void 93adhoc_vdetach(struct ieee80211vap *vap) 94{ 95} 96 97static void 98adhoc_vattach(struct ieee80211vap *vap) 99{ 100 vap->iv_newstate = adhoc_newstate; 101 vap->iv_input = adhoc_input; 102 if (vap->iv_opmode == IEEE80211_M_IBSS) 103 vap->iv_recv_mgmt = adhoc_recv_mgmt; 104 else 105 vap->iv_recv_mgmt = ahdemo_recv_mgmt; 106 vap->iv_recv_ctl = adhoc_recv_ctl; 107 vap->iv_opdetach = adhoc_vdetach; 108#ifdef IEEE80211_SUPPORT_TDMA 109 /* 110 * Throw control to tdma support. Note we do this 111 * after setting up our callbacks so it can piggyback 112 * on top of us. 113 */ 114 if (vap->iv_caps & IEEE80211_C_TDMA) 115 ieee80211_tdma_vattach(vap); 116#endif 117} 118 119static void 120sta_leave(void *arg, struct ieee80211_node *ni) 121{ 122 struct ieee80211vap *vap = arg; 123 124 if (ni->ni_vap == vap && ni != vap->iv_bss) 125 ieee80211_node_leave(ni); 126} 127 128/* 129 * IEEE80211_M_IBSS+IEEE80211_M_AHDEMO vap state machine handler. 130 */ 131static int 132adhoc_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 133{ 134 struct ieee80211com *ic = vap->iv_ic; 135 struct ieee80211_node *ni; 136 enum ieee80211_state ostate; 137 138 IEEE80211_LOCK_ASSERT(vap->iv_ic); 139 140 ostate = vap->iv_state; 141 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n", 142 __func__, ieee80211_state_name[ostate], 143 ieee80211_state_name[nstate], arg); 144 vap->iv_state = nstate; /* state transition */ 145 if (ostate != IEEE80211_S_SCAN) 146 ieee80211_cancel_scan(vap); /* background scan */ 147 ni = vap->iv_bss; /* NB: no reference held */ 148 switch (nstate) { 149 case IEEE80211_S_INIT: 150 switch (ostate) { 151 case IEEE80211_S_SCAN: 152 ieee80211_cancel_scan(vap); 153 break; 154 default: 155 break; 156 } 157 if (ostate != IEEE80211_S_INIT) { 158 /* NB: optimize INIT -> INIT case */ 159 ieee80211_reset_bss(vap); 160 } 161 break; 162 case IEEE80211_S_SCAN: 163 switch (ostate) { 164 case IEEE80211_S_RUN: /* beacon miss */ 165 /* purge station table; entries are stale */ 166 ieee80211_iterate_nodes(&ic->ic_sta, sta_leave, vap); 167 /* fall thru... */ 168 case IEEE80211_S_INIT: 169 if (vap->iv_des_chan != IEEE80211_CHAN_ANYC && 170 !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) { 171 /* 172 * Already have a channel; bypass the 173 * scan and startup immediately. 174 */ 175 ieee80211_create_ibss(vap, 176 ieee80211_ht_adjust_channel(ic, 177 vap->iv_des_chan, vap->iv_flags_ht)); 178 break; 179 } 180 /* 181 * Initiate a scan. We can come here as a result 182 * of an IEEE80211_IOC_SCAN_REQ too in which case 183 * the vap will be marked with IEEE80211_FEXT_SCANREQ 184 * and the scan request parameters will be present 185 * in iv_scanreq. Otherwise we do the default. 186 */ 187 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) { 188 ieee80211_check_scan(vap, 189 vap->iv_scanreq_flags, 190 vap->iv_scanreq_duration, 191 vap->iv_scanreq_mindwell, 192 vap->iv_scanreq_maxdwell, 193 vap->iv_scanreq_nssid, vap->iv_scanreq_ssid); 194 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ; 195 } else 196 ieee80211_check_scan_current(vap); 197 break; 198 case IEEE80211_S_SCAN: 199 /* 200 * This can happen because of a change in state 201 * that requires a reset. Trigger a new scan 202 * unless we're in manual roaming mode in which 203 * case an application must issue an explicit request. 204 */ 205 if (vap->iv_roaming == IEEE80211_ROAMING_AUTO) 206 ieee80211_check_scan_current(vap); 207 break; 208 default: 209 goto invalid; 210 } 211 break; 212 case IEEE80211_S_RUN: 213 if (vap->iv_flags & IEEE80211_F_WPA) { 214 /* XXX validate prerequisites */ 215 } 216 switch (ostate) { 217 case IEEE80211_S_SCAN: 218#ifdef IEEE80211_DEBUG 219 if (ieee80211_msg_debug(vap)) { 220 ieee80211_note(vap, 221 "synchronized with %s ssid ", 222 ether_sprintf(ni->ni_bssid)); 223 ieee80211_print_essid(vap->iv_bss->ni_essid, 224 ni->ni_esslen); 225 /* XXX MCS/HT */ 226 printf(" channel %d start %uMb\n", 227 ieee80211_chan2ieee(ic, ic->ic_curchan), 228 IEEE80211_RATE2MBS(ni->ni_txrate)); 229 } 230#endif 231 break; 232 case IEEE80211_S_RUN: /* IBSS merge */ 233 break; 234 default: 235 goto invalid; 236 } 237 /* 238 * When 802.1x is not in use mark the port authorized 239 * at this point so traffic can flow. 240 */ 241 if (ni->ni_authmode != IEEE80211_AUTH_8021X) 242 ieee80211_node_authorize(ni); 243 /* 244 * Fake association when joining an existing bss. 245 */ 246 if (!IEEE80211_ADDR_EQ(ni->ni_macaddr, vap->iv_myaddr) && 247 ic->ic_newassoc != NULL) 248 ic->ic_newassoc(ni, ostate != IEEE80211_S_RUN); 249 break; 250 case IEEE80211_S_SLEEP: 251 vap->iv_sta_ps(vap, 0); 252 break; 253 default: 254 invalid: 255 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 256 "%s: unexpected state transition %s -> %s\n", __func__, 257 ieee80211_state_name[ostate], ieee80211_state_name[nstate]); 258 break; 259 } 260 return 0; 261} 262 263/* 264 * Decide if a received management frame should be 265 * printed when debugging is enabled. This filters some 266 * of the less interesting frames that come frequently 267 * (e.g. beacons). 268 */ 269static __inline int 270doprint(struct ieee80211vap *vap, int subtype) 271{ 272 switch (subtype) { 273 case IEEE80211_FC0_SUBTYPE_BEACON: 274 return (vap->iv_ic->ic_flags & IEEE80211_F_SCAN); 275 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 276 return 1; 277 } 278 return 1; 279} 280 281/* 282 * Process a received frame. The node associated with the sender 283 * should be supplied. If nothing was found in the node table then 284 * the caller is assumed to supply a reference to iv_bss instead. 285 * The RSSI and a timestamp are also supplied. The RSSI data is used 286 * during AP scanning to select a AP to associate with; it can have 287 * any units so long as values have consistent units and higher values 288 * mean ``better signal''. The receive timestamp is currently not used 289 * by the 802.11 layer. 290 */ 291static int 292adhoc_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf) 293{
| 29#endif 30 31/* 32 * IEEE 802.11 IBSS mode support. 33 */ 34#include "opt_inet.h" 35#include "opt_wlan.h" 36 37#include <sys/param.h> 38#include <sys/systm.h> 39#include <sys/mbuf.h> 40#include <sys/malloc.h> 41#include <sys/kernel.h> 42 43#include <sys/socket.h> 44#include <sys/sockio.h> 45#include <sys/endian.h> 46#include <sys/errno.h> 47#include <sys/proc.h> 48#include <sys/sysctl.h> 49 50#include <net/if.h> 51#include <net/if_var.h> 52#include <net/if_media.h> 53#include <net/if_llc.h> 54#include <net/ethernet.h> 55 56#include <net/bpf.h> 57 58#include <net80211/ieee80211_var.h> 59#include <net80211/ieee80211_adhoc.h> 60#include <net80211/ieee80211_input.h> 61#ifdef IEEE80211_SUPPORT_SUPERG 62#include <net80211/ieee80211_superg.h> 63#endif 64#ifdef IEEE80211_SUPPORT_TDMA 65#include <net80211/ieee80211_tdma.h> 66#endif 67#include <net80211/ieee80211_sta.h> 68 69#define IEEE80211_RATE2MBS(r) (((r) & IEEE80211_RATE_VAL) / 2) 70 71static void adhoc_vattach(struct ieee80211vap *); 72static int adhoc_newstate(struct ieee80211vap *, enum ieee80211_state, int); 73static int adhoc_input(struct ieee80211_node *, struct mbuf *, int, int); 74static void adhoc_recv_mgmt(struct ieee80211_node *, struct mbuf *, 75 int subtype, int, int); 76static void ahdemo_recv_mgmt(struct ieee80211_node *, struct mbuf *, 77 int subtype, int, int); 78static void adhoc_recv_ctl(struct ieee80211_node *, struct mbuf *, int subtype); 79 80void 81ieee80211_adhoc_attach(struct ieee80211com *ic) 82{ 83 ic->ic_vattach[IEEE80211_M_IBSS] = adhoc_vattach; 84 ic->ic_vattach[IEEE80211_M_AHDEMO] = adhoc_vattach; 85} 86 87void 88ieee80211_adhoc_detach(struct ieee80211com *ic) 89{ 90} 91 92static void 93adhoc_vdetach(struct ieee80211vap *vap) 94{ 95} 96 97static void 98adhoc_vattach(struct ieee80211vap *vap) 99{ 100 vap->iv_newstate = adhoc_newstate; 101 vap->iv_input = adhoc_input; 102 if (vap->iv_opmode == IEEE80211_M_IBSS) 103 vap->iv_recv_mgmt = adhoc_recv_mgmt; 104 else 105 vap->iv_recv_mgmt = ahdemo_recv_mgmt; 106 vap->iv_recv_ctl = adhoc_recv_ctl; 107 vap->iv_opdetach = adhoc_vdetach; 108#ifdef IEEE80211_SUPPORT_TDMA 109 /* 110 * Throw control to tdma support. Note we do this 111 * after setting up our callbacks so it can piggyback 112 * on top of us. 113 */ 114 if (vap->iv_caps & IEEE80211_C_TDMA) 115 ieee80211_tdma_vattach(vap); 116#endif 117} 118 119static void 120sta_leave(void *arg, struct ieee80211_node *ni) 121{ 122 struct ieee80211vap *vap = arg; 123 124 if (ni->ni_vap == vap && ni != vap->iv_bss) 125 ieee80211_node_leave(ni); 126} 127 128/* 129 * IEEE80211_M_IBSS+IEEE80211_M_AHDEMO vap state machine handler. 130 */ 131static int 132adhoc_newstate(struct ieee80211vap *vap, enum ieee80211_state nstate, int arg) 133{ 134 struct ieee80211com *ic = vap->iv_ic; 135 struct ieee80211_node *ni; 136 enum ieee80211_state ostate; 137 138 IEEE80211_LOCK_ASSERT(vap->iv_ic); 139 140 ostate = vap->iv_state; 141 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, "%s: %s -> %s (%d)\n", 142 __func__, ieee80211_state_name[ostate], 143 ieee80211_state_name[nstate], arg); 144 vap->iv_state = nstate; /* state transition */ 145 if (ostate != IEEE80211_S_SCAN) 146 ieee80211_cancel_scan(vap); /* background scan */ 147 ni = vap->iv_bss; /* NB: no reference held */ 148 switch (nstate) { 149 case IEEE80211_S_INIT: 150 switch (ostate) { 151 case IEEE80211_S_SCAN: 152 ieee80211_cancel_scan(vap); 153 break; 154 default: 155 break; 156 } 157 if (ostate != IEEE80211_S_INIT) { 158 /* NB: optimize INIT -> INIT case */ 159 ieee80211_reset_bss(vap); 160 } 161 break; 162 case IEEE80211_S_SCAN: 163 switch (ostate) { 164 case IEEE80211_S_RUN: /* beacon miss */ 165 /* purge station table; entries are stale */ 166 ieee80211_iterate_nodes(&ic->ic_sta, sta_leave, vap); 167 /* fall thru... */ 168 case IEEE80211_S_INIT: 169 if (vap->iv_des_chan != IEEE80211_CHAN_ANYC && 170 !IEEE80211_IS_CHAN_RADAR(vap->iv_des_chan)) { 171 /* 172 * Already have a channel; bypass the 173 * scan and startup immediately. 174 */ 175 ieee80211_create_ibss(vap, 176 ieee80211_ht_adjust_channel(ic, 177 vap->iv_des_chan, vap->iv_flags_ht)); 178 break; 179 } 180 /* 181 * Initiate a scan. We can come here as a result 182 * of an IEEE80211_IOC_SCAN_REQ too in which case 183 * the vap will be marked with IEEE80211_FEXT_SCANREQ 184 * and the scan request parameters will be present 185 * in iv_scanreq. Otherwise we do the default. 186 */ 187 if (vap->iv_flags_ext & IEEE80211_FEXT_SCANREQ) { 188 ieee80211_check_scan(vap, 189 vap->iv_scanreq_flags, 190 vap->iv_scanreq_duration, 191 vap->iv_scanreq_mindwell, 192 vap->iv_scanreq_maxdwell, 193 vap->iv_scanreq_nssid, vap->iv_scanreq_ssid); 194 vap->iv_flags_ext &= ~IEEE80211_FEXT_SCANREQ; 195 } else 196 ieee80211_check_scan_current(vap); 197 break; 198 case IEEE80211_S_SCAN: 199 /* 200 * This can happen because of a change in state 201 * that requires a reset. Trigger a new scan 202 * unless we're in manual roaming mode in which 203 * case an application must issue an explicit request. 204 */ 205 if (vap->iv_roaming == IEEE80211_ROAMING_AUTO) 206 ieee80211_check_scan_current(vap); 207 break; 208 default: 209 goto invalid; 210 } 211 break; 212 case IEEE80211_S_RUN: 213 if (vap->iv_flags & IEEE80211_F_WPA) { 214 /* XXX validate prerequisites */ 215 } 216 switch (ostate) { 217 case IEEE80211_S_SCAN: 218#ifdef IEEE80211_DEBUG 219 if (ieee80211_msg_debug(vap)) { 220 ieee80211_note(vap, 221 "synchronized with %s ssid ", 222 ether_sprintf(ni->ni_bssid)); 223 ieee80211_print_essid(vap->iv_bss->ni_essid, 224 ni->ni_esslen); 225 /* XXX MCS/HT */ 226 printf(" channel %d start %uMb\n", 227 ieee80211_chan2ieee(ic, ic->ic_curchan), 228 IEEE80211_RATE2MBS(ni->ni_txrate)); 229 } 230#endif 231 break; 232 case IEEE80211_S_RUN: /* IBSS merge */ 233 break; 234 default: 235 goto invalid; 236 } 237 /* 238 * When 802.1x is not in use mark the port authorized 239 * at this point so traffic can flow. 240 */ 241 if (ni->ni_authmode != IEEE80211_AUTH_8021X) 242 ieee80211_node_authorize(ni); 243 /* 244 * Fake association when joining an existing bss. 245 */ 246 if (!IEEE80211_ADDR_EQ(ni->ni_macaddr, vap->iv_myaddr) && 247 ic->ic_newassoc != NULL) 248 ic->ic_newassoc(ni, ostate != IEEE80211_S_RUN); 249 break; 250 case IEEE80211_S_SLEEP: 251 vap->iv_sta_ps(vap, 0); 252 break; 253 default: 254 invalid: 255 IEEE80211_DPRINTF(vap, IEEE80211_MSG_STATE, 256 "%s: unexpected state transition %s -> %s\n", __func__, 257 ieee80211_state_name[ostate], ieee80211_state_name[nstate]); 258 break; 259 } 260 return 0; 261} 262 263/* 264 * Decide if a received management frame should be 265 * printed when debugging is enabled. This filters some 266 * of the less interesting frames that come frequently 267 * (e.g. beacons). 268 */ 269static __inline int 270doprint(struct ieee80211vap *vap, int subtype) 271{ 272 switch (subtype) { 273 case IEEE80211_FC0_SUBTYPE_BEACON: 274 return (vap->iv_ic->ic_flags & IEEE80211_F_SCAN); 275 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 276 return 1; 277 } 278 return 1; 279} 280 281/* 282 * Process a received frame. The node associated with the sender 283 * should be supplied. If nothing was found in the node table then 284 * the caller is assumed to supply a reference to iv_bss instead. 285 * The RSSI and a timestamp are also supplied. The RSSI data is used 286 * during AP scanning to select a AP to associate with; it can have 287 * any units so long as values have consistent units and higher values 288 * mean ``better signal''. The receive timestamp is currently not used 289 * by the 802.11 layer. 290 */ 291static int 292adhoc_input(struct ieee80211_node *ni, struct mbuf *m, int rssi, int nf) 293{
|
418 uint8_t tid = ieee80211_gettid(wh); 419 if (IEEE80211_QOS_HAS_SEQ(wh) && 420 TID_TO_WME_AC(tid) >= WME_AC_VI) 421 ic->ic_wme.wme_hipri_traffic++; 422 rxseq = le16toh(*(uint16_t *)wh->i_seq); 423 if (! ieee80211_check_rxseq(ni, wh)) { 424 /* duplicate, discard */ 425 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 426 bssid, "duplicate", 427 "seqno <%u,%u> fragno <%u,%u> tid %u", 428 rxseq >> IEEE80211_SEQ_SEQ_SHIFT, 429 ni->ni_rxseqs[tid] >> 430 IEEE80211_SEQ_SEQ_SHIFT, 431 rxseq & IEEE80211_SEQ_FRAG_MASK, 432 ni->ni_rxseqs[tid] & 433 IEEE80211_SEQ_FRAG_MASK, 434 tid); 435 vap->iv_stats.is_rx_dup++; 436 IEEE80211_NODE_STAT(ni, rx_dup); 437 goto out; 438 } 439 ni->ni_rxseqs[tid] = rxseq; 440 } 441 } 442 443 switch (type) { 444 case IEEE80211_FC0_TYPE_DATA: 445 hdrspace = ieee80211_hdrspace(ic, wh); 446 if (m->m_len < hdrspace && 447 (m = m_pullup(m, hdrspace)) == NULL) { 448 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 449 ni->ni_macaddr, NULL, 450 "data too short: expecting %u", hdrspace); 451 vap->iv_stats.is_rx_tooshort++; 452 goto out; /* XXX */ 453 } 454 if (dir != IEEE80211_FC1_DIR_NODS) { 455 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 456 wh, "data", "incorrect dir 0x%x", dir); 457 vap->iv_stats.is_rx_wrongdir++; 458 goto out; 459 } 460 /* XXX no power-save support */ 461 462 /* 463 * Handle A-MPDU re-ordering. If the frame is to be 464 * processed directly then ieee80211_ampdu_reorder 465 * will return 0; otherwise it has consumed the mbuf 466 * and we should do nothing more with it. 467 */ 468 if ((m->m_flags & M_AMPDU) && 469 ieee80211_ampdu_reorder(ni, m) != 0) { 470 m = NULL; 471 goto out; 472 } 473 resubmit_ampdu: 474 475 /* 476 * Handle privacy requirements. Note that we 477 * must not be preempted from here until after 478 * we (potentially) call ieee80211_crypto_demic; 479 * otherwise we may violate assumptions in the 480 * crypto cipher modules used to do delayed update 481 * of replay sequence numbers. 482 */ 483 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 484 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) { 485 /* 486 * Discard encrypted frames when privacy is off. 487 */ 488 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 489 wh, "WEP", "%s", "PRIVACY off"); 490 vap->iv_stats.is_rx_noprivacy++; 491 IEEE80211_NODE_STAT(ni, rx_noprivacy); 492 goto out; 493 } 494 key = ieee80211_crypto_decap(ni, m, hdrspace); 495 if (key == NULL) { 496 /* NB: stats+msgs handled in crypto_decap */ 497 IEEE80211_NODE_STAT(ni, rx_wepfail); 498 goto out; 499 } 500 wh = mtod(m, struct ieee80211_frame *); 501 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; 502 } else { 503 /* XXX M_WEP and IEEE80211_F_PRIVACY */ 504 key = NULL; 505 } 506 507 /* 508 * Save QoS bits for use below--before we strip the header. 509 */ 510 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) { 511 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ? 512 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] : 513 ((struct ieee80211_qosframe *)wh)->i_qos[0]; 514 } else 515 qos = 0; 516 517 /* 518 * Next up, any fragmentation. 519 */ 520 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { 521 m = ieee80211_defrag(ni, m, hdrspace); 522 if (m == NULL) { 523 /* Fragment dropped or frame not complete yet */ 524 goto out; 525 } 526 } 527 wh = NULL; /* no longer valid, catch any uses */ 528 529 /* 530 * Next strip any MSDU crypto bits. 531 */ 532 if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) { 533 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 534 ni->ni_macaddr, "data", "%s", "demic error"); 535 vap->iv_stats.is_rx_demicfail++; 536 IEEE80211_NODE_STAT(ni, rx_demicfail); 537 goto out; 538 } 539 540 /* copy to listener after decrypt */ 541 if (ieee80211_radiotap_active_vap(vap)) 542 ieee80211_radiotap_rx(vap, m); 543 need_tap = 0; 544 545 /* 546 * Finally, strip the 802.11 header. 547 */ 548 m = ieee80211_decap(vap, m, hdrspace); 549 if (m == NULL) { 550 /* XXX mask bit to check for both */ 551 /* don't count Null data frames as errors */ 552 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA || 553 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) 554 goto out; 555 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 556 ni->ni_macaddr, "data", "%s", "decap error"); 557 vap->iv_stats.is_rx_decap++; 558 IEEE80211_NODE_STAT(ni, rx_decap); 559 goto err; 560 } 561 eh = mtod(m, struct ether_header *); 562 if (!ieee80211_node_is_authorized(ni)) { 563 /* 564 * Deny any non-PAE frames received prior to 565 * authorization. For open/shared-key 566 * authentication the port is mark authorized 567 * after authentication completes. For 802.1x 568 * the port is not marked authorized by the 569 * authenticator until the handshake has completed. 570 */ 571 if (eh->ether_type != htons(ETHERTYPE_PAE)) { 572 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 573 eh->ether_shost, "data", 574 "unauthorized port: ether type 0x%x len %u", 575 eh->ether_type, m->m_pkthdr.len); 576 vap->iv_stats.is_rx_unauth++; 577 IEEE80211_NODE_STAT(ni, rx_unauth); 578 goto err; 579 } 580 } else { 581 /* 582 * When denying unencrypted frames, discard 583 * any non-PAE frames received without encryption. 584 */ 585 if ((vap->iv_flags & IEEE80211_F_DROPUNENC) && 586 (key == NULL && (m->m_flags & M_WEP) == 0) && 587 eh->ether_type != htons(ETHERTYPE_PAE)) { 588 /* 589 * Drop unencrypted frames. 590 */ 591 vap->iv_stats.is_rx_unencrypted++; 592 IEEE80211_NODE_STAT(ni, rx_unencrypted); 593 goto out; 594 } 595 } 596 /* XXX require HT? */ 597 if (qos & IEEE80211_QOS_AMSDU) { 598 m = ieee80211_decap_amsdu(ni, m); 599 if (m == NULL) 600 return IEEE80211_FC0_TYPE_DATA; 601 } else { 602#ifdef IEEE80211_SUPPORT_SUPERG 603 m = ieee80211_decap_fastframe(vap, ni, m); 604 if (m == NULL) 605 return IEEE80211_FC0_TYPE_DATA; 606#endif 607 } 608 if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap != NULL) 609 ieee80211_deliver_data(ni->ni_wdsvap, ni, m); 610 else 611 ieee80211_deliver_data(vap, ni, m); 612 return IEEE80211_FC0_TYPE_DATA; 613 614 case IEEE80211_FC0_TYPE_MGT: 615 vap->iv_stats.is_rx_mgmt++; 616 IEEE80211_NODE_STAT(ni, rx_mgmt); 617 if (dir != IEEE80211_FC1_DIR_NODS) { 618 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 619 wh, "data", "incorrect dir 0x%x", dir); 620 vap->iv_stats.is_rx_wrongdir++; 621 goto err; 622 } 623 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) { 624 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 625 ni->ni_macaddr, "mgt", "too short: len %u", 626 m->m_pkthdr.len); 627 vap->iv_stats.is_rx_tooshort++; 628 goto out; 629 } 630#ifdef IEEE80211_DEBUG 631 if ((ieee80211_msg_debug(vap) && doprint(vap, subtype)) || 632 ieee80211_msg_dumppkts(vap)) { 633 if_printf(ifp, "received %s from %s rssi %d\n", 634 ieee80211_mgt_subtype_name[subtype >> 635 IEEE80211_FC0_SUBTYPE_SHIFT], 636 ether_sprintf(wh->i_addr2), rssi); 637 } 638#endif 639 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 640 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 641 wh, NULL, "%s", "WEP set but not permitted"); 642 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */ 643 goto out; 644 } 645 vap->iv_recv_mgmt(ni, m, subtype, rssi, nf); 646 goto out; 647 648 case IEEE80211_FC0_TYPE_CTL: 649 vap->iv_stats.is_rx_ctl++; 650 IEEE80211_NODE_STAT(ni, rx_ctrl); 651 vap->iv_recv_ctl(ni, m, subtype); 652 goto out; 653 654 default: 655 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 656 wh, "bad", "frame type 0x%x", type); 657 /* should not come here */ 658 break; 659 } 660err: 661 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 662out: 663 if (m != NULL) { 664 if (need_tap && ieee80211_radiotap_active_vap(vap)) 665 ieee80211_radiotap_rx(vap, m); 666 m_freem(m); 667 } 668 return type; 669} 670 671static int 672is11bclient(const uint8_t *rates, const uint8_t *xrates) 673{ 674 static const uint32_t brates = (1<<2*1)|(1<<2*2)|(1<<11)|(1<<2*11); 675 int i; 676 677 /* NB: the 11b clients we care about will not have xrates */ 678 if (xrates != NULL || rates == NULL) 679 return 0; 680 for (i = 0; i < rates[1]; i++) { 681 int r = rates[2+i] & IEEE80211_RATE_VAL; 682 if (r > 2*11 || ((1<<r) & brates) == 0) 683 return 0; 684 } 685 return 1; 686} 687 688static void 689adhoc_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, 690 int subtype, int rssi, int nf) 691{ 692 struct ieee80211vap *vap = ni->ni_vap; 693 struct ieee80211com *ic = ni->ni_ic; 694 struct ieee80211_frame *wh; 695 uint8_t *frm, *efrm, *sfrm; 696 uint8_t *ssid, *rates, *xrates; 697#if 0 698 int ht_state_change = 0; 699#endif 700 701 wh = mtod(m0, struct ieee80211_frame *); 702 frm = (uint8_t *)&wh[1]; 703 efrm = mtod(m0, uint8_t *) + m0->m_len; 704 switch (subtype) { 705 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 706 case IEEE80211_FC0_SUBTYPE_BEACON: { 707 struct ieee80211_scanparams scan; 708 /* 709 * We process beacon/probe response 710 * frames to discover neighbors. 711 */ 712 if (ieee80211_parse_beacon(ni, m0, &scan) != 0) 713 return; 714 /* 715 * Count frame now that we know it's to be processed. 716 */ 717 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) { 718 vap->iv_stats.is_rx_beacon++; /* XXX remove */ 719 IEEE80211_NODE_STAT(ni, rx_beacons); 720 } else 721 IEEE80211_NODE_STAT(ni, rx_proberesp); 722 /* 723 * If scanning, just pass information to the scan module. 724 */ 725 if (ic->ic_flags & IEEE80211_F_SCAN) { 726 if (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN) { 727 /* 728 * Actively scanning a channel marked passive; 729 * send a probe request now that we know there 730 * is 802.11 traffic present. 731 * 732 * XXX check if the beacon we recv'd gives 733 * us what we need and suppress the probe req 734 */ 735 ieee80211_probe_curchan(vap, 1); 736 ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN; 737 } 738 ieee80211_add_scan(vap, ic->ic_curchan, &scan, wh, 739 subtype, rssi, nf); 740 return; 741 } 742 if (scan.capinfo & IEEE80211_CAPINFO_IBSS) { 743 if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) { 744 /* 745 * Create a new entry in the neighbor table. 746 */ 747 ni = ieee80211_add_neighbor(vap, wh, &scan); 748 } else if (ni->ni_capinfo == 0) { 749 /* 750 * Update faked node created on transmit. 751 * Note this also updates the tsf. 752 */ 753 ieee80211_init_neighbor(ni, wh, &scan); 754 } else { 755 /* 756 * Record tsf for potential resync. 757 */ 758 memcpy(ni->ni_tstamp.data, scan.tstamp, 759 sizeof(ni->ni_tstamp)); 760 } 761 /* 762 * This isn't enabled yet - otherwise it would 763 * update the HT parameters and channel width 764 * from any node, which could lead to lots of 765 * strange behaviour if the 11n nodes aren't 766 * exactly configured to match. 767 */ 768#if 0 769 if (scan.htcap != NULL && scan.htinfo != NULL && 770 (vap->iv_flags_ht & IEEE80211_FHT_HT)) { 771 if (ieee80211_ht_updateparams(ni, 772 scan.htcap, scan.htinfo)) 773 ht_state_change = 1; 774 } 775#endif 776 if (ni != NULL) { 777 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); 778 ni->ni_noise = nf; 779 } 780 /* 781 * Same here - the channel width change should 782 * be applied to the specific peer node, not 783 * to the ic. Ie, the interface configuration 784 * should stay in its current channel width; 785 * but it should change the rate control and 786 * any queued frames for the given node only. 787 * 788 * Since there's no (current) way to inform 789 * the driver that a channel width change has 790 * occured for a single node, just stub this 791 * out. 792 */ 793#if 0 794 if (ht_state_change) 795 ieee80211_update_chw(ic); 796#endif 797 } 798 break; 799 } 800 801 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 802 if (vap->iv_state != IEEE80211_S_RUN) { 803 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 804 wh, NULL, "wrong state %s", 805 ieee80211_state_name[vap->iv_state]); 806 vap->iv_stats.is_rx_mgtdiscard++; 807 return; 808 } 809 if (IEEE80211_IS_MULTICAST(wh->i_addr2)) { 810 /* frame must be directed */ 811 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 812 wh, NULL, "%s", "not unicast"); 813 vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */ 814 return; 815 } 816 817 /* 818 * prreq frame format 819 * [tlv] ssid 820 * [tlv] supported rates 821 * [tlv] extended supported rates 822 */ 823 ssid = rates = xrates = NULL; 824 sfrm = frm; 825 while (efrm - frm > 1) { 826 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); 827 switch (*frm) { 828 case IEEE80211_ELEMID_SSID: 829 ssid = frm; 830 break; 831 case IEEE80211_ELEMID_RATES: 832 rates = frm; 833 break; 834 case IEEE80211_ELEMID_XRATES: 835 xrates = frm; 836 break; 837 } 838 frm += frm[1] + 2; 839 } 840 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return); 841 if (xrates != NULL) 842 IEEE80211_VERIFY_ELEMENT(xrates, 843 IEEE80211_RATE_MAXSIZE - rates[1], return); 844 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return); 845 IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return); 846 if ((vap->iv_flags & IEEE80211_F_HIDESSID) && ssid[1] == 0) { 847 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 848 wh, NULL, 849 "%s", "no ssid with ssid suppression enabled"); 850 vap->iv_stats.is_rx_ssidmismatch++; /*XXX*/ 851 return; 852 } 853 854 /* XXX find a better class or define it's own */ 855 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2, 856 "%s", "recv probe req"); 857 /* 858 * Some legacy 11b clients cannot hack a complete 859 * probe response frame. When the request includes 860 * only a bare-bones rate set, communicate this to 861 * the transmit side. 862 */ 863 ieee80211_send_proberesp(vap, wh->i_addr2, 864 is11bclient(rates, xrates) ? IEEE80211_SEND_LEGACY_11B : 0); 865 break; 866 867 case IEEE80211_FC0_SUBTYPE_ACTION: 868 case IEEE80211_FC0_SUBTYPE_ACTION_NOACK: 869 if (ni == vap->iv_bss) { 870 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 871 wh, NULL, "%s", "unknown node"); 872 vap->iv_stats.is_rx_mgtdiscard++; 873 } else if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) && 874 !IEEE80211_IS_MULTICAST(wh->i_addr1)) { 875 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 876 wh, NULL, "%s", "not for us"); 877 vap->iv_stats.is_rx_mgtdiscard++; 878 } else if (vap->iv_state != IEEE80211_S_RUN) { 879 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 880 wh, NULL, "wrong state %s", 881 ieee80211_state_name[vap->iv_state]); 882 vap->iv_stats.is_rx_mgtdiscard++; 883 } else { 884 if (ieee80211_parse_action(ni, m0) == 0) 885 (void)ic->ic_recv_action(ni, wh, frm, efrm); 886 } 887 break; 888 889 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 890 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 891 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: 892 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 893 case IEEE80211_FC0_SUBTYPE_ATIM: 894 case IEEE80211_FC0_SUBTYPE_DISASSOC: 895 case IEEE80211_FC0_SUBTYPE_AUTH: 896 case IEEE80211_FC0_SUBTYPE_DEAUTH: 897 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 898 wh, NULL, "%s", "not handled"); 899 vap->iv_stats.is_rx_mgtdiscard++; 900 break; 901 902 default: 903 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 904 wh, "mgt", "subtype 0x%x not handled", subtype); 905 vap->iv_stats.is_rx_badsubtype++; 906 break; 907 } 908} 909#undef IEEE80211_VERIFY_LENGTH 910#undef IEEE80211_VERIFY_ELEMENT 911 912static void 913ahdemo_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, 914 int subtype, int rssi, int nf) 915{ 916 struct ieee80211vap *vap = ni->ni_vap; 917 struct ieee80211com *ic = ni->ni_ic; 918 struct ieee80211_frame *wh; 919 920 /* 921 * Process management frames when scanning; useful for doing 922 * a site-survey. 923 */ 924 if (ic->ic_flags & IEEE80211_F_SCAN) 925 adhoc_recv_mgmt(ni, m0, subtype, rssi, nf); 926 else { 927 wh = mtod(m0, struct ieee80211_frame *); 928 switch (subtype) { 929 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 930 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 931 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: 932 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 933 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 934 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 935 case IEEE80211_FC0_SUBTYPE_BEACON: 936 case IEEE80211_FC0_SUBTYPE_ATIM: 937 case IEEE80211_FC0_SUBTYPE_DISASSOC: 938 case IEEE80211_FC0_SUBTYPE_AUTH: 939 case IEEE80211_FC0_SUBTYPE_DEAUTH: 940 case IEEE80211_FC0_SUBTYPE_ACTION: 941 case IEEE80211_FC0_SUBTYPE_ACTION_NOACK: 942 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 943 wh, NULL, "%s", "not handled"); 944 vap->iv_stats.is_rx_mgtdiscard++; 945 break; 946 default: 947 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 948 wh, "mgt", "subtype 0x%x not handled", subtype); 949 vap->iv_stats.is_rx_badsubtype++; 950 break; 951 } 952 } 953} 954 955static void 956adhoc_recv_ctl(struct ieee80211_node *ni, struct mbuf *m, int subtype) 957{ 958 959 switch (subtype) { 960 case IEEE80211_FC0_SUBTYPE_BAR: 961 ieee80211_recv_bar(ni, m); 962 break; 963 } 964}
| 418 uint8_t tid = ieee80211_gettid(wh); 419 if (IEEE80211_QOS_HAS_SEQ(wh) && 420 TID_TO_WME_AC(tid) >= WME_AC_VI) 421 ic->ic_wme.wme_hipri_traffic++; 422 rxseq = le16toh(*(uint16_t *)wh->i_seq); 423 if (! ieee80211_check_rxseq(ni, wh)) { 424 /* duplicate, discard */ 425 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 426 bssid, "duplicate", 427 "seqno <%u,%u> fragno <%u,%u> tid %u", 428 rxseq >> IEEE80211_SEQ_SEQ_SHIFT, 429 ni->ni_rxseqs[tid] >> 430 IEEE80211_SEQ_SEQ_SHIFT, 431 rxseq & IEEE80211_SEQ_FRAG_MASK, 432 ni->ni_rxseqs[tid] & 433 IEEE80211_SEQ_FRAG_MASK, 434 tid); 435 vap->iv_stats.is_rx_dup++; 436 IEEE80211_NODE_STAT(ni, rx_dup); 437 goto out; 438 } 439 ni->ni_rxseqs[tid] = rxseq; 440 } 441 } 442 443 switch (type) { 444 case IEEE80211_FC0_TYPE_DATA: 445 hdrspace = ieee80211_hdrspace(ic, wh); 446 if (m->m_len < hdrspace && 447 (m = m_pullup(m, hdrspace)) == NULL) { 448 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 449 ni->ni_macaddr, NULL, 450 "data too short: expecting %u", hdrspace); 451 vap->iv_stats.is_rx_tooshort++; 452 goto out; /* XXX */ 453 } 454 if (dir != IEEE80211_FC1_DIR_NODS) { 455 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 456 wh, "data", "incorrect dir 0x%x", dir); 457 vap->iv_stats.is_rx_wrongdir++; 458 goto out; 459 } 460 /* XXX no power-save support */ 461 462 /* 463 * Handle A-MPDU re-ordering. If the frame is to be 464 * processed directly then ieee80211_ampdu_reorder 465 * will return 0; otherwise it has consumed the mbuf 466 * and we should do nothing more with it. 467 */ 468 if ((m->m_flags & M_AMPDU) && 469 ieee80211_ampdu_reorder(ni, m) != 0) { 470 m = NULL; 471 goto out; 472 } 473 resubmit_ampdu: 474 475 /* 476 * Handle privacy requirements. Note that we 477 * must not be preempted from here until after 478 * we (potentially) call ieee80211_crypto_demic; 479 * otherwise we may violate assumptions in the 480 * crypto cipher modules used to do delayed update 481 * of replay sequence numbers. 482 */ 483 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 484 if ((vap->iv_flags & IEEE80211_F_PRIVACY) == 0) { 485 /* 486 * Discard encrypted frames when privacy is off. 487 */ 488 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 489 wh, "WEP", "%s", "PRIVACY off"); 490 vap->iv_stats.is_rx_noprivacy++; 491 IEEE80211_NODE_STAT(ni, rx_noprivacy); 492 goto out; 493 } 494 key = ieee80211_crypto_decap(ni, m, hdrspace); 495 if (key == NULL) { 496 /* NB: stats+msgs handled in crypto_decap */ 497 IEEE80211_NODE_STAT(ni, rx_wepfail); 498 goto out; 499 } 500 wh = mtod(m, struct ieee80211_frame *); 501 wh->i_fc[1] &= ~IEEE80211_FC1_PROTECTED; 502 } else { 503 /* XXX M_WEP and IEEE80211_F_PRIVACY */ 504 key = NULL; 505 } 506 507 /* 508 * Save QoS bits for use below--before we strip the header. 509 */ 510 if (subtype == IEEE80211_FC0_SUBTYPE_QOS) { 511 qos = (dir == IEEE80211_FC1_DIR_DSTODS) ? 512 ((struct ieee80211_qosframe_addr4 *)wh)->i_qos[0] : 513 ((struct ieee80211_qosframe *)wh)->i_qos[0]; 514 } else 515 qos = 0; 516 517 /* 518 * Next up, any fragmentation. 519 */ 520 if (!IEEE80211_IS_MULTICAST(wh->i_addr1)) { 521 m = ieee80211_defrag(ni, m, hdrspace); 522 if (m == NULL) { 523 /* Fragment dropped or frame not complete yet */ 524 goto out; 525 } 526 } 527 wh = NULL; /* no longer valid, catch any uses */ 528 529 /* 530 * Next strip any MSDU crypto bits. 531 */ 532 if (key != NULL && !ieee80211_crypto_demic(vap, key, m, 0)) { 533 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 534 ni->ni_macaddr, "data", "%s", "demic error"); 535 vap->iv_stats.is_rx_demicfail++; 536 IEEE80211_NODE_STAT(ni, rx_demicfail); 537 goto out; 538 } 539 540 /* copy to listener after decrypt */ 541 if (ieee80211_radiotap_active_vap(vap)) 542 ieee80211_radiotap_rx(vap, m); 543 need_tap = 0; 544 545 /* 546 * Finally, strip the 802.11 header. 547 */ 548 m = ieee80211_decap(vap, m, hdrspace); 549 if (m == NULL) { 550 /* XXX mask bit to check for both */ 551 /* don't count Null data frames as errors */ 552 if (subtype == IEEE80211_FC0_SUBTYPE_NODATA || 553 subtype == IEEE80211_FC0_SUBTYPE_QOS_NULL) 554 goto out; 555 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 556 ni->ni_macaddr, "data", "%s", "decap error"); 557 vap->iv_stats.is_rx_decap++; 558 IEEE80211_NODE_STAT(ni, rx_decap); 559 goto err; 560 } 561 eh = mtod(m, struct ether_header *); 562 if (!ieee80211_node_is_authorized(ni)) { 563 /* 564 * Deny any non-PAE frames received prior to 565 * authorization. For open/shared-key 566 * authentication the port is mark authorized 567 * after authentication completes. For 802.1x 568 * the port is not marked authorized by the 569 * authenticator until the handshake has completed. 570 */ 571 if (eh->ether_type != htons(ETHERTYPE_PAE)) { 572 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_INPUT, 573 eh->ether_shost, "data", 574 "unauthorized port: ether type 0x%x len %u", 575 eh->ether_type, m->m_pkthdr.len); 576 vap->iv_stats.is_rx_unauth++; 577 IEEE80211_NODE_STAT(ni, rx_unauth); 578 goto err; 579 } 580 } else { 581 /* 582 * When denying unencrypted frames, discard 583 * any non-PAE frames received without encryption. 584 */ 585 if ((vap->iv_flags & IEEE80211_F_DROPUNENC) && 586 (key == NULL && (m->m_flags & M_WEP) == 0) && 587 eh->ether_type != htons(ETHERTYPE_PAE)) { 588 /* 589 * Drop unencrypted frames. 590 */ 591 vap->iv_stats.is_rx_unencrypted++; 592 IEEE80211_NODE_STAT(ni, rx_unencrypted); 593 goto out; 594 } 595 } 596 /* XXX require HT? */ 597 if (qos & IEEE80211_QOS_AMSDU) { 598 m = ieee80211_decap_amsdu(ni, m); 599 if (m == NULL) 600 return IEEE80211_FC0_TYPE_DATA; 601 } else { 602#ifdef IEEE80211_SUPPORT_SUPERG 603 m = ieee80211_decap_fastframe(vap, ni, m); 604 if (m == NULL) 605 return IEEE80211_FC0_TYPE_DATA; 606#endif 607 } 608 if (dir == IEEE80211_FC1_DIR_DSTODS && ni->ni_wdsvap != NULL) 609 ieee80211_deliver_data(ni->ni_wdsvap, ni, m); 610 else 611 ieee80211_deliver_data(vap, ni, m); 612 return IEEE80211_FC0_TYPE_DATA; 613 614 case IEEE80211_FC0_TYPE_MGT: 615 vap->iv_stats.is_rx_mgmt++; 616 IEEE80211_NODE_STAT(ni, rx_mgmt); 617 if (dir != IEEE80211_FC1_DIR_NODS) { 618 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 619 wh, "data", "incorrect dir 0x%x", dir); 620 vap->iv_stats.is_rx_wrongdir++; 621 goto err; 622 } 623 if (m->m_pkthdr.len < sizeof(struct ieee80211_frame)) { 624 IEEE80211_DISCARD_MAC(vap, IEEE80211_MSG_ANY, 625 ni->ni_macaddr, "mgt", "too short: len %u", 626 m->m_pkthdr.len); 627 vap->iv_stats.is_rx_tooshort++; 628 goto out; 629 } 630#ifdef IEEE80211_DEBUG 631 if ((ieee80211_msg_debug(vap) && doprint(vap, subtype)) || 632 ieee80211_msg_dumppkts(vap)) { 633 if_printf(ifp, "received %s from %s rssi %d\n", 634 ieee80211_mgt_subtype_name[subtype >> 635 IEEE80211_FC0_SUBTYPE_SHIFT], 636 ether_sprintf(wh->i_addr2), rssi); 637 } 638#endif 639 if (wh->i_fc[1] & IEEE80211_FC1_PROTECTED) { 640 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 641 wh, NULL, "%s", "WEP set but not permitted"); 642 vap->iv_stats.is_rx_mgtdiscard++; /* XXX */ 643 goto out; 644 } 645 vap->iv_recv_mgmt(ni, m, subtype, rssi, nf); 646 goto out; 647 648 case IEEE80211_FC0_TYPE_CTL: 649 vap->iv_stats.is_rx_ctl++; 650 IEEE80211_NODE_STAT(ni, rx_ctrl); 651 vap->iv_recv_ctl(ni, m, subtype); 652 goto out; 653 654 default: 655 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 656 wh, "bad", "frame type 0x%x", type); 657 /* should not come here */ 658 break; 659 } 660err: 661 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); 662out: 663 if (m != NULL) { 664 if (need_tap && ieee80211_radiotap_active_vap(vap)) 665 ieee80211_radiotap_rx(vap, m); 666 m_freem(m); 667 } 668 return type; 669} 670 671static int 672is11bclient(const uint8_t *rates, const uint8_t *xrates) 673{ 674 static const uint32_t brates = (1<<2*1)|(1<<2*2)|(1<<11)|(1<<2*11); 675 int i; 676 677 /* NB: the 11b clients we care about will not have xrates */ 678 if (xrates != NULL || rates == NULL) 679 return 0; 680 for (i = 0; i < rates[1]; i++) { 681 int r = rates[2+i] & IEEE80211_RATE_VAL; 682 if (r > 2*11 || ((1<<r) & brates) == 0) 683 return 0; 684 } 685 return 1; 686} 687 688static void 689adhoc_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, 690 int subtype, int rssi, int nf) 691{ 692 struct ieee80211vap *vap = ni->ni_vap; 693 struct ieee80211com *ic = ni->ni_ic; 694 struct ieee80211_frame *wh; 695 uint8_t *frm, *efrm, *sfrm; 696 uint8_t *ssid, *rates, *xrates; 697#if 0 698 int ht_state_change = 0; 699#endif 700 701 wh = mtod(m0, struct ieee80211_frame *); 702 frm = (uint8_t *)&wh[1]; 703 efrm = mtod(m0, uint8_t *) + m0->m_len; 704 switch (subtype) { 705 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 706 case IEEE80211_FC0_SUBTYPE_BEACON: { 707 struct ieee80211_scanparams scan; 708 /* 709 * We process beacon/probe response 710 * frames to discover neighbors. 711 */ 712 if (ieee80211_parse_beacon(ni, m0, &scan) != 0) 713 return; 714 /* 715 * Count frame now that we know it's to be processed. 716 */ 717 if (subtype == IEEE80211_FC0_SUBTYPE_BEACON) { 718 vap->iv_stats.is_rx_beacon++; /* XXX remove */ 719 IEEE80211_NODE_STAT(ni, rx_beacons); 720 } else 721 IEEE80211_NODE_STAT(ni, rx_proberesp); 722 /* 723 * If scanning, just pass information to the scan module. 724 */ 725 if (ic->ic_flags & IEEE80211_F_SCAN) { 726 if (ic->ic_flags_ext & IEEE80211_FEXT_PROBECHAN) { 727 /* 728 * Actively scanning a channel marked passive; 729 * send a probe request now that we know there 730 * is 802.11 traffic present. 731 * 732 * XXX check if the beacon we recv'd gives 733 * us what we need and suppress the probe req 734 */ 735 ieee80211_probe_curchan(vap, 1); 736 ic->ic_flags_ext &= ~IEEE80211_FEXT_PROBECHAN; 737 } 738 ieee80211_add_scan(vap, ic->ic_curchan, &scan, wh, 739 subtype, rssi, nf); 740 return; 741 } 742 if (scan.capinfo & IEEE80211_CAPINFO_IBSS) { 743 if (!IEEE80211_ADDR_EQ(wh->i_addr2, ni->ni_macaddr)) { 744 /* 745 * Create a new entry in the neighbor table. 746 */ 747 ni = ieee80211_add_neighbor(vap, wh, &scan); 748 } else if (ni->ni_capinfo == 0) { 749 /* 750 * Update faked node created on transmit. 751 * Note this also updates the tsf. 752 */ 753 ieee80211_init_neighbor(ni, wh, &scan); 754 } else { 755 /* 756 * Record tsf for potential resync. 757 */ 758 memcpy(ni->ni_tstamp.data, scan.tstamp, 759 sizeof(ni->ni_tstamp)); 760 } 761 /* 762 * This isn't enabled yet - otherwise it would 763 * update the HT parameters and channel width 764 * from any node, which could lead to lots of 765 * strange behaviour if the 11n nodes aren't 766 * exactly configured to match. 767 */ 768#if 0 769 if (scan.htcap != NULL && scan.htinfo != NULL && 770 (vap->iv_flags_ht & IEEE80211_FHT_HT)) { 771 if (ieee80211_ht_updateparams(ni, 772 scan.htcap, scan.htinfo)) 773 ht_state_change = 1; 774 } 775#endif 776 if (ni != NULL) { 777 IEEE80211_RSSI_LPF(ni->ni_avgrssi, rssi); 778 ni->ni_noise = nf; 779 } 780 /* 781 * Same here - the channel width change should 782 * be applied to the specific peer node, not 783 * to the ic. Ie, the interface configuration 784 * should stay in its current channel width; 785 * but it should change the rate control and 786 * any queued frames for the given node only. 787 * 788 * Since there's no (current) way to inform 789 * the driver that a channel width change has 790 * occured for a single node, just stub this 791 * out. 792 */ 793#if 0 794 if (ht_state_change) 795 ieee80211_update_chw(ic); 796#endif 797 } 798 break; 799 } 800 801 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 802 if (vap->iv_state != IEEE80211_S_RUN) { 803 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 804 wh, NULL, "wrong state %s", 805 ieee80211_state_name[vap->iv_state]); 806 vap->iv_stats.is_rx_mgtdiscard++; 807 return; 808 } 809 if (IEEE80211_IS_MULTICAST(wh->i_addr2)) { 810 /* frame must be directed */ 811 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 812 wh, NULL, "%s", "not unicast"); 813 vap->iv_stats.is_rx_mgtdiscard++; /* XXX stat */ 814 return; 815 } 816 817 /* 818 * prreq frame format 819 * [tlv] ssid 820 * [tlv] supported rates 821 * [tlv] extended supported rates 822 */ 823 ssid = rates = xrates = NULL; 824 sfrm = frm; 825 while (efrm - frm > 1) { 826 IEEE80211_VERIFY_LENGTH(efrm - frm, frm[1] + 2, return); 827 switch (*frm) { 828 case IEEE80211_ELEMID_SSID: 829 ssid = frm; 830 break; 831 case IEEE80211_ELEMID_RATES: 832 rates = frm; 833 break; 834 case IEEE80211_ELEMID_XRATES: 835 xrates = frm; 836 break; 837 } 838 frm += frm[1] + 2; 839 } 840 IEEE80211_VERIFY_ELEMENT(rates, IEEE80211_RATE_MAXSIZE, return); 841 if (xrates != NULL) 842 IEEE80211_VERIFY_ELEMENT(xrates, 843 IEEE80211_RATE_MAXSIZE - rates[1], return); 844 IEEE80211_VERIFY_ELEMENT(ssid, IEEE80211_NWID_LEN, return); 845 IEEE80211_VERIFY_SSID(vap->iv_bss, ssid, return); 846 if ((vap->iv_flags & IEEE80211_F_HIDESSID) && ssid[1] == 0) { 847 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 848 wh, NULL, 849 "%s", "no ssid with ssid suppression enabled"); 850 vap->iv_stats.is_rx_ssidmismatch++; /*XXX*/ 851 return; 852 } 853 854 /* XXX find a better class or define it's own */ 855 IEEE80211_NOTE_MAC(vap, IEEE80211_MSG_INPUT, wh->i_addr2, 856 "%s", "recv probe req"); 857 /* 858 * Some legacy 11b clients cannot hack a complete 859 * probe response frame. When the request includes 860 * only a bare-bones rate set, communicate this to 861 * the transmit side. 862 */ 863 ieee80211_send_proberesp(vap, wh->i_addr2, 864 is11bclient(rates, xrates) ? IEEE80211_SEND_LEGACY_11B : 0); 865 break; 866 867 case IEEE80211_FC0_SUBTYPE_ACTION: 868 case IEEE80211_FC0_SUBTYPE_ACTION_NOACK: 869 if (ni == vap->iv_bss) { 870 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 871 wh, NULL, "%s", "unknown node"); 872 vap->iv_stats.is_rx_mgtdiscard++; 873 } else if (!IEEE80211_ADDR_EQ(vap->iv_myaddr, wh->i_addr1) && 874 !IEEE80211_IS_MULTICAST(wh->i_addr1)) { 875 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 876 wh, NULL, "%s", "not for us"); 877 vap->iv_stats.is_rx_mgtdiscard++; 878 } else if (vap->iv_state != IEEE80211_S_RUN) { 879 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 880 wh, NULL, "wrong state %s", 881 ieee80211_state_name[vap->iv_state]); 882 vap->iv_stats.is_rx_mgtdiscard++; 883 } else { 884 if (ieee80211_parse_action(ni, m0) == 0) 885 (void)ic->ic_recv_action(ni, wh, frm, efrm); 886 } 887 break; 888 889 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 890 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 891 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: 892 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 893 case IEEE80211_FC0_SUBTYPE_ATIM: 894 case IEEE80211_FC0_SUBTYPE_DISASSOC: 895 case IEEE80211_FC0_SUBTYPE_AUTH: 896 case IEEE80211_FC0_SUBTYPE_DEAUTH: 897 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 898 wh, NULL, "%s", "not handled"); 899 vap->iv_stats.is_rx_mgtdiscard++; 900 break; 901 902 default: 903 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 904 wh, "mgt", "subtype 0x%x not handled", subtype); 905 vap->iv_stats.is_rx_badsubtype++; 906 break; 907 } 908} 909#undef IEEE80211_VERIFY_LENGTH 910#undef IEEE80211_VERIFY_ELEMENT 911 912static void 913ahdemo_recv_mgmt(struct ieee80211_node *ni, struct mbuf *m0, 914 int subtype, int rssi, int nf) 915{ 916 struct ieee80211vap *vap = ni->ni_vap; 917 struct ieee80211com *ic = ni->ni_ic; 918 struct ieee80211_frame *wh; 919 920 /* 921 * Process management frames when scanning; useful for doing 922 * a site-survey. 923 */ 924 if (ic->ic_flags & IEEE80211_F_SCAN) 925 adhoc_recv_mgmt(ni, m0, subtype, rssi, nf); 926 else { 927 wh = mtod(m0, struct ieee80211_frame *); 928 switch (subtype) { 929 case IEEE80211_FC0_SUBTYPE_ASSOC_REQ: 930 case IEEE80211_FC0_SUBTYPE_ASSOC_RESP: 931 case IEEE80211_FC0_SUBTYPE_REASSOC_REQ: 932 case IEEE80211_FC0_SUBTYPE_REASSOC_RESP: 933 case IEEE80211_FC0_SUBTYPE_PROBE_REQ: 934 case IEEE80211_FC0_SUBTYPE_PROBE_RESP: 935 case IEEE80211_FC0_SUBTYPE_BEACON: 936 case IEEE80211_FC0_SUBTYPE_ATIM: 937 case IEEE80211_FC0_SUBTYPE_DISASSOC: 938 case IEEE80211_FC0_SUBTYPE_AUTH: 939 case IEEE80211_FC0_SUBTYPE_DEAUTH: 940 case IEEE80211_FC0_SUBTYPE_ACTION: 941 case IEEE80211_FC0_SUBTYPE_ACTION_NOACK: 942 IEEE80211_DISCARD(vap, IEEE80211_MSG_INPUT, 943 wh, NULL, "%s", "not handled"); 944 vap->iv_stats.is_rx_mgtdiscard++; 945 break; 946 default: 947 IEEE80211_DISCARD(vap, IEEE80211_MSG_ANY, 948 wh, "mgt", "subtype 0x%x not handled", subtype); 949 vap->iv_stats.is_rx_badsubtype++; 950 break; 951 } 952 } 953} 954 955static void 956adhoc_recv_ctl(struct ieee80211_node *ni, struct mbuf *m, int subtype) 957{ 958 959 switch (subtype) { 960 case IEEE80211_FC0_SUBTYPE_BAR: 961 ieee80211_recv_bar(ni, m); 962 break; 963 } 964}
|