Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

    https://gerrit.osmocom.org/2786

to look at the new patch set (#7).

Extend Get Attribute responder

* detect if attributes are requested for BTS or TRX and act accordingly
* report TRX phy version

Change-Id: I9f72305bbf1ab74745bffac1bee9f539f5a6de32
Related: OS#1614
---
M src/common/oml.c
1 file changed, 48 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/86/2786/7

diff --git a/src/common/oml.c b/src/common/oml.c
index 9dddf57..b5b4278 100644
--- a/src/common/oml.c
+++ b/src/common/oml.c
@@ -46,6 +46,7 @@
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/bts.h>
 #include <osmo-bts/signal.h>
+#include <osmo-bts/phy_link.h>
 
 static int oml_ipa_set_attr(struct gsm_bts *bts, struct msgb *msg);
 
@@ -153,37 +154,63 @@
        return mo_buf;
 }
 
-static inline struct msgb *add_bts_attr(const struct gsm_bts *bts)
+static inline void add_bts_attrs(struct msgb *msg, const struct gsm_bts *bts)
 {
-       struct msgb *a = oml_msgb_alloc();
-
-       if (!a)
-               return NULL;
-
-       abis_nm_put_sw_file(a, btstype2str(GSM_BTS_TYPE_OSMOBTS), 
PACKAGE_VERSION, true);
-       abis_nm_put_sw_file(a, btsatttr2str(BTS_TYPE_VARIANT), 
btsvariant2str(bts->variant), true);
+       abis_nm_put_sw_file(msg, btstype2str(GSM_BTS_TYPE_OSMOBTS), 
PACKAGE_VERSION, true);
+       abis_nm_put_sw_file(msg, btsatttr2str(BTS_TYPE_VARIANT), 
btsvariant2str(bts->variant), true);
 
        if (strlen(bts->sub_model))
-               abis_nm_put_sw_file(a, btsatttr2str(BTS_SUB_MODEL), 
bts->sub_model, true);
-
-       return a;
+               abis_nm_put_sw_file(msg, btsatttr2str(BTS_SUB_MODEL), 
bts->sub_model, true);
 }
 
