aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bts-sysmo/misc/sysmobts_par.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <holger@moiji-mobile.com>2016-07-01 20:56:27 +0200
committerHolger Freyther <holger@freyther.de>2017-04-30 21:45:08 +0000
commit40dca8f991465aaa8e3c95c23d00f155106f584d (patch)
tree71caca18dd3a73decd177a274431f24fa985e37b /src/osmo-bts-sysmo/misc/sysmobts_par.c
parentd62a58dbfb4424a104960bca7ffff01a173c101f (diff)
sysmobts: Store a simple network config in the EEPROM as well
Make it possible to store: * Static vs. DHCP mode * IPv4 address * Netmask * GW IPv4 address * DNS IPv4 address Add a simple CRC8 and pick 0xFF as initial value so an all zero EEPROM will not generate a 0 CRC. The code tries to differentiate exit code between unreadable EEPROM and CRC error. This is a reference to see if we want to have store it in the EEPROM or not. Change-Id: Id8a37fe952ef2a8ef36778729f506f900accf8d1
Diffstat (limited to 'src/osmo-bts-sysmo/misc/sysmobts_par.c')
-rw-r--r--src/osmo-bts-sysmo/misc/sysmobts_par.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/osmo-bts-sysmo/misc/sysmobts_par.c b/src/osmo-bts-sysmo/misc/sysmobts_par.c
index e3a3c56b..98fe02b5 100644
--- a/src/osmo-bts-sysmo/misc/sysmobts_par.c
+++ b/src/osmo-bts-sysmo/misc/sysmobts_par.c
@@ -30,6 +30,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <osmocom/core/crc8gen.h>
#include <osmocom/core/utils.h>
#include "sysmobts_eeprom.h"
@@ -38,6 +39,13 @@
#define EEPROM_PATH "/sys/devices/platform/i2c_davinci.1/i2c-1/1-0050/eeprom"
+static const struct osmo_crc8gen_code crc8_ccit = {
+ .bits = 8,
+ .poly = 0x83,
+ .init = 0xFF,
+ .remainder = 0x00,
+};
+
const struct value_string sysmobts_par_names[_NUM_SYSMOBTS_PAR+1] = {
{ SYSMOBTS_PAR_MAC, "ethaddr" },
{ SYSMOBTS_PAR_CLK_FACTORY, "clk-factory" },
@@ -291,6 +299,50 @@ int sysmobts_par_set_buf(enum sysmobts_par par, const uint8_t *buf,
return len;
}
+int sysmobts_par_get_net(struct sysmobts_net_cfg *cfg)
+{
+ struct sysmobts_eeprom *ee = get_eeprom(0);
+ ubit_t bits[sizeof(*cfg) * 8];
+ uint8_t crc;
+ int rc;
+
+ if (!ee)
+ return -EIO;
+
+ /* convert the net_cfg to unpacked bits */
+ rc = osmo_pbit2ubit(bits, (uint8_t *) &ee->net_cfg, sizeof(bits));
+ if (rc != sizeof(bits))
+ return -EFAULT;
+ /* compute the crc and compare */
+ crc = osmo_crc8gen_compute_bits(&crc8_ccit, bits, sizeof(bits));
+ if (crc != ee->crc) {
+ fprintf(stderr, "Computed CRC(%d) wanted CRC(%d)\n", crc, ee->crc);
+ return -EBADMSG;
+ }
+ /* return the actual data */
+ *cfg = ee->net_cfg;
+ return 0;
+}
+
+int sysmobts_par_set_net(struct sysmobts_net_cfg *cfg)
+{
+ struct sysmobts_eeprom *ee = get_eeprom(1);
+ ubit_t bits[sizeof(*cfg) * 8];
+ int rc;
+
+ if (!ee)
+ return -EIO;
+
+ /* convert the net_cfg to unpacked bits */
+ rc = osmo_pbit2ubit(bits, (uint8_t *) cfg, sizeof(bits));
+ if (rc != sizeof(bits))
+ return -EFAULT;
+ /* compute and store the result */
+ ee->net_cfg = *cfg;
+ ee->crc = osmo_crc8gen_compute_bits(&crc8_ccit, bits, sizeof(bits));
+ return set_eeprom(ee);
+}
+
osmo_static_assert(offsetof(struct sysmobts_eeprom, trx_nr) == 36, offset_36);
osmo_static_assert(offsetof(struct sysmobts_eeprom, boot_state) == 37, offset_37);
osmo_static_assert(offsetof(struct sysmobts_eeprom, _pad1) == 85, offset_85);