aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/channel/abis_ipa_client.c3
-rw-r--r--examples/channel/abis_ipa_server.c3
-rw-r--r--include/osmocom/netif/channel.h4
-rw-r--r--src/channel.c39
4 files changed, 39 insertions, 10 deletions
diff --git a/examples/channel/abis_ipa_client.c b/examples/channel/abis_ipa_client.c
index 8ff0c11..2ddc434 100644
--- a/examples/channel/abis_ipa_client.c
+++ b/examples/channel/abis_ipa_client.c
@@ -54,6 +54,9 @@ int main(void)
osmo_init_logging(&example_log_info);
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
+ /* initialize channel infrastructure. */
+ osmo_chan_init();
+
/* create channel. */
chan = osmo_chan_create(tall_example, CHAN_ABIS_IPA_CLI);
if (chan == NULL) {
diff --git a/examples/channel/abis_ipa_server.c b/examples/channel/abis_ipa_server.c
index 3019e71..1a9d2ed 100644
--- a/examples/channel/abis_ipa_server.c
+++ b/examples/channel/abis_ipa_server.c
@@ -51,6 +51,9 @@ int main(void)
osmo_init_logging(&example_log_info);
log_set_log_level(osmo_stderr_target, LOGL_DEBUG);
+ /* initialize channel infrastructure. */
+ osmo_chan_init();
+
/* create channel. */
chan = osmo_chan_create(tall_example, CHAN_ABIS_IPA_SRV);
if (chan == NULL) {
diff --git a/include/osmocom/netif/channel.h b/include/osmocom/netif/channel.h
index 20be992..baeb2c8 100644
--- a/include/osmocom/netif/channel.h
+++ b/include/osmocom/netif/channel.h
@@ -14,6 +14,8 @@ struct osmo_chan;
struct msgb;
struct osmo_chan_type {
+ struct llist_head head;
+
char *name;
int type;
int datasiz;
@@ -31,6 +33,8 @@ struct osmo_chan {
char data[0];
};
+void osmo_chan_init(void);
+
struct osmo_chan *osmo_chan_create(void *ctx, int type);
void osmo_chan_destroy(struct osmo_chan *c);
diff --git a/src/channel.c b/src/channel.c
index 0fe9e17..16e9dfc 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -1,35 +1,54 @@
#include <osmocom/core/talloc.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/logging.h>
+#include <osmocom/core/linuxlist.h>
#include <osmocom/netif/channel.h>
+static LLIST_HEAD(channel_list);
+
extern struct osmo_chan_type chan_abis_ipa_srv;
extern struct osmo_chan_type chan_abis_ipa_cli;
-static struct osmo_chan_type *chan_type[CHAN_MAX] = {
- [CHAN_ABIS_IPA_SRV] = &chan_abis_ipa_srv,
- [CHAN_ABIS_IPA_CLI] = &chan_abis_ipa_cli,
-};
+void osmo_chan_init(void)
+{
+ llist_add(&chan_abis_ipa_srv.head, &channel_list);
+ llist_add(&chan_abis_ipa_cli.head, &channel_list);
+ /* add your new channel type here */
+}
struct osmo_chan *osmo_chan_create(void *ctx, int type_id)
{
+ struct osmo_chan_type *cur = NULL;
+ int found = 0;
struct osmo_chan *c;
- if (type_id >= CHAN_MAX) {
- LOGP(DLINP, LOGL_ERROR, "unsupported channel type `%u'\n",
- type_id);
+ if (type_id > CHAN_MAX) {
+ LOGP(DLINP, LOGL_ERROR, "unsupported channel type "
+ "number `%u'\n", type_id);
+ return NULL;
+ }
+
+ llist_for_each_entry(cur, &channel_list, head) {
+ if (type_id == cur->type) {
+ found = 1;
+ break;
+ }
+ }
+
+ if (!found) {
+ LOGP(DLINP, LOGL_ERROR, "unsupported channel type `%s'\n",
+ cur->name);
return NULL;
}
- c = talloc_zero_size(ctx, sizeof(struct osmo_chan) +
- chan_type[type_id]->datasiz);
+ c = talloc_zero_size(ctx, sizeof(struct osmo_chan) + cur->datasiz);
if (c == NULL) {
LOGP(DLINP, LOGL_ERROR, "cannot allocate channel data\n");
return NULL;
}
- c->ops = chan_type[type_id];
+ c->ops = cur;
if (c->ops->create(c) < 0) {
LOGP(DLINP, LOGL_ERROR, "cannot create channel\n");