From b5b809da0b18fcb0d4840ea567130b31b8524ca0 Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Wed, 21 Jun 2017 13:18:07 +0200 Subject: reset: fixup for reset We now perform the reset procedure on both sides. Also both sides will clear now their open SCCP connections. --- openbsc/include/openbsc/a_iface.h | 6 + openbsc/include/openbsc/a_iface_bssap.h | 13 +- openbsc/include/openbsc/bsc_msc.h | 2 - openbsc/src/libcommon-cs/a_reset.c | 17 ++- openbsc/src/libmsc/a_iface.c | 213 ++++++++++++++++++++++++-------- openbsc/src/libmsc/a_iface_bssap.c | 77 +++++------- openbsc/src/osmo-bsc/osmo_bsc_bssap.c | 4 +- openbsc/src/osmo-bsc/osmo_bsc_sigtran.c | 40 ++++-- 8 files changed, 245 insertions(+), 127 deletions(-) diff --git a/openbsc/include/openbsc/a_iface.h b/openbsc/include/openbsc/a_iface.h index 483ffa47f..34dfca67a 100644 --- a/openbsc/include/openbsc/a_iface.h +++ b/openbsc/include/openbsc/a_iface.h @@ -35,4 +35,10 @@ int a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac); /* Send assignment request via A-interface */ int a_iface_tx_assignment(struct gsm_trans *trans); +/* Clear all subscriber connections on a specified BSC */ +void a_clear_all(struct osmo_sccp_user *scu, struct osmo_sccp_addr *bsc_addr); + +/* Delete info of a closed connection from the active connection list */ +void a_delete_bsc_con(uint32_t conn_id); + #pragma once diff --git a/openbsc/include/openbsc/a_iface_bssap.h b/openbsc/include/openbsc/a_iface_bssap.h index 211bcf2d9..f0a2187ef 100644 --- a/openbsc/include/openbsc/a_iface_bssap.h +++ b/openbsc/include/openbsc/a_iface_bssap.h @@ -28,16 +28,9 @@ struct a_conn_info { struct osmo_sccp_addr *called_addr; struct osmo_sccp_addr *calling_addr; - int conn_id; + uint32_t conn_id; struct gsm_network *network; -}; - -/* A structure to pack BSC calling addresses into a list */ -struct a_bsc_addr { - struct llist_head list; - struct osmo_sccp_addr called_addr; - struct osmo_sccp_addr calling_addr; - struct osmo_sccp_user *scu; + struct a_reset_ctx *reset; }; /* Receive incoming connection less data messages via sccp */ @@ -46,5 +39,3 @@ void sccp_rx_udt(struct osmo_sccp_user *scu, struct a_conn_info *a_conn_info, st /* Receive incoming connection oriented data messages via sccp */ int sccp_rx_dt(struct osmo_sccp_user *scu, struct a_conn_info *a_conn_info, struct msgb *msg); -/* Get a list with all known BSCs */ -struct llist_head *get_bsc_addr_list(void); diff --git a/openbsc/include/openbsc/bsc_msc.h b/openbsc/include/openbsc/bsc_msc.h index a7c881b84..35b8654d5 100644 --- a/openbsc/include/openbsc/bsc_msc.h +++ b/openbsc/include/openbsc/bsc_msc.h @@ -62,8 +62,6 @@ struct bsc_msc_connection { struct osmo_sccp_addr g_calling_addr; struct osmo_sccp_addr g_called_addr; struct a_reset_ctx reset; - - int conn_id_counter; }; struct bsc_msc_connection *bsc_msc_create(void *ctx, struct llist_head *dest); diff --git a/openbsc/src/libcommon-cs/a_reset.c b/openbsc/src/libcommon-cs/a_reset.c index 94d215562..7eebb152d 100644 --- a/openbsc/src/libcommon-cs/a_reset.c +++ b/openbsc/src/libcommon-cs/a_reset.c @@ -158,7 +158,10 @@ void a_reset_ack_confirm(struct a_reset_ctx *reset) /* Report a failed connection */ void a_reset_conn_fail(struct a_reset_ctx *reset) { - OSMO_ASSERT(reset); + /* If no reset context is supplied, just drop the info */ + if (!reset) + return; + OSMO_ASSERT(reset->fsm); osmo_fsm_inst_dispatch(reset->fsm, EV_N_DISCONNECT, reset); @@ -167,7 +170,10 @@ void a_reset_conn_fail(struct a_reset_ctx *reset) /* Report a successful connection */ void a_reset_conn_success(struct a_reset_ctx *reset) { - OSMO_ASSERT(reset); + /* If no reset context is supplied, just drop the info */ + if (!reset) + return; + OSMO_ASSERT(reset->fsm); osmo_fsm_inst_dispatch(reset->fsm, EV_N_CONNECT, reset); @@ -176,9 +182,12 @@ void a_reset_conn_success(struct a_reset_ctx *reset) /* Check if we have a connection to a specified msc */ bool a_reset_conn_ready(struct a_reset_ctx *reset) { - OSMO_ASSERT(reset); - OSMO_ASSERT(reset->fsm); + /* If no reset context is supplied, we assume that + * the connection can't be ready! */ + if (!reset) + return false; + OSMO_ASSERT(reset->fsm); if (reset->fsm->state == ST_CONN) return true; diff --git a/openbsc/src/libmsc/a_iface.c b/openbsc/src/libmsc/a_iface.c index 85fabe5ed..d4b73080b 100644 --- a/openbsc/src/libmsc/a_iface.c +++ b/openbsc/src/libmsc/a_iface.c @@ -38,6 +38,7 @@ #include #include #include +#include #define SSN_BSSAP 254 /* SCCP_SSN_BSSAP */ #define SENDER_PC 1 /* Our local point code */ @@ -47,15 +48,99 @@ * when calling a_init() */ static struct gsm_network *gsm_network = NULL; +/* A struct to track currently active connections. We need that information + * to handle failure sitautions. In case of a problem, we must know which + * connections are currently open and which BSC is responsible. We also need + * the data to perform our connection checks (a_reset). All other logic will + * look at the connection ids and addresses that are supplied by the + * primitives */ +struct bsc_conn { + struct llist_head list; + struct osmo_sccp_addr called_addr; /* BSC (remote) */ + struct osmo_sccp_addr calling_addr; /* MSC (local) */ + uint32_t conn_id; /* Connection identifier */ +}; + +/* Internal list with connections we currently maintain. This + * list is of type struct bsc_conn (see above) */ +static LLIST_HEAD(active_connections); + +/* Context information about the BSC, will be used only internally in this + * file to manage the BSCs we are associated with */ struct bsc_context { struct llist_head list; - struct a_reset_ctx reset; - struct osmo_sccp_addr addr; + struct a_reset_ctx reset; /* Reset FSM (one per BSC) */ + struct osmo_sccp_addr called_addr; /* BSC (remote) */ + struct osmo_sccp_addr calling_addr; /* MSC (local) */ + struct osmo_sccp_user *sccp_user; /* SCCP user (the same for all) */ }; +/* List with BSCs we are associated with. This list is of type + * struct bsc_context (see above) */ static LLIST_HEAD(bsc_context_list); +/* Record info of a new active connection in the active connection list */ +static void record_bsc_con(void *ctx, struct osmo_sccp_addr *called_addr, struct osmo_sccp_addr *calling_addr, + uint32_t conn_id) +{ + struct bsc_conn *conn; + + conn = talloc_zero(ctx, struct bsc_conn); + OSMO_ASSERT(conn); + + memcpy(&conn->called_addr, called_addr, sizeof(*called_addr)); + memcpy(&conn->calling_addr, calling_addr, sizeof(*calling_addr)); + conn->conn_id = conn_id; + + llist_add_tail(&conn->list, &active_connections); +} + +/* Delete info of a closed connection from the active connection list */ +void a_delete_bsc_con(uint32_t conn_id) +{ + struct bsc_conn *conn; + struct bsc_conn *conn_temp; + + llist_for_each_entry_safe(conn, conn_temp, &active_connections, list) { + if (conn->conn_id == conn_id) { + llist_del(&conn->list); + talloc_free(conn); + } + } +} + +/* Check if a specified connection id has an active SCCP connection */ +static bool check_connection_active(uint32_t conn_id) +{ + struct bsc_conn *conn; + /* Find the address for the current connection id */ + llist_for_each_entry(conn, &active_connections, list) { + if (conn->conn_id == conn_id) { + return true; + } + } + + return false; +} + +/* Get the reset context for a specifiec calling (BSC) address */ +static struct a_reset_ctx *get_reset_ctx_by_sccp_addr(struct osmo_sccp_addr *addr) +{ + struct bsc_context *bsc_ctx; + + if (!addr) + return NULL; + + llist_for_each_entry(bsc_ctx, &bsc_context_list, list) { + if (memcmp(&bsc_ctx->called_addr, addr, sizeof(*addr)) == 0) + return &bsc_ctx->reset; + } + + LOGP(DMSC, LOGL_ERROR, "The calling BSC (%s) is unknown to this MSC ...\n", + osmo_sccp_addr_dump(addr)); + return NULL; +} /* Send DTAP message via A-interface */ int a_iface_tx_dtap(struct msgb *msg) @@ -121,9 +206,9 @@ int a_iface_tx_cipher_mode(struct gsm_subscriber_connection *conn, /* Page a subscriber via A-interface */ int a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac) { - struct a_bsc_addr *addr; - struct llist_head *bsc_addr_list = get_bsc_addr_list(); + struct bsc_context *bsc_ctx; struct gsm0808_cell_id_list cil; + struct msgb *msg; int page_count = 0; cil.id_discr = CELL_IDENT_LAC; @@ -131,16 +216,26 @@ int a_iface_tx_paging(const char *imsi, uint32_t tmsi, uint16_t lac) cil.id_list_len = 1; /* Deliver paging request to all known BSCs */ - llist_for_each_entry(addr, bsc_addr_list, list) { - LOGP(DMSC, LOGL_DEBUG, "Passing paging message from MSC to BSC %s (imsi=%s, tmsi=0x%08x, lac=%u)\n", - osmo_sccp_addr_dump(&addr->calling_addr), imsi, tmsi, lac); - osmo_sccp_tx_unitdata_msg(addr->scu, &addr->called_addr, &addr->calling_addr, - gsm0808_create_paging(imsi, &tmsi, &cil, NULL)); - page_count++; + llist_for_each_entry(bsc_ctx, &bsc_context_list, list) { + if (a_reset_conn_ready(&bsc_ctx->reset)) { + LOGP(DMSC, LOGL_DEBUG, + "Passing paging message from MSC %s to BSC %s (imsi=%s, tmsi=0x%08x, lac=%u)\n", + osmo_sccp_addr_dump(&bsc_ctx->calling_addr), + osmo_sccp_addr_dump(&bsc_ctx->called_addr), imsi, tmsi, lac); + msg = gsm0808_create_paging(imsi, &tmsi, &cil, NULL); + osmo_sccp_tx_unitdata_msg(bsc_ctx->sccp_user, + &bsc_ctx->calling_addr, &bsc_ctx->called_addr, msg); + page_count++; + } else { + LOGP(DMSC, LOGL_DEBUG, + "Connection down, dropping paging from MSC %s to BSC %s (imsi=%s, tmsi=0x%08x, lac=%u)\n", + osmo_sccp_addr_dump(&bsc_ctx->calling_addr), + osmo_sccp_addr_dump(&bsc_ctx->called_addr), imsi, tmsi, lac); + } } if (page_count <= 0) - LOGP(DMSC, LOGL_ERROR, "Could not deliver paging because no BSC is available!\n"); + LOGP(DMSC, LOGL_ERROR, "Could not deliver paging because none of the associated BSCs is available!\n"); return page_count; } @@ -317,26 +412,6 @@ int a_iface_tx_assignment(struct gsm_trans *trans) return osmo_sccp_tx_data_msg(conn->a.scu, conn->a.conn_id, msg); } -/* Check if we already know this BSC from a successfuly executed reset procedure. */ -static bool test_bsc_known(struct osmo_sccp_addr *bsc_addr) -{ - struct a_bsc_addr *addr; - struct llist_head *bsc_addr_list = get_bsc_addr_list(); - - /* Check if the given address is */ - llist_for_each_entry(addr, bsc_addr_list, list) { - if (memcmp(&addr->calling_addr, bsc_addr, sizeof(*bsc_addr)) == 0) { - LOGP(DMSC, LOGL_ERROR, "The calling BSC (%s) is known by this MSC, proceeding...\n", - osmo_sccp_addr_dump(bsc_addr)); - return true; - } - } - - LOGP(DMSC, LOGL_ERROR, "The calling BSC (%s) is unknown to this MSC, rejecting...\n", - osmo_sccp_addr_dump(bsc_addr)); - return false; -} - /* Callback function, called by the SSCP stack when data arrives */ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) { @@ -346,6 +421,7 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) struct a_conn_info a_conn_info; memset(&a_conn_info, 0, sizeof(a_conn_info)); a_conn_info.network = gsm_network; + a_conn_info.reset = NULL; switch (OSMO_PRIM_HDR(&scu_prim->oph)) { case OSMO_PRIM(OSMO_SCU_PRIM_N_CONNECT, PRIM_OP_INDICATION): @@ -353,8 +429,9 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) a_conn_info.conn_id = scu_prim->u.connect.conn_id; a_conn_info.called_addr = &scu_prim->u.connect.called_addr; a_conn_info.calling_addr = &scu_prim->u.connect.calling_addr; + a_conn_info.reset = get_reset_ctx_by_sccp_addr(&scu_prim->u.unitdata.calling_addr); - if (test_bsc_known(a_conn_info.calling_addr) == false) { + if (a_reset_conn_ready(a_conn_info.reset) == false) { rc = osmo_sccp_tx_disconn(scu, a_conn_info.conn_id, a_conn_info.called_addr, SCCP_RETURN_CAUSE_UNQUALIFIED); break; @@ -367,6 +444,8 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) rc = sccp_rx_dt(scu, &a_conn_info, oph->msg); } else LOGP(DMSC, LOGL_DEBUG, "N-CONNECT.ind(%u)\n", scu_prim->u.connect.conn_id); + + record_bsc_con(scu, &scu_prim->u.connect.calling_addr, &scu_prim->u.connect.called_addr, scu_prim->u.connect.conn_id); break; case OSMO_PRIM(OSMO_SCU_PRIM_N_DATA, PRIM_OP_INDICATION): @@ -381,6 +460,8 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) /* Handle inbound UNITDATA */ a_conn_info.called_addr = &scu_prim->u.unitdata.called_addr; a_conn_info.calling_addr = &scu_prim->u.unitdata.calling_addr; + a_conn_info.reset = get_reset_ctx_by_sccp_addr(&scu_prim->u.unitdata.calling_addr); + DEBUGP(DMSC, "N-UNITDATA.ind(%s)\n", osmo_hexdump(msgb_l2(oph->msg), msgb_l2len(oph->msg))); sccp_rx_udt(scu, &a_conn_info, oph->msg); break; @@ -393,15 +474,43 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu) return rc; } +/* Clear all subscriber connections on a specified BSC */ +void a_clear_all(struct osmo_sccp_user *scu, struct osmo_sccp_addr *bsc_addr) +{ + struct gsm_subscriber_connection *conn; + struct gsm_subscriber_connection *conn_temp; + struct gsm_network *network = gsm_network; + + llist_for_each_entry_safe(conn, conn_temp, &network->subscr_conns, entry) { + /* Clear only A connections and connections that actually + * belong to the specified BSC */ + if (conn->via_ran == RAN_GERAN_A + && memcmp(bsc_addr, &conn->a.bsc_addr, sizeof(conn->a.bsc_addr)) == 0) { + LOGP(DMSC, LOGL_NOTICE, "Dropping orphaned subscriber connection (conn_id %i)\n", conn->a.conn_id); + msc_clear_request(conn, GSM48_CC_CAUSE_SWITCH_CONG); + + /* If there is still an SCCP connection active, remove it now */ + if (check_connection_active(conn->a.conn_id)) { + osmo_sccp_tx_disconn(scu, conn->a.conn_id, bsc_addr, SCCP_RELEASE_CAUSE_END_USER_ORIGINATED); + a_delete_bsc_con(conn->a.conn_id); + } + } + } +} + /* Callback function: Close all open connections */ static void a_reset_cb(void *priv) { struct msgb *msg; - struct osmo_sccp_addr *addr = (struct osmo_sccp_addr*) priv; - LOGP(DMSC, LOGL_NOTICE, "Sending RESET to BSC %s\n", osmo_sccp_addr_dump(addr)); + struct bsc_context *bsc_ctx = (struct bsc_context*) priv; + + /* Clear all now orphaned subscriber connections */ + a_clear_all(bsc_ctx->sccp_user, &bsc_ctx->called_addr); + + LOGP(DMSC, LOGL_NOTICE, "Sending RESET to BSC %s\n", osmo_sccp_addr_dump(&bsc_ctx->called_addr)); msg = gsm0808_create_reset(); -// osmo_sccp_tx_unitdata_msg(msc->msc_con->sccp_user, &msc->msc_con->g_calling_addr, -// &msc->msc_con->g_called_addr, msg); + osmo_sccp_tx_unitdata_msg(bsc_ctx->sccp_user, &bsc_ctx->calling_addr, + &bsc_ctx->called_addr, msg); } /* Initalize A interface connection between to MSC and BSC */ @@ -410,31 +519,37 @@ int a_init(void *ctx, const char *name, uint32_t local_pc, { /* FIXME: Remove hardcoded parameters, use parameters in parameter list */ struct osmo_sccp_instance *sccp; + struct osmo_sccp_user *scu; + struct bsc_context *bsc_ctx; LOGP(DMSC, LOGL_NOTICE, "Initalizing SCCP connection to stp...\n"); gsm_network = network; osmo_ss7_init(); + /* SCCP Protocol stack */ + sccp = + osmo_sccp_simple_client(NULL, "osmo-msc", SENDER_PC, OSMO_SS7_ASP_PROT_M3UA, 0, NULL, M3UA_PORT, + "127.0.0.1"); + scu = osmo_sccp_user_bind(sccp, "osmo-msc", sccp_sap_up, SSN_BSSAP); + /* Add some BSCs to the context list */ - /* FIXME: Make this configurable */ - struct bsc_context *bsc_ctx; + /* FIXME: Make this configurable (VTY!) */ bsc_ctx = talloc_zero(NULL, struct bsc_context); - bsc_ctx->reset.priv = &bsc_ctx->addr; + bsc_ctx->reset.priv = bsc_ctx; bsc_ctx->reset.cb = a_reset_cb; llist_add_tail(&bsc_ctx->list, &bsc_context_list); - bsc_ctx->addr.presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC; - bsc_ctx->addr.ssn = SCCP_SSN_BSSAP; - bsc_ctx->addr.ri = OSMO_SCCP_RI_SSN_PC; - bsc_ctx->addr.pc = 1; + bsc_ctx->called_addr.presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC; + bsc_ctx->called_addr.ssn = SCCP_SSN_BSSAP; + bsc_ctx->called_addr.ri = OSMO_SCCP_RI_SSN_PC; + bsc_ctx->called_addr.pc = 23; + bsc_ctx->calling_addr.presence = OSMO_SCCP_ADDR_T_SSN | OSMO_SCCP_ADDR_T_PC; + bsc_ctx->calling_addr.ssn = SCCP_SSN_BSSAP; + bsc_ctx->calling_addr.ri = OSMO_SCCP_RI_SSN_PC; + bsc_ctx->calling_addr.pc = 1; + bsc_ctx->sccp_user = scu; bsc_ctx = NULL; - /* SCCP Protocol stack */ - sccp = - osmo_sccp_simple_client(NULL, "osmo-msc", SENDER_PC, OSMO_SS7_ASP_PROT_M3UA, 0, NULL, M3UA_PORT, - "127.0.0.1"); - osmo_sccp_user_bind(sccp, "osmo-msc", sccp_sap_up, SSN_BSSAP); - /* Start reset procedure for all BSC connections */ llist_for_each_entry(bsc_ctx, &bsc_context_list, list) { a_reset_start(&bsc_ctx->reset); diff --git a/openbsc/src/libmsc/a_iface_bssap.c b/openbsc/src/libmsc/a_iface_bssap.c index b1fd11a03..f2201bb9a 100644 --- a/openbsc/src/libmsc/a_iface_bssap.c +++ b/openbsc/src/libmsc/a_iface_bssap.c @@ -28,15 +28,14 @@ #include #include #include +#include #include #include #include +#include #define IP_V4_ADDR_LEN 4 -/* Addresses of all BSCs which have been registered to this MSC */ -static LLIST_HEAD(bsc_addr_list); - /* * Helper functions to lookup and allocate subscribers */ @@ -94,22 +93,6 @@ struct gsm_subscriber_connection *subscr_conn_lookup_a(struct gsm_network *netwo return NULL; } -/* Clear oprphand subscriber connections (called by bssmap_rx_reset()) */ -static void subscr_conn_clear_all(struct a_conn_info *a_conn_info) -{ - struct gsm_subscriber_connection *conn; - struct gsm_subscriber_connection *conn_temp; - struct gsm_network *network = a_conn_info->network; - - llist_for_each_entry_safe(conn, conn_temp, &network->subscr_conns, entry) { - if (conn->via_ran == RAN_GERAN_A - && memcmp(a_conn_info->calling_addr, &conn->a.bsc_addr, sizeof(conn->a.bsc_addr)) == 0) { - LOGP(DMSC, LOGL_NOTICE, "Dropping old subscriber connection (conn_id %i)\n", conn->a.conn_id); - msc_clear_request(conn, GSM48_CC_CAUSE_SWITCH_CONG); - } - } -} - /* * BSSMAP handling for UNITDATA */ @@ -117,36 +100,32 @@ static void subscr_conn_clear_all(struct a_conn_info *a_conn_info) /* Endpoint to handle BSSMAP reset */ static void bssmap_rx_reset(struct osmo_sccp_user *scu, struct a_conn_info *a_conn_info, struct msgb *msg) { - struct a_bsc_addr *addr; - struct a_bsc_addr *known_addr; - bool addr_unknown = true; - - LOGP(DMSC, LOGL_NOTICE, "Rx RESET from BSC %s\n", osmo_sccp_addr_dump(a_conn_info->calling_addr)); + LOGP(DMSC, LOGL_NOTICE, "Rx RESET from BSC %s, sending RESET ACK\n", osmo_sccp_addr_dump(a_conn_info->calling_addr)); osmo_sccp_tx_unitdata_msg(scu, a_conn_info->called_addr, a_conn_info->calling_addr, gsm0808_create_reset_ack()); /* Make sure all orphand subscriber connections will be cleard */ - subscr_conn_clear_all(a_conn_info); - - /* Check if we know this BSC already, if yes, refresh its item */ - llist_for_each_entry(known_addr, &bsc_addr_list, list) { - if (memcmp(&known_addr->calling_addr, a_conn_info->calling_addr, sizeof(*a_conn_info->calling_addr)) == - 0) { - LOGP(DMSC, LOGL_NOTICE, "This BSC is already known to this MSC, refreshing its list item\n"); - llist_del(&known_addr->list); - talloc_free(known_addr); - addr_unknown = false; - break; - } + a_clear_all(scu, a_conn_info->calling_addr); + + msgb_free(msg); +} + +/* Endpoint to handle BSSMAP reset acknowlegement */ +static void bssmap_rx_reset_ack(struct osmo_sccp_user *scu, struct a_conn_info *a_conn_info, struct msgb *msg) +{ + if (a_conn_info->reset == NULL) { + LOGP(DMSC, LOGL_ERROR, "Received RESET ACK from an unknown BSC %s, ignoring...\n", + osmo_sccp_addr_dump(a_conn_info->calling_addr)); + goto fail; } - if (addr_unknown) - LOGP(DMSC, LOGL_NOTICE, "This BSC is not known to this MSC yet, adding it to list\n"); - addr = talloc_zero(NULL, struct a_bsc_addr); - memcpy(&addr->calling_addr, a_conn_info->calling_addr, sizeof(addr->calling_addr)); - memcpy(&addr->called_addr, a_conn_info->called_addr, sizeof(addr->called_addr)); - addr->scu = scu; - llist_add(&addr->list, &bsc_addr_list); + LOGP(DMSC, LOGL_NOTICE, "Received RESET ACK from BSC %s\n", + osmo_sccp_addr_dump(a_conn_info->calling_addr)); + + /* Confirm that we managed to get the reset ack message + * towards the connection reset logic */ + a_reset_ack_confirm(a_conn_info->reset); +fail: msgb_free(msg); } @@ -167,6 +146,9 @@ static void bssmap_rcvmsg_udt(struct osmo_sccp_user *scu, struct a_conn_info *a_ case BSS_MAP_MSG_RESET: bssmap_rx_reset(scu, a_conn_info, msg); break; + case BSS_MAP_MSG_RESET_ACKNOWLEDGE: + bssmap_rx_reset_ack(scu, a_conn_info, msg); + break; default: LOGP(DMSC, LOGL_NOTICE, "Unimplemented message format: %s -- message discarded!\n", gsm0808_bssmap_name(msg->l3h[0])); @@ -258,6 +240,9 @@ static int bssmap_rx_clear_complete(struct osmo_sccp_user *scu, struct a_conn_in rc = osmo_sccp_tx_disconn(scu, a_conn_info->conn_id, a_conn_info->called_addr, SCCP_RELEASE_CAUSE_END_USER_ORIGINATED); + /* Remove the record from the list with active connections. */ + a_delete_bsc_con(a_conn_info->conn_id); + msgb_free(msg); return rc; } @@ -705,9 +690,3 @@ int sccp_rx_dt(struct osmo_sccp_user *scu, struct a_conn_info *a_conn_info, stru return -EINVAL; } - -/* Get a list with all known BSCs */ -struct llist_head *get_bsc_addr_list(void) -{ - return &bsc_addr_list; -} diff --git a/openbsc/src/osmo-bsc/osmo_bsc_bssap.c b/openbsc/src/osmo-bsc/osmo_bsc_bssap.c index afa81b0e5..38725a0b8 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_bssap.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_bssap.c @@ -194,7 +194,7 @@ static int match_codec_pref(int *full_rate, enum gsm48_chan_mode *chan_mode, static int bssmap_handle_reset_ack(struct bsc_msc_data *msc, struct msgb *msg, unsigned int length) { - LOGP(DMSC, LOGL_NOTICE, "Reset ACK from MSC No.: %i\n", msc->nr); + LOGP(DMSC, LOGL_NOTICE, "RESET ACK from MSC No.: %i\n", msc->nr); /* Inform the FSM that controls the RESET/RESET-ACK procedure * that we have successfully received the reset-ack message */ @@ -207,7 +207,7 @@ static int bssmap_handle_reset_ack(struct bsc_msc_data *msc, static int bssmap_handle_reset(struct bsc_msc_data *msc, struct msgb *msg, unsigned int length) { - LOGP(DMSC, LOGL_NOTICE, "Reset from MSC No.: %i\n", msc->nr); + LOGP(DMSC, LOGL_NOTICE, "RESET from MSC No.: %i\n", msc->nr); /* Instruct the bsc to close all open sigtran connections and to * close all active channels on the BTS side as well */ diff --git a/openbsc/src/osmo-bsc/osmo_bsc_sigtran.c b/openbsc/src/osmo-bsc/osmo_bsc_sigtran.c index 80dac828d..8364d2aad 100644 --- a/openbsc/src/osmo-bsc/osmo_bsc_sigtran.c +++ b/openbsc/src/osmo-bsc/osmo_bsc_sigtran.c @@ -41,8 +41,15 @@ static struct llist_head *msc_list; #define RESET_INTERVAL 1 /* sek */ #define SCCP_MSG_MAXSIZE 1024 +/* Internal list with connections we currently maintain. This + * list is of type struct osmo_bsc_sccp_con */ static LLIST_HEAD(active_connections); +/* The SCCP stack will not assign connection IDs to us automatically, we + * will do this ourselves using a counter variable, that counts one up + * for every new connection */ +static uint32_t conn_id_counter; + /* Helper function to Check if the given connection id is already assigned */ static struct osmo_bsc_sccp_con *get_bsc_conn_by_conn_id(int conn_id) { @@ -60,14 +67,14 @@ static struct osmo_bsc_sccp_con *get_bsc_conn_by_conn_id(int conn_id) /* Pick a free connection id */ static int pick_free_conn_id(struct bsc_msc_data *msc) { - int conn_id = msc->msc_con->conn_id_counter; + int conn_id = conn_id_counter; int i; for (i = 0; i < 0xFFFFFF; i++) { conn_id++; conn_id &= 0xFFFFFF; if (get_bsc_conn_by_conn_id(conn_id) == false) { - msc->msc_con->conn_id_counter = conn_id; + conn_id_counter = conn_id; return conn_id; } } @@ -89,13 +96,12 @@ static void osmo_bsc_sigtran_tx_reset(struct bsc_msc_data *msc) void osmo_bsc_sigtran_tx_reset_ack(struct bsc_msc_data *msc) { struct msgb *msg; - LOGP(DMSC, LOGL_NOTICE, "Sending RESET RACK to MSC No.: %i\n", msc->nr); + LOGP(DMSC, LOGL_NOTICE, "Sending RESET ACK to MSC No.: %i\n", msc->nr); msg = gsm0808_create_reset_ack(); osmo_sccp_tx_unitdata_msg(msc->msc_con->sccp_user, &msc->msc_con->g_calling_addr, &msc->msc_con->g_called_addr, msg); } - /* Find an MSC by its sigtran point code */ static struct bsc_msc_data *get_msc_by_addr(struct osmo_sccp_addr *calling_addr) { @@ -367,12 +373,24 @@ void osmo_bsc_sigtran_reset(struct bsc_msc_data *msc) /* Close all open connections */ llist_for_each_entry_safe(conn, conn_temp, &active_connections, entry) { - if (conn->conn) - gsm0808_clear(conn->conn); - bsc_notify_msc_lost(conn); - osmo_bsc_sigtran_del_conn(conn); + + /* We only may close connections which actually belong to this + * MSC. All other open connections are left untouched */ + if (conn->msc == msc) { + /* Notify active connection users via USSD that the MSC is down */ + bsc_notify_msc_lost(conn); + + /* Take down all occopied RF channels */ + if (conn->conn) + gsm0808_clear(conn->conn); + + /* Disconnect all Sigtran connections */ + osmo_sccp_tx_disconn(msc->msc_con->sccp_user, conn->conn_id, &msc->msc_con->g_calling_addr, 0); + + /* Delete subscriber connection */ + osmo_bsc_sigtran_del_conn(conn); + } } - msc->msc_con->conn_id_counter = 0; } /* Callback function: Close all open connections */ @@ -380,7 +398,7 @@ static void osmo_bsc_sigtran_reset_cb(void *priv) { struct bsc_msc_data *msc = (struct bsc_msc_data*) priv; - /* Shut down all ongoint traffic */ + /* Shut down all ongoing traffic */ osmo_bsc_sigtran_reset(msc); /* Send reset to MSC */ @@ -400,6 +418,8 @@ int osmo_bsc_sigtran_init(struct llist_head *mscs) msc_list = mscs; + conn_id_counter = 0; + llist_for_each_entry(msc, msc_list, entry) { snprintf(msc_name, sizeof(msc_name), "MSC No.: %u", msc->nr); LOGP(DMSC, LOGL_NOTICE, "Initalizing SCCP connection to %s\n", msc_name); -- cgit v1.2.3