From 139b8caa79499ec170b10b035409649b02750af3 Mon Sep 17 00:00:00 2001 From: Vadim Yanitskiy Date: Thu, 27 Jun 2019 02:29:58 +0700 Subject: osmo-bts-trx/trx_if.c: add TRXD header version negotiation This change introduces a new command for TRXD header format negotiation - SETFORMAT. If the transceiver does not support the format negotiation, it would reject this command with 'RSP ERR 1'. If the requested version is not supported by the transceiver, status code of the response message should indicate a preferred (basically, the latest) version. The format of SETFORMAT command is the following: L1 -> TRX: CMD SETFORMAT VER_REQ L1 <- TRX: RSP SETFORMAT VER_RSP VER_REQ where: - VER_REQ is the requested version (suggested by the L1), - VER_RSP is either the applied version if matches VER_REQ, or a preferred version if VER_REQ is not supported. If the transceiver indicates VER_RSP different than VER_REQ, OsmoBTS is supposed to reinitiate the version negotiation using the suggested VER_RSP. For example: L1 -> TRX: CMD SETFORMAT 2 L1 <- TRX: RSP SETFORMAT 1 2 L1 -> TRX: CMD SETFORMAT 1 L1 <- TRX: RSP SETFORMAT 1 1 If no suitable VER_RSP is found, or the VER_REQ is incorrect, the status code in the response would be -1. As soon as VER_RSP matches VER_REQ in the response, the process of negotiation is complete. Changing the header version is supposed to be done before POWERON. Change-Id: I8afe950bd1ec2afaf3347ff848ee46e69c4f5011 Related: OS#4006 --- src/osmo-bts-trx/l1_if.c | 10 +++++++ src/osmo-bts-trx/l1_if.h | 4 +++ src/osmo-bts-trx/trx_if.c | 76 +++++++++++++++++++++++++++++++++++++++++++---- src/osmo-bts-trx/trx_if.h | 6 ++++ 4 files changed, 91 insertions(+), 5 deletions(-) diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c index e6e384ab..9c1dc185 100644 --- a/src/osmo-bts-trx/l1_if.c +++ b/src/osmo-bts-trx/l1_if.c @@ -208,6 +208,13 @@ int l1if_provision_transceiver_trx(struct trx_l1h *l1h) l1h->config.bsic_sent = 1; } + /* Ask transceiver to use the newest TRXD header version */ + if (!l1h->config.setformat_sent) { + trx_if_cmd_setformat(l1h, TRX_DATA_FORMAT_VER); + l1h->config.trxd_hdr_ver_req = TRX_DATA_FORMAT_VER; + l1h->config.setformat_sent = 1; + } + if (!l1h->config.poweron_sent) { trx_if_cmd_poweron(l1h); l1h->config.poweron_sent = 1; @@ -264,6 +271,9 @@ int l1if_provision_transceiver(struct gsm_bts *bts) llist_for_each_entry(trx, &bts->trx_list, list) { struct phy_instance *pinst = trx_phy_instance(trx); struct trx_l1h *l1h = pinst->u.osmotrx.hdl; + l1h->config.trxd_hdr_ver_req = 0; + l1h->config.trxd_hdr_ver_use = 0; + l1h->config.setformat_sent = 0; l1h->config.arfcn_sent = 0; l1h->config.tsc_sent = 0; l1h->config.bsic_sent = 0; diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h index 9c95c53c..87df951b 100644 --- a/src/osmo-bts-trx/l1_if.h +++ b/src/osmo-bts-trx/l1_if.h @@ -6,6 +6,10 @@ #include "trx_if.h" struct trx_config { + uint8_t trxd_hdr_ver_req; /* requested TRXD header version */ + uint8_t trxd_hdr_ver_use; /* actual TRXD header version in use */ + int setformat_sent; + uint8_t poweron; /* poweron(1) or poweroff(0) */ int poweron_sent; diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c index e9193cad..3e53fdb7 100644 --- a/src/osmo-bts-trx/trx_if.c +++ b/src/osmo-bts-trx/trx_if.c @@ -269,6 +269,15 @@ int trx_if_cmd_poweron(struct trx_l1h *l1h) return 0; } +/*! Send "SETFORMAT" command to TRX: change TRXD header format version */ +int trx_if_cmd_setformat(struct trx_l1h *l1h, uint8_t ver) +{ + LOGPPHI(l1h->phy_inst, DTRX, LOGL_INFO, + "Requesting TRXD header format version %u\n", ver); + + return trx_ctrl_cmd(l1h, 0, "SETFORMAT", "%u", ver); +} + /*! Send "SETTSC" command to TRX */ int trx_if_cmd_settsc(struct trx_l1h *l1h, uint8_t tsc) { @@ -433,6 +442,8 @@ static bool cmd_matches_rsp(struct trx_ctrl_msg *tcm, struct trx_ctrl_rsp *rsp) expected that they can return different values */ if (strcmp(tcm->cmd, "SETSLOT") == 0 && strcmp(tcm->params, rsp->params)) return false; + else if (strcmp(tcm->cmd, "SETFORMAT") == 0 && strcmp(tcm->params, rsp->params)) + return false; return true; } @@ -460,11 +471,59 @@ static int trx_ctrl_rx_rsp_setslot(struct trx_l1h *l1h, struct trx_ctrl_rsp *rsp return rsp->status == 0 ? 0 : -EINVAL; } +/* TRXD header format negotiation handler. + * + * If the transceiver does not support the format negotiation, it would + * reject SETFORMAT with 'RSP ERR 1'. If the requested version is not + * supported by the transceiver, status code of the response message + * should indicate a preferred (basically, the latest) version. + */ +static int trx_ctrl_rx_rsp_setformat(struct trx_l1h *l1h, + struct trx_ctrl_rsp *rsp) +{ + /* Old transceivers reject 'SETFORMAT' with 'RSP ERR 1' */ + if (strcmp(rsp->cmd, "SETFORMAT") != 0) { + LOGPPHI(l1h->phy_inst, DTRX, LOGL_NOTICE, + "Transceiver rejected the format negotiation command, " + "using legacy TRXD header format version (0)\n"); + l1h->config.trxd_hdr_ver_use = 0; + return 0; + } + + /* Status shall indicate a proper version supported by the transceiver */ + if (rsp->status < 0 || rsp->status > l1h->config.trxd_hdr_ver_req) { + LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, + "Transceiver indicated an out of range " + "header format version %d (requested %u)\n", + rsp->status, l1h->config.trxd_hdr_ver_req); + return -EINVAL; + } + + /* Transceiver may suggest a lower version (than requested) */ + if (rsp->status == l1h->config.trxd_hdr_ver_req) { + l1h->config.trxd_hdr_ver_use = rsp->status; + LOGPPHI(l1h->phy_inst, DTRX, LOGL_INFO, + "Using TRXD header format version %u\n", + l1h->config.trxd_hdr_ver_use); + } else { + LOGPPHI(l1h->phy_inst, DTRX, LOGL_DEBUG, + "Transceiver suggests TRXD header version %u (requested %u)\n", + rsp->status, l1h->config.trxd_hdr_ver_req); + /* Send another SETFORMAT with suggested version */ + l1h->config.trxd_hdr_ver_req = rsp->status; + trx_if_cmd_setformat(l1h, rsp->status); + } + + return 0; +} + /* -EINVAL: unrecoverable error, exit BTS * N > 0: try sending originating command again after N seconds * 0: Done with response, get originating command out from send queue */ -static int trx_ctrl_rx_rsp(struct trx_l1h *l1h, struct trx_ctrl_rsp *rsp, bool critical) +static int trx_ctrl_rx_rsp(struct trx_l1h *l1h, + struct trx_ctrl_rsp *rsp, + struct trx_ctrl_msg *tcm) { struct phy_instance *pinst = l1h->phy_inst; @@ -484,14 +543,18 @@ static int trx_ctrl_rx_rsp(struct trx_l1h *l1h, struct trx_ctrl_rsp *rsp, bool c } } else if (strcmp(rsp->cmd, "SETSLOT") == 0) { return trx_ctrl_rx_rsp_setslot(l1h, rsp); + /* We may get 'RSP ERR 1' if 'SETFORMAT' is not supported, + * so that's why we should use tcm instead of rsp. */ + } else if (strcmp(tcm->cmd, "SETFORMAT") == 0) { + return trx_ctrl_rx_rsp_setformat(l1h, rsp); } if (rsp->status) { - LOGPPHI(l1h->phy_inst, DTRX, critical ? LOGL_FATAL : LOGL_NOTICE, + LOGPPHI(l1h->phy_inst, DTRX, tcm->critical ? LOGL_FATAL : LOGL_NOTICE, "transceiver rejected TRX command with response: '%s%s%s %d'\n", rsp->cmd, rsp->params[0] != '\0' ? " ":"", rsp->params, rsp->status); - if (critical) + if (tcm->critical) return -EINVAL; } return 0; @@ -547,13 +610,16 @@ static int trx_ctrl_read_cb(struct osmo_fd *ofd, unsigned int what) "Response message '%s' does not match command " "message 'CMD %s%s%s'\n", buf, tcm->cmd, tcm->params_len ? " ":"", tcm->params); - goto rsp_error; + + /* We may get 'RSP ERR 1' for non-critical commands */ + if (tcm->critical) + goto rsp_error; } rsp.cb = tcm->cb; /* check for response code */ - rc = trx_ctrl_rx_rsp(l1h, &rsp, tcm->critical); + rc = trx_ctrl_rx_rsp(l1h, &rsp, tcm); if (rc == -EINVAL) goto rsp_error; diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h index cdfbd41c..dda7116e 100644 --- a/src/osmo-bts-trx/trx_if.h +++ b/src/osmo-bts-trx/trx_if.h @@ -35,4 +35,10 @@ int trx_if_send_burst(struct trx_l1h *l1h, uint8_t tn, uint32_t fn, uint8_t pwr, const ubit_t *bits, uint16_t nbits); int trx_if_powered(struct trx_l1h *l1h); +/* The latest supported TRXD header format version */ +#define TRX_DATA_FORMAT_VER 1 + +/* Format negotiation command */ +int trx_if_cmd_setformat(struct trx_l1h *l1h, uint8_t ver); + #endif /* TRX_IF_H */ -- cgit v1.2.3