aboutsummaryrefslogtreecommitdiffstats
path: root/src/ipa_unit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ipa_unit.c')
-rw-r--r--src/ipa_unit.c163
1 files changed, 148 insertions, 15 deletions
diff --git a/src/ipa_unit.c b/src/ipa_unit.c
index ccf8841..a631921 100644
--- a/src/ipa_unit.c
+++ b/src/ipa_unit.c
@@ -1,9 +1,12 @@
#include <osmocom/core/talloc.h>
+#include <osmocom/core/linuxlist.h>
#include <stdint.h>
#include <string.h>
-struct ipaccess_unit {
+struct osmo_ipa_unit {
+ struct llist_head head;
+
uint16_t site_id;
uint16_t bts_id;
uint16_t trx_id;
@@ -14,13 +17,15 @@ struct ipaccess_unit {
char *location1;
char *location2;
char *serno;
+
+ uint8_t data[0];
};
-struct ipaccess_unit *osmo_ipa_unit_alloc()
+struct osmo_ipa_unit *osmo_ipa_unit_alloc(size_t datalen)
{
- struct ipaccess_unit *unit;
+ struct osmo_ipa_unit *unit;
- unit = talloc_zero(NULL, struct ipaccess_unit);
+ unit = talloc_zero_size(NULL, sizeof(struct osmo_ipa_unit) + datalen);
if (unit == NULL)
return NULL;
@@ -34,7 +39,7 @@ struct ipaccess_unit *osmo_ipa_unit_alloc()
return unit;
}
-void osmo_ipa_unit_free(struct ipaccess_unit *unit)
+void osmo_ipa_unit_free(struct osmo_ipa_unit *unit)
{
if (unit->name)
free(unit->name);
@@ -52,22 +57,27 @@ void osmo_ipa_unit_free(struct ipaccess_unit *unit)
talloc_free(unit);
}
-void osmo_ipa_unit_set_site_id(struct ipaccess_unit *unit, uint16_t site_id)
+void *osmo_ipa_unit_get_data(struct osmo_ipa_unit *unit)
+{
+ return unit->data;
+}
+
+void osmo_ipa_unit_set_site_id(struct osmo_ipa_unit *unit, uint16_t site_id)
{
unit->site_id = site_id;
}
-void osmo_ipa_unit_set_bts_id(struct ipaccess_unit *unit, uint16_t bts_id)
+void osmo_ipa_unit_set_bts_id(struct osmo_ipa_unit *unit, uint16_t bts_id)
{
unit->bts_id = bts_id;
}
-void osmo_ipa_unit_set_trx_id(struct ipaccess_unit *unit, uint16_t trx_id)
+void osmo_ipa_unit_set_trx_id(struct osmo_ipa_unit *unit, uint16_t trx_id)
{
unit->trx_id = trx_id;
}
-void osmo_ipa_unit_set_unit_name(struct ipaccess_unit *unit, const char *name)
+void osmo_ipa_unit_set_unit_name(struct osmo_ipa_unit *unit, const char *name)
{
if (unit->name)
free(unit->name);
@@ -75,7 +85,7 @@ void osmo_ipa_unit_set_unit_name(struct ipaccess_unit *unit, const char *name)
unit->name = strdup(name);
}
-void osmo_ipa_unit_set_unit_hwvers(struct ipaccess_unit *unit, const char *vers)
+void osmo_ipa_unit_set_unit_hwvers(struct osmo_ipa_unit *unit, const char *vers)
{
if (unit->hwvers)
free(unit->hwvers);
@@ -83,7 +93,7 @@ void osmo_ipa_unit_set_unit_hwvers(struct ipaccess_unit *unit, const char *vers)
unit->hwvers = strdup(vers);
}
-void osmo_ipa_unit_set_unit_swvers(struct ipaccess_unit *unit, const char *vers)
+void osmo_ipa_unit_set_unit_swvers(struct osmo_ipa_unit *unit, const char *vers)
{
if (unit->swvers)
free(unit->swvers);
@@ -91,12 +101,12 @@ void osmo_ipa_unit_set_unit_swvers(struct ipaccess_unit *unit, const char *vers)
unit->swvers = strdup(vers);
}
-void osmo_ipa_unit_set_unit_mac_addr(struct ipaccess_unit *unit, uint8_t *addr)
+void osmo_ipa_unit_set_unit_mac_addr(struct osmo_ipa_unit *unit, uint8_t *addr)
{
memcpy(unit->mac_addr, addr, sizeof(unit->mac_addr));
}
-void osmo_ipa_unit_set_unit_loc1(struct ipaccess_unit *unit, const char *loc)
+void osmo_ipa_unit_set_unit_location1(struct osmo_ipa_unit *unit, const char *loc)
{
if (unit->location1)
free(unit->location1);
@@ -104,7 +114,7 @@ void osmo_ipa_unit_set_unit_loc1(struct ipaccess_unit *unit, const char *loc)
unit->location1 = strdup(loc);
}
-void osmo_ipa_unit_set_unit_loc2(struct ipaccess_unit *unit, const char *loc)
+void osmo_ipa_unit_set_unit_location2(struct osmo_ipa_unit *unit, const char *loc)
{
if (unit->location2)
free(unit->location2);
@@ -112,7 +122,130 @@ void osmo_ipa_unit_set_unit_loc2(struct ipaccess_unit *unit, const char *loc)
unit->location2 = strdup(loc);
}
-void osmo_ipa_unit_set_unit_serno(struct ipaccess_unit *unit, const char *serno)
+void osmo_ipa_unit_set_unit_serno(struct osmo_ipa_unit *unit, const char *serno)
{
unit->serno = strdup(serno);
}
+
+uint16_t osmo_ipa_unit_get_site_id(struct osmo_ipa_unit *unit)
+{
+ return unit->site_id;
+}
+
+uint16_t osmo_ipa_unit_get_bts_id(struct osmo_ipa_unit *unit)
+{
+ return unit->bts_id;
+}
+
+uint16_t osmo_ipa_unit_get_trx_id(struct osmo_ipa_unit *unit)
+{
+ return unit->trx_id;
+}
+
+const char *osmo_ipa_unit_get_unit_name(struct osmo_ipa_unit *unit)
+{
+ return unit->name;
+}
+
+const char *osmo_ipa_unit_get_unit_hwvers(struct osmo_ipa_unit *unit)
+{
+ return unit->hwvers;
+}
+
+const char *osmo_ipa_unit_get_unit_swvers(struct osmo_ipa_unit *unit)
+{
+ return unit->swvers;
+}
+
+uint8_t *osmo_ipa_unit_get_unit_mac_addr(struct osmo_ipa_unit *unit)
+{
+ return unit->mac_addr;
+}
+
+const char *osmo_ipa_unit_get_unit_location1(struct osmo_ipa_unit *unit)
+{
+ return unit->location1;
+}
+
+const char *osmo_ipa_unit_get_unit_location2(struct osmo_ipa_unit *unit)
+{
+ return unit->location2;
+}
+
+const char *osmo_ipa_unit_get_unit_serno(struct osmo_ipa_unit *unit)
+{
+ return unit->serno;
+}
+
+struct osmo_ipa_unit *
+osmo_ipa_unit_find(struct llist_head *list, uint16_t site_id, uint16_t bts_id)
+{
+ struct osmo_ipa_unit *unit;
+
+ llist_for_each_entry(unit, list, head) {
+ if (unit->site_id == site_id &&
+ unit->bts_id == bts_id)
+ return unit;
+ }
+ return NULL;
+}
+
+void osmo_ipa_unit_add(struct llist_head *list, struct osmo_ipa_unit *unit)
+{
+ llist_add(&unit->head, list);
+}
+
+int osmo_ipa_unit_snprintf(char *buf, size_t size, struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%u/%u/%u",
+ unit->site_id, unit->bts_id, unit->trx_id);
+}
+
+int osmo_ipa_unit_snprintf_mac_addr(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%02x:%02x:%02x:%02x:%02x:%02x",
+ unit->mac_addr[0], unit->mac_addr[1],
+ unit->mac_addr[2], unit->mac_addr[3],
+ unit->mac_addr[4], unit->mac_addr[5]);
+}
+
+int osmo_ipa_unit_snprintf_name(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s-%02x-%02x-%02x-%02x-%02x-%02x",
+ unit->name,
+ unit->mac_addr[0], unit->mac_addr[1],
+ unit->mac_addr[2], unit->mac_addr[3],
+ unit->mac_addr[4], unit->mac_addr[5]);
+}
+
+int osmo_ipa_unit_snprintf_loc1(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s", unit->location1);
+}
+
+int osmo_ipa_unit_snprintf_loc2(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s", unit->location2);
+}
+
+int osmo_ipa_unit_snprintf_hwvers(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s", unit->hwvers);
+}
+
+int osmo_ipa_unit_snprintf_swvers(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s", unit->hwvers);
+}
+
+int osmo_ipa_unit_snprintf_serno(char *buf, size_t size,
+ struct osmo_ipa_unit *unit)
+{
+ return snprintf(buf, size, "%s", unit->serno);
+}