blob: 45b1dccca574a8b1177b7ec5a3e034ba01d5bce8 [file] [log] [blame]
anjana_sreekumar@infosys.com991c2062020-01-08 11:42:57 +05301/*
2* Copyright 2019-present Open Networking Foundation
3*
4* SPDX-License-Identifier: Apache-2.0
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 <pthread.h>
22#include <string.h>
23#include <unistd.h>
24#include <stdint.h>
25
26#include "log.h"
27#include "err_codes.h"
28#include "s1ap.h"
29#include "message_queues.h"
30#include "ipc_api.h"
31
32#include "main.h"
33#include "sctp_conn.h"
34#include "msgType.h"
35
36
37
38/**
39* Get ProtocolIE value ID Request sent by mme-app
40*/
41static int
42get_attach_id_request_protoie_value(struct proto_IE *value,struct attachIdReq_info *g_attachIdReqInfo)
43{
44
45
46 value->no_of_IEs = ATTACH_ID_REQUEST_NO_OF_IES;
47
48 value->data = (proto_IEs *) malloc(ATTACH_ID_REQUEST_NO_OF_IES*
49 sizeof(proto_IEs));
50
51
52 value->data[0].val.mme_ue_s1ap_id = g_attachIdReqInfo->ue_idx;
53
54 value->data[1].val.enb_ue_s1ap_id = g_attachIdReqInfo->s1ap_enb_ue_id;
55
56
57 log_msg(LOG_INFO, "mme_ue_s1ap_id %d and enb_ue_s1ap_id %d\n",
58 g_attachIdReqInfo->ue_idx, g_attachIdReqInfo->s1ap_enb_ue_id);
59
60 /* TODO: Add enum for security header type */
61 value->data[2].val.nas.header.security_header_type = 0;
62 value->data[2].val.nas.header.proto_discriminator = EPSMobilityManagementMessages;
63 value->data[2].val.nas.header.message_type = IdentityRequest;
64 value->data[2].val.nas.header.nas_security_param = 0;
65
66 return SUCCESS;
67}
68
69
70/**
71* Stage specific message processing.
72*/
73static int
74s1ap_attach_id_req_processing(struct attachIdReq_info *g_attachIdReqInfo)
75{
76 struct Buffer g_buffer;
77 struct Buffer g_value_buffer;
78 struct Buffer g_nas_buffer;
79
80 struct s1ap_PDU s1apPDU= {0};
81
82
83 s1apPDU.procedurecode = id_downlinkNASTransport;
84 s1apPDU.criticality = CRITICALITY_IGNORE;
85
86 get_attach_id_request_protoie_value(&s1apPDU.value,g_attachIdReqInfo);
87
88 /* Copy values to buffer from s1apPDU */
89
90 g_buffer.pos = 0;
91
92 uint8_t initiating_message = 0; /* TODO: Add enum */
93 buffer_copy(&g_buffer, &initiating_message,
94 sizeof(initiating_message));
95
96 buffer_copy(&g_buffer, &s1apPDU.procedurecode,
97 sizeof(s1apPDU.procedurecode));
98
99 buffer_copy(&g_buffer, &s1apPDU.criticality,
100 sizeof(s1apPDU.criticality));
101
102 /* Copy values in g_value_buffer */
103 g_value_buffer.pos = 0;
104
105 /* TODO remove hardcoded values */
106 unsigned char chProtoIENo[3] = {0,0,3};
107
108 buffer_copy(&g_value_buffer, chProtoIENo, 3);
109
110 unsigned char tmpStr[4];
111 /* id-MME-UE-S1AP-ID */
112 uint16_t protocolIe_Id = id_MME_UE_S1AP_ID;
113 copyU16(tmpStr, protocolIe_Id);
114 buffer_copy(&g_value_buffer, tmpStr,
115 sizeof(protocolIe_Id));
116
117 uint8_t protocolIe_criticality = CRITICALITY_REJECT;
118 buffer_copy(&g_value_buffer, &protocolIe_criticality,
119 sizeof(protocolIe_criticality));
120
121 uint8_t datalen = 2;
122
123 /* TODO needs proper handling*/
124 unsigned char mme_ue_id[3];
125 datalen = copyU16(mme_ue_id,
126 s1apPDU.value.data[0].val.mme_ue_s1ap_id);
127 buffer_copy(&g_value_buffer, &datalen, sizeof(datalen));
128 buffer_copy(&g_value_buffer, mme_ue_id, datalen);
129
130 /* id-eNB-UE-S1AP-ID */
131
132 protocolIe_Id = id_eNB_UE_S1AP_ID;
133 copyU16(tmpStr, protocolIe_Id);
134 buffer_copy(&g_value_buffer, tmpStr,
135 sizeof(protocolIe_Id));
136
137 buffer_copy(&g_value_buffer, &protocolIe_criticality,
138 sizeof(protocolIe_criticality));
139
140
141 /* TODO needs proper handling*/
142 unsigned char enb_ue_id[3];
143 datalen = copyU16(enb_ue_id,
144 s1apPDU.value.data[1].val.enb_ue_s1ap_id);
145 buffer_copy(&g_value_buffer, &datalen, sizeof(datalen));
146 buffer_copy(&g_value_buffer, enb_ue_id, datalen);
147
148
149 /* id-NAS-PDU */
150 protocolIe_Id = id_NAS_PDU;
151 copyU16(tmpStr, protocolIe_Id);
152 buffer_copy(&g_value_buffer, tmpStr,
153 sizeof(protocolIe_Id));
154
155 buffer_copy(&g_value_buffer, &protocolIe_criticality,
156 sizeof(protocolIe_criticality));
157
158 struct nasPDU *nas = &(s1apPDU.value.data[2].val.nas);
159 uint8_t value = (nas->header.security_header_type) |
160 nas->header.proto_discriminator;
161
162 g_nas_buffer.pos = 0;
163
164 buffer_copy(&g_nas_buffer, &value, sizeof(value));
165
166 buffer_copy(&g_nas_buffer, &nas->header.message_type,
167 sizeof(nas->header.message_type));
168
169 value = g_attachIdReqInfo->ue_type;
170 buffer_copy(&g_nas_buffer, &value, sizeof(value));
171
172 datalen = g_nas_buffer.pos + 1;
173
174 buffer_copy(&g_value_buffer, &datalen,
175 sizeof(datalen));
176
177 buffer_copy(&g_value_buffer, &g_nas_buffer.pos,
178 sizeof(g_nas_buffer.pos));
179
180
181 buffer_copy(&g_value_buffer, &g_nas_buffer,
182 g_nas_buffer.pos);
183
184 buffer_copy(&g_buffer, &g_value_buffer.pos,
185 sizeof(g_value_buffer.pos));
186
187 buffer_copy(&g_buffer, &g_value_buffer,
188 g_value_buffer.pos);
189
190 free(s1apPDU.value.data[2].val.nas.elements);
191 free(s1apPDU.value.data);
192
193 send_sctp_msg(g_attachIdReqInfo->enb_fd, g_buffer.buf, g_buffer.pos, 1);
194
195 return SUCCESS;
196}
197
198
199
200/**
201* Thread function for stage.
202*/
203void*
204idreq_handler(void *data)
205{
206
207 log_msg(LOG_INFO, "S1Ap attach Id Request handler ready.\n");
208
209 s1ap_attach_id_req_processing((struct attachIdReq_info *)data);
210
211 return NULL;
212}
213