NetSim Source Code Help
Loading...
Searching...
No Matches
IEEE1609_interface.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2021 *
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 "IEEE1609_Interface.h"
28
30 NETSIM_ID nInterfaceId,
32{
33 PIEEE1609_MAC_VAR mac = GET_IEEE1609_MAC_VAR(nDeviceId, nInterfaceId);
34 switch (type)
35 {
37 return &(mac->buffer[0]); //CCH
38 break;
40 return &(mac->buffer[1]); //SCH
41 break;
43 return NULL;
44 break;
45 default:
46 fnNetSimError("Unknown channel type %d\n", type);
47 break;
48 }
49 return NULL;
50}
51
53{
54 if (ndeviceId == 0)
55 {
56 fnNetSimError("Device id is passed 0 in function %s", __FUNCTION__);
57 return NULL;
58 }
59 if (nInterfaceId == 0)
60 {
61 fnNetSimError("Interface id is passed 0 in function %s", __FUNCTION__);
62 return NULL;
63 }
64 switch (DEVICE_MACLAYER(ndeviceId, nInterfaceId)->nMacProtocolId)
65 {
67 return ((PIEEE1609_MAC_VAR)DEVICE_MACVAR(ndeviceId, nInterfaceId))->secondary_protocol_var;
68 break;
70 return ((PIEEE802_11_MAC_VAR)DEVICE_MACVAR(ndeviceId, nInterfaceId));
71 break;
72 default:
73 fnNetSimError("Unknown mac protocol in %s\n", __FUNCTION__);
74 return NULL;
75 break;
76 }
77}
78
80{
81 return GET_IEEE1609_MAC_VAR(nDeviceId, nInterfaceId)->CHANNEL_INFO.channel_type;
82}
83
85{
86 switch (packet->nPacketType)
87 {
88 case PacketType_BSM:
90 default:
92 }
93}
94
96{
97 if (ndeviceId == 0)
98 {
99 fnNetSimError("Device id is passed 0 in function %s", __FUNCTION__);
100 return NULL;
101 }
102 if (nInterfaceId == 0)
103 {
104 fnNetSimError("Interface id is passed 0 in function %s", __FUNCTION__);
105 return NULL;
106 }
107 switch (DEVICE_MACLAYER(ndeviceId, nInterfaceId)->nMacProtocolId)
108 {
110 return ((PIEEE1609_PHY_VAR)DEVICE_PHYVAR(ndeviceId, nInterfaceId))->secondary_protocol_var;;
111 break;
113 return ((PIEEE802_11_PHY_VAR)DEVICE_PHYVAR(ndeviceId, nInterfaceId));
114 break;
115 default:
116 fnNetSimError("Unknown phy protocol in %s\n", __FUNCTION__);
117 return NULL;
118 break;
119 }
120}
121
123{
124 switch (DEVICE_MACLAYER(ndeviceId, nInterfaceId)->nMacProtocolId)
125 {
127 ((PIEEE1609_MAC_VAR)DEVICE_MACVAR(ndeviceId, nInterfaceId))->secondary_protocol_var = mac;
128 break;
130 DEVICE_MACVAR(ndeviceId, nInterfaceId) = mac;
131 break;
132 default:
133 fnNetSimError("Unknown mac protocol in %s\n", __FUNCTION__);
134 break;
135 }
136}
137
139{
140 switch (DEVICE_MACLAYER(ndeviceId, nInterfaceId)->nMacProtocolId)
141 {
143 ((PIEEE1609_PHY_VAR)DEVICE_PHYVAR(ndeviceId, nInterfaceId))->secondary_protocol_var = phy;
144 break;
146 DEVICE_PHYVAR(ndeviceId, nInterfaceId) = phy;
147 break;
148 default:
149 fnNetSimError("Unknown mac protocol in %s\n", __FUNCTION__);
150 break;
151 }
152}
153
154bool isIEEE802_11_Configure(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
155{
156 if (!DEVICE_MACLAYER(ndeviceId, nInterfaceId))
157 return false;
158
159 switch (DEVICE_MACLAYER(ndeviceId, nInterfaceId)->nMacProtocolId)
160 {
162 return ((PIEEE1609_MAC_VAR)DEVICE_MACVAR(ndeviceId, nInterfaceId))->secondary_protocol == MAC_PROTOCOL_IEEE802_11;
163 break;
165 return true;
166 break;
167 default:
168 return false;
169 break;
170 }
171}
172
173static NETSIM_ID add_to_IEEE1609_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET* packet)
174{
176 PIEEE1609_BUFFER buf = get_ieee1609_buffer(nDeviceId,nInterfaceId,type);
177 if (buf->head)
178 {
179 buf->tail->pstruNextPacket = packet;
180 buf->tail = packet;
181 }
182 else
183 {
184 buf->head = packet;
185 buf->tail = packet;
186 }
187 return nInterfaceId;
188}
189
190NETSIM_ID add_to_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET* packet)
191{
192 switch (DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId)
193 {
195 return add_to_IEEE1609_queue(nDeviceId, nInterfaceId, packet);
196 break;
198 return fn_NetSim_IEEE802_11e_AddtoQueue(nDeviceId, nInterfaceId, packet);
199 break;
200 default:
201 fnNetSimError("Unknown Mac protocol %d in %s.",
202 DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId, __FUNCTION__);
203 break;
204 }
205 return 0;
206}
207
208static bool isPacketinIEEE1609Queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, IEEE1609_CHANNEL_TYPE type)
209{
210 PIEEE1609_BUFFER buf = get_ieee1609_buffer(nDeviceId, nInterfaceId, type);
211
212 if (!buf) return false;
213 return buf->head ? true : false;
214}
215
216bool isPacketInQueue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
217{
218 switch (DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId)
219 {
221 return isPacketinIEEE1609Queue(nDeviceId, nInterfaceId, get_curr_channel_type(nDeviceId, nInterfaceId));
222 break;
224 return fn_NetSim_IEEE802_11e_IsPacketInQueue(nDeviceId, nInterfaceId);
225 break;
226 default:
227 fnNetSimError("Unknown Mac protocol %d in %s.",
228 DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId, __FUNCTION__);
229 break;
230 }
231 return false;
232}
233
235 UINT nPacketRequire,
236 UINT* nPacketCount,
238{
239 NetSim_PACKET* p = NULL, *t = NULL;
240 UINT c=0;
241 PIEEE1609_BUFFER buf = get_ieee1609_buffer(nDeviceId, nInterfaceId, type);
242
243 if (!buf)
244 {
245 *nPacketCount = 0;
246 return NULL; // BUFFER is not initialized for this channel type
247 }
248
249 while (buf->head && c<nPacketRequire)
250 {
251 if (p)
252 {
253 t->pstruNextPacket = buf->head;
254 t = t->pstruNextPacket;
255 }
256 else
257 {
258 p = buf->head;
259 t = p;
260 }
261 buf->head = buf->head->pstruNextPacket;
262 t->pstruNextPacket = NULL;
263 if (!buf->head)
264 buf->tail = NULL;
265 c++;
266 }
267 *nPacketCount = c;
268 return p;
269}
270
272 NETSIM_ID nInterfaceId,
273 UINT nPacketRequire,
274 UINT* nPacketCount)
275{
276 switch (DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId)
277 {
279 {
280
281 return get_from_IEEE1609_queue(nDeviceId,
282 nInterfaceId,
283 nPacketRequire,
284 nPacketCount,
285 get_curr_channel_type(nDeviceId,nInterfaceId));
286 }
287 break;
289 return fn_NetSim_IEEE802_11e_GetPacketFromQueue(nDeviceId, nInterfaceId,
290 nPacketRequire,
291 nPacketCount);
292 break;
293 default:
294 fnNetSimError("Unknown Mac protocol %d in %s.",
295 DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId, __FUNCTION__);
296 return NULL;
297 break;
298 }
299}
300
301static void readd_to_IEEE1609_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET* packet)
302{
304 PIEEE1609_BUFFER buf = get_ieee1609_buffer(nDeviceId, nInterfaceId, type);
305 if (buf->head)
306 {
307 packet->pstruNextPacket = buf->head;
308 buf->head = packet;
309 }
310 else
311 {
312 buf->head = packet;
313 buf->tail = packet;
314 }
315}
316
317void readd_to_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET* packet)
318{
319 switch (DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId)
320 {
322 readd_to_IEEE1609_queue(nDeviceId, nInterfaceId, packet);
323 break;
325 fnNetSimError("Mustnot call this function %s for protocol %d.", __FUNCTION__,
327 assert(false);
328 break;
329 default:
330 fnNetSimError("Unknown Mac protocol %d in %s.",
331 DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId, __FUNCTION__);
332 break;
333 }
334}
335
336static bool is_time_in_same_channel(double time, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
337{
338 PIEEE1609_MAC_VAR mac = GET_IEEE1609_MAC_VAR(nDeviceId, nInterfaceId);
339 if (mac->CHANNEL_INFO.dEndTime >= time)
340 return true;
341 else
342 return false;
343}
344
345static void revert_packet(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
346{
347 PIEEE802_11_MAC_VAR mac = IEEE802_11_MAC(nDeviceId, nInterfaceId);
348 if (!mac->currentProcessingPacket)
349 return; //nothing to revert
350
352 {
353 readd_to_IEEE1609_queue(nDeviceId, nInterfaceId,
354 mac->waitingforCTS);
355 mac->waitingforCTS = NULL;
357 mac->currentProcessingPacket = NULL;
358 }
359 else
360 {
361 readd_to_IEEE1609_queue(nDeviceId, nInterfaceId,
363 mac->currentProcessingPacket = NULL;
364 }
365}
366
367static void make_idle(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
368{
369 PIEEE802_11_MAC_VAR mac = IEEE802_11_MAC(nDeviceId, nInterfaceId);
370 PIEEE802_11_PHY_VAR phy = IEEE802_11_PHY(nDeviceId, nInterfaceId);
371
375}
376
377bool validate_processing_time(double time, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
378{
379 switch (DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId)
380 {
382 {
383 if (is_time_in_same_channel(time, nDeviceId, nInterfaceId))
384 return true;
385 revert_packet(nDeviceId,nInterfaceId);
386 make_idle(nDeviceId, nInterfaceId);
387 return false;
388 }
389 break;
391 return true;
392 break;
393 default:
394 fnNetSimError("Unknown MAC protocol %d in %s\n",
395 DEVICE_MACLAYER(nDeviceId, nInterfaceId)->nMacProtocolId,
396 __FUNCTION__);
397 return false;
398 break;
399 }
400}
unsigned int NETSIM_ID
Definition: Animation.h:45
struct stru_IEEE1609_Phy_Var * PIEEE1609_PHY_VAR
@ IEEE1609_ChannelType_GUARD
@ IEEE1609_ChannelType_CCH
@ IEEE1609_ChannelType_SCH
struct stru_IEEE1609_Mac_Var * PIEEE1609_MAC_VAR
#define GET_IEEE1609_MAC_VAR(nDeviceId, nInterfaceId)
enum enum_IEEE1609_ChannelType IEEE1609_CHANNEL_TYPE
PIEEE802_11_MAC_VAR IEEE802_11_MAC(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
void SET_IEEE802_11_MAC(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId, PIEEE802_11_MAC_VAR mac)
static void make_idle(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
bool isIEEE802_11_Configure(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
PIEEE802_11_PHY_VAR IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
bool validate_processing_time(double time, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
NetSim_PACKET * get_from_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, UINT nPacketRequire, UINT *nPacketCount)
bool isPacketInQueue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
static IEEE1609_CHANNEL_TYPE get_curr_channel_type(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
static bool is_time_in_same_channel(double time, NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
static bool isPacketinIEEE1609Queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, IEEE1609_CHANNEL_TYPE type)
static NETSIM_ID add_to_IEEE1609_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET *packet)
void readd_to_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET *packet)
void SET_IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId, PIEEE802_11_PHY_VAR phy)
static NetSim_PACKET * get_from_IEEE1609_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, UINT nPacketRequire, UINT *nPacketCount, IEEE1609_CHANNEL_TYPE type)
static PIEEE1609_BUFFER get_ieee1609_buffer(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, IEEE1609_CHANNEL_TYPE type)
static void revert_packet(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
NETSIM_ID add_to_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET *packet)
static void readd_to_IEEE1609_queue(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId, NetSim_PACKET *packet)
static IEEE1609_CHANNEL_TYPE get_channel_type_of_packet(NetSim_PACKET *packet)
@ IEEE802_11_MACSTATE_MAC_IDLE
Definition: IEEE802_11.h:154
void IEEE802_11_Change_Mac_State(PIEEE802_11_MAC_VAR mac, IEEE802_11_MAC_STATE state)
bool isIEEE802_11_CtrlPacket(NetSim_PACKET *packet)
NetSim_PACKET * fn_NetSim_IEEE802_11e_GetPacketFromQueue(NETSIM_ID d, NETSIM_ID in, UINT nPacketRequire, UINT *nPacketCount)
NETSIM_ID fn_NetSim_IEEE802_11e_AddtoQueue(NETSIM_ID d, NETSIM_ID in, NetSim_PACKET *packet)
bool fn_NetSim_IEEE802_11e_IsPacketInQueue(NETSIM_ID d, NETSIM_ID in)
#define c
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
@ PacketType_BSM
Definition: Packet.h:64
#define DEVICE_PHYVAR(DeviceId, InterfaceId)
Definition: Stack.h:797
#define DEVICE_MACLAYER(DeviceId, InterfaceId)
Definition: Stack.h:786
@ MAC_PROTOCOL_IEEE802_11
Definition: Stack.h:208
@ MAC_PROTOCOL_IEEE1609
Definition: Stack.h:230
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
@ RX_ON_IDLE
Definition: Wireless.h:75
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
NetSim_PACKET * waitingforCTS
Definition: IEEE802_11.h:257
NetSim_PACKET * currentProcessingPacket
Definition: IEEE802_11.h:256
IEEE802_11_RADIO radio
PHY_TX_STATUS radioState
struct stru_IEEE1609_Mac_Var::stru_Channel_Info CHANNEL_INFO
IEEE1609_BUFFER buffer[2]
unsigned long long int nEventId
Definition: Stack.h:745
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
PACKET_TYPE nPacketType
Definition: Packet.h:257