NetSim Source Code Help
Loading...
Searching...
No Matches
IEEE802_11_Radio.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
3 * TETCOS, Bangalore. India *
4 * *
5 * Tetcos owns the intellectual property rights in the Product and its content. *
6 * The copying, redistribution, reselling or publication of any or all of the *
7 * Product or its content without express prior written consent of Tetcos is *
8 * prohibited. Ownership and / or any other right relating to the software and all *
9 * intellectual property rights therein shall remain at all times with Tetcos. *
10 * *
11 * Author: Shashi Kant Suman *
12 * *
13 * ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "IEEE802_11_Phy.h"
16#include "../BatteryModel/BatteryModel.h"
17
19{
20 return phy->radio.radioState;
21}
22
25 PHY_TX_STATUS newState,
26 NETSIM_ID peerId,
27 UINT64 transmissionId)
28{
29 PHY_TX_STATUS oldState = phy->radio.radioState;
30
31 if (newState == RX_ON_BUSY && isMacTransmittingState(mac))
32 return false;
33
34 if (oldState == RX_ON_IDLE)
35 return true; // Radio is idle.
36
37 if (phy->radio.transmissionId == transmissionId)
38 return true;
39
40 if (phy->radio.peerId != peerId)
41 return false;
42
43 if (phy->radio.transmissionId != transmissionId)
44 return false;
45
46 if (oldState == RX_ON_BUSY && newState != RX_ON_IDLE)
47 return false;
48
49 if (oldState == TRX_ON_BUSY && newState != RX_ON_IDLE)
50 return false;
51
52 return true;
53}
54
56 NETSIM_ID in,
57 PHY_TX_STATUS state,
58 NETSIM_ID peerId,
59 UINT64 transmissionId)
60{
63 if (phy == NULL) { return false; }
64 if (phy->radio.radioState == RX_OFF)
65 return false;
66
67 if (!isChangeRadioIsPermitted(mac, phy, state, peerId, transmissionId))
68 return false;
69
70 ptrBATTERY battery = phy->battery;
71 bool isChange = true;
72 if (battery)
73 {
74 isChange = battery_set_mode(battery, state, pstruEventDetails->dEventTime);
75 }
76
77 if (isChange)
78 {
79 phy->radio.radioState = state;
80 phy->radio.peerId = peerId;
81 phy->radio.transmissionId = transmissionId;
82 }
83 else
84 phy->radio.radioState = RX_OFF;
86 return isChange;
87}
88
90{
91 return (phy->radio.radioState==RX_ON_IDLE);
92}
unsigned int NETSIM_ID
Definition: Animation.h:45
bool battery_set_mode(ptrBATTERY battery, int mode, double time)
Definition: BatteryModel.c:158
PIEEE802_11_MAC_VAR IEEE802_11_MAC(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
PIEEE802_11_PHY_VAR IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
bool isMacTransmittingState(PIEEE802_11_MAC_VAR mac)
PHY_TX_STATUS get_radio_state(PIEEE802_11_PHY_VAR phy)
static bool isChangeRadioIsPermitted(PIEEE802_11_MAC_VAR mac, PIEEE802_11_PHY_VAR phy, PHY_TX_STATUS newState, NETSIM_ID peerId, UINT64 transmissionId)
bool is_radio_idle(PIEEE802_11_PHY_VAR phy)
bool set_radio_state(NETSIM_ID d, NETSIM_ID in, PHY_TX_STATUS state, NETSIM_ID peerId, UINT64 transmissionId)
#define UINT64
Definition: Linux.h:37
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
enum enum_tx_status PHY_TX_STATUS
@ RX_OFF
Definition: Wireless.h:74
@ RX_ON_BUSY
Definition: Wireless.h:76
@ TRX_ON_BUSY
Definition: Wireless.h:77
@ RX_ON_IDLE
Definition: Wireless.h:75
IEEE802_11_RADIO radio
PHY_TX_STATUS radioState
unsigned long long int nEventId
Definition: Stack.h:745