aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@gnumonks.org>2013-07-08 05:09:46 +0200
committerHolger Hans Peter Freyther <holger@moiji-mobile.com>2013-07-08 16:46:06 +0200
commit46bd4244a1cfeaa1eca6757c790589a15dd99a5a (patch)
treee2260af756ae8b57578f09d20b13e27680c02fd8 /openbsc
parent1e61b256614ee58af46fa3a3ea2cba9c6d656018 (diff)
libmgcp: add enum mgcp_type and use it
This patch replaces the field 'is_transcoded' in the mgcp_endpoint structure by the enum mgcp_type, that can be further extended with new types.
Diffstat (limited to 'openbsc')
-rw-r--r--openbsc/include/openbsc/mgcp_internal.h7
-rw-r--r--openbsc/src/libmgcp/mgcp_network.c34
-rw-r--r--openbsc/src/libmgcp/mgcp_protocol.c8
3 files changed, 36 insertions, 13 deletions
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h
index 455bb53d..d5bd3ddc 100644
--- a/openbsc/include/openbsc/mgcp_internal.h
+++ b/openbsc/include/openbsc/mgcp_internal.h
@@ -96,6 +96,11 @@ struct mgcp_rtp_tap {
struct sockaddr_in forward;
};
+enum mgcp_type {
+ MGCP_RTP_DEFAULT = 0,
+ MGCP_RTP_TRANSCODED,
+};
+
struct mgcp_endpoint {
int allocated;
uint32_t ci;
@@ -119,7 +124,7 @@ struct mgcp_endpoint {
*/
struct mgcp_rtp_end trans_bts;
struct mgcp_rtp_end trans_net;
- int is_transcoded;
+ enum mgcp_type type;
/* sequence bits */
struct mgcp_rtp_state net_state;
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c
index a2cfc238..e9b58b24 100644
--- a/openbsc/src/libmgcp/mgcp_network.c
+++ b/openbsc/src/libmgcp/mgcp_network.c
@@ -371,10 +371,19 @@ static int rtp_data_net(struct osmo_fd *fd, unsigned int what)
endp->net_end.octets += rc;
forward_data(fd->fd, &endp->taps[MGCP_TAP_NET_IN], buf, rc);
- if (endp->is_transcoded)
- return send_transcoder(&endp->trans_net, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
- else
- return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr, &buf[0], rc);
+
+ switch (endp->type) {
+ case MGCP_RTP_DEFAULT:
+ return send_to(endp, DEST_BTS, proto == PROTO_RTP, &addr,
+ buf, rc);
+ case MGCP_RTP_TRANSCODED:
+ return send_transcoder(&endp->trans_net, endp->cfg,
+ proto == PROTO_RTP, buf, rc);
+ }
+
+ LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
+ endp->type, ENDPOINT_NUMBER(endp));
+ return 0;
}
static void discover_bts(struct mgcp_endpoint *endp, int proto, struct sockaddr_in *addr)
@@ -450,10 +459,19 @@ static int rtp_data_bts(struct osmo_fd *fd, unsigned int what)
endp->bts_end.octets += rc;
forward_data(fd->fd, &endp->taps[MGCP_TAP_BTS_IN], buf, rc);
- if (endp->is_transcoded)
- return send_transcoder(&endp->trans_bts, endp->cfg, proto == PROTO_RTP, &buf[0], rc);
- else
- return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr, &buf[0], rc);
+
+ switch (endp->type) {
+ case MGCP_RTP_DEFAULT:
+ return send_to(endp, DEST_NETWORK, proto == PROTO_RTP, &addr,
+ buf, rc);
+ case MGCP_RTP_TRANSCODED:
+ return send_transcoder(&endp->trans_bts, endp->cfg,
+ proto == PROTO_RTP, buf, rc);
+ }
+
+ LOGP(DMGCP, LOGL_ERROR, "Bad MGCP type %u on endpoint %u\n",
+ endp->type, ENDPOINT_NUMBER(endp));
+ return 0;
}
static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp,
diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c
index 8f6861d9..616e0a94 100644
--- a/openbsc/src/libmgcp/mgcp_protocol.c
+++ b/openbsc/src/libmgcp/mgcp_protocol.c
@@ -500,7 +500,7 @@ static int allocate_ports(struct mgcp_endpoint *endp)
}
/* remember that we have set up transcoding */
- endp->is_transcoded = 1;
+ endp->type = MGCP_RTP_TRANSCODED;
}
return 0;
@@ -1014,7 +1014,7 @@ void mgcp_free_endp(struct mgcp_endpoint *endp)
mgcp_rtp_end_reset(&endp->net_end);
mgcp_rtp_end_reset(&endp->trans_net);
mgcp_rtp_end_reset(&endp->trans_bts);
- endp->is_transcoded = 0;
+ endp->type = MGCP_RTP_DEFAULT;
memset(&endp->net_state, 0, sizeof(endp->net_state));
memset(&endp->bts_state, 0, sizeof(endp->bts_state));
@@ -1118,7 +1118,7 @@ static void create_transcoder(struct mgcp_endpoint *endp)
int in_endp = ENDPOINT_NUMBER(endp);
int out_endp = endp_back_channel(in_endp);
- if (!endp->is_transcoded)
+ if (endp->type != MGCP_RTP_TRANSCODED)
return;
send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv");
@@ -1140,7 +1140,7 @@ static void delete_transcoder(struct mgcp_endpoint *endp)
int in_endp = ENDPOINT_NUMBER(endp);
int out_endp = endp_back_channel(in_endp);
- if (!endp->is_transcoded)
+ if (endp->type != MGCP_RTP_TRANSCODED)
return;
send_dlcx(endp, in_endp);