2015-11-12 13:32:07 +00:00
|
|
|
/* lc15bts - access to hardware related parameters */
|
|
|
|
|
|
|
|
/* Copyright (C) 2015 by Yves Godin <support@nuranwireless.com>
|
|
|
|
*
|
|
|
|
* Based on sysmoBTS:
|
|
|
|
* sysmobts_par.c
|
|
|
|
* (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 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 <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <osmocom/core/utils.h>
|
2017-06-15 13:34:41 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2015-11-12 13:32:07 +00:00
|
|
|
|
|
|
|
#include "lc15bts_par.h"
|
|
|
|
|
|
|
|
const struct value_string lc15bts_par_names[_NUM_LC15BTS_PAR+1] = {
|
|
|
|
{ LC15BTS_PAR_TEMP_SUPPLY_MAX, "temp-supply-max" },
|
|
|
|
{ LC15BTS_PAR_TEMP_SOC_MAX, "temp-soc-max" },
|
|
|
|
{ LC15BTS_PAR_TEMP_FPGA_MAX, "temp-fpga-max" },
|
2016-06-09 20:19:12 +00:00
|
|
|
{ LC15BTS_PAR_TEMP_LOGRF_MAX, "temp-logrf-max" },
|
|
|
|
{ LC15BTS_PAR_TEMP_OCXO_MAX, "temp-ocxo-max" },
|
|
|
|
{ LC15BTS_PAR_TEMP_TX0_MAX, "temp-tx0-max" },
|
2015-11-12 13:32:07 +00:00
|
|
|
{ LC15BTS_PAR_TEMP_TX1_MAX, "temp-tx1-max" },
|
2016-06-09 20:19:12 +00:00
|
|
|
{ LC15BTS_PAR_TEMP_PA0_MAX, "temp-pa0-max" },
|
2015-11-12 13:32:07 +00:00
|
|
|
{ LC15BTS_PAR_TEMP_PA1_MAX, "temp-pa1-max" },
|
|
|
|
{ LC15BTS_PAR_SERNR, "serial-nr" },
|
|
|
|
{ LC15BTS_PAR_HOURS, "hours-running" },
|
|
|
|
{ LC15BTS_PAR_BOOTS, "boot-count" },
|
|
|
|
{ LC15BTS_PAR_KEY, "key" },
|
|
|
|
{ 0, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
int lc15bts_par_is_int(enum lc15bts_par par)
|
|
|
|
{
|
|
|
|
switch (par) {
|
|
|
|
case LC15BTS_PAR_TEMP_SUPPLY_MAX:
|
|
|
|
case LC15BTS_PAR_TEMP_SOC_MAX:
|
|
|
|
case LC15BTS_PAR_TEMP_FPGA_MAX:
|
2016-06-09 20:19:12 +00:00
|
|
|
case LC15BTS_PAR_TEMP_LOGRF_MAX:
|
|
|
|
case LC15BTS_PAR_TEMP_OCXO_MAX:
|
|
|
|
case LC15BTS_PAR_TEMP_TX0_MAX:
|
2015-11-12 13:32:07 +00:00
|
|
|
case LC15BTS_PAR_TEMP_TX1_MAX:
|
2016-06-09 20:19:12 +00:00
|
|
|
case LC15BTS_PAR_TEMP_PA0_MAX:
|
2015-11-12 13:32:07 +00:00
|
|
|
case LC15BTS_PAR_TEMP_PA1_MAX:
|
|
|
|
case LC15BTS_PAR_SERNR:
|
|
|
|
case LC15BTS_PAR_HOURS:
|
|
|
|
case LC15BTS_PAR_BOOTS:
|
|
|
|
return 1;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:34:41 +00:00
|
|
|
FILE *lc15bts_par_get_path(void *ctx, enum lc15bts_par par, const char* mode)
|
2015-11-12 13:32:07 +00:00
|
|
|
{
|
2017-06-15 13:34:41 +00:00
|
|
|
char *fpath;
|
2015-11-12 13:32:07 +00:00
|
|
|
FILE *fp;
|
|
|
|
|
|
|
|
if (par >= _NUM_LC15BTS_PAR)
|
2017-06-15 13:34:41 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fpath = talloc_asprintf(ctx, "%s/%s", USER_ROM_PATH, get_value_string(lc15bts_par_names, par));
|
|
|
|
if (!fpath)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fp = fopen(fpath, mode);
|
|
|
|
if (!fp)
|
|
|
|
fprintf(stderr, "Failed to open %s due to '%s' error\n", fpath, strerror(errno));
|
2015-11-12 13:32:07 +00:00
|
|
|
|
2017-06-15 13:34:41 +00:00
|
|
|
talloc_free(fpath);
|
|
|
|
|
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int lc15bts_par_get_int(void *ctx, enum lc15bts_par par, int *ret)
|
|
|
|
{
|
|
|
|
FILE *fp = lc15bts_par_get_path(ctx, par, "r");
|
|
|
|
int rc;
|
2015-11-12 13:32:07 +00:00
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = fscanf(fp, "%d", ret);
|
|
|
|
if (rc != 1) {
|
|
|
|
fclose(fp);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:34:41 +00:00
|
|
|
int lc15bts_par_set_int(void *ctx, enum lc15bts_par par, int val)
|
2015-11-12 13:32:07 +00:00
|
|
|
{
|
2017-06-15 13:34:41 +00:00
|
|
|
FILE *fp = lc15bts_par_get_path(ctx, par, "w");
|
2015-11-12 13:32:07 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = fprintf(fp, "%d", val);
|
|
|
|
if (rc < 0) {
|
|
|
|
fclose(fp);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:34:41 +00:00
|
|
|
int lc15bts_par_get_buf(void *ctx, enum lc15bts_par par, uint8_t *buf, unsigned int size)
|
2015-11-12 13:32:07 +00:00
|
|
|
{
|
2017-06-15 13:34:41 +00:00
|
|
|
FILE *fp = lc15bts_par_get_path(ctx, par, "rb");
|
2015-11-12 13:32:07 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = fread(buf, 1, size, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:34:41 +00:00
|
|
|
int lc15bts_par_set_buf(void *ctx, enum lc15bts_par par, const uint8_t *buf, unsigned int size)
|
2015-11-12 13:32:07 +00:00
|
|
|
{
|
2017-06-15 13:34:41 +00:00
|
|
|
FILE *fp = lc15bts_par_get_path(ctx, par, "wb");
|
2015-11-12 13:32:07 +00:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (fp == NULL) {
|
|
|
|
return -errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = fwrite(buf, 1, size, fp);
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|