Commit f6c67610 authored by cucengineer's avatar cucengineer

build ok

parent 8707b516
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
*/ */
#define NAS_BUILT_IN_UE 1 //QUES: #undef #define NAS_BUILT_IN_UE 1 //QUES: #undef
#define __LITTLE_ENDIAN_BITFIELD 1 // #define __LITTLE_ENDIAN_BITFIELD 1
#include "utils.h" #include "utils.h"
# include "assertions.h" # include "assertions.h"
...@@ -44,6 +44,9 @@ ...@@ -44,6 +44,9 @@
extern unsigned char NB_eNB_INST; extern unsigned char NB_eNB_INST;
extern uint16_t NB_UE_INST; extern uint16_t NB_UE_INST;
static int _nas_mm_msg_decode_header(mm_msg_header_t *header, const uint8_t *buffer, uint32_t len);
static int _nas_mm_msg_encode_header(const mm_msg_header_t *header, uint8_t *buffer, uint32_t len);
void *nas_ue_task(void *args_p) void *nas_ue_task(void *args_p)
{ {
int nb_events; int nb_events;
...@@ -152,34 +155,48 @@ void *nas_ue_task(void *args_p) ...@@ -152,34 +155,48 @@ void *nas_ue_task(void *args_p)
void nr_nas_proc_dl_transfer_ind (UENAS_msg *msg, Byte_t *data, uint32_t len) { //QUES: 解出的msg干什么 void nr_nas_proc_dl_transfer_ind (UENAS_msg *msg, Byte_t *data, uint32_t len) { //QUES: 解出的msg干什么
uint8_t *buffer; uint8_t *buffer;
UENAS_msg *msg1; UENAS_msg *msg1;
uint32_t len1; uint32_t len1=0;
nr_user_nas_t UErrc= {0};//QUES:user nr_user_nas_t UErrc= {0};//QUES:user
int size; int size;
decodeNasMsg(msg,data,len); decodeNasMsg(msg,data,len);
switch (msg->header.message_type) { switch (msg->header.message_type) {
case IDENTITY_REQUEST: { //send identityResponse in NAS_UPLINK_DATA_REQ // case IDENTITY_REQUEST: { //send identityResponse in NAS_UPLINK_DATA_REQ
msg1->header.protocol_discriminator=0; // msg1->header.ex_protocol_discriminator=0;
msg1->header.security_header_type=0; // msg1->header.security_header_type=0;
len1 += sizeof(uint8_t); // len1 += sizeof(uint8_t);
msg1->header.message_type = IDENTITY_RESPONSE; // msg1->header.message_type = IDENTITY_RESPONSE;
len1 += sizeof(uint8_t); // len1 += sizeof(uint8_t);
len1 += identityResponse((void **)&msg1->identity_response, &UErrc); // len1 += identityResponse((void **)&msg1->identity_response, &UErrc);
size = encodeNasMsg(msg1, buffer, len1); // size = encodeNasMsg(msg1, buffer, len1);
nas_itti_ul_data_req(0,buffer,size,0); // nas_itti_ul_data_req(0,buffer,size,0);
break; // break;
} // }
case AUTHENTICATION_REQUEST: { //send authenticationResponse 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); len1 += authenticationResponse((void **)&msg1->identity_response, &UErrc);
size = encodeNasMsg(msg1, buffer, len1); size = encodeNasMsg(msg1, buffer, len1);
nas_itti_ul_data_req(0,buffer,size,0); nas_itti_ul_data_req(0,buffer,size,0);
break; break;
} }
case SECURITY_MODE_COMMAND: {
len1 += securityModeComplete5g((void **)&msg1->securitymode_complete);
size = encodeNasMsg(msg1, buffer, len1);
nas_itti_ul_data_req(0,buffer,size,0);
break;
}
case REGISTRATION_ACCEPT: {
len1 += registrationComplete5g((void **)&msg1->registration_complete);
size = encodeNasMsg(msg1, buffer, len1);
nas_itti_ul_data_req(0,buffer,size,0);
break;
}
for (int i = 0; i < size; i++)
{
printf("aaaaaaaaaaaaa%x",*(buffer+i));
}
} }
} }
...@@ -189,7 +206,7 @@ int decodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { ...@@ -189,7 +206,7 @@ int decodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) {
int decode_result=0; int decode_result=0;
/* First decode the EMM message header */ /* First decode the EMM message header */
header_result = _emm_msg_decode_header(&msg->header, buffer, len); header_result = _nas_mm_msg_decode_header(&msg->header, buffer, len);
if (header_result < 0) { if (header_result < 0) {
LOG_TRACE(ERROR, "NR_UE - Failed to decode EMM message header " LOG_TRACE(ERROR, "NR_UE - Failed to decode EMM message header "
...@@ -213,7 +230,7 @@ int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_m ...@@ -213,7 +230,7 @@ int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_m
int encode_result=0; int encode_result=0;
/* First encode the EMM message header */ /* First encode the EMM message header */
header_result = _emm_msg_encode_header(&msg->header, buffer, len); header_result = _nas_mm_msg_encode_header(&msg->header, buffer, len);
if (header_result < 0) { if (header_result < 0) {
LOG_TRACE(ERROR, "NR_UE - Failed to encode EMM message header " LOG_TRACE(ERROR, "NR_UE - Failed to encode EMM message header "
...@@ -225,81 +242,120 @@ int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_m ...@@ -225,81 +242,120 @@ int encodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len) { //QUES:UENAS_m
len -= header_result; len -= header_result;
switch(msg->header.message_type) { switch(msg->header.message_type) {
case IDENTITY_RESPONSE: { // case IDENTITY_RESPONSE: {
encode_result = encode_identity_response(&msg->identity_response, buffer, len); // encode_result = encode_identity_response(&msg->identity_response, buffer, len);
// break;
// }
case AUTHENTICATION_RESPONSE: {
encode_result = encode_authentication_response5g(&msg->authentication_response, buffer, len);
break; break;
} }
case AUTHENTICATION_RESPONSE: {
encode_result = encode_authentication_response(&msg->authentication_response, buffer, len); case SECURITY_MODE_COMPLETE: {
encode_result = encode_security_mode_complete5g(&msg->securitymode_complete, buffer, len);//TODO:encode_security_mode_complete5g
break;
}
case REGISTRATION_COMPLETE: {
encode_result = encode_registration_complete5g(&msg->registration_complete, buffer, len);//TODO:encode_security_mode_complete5g
break; break;
} }
} }
LOG_FUNC_RETURN (header_result + encode_result); LOG_FUNC_RETURN (header_result + encode_result);
} }
static int _emm_msg_decode_header(emm_msg_header_t *header, static int _nas_mm_msg_decode_header(mm_msg_header_t *header, const uint8_t *buffer, uint32_t len) { //QUES: 静态函数在哪声明?
const uint8_t *buffer, uint32_t len) {
int size = 0; int size = 0;
/* Check the buffer length */ /* Check the buffer length */
/* Decode the security header type and the protocol discriminator */
DECODE_U8(buffer + size, *(uint8_t *)(header), size); /* Encode the extendedprotocol discriminator */
/* Decode the message type */ DECODE_U8(buffer + size, header->ex_protocol_discriminator, size);
/* Encode the security header type */
DECODE_U8(buffer + size, header->security_header_type, size);
/* Encode the message type */
DECODE_U8(buffer + size, header->message_type, size); DECODE_U8(buffer + size, header->message_type, size);
/* Check the protocol discriminator */ /* Check the protocol discriminator */
return (size); return (size);
} }
static int _emm_msg_encode_header(const emm_msg_header_t *header, static int _nas_mm_msg_encode_header(const mm_msg_header_t *header, uint8_t *buffer, uint32_t len) {
uint8_t *buffer, uint32_t len) {
int size = 0; int size = 0;
/* Check the buffer length */ /* Check the buffer length */
if (len < sizeof(mm_msg_header_t)) {
return (TLV_ENCODE_BUFFER_TOO_SHORT);
}
/* Check the protocol discriminator */ /* 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 the extendedprotocol discriminator */
ENCODE_U8(buffer + size, *(uint8_t *)(header), size); ENCODE_U8(buffer + size, header->ex_protocol_discriminator, size);
/* Encode the security header type */
ENCODE_U8(buffer + size, (header->security_header_type & 0xf), size);
/* Encode the message type */ /* Encode the message type */
ENCODE_U8(buffer + size, header->message_type, size); ENCODE_U8(buffer + size, header->message_type, size);
return (size); return (size);
} }
int encode_IdentityresponseIMSI(IdentityresponseIMSI_t *identity_response, uint8_t *buffer, uint32_t len)
int encode_authentication_response5g(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len)//QUES:AuthenticationResponse.c 中函数同名先编译哪个?
{ {
int encoded = 0; 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 = if (authentication_response->iei > 0) {
encode_mobile_identity(&identity_response->mobileidentity, 0, buffer + *buffer = authentication_response->iei;
encoded, len - encoded)) < 0) //Return in case of error encoded++;
return encode_result; }
else
encoded += encode_result;
*(buffer + encoded) = authentication_response->RESlen;
encoded++;
for (int i = 0; i < authentication_response->RESlen; i++)
{
*(buffer + encoded) = authentication_response->RES[i];
encoded++;
}
return encoded; return encoded;
} }
int encode_authenticationresponse(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len) int encode_security_mode_complete5g(securityModeComplete_t *securitymodecomplete, uint8_t *buffer, uint32_t len)
{ {
int encoded = 0; int encoded = 0;
int encode_result = 0;
/* Checking IEI and pointer */ return encoded;
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, AUTHENTICATION_RESPONSE_MINIMUM_LENGTH, len); }
if ((encode_result = int encode_registration_complete5g(registrationcomplete_t *registrationcomplete, uint8_t *buffer, uint32_t len)
encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter, {
0, buffer + encoded, len - encoded)) < 0) //Return in case of error int encoded = 0;
return encode_result;
else
encoded += encode_result;
return encoded; return encoded;
} }
\ No newline at end of file
int securityModeComplete5g(void **msg) {
myCalloc(resp, securityModeComplete_t);
resp->epd=SGSmobilitymanagementmessages;
resp->sh=0;
resp->mt=Registrationcomplete;
*msg=resp;
return sizeof(securityModeComplete_t);
}
int registrationComplete5g(void **msg) {
myCalloc(resp, registrationcomplete_t);
resp->epd=SGSmobilitymanagementmessages;
resp->sh=0;
resp->mt=Securitymodecomplete;
*msg=resp;
return sizeof(registrationcomplete_t);
}
...@@ -32,23 +32,55 @@ ...@@ -32,23 +32,55 @@
#include "TLVDecoder.h" #include "TLVDecoder.h"
#include "TLVEncoder.h" #include "TLVEncoder.h"
#include "NR_NAS_defs.h" #include "NR_NAS_defs.h"
#include "nas_itti_messaging.h" #include "nr_nas_msg_sim.h"
# define REGISTRATION_ACCEPT 0b01000010
# define REGISTRATION_COMPLETE 0b01000011
typedef struct __attribute__((packed)) {
Extendedprotocoldiscriminator_t epd:8;
Security_header_t sh:8;
SGSmobilitymanagementmessages_t mt:8;
} securityModeComplete_t;
typedef struct __attribute__((packed)) {
unsigned int len:8;
unsigned int allowed:4;
unsigned int value:4;
} SGSregistrationresult;
typedef struct __attribute__((packed)) {
Extendedprotocoldiscriminator_t epd:8;
Security_header_t sh:8;
SGSmobilitymanagementmessages_t mt:8;
SGSregistrationresult rr;
} registrationaccept_t;
typedef struct __attribute__((packed)) {
Extendedprotocoldiscriminator_t epd:8;
Security_header_t sh:8;
SGSmobilitymanagementmessages_t mt:8;
} registrationcomplete_t;
typedef union { typedef union {
emm_msg_header_t header; mm_msg_header_t header;
authenticationrequestHeader_t authentication_request; authenticationrequestHeader_t authentication_request;
authenticationresponse_t authentication_response; authenticationresponse_t authentication_response;
Identityrequest_t identity_request; Identityrequest_t identity_request;
IdentityresponseIMSI_t identity_response; IdentityresponseIMSI_t identity_response;
securityModeCommand_t securitymode_command;
securityModeComplete_t securitymode_complete;
registrationaccept_t registration_accept;
registrationcomplete_t registration_complete;
} UENAS_msg; } UENAS_msg;
void *nas_nrue_task(void *args_p); void *nas_nrue_task(void *args_p);
void nr_nas_proc_dl_transfer_ind (UENAS_msg *msg, Byte_t *data, uint32_t len); 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 decodeNasMsg(UENAS_msg *msg, uint8_t *buffer, uint32_t len);
int encodeNasMsg(UENAS_msg *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 int encode_authentication_response5g(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len);
static int _emm_msg_encode_header(const emm_msg_header_t *header, uint8_t *buffer, uint32_t len); int encode_security_mode_complete5g(securityModeComplete_t *securitymodecomplete, uint8_t *buffer, uint32_t len);
int encode_IdentityresponseIMSI(IdentityresponseIMSI_t *identity_response, uint8_t *buffer, uint32_t len); int encode_registration_complete5g(registrationcomplete_t *registrationcomplete, uint8_t *buffer, uint32_t len);
int encode_authenticationresponse(authenticationresponse_t *authentication_response, uint8_t *buffer, uint32_t len); int securityModeComplete5g(void **msg);
int registrationComplete5g(void **msg);
#endif /* NAS_TASK_H_ */ #endif /* NAS_TASK_H_ */
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