Refactor 5GS registration type encoding (9.11.3.7 of 3GPP TS 24.501)
This commit is contained in:
@@ -30,11 +30,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "TLVEncoder.h"
|
||||
#include "TLVDecoder.h"
|
||||
#include "FGSRegistrationType.h"
|
||||
|
||||
#define NO_FOLLOW_ON_REQUEST 0x0
|
||||
#define FOLLOW_ON_REQUEST 0x08
|
||||
|
||||
int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8_t iei, uint8_t value, uint32_t len)
|
||||
{
|
||||
int decoded = 0;
|
||||
@@ -49,14 +52,14 @@ int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8
|
||||
return decoded;
|
||||
}
|
||||
|
||||
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype)
|
||||
/**
|
||||
* @brief Encode 5GS registration type (9.11.3.7 of 3GPP TS 24.501)
|
||||
* Note: mandatory IE (IEI = 0)
|
||||
*/
|
||||
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype, bool follow_on_request)
|
||||
{
|
||||
uint8_t bufferReturn;
|
||||
uint8_t *buffer = &bufferReturn;
|
||||
uint8_t encoded = 0;
|
||||
uint8_t iei = 0;
|
||||
*(buffer + encoded) = 0x00 | (iei & 0xf0) | 0x8 | (*fgsregistrationtype & 0x7);
|
||||
encoded++;
|
||||
|
||||
return bufferReturn;
|
||||
// Follow-on request bit
|
||||
uint8_t foR = follow_on_request ? FOLLOW_ON_REQUEST : NO_FOLLOW_ON_REQUEST;
|
||||
// Return encoded value
|
||||
return (foR | (*fgsregistrationtype & 0x7));
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "OctetString.h"
|
||||
|
||||
#ifndef FGS_REGISTRATION_TYPE_H_
|
||||
@@ -41,13 +41,15 @@
|
||||
typedef uint8_t FGSRegistrationType;
|
||||
|
||||
// clang-format off
|
||||
/* 3GPP TS 24.501 Table 9.11.3.7.1: 5GS registration type IE */
|
||||
#define INITIAL_REGISTRATION 0b001
|
||||
#define MOBILITY_REGISTRATION_UPDATING 0b010
|
||||
#define PERIODIC_REGISTRATION_UPDATING 0b011
|
||||
#define EMERGENCY_REGISTRATION 0b100
|
||||
#define REG_TYPE_RESERVED 0b111
|
||||
// clang-format on
|
||||
|
||||
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype);
|
||||
int encode_5gs_registration_type(const FGSRegistrationType *fgsregistrationtype, bool follow_on_request);
|
||||
|
||||
int decode_5gs_registration_type(FGSRegistrationType *fgsregistrationtype, uint8_t iei, uint8_t value, uint32_t len);
|
||||
|
||||
|
||||
@@ -72,9 +72,10 @@ int encode_registration_request(const registration_request_msg *registration_req
|
||||
{
|
||||
int encoded = 0;
|
||||
int encode_result = 0;
|
||||
bool is_for = true; // Follow-on request pending
|
||||
|
||||
*(buffer + encoded) = ((encode_nas_key_set_identifier(®istration_request->naskeysetidentifier, IEI_NULL) & 0x0f) << 4)
|
||||
| (encode_5gs_registration_type(®istration_request->fgsregistrationtype) & 0x0f);
|
||||
| (encode_5gs_registration_type(®istration_request->fgsregistrationtype, is_for) & 0x0f);
|
||||
encoded++;
|
||||
|
||||
if ((encode_result = encode_5gs_mobile_identity(®istration_request->fgsmobileidentity, 0, buffer + encoded, len - encoded))
|
||||
|
||||
Reference in New Issue
Block a user