Review at  https://gerrit.osmocom.org/2786

Extend Get Attribute responder

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

Note: including phy_link.h to onl.c somehow breaks the tests so we have
to add stub functions to unbreak them.

Change-Id: I9f72305bbf1ab74745bffac1bee9f539f5a6de32
Related: OS#1614
---
M src/common/oml.c
M tests/agch/agch_test.c
M tests/cipher/cipher_test.c
M tests/handover/handover_test.c
M tests/paging/paging_test.c
5 files changed, 87 insertions(+), 11 deletions(-)


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

diff --git a/src/common/oml.c b/src/common/oml.c
index 4e199e2..70e7e07 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);
 
@@ -169,10 +170,59 @@
        return a;
 }
 
-static inline int handle_attr(const struct gsm_abis_mo *mo, const uint8_t 
*attr, uint16_t attr_len, uint8_t *out)
+static inline struct msgb *add_trx_attr(struct gsm_bts_trx *trx)
+{
+       struct msgb *a = oml_msgb_alloc();
+       struct phy_instance *pinst = trx_phy_instance(trx);
+
+       if (!a)
+               return NULL;
+
+       abis_nm_put_sw_file(a, btsatttr2str(TRX_PHY_VERSION), 
strlen(pinst->version) ? pinst->version : "Unknown", true);
+
+       return a;
+}
+
+static inline struct msgb *add_trx_power(struct gsm_bts_trx *trx)
+{
+       struct msgb *a = oml_msgb_alloc();
+       uint8_t power = get_p_nominal_mdBm(trx);
+
+       if (!a)
+               return NULL;
+
+       if (power <= 0)
+               power = trx->nominal_power;
+
+       if (power <= 0)
+               power = trx->bts->c0->nominal_power;
+
+       if (power <= 0)
+               return NULL;
+
+       msgb_tv_put(a, NM_ATT_MANUF_STATE, power);
+
+       return a;
+}
+
+static inline int cleanup_attr(struct msgb *a, int length, uint8_t *out)
+{
+       int len = 0;
+
+       if (a) {
+               memcpy(out + length - 1, msgb_data(a), a->len);
+               len = a->len;
+               msgb_free(a);
+       }
+
+       return length + len;
+}
+
+static inline int handle_attr(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;
+       struct msgb *ba = NULL, *pa = NULL;
        int length;
 
        for (i = 0; i < attr_len; i++) {
@@ -182,8 +232,30 @@
                        case NM_OC_BTS:
                                ba = add_bts_attr(mo->bts);
                                break;
+                       case NM_OC_BASEB_TRANSC:
+                               ba = add_trx_attr(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;
+                       }
+                       break;
+               case NM_ATT_MANUF_STATE:
+                       switch (mo->obj_class) {
+                       case NM_OC_BTS:
+                               LOGP(DOML, LOGL_NOTICE, "BTS does not support 
NM_ATT_MANUF_STATE in Get Attribute "
+                                    "Response\n");
+                               out[attr_out_index] = attr[i];
+                               attr_out_index++;
+                               break;
+                       case NM_OC_BASEB_TRANSC:
+                               pa = add_trx_power(gsm_bts_trx_num(bts, 
mo->obj_inst.trx_nr));
+                               break;
+                       default:
+                               LOGP(DOML, LOGL_ERROR, "Unsupported MO class %s 
in Get Attribute "
+                                    "Response(NM_ATT_MANUF_STATE)\n",
                                     get_value_string(abis_nm_obj_class_names, 
mo->obj_class));
                                return -EINVAL;
                        }
@@ -206,17 +278,14 @@
 
        length = attr_out_index + 1;
 
-       if (ba) {
-               memcpy(out + attr_out_index, msgb_data(ba), ba->len);
-               length += ba->len;
-               msgb_free(ba);
-       }
+       length = cleanup_attr(pa, length, out);
+       length = cleanup_attr(ba, length, out);
 
        return length;
 }
 
 /* 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 +296,7 @@
        if (!nmsg)
                return -ENOMEM;
 
-       len = handle_attr(mo, attr, attr_len, resp);
+       len = handle_attr(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);
@@ -489,7 +558,7 @@
                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) {
diff --git a/tests/agch/agch_test.c b/tests/agch/agch_test.c
index e275c64..cf05a8d 100644
--- a/tests/agch/agch_test.c
+++ b/tests/agch/agch_test.c
@@ -35,6 +35,8 @@
        0x08, 0x59, 0x51, 0x30, 0x99, 0x00, 0x00, 0x00, 0x19
 };
 
+int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm) { 
return 0; }
+
 static int count_imm_ass_rej_refs(struct gsm48_imm_ass_rej *rej)
 {
        int count = 0;
diff --git a/tests/cipher/cipher_test.c b/tests/cipher/cipher_test.c
index c913925..957dbca 100644
--- a/tests/cipher/cipher_test.c
+++ b/tests/cipher/cipher_test.c
@@ -37,6 +37,8 @@
                abort();                             \
        }
 
+int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm) { 
return 0; }
+
 static void test_cipher_parsing(void)
 {
        int i;
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index 611c441..3ca595a 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -270,6 +270,7 @@
 int bts_model_apply_oml(struct gsm_bts *bts, struct msgb *msg, struct 
tlv_parsed *new_attr, int obj_kind, void *obj) { return 0; }
 int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj) 
{ return 0; }
 int bts_model_chg_adm_state(struct gsm_bts *bts, struct gsm_abis_mo *mo, void 
*obj, uint8_t adm_state) { return 0; }
+int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm) { 
return 0; }
 int bts_model_init(struct gsm_bts *bts) { return 0; }
 int bts_model_trx_deact_rf(struct gsm_bts_trx *trx) { return 0; }
 int bts_model_trx_close(struct gsm_bts_trx *trx) { return 0; }
diff --git a/tests/paging/paging_test.c b/tests/paging/paging_test.c
index 1d5f216..32bf484 100644
--- a/tests/paging/paging_test.c
+++ b/tests/paging/paging_test.c
@@ -41,6 +41,8 @@
                abort();                             \
        }
 
+int bts_model_change_power(struct gsm_bts_trx *trx, int p_trxout_mdBm) { 
return 0; }
+
 static void test_paging_smoke(void)
 {
        int rc;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9f72305bbf1ab74745bffac1bee9f539f5a6de32
Gerrit-PatchSet: 1
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Owner: Max <msur...@sysmocom.de>

Reply via email to