M7350v3_en_gpl

This commit is contained in:
T
2024-09-09 08:55:19 +00:00
parent 801e6d2ad8
commit 2d95e8761a
2791 changed files with 89608 additions and 390711 deletions

View File

@ -0,0 +1,22 @@
DESCRIPTION = "cjson lib"
inherit tp-link-common
SRC_DIR = "${WORKSPACE}/tp-opensource/cjson"
HOMEPAGE = "http://sourceforge.net/projects/cjson/"
LICENSE = "MIT"
LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
PR="r58"
S="${WORKDIR}/cjson"
FILES_${PN} += "/usr/lib"
do_install () {
install -d ${D}${includedir}/cjson
install -m 0755 *.h ${D}${includedir}/cjson
install -d ${D}${libdir}
install -m 0755 libcjson.so ${D}${libdir}/
}

View File

@ -1,6 +1,6 @@
include compat-wireless.inc
PR = "${INC_PR}.7"
PR = "${INC_PR}.4"
SRC_URI += "file://ath6kl_ctrl_wlan"

View File

@ -15,9 +15,7 @@ SRC_URI = "file://${WORKSPACE}/external/compat-wireless"
COMPAT_WIRELESS_VERSION = "3.0"
inherit gitsha
PV = "git-${GITSHA}-${COMPAT_WIRELESS_VERSION}"
SRC_DIR = "${WORKSPACE}/external/compat-wireless"
PV = "${COMPAT_WIRELESS_VERSION}"
S = "${WORKDIR}/compat-wireless"

View File

@ -52,60 +52,10 @@ HOSTAPD_STA_AP_CONF="/etc/sta_mode_hostapd.conf"
retry=0
AR6004_DEVID="0cf3:9374"
# MAC Address
RANDOM_MAC_ADDRESS="00:11:22:33:44:55"
UCI_MAC_ADDRESS="`uci get product.wlan.mac_address`"
# Enable FW error recovery via debug quirks, default is 0x1FC04.
# Disable ATH6KL_MODULE_ENABLE_USB_AUTO_PM(16).
# for more infomation, please refer to debug.h of ath6kl driver.
ATH6KL_DEBUG_QUIRKS="0x4FC04"
# if start FTM
ATH6KL_FTM_QUIRKS="0x10"
# Check existence
if [ ! -n "UCI_MAC_ADDRESS" ]; then
MAC_ADDRESS=$RANDOM_MAC_ADDRESS
else
# Mac address in uci is like: 00-11-22-33-44-55
# But wlan driver need this: 00:11:22:33:44:55
# So convert '-' to ':' in MAC address
MAC_ADDRESS="`echo $UCI_MAC_ADDRESS | sed s/-/:/g`"
fi
# Check if calibration files exist
is_cal_pass () {
# TR961 has no file "calData", just check bdata_self
if [ -e "/misc/bdata_self.bin" ]; then
return 1
else
return 0
fi
}
do_ctrl_ar6004_hsic () {
case "$1" in
start)
echo "Starting WLAN... $@"
echo "WLAN: Starting WLAN... $@" >> /dev/kmsg
# When starts in not FTM mode, and calibration failed, wifi will stop bringing up
ftm_match="`echo $@ | grep "debug_quirks=$ATH6KL_FTM_QUIRKS"`"
if [ -z "$ftm_match" ]; then
# Check if cal passed
is_cal_pass
if [ $? -ne 1 ]; then
echo "Cannot find cal files at /misc, abort."
echo "WLAN: Cannot find cal files at /misc, abort." >> /dev/kmsg
exit 1
fi
else
echo "wifi start in FTM mode"
echo "WLAN: wifi start in FTM mode" >> /dev/kmsg
fi
shift
start_ap1=0
devmode=1
@ -119,23 +69,13 @@ do_ctrl_ar6004_hsic () {
return 1
fi
# Disable HSIC suspend
## HSIC host side may go wrong when resuming and
## cause bam failure.
echo on > /sys/devices/msm_hsic_host/power/control
# Clear caches to reduce chance of mem allocation failure.
## Kernel panic may occur when loading ath6kl drivers if
## dma allocation failure happens previously.
echo "3" > /proc/sys/vm/drop_caches
set -e
insmod $MODULE_BASE/compat/compat.ko
insmod $MODULE_BASE/net/wireless/cfg80211.ko
insmod $MODULE_BASE/drivers/net/wireless/ath/ath6kl/ath6kl_core.ko reg_hint=0 debug_quirks=$ATH6KL_DEBUG_QUIRKS devmode=$devmode enable_ani=1 ath6kl_wifi_mac=$MAC_ADDRESS $@
insmod $MODULE_BASE/drivers/net/wireless/ath/ath6kl/ath6kl_usb.ko
echo hsic 2000 > /sys/bus/platform/devices/usb_bam/inactivity_timer
echo msm_hsic_host > /sys/bus/platform/drivers/msm_hsic_host/bind
insmod $MODULE_BASE/compat/compat.ko
insmod $MODULE_BASE/net/wireless/cfg80211.ko
insmod $MODULE_BASE/drivers/net/wireless/ath/ath6kl/ath6kl_core.ko devmode=$devmode $@
insmod $MODULE_BASE/drivers/net/wireless/ath/ath6kl/ath6kl_usb.ko
set +e
c=1
@ -150,11 +90,9 @@ do_ctrl_ar6004_hsic () {
if [ $c -gt $RETRY_LIMIT ]; then
echo "WLAN bring-up failed!"
echo "WLAN: WLAN bring-up failed!" >> /dev/kmsg
lsusb | grep -q $AR6004_DEVID
if [ $? -ne 0 -a $retry -lt $ENUM_RETRY_LIMIT ]; then
echo "Enumeration failure, try again!"
echo "WLAN: Enumeration failure, try again!" >> /dev/kmsg
do_ctrl_ar6004_hsic stop
sleep 1
if [ $start_ap1 -eq 1 ]; then
@ -171,32 +109,29 @@ do_ctrl_ar6004_hsic () {
if [ $start_ap1 -eq 1 ]; then
echo "Adding second AP interface(wlan1)"
echo "WLAN: Adding second AP interface(wlan1)" >> /dev/kmsg
iw dev wlan0 interface add wlan1 type __ap
ifconfig wlan1 up 2> /dev/null
fi
echo "Starting CXMAPP..."
echo "WLAN: Starting CXMAPP..." >> /dev/kmsg
cxmapp --init
cxmapp &
;;
start_ftm)
do_ctrl_ar6004_hsic start debug_quirks=$ATH6KL_FTM_QUIRKS
do_ctrl_ar6004_hsic start debug_quirks=0x10
;;
stop)
echo "Stopping WLAN..."
echo "WLAN: Stopping WLAN..." >> /dev/kmsg
killall -15 cxmapp
echo msm_hsic_host > /sys/bus/platform/drivers/msm_hsic_host/unbind
echo hsic 0 > /sys/bus/platform/devices/usb_bam/inactivity_timer
rmmod ath6kl_usb
rmmod ath6kl_core
rmmod cfg80211
rmmod compat
echo msm_hsic_host > /sys/bus/platform/drivers/msm_hsic_host/unbind
echo hsic 0 > /sys/bus/platform/devices/usb_bam/inactivity_timer
;;
restart)
@ -273,7 +208,6 @@ do_ctrl_ar6003 () {
stop)
echo "Stopping WLAN..."
echo "WLAN: Stopping WLAN..." >> /dev/kmsg
killall -15 cxmapp
echo 0 > $SDIO_POLLING_PATH

View File

@ -14,6 +14,7 @@ CONFIG_EAP_AKA=y
CONFIG_EAP_AKA_PRIME=y
CONFIG_WPS=y
CONFIG_WPS2=y
CONFIG_WPS_UPNP=y
CONFIG_IEEE80211N=y

View File

@ -1,14 +1,9 @@
include hostap-daemon.inc
PR = "${INC_PR}.4"
PR = "${INC_PR}.2"
SRC_URI += "file://defconfig-ath6kl"
inherit gitsha
PV = "git-${GITSHA}"
SRC_DIR = "${WORKSPACE}/external/hostap"
do_configure() {
install -m 0644 ${WORKDIR}/defconfig-ath6kl .config
}
@ -18,6 +13,4 @@ do_configure_append() {
echo "CFLAGS += -I${WORKSPACE}/wlan/host/include" >> .config
echo "CFLAGS += -I${WORKSPACE}/wlan/host/os/linux/include" >> .config
echo "CFLAGS += -I${WORKSPACE}/wlan/host/wlan/include" >> .config
echo "${@base_conditional('TP_WIRELESS_ACL_TYPE_BLACK', 'y', 'CONFIG_WIRELESS_ACL_TYPE_BLACK=y', '', d)}" >> .config
echo "${@base_conditional('TP_NEED_WLAN_MODULE_BCM', 'y', 'CONFIG_TP_WLAN_MODULE_BCM=y', '', d)}" >> .config
}

View File

@ -9,6 +9,7 @@ DEPENDS = " \
gettext-native \
yaffs2-utils-native \
mkbootimg-native \
kernel-tests \
dtbtool-native \
"

View File

