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 "ogs-sbi.h"
|
2020-06-17 05:22:28 +00:00
|
|
|
#include "yuarel.h"
|
2020-05-18 21:00:37 +00:00
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
char *ogs_uridup(bool https, ogs_sockaddr_t *addr, ogs_sbi_header_t *h)
|
2020-05-18 21:00:37 +00:00
|
|
|
{
|
|
|
|
char buf[OGS_ADDRSTRLEN];
|
2020-06-17 05:22:28 +00:00
|
|
|
char uri[OGS_HUGE_LEN];
|
2020-05-18 21:00:37 +00:00
|
|
|
char *p, *last;
|
2020-06-04 18:12:05 +00:00
|
|
|
int i;
|
2020-05-18 21:00:37 +00:00
|
|
|
|
|
|
|
ogs_assert(addr);
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_assert(h);
|
2020-05-18 21:00:37 +00:00
|
|
|
|
2020-06-17 05:22:28 +00:00
|
|
|
p = uri;
|
|
|
|
last = uri + OGS_HUGE_LEN;
|
2020-05-18 21:00:37 +00:00
|
|
|
|
|
|
|
/* HTTP scheme is selected based on TLS information */
|
|
|
|
if (https == true)
|
|
|
|
p = ogs_slprintf(p, last, "https://");
|
|
|
|
else
|
|
|
|
p = ogs_slprintf(p, last, "http://");
|
|
|
|
|
|
|
|
/* IP address */
|
|
|
|
if (addr->ogs_sa_family == AF_INET6)
|
|
|
|
p = ogs_slprintf(p, last, "[%s]", OGS_ADDR(addr, buf));
|
|
|
|
else
|
|
|
|
p = ogs_slprintf(p, last, "%s", OGS_ADDR(addr, buf));
|
|
|
|
|
|
|
|
/* Port number */
|
2021-05-30 01:35:01 +00:00
|
|
|
if ((https == true && OGS_PORT(addr) == OGS_SBI_HTTPS_PORT)) {
|
|
|
|
/* No Port in URI */
|
|
|
|
} else if (OGS_PORT(addr) == OGS_SBI_HTTP_PORT) {
|
|
|
|
/* No Port in URI */
|
|
|
|
} else {
|
2020-05-18 21:00:37 +00:00
|
|
|
p = ogs_slprintf(p, last, ":%d", OGS_PORT(addr));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* API */
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_assert(h->service.name);
|
|
|
|
p = ogs_slprintf(p, last, "/%s", h->service.name);
|
|
|
|
ogs_assert(h->api.version);
|
|
|
|
p = ogs_slprintf(p, last, "/%s", h->api.version);
|
2020-05-18 21:00:37 +00:00
|
|
|
|
|
|
|
/* Resource */
|
2020-06-04 18:12:05 +00:00
|
|
|
ogs_assert(h->resource.component[0]);
|
|
|
|
for (i = 0; i < OGS_SBI_MAX_NUM_OF_RESOURCE_COMPONENT &&
|
|
|
|
h->resource.component[i]; i++)
|
|
|
|
p = ogs_slprintf(p, last, "/%s", h->resource.component[i]);
|
2020-05-18 21:00:37 +00:00
|
|
|
|
2020-06-17 05:22:28 +00:00
|
|
|
return ogs_strdup(uri);
|
2020-05-18 21:00:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
char *ogs_sbi_server_uri(ogs_sbi_server_t *server, ogs_sbi_header_t *h)
|
2020-05-18 21:00:37 +00:00
|
|
|
{
|
2021-03-19 12:01:38 +00:00
|
|
|
ogs_sockaddr_t *advertise = NULL;
|
2020-05-18 21:00:37 +00:00
|
|
|
bool https = false;
|
2020-06-04 18:12:05 +00:00
|
|
|
|
|
|
|
ogs_assert(server);
|
|
|
|
ogs_assert(h);
|
|
|
|
|
2020-05-18 21:00:37 +00:00
|
|
|
if (server->tls.key && server->tls.pem)
|
|
|
|
https = true;
|
|
|
|
|
2021-03-19 12:01:38 +00:00
|
|
|
advertise = server->advertise;
|
|
|
|
|
|
|
|
if (!advertise)
|
|
|
|
advertise = server->node.addr;
|
|
|
|
ogs_assert(advertise);
|
|
|
|
|
|
|
|
return ogs_uridup(https, advertise, h);
|
2020-05-18 21:00:37 +00:00
|
|
|
}
|
|
|
|
|
2020-06-04 18:12:05 +00:00
|
|
|
char *ogs_sbi_client_uri(ogs_sbi_client_t *client, ogs_sbi_header_t *h)
|
2020-05-18 21:00:37 +00:00
|
|
|
{
|
|
|
|
bool https = false;
|
2020-06-04 18:12:05 +00:00
|
|
|
|
|
|
|
ogs_assert(client);
|
|
|
|
ogs_assert(h);
|
|
|
|
|
2020-05-18 21:00:37 +00:00
|
|
|
if (client->tls.key && client->tls.pem)
|
|
|
|
https = true;
|
|
|
|
|
2020-11-27 02:44:37 +00:00
|
|
|
return ogs_uridup(https, client->node.addr, h);
|
2020-05-18 21:00:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a url-decoded version of str
|
|
|
|
* IMPORTANT: be sure to free() the returned string after use
|
|
|
|
* Thanks Geek Hideout!
|
|
|
|
* http://www.geekhideout.com/urlcode.shtml
|
|
|
|
*/
|
|
|
|
static char *url_decode(const char *str)
|
|
|
|
{
|
|
|
|
if (str != NULL) {
|
|
|
|
char *pstr = (char*)str;
|
2021-06-06 13:35:46 +00:00
|
|
|
char *buf = ogs_malloc_or_assert(strlen(str) + 1);
|
2020-05-18 21:00:37 +00:00
|
|
|
char *pbuf = buf;
|
|
|
|
while (*pstr) {
|
|
|
|
if (*pstr == '%') {
|
|
|
|
if (pstr[1] && pstr[2]) {
|
|
|
|
*pbuf++ = ogs_from_hex(pstr[1]) << 4 |
|
|
|
|
ogs_from_hex(pstr[2]);
|
|
|
|
pstr += 2;
|
|
|
|
}
|
|
|
|
} else if (*pstr == '+') {
|
|
|
|
*pbuf++ = ' ';
|
|
|
|
} else {
|
|
|
|
*pbuf++ = * pstr;
|
|
|
|
}
|
|
|
|
pstr++;
|
|
|
|
}
|
|
|
|
*pbuf = '\0';
|
|
|
|
return buf;
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 05:22:28 +00:00
|
|
|
char *ogs_sbi_parse_uri(char *uri, const char *delim, char **saveptr)
|
2020-05-18 21:00:37 +00:00
|
|
|
{
|
|
|
|
char *item = NULL;
|
|
|
|
|
2020-06-17 05:22:28 +00:00
|
|
|
item = url_decode(strtok_r(uri, delim, saveptr));
|
2020-05-18 21:00:37 +00:00
|
|
|
if (!item) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
|
|
|
|
ogs_sockaddr_t *ogs_sbi_getaddr_from_uri(char *uri)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct yuarel yuarel;
|
|
|
|
char *p = NULL;
|
|
|
|
int port;
|
|
|
|
|
|
|
|
ogs_sockaddr_t *addr = NULL;
|
|
|
|
|
|
|
|
p = ogs_strdup(uri);
|
|
|
|
|
|
|
|
rv = yuarel_parse(&yuarel, p);
|
|
|
|
if (rv != OGS_OK) {
|
|
|
|
ogs_free(p);
|
|
|
|
ogs_error("yuarel_parse() failed [%s]", uri);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!yuarel.scheme) {
|
|
|
|
ogs_error("No http.scheme found [%s]", uri);
|
|
|
|
ogs_free(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(yuarel.scheme, "https") == 0) {
|
|
|
|
port = OGS_SBI_HTTPS_PORT;
|
|
|
|
} else if (strcmp(yuarel.scheme, "http") == 0) {
|
|
|
|
port = OGS_SBI_HTTP_PORT;
|
|
|
|
} else {
|
|
|
|
ogs_error("Invalid http.scheme [%s:%s]", yuarel.scheme, uri);
|
|
|
|
ogs_free(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!yuarel.host) {
|
|
|
|
ogs_error("No http.host found [%s]", uri);
|
|
|
|
ogs_free(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yuarel.port) port = yuarel.port;
|
|
|
|
|
|
|
|
rv = ogs_getaddrinfo(&addr, AF_UNSPEC, yuarel.host, port, 0);
|
|
|
|
if (rv != OGS_OK) {
|
|
|
|
ogs_error("ogs_getaddrinfo() failed [%s]", uri);
|
|
|
|
ogs_free(p);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ogs_free(p);
|
|
|
|
return addr;
|
|
|
|
}
|
2020-06-17 05:22:28 +00:00
|
|
|
|
|
|
|
char *ogs_sbi_bitrate_to_string(uint64_t bitrate, int unit)
|
|
|
|
{
|
|
|
|
if (unit == OGS_SBI_BITRATE_KBPS) {
|
|
|
|
return ogs_msprintf("%lld Kbps",
|
|
|
|
(long long)bitrate / 1024);
|
|
|
|
} else if (unit == OGS_SBI_BITRATE_MBPS) {
|
|
|
|
return ogs_msprintf("%lld Mbps",
|
|
|
|
(long long)bitrate / 1024 / 1024);
|
|
|
|
} else if (unit == OGS_SBI_BITRATE_GBPS) {
|
|
|
|
return ogs_msprintf("%lld Gbps",
|
|
|
|
(long long)bitrate / 1024 / 1024 / 1024);
|
|
|
|
} else if (unit == OGS_SBI_BITRATE_TBPS) {
|
|
|
|
return ogs_msprintf("%lld Tbps",
|
|
|
|
(long long)bitrate / 1024 / 1024 / 1024 / 1024);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ogs_msprintf("%lld bps", (long long)bitrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t ogs_sbi_bitrate_from_string(char *str)
|
|
|
|
{
|
|
|
|
char *unit = NULL;
|
|
|
|
uint64_t bitrate = 0;
|
|
|
|
ogs_assert(str);
|
|
|
|
|
|
|
|
unit = strrchr(str, ' ');
|
|
|
|
bitrate = atoll(str);
|
|
|
|
|
|
|
|
SWITCH(unit+1)
|
|
|
|
CASE("Kbps")
|
|
|
|
return bitrate * 1024;
|
|
|
|
CASE("Mbps")
|
|
|
|
return bitrate * 1024 * 1024;
|
|
|
|
CASE("Gbps")
|
|
|
|
return bitrate * 1024 * 1024 * 1024;
|
|
|
|
CASE("Tbps")
|
|
|
|
return bitrate * 1024 * 1024 * 1024 * 1024;
|
|
|
|
DEFAULT
|
|
|
|
END
|
|
|
|
return bitrate;
|
|
|
|
}
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
#define MAX_TIMESTR_LEN 128
|
|
|
|
|
2021-01-01 02:55:11 +00:00
|
|
|
int ogs_strftimezone(char *str, size_t size, int tm_gmtoff)
|
2020-12-24 20:41:31 +00:00
|
|
|
{
|
|
|
|
uint8_t off_sign;
|
|
|
|
int off;
|
2021-04-05 12:16:52 +00:00
|
|
|
int len;
|
2020-12-24 20:41:31 +00:00
|
|
|
|
|
|
|
ogs_assert(str);
|
|
|
|
ogs_assert(size);
|
|
|
|
|
|
|
|
off_sign = '+';
|
|
|
|
off = tm_gmtoff;
|
|
|
|
if (tm_gmtoff < 0) {
|
|
|
|
off_sign = '-';
|
|
|
|
off = -off;
|
|
|
|
}
|
|
|
|
|
2021-04-05 12:16:52 +00:00
|
|
|
len = ogs_snprintf(str, size, "%c%02d:%02d",
|
2020-12-24 20:41:31 +00:00
|
|
|
off_sign, off / 3600, off % 3600);
|
2021-04-05 12:16:52 +00:00
|
|
|
|
|
|
|
if (len != 6) {
|
|
|
|
ogs_warn("Unknown tm_gmtoff[%d:%d]", tm_gmtoff, off);
|
|
|
|
|
|
|
|
len = ogs_snprintf(str, size, "%c%02d:%02d",
|
|
|
|
off_sign, (off / 3600) % 100, (off % 3600) % 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
2020-12-24 20:41:31 +00:00
|
|
|
}
|
|
|
|
|
2021-01-08 05:24:00 +00:00
|
|
|
#define USE_MILLISECONDS_IN_RFC3339 0
|
2020-12-29 18:26:36 +00:00
|
|
|
|
2020-07-09 05:38:09 +00:00
|
|
|
char *ogs_sbi_localtime_string(ogs_time_t timestamp)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
|
|
|
|
char datetime[MAX_TIMESTR_LEN];
|
|
|
|
char timezone[MAX_TIMESTR_LEN];
|
2020-12-24 20:41:31 +00:00
|
|
|
int len;
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
ogs_localtime(ogs_time_sec(timestamp), &tm);
|
|
|
|
ogs_strftime(datetime, sizeof datetime, "%Y-%m-%dT%H:%M:%S", &tm);
|
2020-12-24 20:41:31 +00:00
|
|
|
|
|
|
|
len = ogs_strftimezone(timezone, MAX_TIMESTR_LEN, tm.tm_gmtoff);
|
|
|
|
ogs_assert(len == 6);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
2020-12-29 18:26:36 +00:00
|
|
|
#if USE_MILLISECONDS_IN_RFC3339
|
|
|
|
return ogs_msprintf("%s.%03lld%s",
|
|
|
|
datetime, (long long)ogs_time_msec(timestamp), timezone);
|
|
|
|
#else
|
2020-07-09 05:38:09 +00:00
|
|
|
return ogs_msprintf("%s.%06lld%s",
|
|
|
|
datetime, (long long)ogs_time_usec(timestamp), timezone);
|
2020-12-29 18:26:36 +00:00
|
|
|
#endif
|
2020-07-09 05:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *ogs_sbi_gmtime_string(ogs_time_t timestamp)
|
|
|
|
{
|
|
|
|
struct tm tm;
|
|
|
|
|
|
|
|
char datetime[MAX_TIMESTR_LEN];
|
|
|
|
|
|
|
|
ogs_gmtime(ogs_time_sec(timestamp), &tm);
|
|
|
|
ogs_strftime(datetime, sizeof datetime, "%Y-%m-%dT%H:%M:%S", &tm);
|
|
|
|
|
2020-12-29 18:26:36 +00:00
|
|
|
#if USE_MILLISECONDS_IN_RFC3339
|
|
|
|
return ogs_msprintf("%s.%03lldZ",
|
|
|
|
datetime, (long long)ogs_time_msec(timestamp));
|
|
|
|
#else
|
2020-07-09 05:38:09 +00:00
|
|
|
return ogs_msprintf("%s.%06lldZ",
|
|
|
|
datetime, (long long)ogs_time_usec(timestamp));
|
2020-12-29 18:26:36 +00:00
|
|
|
#endif
|
2020-07-09 05:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *ogs_sbi_timezone_string(int tm_gmtoff)
|
|
|
|
{
|
|
|
|
char timezone[MAX_TIMESTR_LEN];
|
2020-12-24 20:41:31 +00:00
|
|
|
int len;
|
2020-07-09 05:38:09 +00:00
|
|
|
|
2020-12-24 20:41:31 +00:00
|
|
|
len = ogs_strftimezone(timezone, MAX_TIMESTR_LEN, tm_gmtoff);
|
|
|
|
ogs_assert(len == 6);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
return ogs_msprintf("%s", timezone);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_time_from_string(ogs_time_t *timestamp, char *str)
|
|
|
|
{
|
|
|
|
int rv, i, j, k;
|
|
|
|
struct tm tm;
|
2021-02-08 19:25:40 +00:00
|
|
|
bool is_subsecs, is_time, timezone_found;
|
2020-07-09 05:38:09 +00:00
|
|
|
char seconds[MAX_TIMESTR_LEN];
|
|
|
|
char subsecs[MAX_TIMESTR_LEN];
|
|
|
|
ogs_time_t usecs;
|
|
|
|
|
|
|
|
ogs_assert(str);
|
|
|
|
ogs_assert(timestamp);
|
|
|
|
|
|
|
|
memset(seconds, 0, sizeof seconds);
|
|
|
|
memset(subsecs, 0, sizeof subsecs);
|
|
|
|
|
2021-02-08 19:25:40 +00:00
|
|
|
is_subsecs = false;
|
|
|
|
is_time = false;
|
|
|
|
timezone_found = false;
|
2020-07-09 05:38:09 +00:00
|
|
|
i = 0; j = 0, k = 0;
|
|
|
|
while(str[i]) {
|
2021-02-08 19:25:40 +00:00
|
|
|
if (is_subsecs == false && str[i] == '.')
|
|
|
|
is_subsecs = true;
|
|
|
|
else if (is_subsecs == false && str[i] == 'T')
|
|
|
|
is_time = true;
|
|
|
|
else if (is_subsecs == true && (str[i] < '0' || str[i] > '9'))
|
|
|
|
is_subsecs = false;
|
2020-07-09 05:38:09 +00:00
|
|
|
|
2021-02-08 19:25:40 +00:00
|
|
|
if (is_time == true && (str[i] == '+' || str[i] == '-'))
|
|
|
|
timezone_found = true;
|
|
|
|
|
|
|
|
if (is_subsecs == false) {
|
2020-12-24 20:41:31 +00:00
|
|
|
if (str[i] == ':' && i >= 3 &&
|
|
|
|
(str[i-3] == '+' || str[i-3] == '-')) {
|
2021-02-08 19:25:40 +00:00
|
|
|
/* remove ':' character in timezone string range */
|
2020-12-24 20:41:31 +00:00
|
|
|
} else {
|
|
|
|
seconds[j++] = str[i];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
subsecs[k++] = str[i];
|
|
|
|
}
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&tm, 0, sizeof(tm));
|
2021-02-08 19:25:40 +00:00
|
|
|
if (timezone_found == true)
|
|
|
|
ogs_strptime(seconds, "%Y-%m-%dT%H:%M:%S%z", &tm);
|
|
|
|
else
|
|
|
|
ogs_strptime(seconds, "%Y-%m-%dT%H:%M:%S", &tm);
|
2021-01-09 04:16:54 +00:00
|
|
|
#if USE_MATH
|
2021-01-08 15:42:51 +00:00
|
|
|
usecs = (ogs_time_t)floor(atof(subsecs) * 1000000.0 + 0.5);
|
2021-01-09 04:16:54 +00:00
|
|
|
#else
|
|
|
|
usecs = (ogs_time_t)((atof(subsecs) * 10000000 + 5) / 10);
|
|
|
|
#endif
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
rv = ogs_time_from_gmt(timestamp, &tm, usecs);
|
|
|
|
if (rv != OGS_OK) {
|
|
|
|
ogs_error("Cannot convert time [%s]", str);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-11 19:03:20 +00:00
|
|
|
char *ogs_sbi_s_nssai_to_string(ogs_s_nssai_t *s_nssai)
|
|
|
|
{
|
|
|
|
cJSON *item = NULL;
|
|
|
|
OpenAPI_snssai_t sNSSAI;
|
|
|
|
|
|
|
|
char *v = NULL;
|
|
|
|
|
|
|
|
ogs_assert(s_nssai);
|
|
|
|
|
|
|
|
sNSSAI.sst = s_nssai->sst;
|
|
|
|
sNSSAI.sd = ogs_s_nssai_sd_to_string(s_nssai->sd);
|
|
|
|
|
|
|
|
item = OpenAPI_snssai_convertToJSON(&sNSSAI);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(item, NULL);
|
2020-12-11 19:03:20 +00:00
|
|
|
if (sNSSAI.sd) ogs_free(sNSSAI.sd);
|
|
|
|
|
|
|
|
v = cJSON_Print(item);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect(v);
|
2020-12-11 19:03:20 +00:00
|
|
|
cJSON_Delete(item);
|
|
|
|
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_s_nssai_from_string(ogs_s_nssai_t *s_nssai, char *str)
|
|
|
|
{
|
|
|
|
bool rc = false;
|
|
|
|
|
|
|
|
cJSON *item = NULL;
|
|
|
|
OpenAPI_snssai_t *sNSSAI = NULL;
|
|
|
|
|
|
|
|
ogs_assert(s_nssai);
|
|
|
|
ogs_assert(str);
|
|
|
|
|
|
|
|
item = cJSON_Parse(str);
|
|
|
|
if (item) {
|
|
|
|
sNSSAI = OpenAPI_snssai_parseFromJSON(item);
|
|
|
|
if (sNSSAI) {
|
|
|
|
s_nssai->sst = sNSSAI->sst;
|
|
|
|
s_nssai->sd = ogs_s_nssai_sd_from_string(sNSSAI->sd);
|
|
|
|
OpenAPI_snssai_free(sNSSAI);
|
|
|
|
rc = true;
|
|
|
|
}
|
|
|
|
cJSON_Delete(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2020-07-09 05:38:09 +00:00
|
|
|
OpenAPI_plmn_id_t *ogs_sbi_build_plmn_id(ogs_plmn_id_t *plmn_id)
|
|
|
|
{
|
|
|
|
OpenAPI_plmn_id_t *PlmnId = NULL;
|
|
|
|
|
|
|
|
ogs_assert(plmn_id);
|
|
|
|
|
|
|
|
PlmnId = ogs_calloc(1, sizeof(*PlmnId));
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnId, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
PlmnId->mcc = ogs_plmn_id_mcc_string(plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnId->mcc, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
PlmnId->mnc = ogs_plmn_id_mnc_string(plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnId->mnc, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
return PlmnId;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_parse_plmn_id(
|
|
|
|
ogs_plmn_id_t *plmn_id, OpenAPI_plmn_id_t *PlmnId)
|
|
|
|
{
|
|
|
|
ogs_assert(plmn_id);
|
|
|
|
ogs_assert(PlmnId);
|
|
|
|
ogs_assert(PlmnId->mcc);
|
|
|
|
ogs_assert(PlmnId->mnc);
|
|
|
|
|
|
|
|
ogs_plmn_id_build(plmn_id,
|
|
|
|
atoi(PlmnId->mcc), atoi(PlmnId->mnc), strlen(PlmnId->mnc));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ogs_sbi_free_plmn_id(OpenAPI_plmn_id_t *PlmnId)
|
|
|
|
{
|
|
|
|
ogs_assert(PlmnId);
|
|
|
|
|
|
|
|
if (PlmnId->mcc)
|
|
|
|
ogs_free(PlmnId->mcc);
|
|
|
|
if (PlmnId->mnc)
|
|
|
|
ogs_free(PlmnId->mnc);
|
|
|
|
|
|
|
|
ogs_free(PlmnId);
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenAPI_plmn_id_nid_t *ogs_sbi_build_plmn_id_nid(ogs_plmn_id_t *plmn_id)
|
|
|
|
{
|
|
|
|
OpenAPI_plmn_id_nid_t *PlmnIdNid = NULL;
|
|
|
|
|
|
|
|
ogs_assert(plmn_id);
|
|
|
|
|
|
|
|
PlmnIdNid = ogs_calloc(1, sizeof(*PlmnIdNid));
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnIdNid, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
PlmnIdNid->mcc = ogs_plmn_id_mcc_string(plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnIdNid->mcc, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
PlmnIdNid->mnc = ogs_plmn_id_mnc_string(plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(PlmnIdNid->mnc, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
return PlmnIdNid;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_parse_plmn_id_nid(
|
|
|
|
ogs_plmn_id_t *plmn_id, OpenAPI_plmn_id_nid_t *PlmnIdNid)
|
|
|
|
{
|
|
|
|
ogs_assert(plmn_id);
|
|
|
|
ogs_assert(PlmnIdNid);
|
|
|
|
ogs_assert(PlmnIdNid->mcc);
|
|
|
|
ogs_assert(PlmnIdNid->mnc);
|
|
|
|
|
|
|
|
ogs_plmn_id_build(plmn_id,
|
|
|
|
atoi(PlmnIdNid->mcc), atoi(PlmnIdNid->mnc), strlen(PlmnIdNid->mnc));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ogs_sbi_free_plmn_id_nid(OpenAPI_plmn_id_nid_t *PlmnIdNid)
|
|
|
|
{
|
|
|
|
ogs_assert(PlmnIdNid);
|
|
|
|
|
|
|
|
if (PlmnIdNid->mcc)
|
|
|
|
ogs_free(PlmnIdNid->mcc);
|
|
|
|
if (PlmnIdNid->mnc)
|
|
|
|
ogs_free(PlmnIdNid->mnc);
|
|
|
|
if (PlmnIdNid->nid)
|
|
|
|
ogs_free(PlmnIdNid->nid);
|
|
|
|
|
|
|
|
ogs_free(PlmnIdNid);
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenAPI_guami_t *ogs_sbi_build_guami(ogs_guami_t *guami)
|
|
|
|
{
|
|
|
|
OpenAPI_guami_t *Guami = NULL;
|
|
|
|
|
|
|
|
ogs_assert(guami);
|
|
|
|
|
|
|
|
Guami = ogs_calloc(1, sizeof(*Guami));
|
|
|
|
ogs_assert(Guami);
|
|
|
|
|
2021-03-08 12:25:09 +00:00
|
|
|
Guami->plmn_id = ogs_sbi_build_plmn_id_nid(&guami->plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Guami->plmn_id, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
Guami->amf_id = ogs_amf_id_to_string(&guami->amf_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Guami->amf_id, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
return Guami;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_parse_guami(ogs_guami_t *guami, OpenAPI_guami_t *Guami)
|
|
|
|
{
|
|
|
|
ogs_assert(guami);
|
|
|
|
ogs_assert(Guami);
|
|
|
|
ogs_assert(Guami->amf_id);
|
|
|
|
ogs_assert(Guami->plmn_id);
|
|
|
|
|
|
|
|
ogs_amf_id_from_string(&guami->amf_id, Guami->amf_id);
|
2021-03-08 12:25:09 +00:00
|
|
|
ogs_sbi_parse_plmn_id_nid(&guami->plmn_id, Guami->plmn_id);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ogs_sbi_free_guami(OpenAPI_guami_t *Guami)
|
|
|
|
{
|
|
|
|
ogs_assert(Guami);
|
|
|
|
|
|
|
|
if (Guami->plmn_id)
|
2021-03-08 12:25:09 +00:00
|
|
|
ogs_sbi_free_plmn_id_nid(Guami->plmn_id);
|
2020-07-09 05:38:09 +00:00
|
|
|
if (Guami->amf_id)
|
|
|
|
ogs_free(Guami->amf_id);
|
|
|
|
ogs_free(Guami);
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenAPI_nr_location_t *ogs_sbi_build_nr_location(
|
|
|
|
ogs_5gs_tai_t *tai, ogs_nr_cgi_t *nr_cgi)
|
|
|
|
{
|
|
|
|
OpenAPI_nr_location_t *NrLocation = NULL;
|
|
|
|
OpenAPI_tai_t *Tai = NULL;
|
|
|
|
OpenAPI_ncgi_t *Ncgi = NULL;
|
|
|
|
|
|
|
|
ogs_assert(tai);
|
|
|
|
ogs_assert(nr_cgi);
|
|
|
|
|
|
|
|
Tai = ogs_calloc(1, sizeof(*Tai));
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Tai, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
Tai->plmn_id = ogs_sbi_build_plmn_id(&tai->plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Tai->plmn_id, NULL);
|
2021-01-01 02:07:08 +00:00
|
|
|
Tai->tac = ogs_uint24_to_0string(tai->tac);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Tai->tac, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
Ncgi = ogs_calloc(1, sizeof(*Ncgi));
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Ncgi, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
Ncgi->plmn_id = ogs_sbi_build_plmn_id(&nr_cgi->plmn_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Ncgi->plmn_id, NULL);
|
2021-01-01 02:07:08 +00:00
|
|
|
Ncgi->nr_cell_id = ogs_uint36_to_0string(nr_cgi->cell_id);
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(Ncgi->nr_cell_id, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
NrLocation = ogs_calloc(1, sizeof(*NrLocation));
|
2021-06-06 13:35:46 +00:00
|
|
|
ogs_expect_or_return_val(NrLocation, NULL);
|
2020-07-09 05:38:09 +00:00
|
|
|
NrLocation->tai = Tai;
|
|
|
|
NrLocation->ncgi = Ncgi;
|
|
|
|
|
|
|
|
return NrLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ogs_sbi_parse_nr_location(ogs_5gs_tai_t *tai, ogs_nr_cgi_t *nr_cgi,
|
|
|
|
OpenAPI_nr_location_t *NrLocation)
|
|
|
|
{
|
|
|
|
OpenAPI_tai_t *Tai = NULL;
|
|
|
|
OpenAPI_ncgi_t *Ncgi = NULL;
|
|
|
|
|
|
|
|
ogs_assert(tai);
|
|
|
|
ogs_assert(nr_cgi);
|
|
|
|
ogs_assert(NrLocation);
|
|
|
|
|
|
|
|
Tai = NrLocation->tai;
|
|
|
|
if (Tai) {
|
|
|
|
if (Tai->plmn_id)
|
|
|
|
ogs_sbi_parse_plmn_id(&tai->plmn_id, Tai->plmn_id);
|
|
|
|
if (Tai->tac)
|
|
|
|
tai->tac = ogs_uint24_from_string(Tai->tac);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ncgi = NrLocation->ncgi;
|
|
|
|
if (Ncgi) {
|
|
|
|
if (Ncgi->plmn_id)
|
|
|
|
ogs_sbi_parse_plmn_id(&nr_cgi->plmn_id, Ncgi->plmn_id);
|
|
|
|
if (Ncgi->nr_cell_id)
|
2021-01-01 02:07:08 +00:00
|
|
|
nr_cgi->cell_id = ogs_uint64_from_string(Ncgi->nr_cell_id);
|
2020-07-09 05:38:09 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ogs_sbi_free_nr_location(OpenAPI_nr_location_t *NrLocation)
|
|
|
|
{
|
|
|
|
OpenAPI_tai_t *Tai = NULL;
|
|
|
|
OpenAPI_ncgi_t *Ncgi = NULL;
|
|
|
|
|
|
|
|
ogs_assert(NrLocation);
|
|
|
|
|
|
|
|
Tai = NrLocation->tai;
|
|
|
|
if (Tai) {
|
|
|
|
if (Tai->plmn_id)
|
|
|
|
ogs_sbi_free_plmn_id(Tai->plmn_id);
|
|
|
|
if (Tai->tac)
|
|
|
|
ogs_free(Tai->tac);
|
|
|
|
ogs_free(Tai);
|
|
|
|
}
|
|
|
|
|
|
|
|
Ncgi = NrLocation->ncgi;
|
|
|
|
if (Ncgi) {
|
|
|
|
if (Ncgi->plmn_id)
|
|
|
|
ogs_sbi_free_plmn_id(Ncgi->plmn_id);
|
|
|
|
if (Ncgi->nr_cell_id)
|
|
|
|
ogs_free(Ncgi->nr_cell_id);
|
|
|
|
ogs_free(Ncgi);
|
|
|
|
}
|
|
|
|
|
|
|
|
ogs_free(NrLocation);
|
|
|
|
}
|