/* VTY interface for sysmoBTS */ /* (C) 2011 by Harald Welte * * 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 . * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "femtobts.h" #include "l1_if.h" static struct gsm_bts *vty_bts; /* This generates the logging command string for VTY. */ const char *vty_cmd_string_from_valstr(const struct value_string *vals, const char *prefix) { int len = 0, offset = 0, ret, i, rem; int size = strlen(prefix); const struct value_string *vs; char *str; for (vs = vals; vs->value || vs->str; vs++) size += strlen(vs->str) + 1; rem = size; str = talloc_zero_size(vty_bts, size); if (!str) return NULL; ret = snprintf(str + offset, rem, prefix); if (ret < 0) goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); for (vs = vals; vs->value || vs->str; vs++) { if (vs->str) { int j, name_len = strlen(vs->str)+1; char name[name_len]; for (j = 0; j < name_len; j++) name[j] = tolower(vs->str[j]); name[name_len-1] = '\0'; ret = snprintf(str + offset, rem, "%s|", name); if (ret < 0) goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); } } offset--; /* to remove the trailing | */ rem++; ret = snprintf(str + offset, rem, ")"); if (ret < 0) goto err; OSMO_SNPRINTF_RET(ret, rem, offset, len); err: str[size-1] = '\0'; return str; } DEFUN(show_dsp_trace_f, show_dsp_trace_f_cmd, "show trx <0-0> dsp-trace-flags", SHOW_STR "Display the current setting of the DSP trace flags") { int trx_nr = atoi(argv[0]); struct gsm_bts_trx *trx = gsm_bts_trx_num(vty_bts, trx_nr); struct femtol1_hdl *fl1h; int i; if (!trx) return CMD_WARNING; fl1h = trx_femtol1_hdl(trx); vty_out(vty, "Femto L1 DSP trace flags:%s", VTY_NEWLINE); for (i = 0; i < ARRAY_SIZE(femtobts_tracef_names); i++) { const char *endis; if (femtobts_tracef_names[i].value == 0 && femtobts_tracef_names[i].str == NULL) break; if (fl1h->dsp_trace_f & femtobts_tracef_names[i].value) endis = "enabled"; else endis = "disabled"; vty_out(vty, "DSP Trace %-15s %s%s", femtobts_tracef_names[i].str, endis, VTY_NEWLINE); } return CMD_SUCCESS; } DEFUN(dsp_trace_f, dsp_trace_f_cmd, "HIDDEN", "HIDDEN") { int trx_nr = atoi(argv[0]); struct gsm_bts_trx *trx = gsm_bts_trx_num(vty_bts, trx_nr); struct femtol1_hdl *fl1h; unsigned int flag ; if (!trx) { vty_out(vty, "Cannot find TRX number %u%s", trx_nr, VTY_NEWLINE); return CMD_WARNING; } fl1h = trx_femtol1_hdl(trx); flag = get_string_value(femtobts_tracef_names, argv[1]); l1if_set_trace_flags(fl1h, fl1h->dsp_trace_f | flag); return CMD_SUCCESS; } DEFUN(no_dsp_trace_f, no_dsp_trace_f_cmd, "HIDDEN", "HIDDEN") { int trx_nr = atoi(argv[0]); struct gsm_bts_trx *trx = gsm_bts_trx_num(vty_bts, trx_nr); struct femtol1_hdl *fl1h; unsigned int flag ; if (!trx) { vty_out(vty, "Cannot find TRX number %u%s", trx_nr, VTY_NEWLINE); return CMD_WARNING; } fl1h = trx_femtol1_hdl(trx); flag = get_string_value(femtobts_tracef_names, argv[1]); l1if_set_trace_flags(fl1h, fl1h->dsp_trace_f & ~flag); return CMD_SUCCESS; } int femtol1_vty_init(struct gsm_bts *bts) { vty_bts = bts; /* runtime-patch the command strings with debug levels */ dsp_trace_f_cmd.string = vty_cmd_string_from_valstr(femtobts_tracef_names, "trx <0-0> dsp-trace-flag ("); no_dsp_trace_f_cmd.string = vty_cmd_string_from_valstr(femtobts_tracef_names, "no trx <0-0> dsp-trace-flag ("); install_element_ve(&show_dsp_trace_f_cmd); install_element_ve(&dsp_trace_f_cmd); install_element_ve(&no_dsp_trace_f_cmd); return 0; }