NetSim Source Code Help
Loading...
Searching...
No Matches
InfrastructureBSS.c
Go to the documentation of this file.
1/************************************************************************************
2 * Copyright (C) 2020 *
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
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",
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
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
93{
95
97 {
98 packet->nReceiverId = mac->nBSSId;
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);
108 }
109}
110
112{
113 UINT i;
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}
unsigned int NETSIM_ID
Definition: Animation.h:45
PIEEE802_11_MAC_VAR IEEE802_11_MAC(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
PIEEE802_11_PHY_VAR IEEE802_11_PHY(NETSIM_ID ndeviceId, NETSIM_ID nInterfaceId)
@ INFRASTRUCTURE
Definition: IEEE802_11.h:57
#define IEEE802_11_CURR_MAC
Definition: IEEE802_11.h:285
bool isPacketforsameInfrastructureBSS(PIEEE802_11_MAC_VAR mac, NetSim_PACKET *packet)
int fn_NetSim_802_11_InfrastructureBSS_Init(NETSIM_ID nApID, NETSIM_ID nApInterfaceID)
void fn_NetSim_802_11_InfrastructureBSS_UpdateReceiver(NetSim_PACKET *packet)
#define UINT
Definition: Linux.h:38
#define fnNetSimError(x,...)
Definition: Linux.h:56
#define calloc(c, s)
Definition: Memory.h:29
bool isMulticastPacket(NetSim_PACKET *packet)
NETSIM_ID get_first_dest_from_packet(NetSim_PACKET *packet)
bool isBroadcastPacket(NetSim_PACKET *packet)
bool isDestFoundinPacket(NetSim_PACKET *packet, NETSIM_ID dest)
NETSIM_ID fn_NetSim_Stack_GetConfigIdOfDeviceById(NETSIM_ID nDeviceId)
#define DEVICE_HWADDRESS(DeviceId, InterfaceId)
Definition: Stack.h:799
#define DEVICE_MACLAYER(DeviceId, InterfaceId)
Definition: Stack.h:786
#define DEVICE_INTERFACE_CONFIGID(DeviceId, InterfaceId)
Definition: Stack.h:781
int MAC_COMPARE(PNETSIM_MACADDRESS mac1, PNETSIM_MACADDRESS mac2)
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define DEVICE_PHYLAYER(DeviceId, InterfaceId)
Definition: Stack.h:788
@ LinkType_P2MP
Definition: Stack.h:316
#define DEVICE_POSITION(DeviceId)
Definition: Stack.h:790
double fn_NetSim_Utilities_CalculateDistance(NetSim_COORDINATES *coordinate1, NetSim_COORDINATES *coordinates2)
NETSIM_ID * devIdsinBSS
Definition: IEEE802_11.h:265
PNETSIM_MACADDRESS BSSId
Definition: IEEE802_11.h:261
NETSIM_ID nAPInterfaceId
Definition: IEEE802_11.h:263
IEEE802_11_BSS_TYPE BSSType
Definition: IEEE802_11.h:226
NETSIM_ID * devIfinBSS
Definition: IEEE802_11.h:266
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_ID nInterfaceId
Definition: Stack.h:751
NETSIM_ID nReceiverId
Definition: Packet.h:266
NETSIM_ID nTransmitterId
Definition: Packet.h:265