blob: 673874f5c87c254ddeba977707d9b49c8af0c54f [file] [log] [blame]
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +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>
22#include <osmocom/core/backtrace.h>
23#include <osmocom/gsm/gsm_utils.h>
24}
25
26#include "openbsc_clone.h"
27#include "gprs_tests.h"
28
29#include <gprs_bssgp_pcu.h>
30
31#include <stdint.h>
32#include <string.h>
33
34static const uint8_t attach[] = {
35 0x0e, 0x00, 0x26,
36 0x01, 0xc0, 0x01, 0x08, 0x01, 0x02, 0xe5, 0x80,
37 0x71, 0x0d, 0x01, 0x05, 0xf4, 0x02, 0x30, 0xef,
38 0x0e, 0x09, 0xf1, 0x07, 0x00, 0x01, 0x00, 0x0b,
39 0x34, 0xc7, 0x03, 0x2a, 0xa0, 0x42, 0x7c, 0xad,
40 0xe1, 0x18, 0x0b, 0xf8, 0xef, 0xfc
41};
42
43static const uint8_t id_resp_imei[] = {
44 0x0e, 0x00, 0x11,
45 0x01, 0xc0, 0x05, 0x08, 0x16, 0x08, 0x3a, 0x49,
46 0x50, 0x13, 0x28, 0x15, 0x80, 0x01, 0x21, 0x6c,
47 0x22
48};
49
50static const uint8_t id_resp_imsi[] = {
51 0x0e, 0x00, 0x11,
52 0x01, 0xc0, 0x09, 0x08, 0x16, 0x08, 0x99, 0x10,
53 0x07, 0x00, 0x00, 0x00, 0x03, 0x49, 0xc7, 0x5b,
54 0xb6
55};
56
57static const uint8_t attach_complete[] = {
58 0x0e, 0x00, 0x08,
59 0x01, 0xc0, 0x0d, 0x08, 0x03, 0x55, 0x1c, 0xea
60};
61
62static const uint8_t pdp_context[] = {
63 0x0e, 0x00, 0x5a,
64 0x01, 0xc0, 0x11, 0x0a, 0x41, 0x05, 0x03, 0x0c,
65 0x00, 0x00, 0x1f, 0x10, 0x00, 0x00, 0x00, 0x00,
66 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x21, 0x28,
67 0x12, 0x08, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e,
68 0x65, 0x74, 0x05, 0x65, 0x70, 0x6c, 0x75, 0x73,
69 0x02, 0x64, 0x65, 0x27, 0x2a, 0x80, 0xc0, 0x23,
70 0x13, 0x01, 0x00, 0x00, 0x13, 0x05, 0x65, 0x70,
71 0x6c, 0x75, 0x73, 0x08, 0x69, 0x6e, 0x74, 0x65,
72 0x72, 0x6e, 0x65, 0x74, 0x80, 0x21, 0x10, 0x01,
73 0x00, 0x00, 0x10, 0x81, 0x06, 0x00, 0x00, 0x00,
74 0x00, 0x83, 0x06, 0x00, 0x00, 0x00, 0x00, 0xcf,
75 0x90, 0xcc
76};
77
78static const uint8_t qos_profile[] = { 0x0, 0x0, 0x04 };
79static uint32_t tlli = 0xadf11821;
80
81enum state {
82 Test_Start,
83 Test_IdRespIMEI,
84 Test_IdRespIMSI,
85 Test_AttachCompl,
86 Test_PDPAct,
87 Test_Done,
88};
89
90static enum state current_state = Test_Start;
91
92static void extract_tmsi_and_generate_tlli(struct msgb *msg, struct tlv_parsed *tp)
93{
94 uint32_t tmsi;
95 struct bssgp_ud_hdr *budh;
96 struct gprs_llc_hdr_parsed hp;
97 struct tlv_parsed ack_tp;
98 int rc;
99
100 gprs_llc_hdr_parse(&hp, TLVP_VAL(tp, BSSGP_IE_LLC_PDU),
101 TLVP_LEN(tp, BSSGP_IE_LLC_PDU));
102 msgb_gmmh(msg) = (unsigned char *) hp.data;
103
104 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
105
106 OSMO_ASSERT(gh->msg_type == GSM48_MT_GMM_ATTACH_ACK);
107 struct gsm48_attach_ack *ack = (struct gsm48_attach_ack *) gh->data;
108 rc = tlv_parse(&ack_tp, &gsm48_gmm_att_tlvdef, ack->data,
109 (msg->data + msg->len) - ack->data, 0, 0);
110
111
112 OSMO_ASSERT(TLVP_PRESENT(&ack_tp, GSM48_IE_GMM_ALLOC_PTMSI));
113 memcpy(&tmsi, TLVP_VAL(&ack_tp, GSM48_IE_GMM_ALLOC_PTMSI) + 1, 4);
114 tmsi = ntohl(tmsi);
115 tlli = gprs_tmsi2tlli(tmsi, TLLI_LOCAL);
116 printf("New TLLI(0x%08x) based on tmsi(0x%x)\n", tlli, tmsi);
117}
118
119void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu)
120{
121 struct msgb *msg = create_msg(attach, ARRAY_SIZE(attach));
122 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, msg);
123 current_state = Test_IdRespIMEI;
124}
125
126
127void test_pdp_activation_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
128{
129 const uint8_t *data;
130 size_t len;
131
132 switch (current_state) {
133 case Test_IdRespIMEI:
134 data = id_resp_imei;
135 len = ARRAY_SIZE(id_resp_imei);
136 current_state = Test_IdRespIMSI;
137 break;
138 case Test_IdRespIMSI:
139 data = id_resp_imsi;
140 len = ARRAY_SIZE(id_resp_imsi);
141 current_state = Test_AttachCompl;
142 break;
143 case Test_AttachCompl:
144 data = attach_complete;
145 len = ARRAY_SIZE(attach_complete);
146 extract_tmsi_and_generate_tlli(msg, tp);
147 current_state = Test_PDPAct;
148 break;
149 case Test_PDPAct:
150 printf("PDP context is active or not...\n");
151 return;
152 break;
153 case Test_Done:
154 case Test_Start: /* fall through */
155 return;
156 break;
157 default:
158 printf("Unknown state. %d\n", current_state);
159 return;
160 break;
161 };
162
163 struct msgb *out = create_msg(data, len);
164 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, out);
165
166 /* send it after the PDP... */
167 if (current_state == Test_PDPAct) {
168 out = create_msg(pdp_context, ARRAY_SIZE(pdp_context));
169 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, out);
170 }
171}