am930mgr.c
来自「Linux Wireless LAN Project 的目标是开发一个完整的」· C语言 代码 · 共 2,470 行 · 第 1/5 页
C
2,470 行
sta = am930mgr_stable_lookup( mgr, f->hdr->a3.a2); if ( sta == NULL ) { /* We're not in an exchange with this STA */ pb = am930mgr_mkfrm_auth( mgr, f->hdr->a3.a2, ieee2host16(*(f->auth_alg)), 4, WLAN_MGMT_STATUS_RX_AUTH_NOSEQ, NULL ); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } return; } else if ( sta->sta.state == WLAN_STA_STATE_PENDING_REMOVAL ) { /* A timeout has occurred */ pb = am930mgr_mkfrm_auth( mgr, f->hdr->a3.a2, ieee2host16(*(f->auth_alg)), 4, WLAN_MGMT_STATUS_AUTH_TIMEOUT, NULL ); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } sta->sta.state = WLAN_STA_STATE_FREE; /* next dealloc pass will remove it */ return; } /* Check the challenge text */ am930mgr_mkchallengetext( mgr, ctext, WLAN_CHALLENGE_LEN, mgr->challengekey, sizeof(mgr->challengekey)); if (memcmp( f->challenge->challenge, ctext, WLAN_CHALLENGE_LEN) == 0) { /* Success! the STA is now authenticated */ pb = am930mgr_mkfrm_auth( mgr, f->hdr->a3.a2, ieee2host16(*(f->auth_alg)), 4, WLAN_MGMT_STATUS_SUCCESS, NULL ); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } sta->sta.state = WLAN_STA_STATE_ACTIVE; } else { /* challenge failure */ pb = am930mgr_mkfrm_auth( mgr, f->hdr->a3.a2, ieee2host16(*(f->auth_alg)), 4, WLAN_MGMT_STATUS_CHALLENGE_FAIL, NULL ); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } sta->sta.state = WLAN_STA_STATE_PENDING_REMOVAL; sta->sta.info = 0; } DBFEXIT; return;}/*----------------------------------------------------------------* am930mgr_authen4_rx** Handles incoming authen frames with sequence 4** returns: nothing for now----------------------------------------------------------------*/void am930mgr_authen4_rx( am930mgr_t *mgr, wlan_fr_authen_t *f ){ DBFENTER; if ( ieee2host16(*(f->status)) == WLAN_MGMT_STATUS_SUCCESS ) { WLAN_LOG_NOTICE0("802.11 Authen (SHAREDKEY) Successful.\n"); mgr->mac->state = AM930_MACSTATE_AUTH; am930llc_cmdcomplete(mgr->mac->llc, ieee2host16(*(f->status))); } else { WLAN_LOG_NOTICE0("802.11 Authen (SHAREDKEY) Failed.\n"); am930mgr_prstatus(mgr, ieee2host16(*(f->status)) ); mgr->mac->state = AM930_MACSTATE_NOAUTH; am930llc_cmdcomplete(mgr->mac->llc, ieee2host16(*(f->status))); } DBFEXIT;}/*----------------------------------------------------------------* am930mgr_beacon_rx** Handles beacon frames.** returns: nothing----------------------------------------------------------------*/void am930mgr_beacon_rx( am930mgr_t *mgr, wlan_pb_t *rxpb, am930rxstats_t *stats){ DBFENTER; if ( mgr->mac->mode == AM930_MACMODE_ESS_STA ) { mgr->mac->last_beacon_time = jiffies; mgr->mac->last_beacon_rssi = stats->rssi; } DBFEXIT; return;}/*----------------------------------------------------------------* am930mgr_class2err** Generates a deauth frame to the given daddr.* Arguments:* daddr Destination of the death** returns: nothing----------------------------------------------------------------*/void am930mgr_class2err(am930mgr_t *mgr, UINT8 *daddr){ wlan_pb_t *pb; pb = am930mgr_mkfrm_deauth( mgr, daddr, WLAN_MGMT_REASON_CLASS2_NONAUTH); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } return;}/*----------------------------------------------------------------* am930mgr_class3err** Generates a disassoc frame to the given daddr.* Arguments:* daddr Destination of the disassoc** returns: nothing----------------------------------------------------------------*/void am930mgr_class3err(am930mgr_t *mgr, UINT8 *daddr){ wlan_pb_t *pb; pb = am930mgr_mkfrm_disassoc( mgr, daddr, WLAN_MGMT_REASON_CLASS3_NONASSOC); if ( pb != NULL ) { am930mac_txmac( mgr->mac, pb); } return;}/*----------------------------------------------------------------* am930mgr_createbss** Instructs the hw object to create a bss using the supplied* attributes. Note that this implementation only supports Ad-Hoc* BSS creation.* Arguments:* ch The DS channel to use (1-12)* ssid The SSID to use, formatted as a wlan_ie_ssid_t* bcnrate The beacon rate for the BSS.** returns: zero on success, non-zero on failure----------------------------------------------------------------*/UINT32 am930mgr_createbss( am930mgr_t *mgr, UINT32 ch, wlan_ie_ssid_t *ie_ssid, UINT32 bcn, UINT32 atimwindow){ UINT32 result = 0; UINT8 bssid[WLAN_BSSID_LEN] = {0,0,0,0,0,0}; wlan_bss_ts_t ts = {0,0,0,0,0,0,0,0}; UINT8 one = 1; UINT16 basic_rate = host2amd16(20); char buf[WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN]; DBFENTER; /* set the 'sta basic rate' to 20 and be done with it. */ am930mgr_mibsetitem( mgr, MAC_STA_BASIC_RATE, &basic_rate, sizeof(basic_rate)); if ( am930_isap ) { if ( am930hw_mibsetitem( mgr->hw, LOC_ACTING_AS_AP, &one, MI_SZ(LOC_ACTING_AS_AP)) != AM930HW_SUCCESS ) { result = 1; } memcpy(bssid, mgr->hw->addr, WLAN_BSSID_LEN); } if ( result == 0 ) { if ( !result && (am930hw_joinbss( mgr->hw, ch, 1, /* newBSS */ bssid, ie_ssid, bcn, ts, /* ts (timestamp) */ 0) /* sutro local time */ == AM930HW_SUCCESS ) ) { mgr->curr_ch = ch; am930mgr_mibgetitem( mgr, MAC_STA_BASIC_RATE, &mgr->curr_rate, MI_SZ(MAC_STA_BASIC_RATE)); mgr->curr_rate = amd2host16(mgr->curr_rate); mgr->curr_cap_info = am930_isap ? WLAN_SET_MGMT_CAP_INFO_ESS(1) : WLAN_SET_MGMT_CAP_INFO_IBSS(1); memcpy( mgr->curr_ssid, ie_ssid, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN); memcpy( mgr->curr_bssid, bssid, WLAN_BSSID_LEN ); am930mgr_mibgetitem( mgr, MGMT_CURRENT_BSSID, mgr->curr_bssid, WLAN_BSSID_LEN); mgr->mac->mode = am930_isap ? AM930_MACMODE_ESS_AP : AM930_MACMODE_IBSS_STA; mgr->mac->state = AM930_MACSTATE_NOAUTH; memcpy( buf, ie_ssid->ssid, ie_ssid->len); buf[ie_ssid->len] = '\0'; WLAN_LOG_NOTICE4("%s BSS created, channel=%ld, rate=%d SSID=%s\n", am930_isap ? "Infrastructure" : "AdHoc", ch, mgr->curr_rate, buf); } else { result = 1; WLAN_LOG_ERROR0("Failed to create BSS.\n"); } } DBFEXIT; return result;}/*----------------------------------------------------------------* am930mgr_deauth_rx** Handles incoming deauthentication frames** returns: nothing for now----------------------------------------------------------------*/void am930mgr_deauth_rx( am930mgr_t *mgr, wlan_pb_t *rxpb, am930rxstats_t *stats){ wlan_fr_deauthen_t f; wlan_stable_item_t *sta; DBFENTER; if ( mgr->mac->mode == AM930_MACMODE_ESS_AP ) { f.len = rxpb->p80211buflen - WLAN_CRC_LEN; f.buf = rxpb->p80211buf; wlan_mgmt_decode_deauthen(&f); sta = am930mgr_stable_lookup( mgr, f.hdr->a3.a2); if ( sta != NULL ) { WLAN_LOG_DEBUG1(1, "Station deauthed itself, reason=%d\n", ieee2host16(*(f.reason)) ); sta->sta.info &= ~WLAN_STA_INFO_AUTH; sta->sta.state = WLAN_STA_STATE_PENDING_REMOVAL; } /* TODO: set up a notification to llc and ideally up to user-mode so the user-mode software can react (if necessary). */ } else if ( mgr->mac->mode == AM930_MACMODE_ESS_STA ) { f.len = rxpb->p80211buflen - WLAN_CRC_LEN; f.buf = rxpb->p80211buf; wlan_mgmt_decode_deauthen(&f); mgr->mac->state = AM930_MACSTATE_NOAUTH; WLAN_LOG_DEBUG1(1, "AP deauthed me, reason=%d.\n", ieee2host16(*(f.reason)) ); /* TODO: set up a notification to llc and ideally up to user-mode so the user-mode software can react. */ } /* else, ignore it. TODO: IBSS authentication service would be implemented here */ DBFEXIT; return;}/*----------------------------------------------------------------* am930mgr_disassoc_rx** Handles incoming disassociation frames** returns: nothing for now----------------------------------------------------------------*/void am930mgr_disassoc_rx( am930mgr_t *mgr, wlan_pb_t *rxpb, am930rxstats_t *stats){ wlan_fr_disassoc_t f; wlan_stable_item_t *sta; DBFENTER; if ( mgr->mac->mode == AM930_MACMODE_ESS_AP ) { f.len = rxpb->p80211buflen - WLAN_CRC_LEN; f.buf = rxpb->p80211buf; wlan_mgmt_decode_disassoc(&f); sta = am930mgr_stable_lookup( mgr, f.hdr->a3.a2); if ( sta != NULL ) { WLAN_LOG_DEBUG1(1, "Station disassociated itself, reason=%d\n", ieee2host16(*(f.reason)) ); sta->sta.info &= ~WLAN_STA_INFO_ASSOC; } /* TODO: set up a notification to llc and ideally up to user-mode so the user-mode software can react. */ } else if ( mgr->mac->mode == AM930_MACMODE_ESS_STA ) { f.len = rxpb->p80211buflen - WLAN_CRC_LEN; f.buf = rxpb->p80211buf; wlan_mgmt_decode_disassoc(&f); mgr->mac->state = AM930_MACSTATE_AUTH; WLAN_LOG_DEBUG1(1, "AP disassociated me, reason=%d.\n", ieee2host16(*(f.reason)) ); /* TODO: set up a notification to llc and ideally up to user-mode so the user-mode software can react. */ } /* else, ignore it */ DBFEXIT; return;}/*----------------------------------------------------------------* am930mgr_joinbss** Instructs the hw object to join a bss using the supplied* attributes. The only argument is the bssid, the rest of the* attributes are obtained from the known bss list.** Arguments:* bssid the 48 bit id of the bss to join** returns: zero on success, * 1 if the bss isn't found in the list,* 2 if the hw sync command fails.----------------------------------------------------------------*/UINT32 am930mgr_joinbss( am930mgr_t *mgr, UINT8 *bssid ){ UINT32 result = 0; knownbss_t *curr; UINT8 mibbuf; UINT16 basic_rate = host2amd16(20); char buf[20]; DBFENTER; /* set the 'sta basic rate' to 20 and be done with it. */ am930mgr_mibsetitem( mgr, MAC_STA_BASIC_RATE, &basic_rate, sizeof(basic_rate)); /* first find the bss in the known list */ for (curr = mgr->bsslist; curr != NULL; curr = curr->next) { if ( memcmp( bssid, curr->bssid, WLAN_BSSID_LEN) == 0 ) break; } if ( curr == NULL ) { result = 1; } else { if ( WLAN_GET_MGMT_CAP_INFO_ESS(curr->cap_info) ) { /* infrastructure network */ mibbuf = 1; /* localmib.networkmode = 1 */ am930mgr_mibsetitem( mgr, LOC_NETWORK_MODE, &mibbuf, sizeof(mibbuf)); if ( am930hw_joinbss( mgr->hw, curr->channel, 0, bssid, (wlan_ie_ssid_t*)curr->ssid, curr->bcn_int, curr->bss_timestamp, curr->sutro_reftime) == AM930HW_SUCCESS ) { mgr->curr_ch = curr->channel; mgr->curr_rate = curr->rate; mgr->curr_cap_info = curr->cap_info; memcpy( mgr->curr_ssid, curr->ssid, WLAN_IEHDR_LEN + WLAN_SSID_MAXLEN); p802addr_to_str( buf, bssid); WLAN_LOG_DEBUG3(1, "ESS joined, ch=%ld, rate=%ld bssid=%s\n", curr->channel, curr->rate, buf); memcpy( mgr->curr_bssid, bssid, WLAN_BSSID_LEN ); mgr->mac->mode = AM930_MACMODE_ESS_STA; mgr->mac->state = AM930_MACSTATE_NOAUTH; } else { result = 2; } } else { /* adhoc network */ if ( am930hw_joinbss( mgr->hw, curr->channel, 0, bssid, (wlan_ie_ssid_t*)curr->ssid, curr->bcn_int, curr->bss_timestamp, curr->sutro_reftime) == AM930HW_SUCCESS ) { mgr->curr_ch = curr->channel; mgr->curr_rate = curr->rate; p802addr_to_str( buf, bssid); WLAN_LOG_DEBUG3(1, "IBSS joined, ch=%ld, rate=%ld bssid=%s\n", curr->channel, curr->rate, buf); memcpy( mgr->curr_bssid, bssid, WLAN_BSSID_LEN ); mgr->mac->mode = AM930_MACMODE_IBSS_STA; mgr->mac->state = AM930_MACSTATE_NOAUTH; } else { result = 2; } } } DBFEXIT; return result;}/*----------------------------------------------------------------* am930mgr_[get|set]mib[item]** These are pass-through calls used to prevent the llc object* from knowing about the hw object.** returns: zero on success, non-zero on failure (see hw)----------------------------------------------------------------*/UINT32 am930mgr_mibget( am930mgr_t *mgr, UINT32 mibsec, UINT32 len, void *buf){ return am930hw_mibget( mgr->hw, mibsec, 0, len, buf);}UINT32 am930mgr_mibgetitem( am930mgr_t *mgr, UINT32 itemid, void *buf, UINT32 len){ return am930hw_mibgetitem( mgr->hw, itemid, buf, len);}UINT32 am930mgr_mibset( am930mgr_t *mgr, UINT32 mibsec, UINT32 len, void *buf){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?