NetSim Source Code Help
Loading...
Searching...
No Matches
SCH.c
Go to the documentation of this file.
1#include "main.h"
2#include "802_22.h"
3/** The Superframe Control header decoding is critical, so the SCH shall be transmitted using
4the modulation technique. The length of SCH shall be one OFDM symbol. The
5SCH shall be decoded by all the CPEs associated with that BS .
6The SCH provides information about the IEEE 802.22 cell, in order to protect incumbents,
7support self-coexistence mechanisms, and support the intra-frame and inter-frame mechanisms
8for management of quiet periods for sensing. Transmission of a SCH indicates that
9the WRAN cell is operating in one of the two possible modes: normal mode or self-coexistence mode. */
11{
12 double dTime = pstruEventDetails->dEventTime;
13 BS_MAC* pstruBSMAC;
14 BS_PHY* pstruBSPhy;
15 SCH* pstruSCH;
16 NetSim_PACKET* pstruSCHPacket;
20
21 if(pstruBSPhy->pstruOpratingChannel == NULL)
22 {
23 //Add an event to check for channel
27 return 0; //No channel found
28 }
29 //Increment the superframe number in BS Phy
30 pstruBSPhy->nSuperframeNumber++;
31 pstruBSPhy->nFrameNumber = 0;
34 //Generate the SCH packet
36 pstruSCHPacket->dEventTime = pstruEventDetails->dEventTime;
38 add_dest_to_packet(pstruSCHPacket, 0); //Broadcast packet
39 pstruSCHPacket->nPacketPriority = Priority_High;
40 pstruSCHPacket->nPacketType = PacketType_Control;
41 pstruSCHPacket->nServiceType = ServiceType_CBR;
43 pstruSCHPacket->nSourceId = pstruEventDetails->nDeviceId;
44 //Fill Mac layer details
45 pstruSCHPacket->pstruMacData->dArrivalTime = dTime + 2*pstruBSPhy->pstruSymbolParameter->dSymbolDuration;
46 pstruSCHPacket->pstruMacData->dEndTime = dTime + 2*pstruBSPhy->pstruSymbolParameter->dSymbolDuration;
47 pstruSCHPacket->pstruMacData->dOverhead = SCH_SIZE;
48 pstruSCHPacket->pstruMacData->dPacketSize = SCH_SIZE;
49 pstruSCHPacket->pstruMacData->dStartTime = dTime + 2*pstruBSPhy->pstruSymbolParameter->dSymbolDuration;
51 pstruSCHPacket->pstruMacData->szDestMac = BROADCAST_MAC;
52 pstruSCHPacket->pstruMacData->szSourceMac = szBSMAC;
53
54 //Update SCH header
55 pstruSCH = fnpAllocateMemory(1,sizeof *pstruSCH);
56 pstruSCH->n_SuperframeNumber = pstruBSPhy->nSuperframeNumber;
57 pstruSCH->sz_BS_Id = szBSMAC;
59 pstruSCH->n_CP = pstruBSPhy->nCP;
60 pstruSCH->n_FCH_EncodingFlag = B2_11;
62 pstruSCH->n_MAC_version = 0x01;
63
64 //Call Spectrum manager to schedule quiet period
65 fn_Netsim_CR_SM_ScheduleQuietPeriod(pstruBSPhy,pstruSCH);
66
67 pstruSCH->n_SCW_Cycle_Frame_Bitmap = 0;
68 pstruSCH->n_SCW_Cycle_Length = 0;
69 pstruSCH->n_SCW_Cycle_Offset = 0;
70 pstruSCH->n_Current_DS_US_Split = 0;
71 pstruSCH->n_Claimed_US_DS_Split = 0;
72 pstruSCH->n_DS_US_Change_Offset = 0;
73 pstruSCH->n_HCS = 0;
74 pstruSCH->n_Padding_bits = 0;
75
76 //Add SCH header to SCH packet
77 pstruSCHPacket->pstruMacData->Packet_MACProtocol = pstruSCH;
78 //Create an event for phy out
83 pstruEventDetails->pPacket = pstruSCHPacket;
85 //Add physical out event
87 //Schedule next superfame event
94
95 //Add to metrics
96 pstruBSMAC->struBSMetrics.nSCHSent++;
97 return 1;
98}
99/** The Superframe Control header decoding is critical, so the SCH shall be transmitted using
100the modulation technique. The length of SCH shall be one OFDM symbol. The
101SCH shall be decoded by all the CPEs associated with that BS .
102The SCH provides information about the IEEE 802.22 cell, in order to protect incumbents,
103support self-coexistence mechanisms, and support the intra-frame and inter-frame mechanisms
104for management of quiet periods for sensing. Transmission of a SCH indicates that
105the WRAN cell is operating in one of the two possible modes: normal mode or self-coexistence mode. */
107{
110 SCH* pstruSCH = pstruPacket->pstruMacData->Packet_MACProtocol;
112 {
116 }
117 else
118 {
119 pstruCPEPhy->nIntraFrameQuietPeriodLength = 0;
120 }
121 pstruCPEPhy->nFrameNumber = 0;
122 //Add to metrics
123 pstruCPEMAC->struCPEMetrics.nSCHReceived++;
124 return 1;
125}
#define B16_1111111111111111
Definition: 802_22.h:59
#define SCH_DURATION
SCH Duration is 160 milli seconds.
Definition: 802_22.h:125
#define SCH_SIZE
SCH Size is 45 Bytes.
Definition: 802_22.h:119
@ MMM_SCH
Definition: 802_22.h:231
#define B2_11
Definition: 802_22.h:28
#define B4_0000
Definition: 802_22.h:41
#define CR_CONTROL_PACKET(MMM)
Definition: 802_22.h:235
int fn_Netsim_CR_SM_ScheduleQuietPeriod(BS_PHY *pstruBSPhy, SCH *pstruSCH)
@ TRANSMIT_SCH
Definition: 802_22.h:149
@ SM_UPDATECHANNEL
Definition: 802_22.h:165
#define fnpAllocateMemory(count, size)
Definition: Memory.h:34
@ ServiceType_CBR
Definition: Packet.h:72
@ PacketType_Control
Definition: Packet.h:66
void add_dest_to_packet(NetSim_PACKET *packet, NETSIM_ID dest)
@ Priority_High
Definition: Packet.h:82
int fn_NetSim_CR_TransmitSCH()
Definition: SCH.c:10
int fn_NetSim_CR_CPE_ProcessSCH(NetSim_PACKET *pstruPacket)
Definition: SCH.c:106
EXPORTED PNETSIM_MACADDRESS BROADCAST_MAC
Definition: Stack.h:393
#define DEVICE_PHYVAR(DeviceId, InterfaceId)
Definition: Stack.h:797
@ MAC_PROTOCOL_IEEE802_22
Definition: Stack.h:210
EXPORTED struct stru_NetSim_Network * NETWORK
Definition: Stack.h:742
@ TIMER_EVENT
Definition: Stack.h:114
@ PHYSICAL_OUT_EVENT
Definition: Stack.h:104
@ MAC_LAYER
Definition: Stack.h:95
#define DEVICE_MACVAR(DeviceId, InterfaceId)
Definition: Stack.h:798
EXPORTED struct stru_NetSim_EventDetails * pstruEventDetails
Definition: Stack.h:837
#define fn_NetSim_Packet_CreatePacket(layer)
Definition: main.h:186
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
BS_METRICS struBSMetrics
Definition: 802_22.h:815
double dFrameStartTime
Definition: 802_22.h:807
double dSuperframeStartTime
Definition: 802_22.h:805
unsigned int nCP
Definition: 802_22.h:838
unsigned int nSuperframeNumber
Current super frame number
Definition: 802_22.h:828
unsigned int nFrameNumber
Current super frame number
Definition: 802_22.h:829
struct stru_802_22_Channel * pstruOpratingChannel
Currently operating channel.
Definition: 802_22.h:840
SYMBOL_PARAMETER * pstruSymbolParameter
Definition: 802_22.h:854
CPE structure for IEEE 802.22 MAC.
Definition: 802_22.h:869
CPE_METRICS struCPEMetrics
Definition: 802_22.h:897
CPE structure for CPE PHY.
Definition: 802_22.h:902
unsigned int nFrameNumber
Definition: 802_22.h:914
unsigned int nIntraFrameQuietPeriodDuration
Definition: 802_22.h:913
unsigned int nIntraFrameQuietPeriodLength
Definition: 802_22.h:911
char szIntraFrameQuietPeriodBitmap[17]
Definition: 802_22.h:912
unsigned int n_Current_Intra_frame_Quiet_Period_Duration
Definition: 802_22.h:340
unsigned short int n_FrameAllocationMap
Definition: 802_22.h:264
unsigned int n_Self_coexistence_Capability_Indicator
Definition: 802_22.h:294
unsigned int n_HCS
8 bits Header Check Sequence
Definition: 802_22.h:509
unsigned int n_Current_Intra_frame_Quiet_Period_Cycle_Offset
Definition: 802_22.h:322
unsigned int n_Current_Intra_frame_Quiet_Period_Cycle_Length
Definition: 802_22.h:312
PNETSIM_MACADDRESS sz_BS_Id
48 bits, Base station mac address
Definition: 802_22.h:263
char sz_Current_Intra_frame_Quiet_period_Cycle_Frame_Bitmap[17]
Definition: 802_22.h:329
double dSymbolDuration
Tsym = Tfft + Tcp in microsec.
Definition: 802_22.h:966
unsigned int nSCHSent
Definition: 802_22.h:629
unsigned int nSCHReceived
Definition: 802_22.h:660
struct stru_NetSim_Interface ** ppstruInterfaceList
Definition: Stack.h:717
EVENT_TYPE nEventType
Definition: Stack.h:747
struct stru_NetSim_Packet * pPacket
Definition: Stack.h:754
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
NETSIM_ID nInterfaceId
Definition: Stack.h:751
struct stru_NetSim_PhysicalLayer * pstruPhysicalLayer
Definition: Stack.h:699
struct stru_NetSim_MacLayer * pstruMACLayer
Definition: Stack.h:698
PNETSIM_MACADDRESS szMacAddress
Definition: Stack.h:537
struct stru_NetSim_Device ** ppstruDeviceList
Definition: Stack.h:737
MAC_LAYER_PROTOCOL nMACProtocol
Definition: Packet.h:223
PNETSIM_MACADDRESS szDestMac
Definition: Packet.h:221
PNETSIM_MACADDRESS szSourceMac
Definition: Packet.h:220
double dEventTime
Definition: Packet.h:262
unsigned int nControlDataType
Definition: Packet.h:258
NETSIM_ID nTransmitterId
Definition: Packet.h:265
PACKET_TYPE nPacketType
Definition: Packet.h:257
PACKET_PRIORITY nPacketPriority
Definition: Packet.h:260
SERVICE_TYPE nServiceType
Definition: Packet.h:259
NETSIM_ID nSourceId
Definition: Packet.h:263
struct stru_NetSim_Packet_MACLayer * pstruMacData
Definition: Packet.h:276