edge: Support EGPRS multislot class handling in tbf_alloc

Add an egprs_ms_class argument to the allocation functions and
set/pass it where necessary.

Sponsored-by: On-Waves ehf
diff --git a/src/bts.cpp b/src/bts.cpp
index 26077c2..0e3e8f0 100644
--- a/src/bts.cpp
+++ b/src/bts.cpp
@@ -491,7 +491,7 @@
 		// Create new TBF
 		#warning "Copy and pate with other routines.."
 		/* set class to 0, since we don't know the multislot class yet */
-		tbf = tbf_alloc_ul_tbf(&m_bts, NULL, -1, 0, 1);
+		tbf = tbf_alloc_ul_tbf(&m_bts, NULL, -1, 0, 0, 1);
 		if (!tbf) {
 			LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
 			/* FIXME: send reject */
@@ -580,13 +580,14 @@
 }
 
 
-GprsMs *BTS::ms_alloc(uint8_t ms_class)
+GprsMs *BTS::ms_alloc(uint8_t ms_class, uint8_t egprs_ms_class)
 {
 	GprsMs *ms;
 	ms = ms_store().create_ms();
 
 	ms->set_timeout(m_bts.ms_idle_sec);
 	ms->set_ms_class(ms_class);
+	ms->set_egprs_ms_class(egprs_ms_class);
 
 	return ms;
 }
@@ -968,7 +969,8 @@
 			"message, so we provide one:\n");
 
 		/* This call will register the new TBF with the MS on success */
-		tbf_alloc_ul(bts_data(), tbf->trx->trx_no, tbf->ms_class(),
+		tbf_alloc_ul(bts_data(), tbf->trx->trx_no,
+			tbf->ms_class(), tbf->ms()->egprs_ms_class(),
 			tbf->tlli(), tbf->ta(), tbf->ms());
 
 		/* schedule uplink assignment */
@@ -1053,7 +1055,8 @@
 			LOGP(DRLCMAC, LOGL_NOTICE,
 				"MS supports EGPRS multislot class %d.\n",
 				egprs_ms_class);
-		ul_tbf = tbf_alloc_ul(bts_data(), trx_no(), ms_class, tlli, ta, ms);
+		ul_tbf = tbf_alloc_ul(bts_data(), trx_no(), ms_class,
+			egprs_ms_class, tlli, ta, ms);
 		if (!ul_tbf)
 			return;
 
diff --git a/src/bts.h b/src/bts.h
index 002d450..8831aca 100644
--- a/src/bts.h
+++ b/src/bts.h
@@ -275,7 +275,7 @@
 	GprsMsStorage &ms_store();
 	GprsMs *ms_by_tlli(uint32_t tlli, uint32_t old_tlli = 0);
 	GprsMs *ms_by_imsi(const char *imsi);
-	GprsMs *ms_alloc(uint8_t ms_class);
+	GprsMs *ms_alloc(uint8_t ms_class, uint8_t egprs_ms_class = 0);
 
 	/*
 	 * Statistics
diff --git a/src/tbf.cpp b/src/tbf.cpp
index 0fc6edf..2d0aa9f 100644
--- a/src/tbf.cpp
+++ b/src/tbf.cpp
@@ -271,7 +271,7 @@
 }
 
 gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
-	int8_t use_trx, uint8_t ms_class,
+	int8_t use_trx, uint8_t ms_class, uint8_t egprs_ms_class,
 	uint32_t tlli, uint8_t ta, GprsMs *ms)
 {
 	struct gprs_rlcmac_ul_tbf *tbf;
@@ -279,7 +279,7 @@
 #warning "Copy and paste with tbf_new_dl_assignment"
 	/* create new TBF, use same TRX as DL TBF */
 	/* use multislot class of downlink TBF */
-	tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, ms_class, 0);
+	tbf = tbf_alloc_ul_tbf(bts, ms, use_trx, ms_class, egprs_ms_class, 0);
 	if (!tbf) {
 		LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
 		/* FIXME: send reject */
@@ -537,7 +537,7 @@
 
 static int setup_tbf(struct gprs_rlcmac_tbf *tbf,
 	GprsMs *ms, int8_t use_trx,
-	uint8_t ms_class, uint8_t single_slot)
+	uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
 {
 	int rc;
 	struct gprs_rlcmac_bts *bts;
@@ -594,14 +594,14 @@
 
 struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
 	GprsMs *ms, int8_t use_trx,
-	uint8_t ms_class, uint8_t single_slot)
+	uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
 {
 	struct gprs_rlcmac_ul_tbf *tbf;
 	int rc;
 
 	LOGP(DRLCMAC, LOGL_DEBUG, "********** TBF starts here **********\n");
-	LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d\n",
-		"UL", ms_class);
+	LOGP(DRLCMAC, LOGL_INFO, "Allocating %s TBF: MS_CLASS=%d/%d\n",
+		"UL", ms_class, egprs_ms_class);
 
 	tbf = talloc(tall_pcu_ctx, struct gprs_rlcmac_ul_tbf);
 
@@ -612,9 +612,9 @@
 	new (tbf) gprs_rlcmac_ul_tbf(bts->bts);
 
 	if (!ms)
-		ms = bts->bts->ms_alloc(ms_class);
+		ms = bts->bts->ms_alloc(ms_class, egprs_ms_class);
 
-	rc = setup_tbf(tbf, ms, use_trx, ms_class, single_slot);
+	rc = setup_tbf(tbf, ms, use_trx, ms_class, egprs_ms_class, single_slot);
 	/* if no resource */
 	if (rc < 0) {
 		talloc_free(tbf);
@@ -656,7 +656,7 @@
 
 struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
 	GprsMs *ms, int8_t use_trx,
-	uint8_t ms_class, uint8_t single_slot)
+	uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot)
 {
 	struct gprs_rlcmac_dl_tbf *tbf;
 	int rc;
@@ -674,9 +674,9 @@
 	new (tbf) gprs_rlcmac_dl_tbf(bts->bts);
 
 	if (!ms)
-		ms = bts->bts->ms_alloc(ms_class);
+		ms = bts->bts->ms_alloc(ms_class, egprs_ms_class);
 
-	rc = setup_tbf(tbf, ms, use_trx, ms_class, single_slot);
+	rc = setup_tbf(tbf, ms, use_trx, ms_class, 0, single_slot);
 	/* if no resource */
 	if (rc < 0) {
 		talloc_free(tbf);
@@ -971,7 +971,8 @@
 	bts->tbf_reused();
 
 	new_tbf = tbf_alloc_dl_tbf(bts->bts_data(), ms(),
-		this->trx->trx_no, ms_class(), 0);
+		this->trx->trx_no, ms_class(),
+		ms() ?  ms()->egprs_ms_class() : 0, 0);
 
 	if (!new_tbf) {
 		LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
diff --git a/src/tbf.h b/src/tbf.h
index 43da206..9775397 100644
--- a/src/tbf.h
+++ b/src/tbf.h
@@ -258,16 +258,16 @@
 
 
 struct gprs_rlcmac_ul_tbf *tbf_alloc_ul(struct gprs_rlcmac_bts *bts,
-	int8_t use_trx, uint8_t ms_class,
+	int8_t use_trx, uint8_t ms_class, uint8_t egprs_ms_class,
 	uint32_t tlli, uint8_t ta, GprsMs *ms);
 
 struct gprs_rlcmac_ul_tbf *tbf_alloc_ul_tbf(struct gprs_rlcmac_bts *bts,
 	GprsMs *ms, int8_t use_trx,
-	uint8_t ms_class, uint8_t single_slot);
+	uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot);
 
 struct gprs_rlcmac_dl_tbf *tbf_alloc_dl_tbf(struct gprs_rlcmac_bts *bts,
 	GprsMs *ms, int8_t use_trx,
-	uint8_t ms_class, uint8_t single_slot);
+	uint8_t ms_class, uint8_t egprs_ms_class, uint8_t single_slot);
 
 void tbf_free(struct gprs_rlcmac_tbf *tbf);
 
