aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-08-18 17:30:36 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-18 20:51:03 +0200
commitf5efba40e7068595db788463e8b94ba56642218a (patch)
tree86e52f4ba15e415e08da979e196e09bb0cfb7831
parentc1edf604aed9bafb2ca5b188f9c6d0d5d2973808 (diff)
ipa: add ipaccess_tlv_to_unitdata()
this function takes the parsed TLVs of an IPA ID RESP message and fills a 'struct ipaccess_unit'.
-rw-r--r--include/osmocom/abis/ipa.h2
-rw-r--r--src/input/ipaccess.c45
2 files changed, 47 insertions, 0 deletions
diff --git a/include/osmocom/abis/ipa.h b/include/osmocom/abis/ipa.h
index 7030830..17b5f23 100644
--- a/include/osmocom/abis/ipa.h
+++ b/include/osmocom/abis/ipa.h
@@ -95,5 +95,7 @@ void ipa_msg_push_header(struct msgb *msg, uint8_t proto);
int ipaccess_idtag_parse(struct tlv_parsed *dec, unsigned char *buf, int len);
int ipaccess_send_id_req(int fd);
int ipaccess_parse_unitid(const char *str, struct ipaccess_unit *unit_data);
+int ipaccess_tlv_to_unitdata(struct ipaccess_unit *ud,
+ const struct tlv_parsed *tp);
#endif
diff --git a/src/input/ipaccess.c b/src/input/ipaccess.c
index f62e4b0..b124121 100644
--- a/src/input/ipaccess.c
+++ b/src/input/ipaccess.c
@@ -39,6 +39,7 @@
#include <osmocom/core/select.h>
#include <osmocom/gsm/tlv.h>
#include <osmocom/core/msgb.h>
+#include <osmocom/core/macaddr.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/talloc.h>
#include <osmocom/abis/e1_input.h>
@@ -163,6 +164,50 @@ int ipaccess_parse_unitid(const char *str, struct ipaccess_unit *unit_data)
return 0;
}
+int ipaccess_tlv_to_unitdata(struct ipaccess_unit *ud,
+ const struct tlv_parsed *tp)
+{
+ int rc = 0;
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_SERNR, 1))
+ ud->serno = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_SERNR));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_UNITNAME, 1))
+ ud->unit_name = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_UNITNAME));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_LOCATION1, 1))
+ ud->location1 = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_LOCATION1));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_LOCATION2, 1))
+ ud->location2 = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_LOCATION2));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_EQUIPVERS, 1))
+ ud->equipvers = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_EQUIPVERS));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_SWVERSION, 1))
+ ud->swversion = talloc_strdup(ud, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_SWVERSION));
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_MACADDR, 17)) {
+ rc = osmo_macaddr_parse(ud->mac_addr, (char *)
+ TLVP_VAL(tp, IPAC_IDTAG_MACADDR));
+ if (rc < 0)
+ goto out;
+ }
+
+ if (TLVP_PRES_LEN(tp, IPAC_IDTAG_UNIT, 1))
+ rc = ipaccess_parse_unitid((char *)
+ TLVP_VAL(tp, IPAC_IDTAG_UNIT), ud);
+
+out:
+ return rc;
+}
+
static int ipaccess_send(int fd, const void *msg, size_t msglen)
{
int ret;