fixeria has submitted this change. ( 
https://gerrit.osmocom.org/c/osmocom-bb/+/30326 )

Change subject: mobile: add MNCC handler selection to settings
......................................................................

mobile: add MNCC handler selection to settings

Since the mobile application is potentially able to maintain
multiple MS instances, it's better to have a possibility to
choose an MNCC (Call Control) handler per each MS separately.

This change removes the command-line option '-m', which was used
for enabling the external MNCC.  Now it's possible configure the
MNCC handler for each MS via the VTY interface and settings.

The following MNCC-handlers are available:

  - internal - built-in MNCC-handler (default);
  - external - external MNCC-handler via UNIX-socket (e.g. LCR);
  - dummy - dummy handler without CC support.

Change-Id: I2df91c7a79ba5c39bc6ceae900ef649129dd0346
Related: OS#3400
---
M doc/examples/mobile/default.cfg
M doc/examples/mobile/multi_ms.cfg
M src/host/layer23/include/osmocom/bb/mobile/app_mobile.h
M src/host/layer23/include/osmocom/bb/mobile/settings.h
M src/host/layer23/src/mobile/app_mobile.c
M src/host/layer23/src/mobile/main.c
M src/host/layer23/src/mobile/mnccms.c
M src/host/layer23/src/mobile/settings.c
M src/host/layer23/src/mobile/vty_interface.c
9 files changed, 112 insertions(+), 36 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve
  fixeria: Looks good to me, approved



diff --git a/doc/examples/mobile/default.cfg b/doc/examples/mobile/default.cfg
index d78bef5..e24e07f 100644
--- a/doc/examples/mobile/default.cfg
+++ b/doc/examples/mobile/default.cfg
@@ -15,6 +15,7 @@
  layer2-socket /tmp/osmocom_l2
  sap-socket /tmp/osmocom_sap
  mncc-socket /tmp/ms_mncc_1
+ mncc-handler internal
  sim reader
  network-selection-mode auto
  imei 000000000000000 0
diff --git a/doc/examples/mobile/multi_ms.cfg b/doc/examples/mobile/multi_ms.cfg
index 4ccdb10..86a9840 100644
--- a/doc/examples/mobile/multi_ms.cfg
+++ b/doc/examples/mobile/multi_ms.cfg
@@ -15,6 +15,7 @@
  layer2-socket /tmp/osmocom_l2.one
  sap-socket /tmp/osmocom_sap.one
  mncc-socket /tmp/ms_mncc_one
+ mncc-handler internal
  sim reader
  network-selection-mode auto
  imei 000000000000000 0
@@ -68,6 +69,7 @@
  layer2-socket /tmp/osmocom_l2.two
  sap-socket /tmp/osmocom_sap.two
  mncc-socket /tmp/ms_mncc_two
+ mncc-handler internal
  sim reader
  network-selection-mode auto
  imei 000000000000000 0
diff --git a/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h 
b/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h
index 191f4ba..7a3669d 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/app_mobile.h
@@ -8,8 +8,7 @@
 struct osmocom_ms;
 struct vty;

-int l23_app_init(int (*mncc_recv)(struct osmocom_ms *ms, int, void *),
-       const char *config_file);
+int l23_app_init(const char *config_file);
 int l23_app_exit(void);
 int l23_app_work(int *quit);
 int mobile_delete(struct osmocom_ms *ms, int force);
diff --git a/src/host/layer23/include/osmocom/bb/mobile/settings.h 
b/src/host/layer23/include/osmocom/bb/mobile/settings.h
index 6f4f59c..d5620ff 100644
--- a/src/host/layer23/include/osmocom/bb/mobile/settings.h
+++ b/src/host/layer23/include/osmocom/bb/mobile/settings.h
@@ -3,6 +3,16 @@

 #define MOB_C7_DEFLT_ANY_TIMEOUT       30

+/* CC (Call Control) message handling entity */
+enum mncc_handler_t {
+       /* Built-in mobile's MNCC */
+       MNCC_HANDLER_INTERNAL,
+       /* External MNCC application via UNIX-socket */
+       MNCC_HANDLER_EXTERNAL,
+       /* No call support */
+       MNCC_HANDLER_DUMMY,
+};
+
 /* TCH frame I/O handler */
 enum audio_io_handler {
        /* No handler, drop frames */
@@ -24,6 +34,9 @@
        char                    sap_socket_path[128];
        char                    mncc_socket_path[128];

+       /* MNCC handler */
+       enum mncc_handler_t     mncc_handler;
+
        /* Audio settings */
        struct audio_settings   audio;

diff --git a/src/host/layer23/src/mobile/app_mobile.c 
b/src/host/layer23/src/mobile/app_mobile.c
index 5016582..dd67e70 100644
--- a/src/host/layer23/src/mobile/app_mobile.c
+++ b/src/host/layer23/src/mobile/app_mobile.c
@@ -51,9 +51,9 @@
 extern struct llist_head ms_list;
 extern int vty_reading;

-int mncc_recv_mobile(struct osmocom_ms *ms, int msg_type, void *arg);
+int mncc_recv_internal(struct osmocom_ms *ms, int msg_type, void *arg);
+int mncc_recv_external(struct osmocom_ms *ms, int msg_type, void *arg);
 int mncc_recv_dummy(struct osmocom_ms *ms, int msg_type, void *arg);
-int (*mncc_recv_app)(struct osmocom_ms *ms, int, void *);
 static int quit;

 /* handle ms instance */
@@ -237,6 +237,24 @@
                        "default IMEI.\n***\n");
        }