diff --git a/src/tbf_dl.cpp b/src/tbf_dl.cpp
index 64fbef4..d07f323 100644
--- a/src/tbf_dl.cpp
+++ b/src/tbf_dl.cpp
@@ -128,6 +128,7 @@
 				const char *imsi,
 				const uint32_t tlli, const uint32_t tlli_old,
 				const uint8_t ms_class,
+				const uint8_t egprs_ms_class,
 				struct gprs_rlcmac_dl_tbf **tbf)
 {
 	uint8_t ss;
@@ -161,7 +162,7 @@
 	// Create new TBF (any TRX)
 #warning "Copy and paste with alloc_ul_tbf"
 	/* set number of downlink slots according to multislot class */
-	dl_tbf = tbf_alloc_dl_tbf(bts, ms, use_trx, ms_class, ss);
+	dl_tbf = tbf_alloc_dl_tbf(bts, ms, use_trx, ms_class, egprs_ms_class, ss);
 
 	if (!dl_tbf) {
 		LOGP(DRLCMAC, LOGL_NOTICE, "No PDCH resource\n");
@@ -235,8 +236,8 @@
 	}
 
 	if (!dl_tbf) {
-		rc = tbf_new_dl_assignment(bts, imsi, tlli, tlli_old, ms_class,
-			&dl_tbf);
+		rc = tbf_new_dl_assignment(bts, imsi, tlli, tlli_old,
+			ms_class, 0, &dl_tbf);
 		if (rc < 0)
 			return rc;
 	}