blob: 2b752491ece9f599d34c725f7a2da84fe31a923b [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright 2019-present Infosys Limited
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include <typeinfo>
8#include "actionHandlers/actionHandlers.h"
9#include "controlBlock.h"
10#include "msgType.h"
11#include "contextManager/subsDataGroupManager.h"
12#include "contextManager/dataBlocks.h"
13#include "procedureStats.h"
14#include "log.h"
15#include "secUtils.h"
16#include "state.h"
17#include <string.h>
18#include <sstream>
19#include <smTypes.h>
20
21#include <ipcTypes.h>
22#include <tipcTypes.h>
23#include <msgBuffer.h>
24#include <interfaces/mmeIpcInterface.h>
25#include <utils/mmeContextManagerUtils.h>
26
27using namespace SM;
28using namespace mme;
29using namespace cmn::utils;
30
31extern MmeIpcInterface* mmeIpcIf_g;
32
33ActStatus ActionHandlers::ni_detach_req_to_ue(SM::ControlBlock& cb)
34{
35 log_msg(LOG_DEBUG, "Inside ni_detach_req_to_ue \n");
36
37 UEContext *ue_ctxt = dynamic_cast<UEContext*>(cb.getPermDataBlock());
38
39 if (ue_ctxt == NULL)
40 {
41 log_msg(LOG_DEBUG, "ni_detach_req_to_ue: ue context is NULL\n");
42 return ActStatus::HALT;
43 }
44
45 ni_detach_request_Q_msg ni_detach_req;
46
47 ni_detach_req.msg_type = ni_detach_request;
48 ni_detach_req.enb_fd = ue_ctxt->getEnbFd();
49 ni_detach_req.ue_idx = ue_ctxt->getContextID();
50 ni_detach_req.enb_s1ap_ue_id = ue_ctxt->getS1apEnbUeId();
51 ni_detach_req.detach_type = 00000010;
52
53 ue_ctxt->setDwnLnkSeqNo(ue_ctxt->getDwnLnkSeqNo()+1);
54 ni_detach_req.dl_seq_no = ue_ctxt->getDwnLnkSeqNo();
55
56 memcpy(&(ni_detach_req.int_key), &(ue_ctxt->getUeSecInfo().secinfo_m.int_key), NAS_INT_KEY_SIZE);
57
58 /* Send message to S1app in S1q*/
59 cmn::ipc::IpcAddress destAddr;
60 destAddr.u32 = TipcServiceInstance::s1apAppInstanceNum_c;
61
62 mmeIpcIf_g->dispatchIpcMsg((char *) &ni_detach_req, sizeof(ni_detach_req), destAddr);
63
64 log_msg(LOG_DEBUG, "Leaving ni_detach_req_to_ue \n");
65
66 ProcedureStats::num_of_clr_received ++;
67 ProcedureStats::num_of_detach_req_to_ue_sent ++;
68
69 return ActStatus::PROCEED;
70}
71
72ActStatus ActionHandlers::process_detach_accept_from_ue(SM::ControlBlock& cb)
73{
74 log_msg(LOG_DEBUG, "Inside process_detach_accept_from_ue \n");
75
76 UEContext *ue_ctxt = dynamic_cast<UEContext*>(cb.getPermDataBlock());
77
78 if (ue_ctxt == NULL)
79 {
80 log_msg(LOG_DEBUG, "process_detach_accept_from_ue: ue context is NULL\n");
81 return ActStatus::HALT;
82 }
83
84 ue_ctxt->setUpLnkSeqNo(ue_ctxt->getUpLnkSeqNo()+1);
85
86 log_msg(LOG_DEBUG, "Leaving process_detach_accept_from_ue \n");
87
88 ProcedureStats::num_of_cla_sent ++;
89 ProcedureStats::num_of_detach_accept_from_ue ++;
90
91 return ActStatus::PROCEED;
92}
93
94/***************************************
95* Action handler : send_s1_rel_cmd_to_ue_for_detach
96***************************************/
97ActStatus ActionHandlers::send_s1_rel_cmd_to_ue_for_detach(ControlBlock& cb)
98{
99 log_msg(LOG_DEBUG, "Inside send_s1_rel_cmd_to_ue_for_detach\n");
100
101 UEContext *ue_ctxt = dynamic_cast<UEContext*>(cb.getPermDataBlock());
102 if(ue_ctxt == NULL)
103 {
104 log_msg(LOG_DEBUG, "send_s1_rel_cmd_to_ue_for_detach: ue context is NULL \n");
105 return ActStatus::HALT;
106 }
107
108 struct s1relcmd_info s1relcmd;
109
110 s1relcmd.msg_type = s1_release_command;
111 s1relcmd.ue_idx = ue_ctxt->getContextID();
112 s1relcmd.enb_fd = ue_ctxt->getEnbFd();
113 s1relcmd.enb_s1ap_ue_id = ue_ctxt->getS1apEnbUeId();
114 s1relcmd.cause.present = s1apCause_PR_radioNetwork;
115 s1relcmd.cause.choice.radioNetwork = s1apCauseRadioNetwork_user_inactivity;
116
117 /*Send message to S1AP-APP*/
118 cmn::ipc::IpcAddress destAddr;
119 destAddr.u32 = TipcServiceInstance::s1apAppInstanceNum_c;
120 mmeIpcIf_g->dispatchIpcMsg((char *) &s1relcmd, sizeof(s1relcmd), destAddr);
121
122 log_msg(LOG_DEBUG,"Leaving send_s1_rel_cmd_to_ue \n");
123
124 ProcedureStats::num_of_s1_rel_cmd_sent ++;
125 return ActStatus::PROCEED;
126}
127
128/************************************************************
129* Action handler : process_ue_ctxt_rel_comp_for_detach
130**************************************************************/
131ActStatus ActionHandlers::process_ue_ctxt_rel_comp_for_detach(ControlBlock& cb)
132{
133 log_msg(LOG_DEBUG, "Inside process_ue_ctxt_rel_comp_for_detach \n");
134
135 UEContext *ueCtxt = dynamic_cast<UEContext*>(cb.getPermDataBlock());
136 MmeDetachProcedureCtxt *procCtxt = dynamic_cast<MmeDetachProcedureCtxt*>(cb.getTempDataBlock());
137 if (ueCtxt == NULL || procCtxt == NULL)
138 {
139 log_msg(LOG_DEBUG, "UE context or procedure context is NULL\n");
140 return ActStatus::HALT;
141 }
142
143 MmContext* mmCtxt = ueCtxt->getMmContext();
144 if (mmCtxt == NULL)
145 {
146 log_msg(LOG_DEBUG, "MM context is NULL \n");
147 return ActStatus::HALT;
148 }
149
150 if(procCtxt->getCancellationType() == SUBSCRIPTION_WITHDRAWAL)
151 {
152 MmeContextManagerUtils::deleteUEContext(cb.getCBIndex());
153 }
154 else
155 {
156 mmCtxt->setMmState( EpsDetached );
157 MmeContextManagerUtils::deallocateProcedureCtxt(cb, detach_c);
158 }
159
160 ProcedureStats::num_of_subscribers_detached ++;
161 ProcedureStats::num_of_subscribers_attached --;
162
163 log_msg(LOG_DEBUG, "Leaving process_ue_ctxt_rel_comp_for_detach \n");
164
165 return ActStatus::PROCEED;
166
167}
168