[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-25 Thread dexter
Hello Neels Hofmeyr, Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#13).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

Depends: libosmocore I15e1af68616309555d0ed9ac5da027c9833d42e3

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
5 files changed, 249 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/13

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..21717e3 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constants */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char *audio_ip;
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -65,14 +96,19 @@
 
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
-  enum mgcp_connection_mode mode);
+  enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
-  uint16_t rtp_port, enum mgcp_connection_mode mode);
+  uint16_t rtp_port, enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
-  unsigned int call_id);
+  unsigned int call_id)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
 
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..c7cc989 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,109 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   msg->l2h = msg->data;
+   msg->cb[MSGB_CB_MGCP_TRANS_ID] = trans_id;
+
+   

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-18 Thread dexter
Hello Neels Hofmeyr, Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#11).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

Depends: libosmocore I15e1af68616309555d0ed9ac5da027c9833d42e3

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
5 files changed, 250 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/11

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..21717e3 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constants */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char *audio_ip;
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -65,14 +96,19 @@
 
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
-  enum mgcp_connection_mode mode);
+  enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
-  uint16_t rtp_port, enum mgcp_connection_mode mode);
+  uint16_t rtp_port, enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
-  unsigned int call_id);
+  unsigned int call_id)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
 
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..c7cc989 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,109 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   msg->l2h = msg->data;
+   msg->cb[MSGB_CB_MGCP_TRANS_ID] = trans_id;
+
+   

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-12 Thread dexter
Hello Neels Hofmeyr, Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#6).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

Depends: libosmocore I15e1af68616309555d0ed9ac5da027c9833d42e3

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.err
M tests/mgcp_client/mgcp_client_test.ok
5 files changed, 250 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/6

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..21717e3 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constants */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char *audio_ip;
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -65,14 +96,19 @@
 
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
-  enum mgcp_connection_mode mode);
+  enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
-  uint16_t rtp_port, enum mgcp_connection_mode mode);
+  uint16_t rtp_port, enum mgcp_connection_mode mode)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
 
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
-  unsigned int call_id);
+  unsigned int call_id)
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead");
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
 
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..c7cc989 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,109 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   msg->l2h = msg->data;
+   msg->cb[MSGB_CB_MGCP_TRANS_ID] = trans_id;
+
+   

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-11 Thread dexter
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#5).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

