blob: f62394f7f6e0fe40d059a3f51ca99d4ba22de41b [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
36extern int g_enb_fd;
37extern ipc_handle ipc_S1ap_Hndl;
38extern struct time_stat g_attach_stats[];
39
40int
41s1_init_ue_handler(struct proto_IE *s1_init_ies, int enodeb_fd)
42{
43 struct s1_incoming_msg_data_t ue_info = {0};
44 int nas_index = 0;
45
46 /*****Message structure***
47 */
48 log_msg(LOG_INFO, "Parse s1ap initial UE message\n");
49
50 /*Validate all eNB info*/
51
52 /*Add eNB info to hash*/
53 //STIMER_GET_CURRENT_TP(g_attach_stats[s1_init_ies->data[0].enb_ue_s1ap_id].init_ue);
54
55 /*Create Q structure for stage 1 to MME.
56 contains init UE information.*/
57 ue_info.msg_type = attach_request;
58
59 ue_info.msg_data.ue_attach_info_m.enb_fd = enodeb_fd;
60 ue_info.msg_data.ue_attach_info_m.criticality = s1_init_ies->criticality;//TBD
61 for(int i = 0; i < s1_init_ies->no_of_IEs; i++)
62 {
63 switch(s1_init_ies->data[i].IE_type)
64 {
65 case S1AP_IE_ENB_UE_ID:
66 {
67 ue_info.msg_data.ue_attach_info_m.s1ap_enb_ue_id = s1_init_ies->data[i].val.enb_ue_s1ap_id;
68 }break;
69 case S1AP_IE_TAI:
70 {
71 memcpy(&(ue_info.msg_data.ue_attach_info_m.tai), &(s1_init_ies->data[i].val.tai), sizeof(struct TAI));
72 }break;
73 case S1AP_IE_UTRAN_CGI:
74 {
75 memcpy(&(ue_info.msg_data.ue_attach_info_m.utran_cgi), &(s1_init_ies->data[i].val.utran_cgi),
76 sizeof(struct CGI));
77 }break;
78 case S1AP_IE_NAS_PDU:
79 {
80 while(nas_index < s1_init_ies->data[i].val.nas.elements_len)
81 {
82 log_msg(LOG_INFO, "nasIndex %d, msgType %d\n",
83 nas_index,
84 s1_init_ies->data[i].val.nas.elements[nas_index].msgType);
85 ue_info.msg_data.ue_attach_info_m.seq_no = s1_init_ies->data[i].val.nas.header.seq_no;
86 switch(s1_init_ies->data[i].val.nas.elements[nas_index].msgType)
87 {
88 case NAS_IE_TYPE_ESM_MSG:
89 {
90 break;
91 }
92 case NAS_IE_TYPE_EPS_MOBILE_ID_IMSI:
93 {
94 ue_info.msg_data.ue_attach_info_m.flags = s1_init_ies->data[i].val.nas.flags;
95 if(UE_ID_IMSI(s1_init_ies->data[i].val.nas.flags))
96 {
97 memcpy(&(ue_info.msg_data.ue_attach_info_m.IMSI),
98 &(s1_init_ies->data[i].val.nas.elements[nas_index].pduElement.IMSI),
99 BINARY_IMSI_LEN);
100 }
101 else if(UE_ID_GUTI(s1_init_ies->data[i].val.nas.flags))
102 {
103 memcpy(&(ue_info.msg_data.ue_attach_info_m.mi_guti), &(s1_init_ies->data[i].val.nas.elements[nas_index].pduElement.mi_guti),
104 sizeof(struct guti));
105 }
106 break;
107 }
108 case NAS_IE_TYPE_UE_NETWORK_CAPABILITY:
109 {
110 memcpy(&(ue_info.msg_data.ue_attach_info_m.ue_net_capab),
111 &(s1_init_ies->data[i].val.nas.\
112 elements[nas_index].pduElement.ue_network),
113 sizeof(struct UE_net_capab));
114
115 break;
116 }
117 case NAS_IE_TYPE_MS_NETWORK_CAPABILITY:
118 {
119 memcpy(&(ue_info.msg_data.ue_attach_info_m.ms_net_capab),
120 &(s1_init_ies->data[i].val.nas.\
121 elements[nas_index].pduElement.ms_network),
122 sizeof(struct MS_net_capab));
123
124 break;
125 }
126 case NAS_IE_TYPE_TX_FLAG:
127 {
128 ue_info.msg_data.ue_attach_info_m.esm_info_tx_required =
129 s1_init_ies->data[i].val.nas.elements[nas_index].pduElement.esm_info_tx_required;
130 log_msg(LOG_INFO, "ESM info flag %d \n", ue_info.msg_data.ue_attach_info_m.esm_info_tx_required);
131 break;
132 }
133 case NAS_IE_TYPE_PTI:
134 {
135 ue_info.msg_data.ue_attach_info_m.pti =
136 s1_init_ies->data[i].val.nas.elements[nas_index].pduElement.pti;
137 break;
138 }
139 case NAS_IE_TYPE_PCO:
140 {
141 for(int pco=0; pco < 10; pco++)
142 {
143 ue_info.msg_data.ue_attach_info_m.pco_options[pco] =
144 s1_init_ies->data[i].val.nas.elements[nas_index].pduElement.pco_options[pco];
145 }
146 break;
147 }
148 default:
149 {
150 log_msg(LOG_INFO, "nas element not handled\n");
151 }
152 }
153
154 nas_index++;
155 }
156
157 }break;
158 default:
159 log_msg(LOG_WARNING,"Unhandled IE");
160 }
161 }
162
163 ue_info.destInstAddr = htonl(mmeAppInstanceNum_c);
164 ue_info.srcInstAddr = htonl(s1apAppInstanceNum_c);
165
166 send_tipc_message(ipc_S1ap_Hndl, mmeAppInstanceNum_c, (char *)&ue_info, S1_READ_MSG_BUF_SIZE);
167
168 /*Send S1Setup response*/
169 log_msg(LOG_INFO, "Send to mme-app stage1.\n");
170
171 return SUCCESS;
172}
173
174