NetSim Source Code Help v14.4
All 13 Components
 
Loading...
Searching...
No Matches
Handover.c
1
2/************************************************************************************
3 * Copyright (C) 2023 *
4 * TETCOS, Bangalore. India *
5 * *
6 * Tetcos owns the intellectual property rights in the Product and its content. *
7 * The copying, redistribution, reselling or publication of any or all of the *
8 * Product or its content without express prior written consent of Tetcos is *
9 * prohibited. Ownership and / or any other right relating to the software and all *
10 * intellectual property rights therein shall remain at all times with Tetcos. *
11 * *
12 * Author: Shashi Kant Suman *
13 * *
14 * ---------------------------------------------------------------------------------*/
15#include "main.h"
16#include "GSM.h"
17#include "Cellular.h"
18#include "../Application/Application.h"
19/**
20 As the mobile stations moves out of one cell to the next, it must be possible to hand the call over
21 from the base station of the first cell, to that of the next with no discernable disruption to the call.
22 It is necessary to ensure it can be performed reliably and without disruption to any calls.
23 Failure for it to perform reliably can result in dropped calls.
24 When the handover occurs it is necessary to re-route the call to the relevant base station along with
25 changing the communication between the mobile and the base station to a new channel. All of this needs
26 to be undertaken without any noticeable interruption to the call.
27*/
28int fn_NetSim_Cellular_HandoverCall(NETSIM_ID nMSId,NETSIM_ID nMSInterface,double time)
29{
30 Cellular_MS_MAC* MSMac=DEVICE_MACVAR(nMSId,nMSInterface);
31 //Send channel request to new BTS
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)
37 return 0;
38 MSMac->nMSStatusFlag=Status_ChannelRequestedForHandover;
39 request=fn_NetSim_Cellular_createPacket(pstruEventDetails->dEventTime,
40 CELLULAR_PACKET_TYPE(nProtocol,PacketType_ChannelRequestForHandover),
41 nMSId,
42 MSMac->nNewBTS,
43 1,
44 nProtocol);
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;
51 //Add packet to physical out
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++;
64 return 1;
65}
66/** This function is called as a response for handover */
67int fn_NetSim_Cellular_ChannelResponseForHandover()
68{
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)
73 {
74 //Release old channel
75 MSMac->pstruAllocatedChannel->nAllocationFlag=0;
76 MSMac->pstruAllocatedChannel->nApplicationId=0;
77 MSMac->pstruAllocatedChannel->nDestId=0;
78 MSMac->pstruAllocatedChannel->nMSId=0;
79
80 MSMac->pstruAllocatedChannel=response->channel;
81 MSMac->nMSStatusFlag=Status_CallInProgress;
82 fn_NetSim_Cellular_MoveMS(pstruEventDetails->nDeviceId,MSMac->nNewBTS);
83 }
84 else
85 {
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);
99 }
100 return 1;
101}
102/** This function is called to drop a call */
103int fn_NetSim_Cellular_DropCall()
104{
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)
111 return 1;
112 //Drop call
113 if(MSMac->nSourceFlag==1)
114 {
115 ((APP_CALL_INFO*)appInfo->appData)->fn_BlockCall(appInfo,
116 pstruEventDetails->nDeviceId,
117 MSMac->pstruAllocatedChannel->nDestId,
118 pstruEventDetails->dEventTime);
119 pstruEventDetails->nProtocolId=nProtocol;
120 }
121 while(MSMac->pstruPacketList && MSMac->pstruPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1])
122 {
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);
126 }
127 while(MSMac->receivedPacketList && MSMac->receivedPacketList[MSMac->nApplicationId][MSMac->pstruAllocatedChannel->nMSId-1][MSMac->pstruAllocatedChannel->nDestId-1])
128 {
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);
132 }
133 //Release old channel
134 MSMac->pstruAllocatedChannel->nAllocationFlag=0;
135 MSMac->pstruAllocatedChannel->nApplicationId=0;
136 MSMac->pstruAllocatedChannel->nDestId=0;
137 MSMac->pstruAllocatedChannel->nMSId=0;
138 //Drop call
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))
144 {
145 fn_NetSim_Cellular_MoveMS(pstruEventDetails->nDeviceId,MSMac->nNewBTS);
146 MSMac->MSMetrics.nCallDropeed++;
147 }
148 return 1;
149}