⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsr_wlan_mac.pr.c

📁 afit的ad hoc路由协议源码
💻 C
📖 第 1 页 / 共 5 页
字号:
/* Process model C form file: dsr_wlan_mac.pr.c */
/* Portions of this file copyright 1992-2001 by OPNET Technologies, Inc. */



/* This variable carries the header into the object file */
static const char dsr_wlan_mac_pr_c [] = "MIL_3_Tfile_Hdr_ 80C 30A modeler 7 3C879222 3C879222 1 jballah Jason@Ballah 0 0 none none 0 0 none 0 0 0 0 0 0                                                                                                                                                                                                                                                                                                                                                                                                                 ";
#include <string.h>



/* OPNET system definitions */
#include <opnet.h>

#if defined (__cplusplus)
extern "C" {
#endif
FSM_EXT_DECS
#if defined (__cplusplus)
} /* end of 'extern "C"' */
#endif


/* Header Block */

#include <math.h>
#include "oms_pr.h"
#include "oms_tan.h"
#include "oms_bgutil.h"

/* Definitions to all protocol specific parameters*/
#include "wlan_support.h"

/* Station address assignment definitions.				  */ 
#include "oms_auto_addr_support.h"
#include "oms_dist_support.h"

//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
// define packet Types
#define DATA_PACKET_TYPE 7
#define REQUEST_PACKET_TYPE 2
#define REPLY_PACKET_TYPE 3
#define ERROR_PACKET_TYPE 4

// remote intrpt or self intrpt codes definition
#define ACK_CODE 1
#define ERROR_CODE 2
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/* incoming statistics and stream wires */
#define 	TRANSMITTER_BUSY_INSTAT			4
#define		LOW_LAYER_INPUT_STREAM_CH4		3
#define 	LOW_LAYER_OUT_STREAM_CH1		0
#define 	LOW_LAYER_OUT_STREAM_CH2		1
#define 	LOW_LAYER_OUT_STREAM_CH3		2
#define 	LOW_LAYER_OUT_STREAM_CH4		3

/* Flags to load different variables based on attribute settings.	*/
#define		WLAN_AP						1
#define		WLAN_STA					0

/* Special value indicating BSS identification is not used.			*/
#define		WLAN_BSSID_NOT_USED			-1

/* Special value indicating radio tranceiver frequencies are set	*/
/* based on the BSS identification.									*/
#define 	WLAN_BSS_BASED_FREQ_USED	-1

//$$$$$$$$$$$$$$$$$$ DSR $$$$$$$$$$$$$$$$$$$$$$$$
Stathandle stat_mac_failed_data;
int mac_failed_data;
Stathandle stat_mac_failed_reply;
int mac_failed_reply;
Stathandle stat_mac_failed_error;
int	mac_failed_error=0;
Stathandle stat_mac_total_failed;
int mac_total_failed=0;
Stathandle stat_mac_retry_rts;
int mac_retry_rts;
Stathandle stat_mac_retry_data;
int mac_retry_data;
Stathandle stat_mac_retry_reply;
int mac_retry_reply;
Stathandle stat_mac_retry_error;
int mac_retry_error;
Stathandle stat_mac_total_retry;
int mac_total_retry;
//$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

/* 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 intialized 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;
 
/* Global variable to keep note of the nature of the subnet.					*/
/* This variable is intialized to not set.										*/
WlanT_Bss_Identification_Approach bss_id_type = WlanC_Not_Set;

/* 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		/* Bakcoff done after successful frame transmission	*/	
	} WlanT_Mac_Intrpt_Code;

/* Define codes for data and managment frames use in DCF		        		*/
/* The code defined is consistent with IEEE 802.11 format			    		*/
/* There are 6 bits used to define the code and in the following        		*/
/* enumeration the first 6 bits are used in the type field of the frame.		*/
typedef enum WlanT_Mac_Frame_Type
	{
	WlanC_Rts  = 0x6C, /* Rts code set into the Rts control frame */
    WlanC_Cts  = 0x70, /* Cts code set into the Cts control frame */
	WlanC_Ack  = 0x74, /* Ack code set into the Ack control frame */
 	WlanC_Data = 0x80, /* Data code set into the Data frame       */
	WlanC_None = 0x00  /* None type 							  */
	} WlanT_Mac_Frame_Type;

/* 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;

/* 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 wether 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		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.								*/
	} WlanT_Mac_Flags;

/* This structure contains the destination address to which the received */
/* data packet needs to be sent and the contents of the recieved 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;

/**	Macros	Definition														**/
/** 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			**/
/** Frames cannot be transmitted until medium is idle. Once, the medium 	**/
/** is available then the station is eligible to transmit provided there	**/
/** is a need for backoff. Once the transmission is complete then the		**/
/** station will wait for the response provided the frame transmitted  		**/
/** requires a response (such as Rts and Data frames). If response			**/
/** is not needed then the station will defer to transmit next packet		**/

