blob: 66b6e293d5900e6003bd1d01b015a0fb0b1e93ad [file] [log] [blame]
Harald Weltefbc5ca02010-03-04 10:39:50 +01001/* (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte8470bf22008-12-25 23:28:35 +00002 *
Harald Welte52b1f982008-12-23 20:25:15 +00003 * All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01006 * 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 Welte52b1f982008-12-23 20:25:15 +00008 * (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 Welte9af6ddf2011-01-01 15:25:50 +010013 * GNU Affero General Public License for more details.
Harald Welte52b1f982008-12-23 20:25:15 +000014 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * 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 Welte52b1f982008-12-23 20:25:15 +000017 *
18 */
19
20
21#include <stdlib.h>
Harald Welte51f38452009-02-24 22:36:40 +000022#include <stdio.h>
Harald Welte52b1f982008-12-23 20:25:15 +000023#include <string.h>
Harald Weltefcd24452009-06-20 18:15:19 +020024#include <errno.h>
Harald Welte42581822009-08-08 16:12:58 +020025#include <ctype.h>
Maxc08ee712016-05-11 12:45:13 +020026#include <stdbool.h>
Harald Welte97a282b2010-03-14 15:37:43 +080027#include <netinet/in.h>
28
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010029#include <osmocom/core/linuxlist.h>
30#include <osmocom/core/talloc.h>
31#include <osmocom/gsm/gsm_utils.h>
32#include <osmocom/core/statistics.h>
Maxc08ee712016-05-11 12:45:13 +020033#include <osmocom/gsm/protocol/gsm_04_08.h>
Harald Welte52b1f982008-12-23 20:25:15 +000034
Neels Hofmeyr90843962017-09-04 15:04:35 +020035#include <osmocom/msc/gsm_data.h>
Holger Hans Peter Freythered832862010-06-28 18:20:22 +080036
Andreas Eversberg8226fa72009-06-29 15:19:38 +020037void *tall_bsc_ctx;
38
Harald Welte92b1fe42010-03-25 11:45:30 +080039static 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" },
Maxddee01f2016-05-24 14:23:27 +020043 { GSM_AUTH_POLICY_REGEXP, "regexp" },
Harald Welte92b1fe42010-03-25 11:45:30 +080044 { 0, NULL }
Harald Welte (local)69de3972009-08-12 14:42:23 +020045};
46
47enum gsm_auth_policy gsm_auth_policy_parse(const char *arg)
48{
Harald Welte92b1fe42010-03-25 11:45:30 +080049 return get_string_value(auth_policy_names, arg);
Harald Welte (local)69de3972009-08-12 14:42:23 +020050}
51
52const char *gsm_auth_policy_name(enum gsm_auth_policy policy)
53{
Harald Welte92b1fe42010-03-25 11:45:30 +080054 return get_value_string(auth_policy_names, policy);
Harald Welte (local)69de3972009-08-12 14:42:23 +020055}
56
Harald Welte92b1fe42010-03-25 11:45:30 +080057static 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 Welteeab84a12009-12-13 10:53:12 +010063};
64
65enum rrlp_mode rrlp_mode_parse(const char *arg)
66{
Harald Welte92b1fe42010-03-25 11:45:30 +080067 return get_string_value(rrlp_mode_names, arg);
Harald Welteeab84a12009-12-13 10:53:12 +010068}
69
70const char *rrlp_mode_name(enum rrlp_mode mode)
71{
Harald Welte92b1fe42010-03-25 11:45:30 +080072 return get_value_string(rrlp_mode_names, mode);
Harald Welteeab84a12009-12-13 10:53:12 +010073}
Harald Welted12b0fd2009-12-15 21:36:05 +010074
Holger Hans Peter Freyther06c9da62011-06-09 21:48:49 +020075int 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 Welte2483f1b2016-06-19 18:06:02 +0200100bool 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 Hofmeyr84da6b12016-05-20 21:59:55 +0200109
110const 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};