fixeria has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-bsc/+/34322?usp=email )


Change subject: abis_nm: separate parsing of osmo-bts features into a function
......................................................................

abis_nm: separate parsing of osmo-bts features into a function

This commit prepares for adding handling of additional attributes.
The parse_attr_resp_info_attr() is already quite complex, so take
a chance to simplify it a bit.

Change-Id: Ia5919a8311cd6a7fc16d02d2196276881e96f4c5
---
M src/osmo-bsc/abis_nm.c
1 file changed, 61 insertions(+), 33 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/22/34322/1

diff --git a/src/osmo-bsc/abis_nm.c b/src/osmo-bsc/abis_nm.c
index 5aaf069..2f49424 100644
--- a/src/osmo-bsc/abis_nm.c
+++ b/src/osmo-bsc/abis_nm.c
@@ -560,6 +560,46 @@
        return ari + num_unreported + 1; /* we have to account for 1st byte 
with number of unreported attributes */
 }

+
+/* Parse Attribute Response Info content for 3GPP TS 52.021 §9.4.30 
Manufacturer Id */
+static void parse_osmo_bts_features(struct gsm_bts *bts,
+                                   const uint8_t *data, uint16_t len)
+{
+       /* log potential BTS feature vector overflow */
+       if (len > sizeof(bts->_features_data)) {
+               LOGPMO(&bts->mo, DNM, LOGL_NOTICE,
+                      "Get Attributes Response: feature vector is truncated "
+                      "(from %u to %zu bytes)\n", len, 
sizeof(bts->_features_data));
+               len = sizeof(bts->_features_data);
+       }
+
+       /* check that max. expected BTS attribute is above given feature vector 
length */
+       if (len > OSMO_BYTES_FOR_BITS(_NUM_BTS_FEAT)) {
+               LOGPMO(&bts->mo, DNM, LOGL_NOTICE,
+                      "Get Attributes Response: reported unexpectedly long (%u 
bytes) "
+                      "feature vector - most likely it was compiled against 
newer BSC headers. "
+                      "Consider upgrading your BSC to later version.\n", len);
+       }
+
+       memcpy(bts->_features_data, data, len);
+       bts->features_known = true;
+
+       /* Log each BTS feature in the reported vector */
+       for (unsigned int i = 0; i < len * 8; i++) {
+               if (!osmo_bts_has_feature(&bts->features, i))
+                       continue;
+
+               if (i >= _NUM_BTS_FEAT) {
+                       LOGPMO(&bts->mo, DNM, LOGL_NOTICE,
+                              "Get Attributes Response: unknown feature 0x%02x 
is supported\n", i);
+               } else {
+                       LOGPMO(&bts->mo, DNM, LOGL_NOTICE,
+                              "Get Attributes Response: feature '%s' is 
supported\n",
+                              osmo_bts_features_name(i));
+               }
+       }
+}
+
 /* Handle 3GPP TS 52.021 §8.11.3 Get Attribute Response (with nanoBTS specific 
attribute formatting) */
 static int parse_attr_resp_info_attr(struct gsm_bts *bts, const struct 
gsm_bts_trx *trx, struct abis_om_fom_hdr *foh, struct tlv_parsed *tp)
 {
@@ -572,40 +612,15 @@
        char unit_id[40];
        struct abis_nm_sw_desc sw_descr[MAX_BTS_ATTR];

-       /* Parse Attribute Response Info content for 3GPP TS 52.021 §9.4.30 
Manufacturer Id */
-       if (bts->type == GSM_BTS_TYPE_OSMOBTS && TLVP_PRES_LEN(tp, 
NM_ATT_MANUF_ID, 2)) {
-               len = TLVP_LEN(tp, NM_ATT_MANUF_ID);
-
-               /* log potential BTS feature vector overflow */
-               if (len > sizeof(bts->_features_data)) {
-                       LOGPMO(&bts->mo, DNM, LOGL_NOTICE, "Get Attributes 
Response: feature vector is truncated "
-                              "(from %u to %zu bytes)\n", len, 
sizeof(bts->_features_data));
-                       len = sizeof(bts->_features_data);
+       switch (bts->type) {
+       case GSM_BTS_TYPE_OSMOBTS:
+               if (TLVP_PRES_LEN(tp, NM_ATT_MANUF_ID, 2)) {
+                       parse_osmo_bts_features(bts, TLVP_VAL(tp, 
NM_ATT_MANUF_ID),
+                                                    TLVP_LEN(tp, 
NM_ATT_MANUF_ID));
                }
-
-               /* check that max. expected BTS attribute is above given 
feature vector length */
-               if (len > OSMO_BYTES_FOR_BITS(_NUM_BTS_FEAT)) {
-                       LOGPMO(&bts->mo, DNM, LOGL_NOTICE, "Get Attributes 
Response: reported unexpectedly long (%u bytes) "
-                              "feature vector - most likely it was compiled 
against newer BSC headers. "
-                              "Consider upgrading your BSC to later 
version.\n", len);
-               }
-
-               memcpy(bts->_features_data, TLVP_VAL(tp, NM_ATT_MANUF_ID), len);
-               bts->features_known = true;
-
-               /* Log each BTS feature in the reported vector */
-               for (i = 0; i < len * 8; i++) {
-                       if (!osmo_bts_has_feature(&bts->features, i))
-                               continue;
-
-                       if (i >= _NUM_BTS_FEAT)
-                               LOGPMO(&bts->mo, DNM, LOGL_NOTICE, "Get 
Attributes Response: unknown feature 0x%02x is"
-                                      " supported\n", i);
-                       else
-                               LOGPMO(&bts->mo, DNM, LOGL_NOTICE, "Get 
Attributes Response: feature '%s' is"
-                                      " supported\n", 
osmo_bts_features_name(i));
-               }
-
+               break;
+       default:
+               break;
        }

        /* Parse Attribute Response Info content for 3GPP TS 52.021 §9.4.28 
Manufacturer Dependent State */

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

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: Ia5919a8311cd6a7fc16d02d2196276881e96f4c5
Gerrit-Change-Number: 34322
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <[email protected]>
Gerrit-MessageType: newchange

Reply via email to