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

📄 wlan_mac_tmac_nav_rpm_31jan06_ver2.pr.c

📁 opnet无线网络编程
💻 C
📖 第 1 页 / 共 5 页
字号:
#define	PLCP_OVERHEAD_CTRL(size)				(plcp_overhead_control)
#define	PLCP_OVERHEAD_DATA(size)				(plcp_overhead_data)
#define	PLCP_OVERHEAD_CTRL_DR(size,data_rate)	(plcp_overhead_control)

/* Macro definitions to compute the transmission delay of control and data		*/
/* frames.																		*/
#define	TXTIME_CTRL(size)				(PLCP_OVERHEAD_CTRL (size) + (double) size / control_data_rate + \
										 ((wlan_flags->signal_extension) ? WLANC_11g_SIGNAL_EXTENSION : 0.0))						
#define	TXTIME_DATA(size)				(PLCP_OVERHEAD_DATA (size) + (double) size / wsn_data_rate + \
										 ((wlan_flags->signal_extension) ? WLANC_11g_SIGNAL_EXTENSION : 0.0))
#define	TXTIME_CTRL_DR(size,data_rate)	(PLCP_OVERHEAD_CTRL_DR (size, data_rate) + (double) size / data_rate + \
										 ((wlan_flags->signal_extension) ? WLANC_11g_SIGNAL_EXTENSION : 0.0))

/* The size of the step between two non-overlapping WLAN channels in terms of	*/
/* channel numbers.																*/
#define WLANC_CH_STEP_FOR_NO_OVERLAP	((int) ceil (channel_bandwidth / channel_spacing))	

						
/**	State Transitions **/

/** 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													*/ 
/* If a frame is received indicating that the STA should scan, all bets */
/* are off, and the STA moves into the scan state to look for other APs */

// wsn 
#define READY_TO_TRANSMIT		(((intrpt_type == OPC_INTRPT_STRM && wlan_flags->data_frame_to_send == OPC_TRUE && \
								   (pcf_flag == OPC_BOOLINT_DISABLED || (wlan_flags->pcf_active == OPC_FALSE && \
								    (ap_flag == OPC_BOOLINT_ENABLED || cfp_ap_medium_control == OPC_FALSE)))) || \
								  fresp_to_send != WlanC_None || \
								  wlan_flags->polled == OPC_TRUE || \
								  wlan_flags->tx_beacon == OPC_TRUE || \
								  (wlan_flags->pcf_active == OPC_TRUE && ap_flag == OPC_BOOLINT_ENABLED)) && \
								 !roam_state_ptr->scan_mode) && (!sleep)

/* 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 + PRECISION_RECOVERY >= difs_time) && \
	             				  wlan_flags->receiver_busy == OPC_FALSE && \
								  (current_time - rcv_idle_time + PRECISION_RECOVERY >= difs_time) && \
								  wlan_flags->pcf_active == OPC_FALSE) || \
								 wlan_flags->forced_bk_end == OPC_TRUE) && (!sleep)

/* 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_TRUE || fresp_to_send != WlanC_None || \
								 short_retry_count + long_retry_count > 0 || wlan_flags->tx_beacon == OPC_TRUE || \
								 wlan_flags->cw_required == OPC_TRUE)
	
/* After deferring 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 || intrpt_code == WlanC_NAV_Reset_Time) && \
								 wlan_flags->receiver_busy == OPC_FALSE) && (!sleep)

/* Issue 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.			*/
// wsn
//#define	PERFORM_BACKOFF			(fresp_to_send == WlanC_None) && (wlan_flags->backoff_flag == OPC_TRUE || wlan_flags->perform_cw == OPC_TRUE)
//#define PERFORM_BACKOFF			(wlan_flags->backoff_flag == OPC_TRUE || wlan_flags->perform_cw == OPC_TRUE) && (!sleep)
#define PERFORM_BACKOFF			((fresp_to_send == WlanC_None) && (wlan_flags->backoff_flag == OPC_TRUE || wlan_flags->perform_cw == OPC_TRUE)) && (!sleep)


