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
e190aee7
Commit
e190aee7
authored
Feb 01, 2021
by
Tien-Thinh Nguyen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply clang-format for AMF_APP
parent
d0080142
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
413 additions
and
392 deletions
+413
-392
src/amf-app/amf_config.cpp
src/amf-app/amf_config.cpp
+4
-2
src/amf-app/amf_module_from_config.cpp
src/amf-app/amf_module_from_config.cpp
+27
-23
src/amf-app/amf_module_from_config.hpp
src/amf-app/amf_module_from_config.hpp
+2
-2
src/amf-app/amf_n1.hpp
src/amf-app/amf_n1.hpp
+84
-88
src/amf-app/amf_n11.cpp
src/amf-app/amf_n11.cpp
+6
-3
src/amf-app/amf_n11.hpp
src/amf-app/amf_n11.hpp
+6
-3
src/amf-app/amf_n2.cpp
src/amf-app/amf_n2.cpp
+204
-195
src/amf-app/amf_n2.hpp
src/amf-app/amf_n2.hpp
+19
-19
src/amf-app/amf_statistics.cpp
src/amf-app/amf_statistics.cpp
+16
-15
src/amf-app/amf_statistics.hpp
src/amf-app/amf_statistics.hpp
+2
-2
src/amf-app/mysql_db.cpp
src/amf-app/mysql_db.cpp
+42
-39
src/amf-app/mysql_db.hpp
src/amf-app/mysql_db.hpp
+1
-1
No files found.
src/amf-app/amf_config.cpp
View file @
e190aee7
...
...
@@ -379,9 +379,11 @@ void amf_config::display() {
Logger
::
config
().
info
(
" port .................: %d"
,
n11
.
port
);
Logger
::
config
().
info
(
"- NRF:"
);
Logger
::
config
().
info
(
" IP addr ..............: %s"
,
inet_ntoa
(
nrf_addr
.
ipv4_addr
));
Logger
::
config
().
info
(
" IP addr ..............: %s"
,
inet_ntoa
(
nrf_addr
.
ipv4_addr
));
Logger
::
config
().
info
(
" Port .................: %d"
,
nrf_addr
.
port
);
Logger
::
config
().
info
(
" Api version ..........: %s"
,
nrf_addr
.
api_version
.
c_str
());
Logger
::
config
().
info
(
" Api version ..........: %s"
,
nrf_addr
.
api_version
.
c_str
());
// Logger::config().info(" HTTP2 port ............: %d", n11_http2_port);
...
...
src/amf-app/amf_module_from_config.cpp
View file @
e190aee7
...
...
@@ -36,43 +36,46 @@
namespace
config
{
//------------------------------------------------------------------------------
int
amf_modules
::
load
(
const
std
::
string
&
config_file
)
{
Logger
::
amf_app
().
debug
(
"
\n
Load AMF module configuration file (%s)"
,
config_file
.
c_str
());
int
amf_modules
::
load
(
const
std
::
string
&
config_file
)
{
Logger
::
amf_app
().
debug
(
"
\n
Load AMF module configuration file (%s)"
,
config_file
.
c_str
());
Config
cfg
;
try
{
cfg
.
readFile
(
config_file
.
c_str
());
}
catch
(
const
FileIOException
&
fioex
)
{
Logger
::
amf_app
().
error
(
"I/O error while reading file %s - %s"
,
config_file
.
c_str
(),
fioex
.
what
());
}
catch
(
const
FileIOException
&
fioex
)
{
Logger
::
amf_app
().
error
(
"I/O error while reading file %s - %s"
,
config_file
.
c_str
(),
fioex
.
what
());
throw
;
}
catch
(
const
ParseException
&
pex
)
{
Logger
::
amf_app
().
error
(
"Parse error at %s:%d - %s"
,
pex
.
getFile
(),
pex
.
getLine
(),
pex
.
getError
());
}
catch
(
const
ParseException
&
pex
)
{
Logger
::
amf_app
().
error
(
"Parse error at %s:%d - %s"
,
pex
.
getFile
(),
pex
.
getLine
(),
pex
.
getError
());
throw
;
}
const
Setting
&
root
=
cfg
.
getRoot
();
const
Setting
&
root
=
cfg
.
getRoot
();
try
{
const
Setting
&
modules
=
root
[
MODULES_CONFIG_STRING_AMF_MODULES
];
}
catch
(
const
SettingNotFoundException
&
nfex
)
{
const
Setting
&
modules
=
root
[
MODULES_CONFIG_STRING_AMF_MODULES
];
}
catch
(
const
SettingNotFoundException
&
nfex
)
{
Logger
::
amf_app
().
error
(
"%s : %s"
,
nfex
.
what
(),
nfex
.
getPath
());
return
-
1
;
}
const
Setting
&
modules
=
root
[
MODULES_CONFIG_STRING_AMF_MODULES
];
const
Setting
&
msg
=
modules
[
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE
];
int
count
=
msg
.
getLength
();
const
Setting
&
modules
=
root
[
MODULES_CONFIG_STRING_AMF_MODULES
];
const
Setting
&
msg
=
modules
[
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE
];
int
count
=
msg
.
getLength
();
for
(
int
i
=
0
;
i
<
count
;
i
++
)
{
const
Setting
&
item
=
msg
[
i
];
const
Setting
&
item
=
msg
[
i
];
std
::
string
typeOfMessage
;
int
procedure_code
;
item
.
lookupValue
(
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME
,
msgName
);
item
.
lookupValue
(
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME
,
msgName
);
item
.
lookupValue
(
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE
,
procedure_code
);
item
.
lookupValue
(
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG
,
typeOfMessage
);
procedureCode
=
(
Ngap_ProcedureCode_t
)
procedure_code
;
item
.
lookupValue
(
MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG
,
typeOfMessage
);
procedureCode
=
(
Ngap_ProcedureCode_t
)
procedure_code
;
if
(
!
(
typeOfMessage
.
compare
(
"initialMessage"
)))
{
typeOfMsg
=
Ngap_NGAP_PDU_PR_initiatingMessage
;
}
else
if
(
!
(
typeOfMessage
.
compare
(
"successfuloutcome"
)))
{
...
...
@@ -89,8 +92,9 @@ int amf_modules::load(const std::string &config_file) {
void
amf_modules
::
display
()
{
Logger
::
config
().
info
(
"======= AMF Registered Modules ======="
);
Logger
::
config
().
info
(
"NGAP Message Modules:"
);
Logger
::
config
().
info
(
"- %s(Procedure code %d, Type of Msg %d)
\n
"
,
msgName
.
c_str
(),
procedureCode
,
typeOfMsg
);
Logger
::
config
().
info
(
"- %s(Procedure code %d, Type of Msg %d)
\n
"
,
msgName
.
c_str
(),
procedureCode
,
typeOfMsg
);
}
}
// namespace config
src/amf-app/amf_module_from_config.hpp
View file @
e190aee7
...
...
@@ -40,7 +40,7 @@
#define MODULES_CONFIG_STRING_AMF_MODULES "MODULES"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE "NGAP_MESSAGE"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_NAME "MSG_NAME"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE \
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_PROCEDURECODE
\
"ProcedureCode"
#define MODULES_CONFIG_STRING_AMF_MODULES_NGAP_MESSAGE_TYPEOFMSG "TypeOfMessage"
...
...
@@ -50,7 +50,7 @@ namespace config {
class
amf_modules
{
public:
int
load
(
const
std
::
string
&
config_file
);
int
load
(
const
std
::
string
&
config_file
);
void
display
();
void
makeModulesAlive
();
...
...
src/amf-app/amf_n1.hpp
View file @
e190aee7
This diff is collapsed.
Click to expand it.
src/amf-app/amf_n11.cpp
View file @
e190aee7
...
...
@@ -348,7 +348,8 @@ void amf_n11::send_pdu_session_update_sm_context_request(
//------------------------------------------------------------------------------
void
amf_n11
::
handle_pdu_session_initial_request
(
std
::
string
supi
,
std
::
shared_ptr
<
pdu_session_context
>
psc
,
std
::
string
smf_addr
,
std
::
string
smf_api_version
,
bstring
sm_msg
,
std
::
string
dnn
)
{
std
::
string
smf_addr
,
std
::
string
smf_api_version
,
bstring
sm_msg
,
std
::
string
dnn
)
{
Logger
::
amf_n11
().
debug
(
"Handle PDU Session Establishment Request (SUPI %s, PDU Session ID %d)"
,
supi
.
c_str
(),
psc
.
get
()
->
pdu_session_id
);
...
...
@@ -437,7 +438,8 @@ void amf_n11::set_supi_to_pdu_ctx(
// SMF selection
//------------------------------------------------------------------------------
bool
amf_n11
::
smf_selection_from_configuration
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
)
{
bool
amf_n11
::
smf_selection_from_configuration
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
)
{
for
(
int
i
=
0
;
i
<
amf_cfg
.
smf_pool
.
size
();
i
++
)
{
if
(
amf_cfg
.
smf_pool
[
i
].
selected
)
{
smf_addr
=
amf_cfg
.
smf_pool
[
i
].
ipv4
+
":"
+
amf_cfg
.
smf_pool
[
i
].
port
;
...
...
@@ -449,7 +451,8 @@ bool amf_n11::smf_selection_from_configuration(std::string& smf_addr, std::strin
}
//------------------------------------------------------------------------------
bool
amf_n11
::
smf_selection_from_context
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
)
{
bool
amf_n11
::
smf_selection_from_context
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
)
{
// TODO:
}
...
...
src/amf-app/amf_n11.hpp
View file @
e190aee7
...
...
@@ -46,7 +46,8 @@ class amf_n11 {
void
handle_itti_message
(
itti_smf_services_consumer
&
);
void
handle_pdu_session_initial_request
(
std
::
string
supi
,
std
::
shared_ptr
<
pdu_session_context
>
psc
,
std
::
string
smf_addr
,
std
::
string
smf_api_version
,
bstring
sm_msg
,
std
::
string
dnn
);
std
::
string
smf_addr
,
std
::
string
smf_api_version
,
bstring
sm_msg
,
std
::
string
dnn
);
void
handle_itti_message
(
itti_nsmf_pdusession_update_sm_context
&
itti_msg
);
void
handle_itti_message
(
itti_nsmf_pdusession_release_sm_context
&
itti_msg
);
void
handle_itti_message
(
itti_pdu_session_resource_setup_response
&
itti_msg
);
...
...
@@ -64,8 +65,10 @@ class amf_n11 {
const
std
::
string
&
supi
,
std
::
shared_ptr
<
pdu_session_context
>
psc
);
std
::
map
<
uint8_t
,
std
::
string
>
pduid2supi
;
bool
smf_selection_from_configuration
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
);
bool
smf_selection_from_context
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
);
bool
smf_selection_from_configuration
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
);
bool
smf_selection_from_context
(
std
::
string
&
smf_addr
,
std
::
string
&
smf_api_version
);
void
handle_post_sm_context_response_error_400
();
void
handle_post_sm_context_response_error
(
long
code
,
std
::
string
cause
,
bstring
n1sm
,
std
::
string
supi
,
...
...
src/amf-app/amf_n2.cpp
View file @
e190aee7
This diff is collapsed.
Click to expand it.
src/amf-app/amf_n2.hpp
View file @
e190aee7
...
...
@@ -43,34 +43,34 @@ namespace amf_application {
class
amf_n2
:
public
ngap
::
ngap_app
{
public:
amf_n2
(
const
std
::
string
&
address
,
const
uint16_t
port_num
);
amf_n2
(
const
std
::
string
&
address
,
const
uint16_t
port_num
);
~
amf_n2
();
void
handle_itti_message
(
itti_new_sctp_association
&
new_assoc
);
void
handle_itti_message
(
itti_ng_setup_request
&
ngsetupreq
);
void
handle_itti_message
(
itti_initial_ue_message
&
init_ue_msg
);
void
handle_itti_message
(
itti_ul_nas_transport
&
ul_nas_transport
);
void
handle_itti_message
(
itti_dl_nas_transport
&
dl_nas_transport
);
void
handle_itti_message
(
itti_initial_context_setup_request
&
itti_msg
);
void
handle_itti_message
(
itti_pdu_session_resource_setup_request
&
itti_msg
);
void
handle_itti_message
(
itti_ue_context_release_request
&
itti_msg
);
void
handle_itti_message
(
itti_ue_radio_capability_indication
&
itti_msg
);
void
handle_itti_message
(
itti_ue_context_release_command
&
itti_msg
);
void
handle_itti_message
(
itti_pdu_session_resource_release_command
&
itti_msg
);
void
handle_itti_message
(
itti_handover_required
&
itti_msg
);
void
handle_itti_message
(
itti_handover_request_Ack
&
itti_msg
);
void
handle_itti_message
(
itti_handover_notify
&
itti_msg
);
void
handle_itti_message
(
itti_uplinkranstatsutransfer
&
itti_msg
);
void
handle_itti_message
(
itti_new_sctp_association
&
new_assoc
);
void
handle_itti_message
(
itti_ng_setup_request
&
ngsetupreq
);
void
handle_itti_message
(
itti_initial_ue_message
&
init_ue_msg
);
void
handle_itti_message
(
itti_ul_nas_transport
&
ul_nas_transport
);
void
handle_itti_message
(
itti_dl_nas_transport
&
dl_nas_transport
);
void
handle_itti_message
(
itti_initial_context_setup_request
&
itti_msg
);
void
handle_itti_message
(
itti_pdu_session_resource_setup_request
&
itti_msg
);
void
handle_itti_message
(
itti_ue_context_release_request
&
itti_msg
);
void
handle_itti_message
(
itti_ue_radio_capability_indication
&
itti_msg
);
void
handle_itti_message
(
itti_ue_context_release_command
&
itti_msg
);
void
handle_itti_message
(
itti_pdu_session_resource_release_command
&
itti_msg
);
void
handle_itti_message
(
itti_handover_required
&
itti_msg
);
void
handle_itti_message
(
itti_handover_request_Ack
&
itti_msg
);
void
handle_itti_message
(
itti_handover_notify
&
itti_msg
);
void
handle_itti_message
(
itti_uplinkranstatsutransfer
&
itti_msg
);
bool
verifyPlmn
(
std
::
vector
<
SupportedItem_t
>
list
);
std
::
vector
<
SupportedItem_t
>
get_common_plmn
(
std
::
vector
<
SupportedItem_t
>
list
);
std
::
shared_ptr
<
ue_ngap_context
>
ran_ue_id_2_ue_ngap_context
(
const
uint32_t
&
ran_ue_ngap_id
)
const
;
const
uint32_t
&
ran_ue_ngap_id
)
const
;
bool
is_ran_ue_id_2_ue_ngap_context
(
const
uint32_t
&
ran_ue_ngap_id
)
const
;
bool
is_ran_ue_id_2_ue_ngap_context
(
const
uint32_t
&
ran_ue_ngap_id
)
const
;
void
set_ran_ue_ngap_id_2_ue_ngap_context
(
const
uint32_t
&
ran_ue_ngap_id
,
std
::
shared_ptr
<
ue_ngap_context
>
unc
);
const
uint32_t
&
ran_ue_ngap_id
,
std
::
shared_ptr
<
ue_ngap_context
>
unc
);
private:
std
::
map
<
uint32_t
,
std
::
shared_ptr
<
ue_ngap_context
>>
...
...
src/amf-app/amf_statistics.cpp
View file @
e190aee7
...
...
@@ -79,7 +79,7 @@ void statistics::display() {
"UE NGAP ID | AMF UE ID | PLMN |Cell ID|"
);
int
i
=
0
;
for
(
auto
const
&
ue
:
ue_infos
)
{
for
(
auto
const
&
ue
:
ue_infos
)
{
Logger
::
amf_app
().
info
(
"|%7d|%22s|%18s|%15s|%16d|%11d|%9s|%7d|"
,
i
+
1
,
ue
.
second
.
registerStatus
.
c_str
(),
ue
.
second
.
imsi
.
c_str
(),
...
...
@@ -96,12 +96,12 @@ void statistics::display() {
//------------------------------------------------------------------------------
statistics
::
statistics
()
{
gNB_connected
=
0
;
UE_connected
=
0
;
UE_registred
=
0
;
UE_connected
=
0
;
UE_registred
=
0
;
}
//------------------------------------------------------------------------------
void
statistics
::
update_ue_info
(
const
ue_info_t
&
ue_info
)
{
void
statistics
::
update_ue_info
(
const
ue_info_t
&
ue_info
)
{
if
(
!
(
ue_info
.
imsi
.
size
()
>
0
))
{
Logger
::
amf_app
().
warn
(
"Update UE Info with invalid IMSI"
);
}
...
...
@@ -109,28 +109,29 @@ void statistics::update_ue_info(const ue_info_t &ue_info) {
if
(
ue_infos
.
count
(
ue_info
.
imsi
)
>
0
)
{
ue_infos
.
erase
(
ue_info
.
imsi
);
ue_infos
.
insert
(
std
::
pair
<
std
::
string
,
ue_info_t
>
(
ue_info
.
imsi
,
ue_info
));
Logger
::
amf_app
().
debug
(
"Update UE Info (IMSI %s) success"
,
ue_info
.
imsi
.
c_str
());
Logger
::
amf_app
().
debug
(
"Update UE Info (IMSI %s) success"
,
ue_info
.
imsi
.
c_str
());
}
else
{
ue_infos
.
insert
(
std
::
pair
<
std
::
string
,
ue_info_t
>
(
ue_info
.
imsi
,
ue_info
));
Logger
::
amf_app
().
debug
(
"Add UE Info (IMSI %s) success"
,
ue_info
.
imsi
.
c_str
());
Logger
::
amf_app
().
debug
(
"Add UE Info (IMSI %s) success"
,
ue_info
.
imsi
.
c_str
());
}
}
//------------------------------------------------------------------------------
void
statistics
::
update_5gmm_state
(
const
std
::
string
&
imsi
,
const
std
::
string
&
state
)
{
void
statistics
::
update_5gmm_state
(
const
std
::
string
&
imsi
,
const
std
::
string
&
state
)
{
if
(
ue_infos
.
count
(
imsi
)
>
0
)
{
ue_info_t
ue_info
=
ue_infos
.
at
(
imsi
);
ue_info_t
ue_info
=
ue_infos
.
at
(
imsi
);
ue_info
.
registerStatus
=
state
;
ue_infos
.
erase
(
ue_info
.
imsi
);
ue_infos
.
insert
(
std
::
pair
<
std
::
string
,
ue_info_t
>
(
imsi
,
ue_info
));
Logger
::
amf_app
().
debug
(
"Update UE State (IMSI %s, State %s) success"
,
imsi
.
c_str
(),
state
.
c_str
());
Logger
::
amf_app
().
debug
(
"Update UE State (IMSI %s, State %s) success"
,
imsi
.
c_str
(),
state
.
c_str
());
}
else
{
Logger
::
amf_app
().
warn
(
"Update UE State (IMSI %s), UE does not exist!"
,
imsi
.
c_str
());
Logger
::
amf_app
().
warn
(
"Update UE State (IMSI %s), UE does not exist!"
,
imsi
.
c_str
());
}
}
...
...
src/amf-app/amf_statistics.hpp
View file @
e190aee7
...
...
@@ -63,8 +63,8 @@ class statistics {
void
display
();
statistics
();
~
statistics
();
void
update_ue_info
(
const
ue_info_t
&
ue_info
);
void
update_5gmm_state
(
const
std
::
string
&
imsi
,
const
std
::
string
&
state
);
void
update_ue_info
(
const
ue_info_t
&
ue_info
);
void
update_5gmm_state
(
const
std
::
string
&
imsi
,
const
std
::
string
&
state
);
public:
uint32_t
gNB_connected
;
...
...
src/amf-app/mysql_db.cpp
View file @
e190aee7
...
...
@@ -38,9 +38,9 @@ extern amf_config amf_cfg;
//------------------------------------------------------------------------------
bool
amf_n1
::
get_mysql_auth_info
(
std
::
string
imsi
,
mysql_auth_info_t
&
resp
)
{
// openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES
*
res
;
mysql_auth_info_t
&
resp
)
{
// openair-cn/tree/v0.5.0/src/oai_hss/db/db_connector.c
MYSQL_RES
*
res
;
MYSQL_ROW
row
;
std
::
string
query
;
...
...
@@ -54,8 +54,8 @@ bool amf_n1::get_mysql_auth_info(
pthread_mutex_lock
(
&
db_desc
->
db_cs_mutex
);
if
(
mysql_query
(
db_desc
->
db_conn
,
query
.
c_str
()))
{
pthread_mutex_unlock
(
&
db_desc
->
db_cs_mutex
);
Logger
::
amf_n1
().
error
(
"Query execution failed: %s
\n
"
,
mysql_error
(
db_desc
->
db_conn
));
Logger
::
amf_n1
().
error
(
"Query execution failed: %s
\n
"
,
mysql_error
(
db_desc
->
db_conn
));
return
false
;
}
res
=
mysql_store_result
(
db_desc
->
db_conn
);
...
...
@@ -71,13 +71,13 @@ bool amf_n1::get_mysql_auth_info(
}
memcpy
(
resp
.
key
,
row
[
0
],
KEY_LENGTH
);
uint64_t
sqn
=
0
;
sqn
=
atoll
(
row
[
1
]);
resp
.
sqn
[
0
]
=
(
sqn
&
(
255UL
<<
40
))
>>
40
;
resp
.
sqn
[
1
]
=
(
sqn
&
(
255UL
<<
32
))
>>
32
;
resp
.
sqn
[
2
]
=
(
sqn
&
(
255UL
<<
24
))
>>
24
;
resp
.
sqn
[
3
]
=
(
sqn
&
(
255UL
<<
16
))
>>
16
;
resp
.
sqn
[
4
]
=
(
sqn
&
(
255UL
<<
8
))
>>
8
;
resp
.
sqn
[
5
]
=
(
sqn
&
0xff
);
sqn
=
atoll
(
row
[
1
]);
resp
.
sqn
[
0
]
=
(
sqn
&
(
255UL
<<
40
))
>>
40
;
resp
.
sqn
[
1
]
=
(
sqn
&
(
255UL
<<
32
))
>>
32
;
resp
.
sqn
[
2
]
=
(
sqn
&
(
255UL
<<
24
))
>>
24
;
resp
.
sqn
[
3
]
=
(
sqn
&
(
255UL
<<
16
))
>>
16
;
resp
.
sqn
[
4
]
=
(
sqn
&
(
255UL
<<
8
))
>>
8
;
resp
.
sqn
[
5
]
=
(
sqn
&
0xff
);
memcpy
(
resp
.
rand
,
row
[
2
],
RAND_LENGTH
);
memcpy
(
resp
.
opc
,
row
[
3
],
KEY_LENGTH
);
}
...
...
@@ -88,24 +88,25 @@ bool amf_n1::get_mysql_auth_info(
//------------------------------------------------------------------------------
bool
amf_n1
::
connect_to_mysql
()
{
const
int
mysql_reconnect_val
=
1
;
db_desc
=
(
database_t
*
)
calloc
(
1
,
sizeof
(
database_t
));
db_desc
=
(
database_t
*
)
calloc
(
1
,
sizeof
(
database_t
));
if
(
!
db_desc
)
{
Logger
::
amf_n1
().
error
(
"An error occurs when allocating memory for DB_DESC"
);
return
false
;
}
pthread_mutex_init
(
&
db_desc
->
db_cs_mutex
,
NULL
);
db_desc
->
server
=
amf_cfg
.
auth_para
.
mysql_server
;
db_desc
->
user
=
amf_cfg
.
auth_para
.
mysql_user
;
db_desc
->
server
=
amf_cfg
.
auth_para
.
mysql_server
;
db_desc
->
user
=
amf_cfg
.
auth_para
.
mysql_user
;
db_desc
->
password
=
amf_cfg
.
auth_para
.
mysql_pass
;
db_desc
->
database
=
amf_cfg
.
auth_para
.
mysql_db
;
db_desc
->
db_conn
=
mysql_init
(
NULL
);
db_desc
->
db_conn
=
mysql_init
(
NULL
);
mysql_options
(
db_desc
->
db_conn
,
MYSQL_OPT_RECONNECT
,
&
mysql_reconnect_val
);
if
(
!
mysql_real_connect
(
db_desc
->
db_conn
,
db_desc
->
server
.
c_str
(),
db_desc
->
user
.
c_str
(),
db_desc
->
password
.
c_str
(),
db_desc
->
database
.
c_str
(),
0
,
NULL
,
0
))
{
Logger
::
amf_n1
().
error
(
"An error occurred while connecting to db: %s"
,
mysql_error
(
db_desc
->
db_conn
));
if
(
!
mysql_real_connect
(
db_desc
->
db_conn
,
db_desc
->
server
.
c_str
(),
db_desc
->
user
.
c_str
(),
db_desc
->
password
.
c_str
(),
db_desc
->
database
.
c_str
(),
0
,
NULL
,
0
))
{
Logger
::
amf_n1
().
error
(
"An error occurred while connecting to db: %s"
,
mysql_error
(
db_desc
->
db_conn
));
mysql_thread_end
();
return
false
;
}
...
...
@@ -114,12 +115,12 @@ bool amf_n1::connect_to_mysql() {
}
//------------------------------------------------------------------------------
void
amf_n1
::
mysql_push_rand_sqn
(
std
::
string
imsi
,
uint8_t
*
rand_p
,
uint8_t
*
sqn
)
{
void
amf_n1
::
mysql_push_rand_sqn
(
std
::
string
imsi
,
uint8_t
*
rand_p
,
uint8_t
*
sqn
)
{
int
status
=
0
;
MYSQL_RES
*
res
;
MYSQL_RES
*
res
;
char
query
[
1000
];
int
query_length
=
0
;
int
query_length
=
0
;
uint64_t
sqn_decimal
=
0
;
if
(
!
db_desc
->
db_conn
)
{
Logger
::
amf_n1
().
error
(
"Cannot connect to MySQL DB"
);
...
...
@@ -129,8 +130,8 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p,
Logger
::
amf_n1
().
error
(
"Need sqn and rand"
);
return
;
}
sqn_decimal
=
((
uint64_t
)
sqn
[
0
]
<<
40
)
|
((
uint64_t
)
sqn
[
1
]
<<
32
)
|
((
uint64_t
)
sqn
[
2
]
<<
24
)
|
(
sqn
[
3
]
<<
16
)
|
(
sqn
[
4
]
<<
8
)
|
sqn_decimal
=
((
uint64_t
)
sqn
[
0
]
<<
40
)
|
((
uint64_t
)
sqn
[
1
]
<<
32
)
|
((
uint64_t
)
sqn
[
2
]
<<
24
)
|
(
sqn
[
3
]
<<
16
)
|
(
sqn
[
4
]
<<
8
)
|
sqn
[
5
];
query_length
=
sprintf
(
query
,
"UPDATE `users` SET `rand`=UNHEX('"
);
for
(
int
i
=
0
;
i
<
RAND_LENGTH
;
i
++
)
{
...
...
@@ -144,8 +145,8 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p,
pthread_mutex_lock
(
&
db_desc
->
db_cs_mutex
);
if
(
mysql_query
(
db_desc
->
db_conn
,
query
))
{
pthread_mutex_unlock
(
&
db_desc
->
db_cs_mutex
);
Logger
::
amf_n1
().
error
(
"Query execution failed: %s"
,
mysql_error
(
db_desc
->
db_conn
));
Logger
::
amf_n1
().
error
(
"Query execution failed: %s"
,
mysql_error
(
db_desc
->
db_conn
));
return
;
}
do
{
...
...
@@ -154,8 +155,9 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p,
mysql_free_result
(
res
);
}
else
{
if
(
mysql_field_count
(
db_desc
->
db_conn
)
==
0
)
{
Logger
::
amf_n1
().
error
(
"[MySQL] %lld rows affected"
,
mysql_affected_rows
(
db_desc
->
db_conn
));
Logger
::
amf_n1
().
error
(
"[MySQL] %lld rows affected"
,
mysql_affected_rows
(
db_desc
->
db_conn
));
}
else
{
/* some error occurred */
Logger
::
amf_n1
().
error
(
"Could not retrieve result set"
);
break
;
...
...
@@ -171,22 +173,22 @@ void amf_n1::mysql_push_rand_sqn(std::string imsi, uint8_t *rand_p,
//------------------------------------------------------------------------------
void
amf_n1
::
mysql_increment_sqn
(
std
::
string
imsi
)
{
int
status
;
MYSQL_RES
*
res
;
MYSQL_RES
*
res
;
char
query
[
1000
];
if
(
db_desc
->
db_conn
==
NULL
)
{
Logger
::
amf_n1
().
error
(
"Cannot connect to MySQL DB"
);
return
;
}
sprintf
(
query
,
"UPDATE `users` SET `sqn` = `sqn` + 32 WHERE `users`.`imsi`='%s'"
,
imsi
.
c_str
());
sprintf
(
query
,
"UPDATE `users` SET `sqn` = `sqn` + 32 WHERE `users`.`imsi`='%s'"
,
imsi
.
c_str
());
pthread_mutex_lock
(
&
db_desc
->
db_cs_mutex
);
if
(
mysql_query
(
db_desc
->
db_conn
,
query
))
{
pthread_mutex_unlock
(
&
db_desc
->
db_cs_mutex
);
Logger
::
amf_n1
().
error
(
"Query execution failed: %s"
,
mysql_error
(
db_desc
->
db_conn
));
Logger
::
amf_n1
().
error
(
"Query execution failed: %s"
,
mysql_error
(
db_desc
->
db_conn
));
return
;
}
do
{
...
...
@@ -195,8 +197,9 @@ void amf_n1::mysql_increment_sqn(std::string imsi) {
mysql_free_result
(
res
);
}
else
{
if
(
mysql_field_count
(
db_desc
->
db_conn
)
==
0
)
{
Logger
::
amf_n1
().
error
(
"[MySQL] %lld rows affected"
,
mysql_affected_rows
(
db_desc
->
db_conn
));
Logger
::
amf_n1
().
error
(
"[MySQL] %lld rows affected"
,
mysql_affected_rows
(
db_desc
->
db_conn
));
}
else
{
Logger
::
amf_n1
().
error
(
"Could not retrieve result set"
);
break
;
...
...
src/amf-app/mysql_db.hpp
View file @
e190aee7
...
...
@@ -45,7 +45,7 @@ typedef struct {
typedef
struct
{
// mysql reference connector object
MYSQL
*
db_conn
;
MYSQL
*
db_conn
;
std
::
string
server
;
std
::
string
user
;
std
::
string
password
;
...
...
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