lynxis lazus has submitted this change. ( 
https://gerrit.osmocom.org/c/libosmocore/+/25558 )

Change subject: ns2: correct parse a BLOCK PDU which was received over a 
different NSVC
......................................................................

ns2: correct parse a BLOCK PDU which was received over a different NSVC

BLOCK PDU can be send over a different NSVC than the NSVC.
E.g. informing a NSVC got blocked in case of a lower-layer failure.

Change-Id: I483e3a1d3b8c43bbb0cc6185b7f7f772bcb264bf
---
M src/gb/gprs_ns2_vc_fsm.c
1 file changed, 36 insertions(+), 10 deletions(-)

Approvals:
  daniel: Looks good to me, approved
  pespin: Looks good to me, but someone else must approve
  Jenkins Builder: Verified



diff --git a/src/gb/gprs_ns2_vc_fsm.c b/src/gb/gprs_ns2_vc_fsm.c
index d28897e..1db2a8e 100644
--- a/src/gb/gprs_ns2_vc_fsm.c
+++ b/src/gb/gprs_ns2_vc_fsm.c
@@ -118,6 +118,7 @@
        GPRS_NS2_EV_REQ_OM_RESET,               /* vty cmd: reset */
        GPRS_NS2_EV_REQ_OM_BLOCK,               /* vty cmd: block */
        GPRS_NS2_EV_REQ_OM_UNBLOCK,             /* vty cmd: unblock*/
+       GPRS_NS2_EV_RX_BLOCK_FOREIGN,           /* received a BLOCK over 
another NSVC */
 };

 static const struct value_string ns2_vc_event_names[] = {
@@ -127,6 +128,7 @@
        { GPRS_NS2_EV_RX_UNBLOCK,               "RX-UNBLOCK" },
        { GPRS_NS2_EV_RX_UNBLOCK_ACK,           "RX-UNBLOCK_ACK" },
        { GPRS_NS2_EV_RX_BLOCK,                 "RX-BLOCK" },
+       { GPRS_NS2_EV_RX_BLOCK_FOREIGN,         "RX-BLOCK_FOREIGN" },
        { GPRS_NS2_EV_RX_BLOCK_ACK,             "RX-BLOCK_ACK" },
        { GPRS_NS2_EV_RX_ALIVE,                 "RX-ALIVE" },
        { GPRS_NS2_EV_RX_ALIVE_ACK,             "RX-ALIVE_ACK" },
@@ -368,8 +370,12 @@
                        osmo_timer_del(&fi->timer);
                        break;
                case GPRS_NS2_EV_RX_BLOCK:
-                       priv->accept_unitdata = false;
                        ns2_tx_block_ack(priv->nsvc, NULL);
+                       /* fall through */
+               case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
+                       /* the BLOCK ACK for foreign BLOCK PDUs (rx over 
another nsvc) will be sent
+                        * from the receiving nsvc */
+                       priv->accept_unitdata = false;
                        osmo_timer_del(&fi->timer);
                        break;
                case GPRS_NS2_EV_RX_UNBLOCK:
@@ -380,6 +386,9 @@
                }
        } else if (priv->initiate_block) {
                switch (event) {
+               case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
+                       /* the block ack will be sent by the rx NSVC */
+                       break;
                case GPRS_NS2_EV_RX_BLOCK:
                        /* TODO: BLOCK is a UNBLOCK_NACK */
                        ns2_tx_block_ack(priv->nsvc, NULL);
@@ -396,6 +405,9 @@
        } else {
                /* we are on the receiving end. The initiator who sent RESET is 
responsible to UNBLOCK! */
                switch (event) {
+               case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
+                       /* the block ack will be sent by the rx NSVC */
+                       break;
                case GPRS_NS2_EV_RX_BLOCK:
                        ns2_tx_block_ack(priv->nsvc, NULL);
                        break;
@@ -439,9 +451,13 @@
                ns2_tx_unblock_ack(priv->nsvc);
                break;
        case GPRS_NS2_EV_RX_BLOCK:
+               ns2_tx_block_ack(priv->nsvc, NULL);
+               /* fall through */
+       case GPRS_NS2_EV_RX_BLOCK_FOREIGN:
+               /* the BLOCK ACK for foreign BLOCK PDUs (rx over another nsvc) 
will be sent
+                * from the receiving nsvc */
                priv->initiate_block = false;
                priv->accept_unitdata = false;
-               ns2_tx_block_ack(priv->nsvc, NULL);
                osmo_fsm_inst_state_chg(fi, GPRS_NS2_ST_BLOCKED,
                                        0, 2);
                break;
@@ -493,7 +509,8 @@
        },
        [GPRS_NS2_ST_BLOCKED] = {
                .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | 
S(GPRS_NS2_EV_RX_BLOCK_ACK) |
-               S(GPRS_NS2_EV_RX_UNBLOCK) | S(GPRS_NS2_EV_RX_UNBLOCK_ACK),
+                                S(GPRS_NS2_EV_RX_UNBLOCK) | 
S(GPRS_NS2_EV_RX_UNBLOCK_ACK) |
+                                S(GPRS_NS2_EV_RX_BLOCK_FOREIGN),
                .out_state_mask = S(GPRS_NS2_ST_RESET) |
                                  S(GPRS_NS2_ST_UNBLOCKED) |
                                  S(GPRS_NS2_ST_BLOCKED) |
@@ -504,7 +521,7 @@
        },
        [GPRS_NS2_ST_UNBLOCKED] = {
                .in_event_mask = S(GPRS_NS2_EV_RX_BLOCK) | 
S(GPRS_NS2_EV_RX_UNBLOCK_ACK) |
-                                S(GPRS_NS2_EV_RX_UNBLOCK),
+                                S(GPRS_NS2_EV_RX_UNBLOCK) | 
S(GPRS_NS2_EV_RX_BLOCK_FOREIGN),
                .out_state_mask = S(GPRS_NS2_ST_RESET) | 
S(GPRS_NS2_ST_RECOVERING) |
                                  S(GPRS_NS2_ST_BLOCKED) |
                                  S(GPRS_NS2_ST_UNCONFIGURED),
@@ -889,20 +906,24 @@
                                ns2_tx_reset_ack(nsvc);
                                LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, 
LOGL_ERROR, " with wrong NSVCI (exp: %05u, got %05u). Ignoring PDU.\n", 
nsvc->nsvci, nsvci);
                                goto out;
-                       } else if (nsh->pdu_type == NS_PDUT_STATUS) {
-                               /* this is a PDU received over a NSVC and 
reports a status for another NSVC */
+                       } else if (nsh->pdu_type == NS_PDUT_BLOCK || 
nsh->pdu_type == NS_PDUT_STATUS) {
+                               /* this is a PDU received over a NSVC and 
reports a status/block for another NSVC */
                                target_nsvc = 
gprs_ns2_nsvc_by_nsvci(nsvc->nse->nsi,  nsvci);
                                if (!target_nsvc) {
-                                       LOGPFSML(fi, LOGL_ERROR, "Received a 
STATUS PDU for unknown NSVC (NSVCI %d)\n", nsvci);
+                                       LOGPFSML(fi, LOGL_ERROR, "Received a %s 
PDU for unknown NSVC (NSVCI %d)\n",
+                                                
get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci);
+                                       if (nsh->pdu_type == NS_PDUT_BLOCK)
+                                               ns2_tx_status(nsvc, 
NS_CAUSE_NSVC_UNKNOWN, 0, msg, &nsvci);
                                        goto out;
                                }

                                if (target_nsvc->nse != nsvc->nse) {
-                                       LOGPFSML(fi, LOGL_ERROR, "Received a 
STATUS PDU for a NSVC (NSVCI %d) but it belongs to a different NSE!\n", nsvci);
+                                       LOGPFSML(fi, LOGL_ERROR, "Received a %s 
PDU for a NSVC (NSVCI %d) but it belongs to a different NSE!\n",
+                                                
get_value_string(gprs_ns_pdu_strings, nsh->pdu_type), nsvci);
                                        goto out;
                                }

-                               /* the status will be passed to the nsvc/target 
nsvc in the switch */
+                               /* the status/block will be passed to the 
nsvc/target nsvc in the switch */
                        } else {
                                LOG_NS_SIGNAL(nsvc, "Rx", nsh->pdu_type, 
LOGL_ERROR, " with wrong NSVCI=%05u. Ignoring PDU.\n", nsvci);
                                goto out;
@@ -918,7 +939,12 @@
                osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_RESET_ACK, tp);
                break;
        case NS_PDUT_BLOCK:
-               osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK, tp);
+               if (target_nsvc != nsvc) {
+                       osmo_fsm_inst_dispatch(target_nsvc->fi, 
GPRS_NS2_EV_RX_BLOCK_FOREIGN, tp);
+                       ns2_tx_block_ack(nsvc, &nsvci);
+               } else {
+                       osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK, tp);
+               }
                break;
        case NS_PDUT_BLOCK_ACK:
                osmo_fsm_inst_dispatch(fi, GPRS_NS2_EV_RX_BLOCK_ACK, tp);

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/25558
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I483e3a1d3b8c43bbb0cc6185b7f7f772bcb264bf
Gerrit-Change-Number: 25558
Gerrit-PatchSet: 5
Gerrit-Owner: lynxis lazus <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <[email protected]>
Gerrit-Reviewer: lynxis lazus <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to