2013-07-28 16:34:49 +00:00
|
|
|
/* Code for a software PCU to test a SGSN.. */
|
|
|
|
|
|
|
|
/* (C) 2013 by Holger Hans Peter Freyther
|
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* 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 Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
#include <osmocom/core/talloc.h>
|
|
|
|
#include <pcu_vty.h>
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:59:29 +00:00
|
|
|
#include "gprs_tests.h"
|
|
|
|
|
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
#include <gprs_bssgp_pcu.h>
|
|
|
|
#include <gprs_rlcmac.h>
|
2013-10-17 15:01:54 +00:00
|
|
|
#include <bts.h>
|
2013-07-28 16:34:49 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2015-05-04 07:34:00 +00:00
|
|
|
static size_t current_test;
|
2013-07-31 19:59:29 +00:00
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
/* Extern data to please the underlying code */
|
|
|
|
void *tall_pcu_ctx;
|
|
|
|
int16_t spoof_mnc = 0, spoof_mcc = 0;
|
2018-02-20 23:39:07 +00:00
|
|
|
bool spoof_mnc_3_digits = false;
|
2013-07-28 16:34:49 +00:00
|
|
|
|
2013-07-28 19:14:51 +00:00
|
|
|
extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu);
|
2013-08-22 06:44:38 +00:00
|
|
|
extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed *);
|
2013-07-28 19:14:51 +00:00
|
|
|
|
2013-07-31 19:59:29 +00:00
|
|
|
extern void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu);
|
|
|
|
extern void test_pdp_activation_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed*);
|
|
|
|
|
|
|
|
struct gprs_test all_tests[] = {
|
|
|
|
gprs_test("gprs_attach_with_tmsi",
|
|
|
|
"A simple test that verifies that N(U) is "
|
|
|
|
"increasing across various messages. This makes "
|
|
|
|
"sure that no new LLE/LLME is created on the fly.",
|
|
|
|
test_replay_gprs_attach,
|
|
|
|
test_replay_gprs_data),
|
|
|
|
gprs_test("gprs_full_attach_pdp_activation",
|
|
|
|
"A simple test to do a GPRS attach and open a PDP "
|
|
|
|
"context. Then goes to sleep and waits for you to ping "
|
|
|
|
"the connection and hopefully re-produce a crash.",
|
|
|
|
test_pdp_activation_start,
|
|
|
|
test_pdp_activation_data),
|
|
|
|
};
|
|
|
|
|
2013-10-17 17:41:11 +00:00
|
|
|
static void init_main_bts()
|
2013-07-28 16:34:49 +00:00
|
|
|
{
|
2013-10-17 17:41:11 +00:00
|
|
|
struct gprs_rlcmac_bts *bts = bts_main_data();
|
2013-07-28 16:34:49 +00:00
|
|
|
bts->fc_interval = 100;
|
|
|
|
bts->initial_cs_dl = bts->initial_cs_ul = 1;
|
2020-10-30 16:14:26 +00:00
|
|
|
bts->cs_mask = 1 << 0; /* CS-1 always enabled by default */
|
2013-07-28 16:34:49 +00:00
|
|
|
bts->n3101 = 10;
|
|
|
|
bts->n3103 = 4;
|
|
|
|
bts->n3105 = 8;
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
}
|
2013-07-28 16:34:49 +00:00
|
|
|
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
static void init_pcu(struct gprs_pcu *pcu)
|
|
|
|
{
|
|
|
|
if (!pcu->alloc_algorithm)
|
|
|
|
pcu->alloc_algorithm = alloc_algorithm_b;
|
2021-01-14 11:53:53 +00:00
|
|
|
pcu->vty.alpha = 0; /* a = 0.0 */
|
2013-07-28 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 19:14:51 +00:00
|
|
|
static void bvci_unblocked(struct gprs_bssgp_pcu *pcu)
|
2013-07-28 16:34:49 +00:00
|
|
|
{
|
|
|
|
printf("BVCI unblocked. We can begin with test cases.\n");
|
2013-07-31 19:59:29 +00:00
|
|
|
all_tests[current_test].start(pcu);
|
2013-07-28 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
2013-08-22 06:44:38 +00:00
|
|
|
static void bssgp_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
|
|
|
|
{
|
2013-07-31 19:59:29 +00:00
|
|
|
all_tests[current_test].data(pcu, msg, tp);
|
2013-08-22 06:44:38 +00:00
|
|
|
}
|
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts,
|
|
|
|
uint32_t sgsn_ip, uint16_t sgsn_port)
|
|
|
|
{
|
|
|
|
struct gprs_bssgp_pcu *pcu;
|
2020-09-16 19:52:02 +00:00
|
|
|
struct osmo_sockaddr local, remote;
|
2020-10-12 00:27:22 +00:00
|
|
|
uint16_t nsvci = 20;
|
|
|
|
uint16_t nsei = 20;
|
2020-09-16 19:52:02 +00:00
|
|
|
|
|
|
|
local.u.sin.sin_family = AF_INET;
|
|
|
|
local.u.sin.sin_addr.s_addr = 0;
|
|
|
|
local.u.sin.sin_port = 0;
|
|
|
|
|
|
|
|
remote.u.sin.sin_family = AF_INET;
|
|
|
|
remote.u.sin.sin_addr.s_addr = htonl(sgsn_ip);
|
|
|
|
remote.u.sin.sin_port = htons(sgsn_port);
|
|
|
|
|
|
|
|
pcu = gprs_bssgp_init(bts, 20, 20, 901, 99, false, 1, 0, 0);
|
2020-10-12 00:27:22 +00:00
|
|
|
gprs_ns_config(bts, nsei, &local, &remote, &nsvci, 1);
|
2013-07-28 16:34:49 +00:00
|
|
|
|
|
|
|
pcu->on_unblock_ack = bvci_unblocked;
|
2013-08-22 06:44:38 +00:00
|
|
|
pcu->on_dl_unit_data = bssgp_data;
|
2013-07-28 16:34:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
struct gprs_pcu *pcu = gprs_pcu_alloc(tall_pcu_ctx);
|
|
|
|
the_pcu = pcu; /* globally avaialable object */
|
|
|
|
pcu->bts = bts_alloc(pcu);
|
2020-09-16 19:52:02 +00:00
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
|
|
|
|
if (!tall_pcu_ctx)
|
|
|
|
abort();
|
|
|
|
|
2017-02-08 16:07:31 +00:00
|
|
|
msgb_talloc_ctx_init(tall_pcu_ctx, 0);
|
2018-04-01 14:54:40 +00:00
|
|
|
osmo_init_logging2(tall_pcu_ctx, &gprs_log_info);
|
2019-05-25 03:41:18 +00:00
|
|
|
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
pcu->nsi = gprs_ns2_instantiate(tall_pcu_ctx, &gprs_ns_prim_cb, NULL);
|
|
|
|
if (!pcu->nsi) {
|
2019-05-25 03:41:18 +00:00
|
|
|
LOGP(DBSSGP, LOGL_ERROR, "Failed to create NS instance\n");
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
vty_init(&pcu_vty_info);
|
2019-08-05 12:30:44 +00:00
|
|
|
pcu_vty_init();
|
2013-07-28 16:34:49 +00:00
|
|
|
|
2015-05-04 07:34:00 +00:00
|
|
|
current_test = 0;
|
|
|
|
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
init_pcu(pcu);
|
2013-10-17 17:41:11 +00:00
|
|
|
init_main_bts();
|
Split PCU global PCU object from BTS object
Currently the BTS object (and gprs_rlcmac_bts struct) are used to hold
both PCU global fields and BTS specific fields, all mangled together.
The BTS is even accessed in lots of places by means of a singleton.
This patch introduces a new struct gprs_pcu object aimed at holding all
global state, and several fields are already moved from BTS to it. The
new object can be accessed as global variable "the_pcu", reusing and
including an already exisitng "the_pcu" global variable only used for
bssgp related purposes so far.
This is only a first step towards having a complete split global pcu and
BTS, some fields are still kept in BTS and will be moved over follow-up
smaller patches in the future (since this patch is already quite big).
So far, the code still only supports one BTS, which can be accessed
using the_pcu->bts. In the future that field will be replaced with a
list, and the BTS singletons will be removed.
The cur_fn output changes in TbfTest are actually a side effect fix,
since the singleton main_bts() now points internally to the_pcu->bts,
hence the same we allocate and assign in the test. Beforehand, "the_bts"
was allocated in the stack while main_bts() still returned an unrelated
singleton BTS object instance.
Related: OS#4935
Change-Id: I88e3c6471b80245ce3798223f1a61190f14aa840
2021-01-13 17:54:38 +00:00
|
|
|
bssgp_set_bssgp_callback(gprs_gp_send_cb, pcu->nsi);
|
|
|
|
create_and_connect_bssgp(bts_data(pcu->bts), INADDR_LOOPBACK, 23000);
|
2020-10-30 16:10:32 +00:00
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
for (;;)
|
|
|
|
osmo_select_main(0);
|
|
|
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2013-07-31 19:59:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test handling..
|
|
|
|
*/
|
|
|
|
void gprs_test_success(struct gprs_bssgp_pcu *pcu)
|
|
|
|
{
|
|
|
|
current_test += 1;
|
|
|
|
if (current_test >= ARRAY_SIZE(all_tests)) {
|
|
|
|
printf("All tests executed.\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
all_tests[current_test].start(pcu);
|
|
|
|
}
|
|
|
|
|
2013-07-28 16:34:49 +00:00
|
|
|
/*
|
|
|
|
* stubs that should not be reached
|
|
|
|
*/
|
|
|
|
extern "C" {
|
|
|
|
void l1if_pdch_req() { abort(); }
|
|
|
|
void l1if_connect_pdch() { abort(); }
|
|
|
|
void l1if_close_pdch() { abort(); }
|
|
|
|
void l1if_open_pdch() { abort(); }
|
|
|
|
}
|