Remove utils imported from openbsc, fix building remaining util smpp_mirror
Related: OS#2522 Change-Id: If7e1af11cdac8587bb4d66fb4eacee4b79945359changes/39/5139/5
parent
f6d6a574e2
commit
a55dda703f
|
@ -49,6 +49,7 @@ PKG_CHECK_MODULES(LIBOSMOSIGTRAN, libosmo-sigtran >= 0.8.0)
|
|||
PKG_CHECK_MODULES(LIBOSMOSCCP, libosmo-sccp)
|
||||
PKG_CHECK_MODULES(LIBCRYPTO, libcrypto >= 0.9.5)
|
||||
PKG_CHECK_MODULES(LIBOSMOMGCPCLIENT, libosmo-mgcp-client >= 1.1.0)
|
||||
PKG_CHECK_MODULES(LIBSMPP34, libsmpp34 >= 1.12.0)
|
||||
|
||||
AC_ARG_ENABLE(sanitize,
|
||||
[AS_HELP_STRING(
|
||||
|
|
|
@ -19,27 +19,10 @@ AM_LDFLAGS = \
|
|||
$(NULL)
|
||||
|
||||
noinst_HEADERS = \
|
||||
meas_db.h \
|
||||
$(NULL)
|
||||
|
||||
bin_PROGRAMS = \
|
||||
meas_json \
|
||||
$(NULL)
|
||||
if HAVE_SQLITE3
|
||||
bin_PROGRAMS += \
|
||||
osmo-meas-udp2db \
|
||||
$(NULL)
|
||||
if HAVE_PCAP
|
||||
bin_PROGRAMS += \
|
||||
osmo-meas-pcap2db \
|
||||
$(NULL)
|
||||
endif
|
||||
endif
|
||||
if HAVE_LIBCDK
|
||||
bin_PROGRAMS += \
|
||||
meas_vis \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
if BUILD_SMPP
|
||||
noinst_PROGRAMS = \
|
||||
|
@ -51,6 +34,11 @@ smpp_mirror_SOURCES = \
|
|||
smpp_mirror.c \
|
||||
$(NULL)
|
||||
|
||||
smpp_mirror_CFLAGS = \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBSMPP34_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
smpp_mirror_LDADD = \
|
||||
$(top_builddir)/src/libcommon/libcommon.a \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
|
@ -58,72 +46,3 @@ smpp_mirror_LDADD = \
|
|||
$(LIBSMPP34_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
meas_vis_SOURCES = \
|
||||
meas_vis.c \
|
||||
$(NULL)
|
||||
|
||||
meas_vis_LDADD = \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
-lcdk \
|
||||
-lncurses \
|
||||
$(NULL)
|
||||
|
||||
meas_vis_CFLAGS = \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_pcap2db_SOURCES = \
|
||||
meas_pcap2db.c \
|
||||
meas_db.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_pcap2db_LDADD = \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(SQLITE3_LIBS) \
|
||||
-lpcap \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_pcap2db_CFLAGS = \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_udp2db_SOURCES = \
|
||||
meas_udp2db.c \
|
||||
meas_db.c \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_udp2db_LDADD = \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(SQLITE3_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
osmo_meas_udp2db_CFLAGS = \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
meas_json_SOURCES = \
|
||||
meas_json.c \
|
||||
$(NULL)
|
||||
|
||||
meas_json_LDADD = \
|
||||
$(top_builddir)/src/libcommon/libcommon.a \
|
||||
$(LIBOSMOCORE_LIBS) \
|
||||
$(LIBOSMOGSM_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
meas_json_CFLAGS = \
|
||||
$(LIBOSMOCORE_CFLAGS) \
|
||||
$(LIBOSMOGSM_CFLAGS) \
|
||||
$(LIBOSMOABIS_CFLAGS) \
|
||||
$(LIBOSMOSCCP_CFLAGS) \
|
||||
$(LIBOSMOMGCPCLIENT_CFLAGS) \
|
||||
$(NULL)
|
||||
|
||||
|
|
|
@ -1,330 +0,0 @@
|
|||
/* Routines for storing measurement reports in SQLite3 database */
|
||||
|
||||
/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include <osmocom/core/talloc.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
#include <osmocom/msc/meas_rep.h>
|
||||
|
||||
#include "meas_db.h"
|
||||
|
||||
#define INS_MR "INSERT INTO meas_rep (time, imsi, name, scenario, nr, bs_power, ms_timing_offset, fpc, ms_l1_pwr, ms_l1_ta) VALUES (?,?,?,?,?,?,?,?,?,?)"
|
||||
#define INS_UD "INSERT INTO meas_rep_unidir (meas_id, rx_lev_full, rx_lev_sub, rx_qual_full, rx_qual_sub, dtx, uplink) VALUES (?,?,?,?,?,?,?)"
|
||||
#define UPD_MR "UPDATE meas_rep SET ul_unidir=?, dl_unidir=? WHERE id=?"
|
||||
|
||||
struct meas_db_state {
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *stmt_ins_ud;
|
||||
sqlite3_stmt *stmt_ins_mr;
|
||||
sqlite3_stmt *stmt_upd_mr;
|
||||
};
|
||||
|
||||
/* macros to check for SQLite3 result codes */
|
||||
#define _SCK_OK(db, call, exp) \
|
||||
do { \
|
||||
int rc = call; \
|
||||
if (rc != exp) { \
|
||||
fprintf(stderr,"SQL Error in line %u: %s\n", \
|
||||
__LINE__, sqlite3_errmsg(db)); \
|
||||
goto err_io; \
|
||||
} \
|
||||
} while (0)
|
||||
#define SCK_OK(db, call) _SCK_OK(db, call, SQLITE_OK)
|
||||
#define SCK_DONE(db, call) _SCK_OK(db, call, SQLITE_DONE)
|
||||
|
||||
static int _insert_ud(struct meas_db_state *st, unsigned long meas_id, int dtx,
|
||||
int uplink, const struct gsm_meas_rep_unidir *ud)
|
||||
{
|
||||
unsigned long rowid;
|
||||
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 1, meas_id));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 2,
|
||||
rxlev2dbm(ud->full.rx_lev)));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 3,
|
||||
rxlev2dbm(ud->sub.rx_lev)));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 4, ud->full.rx_qual));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 5, ud->sub.rx_qual));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 6, dtx));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_ud, 7, uplink));
|
||||
|
||||
SCK_DONE(st->db, sqlite3_step(st->stmt_ins_ud));
|
||||
|
||||
SCK_OK(st->db, sqlite3_reset(st->stmt_ins_ud));
|
||||
|
||||
return sqlite3_last_insert_rowid(st->db);
|
||||
err_io:
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* insert a measurement report into the database */
|
||||
int meas_db_insert(struct meas_db_state *st, const char *imsi,
|
||||
const char *name, unsigned long timestamp,
|
||||
const char *scenario,
|
||||
const struct gsm_meas_rep *mr)
|
||||
{
|
||||
int rc;
|
||||
sqlite3_int64 rowid, ul_rowid, dl_rowid;
|
||||
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 1, timestamp));
|
||||
|
||||
if (imsi)
|
||||
SCK_OK(st->db, sqlite3_bind_text(st->stmt_ins_mr, 2,
|
||||
imsi, -1, SQLITE_STATIC));
|
||||
else
|
||||
SCK_OK(st->db, sqlite3_bind_null(st->stmt_ins_mr, 2));
|
||||
|
||||
if (name)
|
||||
SCK_OK(st->db, sqlite3_bind_text(st->stmt_ins_mr, 3,
|
||||
name, -1, SQLITE_STATIC));
|
||||
else
|
||||
SCK_OK(st->db, sqlite3_bind_null(st->stmt_ins_mr, 3));
|
||||
|
||||
if (scenario)
|
||||
SCK_OK(st->db, sqlite3_bind_text(st->stmt_ins_mr, 4,
|
||||
scenario, -1, SQLITE_STATIC));
|
||||
else
|
||||
SCK_OK(st->db, sqlite3_bind_null(st->stmt_ins_mr, 4));
|
||||
|
||||
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 5, mr->nr));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 6, mr->bs_power));
|
||||
|
||||
if (mr->flags & MEAS_REP_F_MS_TO)
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 7, mr->ms_timing_offset));
|
||||
else
|
||||
SCK_OK(st->db, sqlite3_bind_null(st->stmt_ins_mr, 7));
|
||||
|
||||
if (mr->flags & MEAS_REP_F_FPC)
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 8, 1));
|
||||
else
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 8, 0));
|
||||
|
||||
if (mr->flags & MEAS_REP_F_MS_L1) {
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 9,
|
||||
mr->ms_l1.pwr));
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_ins_mr, 10,
|
||||
mr->ms_l1.ta));
|
||||
}
|
||||
|
||||
SCK_DONE(st->db, sqlite3_step(st->stmt_ins_mr));
|
||||
SCK_OK(st->db, sqlite3_reset(st->stmt_ins_mr));
|
||||
|
||||
rowid = sqlite3_last_insert_rowid(st->db);
|
||||
|
||||
/* insert uplink measurement */
|
||||
ul_rowid = _insert_ud(st, rowid, mr->flags & MEAS_REP_F_UL_DTX,
|
||||
1, &mr->ul);
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_upd_mr, 1, ul_rowid));
|
||||
|
||||
/* insert downlink measurement, if present */
|
||||
if (mr->flags & MEAS_REP_F_DL_VALID) {
|
||||
dl_rowid = _insert_ud(st, rowid, mr->flags & MEAS_REP_F_DL_DTX,
|
||||
0, &mr->dl);
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_upd_mr, 2, dl_rowid));
|
||||
} else
|
||||
SCK_OK(st->db, sqlite3_bind_null(st->stmt_upd_mr, 2));
|
||||
|
||||
/* update meas_rep with the id's of the unidirectional
|
||||
* measurements */
|
||||
SCK_OK(st->db, sqlite3_bind_int(st->stmt_upd_mr, 3, rowid));
|
||||
SCK_DONE(st->db, sqlite3_step(st->stmt_upd_mr));
|
||||
SCK_OK(st->db, sqlite3_reset(st->stmt_upd_mr));
|
||||
|
||||
return 0;
|
||||
|
||||
err_io:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
int meas_db_begin(struct meas_db_state *st)
|
||||
{
|
||||
SCK_OK(st->db, sqlite3_exec(st->db, "BEGIN", NULL, NULL, NULL));
|
||||
|
||||
return 0;
|
||||
|
||||
err_io:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
int meas_db_commit(struct meas_db_state *st)
|
||||
{
|
||||
SCK_OK(st->db, sqlite3_exec(st->db, "COMMIT", NULL, NULL, NULL));
|
||||
|
||||
return 0;
|
||||
|
||||
err_io:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
static const char *create_stmts[] = {
|
||||
"CREATE TABLE IF NOT EXISTS meas_rep ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"time TIMESTAMP,"
|
||||
"imsi TEXT,"
|
||||
"name TEXT,"
|
||||
"scenario TEXT,"
|
||||
"nr INTEGER,"
|
||||
"bs_power INTEGER NOT NULL,"
|
||||
"ms_timing_offset INTEGER,"
|
||||
"fpc INTEGER NOT NULL DEFAULT 0,"
|
||||
"ul_unidir INTEGER REFERENCES meas_rep_unidir(id),"
|
||||
"dl_unidir INTEGER REFERENCES meas_rep_unidir(id),"
|
||||
"ms_l1_pwr INTEGER,"
|
||||
"ms_l1_ta INTEGER"
|
||||
")",
|
||||
"CREATE TABLE IF NOT EXISTS meas_rep_unidir ("
|
||||
"id INTEGER PRIMARY KEY AUTOINCREMENT,"
|
||||
"meas_id INTEGER NOT NULL REFERENCES meas_rep(id),"
|
||||
"rx_lev_full INTEGER NOT NULL,"
|
||||
"rx_lev_sub INTEGER NOT NULL,"
|
||||
"rx_qual_full INTEGER NOT NULL,"
|
||||
"rx_qual_sub INTEGER NOT NULL,"
|
||||
"dtx BOOLEAN NOT NULL DEFAULT 0,"
|
||||
"uplink BOOLEAN NOT NULL"
|
||||
")",
|
||||
"CREATE VIEW IF NOT EXISTS path_loss AS "
|
||||
"SELECT "
|
||||
"meas_rep.id, "
|
||||
"datetime(time,'unixepoch') AS timestamp, "
|
||||
"imsi, "
|
||||
"name, "
|
||||
"scenario, "
|
||||
"ms_timing_offset, "
|
||||
"ms_l1_ta, "
|
||||
"fpc, "
|
||||
"ms_l1_pwr, "
|
||||
"ud_ul.rx_lev_full AS ul_rx_lev_full, "
|
||||
"ms_l1_pwr-ud_ul.rx_lev_full AS ul_path_loss_full, "
|
||||
"ud_ul.rx_lev_sub ul_rx_lev_sub, "
|
||||
"ms_l1_pwr-ud_ul.rx_lev_sub AS ul_path_loss_sub, "
|
||||
"ud_ul.rx_qual_full AS ul_rx_qual_full, "
|
||||
"ud_ul.rx_qual_sub AS ul_rx_qual_sub, "
|
||||
"bs_power, "
|
||||
"ud_dl.rx_lev_full AS dl_rx_lev_full, "
|
||||
"bs_power-ud_dl.rx_lev_full AS dl_path_loss_full, "
|
||||
"ud_dl.rx_lev_sub AS dl_rx_lev_sub, "
|
||||
"bs_power-ud_dl.rx_lev_sub AS dl_path_loss_sub, "
|
||||
"ud_dl.rx_qual_full AS dl_rx_qual_full, "
|
||||
"ud_dl.rx_qual_sub AS dl_rx_qual_sub "
|
||||
"FROM "
|
||||
"meas_rep, "
|
||||
"meas_rep_unidir AS ud_dl, "
|
||||
"meas_rep_unidir AS ud_ul "
|
||||
"WHERE "
|
||||
"ud_ul.id = meas_rep.ul_unidir AND "
|
||||
"ud_dl.id = meas_rep.dl_unidir",
|
||||
"CREATE VIEW IF NOT EXISTS overview AS "
|
||||
"SELECT "
|
||||
"id,"
|
||||
"timestamp,"
|
||||
"imsi,"
|
||||
"name,"
|
||||
"scenario,"
|
||||
"ms_l1_pwr,"
|
||||
"ul_rx_lev_full,"
|
||||
"ul_path_loss_full,"
|
||||
"ul_rx_qual_full,"
|
||||
"bs_power,"
|
||||
"dl_rx_lev_full,"
|
||||
"dl_path_loss_full,"
|
||||
"dl_rx_qual_full "
|
||||
"FROM path_loss",
|
||||
};
|
||||
|
||||
static int check_create_tbl(struct meas_db_state *st)
|
||||
{
|
||||
int i, rc;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(create_stmts); i++) {
|
||||
SCK_OK(st->db, sqlite3_exec(st->db, create_stmts[i],
|
||||
NULL, NULL, NULL));
|
||||
}
|
||||
|
||||
return 0;
|
||||
err_io:
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
||||
#define PREP_CHK(db, stmt, ptr) \
|
||||
do { \
|
||||
int rc; \
|
||||
rc = sqlite3_prepare_v2(db, stmt, strlen(stmt)+1, \
|
||||
ptr, NULL); \
|
||||
if (rc != SQLITE_OK) { \
|
||||
fprintf(stderr, "Error during prepare of '%s': %s\n", \
|
||||
stmt, sqlite3_errmsg(db)); \
|
||||
goto err_io; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
struct meas_db_state *meas_db_open(void *ctx, const char *fname)
|
||||
{
|
||||
int rc;
|
||||
struct meas_db_state *st = talloc_zero(ctx, struct meas_db_state);
|
||||
|
||||
if (!st)
|
||||
return NULL;
|
||||
|
||||
rc = sqlite3_open_v2(fname, &st->db,
|
||||
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE,
|
||||
NULL);
|
||||
if (rc != SQLITE_OK) {
|
||||
fprintf(stderr, "Unable to open DB: %s\n",
|
||||
sqlite3_errmsg(st->db));
|
||||
goto err_io;
|
||||
}
|
||||
|
||||
rc = check_create_tbl(st);
|
||||
|
||||
PREP_CHK(st->db, INS_MR, &st->stmt_ins_mr);
|
||||
PREP_CHK(st->db, INS_UD, &st->stmt_ins_ud);
|
||||
PREP_CHK(st->db, UPD_MR, &st->stmt_upd_mr);
|
||||
|
||||
return st;
|
||||
err_io:
|
||||
talloc_free(st);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void meas_db_close(struct meas_db_state *st)
|
||||
{
|
||||
if (sqlite3_finalize(st->stmt_ins_mr) != SQLITE_OK)
|
||||
fprintf(stderr, "DB insert measurement report finalize error: %s\n",
|
||||
sqlite3_errmsg(st->db));
|
||||
if (sqlite3_finalize(st->stmt_ins_ud) != SQLITE_OK)
|
||||
fprintf(stderr, "DB insert unidir finalize error: %s\n",
|
||||
sqlite3_errmsg(st->db));
|
||||
if (sqlite3_finalize(st->stmt_upd_mr) != SQLITE_OK)
|
||||
fprintf(stderr, "DB update measurement report finalize error: %s\n",
|
||||
sqlite3_errmsg(st->db));
|
||||
if (sqlite3_close(st->db) != SQLITE_OK)
|
||||
fprintf(stderr, "Unable to close DB, abandoning.\n");
|
||||
|
||||
talloc_free(st);
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef OPENBSC_MEAS_DB_H
|
||||
#define OPENBSC_MEAS_DB_H
|
||||
|
||||
struct meas_db_state;
|
||||
|
||||
struct meas_db_state *meas_db_open(void *ctx, const char *fname);
|
||||
void meas_db_close(struct meas_db_state *st);
|
||||
|
||||
int meas_db_begin(struct meas_db_state *st);
|
||||
int meas_db_commit(struct meas_db_state *st);
|
||||
|
||||
int meas_db_insert(struct meas_db_state *st, const char *imsi,
|
||||
const char *name, unsigned long timestamp,
|
||||
const char *scenario,
|
||||
const struct gsm_meas_rep *mr);
|
||||
|
||||
#endif
|
|
@ -1,190 +0,0 @@
|
|||
/* Convert measurement report feed into JSON feed printed to stdout.
|
||||
* Each measurement report is printed as a separae JSON root entry.
|
||||
* All measurement reports are separated by a new line.
|
||||
*/
|
||||
|
||||
/* (C) 2015 by Alexander Chemeris <Alexander.Chemeris@fairwaves.co>
|
||||
* With parts of code adopted from different places in OpenBSC.
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <osmocom/core/socket.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
|
||||
#include <osmocom/msc/gsm_data.h>
|
||||
#include <osmocom/msc/gsm_data_shared.h>
|
||||
#include <osmocom/msc/meas_feed.h>
|
||||
|
||||
static void print_meas_rep_uni_json(struct gsm_meas_rep_unidir *mru)
|
||||
{
|
||||
printf("\"RXL-FULL\":%d, \"RXL-SUB\":%d, ",
|
||||
rxlev2dbm(mru->full.rx_lev),
|
||||
rxlev2dbm(mru->sub.rx_lev));
|
||||
printf("\"RXQ-FULL\":%d, \"RXQ-SUB\":%d",
|
||||
mru->full.rx_qual, mru->sub.rx_qual);
|
||||
}
|
||||
|
||||
static void print_meas_rep_json(struct gsm_meas_rep *mr)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("\"NR\":%d", mr->nr);
|
||||
|
||||
if (mr->flags & MEAS_REP_F_DL_DTX)
|
||||
printf(", \"DTXd\":true");
|
||||
|
||||
printf(", \"UL_MEAS\":{");
|
||||
print_meas_rep_uni_json(&mr->ul);
|
||||
printf("}");
|
||||
printf(", \"BS_POWER\":%d", mr->bs_power);
|
||||
if (mr->flags & MEAS_REP_F_MS_TO)
|
||||
printf(", \"MS_TO\":%d", mr->ms_timing_offset);
|
||||
|
||||
if (mr->flags & MEAS_REP_F_MS_L1) {
|
||||
printf(", \"L1_MS_PWR\":%d", mr->ms_l1.pwr);
|
||||
printf(", \"L1_FPC\":%s",
|
||||
mr->flags & MEAS_REP_F_FPC ? "true" : "false");
|
||||
printf(", \"L1_TA\":%u", mr->ms_l1.ta);
|
||||
}
|
||||
|
||||
if (mr->flags & MEAS_REP_F_UL_DTX)
|
||||
printf(", \"DTXu\":true");
|
||||
if (mr->flags & MEAS_REP_F_BA1)
|
||||
printf(", \"BA1\":true");
|
||||
if (mr->flags & MEAS_REP_F_DL_VALID) {
|
||||
printf(", \"DL_MEAS\":{");
|
||||
print_meas_rep_uni_json(&mr->dl);
|
||||
printf("}");
|
||||
}
|
||||
|
||||
if (mr->num_cell == 7)
|
||||
return;
|
||||
printf(", \"NUM_NEIGH\":%u, \"NEIGH\":[", mr->num_cell);
|
||||
for (i = 0; i < mr->num_cell; i++) {
|
||||
struct gsm_meas_rep_cell *mrc = &mr->cell[i];
|
||||
if (i!=0) printf(", ");
|
||||
printf("{\"IDX\":%u, \"ARFCN\":%u, \"BSIC\":%u, \"POWER\":%d}",
|
||||
mrc->neigh_idx, mrc->arfcn, mrc->bsic, rxlev2dbm(mrc->rxlev));
|
||||
}
|
||||
printf("]");
|
||||
}
|
||||
|
||||
static void print_chan_info_json(struct meas_feed_meas *mfm)
|
||||
{
|
||||
printf("\"lchan_type\":\"%s\", \"pchan_type\":\"%s\", "
|
||||
"\"bts_nr\":%d, \"trx_nr\":%d, \"ts_nr\":%d, \"ss_nr\":%d",
|
||||
gsm_lchant_name(mfm->lchan_type), gsm_pchan_name(mfm->pchan_type),
|
||||
mfm->bts_nr, mfm->trx_nr, mfm->ts_nr, mfm->ss_nr);
|
||||
}
|
||||
|
||||
static void print_meas_feed_json(struct meas_feed_meas *mfm)
|
||||
{
|
||||
time_t now = time(NULL);
|
||||
|
||||
printf("{");
|
||||
printf("\"time\":%ld, \"imsi\":\"%s\", \"name\":\"%s\", \"scenario\":\"%s\", ",
|
||||
now, mfm->imsi, mfm->name, mfm->scenario);
|
||||
|
||||
switch (mfm->hdr.version) {
|
||||
case 1:
|
||||
printf("\"chan_info\":{");
|
||||
print_chan_info_json(mfm);
|
||||
printf("}, ");
|
||||
/* no break, fall to version 0 */
|
||||
case 0:
|
||||
printf("\"meas_rep\":{");
|
||||
print_meas_rep_json(&mfm->mr);
|
||||
printf("}");
|
||||
break;
|
||||
}
|
||||
|
||||
printf("}\n");
|
||||
|
||||
}
|
||||
|
||||
static int handle_meas(struct msgb *msg)
|
||||
{
|
||||
struct meas_feed_meas *mfm = (struct meas_feed_meas *) msgb_data(msg);
|
||||
|
||||
print_meas_feed_json(mfm);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_msg(struct msgb *msg)
|
||||
{
|
||||
struct meas_feed_hdr *mfh = (struct meas_feed_hdr *) msgb_data(msg);
|
||||
|
||||
if (mfh->version != MEAS_FEED_VERSION)
|
||||
return -EINVAL;
|
||||
|
||||
switch (mfh->msg_type) {
|
||||
case MEAS_FEED_MEAS:
|
||||
handle_meas(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int udp_fd_cb(struct osmo_fd *ofd, unsigned int what)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (what & BSC_FD_READ) {
|
||||
struct msgb *msg = msgb_alloc(1024, "UDP Rx");
|
||||
|
||||
rc = read(ofd->fd, msgb_data(msg), msgb_tailroom(msg));
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
msgb_put(msg, rc);
|
||||
handle_msg(msg);
|
||||
msgb_free(msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
struct osmo_fd udp_ofd;
|
||||
|
||||
udp_ofd.cb = udp_fd_cb;
|
||||
rc = osmo_sock_init_ofd(&udp_ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 8888, OSMO_SOCK_F_BIND);
|
||||
if (rc < 0)
|
||||
exit(1);
|
||||
|
||||
while (1) {
|
||||
osmo_select_main(0);
|
||||
};
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,138 +0,0 @@
|
|||
/* read PCAP file with meas_feed data and write it to sqlite3 database */
|
||||
|
||||
/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
|
||||
#include <osmocom/core/socket.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
|
||||
#include <osmocom/msc/meas_feed.h>
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
#include "meas_db.h"
|
||||
|
||||
static struct meas_db_state *db;
|
||||
|
||||
static void handle_mfm(const struct pcap_pkthdr *h,
|
||||
const struct meas_feed_meas *mfm)
|
||||
{
|
||||
const char *scenario;
|
||||
|
||||
if (strlen(mfm->scenario))
|
||||
scenario = mfm->scenario;
|
||||
else
|
||||
scenario = NULL;
|
||||
|
||||
meas_db_insert(db, mfm->imsi, mfm->name, h->ts.tv_sec,
|
||||
scenario, &mfm->mr);
|
||||
}
|
||||
|
||||
static void pcap_cb(u_char *user, const struct pcap_pkthdr *h,
|
||||
const u_char *bytes)
|
||||
{
|
||||
const char *cur = bytes;
|
||||
const struct iphdr *ip;
|
||||
const struct udphdr *udp;
|
||||
const struct meas_feed_meas *mfm;
|
||||
uint16_t udplen;
|
||||
|
||||
if (h->caplen < 14+20+8)
|
||||
return;
|
||||
|
||||
/* Check if there is IPv4 in the Ethernet */
|
||||
if (cur[12] != 0x08 || cur[13] != 0x00)
|
||||
return;
|
||||
|
||||
cur += 14; /* ethernet header */
|
||||
ip = (struct iphdr *) cur;
|
||||
|
||||
if (ip->version != 4)
|
||||
return;
|
||||
cur += ip->ihl * 4;
|
||||
|
||||
if (ip->protocol != IPPROTO_UDP)
|
||||
return;
|
||||
|
||||
udp = (struct udphdr *) cur;
|
||||
|
||||
if (udp->dest != htons(8888))
|
||||
return;
|
||||
|
||||
udplen = ntohs(udp->len);
|
||||
if (udplen != sizeof(*udp) + sizeof(*mfm))
|
||||
return;
|
||||
cur += sizeof(*udp);
|
||||
|
||||
mfm = (const struct meas_feed_meas *) cur;
|
||||
|
||||
handle_mfm(h, mfm);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||
char *pcap_fname, *db_fname;
|
||||
pcap_t *pc;
|
||||
int rc;
|
||||
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "You need to specify PCAP and database file\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
pcap_fname = argv[1];
|
||||
db_fname = argv[2];
|
||||
|
||||
pc = pcap_open_offline(pcap_fname, errbuf);
|
||||
if (!pc) {
|
||||
fprintf(stderr, "Cannot open %s: %s\n", pcap_fname, errbuf);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
db = meas_db_open(NULL, db_fname);
|
||||
if (!db)
|
||||
exit(0);
|
||||
|
||||
rc = meas_db_begin(db);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error during BEGIN\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pcap_loop(pc, 0 , pcap_cb, NULL);
|
||||
|
||||
meas_db_commit(db);
|
||||
|
||||
exit(0);
|
||||
}
|
|
@ -1,126 +0,0 @@
|
|||
/* liesten to meas_feed on UDP and write it to sqlite3 database */
|
||||
|
||||
/* (C) 2012 by Harald Welte <laforge@gnumonks.org>
|
||||
*
|
||||
* All Rights Reserved
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <osmocom/core/socket.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
|
||||
#include <osmocom/msc/meas_feed.h>
|
||||
|
||||
#include "meas_db.h"
|
||||
|
||||
static struct osmo_fd udp_ofd;
|
||||
static struct meas_db_state *db;
|
||||
|
||||
static int handle_msg(struct msgb *msg)
|
||||
{
|
||||
struct meas_feed_hdr *mfh = (struct meas_feed_hdr *) msgb_data(msg);
|
||||
struct meas_feed_meas *mfm = (struct meas_feed_meas *) msgb_data(msg);
|
||||
const char *scenario;
|
||||
time_t now = time(NULL);
|
||||
|
||||
if (mfh->version != MEAS_FEED_VERSION)
|
||||
return -EINVAL;
|
||||
|
||||
if (mfh->msg_type != MEAS_FEED_MEAS)
|
||||
return -EINVAL;
|
||||
|
||||
if (strlen(mfm->scenario))
|
||||
scenario = mfm->scenario;
|
||||
else
|
||||
scenario = NULL;
|
||||
|
||||
meas_db_insert(db, mfm->imsi, mfm->name, now,
|
||||
scenario, &mfm->mr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int udp_fd_cb(struct osmo_fd *ofd, unsigned int what)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (what & BSC_FD_READ) {
|
||||
struct msgb *msg = msgb_alloc(1024, "UDP Rx");
|
||||
|
||||
rc = read(ofd->fd, msgb_data(msg), msgb_tailroom(msg));
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
msgb_put(msg, rc);
|
||||
handle_msg(msg);
|
||||
msgb_free(msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char *db_fname;
|
||||
int rc;
|
||||
|
||||
msgb_talloc_ctx_init(NULL, 0);
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "You have to specify the database file name\n");
|
||||
exit(2);
|
||||
}
|
||||
|
||||
db_fname = argv[1];
|
||||
|
||||
udp_ofd.cb = udp_fd_cb;
|
||||
rc = osmo_sock_init_ofd(&udp_ofd, AF_INET, SOCK_DGRAM,
|
||||
IPPROTO_UDP, NULL, 8888, OSMO_SOCK_F_BIND);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Unable to create UDP listen socket\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
db = meas_db_open(NULL, db_fname);
|
||||
if (!db) {
|
||||
fprintf(stderr, "Unable to open database\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* FIXME: timer-based BEGIN/COMMIT */
|
||||
|
||||
while (1) {
|
||||
osmo_select_main(0);
|
||||
};
|
||||
|
||||
meas_db_close(db);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
@ -1,310 +0,0 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <cdk/cdk.h>
|
||||
|
||||
#include <osmocom/core/socket.h>
|
||||
#include <osmocom/core/utils.h>
|
||||
#include <osmocom/core/msgb.h>
|
||||
#include <osmocom/core/select.h>
|
||||
#include <osmocom/core/talloc.h>
|
||||
|
||||
#include <osmocom/gsm/gsm_utils.h>
|
||||
|
||||
#include <osmocom/msc/meas_feed.h>
|
||||
|
||||
struct ms_state_uni {
|
||||
CDKSLIDER *cdk;
|
||||
CDKLABEL *cdk_label;
|
||||
|
||||
time_t last_update;
|
||||
char label[32];
|
||||
char *_lbl[1];
|
||||
};
|
||||
|
||||
|
||||
struct ms_state {
|
||||
struct llist_head list;
|
||||
|
||||
char name[31+1];
|
||||
char imsi[15+1];
|
||||
struct gsm_meas_rep mr;
|
||||
|
||||
struct ms_state_uni ul;
|
||||
struct ms_state_uni dl;
|
||||
};
|
||||
|
||||
struct state {
|
||||
struct osmo_fd udp_ofd;
|
||||
struct llist_head ms_list;
|
||||
|
||||
CDKSCREEN *cdkscreen;
|
||||
WINDOW *curses_win;
|
||||
|
||||
CDKLABEL *cdk_title;
|
||||
char *title;
|
||||
|
||||
CDKLABEL *cdk_header;
|
||||
char header[256];
|
||||
};
|
||||
|
||||
static struct state g_st;
|
||||
|
||||
struct ms_state *find_ms(const char *imsi)
|
||||
{
|
||||
struct ms_state *ms;
|
||||
|
||||
llist_for_each_entry(ms, &g_st.ms_list, list) {
|
||||
if (!strcmp(ms->imsi, imsi))
|
||||
return ms;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct ms_state *find_alloc_ms(const char *imsi)
|
||||
{
|
||||
struct ms_state *ms;
|
||||
|
||||
ms = find_ms(imsi);
|
||||
if (!ms) {
|
||||
ms = talloc_zero(NULL, struct ms_state);
|
||||
osmo_strlcpy(ms->imsi, imsi, sizeof(ms->imsi));
|
||||
ms->ul._lbl[0] = ms->ul.label;
|
||||
ms->dl._lbl[0] = ms->dl.label;
|
||||
llist_add_tail(&ms->list, &g_st.ms_list);
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
static int handle_meas(struct msgb *msg)
|
||||
{
|
||||
struct meas_feed_meas *mfm = (struct meas_feed_meas *) msgb_data(msg);
|
||||
struct ms_state *ms = find_alloc_ms(mfm->imsi);
|
||||
time_t now = time(NULL);
|
||||
|
||||
osmo_strlcpy(ms->name, mfm->name, sizeof(ms->name));
|
||||
memcpy(&ms->mr, &mfm->mr, sizeof(ms->mr));
|
||||
ms->ul.last_update = now;
|
||||
if (ms->mr.flags & MEAS_REP_F_DL_VALID)
|
||||
ms->dl.last_update = now;
|
||||
|
||||
/* move to head of list */
|
||||
llist_del(&ms->list);
|
||||
llist_add(&ms->list, &g_st.ms_list);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int handle_msg(struct msgb *msg)
|
||||
{
|
||||
struct meas_feed_hdr *mfh = (struct meas_feed_hdr *) msgb_data(msg);
|
||||
|
||||
if (mfh->version != MEAS_FEED_VERSION)
|
||||
return -EINVAL;
|
||||
|
||||
switch (mfh->msg_type) {
|
||||
case MEAS_FEED_MEAS:
|
||||
handle_meas(msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int udp_fd_cb(struct osmo_fd *ofd, unsigned int what)
|
||||
{
|
||||
int rc;
|
||||
|
||||
if (what & BSC_FD_READ) {
|
||||
struct msgb *msg = msgb_alloc(1024, "UDP Rx");
|
||||
|
||||
rc = read(ofd->fd, msgb_data(msg), msgb_tailroom(msg));
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
msgb_put(msg, rc);
|
||||
handle_msg(msg);
|
||||
msgb_free(msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void destroy_dir(struct ms_state_uni *uni)
|
||||
{
|
||||
if (uni->cdk) {
|
||||
destroyCDKSlider(uni->cdk);
|
||||
uni->cdk = NULL;
|
||||
}
|
||||
if (uni->cdk_label) {
|
||||
destroyCDKLabel(uni->cdk_label);
|
||||
uni->cdk_label = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#define DIR_UL 0
|
||||
#define DIR_DL 1
|
||||
static const char *dir_str[2] = {
|
||||
[DIR_UL] = "UL",
|
||||
[DIR_DL] = "DL",
|
||||
};
|
||||
|
||||
static int colpair_by_qual(uint8_t rx_qual)
|
||||
{
|
||||
if (rx_qual == 0)
|
||||
return 24;
|
||||
else if (rx_qual <= 4)
|
||||
return 32;
|
||||
else
|
||||
return 16;
|
||||
}
|
||||
|
||||
static int colpair_by_lev(int rx_lev)
|
||||
{
|
||||
if (rx_lev < -95)
|
||||
return 16;
|
||||
else if (rx_lev < -80)
|
||||
return 32;
|
||||
else
|
||||
return 24;
|
||||
}
|
||||
|
||||
|
||||
void write_uni(struct ms_state *ms, struct ms_state_uni *msu,
|
||||
struct gsm_rx_lev_qual *lq, int dir, int row)
|
||||
{
|
||||
|
||||
char label[128];
|
||||
time_t now = time(NULL);
|
||||
int qual_col = colpair_by_qual(lq->rx_qual);
|
||||
int lev_col = colpair_by_lev(rxlev2dbm(lq->rx_lev));
|
||||
int color, pwr;
|
||||
|
||||
if (dir == DIR_UL) {
|
||||
pwr = ms->mr.ms_l1.pwr;
|
||||
} else {
|
||||
pwr = ms->mr.bs_power;
|
||||
}
|
||||
|
||||
color = A_REVERSE | COLOR_PAIR(lev_col) | ' ';
|
||||
snprintf(label, sizeof(label), "%s %s ", ms->imsi, dir_str[dir]);
|
||||
msu->cdk = newCDKSlider(g_st.cdkscreen, 0, row, NULL, label, color,
|
||||
COLS-40, rxlev2dbm(lq->rx_lev), -110, -47,
|
||||
1, 2, FALSE, FALSE);
|
||||
//IsVisibleObj(ms->ul.cdk) = FALSE;
|
||||
snprintf(msu->label, sizeof(msu->label), "</%d>%1d<!%d> %3d %2u %2d %4u",
|
||||
qual_col, lq->rx_qual, qual_col, pwr,
|
||||
ms->mr.ms_l1.ta, ms->mr.ms_timing_offset,
|
||||
now - msu->last_update);
|
||||
msu->cdk_label = newCDKLabel(g_st.cdkscreen, RIGHT, row,
|
||||
msu->_lbl, 1, FALSE, FALSE);
|
||||
}
|
||||
|
||||
static void update_sliders(void)
|
||||
{
|
||||
int num_vis_sliders = 0;
|
||||
struct ms_state *ms;
|
||||
#define HEADER_LINES 2
|
||||
|
||||
/* remove all sliders */
|
||||
llist_for_each_entry(ms, &g_st.ms_list, list) {
|
||||
destroy_dir(&ms->ul);
|
||||
destroy_dir(&ms->dl);
|
||||
|
||||
}
|
||||
|
||||
llist_for_each_entry(ms, &g_st.ms_list, list) {
|
||||
struct gsm_rx_lev_qual *lq;
|
||||
unsigned int row = HEADER_LINES + num_vis_sliders*3;
|
||||
|
||||
if (ms->mr.flags & MEAS_REP_F_UL_DTX)
|
||||
lq = &ms->mr.ul.sub;
|
||||
else
|
||||
lq = &ms->mr.ul.full;
|
||||
write_uni(ms, &ms->ul, lq, DIR_UL, row);
|
||||
|
||||
if (ms->mr.flags & MEAS_REP_F_DL_DTX)
|
||||
lq = &ms->mr.dl.sub;
|
||||
else
|
||||
lq = &ms->mr.dl.full;
|
||||
write_uni(ms, &ms->dl, lq, DIR_DL, row+1);
|
||||
|
||||
num_vis_sliders++;
|
||||
if (num_vis_sliders >= LINES/3)
|
||||
break;
|
||||
}
|
||||
|
||||
refreshCDKScreen(g_st.cdkscreen);
|
||||
|
||||
}
|
||||
|
||||
const struct value_string col_strs[] = {
|
||||
{ COLOR_WHITE, "white" },
|
||||
{ COLOR_RED, "red" },
|
||||
{ COLOR_GREEN, "green" },
|
||||
{ COLOR_YELLOW, "yellow" },
|
||||
{ COLOR_BLUE, "blue" },
|
||||
{ COLOR_MAGENTA,"magenta" },
|
||||
{ COLOR_CYAN, "cyan" },
|
||||
{ COLOR_BLACK, "black" },
|
||||
{ 0, NULL }
|
||||
};
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int rc;
|
||||
char *header[1];
|
||||
char *title[1];
|
||||
|
||||
msgb_talloc_ctx_init(NULL, 0);
|
||||
|
||||
printf("sizeof(gsm_meas_rep)=%u\n", sizeof(struct gsm_meas_rep));
|
||||
printf("sizeof(meas_feed_meas)=%u\n", sizeof(struct meas_feed_meas));
|
||||
|
||||
INIT_LLIST_HEAD(&g_st.ms_list);
|
||||
g_st.curses_win = initscr();
|
||||
g_st.cdkscreen = initCDKScreen(g_st.curses_win);
|
||||
initCDKColor();
|
||||
|
||||
g_st.title = "OpenBSC link quality monitor";
|
||||
title[0] = g_st.title;
|
||||
g_st.cdk_title = newCDKLabel(g_st.cdkscreen, CENTER, 0, title, 1, FALSE, FALSE);
|
||||
|
||||
snprintf(g_st.header, sizeof(g_st.header), "Q Pwr TA TO Time");
|
||||
header[0] = g_st.header;
|
||||
g_st.cdk_header = newCDKLabel(g_st.cdkscreen, RIGHT, 1, header, 1, FALSE, FALSE);
|
||||
|
||||
#if 0
|
||||
int i;
|
||||
for (i = 0; i < 64; i++) {
|
||||
short f, b;
|
||||
pair_content(i, &f, &b);
|
||||
attron(COLOR_PAIR(i));
|
||||
printw("%u: %u (%s) ", i, f, get_value_string(col_strs, f));
|
||||
printw("%u (%s)\n\r", b, get_value_string(col_strs, b));
|
||||
}
|
||||
refresh();
|
||||
getch();
|
||||
exit(0);
|
||||
#endif
|
||||
|
||||
g_st.udp_ofd.cb = udp_fd_cb;
|
||||
rc = osmo_sock_init_ofd(&g_st.udp_ofd, AF_INET, SOCK_DGRAM, IPPROTO_UDP, NULL, 8888, OSMO_SOCK_F_BIND);
|
||||
if (rc < 0)
|
||||
exit(1);
|
||||
|
||||
while (1) {
|
||||
osmo_select_main(0);
|
||||
update_sliders();
|
||||
};
|
||||
|
||||
exit(0);
|
||||
}
|
Loading…
Reference in New Issue