nr_nas_msg_sim.h 7.16 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

22
/*! \file nr_nas_msg_sim.h
23 24 25 26 27 28
 * \brief simulator for nr nas message
 * \author Yoshio INOUE, Masayuki HARADA
 * \email yoshio.inoue@fujitsu.com,masayuki.harada@fujitsu.com
 * \date 2020
 * \version 0.1
 */
29 30 31 32 33 34 35



#ifndef __NR_NAS_MSG_SIM_H__
#define __NR_NAS_MSG_SIM_H__

#include "RegistrationRequest.h"
heshanyun's avatar
heshanyun committed
36 37
#include "FGSIdentityResponse.h"
#include "FGSAuthenticationResponse.h"
Xue Song's avatar
Xue Song committed
38
#include "FGSNASSecurityModeComplete.h"
Robert Schmidt's avatar
Robert Schmidt committed
39
#include "FGSDeregistrationRequestUEOriginating.h"
40
#include "RegistrationComplete.h"
41
#include "as_message.h"
42
#include "FGSUplinkNasTransport.h"
43
#include <openair3/UICC/usim_interface.h>
44
#include "secu_defs.h"
45 46 47

#define PLAIN_5GS_MSG                                      0b0000
#define INTEGRITY_PROTECTED                                0b0001
48
#define INTEGRITY_PROTECTED_AND_CIPHERED                   0b0010
Xue Song's avatar
Xue Song committed
49 50
#define INTEGRITY_PROTECTED_WITH_NEW_SECU_CTX              0b0011          // only for SECURITY MODE COMMAND
#define INTEGRITY_PROTECTED_AND_CIPHERED_WITH_NEW_SECU_CTX 0b0100         // only for SECURITY MODE COMPLETE
51

52 53 54
#define REGISTRATION_REQUEST                               0b01000001 /* 65 = 0x41 */
#define REGISTRATION_ACCEPT                                0b01000010 /* 66 = 0x42 */
#define REGISTRATION_COMPLETE                              0b01000011 /* 67 = 0x43 */
55
#define REGISTRATION_REJECT                                68
Robert Schmidt's avatar
Robert Schmidt committed
56
#define FGS_DEREGISTRATION_REQUEST_UE_ORIGINATING          0b01000101
57
#define FGS_DEREGISTRATION_ACCEPT                          0b01000110
heshanyun's avatar
heshanyun committed
58 59 60 61 62 63
#define FGS_AUTHENTICATION_REQUEST                         0b01010110 /* 86 = 0x56 */
#define FGS_AUTHENTICATION_RESPONSE                        0b01010111 /* 87 = 0x57 */
#define FGS_IDENTITY_REQUEST                               0b01011011 /* 91 = 0x5b */
#define FGS_IDENTITY_RESPONSE                              0b01011100 /* 92 = 0x5c */
#define FGS_SECURITY_MODE_COMMAND                          0b01011101 /* 93 = 0x5d */
#define FGS_SECURITY_MODE_COMPLETE                         0b01011110 /* 94 = 0x5e */
64
#define FGS_UPLINK_NAS_TRANSPORT                           0b01100111 /* 103= 0x67 */
65
#define FGS_DOWNLINK_NAS_TRANSPORT                         0b01101000 /* 104= 0x68 */
66

67 68
// message type for 5GS session management
#define FGS_PDU_SESSION_ESTABLISHMENT_REQ                  0b11000001 /* 193= 0xc1 */
69
#define FGS_PDU_SESSION_ESTABLISHMENT_ACC                  0b11000010 /* 194= 0xc2 */
70
#define FGS_PDU_SESSION_ESTABLISHMENT_REJ                  0b11000011 /* 195= 0xc3 */
heshanyun's avatar
heshanyun committed
71

72
#define INITIAL_REGISTRATION                               0b001
73

Laurent Thomas's avatar
Laurent Thomas committed
74 75 76 77
#define PLAIN_5GS_NAS_MESSAGE_HEADER_LENGTH                3
#define SECURITY_PROTECTED_5GS_NAS_MESSAGE_HEADER_LENGTH   7
#define PAYLOAD_CONTAINER_LENGTH_MIN                       3
#define PAYLOAD_CONTAINER_LENGTH_MAX                       65537
78

79 80 81 82 83 84 85 86
/* List of allowed NSSAI from NAS messaging. */
typedef struct {
  int sst;
  int hplmn_sst;
  int sd;
  int hplmn_sd;
} nr_nas_msg_snssai_t;

