From f5efba40e7068595db788463e8b94ba56642218a Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 18 Aug 2014 17:30:36 +0200 Subject: ipa: add ipaccess_tlv_to_unitdata() this function takes the parsed TLVs of an IPA ID RESP message and fills a 'struct ipaccess_unit'. --- src/input/ipaccess.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'src/input') 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 #include #include +#include #include #include #include @@ -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; -- cgit v1.2.3