blob: 5ff68d2db85849d7d27d865408ae39d2c8bd92e5 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2 * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
3 * Copyright (c) 2017 Intel Corporation
4 * Copyright (c) 2019, Infosys Ltd.
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <unistd.h>
22#include <string.h>
23#include <pthread.h>
24
25#include "err_codes.h"
26#include "options.h"
27#include "ipc_api.h"
28#include "main.h"
29#include "s1ap.h"
30#include "s1ap_config.h"
31#include "sctp_conn.h"
32#include "s1ap_structs.h"
33#include "s1ap_msg_codes.h"
34#include "msgType.h"
35
36
37extern int g_enb_fd;
38extern ipc_handle ipc_S1ap_Hndl;
39
40int
41detach_stage1_handler(struct proto_IE *detach_ies, bool retransmit)
42{
43 struct s1_incoming_msg_data_t req= {0};
44
45 /*****Message structure***
46 */
47 log_msg(LOG_INFO, "Parse s1ap detach request message\n");
48
49 /*Validate all eNB info*/
50
51 /*Add eNB info to hash*/
52
53 /*Create Q structure for detach stage 1 to MME.
54 contains init UE information.*/
55 /* TODO : Revisit, in InitialContextSetup Request we are sending
56 * MME UE S1AP Id as M-TMSI.
57 */
58 req.msg_type = detach_request;
59 for(int i = 0; i < detach_ies->no_of_IEs; i++)
60 {
61 switch(detach_ies->data[i].IE_type)
62 {
63 case S1AP_IE_MME_UE_ID:
64 {
65 if (!retransmit)
66 {
67 req.ue_idx = detach_ies->data[i].val.mme_ue_s1ap_id;
68 }
69 }break;
70 case S1AP_IE_ENB_UE_ID:
71 {
72 req.s1ap_enb_ue_id = detach_ies->data[i].val.enb_ue_s1ap_id;
73 }break;
74 case S1AP_IE_NAS_PDU:
75 {
76 if(retransmit)
77 {
78 req.msg_data.detachReq_Q_msg_m.ue_m_tmsi = ntohl(detach_ies->data[i].val.nas.elements[0].pduElement.mi_guti.m_TMSI);
79 }
80 }break;
81 default:
82 log_msg(LOG_WARNING,"Unhandled IE");
83 }
84 }
85
86 req.destInstAddr = htonl(mmeAppInstanceNum_c);
87 req.srcInstAddr = htonl(s1apAppInstanceNum_c);
88 send_tipc_message(ipc_S1ap_Hndl, mmeAppInstanceNum_c, (char *)&req, S1_READ_MSG_BUF_SIZE);
89
90 /*Send S1Setup response*/
91 log_msg(LOG_INFO, "Send to mme-app stage1.\n");
92
93 return SUCCESS;
94}
95
96