├── utils ├── luci-app-ipcam2 │ ├── docs │ │ └── img │ │ │ ├── ipcam2_services.jpg │ │ │ ├── ipcam2_settings.jpg │ │ │ ├── ipcam2_filebrowser.jpg │ │ │ ├── ipcam2_minisnmpd.jpg │ │ │ └── ipcam2_sdcardsettings.jpg │ ├── luasrc │ │ ├── controller │ │ │ └── admin │ │ │ │ ├── settings.lua │ │ │ │ ├── snmpd.lua │ │ │ │ ├── service.lua │ │ │ │ ├── ipcam.lua │ │ │ │ └── filebrowser2.lua │ │ ├── view │ │ │ └── admin_ipcam │ │ │ │ ├── sdcard_status.htm │ │ │ │ ├── sdcard_format_f2fs.htm │ │ │ │ ├── sdcard_format_vfat.htm │ │ │ │ ├── range.htm │ │ │ │ ├── service.htm │ │ │ │ └── filebrowser.htm │ │ ├── model │ │ │ └── cbi │ │ │ │ └── admin_ipcam │ │ │ │ ├── sdcard_settings.lua │ │ │ │ ├── mini_snmpd.lua │ │ │ │ └── settings.lua │ │ └── LIP.lua │ ├── Makefile │ └── README.md ├── xmdp │ ├── src │ │ ├── netip.h │ │ ├── Makefile │ │ ├── utils.h │ │ ├── utils.c │ │ ├── netip.c │ │ ├── xmdp.c │ │ └── cjson │ │ │ └── cJSON.h │ ├── README.md │ ├── LICENSE │ └── Makefile ├── memdump │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ └── memdump.c ├── hisi_gpio_scanner │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ ├── hisi_gpio_scanner.c.bak │ │ └── hisi_gpio_scanner.c ├── hisi_gpio_watcher │ ├── README.md │ ├── LICENSE │ ├── Makefile │ └── src │ │ └── hisi_gpio_watcher.c └── ipctool │ └── Makefile ├── LICENSE └── README.md /utils/luci-app-ipcam2/docs/img/ipcam2_services.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_services.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_settings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_settings.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_filebrowser.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_filebrowser.jpg -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_minisnmpd.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_minisnmpd.jpg -------------------------------------------------------------------------------- /utils/xmdp/src/netip.h: -------------------------------------------------------------------------------- 1 | #ifndef NETIP_H 2 | #define NETIP_H 3 | 4 | bool netip_connect(const char* addr, uint16_t port); 5 | 6 | #endif /* NETIP_H */ 7 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/docs/img/ipcam2_sdcardsettings.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OpenIPC/packages/main/utils/luci-app-ipcam2/docs/img/ipcam2_sdcardsettings.jpg -------------------------------------------------------------------------------- /utils/xmdp/src/Makefile: -------------------------------------------------------------------------------- 1 | CFLAGS=-Wall -Wpedantic 2 | LDFLAGS=-lm 3 | 4 | all: xmdp 5 | 6 | xmdp: xmdp.o netip.o utils.o cjson/cJSON.c 7 | $(CC) -o $@ $^ $(LDFLAGS) 8 | 9 | clean: 10 | -rm xmdp *.o 11 | -------------------------------------------------------------------------------- /utils/xmdp/README.md: -------------------------------------------------------------------------------- 1 | # XMDP 2 | 3 | Utility for finding devices that support the NETIP protocol 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/xmdp/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/settings.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.settings", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "settings"}, cbi("admin_ipcam/settings"), _("Settings")) 5 | end -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/snmpd.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.snmpd", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "mini_snmpd"}, cbi("admin_ipcam/mini_snmpd"), _("Mini SNMPd")) 5 | end -------------------------------------------------------------------------------- /utils/memdump/README.md: -------------------------------------------------------------------------------- 1 | # MEMDUMP 2 | 3 | An alternative simple utility for getting dumps from memory 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/memdump/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/README.md: -------------------------------------------------------------------------------- 1 | # HISI_GPIO_SCANNER 2 | 3 | Utility for diagnosing and displaying GPIO statuses 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/hisi_gpio_scanner/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/README.md: -------------------------------------------------------------------------------- 1 | # HISI_GPIO_WATCHER 2 | 3 | Utility for run commands when changing GPIO statuses 4 | 5 | ### Example compilation in OpenIPC root dir 6 | 7 | ```make -j1 V=s package/feeds/futurum/hisi_gpio_watcher/{clean,compile,install}``` 8 | -------------------------------------------------------------------------------- /utils/xmdp/src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | const char *get_json_strval(const cJSON *json, const char *key, 5 | const char *def_val); 6 | int get_json_intval(const cJSON *json, const char *key, 7 | int def_val); 8 | 9 | #endif /* UTILS_H */ 10 | -------------------------------------------------------------------------------- /utils/xmdp/src/utils.c: -------------------------------------------------------------------------------- 1 | #include "cjson/cJSON.h" 2 | #include "utils.h" 3 | 4 | const char *get_json_strval(const cJSON *json, const char *key, 5 | const char *def_val) { 6 | const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key); 7 | if (cJSON_IsString(jval) && (jval->valuestring != NULL)) { 8 | return jval->valuestring; 9 | } else { 10 | return def_val; 11 | } 12 | } 13 | 14 | int get_json_intval(const cJSON *json, const char *key, 15 | int def_val) { 16 | const cJSON *jval = cJSON_GetObjectItemCaseSensitive(json, key); 17 | if (cJSON_IsNumber(jval) && (jval->valueint)) { 18 | return jval->valueint; 19 | } else { 20 | return def_val; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_status.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 21 | 22 | 23 | <%+cbi/valuefooter%> 24 | 25 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/service.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.service", package.seeall) 2 | 3 | function index() 4 | entry({"admin", "ipcam", "service"}, template("admin_ipcam/service"), _("Service"), 1) 5 | entry({"admin", "ipcam", "service", "control"}, call("svc_control")).leaf = true 6 | end 7 | 8 | function svc_control() 9 | if luci.http.formvalue("action") == "Restart" then 10 | luci.sys.call("killall -sigint majestic") 11 | luci.sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 12 | end 13 | if luci.http.formvalue("action") == "Stop" then 14 | luci.sys.call("killall -sigint majestic") 15 | end 16 | if luci.http.formvalue("action") == "Start" then 17 | luci.sys.call("killall -sigint majestic") 18 | luci.sys.call("export SENSOR=`fw_printenv -n sensor`; majestic 2>&1 | logger -p daemon.info -t majestic &") 19 | end 20 | luci.http.redirect(luci.dispatcher.build_url("admin/ipcam/service")) 21 | end -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/xmdp/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/memdump/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OpenIPC.org 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2011-2014 OpenWrt.org 3 | # 4 | # This is free software, licensed under the GNU General Public License v2. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=luci-app-ipcam2 11 | PKG_VERSION:=2021-04-21 12 | PKG_RELEASE:=2.0 13 | PKG_MAINTAINER:=Randy 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=GPL-2.0 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Other 24 | TITLE:=OpenIPC luci extension 25 | MAINTAINER:=Randy D. 26 | URL:=http://openipc.org 27 | endef 28 | 29 | define Package/$(PKG_NAME)/description 30 | Original concept from luci-app-config by Igor Zalatov (ZFT Lab.) . Modified to configure OpenIPC settings and monitor services. 31 | endef 32 | 33 | define Build/Prepare 34 | endef 35 | 36 | define Build/Compile 37 | endef 38 | 39 | define Package/$(PKG_NAME)/install 40 | $(INSTALL_DIR) $(1)/usr/lib/lua/luci 41 | $(CP) ./luasrc/* $(1)/usr/lib/lua/luci/ 42 | $(CP) ./htdocs/ $(1)/www/ 43 | endef 44 | 45 | $(eval $(call BuildPackage,$(PKG_NAME))) 46 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/model/cbi/admin_ipcam/sdcard_settings.lua: -------------------------------------------------------------------------------- 1 | local os = require "os"; 2 | local fs = require "nixio.fs"; 3 | local config = 'ipcam'; 4 | 5 | local m, d, a, s, dm, t; 6 | 7 | if fs.stat('/etc/config/'..config, "type") ~= "reg" then 8 | os.execute('touch /etc/config/'..config) 9 | end 10 | 11 | m = Map(config, translate("SD Card Settings"), translate("Here you can configure sd card settings.")); 12 | 13 | s = "sdcard"; 14 | 15 | dm = m:section(NamedSection, "sdcard", ""); 16 | 17 | t = dm:option(DummyValue, "_capacity", translate("Capacity")) 18 | t.template = "admin_ipcam/sdcard_status" 19 | 20 | a = dm:option(Flag, "photo", "Save event photo to SD card"); 21 | a.optional = false; a.rmempty = false; 22 | 23 | a = dm:option(Flag, "video", "Save event video to SD card"); 24 | a.optional = false; a.rmempty = false; 25 | 26 | a = dm:option(Flag, "overwrite", "Over-write when full"); 27 | a.optional = false; a.rmempty = false; 28 | 29 | t = dm:option(DummyValue, "_format_sd_card_f2fs", "Format SD Card") 30 | t.template = "admin_ipcam/sdcard_format_f2fs" 31 | 32 | t = dm:option(DummyValue, "_format_sd_card_vfat", "Format SD Card") 33 | t.template = "admin_ipcam/sdcard_format_vfat" 34 | 35 | return m 36 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=hisi_gpio_scanner 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Andrew_kmr 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for diagnosing and displaying GPIO statuses 25 | MAINTAINER:=Andrew_kmr 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for diagnosing and displaying GPIO statuses 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/hisi_gpio_scanner.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/memdump/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=memdump 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=An alternative simple utility for getting dumps from memory 25 | MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | An alternative simple utility for getting dumps from memory 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/memdump.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=hisi_gpio_watcher 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for run commands when changing GPIO statuses 25 | MAINTAINER:=Maksim Patrushev <330379404icq@gmail.com> 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for run commands when changing GPIO statuses 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -o $(PKG_BUILD_DIR)/$(PKG_NAME) $(PKG_BUILD_DIR)/hisi_gpio_watcher.c 39 | endef 40 | 41 | define Package/$(PKG_NAME)/install 42 | $(INSTALL_DIR) $(1)/usr/bin 43 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 44 | endef 45 | 46 | $(eval $(call BuildPackage,$(PKG_NAME))) 47 | -------------------------------------------------------------------------------- /utils/xmdp/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=xmdp 11 | PKG_VERSION:=0.1 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Dmitry Ilyin 14 | 15 | include $(INCLUDE_DIR)/package.mk 16 | 17 | PKG_LICENSE:=MIT 18 | PKG_LICENSE_FILES:=LICENSE 19 | 20 | define Package/$(PKG_NAME) 21 | SECTION:=openipc 22 | CATEGORY:=OpenIPC 23 | SUBMENU:=Utils 24 | TITLE:=Utility for finding devices that support the NETIP protocol 25 | MAINTAINER:=Dmitry Ilyin 26 | endef 27 | 28 | define Package/$(PKG_NAME)/description 29 | Utility for finding devices that support the NETIP protocol 30 | endef 31 | 32 | define Build/Prepare 33 | $(INSTALL_DIR) $(PKG_BUILD_DIR) 34 | $(CP) ./src/* $(PKG_BUILD_DIR)/ 35 | endef 36 | 37 | define Build/Compile 38 | $(TARGET_CC) $(TARGET_CFLAGS) $(TARGET_LDFLAGS) -O -g -D LINUX -std=c99 -Wall -Wpedantic -lm -o $(PKG_BUILD_DIR)/$(PKG_NAME) \ 39 | $(PKG_BUILD_DIR)/xmdp.c $(PKG_BUILD_DIR)/netip.c $(PKG_BUILD_DIR)/utils.c $(PKG_BUILD_DIR)/cjson/cJSON.c 40 | endef 41 | 42 | define Package/$(PKG_NAME)/install 43 | $(INSTALL_DIR) $(1)/usr/bin 44 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 45 | endef 46 | 47 | $(eval $(call BuildPackage,$(PKG_NAME))) 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## OpenIPC packages 2 | 3 | New packages feed **futurum** for IP cameras and NVRs based on the HiSilicon (and other) SoC's 4 | 5 | More information about project on our website [https://openipc.org](https://openipc.org) 6 | 7 | ![GitHub repo size](https://img.shields.io/github/repo-size/OpenIPC/packages) 8 | ![GitHub issues](https://img.shields.io/github/issues/OpenIPC/packages) 9 | ![GitHub pull requests](https://img.shields.io/github/issues-pr/OpenIPC/packages) 10 | [![License](https://img.shields.io/github/license/OpenIPC/packages)](https://opensource.org/licenses/MIT) 11 | 12 | ----- 13 | 14 | ### Supporting 15 | 16 | If you like our work, please consider supporting us on [Open Collective](https://opencollective.com/openipc/contribute/backer-14335/checkout). 17 | 18 | [![Backers](https://opencollective.com/openipc/tiers/backer/badge.svg?label=backer&color=brightgreen)](https://opencollective.com/openipc) 19 | [![Backers](https://opencollective.com/openipc/tiers/badge.svg)](https://opencollective.com/openipc) 20 | 21 | [![Backers](https://opencollective.com/openipc/tiers/backer.svg?avatarHeight=36)](https://opencollective.com/openipc#support) 22 | 23 | ### Thanks a lot !!! 24 | 25 |

