Commit c0f0c02a authored by cucengineer's avatar cucengineer

identity_response

parent 019ffaef
......@@ -288,10 +288,10 @@ typedef struct {
// the message continues with the identity value, depending on identity type, see TS 14.501, 9.11.3.4
typedef struct __attribute__((packed)) {
Extendedprotocoldiscriminator_t epd:8;
Security_header_t sh:8;
SGSmobilitymanagementmessages_t mt:8;
uint16_t len;
Extendedprotocoldiscriminator_t epd:8; //CUC:√
Security_header_t sh:8;//√
SGSmobilitymanagementmessages_t mt:8;//√
uint16_t len;//√
}
Identityresponse_t;
......
#ifndef __NAS_NRUE_DEFS_H__
#define __NAS_NRUE_DEFS_H__
#include "NR_NAS_defs.h"
typedef struct {
uint8_t iei;
uint8_t len1;
uint8_t len2;
uint8_t mi:8;
} noidentity_identity_response_msg;
#endif /* __NAS_NRUE_DEFS_H__*/
\ No newline at end of file
// #include "nas_nrue_dencode.h"
// int encode_IdentityresponseIMSI(IdentityresponseIMSI_t *identity_response, uint8_t *buffer, uint32_t len)
// {
// int encoded = 0;
// int encode_result = 0;
// /* Checking IEI and pointer */
// // CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, IDENTITY_RESPONSE_MINIMUM_LENGTH, len);
// if ((encode_result =
// encode_mobileidentity(identity_response, 0, buffer +
// encoded, len - encoded)) < 0) //Return in case of error
// return encode_result;
// else
// encoded += encode_result;
// return encoded;
// }
// int encode_authenticationresponse(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len)
// {
// int encoded = 0;
// int encode_result = 0;
// /* Checking IEI and pointer */
// CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, AUTHENTICATION_RESPONSE_MINIMUM_LENGTH, len);
// if ((encode_result =
// encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
// 0, buffer + encoded, len - encoded)) < 0) //Return in case of error
// return encode_result;
// else
// encoded += encode_result;
// return encoded;
// }
// int encode_mobileidentity(IdentityresponseIMSI_t *identity_response, uint8_t iei, uint8_t *buffer, uint32_t len)
// {
// uint8_t *lenPtr;
// int encoded_rc = TLV_ENCODE_VALUE_DOESNT_MATCH;
// uint32_t encoded = 0;
// // /* Checking IEI and pointer */
// // CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, MOBILE_IDENTITY_MINIMUM_LENGTH, len);
// // #if defined (NAS_DEBUG)
// // dump_mobile_identity_xml(mobileidentity, iei);
// // #endif
// if (iei > 0) {
// *buffer = iei;
// encoded++;
// }
// lenPtr = (buffer + encoded);
// encoded ++;
// if (identity_response->mi == SUCI) {
// encoded_rc = encode_suci_identity(identity_response,
// buffer + encoded);
// }
// if (encoded_rc > 0) {
// *lenPtr = encoded + encoded_rc - 1 - ((iei > 0) ? 1 : 0);
// }
// if (encoded_rc < 0) {
// return encoded_rc;
// }
// return (encoded + encoded_rc);
// }
// static int encode_suci_identity(IdentityresponseIMSI_t *imsi, uint8_t *buffer)
// {
// uint32_t encoded = 0;
// *(buffer + encoded) = 0x00 | (imsi->supiFormat << 4) | imsi->identityType;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->mcc2 << 4) | imsi->mcc1;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->mnc3 << 4) | imsi->mcc3;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->mnc2 << 4) | imsi->mnc1;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->routing2 << 4) | imsi->routing1;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->routing4 << 4) | imsi->routing3;
// encoded++;
// *(buffer + encoded) = 0x00 | (imsi->spare << 4) | imsi->protectScheme;
// encoded++;
// //QUES:encode_suci_identity
// // Home network public key identifier
// // Scheme output 没写
// // return encoded;
// // 定义的hplmnId nocore没用
// }
int encode_noidentity_response (noidentity_identity_response_msg *identity_response, uint8_t *buffer, uint32_t len)
{
int encoded = 0;
int encode_result = 0;
if (identity_response->iei> 0) {
*buffer = identity_response->iei;
encoded++;
}
*(buffer + encoded)=0;
encoded++;
*(buffer + encoded)=3;
encoded++;
*(buffer + encoded)=0;
encoded++;
return encoded;
}
\ No newline at end of file
#ifndef __NAS_NRUE_DECODE_H__
#define __NAS_NRUE_DECODE_H__
#include "nas_nrue_defs.h"
int encode_noidentity_response (noidentity_identity_response_msg *identity_response, uint8_t *buffer, uint32_t len);
#endif /* __NAS_NRUE_DECODE_H__*/
......@@ -149,157 +149,144 @@ void *nas_ue_task(void *args_p)
return NULL;
}
void nr_nas_proc_dl_transfer_ind (UENAS_msg *msg, Byte_t *data, uint32_t len) { //QUES: 解出的msg干什么
#include "NR_NAS_defs.h"
void nr_nas_proc_dl_transfer_ind (MM_msg *msg, Byte_t *data, uint32_t len) { //QUES: 解出的msg干什么
uint8_t *buffer;
UENAS_msg *msg1;
uint32_t len1;
IdentityresponseIMSI_t *identity_response;
MM_msg *msg2;
uint32_t len1=0;
uint32_t len2=0;
nr_user_nas_t UErrc= {0};//QUES:user
int size;
decodeNasMsg(msg,data,len);
mm_msg_decode(msg,data,len);
switch (msg->header.message_type) {
case IDENTITY_REQUEST: { //send identityResponse in NAS_UPLINK_DATA_REQ
msg1->header.protocol_discriminator=0;
msg1->header.security_header_type=0;
len1 += sizeof(uint8_t);
msg1->header.message_type = IDENTITY_RESPONSE;
len1 += sizeof(uint8_t);
len1 += identityResponse((void **)&msg1->identity_response, &UErrc);
size = encodeNasMsg(msg1, buffer, len1);
msg2->header.ex_protocol_discriminator=SGSmobilitymanagementmessages;
msg2->header.security_header_type=0;
msg2->header.message_type = Identityresponse;
len2 = sizeof(uint8_t)*3;
msg2->identity_response.len1=0;
msg2->identity_response.len2=3;
msg2->identity_response.mi=0;
len2 += sizeof(uint8_t)*3;
size = mm_msg_encode(msg2, buffer, len2);
nas_itti_ul_data_req(0,buffer,size,0);
break;
}
case AUTHENTICATION_REQUEST: { //send authenticationResponse
msg1->header.protocol_discriminator=0;
msg1->header.security_header_type=0;
len1 += sizeof(uint8_t);
msg1->header.message_type = AUTHENTICATION_RESPONSE;
len1 += sizeof(uint8_t);
len1 += authenticationResponse((void **)&msg1->identity_response, &UErrc);
size = encodeNasMsg(msg1, buffer, len1);
nas_itti_ul_data_req(0,buffer,size,0);
break;
// msg1->header.protocol_discriminator=0;
// msg1->header.security_header_type=0;
// len1 += sizeof(uint8_t);
// msg1->header.message_type = AUTHENTICATION_RESPONSE;
// len1 += sizeof(uint8_t);
// len1 += authenticationResponse((void **)&msg1->identity_response, &UErrc);
// size = encodeNasMsg(msg1, buffer, len1);
// nas_itti_ul_data_req(0,buffer,size,0);
// break;
}
}
}
int decodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) {
int header_result;
int decode_result=0;
// #include "nr_nas_msg_sim.h"
/* First decode the EMM message header */
header_result = _emm_msg_decode_header(&msg->header, buffer, len);
// int mm_msg_decode(MM_msg *mm_msg, uint8_t *buffer, uint32_t len) {
// int header_result;
// int decode_result=0;
// uint8_t msg_type = mm_msg->header.message_type;
if (header_result < 0) {
LOG_TRACE(ERROR, "NR_UE - Failed to decode EMM message header "
"(%d)", header_result);
LOG_FUNC_RETURN(header_result);
}
buffer += header_result;
len -= header_result;
LOG_TRACE(INFO, "NR_UE - Message Type 0x%02x", msg->header.message_type);
// /* First decode the EMM message header */
// header_result = _nas_mm_msg_decode_header(&mm_msg->header, buffer, len);
switch(msg->header.message_type) {
// if (header_result < 0) {
// LOG_TRACE(ERROR, "NR_UE - Failed to decode EMM message header "
// "(%d)", header_result);
// LOG_FUNC_RETURN(header_result);
// }
}
// buffer += header_result;
// len -= header_result;
LOG_FUNC_RETURN (header_result + decode_result);
}
// LOG_TRACE(INFO, "NR_UE - Message Type 0x%02x", msg_type);
int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_msg *msg
int header_result;
int encode_result=0;
// switch(msg->header.message_type) {
/* First encode the EMM message header */
header_result = _emm_msg_encode_header(&msg->header, buffer, len);
// }
if (header_result < 0) {
LOG_TRACE(ERROR, "NR_UE - Failed to encode EMM message header "
"(%d)", header_result);
LOG_FUNC_RETURN(header_result);
}
// LOG_FUNC_RETURN (header_result + decode_result);
// }
buffer += header_result;
len -= header_result;
// int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_msg *msg
// int header_result;
// int encode_result=0;
switch(msg->header.message_type) {
case IDENTITY_RESPONSE: {
encode_result = encode_identity_response(&msg->identity_response, buffer, len);
break;
}
case AUTHENTICATION_RESPONSE: {
encode_result = encode_authentication_response(&msg->authentication_response, buffer, len);
break;
}
}
LOG_FUNC_RETURN (header_result + encode_result);
}
// /* First encode the EMM message header */
// header_result = _emm_msg_encode_header(&msg->header, buffer, len);
static int _emm_msg_decode_header(emm_msg_header_t *header,
const uint8_t *buffer, uint32_t len) {
int size = 0;
// if (header_result < 0) {
// LOG_TRACE(ERROR, "NR_UE - Failed to encode EMM message header "
// "(%d)", header_result);
// LOG_FUNC_RETURN(header_result);
// }
/* Check the buffer length */
// buffer += header_result;
// len -= header_result;
/* Decode the security header type and the protocol discriminator */
DECODE_U8(buffer + size, *(uint8_t *)(header), size);
/* Decode the message type */
DECODE_U8(buffer + size, header->message_type, size);
// switch(msg->header.message_type) {
// case IDENTITY_RESPONSE: {
// encode_result = encode_identity_response(&msg->identity_response, buffer, len);
// break;
// }
// case AUTHENTICATION_RESPONSE: {
// encode_result = encode_authentication_response(&msg->authentication_response, buffer, len);
// break;
// }
// }
// LOG_FUNC_RETURN (header_result + encode_result);
// }
/* Check the protocol discriminator */
return (size);
}
static int _emm_msg_encode_header(const emm_msg_header_t *header,
uint8_t *buffer, uint32_t len) {
static int _nas_mm_msg_decode_header(mm_msg_header_t *header,,
const uint8_t *buffer, uint32_t len) {
int size = 0;
/* Check the buffer length */
if (len < sizeof(mm_msg_header_t)) {
return (TLV_ENCODE_BUFFER_TOO_SHORT);
}
/* Check the protocol discriminator */
if (header->ex_protocol_discriminator != FGS_MOBILITY_MANAGEMENT_MESSAGE) {
LOG_TRACE(ERROR, "ESM-MSG - Unexpected extened protocol discriminator: 0x%x",
header->ex_protocol_discriminator);
return (TLV_ENCODE_PROTOCOL_NOT_SUPPORTED);
}
/* Encode the security header type and the protocol discriminator */
ENCODE_U8(buffer + size, *(uint8_t *)(header), size);
/* Encode the message type */
ENCODE_U8(buffer + size, header->message_type, size);
return (size);
}
int encode_IdentityresponseIMSI(IdentityresponseIMSI_t *identity_response, uint8_t *buffer, uint32_t len)
{
// int encoded = 0;
// int encode_result = 0;
// /* Checking IEI and pointer */
// CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, IDENTITY_RESPONSE_MINIMUM_LENGTH, len);
/* Encode the extendedprotocol discriminator */
DECODE_U8(buffer + size, header->ex_protocol_discriminator, size);
/* Encode the security header type */
DECODE_U8(buffer + size, header->security_header_type , size);
/* Decode the message type */
DECODE_U8(buffer + size, header->message_type, size);
// if ((encode_result =
// encode_mobile_identity(&identity_response->mobileidentity, 0, buffer +
// encoded, len - encoded)) < 0) //Return in case of error
// return encode_result;
// else
// encoded += encode_result;
/* Check the protocol discriminator */
// return encoded;
return (size);
}
int encode_authenticationresponse(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len)
{
// int encoded = 0;
// int encode_result = 0;
// static int _emm_msg_encode_header(const emm_msg_header_t *header,
// uint8_t *buffer, uint32_t len) {
// int size = 0;
// /* Checking IEI and pointer */
// CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, AUTHENTICATION_RESPONSE_MINIMUM_LENGTH, len);
// /* Check the buffer length */
// if ((encode_result =
// encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
// 0, buffer + encoded, len - encoded)) < 0) //Return in case of error
// return encode_result;
// else
// encoded += encode_result;
// /* Check the protocol discriminator */
// return encoded;
}
\ No newline at end of file
// /* Encode the security header type and the protocol discriminator */
// ENCODE_U8(buffer + size, *(uint8_t *)(header), size);
// /* Encode the message type */
// ENCODE_U8(buffer + size, header->message_type, size);
// return (size);
// }
......@@ -33,6 +33,7 @@
#include "TLVEncoder.h"
#include "NR_NAS_defs.h"
#include "nas_itti_messaging.h"
#include "nr_nas_msg_sim.h"
typedef union {
emm_msg_header_t header;
......@@ -44,9 +45,9 @@ typedef union {
void *nas_nrue_task(void *args_p);
void nr_nas_proc_dl_transfer_ind (UENAS_msg *msg, Byte_t *data, uint32_t len);
int decodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len);
int mm_msg_decode(MM_msg *mm_msg, uint8_t *buffer, uint32_t len);
int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len);
static int _emm_msg_decode_header(emm_msg_header_t *header, const uint8_t *buffer, uint32_t len); //QUES: defined in emm_msg.c and no check
static int _nas_mm_msg_encode_header(emm_msg_header_t *header, const uint8_t *buffer, uint32_t len); //QUES: defined in emm_msg.c and no check
static int _emm_msg_encode_header(const emm_msg_header_t *header, uint8_t *buffer, uint32_t len);
int encode_IdentityresponseIMSI(IdentityresponseIMSI_t *identity_response, uint8_t *buffer, uint32_t len);
int encode_authenticationresponse(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len);
......
......@@ -87,6 +87,10 @@ int mm_msg_encode(MM_msg *mm_msg, uint8_t *buffer, uint32_t len) {
encode_result = encode_registration_request(&mm_msg->registration_request, buffer, len);
break;
case Identityresponse:
encode_result = encode_noidentity_response(&mm_msg->identity_response, buffer, len);
break;
default:
LOG_TRACE(ERROR, "EMM-MSG - Unexpected message type: 0x%x",
mm_msg->header.message_type);
......
......@@ -33,7 +33,8 @@
#define __NR_NAS_MSG_SIM_H__
#include "RegistrationRequest.h"
#include "as_message.h"
#include "as_message.h
#include "nas_nrue_dencode.h"
#define PLAIN_5GS_MSG 0b0000
......@@ -69,6 +70,7 @@ typedef struct {
typedef union {
mm_msg_header_t header;
registration_request_msg registration_request;
noidentity_identity_response_msg identity_response;
} 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