blob: c6ad1925696533b500d2eb89add9df25901d3485 [file] [log] [blame]
Ivan Kluchnikov487a1412011-12-21 13:17:53 +03001/* RLCMACTest.cpp
2 *
3 * Copyright (C) 2011 Ivan Klyuchnikov
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (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 General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19
20
21
22//#include <BitVector.h>
23#include <iostream>
24#include <cstdlib>
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +040025#include <cstring>
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +010026#include <assert.h>
Max7426c5f2019-02-18 20:42:42 +010027#include "gprs_rlcmac.h"
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +010028#include "decoding.h"
Max7426c5f2019-02-18 20:42:42 +010029
Andreas Eversberg138f4e62013-01-14 12:31:11 +010030extern "C" {
31extern const struct log_info gprs_log_info;
32#include "pcu_vty.h"
33#include <osmocom/vty/telnet_interface.h>
34#include <osmocom/vty/logging.h>
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +053035#include <osmocom/core/utils.h>
Maxd3a0d912019-03-05 16:15:01 +010036#include <osmocom/core/msgb.h>
Andreas Eversberg138f4e62013-01-14 12:31:11 +010037#include <osmocom/core/application.h>
Vadim Yanitskiy39a65052020-01-25 01:24:59 +070038
39#include "csn1.h"
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010040#include "gsm_rlcmac.h"
Andreas Eversberg138f4e62013-01-14 12:31:11 +010041}
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030042using namespace std;
43
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +010044void *tall_pcu_ctx;
45
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030046void printSizeofRLCMAC()
47{
Pau Espin Pedrol54681c32020-01-23 21:59:23 +010048 printf("*** %s ***\n", __func__);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030049 cout << "sizeof RlcMacUplink_t " << sizeof(RlcMacUplink_t) << endl;
50 cout << "sizeof Packet_Cell_Change_Failure_t " << sizeof(Packet_Cell_Change_Failure_t) << endl;
51 cout << "sizeof Packet_Control_Acknowledgement_t " << sizeof(Packet_Control_Acknowledgement_t) << endl;
52 cout << "sizeof Packet_Downlink_Ack_Nack_t " << sizeof(Packet_Downlink_Ack_Nack_t) << endl;
53 cout << "sizeof EGPRS_PD_AckNack_t " << sizeof(EGPRS_PD_AckNack_t) << endl;
54 cout << "sizeof Packet_Uplink_Dummy_Control_Block_t " << sizeof(Packet_Uplink_Dummy_Control_Block_t) << endl;
55 cout << "sizeof Packet_Measurement_Report_t " << sizeof(Packet_Measurement_Report_t) << endl;
56 cout << "sizeof Packet_Resource_Request_t " << sizeof(Packet_Resource_Request_t) << endl;
57 cout << "sizeof Packet_Mobile_TBF_Status_t " << sizeof(Packet_Mobile_TBF_Status_t) << endl;
58 cout << "sizeof Packet_PSI_Status_t " << sizeof(Packet_PSI_Status_t) << endl;
59 cout << "sizeof Packet_Enh_Measurement_Report_t " << sizeof(Packet_Enh_Measurement_Report_t) << endl;
60 cout << "sizeof Packet_Cell_Change_Notification_t " << sizeof(Packet_Cell_Change_Notification_t) << endl;
61 cout << "sizeof Packet_SI_Status_t " << sizeof(Packet_SI_Status_t) << endl;
62 cout << "sizeof Additional_MS_Rad_Access_Cap_t " << sizeof(Additional_MS_Rad_Access_Cap_t) << endl;
63 cout << "sizeof Packet_Pause_t " << sizeof(Packet_Pause_t) << endl;
64
65 cout << "sizeof RlcMacDownlink_t " << sizeof(RlcMacDownlink_t) << endl;
66 cout << "sizeof Packet_Access_Reject_t " << sizeof(Packet_Access_Reject_t) << endl;
Holger Hans Peter Freythere13298d2013-07-28 16:45:54 +020067 cout << "sizeof Packet_Cell_Change_Order_t " << sizeof(Packet_Cell_Change_Order_t) << endl;
68 cout << "sizeof Packet_Downlink_Assignment_t " << sizeof(Packet_Downlink_Assignment_t) << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030069 cout << "sizeof Packet_Neighbour_Cell_Data_t " << sizeof(Packet_Neighbour_Cell_Data_t) << endl;
70 cout << "sizeof Packet_Serving_Cell_Data_t " << sizeof(Packet_Serving_Cell_Data_t) << endl;
71 cout << "sizeof Packet_Paging_Request_t " << sizeof(Packet_Paging_Request_t) << endl;
72 cout << "sizeof Packet_PDCH_Release_t " << sizeof(Packet_PDCH_Release_t) << endl;
73 cout << "sizeof Packet_Polling_Request_t " << sizeof(Packet_Polling_Request_t) << endl;
74 cout << "sizeof Packet_Power_Control_Timing_Advance_t " << sizeof(Packet_Power_Control_Timing_Advance_t) << endl;
75 cout << "sizeof Packet_PRACH_Parameters_t " << sizeof(Packet_PRACH_Parameters_t) << endl;
76 cout << "sizeof Packet_Queueing_Notification_t " << sizeof(Packet_Queueing_Notification_t) << endl;
77 cout << "sizeof Packet_Timeslot_Reconfigure_t " << sizeof(Packet_Timeslot_Reconfigure_t) << endl;
78 cout << "sizeof Packet_TBF_Release_t " << sizeof(Packet_TBF_Release_t) << endl;
79 cout << "sizeof Packet_Uplink_Ack_Nack_t " << sizeof(Packet_Uplink_Ack_Nack_t) << endl;
80 cout << "sizeof Packet_Uplink_Assignment_t " << sizeof(Packet_Uplink_Assignment_t) << endl;
81 cout << "sizeof Packet_Cell_Change_Continue_t " << sizeof(Packet_Cell_Change_Continue_t) << endl;
82 cout << "sizeof Packet_Handover_Command_t " << sizeof(Packet_Handover_Command_t) << endl;
83 cout << "sizeof Packet_PhysicalInformation_t " << sizeof(Packet_PhysicalInformation_t) << endl;
84 cout << "sizeof Packet_Downlink_Dummy_Control_Block_t " << sizeof(Packet_Downlink_Dummy_Control_Block_t) << endl;
85 cout << "sizeof PSI1_t " << sizeof(PSI1_t) << endl;
86 cout << "sizeof PSI2_t " << sizeof(PSI2_t) << endl;
87 cout << "sizeof PSI3_t " << sizeof(PSI3_t) << endl;
88 cout << "sizeof PSI3_BIS_t " << sizeof(PSI3_BIS_t) << endl;
89 cout << "sizeof PSI4_t " << sizeof(PSI4_t) << endl;
90 cout << "sizeof PSI13_t " << sizeof(PSI13_t) << endl;
91 cout << "sizeof PSI5_t " << sizeof(PSI5_t) << endl;
92}
93
Alexander Couzensccde5c92017-02-04 03:10:08 +010094void testRlcMacDownlink(void *test_ctx)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +030095{
Pau Espin Pedrol54681c32020-01-23 21:59:23 +010096 printf("*** %s ***\n", __func__);
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +010097
98 int rc;
Alexander Couzensccde5c92017-02-04 03:10:08 +010099 struct bitvec *resultVector = bitvec_alloc(23, test_ctx);
Max7426c5f2019-02-18 20:42:42 +0100100 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300101
102 std::string testData[] = {
103 "4e082500e3f1a81d080820800b2b2b2b2b2b2b2b2b2b2b", // Packet Downlink Assignment
Saurabh Sharan656eed52016-03-10 14:15:29 +0530104 "48282407a6a07422720100032b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Assignment
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300105 "47240c00400000000000000079eb2ac9402b2b2b2b2b2b", // Packet Uplink Ack Nack
Saurabh Sharanbacb65b2016-03-10 17:24:49 +0530106 "47283c367513ba333004242b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Assignment
107 "400820001a3904df0680efb3300b2b2b2b2b2b2b2b2b2b", // Packet Downlink Assignment (EGPRS)
Saurabh Sharan2b09c392016-03-16 19:17:32 +0530108 "40284f0000001009810c826f4406809dcecb2b2b2b2b2b", // Packet Uplink Assignment (EGPRS)
Pau Espin Pedrol5cb002f2020-01-23 23:45:17 +0100109 "4024030f2f0000000087b0042b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Ack Nack (EGPRS)
Vadim Yanitskiy9b2f7c42020-02-11 21:45:19 +0700110 "4913e00850884013a8048b2b2b2b2b2b2b2b2b2b2b2b2b", // Polling Request (malformed)
Pau Espin Pedrol5cb002f2020-01-23 23:45:17 +0100111 "412430007fffffffffffffffefd19c7ba12b2b2b2b2b2b", // Packet Uplink Ack Nack?
112 "41942b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // System Info 13?
Pau Espin Pedrol259a6942020-11-23 17:57:35 +0100113 "40883c1493120000000012002b2b2b2b2b2b2b2b2b2b2b", // Pkt Paging Request (OS#4838)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300114 };
115
116 int testDataSize = sizeof(testData)/sizeof(testData[0]);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300117
118 cout << " DOWNLINK " << endl;
119 for (int i = 0; i < testDataSize; i++)
120 {
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100121 cout << "vector1 = " << testData[i] << endl;
Alexander Couzensccde5c92017-02-04 03:10:08 +0100122 bitvec *vector = bitvec_alloc(23, test_ctx);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400123 bitvec_unhex(vector, testData[i].c_str());
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100124
Pau Espin Pedrol99c437b2020-01-24 12:34:50 +0100125 RlcMacDownlink_t data;
126 memset(&data, 0, sizeof(data));
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300127 cout << "=========Start DECODE===========" << endl;
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100128 rc = decode_gsm_rlcmac_downlink(vector, &data);
129 cout << "+++++++++Finish DECODE ("<< rc <<")++++++++++" << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300130 cout << "=========Start ENCODE=============" << endl;
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100131 rc = encode_gsm_rlcmac_downlink(resultVector, &data);
132 cout << "+++++++++Finish ENCODE ("<< rc <<")+++++++++++" << endl;
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100133 cout << "vector1 = " << osmo_hexdump(vector->data, 23) << endl;
134 cout << "vector2 = " << osmo_hexdump(resultVector->data, 23) << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400135 if (memcmp(vector->data, resultVector->data, 23) == 0)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300136 cout << "vector1 == vector2 : TRUE" << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300137 else
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300138 cout << "vector1 == vector2 : FALSE" << endl;
Max7426c5f2019-02-18 20:42:42 +0100139 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400140 bitvec_free(vector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300141 }
Andreas Eversberg273a2222013-01-16 08:56:33 +0100142
143 bitvec_free(resultVector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300144}
145
146
Alexander Couzensccde5c92017-02-04 03:10:08 +0100147void testRlcMacUplink(void *test_ctx)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300148{
Pau Espin Pedrol54681c32020-01-23 21:59:23 +0100149 printf("*** %s ***\n", __func__);
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100150
151 int rc;
Alexander Couzensccde5c92017-02-04 03:10:08 +0100152 struct bitvec *resultVector = bitvec_alloc(23, test_ctx);
Max7426c5f2019-02-18 20:42:42 +0100153 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300154
155 std::string testData[] = {
Saurabh Sharan656eed52016-03-10 14:15:29 +0530156 "400e1e61d11d2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // Packet Uplink Dummy Control Block
157 "400b8020000000000000002480e0032b2b2b2b2b2b2b2b", // Packet Downlink Ack/Nack
Saurabh Sharanbacb65b2016-03-10 17:24:49 +0530158 "4016713dc094270ca2ae57ef909006aa0fc0001f80222b", // Packet Resource Request
Vadim Yanitskiyf22163b2020-03-06 06:51:48 +0700159 "401673c87f24af2632b25964200600000091000b780080", // Packet Resource Request (from keith)
Saurabh Sharanbacb65b2016-03-10 17:24:49 +0530160 "40200ffc0021ec010b2b2b2b2b2b2b2b2b2b2b2b2b2b2b", // EPDAN
Pau Espin Pedrol5cb002f2020-01-23 23:45:17 +0100161 "400a9020000000000000003010012a0800132b2b2b2b2b", // Packet Downlink Ack/Nack ?
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300162 };
163
164 int testDataSize = sizeof(testData)/sizeof(testData[0]);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300165
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300166
167 cout << " UPLINK " << endl;
168 for (int i = 0; i < testDataSize; i++)
169 {
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100170 cout << "vector1 = " << testData[i] << endl;
Alexander Couzensccde5c92017-02-04 03:10:08 +0100171 bitvec *vector = bitvec_alloc(23, test_ctx);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400172 bitvec_unhex(vector, testData[i].c_str());
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100173
Pau Espin Pedrol99c437b2020-01-24 12:34:50 +0100174 RlcMacUplink_t data;
175 memset(&data, 0, sizeof(data));
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300176 cout << "=========Start DECODE===========" << endl;
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100177 rc = decode_gsm_rlcmac_uplink(vector, &data);
178 cout << "+++++++++Finish DECODE ("<< rc << ")++++++++++" << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300179 cout << "=========Start ENCODE=============" << endl;
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100180 rc = encode_gsm_rlcmac_uplink(resultVector, &data);
181 cout << "+++++++++Finish ENCODE ("<< rc <<")+++++++++++" << endl;
Pau Espin Pedrol87bfbe42020-01-23 23:51:34 +0100182 cout << "vector1 = " << osmo_hexdump(vector->data, 23) << endl;
183 cout << "vector2 = " << osmo_hexdump(resultVector->data, 23) << endl;
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400184 if (memcmp(vector->data, resultVector->data, 23) == 0)
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300185 cout << "vector1 == vector2 : TRUE" << endl;
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300186 else
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300187 cout << "vector1 == vector2 : FALSE" << endl;
Max7426c5f2019-02-18 20:42:42 +0100188 bitvec_unhex(resultVector, DUMMY_VEC);
Ivan Kluchnikov835f91e2012-04-30 18:00:36 +0400189 bitvec_free(vector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300190 }
Andreas Eversberg273a2222013-01-16 08:56:33 +0100191
192 bitvec_free(resultVector);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300193}
194
Alexander Couzensccde5c92017-02-04 03:10:08 +0100195void testCsnLeftAlignedVarBmpBounds(void *test_ctx)
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530196{
Pau Espin Pedrol54681c32020-01-23 21:59:23 +0100197 printf("*** %s ***\n", __func__);
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100198
Maxd3a0d912019-03-05 16:15:01 +0100199 struct msgb *m = msgb_alloc(80, "test");
200 static uint8_t exp[] = { 0x7f, 0xff, 0xff, 0xee, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
Alexander Couzensccde5c92017-02-04 03:10:08 +0100201 bitvec *vector = bitvec_alloc(23, test_ctx);
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100202 int rc;
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530203
204 bitvec_unhex(vector, "40200bffd161003e0e519ffffffb800000000000000000");
205 RlcMacUplink_t data;
Pau Espin Pedrol99c437b2020-01-24 12:34:50 +0100206 memset(&data, 0, sizeof(data));
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530207
208 EGPRS_AckNack_Desc_t *urbb =
209 &data.u.Egprs_Packet_Downlink_Ack_Nack.EGPRS_AckNack.Desc;
Pau Espin Pedrol5e300ce2020-02-03 17:18:03 +0100210 rc = decode_gsm_rlcmac_uplink(vector, &data);
211 OSMO_ASSERT(rc == 0);
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530212
Maxd3a0d912019-03-05 16:15:01 +0100213 memcpy(msgb_put(m, 13), urbb->URBB, 13);
214 if (!msgb_eq_data_print(m, exp, 13))
215 printf("%s failed!\n", __func__);
216 msgb_free(m);
Aravind Sirsikar9f5f0082016-08-30 13:20:23 +0530217}
218
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +0100219extern "C" {
Pau Espin Pedrol007056e2020-03-26 15:03:33 +0100220int encode_gsm_ra_cap(struct bitvec *vector, MS_Radio_Access_capability_t * data);
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +0100221}
Vadim Yanitskiyb47e53b2020-02-20 04:33:50 +0700222
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100223void testRAcap(void *test_ctx)
224{
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100225 printf("*** %s ***\n", __func__);
226 MS_Radio_Access_capability_t data;
227 memset(&data, 0, sizeof(data));
228 bitvec *bv_dec = bitvec_alloc(23, test_ctx);
229 bitvec *bv_enc = bitvec_alloc(23, test_ctx);
230 unsigned int len_dec, len_enc;
231 int rc;
232/*
233MS RA capability 1
234 0001 .... = Access Technology Type: GSM E --note that GSM E covers GSM P (1)
235 .... 0011 011. .... = Length in bits: 0x1b (27)
236 ...0 01.. RF Power Capability, GMSK Power Class: Not specified (1)
237 A5 Bits: Same values apply for parameters as in the immediately preceding Access capabilities field within this IE (0)
238 .... ...1 = Controlled early Classmark Sending: Implemented
239 0... .... = Pseudo Synchronisation: Not Present
240 .0.. .... = Voice Group Call Service: no VGCS capability or no notifications wanted
241 ..0. .... = Voice Broadcast Service: no VBS capability or no notifications wanted
242 ...1 .... = Multislot capability struct: Present
243 HSCSD multislot class: Bits are not available (0)
244 SMS_VALUE (Switch-Measure-Switch): Bits are not available (0)
245 ECSD multislot class: Bits are not available (0)
246 DTM GPRS Multi Slot Class: Bits are not available (0)
247 .... ..00 011. .... = GPRS multislot class: Max Rx-Slot/TDMA:2 Max Tx-Slot/TDMA:2 Max-Sum-Slot/TDMA:3 Tta:3 Ttb:2 Tra:3 Trb:1 Type:1 (3)
248 ...0 .... = GPRS Extended Dynamic Allocation Capability: Not Implemented
249 .... ...0 0011 .... = EGPRS multislot class: Max Rx-Slot/TDMA:2 Max Tx-Slot/TDMA:2 Max-Sum-Slot/TDMA:3 Tta:3 Ttb:2 Tra:3 Trb:1 Type:1 (3)
250 .... 0... = EGPRS Extended Dynamic Allocation Capability: Not Implemented
251*/
252 bitvec_unhex(bv_dec, "1365146230");
253
254 printf("=== Test decoding of MS RA Capability ===\n");
255 rc = decode_gsm_ra_cap(bv_dec, &data);
256 OSMO_ASSERT(rc == 0);
257
258 /* Make sure there's 1 value (currently fails due to failed decoding) */
259 OSMO_ASSERT(data.Count_MS_RA_capability_value == 1);
260
261 /* Make sure GPRS / EGPRS multislot class is parsed correctly */
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100262 printf("GPRS multislot class = %u\n", get_ms_class_by_capability(&data));
263 printf("EGPRS multislot class = %u\n", get_egprs_ms_class_by_capability(&data));
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100264
265 /* Test encoding of decoded MS RA Capability */
266 printf("=== Test encoding of MS RA Capability ===\n");
267 rc = encode_gsm_ra_cap(bv_enc, &data);
268 printf("encode_gsm_ra_cap() returns %d\n", rc);
269
270 bv_dec->cur_bit = 4;
271 len_dec = bitvec_get_uint(bv_dec, 7);
272 bv_enc->cur_bit = 4;
273 len_enc = bitvec_get_uint(bv_enc, 7);
274
275 /* NOTE: vector2 is expected to be different because there is actually no
276 * way to distinguish between NULL and 0 in MS_Radio_Access_capability_t.
277 * The difference is in length indicator: 27 bits vs 65 bits. */
278 printf("vector1 (len_ind=%u) = %s\n", len_dec, osmo_hexdump(bv_dec->data, bv_dec->data_len));
279 printf("vector2 (len_ind=%u) = %s\n", len_enc, osmo_hexdump(bv_enc->data, bv_enc->data_len));
280
281 /* Mangle the length indicator (set it to 21) */
282 unsigned int writeIndex = 4;
283 rc = bitvec_write_field(bv_dec, &writeIndex, 21, 7);
284 OSMO_ASSERT(rc == 0);
285
286 /* Make sure decoding attempt fails */
287 printf("=== Test decoding of a malformed vector (short length indicator) ===\n");
288 rc = decode_gsm_ra_cap(bv_dec, &data);
289 printf("decode_gsm_ra_cap() returns %d\n", rc);
290}
291
292void testMalformedRAcap(void *test_ctx)
293{
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100294 printf("*** %s ***\n", __func__);
295 MS_Radio_Access_capability_t data;
296 memset(&data, 0, sizeof(data));
Vadim Yanitskiyb47e53b2020-02-20 04:33:50 +0700297 bitvec *bv_dec = bitvec_alloc(23, test_ctx);
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100298 int rc;
299/*
300 MS RA capability 1
301 0001 .... = Access Technology Type: GSM E --note that GSM E covers GSM P (1)
Vadim Yanitskiy55f06c32020-02-18 05:45:15 +0700302 .... 0011 101. .... = Length in bits: 0x1d (29)
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100303 ...0 01.. RF Power Capability, GMSK Power Class: Not specified (1)
304 A5 Bits: Same values apply for parameters as in the immediately preceding Access capabilities field within this IE (0)
305 .... ...1 = Controlled early Classmark Sending: Implemented
306 0... .... = Pseudo Synchronisation: Not Present
307 .0.. .... = Voice Group Call Service: no VGCS capability or no notifications wanted
308 ..0. .... = Voice Broadcast Service: no VBS capability or no notifications wanted
309 ...1 .... = Multislot capability struct: Present
310 .... ..00 011. .... = GPRS multislot class: Max Rx-Slot/TDMA:2 Max Tx-Slot/TDMA:2 Max-Sum-Slot/TDMA:3 Tta:3 Ttb:2 Tra:3 Trb:1 Type:1 (3)
311 ...0 .... = GPRS Extended Dynamic Allocation Capability: Not Implemented
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100312
313 It doesn't show up in wireshark's tree above because specific parser is
314 used, but this RA Cap bitstream has Exist_EGPRS_multislot_class = 1 but
315 it provides no struct with the expected data (malformed, generated
316 erroneusly through TTCN3). The CSN.1 dceoder should ideally return an
317 error here, but it doesn't (it returns a >0 value which we convert to 0
318 in decode_gsm_ra_cap()).
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100319*/
Vadim Yanitskiyb47e53b2020-02-20 04:33:50 +0700320 bitvec_unhex(bv_dec, "13a5146200");
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100321
Vadim Yanitskiyb47e53b2020-02-20 04:33:50 +0700322 printf("=== Test decoding of MS RA Capability ===\n");
323 rc = decode_gsm_ra_cap(bv_dec, &data);
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100324 printf("decode_gsm_ra_cap() returns %d\n", rc);
Vadim Yanitskiy55f06c32020-02-18 05:45:15 +0700325 OSMO_ASSERT(rc == 0);
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100326
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100327 /* For sake of completeness, check if the decoder could find 1 value
328 before failing to decode it */
Vadim Yanitskiy55f06c32020-02-18 05:45:15 +0700329 OSMO_ASSERT(data.Count_MS_RA_capability_value == 1);
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100330
Pau Espin Pedrol2f169242020-03-20 23:59:44 +0100331 bitvec_free(bv_dec);
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100332}
333
Pau Espin Pedrolefad80b2020-03-23 14:35:26 +0100334/* Reproduce crash from ticket OS#4463 */
335void testRAcap2(void *test_ctx)
336{
337 printf("*** %s ***\n", __func__);
338 MS_Radio_Access_capability_t data;
339 memset(&data, 0, sizeof(data));
340 bitvec *bv_dec = bitvec_alloc(23, test_ctx);
341 int rc;
342/*
343MS Radio Access Capability
344 Element ID: 0x13
345 1... .... = ext: 1
346 Length: 23
347 ------------------------------------------- Hex bitstream starts here:
348 MS RA capability 1
349 0001 .... = Access Technology Type: GSM E --note that GSM E covers GSM P (1)
350 .... 1001 001. .... = Length in bits: 0x49 (73)
351 ...1 00.. RF Power Capability, GMSK Power Class: 2 W (33 dBm) (4)
352 A5 Bits: A5 bits follow (1)
353 A5/1: encryption algorithm available (1)
354 A5/2: encryption algorithm not available (0)
355 A5/3: encryption algorithm available (1)
356 A5/4: encryption algorithm not available (0)
357 A5/5: encryption algorithm not available (0)
358 A5/6: encryption algorithm not available (0)
359 A5/7: encryption algorithm not available (0)
360 .... ..1. = Controlled early Classmark Sending: Implemented
361 .... ...1 = Pseudo Synchronisation: Present
362 0... .... = Voice Group Call Service: no VGCS capability or no notifications wanted
363 .0.. .... = Voice Broadcast Service: no VBS capability or no notifications wanted
364 ..1. .... = Multislot capability struct: Present
365 HSCSD multislot class: Bits are not available (0)
366 .... 0111 = SMS_VALUE (Switch-Measure-Switch): 8/4 timeslot (~1154 microseconds) (7)
367 0001 .... = (SM_VALUE) Switch-Measure: 2/4 timeslot (~288 microseconds) (1)
368 ECSD multislot class: Bits are not available (0)
369 .... ...0 = Single Slot DTM: Not supported
370 1... .... = DTM EGPRS Multi Slot Class: Present
371 .... .011 00.. .... = GPRS multislot class: Max Rx-Slot/TDMA:4 Max Tx-Slot/TDMA:4 Max-Sum-Slot/TDMA:5 Tta:2 Ttb:1 Tra:2 Trb:1 Type:1 (12)
372 ..1. .... = GPRS Extended Dynamic Allocation Capability: Implemented
373 .... ..01 100. .... = EGPRS multislot class: Max Rx-Slot/TDMA:4 Max Tx-Slot/TDMA:4 Max-Sum-Slot/TDMA:5 Tta:2 Ttb:1 Tra:2 Trb:1 Type:1 (12)
374 ...1 .... = EGPRS Extended Dynamic Allocation Capability: Implemented
375 .... .11. = DTM GPRS Multi Slot Class: Multislot class 11 supported (3)
376 .11. .... = DTM EGPRS Multi Slot Class: Multislot class 11 supported (3)
377 ...1 .... = 8PSK Power Capability Bits: Present
378 8PSK Power Capability: Power class E2 (2)
379 .... ..0. = COMPACT Interference Measurement Capability: Not Implemented
380 .... ...1 = Revision Level Indicator: The ME is Release '99 onwards
381 0... .... = UMTS FDD Radio Access Technology Capability: Not supported
382 .0.. .... = UMTS 3.84 Mcps TDD Radio Access Technology Capability: Not supported
383 ..0. .... = CDMA 2000 Radio Access Technology Capability: Not supported
384 ...0 .... = UMTS 1.28 Mcps TDD Radio Access Technology Capability: Not supported
385 .... 1... = GERAN Feature Package 1: Supported
386 Extended DTM EGPRS Multi Slot Class: Bits are not available (0)
387 .... ..0. = Modulation based multislot class support: Not supported
388 High Multislot Capability: Bits are not available (0)
389 0... .... = GERAN Iu mode: Not supported
390 GMSK Multislot Power Profile: GMSK_MULTISLOT_POWER_PROFILE 3 (3)
391 8-PSK Multislot Power Profile: 8-PSK_MULTISLOT_POWER_PROFILE 3 (3)
392 .... .0.. = Multiple TBF Capability: Not supported
393 .... ..01 = Downlink Advanced Receiver Performance: Downlink Advanced Receiver Performance - phase I supported (1)
394 1... .... = Extended RLC/MAC Control Message Segmentation Capability: Supported
395 .1.. .... = DTM Enhancements Capability: The mobile station supports enhanced DTM CS establishment and enhanced DTM CS release procedures
396 ...0 .... = PS Handover Capability: Not supported
397 MS RA capability 2
398 .... .011 1... .... = Access Technology Type: GSM 850 (7)
399 .010 0010 = Length in bits: 0x22 (34)
400 100. .... RF Power Capability, GMSK Power Class: 2 W (33 dBm) (4)
401 A5 Bits: Same values apply for parameters as in the immediately preceding Access capabilities field within this IE (0)
402 .... 1... = Controlled early Classmark Sending: Implemented
403 .... .1.. = Pseudo Synchronisation: Present
404 .... ..0. = Voice Group Call Service: no VGCS capability or no notifications wanted
405 .... ...0 = Voice Broadcast Service: no VBS capability or no notifications wanted
406 0... .... = Multislot capability struct: Not Present
407 .1.. .... = 8PSK Power Capability Bits: Present
408 8PSK Power Capability: Power class E2 (2)
409 .... 0... = COMPACT Interference Measurement Capability: Not Implemented
410 .... .1.. = Revision Level Indicator: The ME is Release '99 onwards
411 .... ..0. = UMTS FDD Radio Access Technology Capability: Not supported
412 .... ...0 = UMTS 3.84 Mcps TDD Radio Access Technology Capability: Not supported
413 0... .... = CDMA 2000 Radio Access Technology Capability: Not supported
414 .0.. .... = UMTS 1.28 Mcps TDD Radio Access Technology Capability: Not supported
415 ..1. .... = GERAN Feature Package 1: Supported
416 Extended DTM EGPRS Multi Slot Class: Bits are not available (0)
417 .... 0... = Modulation based multislot class support: Not supported
418 High Multislot Capability: Bits are not available (0)
419 .... ..0. = GERAN Iu mode: Not supported
420 GMSK Multislot Power Profile: GMSK_MULTISLOT_POWER_PROFILE 3 (3)
421 8-PSK Multislot Power Profile: 8-PSK_MULTISLOT_POWER_PROFILE 3 (3)
422 ...0 .... = Multiple TBF Capability: Not supported
423 .... 01.. = Downlink Advanced Receiver Performance: Downlink Advanced Receiver Performance - phase I supported (1)
424 .... ..1. = Extended RLC/MAC Control Message Segmentation Capability: Supported
425 .... ...1 = DTM Enhancements Capability: The mobile station supports enhanced DTM CS establishment and enhanced DTM CS release procedures
426 .0.. .... = PS Handover Capability: Not supported
427 MS RA capability 3
428 ...0 011. = Access Technology Type: GSM 1800 (3)
429 .... ...0 1000 10.. = Length in bits: 0x22 (34)
430 .... ..00 1... .... RF Power Capability, GMSK Power Class: 1 W (30 dBm) (1)
431 A5 Bits: Same values apply for parameters as in the immediately preceding Access capabilities field within this IE (0)
432 ..1. .... = Controlled early Classmark Sending: Implemented
433 ...1 .... = Pseudo Synchronisation: Present
434 .... 0... = Voice Group Call Service: no VGCS capability or no notifications wanted
435 .... .0.. = Voice Broadcast Service: no VBS capability or no notifications wanted
436 .... ..0. = Multislot capability struct: Not Present
437 .... ...1 = 8PSK Power Capability Bits: Present
438 8PSK Power Capability: Power class E2 (2)
439 ..0. .... = COMPACT Interference Measurement Capability: Not Implemented
440 ...1 .... = Revision Level Indicator: The ME is Release '99 onwards
441 .... 0... = UMTS FDD Radio Access Technology Capability: Not supported
442 .... .0.. = UMTS 3.84 Mcps TDD Radio Access Technology Capability: Not supported
443 .... ..0. = CDMA 2000 Radio Access Technology Capability: Not supported
444 .... ...0 = UMTS 1.28 Mcps TDD Radio Access Technology Capability: Not supported
445 1... .... = GERAN Feature Package 1: Supported
446 Extended DTM EGPRS Multi Slot Class: Bits are not available (0)
447 ..0. .... = Modulation based multislot class support: Not supported
448 High Multislot Capability: Bits are not available (0)
449 .... 0... = GERAN Iu mode: Not supported
450 GMSK Multislot Power Profile: GMSK_MULTISLOT_POWER_PROFILE 3 (3)
451 8-PSK Multislot Power Profile: 8-PSK_MULTISLOT_POWER_PROFILE 3 (3)
452 .0.. .... = Multiple TBF Capability: Not supported
453 ..01 .... = Downlink Advanced Receiver Performance: Downlink Advanced Receiver Performance - phase I supported (1)
454 .... 1... = Extended RLC/MAC Control Message Segmentation Capability: Supported
455 .... .1.. = DTM Enhancements Capability: The mobile station supports enhanced DTM CS establishment and enhanced DTM CS release procedures
456 .... ...0 = PS Handover Capability: Not supported
457*/
458 bitvec_unhex(bv_dec, "1933432b37159ef90879cba28c6421e72688b190879c00");
459
460 printf("=== Test decoding of multi-band MS RA Capability ===\n");
461 rc = decode_gsm_ra_cap(bv_dec, &data);
Pau Espin Pedrol7faa5da2020-03-21 00:13:33 +0100462 printf("decode_gsm_ra_cap() returns %d\n", rc);
463 OSMO_ASSERT(rc == 0);
464
465 /* Make sure there's 3 values */
Pau Espin Pedrolefad80b2020-03-23 14:35:26 +0100466 OSMO_ASSERT(data.Count_MS_RA_capability_value == 3);
467
468 /* Make sure GPRS / EGPRS multislot class is parsed correctly */
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +0100469 printf("GPRS multislot class = %u\n", get_ms_class_by_capability(&data));
470 printf("EGPRS multislot class = %u\n", get_egprs_ms_class_by_capability(&data));
Pau Espin Pedrol7faa5da2020-03-21 00:13:33 +0100471
Pau Espin Pedrolefad80b2020-03-23 14:35:26 +0100472 bitvec_free(bv_dec);
473}
474
Vadim Yanitskiya2d972a2020-04-04 03:44:35 +0700475void testEGPRSPktChReq(void *test_ctx)
476{
477 EGPRS_PacketChannelRequest_t req;
478 int rc;
479
480 printf("*** %s ***\n", __func__);
481
482 static const uint16_t EGPRSPktChReqs[] = {
483 /* < One Phase Access Request : '0'B
484 < MultislotClass : '10101'B >
485 < Priority : '10'B >
486 < RandomBits : '101'B > > */
487 0x2b5,
488 /* < One Phase Access Request : '0'B
489 < MultislotClass : '01010'B >
490 < Priority : '01'B >
491 < RandomBits : '010'B > > */
492 0x14a,
493 /* < Short Access Request : '100'B
494 < NumberOfBlocks : '001'B >
495 < Priority : '01'B >
496 < RandomBits : '000'B > > */
497 0x428,
498 /* < Two Phase Access Request : '110000'B
499 < Priority : '00'B >
500 < RandomBits : '000'B > > */
501 0x600,
502 /* < Two Phase Access Request : '110000'B
503 < Priority : '11'B >
504 < RandomBits : '111'B > > */
505 0x61f,
506 /* < Signalling : '110011'B
507 < RandomBits : '10101'B > > */
508 0x675,
509 /* < Signalling : '110011'B
510 < RandomBits : '10001'B > > */
511 0x671,
512 /* < Emergency call : '110111'B
513 < RandomBits : '11001'B > > */
514 0x6f9,
515 /* < Unknown (test) : '111111'B
516 < RandomBits : '01010'B > > */
517 0x7ea,
518 };
519
520 for (size_t i = 0; i < ARRAY_SIZE(EGPRSPktChReqs); i++) {
521 rc = decode_egprs_pkt_ch_req(EGPRSPktChReqs[i], &req);
522 printf("decode_egprs_pkt_ch_req(0x%03x) returns %d\n", EGPRSPktChReqs[i], rc);
523 if (rc == 0)
524 printf(" ==> %s\n", get_value_string(egprs_pkt_ch_req_type_names, req.Type));
525 }
526}
527
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300528int main(int argc, char *argv[])
529{
Alexander Couzensccde5c92017-02-04 03:10:08 +0100530 void *ctx = talloc_named_const(NULL, 1, "RLCMACTest");
Neels Hofmeyr42f2d612018-04-01 16:54:40 +0200531 osmo_init_logging2(ctx, &gprs_log_info);
Harald Welte570f9132020-03-19 15:03:01 +0100532 log_parse_category_mask(osmo_stderr_target, "DPCU,3:DLGLOBAL,1:DRLCMACDATA,2:DCSN1,1:");
Vadim Yanitskiy8a87f912020-02-17 01:19:10 +0700533
534 log_set_print_filename2(osmo_stderr_target, LOG_FILENAME_NONE);
535 log_set_print_category_hex(osmo_stderr_target, 0);
536 log_set_print_category(osmo_stderr_target, 1);
537 log_set_print_level(osmo_stderr_target, 1);
538 log_set_use_color(osmo_stderr_target, 0);
Andreas Eversberg138f4e62013-01-14 12:31:11 +0100539
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300540 //printSizeofRLCMAC();
Alexander Couzensccde5c92017-02-04 03:10:08 +0100541 testRlcMacDownlink(ctx);
542 testRlcMacUplink(ctx);
543 testCsnLeftAlignedVarBmpBounds(ctx);
Pau Espin Pedrolcdbc5db2020-01-23 21:00:19 +0100544 testRAcap(ctx);
Pau Espin Pedrol866bece2020-03-21 01:20:52 +0100545 testMalformedRAcap(ctx);
Pau Espin Pedrolefad80b2020-03-23 14:35:26 +0100546 testRAcap2(ctx);
Vadim Yanitskiya2d972a2020-04-04 03:44:35 +0700547
548 testEGPRSPktChReq(ctx);
549
Alexander Couzensccde5c92017-02-04 03:10:08 +0100550 talloc_free(ctx);
Ivan Kluchnikov487a1412011-12-21 13:17:53 +0300551}