changeset 2:e2db512abbee

fc-cmu200d: band and ARFCN tables implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 May 2017 06:37:56 +0000
parents 698602bbd120
children b552e8d86474
files cmu200/Makefile cmu200/band.c cmu200/band.h
diffstat 3 files changed, 85 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/cmu200/Makefile	Sat May 20 18:58:44 2017 +0000
+++ b/cmu200/Makefile	Sun May 21 06:37:56 2017 +0000
@@ -3,7 +3,8 @@
 PROGS=	fc-cmu200d fc-serscpi
 INSTBIN=/opt/freecalypso/bin
 
-CMU200D_OBJS=	dispatch.o init.o main.o openport.o sercmd.o session.o socket.o
+CMU200D_OBJS=	band.o dispatch.o init.o main.o openport.o sercmd.o session.o \
+		socket.o
 SERSCPI_OBJS=	openport.o sertool.o
 
 all:	${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmu200/band.c	Sun May 21 06:37:56 2017 +0000
@@ -0,0 +1,65 @@
+/*
+ * Our band and ARFCN tables and lookup code live here.
+ */
+
+#include <string.h>
+#include <strings.h>
+#include "band.h"
+#include "secaddr.h"
+
+struct arfcn_range band850_arfcn_range =     {128,  251,  824200,  869200};
+struct arfcn_range band900_arfcn_range =     {  0,  124,  890000,  935000};
+struct arfcn_range band900_arfcn_range_ext = {975, 1023,  880200,  925200};
+struct arfcn_range band1800_arfcn_range =    {512,  885, 1710200, 1805200};
+struct arfcn_range band1900_arfcn_range =    {512,  810, 1850200, 1930200};
+
+struct band supported_bands[] = {
+	{"850",  SECADDR_GSM850MS_NSIG,  &band850_arfcn_range,  0},
+	{"900",  SECADDR_GSM900MS_NSIG,  &band900_arfcn_range,
+					 &band900_arfcn_range_ext},
+	{"1800", SECADDR_GSM1800MS_NSIG, &band1800_arfcn_range, 0},
+	{"1900", SECADDR_GSM1900MS_NSIG, &band1900_arfcn_range, 0},
+	{0,	 0,			 0,			0}
+};
+
+struct band *current_band;
+
+find_named_band(srchname)
+	char *srchname;
+{
+	struct band *band;
+
+	for (band = supported_bands; band->name; band++)
+		if (!strcmp(band->name, srchname))
+			break;
+	if (!band->name)
+		return(-1);
+	current_band = band;
+	return(0);
+}
+
+check_arfcn_range(range, arfcn, ulp, dlp)
+	struct arfcn_range *range;
+	unsigned arfcn, *ulp, *dlp;
+{
+	if (arfcn < range->min)
+		return(-1);
+	if (arfcn > range->max)
+		return(-1);
+	if (ulp)
+		*ulp = range->ul_khz + (arfcn - range->min) * 200;
+	if (dlp)
+		*dlp = range->dl_khz + (arfcn - range->min) * 200;
+	return(0);
+}
+
+verify_arfcn(arfcn, ulp, dlp)
+	unsigned arfcn, *ulp, *dlp;
+{
+	if (!check_arfcn_range(current_band->arfcn_range, arfcn, ulp, dlp))
+		return(0);
+	if (current_band->arfcn_range_ext &&
+	    !check_arfcn_range(current_band->arfcn_range_ext, arfcn, ulp, dlp))
+		return(0);
+	return(-1);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cmu200/band.h	Sun May 21 06:37:56 2017 +0000
@@ -0,0 +1,18 @@
+/*
+ * In this header file we are going to define structures which contain
+ * our knowledge about GSM frequency bands we work with.
+ */
+
+struct arfcn_range {
+	unsigned	min;
+	unsigned	max;
+	unsigned	ul_khz;
+	unsigned	dl_khz;
+};
+
+struct band {
+	char			*name;
+	int			secaddr;
+	struct arfcn_range	*arfcn_range;
+	struct arfcn_range	*arfcn_range_ext;
+};