/* 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_FALSE || wlan_flags->forced_bk_end == OPC_TRUE)) && (!sleep)

/* 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_FALSE || wlan_flags->forced_bk_end == OPC_TRUE)) && (!sleep)

/* 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 (successfully) received						*/
#define FRAME_TIMEOUT           ((intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Frame_Timeout) || \
								 bad_cts_to_self_rcvd == OPC_TRUE)

/* 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_FALSE && \
		 						 i_strm == LOW_LAYER_INPUT_STREAM)

/* Skip backoff if no backoff is needed								    */
// wsn
#define	TRANSMIT_FRAME			(wlan_flags->backoff_flag != OPC_TRUE && wlan_flags->perform_cw != OPC_TRUE) && (!sleep)
//#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	BACK_TO_IDLE			(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_FALSE && !roam_state_ptr->scan_mode) && (!sleep)
	
#define SEND_NEW_FRAME_AFTER_CW	(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_TRUE && MEDIUM_IS_IDLE && !roam_state_ptr->scan_mode) && (!sleep)

#define DEFER_AFTER_CW			(CW_COMPLETED && wlan_flags->data_frame_to_send == OPC_TRUE && !MEDIUM_IS_IDLE && !roam_state_ptr->scan_mode) && (!sleep)

/* 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) > rx_power_threshold && !wlan_flags->collision)

#define	RECEIVER_BUSY_LOW		(((intrpt_type == OPC_INTRPT_STAT && intrpt_code < TRANSMITTER_BUSY_INSTAT) || 			\
								  (intrpt_type == OPC_INTRPT_STRM && i_strm != instrm_from_mac_if)			   ) && 	\
	                             !wlan_flags->receiver_busy)
// wsn
#define	PERFORM_TRANSMIT		((BACKOFF_COMPLETED || SEND_NEW_FRAME_AFTER_CW))

#define	BACK_TO_DEFER			((FRAME_RCVD || DEFER_AFTER_CW || \
								 (wlan_flags->tx_beacon == OPC_TRUE && !wlan_flags->receiver_busy)) && (!sleep) )				

/* Macro to evaluate whether the MAC is in a contention free period.	*/
#define	IN_CFP					(pcf_flag == OPC_BOOLINT_ENABLED && \
								 (cfp_ap_medium_control == OPC_TRUE || wlan_flags->pcf_active == OPC_TRUE))

/* After receiving a packet that indicates the end of the current CFP	*/
/* go to back to IDLE state if there is no packet to transmit in the CP.*/
#define	IDLE_AFTER_CFP			(intrpt_type == OPC_INTRPT_STRM && !FRAME_TO_TRANSMIT && !IN_CFP)

/* Macro to cancel the self interrupt for end of deference. It is		*/
/* called at the state transition from DEFER to IDLE.					*/
#define	CANCEL_DEF_EVENT		(op_ev_cancel (deference_evh))

#define FRM_END_TO_IDLE			(!FRAME_TO_TRANSMIT && !EXPECTING_FRAME && !IN_CFP)
	
#define	FRM_END_TO_DEFER		(!EXPECTING_FRAME && (FRAME_TO_TRANSMIT || IN_CFP))

/* Macros associated with the "SCAN" state. If the scan mode flag is	*/
/* set, the STA considers itself disconnected from its AP and starts	*/
/* scanning for a new AP-- only in DCF STAs.							*/
#define AP_DISCONNECTED 		(roam_state_ptr->scan_mode == OPC_TRUE) && (!sleep)

#define AP_CONNECTED 			(roam_state_ptr->scan_mode == OPC_FALSE) && (!sleep)

#define DATA_FRAME_TO_TX 		(wlan_flags->data_frame_to_send == OPC_TRUE) && (!sleep)

#define SCAN_TIMEOUT			(intrpt_type == OPC_INTRPT_SELF && intrpt_code == WlanC_Scan_Timeout) && (!sleep)

#define SCAN_AFTER_CW			(CW_COMPLETED && AP_DISCONNECTED) && (!sleep)

// wsn
#define SLEEP_NOW					sleep
#define	WAKE_UP_TRANSIT				(!sleep)
#define WAKE_UP_IDLE				(!sleep) && (state == WSN_IDLE)

/** Function Prototypes **/
static void			wlan_mac_sv_init (void);

⌨️ 快捷键说明

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