osmith has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/31542 )

Change subject: bssmap_handle_ass_req_ct_speech: split up
......................................................................

bssmap_handle_ass_req_ct_speech: split up

Allow reusing common code in an upcoming bssmap_handle_ass_req_ct_data.
It won't use _osmux for now (maybe in the future?), but splitting it
out as well makes it consistent.

Related: OS#4393
Change-Id: I4d9a4df314b1e56b9c1f90c9d7914332b70b56f8
---
M src/osmo-bsc/osmo_bsc_bssap.c
1 file changed, 92 insertions(+), 29 deletions(-)

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




diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index d0ff1cf..1a7c56e 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -796,28 +796,29 @@
        return nc > 0 ? 0 : -EINVAL;
 }

-static int bssmap_handle_ass_req_ct_speech(struct gsm_subscriber_connection 
*conn, struct tlv_parsed *tp,
-                                          struct gsm0808_channel_type *ct, 
struct assignment_request *req,
-                                          uint8_t *cause)
+static int bssmap_handle_ass_req_tp_cic(struct tlv_parsed *tp, bool aoip, 
uint16_t *cic, uint8_t *cause)
 {
-       uint16_t cic = 0;
-       bool aoip = gscon_is_aoip(conn);
-       bool use_osmux = false;
-       uint8_t osmux_cid = 0;
-       struct sockaddr_storage rtp_addr;
-       int rc;
-
        if (TLVP_PRESENT(tp, GSM0808_IE_CIRCUIT_IDENTITY_CODE)) {
                /* CIC is permitted in both AoIP and SCCPlite */
-               cic = osmo_load16be(TLVP_VAL(tp, 
GSM0808_IE_CIRCUIT_IDENTITY_CODE));
-       } else {
-               if (!aoip) {
-                       /* no CIC but SCCPlite: illegal */
-                       LOGP(DMSC, LOGL_ERROR, "SCCPlite MSC, but no CIC in 
ASSIGN REQ?\n");
-                       *cause = 
GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
-                       return -1;
-               }
+               *cic = osmo_load16be(TLVP_VAL(tp, 
GSM0808_IE_CIRCUIT_IDENTITY_CODE));
+               return 0;
        }
+
+       if (!aoip) {
+               /* no CIC but SCCPlite: illegal */
+               LOGP(DMSC, LOGL_ERROR, "SCCPlite MSC, but no CIC in ASSIGN 
REQ?\n");
+               *cause = GSM0808_CAUSE_INFORMATION_ELEMENT_OR_FIELD_MISSING;
+               return -1;
+       }
+
+       return 0;
+}
+
+static int bssmap_handle_ass_req_tp_rtp_addr(struct tlv_parsed *tp, bool aoip, 
struct sockaddr_storage *rtp_addr,
+                                            uint8_t *cause)
+{
+       int rc;
+
        if (TLVP_PRESENT(tp, GSM0808_IE_AOIP_TRASP_ADDR)) {
                if (!aoip) {
                        /* SCCPlite and AoIP transport address: illegal */
@@ -826,7 +827,7 @@
                        return -1;
                }
                /* Decode AoIP transport address element */
-               rc = gsm0808_dec_aoip_trasp_addr(&rtp_addr,
+               rc = gsm0808_dec_aoip_trasp_addr(rtp_addr,
                                                 TLVP_VAL(tp, 
GSM0808_IE_AOIP_TRASP_ADDR),
                                                 TLVP_LEN(tp, 
GSM0808_IE_AOIP_TRASP_ADDR));
                if (rc < 0) {
@@ -834,7 +835,10 @@
                        *cause = GSM0808_CAUSE_INCORRECT_VALUE;
                        return -1;
                }
-       } else if (aoip) {
+               return 0;
+       }
+
+       if (aoip) {
                /* no AoIP transport level address but AoIP transport: illegal 
*/
                LOGP(DMSC, LOGL_ERROR, "AoIP transport address missing in 
ASSIGN REQ, "
                     "audio would not work; rejecting\n");
@@ -842,14 +846,22 @@
                return -1;
        }

+       return 0;
+}
+
+static int bssmap_handle_ass_req_tp_osmux(struct gsm_subscriber_connection 
*conn, struct tlv_parsed *tp,
+                                         bool *use_osmux, uint8_t *osmux_cid, 
uint8_t *cause)
+{
+       int rc;
+
        if (TLVP_PRESENT(tp, GSM0808_IE_OSMO_OSMUX_CID)) {
                if (conn->sccp.msc->use_osmux == OSMUX_USAGE_OFF) {
                        LOGP(DMSC, LOGL_ERROR, "MSC using Osmux but we have it 
disabled.\n");
                        *cause = GSM0808_CAUSE_INCORRECT_VALUE;
                        return -1;
                }
-               use_osmux = true;
-               rc = gsm0808_dec_osmux_cid(&osmux_cid,
+               *use_osmux = true;
+               rc = gsm0808_dec_osmux_cid(osmux_cid,
                                           TLVP_VAL(tp, 
GSM0808_IE_OSMO_OSMUX_CID),
                                           TLVP_LEN(tp, 
GSM0808_IE_OSMO_OSMUX_CID));
                if (rc < 0) {
@@ -857,15 +869,26 @@
                        *cause = GSM0808_CAUSE_INCORRECT_VALUE;
                        return -1;
                }
-       } else {
-               if (conn->sccp.msc->use_osmux == OSMUX_USAGE_ONLY) {
-                       LOGP(DMSC, LOGL_ERROR, "MSC not using Osmux but we are 
forced to use it.\n");
-                       *cause = GSM0808_CAUSE_INCORRECT_VALUE;
-                       return -1;
-               } else if (conn->sccp.msc->use_osmux == OSMUX_USAGE_ON)
-                       LOGP(DMSC, LOGL_NOTICE, "MSC not using Osmux but we 
have Osmux enabled.\n");
+               return 0;
        }

+       if (conn->sccp.msc->use_osmux == OSMUX_USAGE_ONLY) {
+               LOGP(DMSC, LOGL_ERROR, "MSC not using Osmux but we are forced 
to use it.\n");
+               *cause = GSM0808_CAUSE_INCORRECT_VALUE;
+               return -1;
+       }
+
+       if (conn->sccp.msc->use_osmux == OSMUX_USAGE_ON)
+               LOGP(DMSC, LOGL_NOTICE, "MSC not using Osmux but we have Osmux 
enabled.\n");
+
+       return 0;
+}
+
+static int bssmap_handle_ass_req_tp_codec_list(struct 
gsm_subscriber_connection *conn, struct tlv_parsed *tp, bool aoip,
+                                              uint8_t *cause)
+{
+       int rc;
+
        /* Decode speech codec list. First set len = 0. */
        conn->codec_list = (struct gsm0808_speech_codec_list){};
        /* Check for speech codec list element */
@@ -888,6 +911,32 @@
                return -1;
        }

+       return 0;
+}
+
+static int bssmap_handle_ass_req_ct_speech(struct gsm_subscriber_connection 
*conn, struct tlv_parsed *tp,
+                                          struct gsm0808_channel_type *ct, 
struct assignment_request *req,
+                                          uint8_t *cause)
+{
+       uint16_t cic = 0;
+       bool aoip = gscon_is_aoip(conn);
+       bool use_osmux = false;
+       uint8_t osmux_cid = 0;
+       struct sockaddr_storage rtp_addr;
+       int rc;
+
+       if (bssmap_handle_ass_req_tp_cic(tp, aoip, &cic, cause) < 0)
+               return -1;
+
+       if (bssmap_handle_ass_req_tp_rtp_addr(tp, aoip, &rtp_addr, cause) < 0)
+               return -1;
+
+       if (bssmap_handle_ass_req_tp_osmux(conn, tp, &use_osmux, &osmux_cid, 
cause) < 0)
+               return -1;
+
+       if (bssmap_handle_ass_req_tp_codec_list(conn, tp, aoip, cause) < 0)
+               return -1;
+
        *req = (struct assignment_request){
                .assign_for = ASSIGN_FOR_BSSMAP_REQ,
                .aoip = aoip,

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I4d9a4df314b1e56b9c1f90c9d7914332b70b56f8
Gerrit-Change-Number: 31542
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>
Gerrit-MessageType: merged

Reply via email to