Handle packet access reject during EPDAN/PDAN with channel description

When PDAN/EPDAN with channel description is received, PCU will generate the
packet access reject if no resources are present. The encoding is done
based on section 7.1.3.2.1 and 8.1.2.5 of 44.060 version 7.27.0 Release 7.
This patch also includes the test case to validate the generated
packet access reject message.

This patch is integration tested on Osmo-trx setup with Ettus B210 board
and LG F70 MS with some simulation code changes in Osmo-pcu.

Change-Id: I096a3bb44a65533b9e9b091925dd5f70a8696d6
diff --git a/tests/tbf/TbfTest.cpp b/tests/tbf/TbfTest.cpp
index 339390b..213bd12 100644
--- a/tests/tbf/TbfTest.cpp
+++ b/tests/tbf/TbfTest.cpp
@@ -2831,6 +2831,29 @@
 	ARRAY_SIZE(default_categories),
 };
 
+void test_packet_access_rej_epdan()
+{
+	BTS the_bts;
+	uint32_t tlli = 0xffeeddcc;
+
+	printf("=== start %s ===\n", __func__);
+	setup_bts(&the_bts, 4);
+	static gprs_rlcmac_dl_tbf *dl_tbf = tbf_init(&the_bts, 1);
+
+	dl_tbf->update_ms(tlli, GPRS_RLCMAC_DL_TBF);
+
+	struct msgb *msg = dl_tbf->create_packet_access_reject();
+
+	printf("packet reject: %s\n",
+			osmo_hexdump(msg->data, 23));
+
+	OSMO_ASSERT(!strcmp(osmo_hexdump(msg->data, 23),
+			    "40 84 7f f7 6e e6 41 4b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b "));
+	printf("=== end %s ===\n", __func__);
+
+}
+
+
 int main(int argc, char **argv)
 {
 	struct vty_app_info pcu_vty_info = {0};
@@ -2874,6 +2897,7 @@
 	test_tbf_li_decoding();
 	test_tbf_epdan_out_of_rx_window();
 	test_immediate_assign_rej();
+	test_packet_access_rej_epdan();
 
 	if (getenv("TALLOC_REPORT_FULL"))
 		talloc_report_full(tall_pcu_ctx, stderr);
diff --git a/tests/tbf/TbfTest.err b/tests/tbf/TbfTest.err
index 627cdc3..a680812 100644
--- a/tests/tbf/TbfTest.err
+++ b/tests/tbf/TbfTest.err
@@ -6846,3 +6846,27 @@
 No PDCH available.
 No PDCH resource for single block allocation.sending Immediate Assignment Uplink (AGCH) reject
 Sending data request: trx=0 ts=0 sapi=2 arfcn=0 fn=0 block=0 data=4d 06 3a 10 70 8b 29 14 70 8b 29 14 70 8b 29 14 70 8b 29 14 0b 2b 2b 
+Searching for first unallocated TFI: TRX=0
+ Found TFI=0.
+********** TBF starts here **********
+Allocating DL TBF: MS_CLASS=11/11
+Creating MS object, TLLI = 0x00000000
+Modifying MS object, TLLI = 0x00000000, MS class 0 -> 11
+Modifying MS object, TLLI = 0x00000000, EGPRS MS class 0 -> 11
+Slot Allocation (Algorithm A) for class 11
+- Skipping TS 0, because not enabled
+- Skipping TS 1, because not enabled
+- Skipping TS 2, because not enabled
+- Skipping TS 3, because not enabled
+- Skipping TS 5, because not enabled
+- Skipping TS 6, because not enabled
+- Skipping TS 7, because not enabled
+- Assign downlink TS=4 TFI=0
+PDCH(TS 4, TRX 0): Attaching TBF(TFI=0 TLLI=0x00000000 DIR=DL STATE=NULL), 1 TBFs, USFs = 00, TFIs = 00000001.
+- Setting Control TS 4
+Attaching TBF to MS object, TLLI = 0x00000000, TBF = TBF(TFI=0 TLLI=0x00000000 DIR=DL STATE=NULL)
+Allocated TBF(TFI=0 TLLI=0x00000000 DIR=DL STATE=NULL): trx = 0, ul_slots = 10, dl_slots = 10
+Modifying MS object, TLLI = 0x00000000, TA 220 -> 0
+TBF(TFI=0 TLLI=0x00000000 DIR=DL STATE=NULL) changes state from NULL to FLOW
+The MS object cannot fully confirm an unexpected TLLI: 0xffeeddcc, partly confirmed
+TBF(TFI=0 TLLI=0xffeeddcc DIR=DL STATE=FLOW) append
diff --git a/tests/tbf/TbfTest.ok b/tests/tbf/TbfTest.ok
index f921dfc..dc07fc7 100644
--- a/tests/tbf/TbfTest.ok
+++ b/tests/tbf/TbfTest.ok
@@ -72,3 +72,6 @@
 === end test_immediate_assign_rej_multi_block ===
 === start test_immediate_assign_rej_single_block ===
 === end test_immediate_assign_rej_single_block ===
+=== start test_packet_access_rej_epdan ===
+packet reject: 40 84 7f f7 6e e6 41 4b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 2b 
+=== end test_packet_access_rej_epdan ===