@ -1,49 +0,0 @@
# Force a few additional dependencies in the mix so that we get the needed
# recipes to build in the right order so we can make the bootimg file and
# our yaffs2 image...
DEPENDS = " \
virtual/kernel \
virtual/bootloader \
pkgconfig-native \
gtk-doc-native \
gettext-native \
yaffs2-utils-native \
mkbootimg-native \
dtbtool-native \
"
# Image output types
IMAGE_FSTYPES = "tar.gz yaffs2 ${INITRAMFS_FSTYPES}"
# Make the bootimg image file using the information available in the sysroot...
do_rootfs_append() {
# Make bootimage
ver=`sed -r 's/#define UTS_RELEASE "(.*)"/\1/' ${STAGING_KERNEL_DIR}/include/generated/utsrelease.h`
# Make Device tree blobs for various hardware configurations
dts_files=`find ${WORKSPACE}/kernel/arch/arm/boot/dts -iname *${MACHINE_DTS_NAME}*.dts | awk -F/ '{print $NF}' | awk -F[.][d] '{print $1}'`
for d in ${dts_files}; do
${STAGING_KERNEL_DIR}/scripts/dtc/dtc -p 4096 -O dtb -o ${STAGING_DIR_TARGET}/boot/${d}.dtb ${WORKSPACE}/kernel/arch/arm/boot/dts/${d}.dts
done
dtb_files=`find ${STAGING_DIR_TARGET}/boot -iname *${MACHINE_DTS_NAME}*.dtb | awk -F/ '{print $NF}' | awk -F[.][d] '{print $1}'`
# Create separate images with dtb appended to zImage for all targets.
for d in ${dtb_files}; do
targets=`echo ${d#${MACHINE_DTS_NAME}-}`
cat ${STAGING_DIR_TARGET}/boot/zImage-${ver} ${STAGING_DIR_TARGET}/boot/${d}.dtb > ${STAGING_DIR_TARGET}/boot/dtb-zImage-${ver}-${targets}
done
${STAGING_BINDIR_NATIVE}/dtbtool ${STAGING_DIR_TARGET}/boot/ -o ${STAGING_DIR_TARGET}/boot/masterDTB -p ${STAGING_KERNEL_DIR}/scripts/dtc/ -v
# Updated base address according to new memory map.
${STAGING_BINDIR_NATIVE}/mkbootimg --kernel ${STAGING_DIR_TARGET}/boot/zImage-${ver} \
--dt ${STAGING_DIR_TARGET}/boot/masterDTB \
--ramdisk /dev/null \
--cmdline "noinitrd root=/dev/mtdblock17 rw rootfstype=yaffs2 console=ttyHSL0,115200,n8 androidboot.hardware=qcom ehci-hcd.park=3 g-android.rx_trigger_enabled=1" \
--base 0x00300000 \
--tags-addr 0x06800000 \
--ramdisk_offset 0x0 \
--output ${DEPLOY_DIR_IMAGE}/${PN}-boot-${MACHINE}.img
}

View File

@ -7,7 +7,7 @@ IMAGE_INSTALL += "${ROOTFS_PKGMANAGE_BOOTSTRAP}"
IMAGE_INSTALL += "${POKY_EXTRA_INSTALL}"
# The MSM Linux minimal boot image files.
#IMAGE_INSTALL += "alsa-intf"
IMAGE_INSTALL += "alsa-intf"
IMAGE_INSTALL += "avahi-systemd"
IMAGE_INSTALL += "avahi-daemon"
IMAGE_INSTALL += "avahi-dnsconfd"
@ -47,9 +47,9 @@ IMAGE_INSTALL += "libavahi-glib"
IMAGE_INSTALL += "libstdc++"
IMAGE_INSTALL += "libxml2"
IMAGE_INSTALL += "lighttpd"
#IMAGE_INSTALL += "loc-api"
#IMAGE_INSTALL += "minidlna"
#IMAGE_INSTALL += "miniupnpd"
IMAGE_INSTALL += "loc-api"
IMAGE_INSTALL += "minidlna"
IMAGE_INSTALL += "miniupnpd"
IMAGE_INSTALL += "openssl"
IMAGE_INSTALL += "open-source-kernel-tests"
IMAGE_INSTALL += "powerapp"
@ -66,13 +66,7 @@ IMAGE_INSTALL += "system-core-libcutils"
IMAGE_INSTALL += "tcpdump"
IMAGE_INSTALL += "wireless-tools"
IMAGE_INSTALL += "wlan"
#IMAGE_INSTALL += "wpa-supplicant-ath6kl"
IMAGE_INSTALL += "samba"
IMAGE_INSTALL += "uci"
IMAGE_INSTALL += "ubus"
IMAGE_INSTALL += "libubox"
IMAGE_INSTALL += "libghttp"
IMAGE_INSTALL += "tp-domain"
IMAGE_INSTALL += "wpa-supplicant-ath6kl"
IMAGE_PREPROCESS_COMMAND += "mkdir -p ${IMAGE_ROOTFS}/cache;"
IMAGE_PREPROCESS_COMMAND += "echo ro.build.version.release=`cat ${IMAGE_ROOTFS}/etc/version ` >> ${IMAGE_ROOTFS}/build.prop;"

View File

