Merge remote-tracking branch 'origin/issue_178' into next

This commit is contained in:
Andre Puschmann 2018-09-25 15:10:38 +02:00
commit b27ff06e79
6 changed files with 82 additions and 118 deletions

View File

@ -0,0 +1,66 @@
/**
*
* \section COPYRIGHT
*
* Copyright 2013-2015 Software Radio Systems Limited
*
* \section LICENSE
*
* This file is part of the srsUE library.
*
* srsUE 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.
*
* srsUE 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 Affero General Public License for more details.
*
* A copy of the GNU Affero General Public License can be found in
* the LICENSE file in the top-level directory of this distribution
* and at http://www.gnu.org/licenses/.
*
*/
#ifndef SRSLTE_INT_HELPERS_H
#define SRSLTE_INT_HELPERS_H
namespace srslte {
/******************************************************************************
* Safe conversions between byte buffers and integer types.
* Note: these don't perform endian conversion - use e.g. htonl/ntohl if required
*****************************************************************************/
inline void uint8_to_uint32(uint8_t *buf, uint32_t *i)
{
*i = (uint32_t)buf[0] << 24 |
(uint32_t)buf[1] << 16 |
(uint32_t)buf[2] << 8 |
(uint32_t)buf[3];
}
inline void uint32_to_uint8(uint32_t i, uint8_t *buf)
{
buf[0] = (i >> 24) & 0xFF;
buf[1] = (i >> 16) & 0xFF;
buf[2] = (i >> 8) & 0xFF;
buf[3] = i & 0xFF;
}
inline void uint8_to_uint16(uint8_t *buf, uint16_t *i)
{
*i = (uint32_t)buf[0] << 8 |
(uint32_t)buf[1];
}
inline void uint16_to_uint8(uint16_t i, uint8_t *buf)
{
buf[0] = (i >> 8) & 0xFF;
buf[1] = i & 0xFF;
}
}; //namespace
#endif // SRSLTE_INT_HELPERS_H

View File

