NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
IEEE802_11.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* This source code is licensed per the NetSim license agreement. *
12* *
13* No portion of this source code may be used as the basis for a derivative work, *
14* or used, for any purpose other than its intended use per the NetSim license *
15* agreement. *
16* *
17* This source code and the algorithms contained within it are confidential trade *
18* secrets of TETCOS and may not be used as the basis for any other software, *
19* hardware, product or service. *
20* *
21* Author: Shashi Kant Suman *
22* *
23* ----------------------------------------------------------------------------------*/
24#include "main.h"
25#include "IEEE802_11.h"
26#include "IEEE802_11_Phy.h"
27#include "NetSim_utility.h"
28#include "AdvancedPlots.h"
29#pragma comment(lib,"AdvancedPlots.lib")
30
31//Function prototype
32int fn_NetSim_IEEE802_11_Configure_F(void** var);
33int fn_NetSim_IEEE802_11_Init_F(struct stru_NetSim_Network *NETWORK_Formal,
34 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
35 char *pszAppPath_Formal,
36 char *pszWritePath_Formal,
37 int nVersion_Type);
38int fn_NetSim_IEEE802_11_Metrics_F(PMETRICSWRITER metricsWriter);
39void print_minstrel_table(PMETRICSWRITER metricsWriter);
40
41_declspec(dllexport) int fn_NetSim_IEEE802_11_Configure(void** var)
42{
43 return fn_NetSim_IEEE802_11_Configure_F(var);
44}
45
46_declspec(dllexport) int fn_NetSim_IEEE802_11_Init(struct stru_NetSim_Network *NETWORK_Formal,
47 NetSim_EVENTDETAILS *pstruEventDetails_Formal,
48 char *pszAppPath_Formal,
49 char *pszWritePath_Formal,
50 int nVersion_Type)
51{
52 init_linkpacketlog();
53 fnNetSim_buffer_log_init();
54 IEEE_802_11RadioMeasurements_Init();
55 return fn_NetSim_IEEE802_11_Init_F(NETWORK_Formal,
56 pstruEventDetails_Formal,pszAppPath_Formal,
57 pszWritePath_Formal,
58 nVersion_Type);
59}
60
61_declspec(dllexport) int fn_NetSim_IEEE802_11_Run()
62{
63 switch(pstruEventDetails->nEventType)
64 {
65 case MAC_OUT_EVENT:
66 fn_NetSim_IEEE802_11_MacOut();
67 break;
68 case MAC_IN_EVENT:
69 fn_NetSim_IEEE802_11_MacIn();
70 break;
71 case PHYSICAL_OUT_EVENT:
72 fn_NetSim_IEEE802_11_PhyOut();
73 break;
74 case PHYSICAL_IN_EVENT:
75 fn_NetSim_IEEE802_11_PhyIn();
76 break;
77 case TIMER_EVENT:
78 fn_NetSim_IEEE802_11_Timer();
79 break;
80 default:
81 fnNetSimError("Unknown event type %d for IEEE802.11 protocol",pstruEventDetails->nEventType);
82 break;
83 }
84 return 0;
85}
86
87/**
88This function is called by NetworkStack.dll, while writing the event trace
89to get the sub event as a string.
90*/
91_declspec(dllexport) char* fn_NetSim_IEEE802_11_Trace(int nSubEvent)
92{
93 return GetStringIEEE802_11_Subevent(nSubEvent);
94}
95
96/**
97This function is called by NetworkStack.dll, to free the WLAN protocol
98pstruMacData->Packet_MACProtocol.
99*/
100_declspec(dllexport) int fn_NetSim_IEEE802_11_FreePacket(NetSim_PACKET* pstruPacket)
101{
102 ieee802_11_free_hdr(pstruPacket);
103 free_ieee802_11_phy_header(pstruPacket);
104 return 0;
105}
106
107/**
108This function is called by NetworkStack.dll, to copy the WLAN protocol
109pstruMacData->Packet_MACProtocol from source packet to destination.
110*/
111_declspec(dllexport) int fn_NetSim_IEEE802_11_CopyPacket(NetSim_PACKET* pstruDestPacket,NetSim_PACKET* pstruSrcPacket)
112{
113 ieee802_11_hdr_copy(pstruDestPacket,pstruSrcPacket);
114 copy_ieee802_11_phy_header(pstruDestPacket, pstruSrcPacket);
115 return 0;
116}
117
118/**
119This function call WLAN Metrics function in lib file to write the Metrics in Metrics.txt
120*/
121_declspec(dllexport) int fn_NetSim_IEEE802_11_Metrics(PMETRICSWRITER metricsWriter)
122{
123 fn_NetSim_IEEE802_11_Metrics_F(metricsWriter);
124 print_minstrel_table(metricsWriter);
125 return 0;
126}
127
128/**
129This function is to configure the WLAN protocol packet trace parameter.
130This function return a string which has the parameters separated by comma.
131*/
132_declspec(dllexport) char* fn_NetSim_IEEE802_11_ConfigPacketTrace(const void* xmlNetSimNode)
133{
134 xmlNetSimNode;
135 return "";
136}
137
138/**
139This function is called while writing the Packet trace for WLAN protocol.
140This function is called for every packet while writing the packet trace.
141*/
142_declspec(dllexport) int fn_NetSim_IEEE802_11_WritePacketTrace(NetSim_PACKET* pstruPacket, char** ppszTrace)
143{
144 pstruPacket;
145 ppszTrace;
146 return 1;
147}
148
149/**
150This function is called by NetworkStack.dll, once simulation end to free the
151allocated memory for the network.
152*/
153_declspec(dllexport) int fn_NetSim_IEEE802_11_Finish()
154{
155 fn_NetSim_buffer_log_close();
156 LinkPacketLog_close();
157 IEEE_802_11RadioMeasurements_Finish();
158 return fn_NetSim_IEEE802_11_Finish_F();
159}
160
161void fn_NetSim_IEEE802_11_Timer()
162{
163 switch(pstruEventDetails->nSubEventType)
164 {
165 case ACK_TIMEOUT:
166 fn_NetSim_IEEE802_11_CSMA_AckTimeOut();
167 break;
168 case CTS_TIMEOUT:
169 fn_NetSim_IEEE802_11_RTS_CTS_CTSTimeOut();
170 break;
171 default:
172 fnNetSimError("Unknown Timer event-%d subevent for IEEE802.11 protocol in %s\n",
173 pstruEventDetails->nSubEventType,
174 __FUNCTION__);
175 }
176}
177
178bool isIEEE802_11_log()
179{
180 if (get_protocol_log_status("IEEE802_11_LOG"))
181 return true;
182 else
183 return false;
184}
185
186bool isieee802_11_Backoff_log()
187{
188 if (get_protocol_log_status("IEEE802_11_BACKOFF_LOG"))
189 return true;
190 else
191 return false;
192}
193
194bool get_protocol_log_status(char* logname)
195{
196 FILE* fp;
197 char str[BUFSIZ];
198 char data[BUFSIZ];
199
200 sprintf(str, "%s/%s", pszIOPath, "ProtocolLogsConfig.txt");
201 fp = fopen(str, "r");
202 if (!fp)
203 return false;
204
205 sprintf(str, "%s=true", logname);
206
207 while (fgets(data, BUFSIZ, fp))
208 {
209 lskip(data);
210 if (!_strnicmp(data, str, strlen(str)))
211 {
212 fclose(fp);
213 return true;
214 }
215 }
216 fclose(fp);
217
218 return false;
219}
220