87 88 89 90 91 92
/* Security Key for SA UE */
typedef struct {
  uint8_t kausf[32];
  uint8_t kseaf[32];
  uint8_t kamf[32];
  uint8_t knas_int[16];
93
  uint8_t knas_enc[16];
94 95 96
  uint8_t res[16];
  uint8_t rand[16];
  uint8_t kgnb[32];
97 98
  uint32_t nas_count_ul;
  uint32_t nas_count_dl;
99 100
} ue_sa_security_key_t;

101 102 103
typedef struct {
  uicc_t *uicc;
  ue_sa_security_key_t security;
104
  stream_security_container_t *security_container;
105
  Guti5GSMobileIdentity_t *guti;
106
  bool termination_procedure;
107 108
  uint8_t  *registration_request_buf;
  uint32_t  registration_request_len;
109
  instance_t UE_id;
110 111
} nr_ue_nas_t;

112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
typedef enum fgs_protocol_discriminator_e {
  /* Protocol discriminator identifier for 5GS Mobility Management */
  FGS_MOBILITY_MANAGEMENT_MESSAGE =   0x7E,

  /* Protocol discriminator identifier for 5GS Session Management */
  FGS_SESSION_MANAGEMENT_MESSAGE =    0x2E,
} fgs_protocol_discriminator_t;


typedef struct {
  uint8_t ex_protocol_discriminator;
  uint8_t security_header_type;
  uint8_t message_type;
} mm_msg_header_t;

/* Structure of security protected header */
typedef struct {
  fgs_protocol_discriminator_t    protocol_discriminator;
  uint8_t                         security_header_type;
  uint32_t                        message_authentication_code;
  uint8_t                         sequence_number;
} fgs_nas_message_security_header_t;

typedef union {
  mm_msg_header_t                        header;
  registration_request_msg               registration_request;
heshanyun's avatar
heshanyun committed
138 139
  fgs_identiy_response_msg               fgs_identity_response;
  fgs_authentication_response_msg        fgs_auth_response;
Robert Schmidt's avatar
Robert Schmidt committed
140
  fgs_deregistration_request_ue_originating_msg fgs_deregistration_request_ue_originating;
Xue Song's avatar
Xue Song committed
141
  fgs_security_mode_complete_msg         fgs_security_mode_complete;
142
  registration_complete_msg              registration_complete;
143
  fgs_uplink_nas_transport_msg           uplink_nas_transport;
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
} MM_msg;



typedef struct {
  MM_msg mm_msg;    /* 5GS Mobility Management messages */
} fgs_nas_message_plain_t;

typedef struct {
  fgs_nas_message_security_header_t header;
  fgs_nas_message_plain_t plain;
} fgs_nas_message_security_protected_t;


typedef union {
  fgs_nas_message_security_header_t header;
  fgs_nas_message_security_protected_t security_protected;
  fgs_nas_message_plain_t plain;
} fgs_nas_message_t;

Laurent Thomas's avatar
Laurent Thomas committed
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
typedef struct {
  union {
    mm_msg_header_t plain_nas_msg_header;
    struct security_protected_nas_msg_header_s {
      uint8_t  ex_protocol_discriminator;
      uint8_t  security_header_type;
      uint16_t message_authentication_code1;
      uint16_t message_authentication_code2;
      uint8_t  sequence_number;
    } security_protected_nas_msg_header_t;
  } choice;
} nas_msg_header_t;

typedef struct {
  uint8_t ex_protocol_discriminator;
  uint8_t pdu_session_id;
  uint8_t PTI;
  uint8_t message_type;
} fgs_sm_nas_msg_header_t;

typedef struct {
    mm_msg_header_t         plain_nas_msg_header;
    uint8_t                 payload_container_type;
    uint16_t                payload_container_length;
    fgs_sm_nas_msg_header_t sm_nas_msg_header;
} dl_nas_transport_t;

191 192
nr_ue_nas_t *get_ue_nas_info(module_id_t module_id);
void generateRegistrationRequest(as_nas_info_t *initialNasMsg, nr_ue_nas_t *nas);
Xue Song's avatar
Xue Song committed
193
void *nas_nrue_task(void *args_p);
194
void *nas_nrue(void *args_p);
195 196

#endif /* __NR_NAS_MSG_SIM_H__*/
heshanyun's avatar
heshanyun committed
197 198


199