blob: eff8140a5764d22b9dbc121843658519c136b7de [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 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <unistd.h>
21#include <string.h>
22#include <pthread.h>
23
24#include "err_codes.h"
25#include "options.h"
26#include "ipc_api.h"
27#include "main.h"
28#include "s1ap.h"
29#include "s1ap_config.h"
30#include "sctp_conn.h"
31#include "s1ap_structs.h"
32#include "s1ap_msg_codes.h"
33#include "msgType.h"
34
35extern int g_enb_fd;
36extern s1ap_config g_s1ap_cfg;
37extern ipc_handle ipc_S1ap_Hndl;
38
39int
40s1_init_ue_service_req_handler(struct proto_IE *service_req_ies, int enb_fd)
41{
42 struct s1_incoming_msg_data_t req= {0};
43
44 /*****Message structure***
45 */
46 log_msg(LOG_INFO, "Parse s1ap Service request message\n");
47
48 /*Validate all eNB info*/
49
50 /*Add eNB info to hash*/
51
52 /*Create Q structure for Service req to MME.
53 contains init UE information.*/
54 /* TODO : Revisit, in InitialContextSetup Request we are sending
55 * MME UE S1AP Id as M-TMSI.
56 */
57 req.msg_type = service_request;
58 req.msg_data.service_req_Q_msg_m.enb_fd = enb_fd;
59 for(int i = 0; i < service_req_ies->no_of_IEs; i++)
60 {
61 switch(service_req_ies->data[i].IE_type)
62 {
63 case S1AP_IE_ENB_UE_ID:
64 {
65 log_msg(LOG_INFO, "Service Req S1AP_IE_ENB_UE_ID.\n");
66 req.s1ap_enb_ue_id = service_req_ies->data[i].val.enb_ue_s1ap_id;
67 }break;
68 case S1AP_IE_NAS_PDU:
69 {
70 log_msg(LOG_INFO, "Service Req NAS PDU.\n");
71 req.msg_data.service_req_Q_msg_m.ksi = service_req_ies->data[i].val.nas.header.ksi;;
72 req.msg_data.service_req_Q_msg_m.seq_no = service_req_ies->data[i].val.nas.header.seq_no;
73 memcpy(&req.msg_data.service_req_Q_msg_m.mac, service_req_ies->data[i].val.nas.header.short_mac, sizeof(uint16_t));
74 }break;
75 case S1AP_IE_TAI:
76 {
77 log_msg(LOG_INFO, "Service Req TAI.\n");
78 memcpy(&req.msg_data.service_req_Q_msg_m.tai,
79 &service_req_ies->data[i].val.tai,
80 sizeof(struct TAI));
81 }break;
82 case S1AP_IE_UTRAN_CGI:
83 {
84 log_msg(LOG_INFO, "Service Req CGI.\n");
85 memcpy(&req.msg_data.service_req_Q_msg_m.utran_cgi,
86 &service_req_ies->data[i].val.utran_cgi,
87 sizeof(struct CGI));
88 }break;
89 case S1AP_IE_S_TMSI:
90 {
91 log_msg(LOG_INFO, "Service Req STMSI.\n");
92 if(service_req_ies->data[i].val.s_tmsi.mme_code
93 == g_s1ap_cfg.mme_code)
94 {
95 log_msg(LOG_INFO, "Service Req MME Code matched.\n");
96 req.ue_idx = ntohl(service_req_ies->data[i].val.s_tmsi.m_TMSI);
97 memcpy(&req.msg_data.service_req_Q_msg_m.s_tmsi,
98 &service_req_ies->data[i].val.s_tmsi,
99 sizeof(struct STMSI));
100 }
101 else
102 {
103 log_msg(LOG_ERROR, "MME code mismatch. Send Service Reject. TBD");
104 return -E_FAIL;
105 }
106 }break;
107 default:
108 log_msg(LOG_WARNING,"Unhandled IE");
109 }
110 }
111
112 req.destInstAddr = htonl(mmeAppInstanceNum_c);
113 req.srcInstAddr = htonl(s1apAppInstanceNum_c);
114 send_tipc_message(ipc_S1ap_Hndl, mmeAppInstanceNum_c, (char *)&req, S1_READ_MSG_BUF_SIZE);
115
116
117 /*Send Service req to mme-app*/
118 log_msg(LOG_INFO, "Send to mme-app service req handler.\n");
119
120 return SUCCESS;
121}
122
123