NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
InfrastructureBSS.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.h"
16#include "IEEE802_11_Phy.h"
17
18int fn_NetSim_802_11_InfrastructureBSS_Init(NETSIM_ID nApID,NETSIM_ID nApInterfaceID)
19{
20 int nConnectedDeviceCount;
21 int nLoop;
22 NETSIM_ID nDevId, nIntefId, nProtocolId;
23 NETSIM_ID nLinkType;
24 PIEEE802_11_MAC_VAR pstruApMac;
25 PIEEE802_11_PHY_VAR pstruApPhy;
26 PIEEE802_11_MAC_VAR pstruNodeMac;
27 PIEEE802_11_PHY_VAR pstruNodePhy;
28
29 NetSim_LINKS* pstruLink;
30 pstruApMac = IEEE802_11_MAC(nApID,nApInterfaceID);
31 pstruApPhy = IEEE802_11_PHY(nApID,nApInterfaceID);
32 nLinkType = DEVICE_PHYLAYER(nApID,nApInterfaceID)->pstruNetSimLinks->nLinkType;
33 pstruLink = DEVICE_PHYLAYER(nApID,nApInterfaceID)->pstruNetSimLinks;
34
35 if(pstruLink->nLinkType != LinkType_P2MP)
36 {
37 fnNetSimError("AP %d interface %d is not connected with point-to-multipoint link",
38 fn_NetSim_Stack_GetConfigIdOfDeviceById(nApID),
39 DEVICE_INTERFACE_CONFIGID(nApID,nApInterfaceID));
40 return -1;
41 }
42 nConnectedDeviceCount = pstruLink->puniDevList.pstrup2MP.nConnectedDeviceCount;
43
44 //AP init
45 pstruApMac->BSSType=INFRASTRUCTURE;
46 pstruApMac->BSSId= DEVICE_HWADDRESS(nApID,nApInterfaceID);
47 pstruApMac->nBSSId = nApID;
48 pstruApMac->nAPInterfaceId= nApInterfaceID;
49 pstruApMac->devCountinBSS = nConnectedDeviceCount+1;
50 pstruApMac->devIdsinBSS=(NETSIM_ID*)calloc(nConnectedDeviceCount+1,sizeof* pstruApMac->devIdsinBSS);
51 pstruApMac->devIfinBSS=(NETSIM_ID*)calloc(nConnectedDeviceCount+1,sizeof* pstruApMac->devIfinBSS);
52 pstruApMac->devIdsinBSS[0]=nApID;
53 pstruApMac->devIfinBSS[0]=nApInterfaceID;
54 memcpy(pstruApMac->devIdsinBSS+1,pstruLink->puniDevList.pstrup2MP.anDevIds,
55 nConnectedDeviceCount*sizeof(NETSIM_ID));
56 memcpy(pstruApMac->devIfinBSS+1,pstruLink->puniDevList.pstrup2MP.anDevInterfaceIds,
57 nConnectedDeviceCount*sizeof(NETSIM_ID));
58
59 for(nLoop = 0; nLoop < nConnectedDeviceCount-1; nLoop++)
60 {
61 nDevId = pstruLink->puniDevList.pstrup2MP.anDevIds[nLoop];
62 nIntefId = pstruLink->puniDevList.pstrup2MP.anDevInterfaceIds[nLoop];
63
64 pstruNodeMac = IEEE802_11_MAC(nDevId,nIntefId);
65 pstruNodePhy = IEEE802_11_PHY(nDevId,nIntefId);
66 nProtocolId = DEVICE_MACLAYER(nDevId,nIntefId)->nMacProtocolId;
67
68 pstruNodeMac->devIdsinBSS=(NETSIM_ID*)calloc(nConnectedDeviceCount+1,sizeof* pstruNodeMac->devIdsinBSS);
69 pstruNodeMac->devIfinBSS=(NETSIM_ID*)calloc(nConnectedDeviceCount+1,sizeof* pstruNodeMac->devIfinBSS);
70 pstruNodeMac->devIdsinBSS[0]=nApID;
71 pstruNodeMac->devIfinBSS[0]=nApInterfaceID;
72 memcpy(pstruNodeMac->devIdsinBSS+1,pstruLink->puniDevList.pstrup2MP.anDevIds,
73 nConnectedDeviceCount*sizeof(NETSIM_ID));
74 memcpy(pstruNodeMac->devIfinBSS+1,pstruLink->puniDevList.pstrup2MP.anDevInterfaceIds,
75 nConnectedDeviceCount*sizeof(NETSIM_ID));
76
77 // calculate the distance between AP and the node
78 pstruNodeMac->dDistFromAp = fn_NetSim_Utilities_CalculateDistance(DEVICE_POSITION(nDevId),DEVICE_POSITION(nApID));
79
80 // Assign the link details to Phy variables of device
81 pstruNodePhy->dFrequency= pstruApPhy->dFrequency;
82
83 // Assign the AP details/ center device details to WLAN nodes
84 pstruNodeMac->BSSType=INFRASTRUCTURE;
85 pstruNodeMac->BSSId = DEVICE_HWADDRESS(nApID,nApInterfaceID);
86 pstruNodeMac->nBSSId = nApID;
87 pstruNodeMac->nAPInterfaceId= nApInterfaceID;
88 }// End of for loop
89 return 0;
90}
91
92void fn_NetSim_802_11_InfrastructureBSS_UpdateReceiver(NetSim_PACKET* packet)
93{
94 PIEEE802_11_MAC_VAR mac=IEEE802_11_CURR_MAC;
95
96 if(MAC_COMPARE(DEVICE_HWADDRESS(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId),mac->BSSId))
97 {
98 packet->nReceiverId = mac->nBSSId;
99 packet->nTransmitterId = pstruEventDetails->nDeviceId;
100 }
101 else
102 {
103 if (isMulticastPacket(packet) || isBroadcastPacket(packet))
104 packet->nReceiverId = 0;
105 else
106 packet->nReceiverId = get_first_dest_from_packet(packet);
107 packet->nTransmitterId = pstruEventDetails->nDeviceId;
108 }
109}
110
111bool isPacketforsameInfrastructureBSS(PIEEE802_11_MAC_VAR mac,NetSim_PACKET* packet)
112{
113 UINT i;
114 if(!MAC_COMPARE(DEVICE_HWADDRESS(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId),mac->BSSId))
115 {
116 for (i = 0; i < mac->devCountinBSS; i++)
117 {
118 if (isDestFoundinPacket(packet, mac->devIdsinBSS[i]))
119 return true;
120 }
121 return false;
122 }
123 return true;
124}