15#include "IEEE802_11.h"
16#include "IEEE802_11_Phy.h"
18int fn_NetSim_802_11_InfrastructureBSS_Init(NETSIM_ID nApID,NETSIM_ID nApInterfaceID)
20 int nConnectedDeviceCount;
22 NETSIM_ID nDevId, nIntefId, nProtocolId;
24 PIEEE802_11_MAC_VAR pstruApMac;
25 PIEEE802_11_PHY_VAR pstruApPhy;
26 PIEEE802_11_MAC_VAR pstruNodeMac;
27 PIEEE802_11_PHY_VAR pstruNodePhy;
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;
35 if(pstruLink->nLinkType != LinkType_P2MP)
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));
42 nConnectedDeviceCount = pstruLink->puniDevList.pstrup2MP.nConnectedDeviceCount;
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));
59 for(nLoop = 0; nLoop < nConnectedDeviceCount-1; nLoop++)
61 nDevId = pstruLink->puniDevList.pstrup2MP.anDevIds[nLoop];
62 nIntefId = pstruLink->puniDevList.pstrup2MP.anDevInterfaceIds[nLoop];
64 pstruNodeMac = IEEE802_11_MAC(nDevId,nIntefId);
65 pstruNodePhy = IEEE802_11_PHY(nDevId,nIntefId);
66 nProtocolId = DEVICE_MACLAYER(nDevId,nIntefId)->nMacProtocolId;
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));
78 pstruNodeMac->dDistFromAp = fn_NetSim_Utilities_CalculateDistance(DEVICE_POSITION(nDevId),DEVICE_POSITION(nApID));
81 pstruNodePhy->dFrequency= pstruApPhy->dFrequency;
84 pstruNodeMac->BSSType=INFRASTRUCTURE;
85 pstruNodeMac->BSSId = DEVICE_HWADDRESS(nApID,nApInterfaceID);
86 pstruNodeMac->nBSSId = nApID;
87 pstruNodeMac->nAPInterfaceId= nApInterfaceID;
92void fn_NetSim_802_11_InfrastructureBSS_UpdateReceiver(NetSim_PACKET* packet)
94 PIEEE802_11_MAC_VAR mac=IEEE802_11_CURR_MAC;
96 if(MAC_COMPARE(DEVICE_HWADDRESS(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId),mac->BSSId))
98 packet->nReceiverId = mac->nBSSId;
99 packet->nTransmitterId = pstruEventDetails->nDeviceId;
103 if (isMulticastPacket(packet) || isBroadcastPacket(packet))
104 packet->nReceiverId = 0;
106 packet->nReceiverId = get_first_dest_from_packet(packet);
107 packet->nTransmitterId = pstruEventDetails->nDeviceId;
111bool isPacketforsameInfrastructureBSS(PIEEE802_11_MAC_VAR mac,NetSim_PACKET* packet)
114 if(!MAC_COMPARE(DEVICE_HWADDRESS(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId),mac->BSSId))
116 for (i = 0; i < mac->devCountinBSS; i++)
118 if (isDestFoundinPacket(packet, mac->devIdsinBSS[i]))