2017-01-09 16:05:31 +00:00
|
|
|
/* osmocom includes */
|
|
|
|
|
|
|
|
#include <osmocom/core/msgb.h>
|
|
|
|
#include <osmocom/core/select.h>
|
|
|
|
#include <stdint.h>
|
2017-04-24 08:45:17 +00:00
|
|
|
#include <string.h>
|
2017-01-09 16:05:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2017-03-12 13:11:40 +00:00
|
|
|
#include <getopt.h>
|
2017-02-06 13:14:31 +00:00
|
|
|
#include <virtphy/virtual_um.h>
|
|
|
|
#include <virtphy/l1ctl_sock.h>
|
|
|
|
#include <virtphy/virt_l1_model.h>
|
|
|
|
#include <virtphy/l1ctl_sap.h>
|
|
|
|
#include <virtphy/gsmtapl1_if.h>
|
|
|
|
#include <virtphy/logging.h>
|
2017-02-25 15:17:12 +00:00
|
|
|
#include <virtphy/virt_l1_sched.h>
|
2017-01-09 16:05:31 +00:00
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
#define DEFAULT_MCAST_PORT 4729 /* IANA-registered port for GSMTAP */
|
|
|
|
#define DEFAULT_LOG_MASK "DL1C,1:DVIRPHY,1"
|
|
|
|
|
|
|
|
static char* dl_rx_grp = DEFAULT_MS_MCAST_GROUP;
|
|
|
|
static char* ul_tx_grp = DEFAULT_BTS_MCAST_GROUP;
|
|
|
|
static int port = DEFAULT_MCAST_PORT;
|
|
|
|
static char* log_mask = DEFAULT_LOG_MASK;
|
|
|
|
static char * l1ctl_sock_path = L1CTL_SOCK_PATH;
|
2017-04-24 08:45:17 +00:00
|
|
|
static char * arfcn_sig_lev_red_mask = NULL;
|
|
|
|
static char * pm_timeout = NULL;
|
2017-03-12 13:11:40 +00:00
|
|
|
|
|
|
|
static void handle_options(int argc, char **argv)
|
2017-01-09 16:05:31 +00:00
|
|
|
{
|
2017-03-12 13:11:40 +00:00
|
|
|
while (1) {
|
|
|
|
int option_index = 0, c;
|
|
|
|
static struct option long_options[] = {
|
|
|
|
{"dl-rx-grp", required_argument, 0, 'z'},
|
|
|
|
{"ul-tx-grp", required_argument, 0, 'y'},
|
|
|
|
{"port", required_argument, 0, 'x'},
|
|
|
|
{"log-mask", required_argument, 0, 'd'},
|
|
|
|
{"l1ctl-sock", required_argument, 0, 's'},
|
2017-04-24 08:45:17 +00:00
|
|
|
{"arfcn-sig-lev-red", required_argument, 0, 'r'},
|
|
|
|
{"pm-timeout", required_argument, 0, 't'},
|
2017-03-12 13:11:40 +00:00
|
|
|
{0, 0, 0, 0},
|
|
|
|
};
|
2017-04-24 08:45:17 +00:00
|
|
|
c = getopt_long(argc, argv, "z:y:x:d:s:r:t:", long_options,
|
2017-03-12 13:11:40 +00:00
|
|
|
&option_index);
|
|
|
|
if (c == -1)
|
|
|
|
break;
|
2017-02-09 16:59:54 +00:00
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'z':
|
|
|
|
dl_rx_grp = optarg;
|
|
|
|
break;
|
|
|
|
case 'y':
|
|
|
|
ul_tx_grp = optarg;
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
port = atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
log_mask = optarg;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
l1ctl_sock_path = optarg;
|
|
|
|
break;
|
2017-04-24 08:45:17 +00:00
|
|
|
case 'r':
|
|
|
|
arfcn_sig_lev_red_mask = optarg;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
pm_timeout = optarg;
|
|
|
|
break;
|
2017-03-12 13:11:40 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-02-09 16:59:54 +00:00
|
|
|
}
|
2017-03-12 13:11:40 +00:00
|
|
|
}
|
|
|
|
|
2017-04-24 08:45:17 +00:00
|
|
|
void parse_pm_timeout(struct l1_model_ms *model, char *pm_timeout) {
|
|
|
|
|
|
|
|
if(!pm_timeout || (strcmp(pm_timeout, "") == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// seconds
|
|
|
|
char *buf = strtok(pm_timeout, ":");
|
|
|
|
model->state->pm.timeout_s = atoi(buf);
|
|
|
|
// microseconds
|
|
|
|
buf = strtok(NULL, ":");
|
|
|
|
if(buf) {
|
|
|
|
model->state->pm.timeout_us = atoi(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* arfcn_sig_lev_red_mask has to be formatted like 666,12:888,43:176,22
|
|
|
|
*/
|
|
|
|
void parse_arfcn_sig_lev_red(struct l1_model_ms *model, char * arfcn_sig_lev_red_mask) {
|
|
|
|
|
|
|
|
if(!arfcn_sig_lev_red_mask || (strcmp(arfcn_sig_lev_red_mask, "") == 0)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char *token = strtok(arfcn_sig_lev_red_mask, ":");
|
|
|
|
do {
|
|
|
|
char* colon = strstr(token, ",");
|
|
|
|
uint16_t arfcn;
|
|
|
|
uint8_t red;
|
|
|
|
if(!colon) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
colon[0] = '\0';
|
|
|
|
|
|
|
|
arfcn = atoi(token);
|
|
|
|
red = atoi(colon + 1);
|
|
|
|
|
|
|
|
//TODO: this may go wild if the token string is not properly formatted
|
|
|
|
model->state->pm.meas.arfcn_sig_lev_red_dbm[arfcn] = red;
|
|
|
|
} while ((token = strtok(NULL, ":")));
|
|
|
|
}
|
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
// init loginfo
|
|
|
|
static struct l1_model_ms *model;
|
2017-02-09 16:59:54 +00:00
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
handle_options(argc, argv);
|
2017-02-09 16:59:54 +00:00
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
ms_log_init(log_mask);
|
2017-01-09 16:05:31 +00:00
|
|
|
|
|
|
|
LOGP(DVIRPHY, LOGL_INFO, "Virtual physical layer starting up...\n");
|
|
|
|
|
|
|
|
model = l1_model_ms_init(NULL);
|
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
model->vui = virt_um_init(NULL, ul_tx_grp, port, dl_rx_grp, port,
|
|
|
|
gsmtapl1_rx_from_virt_um_inst_cb);
|
|
|
|
model->lsi = l1ctl_sock_init(NULL, l1ctl_sap_rx_from_l23_inst_cb,
|
|
|
|
l1ctl_sock_path);
|
2017-01-09 16:05:31 +00:00
|
|
|
|
|
|
|
gsmtapl1_init(model);
|
|
|
|
l1ctl_sap_init(model);
|
2017-02-25 15:17:12 +00:00
|
|
|
virt_l1_sched_init(model);
|
2017-01-09 16:05:31 +00:00
|
|
|
|
2017-04-24 08:45:17 +00:00
|
|
|
// apply timeout and arfcn reduction value config to model
|
|
|
|
parse_pm_timeout(model, pm_timeout);
|
|
|
|
parse_arfcn_sig_lev_red(model, arfcn_sig_lev_red_mask);
|
|
|
|
|
2017-03-12 13:11:40 +00:00
|
|
|
LOGP(DVIRPHY, LOGL_INFO,
|
|
|
|
"Virtual physical layer ready...\n \
|
|
|
|
Waiting for l23 app on %s",
|
|
|
|
l1ctl_sock_path);
|
2017-01-09 16:05:31 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
// handle osmocom fd READ events (l1ctl-unix-socket, virtual-um-mcast-socket)
|
|
|
|
osmo_select_main(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
l1_model_ms_destroy(model);
|
|
|
|
|
|
|
|
// not reached
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|