+       switch (ms->settings.mncc_handler) {
+       case MNCC_HANDLER_INTERNAL:
+               LOGP(DMOB, LOGL_INFO, "Using the built-in MNCC-handler for MS 
'%s'\n", ms->name);
+               ms->mncc_entity.mncc_recv = &mncc_recv_internal;
+               break;
+       case MNCC_HANDLER_EXTERNAL:
+               LOGP(DMOB, LOGL_INFO, "Using external MNCC-handler (socket 
'%s') for MS '%s'\n",
+                    ms->settings.mncc_socket_path, ms->name);
+               ms->mncc_entity.mncc_recv = &mncc_recv_external;
+               ms->mncc_entity.sock_state = mncc_sock_init(ms, 
ms->settings.mncc_socket_path);
+               break;
+       case MNCC_HANDLER_DUMMY:
+       default:
+               LOGP(DMOB, LOGL_INFO, "Using dummy MNCC-handler (no call 
support) "
+                       "for MS '%s'\n", ms->name);
+               ms->mncc_entity.mncc_recv = &mncc_recv_dummy;
+       }
+
        l1ctl_tx_reset_req(ms, L1CTL_RES_T_FULL);
        LOGP(DMOB, LOGL_NOTICE, "Mobile '%s' initialized, please start phone 
now!\n", ms->name);
        return 0;
@@ -319,15 +337,6 @@
 
        mobile_set_shutdown(ms, MS_SHUTDOWN_COMPL);

-       if (mncc_recv_app) {
-               ms->mncc_entity.mncc_recv = mncc_recv_app;
-               ms->mncc_entity.sock_state = mncc_sock_init(ms, 
ms->settings.mncc_socket_path);
-       } else if (ms->settings.ch_cap == GSM_CAP_SDCCH)
-               ms->mncc_entity.mncc_recv = mncc_recv_dummy;
-       else
-               ms->mncc_entity.mncc_recv = mncc_recv_mobile;
-
-
        return ms;
 }

@@ -338,7 +347,7 @@

        ms->deleting = true;

-       if (mncc_recv_app) {
+       if (ms->settings.mncc_handler == MNCC_HANDLER_EXTERNAL) {
                mncc_sock_exit(ms->mncc_entity.sock_state);
                ms->mncc_entity.sock_state = NULL;
        }
@@ -432,14 +441,11 @@
 };

 /* global init */
-int l23_app_init(int (*mncc_recv)(struct osmocom_ms *ms, int, void *),
-       const char *config_file)
+int l23_app_init(const char *config_file)
 {
        struct telnet_connection dummy_conn;
        int rc = 0;

-       mncc_recv_app = mncc_recv;
-
        osmo_gps_init();

        vty_info.tall_ctx = l23_ctx;
diff --git a/src/host/layer23/src/mobile/main.c 
b/src/host/layer23/src/mobile/main.c
index 9533553..926358e 100644
--- a/src/host/layer23/src/mobile/main.c
+++ b/src/host/layer23/src/mobile/main.c
@@ -48,11 +48,8 @@
 static const char *custom_cfg_file = NULL;
 struct gsmtap_inst *gsmtap_inst = NULL;
 char *config_dir = NULL;
-int use_mncc_sock = 0;
 int daemonize = 0;

-int mncc_recv_socket(struct osmocom_ms *ms, int msg_type, void *arg);
-
 int mobile_delete(struct osmocom_ms *ms, int force);
 int mobile_signal_cb(unsigned int subsys, unsigned int signal,
                     void *handler_data, void *signal_data);
@@ -85,8 +82,6 @@
                debug_default);
        printf("  -D --daemonize        Run as daemon\n");
        printf("  -c --config-file filename The config file to use.\n");
-       printf("  -m --mncc-sock        Disable built-in MNCC handler and "
-               "offer socket\n");
 }

 static int handle_options(int argc, char **argv)
@@ -99,8 +94,8 @@
                        {"debug", 1, 0, 'd'},
                        {"daemonize", 0, 0, 'D'},
                        {"config-file", 1, 0, 'c'},
-                       {"mncc-sock", 0, 0, 'm'},
                        /* DEPRECATED options, to be removed */
+                       {"mncc-sock", 0, 0, 'm'},
                        {"vty-ip", 1, 0, 'u'},
                        {"vty-port", 1, 0, 'v'},
                        {0, 0, 0, 0},
@@ -129,10 +124,12 @@
                case 'D':
                        daemonize = 1;
                        break;
-               case 'm':
-                       use_mncc_sock = 1;
-                       break;
                /* DEPRECATED options, to be removed */
+               case 'm':
+                       fprintf(stderr, "Option 'm' is deprecated! "
+                               "Please use the configuration file "
+                               "in order to change the MNCC handler.\n");
+                       return -EINVAL;
                case 'u':
                case 'v':
                        fprintf(stderr, "Both 'u' and 'v' options are "
@@ -253,10 +250,7 @@
        config_dir = talloc_strdup(l23_ctx, config_file);
        config_dir = dirname(config_dir);

-       if (use_mncc_sock)
-               rc = l23_app_init(mncc_recv_socket, config_file);
-       else
-               rc = l23_app_init(NULL, config_file);
+       rc = l23_app_init(config_file);
        if (rc)
                exit(rc);

diff --git a/src/host/layer23/src/mobile/mnccms.c 
b/src/host/layer23/src/mobile/mnccms.c
index 3fec11e..5accd5e 100644
--- a/src/host/layer23/src/mobile/mnccms.c
+++ b/src/host/layer23/src/mobile/mnccms.c
@@ -216,7 +216,7 @@
 /*
  * MNCCms call application via socket
  */
-int mncc_recv_socket(struct osmocom_ms *ms, int msg_type, void *arg)
+int mncc_recv_external(struct osmocom_ms *ms, int msg_type, void *arg)
 {
        struct mncc_sock_state *state = ms->mncc_entity.sock_state;
        struct gsm_mncc *mncc = arg;
@@ -253,7 +253,7 @@
  * MNCCms basic call application
  */

-int mncc_recv_mobile(struct osmocom_ms *ms, int msg_type, void *arg)
+int mncc_recv_internal(struct osmocom_ms *ms, int msg_type, void *arg)
 {
        struct gsm_settings *set = &ms->settings;
        struct gsm_mncc *data = arg;
diff --git a/src/host/layer23/src/mobile/settings.c 
b/src/host/layer23/src/mobile/settings.c
index 769fad6..3444d66 100644
--- a/src/host/layer23/src/mobile/settings.c
+++ b/src/host/layer23/src/mobile/settings.c
@@ -45,6 +45,9 @@
        /* Audio settings: drop TCH frames by default */
        set->audio.io_handler = AUDIO_IOH_NONE;

+       /* Built-in MNCC handler */
+       set->mncc_handler = MNCC_HANDLER_INTERNAL;
+
        /* network search */
        set->plmn_mode = PLMN_MODE_AUTO;

diff --git a/src/host/layer23/src/mobile/vty_interface.c 
b/src/host/layer23/src/mobile/vty_interface.c
index 7c757a6..9c3e429 100644
--- a/src/host/layer23/src/mobile/vty_interface.c
+++ b/src/host/layer23/src/mobile/vty_interface.c
@@ -1325,6 +1325,16 @@
                VTY_NEWLINE);
        vty_out(vty, " sap-socket %s%s", set->sap_socket_path, VTY_NEWLINE);
        vty_out(vty, " mncc-socket %s%s", set->mncc_socket_path, VTY_NEWLINE);
+       switch (set->mncc_handler) {
+       case MNCC_HANDLER_INTERNAL:
+               vty_out(vty, " mncc-handler internal%s", VTY_NEWLINE);
+               break;
+       case MNCC_HANDLER_EXTERNAL:
+               vty_out(vty, " mncc-handler external%s", VTY_NEWLINE);
+               break;
+       case MNCC_HANDLER_DUMMY:
+               vty_out(vty, " mncc-handler dummy%s", VTY_NEWLINE);
+       }
        switch(set->sim_type) {
                case GSM_SIM_TYPE_NONE:
                vty_out(vty, " sim none%s", VTY_NEWLINE);
@@ -1605,8 +1615,8 @@
        return CMD_SUCCESS;
 }

-DEFUN(cfg_ms_mncc, cfg_ms_mncc_cmd, "mncc-socket PATH",
-       "Define socket path for the MNCC interface\n"
+DEFUN(cfg_ms_mncc_sock, cfg_ms_mncc_sock_cmd, "mncc-socket PATH",
+       "Define socket path for MNCC interface\n"
        "UNIX socket path (default '/tmp/ms_mncc_' + MS_NAME)")
 {
        struct osmocom_ms *ms = vty->index;
@@ -1618,6 +1628,52 @@
        return CMD_SUCCESS;
 }

+DEFUN(cfg_ms_mncc_handler, cfg_ms_mncc_handler_cmd,
+      "mncc-handler (internal|external|dummy)",
+      "Set MNCC (Call Control) handler\n"
+      "Built-in MNCC handler (default)\n"
+      "External MNCC application via UNIX-socket (e.g. LCR)\n"
+      "Dummy MNCC handler (no Call Control)\n")
+{
+       struct osmocom_ms *ms = vty->index;
+       struct gsm_settings *set = &ms->settings;
+
+       switch (argv[0][0]) {
+       case 'i':
+               if (set->ch_cap == GSM_CAP_SDCCH) { /* SDCCH only */
+                       vty_out(vty, "TCH support is disabled, "
+                               "check 'channel-capability' param%s", 
VTY_NEWLINE);
+                       return CMD_WARNING;
+               }
+               set->mncc_handler = MNCC_HANDLER_INTERNAL;
+               break;
+       case 'e':
+               set->mncc_handler = MNCC_HANDLER_EXTERNAL;
+               break;
+       case 'd':
+               set->mncc_handler = MNCC_HANDLER_DUMMY;
+               break;
+       default:
+               /* Shall not happen */
+               OSMO_ASSERT(0);
+       }
+
+       vty_restart_if_started(vty, ms);
+       return CMD_SUCCESS;
+}
+
+DEFUN(cfg_ms_no_mncc_handler, cfg_ms_no_mncc_handler_cmd,
+      "no mncc-handler", NO_STR "Disable Call Control")
+{
+       struct osmocom_ms *ms = vty->index;
+       struct gsm_settings *set = &ms->settings;
+
+       set->mncc_handler = MNCC_HANDLER_DUMMY;
+
+       vty_restart_if_started(vty, ms);
+       return CMD_SUCCESS;
+}
+
 DEFUN(cfg_ms_sim, cfg_ms_sim_cmd, "sim (none|reader|test|sap)",
        "Set SIM card to attach when powering on\nAttach no SIM\n"
        "Attach SIM from reader\nAttach build in test SIM\n"
@@ -2947,7 +3003,9 @@
        install_element(MS_NODE, &cfg_ms_show_this_cmd);
        install_element(MS_NODE, &cfg_ms_layer2_cmd);
        install_element(MS_NODE, &cfg_ms_sap_cmd);
-       install_element(MS_NODE, &cfg_ms_mncc_cmd);
+       install_element(MS_NODE, &cfg_ms_mncc_sock_cmd);
+       install_element(MS_NODE, &cfg_ms_mncc_handler_cmd);
+       install_element(MS_NODE, &cfg_ms_no_mncc_handler_cmd);
        install_element(MS_NODE, &cfg_ms_sim_cmd);
        install_element(MS_NODE, &cfg_ms_mode_cmd);
        install_element(MS_NODE, &cfg_ms_imei_cmd);

--
To view, visit https://gerrit.osmocom.org/c/osmocom-bb/+/30326
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: osmocom-bb
Gerrit-Branch: master
Gerrit-Change-Id: I2df91c7a79ba5c39bc6ceae900ef649129dd0346
Gerrit-Change-Number: 30326
Gerrit-PatchSet: 3
Gerrit-Owner: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-Reviewer: pespin <pes...@sysmocom.de>
Gerrit-CC: msuraev <msur...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to