NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Component 6/ZigBee/802_15_4.h
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
15/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
16* *
17* THIS FILES CONTAINS IEEE 802.15.4 DATASTUCTURE WHICH HAS VARIABLES THAT ARE PROVIDED *
18* FOR USERS. BY MAKING USE OF THESE VARIABLES THE USER CAN CREATE THEIR OWN PROJECT. *
19* *
20* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21#ifndef _NETSIM_802_15_4_H_
22#define _NETSIM_802_15_4_H_
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27 //#define RADIO_MEASUREMENTS_LOG_802_15_4
28
29#pragma comment(lib,"PropagationModel.lib")
30#pragma comment(lib,"BatteryModel.lib")
31
32 //Default Battery config parameter
33#define BATTERY_RECHARGING_CURRENT_MA_DEFAULT 0
34#define BATTERY_VOLTAGE_V_DEFAULT 0
35#define BATTERY_INITIAL_ENERGY_DEFAULT 0
36#define BATTERY_TRANSMITTING_CURRENT_MA_DEFAULT 0
37#define BATTERY_RECEIVING_CURRENT_MA_DEFAULT 0
38#define BATTERY_IDLEMODE_CURRENT_MA_DEFAULT 0
39#define BATTERY_SLEEPMODE_CURRENT_MA_DEFAULT 0
40
41#define dUnitSymbolTime ((4*1000000.0)/250000) //Time taken to transfer 1 symbols. Each symbol is 4 bit long.
42#define WSN_PHY(devId) ((IEEE802_15_4_PHY_VAR*)DEVICE_PHYVAR(devId,1))
43#define WSN_MAC(devId) ((IEEE802_15_4_MAC_VAR*)DEVICE_MACVAR(devId,1))
44#define WSN_LINK_ID(nDevice_Id,nInterfaceId,nConnectedDevId,nConnectedDevPortId) fn_NetSim_Stack_GetConnectedDevice(nDevice_Id,nInterfaceId,nConnectedDevId,nConnectedDevPortId);
45#define WSN_MAC_HEADER(pPacket) ((IEEE802_15_4_HEADER*)PACKET_MACPROTOCOLDATA(pPacket))
46#define CHANNEL_IDLE 0
47#define CHANNEL_BUSY 1
48
49#define MAX_TTL 255
50#define SOURCEPORT 45
51#define DESTINATIONPORT 50
52
53 /* Typedef declaration of structures */
54
56 {
57 NETSIM_ID TX_ID;
58 NETSIM_ID RX_ID;
59 NETSIM_ID TX_IF_ID;
60 NETSIM_ID RX_IF_ID;
61 PPROPAGATION_INFO Propagation_Info;
62 _ptr_ele ele;
63 }propagation_info_for_list, * ptrpropagation_info_for_list;
64
65#define PPROPAGATION_INFO_ALLOC() (struct stru_propagation_info_for_list*)list_alloc(sizeof(struct stru_propagation_info_for_list),offsetof(struct stru_propagation_info_for_list,ele))
66#define PPROPAGATION_INFO_ADD(info,e) (LIST_ADD_LAST(&(info),(e)))
67#define PPROPAGATION_INFO_NEXT(entity) (LIST_NEXT(entity))
68#define PPROPAGATION_INFO_REMOVE(ls, mem) (LIST_FREE((void**)(ls),(mem)))
69
70 PPROPAGATION_INFO find_propagation_info(NETSIM_ID t, NETSIM_ID ti, NETSIM_ID r, NETSIM_ID ri);
71 void fn_NetSim_ieee802_15_4_PropagationInit();
72 int fn_NetSim_IEEE802_15_4_FreePropagationInfo();
73
74 typedef struct stru_IEEE802_15_4_Header IEEE802_15_4_HEADER;
75 typedef struct stru_IEEE802_15_4_MacVar IEEE802_15_4_MAC_VAR;
76 typedef struct stru_IEEE802_15_4_PhyVar IEEE802_15_4_PHY_VAR, *ptrIEEE802_15_4_PHY_VAR;
77 typedef struct stru_BeaconFrame BEACONFRAME;
78 typedef struct stru_SuperFrame SUPERFRAME;
79 typedef struct stru_Position_2D POS_2D;
80 typedef struct struChannel CHANNELS;
81 typedef struct stru_IEEE802_15_4_Metrics IEEE802_15_4_METRCIS;
82 typedef struct stru_Metrics METRICS;
83
84 /* Typedef declaration of enumerations */
85 typedef enum enum_CCAMODE CCAMODE;
86 typedef enum enum_IEEE_802_15_4_ControlPacket_Type IEEE802_15_4_PACKET_TYPE;
87 typedef enum enum_BeaconMode BEACON_MODE;
88 typedef enum enum_IEEE802_15_4_Subevent_Type SUB_EVENT;
89 typedef enum enum_MacState MAC_STATE;
90 /** Enumeration for Zigbee Control packet type */
91 enum enum_IEEE_802_15_4_ControlPacket_Type
92 {
93 BEACON_FRAME = MAC_PROTOCOL_IEEE802_15_4*100+1,
94 SLEEP_FRAME,
95 ACK_FRAME,
96 };
97 /** Enumeration for Zigbee Super frame statue */
98 enum enum_SuperFrame_Status
99 {
100 BEACONTRANSMISSIONMODE,
101 CAPMODE,
102 CFPMODE,
103 INACTIVEMODE,
104 };
105
106 /** Defining sub event type of IEEE 802.15.4*/
107 enum enum_IEEE802_15_4_Subevent_Type
108 {
109 SUPERFRAME_EVENT = MAC_PROTOCOL_IEEE802_15_4*100+1,
110 CARRIERSENSE_START,
111 CARRIERSENSE_END,
112 ACK_TIMEOUT,
113 BEACON_TRANSMISSION,
114 GOFORSLEEP,
115 BEACON_TRANSMISSION_END,
116 CAP_END,
117 CFP_END,
118 ACK_EVENT,
119 CSMA_DATATRANSFER,
120 CHANGE_RX,
121 CHANGE_RXANDSENDDATA,
122 UPDATE_MEDIUM,
123 };
124 /** Enumeration for Zigbee CCA Mode */
125 enum enum_CCAMODE
126 {
127 CARRIERSENSE,
128 ENERGYABOVETHERESHOLD,
129 CARRIERSENSE_AND_ENERGYABOVETHERESHOLD,
130 CARRIERSENSE_OR_ENERGYABOVETHERESHOLD,
131 };
132 /** Enumeration for Beacon mode (Enable or disable) */
133 enum enum_BeaconMode
134 {
135 BEACON_DISABLE,
136 BEACON_ENABLE,
137 };
138
139 /** Enumeration for MAc state */
140 enum enum_MacState
141 {
142 IDLE,
143 BACKOFF_MODE,
144 CCA_MODE,
145 TX_MODE,
146 RX_MODE,
147 OFF,
148 };
149
150 enum enum_IEEE802_15_4_isConfigured
151 {
152 DISABLE=0,
153 ENABLE=1,
154 };
155
156 NETSIM_ID nGlobalPANCoordinatorId;
157 /** Structure for IEEE 802.15.4 */
159 {
160 //int n_NC_ChannelId;
161 int nAckRequestFlag;
162 struct stru_BeaconFrame* pstruBeaconFrame;
163 };
164
165 /** Data structure for Beacon frame */
166 struct stru_BeaconFrame
167 {
168 int nBeaconId;
169 int nSuperFrameId;
170 int nBeaconTime;
171 double dPayload;
172 double dOverhead;
173 double dFrameSize;
174 };
175
176 /** Data structure for Super frame */
177 struct stru_SuperFrame
178 {
179 int nSuperFrameId;
180 int nTimeSlotCount;
181 int nSuperFrameStatus;
182 double dSuperFrameStartTime;
183 double dSuperFrameLength;
184 double dActivePeriodLength;
185 double dInactivePeriodLength;
186 double dTimeSlotLength;
187 double dCAPLength;
188 double dCFPLength;
189 double dBeaconLength;
190 BEACONFRAME* pstruBeacon;
191 struct stru_SuperFrame* pstruNextSuperFrame;
192 };
193 SUPERFRAME* pstruSuperFrame;
194
195 /// Stores the information of MAC layer.
197 {
198 ptrSOCKETINTERFACE sock;
199 MAC_STATE nNodeStatus;
200 int nAckRequestFlag;
201 BEACON_MODE nBeaconMode;
202 /// Range = 0 - 15 ; Default = 15
203 int nMacBeaconOrder;
204 /// Range = 0 - 15 ; Default = 15
206 /// 15.36 ms for 2.4 GHz
208 /// Enable or Disable
210 /// Range = 3 - 8 ; Default = 5
211 int nMacMaxBE;
212 /// Range = 0 - 5 ; Default = 4
214 /// Range = 0 - nMacMaxBE ; Default = 3
215 int nMacMinBE;
216 /// Range = 0 - 7 ; Default = 3
218 /// 20 Symbols fixed
220 int nMinCAPLength;
221
222 /// specific to simulation
224 NetSim_PACKET *pstruBuffer;
225 int nRetryCount;
226 /// To perform CCA in Slotted CSMACA
228 int nNoOfBackOff;
229 int nBeaconReceivedFlag;
230 int nLastBeaconId;
231 int nChannelNumber;
232 };
233
234 /// Stores information of physical layer.
236 {
237 double dAntennaHeight;
238 double dAntennaGain;
239 unsigned long int ulSeed1, ulSeed2;
240 /// -85 dbm default
241 double dReceiverSensivity;
242 /// -85 -10 = -95 dbm default
243 double dEDThreshold;
244 double dTransmitterPower_mw;
245 double dTransmitterRange_m;
246 /// Working Frequency Range. In MHz
247 double dFrequencyBand_MHz;
248 /// Data rate in kbps
249 double dDataRate_kbps;
250 /// Chip Rate in mcps
251 double dChipRate_mcps;
252 double dSymobleRate_kSymbolsPS;
253 char* pszModulationTechnique;
254 double dMinLIFSPeriod_Symbols;
255 double dMinSIFSPeriod_Symbols;
256
257 /// 20 symbols fixed
259 /// 12 symbols fixed
260 int aTurnaroundTime;
261 /// 3, 7, 10, 40
262 int phySHRDDuration;
263 /// 0.4, 1.6, 2, 8
264 double phySymbolsPerOctet;
265 /// CCA Mode
266 CCAMODE enumCCAMode;
267 PHY_TX_STATUS nRadioState;
268 double dTotalReceivedPower;
269 double macAckWaitDuration;
270 int nSensorFlag;
271 PHY_TX_STATUS nOldState;
272
273 double d0;
274 double pl_d0;
275
276 void* battery;
277 bool isDeviceOn;
278
279 ptrpropagation_info_for_list propagation_info_list;
280 };
281 /** Data structure for channel */
282 struct struChannel
283 {
284 /// Stores the channel number.
285 int nChannelNumber;
286 /// Stores the frequency.
287 double dFrequency;
288 /// Stores channel(IDLE,BUSY etc) status.
289 int nChannelStatus;
290 /// Device id to which it is allocated.
292 /// Type of the device to which it is allocated.
294 /// Count of the devices those have been assigned to the channel
296 int nNoOfPacket;
297 };
298 CHANNELS* pstruChannelList;
299
300 /// Structure for IEEE 802.15.4 Metrics
302 {
303 int nPacketTransmitted;
304 int nPacketReceived;
305 int nAckTransmitted;
306 int nAckReceived;
307 int nCCAAttempt;
308 int nSuccessfulCCAAttempt;
309 int nFailedCCA;
310 double dTotalbackofftime;
311 double dAveragebackofftime;
312 int nNumberofBackoffCall;
313 int nBeaconTransmitted;
314 int nBeaconReceived;
315 int nBeaconForwarded;
316 double dBeaconTime;
317 double dCAPTime;
318 double dCFPTime;
319 };
320
321 /// Data structure for IEEE 802.15.4 metrics which consists of sensor metrics and power model metrics also.
322 struct stru_Metrics
323 {
324 IEEE802_15_4_METRCIS *pstruIEEE802_15_4_Metrics;
325 };
326 METRICS** pstruMetrics;
327
328 //Propagation macro
329#define GET_RX_POWER_dbm(tx, rx, time) (_propagation_get_received_power_dbm(find_propagation_info(tx, 1, rx, 1), time))
330#define GET_RX_POWER_mw(tx,rx,time) (DBM_TO_MW(GET_RX_POWER_dbm(tx,rx,time)))
331
332
333#define ZIGBEE_UNSLOTTED() fn_NetSim_Zigbee_UnslottedCSMACA()
334#define ZIGBEE_SLOTTED() fn_NetSim_Zigbee_SlottedCSMACA()
335#define ZIGBEE_CHANGERADIOSTATE(nDeviceId,nOldState,nNewState) fn_NetSim_Zigbee_ChangeRadioState(nDeviceId,nOldState,nNewState)
336#define ZIGBEE_RECEIVEDPOWER(pstruPhyVar,dDistance,dReceivedPower,nLinkID) fn_NetSim_Zigbee_CalculateReceivedPower(pstruPhyVar,dDistance,dReceivedPower,nLinkID)
337#define ZIGBEE_LOCATEBACKOFFBOUNDARY(dTime,dBoundaryTime,aUnitBackoffPeriod,pstruSuperFrame) fn_NetSim_Zigbee_LocateBackoffBoundary(dTime,dBoundaryTime,aUnitBackoffPeriod,pstruSuperFrame)
338#define ZIGBEE_SUPERFRAME() fn_NetSim_Zigbee_SuperFrameInitialization(&pstruSuperFrame,nGlobalPANCoordinatorId,pstruMetrics)
339#define ZIGBEE_BACKOFF(nBackoffExponent,dBackoffTime,nUnitBacoffPeriod) fn_NetSim_Zigbee_BackoffTimeCalculation(nBackoffExponent,dBackoffTime,nUnitBacoffPeriod,pstruMetrics)
340#define ZIGBEE_CHANNELFORMATION() fn_NetSim_Zigbee_ChannelFormation(&pstruChannelList)
341#define ZIGBEE_CCA(dInterferencePower,nCCA_Mode,dReceiverSensivity,dEDThreshold) fn_NetSim_Zigbee_CCA(dInterferencePower,nCCA_Mode,dReceiverSensivity,dEDThreshold,pstruMetrics)
342#define ZIGBEE_SINR(SNR,dTotalReceivedPower,dReceivedPower) fn_NetSim_Zigbee_CalculateSINR(SNR,dTotalReceivedPower,dReceivedPower)
343
344 /* Zigbee Function */
345 int fn_NetSim_Configure_WSN_POWER(void*, int);
346
347
348 /****************** NetWorkStack DLL functions declarations *****************************************/
349 int fn_NetSim_Zigbee_Configure_F(void** var);
350 int fn_NetSim_Zigbee_Init_F();
351 /** Function to run Zigbee protocol */
352 _declspec (dllexport) int fn_NetSim_Zigbee_Run();
353
354 /// Function to free the Zigbee protocol variable and Unload the primitives
355 _declspec(dllexport) int fn_NetSim_Zigbee_Finish();
356 int fn_NetSim_Zigbee_Finish_F();
357 /// Return the sub event name with respect to the sub event number for writing event trace
358 _declspec (dllexport) char *fn_NetSim_Zigbee_Trace(int nSubEvent);
359 char *fn_NetSim_Zigbee_Trace_F(int nSubEvent);
360 /// Function to free the allocated memory for the Zigbee packet
361 _declspec(dllexport) int fn_NetSim_Zigbee_FreePacket(NetSim_PACKET* );
362 int fn_NetSim_zigbee_FreePacket_F(NetSim_PACKET* );
363 /// Function to copy the Zigbee packet from source to destination
364 _declspec(dllexport) int fn_NetSim_Zigbee_CopyPacket(NetSim_PACKET* ,NetSim_PACKET* );
365 int fn_NetSim_Zigbee_CopyPacket_F(NetSim_PACKET* ,NetSim_PACKET* );
366 /// Function to write Zigbee Metrics into Metrics.txt
367 _declspec(dllexport) int fn_NetSim_Zigbee_Metrics(PMETRICSWRITER metricsWriter);
368 int fn_NetSim_Zigbee_Metrics_F(PMETRICSWRITER metricsWriter);
369
370 //Backoff seed
371
372 unsigned long ulBackoffSeed1;
373 unsigned long ulBackoffSeed2;
374
375 int fn_NetSim_Zigbee_UnslottedCSMACA();
376 int fn_NetSim_Zigbee_SlottedCSMACA();
377 bool fn_NetSim_Zigbee_ChangeRadioState(NETSIM_ID nDeviceId, PHY_TX_STATUS nOldState, PHY_TX_STATUS nNewState);
378 double fn_NetSim_Zigbee_CalculateBER(double sinr);
379 int fn_NetSim_Zigbee_LocateBackoffBoundary(double dTime, double* dBoundaryTime, int aUnitBackoffPeriod, SUPERFRAME* pstruSuperFrame);
380 int fn_NetSim_Zigbee_SuperFrameInitialization(SUPERFRAME** ppstruSuperFrame,NETSIM_ID nGlobalPANCoordinatorId,METRICS** pstruMetrics);
381 int fn_NetSim_Zigbee_BackoffTimeCalculation(int nBackoffExponent,double* dBackoffTime,int nUnitBacoffPeriod,METRICS** pstruMetrics);
382 int fn_NetSim_Zigbee_CCA(double dInterferencePower, CCAMODE nCCA_Mode, double dReceiverSensivity, double dEDThreshold,METRICS** pstruMetrics);
383 int fn_NetSim_Zigbee_CalculateSINR(double *SNR, double dTotalReceivedPower,double dReceivedPower);
384 int fn_NetSim_Zigbee_ChannelFormation(CHANNELS** pstruChannelList);
385
386 // Radio Measurements Logs
387 void RadioMeasurements_802_15_4_Finish();
388 void RadioMeasurements_802_15_4_Init();
389 void RadioMeasurements_802_15_4_Log(NetSim_PACKET* packet, NETSIM_ID txid, NETSIM_ID txif, NETSIM_ID rxid, NETSIM_ID rxif);
390
391 bool get_protocol_log_status(char* logname);
392
393#ifdef __cplusplus
394}
395#endif
396#endif
Stores the information of MAC layer.
int nBackoffExponent
specific to simulation
int nContentionWindow
To perform CCA in Slotted CSMACA.
int nMacSuperframeOrder
Range = 0 - 15 ; Default = 15.
int nBatteryLifeExtension
Enable or Disable.
int nMacMaxBE
Range = 3 - 8 ; Default = 5.
int nMacMaxFrameRetries
Range = 0 - 7 ; Default = 3.
int nMacMaxCSMABackoff
Range = 0 - 5 ; Default = 4.
double dBaseSuperFrameDuration
15.36 ms for 2.4 GHz
int nMacBeaconOrder
Range = 0 - 15 ; Default = 15.
int nMacMinBE
Range = 0 - nMacMaxBE ; Default = 3.
Structure for IEEE 802.15.4 Metrics.
Stores information of physical layer.
double dFrequencyBand_MHz
Working Frequency Range. In MHz.
double dChipRate_mcps
Chip Rate in mcps.
double dEDThreshold
-85 -10 = -95 dbm default
double dDataRate_kbps
Data rate in kbps.
Data structure for IEEE 802.15.4 metrics which consists of sensor metrics and power model metrics als...
int nAllocatedDeviceType
Type of the device to which it is allocated.
int nAssociatedDeviceCount
Count of the devices those have been assigned to the channel.
double dFrequency
Stores the frequency.
int nChannelNumber
Stores the channel number.
int nAllocatedDeviceId
Device id to which it is allocated.
int nChannelStatus
Stores channel(IDLE,BUSY etc) status.