blob: 8c885e582ca6d37e9b4581177fdafbce2646869f [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;
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020095 struct gprs_llc_hdr_parsed hp;
96 struct tlv_parsed ack_tp;
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +020097
98 gprs_llc_hdr_parse(&hp, TLVP_VAL(tp, BSSGP_IE_LLC_PDU),
99 TLVP_LEN(tp, BSSGP_IE_LLC_PDU));
100 msgb_gmmh(msg) = (unsigned char *) hp.data;
101
102 struct gsm48_hdr *gh = (struct gsm48_hdr *) msgb_gmmh(msg);
103
104 OSMO_ASSERT(gh->msg_type == GSM48_MT_GMM_ATTACH_ACK);
105 struct gsm48_attach_ack *ack = (struct gsm48_attach_ack *) gh->data;
Jacob Erlbeck1f332942015-05-04 08:21:17 +0200106 tlv_parse(&ack_tp, &gsm48_gmm_att_tlvdef, ack->data,
Holger Hans Peter Freyther9d938382013-07-31 21:59:29 +0200107 (msg->data + msg->len) - ack->data, 0, 0);
108
109
110 OSMO_ASSERT(TLVP_PRESENT(&ack_tp, GSM48_IE_GMM_ALLOC_PTMSI));
111 memcpy(&tmsi, TLVP_VAL(&ack_tp, GSM48_IE_GMM_ALLOC_PTMSI) + 1, 4);
112 tmsi = ntohl(tmsi);
113 tlli = gprs_tmsi2tlli(tmsi, TLLI_LOCAL);
114 printf("New TLLI(0x%08x) based on tmsi(0x%x)\n", tlli, tmsi);
115}
116
117void test_pdp_activation_start(struct gprs_bssgp_pcu *pcu)
118{
119 struct msgb *msg = create_msg(attach, ARRAY_SIZE(attach));
120 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, msg);
121 current_state = Test_IdRespIMEI;
122}
123
124
125void test_pdp_activation_data(struct gprs_bssgp_pcu *pcu, struct msgb *msg, struct tlv_parsed *tp)
126{
127 const uint8_t *data;
128 size_t len;
129
130 switch (current_state) {
131 case Test_IdRespIMEI:
132 data = id_resp_imei;
133 len = ARRAY_SIZE(id_resp_imei);
134 current_state = Test_IdRespIMSI;
135 break;
136 case Test_IdRespIMSI:
137 data = id_resp_imsi;
138 len = ARRAY_SIZE(id_resp_imsi);
139 current_state = Test_AttachCompl;
140 break;
141 case Test_AttachCompl:
142 data = attach_complete;
143 len = ARRAY_SIZE(attach_complete);
144 extract_tmsi_and_generate_tlli(msg, tp);
145 current_state = Test_PDPAct;
146 break;
147 case Test_PDPAct:
148 printf("PDP context is active or not...\n");
149 return;
150 break;
151 case Test_Done:
152 case Test_Start: /* fall through */
153 return;
154 break;
155 default:
156 printf("Unknown state. %d\n", current_state);
157 return;
158 break;
159 };
160
161 struct msgb *out = create_msg(data, len);
162 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, out);
163
164 /* send it after the PDP... */
165 if (current_state == Test_PDPAct) {
166 out = create_msg(pdp_context, ARRAY_SIZE(pdp_context));
167 bssgp_tx_ul_ud(pcu->bctx, tlli, qos_profile, out);
168 }
169}