aboutsummaryrefslogtreecommitdiffstats
path: root/contrib
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2012-07-05 00:16:36 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2012-07-05 00:17:02 +0200
commiteda6c2636031eedfb701011a3882d4ca54228ad6 (patch)
tree9a8dff85df96a5f7bc5aedb6122d902d9c680aa4 /contrib
parent6b561bb7ba5f10c5fd96542a7e42de2822352a67 (diff)
calib: Add a mode to follow the BCCH of a given cell.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/sysmobts-calib/Makefile3
-rw-r--r--contrib/sysmobts-calib/sysmobts-calib.c49
-rw-r--r--contrib/sysmobts-calib/sysmobts-layer1.c22
3 files changed, 71 insertions, 3 deletions
diff --git a/contrib/sysmobts-calib/Makefile b/contrib/sysmobts-calib/Makefile
index e6e9b6f6..ba74ec1d 100644
--- a/contrib/sysmobts-calib/Makefile
+++ b/contrib/sysmobts-calib/Makefile
@@ -1,9 +1,10 @@
CFLAGS=`pkg-config --cflags libosmocore` -Wall -Werror
+LIBS=`pkg-config --libs libosmocore`
all: sysmobts-calib
sysmobts-calib: sysmobts-calib.o sysmobts-layer1.o
- $(CC) $(CPPFLAGS) -o $@ $^ -lrt
+ $(CC) $(CPPFLAGS) -o $@ $^ -lrt $(LIBS)
clean:
@rm -f sysmobts-calib *.o
diff --git a/contrib/sysmobts-calib/sysmobts-calib.c b/contrib/sysmobts-calib/sysmobts-calib.c
index e881b08c..2b585db1 100644
--- a/contrib/sysmobts-calib/sysmobts-calib.c
+++ b/contrib/sysmobts-calib/sysmobts-calib.c
@@ -33,16 +33,18 @@
#include <sysmocom/femtobts/superfemto.h>
#include <sysmocom/femtobts/gsml1types.h>
-#define ARRAY_SIZE(ar) (sizeof(ar)/sizeof((ar)[0]))
+#include <osmocom/core/utils.h>
enum actions {
ACTION_SCAN,
ACTION_CALIB,
+ ACTION_BCCH,
};
static const char *modes[] = {
[ACTION_SCAN] = "scan",
[ACTION_CALIB] = "calibrate",
+ [ACTION_BCCH] = "bcch",
};
static const char *bands[] = {
@@ -98,7 +100,7 @@ static void print_help(void)
printf(" -s --calibration-source "
"ocxo|tcxo|external|gps|trx|rx|edge|netlisten\n");
printf(" -b --band 850|900|1800|1900\n");
- printf(" -m --mode scan|calibrate\n");
+ printf(" -m --mode scan|calibrate|bcch\n");
printf(" -a --arfcn NR arfcn for calibration\n");
printf(" -d --dsp-flags NR dsp mask for debug log\n");
printf(" -t --threshold level\n");
@@ -213,6 +215,8 @@ extern int set_clock_cor(int clock_corr, int calib, int source);
extern int rf_clock_info(HANDLE *layer1, int *clkErr, int *clkErrRes);
extern int mph_close(HANDLE layer1);
extern int wait_for_sync(HANDLE layer1, int cor, int calib, int source);
+extern int follow_bcch(HANDLE layer1);
+extern int wait_for_data(uint8_t *data, size_t *size);
#define CHECK_RC(rc) \
if (rc != 0) \
@@ -374,6 +378,45 @@ static int calib_clock(void)
return EXIT_SUCCESS;
}
+static int bcch_follow(void)
+{
+ int rc, cor = initial_cor;
+ float mean_rssi;
+ HANDLE layer1;
+
+ rc = power_scan(band, cal_arfcn, 10, &mean_rssi);
+ CHECK_RC_MSG(rc, "ARFCN measurement scan failed");
+ if (mean_rssi < -118.0f)
+ printf("ARFCN has weak signal for calibration: %f\n", mean_rssi);
+
+ /* initial lock */
+ rc = follow_sch(band, cal_arfcn, calib, source, &layer1);
+ if (rc == -23)
+ rc = find_initial_clock(layer1, &cor);
+ CHECK_RC_MSG(rc, "Following SCH failed");
+
+ /* follow the bcch */
+ rc = follow_bcch(layer1);
+ CHECK_RC_MSG(rc, "Follow BCCH");
+
+ /* now wait for the PhDataInd */
+ for (;;) {
+ uint8_t data[23];
+ size_t size;
+
+ rc = wait_for_data(data, &size);
+ if (rc == 1)
+ continue;
+ CHECK_RC_MSG(rc, "No Data Indication");
+ printf("Data: %s\n", osmo_hexdump(data, size));
+ }
+
+ rc = mph_close(layer1);
+ CHECK_RC_MSG(rc, "MPH-Close");
+
+ return EXIT_SUCCESS;
+}
+
int main(int argc, char **argv)
{
int rc;
@@ -394,6 +437,8 @@ int main(int argc, char **argv)
if (action == ACTION_SCAN)
return scan_band();
+ else if (action == ACTION_BCCH)
+ return bcch_follow();
else
return calib_clock();
diff --git a/contrib/sysmobts-calib/sysmobts-layer1.c b/contrib/sysmobts-calib/sysmobts-layer1.c
index d886997f..239318b4 100644
--- a/contrib/sysmobts-calib/sysmobts-layer1.c
+++ b/contrib/sysmobts-calib/sysmobts-layer1.c
@@ -498,6 +498,12 @@ int follow_bcch(HANDLE layer1)
return rc;
}
+ if (prim.u.phConnectInd.sapi != GsmL1_Sapi_Bcch) {
+ printf("Got a connect indication for the wrong type: %d\n",
+ prim.u.phConnectInd.sapi);
+ return -6;
+ }
+
/* 3.) Wait for PhDataInd... */
printf("Waiting for BCCH data.\n");
rc = wait_for_indication(GsmL1_PrimId_PhDataInd, &prim);
@@ -632,6 +638,22 @@ int wait_for_sync(HANDLE layer1, int cor, int calib, int source)
return 0;
}
+int wait_for_data(uint8_t *data, size_t *size)
+{
+ GsmL1_Prim_t prim;
+ int rc;
+
+ rc = wait_for_indication(GsmL1_PrimId_PhDataInd, &prim);
+ if (rc < 0)
+ return rc;
+ if (prim.u.phDataInd.sapi == GsmL1_Sapi_Sch)
+ return 1;
+
+ *size = prim.u.phDataInd.msgUnitParam.u8Size;
+ memcpy(data, prim.u.phDataInd.msgUnitParam.u8Buffer, *size);
+ return 0;
+}
+
/**
* Make sure the pipe is not running full.
*