/* After receiving a stream interrupt, we need to switch states from	*/
/* idle to defer or transmit if there is a frame to transmit and the	*/
/* receiver is not busy													*/ 
#define READY_TO_TRANSMIT		(intrpt_type == OPC_INTRPT_STRM && wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED && \
								(wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED || fresp_to_send != WlanC_None))
	
/* When we have a frame to transmit, we move to transmit state if the	*/
/* medium was idle for at least a DIFS time, otherwise we go to defer	*/
/* state.																*/
#define MEDIUM_IS_IDLE			((current_time - nav_duration >= difs_time) && \
	             				 (wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED) && \
								 (current_time - rcv_idle_time >= difs_time))

/* Change state to Defer from Frm_End, if the input buffers are not empty or a frame needs	*/
/* to be retransmitted or the station has to respond to some frame.							*/		
#define FRAME_TO_TRANSMIT		(wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED || fresp_to_send != WlanC_None || \
	                             retry_count != 0 || wlan_flags->cw_required == OPC_BOOLINT_ENABLED)
	
/* After defering for either collision avoidance or interframe gap      */
/* the channel will be available for transmission 						*/
#define DEFERENCE_OFF			(intrpt_type == OPC_INTRPT_SELF && \
								 intrpt_code == WlanC_Deference_Off && \
								 wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED)

/* Isssue a transmission complete stat once the packet has successfully */
/* been transmitted from the source station								*/						 
#define TRANSMISSION_COMPLETE	(intrpt_type == OPC_INTRPT_STAT && \
								 op_intrpt_stat () == TRANSMITTER_BUSY_INSTAT)

/* Backoff is performed based on the value of the backoff flag.			*/
#define PERFORM_BACKOFF			(wlan_flags->backoff_flag == OPC_BOOLINT_ENABLED || wlan_flags->perform_cw == OPC_BOOLINT_ENABLED)

/* Need to start transmitting frame once the backoff (self intrpt) 		*/
/* completed															*/
#define BACKOFF_COMPLETED		(intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Backoff_Elapsed && \
								 wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED)

/* Contention Window period, which follows a successful packet			*/
/* transmission, is completed.											*/
#define CW_COMPLETED			(intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_CW_Elapsed && \
								 wlan_flags->receiver_busy == OPC_BOOLINT_DISABLED)


/* After transmission the station will wait for a frame response for    */
/* Data and Rts frames.												    */
#define WAIT_FOR_FRAME          (expected_frame_type != WlanC_None)

/* Need to retransmit frame if there is a frame timeout and the         */
/* required frame is not received									    */
#define FRAME_TIMEOUT           (intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Frame_Timeout)

/* If the frame is received appropriate response will be transmitted    */
/* provided the medium is considered to be idle						    */
#define FRAME_RCVD			    (intrpt_type == OPC_INTRPT_STRM && bad_packet_rcvd == OPC_BOOLINT_DISABLED && \
		 						 i_strm <= LOW_LAYER_INPUT_STREAM_CH4)

/* Skip backoff if no backoff is needed								    */
#define TRANSMIT_FRAME			(!PERFORM_BACKOFF)

/* Expecting frame response	after data or Rts transmission			    */
#define EXPECTING_FRAME			(expected_frame_type != WlanC_None)

/* When the contention window period is over then we go to IDLE state	*/
/* if we don't have another frame to send at that moment. If we have	*/
/* one then we go to TRANSMIT state if we did not sense any activity	*/
/* on our receiver for a period that is greater than or equal to DIFS	*/
/* period; otherwise we go to DEFER state to defer and back-off before	*/
/* transmitting the new frame.											*/
#define	IDLE_AFTER_CW			(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_BOOLINT_DISABLED)
#define SEND_NEW_FRAME_AFTER_CW	(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED && MEDIUM_IS_IDLE)
#define DEFER_AFTER_CW			(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED && !MEDIUM_IS_IDLE)

/* Macros that check the change in the busy status of the receiver.	   	*/
#define	RECEIVER_BUSY_HIGH		(intrpt_type == OPC_INTRPT_STAT && intrpt_code < TRANSMITTER_BUSY_INSTAT && \
								 op_stat_local_read (intrpt_code) == 1.0 && ((rcv_channel_status ^ (1 << intrpt_code)) == 0))
#define	RECEIVER_BUSY_LOW		(intrpt_type == OPC_INTRPT_STAT && intrpt_code < TRANSMITTER_BUSY_INSTAT && \
								 rcv_channel_status == 0)

/* This condition was created for the DSR model to fix a NIL pointer problem when 
	RTS/CTS is turned on and a packet of size zero is sent */		
#define FRAME_TO_SEND			(wlan_flags->data_frame_to_send == OPC_BOOLINT_ENABLED || fresp_to_send != WlanC_None || \
	                             retry_count != 0 || (op_prg_list_size (hld_list_ptr) != 0) || \
								(op_sar_buf_size (fragmentation_buffer_ptr) != 0))
	

/* Function declarations.	*/
static void			wlan_mac_sv_init ();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -