mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-10-29 20:25:13 +08:00
update 2026-05-10 09:48:30
This commit is contained in:
1 parent
95ac96413e
commit
0b362674f1
6244 files changed
+2992248
No files matched your search
@@ -0,0 +1,56 @@
|
||||
#
|
||||
# Copyright (C) 2015-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=LingTiGameAcc
|
||||
PKG_VERSION:=2023
|
||||
PKG_RELEASE:=1.7.1
|
||||
|
||||
PKG_LICENSE:=GPLv3
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_MAINTAINER:=eSir Playground
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
CATEGORY:=eSir Playground
|
||||
SUBMENU:=2. GameAcc
|
||||
TITLE:=LingTi Game Accelerator
|
||||
URL:=https://github.com/esirplayground/LingTiGameAcc
|
||||
DEPENDS:=+kmod-tun
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
LingTi Game Acc is a Game Accelerator which is paid service.
|
||||
endef
|
||||
|
||||
DIR_ARCH:=$(ARCH)
|
||||
|
||||
define Build/Prepare
|
||||
mkdir $(PKG_BUILD_DIR)/$(PKG_NAME)
|
||||
cp -r ./files/$(DIR_ARCH)/* $(PKG_BUILD_DIR)/$(PKG_NAME)/lingti
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/$(PKG_NAME)/lingti $(1)/usr/bin
|
||||
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./root/etc/init.d/lingti $(1)/etc/init.d
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/postinst
|
||||
#!/bin/sh
|
||||
chmod +x $(1)/usr/bin/lingti
|
||||
chmod +x $(1)/etc/init.d/lingti
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
@@ -0,0 +1,3 @@
|
||||
# LingTiGameAcc
|
||||
|
||||
This Tools can be functioning `independently` without luci app.
|
||||
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
|
||||
[ -d /var/bin ] || mkdir -p /var/bin
|
||||
[ -f /var/bin/lingti ] || cp /usr/bin/lingti /var/bin/lingti
|
||||
|
||||
start() {
|
||||
state=`pgrep -f "/var/bin/lingti"`
|
||||
if [ ! -z "$state" ]; then
|
||||
restart
|
||||
else
|
||||
/var/bin/lingti &
|
||||
fi
|
||||
echo "LingTiGameAcc Started..."
|
||||
}
|
||||
|
||||
stop() {
|
||||
kill -9 `pgrep -f "/var/bin/lingti"` 2>/dev/null
|
||||
echo "LingTiGameAcc Stopped ..."
|
||||
}
|
||||
|
||||
restart() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
echo "Restarted."
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
# SPDX-Identifier-License: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=UnblockNeteaseMusic-Go
|
||||
PKG_VERSION:=0.2.13
|
||||
PKG_RELEASE:=$(AUTORELEASE)
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/cnsilvan/UnblockNeteaseMusic/tar.gz/$(PKG_VERSION)?
|
||||
PKG_HASH:=92201b7f04ab1015c806c672b98a29b97d0f137d9b60e6d35d279c2064ed86a4
|
||||
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
PKG_LICENSE_FILE:=LICENSE
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
PKG_CONFIG_DEPENDS:= \
|
||||
CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_GOPROXY \
|
||||
CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_UPX
|
||||
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(firstword $(subst -, ,$(PKG_NAME)))-$(PKG_VERSION)
|
||||
PKG_BUILD_DEPENDS:=golang/host upx/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
|
||||
GO_PKG:=github.com/cnsilvan/UnblockNeteaseMusic
|
||||
GO_PKG_BUILD_PKG:=$$(GO_PKG)
|
||||
GO_PKG_LDFLAGS:=-s -w
|
||||
COMPILE_TIME:= $(shell TZ=UTC-8 date '+%Y-%m-%d %H:%M:%S')
|
||||
GO_PKG_LDFLAGS+= \
|
||||
-X '$(GO_PKG)/version.Version=$(PKG_VERSION)' \
|
||||
-X '$(GO_PKG)/version.BuildTime=$(COMPILE_TIME)' \
|
||||
-X '$(GO_PKG)/version.ExGoVersionInfo=$(GO_ARM) $(GO_MIPS)$(GO_MIPS64)'
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../../lang/golang/golang-package.mk
|
||||
|
||||
define Package/UnblockNeteaseMusic-Go/config
|
||||
config UNBLOCKNETEASEMUSIC_GO_COMPRESS_GOPROXY
|
||||
bool "Compiling with GOPROXY proxy"
|
||||
default n
|
||||
|
||||
config UNBLOCKNETEASEMUSIC_GO_COMPRESS_UPX
|
||||
bool "Compress executable files with UPX"
|
||||
depends on !mips64
|
||||
default n
|
||||
endef
|
||||
|
||||
ifeq ($(CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_GOPROXY),y)
|
||||
export GO111MODULE=on
|
||||
export GOPROXY=https://goproxy.io
|
||||
endif
|
||||
|
||||
define Package/UnblockNeteaseMusic-Go
|
||||
SECTION:=multimedia
|
||||
CATEGORY:=Multimedia
|
||||
TITLE:=Revive Netease Cloud Music (Golang)
|
||||
URL:=https://github.com/cnsilvan/UnblockNeteaseMusic
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(call GoPackage/Build/Compile)
|
||||
ifeq ($(CONFIG_UNBLOCKNETEASEMUSIC_GO_COMPRESS_UPX),y)
|
||||
$(STAGING_DIR_HOST)/bin/upx --lzma --best $(GO_PKG_BUILD_BIN_DIR)/UnblockNeteaseMusic
|
||||
endif
|
||||
endef
|
||||
|
||||
define Package/UnblockNeteaseMusic-Go/install
|
||||
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/UnblockNeteaseMusic $(1)/usr/bin/UnblockNeteaseMusic
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/UnblockNeteaseMusicGo
|
||||
$(CP) ./files/* $(1)/usr/share/UnblockNeteaseMusicGo/
|
||||
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,UnblockNeteaseMusic-Go))
|
||||
$(eval $(call BuildPackage,UnblockNeteaseMusic-Go))
|
||||
@@ -0,0 +1,14 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICIjCCAaigAwIBAgIUTc9HQDej5hLCQ74u436a5yE4MDcwCgYIKoZIzj0EAwMw
|
||||
SDELMAkGA1UEBhMCQ04xJDAiBgNVBAMMG1VuYmxvY2tOZXRlYXNlTXVzaWMgUm9v
|
||||
dCBDQTETMBEGA1UECgwKMTcxNTE3MzMyOTAeFw0yMTA0MzAwNzIzMDJaFw0yNjA0
|
||||
MjkwNzIzMDJaMEgxCzAJBgNVBAYTAkNOMSQwIgYDVQQDDBtVbmJsb2NrTmV0ZWFz
|
||||
ZU11c2ljIFJvb3QgQ0ExEzARBgNVBAoMCjE3MTUxNzMzMjkwdjAQBgcqhkjOPQIB
|
||||
BgUrgQQAIgNiAASIyI7lYgGlq49qWtY1O2/XNDeowYf7W/Z+l7C14bphxAJ9jSDo
|
||||
tLwbFPWy5VPENc0rB0/yeHA2z7LU67POL2gGgp+17y7scLkkBk3Q7wRMETrtP44Z
|
||||
ITBstZ0wzVyyQEKjUzBRMB0GA1UdDgQWBBQ2F7+t8cPHJaWuCD8RHTSdLugKYzAf
|
||||
BgNVHSMEGDAWgBQ2F7+t8cPHJaWuCD8RHTSdLugKYzAPBgNVHRMBAf8EBTADAQH/
|
||||
MAoGCCqGSM49BAMDA2gAMGUCMQDqaRX2e01e0U+f0As/KUKDhmG5ElkK5CjYK9jk
|
||||
kXLNGFXJLGta6CDvjtMLBPc20qkCMBvDs+JnJKVBEJNZVsRBBs+v2YxNU/u2aYJa
|
||||
dMwXuFveSDWOS7mBeRztX/geEggiSw==
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,15 @@
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICRDCCAcqgAwIBAgIUeVqRrT2mHG5Mc8JD+ErphiAmlgkwCgYIKoZIzj0EAwMw
|
||||
SDELMAkGA1UEBhMCQ04xJDAiBgNVBAMMG1VuYmxvY2tOZXRlYXNlTXVzaWMgUm9v
|
||||
dCBDQTETMBEGA1UECgwKMTcxNTE3MzMyOTAeFw0yMTA0MzAwNzIzMDJaFw0yMjA0
|
||||
MzAwNzIzMDJaMHsxCzAJBgNVBAYTAkNOMREwDwYDVQQHDAhIYW5nemhvdTEsMCoG
|
||||
A1UECgwjTmV0RWFzZSAoSGFuZ3pob3UpIE5ldHdvcmsgQ28uLCBMdGQxETAPBgNV
|
||||
BAsMCElUIERlcHQuMRgwFgYDVQQDDA8qLm11c2ljLjE2My5jb20wdjAQBgcqhkjO
|
||||
PQIBBgUrgQQAIgNiAAQTPyU9RQ1pAFMLmozi+c4pEC1rrxAlPGwO9Em+qV+a5qLW
|
||||
gQjjsJeabMqJ/UQ7hDtdKVxWuXiAjMiDcXwL63I71MZKPTAEKXdCmNQwb4kXvRUn
|
||||
oOR4r7BMxEpGlf0CULWjQjBAMBMGA1UdJQQMMAoGCCsGAQUFBwMBMCkGA1UdEQQi
|
||||
MCCCDW11c2ljLjE2My5jb22CDyoubXVzaWMuMTYzLmNvbTAKBggqhkjOPQQDAwNo
|
||||
ADBlAjEAs5bdgnNP/DiK919RiWscC0kyuY0ugG1C8m8F2Yod4MI3oTyrkVcag21o
|
||||
NSzm802uAjBoPuKEbjjFP4ics0BQdICiVd6WCVAsE69FnlmqRteAJqxvdKGpVLi+
|
||||
Qi3arfomrrc=
|
||||
-----END CERTIFICATE-----
|
||||
@@ -0,0 +1,9 @@
|
||||
-----BEGIN EC PARAMETERS-----
|
||||
BgUrgQQAIg==
|
||||
-----END EC PARAMETERS-----
|
||||
-----BEGIN EC PRIVATE KEY-----
|
||||
MIGkAgEBBDBfW3twxGaQmMzP9p0/UU5EvHFVCbBw4piVFJ+pm/uFY6CKZkC5LGMa
|
||||
Uc9vn/KiewGgBwYFK4EEACKhZANiAAQTPyU9RQ1pAFMLmozi+c4pEC1rrxAlPGwO
|
||||
9Em+qV+a5qLWgQjjsJeabMqJ/UQ7hDtdKVxWuXiAjMiDcXwL63I71MZKPTAEKXdC
|
||||
mNQwb4kXvRUnoOR4r7BMxEpGlf0CULU=
|
||||
-----END EC PRIVATE KEY-----
|
||||
@@ -0,0 +1,144 @@
|
||||
From f4f5d11b578a1ab2c3d089bbe5453052b43892bb Mon Sep 17 00:00:00 2001
|
||||
From: tofuliang <tofuliang@gmail.com>
|
||||
Date: Mon, 24 Jan 2022 18:53:11 +0800
|
||||
Subject: [PATCH] fix block ad,add web traffic logs
|
||||
|
||||
---
|
||||
app.go | 1 +
|
||||
config/config.go | 1 +
|
||||
processor/processor.go | 55 +++++++++++++++++++++++++++++++++---------
|
||||
3 files changed, 45 insertions(+), 12 deletions(-)
|
||||
|
||||
diff --git a/app.go b/app.go
|
||||
index 73a6070..1018d75 100644
|
||||
--- a/app.go
|
||||
+++ b/app.go
|
||||
@@ -45,6 +45,7 @@ func main() {
|
||||
log.Println("EnableLocalVip=", *config.EnableLocalVip)
|
||||
log.Println("UnlockSoundEffects=", *config.UnlockSoundEffects)
|
||||
log.Println("QQCookieFile=", *config.QQCookieFile)
|
||||
+ log.Println("LogWebTraffic=", *config.LogWebTraffic)
|
||||
if host.InitHosts() == nil {
|
||||
//go func() {
|
||||
// // // terminal: $ go tool pprof -http=:8081 http://localhost:6060/debug/pprof/heap
|
||||
diff --git a/config/config.go b/config/config.go
|
||||
index 6c07873..a653cdf 100644
|
||||
--- a/config/config.go
|
||||
+++ b/config/config.go
|
||||
@@ -31,6 +31,7 @@ var (
|
||||
EnableLocalVip = flag.Bool("lv", false, "enable local vip")
|
||||
UnlockSoundEffects = flag.Bool("sef", false, "unlock SoundEffects")
|
||||
QQCookieFile = flag.String("qc", "./qq.cookie", "specify cookies file ,such as : \"qq.cookie\"")
|
||||
+ LogWebTraffic = flag.Bool("wl", false, "log request url and response")
|
||||
)
|
||||
|
||||
func ValidParams() bool {
|
||||
diff --git a/processor/processor.go b/processor/processor.go
|
||||
index 8d09dbf..d07b9d3 100644
|
||||
--- a/processor/processor.go
|
||||
+++ b/processor/processor.go
|
||||
@@ -6,14 +6,6 @@ import (
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/cache"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/common"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/config"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/network"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/processor/crypto"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/provider"
|
||||
- "github.com/cnsilvan/UnblockNeteaseMusic/utils"
|
||||
- "golang.org/x/text/width"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@@ -22,6 +14,15 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
+
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/cache"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/common"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/config"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/network"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/processor/crypto"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/provider"
|
||||
+ "github.com/cnsilvan/UnblockNeteaseMusic/utils"
|
||||
+ "golang.org/x/text/width"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -188,6 +189,9 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
|
||||
if ok {
|
||||
code = codeN.String()
|
||||
}
|
||||
+
|
||||
+ logResponse(netease)
|
||||
+
|
||||
if strings.EqualFold(netease.Path, "/api/osx/version") {
|
||||
modified = disableUpdate(netease)
|
||||
} else if strings.Contains(netease.Path, "/usertool/sound/") {
|
||||
@@ -197,9 +201,24 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
|
||||
for key, resp := range netease.JsonBody {
|
||||
if strings.Contains(key, "/usertool/sound/") {
|
||||
modified = unblockSoundEffects(resp.(map[string]interface{}))
|
||||
- } else if *config.BlockAds && strings.Contains(netease.Path, "api/ad/") {
|
||||
+ } else if *config.BlockAds && strings.Contains(key, "api/ad/") {
|
||||
+ log.Println("block Ad has been triggered(" + key + ").")
|
||||
resp = &common.MapType{}
|
||||
modified = true
|
||||
+ } else if *config.BlockAds && strings.EqualFold(key, "/api/v2/banner/get") {
|
||||
+ newInfo := make(common.SliceType, 0)
|
||||
+ info := netease.JsonBody[key]
|
||||
+ for _, data := range info.(common.MapType)["banners"].(common.SliceType) {
|
||||
+ if banner, ok := data.(common.MapType); ok {
|
||||
+ if banner["adid"] == nil {
|
||||
+ newInfo = append(newInfo, banner)
|
||||
+ } else {
|
||||
+ log.Println("block banner Ad has been triggered.")
|
||||
+ modified = true
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ info.(common.MapType)["banners"] = newInfo
|
||||
}
|
||||
}
|
||||
} else if !netease.Web && (code == "401" || code == "512") && strings.Contains(netease.Path, "manipulate") {
|
||||
@@ -220,7 +239,9 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
|
||||
// log.Println("NeedRepackage")
|
||||
modifiedJson, _ := json.Marshal(netease.JsonBody)
|
||||
// log.Println(netease)
|
||||
- // log.Println(string(modifiedJson))
|
||||
+ if *config.LogWebTraffic {
|
||||
+ log.Println("modified =>\n" + string(modifiedJson))
|
||||
+ }
|
||||
if netease.Encrypted {
|
||||
modifiedJson = crypto.AesEncryptECB(modifiedJson, []byte(aeskey))
|
||||
}
|
||||
@@ -258,14 +279,24 @@ func disableUpdate(netease *Netease) bool {
|
||||
if len(value.(common.SliceType)) > 0 {
|
||||
modified = true
|
||||
jsonBody["updateFiles"] = make(common.SliceType, 0)
|
||||
+ log.Println("disable update has been triggered.")
|
||||
}
|
||||
default:
|
||||
}
|
||||
}
|
||||
- // modifiedJson, _ := json.Marshal(jsonBody)
|
||||
- // log.Println(string(modifiedJson))
|
||||
return modified
|
||||
}
|
||||
+
|
||||
+func logResponse(netease *Netease) {
|
||||
+ if *config.LogWebTraffic {
|
||||
+ reqUrl := netease.Path
|
||||
+ jsonBody := netease.JsonBody
|
||||
+ modifiedJson, _ := json.Marshal(jsonBody)
|
||||
+ sep := "===================================\n"
|
||||
+ log.Println(sep + reqUrl + " => \n" + string(modifiedJson) + "\n")
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
func localVIP(netease *Netease) bool {
|
||||
if !*config.EnableLocalVip {
|
||||
return false
|
||||
@@ -0,0 +1,29 @@
|
||||
From 6c009953d357d1cc03478cf65fc05701fb1966d6 Mon Sep 17 00:00:00 2001
|
||||
From: ameansone <ameansone@outlook.com>
|
||||
Date: Sun, 5 Dec 2021 19:18:20 +0800
|
||||
Subject: [PATCH] fix(processor): avoid unnecessary decryption
|
||||
|
||||
---
|
||||
processor/processor.go | 8 ++++++--
|
||||
1 file changed, 6 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/processor/processor.go b/processor/processor.go
|
||||
index 8d09dbf..011571b 100644
|
||||
--- a/processor/processor.go
|
||||
+++ b/processor/processor.go
|
||||
@@ -177,9 +177,13 @@ func RequestAfter(request *http.Request, response *http.Response, netease *Netea
|
||||
if netease.Forward {
|
||||
aeskey = linuxApiKey
|
||||
}
|
||||
- decryptECBBytes, encrypted := crypto.AesDecryptECB(decryptECBBytes, []byte(aeskey))
|
||||
- netease.Encrypted = encrypted
|
||||
result := utils.ParseJson(decryptECBBytes)
|
||||
+ netease.Encrypted = false;
|
||||
+ if result == nil {
|
||||
+ decryptECBBytes, encrypted := crypto.AesDecryptECB(decryptECBBytes, []byte(aeskey))
|
||||
+ netease.Encrypted = encrypted
|
||||
+ result = utils.ParseJson(decryptECBBytes)
|
||||
+ }
|
||||
netease.JsonBody = result
|
||||
|
||||
modified := false
|
||||
@@ -0,0 +1,47 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=UnblockNeteaseMusic
|
||||
PKG_VERSION:=0.28.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/UnblockNeteaseMusic/server/tar.gz/v${PKG_VERSION}?
|
||||
PKG_HASH:=0a1e843ffaa7b8ce65cc221daec07b63754473f0430019acb228f5b254602318
|
||||
|
||||
PKG_SOURCE_SUBDIR:=$(PKG_NAME)
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_SOURCE_SUBDIR)
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/UnblockNeteaseMusic
|
||||
SECTION:=multimedia
|
||||
CATEGORY:=Multimedia
|
||||
TITLE:=Revive Netease Cloud Music (NodeJS)
|
||||
URL:=https://github.com/nondanee/UnblockNeteaseMusic
|
||||
DEPENDS:=+node
|
||||
PKGARCH:=all
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
Revive Netease Cloud Music (NodeJS)
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
tar -xzvf $(DL_DIR)/$(PKG_SOURCE) -C $(PKG_BUILD_DIR)
|
||||
mkdir -p $(PKG_BUILD_DIR)/$(PKG_NAME)
|
||||
echo -e $(PKG_VERSION) > $(PKG_BUILD_DIR)/$(PKG_NAME)/core_ver
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(INSTALL_DIR) $(1)/usr/share/$(PKG_NAME)
|
||||
$(CP) $(PKG_BUILD_DIR)/$(PKG_NAME)/* $(1)/usr/share/$(PKG_NAME)
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
@@ -0,0 +1,77 @@
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=adguardhome
|
||||
PKG_VERSION:=0.107.51
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/AdguardTeam/AdGuardHome/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=dea9685282e55940925ff7211f7d72072de5b98134c8f01d5569c04284681650
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/AdGuardHome-$(PKG_VERSION)
|
||||
|
||||
PKG_LICENSE:=GPL-3.0-only
|
||||
PKG_LICENSE_FILES:=LICENSE.txt
|
||||
PKG_MAINTAINER:=Dobroslaw Kijowski <dobo90@gmail.com>
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/AdguardTeam/AdGuardHome
|
||||
GO_PKG_BUILD_PKG:=$(GO_PKG)
|
||||
|
||||
AGH_BUILD_TIME:=$(shell date -d @$(SOURCE_DATE_EPOCH) +%FT%TZ%z)
|
||||
GO_PKG_LDFLAGS_X:= \
|
||||
$(GO_PKG)/internal/version.channel=release \
|
||||
$(GO_PKG)/internal/version.version=v$(PKG_VERSION) \
|
||||
$(GO_PKG)/internal/version.buildtime=$(AGH_BUILD_TIME) \
|
||||
$(GO_PKG)/internal/version.goarm=$(GO_ARM) \
|
||||
$(GO_PKG)/internal/version.gomips=$(GO_MIPS)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../../lang/golang/golang-package.mk
|
||||
|
||||
define Package/adguardhome
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
TITLE:=Network-wide ads and trackers blocking DNS server
|
||||
URL:=https://github.com/AdguardTeam/AdGuardHome
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
|
||||
endef
|
||||
|
||||
define Package/adguardhome/conffiles
|
||||
/etc/adguardhome.yaml
|
||||
/etc/config/adguardhome
|
||||
endef
|
||||
|
||||
define Package/adguardhome/description
|
||||
Free and open source, powerful network-wide ads and trackers blocking DNS server.
|
||||
endef
|
||||
|
||||
FRONTEND_FILE:=$(PKG_NAME)-frontend-$(PKG_VERSION).tar.gz
|
||||
define Download/adguardhome-frontend
|
||||
URL:=https://github.com/AdguardTeam/AdGuardHome/releases/download/v$(PKG_VERSION)/
|
||||
URL_FILE:=AdGuardHome_frontend.tar.gz
|
||||
FILE:=$(FRONTEND_FILE)
|
||||
HASH:=253d05185865840e14e841e4245c3fdb0fdcca28649902303d3869e0bd07cfd7
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
|
||||
gzip -dc $(DL_DIR)/$(FRONTEND_FILE) | $(HOST_TAR) -C $(PKG_BUILD_DIR)/ $(TAR_OPTIONS)
|
||||
endef
|
||||
|
||||
define Package/adguardhome/install
|
||||
$(call GoPackage/Package/Install/Bin,$(1))
|
||||
endef
|
||||
|
||||
$(eval $(call Download,adguardhome-frontend))
|
||||
$(eval $(call GoBinPackage,adguardhome))
|
||||
$(eval $(call BuildPackage,adguardhome))
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/client/src/__locales/zh-cn.json
|
||||
+++ b/client/src/__locales/zh-cn.json
|
||||
@@ -571,7 +571,7 @@
|
||||
"filters_interval": "过滤器更新间隔",
|
||||
"disabled": "已禁用",
|
||||
"username_label": "用户名",
|
||||
- "username_placeholder": "输入用户名",
|
||||
+ "username_placeholder": "默认用户名密码都是root",
|
||||
"password_label": "密码",
|
||||
"password_placeholder": "输入密码",
|
||||
"sign_in": "登入",
|
||||
@@ -0,0 +1,9 @@
|
||||
--- a/client/src/helpers/version.ts
|
||||
+++ b/client/src/helpers/version.ts
|
||||
@@ -13,5 +13,5 @@ export const areEqualVersions = (left: any, right: any) => {
|
||||
|
||||
const leftVersion = left.replace(/^v/, '');
|
||||
const rightVersion = right.replace(/^v/, '');
|
||||
- return leftVersion === rightVersion;
|
||||
+ return leftVersion >= rightVersion;
|
||||
};
|
||||
@@ -0,0 +1,96 @@
|
||||
#
|
||||
# Copyright (C) 2015-2016 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v3.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=alist
|
||||
PKG_VERSION:=3.60.0
|
||||
PKG_WEB_VERSION:=3.60.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/AlistGo/alist/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=beccffdfba65a168e796a1789b6bea11ca225101cbc4276451e02b9ad8751a82
|
||||
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
PKG_LICENSE_FILE:=LICENSE
|
||||
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
|
||||
|
||||
define Download/$(PKG_NAME)-web
|
||||
FILE:=$(PKG_NAME)-web-$(PKG_WEB_VERSION).tar.gz
|
||||
URL_FILE:=dist.tar.gz
|
||||
URL:=https://github.com/AlistGo/alist-web/releases/download/$(PKG_WEB_VERSION)/
|
||||
HASH:=35c4a218fce07c9ef5113b70ec93e385c57c2910de8852b2d0973129c12b0843
|
||||
endef
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/AlistGo/alist
|
||||
GO_PKG_LDFLAGS:= \
|
||||
-X '$(GO_PKG)/v3/internal/conf.BuiltAt=$(shell date '+%Y-%m-%d %H:%M:%S %z')' \
|
||||
-X '$(GO_PKG)/v3/internal/conf.GoVersion=$(shell $(STAGING_DIR_HOSTPKG)/bin/go version | sed 's/go version //')' \
|
||||
-X '$(GO_PKG)/v3/internal/conf.GitAuthor=Xhofe <i@nn.ci>' \
|
||||
-X '$(GO_PKG)/v3/internal/conf.GitCommit=tarball/$(shell echo $(PKG_HASH) | cut -c 1-7)' \
|
||||
-X '$(GO_PKG)/v3/internal/conf.Version=v$(PKG_VERSION) (OpenWrt $(ARCH_PACKAGES))' \
|
||||
-X '$(GO_PKG)/v3/internal/conf.WebVersion=$(PKG_WEB_VERSION)'
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
define Package/$(PKG_NAME)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=A file list program that supports multiple storage
|
||||
URL:=https://alist.nn.ci/
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/conffiles
|
||||
/etc/alist
|
||||
/etc/config/alist
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/description
|
||||
A file list program that supports multiple storage, powered by Gin and Solidjs.
|
||||
endef
|
||||
|
||||
ifeq ($(ARCH),arm)
|
||||
ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
|
||||
ifeq ($(ARM_CPU_FEATURES),)
|
||||
TARGET_CFLAGS:=
|
||||
TARGET_LDFLAGS:=
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(CONFIG_USE_MUSL),)
|
||||
TARGET_CFLAGS += -D_LARGEFILE64_SOURCE
|
||||
endif
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
$(TAR) --strip-components=1 -C $(PKG_BUILD_DIR)/public/dist -xzf $(DL_DIR)/$(PKG_NAME)-web-$(PKG_WEB_VERSION).tar.gz
|
||||
$(SED) 's_https://jsd.nn.ci/gh/alist-org/logo@main/logo.png_/assets/logo.png_g' $(PKG_BUILD_DIR)/public/dist/index.html
|
||||
ifneq ($(CONFIG_ARCH_64BIT),y)
|
||||
$(RM) -rf $(PKG_BUILD_DIR)/drivers/{lark,lark.go}
|
||||
endif
|
||||
endef
|
||||
|
||||
define Package/$(PKG_NAME)/install
|
||||
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/alist $(1)/usr/bin
|
||||
$(INSTALL_DIR) $(1)/etc/config $(1)/etc/init.d $(1)/etc/alist
|
||||
$(INSTALL_CONF) $(CURDIR)/files/alist.config $(1)/etc/config/alist
|
||||
$(INSTALL_BIN) $(CURDIR)/files/alist.init $(1)/etc/init.d/alist
|
||||
$(INSTALL_DATA) $(CURDIR)/files/data.db $(1)/etc/alist/data.db
|
||||
endef
|
||||
|
||||
$(eval $(call Download,$(PKG_NAME)-web))
|
||||
$(eval $(call BuildPackage,$(PKG_NAME)))
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
config alist
|
||||
option enabled '0'
|
||||
option port '5244'
|
||||
option delayed_start '0'
|
||||
option allow_wan '0'
|
||||
option force '1'
|
||||
option token_expires_in '48'
|
||||
option max_connections '0'
|
||||
option tls_insecure_skip_verify '1'
|
||||
option data_dir '/etc/alist'
|
||||
option temp_dir '/tmp/alist'
|
||||
option log '1'
|
||||
option log_max_size '10'
|
||||
option log_max_backups '5'
|
||||
option log_max_age '28'
|
||||
option log_compress '0'
|
||||
option database_type 'sqlite3'
|
||||
option ssl '0'
|
||||
option download_workers '5'
|
||||
option download_max_retry '1'
|
||||
option transfer_workers '5'
|
||||
option transfer_max_retry '2'
|
||||
option upload_workers '5'
|
||||
option upload_max_retry '0'
|
||||
option copy_workers '5'
|
||||
option copy_max_retry '2'
|
||||
option cors_allow_origins '*'
|
||||
option cors_allow_methods '*'
|
||||
option cors_allow_headers '*'
|
||||
option s3 '0'
|
||||
Executable
+246
@@ -0,0 +1,246 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
PROG=/usr/bin/alist
|
||||
LOG_FILE=/var/log/alist.log
|
||||
|
||||
get_config() {
|
||||
config_get_bool enabled $1 enabled 1
|
||||
config_get port $1 port 5244
|
||||
config_get allow_wan $1 allow_wan 0
|
||||
config_get delayed_start $1 delayed_start 0
|
||||
|
||||
config_get force $1 force 1
|
||||
config_get site_url $1 site_url ""
|
||||
config_get cdn $1 cdn ""
|
||||
config_get jwt_secret $1 jwt_secret ""
|
||||
config_get data_dir $1 data_dir "/etc/alist"
|
||||
config_get temp_dir $1 temp_dir "/tmp/alist"
|
||||
config_get token_expires_in $1 token_expires_in 48
|
||||
config_get max_connections $1 max_connections 0
|
||||
config_get tls_insecure_skip_verify $1 tls_insecure_skip_verify 1
|
||||
|
||||
# log
|
||||
config_get log $1 log 1
|
||||
config_get log_max_size $1 log_max_size 10
|
||||
config_get log_max_backups $1 log_max_backups 5
|
||||
config_get log_max_age $1 log_max_age 28
|
||||
config_get log_compress $1 log_compress 0
|
||||
|
||||
# scheme
|
||||
config_get ssl $1 ssl 0
|
||||
config_get force_https $1 force_https 0
|
||||
config_get ssl_cert $1 ssl_cert ""
|
||||
config_get ssl_key $1 ssl_key ""
|
||||
|
||||
# database
|
||||
config_get database_type $1 database_type "sqlite3"
|
||||
config_get mysql_host $1 mysql_host ""
|
||||
config_get mysql_port $1 mysql_port "3306"
|
||||
config_get mysql_username $1 mysql_username ""
|
||||
config_get mysql_password $1 mysql_password ""
|
||||
config_get mysql_database $1 mysql_database ""
|
||||
config_get mysql_table_prefix $1 mysql_table_prefix "x_"
|
||||
config_get mysql_ssl_mode $1 mysql_ssl_mode ""
|
||||
config_get mysql_dsn $1 mysql_dsn ""
|
||||
|
||||
# tasks
|
||||
config_get download_workers $1 download_workers 5
|
||||
config_get download_max_retry $1 download_max_retry 1
|
||||
config_get transfer_workers $1 transfer_workers 5
|
||||
config_get transfer_max_retry $1 transfer_max_retry 2
|
||||
config_get upload_workers $1 upload_workers 5
|
||||
config_get upload_max_retry $1 upload_max_retry 0
|
||||
config_get copy_workers $1 copy_workers 5
|
||||
config_get copy_max_retry $1 copy_max_retry 2
|
||||
|
||||
# cors
|
||||
config_get cors_allow_origins $1 cors_allow_origins '*'
|
||||
config_get cors_allow_methods $1 cors_allow_methods '*'
|
||||
config_get cors_allow_headers $1 cors_allow_headers '*'
|
||||
|
||||
# s3
|
||||
config_get s3 $1 s3 0
|
||||
config_get s3_port $1 s3_port 5246
|
||||
config_get s3_ssl $1 s3_ssl 0
|
||||
|
||||
config_load network
|
||||
config_get lan_addr lan ipaddr "0.0.0.0"
|
||||
if echo "${lan_addr}" | grep -Fq ' '; then
|
||||
lan_addr="0.0.0.0"
|
||||
else
|
||||
lan_addr=${lan_addr%%/*}
|
||||
fi
|
||||
|
||||
# init jwt_secret
|
||||
[ -z "$jwt_secret" ] && jwt_secret=$(tr -cd "a-zA-Z0-9" < "/dev/urandom" | head -c16)
|
||||
uci -q set alist.@alist[0].jwt_secret="$jwt_secret"
|
||||
uci commit alist
|
||||
}
|
||||
|
||||
set_firewall() {
|
||||
if [ "$external_access" = "allow" ]; then
|
||||
uci -q delete firewall.alist
|
||||
uci set firewall.alist=rule
|
||||
uci set firewall.alist.name="alist"
|
||||
uci set firewall.alist.target="ACCEPT"
|
||||
uci set firewall.alist.src="wan"
|
||||
uci set firewall.alist.proto="tcp"
|
||||
uci set firewall.alist.dest_port="$port"
|
||||
uci set firewall.alist.enabled="1"
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
elif [ "$external_access" = "deny" ]; then
|
||||
uci -q delete firewall.alist
|
||||
uci commit firewall
|
||||
/etc/init.d/firewall reload >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load alist
|
||||
config_foreach get_config alist
|
||||
[ $enabled -ne 1 ] && return 1
|
||||
mkdir -p "$temp_dir" "$data_dir"
|
||||
[ "$ssl" -eq 1 ] && https_port=$port http_port="-1" || https_port="-1" http_port=$port
|
||||
if [ -e /proc/uptime ]; then
|
||||
[ $(awk -F. '{print $1}' /proc/uptime) -lt "120" ] && delayed_start=$delayed_start || delayed_start=0
|
||||
else
|
||||
delayed_start=$delayed_start
|
||||
fi
|
||||
if [ "$allow_wan" -eq "1" ]; then
|
||||
listen_addr="0.0.0.0"
|
||||
external_access="allow"
|
||||
else
|
||||
listen_addr=$lan_addr
|
||||
external_access="deny"
|
||||
fi
|
||||
|
||||
set_firewall
|
||||
> $LOG_FILE
|
||||
|
||||
# init config
|
||||
json_init
|
||||
json_add_boolean "force" "$force"
|
||||
json_add_string "site_url" "$site_url"
|
||||
json_add_string "cdn" "$cdn"
|
||||
json_add_string "jwt_secret" "$jwt_secret"
|
||||
json_add_int "token_expires_in" "$token_expires_in"
|
||||
|
||||
# database
|
||||
json_add_object 'database'
|
||||
json_add_string "type" "$database_type"
|
||||
json_add_string "host" "$mysql_host"
|
||||
json_add_int "port" "$mysql_port"
|
||||
json_add_string "user" "$mysql_username"
|
||||
json_add_string "password" "$mysql_password"
|
||||
json_add_string "name" "$mysql_database"
|
||||
json_add_string "db_file" "$data_dir/data.db"
|
||||
json_add_string "table_prefix" "$mysql_table_prefix"
|
||||
json_add_string "ssl_mode" "$mysql_ssl_mode"
|
||||
json_add_string "dsn" "$mysql_dsn"
|
||||
json_close_object
|
||||
|
||||
# meilisearch
|
||||
json_add_object "meilisearch"
|
||||
json_add_string "host" "http://localhost:7700"
|
||||
json_add_string "api_key" ""
|
||||
json_add_string "index_prefix" ""
|
||||
json_close_object
|
||||
|
||||
# scheme
|
||||
json_add_object "scheme"
|
||||
json_add_string "address" "$listen_addr"
|
||||
json_add_int "http_port" "$http_port"
|
||||
json_add_int "https_port" "$https_port"
|
||||
json_add_boolean "force_https" "$force_https"
|
||||
json_add_string "cert_file" "$ssl_cert"
|
||||
json_add_string "key_file" "$ssl_key"
|
||||
json_add_string "unix_file" ""
|
||||
json_add_string "unix_file_perm" ""
|
||||
json_close_object
|
||||
|
||||
json_add_string "temp_dir" "$temp_dir"
|
||||
json_add_string "bleve_dir" "$data_dir/bleve"
|
||||
json_add_string "dist_dir" ""
|
||||
|
||||
# log
|
||||
json_add_object "log"
|
||||
json_add_boolean "enable" "$log"
|
||||
json_add_string "name" "$LOG_FILE"
|
||||
json_add_int "max_size" "$log_max_size"
|
||||
json_add_int "max_backups" "$log_max_backups"
|
||||
json_add_int "max_age" "$log_max_age"
|
||||
json_add_boolean "compress" "$log_compress"
|
||||
json_close_object
|
||||
|
||||
json_add_int "delayed_start" "$delayed_start"
|
||||
json_add_int "max_connections" "$max_connections"
|
||||
json_add_boolean "tls_insecure_skip_verify" "$tls_insecure_skip_verify"
|
||||
|
||||
# tasks
|
||||
json_add_object "tasks"
|
||||
json_add_object "download"
|
||||
json_add_int "workers" "$download_workers"
|
||||
json_add_int "max_retry" "$download_max_retry"
|
||||
json_close_object
|
||||
json_add_object "transfer"
|
||||
json_add_int "workers" "$transfer_workers"
|
||||
json_add_int "max_retry" "$transfer_max_retry"
|
||||
json_close_object
|
||||
json_add_object "upload"
|
||||
json_add_int "workers" "$upload_workers"
|
||||
json_add_int "max_retry" "$upload_max_retry"
|
||||
json_close_object
|
||||
json_add_object "copy"
|
||||
json_add_int "workers" "$copy_workers"
|
||||
json_add_int "max_retry" "$copy_max_retry"
|
||||
json_close_object
|
||||
json_close_object
|
||||
|
||||
# cors
|
||||
json_add_object "cors"
|
||||
json_add_array "allow_origins"
|
||||
json_add_string "" "$cors_allow_origins"
|
||||
json_close_array
|
||||
json_add_array "allow_methods"
|
||||
json_add_string "" "$cors_allow_methods"
|
||||
json_close_array
|
||||
json_add_array "allow_headers"
|
||||
json_add_string "" "$cors_allow_headers"
|
||||
json_close_array
|
||||
json_close_object
|
||||
|
||||
# s3
|
||||
json_add_object "s3"
|
||||
json_add_boolean "enable" "$s3"
|
||||
json_add_int "port" "$s3_port"
|
||||
json_add_boolean "ssl" "$s3_ssl"
|
||||
json_close_object
|
||||
|
||||
json_dump > "$data_dir/config.json"
|
||||
|
||||
procd_open_instance alist
|
||||
procd_set_param command $PROG
|
||||
procd_append_param command server
|
||||
procd_append_param command --data "$data_dir"
|
||||
procd_set_param file "$data_dir/config.json"
|
||||
procd_set_param stdout 0
|
||||
procd_set_param stderr 0
|
||||
procd_set_param respawn
|
||||
procd_set_param limits core="unlimited"
|
||||
procd_set_param limits nofile="200000 200000"
|
||||
procd_close_instance alist
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "alist"
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
external_access="deny"
|
||||
set_firewall
|
||||
}
|
||||
Binary file not shown.
+10
@@ -0,0 +1,10 @@
|
||||
<svg width="1252" height="1252" xmlns="http://www.w3.org/2000/svg" version="1.1">
|
||||
<g>
|
||||
<g id="#70c6beff">
|
||||
<path id="svg_2" d="m634.37,138.38c11.88,-1.36 24.25,1.3 34.18,8.09c14.96,9.66 25.55,24.41 34.49,39.51c40.59,68.03 81.45,135.91 122.02,203.96c54.02,90.99 108.06,181.97 161.94,273.06c37.28,63 74.65,125.96 112.18,188.82c24.72,41.99 50.21,83.54 73.84,126.16c10.18,17.84 15.77,38.44 14.93,59.03c-0.59,15.92 -3.48,32.28 -11.84,46.08c-11.73,19.46 -31.39,33.2 -52.71,40.36c-11.37,4.09 -23.3,6.87 -35.43,6.89c-132.32,-0.05 -264.64,0.04 -396.95,0.03c-11.38,-0.29 -22.95,-1.6 -33.63,-5.72c-7.81,-3.33 -15.5,-7.43 -21.61,-13.42c-10.43,-10.32 -17.19,-24.96 -15.38,-39.83c0.94,-10.39 3.48,-20.64 7.76,-30.16c4.15,-9.77 9.99,-18.67 15.06,-27.97c22.13,-39.47 45.31,-78.35 69.42,-116.65c7.72,-12.05 14.44,-25.07 25.12,-34.87c11.35,-10.39 25.6,-18.54 41.21,-19.6c12.55,-0.52 24.89,3.82 35.35,10.55c11.8,6.92 21.09,18.44 24.2,31.88c4.49,17.01 -0.34,34.88 -7.55,50.42c-8.09,17.65 -19.62,33.67 -25.81,52.18c-1.13,4.21 -2.66,9.52 0.48,13.23c3.19,3 7.62,4.18 11.77,5.22c12,2.67 24.38,1.98 36.59,2.06c45,-0.01 90,0 135,0c8.91,-0.15 17.83,0.3 26.74,-0.22c6.43,-0.74 13.44,-1.79 18.44,-6.28c3.3,-2.92 3.71,-7.85 2.46,-11.85c-2.74,-8.86 -7.46,-16.93 -12.12,-24.89c-119.99,-204.91 -239.31,-410.22 -360.56,-614.4c-3.96,-6.56 -7.36,-13.68 -13.03,-18.98c-2.8,-2.69 -6.95,-4.22 -10.77,-3.11c-3.25,1.17 -5.45,4.03 -7.61,6.57c-5.34,6.81 -10.12,14.06 -14.51,21.52c-20.89,33.95 -40.88,68.44 -61.35,102.64c-117.9,198.43 -235.82,396.85 -353.71,595.29c-7.31,13.46 -15.09,26.67 -23.57,39.43c-7.45,10.96 -16.49,21.23 -28.14,27.83c-13.73,7.94 -30.69,11.09 -46.08,6.54c-11.23,-3.47 -22.09,-9.12 -30.13,-17.84c-10.18,-10.08 -14.69,-24.83 -14.17,-38.94c0.52,-14.86 5.49,-29.34 12.98,-42.1c71.58,-121.59 143.62,-242.92 215.93,-364.09c37.2,-62.8 74.23,-125.69 111.64,-188.36c37.84,-63.5 75.77,-126.94 113.44,-190.54c21.02,-35.82 42.19,-71.56 64.28,-106.74c6.79,-11.15 15.58,-21.15 26.16,-28.85c8.68,-5.92 18.42,-11 29.05,-11.94z" fill="#70c6be"/>
|
||||
</g>
|
||||
<g id="#1ba0d8ff">
|
||||
<path id="svg_3" d="m628.35,608.38c17.83,-2.87 36.72,1.39 51.5,11.78c11.22,8.66 19.01,21.64 21.26,35.65c1.53,10.68 0.49,21.75 -3.44,31.84c-3.02,8.73 -7.35,16.94 -12.17,24.81c-68.76,115.58 -137.5,231.17 -206.27,346.75c-8.8,14.47 -16.82,29.47 -26.96,43.07c-7.37,9.11 -16.58,16.85 -27.21,21.89c-22.47,11.97 -51.79,4.67 -68.88,-13.33c-8.66,-8.69 -13.74,-20.63 -14.4,-32.84c-0.98,-12.64 1.81,-25.42 7.53,-36.69c5.03,-10.96 10.98,-21.45 17.19,-31.77c30.22,-50.84 60.17,-101.84 90.3,-152.73c41.24,-69.98 83.16,-139.55 124.66,-209.37c4.41,-7.94 9.91,-15.26 16.09,-21.9c8.33,-8.46 18.9,-15.3 30.8,-17.16z" fill="#1ba0d8"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.6 KiB |
@@ -0,0 +1,76 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=aliyundrive-webdav
|
||||
PKG_VERSION:=2.3.3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_MAINTAINER:=messense <messense@icloud.com>
|
||||
|
||||
PKG_LIBC:=musl
|
||||
ifeq ($(ARCH),arm)
|
||||
PKG_LIBC:=musleabi
|
||||
|
||||
ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
|
||||
ifneq ($(filter $(ARM_CPU_FEATURES),vfp vfpv2),)
|
||||
PKG_LIBC:=musleabihf
|
||||
endif
|
||||
endif
|
||||
|
||||
PKG_ARCH=$(ARCH)
|
||||
ifeq ($(ARCH),i386)
|
||||
PKG_ARCH:=i686
|
||||
endif
|
||||
|
||||
PKG_SOURCE:=aliyundrive-webdav-v$(PKG_VERSION).$(PKG_ARCH)-unknown-linux-$(PKG_LIBC).tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/messense/aliyundrive-webdav/releases/download/v$(PKG_VERSION)/
|
||||
PKG_HASH:=skip
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/aliyundrive-webdav
|
||||
SECTION:=multimedia
|
||||
CATEGORY:=Multimedia
|
||||
TITLE:=WebDAV server for AliyunDrive
|
||||
URL:=https://github.com/messense/aliyundrive-webdav
|
||||
endef
|
||||
|
||||
define Package/aliyundrive-webdav/description
|
||||
WebDAV server for AliyunDrive.
|
||||
endef
|
||||
|
||||
define Package/aliyundrive-webdav/conffiles
|
||||
/etc/config/aliyundrive-webdav
|
||||
endef
|
||||
|
||||
define Download/sha256sum
|
||||
FILE:=$(PKG_SOURCE).sha256
|
||||
URL_FILE:=$(FILE)
|
||||
URL:=$(PKG_SOURCE_URL)
|
||||
HASH:=skip
|
||||
endef
|
||||
$(eval $(call Download,sha256sum))
|
||||
|
||||
define Build/Prepare
|
||||
mv $(DL_DIR)/$(PKG_SOURCE).sha256 .
|
||||
cp $(DL_DIR)/$(PKG_SOURCE) .
|
||||
shasum -a 256 -c $(PKG_SOURCE).sha256
|
||||
rm $(PKG_SOURCE).sha256 $(PKG_SOURCE)
|
||||
|
||||
tar -C $(PKG_BUILD_DIR)/ -zxf $(DL_DIR)/$(PKG_SOURCE)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
echo "aliyundrive-webdav using precompiled binary."
|
||||
endef
|
||||
|
||||
define Package/aliyundrive-webdav/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/aliyundrive-webdav $(1)/usr/bin/aliyundrive-webdav
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/aliyundrive-webdav.init $(1)/etc/init.d/aliyundrive-webdav
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/aliyundrive-webdav.config $(1)/etc/config/aliyundrive-webdav
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,aliyundrive-webdav))
|
||||
@@ -0,0 +1,21 @@
|
||||
config server
|
||||
option enable '0'
|
||||
option debug '0'
|
||||
option refresh_token ''
|
||||
option host '0.0.0.0'
|
||||
option port '8080'
|
||||
option drive_type ''
|
||||
option auth_user ''
|
||||
option auth_password ''
|
||||
option read_buffer_size '10485760'
|
||||
option upload_buffer_size '16777216'
|
||||
option cache_size '1000'
|
||||
option cache_ttl '600'
|
||||
option root '/'
|
||||
option no_trash '0'
|
||||
option read_only '0'
|
||||
option tls_cert ''
|
||||
option tls_key ''
|
||||
option skip_upload_same_size '0'
|
||||
option prefer_http_download '0'
|
||||
option redirect '1'
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
START=99
|
||||
STOP=15
|
||||
|
||||
NAME=aliyundrive-webdav
|
||||
|
||||
uci_get_by_type() {
|
||||
local ret=$(uci get $NAME.@$1[0].$2 2>/dev/null)
|
||||
echo ${ret:=$3}
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local enable=$(uci_get_by_type server enable)
|
||||
case "$enable" in
|
||||
1|on|true|yes|enabled)
|
||||
local refresh_token=$(uci_get_by_type server refresh_token)
|
||||
local auth_user=$(uci_get_by_type server auth_user)
|
||||
local auth_password=$(uci_get_by_type server auth_password)
|
||||
local read_buf_size=$(uci_get_by_type server read_buffer_size 10485760)
|
||||
local upload_buf_size=$(uci_get_by_type server upload_buffer_size 16777216)
|
||||
local cache_size=$(uci_get_by_type server cache_size 1000)
|
||||
local cache_ttl=$(uci_get_by_type server cache_ttl 600)
|
||||
local host=$(uci_get_by_type server host 127.0.0.1)
|
||||
local port=$(uci_get_by_type server port 8080)
|
||||
local root=$(uci_get_by_type server root /)
|
||||
local tls_cert=$(uci_get_by_type server tls_cert)
|
||||
local tls_key=$(uci_get_by_type server tls_key)
|
||||
local drive_type=$(uci_get_by_type server drive_type)
|
||||
|
||||
local extra_options="--auto-index"
|
||||
|
||||
case "$(uci_get_by_type server no_trash 0)" in
|
||||
1|on|true|yes|enabled)
|
||||
extra_options="$extra_options --no-trash"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
case "$(uci_get_by_type server read_only 0)" in
|
||||
1|on|true|yes|enabled)
|
||||
extra_options="$extra_options --read-only"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
case "$(uci_get_by_type server skip_upload_same_size 0)" in
|
||||
1|on|true|yes|enabled)
|
||||
extra_options="$extra_options --skip-upload-same-size"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
case "$(uci_get_by_type server prefer_http_download 0)" in
|
||||
1|on|true|yes|enabled)
|
||||
extra_options="$extra_options --prefer-http-download"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
case "$(uci_get_by_type server redirect 0)" in
|
||||
1|on|true|yes|enabled)
|
||||
extra_options="$extra_options --redirect"
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
if [[ ! -z "$tls_cert" && ! -z "$tls_key" ]]; then
|
||||
extra_options="$extra_options --tls-cert $tls_cert --tls-key $tls_key"
|
||||
fi
|
||||
|
||||
if [[ ! -z "$drive_type" ]]; then
|
||||
extra_options="$extra_options --drive-type $drive_type"
|
||||
fi
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command /bin/sh -c "/usr/bin/$NAME $extra_options --host $host --port $port --root $root --read-buffer-size $read_buf_size --upload-buffer-size $upload_buf_size --cache-size $cache_size --cache-ttl $cache_ttl --workdir /var/run/$NAME >>/var/log/$NAME.log 2>&1"
|
||||
procd_set_param pidfile /var/run/$NAME.pid
|
||||
procd_set_param env REFRESH_TOKEN="$refresh_token"
|
||||
[[ ! -z "$auth_user" ]] && procd_append_param env WEBDAV_AUTH_USER="$auth_user"
|
||||
[[ ! -z "$auth_password" ]] && procd_append_param env WEBDAV_AUTH_PASSWORD="$auth_password"
|
||||
case $(uci_get_by_type server debug) in
|
||||
1|on|true|yes|enabled)
|
||||
procd_append_param env RUST_LOG="aliyundrive_webdav=debug" ;;
|
||||
*) ;;
|
||||
esac
|
||||
procd_close_instance ;;
|
||||
*)
|
||||
stop_service ;;
|
||||
esac
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "aliyundrive-webdav"
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
menu "Aria2 Configuration"
|
||||
depends on PACKAGE_aria2
|
||||
|
||||
choice
|
||||
prompt "SSL Library"
|
||||
default ARIA2_OPENSSL
|
||||
|
||||
config ARIA2_OPENSSL
|
||||
bool "OpenSSL"
|
||||
|
||||
config ARIA2_GNUTLS
|
||||
bool "GnuTLS"
|
||||
|
||||
config ARIA2_NOSSL
|
||||
bool "No SSL Support"
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "Crypto Library"
|
||||
depends on !ARIA2_OPENSSL
|
||||
default ARIA2_NOCRYPTO
|
||||
|
||||
config ARIA2_NETTLE
|
||||
bool "Nettle"
|
||||
|
||||
config ARIA2_LIBGCRYPT
|
||||
bool "Libgcrypt"
|
||||
|
||||
config ARIA2_NOCRYPTO
|
||||
bool "No Crypto Library"
|
||||
|
||||
endchoice
|
||||
|
||||
choice
|
||||
prompt "XML Library"
|
||||
default ARIA2_NOXML
|
||||
|
||||
config ARIA2_LIBXML2
|
||||
bool "Libxml2"
|
||||
|
||||
config ARIA2_EXPAT
|
||||
bool "Expat"
|
||||
|
||||
config ARIA2_NOXML
|
||||
bool "No XML Library"
|
||||
|
||||
endchoice
|
||||
|
||||
config ARIA2_GMP
|
||||
bool "GNU Multiple Precision Arithmetic Library"
|
||||
depends on ARIA2_NETTLE
|
||||
default n
|
||||
|
||||
config ARIA2_BITTORRENT
|
||||
bool "Enable Bittorrent Support"
|
||||
depends on ARIA2_OPENSSL || ARIA2_LIBGCRYPT || \
|
||||
(ARIA2_NETTLE && ARIA2_GMP)
|
||||
default y
|
||||
|
||||
config ARIA2_METALINK
|
||||
bool "Enable Metalink Support"
|
||||
depends on !ARIA2_NOXML
|
||||
default n
|
||||
|
||||
config ARIA2_SFTP
|
||||
bool "Enable SFTP Support"
|
||||
default n
|
||||
|
||||
config ARIA2_ASYNC_DNS
|
||||
bool "Enable Async DNS Support"
|
||||
default n
|
||||
|
||||
config ARIA2_COOKIE
|
||||
bool "Enable Firefox3/Chromium Cookie Support"
|
||||
default n
|
||||
|
||||
config ARIA2_WEBSOCKET
|
||||
bool "Enable JSON-RPC over WebSocket Support"
|
||||
depends on ARIA2_OPENSSL || ARIA2_LIBGCRYPT || ARIA2_NETTLE
|
||||
default y
|
||||
|
||||
endmenu
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
#
|
||||
# Copyright (C) 2012-2023 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=aria2
|
||||
PKG_VERSION:=1.37.0
|
||||
PKG_RELEASE:=9
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
|
||||
PKG_SOURCE_URL:=https://github.com/aria2/aria2/releases/download/release-$(PKG_VERSION)/
|
||||
PKG_HASH:=skip
|
||||
PKG_INSTALL:=1
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=gc-sections lto
|
||||
|
||||
PKG_MAINTAINER:=Imre Kaloz <kaloz@openwrt.org>, \
|
||||
Hsing-Wang Liao <kuoruan@gmail.com>
|
||||
PKG_LICENSE:=GPLv2
|
||||
PKG_LICENSE_FILES:=COPYING
|
||||
PKG_CPE_ID:=cpe:/a:aria2_project:aria2
|
||||
|
||||
PKG_CONFIG_DEPENDS := \
|
||||
CONFIG_ARIA2_NOSSL \
|
||||
CONFIG_ARIA2_OPENSSL \
|
||||
CONFIG_ARIA2_GNUTLS \
|
||||
CONFIG_ARIA2_NOCRYPTO \
|
||||
CONFIG_ARIA2_NETTLE \
|
||||
CONFIG_ARIA2_LIBGCRYPT \
|
||||
CONFIG_ARIA2_LIBXML2 \
|
||||
CONFIG_ARIA2_EXPAT \
|
||||
CONFIG_ARIA2_GMP \
|
||||
CONFIG_ARIA2_BITTORRENT \
|
||||
CONFIG_ARIA2_METALINK \
|
||||
CONFIG_ARIA2_SFTP \
|
||||
CONFIG_ARIA2_ASYNC_DNS \
|
||||
CONFIG_ARIA2_COOKIE \
|
||||
CONFIG_ARIA2_WEBSOCKET
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/nls.mk
|
||||
|
||||
define Package/aria2-openssl
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=File Transfer
|
||||
TITLE:=lightweight download utility (OpenSSL dependencies)
|
||||
DEPENDS:=+libopenssl +libopenssl-legacy
|
||||
HIDDEN:=1
|
||||
endef
|
||||
|
||||
define Package/aria2/config
|
||||
source "$(SOURCE)/Config.in"
|
||||
endef
|
||||
|
||||
define Package/aria2
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=File Transfer
|
||||
TITLE:=lightweight download utility
|
||||
URL:=https://aria2.github.io/
|
||||
DEPENDS:=+zlib +libstdcpp +ARIA2_OPENSSL:aria2-openssl +ARIA2_GNUTLS:libgnutls \
|
||||
+ARIA2_NETTLE:libnettle +ARIA2_LIBGCRYPT:libgcrypt +ARIA2_GMP:libgmp \
|
||||
+ARIA2_LIBXML2:libxml2 +ARIA2_EXPAT:libexpat +ARIA2_SFTP:libssh2 \
|
||||
+ARIA2_ASYNC_DNS:libcares +ARIA2_COOKIE:libsqlite3
|
||||
USERID:=aria2=6800:aria2=6800
|
||||
endef
|
||||
|
||||
define Package/aria2/description
|
||||
aria2 is a lightweight multi-protocol & multi-source command-line download
|
||||
utility
|
||||
endef
|
||||
|
||||
CONFIGURE_ARGS += \
|
||||
--disable-nls \
|
||||
$(if $(CONFIG_ARIA2_NOSSL),--disable,--enable)-ssl \
|
||||
$(if $(CONFIG_ARIA2_BITTORRENT),--enable,--disable)-bittorrent \
|
||||
$(if $(CONFIG_ARIA2_METALINK),--enable,--disable)-metalink \
|
||||
$(if $(CONFIG_ARIA2_WEBSOCKET),--enable,--disable)-websocket \
|
||||
$(if $(CONFIG_ARIA2_OPENSSL),--with,--without)-openssl \
|
||||
$(if $(CONFIG_ARIA2_GNUTLS),--with,--without)-gnutls \
|
||||
$(if $(CONFIG_ARIA2_NETTLE),--with,--without)-libnettle \
|
||||
$(if $(CONFIG_ARIA2_LIBGCRYPT),--with,--without)-libgcrypt \
|
||||
$(if $(CONFIG_ARIA2_GMP),--with,--without)-libgmp \
|
||||
$(if $(CONFIG_ARIA2_LIBXML2),--with,--without)-libxml2 \
|
||||
$(if $(CONFIG_ARIA2_EXPAT),--with,--without)-libexpat \
|
||||
$(if $(CONFIG_ARIA2_SFTP),--with,--without)-libssh2 \
|
||||
$(if $(CONFIG_ARIA2_ASYNC_DNS),--with,--without)-libcares \
|
||||
$(if $(CONFIG_ARIA2_COOKIE),--with,--without)-sqlite3 \
|
||||
--without-libuv \
|
||||
--with-libz
|
||||
|
||||
define Package/aria2/conffiles
|
||||
/etc/config/aria2
|
||||
endef
|
||||
|
||||
define Download/aria2.conf
|
||||
URL:=https://github.com/P3TERX/aria2.conf/archive
|
||||
URL_FILE:=master.zip
|
||||
FILE:=aria2.conf
|
||||
HASH:=skip
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
unzip $(DL_DIR)/aria2.conf -d $(PKG_BUILD_DIR)/
|
||||
sed -i '/rpc-secret/d' $(PKG_BUILD_DIR)/aria2.conf-master/*
|
||||
[ -x $(PKG_BUILD_DIR)/aria2.conf-master/tracker.sh ] && { cd $(PKG_BUILD_DIR)/aria2.conf-master && sh ./tracker.sh >/dev/null 2>&1; }
|
||||
endef
|
||||
|
||||
define Package/aria2/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/aria2c $(1)/usr/bin
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/aria2.init $(1)/etc/init.d/aria2
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/aria2.conf $(1)/etc/config/aria2
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/aria2
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/aria2.conf-master/* $(1)/usr/share/aria2/
|
||||
endef
|
||||
|
||||
define Package/aria2-openssl/install
|
||||
true
|
||||
endef
|
||||
|
||||
$(eval $(call Download,aria2.conf))
|
||||
$(eval $(call BuildPackage,aria2))
|
||||
$(eval $(call BuildPackage,aria2-openssl))
|
||||
@@ -0,0 +1,23 @@
|
||||
|
||||
# You can use most aria2 command-line options, replace '-' with '_'.
|
||||
# eg. 'rpc-secret' ==> 'rpc_secret'
|
||||
#
|
||||
# We do not support all options at this time. But you can add any option
|
||||
# with 'list extra_settings'.
|
||||
#
|
||||
# You can also add new config sections to define multi instance.
|
||||
#
|
||||
config aria2 'main'
|
||||
option enabled '0'
|
||||
option user 'aria2'
|
||||
option dir '/mnt/sda1/aria2'
|
||||
option config_dir '/var/etc/aria2'
|
||||
option bt_enable_lpd 'true'
|
||||
option enable_dht 'true'
|
||||
option follow_torrent 'true'
|
||||
option file_allocation 'none'
|
||||
option save_session_interval '30'
|
||||
option split '128'
|
||||
option min_split_size '100K'
|
||||
option max_connection_per_server '128'
|
||||
list extra_settings 'dht-file-path=/usr/share/aria2/dht.dat'
|
||||
@@ -0,0 +1,364 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2016-2017 Hsing-wang Liao <kuoruan@gmail.com>
|
||||
# Licensed to the public under the Apache License 2.0.
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
NAME=aria2
|
||||
PROG=/usr/bin/aria2c
|
||||
|
||||
_info() {
|
||||
logger -p daemon.info -t "$NAME" "$*"
|
||||
}
|
||||
|
||||
_err() {
|
||||
logger -p daemon.err -t "$NAME" "$*"
|
||||
}
|
||||
|
||||
_make_dir() {
|
||||
local d
|
||||
for d in "$@"; do
|
||||
if [ ! -d "$d" ]; then
|
||||
mkdir -p "$d" 2>/dev/null || return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_create_file() {
|
||||
touch "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
_change_owner() {
|
||||
local u="$1"; shift
|
||||
|
||||
local d
|
||||
for d in "$@"; do
|
||||
if [ -f "$d" ]; then
|
||||
chown "$u" "$d" 2>/dev/null || return 1
|
||||
elif [ -d "$d" ]; then
|
||||
chown -R "$u" "$d" 2>/dev/null || return 1
|
||||
fi
|
||||
done
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
_change_file_mode() {
|
||||
local mod="$1"; shift
|
||||
chmod "$mod" "$@" 2>/dev/null
|
||||
}
|
||||
|
||||
_reset_dir_mode() {
|
||||
local d
|
||||
for d in "$@"; do
|
||||
if [ -d "$d" ]; then
|
||||
find "$d" -type d -exec chmod 755 {} \; 2>/dev/null
|
||||
find "$d" -type f -exec chmod 644 {} \; 2>/dev/null
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
append_options() {
|
||||
local o; local v
|
||||
for o in "$@"; do
|
||||
v="$(eval echo "\$$o")"
|
||||
[ -n "$v" ] && \
|
||||
echo "${o//_/-}=$v" >>"$config_file_tmp"
|
||||
done
|
||||
}
|
||||
|
||||
append_setting() {
|
||||
local s="$1"
|
||||
[ -n "$s" ] && \
|
||||
echo "$s" >>"$config_file_tmp"
|
||||
}
|
||||
|
||||
append_header() {
|
||||
local h="$1"
|
||||
[ -n "$h" ] && \
|
||||
echo "header=\"$h\"" >>"$config_file_tmp"
|
||||
}
|
||||
|
||||
aria2_validate() {
|
||||
uci_load_validate "$NAME" aria2 "$1" "$2" \
|
||||
'enabled:bool:0' \
|
||||
'enable_logging:bool' \
|
||||
'enable_proxy:bool' \
|
||||
'config_dir:string:/var/etc/aria2' \
|
||||
'user:string' \
|
||||
'all_proxy:string' \
|
||||
'all_proxy_passwd:string' \
|
||||
'all_proxy_user:string' \
|
||||
'auto_save_interval:range(0,600)' \
|
||||
'bt_enable_lpd:or("true","false")' \
|
||||
'bt_detach_seed_only:or("true","false")' \
|
||||
'bt_load_saved_metadata:or("true","false")' \
|
||||
'bt_prioritize_piece:string' \
|
||||
'bt_max_open_files:uinteger' \
|
||||
'bt_max_peers:uinteger' \
|
||||
'bt_remove_unselected_file:or("true","false")' \
|
||||
'bt_request_peer_speed_limit:string' \
|
||||
'bt_save_metadata:or("true","false")' \
|
||||
'bt_seed_unverified:or("true","false")' \
|
||||
'bt_stop_timeout:uinteger' \
|
||||
'bt_tracker:list(string)' \
|
||||
'ca_certificate:file' \
|
||||
'certificate:file' \
|
||||
'check_certificate:or("true","false"):true' \
|
||||
'check_integrity:or("true","false")' \
|
||||
'connect_timeout:uinteger' \
|
||||
'dht_listen_port:string' \
|
||||
'dir:string' \
|
||||
'disable_ipv6:or("true","false")' \
|
||||
'disk_cache:string' \
|
||||
'enable_dht:or("true","false"):true' \
|
||||
'enable_dht6:or("true","false")' \
|
||||
'enable_peer_exchange:or("true","false")' \
|
||||
'event_poll:or("epoll","kqueue","port","poll","select")' \
|
||||
'file_allocation:or("none","prealloc","trunc","falloc")' \
|
||||
'follow_torrent:or("true","false","mem")' \
|
||||
'force_save:or("true","false")' \
|
||||
'http_accept_gzip:or("true","false")' \
|
||||
'http_no_cache:or("true","false")' \
|
||||
'listen_port:string' \
|
||||
'log:string' \
|
||||
'log_level:or("debug","info","notice","warn","error")' \
|
||||
'lowest_speed_limit:string' \
|
||||
'max_concurrent_downloads:uinteger' \
|
||||
'max_connection_per_server:uinteger' \
|
||||
'max_download_limit:string' \
|
||||
'max_overall_download_limit:string' \
|
||||
'max_overall_upload_limit:string' \
|
||||
'max_tries:uinteger' \
|
||||
'max_upload_limit:string' \
|
||||
'min_split_size:string' \
|
||||
'pause:or("true","false")' \
|
||||
'pause_metadata:or("true","false")' \
|
||||
'peer_id_prefix:string' \
|
||||
'private_key:file' \
|
||||
'retry_wait:uinteger' \
|
||||
'rpc_auth_method:or("none","user_pass","token")' \
|
||||
'rpc_certificate:file' \
|
||||
'rpc_listen_port:range(1024,65535)' \
|
||||
'rpc_passwd:string' \
|
||||
'rpc_private_key:file' \
|
||||
'rpc_secret:string' \
|
||||
'rpc_secure:or("true","false")' \
|
||||
'rpc_user:string' \
|
||||
'save_session_interval:uinteger' \
|
||||
'seed_ratio:ufloat' \
|
||||
'seed_time:ufloat' \
|
||||
'split:uinteger' \
|
||||
'timeout:uinteger' \
|
||||
'user_agent:string'
|
||||
}
|
||||
|
||||
aria2_start() {
|
||||
local section="$1"
|
||||
[ "$2" = "0" ] || { _err "Validation failed."; return 1; }
|
||||
|
||||
[ "$enabled" = "1" ] || { _info "Instance \"$section\" disabled."; return 1; }
|
||||
[ -n "$dir" ] || { _err "Please set download dir."; return 1; }
|
||||
[ -d "$dir" ] || _make_dir "$dir" || {
|
||||
_err "Can't create download dir: $dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
config_file="$config_dir/$NAME.conf.$section"
|
||||
config_file_tmp="$config_dir/$NAME.conf.tmp"
|
||||
session_file="$config_dir/$NAME.session.$section"
|
||||
|
||||
_make_dir "$config_dir" || {
|
||||
_err "Can't create config dir: $config_dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
_create_file "$session_file" "$config_file" "$config_file_tmp" || {
|
||||
_err "Can't create files: $session_file, $config_file, $config_file_tmp"
|
||||
return 1
|
||||
}
|
||||
|
||||
# create tmp file
|
||||
cat >"$config_file_tmp" <<-EOF
|
||||
# Auto generated file, changes to this file will be lost.
|
||||
EOF
|
||||
|
||||
append_setting "dir=$dir"
|
||||
append_setting "enable-rpc=true"
|
||||
append_setting "rpc-allow-origin-all=true"
|
||||
append_setting "rpc-listen-all=true"
|
||||
append_setting "quiet=true"
|
||||
append_setting "continue=true"
|
||||
append_setting "input-file=$session_file"
|
||||
append_setting "save-session=$session_file"
|
||||
|
||||
if [ -z "$enable_logging" ]; then
|
||||
append_options "log" "log_level"
|
||||
elif [ "$enable_logging" = "1" ]; then
|
||||
log=${log:-"/var/log/aria2.log"}
|
||||
|
||||
local log_dir
|
||||
log_dir="$(dirname "$log")"
|
||||
|
||||
_make_dir "$log_dir" || {
|
||||
_err "Can't create log dir: $log_dir"
|
||||
return 1
|
||||
}
|
||||
|
||||
# create or clear log file
|
||||
echo >"$log"
|
||||
|
||||
append_setting "log=$log"
|
||||
append_options "log_level"
|
||||
fi
|
||||
|
||||
if [ -z "$enable_proxy" ] || [ "$enable_proxy" = "1" ]; then
|
||||
append_options "all_proxy" "all_proxy_user" "all_proxy_passwd"
|
||||
fi
|
||||
|
||||
unset_auth_method() {
|
||||
uci -q batch <<-EOF
|
||||
set $NAME.$section.rpc_auth_method=""
|
||||
commit $NAME
|
||||
EOF
|
||||
}
|
||||
|
||||
if [ -z "$rpc_auth_method" ]; then
|
||||
if [ -n "$rpc_secret" ]; then
|
||||
append_setting "rpc-secret=$rpc_secret"
|
||||
elif [ -n "$rpc_user" ]; then
|
||||
append_setting "rpc-user=$rpc_user"
|
||||
append_setting "rpc-passwd=$rpc_passwd"
|
||||
else
|
||||
_info "It is recommended to set RPC secret."
|
||||
fi
|
||||
elif [ "$rpc_auth_method" = "token" ]; then
|
||||
if [ -n "$rpc_secret" ]; then
|
||||
append_setting "rpc-secret=$rpc_secret"
|
||||
else
|
||||
unset_auth_method
|
||||
fi
|
||||
elif [ "$rpc_auth_method" = "user_pass" ]; then
|
||||
if [ -n "$rpc_user" ]; then
|
||||
append_setting "rpc-user=$rpc_user"
|
||||
append_setting "rpc-passwd=$rpc_passwd"
|
||||
else
|
||||
_info "Please set RPC user."
|
||||
unset_auth_method
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ ."$rpc_secure" = ."true" ] && [ -n "$rpc_certificate" ]; then
|
||||
append_setting "rpc-secure=true"
|
||||
append_options "rpc_certificate" "rpc_private_key"
|
||||
fi
|
||||
|
||||
if [ ."$check_certificate" = ."true" ]; then
|
||||
append_setting "check-certificate=true"
|
||||
append_options "ca_certificate"
|
||||
elif [ ."$check_certificate" = ."false" ]; then
|
||||
append_setting "check-certificate=false"
|
||||
fi
|
||||
|
||||
if [ ."$enable_dht" = ."true" ]; then
|
||||
dht_file="$config_dir/dht.dat.$section"
|
||||
_create_file "$dht_file" || {
|
||||
_err "Can't create DHT file: $dht_file"
|
||||
return 1
|
||||
}
|
||||
|
||||
append_setting "enable-dht=true"
|
||||
append_setting "dht-file-path=$dht_file"
|
||||
fi
|
||||
|
||||
if [ ."$enable_dht6" = ."true" ] && [ ."$disable_ipv6" != ."true" ]; then
|
||||
dht6_file="$config_dir/dht6.dat.$section"
|
||||
_create_file "$dht6_file" || {
|
||||
_err "Can't create DHT6 file: $dht6_file"
|
||||
return 1
|
||||
}
|
||||
|
||||
append_setting "enable-dht6=true"
|
||||
append_setting "dht-file-path6=$dht6_file"
|
||||
fi
|
||||
|
||||
if [ -n "$bt_tracker" ]; then
|
||||
local bt_tracker_list; local t
|
||||
for t in $bt_tracker; do
|
||||
if [ -z "$bt_tracker_list" ]; then
|
||||
bt_tracker_list="$t"
|
||||
else
|
||||
bt_tracker_list="$bt_tracker_list,$t"
|
||||
fi
|
||||
done
|
||||
|
||||
append_setting "bt-tracker=$bt_tracker_list"
|
||||
fi
|
||||
|
||||
append_options "auto_save_interval" "bt_enable_lpd" "bt_max_open_files" "bt_max_peers" \
|
||||
"bt_remove_unselected_file" "bt_request_peer_speed_limit" "bt_prioritize_piece" \
|
||||
"bt_stop_timeout" "bt_detach_seed_only" "bt_save_metadata" "bt_load_saved_metadata" \
|
||||
"bt_seed_unverified" "certificate" "check_integrity" "connect_timeout" "dht_listen_port" \
|
||||
"disable_ipv6" "disk_cache" "enable_peer_exchange" "event_poll" "file_allocation" \
|
||||
"follow_torrent" "force_save" "http_accept_gzip" "http_no_cache" "listen_port" \
|
||||
"lowest_speed_limit" "max_concurrent_downloads" "max_connection_per_server" \
|
||||
"max_download_limit" "max_overall_download_limit" "max_overall_upload_limit" "max_tries" \
|
||||
"max_upload_limit" "min_split_size" "pause" "pause_metadata" "peer_id_prefix" "private_key" \
|
||||
"retry_wait" "rpc_listen_port" "save_session_interval" "seed_ratio" "seed_time" "split" "timeout" \
|
||||
"user_agent"
|
||||
|
||||
config_list_foreach "$section" "header" append_header
|
||||
config_list_foreach "$section" "extra_settings" append_setting
|
||||
|
||||
cd /usr/share/aria2 && sh ./tracker.sh >/dev/null 2>&1 &
|
||||
cat /usr/share/aria2/aria2.conf > "$config_file"
|
||||
echo '' >> "$config_file"
|
||||
sed '/^$/d' "$config_file_tmp" >> "$config_file"
|
||||
rm -f "$config_file_tmp"
|
||||
|
||||
_reset_dir_mode "$config_dir"
|
||||
_change_file_mode 600 "$config_file"
|
||||
|
||||
if [ -n "$user" ]; then
|
||||
if ( user_exists "$user" && _change_owner "$user" "$config_dir" "$log" ); then
|
||||
_info "Aria2 will run with user '$user'."
|
||||
if [ "$user" != "root" ]; then
|
||||
_info "Please make sure user '$user' has write access to download dir: $dir"
|
||||
fi
|
||||
else
|
||||
_info "Setting run user to '$user' failed, default user will be used."
|
||||
user=
|
||||
fi
|
||||
fi
|
||||
|
||||
procd_open_instance "$NAME.$section"
|
||||
procd_set_param command "$PROG"
|
||||
procd_append_param command --conf-path="$config_file"
|
||||
|
||||
procd_set_param respawn
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
|
||||
procd_set_param file "$config_file"
|
||||
[ -n "$user" ] && \
|
||||
procd_set_param user "$user"
|
||||
|
||||
procd_add_jail "$NAME.$section" log
|
||||
procd_add_jail_mount "/usr/lib/ossl-modules"
|
||||
procd_add_jail_mount "$ca_certificate" "$certificate" "$rpc_certificate" "$rpc_private_key"
|
||||
procd_add_jail_mount_rw "$dir" "$config_dir" "$log"
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$NAME"
|
||||
procd_add_validation aria2_validate
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$NAME"
|
||||
config_foreach aria2_validate "aria2" aria2_start
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
--- /src/OptionHandlerFactory.cc 2018-05-15 20:33:25.000000000 +0800
|
||||
+++ /src/OptionHandlerFactory.cc 2018-07-05 10:40:25.000000000 +0800
|
||||
@@ -440,7 +440,7 @@
|
||||
{
|
||||
OptionHandler* op(new NumberOptionHandler(PREF_MAX_CONNECTION_PER_SERVER,
|
||||
TEXT_MAX_CONNECTION_PER_SERVER,
|
||||
- "1", 1, 16, 'x'));
|
||||
+ "64", 1, -1, 'x'));
|
||||
op->addTag(TAG_BASIC);
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
@@ -501,7 +501,7 @@
|
||||
}
|
||||
{
|
||||
OptionHandler* op(new UnitNumberOptionHandler(
|
||||
- PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "20M", 1_m, 1_g, 'k'));
|
||||
+ PREF_MIN_SPLIT_SIZE, TEXT_MIN_SPLIT_SIZE, "1M", 1_k, 1_g, 'k'));
|
||||
op->addTag(TAG_BASIC);
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
@@ -905,7 +905,7 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
||||
}
|
||||
{
|
||||
OptionHandler* op(new UnitNumberOptionHandler(
|
||||
- PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_m, 1_g));
|
||||
+ PREF_PIECE_LENGTH, TEXT_PIECE_LENGTH, "1M", 1_k, 1_g));
|
||||
op->addTag(TAG_ADVANCED);
|
||||
op->addTag(TAG_FTP);
|
||||
op->addTag(TAG_HTTP);
|
||||
@@ -0,0 +1,61 @@
|
||||
From 66524bee738e98742c908d93c993d0a78a2d9891 Mon Sep 17 00:00:00 2001
|
||||
From: myfreeer <myfreeer@users.noreply.github.com>
|
||||
Date: Sat, 18 Nov 2017 11:55:04 +0800
|
||||
Subject: [PATCH 3/4] download: retry on slow speed and conection close
|
||||
|
||||
This would provide better speed on bad network conditions
|
||||
---
|
||||
src/DownloadCommand.cc | 2 +-
|
||||
src/SocketBuffer.cc | 3 ++-
|
||||
src/SocketCore.cc | 2 +-
|
||||
3 files changed, 4 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
|
||||
index 2db41e4..f49eb80 100644
|
||||
--- a/src/DownloadCommand.cc
|
||||
+++ b/src/DownloadCommand.cc
|
||||
@@ -306,7 +306,7 @@ void DownloadCommand::checkLowestDownloadSpeed() const
|
||||
startupIdleTime_) {
|
||||
int nowSpeed = peerStat_->calculateDownloadSpeed();
|
||||
if (nowSpeed <= lowestDownloadSpeedLimit_) {
|
||||
- throw DL_ABORT_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed,
|
||||
+ throw DL_RETRY_EX2(fmt(EX_TOO_SLOW_DOWNLOAD_SPEED, nowSpeed,
|
||||
lowestDownloadSpeedLimit_,
|
||||
getRequest()->getHost().c_str()),
|
||||
error_code::TOO_SLOW_DOWNLOAD_SPEED);
|
||||
diff --git a/src/SocketBuffer.cc b/src/SocketBuffer.cc
|
||||
index 62862ff..1906173 100644
|
||||
--- a/src/SocketBuffer.cc
|
||||
+++ b/src/SocketBuffer.cc
|
||||
@@ -39,6 +39,7 @@
|
||||
|
||||
#include "SocketCore.h"
|
||||
#include "DlAbortEx.h"
|
||||
+#include "DlRetryEx.h"
|
||||
#include "message.h"
|
||||
#include "fmt.h"
|
||||
#include "LogFactory.h"
|
||||
@@ -158,7 +159,7 @@ ssize_t SocketBuffer::send()
|
||||
}
|
||||
ssize_t slen = socket_->writeVector(iov, num);
|
||||
if (slen == 0 && !socket_->wantRead() && !socket_->wantWrite()) {
|
||||
- throw DL_ABORT_EX(fmt(EX_SOCKET_SEND, "Connection closed."));
|
||||
+ throw DL_RETRY_EX(fmt(EX_SOCKET_SEND, "Connection closed."));
|
||||
}
|
||||
// A2_LOG_NOTICE(fmt("num=%zu, amount=%d, bufq.size()=%zu, SEND=%d",
|
||||
// num, amount, bufq_.size(), slen));
|
||||
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
|
||||
index 77dc30c..537375a 100644
|
||||
--- a/src/SocketCore.cc
|
||||
+++ b/src/SocketCore.cc
|
||||
@@ -1009,7 +1009,7 @@ bool SocketCore::tlsHandshake(TLSContext* tlsctx, const std::string& hostname)
|
||||
|
||||
if (rv == TLS_ERR_ERROR) {
|
||||
// Damn those error.
|
||||
- throw DL_ABORT_EX(fmt("SSL/TLS handshake failure: %s",
|
||||
+ throw DL_RETRY_EX(fmt("SSL/TLS handshake failure: %s",
|
||||
handshakeError.empty()
|
||||
? tlsSession_->getLastErrorString().c_str()
|
||||
: handshakeError.c_str()));
|
||||
--
|
||||
2.17.1
|
||||
@@ -0,0 +1,239 @@
|
||||
From 8adbc01dc5975a64c55fe594d8c758c71e8183b3 Mon Sep 17 00:00:00 2001
|
||||
From: myfreeer <myfreeer@users.noreply.github.com>
|
||||
Date: Sun, 22 Jul 2018 19:59:02 +0800
|
||||
Subject: [PATCH] option: add option to retry on http 400, 403, 406, or unknown
|
||||
|
||||
--retry-on-400[=true|false] Configure whether retry or not when
|
||||
HTTP server returns 400 Bad Request.
|
||||
Only effective if retry-wait > 0.
|
||||
|
||||
Possible Values: true, false
|
||||
Default: false
|
||||
Tags: #advanced, #http
|
||||
|
||||
--retry-on-403[=true|false] Configure whether retry or not when
|
||||
HTTP server returns 403 Forbidden.
|
||||
Only effective if retry-wait > 0.
|
||||
|
||||
Possible Values: true, false
|
||||
Default: false
|
||||
Tags: #advanced, #http
|
||||
|
||||
--retry-on-406[=true|false] Configure whether retry or not when
|
||||
HTTP server returns 406 Not Acceptable.
|
||||
Only effective if retry-wait > 0.
|
||||
|
||||
Possible Values: true, false
|
||||
Default: false
|
||||
Tags: #advanced, #http
|
||||
|
||||
--retry-on-unknown[=true|false] Configure whether retry or not when
|
||||
HTTP server returns unknown status code.
|
||||
Only effective if retry-wait > 0.
|
||||
|
||||
Possible Values: true, false
|
||||
Default: false
|
||||
Tags: #advanced, #http
|
||||
---
|
||||
src/HttpSkipResponseCommand.cc | 42 +++++++++++++++++++++++++++++-----
|
||||
src/OptionHandlerFactory.cc | 40 ++++++++++++++++++++++++++++++++
|
||||
src/prefs.cc | 8 +++++++
|
||||
src/prefs.h | 8 +++++++
|
||||
src/usage_text.h | 16 +++++++++++++
|
||||
5 files changed, 108 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc
|
||||
index a722d77..de4ad6c 100644
|
||||
--- a/src/HttpSkipResponseCommand.cc
|
||||
+++ b/src/HttpSkipResponseCommand.cc
|
||||
@@ -204,7 +204,7 @@ bool HttpSkipResponseCommand::processResponse()
|
||||
auto statusCode = httpResponse_->getStatusCode();
|
||||
if (statusCode >= 400) {
|
||||
switch (statusCode) {
|
||||
- case 401:
|
||||
+ case 401: // Unauthorized
|
||||
if (getOption()->getAsBool(PREF_HTTP_AUTH_CHALLENGE) &&
|
||||
!httpResponse_->getHttpRequest()->authenticationUsed() &&
|
||||
getDownloadEngine()->getAuthConfigFactory()->activateBasicCred(
|
||||
@@ -213,15 +213,41 @@ bool HttpSkipResponseCommand::processResponse()
|
||||
return prepareForRetry(0);
|
||||
}
|
||||
throw DL_ABORT_EX2(EX_AUTH_FAILED, error_code::HTTP_AUTH_FAILED);
|
||||
- case 404:
|
||||
+ case 404: // Not Found
|
||||
if (getOption()->getAsInt(PREF_MAX_FILE_NOT_FOUND) == 0) {
|
||||
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
|
||||
error_code::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
throw DL_RETRY_EX2(MSG_RESOURCE_NOT_FOUND,
|
||||
error_code::RESOURCE_NOT_FOUND);
|
||||
- case 502:
|
||||
- case 503:
|
||||
+ case 400: // Bad Request
|
||||
+ if (getOption()->getAsBool(PREF_RETRY_ON_400)
|
||||
+ && getOption()->getAsInt(PREF_RETRY_WAIT) > 0) {
|
||||
+ throw DL_RETRY_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
+ error_code::HTTP_PROTOCOL_ERROR);
|
||||
+ }
|
||||
+ break;
|
||||
+ case 403: // Forbidden
|
||||
+ if (getOption()->getAsBool(PREF_RETRY_ON_403)
|
||||
+ && getOption()->getAsInt(PREF_RETRY_WAIT) > 0) {
|
||||
+ throw DL_RETRY_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
+ error_code::HTTP_PROTOCOL_ERROR);
|
||||
+ }
|
||||
+ break;
|
||||
+ case 406: // Not Acceptable
|
||||
+ if (getOption()->getAsBool(PREF_RETRY_ON_406)
|
||||
+ && getOption()->getAsInt(PREF_RETRY_WAIT) > 0) {
|
||||
+ throw DL_RETRY_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
+ error_code::HTTP_PROTOCOL_ERROR);
|
||||
+ }
|
||||
+ break;
|
||||
+ case 408: // Request Timeout
|
||||
+ case 429: // Too Many Requests
|
||||
+ case 502: // Bad Gateway
|
||||
+ case 503: // Service Unavailable
|
||||
+ case 507: // Insufficient Storage
|
||||
+ case 520: // https://github.com/aria2/aria2/issues/1229
|
||||
+ case 521: // https://github.com/aria2/aria2/issues/1229
|
||||
// Only retry if pretry-wait > 0. Hammering 'busy' server is not
|
||||
// a good idea.
|
||||
if (getOption()->getAsInt(PREF_RETRY_WAIT) > 0) {
|
||||
@@ -230,12 +256,16 @@ bool HttpSkipResponseCommand::processResponse()
|
||||
}
|
||||
throw DL_ABORT_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
error_code::HTTP_SERVICE_UNAVAILABLE);
|
||||
- case 504:
|
||||
+ case 504: // Gateway Timeout
|
||||
// This is Gateway Timeout, so try again
|
||||
throw DL_RETRY_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
error_code::HTTP_SERVICE_UNAVAILABLE);
|
||||
};
|
||||
-
|
||||
+ if (getOption()->getAsBool(PREF_RETRY_ON_UNKNOWN)
|
||||
+ && getOption()->getAsInt(PREF_RETRY_WAIT) > 0) {
|
||||
+ throw DL_RETRY_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
+ error_code::HTTP_PROTOCOL_ERROR);
|
||||
+ }
|
||||
throw DL_ABORT_EX2(fmt(EX_BAD_STATUS, statusCode),
|
||||
error_code::HTTP_PROTOCOL_ERROR);
|
||||
}
|
||||
diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc
|
||||
index 5768f7b..decb03e 100644
|
||||
--- a/src/OptionHandlerFactory.cc
|
||||
+++ b/src/OptionHandlerFactory.cc
|
||||
@@ -934,6 +934,46 @@ std::vector<OptionHandler*> OptionHandlerFactory::createOptionHandlers()
|
||||
op->setChangeOptionForReserved(true);
|
||||
handlers.push_back(op);
|
||||
}
|
||||
+ {
|
||||
+ OptionHandler* op(new BooleanOptionHandler(
|
||||
+ PREF_RETRY_ON_400, TEXT_RETRY_ON_400, A2_V_FALSE, OptionHandler::OPT_ARG));
|
||||
+ op->addTag(TAG_ADVANCED);
|
||||
+ op->addTag(TAG_HTTP);
|
||||
+ op->setInitialOption(true);
|
||||
+ op->setChangeGlobalOption(true);
|
||||
+ op->setChangeOptionForReserved(true);
|
||||
+ handlers.push_back(op);
|
||||
+ }
|
||||
+ {
|
||||
+ OptionHandler* op(new BooleanOptionHandler(
|
||||
+ PREF_RETRY_ON_403, TEXT_RETRY_ON_403, A2_V_FALSE, OptionHandler::OPT_ARG));
|
||||
+ op->addTag(TAG_ADVANCED);
|
||||
+ op->addTag(TAG_HTTP);
|
||||
+ op->setInitialOption(true);
|
||||
+ op->setChangeGlobalOption(true);
|
||||
+ op->setChangeOptionForReserved(true);
|
||||
+ handlers.push_back(op);
|
||||
+ }
|
||||
+ {
|
||||
+ OptionHandler* op(new BooleanOptionHandler(
|
||||
+ PREF_RETRY_ON_406, TEXT_RETRY_ON_406, A2_V_FALSE, OptionHandler::OPT_ARG));
|
||||
+ op->addTag(TAG_ADVANCED);
|
||||
+ op->addTag(TAG_HTTP);
|
||||
+ op->setInitialOption(true);
|
||||
+ op->setChangeGlobalOption(true);
|
||||
+ op->setChangeOptionForReserved(true);
|
||||
+ handlers.push_back(op);
|
||||
+ }
|
||||
+ {
|
||||
+ OptionHandler* op(new BooleanOptionHandler(
|
||||
+ PREF_RETRY_ON_UNKNOWN, TEXT_RETRY_ON_UNKNOWN, A2_V_FALSE, OptionHandler::OPT_ARG));
|
||||
+ op->addTag(TAG_ADVANCED);
|
||||
+ op->addTag(TAG_HTTP);
|
||||
+ op->setInitialOption(true);
|
||||
+ op->setChangeGlobalOption(true);
|
||||
+ op->setChangeOptionForReserved(true);
|
||||
+ handlers.push_back(op);
|
||||
+ }
|
||||
{
|
||||
OptionHandler* op(new BooleanOptionHandler(
|
||||
PREF_REUSE_URI, TEXT_REUSE_URI, A2_V_TRUE, OptionHandler::OPT_ARG));
|
||||
diff --git a/src/prefs.cc b/src/prefs.cc
|
||||
index 937e927..33eff91 100644
|
||||
--- a/src/prefs.cc
|
||||
+++ b/src/prefs.cc
|
||||
@@ -327,6 +327,14 @@ PrefPtr PREF_ENABLE_ASYNC_DNS6 = makePref("enable-async-dns6");
|
||||
PrefPtr PREF_MAX_DOWNLOAD_RESULT = makePref("max-download-result");
|
||||
// value: 1*digit
|
||||
PrefPtr PREF_RETRY_WAIT = makePref("retry-wait");
|
||||
+// value: true | false
|
||||
+PrefPtr PREF_RETRY_ON_400 = makePref("retry-on-400");
|
||||
+// value: true | false
|
||||
+PrefPtr PREF_RETRY_ON_403 = makePref("retry-on-403");
|
||||
+// value: true | false
|
||||
+PrefPtr PREF_RETRY_ON_406 = makePref("retry-on-406");
|
||||
+// value: true | false
|
||||
+PrefPtr PREF_RETRY_ON_UNKNOWN = makePref("retry-on-unknown");
|
||||
// value: string
|
||||
PrefPtr PREF_ASYNC_DNS_SERVER = makePref("async-dns-server");
|
||||
// value: true | false
|
||||
diff --git a/src/prefs.h b/src/prefs.h
|
||||
index e1f8397..019e774 100644
|
||||
--- a/src/prefs.h
|
||||
+++ b/src/prefs.h
|
||||
@@ -280,6 +280,14 @@ extern PrefPtr PREF_ENABLE_ASYNC_DNS6;
|
||||
extern PrefPtr PREF_MAX_DOWNLOAD_RESULT;
|
||||
// value: 1*digit
|
||||
extern PrefPtr PREF_RETRY_WAIT;
|
||||
+// value: true | false
|
||||
+extern PrefPtr PREF_RETRY_ON_400;
|
||||
+// value: true | false
|
||||
+extern PrefPtr PREF_RETRY_ON_403;
|
||||
+// value: true | false
|
||||
+extern PrefPtr PREF_RETRY_ON_406;
|
||||
+// value: true | false
|
||||
+extern PrefPtr PREF_RETRY_ON_UNKNOWN;
|
||||
// value: string
|
||||
extern PrefPtr PREF_ASYNC_DNS_SERVER;
|
||||
// value: true | false
|
||||
diff --git a/src/usage_text.h b/src/usage_text.h
|
||||
index d73b50d..75d34a0 100644
|
||||
--- a/src/usage_text.h
|
||||
+++ b/src/usage_text.h
|
||||
@@ -64,6 +64,22 @@
|
||||
_(" --retry-wait=SEC Set the seconds to wait between retries. \n" \
|
||||
" With SEC > 0, aria2 will retry download when the\n" \
|
||||
" HTTP server returns 503 response.")
|
||||
+#define TEXT_RETRY_ON_400 \
|
||||
+ _(" --retry-on-400[=true|false] Configure whether retry or not when\n" \
|
||||
+ " HTTP server returns 400 Bad Request.\n" \
|
||||
+ " Only effective if retry-wait > 0.")
|
||||
+#define TEXT_RETRY_ON_403 \
|
||||
+ _(" --retry-on-403[=true|false] Configure whether retry or not when\n" \
|
||||
+ " HTTP server returns 403 Forbidden.\n" \
|
||||
+ " Only effective if retry-wait > 0.")
|
||||
+#define TEXT_RETRY_ON_406 \
|
||||
+ _(" --retry-on-406[=true|false] Configure whether retry or not when\n" \
|
||||
+ " HTTP server returns 406 Not Acceptable.\n" \
|
||||
+ " Only effective if retry-wait > 0.")
|
||||
+#define TEXT_RETRY_ON_UNKNOWN \
|
||||
+ _(" --retry-on-unknown[=true|false] Configure whether retry or not when\n" \
|
||||
+ " HTTP server returns unknown status code.\n" \
|
||||
+ " Only effective if retry-wait > 0.")
|
||||
#define TEXT_TIMEOUT \
|
||||
_(" -t, --timeout=SEC Set timeout in seconds.")
|
||||
#define TEXT_MAX_TRIES \
|
||||
--
|
||||
2.18.0
|
||||
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Copyright (C) 2010-2011 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=autoshare-ksmbd
|
||||
PKG_VERSION:=1
|
||||
PKG_RELEASE:=11
|
||||
PKG_ARCH:=all
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/autoshare-ksmbd
|
||||
TITLE:=Samba autoconfig hotplug script.
|
||||
MAINTAINER:=Lean
|
||||
DEPENDS:=+wsdd2
|
||||
endef
|
||||
|
||||
define Package/autoshare-ksmbd/description
|
||||
A hotplug script to config Samba share automatically.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/autoshare-ksmbd/install
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/block
|
||||
$(INSTALL_BIN) ./files/20-smb-ksmbd $(1)/etc/hotplug.d/block/20-smb-ksmbd
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,autoshare-ksmbd))
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/service.sh
|
||||
|
||||
global=0
|
||||
config_file="/etc/config/ksmbd"
|
||||
|
||||
[ ! -f /etc/config/ksmbd ] && {
|
||||
echo "
|
||||
config globals
|
||||
option workgroup 'WORKGROUP'
|
||||
option charset 'UTF-8'
|
||||
option description 'Ksmbd on OpenWRT'
|
||||
" > $config_file
|
||||
}
|
||||
|
||||
wait_for_init() {
|
||||
for i in `seq 30`
|
||||
do
|
||||
[ -e /tmp/procd.done ] || {
|
||||
sleep 1; continue;
|
||||
}
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
smb_handle() {
|
||||
local path
|
||||
config_get path "$1" path
|
||||
if [ -n "$path" ]; then
|
||||
case "$path" in
|
||||
"$2" | "$2"/*) global=1 ;;
|
||||
esac
|
||||
case "$2" in
|
||||
"$path" | "$path"/*) global=1 ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
chk_en() {
|
||||
config_get_bool autoshare "$1" autoshare 1
|
||||
[ "$autoshare" -eq 0 ] && exit
|
||||
}
|
||||
|
||||
config_load ksmbd
|
||||
config_foreach chk_en ksmbd
|
||||
|
||||
device=`basename "$DEVPATH"`
|
||||
|
||||
case "$ACTION" in
|
||||
add)
|
||||
|
||||
case "$device" in
|
||||
sd*);;
|
||||
md*);;
|
||||
hd*);;
|
||||
mmcblk*);;
|
||||
nvme*);;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
path="/dev/$device"
|
||||
|
||||
wait_for_init
|
||||
|
||||
grep -v '/boot\|/opt' /proc/mounts | while read -r j
|
||||
do
|
||||
str=${j%% *}
|
||||
if [ "$str" = "$path" ];then
|
||||
strr=${j#* }
|
||||
target=${strr%% *}
|
||||
global=0
|
||||
|
||||
config_load ksmbd
|
||||
config_foreach smb_handle share "$target"
|
||||
|
||||
name=${target#*/mnt/}
|
||||
name=$(echo "$name" | sed -e "s/^\///")
|
||||
|
||||
if [ "$global" -eq 0 ] ;then
|
||||
echo -e "\n\nconfig share" >> $config_file
|
||||
echo -e "\toption auto '1'" >> $config_file
|
||||
echo -e "\toption name '$name'" >> $config_file
|
||||
echo -e "\toption path '$target'" >> $config_file
|
||||
echo -e "\toption read_only 'no'" >> $config_file
|
||||
echo -e "\toption guest_ok 'yes'" >> $config_file
|
||||
echo -e "\toption create_mask '0666'" >> $config_file
|
||||
echo -e "\toption dir_mask '0777'" >> $config_file
|
||||
echo -e "\toption device '$device'" >> $config_file
|
||||
echo -e "\toption force_root '1'" >> $config_file
|
||||
/etc/init.d/ksmbd reload
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
remove)
|
||||
i=0
|
||||
while true
|
||||
do
|
||||
if ! uci -q get ksmbd.@share[$i] >/dev/null; then
|
||||
break
|
||||
fi
|
||||
|
||||
dev=$(uci -q get ksmbd.@share[$i].device)
|
||||
if [ "$dev" = "$device" ]; then
|
||||
auto=$(uci -q get ksmbd.@share[$i].auto)
|
||||
if [ "$auto" = "1" ]; then
|
||||
uci delete ksmbd.@share[$i]
|
||||
uci commit ksmbd
|
||||
/etc/init.d/ksmbd reload
|
||||
return
|
||||
fi
|
||||
fi
|
||||
let i+=1
|
||||
done
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,35 @@
|
||||
#
|
||||
# Copyright (C) 2010-2011 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=autoshare-samba
|
||||
PKG_VERSION:=1
|
||||
PKG_RELEASE:=11
|
||||
PKG_ARCH:=all
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/autoshare-samba
|
||||
TITLE:=Samba autoconfig hotplug script.
|
||||
MAINTAINER:=Lean
|
||||
DEPENDS:=+wsdd2
|
||||
endef
|
||||
|
||||
define Package/autoshare-samba/description
|
||||
A hotplug script to config Samba share automatically.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/autoshare-samba/install
|
||||
$(INSTALL_DIR) $(1)/etc/hotplug.d/block
|
||||
$(INSTALL_BIN) ./files/20-smb $(1)/etc/hotplug.d/block/20-smb
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,autoshare-samba))
|
||||
@@ -0,0 +1,120 @@
|
||||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
. /lib/functions/service.sh
|
||||
|
||||
global=0
|
||||
config_file="/etc/config/samba4"
|
||||
|
||||
[ ! -f /etc/config/samba4 ] && {
|
||||
echo "
|
||||
config samba
|
||||
option workgroup 'WORKGROUP'
|
||||
option charset 'UTF-8'
|
||||
option description 'Samba on OpenWRT'
|
||||
" > $config_file
|
||||
}
|
||||
|
||||
wait_for_init() {
|
||||
for i in `seq 30`
|
||||
do
|
||||
[ -e /tmp/procd.done ] || {
|
||||
sleep 1; continue;
|
||||
}
|
||||
return
|
||||
done
|
||||
}
|
||||
|
||||
smb_handle() {
|
||||
local path
|
||||
config_get path "$1" path
|
||||
if [ -n "$path" ]; then
|
||||
case "$path" in
|
||||
"$2" | "$2"/*) global=1 ;;
|
||||
esac
|
||||
case "$2" in
|
||||
"$path" | "$path"/*) global=1 ;;
|
||||
esac
|
||||
fi
|
||||
}
|
||||
|
||||
chk_en() {
|
||||
config_get_bool autoshare "$1" autoshare 1
|
||||
[ "$autoshare" -eq 0 ] && exit
|
||||
}
|
||||
|
||||
config_load samba4
|
||||
config_foreach chk_en samba4
|
||||
|
||||
device=`basename "$DEVPATH"`
|
||||
|
||||
case "$ACTION" in
|
||||
add)
|
||||
|
||||
case "$device" in
|
||||
sd*);;
|
||||
md*);;
|
||||
hd*);;
|
||||
mmcblk*);;
|
||||
nvme*);;
|
||||
*) return;;
|
||||
esac
|
||||
|
||||
path="/dev/$device"
|
||||
|
||||
wait_for_init
|
||||
|
||||
grep -v '/boot\|/opt' /proc/mounts | while read -r j
|
||||
do
|
||||
str=${j%% *}
|
||||
if [ "$str" = "$path" ];then
|
||||
strr=${j#* }
|
||||
target=${strr%% *}
|
||||
global=0
|
||||
|
||||
config_load samba4
|
||||
config_foreach smb_handle sambashare "$target"
|
||||
|
||||
name=${target#*/mnt/}
|
||||
name=$(echo "$name" | sed -e "s/^\///")
|
||||
|
||||
if [ "$global" -eq 0 ] ;then
|
||||
echo -e "\n\nconfig sambashare" >> $config_file
|
||||
echo -e "\toption auto '1'" >> $config_file
|
||||
echo -e "\toption name '$name'" >> $config_file
|
||||
echo -e "\toption path '$target'" >> $config_file
|
||||
echo -e "\toption read_only 'no'" >> $config_file
|
||||
echo -e "\toption guest_ok 'yes'" >> $config_file
|
||||
echo -e "\toption create_mask '0666'" >> $config_file
|
||||
echo -e "\toption dir_mask '0777'" >> $config_file
|
||||
echo -e "\toption device '$device'" >> $config_file
|
||||
echo -e "\toption force_root '1'" >> $config_file
|
||||
/etc/init.d/samba4 reload
|
||||
return
|
||||
fi
|
||||
fi
|
||||
done
|
||||
;;
|
||||
|
||||
remove)
|
||||
i=0
|
||||
while true
|
||||
do
|
||||
if ! uci -q get samba4.@sambashare[$i] >/dev/null; then
|
||||
break
|
||||
fi
|
||||
|
||||
dev=$(uci -q get samba4.@sambashare[$i].device)
|
||||
if [ "$dev" = "$device" ]; then
|
||||
auto=$(uci -q get samba4.@sambashare[$i].auto)
|
||||
if [ "$auto" = "1" ]; then
|
||||
uci delete samba4.@sambashare[$i]
|
||||
uci commit samba4
|
||||
/etc/init.d/samba4 reload
|
||||
return
|
||||
fi
|
||||
fi
|
||||
let i+=1
|
||||
done
|
||||
;;
|
||||
esac
|
||||
@@ -0,0 +1,46 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2009-2013 OpenWrt.org
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=BaiduPCS-Go
|
||||
PKG_VERSION:=3.9.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/qjfoidnh/BaiduPCS-Go/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=de71666e961a3eeb90f8aca7b11934c3f0296d1870e036a7c086ba1decfca8ab
|
||||
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
|
||||
GO_PKG:=github.com/qjfoidnh/BaiduPCS-Go
|
||||
GO_PKG_LDFLAGS_X:=main.Version=v$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../../lang/golang/golang-package.mk
|
||||
|
||||
define Package/BaiduPCS-Go
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Download Manager
|
||||
TITLE:=Terminal utility for Baidu Network Disk
|
||||
URL:=https://github.com/qjfoidnh/BaiduPCS-Go
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
|
||||
endef
|
||||
|
||||
define Package/BaiduPCS-Go/install
|
||||
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/bin/
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/bin/BaiduPCS-Go $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,BaiduPCS-Go))
|
||||
$(eval $(call BuildPackage,BaiduPCS-Go))
|
||||
Executable
+8
@@ -0,0 +1,8 @@
|
||||
__
|
||||
___ ___ ___ ___ _ ______/ /_
|
||||
/ _ \/ _ \/ -_) _ \ |/|/ / __/ __/
|
||||
\___/ .__/\__/_//_/__,__/_/ \__/
|
||||
/_/
|
||||
--------------------------------
|
||||
%D %V, %C
|
||||
--------------------------------
|
||||
@@ -0,0 +1,57 @@
|
||||
#
|
||||
# Copyright (C) 2006-2009 OpenWrt.org
|
||||
# Copyright (C) 2005-2016 Weijie Gao <hackpascal@gmail.com>
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=brlaser
|
||||
PKG_VERSION:=v3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE_URL:=https://github.com/pdewacht/brlaser.git
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
|
||||
PKG_SOURCE_VERSION:=2a49e3287c70c254e7e3ac9dabe9d6a07218c3fa
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||
|
||||
PKG_FIXUP:=autoreconf
|
||||
|
||||
PKG_INSTALL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/cmake.mk
|
||||
|
||||
define Package/brlaser
|
||||
SECTION:=print
|
||||
CATEGORY:=Printing and Imaging
|
||||
TITLE:=Driver for (some) Brother laster printers
|
||||
DEPENDS:=+libcupsimage +libstdcpp
|
||||
MAINTAINER:=Weijie Gao <hackpascal@gmail.com>
|
||||
URL:=https://github.com/pdewacht/brlaser
|
||||
endef
|
||||
|
||||
define Package/brlaser/description
|
||||
Driver for Brother DCP-7030 / Brother DCP-7055 / Brother DCP-7065DN
|
||||
endef
|
||||
|
||||
define Package/brlaser/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/cups/filter
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/cups/filter/rastertobrlaser $(1)/usr/lib/cups/filter/
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/cups/drv
|
||||
$(INSTALL_DATA) $(PKG_INSTALL_DIR)/usr/share/cups/drv/brlaser.drv $(1)/usr/share/cups/drv/
|
||||
|
||||
(cd $(PKG_BUILD_DIR) && ppdc brlaser.drv)
|
||||
|
||||
$(INSTALL_DIR) $(1)/usr/share/ppd/Brother
|
||||
$(CP) $(PKG_BUILD_DIR)/ppd/*.ppd $(1)/usr/share/ppd/Brother
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/uci-defaults
|
||||
$(INSTALL_BIN) ./files/brlaser-set-cups-filter-permission $(1)/etc/uci-defaults/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,brlaser))
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
|
||||
[ -d /usr/lib/cups/filter ] && chmod 0754 /usr/lib/cups/filter/*
|
||||
@@ -0,0 +1,45 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021-2023 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=brook
|
||||
PKG_VERSION:=20260101.0
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/txthinking/brook/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=8ddba4ed9ae9d10928e169f8121c6791e0e3c2907fa27d6e0055fe434f6e700e
|
||||
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
PKG_LICENSE:=GPL-3.0
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_USE_MIPS16:=0
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/txthinking/brook
|
||||
GO_PKG_BUILD_PKG:=$(GO_PKG)/cli/brook
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
define Package/brook
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=A cross-platform proxy software
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
|
||||
URL:=https://github.com/txthinking/brook
|
||||
endef
|
||||
|
||||
define Package/brook/description
|
||||
Brook is a cross-platform strong encryption and not detectable proxy.
|
||||
Zero-Configuration.
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,brook))
|
||||
$(eval $(call BuildPackage,brook))
|
||||
@@ -0,0 +1,72 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=chinadns-ng
|
||||
PKG_VERSION:=2025.08.09
|
||||
PKG_RELEASE:=1
|
||||
|
||||
ifeq ($(ARCH),aarch64)
|
||||
ifeq ($(BOARD),rockchip)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@aarch64-linux-musl@generic+v8a@fast+lto
|
||||
PKG_HASH:=3fe0217615dd7060b7287d2b6b31d2a0b364137398bfb335a03bead322eac716
|
||||
else
|
||||
PKG_ARCH:=chinadns-ng+wolfssl_noasm@aarch64-linux-musl@generic+v8a@fast+lto
|
||||
PKG_HASH:=42ddd494200ec6d88b35902927688d316bc23e06e6c08d9e01eb2412196ab845
|
||||
endif
|
||||
else ifeq ($(ARCH),arm)
|
||||
ARM_CPU_FEATURES:=$(word 2,$(subst +,$(space),$(call qstrip,$(CONFIG_CPU_TYPE))))
|
||||
ifeq ($(ARM_CPU_FEATURES),)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@arm-linux-musleabi@generic+v6+soft_float@fast+lto
|
||||
PKG_HASH:=0a401d1dc11129481b2baf86f847d55d66bd7e725cba4bf57875fdad27ef0052
|
||||
else
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@arm-linux-musleabihf@generic+v7a@fast+lto
|
||||
PKG_HASH:=dfa1f6ba80fb0925613822f4c4e00df8da68e7b8b772048d26a0d1a9d07d346b
|
||||
endif
|
||||
else ifeq ($(ARCH),mips)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@mips-linux-musl@mips32+soft_float@fast+lto
|
||||
PKG_HASH:=b610821a8f61b0ed3c8c7e82e10d401348a9de17f900988589024a37c4099c8e
|
||||
else ifeq ($(ARCH),mipsel)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@mipsel-linux-musl@mips32+soft_float@fast+lto
|
||||
PKG_HASH:=760544a88724e3b1b9eac79c9400231e81aa8786f8f00a979229e175811ffe6d
|
||||
else ifeq ($(ARCH),mips64)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@mips64-linux-musl@mips64+soft_float@fast+lto
|
||||
PKG_HASH:=2d0fce18a7ef1d74fdc12738767e66998a52c2b30d8790da760933853fe8726e
|
||||
else ifeq ($(ARCH),i386)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@i386-linux-musl@i686@fast+lto
|
||||
PKG_HASH:=85e057dd0a0e8913b30471737436ab8b71834c494ed9f9e53544261b1ffdc8d6
|
||||
else ifeq ($(ARCH),x86_64)
|
||||
PKG_ARCH:=chinadns-ng+wolfssl@x86_64-linux-musl@x86_64@fast+lto
|
||||
PKG_HASH:=842ea4e9816efd91d39bc76ead5c4a42e79011757e37c521b4270b675cfcb30c
|
||||
else
|
||||
PKG_HASH:=dummy
|
||||
endif
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_ARCH)
|
||||
PKG_SOURCE_URL:=https://github.com/zfl9/chinadns-ng/releases/download/$(PKG_VERSION)/$(PKG_ARCH)?
|
||||
UNPACK_CMD=$(CP) $(DL_DIR)/$(PKG_SOURCE) $(PKG_BUILD_DIR)/$(PKG_NAME)
|
||||
|
||||
PKG_LICENSE:=AGPL-3.0-only
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_MAINTAINER:=sbwml <admin@cooluc.com>
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/chinadns-ng
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=ChinaDNS next generation, refactoring with epoll and ipset.
|
||||
URL:=https://github.com/zfl9/chinadns-ng
|
||||
DEPENDS:=@(aarch64||arm||i386||mips||mipsel||mips64||x86_64) +ipset
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/chinadns-ng/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/chinadns-ng $(1)/usr/bin
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,chinadns-ng))
|
||||
@@ -0,0 +1,60 @@
|
||||
#
|
||||
# Copyright (C) 2017-2024
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=CloudDrive2
|
||||
PKG_VERSION:=0.8.16
|
||||
PKG_RELEASE=1
|
||||
|
||||
ifeq ($(ARCH),x86_64)
|
||||
PKG_ARCH:=x86_64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),aarch64)
|
||||
PKG_ARCH:=aarch64
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH),arm)
|
||||
PKG_ARCH:=armv7
|
||||
endif
|
||||
|
||||
PKG_SOURCE:=clouddrive-2-linux-$(PKG_ARCH)-$(PKG_VERSION).tgz
|
||||
PKG_SOURCE_URL:=https://github.com/cloud-fs/cloud-fs.github.io/releases/download/v$(PKG_VERSION)
|
||||
PKG_HASH:=skip
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/clouddrive2
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=@(arm||aarch64||x86_64) +fuse3-utils
|
||||
TITLE:=CloudDrive2
|
||||
endef
|
||||
|
||||
define Package/clouddrive2/description
|
||||
CloudDrive2 is a cloud storage mounting tool for OpenWrt.
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
tar -xzvf $(DL_DIR)/clouddrive-2-linux-$(PKG_ARCH)-$(PKG_VERSION).tgz -C $(PKG_BUILD_DIR)/ --strip-components=1
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
endef
|
||||
|
||||
define Package/clouddrive2/install
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/clouddrive2.init $(1)/etc/init.d/clouddrive2
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/clouddrive2.config $(1)/etc/config/clouddrive2
|
||||
$(INSTALL_DIR) $(1)/usr/share/clouddrive2
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/clouddrive-2-linux-$(PKG_ARCH)-$(PKG_VERSION)/clouddrive $(1)/usr/share/clouddrive2/
|
||||
cp -rf $(PKG_BUILD_DIR)/clouddrive-2-linux-$(PKG_ARCH)-$(PKG_VERSION)/wwwroot $(1)/usr/share/clouddrive2/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,clouddrive2))
|
||||
@@ -0,0 +1,4 @@
|
||||
config clouddrive2 'main'
|
||||
option enabled '0'
|
||||
option port '19798'
|
||||
option mount_point '/mnt/clouddrive'
|
||||
@@ -0,0 +1,41 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
STOP=15
|
||||
USE_PROCD=1
|
||||
|
||||
SERVICE=clouddrive2
|
||||
PROGDIR=/usr/share/clouddrive2/clouddrive
|
||||
|
||||
load_config() {
|
||||
config_load 'clouddrive2'
|
||||
config_get_bool enabled main enabled 1
|
||||
config_get port main port 19798
|
||||
config_get mount_point main mount_point '/mnt/clouddrive'
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "clouddrive2"
|
||||
}
|
||||
|
||||
start_service() {
|
||||
load_config
|
||||
[ "$enabled" = "1" ] || return
|
||||
|
||||
[ -d "$mount_point" ] || mkdir -p "$mount_point"
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command "$PROGDIR"
|
||||
procd_append_param command -p "$port"
|
||||
procd_append_param command -m "$mount_point"
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
echo "$SERVICE started on port $port, mounted at $mount_point"
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
load_config
|
||||
echo "Stopping $SERVICE"
|
||||
killall -q clouddrive
|
||||
[ -d "$mount_point" ] && fusermount3 -u "$mount_point"
|
||||
}
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
#
|
||||
# Copyright (C) 2006-2016 OpenWrt.org
|
||||
# Copyright (C) 2016 lede-project.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=cups
|
||||
PKG_VERSION:=2.3.3op2
|
||||
PKG_RELEASE:=2
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-source.tar.gz
|
||||
PKG_SOURCE_URL:=https://github.com/OpenPrinting/cups/releases/download/v$(PKG_VERSION)
|
||||
PKG_MD5SUM:=524266752cf243c968921547b18ee594
|
||||
|
||||
TARGET_LDFLAGS+=-Wl,-rpath-link=$(STAGING_DIR)/usr/lib
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/cups/Default
|
||||
URL:=http://www.cups.org/
|
||||
SUBMENU:=Printing
|
||||
endef
|
||||
|
||||
define Package/cups
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libcups +libcupsmime +libcupscgi +libcupsppdc +libusb-1.0
|
||||
TITLE:=Common UNIX Printing System (daemon)
|
||||
endef
|
||||
|
||||
define Package/cups/description
|
||||
Common UNIX Printing System (daemon)
|
||||
endef
|
||||
|
||||
define Package/cups/conffiles
|
||||
/etc/config/cupsd
|
||||
/etc/cups/classes.conf
|
||||
/etc/cups/cupsd.conf
|
||||
/etc/cups/printers.conf
|
||||
/etc/cups/ppd/
|
||||
endef
|
||||
|
||||
define Package/cups-bsd
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libcups
|
||||
TITLE:=Common UNIX Printing System - BSD commands (old)
|
||||
endef
|
||||
|
||||
define Package/cups-bsd/description
|
||||
Common UNIX Printing System - BSD commands (old)
|
||||
endef
|
||||
|
||||
define Package/cups-client
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libcups +libcupsimage +libcupsmime
|
||||
TITLE:=Common UNIX Printing System - Client commands
|
||||
endef
|
||||
|
||||
define Package/cups-client/conffiles
|
||||
/etc/cups/client.conf
|
||||
endef
|
||||
|
||||
define Package/cups-client/description
|
||||
Common UNIX Printing System - Client commands
|
||||
endef
|
||||
|
||||
define Package/cups-filters
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libcupsimage
|
||||
TITLE:=Common UNIX Printing System - Filter
|
||||
endef
|
||||
|
||||
define Package/cups-filters/description
|
||||
Common UNIX Printing System - Filter
|
||||
endef
|
||||
|
||||
define Package/cups-ppdc
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libcupsppdc
|
||||
TITLE:=Common UNIX Printing System - PPDC utils
|
||||
endef
|
||||
|
||||
define Package/cups-ppdc/description
|
||||
Common UNIX Printing System - PPDC utils
|
||||
endef
|
||||
|
||||
define Package/libcups
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+zlib +libpthread +libpng +libjpeg
|
||||
TITLE:=Common UNIX Printing System - Core library
|
||||
endef
|
||||
|
||||
define Package/libcups/description
|
||||
Common UNIX Printing System - Core library
|
||||
endef
|
||||
|
||||
define Package/libcupscgi
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+libcups
|
||||
TITLE:=Common UNIX Printing System - CGI library
|
||||
endef
|
||||
|
||||
define Package/libcupscgi/description
|
||||
Common UNIX Printing System - CGI library
|
||||
endef
|
||||
|
||||
define Package/libcupsimage
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+libcups
|
||||
TITLE:=Common UNIX Printing System - Image library
|
||||
endef
|
||||
|
||||
define Package/libcupsimage/description
|
||||
Common UNIX Printing System - Image library
|
||||
endef
|
||||
|
||||
define Package/libcupsmime
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+libcups
|
||||
TITLE:=Common UNIX Printing System - MIME library
|
||||
endef
|
||||
|
||||
define Package/libcupsmime/description
|
||||
Common UNIX Printing System - MIME library
|
||||
endef
|
||||
|
||||
define Package/libcupsppdc
|
||||
$(call Package/cups/Default)
|
||||
SECTION:=libs
|
||||
CATEGORY:=Libraries
|
||||
DEPENDS:=+libcups +libstdcpp
|
||||
TITLE:=Common UNIX Printing System - PPDC library
|
||||
endef
|
||||
|
||||
define Package/libcupsppdc/description
|
||||
Common UNIX Printing System - PPDC library
|
||||
endef
|
||||
|
||||
define Build/Configure
|
||||
$(call Build/Configure/Default, \
|
||||
--with-cups-user="nobody" \
|
||||
--with-cups-group="nogroup" \
|
||||
--with-system-groups="root" \
|
||||
--with-pdftops="none" \
|
||||
--without-perl \
|
||||
--without-python \
|
||||
--without-php \
|
||||
--enable-default-shared \
|
||||
--enable-shared \
|
||||
--enable-image \
|
||||
--enable-libusb \
|
||||
--disable-acl \
|
||||
--disable-dnssd \
|
||||
--disable-dbus \
|
||||
--disable-avahi \
|
||||
--disable-launchd \
|
||||
--disable-ldap \
|
||||
--disable-pam \
|
||||
--disable-slp \
|
||||
--disable-gnutls \
|
||||
--disable-openssl \
|
||||
--disable-cdsassl \
|
||||
--disable-ssl \
|
||||
--disable-gssapi \
|
||||
--disable-tiff, \
|
||||
UNAME="Linux" \
|
||||
LIBS="$(TARGET_LDFLAGS) -lz -lpng -ljpeg" \
|
||||
)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(MAKE) -C $(PKG_BUILD_DIR) \
|
||||
$(TARGET_CONFIGURE_OPTS) \
|
||||
DSTROOT="$(PKG_INSTALL_DIR)" \
|
||||
STRIP="/bin/true" \
|
||||
all install
|
||||
endef
|
||||
|
||||
define Package/cups/install
|
||||
rm -rf $(1)/etc/cups
|
||||
$(INSTALL_DIR) $(1)/etc/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/etc/cups/* $(1)/etc/cups/
|
||||
rm -rf $(1)/etc/cups/certs
|
||||
ln -sf /tmp $(1)/etc/cups/certs
|
||||
rm -f $(1)/usr/bin/cups-config
|
||||
$(INSTALL_DIR) $(1)/usr/lib/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/backend $(1)/usr/lib/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/cgi-bin $(1)/usr/lib/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/daemon $(1)/usr/lib/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/driver $(1)/usr/lib/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/monitor $(1)/usr/lib/cups
|
||||
$(INSTALL_DIR) $(1)/usr/lib/cups/filter
|
||||
### $(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/filter/{commandtops,pstops} \
|
||||
$(PKG_INSTALL_DIR)/usr/lib/cups/filter/gziptoany \
|
||||
$(1)/usr/lib/cups/filter
|
||||
$(INSTALL_DIR) $(1)/usr/share/cups/templates
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/cups/templates/*.tmpl \
|
||||
$(1)/usr/share/cups/templates/
|
||||
$(INSTALL_DIR) $(1)/usr/share/cups/mime
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/cups/mime/* $(1)/usr/share/cups/mime/
|
||||
### Do install docs: cups web interface relies on them
|
||||
$(INSTALL_DIR) $(1)/usr/share/doc/cups
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/doc/cups/*.*html \
|
||||
$(1)/usr/share/doc/cups/
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/doc/cups/*.css \
|
||||
$(1)/usr/share/doc/cups/
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/doc/cups/*.txt \
|
||||
$(1)/usr/share/doc/cups/
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/share/doc/cups/images \
|
||||
$(1)/usr/share/doc/cups/
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
# overwrite default config with our own
|
||||
$(CP) ./files/etc/cups/* $(1)/etc/cups/
|
||||
$(CP) ./files/etc/cups/cupsd.conf $(1)/etc/cups/cupsd.conf.default
|
||||
# install initscript with priority 60
|
||||
$(INSTALL_DIR) $(1)/etc/init.d $(1)/etc/config
|
||||
$(INSTALL_BIN) ./files/cupsd.init $(1)/etc/init.d/cupsd
|
||||
$(INSTALL_CONF) ./files/cupsd.config $(1)/etc/config/cupsd
|
||||
$(INSTALL_BIN) \
|
||||
$(PKG_INSTALL_DIR)/usr/sbin/{cupsctl,cupsd} \
|
||||
$(1)/usr/sbin/
|
||||
# needed for cups to find usb printers per http://wiki.openwrt.org/doc/howto/cups.server
|
||||
chmod 700 $(1)/usr/lib/cups/backend/usb
|
||||
endef
|
||||
|
||||
define Package/cups-bsd/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/{lprm,lpq,lpr} $(1)/usr/bin/
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/lpc $(1)/usr/sbin/
|
||||
endef
|
||||
|
||||
define Package/cups-client/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) \
|
||||
$(PKG_INSTALL_DIR)/usr/bin/{lp,cancel,cupstestppd} \
|
||||
$(PKG_INSTALL_DIR)/usr/bin/{ipptool,lpoptions,lpstat} \
|
||||
$(1)/usr/bin/
|
||||
$(INSTALL_DIR) $(1)/usr/sbin
|
||||
$(INSTALL_BIN) \
|
||||
$(PKG_INSTALL_DIR)/usr/sbin/{cupsaccept,cupsfilter} \
|
||||
$(PKG_INSTALL_DIR)/usr/sbin/{lpadmin,lpinfo,lpmove} \
|
||||
$(1)/usr/sbin/
|
||||
(cd $(1)/usr/sbin; ln -sf cupsaccept accept; ln -sf cupsaccept cupsenable; ln -sf cupsaccept cupsdisable; ln -sf cupsaccept reject; ln -sf cupsaccept cupsreject;)
|
||||
endef
|
||||
|
||||
define Package/cups-filters/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/cups/filter
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/lib/cups/filter/{rastertoepson,rastertohp,rastertolabel,rastertopwg} \
|
||||
$(1)/usr/lib/cups/filter
|
||||
(cd $(1)/usr/lib/cups/filter; ln -sf rastertolabel rastertodymo;)
|
||||
endef
|
||||
|
||||
define Package/cups-ppdc/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) \
|
||||
$(PKG_INSTALL_DIR)/usr/bin/{ppdc,ppdhtml,ppdi,ppdmerge,ppdpo} \
|
||||
$(1)/usr/bin/
|
||||
endef
|
||||
|
||||
define Package/libcups/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/cups/libcups.so* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libcupscgi/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/cgi-bin/libcupscgi.a $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libcupsimage/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/cups/libcupsimage.so* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libcupsmime/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/scheduler/libcupsmime.a $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Package/libcupsppdc/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/ppdc/libcupsppdc.a $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
define Build/InstallDev
|
||||
$(INSTALL_DIR) $(2)/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/cups-config $(2)/bin/
|
||||
$(INSTALL_DIR) $(1)/usr/include
|
||||
$(CP) $(PKG_INSTALL_DIR)/usr/include/cups $(1)/usr/include/
|
||||
$(INSTALL_DIR) $(1)/usr/lib
|
||||
$(CP) $(PKG_BUILD_DIR)/cups/libcups*.so* $(1)/usr/lib/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,cups))
|
||||
$(eval $(call BuildPackage,libcups))
|
||||
$(eval $(call BuildPackage,libcupscgi))
|
||||
$(eval $(call BuildPackage,libcupsimage))
|
||||
$(eval $(call BuildPackage,libcupsmime))
|
||||
$(eval $(call BuildPackage,libcupsppdc))
|
||||
$(eval $(call BuildPackage,cups-bsd))
|
||||
$(eval $(call BuildPackage,cups-client))
|
||||
$(eval $(call BuildPackage,cups-filters))
|
||||
$(eval $(call BuildPackage,cups-ppdc))
|
||||
@@ -0,0 +1,5 @@
|
||||
|
||||
config cupsd
|
||||
option enabled '0'
|
||||
option logger '1'
|
||||
option port '631'
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2006-2011 OpenWrt.org
|
||||
# Copyright (C) 2021-2022 sirpdboy <herboy2008@gmail.com> https://github.com/sirpdboy/luci-app-cupsd
|
||||
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
|
||||
PROG=/usr/sbin/cupsd
|
||||
get_config() {
|
||||
config_get_bool enabled $1 enabled 1
|
||||
config_get_bool logger $1 logger 1
|
||||
config_get port $1 port 631
|
||||
}
|
||||
|
||||
|
||||
start_service() {
|
||||
config_load cupsd
|
||||
config_foreach get_config cupsd
|
||||
[ x$enabled == x1 ] || return 1
|
||||
sed -i "s/Port.*/Port ${port}/g" /etc/cups/cupsd.conf
|
||||
[ -d /var/cache/cups ] || mkdir -m 0755 -p /var/cache/cups
|
||||
[ -d /var/cups ] || mkdir -m 0755 -p /var/cups
|
||||
[ -d /var/spool/cups/tmp ] || mkdir -m 0755 -p /var/spool/cups/tmp
|
||||
logger -t cupsd -p warn "cupsd is start."
|
||||
echo "cupsd is start."
|
||||
procd_open_instance
|
||||
procd_set_param command $PROG -f
|
||||
[ "x$logger" == x1 ] && procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "cupsd"
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
########################################################################
|
||||
# #
|
||||
# This is a sample class configuration file. This file is included #
|
||||
# from the main configuration file (cups.conf) and lists all of the #
|
||||
# printer classes known to the system. #
|
||||
# #
|
||||
########################################################################
|
||||
@@ -0,0 +1,9 @@
|
||||
########################################################################
|
||||
# #
|
||||
# This is the CUPS client configuration file. This file is used to #
|
||||
# define client-specific parameters, such as the default server or #
|
||||
# default encryption settings. #
|
||||
# #
|
||||
########################################################################
|
||||
|
||||
Encryption Never
|
||||
@@ -0,0 +1,58 @@
|
||||
########################################################################
|
||||
# #
|
||||
# This is the CUPS configuration file. If you are familiar with #
|
||||
# Apache or any of the other popular web servers, we've followed the #
|
||||
# same format. Any configuration variable used here has the same #
|
||||
# semantics as the corresponding variable in Apache. If we need #
|
||||
# different functionality then a different name is used to avoid #
|
||||
# confusion... #
|
||||
# #
|
||||
########################################################################
|
||||
|
||||
|
||||
AccessLog syslog
|
||||
ErrorLog syslog
|
||||
LogLevel info
|
||||
PageLog syslog
|
||||
PreserveJobHistory No
|
||||
PreserveJobFiles No
|
||||
AutoPurgeJobs Yes
|
||||
MaxJobs 25
|
||||
MaxPrinterHistory 10
|
||||
#Printcap /etc/printcap
|
||||
#PrintcapFormat BSD
|
||||
RequestRoot /var/cups
|
||||
#RemoteRoot remroot
|
||||
#User nobody
|
||||
#Group nogroup
|
||||
# root permissions required to make cups work with the usb backend
|
||||
User root
|
||||
Group root
|
||||
RIPCache auto
|
||||
TempDir /var/cups
|
||||
Port 631
|
||||
HostNameLookups On
|
||||
KeepAlive On
|
||||
# No: "BrowseOrder" "BrowseAllow" "BrowseRemoteProtocols"
|
||||
Browsing Yes
|
||||
BrowsingWebIF Yes
|
||||
BrowseLocalProtocols DNSSD
|
||||
DefaultShared Yes
|
||||
WebInterface Yes
|
||||
Listen /var/run/cups/cups.sock
|
||||
|
||||
ServerAlias *
|
||||
|
||||
<Location />
|
||||
Order Allow,Deny
|
||||
Allow all
|
||||
|
||||
</Location>
|
||||
|
||||
<Location /admin>
|
||||
AuthType Basic
|
||||
AuthClass System
|
||||
Order Allow,Deny
|
||||
Allow all
|
||||
|
||||
</Location>
|
||||
@@ -0,0 +1,23 @@
|
||||
<DefaultPrinter USB>
|
||||
Info USB Printer
|
||||
Location
|
||||
DeviceURI usb:/dev/usb/lp0
|
||||
State Idle
|
||||
Accepting Yes
|
||||
JobSheets none none
|
||||
QuotaPeriod 0
|
||||
PageLimit 0
|
||||
KLimit 0
|
||||
</Printer>
|
||||
|
||||
<Printer LP>
|
||||
Info Parallel Port Printer
|
||||
Location
|
||||
DeviceURI parallel:/dev/printers/0
|
||||
State Idle
|
||||
Accepting Yes
|
||||
JobSheets none none
|
||||
QuotaPeriod 0
|
||||
PageLimit 0
|
||||
KLimit 0
|
||||
</Printer>
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2023 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dae
|
||||
PKG_VERSION:=2026.05.08
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=2b3c63f9720654b6c1dc89c91644651ccb6be486
|
||||
PKG_SOURCE_URL:=https://github.com/olicesx/dae.git
|
||||
PKG_MIRROR_HASH:=skip
|
||||
|
||||
PKG_LICENSE:=AGPL-3.0-only
|
||||
PKG_LICENSE_FILE:=LICENSE
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host bpf-headers
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/daeuniverse/dae
|
||||
GO_PKG_EXCLUDES:=control/kern/tests
|
||||
|
||||
GO_PKG_LDFLAGS:= \
|
||||
-s -w -buildid= \
|
||||
-linkmode external -extldflags '-static -Wl,-s'
|
||||
GO_PKG_LDFLAGS_X:= \
|
||||
$(GO_PKG)/cmd.Version=$(PKG_VERSION) \
|
||||
$(GO_PKG)/common/consts.MaxMatchSetLen_=1024
|
||||
GO_PKG_TAGS:=trace
|
||||
|
||||
PGO_PROFILE:=$(CURDIR)/pprof/default.pgo
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/bpf.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
GO_PKG_BUILD_VARS+= \
|
||||
GOFLAGS="-trimpath -buildvcs=false -pgo=auto"
|
||||
|
||||
GO_PKG_TARGET_VARS+= \
|
||||
CGO_LDFLAGS="$(TARGET_LDFLAGS) -static -Wl,-s" \
|
||||
GOEXPERIMENT=newinliner,simd
|
||||
|
||||
define Package/dae
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
TITLE:=A lightweight and high-performance transparent proxy solution
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) \
|
||||
+ca-bundle +kmod-sched-core +kmod-sched-bpf \
|
||||
+kmod-veth +v2ray-geoip +v2ray-geosite \
|
||||
+@KERNEL_XDP_SOCKETS \
|
||||
+DAE_USE_VMLINUX_BTF:vmlinux-btf
|
||||
endef
|
||||
|
||||
define Package/dae/config
|
||||
choice
|
||||
prompt "BTF source for CO-RE"
|
||||
default DAE_USE_KERNEL_BTF
|
||||
depends on PACKAGE_dae
|
||||
|
||||
config DAE_USE_KERNEL_BTF
|
||||
bool "Use kernel BTF (integrated)"
|
||||
depends on KERNEL_DEBUG_INFO_BTF
|
||||
|
||||
config DAE_USE_VMLINUX_BTF
|
||||
bool "Use vmlinux-btf package"
|
||||
endchoice
|
||||
endef
|
||||
|
||||
define Package/dae/conffiles
|
||||
/etc/dae/
|
||||
/etc/config/dae
|
||||
endef
|
||||
|
||||
DAE_CFLAGS:= \
|
||||
-O2 -Wall -Werror \
|
||||
-DMAX_MATCH_SET_LEN=1024 \
|
||||
-I$(BPF_HEADERS_DIR)/tools/lib \
|
||||
-I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/asm/mach-generic
|
||||
|
||||
define Build/Prepare
|
||||
$(call Build/Prepare/Default)
|
||||
[ -f "$(PGO_PROFILE)" ] && $(CP) "$(PGO_PROFILE)" "$(PKG_BUILD_DIR)/default.pgo" || true
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
( \
|
||||
pushd $(PKG_BUILD_DIR) ; \
|
||||
go get -u=patch ; \
|
||||
go mod tidy ; \
|
||||
export \
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_VARS) \
|
||||
BPF_CLANG="$(CLANG)" \
|
||||
BPF_STRIP_FLAG="-strip=$(LLVM_STRIP)" \
|
||||
BPF_CFLAGS="$(DAE_CFLAGS)" \
|
||||
BPF_TARGET="bpfel,bpfeb" \
|
||||
BPF_TRACE_TARGET="$(GO_ARCH)" ; \
|
||||
go generate ./control/control.go ; \
|
||||
go generate ./trace/trace.go ; \
|
||||
popd ; \
|
||||
)
|
||||
$(call GoPackage/Build/Compile)
|
||||
endef
|
||||
|
||||
define Package/dae/install
|
||||
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
|
||||
$(INSTALL_DIR) $(1)/usr/bin/
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/dae $(1)/usr/bin/dae
|
||||
$(INSTALL_DIR) $(1)/etc/dae/
|
||||
$(INSTALL_CONF) $(PKG_BUILD_DIR)/example.dae $(1)/etc/dae/
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) $(CURDIR)/files/dae.config $(1)/etc/config/dae
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) $(CURDIR)/files/dae.init $(1)/etc/init.d/dae
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,dae))
|
||||
$(eval $(call BuildPackage,dae))
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
config dae 'config'
|
||||
option enabled '0'
|
||||
option config_file '/etc/dae/config.dae'
|
||||
option log_maxbackups '1'
|
||||
option log_maxsize '1'
|
||||
Executable
+102
@@ -0,0 +1,102 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2023 Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
USE_PROCD=1
|
||||
START=96
|
||||
STOP=10
|
||||
|
||||
extra_command "hot_reload" "Hot-reload service"
|
||||
|
||||
CONF="dae"
|
||||
PROG="/usr/bin/dae"
|
||||
LOG="/var/log/dae/dae.log"
|
||||
CRON_FILE="/etc/crontabs/root"
|
||||
DAENETNS="/run/netns/daens"
|
||||
RANDOM_SEED=$RANDOM
|
||||
RANDOM_NUM=$((RANDOM_SEED % 10 + 1))
|
||||
|
||||
setcron() {
|
||||
touch $CRON_FILE
|
||||
sed -i '/dae hot_reload/d' $CRON_FILE 2>/dev/null
|
||||
[ "$(uci -q get dae.config.subscribe_auto_update)" -eq 1 ] && echo "${RANDOM_NUM} $(uci -q get dae.config.subscribe_update_day_time) * * $(uci -q get dae.config.subscribe_update_week_time) /etc/init.d/dae hot_reload >/dev/null 2>&1" >>$CRON_FILE
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
delcron() {
|
||||
sed -i '/dae hot_reload/d' $CRON_FILE 2>/dev/null
|
||||
crontab $CRON_FILE
|
||||
}
|
||||
|
||||
set_chmod_640() {
|
||||
chmod -R 640 /etc/dae/
|
||||
mkdir -p /etc/dae/config.d
|
||||
mkdir -p /var/log/dae
|
||||
}
|
||||
|
||||
setlocaluse() {
|
||||
uci set dhcp.@dnsmasq[0].localuse="1"
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
}
|
||||
|
||||
dellocaluse() {
|
||||
local dns_list
|
||||
uci set dhcp.@dnsmasq[0].localuse="0"
|
||||
uci commit dhcp
|
||||
/etc/init.d/dnsmasq restart
|
||||
. /lib/functions/network.sh
|
||||
network_find_wan LOGICAL_WAN || exit 1
|
||||
dns_list=$(ubus call network.interface.$LOGICAL_WAN status | jsonfilter -e '@["dns-server"]' | sed 's/[]["]//g' | sed 's/,/\n/g' | grep -oE '\b([0-9]{1,3}\.){3}[0-9]{1,3}\b')
|
||||
[ -z "$dns_list" ] && dns_list="119.29.29.29 180.76.76.76 223.5.5.5"
|
||||
grep -v '^nameserver ' /etc/resolv.conf > /tmp/resolv.conf.new.dae 2>/dev/null
|
||||
for dns in $dns_list; do
|
||||
echo "nameserver $dns" >> /tmp/resolv.conf.new.dae
|
||||
done
|
||||
cat /tmp/resolv.conf.new.dae > /etc/resolv.conf
|
||||
rm -f /tmp/resolv.conf.new.dae
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local enabled config_file log_maxbackups log_maxsize
|
||||
set_chmod_640
|
||||
uci commit "$CONF" 2>/dev/null
|
||||
config_load "$CONF"
|
||||
|
||||
config_get_bool enabled "config" "enabled" "0"
|
||||
[ "$enabled" -eq "1" ] || return 1
|
||||
config_get config_file "config" "config_file" "/etc/dae/config.dae"
|
||||
"$PROG" validate -c "$config_file" || return 1
|
||||
setcron
|
||||
dellocaluse
|
||||
config_get log_maxbackups "config" "log_maxbackups" "1"
|
||||
config_get log_maxsize "config" "log_maxsize" "1"
|
||||
procd_open_instance "$CONF"
|
||||
uname -r | grep -Eq "^6\.6" && procd_set_param env "QUIC_GO_DISABLE_GSO"="true"
|
||||
procd_set_param env DAE_LOCATION_ASSET="/usr/share/v2ray"
|
||||
procd_set_param command "$PROG" run
|
||||
procd_append_param command --config "$config_file"
|
||||
procd_append_param command --disable-timestamp
|
||||
procd_append_param command --logfile "$LOG"
|
||||
procd_append_param command --logfile-maxbackups "$log_maxbackups"
|
||||
procd_append_param command --logfile-maxsize "$log_maxsize"
|
||||
procd_set_param limits core="unlimited"
|
||||
procd_set_param limits nofile="1000000 1000000"
|
||||
procd_set_param respawn
|
||||
procd_set_param stderr 1
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
delcron
|
||||
setlocaluse
|
||||
[ -f "$DAENETNS" ] && umount "$DAENETNS"
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$CONF"
|
||||
}
|
||||
|
||||
hot_reload() {
|
||||
set_chmod_640
|
||||
/etc/init.d/dae running && "$PROG" reload
|
||||
}
|
||||
Binary file not shown.
+192
@@ -0,0 +1,192 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2023 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=daed
|
||||
PKG_VERSION:=2026.05.09
|
||||
DAED_VERSION:=daed-1e35217
|
||||
WING_VERSION:=wing-dc50308
|
||||
CORE_VERSION:=core-2b3c63f
|
||||
WING_HASH_SHORT:=$(shell echo $(WING_VERSION) | cut -d- -f2)
|
||||
CORE_HASH_SHORT:=$(shell echo $(CORE_VERSION) | cut -d- -f2)
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_VERSION:=1e35217375eb11f4fe1c4c4dae60cce9d99ee466
|
||||
PKG_SOURCE_URL:=https://github.com/daeuniverse/daed.git
|
||||
PKG_MIRROR_HASH:=skip
|
||||
|
||||
PKG_LICENSE:=AGPL-3.0-only MIT
|
||||
PKG_LICENSE_FILES:=LICENSE wing/LICENSE
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
DAED_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
PKG_BUILD_DIR:=$(DAED_BUILD_DIR)/wing
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host bpf-headers
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/daeuniverse/dae-wing
|
||||
|
||||
GO_PKG_LDFLAGS:= \
|
||||
-s -w -buildid= \
|
||||
-linkmode external -extldflags '-static -Wl,-s' \
|
||||
-X '$(GO_PKG)/db.AppDescription=$(PKG_NAME) is a integration solution of dae, API and UI.'
|
||||
GO_PKG_LDFLAGS_X:= \
|
||||
$(GO_PKG)/db.AppName=$(PKG_NAME) \
|
||||
$(GO_PKG)/db.AppVersion=$(DAED_VERSION)_$(WING_VERSION)_$(CORE_VERSION)
|
||||
GO_PKG_TAGS:=embedallowed,trace
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(INCLUDE_DIR)/bpf.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
GO_PKG_BUILD_VARS+= \
|
||||
GOFLAGS="-trimpath -buildvcs=false -pgo=auto"
|
||||
|
||||
GO_PKG_TARGET_VARS+= \
|
||||
CGO_LDFLAGS="$(TARGET_LDFLAGS) -static -Wl,-s" \
|
||||
GOEXPERIMENT=newinliner,simd
|
||||
|
||||
define Package/daed/Default
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=Web Servers/Proxies
|
||||
URL:=https://github.com/daeuniverse/daed
|
||||
endef
|
||||
|
||||
define Package/daed
|
||||
$(call Package/daed/Default)
|
||||
TITLE:=A Modern Dashboard For dae
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) \
|
||||
+ca-bundle +kmod-sched-core +kmod-sched-bpf \
|
||||
+kmod-veth +v2ray-geoip +v2ray-geosite \
|
||||
+@KERNEL_XDP_SOCKETS \
|
||||
+DAED_USE_VMLINUX_BTF:vmlinux-btf
|
||||
endef
|
||||
|
||||
define Package/daed/config
|
||||
choice
|
||||
prompt "BTF source for CO-RE"
|
||||
default DAED_USE_KERNEL_BTF
|
||||
depends on PACKAGE_daed
|
||||
|
||||
config DAED_USE_KERNEL_BTF
|
||||
bool "Use kernel BTF (integrated)"
|
||||
depends on KERNEL_DEBUG_INFO_BTF
|
||||
|
||||
config DAED_USE_VMLINUX_BTF
|
||||
bool "Use vmlinux-btf package"
|
||||
endchoice
|
||||
endef
|
||||
|
||||
define Package/daed/description
|
||||
daed is a backend of dae, provides a method to bundle arbitrary
|
||||
frontend, dae and geodata into one binary.
|
||||
endef
|
||||
|
||||
define Package/daed/conffiles
|
||||
/etc/daed/wing.db
|
||||
/etc/config/daed
|
||||
endef
|
||||
|
||||
NODE_VERSION:=v24.12.0
|
||||
NODE_DIST:=node-$(NODE_VERSION)-linux-x64
|
||||
NODE_URL:=https://nodejs.org/dist/$(NODE_VERSION)/$(NODE_DIST).tar.xz
|
||||
|
||||
define Build/Prepare
|
||||
( \
|
||||
rm -rf $(DAED_BUILD_DIR) ; \
|
||||
mkdir -p $(DAED_BUILD_DIR) ; \
|
||||
$(TAR) --strip-components=1 -C $(DAED_BUILD_DIR) -xzf $(DL_DIR)/$(PKG_NAME)-$(PKG_VERSION).tar.gz ; \
|
||||
git clone https://github.com/daeuniverse/dae-wing $(PKG_BUILD_DIR) && \
|
||||
git -C $(PKG_BUILD_DIR) checkout $(WING_HASH_SHORT) ; \
|
||||
rm -rf $(PKG_BUILD_DIR)/dae-core ; \
|
||||
git clone https://github.com/olicesx/dae $(PKG_BUILD_DIR)/dae-core && \
|
||||
git -C $(PKG_BUILD_DIR)/dae-core checkout $(CORE_HASH_SHORT) ; \
|
||||
rm -rf $(DAED_BUILD_DIR)/outbound ; \
|
||||
git clone --depth=1 -b perf/complete-optimizations https://github.com/olicesx/outbound.git $(DAED_BUILD_DIR)/outbound ; \
|
||||
rm -rf $(DAED_BUILD_DIR)/quic-go ; \
|
||||
git clone --depth=1 -b perf/node-pooling-v2 https://github.com/olicesx/quic-go.git $(DAED_BUILD_DIR)/quic-go ; \
|
||||
pushd $(PKG_BUILD_DIR)/dae-core ; \
|
||||
git submodule update --init ; \
|
||||
go get -u=patch ; \
|
||||
go mod tidy ; \
|
||||
popd ; \
|
||||
pushd $(PKG_BUILD_DIR) ; \
|
||||
go mod edit -replace github.com/daeuniverse/outbound=../outbound ; \
|
||||
go mod edit -replace github.com/daeuniverse/quic-go=../quic-go ; \
|
||||
go get -u=patch ; \
|
||||
go mod tidy ; \
|
||||
wget -qO default.pgo "https://github.com/QiuSimons/luci-app-dae/raw/refs/heads/kix/dae/pprof/default.pgo" ; \
|
||||
popd ; \
|
||||
mkdir -p $(DAED_BUILD_DIR)/.node_tmp/config ; \
|
||||
wget -qO - "$(NODE_URL)" | tar -xJ -C $(DAED_BUILD_DIR)/.node_tmp --strip-components=1 ; \
|
||||
export PATH="$(DAED_BUILD_DIR)/.node_tmp/bin:$$$$PATH" ; \
|
||||
export XDG_CONFIG_HOME="$(DAED_BUILD_DIR)/.node_tmp/config" ; \
|
||||
npm install -g pnpm ; \
|
||||
pushd $(DAED_BUILD_DIR) ; \
|
||||
pnpm install ; \
|
||||
pnpm build --filter daed ; \
|
||||
popd ; \
|
||||
mkdir -p $(PKG_BUILD_DIR)/webrender/web ; \
|
||||
cp -rf $(DAED_BUILD_DIR)/apps/web/dist/* $(PKG_BUILD_DIR)/webrender/web ; \
|
||||
find $(PKG_BUILD_DIR)/webrender/web -name "*.map" -type f -delete ; \
|
||||
find $(PKG_BUILD_DIR)/webrender/web -type f -size +4k ! -name "*.gz" ! -name "*.woff" ! -name "*.woff2" -exec sh -c '\
|
||||
gzip -9 -k "{}"; \
|
||||
if [ "$$$$(stat -c %s {})" -lt "$$$$(stat -c %s {}.gz)" ]; then \
|
||||
rm {}.gz; \
|
||||
else \
|
||||
rm {}; \
|
||||
fi' \
|
||||
";" ; \
|
||||
rm -rf $(DAED_BUILD_DIR)/.node_tmp ; \
|
||||
)
|
||||
endef
|
||||
|
||||
DAE_CFLAGS:= \
|
||||
-O2 -Wall -Werror \
|
||||
-DMAX_MATCH_SET_LEN=1024 \
|
||||
-I$(BPF_HEADERS_DIR)/tools/lib \
|
||||
-I$(BPF_HEADERS_DIR)/arch/$(BPF_KARCH)/include/asm/mach-generic
|
||||
|
||||
define Build/Compile
|
||||
( \
|
||||
pushd $(PKG_BUILD_DIR) ; \
|
||||
export \
|
||||
$(GO_GENERAL_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_CONFIG_VARS) \
|
||||
$(GO_PKG_BUILD_VARS) ; \
|
||||
go generate ./... ; \
|
||||
cd dae-core ; \
|
||||
export \
|
||||
BPF_CLANG="$(CLANG)" \
|
||||
BPF_STRIP_FLAG="-strip=$(LLVM_STRIP)" \
|
||||
BPF_CFLAGS="$(DAE_CFLAGS)" \
|
||||
BPF_TARGET="bpfel,bpfeb" \
|
||||
BPF_TRACE_TARGET="$(GO_ARCH)" ; \
|
||||
go generate ./control/control.go ; \
|
||||
go generate ./trace/trace.go ; \
|
||||
popd ; \
|
||||
)
|
||||
$(call GoPackage/Build/Compile)
|
||||
endef
|
||||
|
||||
define Package/daed/install
|
||||
$(call GoPackage/Package/Install/Bin,$(PKG_INSTALL_DIR))
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/dae-wing $(1)/usr/bin/daed
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) $(CURDIR)/files/daed.config $(1)/etc/config/daed
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) $(CURDIR)/files/daed.init $(1)/etc/init.d/daed
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,daed))
|
||||
$(eval $(call BuildPackage,daed))
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
config daed 'config'
|
||||
option enabled '0'
|
||||
option listen_addr '0.0.0.0:2023'
|
||||
option log_maxbackups '1'
|
||||
option log_maxsize '5'
|
||||
|
||||
Executable
+48
@@ -0,0 +1,48 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
# Copyright (C) 2023 Tianling Shen <cnsztl@immortalwrt.org>
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
|
||||
CONF="daed"
|
||||
PROG="/usr/bin/daed"
|
||||
LOG="/var/log/daed/daed.log"
|
||||
DAENETNS="/run/netns/daens"
|
||||
|
||||
start_service() {
|
||||
config_load "$CONF"
|
||||
|
||||
local enabled
|
||||
config_get_bool enabled "config" "enabled" "0"
|
||||
[ "$enabled" -eq "1" ] || return 1
|
||||
|
||||
local listen_addr log_maxbackups log_maxsize
|
||||
config_get listen_addr "config" "listen_addr" "0.0.0.0:2023"
|
||||
config_get log_maxbackups "config" "log_maxbackups" "1"
|
||||
config_get log_maxsize "config" "log_maxsize" "5"
|
||||
|
||||
procd_open_instance "$CONF"
|
||||
procd_set_param command "$PROG" run
|
||||
procd_append_param command --config "/etc/daed/"
|
||||
procd_append_param command --listen "$listen_addr"
|
||||
procd_append_param command --logfile "$LOG"
|
||||
procd_append_param command --logfile-maxbackups "$log_maxbackups"
|
||||
procd_append_param command --logfile-maxsize "$log_maxsize"
|
||||
|
||||
procd_set_param limits core="unlimited"
|
||||
procd_set_param limits nofile="1000000 1000000"
|
||||
procd_set_param respawn
|
||||
# procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
rm -f "$LOG"
|
||||
[ -f "$DAENETNS" ] && umount "$DAENETNS"
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$CONF"
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#
|
||||
# Copyright (C) 2007-2011 OpenWrt.org
|
||||
#
|
||||
# This is free software, licensed under the GNU General Public License v2.
|
||||
# See /LICENSE for more information.
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=daemonlogger
|
||||
PKG_VERSION:=1.2.1
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=@SF/daemonlogger
|
||||
PKG_HASH:=79fcd34d815e9c671ffa1ea3c7d7d50f895bb7a79b4448c4fd1c37857cf44a0b
|
||||
|
||||
PKG_LICENSE:=GPL-2.0
|
||||
PKG_LICENSE_FILES:=COPYING
|
||||
|
||||
PKG_MAINTAINER:=Mirko Vogt <mirko@openwrt.org>
|
||||
|
||||
PKG_INSTALL:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/daemonlogger
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
DEPENDS:=+libpcap +libdnet
|
||||
TITLE:=Software Network Tap
|
||||
URL:=http://www.snort.org/snort-downloads/additional-downloads
|
||||
endef
|
||||
|
||||
CONFIGURE_VARS += \
|
||||
BUILD_CC="$(TARGET_CC)" \
|
||||
HOSTCC="$(HOSTCC)"
|
||||
|
||||
MAKE_FLAGS := CCOPT="$(TARGET_CFLAGS)" INCLS="-I. $(TARGET_CPPFLAGS)"
|
||||
|
||||
define Package/daemonlogger/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/daemonlogger $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,daemonlogger))
|
||||
@@ -0,0 +1,61 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021-2026 sirpdboy <herboy2008@gmail.com>
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=ddns-go
|
||||
PKG_VERSION:=6.16.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/jeessy2/ddns-go/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=1a92f53e50c8ca81e20c15c6dbaf490544f1a7b7b8c8d1c4c60ad8f1bc890276
|
||||
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
PKG_MAINTAINER:=sirpdboy <herboy2008@gmail.com>
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/jeessy2/ddns-go/v6
|
||||
GO_PKG_LDFLAGS_X:=main.Version=$(PKG_VERSION)
|
||||
GO_PKG_LDFLAGS:=$(GO_PKG_LDFLAGS_X)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk
|
||||
|
||||
define Package/ddns-go
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=Support IPV4 and IPV6 simple and easy-to-use IP binding domain name tool
|
||||
URL:=https://github.com/jeessy2/ddns-go
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) +ca-bundle
|
||||
USERID:=ddns-go:ddns-go
|
||||
endef
|
||||
|
||||
define Package/ddns-go/description
|
||||
A simple and easy-to-use IP binding domain name tool that supports IPV4 and IPV6.
|
||||
endef
|
||||
|
||||
define Package/ddns-go/conffiles
|
||||
/etc/config/ddns-go
|
||||
/etc/ddns-go/ddns-go-config.yaml
|
||||
endef
|
||||
|
||||
|
||||
define Package/ddns-go/install
|
||||
$(call GoPackage/Package/Install/Bin,$(1))
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_BIN) $(CURDIR)/files/ddns-go.init $(1)/etc/init.d/ddns-go
|
||||
$(INSTALL_CONF) $(CURDIR)/files/ddns-go.conf $(1)/etc/config/ddns-go
|
||||
endef
|
||||
|
||||
$(eval $(call GoBinPackage,ddns-go))
|
||||
$(eval $(call BuildPackage,ddns-go))
|
||||
@@ -0,0 +1,9 @@
|
||||
config basic 'config'
|
||||
option enabled '0'
|
||||
option logger '1'
|
||||
option port '9876'
|
||||
option time '300'
|
||||
option ctimes '5'
|
||||
option skipverify '0'
|
||||
option delay '0'
|
||||
option dns '223.5.5.5'
|
||||
@@ -0,0 +1,84 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
#
|
||||
# Copyright (C) 2021-2026 sirpdboy <herboy2008@gmail.com>
|
||||
#
|
||||
# This file is part of ddns-go .
|
||||
#
|
||||
# This is free software, licensed under the Apache License, Version 2.0 .
|
||||
#
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
NAME=ddns-go
|
||||
PROG=/usr/bin/ddns-go
|
||||
CONFDIR=/etc/ddns-go
|
||||
CONF=$CONFDIR/ddns-go-config.yaml
|
||||
|
||||
init_yaml() {
|
||||
[ -d "$CONFDIR" ] || mkdir -p "$CONFDIR"
|
||||
chown -R ddns-go:ddns-go "$CONFDIR"
|
||||
chmod 755 "$CONFDIR"
|
||||
[ -f "$CONF" ] && chmod 644 "$CONF"
|
||||
}
|
||||
|
||||
build_args() {
|
||||
local cfg="$1"
|
||||
local args="-c $CONF"
|
||||
|
||||
config_get port "$cfg" port '9876'
|
||||
args="$args -l :$port"
|
||||
|
||||
config_get time "$cfg" time '300'
|
||||
[ -n "$time" ] && args="$args -f $time"
|
||||
|
||||
config_get ctimes "$cfg" ctimes '5'
|
||||
[ -n "$ctimes" ] && args="$args -cacheTimes $ctimes"
|
||||
|
||||
config_get dns "$cfg" dns '223.5.5.5'
|
||||
[ -n "$dns" ] && args="$args -dns $dns"
|
||||
|
||||
config_get_bool noweb "$cfg" noweb 0
|
||||
[ "$noweb" -eq 1 ] && args="$args -noweb"
|
||||
|
||||
config_get_bool skipverify "$cfg" skipverify 0
|
||||
[ "$skipverify" -eq 1 ] && args="$args -skipVerify"
|
||||
|
||||
echo "$args"
|
||||
}
|
||||
|
||||
start_instance() {
|
||||
local cfg="$1"
|
||||
config_get_bool enabled "$cfg" enabled 0
|
||||
[ "$enabled" -eq 0 ] && return 0
|
||||
|
||||
config_get delay "$cfg" delay 0
|
||||
if [ "$delay" -gt 0 ]; then
|
||||
local uptime=$(awk -F. '{print $1}' /proc/uptime)
|
||||
[ "$uptime" -lt 120 ] && sleep "$delay"
|
||||
fi
|
||||
|
||||
init_yaml
|
||||
|
||||
local args=$(build_args "$cfg")
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param command $PROG $args
|
||||
|
||||
procd_set_param stdout 1
|
||||
procd_set_param stderr 1
|
||||
procd_set_param log_level 7
|
||||
|
||||
procd_set_param user ddns-go
|
||||
procd_set_param respawn
|
||||
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$NAME"
|
||||
config_foreach start_instance 'basic'
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "$NAME"
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
#
|
||||
# Copyright (C) 2017-2024 Zxlhhyccc <zxlhhyccc@gmail.com>
|
||||
# Copyright (C) 2021-2024 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dns2socks-rust
|
||||
PKG_VERSION:=0.2.4
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/tun2proxy/dns2socks/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=978df21984f3601781f48ba01c5819bf5971f6d7da07968457b0fb16bd323d7f
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/dns2socks-$(PKG_VERSION)
|
||||
|
||||
PKG_MAINTAINER:=Zxlhhyccc <zxlhhyccc@gmail.com>
|
||||
PKG_LICENSE:=MIT
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
PKG_BUILD_DEPENDS:=rust/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
|
||||
#RUST_PKG:=dns2socks
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include $(TOPDIR)/feeds/packages/lang/rust/rust-package.mk
|
||||
|
||||
define Package/dns2socks-rust
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=DNS forwards to SOCKS5 server
|
||||
URL:=https://github.com/tun2proxy/dns2socks.git
|
||||
DEPENDS:=$$(RUST_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Package/dns2socks-rust/description
|
||||
This is a DNS server that forwards DNS requests to a SOCKS5 server.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(call Build/Compile/Cargo,,--all-features)
|
||||
endef
|
||||
|
||||
define Package/dns2socks-rust/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/target/$(RUSTC_TARGET_ARCH)/release/dns2socks $(1)/usr/bin/dns2socks-rust
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,dns2socks-rust))
|
||||
@@ -0,0 +1,51 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2021-2026 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dns2socks
|
||||
PKG_VERSION:=2.2
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/kenzok8/dns2socks/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=790f7ca5ec07677a699121eb071c9e66cdafe65a22bb229eed7fd3cf215631d2
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
PKG_LICENSE_FILE:=LICENSE
|
||||
PKG_MAINTAINER:=ghostmaker
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/dns2socks
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=DNS to SOCKS or HTTP proxy
|
||||
URL:=https://github.com/kenzok8/dns2socks
|
||||
DEPENDS:=+libpthread
|
||||
endef
|
||||
|
||||
define Package/dns2socks/description
|
||||
This is a command line utility to resolve DNS requests via
|
||||
a SOCKS tunnel like Tor or a HTTP proxy.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(TARGET_CC) \
|
||||
$(TARGET_CFLAGS) \
|
||||
$(TARGET_CPPFLAGS) \
|
||||
$(FPIC) \
|
||||
-o $(PKG_BUILD_DIR)/dns2socks \
|
||||
$(PKG_BUILD_DIR)/src/dns2socks.c \
|
||||
$(TARGET_LDFLAGS) -pthread
|
||||
endef
|
||||
|
||||
define Package/dns2socks/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/dns2socks $(1)/usr/bin/dns2socks
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,dns2socks))
|
||||
@@ -0,0 +1,42 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-only
|
||||
#
|
||||
# Copyright (C) 2022 ImmortalWrt.org
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dns2tcp
|
||||
PKG_VERSION:=1.1.2
|
||||
PKG_RELEASE:=2
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/zfl9/dns2tcp/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=5e8c6302a1d32c16ae7d4b8e39cd9aad1f2d7e68fe18813e76cb1e48ec5940d2
|
||||
|
||||
PKG_MAINTAINER:=Tianling Shen <cnsztl@immortalwrt.org>
|
||||
PKG_LICENSE:=AGPL-3.0-only
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16 gc-sections lto
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/dns2tcp
|
||||
SECTION:=net
|
||||
CATEGORY:=Network
|
||||
SUBMENU:=IP Addresses and Names
|
||||
TITLE:=utility to convert dns query from udp to tcp
|
||||
URL:=https://github.com/zfl9/dns2tcp
|
||||
endef
|
||||
|
||||
TARGET_CFLAGS+= $(FPIC)
|
||||
MAKE_FLAGS+= \
|
||||
CFLAGS="-std=c99 $(TARGET_CFLAGS)" \
|
||||
EVCFLAGS="$(TARGET_CFLAGS)"
|
||||
|
||||
define Package/dns2tcp/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/dns2tcp $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,dns2tcp))
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 91 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 319 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 389 KiB |
@@ -0,0 +1,74 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=docker
|
||||
PKG_VERSION:=29.4.3
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_SOURCE_URL:=https://codeload.github.com/docker/cli/tar.gz/v$(PKG_VERSION)?
|
||||
PKG_HASH:=e9341f05882778096d85f8cc34222b5b731bad9561980c377b9e8477dfb1ebc2
|
||||
PKG_BUILD_DIR:=$(BUILD_DIR)/cli-$(PKG_VERSION)
|
||||
PKG_GIT_SHORT_COMMIT:=$(shell $(CURDIR)/git-short-commit.sh 'github.com/docker/cli' 'v$(PKG_VERSION)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)')
|
||||
|
||||
PKG_MAINTAINER:=Gerard Ryan <G.M0N3Y.2503@gmail.com>
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/docker/cli
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../../lang/golang/golang-package.mk
|
||||
|
||||
define Package/docker
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=Docker Community Edition CLI
|
||||
URL:=https://www.docker.com/
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS)
|
||||
endef
|
||||
|
||||
define Package/docker/description
|
||||
The CLI used in the Docker CE and Docker EE products.
|
||||
endef
|
||||
|
||||
GO_PKG_INSTALL_EXTRA:=\
|
||||
cli/compose/schema/data \
|
||||
vendor/google.golang.org/protobuf/internal/editiondefaults/editions_defaults.binpb
|
||||
|
||||
TAR_OPTIONS:=--strip-components 1 $(TAR_OPTIONS)
|
||||
TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS)
|
||||
TARGET_LDFLAGS += $(if $(CONFIG_USE_GLIBC),-lc -lgcc_eh)
|
||||
|
||||
define Build/Prepare
|
||||
$(Build/Prepare/Default)
|
||||
|
||||
# Verify PKG_GIT_SHORT_COMMIT
|
||||
( \
|
||||
EXPECTED_PKG_GIT_SHORT_COMMIT=$$$$( $(CURDIR)/git-short-commit.sh 'github.com/docker/cli' 'v$(PKG_VERSION)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)' ); \
|
||||
if [ "$$$${EXPECTED_PKG_GIT_SHORT_COMMIT}" != "$(strip $(PKG_GIT_SHORT_COMMIT))" ]; then \
|
||||
echo "ERROR: Expected 'PKG_GIT_SHORT_COMMIT:=$$$${EXPECTED_PKG_GIT_SHORT_COMMIT}', found 'PKG_GIT_SHORT_COMMIT:=$(strip $(PKG_GIT_SHORT_COMMIT))'"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
)
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
( \
|
||||
cd $(PKG_BUILD_DIR); \
|
||||
$(GO_PKG_VARS) \
|
||||
GITCOMMIT=$(PKG_GIT_SHORT_COMMIT) \
|
||||
VERSION=$(PKG_VERSION) \
|
||||
./scripts/build/binary; \
|
||||
)
|
||||
endef
|
||||
|
||||
define Package/docker/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/build/docker $(1)/usr/bin/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,docker))
|
||||
@@ -0,0 +1,49 @@
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# USAGE: git-short-commit.sh <GIT_URL> <GIT_REF> <GIT_DIR>
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
error() {
|
||||
echo "ERROR: ${*}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
GIT_URL="${1}"
|
||||
if [ -z "${GIT_URL}" ]; then
|
||||
error "Git URL not specified"
|
||||
fi
|
||||
|
||||
GIT_REF="${2}"
|
||||
if [ -z "${GIT_REF}" ]; then
|
||||
error "Git reference not specified"
|
||||
fi
|
||||
|
||||
GIT_DIR="${3}"
|
||||
if [ -z "${GIT_DIR}" ]; then
|
||||
error "Git clone directory not specified"
|
||||
fi
|
||||
|
||||
clean_up() {
|
||||
rm -rf "${GIT_DIR}"
|
||||
}
|
||||
trap clean_up EXIT
|
||||
|
||||
git init --quiet "${GIT_DIR}"
|
||||
(
|
||||
cd "${GIT_DIR}"
|
||||
for PREFIX in "" "https://" "http://" "git@"; do
|
||||
echo "Trying remote '${PREFIX}${GIT_URL}'" >&2
|
||||
git remote add origin "${PREFIX}${GIT_URL}"
|
||||
|
||||
if git fetch --depth 1 origin "${GIT_REF}"; then
|
||||
git checkout --detach FETCH_HEAD --
|
||||
git rev-parse --short HEAD
|
||||
break
|
||||
fi
|
||||
|
||||
git remote remove origin
|
||||
done
|
||||
)
|
||||
@@ -0,0 +1,87 @@
|
||||
config DOCKER_CHECK_CONFIG
|
||||
bool "Installs check-config.sh with dependencies"
|
||||
default n
|
||||
depends on PACKAGE_dockerd
|
||||
select PACKAGE_bash
|
||||
select PACKAGE_kmod-ikconfig
|
||||
|
||||
# These options are mostly specified by https://github.com/moby/moby/blob/master/contrib/check-config.sh
|
||||
|
||||
config DOCKER_CGROUP_OPTIONS
|
||||
bool "Enable available kernel support for CGroupsV1"
|
||||
default y
|
||||
depends on PACKAGE_dockerd
|
||||
select KERNEL_CGROUP_DEVICE
|
||||
select KERNEL_CGROUP_FREEZER
|
||||
select KERNEL_NET_CLS_CGROUP
|
||||
select KERNEL_CGROUP_NET_PRIO
|
||||
select PACKAGE_cgroupfs-mount
|
||||
help
|
||||
Selects kernel options to enable CGroups V1.
|
||||
|
||||
config DOCKER_OPTIONAL_FEATURES
|
||||
bool "Enable optional kernel support for Docker"
|
||||
default n
|
||||
depends on PACKAGE_dockerd
|
||||
select KERNEL_MEMCG_SWAP_ENABLED
|
||||
select KERNEL_CFQ_GROUP_IOSCHED
|
||||
select KERNEL_CGROUP_PERF
|
||||
select KERNEL_CGROUP_HUGETLB
|
||||
help
|
||||
Select 'Optional Features' kernel options for Docker that are unselected.
|
||||
See https://github.com/moby/moby/blob/master/contrib/check-config.sh
|
||||
|
||||
menu "Network"
|
||||
depends on PACKAGE_dockerd
|
||||
|
||||
config DOCKER_NET_OVERLAY
|
||||
bool "Includes the Overlay network feature"
|
||||
default n
|
||||
select PACKAGE_kmod-vxlan
|
||||
help
|
||||
Selects kmod-vxlan for the Overlay network feature.
|
||||
|
||||
config DOCKER_NET_ENCRYPT
|
||||
bool "Includes encrypted networking kernel modules"
|
||||
depends on DOCKER_NET_OVERLAY
|
||||
default n
|
||||
select PACKAGE_kmod-crypto-gcm
|
||||
select PACKAGE_kmod-crypto-seqiv
|
||||
select PACKAGE_kmod-crypto-ghash
|
||||
select PACKAGE_kmod-ipsec
|
||||
help
|
||||
Select needed kernel modules for encrypted networking support.
|
||||
|
||||
config DOCKER_NET_MACVLAN
|
||||
bool "Includes macvlan kernel modules"
|
||||
default y
|
||||
select PACKAGE_kmod-macvlan
|
||||
select PACKAGE_kmod-dummy
|
||||
|
||||
config DOCKER_NET_TFTP
|
||||
bool "Includes ftp/tftp client kernel modules"
|
||||
default n
|
||||
select PACKAGE_kmod-nf-nathelper
|
||||
select PACKAGE_kmod-nf-nathelper-extra
|
||||
endmenu
|
||||
|
||||
menu "Storage"
|
||||
depends on PACKAGE_dockerd
|
||||
|
||||
config DOCKER_STO_DEVMAPPER
|
||||
bool "Enables support for devmapper snapshotting"
|
||||
default n
|
||||
select PACKAGE_libdevmapper
|
||||
|
||||
config DOCKER_STO_EXT4
|
||||
bool "Enables support for ext3 or ext4 as the backing filesystem"
|
||||
default y
|
||||
select KERNEL_EXT4_FS_POSIX_ACL
|
||||
select KERNEL_EXT4_FS_SECURITY
|
||||
|
||||
config DOCKER_STO_BTRFS
|
||||
bool "Enables support for btrfs as the backing filesystem"
|
||||
default n
|
||||
select KERNEL_BTRFS_FS_POSIX_ACL
|
||||
select PACKAGE_btrfs-progs
|
||||
endmenu
|
||||
@@ -0,0 +1,182 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=dockerd
|
||||
PKG_VERSION:=29.4.3
|
||||
PKG_RELEASE:=1
|
||||
PKG_LICENSE:=Apache-2.0
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
|
||||
PKG_GIT_URL:=github.com/moby/moby
|
||||
PKG_GIT_REF:=docker-v$(PKG_VERSION)
|
||||
PKG_SOURCE_URL:=https://codeload.$(PKG_GIT_URL)/tar.gz/$(PKG_GIT_REF)?
|
||||
PKG_HASH:=3dd4e709e1928ba90cf7bcd31025e13dda5517867989972b38f8fe4bd6f3dab6
|
||||
PKG_GIT_SHORT_COMMIT:=$(shell $(CURDIR)/git-short-commit.sh '$(PKG_GIT_URL)' '$(PKG_GIT_REF)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)')
|
||||
|
||||
PKG_MAINTAINER:=Gerard Ryan <G.M0N3Y.2503@gmail.com>
|
||||
|
||||
PKG_BUILD_DEPENDS:=golang/host
|
||||
PKG_BUILD_PARALLEL:=1
|
||||
PKG_BUILD_FLAGS:=no-mips16
|
||||
|
||||
GO_PKG:=github.com/docker/docker
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
include ../../lang/golang/golang-package.mk
|
||||
|
||||
define Package/dockerd/config
|
||||
source "$(SOURCE)/Config.in"
|
||||
endef
|
||||
|
||||
define Package/dockerd
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=Docker Community Edition Daemon
|
||||
URL:=https://www.docker.com/
|
||||
DEPENDS:=$(GO_ARCH_DEPENDS) \
|
||||
+ca-certificates \
|
||||
+containerd \
|
||||
+iptables \
|
||||
+iptables-mod-extra \
|
||||
+IPV6:ip6tables \
|
||||
+IPV6:kmod-ipt-nat6 \
|
||||
+KERNEL_SECCOMP:libseccomp \
|
||||
+kmod-ipt-nat \
|
||||
+kmod-ipt-physdev \
|
||||
+kmod-nf-ipvs \
|
||||
+kmod-veth \
|
||||
+tini \
|
||||
+uci-firewall \
|
||||
@!(mips||mips64||mipsel)
|
||||
USERID:=docker:docker
|
||||
MENU:=1
|
||||
endef
|
||||
|
||||
define Package/dockerd/conffiles
|
||||
/etc/config/dockerd
|
||||
endef
|
||||
|
||||
define Package/dockerd/description
|
||||
The Docker CE Engine.
|
||||
endef
|
||||
|
||||
TAR_OPTIONS:=--strip-components 1 $(TAR_OPTIONS)
|
||||
TAR_CMD=$(HOST_TAR) -C $(1) $(TAR_OPTIONS)
|
||||
TARGET_LDFLAGS += $(if $(CONFIG_USE_GLIBC),-lc -lgcc_eh)
|
||||
|
||||
# $(1) = path to dependent package 'Makefile'
|
||||
# $(2) = relevant dependency '.installer' file
|
||||
define EnsureVendoredVersion
|
||||
( \
|
||||
DEP_VER=$$$$( grep --only-matching --perl-regexp '(?<=PKG_VERSION:=)(.*)' "$(1)" ); \
|
||||
VEN_VER=$$$$( grep --only-matching --perl-regexp '(?<=_VERSION:=v)(.*)(?=})' "$(PKG_BUILD_DIR)/hack/dockerfile/install/$(2)" ); \
|
||||
if [ "$$$${VEN_VER}" != "$$$${DEP_VER}" ]; then \
|
||||
echo "ERROR: Expected 'PKG_VERSION:=$$$${VEN_VER}' in '$(1)', found 'PKG_VERSION:=$$$${DEP_VER}'"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
)
|
||||
endef
|
||||
|
||||
# $(1) = path to dependent package 'Makefile'
|
||||
# $(2) = relevant dependency '.installer' file
|
||||
define EnsureVendoredCommit
|
||||
( \
|
||||
DEP_VER=$$$$( grep --only-matching --perl-regexp '(?<=PKG_SOURCE_VERSION:=)(.*)' "$(1)" ); \
|
||||
VEN_VER=$$$$( grep --only-matching --perl-regexp '(?<=_COMMIT:=)(.*)(?=})' "$(PKG_BUILD_DIR)/hack/dockerfile/install/$(2)" ); \
|
||||
if [ "$$$${VEN_VER}" != "$$$${DEP_VER}" ]; then \
|
||||
echo "ERROR: Expected 'PKG_SOURCE_VERSION:=$$$${VEN_VER}' in '$(1)', found 'PKG_SOURCE_VERSION:=$$$${DEP_VER}'"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
)
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
$(Build/Prepare/Default)
|
||||
|
||||
# Verify dependencies are the vendored version
|
||||
$(call EnsureVendoredVersion,../containerd/Makefile,containerd.installer)
|
||||
$(call EnsureVendoredVersion,../runc/Makefile,runc.installer)
|
||||
$(call EnsureVendoredVersion,../tini/Makefile,tini.installer)
|
||||
|
||||
# Verify CLI is the same version
|
||||
( \
|
||||
CLI_MAKEFILE="../docker/Makefile"; \
|
||||
CLI_VERSION=$$$$( grep --only-matching --perl-regexp '(?<=PKG_VERSION:=)(.*)' "$$$${CLI_MAKEFILE}" ); \
|
||||
if [ "$$$${CLI_VERSION}" != "$(PKG_VERSION)" ]; then \
|
||||
echo "ERROR: Expected 'PKG_VERSION:=$(PKG_VERSION)' in '$$$${CLI_MAKEFILE}', found 'PKG_VERSION:=$$$${CLI_VERSION}'"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
)
|
||||
|
||||
# Verify PKG_GIT_SHORT_COMMIT
|
||||
( \
|
||||
EXPECTED_PKG_GIT_SHORT_COMMIT=$$$$( $(CURDIR)/git-short-commit.sh '$(PKG_GIT_URL)' '$(PKG_GIT_REF)' '$(TMP_DIR)/git-short-commit/$(PKG_NAME)-$(PKG_VERSION)' ); \
|
||||
if [ "$$$${EXPECTED_PKG_GIT_SHORT_COMMIT}" != "$(strip $(PKG_GIT_SHORT_COMMIT))" ]; then \
|
||||
echo "ERROR: Expected 'PKG_GIT_SHORT_COMMIT:=$$$${EXPECTED_PKG_GIT_SHORT_COMMIT}', found 'PKG_GIT_SHORT_COMMIT:=$(strip $(PKG_GIT_SHORT_COMMIT))'"; \
|
||||
exit 1; \
|
||||
fi \
|
||||
)
|
||||
endef
|
||||
|
||||
BUILDTAGS:=
|
||||
ifeq ($(KERNEL_SECCOMP),y)
|
||||
BUILDTAGS += seccomp
|
||||
endif
|
||||
ifeq ($(CONFIG_SELINUX),y)
|
||||
BUILDTAGS += selinux
|
||||
endif
|
||||
|
||||
define Build/Compile
|
||||
( \
|
||||
cd $(PKG_BUILD_DIR); \
|
||||
$(GO_PKG_VARS) \
|
||||
DOCKER_GITCOMMIT=$(PKG_GIT_SHORT_COMMIT) \
|
||||
DOCKER_BUILDTAGS='$(BUILDTAGS)' \
|
||||
VERSION=$(PKG_VERSION) \
|
||||
./hack/make.sh binary; \
|
||||
)
|
||||
endef
|
||||
|
||||
define Package/dockerd/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bundles/binary-daemon/dockerd $(1)/usr/bin/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bundles/binary-daemon/docker-proxy $(1)/usr/bin/
|
||||
|
||||
$(INSTALL_DIR) $(1)/opt/docker/
|
||||
|
||||
ifeq ($(CONFIG_DOCKER_CHECK_CONFIG),y)
|
||||
$(INSTALL_DIR) $(1)/usr/share/docker/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/contrib/check-config.sh $(1)/usr/share/docker/
|
||||
endif
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/init.d
|
||||
$(INSTALL_BIN) ./files/dockerd.init $(1)/etc/init.d/dockerd
|
||||
|
||||
$(INSTALL_DIR) $(1)/etc/config
|
||||
$(INSTALL_CONF) ./files/etc/config/dockerd $(1)/etc/config/dockerd
|
||||
|
||||
# Must be after systcl 11-br-netfilter.conf from kmod-br-netfilter
|
||||
$(INSTALL_DIR) $(1)/etc/sysctl.d
|
||||
$(INSTALL_DATA) ./files/etc/sysctl.d/sysctl-br-netfilter-ip.conf \
|
||||
$(1)/etc/sysctl.d/12-br-netfilter-ip.conf
|
||||
endef
|
||||
|
||||
define Package/dockerd/postinst
|
||||
#!/bin/sh
|
||||
[ -n "$$IPKG_INSTROOT" ] || {
|
||||
/etc/init.d/dockerd enable
|
||||
/etc/init.d/dockerd uciadd
|
||||
/etc/init.d/dockerd start
|
||||
}
|
||||
endef
|
||||
|
||||
define Package/dockerd/prerm
|
||||
#!/bin/sh
|
||||
[ -n "$$IPKG_INSTROOT" ] || {
|
||||
/etc/init.d/dockerd disable
|
||||
/etc/init.d/dockerd stop
|
||||
/etc/init.d/dockerd ucidel
|
||||
}
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,dockerd))
|
||||
Executable
+285
@@ -0,0 +1,285 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
|
||||
USE_PROCD=1
|
||||
START=99
|
||||
|
||||
extra_command "uciadd" "<interface> <device> <zone> Add docker bridge configuration to network and firewall uci config"
|
||||
extra_command "ucidel" "<interface> <device> <zone> Delete docker bridge configuration from network and firewall uci config"
|
||||
|
||||
DOCKER_CONF_DIR="/tmp/dockerd"
|
||||
DOCKERD_CONF="${DOCKER_CONF_DIR}/daemon.json"
|
||||
|
||||
uci_quiet() {
|
||||
uci -q "${@}" >/dev/null
|
||||
}
|
||||
|
||||
json_add_array_string() {
|
||||
json_add_string "" "${1}"
|
||||
}
|
||||
|
||||
find_network_device() {
|
||||
local device="${1}"
|
||||
local device_section=""
|
||||
|
||||
check_device() {
|
||||
local cfg="${1}"
|
||||
local device="${2}"
|
||||
|
||||
local type name
|
||||
config_get type "${cfg}" type
|
||||
config_get name "${cfg}" name
|
||||
|
||||
[ "${type}" = "bridge" ] && [ "${name}" = "${device}" ] \
|
||||
&& device_section="${cfg}"
|
||||
}
|
||||
|
||||
config_load network
|
||||
config_foreach check_device device "${device}"
|
||||
|
||||
echo "${device_section}"
|
||||
}
|
||||
|
||||
boot() {
|
||||
uciadd
|
||||
rc_procd start_service
|
||||
}
|
||||
|
||||
uciadd() {
|
||||
local iface="${1}"
|
||||
local device="${2}"
|
||||
local zone="${3}"
|
||||
|
||||
[ -z "${iface}" ] && {
|
||||
iface="docker"
|
||||
device="docker0"
|
||||
zone="docker"
|
||||
}
|
||||
|
||||
/etc/init.d/dockerd running && {
|
||||
echo "Please stop dockerd service first"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Add network interface
|
||||
if ! uci_quiet get network.${iface}; then
|
||||
logger -t "dockerd-init" -p notice "Adding interface '${iface}' to network config"
|
||||
uci_quiet add network interface
|
||||
uci_quiet rename network.@interface[-1]="${iface}"
|
||||
uci_quiet set network.@interface[-1].device="${device}"
|
||||
uci_quiet set network.@interface[-1].proto="none"
|
||||
uci_quiet set network.@interface[-1].auto="0"
|
||||
uci_quiet commit network
|
||||
fi
|
||||
|
||||
# Add docker bridge device
|
||||
if [ "$(find_network_device "$device")" = "" ]; then
|
||||
logger -t "dockerd-init" -p notice "Adding bridge device '${device}' to network config"
|
||||
uci_quiet add network device
|
||||
uci_quiet set network.@device[-1].type="bridge"
|
||||
uci_quiet set network.@device[-1].name="${device}"
|
||||
uci_quiet commit network
|
||||
else
|
||||
logger -t "dockerd-init" -p notice "Bridge device '${device}' already defined in network config"
|
||||
fi
|
||||
|
||||
# Add firewall zone
|
||||
if ! uci_quiet get firewall.${zone}; then
|
||||
logger -t "dockerd-init" -p notice "Adding firewall zone '${zone}' to firewall config"
|
||||
uci_quiet add firewall zone
|
||||
uci_quiet rename firewall.@zone[-1]="${zone}"
|
||||
uci_quiet set firewall.@zone[-1].input="ACCEPT"
|
||||
uci_quiet set firewall.@zone[-1].output="ACCEPT"
|
||||
uci_quiet set firewall.@zone[-1].forward="ACCEPT"
|
||||
uci_quiet set firewall.@zone[-1].name="${zone}"
|
||||
uci_quiet commit firewall
|
||||
fi
|
||||
|
||||
# Add interface to firewall zone
|
||||
if uci_quiet get firewall.${zone}; then
|
||||
uci_quiet del_list firewall.${zone}.network="${iface}"
|
||||
uci_quiet add_list firewall.${zone}.network="${iface}"
|
||||
uci_quiet commit firewall
|
||||
fi
|
||||
|
||||
reload_config
|
||||
}
|
||||
|
||||
ucidel() {
|
||||
local iface="${1}"
|
||||
local device="${2}"
|
||||
local zone="${3}"
|
||||
|
||||
[ -z "${iface}" ] && {
|
||||
iface="docker"
|
||||
device="docker0"
|
||||
zone="docker"
|
||||
}
|
||||
|
||||
/etc/init.d/dockerd running && {
|
||||
echo "Please stop dockerd service first"
|
||||
exit 0
|
||||
}
|
||||
|
||||
# Remove network device
|
||||
if uci_quiet delete network.$(find_network_device "${device}"); then
|
||||
logger -t "dockerd-init" -p notice "Deleting bridge device '${device}' from network config"
|
||||
uci_quiet commit network
|
||||
fi
|
||||
|
||||
# Remove network interface
|
||||
if uci_quiet get network.${iface}; then
|
||||
logger -t "dockerd-init" -p notice "Deleting interface '${iface}' from network config"
|
||||
uci_quiet delete network.${iface}
|
||||
uci_quiet commit network
|
||||
fi
|
||||
|
||||
# Remove interface from firewall zone
|
||||
if uci_quiet get firewall.${zone}; then
|
||||
logger -t "dockerd-init" -p notice "Deleting network interface '${iface}' in zone '${zone}' from firewall config"
|
||||
uci_quiet del_list firewall.${zone}.network="${iface}"
|
||||
uci_quiet commit firewall
|
||||
# Remove Firewall zone if network is empty
|
||||
if ! uci_quiet get firewall.${zone}.network; then
|
||||
logger -t "dockerd-init" -p notice "Deleting firewall zone '${zone}' from firewall config"
|
||||
uci_quiet delete firewall.${zone}
|
||||
fi
|
||||
uci_quiet commit firewall
|
||||
fi
|
||||
|
||||
reload_config
|
||||
}
|
||||
|
||||
process_config() {
|
||||
local alt_config_file data_root log_level iptables bip
|
||||
|
||||
[ -f /etc/config/dockerd ] || {
|
||||
# Use the daemon default configuration
|
||||
DOCKERD_CONF=""
|
||||
return 0
|
||||
}
|
||||
|
||||
# reset configuration
|
||||
rm -fr "${DOCKER_CONF_DIR}"
|
||||
mkdir -p "${DOCKER_CONF_DIR}"
|
||||
|
||||
config_load 'dockerd'
|
||||
config_get alt_config_file globals alt_config_file
|
||||
[ -n "${alt_config_file}" ] && [ -f "${alt_config_file}" ] && {
|
||||
ln -s "${alt_config_file}" "${DOCKERD_CONF}"
|
||||
return 0
|
||||
}
|
||||
|
||||
config_get data_root globals data_root "/opt/docker/"
|
||||
config_get log_level globals log_level "warn"
|
||||
config_get_bool iptables globals iptables "1"
|
||||
|
||||
# Don't add these options by default
|
||||
# omission == docker defaults
|
||||
config_get log_driver globals log_driver ""
|
||||
config_get bip globals bip ""
|
||||
config_get registry_mirrors globals registry_mirrors ""
|
||||
config_get hosts globals hosts ""
|
||||
config_get dns globals dns ""
|
||||
config_get_bool ipv6 globals ipv6 ""
|
||||
config_get ip globals ip ""
|
||||
config_get fixed_cidr globals fixed_cidr ""
|
||||
config_get fixed_cidr_v6 globals fixed_cidr_v6 ""
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
json_init
|
||||
json_add_string "data-root" "${data_root}"
|
||||
json_add_string "log-level" "${log_level}"
|
||||
json_add_boolean "iptables" "${iptables}"
|
||||
[ -z "${log_driver}" ] || json_add_string "log-driver" "${log_driver}"
|
||||
[ -z "${bip}" ] || json_add_string "bip" "${bip}"
|
||||
[ -z "${registry_mirrors}" ] || json_add_array "registry-mirrors"
|
||||
[ -z "${registry_mirrors}" ] || config_list_foreach globals registry_mirrors json_add_array_string
|
||||
[ -z "${registry_mirrors}" ] || json_close_array
|
||||
[ -z "${hosts}" ] || json_add_array "hosts"
|
||||
[ -z "${hosts}" ] || config_list_foreach globals hosts json_add_array_string
|
||||
[ -z "${hosts}" ] || json_close_array
|
||||
[ -z "${dns}" ] || json_add_array "dns"
|
||||
[ -z "${dns}" ] || config_list_foreach globals dns json_add_array_string
|
||||
[ -z "${dns}" ] || json_close_array
|
||||
[ -z "${ipv6}" ] || json_add_boolean "ipv6" "${ipv6}"
|
||||
[ -z "${ip}" ] || json_add_string "ip" "${ip}"
|
||||
[ -z "${fixed_cidr}" ] || json_add_string "fixed-cidr" "${fixed_cidr}"
|
||||
[ -z "${fixed_cidr_v6}" ] || json_add_string "fixed-cidr-v6" "${fixed_cidr_v6}"
|
||||
json_dump > "${DOCKERD_CONF}"
|
||||
|
||||
[ "${iptables}" -eq "1" ] && config_foreach iptables_add_blocking_rule firewall
|
||||
}
|
||||
|
||||
start_service() {
|
||||
local nofile=$(cat /proc/sys/fs/nr_open)
|
||||
|
||||
process_config
|
||||
|
||||
procd_open_instance
|
||||
procd_set_param stderr 1
|
||||
if [ -z "${DOCKERD_CONF}" ]; then
|
||||
procd_set_param command /usr/bin/dockerd
|
||||
else
|
||||
procd_set_param command /usr/bin/dockerd --config-file="${DOCKERD_CONF}"
|
||||
fi
|
||||
procd_set_param limits nofile="${nofile} ${nofile}"
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
process_config
|
||||
procd_send_signal dockerd
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger 'dockerd'
|
||||
}
|
||||
|
||||
iptables_add_blocking_rule() {
|
||||
local cfg="${1}"
|
||||
|
||||
local device=""
|
||||
local extra_iptables_args=""
|
||||
|
||||
handle_iptables_rule() {
|
||||
local interface="${1}"
|
||||
local outbound="${2}"
|
||||
local extra_iptables_args="${3}"
|
||||
|
||||
local inbound=""
|
||||
|
||||
. /lib/functions/network.sh
|
||||
network_get_physdev inbound "${interface}"
|
||||
|
||||
[ -z "${inbound}" ] && {
|
||||
logger -t "dockerd-init" -p notice "Unable to get physical device for interface ${interface}"
|
||||
return
|
||||
}
|
||||
|
||||
# Wait for a maximum of 10 second per command, retrying every millisecond
|
||||
local iptables_wait_args="--wait 10 --wait-interval 1000"
|
||||
|
||||
# Ignore errors as it might already be present
|
||||
iptables ${iptables_wait_args} --table filter --new DOCKER-USER 2>/dev/null
|
||||
if ! iptables ${iptables_wait_args} --table filter --check DOCKER-USER --in-interface "${inbound}" --out-interface "${outbound}" ${extra_iptables_args} --jump REJECT 2>/dev/null; then
|
||||
logger -t "dockerd-init" -p notice "Drop traffic from ${inbound} to ${outbound}"
|
||||
iptables ${iptables_wait_args} --table filter --insert DOCKER-USER --in-interface "${inbound}" --out-interface "${outbound}" ${extra_iptables_args} --jump REJECT
|
||||
fi
|
||||
}
|
||||
|
||||
config_get device "${cfg}" device
|
||||
|
||||
[ -z "${device}" ] && {
|
||||
logger -t "dockerd-init" -p notice "No device configured for ${cfg}"
|
||||
return
|
||||
}
|
||||
|
||||
config_get extra_iptables_args "${cfg}" extra_iptables_args
|
||||
config_list_foreach "${cfg}" blocked_interfaces handle_iptables_rule "${device}" "${extra_iptables_args}"
|
||||
}
|
||||
|
||||
stop_service() {
|
||||
if /etc/init.d/dockerd running; then
|
||||
service_stop "/usr/bin/dockerd"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
# The following settings require a restart of docker to take full effect, A reload will only have partial or no effect:
|
||||
# log_driver
|
||||
# bip
|
||||
# blocked_interfaces
|
||||
# extra_iptables_args
|
||||
# device
|
||||
|
||||
config globals 'globals'
|
||||
# option alt_config_file '/etc/docker/daemon.json'
|
||||
option data_root '/opt/docker/'
|
||||
# option log_driver 'local'
|
||||
option log_level 'warn'
|
||||
option iptables '1'
|
||||
# list hosts 'unix:///var/run/docker.sock'
|
||||
# option bip '172.18.0.1/24'
|
||||
# option fixed_cidr '172.17.0.0/16'
|
||||
# option fixed_cidr_v6 'fc00:1::/80'
|
||||
# option ipv6 '1'
|
||||
# option ip '::ffff:0.0.0.0'
|
||||
# list dns '172.17.0.1'
|
||||
# list registry_mirrors 'https://<my-docker-mirror-host>'
|
||||
# list registry_mirrors 'https://hub.docker.com'
|
||||
|
||||
# Docker doesn't work well out of the box with fw4. This is because Docker relies on a compatibility layer that
|
||||
# naively translates iptables rules. For the best compatibility replace the following dependencies:
|
||||
# `firewall4` -> `firewall`
|
||||
# `iptables-nft` -> `iptables-legacy`
|
||||
# `ip6tables-nft` -> `ip6tables-legacy`
|
||||
|
||||
# Docker undermines the fw3 rules. By default all external source IPs are allowed to connect to the Docker host.
|
||||
# See https://docs.docker.com/network/iptables/ for more details.
|
||||
|
||||
# firewall config changes are only additive i.e firewall will need to be restarted first to clear old changes,
|
||||
# then docker restarted to load in new changes.
|
||||
config firewall 'firewall'
|
||||
option device 'docker0'
|
||||
list blocked_interfaces 'wan'
|
||||
# option extra_iptables_args '--match conntrack ! --ctstate RELATED,ESTABLISHED' # allow outbound connections
|
||||
@@ -0,0 +1,7 @@
|
||||
# Do not edit, changes to this file will be lost on upgrades
|
||||
# /etc/sysctl.conf can be used to customize sysctl settings
|
||||
|
||||
# enable bridge firewalling for docker
|
||||
net.bridge.bridge-nf-call-ip6tables=1
|
||||
net.bridge.bridge-nf-call-iptables=1
|
||||
|
||||
Executable
+52
@@ -0,0 +1,52 @@
|
||||
|
||||
#!/bin/sh
|
||||
#
|
||||
# USAGE: git-short-commit.sh <GIT_URL> <GIT_REF> <GIT_DIR>
|
||||
#
|
||||
|
||||
set -e
|
||||
|
||||
error() {
|
||||
echo "ERROR: ${*}" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
GIT_URL="${1}"
|
||||
if [ -z "${GIT_URL}" ]; then
|
||||
error "Git URL not specified"
|
||||
fi
|
||||
|
||||
GIT_REF="${2}"
|
||||
if [ -z "${GIT_REF}" ]; then
|
||||
error "Git reference not specified"
|
||||
fi
|
||||
|
||||
# Remove docker- prefix if present (e.g., docker-v29.2.1 -> v29.2.1)
|
||||
GIT_REF=$(echo "$GIT_REF" | sed 's/^docker-//')
|
||||
|
||||
GIT_DIR="${3}"
|
||||
if [ -z "${GIT_DIR}" ]; then
|
||||
error "Git clone directory not specified"
|
||||
fi
|
||||
|
||||
clean_up() {
|
||||
rm -rf "${GIT_DIR}"
|
||||
}
|
||||
trap clean_up EXIT
|
||||
|
||||
git init --quiet "${GIT_DIR}"
|
||||
(
|
||||
cd "${GIT_DIR}"
|
||||
for PREFIX in "" "https://" "http://" "git@"; do
|
||||
echo "Trying remote '${PREFIX}${GIT_URL}'" >&2
|
||||
git remote add origin "${PREFIX}${GIT_URL}"
|
||||
|
||||
if git fetch --depth 1 origin "${GIT_REF}"; then
|
||||
git checkout --detach FETCH_HEAD --
|
||||
git rev-parse --short HEAD
|
||||
break
|
||||
fi
|
||||
|
||||
git remote remove origin
|
||||
done
|
||||
)
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=fibocom-dial
|
||||
PKG_RELEASE:=1
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/fibocom-dial
|
||||
SECTION:=utils
|
||||
CATEGORY:=Utilities
|
||||
TITLE:=Fibocom Dial
|
||||
endef
|
||||
|
||||
define Build/Prepare
|
||||
mkdir -p $(PKG_BUILD_DIR)
|
||||
$(CP) ./src/* $(PKG_BUILD_DIR)/
|
||||
endef
|
||||
|
||||
define Package/fibocom-dial/install
|
||||
$(INSTALL_DIR) $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fibocom-dial $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/fibo_qmimsg_server $(1)/usr/bin
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/multi-pdn-manager $(1)/usr/bin
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,fibocom-dial))
|
||||
Executable
+275
@@ -0,0 +1,275 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
|
||||
#include "QMIThread.h"
|
||||
|
||||
#ifdef CONFIG_GOBINET
|
||||
|
||||
// IOCTL to generate a client ID for this service type
|
||||
#define IOCTL_QMI_GET_SERVICE_FILE 0x8BE0 + 1
|
||||
|
||||
// IOCTL to get the VIDPID of the device
|
||||
#define IOCTL_QMI_GET_DEVICE_VIDPID 0x8BE0 + 2
|
||||
|
||||
// IOCTL to get the MEID of the device
|
||||
#define IOCTL_QMI_GET_DEVICE_MEID 0x8BE0 + 3
|
||||
|
||||
static int GobiNetSendQMI(PQCQMIMSG pRequest)
|
||||
{
|
||||
int ret, fd;
|
||||
|
||||
static int send_count = 0;
|
||||
fd = qmiclientId[pRequest->QMIHdr.QMIType];
|
||||
|
||||
if (fd <= 0) {
|
||||
dbg_time("%s QMIType: %d has no clientID", __func__,
|
||||
pRequest->QMIHdr.QMIType);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
// Always ready to write
|
||||
re_write:
|
||||
if (1 == 1) {
|
||||
ssize_t nwrites =
|
||||
le16_to_cpu(pRequest->QMIHdr.Length) + 1 - sizeof(QCQMI_HDR);
|
||||
ret = write(fd, &pRequest->MUXMsg, nwrites);
|
||||
if (ret == nwrites)
|
||||
{
|
||||
ret = 0;
|
||||
send_count = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
send_count++;
|
||||
dbg_time("%s write=%d, errno: %d (%s) send_count %d", __func__, ret, errno, strerror(errno), send_count);
|
||||
if (send_count < 3)
|
||||
{
|
||||
sleep(1);
|
||||
goto re_write;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
dbg_time("%s poll=%d, errno: %d (%s)", __func__, ret, errno,
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int GobiNetGetClientID(const char *qcqmi, UCHAR QMIType)
|
||||
{
|
||||
int ClientId;
|
||||
ClientId = open(qcqmi, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||
if (ClientId == -1) {
|
||||
dbg_time("failed to open %s, errno: %d (%s)", qcqmi, errno,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ioctl(ClientId, IOCTL_QMI_GET_SERVICE_FILE, QMIType) != 0) {
|
||||
dbg_time("failed to get ClientID for 0x%02x errno: %d (%s)", QMIType,
|
||||
errno, strerror(errno));
|
||||
close(ClientId);
|
||||
ClientId = 0;
|
||||
}
|
||||
|
||||
dbg_time("%s: QMIType = %d clientid %d", __func__, QMIType, ClientId);
|
||||
|
||||
switch (QMIType) {
|
||||
case QMUX_TYPE_WDS:
|
||||
dbg_time("Get clientWDS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_DMS:
|
||||
dbg_time("Get clientDMS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_NAS:
|
||||
dbg_time("Get clientNAS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_QOS:
|
||||
dbg_time("Get clientQOS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_WMS:
|
||||
dbg_time("Get clientWMS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_PDS:
|
||||
dbg_time("Get clientPDS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_UIM:
|
||||
dbg_time("Get clientUIM = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_WDS_ADMIN:
|
||||
dbg_time("Get clientWDA = %d", ClientId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ClientId;
|
||||
}
|
||||
|
||||
static int GobiNetDeInit(void)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < sizeof(qmiclientId) / sizeof(qmiclientId[0]); i++) {
|
||||
if (qmiclientId[i] != 0) {
|
||||
close(qmiclientId[i]);
|
||||
qmiclientId[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
static void *GobiNetThread(void *pData)
|
||||
{
|
||||
PROFILE_T *profile = (PROFILE_T *)pData;
|
||||
const char *qcqmi = (const char *)profile->qmichannel;
|
||||
int wait_for_request_quit = 0;
|
||||
dbg_time("%s %d", __func__, __LINE__);
|
||||
if (profile->ipv4_flag)
|
||||
qmiclientId[QMUX_TYPE_WDS] = GobiNetGetClientID(qcqmi, QMUX_TYPE_WDS);
|
||||
if (profile->ipv6_flag)
|
||||
qmiclientId[QMUX_TYPE_WDS_IPV6] = GobiNetGetClientID(qcqmi, QMUX_TYPE_WDS);
|
||||
qmiclientId[QMUX_TYPE_DMS] = GobiNetGetClientID(qcqmi, QMUX_TYPE_DMS);
|
||||
qmiclientId[QMUX_TYPE_NAS] = GobiNetGetClientID(qcqmi, QMUX_TYPE_NAS);
|
||||
qmiclientId[QMUX_TYPE_UIM] = GobiNetGetClientID(qcqmi, QMUX_TYPE_UIM);
|
||||
// qmiclientId[QMUX_TYPE_WDS_ADMIN] =
|
||||
// GobiNetGetClientID(qcqmi, QMUX_TYPE_WDS_ADMIN);
|
||||
|
||||
//if ((qmiclientId[QMUX_TYPE_WDS] == 0) && (qmiclientId[QMUX_TYPE_WDS_IPV6] == 0)) /*|| (clientWDA == -1)*/ {
|
||||
|
||||
if ((qmiclientId[QMUX_TYPE_DMS] == 0) ||
|
||||
(qmiclientId[QMUX_TYPE_NAS] == 0) ||
|
||||
(qmiclientId[QMUX_TYPE_UIM] == 0) ||
|
||||
(profile->ipv4_flag ? ((qmiclientId[QMUX_TYPE_WDS] == 0) ? 1 : 0):0)||
|
||||
(profile->ipv6_flag ? ((qmiclientId[QMUX_TYPE_WDS_IPV6] == 0) ? 1 : 0):0))
|
||||
{
|
||||
GobiNetDeInit();
|
||||
dbg_time("%s Failed to open %s, errno: %d (%s)", __func__, qcqmi, errno,strerror(errno));
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_DISCONNECTED);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_CONNECTED);
|
||||
|
||||
while (1) {
|
||||
struct pollfd pollfds[16] = {{qmidevice_control_fd[1], POLLIN, 0}};
|
||||
int ne, ret, nevents = 1;
|
||||
unsigned int i;
|
||||
for (i = 0; i < sizeof(qmiclientId) / sizeof(qmiclientId[0]); i++) {
|
||||
if (qmiclientId[i] != 0) {
|
||||
pollfds[nevents].fd = qmiclientId[i];
|
||||
pollfds[nevents].events = POLLIN;
|
||||
pollfds[nevents].revents = 0;
|
||||
nevents++;
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
ret = poll(pollfds, nevents, wait_for_request_quit ? 1000 : -1);
|
||||
} while ((ret < 0) && (errno == EINTR));
|
||||
|
||||
if (ret == 0 && wait_for_request_quit) {
|
||||
QmiThreadRecvQMI(
|
||||
NULL); // main thread may pending on QmiThreadSendQMI()
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ret <= 0) {
|
||||
dbg_time("%s poll=%d, errno: %d (%s)", __func__, ret, errno,
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
for (ne = 0; ne < nevents; ne++) {
|
||||
int fd = pollfds[ne].fd;
|
||||
short revents = pollfds[ne].revents;
|
||||
|
||||
if (revents & (POLLERR | POLLHUP | POLLNVAL)) {
|
||||
dbg_time("%s poll err/hup/inval", __func__);
|
||||
dbg_time("epoll fd = %d, events = 0x%04x", fd, revents);
|
||||
if (fd == qmidevice_control_fd[1]) {
|
||||
} else {
|
||||
}
|
||||
if (revents & (POLLERR | POLLHUP | POLLNVAL))
|
||||
goto __GobiNetThread_quit;
|
||||
}
|
||||
if ((revents & POLLIN) == 0)
|
||||
continue;
|
||||
|
||||
if (fd == qmidevice_control_fd[1]) {
|
||||
int triger_event;
|
||||
if (read(fd, &triger_event, sizeof(triger_event)) ==
|
||||
sizeof(triger_event)) {
|
||||
// DBG("triger_event = 0x%x", triger_event);
|
||||
switch (triger_event) {
|
||||
case RIL_REQUEST_QUIT:
|
||||
goto __GobiNetThread_quit;
|
||||
break;
|
||||
case SIGTERM:
|
||||
wait_for_request_quit = 1;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
{
|
||||
ssize_t nreads;
|
||||
static UCHAR QMIBuf[4096];
|
||||
PQCQMIMSG pResponse = (PQCQMIMSG)QMIBuf;
|
||||
|
||||
nreads = read(fd, &pResponse->MUXMsg,
|
||||
sizeof(QMIBuf) - sizeof(QCQMI_HDR));
|
||||
if (nreads <= 0) {
|
||||
dbg_time("%s read=%d errno: %d (%s)", __func__, (int)nreads,
|
||||
errno, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
for (i = 0; i < sizeof(qmiclientId) / sizeof(qmiclientId[0]);
|
||||
i++) {
|
||||
if (qmiclientId[i] == fd) {
|
||||
pResponse->QMIHdr.QMIType = i;
|
||||
}
|
||||
}
|
||||
|
||||
pResponse->QMIHdr.IFType = USB_CTL_MSG_TYPE_QMI;
|
||||
pResponse->QMIHdr.Length =
|
||||
cpu_to_le16(nreads + sizeof(QCQMI_HDR) - 1);
|
||||
pResponse->QMIHdr.CtlFlags = 0x00;
|
||||
pResponse->QMIHdr.ClientId = fd & 0xFF;
|
||||
|
||||
QmiThreadRecvQMI(pResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__GobiNetThread_quit:
|
||||
GobiNetDeInit();
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_DISCONNECTED);
|
||||
QmiThreadRecvQMI(NULL); // main thread may pending on QmiThreadSendQMI()
|
||||
dbg_time("%s exit", __func__);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#else
|
||||
static int GobiNetSendQMI(PQCQMIMSG pRequest) { return -1; }
|
||||
static void *GobiNetThread(void *pData)
|
||||
{
|
||||
dbg_time("please set CONFIG_GOBINET");
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
const struct qmi_device_ops gobi_qmidev_ops = {
|
||||
.deinit = GobiNetDeInit,
|
||||
.send = GobiNetSendQMI,
|
||||
.read = GobiNetThread,
|
||||
};
|
||||
Executable
+363
@@ -0,0 +1,363 @@
|
||||
/*===========================================================================
|
||||
|
||||
M P Q C T L. H
|
||||
DESCRIPTION:
|
||||
|
||||
This module contains QMI QCTL module.
|
||||
|
||||
INITIALIZATION AND SEQUENCING REQUIREMENTS:
|
||||
|
||||
Copyright (C) 2011 by Qualcomm Technologies, Incorporated. All Rights Reserved.
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef MPQCTL_H
|
||||
#define MPQCTL_H
|
||||
|
||||
#include "MPQMI.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// ================= QMICTL ==================
|
||||
|
||||
// QMICTL Control Flags
|
||||
#define QMICTL_CTL_FLAG_CMD 0x00
|
||||
#define QMICTL_CTL_FLAG_RSP 0x01
|
||||
#define QMICTL_CTL_FLAG_IND 0x02
|
||||
|
||||
#if 0
|
||||
typedef struct _QMICTL_TRANSACTION_ITEM
|
||||
{
|
||||
LIST_ENTRY List;
|
||||
UCHAR TransactionId; // QMICTL transaction id
|
||||
PVOID Context; // Adapter or IocDev
|
||||
PIRP Irp;
|
||||
} QMICTL_TRANSACTION_ITEM, *PQMICTL_TRANSACTION_ITEM;
|
||||
#endif
|
||||
|
||||
typedef struct _QCQMICTL_MSG_HDR {
|
||||
UCHAR CtlFlags; // 00-cmd, 01-rsp, 10-ind
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType;
|
||||
USHORT Length;
|
||||
} __attribute__((packed)) QCQMICTL_MSG_HDR, *PQCQMICTL_MSG_HDR;
|
||||
|
||||
#define QCQMICTL_MSG_HDR_SIZE sizeof(QCQMICTL_MSG_HDR)
|
||||
|
||||
typedef struct _QCQMICTL_MSG_HDR_RESP {
|
||||
UCHAR CtlFlags; // 00-cmd, 01-rsp, 10-ind
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType;
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // 0x02 - result code
|
||||
USHORT TLVLength; // 4
|
||||
USHORT QMUXResult; // QMI_RESULT_SUCCESS
|
||||
// QMI_RESULT_FAILURE
|
||||
USHORT QMUXError; // QMI_ERR_INVALID_ARG
|
||||
// QMI_ERR_NO_MEMORY
|
||||
// QMI_ERR_INTERNAL
|
||||
// QMI_ERR_FAULT
|
||||
} __attribute__((packed)) QCQMICTL_MSG_HDR_RESP, *PQCQMICTL_MSG_HDR_RESP;
|
||||
|
||||
typedef struct _QCQMICTL_MSG {
|
||||
UCHAR CtlFlags; // 00-cmd, 01-rsp, 10-ind
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType;
|
||||
USHORT Length;
|
||||
UCHAR Payload;
|
||||
} __attribute__((packed)) QCQMICTL_MSG, *PQCQMICTL_MSG;
|
||||
|
||||
// TLV Header
|
||||
typedef struct _QCQMICTL_TLV_HDR {
|
||||
UCHAR TLVType;
|
||||
USHORT TLVLength;
|
||||
} __attribute__((packed)) QCQMICTL_TLV_HDR, *PQCQMICTL_TLV_HDR;
|
||||
|
||||
#define QCQMICTL_TLV_HDR_SIZE sizeof(QCQMICTL_TLV_HDR)
|
||||
|
||||
// QMICTL Type
|
||||
#define QMICTL_SET_INSTANCE_ID_REQ 0x0020
|
||||
#define QMICTL_SET_INSTANCE_ID_RESP 0x0020
|
||||
#define QMICTL_GET_VERSION_REQ 0x0021
|
||||
#define QMICTL_GET_VERSION_RESP 0x0021
|
||||
#define QMICTL_GET_CLIENT_ID_REQ 0x0022
|
||||
#define QMICTL_GET_CLIENT_ID_RESP 0x0022
|
||||
#define QMICTL_RELEASE_CLIENT_ID_REQ 0x0023
|
||||
#define QMICTL_RELEASE_CLIENT_ID_RESP 0x0023
|
||||
#define QMICTL_REVOKE_CLIENT_ID_IND 0x0024
|
||||
#define QMICTL_INVALID_CLIENT_ID_IND 0x0025
|
||||
#define QMICTL_SET_DATA_FORMAT_REQ 0x0026
|
||||
#define QMICTL_SET_DATA_FORMAT_RESP 0x0026
|
||||
#define QMICTL_SYNC_REQ 0x0027
|
||||
#define QMICTL_SYNC_RESP 0x0027
|
||||
#define QMICTL_SYNC_IND 0x0027
|
||||
|
||||
#define QMICTL_FLAG_REQUEST 0x00
|
||||
#define QMICTL_FLAG_RESPONSE 0x01
|
||||
#define QMICTL_FLAG_INDICATION 0x02
|
||||
|
||||
// QMICTL Message Definitions
|
||||
|
||||
typedef struct _QMICTL_SET_INSTANCE_ID_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_SET_INSTANCE_ID_REQ
|
||||
USHORT Length; // 4
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR Value; // Host-unique QMI instance for this device driver
|
||||
} __attribute__((packed)) QMICTL_SET_INSTANCE_ID_REQ_MSG,
|
||||
*PQMICTL_SET_INSTANCE_ID_REQ_MSG;
|
||||
|
||||
typedef struct _QMICTL_SET_INSTANCE_ID_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_SET_INSTANCE_ID_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult;
|
||||
USHORT QMIError;
|
||||
UCHAR TLV2Type; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLV2Length; // 0x0002
|
||||
USHORT QMI_ID; // Upper byte is assigned by MSM,
|
||||
// lower assigned by host
|
||||
} __attribute__((packed)) QMICTL_SET_INSTANCE_ID_RESP_MSG,
|
||||
*PQMICTL_SET_INSTANCE_ID_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_GET_VERSION_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_GET_VERSION_REQ
|
||||
USHORT Length; // 0
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // var
|
||||
UCHAR QMUXTypes; // List of one byte QMUX_TYPE values
|
||||
// 0xFF returns a list of versions for all
|
||||
// QMUX_TYPEs implemented on the device
|
||||
} __attribute__((packed)) QMICTL_GET_VERSION_REQ_MSG,
|
||||
*PQMICTL_GET_VERSION_REQ_MSG;
|
||||
|
||||
typedef struct _QMUX_TYPE_VERSION_STRUCT {
|
||||
UCHAR QMUXType;
|
||||
USHORT MajorVersion;
|
||||
USHORT MinorVersion;
|
||||
} __attribute__((packed)) QMUX_TYPE_VERSION_STRUCT, *PQMUX_TYPE_VERSION_STRUCT;
|
||||
|
||||
typedef struct _ADDENDUM_VERSION_PREAMBLE {
|
||||
UCHAR LabelLength;
|
||||
UCHAR Label;
|
||||
} __attribute__((packed)) ADDENDUM_VERSION_PREAMBLE,
|
||||
*PADDENDUM_VERSION_PREAMBLE;
|
||||
|
||||
#define QMICTL_GET_VERSION_RSP_TLV_TYPE_VERSION 0x01
|
||||
#define QMICTL_GET_VERSION_RSP_TLV_TYPE_ADD_VERSION 0x10
|
||||
|
||||
typedef struct _QMICTL_GET_VERSION_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_GET_VERSION_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult;
|
||||
USHORT QMIError;
|
||||
UCHAR TLV2Type; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLV2Length; // var
|
||||
UCHAR NumElements; // Num of QMUX_TYPE_VERSION_STRUCT
|
||||
QMUX_TYPE_VERSION_STRUCT TypeVersion[0];
|
||||
} __attribute__((packed)) QMICTL_GET_VERSION_RESP_MSG,
|
||||
*PQMICTL_GET_VERSION_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_GET_CLIENT_ID_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_GET_CLIENT_ID_REQ
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR QMIType; // QMUX type
|
||||
} __attribute__((packed)) QMICTL_GET_CLIENT_ID_REQ_MSG,
|
||||
*PQMICTL_GET_CLIENT_ID_REQ_MSG;
|
||||
|
||||
typedef struct _QMICTL_GET_CLIENT_ID_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_GET_CLIENT_ID_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult; // result code
|
||||
USHORT QMIError; // error code
|
||||
UCHAR TLV2Type; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLV2Length; // 2
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QMICTL_GET_CLIENT_ID_RESP_MSG,
|
||||
*PQMICTL_GET_CLIENT_ID_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_RELEASE_CLIENT_ID_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_RELEASE_CLIENT_ID_REQ
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 0x0002
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QMICTL_RELEASE_CLIENT_ID_REQ_MSG,
|
||||
*PQMICTL_RELEASE_CLIENT_ID_REQ_MSG;
|
||||
|
||||
typedef struct _QMICTL_RELEASE_CLIENT_ID_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_RELEASE_CLIENT_ID_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult; // result code
|
||||
USHORT QMIError; // error code
|
||||
UCHAR TLV2Type; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLV2Length; // 2
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QMICTL_RELEASE_CLIENT_ID_RESP_MSG,
|
||||
*PQMICTL_RELEASE_CLIENT_ID_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_REVOKE_CLIENT_ID_IND_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_INDICATION
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_REVOKE_CLIENT_ID_IND
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 0x0002
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QMICTL_REVOKE_CLIENT_ID_IND_MSG,
|
||||
*PQMICTL_REVOKE_CLIENT_ID_IND_MSG;
|
||||
|
||||
typedef struct _QMICTL_INVALID_CLIENT_ID_IND_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_INDICATION
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_REVOKE_CLIENT_ID_IND
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 0x0002
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QMICTL_INVALID_CLIENT_ID_IND_MSG,
|
||||
*PQMICTL_INVALID_CLIENT_ID_IND_MSG;
|
||||
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_SET_DATA_FORMAT_REQ
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_REQUIRED_PARAMETER
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR DataFormat; // 0-default; 1-QoS hdr present
|
||||
} __attribute__((packed)) QMICTL_SET_DATA_FORMAT_REQ_MSG,
|
||||
*PQMICTL_SET_DATA_FORMAT_REQ_MSG;
|
||||
|
||||
#ifdef QC_IP_MODE
|
||||
#define SET_DATA_FORMAT_TLV_TYPE_LINK_PROTO 0x10
|
||||
#define SET_DATA_FORMAT_LINK_PROTO_ETH 0x0001
|
||||
#define SET_DATA_FORMAT_LINK_PROTO_IP 0x0002
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_TLV_LINK_PROT {
|
||||
UCHAR TLVType; // Link-Layer Protocol
|
||||
USHORT TLVLength; // 2
|
||||
USHORT LinkProt; // 0x1: ETH; 0x2: IP
|
||||
} QMICTL_SET_DATA_FORMAT_TLV_LINK_PROT, *PQMICTL_SET_DATA_FORMAT_TLV_LINK_PROT;
|
||||
|
||||
#ifdef QCMP_UL_TLP
|
||||
#define SET_DATA_FORMAT_TLV_TYPE_UL_TLP 0x11
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_TLV_UL_TLP {
|
||||
UCHAR TLVType; // 0x11, Uplink TLP Setting
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR UlTlpSetting; // 0x0: Disable; 0x01: Enable
|
||||
} QMICTL_SET_DATA_FORMAT_TLV_UL_TLP, *PQMICTL_SET_DATA_FORMAT_TLV_UL_TLP;
|
||||
#endif // QCMP_UL_TLP
|
||||
|
||||
#ifdef QCMP_DL_TLP
|
||||
#define SET_DATA_FORMAT_TLV_TYPE_DL_TLP 0x13
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_TLV_DL_TLP {
|
||||
UCHAR TLVType; // 0x11, Uplink TLP Setting
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR DlTlpSetting; // 0x0: Disable; 0x01: Enable
|
||||
} QMICTL_SET_DATA_FORMAT_TLV_DL_TLP, *PQMICTL_SET_DATA_FORMAT_TLV_DL_TLP;
|
||||
#endif // QCMP_DL_TLP
|
||||
|
||||
#endif // QC_IP_MODE
|
||||
|
||||
#ifdef MP_QCQOS_ENABLED
|
||||
#define SET_DATA_FORMAT_TLV_TYPE_QOS_SETTING 0x12
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_TLV_QOS_SETTING {
|
||||
UCHAR TLVType; // 0x12, QoS setting
|
||||
USHORT TLVLength; // 1
|
||||
UCHAR QosSetting; // 0x0: Disable; 0x01: Enable
|
||||
} QMICTL_SET_DATA_FORMAT_TLV_QOS_SETTING,
|
||||
*PQMICTL_SET_DATA_FORMAT_TLV_QOS_SETTING;
|
||||
#endif // MP_QCQOS_ENABLED
|
||||
|
||||
typedef struct _QMICTL_SET_DATA_FORMAT_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_SET_DATA_FORMAT_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult; // result code
|
||||
USHORT QMIError; // error code
|
||||
} __attribute__((packed)) QMICTL_SET_DATA_FORMAT_RESP_MSG,
|
||||
*PQMICTL_SET_DATA_FORMAT_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_SYNC_REQ_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_REQUEST
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_CTL_SYNC_REQ
|
||||
USHORT Length; // 0
|
||||
} __attribute__((packed)) QMICTL_SYNC_REQ_MSG, *PQMICTL_SYNC_REQ_MSG;
|
||||
|
||||
typedef struct _QMICTL_SYNC_RESP_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_RESPONSE
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_CTL_SYNC_RESP
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // QCTLV_TYPE_RESULT_CODE
|
||||
USHORT TLVLength; // 0x0004
|
||||
USHORT QMIResult;
|
||||
USHORT QMIError;
|
||||
} __attribute__((packed)) QMICTL_SYNC_RESP_MSG, *PQMICTL_SYNC_RESP_MSG;
|
||||
|
||||
typedef struct _QMICTL_SYNC_IND_MSG {
|
||||
UCHAR CtlFlags; // QMICTL_FLAG_INDICATION
|
||||
UCHAR TransactionId;
|
||||
USHORT QMICTLType; // QMICTL_REVOKE_CLIENT_ID_IND
|
||||
USHORT Length;
|
||||
} __attribute__((packed)) QMICTL_SYNC_IND_MSG, *PQMICTL_SYNC_IND_MSG;
|
||||
|
||||
typedef struct _QMICTL_MSG {
|
||||
union {
|
||||
// Message Header
|
||||
QCQMICTL_MSG_HDR QMICTLMsgHdr;
|
||||
QCQMICTL_MSG_HDR_RESP QMICTLMsgHdrRsp;
|
||||
|
||||
// QMICTL Message
|
||||
QMICTL_SET_INSTANCE_ID_REQ_MSG SetInstanceIdReq;
|
||||
QMICTL_SET_INSTANCE_ID_RESP_MSG SetInstanceIdRsp;
|
||||
QMICTL_GET_VERSION_REQ_MSG GetVersionReq;
|
||||
QMICTL_GET_VERSION_RESP_MSG GetVersionRsp;
|
||||
QMICTL_GET_CLIENT_ID_REQ_MSG GetClientIdReq;
|
||||
QMICTL_GET_CLIENT_ID_RESP_MSG GetClientIdRsp;
|
||||
QMICTL_RELEASE_CLIENT_ID_REQ_MSG ReleaseClientIdReq;
|
||||
QMICTL_RELEASE_CLIENT_ID_RESP_MSG ReleaseClientIdRsp;
|
||||
QMICTL_REVOKE_CLIENT_ID_IND_MSG RevokeClientIdInd;
|
||||
QMICTL_INVALID_CLIENT_ID_IND_MSG InvalidClientIdInd;
|
||||
QMICTL_SET_DATA_FORMAT_REQ_MSG SetDataFormatReq;
|
||||
QMICTL_SET_DATA_FORMAT_RESP_MSG SetDataFormatRsp;
|
||||
QMICTL_SYNC_REQ_MSG SyncReq;
|
||||
QMICTL_SYNC_RESP_MSG SyncRsp;
|
||||
QMICTL_SYNC_IND_MSG SyncInd;
|
||||
};
|
||||
} __attribute__((packed)) QMICTL_MSG, *PQMICTL_MSG;
|
||||
|
||||
#endif // MPQCTL_H
|
||||
Executable
+287
@@ -0,0 +1,287 @@
|
||||
/*===========================================================================
|
||||
|
||||
M P Q M I. H
|
||||
DESCRIPTION:
|
||||
|
||||
This module contains forward references to the QMI module.
|
||||
|
||||
INITIALIZATION AND SEQUENCING REQUIREMENTS:
|
||||
|
||||
Copyright (C) 2011 by Qualcomm Technologies, Incorporated. All Rights Reserved.
|
||||
===========================================================================*/
|
||||
/*===========================================================================
|
||||
|
||||
EDIT HISTORY FOR FILE
|
||||
$Header: //depot/QMI/win/qcdrivers/ndis/MPQMI.h#3 $
|
||||
|
||||
when who what, where, why
|
||||
-------- --- ----------------------------------------------------------
|
||||
11/20/04 hg Initial version.
|
||||
===========================================================================*/
|
||||
|
||||
#ifndef USBQMI_H
|
||||
#define USBQMI_H
|
||||
|
||||
typedef char CHAR;
|
||||
typedef unsigned char UCHAR;
|
||||
typedef unsigned short USHORT;
|
||||
typedef int INT;
|
||||
typedef unsigned int UINT;
|
||||
typedef long LONG;
|
||||
typedef unsigned int ULONG;
|
||||
typedef unsigned long long ULONG64;
|
||||
typedef char *PCHAR;
|
||||
typedef unsigned char *PUCHAR;
|
||||
typedef int *PINT;
|
||||
typedef int BOOL;
|
||||
|
||||
#define TRUE (1 == 1)
|
||||
#define FALSE (1 != 1)
|
||||
|
||||
#define QMICTL_SUPPORTED_MAJOR_VERSION 1
|
||||
#define QMICTL_SUPPORTED_MINOR_VERSION 0
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
// ========= USB Control Message ==========
|
||||
|
||||
#define USB_CTL_MSG_TYPE_QMI 0x01
|
||||
|
||||
// USB Control Message
|
||||
typedef struct _QCUSB_CTL_MSG_HDR {
|
||||
UCHAR IFType;
|
||||
} __attribute__((packed)) QCUSB_CTL_MSG_HDR, *PQCUSB_CTL_MSG_HDR;
|
||||
|
||||
#define QCUSB_CTL_MSG_HDR_SIZE sizeof(QCUSB_CTL_MSG_HDR)
|
||||
|
||||
typedef struct _QCUSB_CTL_MSG {
|
||||
UCHAR IFType;
|
||||
UCHAR Message;
|
||||
} __attribute__((packed)) QCUSB_CTL_MSG, *PQCUSB_CTL_MSG;
|
||||
|
||||
#define QCTLV_TYPE_REQUIRED_PARAMETER 0x01
|
||||
#define QCTLV_TYPE_RESULT_CODE 0x02
|
||||
|
||||
// ================= QMI ==================
|
||||
|
||||
// Define QMI Type
|
||||
typedef enum _QMI_SERVICE_TYPE {
|
||||
QMUX_TYPE_CTL = 0x00,
|
||||
QMUX_TYPE_WDS = 0x01,
|
||||
QMUX_TYPE_DMS = 0x02,
|
||||
QMUX_TYPE_NAS = 0x03,
|
||||
QMUX_TYPE_QOS = 0x04,
|
||||
QMUX_TYPE_WMS = 0x05,
|
||||
QMUX_TYPE_PDS = 0x06,
|
||||
QMUX_TYPE_UIM = 0x0B,
|
||||
QMUX_TYPE_WDS_IPV6 = 0x11,
|
||||
QMUX_TYPE_WDS_ADMIN = 0x1A,
|
||||
QMUX_TYPE_MAX = 0xFF,
|
||||
QMUX_TYPE_ALL = 0xFF
|
||||
} QMI_SERVICE_TYPE;
|
||||
|
||||
typedef enum _QMI_RESULT_CODE_TYPE {
|
||||
QMI_RESULT_SUCCESS = 0x0000,
|
||||
QMI_RESULT_FAILURE = 0x0001
|
||||
} QMI_RESULT_CODE_TYPE;
|
||||
|
||||
typedef enum _QMI_ERROR_CODE_TYPE {
|
||||
QMI_ERR_NONE = 0x0000,
|
||||
QMI_ERR_MALFORMED_MSG = 0x0001,
|
||||
QMI_ERR_NO_MEMORY = 0x0002,
|
||||
QMI_ERR_INTERNAL = 0x0003,
|
||||
QMI_ERR_ABORTED = 0x0004,
|
||||
QMI_ERR_CLIENT_IDS_EXHAUSTED = 0x0005,
|
||||
QMI_ERR_UNABORTABLE_TRANSACTION = 0x0006,
|
||||
QMI_ERR_INVALID_CLIENT_ID = 0x0007,
|
||||
QMI_ERR_NO_THRESHOLDS = 0x0008,
|
||||
QMI_ERR_INVALID_HANDLE = 0x0009,
|
||||
QMI_ERR_INVALID_PROFILE = 0x000A,
|
||||
QMI_ERR_INVALID_PINID = 0x000B,
|
||||
QMI_ERR_INCORRECT_PIN = 0x000C,
|
||||
QMI_ERR_NO_NETWORK_FOUND = 0x000D,
|
||||
QMI_ERR_CALL_FAILED = 0x000E,
|
||||
QMI_ERR_OUT_OF_CALL = 0x000F,
|
||||
QMI_ERR_NOT_PROVISIONED = 0x0010,
|
||||
QMI_ERR_MISSING_ARG = 0x0011,
|
||||
QMI_ERR_ARG_TOO_LONG = 0x0013,
|
||||
QMI_ERR_INVALID_TX_ID = 0x0016,
|
||||
QMI_ERR_DEVICE_IN_USE = 0x0017,
|
||||
QMI_ERR_OP_NETWORK_UNSUPPORTED = 0x0018,
|
||||
QMI_ERR_OP_DEVICE_UNSUPPORTED = 0x0019,
|
||||
QMI_ERR_NO_EFFECT = 0x001A,
|
||||
QMI_ERR_NO_FREE_PROFILE = 0x001B,
|
||||
QMI_ERR_INVALID_PDP_TYPE = 0x001C,
|
||||
QMI_ERR_INVALID_TECH_PREF = 0x001D,
|
||||
QMI_ERR_INVALID_PROFILE_TYPE = 0x001E,
|
||||
QMI_ERR_INVALID_SERVICE_TYPE = 0x001F,
|
||||
QMI_ERR_INVALID_REGISTER_ACTION = 0x0020,
|
||||
QMI_ERR_INVALID_PS_ATTACH_ACTION = 0x0021,
|
||||
QMI_ERR_AUTHENTICATION_FAILED = 0x0022,
|
||||
QMI_ERR_PIN_BLOCKED = 0x0023,
|
||||
QMI_ERR_PIN_PERM_BLOCKED = 0x0024,
|
||||
QMI_ERR_SIM_NOT_INITIALIZED = 0x0025,
|
||||
QMI_ERR_MAX_QOS_REQUESTS_IN_USE = 0x0026,
|
||||
QMI_ERR_INCORRECT_FLOW_FILTER = 0x0027,
|
||||
QMI_ERR_NETWORK_QOS_UNAWARE = 0x0028,
|
||||
QMI_ERR_INVALID_QOS_ID = 0x0029,
|
||||
QMI_ERR_INVALID_ID = 0x0029,
|
||||
QMI_ERR_REQUESTED_NUM_UNSUPPORTED = 0x002A,
|
||||
QMI_ERR_INTERFACE_NOT_FOUND = 0x002B,
|
||||
QMI_ERR_FLOW_SUSPENDED = 0x002C,
|
||||
QMI_ERR_INVALID_DATA_FORMAT = 0x002D,
|
||||
QMI_ERR_GENERAL = 0x002E,
|
||||
QMI_ERR_UNKNOWN = 0x002F,
|
||||
QMI_ERR_INVALID_ARG = 0x0030,
|
||||
QMI_ERR_INVALID_INDEX = 0x0031,
|
||||
QMI_ERR_NO_ENTRY = 0x0032,
|
||||
QMI_ERR_DEVICE_STORAGE_FULL = 0x0033,
|
||||
QMI_ERR_DEVICE_NOT_READY = 0x0034,
|
||||
QMI_ERR_NETWORK_NOT_READY = 0x0035,
|
||||
QMI_ERR_CAUSE_CODE = 0x0036,
|
||||
QMI_ERR_MESSAGE_NOT_SENT = 0x0037,
|
||||
QMI_ERR_MESSAGE_DELIVERY_FAILURE = 0x0038,
|
||||
QMI_ERR_INVALID_MESSAGE_ID = 0x0039,
|
||||
QMI_ERR_ENCODING = 0x003A,
|
||||
QMI_ERR_AUTHENTICATION_LOCK = 0x003B,
|
||||
QMI_ERR_INVALID_TRANSITION = 0x003C,
|
||||
QMI_ERR_NOT_A_MCAST_IFACE = 0x003D,
|
||||
QMI_ERR_MAX_MCAST_REQUESTS_IN_USE = 0x003E,
|
||||
QMI_ERR_INVALID_MCAST_HANDLE = 0x003F,
|
||||
QMI_ERR_INVALID_IP_FAMILY_PREF = 0x0040,
|
||||
QMI_ERR_SESSION_INACTIVE = 0x0041,
|
||||
QMI_ERR_SESSION_INVALID = 0x0042,
|
||||
QMI_ERR_SESSION_OWNERSHIP = 0x0043,
|
||||
QMI_ERR_INSUFFICIENT_RESOURCES = 0x0044,
|
||||
QMI_ERR_DISABLED = 0x0045,
|
||||
QMI_ERR_INVALID_OPERATION = 0x0046,
|
||||
QMI_ERR_INVALID_QMI_CMD = 0x0047,
|
||||
QMI_ERR_TPDU_TYPE = 0x0048,
|
||||
QMI_ERR_SMSC_ADDR = 0x0049,
|
||||
QMI_ERR_INFO_UNAVAILABLE = 0x004A,
|
||||
QMI_ERR_SEGMENT_TOO_LONG = 0x004B,
|
||||
QMI_ERR_SEGMENT_ORDER = 0x004C,
|
||||
QMI_ERR_BUNDLING_NOT_SUPPORTED = 0x004D,
|
||||
QMI_ERR_OP_PARTIAL_FAILURE = 0x004E,
|
||||
QMI_ERR_POLICY_MISMATCH = 0x004F,
|
||||
QMI_ERR_SIM_FILE_NOT_FOUND = 0x0050,
|
||||
QMI_ERR_EXTENDED_INTERNAL = 0x0051,
|
||||
QMI_ERR_ACCESS_DENIED = 0x0052,
|
||||
QMI_ERR_HARDWARE_RESTRICTED = 0x0053,
|
||||
QMI_ERR_ACK_NOT_SENT = 0x0054,
|
||||
QMI_ERR_INJECT_TIMEOUT = 0x0055,
|
||||
QMI_ERR_INCOMPATIBLE_STATE = 0x005A,
|
||||
QMI_ERR_FDN_RESTRICT = 0x005B,
|
||||
QMI_ERR_SUPS_FAILURE_CAUSE = 0x005C,
|
||||
QMI_ERR_NO_RADIO = 0x005D,
|
||||
QMI_ERR_NOT_SUPPORTED = 0x005E,
|
||||
QMI_ERR_NO_SUBSCRIPTION = 0x005F,
|
||||
QMI_ERR_CARD_CALL_CONTROL_FAILED = 0x0060,
|
||||
QMI_ERR_NETWORK_ABORTED = 0x0061,
|
||||
QMI_ERR_MSG_BLOCKED = 0x0062,
|
||||
QMI_ERR_INVALID_SESSION_TYPE = 0x0064,
|
||||
QMI_ERR_INVALID_PB_TYPE = 0x0065,
|
||||
QMI_ERR_NO_SIM = 0x0066,
|
||||
QMI_ERR_PB_NOT_READY = 0x0067,
|
||||
QMI_ERR_PIN_RESTRICTION = 0x0068,
|
||||
QMI_ERR_PIN2_RESTRICTION = 0x0069,
|
||||
QMI_ERR_PUK_RESTRICTION = 0x006A,
|
||||
QMI_ERR_PUK2_RESTRICTION = 0x006B,
|
||||
QMI_ERR_PB_ACCESS_RESTRICTED = 0x006C,
|
||||
QMI_ERR_PB_DELETE_IN_PROG = 0x006D,
|
||||
QMI_ERR_PB_TEXT_TOO_LONG = 0x006E,
|
||||
QMI_ERR_PB_NUMBER_TOO_LONG = 0x006F,
|
||||
QMI_ERR_PB_HIDDEN_KEY_RESTRICTION = 0x0070
|
||||
} QMI_ERROR_CODE_TYPE;
|
||||
|
||||
#define QCQMI_CTL_FLAG_SERVICE 0x80
|
||||
#define QCQMI_CTL_FLAG_CTL_POINT 0x00
|
||||
|
||||
typedef struct _QCQMI_HDR {
|
||||
UCHAR IFType;
|
||||
USHORT Length;
|
||||
UCHAR CtlFlags; // reserved
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
} __attribute__((packed)) QCQMI_HDR, *PQCQMI_HDR;
|
||||
|
||||
#define QCQMI_HDR_SIZE (sizeof(QCQMI_HDR) - 1)
|
||||
|
||||
typedef struct _QCQMI {
|
||||
UCHAR IFType;
|
||||
USHORT Length;
|
||||
UCHAR CtlFlags; // reserved
|
||||
UCHAR QMIType;
|
||||
UCHAR ClientId;
|
||||
UCHAR SDU;
|
||||
} __attribute__((packed)) QCQMI, *PQCQMI;
|
||||
|
||||
typedef struct _QMI_SERVICE_VERSION {
|
||||
USHORT Major;
|
||||
USHORT Minor;
|
||||
USHORT AddendumMajor;
|
||||
USHORT AddendumMinor;
|
||||
} __attribute__((packed)) QMI_SERVICE_VERSION, *PQMI_SERVICE_VERSION;
|
||||
|
||||
// ================= QMUX ==================
|
||||
|
||||
#define QMUX_MSG_OVERHEAD_BYTES 4 // Type(USHORT) Length(USHORT) -- header
|
||||
|
||||
#define QMUX_BROADCAST_CID 0xFF
|
||||
|
||||
typedef struct _QCQMUX_HDR {
|
||||
UCHAR CtlFlags; // 0: single QMUX Msg; 1:
|
||||
USHORT TransactionId;
|
||||
} __attribute__((packed)) QCQMUX_HDR, *PQCQMUX_HDR;
|
||||
|
||||
typedef struct _QCQMUX {
|
||||
UCHAR CtlFlags; // 0: single QMUX Msg; 1:
|
||||
USHORT TransactionId;
|
||||
UCHAR Message; // Type(2), Length(2), Value
|
||||
} __attribute__((packed)) QCQMUX, *PQCQMUX;
|
||||
|
||||
#define QCQMUX_HDR_SIZE sizeof(QCQMUX_HDR)
|
||||
|
||||
typedef struct _QCQMUX_MSG_HDR {
|
||||
USHORT Type;
|
||||
USHORT Length;
|
||||
} __attribute__((packed)) QCQMUX_MSG_HDR, *PQCQMUX_MSG_HDR;
|
||||
|
||||
#define QCQMUX_MSG_HDR_SIZE sizeof(QCQMUX_MSG_HDR)
|
||||
|
||||
typedef struct _QCQMUX_MSG_HDR_RESP {
|
||||
USHORT Type;
|
||||
USHORT Length;
|
||||
UCHAR TLVType; // 0x02 - result code
|
||||
USHORT TLVLength; // 4
|
||||
USHORT QMUXResult; // QMI_RESULT_SUCCESS
|
||||
// QMI_RESULT_FAILURE
|
||||
USHORT QMUXError; // QMI_ERR_INVALID_ARG
|
||||
// QMI_ERR_NO_MEMORY
|
||||
// QMI_ERR_INTERNAL
|
||||
// QMI_ERR_FAULT
|
||||
} __attribute__((packed)) QCQMUX_MSG_HDR_RESP, *PQCQMUX_MSG_HDR_RESP;
|
||||
|
||||
typedef struct _QCQMUX_TLV {
|
||||
UCHAR Type;
|
||||
USHORT Length;
|
||||
UCHAR Value;
|
||||
} __attribute__((packed)) QCQMUX_TLV, *PQCQMUX_TLV;
|
||||
|
||||
typedef struct _QMI_TLV_HDR {
|
||||
UCHAR TLVType;
|
||||
USHORT TLVLength;
|
||||
} __attribute__((packed)) QMI_TLV_HDR, *PQMI_TLV_HDR;
|
||||
|
||||
// QMUX Message Definitions -- QMI SDU
|
||||
#define QMUX_CTL_FLAG_SINGLE_MSG 0x00
|
||||
#define QMUX_CTL_FLAG_COMPOUND_MSG 0x01
|
||||
#define QMUX_CTL_FLAG_TYPE_CMD 0x00
|
||||
#define QMUX_CTL_FLAG_TYPE_RSP 0x02
|
||||
#define QMUX_CTL_FLAG_TYPE_IND 0x04
|
||||
#define QMUX_CTL_FLAG_MASK_COMPOUND 0x01
|
||||
#define QMUX_CTL_FLAG_MASK_TYPE 0x06 // 00-cmd, 01-rsp, 10-ind
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif // USBQMI_H
|
||||
Executable
+437
@@ -0,0 +1,437 @@
|
||||
#include "QMIThread.h"
|
||||
static char line[1024];
|
||||
static pthread_mutex_t dumpQMIMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#undef dbg
|
||||
#define dbg(format, arg...) \
|
||||
do { \
|
||||
if (strlen(line) < sizeof(line)) \
|
||||
snprintf(&line[strlen(line)], sizeof(line) - strlen(line), format, \
|
||||
##arg); \
|
||||
} while (0)
|
||||
|
||||
PQMI_TLV_HDR GetTLV(PQCQMUX_MSG_HDR pQMUXMsgHdr, int TLVType);
|
||||
|
||||
typedef struct {
|
||||
UINT type;
|
||||
const char *name;
|
||||
} QMI_NAME_T;
|
||||
|
||||
#define qmi_name_item(type) \
|
||||
{ \
|
||||
type, #type \
|
||||
}
|
||||
|
||||
static const QMI_NAME_T qmux_ctl_QMICTLType[] = {
|
||||
// QMICTL Type
|
||||
qmi_name_item(QMICTL_SET_INSTANCE_ID_REQ), // 0x0020
|
||||
qmi_name_item(QMICTL_SET_INSTANCE_ID_RESP), // 0x0020
|
||||
qmi_name_item(QMICTL_GET_VERSION_REQ), // 0x0021
|
||||
qmi_name_item(QMICTL_GET_VERSION_RESP), // 0x0021
|
||||
qmi_name_item(QMICTL_GET_CLIENT_ID_REQ), // 0x0022
|
||||
qmi_name_item(QMICTL_GET_CLIENT_ID_RESP), // 0x0022
|
||||
qmi_name_item(QMICTL_RELEASE_CLIENT_ID_REQ), // 0x0023
|
||||
qmi_name_item(QMICTL_RELEASE_CLIENT_ID_RESP), // 0x0023
|
||||
qmi_name_item(QMICTL_REVOKE_CLIENT_ID_IND), // 0x0024
|
||||
qmi_name_item(QMICTL_INVALID_CLIENT_ID_IND), // 0x0025
|
||||
qmi_name_item(QMICTL_SET_DATA_FORMAT_REQ), // 0x0026
|
||||
qmi_name_item(QMICTL_SET_DATA_FORMAT_RESP), // 0x0026
|
||||
qmi_name_item(QMICTL_SYNC_REQ), // 0x0027
|
||||
qmi_name_item(QMICTL_SYNC_RESP), // 0x0027
|
||||
qmi_name_item(QMICTL_SYNC_IND), // 0x0027
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_CtlFlags[] = {
|
||||
qmi_name_item(QMUX_CTL_FLAG_TYPE_CMD),
|
||||
qmi_name_item(QMUX_CTL_FLAG_TYPE_RSP),
|
||||
qmi_name_item(QMUX_CTL_FLAG_TYPE_IND),
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_wds_Type[] = {
|
||||
qmi_name_item(QMIWDS_SET_EVENT_REPORT_REQ), // 0x0001
|
||||
qmi_name_item(QMIWDS_SET_EVENT_REPORT_RESP), // 0x0001
|
||||
qmi_name_item(QMIWDS_EVENT_REPORT_IND), // 0x0001
|
||||
qmi_name_item(QMIWDS_START_NETWORK_INTERFACE_REQ), // 0x0020
|
||||
qmi_name_item(QMIWDS_START_NETWORK_INTERFACE_RESP), // 0x0020
|
||||
qmi_name_item(QMIWDS_STOP_NETWORK_INTERFACE_REQ), // 0x0021
|
||||
qmi_name_item(QMIWDS_STOP_NETWORK_INTERFACE_RESP), // 0x0021
|
||||
qmi_name_item(QMIWDS_GET_PKT_SRVC_STATUS_REQ), // 0x0022
|
||||
qmi_name_item(QMIWDS_GET_PKT_SRVC_STATUS_RESP), // 0x0022
|
||||
qmi_name_item(QMIWDS_GET_PKT_SRVC_STATUS_IND), // 0x0022
|
||||
qmi_name_item(QMIWDS_GET_CURRENT_CHANNEL_RATE_REQ), // 0x0023
|
||||
qmi_name_item(QMIWDS_GET_CURRENT_CHANNEL_RATE_RESP), // 0x0023
|
||||
qmi_name_item(QMIWDS_GET_PKT_STATISTICS_REQ), // 0x0024
|
||||
qmi_name_item(QMIWDS_GET_PKT_STATISTICS_RESP), // 0x0024
|
||||
//begin modified by zhangkaibo add create profile qmi. mantis 0049137,0048741 20200610
|
||||
qmi_name_item(QMIWDS_CREATE_PROFILE_SETTINGS_REQ), // 0x0027
|
||||
qmi_name_item(QMIWDS_CREATE_PROFILE_SETTINGS_RESP), // 0x0027
|
||||
//end modified by zhangkaibo add create profile qmi. mantis 0049137,0048741 20200610
|
||||
qmi_name_item(QMIWDS_MODIFY_PROFILE_SETTINGS_REQ), // 0x0028
|
||||
qmi_name_item(QMIWDS_MODIFY_PROFILE_SETTINGS_RESP), // 0x0028
|
||||
qmi_name_item(QMIWDS_GET_PROFILE_SETTINGS_REQ), // 0x002B
|
||||
qmi_name_item(QMIWDS_GET_PROFILE_SETTINGS_RESP), // 0x002BD
|
||||
qmi_name_item(QMIWDS_GET_DEFAULT_SETTINGS_REQ), // 0x002C
|
||||
qmi_name_item(QMIWDS_GET_DEFAULT_SETTINGS_RESP), // 0x002C
|
||||
qmi_name_item(QMIWDS_GET_RUNTIME_SETTINGS_REQ), // 0x002D
|
||||
qmi_name_item(QMIWDS_GET_RUNTIME_SETTINGS_RESP), // 0x002D
|
||||
qmi_name_item(QMIWDS_GET_MIP_MODE_REQ), // 0x002F
|
||||
qmi_name_item(QMIWDS_GET_MIP_MODE_RESP), // 0x002F
|
||||
qmi_name_item(QMIWDS_GET_DATA_BEARER_REQ), // 0x0037
|
||||
qmi_name_item(QMIWDS_GET_DATA_BEARER_RESP), // 0x0037
|
||||
qmi_name_item(QMIWDS_DUN_CALL_INFO_REQ), // 0x0038
|
||||
qmi_name_item(QMIWDS_DUN_CALL_INFO_RESP), // 0x0038
|
||||
qmi_name_item(QMIWDS_DUN_CALL_INFO_IND), // 0x0038
|
||||
qmi_name_item(QMIWDS_SET_CLIENT_IP_FAMILY_PREF_REQ), // 0x004D
|
||||
qmi_name_item(QMIWDS_SET_CLIENT_IP_FAMILY_PREF_RESP), // 0x004D
|
||||
qmi_name_item(QMIWDS_SET_AUTO_CONNECT_REQ), // 0x0051
|
||||
qmi_name_item(QMIWDS_SET_AUTO_CONNECT_RESP), // 0x0051
|
||||
qmi_name_item(QMIWDS_BIND_MUX_DATA_PORT_REQ), // 0x00A2
|
||||
qmi_name_item(QMIWDS_BIND_MUX_DATA_PORT_RESP), // 0x00A2
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_dms_Type[] = {
|
||||
// ======================= DMS ==============================
|
||||
qmi_name_item(QMIDMS_SET_EVENT_REPORT_REQ), // 0x0001
|
||||
qmi_name_item(QMIDMS_SET_EVENT_REPORT_RESP), // 0x0001
|
||||
qmi_name_item(QMIDMS_EVENT_REPORT_IND), // 0x0001
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_CAP_REQ), // 0x0020
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_CAP_RESP), // 0x0020
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_MFR_REQ), // 0x0021
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_MFR_RESP), // 0x0021
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_MODEL_ID_REQ), // 0x0022
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_MODEL_ID_RESP), // 0x0022
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_REV_ID_REQ), // 0x0023
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_REV_ID_RESP), // 0x0023
|
||||
qmi_name_item(QMIDMS_GET_MSISDN_REQ), // 0x0024
|
||||
qmi_name_item(QMIDMS_GET_MSISDN_RESP), // 0x0024
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_SERIAL_NUMBERS_REQ), // 0x0025
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_SERIAL_NUMBERS_RESP), // 0x0025
|
||||
qmi_name_item(QMIDMS_UIM_SET_PIN_PROTECTION_REQ), // 0x0027
|
||||
qmi_name_item(QMIDMS_UIM_SET_PIN_PROTECTION_RESP), // 0x0027
|
||||
qmi_name_item(QMIDMS_UIM_VERIFY_PIN_REQ), // 0x0028
|
||||
qmi_name_item(QMIDMS_UIM_VERIFY_PIN_RESP), // 0x0028
|
||||
qmi_name_item(QMIDMS_UIM_UNBLOCK_PIN_REQ), // 0x0029
|
||||
qmi_name_item(QMIDMS_UIM_UNBLOCK_PIN_RESP), // 0x0029
|
||||
qmi_name_item(QMIDMS_UIM_CHANGE_PIN_REQ), // 0x002A
|
||||
qmi_name_item(QMIDMS_UIM_CHANGE_PIN_RESP), // 0x002A
|
||||
qmi_name_item(QMIDMS_UIM_GET_PIN_STATUS_REQ), // 0x002B
|
||||
qmi_name_item(QMIDMS_UIM_GET_PIN_STATUS_RESP), // 0x002B
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_HARDWARE_REV_REQ), // 0x002C
|
||||
qmi_name_item(QMIDMS_GET_DEVICE_HARDWARE_REV_RESP), // 0x002C
|
||||
qmi_name_item(QMIDMS_GET_OPERATING_MODE_REQ), // 0x002D
|
||||
qmi_name_item(QMIDMS_GET_OPERATING_MODE_RESP), // 0x002D
|
||||
qmi_name_item(QMIDMS_SET_OPERATING_MODE_REQ), // 0x002E
|
||||
qmi_name_item(QMIDMS_SET_OPERATING_MODE_RESP), // 0x002E
|
||||
qmi_name_item(QMIDMS_GET_ACTIVATED_STATUS_REQ), // 0x0031
|
||||
qmi_name_item(QMIDMS_GET_ACTIVATED_STATUS_RESP), // 0x0031
|
||||
qmi_name_item(QMIDMS_ACTIVATE_AUTOMATIC_REQ), // 0x0032
|
||||
qmi_name_item(QMIDMS_ACTIVATE_AUTOMATIC_RESP), // 0x0032
|
||||
qmi_name_item(QMIDMS_ACTIVATE_MANUAL_REQ), // 0x0033
|
||||
qmi_name_item(QMIDMS_ACTIVATE_MANUAL_RESP), // 0x0033
|
||||
qmi_name_item(QMIDMS_UIM_GET_ICCID_REQ), // 0x003C
|
||||
qmi_name_item(QMIDMS_UIM_GET_ICCID_RESP), // 0x003C
|
||||
qmi_name_item(QMIDMS_UIM_GET_CK_STATUS_REQ), // 0x0040
|
||||
qmi_name_item(QMIDMS_UIM_GET_CK_STATUS_RESP), // 0x0040
|
||||
qmi_name_item(QMIDMS_UIM_SET_CK_PROTECTION_REQ), // 0x0041
|
||||
qmi_name_item(QMIDMS_UIM_SET_CK_PROTECTION_RESP), // 0x0041
|
||||
qmi_name_item(QMIDMS_UIM_UNBLOCK_CK_REQ), // 0x0042
|
||||
qmi_name_item(QMIDMS_UIM_UNBLOCK_CK_RESP), // 0x0042
|
||||
qmi_name_item(QMIDMS_UIM_GET_IMSI_REQ), // 0x0043
|
||||
qmi_name_item(QMIDMS_UIM_GET_IMSI_RESP), // 0x0043
|
||||
qmi_name_item(QMIDMS_UIM_GET_STATE_REQ), // 0x0044
|
||||
qmi_name_item(QMIDMS_UIM_GET_STATE_RESP), // 0x0044
|
||||
qmi_name_item(QMIDMS_GET_BAND_CAP_REQ), // 0x0045
|
||||
qmi_name_item(QMIDMS_GET_BAND_CAP_RESP), // 0x0045
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_nas_Type[] = {
|
||||
// ======================= NAS ==============================
|
||||
qmi_name_item(QMINAS_SET_EVENT_REPORT_REQ), // 0x0002
|
||||
qmi_name_item(QMINAS_SET_EVENT_REPORT_RESP), // 0x0002
|
||||
qmi_name_item(QMINAS_EVENT_REPORT_IND), // 0x0002
|
||||
qmi_name_item(QMINAS_GET_SIGNAL_STRENGTH_REQ), // 0x0020
|
||||
qmi_name_item(QMINAS_GET_SIGNAL_STRENGTH_RESP), // 0x0020
|
||||
qmi_name_item(QMINAS_PERFORM_NETWORK_SCAN_REQ), // 0x0021
|
||||
qmi_name_item(QMINAS_PERFORM_NETWORK_SCAN_RESP), // 0x0021
|
||||
qmi_name_item(QMINAS_INITIATE_NW_REGISTER_REQ), // 0x0022
|
||||
qmi_name_item(QMINAS_INITIATE_NW_REGISTER_RESP), // 0x0022
|
||||
qmi_name_item(QMINAS_INITIATE_ATTACH_REQ), // 0x0023
|
||||
qmi_name_item(QMINAS_INITIATE_ATTACH_RESP), // 0x0023
|
||||
qmi_name_item(QMINAS_GET_SERVING_SYSTEM_REQ), // 0x0024
|
||||
qmi_name_item(QMINAS_GET_SERVING_SYSTEM_RESP), // 0x0024
|
||||
qmi_name_item(QMINAS_SERVING_SYSTEM_IND), // 0x0024
|
||||
qmi_name_item(QMINAS_GET_HOME_NETWORK_REQ), // 0x0025
|
||||
qmi_name_item(QMINAS_GET_HOME_NETWORK_RESP), // 0x0025
|
||||
qmi_name_item(QMINAS_GET_PREFERRED_NETWORK_REQ), // 0x0026
|
||||
qmi_name_item(QMINAS_GET_PREFERRED_NETWORK_RESP), // 0x0026
|
||||
qmi_name_item(QMINAS_SET_PREFERRED_NETWORK_REQ), // 0x0027
|
||||
qmi_name_item(QMINAS_SET_PREFERRED_NETWORK_RESP), // 0x0027
|
||||
qmi_name_item(QMINAS_GET_FORBIDDEN_NETWORK_REQ), // 0x0028
|
||||
qmi_name_item(QMINAS_GET_FORBIDDEN_NETWORK_RESP), // 0x0028
|
||||
qmi_name_item(QMINAS_SET_FORBIDDEN_NETWORK_REQ), // 0x0029
|
||||
qmi_name_item(QMINAS_SET_FORBIDDEN_NETWORK_RESP), // 0x0029
|
||||
qmi_name_item(QMINAS_SET_TECHNOLOGY_PREF_REQ), // 0x002A
|
||||
qmi_name_item(QMINAS_SET_TECHNOLOGY_PREF_RESP), // 0x002A
|
||||
qmi_name_item(QMINAS_GET_RF_BAND_INFO_REQ), // 0x0031
|
||||
qmi_name_item(QMINAS_GET_RF_BAND_INFO_RESP), // 0x0031
|
||||
qmi_name_item(QMINAS_GET_PLMN_NAME_REQ), // 0x0044
|
||||
qmi_name_item(QMINAS_GET_PLMN_NAME_RESP), // 0x0044
|
||||
qmi_name_item(FIBO_PACKET_TRANSFER_START_IND), // 0X100
|
||||
qmi_name_item(FIBO_PACKET_TRANSFER_END_IND), // 0X101
|
||||
qmi_name_item(QMINAS_GET_SYS_INFO_REQ), // 0x004D
|
||||
qmi_name_item(QMINAS_GET_SYS_INFO_RESP), // 0x004D
|
||||
qmi_name_item(QMINAS_SYS_INFO_IND), // 0x004D
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_wms_Type[] = {
|
||||
// ======================= WMS ==============================
|
||||
qmi_name_item(QMIWMS_SET_EVENT_REPORT_REQ), // 0x0001
|
||||
qmi_name_item(QMIWMS_SET_EVENT_REPORT_RESP), // 0x0001
|
||||
qmi_name_item(QMIWMS_EVENT_REPORT_IND), // 0x0001
|
||||
qmi_name_item(QMIWMS_RAW_SEND_REQ), // 0x0020
|
||||
qmi_name_item(QMIWMS_RAW_SEND_RESP), // 0x0020
|
||||
qmi_name_item(QMIWMS_RAW_WRITE_REQ), // 0x0021
|
||||
qmi_name_item(QMIWMS_RAW_WRITE_RESP), // 0x0021
|
||||
qmi_name_item(QMIWMS_RAW_READ_REQ), // 0x0022
|
||||
qmi_name_item(QMIWMS_RAW_READ_RESP), // 0x0022
|
||||
qmi_name_item(QMIWMS_MODIFY_TAG_REQ), // 0x0023
|
||||
qmi_name_item(QMIWMS_MODIFY_TAG_RESP), // 0x0023
|
||||
qmi_name_item(QMIWMS_DELETE_REQ), // 0x0024
|
||||
qmi_name_item(QMIWMS_DELETE_RESP), // 0x0024
|
||||
qmi_name_item(QMIWMS_GET_MESSAGE_PROTOCOL_REQ), // 0x0030
|
||||
qmi_name_item(QMIWMS_GET_MESSAGE_PROTOCOL_RESP), // 0x0030
|
||||
qmi_name_item(QMIWMS_LIST_MESSAGES_REQ), // 0x0031
|
||||
qmi_name_item(QMIWMS_LIST_MESSAGES_RESP), // 0x0031
|
||||
qmi_name_item(QMIWMS_GET_SMSC_ADDRESS_REQ), // 0x0034
|
||||
qmi_name_item(QMIWMS_GET_SMSC_ADDRESS_RESP), // 0x0034
|
||||
qmi_name_item(QMIWMS_SET_SMSC_ADDRESS_REQ), // 0x0035
|
||||
qmi_name_item(QMIWMS_SET_SMSC_ADDRESS_RESP), // 0x0035
|
||||
qmi_name_item(QMIWMS_GET_STORE_MAX_SIZE_REQ), // 0x0036
|
||||
qmi_name_item(QMIWMS_GET_STORE_MAX_SIZE_RESP), // 0x0036
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_wds_admin_Type[] = {
|
||||
qmi_name_item(QMIWDS_ADMIN_SET_DATA_FORMAT_REQ), // 0x0020
|
||||
qmi_name_item(QMIWDS_ADMIN_SET_DATA_FORMAT_RESP), // 0x0020
|
||||
qmi_name_item(QMIWDS_ADMIN_GET_DATA_FORMAT_REQ), // 0x0021
|
||||
qmi_name_item(QMIWDS_ADMIN_GET_DATA_FORMAT_RESP), // 0x0021
|
||||
qmi_name_item(QMIWDS_ADMIN_SET_QMAP_SETTINGS_REQ), // 0x002B
|
||||
qmi_name_item(QMIWDS_ADMIN_SET_QMAP_SETTINGS_RESP), // 0x002B
|
||||
qmi_name_item(QMIWDS_ADMIN_GET_QMAP_SETTINGS_REQ), // 0x002C
|
||||
qmi_name_item(QMIWDS_ADMIN_GET_QMAP_SETTINGS_RESP), // 0x002C
|
||||
};
|
||||
|
||||
static const QMI_NAME_T qmux_uim_Type[] = {
|
||||
qmi_name_item(QMIUIM_READ_TRANSPARENT_REQ), // 0x0020
|
||||
qmi_name_item(QMIUIM_READ_TRANSPARENT_RESP), // 0x0020
|
||||
qmi_name_item(QMIUIM_READ_TRANSPARENT_IND), // 0x0020
|
||||
qmi_name_item(QMIUIM_READ_RECORD_REQ), // 0x0021
|
||||
qmi_name_item(QMIUIM_READ_RECORD_RESP), // 0x0021
|
||||
qmi_name_item(QMIUIM_READ_RECORD_IND), // 0x0021
|
||||
qmi_name_item(QMIUIM_WRITE_TRANSPARENT_REQ), // 0x0022
|
||||
qmi_name_item(QMIUIM_WRITE_TRANSPARENT_RESP), // 0x0022
|
||||
qmi_name_item(QMIUIM_WRITE_TRANSPARENT_IND), // 0x0022
|
||||
qmi_name_item(QMIUIM_WRITE_RECORD_REQ), // 0x0023
|
||||
qmi_name_item(QMIUIM_WRITE_RECORD_RESP), // 0x0023
|
||||
qmi_name_item(QMIUIM_WRITE_RECORD_IND), // 0x0023
|
||||
qmi_name_item(QMIUIM_SET_PIN_PROTECTION_REQ), // 0x0025
|
||||
qmi_name_item(QMIUIM_SET_PIN_PROTECTION_RESP), // 0x0025
|
||||
qmi_name_item(QMIUIM_SET_PIN_PROTECTION_IND), // 0x0025
|
||||
qmi_name_item(QMIUIM_VERIFY_PIN_REQ), // 0x0026
|
||||
qmi_name_item(QMIUIM_VERIFY_PIN_RESP), // 0x0026
|
||||
qmi_name_item(QMIUIM_VERIFY_PIN_IND), // 0x0026
|
||||
qmi_name_item(QMIUIM_UNBLOCK_PIN_REQ), // 0x0027
|
||||
qmi_name_item(QMIUIM_UNBLOCK_PIN_RESP), // 0x0027
|
||||
qmi_name_item(QMIUIM_UNBLOCK_PIN_IND), // 0x0027
|
||||
qmi_name_item(QMIUIM_CHANGE_PIN_REQ), // 0x0028
|
||||
qmi_name_item(QMIUIM_CHANGE_PIN_RESP), // 0x0028
|
||||
qmi_name_item(QMIUIM_CHANGE_PIN_IND), // 0x0028
|
||||
qmi_name_item(QMIUIM_DEPERSONALIZATION_REQ), // 0x0029
|
||||
qmi_name_item(QMIUIM_DEPERSONALIZATION_RESP), // 0x0029
|
||||
qmi_name_item(QMIUIM_EVENT_REG_REQ), // 0x002E
|
||||
qmi_name_item(QMIUIM_EVENT_REG_RESP), // 0x002E
|
||||
qmi_name_item(QMIUIM_GET_CARD_STATUS_REQ), // 0x002F
|
||||
qmi_name_item(QMIUIM_GET_CARD_STATUS_RESP), // 0x002F
|
||||
qmi_name_item(QMIUIM_STATUS_CHANGE_IND), // 0x0032
|
||||
};
|
||||
|
||||
static const char *qmi_name_get(const QMI_NAME_T *table, size_t size, int type,
|
||||
const char *tag)
|
||||
{
|
||||
static char unknow[40];
|
||||
size_t i;
|
||||
|
||||
if (qmux_CtlFlags == table) {
|
||||
if (!strcmp(tag, "_REQ"))
|
||||
tag = "_CMD";
|
||||
else if (!strcmp(tag, "_RESP"))
|
||||
tag = "_RSP";
|
||||
}
|
||||
|
||||
for (i = 0; i < size; i++) {
|
||||
if (table[i].type == (UINT)type) {
|
||||
if (!tag || (strstr(table[i].name, tag)))
|
||||
return table[i].name;
|
||||
}
|
||||
}
|
||||
sprintf(unknow, "unknow_%x", type);
|
||||
return unknow;
|
||||
}
|
||||
|
||||
#define QMI_NAME(table, type) \
|
||||
qmi_name_get(table, sizeof(table) / sizeof(table[0]), type, 0)
|
||||
#define QMUX_NAME(table, type, tag) \
|
||||
qmi_name_get(table, sizeof(table) / sizeof(table[0]), type, tag)
|
||||
|
||||
void dump_tlv(PQCQMUX_MSG_HDR pQMUXMsgHdr)
|
||||
{
|
||||
int TLVFind = 0;
|
||||
int i;
|
||||
// dbg("QCQMUX_TLV-----------------------------------\n");
|
||||
// dbg("{Type,\tLength,\tValue}\n");
|
||||
|
||||
while (1) {
|
||||
PQMI_TLV_HDR TLVHdr = GetTLV(pQMUXMsgHdr, 0x1000 + (++TLVFind));
|
||||
if (TLVHdr == NULL)
|
||||
break;
|
||||
|
||||
// if ((TLVHdr->TLVType == 0x02) && ((USHORT *)(TLVHdr+1))[0])
|
||||
{
|
||||
dbg("{%02x,\t%04x,\t", TLVHdr->TLVType,
|
||||
le16_to_cpu(TLVHdr->TLVLength));
|
||||
for (i = 0; i < le16_to_cpu(TLVHdr->TLVLength); i++) {
|
||||
dbg("%02x ", ((UCHAR *)(TLVHdr + 1))[i]);
|
||||
}
|
||||
dbg("}\n");
|
||||
}
|
||||
} // while
|
||||
}
|
||||
|
||||
void dump_ctl(PQCQMICTL_MSG_HDR CTLHdr)
|
||||
{
|
||||
const char *tag;
|
||||
|
||||
// dbg("QCQMICTL_MSG--------------------------------------------\n");
|
||||
// dbg("CtlFlags: %02x\t\t%s\n", CTLHdr->CtlFlags,
|
||||
// QMI_NAME(qmi_ctl_CtlFlags, CTLHdr->CtlFlags));
|
||||
dbg("TransactionId: %02x\n", CTLHdr->TransactionId);
|
||||
switch (CTLHdr->CtlFlags) {
|
||||
case QMICTL_FLAG_REQUEST:
|
||||
tag = "_REQ";
|
||||
break;
|
||||
case QMICTL_FLAG_RESPONSE:
|
||||
tag = "_RESP";
|
||||
break;
|
||||
case QMICTL_FLAG_INDICATION:
|
||||
tag = "_IND";
|
||||
break;
|
||||
default:
|
||||
tag = 0;
|
||||
break;
|
||||
}
|
||||
dbg("QMICTLType: %04x\t%s\n", le16_to_cpu(CTLHdr->QMICTLType),
|
||||
QMUX_NAME(qmux_ctl_QMICTLType, le16_to_cpu(CTLHdr->QMICTLType), tag));
|
||||
dbg("Length: %04x\n", le16_to_cpu(CTLHdr->Length));
|
||||
|
||||
dump_tlv((PQCQMUX_MSG_HDR)(&CTLHdr->QMICTLType));
|
||||
}
|
||||
|
||||
int dump_qmux(QMI_SERVICE_TYPE serviceType, PQCQMUX_HDR QMUXHdr)
|
||||
{
|
||||
PQCQMUX_MSG_HDR QMUXMsgHdr = (PQCQMUX_MSG_HDR)(QMUXHdr + 1);
|
||||
CHAR *tag;
|
||||
|
||||
// dbg("QCQMUX--------------------------------------------\n");
|
||||
switch (QMUXHdr->CtlFlags & QMUX_CTL_FLAG_MASK_TYPE) {
|
||||
case QMUX_CTL_FLAG_TYPE_CMD:
|
||||
tag = "_REQ";
|
||||
break;
|
||||
case QMUX_CTL_FLAG_TYPE_RSP:
|
||||
tag = "_RESP";
|
||||
break;
|
||||
case QMUX_CTL_FLAG_TYPE_IND:
|
||||
tag = "_IND";
|
||||
break;
|
||||
default:
|
||||
tag = 0;
|
||||
break;
|
||||
}
|
||||
// dbg("CtlFlags: %02x\t\t%s\n", QMUXHdr->CtlFlags,
|
||||
// QMUX_NAME(qmux_CtlFlags, QMUXHdr->CtlFlags, tag));
|
||||
dbg("TransactionId: %04x\n", le16_to_cpu(QMUXHdr->TransactionId));
|
||||
|
||||
// dbg("QCQMUX_MSG_HDR-----------------------------------\n");
|
||||
switch (serviceType) {
|
||||
case QMUX_TYPE_DMS:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_dms_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_NAS:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_nas_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_WDS:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_wds_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_WMS:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_wms_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_WDS_ADMIN:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_wds_admin_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_UIM:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
QMUX_NAME(qmux_uim_Type, le16_to_cpu(QMUXMsgHdr->Type), tag));
|
||||
break;
|
||||
case QMUX_TYPE_PDS:
|
||||
case QMUX_TYPE_QOS:
|
||||
case QMUX_TYPE_CTL:
|
||||
default:
|
||||
dbg("Type: %04x\t%s\n", le16_to_cpu(QMUXMsgHdr->Type),
|
||||
"PDS/QOS/CTL/unknown!");
|
||||
break;
|
||||
}
|
||||
dbg("Length: %04x\n", le16_to_cpu(QMUXMsgHdr->Length));
|
||||
|
||||
dump_tlv(QMUXMsgHdr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dump_qmi(void *dataBuffer, int dataLen)
|
||||
{
|
||||
PQCQMI_HDR QMIHdr = (PQCQMI_HDR)dataBuffer;
|
||||
PQCQMUX_HDR QMUXHdr = (PQCQMUX_HDR)(QMIHdr + 1);
|
||||
PQCQMICTL_MSG_HDR CTLHdr = (PQCQMICTL_MSG_HDR)(QMIHdr + 1);
|
||||
|
||||
int i;
|
||||
|
||||
if (!debug_qmi)
|
||||
return;
|
||||
|
||||
pthread_mutex_lock(&dumpQMIMutex);
|
||||
line[0] = 0;
|
||||
for (i = 0; i < dataLen; i++) {
|
||||
dbg("%02x ", ((unsigned char *)dataBuffer)[i]);
|
||||
}
|
||||
dbg_time("%s", line);
|
||||
line[0] = 0;
|
||||
|
||||
// dbg("QCQMI_HDR-----------------------------------------");
|
||||
// dbg("IFType: %02x\t\t%s", QMIHdr->IFType,
|
||||
// QMI_NAME(qmi_IFType, QMIHdr->IFType)); dbg("Length: %04x",
|
||||
// le16_to_cpu(QMIHdr->Length)); dbg("CtlFlags: %02x\t\t%s",
|
||||
// QMIHdr->CtlFlags, QMI_NAME(qmi_CtlFlags, QMIHdr->CtlFlags));
|
||||
// dbg("QMIType: %02x\t\t%s", QMIHdr->QMIType, QMI_NAME(qmi_QMIType,
|
||||
// QMIHdr->QMIType)); dbg("ClientId: %02x", QMIHdr->ClientId);
|
||||
|
||||
if (QMIHdr->QMIType == QMUX_TYPE_CTL) {
|
||||
dump_ctl(CTLHdr);
|
||||
} else {
|
||||
dump_qmux(QMIHdr->QMIType, QMUXHdr);
|
||||
}
|
||||
dbg_time("%s", line);
|
||||
pthread_mutex_unlock(&dumpQMIMutex);
|
||||
}
|
||||
Executable
+3671
File diff suppressed because it is too large.
Load diff
Executable
+42
@@ -0,0 +1,42 @@
|
||||
ifneq ($(CROSS_COMPILE),)
|
||||
CROSS-COMPILE:=$(CROSS_COMPILE)
|
||||
endif
|
||||
|
||||
CFLAGS += -DGHT_FEATURE_PCIE_AUTO
|
||||
|
||||
ifeq ($(CC),cc)
|
||||
CC:=$(CROSS-COMPILE)gcc
|
||||
endif
|
||||
LD:=$(CROSS-COMPILE)ld
|
||||
|
||||
SRC=QmiWwanCM.c GobiNetCM.c main.c MPQMUX.c QMIThread.c util.c qmap_bridge_mode.c query_pcie_mode.c
|
||||
|
||||
FB_DHCP=udhcpc.c
|
||||
|
||||
FIBO_PROXY_SRC=fibo_qmimsg_server.c
|
||||
|
||||
LIBMNL=libmnl/ifutils.c libmnl/attr.c libmnl/callback.c libmnl/nlmsg.c libmnl/socket.c
|
||||
FB_NDHCP=udhcpc_netlink.c
|
||||
FB_NDHCP+=${LIBMNL}
|
||||
|
||||
release: clean
|
||||
$(CC) $(CFLAGS) -Wall -s ${SRC} ${FB_NDHCP} -o fibocom-dial -lpthread -ldl
|
||||
$(CC) -Wall -s multi-pdn-manager.c query_pcie_mode.c util.c -o multi-pdn-manager -lpthread -ldl
|
||||
$(CC) -Wall -s ${FIBO_PROXY_SRC} -o fibo_qmimsg_server -lpthread -ldl
|
||||
|
||||
dhcp: clean
|
||||
$(CC) $(CFLAGS) -Wall -s ${SRC} ${FB_DHCP} -o fibocom-dial -lpthread -ldl
|
||||
$(CC) -Wall -s multi-pdn-manager.c query_pcie_mode.c util.c -o multi-pdn-manager -lpthread -ldl
|
||||
$(CC) -Wall -s ${FIBO_PROXY_SRC} -o fibo_qmimsg_server -lpthread -ldl
|
||||
|
||||
ndhcp: clean
|
||||
$(CC) $(CFLAGS) -Wall -s ${SRC} ${FB_NDHCP} -o fibocom-dial -lpthread -ldl
|
||||
$(CC) -Wall -s multi-pdn-manager.c query_pcie_mode.cutil.c -o multi-pdn-manager -lpthread -ldl
|
||||
$(CC) -Wall -s ${FIBO_PROXY_SRC} -o fibo_qmimsg_server -lpthread -ldl
|
||||
|
||||
qmi-proxy:
|
||||
$(CC) -Wall -s fibo-qmi-proxy.c -o fibo-qmi-proxy -lpthread -ldl
|
||||
|
||||
clean:
|
||||
rm -rf fibocom-dial *~ multi-pdn-manager fibo_qmimsg_server
|
||||
|
||||
Executable
+2551
File diff suppressed because it is too large.
Load diff
Executable
+260
@@ -0,0 +1,260 @@
|
||||
#ifndef __QMI_THREAD_H__
|
||||
#define __QMI_THREAD_H__
|
||||
|
||||
#define CONFIG_GOBINET
|
||||
#define CONFIG_QMIWWAN
|
||||
#define CONFIG_SIM
|
||||
#define CONFIG_APN
|
||||
#define CONFIG_VERSION
|
||||
//2021-03-24 willa.liu@fibocom.com changed begin for support mantis 0071817
|
||||
#define CONFIG_IMSI_ICCID
|
||||
//2021-03-24 willa.liu@fibocom.com changed end for support mantis 0071817
|
||||
#define CONFIG_DEFAULT_PDP 1
|
||||
#define CONFIG_DEFAULT_PDPINDEX 1
|
||||
//#define CONFIG_IMSI_ICCID
|
||||
|
||||
#define CONFIG_RESET_RADIO \
|
||||
(45) // Reset Radiao(AT+CFUN=4,AT+CFUN=1) when cann not register network or
|
||||
// setup data call in 45 seconds
|
||||
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/epoll.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/poll.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <termios.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "MPQCTL.h"
|
||||
#include "MPQMI.h"
|
||||
#include "MPQMUX.h"
|
||||
|
||||
#define DEVICE_CLASS_UNKNOWN 0
|
||||
#define DEVICE_CLASS_CDMA 1
|
||||
#define DEVICE_CLASS_GSM 2
|
||||
|
||||
#define WWAN_DATA_CLASS_NONE 0x00000000
|
||||
#define WWAN_DATA_CLASS_GPRS 0x00000001
|
||||
#define WWAN_DATA_CLASS_EDGE 0x00000002 /* EGPRS */
|
||||
#define WWAN_DATA_CLASS_UMTS 0x00000004
|
||||
#define WWAN_DATA_CLASS_HSDPA 0x00000008
|
||||
#define WWAN_DATA_CLASS_HSUPA 0x00000010
|
||||
#define WWAN_DATA_CLASS_LTE 0x00000020
|
||||
//begin modified by zhangkaibo add 5G network detect feature on x55 platform. 20200605
|
||||
#define WWAN_DATA_CLASS_5G 0x00000040
|
||||
//end modified by zhangkaibo add 5G network detect feature on x55 platform. 20200605
|
||||
#define WWAN_DATA_CLASS_1XRTT 0x00010000
|
||||
#define WWAN_DATA_CLASS_1XEVDO 0x00020000
|
||||
#define WWAN_DATA_CLASS_1XEVDO_REVA 0x00040000
|
||||
#define WWAN_DATA_CLASS_1XEVDV 0x00080000
|
||||
#define WWAN_DATA_CLASS_3XRTT 0x00100000
|
||||
#define WWAN_DATA_CLASS_1XEVDO_REVB 0x00200000 /* for future use */
|
||||
#define WWAN_DATA_CLASS_UMB 0x00400000
|
||||
#define WWAN_DATA_CLASS_CUSTOM 0x80000000
|
||||
|
||||
struct wwan_data_class_str {
|
||||
ULONG class;
|
||||
CHAR *str;
|
||||
};
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
typedef struct _QCQMIMSG {
|
||||
QCQMI_HDR QMIHdr;
|
||||
union {
|
||||
QMICTL_MSG CTLMsg;
|
||||
QMUX_MSG MUXMsg;
|
||||
//2021-03-24 willa.liu@fibocom.com changed begin for support mantis 0071817
|
||||
QMUX_MSG QMUXMsgHdrResp;
|
||||
//2021-03-24 willa.liu@fibocom.com changed end for support mantis 0071817
|
||||
};
|
||||
} __attribute__((packed)) QCQMIMSG, *PQCQMIMSG;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
typedef struct __IPV4 {
|
||||
uint32_t Address;
|
||||
uint32_t Gateway;
|
||||
uint32_t SubnetMask;
|
||||
uint32_t DnsPrimary;
|
||||
uint32_t DnsSecondary;
|
||||
uint32_t Mtu;
|
||||
} IPV4_T;
|
||||
|
||||
typedef struct __IPV6 {
|
||||
UCHAR Address[16];
|
||||
UCHAR Gateway[16];
|
||||
UCHAR SubnetMask[16];
|
||||
UCHAR DnsPrimary[16];
|
||||
UCHAR DnsSecondary[16];
|
||||
UCHAR PrefixLengthIPAddr;
|
||||
UCHAR PrefixLengthGateway;
|
||||
ULONG Mtu;
|
||||
} IPV6_T;
|
||||
|
||||
#define IpFamilyV4 (0x04)
|
||||
#define IpFamilyV6 (0x06)
|
||||
|
||||
struct __PROFILE;
|
||||
struct qmi_device_ops {
|
||||
int (*init)(struct __PROFILE *profile);
|
||||
int (*deinit)(void);
|
||||
int (*send)(PQCQMIMSG pRequest);
|
||||
void *(*read)(void *pData);
|
||||
};
|
||||
extern int (*qmidev_send)(PQCQMIMSG pRequest);
|
||||
|
||||
#ifndef bool
|
||||
#define bool uint8_t
|
||||
#endif
|
||||
//2021-03-15 zhangkaibo@fibocom.com changed begin for oa 20210311037
|
||||
typedef struct {
|
||||
unsigned int size;
|
||||
unsigned int rx_urb_size;
|
||||
unsigned int ep_type;
|
||||
unsigned int iface_id;
|
||||
unsigned int qmap_mode;
|
||||
unsigned int qmap_version;
|
||||
unsigned int dl_minimum_padding;
|
||||
char ifname[8][16];
|
||||
unsigned char mux_id[8];
|
||||
} RMNET_INFO;
|
||||
//2021-03-15 zhangkaibo@fibocom.com changed end for oa 20210311037
|
||||
|
||||
typedef struct __PROFILE {
|
||||
char *qmichannel;
|
||||
char *usbnet_adapter;
|
||||
char *qmapnet_adapter;
|
||||
const char *driver_name;
|
||||
int qmap_mode;
|
||||
int qmap_size;
|
||||
int qmap_version;
|
||||
const char *apn;
|
||||
const char *user;
|
||||
const char *password;
|
||||
const char *pincode;
|
||||
int auth;
|
||||
int pdp;
|
||||
int pdpindex;
|
||||
int pdpnum;
|
||||
int curIpFamily;
|
||||
int rawIP;
|
||||
int muxid;
|
||||
IPV4_T ipv4;
|
||||
IPV6_T ipv6;
|
||||
int ipv4_flag;
|
||||
int ipv6_flag;
|
||||
|
||||
//2021-02-25 willa.liu@fibocom.com changed begin for support eipd SN-20210129001
|
||||
int ipv6_prigateway_flag;
|
||||
//2021-02-25 willa.liu@fibocom.com changed begin for support eipd SN-20210129001
|
||||
|
||||
int dual_flag;
|
||||
int apntype;
|
||||
const struct qmi_device_ops *qmi_ops;
|
||||
bool loopback_state;
|
||||
int replication_factor;
|
||||
//2021-02-08 zhangkaibo@fibocom.com changed begin for mantis 0070613
|
||||
int interfacenum;
|
||||
//2021-02-08 zhangkaibo@fibocom.com changed end for mantis 0070613
|
||||
//2021-03-15 zhangkaibo@fibocom.com changed begin for oa 20210311037
|
||||
RMNET_INFO rmnet_info;
|
||||
//2021-03-15 zhangkaibo@fibocom.com changed end for oa 20210311037
|
||||
} PROFILE_T;
|
||||
|
||||
typedef enum {
|
||||
SIM_ABSENT = 0,
|
||||
SIM_NOT_READY = 1,
|
||||
SIM_READY =
|
||||
2, /* SIM_READY means the radio state is RADIO_STATE_SIM_READY */
|
||||
SIM_PIN = 3,
|
||||
SIM_PUK = 4,
|
||||
SIM_NETWORK_PERSONALIZATION = 5,
|
||||
SIM_BAD = 6,
|
||||
} SIM_Status;
|
||||
//2021-03-24 willa.liu@fibocom.com changed begin for support mantis 0071817
|
||||
typedef enum {
|
||||
SIM_Card0 = 0,
|
||||
SIM_Card1 = 1
|
||||
} SIM_Select;
|
||||
//2021-03-24 willa.liu@fibocom.com changed end for support mantis 0071817
|
||||
#define WDM_DEFAULT_BUFSIZE 256
|
||||
#define RIL_REQUEST_QUIT 0x1000
|
||||
#define RIL_INDICATE_DEVICE_CONNECTED 0x1002
|
||||
#define RIL_INDICATE_DEVICE_DISCONNECTED 0x1003
|
||||
#define RIL_UNSOL_RESPONSE_VOICE_NETWORK_STATE_CHANGED 0x1004
|
||||
#define RIL_UNSOL_DATA_CALL_LIST_CHANGED 0x1005
|
||||
|
||||
extern int pthread_cond_timeout_np(pthread_cond_t *cond, pthread_mutex_t *mutex,
|
||||
unsigned msecs);
|
||||
extern int QmiThreadSendQMI(PQCQMIMSG pRequest, PQCQMIMSG *ppResponse);
|
||||
extern int QmiThreadSendQMITimeout(PQCQMIMSG pRequest, PQCQMIMSG *ppResponse,
|
||||
unsigned msecs);
|
||||
extern void QmiThreadRecvQMI(PQCQMIMSG pResponse);
|
||||
extern int fibo_raw_ip_mode_check(const char *ifname);
|
||||
extern void udhcpc_start(PROFILE_T *profile);
|
||||
extern void udhcpc_stop(PROFILE_T *profile);
|
||||
extern void udhcpc_start_pcie(PROFILE_T *profile);
|
||||
extern void udhcpc_stop_pcie(PROFILE_T *profile);
|
||||
|
||||
extern void dump_qmi(void *dataBuffer, int dataLen);
|
||||
extern void qmidevice_send_event_to_main(int triger_event);
|
||||
extern int requestSetEthMode(PROFILE_T *profile);
|
||||
//2021-03-24 willa.liu@fibocom.com changed begin for support mantis 0071817
|
||||
//extern int requestGetSIMStatus(SIM_Status *pSIMStatus);
|
||||
extern int requestGetSIMStatus(SIM_Status *pSIMStatus , const int sim_select);
|
||||
//2021-03-24 willa.liu@fibocom.com changed end for support mantis 0071817
|
||||
extern int requestEnterSimPin(const CHAR *pPinCode);
|
||||
extern int requestGetICCID(void);
|
||||
extern int requestGetIMSI(void);
|
||||
extern int requestRegistrationState(UCHAR *pPSAttachedState);
|
||||
extern int requestQueryDataCall(UCHAR *pConnectionStatus, int curIpFamily);
|
||||
extern int requestSetupDataCall(PROFILE_T *profile, int curIpFamily);
|
||||
extern int requestDeactivateDefaultPDP(PROFILE_T *profile, int curIpFamily);
|
||||
extern int requestSetProfile(PROFILE_T *profile);
|
||||
extern int requestGetProfile(PROFILE_T *profile);
|
||||
extern int requestBaseBandVersion(const char **pp_reversion);
|
||||
extern int requestGetIPAddress(PROFILE_T *profile, int curIpFamily);
|
||||
extern int requestSetOperatingMode(UCHAR OperatingMode);
|
||||
int requestRegistrationState2(UCHAR *pPSAttachedState);
|
||||
|
||||
extern int fibo_qmap_mode_set(PROFILE_T *profile);
|
||||
extern int fibo_bridge_mode_detect(PROFILE_T *profile);
|
||||
extern int fibo_qmap_mode_detect(PROFILE_T *profile);
|
||||
extern const struct qmi_device_ops qmiwwan_qmidev_ops;
|
||||
|
||||
#define qmidev_is_gobinet(_qmichannel) \
|
||||
(strncmp(_qmichannel, "/dev/qcqmi", strlen("/dev/qcqmi")) == 0)
|
||||
#define qmidev_is_qmiwwan(_qmichannel) \
|
||||
(strncmp(_qmichannel, "/dev/cdc-wdm", strlen("/dev/cdc-wdm")) == 0)
|
||||
#define qmidev_is_pciemhi(_qmichannel) \
|
||||
(strncmp(_qmichannel, "/dev/mhi_", strlen("/dev/mhi_")) == 0)
|
||||
|
||||
#define driver_is_qmi(_drv_name) \
|
||||
(strncasecmp(_drv_name, "qmi_wwan", strlen("qmi_wwan")) == 0)
|
||||
#define driver_is_mbim(_drv_name) \
|
||||
(strncasecmp(_drv_name, "cdc_mbim", strlen("cdc_mbim")) == 0)
|
||||
|
||||
extern FILE *logfilefp;
|
||||
extern int debug_qmi;
|
||||
extern USHORT g_MobileCountryCode;
|
||||
extern USHORT g_MobileNetworkCode;
|
||||
extern int qmidevice_control_fd[2];
|
||||
extern int qmiclientId[QMUX_TYPE_WDS_ADMIN + 1];
|
||||
extern void dbg_time(const char *fmt, ...);
|
||||
extern USHORT le16_to_cpu(USHORT v16);
|
||||
extern UINT le32_to_cpu(UINT v32);
|
||||
extern USHORT cpu_to_le16(USHORT v16);
|
||||
extern UINT cpu_to_le32(UINT v32);
|
||||
#endif
|
||||
Executable
+426
@@ -0,0 +1,426 @@
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <termios.h>
|
||||
typedef unsigned short sa_family_t;
|
||||
#include <linux/un.h>
|
||||
|
||||
#include "QMIThread.h"
|
||||
|
||||
#ifdef CONFIG_QMIWWAN
|
||||
#define FIBO_QMI_PROXY "fibo_qmimsg_server"
|
||||
static int cdc_wdm_fd = -1;
|
||||
|
||||
static UCHAR GetQCTLTransactionId(void)
|
||||
{
|
||||
static int TransactionId = 0;
|
||||
if (++TransactionId > 0xFF)
|
||||
TransactionId = 1;
|
||||
return TransactionId;
|
||||
}
|
||||
|
||||
typedef USHORT (*CUSTOMQCTL)(PQMICTL_MSG pCTLMsg, void *arg);
|
||||
|
||||
static PQCQMIMSG ComposeQCTLMsg(USHORT QMICTLType,
|
||||
CUSTOMQCTL customQctlMsgFunction, void *arg)
|
||||
{
|
||||
UCHAR QMIBuf[WDM_DEFAULT_BUFSIZE];
|
||||
PQCQMIMSG pRequest = (PQCQMIMSG)QMIBuf;
|
||||
int Length;
|
||||
|
||||
pRequest->QMIHdr.IFType = USB_CTL_MSG_TYPE_QMI;
|
||||
pRequest->QMIHdr.CtlFlags = 0x00;
|
||||
pRequest->QMIHdr.QMIType = QMUX_TYPE_CTL;
|
||||
pRequest->QMIHdr.ClientId = 0x00;
|
||||
|
||||
pRequest->CTLMsg.QMICTLMsgHdr.CtlFlags = QMICTL_FLAG_REQUEST;
|
||||
pRequest->CTLMsg.QMICTLMsgHdr.TransactionId = GetQCTLTransactionId();
|
||||
pRequest->CTLMsg.QMICTLMsgHdr.QMICTLType = cpu_to_le16(QMICTLType);
|
||||
if (customQctlMsgFunction)
|
||||
pRequest->CTLMsg.QMICTLMsgHdr.Length =
|
||||
cpu_to_le16(customQctlMsgFunction(&pRequest->CTLMsg, arg) -
|
||||
sizeof(QCQMICTL_MSG_HDR));
|
||||
else
|
||||
pRequest->CTLMsg.QMICTLMsgHdr.Length = cpu_to_le16(0x0000);
|
||||
|
||||
pRequest->QMIHdr.Length =
|
||||
cpu_to_le16(le16_to_cpu(pRequest->CTLMsg.QMICTLMsgHdr.Length) +
|
||||
sizeof(QCQMICTL_MSG_HDR) + sizeof(QCQMI_HDR) - 1);
|
||||
Length = le16_to_cpu(pRequest->QMIHdr.Length) + 1;
|
||||
|
||||
pRequest = (PQCQMIMSG)malloc(Length);
|
||||
if (pRequest == NULL) {
|
||||
dbg_time("%s fail to malloc", __func__);
|
||||
} else {
|
||||
memcpy(pRequest, QMIBuf, Length);
|
||||
}
|
||||
|
||||
return pRequest;
|
||||
}
|
||||
|
||||
static USHORT CtlGetVersionReq(PQMICTL_MSG QCTLMsg, void *arg)
|
||||
{
|
||||
QCTLMsg->GetVersionReq.TLVType = QCTLV_TYPE_REQUIRED_PARAMETER;
|
||||
QCTLMsg->GetVersionReq.TLVLength = cpu_to_le16(0x0001);
|
||||
QCTLMsg->GetVersionReq.QMUXTypes = QMUX_TYPE_ALL;
|
||||
return sizeof(QMICTL_GET_VERSION_REQ_MSG);
|
||||
}
|
||||
|
||||
static USHORT CtlGetClientIdReq(PQMICTL_MSG QCTLMsg, void *arg)
|
||||
{
|
||||
QCTLMsg->GetClientIdReq.TLVType = QCTLV_TYPE_REQUIRED_PARAMETER;
|
||||
QCTLMsg->GetClientIdReq.TLVLength = cpu_to_le16(0x0001);
|
||||
QCTLMsg->GetClientIdReq.QMIType = ((UCHAR *)arg)[0];
|
||||
return sizeof(QMICTL_GET_CLIENT_ID_REQ_MSG);
|
||||
}
|
||||
|
||||
static USHORT CtlReleaseClientIdReq(PQMICTL_MSG QCTLMsg, void *arg)
|
||||
{
|
||||
QCTLMsg->ReleaseClientIdReq.TLVType = QCTLV_TYPE_REQUIRED_PARAMETER;
|
||||
QCTLMsg->ReleaseClientIdReq.TLVLength = cpu_to_le16(0x0002);
|
||||
QCTLMsg->ReleaseClientIdReq.QMIType = ((UCHAR *)arg)[0];
|
||||
QCTLMsg->ReleaseClientIdReq.ClientId = ((UCHAR *)arg)[1];
|
||||
return sizeof(QMICTL_RELEASE_CLIENT_ID_REQ_MSG);
|
||||
}
|
||||
|
||||
static int QmiWwanSendQMI(PQCQMIMSG pRequest)
|
||||
{
|
||||
struct pollfd pollfds[] = {{cdc_wdm_fd, POLLOUT, 0}};
|
||||
int ret;
|
||||
|
||||
if (cdc_wdm_fd == -1) {
|
||||
dbg_time("%s cdc_wdm_fd = -1", __func__);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
if (pRequest->QMIHdr.QMIType == QMUX_TYPE_WDS_IPV6)
|
||||
pRequest->QMIHdr.QMIType = QMUX_TYPE_WDS;
|
||||
|
||||
do {
|
||||
ret = poll(pollfds, sizeof(pollfds) / sizeof(pollfds[0]), 5000);
|
||||
} while ((ret < 0) && (errno == EINTR));
|
||||
|
||||
if (pollfds[0].revents & POLLOUT) {
|
||||
ssize_t nwrites = le16_to_cpu(pRequest->QMIHdr.Length) + 1;
|
||||
ret = write(cdc_wdm_fd, pRequest, nwrites);
|
||||
if (ret == nwrites) {
|
||||
ret = 0;
|
||||
} else {
|
||||
dbg_time("%s write=%d, errno: %d (%s)", __func__, ret, errno,
|
||||
strerror(errno));
|
||||
}
|
||||
} else {
|
||||
dbg_time("%s poll=%d, revents = 0x%x, errno: %d (%s)", __func__, ret,
|
||||
pollfds[0].revents, errno, strerror(errno));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int QmiWwanGetClientID(UCHAR QMIType)
|
||||
{
|
||||
PQCQMIMSG pResponse;
|
||||
|
||||
QmiThreadSendQMI(
|
||||
ComposeQCTLMsg(QMICTL_GET_CLIENT_ID_REQ, CtlGetClientIdReq, &QMIType),
|
||||
&pResponse);
|
||||
|
||||
if (pResponse) {
|
||||
USHORT QMUXResult = cpu_to_le16(pResponse->CTLMsg.QMICTLMsgHdrRsp
|
||||
.QMUXResult); // QMI_RESULT_SUCCESS
|
||||
USHORT QMUXError = cpu_to_le16(pResponse->CTLMsg.QMICTLMsgHdrRsp
|
||||
.QMUXError); // QMI_ERR_INVALID_ARG
|
||||
// UCHAR QMIType = pResponse->CTLMsg.GetClientIdRsp.QMIType;
|
||||
UCHAR ClientId = pResponse->CTLMsg.GetClientIdRsp.ClientId;
|
||||
|
||||
dbg_time("%s: QMIType = %d clientid %d", __func__, QMIType, ClientId);
|
||||
|
||||
if (!QMUXResult && !QMUXError &&
|
||||
(QMIType == pResponse->CTLMsg.GetClientIdRsp.QMIType)) {
|
||||
switch (QMIType) {
|
||||
case QMUX_TYPE_WDS:
|
||||
dbg_time("Get clientWDS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_DMS:
|
||||
dbg_time("Get clientDMS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_NAS:
|
||||
dbg_time("Get clientNAS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_QOS:
|
||||
dbg_time("Get clientQOS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_WMS:
|
||||
dbg_time("Get clientWMS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_PDS:
|
||||
dbg_time("Get clientPDS = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_UIM:
|
||||
dbg_time("Get clientUIM = %d", ClientId);
|
||||
break;
|
||||
case QMUX_TYPE_WDS_ADMIN:
|
||||
dbg_time("Get clientWDA = %d", ClientId);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ClientId;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int QmiWwanReleaseClientID(QMI_SERVICE_TYPE QMIType, UCHAR ClientId)
|
||||
{
|
||||
UCHAR argv[] = {QMIType, ClientId};
|
||||
QmiThreadSendQMI(ComposeQCTLMsg(QMICTL_RELEASE_CLIENT_ID_REQ,
|
||||
CtlReleaseClientIdReq, argv),
|
||||
NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int QmiWwanInit(PROFILE_T *profile)
|
||||
{
|
||||
unsigned i;
|
||||
int ret;
|
||||
PQCQMIMSG pResponse;
|
||||
|
||||
if (profile->qmap_mode == 0 || profile->qmap_mode == 1) {
|
||||
for (i = 0; i < 10; i++) {
|
||||
ret = QmiThreadSendQMITimeout(
|
||||
ComposeQCTLMsg(QMICTL_SYNC_REQ, NULL, NULL), NULL, 1 * 1000);
|
||||
if (!ret)
|
||||
break;
|
||||
sleep(1);
|
||||
}
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
|
||||
QmiThreadSendQMI(
|
||||
ComposeQCTLMsg(QMICTL_GET_VERSION_REQ, CtlGetVersionReq, NULL),
|
||||
&pResponse);
|
||||
if (profile->qmap_mode) {
|
||||
if (pResponse) {
|
||||
if (pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXResult == 0 &&
|
||||
pResponse->CTLMsg.QMICTLMsgHdrRsp.QMUXError == 0) {
|
||||
uint8_t NumElements = 0;
|
||||
|
||||
for (NumElements = 0;
|
||||
NumElements < pResponse->CTLMsg.GetVersionRsp.NumElements;
|
||||
NumElements++) {
|
||||
if (pResponse->CTLMsg.GetVersionRsp.TypeVersion[NumElements]
|
||||
.QMUXType == QMUX_TYPE_WDS_ADMIN)
|
||||
profile->qmap_version = (pResponse->CTLMsg.GetVersionRsp
|
||||
.TypeVersion[NumElements]
|
||||
.MinorVersion > 16);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pResponse)
|
||||
free(pResponse);
|
||||
if (profile->ipv4_flag)
|
||||
qmiclientId[QMUX_TYPE_WDS] = QmiWwanGetClientID(QMUX_TYPE_WDS);
|
||||
if (profile->ipv6_flag)
|
||||
qmiclientId[QMUX_TYPE_WDS_IPV6] = QmiWwanGetClientID(QMUX_TYPE_WDS);
|
||||
qmiclientId[QMUX_TYPE_DMS] = QmiWwanGetClientID(QMUX_TYPE_DMS);
|
||||
qmiclientId[QMUX_TYPE_NAS] = QmiWwanGetClientID(QMUX_TYPE_NAS);
|
||||
qmiclientId[QMUX_TYPE_UIM] = QmiWwanGetClientID(QMUX_TYPE_UIM);
|
||||
if (profile->qmap_mode == 0 || profile->qmap_mode == 1)
|
||||
qmiclientId[QMUX_TYPE_WDS_ADMIN] =
|
||||
QmiWwanGetClientID(QMUX_TYPE_WDS_ADMIN);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int QmiWwanDeInit(void)
|
||||
{
|
||||
unsigned int i;
|
||||
for (i = 0; i < sizeof(qmiclientId) / sizeof(qmiclientId[0]); i++) {
|
||||
if (qmiclientId[i] != 0) {
|
||||
QmiWwanReleaseClientID(i, qmiclientId[i]);
|
||||
qmiclientId[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int qmi_proxy_open(const char *name)
|
||||
{
|
||||
int sockfd = -1;
|
||||
int reuse_addr = 1;
|
||||
struct sockaddr_un sockaddr;
|
||||
socklen_t alen;
|
||||
|
||||
/*Create server socket*/
|
||||
(sockfd = socket(AF_LOCAL, SOCK_STREAM, 0));
|
||||
if (sockfd < 0)
|
||||
return sockfd;
|
||||
|
||||
memset(&sockaddr, 0, sizeof(sockaddr));
|
||||
sockaddr.sun_family = AF_LOCAL;
|
||||
sockaddr.sun_path[0] = 0;
|
||||
memcpy(sockaddr.sun_path + 1, name, strlen(name));
|
||||
|
||||
alen = strlen(name) + offsetof(struct sockaddr_un, sun_path) + 1;
|
||||
if (connect(sockfd, (struct sockaddr *)&sockaddr, alen) < 0) {
|
||||
close(sockfd);
|
||||
dbg_time("%s connect %s errno: %d (%s)\n", __func__, name, errno,
|
||||
strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
(setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse_addr,
|
||||
sizeof(reuse_addr)));
|
||||
|
||||
dbg_time("connect to %s sockfd = %d\n", name, sockfd);
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
|
||||
static ssize_t qmi_proxy_read(int fd, void *buf, size_t size)
|
||||
{
|
||||
ssize_t nreads;
|
||||
PQCQMI_HDR pHdr = (PQCQMI_HDR)buf;
|
||||
|
||||
nreads = read(fd, pHdr, sizeof(QCQMI_HDR));
|
||||
if (nreads == sizeof(QCQMI_HDR)) {
|
||||
nreads += read(fd, pHdr + 1,
|
||||
le16_to_cpu(pHdr->Length) + 1 - sizeof(QCQMI_HDR));
|
||||
}
|
||||
|
||||
return nreads;
|
||||
}
|
||||
|
||||
static void *QmiWwanThread(void *pData)
|
||||
{
|
||||
PROFILE_T *profile = (PROFILE_T *)pData;
|
||||
const char *cdc_wdm = (const char *)profile->qmichannel;
|
||||
|
||||
if (profile->qmap_mode == 0 || profile->qmap_mode == 1)
|
||||
cdc_wdm_fd = open(cdc_wdm, O_RDWR | O_NONBLOCK | O_NOCTTY);
|
||||
else
|
||||
cdc_wdm_fd = qmi_proxy_open(FIBO_QMI_PROXY);
|
||||
|
||||
if (cdc_wdm_fd == -1) {
|
||||
dbg_time("%s Failed to open %s, errno: %d (%s)", __func__, cdc_wdm,
|
||||
errno, strerror(errno));
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_DISCONNECTED);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
fcntl(cdc_wdm_fd, F_SETFL, fcntl(cdc_wdm_fd, F_GETFL) | O_NONBLOCK);
|
||||
fcntl(cdc_wdm_fd, F_SETFD, FD_CLOEXEC);
|
||||
|
||||
dbg_time("cdc_wdm_fd = %d", cdc_wdm_fd);
|
||||
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_CONNECTED);
|
||||
|
||||
while (1) {
|
||||
struct pollfd pollfds[] = {{qmidevice_control_fd[1], POLLIN, 0},
|
||||
{cdc_wdm_fd, POLLIN, 0}};
|
||||
int ne, ret, nevents = sizeof(pollfds) / sizeof(pollfds[0]);
|
||||
|
||||
do {
|
||||
ret = poll(pollfds, nevents, -1);
|
||||
} while ((ret < 0) && (errno == EINTR));
|
||||
|
||||
if (ret <= 0) {
|
||||
dbg_time("%s poll=%d, errno: %d (%s)", __func__, ret, errno,
|
||||
strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
for (ne = 0; ne < nevents; ne++) {
|
||||
int fd = pollfds[ne].fd;
|
||||
short revents = pollfds[ne].revents;
|
||||
|
||||
// dbg_time("{%d, %x, %x}", pollfds[ne].fd, pollfds[ne].events,
|
||||
// pollfds[ne].revents);
|
||||
|
||||
if (revents & (POLLERR | POLLHUP | POLLNVAL)) {
|
||||
dbg_time("%s poll err/hup/inval", __func__);
|
||||
dbg_time("poll fd = %d, events = 0x%04x", fd, revents);
|
||||
if (fd == cdc_wdm_fd) {
|
||||
} else {
|
||||
}
|
||||
if (revents &
|
||||
(POLLHUP | POLLNVAL)) // EC20 bug, Can get POLLERR
|
||||
goto __QmiWwanThread_quit;
|
||||
}
|
||||
|
||||
if ((revents & POLLIN) == 0)
|
||||
continue;
|
||||
|
||||
if (fd == qmidevice_control_fd[1]) {
|
||||
int triger_event;
|
||||
if (read(fd, &triger_event, sizeof(triger_event)) ==
|
||||
sizeof(triger_event)) {
|
||||
// DBG("triger_event = 0x%x", triger_event);
|
||||
switch (triger_event) {
|
||||
case RIL_REQUEST_QUIT:
|
||||
goto __QmiWwanThread_quit;
|
||||
break;
|
||||
case SIGTERM:
|
||||
case SIGHUP:
|
||||
case SIGINT:
|
||||
QmiThreadRecvQMI(NULL);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fd == cdc_wdm_fd) {
|
||||
ssize_t nreads;
|
||||
UCHAR QMIBuf[4096];
|
||||
PQCQMIMSG pResponse = (PQCQMIMSG)QMIBuf;
|
||||
|
||||
if (profile->qmap_mode == 0 || profile->qmap_mode == 1)
|
||||
nreads = read(fd, QMIBuf, sizeof(QMIBuf));
|
||||
else
|
||||
nreads = qmi_proxy_read(fd, QMIBuf, sizeof(QMIBuf));
|
||||
// dbg_time("%s read=%d errno: %d (%s)", __func__, (int)nreads,
|
||||
// errno, strerror(errno));
|
||||
if (nreads <= 0) {
|
||||
dbg_time("%s read=%d errno: %d (%s)", __func__, (int)nreads,
|
||||
errno, strerror(errno));
|
||||
break;
|
||||
}
|
||||
|
||||
if (nreads != (le16_to_cpu(pResponse->QMIHdr.Length) + 1)) {
|
||||
dbg_time("%s nreads=%d, pQCQMI->QMIHdr.Length = %d",
|
||||
__func__, (int)nreads,
|
||||
le16_to_cpu(pResponse->QMIHdr.Length));
|
||||
continue;
|
||||
}
|
||||
|
||||
QmiThreadRecvQMI(pResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__QmiWwanThread_quit:
|
||||
if (cdc_wdm_fd != -1) {
|
||||
close(cdc_wdm_fd);
|
||||
cdc_wdm_fd = -1;
|
||||
}
|
||||
qmidevice_send_event_to_main(RIL_INDICATE_DEVICE_DISCONNECTED);
|
||||
QmiThreadRecvQMI(NULL); // main thread may pending on QmiThreadSendQMI()
|
||||
dbg_time("%s exit", __func__);
|
||||
pthread_exit(NULL);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
const struct qmi_device_ops qmiwwan_qmidev_ops = {
|
||||
.init = QmiWwanInit,
|
||||
.deinit = QmiWwanDeInit,
|
||||
.send = QmiWwanSendQMI,
|
||||
.read = QmiWwanThread,
|
||||
};
|
||||
Executable
+63
@@ -0,0 +1,63 @@
|
||||
#!/bin/sh
|
||||
# Busybox udhcpc dispatcher script. Copyright (C) 2009 by Axel Beckert.
|
||||
#
|
||||
# Based on the busybox example scripts and the old udhcp source
|
||||
# package default.* scripts.
|
||||
|
||||
RESOLV_CONF="/etc/resolv.conf"
|
||||
|
||||
case $1 in
|
||||
bound|renew)
|
||||
[ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
|
||||
[ -n "$subnet" ] && NETMASK="netmask $subnet"
|
||||
|
||||
/sbin/ifconfig $interface $ip $BROADCAST $NETMASK
|
||||
|
||||
if [ -n "$router" ]; then
|
||||
echo "$0: Resetting default routes"
|
||||
while /sbin/route del default gw 0.0.0.0 dev $interface; do :; done
|
||||
|
||||
metric=0
|
||||
for i in $router; do
|
||||
/sbin/route add default gw $i dev $interface metric $metric
|
||||
metric=$(($metric + 1))
|
||||
done
|
||||
fi
|
||||
|
||||
# Update resolver configuration file
|
||||
R=""
|
||||
[ -n "$domain" ] && R="domain $domain
|
||||
"
|
||||
for i in $dns; do
|
||||
echo "$0: Adding DNS $i"
|
||||
R="${R}nameserver $i
|
||||
"
|
||||
done
|
||||
|
||||
if [ -x /sbin/resolvconf ]; then
|
||||
echo -n "$R" | resolvconf -a "${interface}.udhcpc"
|
||||
else
|
||||
echo -n "$R" > "$RESOLV_CONF"
|
||||
fi
|
||||
;;
|
||||
|
||||
deconfig)
|
||||
if [ -x /sbin/resolvconf ]; then
|
||||
resolvconf -d "${interface}.udhcpc"
|
||||
fi
|
||||
/sbin/ifconfig $interface 0.0.0.0
|
||||
;;
|
||||
|
||||
leasefail)
|
||||
echo "$0: Lease failed: $message"
|
||||
;;
|
||||
|
||||
nak)
|
||||
echo "$0: Received a NAK: $message"
|
||||
;;
|
||||
|
||||
*)
|
||||
echo "$0: Unknown udhcpc command: $1";
|
||||
exit 1;
|
||||
;;
|
||||
esac
|
||||
Executable
+1331
File diff suppressed because it is too large.
Load diff
Executable
+28
@@ -0,0 +1,28 @@
|
||||
= What is libmnl? =
|
||||
|
||||
libmnl is a minimalistic user-space library oriented to Netlink developers.
|
||||
There are a lot of common tasks in parsing, validating, constructing of
|
||||
both the Netlink header and TLVs that are repetitive and easy to get wrong.
|
||||
This library aims to provide simple helpers that allows you to re-use code
|
||||
and to avoid re-inventing the wheel. The main features of this library are:
|
||||
|
||||
* Small: the shared library requires around 30KB for an x86-based computer.
|
||||
* Simple: this library avoids complexity and elaborated abstractions that
|
||||
tend to hide Netlink details.
|
||||
* Easy to use: the library simplifies the work for Netlink-wise developers.
|
||||
It provides functions to make socket handling, message building, validating,
|
||||
parsing and sequence tracking, easier.
|
||||
* Easy to re-use: you can use the library to build your own abstraction layer
|
||||
on top of this library.
|
||||
* Decoupling: the interdependency of the main bricks that compose the library
|
||||
is reduced, i.e. the library provides many helpers, but the programmer is not
|
||||
forced to use them.
|
||||
|
||||
= Example files =
|
||||
|
||||
You can find several example files under examples/ that you can compile by
|
||||
invoking `make check'.
|
||||
|
||||
--
|
||||
08/sep/2010
|
||||
Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
Executable
+722
@@ -0,0 +1,722 @@
|
||||
/*
|
||||
* (C) 2008-2012 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
#include <limits.h> /* for INT_MAX */
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "libmnl.h"
|
||||
|
||||
/**
|
||||
* \defgroup attr Netlink attribute helpers
|
||||
*
|
||||
* Netlink Type-Length-Value (TLV) attribute:
|
||||
* \verbatim
|
||||
|<-- 2 bytes -->|<-- 2 bytes -->|<-- variable -->|
|
||||
-------------------------------------------------
|
||||
| length | type | value |
|
||||
-------------------------------------------------
|
||||
|<--------- header ------------>|<-- payload --->|
|
||||
\endverbatim
|
||||
* The payload of the Netlink message contains sequences of attributes that are
|
||||
* expressed in TLV format.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_attr_get_type - get type of netlink attribute
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute type.
|
||||
*/
|
||||
uint16_t mnl_attr_get_type(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_type & NLA_TYPE_MASK;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_len - get length of netlink attribute
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute length that is the attribute header
|
||||
* plus the attribute payload.
|
||||
*/
|
||||
uint16_t mnl_attr_get_len(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_len;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_payload_len - get the attribute payload-value length
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the attribute payload-value length.
|
||||
*/
|
||||
uint16_t mnl_attr_get_payload_len(const struct nlattr *attr)
|
||||
{
|
||||
return attr->nla_len - MNL_ATTR_HDRLEN;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_payload - get pointer to the attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function return a pointer to the attribute payload.
|
||||
*/
|
||||
void *mnl_attr_get_payload(const struct nlattr *attr)
|
||||
{
|
||||
return (void *)attr + MNL_ATTR_HDRLEN;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_ok - check if there is room for an attribute in a buffer
|
||||
* \param attr attribute that we want to check if there is room for
|
||||
* \param len remaining bytes in a buffer that contains the attribute
|
||||
*
|
||||
* This function is used to check that a buffer, which is supposed to contain
|
||||
* an attribute, has enough room for the attribute that it stores, i.e. this
|
||||
* function can be used to verify that an attribute is neither malformed nor
|
||||
* truncated.
|
||||
*
|
||||
* This function does not set errno in case of error since it is intended
|
||||
* for iterations. Thus, it returns true on success and false on error.
|
||||
*
|
||||
* The len parameter may be negative in the case of malformed messages during
|
||||
* attribute iteration, that is why we use a signed integer.
|
||||
*/
|
||||
bool mnl_attr_ok(const struct nlattr *attr, int len)
|
||||
{
|
||||
return len >= (int)sizeof(struct nlattr) &&
|
||||
attr->nla_len >= sizeof(struct nlattr) &&
|
||||
(int)attr->nla_len <= len;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_next - get the next attribute in the payload of a netlink message
|
||||
* \param attr pointer to the current attribute
|
||||
*
|
||||
* This function returns a pointer to the next attribute after the one passed
|
||||
* as parameter. You have to use mnl_attr_ok() to ensure that the next
|
||||
* attribute is valid.
|
||||
*/
|
||||
struct nlattr *mnl_attr_next(const struct nlattr *attr)
|
||||
{
|
||||
return (struct nlattr *)((void *)attr + MNL_ALIGN(attr->nla_len));
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_type_valid - check if the attribute type is valid
|
||||
* \param attr pointer to attribute to be checked
|
||||
* \param max maximum attribute type
|
||||
*
|
||||
* This function allows to check if the attribute type is higher than the
|
||||
* maximum supported type. If the attribute type is invalid, this function
|
||||
* returns -1 and errno is explicitly set. On success, this function returns 1.
|
||||
*
|
||||
* Strict attribute checking in user-space is not a good idea since you may
|
||||
* run an old application with a newer kernel that supports new attributes.
|
||||
* This leads to backward compatibility breakages in user-space. Better check
|
||||
* if you support an attribute, if not, skip it.
|
||||
*/
|
||||
int mnl_attr_type_valid(const struct nlattr *attr, uint16_t max)
|
||||
{
|
||||
if (mnl_attr_get_type(attr) > max) {
|
||||
errno = EOPNOTSUPP;
|
||||
return -1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int __mnl_attr_validate(const struct nlattr *attr,
|
||||
enum mnl_attr_data_type type, size_t exp_len)
|
||||
{
|
||||
uint16_t attr_len = mnl_attr_get_payload_len(attr);
|
||||
const char *attr_data = mnl_attr_get_payload(attr);
|
||||
|
||||
if (attr_len < exp_len) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
switch(type) {
|
||||
case MNL_TYPE_FLAG:
|
||||
if (attr_len > 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_NUL_STRING:
|
||||
if (attr_len == 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
if (attr_data[attr_len-1] != '\0') {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_STRING:
|
||||
if (attr_len == 0) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case MNL_TYPE_NESTED:
|
||||
/* empty nested attributes are OK. */
|
||||
if (attr_len == 0)
|
||||
break;
|
||||
/* if not empty, they must contain one header, eg. flag */
|
||||
if (attr_len < MNL_ATTR_HDRLEN) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
/* make gcc happy. */
|
||||
break;
|
||||
}
|
||||
if (exp_len && attr_len > exp_len) {
|
||||
errno = ERANGE;
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const size_t mnl_attr_data_type_len[MNL_TYPE_MAX] = {
|
||||
[MNL_TYPE_U8] = sizeof(uint8_t),
|
||||
[MNL_TYPE_U16] = sizeof(uint16_t),
|
||||
[MNL_TYPE_U32] = sizeof(uint32_t),
|
||||
[MNL_TYPE_U64] = sizeof(uint64_t),
|
||||
[MNL_TYPE_MSECS] = sizeof(uint64_t),
|
||||
};
|
||||
|
||||
/**
|
||||
* mnl_attr_validate - validate netlink attribute (simplified version)
|
||||
* \param attr pointer to netlink attribute that we want to validate
|
||||
* \param type data type (see enum mnl_attr_data_type)
|
||||
*
|
||||
* The validation is based on the data type. Specifically, it checks that
|
||||
* integers (u8, u16, u32 and u64) have enough room for them. This function
|
||||
* returns -1 in case of error, and errno is explicitly set.
|
||||
*/
|
||||
int mnl_attr_validate(const struct nlattr *attr, enum mnl_attr_data_type type)
|
||||
{
|
||||
int exp_len;
|
||||
|
||||
if (type >= MNL_TYPE_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
exp_len = mnl_attr_data_type_len[type];
|
||||
return __mnl_attr_validate(attr, type, exp_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_validate2 - validate netlink attribute (extended version)
|
||||
* \param attr pointer to netlink attribute that we want to validate
|
||||
* \param type attribute type (see enum mnl_attr_data_type)
|
||||
* \param exp_len expected attribute data size
|
||||
*
|
||||
* This function allows to perform a more accurate validation for attributes
|
||||
* whose size is variable. If the size of the attribute is not what we expect,
|
||||
* this functions returns -1 and errno is explicitly set.
|
||||
*/
|
||||
int mnl_attr_validate2(const struct nlattr *attr,
|
||||
enum mnl_attr_data_type type,
|
||||
size_t exp_len)
|
||||
{
|
||||
if (type >= MNL_TYPE_MAX) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
return __mnl_attr_validate(attr, type, exp_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_parse - parse attributes
|
||||
* \param nlh pointer to netlink message
|
||||
* \param offset offset to start parsing from (if payload is after any header)
|
||||
* \param cb callback function that is called for each attribute
|
||||
* \param data pointer to data that is passed to the callback function
|
||||
*
|
||||
* This function allows to iterate over the sequence of attributes that compose
|
||||
* the Netlink message. You can then put the attribute in an array as it
|
||||
* usually happens at this stage or you can use any other data structure (such
|
||||
* as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int mnl_attr_parse(const struct nlmsghdr *nlh,
|
||||
unsigned int offset, mnl_attr_cb_t cb,
|
||||
void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each(attr, nlh, offset)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_parse_nested - parse attributes inside a nest
|
||||
* \param nested pointer to netlink attribute that contains a nest
|
||||
* \param cb callback function that is called for each attribute in the nest
|
||||
* \param data pointer to data passed to the callback function
|
||||
*
|
||||
* This function allows to iterate over the sequence of attributes that compose
|
||||
* the Netlink message. You can then put the attribute in an array as it
|
||||
* usually happens at this stage or you can use any other data structure (such
|
||||
* as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int mnl_attr_parse_nested(const struct nlattr *nested,
|
||||
mnl_attr_cb_t cb, void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each_nested(attr, nested)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_parse_payload - parse attributes in payload of Netlink message
|
||||
* \param payload pointer to payload of the Netlink message
|
||||
* \param payload_len payload length that contains the attributes
|
||||
* \param cb callback function that is called for each attribute
|
||||
* \param data pointer to data that is passed to the callback function
|
||||
*
|
||||
* This function takes a pointer to the area that contains the attributes,
|
||||
* commonly known as the payload of the Netlink message. Thus, you have to
|
||||
* pass a pointer to the Netlink message payload, instead of the entire
|
||||
* message.
|
||||
*
|
||||
* This function allows you to iterate over the sequence of attributes that are
|
||||
* located at some payload offset. You can then put the attributes in one array
|
||||
* as usual, or you can use any other data structure (such as lists or trees).
|
||||
*
|
||||
* This function propagates the return value of the callback, which can be
|
||||
* MNL_CB_ERROR, MNL_CB_OK or MNL_CB_STOP.
|
||||
*/
|
||||
int mnl_attr_parse_payload(const void *payload,
|
||||
size_t payload_len,
|
||||
mnl_attr_cb_t cb, void *data)
|
||||
{
|
||||
int ret = MNL_CB_OK;
|
||||
const struct nlattr *attr;
|
||||
|
||||
mnl_attr_for_each_payload(payload, payload_len)
|
||||
if ((ret = cb(attr, data)) <= MNL_CB_STOP)
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u8 - returns 8-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 8-bit value of the attribute payload.
|
||||
*/
|
||||
uint8_t mnl_attr_get_u8(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint8_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u16 - returns 16-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 16-bit value of the attribute payload.
|
||||
*/
|
||||
uint16_t mnl_attr_get_u16(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint16_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u32 - returns 32-bit unsigned integer attribute payload
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 32-bit value of the attribute payload.
|
||||
*/
|
||||
uint32_t mnl_attr_get_u32(const struct nlattr *attr)
|
||||
{
|
||||
return *((uint32_t *)mnl_attr_get_payload(attr));
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_u64 - returns 64-bit unsigned integer attribute.
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the 64-bit value of the attribute payload. This
|
||||
* function is align-safe, since accessing 64-bit Netlink attributes is a
|
||||
* common source of alignment issues.
|
||||
*/
|
||||
uint64_t mnl_attr_get_u64(const struct nlattr *attr)
|
||||
{
|
||||
uint64_t tmp;
|
||||
memcpy(&tmp, mnl_attr_get_payload(attr), sizeof(tmp));
|
||||
return tmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_get_str - returns pointer to string attribute.
|
||||
* \param attr pointer to netlink attribute
|
||||
*
|
||||
* This function returns the payload of string attribute value.
|
||||
*/
|
||||
const char *mnl_attr_get_str(const struct nlattr *attr)
|
||||
{
|
||||
return mnl_attr_get_payload(attr);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put - add an attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type that you want to add
|
||||
* \param len netlink attribute payload length
|
||||
* \param data pointer to the data that will be stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put(struct nlmsghdr *nlh, uint16_t type,
|
||||
size_t len, const void *data)
|
||||
{
|
||||
struct nlattr *attr = mnl_nlmsg_get_payload_tail(nlh);
|
||||
uint16_t payload_len = MNL_ALIGN(sizeof(struct nlattr)) + len;
|
||||
int pad;
|
||||
|
||||
attr->nla_type = type;
|
||||
attr->nla_len = payload_len;
|
||||
memcpy(mnl_attr_get_payload(attr), data, len);
|
||||
pad = MNL_ALIGN(len) - len;
|
||||
if (pad > 0)
|
||||
memset(mnl_attr_get_payload(attr) + len, 0, pad);
|
||||
|
||||
nlh->nlmsg_len += MNL_ALIGN(payload_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u8 - add 8-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 8-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u8(struct nlmsghdr *nlh, uint16_t type,
|
||||
uint8_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint8_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u16 - add 16-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 16-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u16(struct nlmsghdr *nlh, uint16_t type,
|
||||
uint16_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint16_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u32 - add 32-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 32-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u32(struct nlmsghdr *nlh, uint16_t type,
|
||||
uint32_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint32_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u64 - add 64-bit unsigned integer attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data 64-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_u64(struct nlmsghdr *nlh, uint16_t type,
|
||||
uint64_t data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, sizeof(uint64_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_str - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_str(struct nlmsghdr *nlh, uint16_t type,
|
||||
const char *data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, strlen(data), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_strz - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function is similar to mnl_attr_put_str, but it includes the
|
||||
* NUL/zero ('\0') terminator at the end of the string.
|
||||
*
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
void mnl_attr_put_strz(struct nlmsghdr *nlh, uint16_t type,
|
||||
const char *data)
|
||||
{
|
||||
mnl_attr_put(nlh, type, strlen(data)+1, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_start - start an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
*
|
||||
* This function adds the attribute header that identifies the beginning of
|
||||
* an attribute nest. This function always returns a valid pointer to the
|
||||
* beginning of the nest.
|
||||
*/
|
||||
struct nlattr *mnl_attr_nest_start(struct nlmsghdr *nlh,
|
||||
uint16_t type)
|
||||
{
|
||||
struct nlattr *start = mnl_nlmsg_get_payload_tail(nlh);
|
||||
|
||||
/* set start->nla_len in mnl_attr_nest_end() */
|
||||
start->nla_type = NLA_F_NESTED | type;
|
||||
nlh->nlmsg_len += MNL_ALIGN(sizeof(struct nlattr));
|
||||
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_check - add an attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type that you want to add
|
||||
* \param len netlink attribute payload length
|
||||
* \param data pointer to the data that will be stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool mnl_attr_put_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, size_t len,
|
||||
const void *data)
|
||||
{
|
||||
if (nlh->nlmsg_len + MNL_ATTR_HDRLEN + MNL_ALIGN(len) > buflen)
|
||||
return false;
|
||||
mnl_attr_put(nlh, type, len, data);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u8_check - add 8-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 8-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool mnl_attr_put_u8_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint8_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint8_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u16_check - add 16-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 16-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool mnl_attr_put_u16_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint16_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint16_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u32_check - add 32-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 32-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool mnl_attr_put_u32_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint32_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint32_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_u64_check - add 64-bit unsigned int attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data 64-bit unsigned integer data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool mnl_attr_put_u64_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, uint64_t data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, sizeof(uint64_t), &data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_str_check - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
* This function updates the length field of the Netlink message (nlmsg_len)
|
||||
* by adding the size (header + payload) of the new attribute.
|
||||
*/
|
||||
bool mnl_attr_put_str_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, const char *data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, strlen(data), data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_put_strz_check - add string attribute to netlink message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param type netlink attribute type
|
||||
* \param data pointer to string data that is stored by the new attribute
|
||||
*
|
||||
* This function is similar to mnl_attr_put_str, but it includes the
|
||||
* NUL/zero ('\0') terminator at the end of the string.
|
||||
*
|
||||
* This function first checks that the data can be added to the message
|
||||
* (fits into the buffer) and then updates the length field of the Netlink
|
||||
* message (nlmsg_len) by adding the size (header + payload) of the new
|
||||
* attribute. The function returns true if the attribute could be added
|
||||
* to the message, otherwise false is returned.
|
||||
*/
|
||||
bool mnl_attr_put_strz_check(struct nlmsghdr *nlh, size_t buflen,
|
||||
uint16_t type, const char *data)
|
||||
{
|
||||
return mnl_attr_put_check(nlh, buflen, type, strlen(data)+1, data);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_start_check - start an attribute nest
|
||||
* \param buflen size of buffer which stores the message
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param type netlink attribute type
|
||||
*
|
||||
* This function adds the attribute header that identifies the beginning of
|
||||
* an attribute nest. If the nested attribute cannot be added then NULL,
|
||||
* otherwise valid pointer to the beginning of the nest is returned.
|
||||
*/
|
||||
struct nlattr *mnl_attr_nest_start_check(struct nlmsghdr *nlh,
|
||||
size_t buflen,
|
||||
uint16_t type)
|
||||
{
|
||||
if (nlh->nlmsg_len + MNL_ATTR_HDRLEN > buflen)
|
||||
return NULL;
|
||||
return mnl_attr_nest_start(nlh, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_end - end an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param start pointer to the attribute nest returned by mnl_attr_nest_start()
|
||||
*
|
||||
* This function updates the attribute header that identifies the nest.
|
||||
*/
|
||||
void mnl_attr_nest_end(struct nlmsghdr *nlh,
|
||||
struct nlattr *start)
|
||||
{
|
||||
start->nla_len = mnl_nlmsg_get_payload_tail(nlh) - (void *)start;
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_attr_nest_cancel - cancel an attribute nest
|
||||
* \param nlh pointer to the netlink message
|
||||
* \param start pointer to the attribute nest returned by mnl_attr_nest_start()
|
||||
*
|
||||
* This function updates the attribute header that identifies the nest.
|
||||
*/
|
||||
void mnl_attr_nest_cancel(struct nlmsghdr *nlh,
|
||||
struct nlattr *start)
|
||||
{
|
||||
nlh->nlmsg_len -= mnl_nlmsg_get_payload_tail(nlh) - (void *)start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
Executable
+167
@@ -0,0 +1,167 @@
|
||||
/*
|
||||
* (C) 2008-2010 by Pablo Neira Ayuso <pablo@netfilter.org>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published
|
||||
* by the Free Software Foundation; either version 2.1 of the License, or
|
||||
* (at your option) any later version.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "libmnl.h"
|
||||
|
||||
static int mnl_cb_noop(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
static int mnl_cb_error(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
const struct nlmsgerr *err = mnl_nlmsg_get_payload(nlh);
|
||||
|
||||
if (nlh->nlmsg_len < mnl_nlmsg_size(sizeof(struct nlmsgerr))) {
|
||||
errno = EBADMSG;
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
/* Netlink subsystems returns the errno value with different signess */
|
||||
if (err->error < 0)
|
||||
errno = -err->error;
|
||||
else
|
||||
errno = err->error;
|
||||
|
||||
return err->error == 0 ? MNL_CB_STOP : MNL_CB_ERROR;
|
||||
}
|
||||
|
||||
static int mnl_cb_stop(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
return MNL_CB_STOP;
|
||||
}
|
||||
|
||||
static const mnl_cb_t default_cb_array[NLMSG_MIN_TYPE] = {
|
||||
[NLMSG_NOOP] = mnl_cb_noop,
|
||||
[NLMSG_ERROR] = mnl_cb_error,
|
||||
[NLMSG_DONE] = mnl_cb_stop,
|
||||
[NLMSG_OVERRUN] = mnl_cb_noop,
|
||||
};
|
||||
|
||||
static inline int __mnl_cb_run(const void *buf, size_t numbytes,
|
||||
unsigned int seq, unsigned int portid,
|
||||
mnl_cb_t cb_data, void *data,
|
||||
const mnl_cb_t *cb_ctl_array,
|
||||
unsigned int cb_ctl_array_len)
|
||||
{
|
||||
int ret = MNL_CB_OK, len = numbytes;
|
||||
const struct nlmsghdr *nlh = buf;
|
||||
|
||||
while (mnl_nlmsg_ok(nlh, len)) {
|
||||
/* check message source */
|
||||
if (!mnl_nlmsg_portid_ok(nlh, portid)) {
|
||||
errno = ESRCH;
|
||||
return -1;
|
||||
}
|
||||
/* perform sequence tracking */
|
||||
if (!mnl_nlmsg_seq_ok(nlh, seq)) {
|
||||
errno = EPROTO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* dump was interrupted */
|
||||
if (nlh->nlmsg_flags & NLM_F_DUMP_INTR) {
|
||||
errno = EINTR;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* netlink data message handling */
|
||||
if (nlh->nlmsg_type >= NLMSG_MIN_TYPE) {
|
||||
if (cb_data){
|
||||
ret = cb_data(nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
} else if (nlh->nlmsg_type < cb_ctl_array_len) {
|
||||
if (cb_ctl_array && cb_ctl_array[nlh->nlmsg_type]) {
|
||||
ret = cb_ctl_array[nlh->nlmsg_type](nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
} else if (default_cb_array[nlh->nlmsg_type]) {
|
||||
ret = default_cb_array[nlh->nlmsg_type](nlh, data);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
goto out;
|
||||
}
|
||||
nlh = mnl_nlmsg_next(nlh, &len);
|
||||
}
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* \defgroup callback Callback helpers
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* mnl_cb_run2 - callback runqueue for netlink messages
|
||||
* \param buf buffer that contains the netlink messages
|
||||
* \param numbytes number of bytes stored in the buffer
|
||||
* \param seq sequence number that we expect to receive
|
||||
* \param portid Netlink PortID that we expect to receive
|
||||
* \param cb_data callback handler for data messages
|
||||
* \param data pointer to data that will be passed to the data callback handler
|
||||
* \param cb_ctl_array array of custom callback handlers from control messages
|
||||
* \param cb_ctl_array_len array length of custom control callback handlers
|
||||
*
|
||||
* You can set the cb_ctl_array to NULL if you want to use the default control
|
||||
* callback handlers, in that case, the parameter cb_ctl_array_len is not
|
||||
* checked.
|
||||
*
|
||||
* Your callback may return three possible values:
|
||||
* - MNL_CB_ERROR (<=-1): an error has occurred. Stop callback runqueue.
|
||||
* - MNL_CB_STOP (=0): stop callback runqueue.
|
||||
* - MNL_CB_OK (>=1): no problem has occurred.
|
||||
*
|
||||
* This function propagates the callback return value. On error, it returns
|
||||
* -1 and errno is explicitly set. If the portID is not the expected, errno
|
||||
* is set to ESRCH. If the sequence number is not the expected, errno is set
|
||||
* to EPROTO. If the dump was interrupted, errno is set to EINTR and you should
|
||||
* request a new fresh dump again.
|
||||
*/
|
||||
int mnl_cb_run2(const void *buf, size_t numbytes,
|
||||
unsigned int seq, unsigned int portid,
|
||||
mnl_cb_t cb_data, void *data,
|
||||
const mnl_cb_t *cb_ctl_array,
|
||||
unsigned int cb_ctl_array_len)
|
||||
{
|
||||
return __mnl_cb_run(buf, numbytes, seq, portid, cb_data, data,
|
||||
cb_ctl_array, cb_ctl_array_len);
|
||||
}
|
||||
|
||||
/**
|
||||
* mnl_cb_run - callback runqueue for netlink messages (simplified version)
|
||||
* \param buf buffer that contains the netlink messages
|
||||
* \param numbytes number of bytes stored in the buffer
|
||||
* \param seq sequence number that we expect to receive
|
||||
* \param portid Netlink PortID that we expect to receive
|
||||
* \param cb_data callback handler for data messages
|
||||
* \param data pointer to data that will be passed to the data callback handler
|
||||
*
|
||||
* This function is like mnl_cb_run2() but it does not allow you to set
|
||||
* the control callback handlers.
|
||||
*
|
||||
* Your callback may return three possible values:
|
||||
* - MNL_CB_ERROR (<=-1): an error has occurred. Stop callback runqueue.
|
||||
* - MNL_CB_STOP (=0): stop callback runqueue.
|
||||
* - MNL_CB_OK (>=1): no problems has occurred.
|
||||
*
|
||||
* This function propagates the callback return value.
|
||||
*/
|
||||
int mnl_cb_run(const void *buf, size_t numbytes, unsigned int seq,
|
||||
unsigned int portid, mnl_cb_t cb_data, void *data)
|
||||
{
|
||||
return __mnl_cb_run(buf, numbytes, seq, portid, cb_data, data, NULL, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
Executable
+5
@@ -0,0 +1,5 @@
|
||||
#ifndef __DHCP_H__
|
||||
#define __DHCP_H__
|
||||
|
||||
int do_dhcp(char *iname);
|
||||
#endif //__DHCP_H__
|
||||
Executable
+515
@@ -0,0 +1,515 @@
|
||||
/*
|
||||
* Copyright 2008, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <net/if.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include "../ifutils.h"
|
||||
#include "dhcpmsg.h"
|
||||
#include "packet.h"
|
||||
|
||||
#define VERBOSE 2
|
||||
|
||||
static int verbose = 1;
|
||||
static char errmsg[2048];
|
||||
|
||||
typedef unsigned long long msecs_t;
|
||||
#if VERBOSE
|
||||
void dump_dhcp_msg();
|
||||
#endif
|
||||
|
||||
msecs_t get_msecs(void)
|
||||
{
|
||||
struct timespec ts;
|
||||
|
||||
if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
|
||||
return 0;
|
||||
} else {
|
||||
return (((msecs_t) ts.tv_sec) * ((msecs_t) 1000)) +
|
||||
(((msecs_t) ts.tv_nsec) / ((msecs_t) 1000000));
|
||||
}
|
||||
}
|
||||
|
||||
void printerr(char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vsnprintf(errmsg, sizeof(errmsg), fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
printf("%s\n", errmsg);
|
||||
}
|
||||
|
||||
const char *dhcp_lasterror()
|
||||
{
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
int fatal(const char *reason)
|
||||
{
|
||||
printerr("%s: %s\n", reason, strerror(errno));
|
||||
return -1;
|
||||
// exit(1);
|
||||
}
|
||||
|
||||
typedef struct dhcp_info dhcp_info;
|
||||
|
||||
struct dhcp_info {
|
||||
uint32_t type;
|
||||
|
||||
uint32_t ipaddr;
|
||||
uint32_t gateway;
|
||||
uint32_t prefixLength;
|
||||
|
||||
uint32_t dns1;
|
||||
uint32_t dns2;
|
||||
|
||||
uint32_t serveraddr;
|
||||
uint32_t lease;
|
||||
};
|
||||
|
||||
dhcp_info last_good_info;
|
||||
|
||||
void get_dhcp_info(uint32_t *ipaddr, uint32_t *gateway, uint32_t *prefixLength,
|
||||
uint32_t *dns1, uint32_t *dns2, uint32_t *server,
|
||||
uint32_t *lease)
|
||||
{
|
||||
*ipaddr = last_good_info.ipaddr;
|
||||
*gateway = last_good_info.gateway;
|
||||
*prefixLength = last_good_info.prefixLength;
|
||||
*dns1 = last_good_info.dns1;
|
||||
*dns2 = last_good_info.dns2;
|
||||
*server = last_good_info.serveraddr;
|
||||
*lease = last_good_info.lease;
|
||||
}
|
||||
|
||||
static int dhcp_configure(const char *ifname, dhcp_info *info)
|
||||
{
|
||||
last_good_info = *info;
|
||||
return if_set_network_v4(ifname, info->ipaddr, info->prefixLength, info->gateway,
|
||||
info->dns1, info->dns2);
|
||||
}
|
||||
|
||||
static const char *dhcp_type_to_name(uint32_t type)
|
||||
{
|
||||
switch(type) {
|
||||
case DHCPDISCOVER: return "discover";
|
||||
case DHCPOFFER: return "offer";
|
||||
case DHCPREQUEST: return "request";
|
||||
case DHCPDECLINE: return "decline";
|
||||
case DHCPACK: return "ack";
|
||||
case DHCPNAK: return "nak";
|
||||
case DHCPRELEASE: return "release";
|
||||
case DHCPINFORM: return "inform";
|
||||
default: return "???";
|
||||
}
|
||||
}
|
||||
|
||||
void dump_dhcp_info(dhcp_info *info)
|
||||
{
|
||||
char addr[20], gway[20];
|
||||
printf("--- dhcp %s (%d) ---\n",
|
||||
dhcp_type_to_name(info->type), info->type);
|
||||
strcpy(addr, ipaddr_to_string_v4(info->ipaddr));
|
||||
strcpy(gway, ipaddr_to_string_v4(info->gateway));
|
||||
printf("ip %s gw %s prefixLength %d\n", addr, gway, info->prefixLength);
|
||||
if (info->dns1) printf("dns1: %s\n", ipaddr_to_string_v4(info->dns1));
|
||||
if (info->dns2) printf("dns2: %s\n", ipaddr_to_string_v4(info->dns2));
|
||||
printf("server %s, lease %d seconds\n",
|
||||
ipaddr_to_string_v4(info->serveraddr), info->lease);
|
||||
}
|
||||
|
||||
|
||||
int decode_dhcp_msg(dhcp_msg *msg, int len, dhcp_info *info)
|
||||
{
|
||||
uint8_t *x;
|
||||
unsigned int opt;
|
||||
int optlen;
|
||||
|
||||
memset(info, 0, sizeof(dhcp_info));
|
||||
if (len < (DHCP_MSG_FIXED_SIZE + 4)) return -1;
|
||||
|
||||
len -= (DHCP_MSG_FIXED_SIZE + 4);
|
||||
|
||||
if (msg->options[0] != OPT_COOKIE1) return -1;
|
||||
if (msg->options[1] != OPT_COOKIE2) return -1;
|
||||
if (msg->options[2] != OPT_COOKIE3) return -1;
|
||||
if (msg->options[3] != OPT_COOKIE4) return -1;
|
||||
|
||||
x = msg->options + 4;
|
||||
|
||||
while (len > 2) {
|
||||
opt = *x++;
|
||||
if (opt == OPT_PAD) {
|
||||
len--;
|
||||
continue;
|
||||
}
|
||||
if (opt == OPT_END) {
|
||||
break;
|
||||
}
|
||||
optlen = *x++;
|
||||
len -= 2;
|
||||
if (optlen > len) {
|
||||
break;
|
||||
}
|
||||
switch(opt) {
|
||||
case OPT_SUBNET_MASK:
|
||||
if (optlen >= 4) {
|
||||
in_addr_t mask;
|
||||
memcpy(&mask, x, 4);
|
||||
info->prefixLength = mask_to_prefix_v4(mask);
|
||||
}
|
||||
break;
|
||||
case OPT_GATEWAY:
|
||||
if (optlen >= 4) memcpy(&info->gateway, x, 4);
|
||||
break;
|
||||
case OPT_DNS:
|
||||
if (optlen >= 4) memcpy(&info->dns1, x + 0, 4);
|
||||
if (optlen >= 8) memcpy(&info->dns2, x + 4, 4);
|
||||
break;
|
||||
case OPT_LEASE_TIME:
|
||||
if (optlen >= 4) {
|
||||
memcpy(&info->lease, x, 4);
|
||||
info->lease = ntohl(info->lease);
|
||||
}
|
||||
break;
|
||||
case OPT_SERVER_ID:
|
||||
if (optlen >= 4) memcpy(&info->serveraddr, x, 4);
|
||||
break;
|
||||
case OPT_MESSAGE_TYPE:
|
||||
info->type = *x;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
x += optlen;
|
||||
len -= optlen;
|
||||
}
|
||||
|
||||
info->ipaddr = msg->yiaddr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if VERBOSE
|
||||
|
||||
static void hex2str(char *buf, size_t buf_size, const unsigned char *array, int len)
|
||||
{
|
||||
int i;
|
||||
char *cp = buf;
|
||||
char *buf_end = buf + buf_size;
|
||||
for (i = 0; i < len; i++) {
|
||||
cp += snprintf(cp, buf_end - cp, " %02x ", array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void dump_dhcp_msg(dhcp_msg *msg, int len)
|
||||
{
|
||||
unsigned char *x;
|
||||
unsigned int n,c;
|
||||
int optsz;
|
||||
const char *name;
|
||||
char buf[2048];
|
||||
|
||||
if (len < DHCP_MSG_FIXED_SIZE) {
|
||||
printf("Invalid length %d, should be %d", len, DHCP_MSG_FIXED_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
len -= DHCP_MSG_FIXED_SIZE;
|
||||
|
||||
if (msg->op == OP_BOOTREQUEST)
|
||||
name = "BOOTREQUEST";
|
||||
else if (msg->op == OP_BOOTREPLY)
|
||||
name = "BOOTREPLY";
|
||||
else
|
||||
name = "????";
|
||||
|
||||
c = msg->hlen > 16 ? 16 : msg->hlen;
|
||||
hex2str(buf, sizeof(buf), msg->chaddr, c);
|
||||
|
||||
for (n = 0; n < 64; n++) {
|
||||
unsigned char x = msg->sname[n];
|
||||
if ((x < ' ') || (x > 127)) {
|
||||
if (x == 0) break;
|
||||
msg->sname[n] = '.';
|
||||
}
|
||||
}
|
||||
msg->sname[63] = 0;
|
||||
|
||||
for (n = 0; n < 128; n++) {
|
||||
unsigned char x = msg->file[n];
|
||||
if ((x < ' ') || (x > 127)) {
|
||||
if (x == 0) break;
|
||||
msg->file[n] = '.';
|
||||
}
|
||||
}
|
||||
msg->file[127] = 0;
|
||||
|
||||
if (len < 4) return;
|
||||
len -= 4;
|
||||
x = msg->options + 4;
|
||||
|
||||
while (len > 2) {
|
||||
if (*x == 0) {
|
||||
x++;
|
||||
len--;
|
||||
continue;
|
||||
}
|
||||
if (*x == OPT_END) {
|
||||
break;
|
||||
}
|
||||
len -= 2;
|
||||
optsz = x[1];
|
||||
if (optsz > len) break;
|
||||
if (x[0] == OPT_DOMAIN_NAME || x[0] == OPT_MESSAGE) {
|
||||
if ((unsigned int)optsz < sizeof(buf) - 1) {
|
||||
n = optsz;
|
||||
} else {
|
||||
n = sizeof(buf) - 1;
|
||||
}
|
||||
memcpy(buf, &x[2], n);
|
||||
buf[n] = '\0';
|
||||
} else {
|
||||
hex2str(buf, sizeof(buf), &x[2], optsz);
|
||||
}
|
||||
if (x[0] == OPT_MESSAGE_TYPE)
|
||||
name = dhcp_type_to_name(x[2]);
|
||||
else
|
||||
name = NULL;
|
||||
len -= optsz;
|
||||
x = x + optsz + 2;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
static int send_message(int sock, int if_index, dhcp_msg *msg, int size)
|
||||
{
|
||||
#if VERBOSE > 1
|
||||
dump_dhcp_msg(msg, size);
|
||||
#endif
|
||||
return send_packet(sock, if_index, msg, size, INADDR_ANY, INADDR_BROADCAST,
|
||||
PORT_BOOTP_CLIENT, PORT_BOOTP_SERVER);
|
||||
}
|
||||
|
||||
static int is_valid_reply(dhcp_msg *msg, dhcp_msg *reply, int sz)
|
||||
{
|
||||
if (sz < DHCP_MSG_FIXED_SIZE) {
|
||||
if (verbose) printf("Wrong size %d != %d\n", sz, DHCP_MSG_FIXED_SIZE);
|
||||
return 0;
|
||||
}
|
||||
if (reply->op != OP_BOOTREPLY) {
|
||||
if (verbose) printf("Wrong Op %d != %d\n", reply->op, OP_BOOTREPLY);
|
||||
return 0;
|
||||
}
|
||||
if (reply->xid != msg->xid) {
|
||||
if (verbose) printf("Wrong Xid 0x%x != 0x%x\n", ntohl(reply->xid),
|
||||
ntohl(msg->xid));
|
||||
return 0;
|
||||
}
|
||||
if (reply->htype != msg->htype) {
|
||||
if (verbose) printf("Wrong Htype %d != %d\n", reply->htype, msg->htype);
|
||||
return 0;
|
||||
}
|
||||
if (reply->hlen != msg->hlen) {
|
||||
if (verbose) printf("Wrong Hlen %d != %d\n", reply->hlen, msg->hlen);
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(msg->chaddr, reply->chaddr, msg->hlen)) {
|
||||
if (verbose) printf("Wrong chaddr %x != %x\n", *(reply->chaddr),*(msg->chaddr));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define STATE_SELECTING 1
|
||||
#define STATE_REQUESTING 2
|
||||
|
||||
#define TIMEOUT_INITIAL 4000
|
||||
#define TIMEOUT_MAX 32000
|
||||
|
||||
int dhcp_init_ifc(const char *ifname)
|
||||
{
|
||||
dhcp_msg discover_msg;
|
||||
dhcp_msg request_msg;
|
||||
dhcp_msg reply;
|
||||
dhcp_msg *msg;
|
||||
dhcp_info info;
|
||||
int s, r, size;
|
||||
int valid_reply;
|
||||
uint32_t xid;
|
||||
unsigned char hwaddr[6];
|
||||
struct pollfd pfd;
|
||||
unsigned int state;
|
||||
unsigned int timeout;
|
||||
int if_index;
|
||||
|
||||
xid = (uint32_t) get_msecs();
|
||||
|
||||
if (if_get_hwaddr(ifname, hwaddr)) {
|
||||
return fatal("cannot obtain interface address");
|
||||
}
|
||||
if ((if_index = if_nametoindex(ifname)) == 0) {
|
||||
return fatal("cannot obtain interface index");
|
||||
}
|
||||
|
||||
s = open_raw_socket(ifname, hwaddr, if_index);
|
||||
|
||||
timeout = TIMEOUT_INITIAL;
|
||||
state = STATE_SELECTING;
|
||||
info.type = 0;
|
||||
goto transmit;
|
||||
|
||||
for (;;) {
|
||||
pfd.fd = s;
|
||||
pfd.events = POLLIN;
|
||||
pfd.revents = 0;
|
||||
r = poll(&pfd, 1, timeout);
|
||||
|
||||
if (r == 0) {
|
||||
#if VERBOSE
|
||||
printerr("TIMEOUT\n");
|
||||
#endif
|
||||
if (timeout >= TIMEOUT_MAX) {
|
||||
printerr("timed out\n");
|
||||
if ( info.type == DHCPOFFER ) {
|
||||
printerr("no acknowledgement from DHCP server\nconfiguring %s with offered parameters\n", ifname);
|
||||
return dhcp_configure(ifname, &info);
|
||||
}
|
||||
errno = ETIME;
|
||||
close(s);
|
||||
return -1;
|
||||
}
|
||||
timeout = timeout * 2;
|
||||
|
||||
transmit:
|
||||
size = 0;
|
||||
msg = NULL;
|
||||
switch(state) {
|
||||
case STATE_SELECTING:
|
||||
msg = &discover_msg;
|
||||
size = init_dhcp_discover_msg(msg, hwaddr, xid);
|
||||
break;
|
||||
case STATE_REQUESTING:
|
||||
msg = &request_msg;
|
||||
size = init_dhcp_request_msg(msg, hwaddr, xid, info.ipaddr, info.serveraddr);
|
||||
break;
|
||||
default:
|
||||
r = 0;
|
||||
}
|
||||
if (size != 0) {
|
||||
r = send_message(s, if_index, msg, size);
|
||||
if (r < 0) {
|
||||
printerr("error sending dhcp msg: %s\n", strerror(errno));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (r < 0) {
|
||||
if ((errno == EAGAIN) || (errno == EINTR)) {
|
||||
continue;
|
||||
}
|
||||
return fatal("poll failed");
|
||||
}
|
||||
|
||||
errno = 0;
|
||||
r = receive_packet(s, &reply);
|
||||
if (r < 0) {
|
||||
if (errno != 0) {
|
||||
printf("receive_packet failed (%d): %s", r, strerror(errno));
|
||||
if (errno == ENETDOWN || errno == ENXIO) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
#if VERBOSE > 1
|
||||
dump_dhcp_msg(&reply, r);
|
||||
#endif
|
||||
decode_dhcp_msg(&reply, r, &info);
|
||||
|
||||
if (state == STATE_SELECTING) {
|
||||
valid_reply = is_valid_reply(&discover_msg, &reply, r);
|
||||
} else {
|
||||
valid_reply = is_valid_reply(&request_msg, &reply, r);
|
||||
}
|
||||
if (!valid_reply) {
|
||||
printerr("invalid reply\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (verbose) dump_dhcp_info(&info);
|
||||
|
||||
switch(state) {
|
||||
case STATE_SELECTING:
|
||||
if (info.type == DHCPOFFER) {
|
||||
state = STATE_REQUESTING;
|
||||
timeout = TIMEOUT_INITIAL;
|
||||
xid++;
|
||||
goto transmit;
|
||||
}
|
||||
break;
|
||||
case STATE_REQUESTING:
|
||||
if (info.type == DHCPACK) {
|
||||
printerr("configuring %s\n", ifname);
|
||||
close(s);
|
||||
return dhcp_configure(ifname, &info);
|
||||
} else if (info.type == DHCPNAK) {
|
||||
printerr("configuration request denied\n");
|
||||
close(s);
|
||||
return -1;
|
||||
} else {
|
||||
printerr("ignoring %s message in state %d\n",
|
||||
dhcp_type_to_name(info.type), state);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
close(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int do_dhcp(char *iname)
|
||||
{
|
||||
if (if_set_addr_v4(iname, 0, 32)) {
|
||||
printerr("failed to set ip addr for %s to 0.0.0.0: %s\n", iname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (if_link_up(iname)) {
|
||||
printerr("failed to bring up interface %s: %s\n", iname, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dhcp_init_ifc(iname);
|
||||
}
|
||||
Executable
+100
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright 2008, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include "dhcpmsg.h"
|
||||
|
||||
static void *init_dhcp_msg(dhcp_msg *msg, int type, void *hwaddr, uint32_t xid)
|
||||
{
|
||||
uint8_t *x;
|
||||
|
||||
memset(msg, 0, sizeof(dhcp_msg));
|
||||
|
||||
msg->op = OP_BOOTREQUEST;
|
||||
msg->htype = HTYPE_ETHER;
|
||||
msg->hlen = 6;
|
||||
msg->hops = 0;
|
||||
|
||||
msg->flags = htons(FLAGS_BROADCAST);
|
||||
|
||||
msg->xid = xid;
|
||||
|
||||
memcpy(msg->chaddr, hwaddr, 6);
|
||||
|
||||
x = msg->options;
|
||||
|
||||
*x++ = OPT_COOKIE1;
|
||||
*x++ = OPT_COOKIE2;
|
||||
*x++ = OPT_COOKIE3;
|
||||
*x++ = OPT_COOKIE4;
|
||||
|
||||
*x++ = OPT_MESSAGE_TYPE;
|
||||
*x++ = 1;
|
||||
*x++ = type;
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
int init_dhcp_discover_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid)
|
||||
{
|
||||
uint8_t *x;
|
||||
|
||||
x = init_dhcp_msg(msg, DHCPDISCOVER, hwaddr, xid);
|
||||
|
||||
*x++ = OPT_PARAMETER_LIST;
|
||||
*x++ = 4;
|
||||
*x++ = OPT_SUBNET_MASK;
|
||||
*x++ = OPT_GATEWAY;
|
||||
*x++ = OPT_DNS;
|
||||
*x++ = OPT_BROADCAST_ADDR;
|
||||
|
||||
*x++ = OPT_END;
|
||||
|
||||
return DHCP_MSG_FIXED_SIZE + (x - msg->options);
|
||||
}
|
||||
|
||||
int init_dhcp_request_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid,
|
||||
uint32_t ipaddr, uint32_t serveraddr)
|
||||
{
|
||||
uint8_t *x;
|
||||
|
||||
x = init_dhcp_msg(msg, DHCPREQUEST, hwaddr, xid);
|
||||
|
||||
*x++ = OPT_PARAMETER_LIST;
|
||||
*x++ = 4;
|
||||
*x++ = OPT_SUBNET_MASK;
|
||||
*x++ = OPT_GATEWAY;
|
||||
*x++ = OPT_DNS;
|
||||
*x++ = OPT_BROADCAST_ADDR;
|
||||
|
||||
*x++ = OPT_REQUESTED_IP;
|
||||
*x++ = 4;
|
||||
memcpy(x, &ipaddr, 4);
|
||||
x += 4;
|
||||
|
||||
*x++ = OPT_SERVER_ID;
|
||||
*x++ = 4;
|
||||
memcpy(x, &serveraddr, 4);
|
||||
x += 4;
|
||||
|
||||
*x++ = OPT_END;
|
||||
|
||||
return DHCP_MSG_FIXED_SIZE + (x - msg->options);
|
||||
}
|
||||
Executable
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2008, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _WIFI_DHCP_H_
|
||||
#define _WIFI_DHCP_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define PORT_BOOTP_SERVER 67
|
||||
#define PORT_BOOTP_CLIENT 68
|
||||
|
||||
/* RFC 2131 p 9 */
|
||||
typedef struct dhcp_msg dhcp_msg;
|
||||
|
||||
#define OP_BOOTREQUEST 1
|
||||
#define OP_BOOTREPLY 2
|
||||
|
||||
#define FLAGS_BROADCAST 0x8000
|
||||
|
||||
#define HTYPE_ETHER 1
|
||||
|
||||
struct dhcp_msg
|
||||
{
|
||||
uint8_t op; /* BOOTREQUEST / BOOTREPLY */
|
||||
uint8_t htype; /* hw addr type */
|
||||
uint8_t hlen; /* hw addr len */
|
||||
uint8_t hops; /* client set to 0 */
|
||||
|
||||
uint32_t xid; /* transaction id */
|
||||
|
||||
uint16_t secs; /* seconds since start of acq */
|
||||
uint16_t flags;
|
||||
|
||||
uint32_t ciaddr; /* client IP addr */
|
||||
uint32_t yiaddr; /* your (client) IP addr */
|
||||
uint32_t siaddr; /* ip addr of next server */
|
||||
/* (DHCPOFFER and DHCPACK) */
|
||||
uint32_t giaddr; /* relay agent IP addr */
|
||||
|
||||
uint8_t chaddr[16]; /* client hw addr */
|
||||
char sname[64]; /* asciiz server hostname */
|
||||
char file[128]; /* asciiz boot file name */
|
||||
|
||||
uint8_t options[1024]; /* optional parameters */
|
||||
};
|
||||
|
||||
#define DHCP_MSG_FIXED_SIZE 236
|
||||
|
||||
/* first four bytes of options are a cookie to indicate that
|
||||
** the payload are DHCP options as opposed to some other BOOTP
|
||||
** extension.
|
||||
*/
|
||||
#define OPT_COOKIE1 0x63
|
||||
#define OPT_COOKIE2 0x82
|
||||
#define OPT_COOKIE3 0x53
|
||||
#define OPT_COOKIE4 0x63
|
||||
|
||||
/* BOOTP/DHCP options - see RFC 2132 */
|
||||
#define OPT_PAD 0
|
||||
|
||||
#define OPT_SUBNET_MASK 1 /* 4 <ipaddr> */
|
||||
#define OPT_TIME_OFFSET 2 /* 4 <seconds> */
|
||||
#define OPT_GATEWAY 3 /* 4*n <ipaddr> * n */
|
||||
#define OPT_DNS 6 /* 4*n <ipaddr> * n */
|
||||
#define OPT_DOMAIN_NAME 15 /* n <domainnamestring> */
|
||||
#define OPT_BROADCAST_ADDR 28 /* 4 <ipaddr> */
|
||||
|
||||
#define OPT_REQUESTED_IP 50 /* 4 <ipaddr> */
|
||||
#define OPT_LEASE_TIME 51 /* 4 <seconds> */
|
||||
#define OPT_MESSAGE_TYPE 53 /* 1 <msgtype> */
|
||||
#define OPT_SERVER_ID 54 /* 4 <ipaddr> */
|
||||
#define OPT_PARAMETER_LIST 55 /* n <optcode> * n */
|
||||
#define OPT_MESSAGE 56 /* n <errorstring> */
|
||||
#define OPT_CLASS_ID 60 /* n <opaque> */
|
||||
#define OPT_CLIENT_ID 61 /* n <opaque> */
|
||||
#define OPT_END 255
|
||||
|
||||
/* DHCP message types */
|
||||
#define DHCPDISCOVER 1
|
||||
#define DHCPOFFER 2
|
||||
#define DHCPREQUEST 3
|
||||
#define DHCPDECLINE 4
|
||||
#define DHCPACK 5
|
||||
#define DHCPNAK 6
|
||||
#define DHCPRELEASE 7
|
||||
#define DHCPINFORM 8
|
||||
|
||||
int init_dhcp_discover_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid);
|
||||
|
||||
int init_dhcp_request_msg(dhcp_msg *msg, void *hwaddr, uint32_t xid,
|
||||
uint32_t ipaddr, uint32_t serveraddr);
|
||||
|
||||
#endif
|
||||
Executable
+247
@@ -0,0 +1,247 @@
|
||||
/*
|
||||
* Copyright 2008, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/uio.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/if_packet.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/udp.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "dhcpmsg.h"
|
||||
|
||||
int fatal();
|
||||
|
||||
int open_raw_socket(const char *ifname __attribute__((unused)), uint8_t *hwaddr, int if_index)
|
||||
{
|
||||
int s;
|
||||
struct sockaddr_ll bindaddr;
|
||||
|
||||
if((s = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_IP))) < 0) {
|
||||
return fatal("socket(PF_PACKET)");
|
||||
}
|
||||
|
||||
memset(&bindaddr, 0, sizeof(bindaddr));
|
||||
bindaddr.sll_family = AF_PACKET;
|
||||
bindaddr.sll_protocol = htons(ETH_P_IP);
|
||||
bindaddr.sll_halen = ETH_ALEN;
|
||||
memcpy(bindaddr.sll_addr, hwaddr, ETH_ALEN);
|
||||
bindaddr.sll_ifindex = if_index;
|
||||
|
||||
if (bind(s, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) {
|
||||
return fatal("Cannot bind raw socket to interface");
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
static uint32_t checksum(void *buffer, unsigned int count, uint32_t startsum)
|
||||
{
|
||||
uint16_t *up = (uint16_t *)buffer;
|
||||
uint32_t sum = startsum;
|
||||
uint32_t upper16;
|
||||
|
||||
while (count > 1) {
|
||||
sum += *up++;
|
||||
count -= 2;
|
||||
}
|
||||
if (count > 0) {
|
||||
sum += (uint16_t) *(uint8_t *)up;
|
||||
}
|
||||
while ((upper16 = (sum >> 16)) != 0) {
|
||||
sum = (sum & 0xffff) + upper16;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
static uint32_t finish_sum(uint32_t sum)
|
||||
{
|
||||
return ~sum & 0xffff;
|
||||
}
|
||||
|
||||
int send_packet(int s, int if_index, struct dhcp_msg *msg, int size,
|
||||
uint32_t saddr, uint32_t daddr, uint32_t sport, uint32_t dport)
|
||||
{
|
||||
struct iphdr ip;
|
||||
struct udphdr udp;
|
||||
struct iovec iov[3];
|
||||
uint32_t udpsum;
|
||||
uint16_t temp;
|
||||
struct msghdr msghdr;
|
||||
struct sockaddr_ll destaddr;
|
||||
|
||||
ip.version = IPVERSION;
|
||||
ip.ihl = sizeof(ip) >> 2;
|
||||
ip.tos = 0;
|
||||
ip.tot_len = htons(sizeof(ip) + sizeof(udp) + size);
|
||||
ip.id = 0;
|
||||
ip.frag_off = 0;
|
||||
ip.ttl = IPDEFTTL;
|
||||
ip.protocol = IPPROTO_UDP;
|
||||
ip.check = 0;
|
||||
ip.saddr = saddr;
|
||||
ip.daddr = daddr;
|
||||
ip.check = finish_sum(checksum(&ip, sizeof(ip), 0));
|
||||
|
||||
udp.source = htons(sport);
|
||||
udp.dest = htons(dport);
|
||||
udp.len = htons(sizeof(udp) + size);
|
||||
udp.check = 0;
|
||||
|
||||
/* Calculate checksum for pseudo header */
|
||||
udpsum = checksum(&ip.saddr, sizeof(ip.saddr), 0);
|
||||
udpsum = checksum(&ip.daddr, sizeof(ip.daddr), udpsum);
|
||||
temp = htons(IPPROTO_UDP);
|
||||
udpsum = checksum(&temp, sizeof(temp), udpsum);
|
||||
temp = udp.len;
|
||||
udpsum = checksum(&temp, sizeof(temp), udpsum);
|
||||
|
||||
/* Add in the checksum for the udp header */
|
||||
udpsum = checksum(&udp, sizeof(udp), udpsum);
|
||||
|
||||
/* Add in the checksum for the data */
|
||||
udpsum = checksum(msg, size, udpsum);
|
||||
udp.check = finish_sum(udpsum);
|
||||
|
||||
iov[0].iov_base = (char *)&ip;
|
||||
iov[0].iov_len = sizeof(ip);
|
||||
iov[1].iov_base = (char *)&udp;
|
||||
iov[1].iov_len = sizeof(udp);
|
||||
iov[2].iov_base = (char *)msg;
|
||||
iov[2].iov_len = size;
|
||||
memset(&destaddr, 0, sizeof(destaddr));
|
||||
destaddr.sll_family = AF_PACKET;
|
||||
destaddr.sll_protocol = htons(ETH_P_IP);
|
||||
destaddr.sll_ifindex = if_index;
|
||||
destaddr.sll_halen = ETH_ALEN;
|
||||
memcpy(destaddr.sll_addr, "\xff\xff\xff\xff\xff\xff", ETH_ALEN);
|
||||
|
||||
msghdr.msg_name = &destaddr;
|
||||
msghdr.msg_namelen = sizeof(destaddr);
|
||||
msghdr.msg_iov = iov;
|
||||
msghdr.msg_iovlen = sizeof(iov) / sizeof(struct iovec);
|
||||
msghdr.msg_flags = 0;
|
||||
msghdr.msg_control = 0;
|
||||
msghdr.msg_controllen = 0;
|
||||
return sendmsg(s, &msghdr, 0);
|
||||
}
|
||||
|
||||
int receive_packet(int s, struct dhcp_msg *msg)
|
||||
{
|
||||
int nread;
|
||||
int is_valid;
|
||||
struct dhcp_packet {
|
||||
struct iphdr ip;
|
||||
struct udphdr udp;
|
||||
struct dhcp_msg dhcp;
|
||||
} packet;
|
||||
int dhcp_size;
|
||||
uint32_t sum;
|
||||
uint16_t temp;
|
||||
uint32_t saddr, daddr;
|
||||
|
||||
nread = read(s, &packet, sizeof(packet));
|
||||
if (nread < 0) {
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* The raw packet interface gives us all packets received by the
|
||||
* network interface. We need to filter out all packets that are
|
||||
* not meant for us.
|
||||
*/
|
||||
is_valid = 0;
|
||||
if (nread < (int)(sizeof(struct iphdr) + sizeof(struct udphdr))) {
|
||||
#if VERBOSE
|
||||
ALOGD("Packet is too small (%d) to be a UDP datagram", nread);
|
||||
#endif
|
||||
} else if (packet.ip.version != IPVERSION || packet.ip.ihl != (sizeof(packet.ip) >> 2)) {
|
||||
#if VERBOSE
|
||||
ALOGD("Not a valid IP packet");
|
||||
#endif
|
||||
} else if (nread < ntohs(packet.ip.tot_len)) {
|
||||
#if VERBOSE
|
||||
ALOGD("Packet was truncated (read %d, needed %d)", nread, ntohs(packet.ip.tot_len));
|
||||
#endif
|
||||
} else if (packet.ip.protocol != IPPROTO_UDP) {
|
||||
#if VERBOSE
|
||||
ALOGD("IP protocol (%d) is not UDP", packet.ip.protocol);
|
||||
#endif
|
||||
} else if (packet.udp.dest != htons(PORT_BOOTP_CLIENT)) {
|
||||
#if VERBOSE
|
||||
ALOGD("UDP dest port (%d) is not DHCP client", ntohs(packet.udp.dest));
|
||||
#endif
|
||||
} else {
|
||||
is_valid = 1;
|
||||
}
|
||||
|
||||
if (!is_valid) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Seems like it's probably a valid DHCP packet */
|
||||
/* validate IP header checksum */
|
||||
sum = finish_sum(checksum(&packet.ip, sizeof(packet.ip), 0));
|
||||
if (sum != 0) {
|
||||
printf("IP header checksum failure (0x%x)\n", packet.ip.check);
|
||||
return -1;
|
||||
}
|
||||
/*
|
||||
* Validate the UDP checksum.
|
||||
* Since we don't need the IP header anymore, we "borrow" it
|
||||
* to construct the pseudo header used in the checksum calculation.
|
||||
*/
|
||||
dhcp_size = ntohs(packet.udp.len) - sizeof(packet.udp);
|
||||
/*
|
||||
* check validity of dhcp_size.
|
||||
* 1) cannot be negative or zero.
|
||||
* 2) src buffer contains enough bytes to copy
|
||||
* 3) cannot exceed destination buffer
|
||||
*/
|
||||
if ((dhcp_size <= 0) ||
|
||||
((int)(nread - sizeof(struct iphdr) - sizeof(struct udphdr)) < dhcp_size) ||
|
||||
((int)sizeof(struct dhcp_msg) < dhcp_size)) {
|
||||
#if VERBOSE
|
||||
printf("Malformed Packet\n");
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
saddr = packet.ip.saddr;
|
||||
daddr = packet.ip.daddr;
|
||||
nread = ntohs(packet.ip.tot_len);
|
||||
memset(&packet.ip, 0, sizeof(packet.ip));
|
||||
packet.ip.saddr = saddr;
|
||||
packet.ip.daddr = daddr;
|
||||
packet.ip.protocol = IPPROTO_UDP;
|
||||
packet.ip.tot_len = packet.udp.len;
|
||||
temp = packet.udp.check;
|
||||
packet.udp.check = 0;
|
||||
sum = finish_sum(checksum(&packet, nread, 0));
|
||||
packet.udp.check = temp;
|
||||
if (!sum)
|
||||
sum = finish_sum(sum);
|
||||
if (temp != sum) {
|
||||
printf("UDP header checksum failure (0x%x should be 0x%x)\n", sum, temp);
|
||||
return -1;
|
||||
}
|
||||
memcpy(msg, &packet.dhcp, dhcp_size);
|
||||
return dhcp_size;
|
||||
}
|
||||
Executable
+25
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2008, The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef _WIFI_PACKET_H_
|
||||
#define _WIFI_PACKET_H_
|
||||
|
||||
int open_raw_socket(const char *ifname, uint8_t *hwaddr, int if_index);
|
||||
int send_packet(int s, int if_index, struct dhcp_msg *msg, int size,
|
||||
uint32_t saddr, uint32_t daddr, uint32_t sport, uint32_t dport);
|
||||
int receive_packet(int s, struct dhcp_msg *msg);
|
||||
|
||||
#endif
|
||||
Executable
+748
@@ -0,0 +1,748 @@
|
||||
/* This example is placed in the public domain. */
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <strings.h>
|
||||
#include <net/if.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <linux/if_link.h>
|
||||
#include <linux/if_ether.h>
|
||||
#include <linux/rtnetlink.h>
|
||||
//#include <linux/if.h>
|
||||
|
||||
#include "libmnl.h"
|
||||
#include "ifutils.h"
|
||||
|
||||
#define ERRMSG(v...) printf("%s-%d: error=%s %s\n", __func__, __LINE__, strerror(errno), ##v)
|
||||
extern void dbg_time(const char *fmt, ...);
|
||||
int mask_to_prefix_v4(uint32_t mask)
|
||||
{
|
||||
int ret = 0;
|
||||
while (mask)
|
||||
{
|
||||
mask = mask & (mask - 1);
|
||||
ret++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
const char *ipaddr_to_string_v4(in_addr_t ipaddr)
|
||||
{
|
||||
static char buf[INET6_ADDRSTRLEN] = {'\0'};
|
||||
buf[0] = '\0';
|
||||
uint32_t addr = ipaddr;
|
||||
return inet_ntop(AF_INET, &addr, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
const char *ipaddr_to_string_v6(uint8_t *ipaddr)
|
||||
{
|
||||
static char buf[INET6_ADDRSTRLEN] = {'\0'};
|
||||
buf[0] = '\0';
|
||||
return inet_ntop(AF_INET6, ipaddr, buf, sizeof(buf));
|
||||
}
|
||||
|
||||
static void ifc_init_ifr(const char *name, struct ifreq *ifr)
|
||||
{
|
||||
memset(ifr, 0, sizeof(struct ifreq));
|
||||
strncpy(ifr->ifr_name, name, IFNAMSIZ);
|
||||
ifr->ifr_name[IFNAMSIZ - 1] = 0;
|
||||
}
|
||||
|
||||
int if_get_hwaddr(const char *name, void *ptr)
|
||||
{
|
||||
int r;
|
||||
struct ifreq ifr;
|
||||
ifc_init_ifr(name, &ifr);
|
||||
|
||||
int ifc_ctl_sock = socket(AF_INET, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||
if (ifc_ctl_sock < 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
r = ioctl(ifc_ctl_sock, SIOCGIFHWADDR, &ifr);
|
||||
if (r < 0)
|
||||
return -1;
|
||||
|
||||
memcpy(ptr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int if_act_on_link(const char *ifname, int state)
|
||||
{
|
||||
struct mnl_socket *nl;
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
struct nlmsghdr *nlh;
|
||||
struct ifinfomsg *ifm;
|
||||
int ret;
|
||||
unsigned int seq, portid, change = 0, flags = 0;
|
||||
static int oldstate = -1;
|
||||
|
||||
if (state == oldstate)
|
||||
return 0;
|
||||
oldstate = state;
|
||||
|
||||
if (state)
|
||||
{
|
||||
change |= IFF_UP;
|
||||
flags |= IFF_UP;
|
||||
}
|
||||
else
|
||||
{
|
||||
change |= IFF_UP;
|
||||
flags &= ~IFF_UP;
|
||||
}
|
||||
|
||||
nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = RTM_NEWLINK;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
|
||||
nlh->nlmsg_seq = seq = time(NULL);
|
||||
ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(*ifm));
|
||||
ifm->ifi_family = AF_UNSPEC;
|
||||
ifm->ifi_change = change;
|
||||
ifm->ifi_flags = flags;
|
||||
|
||||
mnl_attr_put_str(nlh, IFLA_IFNAME, ifname);
|
||||
|
||||
nl = mnl_socket_open(NETLINK_ROUTE);
|
||||
if (nl == NULL)
|
||||
{
|
||||
ERRMSG("mnl_socket_open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_bind");
|
||||
return -1;
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
if (ret == -1)
|
||||
{
|
||||
ERRMSG(" mnl_socket_recvfrom");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
|
||||
if (ret == -1)
|
||||
{
|
||||
ERRMSG(" mnl_cb_run");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnl_socket_close(nl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_link_up(const char *ifname)
|
||||
{
|
||||
dbg_time("if_link_up %s",ifname);
|
||||
return if_act_on_link(ifname, 1);
|
||||
}
|
||||
|
||||
int if_link_down(const char *ifname)
|
||||
{
|
||||
|
||||
dbg_time("if_link_down %s",ifname);
|
||||
return if_act_on_link(ifname, 0);
|
||||
}
|
||||
|
||||
int if_set_mtu(const char *ifname, uint32_t mtu)
|
||||
{
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
unsigned int seq, portid;
|
||||
struct mnl_socket *nl;
|
||||
struct nlmsghdr *nlh;
|
||||
struct ifinfomsg *ifm;
|
||||
int ret;
|
||||
int iface;
|
||||
static uint32_t oldmtu = 1500;
|
||||
|
||||
if (mtu == oldmtu)
|
||||
return 0;
|
||||
oldmtu = mtu;
|
||||
|
||||
iface = if_nametoindex(ifname);
|
||||
if (iface == 0)
|
||||
{
|
||||
ERRMSG(" if_nametoindex");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = RTM_NEWLINK;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK;
|
||||
nlh->nlmsg_seq = seq = time(NULL);
|
||||
ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifinfomsg));
|
||||
ifm->ifi_family = AF_UNSPEC;
|
||||
ifm->ifi_index = iface;
|
||||
ifm->ifi_change = 0xFFFFFFFF;
|
||||
ifm->ifi_type = 0;
|
||||
ifm->ifi_flags = IFF_NOARP | IFF_MULTICAST;
|
||||
|
||||
mnl_attr_put_u32(nlh, IFLA_MTU, mtu);
|
||||
|
||||
nl = mnl_socket_open(NETLINK_ROUTE);
|
||||
if (nl == NULL)
|
||||
{
|
||||
ERRMSG(" mnl_socket_open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_bind");
|
||||
return -1;
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
if (ret == -1)
|
||||
{
|
||||
ERRMSG(" mnl_socket_recvfrom");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
|
||||
if (ret == -1)
|
||||
{
|
||||
ERRMSG(" mnl_cb_run");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnl_socket_close(nl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the ip addr object
|
||||
*
|
||||
* @param operate
|
||||
* 0 -> add address on interface
|
||||
* 1 -> delete address on interface
|
||||
* @param ifname
|
||||
* @param ipaddr
|
||||
* @param prefix
|
||||
* @return int
|
||||
*/
|
||||
static int if_act_on_addr(bool operate, int proto, const char *ifname, addr_t *ipaddr, uint32_t prefix)
|
||||
{
|
||||
struct mnl_socket *nl;
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
struct nlmsghdr *nlh;
|
||||
struct ifaddrmsg *ifm;
|
||||
uint32_t seq, portid;
|
||||
int ret, family = proto;
|
||||
|
||||
int iface;
|
||||
|
||||
iface = if_nametoindex(ifname);
|
||||
if (iface == 0)
|
||||
{
|
||||
ERRMSG(" if_nametoindex");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nlh = mnl_nlmsg_put_header(buf);
|
||||
if (operate)
|
||||
nlh->nlmsg_type = RTM_NEWADDR;
|
||||
else
|
||||
nlh->nlmsg_type = RTM_DELADDR;
|
||||
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_REPLACE | NLM_F_ACK;
|
||||
nlh->nlmsg_seq = seq = time(NULL);
|
||||
|
||||
ifm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct ifaddrmsg));
|
||||
|
||||
ifm->ifa_family = family;
|
||||
ifm->ifa_prefixlen = prefix;
|
||||
ifm->ifa_flags = IFA_F_PERMANENT;
|
||||
|
||||
ifm->ifa_scope = RT_SCOPE_UNIVERSE;
|
||||
ifm->ifa_index = iface;
|
||||
|
||||
/*
|
||||
* The exact meaning of IFA_LOCAL and IFA_ADDRESS depend
|
||||
* on the address family being used and the device type.
|
||||
* For broadcast devices (like the interfaces we use),
|
||||
* for IPv4 we specify both and they are used interchangeably.
|
||||
* For IPv6, only IFA_ADDRESS needs to be set.
|
||||
*/
|
||||
if (family == AF_INET)
|
||||
{
|
||||
mnl_attr_put_u32(nlh, IFA_LOCAL, ipaddr->ip);
|
||||
mnl_attr_put_u32(nlh, IFA_ADDRESS, ipaddr->ip);
|
||||
}
|
||||
else
|
||||
{
|
||||
mnl_attr_put(nlh, IFA_ADDRESS, sizeof(struct in6_addr), ipaddr);
|
||||
}
|
||||
|
||||
nl = mnl_socket_open(NETLINK_ROUTE);
|
||||
if (nl == NULL)
|
||||
{
|
||||
ERRMSG(" mnl_socket_open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_bind");
|
||||
return -1;
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
if (ret < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_recvfrom");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
ERRMSG(" mnl_cb_run");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnl_socket_close(nl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_set_addr_v4(const char *ifname, in_addr_t ipaddr, uint32_t prefix)
|
||||
{
|
||||
addr_t addr;
|
||||
addr.ip = ipaddr;
|
||||
return if_act_on_addr(1, AF_INET, ifname, &addr, prefix);
|
||||
}
|
||||
|
||||
int if_del_addr_v4(const char *ifname, in_addr_t ipaddr, uint32_t prefix)
|
||||
{
|
||||
addr_t addr;
|
||||
addr.ip = ipaddr;
|
||||
return if_act_on_addr(0, AF_INET, ifname, &addr, prefix);
|
||||
}
|
||||
|
||||
int if_set_addr_v6(const char *ifname, uint8_t *ipaddr, uint32_t prefix)
|
||||
{
|
||||
addr_t addr;
|
||||
memcpy(&addr.ip6, ipaddr, 16);
|
||||
return if_act_on_addr(1, AF_INET6, ifname, &addr, prefix);
|
||||
}
|
||||
|
||||
int if_del_addr_v6(const char *ifname, uint8_t *ipaddr, uint32_t prefix)
|
||||
{
|
||||
addr_t addr;
|
||||
memcpy(&addr.ip6, ipaddr, 16);
|
||||
return if_act_on_addr(0, AF_INET6, ifname, &addr, prefix);
|
||||
}
|
||||
|
||||
static int data_attr_cb(const struct nlattr *attr, void *data)
|
||||
{
|
||||
const struct nlattr **tb = data;
|
||||
int type = mnl_attr_get_type(attr);
|
||||
|
||||
/* skip unsupported attribute in user-space */
|
||||
if (mnl_attr_type_valid(attr, IFA_MAX) < 0)
|
||||
return MNL_CB_OK;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case IFA_ADDRESS:
|
||||
if (mnl_attr_validate(attr, MNL_TYPE_BINARY) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_attr_validate");
|
||||
return MNL_CB_ERROR;
|
||||
}
|
||||
break;
|
||||
}
|
||||
tb[type] = attr;
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
static int data_cb(const struct nlmsghdr *nlh, void *data)
|
||||
{
|
||||
struct nlattr *tb[IFA_MAX + 1] = {};
|
||||
struct ifaddrmsg *ifa = mnl_nlmsg_get_payload(nlh);
|
||||
struct addrinfo_t *addrinfo = (struct addrinfo_t *)data;
|
||||
void *addr = NULL;
|
||||
|
||||
mnl_attr_parse(nlh, sizeof(*ifa), data_attr_cb, tb);
|
||||
if (tb[IFA_ADDRESS])
|
||||
{
|
||||
char out[INET6_ADDRSTRLEN];
|
||||
|
||||
addr = mnl_attr_get_payload(tb[IFLA_ADDRESS]);
|
||||
addr = mnl_attr_get_payload(tb[IFA_ADDRESS]);
|
||||
if (!inet_ntop(ifa->ifa_family, addr, out, sizeof(out)))
|
||||
ERRMSG("inet_ntop");
|
||||
// printf("%d %d-> %d %s\n", addrinfo->iface, ifa->ifa_index, ifa->ifa_scope, out);
|
||||
|
||||
addrinfo->addrs[addrinfo->num].prefix = ifa->ifa_prefixlen;
|
||||
if (ifa->ifa_index == addrinfo->iface)
|
||||
{
|
||||
if (ifa->ifa_family == AF_INET6)
|
||||
memcpy(addrinfo->addrs[addrinfo->num].address.ip6.s6_addr, addr, 16);
|
||||
if (ifa->ifa_family == AF_INET)
|
||||
memcpy(&(addrinfo->addrs[addrinfo->num].address.ip), addr, 4);
|
||||
addrinfo->num++;
|
||||
}
|
||||
}
|
||||
|
||||
// ifa->ifa_scope
|
||||
// 0: global
|
||||
// 200: site
|
||||
// 253: link
|
||||
// 254: host
|
||||
// 255: nowhere
|
||||
|
||||
return MNL_CB_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief
|
||||
*
|
||||
* @param ifname
|
||||
* @param proto
|
||||
* AF_INET -> for IPv4
|
||||
* AF_INET6 -> for IPv6
|
||||
* @return int
|
||||
*/
|
||||
static int if_get_addr(const char *ifname, int proto, struct addrinfo_t *addrinfo)
|
||||
{
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
unsigned int seq, portid;
|
||||
struct mnl_socket *nl;
|
||||
struct nlmsghdr *nlh;
|
||||
struct rtgenmsg *rt;
|
||||
int ret;
|
||||
|
||||
addrinfo->iface = if_nametoindex(ifname);
|
||||
if (addrinfo->iface == 0)
|
||||
{
|
||||
ERRMSG(" if_nametoindex");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nlh = mnl_nlmsg_put_header(buf);
|
||||
nlh->nlmsg_type = RTM_GETADDR;
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_DUMP;
|
||||
nlh->nlmsg_seq = seq = time(NULL);
|
||||
rt = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtgenmsg));
|
||||
if (proto == AF_INET)
|
||||
rt->rtgen_family = AF_INET;
|
||||
else if (proto == AF_INET6)
|
||||
rt->rtgen_family = AF_INET6;
|
||||
|
||||
nl = mnl_socket_open(NETLINK_ROUTE);
|
||||
if (nl == NULL)
|
||||
{
|
||||
ERRMSG(" mnl_socket_open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_bind");
|
||||
return -1;
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
while (ret > 0)
|
||||
{
|
||||
ret = mnl_cb_run(buf, ret, seq, portid, data_cb, addrinfo);
|
||||
if (ret <= MNL_CB_STOP)
|
||||
break;
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
}
|
||||
if (ret == -1)
|
||||
{
|
||||
ERRMSG(" error");
|
||||
return -1;
|
||||
}
|
||||
mnl_socket_close(nl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_flush_v4_addr(const char *ifname)
|
||||
{
|
||||
struct addrinfo_t addrinfo;
|
||||
int i = 0;
|
||||
|
||||
memset(&addrinfo, 0, sizeof(struct addrinfo_t));
|
||||
if_get_addr(ifname, AF_INET, &addrinfo);
|
||||
for (; i < addrinfo.num; i++)
|
||||
{
|
||||
// printf("remove address: %s\n", ipaddr_to_string_v4(addrinfo.addrs[i].address.ip));
|
||||
if_del_addr_v4(ifname, addrinfo.addrs[i].address.ip, addrinfo.addrs[i].prefix);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_flush_v6_addr(const char *ifname)
|
||||
{
|
||||
struct addrinfo_t addrinfo;
|
||||
int i = 0;
|
||||
|
||||
memset(&addrinfo, 0, sizeof(struct addrinfo_t));
|
||||
if_get_addr(ifname, AF_INET6, &addrinfo);
|
||||
for (; i < addrinfo.num; i++)
|
||||
{
|
||||
// printf("remove address: %s\n", ipaddr_to_string_v6(addrinfo.addrs[i].address.ip6.s6_addr));
|
||||
if_del_addr_v6(ifname, addrinfo.addrs[i].address.ip6.s6_addr, addrinfo.addrs[i].prefix);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the route addr object
|
||||
* Usage:
|
||||
* iface destination cidr [gateway]
|
||||
* Example:
|
||||
* eth0 10.0.1.12 32 10.0.1.11
|
||||
* eth0 ffff::10.0.1.12 128 fdff::1
|
||||
* @param operate
|
||||
* add or del
|
||||
* @param ifname
|
||||
* @param dstaddr
|
||||
* @param prefix
|
||||
* @param gwaddr
|
||||
* @return int
|
||||
*/
|
||||
int if_act_on_route(bool operate, int proto, const char *ifname, addr_t *dstaddr, uint32_t prefix, addr_t *gwaddr)
|
||||
{
|
||||
struct mnl_socket *nl;
|
||||
char buf[MNL_SOCKET_BUFFER_SIZE];
|
||||
struct nlmsghdr *nlh;
|
||||
struct rtmsg *rtm;
|
||||
uint32_t seq, portid;
|
||||
int iface, ret, family = proto;
|
||||
|
||||
iface = if_nametoindex(ifname);
|
||||
if (iface == 0)
|
||||
{
|
||||
ERRMSG(" if_nametoindex");
|
||||
return -1;
|
||||
}
|
||||
|
||||
nlh = mnl_nlmsg_put_header(buf);
|
||||
if (operate)
|
||||
nlh->nlmsg_type = RTM_NEWROUTE;
|
||||
else
|
||||
nlh->nlmsg_type = RTM_DELROUTE;
|
||||
|
||||
nlh->nlmsg_flags = NLM_F_REQUEST | NLM_F_CREATE | NLM_F_ACK;
|
||||
nlh->nlmsg_seq = seq = time(NULL);
|
||||
|
||||
rtm = mnl_nlmsg_put_extra_header(nlh, sizeof(struct rtmsg));
|
||||
rtm->rtm_family = family;
|
||||
rtm->rtm_dst_len = prefix;
|
||||
rtm->rtm_src_len = 0;
|
||||
rtm->rtm_tos = 0;
|
||||
rtm->rtm_protocol = RTPROT_STATIC;
|
||||
rtm->rtm_table = RT_TABLE_MAIN;
|
||||
rtm->rtm_type = RTN_UNICAST;
|
||||
/* is there any gateway? */
|
||||
rtm->rtm_scope = gwaddr ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK;
|
||||
rtm->rtm_flags = 0;
|
||||
|
||||
if (family == AF_INET)
|
||||
mnl_attr_put_u32(nlh, RTA_DST, dstaddr->ip);
|
||||
else
|
||||
mnl_attr_put(nlh, RTA_DST, sizeof(struct in6_addr), dstaddr);
|
||||
|
||||
mnl_attr_put_u32(nlh, RTA_OIF, iface);
|
||||
if (gwaddr)
|
||||
{
|
||||
if (family == AF_INET)
|
||||
mnl_attr_put_u32(nlh, RTA_GATEWAY, gwaddr->ip);
|
||||
else
|
||||
{
|
||||
mnl_attr_put(nlh, RTA_GATEWAY, sizeof(struct in6_addr), gwaddr);
|
||||
}
|
||||
}
|
||||
|
||||
nl = mnl_socket_open(NETLINK_ROUTE);
|
||||
if (nl == NULL)
|
||||
{
|
||||
ERRMSG(" mnl_socket_open");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_bind");
|
||||
return -1;
|
||||
}
|
||||
portid = mnl_socket_get_portid(nl);
|
||||
|
||||
if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_sendto");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_socket_recvfrom(nl, buf, sizeof(buf));
|
||||
if (ret < 0)
|
||||
{
|
||||
ERRMSG(" mnl_socket_recvfrom");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mnl_cb_run(buf, ret, seq, portid, NULL, NULL);
|
||||
if (ret < 0)
|
||||
{
|
||||
ERRMSG(" mnl_cb_run");
|
||||
return -1;
|
||||
}
|
||||
|
||||
mnl_socket_close(nl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_set_default_route_v4(const char *ifname)
|
||||
{
|
||||
return if_act_on_route(1, AF_INET, ifname, (addr_t *)&in6addr_any, 0, NULL);
|
||||
}
|
||||
|
||||
int if_del_default_route_v4(const char *ifname)
|
||||
{
|
||||
return if_act_on_route(0, AF_INET, ifname, (addr_t *)&in6addr_any, 0, NULL);
|
||||
}
|
||||
|
||||
int if_set_default_route_v6(const char *ifname)
|
||||
{
|
||||
return if_act_on_route(1, AF_INET6, ifname, (addr_t *)&in6addr_any, 0, NULL);
|
||||
}
|
||||
|
||||
int if_del_default_route_v6(const char *ifname)
|
||||
{
|
||||
return if_act_on_route(0, AF_INET6, ifname, (addr_t *)&in6addr_any, 0, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Set the default gwaddr object
|
||||
* set default gw
|
||||
* @param operate
|
||||
* @param ifname
|
||||
* @param gwaddr
|
||||
* gateway ip
|
||||
* @return int
|
||||
*/
|
||||
int if_set_route_gw_v4(const char *ifname, in_addr_t gwaddr)
|
||||
{
|
||||
addr_t addr;
|
||||
memset(&addr, 0, sizeof(addr_t));
|
||||
addr.ip = gwaddr;
|
||||
return if_act_on_route(1, AF_INET, ifname, (addr_t *)&in6addr_any, 0, &addr);
|
||||
}
|
||||
|
||||
int if_del_route_gw_v4(const char *ifname, in_addr_t gwaddr)
|
||||
{
|
||||
addr_t addr;
|
||||
memset(&addr, 0, sizeof(addr_t));
|
||||
addr.ip = gwaddr;
|
||||
return if_act_on_route(0, AF_INET, ifname, (addr_t *)&in6addr_any, 0, &addr);
|
||||
}
|
||||
|
||||
int if_set_route_gw_v6(const char *ifname, uint8_t *gwaddr)
|
||||
{
|
||||
addr_t addr;
|
||||
memset(&addr, 0, sizeof(addr_t));
|
||||
memcpy(&addr.ip6, gwaddr, 16);
|
||||
return if_act_on_route(1, AF_INET6, ifname, (addr_t *)&in6addr_any, 0, &addr);
|
||||
}
|
||||
|
||||
int if_del_route_gw_v6(const char *ifname, uint8_t *gwaddr)
|
||||
{
|
||||
addr_t addr;
|
||||
memset(&addr, 0, sizeof(addr_t));
|
||||
memcpy(&addr.ip6, gwaddr, 16);
|
||||
return if_act_on_route(0, AF_INET6, ifname, (addr_t *)&in6addr_any, 0, &addr);
|
||||
}
|
||||
|
||||
int if_set_dns(const char *dns1, const char *dns2)
|
||||
{
|
||||
int ret = 0;
|
||||
char buf[128] = {'\0'};
|
||||
int fd = open("/etc/resolv.conf", O_CREAT | O_WRONLY | O_TRUNC);
|
||||
if (fd < 0)
|
||||
{
|
||||
ERRMSG(" fail to open /etc/resolv.conf");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dns1)
|
||||
snprintf(buf, sizeof(buf), "nameserver %s\n", dns1);
|
||||
if (dns2)
|
||||
snprintf(buf, sizeof(buf), "nameserver %s\n", dns2);
|
||||
ret = write(fd, buf, strlen(buf));
|
||||
if (ret < 0)
|
||||
{
|
||||
ERRMSG(" write dns");
|
||||
}
|
||||
close(fd);
|
||||
return ret > 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int if_set_network_v4(const char *ifname, in_addr_t ipaddr, uint32_t prefix,
|
||||
in_addr_t gwaddr, in_addr_t dns1, in_addr_t dns2)
|
||||
{
|
||||
if_link_up(ifname);
|
||||
sleep(2);
|
||||
if_set_addr_v4(ifname, ipaddr, prefix);
|
||||
if_set_default_route_v4(ifname);
|
||||
if_set_dns(ipaddr_to_string_v4(dns1), ipaddr_to_string_v4(dns2));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int if_set_network_v6(const char *ifname, uint8_t *ipaddr, uint32_t prefix,
|
||||
uint8_t *gwaddr, uint8_t *dns1, uint8_t *dns2)
|
||||
{
|
||||
if_link_up(ifname);
|
||||
sleep(2);
|
||||
if_set_addr_v6(ifname, ipaddr, prefix);
|
||||
if_set_default_route_v6(ifname);
|
||||
if_set_dns(ipaddr_to_string_v6(dns1), ipaddr_to_string_v6(dns2));
|
||||
return 0;
|
||||
}
|
||||
Loaded 100 of 6244 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user