?? p80211.c
字號:
/* p80211.c: ieee 802.11 support functions* --------------------------------------------------------------------* Linux WLAN ** The contents of this file are subject to the Mozilla Public* License Version 1.0 (the "License"); you may not use this file* except in compliance with the License. You may obtain a copy of* the License at http://www.mozilla.org/MPL/** Software distributed under the License is distributed on an "AS* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or* implied. See the License for the specific language governing* rights and limitations under the License.** The initial developer of the original code is Mark S. Mathews* <mark@absoval.com>. Portions created by Mark S. Mathews* are Copyright (C) 1998 AbsoluteValue Software, Inc. All Rights Reserved.** --------------------------------------------------------------------** Provides the implementation of functions handling generic ieee 802.11* networking issues.*/#include <linux/config.h>#include <wlan/wlan_compat.h>#if (WLAN_OS == WLAN_LINUX_KERNEL)/* The following prevents "kernel_version" from being set in this file. */#define __NO_VERSION__#include <linux/version.h>#include <linux/modversions.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/string.h>/* Standard driver includes */#include <linux/kernel.h>#elif (WLAN_OS == WLAN_LWOS)#include <wlan/wlan_compat.h>#include <kernel.h>#endif#include <wlan/p80211hdr.h>#include <wlan/p80211mgmt.h>/*-------------------------------------------------------------- p80211addr_to_str Formats a 6 byte IEEE 802 address as a string of the form xx:xx:xx:xx:xx:xx where the bytes are in hex. On entry Assumptions: buf is at least 18 bytes long addr is at least 6 bytes long--------------------------------------------------------------*/void p802addr_to_str( char *buf, UINT8 *addr){ int strindex = 0; int addrindex; for( addrindex = 0; addrindex < 6; addrindex++) { buf[strindex] = ((addr[addrindex] & 0xf0) >> 4) > 9 ? 'a' + (((addr[addrindex] & 0xf0) >> 4) - 10) : '0' + ((addr[addrindex] & 0xf0) >> 4); buf[strindex + 1] = (addr[addrindex] & 0x0f) > 9 ? 'a' + ((addr[addrindex] & 0x0f) - 10) : '0' + (addr[addrindex] & 0x0f); buf[strindex + 2] = ':'; strindex += 3; } buf[strindex] = '\0'; return;}/*-------------------------------------------------------------- Encode Beacon Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field. On entry Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len, buf, and priv are zero--------------------------------------------------------------*/void wlan_mgmt_encode_beacon( wlan_fr_beacon_t *f ){ f->type = WLAN_FSTYPE_BEACON; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT( f->len >= WLAN_BEACON_FR_MAXLEN ); /*-- Fixed Fields ----*/ f->ts = (UINT64*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_TS); f->bcn_int = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_BCN_INT); f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_CAPINFO); f->len = WLAN_HDR_A3_LEN + WLAN_BEACON_OFF_CAPINFO + sizeof(*(f->cap_info)); return;}/*-------------------------------------------------------------- Decode Beacon Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len and buf are zero--------------------------------------------------------------*/void wlan_mgmt_decode_beacon( wlan_fr_beacon_t *f ){ wlan_ie_t *ie_ptr; f->type = WLAN_FSTYPE_BEACON; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT(WLAN_FTYPE_MGMT == WLAN_GET_FC_FTYPE(ieee2host16(f->hdr->a3.fc))); WLAN_ASSERT(WLAN_FSTYPE_BEACON == WLAN_GET_FC_FSTYPE(ieee2host16(f->hdr->a3.fc))); /*-- Fixed Fields ----*/ f->ts = (UINT64*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_TS); f->bcn_int = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_BCN_INT); f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_CAPINFO); /*-- Information elements */ ie_ptr = (wlan_ie_t*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_BEACON_OFF_SSID); while( ((UINT8*)ie_ptr) < (f->buf + f->len) ) { switch (ie_ptr->eid) { case WLAN_EID_SSID: f->ssid = (wlan_ie_ssid_t*)ie_ptr; break; case WLAN_EID_SUPP_RATES: f->supp_rates = (wlan_ie_supp_rates_t*)ie_ptr; break; case WLAN_EID_FH_PARMS: f->fh_parms = (wlan_ie_fh_parms_t*)ie_ptr; break; case WLAN_EID_DS_PARMS: f->ds_parms = (wlan_ie_ds_parms_t*)ie_ptr; break; case WLAN_EID_CF_PARMS: f->cf_parms = (wlan_ie_cf_parms_t*)ie_ptr; break; case WLAN_EID_IBSS_PARMS: f->ibss_parms = (wlan_ie_ibss_parms_t*)ie_ptr; break; case WLAN_EID_TIM: f->tim = (wlan_ie_tim_t*)ie_ptr; break; default: WLAN_LOG_WARNING1( "Unrecognized EID=%dd in beacon decode.\n",ie_ptr->eid); WLAN_HEX_DUMP(3, "frm w/ bad eid:", f->buf, f->len ); break; } ie_ptr = (wlan_ie_t*)(((UINT8*)ie_ptr) + 2 + ie_ptr->len); } return;}/*-------------------------------------------------------------- Encode IBSS ATIM Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field. On entry Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len, buf, and priv are zero--------------------------------------------------------------*/void wlan_mgmt_encode_ibssatim( wlan_fr_ibssatim_t *f ){ f->type = WLAN_FSTYPE_ATIM; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT( f->len >= WLAN_ATIM_FR_MAXLEN ); /*-- Fixed Fields ----*/ /*-- Information elements */ f->len = WLAN_HDR_A3_LEN; return;}/*-------------------------------------------------------------- Decode IBSS ATIM Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len and buf are zero--------------------------------------------------------------*/void wlan_mgmt_decode_ibssatim( wlan_fr_ibssatim_t *f ){ f->type = WLAN_FSTYPE_ATIM; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT(WLAN_FTYPE_MGMT == WLAN_GET_FC_FTYPE(ieee2host16(f->hdr->a3.fc))); WLAN_ASSERT(WLAN_FSTYPE_ATIM == WLAN_GET_FC_FSTYPE(ieee2host16(f->hdr->a3.fc))); /*-- Fixed Fields ----*/ /*-- Information elements */ return;}/*-------------------------------------------------------------- Encode Disassociation Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field. On entry Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len, buf, and priv are zero--------------------------------------------------------------*/void wlan_mgmt_encode_disassoc( wlan_fr_disassoc_t *f ){ f->type = WLAN_FSTYPE_DISASSOC; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT( f->len >= WLAN_DISASSOC_FR_MAXLEN ); /*-- Fixed Fields ----*/ f->reason = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_DISASSOC_OFF_REASON); f->len = WLAN_HDR_A3_LEN + WLAN_DISASSOC_OFF_REASON + sizeof(*(f->reason)); return;}/*-------------------------------------------------------------- Decode Disassociation Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len and buf are zero--------------------------------------------------------------*/void wlan_mgmt_decode_disassoc( wlan_fr_disassoc_t *f ){ f->type = WLAN_FSTYPE_DISASSOC; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT(WLAN_FTYPE_MGMT == WLAN_GET_FC_FTYPE(ieee2host16(f->hdr->a3.fc))); WLAN_ASSERT(WLAN_FSTYPE_DISASSOC == WLAN_GET_FC_FSTYPE(ieee2host16(f->hdr->a3.fc))); /*-- Fixed Fields ----*/ f->reason = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_DISASSOC_OFF_REASON); /*-- Information elements */ return;}/*-------------------------------------------------------------- Encode Association Request Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field. On entry Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len, buf, and priv are zero--------------------------------------------------------------*/void wlan_mgmt_encode_assocreq( wlan_fr_assocreq_t *f ){ f->type = WLAN_FSTYPE_ASSOCREQ; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT( f->len >= WLAN_ASSOCREQ_FR_MAXLEN ); /*-- Fixed Fields ----*/ f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCREQ_OFF_CAP_INFO); f->listen_int = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCREQ_OFF_LISTEN_INT); f->len = WLAN_HDR_A3_LEN + WLAN_ASSOCREQ_OFF_LISTEN_INT + sizeof(*(f->listen_int)); return;}/*-------------------------------------------------------------- Decode Association Request Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len and buf are zero--------------------------------------------------------------*/void wlan_mgmt_decode_assocreq( wlan_fr_assocreq_t *f ){ wlan_ie_t *ie_ptr; f->type = WLAN_FSTYPE_ASSOCREQ; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT(WLAN_FTYPE_MGMT == WLAN_GET_FC_FTYPE(ieee2host16(f->hdr->a3.fc))); WLAN_ASSERT(WLAN_FSTYPE_ASSOCREQ == WLAN_GET_FC_FSTYPE(ieee2host16(f->hdr->a3.fc))); /*-- Fixed Fields ----*/ f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCREQ_OFF_CAP_INFO); f->listen_int = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCREQ_OFF_LISTEN_INT); /*-- Information elements */ ie_ptr = (wlan_ie_t*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCREQ_OFF_SSID); while( ((UINT8*)ie_ptr) < (f->buf + f->len) ) { switch (ie_ptr->eid) { case WLAN_EID_SSID: f->ssid = (wlan_ie_ssid_t*)ie_ptr; break; case WLAN_EID_SUPP_RATES: f->supp_rates = (wlan_ie_supp_rates_t*)ie_ptr; break; default: WLAN_LOG_WARNING1( "Unrecognized EID=%dd in assocreq decode.\n", ie_ptr->eid); WLAN_HEX_DUMP(3, "frm w/ bad eid:", f->buf, f->len ); break; } ie_ptr = (wlan_ie_t*)(((UINT8*)ie_ptr) + 2 + ie_ptr->len); } return;}/*-------------------------------------------------------------- Encode Association Response Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field. On entry Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len, buf, and priv are zero--------------------------------------------------------------*/void wlan_mgmt_encode_assocresp( wlan_fr_assocresp_t *f ){ f->type = WLAN_FSTYPE_ASSOCRESP; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT( f->len >= WLAN_ASSOCRESP_FR_MAXLEN ); /*-- Fixed Fields ----*/ f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_CAP_INFO); f->status = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_STATUS); f->aid = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_AID); f->len = WLAN_HDR_A3_LEN + WLAN_ASSOCRESP_OFF_AID + sizeof(*(f->aid)); return;}/*-------------------------------------------------------------- Decode Association Response Assumptions: 1) f->len and f->buf are already set 2) f->len is the length of the MAC header + data, the CRC is NOT included 3) all members except len and buf are zero--------------------------------------------------------------*/void wlan_mgmt_decode_assocresp( wlan_fr_assocresp_t *f ){ f->type = WLAN_FSTYPE_ASSOCRESP; f->hdr = (p80211_hdr_t*)f->buf; WLAN_ASSERT(WLAN_FTYPE_MGMT == WLAN_GET_FC_FTYPE(ieee2host16(f->hdr->a3.fc))); WLAN_ASSERT(WLAN_FSTYPE_ASSOCRESP == WLAN_GET_FC_FSTYPE(ieee2host16(f->hdr->a3.fc))); /*-- Fixed Fields ----*/ f->cap_info = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_CAP_INFO); f->status = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_STATUS); f->aid = (UINT16*)(WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_AID); /*-- Information elements */ f->supp_rates = (wlan_ie_supp_rates_t*) (WLAN_HDR_A3_DATAP(&(f->hdr->a3)) + WLAN_ASSOCRESP_OFF_SUPP_RATES); return;}/*-------------------------------------------------------------- Encode Reassociation Request Receives an fr_mgmt struct with its len and buf set. Fills in the rest of the members as far as possible. On entry len is the length of the buffer, on return len is the actual length of the frame with all the currently encoded fields. For frames where the caller adds variable/optional IEs, the caller will have to update the len field.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -