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
8f64764b
Commit
8f64764b
authored
Nov 15, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup for AMF_N1
parent
77842cc6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
32 additions
and
78 deletions
+32
-78
src/amf-app/amf_n1.cpp
src/amf-app/amf_n1.cpp
+16
-64
src/amf-app/amf_n1.hpp
src/amf-app/amf_n1.hpp
+16
-11
src/amf-app/amf_n11.cpp
src/amf-app/amf_n11.cpp
+0
-1
src/amf-app/amf_n2.cpp
src/amf-app/amf_n2.cpp
+0
-2
No files found.
src/amf-app/amf_n1.cpp
View file @
8f64764b
...
...
@@ -61,9 +61,9 @@
#include "itti_msg_n2.hpp"
#include "logger.hpp"
#include "nas_algorithms.hpp"
#include "sha256.hpp"
#include "comUt.hpp"
#include "3gpp_24.501.h"
#include "sha256.hpp"
extern
"C"
{
#include "bstrlib.h"
...
...
@@ -71,7 +71,6 @@ extern "C" {
}
using
namespace
oai
::
amf
::
model
;
using
namespace
nas
;
using
namespace
amf_application
;
using
namespace
config
;
...
...
@@ -84,10 +83,8 @@ extern amf_app* amf_app_inst;
extern
amf_n2
*
amf_n2_inst
;
extern
statistics
stacs
;
Sha256
ctx
;
random_state_t
random_state
;
static
uint8_t
no_random_delta
=
0
;
static
std
::
map
<
std
::
string
,
std
::
string
>
rand_record
;
uint8_t
amf_n1
::
no_random_delta
=
0
;
std
::
map
<
std
::
string
,
std
::
string
>
amf_n1
::
rand_record
=
{};
void
amf_n1_task
(
void
*
);
...
...
@@ -100,7 +97,7 @@ void amf_n1_task(void*) {
auto
*
msg
=
shared_msg
.
get
();
switch
(
msg
->
msg_type
)
{
case
UL_NAS_DATA_IND
:
{
// receive nas message buffer from amf_n2
case
UL_NAS_DATA_IND
:
{
Logger
::
amf_n1
().
info
(
"Received UL_NAS_DATA_IND"
);
itti_uplink_nas_data_ind
*
m
=
dynamic_cast
<
itti_uplink_nas_data_ind
*>
(
msg
);
...
...
@@ -152,7 +149,7 @@ amf_n1::amf_n1() {
}
Logger
::
amf_n1
().
startup
(
"amf_n1 started"
);
//
S
ubscribe to UE Reachability Status change
//
EventExposure: s
ubscribe to UE Reachability Status change
ee_ue_reachability_status_connection
=
event_sub
.
subscribe_ue_reachability_status
(
boost
::
bind
(
&
amf_n1
::
handle_ue_reachability_status_change
,
this
,
_1
,
_2
));
...
...
@@ -279,7 +276,6 @@ void amf_n1::handle_itti_message(itti_downlink_nas_transfer& itti_msg) {
secu
->
ul_count
.
seq_num
|
(
secu
->
ul_count
.
overflow
<<
8
);
Authentication_5gaka
::
derive_kgnb
(
0
,
0x01
,
kamf
,
kgnb
);
comUt
::
print_buffer
(
"amf_n1"
,
"kamf"
,
kamf
,
32
);
// Authentication_5gaka::derive_kgnb(ulcount, 0x01, kamf, kgnb);
bstring
kgnb_bs
=
blk2bstr
(
kgnb
,
32
);
itti_initial_context_setup_request
*
csr
=
...
...
@@ -412,11 +408,7 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
nc
.
get
()
->
security_ctx
,
NAS_MESSAGE_UPLINK
,
(
uint8_t
*
)
bdata
(
recved_nas_msg
)
+
6
,
blength
(
recved_nas_msg
)
-
6
,
mac32
))
{
// IA0_5G
// decoded_plain_msg = blk2bstr(
// (uint8_t*) bdata(recved_nas_msg) + 7, blength(recved_nas_msg) -
// 7);
Logger
::
amf_n1
().
debug
(
"IA0_5G"
);
}
else
{
bool
isMatched
=
false
;
uint8_t
*
buf
=
(
uint8_t
*
)
bdata
(
recved_nas_msg
);
...
...
@@ -469,7 +461,6 @@ void amf_n1::handle_itti_message(itti_uplink_nas_data_ind& nas_data_ind) {
}
}
// handlers for lower layer
//------------------------------------------------------------------------------
void
amf_n1
::
nas_signalling_establishment_request_handle
(
SecurityHeaderType
type
,
std
::
shared_ptr
<
nas_context
>
nc
,
...
...
@@ -747,7 +738,6 @@ void amf_n1::service_request_handle(
Logger
::
amf_n1
().
debug
(
"Key for pdu session context: SUPI %s"
,
supi
.
c_str
());
// get the status of PDU Session context
std
::
shared_ptr
<
pdu_session_context
>
old_psc
=
{};
if
(
amf_app_inst
->
is_supi_2_ue_context
(
supi
))
{
std
::
shared_ptr
<
ue_context
>
old_uc
=
{};
...
...
@@ -1048,7 +1038,6 @@ void amf_n1::registration_request_handle(
supi2amfId
[(
"imsi-"
+
nc
.
get
()
->
imsi
)]
=
amf_ue_ngap_id
;
supi2ranId
[(
"imsi-"
+
nc
.
get
()
->
imsi
)]
=
ran_ue_ngap_id
;
// test 5g guti //
nc
.
get
()
->
is_auth_vectors_present
=
false
;
nc
.
get
()
->
is_current_security_available
=
false
;
if
(
nc
.
get
()
->
security_ctx
)
...
...
@@ -1200,12 +1189,10 @@ void amf_n1::registration_request_handle(
}
//------------------------------------------------------------------------------
// authentication vector handlers
bool
amf_n1
::
generate_authentication_vector
()
{
return
true
;
}
// context management functions
//------------------------------------------------------------------------------
bool
amf_n1
::
is_amf_ue_id_2_nas_context
(
const
long
&
amf_ue_ngap_id
)
const
{
std
::
shared_lock
lock
(
m_amfueid2nas_context
);
...
...
@@ -1246,7 +1233,6 @@ void amf_n1::set_guti_2_nas_context(
guti2nas_context
[
guti
]
=
nc
;
}
// to lower layer TASK_N2
//------------------------------------------------------------------------------
void
amf_n1
::
itti_send_dl_nas_buffer_to_task_n2
(
bstring
&
b
,
uint32_t
ran_ue_ngap_id
,
long
amf_ue_ngap_id
)
{
...
...
@@ -1389,41 +1375,27 @@ bool amf_n1::get_authentication_vectors_from_ausf(
std
::
string
authenticationinfo_auts
;
std
::
string
authenticationinfo_rand
;
if
(
auts_value
)
{
Logger
::
amf_n1
().
debug
(
"
********* has auts *********
"
);
Logger
::
amf_n1
().
debug
(
"
has auts
"
);
char
*
auts_s
=
(
char
*
)
malloc
(
auts_len
*
2
+
1
);
// char *rand_s = (char *)malloc(RAND_LENGTH * 2 + 1);
memset
(
auts_s
,
0
,
auts_len
*
2
);
// memset(rand_s, 0, sizeof(rand_s));
// uint8_t rand_value[RAND_LENGTH];
Logger
::
amf_n1
().
debug
(
"
********* auts_len (%d) *********
"
,
auts_len
);
Logger
::
amf_n1
().
debug
(
"
auts_len (%d)
"
,
auts_len
);
for
(
int
i
=
0
;
i
<
auts_len
;
i
++
)
{
sprintf
(
&
auts_s
[
i
*
2
],
"%02X"
,
auts_value
[
i
]);
}
authenticationinfo_auts
=
auts_s
;
comUt
::
print_buffer
(
"amf_n1"
,
"********** ausf ***********"
,
auts_value
,
auts_len
);
Logger
::
amf_n1
().
info
(
"********** ausf_s (%s) ***********"
,
auts_s
);
comUt
::
print_buffer
(
"amf_n1"
,
"ausf"
,
auts_value
,
auts_len
);
Logger
::
amf_n1
().
info
(
"ausf_s (%s)"
,
auts_s
);
// generate_random(rand_value, RAND_LENGTH);
std
::
map
<
std
::
string
,
std
::
string
>::
iterator
iter
;
iter
=
rand_record
.
find
(
nc
.
get
()
->
imsi
);
if
(
iter
!=
rand_record
.
end
())
{
authenticationinfo_rand
=
iter
->
second
;
Logger
::
amf_n1
().
info
(
"********** rand_s (%s) ***********"
,
authenticationinfo_rand
.
c_str
());
Logger
::
amf_n1
().
info
(
"rand_s (%s)"
,
authenticationinfo_rand
.
c_str
());
}
else
{
Logger
::
amf_n1
().
error
(
"
********** There's no last rand ***********
"
);
Logger
::
amf_n1
().
error
(
"
There's no last rand
"
);
}
// rand_value = nc.get()->_5g_av[0].rand;
// for(int i=0;i<RAND_LENGTH;i++)
// {
// sprintf(&rand_s[i*2],"%02X",rand_value[i]);
// }
// authenticationinfo_rand = rand_s;
// comUt::print_buffer("amf_n1", "********** rand ***********",
// rand_value, RAND_LENGTH);
resynchronizationInfo
.
setAuts
(
authenticationinfo_auts
);
resynchronizationInfo
.
setRand
(
authenticationinfo_rand
);
...
...
@@ -1497,9 +1469,8 @@ bool amf_n1::_5g_aka_confirmation_from_ausf(
sprintf
(
&
resStar_s
[
i
*
2
],
"%02X"
,
resStar_value
[
i
]);
}
resStar_string
=
resStar_s
;
comUt
::
print_buffer
(
"amf_n1"
,
"********** resStar ***********"
,
resStar_value
,
resStar_len
);
Logger
::
amf_n1
().
info
(
"********** resStar_s (%s) ***********"
,
resStar_s
);
comUt
::
print_buffer
(
"amf_n1"
,
"resStar"
,
resStar_value
,
resStar_len
);
Logger
::
amf_n1
().
info
(
"resStar_s (%s)"
,
resStar_s
);
nlohmann
::
json
confirmationdata_j
;
ConfirmationData
confirmationdata
;
...
...
@@ -1563,17 +1534,11 @@ bool amf_n1::authentication_vectors_generator_in_ausf(
Authentication_5gaka
::
derive_kseaf
(
nc
.
get
()
->
serving_network
,
nc
.
get
()
->
_5g_he_av
[
i
].
kausf
,
kseaf
);
memcpy
(
nc
.
get
()
->
_5g_av
[
i
].
kseaf
,
kseaf
,
32
);
// comUt::print_buffer("amf_n1", "5G AV: rand", nc.get()->_5g_av[i].rand,
// 16); comUt::print_buffer("amf_n1", "5G AV: autn",
// nc.get()->_5g_av[i].autn, 16); comUt::print_buffer("amf_n1", "5G AV:
// kseaf", nc.get()->_5g_av[i].kseaf, 32); comUt::print_buffer("amf_n1", "5G
// AV: hxres*", nc.get()->_5g_av[i].hxresStar, 16);
}
return
true
;
}
//------------------------------------------------------------------------------
// TODO: Get from UDM
bool
amf_n1
::
authentication_vectors_generator_in_udm
(
std
::
shared_ptr
<
nas_context
>&
nc
)
{
Logger
::
amf_n1
().
debug
(
"Generate authentication vectors"
);
...
...
@@ -1618,12 +1583,6 @@ bool amf_n1::authentication_vectors_generator_in_udm(
Logger
::
amf_n1
().
debug
(
"Receive information from MySQL with IMSI %s"
,
nc
.
get
()
->
imsi
.
c_str
());
// comUt::print_buffer("amf_n1", "Received from MYSQL: rand",
// mysql_resp.rand, 16); comUt::print_buffer("amf_n1", "Received from
// MYSQL: opc", mysql_resp.opc, 16); comUt::print_buffer("amf_n1",
// "Received from MYSQL: key", mysql_resp.key, 16);
// comUt::print_buffer("amf_n1", "Received from MYSQL: sqn",
// mysql_resp.sqn, 6);
for
(
int
i
=
0
;
i
<
MAX_5GS_AUTH_VECTORS
;
i
++
)
{
generate_random
(
vector
[
i
].
rand
,
RAND_LENGTH
);
sqn
=
mysql_resp
.
sqn
;
...
...
@@ -1705,7 +1664,6 @@ void amf_n1::generate_random(uint8_t* random_p, ssize_t length) {
}
//------------------------------------------------------------------------------
// TODO: read from UDM
void
amf_n1
::
generate_5g_he_av_in_udm
(
const
uint8_t
opc
[
16
],
string
imsi
,
uint8_t
key
[
16
],
uint8_t
sqn
[
6
],
std
::
string
serving_network
,
_5G_HE_AV_t
&
vector
)
{
...
...
@@ -2224,14 +2182,7 @@ void amf_n1::security_mode_complete_handle(
nc
.
get
()
->
imsi
.
c_str
(),
guti
.
c_str
(),
ran_ue_ngap_id
,
amf_ue_ngap_id
);
if
(
nc
.
get
()
->
is_stacs_available
)
{
stacs
.
update_5gmm_state
(
nc
.
get
()
->
imsi
,
"5GMM-REGISTERED"
);
// update_ue_information_statics(stacs.ues[index], "", "RM-REGISTRED",
// ran_ue_ngap_id, amf_ue_ngap_id, "", guti, "", "", 0);
}
else
{
// ue_infos ueItem;
// update_ue_information_statics(ueItem, "CM-CONNECTED",
// "REGISTRATION-REGISTRED", ran_ue_ngap_id, amf_ue_ngap_id,
// nc.get()->imsi, "", mcc, mnc, uc.get()->cgi.nrCellID);
// stacs.ues.push_back(ueItem);
nc
.
get
()
->
is_stacs_available
=
true
;
}
set_5gmm_state
(
nc
,
_5GMM_REGISTERED
);
...
...
@@ -2243,7 +2194,7 @@ void amf_n1::security_mode_complete_handle(
Logger
::
amf_n1
().
error
(
"No Security Context found"
);
return
;
}
// protect nas message
bstring
protectedNas
;
encode_nas_message_protected
(
secu
,
false
,
INTEGRITY_PROTECTED_AND_CIPHERED
,
NAS_MESSAGE_DOWNLINK
,
...
...
@@ -2788,6 +2739,7 @@ void amf_n1::ue_authentication_simulator(uint8_t* rand, uint8_t* autn) {
void
amf_n1
::
sha256
(
unsigned
char
*
message
,
int
msg_len
,
unsigned
char
*
output
)
{
memset
(
output
,
0
,
Sha256
::
DIGEST_SIZE
);
Sha256
ctx
=
{};
ctx
.
init
();
ctx
.
update
(
message
,
msg_len
);
ctx
.
finalResult
(
output
);
...
...
src/amf-app/amf_n1.hpp
View file @
8f64764b
...
...
@@ -64,6 +64,22 @@ typedef enum {
class
amf_n1
{
public:
std
::
map
<
long
,
std
::
shared_ptr
<
nas_context
>>
amfueid2nas_context
;
// amf ue ngap id
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
nas_context
>>
imsi2nas_context
;
std
::
map
<
std
::
string
,
long
>
supi2amfId
;
std
::
map
<
std
::
string
,
uint32_t
>
supi2ranId
;
mutable
std
::
shared_mutex
m_nas_context
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
nas_context
>>
guti2nas_context
;
mutable
std
::
shared_mutex
m_guti2nas_context
;
static
std
::
map
<
std
::
string
,
std
::
string
>
rand_record
;
static
uint8_t
no_random_delta
;
random_state_t
random_state
;
database_t
*
db_desc
;
amf_n1
();
~
amf_n1
();
void
handle_itti_message
(
itti_uplink_nas_data_ind
&
);
...
...
@@ -78,16 +94,6 @@ class amf_n1 {
plmn_t
plmn
);
bool
check_security_header_type
(
SecurityHeaderType
&
type
,
uint8_t
*
buffer
);
std
::
map
<
long
,
std
::
shared_ptr
<
nas_context
>>
amfueid2nas_context
;
// amf ue ngap id
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
nas_context
>>
imsi2nas_context
;
std
::
map
<
std
::
string
,
long
>
supi2amfId
;
std
::
map
<
std
::
string
,
uint32_t
>
supi2ranId
;
mutable
std
::
shared_mutex
m_nas_context
;
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
nas_context
>>
guti2nas_context
;
mutable
std
::
shared_mutex
m_guti2nas_context
;
bool
is_guti_2_nas_context
(
const
std
::
string
&
guti
)
const
;
std
::
shared_ptr
<
nas_context
>
guti_2_nas_context
(
const
std
::
string
&
guti
)
const
;
...
...
@@ -100,7 +106,6 @@ class amf_n1 {
const
long
&
amf_ue_ngap_id
)
const
;
void
set_amf_ue_ngap_id_2_nas_context
(
const
long
&
amf_ue_ngap_id
,
std
::
shared_ptr
<
nas_context
>
nc
);
database_t
*
db_desc
;
// procedures
// specific procedures running logic
...
...
src/amf-app/amf_n11.cpp
View file @
8f64764b
...
...
@@ -61,7 +61,6 @@ using namespace oai::smf::model;
using
namespace
oai
::
smf
::
api
;
using
namespace
web
;
using
namespace
web
::
http
;
// Common features like URIs.
using
namespace
web
::
http
::
client
;
using
namespace
config
;
using
namespace
amf_application
;
...
...
src/amf-app/amf_n2.cpp
View file @
8f64764b
...
...
@@ -75,8 +75,6 @@ extern amf_n11* amf_n11_inst;
extern
amf_config
amf_cfg
;
extern
amf_app
*
amf_app_inst
;
extern
statistics
stacs
;
extern
void
print_buffer
(
const
std
::
string
app
,
const
std
::
string
commit
,
uint8_t
*
buf
,
int
len
);
void
amf_n2_task
(
void
*
);
...
...
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