blob: 60e92d75676ed6bdad6e5a61901dc9dd19be1d69 [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
34extern int g_enb_fd;
35extern s1ap_config g_s1ap_cfg;
36static struct Buffer resp_buf;
37
38int
39create_s1setup_response(/*enb info,*/unsigned char **s1_setup_resp)
40{
41 unsigned char data_len = 0;
42 unsigned char msg[50];
43 struct Buffer proto_ies;
44 struct Buffer gummies;
45 uint16_t proto_ie_id;
46 unsigned char tmp_str[4];
47 uint8_t criticality;
48
49 /*Leave a byte to fill length*/
50 resp_buf.pos = 0;
51 /*Only in case of s1setup resp, first byte is 0x20, not for any other
52 s1ap message. Nothing found in specs, please check.*/
53 /**procedureCode: id-S1Setup (17)**/
54 msg[0] = 0x20;
55 msg[1] = S1AP_SETUP_REQUEST_CODE;
56 msg[2] = CRITICALITY_REJECT;
57 buffer_copy(&resp_buf, msg, 3);
58
59 /**IE1*/
60 /**Item 0: id-MMEname*/
61 proto_ie_id = S1AP_IE_MMENAME;
62 copyU16(tmp_str, proto_ie_id);
63 buffer_copy(&proto_ies, tmp_str, sizeof(proto_ie_id));
64 criticality = CRITICALITY_IGNORE;
65 buffer_copy(&proto_ies, &criticality, sizeof(criticality));
66
67 data_len = strlen(g_s1ap_cfg.mme_name);
68 data_len = copyU16(tmp_str, data_len);
69 tmp_str[1] = tmp_str[1]+2;
70 buffer_copy(&proto_ies, &tmp_str[1], 1);
71 proto_ies.buf[proto_ies.pos++] = 0x06;/*quest: what is this in encoding?*/
72 proto_ies.buf[proto_ies.pos++] = 0x80;
73 buffer_copy(&proto_ies, g_s1ap_cfg.mme_name, strlen(g_s1ap_cfg.mme_name));
74
75 /*IE2*/
76 /**Item 1: id-ServedGUMMEIs*/
77 proto_ie_id = S1AP_IE_SERVED_GUMMEIES;
78 copyU16(tmp_str, proto_ie_id);
79 buffer_copy(&proto_ies, tmp_str, sizeof(proto_ie_id));
80 criticality = CRITICALITY_REJECT;
81 buffer_copy(&proto_ies, &criticality, sizeof(criticality));
82
83 //msg[i++] = 0x0b;//len
84 gummies.buf[0]=0x0;
85 gummies.buf[1]=0x0;
86 gummies.pos = 2;
87
88 /**Item 1: id-ServedGUMMEIs
89 * servedPLMNs: 1 item*/
90 buffer_copy(&gummies, &(g_s1ap_cfg.mme_plmn_id), sizeof(struct PLMN));
91 gummies.buf[gummies.pos++]=0x0;
92 gummies.buf[gummies.pos++]=0x0;
93
94 /**Item 1: id-ServedGUMMEIs
95 * servedGroupIDs: 1 item*/
96 data_len = copyU16(tmp_str, g_s1ap_cfg.mme_group_id);
97 buffer_copy(&gummies, tmp_str, data_len);
98
99 /**Item 1: id-ServedGUMMEIs
100 * servedMMECs: 1 item*/
101 gummies.buf[gummies.pos++]=0x0;
102 gummies.buf[gummies.pos++] = g_s1ap_cfg.mme_code;
103
104 data_len = copyU16(tmp_str, gummies.pos);
105 buffer_copy(&proto_ies, &(tmp_str[1]), 1);
106 buffer_copy(&proto_ies, &gummies.buf, gummies.pos);
107
108 /*IE3*/
109 /**id: id-RelativeMMECapacity (87)*/
110 proto_ie_id = S1AP_IE_REL_MME_CAPACITY;
111 copyU16(tmp_str, proto_ie_id);
112 buffer_copy(&proto_ies, tmp_str, sizeof(proto_ie_id));
113 criticality = CRITICALITY_IGNORE;
114 buffer_copy(&proto_ies, &criticality, sizeof(criticality));
115 data_len = 1;
116 buffer_copy(&proto_ies, &(data_len), 1);
117 g_s1ap_cfg.rel_cap = 1;
118 buffer_copy(&proto_ies, &(g_s1ap_cfg.rel_cap), 1);
119
120 /*number of proto IEs = 3*/
121 data_len = copyU16(tmp_str, 3);
122
123 data_len = data_len + proto_ies.pos + 1;
124 buffer_copy(&resp_buf, &data_len, 1);
125
126 resp_buf.buf[resp_buf.pos++] = 0;/*quest: packed value should be 2 bytes...
127 here it needs 3 bytes*/
128 buffer_copy(&resp_buf, tmp_str, 2);
129
130 buffer_copy(&resp_buf, &proto_ies, proto_ies.pos);
131 *s1_setup_resp = resp_buf.buf;
132
133 return resp_buf.pos;
134}
135
136int
137s1_setup_handler(InitiatingMessage_t *msg, int enb_fd)
138{
139 unsigned char *resp_msg = NULL;
140 int resp_len = 0;
141 /*struct proto_IE s1_init_ies;
142
143 /*****Message structure***
144 */
145 /*parse_IEs(msg+2, &s1_init_ies, S1AP_SETUP_REQUEST_CODE);
146
147 /*Validate all eNB info*/
148
149 /*Add eNB info to hash*/
150
151 /*Create S1Setup response*/
152 resp_len = create_s1setup_response(/*enb info,*/ &resp_msg);
153
154 /*Send S1Setup response*/
155 log_msg(LOG_INFO, "Send s1setup response.\n");
156 resp_len = send_sctp_msg(enb_fd, resp_msg, resp_len, 0);
157 log_msg(LOG_INFO, "send len %d\n", resp_len);
158 //free(resp_msg);
159
160 return SUCCESS;
161}
162