@ -36,7 +36,6 @@
namespace srsenb {
#define ENB_METRICS_MAX_USERS 64
#define SRSENB_RRC_MAX_N_PLMN_IDENTITIES 6
#define SRSENB_N_SRB 3
@ -74,111 +73,6 @@ static const char rb_id_text[RB_ID_N_ITEMS][20] = { "SRB0",
#define SRSENB_MAX_BUFFER_SIZE_BITS 102048
#define SRSENB_MAX_BUFFER_SIZE_BYTES 12756
#define SRSENB_BUFFER_HEADER_OFFSET 1024
/******************************************************************************
* Convert PLMN to BCD-coded MCC and MNC.
* Digits are represented by 4-bit nibbles. Unused nibbles are filled with 0xF.
* MNC 001 represented as 0xF001
* MNC 01 represented as 0xFF01
* PLMN encoded as per TS 36.413 sec 9.2.3.8
*****************************************************************************/
inline void s1ap_plmn_to_mccmnc(uint32_t plmn, uint16_t *mcc, uint16_t *mnc)
{
uint8_t nibbles[6];
nibbles[0] = (plmn & 0xF00000) >> 20;
nibbles[1] = (plmn & 0x0F0000) >> 16;
nibbles[2] = (plmn & 0x00F000) >> 12;
nibbles[3] = (plmn & 0x000F00) >> 8;
nibbles[4] = (plmn & 0x0000F0) >> 4;
nibbles[5] = (plmn & 0x00000F);
*mcc = 0xF000;
*mnc = 0xF000;
*mcc |= nibbles[1] << 8; // MCC digit 1
*mcc |= nibbles[0] << 4; // MCC digit 2
*mcc |= nibbles[3]; // MCC digit 3
if(nibbles[2] == 0xF) {
// 2-digit MNC
*mnc |= 0x0F00; // MNC digit 1
*mnc |= nibbles[5] << 4; // MNC digit 2
*mnc |= nibbles[4]; // MNC digit 3
} else {
// 3-digit MNC
*mnc |= nibbles[5] << 8; // MNC digit 1
*mnc |= nibbles[4] << 4; // MNC digit 2
*mnc |= nibbles[2] ; // MNC digit 3
}
}
/******************************************************************************
* Convert BCD-coded MCC and MNC to PLMN.
* Digits are represented by 4-bit nibbles. Unused nibbles are filled with 0xF.
* MNC 001 represented as 0xF001
* MNC 01 represented as 0xFF01
* PLMN encoded as per TS 36.413 sec 9.2.3.8
*****************************************************************************/
inline void s1ap_mccmnc_to_plmn(uint16_t mcc, uint16_t mnc, uint32_t *plmn)
{
uint8_t nibbles[6];
nibbles[1] = (mcc & 0x0F00) >> 8; // MCC digit 1
nibbles[0] = (mcc & 0x00F0) >> 4; // MCC digit 2
nibbles[3] = (mcc & 0x000F); // MCC digit 3
if((mnc & 0xFF00) == 0xFF00) {
// 2-digit MNC
nibbles[2] = 0x0F; // MNC digit 1
nibbles[5] = (mnc & 0x00F0) >> 4; // MNC digit 2
nibbles[4] = (mnc & 0x000F); // MNC digit 3
} else {
// 3-digit MNC
nibbles[5] = (mnc & 0x0F00) >> 8; // MNC digit 1
nibbles[4] = (mnc & 0x00F0) >> 4; // MNC digit 2
nibbles[2] = (mnc & 0x000F); // MNC digit 3
}
*plmn = 0x000000;
*plmn |= nibbles[0] << 20;
*plmn |= nibbles[1] << 16;
*plmn |= nibbles[2] << 12;
*plmn |= nibbles[3] << 8;
*plmn |= nibbles[4] << 4;
*plmn |= nibbles[5];
}
/******************************************************************************
* Safe conversions between byte buffers and integer types.
* Note: these don't perform endian conversion - use e.g. htonl/ntohl if required
*****************************************************************************/
inline void uint8_to_uint32(uint8_t *buf, uint32_t *i)
{
*i = (uint32_t)buf[0] << 24 |
(uint32_t)buf[1] << 16 |
(uint32_t)buf[2] << 8 |
(uint32_t)buf[3];
}
inline void uint32_to_uint8(uint32_t i, uint8_t *buf)
{
buf[0] = (i >> 24) & 0xFF;
buf[1] = (i >> 16) & 0xFF;
buf[2] = (i >> 8) & 0xFF;
buf[3] = i & 0xFF;
}
inline void uint8_to_uint16(uint8_t *buf, uint16_t *i)
{
*i = (uint32_t)buf[0] << 8 |
(uint32_t)buf[1];
}
inline void uint16_to_uint8(uint16_t i, uint8_t *buf)
{
buf[0] = (i >> 8) & 0xFF;
buf[1] = i & 0xFF;
}
} // namespace srsenb
#endif // SRSENB_COMMON_ENB_H

View File

@ -29,10 +29,12 @@
#include "srsenb/hdr/upper/rrc.h"
#include "srslte/srslte.h"
#include "srslte/asn1/liblte_mme.h"
#include "srslte/common/int_helpers.h"
using srslte::byte_buffer_t;
using srslte::bit_buffer_t;
using srslte::uint32_to_uint8;
using srslte::uint8_to_uint32;
namespace srsenb {

View File

@ -26,6 +26,8 @@
#include "srsenb/hdr/upper/s1ap.h"
#include "srsenb/hdr/upper/common_enb.h"
#include "srslte/common/bcd_helpers.h"
#include "srslte/common/int_helpers.h"
#include <stdio.h>
#include <string.h>
@ -36,6 +38,9 @@
#include <netinet/sctp.h>
#include <arpa/inet.h> //for inet_ntop()
using srslte::s1ap_mccmnc_to_plmn;
using srslte::uint32_to_uint8;
namespace srsenb{
bool s1ap::init(s1ap_args_t args_, rrc_interface_s1ap *rrc_, srslte::log *s1ap_log_)

View File

@ -10,6 +10,7 @@
#include <assert.h>
#include "srsenb/hdr/upper/common_enb.h"
#include "srslte/asn1/liblte_rrc.h"
#include "srslte/common/bcd_helpers.h"
void rrc_plmn_test()
{
@ -55,17 +56,17 @@ void s1ap_plmn_test()
uint32_t plmn;
// 2-digit MNC test
srsenb::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
srslte::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
assert(plmn == 0x21F354);
srsenb::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
srslte::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
assert(mcc == 0xF123);
assert(mnc == 0xFF45);
// 3-digit MNC test
mnc = 0xF456;
srsenb::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
srslte::s1ap_mccmnc_to_plmn(mcc, mnc, &plmn);
assert(plmn == 0x216354);
srsenb::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
srslte::s1ap_plmn_to_mccmnc(plmn, &mcc, &mnc);
assert(mcc == 0xF123);
assert(mnc == 0xF456);
}

View File

@ -24,11 +24,11 @@
*
*/
//#include "srslte/upper/s1ap_common.h"
#include "srslte/common/bcd_helpers.h"
#include "srsepc/hdr/mme/s1ap.h"
#include "srsepc/hdr/mme/s1ap_ctx_mngmt_proc.h"
#include "srslte/common/liblte_security.h"
#include "srslte/common/int_helpers.h"
namespace srsepc{
@ -122,18 +122,14 @@ s1ap_ctx_mngmt_proc::send_initial_context_setup_request(ue_emm_ctx_t *emm_ctx,
//Set E-RAB S-GW F-TEID
//if (cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid_present == false){
// m_s1ap_log->error("Did not receive S1-U TEID in create session response\n");
// return false;
//}
erab_ctx_req->transportLayerAddress.n_bits = 32; //IPv4
uint32_t sgw_s1u_ip = htonl(erab_ctx->sgw_s1u_fteid.ipv4);
//uint32_t sgw_s1u_ip = cs_resp->eps_bearer_context_created.s1_u_sgw_f_teid.ipv4;
uint8_t *tmp_ptr = erab_ctx_req->transportLayerAddress.buffer;
liblte_value_2_bits(sgw_s1u_ip, &tmp_ptr, 32);//FIXME consider ipv6
uint32_t sgw_s1u_teid = erab_ctx->sgw_s1u_fteid.teid;
memcpy(erab_ctx_req->gTP_TEID.buffer, &sgw_s1u_teid, sizeof(uint32_t));
uint32_t sgw_s1u_teid = erab_ctx->sgw_s1u_fteid.teid;
srslte::uint32_to_uint8(sgw_s1u_teid,erab_ctx_req->gTP_TEID.buffer);
//Set UE security capabilities and k_enb
bzero(in_ctxt_req->UESecurityCapabilities.encryptionAlgorithms.buffer,sizeof(uint8_t)*16);