2019-04-26 12:27:38 -07:00
|
|
|
/*
|
2020-03-13 04:12:52 -07:00
|
|
|
* Copyright 2013-2020 Software Radio Systems Limited
|
2017-05-18 03:52:29 -07:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* This file is part of srsLTE.
|
2017-05-18 03:52:29 -07:00
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* srsLTE is free software: you can redistribute it and/or modify
|
2017-05-18 03:52:29 -07:00
|
|
|
* 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.
|
|
|
|
*
|
2019-04-26 12:27:38 -07:00
|
|
|
* srsLTE is distributed in the hope that it will be useful,
|
2017-05-18 03:52:29 -07:00
|
|
|
* 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/.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-03-07 01:29:59 -08:00
|
|
|
#include "srslte/common/bcd_helpers.h"
|
2018-01-08 01:47:20 -08:00
|
|
|
#include "srslte/common/log_filter.h"
|
2020-01-27 10:15:38 -08:00
|
|
|
#include "srslte/common/logmap.h"
|
2017-06-01 03:25:42 -07:00
|
|
|
#include "srslte/interfaces/ue_interfaces.h"
|
2020-03-30 10:53:05 -07:00
|
|
|
#include "srslte/test/ue_test_interfaces.h"
|
2019-03-07 01:29:59 -08:00
|
|
|
#include "srslte/upper/pdcp.h"
|
2019-07-02 07:47:25 -07:00
|
|
|
#include "srslte/upper/pdcp_entity_lte.h"
|
2019-03-07 01:29:59 -08:00
|
|
|
#include "srslte/upper/rlc.h"
|
2019-05-07 01:11:57 -07:00
|
|
|
#include "srsue/hdr/stack/mac/mac.h"
|
|
|
|
#include "srsue/hdr/stack/rrc/rrc.h"
|
|
|
|
#include "srsue/hdr/stack/upper/gw.h"
|
|
|
|
#include "srsue/hdr/stack/upper/nas.h"
|
|
|
|
#include "srsue/hdr/stack/upper/usim.h"
|
|
|
|
#include "srsue/hdr/stack/upper/usim_base.h"
|
2019-03-07 01:29:59 -08:00
|
|
|
#include <assert.h>
|
|
|
|
#include <iostream>
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
using namespace srsue;
|
2019-01-17 03:42:01 -08:00
|
|
|
using namespace asn1::rrc;
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
#define LCID 1
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
#define TESTASSERT(cond) \
|
|
|
|
{ \
|
|
|
|
if (!(cond)) { \
|
|
|
|
std::cout << "[" << __FUNCTION__ << "][Line " << __LINE__ << "]: FAIL at " << (#cond) << std::endl; \
|
|
|
|
return -1; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
2019-08-08 07:46:21 -07:00
|
|
|
uint8_t auth_request_pdu[] = {0x07, 0x52, 0x01, 0x0c, 0x63, 0xa8, 0x54, 0x13, 0xe6, 0xa4, 0xce, 0xd9,
|
|
|
|
0x86, 0xfb, 0xe5, 0xce, 0x9b, 0x62, 0x5e, 0x10, 0x67, 0x57, 0xb3, 0xc2,
|
|
|
|
0xb9, 0x70, 0x90, 0x01, 0x0c, 0x72, 0x8a, 0x67, 0x57, 0x92, 0x52, 0xb8};
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-08-08 07:46:21 -07:00
|
|
|
uint8_t sec_mode_command_pdu[] = {0x37, 0x4e, 0xfd, 0x57, 0x11, 0x00, 0x07, 0x5d, 0x02, 0x01, 0x02, 0xf0, 0x70, 0xc1};
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-08-08 07:46:21 -07:00
|
|
|
uint8_t attach_accept_pdu[] = {0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x42, 0x01, 0x3e, 0x06, 0x00, 0x00,
|
|
|
|
0xf1, 0x10, 0x00, 0x01, 0x00, 0x2a, 0x52, 0x01, 0xc1, 0x01, 0x04, 0x1b, 0x07,
|
|
|
|
0x74, 0x65, 0x73, 0x74, 0x31, 0x32, 0x33, 0x06, 0x6d, 0x6e, 0x63, 0x30, 0x30,
|
|
|
|
0x31, 0x06, 0x6d, 0x63, 0x63, 0x30, 0x30, 0x31, 0x04, 0x67, 0x70, 0x72, 0x73,
|
|
|
|
0x05, 0x01, 0xc0, 0xa8, 0x05, 0x02, 0x27, 0x01, 0x80, 0x50, 0x0b, 0xf6, 0x00,
|
|
|
|
0xf1, 0x10, 0x80, 0x01, 0x01, 0x35, 0x16, 0x6d, 0xbc, 0x64, 0x01, 0x00};
|
2018-04-26 04:21:13 -07:00
|
|
|
|
2019-08-08 07:46:21 -07:00
|
|
|
uint8_t esm_info_req_pdu[] = {0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x5a, 0xd9};
|
2018-04-17 06:24:47 -07:00
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
uint8_t activate_dedicated_eps_bearer_pdu[] = {0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0xc5, 0x05,
|
|
|
|
0x01, 0x01, 0x07, 0x21, 0x31, 0x00, 0x03, 0x40, 0x08, 0xae,
|
|
|
|
0x5d, 0x02, 0x00, 0xc2, 0x81, 0x34, 0x01, 0x4d};
|
|
|
|
|
|
|
|
uint8_t deactivate_eps_bearer_pdu[] = {0x27, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0xcd, 0x24};
|
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
uint16 mcc = 61441;
|
|
|
|
uint16 mnc = 65281;
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
using namespace srslte;
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
namespace srslte {
|
2017-05-18 03:52:29 -07:00
|
|
|
|
|
|
|
// fake classes
|
2018-11-15 01:48:47 -08:00
|
|
|
class pdcp_dummy : public rrc_interface_pdcp, public pdcp_interface_gw
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
|
|
|
public:
|
2019-05-13 07:34:15 -07:00
|
|
|
void write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) {}
|
|
|
|
void write_pdu_bcch_bch(unique_byte_buffer_t pdu) {}
|
|
|
|
void write_pdu_bcch_dlsch(unique_byte_buffer_t pdu) {}
|
|
|
|
void write_pdu_pcch(unique_byte_buffer_t pdu) {}
|
|
|
|
void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {}
|
2018-11-15 01:48:47 -08:00
|
|
|
std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); }
|
2019-05-13 07:34:15 -07:00
|
|
|
void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking) {}
|
2019-07-02 07:47:25 -07:00
|
|
|
bool is_lcid_enabled(uint32_t lcid) { return false; }
|
2017-05-18 03:52:29 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class rrc_dummy : public rrc_interface_nas
|
|
|
|
{
|
|
|
|
public:
|
2019-12-16 07:04:22 -08:00
|
|
|
rrc_dummy() : last_sdu_len(0)
|
|
|
|
{
|
2019-07-03 08:20:32 -07:00
|
|
|
plmns.plmn_id.from_number(mcc, mnc);
|
2018-04-26 04:21:13 -07:00
|
|
|
plmns.tac = 0xffff;
|
|
|
|
}
|
2019-06-20 08:33:03 -07:00
|
|
|
void init(nas* nas_) { nas_ptr = nas_; }
|
2019-05-13 07:34:15 -07:00
|
|
|
void write_sdu(unique_byte_buffer_t sdu)
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2018-01-08 01:47:20 -08:00
|
|
|
last_sdu_len = sdu->N_bytes;
|
2019-12-16 07:04:22 -08:00
|
|
|
// printf("NAS generated SDU (len=%d):\n", sdu->N_bytes);
|
|
|
|
// srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes);
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|
2018-01-08 01:47:20 -08:00
|
|
|
std::string get_rb_name(uint32_t lcid) { return std::string("lcid"); }
|
2019-12-16 07:04:22 -08:00
|
|
|
uint32_t get_last_sdu_len() { return last_sdu_len; }
|
|
|
|
void reset() { last_sdu_len = 0; }
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-06-20 08:33:03 -07:00
|
|
|
bool plmn_search()
|
|
|
|
{
|
|
|
|
nas_ptr->plmn_search_completed(&plmns, 1);
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-03 08:20:32 -07:00
|
|
|
void plmn_select(srslte::plmn_id_t plmn_id){};
|
|
|
|
void set_ue_identity(srslte::s_tmsi_t s_tmsi) {}
|
|
|
|
bool connection_request(srslte::establishment_cause_t cause, srslte::unique_byte_buffer_t sdu)
|
2019-01-17 03:42:01 -08:00
|
|
|
{
|
2018-04-26 04:21:13 -07:00
|
|
|
printf("NAS generated SDU (len=%d):\n", sdu->N_bytes);
|
|
|
|
last_sdu_len = sdu->N_bytes;
|
|
|
|
srslte_vec_fprint_byte(stdout, sdu->msg, sdu->N_bytes);
|
2019-10-02 03:06:39 -07:00
|
|
|
is_connected_flag = true;
|
2019-06-20 08:33:03 -07:00
|
|
|
nas_ptr->connection_request_completed(true);
|
2018-04-26 04:21:13 -07:00
|
|
|
return true;
|
|
|
|
}
|
2019-10-02 03:06:39 -07:00
|
|
|
bool is_connected() { return is_connected_flag; }
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
uint16_t get_mcc() { return mcc; }
|
|
|
|
uint16_t get_mnc() { return mnc; }
|
2019-12-16 07:04:22 -08:00
|
|
|
void enable_capabilities() {}
|
2019-06-05 05:56:30 -07:00
|
|
|
uint32_t get_lcid_for_eps_bearer(const uint32_t& eps_bearer_id) { return 0; }
|
2019-06-20 08:33:03 -07:00
|
|
|
void paging_completed(bool outcome) {}
|
2018-01-08 01:47:20 -08:00
|
|
|
|
|
|
|
private:
|
2019-06-20 08:33:03 -07:00
|
|
|
nas* nas_ptr;
|
2019-10-02 03:06:39 -07:00
|
|
|
uint32_t last_sdu_len;
|
2018-04-26 04:21:13 -07:00
|
|
|
found_plmn_t plmns;
|
2019-10-02 03:06:39 -07:00
|
|
|
bool is_connected_flag = false;
|
2017-05-18 03:52:29 -07:00
|
|
|
};
|
|
|
|
|
2020-03-30 10:53:05 -07:00
|
|
|
class test_stack_dummy : public srsue::stack_test_dummy, public stack_interface_gw, public thread
|
2019-06-19 11:12:33 -07:00
|
|
|
{
|
|
|
|
public:
|
2020-03-19 10:24:16 -07:00
|
|
|
test_stack_dummy(pdcp_interface_gw* pdcp_) : pdcp(pdcp_), thread("DUMMY STACK") {}
|
|
|
|
void init(srsue::nas* nas_)
|
|
|
|
{
|
|
|
|
nas = nas_;
|
|
|
|
start(-1);
|
|
|
|
}
|
2019-06-20 08:33:03 -07:00
|
|
|
bool switch_on() final
|
|
|
|
{
|
2019-10-18 10:26:33 -07:00
|
|
|
proc_state_t proc_result;
|
2020-03-29 03:21:15 -07:00
|
|
|
nas->start_attach_proc(&proc_result, srslte::establishment_cause_t::mo_data);
|
2019-10-02 03:06:39 -07:00
|
|
|
while (not proc_result.is_complete()) {
|
2019-06-20 08:33:03 -07:00
|
|
|
usleep(1000);
|
|
|
|
}
|
2019-10-02 03:06:39 -07:00
|
|
|
return proc_result.is_success();
|
2019-06-20 08:33:03 -07:00
|
|
|
}
|
2019-06-19 11:12:33 -07:00
|
|
|
void write_sdu(uint32_t lcid, srslte::unique_byte_buffer_t sdu, bool blocking)
|
|
|
|
{
|
|
|
|
pdcp->write_sdu(lcid, std::move(sdu), blocking);
|
|
|
|
}
|
|
|
|
bool is_lcid_enabled(uint32_t lcid) { return pdcp->is_lcid_enabled(lcid); }
|
2019-06-20 08:33:03 -07:00
|
|
|
void run_thread()
|
|
|
|
{
|
2020-03-18 08:43:28 -07:00
|
|
|
running = true;
|
2019-06-20 08:33:03 -07:00
|
|
|
while (running) {
|
2020-07-08 10:39:23 -07:00
|
|
|
task_sched.tic();
|
2020-07-09 08:03:22 -07:00
|
|
|
task_sched.run_pending_tasks();
|
2020-03-18 08:43:28 -07:00
|
|
|
nas->run_tti();
|
2019-06-20 08:33:03 -07:00
|
|
|
}
|
|
|
|
}
|
2019-06-20 05:29:15 -07:00
|
|
|
void stop()
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
wait_thread_finish();
|
|
|
|
}
|
2019-06-19 11:12:33 -07:00
|
|
|
pdcp_interface_gw* pdcp = nullptr;
|
|
|
|
srsue::nas* nas = nullptr;
|
|
|
|
bool running = false;
|
|
|
|
};
|
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
class gw_dummy : public gw_interface_nas, public gw_interface_pdcp
|
|
|
|
{
|
2019-06-05 10:12:01 -07:00
|
|
|
int setup_if_addr(uint32_t lcid, uint8_t pdn_type, uint32_t ip_addr, uint8_t* ipv6_if_id, char* err_str)
|
2019-06-05 05:56:30 -07:00
|
|
|
{
|
2019-06-05 10:12:01 -07:00
|
|
|
return SRSLTE_SUCCESS;
|
2019-06-05 05:56:30 -07:00
|
|
|
}
|
2019-06-06 06:07:31 -07:00
|
|
|
int apply_traffic_flow_template(const uint8_t& eps_bearer_id,
|
|
|
|
const uint8_t& lcid,
|
|
|
|
const LIBLTE_MME_TRAFFIC_FLOW_TEMPLATE_STRUCT* tft)
|
2019-06-04 09:23:36 -07:00
|
|
|
{
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
}
|
2019-12-16 07:04:22 -08:00
|
|
|
void write_pdu(uint32_t lcid, unique_byte_buffer_t pdu) {}
|
|
|
|
void write_pdu_mch(uint32_t lcid, srslte::unique_byte_buffer_t sdu) {}
|
2020-04-08 05:43:24 -07:00
|
|
|
void set_test_loop_mode(const test_loop_mode_state_t mode, const uint32_t ip_pdu_delay_ms = 0) {}
|
2017-05-18 03:52:29 -07:00
|
|
|
};
|
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
} // namespace srslte
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
int security_command_test()
|
2017-05-18 03:52:29 -07:00
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
int ret = SRSLTE_ERROR;
|
2018-01-08 01:47:20 -08:00
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
srslte::log_filter usim_log("USIM");
|
2017-05-18 03:52:29 -07:00
|
|
|
|
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
rrc_log.set_hex_limit(100000);
|
|
|
|
|
2020-03-30 10:53:05 -07:00
|
|
|
stack_test_dummy stack;
|
2019-10-16 01:35:24 -07:00
|
|
|
|
2017-05-18 03:52:29 -07:00
|
|
|
rrc_dummy rrc_dummy;
|
2019-10-21 10:00:49 -07:00
|
|
|
gw_dummy gw;
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
usim_args_t args;
|
2019-10-21 10:00:49 -07:00
|
|
|
args.algo = "xor";
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
args.imsi = "001010123456789";
|
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
2019-01-15 07:34:41 -08:00
|
|
|
args.using_op = true;
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
// init USIM
|
2019-06-27 01:50:47 -07:00
|
|
|
srsue::usim usim(&usim_log);
|
|
|
|
usim.init(&args);
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-05-01 09:41:04 -07:00
|
|
|
{
|
2020-07-08 14:06:15 -07:00
|
|
|
srsue::nas nas(&stack.task_sched);
|
2019-05-01 09:41:04 -07:00
|
|
|
nas_args_t cfg;
|
2019-07-28 05:10:30 -07:00
|
|
|
cfg.eia = "1,2,3";
|
|
|
|
cfg.eea = "0,1,2,3";
|
2019-06-27 01:50:47 -07:00
|
|
|
nas.init(&usim, &rrc_dummy, &gw, cfg);
|
2019-06-20 08:33:03 -07:00
|
|
|
rrc_dummy.init(&nas);
|
2019-05-01 09:41:04 -07:00
|
|
|
|
|
|
|
// push auth request PDU to NAS to generate security context
|
2019-12-16 07:04:22 -08:00
|
|
|
byte_buffer_pool* pool = byte_buffer_pool::get_instance();
|
2019-05-13 07:34:15 -07:00
|
|
|
unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true);
|
2019-05-01 09:41:04 -07:00
|
|
|
memcpy(tmp->msg, auth_request_pdu, sizeof(auth_request_pdu));
|
|
|
|
tmp->N_bytes = sizeof(auth_request_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
|
|
|
|
// TODO: add check for authentication response
|
|
|
|
rrc_dummy.reset();
|
|
|
|
|
|
|
|
// reuse buffer for security mode command
|
|
|
|
tmp = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(tmp->msg, sec_mode_command_pdu, sizeof(sec_mode_command_pdu));
|
|
|
|
tmp->N_bytes = sizeof(sec_mode_command_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
|
|
|
|
// check length of generated NAS SDU
|
|
|
|
if (rrc_dummy.get_last_sdu_len() > 3) {
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
}
|
2018-01-08 01:47:20 -08:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-04-26 04:21:13 -07:00
|
|
|
byte_buffer_pool::get_instance()->cleanup();
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
return ret;
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
int mme_attach_request_test()
|
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
int ret = SRSLTE_ERROR;
|
2018-01-08 01:47:20 -08:00
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
srslte::log_filter usim_log("USIM");
|
2018-11-15 01:48:47 -08:00
|
|
|
srslte::log_filter gw_log("GW");
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
2018-04-04 02:53:36 -07:00
|
|
|
usim_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
2018-11-15 01:48:47 -08:00
|
|
|
gw_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
2018-01-08 01:47:20 -08:00
|
|
|
rrc_log.set_hex_limit(100000);
|
2018-04-04 02:53:36 -07:00
|
|
|
usim_log.set_hex_limit(100000);
|
2018-11-15 01:48:47 -08:00
|
|
|
gw_log.set_hex_limit(100000);
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2019-10-21 10:00:49 -07:00
|
|
|
rrc_dummy rrc_dummy;
|
2018-11-15 01:48:47 -08:00
|
|
|
pdcp_dummy pdcp_dummy;
|
|
|
|
|
2019-06-27 01:50:47 -07:00
|
|
|
srsue::usim usim(&usim_log);
|
2018-01-08 01:47:20 -08:00
|
|
|
usim_args_t args;
|
2018-04-17 06:24:47 -07:00
|
|
|
args.mode = "soft";
|
2018-01-08 01:47:20 -08:00
|
|
|
args.algo = "xor";
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
args.imsi = "001010123456789";
|
2019-10-16 11:00:29 -07:00
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
2019-06-27 01:50:47 -07:00
|
|
|
usim.init(&args);
|
2018-01-08 01:47:20 -08:00
|
|
|
|
2019-05-01 09:41:04 -07:00
|
|
|
{
|
|
|
|
nas_args_t nas_cfg;
|
|
|
|
nas_cfg.force_imsi_attach = true;
|
|
|
|
nas_cfg.apn_name = "test123";
|
2020-03-19 10:24:16 -07:00
|
|
|
test_stack_dummy stack(&pdcp_dummy);
|
2020-07-08 14:06:15 -07:00
|
|
|
srsue::nas nas(&stack.task_sched);
|
2020-03-19 10:24:16 -07:00
|
|
|
srsue::gw gw;
|
2019-05-01 09:41:04 -07:00
|
|
|
|
2019-06-27 01:50:47 -07:00
|
|
|
nas.init(&usim, &rrc_dummy, &gw, nas_cfg);
|
2019-06-20 08:33:03 -07:00
|
|
|
rrc_dummy.init(&nas);
|
2019-05-01 09:41:04 -07:00
|
|
|
|
2019-05-07 01:11:57 -07:00
|
|
|
gw_args_t gw_args;
|
2019-06-20 05:41:45 -07:00
|
|
|
gw_args.tun_dev_name = "tun0";
|
2019-06-19 11:12:33 -07:00
|
|
|
gw_args.log.gw_level = "debug";
|
|
|
|
gw_args.log.gw_hex_limit = 100000;
|
|
|
|
srslte::logger_stdout def_logstdout;
|
|
|
|
srslte::logger* logger = &def_logstdout;
|
|
|
|
gw.init(gw_args, logger, &stack);
|
2020-03-19 10:24:16 -07:00
|
|
|
stack.init(&nas);
|
2019-05-01 09:41:04 -07:00
|
|
|
|
2020-07-09 03:38:28 -07:00
|
|
|
usleep(5000); // Wait for stack to initialize before stoping it.
|
|
|
|
|
2019-05-01 09:41:04 -07:00
|
|
|
// trigger test
|
2019-06-19 11:12:33 -07:00
|
|
|
stack.switch_on();
|
2019-06-20 05:29:15 -07:00
|
|
|
stack.stop();
|
2019-05-01 09:41:04 -07:00
|
|
|
|
|
|
|
// this will time out in the first place
|
|
|
|
|
|
|
|
// reset length of last received NAS PDU
|
|
|
|
rrc_dummy.reset();
|
|
|
|
|
|
|
|
// finally push attach accept
|
2019-12-16 07:04:22 -08:00
|
|
|
byte_buffer_pool* pool = byte_buffer_pool::get_instance();
|
2019-05-13 07:34:15 -07:00
|
|
|
unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true);
|
2019-05-01 09:41:04 -07:00
|
|
|
memcpy(tmp->msg, attach_accept_pdu, sizeof(attach_accept_pdu));
|
|
|
|
tmp->N_bytes = sizeof(attach_accept_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
nas_metrics_t metrics;
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 1);
|
|
|
|
|
2019-05-01 09:41:04 -07:00
|
|
|
// check length of generated NAS SDU (attach complete)
|
|
|
|
if (rrc_dummy.get_last_sdu_len() > 3) {
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
}
|
|
|
|
// ensure buffers are deleted before pool cleanup
|
2018-01-08 01:47:20 -08:00
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-04-26 04:21:13 -07:00
|
|
|
byte_buffer_pool::get_instance()->cleanup();
|
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
return ret;
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-04-17 06:24:47 -07:00
|
|
|
int esm_info_request_test()
|
|
|
|
{
|
2019-12-16 07:04:22 -08:00
|
|
|
int ret = SRSLTE_ERROR;
|
2018-04-17 06:24:47 -07:00
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
srslte::log_filter usim_log("USIM");
|
|
|
|
|
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
rrc_log.set_hex_limit(100000);
|
|
|
|
|
2020-03-30 10:53:05 -07:00
|
|
|
srsue::stack_test_dummy stack{};
|
2019-10-16 01:35:24 -07:00
|
|
|
|
2018-04-17 06:24:47 -07:00
|
|
|
rrc_dummy rrc_dummy;
|
2019-10-21 10:00:49 -07:00
|
|
|
gw_dummy gw;
|
2018-04-17 06:24:47 -07:00
|
|
|
|
|
|
|
usim_args_t args;
|
|
|
|
args.algo = "xor";
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
args.imsi = "001010123456789";
|
2019-12-16 07:04:22 -08:00
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
2018-04-17 06:24:47 -07:00
|
|
|
|
|
|
|
// init USIM
|
2019-06-27 01:50:47 -07:00
|
|
|
srsue::usim usim(&usim_log);
|
|
|
|
usim.init(&args);
|
2018-04-17 06:24:47 -07:00
|
|
|
|
2019-10-16 11:00:29 -07:00
|
|
|
srslte::byte_buffer_pool* pool;
|
2018-04-17 06:24:47 -07:00
|
|
|
pool = byte_buffer_pool::get_instance();
|
|
|
|
|
2019-05-01 09:41:04 -07:00
|
|
|
{
|
2020-07-08 14:06:15 -07:00
|
|
|
srsue::nas nas(&stack.task_sched);
|
2019-05-01 09:41:04 -07:00
|
|
|
nas_args_t cfg;
|
|
|
|
cfg.apn_name = "srslte";
|
|
|
|
cfg.apn_user = "srsuser";
|
|
|
|
cfg.apn_pass = "srspass";
|
|
|
|
cfg.force_imsi_attach = true;
|
2019-06-27 01:50:47 -07:00
|
|
|
nas.init(&usim, &rrc_dummy, &gw, cfg);
|
2019-05-01 09:41:04 -07:00
|
|
|
|
|
|
|
// push ESM info request PDU to NAS to generate response
|
2019-05-13 07:34:15 -07:00
|
|
|
unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true);
|
2019-05-01 09:41:04 -07:00
|
|
|
memcpy(tmp->msg, esm_info_req_pdu, sizeof(esm_info_req_pdu));
|
|
|
|
tmp->N_bytes = sizeof(esm_info_req_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
|
|
|
|
// check length of generated NAS SDU
|
|
|
|
if (rrc_dummy.get_last_sdu_len() > 3) {
|
|
|
|
ret = SRSLTE_SUCCESS;
|
|
|
|
}
|
2018-04-17 06:24:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pool->cleanup();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
int dedicated_eps_bearer_test()
|
|
|
|
{
|
|
|
|
srslte::log_filter rrc_log("RRC");
|
|
|
|
srslte::log_filter mac_log("MAC");
|
|
|
|
srslte::log_filter usim_log("USIM");
|
|
|
|
|
|
|
|
rrc_log.set_level(srslte::LOG_LEVEL_DEBUG);
|
|
|
|
rrc_log.set_hex_limit(100000);
|
|
|
|
|
2020-03-30 10:53:05 -07:00
|
|
|
srsue::stack_test_dummy stack;
|
2019-10-16 01:35:24 -07:00
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
rrc_dummy rrc_dummy;
|
|
|
|
gw_dummy gw;
|
|
|
|
|
|
|
|
usim_args_t args;
|
|
|
|
args.algo = "xor";
|
|
|
|
args.imei = "353490069873319";
|
|
|
|
args.imsi = "001010123456789";
|
|
|
|
args.k = "00112233445566778899aabbccddeeff";
|
|
|
|
args.op = "63BFA50EE6523365FF14C1F45F88737D";
|
|
|
|
|
|
|
|
// init USIM
|
2019-06-27 01:50:47 -07:00
|
|
|
srsue::usim usim(&usim_log);
|
|
|
|
usim.init(&args);
|
2019-05-24 05:40:10 -07:00
|
|
|
|
|
|
|
srslte::byte_buffer_pool* pool = byte_buffer_pool::get_instance();
|
|
|
|
|
2020-07-08 14:06:15 -07:00
|
|
|
srsue::nas nas(&stack.task_sched);
|
2019-05-24 05:40:10 -07:00
|
|
|
nas_args_t cfg = {};
|
|
|
|
cfg.force_imsi_attach = true; // make sure we get a fresh security context
|
2019-06-27 01:50:47 -07:00
|
|
|
nas.init(&usim, &rrc_dummy, &gw, cfg);
|
2019-05-24 05:40:10 -07:00
|
|
|
|
|
|
|
// push dedicated EPS bearer PDU to NAS
|
|
|
|
unique_byte_buffer_t tmp = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu));
|
|
|
|
tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
|
|
|
|
// This should fail since no default bearer has been created yet
|
|
|
|
nas_metrics_t metrics;
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 0);
|
|
|
|
|
|
|
|
// add default EPS beaerer
|
|
|
|
unique_byte_buffer_t attach_with_default_bearer = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(attach_with_default_bearer->msg, attach_accept_pdu, sizeof(attach_accept_pdu));
|
|
|
|
attach_with_default_bearer->N_bytes = sizeof(attach_accept_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(attach_with_default_bearer));
|
|
|
|
|
|
|
|
// This should fail since no default bearer has been created yet
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 1);
|
|
|
|
|
|
|
|
// push dedicated bearer activation and check that it was added
|
|
|
|
tmp = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(tmp->msg, activate_dedicated_eps_bearer_pdu, sizeof(activate_dedicated_eps_bearer_pdu));
|
|
|
|
tmp->N_bytes = sizeof(activate_dedicated_eps_bearer_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 2);
|
|
|
|
|
|
|
|
// tear-down dedicated bearer
|
|
|
|
tmp = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu));
|
|
|
|
tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 1);
|
|
|
|
|
|
|
|
// try to tear-down dedicated bearer again
|
|
|
|
tmp = srslte::allocate_unique_buffer(*pool, true);
|
|
|
|
memcpy(tmp->msg, deactivate_eps_bearer_pdu, sizeof(deactivate_eps_bearer_pdu));
|
|
|
|
tmp->N_bytes = sizeof(deactivate_eps_bearer_pdu);
|
|
|
|
nas.write_pdu(LCID, std::move(tmp));
|
|
|
|
nas.get_metrics(&metrics);
|
|
|
|
TESTASSERT(metrics.nof_active_eps_bearer == 1);
|
|
|
|
|
|
|
|
pool->cleanup();
|
|
|
|
|
|
|
|
return SRSLTE_SUCCESS;
|
|
|
|
}
|
2018-04-17 06:24:47 -07:00
|
|
|
|
2019-12-16 07:04:22 -08:00
|
|
|
int main(int argc, char** argv)
|
2018-01-08 01:47:20 -08:00
|
|
|
{
|
2020-02-27 04:41:38 -08:00
|
|
|
srslte::logmap::set_default_log_level(LOG_LEVEL_DEBUG);
|
|
|
|
srslte::logmap::set_default_hex_limit(100000);
|
2020-01-27 10:15:38 -08:00
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
if (security_command_test()) {
|
|
|
|
printf("Security command test failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mme_attach_request_test()) {
|
|
|
|
printf("Attach request test failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2017-05-18 03:52:29 -07:00
|
|
|
|
2018-04-17 06:24:47 -07:00
|
|
|
if (esm_info_request_test()) {
|
|
|
|
printf("ESM info request test failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2019-05-24 05:40:10 -07:00
|
|
|
if (dedicated_eps_bearer_test()) {
|
|
|
|
printf("Dedicated EPS bearer test failed.\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-08 01:47:20 -08:00
|
|
|
return 0;
|
2017-05-18 03:52:29 -07:00
|
|
|
}
|