Harald Welte | fbc5ca0 | 2010-03-04 10:39:50 +0100 | [diff] [blame] | 1 | /* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org> |
Harald Welte | 8470bf2 | 2008-12-25 23:28:35 +0000 | [diff] [blame] | 2 | * |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 3 | * All Rights Reserved |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 6 | * it under the terms of the GNU Affero General Public License as published by |
| 7 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 13 | * GNU Affero General Public License for more details. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 14 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * You should have received a copy of the GNU Affero General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 17 | * |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | #include <stdlib.h> |
Harald Welte | 51f3845 | 2009-02-24 22:36:40 +0000 | [diff] [blame] | 22 | #include <stdio.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 23 | #include <string.h> |
Harald Welte | fcd2445 | 2009-06-20 18:15:19 +0200 | [diff] [blame] | 24 | #include <errno.h> |
Harald Welte | 4258182 | 2009-08-08 16:12:58 +0200 | [diff] [blame] | 25 | #include <ctype.h> |
Max | c08ee71 | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 26 | #include <stdbool.h> |
Harald Welte | 97a282b | 2010-03-14 15:37:43 +0800 | [diff] [blame] | 27 | #include <netinet/in.h> |
| 28 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/linuxlist.h> |
| 30 | #include <osmocom/core/talloc.h> |
| 31 | #include <osmocom/gsm/gsm_utils.h> |
| 32 | #include <osmocom/core/statistics.h> |
Max | c08ee71 | 2016-05-11 12:45:13 +0200 | [diff] [blame] | 33 | #include <osmocom/gsm/protocol/gsm_04_08.h> |
Harald Welte | 52b1f98 | 2008-12-23 20:25:15 +0000 | [diff] [blame] | 34 | |
Neels Hofmeyr | 9084396 | 2017-09-04 15:04:35 +0200 | [diff] [blame] | 35 | #include <osmocom/msc/gsm_data.h> |
Holger Hans Peter Freyther | ed83286 | 2010-06-28 18:20:22 +0800 | [diff] [blame] | 36 | |
Andreas Eversberg | 8226fa7 | 2009-06-29 15:19:38 +0200 | [diff] [blame] | 37 | void *tall_bsc_ctx; |
| 38 | |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 39 | static const struct value_string auth_policy_names[] = { |
| 40 | { GSM_AUTH_POLICY_CLOSED, "closed" }, |
| 41 | { GSM_AUTH_POLICY_ACCEPT_ALL, "accept-all" }, |
| 42 | { GSM_AUTH_POLICY_TOKEN, "token" }, |
Max | ddee01f | 2016-05-24 14:23:27 +0200 | [diff] [blame] | 43 | { GSM_AUTH_POLICY_REGEXP, "regexp" }, |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 44 | { 0, NULL } |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | enum gsm_auth_policy gsm_auth_policy_parse(const char *arg) |
| 48 | { |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 49 | return get_string_value(auth_policy_names, arg); |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | const char *gsm_auth_policy_name(enum gsm_auth_policy policy) |
| 53 | { |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 54 | return get_value_string(auth_policy_names, policy); |
Harald Welte (local) | 69de397 | 2009-08-12 14:42:23 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 57 | static const struct value_string rrlp_mode_names[] = { |
| 58 | { RRLP_MODE_NONE, "none" }, |
| 59 | { RRLP_MODE_MS_BASED, "ms-based" }, |
| 60 | { RRLP_MODE_MS_PREF, "ms-preferred" }, |
| 61 | { RRLP_MODE_ASS_PREF, "ass-preferred" }, |
| 62 | { 0, NULL } |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | enum rrlp_mode rrlp_mode_parse(const char *arg) |
| 66 | { |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 67 | return get_string_value(rrlp_mode_names, arg); |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | const char *rrlp_mode_name(enum rrlp_mode mode) |
| 71 | { |
Harald Welte | 92b1fe4 | 2010-03-25 11:45:30 +0800 | [diff] [blame] | 72 | return get_value_string(rrlp_mode_names, mode); |
Harald Welte | eab84a1 | 2009-12-13 10:53:12 +0100 | [diff] [blame] | 73 | } |
Harald Welte | d12b0fd | 2009-12-15 21:36:05 +0100 | [diff] [blame] | 74 | |
Holger Hans Peter Freyther | 06c9da6 | 2011-06-09 21:48:49 +0200 | [diff] [blame] | 75 | int gsm_parse_reg(void *ctx, regex_t *reg, char **str, int argc, const char **argv) |
| 76 | { |
| 77 | int ret; |
| 78 | |
| 79 | ret = 0; |
| 80 | if (*str) { |
| 81 | talloc_free(*str); |
| 82 | *str = NULL; |
| 83 | } |
| 84 | regfree(reg); |
| 85 | |
| 86 | if (argc > 0) { |
| 87 | *str = talloc_strdup(ctx, argv[0]); |
| 88 | ret = regcomp(reg, argv[0], 0); |
| 89 | |
| 90 | /* handle compilation failures */ |
| 91 | if (ret != 0) { |
| 92 | talloc_free(*str); |
| 93 | *str = NULL; |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | return ret; |
| 98 | } |
| 99 | |
Harald Welte | 2483f1b | 2016-06-19 18:06:02 +0200 | [diff] [blame] | 100 | bool classmark_is_r99(struct gsm_classmark *cm) |
| 101 | { |
| 102 | int rev_lev = 0; |
| 103 | if (cm->classmark1_set) |
| 104 | rev_lev = cm->classmark1.rev_lev; |
| 105 | else if (cm->classmark2_len > 0) |
| 106 | rev_lev = (cm->classmark2[0] >> 5) & 0x3; |
| 107 | return rev_lev >= 2; |
| 108 | } |
Neels Hofmeyr | 84da6b1 | 2016-05-20 21:59:55 +0200 | [diff] [blame] | 109 | |
| 110 | const struct value_string ran_type_names[] = { |
| 111 | OSMO_VALUE_STRING(RAN_UNKNOWN), |
| 112 | OSMO_VALUE_STRING(RAN_GERAN_A), |
| 113 | OSMO_VALUE_STRING(RAN_UTRAN_IU), |
| 114 | { 0, NULL } |
| 115 | }; |