blob: 337c0c8f7448f564723ec689191100c2f3f249c8 [file] [log] [blame]
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +02001/* Code for a software PCU to test a SGSN.. */
2
3/* (C) 2013 by Holger Hans Peter Freyther
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22extern "C" {
23#include <osmocom/core/talloc.h>
24#include <pcu_vty.h>
25}
26
27#include <gprs_bssgp_pcu.h>
28#include <gprs_rlcmac.h>
29
30#include <stdlib.h>
31#include <sys/types.h>
32#include <sys/socket.h>
33
34/* Extern data to please the underlying code */
35void *tall_pcu_ctx;
36struct gprs_rlcmac_bts *gprs_rlcmac_bts;
37int16_t spoof_mnc = 0, spoof_mcc = 0;
38
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020039extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu);
40
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020041struct gprs_rlcmac_bts *create_bts()
42{
43 struct gprs_rlcmac_bts *bts;
44
45 bts = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_bts);
46 if (!bts)
47 return NULL;
48 bts->fc_interval = 100;
49 bts->initial_cs_dl = bts->initial_cs_ul = 1;
50 bts->cs1 = 1;
51 bts->t3142 = 20;
52 bts->t3169 = 5;
53 bts->t3191 = 5;
54 bts->t3193_msec = 100;
55 bts->t3195 = 5;
56 bts->n3101 = 10;
57 bts->n3103 = 4;
58 bts->n3105 = 8;
59 bts->alpha = 0; /* a = 0.0 */
60
61 if (!bts->alloc_algorithm)
62 bts->alloc_algorithm = alloc_algorithm_b;
63
64 return bts;
65}
66
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020067static void bvci_unblocked(struct gprs_bssgp_pcu *pcu)
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020068{
69 printf("BVCI unblocked. We can begin with test cases.\n");
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020070 test_replay_gprs_attach(pcu);
Holger Hans Peter Freyther4ea94072013-07-28 18:34:49 +020071}
72
73void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts,
74 uint32_t sgsn_ip, uint16_t sgsn_port)
75{
76 struct gprs_bssgp_pcu *pcu;
77
78 pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port,
79 20, 20, 20, 0x901, 0x99, 1, 0, 0);
80 pcu->on_unblock_ack = bvci_unblocked;
81}
82
83int main(int argc, char **argv)
84{
85 struct gprs_rlcmac_bts *bts;
86
87 tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context");
88 if (!tall_pcu_ctx)
89 abort();
90
91 msgb_set_talloc_ctx(tall_pcu_ctx);
92 osmo_init_logging(&gprs_log_info);
93 vty_init(&pcu_vty_info);
94 pcu_vty_init(&gprs_log_info);
95
96 gprs_rlcmac_bts = create_bts();
97 if (!gprs_rlcmac_bts)
98 abort();
99
100 create_and_connect_bssgp(gprs_rlcmac_bts, INADDR_LOOPBACK, 23000);
101
102 for (;;)
103 osmo_select_main(0);
104
105 return EXIT_SUCCESS;
106}
107
108/*
109 * stubs that should not be reached
110 */
111extern "C" {
112void l1if_pdch_req() { abort(); }
113void l1if_connect_pdch() { abort(); }
114void l1if_close_pdch() { abort(); }
115void l1if_open_pdch() { abort(); }
116}