Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 1 | #include <stdint.h> |
| 2 | #include <unistd.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include <string.h> |
| 6 | |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 7 | #define _GNU_SOURCE |
| 8 | #include <getopt.h> |
| 9 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 10 | #include <osmocom/core/select.h> |
| 11 | #include <osmocom/core/prim.h> |
| 12 | #include <osmocom/core/talloc.h> |
| 13 | #include <osmocom/core/logging.h> |
| 14 | #include <osmocom/core/application.h> |
| 15 | #include <osmocom/vty/logging.h> |
| 16 | |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 17 | #include <osmocom/gsm/gsm48.h> |
| 18 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 19 | #include <osmocom/sigtran/sua.h> |
| 20 | #include <osmocom/sigtran/sccp_sap.h> |
| 21 | |
| 22 | #include "test_common.h" |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 23 | |
Neels Hofmeyr | 96979af | 2016-01-05 15:19:44 +0100 | [diff] [blame] | 24 | #include <osmocom/ranap/ranap_ies_defs.h> |
Daniel Willmann | b02d77c | 2016-01-07 12:59:21 +0100 | [diff] [blame] | 25 | #include <osmocom/ranap/ranap_common_cn.h> |
Neels Hofmeyr | b9f46a7 | 2016-01-13 11:51:34 +0100 | [diff] [blame] | 26 | #include <osmocom/ranap/ranap_msg_factory.h> |
Neels Hofmeyr | df63de2 | 2016-08-18 13:13:55 +0200 | [diff] [blame] | 27 | #include <osmocom/iuh/hnbgw.h> |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 28 | |
| 29 | int asn1_xer_print = 1; |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 30 | const char *cmdline_bind_addr = "127.0.0.1"; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 31 | |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 32 | struct ue_conn_ctx { |
| 33 | struct llist_head list; |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 34 | struct osmo_sccp_link *link; |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 35 | uint32_t conn_id; |
| 36 | }; |
| 37 | |
| 38 | static LLIST_HEAD(conn_ctx_list); |
| 39 | |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 40 | struct ue_conn_ctx *ue_conn_ctx_alloc(struct osmo_sccp_link *link, uint32_t conn_id) |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 41 | { |
| 42 | struct ue_conn_ctx *ctx = talloc_zero(NULL, struct ue_conn_ctx); |
| 43 | |
| 44 | ctx->link = link; |
| 45 | ctx->conn_id = conn_id; |
| 46 | llist_add(&ctx->list, &conn_ctx_list); |
| 47 | |
| 48 | return ctx; |
| 49 | } |
| 50 | |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 51 | struct ue_conn_ctx *ue_conn_ctx_find(struct osmo_sccp_link *link, uint32_t conn_id) |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 52 | { |
| 53 | struct ue_conn_ctx *ctx; |
| 54 | |
| 55 | llist_for_each_entry(ctx, &conn_ctx_list, list) { |
| 56 | if (ctx->link == link && ctx->conn_id == conn_id) |
| 57 | return ctx; |
| 58 | } |
| 59 | return NULL; |
| 60 | } |
| 61 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 62 | /*********************************************************************** |
| 63 | * RANAP handling |
| 64 | ***********************************************************************/ |
| 65 | |
Daniel Willmann | b39bad1 | 2016-01-14 15:36:12 +0100 | [diff] [blame] | 66 | static int ranap_handle_co_initial_ue(struct ue_conn_ctx *ctx, RANAP_InitialUE_MessageIEs_t *ies) |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 67 | { |
| 68 | struct gprs_ra_id ra_id; |
| 69 | uint16_t sai; |
| 70 | struct msgb *msg = msgb_alloc(256, "RANAP->NAS"); |
| 71 | uint8_t *cur; |
Daniel Willmann | b39bad1 | 2016-01-14 15:36:12 +0100 | [diff] [blame] | 72 | struct osmo_scu_prim *prim; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 73 | |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 74 | ranap_parse_lai(&ra_id, &ies->lai); |
| 75 | sai = asn1str_to_u16(&ies->sai.sAC); |
| 76 | cur = msgb_put(msg, ies->nas_pdu.size); |
| 77 | memcpy(msg, ies->nas_pdu.buf, ies->nas_pdu.size); |
Daniel Willmann | b39bad1 | 2016-01-14 15:36:12 +0100 | [diff] [blame] | 78 | msgb_free(msg); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 79 | /* FIXME: set msgb_gmmh() */ |
| 80 | |
| 81 | /* FIXME: Feed into the MM layer */ |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 82 | //rc = gsm0408_gprs_rcvmsg_iu(msg, ra_id, sai, conn_id); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 83 | |
Daniel Willmann | b39bad1 | 2016-01-14 15:36:12 +0100 | [diff] [blame] | 84 | msg = ranap_new_msg_dt(0, NULL, 0); |
| 85 | |
| 86 | msg->l2h = msg->data; |
| 87 | prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim)); |
| 88 | prim->u.data.conn_id = ctx->conn_id; |
| 89 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, OSMO_SCU_PRIM_N_DATA, |
| 90 | PRIM_OP_REQUEST, msg); |
| 91 | |
| 92 | osmo_sua_user_link_down(ctx->link, &prim->oph); |
| 93 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | static int ranap_handle_co_dt(void *ctx, RANAP_DirectTransferIEs_t *ies) |
| 98 | { |
| 99 | struct gprs_ra_id _ra_id, *ra_id = NULL; |
| 100 | uint16_t _sai, *sai = NULL; |
| 101 | struct msgb *msg = msgb_alloc(256, "RANAP->NAS"); |
| 102 | uint8_t *cur; |
| 103 | |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 104 | if (ies->presenceMask & DIRECTTRANSFERIES_RANAP_LAI_PRESENT) { |
| 105 | ranap_parse_lai(&_ra_id, &ies->lai); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 106 | ra_id = &_ra_id; |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 107 | if (ies->presenceMask & DIRECTTRANSFERIES_RANAP_RAC_PRESENT) { |
| 108 | _ra_id.rac = asn1str_to_u8(&ies->rac); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 109 | } |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 110 | if (ies->presenceMask & DIRECTTRANSFERIES_RANAP_SAI_PRESENT) { |
| 111 | _sai = asn1str_to_u16(&ies->sai.sAC); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 112 | sai = &_sai; |
| 113 | } |
| 114 | } |
| 115 | |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 116 | cur = msgb_put(msg, ies->nas_pdu.size); |
| 117 | memcpy(msg, ies->nas_pdu.buf, ies->nas_pdu.size); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 118 | /* FIXME: set msgb_gmmh() */ |
| 119 | |
| 120 | /* FIXME: Feed into the MM/CC/SMS-CP layer */ |
Harald Welte | 1be24f1 | 2015-12-26 23:44:28 +0100 | [diff] [blame] | 121 | //rc = gsm0408_gprs_rcvmsg_iu(msg, ra_id, sai, conn_id); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | static int ranap_handle_co_err_ind(void *ctx, RANAP_ErrorIndicationIEs_t *ies) |
| 127 | { |
| 128 | if (ies->presenceMask & ERRORINDICATIONIES_RANAP_CAUSE_PRESENT) |
| 129 | LOGP(DRANAP, LOGL_ERROR, "Rx Error Indication (%s)\n", |
| 130 | ranap_cause_str(&ies->cause)); |
| 131 | else |
| 132 | LOGP(DRANAP, LOGL_ERROR, "Rx Error Indication\n"); |
| 133 | |
| 134 | return 0; |
| 135 | } |
| 136 | |
Harald Welte | 0744d6f | 2015-12-26 23:45:18 +0100 | [diff] [blame] | 137 | static int ranap_handle_co_iu_rel_req(struct ue_conn_ctx *ctx, RANAP_Iu_ReleaseRequestIEs_t *ies) |
| 138 | { |
| 139 | struct msgb *msg; |
| 140 | struct osmo_scu_prim *prim; |
| 141 | |
| 142 | LOGP(DRANAP, LOGL_INFO, "Received Iu Release Request, Sending Release Command\n"); |
| 143 | msg = ranap_new_msg_iu_rel_cmd(&ies->cause); |
| 144 | msg->l2h = msg->data; |
| 145 | prim = (struct osmo_scu_prim *) msgb_push(msg, sizeof(*prim)); |
| 146 | prim->u.data.conn_id = ctx->conn_id; |
| 147 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, |
| 148 | OSMO_SCU_PRIM_N_DATA, |
| 149 | PRIM_OP_REQUEST, msg); |
| 150 | osmo_sua_user_link_down(ctx->link, &prim->oph); |
| 151 | return 0; |
| 152 | } |
| 153 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 154 | /* Entry point for connection-oriented ANAP message */ |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 155 | static void cn_ranap_handle_co(void *ctx, ranap_message *message) |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 156 | { |
| 157 | int rc = 0; |
| 158 | |
| 159 | switch (message->direction) { |
| 160 | case RANAP_RANAP_PDU_PR_initiatingMessage: |
| 161 | switch (message->procedureCode) { |
| 162 | case RANAP_ProcedureCode_id_InitialUE_Message: |
| 163 | rc = ranap_handle_co_initial_ue(ctx, &message->msg.initialUE_MessageIEs); |
| 164 | break; |
| 165 | case RANAP_ProcedureCode_id_DirectTransfer: |
| 166 | rc = ranap_handle_co_dt(ctx, &message->msg.directTransferIEs); |
| 167 | break; |
| 168 | case RANAP_ProcedureCode_id_ErrorIndication: |
| 169 | rc = ranap_handle_co_err_ind(ctx, &message->msg.errorIndicationIEs); |
| 170 | break; |
Harald Welte | 0744d6f | 2015-12-26 23:45:18 +0100 | [diff] [blame] | 171 | case RANAP_ProcedureCode_id_Iu_ReleaseRequest: |
| 172 | /* Iu Release Request */ |
| 173 | rc = ranap_handle_co_iu_rel_req(ctx, &message->msg.iu_ReleaseRequestIEs); |
| 174 | break; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 175 | } |
| 176 | break; |
| 177 | case RANAP_RANAP_PDU_PR_successfulOutcome: |
| 178 | switch (message->procedureCode) { |
| 179 | case RANAP_ProcedureCode_id_RAB_Assignment: |
| 180 | /* RAB Assignment Response */ |
| 181 | break; |
| 182 | case RANAP_ProcedureCode_id_SecurityModeControl: |
| 183 | /* Security Mode Complete */ |
| 184 | break; |
| 185 | case RANAP_ProcedureCode_id_Iu_Release: |
| 186 | /* Iu Release Complete */ |
| 187 | break; |
| 188 | } |
| 189 | case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: |
| 190 | case RANAP_RANAP_PDU_PR_outcome: |
| 191 | default: |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 192 | break; |
| 193 | } |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int ranap_handle_cl_reset_req(void *ctx, RANAP_ResetIEs_t *ies) |
| 197 | { |
| 198 | /* FIXME: send reset response */ |
Neels Hofmeyr | 0968a58 | 2016-01-11 15:19:38 +0100 | [diff] [blame] | 199 | |
| 200 | LOGP(DRANAP, LOGL_ERROR, "Rx Reset Request\n"); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | static int ranap_handle_cl_err_ind(void *ctx, RANAP_ErrorIndicationIEs_t *ies) |
| 204 | { |
| 205 | if (ies->presenceMask & ERRORINDICATIONIES_RANAP_CAUSE_PRESENT) |
| 206 | LOGP(DRANAP, LOGL_ERROR, "Rx Error Indication (%s)\n", |
| 207 | ranap_cause_str(&ies->cause)); |
| 208 | else |
| 209 | LOGP(DRANAP, LOGL_ERROR, "Rx Error Indication\n"); |
| 210 | |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | /* Entry point for connection-less RANAP message */ |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 215 | static void cn_ranap_handle_cl(void *ctx, ranap_message *message) |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 216 | { |
| 217 | int rc = 0; |
| 218 | |
| 219 | switch (message->direction) { |
| 220 | case RANAP_RANAP_PDU_PR_initiatingMessage: |
| 221 | switch (message->procedureCode) { |
| 222 | case RANAP_ProcedureCode_id_Reset: |
| 223 | /* received reset.req, send reset.resp */ |
| 224 | rc = ranap_handle_cl_reset_req(ctx, &message->msg.resetIEs); |
| 225 | break; |
| 226 | case RANAP_ProcedureCode_id_ErrorIndication: |
| 227 | rc = ranap_handle_cl_err_ind(ctx, &message->msg.errorIndicationIEs); |
| 228 | break; |
| 229 | } |
| 230 | break; |
| 231 | case RANAP_RANAP_PDU_PR_successfulOutcome: |
| 232 | case RANAP_RANAP_PDU_PR_unsuccessfulOutcome: |
| 233 | case RANAP_RANAP_PDU_PR_outcome: |
| 234 | default: |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 235 | break; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /*********************************************************************** |
| 240 | * |
| 241 | ***********************************************************************/ |
| 242 | |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 243 | int tx_unitdata(struct osmo_sccp_link *link); |
| 244 | int tx_conn_req(struct osmo_sccp_link *link, uint32_t conn_id); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 245 | |
| 246 | struct osmo_prim_hdr *make_conn_req(uint32_t conn_id); |
| 247 | struct osmo_prim_hdr *make_dt1_req(uint32_t conn_id, const uint8_t *data, unsigned int len); |
| 248 | |
| 249 | struct osmo_prim_hdr *make_conn_resp(struct osmo_scu_connect_param *param) |
| 250 | { |
| 251 | struct msgb *msg = msgb_alloc(1024, "conn_resp"); |
| 252 | struct osmo_scu_prim *prim; |
| 253 | |
| 254 | prim = (struct osmo_scu_prim *) msgb_put(msg, sizeof(*prim)); |
| 255 | osmo_prim_init(&prim->oph, SCCP_SAP_USER, |
| 256 | OSMO_SCU_PRIM_N_CONNECT, |
| 257 | PRIM_OP_RESPONSE, msg); |
| 258 | memcpy(&prim->u.connect, param, sizeof(prim->u.connect)); |
| 259 | return &prim->oph; |
| 260 | } |
| 261 | |
| 262 | static int sccp_sap_up(struct osmo_prim_hdr *oph, void *link) |
| 263 | { |
| 264 | struct osmo_scu_prim *prim = (struct osmo_scu_prim *) oph; |
| 265 | struct osmo_prim_hdr *resp = NULL; |
| 266 | const uint8_t payload[] = { 0xb1, 0xb2, 0xb3 }; |
| 267 | int rc; |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 268 | struct ue_conn_ctx *ue; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 269 | |
| 270 | printf("sccp_sap_up(%s)\n", osmo_scu_prim_name(oph)); |
| 271 | |
| 272 | switch (OSMO_PRIM_HDR(oph)) { |
| 273 | case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_CONFIRM): |
| 274 | /* confirmation of outbound connection */ |
| 275 | break; |
| 276 | case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION): |
| 277 | /* indication of new inbound connection request*/ |
| 278 | printf("N-CONNECT.ind(X->%u)\n", prim->u.connect.conn_id); |
| 279 | if (/* prim->u.connect.called_addr.ssn != OSMO_SCCP_SSN_RANAP || */ |
| 280 | !msgb_l2(oph->msg) || msgb_l2len(oph->msg) == 0) { |
| 281 | LOGP(DMAIN, LOGL_NOTICE, "Received invalid N-CONNECT.ind\n"); |
| 282 | return 0; |
| 283 | } |
| 284 | /* FIXME: allocate UE context */ |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 285 | ue = ue_conn_ctx_alloc(link, prim->u.connect.conn_id); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 286 | /* first ensure the local SUA/SCCP socket is ACTIVE */ |
| 287 | resp = make_conn_resp(&prim->u.connect); |
| 288 | osmo_sua_user_link_down(link, resp); |
| 289 | /* then handle the RANAP payload */ |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 290 | rc = ranap_cn_rx_co(cn_ranap_handle_co, ue, msgb_l2(oph->msg), msgb_l2len(oph->msg)); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 291 | break; |
| 292 | case OSMO_PRIM(OSMO_SCU_PRIM_N_DISCONNECT, PRIM_OP_INDICATION): |
| 293 | /* indication of disconnect */ |
| 294 | printf("N-DISCONNECT.ind(%u)\n", prim->u.disconnect.conn_id); |
Harald Welte | 4e2783f | 2015-12-26 23:49:52 +0100 | [diff] [blame] | 295 | ue = ue_conn_ctx_find(link, prim->u.disconnect.conn_id); |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 296 | rc = ranap_cn_rx_co(cn_ranap_handle_co, ue, msgb_l2(oph->msg), msgb_l2len(oph->msg)); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 297 | break; |
| 298 | case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION): |
| 299 | /* connection-oriented data received */ |
| 300 | printf("N-DATA.ind(%u, %s)\n", prim->u.data.conn_id, |
| 301 | osmo_hexdump(msgb_l2(oph->msg), msgb_l2len(oph->msg))); |
Harald Welte | 2bc20f8 | 2015-12-26 23:43:48 +0100 | [diff] [blame] | 302 | /* resolve UE context */ |
| 303 | ue = ue_conn_ctx_find(link, prim->u.data.conn_id); |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 304 | rc = ranap_cn_rx_co(cn_ranap_handle_co, ue, msgb_l2(oph->msg), msgb_l2len(oph->msg)); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 305 | break; |
| 306 | case OSMO_PRIM(OSMO_SCU_PRIM_N_UNITDATA, PRIM_OP_INDICATION): |
| 307 | /* connection-oriented data received */ |
| 308 | printf("N-UNITDATA.ind(%s)\n", |
| 309 | osmo_hexdump(msgb_l2(oph->msg), msgb_l2len(oph->msg))); |
Harald Welte | 8fa5d55 | 2016-01-05 15:01:53 +0100 | [diff] [blame] | 310 | rc = ranap_cn_rx_cl(cn_ranap_handle_cl, link, msgb_l2(oph->msg), msgb_l2len(oph->msg)); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 311 | break; |
| 312 | } |
| 313 | |
| 314 | msgb_free(oph->msg); |
| 315 | return 0; |
| 316 | } |
| 317 | |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 318 | static void print_usage() |
| 319 | { |
| 320 | printf("Usage: dummy-cn\n"); |
| 321 | } |
| 322 | |
| 323 | static void print_help() |
| 324 | { |
| 325 | printf(" -h --help This text.\n"); |
| 326 | printf(" -b --bind addr Bind to local IP address (default 127.0.0.1)\n"); |
| 327 | } |
| 328 | |
| 329 | static void handle_options(int argc, char **argv) |
| 330 | { |
| 331 | while (1) { |
| 332 | int option_index = 0, c; |
| 333 | static struct option long_options[] = { |
| 334 | {"help", 0, 0, 'h'}, |
| 335 | {"bind", 1, 0, 'b'}, |
| 336 | {0, 0, 0, 0} |
| 337 | }; |
| 338 | |
| 339 | c = getopt_long(argc, argv, "hb:V", |
| 340 | long_options, &option_index); |
| 341 | if (c == -1) |
| 342 | break; |
| 343 | |
| 344 | switch (c) { |
| 345 | case 'h': |
| 346 | print_usage(); |
| 347 | print_help(); |
| 348 | exit(0); |
| 349 | case 'b': |
| 350 | cmdline_bind_addr = optarg; |
| 351 | break; |
| 352 | default: |
| 353 | printf("Unknown cmdline argument (-h shows help)\n"); |
| 354 | exit(1); |
| 355 | break; |
| 356 | } |
| 357 | } |
| 358 | } |
| 359 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 360 | int main(int argc, char **argv) |
| 361 | { |
Neels Hofmeyr | 0a43722 | 2016-07-06 15:58:48 +0200 | [diff] [blame] | 362 | struct osmo_sccp_user *user; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 363 | void *ctx = talloc_named_const(NULL, 1, "root"); |
| 364 | int rc; |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 365 | int port = 14001; |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 366 | |
| 367 | osmo_sua_set_log_area(DSUA); |
Harald Welte | bdf3fd1 | 2016-01-03 17:04:09 +0100 | [diff] [blame] | 368 | ranap_set_log_area(DRANAP); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 369 | |
| 370 | test_common_init(); |
| 371 | |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 372 | handle_options(argc, argv); |
| 373 | |
Harald Welte | 2ebe42f | 2015-12-26 23:38:38 +0100 | [diff] [blame] | 374 | user = osmo_sua_user_create(ctx, sccp_sap_up, ctx); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 375 | |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 376 | rc = osmo_sua_server_listen(user, cmdline_bind_addr, port); |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 377 | if (rc < 0) { |
| 378 | exit(1); |
| 379 | } |
| 380 | |
Neels Hofmeyr | 3d12748 | 2016-04-20 11:04:49 +0200 | [diff] [blame] | 381 | printf("dummy-cn listening on %s %d\n", cmdline_bind_addr, port); |
| 382 | |
Harald Welte | 3aad6af | 2015-12-26 08:43:04 +0100 | [diff] [blame] | 383 | while (1) { |
| 384 | osmo_select_main(0); |
| 385 | } |
| 386 | } |