-static inline int handle_attr(const struct gsm_abis_mo *mo, const uint8_t 
*attr, uint16_t attr_len, uint8_t *out)
+static inline void add_trx_attr(struct msgb *msg, struct gsm_bts_trx *trx)
+{
+       struct phy_instance *pinst = trx_phy_instance(trx);
+
+       abis_nm_put_sw_file(msg, btsatttr2str(TRX_PHY_VERSION), 
strlen(pinst->version) ? pinst->version : "Unknown",
+                           true);
+}
+
+/* copy all the attributes accumulated in msg to out and return the total 
length of out buffer */
+static inline int cleanup_attr_msg(uint8_t *out, int out_offset, struct msgb 
*msg)
+{
+       int len = 0;
+
+       if (msg) {
+               memcpy(out + out_offset, msgb_data(msg), msg->len);
+               len = msg->len;
+               msgb_free(msg);
+       }
+
+       return len + out_offset + 1;
+}
+
+/* assemble values of supported attributes and list of unsupported ones */
+static inline int handle_attrs(const struct gsm_bts *bts, const struct 
gsm_abis_mo *mo,
+                             const uint8_t *attr, uint16_t attr_len, uint8_t 
*out)
 {
        uint16_t i, attr_out_index = 1; /* byte 0 is reserved for unsupported 
attributes counter */
-       struct msgb *ba = NULL;
-       int length;
+       struct msgb *attr_buf = oml_msgb_alloc();
+
+       if (!attr_buf)
+               return -ENOMEM;
+
+       if (!mo)
+               return -EINVAL;
 
        for (i = 0; i < attr_len; i++) {
                switch (attr[i]) {
                case NM_ATT_SW_CONFIG:
                        switch (mo->obj_class) {
                        case NM_OC_BTS:
-                               ba = add_bts_attr(mo->bts);
+                               add_bts_attrs(attr_buf, mo->bts);
+                               break;
+                       case NM_OC_BASEB_TRANSC:
+                               add_trx_attr(attr_buf, gsm_bts_trx_num(bts, 
mo->obj_inst.trx_nr));
                                break;
                        default:
-                               LOGP(DOML, LOGL_ERROR, "Unsupported MO class %s 
in Get Attribute Response\n",
+                               LOGP(DOML, LOGL_ERROR, "Unsupported MO class %s 
in Get Attribute "
+                                    "Response(NM_ATT_SW_CONFIG)\n",
                                     get_value_string(abis_nm_obj_class_names, 
mo->obj_class));
                                return -EINVAL;
                        }
@@ -204,19 +231,11 @@
        } else
                out[0] = attr_out_index - 1; /* Count number of unhandled 
attributes */
 
-       length = attr_out_index + 1;
-
-       if (ba) {
-               memcpy(out + attr_out_index, msgb_data(ba), ba->len);
-               length += ba->len;
-               msgb_free(ba);
-       }
-
-       return length;
+       return cleanup_attr_msg(out, attr_out_index, attr_buf);
 }
 
 /* send 3GPP TS 52.021 ยง8.11.2 Get Attribute Response */
-static int oml_tx_attr_resp(struct gsm_abis_mo *mo, const uint8_t *attr, 
uint16_t attr_len)
+static int oml_tx_attr_resp(const struct gsm_bts *bts, struct gsm_abis_mo *mo, 
const uint8_t *attr, uint16_t attr_len)
 {
        struct msgb *nmsg = oml_msgb_alloc();
        uint8_t resp[MAX_VERSION_LENGTH * attr_len * 2]; /* heuristic for 
Attribute Response Info space requirements */
@@ -227,7 +246,7 @@
        if (!nmsg)
                return -ENOMEM;
 
-       len = handle_attr(mo, attr, attr_len, resp);
+       len = handle_attrs(bts, mo, attr, attr_len, resp);
        if (len < 0) {
                LOGP(DOML, LOGL_ERROR, "Tx Get Attribute Response FAILED with 
%d\n", len);
                msgb_free(nmsg);
@@ -483,13 +502,13 @@
                return oml_fom_ack_nack(msg, NM_NACK_INCORR_STRUCT);
        }
 
-       if (!TLVP_PRESENT(&tp, NM_ATT_LIST_REQ_ATTR)) {
+       if (!TLVP_PRES_LEN(&tp, NM_ATT_LIST_REQ_ATTR, 1)) {
                LOGP(DOML, LOGL_ERROR, "O&M Get Attributes message without 
Attribute List?!\n");
                oml_tx_failure_event_rep(&bts->mo, OSMO_EVT_MAJ_UNSUP_ATTR, 
"Get Attribute without Attribute List");
                return oml_fom_ack_nack(msg, NM_NACK_INCORR_STRUCT);
        }
 
-       rc = oml_tx_attr_resp(mo, TLVP_VAL(&tp, NM_ATT_LIST_REQ_ATTR), 
TLVP_LEN(&tp, NM_ATT_LIST_REQ_ATTR));
+       rc = oml_tx_attr_resp(bts, mo, TLVP_VAL(&tp, NM_ATT_LIST_REQ_ATTR), 
TLVP_LEN(&tp, NM_ATT_LIST_REQ_ATTR));
        if (rc < 0) {
                LOGP(DOML, LOGL_ERROR, "Failed to respond to O&M Get Attributes 
message: %s\n", strerror(-rc));
                switch (-rc) {

-- 
To view, visit https://gerrit.osmocom.org/2786
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I9f72305bbf1ab74745bffac1bee9f539f5a6de32
Gerrit-PatchSet: 7
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <[email protected]>
Gerrit-Reviewer: Harald Welte <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <[email protected]>

Reply via email to