1 /* Generic GSM utility routines */
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
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.
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.
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.
28 enum gsm_band gsm_arfcn2band(uint16_t arfcn)
30 if (arfcn & ARFCN_PCS)
32 else if (arfcn <= 124)
34 else if (arfcn >= 955 && arfcn <= 1023)
36 else if (arfcn >= 128 && arfcn <= 251)
38 else if (arfcn >= 512 && arfcn <= 885)
40 else if (arfcn >= 259 && arfcn <= 293)
42 else if (arfcn >= 306 && arfcn <= 340)
44 else if (arfcn >= 350 && arfcn <= 425)
46 else if (arfcn >= 438 && arfcn <= 511)
52 /* Convert an ARFCN to the frequency in MHz * 10 */
53 uint16_t gsm_arfcn2freq10(uint16_t arfcn, int uplink)
58 if (arfcn & ARFCN_PCS) {
61 freq10_ul = 18502 + 2 * (arfcn-512);
62 freq10_dl = freq10_ul + 800;
63 } else if (arfcn <= 124) {
64 /* Primary GSM + ARFCN 0 of E-GSM */
65 freq10_ul = 8900 + 2 * arfcn;
66 freq10_dl = freq10_ul + 450;
67 } else if (arfcn >= 955 && arfcn <= 1023) {
69 freq10_ul = 8900 + 2 * (arfcn - 1024);
70 freq10_dl = freq10_ul + 450;
71 } else if (arfcn >= 128 && arfcn <= 251) {
73 freq10_ul = 8242 + 2 * (arfcn - 128);
74 freq10_dl = freq10_ul + 450;
75 } else if (arfcn >= 512 && arfcn <= 885) {
77 freq10_ul = 17102 + 2 * (arfcn - 512);
78 freq10_dl = freq10_ul + 950;
79 } else if (arfcn >= 259 && arfcn <= 293) {
81 freq10_ul = 4506 + 2 * (arfcn - 259);
82 freq10_dl = freq10_ul + 100;
83 } else if (arfcn >= 306 && arfcn <= 340) {
85 freq10_ul = 4790 + 2 * (arfcn - 306);
86 freq10_dl = freq10_ul + 100;
87 } else if (arfcn >= 350 && arfcn <= 425) {
89 freq10_ul = 8060 + 2 * (arfcn - 350);
90 freq10_dl = freq10_ul + 450;
91 } else if (arfcn >= 438 && arfcn <= 511) {
93 freq10_ul = 7472 + 2 * (arfcn - 438);
94 freq10_dl = freq10_ul + 300;
104 void gsm_fn2gsmtime(struct gsm_time *time, uint32_t fn)
107 time->t1 = time->fn / (26*51);
108 time->t2 = time->fn % 26;
109 time->t3 = time->fn % 51;
110 time->tc = (time->fn / 51) % 8;
113 uint32_t gsm_gsmtime2fn(struct gsm_time *time)
115 /* TS 05.02 Chapter 4.3.3 TDMA frame number */
116 return (51 * ((time->t3 - time->t2 + 26) % 26) + time->t3 + (26 * 51 * time->t1));