From 0dbddb8a4bf2f42f93a0ef63a19997a8c6d113aa Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Fri, 20 Oct 2017 11:45:45 +0100 Subject: [PATCH] Finished separating the pack/unpack from the main S1AP class. --- srsepc/hdr/mme/s1ap.h | 21 +++-- srsepc/hdr/mme/s1ap_mngmt_proc.h | 21 +---- srsepc/src/mme/s1ap.cc | 124 ++++++++---------------------- srsepc/src/mme/s1ap_mngmt_proc.cc | 27 ++++--- 4 files changed, 59 insertions(+), 134 deletions(-) diff --git a/srsepc/hdr/mme/s1ap.h b/srsepc/hdr/mme/s1ap.h index 9b3c546c6..d8e347661 100644 --- a/srsepc/hdr/mme/s1ap.h +++ b/srsepc/hdr/mme/s1ap.h @@ -37,22 +37,13 @@ #include #include +#include "mme/s1ap_common.h" #include "mme/s1ap_mngmt_proc.h" namespace srsepc{ const uint16_t S1MME_PORT = 36412; -typedef struct{ - uint8_t mme_code; - uint16_t mme_group; - uint16_t tac; // 16-bit tac - uint16_t mcc; // BCD-coded with 0xF filler - uint16_t mnc; // BCD-coded with 0xF filler - std::string mme_bind_addr; - std::string mme_name; -} s1ap_args_t; - class s1ap { public: @@ -73,18 +64,24 @@ public: bool send_s1_setup_failure(struct sctp_sndrcvinfo *enb_sri); bool send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri); + + void print_enb_ctx_info(const enb_ctx_t &enb_ctx); private: + + s1ap_args_t m_s1ap_args; + uint32_t m_plmn; + /* uint8_t m_mme_code; uint16_t m_mme_group; uint16_t m_tac; // 16-bit tac uint16_t m_mcc; // BCD-coded with 0xF filler uint16_t m_mnc; // BCD-coded with 0xF filler uint32_t m_plmn; - + std::string m_mme_bind_addr; std::string m_mme_name; - + */ srslte::log *m_s1ap_log; int m_s1mme; diff --git a/srsepc/hdr/mme/s1ap_mngmt_proc.h b/srsepc/hdr/mme/s1ap_mngmt_proc.h index c70c918bc..53c74f9eb 100644 --- a/srsepc/hdr/mme/s1ap_mngmt_proc.h +++ b/srsepc/hdr/mme/s1ap_mngmt_proc.h @@ -28,24 +28,9 @@ #include "srslte/asn1/liblte_s1ap.h" #include "srslte/common/common.h" -namespace srsepc{ - -static const uint8_t MAX_TA=255; -static const uint8_t MAX_BPLMN=6; +#include "mme/s1ap_common.h" -typedef struct{ - bool enb_name_present; - uint32_t enb_id; - uint8_t enb_name[150]; - uint16_t mcc, mnc; - uint32_t plmn; - uint8_t nof_supported_ta; - uint16_t tac[MAX_TA]; - uint8_t nof_supported_bplmns[MAX_TA]; - uint16_t bplmns[MAX_TA][MAX_BPLMN]; - LIBLTE_S1AP_PAGINGDRX_ENUM drx; - struct sctp_sndrcvinfo sri; -} enb_ctx_t; +namespace srsepc{ class s1ap_mngmt_proc { @@ -55,7 +40,7 @@ public: bool unpack_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, enb_ctx_t* enb_ctx); bool pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte::byte_buffer_t* msg); - bool pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu); + bool pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buffer_t* msg); }; } //namespace srsepc diff --git a/srsepc/src/mme/s1ap.cc b/srsepc/src/mme/s1ap.cc index 58a2185ce..765a0646e 100644 --- a/srsepc/src/mme/s1ap.cc +++ b/srsepc/src/mme/s1ap.cc @@ -43,6 +43,7 @@ s1ap::~s1ap() int s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log) { + /* m_mme_code = s1ap_args.mme_code ; m_mme_group = s1ap_args.mme_group; m_tac = s1ap_args.tac; @@ -50,8 +51,10 @@ s1ap::init(s1ap_args_t s1ap_args, srslte::log *s1ap_log) m_mnc = s1ap_args.mnc; m_mme_bind_addr = s1ap_args.mme_bind_addr; m_mme_name = std::string("srsmme0"); + */ + m_s1ap_args = s1ap_args; - srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &m_plmn); + srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &m_plmn); m_s1ap_log = s1ap_log; @@ -101,7 +104,7 @@ s1ap::enb_listen() //S1-MME bind bzero(&s1mme_addr, sizeof(s1mme_addr)); s1mme_addr.sin_family = AF_INET; - inet_pton(AF_INET, m_mme_bind_addr.c_str(), &(s1mme_addr.sin_addr) ); + inet_pton(AF_INET, m_s1ap_args.mme_bind_addr.c_str(), &(s1mme_addr.sin_addr) ); s1mme_addr.sin_port = htons(S1MME_PORT); err = bind(sock_fd, (struct sockaddr*) &s1mme_addr, sizeof (s1mme_addr)); if (err != 0){ @@ -182,120 +185,61 @@ s1ap::handle_s1_setup_request(LIBLTE_S1AP_MESSAGE_S1SETUPREQUEST_STRUCT *msg, st } //Log S1 Setup Request Info - if(enb_ctx.enb_name_present) - { - m_s1ap_log->console("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id); - m_s1ap_log->info("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id); - } - else - { - m_s1ap_log->console("S1 Setup Request - eNB Id 0x%x\n", enb_ctx.enb_id); - m_s1ap_log->info("S1 Setup request - eNB Id 0x%x\n", enb_ctx.enb_id); - } - srslte::mcc_to_string(enb_ctx.mcc, &mcc_str); - srslte::mnc_to_string(enb_ctx.mnc, &mnc_str); - m_s1ap_log->info("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); - m_s1ap_log->console("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); - for(int i=0;iinfo("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]); - m_s1ap_log->console("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]); - } - } - m_s1ap_log->console("S1 Setup Request - Paging DRX %d\n",enb_ctx.drx); + print_enb_ctx_info(enb_ctx); //Check matching PLMNs if(enb_ctx.plmn!=m_plmn){ m_s1ap_log->console("S1 Setup Failure - Unkown PLMN\n"); m_s1ap_log->info("S1 Setup Failure - Unkown PLMN\n"); m_s1ap_mngmt_proc.pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_UNKNOWN_PLMN,&reply_msg); - ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0); //FIXME } else{ m_s1ap_log->console("S1 Setup Response\n"); m_s1ap_log->info("S1 Setup Response\n"); - //m_s1ap_mngmt_proc.pack_s1_setup_response(,&reply_msg); - send_s1_setup_response(enb_sri); + m_s1ap_mngmt_proc.pack_s1_setup_response(m_s1ap_args, &reply_msg); } //Send Reply to eNB - /* - ssize_t n_sent = sctp_send(m_s1mme,msg.msg, msg.N_bytes, enb_sri, 0); + ssize_t n_sent = sctp_send(m_s1mme,reply_msg.msg, reply_msg.N_bytes, enb_sri, 0); if(n_sent == -1) { m_s1ap_log->console("Failed to send S1 Setup Setup Reply"); return false; } - */ + return true; } -bool -s1ap::send_s1_setup_response(struct sctp_sndrcvinfo *enb_sri) +void +s1ap::print_enb_ctx_info(const enb_ctx_t &enb_ctx) { - srslte::byte_buffer_t msg; - LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; - bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); - - pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME; - - LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu.choice.successfulOutcome; - succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP; - succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE; - succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE; - - LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT* s1_resp=(LIBLTE_S1AP_MESSAGE_S1SETUPRESPONSE_STRUCT*)&succ->choice; - - s1_resp->ext=false; - - //MME Name - s1_resp->MMEname_present=true; - s1_resp->MMEname.ext=false; - s1_resp->MMEname.n_octets=m_mme_name.length(); - memcpy(s1_resp->MMEname.buffer,m_mme_name.c_str(),m_mme_name.length()); - - //Served GUMEIs - s1_resp->ServedGUMMEIs.len=1;//TODO Only one served GUMMEI supported - LIBLTE_S1AP_SERVEDGUMMEISITEM_STRUCT *serv_gummei = &s1_resp->ServedGUMMEIs.buffer[0]; - - serv_gummei->ext=false; - //serv_gummei->iE_Extensions=false; - - uint32_t plmn=0; - srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &plmn); - plmn=htonl(plmn); - serv_gummei->servedPLMNs.len = 1; //Only one PLMN supported - serv_gummei->servedPLMNs.buffer[0].buffer[0]=((uint8_t*)&plmn)[1]; - serv_gummei->servedPLMNs.buffer[0].buffer[1]=((uint8_t*)&plmn)[2]; - serv_gummei->servedPLMNs.buffer[0].buffer[2]=((uint8_t*)&plmn)[3]; - - serv_gummei->servedGroupIDs.len=1; //LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT - uint16_t tmp=htons(m_mme_group); - serv_gummei->servedGroupIDs.buffer[0].buffer[0]=((uint8_t*)&tmp)[0]; - serv_gummei->servedGroupIDs.buffer[0].buffer[1]=((uint8_t*)&tmp)[1]; - - serv_gummei->servedMMECs.len=1; //Only one MMEC served - serv_gummei->servedMMECs.buffer[0].buffer[0]=m_mme_code; - - //Relative MME Capacity - s1_resp->RelativeMMECapacity.RelativeMMECapacity=255; + std::string mnc_str, mcc_str; - //Relay Unsupported - s1_resp->MMERelaySupportIndicator_present=false; - - liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg); - - ssize_t n_sent = sctp_send(m_s1mme,msg.msg, msg.N_bytes, enb_sri, 0); - - if(n_sent == -1) + if(enb_ctx.enb_name_present) { - m_s1ap_log->console("Failed to send S1 Setup Failure"); - return false; + m_s1ap_log->console("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id); + m_s1ap_log->info("S1 Setup Request - eNB Name: %s, eNB id: 0x%x\n", enb_ctx.enb_name, enb_ctx.enb_id); } - return true; + else + { + m_s1ap_log->console("S1 Setup Request - eNB Id 0x%x\n", enb_ctx.enb_id); + m_s1ap_log->info("S1 Setup request - eNB Id 0x%x\n", enb_ctx.enb_id); + } + srslte::mcc_to_string(enb_ctx.mcc, &mcc_str); + srslte::mnc_to_string(enb_ctx.mnc, &mnc_str); + m_s1ap_log->info("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); + m_s1ap_log->console("S1 Setup Request - MCC:%s, MNC:%s, PLMN: %d\n", mcc_str.c_str(), mnc_str.c_str(), enb_ctx.plmn); + for(int i=0;iinfo("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]); + m_s1ap_log->console("S1 Setup Request - TAC %d, B-PLMN %d\n",enb_ctx.tac[i],enb_ctx.bplmns[i][j]); + } + } + m_s1ap_log->console("S1 Setup Request - Paging DRX %d\n",enb_ctx.drx); + return; } } //namespace srsepc diff --git a/srsepc/src/mme/s1ap_mngmt_proc.cc b/srsepc/src/mme/s1ap_mngmt_proc.cc index be66399cc..3a4768bc1 100644 --- a/srsepc/src/mme/s1ap_mngmt_proc.cc +++ b/srsepc/src/mme/s1ap_mngmt_proc.cc @@ -123,16 +123,15 @@ s1ap_mngmt_proc::pack_s1_setup_failure(LIBLTE_S1AP_CAUSEMISC_ENUM cause, srslte: bool -s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) +s1ap_mngmt_proc::pack_s1_setup_response(s1ap_args_t s1ap_args, srslte::byte_buffer_t *msg) { -/* - srslte::byte_buffer_t msg; - //LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; - bzero(pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); - pdu->choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME; + LIBLTE_S1AP_S1AP_PDU_STRUCT pdu; + bzero(&pdu, sizeof(LIBLTE_S1AP_S1AP_PDU_STRUCT)); + + pdu.choice_type = LIBLTE_S1AP_S1AP_PDU_CHOICE_SUCCESSFULOUTCOME; - LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu->choice.successfulOutcome; + LIBLTE_S1AP_SUCCESSFULOUTCOME_STRUCT *succ = &pdu.choice.successfulOutcome; succ->procedureCode = LIBLTE_S1AP_PROC_ID_S1SETUP; succ->criticality = LIBLTE_S1AP_CRITICALITY_IGNORE; succ->choice_type = LIBLTE_S1AP_SUCCESSFULOUTCOME_CHOICE_S1SETUPRESPONSE; @@ -144,8 +143,8 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) //MME Name s1_resp->MMEname_present=true; s1_resp->MMEname.ext=false; - s1_resp->MMEname.n_octets=m_mme_name.length(); - memcpy(s1_resp->MMEname.buffer,m_mme_name.c_str(),m_mme_name.length()); + s1_resp->MMEname.n_octets=s1ap_args.mme_name.length(); + memcpy(s1_resp->MMEname.buffer,s1ap_args.mme_name.c_str(),s1ap_args.mme_name.length()); //Served GUMEIs s1_resp->ServedGUMMEIs.len=1;//TODO Only one served GUMMEI supported @@ -155,7 +154,7 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) //serv_gummei->iE_Extensions=false; uint32_t plmn=0; - srslte::s1ap_mccmnc_to_plmn(m_mcc, m_mnc, &plmn); + srslte::s1ap_mccmnc_to_plmn(s1ap_args.mcc, s1ap_args.mnc, &plmn); plmn=htonl(plmn); serv_gummei->servedPLMNs.len = 1; //Only one PLMN supported serv_gummei->servedPLMNs.buffer[0].buffer[0]=((uint8_t*)&plmn)[1]; @@ -163,12 +162,12 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) serv_gummei->servedPLMNs.buffer[0].buffer[2]=((uint8_t*)&plmn)[3]; serv_gummei->servedGroupIDs.len=1; //LIBLTE_S1AP_SERVEDGROUPIDS_STRUCT - uint16_t tmp=htons(m_mme_group); + uint16_t tmp=htons(s1ap_args.mme_group); serv_gummei->servedGroupIDs.buffer[0].buffer[0]=((uint8_t*)&tmp)[0]; serv_gummei->servedGroupIDs.buffer[0].buffer[1]=((uint8_t*)&tmp)[1]; serv_gummei->servedMMECs.len=1; //Only one MMEC served - serv_gummei->servedMMECs.buffer[0].buffer[0]=m_mme_code; + serv_gummei->servedMMECs.buffer[0].buffer[0]=s1ap_args.mme_code; //Relative MME Capacity s1_resp->RelativeMMECapacity.RelativeMMECapacity=255; @@ -176,8 +175,8 @@ s1ap_mngmt_proc::pack_s1_setup_response(LIBLTE_S1AP_S1AP_PDU_STRUCT *pdu) //Relay Unsupported s1_resp->MMERelaySupportIndicator_present=false; - liblte_s1ap_pack_s1ap_pdu(pdu, (LIBLTE_BYTE_MSG_STRUCT*)&msg); -*/ + liblte_s1ap_pack_s1ap_pdu(&pdu, (LIBLTE_BYTE_MSG_STRUCT*)msg); + return true; }