📄 gpr_wlan_mac.pr.c
字号:
/* Process model C form file: gpr_wlan_mac.pr.c */
/* Portions of this file copyright 1992-2003 by OPNET Technologies, Inc. */
/* This variable carries the header into the object file */
const char gpr_wlan_mac_pr_c [] = "MIL_3_Tfile_Hdr_ 100A 30A op_runsim 7 42FB0CD7 42FB0CD7 1 zhangzhong jc 0 0 none none 0 0 none 0 0 0 0 0 0 0 0 8f3 1 ";
#include <string.h>
/* OPNET system definitions */
#include <opnet.h>
/* Header Block */
/** Include files **/
#include <math.h>
#include <string.h>
#include "oms_pr.h"
#include "oms_tan.h"
#include "oms_bgutil.h"
#include "wlan_support.h"
#include "oms_auto_addr_support.h"
#include "oms_dist_support.h"
#include "bridge_header.h"
#include "prg_mapping.h"
#include <prg_geo.h>
/** Constants **/
/* Incoming statistics and stream wires. */
#define TRANSMITTER_BUSY_INSTAT 1
#define LOW_LAYER_INPUT_STREAM 0
#define LOW_LAYER_OUTPUT_STREAM 0
/* Flags to load different variables based on attribute settings. */
#define WLAN_AP 1
#define WLAN_STA 0
/* Flags to indicate the medium access mode (PCF/DCF). */
#define PCF_ACTIVE 1
#define PCF_INACTIVE 0
/* Special value indicating BSS identification is not used. */
#define WLAN_BSSID_NOT_USED -1
/* Special value indicating radio transceiver frequencies are set */
/* based on the BSS identification. */
#define WLAN_BSS_BASED_FREQ_USED -1
/* Special value indicating that the number of back-off slots are */
/* not determined yet. */
#define BACKOFF_SLOTS_UNSET -1.0
/* Define a small value (= 1 psec), which will be used to recover */
/* from double arithmetic precision losts while doing time related */
/* precision sensitive computations. */
#define PRECISION_RECOVERY 0.000000000001
/* Special value indicating BSS identification is currently unset. */
#define WLANC_BSS_ID_UNKNOWN -2
/* Define the lowest data transmission rate supported by WLAN MAC. */
#define LOWEST_TX_RATE 1000000.0 /* bits/sec */
/* Speed of light (m/s). */
#define C 3.0E+08
/* 16 times pi-squared. */
#define SIXTEEN_PI_SQ 157.91367
/* In the idle state, number of beacon intervals after which the STA will wake */
/* up to check if it is still connected, if scanning is based on beacon */
/* reliability. There are no interrupts pending in the idle state, therefore, */
/* it is possible that the STA's state may be set to "scan" from a pipeline */
/* state without the MAC becoming aware of the state change till a packet */
/* arrives from the higher layer. Hence, there is a need to schedule periodic */
/* interrupts when in IDLE. */
#define WLANC_CONN_CHK_BEACON_MULT 5.0
/* Period after which the STA will check for connectivity if scanning is */
/* distance based. */
#define WLANC_CONN_CHK_DIST_INTERVAL 10.0
/* When in the SCAN state, the period that an STA will wait before trying a new */
/* channel. */
#define WLANC_NEW_SCAN_BEACON_MULT 2.5
/* Physical layer parameters used during roaming/channel scanning. */
#define WLANC_CHANNEL_COUNT 11
#define WLANC_FIRST_CHAN_MIN_FREQ 2401.0 /* MHz */
#define WLANC_CHANNEL_BANDWIDTH 22.0 /* MHz */
#define WLANC_CHANNEL_SPACING 5.0 /* MHz */
#define WLANC_LAST_CHAN_MIN_FREQ ((WLANC_CHANNEL_COUNT - 1) * WLANC_CHANNEL_SPACING + WLANC_FIRST_CHAN_MIN_FREQ)
#define WLANC_CH_STEP_FOR_NO_OVERLAP ((int) ceil (WLANC_CHANNEL_BANDWIDTH / WLANC_CHANNEL_SPACING))
/* When virtual scanning is used, two different thresholds are used to decide */
/* when the STA must start looking for a new AP, and when a new AP is */
/* considered acceptable. This brings in a "hysteresis" which ensures that the */
/* STA does not flip-flop rapidly between APs. */
#define WLANC_ROAM_SCAN_START_VIRTUAL_THRESH rx_power_threshold
#define WLANC_ROAM_NEW_CONN_VIRTUAL_THRESH (rx_power_threshold * 1.1)
/** Enumarated Types **/
/* Define the three possible values that a global variable takes */
/* to check and ensure that all the MAC modules are either BSS ID */
/* based or purely subnet based. The variable is initialized to */
/* Not_Set and the first wireless MAC process sets it to either */
/* Entire_Subnet (if BSS_Identifier is Not Used) or Bssid_Subnet */
/* (if the BSS_Identifier is set to some value other than Not */
/* Used). */
typedef enum WlanT_Bssid_Approach
{
WlanC_Not_Set, /* Type of network not set */
WlanC_Entire_Subnet, /* The network is a pure subnet */
WlanC_Bss_Divided_Subnet /* The network is a BSS based subnet */
} WlanT_Bss_Identification_Approach;
/* Define interrupt codes for generating handling interrupts */
/* indicating changes in deference, frame timeout which infers */
/* that the collision has occurred, random backoff and transmission */
/* completion by the physical layer (self interrupts). */
typedef enum WlanT_Mac_Intrpt_Code
{
WlanC_Deference_Off, /* Deference before frame transmission */
WlanC_Frame_Timeout, /* No frame rcvd in set duration (infer collision) */
WlanC_Backoff_Elapsed, /* Backoff done before frame transmission */
WlanC_CW_Elapsed, /* Backoff done after successful frame transmission */
WlanC_Beacon_Tx_Time, /* Time to transmit beacon frame */
WlanC_Cfp_End, /* End of the Contention free period */
WlanC_Scan_Timeout, /* End of scan duration for given channel */
WlanC_AP_Check_Timeout /* Time to check the connectivity status with the */
/* current AP. */
} WlanT_Mac_Intrpt_Code;
/* Defining codes for the physical layer characteristics type. */
typedef enum WlanT_Phy_Char_Code
{
WlanC_Frequency_Hopping,
WlanC_Direct_Sequence,
WlanC_Infra_Red
} WlanT_Phy_Char_Code;
/** Data Structures **/
/* Define a structure to maintain data fragments received by each */
/* station for the purpose of reassembly (or defragmentation) */
typedef struct WlanT_Mac_Defragmentation_Buffer_Entry
{
int tx_station_address ;/* Store the station address of transmitting station */
double time_rcvd ;/* Store time the last fragment for this frame was received */
Sbhandle reassembly_buffer_ptr ;/* Store data fragments for a particular packet */
} WlanT_Mac_Defragmentation_Buffer_Entry;
/* Define a structure to maintain a copy of each unique data frame */
/* received by the station. This is done so that the station can */
/* discard any additional copies of the frame received by it. */
typedef struct WlanT_Mac_Duplicate_Buffer_Entry
{
int tx_station_address; /* store the station address of transmitting station */
int sequence_id ; /* rcvd packet sequence id */
int fragment_number ; /* rcvd packet fragment number */
} WlanT_Mac_Duplicate_Buffer_Entry;
/* This structure contains all the flags used in this process model to determine */
/* various conditions as mentioned in the comments for each flag */
typedef struct WlanT_Mac_Flags
{
Boolean data_frame_to_send; /* Flag to check when station needs to transmit. */
Boolean backoff_flag; /* Backoff flag is set when either the collision is */
/* inferred or the channel switched from busy to idle */
Boolean rts_sent; /* Flag to indicate that whether the Rts for this */
/* particular data frame is sent */
Boolean rcvd_bad_packet; /* Flag to indicate that the received packet is bad */
Boolean receiver_busy; /* Set this flag if receiver busy stat is enabled */
Boolean transmitter_busy; /* Set this flag if we are transmitting something. */
Boolean wait_eifs_dur; /* Set this flag if the station needs to wait for eifs */
/* duration. */
Boolean gateway_flag; /* Set this flag if the station is a gateway. */
Boolean bridge_flag; /* Set this flag if the station is a bridge */
Boolean immediate_xmt; /* Set this flag if the new frame can be transmitted */
/* without deferring. */
Boolean forced_bk_end; /* Special case: resume with completion of back-off (or */
/* CW) period regardless of receiver's status. */
Boolean cw_required; /* Indicates that the MAC is in contention window */
/* period following a successful transmission. */
Boolean perform_cw; /* Flag that triggers backoff process for CW period. */
Boolean nav_updated; /* Indicates a new NAV value since the last time when */
/* self interrupt is scheduled for the end of deference.*/
Boolean collision; /* Set this flag if a channel became busy while another */
/* one busy. */
Boolean collided_packet; /* Set this flag to drop the next received packet */
/* because of collision. */
Boolean duration_zero; /* Set this flag if duration should be zero in next ack */
Boolean ignore_busy; /* Set this flag if the STA should ignore receiver busy */
Boolean tx_beacon; /* Set this flag if time to send a beacon */
Boolean tx_cf_end; /* Set this flag if time to send a CF End frame */
Boolean pcf_active; /* Set this flag for AP if PCF is currently in effect */
Boolean polled; /* Set this flag if the station has received a poll */
Boolean more_data; /* Set this flag if must poll for more data (MSDU) */
Boolean more_frag; /* Set this flag if must poll for more fragments */
Boolean pcf_side_traf; /* Set this flag if the AP detects STA to STA traffic */
Boolean active_poll; /* Set this flag if an active poll is outstanding */
} WlanT_Mac_Flags;
/* This structure contains the destination address to which the received */
/* data packet needs to be sent and the contents of the received packet */
/* from the higher layer. */
typedef struct WlanT_Hld_List_Elem
{
double time_rcvd; /* Time packet is received by the higher layer */
int destination_address; /* Station to which this packet needs to be sent*/
Packet* pkptr; /* store packet contents */
} WlanT_Hld_List_Elem;
/* Information record for each BSS */
typedef struct bss_mapping_info
{
int bss_idx;
int ap_sta_addr;
PrgT_Mapping_Handle sta_mapping_hndl;
}WlanT_Bss_Mapping_Info;
/* Information record for each STA */
typedef struct sta_mapping_info
{
int sta_addr;
PrgT_Mapping_Handle dup_mapping_hndl;
}WlanT_Sta_Mapping_Info;
/* Information record for each STA */
typedef struct dup_mapping_info
{
int rem_sta_addr;
WlanT_Mac_Duplicate_Buffer_Entry* duplicate_ptr;
}WlanT_Duplicate_Mapping_Info;
/* Information regarding the location of each APs */
typedef struct
{
int ap_bss_id;
int ap_channel_num;
double tx_power;
double lat;
double lon;
double alt;
}
WlanT_AP_Position_Info;
/** Global Variables **/
/* Global list of AP position info. */
List* global_ap_pos_info_lptr = OPC_NIL;
/* Global variable to keep note of the nature of the subnet. */
/* This variable is initialized to not set. */
WlanT_Bss_Identification_Approach bss_id_type = WlanC_Not_Set;
/** Macro Definitions **/
/** The data frame send flag is set whenever there is a data to be send by **/
/** the higher layer or the response frame needs to be sent. However, in **/
/** either case the flag will not be set if the receiver is busy **/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -