summaryrefslogtreecommitdiff
path: root/gsm-tvoid/src/lib
diff options
context:
space:
mode:
authorleo <leo@brix.(none)>2008-04-17 13:48:57 +0100
committerleo <leo@brix.(none)>2008-04-17 13:48:57 +0100
commita4c10650e03854a79f9b2244924f2a132c7c2e62 (patch)
tree958754ae6ac3fd698a9cd9fe0c384bdf7940f912 /gsm-tvoid/src/lib
parente24a2e69fbc23ab9b7fcd122905a4af4ebdb55b7 (diff)
lala
Diffstat (limited to 'gsm-tvoid/src/lib')
-rwxr-xr-xgsm-tvoid/src/lib/Makefile.am2
-rw-r--r--gsm-tvoid/src/lib/fire_crc.c179
-rw-r--r--gsm-tvoid/src/lib/fire_crc.h65
3 files changed, 246 insertions, 0 deletions
diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am
index 2d4d7f7..8a84086 100755
--- a/gsm-tvoid/src/lib/Makefile.am
+++ b/gsm-tvoid/src/lib/Makefile.am
@@ -38,6 +38,7 @@ ourlib_LTLIBRARIES = _gsm.la
# These are the source files that go into the shared library
_gsm_la_SOURCES = \
+ fire_crc. \
gsmstack.c \
interleave.c \
conv.c \
@@ -63,6 +64,7 @@ gsm.cc gsm.py: $(LOCAL_IFILES) $(ALL_IFILES)
# These headers get installed in ${prefix}/include/gnuradio
grinclude_HEADERS = \
+ fire_crc.h \
gsm_burst.h \
gsmstack.h \
interleave.h \
diff --git a/gsm-tvoid/src/lib/fire_crc.c b/gsm-tvoid/src/lib/fire_crc.c
new file mode 100644
index 0000000..ea14bcb
--- /dev/null
+++ b/gsm-tvoid/src/lib/fire_crc.c
@@ -0,0 +1,179 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "fire_crc.h"
+#include <math.h>
+#include <iostream>
+
+#define REM(x, y) (x) % (y)
+
+static int FC_syndrome_shift(FC_CTX *ctx, unsigned int bit);
+
+static int
+outit(int *data, int len)
+{
+ for (int i = 0; i < len; i++)
+ printf("%d ", data[i]);
+ printf("\n");
+}
+
+int
+FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size)
+{
+ ctx->crc_size = crc_size;
+ ctx->data_size = data_size;
+ ctx->syn_start = 0;
+
+ return 0;
+}
+
+int
+FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data)
+{
+ int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0;
+
+ ctx->syn_start = 0;
+ // reset the syndrome register
+ memset(ctx->syndrome_reg, 0, sizeof ctx->syndrome_reg);
+ // d_syndrome_reg.clear();
+ //d_syndrome_reg.insert(d_syndrome_reg.begin(),40,0);
+
+ // shift in the data bits
+ //for (unsigned int i=0; i < 1; i++) {
+ for (unsigned int i=0; i < ctx->data_size; i++) {
+ error_count = FC_syndrome_shift(ctx, input_bits[i]);
+ control_data[i] = input_bits[i];
+ }
+
+ // shift in the crc bits
+ for (unsigned int i=0; i < ctx->crc_size; i++) {
+ error_count = FC_syndrome_shift(ctx, 1-input_bits[i+ctx->data_size]);
+ }
+
+ // Find position of error burst
+ if (error_count == 0) {
+ error_index = 0;
+ }
+ else {
+ error_index = 1;
+ error_count = FC_syndrome_shift(ctx, 0);
+ error_index += 1;
+ while (error_index < (ctx->data_size + ctx->crc_size) ) {
+ error_count = FC_syndrome_shift(ctx, 0);
+ error_index += 1;
+ if ( error_count == 0 ) break;
+ }
+ }
+
+ // Test for correctable errors
+ //printf("error_index %d\n",error_index);
+ if (error_index == 224) success_flag = 0;
+ else {
+
+ // correct index depending on the position of the error
+ if (error_index == 0) syn_index = error_index;
+ else syn_index = error_index - 1;
+
+ // error burst lies within data bits
+ if (error_index < 184) {
+ //printf("error < bit 184,%d\n",error_index);
+ j = error_index;
+ while ( j < (error_index+12) ) {
+ if (j < 184) {
+ control_data[j] = control_data[j] ^
+ ctx->syndrome_reg[REM(ctx->syn_start+39-j+syn_index,40)];
+ }
+ else break;
+ j = j + 1;
+ }
+ }
+ else if ( error_index > 212 ) {
+ //printf("error > bit 212,%d\n",error_index);
+ j = 0;
+ while ( j < (error_index - 212) ) {
+ control_data[j] = control_data[j] ^
+ ctx->syndrome_reg[REM(ctx->syn_start+39-j-224+syn_index,40)];
+ j = j + 1;
+ }
+ }
+ // for 183 < error_index < 213 error in parity alone so ignore
+ success_flag = 1;
+ }
+ return success_flag;
+}
+
+static int
+FC_syndrome_shift(FC_CTX *ctx, unsigned int bit)
+{
+ int error_count = 0;
+
+ if (ctx->syn_start == 0)
+ ctx->syn_start = 39;
+ else ctx->syn_start -= 1;
+
+ int temp_syndrome_reg[sizeof ctx->syndrome_reg];
+
+ memcpy(temp_syndrome_reg, ctx->syndrome_reg, sizeof temp_syndrome_reg);
+
+ //std::vector<int> temp_syndrome_reg = ctx->syndrome_reg;
+
+ temp_syndrome_reg[REM(ctx->syn_start+3,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+3,40)] ^
+ ctx->syndrome_reg[ctx->syn_start];
+ temp_syndrome_reg[REM(ctx->syn_start+17,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+17,40)] ^
+ ctx->syndrome_reg[ctx->syn_start];
+ temp_syndrome_reg[REM(ctx->syn_start+23,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+23,40)] ^
+ ctx->syndrome_reg[ctx->syn_start];
+ temp_syndrome_reg[REM(ctx->syn_start+26,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+26,40)] ^
+ ctx->syndrome_reg[ctx->syn_start];
+
+ temp_syndrome_reg[REM(ctx->syn_start+4,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+4,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+6,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+6,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+10,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+10,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+16,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+16,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+27,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+27,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+29,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+29,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+33,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+33,40)] ^ bit;
+ temp_syndrome_reg[REM(ctx->syn_start+39,40)] =
+ ctx->syndrome_reg[REM(ctx->syn_start+39,40)] ^ bit;
+
+ temp_syndrome_reg[ctx->syn_start] = ctx->syndrome_reg[ctx->syn_start] ^ bit;
+
+ memcpy(ctx->syndrome_reg, temp_syndrome_reg, sizeof ctx->syndrome_reg);
+
+ for (unsigned int i = 0; i < 28; i++) {
+ error_count = error_count + ctx->syndrome_reg[REM(ctx->syn_start+i,40)];
+ }
+ return error_count;
+}
+
+
diff --git a/gsm-tvoid/src/lib/fire_crc.h b/gsm-tvoid/src/lib/fire_crc.h
new file mode 100644
index 0000000..91cdee3
--- /dev/null
+++ b/gsm-tvoid/src/lib/fire_crc.h
@@ -0,0 +1,65 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2005 Free Software Foundation, Inc.
+ *
+ * This file is part of GNU Radio
+ *
+ * GNU Radio 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, or (at your option)
+ * any later version.
+ *
+ * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+
+#ifndef INCLUDED_FIRE_CRC_H
+#define INCLUDED_FIRE_CRC_H
+
+typedef struct
+{
+ unsigned int crc_size;
+ unsigned int data_size;
+ unsigned int syn_start;
+ int syndrome_reg[40];
+} FC_CTX;
+
+int FC_init(FC_CTX *ctx, unsigned int crc_size, unsigned int data_size);
+int FC_check_crc(FC_CTX *ctx, unsigned char *input_bits, unsigned char *control_data);
+
+#if 0
+/*!
+ * \brief
+ * \ingroup
+ */
+
+class fire_crc
+{
+protected:
+
+ unsigned int d_crc_size;
+ unsigned int d_data_size;
+ unsigned int d_syn_start;
+ std::vector<int> d_syndrome_reg;
+
+public:
+
+ fire_crc (unsigned int crc_size, unsigned int data_size);
+ ~fire_crc ();
+ int check_crc (const std::vector<int> &input_bits,
+ std::vector<int> &control_bits);
+ int syndrome_shift (unsigned int bit);
+ int rem (const int x, const int y);
+
+};
+#endif
+
+#endif
personal git repositories of Harald Welte. Your mileage may vary