|
|
@ -46,32 +46,34 @@
|
|
|
|
#define FLEN 9600
|
|
|
|
#define FLEN 9600
|
|
|
|
#define FLEN_PERIOD 0.005
|
|
|
|
#define FLEN_PERIOD 0.005
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_EARFCN 1000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int band = -1;
|
|
|
|
int band = -1;
|
|
|
|
int earfcn_start=-1, earfcn_end = -1;
|
|
|
|
int earfcn_start=-1, earfcn_end = -1;
|
|
|
|
int nof_frames_find=200;
|
|
|
|
int nof_frames_total = 50;
|
|
|
|
|
|
|
|
int nof_frames_detected = 10;
|
|
|
|
|
|
|
|
float threshold = -1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float uhd_gain = 60.0;
|
|
|
|
float uhd_gain = 60.0;
|
|
|
|
char *uhd_args="";
|
|
|
|
char *uhd_args="";
|
|
|
|
|
|
|
|
|
|
|
|
#define MAX_EARFCN 1000
|
|
|
|
|
|
|
|
lte_earfcn_t channels[MAX_EARFCN];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void usage(char *prog) {
|
|
|
|
void usage(char *prog) {
|
|
|
|
printf("Usage: %s [asefgv] -b band\n", prog);
|
|
|
|
printf("Usage: %s [agsendtvb] -b band\n", prog);
|
|
|
|
printf("\t-a UHD args [Default %s]\n", uhd_args);
|
|
|
|
printf("\t-a UHD args [Default %s]\n", uhd_args);
|
|
|
|
printf("\t-g UHD gain [Default %.2f dB]\n", uhd_gain);
|
|
|
|
printf("\t-g UHD gain [Default %.2f dB]\n", uhd_gain);
|
|
|
|
printf("\t-s earfcn_start [Default All]\n");
|
|
|
|
printf("\t-s earfcn_start [Default All]\n");
|
|
|
|
printf("\t-e earfcn_end [Default All]\n");
|
|
|
|
printf("\t-e earfcn_end [Default All]\n");
|
|
|
|
printf("\t-f nof_frames_find [Default %d]\n", nof_frames_find);
|
|
|
|
printf("\t-n nof_frames_total [Default 100]\n");
|
|
|
|
|
|
|
|
printf("\t-d nof_frames_detected [Default 10]\n");
|
|
|
|
|
|
|
|
printf("\t-t threshold [Default %.2f]\n",threshold);
|
|
|
|
printf("\t-v [set verbose to debug, default none]\n");
|
|
|
|
printf("\t-v [set verbose to debug, default none]\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void parse_args(int argc, char **argv) {
|
|
|
|
void parse_args(int argc, char **argv) {
|
|
|
|
int opt;
|
|
|
|
int opt;
|
|
|
|
while ((opt = getopt(argc, argv, "asefgvb")) != -1) {
|
|
|
|
while ((opt = getopt(argc, argv, "agsendtvb")) != -1) {
|
|
|
|
switch(opt) {
|
|
|
|
switch(opt) {
|
|
|
|
case 'a':
|
|
|
|
case 'a':
|
|
|
|
uhd_args = argv[optind];
|
|
|
|
uhd_args = argv[optind];
|
|
|
@ -85,8 +87,14 @@ void parse_args(int argc, char **argv) {
|
|
|
|
case 'e':
|
|
|
|
case 'e':
|
|
|
|
earfcn_end = atoi(argv[optind]);
|
|
|
|
earfcn_end = atoi(argv[optind]);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
case 'n':
|
|
|
|
nof_frames_find = atoi(argv[optind]);
|
|
|
|
nof_frames_total = atoi(argv[optind]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
|
|
|
|
nof_frames_detected = atoi(argv[optind]);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
|
|
|
|
threshold = atof(argv[optind]);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case 'g':
|
|
|
|
case 'g':
|
|
|
|
uhd_gain = atof(argv[optind]);
|
|
|
|
uhd_gain = atof(argv[optind]);
|
|
|
@ -105,26 +113,127 @@ void parse_args(int argc, char **argv) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int cuhd_recv_wrapper(void *h, void *data, uint32_t nsamples) {
|
|
|
|
int decode_pbch(void *uhd, cf_t *buffer, ue_celldetect_result_t *found_cell)
|
|
|
|
DEBUG(" ---- Receive %d samples ---- \n", nsamples);
|
|
|
|
{
|
|
|
|
return cuhd_recv(h, data, nsamples, 1);
|
|
|
|
ue_mib_t uemib;
|
|
|
|
|
|
|
|
pbch_mib_t mib;
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bzero(&mib, sizeof(pbch_mib_t));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t nof_frames = 0;
|
|
|
|
|
|
|
|
uint32_t flen = MIB_FRAME_SIZE;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ue_mib_init(&uemib, found_cell->cell_id, found_cell->cp)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error initiating PBCH decoder\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 1.92 MHz for PBCH decoding\n", 0);
|
|
|
|
|
|
|
|
cuhd_set_rx_srate(uhd, 1920000.0);
|
|
|
|
|
|
|
|
INFO("Starting receiver...\n", 0);
|
|
|
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen, 1)<0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("Calling ue_mib_decode() %d/%d\n", nof_frames, nof_frames_total);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = ue_mib_decode(&uemib, buffer, flen, &mib);
|
|
|
|
|
|
|
|
if (n == LIBLTE_ERROR || n == LIBLTE_ERROR_INVALID_INPUTS) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling ue_mib_decode()\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n == MIB_FRAME_UNALIGNED) {
|
|
|
|
|
|
|
|
printf("Realigning frame\n");
|
|
|
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen/2, 1)<0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
nof_frames++;
|
|
|
|
|
|
|
|
} while (n != MIB_FOUND && nof_frames < 2*nof_frames_total);
|
|
|
|
|
|
|
|
if (n == MIB_FOUND) {
|
|
|
|
|
|
|
|
printf("\n\nMIB decoded in %d ms (%d half frames)\n", nof_frames*5, nof_frames);
|
|
|
|
|
|
|
|
pbch_mib_fprint(stdout, &mib, found_cell->cell_id);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
printf("\nCould not decode MIB\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
|
|
|
cuhd_flush_buffer(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ue_mib_free(&uemib);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return LIBLTE_SUCCESS;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int find_cell(void *uhd, ue_celldetect_t *s, cf_t *buffer, ue_celldetect_result_t *found_cell)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("Setting sampling frequency 960 KHz for PSS search\n", 0);
|
|
|
|
|
|
|
|
cuhd_set_rx_srate(uhd, 960000.0);
|
|
|
|
|
|
|
|
INFO("Starting receiver...\n", 0);
|
|
|
|
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint32_t nof_scanned_cells = 0;
|
|
|
|
|
|
|
|
uint32_t flen = 4800;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen, 1)<0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = ue_celldetect_scan(s, buffer, flen, found_cell);
|
|
|
|
|
|
|
|
switch(n) {
|
|
|
|
|
|
|
|
case CS_FRAME_UNALIGNED:
|
|
|
|
|
|
|
|
printf("Realigning frame\n");
|
|
|
|
|
|
|
|
if (cuhd_recv(uhd, buffer, flen/2, 1)<0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error receiving from USRP\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
case CS_CELL_DETECTED:
|
|
|
|
|
|
|
|
if (found_cell->peak > 0) {
|
|
|
|
|
|
|
|
printf("\n\tCELL ID: %d, CP: %s, Peak: %.2f, Mode: %d/%d\n",
|
|
|
|
|
|
|
|
found_cell->cell_id, lte_cp_string(found_cell->cp),
|
|
|
|
|
|
|
|
found_cell->peak, found_cell->mode, s->nof_frames_detected);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
nof_scanned_cells++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CS_CELL_NOT_DETECTED:
|
|
|
|
|
|
|
|
nof_scanned_cells++;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case LIBLTE_ERROR:
|
|
|
|
|
|
|
|
case LIBLTE_ERROR_INVALID_INPUTS:
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling cellsearch_scan()\n");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} while(nof_scanned_cells < 3 && n != CS_CELL_DETECTED);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
INFO("Stopping receiver...\n", 0);
|
|
|
|
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
|
|
|
cuhd_flush_buffer(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return n;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
int ret;
|
|
|
|
int n;
|
|
|
|
int frame_cnt;
|
|
|
|
|
|
|
|
int nof_freqs;
|
|
|
|
|
|
|
|
uint32_t freq;
|
|
|
|
|
|
|
|
ue_sync_t uesync;
|
|
|
|
|
|
|
|
void *uhd;
|
|
|
|
void *uhd;
|
|
|
|
|
|
|
|
ue_celldetect_t s;
|
|
|
|
|
|
|
|
ue_celldetect_result_t found_cell;
|
|
|
|
cf_t *buffer;
|
|
|
|
cf_t *buffer;
|
|
|
|
lte_cell_t cell;
|
|
|
|
int nof_freqs;
|
|
|
|
|
|
|
|
lte_earfcn_t channels[MAX_EARFCN];
|
|
|
|
if (argc < 3) {
|
|
|
|
uint32_t freq;
|
|
|
|
usage(argv[0]);
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse_args(argc, argv);
|
|
|
|
parse_args(argc, argv);
|
|
|
|
|
|
|
|
|
|
|
@ -133,8 +242,6 @@ int main(int argc, char **argv) {
|
|
|
|
fprintf(stderr, "Error opening uhd\n");
|
|
|
|
fprintf(stderr, "Error opening uhd\n");
|
|
|
|
exit(-1);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set uhd_gain */
|
|
|
|
|
|
|
|
cuhd_set_rx_gain(uhd, uhd_gain);
|
|
|
|
cuhd_set_rx_gain(uhd, uhd_gain);
|
|
|
|
|
|
|
|
|
|
|
|
nof_freqs = lte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
|
|
|
|
nof_freqs = lte_band_get_fd_band(band, channels, earfcn_start, earfcn_end, MAX_EARFCN);
|
|
|
@ -143,59 +250,58 @@ int main(int argc, char **argv) {
|
|
|
|
exit(-1);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buffer = vec_malloc(sizeof(cf_t) * 96000);
|
|
|
|
|
|
|
|
if (!buffer) {
|
|
|
|
|
|
|
|
perror("malloc");
|
|
|
|
|
|
|
|
return LIBLTE_ERROR;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (freq=0;freq<nof_freqs;freq++) {
|
|
|
|
if (ue_celldetect_init(&s)) {
|
|
|
|
/* set freq */
|
|
|
|
fprintf(stderr, "Error initiating UE sync module\n");
|
|
|
|
cuhd_stop_rx_stream(uhd);
|
|
|
|
|
|
|
|
cuhd_set_rx_freq(uhd, (double) channels[freq].fd * MHZ);
|
|
|
|
|
|
|
|
cuhd_rx_wait_lo_locked(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (ue_sync_init(&uesync, cell, cuhd_recv_wrapper, uhd)) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error initiating UE sync\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (threshold > 0) {
|
|
|
|
|
|
|
|
ue_celldetect_set_threshold(&s, threshold);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ue_sync_decode_sss_on_track(&uesync, true);
|
|
|
|
if (nof_frames_total > 0) {
|
|
|
|
|
|
|
|
ue_celldetect_set_nof_frames_total(&s, nof_frames_total);
|
|
|
|
DEBUG("Starting receiver...\n",0);
|
|
|
|
}
|
|
|
|
cuhd_start_rx_stream(uhd);
|
|
|
|
if (nof_frames_detected > 0) {
|
|
|
|
usleep(10000);
|
|
|
|
ue_celldetect_set_nof_frames_detected(&s, nof_frames_detected);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (freq=0;freq<nof_freqs;freq+=10) {
|
|
|
|
|
|
|
|
|
|
|
|
/* Receive up to a maximum of nof_frames_find */
|
|
|
|
/* set uhd_freq */
|
|
|
|
frame_cnt = 0;
|
|
|
|
cuhd_set_rx_freq(uhd, (double) channels[freq].fd * MHZ);
|
|
|
|
ret = 0;
|
|
|
|
cuhd_rx_wait_lo_locked(uhd);
|
|
|
|
ue_sync_reset(&uesync);
|
|
|
|
usleep(10000);
|
|
|
|
|
|
|
|
INFO("Set uhd_freq to %.3f MHz\n", (double) channels[freq].fd * MHZ/1000000);
|
|
|
|
|
|
|
|
|
|
|
|
while(frame_cnt < nof_frames_find && ret == 0) {
|
|
|
|
|
|
|
|
ret = ue_sync_get_buffer(&uesync, &buffer);
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error calling ue_sync_work()\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
frame_cnt++;
|
|
|
|
|
|
|
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS. \r", freq, nof_freqs,
|
|
|
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz looking for PSS. \r", freq, nof_freqs,
|
|
|
|
channels[freq].id, channels[freq].fd);fflush(stdout);
|
|
|
|
channels[freq].id, channels[freq].fd);fflush(stdout);
|
|
|
|
|
|
|
|
|
|
|
|
if (VERBOSE_ISINFO()) {
|
|
|
|
if (VERBOSE_ISINFO()) {
|
|
|
|
printf("\n");
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
n = find_cell(uhd, &s, buffer, &found_cell);
|
|
|
|
|
|
|
|
if (n < 0) {
|
|
|
|
|
|
|
|
fprintf(stderr, "Error searching cell\n");
|
|
|
|
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ret == 1) {
|
|
|
|
if (n == CS_CELL_DETECTED) {
|
|
|
|
if (VERBOSE_ISINFO()) {
|
|
|
|
if (decode_pbch(uhd, buffer, &found_cell)) {
|
|
|
|
printf("[%3d/%d]: EARFCN %d Freq. %.2f MHz FOUND MIB ", freq, nof_freqs,
|
|
|
|
fprintf(stderr, "Error decoding PBCH\n");
|
|
|
|
channels[freq].id, channels[freq].fd);
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("CFO: %+.4f KHz\n", ue_sync_get_cfo(&uesync));
|
|
|
|
|
|
|
|
printf("\n");fflush(stdout);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ue_sync_free(&uesync);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ue_celldetect_free(&s);
|
|
|
|
cuhd_close(uhd);
|
|
|
|
cuhd_close(uhd);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
printf("\n\nDone\n");
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|