blob: 95eb089a0f51140851a9b7a8bf2729837d88ca5f [file] [log] [blame]
Harald Weltea9caad82020-02-14 14:32:02 +01001
2#include <signal.h>
3#include <unistd.h>
4#define _GNU_SOURCE
5#include <getopt.h>
6
7#include <osmocom/core/msgb.h>
8#include <osmocom/core/application.h>
9
10#include "client.h"
11
12static void *g_tall_ctx;
13void __thread *talloc_asn1_ctx;
14int asn_debug;
15
16static void handle_sig_usr1(int signal)
17{
18 OSMO_ASSERT(signal == SIGUSR1);
19 talloc_report_full(g_tall_ctx, stderr);
20}
21
22static void printf_help()
23{
24 printf(
25 " -h --help Print this help message\n"
26 " -i --server-ip A.B.C.D remsim-server IP address\n"
27 " -p --server-port 13245 remsim-server TCP port\n"
28 " -i --client-id <0-65535> RSPRO ClientId of this client\n"
29 " -n --client-slot <0-65535> RSPRO SlotNr of this client\n"
30 );
31}
32
33static void handle_options(struct bankd_client *bc, int argc, char **argv)
34{
35 while (1) {
36 int option_index = 0, c;
37 static const struct option long_options[] = {
38 { "help", 0, 0, 'h' },
39 { "server-ip", 1, 0, 'i' },
40 { "server-port", 1, 0, 'p' },
41 { "client-id", 1, 0, 'c' },
42 { "client-slot", 1, 0, 'n' },
43 { 0, 0, 0, 0 }
44 };
45
46 c = getopt_long(argc, argv, "hi:p:c:n:",
47 long_options, &option_index);
48 if (c == -1)
49 break;
50
51 switch (c) {
52 case 'h':
53 printf_help();
54 exit(0);
55 break;
56 case 'i':
57 bc->srv_conn.server_host = optarg;
58 break;
59 case 'p':
60 bc->srv_conn.server_port = atoi(optarg);
61 break;
62 case 'c':
63 remsim_client_set_clslot(bc, atoi(optarg), -1);
64 break;
65 case 'n':
66 remsim_client_set_clslot(bc, -1, atoi(optarg));
67 break;
68 default:
69 break;
70 }
71 }
72}
73
74int main(int argc, char **argv)
75{
76 struct bankd_client *g_client;
77 char hostname[256];
78
79 gethostname(hostname, sizeof(hostname));
80
81 g_tall_ctx = talloc_named_const(NULL, 0, "global");
82 talloc_asn1_ctx = talloc_named_const(g_tall_ctx, 0, "asn1");
83 msgb_talloc_ctx_init(g_tall_ctx, 0);
84
85 osmo_init_logging2(g_tall_ctx, &log_info);
86
87 g_client = remsim_client_create(g_tall_ctx, hostname, "remsim-client");
88
89 handle_options(g_client, argc, argv);
90
91 osmo_fsm_inst_dispatch(g_client->srv_conn.fi, SRVC_E_ESTABLISH, NULL);
92
93 signal(SIGUSR1, handle_sig_usr1);
94
95 asn_debug = 0;
96
97 client_user_main(g_client);
98}