diff --git a/.travis.yml b/.travis.yml index f988e9d..dd40986 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,14 +25,22 @@ script: - echo "$PWD" - export SRC_PATH="$PWD" - cd "$HOME/openwrt-sdk-omnia" - - echo "src-cpy nemea $SRC_PATH" > feeds.conf + - echo "src-cpy siot $SRC_PATH" > feeds.conf - ./scripts/feeds update - ./scripts/feeds install -a + - echo "src-git packages https://github.com/openwrt/packages.git^3a2c97600f051ba47f9aa83a121f3de09f567480" > feeds.conf + - ./scripts/feeds update packages poco + - ./scripts/feeds install -p packages poco + - ./scripts/feeds update packages libloragw + - ./scripts/feeds install -p packages libloragw + - echo "src-git turrispackages https://gitlab.labs.nic.cz/turris/turris-os-packages.git^6b0685fce4816e5c20cd0f6eacf5e37166c87c74" > feeds.conf + - ./scripts/feeds update turrispackages glib2 + - ./scripts/feeds install -p turrispackages glib2 - make -j8 && { mkdir -p $HOME/dist-pkgs/turris-omnia; cp -r bin/*/packages $HOME/dist-pkgs/turris-omnia; true;} || make -j1 V=s - cd "$HOME/openwrt-sdk-turris" - - echo "src-cpy nemea $SRC_PATH" > feeds.conf + - echo "src-cpy siot $SRC_PATH" > feeds.conf - ./scripts/feeds update - - ./scripts/feeds install -p nemea nemea-ipfixprobe + - ./scripts/feeds install -p siot nemea-ipfixprobe - make -j8 && { mkdir -p $HOME/dist-pkgs/turris; cp -r bin/*/packages $HOME/dist-pkgs/turris; true; } || make -j1 V=s deploy: @@ -40,7 +48,7 @@ deploy: skip_cleanup: true local_dir: $HOME/dist-pkgs github_token: $GITHUB_TOKEN - target_branch: turris-packages + target_branch: turris-packages-devel on: - branch: master + branch: devel diff --git a/README.md b/README.md index 5b46fa7..eeb065b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,13 @@ # NEMEA OpenWrt feed ## Description +This OpenWrt package feed contains parts that are necessary for the SIoT project but are not ready to be deployed on the Turris Omnia router without certain changes. -This is an OpenWrt package feed containing [NEMEA system](https://github.com/CESNET/Nemea) components and P4 generated [IPFIX exporter](https://github.com/CESNET/NEMEA-Probe) for exporting flow data . +Conditions for the pull request to master branch include: +* Newer version of glib (2.58.3 or newer) in Turris OS +* Poco libraries from [newer commit](https://github.com/openwrt/packages/commit/4712deffa57c9f919b1e60238daff7d164f6a695) in Turris OS + +Besides [NEMEA system](https://github.com/CESNET/Nemea) components and P4 generated [IPFIX exporter](https://github.com/CESNET/NEMEA-Probe) for exporting flow data, this Openwrt package feed contains [BeeeOn gateway] (https://github.com/BeeeOn/gateway). ![Infrastructure with NEMEA and OpenWRT router](doc/openwrt-scheme.png) diff --git a/net/nemea-siot/Makefile b/net/nemea-siot/Makefile index 047d818..cc4388a 100644 --- a/net/nemea-siot/Makefile +++ b/net/nemea-siot/Makefile @@ -1,14 +1,17 @@ include $(TOPDIR)/rules.mk PKG_NAME:=nemea-siot -PKG_VERSION:=19-08.1 +PKG_VERSION:=20-03.1 PKG_RELEASE:=1 PKG_SOURCE_PROTO:=git PKG_SOURCE_URL:=https://github.com/CESNET/nemea-siot.git -PKG_SOURCE_VERSION:=dd3b9a73af68aa54857b38ed18320c5078f08523 +PKG_SOURCE_VERSION:=78a6af6c236c29b46480ebef5eddd20b7477979f PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz +PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_SOURCE_VERSION) +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_SOURCE_VERSION) + PKG_MAINTAINER:=Tomas Cejka PKG_LICENSE:=BSD-3-Clause PKG_LICENSE_FILES:=LICENSE @@ -55,11 +58,49 @@ define Package/siot-lora-replay TITLE:=LoRaWAN Replay attack ABP detection endef +define Package/siot-ble-adv-collector + $(call Package/nemea-siot/Default) + TITLE:=BLE collector + DEPENDS+= +libstdcpp +bluez-libs +endef + +define Package/siot-ble-conn-detector + $(call Package/nemea-siot/Default) + TITLE:=BLE connection detector + DEPENDS+= +libstdcpp +bluez-libs +endef + +define Package/siot-ble-conn-guard + $(call Package/nemea-siot/Default) + TITLE:=BLE connection guard + DEPENDS+= +libstdcpp +bluez-libs +endef + define Package/siot-wsn-anomaly $(call Package/nemea-siot/Default) TITLE:=Wireless Sensor Network Detector (based on time series) endef +define Package/siot-zwave-collector + $(call Package/nemea-siot/Default) + TITLE:=Zwave collector +endef + +define Package/siot-zwave-detector + $(call Package/nemea-siot/Default) + TITLE:=Zwave detector +endef + +define Package/siot-zwave-stats-creator + $(call Package/nemea-siot/Default) + TITLE:=Zwave stats creator +endef + +define Package/siot-zwave-sniffer + $(call Package/nemea-siot/Default) + TITLE:=Zwave SDR sniffer +endef + TARGET_CFLAGS += \ -ffunction-sections \ -fdata-sections @@ -107,14 +148,59 @@ define Package/siot-lora-replay/install $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-lora-replay $(1)/usr/bin/nemea/ endef +define Package/siot-ble-adv-collector/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-ble-adv-collector $(1)/usr/bin/nemea/ +endef + +define Package/siot-ble-conn-detector/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-ble-conn-detector $(1)/usr/bin/nemea/ +endef + +define Package/siot-ble-conn-guard/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-ble-conn-guard $(1)/usr/bin/nemea/ +endef + define Package/siot-wsn-anomaly/install $(INSTALL_DIR) $(1)/usr/bin/nemea $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-wsn-anomaly $(1)/usr/bin/nemea/ endef +define Package/siot-zwave-collector/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-zwave-collector $(1)/usr/bin/nemea/ +endef + +define Package/siot-zwave-detector/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-zwave-detector $(1)/usr/bin/nemea/ +endef + +define Package/siot-zwave-stats-creator/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-zwave-stats-creator $(1)/usr/bin/nemea/ +endef + +define Package/siot-zwave-sniffer/install + $(INSTALL_DIR) $(1)/usr/bin/nemea + $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/nemea/siot-zwave-sdr-sniffer $(1)/usr/bin/nemea/ +endef + + + + $(eval $(call BuildPackage,siot-ble-pairing)) $(eval $(call BuildPackage,siot-hci-collector)) $(eval $(call BuildPackage,siot-lora-airtime)) $(eval $(call BuildPackage,siot-lora-distance)) $(eval $(call BuildPackage,siot-lora-replay)) +$(eval $(call BuildPackage,siot-ble-adv-collector)) +$(eval $(call BuildPackage,siot-ble-conn-detector)) +$(eval $(call BuildPackage,siot-ble-conn-guard)) $(eval $(call BuildPackage,siot-wsn-anomaly)) +$(eval $(call BuildPackage,siot-zwave-collector)) +$(eval $(call BuildPackage,siot-zwave-detector)) +$(eval $(call BuildPackage,siot-zwave-stats-creator)) +$(eval $(call BuildPackage,siot-zwave-sniffer)) diff --git a/net/nemea-siot/patches/001-remove-lora-collector-configure.patch b/net/nemea-siot/patches/001-remove-lora-collector-configure.patch new file mode 100644 index 0000000..43ce7c6 --- /dev/null +++ b/net/nemea-siot/patches/001-remove-lora-collector-configure.patch @@ -0,0 +1,10 @@ +--- a/configure.ac 2020-04-28 05:23:43.317176682 -0400 ++++ b/configure.ac 2020-04-28 05:25:09.458993152 -0400 +@@ -43,7 +43,6 @@ + AC_CONFIG_SUBDIRS([hci-collector + ble-pairing + wsn-anomaly +-lora-collector + lora-airtime + lora-replay + lora-distance diff --git a/net/nemea-siot/patches/002-remove-lora-collector-makefile.patch b/net/nemea-siot/patches/002-remove-lora-collector-makefile.patch new file mode 100644 index 0000000..a91b0e7 --- /dev/null +++ b/net/nemea-siot/patches/002-remove-lora-collector-makefile.patch @@ -0,0 +1,10 @@ +--- a/Makefile.am 2020-04-28 05:41:06.315152708 -0400 ++++ b/Makefile.am 2020-04-28 05:41:25.035546967 -0400 +@@ -3,7 +3,6 @@ + SUBDIRS=ble-pairing \ + hci-collector \ + wsn-anomaly \ +-lora-collector \ + lora-airtime \ + lora-replay \ + lora-distance \ diff --git a/utils/beeeon-gateway/Config.in b/utils/beeeon-gateway/Config.in new file mode 100644 index 0000000..48fc609 --- /dev/null +++ b/utils/beeeon-gateway/Config.in @@ -0,0 +1,95 @@ +menu "Configuration" + depends on PACKAGE_beeeon-gateway + +choice + prompt "Gateway Identity" + +config BEEEON_GATEWAY_ID_RANDOM + bool "random" + help + BeeeOn Gateway ID would be generated during the build + at random. + +config BEEEON_GATEWAY_ID_CUSTOM + bool "custom" + help + BeeeOn Gateway ID is to be entered manually. + +config BEEEON_GATEWAY_ID_CERT + bool "from certificate" + help + BeeeOn Gateway ID would be extracted from the given + certificate. It is thus required to give a path to + the gateway's private key, certificate and signing + certification authority. + +endchoice + +config BEEEON_GATEWAY_ID_CUSTOM_VALUE + string "ID" + depends on BEEEON_GATEWAY_ID_CUSTOM + default "1254321374233360" + help + The Gateway ID must be in the following decadic + format: VDDD DDDD DDDD DDDC. The V is "version" + and should be always 1. The series of D denotes + the unique identification part. The C is the DAMM + check sum digit. + +config BEEEON_GATEWAY_ID_CERT_FILE + string "Certificate file" + depends on BEEEON_GATEWAY_ID_CERT + help + The certification should prove that the gateway's + public key and ID are trusted by its signing CA. + +config BEEEON_GATEWAY_ID_CERT_PKEY + string "Private key file" + depends on BEEEON_GATEWAY_ID_CERT + help + Private key of the BeeeOn Gateway. + +config BEEEON_GATEWAY_ID_CERT_AUTHORITY + string "CA public key" + depends on BEEEON_GATEWAY_ID_CERT + help + The given file should represent the public key of CA + that has signed the certificate of the gateway. + +config BEEEON_GATEWAY_GWS + bool "GWS connector" + default n + help + Enable GWS connector, component to connect + to the remote BeeeOn Server. + +config BEEEON_GATEWAY_GWS_HOST + string "GWS host" + depends on BEEEON_GATEWAY_GWS + default "" if !BEEEON_GATEWAY_GWS + +config BEEEON_GATEWAY_GWS_PORT + int "GWS port" + depends on BEEEON_GATEWAY_GWS + range 1 65535 + default 8850 + +endmenu + +menu "Modules" + depends on PACKAGE_beeeon-gateway + +config BEEEON_GATEWAY_USB_UART_RECOMMENDED + bool + default n + +config BEEEON_GATEWAY_HAS_KMOD_USB_ACM + bool + default y if PACKAGE_kmod-usb-acm + default n + +comment "You may need to select kmod-usb-acm to support UART-over-USB." + depends on BEEEON_GATEWAY_USB_UART_RECOMMENDED + depends on !BEEEON_GATEWAY_HAS_KMOD_USB_ACM + +endmenu diff --git a/utils/beeeon-gateway/Makefile b/utils/beeeon-gateway/Makefile new file mode 100644 index 0000000..b4b7c3d --- /dev/null +++ b/utils/beeeon-gateway/Makefile @@ -0,0 +1,343 @@ +# +# Copyright (c) 2016, 2017, Brno University of Technology +# +# This is free software, licensed under the BSD-3-Clause. +# +# This file is based on +# https://github.com/BeeeOn/openwrt-packages/tree/master/beeeon-gateway +# + +include $(TOPDIR)/rules.mk + +PKG_NAME:=beeeon-gateway +PKG_VERSION:=v2020.3.1 +PKG_RELEASE:=1 +INIT_SCRIPT_NAME:=$(PKG_NAME) + + +PKG_SOURCE_PROTO:=git +PKG_SOURCE_URL:=https://github.com/BeeeOn/gateway.git +PKG_SOURCE_VERSION:=2d52852c0547484a31ace3ea41b91c5c3ae72fa3 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_SOURCE_VERSION).tar.gz + +PKG_MAINTAINER:=Jakub Jalowiczor +PKG_LICENSE:=BSD-3-Clause +PKG_LICENSE_FILES:=LICENSE + +PKG_BUILD_PARALLEL:=1 +CMAKE_INSTALL:=1 +BUILD_DIR:=$(TOPDIR)/build_dir/turris +PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION) + +include $(INCLUDE_DIR)/package.mk +include $(INCLUDE_DIR)/cmake.mk + +ifeq ($(BUILD_VARIANT),all) + CMAKE_OPTIONS += \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DENABLE_TESTS=OFF \ + -DENABLE_UDEV=OFF \ + -DENABLE_BELKIN_WEMO=ON \ + -DENABLE_BLE_SMART=ON \ + -DENABLE_BLUETOOTH_AVAILABILITY=ON \ + -DENABLE_HCI_INFO_REPORTER=ON \ + -DENABLE_FITP=OFF \ + -DENABLE_IQRF=ON \ + -DENABLE_JABLOTRON=ON \ + -DENABLE_PHILIPS_HUE=ON \ + -DENABLE_VEKTIVA=ON \ + -DENABLE_CONRAD=OFF \ + -DENABLE_PRESSURE_SENSOR=ON \ + -DENABLE_VIRTUAL_DEVICES=ON \ + -DENABLE_VPT=ON \ + -DENABLE_ZWAVE=ON \ + -DENABLE_TESTING_CENTER=ON \ + -DENABLE_SONOFF=ON \ + -DENABLE_NEMEA=ON +else + CMAKE_OPTIONS += \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DENABLE_TESTS=OFF \ + -DENABLE_UDEV=OFF \ + -DENABLE_BELKIN_WEMO=OFF \ + -DENABLE_BLE_SMART=OFF \ + -DENABLE_BLUETOOTH_AVAILABILITY=OFF \ + -DENABLE_HCI_INFO_REPORTER=OFF \ + -DENABLE_FITP=OFF \ + -DENABLE_IQRF=OFF \ + -DENABLE_JABLOTRON=OFF \ + -DENABLE_PHILIPS_HUE=OFF \ + -DENABLE_VEKTIVA=OFF \ + -DENABLE_CONRAD=OFF \ + -DENABLE_PRESSURE_SENSOR=ON \ + -DENABLE_VIRTUAL_DEVICES=ON \ + -DENABLE_VPT=OFF \ + -DENABLE_ZWAVE=OFF \ + -DENABLE_TESTING_CENTER=ON \ + -DENABLE_SONOFF=OFF \ + -DENABLE_NEMEA=OFF +endif + +TARGET_CXXFLAGS += -DPOCO_NO_FPENVIRONMENT + +define Package/beeeon-gateway/config + source "$(SOURCE)/Config.in" +endef + +define Package/beeeon-gateway-all/config + source "$(SOURCE)/Config.in" +endef + +PKG_BUILD_DEPENDS += +poco-all python3/host +mosquitto + +ifeq ($(BUILD_VARIANT),all) + PKG_BUILD_DEPENDS += +glib2 +bluez +openzwave +endif + +define Package/beeeon-gateway + SECTION:=utils + CATEGORY:=Utilities + TITLE:=BeeeOn Gateway (minimal version) + URL:=https://beeeon.github.io/gateway/ + DEPENDS:=+poco-all + DEPENDS += +libmosquittopp + VARIANT:=minimal +endef + +define Package/beeeon-gateway/description + The main application for BeeeOn Gateway with all modules disabled. +endef + +define Package/beeeon-gateway-all + SECTION:=utils + CATEGORY:=Utilities + TITLE:=BeeeOn Gateway (version with all modules enabled) + URL:=https://beeeon.github.io/gateway/ + DEPENDS:=+poco-all + DEPENDS += +bluez-daemon +bluez-libs +glib2 +libmosquittopp +nemea-framework +libpcap +openzwave-config +libopenzwave + VARIANT:=all +endef + +define Package/beeeon-gateway-all/description + The main application for BeeeOn Gateway with all modules enabled. +endef + +BEEEON_GATEWAY_MODULE_ENABLE += psdev \ + vdev \ + testing.center \ + testing.collector \ + exporter.mqtt \ + gws + +BEEEON_GATEWAY_MODULE_DISABLE += fitp \ + conrad + +ifeq ($(BUILD_VARIANT),all) + BEEEON_GATEWAY_MODULE_ENABLE += belkinwemo \ + blesmart \ + bluetooth.availability \ + bluetooth.reporting \ + iqrf \ + jablotron \ + philipshue \ + vpt \ + zwave \ + vektiva \ + sonoff \ + nemea +else + BEEEON_GATEWAY_MODULE_DISABLE += belkinwemo \ + blesmart \ + bluetooth.availability \ + bluetooth.reporting \ + iqrf \ + jablotron \ + philipshue \ + vpt \ + zwave \ + vektiva \ + sonoff \ + nemea +endif + +# Generate random BeeeOn Gateway ID +ifeq ($(CONFIG_BEEEON_GATEWAY_ID_RANDOM),y) +BEEEON_GATEWAY_MODULE_ENABLE += gateway.id + +define BEEEON_GATEWAY_ID_INSTALL + echo gateway.id = `python3 $(PKG_BUILD_DIR)/tools/gateway-genid.py` \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + echo ssl.key = >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + echo ssl.certificate = >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties +endef +endif + +# Configure the manually inserted BeeeOn Gateway ID +ifeq ($(CONFIG_BEEEON_GATEWAY_ID_CUSTOM),y) +BEEEON_GATEWAY_MODULE_ENABLE += gateway.id + +define BEEEON_GATEWAY_ID_INSTALL + echo gateway.id = $(CONFIG_BEEEON_GATEWAY_ID_CUSTOM_VALUE) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + echo ssl.key = >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + echo ssl.certificate = >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties +endef +endif + +# Use SSL/TLS to provide BeeeOn Gateway ID +ifeq ($(CONFIG_BEEEON_GATEWAY_ID_CERT),y) +BEEEON_GATEWAY_MODULE_DISABLE += gateway.id + +define BEEEON_GATEWAY_ID_INSTALL + $(INSTALL_DIR) $(PKG_INSTALL_DIR)/etc/ssl/beeeon/private + $(CP) $(CONFIG_BEEEON_GATEWAY_ID_CERT_PKEY) \ + $(PKG_INSTALL_DIR)/etc/ssl/beeeon/private/beeeon_gateway.key + + $(INSTALL_DIR) $(PKG_INSTALL_DIR)/etc/ssl/beeeon/certs + $(CP) $(CONFIG_BEEEON_GATEWAY_ID_CERT_FILE) \ + $(PKG_INSTALL_DIR)/etc/ssl/beeeon/certs/beeeon_gateway.crt + $(CP) $(CONFIG_BEEEON_GATEWAY_ID_CERT_AUTHORITY) \ + $(PKG_INSTALL_DIR)/etc/ssl/beeeon/certs/beeeon_root_ca.crt +endef +endif + +ifeq ($(CONFIG_BEEEON_GATEWAY_MQTT_EXPORTER),y) +define BEEEON_GATEWAY_MQTT_INSTALL + echo exporter.mqtt.host = $(CONFIG_BEEEON_GATEWAY_MQTT_EXPORTER_HOST) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-mqtt.properties + echo exporter.mqtt.port = $(CONFIG_BEEEON_GATEWAY_MQTT_EXPORTER_PORT) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-mqtt.properties + echo exporter.mqtt.topic = $(CONFIG_BEEEON_GATEWAY_MQTT_EXPORTER_TOPIC) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-mqtt.properties + echo exporter.mqtt.clientID = $(CONFIG_BEEEON_GATEWAY_MQTT_EXPORTER_CLIENT_ID) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-mqtt.properties +endef +endif + +define Package/beeeon-gateway/install + echo hotplug.impl = pipeHotplug \ + > $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-hotplug.properties + + $(RM) $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties + $(foreach module,$(BEEEON_GATEWAY_MODULE_ENABLE),\ + echo $(module).enable = yes \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties;) + $(foreach module,$(BEEEON_GATEWAY_MODULE_DISABLE),\ + echo $(module).enable = no \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties;) + + $(RM) $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + + $(if $(CONFIG_BEEEON_GATEWAY_GWS_HOST),\ + echo gws.host = $(CONFIG_BEEEON_GATEWAY_GWS_HOST) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties) + $(if $(CONFIG_BEEEON_GATEWAY_GWS_PORT),\ + echo gws.port = $(CONFIG_BEEEON_GATEWAY_GWS_PORT) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties) + + $(BEEEON_GATEWAY_ID_INSTALL) + + sed -i "s|/var/cache|/usr/lib|" ${PKG_INSTALL_DIR}/usr/etc/beeeon/gateway/gateway-startup.ini + mkdir -p $(1)/usr/lib/beeeon/gateway + + $(INSTALL_DIR) $(1) + $(CP) -r $(PKG_INSTALL_DIR)/* $(1) + $(RM) -r $(1)/var + + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/$(INIT_SCRIPT_NAME) $(1)/etc/init.d/$(INIT_SCRIPT_NAME) + + $(INSTALL_DIR) $(1)/etc/hotplug.d + $(CP) ./files/beeeon-hotplug-functions $(1)/etc/hotplug.d/beeeon-hotplug-functions + $(INSTALL_DIR) $(1)/etc/hotplug.d/tty + $(CP) ./files/tty-beeeon-dongle $(1)/etc/hotplug.d/tty/30-beeeon-dongle + $(INSTALL_DIR) $(1)/etc/hotplug.d/bluetooth + $(CP) ./files/bluetooth-beeeon-dongle $(1)/etc/hotplug.d/bluetooth/30-beeeon-dongle +endef + +define Package/beeeon-gateway-all/install + echo hotplug.impl = pipeHotplug \ + > $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-hotplug.properties + + $(RM) $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties + $(foreach module,$(BEEEON_GATEWAY_MODULE_ENABLE),\ + echo $(module).enable = yes \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties;) + $(foreach module,$(BEEEON_GATEWAY_MODULE_DISABLE),\ + echo $(module).enable = no \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-modules.properties;) + + $(RM) $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties + + $(if $(CONFIG_BEEEON_GATEWAY_GWS_HOST),\ + echo gws.host = $(CONFIG_BEEEON_GATEWAY_GWS_HOST) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties) + $(if $(CONFIG_BEEEON_GATEWAY_GWS_PORT),\ + echo gws.port = $(CONFIG_BEEEON_GATEWAY_GWS_PORT) \ + >> $(PKG_INSTALL_DIR)/usr/etc/beeeon/gateway/config.d/x-gws.properties) + + $(BEEEON_GATEWAY_ID_INSTALL) + + sed -i "s|/var/cache|/usr/lib|" ${PKG_INSTALL_DIR}/usr/etc/beeeon/gateway/gateway-startup.ini + mkdir -p $(1)/usr/lib/beeeon/gateway + + $(INSTALL_DIR) $(1) + $(CP) -r $(PKG_INSTALL_DIR)/* $(1) + $(RM) -r $(1)/var + + $(INSTALL_DIR) $(1)/etc/init.d + $(INSTALL_BIN) ./files/$(INIT_SCRIPT_NAME) $(1)/etc/init.d/$(INIT_SCRIPT_NAME) + + $(INSTALL_DIR) $(1)/etc/hotplug.d + $(CP) ./files/beeeon-hotplug-functions $(1)/etc/hotplug.d/beeeon-hotplug-functions + $(INSTALL_DIR) $(1)/etc/hotplug.d/tty + $(CP) ./files/tty-beeeon-dongle $(1)/etc/hotplug.d/tty/30-beeeon-dongle + $(INSTALL_DIR) $(1)/etc/hotplug.d/bluetooth + $(CP) ./files/bluetooth-beeeon-dongle $(1)/etc/hotplug.d/bluetooth/30-beeeon-dongle +endef + +define Package/beeeon-gateway/postinst +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + echo "Enabling and starting $(PKG_NAME) service" + /etc/init.d/$(INIT_SCRIPT_NAME) enable + /etc/init.d/$(INIT_SCRIPT_NAME) start +fi +exit 0 +endef + +define Package/beeeon-gateway-all/postinst +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + echo "Enabling and starting $(PKG_NAME) service" + /etc/init.d/$(INIT_SCRIPT_NAME) enable + /etc/init.d/$(INIT_SCRIPT_NAME) start +fi +exit 0 +endef + +define Package/beeeon-gateway/prerm +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + echo "Disabling and stopping $(PKG_NAME) service" + /etc/init.d/$(INIT_SCRIPT_NAME) disable + /etc/init.d/$(INIT_SCRIPT_NAME) stop +fi +exit 0 +endef + +define Package/beeeon-gateway-all/prerm +#!/bin/sh +if [ -z "$${IPKG_INSTROOT}" ]; then + echo "Disabling and stopping $(PKG_NAME) service" + /etc/init.d/$(INIT_SCRIPT_NAME) disable + /etc/init.d/$(INIT_SCRIPT_NAME) stop +fi +exit 0 +endef + +$(eval $(call BuildPackage,beeeon-gateway)) +$(eval $(call BuildPackage,beeeon-gateway-all)) diff --git a/utils/beeeon-gateway/files/beeeon-gateway b/utils/beeeon-gateway/files/beeeon-gateway new file mode 100644 index 0000000..85c354b --- /dev/null +++ b/utils/beeeon-gateway/files/beeeon-gateway @@ -0,0 +1,29 @@ +#!/bin/sh /etc/rc.common +# +# BeeeOn Project 2016 +# Author: Matej Postolka +# Last modified: 2016-04-04 +# + +USE_PROCD=1 +START=80 +APP=beeeon-gateway +BINARY_PATH=/usr/bin +CONFIG_PATH=/usr/etc/beeeon/gateway + +registerIniFiles() { + for f in $(ls $CONFIG_PATH/*.ini $CONFIG_PATH/config.d/*.ini $CONFIG_PATH/config.d/*.xml); do + procd_set_param file "$f" + done +} + +start_service() { + mkdir -p /var/run/beeeon/gateway + + procd_open_instance + procd_set_param command ${BINARY_PATH}/${APP} --config=${CONFIG_PATH}/gateway-startup.ini + registerIniFiles() + procd_set_param stdout 1 + procd_set_param stderr 1 + procd_close_instance +} diff --git a/utils/beeeon-gateway/files/beeeon-hotplug-functions b/utils/beeeon-gateway/files/beeeon-hotplug-functions new file mode 100755 index 0000000..4a457f4 --- /dev/null +++ b/utils/beeeon-gateway/files/beeeon-hotplug-functions @@ -0,0 +1,82 @@ +#! /bin/sh + +FIFO_PATH="/var/run/beeeon/gateway.hotplug" +OUTPUT_DATA="" + +propagate_uevents() +{ + PARENT="/sys${3}" + DEVICE="/sys${3}/device" + if [[ -z $OUTPUT_DATA ]]; then + OUTPUT_DATA="ACTION=$ACTION +SUBSYSTEM=${1}" + else + OUTPUT_DATA="ACTION=$ACTION +SUBSYSTEM=${1} +$OUTPUT_DATA" + fi + propagate_device_uevents "${DEVICE}" "${1}" + propagate_parent_uevents "${PARENT}" "${1}" +} + +ensure_pipe_existence() +{ + if [ ! -p "${FIFO_PATH}" ]; then + if [ -f "${FIFO_PATH}" ]; then + rm -f "${FIFO_PATH}" + fi + mkfifo "${FIFO_PATH}" + fi +} + +init_and_propagate_uevents() +{ + ensure_pipe_existence + OUTPUT_DATA=${4} + propagate_uevents "${1}" "${2}" "${3}" + propagate_lines "$OUTPUT_DATA" +} + +propagate_device_uevents() +{ + UEVENT=${1}/uevent + #DEVICE_UEVENT=$(sed 's/^/'${2}'./;' $UEVENT) + DEVICE_UEVENT=$(cat $UEVENT) + OUTPUT_DATA="$OUTPUT_DATA +$DEVICE_UEVENT" +} + +propagate_parent_uevents() +{ + UEVENT=${1}/uevent + #PARENT_UEVENT=$(sed 's/^/'${2}'./;' $UEVENT) + PARENT_UEVENT=$(cat $UEVENT) + OUTPUT_DATA="$OUTPUT_DATA +$PARENT_UEVENT" + UEVENT_CONTENT=$(cat $UEVENT) + if [[ -z "${UEVENT_CONTENT##*DEVNAME*}" ]] && [[ -z "${UEVENT_CONTENT##*MAJOR*}" ]] && [[ -z "${UEVENT_CONTENT##*MINOR*}" ]]; then + check_major_minor "$UEVENT" "${2}" + fi +} + +check_major_minor() +{ + DEVICE_NAME=$(cat ${1} | grep "DEVNAME" | cut -c 9-) + MAJOR_NUMBER_ORIG=$(ls -l /dev | grep $DEVICE_NAME | tr -s ' ' | cut -f5 -d" " | tr -d ,) + MINOR_NUMBER_ORIG=$(ls -l /dev | grep $DEVICE_NAME | tr -s ' ' | cut -f6 -d" ") + MAJOR_NUMBER_HOTPLUG=$(cat ${1} | grep "MAJOR" | cut -c 7-) + MINOR_NUMBER_HOTPLUG=$(cat ${1} | grep "MINOR" | cut -c 7-) + if [ "$MAJOR_NUMBER_ORIG" = "$MAJOR_NUMBER_HOTPLUG" ] && [ "$MINOR_NUMBER_ORIG" = "$MINOR_NUMBER_HOTPLUG" ]; then + OUTPUT_DATA="$OUTPUT_DATA +NODE=/dev/$DEVICE_NAME" + fi +} + +propagate_lines() +{ + ensure_pipe_existence + cat <<__EOF >"${FIFO_PATH}" +${1} + +__EOF +} diff --git a/utils/beeeon-gateway/files/bluetooth-beeeon-dongle b/utils/beeeon-gateway/files/bluetooth-beeeon-dongle new file mode 100644 index 0000000..a918a45 --- /dev/null +++ b/utils/beeeon-gateway/files/bluetooth-beeeon-dongle @@ -0,0 +1,31 @@ +#! /bin/sh + +. /etc/hotplug.d/beeeon-hotplug-functions + +if [[ -n "$DEVPATH" ]] && [[ $ACTION == "add" ]]; then + if [ "$DEVTYPE" = "host" ]; then + OUTPUT_LINES='bluetooth.BEEEON_DONGLE="bluetooth"' + fi + DEVICE_UEVENT="/sys$DEVPATH/device/uevent" + UEVENT_CONTENT=$(cat $DEVICE_UEVENT) + if [[ -z "${UEVENT_CONTENT##*PRODUCT*}" ]]; then + idVendor=$(cat $DEVICE_UEVENT | grep "PRODUCT" | cut -c 9-12) + idProduct=$(cat $DEVICE_UEVENT | grep "PRODUCT" | cut -c 14-17) + OUTPUT_LINES="$OUTPUT_LINES +idVendor=$idVendor +idProduct=$idProduct" + fi + init_and_propagate_uevents "$SUBSYSTEM" "$ACTION" "$DEVPATH" "$OUTPUT_LINES" +fi + +if [[ $ACTION == "remove" ]]; then + OUTPUT_LINES="ACTION=remove +SUBSYSTEM=$SUBSYSTEM +NAME=$DEVICENAME +DEVPATH=$DEVPATH" + if [ "$DEVTYPE" = "host" ]; then + OUTPUT_LINES="$OUTPUT_LINES +bluetooth.BEEEON_DONGLE=\"bluetooth\"" + fi + propagate_lines "$OUTPUT_LINES" +fi diff --git a/utils/beeeon-gateway/files/tty-beeeon-dongle b/utils/beeeon-gateway/files/tty-beeeon-dongle new file mode 100644 index 0000000..b2ddde2 --- /dev/null +++ b/utils/beeeon-gateway/files/tty-beeeon-dongle @@ -0,0 +1,55 @@ +#! /bin/sh + +. /etc/hotplug.d/beeeon-hotplug-functions + +usb_vendor_id() +{ + awk -F'[=/]' '/^PRODUCT/ {print $2}' < "${1}" \ + | sed -e 's/^.$/000&/' -e 's/^..$/00&/' -e 's/^...$/0&/' +} + +usb_product_id() +{ + awk -F'[=/]' '/^PRODUCT/ {print $3}' < "${1}" \ + | sed -e 's/^.$/000&/' -e 's/^..$/00&/' -e 's/^...$/0&/' +} + +if [[ -n "$DEVPATH" ]] && [[ $SUBSYSTEM != "usb-serial" ]] && [[ $ACTION == "add" ]]; then + DEVICE_UEVENT="/sys$DEVPATH/device/uevent" + UEVENT_CONTENT=$(cat $DEVICE_UEVENT) + if [[ -z "${UEVENT_CONTENT##*PRODUCT*}" ]]; then + idVendor=`usb_vendor_id "${DEVICE_UEVENT}"` + idProduct=`usb_product_id "${DEVICE_UEVENT}"` + OUTPUT_DATA="idVendor=$idVendor +idProduct=$idProduct" + case "${idVendor}-${idProduct}" in + "0403-6015") + OUTPUT_DATA="$OUTPUT_DATA +tty.BEEEON_DONGLE=jablotron" + ;; + "0658-0200") + OUTPUT_DATA="$OUTPUT_DATA +tty.BEEEON_DONGLE=zwave" + ;; + esac + fi + init_and_propagate_uevents "$SUBSYSTEM" "$ACTION" "$DEVPATH" "$OUTPUT_DATA" +fi + +if [[ $SUBSYSTEM != "usb-serial" ]] && [[ $ACTION == "remove" ]]; then + if [ -n "$DEVNAME" ]; then + OUTPUT_DATA="DEVNAME=$DEVNAME +NODE=/dev/$DEVNAME" + fi + if [ -n "$MAJOR" ]; then + OUTPUT_DATA="$OUTPUT_DATA +MAJOR=$MAJOR +MINOR=$MINOR" + fi + DATA_TO_OUTPUT="ACTION=remove +SUBSYSTEM=$SUBSYSTEM +DEVNAME=$DEVICENAME +DEVPATH=$DEVPATH +$OUTPUT_DATA" + propagate_lines "$DATA_TO_OUTPUT" +fi