blob: 38c20dd7122a0e1867ae994468db0ba73f7139ea [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
25#include "log.h"
26#include "err_codes.h"
27#include "s1ap.h"
28#include "message_queues.h"
29#include "ipc_api.h"
30#include "main.h"
31#include "sctp_conn.h"
32#include "msgType.h"
33
34
35
36
37/**
38* Get ProtocolIE value for Auth Request sent by mme-app
39*/
40static int
41get_attachReject_protoie_value(struct proto_IE *value, struct attachReqRej_info *g_attachReqRejInfo)
42{
43 value->no_of_IEs = AUTH_REQ_NO_OF_IES;
44
45 value->data = (proto_IEs *) malloc(ATTACH_REJECT_NO_OF_IES*
46 sizeof(proto_IEs));
47
48 value->data[0].val.mme_ue_s1ap_id = g_attachReqRejInfo->ue_idx;
49 value->data[1].val.enb_ue_s1ap_id = g_attachReqRejInfo->s1ap_enb_ue_id;
50
51 log_msg(LOG_INFO, "mme_ue_s1ap_id %d and enb_ue_s1ap_id %d\n",
52 g_attachReqRejInfo->ue_idx, g_attachReqRejInfo->s1ap_enb_ue_id);
53
54 /* TODO: Add enum for security header type */
55 value->data[2].val.nas.header.security_header_type = 0;
56 value->data[2].val.nas.header.proto_discriminator = EPSMobilityManagementMessages;
57 value->data[2].val.nas.header.message_type = AttachReject;
58 value->data[2].val.nas.header.nas_security_param = 0;
59
60#if 0
61 value->data[2].nas.elements = (nas_pdu_elements *)
62 malloc(AUTH_REQ_NO_OF_NAS_IES * sizeof(nas_pdu_elements));
63
64 memcpy(value->data[2].nas.elements[0].rand,
65 g_attachReqRejInfo->rand, NAS_RAND_SIZE);
66 memcpy(value->data[2].nas.elements[1].autn,
67 g_attachReqRejInfo->autn, NAS_AUTN_SIZE);
68#endif
69
70
71 return SUCCESS;
72}
73
74
75/**
76* Stage specific message processing.
77*/
78static int
79s1ap_attach_reject_processing(struct attachReqRej_info *g_attachReqRejInfo)
80{
81 struct Buffer g_buffer;
82 struct Buffer g_value_buffer;
83 struct Buffer g_nas_buffer;
84 struct s1ap_PDU s1apPDU= {0};
85
86
87
88 /* Assigning values to s1apPDU */
89 s1apPDU.procedurecode = id_downlinkNASTransport;
90 s1apPDU.criticality = CRITICALITY_IGNORE;
91
92 get_attachReject_protoie_value(&s1apPDU.value,g_attachReqRejInfo);
93
94 /* Copy values to buffer from s1apPDU */
95
96 g_buffer.pos = 0;
97
98 uint8_t initiating_message = 0; /* TODO: Add enum */
99 buffer_copy(&g_buffer, &initiating_message,
100 sizeof(initiating_message));
101
102 buffer_copy(&g_buffer, &s1apPDU.procedurecode,
103 sizeof(s1apPDU.procedurecode));
104
105 buffer_copy(&g_buffer, &s1apPDU.criticality,
106 sizeof(s1apPDU.criticality));
107
108 /* Copy values in g_value_buffer */
109 g_value_buffer.pos = 0;
110
111 /* TODO remove hardcoded values */
112 unsigned char chProtoIENo[3] = {0,0,3};
113
114 buffer_copy(&g_value_buffer, chProtoIENo, 3);
115
116 unsigned char tmpStr[4];
117
118 /* id-MME-UE-S1AP-ID */
119 uint16_t protocolIe_Id = id_MME_UE_S1AP_ID;
120 copyU16(tmpStr, protocolIe_Id);
121 buffer_copy(&g_value_buffer, tmpStr,
122 sizeof(protocolIe_Id));
123
124 uint8_t protocolIe_criticality = CRITICALITY_REJECT;
125 buffer_copy(&g_value_buffer, &protocolIe_criticality,
126 sizeof(protocolIe_criticality));
127
128 uint8_t datalen = 2;
129
130 /* TODO needs proper handling*/
131 unsigned char mme_ue_id[3];
132 datalen = copyU16(mme_ue_id,
133 s1apPDU.value.data[0].val.mme_ue_s1ap_id);
134 buffer_copy(&g_value_buffer, &datalen, sizeof(datalen));
135 buffer_copy(&g_value_buffer, mme_ue_id, datalen);
136
137 /* id-eNB-UE-S1AP-ID */
138
139 protocolIe_Id = id_eNB_UE_S1AP_ID;
140 copyU16(tmpStr, protocolIe_Id);
141 buffer_copy(&g_value_buffer, tmpStr,
142 sizeof(protocolIe_Id));
143
144 buffer_copy(&g_value_buffer, &protocolIe_criticality,
145 sizeof(protocolIe_criticality));
146
147
148 /* TODO needs proper handling*/
149 unsigned char enb_ue_id[3];
150 datalen = copyU16(enb_ue_id,
151 s1apPDU.value.data[1].val.enb_ue_s1ap_id);
152 buffer_copy(&g_value_buffer, &datalen, sizeof(datalen));
153 buffer_copy(&g_value_buffer, enb_ue_id, datalen);
154
155 /* id-NAS-PDU */
156 protocolIe_Id = id_NAS_PDU;
157 copyU16(tmpStr, protocolIe_Id);
158 buffer_copy(&g_value_buffer, tmpStr,
159 sizeof(protocolIe_Id));
160
161 buffer_copy(&g_value_buffer, &protocolIe_criticality,
162 sizeof(protocolIe_criticality));
163
164 struct nasPDU *nas = &(s1apPDU.value.data[2].val.nas);
165 uint8_t value = (nas->header.security_header_type) |
166 nas->header.proto_discriminator;
167
168 g_nas_buffer.pos = 0;
169
170 buffer_copy(&g_nas_buffer, &value, sizeof(value));
171
172 buffer_copy(&g_nas_buffer, &nas->header.message_type,
173 sizeof(nas->header.message_type));
174
175#if 0
176 buffer_copy(&g_nas_buffer, &nas->header.nas_security_param,
177 sizeof(nas->header.nas_security_param));
178
179#endif
180 value = 0x09; // UE identity can not be derived by the network
181 buffer_copy(&g_nas_buffer, &value, sizeof(value));
182
183#if 0
184 buffer_copy(&g_nas_buffer, &nas->elements[0].pduElement.rand,
185 sizeof(nas->elements[0].pduElement.rand));
186
187 datalen = 16;
188 buffer_copy(&g_nas_buffer, &datalen, sizeof(datalen));
189
190 buffer_copy(&g_nas_buffer, &nas->elements[1].pduElement.autn,
191 sizeof(nas->elements[1].pduElement.autn));
192
193 /* Done with filling NAS message */
194#endif
195 datalen = g_nas_buffer.pos + 1;
196
197 buffer_copy(&g_value_buffer, &datalen,
198 sizeof(datalen));
199
200 buffer_copy(&g_value_buffer, &g_nas_buffer.pos,
201 sizeof(g_nas_buffer.pos));
202
203
204 buffer_copy(&g_value_buffer, &g_nas_buffer,
205 g_nas_buffer.pos);
206
207 buffer_copy(&g_buffer, &g_value_buffer.pos,
208 sizeof(g_value_buffer.pos));
209
210 buffer_copy(&g_buffer, &g_value_buffer,
211 g_value_buffer.pos);
212
213 free(s1apPDU.value.data[2].val.nas.elements);
214 free(s1apPDU.value.data);
215 send_sctp_msg(g_attachReqRejInfo->enb_fd, g_buffer.buf, g_buffer.pos,1);
216 return SUCCESS;
217}
218
219
220void*
221attach_reject_handler(void *data)
222{
223
224 log_msg(LOG_INFO, "S1Ap attach Reject handler ready.\n");
225
226s1ap_attach_reject_processing((struct attachReqRej_info *)data);
227
228
229 return NULL;
230}
231