mirror of https://github.com/OpenIPC/firmware.git
Sync
parent
06fae2efa9
commit
96629c3fe8
|
@ -63,7 +63,7 @@ jobs:
|
|||
ARCHIVE_FW="${GITHUB_WORKSPACE}/output/images/openipc.hi3516ev200-br.tgz"
|
||||
echo "ARCHIVE_FW=$ARCHIVE_FW" >> $GITHUB_ENV
|
||||
cd $GITHUB_WORKSPACE
|
||||
make BOARD=unknown_unknown_hi3516ev200_openipc all
|
||||
make PLATFORM=hisilicon BOARD=unknown_unknown_hi3516ev200_openipc all
|
||||
tar -C ${GITHUB_WORKSPACE}/output/images -cvzf $ARCHIVE_FW rootfs.squashfs uImage
|
||||
|
||||
- name: Build Hi3516Ev200 SDK
|
||||
|
|
|
@ -63,7 +63,7 @@ jobs:
|
|||
ARCHIVE_FW="${GITHUB_WORKSPACE}/output/images/openipc.hi3516ev300-br.tgz"
|
||||
echo "ARCHIVE_FW=$ARCHIVE_FW" >> $GITHUB_ENV
|
||||
cd $GITHUB_WORKSPACE
|
||||
make BOARD=unknown_unknown_hi3516ev300_openipc all
|
||||
make PLATFORM=hisilicon BOARD=unknown_unknown_hi3516ev300_openipc all
|
||||
tar -C ${GITHUB_WORKSPACE}/output/images -cvzf $ARCHIVE_FW rootfs.squashfs uImage
|
||||
|
||||
- name: Build Hi3516Ev300 SDK
|
||||
|
|
|
@ -63,7 +63,7 @@ jobs:
|
|||
ARCHIVE_FW="${GITHUB_WORKSPACE}/output/images/openipc.hi3518ev300-br.tgz"
|
||||
echo "ARCHIVE_FW=$ARCHIVE_FW" >> $GITHUB_ENV
|
||||
cd $GITHUB_WORKSPACE
|
||||
make BOARD=unknown_unknown_hi3518ev300_openipc all
|
||||
make PLATFORM=hisilicon BOARD=unknown_unknown_hi3518ev300_openipc all
|
||||
tar -C ${GITHUB_WORKSPACE}/output/images -cvzf $ARCHIVE_FW rootfs.squashfs uImage
|
||||
|
||||
- name: Build Hi3518Ev300 SDK
|
||||
|
|
|
@ -3,7 +3,7 @@ name: OpenIPC for SSC335
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- ssc335
|
||||
- master
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
|
@ -63,7 +63,7 @@ jobs:
|
|||
ARCHIVE_FW="${GITHUB_WORKSPACE}/output/images/openipc.ssc335-br.tgz"
|
||||
echo "ARCHIVE_FW=$ARCHIVE_FW" >> $GITHUB_ENV
|
||||
cd $GITHUB_WORKSPACE
|
||||
make BOARD=unknown_unknown_ssc335_openipc all
|
||||
make PLATFORM=sigmastar BOARD=unknown_unknown_ssc335_openipc all
|
||||
tar -C ${GITHUB_WORKSPACE}/output/images -cvzf $ARCHIVE_FW rootfs.squashfs uImage
|
||||
|
||||
- name: Build SSC335 SDK
|
||||
|
|
|
@ -3,7 +3,7 @@ name: OpenIPC for XM530
|
|||
on:
|
||||
push:
|
||||
branches:
|
||||
- xm530
|
||||
- master
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
|
@ -63,7 +63,7 @@ jobs:
|
|||
ARCHIVE_FW="${GITHUB_WORKSPACE}/output/images/openipc.xm530-br.tgz"
|
||||
echo "ARCHIVE_FW=$ARCHIVE_FW" >> $GITHUB_ENV
|
||||
cd $GITHUB_WORKSPACE
|
||||
make BOARD=unknown_unknown_xm530_openipc all
|
||||
make PLATFORM=xiongmai BOARD=unknown_unknown_xm530_openipc all
|
||||
mv ${GITHUB_WORKSPACE}/output/images/uImage ${GITHUB_WORKSPACE}/output/images/uImage_xm530
|
||||
mv ${GITHUB_WORKSPACE}/output/images/rootfs.squashfs ${GITHUB_WORKSPACE}/output/images/rootfs.squashfs_xm530
|
||||
tar -C ${GITHUB_WORKSPACE}/output/images -cvzf $ARCHIVE_FW rootfs.squashfs_xm530 uImage_xm530
|
||||
|
|
4
Makefile
4
Makefile
|
@ -2,9 +2,7 @@
|
|||
ROOT_DIR := $(CURDIR)
|
||||
BR_VER := 2020.02
|
||||
BR_DIR := $(ROOT_DIR)/buildroot-$(BR_VER)
|
||||
#BR_EXT_DIR := $(ROOT_DIR)/br-ext-chip-hisilicon
|
||||
BR_EXT_DIR := $(ROOT_DIR)/br-ext-chip-sigmastar
|
||||
#BR_EXT_DIR := $(ROOT_DIR)/br-ext-chip-xiongmai
|
||||
BR_EXT_DIR := $(ROOT_DIR)/br-ext-chip-$(PLATFORM)
|
||||
SCRIPTS_DIR := $(ROOT_DIR)/scripts
|
||||
BOARDS := $(shell ls -1 $(BR_EXT_DIR)/configs)
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
IPCTOOL_VERSION = 7e523a84b054a122245039b7b32e67bf0995ba8f
|
||||
IPCTOOL_VERSION = 84b48c5035795de5233b354e843d30f58a1e8bc4
|
||||
IPCTOOL_SITE = $(call github,openipc,ipctool,$(IPCTOOL_VERSION))
|
||||
IPCTOOL_LICENSE = MIT
|
||||
IPCTOOL_LICENSE_FILES = LICENSE
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/linux/linux-ext-sigmastar_patcher.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/sigmastar_patcher/sigmastar_patcher.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/sigmastar-osdrv-xm530/sigmastar-osdrv-ssc335.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/sigmastar-osdrv-ssc335/sigmastar-osdrv-ssc335.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/fwprintenv-ng/fwprintenv-ng.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/ipctool/ipctool.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/libevent-mini/libevent-mini.mk
|
||||
include $(BR2_EXTERNAL_SIGMASTAR_PATH)/package/majestic/majestic.mk
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../general/package/fwprintenv-ng
|
|
@ -0,0 +1 @@
|
|||
../../general/package/ipctool
|
|
@ -0,0 +1 @@
|
|||
../../general/package/libevent-mini
|
|
@ -0,0 +1 @@
|
|||
../../general/package/vtund-lite
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
################################################################################
|
||||
|
||||
IPCTOOL_VERSION = 56fa840899fc024a4e3c5126a5792f4498dca7d2
|
||||
IPCTOOL_VERSION = 84b48c5035795de5233b354e843d30f58a1e8bc4
|
||||
IPCTOOL_SITE = $(call github,openipc,ipctool,$(IPCTOOL_VERSION))
|
||||
IPCTOOL_LICENSE = MIT
|
||||
IPCTOOL_LICENSE_FILES = LICENSE
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
../../general/package/vtund-lite
|
|
@ -0,0 +1,353 @@
|
|||
diff -urn -- a/miscutils/rng_fips.h b/miscutils/rng_fips.h
|
||||
--- a/miscutils/rng_fips.h 1970-01-01 00:00:00.000000000 +0000
|
||||
+++ b/miscutils/rng_fips.h 2008-08-17 13:28:27.000000000 +0000
|
||||
@@ -0,0 +1,152 @@
|
||||
+/* vi: set sw=4 ts=4: */
|
||||
+/* rng_fips.h
|
||||
+ *
|
||||
+ * Ported to busybox by Malek Degachi
|
||||
+ *
|
||||
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
+ */
|
||||
+
|
||||
+#ifndef _RNG_FIPS_H
|
||||
+#define _RNG_FIPS_H
|
||||
+
|
||||
+#include "libbb.h"
|
||||
+
|
||||
+/**********************************************
|
||||
+ * FIPS part
|
||||
+ *********************************************/
|
||||
+
|
||||
+/* Size of a FIPS test buffer, do not change this */
|
||||
+#define FIPS_RNG_BUFFER_SIZE 2500
|
||||
+
|
||||
+/* Context for running FIPS tests */
|
||||
+typedef struct {
|
||||
+ int poker[16];
|
||||
+ int runs[12];
|
||||
+ int ones;
|
||||
+ int rlength;
|
||||
+ int current_bit;
|
||||
+ int last_bit;
|
||||
+ int longrun;
|
||||
+ unsigned int last32;
|
||||
+} fips_ctx_t;
|
||||
+
|
||||
+/*
|
||||
+ * Return values for fips_run_rng_test. These values are OR'ed together
|
||||
+ * for all tests that failed.
|
||||
+ */
|
||||
+#define FIPS_RNG_MONOBIT 0x0001 /* FIPS 140-2 2001-10-10 monobit */
|
||||
+#define FIPS_RNG_POKER 0x0002 /* FIPS 140-2 2001-10-10 poker */
|
||||
+#define FIPS_RNG_RUNS 0x0004 /* FIPS 140-2 2001-10-10 runs */
|
||||
+#define FIPS_RNG_LONGRUN 0x0008 /* FIPS 140-2 2001-10-10 long run */
|
||||
+#define FIPS_RNG_CONTINUOUS_RUN 0x0010 /* FIPS 140-2 continuous run */
|
||||
+
|
||||
+/*
|
||||
+ * fips_test_store - store 8 bits of entropy in FIPS
|
||||
+ * internal test data pool
|
||||
+ */
|
||||
+static void fips_test_store(fips_ctx_t *ctx, unsigned int rng_data)
|
||||
+{
|
||||
+ int j;
|
||||
+
|
||||
+ ctx->poker[rng_data >> 4]++;
|
||||
+ ctx->poker[rng_data & 15]++;
|
||||
+
|
||||
+ /* Note in the loop below rlength is always one less than the actual
|
||||
+ run length. This makes things easier. */
|
||||
+ for (j = 7; j >= 0; j--) {
|
||||
+ ctx->ones += ctx->current_bit = ((rng_data >> j) & 1);
|
||||
+ if (ctx->current_bit != ctx->last_bit) {
|
||||
+ /* If runlength is 1-6 count it in correct bucket. 0's go in
|
||||
+ runs[0-5] 1's go in runs[6-11] hence the 6*current_bit below */
|
||||
+ if (ctx->rlength < 5) {
|
||||
+ ctx->runs[ctx->rlength +
|
||||
+ (6 * ctx->current_bit)]++;
|
||||
+ } else {
|
||||
+ ctx->runs[5 + (6 * ctx->current_bit)]++;
|
||||
+ }
|
||||
+
|
||||
+ /* Check if we just failed longrun test */
|
||||
+ if (ctx->rlength >= 25)
|
||||
+ ctx->longrun = 1;
|
||||
+ ctx->rlength = 0;
|
||||
+ /* flip the current run type */
|
||||
+ ctx->last_bit = ctx->current_bit;
|
||||
+ } else {
|
||||
+ ctx->rlength++;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static int fips_run_rng_test(fips_ctx_t *ctx, const void *buf)
|
||||
+{
|
||||
+ int i, j;
|
||||
+ int rng_test = 0;
|
||||
+ unsigned char *rngdatabuf;
|
||||
+
|
||||
+ if (!ctx) return -1;
|
||||
+ if (!buf) return -1;
|
||||
+ rngdatabuf = (unsigned char *)buf;
|
||||
+
|
||||
+ for (i=0; i<FIPS_RNG_BUFFER_SIZE; i += 4) {
|
||||
+ int new32 = rngdatabuf[i] |
|
||||
+ ( rngdatabuf[i+1] << 8 ) |
|
||||
+ ( rngdatabuf[i+2] << 16 ) |
|
||||
+ ( rngdatabuf[i+3] << 24 );
|
||||
+ if (new32 == ctx->last32) rng_test |= FIPS_RNG_CONTINUOUS_RUN;
|
||||
+ ctx->last32 = new32;
|
||||
+ fips_test_store(ctx, rngdatabuf[i]);
|
||||
+ fips_test_store(ctx, rngdatabuf[i+1]);
|
||||
+ fips_test_store(ctx, rngdatabuf[i+2]);
|
||||
+ fips_test_store(ctx, rngdatabuf[i+3]);
|
||||
+ }
|
||||
+
|
||||
+ /* add in the last (possibly incomplete) run */
|
||||
+ if (ctx->rlength < 5)
|
||||
+ ctx->runs[ctx->rlength + (6 * ctx->current_bit)]++;
|
||||
+ else {
|
||||
+ ctx->runs[5 + (6 * ctx->current_bit)]++;
|
||||
+ if (ctx->rlength >= 25)
|
||||
+ rng_test |= FIPS_RNG_LONGRUN;
|
||||
+ }
|
||||
+
|
||||
+ if (ctx->longrun) {
|
||||
+ rng_test |= FIPS_RNG_LONGRUN;
|
||||
+ ctx->longrun = 0;
|
||||
+ }
|
||||
+
|
||||
+ /* Ones test */
|
||||
+ if ((ctx->ones >= 10275) || (ctx->ones <= 9725))
|
||||
+ rng_test |= FIPS_RNG_MONOBIT;
|
||||
+ /* Poker calcs */
|
||||
+ for (i = 0, j = 0; i < 16; i++)
|
||||
+ j += ctx->poker[i] * ctx->poker[i];
|
||||
+ /* 16/5000*1563176-5000 = 2.1632 */
|
||||
+ /* 16/5000*1576928-5000 = 46.1696 */
|
||||
+ if ((j > 1576928) || (j < 1563176))
|
||||
+ rng_test |= FIPS_RNG_POKER;
|
||||
+
|
||||
+ if ((ctx->runs[0] < 2315) || (ctx->runs[0] > 2685) ||
|
||||
+ (ctx->runs[1] < 1114) || (ctx->runs[1] > 1386) ||
|
||||
+ (ctx->runs[2] < 527) || (ctx->runs[2] > 723) ||
|
||||
+ (ctx->runs[3] < 240) || (ctx->runs[3] > 384) ||
|
||||
+ (ctx->runs[4] < 103) || (ctx->runs[4] > 209) ||
|
||||
+ (ctx->runs[5] < 103) || (ctx->runs[5] > 209) ||
|
||||
+ (ctx->runs[6] < 2315) || (ctx->runs[6] > 2685) ||
|
||||
+ (ctx->runs[7] < 1114) || (ctx->runs[7] > 1386) ||
|
||||
+ (ctx->runs[8] < 527) || (ctx->runs[8] > 723) ||
|
||||
+ (ctx->runs[9] < 240) || (ctx->runs[9] > 384) ||
|
||||
+ (ctx->runs[10] < 103) || (ctx->runs[10] > 209) ||
|
||||
+ (ctx->runs[11] < 103) || (ctx->runs[11] > 209)) {
|
||||
+ rng_test |= FIPS_RNG_RUNS;
|
||||
+ }
|
||||
+
|
||||
+ /* finally, clear out FIPS variables for start of next run */
|
||||
+ memset(ctx->poker, 0, sizeof (ctx->poker));
|
||||
+ memset(ctx->runs, 0, sizeof (ctx->runs));
|
||||
+ ctx->ones = 0;
|
||||
+ ctx->rlength = -1;
|
||||
+ ctx->current_bit = 0;
|
||||
+
|
||||
+ return rng_test;
|
||||
+}
|
||||
+#endif /* _RNG_FIPS_H */
|
||||
diff -urn -- a/miscutils/rngd.c b/miscutils/rngd.c
|
||||
--- a/miscutils/rngd.c 2021-04-14 10:06:59.131381906 +0300
|
||||
+++ b/miscutils/rngd.c 2021-04-14 10:04:59.785401231 +0300
|
||||
@@ -0,0 +1,193 @@
|
||||
+/* vi: set sw=4 ts=4: */
|
||||
+/*
|
||||
+ * rngd implementation for busybox
|
||||
+ *
|
||||
+ * Ported to busybox by Malek Degachi
|
||||
+ *
|
||||
+ * Licensed under GPLv2 or later, see file License in this tarball for details.
|
||||
+ *
|
||||
+ */
|
||||
+
|
||||
+//config:config RNGD
|
||||
+//config: bool "rngd"
|
||||
+//config: default n
|
||||
+//config: help
|
||||
+//config: Hardware random number generation daemon.
|
||||
+//config:config FEATURE_RNGD_LONG_OPTIONS
|
||||
+//config: bool "Enable long options"
|
||||
+//config: default n
|
||||
+//config: depends on RNGD && GETOPT_LONG
|
||||
+//config: help
|
||||
+//config: Support long options for the rngd applet.
|
||||
+
|
||||
+//applet:IF_RNGD(APPLET(rngd, BB_DIR_USR_SBIN, BB_SUID_DROP))
|
||||
+
|
||||
+//kbuild:lib-$(CONFIG_RNGD) += rngd.o
|
||||
+
|
||||
+//usage:#define rngd_trivial_usage
|
||||
+//usage: "[-bf] [-o random file] [-r rng file] [-s step] [-t nnn] [-W n]"
|
||||
+//usage:#define rngd_full_usage "\n\n"
|
||||
+//usage: "Check and feed random data from hardware device to kernel entropy pool.\n"
|
||||
+//usage: "\nOptions:"
|
||||
+//usage: "\n -b,--background Become a daemon (default)"
|
||||
+//usage: "\n -f,--foreground Do not fork and become a daemon"
|
||||
+//usage: "\n -o,--rng-device=file Kernel device used for random number output"
|
||||
+//usage: "\n (default: /dev/random)"
|
||||
+//usage: "\n -r,--random-step=nnn Kernel device used for random number input"
|
||||
+//usage: "\n (default: /dev/hw_random)"
|
||||
+//usage: "\n -s,--random-step=nnn Number of bytes written to random-device at a time"
|
||||
+//usage: "\n (default: 64)"
|
||||
+//usage: "\n -t,--timeout=nnn Interval written to random-device when the entropy"
|
||||
+//usage: "\n pool is full, in seconds (default: 60)"
|
||||
+//usage: "\n -W,--fill-watermark=n Do not stop feeding entropy to random-device until"
|
||||
+//usage: "\n at least n bits of entropy are available in the"
|
||||
+//usage: "\n pool (default: 2048), 0 <= n <= 4096"
|
||||
+
|
||||
+
|
||||
+#include "libbb.h"
|
||||
+#include "rng_fips.h"
|
||||
+#include <syslog.h>
|
||||
+
|
||||
+#ifndef __u32
|
||||
+typedef unsigned int __u32;
|
||||
+#endif
|
||||
+#include <linux/random.h> /* struct rand_pool_info, RNDADDENTROPY and RNDGETENTCNT */
|
||||
+
|
||||
+enum {
|
||||
+ RNG_b = (1 << 0),
|
||||
+ RNG_f = (1 << 1),
|
||||
+ RNG_o = (1 << 2),
|
||||
+ RNG_r = (1 << 3),
|
||||
+ RNG_s = (1 << 4),
|
||||
+ RNG_t = (1 << 5),
|
||||
+ RNG_W = (1 << 6),
|
||||
+};
|
||||
+
|
||||
+static void random_add_entropy(int random_fd, void *buf, size_t size)
|
||||
+{
|
||||
+ struct rand_pool_info *entropy;
|
||||
+
|
||||
+ entropy = xmalloc(sizeof(struct rand_pool_info) + size);
|
||||
+
|
||||
+ entropy->entropy_count = size * 8;
|
||||
+ entropy->buf_size = size;
|
||||
+ memcpy(entropy->buf, buf, size);
|
||||
+
|
||||
+ ioctl_or_perror_and_die(random_fd, RNDADDENTROPY, entropy, "RNDADDENTROPY failed: %s\n",
|
||||
+ strerror(errno));
|
||||
+}
|
||||
+
|
||||
+static void random_sleep(int random_fd, double timeout, unsigned fill_watermark)
|
||||
+{
|
||||
+ int ent_count;
|
||||
+ struct pollfd pfd[1];
|
||||
+
|
||||
+ pfd[0].fd = random_fd;
|
||||
+ pfd[0].events = POLLOUT;
|
||||
+
|
||||
+ ioctl_or_perror_and_die(random_fd, RNDGETENTCNT, &ent_count, "RNDGETENTCNT failed: %s\n",
|
||||
+ strerror(errno));
|
||||
+ if (ent_count < fill_watermark) return;
|
||||
+
|
||||
+ safe_poll(pfd, 1, 1000.0 * timeout);
|
||||
+}
|
||||
+
|
||||
+/* Initialize entropy source */
|
||||
+static int discard_initial_data(int rng_fd)
|
||||
+{
|
||||
+ /* Trash 32 bits of what is probably stale (non-random)
|
||||
+ * initial state from the RNG. For Intel's, 8 bits would
|
||||
+ * be enough, but since AMD's generates 32 bits at a time...
|
||||
+ *
|
||||
+ * The kernel drivers should be doing this at device powerup,
|
||||
+ * but at least up to 2.4.24, it doesn't. */
|
||||
+ unsigned char tempbuf[4];
|
||||
+
|
||||
+ xread(rng_fd, tempbuf, sizeof tempbuf);
|
||||
+
|
||||
+ /* Return 32 bits of bootstrap data */
|
||||
+ xread(rng_fd, tempbuf, sizeof tempbuf);
|
||||
+
|
||||
+ return tempbuf[0] | (tempbuf[1] << 8) |
|
||||
+ (tempbuf[2] << 16) | (tempbuf[3] << 24);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+#if ENABLE_FEATURE_RNGD_LONG_OPTIONS
|
||||
+static const char rngd_longopts[] ALIGN1 =
|
||||
+ "background\0" No_argument "b"
|
||||
+ "foreground\0" No_argument "f"
|
||||
+ "random-device\0" Required_argument "o"
|
||||
+ "rng-device\0" Required_argument "r"
|
||||
+ "random-step\0" Required_argument "s"
|
||||
+ "timeout\0" Required_argument "t"
|
||||
+ "fill-watermark\0" Required_argument "W"
|
||||
+ ;
|
||||
+#endif
|
||||
+
|
||||
+int rngd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||
+int rngd_main(int argc UNUSED_PARAM, char **argv)
|
||||
+{
|
||||
+ const char *random_name = "/dev/random";
|
||||
+ const char *rng_name = "/dev/hw_random";
|
||||
+ int random_step = 64;
|
||||
+ unsigned fill_watermark;
|
||||
+ double poll_timeout = 60;
|
||||
+
|
||||
+ const char *watermark = "2048";
|
||||
+ static int rng_fd;
|
||||
+ static int random_fd;
|
||||
+
|
||||
+ unsigned char buf[FIPS_RNG_BUFFER_SIZE];
|
||||
+ unsigned char *p;
|
||||
+ int fips;
|
||||
+ fips_ctx_t *fipsctx;
|
||||
+
|
||||
+#if ENABLE_FEATURE_RNGD_LONG_OPTIONS
|
||||
+ applet_long_options = rngd_longopts;
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
+ getopt32(argv, "bfo:r:s:t:W:", &random_name, &rng_name, &random_step, &poll_timeout, &watermark);
|
||||
+ argv += optind;
|
||||
+
|
||||
+ fill_watermark = xatou_range(watermark, 0, 4096);
|
||||
+
|
||||
+ /* Init entropy source, and open hardware RNG device */
|
||||
+ rng_fd = xopen(rng_name, O_RDONLY);
|
||||
+
|
||||
+ /* Bootstrap FIPS tests */
|
||||
+ fipsctx = (fips_ctx_t *) xzalloc(sizeof(fips_ctx_t));
|
||||
+ fipsctx->rlength = -1;
|
||||
+ fipsctx->last32 = discard_initial_data(rng_fd);
|
||||
+
|
||||
+ /* Init entropy sink and open random device */
|
||||
+ random_fd = xopen(random_name, O_RDWR);
|
||||
+
|
||||
+ if (!(option_mask32 & RNG_f)) { /* no -f */
|
||||
+ bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv);
|
||||
+ openlog(applet_name, LOG_PID, LOG_DAEMON);
|
||||
+ logmode = LOGMODE_SYSLOG;
|
||||
+ }
|
||||
+
|
||||
+ write_pidfile("/var/run/rngd.pid");
|
||||
+ for (;;) {
|
||||
+ xread(rng_fd, buf, sizeof buf);
|
||||
+
|
||||
+ fips = fips_run_rng_test(fipsctx, buf);
|
||||
+
|
||||
+ if (fips) {
|
||||
+ bb_info_msg("failed fips test");
|
||||
+ sleep(1);
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ for (p = buf; p + random_step <= &buf[sizeof buf]; p += random_step) {
|
||||
+ random_add_entropy(random_fd, p, random_step);
|
||||
+ random_sleep(random_fd, poll_timeout ? : -1.0, fill_watermark);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ return EXIT_SUCCESS;
|
||||
+}
|
||||
+
|
File diff suppressed because it is too large
Load Diff
|
@ -1,10 +1,10 @@
|
|||
################################################################################
|
||||
#
|
||||
# ipctool | updated 2021.04.23
|
||||
# ipctool | updated 2021.04.25
|
||||
#
|
||||
################################################################################
|
||||
|
||||
IPCTOOL_VERSION = 56fa840899fc024a4e3c5126a5792f4498dca7d2
|
||||
IPCTOOL_VERSION = 84b48c5035795de5233b354e843d30f58a1e8bc4
|
||||
IPCTOOL_SITE = $(call github,openipc,ipctool,$(IPCTOOL_VERSION))
|
||||
IPCTOOL_LICENSE = MIT
|
||||
IPCTOOL_LICENSE_FILES = LICENSE
|
|
@ -1,5 +1,5 @@
|
|||
config BR2_PACKAGE_VTUND_LITE
|
||||
bool "vtun"
|
||||
bool "vtund-lite"
|
||||
depends on BR2_USE_MMU # fork()
|
||||
help
|
||||
Tool for easily creating Virtual Tunnels over TCP/IP networks
|
|
@ -0,0 +1,6 @@
|
|||
config BR2_PACKAGE_XMDP
|
||||
bool "xmdp"
|
||||
help
|
||||
Utility for finding devices that support the NETIP protocol
|
||||
|
||||
https://openipc.org
|
|
@ -0,0 +1,10 @@
|
|||
CFLAGS=-Wall -Wpedantic
|
||||
LDFLAGS=-lm
|
||||
|
||||
all: xmdp
|
||||
|
||||
xmdp: xmdp.o netip.o utils.o cjson/cJSON.c
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
-rm xmdp *.o
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef cJSON__h
|
||||
#define cJSON__h
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
||||
#define __WINDOWS__
|
||||
#endif
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
|
||||
/* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options:
|
||||
|
||||
CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols
|
||||
CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default)
|
||||
CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol
|
||||
|
||||
For *nix builds that support visibility attribute, you can define similar behavior by
|
||||
|
||||
setting default visibility to hidden by adding
|
||||
-fvisibility=hidden (for gcc)
|
||||
or
|
||||
-xldscope=hidden (for sun cc)
|
||||
to CFLAGS
|
||||
|
||||
then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does
|
||||
|
||||
*/
|
||||
|
||||
#define CJSON_CDECL __cdecl
|
||||
#define CJSON_STDCALL __stdcall
|
||||
|
||||
/* export symbols by default, this is necessary for copy pasting the C and header file */
|
||||
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_EXPORT_SYMBOLS
|
||||
#endif
|
||||
|
||||
#if defined(CJSON_HIDE_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
||||
#elif defined(CJSON_EXPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
||||
#elif defined(CJSON_IMPORT_SYMBOLS)
|
||||
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
||||
#endif
|
||||
#else /* !__WINDOWS__ */
|
||||
#define CJSON_CDECL
|
||||
#define CJSON_STDCALL
|
||||
|
||||
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
||||
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
||||
#else
|
||||
#define CJSON_PUBLIC(type) type
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* project version */
|
||||
#define CJSON_VERSION_MAJOR 1
|
||||
#define CJSON_VERSION_MINOR 7
|
||||
#define CJSON_VERSION_PATCH 13
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
/* cJSON Types: */
|
||||
#define cJSON_Invalid (0)
|
||||
#define cJSON_False (1 << 0)
|
||||
#define cJSON_True (1 << 1)
|
||||
#define cJSON_NULL (1 << 2)
|
||||
#define cJSON_Number (1 << 3)
|
||||
#define cJSON_String (1 << 4)
|
||||
#define cJSON_Array (1 << 5)
|
||||
#define cJSON_Object (1 << 6)
|
||||
#define cJSON_Raw (1 << 7) /* raw json */
|
||||
|
||||
#define cJSON_IsReference 256
|
||||
#define cJSON_StringIsConst 512
|
||||
|
||||
/* The cJSON structure: */
|
||||
typedef struct cJSON
|
||||
{
|
||||
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
|
||||
struct cJSON *next;
|
||||
struct cJSON *prev;
|
||||
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
|
||||
struct cJSON *child;
|
||||
|
||||
/* The type of the item, as above. */
|
||||
int type;
|
||||
|
||||
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
|
||||
char *valuestring;
|
||||
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
|
||||
int valueint;
|
||||
/* The item's number, if type==cJSON_Number */
|
||||
double valuedouble;
|
||||
|
||||
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
|
||||
char *string;
|
||||
} cJSON;
|
||||
|
||||
typedef struct cJSON_Hooks
|
||||
{
|
||||
/* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */
|
||||
void *(CJSON_CDECL *malloc_fn)(size_t sz);
|
||||
void (CJSON_CDECL *free_fn)(void *ptr);
|
||||
} cJSON_Hooks;
|
||||
|
||||
typedef int cJSON_bool;
|
||||
|
||||
/* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them.
|
||||
* This is to prevent stack overflows. */
|
||||
#ifndef CJSON_NESTING_LIMIT
|
||||
#define CJSON_NESTING_LIMIT 1000
|
||||
#endif
|
||||
|
||||
/* returns the version of cJSON as a string */
|
||||
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
||||
|
||||
/* Supply malloc, realloc and free functions to cJSON */
|
||||
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
||||
|
||||
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
|
||||
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length);
|
||||
/* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
|
||||
/* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated);
|
||||
|
||||
/* Render a cJSON entity to text for transfer/storage. */
|
||||
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
|
||||
/* Render a cJSON entity to text for transfer/storage without any formatting. */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);
|
||||
/* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */
|
||||
CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt);
|
||||
/* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */
|
||||
/* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format);
|
||||
/* Delete a cJSON entity and all subentities. */
|
||||
CJSON_PUBLIC(void) cJSON_Delete(cJSON *item);
|
||||
|
||||
/* Returns the number of items in an array (or object). */
|
||||
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array);
|
||||
/* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index);
|
||||
/* Get item "string" from object. Case insensitive. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string);
|
||||
/* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */
|
||||
CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void);
|
||||
|
||||
/* Check item type and return its value */
|
||||
CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item);
|
||||
CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item);
|
||||
|
||||
/* These functions check the type of an item */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item);
|
||||
|
||||
/* These calls create a cJSON item of the appropriate type. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string);
|
||||
/* raw json */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void);
|
||||
|
||||
/* Create a string where valuestring references a string so
|
||||
* it will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string);
|
||||
/* Create an object/array that only references it's elements so
|
||||
* they will not be freed by cJSON_Delete */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child);
|
||||
|
||||
/* These utilities create an Array of count items.
|
||||
* The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count);
|
||||
|
||||
/* Append item to the specified array/object. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item);
|
||||
/* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object.
|
||||
* WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before
|
||||
* writing to `item->string` */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item);
|
||||
/* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item);
|
||||
|
||||
/* Remove/Detach items from Arrays/Objects. */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string);
|
||||
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string);
|
||||
|
||||
/* Update array items. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem);
|
||||
|
||||
/* Duplicate a cJSON item */
|
||||
CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse);
|
||||
/* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
|
||||
* need to be released. With recurse!=0, it will duplicate any children connected to the item.
|
||||
* The item->next and ->prev pointers are always zero on return from Duplicate. */
|
||||
/* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal.
|
||||
* case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */
|
||||
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive);
|
||||
|
||||
/* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings.
|
||||
* The input pointer json cannot point to a read-only address area, such as a string constant,
|
||||
* but should point to a readable and writable adress area. */
|
||||
CJSON_PUBLIC(void) cJSON_Minify(char *json);
|
||||
|
||||
/* Helper functions for creating and adding items to an object at the same time.
|
||||
* They return the added item or NULL on failure. */
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name);
|
||||
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name);
|
||||
|
||||
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
|
||||
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
||||
/* helper for the cJSON_SetNumberValue macro */
|
||||
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number);
|
||||
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
||||
/* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */
|
||||
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring);
|
||||
|
||||
/* Macro for iterating over an array or object */
|
||||
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
||||
|
||||
/* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */
|
||||
CJSON_PUBLIC(void *) cJSON_malloc(size_t size);
|
||||
CJSON_PUBLIC(void) cJSON_free(void *object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,97 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
#include "netip.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define PACKED __attribute__((packed))
|
||||
|
||||
#define OP_LOGIN 1000
|
||||
#define OP_SYSINFO 1020
|
||||
|
||||
#define RESULT_OK 100
|
||||
#define RESULT_UNKNOWN_ERROR 101
|
||||
#define RESULT_INCORRECT_PWD 203
|
||||
|
||||
typedef struct netip_preabmle {
|
||||
uint8_t head;
|
||||
uint8_t version;
|
||||
uint16_t unused;
|
||||
uint32_t session;
|
||||
uint32_t sequence;
|
||||
uint8_t total;
|
||||
uint8_t cur;
|
||||
uint16_t msgid;
|
||||
uint32_t len_data;
|
||||
char data[];
|
||||
} PACKED netip_preabmle_t;
|
||||
|
||||
#define MAX_UDP_PACKET_SIZE 0xFFFF
|
||||
|
||||
typedef union netip_pkt {
|
||||
char buf[MAX_UDP_PACKET_SIZE];
|
||||
netip_preabmle_t header;
|
||||
} netip_pkt_t;
|
||||
|
||||
#define NETIP_HSIZE sizeof(netip_preabmle_t)
|
||||
#define NETIP_MAX_JSON sizeof(resp) - NETIP_HSIZE - 1
|
||||
|
||||
bool netip_connect(const char *addr, uint16_t port) {
|
||||
bool res = true;
|
||||
|
||||
int s = socket(AF_INET, SOCK_STREAM, 0);
|
||||
if (s == -1)
|
||||
return false;
|
||||
|
||||
struct sockaddr_in srv;
|
||||
srv.sin_addr.s_addr = inet_addr(addr);
|
||||
srv.sin_family = AF_INET;
|
||||
srv.sin_port = htons(port);
|
||||
|
||||
if (connect(s, (struct sockaddr *)&srv, sizeof(srv)) < 0)
|
||||
return false;
|
||||
|
||||
netip_pkt_t msg;
|
||||
memset(&msg.header, 0, sizeof(msg.header));
|
||||
msg.header.head = 0xff;
|
||||
msg.header.msgid = OP_LOGIN;
|
||||
const char default_login[] =
|
||||
"{\"EncryptType\": \"MD5\", \"LoginType\": \"DVRIP-Web\", \"PassWord\": "
|
||||
"\"tlJwpbo6\", \"UserName\": \"admin\"}\n\0";
|
||||
strcpy(msg.header.data, default_login);
|
||||
msg.header.len_data = sizeof(default_login);
|
||||
|
||||
if (send(s, &msg, sizeof(default_login) + NETIP_HSIZE, 0) < 0) {
|
||||
puts("Send failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recv(s, &msg, sizeof(msg), 0) <= NETIP_HSIZE) {
|
||||
puts("recv failed");
|
||||
}
|
||||
|
||||
cJSON *json = cJSON_Parse(msg.header.data);
|
||||
if (!json) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL) {
|
||||
fprintf(stderr, "Error before: %s\n", error_ptr);
|
||||
}
|
||||
res = false;
|
||||
goto skip_loop;
|
||||
}
|
||||
const int retval = get_json_intval(json, "Ret", 0);
|
||||
if (retval != RESULT_OK)
|
||||
return false;
|
||||
|
||||
skip_loop:
|
||||
cJSON_Delete(json);
|
||||
|
||||
return res;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef NETIP_H
|
||||
#define NETIP_H
|
||||
|
||||
bool netip_connect(const char* addr, uint16_t port);
|
||||
|
||||
#endif /* NETIP_H */
|
|
@ -0,0 +1,22 @@
|
|||
#include "cjson/cJSON.h"
|
||||
#include "utils.h"
|
||||
|
||||
const char *get_json_strval(const cJSON *json, const char *key,
|
||||
const char *def_val) {
|
||||
const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key);
|
||||
if (cJSON_IsString(jval) && (jval->valuestring != NULL)) {
|
||||
return jval->valuestring;
|
||||
} else {
|
||||
return def_val;
|
||||
}
|
||||
}
|
||||
|
||||
int get_json_intval(const cJSON *json, const char *key,
|
||||
int def_val) {
|
||||
const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key);
|
||||
if (cJSON_IsNumber(jval) && (jval->valueint)) {
|
||||
return jval->valueint;
|
||||
} else {
|
||||
return def_val;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
const char *get_json_strval(const cJSON *json, const char *key,
|
||||
const char *def_val);
|
||||
int get_json_intval(const cJSON *json, const char *key,
|
||||
int def_val);
|
||||
|
||||
#endif /* UTILS_H */
|
|
@ -0,0 +1,218 @@
|
|||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <netinet/in.h>
|
||||
#include <signal.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "cjson/cJSON.h"
|
||||
#include "netip.h"
|
||||
#include "utils.h"
|
||||
|
||||
#define SERVERPORT 34569
|
||||
// send broadcast packets periodically
|
||||
#define TIMEOUT 5 // seconds
|
||||
|
||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
const char brpkt[] =
|
||||
"\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfa\x05"
|
||||
"\x00\x00\x00\x00";
|
||||
static const char *Reset = "\x1b[0m";
|
||||
static const char *FgRed = "\x1b[31m";
|
||||
|
||||
// get sockaddr, IPv4 or IPv6:
|
||||
void *get_in_addr(struct sockaddr *sa) {
|
||||
if (sa->sa_family == AF_INET) {
|
||||
return &(((struct sockaddr_in *)sa)->sin_addr);
|
||||
}
|
||||
|
||||
return &(((struct sockaddr_in6 *)sa)->sin6_addr);
|
||||
}
|
||||
|
||||
int ipaddr_from32bit(char *dst, size_t dlen, const char *coded) {
|
||||
if (strlen(coded) != 10)
|
||||
return -1;
|
||||
|
||||
unsigned char octet[4];
|
||||
char cnvt[5] = "0x01";
|
||||
for (int i = 0; i < sizeof(octet); i++) {
|
||||
cnvt[2] = coded[i * 2 + 2];
|
||||
cnvt[3] = coded[i * 2 + 3];
|
||||
sscanf(cnvt, "%hhx", &octet[i]);
|
||||
}
|
||||
|
||||
snprintf(dst, dlen, "%d.%d.%d.%d", octet[3], octet[2], octet[1], octet[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bsock;
|
||||
|
||||
void send_netip_broadcast() {
|
||||
struct sockaddr_in sa;
|
||||
memset(sa.sin_zero, '\0', sizeof sa.sin_zero);
|
||||
|
||||
sa.sin_family = AF_INET;
|
||||
sa.sin_addr.s_addr = 0xffffffff;
|
||||
sa.sin_port = htons(SERVERPORT);
|
||||
|
||||
int rcvbts;
|
||||
if ((rcvbts = sendto(bsock, brpkt, sizeof(brpkt) - 1, 0,
|
||||
(struct sockaddr *)&sa, sizeof(struct sockaddr_in))) ==
|
||||
-1) {
|
||||
perror("sendto");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void sigalarm(int sig) {
|
||||
if (sig == SIGALRM) {
|
||||
send_netip_broadcast();
|
||||
alarm(TIMEOUT);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
bsock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (bsock == -1) {
|
||||
perror("socket");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct sockaddr_in name;
|
||||
name.sin_family = AF_INET;
|
||||
name.sin_port = htons(SERVERPORT);
|
||||
name.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (bind(bsock, (struct sockaddr *)&name, sizeof(name)) < 0) {
|
||||
perror("bind");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// this call is what allows broadcast packets to be sent:
|
||||
int broadcast = 1;
|
||||
if (setsockopt(bsock, SOL_SOCKET, SO_BROADCAST, &broadcast,
|
||||
sizeof broadcast) == -1) {
|
||||
perror("setsockopt (SO_BROADCAST)");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
send_netip_broadcast();
|
||||
|
||||
printf("Searching for XM cameras... Abort with CTRL+C.\n\n"
|
||||
"IP\t\tMAC-Address\t\tIdentity\n");
|
||||
|
||||
signal(SIGALRM, sigalarm);
|
||||
alarm(TIMEOUT);
|
||||
|
||||
size_t seen_len = 0;
|
||||
size_t seen_cap = 1;
|
||||
uint32_t *seen_vec = malloc(seen_cap * sizeof(*seen_vec));
|
||||
|
||||
while (1) {
|
||||
char buf[1024];
|
||||
struct sockaddr_in their_addr;
|
||||
socklen_t addr_len = sizeof their_addr;
|
||||
int rcvbts;
|
||||
if ((rcvbts = recvfrom(bsock, buf, sizeof buf - 1, 0,
|
||||
(struct sockaddr *)&their_addr, &addr_len)) == -1) {
|
||||
perror("recvfrom");
|
||||
exit(1);
|
||||
}
|
||||
if (rcvbts <= sizeof brpkt)
|
||||
continue;
|
||||
|
||||
buf[rcvbts] = '\0';
|
||||
|
||||
cJSON *json = cJSON_Parse(buf + 20);
|
||||
if (!json) {
|
||||
const char *error_ptr = cJSON_GetErrorPtr();
|
||||
if (error_ptr != NULL) {
|
||||
fprintf(stderr, "Error before: %s\n", error_ptr);
|
||||
}
|
||||
goto skip_loop;
|
||||
}
|
||||
#if 0
|
||||
char *str = cJSON_Print(json);
|
||||
if (str) {
|
||||
puts(str);
|
||||
}
|
||||
free(str);
|
||||
#endif
|
||||
|
||||
const cJSON *netcommon =
|
||||
cJSON_GetObjectItemCaseSensitive(json, "NetWork.NetCommon");
|
||||
const char *hostname = get_json_strval(netcommon, "HostName", "");
|
||||
const char *mac = get_json_strval(netcommon, "MAC", "");
|
||||
const char *host_ip = get_json_strval(netcommon, "HostIP", "");
|
||||
const int netip_port = get_json_intval(netcommon, "TCPPort", 0);
|
||||
const int chan_num = get_json_intval(netcommon, "ChannelNum", 0);
|
||||
const char *sn = get_json_strval(netcommon, "SN", "");
|
||||
const char *version = get_json_strval(netcommon, "Version", "");
|
||||
const char *builddt = get_json_strval(netcommon, "BuildDate", "");
|
||||
|
||||
uint32_t numipv4;
|
||||
if (sscanf(host_ip, "0x%x", &numipv4) == 1) {
|
||||
// find occurence
|
||||
for (int i = 0; i < seen_len; i++)
|
||||
if (seen_vec[i] == numipv4)
|
||||
goto skip_loop;
|
||||
if (seen_len == seen_cap) {
|
||||
seen_cap *= 2;
|
||||
seen_vec = realloc(seen_vec, seen_cap * sizeof(*seen_vec));
|
||||
}
|
||||
seen_vec[seen_len++] = numipv4;
|
||||
}
|
||||
|
||||
char abuf[50] = {0};
|
||||
if (strlen(host_ip)) {
|
||||
ipaddr_from32bit(abuf, sizeof abuf, host_ip);
|
||||
host_ip = abuf;
|
||||
}
|
||||
bool netip_ok = netip_connect(host_ip, netip_port);
|
||||
|
||||
char verstr[128] = {0};
|
||||
if (strlen(version)) {
|
||||
int n_dot = 0, i = 0;
|
||||
while (*version) {
|
||||
if (*version == '.') {
|
||||
n_dot++;
|
||||
if (n_dot == 4)
|
||||
break;
|
||||
} else if (n_dot == 3) {
|
||||
verstr[i++] = *version;
|
||||
}
|
||||
version++;
|
||||
}
|
||||
|
||||
if (strlen(builddt)) {
|
||||
const char *end;
|
||||
if ((end = strchr(builddt, ' '))) {
|
||||
strcat(verstr + strlen(verstr), " (");
|
||||
snprintf(verstr + strlen(verstr),
|
||||
MIN(sizeof(verstr) - strlen(verstr), end - builddt + 1),
|
||||
"%s", builddt);
|
||||
strcat(verstr + strlen(verstr), ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s%s\t%s\t%s %s, %s", netip_ok ? FgRed : "", host_ip, mac,
|
||||
chan_num > 1 ? "DVR" : "IPC", sn, hostname);
|
||||
if (strlen(verstr))
|
||||
printf("\t%s", verstr);
|
||||
printf("%s\n", netip_ok ? Reset : "");
|
||||
|
||||
skip_loop:
|
||||
|
||||
cJSON_Delete(json);
|
||||
}
|
||||
|
||||
free(seen_vec);
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
################################################################################
|
||||
#
|
||||
# xmdp
|
||||
#
|
||||
################################################################################
|
||||
|
||||
MCOOKIE_LICENSE = Public Domain
|
||||
|
||||
define XMDP_EXTRACT_CMDS
|
||||
cp package/x11r7/mcookie/mcookie.c $(@D)/
|
||||
endef
|
||||
|
||||
define XMDP_BUILD_CMDS
|
||||
(cd $(@D); $(TARGET_CC) -Wall -Os -s mcookie.c -o mcookie)
|
||||
<------>$(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -O -g -D LINUX -std=c99 -Wall -Wpedantic -lm -o $(PKG_BUILD_DIR)/$(PKG_NAME) \
|
||||
<------>$(PKG_BUILD_DIR)/xmdp.c $(PKG_BUILD_DIR)/netip.c $(PKG_BUILD_DIR)/utils.c $(PKG_BUILD_DIR)/cjson/cJSON.c
|
||||
endef
|
||||
|
||||
define XMDP_INSTALL_TARGET_CMDS
|
||||
install -m 0755 -D $(@D)/xmdp $(TARGET_DIR)/usr/bin/xmdp
|
||||
endef
|
||||
|
||||
$(eval $(generic-package))
|
Loading…
Reference in New Issue