📄 wlan_mac_tmac_nav_rpm_31jan06_ver2.header block
字号:
double wsn_energy_global = 0;
double wsn_global_energy_pool = 0;
double wsn_global_Sleep_Percentage = 0;
double wsn_global_LPM3_Percentage = 0;
double wsn_global_LPM2_Percentage = 0;
double wsn_global_LPM1_Percentage = 0;
// mib WSN global variable from the WSN_Sink
extern double Cumulative_ETE_Delay;
extern int Total_Number_Packets;
Boolean wsn_channel_busy_global = OPC_FALSE; /* used in adaptive timeout for immediate response */
int wsn_number_TX_nodes_global = 0; /* used in adaptive timeout for immediate response */
/* Global linked list of AP position info. */
WlanT_AP_Position_Info* global_ap_pos_info_head = 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;
/* Read-only array of the minimum frequencies of the 12 operational 802.11a */
/* WLAN channels. */
double WLANC_11a_CHNL_MIN_FREQ_ARRAY [WLANC_11a_OPER_CHNL_COUNT] =
{5170.0, 5190.0, 5210.0, 5230.0, 5250.0, 5270.0, 5290.0, 5310.0, 5735.0, 5755.0, 5775.0, 5795.0};
/* Read-only arrays for mandatory 802.11a and 802.11g data rates. */
double WLANC_11a_MANDATORY_DRATE_ARRAY [3] = {24000000.0, 12000000.0, 6000000.0};
double WLANC_11g_MANDATORY_DRATE_ARRAY [7] = {24000000.0, 12000000.0, 11000000.0, 6000000.0, 5500000.0, 2000000.0, 1000000.0};
/** Macro Definitions **/
/* 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)
/* Macro definitions to compute the PLCP overhead for control and data frames. */
#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);
static void wlan_transceiver_channel_init (void);
static void wlan_rxgroup_reduce (void);
static void wlan_higher_layer_data_arrival (void);
static void wlan_hl_packet_drop (Packet* hld_pkptr, OpT_Packet_Size data_size);
static void wlan_hlpk_enqueue (Packet* hld_pkptr, int dest_addr, Boolean polling);
static void wlan_frame_transmit (void);
static void wlan_prepare_frame_to_send (WlanT_Mac_Frame_Type frame_type);
//static double wlan_ctrl_response_drate_determine (double rcvd_data_rate);
static void wlan_slot_time_set (double new_slot_time);
static void wlan_frame_tx_phy_info_set (Packet* frame_ptr, double tx_data_rate);
static void wlan_interrupts_process (void);
static void wlan_physical_layer_data_arrival (void);
static Boolean wlan_tuple_find (int sta_addr, int seq_id, int frag_num, int dest_addr);
static void wlan_data_process (Packet* seg_pkptr, int dest_addr, int sta_addr, int final_dest_addr, int frag_num, int more_frag, OpT_Packet_Id pkt_id);
static void wlan_received_packet_to_higher_layer_forward (Packet* pkptr);
static void wlan_accepted_frame_stats_update (Packet* seg_pkptr);
static void wlan_schedule_deference (void);
static void wlan_frame_discard (void);
static void wlan_mac_rcv_channel_status_update (int channel_id);
static void wlan_mac_error (const char* msg1, const char* msg2, const char* msg3);
static void wlan_frame_type_conv (WlanT_Mac_Frame_Type frame_type, char* frame_type_name);
static int wlan_bss_id_list_manage (int bssid, const char* operation);
static PrgT_Mapping_Handle wlan_bss_mapping_get (void);
static int wlan_get_ap_sta_addr (int bss_idx);
static WlanT_Sta_Mapping_Info* wlan_sta_addr_register (int bss_idx, int sta_addr, int sta_is_ap, Objid sta_mac_objid, WlanT_Phy_Char_Code phy_char);
static WlanT_Bss_Mapping_Info* wlan_bss_info_get (int bssid);
static WlanT_Sta_Mapping_Info* wlan_sta_info_get (int sta_addr, Boolean serialize);
static double wlan_min_freq_for_chan (int chan_num);
static void wlan_begin_new_scan (void);
static void wlan_set_transceiver_channel (int chan_num);
static void wlan_ap_switch (void);
static void wlan_sta_addr_deregister (int bss_idx, int sta_addr);
static void wlan_reset_sv (void);
static void wlan_ap_position_publish (void);
static void wlan_ap_eval_virtual (void);
static double wlan_ap_signal_strength_calc (double prop_distance, WlanT_AP_Position_Info *ap_info_ptr);
static void wlan_find_new_ap_virtual (void);
//static double wlan_non_11b_plcp_overhead_compute (OpT_Packet_Size mpdu_length, double data_rate);
//static double wlan_plcp_overhead_ofdm_compute (OpT_Packet_Size mpdu_length, double data_rate);
//static Boolean wlan_dest_is_11g_enabled (int dest_mac_addr);
//static Boolean wlanc_11a_channel_is_regular (double frequency, int* channel_num_ptr);
//static Boolean wlan_poll_list_member_find (int dest_addr);
//static void wlan_pcf_frame_discard (void);
/* Callback functions */
#if defined (__cplusplus)
extern "C" {
#endif
static int wlan_hld_list_elem_add_comp (const void* list_elem_ptr1, const void* list_elem_ptr2);
static void* wlan_bss_info_get_key (void *value_ptr);
static int wlan_mapping_int_key_compare (void *key_a_ptr, void *key_b_ptr);
static void wlan_bss_info_free (void *value_ptr);
static void* wlan_sta_info_get_key (void *value_ptr);
static void wlan_sta_info_free (void *value_ptr);
static void* wlan_dup_info_get_key (void *value_ptr);
static void wlan_dup_info_free (void *value_ptr);
static void Update_Energy(void);
static void wsn_sv_init (void);
#if defined (__cplusplus)
} /* end of 'extern "C" {' */
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -