summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2020-03-06 08:41:58 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2020-03-06 08:41:58 +0000
commit3cb00cbe60c1afc3e69c0eb46488430d19037c9c (patch)
tree24bc255f3805302ffd96fc807917a936cab456e0 /sys/dev/ic
parent0f7d1eb38e8a6ee4cadc7a96203ed6d3db88f2e4 (diff)
Process the NVRAM in bwfm(4) itself. So far we have relied on some
external tool to pre-process the NVRAM, even though it's simple to do ourselves. This allows easier firmware distribution. ok kurt@
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/bwfm.c51
-rw-r--r--sys/dev/ic/bwfmvar.h3
2 files changed, 52 insertions, 2 deletions
diff --git a/sys/dev/ic/bwfm.c b/sys/dev/ic/bwfm.c
index 377305b9b1a..a8b0ca0becd 100644
--- a/sys/dev/ic/bwfm.c
+++ b/sys/dev/ic/bwfm.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bwfm.c,v 1.69 2020/02/25 14:24:58 patrick Exp $ */
+/* $OpenBSD: bwfm.c,v 1.70 2020/03/06 08:41:57 patrick Exp $ */
/*
* Copyright (c) 2010-2016 Broadcom Corporation
* Copyright (c) 2016,2017 Patrick Wildt <patrick@blueri.se>
@@ -2700,3 +2700,52 @@ bwfm_newstate(struct ieee80211com *ic, enum ieee80211_state nstate, int arg)
splx(s);
return 0;
}
+
+int
+bwfm_nvram_convert(u_char *buf, size_t len, size_t *newlenp)
+{
+ u_char *src, *dst, *end = buf + len;
+ size_t count = 0, pad;
+ uint32_t token;
+ int skip = 0;
+
+ for (src = buf, dst = buf; src != end; ++src) {
+ if (*src == '\n') {
+ if (count > 0)
+ *dst++ = '\0';
+ count = 0;
+ skip = 0;
+ continue;
+ }
+ if (skip)
+ continue;
+ if (*src == '#' && count == 0) {
+ skip = 1;
+ continue;
+ }
+ if (*src == '\r')
+ continue;
+ *dst++ = *src;
+ ++count;
+ }
+
+ count = dst - buf;
+ pad = roundup(count + 1, 4) - count;
+
+ if (count + pad + sizeof(token) > len)
+ return 1;
+
+ memset(dst, 0, pad);
+ count += pad;
+ dst += pad;
+
+ token = (count / 4) & 0xffff;
+ token |= ~token << 16;
+ token = htole32(token);
+
+ memcpy(dst, &token, sizeof(token));
+ count += sizeof(token);
+
+ *newlenp = count;
+ return 0;
+}
diff --git a/sys/dev/ic/bwfmvar.h b/sys/dev/ic/bwfmvar.h
index 1d235fa857c..5080c17220d 100644
--- a/sys/dev/ic/bwfmvar.h
+++ b/sys/dev/ic/bwfmvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bwfmvar.h,v 1.17 2020/02/25 14:24:58 patrick Exp $ */
+/* $OpenBSD: bwfmvar.h,v 1.18 2020/03/06 08:41:57 patrick Exp $ */
/*
* Copyright (c) 2010-2016 Broadcom Corporation
* Copyright (c) 2016,2017 Patrick Wildt <patrick@blueri.se>
@@ -183,3 +183,4 @@ struct bwfm_core *bwfm_chip_get_pmu(struct bwfm_softc *);
void bwfm_rx(struct bwfm_softc *, struct mbuf *, struct mbuf_list *);
void bwfm_do_async(struct bwfm_softc *, void (*)(struct bwfm_softc *, void *),
void *, int);
+int bwfm_nvram_convert(u_char *, size_t, size_t *);