@ -1,78 +0,0 @@
# The mkbootimg production process.
require mdm-bootimg.inc
# The OE-Core minimal boot image files.
IMAGE_INSTALL += "task-core-boot"
IMAGE_INSTALL += "${ROOTFS_PKGMANAGE_BOOTSTRAP}"
IMAGE_INSTALL += "${POKY_EXTRA_INSTALL}"
# The MSM Linux minimal boot image files.
#IMAGE_INSTALL += "alsa-intf"
IMAGE_INSTALL += "avahi-systemd"
IMAGE_INSTALL += "avahi-daemon"
IMAGE_INSTALL += "avahi-dnsconfd"
IMAGE_INSTALL += "avahi-autoipd"
IMAGE_INSTALL += "avahi-utils"
IMAGE_INSTALL += "pimd"
IMAGE_INSTALL += "base-files"
IMAGE_INSTALL += "base-passwd"
#IMAGE_INSTALL += "bridge-utils"
IMAGE_INSTALL += "compat-wireless-ath6kl"
IMAGE_INSTALL += "conntrack-tools"
IMAGE_INSTALL += "data-ipa-cfg-mgr"
IMAGE_INSTALL += "dhcpcd"
IMAGE_INSTALL += "dnsmasq"
IMAGE_INSTALL += "dropbear"
IMAGE_INSTALL += "ebtables"
DEPENDS += "gdb-cross"
IMAGE_INSTALL += "gdbserver"
IMAGE_INSTALL += "glib-2.0"
IMAGE_INSTALL += "hostap-daemon-ath6kl"
# FIXME - This has a conflict with the task-core-boot. You'll probably want to specify
# bbappend-s to things there or come up with a new task set that involves this recipe's
# work.
#IMAGE_INSTALL += "initscripts-msm"
IMAGE_INSTALL += "init-audio"
IMAGE_INSTALL += "iproute2"
IMAGE_INSTALL += "iptables"
IMAGE_INSTALL += "iw"
IMAGE_INSTALL += "jquery"
IMAGE_INSTALL += "jquery-ui"
IMAGE_INSTALL += "kernel-modules"
IMAGE_INSTALL += "libnl"
IMAGE_INSTALL += "libavahi-common"
IMAGE_INSTALL += "libavahi-core"
IMAGE_INSTALL += "libavahi-client"
IMAGE_INSTALL += "libavahi-glib"
IMAGE_INSTALL += "libstdc++"
IMAGE_INSTALL += "libxml2"
IMAGE_INSTALL += "lighttpd"
#IMAGE_INSTALL += "loc-api"
#IMAGE_INSTALL += "minidlna"
#IMAGE_INSTALL += "miniupnpd"
IMAGE_INSTALL += "openssl"
IMAGE_INSTALL += "open-source-kernel-tests"
IMAGE_INSTALL += "powerapp"
IMAGE_INSTALL += "powerapp-powerconfig"
IMAGE_INSTALL += "powerapp-reboot"
IMAGE_INSTALL += "powerapp-shutdown"
IMAGE_INSTALL += "qrngd"
IMAGE_INSTALL += "reboot-daemon"
IMAGE_INSTALL += "rtsp-alg"
IMAGE_INSTALL += "system-core-adbd"
IMAGE_INSTALL += "system-core-usb"
IMAGE_INSTALL += "system-core-liblog"
IMAGE_INSTALL += "system-core-libcutils"
IMAGE_INSTALL += "tcpdump"
IMAGE_INSTALL += "wireless-tools"
IMAGE_INSTALL += "wlan"
#IMAGE_INSTALL += "wpa-supplicant-ath6kl"
IMAGE_INSTALL += "samba"
IMAGE_INSTALL += "uci"
IMAGE_INSTALL += "ubus"
IMAGE_INSTALL += "libubox"
IMAGE_INSTALL += "libghttp"
IMAGE_INSTALL += "tp-domain"
IMAGE_PREPROCESS_COMMAND += "mkdir -p ${IMAGE_ROOTFS}/cache;"
IMAGE_PREPROCESS_COMMAND += "echo ro.build.version.release=`cat ${IMAGE_ROOTFS}/etc/version ` >> ${IMAGE_ROOTFS}/build.prop;"

View File

@ -41,7 +41,7 @@ EXTRA_OECONF = " \
# This list indicate with which size of DDR the smbd needs to be moved to system partition
SMALL_MEMORY_LIST = "1G"
#PRODUCT_MEMORY = "${@base_contains("SMALL_MEMORY_LIST", "${DDR_SIZE}", "_SMALL_MEMORY", "", d)}"
PRODUCT_MEMORY = "${@base_contains("SMALL_MEMORY_LIST", "${DDR_SIZE}", "_SMALL_MEMORY", "", d)}"
do_configure () {
install -m 0755 ${WORKDIR}/armsel-linux.cache ${S}/armsel-linux.cache

View File

@ -1,16 +0,0 @@
# If KERNELRELEASE is defined, we've been invoked from the
# kernel build system and can use its language.
obj-m += tp_domain.o
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) modules_install
.PHONY:clean
clean:
$(MAKE) -C $(KERNEL_SRC) M=$(PWD) clean

View File