26 | OpenCollective donate button 27 |

28 | 29 | ----- 30 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/model/cbi/admin_ipcam/mini_snmpd.lua: -------------------------------------------------------------------------------- 1 | local fs = require "nixio.fs" 2 | local sys = require "luci.sys" 3 | 4 | m = Map("snmpd", translate("Mini_snmpd"), 5 | translate("Mini_snmpd offers a SNMP server. You can configure the settings for it here.")) 6 | 7 | s = m:section(TypedSection, "snmpd", "") 8 | s.anonymous = true 9 | s.addremove = false 10 | s.reset = false 11 | 12 | t = s:option(Flag, "enable", translate("Enable"), 13 | translate("Specifies if the SNMP server is enabled or disabled")) 14 | t.enabled = "1" 15 | t.disabled = "0" 16 | t.default = t.enabled 17 | t.rmempty = false 18 | 19 | l = s:option(Value, "location", translate("Location"), 20 | translate("Specifies the SNMP server location reply")) 21 | l.default = "World" 22 | 23 | d = s:option(Value, "disk", translate("Disk"), 24 | translate("Specifies the location to store SNMP temporary files")) 25 | d.default = "/overlay,/tmp" 26 | 27 | 28 | t = s:option(Value, "timeout", translate("Timeout"), 29 | translate("Specifies the timeout for SNMP queries to the server")) 30 | t.default = "1" 31 | 32 | c = s:option(Value, "community", translate("Community"), 33 | translate("Specifies the SNMP server read/write community")) 34 | c.default = "public" 35 | 36 | c2 = s:option(Value, "contact", translate("Contact"), 37 | translate("Specifies the SNMP server contact reply")) 38 | c2.default = "OpenIPC" 39 | 40 | i = s:option(Value, "interface", translate("Interface"), 41 | translate("Specifies the SNMP server listening interface, eth0 by default")) 42 | i.widget = "radio" 43 | i.template = "cbi/network_ifacelist" 44 | 45 | return m -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_format_f2fs.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 51 | 52 | 53 | <%+cbi/valuefooter%> 54 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/sdcard_format_vfat.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 3 | 51 | 52 | 53 | <%+cbi/valuefooter%> 54 | -------------------------------------------------------------------------------- /utils/ipctool/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (C) 2013-2021 OpenIPC.org 3 | # 4 | # This is free software, licensed under the MIT License. 5 | # See /LICENSE for more information. 6 | # 7 | 8 | include $(TOPDIR)/rules.mk 9 | 10 | PKG_NAME:=ipctool 11 | PKG_VERSION:=master 12 | PKG_RELEASE:=latest 13 | PKG_MAINTAINER:=Dmitry Ilyin 14 | 15 | PKG_LICENSE:=MIT 16 | PKG_LICENSE_FILES:=LICENSE 17 | 18 | PKG_SOURCE_PROTO:=git 19 | PKG_SOURCE_URL:=https://github.com/OpenIPC/ipctool.git 20 | PKG_SOURCE_VERSION:=3c21f3c914b5f55fee9243a517f22b47ee3eeb24 21 | #PKG_SOURCE_VERSION:=360ba07038af31d3f9c64fee44d88086c92e6676 22 | #PKG_SOURCE_VERSION:=04b2eec1f6d2cbb053548257836e6a7bbebf9d93 23 | #PKG_SOURCE_VERSION:=84b48c5035795de5233b354e843d30f58a1e8bc4 24 | #PKG_SOURCE_VERSION:=7e523a84b054a122245039b7b32e67bf0995ba8f 25 | 26 | PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION) 27 | PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) 28 | PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz 29 | 30 | include $(INCLUDE_DIR)/package.mk 31 | include $(INCLUDE_DIR)/cmake.mk 32 | 33 | define Package/$(PKG_NAME) 34 | SECTION:=openipc 35 | CATEGORY:=OpenIPC 36 | SUBMENU:=Utils 37 | TITLE:=New util for get info from IPCamera SoCs 38 | MAINTAINER:=Dmitry Ilyin 39 | DEPENDS:=@(TARGET_hi35xx) 40 | endef 41 | 42 | define Package/$(PKG_NAME)/description 43 | New util for get info from IPCamera (Hisi) SoCs 44 | endef 45 | 46 | CMAKE_OPTIONS += -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DSKIP_VERSION=ON 47 | 48 | define Build/Prepare 49 | (cd $(PKG_BUILD_DIR) && tar --strip-components 1 -xvzf $(DL_DIR)/$(PKG_SOURCE)) 50 | endef 51 | 52 | define Package/$(PKG_NAME)/install 53 | $(INSTALL_DIR) $(1)/usr/bin 54 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME) $(1)/usr/bin/ 55 | $(INSTALL_BIN) $(PKG_BUILD_DIR)/ipcinfo $(1)/usr/bin/ 56 | 57 | endef 58 | 59 | $(eval $(call BuildPackage,$(PKG_NAME))) 60 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/README.md: -------------------------------------------------------------------------------- 1 | # luci-app-ipcam2 2 | ### About: 3 | 4 | Original package from [luci-app-config](https://github.com/ZigFisher/Glutinium/tree/master/luci-app-ipcam) by @ZigFisher. Modified to configure OpenIPC settings, view OpenIPC service information, etc. 5 | 6 | This should be considered a beta extension! 7 | 8 | ### Download 9 | 10 | Download the luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk release [here](https://github.com/randysbytes/luci-app-ipcam2/releases/download/v2.0/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk) or clone this repository to your OpenIPC source code directory. 11 | 12 | ### Installation 13 | 14 | First download the ipk package or build it from source and transfer it to the /tmp/ directoy of your OpenIPC camera using scp. 15 | 16 | `# scp luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk root@OpenIPC_CAMERAIP:/tmp/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk` 17 | 18 | If the package luci-app-ipcam is installed on OpenIPC, remove it by running this command on your camera. 19 | 20 | `# opkg remove luci-app-ipcam` 21 | 22 | Now run the opkg install process on your camera. 23 | 24 | `# opkg install /tmp/luci-app-ipcam2_2021-04-21-2.0_hi35xx.ipk` 25 | 26 | Now from your OpenIPC camera you can use the IPCam menu in luci. 27 | 28 | ### Configuration 29 | 30 | Due to the default configuration having comments in it and the way the configuration is parsed in lua, some settings with the default /etc/majestic.yaml configuration may have comments in them or white space's, if you wish to get rid of this, it is suggested you restore the configuration on the Reset/Edit tab of the settings page, you will lose any configuration changes you have made to your majestic.yaml configuration and a "cleaned" configuration will be written. 31 | 32 | If for some reason you need to remove this application and want to restore the the default majestic configuration yaml, run the following command. 33 | 34 | `# cp /rom/etc/majestic.yaml /etc/majestic.yaml` 35 | 36 | ### Screenshots 37 | 38 | **![IPCam Settings](https://github.com/randysbytes/luci-app-ipcam2/blob/main/docs/img/ipcam2_settings.jpg)** 39 | 40 | **![IPCam Services](https://github.com/randysbytes/luci-app-ipcam2/blob/main/docs/img/ipcam2_services.jpg)** 41 | 42 | **![IPCam Mini SNMPd](https://github.com/randysbytes/luci-app-ipcam2/blob/main/docs/img/ipcam2_minisnmpd.jpg)** 43 | 44 | **![IPCam SDCard Settings](https://github.com/randysbytes/luci-app-ipcam2/blob/main/docs/img/ipcam2_sdcardsettings.jpg)** 45 | 46 | **![IPCam FileBrowser](https://github.com/randysbytes/luci-app-ipcam2/blob/main/docs/img/ipcam2_filebrowser.jpg)** 47 | -------------------------------------------------------------------------------- /utils/xmdp/src/netip.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "cjson/cJSON.h" 11 | #include "netip.h" 12 | #include "utils.h" 13 | 14 | #define PACKED __attribute__((packed)) 15 | 16 | #define OP_LOGIN 1000 17 | #define OP_SYSINFO 1020 18 | 19 | #define RESULT_OK 100 20 | #define RESULT_UNKNOWN_ERROR 101 21 | #define RESULT_INCORRECT_PWD 203 22 | 23 | typedef struct netip_preabmle { 24 | uint8_t head; 25 | uint8_t version; 26 | uint16_t unused; 27 | uint32_t session; 28 | uint32_t sequence; 29 | uint8_t total; 30 | uint8_t cur; 31 | uint16_t msgid; 32 | uint32_t len_data; 33 | char data[]; 34 | } PACKED netip_preabmle_t; 35 | 36 | #define MAX_UDP_PACKET_SIZE 0xFFFF 37 | 38 | typedef union netip_pkt { 39 | char buf[MAX_UDP_PACKET_SIZE]; 40 | netip_preabmle_t header; 41 | } netip_pkt_t; 42 | 43 | #define NETIP_HSIZE sizeof(netip_preabmle_t) 44 | #define NETIP_MAX_JSON sizeof(resp) - NETIP_HSIZE - 1 45 | 46 | bool netip_connect(const char *addr, uint16_t port) { 47 | bool res = true; 48 | 49 | int s = socket(AF_INET, SOCK_STREAM, 0); 50 | if (s == -1) 51 | return false; 52 | 53 | struct sockaddr_in srv; 54 | srv.sin_addr.s_addr = inet_addr(addr); 55 | srv.sin_family = AF_INET; 56 | srv.sin_port = htons(port); 57 | 58 | if (connect(s, (struct sockaddr *)&srv, sizeof(srv)) < 0) 59 | return false; 60 | 61 | netip_pkt_t msg; 62 | memset(&msg.header, 0, sizeof(msg.header)); 63 | msg.header.head = 0xff; 64 | msg.header.msgid = OP_LOGIN; 65 | const char default_login[] = 66 | "{\"EncryptType\": \"MD5\", \"LoginType\": \"DVRIP-Web\", \"PassWord\": " 67 | "\"tlJwpbo6\", \"UserName\": \"admin\"}\n\0"; 68 | strcpy(msg.header.data, default_login); 69 | msg.header.len_data = sizeof(default_login); 70 | 71 | if (send(s, &msg, sizeof(default_login) + NETIP_HSIZE, 0) < 0) { 72 | puts("Send failed"); 73 | return false; 74 | } 75 | 76 | if (recv(s, &msg, sizeof(msg), 0) <= NETIP_HSIZE) { 77 | puts("recv failed"); 78 | } 79 | 80 | cJSON *json = cJSON_Parse(msg.header.data); 81 | if (!json) { 82 | const char *error_ptr = cJSON_GetErrorPtr(); 83 | if (error_ptr != NULL) { 84 | fprintf(stderr, "Error before: %s\n", error_ptr); 85 | } 86 | res = false; 87 | goto skip_loop; 88 | } 89 | const int retval = get_json_intval(json, "Ret", 0); 90 | if (retval != RESULT_OK) 91 | return false; 92 | 93 | skip_loop: 94 | cJSON_Delete(json); 95 | 96 | return res; 97 | } 98 | -------------------------------------------------------------------------------- /utils/memdump/src/memdump.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | unsigned long parse_int (char *str); 12 | 13 | void dumphex(const void* data, size_t size) { 14 | char ascii[17]; 15 | size_t i, j; 16 | ascii[16] = '\0'; 17 | for (i = 0; i < size; ++i) { 18 | printf("%02X ", ((unsigned char*)data)[i]); 19 | if (((unsigned char*)data)[i] >= ' ' && ((unsigned char*)data)[i] <= '~') { 20 | ascii[i % 16] = ((unsigned char*)data)[i]; 21 | } else { 22 | ascii[i % 16] = '.'; 23 | } 24 | if ((i+1) % 8 == 0 || i+1 == size) { 25 | printf(" "); 26 | if ((i+1) % 16 == 0) { 27 | printf("| %s \n", ascii); 28 | } else if (i+1 == size) { 29 | ascii[(i+1) % 16] = '\0'; 30 | if ((i+1) % 16 <= 8) { 31 | printf(" "); 32 | } 33 | for (j = (i+1) % 16; j < 16; ++j) { 34 | printf(" "); 35 | } 36 | printf("| %s \n", ascii); 37 | } 38 | } 39 | } 40 | } 41 | 42 | int main (int argc, char *argv[]) { 43 | unsigned long addr, length; 44 | 45 | int devmem; 46 | void *mapping; 47 | 48 | long page_size; 49 | off_t map_base, extra_bytes; 50 | 51 | char *buf; 52 | ssize_t ret; 53 | 54 | if (argc != 3) { 55 | fprintf(stderr, "Usage: %s ADDR LENGTH\n", argv[0]); 56 | exit(EXIT_FAILURE); 57 | } 58 | 59 | addr = parse_int(argv[1]); 60 | length = parse_int(argv[2]); 61 | 62 | devmem = open("/dev/mem", O_RDONLY); 63 | if (devmem == -1) { 64 | perror("Could not open /dev/mem"); 65 | goto open_fail; 66 | } 67 | 68 | page_size = sysconf(_SC_PAGE_SIZE); 69 | map_base = addr & ~(page_size - 1); 70 | extra_bytes = addr - map_base; 71 | 72 | mapping = mmap(NULL, length + extra_bytes, PROT_READ, MAP_SHARED, 73 | devmem, map_base); 74 | if (mapping == MAP_FAILED) { 75 | perror("Could not map memory"); 76 | goto map_fail; 77 | } 78 | 79 | buf = malloc(length); 80 | if (buf == NULL) { 81 | fprintf(stderr, "Failed to allocate memory\n"); 82 | goto alloc_fail; 83 | } 84 | 85 | memcpy(buf, (char *)mapping + extra_bytes, length); 86 | 87 | dumphex(buf,length); 88 | 89 | free(buf); 90 | 91 | alloc_fail: 92 | munmap(mapping, length + extra_bytes); 93 | 94 | map_fail: 95 | close(devmem); 96 | 97 | open_fail: 98 | return EXIT_SUCCESS; 99 | } 100 | 101 | unsigned long parse_int (char *str) { 102 | long long result; 103 | char *endptr; 104 | 105 | result = strtoll(str, &endptr, 0); 106 | if (str == '\0' || *endptr != '\0') { 107 | fprintf(stderr, "\"%s\" is not a valid number\n", str); 108 | exit(EXIT_FAILURE); 109 | } 110 | 111 | return (unsigned long)result; 112 | } 113 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/ipcam.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.ipcam", package.seeall) 2 | 3 | util = require "luci.util" 4 | 5 | 6 | function index() 7 | 8 | entry({"admin", "ipcam"}, alias("admin", "ipcam", "settings"), _("IPCam"), 55).index = true 9 | 10 | entry({"admin", "ipcam", "sdcard_settings"}, cbi("admin_ipcam/sdcard_settings"), _("SD Card Settings"), 11) 11 | 12 | entry({"admin", "ipcam", "sdcard_status"}, call("action_sdcard_status")) 13 | 14 | entry({"admin", "ipcam", "sdcard_format_f2fs"}, call("action_sdcard_format_f2fs")) 15 | 16 | entry({"admin", "ipcam", "sdcard_format_vfat"}, call("action_sdcard_format_vfat")) 17 | 18 | entry({"admin", "ipcam", "test_mail"}, call("action_send_mail")) 19 | 20 | end 21 | 22 | 23 | function sdcard_present() 24 | return (os.execute("mount |grep mmcblk0") == 0) 25 | end 26 | 27 | 28 | function action_sdcard_status() 29 | local sd_status = "detecting..." 30 | if( sdcard_present() == true ) then 31 | sd_status = util.exec("df -h /dev/mmcblk0|awk '/mmc/ {print $4}'") 32 | end 33 | luci.http.prepare_content("application/json") 34 | luci.http.write_json({ sdstring = sd_status }) 35 | 36 | end 37 | 38 | 39 | function action_sdcard_format_f2fs() 40 | if( sdcard_present() == true ) then 41 | os.execute("echo dd if=/dev/zero of=/dev/mmcblk0 bs=4M count=1 ; mkfs.f2fs -l IPCam /dev/mmcblk0") 42 | luci.http.status(200, "Formated") 43 | end 44 | end 45 | 46 | function action_sdcard_format_vfat() 47 | if( sdcard_present() == true ) then 48 | os.execute("echo dd if=/dev/zero of=/dev/mmcblk0 bs=4M count=1 ; mkfs.vfat -v -n IPCam /dev/mmcblk0") 49 | luci.http.status(200, "Formated") 50 | end 51 | end 52 | 53 | 54 | function create_temp_file(from, rcpt, subject) 55 | local jiji = os.tmpname() 56 | local f = io.open(jiji, "w+") 57 | 58 | f:write("From: "..from.."\nTo: "..rcpt.."\nSubject: "..subject.."\n\n Hello from IPCam!\n") 59 | f:close() 60 | return jiji 61 | end 62 | 63 | 64 | function action_send_mail() 65 | local server = (luci.http.formvalue("server")) 66 | local sender = (luci.http.formvalue("sender")) 67 | local password = (luci.http.formvalue("password")) 68 | local rcpt = (luci.http.formvalue("rcpt")) 69 | local subject = (luci.http.formvalue("subject")) 70 | local port = tonumber(luci.http.formvalue("port")) 71 | local auth = (luci.http.formvalue("auth")) 72 | 73 | temp_file = create_temp_file(sender, rcpt, subject) 74 | if( auth == "true") then 75 | os.execute("curl --url \'"..server..":"..port.."\' --ssl-reqd --mail-from \'"..sender.."\' --mail-rcpt \'"..rcpt.."\' --upload-file "..temp_file.." --user \'"..sender..":"..password.."\' --insecure"); 76 | else 77 | os.execute("curl --url \'"..server..":"..port.."\' --ssl-reqd --mail-from \'"..sender.."\' --mail-rcpt \'"..rcpt.."\' --upload-file "..temp_file.." --insecure"); 78 | end 79 | os.execute("rm "..temp_file.."") 80 | 81 | end 82 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/LIP.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | Copyright (c) 2012 Carreras Nicolas 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | --]] 22 | --- Lua INI Parser. 23 | -- It has never been that simple to use INI files with Lua. 24 | --@author Dynodzzo 25 | 26 | local LIP = {}; 27 | 28 | --- Returns a table containing all the data from the INI file. 29 | --@param fileName The name of the INI file to parse. [string] 30 | --@return The table containing all data from the INI file. [table] 31 | function LIP.load(fileName) 32 | assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.'); 33 | local file = assert(io.open(fileName, 'r'), 'Error loading file : ' .. fileName); 34 | local data = {}; 35 | local section; 36 | for line in file:lines() do 37 | local tempSection = line:match('^%[([^%[%]]+)%]$'); 38 | if(tempSection)then 39 | section = tonumber(tempSection) and tonumber(tempSection) or tempSection; 40 | data[section] = data[section] or {}; 41 | end 42 | line = line:gsub("^[;]", "", 1) 43 | local param, value = line:match('^([%w|_]+)%s-=%s-(.+)$'); 44 | if(param and value ~= nil)then 45 | if(tonumber(value))then 46 | value = tonumber(value); 47 | elseif(value == 'true')then 48 | value = true; 49 | elseif(value == 'false')then 50 | value = false; 51 | end 52 | if(tonumber(param))then 53 | param = tonumber(param); 54 | end 55 | data[section][param] = value; 56 | end 57 | end 58 | file:close(); 59 | return data; 60 | end 61 | 62 | --- Saves all the data from a table to an INI file. 63 | --@param fileName The name of the INI file to fill. [string] 64 | --@param data The table containing all the data to store. [table] 65 | function LIP.save(fileName, data) 66 | assert(type(fileName) == 'string', 'Parameter "fileName" must be a string.'); 67 | assert(type(data) == 'table', 'Parameter "data" must be a table.'); 68 | local file = assert(io.open(fileName, 'w+b'), 'Error loading file :' .. fileName); 69 | local contents = ''; 70 | for section, param in pairs(data) do 71 | contents = contents .. ('[%s]\n'):format(section); 72 | for key, value in pairs(param) do 73 | contents = contents .. ('%s=%s\n'):format(key, tostring(value)); 74 | end 75 | contents = contents .. '\n'; 76 | end 77 | file:write(contents); 78 | file:close(); 79 | end 80 | 81 | return LIP; -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/range.htm: -------------------------------------------------------------------------------- 1 | <%+cbi/valueheader%> 2 | 97 |
98 | > 99 | 0 100 |
101 | 102 | 123 | 124 | <%+cbi/valuefooter%> 125 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/service.htm: -------------------------------------------------------------------------------- 1 | <% 2 | local util = require "luci.util" 3 | local ntm = require "luci.model.network".init() 4 | local LIP = require 'luci.LIP' 5 | local wan = ntm:get_wannet() 6 | 7 | local ps = luci.util.exec("/bin/busybox pgrep majestic") 8 | local pstext 9 | if ps == "" then 10 | pstext = "/usr/bin/majestic not running" 11 | else 12 | pstext = "/usr/bin/majestic running as pid "..ps 13 | end 14 | 15 | if wan then 16 | host_ipaddr = wan:ipaddr() 17 | end 18 | 19 | tbl = LIP.load('/etc/majestic.yaml') 20 | host_webport = tbl['system']['web_port'] 21 | host_rtspport = tbl['rtsp']['port'] 22 | 23 | ns = luci.util.exec("netstat -p |grep majestic | tr ':' ' ' | awk -F ' ' '{print $5,$6}'") 24 | nstbl = {} 25 | nstbl_i = 1 26 | for line in ns:gmatch '[^\n]+' do 27 | fstbl = {} 28 | fstbl_i = 1 29 | for fs in line:gmatch '%S+' do 30 | fstbl[fstbl_i] = fs 31 | fstbl_i = fstbl_i + 1 32 | end 33 | nstbl[nstbl_i] = {clientip = fstbl[2], port = fstbl[1]} 34 | nstbl_i = nstbl_i + 1 35 | end 36 | 37 | %> 38 | 39 | <%+header%> 40 | 41 |

