blob: b60059d0cc5c7c234ff5dcfc0f73a1dfe2f4f011 [file] [log] [blame]
Harald Welte2ff0ab92018-08-17 22:10:49 +02001
2#include <errno.h>
3#include <string.h>
4
5#include <talloc.h>
6
7#include <osmocom/core/msgb.h>
8#include <osmocom/core/fsm.h>
9#include <osmocom/core/utils.h>
10#include <osmocom/core/logging.h>
11#include <osmocom/core/application.h>
12
13#include <osmocom/abis/ipa.h>
14#include <osmocom/gsm/protocol/ipaccess.h>
15
16#include "rspro_util.h"
Harald Welte24173fb2018-08-24 20:37:28 +020017#include "client.h"
Harald Welte2ff0ab92018-08-17 22:10:49 +020018
Harald Welte24173fb2018-08-24 20:37:28 +020019static int bankd_handle_msg(struct bankd_client *bc, struct msgb *msg)
Harald Welte2ff0ab92018-08-17 22:10:49 +020020{
Harald Welte24173fb2018-08-24 20:37:28 +020021 RsproPDU_t *pdu = rspro_dec_msg(msg);
22 if (!pdu) {
23 fprintf(stderr, "Error decoding PDU\n");
24 return -1;
Harald Welte2ff0ab92018-08-17 22:10:49 +020025 }
Harald Welte24173fb2018-08-24 20:37:28 +020026
27 switch (pdu->msg.present) {
28 case RsproPDUchoice_PR_connectClientRes:
Harald Welte417b9612018-09-24 14:53:41 +020029 osmo_fsm_inst_dispatch(bc->bankd_fi, BDC_E_CLIENT_CONN_RES, pdu);
Harald Welte24173fb2018-08-24 20:37:28 +020030 break;
31 default:
32 fprintf(stderr, "Unknown/Unsuppoerted RSPRO PDU: %s\n", msgb_hexdump(msg));
33 return -1;
34 }
35
36 return 0;
Harald Welte2ff0ab92018-08-17 22:10:49 +020037}
38
Harald Welte24173fb2018-08-24 20:37:28 +020039int bankd_read_cb(struct ipa_client_conn *conn, struct msgb *msg)
Harald Welte2ff0ab92018-08-17 22:10:49 +020040{
41 struct ipaccess_head *hh = (struct ipaccess_head *) msg->data;
42 struct ipaccess_head_ext *he = (struct ipaccess_head_ext *) msgb_l2(msg);
43 struct bankd_client *bc = conn->data;
Harald Welte24173fb2018-08-24 20:37:28 +020044 int rc;
Harald Welte2ff0ab92018-08-17 22:10:49 +020045
46 if (msgb_length(msg) < sizeof(*hh))
47 goto invalid;
48 msg->l2h = &hh->data[0];
49 if (hh->proto != IPAC_PROTO_OSMO)
50 goto invalid;
51 if (!he || msgb_l2len(msg) < sizeof(*he))
52 goto invalid;
53 msg->l2h = &he->data[0];
54
55 if (he->proto != IPAC_PROTO_EXT_RSPRO)
56 goto invalid;
57
Harald Welte2ff0ab92018-08-17 22:10:49 +020058 printf("Received RSPRO %s\n", msgb_hexdump(msg));
59
Harald Welte24173fb2018-08-24 20:37:28 +020060 rc = bankd_handle_msg(bc, msg);
Harald Welte24173fb2018-08-24 20:37:28 +020061
62 return rc;
Harald Welte2ff0ab92018-08-17 22:10:49 +020063
64invalid:
65 msgb_free(msg);
66 return -1;
67}
68
69static const struct log_info_cat default_categories[] = {
Harald Welte24173fb2018-08-24 20:37:28 +020070 [DMAIN] = {
71 .name = "DMAIN",
72 .loglevel = LOGL_DEBUG,
73 .enabled = 1,
74 },
Harald Welte2ff0ab92018-08-17 22:10:49 +020075};
76
77static const struct log_info log_info = {
78 .cat = default_categories,
79 .num_cat = ARRAY_SIZE(default_categories),
80};
81
Harald Welte24173fb2018-08-24 20:37:28 +020082static struct bankd_client *g_client;
Harald Welte2ff0ab92018-08-17 22:10:49 +020083static void *g_tall_ctx;
84void __thread *talloc_asn1_ctx;
Harald Welte43ab79f2018-10-03 23:34:21 +020085int asn_debug;
Harald Welte2ff0ab92018-08-17 22:10:49 +020086
87int main(int argc, char **argv)
88{
Harald Welte2ff0ab92018-08-17 22:10:49 +020089 g_tall_ctx = talloc_named_const(NULL, 0, "global");
90
Harald Welte24173fb2018-08-24 20:37:28 +020091 osmo_fsm_register(&remsim_client_bankd_fsm);
92 osmo_fsm_register(&remsim_client_server_fsm);
93
94 g_client = talloc_zero(g_tall_ctx, struct bankd_client);
95 g_client->bankd_host = "localhost";
96 g_client->bankd_port = 9999;
97 g_client->own_comp_id.type = ComponentType_remsimClient;
98 OSMO_STRLCPY_ARRAY(g_client->own_comp_id.name, "fixme-name");
99 OSMO_STRLCPY_ARRAY(g_client->own_comp_id.software, "remsim-client");
100 OSMO_STRLCPY_ARRAY(g_client->own_comp_id.sw_version, PACKAGE_VERSION);
Harald Welte2ff0ab92018-08-17 22:10:49 +0200101
Harald Welte43ab79f2018-10-03 23:34:21 +0200102 asn_debug = 0;
Harald Welte2ff0ab92018-08-17 22:10:49 +0200103 osmo_init_logging2(g_tall_ctx, &log_info);
104
Harald Welte24173fb2018-08-24 20:37:28 +0200105 if (bankd_conn_fsm_alloc(g_client) < 0) {
Harald Welte2ff0ab92018-08-17 22:10:49 +0200106 fprintf(stderr, "Unable to connect: %s\n", strerror(errno));
107 exit(1);
108 }
Harald Welte2ff0ab92018-08-17 22:10:49 +0200109
110 while (1) {
111 osmo_select_main(0);
112 }
113}