NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
IEEE802_11_Radio.c
1/************************************************************************************
2 * Copyright (C) 2023 *
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
18PHY_TX_STATUS get_radio_state(PIEEE802_11_PHY_VAR phy)
19{
20 return phy->radio.radioState;
21}
22
23static bool isChangeRadioIsPermitted(PIEEE802_11_MAC_VAR mac,
24 PIEEE802_11_PHY_VAR phy,
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
55bool set_radio_state(NETSIM_ID d,
56 NETSIM_ID in,
57 PHY_TX_STATUS state,
58 NETSIM_ID peerId,
59 UINT64 transmissionId)
60{
61 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(d, in);
62 PIEEE802_11_MAC_VAR mac = IEEE802_11_MAC(d, in);
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;
85 phy->radio.eventId = pstruEventDetails->nEventId;
86 return isChange;
87}
88
89bool is_radio_idle(PIEEE802_11_PHY_VAR phy)
90{
91 return (phy->radio.radioState==RX_ON_IDLE);
92}