summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xgsm-tvoid/src/lib/Makefile.am2
-rw-r--r--gsm-tvoid/src/lib/cch.c1
-rw-r--r--gsm-tvoid/src/lib/fire_crc.c29
-rw-r--r--gsm-tvoid/src/lib/fire_crc.h31
4 files changed, 22 insertions, 41 deletions
diff --git a/gsm-tvoid/src/lib/Makefile.am b/gsm-tvoid/src/lib/Makefile.am
index 8a84086..f4072d9 100755
--- a/gsm-tvoid/src/lib/Makefile.am
+++ b/gsm-tvoid/src/lib/Makefile.am
@@ -38,7 +38,7 @@ ourlib_LTLIBRARIES = _gsm.la
# These are the source files that go into the shared library
_gsm_la_SOURCES = \
- fire_crc. \
+ fire_crc.c \
gsmstack.c \
interleave.c \
conv.c \
diff --git a/gsm-tvoid/src/lib/cch.c b/gsm-tvoid/src/lib/cch.c
index 8070649..17ee4ee 100644
--- a/gsm-tvoid/src/lib/cch.c
+++ b/gsm-tvoid/src/lib/cch.c
@@ -419,6 +419,7 @@ static unsigned char *decode_sacch(GS_CTX *ctx, unsigned char *burst, unsigned i
DEBUGF("error: sacch: parity error (%d)\n", errors);
return NULL;
} else {
+ DEBUGF("Successfully corrected parity bits!\n");
memcpy(decoded_data, crc_result, sizeof crc_result);
errors = 0;
}
diff --git a/gsm-tvoid/src/lib/fire_crc.c b/gsm-tvoid/src/lib/fire_crc.c
index ea14bcb..c9f0348 100644
--- a/gsm-tvoid/src/lib/fire_crc.c
+++ b/gsm-tvoid/src/lib/fire_crc.c
@@ -21,8 +21,8 @@
*/
#include "fire_crc.h"
-#include <math.h>
-#include <iostream>
+#include <stdio.h>
+#include <string.h>
#define REM(x, y) (x) % (y)
@@ -31,7 +31,9 @@ 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++)
+ int i;
+
+ for (i = 0; i < len; i++)
printf("%d ", data[i]);
printf("\n");
}
@@ -49,23 +51,21 @@ 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)
{
- int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0;
+ int j,error_count = 0, error_index = 0, success_flag = 0, syn_index = 0;
+ unsigned int i;
- ctx->syn_start = 0;
- // reset the syndrome register
+ 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++) {
+ // shift in the data bits
+ for (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++) {
+ for (i=0; i < ctx->crc_size; i++) {
error_count = FC_syndrome_shift(ctx, 1-input_bits[i+ctx->data_size]);
}
@@ -125,6 +125,7 @@ static int
FC_syndrome_shift(FC_CTX *ctx, unsigned int bit)
{
int error_count = 0;
+ unsigned int i;
if (ctx->syn_start == 0)
ctx->syn_start = 39;
@@ -134,8 +135,6 @@ FC_syndrome_shift(FC_CTX *ctx, unsigned int bit)
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];
@@ -170,7 +169,7 @@ FC_syndrome_shift(FC_CTX *ctx, unsigned int bit)
memcpy(ctx->syndrome_reg, temp_syndrome_reg, sizeof ctx->syndrome_reg);
- for (unsigned int i = 0; i < 28; i++) {
+ for (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
index 91cdee3..15d5b81 100644
--- a/gsm-tvoid/src/lib/fire_crc.h
+++ b/gsm-tvoid/src/lib/fire_crc.h
@@ -24,6 +24,10 @@
#ifndef INCLUDED_FIRE_CRC_H
#define INCLUDED_FIRE_CRC_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct
{
unsigned int crc_size;
@@ -35,31 +39,8 @@ typedef struct
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);
-
-};
+#ifdef __cplusplus
+}
#endif
#endif
personal git repositories of Harald Welte. Your mileage may vary