Majestic Service

42 | 43 |
44 | Service Status 45 |
This shows you the status of the Majestic service and provides control over starting, stopping, restarting the service.
46 | 47 | 48 | 49 | 50 | 51 | 60 | 61 | 62 |
ProcessControl
52 | <%=pstext%> 53 | 54 |
"> 55 | 56 | 57 | 58 |
59 |
63 |
64 | 65 |
66 | Access URL's 67 |
You access Majestic's services via the URLs provided below.
68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 |
MJPEG & MP3 streamhttp://<%=host_ipaddr%>:<%=host_webport%>
JPEGhttp://<%=host_ipaddr%>:<%=host_webport%>/image.jpg
JPEG Optionshttp://<%=host_ipaddr%>:<%=host_webport%>/image.jpg?width=640&height=360&qfactor=73&color2gray=1
RAW (only for 16cv300/16ev100 and better processor)http://<%=host_ipaddr%>:<%=host_webport%>/image.dng
MJPEG Embeddedhttp://<%=host_ipaddr%>:<%=host_webport%>/mjpeg.html
H264 Embeddedhttp://<%=host_ipaddr%>:<%=host_webport%>/video.html
MJPEGhttp://<%=host_ipaddr%>:<%=host_webport%>/mjpeg
H264http://<%=host_ipaddr%>:<%=host_webport%>/video.mp4
MP3http://<%=host_ipaddr%>:<%=host_webport%>/stream.mp3
RTSP Demortsp://<%=host_ipaddr%>:<%=host_rtspport%>/demo
RTSP Stream 9rtsp://<%=host_ipaddr%>:<%=host_rtspport%>/stream=0
RTSP Stream 1rtsp://<%=host_ipaddr%>:<%=host_rtspport%>/stream=1
83 |
84 | 85 |
86 | Activate Connections 87 |
This shows active clients connected to Majestic.
88 |
89 | 90 | 91 | 92 | 93 | 94 | <% for index, data in pairs(nstbl) do %> 95 | 96 | <% for value, value2 in pairs(data) do %> 97 | 100 | <% end %> 101 | <% end %> 102 |
Service/PortClient IP
98 | <%=value2%> 99 |
103 |
104 |
105 | 106 | <%+footer%> -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/controller/admin/filebrowser2.lua: -------------------------------------------------------------------------------- 1 | module("luci.controller.admin.filebrowser2", package.seeall) 2 | 3 | local root_path = "/mnt" 4 | 5 | function index() 6 | 7 | page = entry({"admin", "ipcam", "filebrowser"}, template("admin_ipcam/filebrowser"), _("File Browser"), 1) 8 | page.i18n = "base" 9 | page.dependent = true 10 | 11 | page = entry({"admin", "ipcam", "filebrowser_list"}, call("filebrowser_list"), nil) 12 | page.leaf = true 13 | 14 | page = entry({"admin", "ipcam", "filebrowser_open"}, call("filebrowser_open"), nil) 15 | page.leaf = true 16 | 17 | page = entry({"admin", "ipcam", "filebrowser_delete"}, call("filebrowser_delete"), nil) 18 | page.leaf = true 19 | 20 | page = entry({"admin", "ipcam", "filebrowser_rename"}, call("filebrowser_rename"), nil) 21 | page.leaf = true 22 | 23 | page = entry({"admin", "ipcam", "filebrowser_upload"}, call("filebrowser_upload"), nil) 24 | page.leaf = true 25 | 26 | end 27 | 28 | function filebrowser_list() 29 | local rv = { } 30 | local path = root_path..luci.http.formvalue("path"):gsub("%.%.", "") 31 | 32 | rv = scandir(path) 33 | 34 | if #rv > 0 then 35 | luci.http.prepare_content("application/json") 36 | luci.http.write_json(rv) 37 | return 38 | end 39 | 40 | end 41 | 42 | function filebrowser_open(file, filename) 43 | filename = filename:gsub("%.%.", "") 44 | file = root_path..file:gsub("%.%.", ""):gsub("<>", "/") 45 | 46 | local io = require "io" 47 | local mime = to_mime(filename) 48 | 49 | local download_fpi = io.open(file, "r") 50 | luci.http.header('Content-Disposition', 'inline; filename="'..filename..'"' ) 51 | luci.http.prepare_content(mime or "application/octet-stream") 52 | luci.ltn12.pump.all(luci.ltn12.source.file(download_fpi), luci.http.write) 53 | end 54 | 55 | function filebrowser_delete() 56 | local path = root_path..luci.http.formvalue("path"):gsub("%.%.", "") 57 | local isdir = luci.http.formvalue("isdir") 58 | path = path:gsub("<>", "/") 59 | path = path:gsub(" ", "\ ") 60 | if isdir then 61 | local success = os.execute('rm -r "'..path..'"') 62 | else 63 | local success = os.remove(path) 64 | end 65 | return success 66 | end 67 | 68 | function filebrowser_rename() 69 | local filepath = root_path..luci.http.formvalue("filepath"):gsub("%.%.", "") 70 | local newpath = root_path..luci.http.formvalue("newpath"):gsub("%.%.", "") 71 | local success = os.execute('mv "'..filepath..'" "'..newpath..'"') 72 | return success 73 | end 74 | 75 | function filebrowser_upload() 76 | local filecontent = luci.http.formvalue("upload-file") 77 | local filename = luci.http.formvalue("upload-filename") 78 | local uploaddir = root_path..luci.http.formvalue("upload-dir"):gsub("%.%.", "") 79 | local filepath = uploaddir..filename 80 | local url = luci.dispatcher.build_url('admin', 'ipcam', 'filebrowser') 81 | 82 | --[[ 83 | local fp 84 | fp = io.open(filepath, "w") 85 | fp:write(filecontent) 86 | fp:close() 87 | ]] 88 | 89 | luci.http.redirect(url..'?path='..luci.http.formvalue("upload-dir")) 90 | 91 | --[[luci.http.setfilehandler( 92 | function(meta, chunk, eof) 93 | uci.http.write('open '..filepath) 94 | if not fp then 95 | if meta and meta.name == 'upload-file' then 96 | --luci.http.write('open file '..filepath) 97 | fp = io.open(filepath, "w") 98 | end 99 | end 100 | if fp and chunk then 101 | --luci.http.write(chunk) 102 | fp:write(chunk) 103 | end 104 | if fp and eof then 105 | --luci.http.write('close') 106 | fp:close() 107 | luci.http.redirect(url..'?path='..uploaddir) 108 | end 109 | end 110 | )]]-- 111 | end 112 | 113 | function scandir(directory) 114 | local i, t, popen = 0, {}, io.popen 115 | 116 | local ls_cmd = "ls -l \""..directory.."\" | egrep '^d' ; ls -lh \""..directory.."\" | egrep -v '^d'" 117 | 118 | local pfile = popen(ls_cmd) 119 | for filename in pfile:lines() do 120 | i = i + 1 121 | t[i] = filename 122 | end 123 | pfile:close() 124 | return t 125 | end 126 | 127 | MIME_TYPES = { 128 | ["txt"] = "text/plain"; 129 | ["js"] = "text/javascript"; 130 | ["css"] = "text/css"; 131 | ["htm"] = "text/html"; 132 | ["html"] = "text/html"; 133 | ["patch"] = "text/x-patch"; 134 | ["c"] = "text/x-csrc"; 135 | ["h"] = "text/x-chdr"; 136 | ["o"] = "text/x-object"; 137 | ["ko"] = "text/x-object"; 138 | 139 | ["bmp"] = "image/bmp"; 140 | ["gif"] = "image/gif"; 141 | ["png"] = "image/png"; 142 | ["jpg"] = "image/jpeg"; 143 | ["jpeg"] = "image/jpeg"; 144 | ["svg"] = "image/svg+xml"; 145 | 146 | ["zip"] = "application/zip"; 147 | ["pdf"] = "application/pdf"; 148 | ["xml"] = "application/xml"; 149 | ["xsl"] = "application/xml"; 150 | ["doc"] = "application/msword"; 151 | ["ppt"] = "application/vnd.ms-powerpoint"; 152 | ["xls"] = "application/vnd.ms-excel"; 153 | ["odt"] = "application/vnd.oasis.opendocument.text"; 154 | ["odp"] = "application/vnd.oasis.opendocument.presentation"; 155 | ["pl"] = "application/x-perl"; 156 | ["sh"] = "application/x-shellscript"; 157 | ["php"] = "application/x-php"; 158 | ["deb"] = "application/x-deb"; 159 | ["iso"] = "application/x-cd-image"; 160 | ["tgz"] = "application/x-compressed-tar"; 161 | 162 | ["mp3"] = "audio/mpeg"; 163 | ["ogg"] = "audio/x-vorbis+ogg"; 164 | ["wav"] = "audio/x-wav"; 165 | 166 | ["mpg"] = "video/mpeg"; 167 | ["mpeg"] = "video/mpeg"; 168 | ["avi"] = "video/x-msvideo"; 169 | } 170 | 171 | function to_mime(filename) 172 | if type(filename) == "string" then 173 | local ext = filename:match("[^%.]+$") 174 | 175 | if ext and MIME_TYPES[ext:lower()] then 176 | return MIME_TYPES[ext:lower()] 177 | end 178 | end 179 | 180 | return "application/octet-stream" 181 | end 182 | -------------------------------------------------------------------------------- /utils/xmdp/src/xmdp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "cjson/cJSON.h" 15 | #include "netip.h" 16 | #include "utils.h" 17 | 18 | #define SERVERPORT 34569 19 | // send broadcast packets periodically 20 | #define TIMEOUT 5 // seconds 21 | 22 | #define MIN(x, y) ((x) < (y) ? (x) : (y)) 23 | 24 | const char brpkt[] = 25 | "\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfa\x05" 26 | "\x00\x00\x00\x00"; 27 | static const char *Reset = "\x1b[0m"; 28 | static const char *FgRed = "\x1b[31m"; 29 | 30 | // get sockaddr, IPv4 or IPv6: 31 | void *get_in_addr(struct sockaddr *sa) { 32 | if (sa->sa_family == AF_INET) { 33 | return &(((struct sockaddr_in *)sa)->sin_addr); 34 | } 35 | 36 | return &(((struct sockaddr_in6 *)sa)->sin6_addr); 37 | } 38 | 39 | int ipaddr_from32bit(char *dst, size_t dlen, const char *coded) { 40 | if (strlen(coded) != 10) 41 | return -1; 42 | 43 | unsigned char octet[4]; 44 | char cnvt[5] = "0x01"; 45 | for (int i = 0; i < sizeof(octet); i++) { 46 | cnvt[2] = coded[i * 2 + 2]; 47 | cnvt[3] = coded[i * 2 + 3]; 48 | sscanf(cnvt, "%hhx", &octet[i]); 49 | } 50 | 51 | snprintf(dst, dlen, "%d.%d.%d.%d", octet[3], octet[2], octet[1], octet[0]); 52 | 53 | return 0; 54 | } 55 | 56 | int bsock; 57 | 58 | void send_netip_broadcast() { 59 | struct sockaddr_in sa; 60 | memset(sa.sin_zero, '\0', sizeof sa.sin_zero); 61 | 62 | sa.sin_family = AF_INET; 63 | sa.sin_addr.s_addr = 0xffffffff; 64 | sa.sin_port = htons(SERVERPORT); 65 | 66 | int rcvbts; 67 | if ((rcvbts = sendto(bsock, brpkt, sizeof(brpkt) - 1, 0, 68 | (struct sockaddr *)&sa, sizeof(struct sockaddr_in))) == 69 | -1) { 70 | perror("sendto"); 71 | exit(1); 72 | } 73 | } 74 | 75 | void sigalarm(int sig) { 76 | if (sig == SIGALRM) { 77 | send_netip_broadcast(); 78 | alarm(TIMEOUT); 79 | } 80 | } 81 | 82 | int main() { 83 | bsock = socket(AF_INET, SOCK_DGRAM, 0); 84 | if (bsock == -1) { 85 | perror("socket"); 86 | exit(1); 87 | } 88 | 89 | struct sockaddr_in name; 90 | name.sin_family = AF_INET; 91 | name.sin_port = htons(SERVERPORT); 92 | name.sin_addr.s_addr = htonl(INADDR_ANY); 93 | if (bind(bsock, (struct sockaddr *)&name, sizeof(name)) < 0) { 94 | perror("bind"); 95 | exit(EXIT_FAILURE); 96 | } 97 | 98 | // this call is what allows broadcast packets to be sent: 99 | int broadcast = 1; 100 | if (setsockopt(bsock, SOL_SOCKET, SO_BROADCAST, &broadcast, 101 | sizeof broadcast) == -1) { 102 | perror("setsockopt (SO_BROADCAST)"); 103 | exit(1); 104 | } 105 | 106 | send_netip_broadcast(); 107 | 108 | printf("Searching for XM cameras... Abort with CTRL+C.\n\n" 109 | "IP\t\tMAC-Address\t\tIdentity\n"); 110 | 111 | signal(SIGALRM, sigalarm); 112 | alarm(TIMEOUT); 113 | 114 | size_t seen_len = 0; 115 | size_t seen_cap = 1; 116 | uint32_t *seen_vec = malloc(seen_cap * sizeof(*seen_vec)); 117 | 118 | while (1) { 119 | char buf[1024]; 120 | struct sockaddr_in their_addr; 121 | socklen_t addr_len = sizeof their_addr; 122 | int rcvbts; 123 | if ((rcvbts = recvfrom(bsock, buf, sizeof buf - 1, 0, 124 | (struct sockaddr *)&their_addr, &addr_len)) == -1) { 125 | perror("recvfrom"); 126 | exit(1); 127 | } 128 | if (rcvbts <= sizeof brpkt) 129 | continue; 130 | 131 | buf[rcvbts] = '\0'; 132 | 133 | cJSON *json = cJSON_Parse(buf + 20); 134 | if (!json) { 135 | const char *error_ptr = cJSON_GetErrorPtr(); 136 | if (error_ptr != NULL) { 137 | fprintf(stderr, "Error before: %s\n", error_ptr); 138 | } 139 | goto skip_loop; 140 | } 141 | #if 0 142 | char *str = cJSON_Print(json); 143 | if (str) { 144 | puts(str); 145 | } 146 | free(str); 147 | #endif 148 | 149 | const cJSON *netcommon = 150 | cJSON_GetObjectItemCaseSensitive(json, "NetWork.NetCommon"); 151 | const char *hostname = get_json_strval(netcommon, "HostName", ""); 152 | const char *mac = get_json_strval(netcommon, "MAC", ""); 153 | const char *host_ip = get_json_strval(netcommon, "HostIP", ""); 154 | const int netip_port = get_json_intval(netcommon, "TCPPort", 0); 155 | const int chan_num = get_json_intval(netcommon, "ChannelNum", 0); 156 | const char *sn = get_json_strval(netcommon, "SN", ""); 157 | const char *version = get_json_strval(netcommon, "Version", ""); 158 | const char *builddt = get_json_strval(netcommon, "BuildDate", ""); 159 | 160 | uint32_t numipv4; 161 | if (sscanf(host_ip, "0x%x", &numipv4) == 1) { 162 | // find occurence 163 | for (int i = 0; i < seen_len; i++) 164 | if (seen_vec[i] == numipv4) 165 | goto skip_loop; 166 | if (seen_len == seen_cap) { 167 | seen_cap *= 2; 168 | seen_vec = realloc(seen_vec, seen_cap * sizeof(*seen_vec)); 169 | } 170 | seen_vec[seen_len++] = numipv4; 171 | } 172 | 173 | char abuf[50] = {0}; 174 | if (strlen(host_ip)) { 175 | ipaddr_from32bit(abuf, sizeof abuf, host_ip); 176 | host_ip = abuf; 177 | } 178 | bool netip_ok = netip_connect(host_ip, netip_port); 179 | 180 | char verstr[128] = {0}; 181 | if (strlen(version)) { 182 | int n_dot = 0, i = 0; 183 | while (*version) { 184 | if (*version == '.') { 185 | n_dot++; 186 | if (n_dot == 4) 187 | break; 188 | } else if (n_dot == 3) { 189 | verstr[i++] = *version; 190 | } 191 | version++; 192 | } 193 | 194 | if (strlen(builddt)) { 195 | const char *end; 196 | if ((end = strchr(builddt, ' '))) { 197 | strcat(verstr + strlen(verstr), " ("); 198 | snprintf(verstr + strlen(verstr), 199 | MIN(sizeof(verstr) - strlen(verstr), end - builddt + 1), 200 | "%s", builddt); 201 | strcat(verstr + strlen(verstr), ")"); 202 | } 203 | } 204 | } 205 | 206 | printf("%s%s\t%s\t%s %s, %s", netip_ok ? FgRed : "", host_ip, mac, 207 | chan_num > 1 ? "DVR" : "IPC", sn, hostname); 208 | if (strlen(verstr)) 209 | printf("\t%s", verstr); 210 | printf("%s\n", netip_ok ? Reset : ""); 211 | 212 | skip_loop: 213 | 214 | cJSON_Delete(json); 215 | } 216 | 217 | free(seen_vec); 218 | } 219 | -------------------------------------------------------------------------------- /utils/luci-app-ipcam2/luasrc/view/admin_ipcam/filebrowser.htm: -------------------------------------------------------------------------------- 1 | <%+header%> 2 | 3 | 150 | 151 | 208 | 209 |

