Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 1 | /* 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 | |
| 22 | extern "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 */ |
| 35 | void *tall_pcu_ctx; |
| 36 | struct gprs_rlcmac_bts *gprs_rlcmac_bts; |
| 37 | int16_t spoof_mnc = 0, spoof_mcc = 0; |
| 38 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 39 | extern void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu); |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 40 | extern void test_replay_gprs_data(struct gprs_bssgp_pcu *, struct msgb *, struct tlv_parsed *); |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 41 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 42 | struct gprs_rlcmac_bts *create_bts() |
| 43 | { |
| 44 | struct gprs_rlcmac_bts *bts; |
| 45 | |
| 46 | bts = talloc_zero(tall_pcu_ctx, struct gprs_rlcmac_bts); |
| 47 | if (!bts) |
| 48 | return NULL; |
| 49 | bts->fc_interval = 100; |
| 50 | bts->initial_cs_dl = bts->initial_cs_ul = 1; |
| 51 | bts->cs1 = 1; |
| 52 | bts->t3142 = 20; |
| 53 | bts->t3169 = 5; |
| 54 | bts->t3191 = 5; |
| 55 | bts->t3193_msec = 100; |
| 56 | bts->t3195 = 5; |
| 57 | bts->n3101 = 10; |
| 58 | bts->n3103 = 4; |
| 59 | bts->n3105 = 8; |
| 60 | bts->alpha = 0; /* a = 0.0 */ |
| 61 | |
| 62 | if (!bts->alloc_algorithm) |
| 63 | bts->alloc_algorithm = alloc_algorithm_b; |
| 64 | |
| 65 | return bts; |
| 66 | } |
| 67 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 68 | static void bvci_unblocked(struct gprs_bssgp_pcu *pcu) |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 69 | { |
| 70 | printf("BVCI unblocked. We can begin with test cases.\n"); |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 71 | test_replay_gprs_attach(pcu); |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 72 | } |
| 73 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 74 | static void bssgp_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp) |
| 75 | { |
| 76 | test_replay_gprs_data(pcu, msg, tp); |
| 77 | } |
| 78 | |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 79 | void create_and_connect_bssgp(struct gprs_rlcmac_bts *bts, |
| 80 | uint32_t sgsn_ip, uint16_t sgsn_port) |
| 81 | { |
| 82 | struct gprs_bssgp_pcu *pcu; |
| 83 | |
| 84 | pcu = gprs_bssgp_create_and_connect(bts, 0, sgsn_ip, sgsn_port, |
| 85 | 20, 20, 20, 0x901, 0x99, 1, 0, 0); |
| 86 | pcu->on_unblock_ack = bvci_unblocked; |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 87 | pcu->on_dl_unit_data = bssgp_data; |
Holger Hans Peter Freyther | 4ea9407 | 2013-07-28 18:34:49 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | int main(int argc, char **argv) |
| 91 | { |
| 92 | struct gprs_rlcmac_bts *bts; |
| 93 | |
| 94 | tall_pcu_ctx = talloc_named_const(NULL, 1, "moiji-mobile Emu-PCU context"); |
| 95 | if (!tall_pcu_ctx) |
| 96 | abort(); |
| 97 | |
| 98 | msgb_set_talloc_ctx(tall_pcu_ctx); |
| 99 | osmo_init_logging(&gprs_log_info); |
| 100 | vty_init(&pcu_vty_info); |
| 101 | pcu_vty_init(&gprs_log_info); |
| 102 | |
| 103 | gprs_rlcmac_bts = create_bts(); |
| 104 | if (!gprs_rlcmac_bts) |
| 105 | abort(); |
| 106 | |
| 107 | create_and_connect_bssgp(gprs_rlcmac_bts, INADDR_LOOPBACK, 23000); |
| 108 | |
| 109 | for (;;) |
| 110 | osmo_select_main(0); |
| 111 | |
| 112 | return EXIT_SUCCESS; |
| 113 | } |
| 114 | |
| 115 | /* |
| 116 | * stubs that should not be reached |
| 117 | */ |
| 118 | extern "C" { |
| 119 | void l1if_pdch_req() { abort(); } |
| 120 | void l1if_connect_pdch() { abort(); } |
| 121 | void l1if_close_pdch() { abort(); } |
| 122 | void l1if_open_pdch() { abort(); } |
| 123 | } |