blob: 933600ad4aab6c5efb117e1f0db64d82e9e70c7a [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2019, Infosys Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <controlBlock.h>
18#include <contextManager/subsDataGroupManager.h>
19#include <log.h>
20#include <utils/mmeContextManagerUtils.h>
21
22using namespace mme;
23
24bool MmeContextManagerUtils::deleteProcedureCtxt(MmeProcedureCtxt* procedure_p)
25{
26 log_msg(LOG_DEBUG, "deleteProcedureCtxt: Entry");
27
28 if (procedure_p == NULL)
29 {
30 log_msg(LOG_INFO, "Procedure Context is NULL");
31
32 return false;
33 }
34
35 SubsDataGroupManager* subsDgMgr_p = SubsDataGroupManager::Instance();
36
37 log_msg(LOG_INFO, "Procedure Type is %d", procedure_p->getCtxtType());
38
39 bool rc = true;
40 switch (procedure_p->getCtxtType())
41 {
42 case attach_c:
43 case s1Release_c:
44 {
45 subsDgMgr_p->deleteMmeProcedureCtxt(procedure_p);
46 break;
47 }
48 case detach_c:
49 {
50 MmeDetachProcedureCtxt* detachProc_p =
51 static_cast<MmeDetachProcedureCtxt *>(procedure_p);
52
53 subsDgMgr_p->deleteMmeDetachProcedureCtxt(detachProc_p);
54
55 break;
56 }
57 case serviceRequest_c:
58 {
59 MmeSvcReqProcedureCtxt* svcReqProc_p =
60 static_cast<MmeSvcReqProcedureCtxt*>(procedure_p);
61
62 subsDgMgr_p->deleteMmeSvcReqProcedureCtxt(svcReqProc_p);
63
64 break;
65 }
66 case tau_c:
67 {
68 MmeTauProcedureCtxt* tauProc_p =
69 static_cast<MmeTauProcedureCtxt*>(procedure_p);
70
71 subsDgMgr_p->deleteMmeTauProcedureCtxt(tauProc_p);
72
73 break;
74 }
75 default:
76 {
77 log_msg(LOG_INFO, "Unsupported procedure type %d\n", procedure_p->getCtxtType());
78 rc = false;
79 }
80 }
81 return rc;
82}
83
84bool MmeContextManagerUtils::deallocateProcedureCtxt(SM::ControlBlock& cb_r, ProcedureType procType)
85{
86 bool rc = false;
87
88 MmeProcedureCtxt* procedure_p =
89 static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
90
91 MmeProcedureCtxt* prevProcedure_p = NULL;
92 MmeProcedureCtxt* nextProcedure_p = NULL;
93
94 while (procedure_p != NULL)
95 {
96 nextProcedure_p =
97 static_cast<MmeProcedureCtxt*>(procedure_p->getNextTempDataBlock());
98
99 ProcedureType procedureType = procedure_p->getCtxtType();
100 if (procType == procedureType)
101 {
102 log_msg(LOG_INFO, "Procedure type %d\n", procedureType);
103
104 rc = deleteProcedureCtxt(procedure_p);
105
106 if (rc == true)
107 {
108 if (prevProcedure_p != NULL)
109 {
110 if (nextProcedure_p != NULL)
111 {
112 prevProcedure_p->setNextTempDataBlock(nextProcedure_p);
113 }
114 }
115 else
116 {
117 cb_r.setTempDataBlock(nextProcedure_p);
118 }
119 }
120 // break out of while loop
121 break;
122 }
123 prevProcedure_p = procedure_p;
124 procedure_p = nextProcedure_p;
125 }
126
127 return rc;
128}
129
130bool MmeContextManagerUtils::deallocateAllProcedureCtxts(SM::ControlBlock& cb_r)
131{
132 bool rc = false;
133
134 MmeProcedureCtxt* procedure_p =
135 static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
136
137 MmeProcedureCtxt* nextProcedure_p = NULL;
138
139 while (procedure_p != NULL)
140 {
141 nextProcedure_p =
142 static_cast<MmeProcedureCtxt*>(procedure_p->getNextTempDataBlock());
143
144 if (procedure_p->getCtxtType() != defaultMmeProcedure_c)
145 {
146 rc = deleteProcedureCtxt(procedure_p);
147 }
148
149 procedure_p = nextProcedure_p;
150 }
151 return rc;
152}
153
154MmeProcedureCtxt* MmeContextManagerUtils::findProcedureCtxt(SM::ControlBlock& cb_r, ProcedureType procType)
155{
156 MmeProcedureCtxt* mmeProcCtxt_p = NULL;
157
158 MmeProcedureCtxt* currentProcedure_p =
159 static_cast<MmeProcedureCtxt*>(cb_r.getTempDataBlock());
160
161 MmeProcedureCtxt* nextProcedure_p = NULL;
162
163 while (currentProcedure_p != NULL)
164 {
165 nextProcedure_p = static_cast<MmeProcedureCtxt*>(
166 currentProcedure_p->getNextTempDataBlock());
167
168 if (currentProcedure_p->getCtxtType() == procType)
169 {
170 mmeProcCtxt_p = currentProcedure_p;
171 break;
172 }
173 currentProcedure_p = nextProcedure_p;
174 }
175
176 return mmeProcCtxt_p;
177}
178
179void MmeContextManagerUtils::deleteSessionContext(SM::ControlBlock& cb_r)
180{
181 UEContext* ueCtxt_p = static_cast<UEContext *>(cb_r.getPermDataBlock());
182 if (ueCtxt_p == NULL)
183 {
184 log_msg(LOG_DEBUG, "Failed to retrieve UEContext from control block %u", cb_r.getCBIndex());
185 return;
186 }
187
188 SessionContext* sessCtxt_p = ueCtxt_p->getSessionContext();
189 if (sessCtxt_p == NULL)
190 {
191 log_msg(LOG_DEBUG, "Failed to retrieve SessionContext from UEContext %u", cb_r.getCBIndex());
192 return;
193 }
194
195 BearerContext* bearerCtxt_p = sessCtxt_p->getBearerContext();
196 if(bearerCtxt_p != NULL)
197 {
198 log_msg(LOG_INFO, "Deallocating bearer context for UE block %u", cb_r.getCBIndex());
199
200 SubsDataGroupManager::Instance()->deleteBearerContext(bearerCtxt_p);
201 sessCtxt_p->setBearerContext(NULL);
202 }
203
204 log_msg(LOG_INFO, "Deallocating session context for UE block %u", cb_r.getCBIndex());
205
206 SubsDataGroupManager::Instance()->deleteSessionContext(sessCtxt_p);
207 ueCtxt_p->setSessionContext(NULL);
208}
209
210void MmeContextManagerUtils::deleteUEContext(uint32_t cbIndex)
211{
212 SM::ControlBlock* cb_p = SubsDataGroupManager::Instance()->findControlBlock(cbIndex);
213 if (cb_p == NULL)
214 {
215 log_msg(LOG_DEBUG, "Failed to find control block for index %u", cbIndex);
216 return;
217 }
218
219 deallocateAllProcedureCtxts(*cb_p);
220
221 deleteSessionContext(*cb_p);
222
223 UEContext* ueCtxt_p = static_cast<UEContext *>(cb_p->getPermDataBlock());
224 if (ueCtxt_p == NULL)
225 {
226 log_msg(LOG_DEBUG, "Failed to retrieve UEContext from control block %u", cbIndex);
227 }
228 else
229 {
230 MmContext* mmContext_p = ueCtxt_p->getMmContext();
231 if (mmContext_p != NULL)
232 {
233 SubsDataGroupManager::Instance()->deleteMmContext(mmContext_p);
234 ueCtxt_p->setMmContext(NULL);
235 }
236
237 // Remove IMSI -> CBIndex key mapping
238 const DigitRegister15& ue_imsi = ueCtxt_p->getImsi();
239 SubsDataGroupManager::Instance()->deleteimsikey(ue_imsi);
240
241 // Remove mTMSI -> CBIndex mapping
242 SubsDataGroupManager::Instance()->deletemTmsikey(ueCtxt_p->getMtmsi());
243
244 SubsDataGroupManager::Instance()->deleteUEContext(ueCtxt_p);
245 }
246
247 SubsDataGroupManager::Instance()->deAllocateCB(cb_p->getCBIndex());
248}