Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 1 | /* (C) 2013 by Holger Hans Peter Freyther |
| 2 | * |
| 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | extern "C" { |
| 21 | #include <osmocom/core/msgb.h> |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 22 | #include <osmocom/core/backtrace.h> |
| 23 | #include <osmocom/gsm/gsm_utils.h> |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 24 | } |
| 25 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 26 | #include "openbsc_clone.h" |
| 27 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 28 | #include <gprs_bssgp_pcu.h> |
| 29 | |
| 30 | #include <stdint.h> |
| 31 | #include <string.h> |
| 32 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 33 | /* GPRS attach with a foreign TLLI */ |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 34 | static const uint8_t gprs_attach_llc[] = { |
| 35 | /* LLC-PDU IE */ |
| 36 | 0x0e, 0x00, 0x2e, |
| 37 | |
| 38 | 0x01, 0xc0, 0x01, 0x08, 0x01, 0x02, 0xf5, 0x40, |
| 39 | 0x71, 0x08, 0x00, 0x05, 0xf4, 0x2d, 0xf1, 0x18, |
| 40 | 0x20, 0x62, 0xf2, 0x10, 0x09, 0x67, 0x00, 0x13, |
| 41 | 0x16, 0x73, 0x43, 0x2a, 0x80, 0x42, 0x00, 0x42, |
| 42 | 0x88, 0x0b, 0x04, 0x20, 0x04, 0x2e, 0x82, 0x30, |
| 43 | 0x42, 0x00, 0x40, 0xaa, 0xf3, 0x18 |
| 44 | }; |
| 45 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 46 | static int next_wanted_nu; |
| 47 | |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 48 | struct msgb *create_msg(const uint8_t *data, size_t len) |
| 49 | { |
| 50 | struct msgb *msg = msgb_alloc_headroom(4096, 128, "create msg"); |
| 51 | msg->l3h = msgb_put(msg, len); |
| 52 | memcpy(msg->l3h, data, len); |
| 53 | return msg; |
| 54 | } |
| 55 | |
| 56 | void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu) |
| 57 | { |
| 58 | uint32_t tlli = 0xadf11820; |
| 59 | const uint8_t qos_profile[] = { 0x0, 0x0, 0x04 }; |
| 60 | |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 61 | next_wanted_nu = 0; |
Holger Hans Peter Freyther | 741481d | 2013-07-28 21:14:51 +0200 | [diff] [blame] | 62 | struct msgb *msg = create_msg(gprs_attach_llc, ARRAY_SIZE(gprs_attach_llc)); |
| 63 | bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, msg); |
| 64 | } |
Holger Hans Peter Freyther | bc1e52c | 2013-08-22 08:44:38 +0200 | [diff] [blame^] | 65 | |
| 66 | void test_replay_gprs_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp) |
| 67 | { |
| 68 | struct bssgp_ud_hdr *budh; |
| 69 | struct gprs_llc_hdr_parsed ph; |
| 70 | uint32_t tlli; |
| 71 | |
| 72 | if (!TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU)) |
| 73 | return; |
| 74 | |
| 75 | |
| 76 | gprs_llc_hdr_parse(&ph, TLVP_VAL(tp, BSSGP_IE_LLC_PDU), |
| 77 | TLVP_LEN(tp, BSSGP_IE_LLC_PDU)); |
| 78 | |
| 79 | budh = (struct bssgp_ud_hdr *)msgb_bssgph(msg); |
| 80 | tlli = ntohl(budh->tlli); |
| 81 | |
| 82 | /* all messages we should get, should be for a foreign tlli */ |
| 83 | OSMO_ASSERT(gprs_tlli_type(tlli) == TLLI_FOREIGN); |
| 84 | printf("TLLI(0x%08x) is foreign!\n", tlli); |
| 85 | |
| 86 | OSMO_ASSERT(ph.cmd == GPRS_LLC_UI); |
| 87 | OSMO_ASSERT(ph.sapi == 1); |
| 88 | OSMO_ASSERT(ph.seq_tx == next_wanted_nu++); |
| 89 | |
| 90 | /* this test just wants to see messages... no further data is sent */ |
| 91 | if (next_wanted_nu == 4) { |
| 92 | printf("Test done.\n"); |
| 93 | exit(EXIT_SUCCESS); |
| 94 | } |
| 95 | } |