aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/utils.c
diff options
context:
space:
mode:
authorÁlvaro Neira Ayuso <anayuso@sysmocom.de>2014-05-23 10:14:22 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2014-05-25 13:41:08 +0200
commit399b3fe1b4ab1a8d78ef5bf39d185b3defdf1b5e (patch)
tree5a59435c288698924cf51fe73f3d454e85b3f699 /src/osmo-bts-sysmo/utils.c
parent69925cef390289cf9eb0db283230953f82d9617c (diff)
sysmobts: Move the function check_oml_msg to oml file
This patch move this function to oml and we can use in the future for doing a sanity check to all the received OML message. Signed-off-by: Alvaro Neira Ayuso <anayuso@sysmocom.de>
Diffstat (limited to 'src/osmo-bts-sysmo/utils.c')
-rw-r--r--src/osmo-bts-sysmo/utils.c121
1 files changed, 1 insertions, 120 deletions
diff --git a/src/osmo-bts-sysmo/utils.c b/src/osmo-bts-sysmo/utils.c
index f867a424..bd75c81d 100644
--- a/src/osmo-bts-sysmo/utils.c
+++ b/src/osmo-bts-sysmo/utils.c
@@ -26,6 +26,7 @@
#include <osmo-bts/bts.h>
#include <osmo-bts/gsm_data.h>
#include <osmo-bts/logging.h>
+#include <osmo-bts/oml.h>
#include <osmocom/core/msgb.h>
#include <osmocom/gsm/protocol/ipaccess.h>
@@ -160,126 +161,6 @@ void prepend_oml_ipa_header(struct msgb *msg)
hh->len = htons(msg->len - sizeof(struct ipaccess_head));
}
-static int check_oml_fom(struct abis_om_hdr *omh, size_t len)
-{
- if (omh->length != len) {
- LOGP(DL1C, LOGL_ERROR, "Incorrect om length value %d %d\n",
- omh->length, len);
- return -1;
- }
-
- if (len < sizeof(struct abis_om_fom_hdr)) {
- LOGP(DL1C, LOGL_ERROR, "Fom header insufficient space %d %d\n",
- len, sizeof(struct abis_om_fom_hdr));
- return -1;
- }
-
- return 0;
-}
-
-static int check_oml_manuf(struct abis_om_hdr *hdr, size_t msg_size)
-{
- if (msg_size < 1) {
- LOGP(DL1C, LOGL_ERROR, "No ManId Length Indicator %d\n",
- msg_size);
- return -1;
- }
-
- if (hdr->data[0] >= msg_size - 1) {
- LOGP(DL1C, LOGL_ERROR,
- "Insuficient message space for this ManId Lenght %d %d\n",
- hdr->data[0], msg_size - 1);
- return -1;
- }
-
- if (hdr->data[0] == sizeof(ipaccess_magic) &&
- strncmp(ipaccess_magic, (const char *)hdr->data + 1,
- sizeof(ipaccess_magic)) == 0) {
- return OML_MSG_TYPE_IPA;
- } else if (hdr->data[0] == sizeof(osmocom_magic) &&
- strncmp(osmocom_magic, (const char *) hdr->data + 1,
- sizeof(osmocom_magic)) == 0) {
- return OML_MSG_TYPE_OSMO;
- } else {
- LOGP(DL1C, LOGL_ERROR,
- "Manuf Label Unknown\n");
- return -1;
- }
-}
-
-/**
- * \brief Check that the data in \param msg is a proper OML message
- *
- * This function verifies that the data in \param in msg is a proper
- * OML message and can be handled by later functions. In the successful
- * case the msg->l2h will now point to the OML header and the msg->l3h
- * will point to the FOM header. The value of l2h/l3h is undefined in
- * case the verification of the \param msg is failing.
- *
- * \param msg The message to analyze. msg->len starting from msg->data
- * will be analyzed.
- * \return This function returns the msg with the l2h/l3h pointers in the right
- * direction on success and on failure, in the case that the msg doesn't contain
- * the OML header or the OML header values aren't the expect, the function
- * doesn't set the l2h and l3h. In the case that the msg don't contains the FOM
- * header or the FOM header values aren't the expect, the function set the l2h
- * but doesn't set the l3h.
- */
-
-int check_oml_msg(struct msgb *msg)
-{
- struct abis_om_hdr *omh;
- int ret = OML_MSG_TYPE_ETSI;
-
- if (msg->len < sizeof(*omh)) {
- LOGP(DL1C, LOGL_ERROR, "Om header insufficient space %d %d\n",
- msg->len, sizeof(*omh));
- return -1;
- }
-
- msg->l2h = msg->data;
-
- omh = (struct abis_om_hdr *) msg->l2h;
-
- if (omh->mdisc != ABIS_OM_MDISC_FOM &&
- omh->mdisc != ABIS_OM_MDISC_MANUF) {
- LOGP(DL1C, LOGL_ERROR, "Incorrect om mdisc value %x\n",
- omh->mdisc);
- return -1;
- }
-
- if (omh->placement != ABIS_OM_PLACEMENT_ONLY) {
- LOGP(DL1C, LOGL_ERROR, "Incorrect om placement value %x %x\n",
- omh->placement, ABIS_OM_PLACEMENT_ONLY);
- return -1;
- }
-
- if (omh->sequence != 0) {
- LOGP(DL1C, LOGL_ERROR, "Incorrect om sequence value %d\n",
- omh->sequence);
- return -1;
- }
-
- if (omh->mdisc == ABIS_OM_MDISC_MANUF)
- ret = check_oml_manuf(omh, msgb_l2len(msg) - sizeof(*omh));
-
- if (ret == OML_MSG_TYPE_OSMO)
- msg->l3h = omh->data + sizeof(osmocom_magic) + 1;
- else if (ret == OML_MSG_TYPE_IPA)
- msg->l3h = omh->data + sizeof(ipaccess_magic) + 1;
- else if (ret == OML_MSG_TYPE_ETSI)
- msg->l3h = omh->data;
- else
- msg->l3h = NULL;
-
- if (ret < 0)
- return -1;
-
- check_oml_fom(omh, msgb_l3len(msg));
-
- return ret;
-}
-
int check_ipa_header(struct msgb *msg)
{
struct ipaccess_head *hh;