18#include "../Application/Application.h"
28int fn_NetSim_Cellular_HandoverCall(NETSIM_ID nMSId,NETSIM_ID nMSInterface,
double time)
30 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSId,nMSInterface);
32 NetSim_PACKET* request;
33 Cellular_PACKET* gsmPacket=calloc(1,
sizeof* gsmPacket);
34 Cellular_CHANNEL_REQUEST* requestData=calloc(1,
sizeof* requestData);
35 unsigned int nProtocol=DEVICE_MACLAYER(nMSId,nMSInterface)->nMacProtocolId;
36 if(MSMac->pstruAllocatedChannel==NULL)
38 MSMac->nMSStatusFlag=Status_ChannelRequestedForHandover;
39 request=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
40 CELLULAR_PACKET_TYPE(nProtocol,PacketType_ChannelRequestForHandover),
45 request->pstruMacData->Packet_MACProtocol=gsmPacket;
46 gsmPacket->controlData=requestData;
47 requestData->nApplicationId=MSMac->nApplicationId;
48 requestData->nMSId=nMSId;
49 requestData->nDestId=MSMac->pstruAllocatedChannel->nDestId;
50 requestData->nRequestType=PacketType_ChannelRequestForHandover;
52 pstruEventDetails->nApplicationId=MSMac->nApplicationId;
53 pstruEventDetails->nDeviceId=nMSId;
54 pstruEventDetails->nDeviceType=MOBILESTATION;
55 pstruEventDetails->nInterfaceId=1;
56 pstruEventDetails->dPacketSize=1;
57 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
58 pstruEventDetails->nProtocolId=nProtocol;
59 pstruEventDetails->nPacketId=0;
60 pstruEventDetails->pPacket=request;
61 fnpAddEvent(pstruEventDetails);
62 MSMac->MSMetrics.nHandoverRequest++;
63 MSMac->MSMetrics.nChannelRequestSent++;
67int fn_NetSim_Cellular_ChannelResponseForHandover()
69 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
70 Cellular_PACKET* gsmPacket=pstruEventDetails->pPacket->pstruMacData->Packet_MACProtocol;
71 Cellular_CHANNEL_RESPONSE* response=gsmPacket->controlData;
72 if(response->nAllocationFlag==1)
77 MSMac->pstruAllocatedChannel->nDestId=0;
78 MSMac->pstruAllocatedChannel->
nMSId=0;
80 MSMac->pstruAllocatedChannel=response->channel;
81 MSMac->nMSStatusFlag=Status_CallInProgress;
82 fn_NetSim_Cellular_MoveMS(pstruEventDetails->nDeviceId,MSMac->nNewBTS);
86 NetSim_PACKET* packet=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
87 CELLULAR_PACKET_TYPE(pstruEventDetails->nProtocolId,PacketType_DropCall),
88 pstruEventDetails->nDeviceId,
89 MSMac->pstruAllocatedChannel->nDestId,
90 1,pstruEventDetails->nProtocolId);
91 Cellular_PACKET* gsmPacket=calloc(1,
sizeof* gsmPacket);
92 gsmPacket->nApplicationId=MSMac->pstruAllocatedChannel->
nApplicationId;
93 gsmPacket->nTimeSlot=MSMac->pstruAllocatedChannel->nTimeSlot;
94 packet->pstruMacData->Packet_MACProtocol=gsmPacket;
95 pstruEventDetails->dPacketSize=1;
96 pstruEventDetails->nEventType=PHYSICAL_OUT_EVENT;
97 pstruEventDetails->pPacket=packet;
98 fnpAddEvent(pstruEventDetails);
103int fn_NetSim_Cellular_DropCall()
105 unsigned int nProtocol=pstruEventDetails->nProtocolId;
106 unsigned int nSubevent=pstruEventDetails->nSubEventType;
107 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(pstruEventDetails->nDeviceId,pstruEventDetails->nInterfaceId);
108 ptrAPPLICATION_INFO appInfo=((ptrAPPLICATION_INFO*)NETWORK->appInfo)[MSMac->nApplicationId-1];
109 MSMac->nMSStatusFlag=Status_IDLE;
110 if(MSMac->pstruAllocatedChannel==NULL)
113 if(MSMac->nSourceFlag==1)
115 ((APP_CALL_INFO*)appInfo->appData)->fn_BlockCall(appInfo,
116 pstruEventDetails->nDeviceId,
117 MSMac->pstruAllocatedChannel->nDestId,
118 pstruEventDetails->dEventTime);
119 pstruEventDetails->nProtocolId=nProtocol;
121 while(MSMac->pstruPacketList && MSMac->pstruPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1])
123 NetSim_PACKET* packet=MSMac->pstruPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1];
124 MSMac->pstruPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1]=packet->pstruNextPacket;
125 fn_NetSim_Packet_FreePacket(packet);
127 while(MSMac->receivedPacketList && MSMac->receivedPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1])
129 NetSim_PACKET* packet=MSMac->receivedPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1];
130 MSMac->receivedPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->
nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1]=packet->pstruNextPacket;
131 fn_NetSim_Packet_FreePacket(packet);
136 MSMac->pstruAllocatedChannel->nDestId=0;
137 MSMac->pstruAllocatedChannel->
nMSId=0;
139 MSMac->pstruAllocatedChannel=NULL;
140 MSMac->nApplicationId=0;
141 MSMac->nSourceFlag=0;
142 if(nSubevent==CELLULAR_SUBEVENT(MAC_PROTOCOL_GSM,Subevent_DropCall) ||
143 nSubevent==CELLULAR_SUBEVENT(MAC_PROTOCOL_CDMA,Subevent_DropCall))
145 fn_NetSim_Cellular_MoveMS(pstruEventDetails->nDeviceId,MSMac->nNewBTS);
146 MSMac->MSMetrics.nCallDropeed++;