layer23: Move app logic in layer3.c with state struct.
authorSylvain Munaut <tnt@246tNt.com>
Sun, 1 Aug 2010 09:56:17 +0000 (11:56 +0200)
committerSylvain Munaut <tnt@246tNt.com>
Tue, 14 Sep 2010 19:21:42 +0000 (21:21 +0200)
It's far from perfect but at least it's not split in two file and
makes it easier to expand the logic.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
src/host/layer23/include/osmocom/bb/misc/layer3.h
src/host/layer23/src/misc/app_phone.c
src/host/layer23/src/misc/layer3.c
src/host/layer23/src/misc/rslms.c

index dc7da87..7d364e7 100644 (file)
@@ -11,4 +11,7 @@ int gsm48_rx_bcch(struct msgb *msg, struct osmocom_ms *ms);
 /* Initialize layer3 for the MS, hook it to L2 */
 int layer3_init(struct osmocom_ms *ms);
 
+/* Reset the 'aplication' state */
+void layer3_app_reset(void);
+
 #endif
index bdb9b79..6b2c928 100644 (file)
@@ -43,6 +43,7 @@ static int signal_cb(unsigned int subsys, unsigned int signal,
        switch (signal) {
        case S_L1CTL_RESET:
                ms = signal_data;
+               layer3_app_reset();
                return l1ctl_tx_fbsb_req(ms, ms->test_arfcn,
                                         L1CTL_FBSB_F_FB01SB, 100, 0,
                                         CCCH_MODE_NONE);
index 69f558d..3ba4734 100644 (file)
 #include <osmocom/bb/common/osmocom_data.h>
 #include <osmocom/bb/common/l1ctl.h>
 
-static int ccch_mode = CCCH_MODE_NONE;
+static struct {
+       int ccch_mode;
+       int ccch_enabled;
+       int rach_count;
+} app_state;
+
 
 static void dump_bcch(struct osmocom_ms *ms, uint8_t tc, const uint8_t *data)
 {
@@ -43,16 +48,16 @@ static void dump_bcch(struct osmocom_ms *ms, uint8_t tc, const uint8_t *data)
                if (tc != 2 && tc != 6)
                        fprintf(stderr, " on wrong TC");
 #endif
-               if (ccch_mode == CCCH_MODE_NONE) {
+               if (app_state.ccch_mode == CCCH_MODE_NONE) {
                        struct gsm48_system_information_type_3 *si3 =
                                (struct gsm48_system_information_type_3 *)data;
 
                        if (si3->control_channel_desc.ccch_conf == RSL_BCCH_CCCH_CONF_1_C)
-                               ccch_mode = CCCH_MODE_COMBINED;
+                               app_state.ccch_mode = CCCH_MODE_COMBINED;
                        else
-                               ccch_mode = CCCH_MODE_NON_COMBINED;
+                               app_state.ccch_mode = CCCH_MODE_NON_COMBINED;
 
-                       l1ctl_tx_ccch_mode_req(ms, ccch_mode);
+                       l1ctl_tx_ccch_mode_req(ms, app_state.ccch_mode);
                }
                break;
        case GSM48_MT_RR_SYSINFO_4:
@@ -231,5 +236,21 @@ int gsm48_rx_bcch(struct msgb *msg, struct osmocom_ms *ms)
        //dump_bcch(dl->time.tc, ccch->data);
        dump_bcch(ms, 0, msg->l3h);
 
+       /* Req channel logic */
+       if (app_state.ccch_enabled && (app_state.rach_count < 2)) {
+               l1ctl_tx_rach_req(ms, app_state.rach_count,
+                       app_state.ccch_mode == CCCH_MODE_COMBINED ? 27 : 51, 0);
+               app_state.rach_count++;
+       }
+
        return 0;
 }
+
+void layer3_app_reset(void)
+{
+       /* Reset state */
+       app_state.ccch_mode = CCCH_MODE_NONE;
+       app_state.ccch_enabled = 0;
+       app_state.rach_count = 0;
+}
+
index 7231fda..b2e0047 100644 (file)
@@ -56,9 +56,6 @@ int rslms_tx_rll_req_l3(struct osmocom_ms *ms, uint8_t msg_type,
        return rslms_recvmsg(msg, ms);
 }
 
-static int ccch_enabled = 0;
-static int rach_count = 0;
-
 static int rslms_rx_udata_ind(struct msgb *msg, struct osmocom_ms *ms)
 {
        struct abis_rsl_rll_hdr *rllh = msgb_l2(msg);
@@ -77,13 +74,8 @@ static int rslms_rx_udata_ind(struct msgb *msg, struct osmocom_ms *ms)
 
        if (rllh->chan_nr == RSL_CHAN_PCH_AGCH) {
                rc = gsm48_rx_ccch(msg, ms);
-               ccch_enabled = 1;
        } else if (rllh->chan_nr == RSL_CHAN_BCCH) {
                rc = gsm48_rx_bcch(msg, ms);
-               if (ccch_enabled && (rach_count < 2)) {
-                       l1ctl_tx_rach_req(ms, rach_count, 27, 0);
-                       rach_count++;
-               }
        }
 
        return rc;