aboutsummaryrefslogtreecommitdiffstats
path: root/sigtran/sua_server_test.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2015-12-21 23:35:56 +0100
committerHarald Welte <laforge@gnumonks.org>2015-12-21 23:35:56 +0100
commit283c7fde3809d3bb010b736c4597641f3d290260 (patch)
tree5e56e05c534dff33bfb267a98ac15bfbefcfbaf1 /sigtran/sua_server_test.c
parent71f73a2919ec071de8b8f1972db6cc92c29a55ee (diff)
Add WIP code for SCCP User Adaptation (SUA) and SCCP User SAP
The idea of this code is to * provide a SCCP User SAP as boundary between the User of SCCP or SCCP-like transport like SUA * implement the minimum subset of SUA to transport RANAP messages betweene HNB-GW and MSC/SGSN At this point * we don't yet implement the proper state machines and timer * we don't imp[lement the SCCP RESET procedure * we don't implement AS/ASP management The code is full of FIXMEs whihc hopefully will get fixed gradually. After some cleanup + verification, it should move to a library, possibly either replacing/renaming libomo-sccp, or adding it to libosmo-netif?
Diffstat (limited to 'sigtran/sua_server_test.c')
-rw-r--r--sigtran/sua_server_test.c79
1 files changed, 79 insertions, 0 deletions
diff --git a/sigtran/sua_server_test.c b/sigtran/sua_server_test.c
new file mode 100644
index 0000000..be123c2
--- /dev/null
+++ b/sigtran/sua_server_test.c
@@ -0,0 +1,79 @@
+#include "sua_test_common.h"
+
+struct osmo_prim_hdr *make_conn_resp(struct osmo_scu_connect_param *param)
+{
+ struct msgb *msg = msgb_alloc(1024, "conn_resp");
+ struct osmo_scu_prim *prim;
+
+ prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim));
+ osmo_prim_init(&prim->oph, SCCP_SAP_USER,
+ OSMO_SCU_PRIM_N_CONNECT,
+ PRIM_OP_RESPONSE, msg);
+ memcpy(&prim->u.connect, param, sizeof(prim->u.connect));
+ return &prim->oph;
+}
+
+static int sccp_sap_up(struct osmo_prim_hdr *oph, void *link)
+{
+ struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph;
+ struct osmo_prim_hdr *resp = NULL;
+ const uint8_t payload[] = { 0xb1, 0xb2, 0xb3 };
+
+ printf("sccp_sap_up(%s)\n", osmo_sccp_prim_name(oph));
+
+ switch (OSMO_PRIM_HDR(oph)) {
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_CONFIRM):
+ /* confirmation of outbound connection */
+ break;
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION):
+ /* indication of new inbound connection request*/
+ printf("N-CONNECT.ind(X->%u)\n", prim->u.connect.conn_id);
+ resp = make_conn_resp(&prim->u.connect);
+ break;
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_DISCONNECT, PRIM_OP_INDICATION):
+ /* indication of disconnect */
+ printf("N-DISCONNECT.ind(%u)\n", prim->u.disconnect.conn_id);
+ break;
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION):
+ /* connection-oriented data received */
+ printf("N-DATA.ind(%u, %s)\n", prim->u.data.conn_id,
+ osmo_hexdump(msgb_l2(oph->msg), msgb_l2len(oph->msg)));
+ resp = make_dt1_req(prim->u.data.conn_id, payload, sizeof(payload));
+ break;
+ case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION):
+ /* connection-oriented data received */
+ printf("N-UNITDATA.ind(%s)\n",
+ osmo_hexdump(msgb_l2(oph->msg), msgb_l2len(oph->msg)));
+ tx_unitdata(link);
+ break;
+ }
+
+ if (resp)
+ osmo_osmo_sua_user_link_down(link, resp);
+
+ msgb_free(oph->msg);
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ struct osmo_sua_user *user;
+ void *ctx = talloc_named_const(NULL, 1, "root");
+ int rc;
+
+ osmo_sua_set_log_area(DSUA);
+ xua_set_log_area(DXUA);
+
+ osmo_init_logging(&test_log_info);
+
+ user = osmo_sua_user_create(ctx, sccp_sap_up);
+
+ rc = sua_server_listen(user, "127.0.0.1", 2342);
+ if (rc < 0) {
+ exit(1);
+ }
+
+ while (1) {
+ osmo_select_main(0);
+ }
+}