Holger Hans Peter Freyther | dcf8a7d | 2010-06-15 18:48:01 +0800 | [diff] [blame] | 1 | |
| 2 | /* BSC Multiplexer/NAT Utilities */ |
| 3 | |
| 4 | /* |
| 5 | * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * (C) 2010 by On-Waves |
| 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include <openbsc/bsc_nat.h> |
| 26 | #include <openbsc/gsm_data.h> |
| 27 | |
| 28 | #include <osmocore/talloc.h> |
| 29 | |
| 30 | struct bsc_nat *bsc_nat_alloc(void) |
| 31 | { |
| 32 | struct bsc_nat *nat = talloc_zero(tall_bsc_ctx, struct bsc_nat); |
| 33 | if (!nat) |
| 34 | return NULL; |
| 35 | |
| 36 | INIT_LLIST_HEAD(&nat->sccp_connections); |
| 37 | INIT_LLIST_HEAD(&nat->bsc_connections); |
| 38 | INIT_LLIST_HEAD(&nat->bsc_configs); |
| 39 | return nat; |
| 40 | } |
| 41 | |
| 42 | struct bsc_connection *bsc_connection_alloc(struct bsc_nat *nat) |
| 43 | { |
| 44 | struct bsc_connection *con = talloc_zero(nat, struct bsc_connection); |
| 45 | if (!con) |
| 46 | return NULL; |
| 47 | |
Holger Hans Peter Freyther | f8048d9 | 2010-03-29 15:14:15 +0200 | [diff] [blame] | 48 | con->nat = nat; |
Holger Hans Peter Freyther | dcf8a7d | 2010-06-15 18:48:01 +0800 | [diff] [blame] | 49 | return con; |
| 50 | } |
| 51 | |
| 52 | struct bsc_config *bsc_config_alloc(struct bsc_nat *nat, const char *token, unsigned int lac) |
| 53 | { |
| 54 | struct bsc_config *conf = talloc_zero(nat, struct bsc_config); |
| 55 | if (!conf) |
| 56 | return NULL; |
| 57 | |
| 58 | conf->token = talloc_strdup(conf, token); |
| 59 | conf->lac = lac; |
| 60 | conf->nr = nat->num_bsc; |
| 61 | conf->nat = nat; |
| 62 | |
| 63 | llist_add(&conf->entry, &nat->bsc_configs); |
| 64 | ++nat->num_bsc; |
| 65 | |
| 66 | return conf; |
| 67 | } |