@ -1,587 +0,0 @@
/******************************************************************************
*
* Copyright (c) 2010 TP-LINK Technologies CO.,LTD.
* All rights reserved.
*
* FILE NAME : tp_domain.c
* VERSION : 1.0
* DESCRIPTION : tp domain kernel module
*
* AUTHOR : huangwenzhong <huangwenzhong@tp-link.net>
* CREATE DATE: 12/02/2010
*
* HISTORY :
* 01 12/02/2010 huangwenzhong Create.
* 02 18/03/2014 houjihai Modify for 3.4.0 kernel.
*
******************************************************************************/
#include <linux/compiler.h>
#include <linux/sockios.h>
#include <linux/inetdevice.h>
#include <linux/netdevice.h>
#include <linux/types.h>
#include <linux/skbuff.h>
#include <linux/if_ether.h>
#include "tp_domain.h"
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/string.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/workqueue.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/socket.h>
#include <linux/ip.h>
#include <linux/udp.h>
#include <net/sock.h>
#include <net/route.h>
#include <net/ip.h>
#include <net/flow.h>
#include <linux/version.h>
#include <linux/netfilter_bridge.h>
#include <linux/version.h>
#include <linux/random.h>
#include <linux/rculist.h>
#include <linux/jhash.h>
#include <linux/rculist.h>
#include <linux/spinlock.h>
#include <linux/times.h>
#include <linux/etherdevice.h>
#include <asm/atomic.h>
#include <asm/unaligned.h>
#include <linux/inetdevice.h>
#define MAX_LAN_DOMAIN_LEN 64
#ifdef NEED_WLAN_PACKAGE_BCM
#define BR_NAME "br0"
#else
#define BR_NAME "bridge0"
#endif
static __u32 lan_ip = 0xc0a80101;
static char *lan_domain = "tplinklogin.net";
module_param(lan_ip, uint, 0);
module_param(lan_domain, charp, 0);
static char query[MAX_LAN_DOMAIN_LEN];
static char query_www[MAX_LAN_DOMAIN_LEN];
/* marco to compute length of query */
#define DNS_QUERY_LEN(q) (q == NULL ? 0 : (strlen(q) + 1))
#define DNS_DATA_LEN(q) (DNS_QUERY_LEN(q) + 4 + 16)
struct proc_dir_entry *tp_domain_config_entry = NULL;
EXPORT_SYMBOL(tp_domain_config_entry);
int g_rootap_status = 1; /* 1 connect rootap; 0 disconnection rootap */
static struct proc_dir_entry * rootap_status_entry = NULL;
static int rootap_status_entry_read (char *page, char **start, off_t off,
int count, int *eof, void *data)
{
return sprintf (page, "%d\n", g_rootap_status);
}
static int rootap_status_entry_write (struct file *file, const char *buf,
unsigned long count, void *data)
{
u_int32_t val;
if (sscanf(buf, "%d", &val) != 1)
return -EINVAL;
if ((val < 0) || (val > 1))
{
return -EINVAL;
}
g_rootap_status = val;
return count;
}
static int create_tp_domain_config_proc(void)
{
if (tp_domain_config_entry != NULL)
{
printk ("Already have a proc entry for /proc/tp_domain_config!\n");
return -ENOENT;
}
tp_domain_config_entry = proc_mkdir("tp_domain_config", NULL);
if (!tp_domain_config_entry )
{
return -ENOENT;
}
rootap_status_entry = create_proc_entry("rootap_status", 0666, tp_domain_config_entry);
if (!rootap_status_entry )
{
return -ENOENT;
}
rootap_status_entry ->read_proc = rootap_status_entry_read;
rootap_status_entry ->write_proc = rootap_status_entry_write;
return 0;
}
static int remove_tp_domain_config_proc(void)
{
if (!tp_domain_config_entry || !rootap_status_entry)
{
return -ENOENT;
}
remove_proc_entry("rootap_status", tp_domain_config_entry);
remove_proc_entry("tp_domain_config", NULL);
rootap_status_entry = NULL;
tp_domain_config_entry = NULL;
return 0;
}
static void create_domain_query(char *dn_query, char *lan_dn)
{
char *pstr = NULL;
char *tmp = dn_query;
if (!dn_query || !lan_dn)
{
return;
}
strncpy(dn_query + 1, lan_dn, MAX_LAN_DOMAIN_LEN - 1);
pstr = strchr(tmp + 1, '.');
while (pstr) {
*tmp = pstr - tmp - 1;
tmp = pstr;
pstr = strchr(tmp + 1, '.');
}
*tmp = strlen(dn_query) - (tmp - dn_query) - 1;
}
/**
* by dyf, on 19Apr2013, parse domain string to packet matching buf @query.
*/
static void parse_domain(void)
{
unsigned char dn_tmp[MAX_LAN_DOMAIN_LEN] = {0};
create_domain_query(query, lan_domain);
strcpy(dn_tmp, "www.");
strncat(dn_tmp + strlen(dn_tmp), lan_domain, MAX_LAN_DOMAIN_LEN - strlen(dn_tmp));
create_domain_query(query_www, dn_tmp);
}
/******************************************************************************
* FUNCTION : tp_send_dns_packet()
* AUTHOR : huangwenzhong <huangwenzhong@tp-link.net>
* DESCRIPTION : construct and send DNS packet
* INPUT : skb - DNS request
* old_iphdr - DNS request Packet IP header
* old_udphdr - DNS request Packet UDP header
* old_dnshdr - DNS request Packet DNSP header
*
* OUTPUT : N/A
* RETURN : N/A
* OTHERS :
******************************************************************************/
static void tp_send_dns_packet(struct sk_buff *skb ,
struct iphdr *old_iphdr,
struct udphdr *old_udphdr,
DNS_HEADER *old_dnshdr,
unsigned char * skb_payload
)
{
struct sk_buff *dns_skb;
int skb_len;
int data_len;
int dns_query_len = 0;
struct iphdr *new_iphdr; /* DNS Reply Packet IP header */
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31))
struct net_device* br0_dev;
#endif
struct udphdr *new_udphdr;
DNS_HEADER *new_dnshdr;
unsigned char *dns_payload;
unsigned char *tmp;
struct in_device * in_dev = NULL;
__u16 short_val;
__u32 int_val;
struct rtable *rt;
struct flowi4 fl = {
.daddr = old_iphdr->saddr,
};
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
br0_dev = dev_get_by_name(&init_net, BR_NAME);
rt = ip_route_output_key(dev_net(br0_dev), &fl);
in_dev = (struct in_device *)br0_dev->ip_ptr;
dev_put(br0_dev);
#else
ret = ip_route_output_key(&rt, &fl);
#endif
if (IS_ERR(rt))
{
printk("ip_route_output_key() failed in file create_tp_dns_skb.c\r\n");
return;
}
if (g_rootap_status == 1)
{
data_len = DNS_DATA_LEN(skb_payload);
}
else
{
//printk("dns_query_len = %d\n", skb->tail - skb_payload);
dns_query_len = skb->tail - skb_payload;
data_len = dns_query_len + 16;
}
skb_len = ETH_HEADER_LEN + old_iphdr->ihl * 4 +
UDP_HEADER_LEN + DNS_HEADER_LEN + data_len;
dns_skb = alloc_skb(skb_len, GFP_ATOMIC);
if (!dns_skb)
{
return;
}
nf_reset(dns_skb);
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
dns_skb->mark = 0;
#else
dns_skb->nfmark = 0;
#endif
nf_ct_attach(dns_skb, skb); /* needed by NAT */
dns_skb->pkt_type = PACKET_OTHERHOST;
dns_skb->protocol = htons(ETH_P_IP);
dns_skb->ip_summed = CHECKSUM_NONE;
dns_skb->priority = 0;
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
skb_dst_set(dns_skb, &rt->dst);
#else
dns_skb->dst = &rt->u.dst;
#endif
skb_reserve(dns_skb, ETH_HEADER_LEN);
/* create IP header */
new_iphdr = (struct iphdr *)skb_put(dns_skb, sizeof(struct iphdr));
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31))
/* we must specify the network header to avoid kernel panic.
when ip_nat hook was called, it use iphr(skb)to get network header.
by HouXB, 12May11 */
//skb_set_network_header(dns_skb, ETH_HEADER_LEN);
dns_skb->network_header = (sk_buff_data_t)new_iphdr;
#else
dns_skb->nh.iph = new_iphdr;
#endif
memcpy((unsigned char *)new_iphdr, (unsigned char *)old_iphdr, old_iphdr->ihl *4);
new_iphdr->ttl = IP_PACKET_TTL;
new_iphdr->frag_off |= htons(0x4000);
memcpy((unsigned char *)&new_iphdr->saddr,
(unsigned char *)&old_iphdr->daddr, IP_ADDR_LEN);
memcpy((unsigned char *)&new_iphdr->daddr,
(unsigned char *)&old_iphdr->saddr, IP_ADDR_LEN);
ip_select_ident(new_iphdr, &rt->dst, NULL);/* always 0 */
new_iphdr->tot_len = new_iphdr->ihl * 4 + UDP_HEADER_LEN
+ DNS_HEADER_LEN + data_len;
new_iphdr->tot_len = htons(new_iphdr->tot_len);
new_iphdr->check = 0x0000;
new_iphdr->check = ip_fast_csum((unsigned char *)new_iphdr, new_iphdr->ihl);
/* create udp header */
new_udphdr = (struct udphdr *)skb_put(dns_skb, sizeof(struct udphdr));
memcpy((unsigned char *)&new_udphdr->dest,
(unsigned char *)&old_udphdr->source, PORT_LEN);
memcpy((unsigned char *)&new_udphdr->source,
(unsigned char *)&old_udphdr->dest, PORT_LEN);
new_udphdr->len = htons(UDP_HEADER_LEN + DNS_HEADER_LEN + data_len);
new_udphdr->check = 0x0000;
/* create dns header */
new_dnshdr = (DNS_HEADER *)skb_put(dns_skb, sizeof(DNS_HEADER));
memcpy((unsigned char *)&new_dnshdr->transaction_id,
(unsigned char *)&old_dnshdr->transaction_id, sizeof(__u16));
memcpy((unsigned char *)&new_dnshdr->flag,
(unsigned char *)&old_dnshdr->flag, sizeof(__u16));
new_dnshdr->flag |= htons(DNS_RESPONSE_FLAG);
memcpy((unsigned char *)&new_dnshdr->questions,
(unsigned char *)&old_dnshdr->questions, sizeof(__u16));
new_dnshdr->answers_rrs = htons(0x0001);
new_dnshdr->authority_rrs = 0x0000;
new_dnshdr->additional_rrs = 0x0000;
/* create dns questions */
dns_payload = (unsigned char *)skb_put(dns_skb, data_len);
tmp = dns_payload;
if (g_rootap_status == 1 )
{
memcpy(tmp, skb_payload, strlen(skb_payload) + 1);
tmp = tmp + strlen(skb_payload);
*tmp = 0x00;
tmp++;
short_val = htons(DNS_QUERY_TYPE);
memcpy(tmp, &short_val, sizeof(short_val));
tmp += sizeof(short_val);
short_val = htons(DNS_QUERY_CLASS);
memcpy(tmp, &short_val, sizeof(short_val));
}
else
{
memcpy( tmp, skb_payload, dns_query_len-2 );
tmp += skb->tail - skb_payload -2;
}
/* create dns answer */
tmp += sizeof(short_val);
short_val = htons(DNS_RESPONSE_POINTER);
memcpy(tmp, &short_val, sizeof(short_val));
tmp += sizeof(short_val);
short_val = htons(DNS_QUERY_TYPE);
memcpy(tmp, &short_val, sizeof(short_val));
tmp += sizeof(short_val);
short_val = htons(DNS_QUERY_CLASS);
memcpy(tmp, &short_val, sizeof(short_val));
tmp += sizeof(short_val);
int_val = htonl(DNS_ANSWER_TTL);
memcpy(tmp, &int_val, sizeof(int_val));
tmp += sizeof(int_val);
short_val = htons(DNS_RESOURCE_LEN);
memcpy(tmp, &short_val, sizeof(short_val));
tmp += sizeof(short_val);
lan_ip = in_dev->ifa_list->ifa_address;
int_val = lan_ip ;
memcpy(tmp, &int_val, sizeof(int_val));
dst_output(dns_skb);
return;
}
/******************************************************************************
* FUNCTION : tp_dns_handler()
* AUTHOR : huangwenzhong <huangwenzhong@tp-link.net>
* DESCRIPTION : register to FORWARD,
intercept ${lan_domain} DNS request and send Reply packets
* INPUT : N/A
* OUTPUT : N/A
* RETURN : N/A
* OTHERS :
******************************************************************************/
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
static unsigned int tp_dns_handler(unsigned int hooknum,
struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *pskb = skb;
struct iphdr *iph = ip_hdr(pskb);
#else
static unsigned int tp_dns_handler(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
struct sk_buff *pskb = *skb;
struct iphdr *iph;
#endif
struct udphdr *udp_hdr;
DNS_HEADER *dns_hdr;
unsigned char * dns_payload;
unsigned char * tmp;
unsigned int dns_query_len;
__u16 dport;
__u16 query_type;
int ret;
if (ETH_P_IP != htons(pskb->protocol)) /* not IP packets */
{
return NF_ACCEPT;
}
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
/* nothing */
#else
iph = pskb->nh.iph;
#endif
if ( NULL == iph || 4 != iph->version)/* not IPv4 packets */
{
return NF_ACCEPT;
}
if (IPPROTO_UDP != iph->protocol) /* not UDP packets */
{
return NF_ACCEPT;
}
udp_hdr = (struct udphdr *)((unsigned char *)iph + iph->ihl * 4);
if ( NULL == udp_hdr )
{
return NF_ACCEPT;
}
dport = udp_hdr->dest;
dport = ntohs(dport);
if (DOMAIN_PORT != dport) /* not dns request packet */
{
return NF_ACCEPT;
}
dns_hdr = (DNS_HEADER *)((unsigned char *)udp_hdr + UDP_HEADER_LEN);
if ( NULL == dns_hdr)
{
return NF_ACCEPT;
}
if ((ntohs(dns_hdr->flag) & DNS_RESPONSE_PACKET)) /* not dns request? */
{
return NF_ACCEPT;
}
dns_payload = (unsigned char *)((unsigned char *)dns_hdr + DNS_HEADER_LEN);
if ( NULL == dns_payload )
{
return NF_ACCEPT;
}
if (g_rootap_status == 1)
{
dns_query_len = DNS_QUERY_LEN(query);
ret = memcmp(dns_payload, query, dns_query_len);
if ( 0 == ret )
{
tmp = dns_payload + dns_query_len;
}
else
{
/* TODO: match www.[tp-domain-name] */
dns_query_len = DNS_QUERY_LEN(query_www);
ret = memcmp(dns_payload, query_www, dns_query_len);
if (0 == ret)
{
tmp = dns_payload + dns_query_len;
}
else
{
return NF_ACCEPT;
}
}
memcpy(&query_type, tmp, sizeof(query_type));
query_type = ntohs(query_type);
if (DNS_QUERY_TYPE != query_type && DNS_QUERY_TYPE_AAAA != query_type) /* is query type not A? */
{
return NF_ACCEPT;
}
tp_send_dns_packet( pskb, iph, udp_hdr, dns_hdr, dns_payload);
return NF_DROP;
}
else
{
dns_payload = ( unsigned char * )( ( unsigned char * )dns_hdr + DNS_HEADER_LEN );
tp_send_dns_packet( skb, iph, udp_hdr, dns_hdr, dns_payload);
return NF_DROP;
}
}
static struct nf_hook_ops tp_dns_forward_hook_ops = {
.hook = tp_dns_handler,
.owner = THIS_MODULE,
.pf = PF_BRIDGE,
.hooknum = NF_BR_FORWARD,
.priority = NF_BR_PRI_FIRST,
};
static struct nf_hook_ops tp_dns_localin_hook_ops = {
.hook = tp_dns_handler,
.owner = THIS_MODULE,
.pf = PF_BRIDGE,
.hooknum = NF_BR_LOCAL_IN,
.priority = NF_BR_PRI_FIRST,
};
static int __init dns_init(void)
{
int ret;
create_tp_domain_config_proc();
/* parse domain string at module init */
parse_domain();
ret = nf_register_hook( &tp_dns_forward_hook_ops );
if (ret < 0)
{
return ret;
}
ret = nf_register_hook( &tp_dns_localin_hook_ops );
if ( ret < 0 )
{
return ret;
}
return 0;
}
static void __exit dns_exit(void)
{
nf_unregister_hook( &tp_dns_forward_hook_ops );
nf_unregister_hook( &tp_dns_localin_hook_ops );
remove_tp_domain_config_proc();
}
module_init(dns_init);
module_exit(dns_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Huang Wenzhong <huangwenzhong@tp-link.net>");
MODULE_DESCRIPTION("The domain name tplinklogin.net for web page manage.");
/* by HouXB, 12May11 */
MODULE_ALIAS("tp_domain");

View File

@ -1,53 +0,0 @@
/******************************************************************************
*
* Copyright (c) 2009 TP-LINK Technologies CO.,LTD.
* All rights reserved.
*
* FILE NAME : tp_domain.h
* VERSION : 1.0
* DESCRIPTION: tp domain kernel module
*
* AUTHOR : huangwenzhong <huangwenzhong@tp-link.net>
* CREATE DATE: 11/30/2010
*
* HISTORY :
* 01 11/30/2010 huangwenzhong Create.
*
******************************************************************************/
#ifndef _TP_DOMAIN_H
#define _TP_DOMAIN_H
#define DOMAIN_PORT 53
#define ETH_HEADER_LEN (2 + 14)
#define IP_PACKET_TTL 128
//#define DNS_ANSWER_TTL ( 2 * 24 * 60 *60 )
#define DNS_ANSWER_TTL 0
#define IP_ADDR_LEN sizeof(__u32)
#define PORT_LEN sizeof(__u16)
#define UDP_HEADER_LEN sizeof(struct udphdr)
#define DNS_HEADER_LEN sizeof(DNS_HEADER)
#define DNS_RESPONSE_PACKET (0x8000) /* response packet flag */
#define DNS_QUERY_TYPE (0x0001) /* query type,type A */
#define DNS_QUERY_TYPE_AAAA ( 0x001c ) /* query type,type AAAA */
#define DNS_QUERY_CLASS (0x0001) /* query class,clase internet */
#define DNS_RESPONSE_FLAG (0x8080) /* response flag value */
#define DNS_RESPONSE_POINTER (0xc00c) /* response field pointer */
#define DNS_RESOURCE_LEN (0x0004) /* response field IP length */
/* DNS<4E><53><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD>ṹ.added by huangwenzhong. 11/30/2010. */
typedef struct
{
__u16 transaction_id;
__u16 flag;
__u16 questions;
__u16 answers_rrs;
__u16 authority_rrs;
__u16 additional_rrs;
}__attribute__ ((__packed__))DNS_HEADER;
#endif

View File

@ -1,17 +0,0 @@
DESCRIPTION = "tplink domain kernel module."
LICENSE = "CLOSED"
inherit module
PR = r1
# Broadcom chip support
EXTRA_OEMAKE += "${@base_conditional('TP_NEED_WLAN_MODULE_BCM', 'y', 'CFLAGS+=-DNEED_WLAN_PACKAGE_BCM', ' ', d)}"
SRC_URI = "file://Makefile \
file://tp_domain.c \
file://tp_domain.h \
"
S = "${WORKDIR}"

View File

@ -1,17 +0,0 @@
DESCRIPTION = "tplink domain kernel module."
LICENSE = "CLOSED"
inherit module
PR = r1
# Broadcom chip support
EXTRA_OEMAKE += "${@base_conditional('TP_NEED_WLAN_MODULE_BCM', 'y', 'CFLAGS+=-DNEED_WLAN_PACKAGE_BCM', ' ', d)}"
SRC_URI = "file://Makefile \
file://tp_domain.c \
file://tp_domain.h \
"
S = "${WORKDIR}"