blob: c8aae428416821cded7b2e8624307e936ed2e3c9 [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;
39extern struct time_stat g_attach_stats[];
40
41int
42s1_auth_resp_handler(struct proto_IE *s1_auth_resp_ies)
43{
44 //TODO: use static instead of synamic for perf.
45 struct s1_incoming_msg_data_t auth_resp= {0};
46
47 /*****Message structure***
48 */
49 log_msg(LOG_INFO, "Parse s1ap auth resp message:--\n");
50
51 /*Validate all eNB info*/
52
53 /*Add eNB info to hash*/
54
55 /*Create Q structure for stage 1 to MME.
56 contains init UE information.*/
57 auth_resp.msg_type = auth_response;
58
59 for(int i = 0; i < s1_auth_resp_ies->no_of_IEs; i++)
60 {
61 switch(s1_auth_resp_ies->data[i].IE_type)
62 {
63 case S1AP_IE_MME_UE_ID:
64 {
65 auth_resp.ue_idx = s1_auth_resp_ies->data[i].val.mme_ue_s1ap_id;
66 }break;
67 case S1AP_IE_NAS_PDU:
68 {
69 if(s1_auth_resp_ies->data[i].val.nas.header.message_type != NAS_AUTH_RESP)
70 {
71 auth_resp.msg_data.authresp_Q_msg_m.status = S1AP_AUTH_FAILED;//Error in authentication
72 }
73 else
74 {
75 auth_resp.msg_data.authresp_Q_msg_m.status = SUCCESS;
76 }
77
78 memcpy(&(auth_resp.msg_data.authresp_Q_msg_m.res),
79 &(s1_auth_resp_ies->data[i].val.nas.elements[0].pduElement.auth_resp),
80 sizeof(struct XRES));
81 }break;
82 default:
83 log_msg(LOG_WARNING,"Unhandled IE");
84 }
85 }
86
87 auth_resp.destInstAddr = htonl(mmeAppInstanceNum_c);
88 auth_resp.srcInstAddr = htonl(s1apAppInstanceNum_c);
89
90 //STIMER_GET_CURRENT_TP(g_attach_stats[s1_auth_resp_ies->data[1].enb_ue_s1ap_id].auth_to_mme);
91 send_tipc_message(ipc_S1ap_Hndl, mmeAppInstanceNum_c, (char *)&auth_resp, S1_READ_MSG_BUF_SIZE);
92
93 /*Send S1Setup response*/
94 log_msg(LOG_INFO, "Auth resp send to mme-app stage3.\n");
95
96 //TODO: free IEs
97 return SUCCESS;
98}
99
100int
101s1_auth_fail_handler(struct proto_IE *s1_auth_resp_ies)
102{
103 //TODO: use static instead of synamic for perf.
104 struct s1_incoming_msg_data_t auth_resp;
105
106 /*****Message structure***
107 */
108 log_msg(LOG_INFO, "Parse s1ap auth fail resp:--\n");
109
110 /*Validate all eNB info*/
111
112 /*Add eNB info to hash*/
113
114 /*Create Q structure for stage 1 to MME.
115 contains init UE information.*/
116
117 /* msg_type for auth_failure
118 ?auth_resp.msg_type =?;*/
119 for(int i = 0; i < s1_auth_resp_ies->no_of_IEs; i++)
120 {
121 switch(s1_auth_resp_ies->data[i].IE_type)
122 {
123 case S1AP_IE_MME_UE_ID:
124 {
125 auth_resp.ue_idx = s1_auth_resp_ies->data[i].val.mme_ue_s1ap_id;
126 }break;
127 case S1AP_IE_NAS_PDU:
128 {
129 auth_resp.msg_data.authresp_Q_msg_m.status = S1AP_AUTH_FAILED;//Error in authentication
130 memcpy(&(auth_resp.msg_data.authresp_Q_msg_m.auts),
131 &(s1_auth_resp_ies->data[i].val.nas.elements[0].pduElement.auth_fail_resp),
132 sizeof(struct AUTS));
133 }break;
134 default:
135 log_msg(LOG_WARNING,"Unhandled IE");
136 }
137 }
138
139 auth_resp.destInstAddr = htonl(mmeAppInstanceNum_c);
140 auth_resp.srcInstAddr = htonl(s1apAppInstanceNum_c);
141
142 //STIMER_GET_CURRENT_TP(g_attach_stats[s1_auth_resp_ies->data[1].enb_ue_s1ap_id].auth_to_mme);
143 send_tipc_message(ipc_S1ap_Hndl, mmeAppInstanceNum_c, (char *)&auth_resp, S1_READ_MSG_BUF_SIZE);
144
145 /*Send S1Setup response*/
146 log_msg(LOG_INFO, "Auth resp send to mme-app stage3.\n");
147
148 //TODO: free IEs
149 return SUCCESS;
150}
151