aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2012-08-19 00:52:00 +0200
committerPablo Neira Ayuso <pablo@gnumonks.org>2012-08-19 00:52:00 +0200
commit775c1de0891da2d3b16efada5ee8b99f96d045a1 (patch)
tree3d0c015075c215ca4200b0c165f882195d0ca7e8
parentb71627b1f74f8c7368fd132f7eec3b2dc26d165f (diff)
channel: add subtype ID to osmo_chan_create
This adds the possibility to specify the variant of the channel. This was discussed during the osmocom workshop. Harald wanted a way to say if the channel is using TCP, UDP, DADHDI and so on.
-rw-r--r--examples/channel/abis_ipa_client.c2
-rw-r--r--examples/channel/abis_ipa_server.c2
-rw-r--r--include/osmocom/netif/channel.h9
-rw-r--r--src/channel.c19
-rw-r--r--src/channel/abis_ipa_client.c1
-rw-r--r--src/channel/abis_ipa_server.c1
6 files changed, 28 insertions, 6 deletions
diff --git a/examples/channel/abis_ipa_client.c b/examples/channel/abis_ipa_client.c
index c560e9f..3e24b62 100644
--- a/examples/channel/abis_ipa_client.c
+++ b/examples/channel/abis_ipa_client.c
@@ -58,7 +58,7 @@ int main(void)
osmo_chan_init(tall_example);
/* create channel. */
- chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_CLI);
+ chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_CLI, OSMO_SUBCHAN_STREAM);
if (chan == NULL) {
LOGP(DEXAMPLE, LOGL_ERROR, "Cannot create A-bis IPA client\n");
exit(EXIT_FAILURE);
diff --git a/examples/channel/abis_ipa_server.c b/examples/channel/abis_ipa_server.c
index 27eebc7..a1b2ffd 100644
--- a/examples/channel/abis_ipa_server.c
+++ b/examples/channel/abis_ipa_server.c
@@ -55,7 +55,7 @@ int main(void)
osmo_chan_init(tall_example);
/* create channel. */
- chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_SRV);
+ chan = osmo_chan_create(OSMO_CHAN_ABIS_IPA_SRV, OSMO_SUBCHAN_STREAM);
if (chan == NULL) {
LOGP(DEXAMPLE, LOGL_ERROR, "Cannot create A-bis IPA server\n");
exit(EXIT_FAILURE);
diff --git a/include/osmocom/netif/channel.h b/include/osmocom/netif/channel.h
index f044605..1abc828 100644
--- a/include/osmocom/netif/channel.h
+++ b/include/osmocom/netif/channel.h
@@ -11,6 +11,12 @@ enum {
OSMO_CHAN_MAX,
};
+/* channel subtypes */
+enum {
+ OSMO_SUBCHAN_STREAM,
+ OSMO_SUBCHAN_MAX,
+};
+
struct osmo_chan;
struct msgb;
@@ -19,6 +25,7 @@ struct osmo_chan_type {
char *name;
int type;
+ int subtype;
int datasiz;
int (*create)(struct osmo_chan *chan);
@@ -36,7 +43,7 @@ struct osmo_chan {
void osmo_chan_init(void *ctx);
-struct osmo_chan *osmo_chan_create(int type);
+struct osmo_chan *osmo_chan_create(int type, int subtype);
void osmo_chan_destroy(struct osmo_chan *c);
int osmo_chan_open(struct osmo_chan *c);
diff --git a/src/channel.c b/src/channel.c
index 3b317de..2cae973 100644
--- a/src/channel.c
+++ b/src/channel.c
@@ -20,10 +20,10 @@ void osmo_chan_init(void *ctx)
/* add your new channel type here */
}
-struct osmo_chan *osmo_chan_create(int type_id)
+struct osmo_chan *osmo_chan_create(int type_id, int subtype_id)
{
struct osmo_chan_type *cur = NULL;
- int found = 0;
+ int found = 0, found_partial = 0;
struct osmo_chan *c;
if (type_id > OSMO_CHAN_MAX) {
@@ -31,11 +31,19 @@ struct osmo_chan *osmo_chan_create(int type_id)
"number `%u'\n", type_id);
return NULL;
}
+ if (subtype_id > OSMO_SUBCHAN_MAX) {
+ LOGP(DLINP, LOGL_ERROR, "unsupported subchannel type "
+ "number `%u'\n", type_id);
+ return NULL;
+ }
llist_for_each_entry(cur, &channel_list, head) {
- if (type_id == cur->type) {
+ if (type_id == cur->type && subtype_id == cur->subtype) {
found = 1;
break;
+ } else if (type_id == cur->type) {
+ found_partial = 1;
+ break;
}
}
@@ -44,6 +52,11 @@ struct osmo_chan *osmo_chan_create(int type_id)
cur->name);
return NULL;
}
+ if (found_partial) {
+ LOGP(DLINP, LOGL_ERROR, "Sorry, channel type `%s' does not "
+ "support subtype `%u'\n", cur->name, subtype_id);
+ return NULL;
+ }
c = talloc_zero_size(osmo_chan_ctx,
sizeof(struct osmo_chan) + cur->datasiz);
diff --git a/src/channel/abis_ipa_client.c b/src/channel/abis_ipa_client.c
index 2a971c7..bb6a1ee 100644
--- a/src/channel/abis_ipa_client.c
+++ b/src/channel/abis_ipa_client.c
@@ -359,6 +359,7 @@ static int rsl_read_cb(struct osmo_stream_cli *conn)
struct osmo_chan_type chan_abis_ipa_cli = {
.type = OSMO_CHAN_ABIS_IPA_CLI,
+ .subtype = OSMO_SUBCHAN_STREAM,
.name = "A-bis IPA client",
.datasiz = sizeof(struct chan_abis_ipa_cli),
.create = chan_abis_ipa_cli_create,
diff --git a/src/channel/abis_ipa_server.c b/src/channel/abis_ipa_server.c
index 7e21f49..6524033 100644
--- a/src/channel/abis_ipa_server.c
+++ b/src/channel/abis_ipa_server.c
@@ -511,6 +511,7 @@ static int rsl_read_cb(struct osmo_stream_srv *conn)
struct osmo_chan_type chan_abis_ipa_srv = {
.type = OSMO_CHAN_ABIS_IPA_SRV,
+ .subtype = OSMO_SUBCHAN_STREAM,
.name = "A-bis IPA server",
.datasiz = sizeof(struct chan_abis_ipa_srv),
.create = chan_abis_ipa_srv_create,