From 0cfefa0e120c51fb745b66b7a6915b140635f9b5 Mon Sep 17 00:00:00 2001 From: Holger Hans Peter Freyther Date: Wed, 11 Jul 2012 23:14:10 +0200 Subject: calib: Add code to change the BSIC/TSC before following the BCCH. --- contrib/sysmobts-calib/sysmobts-calib.c | 14 +++++++++ contrib/sysmobts-calib/sysmobts-layer1.c | 51 +++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) (limited to 'contrib') diff --git a/contrib/sysmobts-calib/sysmobts-calib.c b/contrib/sysmobts-calib/sysmobts-calib.c index e246a327..6e7cac34 100644 --- a/contrib/sysmobts-calib/sysmobts-calib.c +++ b/contrib/sysmobts-calib/sysmobts-calib.c @@ -211,6 +211,8 @@ extern int activate_rf_frontend(int clock_source, int clock_cor); extern int power_scan(int band, int arfcn, int duration, float *mean_rssi); extern int follow_sch(int band, int arfcn, int calib, int reference, HANDLE *layer1); extern int follow_bch(HANDLE layer1); +extern int find_bsic(void); +extern int set_tsc_from_bsic(HANDLE layer1, int bsic); 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); @@ -227,6 +229,11 @@ extern int wait_for_data(uint8_t *data, size_t *size); printf("%s: %d\n", msg, rc); \ return EXIT_FAILURE; \ } +#define CHECK_COND_MSG(cond, rc, msg) \ + if (cond) { \ + printf("%s: %d\n", msg, rc); \ + return EXIT_FAILURE; \ + } struct scan_result { @@ -395,6 +402,13 @@ static int bcch_follow(void) rc = find_initial_clock(layer1, &cor); CHECK_RC_MSG(rc, "Following SCH failed"); + /* identify the BSIC and set it as TSC */ + rc = find_bsic(); + CHECK_COND_MSG(rc < 0, rc, "Identifying the BSIC failed"); + rc = set_tsc_from_bsic(layer1, rc); + CHECK_RC_MSG(rc, "Setting the TSC failed"); + + /* follow the bcch */ rc = follow_bcch(layer1); CHECK_RC_MSG(rc, "Follow BCCH"); diff --git a/contrib/sysmobts-calib/sysmobts-layer1.c b/contrib/sysmobts-calib/sysmobts-layer1.c index 239318b4..c53a21c2 100644 --- a/contrib/sysmobts-calib/sysmobts-layer1.c +++ b/contrib/sysmobts-calib/sysmobts-layer1.c @@ -407,7 +407,8 @@ int follow_sch(int band, int arfcn, int clock, int ref, HANDLE *layer1) memset(&prim, 0, sizeof(prim)); prim.u.mphConnectReq.hLayer1 = *layer1; prim.u.mphConnectReq.u8Tn = 0; - prim.u.mphConnectReq.logChComb = GsmL1_LogChComb_V; + prim.u.mphConnectReq.logChComb = GsmL1_LogChComb_IV; + printf("FIVE\n"); rc = send_recv_sig_prim(GsmL1_PrimId_MphConnectReq, &prim); if (rc != 0) { printf("Failed to connect.\n"); @@ -515,6 +516,54 @@ int follow_bcch(HANDLE layer1) return 0; } +int find_bsic(void) +{ + int rc, i; + GsmL1_Prim_t prim; + + printf("Waiting for SCH data.\n"); + for (i = 0; i < 10; ++i) { + uint8_t bsic; + rc = wait_for_indication(GsmL1_PrimId_PhDataInd, &prim); + if (rc < 0) { + printf("Didn't get SCH data.\n"); + return rc; + } + if (prim.u.phDataInd.sapi != GsmL1_Sapi_Sch) + continue; + + bsic = (prim.u.phDataInd.msgUnitParam.u8Buffer[0] >> 2) & 0xFF; + return bsic; + } + + printf("Giving up finding the SCH\n"); + return -1; +} + +int set_tsc_from_bsic(HANDLE layer1, int bsic) +{ + int rc; + int tsc = bsic & 0x7; + GsmL1_Prim_t prim; + + memset(&prim, 0, sizeof(prim)); + prim.u.mphConfigReq.hLayer3 = 0x23; + prim.u.mphConfigReq.hLayer1 = layer1; + prim.u.mphConfigReq.cfgParamId = GsmL1_ConfigParamId_SetNbTsc; + prim.u.mphConfigReq.cfgParams.setNbTsc.u8NbTsc = tsc; + rc = send_recv_sig_prim(GsmL1_PrimId_MphConfigReq, &prim); + if (rc != 0) { + printf("Failed to send configure.\n"); + } + + if (prim.u.mphConfigCnf.status != GsmL1_Status_Success) { + printf("Failed to set the config cnf.\n"); + return -1; + } + + return 0; +} + int set_clock_cor(int clock_cor, int calib, int source) { int rc; -- cgit v1.2.3