Add common definitions to new fgmm_lib.c/.h files
The 5GMM library in openair3/NAS/NR_UE/5GS/5GMM/ contains the all the definitions necessary to do the enc/dec of 5GMM IEs. 5GMM messages can share the same IEs, therefore they can use common definitions and enc/dec functions. The goal of this commit is to add common definitions to new shared 5GMM library files. The consumers of fgmm_lib are the functions defined in the openair3/NAS/NR_UE/5GS/5GMM/ library.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
add_library(fgs_5gmm_lib OBJECT
|
||||
fgmm_lib.c
|
||||
fgs_service_request.c
|
||||
RegistrationRequest.c
|
||||
RegistrationAccept.c
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#include "fgmm_lib.h"
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h> // For htons and ntohs
|
||||
#include <stdlib.h> // For malloc and free
|
||||
#include "common/utils/ds/byte_array.h"
|
||||
|
||||
#define GPRS_TIMER_LENGTH 3 // octets
|
||||
|
||||
/**
|
||||
* Encode PDU Session Status and PDU session reactivation result (optional IEs)
|
||||
* According to 9.11.3.42 and 9.11.3.44 of 3GPP TS 24.501, both IEs share the same
|
||||
* structure, therefore this function covers them both.
|
||||
* @param iei IE identifier to distinguish between PDU Session Status and PDU session reactivation result.
|
||||
* @param psi pointer to PDU Session Status IE buffer to be encoded: index i corresponds to PDU Session i
|
||||
*/
|
||||
int encode_pdu_session_ie(byte_array_t *buffer, nas_service_IEI_t iei, const uint8_t *psi)
|
||||
{
|
||||
if (buffer->len < MIN_PDU_SESSION_CONTENTS_LEN + 2) {
|
||||
PRINT_NAS_ERROR("%s failed: buffer is too small", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t *buf = buffer->buf;
|
||||
int encoded = 0;
|
||||
buf[encoded++] = iei;
|
||||
buf[encoded++] = MIN_PDU_SESSION_CONTENTS_LEN; // no spare octets
|
||||
|
||||
// Initialize the PDU session status octets to zero
|
||||
buf[encoded] = 0x00;
|
||||
buf[encoded + 1] = 0x00;
|
||||
|
||||
/* Encode Octet 3 (PSI 1-7) and Octet 4 (PSI 8-15).
|
||||
Set each PSI bit according to the psi array containing the content IEs.
|
||||
Start from bit 1 of octet 3 (i.e. PSI(0)), which is spare and shall be coded as zero.
|
||||
The enabled bit translates to either PDU Session Active or PDU Session Reactivation Result */
|
||||
for (int i = 1; i < 8; i++) { // skip spare bit
|
||||
buf[encoded] |= psi[i] << i;
|
||||
}
|
||||
encoded++;
|
||||
|
||||
for (int i = 8; i < MAX_NUM_PSI; i++) {
|
||||
buf[encoded] |= psi[i] << i % 8;
|
||||
}
|
||||
encoded++;
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode PDU Session Status and PDU session reactivation result (optional IEs)
|
||||
* According to 9.11.3.42 and 9.11.3.44 of 3GPP TS 24.501, both IEs share the same
|
||||
* structure, therefore this function covers them both.
|
||||
* @param psi pointer to buffer for the PDU Session Status IE to be decoded
|
||||
*/
|
||||
int decode_pdu_session_ie(uint8_t *psi, const byte_array_t *buffer)
|
||||
{
|
||||
int decoded = 0;
|
||||
uint8_t *buf = buffer->buf;
|
||||
|
||||
if (buffer->len < MIN_PDU_SESSION_CONTENTS_LEN + 2) {
|
||||
PRINT_NAS_ERROR("%s failed: buffer length is too small", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// start decoding from length IE (IEI is decoded in the caller)
|
||||
uint8_t pdu_session_status_len = buf[decoded++];
|
||||
if (pdu_session_status_len > MAX_PDU_SESSION_CONTENTS_LEN) {
|
||||
PRINT_NAS_ERROR("decoded length is out of bound for PDU Session Status/Reactivation result\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Decode PDU Session Status content IEs bits in octet 3 (PSI 1-7).
|
||||
Store the result psi array.
|
||||
Skip bit 1 of octet 3 (i.e. PSI(0)), which is spare and shall be coded as zero. */
|
||||
for (int i = 1; i < 8; i++) { // skip spare bit
|
||||
psi[i] = (buf[decoded] >> i) & 0x01;
|
||||
}
|
||||
decoded++;
|
||||
|
||||
/* Decode PDU Session Status content IEs bits in octet 4 (PSI 8-15).
|
||||
Store the result psi array. */
|
||||
for (int i = 8; i < MAX_NUM_PSI; i++) {
|
||||
psi[i] = (buf[decoded] >> i % 8) & 0x01;
|
||||
}
|
||||
decoded++;
|
||||
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/* Encode GPRS Timer IE (3GPP TS 24.008 10.5.7.3) */
|
||||
int encode_gprs_timer_ie(byte_array_t *buffer, nas_service_IEI_t iei, const gprs_timer_t *timer)
|
||||
{
|
||||
if (buffer->len < GPRS_TIMER_LENGTH) {
|
||||
PRINT_NAS_ERROR("Buffer length is too short to encode the GPRS Timer IE\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t *buf = buffer->buf;
|
||||
|
||||
int encoded = 0;
|
||||
// IEI
|
||||
buf[encoded++] = iei;
|
||||
// length
|
||||
buf[encoded++] = 1; // length field (1 octet)
|
||||
// Unit and value (1 octet)
|
||||
uint8_t encoded_byte = 0;
|
||||
encoded_byte |= (timer->unit & 0x07) << 5;
|
||||
encoded_byte |= timer->value & 0x1F;
|
||||
buf[encoded++] = encoded_byte;
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
/* Decode GPRS Timer IE (3GPP TS 24.008 10.5.7.3) */
|
||||
int decode_gprs_timer_ie(gprs_timer_t *timer, const byte_array_t *buffer)
|
||||
{
|
||||
int decoded = 1; // Skip length ie (1 octet)
|
||||
// Extract unit and value
|
||||
uint8_t *buf = buffer->buf;
|
||||
timer->unit = (buf[decoded] >> 5) & 0x07;
|
||||
timer->value = buf[decoded++] & 0x1F;
|
||||
return decoded;
|
||||
}
|
||||
|
||||
/* Decode EAP Message (todo) */
|
||||
int decode_eap_msg_ie(const byte_array_t *buffer)
|
||||
{
|
||||
int eap_msg_len = (buffer->buf[0] << 8) | buffer->buf[1];
|
||||
PRINT_NAS_ERROR("EAP message IE in NAS Service Reject is not handled\n");
|
||||
return eap_msg_len + 2; // content length + 2 octets for the length IE
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
/*
|
||||
* This header file defines structures, macros,
|
||||
* and functions for the handling of common NAS 5GMM IEs.
|
||||
* This library is intended for use within the 5GMM encode/decode library only.
|
||||
*/
|
||||
|
||||
#ifndef FGS_LIB_H
|
||||
#define FGS_LIB_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "fgs_nas_utils.h"
|
||||
#include "common/utils/ds/byte_array.h"
|
||||
|
||||
/* The following defines are valide for
|
||||
both PDU Session Status and PDU session Reactivation Result IEs */
|
||||
#define MIN_PDU_SESSION_CONTENTS_LEN 2
|
||||
#define MAX_PDU_SESSION_CONTENTS_LEN 32
|
||||
#define MAX_NUM_PSI 16
|
||||
#define MAX_NUM_PDU_ERRORS 256
|
||||
|
||||
/* This macro updates the local copy of
|
||||
a byte_array_t pointer used for enc/dec */
|
||||
#define UPDATE_BYTE_ARRAY(ba, shift) \
|
||||
do { \
|
||||
(ba).buf += (shift); \
|
||||
(ba).len -= (shift); \
|
||||
} while (0)
|
||||
|
||||
/* This macro checks the result of the encoder.
|
||||
If successful, it updates the encoded bytes counter
|
||||
and the local copy of the byte_array_t pointer.
|
||||
Otherwise, it returns -1. */
|
||||
#define ENCODE_NAS_IE(ba, exp, encoded) \
|
||||
do { \
|
||||
int ret = (exp); \
|
||||
if (ret < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
(encoded) += ret; \
|
||||
UPDATE_BYTE_ARRAY((ba), ret); \
|
||||
} while (0)
|
||||
|
||||
/* This macro checks the result of the decoder.
|
||||
If successful, it updates the decoded bytes counter
|
||||
and the local copy of the byte_array_t pointer.
|
||||
Otherwise, it returns -1. */
|
||||
#define DECODE_NAS_IE(ba, exp, decoded) \
|
||||
do { \
|
||||
int ret = (exp); \
|
||||
if (ret < 0) { \
|
||||
return -1; \
|
||||
} \
|
||||
(decoded) += ret; \
|
||||
UPDATE_BYTE_ARRAY((ba), ret); \
|
||||
} while (0)
|
||||
|
||||
/* Timer value is incremented in multiples of 2 seconds,
|
||||
1 minute, etc (10.5.7.3 of 3GPP TS 24.008) */
|
||||
#define FOREACH_TIMER_UNIT(TIMER_UNIT) \
|
||||
TIMER_UNIT(TWO_SECONDS, 0x00) \
|
||||
TIMER_UNIT(ONE_MINUTE, 0x01) \
|
||||
TIMER_UNIT(DECIHOURS, 0x02) \
|
||||
TIMER_UNIT(DEACTIVATED, 0x07)
|
||||
|
||||
typedef enum { FOREACH_TIMER_UNIT(TO_ENUM) } GPRS_Timer_t;
|
||||
|
||||
typedef enum { PDU_SESSION_INACTIVE = 0, PDU_SESSION_ACTIVE } PSI_status_t;
|
||||
|
||||
typedef enum { REACTIVATION_SUCCESS = 0, REACTIVATION_FAILED } PSI_reactivation_t;
|
||||
|
||||
#define FOREACH_SA_IEI(IEI_DEF) \
|
||||
IEI_DEF(IEI_PDU_SESSION_STATUS, 0x50) \
|
||||
IEI_DEF(IEI_PDU_SESSION_REACT_RESULT, 0x26) \
|
||||
IEI_DEF(IEI_PDU_SESSION_REACT_RESULT_ERROR_CAUSE, 0x72) \
|
||||
IEI_DEF(IEI_EAPMSG, 0x78) \
|
||||
IEI_DEF(IEI_CAG_INFO_LIST, 0x75) \
|
||||
IEI_DEF(IEI_T3448_VALUE, 0x6B) \
|
||||
IEI_DEF(IEI_T3446_VALUE, 0x5F)
|
||||
|
||||
// Enum for Service Accept IEIs
|
||||
typedef enum { FOREACH_SA_IEI(TO_ENUM) } nas_service_IEI_t;
|
||||
|
||||
static const text_info_t sa_iei_s[] = {FOREACH_SA_IEI(TO_TEXT)};
|
||||
|
||||
// table 9.11.3.2.1
|
||||
#define FOREACH_CAUSE(CAUSE_DEF) \
|
||||
CAUSE_DEF(Illegal_UE, 0x3) \
|
||||
CAUSE_DEF(PEI_not_accepted, 0x5) \
|
||||
CAUSE_DEF(Illegal_ME, 0x6) \
|
||||
CAUSE_DEF(SGS_services_not_allowed, 0x7) \
|
||||
CAUSE_DEF(UE_identity_cannot_be_derived_by_the_network, 0x9) \
|
||||
CAUSE_DEF(Implicitly_de_registered, 0x0a) \
|
||||
CAUSE_DEF(PLMN_not_allowed, 0x0b) \
|
||||
CAUSE_DEF(Tracking_area_not_allowed, 0x0c) \
|
||||
CAUSE_DEF(Roaming_not_allowed_in_this_tracking_area, 0x0d) \
|
||||
CAUSE_DEF(No_suitable_cells_in_tracking_area, 0x0f) \
|
||||
CAUSE_DEF(MAC_failure, 0x14) \
|
||||
CAUSE_DEF(Synch_failure, 0x15) \
|
||||
CAUSE_DEF(Congestion, 0x16) \
|
||||
CAUSE_DEF(UE_security_capabilities_mismatch, 0x17) \
|
||||
CAUSE_DEF(Security_mode_rejected_unspecified, 0x18) \
|
||||
CAUSE_DEF(Non_5G_authentication_unacceptable, 0x1a) \
|
||||
CAUSE_DEF(N1_mode_not_allowed, 0x1b) \
|
||||
CAUSE_DEF(Restricted_service_area, 0x1c) \
|
||||
CAUSE_DEF(Redirection_to_EPC_required, 0x1f) \
|
||||
CAUSE_DEF(LADN_not_available, 0x2b) \
|
||||
CAUSE_DEF(No_network_slices_available, 0x3e) \
|
||||
CAUSE_DEF(Maximum_number_of_PDU_sessions_reached, 0x41) \
|
||||
CAUSE_DEF(Insufficient_resources_for_specific_slice_and_DNN, 0x43) \
|
||||
CAUSE_DEF(Insufficient_resources_for_specific_slice, 0x45) \
|
||||
CAUSE_DEF(ngKSI_already_in_use, 0x47) \
|
||||
CAUSE_DEF(Non_3GPP_access_to_5GCN_not_allowed, 0x48) \
|
||||
CAUSE_DEF(Serving_network_not_authorized, 0x49) \
|
||||
CAUSE_DEF(Temporarily_not_authorized_for_this_SNPN, 0x4A) \
|
||||
CAUSE_DEF(Permanently_not_authorized_for_this_SNPN, 0x4b) \
|
||||
CAUSE_DEF(Not_authorized_for_this_CAG_or_authorized_for_CAG_cells_only, 0x4c) \
|
||||
CAUSE_DEF(Wireline_access_area_not_allowed, 0x4d) \
|
||||
CAUSE_DEF(Payload_was_not_forwarded, 0x5a) \
|
||||
CAUSE_DEF(DNN_not_supported_or_not_subscribed_in_the_slice, 0x5b) \
|
||||
CAUSE_DEF(Insufficient_user_plane_resources_for_the_PDU_session, 0x5c) \
|
||||
CAUSE_DEF(Semantically_incorrect_message, 0x5f) \
|
||||
CAUSE_DEF(Invalid_mandatory_information, 0x60) \
|
||||
CAUSE_DEF(Message_type_non_existent_or_not_implemented, 0x61) \
|
||||
CAUSE_DEF(Message_type_not_compatible_with_the_protocol_state, 0x62) \
|
||||
CAUSE_DEF(Information_element_non_existent_or_not_implemented, 0x63) \
|
||||
CAUSE_DEF(Conditional_IE_error, 0x64) \
|
||||
CAUSE_DEF(Message_not_compatible_with_the_protocol_state, 0x65) \
|
||||
CAUSE_DEF(Protocol_error_unspecified, 0x67)
|
||||
|
||||
typedef enum { FOREACH_CAUSE(TO_ENUM) } cause_id_t;
|
||||
|
||||
/* 10.5.7.3 3GPP TS 24.008 */
|
||||
typedef struct {
|
||||
uint8_t value;
|
||||
uint8_t unit;
|
||||
} gprs_timer_t;
|
||||
|
||||
int encode_pdu_session_ie(byte_array_t *buffer, nas_service_IEI_t iei, const uint8_t *psi);
|
||||
int decode_pdu_session_ie(uint8_t *psi, const byte_array_t *buffer);
|
||||
int encode_gprs_timer_ie(byte_array_t *buffer, nas_service_IEI_t iei, const gprs_timer_t *timer);
|
||||
int decode_gprs_timer_ie(gprs_timer_t *timer, const byte_array_t *buffer);
|
||||
int decode_eap_msg_ie(const byte_array_t *buffer);
|
||||
|
||||
#endif /* FGS_LIB_H */
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdint.h>
|
||||
#include "openair3/UICC/usim_interface.h"
|
||||
#include "fgs_nas_utils.h"
|
||||
#include "fgmm_lib.h"
|
||||
#include "FGSAuthenticationResponse.h"
|
||||
#include "FGSDeregistrationRequestUEOriginating.h"
|
||||
#include "FGSIdentityResponse.h"
|
||||
@@ -111,51 +112,6 @@ typedef enum { FOREACH_HEADER(TO_ENUM) } Security_header_t;
|
||||
|
||||
static const text_info_t security_header_type_s[] = {FOREACH_HEADER(TO_TEXT)};
|
||||
|
||||
// table 9.11.3.2.1
|
||||
#define FOREACH_CAUSE(CAUSE_DEF) \
|
||||
CAUSE_DEF(Illegal_UE,0x3 )\
|
||||
CAUSE_DEF(PEI_not_accepted,0x5 )\
|
||||
CAUSE_DEF(Illegal_ME,0x6 )\
|
||||
CAUSE_DEF(SGS_services_not_allowed,0x7 )\
|
||||
CAUSE_DEF(UE_identity_cannot_be_derived_by_the_network,0x9 )\
|
||||
CAUSE_DEF(Implicitly_de_registered,0x0a )\
|
||||
CAUSE_DEF(PLMN_not_allowed,0x0b )\
|
||||
CAUSE_DEF(Tracking_area_not_allowed,0x0c )\
|
||||
CAUSE_DEF(Roaming_not_allowed_in_this_tracking_area,0x0d )\
|
||||
CAUSE_DEF(No_suitable_cells_in_tracking_area,0x0f )\
|
||||
CAUSE_DEF(MAC_failure,0x14 )\
|
||||
CAUSE_DEF(Synch_failure,0x15 )\
|
||||
CAUSE_DEF(Congestion,0x16 )\
|
||||
CAUSE_DEF(UE_security_capabilities_mismatch,0x17 )\
|
||||
CAUSE_DEF(Security_mode_rejected_unspecified,0x18 )\
|
||||
CAUSE_DEF(Non_5G_authentication_unacceptable,0x1a )\
|
||||
CAUSE_DEF(N1_mode_not_allowed,0x1b )\
|
||||
CAUSE_DEF(Restricted_service_area,0x1c )\
|
||||
CAUSE_DEF(Redirection_to_EPC_required,0x1f )\
|
||||
CAUSE_DEF(LADN_not_available,0x2b )\
|
||||
CAUSE_DEF(No_network_slices_available,0x3e )\
|
||||
CAUSE_DEF(Maximum_number_of_PDU_sessions_reached,0x41 )\
|
||||
CAUSE_DEF(Insufficient_resources_for_specific_slice_and_DNN,0x43 )\
|
||||
CAUSE_DEF(Insufficient_resources_for_specific_slice,0x45 )\
|
||||
CAUSE_DEF(ngKSI_already_in_use,0x47 )\
|
||||
CAUSE_DEF(Non_3GPP_access_to_5GCN_not_allowed,0x48 )\
|
||||
CAUSE_DEF(Serving_network_not_authorized,0x49 )\
|
||||
CAUSE_DEF(Temporarily_not_authorized_for_this_SNPN,0x4A )\
|
||||
CAUSE_DEF(Permanently_not_authorized_for_this_SNPN,0x4b )\
|
||||
CAUSE_DEF(Not_authorized_for_this_CAG_or_authorized_for_CAG_cells_only,0x4c )\
|
||||
CAUSE_DEF(Wireline_access_area_not_allowed,0x4d )\
|
||||
CAUSE_DEF(Payload_was_not_forwarded,0x5a )\
|
||||
CAUSE_DEF(DNN_not_supported_or_not_subscribed_in_the_slice,0x5b )\
|
||||
CAUSE_DEF(Insufficient_user_plane_resources_for_the_PDU_session,0x5c )\
|
||||
CAUSE_DEF(Semantically_incorrect_message,0x5f )\
|
||||
CAUSE_DEF(Invalid_mandatory_information,0x60 )\
|
||||
CAUSE_DEF(Message_type_non_existent_or_not_implemented,0x61 )\
|
||||
CAUSE_DEF(Message_type_not_compatible_with_the_protocol_state,0x62 )\
|
||||
CAUSE_DEF(Information_element_non_existent_or_not_implemented,0x63 )\
|
||||
CAUSE_DEF(Conditional_IE_error,0x64 )\
|
||||
CAUSE_DEF(Message_not_compatible_with_the_protocol_state,0x65 )\
|
||||
CAUSE_DEF(Protocol_error_unspecified,0x67 )
|
||||
|
||||
/* Map task id to printable name. */
|
||||
#define CAUSE_TEXT(LabEl, nUmID) {nUmID, #LabEl},
|
||||
|
||||
@@ -163,11 +119,8 @@ static const text_info_t cause_text_info[] = {
|
||||
FOREACH_CAUSE(TO_TEXT)
|
||||
};
|
||||
|
||||
#define CAUSE_ENUM(LabEl, nUmID ) LabEl = nUmID,
|
||||
#define CAUSE_ENUM(LabEl, nUmID) LabEl = nUmID,
|
||||
//! Tasks id of each task
|
||||
typedef enum {
|
||||
FOREACH_CAUSE(TO_ENUM)
|
||||
} cause_id_t;
|
||||
|
||||
//_table_9.11.4.2.1:_5GSM_cause_information_element
|
||||
#define FOREACH_CAUSE_SECU(CAUSE_SECU_DEF) \
|
||||
|
||||
Reference in New Issue
Block a user