2020-05-18 21:00:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of Open5GS.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "context.h"
|
|
|
|
#include "sbi-path.h"
|
|
|
|
|
|
|
|
static int server_cb(ogs_sbi_server_t *server,
|
|
|
|
ogs_sbi_session_t *session, ogs_sbi_request_t *request)
|
|
|
|
{
|
|
|
|
smf_event_t *e = NULL;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
ogs_assert(session);
|
|
|
|
ogs_assert(request);
|
|
|
|
|
|
|
|
e = smf_event_new(SMF_EVT_SBI_SERVER);
|
|
|
|
ogs_assert(e);
|
|
|
|
|
|
|
|
e->sbi.server = server;
|
|
|
|
e->sbi.session = session;
|
|
|
|
e->sbi.request = request;
|
|
|
|
|
|
|
|
rv = ogs_queue_push(smf_self()->queue, e);
|
|
|
|
if (rv != OGS_OK) {
|
|
|
|
ogs_warn("ogs_queue_push() failed:%d", (int)rv);
|
|
|
|
smf_event_free(e);
|
|
|
|
return OGS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OGS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int client_cb(ogs_sbi_response_t *response, void *data)
|
|
|
|
{
|
|
|
|
smf_event_t *e = NULL;
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
ogs_assert(response);
|
|
|
|
|
|
|
|
e = smf_event_new(SMF_EVT_SBI_CLIENT);
|
|
|
|
ogs_assert(e);
|
|
|
|
e->sbi.response = response;
|
|
|
|
e->sbi.data = data;
|
|
|
|
|
|
|
|
rv = ogs_queue_push(smf_self()->queue, e);
|
|
|
|
if (rv != OGS_OK) {
|
|
|
|
ogs_warn("ogs_queue_push() failed:%d", (int)rv);
|
|
|
|
smf_event_free(e);
|
|
|
|
return OGS_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OGS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
int smf_sbi_open(void)
|
|
|
|
{
|
|
|
|
ogs_sbi_nf_instance_t *nf_instance = NULL;
|
|
|
|
|
|
|
|
ogs_sbi_server_start_all(server_cb);
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_list_for_each(&ogs_sbi_self()->nf_instance_list, nf_instance) {
|
2020-05-18 21:00:37 +00:00
|
|
|
ogs_sbi_nf_service_t *service = NULL;
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_sbi_nf_instance_build_default(nf_instance, smf_self()->nf_type);
|
2020-05-18 21:00:37 +00:00
|
|
|
|
|
|
|
service = ogs_sbi_nf_service_build_default(nf_instance,
|
2020-06-04 18:12:05 +00:00
|
|
|
(char*)OGS_SBI_SERVICE_NAME_NSMF_PDUSESSION);
|
2020-05-18 21:00:37 +00:00
|
|
|
ogs_assert(service);
|
|
|
|
ogs_sbi_nf_service_add_version(service, (char*)OGS_SBI_API_VERSION,
|
|
|
|
(char*)OGS_SBI_API_FULL_VERSION, NULL);
|
|
|
|
|
|
|
|
smf_nf_fsm_init(nf_instance);
|
2020-06-04 18:12:05 +00:00
|
|
|
smf_sbi_setup_client_callback(nf_instance);
|
2020-05-18 21:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return OGS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smf_sbi_close(void)
|
|
|
|
{
|
|
|
|
ogs_sbi_server_stop_all();
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
void smf_sbi_setup_client_callback(ogs_sbi_nf_instance_t *nf_instance)
|
2020-05-18 21:00:37 +00:00
|
|
|
{
|
|
|
|
ogs_sbi_client_t *client = NULL;
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_sbi_nf_service_t *nf_service = NULL;
|
2020-05-18 21:00:37 +00:00
|
|
|
ogs_assert(nf_instance);
|
|
|
|
|
|
|
|
client = nf_instance->client;
|
|
|
|
ogs_assert(client);
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
client->cb = client_cb;
|
2020-05-18 21:00:37 +00:00
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_list_for_each(&nf_instance->nf_service_list, nf_service) {
|
|
|
|
client = nf_service->client;
|
|
|
|
if (client)
|
|
|
|
client->cb = client_cb;
|
|
|
|
}
|
2020-05-18 21:00:37 +00:00
|
|
|
}
|