This commit depends on libosmocore Change:
Change-Id I15e1af68616309555d0ed9ac5da027c9833d42e3

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.ok
4 files changed, 229 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/5

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..c9e77de 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constands above */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char *audio_ip;
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -63,17 +94,22 @@
 
 enum mgcp_connection_mode;
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
   enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
   uint16_t rtp_port, enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
   unsigned int call_id);
 
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
+
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
 {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..0d5dbcd 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,107 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   msg->l2h = msg->data;
+   msg->cb[MSGB_CB_MGCP_TRANS_ID] = trans_id;
+
+   /* Add command verb */
+   switch (mgcp_msg->verb) {
+   case MGCP_VERB_CRCX:
+   mandatory_mask = MGCP_CRCX_MANDATORY;
+   rc += 

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-11 Thread dexter
Hello Harald Welte, Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#4).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

This commit depends on libosmocore Change:
Change-Id I15e1af68616309555d0ed9ac5da027c9833d42e3

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.ok
4 files changed, 224 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/4

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..1e92da7 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constands above */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char audio_ip[INET_ADDRSTRLEN];
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -63,17 +94,22 @@
 
 enum mgcp_connection_mode;
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
   enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
   uint16_t rtp_port, enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
   unsigned int call_id);
 
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
+
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
 {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..2bb669e 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,104 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   /* Add command verb */
+   switch (mgcp_msg->verb) {
+   case MGCP_VERB_CRCX:
+   mandatory_mask = MGCP_CRCX_MANDATORY;
+   rc += msgb_printf(msg, "CRCX %u", trans_id);
+   break;
+   case 

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-10 Thread dexter
Hello Jenkins Builder,

I'd like you to reexamine a change.  Please visit

https://gerrit.osmocom.org/4146

to look at the new patch set (#2).

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.ok
4 files changed, 223 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/2

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..1e92da7 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,36 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_PRESENCE_ENDPOINT 0x0001
+#define MGCP_MSG_PRESENCE_CALL_ID  0x0002
+#define MGCP_MSG_PRESENCE_CONN_ID  0x0004
+#define MGCP_MSG_PRESENCE_AUDIO_IP 0x0008
+#define MGCP_MSG_PRESENCE_AUDIO_PORT   0x0010
+#define MGCP_MSG_PRESENCE_CONN_MODE0x0020
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_ENDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   /* See MGCP_MSG_PRESENCE_* constands above */
+   uint32_t presence;
+   char endpoint[MGCP_ENDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+uint16_t audio_port;
+char audio_ip[INET_ADDRSTRLEN];
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -63,17 +94,22 @@
 
 enum mgcp_connection_mode;
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
   enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
   uint16_t rtp_port, enum mgcp_connection_mode mode);
 
+OSMO_DEPRECATED("Use mgcp_msg_gen() instead")
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
   unsigned int call_id);
 
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
+
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
 {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..2bb669e 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -614,6 +615,104 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CALL_ID | \
+MGCP_MSG_PRESENCE_CONN_ID | \
+MGCP_MSG_PRESENCE_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT | \
+MGCP_MSG_PRESENCE_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_PRESENCE_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+   struct msgb *msg = msgb_alloc_headroom(4096, 128, "MGCP tx");
+   int rc = 0;
+
+   /* Add command verb */
+   switch (mgcp_msg->verb) {
+   case MGCP_VERB_CRCX:
+   mandatory_mask = MGCP_CRCX_MANDATORY;
+   rc += msgb_printf(msg, "CRCX %u", trans_id);
+   break;
+   case MGCP_VERB_MDCX:
+   mandatory_mask = MGCP_MDCX_MANDATORY;
+   rc += msgb_printf(msg, "MDCX 

[PATCH] osmo-mgw[master]: client: add unified function to generate MGCP messages

2017-10-05 Thread dexter

Review at  https://gerrit.osmocom.org/4146

client: add unified function to generate MGCP messages

currently the only way to generate MGCP messages is to use
mgcp_msg_crcx(), mgcp_msg_mdcx() and mgcp_msg_dlcx(). All
three function take a fixed set of parameters via their
parameter list. There is no way to add or leave away optional
parameters.

add function mgcp_msg_gen(), this function takes a unified
message struct. The struct features a presence bitmask which
allows to enable and disable parameters as needed. It is also
possible to add new parameters in the future without breaking
the API.

Change-Id: I29c5e2fb972896faeb771ba040f015592487fcbe
---
M include/osmocom/mgcp_client/mgcp_client.h
M src/libosmo-mgcp-client/mgcp_client.c
M tests/mgcp_client/mgcp_client_test.c
M tests/mgcp_client/mgcp_client_test.ok
4 files changed, 237 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/46/4146/1

diff --git a/include/osmocom/mgcp_client/mgcp_client.h 
b/include/osmocom/mgcp_client/mgcp_client.h
index efc1f76..9368a76 100644
--- a/include/osmocom/mgcp_client/mgcp_client.h
+++ b/include/osmocom/mgcp_client/mgcp_client.h
@@ -1,6 +1,7 @@
 #pragma once
 
 #include 
+#include 
 
 #include 
 
@@ -37,6 +38,33 @@
uint16_t audio_port;
 };
 
+enum mgcp_verb {
+   MGCP_VERB_CRCX,
+   MGCP_VERB_MDCX,
+   MGCP_VERB_DLCX,
+   MGCP_VERB_AUEP,
+   MGCP_VERB_RSIP,
+};
+
+#define MGCP_MSG_T_ENDPOINT0x0001
+#define MGCP_MSG_T_CALL_ID 0x0002
+#define MGCP_MSG_T_CONN_ID 0x0004
+#define MGCP_MSG_T_RTP_ADDR0x0008
+#define MGCP_MSG_T_CONN_MODE   0x0010
+
+/* See also RFC3435 section 3.2.1.3 */
+#define MGCP_EINDPOINT_MAXLEN (255*2+1+1)
+
+struct mgcp_msg {
+   enum mgcp_verb verb;
+   uint32_t presence;
+   char endpoint[MGCP_EINDPOINT_MAXLEN];
+   unsigned int call_id;
+   uint32_t conn_id;
+   struct sockaddr_storage rtp_addr;
+   enum mgcp_connection_mode conn_mode;
+};
+
 void mgcp_client_conf_init(struct mgcp_client_conf *conf);
 void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf 
*conf);
 int mgcp_client_config_write(struct vty *vty, const char *indent);
@@ -63,17 +91,22 @@
 
 enum mgcp_connection_mode;
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
   enum mgcp_connection_mode mode);
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
   uint16_t rtp_port, enum mgcp_connection_mode mode);
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
   unsigned int call_id);
 
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg);
+
 extern const struct value_string mgcp_client_connection_mode_strs[];
 static inline const char *mgcp_client_cmode_name(enum mgcp_connection_mode 
mode)
 {
diff --git a/src/libosmo-mgcp-client/mgcp_client.c 
b/src/libosmo-mgcp-client/mgcp_client.c
index 1cd37be..175f81a 100644
--- a/src/libosmo-mgcp-client/mgcp_client.c
+++ b/src/libosmo-mgcp-client/mgcp_client.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -568,6 +569,7 @@
return mgcp->next_trans_id ++;
 }
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_crcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, unsigned int call_id,
   enum mgcp_connection_mode mode)
@@ -585,6 +587,7 @@
 mgcp_client_cmode_name(mode));
 }
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_mdcx(struct mgcp_client *mgcp,
   uint16_t rtp_endpoint, const char *rtp_conn_addr,
   uint16_t rtp_port, enum mgcp_connection_mode mode)
@@ -605,6 +608,7 @@
 rtp_port);
 }
 
+/* Deprecated, please use mgcp_msg_gen() instead */
 struct msgb *mgcp_msg_dlcx(struct mgcp_client *mgcp, uint16_t rtp_endpoint,
   unsigned int call_id)
 {
@@ -614,6 +618,113 @@
 "C: %x\r\n", trans_id, rtp_endpoint, call_id);
 }
 
+#define MGCP_CRCX_MANDATORY (MGCP_MSG_T_ENDPOINT | MGCP_MSG_T_CALL_ID | 
MGCP_MSG_T_CONN_ID | MGCP_MSG_T_CONN_MODE)
+#define MGCP_MDCX_MANDATORY (MGCP_MSG_T_ENDPOINT | MGCP_MSG_T_CONN_ID)
+#define MGCP_DLCX_MANDATORY (MGCP_MSG_T_ENDPOINT)
+#define MGCP_AUEP_MANDATORY (MGCP_MSG_T_ENDPOINT)
+#define MGCP_RSIP_MANDATORY 0  /* none */
+
+struct msgb *mgcp_msg_gen(struct mgcp_client *mgcp, struct mgcp_msg *mgcp_msg)
+{
+   mgcp_trans_id_t trans_id = mgcp_client_next_trans_id(mgcp);
+   uint32_t mandatory_mask;
+