laforge has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmocore/+/21611 )


Change subject: bssgp_bvc_fsm: Add basic BVC flow control rx/tx support
......................................................................

bssgp_bvc_fsm: Add basic BVC flow control rx/tx support

The FSM doesn't actually implement the flow control logic,
it only decodes / dispatches and encodes messages.

Change-Id: Ie59be6761177c43456898be9148727f15861a622
---
M include/osmocom/gprs/bssgp_bvc_fsm.h
M src/gb/bssgp_bvc_fsm.c
2 files changed, 41 insertions(+), 1 deletion(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/11/21611/1

diff --git a/include/osmocom/gprs/bssgp_bvc_fsm.h 
b/include/osmocom/gprs/bssgp_bvc_fsm.h
index 7c6fdeb..e69c205 100644
--- a/include/osmocom/gprs/bssgp_bvc_fsm.h
+++ b/include/osmocom/gprs/bssgp_bvc_fsm.h
@@ -4,6 +4,7 @@
 struct gprs_ns2_inst;
 struct osmo_fsm_inst;
 struct gprs_ra_id;
+struct bssgp2_flow_ctrl;

 enum bssp_ptp_bvc_fsm_state {
        BSSGP_BVCFSM_S_NULL,
@@ -22,10 +23,13 @@
        BSSGP_BVCFSM_E_RX_UNBLOCK_ACK,
        BSSGP_BVCFSM_E_RX_RESET,
        BSSGP_BVCFSM_E_RX_RESET_ACK,
+       BSSGP_BVCFSM_E_RX_FC_BVC,
+       BSSGP_BVCFSM_E_RX_FC_BVC_ACK,
        /* Requests of the local user */
        BSSGP_BVCFSM_E_REQ_BLOCK,       /* data: uint8_t *cause */
        BSSGP_BVCFSM_E_REQ_UNBLOCK,
        BSSGP_BVCFSM_E_REQ_RESET,       /* data: uint8_t *cause */
+       BSSGP_BVCFSM_E_REQ_FC_BVC,      /* data: struct bssgp2_flow_ctrl */
 };

 struct bssgp_bvc_fsm_ops {
@@ -35,6 +39,7 @@
        /* call-back notifying the user of a BVC-RESET event */
        void (*reset_notification)(uint16_t nsei, uint16_t bvci, const struct 
gprs_ra_id *ra_id,
                                   uint16_t cell_id, uint8_t cause, void *priv);
+       void (*rx_fc_bvc)(uint16_t nsei, uint16_t bvci, const struct 
bssgp2_flow_ctrl *fc, void *priv);
 };

 struct osmo_fsm_inst *
diff --git a/src/gb/bssgp_bvc_fsm.c b/src/gb/bssgp_bvc_fsm.c
index a0e4b01..2224eba 100644
--- a/src/gb/bssgp_bvc_fsm.c
+++ b/src/gb/bssgp_bvc_fsm.c
@@ -86,6 +86,8 @@
        { BSSGP_BVCFSM_E_REQ_BLOCK, "REQ-BLOCK" },
        { BSSGP_BVCFSM_E_REQ_UNBLOCK, "REQ-UNBLOCK" },
        { BSSGP_BVCFSM_E_REQ_RESET, "REQ-RESET" },
+       { BSSGP_BVCFSM_E_RX_FC_BVC, "RX-FLOW-CONTROL-BVC" },
+       { BSSGP_BVCFSM_E_RX_FC_BVC_ACK, "RX-FLOW-CONTROL-BVC-ACK" },
        { 0, NULL }
 };

@@ -114,6 +116,8 @@
                uint32_t advertised;
                uint32_t received;
                uint32_t negotiated;
+               /* only used if BSSGP_XFEAT_GBIT is negotiated */
+               enum bssgp_fc_granularity fc_granularity;
        } features;

        /* Cell Identification used by BSS when
@@ -372,9 +376,11 @@

 static void bssgp_bvc_fsm_unblocked(struct osmo_fsm_inst *fi, uint32_t event, 
void *data)
 {
+       struct bssgp2_flow_ctrl rx_fc, *tx_fc;
        struct bvc_fsm_priv *bfp = fi->priv;
        const struct tlv_parsed *tp = NULL;
        struct msgb *rx = NULL, *tx;
+       int rc;

        switch (event) {
        case BSSGP_BVCFSM_E_RX_UNBLOCK_ACK:
@@ -440,6 +446,33 @@
                fi_tx_sig(fi, tx);
                osmo_fsm_inst_state_chg(fi, BSSGP_BVCFSM_S_BLOCKED, T1_SECS, 
T1);
                break;
+       case BSSGP_BVCFSM_E_RX_FC_BVC:
+               rx = data;
+               tp = (const struct tlv_parsed *) msgb_bcid(rx);
+               /* we assume osmo_tlv_prot_* has been used before calling here 
to ensure this */
+               OSMO_ASSERT(bfp->role_sgsn);
+               rc = bssgp2_dec_fc_bvc(&rx_fc, tp);
+               if (rc < 0) {
+                       _tx_status(fi, BSSGP_CAUSE_SEM_INCORR_PDU, rx);
+                       break;
+               }
+               if (bfp->ops->rx_fc_bvc)
+                       bfp->ops->rx_fc_bvc(bfp->nsei, bfp->bvci, &rx_fc, 
bfp->ops_priv);
+               tx = bssgp2_enc_fc_bvc_ack(rx_fc.tag);
+               fi_tx_sig(fi, tx);
+               break;
+       case BSSGP_BVCFSM_E_RX_FC_BVC_ACK:
+               rx = data;
+               tp = (const struct tlv_parsed *) msgb_bcid(rx);
+               /* we assume osmo_tlv_prot_* has been used before calling here 
to ensure this */
+               OSMO_ASSERT(!bfp->role_sgsn);
+               break;
+       case BSSGP_BVCFSM_E_REQ_FC_BVC:
+               tx_fc = data;
+               tx = bssgp2_enc_fc_bvc(tx_fc, bfp->features.negotiated & 
(BSSGP_XFEAT_GBIT << 8) ?
+                                       &bfp->features.fc_granularity : NULL);
+               fi_tx_sig(fi, tx);
+               break;
        }
 }

@@ -561,7 +594,9 @@
                .in_event_mask = S(BSSGP_BVCFSM_E_RX_BLOCK) |
                                 S(BSSGP_BVCFSM_E_RX_UNBLOCK) |
                                 S(BSSGP_BVCFSM_E_RX_UNBLOCK_ACK) |
-                                S(BSSGP_BVCFSM_E_REQ_BLOCK),
+                                S(BSSGP_BVCFSM_E_REQ_BLOCK) |
+                                S(BSSGP_BVCFSM_E_RX_FC_BVC) |
+                                S(BSSGP_BVCFSM_E_RX_FC_BVC_ACK),
                .out_state_mask = S(BSSGP_BVCFSM_S_BLOCKED) |
                                  S(BSSGP_BVCFSM_S_WAIT_RESET_ACK) |
                                  S(BSSGP_BVCFSM_S_UNBLOCKED),

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

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: Ie59be6761177c43456898be9148727f15861a622
Gerrit-Change-Number: 21611
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <lafo...@osmocom.org>
Gerrit-MessageType: newchange

Reply via email to