blob: 15adbca2647820e97ffc9730a160e70a88edd18c [file] [log] [blame]
Harald Welteeeb78dd2011-08-02 13:44:54 +02001/* Utility program for ARFCN / frequency calculations */
2/*
3 * (C) 2011 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <stdio.h>
24#include <getopt.h>
25#include <errno.h>
26#include <unistd.h>
27#include <stdlib.h>
28
29#include <osmocom/gsm/gsm_utils.h>
30
31enum program_mode {
32 MODE_NONE,
33 MODE_A2F,
34 MODE_F2A,
35};
36
37static int arfcn2freq(char *arfcn_str)
38{
39 int arfcn = atoi(arfcn_str);
40 uint16_t freq10u, freq10d;
41
42 if (arfcn < 0 || arfcn > 0xffff) {
43 fprintf(stderr, "Invalid ARFCN %d\n", arfcn);
44 return -EINVAL;
45 }
46
47 freq10u = gsm_arfcn2freq10(arfcn, 1);
48 freq10d = gsm_arfcn2freq10(arfcn, 0);
49 if (freq10u == 0xffff || freq10d == 0xffff) {
50 fprintf(stderr, "Error during conversion of ARFCN %d\n",
51 arfcn);
52 return -EINVAL;
53 }
54
55 printf("ARFCN %4d: Uplink %4u.%1u MHz / Downlink %4u.%1u MHz\n",
56 arfcn, freq10u/10, freq10u%10, freq10d/10, freq10d%10);
57
58 return 0;
59}
60
61static void help(const char *progname)
62{
63 printf("Usage: %s [-h] [-a arfcn] [-f freq] [-u|-d]\n",
64 progname);
65}
66
67int main(int argc, char **argv)
68{
69 int opt;
70 char *param;
71 enum program_mode mode = MODE_NONE;
72
73 while ((opt = getopt(argc, argv, "a:f:ud")) != -1) {
74 switch (opt) {
75 case 'a':
76 mode = MODE_A2F;
77 param = optarg;
78 break;
79 case 'f':
80 mode = MODE_F2A;
81 param = optarg;
82 break;
83 case 'h':
84 help(argv[0]);
85 exit(0);
86 break;
87 default:
88 break;
89 }
90 }
91
92 switch (mode) {
93 case MODE_NONE:
94 help(argv[0]);
95 exit(2);
96 break;
97 case MODE_A2F:
98 arfcn2freq(param);
99 break;
100 }
101
102 exit(0);
103}