open5gs/lib/s1ap/conv.c

87 lines
2.7 KiB
C
Raw Normal View History

2019-06-16 02:25:41 +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/>.
*/
2019-09-13 12:07:47 +00:00
#include "ogs-s1ap.h"
2019-09-13 12:07:47 +00:00
void ogs_s1ap_buffer_to_OCTET_STRING(
2018-03-05 14:01:07 +00:00
void *buf, int size, S1AP_TBCD_STRING_t *tbcd_string)
{
2017-03-24 13:52:55 +00:00
tbcd_string->size = size;
tbcd_string->buf = CALLOC(tbcd_string->size, sizeof(uint8_t));
2017-03-24 13:52:55 +00:00
memcpy(tbcd_string->buf, buf, size);
}
2019-09-13 12:07:47 +00:00
void ogs_s1ap_uint32_to_ENB_ID(
2019-04-27 14:54:30 +00:00
S1AP_ENB_ID_PR present, uint32_t enb_id, S1AP_ENB_ID_t *eNB_ID)
{
2019-04-27 14:54:30 +00:00
ogs_assert(eNB_ID);
2017-03-05 02:29:15 +00:00
eNB_ID->present = present;
2019-06-16 02:25:41 +00:00
if (present == S1AP_ENB_ID_PR_macroENB_ID) {
2017-03-05 02:29:15 +00:00
BIT_STRING_t *bit_string = &eNB_ID->choice.macroENB_ID;
2019-04-27 14:54:30 +00:00
ogs_assert(bit_string);
2017-03-05 02:29:15 +00:00
bit_string->size = 3;
bit_string->buf = CALLOC(bit_string->size, sizeof(uint8_t));
2017-03-05 02:29:15 +00:00
bit_string->buf[0] = enb_id >> 12;
bit_string->buf[1] = enb_id >> 4;
bit_string->buf[2] = (enb_id & 0xf) << 4;
bit_string->bits_unused = 4;
2019-06-16 02:25:41 +00:00
} else if (present == S1AP_ENB_ID_PR_homeENB_ID) {
2017-03-05 02:29:15 +00:00
BIT_STRING_t *bit_string = &eNB_ID->choice.homeENB_ID;
2019-04-27 14:54:30 +00:00
ogs_assert(bit_string);
2017-03-05 02:29:15 +00:00
bit_string->size = 4;
bit_string->buf = CALLOC(bit_string->size, sizeof(uint8_t));
2017-03-05 02:29:15 +00:00
bit_string->buf[0] = enb_id >> 20;
bit_string->buf[1] = enb_id >> 12;
bit_string->buf[2] = enb_id >> 4;
bit_string->buf[3] = (enb_id & 0xf) << 4;
bit_string->bits_unused = 4;
2019-06-16 02:25:41 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2017-03-05 02:29:15 +00:00
}
}
2017-02-13 05:41:20 +00:00
2019-09-13 12:07:47 +00:00
void ogs_s1ap_ENB_ID_to_uint32(S1AP_ENB_ID_t *eNB_ID, uint32_t *uint32)
2017-02-13 05:41:20 +00:00
{
2019-04-27 14:54:30 +00:00
ogs_assert(uint32);
ogs_assert(eNB_ID);
2017-02-13 05:41:20 +00:00
2019-06-16 02:25:41 +00:00
if (eNB_ID->present == S1AP_ENB_ID_PR_homeENB_ID) {
2019-04-27 14:54:30 +00:00
uint8_t *buf = eNB_ID->choice.homeENB_ID.buf;
ogs_assert(buf);
2017-02-13 05:41:20 +00:00
*uint32 = (buf[0] << 20) + (buf[1] << 12) + (buf[2] << 4) +
((buf[3] & 0xf0) >> 4);
2019-06-16 02:25:41 +00:00
} else if (eNB_ID->present == S1AP_ENB_ID_PR_macroENB_ID) {
2019-04-27 14:54:30 +00:00
uint8_t *buf = eNB_ID->choice.macroENB_ID.buf;
ogs_assert(buf);
2017-02-13 05:41:20 +00:00
*uint32 = (buf[0] << 12) + (buf[1] << 4) + ((buf[2] & 0xf0) >> 4);
2019-06-16 02:25:41 +00:00
} else {
2019-04-27 14:54:30 +00:00
ogs_assert_if_reached();
2017-02-13 05:41:20 +00:00
}
}