This patch adds a common function bts_ccch_copy_msg() that provides
and schedules AGCH and PCH messages. It is basically a frontend to
paging_gen_msg() and bts_agch_dequeue() and contains refactored code
from l1_if.c.

Sponsored-by: On-Waves ehf
---
 include/osmo-bts/bts.h     |    2 ++
 src/common/bts.c           |   22 ++++++++++++++++++++++
 src/osmo-bts-sysmo/l1_if.c |   17 ++++-------------
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/include/osmo-bts/bts.h b/include/osmo-bts/bts.h
index e202035..49ef617 100644
--- a/include/osmo-bts/bts.h
+++ b/include/osmo-bts/bts.h
@@ -26,6 +26,8 @@ void bts_setup_slot(struct gsm_bts_trx_ts *slot, uint8_t 
comb);
 
 int bts_agch_enqueue(struct gsm_bts *bts, struct msgb *msg);
 struct msgb *bts_agch_dequeue(struct gsm_bts *bts);
+int bts_ccch_copy_msg(struct gsm_bts *bts, uint8_t *out_buf, struct gsm_time 
*gt,
+                     int is_ag_res);
 
 uint8_t *bts_sysinfo_get(struct gsm_bts *bts, struct gsm_time *g_time);
 uint8_t *lchan_sacch_get(struct gsm_lchan *lchan, struct gsm_time *g_time);
diff --git a/src/common/bts.c b/src/common/bts.c
index 35fc302..7bbf587 100644
--- a/src/common/bts.c
+++ b/src/common/bts.c
@@ -231,6 +231,28 @@ struct msgb *bts_agch_dequeue(struct gsm_bts *bts)
        return msg;
 }
 
+int bts_ccch_copy_msg(struct gsm_bts *bts, uint8_t *out_buf, struct gsm_time 
*gt,
+                     int is_ag_res)
+{
+       struct msgb *msg;
+       struct gsm_bts_role_bts *btsb = bts->role;
+       int rc;
+
+       if (!is_ag_res)
+               return paging_gen_msg(btsb->paging_state, out_buf, gt);
+
+       /* special queue of messages from IMM ASS CMD */
+       msg = bts_agch_dequeue(bts);
+       if (!msg)
+               return 0;
+
+       memcpy(out_buf, msgb_l3(msg), msgb_l3len(msg));
+       rc = msgb_l3len(msg);
+       msgb_free(msg);
+
+       return rc;
+}
+
 int bts_supports_cipher(struct gsm_bts_role_bts *bts, int rsl_cipher)
 {
        int sup;
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index 39c020b..ba34c69 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -373,7 +373,6 @@ static int handle_ph_readytosend_ind(struct femtol1_hdl 
*fl1,
 {
        struct gsm_bts_trx *trx = fl1->priv;
        struct gsm_bts *bts = trx->bts;
-       struct gsm_bts_role_bts *btsb = bts->role;
        struct msgb *resp_msg;
        GsmL1_PhDataReq_t *data_req;
        GsmL1_MsgUnitParam_t *msu_param;
@@ -513,19 +512,11 @@ static int handle_ph_readytosend_ind(struct femtol1_hdl 
*fl1,
                }
                break;
        case GsmL1_Sapi_Agch:
-               /* special queue of messages from IMM ASS CMD */
-               {
-                       struct msgb *msg = bts_agch_dequeue(bts);
-                       if (!msg)
-                               memcpy(msu_param->u8Buffer, fill_frame, 
GSM_MACBLOCK_LEN);
-                       else {
-                               memcpy(msu_param->u8Buffer, msgb_l3(msg), 
msgb_l3len(msg));
-                               msgb_free(msg);
-                       }
-               }
-               break;
        case GsmL1_Sapi_Pch:
-               rc = paging_gen_msg(btsb->paging_state, msu_param->u8Buffer, 
&g_time);
+               rc = bts_ccch_copy_msg(bts, msu_param->u8Buffer, &g_time,
+                                      rts_ind->sapi == GsmL1_Sapi_Agch);
+               if (rc <= 0)
+                       memcpy(msu_param->u8Buffer, fill_frame, 
GSM_MACBLOCK_LEN);
                break;
        case GsmL1_Sapi_TchF:
        case GsmL1_Sapi_TchH:
-- 
1.7.9.5


Reply via email to