NetSim Source Code Help
Loading...
Searching...
No Matches
DSMAP.c
Go to the documentation of this file.
1#include "main.h"
2#include "802_22.h"
3typedef struct stru_ExtentedDSMAPIE
4{
8/** The DS-MAP message defines the access to the downstream information.
9The length of the DS-MAP shall be an integer number of bytes. */
11{
12 BS_PHY* pstruBSPhy;
13 BS_MAC* pstruBSMAC;
14 unsigned int nDSIECount=0;
15 NetSim_PACKET* pstruPacket;
16 unsigned int nPacketSize;
17 unsigned int nSID;
18 int nDSBurst;
19 unsigned int SlotRequire;
21 ExtendedDSIE *pstruTempDSMAPIE = NULL;
22 ExtendedDSIE *pstruFirstDSMAPIE = NULL;
23 pstruBSPhy = DEVICE_PHYVAR(nDeviceId,nInterfaceId);
24 pstruBSMAC = DEVICE_MACVAR(nDeviceId,nInterfaceId);
25 //Allocate memory for DS-MAP
26 pstruBSMAC->pstruDSMAP = fnpAllocateMemory(1,sizeof(DSMAP));
28 pstruBSMAC->pstruDSMAP->nPaddingBits = 0;
29
30 //Loop through access buffer
31 while(pstruBSMAC->pstruDSPacketList)
32 {
33 pstruPacket = pstruBSMAC->pstruDSPacketList;
34 UINT destCount;
35 NETSIM_ID* dest = get_dest_from_packet(pstruPacket, &destCount);
36 UINT i;
37 nSID = 0;
38 for (i = 0; i < destCount; i++)
39 {
40 nSID = pstruBSMAC->anSIDFromDevId[dest[i]];
41 if (nSID)
42 break;
43 }
44 if (!nSID)
45 {
46 if (!isBroadcastPacket(pstruPacket))
47 {
48 //The packet is not for this BS
49 pstruBSMAC->pstruDSPacketList = pstruBSMAC->pstruDSPacketList->pstruNextPacket;
50 pstruPacket->pstruNextPacket = NULL;
51 fn_NetSim_Packet_FreePacket(pstruPacket);
52 continue;
53 }
54 }
55 //Set the receiver id
56 pstruPacket->nReceiverId = destCount > 1 ? 0 : dest[0];
57 pstruPacket->nTransmitterId = nDeviceId;
58
59 nPacketSize = (unsigned int)fnGetPacketSize(pstruPacket);
60
61 if (pstruBSPhy->nFrameNumber == 0)// for considering SCH & preamble
62 nDSBurst = fn_NetSim_CR_FillDSFrame(nPacketSize, pstruBSMAC->pstruDSBurst, pstruBSPhy->pstruSymbolParameter, 4, &SlotRequire);
63 else
64 nDSBurst = fn_NetSim_CR_FillDSFrame(nPacketSize, pstruBSMAC->pstruDSBurst, pstruBSPhy->pstruSymbolParameter, 2, &SlotRequire);
65
66 if (nDSBurst)
67 {
68 //Allocated
69 pstruBSMAC->pstruDSPacketList = pstruBSMAC->pstruDSPacketList->pstruNextPacket;
70 pstruPacket->pstruNextPacket = NULL;
71 fn_NetSim_CR_AddPacketToDSBurst(pstruBSMAC->pstruDSBurst[nDSBurst],pstruPacket);
72 //Prepare the DS-MAP IE
73 pstruTempDSMAPIE = calloc(1,sizeof *pstruTempDSMAPIE);
74 pstruTempDSMAPIE->pstruDSMAPIE = calloc(1,sizeof *pstruTempDSMAPIE->pstruDSMAPIE);
75 pstruTempDSMAPIE->pstruDSMAPIE->SID = nSID;
76 pstruTempDSMAPIE->pstruDSMAPIE->length = SlotRequire;
77 nDSIECount++;
78 if(!pstruFirstDSMAPIE)
79 {
80 pstruFirstDSMAPIE = pstruTempDSMAPIE;
81 pstruDSMAPIE = pstruFirstDSMAPIE;
82 }
83 else
84 {
85 pstruDSMAPIE->pstruNext = pstruTempDSMAPIE;
86 pstruDSMAPIE = pstruTempDSMAPIE;
87 }
88 }
89 else
90 break; // No space available in DS-Frame
91 }
92 pstruBSMAC->pstruDSMAP->nIECount = nDSIECount;
93 if(nDSIECount)
94 pstruBSMAC->pstruDSMAP->pstruIE = calloc(nDSIECount,sizeof(DSMAP_IE*));
95 nDSIECount = 0;
96 while(pstruFirstDSMAPIE)
97 {
98 pstruBSMAC->pstruDSMAP->pstruIE[nDSIECount++] = pstruFirstDSMAPIE->pstruDSMAPIE;
99 pstruTempDSMAPIE = pstruFirstDSMAPIE;
100 pstruFirstDSMAPIE = pstruFirstDSMAPIE->pstruNext;
101 free(pstruTempDSMAPIE);
102 }
103 return fn_NetSim_CR_GenerateBroadcastCtrlPacket(nDeviceId,nInterfaceId,MMM_DS_MAP);
104}
106{
107 return 1;
108}
int fn_NetSim_CR_FillDSFrame(unsigned int size, DS_BURST **pstruDSBurst, SYMBOL_PARAMETER *pstruSymbolParameter, int nFlag, unsigned int *nSlotRequire)
@ MMM_DS_MAP
Downstream access definition, defines the access to the downstream information.
Definition: 802_22.h:174
int fn_NetSim_CR_AddPacketToDSBurst(DS_BURST *pstruDSBurst, NetSim_PACKET *pstruPacket)
NetSim_PACKET * fn_NetSim_CR_GenerateBroadcastCtrlPacket(int nDeviceId, int nInterfaceId, MANAGEMENT_MESSAGE nMessageType)
unsigned int NETSIM_ID
Definition: Animation.h:45
int fn_NetSim_CR_CPE_ProcessDSMAP()
Definition: DSMAP.c:105
NetSim_PACKET * fn_NetSim_CR_FormDSMAP(NETSIM_ID nDeviceId, NETSIM_ID nInterfaceId)
Definition: DSMAP.c:10
struct stru_ExtentedDSMAPIE ExtendedDSIE
#define UINT
Definition: Linux.h:38
#define free(p)
Definition: Memory.h:31
#define fnpAllocateMemory(count, size)
Definition: Memory.h:34
#define calloc(c, s)
Definition: Memory.h:29
double fnGetPacketSize(NetSim_PACKET *pstruData)
NETSIM_ID * get_dest_from_packet(NetSim_PACKET *packet, UINT *count)
bool isBroadcastPacket(NetSim_PACKET *packet)
#define DEVICE_PHYVAR(DeviceId, InterfaceId)
Definition: Stack.h:797
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
#define fn_NetSim_Packet_FreePacket(pstruPacket)
Definition: main.h:177
int * anSIDFromDevId
Have the list of CPE associated with BS. If SID is set CPE is associated else not.
Definition: 802_22.h:802
NetSim_PACKET * pstruDSPacketList
Definition: 802_22.h:816
DS_BURST ** pstruDSBurst
DS-Burst each is one symbol long.
Definition: 802_22.h:799
DSMAP * pstruDSMAP
Definition: 802_22.h:800
unsigned int nFrameNumber
Current super frame number
Definition: 802_22.h:829
SYMBOL_PARAMETER * pstruSymbolParameter
Definition: 802_22.h:854
unsigned int SID
Definition: 802_22.h:1032
unsigned int length
Definition: 802_22.h:1033
unsigned int nManagementMessageType
Definition: 802_22.h:1041
struct stru_802_22_DSMAP_IE ** pstruIE
Definition: 802_22.h:1044
unsigned int nPaddingBits
Definition: 802_22.h:1045
unsigned int nIECount
Definition: 802_22.h:1043
struct stru_ExtentedDSMAPIE * pstruNext
Definition: DSMAP.c:6
DSMAP_IE * pstruDSMAPIE
Definition: DSMAP.c:5
NETSIM_ID nReceiverId
Definition: Packet.h:266
struct stru_NetSim_Packet * pstruNextPacket
Definition: Packet.h:278
NETSIM_ID nTransmitterId
Definition: Packet.h:265