Commit 89d1be31 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

polish the code

parent 3a113978
/**
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
* Nsmf_PDUSession
* SMF PDU Session Service. © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* The version of the OpenAPI document: 1.1.0.alpha-1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "SMContextsCollectionApiImpl.h"
#include "logger.hpp"
......@@ -17,8 +17,6 @@
extern "C" {
#include "nas_message.h"
#include "mmData.h"
//#include "common_types.h"
//#include "common_defs.h"
}
namespace oai {
......@@ -28,15 +26,18 @@ namespace api {
using namespace oai::smf::model;
SMContextsCollectionApiImpl::SMContextsCollectionApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr, pgwc::pgw_app *smf_app_inst)
: SMContextsCollectionApi(rtr), m_smf_app(smf_app_inst)
: SMContextsCollectionApi(rtr), m_smf_app(smf_app_inst)
{ }
{ }
void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smContextMessage, Pistache::Http::ResponseWriter &response) {
Logger::smf_api_server().info("post_sm_contexts...");
//decode NAS message and assign the necessary informations to pgwc::pdu_session_create_sm_context_request and pass to SMF to handle this message
//decode NAS message and assign the necessary informations to pgwc::pdu_session_create_sm_context_request
//and pass this message to SMF to handle this message
//step 1. Decode NAS message (for instance, ... only served as an example)
nas_message_decode_status_t decode_status = {0};
nas_message_t decoded_nas_msg;
memset (&decoded_nas_msg, 0, sizeof (nas_message_t));
......@@ -61,7 +62,7 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
security->selected_algorithms.integrity = NAS_SECURITY_ALGORITHMS_NIA1;
security->knas_int[0] = 0x41;
//decode message
//decode the NAS message (using NAS lib)
decoder_rc = nas_message_decode (data, &decoded_nas_msg, sizeof(data), security, &decode_status);
Logger::smf_api_server().debug("nas header decode extended_protocol_discriminator %d, security_header_type:%d,sequence_number:%d,message_authentication_code:%d\n",
......@@ -70,7 +71,7 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
decoded_nas_msg.header.sequence_number,
decoded_nas_msg.header.message_authentication_code);
//Get the value from AMF
//Step 2. Create a pdu_session_create_sm_context_request message and store the necessary information
pgwc::pdu_session_create_sm_context_request *sm_context_req = new pgwc::pdu_session_create_sm_context_request();
std::shared_ptr<pgwc::pdu_session_create_sm_context_request> sm_context_req_msg = std::shared_ptr<pgwc::pdu_session_create_sm_context_request>(sm_context_req);
......@@ -101,12 +102,15 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
//Subscription for PDU Session Status Notification
// Trace requirement
//From N1 Container (NAS)
//Extended protocol discriminator (Mandatory)
sm_context_req_msg->set_epd(decoded_nas_msg.header.extended_protocol_discriminator);
//PDU session ID (Mandatory)
//TODO:
//PTI (Mandatory)
//TODO:
//Message type (Mandatory) (PDU SESSION ESTABLISHMENT REQUEST message identity)
sm_context_req_msg->set_message_type(decoded_nas_msg.plain.sm.pdu_session_establishment_request.messagetype);
//Integrity protection maximum data rate (Mandatory)
//PDU session type (Optional)
//SSC mode (Optional)
......@@ -117,20 +121,9 @@ void SMContextsCollectionApiImpl::post_sm_contexts(const SmContextMessage &smCon
//SM PDU DN request container (Optional)
//Extended protocol configuration options (Optional) e.g, FOR DHCP
sm_context_req_msg->set_dnn_selection_mode(smContextCreateData.getSelMode());
//handle the message from pwg_app
//Step 3. Handle the pdu_session_create_sm_context_request message in pwg_app
m_smf_app->handle_amf_msg(sm_context_req_msg, response);
/*
//move the response part to pgw_app
//step 3. send reply to AMF
nlohmann::json jsonData;
to_json(jsonData, smContextCreatedData);
std::string resBody = jsonData.dump();
response.headers().add<Pistache::Http::Header::Location>(url);
response.send(Pistache::Http::Code::Ok, resBody);
*/
}
}
......
......@@ -25,10 +25,16 @@
typedef enum extended_protocol_discriminator_e {
/* Protocol discriminator identifier for 5G Session Management */
FIVEGS_SESSION_MANAGEMENT_MESSAGES = 0x2e,
EPD_5GS_SESSION_MANAGEMENT_MESSAGES = 0x2e,
/* Protocol discriminator identifier for 5G Mobility Management */
FIVEGS_MOBILITY_MANAGEMENT_MESSAGES = 0x7e,
EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES = 0x7e,
} extended_protocol_discriminator_t;
// Integrity protection maximum data rate
typedef struct ipmdr_s {
uint8_t ul;
uint8_t dl;
} ipmdr_t;
#endif
#ifndef FILE_3GPP_24_501_H_SEEN
#define FILE_3GPP_24_501_H_SEEN
//#include <stdint.h>
//#include <stdbool.h>
// 9.3.1 Security header type
#define SECURITY_HEADER_TYPE_NOT_PROTECTED 0b0000
#define SECURITY_HEADER_TYPE_INTEGRITY_PROTECTED 0b0001
......@@ -613,6 +610,23 @@
//0b11******
//5GS Session Management Messages
typedef enum pdu_session_message_e {
PDU_SESSION_ESTABLISHMENT_REQUEST = 193,
PDU_SESSION_ESTABLISHMENT_ACCEPT = 194,
PDU_SESSION_ESTABLISHMENT_REJECT = 195,
PDU_SESSION_AUTHENTICATION_COMMAND = 197,
PDU_SESSION_AUTHENTICATION_COMPLETE = 198,
PDU_SESSION_AUTHENTICATION_RESULT = 199,
PDU_SESSION_MODIFICATION_REQUEST = 201,
PDU_SESSION_MODIFICATION_REJECT = 202,
PDU_SESSION_MODIFICATION_COMMAND = 203,
PDU_SESSION_MODIFICATION_COMPLETE = 204,
PDU_SESSION_MODIFICATION_COMMAND_REJECT = 205,
PDU_SESSION_RELEASE_REQUEST = 209,
PDU_SESSION_RELEASE_REJECT = 210,
PDU_SESSION_RELEASE_COMMAND = 211,
PDU_SESSION_RELEASE_COMPLETE = 212
};
#define PDUSessionEstablishmentRequest 0b11000001
#define PDUSessionEstablishmentAccept 0b11000010
......
This diff is collapsed.
#ifndef FILE_MM_DATA_H_SEEN
#define FILE_MM_DATA_H_SEEN
//#include "bstrlib.h"
#include "common_types.h"
#include "securityDef.h"
......@@ -44,4 +43,5 @@ typedef struct fivegmm_security_context_s {
uint8_t activated;
} fivegmm_security_context_t;
#endif
......@@ -156,7 +156,7 @@ _fivegmm_msg_encode_header (
/*
* Check the protocol discriminator
*/
if (header->extended_protocol_discriminator != FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->extended_protocol_discriminator != EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
//OAILOG_ERROR (LOG_NAS_EMM, "ESM-MSG - Unexpected protocol discriminator: 0x%x\n", header->extended_protocol_discriminator);
return (TLV_PROTOCOL_NOT_SUPPORTED);
}
......@@ -290,7 +290,7 @@ _fivegmm_msg_decode_header (
/*
* Check the protocol discriminator
*/
if (header->extended_protocol_discriminator != FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->extended_protocol_discriminator != EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
//OAILOG_ERROR (LOG_NAS_EMM, "ESM-MSG - Unexpected protocol discriminator: 0x%x\n", header->protocol_discriminator);
return (TLV_PROTOCOL_NOT_SUPPORTED);
}
......
......@@ -348,8 +348,8 @@ static int _nas_message_header_encode (
//printf("encoded nas security header type: %x\n",buffer[size-1]);
//printf("encoded nas security header type: %x\n",header->security_header_type);
if (header->extended_protocol_discriminator == FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
//printf("header->extended_protocol_discriminator == FIVEGS_MOBILITY_MANAGEMENT_MESSAGES\n");
if (header->extended_protocol_discriminator == EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
//printf("header->extended_protocol_discriminator == EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES\n");
//printf("%x\n",header->security_header_type);
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED) {
//printf("header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED\n");
......@@ -467,7 +467,7 @@ static int _nas_message_plain_encode (
//OAILOG_FUNC_IN (LOG_NAS);
int bytes = TLV_PROTOCOL_NOT_SUPPORTED;
if (header->extended_protocol_discriminator == FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->extended_protocol_discriminator == EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
/*
* Encode EPS Mobility Management L3 message
*/
......@@ -475,7 +475,7 @@ static int _nas_message_plain_encode (
bytes = fivegmm_msg_encode ((MM_msg *) (&msg->mm), (uint8_t *) buffer, length);
//printf("fivegmm_msg_encode bytes:%d\n", bytes);
//printf("Encode EPS Mobility Management L3 message 1.2.1.1.2\n");
} else if (header->extended_protocol_discriminator == FIVEGS_SESSION_MANAGEMENT_MESSAGES) {
} else if (header->extended_protocol_discriminator == EPD_5GS_SESSION_MANAGEMENT_MESSAGES) {
/*
* Encode EPS Session Management L3 message
*/
......@@ -754,7 +754,7 @@ static int _nas_message_header_decode (
DECODE_U8 (buffer + size, header->security_header_type , size);
//OAILOG_DEBUG(LOG_NAS,"security header type(%x)\n",header->security_header_type&0x0f);
*is_sr = false;
if (header->extended_protocol_discriminator == FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->extended_protocol_discriminator == EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->security_header_type != SECURITY_HEADER_TYPE_NOT_PROTECTED) {
if (status) {
switch (header->security_header_type) {
......@@ -1005,14 +1005,14 @@ static int _nas_message_plain_decode (
//OAILOG_FUNC_IN (LOG_NAS);
int bytes = TLV_PROTOCOL_NOT_SUPPORTED;
//printf("_nas_message_plain_decode extended_protocol_discriminator:%0x\n", header->extended_protocol_discriminator);
if (header->extended_protocol_discriminator == FIVEGS_MOBILITY_MANAGEMENT_MESSAGES) {
if (header->extended_protocol_discriminator == EPD_5GS_MOBILITY_MANAGEMENT_MESSAGES) {
/*
* Decode 5G Mobility Management L3 message
*/
//printf("calling mm_msg_decode\n");
bytes = mm_msg_decode (&msg->mm, (uint8_t *) buffer, length);
//printf("mm_msg_decode bytes:%d\n", bytes);
} else if (header->extended_protocol_discriminator == FIVEGS_SESSION_MANAGEMENT_MESSAGES) {
} else if (header->extended_protocol_discriminator == EPD_5GS_SESSION_MANAGEMENT_MESSAGES) {
/*
* Decode 5G Session Management L3 message
*/
......
This diff is collapsed.
......@@ -707,10 +707,7 @@ void pgw_app::handle_amf_msg(std::shared_ptr<pdu_session_create_sm_context_reque
Logger::pgwc_app().debug("Handle AMF message, supi " SUPI_64_FMT " ", supi64);
//pdu_session_establishment_request_msg pdu_session_establishment_request = sm_context_req_msg->get_nas_msg() ;
//pdu_session_type_t pdu_session_type = {.pdu_session_type = (uint8_t)pdu_session_establishment_request._pdusessiontype};
pdu_session_type_t pdu_session_type = {.pdu_session_type = 0}; //to be removed
pdu_session_type_t pdu_session_type = {.pdu_session_type = sm_context_req_msg->get_pdu_session_type()};
Logger::pgwc_app().debug("Handle AMF message, _pdusessiontype: %d", pdu_session_type.pdu_session_type);
//Step 2. check if the DNN requested is valid
......
......@@ -985,23 +985,18 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
Logger::pgwc_app().info("Handle AMF message");
oai::smf::model::SmContextCreateError smContextCreateError;
oai::smf::model::ProblemDetails problem_details;
bool request_accepted = true;
//Step 1. get necessary information
Logger::pgwc_app().debug("Handle AMF message, supi " SUPI_64_FMT " ", sm_context_req_msg->get_supi());
std::string dnn = sm_context_req_msg->get_dnn();
//oai::smf::model::Snssai snssai_sm = smContextCreateData.getSNssai();
snssai_t snssai = sm_context_req_msg->get_snssai();
std::string requestType = sm_context_req_msg->get_request_type();
supi_t supi = sm_context_req_msg->get_supi();
supi64_t supi64 = smf_supi_to_u64(supi);
uint32_t pdu_session_id = sm_context_req_msg->get_pdu_session_id();
oai::smf::model::SmContextCreateError smContextCreateError;
oai::smf::model::ProblemDetails problem_details;
bool request_accepted = true;
//problem_details.setCause()
//Step 2. check the validity of the UE request, if valid send PDU Session Accept, otherwise send PDU Session Reject to AMF
if (!verify_sm_context_request(sm_context_req_msg)){ //TODO: Need to implement this function
// Not a valid request...
......@@ -1050,7 +1045,6 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
//create a new pdn connection
pgw_pdn_connection *p = new (pgw_pdn_connection);
p->pdn_type.pdn_type = sm_context_req_msg->get_pdu_session_type();
p->pdn_type.pdn_type = PDN_TYPE_E_IPV4; //TODO: should be removed after get the correct information from NAS_MSG
p->pdu_session_id = pdu_session_id; //should check also nas_msg.pdusessionidentity ??
//amf id
p->amf_id = sm_context_req_msg->get_serving_nf_id();
......@@ -1061,7 +1055,6 @@ void pgw_context::handle_amf_msg (std::shared_ptr<pdu_session_create_sm_context_
//TODO:
}
//pending session??
//step 4. check if supi is authenticated
......
......@@ -247,7 +247,6 @@ int session_establishment_procedure::run(std::shared_ptr<pdu_session_create_sm_c
itti_sxab_session_establishment_request *sx_ser = new itti_sxab_session_establishment_request(TASK_PGWC_APP, TASK_PGWC_SX);
sx_ser->seid = 0;
sx_ser->trxn_id = this->trxn_id;
//sx_ser->l_endpoint = boost::asio::ip::udp::endpoint(boost::asio::ip::address_v4(0xC0A8A064), 8805);
sx_ser->r_endpoint = endpoint(up_node_id.u1.ipv4_address, pfcp::default_port);
sx_triggered = std::shared_ptr<itti_sxab_session_establishment_request>(sx_ser);
......@@ -267,7 +266,6 @@ int session_establishment_procedure::run(std::shared_ptr<pdu_session_create_sm_c
sx_ser->pfcp_ies.set(cp_fseid);
// for (auto it : s5_trigger->gtp_ies.bearer_contexts_to_be_created) {
//*******************
// UPLINK
//*******************
......@@ -353,7 +351,6 @@ int session_establishment_procedure::run(std::shared_ptr<pdu_session_create_sm_c
pgw_eps_bearer b2 = b;
ppc->add_eps_bearer(b2);
// }
// for finding procedure when receiving response
pgw_app_inst->set_seid_2_pgw_context(cp_fseid.seid, pc);
......
......@@ -34,6 +34,7 @@ supi_t pdu_session_create_sm_context_request::get_supi() const
{
return m_supi;
}
void pdu_session_create_sm_context_request::set_supi(supi_t const& supi)
{
m_supi = supi;
......@@ -43,6 +44,7 @@ int32_t pdu_session_create_sm_context_request::get_pdu_session_id() const
{
return m_pdu_session_id;
}
void pdu_session_create_sm_context_request::set_pdu_session_id(int32_t const pdu_session_id)
{
m_pdu_session_id = pdu_session_id;
......@@ -52,6 +54,7 @@ std::string pdu_session_create_sm_context_request::get_dnn() const
{
return m_dnn;
}
void pdu_session_create_sm_context_request::set_dnn(std::string const& dnn)
{
m_dnn = dnn;
......@@ -61,6 +64,7 @@ snssai_t pdu_session_create_sm_context_request::get_snssai() const
{
return m_snssai;
}
void pdu_session_create_sm_context_request::set_snssai(snssai_t const& snssai)
{
m_snssai = snssai;
......@@ -70,6 +74,7 @@ std::string pdu_session_create_sm_context_request::get_serving_nf_id() const
{
return m_serving_nf_id;
}
void pdu_session_create_sm_context_request::set_serving_nf_id(std::string const& serving_nf_id)
{
m_serving_nf_id = serving_nf_id;
......@@ -79,10 +84,12 @@ std::string pdu_session_create_sm_context_request::get_request_type() const
{
return m_request_type;
}
void pdu_session_create_sm_context_request::set_request_type(std::string const& request_type)
{
m_request_type = request_type;
}
/*
pdu_session_establishment_request_msg pdu_session_create_sm_context_request::get_nas_msg() const
{
......@@ -93,24 +100,68 @@ void pdu_session_create_sm_context_request::set_nas_msg(pdu_session_establishmen
{
nas_msg = value;
}
*/
void pdu_session_create_sm_context_request::set_dnn_selection_mode (std::string const& dnn_selection_mode)
*/
void pdu_session_create_sm_context_request::set_dnn_selection_mode(std::string const& dnn_selection_mode)
{
m_dnn_selection_mode = dnn_selection_mode;
}
std::string pdu_session_create_sm_context_request::get_dnn_selection_mode () const
std::string pdu_session_create_sm_context_request::get_dnn_selection_mode() const
{
return m_dnn_selection_mode;
}
uint8_t pdu_session_create_sm_context_request::get_pdu_session_type ()
uint8_t pdu_session_create_sm_context_request::get_pdu_session_type() const
{
//return (uint8_t)nas_msg._pdusessiontype;
return m_pdu_session_type;
}
void pdu_session_create_sm_context_request::set_pdu_session_type (uint8_t const& pdu_session_type)
{
m_pdu_session_type = pdu_session_type;
}
extended_protocol_discriminator_t pdu_session_create_sm_context_request::get_epd() const
{
return m_epd;
}
void pdu_session_create_sm_context_request::set_epd(extended_protocol_discriminator_t const& epd)
{
m_epd = epd;
}
procedure_transaction_id_t pdu_session_create_sm_context_request::get_pti() const
{
return m_pti;
}
void pdu_session_create_sm_context_request::set_pti(procedure_transaction_id_t const& pti)
{
m_pti = pti;
}
uint8_t pdu_session_create_sm_context_request::get_message_type() const
{
return m_message_type;
}
void pdu_session_create_sm_context_request::set_message_type(uint8_t const& message_type){
m_message_type = message_type;
}
ipmdr_t pdu_session_create_sm_context_request::get_ipmdr() const
{
return m_ipmdr;
}
void pdu_session_create_sm_context_request::set_ipmdr(ipmdr_t const& ipmdr)
{
m_ipmdr = ipmdr;
}
//------------------------------------------------------------------
void pdu_session_create_sm_context_response::set_cause(uint8_t cause)
{
m_cause = cause;
......
......@@ -30,6 +30,8 @@
#include "smf.h"
#include "pistache/http.h"
#include "3gpp_29.274.h"
#include "3gpp_24.007.h"
namespace pgwc {
......@@ -56,14 +58,26 @@ public:
std::string get_request_type() const;
void set_request_type(std::string const& value);
// pdu_session_establishment_request_msg get_nas_msg() const;
// void set_nas_msg(pdu_session_establishment_request_msg const& value);
// pdu_session_establishment_request_msg get_nas_msg() const;
// void set_nas_msg(pdu_session_establishment_request_msg const& value);
void set_dnn_selection_mode (std::string const& value);
std::string get_dnn_selection_mode () const;
void set_dnn_selection_mode(std::string const& value);
std::string get_dnn_selection_mode() const;
uint8_t get_pdu_session_type ();
extended_protocol_discriminator_t get_epd() const;
void set_epd(extended_protocol_discriminator_t const& epd);
procedure_transaction_id_t get_pti() const;
void set_pti(procedure_transaction_id_t const& pti);
uint8_t get_message_type() const;
void set_message_type(uint8_t const& message_type);
uint8_t get_pdu_session_type() const;
void set_pdu_session_type(uint8_t const& pdu_session_type);
ipmdr_t get_ipmdr() const;
void set_ipmdr(ipmdr_t const& ipmdr);
private:
//pdu_session_establishment_request_msg nas_msg;
......@@ -115,7 +129,27 @@ private:
//std::string m_SmContextRef;
//NAS
//Extended protocol discriminator (Mandatory)
extended_protocol_discriminator_t m_epd;
//PDU session ID (Mandatory)
//TODO: need to check with PDU_session_id from outside of NAS??
//PTI (Mandatory)
procedure_transaction_id_t m_pti;
//Message type (Mandatory) (PDU SESSION ESTABLISHMENT REQUEST message identity)
uint8_t m_message_type;
//Integrity protection maximum data rate (Mandatory)
ipmdr_t m_ipmdr;
//PDU session type (Optional)
uint8_t m_pdu_session_type;
//SSC mode (Optional)
//5GSM capability (Optional)
//Maximum number of supported (Optional)
//Maximum number of supported packet filters (Optional)
//Always-on PDU session requested (Optional)
//SM PDU DN request container (Optional)
//Extended protocol configuration options (Optional) e.g, FOR DHCP
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment