summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile.am10
-rwxr-xr-xutils/gen_website_doc_tree.sh14
-rw-r--r--utils/osmo-arfcn.c103
-rw-r--r--utils/osmo-auc-gen.c231
4 files changed, 358 insertions, 0 deletions
diff --git a/utils/Makefile.am b/utils/Makefile.am
new file mode 100644
index 00000000..4e7869e4
--- /dev/null
+++ b/utils/Makefile.am
@@ -0,0 +1,10 @@
+if ENABLE_UTILITIES
+INCLUDES = $(all_includes) -I$(top_srcdir)/include
+noinst_PROGRAMS = osmo-arfcn osmo-auc-gen
+
+osmo_arfcn_SOURCES = osmo-arfcn.c
+osmo_arfcn_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
+
+osmo_auc_gen_SOURCES = osmo-auc-gen.c
+osmo_auc_gen_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gsm/libosmogsm.la
+endif
diff --git a/utils/gen_website_doc_tree.sh b/utils/gen_website_doc_tree.sh
new file mode 100755
index 00000000..622db56d
--- /dev/null
+++ b/utils/gen_website_doc_tree.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+TOPDIR=`pwd`
+INDIR="$TOPDIR/doc"
+OUTDIR=/tmp/doxywww
+GITREV=`./git-version-gen .tarball-version`
+
+[ -f "$OUTDIR" ] || mkdir "$OUTDIR"
+
+for MOD in core gsm vty codec; do
+ TGTDIR="$OUTDIR/libosmo$MOD/$GITREV"
+ mkdir -p "$TGTDIR"
+ cp -R "$INDIR/$MOD/"* "$TGTDIR/"
+done
diff --git a/utils/osmo-arfcn.c b/utils/osmo-arfcn.c
new file mode 100644
index 00000000..15adbca2
--- /dev/null
+++ b/utils/osmo-arfcn.c
@@ -0,0 +1,103 @@
+/* Utility program for ARFCN / frequency calculations */
+/*
+ * (C) 2011 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 General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+#include <stdio.h>
+#include <getopt.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#include <osmocom/gsm/gsm_utils.h>
+
+enum program_mode {
+ MODE_NONE,
+ MODE_A2F,
+ MODE_F2A,
+};
+
+static int arfcn2freq(char *arfcn_str)
+{
+ int arfcn = atoi(arfcn_str);
+ uint16_t freq10u, freq10d;
+
+ if (arfcn < 0 || arfcn > 0xffff) {
+ fprintf(stderr, "Invalid ARFCN %d\n", arfcn);
+ return -EINVAL;
+ }
+
+ freq10u = gsm_arfcn2freq10(arfcn, 1);
+ freq10d = gsm_arfcn2freq10(arfcn, 0);
+ if (freq10u == 0xffff || freq10d == 0xffff) {
+ fprintf(stderr, "Error during conversion of ARFCN %d\n",
+ arfcn);
+ return -EINVAL;
+ }
+
+ printf("ARFCN %4d: Uplink %4u.%1u MHz / Downlink %4u.%1u MHz\n",
+ arfcn, freq10u/10, freq10u%10, freq10d/10, freq10d%10);
+
+ return 0;
+}
+
+static void help(const char *progname)
+{
+ printf("Usage: %s [-h] [-a arfcn] [-f freq] [-u|-d]\n",
+ progname);
+}
+
+int main(int argc, char **argv)
+{
+ int opt;
+ char *param;
+ enum program_mode mode = MODE_NONE;
+
+ while ((opt = getopt(argc, argv, "a:f:ud")) != -1) {
+ switch (opt) {
+ case 'a':
+ mode = MODE_A2F;
+ param = optarg;
+ break;
+ case 'f':
+ mode = MODE_F2A;
+ param = optarg;
+ break;
+ case 'h':
+ help(argv[0]);
+ exit(0);
+ break;
+ default:
+ break;
+ }
+ }
+
+ switch (mode) {
+ case MODE_NONE:
+ help(argv[0]);
+ exit(2);
+ break;
+ case MODE_A2F:
+ arfcn2freq(param);
+ break;
+ }
+
+ exit(0);
+}
diff --git a/utils/osmo-auc-gen.c b/utils/osmo-auc-gen.c
new file mode 100644
index 00000000..e3502b2c
--- /dev/null
+++ b/utils/osmo-auc-gen.c
@@ -0,0 +1,231 @@
+/* GSM/GPRS/3G authentication testing tool */
+
+/* (C) 2010-2012 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 General Public License as published by
+ * the Free Software Foundation; either version 2 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <getopt.h>
+
+#include <osmocom/crypt/auth.h>
+#include <osmocom/core/utils.h>
+
+static void dump_auth_vec(struct osmo_auth_vector *vec)
+{
+ printf("RAND:\t%s\n", osmo_hexdump(vec->rand, sizeof(vec->rand)));
+
+ if (vec->auth_types & OSMO_AUTH_TYPE_UMTS) {
+ printf("AUTN:\t%s\n", osmo_hexdump(vec->autn, sizeof(vec->autn)));
+ printf("IK:\t%s\n", osmo_hexdump(vec->ik, sizeof(vec->ik)));
+ printf("CK:\t%s\n", osmo_hexdump(vec->ck, sizeof(vec->ck)));
+ printf("RES:\t%s\n", osmo_hexdump(vec->res, vec->res_len));
+ }
+
+ if (vec->auth_types & OSMO_AUTH_TYPE_GSM) {
+ printf("SRES:\t%s\n", osmo_hexdump(vec->sres, sizeof(vec->sres)));
+ printf("Kc:\t%s\n", osmo_hexdump(vec->kc, sizeof(vec->kc)));
+ }
+}
+
+static struct osmo_sub_auth_data test_aud = {
+ .type = OSMO_AUTH_TYPE_NONE,
+ .algo = OSMO_AUTH_ALG_NONE,
+};
+
+static void help()
+{
+ printf( "-2 --2g\tUse 2G (GSM) authentication\n"
+ "-3 --3g\tUse 3G (UMTS) authentication\n"
+ "-a --algorithm\tSpecify name of the algorithm\n"
+ "-k --key\tSpecify Ki / K\n"
+ "-o --opc\tSpecify OPC (only for 3G)\n"
+ "-O --op\tSpecify OP (only for 3G)\n"
+ "-a --amf\tSpecify AMF (only for 3G)\n"
+ "-s --sqn\tSpecify SQN (only for 3G)\n"
+ "-A --auts\tSpecify AUTS (only for 3G)\n"
+ "-r --rand\tSpecify random value\n");
+}
+
+int main(int argc, char **argv)
+{
+ struct osmo_auth_vector _vec;
+ struct osmo_auth_vector *vec = &_vec;
+ uint8_t _rand[16], _auts[16];
+ int rc, option_index;
+ int rand_is_set = 0;
+ int auts_is_set = 0;
+
+ printf("osmo-auc-gen (C) 2011-2012 by Harald Welte\n");
+ printf("This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY\n\n");
+
+ memset(_auts, 0, sizeof(_auts));
+
+ while (1) {
+ int c;
+ unsigned long ul;
+ static struct option long_options[] = {
+ { "2g", 0, 0, '2' },
+ { "3g", 0, 0, '3' },
+ { "algorithm", 1, 0, 'a' },
+ { "key", 1, 0, 'k' },
+ { "opc", 1, 0, 'o' },
+ { "op", 1, 0, 'O' },
+ { "amf", 1, 0, 'f' },
+ { "sqn", 1, 0, 's' },
+ { "rand", 1, 0, 'r' },
+ { "auts", 1, 0, 'A' },
+ { "help", 0, 0, 'h' },
+ { 0, 0, 0, 0 }
+ };
+
+ rc = 0;
+
+ c = getopt_long(argc, argv, "23a:k:o:f:s:r:hO:A:", long_options,
+ &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case '2':
+ test_aud.type = OSMO_AUTH_TYPE_GSM;
+ break;
+ case '3':
+ test_aud.type = OSMO_AUTH_TYPE_UMTS;
+ break;
+ case 'a':
+ rc = osmo_auth_alg_parse(optarg);
+ if (rc < 0)
+ break;
+ test_aud.algo = rc;
+ break;
+ case 'k':
+ switch (test_aud.type) {
+ case OSMO_AUTH_TYPE_GSM:
+ rc = osmo_hexparse(optarg, test_aud.u.gsm.ki,
+ sizeof(test_aud.u.gsm.ki));
+ break;
+ case OSMO_AUTH_TYPE_UMTS:
+ rc = osmo_hexparse(optarg, test_aud.u.umts.k,
+ sizeof(test_aud.u.umts.k));
+ break;
+ default:
+ fprintf(stderr, "please specify 2g/3g first!\n");
+ }
+ break;
+ case 'o':
+ if (test_aud.type != OSMO_AUTH_TYPE_UMTS) {
+ fprintf(stderr, "Only UMTS has OPC\n");
+ exit(2);
+ }
+ rc = osmo_hexparse(optarg, test_aud.u.umts.opc,
+ sizeof(test_aud.u.umts.opc));
+ test_aud.u.umts.opc_is_op = 0;
+ break;
+ case 'O':
+ if (test_aud.type != OSMO_AUTH_TYPE_UMTS) {
+ fprintf(stderr, "Only UMTS has OP\n");
+ exit(2);
+ }
+ rc = osmo_hexparse(optarg, test_aud.u.umts.opc,
+ sizeof(test_aud.u.umts.opc));
+ test_aud.u.umts.opc_is_op = 1;
+ break;
+ case 'A':
+ if (test_aud.type != OSMO_AUTH_TYPE_UMTS) {
+ fprintf(stderr, "Only UMTS has AUTS\n");
+ exit(2);
+ }
+ rc = osmo_hexparse(optarg, _auts, sizeof(_auts));
+ auts_is_set = 1;
+ break;
+ case 'f':
+ if (test_aud.type != OSMO_AUTH_TYPE_UMTS) {
+ fprintf(stderr, "Only UMTS has AMF\n");
+ exit(2);
+ }
+ rc = osmo_hexparse(optarg, test_aud.u.umts.amf,
+ sizeof(test_aud.u.umts.amf));
+ break;
+ case 's':
+ if (test_aud.type != OSMO_AUTH_TYPE_UMTS) {
+ fprintf(stderr, "Only UMTS has SQN\n");
+ exit(2);
+ }
+ ul = strtoul(optarg, 0, 10);
+ test_aud.u.umts.sqn = ul;
+ break;
+ case 'r':
+ rc = osmo_hexparse(optarg, _rand, sizeof(_rand));
+ rand_is_set = 1;
+ break;
+ case 'h':
+ help();
+ exit(0);
+ default:
+ help();
+ exit(1);
+ }
+
+ if (rc < 0) {
+ fprintf(stderr, "Error parsing argument of option `%c'\n", c);
+ exit(2);
+ }
+ }
+
+ if (!rand_is_set) {
+ printf("WARNING: We're using really weak random numbers!\n\n");
+ srand(time(NULL));
+ *(uint32_t *)&_rand[0] = rand();
+ *(uint32_t *)(&_rand[4]) = rand();
+ *(uint32_t *)(&_rand[8]) = rand();
+ *(uint32_t *)(&_rand[12]) = rand();
+ }
+
+ if (test_aud.type == OSMO_AUTH_TYPE_NONE ||
+ test_aud.algo == OSMO_AUTH_ALG_NONE) {
+ help();
+ exit(2);
+ }
+
+ memset(vec, 0, sizeof(*vec));
+
+ if (!auts_is_set)
+ rc = osmo_auth_gen_vec(vec, &test_aud, _rand);
+ else
+ rc = osmo_auth_gen_vec_auts(vec, &test_aud, _auts, _rand, _rand);
+ if (rc < 0) {
+ if (!auts_is_set)
+ fprintf(stderr, "error generating auth vector\n");
+ else
+ fprintf(stderr, "AUTS from MS seems incorrect\n");
+ exit(1);
+ }
+
+ dump_auth_vec(vec);
+
+ if (auts_is_set)
+ printf("AUTS success: SEQ.MS = %lu\n", test_aud.u.umts.sqn);
+
+ exit(0);
+}