blob: c5098bcb5e2989594b1a19c3da667ed4c71ffec1 [file] [log] [blame]
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +02001/* (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
20extern "C" {
21#include <osmocom/core/msgb.h>
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020022#include <osmocom/core/backtrace.h>
23#include <osmocom/gsm/gsm_utils.h>
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020024}
25
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020026#include "openbsc_clone.h"
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020027#include "gprs_tests.h"
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020028
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020029#include <gprs_bssgp_pcu.h>
30
31#include <stdint.h>
32#include <string.h>
33
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020034/* GPRS attach with a foreign TLLI */
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020035static const uint8_t gprs_attach_llc[] = {
36 /* LLC-PDU IE */
37 0x0e, 0x00, 0x2e,
38
39 0x01, 0xc0, 0x01, 0x08, 0x01, 0x02, 0xf5, 0x40,
40 0x71, 0x08, 0x00, 0x05, 0xf4, 0x2d, 0xf1, 0x18,
41 0x20, 0x62, 0xf2, 0x10, 0x09, 0x67, 0x00, 0x13,
42 0x16, 0x73, 0x43, 0x2a, 0x80, 0x42, 0x00, 0x42,
43 0x88, 0x0b, 0x04, 0x20, 0x04, 0x2e, 0x82, 0x30,
44 0x42, 0x00, 0x40, 0xaa, 0xf3, 0x18
45};
46
Jacob Erlbeck1f332942015-05-04 08:21:17 +020047static uint32_t next_wanted_nu;
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020048
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020049void test_replay_gprs_attach(struct gprs_bssgp_pcu *pcu)
50{
51 uint32_t tlli = 0xadf11820;
52 const uint8_t qos_profile[] = { 0x0, 0x0, 0x04 };
53
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020054 next_wanted_nu = 0;
Holger Hans Peter Freyther741481d2013-07-28 21:14:51 +020055 struct msgb *msg = create_msg(gprs_attach_llc, ARRAY_SIZE(gprs_attach_llc));
56 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, msg);
57}
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020058
59void test_replay_gprs_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
60{
61 struct bssgp_ud_hdr *budh;
62 struct gprs_llc_hdr_parsed ph;
63 uint32_t tlli;
64
65 if (!TLVP_PRESENT(tp, BSSGP_IE_LLC_PDU))
66 return;
67
68
69 gprs_llc_hdr_parse(&ph, TLVP_VAL(tp, BSSGP_IE_LLC_PDU),
70 TLVP_LEN(tp, BSSGP_IE_LLC_PDU));
71
72 budh = (struct bssgp_ud_hdr *)msgb_bssgph(msg);
73 tlli = ntohl(budh->tlli);
74
75 /* all messages we should get, should be for a foreign tlli */
76 OSMO_ASSERT(gprs_tlli_type(tlli) == TLLI_FOREIGN);
77 printf("TLLI(0x%08x) is foreign!\n", tlli);
78
79 OSMO_ASSERT(ph.cmd == GPRS_LLC_UI);
80 OSMO_ASSERT(ph.sapi == 1);
Holger Hans Peter Freytherb3a87ce2013-12-12 14:42:35 +010081 OSMO_ASSERT(ph.seq_tx == next_wanted_nu);
82 next_wanted_nu += 1;
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020083
84 /* this test just wants to see messages... no further data is sent */
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020085 if (next_wanted_nu == 6) {
86 printf("GPRS attach with increasing N(U) done.\n");
87 gprs_test_success(pcu);
Holger Hans Peter Freytherbc1e52c2013-08-22 08:44:38 +020088 }
89}