MME2 changes - Propped commits from openmme/paging branch. Added scripts
for code gen
Change-Id: Ie55032217232214ac8544ca76ea34335205329e4
diff --git a/include/s1ap/enb.h b/include/s1ap/enb.h
new file mode 100644
index 0000000..4d976f0
--- /dev/null
+++ b/include/s1ap/enb.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __ENB_H_
+#define __ENB_H_
+
+#endif /*__ENB_H_*/
diff --git a/include/s1ap/main.h b/include/s1ap/main.h
new file mode 100644
index 0000000..089121a
--- /dev/null
+++ b/include/s1ap/main.h
@@ -0,0 +1,112 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * main.h
+ *
+ */
+
+#ifndef MAIN_H_
+#define MAIN_H_
+
+#include <time.h>
+#include <stdint.h>
+
+#include "stimer.h"
+
+#define THREADPOOL_SIZE 10
+
+#define SCTP_BUF_SIZE 1024
+
+/*Timer and stat calculations*/
+struct time_stat {
+ stimer_t init_ue;
+ stimer_t esm_in;
+ stimer_t esm_out;
+ stimer_t auth_in;
+ stimer_t auth_to_mme;
+ stimer_t secreq_in;
+ stimer_t secreq_out;
+ stimer_t secresp_in;
+ stimer_t secresp_to_mme;
+ stimer_t esmreq_in;
+ stimer_t esmreq_out;
+ stimer_t espresp_in;
+ stimer_t espresp_to_mme;
+ stimer_t initctx_out;
+ stimer_t initctx_resp;
+ stimer_t att_done;
+};
+
+void
+*authreq_handler(void *);
+
+void
+*attach_reject_handler(void *);
+
+void
+*idreq_handler(void *);
+
+void
+*secreq_handler(void *);
+
+void
+*esmreq_handler(void *);
+
+void
+*icsreq_handler(void *);
+
+void
+*detach_accept_handler(void *);
+
+void
+*s1_release_command_handler(void *);
+
+void
+*paging_handler(void *);
+
+void
+*ics_req_paging_handler(void *);
+
+void
+*tau_response_handler(void *);
+
+void
+calculate_mac(uint8_t *int_key, uint32_t seq_no, uint8_t direction,
+ uint8_t bearer, uint8_t *data, uint16_t data_len,
+ uint8_t *mac);
+
+typedef long long int stimer_t;
+
+#define STIMER_GET_CURRENT_TP(__now__) \
+ ({ \
+ struct timespec __ts__; \
+ __now__ = clock_gettime(CLOCK_REALTIME,&__ts__) ? \
+ -1 : (((stimer_t)__ts__.tv_sec) * 1000000000) + ((stimer_t)__ts__.tv_nsec); \
+ __now__; \
+ })
+
+#define STIMER_GET_ELAPSED_NS(_start_) \
+ ({ \
+ stimer_t __ns__; \
+ STIMER_GET_CURRENT_TP(__ns__); \
+ if (__ns__ != -1) \
+ __ns__ -= _start_; \
+ __ns__; \
+ })
+
+#endif /* MAIN_H_ */
diff --git a/include/s1ap/options.h b/include/s1ap/options.h
new file mode 100644
index 0000000..50eab87
--- /dev/null
+++ b/include/s1ap/options.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * options.h
+ *
+ */
+
+#ifndef OPTIONS_H_
+#define OPTIONS_H_
+
+#include "s1ap.h"
+
+#define REQ_ARGS 0x0000
+void parse_args(int argc, char **argv);
+void log_buffer_free(char** buffer);
+void convert_imsi_to_bcd_str(uint8_t *src, uint8_t* dest);
+#endif /* OPTIONS_H_ */
diff --git a/include/s1ap/s1ap.h b/include/s1ap/s1ap.h
new file mode 100644
index 0000000..b955a03
--- /dev/null
+++ b/include/s1ap/s1ap.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __S1AP_H_
+#define __S1AP_H_
+
+#include <stdbool.h>
+
+#include "s1ap_structs.h"
+#include "log.h"
+#include "s1ap_ie.h"
+#include "InitiatingMessage.h"
+#include "SuccessfulOutcome.h"
+#include "UnsuccessfulOutcome.h"
+#include "common_proc_info.h"
+
+int
+s1_init_ctx_resp_handler(SuccessfulOutcome_t *msg);
+
+int
+parse_IEs(char *msg, struct proto_IE *proto_ies, unsigned short proc_code);
+
+int convertToInitUeProtoIe(InitiatingMessage_t *msg, struct proto_IE* proto_ies);
+int convertUplinkNasToProtoIe(InitiatingMessage_t *msg, struct proto_IE* proto_ies);
+int convertUeCtxRelReqToProtoIe(InitiatingMessage_t *msg, struct proto_IE* proto_ies);
+int convertInitCtxRspToProtoIe(SuccessfulOutcome_t *msg, struct proto_IE* proto_ies);
+int convertUeCtxRelComplToProtoIe(SuccessfulOutcome_t *msg, struct proto_IE* proto_ies);
+
+int
+s1_setup_handler(InitiatingMessage_t *msg, int enb_fd);
+
+int
+s1_init_ue_handler(struct proto_IE *s1_init_ies, int enb_fd);
+
+void
+handle_s1ap_message(void *message);
+
+int
+init_s1ap();
+
+void
+read_config();
+
+void*
+IAM_handler(void *data);
+
+int s1_esm_resp_handler(struct proto_IE *s1_esm_resp_ies);
+
+int s1_secmode_resp_handler(struct proto_IE *s1_sec_resp_ies);
+
+int s1_auth_resp_handler(struct proto_IE *s1_auth_resp_ies);
+
+int s1_auth_fail_handler(struct proto_IE *s1_auth_resp_ies);
+
+int s1_identity_resp_handler(struct proto_IE *s1_id_resp_ies);
+
+int s1_attach_complete_handler(struct proto_IE *s1_esm_resp_ies);
+
+int
+detach_stage1_handler(struct proto_IE *detach_ies, bool retransmit);
+
+int
+s1_init_ue_service_req_handler(struct proto_IE *service_req_ies, int enb_fd);
+
+int
+tau_request_handler(struct proto_IE *s1_tau_req_ies, int enb_fd);
+
+int
+s1_ctx_release_resp_handler(SuccessfulOutcome_t *msg);
+
+int
+s1_ctx_release_request_handler(InitiatingMessage_t *msg);
+
+int
+s1_ctx_release_complete_handler(SuccessfulOutcome_t *msg);
+
+int
+detach_accept_from_ue_handler(struct proto_IE *detach_ies, bool retransmit);
+
+int s1ap_mme_encode_ue_context_release_command(
+ struct s1ap_common_req_Q_msg *s1apPDU,
+ uint8_t **buffer, uint32_t *length);
+
+int s1ap_mme_encode_paging_request(
+ struct s1ap_common_req_Q_msg *s1apPDU,
+ uint8_t **buffer, uint32_t *length);
+
+int s1ap_mme_encode_initiating(
+ struct s1ap_common_req_Q_msg *s1apPDU,
+ uint8_t **buffer, uint32_t *length);
+
+int s1ap_mme_encode_initial_context_setup_request(
+ struct s1ap_common_req_Q_msg *s1apPDU,
+ uint8_t **buffer, uint32_t *length);
+
+int
+s1ap_mme_decode_initiating (InitiatingMessage_t *initiating_p, int enb_fd);
+
+int
+s1ap_mme_decode_successfull_outcome (SuccessfulOutcome_t *initiating_p);
+
+int
+s1ap_mme_decode_unsuccessfull_outcome (UnsuccessfulOutcome_t *initiating_p);
+
+int
+copyU16(unsigned char *buffer, uint32_t val);
+
+int
+send_sctp_msg(int connSock, unsigned char *buffer, size_t len, uint16_t stream_no);
+
+void
+buffer_copy(struct Buffer *buffer, void *value, size_t size);
+
+/**
+ * @brief Decode int value from the byte array received in the s1ap incoming
+ * packet.
+ * @param[in] bytes - Array of bytes in packet
+ * @param[in] len - Length of the bytes array from which to extract the int
+ * @return Integer value extracted out of bytes array. 0 if failed.
+ */
+int
+decode_int_val(unsigned char *bytes, short len);
+
+char*
+msg_to_hex_str(const char *msg, int len, char **buffer);
+
+unsigned short
+get_length(char **msg);
+#endif /*__S1AP_H_*/
diff --git a/include/s1ap/s1ap_config.h b/include/s1ap/s1ap_config.h
new file mode 100644
index 0000000..5f18140
--- /dev/null
+++ b/include/s1ap/s1ap_config.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __S1AP_CONFIG_H_
+#define __S1AP_CONFIG_H_
+
+#include <stdbool.h>
+#include "s1ap_structs.h"
+
+#define MME_NAME_LEN 256
+
+/**
+ * s1ap interface configuration parameters
+ */
+typedef struct s1ap_config
+{
+ unsigned short sctp_port;
+ unsigned short enb_port;
+ unsigned int enb_ip;
+ char *mme_name;
+ unsigned int s1ap_local_ip;
+ unsigned short mme_group_id;
+ unsigned short max_enbs_cnt;
+ unsigned char rel_cap;
+ unsigned char mme_code;
+ char sctp_type; /* sctp, udp */
+ struct PLMN mme_plmn_id;
+ struct PLMN target_mme_plmn_id;
+} s1ap_config;
+
+void
+init_parser(char *path);
+
+int
+parse_s1ap_conf();
+
+#endif /*__S1AP_CONFIG_H_*/
diff --git a/include/s1ap/s1ap_ie.h b/include/s1ap/s1ap_ie.h
new file mode 100644
index 0000000..f93a461
--- /dev/null
+++ b/include/s1ap/s1ap_ie.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __S1AP_IE_H_
+#define __S1AP_IE_H_
+
+#include "s1ap_msg_codes.h"
+#include "s1ap_structs.h"
+
+
+#define S1AP_INITUE_IEs 5
+
+/*** IE parsing functions ***/
+typedef void * (ie_parser_function)(char *msg, int len);
+
+//ie_parser_function ie_parser[32];//={};
+
+void* ie_parse_global_enb_id(char *msg, int len);
+void* ie_parse_enb_name(char *msg, int len);
+void* ie_parse_supported_TAs(char *msg, int len);
+void* ie_parse_pagins_DRX(char *msg, int len);
+
+/*** IE parsing functions end***/
+
+#endif /*S1AP_IE_H_*/
diff --git a/include/s1ap/s1ap_msg_codes.h b/include/s1ap/s1ap_msg_codes.h
new file mode 100644
index 0000000..67ca2c9
--- /dev/null
+++ b/include/s1ap/s1ap_msg_codes.h
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __S1AP_MSG_CODES_H_
+#define __S1AP_MSG_CODES_H_
+
+/****S1AP Procedude codes****/
+#define S1AP_SETUP_REQUEST_CODE 17
+#define S1AP_INITIAL_UE_MSG_CODE 12
+#define S1AP_UE_CONTEXT_RELEASE_REQUEST_CODE 18
+#define S1AP_UE_CONTEXT_RELEASE_CODE 23
+/*uplink NAS Transport*/
+#define S1AP_UL_NAS_TX_MSG_CODE 13
+#define S1AP_INITIAL_CTX_RESP_CODE 9
+
+/*S1AP Protocol IE types*/
+#define S1AP_IE_GLOBAL_ENB_ID 59
+#define S1AP_IE_ENB_NAME 60
+#define S1AP_IE_SUPPORTED_TAS 64
+#define S1AP_IE_DEF_PAGING_DRX 137
+#define S1AP_IE_MMENAME 61
+#define S1AP_IE_SERVED_GUMMEIES 105
+#define S1AP_IE_REL_MME_CAPACITY 87
+
+#define S1AP_IE_MME_UE_ID 0
+#define S1AP_IE_CAUSE 2
+#define S1AP_IE_ENB_UE_ID 8
+#define S1AP_IE_NAS_PDU 26
+#define S1AP_IE_TAI 67
+#define S1AP_IE_UTRAN_CGI 100
+#define S1AP_IE_S_TMSI 96
+#define S1AP_IE_RRC_EST_CAUSE 134
+#define S1AP_ERAB_SETUP_CTX_SUR 51
+
+/*NAS message type codes*/
+#define NAS_ESM_RESP 0xda
+#define NAS_AUTH_RESP 0x53
+#define NAS_AUTH_REJECT 0x54
+#define NAS_AUTH_FAILURE 0x5c
+#define NAS_IDENTITY_REQUEST 0x55
+#define NAS_IDENTITY_RESPONSE 0x56
+#define NAS_SEC_MODE_COMPLETE 0x5e
+#define NAS_SEC_MODE_REJECT 0x5f
+#define NAS_ATTACH_REQUEST 0x41
+#define NAS_ATTACH_COMPLETE 0x43
+#define NAS_ATTACH_REJECT 0x44
+#define NAS_TAU_REQUEST 0x48
+#define NAS_TAU_COMPLETE 0x4
+#define NAS_DETACH_REQUEST 0x45
+#define NAS_DETACH_ACCEPT 0x46
+#define NAS_SERVICE_REQUEST 0x4D
+
+#endif /*__S1AP_MSG_CODES*/
diff --git a/include/s1ap/sctp_conn.h b/include/s1ap/sctp_conn.h
new file mode 100644
index 0000000..be9a9e0
--- /dev/null
+++ b/include/s1ap/sctp_conn.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2003-2018, Great Software Laboratory Pvt. Ltd.
+ * Copyright (c) 2017 Intel Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __S1AP_SCTP_CONN_H_
+#define __S1AP_SCTP_CONN_H_
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netinet/sctp.h>
+
+#define MAX_STREAM 5
+#define MAX_PENDING_CONN 5
+#define ENB_PORT 62324
+
+int create_sctp_socket(unsigned int remote_ip, unsigned short port);
+
+int accept_sctp_socket(int sockfd);
+
+int recv_sctp_msg(int sockfd, unsigned char *buf, size_t len);
+
+int send_sctp_msg(int connSock, unsigned char *buffer, size_t len, uint16_t stream_no);
+
+int close_sctp_socket(int sockfd);
+
+#endif /*__S1AP_SCTP_CONN_H*/