File browser

210 | 211 |
212 | Files list: 213 |
214 |
215 | 227 | <%+footer%> 228 | -------------------------------------------------------------------------------- /utils/hisi_gpio_scanner/src/hisi_gpio_scanner.c.bak: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | typedef struct tag_MMAP_Node { 10 | unsigned int Start_P; 11 | unsigned int Start_V; 12 | unsigned int length; 13 | unsigned int refcount; 14 | struct tag_MMAP_Node *next; 15 | } TMMAP_Node_t; 16 | 17 | TMMAP_Node_t *pTMMAPNode = NULL; 18 | #define PAGE_SIZE 0x1000 19 | #define PAGE_SIZE_MASK 0xfffff000 20 | 21 | static int fd = -1; 22 | static const char dev[] = "/dev/mem"; 23 | jmp_buf *sigbus_jmp; 24 | 25 | //************************************************************ 26 | void *memmap(unsigned long phy_addr, unsigned long size) { 27 | unsigned long phy_addr_in_page; 28 | unsigned long page_diff; 29 | unsigned long size_in_page; 30 | unsigned long value = 0; 31 | TMMAP_Node_t *pTmp; 32 | TMMAP_Node_t *pNew; 33 | void *addr = NULL; 34 | if (size == 0) { 35 | printf("memmap():size can't be zero!\n"); 36 | return NULL; 37 | } 38 | /* проверить, было ли преобразовано пространство физической памяти */ 39 | pTmp = pTMMAPNode; 40 | while (pTmp != NULL) { 41 | if ((phy_addr >= pTmp->Start_P) && 42 | ((phy_addr + size) <= (pTmp->Start_P + pTmp->length))) { 43 | pTmp->refcount++; /* referrence count increase by 1 */ 44 | return (void *)(pTmp->Start_V + phy_addr - pTmp->Start_P); 45 | } 46 | pTmp = pTmp->next; 47 | } 48 | /* not mmaped yet */ 49 | if (fd < 0) { 50 | /* dev not opened yet, so open it */ 51 | fd = open(dev, O_RDWR | O_SYNC); 52 | if (fd < 0) { 53 | printf("memmap():open %s error!\n", dev); 54 | return NULL; 55 | } 56 | } 57 | /* addr align in page_size(4K) */ 58 | phy_addr_in_page = phy_addr & PAGE_SIZE_MASK; 59 | page_diff = phy_addr - phy_addr_in_page; 60 | /* size in page_size */ 61 | size_in_page = ((size + page_diff - 1) & PAGE_SIZE_MASK) + PAGE_SIZE; 62 | addr = mmap((void *)0, size_in_page, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 63 | phy_addr_in_page); 64 | if (addr == MAP_FAILED) { 65 | printf("memmap():mmap @ 0x%lx error!\n", phy_addr_in_page); 66 | return NULL; 67 | } 68 | /* add this mmap to MMAP Node */ 69 | pNew = (TMMAP_Node_t *)malloc(sizeof(TMMAP_Node_t)); 70 | if (NULL == pNew) { 71 | printf("memmap():malloc new node failed!\n"); 72 | return NULL; 73 | } 74 | pNew->Start_P = phy_addr_in_page; 75 | pNew->Start_V = (unsigned long)addr; 76 | pNew->length = size_in_page; 77 | pNew->refcount = 1; 78 | pNew->next = NULL; 79 | if (pTMMAPNode == NULL) { 80 | pTMMAPNode = pNew; 81 | } else { 82 | pTmp = pTMMAPNode; 83 | while (pTmp->next != NULL) { 84 | pTmp = pTmp->next; 85 | } 86 | pTmp->next = pNew; 87 | } 88 | return (void *)(addr + page_diff); 89 | } 90 | 91 | #define DEFAULT_MD_LEN 256 92 | //************************************************************ 93 | unsigned long GetValueRegister(unsigned long adress) { 94 | void *pMem = NULL; 95 | unsigned long value = -1; 96 | jmp_buf sigbus_jmpbuf; 97 | sigbus_jmp = &sigbus_jmpbuf; 98 | if (sigsetjmp(sigbus_jmpbuf, 1) == 0) { 99 | pMem = memmap(adress, DEFAULT_MD_LEN); 100 | if (pMem == NULL) { 101 | printf("memmap failed!\n"); 102 | return -1; 103 | } 104 | value = *(unsigned int *)pMem; //читаем региср 105 | } 106 | return value; 107 | } 108 | 109 | //************************************************************ 110 | int SetValueRegister(unsigned long adress, unsigned long value) { 111 | void *pMem = NULL; 112 | pMem = memmap(adress, DEFAULT_MD_LEN); 113 | if (pMem == NULL) { 114 | printf("memmap failed!\n"); 115 | return -1; 116 | } 117 | *(unsigned int *)pMem = value; //пишем в регистр 118 | return 0; 119 | } 120 | 121 | //************************************************************ 122 | void print_bin(unsigned long data) { 123 | int i; 124 | unsigned long ulbit; 125 | for (i = 7; i >= 0; i--) { 126 | ulbit = data >> i; 127 | if (ulbit & 1) 128 | printf("1"); 129 | else 130 | printf("0"); 131 | } 132 | } 133 | 134 | //************************************************************ 135 | void get_gpio_adress(unsigned long *Chip_Id, unsigned long *GPIO_Groups, 136 | unsigned long *GPIO_Base, unsigned long *GPIO_Offset) { 137 | switch (*Chip_Id) { 138 | //------------------------------------------- 139 | // Hi3516Av100 A7 @600 MHz 140 | case 0x3516A100: 141 | *GPIO_Groups = 17; //пропустить G15 142 | *GPIO_Base = 0x20140000; 143 | *GPIO_Offset = 0x10000; 144 | break; 145 | //------------------------------------------- 146 | // Hi3516Cv100 ARM926 @440 MHz 147 | case 0x3516C100: 148 | *GPIO_Groups = 12; 149 | *GPIO_Base = 0x20140000; 150 | *GPIO_Offset = 0x10000; 151 | break; 152 | //------------------------------------------- 153 | // Hi3516Cv200 ARM926 @540 MHz 154 | case 0x3516C200: 155 | *GPIO_Groups = 9; 156 | *GPIO_Base = 0x20140000; 157 | *GPIO_Offset = 0x10000; 158 | break; 159 | //------------------------------------------- 160 | // Hi3516Cv300 ARM926 @800 161 | case 0x3516C300: 162 | *GPIO_Groups = 9; 163 | *GPIO_Base = 0x12140000; 164 | *GPIO_Offset = 0x1000; 165 | break; 166 | //------------------------------------------- 167 | // Hi3516Dv100 A7 @600 MHz 168 | case 0x3516D100: 169 | *GPIO_Groups = 15; 170 | *GPIO_Base = 0x20140000; 171 | *GPIO_Offset = 0x10000; 172 | break; 173 | //------------------------------------------- 174 | // Hi3516Ev200 A7 @900MHz 175 | case 0x3516E200: 176 | *GPIO_Groups = 9; 177 | *GPIO_Base = 0x120B0000; 178 | *GPIO_Offset = 0x1000; 179 | break; 180 | //------------------------------------------- 181 | // Hi3516Ev300 A7 @900MHz 182 | case 0x3516E300: 183 | *GPIO_Groups = 10; 184 | *GPIO_Base = 0x120B0000; 185 | *GPIO_Offset = 0x1000; 186 | break; 187 | //------------------------------------------- 188 | // Hi3518Ev100 ARM926 @440 MHz 189 | case 0x35180100: 190 | *GPIO_Groups = 12; 191 | *GPIO_Base = 0x20140000; 192 | *GPIO_Offset = 0x10000; 193 | break; 194 | //------------------------------------------- 195 | // Hi3518Ev200 ARM926 @540 MHz 196 | case 0x3518E200: 197 | *GPIO_Groups = 9; 198 | *GPIO_Base = 0x20140000; 199 | *GPIO_Offset = 0x10000; 200 | break; 201 | //------------------------------------------- 202 | // Hi3518Ev201 ARM926 @540 MHz 203 | case 0x3518E201: 204 | *GPIO_Groups = 9; 205 | *GPIO_Base = 0x20140000; 206 | *GPIO_Offset = 0x10000; 207 | break; 208 | //------------------------------------------- 209 | default: 210 | *GPIO_Groups = 0; 211 | *GPIO_Base = 0; 212 | *GPIO_Offset = 0; 213 | break; 214 | //--------------------------------- 215 | } 216 | } 217 | //************************************************************ 218 | int main() { 219 | unsigned long Chip_Id; 220 | unsigned long GPIO_Groups, GPIO_Base, GPIO_Offset; 221 | unsigned long address = 0; 222 | unsigned long direct = 0; 223 | unsigned long value = 0; 224 | unsigned long OldValue[20]; 225 | int bit, old_bit, new_bit; 226 | int i, group, mask; 227 | //--------------------------------------------------------------- 228 | Chip_Id = 0x3516E200; 229 | printf("========== Hisilicon GPIO Scaner (2020) Andrew_kmr - OpenIPC.org " 230 | "collective ==========\n"); 231 | printf("Chip_Id: 0x%08lX\n", Chip_Id); 232 | printf("---------------------------------------------------------------------" 233 | "-----------------\n"); 234 | get_gpio_adress(&Chip_Id, &GPIO_Groups, &GPIO_Base, &GPIO_Offset); 235 | if (GPIO_Base == 0) { 236 | printf("This CPU is not supported!\n"); 237 | return 0; 238 | } 239 | for (group = 0; group < GPIO_Groups; group++) { 240 | address = GPIO_Base + (group * GPIO_Offset) + 0x3fc; //регистр данных портов 241 | value = GetValueRegister(address); //регистр данных портов 242 | OldValue[group] = value; //запоминаем в массив значение 243 | printf("Gr:%2d, Addr:0x%08lX, Data:0x%02lX = 0b", group, address, value); 244 | print_bin(value); //выводим бинарный вид 245 | address = 246 | GPIO_Base + (group * GPIO_Offset) + 0x400; //регистр направления портов 247 | direct = GetValueRegister(address); 248 | printf(", Addr:0x%08lX, Dir:0x%02lX = 0b", address, direct); 249 | print_bin(direct); 250 | printf("\n"); 251 | } 252 | printf("While change value...\n"); 253 | while (1) { 254 | for (group = 0; group < GPIO_Groups; group++) { 255 | address = 256 | GPIO_Base + (group * GPIO_Offset) + 0x3fc; //регистр данных портов 257 | value = GetValueRegister(address); 258 | if (OldValue[group] != value) //старый и новый байты не равны 259 | { 260 | printf("---------------------------------------------------------------" 261 | "-----------------------\n"); 262 | printf("Gr:%d, Addr:0x%08lX, Data:0x%02lX = 0b", group, address, 263 | OldValue[group]); 264 | print_bin(OldValue[group]); 265 | printf(" --> 0x%02lX = 0b", value); 266 | print_bin(value); 267 | printf("\n"); 268 | for (bit = 7; bit >= 0; bit--) //цикл побитного сравнения 269 | { 270 | old_bit = (OldValue[group] >> bit) & 1; 271 | new_bit = (value >> bit) & 1; 272 | if (old_bit != new_bit) { 273 | address = GPIO_Base + (group * GPIO_Offset) + 274 | 0x400; //регистр направления портов 275 | direct = GetValueRegister(address); 276 | direct = (direct >> bit) & 277 | 1; //получили бит направления порта 0-вход 1-выход 278 | address = GPIO_Base + (group * GPIO_Offset) + (1 << (bit + 2)); 279 | if (direct == 1) { 280 | mask = value & 1 << bit; 281 | printf("Mask: \"himm 0x%08lX 0x%02X\", GPIO%d_%d, GPIO%d, " 282 | "Dir:Output, Level:%d\n", 283 | address, mask, group, bit, (group * 8) + bit, new_bit); 284 | } else { 285 | mask = value & 1 << bit; 286 | printf("Mask: \"himm 0x%08lX 0x%02X\", GPIO%d_%d, GPIO%d, " 287 | "Dir:Input, Level:%d\n", 288 | address, mask, group, bit, (group * 8) + bit, new_bit); 289 | } 290 | } 291 | } 292 | OldValue[group] = value; //запоминаем новое значение 293 | } 294 | } 295 | usleep(100000); 296 | } 297 | return 0; 298 | } 299 | -------------------------------------------------------------------------------- /utils/hisi_gpio_watcher/src/hisi_gpio_watcher.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define SYSFS_GPIO_DIR "/sys/class/gpio" 11 | #define MAX_BUF 64 12 | 13 | //#define DEBUG_ENABLE 0 //debug 1 14 | 15 | #define DEFAULT_MD_LEN 128 16 | #define PAGE_SIZE 0x1000 17 | #define PAGE_SIZE_MASK (~(0xfff)) 18 | 19 | int debug; 20 | 21 | typedef struct tag_MMAP_Node 22 | { 23 | unsigned long Start_P; 24 | unsigned long Start_V; 25 | unsigned long length; 26 | unsigned long refcount; 27 | struct tag_MMAP_Node * next; 28 | }TMMAP_Node_t; 29 | 30 | TMMAP_Node_t * pTMMAPNode = NULL; 31 | int fd = -1; 32 | const char dev[]="/dev/mem"; 33 | jmp_buf *sigbus_jmp; // global 34 | 35 | /**************************************************************** 36 | * signal_handler 37 | ****************************************************************/ 38 | void signal_handler (int sig) 39 | { 40 | if (sig == SIGBUS) 41 | { 42 | //printf("signal_handler SIGBUS!\n"); 43 | if(sigbus_jmp) siglongjmp(*sigbus_jmp, 1); 44 | // no one to catch the error, so abort 45 | abort(); 46 | } 47 | } 48 | /**************************************************************** 49 | * set_handle 50 | ****************************************************************/ 51 | int set_handler() 52 | { 53 | struct sigaction act; 54 | memset (&act, 0, sizeof(act)); 55 | act.sa_sigaction = (void *)signal_handler; 56 | act.sa_flags = SA_SIGINFO; 57 | if (sigaction(SIGBUS, &act, 0)) 58 | { 59 | perror ("sigaction"); 60 | return -1; 61 | } 62 | return 0; 63 | } 64 | /**************************************************************** 65 | * memmap 66 | ****************************************************************/ 67 | void * memmap(unsigned long phy_addr, unsigned long size) 68 | { 69 | unsigned long phy_addr_in_page; 70 | unsigned long page_diff; 71 | unsigned long size_in_page; 72 | unsigned long value = 0; 73 | TMMAP_Node_t * pTmp; 74 | TMMAP_Node_t * pNew; 75 | void *addr=NULL; 76 | if(size == 0) 77 | { 78 | printf("memmap():size can't be zero!\n"); 79 | return NULL; 80 | } 81 | /* check if the physical memory space have been mmaped */ 82 | pTmp = pTMMAPNode; 83 | while(pTmp != NULL) 84 | { 85 | if( (phy_addr >= pTmp->Start_P) && ( (phy_addr + size) <= (pTmp->Start_P + pTmp->length) ) ) 86 | { 87 | pTmp->refcount++; /* referrence count increase by 1 */ 88 | return (void *)(pTmp->Start_V + phy_addr - pTmp->Start_P); 89 | } 90 | pTmp = pTmp->next; 91 | } 92 | /* not mmaped yet */ 93 | if(fd < 0) 94 | { 95 | /* dev not opened yet, so open it */ 96 | fd = open (dev, O_RDONLY); 97 | if(fd < 0) 98 | { 99 | printf("memmap():open %s error!\n", dev); 100 | return NULL; 101 | } 102 | } 103 | /* addr align in page_size(4K) */ 104 | phy_addr_in_page = phy_addr & PAGE_SIZE_MASK; 105 | page_diff = phy_addr - phy_addr_in_page; 106 | /* size in page_size */ 107 | size_in_page =((size + page_diff - 1) & PAGE_SIZE_MASK) + PAGE_SIZE; 108 | addr = mmap((void *)0, size_in_page, PROT_READ, MAP_SHARED, fd, phy_addr_in_page); 109 | if(addr == MAP_FAILED) 110 | { 111 | printf("memmap():mmap @ 0x%x error!\n", phy_addr_in_page); 112 | return NULL; 113 | } 114 | /* add this mmap to MMAP Node */ 115 | pNew = (TMMAP_Node_t *)malloc(sizeof(TMMAP_Node_t)); 116 | if(NULL == pNew) 117 | { 118 | printf("memmap():malloc new node failed!\n"); 119 | return NULL; 120 | } 121 | pNew->Start_P = phy_addr_in_page; 122 | pNew->Start_V = (unsigned long)addr; 123 | pNew->length = size_in_page; 124 | pNew->refcount = 1; 125 | pNew->next = NULL; 126 | if(pTMMAPNode == NULL) 127 | { 128 | pTMMAPNode = pNew; 129 | } 130 | else 131 | { 132 | pTmp = pTMMAPNode; 133 | while(pTmp->next != NULL) 134 | { 135 | pTmp = pTmp->next; 136 | } 137 | pTmp->next = pNew; 138 | } 139 | return (void *)(addr+page_diff); 140 | } 141 | /**************************************************************** 142 | * GetValueRegister 143 | ****************************************************************/ 144 | unsigned long GetValueRegister(unsigned long adress) 145 | { 146 | void *pMem = NULL; 147 | unsigned long value = -1; 148 | jmp_buf sigbus_jmpbuf; 149 | sigbus_jmp = &sigbus_jmpbuf; 150 | if(sigsetjmp(sigbus_jmpbuf, 1) == 0) 151 | { 152 | pMem = memmap(adress,DEFAULT_MD_LEN); 153 | if (pMem == NULL) 154 | { 155 | printf("memmap failed!\n"); 156 | return -1; 157 | } 158 | value = *(unsigned int*)pMem; 159 | } 160 | return value; 161 | } 162 | /**************************************************************** 163 | * parse_int 164 | ****************************************************************/ 165 | unsigned long parse_int (char *str) { 166 | long long result; 167 | char *endptr; 168 | 169 | result = strtoll(str, &endptr, 0); 170 | if (str == '\0' || *endptr != '\0') { 171 | fprintf(stderr, "\"%s\" is not a valid number\n", str); 172 | exit(EXIT_FAILURE); 173 | } 174 | 175 | return (unsigned long)result; 176 | } 177 | 178 | /**************************************************************** 179 | * gpio_get_value 180 | ****************************************************************/ 181 | int gpio_get_value(unsigned int gpio, unsigned long *value) 182 | { 183 | int fd, len; 184 | char buf[MAX_BUF]; 185 | char ch; 186 | 187 | len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/value", gpio); 188 | 189 | fd = open(buf, O_RDONLY | O_NONBLOCK); 190 | if (fd < 0) { 191 | perror("gpio/get-value"); 192 | return fd; 193 | } 194 | 195 | read(fd, &ch, 1); 196 | 197 | if (ch != '0') { 198 | *value = 1; 199 | } else { 200 | *value = 0; 201 | } 202 | 203 | close(fd); 204 | return 0; 205 | } 206 | /**************************************************************** 207 | * gpio_get_dir 208 | ****************************************************************/ 209 | int gpio_get_dir(unsigned int gpio, unsigned long *value) 210 | { 211 | int fd, len, i; 212 | char buf[MAX_BUF]; 213 | char ch[5]; 214 | 215 | len = snprintf(buf, sizeof(buf), SYSFS_GPIO_DIR "/gpio%d/direction", gpio); 216 | 217 | 218 | fd = open(buf, O_RDONLY | O_NONBLOCK); 219 | if (fd < 0) { 220 | perror("gpio/direction"); 221 | return fd; 222 | } 223 | i = read(fd, ch, 5); 224 | ch[i] = 0; 225 | 226 | 227 | if(!strncmp("in",ch,2)){*value = 0;} 228 | else if(!strncmp("out",ch,2)){*value = 1;} 229 | else {*value = -1;} 230 | 231 | close(fd); 232 | return 0; 233 | } 234 | /**************************************************************** 235 | * check_run 236 | ****************************************************************/ 237 | void check_run(unsigned char *runsh, int chkbit, int chkstat, int chkdirect) 238 | { 239 | if (chkbit==chkstat) 240 | { 241 | if(debug) 242 | { 243 | if (chkdirect==1) {printf("Direction: Output\n");} else {printf("Direction: Input\n");} 244 | printf("Check Level:%d Current Level:%d\n",chkstat,chkbit); 245 | printf("Run Script: %s\n", runsh);} 246 | system (runsh); 247 | 248 | } 249 | else if (chkstat==-1) 250 | { 251 | if(debug) 252 | { 253 | if (chkdirect==1) {printf("Direction: Output\n");} else {printf("Direction: Input\n");} 254 | printf("Check Level:%d Current Level:%d\n",chkstat,chkbit); 255 | printf("Run Script: %s\n", runsh);} 256 | system (runsh); 257 | 258 | } 259 | } 260 | /****************************************************************************** 261 | * show usage 262 | ******************************************************************************/ 263 | void show_sage(char *sPrgNm, int usgc) 264 | { 265 | const char gpiou[]="Usage : %s GPIO(gpioN) Status(on|off|both) 'Programm_run'.\n"; 266 | const char memu[]="Usage : %s GPIO_Base GPIO_Offset GPIO_Group GPIO_Bit Status(on|off|both) 'Programm_run'.\n"; 267 | 268 | switch (usgc) 269 | { 270 | case 1: 271 | printf(memu,sPrgNm); 272 | break; 273 | case 2: 274 | printf(gpiou,sPrgNm); 275 | break; 276 | default: 277 | printf(memu,sPrgNm); 278 | printf(gpiou,sPrgNm); 279 | exit(EXIT_FAILURE); 280 | } 281 | } 282 | 283 | //************************************************************ 284 | //************************************************************ 285 | //************************************************************ 286 | /**************************************************************** 287 | * main 288 | ****************************************************************/ 289 | int main(int argc, char *argv[]) 290 | { 291 | unsigned int gpio; 292 | int sfs = 0; 293 | char *stat = NULL; 294 | char *cmd = NULL; 295 | unsigned long GPIO_Base, GPIO_Offset; 296 | unsigned long adress = 0; 297 | unsigned long direct = 0; 298 | unsigned long value = 0; 299 | unsigned long OldValue= 0; 300 | int GPIO_Group, GPIO_Bit, old_bit, new_bit, status; 301 | 302 | if(set_handler()==-1) 303 | { 304 | printf("Set handler Error!\n"); 305 | return 0; 306 | } 307 | 308 | if ( (argc < 2)) 309 | { 310 | show_sage(argv[0], 0); 311 | exit(EXIT_FAILURE); 312 | } 313 | 314 | debug = (argv[0][strlen(argv[0])-1])- '0'; //debug ON 315 | if ((debug) == 1){ printf("Debug ON!\n"); } 316 | 317 | 318 | if ((sscanf (argv[1], "gpio%d", &gpio) == 1) || (!strncmp("gpio",argv[1],4))) 319 | { 320 | if (argc != 4) { 321 | show_sage(argv[0], 2); 322 | exit(EXIT_FAILURE);} 323 | 324 | sfs = 1; 325 | stat = malloc(strlen(argv[2])); 326 | strcpy(stat, argv[2]); //Status_on|off|both 327 | cmd = malloc(strlen(argv[3])); 328 | strcpy(cmd, argv[3]); //Programm_run 329 | gpio_get_value(gpio, &OldValue); //Save current value 330 | } 331 | else 332 | { 333 | if (argc != 7) { 334 | show_sage(argv[0], 1); 335 | exit(EXIT_FAILURE);} 336 | 337 | GPIO_Base=parse_int(argv[1]); //GPIO_Base 338 | GPIO_Offset=parse_int(argv[2]); //GPIO_Offset 339 | GPIO_Group=atoi(argv[3]); //GPIO_Group 340 | GPIO_Bit = atoi(argv[4]); //GPIO_Bit 341 | stat = malloc(strlen(argv[5])); 342 | strcpy(stat, argv[5]); //Status_on|off|both 343 | cmd = malloc(strlen(argv[6])); 344 | strcpy(cmd, argv[6]); //Programm_run 345 | } 346 | //Status 347 | if(!strcmp("on",stat)){status = 1;} //on = 1 348 | else if(!strcmp("off",stat)){status = 0;} //off = 0 349 | else if(!strcmp("both",stat)){status = -1;} //both = -1 (The script is executed twice) 350 | else {status = -1;} 351 | 352 | 353 | while(1) 354 | { 355 | if (sfs == 0) 356 | { 357 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+0x3fc; 358 | value = GetValueRegister(adress); 359 | } 360 | else { 361 | gpio_get_value(gpio, &value); 362 | } 363 | 364 | if(OldValue!=value) 365 | { 366 | if (sfs == 0){ 367 | old_bit = (OldValue>>GPIO_Bit)&1; 368 | new_bit = (value>>GPIO_Bit)&1; 369 | 370 | if(old_bit!=new_bit) 371 | { 372 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+0x400; 373 | direct = GetValueRegister(adress); 374 | direct = (direct>>GPIO_Bit)&1; 375 | adress=GPIO_Base+(GPIO_Group*GPIO_Offset)+(1<