osmo-iuh/src/context_map.c

183 lines
4.9 KiB
C
Raw Normal View History

/* Mapper between RUA ContextID (24 bit, per HNB) and the SUA/SCCP
* Connection ID (32bit, per signalling link) */
/* (C) 2015 by Harald Welte <laforge@gnumonks.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* an expired mapping is destroyed after 1..2 * EXPIRY_TIMER_SECS */
#define EXPIRY_TIMER_SECS 23
#include <osmocom/core/timer.h>
#include <osmocom/iuh/hnbgw.h>
#include <osmocom/iuh/context_map.h>
const struct value_string hnbgw_context_map_state_names[] = {
{MAP_S_NULL , "not-initialized"},
{MAP_S_ACTIVE , "active"},
{MAP_S_RESERVED1, "inactive-reserved"},
{MAP_S_RESERVED2, "inactive-discard"},
{0, NULL}
};
/* is a given SCCP USER SAP Connection ID in use for a given CN link? */
static int cn_id_in_use(struct hnbgw_cnlink *cn, uint32_t id)
{
struct hnbgw_context_map *map;
llist_for_each_entry(map, &cn->map_list, cn_list) {
if (map->scu_conn_id == id)
return 1;
}
return 0;
}
/* try to allocate a new SCCP User SAP Connection ID */
static int alloc_cn_conn_id(struct hnbgw_cnlink *cn, uint32_t *id_out)
{
uint32_t i;
uint32_t id;
for (i = 0; i < 0xffffffff; i++) {
id = cn->next_conn_id++;
if (!cn_id_in_use(cn, id)) {
*id_out = id;
return 1;
}
}
return -1;
}
/* Map from a HNB + ContextID to the SCCP-side Connection ID */
struct hnbgw_context_map *
context_map_alloc_by_hnb(struct hnb_context *hnb, uint32_t rua_ctx_id,
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
bool is_ps,
struct hnbgw_cnlink *cn_if_new)
{
struct hnbgw_context_map *map;
uint32_t new_scu_conn_id;
llist_for_each_entry(map, &hnb->map_list, hnb_list) {
if (map->state != MAP_S_ACTIVE)
continue;
if (map->cn_link != cn_if_new) {
continue;
}
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
if (map->rua_ctx_id == rua_ctx_id
&& map->is_ps == is_ps) {
return map;
}
}
if (alloc_cn_conn_id(cn_if_new, &new_scu_conn_id) < 0) {
LOGP(DMAIN, LOGL_ERROR, "Unable to allocate CN connection ID\n");
return NULL;
}
2015-12-29 18:00:35 +00:00
LOGP(DMAIN, LOGL_INFO, "Creating new Mapping RUA CTX %p/%u <-> SCU Conn ID %p/%u\n",
hnb, rua_ctx_id, cn_if_new, new_scu_conn_id);
/* alloate a new map entry */
map = talloc_zero(hnb, struct hnbgw_context_map);
map->state = MAP_S_NULL;
map->cn_link = cn_if_new;
map->hnb_ctx = hnb;
map->rua_ctx_id = rua_ctx_id;
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
map->is_ps = is_ps;
map->scu_conn_id = new_scu_conn_id;
/* put it into both lists */
llist_add_tail(&map->hnb_list, &hnb->map_list);
llist_add_tail(&map->cn_list, &cn_if_new->map_list);
map->state = MAP_S_ACTIVE;
return map;
}
/* Map from a CN + Connection ID to HNB + Context ID */
struct hnbgw_context_map *
context_map_by_cn(struct hnbgw_cnlink *cn, uint32_t scu_conn_id)
{
struct hnbgw_context_map *map;
llist_for_each_entry(map, &cn->map_list, cn_list) {
if (map->state != MAP_S_ACTIVE)
continue;
if (map->scu_conn_id == scu_conn_id) {
return map;
}
}
/* we don't allocate new mappings in the CN->HNB
* direction, as the RUA=SCCP=SUA connections are always
* established from HNB towards CN. */
LOGP(DMAIN, LOGL_NOTICE, "Unable to resolve map for CN "
2015-12-29 18:00:35 +00:00
"connection ID %p/%u\n", cn, scu_conn_id);
return NULL;
}
void context_map_deactivate(struct hnbgw_context_map *map)
{
/* set the state to reserved. We still show up in the list and
* avoid re-allocation of the context-id until we are cleaned up
* by the context_map garbage collector timer */
if (map->state != MAP_S_RESERVED2)
map->state = MAP_S_RESERVED1;
}
static struct osmo_timer_list context_map_tmr;
static void context_map_tmr_cb(void *data)
{
struct hnb_gw *gw = data;
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
struct hnbgw_cnlink *cn = gw->sccp.cnlink;
struct hnbgw_context_map *map, *next_map;
DEBUGP(DMAIN, "Running context mapper garbage collection\n");
llist_for_each_entry_safe(map, next_map, &cn->map_list, cn_list) {
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
switch (map->state) {
case MAP_S_RESERVED1:
/* first time we see this reserved
* entry: mark it for stage 2 */
map->state = MAP_S_RESERVED2;
break;
case MAP_S_RESERVED2:
/* second time we see this reserved
migrate osmo-hnbgw to libosmo-sigtran's SCCP/M3UA libosmo-sigtran now has a "proper" SCCP/M3UA stack, so we can make our hnb-gw 3GPP compliant by switching from the old SUA code to the new universal SCCP user API with support for (currently) M3UA and SUA. Main changes: Use one cn_link to STP: We will connect to the core network using an (Osmo)STP instance that routes to MSC and SGSN, so we want one SCCP link instead of two. The only difference between IuCS and IuPS is a different remote osmo_sccp_addr. This has various effects through the messaging code; the patch is a bit larger than I would like, but it is hard to separate out truly independent smaller changes. CS or PS domain was previously flagged in the separate cn_link, as ctx pointer for two separate sccp_sap_up()s. Now there's just one such ctx, so determine is_ps from the RANAP Domain Indicator, or from the conn's hnbgw_context_map: - Add is_ps to context_map_alloc_by_hnb(). - To find a matching context, the RUA ID alone is no longer sufficient, also match is_ps (possible optimization todo: separate lists). We would send separate CS or PS Reset messages based on the cn_link, instead send both CS and PS Reset at the same time for the single cn_link. This could be adjusted to detect presence of MSC or SGSN instead. Pending: adjust the VTY config to reflect that there is only one remote address. Place a TODO comment for that. Smaller changes: rua_to_scu(): populate called and calling addresses for N_CONNECT and N_UNITDATA. Remove DSUA. Don't build dummy_cn, which is still implemented on SUA. Mark todo to maybe re-include it based on M3UA later. In hnbgw_cnlink, place sccp related items in a separate sub-struct. Do not keep an llist of cn_links, just have the one. Remove iteration and list management. Change jenkins script to build libosmo-sccp master. Patch-by: hwelte, nhofmeyr Change-Id: I8ac15fa2fd25bedb26297177e416976a5389b573
2017-07-03 14:49:43 +00:00
* entry: remove it */
map->state = MAP_S_NULL;
llist_del(&map->cn_list);
llist_del(&map->hnb_list);
talloc_free(map);
break;
default:
break;
}
}
/* re-schedule this timer */
osmo_timer_schedule(&context_map_tmr, EXPIRY_TIMER_SECS, 0);
}
int context_map_init(struct hnb_gw *gw)
{
context_map_tmr.cb = context_map_tmr_cb;
context_map_tmr.data = gw;
osmo_timer_schedule(&context_map_tmr, EXPIRY_TIMER_SECS, 0);
return 0;
}