Commit 3e0efbfa authored by cucengineer's avatar cucengineer

Add nas massage decode

parent 73958504
......@@ -2592,6 +2592,10 @@ endif()
${NAS_SRC}COMMON/EMM/MSG/RegistrationComplete.c
${NAS_SRC}COMMON/EMM/MSG/FGSUplinkNasTransport.c
${NAS_SRC}COMMON/ESM/MSG/PduSessionEstablishRequest.c
${NAS_SRC}COMMON/EMM/MSG/FGSAuthenticationRequest.c
${NAS_SRC}COMMON/EMM/MSG/FGSIdentityRequest.c
${NAS_SRC}COMMON/EMM/MSG/FGSRegistrationAccept.c
${NAS_SRC}COMMON/EMM/MSG/FGSSecurityModeCommand.c
)
set(libnrnas_ies_OBJS
......
/*! \file FGSAuthenticationRequest.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FGSAuthenticationRequest.h"
int decode_fgs_authentication_request(authenticationrequestHeader_t *fgs_authentication_req, uint8_t *buffer, uint32_t len)
{
int decoded = 0;
fgs_authentication_req->ngKSI = (*(buffer + decoded)>>4) & 0x0f;
fgs_authentication_req->spare = *(buffer + decoded) & 0x0f;
decoded++;
IES_DECODE_U8(buffer, decoded, fgs_authentication_req->ABBALen);
IES_DECODE_U16(buffer, decoded, fgs_authentication_req->ABBA);
while(len - decoded > 0) {
uint8_t ieiDecoded = *(buffer + decoded);
switch(ieiDecoded) {
case AUTHENTICATION_PARAMETER_RAND_IEI:
IES_DECODE_U8(buffer, decoded, fgs_authentication_req->ieiRAND);
memcpy(fgs_authentication_req->RAND, buffer+decoded, sizeof(fgs_authentication_req->RAND));
decoded += sizeof(fgs_authentication_req->RAND);
break;
case AUTHENTICATION_PARAMETER_AUTN_IEI:
IES_DECODE_U8(buffer, decoded, fgs_authentication_req->ieiAUTN);
IES_DECODE_U8(buffer, decoded, fgs_authentication_req->AUTNlen);
memcpy(fgs_authentication_req->AUTN, buffer+decoded, sizeof(fgs_authentication_req->AUTN));
decoded += sizeof(fgs_authentication_req->AUTN);
default:
return TLV_DECODE_UNEXPECTED_IEI;
}
}
return decoded;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "NR_NAS_defs.h"
#include "nas_log.h"
#include "TLVDecoder.h"
#ifndef FGS_AUTHENTICATION_REQUEST_H_
#define FGS_AUTHENTICATION_REQUEST_H_
#define AUTHENTICATION_PARAMETER_RAND_IEI 0x21
#define AUTHENTICATION_PARAMETER_AUTN_IEI 0x20
int decode_fgs_authentication_request(authenticationrequestHeader_t *fgs_authentication_req, uint8_t *buffer, uint32_t len);
#endif /* FGS AUTHENTICATION REQUEST_H_*/
\ No newline at end of file
/*! \file FGSIdentityRequest.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "nas_log.h"
#include "FGSIdentityRequest.h"
int decode_fgs_identity_request(Identityrequest_t *fgs_identity_req, uint8_t *buffer, uint32_t len)
{
int decoded = 0;
fgs_identity_req->it = *(buffer + decoded);
decoded++;
return decoded;
}
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "NR_NAS_defs.h"
#include "nas_log.h"
#include "TLVDecoder.h"
#ifndef FGS_IDENTITY_REQUEST_H_
#define FGS_IDENTITY_REQUEST_H_
int decode_fgs_identity_request(Identityrequest_t *fgs_identity_req, uint8_t *buffer, uint32_t len);
#endif /* FGS IDENTITY REQUEST_H_*/
\ No newline at end of file
/*! \file FGSRegistrationAccept.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FGSRegistrationAccept.h"
int decode_fgs_tracking_area_identity_list(FGSTrackingAreaIdentityList *tailist, uint8_t iei, uint8_t *buffer, uint32_t len) {
int decoded_rc = TLV_DECODE_VALUE_DOESNT_MATCH;
int decoded = 0;
uint8_t ielen = 0;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
decoded++;
}
ielen = *(buffer + decoded);
decoded ++;
CHECK_LENGTH_DECODER(len - decoded, ielen);
uint8_t typeoflist = *(buffer + decoded) & 0x60;
if (typeoflist == TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS) {
tailist->typeoflist = (*(buffer + decoded) >> 5) & 0x3;
tailist->numberofelements = *(buffer + decoded) & 0x1f;
decoded++;
tailist->mccdigit2 = (*(buffer + decoded) >> 4) & 0xf;
tailist->mccdigit1 = *(buffer + decoded) & 0xf;
decoded++;
tailist->mncdigit3 = (*(buffer + decoded) >> 4) & 0xf;
tailist->mccdigit3 = *(buffer + decoded) & 0xf;
decoded++;
tailist->mncdigit2 = (*(buffer + decoded) >> 4) & 0xf;
tailist->mncdigit1 = *(buffer + decoded) & 0xf;
decoded++;
IES_DECODE_U24(buffer, decoded, tailist->tac);
return decoded;
} else {
return decoded_rc;
}
}
int decode_fgs_allowed_nssa(NSSAI *nssai, uint8_t iei, uint8_t *buffer, uint32_t len) {
int decoded = 0;
uint8_t ielen = 0;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
decoded++;
}
ielen = *(buffer + decoded);
decoded ++;
CHECK_LENGTH_DECODER(len - decoded, ielen);
IES_DECODE_U8(buffer, decoded, nssai->length);
IES_DECODE_U8(buffer, decoded, nssai->value);
return decoded;
}
int decode_fgs_network_feature_support(FGSNetworkFeatureSupport *fgsnetworkfeaturesupport, uint8_t iei, uint8_t *buffer, uint32_t len) {
int decoded = 0;
uint8_t ielen = 0;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
decoded++;
}
ielen = *(buffer + decoded);
decoded ++;
CHECK_LENGTH_DECODER(len - decoded, ielen);
fgsnetworkfeaturesupport->mpsi = (*(buffer + decoded)>>7) & 0x1;
fgsnetworkfeaturesupport->iwkn26 = (*(buffer + decoded)>>6) & 0x1;
fgsnetworkfeaturesupport->EMF = (*(buffer + decoded)>>4) & 0x3;
fgsnetworkfeaturesupport->EMC = (*(buffer + decoded)>>2) & 0x3;
fgsnetworkfeaturesupport->IMSVoPSN3GPP = (*(buffer + decoded)>>1) & 0x1;
fgsnetworkfeaturesupport->IMSVoPS3GPP = *(buffer + decoded) & 0x1;
decoded ++;
fgsnetworkfeaturesupport->MCSI = (*(buffer + decoded)>>1) & 0x1;
fgsnetworkfeaturesupport->EMCN3 = *(buffer + decoded) & 0x1;
decoded ++;
return decoded;
}
int decode_fgs_registration_accept(fgs_registration_accept_msg *fgs_registration_acc, uint8_t *buffer, uint32_t len)
{
int decoded = 0;
int decode_result = 0;
IES_DECODE_U8(buffer, decoded, fgs_registration_acc->fgsregistrationresult.resultlength);
fgs_registration_acc->fgsregistrationresult.smsallowed = (*(buffer + decoded)>>3) & 0x1;
fgs_registration_acc->fgsregistrationresult.registrationresult = *(buffer + decoded) & 0x7;
decoded++;
while(len - decoded > 0) {
uint8_t ieiDecoded = *(buffer + decoded);
switch(ieiDecoded) {
case REGISTRATION_ACCEPT_MOBILE_IDENTITY:
if ((decode_result = decode_5gs_mobile_identity(&fgs_registration_acc->fgsmobileidentity, REGISTRATION_ACCEPT_MOBILE_IDENTITY, buffer +
decoded, len - decoded)) < 0) { //Return in case of error
return decode_result;
} else {
decoded += decode_result;
break;
}
case REGISTRATION_ACCEPT_5GS_TRACKING_AREA_IDENTITY_LIST:
if ((decode_result = decode_fgs_tracking_area_identity_list(&fgs_registration_acc->tailist, REGISTRATION_ACCEPT_5GS_TRACKING_AREA_IDENTITY_LIST, buffer +
decoded, len - decoded)) < 0) { //Return in case of error
return decode_result;
} else {
decoded += decode_result;
break;
}
case REGISTRATION_ACCEPT_ALLOWED_NSSA:
if ((decode_result = decode_fgs_allowed_nssa(&fgs_registration_acc->nssai, REGISTRATION_ACCEPT_ALLOWED_NSSA, buffer +
decoded, len - decoded)) < 0) { //Return in case of error
return decode_result;
} else {
decoded += decode_result;
break;
}
case REGISTRATION_ACCEPT_5GS_NETWORK_FEATURE_SUPPORT:
if ((decode_result = decode_fgs_network_feature_support(&fgs_registration_acc->fgsnetworkfeaturesupport, REGISTRATION_ACCEPT_5GS_NETWORK_FEATURE_SUPPORT, buffer +
decoded, len - decoded)) < 0) { //Return in case of error
return decode_result;
} else {
decoded += decode_result;
break;
}
default:
return TLV_DECODE_UNEXPECTED_IEI;
}
}
return decoded;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "ExtendedProtocolDiscriminator.h"
#include "SecurityHeaderType.h"
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "FGSRegistrationResult.h"
#include "FGSMobileIdentity.h"
#include "NR_NAS_defs.h"
#include "nas_log.h"
#include "TLVDecoder.h"
#ifndef FGS_REGISTRATION_ACCEPT_H_
#define FGS_REGISTRATION_ACCEPT_H_
#define REGISTRATION_ACCEPT_MOBILE_IDENTITY 0x77
#define REGISTRATION_ACCEPT_5GS_TRACKING_AREA_IDENTITY_LIST 0x54
#define REGISTRATION_ACCEPT_ALLOWED_NSSA 0x15
#define REGISTRATION_ACCEPT_5GS_NETWORK_FEATURE_SUPPORT 0x21
typedef struct FGSTrackingAreaIdentityList_tag {
#define TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NON_CONSECUTIVE_TACS 0b00
//#define TRACKING_AREA_IDENTITY_LIST_ONE_PLMN_NONCONSECUTIVE_TACS 0b01
//#define TRACKING_AREA_IDENTITY_LIST_MANY_PLMNS 0b10
uint8_t typeoflist:2;
uint8_t numberofelements:5;
uint8_t mccdigit2:4;
uint8_t mccdigit1:4;
uint8_t mncdigit3:4;
uint8_t mccdigit3:4;
uint8_t mncdigit2:4;
uint8_t mncdigit1:4;
unsigned int tac:24;
} FGSTrackingAreaIdentityList;
typedef struct NSSAI_tag {
uint8_t length;
uint8_t value;
} NSSAI;
typedef struct FGSNetworkFeatureSupport_tag {
unsigned int mpsi:1;
unsigned int iwkn26:1;
unsigned int EMF:2;
unsigned int EMC:2;
unsigned int IMSVoPSN3GPP:1;
unsigned int IMSVoPS3GPP:1;
unsigned int MCSI:1;
unsigned int EMCN3:1;
} FGSNetworkFeatureSupport;
typedef struct fgs_registration_accept_msg_tag {
/* Mandatory fields */
ExtendedProtocolDiscriminator protocoldiscriminator;
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
FGSRegistrationResult fgsregistrationresult;
FGSMobileIdentity fgsmobileidentity;
FGSTrackingAreaIdentityList tailist ;
NSSAI nssai;
FGSNetworkFeatureSupport fgsnetworkfeaturesupport;
} fgs_registration_accept_msg;
int decode_fgs_tracking_area_identity_list(FGSTrackingAreaIdentityList *tailist, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_fgs_allowed_nssa(NSSAI *nssai, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_fgs_network_feature_support(FGSNetworkFeatureSupport *fgsnetworkfeaturesupport, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_fgs_registration_accept(fgs_registration_accept_msg *fgs_registration_acc, uint8_t *buffer, uint32_t len);
#endif /* FGS REGISTRATION ACCEPT_H_*/
\ No newline at end of file
/*! \file FGSSecurityModeCommand.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "FGSSecurityModeCommand.h"
int decode_fgs_security_mode_command(securityModeCommand_t *fgs_security_mode_com, uint8_t *buffer, uint32_t len)
{
int decoded = 0;
IES_DECODE_U8(buffer, decoded, fgs_security_mode_com->selectedNASsecurityalgorithms);
fgs_security_mode_com->ngKSI = (*(buffer + decoded)>>4) & 0x0f;
decoded++;
fgs_security_mode_com->spare = *(buffer + decoded) & 0x0f;
decoded++;
return decoded;
}
\ No newline at end of file
#include "NR_NAS_defs.h"
#include "nas_log.h"
#include "TLVDecoder.h"
#ifndef FGS_SECURITY_MODE_COMMAND_H_
#define FGS_SECURITY_MODE_COMMAND_H_
int decode_fgs_security_mode_command(securityModeCommand_t *fgs_security_mode_com, uint8_t *buffer, uint32_t len);
#endif /* FGS SECURITY MODE COMMAND_H_*/
\ No newline at end of file
......@@ -47,15 +47,15 @@ int decode_5gs_mobile_identity(FGSMobileIdentity *fgsmobileidentity, uint8_t iei
{
int decoded_rc = TLV_DECODE_VALUE_DOESNT_MATCH;
int decoded = 0;
uint8_t ielen = 0;
uint16_t ielen = 0;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
decoded++;
}
ielen = *(buffer + decoded);
decoded++;
IES_DECODE_U16(buffer, decoded, ielen);
decoded += 2;
CHECK_LENGTH_DECODER(len - decoded, ielen);
uint8_t typeofidentity = *(buffer + decoded) & 0x7;
......
......@@ -180,6 +180,8 @@ void nr_nas_proc_dl_transfer_ind (Byte_t *data, uint32_t len) {
case REGISTRATION_ACCEPT: {
generateRegistrationComplete(&nas_info, 0);
nr_nas_itti_ul_data_req(0, nas_info.data, nas_info.length, 0);
generatePduSessionEstablishRequest(&nas_info);
nr_nas_itti_ul_data_req(0, nas_info.data, nas_info.length, 0);
break;
}
......@@ -280,22 +282,22 @@ int decodeNasMsg(MM_msg *msg, uint8_t *buffer, uint32_t len) {
switch(msg->header.message_type) {
case FGS_IDENTITY_REQUEST: {
decode_result = decode_fgs_identity_request(&msg->fgs_identity_request, buffer, len);
break;
}
case FGS_AUTHENTICATION_REQUEST: {
case FGS_AUTHENTICATION_REQUEST: {
decode_result = decode_fgs_authentication_request(&msg->fgs_authentication_request, buffer, len);
break;
}
case FGS_SECURITY_MODE_COMMAND: {
decode_result = decode_fgs_security_mode_command(&msg->fgs_security_mode_command, buffer, len);
break;
}
case REGISTRATION_ACCEPT: {
case REGISTRATION_ACCEPT: {
decode_result = decode_fgs_registration_accept(&msg->fgs_registration_accept, buffer, len);
break;
}
......
......@@ -32,6 +32,10 @@
#include "TLVEncoder.h"
#include "nr_nas_msg_sim.h"
# include "FGSIdentityRequest.h"
# include "FGSAuthenticationRequest.h"
# include "FGSSecurityModeCommand.h"
# include "FGSRegistrationAccept.h"
void *nas_nrue_task(void *args_p);
void nr_nas_proc_dl_transfer_ind (Byte_t *data, uint32_t len);
......
......@@ -39,6 +39,8 @@
#include "RegistrationComplete.h"
#include "as_message.h"
#include "FGSUplinkNasTransport.h"
#include "NR_NAS_defs.h"
#include "FGSRegistrationAccept.h"
#define PLAIN_5GS_MSG 0b0000
#define INTEGRITY_PROTECTED 0b0001
......@@ -113,6 +115,10 @@ typedef union {
fgs_security_mode_complete_msg fgs_security_mode_complete;
registration_complete_msg registration_complete;
fgs_uplink_nas_transport_msg uplink_nas_transport;
Identityrequest_t fgs_identity_request;
authenticationrequestHeader_t fgs_authentication_request;
securityModeCommand_t fgs_security_mode_command;
fgs_registration_accept_msg fgs_registration_accept;
} MM_msg;
......
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