Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
OpenXG-AMF
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenXG
OpenXG-AMF
Commits
b9e37eb1
Commit
b9e37eb1
authored
Jan 09, 2023
by
Tien Thinh NGUYEN
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First update 5GSMobileIdentity
parent
a0052e37
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
237 additions
and
138 deletions
+237
-138
src/nas/common/Ie_Const.hpp
src/nas/common/Ie_Const.hpp
+4
-1
src/nas/ies/5GSMobileIdentity.cpp
src/nas/ies/5GSMobileIdentity.cpp
+94
-116
src/nas/ies/5GSMobileIdentity.hpp
src/nas/ies/5GSMobileIdentity.hpp
+12
-11
src/nas/ies/NSSAI.cpp
src/nas/ies/NSSAI.cpp
+1
-1
src/nas/ies/Type4NasIe.cpp
src/nas/ies/Type4NasIe.cpp
+16
-0
src/nas/ies/Type4NasIe.hpp
src/nas/ies/Type4NasIe.hpp
+3
-0
src/nas/ies/Type6NasIe.cpp
src/nas/ies/Type6NasIe.cpp
+91
-3
src/nas/ies/Type6NasIe.hpp
src/nas/ies/Type6NasIe.hpp
+9
-0
src/nas/msgs/RegistrationAccept.cpp
src/nas/msgs/RegistrationAccept.cpp
+2
-2
src/nas/msgs/RegistrationRequest.cpp
src/nas/msgs/RegistrationRequest.cpp
+1
-1
src/nas/msgs/RegistrationRequest.hpp
src/nas/msgs/RegistrationRequest.hpp
+1
-1
src/nas/msgs/SecurityModeComplete.cpp
src/nas/msgs/SecurityModeComplete.cpp
+3
-2
No files found.
src/nas/common/Ie_Const.hpp
View file @
b9e37eb1
...
...
@@ -112,6 +112,9 @@ constexpr uint8_t kIeiRejectedNssaiRr = 0x69;
constexpr
uint8_t
kIeiEpsNasMessageContainer
=
0x70
;
constexpr
uint8_t
kIeiNasMessageContainer
=
0x71
;
constexpr
uint8_t
kIei5gGuti
=
0x77
;
constexpr
uint8_t
kIeiEapMessage
=
0x78
;
constexpr
uint8_t
kIeiImeisv
=
0x77
;
constexpr
uint8_t
kIeiNonImeisvPei
=
0x78
;
constexpr
uint8_t
kIeiEapMessage
=
0x78
;
// TODO: to be verified
constexpr
uint8_t
kIeiPayloadContainer
=
0x7b
;
// Should be verified (kIeiExtendedProtocolConfigurationOptions)
src/nas/ies/5GSMobileIdentity.cpp
View file @
b9e37eb1
...
...
@@ -32,30 +32,24 @@
using
namespace
nas
;
//------------------------------------------------------------------------------
_5GSMobileIdentity
::
_5GSMobileIdentity
()
{
iei_
=
0
;
_5g_guti
=
std
::
nullopt
;
_imei
=
std
::
nullopt
;
supi_format_imsi
=
std
::
nullopt
;
_5g_s_tmsi
=
std
::
nullopt
;
_IMEISV
=
std
::
nullopt
;
length
=
0
;
typeOfIdentity
=
0
;
_5GSMobileIdentity
::
_5GSMobileIdentity
()
:
Type6NasIe
()
{
typeOfIdentity
=
0
;
clearIe
();
SetIeName
(
k5gsMobileIdentityIeName
);
}
//------------------------------------------------------------------------------
_5GSMobileIdentity
::
_5GSMobileIdentity
(
uint8_t
iei
)
:
iei_
(
iei
)
{
_5g_guti
=
std
::
nullopt
;
_imei
=
std
::
nullopt
;
supi_format_imsi
=
std
::
nullopt
;
_5g_s_tmsi
=
std
::
nullopt
;
_IMEISV
=
std
::
nullopt
;
length
=
0
;
typeOfIdentity
=
0
;
_5GSMobileIdentity
::
_5GSMobileIdentity
(
uint8_t
iei
)
:
Type6NasIe
(
iei
)
{
typeOfIdentity
=
0
;
clearIe
();
SetIeName
(
k5gsMobileIdentityIeName
);
}
//------------------------------------------------------------------------------
void
_5GSMobileIdentity
::
clear
()
{
_5GSMobileIdentity
::~
_5GSMobileIdentity
()
{}
//------------------------------------------------------------------------------
void
_5GSMobileIdentity
::
clearIe
()
{
_5g_guti
=
std
::
nullopt
;
_imei
=
std
::
nullopt
;
supi_format_imsi
=
std
::
nullopt
;
...
...
@@ -63,27 +57,17 @@ void _5GSMobileIdentity::clear() {
_IMEISV
=
std
::
nullopt
;
}
//------------------------------------------------------------------------------
_5GSMobileIdentity
::~
_5GSMobileIdentity
()
{}
//------------------------------------------------------------------------------
void
_5GSMobileIdentity
::
setIEI
(
uint8_t
iei
)
{
iei_
=
iei
;
}
//------------------------------------------------------------------------------
int
_5GSMobileIdentity
::
_5g_s_tmsi_encode2buffer
(
uint8_t
*
buf
,
int
len
)
{
Logger
::
nas_mm
().
debug
(
"Encoding 5GSMobilityIdentity 5G-S-TMSI"
);
if
(
!
_5g_s_tmsi
.
has_value
())
return
KEncodeDecodeError
;
int
encoded_size
=
0
;
if
(
iei_
)
{
ENCODE_U8
(
buf
+
encoded_size
,
iei_
,
encoded_size
);
}
// LENGTH
uint16_t
ie_len
=
0x0007
;
// fix with 7 bytes
ENCODE_U16
(
buf
+
encoded_size
,
ie_len
,
encoded_size
);
// IEI and Length
int
encoded_header_size
=
Type6NasIe
::
Encode
(
buf
+
encoded_size
,
len
);
if
(
encoded_header_size
==
KEncodeDecodeError
)
return
KEncodeDecodeError
;
encoded_size
+=
encoded_header_size
;
// Type of identity
ENCODE_U8
(
buf
+
encoded_size
,
0xf0
|
_5G_S_TMSI
,
encoded_size
);
...
...
@@ -114,7 +98,7 @@ int _5GSMobileIdentity::_5g_s_tmsi_decodefrombuffer(uint8_t* buf, int len) {
_5G_S_TMSI_t
_5g_s_tmsi_tmp
=
{};
uint8_t
octet
=
0
;
// Type of Identity
//
Decode SUPI format/
Type of Identity
DECODE_U8
(
buf
+
decoded_size
,
octet
,
decoded_size
);
// TODO: validate Type of Identity
...
...
@@ -152,7 +136,7 @@ void _5GSMobileIdentity::set5G_S_TMSI(
const
uint16_t
amf_set_id
,
const
uint8_t
amf_pointer
,
const
std
::
string
&
tmsi
)
{
// Clear all identity types first
clear
();
clear
Ie
();
// Set value for 5GS TMSI
_5G_S_TMSI_t
_5g_s_tmsi_tmp
=
{};
...
...
@@ -162,8 +146,7 @@ void _5GSMobileIdentity::set5G_S_TMSI(
_5g_s_tmsi_tmp
.
_5g_tmsi
=
tmsi
;
_5g_s_tmsi
=
std
::
optional
<
_5G_S_TMSI_t
>
(
_5g_s_tmsi_tmp
);
// TODO: length
SetLengthIndicator
(
k5gsMobileIdentityIe5gSTmsiLength
);
}
//------------------------------------------------------------------------------
...
...
@@ -172,7 +155,7 @@ void _5GSMobileIdentity::set5GGUTI(
const
uint8_t
&
amf_region_id
,
const
uint16_t
&
amf_set_id
,
const
uint8_t
&
amf_pointer
,
const
uint32_t
&
_5g_tmsi
)
{
// Clear all identity types first
clear
();
clear
Ie
();
// Set value for 5G GUTI
typeOfIdentity
=
_5G_GUTI
;
...
...
@@ -184,7 +167,7 @@ void _5GSMobileIdentity::set5GGUTI(
tmp
.
amf_pointer
=
amf_pointer
;
tmp
.
_5g_tmsi
=
_5g_tmsi
;
_5g_guti
=
std
::
optional
<
_5G_GUTI_t
>
(
tmp
);
length
=
k5gMobileIdentityIe5gGutiLength
;
SetLengthIndicator
(
k5gsMobileIdentityIe5gGutiLength
)
;
}
//------------------------------------------------------------------------------
...
...
@@ -198,7 +181,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
const
std
::
string
&
routing_ind
,
const
uint8_t
protection_sch_id
,
const
std
::
string
&
msin
)
{
// Clear all identity types first
clear
();
clear
Ie
();
// Set value for SUCI/SUPI format IMSI
SUCI_imsi_t
supi_format_imsi_tmp
=
{};
...
...
@@ -213,7 +196,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
supi_format_imsi_tmp
.
protectionSchemeId
=
protection_sch_id
;
supi_format_imsi_tmp
.
homeNetworkPKI
=
HOME_NETWORK_PKI_0_WHEN_PSI_0
;
supi_format_imsi_tmp
.
msin
=
msin
;
length
=
10
+
ceil
(
msin
.
length
()
/
2
);
SetLengthIndicator
(
10
+
ceil
(
msin
.
length
()
/
2
)
);
supi_format_imsi
=
std
::
optional
<
SUCI_imsi_t
>
(
supi_format_imsi_tmp
);
}
...
...
@@ -224,7 +207,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
const
std
::
string
&
routing_ind
,
const
uint8_t
protection_sch_id
,
const
uint8_t
home_pki
,
const
std
::
string
&
msin_digits
)
{
// Clear all identity types first
clear
();
clear
Ie
();
// Set value for SUCI/SUPI format IMSI
SUCI_imsi_t
supi_format_imsi_tmp
=
{};
...
...
@@ -233,6 +216,7 @@ void _5GSMobileIdentity::setSuciWithSupiImsi(
supi_format_imsi_tmp
.
mcc
=
mcc
;
supi_format_imsi_tmp
.
mnc
=
mnc
;
supi_format_imsi
=
std
::
optional
<
SUCI_imsi_t
>
(
supi_format_imsi_tmp
);
// TODO: SetLengthIndicator();
}
//------------------------------------------------------------------------------
...
...
@@ -245,11 +229,11 @@ bool _5GSMobileIdentity::getSuciWithSupiImsi(SUCI_imsi_t& suci) const {
//------------------------------------------------------------------------------
void
_5GSMobileIdentity
::
setIMEISV
(
const
IMEISV_t
&
imeisv
)
{
// Clear all identity types first
clear
();
clear
Ie
();
// Set value for IMEISV
typeOfIdentity
=
IMEISV
;
length
=
blength
(
imeisv
.
identity
)
-
1
+
4
;
typeOfIdentity
=
IMEISV
;
//
length = blength(imeisv.identity) - 1 + 4;
IMEISV_t
IMEISV_tmp
=
{};
IMEISV_tmp
.
identity
=
bstrcpy
(
imeisv
.
identity
);
IMEISV_tmp
.
identity
->
data
[
blength
(
imeisv
.
identity
)
-
1
]
|=
0xf0
;
...
...
@@ -265,6 +249,7 @@ bool _5GSMobileIdentity::getIMEISV(IMEISV_t& imeisv) const {
//------------------------------------------------------------------------------
int
_5GSMobileIdentity
::
encode2Buffer
(
uint8_t
*
buf
,
int
len
)
{
Logger
::
nas_mm
().
debug
(
"Encoding %s"
,
GetIeName
().
c_str
());
switch
(
typeOfIdentity
)
{
case
SUCI
:
{
return
suci_encode2buffer
(
buf
,
len
);
...
...
@@ -290,19 +275,14 @@ int _5GSMobileIdentity::suci_encode2buffer(uint8_t* buf, int len) {
Logger
::
nas_mm
().
debug
(
"Encoding SUCI"
);
if
(
!
supi_format_imsi
.
has_value
())
return
KEncodeDecodeError
;
if
(
len
<
length
)
{
Logger
::
nas_mm
().
debug
(
"Error: len is less than %d"
,
length
);
return
KEncodeDecodeError
;
}
int
encoded_size
=
0
;
if
(
iei_
)
{
Logger
::
nas_mm
().
debug
(
"Decoding 5GSMobilityIdentity IEI 0x%x"
,
typeOfIdentity
);
ENCODE_U8
(
buf
+
encoded_size
,
iei_
,
encoded_size
);
}
encoded_size
+=
2
;
// For encode Lengh IE later on
// IEI and Length
int
len_pos
=
0
;
int
encoded_header_size
=
Type6NasIe
::
Encode
(
buf
+
encoded_size
,
len
,
len_pos
);
if
(
encoded_header_size
==
KEncodeDecodeError
)
return
KEncodeDecodeError
;
encoded_size
+=
encoded_header_size
;
// SUPI format + Type of Identity
ENCODE_U8
(
...
...
@@ -349,13 +329,10 @@ int _5GSMobileIdentity::suci_encode2buffer(uint8_t* buf, int len) {
ENCODE_U8
(
buf
+
encoded_size
,
octet
,
encoded_size
);
}
// Encode
L
ength
// Encode
l
ength
int
encoded_len_ie
=
0
;
if
(
!
iei_
)
{
ENCODE_U16
(
buf
,
encoded_size
-
2
,
encoded_len_ie
);
}
else
{
ENCODE_U16
(
buf
+
1
,
encoded_size
-
3
,
encoded_len_ie
);
}
ENCODE_U16
(
buf
+
len_pos
,
encoded_size
-
GetHeaderLength
(),
encoded_len_ie
);
Logger
::
nas_mm
().
debug
(
"Encoded SUCI IE (len %d octets)"
,
encoded_size
);
return
encoded_size
;
}
...
...
@@ -363,22 +340,25 @@ int _5GSMobileIdentity::suci_encode2buffer(uint8_t* buf, int len) {
//------------------------------------------------------------------------------
int
_5GSMobileIdentity
::
_5g_guti_encode2buffer
(
uint8_t
*
buf
,
int
len
)
{
Logger
::
nas_mm
().
debug
(
"Encoding 5G-GUTI IEI 0x%x"
,
iei_
);
if
(
len
<
length
)
Logger
::
nas_mm
().
debug
(
"Error: len is less than %d"
,
length
);
int
encoded_size
=
0
;
if
(
iei_
)
{
Logger
::
nas_mm
().
debug
(
"Encoding 5GSMobilityIdentity type 0x%x"
,
typeOfIdentity
);
ENCODE_U8
(
buf
+
encoded_size
,
iei_
,
encoded_size
);
}
encoded_size
+=
2
;
// store length, do it later
// IEI and Length
int
len_pos
=
0
;
int
encoded_header_size
=
Type6NasIe
::
Encode
(
buf
+
encoded_size
,
len
,
len_pos
);
if
(
encoded_header_size
==
KEncodeDecodeError
)
return
KEncodeDecodeError
;
encoded_size
+=
encoded_header_size
;
// Type of Identity
ENCODE_U8
(
buf
+
encoded_size
,
0xf0
|
_5G_GUTI
,
encoded_size
);
// Type of Identity
// MCC/MNC
encoded_size
+=
NasUtils
::
encodeMccMnc2Buffer
(
_5g_guti
.
value
().
mcc
,
_5g_guti
.
value
().
mnc
,
buf
+
encoded_size
,
len
-
encoded_size
);
// AMF Region ID
ENCODE_U8
(
buf
+
encoded_size
,
_5g_guti
.
value
().
amf_region_id
,
encoded_size
);
// AMF Set Id/AMF pointer
ENCODE_U8
(
buf
+
encoded_size
,
((
_5g_guti
.
value
().
amf_set_id
&
0x03ff
)
>>
2
),
encoded_size
);
...
...
@@ -392,17 +372,22 @@ int _5GSMobileIdentity::_5g_guti_encode2buffer(uint8_t* buf, int len) {
uint32_t
tmsi
=
_5g_guti
.
value
().
_5g_tmsi
;
ENCODE_U32
(
buf
+
encoded_size
,
tmsi
,
encoded_size
);
// Encode Len
uint8_t
ie_len
=
0
;
uint8_t
encoded_size_tmp
=
0
;
if
(
!
iei_
)
{
ie_len
=
encoded_size
-
2
;
encoded_size_tmp
=
0
;
}
else
{
ie_len
=
encoded_size
-
3
;
encoded_size_tmp
=
1
;
}
ENCODE_U16
(
buf
+
encoded_size_tmp
,
ie_len
,
encoded_size_tmp
);
/* // Encode Len
uint8_t ie_len = 0;
uint8_t encoded_size_tmp = 0;
if (!iei_) {
ie_len = encoded_size - 2;
encoded_size_tmp = 0;
} else {
ie_len = encoded_size - 3;
encoded_size_tmp = 1;
}
ENCODE_U16(buf + encoded_size_tmp, ie_len, encoded_size_tmp);
*/
// Encode length
int
encoded_len_ie
=
0
;
ENCODE_U16
(
buf
+
len_pos
,
encoded_size
-
GetHeaderLength
(),
encoded_len_ie
);
Logger
::
nas_mm
().
debug
(
"Encoded 5G-GUTI IE (len %d octets)"
,
encoded_size
);
return
encoded_size
;
...
...
@@ -464,52 +449,44 @@ int _5GSMobileIdentity::encodeMSIN2buffer(
int
_5GSMobileIdentity
::
imeisv_encode2buffer
(
uint8_t
*
buf
,
int
len
)
{
Logger
::
nas_mm
().
debug
(
"Encoding IMEISV IE"
);
if
(
!
_IMEISV
.
has_value
())
return
KEncodeDecodeError
;
if
(
len
<
length
)
{
Logger
::
nas_mm
().
debug
(
"Error: len is less than %d"
,
length
);
// TODO
// return KEncodeDecodeError;
}
int
encoded_size
=
0
;
if
(
iei_
)
{
Logger
::
nas_mm
().
debug
(
"Encoding 5GSMobilityIdentity IEI 0x%x"
,
typeOfIdentity
);
ENCODE_U8
(
buf
+
encoded_size
,
iei_
,
encoded_size
);
}
encoded_size
+=
2
;
// Skip len for now
int
encoded_size
=
0
;
int
len_pos
=
0
;
// IEI and Length
int
encoded_header_size
=
Type6NasIe
::
Encode
(
buf
+
encoded_size
,
len
,
len_pos
);
if
(
encoded_header_size
==
KEncodeDecodeError
)
return
KEncodeDecodeError
;
encoded_size
+=
encoded_header_size
;
int
size
=
encode_bstring
(
_IMEISV
.
value
().
identity
,
(
buf
+
encoded_size
),
len
-
encoded_size
);
encoded_size
+=
size
;
// Update Type of identity (3 bits of Octet 4)
*
(
buf
+
3
)
|=
(
0x01
<<
3
)
|
IMEISV
;
// Update Type of identity (3 bits of Octet
3/
4)
*
(
buf
+
GetHeaderLength
()
)
|=
(
0x01
<<
3
)
|
IMEISV
;
// TODO: odd/even indic
// Encode length
int
encoded_len
=
0
;
if
(
!
iei_
)
{
ENCODE_U16
(
buf
,
encoded_size
-
2
,
encoded_len
);
}
else
{
ENCODE_U16
(
buf
+
1
,
encoded_size
-
3
,
encoded_len
);
}
int
encoded_len_ie
=
0
;
ENCODE_U16
(
buf
+
len_pos
,
encoded_size
-
GetHeaderLength
(),
encoded_len_ie
);
Logger
::
nas_mm
().
debug
(
"Encoded IMEISV IE (len %d octets)"
,
encoded_size
);
return
encoded_size
;
}
//------------------------------------------------------------------------------
int
_5GSMobileIdentity
::
decodeFromBuffer
(
uint8_t
*
buf
,
int
len
,
bool
is_option
)
{
int
_5GSMobileIdentity
::
decodeFromBuffer
(
uint8_t
*
buf
,
int
len
,
bool
is_iei
)
{
Logger
::
nas_mm
().
debug
(
"Decoding 5GSMobilityIdentity"
);
int
decoded_size
=
0
;
if
(
is_option
)
{
DECODE_U8
(
buf
+
decoded_size
,
iei_
,
decoded_size
);
}
DECODE_U16
(
buf
+
decoded_size
,
length
,
decoded_size
);
// IEI and Length
uint16_t
ie_len
=
0
;
int
decoded_header_size
=
Type6NasIe
::
Decode
(
buf
+
decoded_size
,
len
,
is_iei
);
if
(
decoded_header_size
==
KEncodeDecodeError
)
return
KEncodeDecodeError
;
decoded_size
+=
decoded_header_size
;
ie_len
=
GetLengthIndicator
();
Logger
::
amf_n1
().
debug
(
"Decoded 5GSMobilityIdentity IE length %d"
,
length
);
Logger
::
amf_n1
().
debug
(
"Decoded 5GSMobilityIdentity IE length %d"
,
ie_len
);
int
decoded_size_tmp
=
0
;
uint8_t
octet
=
0
;
...
...
@@ -522,34 +499,34 @@ int _5GSMobileIdentity::decodeFromBuffer(
case
SUCI
:
{
typeOfIdentity
=
SUCI
;
decoded_size
+=
suci_decodefrombuffer
(
buf
+
decoded_size
,
len
-
decoded_size
,
length
);
suci_decodefrombuffer
(
buf
+
decoded_size
,
len
-
decoded_size
,
ie_len
);
Logger
::
nas_mm
().
debug
(
"Decoded SUCI (%d octets)"
,
decoded_size
);
return
decoded_size
;
}
break
;
case
_5G_GUTI
:
{
typeOfIdentity
=
_5G_GUTI
;
decoded_size
+=
_5g_guti_decodefrombuffer
(
buf
+
decoded_size
,
len
-
decoded_size
);
return
decoded_size
;
}
break
;
// TODO: IMEI
case
_5G_S_TMSI
:
{
typeOfIdentity
=
_5G_S_TMSI
;
decoded_size
+=
_5g_s_tmsi_decodefrombuffer
(
buf
+
decoded_size
,
len
-
decoded_size
);
return
decoded_size
;
}
break
;
case
IMEISV
:
{
typeOfIdentity
=
IMEISV
;
decoded_size
+=
imeisv_decodefrombuffer
(
buf
+
decoded_size
,
length
);
return
decoded_size
;
decoded_size
+=
imeisv_decodefrombuffer
(
buf
+
decoded_size
,
ie_len
);
}
break
;
// TODO: MAC Address
default:
{
// TODO:
return
0
;
}
}
return
0
;
Logger
::
nas_mm
().
debug
(
"Decoded %s, len (%d)"
,
GetIeName
().
c_str
(),
decoded_size
);
return
decoded_size
;
}
//------------------------------------------------------------------------------
...
...
@@ -559,7 +536,7 @@ int _5GSMobileIdentity::suci_decodefrombuffer(
int
decoded_size
=
0
;
uint8_t
octet
=
0
;
//
Starting from 3rd Octet
//
Decode SUPI format/Type of Identity
DECODE_U8
(
buf
+
decoded_size
,
octet
,
decoded_size
);
switch
((
octet
&
0x70
)
>>
4
)
{
...
...
@@ -655,10 +632,11 @@ int _5GSMobileIdentity::suci_decodefrombuffer(
//------------------------------------------------------------------------------
int
_5GSMobileIdentity
::
_5g_guti_decodefrombuffer
(
uint8_t
*
buf
,
int
len
)
{
Logger
::
nas_mm
().
debug
(
"Decoding 5GSMobilityIdentity 5G-GUTI"
);
// Starting from Octet 3 (Type of Identity)
int
decoded_size
=
0
;
uint8_t
octet
=
0
;
// Decode SUPI format/Type of Identity
DECODE_U8
(
buf
+
decoded_size
,
octet
,
decoded_size
);
// Type of Identity
// TODO:validate Type of Identity
...
...
src/nas/ies/5GSMobileIdentity.hpp
View file @
b9e37eb1
...
...
@@ -22,17 +22,20 @@
#ifndef _5GS_MOBILE_IDENTITY_H_
#define _5GS_MOBILE_IDENTITY_H_
#include "Type6NasIe.hpp"
#include "struct.hpp"
#include <stdint.h>
#include <optional>
#include "struct.hpp"
extern
"C"
{
#include "TLVDecoder.h"
#include "TLVEncoder.h"
#include "bstrlib.h"
}
constexpr
uint8_t
k5gMobileIdentityIe5gGutiLength
=
14
;
constexpr
uint8_t
k5gsMobileIdentityIe5gGutiLength
=
11
;
constexpr
uint8_t
k5gsMobileIdentityIe5gSTmsiLength
=
7
;
constexpr
auto
k5gsMobileIdentityIeName
=
"5GS Mobile Identity"
;
namespace
nas
{
...
...
@@ -83,18 +86,17 @@ typedef struct _5G_S_TMSI_s {
// TODO: 5GS mobile identity information element for type of identity "MAC
// address"
class
_5GSMobileIdentity
{
class
_5GSMobileIdentity
:
public
Type6NasIe
{
public:
_5GSMobileIdentity
();
_5GSMobileIdentity
(
uint8_t
iei
);
~
_5GSMobileIdentity
();
// Common
void
clear
();
void
clear
Ie
();
uint8_t
getTypeOfIdentity
()
const
{
return
typeOfIdentity
;
};
void
setIEI
(
uint8_t
iei
);
int
encode2Buffer
(
uint8_t
*
buf
,
int
len
);
int
decodeFromBuffer
(
uint8_t
*
buf
,
int
len
,
bool
is_
option
);
int
decodeFromBuffer
(
uint8_t
*
buf
,
int
len
,
bool
is_
iei
);
// 5G GUTI
int
_5g_guti_decodefrombuffer
(
uint8_t
*
buf
,
int
len
);
...
...
@@ -113,7 +115,6 @@ class _5GSMobileIdentity {
const
std
::
string
&
mcc
,
const
std
::
string
&
mnc
,
const
std
::
string
&
routing_ind
,
const
uint8_t
protection_sch_id
,
const
std
::
string
&
msin
);
// TODO: SetSUCI, SUCI and SUPI format IMSI
void
setSuciWithSupiImsi
(
const
std
::
string
&
mcc
,
const
std
::
string
&
mnc
,
const
std
::
string
&
routing_ind
,
const
uint8_t
protection_sch_id
,
...
...
@@ -127,12 +128,12 @@ class _5GSMobileIdentity {
// TMSI
int
_5g_s_tmsi_decodefrombuffer
(
uint8_t
*
buf
,
int
len
);
int
_5g_s_tmsi_encode2buffer
(
uint8_t
*
buf
,
int
len
);
bool
get5G_S_TMSI
(
uint16_t
&
amf_set_id
,
uint8_t
&
amf_pointer
,
std
::
string
&
tmsi
)
const
;
void
set5G_S_TMSI
(
const
uint16_t
amf_set_id
,
const
uint8_t
amf_pointer
,
const
std
::
string
&
tmsi
);
bool
get5G_S_TMSI
(
uint16_t
&
amf_set_id
,
uint8_t
&
amf_pointer
,
std
::
string
&
tmsi
)
const
;
// IMEISV
int
imeisv_encode2buffer
(
uint8_t
*
buf
,
int
len
);
...
...
@@ -142,8 +143,8 @@ class _5GSMobileIdentity {
bool
getIMEISV
(
IMEISV_t
&
imeisv
)
const
;
private:
uint8_t
iei_
;
uint16_t
length
;
//
uint8_t iei_;
//
uint16_t length;
uint8_t
typeOfIdentity
:
3
;
std
::
optional
<
SUCI_imsi_t
>
supi_format_imsi
;
...
...
src/nas/ies/NSSAI.cpp
View file @
b9e37eb1
...
...
@@ -41,7 +41,7 @@ NSSAI::NSSAI(uint8_t iei, const std::vector<struct SNSSAI_s>& nssai)
int
length
=
0
;
S_NSSAIs
.
assign
(
nssai
.
begin
(),
nssai
.
end
());
for
(
int
i
=
0
;
i
<
nssai
.
size
();
i
++
)
{
length
+=
(
1
+
nssai
[
i
].
length
);
// 1 for length
of NSSAI[i]
length
+=
(
1
+
nssai
[
i
].
length
);
// 1 for length
IE
}
SetLengthIndicator
(
length
);
SetIeName
(
kNssaiIeName
);
...
...
src/nas/ies/Type4NasIe.cpp
View file @
b9e37eb1
...
...
@@ -94,6 +94,7 @@ bool Type4NasIe::ValidateHeader(const int& len) const {
}
return
true
;
}
//------------------------------------------------------------------------------
int
Type4NasIe
::
Encode
(
uint8_t
*
buf
,
const
int
&
len
)
{
if
(
!
Validate
(
len
))
return
KEncodeDecodeError
;
...
...
@@ -108,6 +109,21 @@ int Type4NasIe::Encode(uint8_t* buf, const int& len) {
return
encoded_size
;
}
//------------------------------------------------------------------------------
int
Type4NasIe
::
Encode
(
uint8_t
*
buf
,
const
int
&
len
,
int
&
len_pos
)
{
if
(
!
Validate
(
len
))
return
KEncodeDecodeError
;
int
encoded_size
=
0
;
uint8_t
octet
=
0
;
if
(
iei_
.
has_value
())
{
ENCODE_U8
(
buf
+
encoded_size
,
iei_
.
value
(),
encoded_size
);
}
len_pos
=
encoded_size
;
encoded_size
++
;
// IE len will be encoded later
// ENCODE_U8(buf + encoded_size, li_, encoded_size);
return
encoded_size
;
}
//------------------------------------------------------------------------------
int
Type4NasIe
::
Decode
(
const
uint8_t
*
const
buf
,
const
int
&
len
,
bool
is_iei
)
{
if
(
!
ValidateHeader
(
len
))
return
KEncodeDecodeError
;
...
...
src/nas/ies/Type4NasIe.hpp
View file @
b9e37eb1
...
...
@@ -42,6 +42,9 @@ class Type4NasIe : public NasIe {
uint8_t
GetHeaderLength
()
const
;
int
Encode
(
uint8_t
*
buf
,
const
int
&
len
)
override
;
int
Encode
(
uint8_t
*
buf
,
const
int
&
len
,
int
&
len_pos
);
// Use this function to encode IE lengh later
int
Decode
(
const
uint8_t
*
const
buf
,
const
int
&
len
,
bool
is_iei
=
false
)
override
;
...
...
src/nas/ies/Type6NasIe.cpp
View file @
b9e37eb1
...
...
@@ -35,6 +35,7 @@ Type6NasIe::Type6NasIe() : NasIe() {
//------------------------------------------------------------------------------
Type6NasIe
::
Type6NasIe
(
const
uint8_t
&
iei
)
:
NasIe
()
{
iei_
=
std
::
optional
<
uint8_t
>
(
iei
);
li_
=
0
;
}
//------------------------------------------------------------------------------
...
...
@@ -45,14 +46,101 @@ void Type6NasIe::SetIei(const uint8_t& iei) {
iei_
=
std
::
optional
<
uint8_t
>
(
iei
);
}
//------------------------------------------------------------------------------
void
Type6NasIe
::
SetLengthIndicator
(
const
uint16_t
&
li
)
{
li_
=
li
;
}
//------------------------------------------------------------------------------
void
Type6NasIe
::
GetLengthIndicator
(
uint16_t
&
li
)
const
{
li
=
li_
;
}
//------------------------------------------------------------------------------
uint16_t
Type6NasIe
::
GetLengthIndicator
()
const
{
return
li_
;
}
//------------------------------------------------------------------------------
uint16_t
Type6NasIe
::
GetIeLength
()
const
{
return
(
GetHeaderLength
()
+
li_
);
}
//------------------------------------------------------------------------------
uint8_t
Type6NasIe
::
GetHeaderLength
()
const
{
return
(
iei_
.
has_value
()
?
3
:
2
);
// 1 for IEI, 2 for Length
}
//------------------------------------------------------------------------------
bool
Type6NasIe
::
Validate
(
const
int
&
len
)
const
{
uint16_t
actual_lengh
=
iei_
.
has_value
()
?
li_
+
1
:
li_
;
if
(
len
<
actual_lengh
)
{
uint16_t
ie_len
=
GetIeLength
()
;
if
(
len
<
ie_len
)
{
Logger
::
nas_mm
().
error
(
"Buffer length is less than the minimum length of this IE (%d octet)"
,
actual_lengh
);
ie_len
);
return
false
;
}
return
true
;
}
//------------------------------------------------------------------------------
bool
Type6NasIe
::
ValidateHeader
(
const
int
&
len
)
const
{
int
header_len
=
GetHeaderLength
();
// Length of IEI/Len
if
(
len
<
header_len
)
{
Logger
::
nas_mm
().
error
(
"Buffer length is less than the length of the header (IEI/Length) of "
"this IE (%d octet(s))"
,
header_len
);
return
false
;
}
return
true
;
}
//------------------------------------------------------------------------------
int
Type6NasIe
::
Encode
(
uint8_t
*
buf
,
const
int
&
len
)
{
if
(
!
Validate
(
len
))
return
KEncodeDecodeError
;
int
encoded_size
=
0
;
uint8_t
octet
=
0
;
if
(
iei_
.
has_value
())
{
ENCODE_U8
(
buf
+
encoded_size
,
iei_
.
value
(),
encoded_size
);
}
ENCODE_U16
(
buf
+
encoded_size
,
li_
,
encoded_size
);
return
encoded_size
;
}
//------------------------------------------------------------------------------
int
Type6NasIe
::
Encode
(
uint8_t
*
buf
,
const
int
&
len
,
int
&
len_pos
)
{
if
(
!
Validate
(
len
))
return
KEncodeDecodeError
;
int
encoded_size
=
0
;
uint8_t
octet
=
0
;
if
(
iei_
.
has_value
())
{
ENCODE_U8
(
buf
+
encoded_size
,
iei_
.
value
(),
encoded_size
);
}
len_pos
=
encoded_size
;
encoded_size
+=
sizeof
(
uint16_t
);
// ENCODE_U16(buf + encoded_size, li_, encoded_size);
return
encoded_size
;
}
//------------------------------------------------------------------------------
int
Type6NasIe
::
Decode
(
const
uint8_t
*
const
buf
,
const
int
&
len
,
bool
is_iei
)
{
if
(
!
ValidateHeader
(
len
))
return
KEncodeDecodeError
;
int
decoded_size
=
0
;
uint8_t
octet
=
0
;
if
(
is_iei
)
{
DECODE_U8
(
buf
+
decoded_size
,
octet
,
decoded_size
);
iei_
=
std
::
optional
<
uint8_t
>
(
octet
);
}
DECODE_U16
(
buf
+
decoded_size
,
li_
,
decoded_size
);
// after obtaining information for IEI/Length, validate the buffer size
if
(
!
Validate
(
len
))
return
KEncodeDecodeError
;
return
decoded_size
;
}
src/nas/ies/Type6NasIe.hpp
View file @
b9e37eb1
...
...
@@ -32,10 +32,19 @@ class Type6NasIe : public NasIe {
virtual
~
Type6NasIe
();
bool
Validate
(
const
int
&
len
)
const
override
;
bool
ValidateHeader
(
const
int
&
len
)
const
;
void
SetIei
(
const
uint8_t
&
iei
);
void
SetLengthIndicator
(
const
uint16_t
&
li
);
void
GetLengthIndicator
(
uint16_t
&
li
)
const
;
uint16_t
GetLengthIndicator
()
const
;
uint16_t
GetIeLength
()
const
;
uint8_t
GetHeaderLength
()
const
;
int
Encode
(
uint8_t
*
buf
,
const
int
&
len
)
override
;
int
Encode
(
uint8_t
*
buf
,
const
int
&
len
,
int
&
len_pos
);
// Use this function to encode IE lengh later
int
Decode
(
const
uint8_t
*
const
buf
,
const
int
&
len
,
bool
is_iei
=
false
)
override
;
...
...
src/nas/msgs/RegistrationAccept.cpp
View file @
b9e37eb1
...
...
@@ -92,7 +92,7 @@ void RegistrationAccept::setSUCI_SUPI_format_IMSI(
return
;
}
else
{
_5GSMobileIdentity
ie_5g_guti_tmp
=
{};
ie_5g_guti_tmp
.
setIEI
(
kIei5gGuti
);
ie_5g_guti_tmp
.
SetIei
(
kIei5gGuti
);
ie_5g_guti_tmp
.
setSuciWithSupiImsi
(
mcc
,
mnc
,
routingInd
,
protection_sch_id
,
msin
);
ie_5g_guti
=
std
::
optional
<
_5GSMobileIdentity
>
(
ie_5g_guti_tmp
);
...
...
@@ -116,7 +116,7 @@ void RegistrationAccept::set5G_GUTI(
int
regionId
=
fromString
<
int
>
(
amfRegionId
);
int
setId
=
fromString
<
int
>
(
amfSetId
);
int
pointer
=
fromString
<
int
>
(
amfPointer
);
ie_5g_guti_tmp
.
setIEI
(
kIei5gGuti
);
ie_5g_guti_tmp
.
SetIei
(
kIei5gGuti
);
ie_5g_guti_tmp
.
set5GGUTI
(
mcc
,
mnc
,
(
uint8_t
)
regionId
,
(
uint16_t
)
setId
,
(
uint8_t
)
pointer
,
tmsi
);
ie_5g_guti
=
std
::
optional
<
_5GSMobileIdentity
>
(
ie_5g_guti_tmp
);
...
...
src/nas/msgs/RegistrationRequest.cpp
View file @
b9e37eb1
...
...
@@ -136,7 +136,7 @@ void RegistrationRequest::setAdditional_GUTI_SUCI_SUPI_format_IMSI(
const
string
mcc
,
const
string
mnc
,
uint8_t
amf_region_id
,
uint8_t
amf_set_id
,
uint8_t
amf_pointer
,
const
string
_5g_tmsi
)
{
_5GSMobileIdentity
ie_additional_guti_tmp
=
{};
ie_additional_guti_tmp
.
setIEI
(
0x77
);
ie_additional_guti_tmp
.
SetIei
(
kIei5gGuti
);
uint32_t
tmsi
=
fromString
<
uint32_t
>
(
_5g_tmsi
);
ie_additional_guti_tmp
.
set5GGUTI
(
mcc
,
mnc
,
amf_region_id
,
amf_set_id
,
amf_pointer
,
tmsi
);
...
...
src/nas/msgs/RegistrationRequest.hpp
View file @
b9e37eb1
...
...
@@ -160,8 +160,8 @@ class RegistrationRequest : public NasMmPlainHeader {
std
::
optional
<
UplinkDataStatus
>
ie_uplink_data_status
;
// Optional
std
::
optional
<
PDUSessionStatus
>
ie_PDU_session_status
;
// Optional
std
::
optional
<
MicoIndication
>
ie_MICO_indication
;
// Optional
std
::
optional
<
UEStatus
>
ie_ue_status
;
// Optional
std
::
optional
<
UEStatus
>
ie_ue_status
;
// Optional
std
::
optional
<
_5GSMobileIdentity
>
ie_additional_guti
;
// Optional
std
::
optional
<
AllowedPDUSessionStatus
>
ie_allowed_PDU_session_status
;
// Optional
...
...
src/nas/msgs/SecurityModeComplete.cpp
View file @
b9e37eb1
...
...
@@ -29,6 +29,7 @@
#include "SecurityModeComplete.hpp"
#include "3gpp_24.501.hpp"
#include "Ie_Const.hpp"
#include "logger.hpp"
using
namespace
nas
;
...
...
@@ -55,7 +56,7 @@ void SecurityModeComplete::setHeader(uint8_t security_header_type) {
//------------------------------------------------------------------------------
void
SecurityModeComplete
::
setIMEISV
(
IMEISV_t
imeisv
)
{
ie_imeisv
=
new
_5GSMobileIdentity
();
ie_imeisv
->
setIEI
(
0x77
);
ie_imeisv
->
SetIei
(
kIeiImeisv
);
ie_imeisv
->
setIMEISV
(
imeisv
);
}
...
...
@@ -67,7 +68,7 @@ void SecurityModeComplete::setNAS_Message_Container(bstring value) {
//------------------------------------------------------------------------------
void
SecurityModeComplete
::
setNON_IMEISV
(
IMEISV_t
imeisv
)
{
ie_non_imeisvpei
=
new
_5GSMobileIdentity
();
ie_non_imeisvpei
->
setIEI
(
0x78
);
ie_non_imeisvpei
->
SetIei
(
kIeiNonImeisvPei
);
ie_non_imeisvpei
->
setIMEISV
(
imeisv
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment