From e9b63ad24536b3cd6e0b2721f2596e1bf9bccab7 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Fri, 21 Aug 2020 15:58:55 +0800
Subject: [PATCH] Add pppd build shell script and patches

---
 3rdparty/pppd/patch/ppp-2.4.7.patch |  154 ++++++++++++++++++++++++++++++
 3rdparty/pppd/build.sh              |  114 ++++++++++++++++++++++
 2 files changed, 268 insertions(+), 0 deletions(-)

diff --git a/3rdparty/pppd/build.sh b/3rdparty/pppd/build.sh
new file mode 100755
index 0000000..040d3b8
--- /dev/null
+++ b/3rdparty/pppd/build.sh
@@ -0,0 +1,114 @@
+#!/bin/bash
+
+#+--------------------------------------------------------------------------------------------
+#|Description:  This shell script used download and compile pppd for ARM
+#|     Author:  GuoWenxue <guowenxue@gmail.com>
+#|  ChangeLog:
+#|           1, Initialize 1.0.0 on 2011.04.12
+#+--------------------------------------------------------------------------------------------
+
+PREFIX_PATH=`pwd`/../install/bin
+
+LYFTP_SRC=ftp://master.iot-yun.club/src/
+
+CROSSTOOL=/opt/xtools/arm920t/bin/arm-linux-
+
+SYSROOT=`${CROSSTOOL}gcc -print-sysroot`
+
+function msg_banner()
+{
+    echo ""
+    echo "+-----------------------------------------------------------------------"
+    echo "|  $1 "
+    echo "+-----------------------------------------------------------------------"
+    echo ""
+}
+
+function check_result()
+{
+    if [ $? != 0 ] ; then
+       echo ""
+       echo "+-----------------------------------------------------------------------"
+       echo "|  $1 "
+       echo "+-----------------------------------------------------------------------"
+       echo ""
+       exit ;
+    fi
+}
+
+function export_cross()
+{
+    # export cross toolchain
+    export CC=${CROSSTOOL}gcc
+    export AS=${CROSSTOOL}as
+    export AR=${CROSSTOOL}ar
+    export LD=${CROSSTOOL}ld
+    export NM=${CROSSTOOL}nm
+    export RANLIB=${CROSSTOOL}ranlib
+    export OBJDUMP=${CROSSTOOL}objdump
+    export STRIP=${CROSSTOOL}strip
+
+    # export cross configure 
+    export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
+
+    # Clear LDFLAGS and CFLAGS
+    export LDFLAGS=
+    export CFLAGS=
+}
+
+function compile_pppd()
+{
+    SRC_NAME=ppp-2.4.7
+    PACK_SUFIX=tar.gz
+
+    if [ -f ${PREFIX_PATH}/pppd ] ; then
+        msg_banner "$SRC_NAME already compile and installed"
+        return 0;
+    fi
+
+    msg_banner "Start cross compile $SRC_NAME "
+
+    if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
+        #wget https://download.samba.org/pub/ppp/${SRC_NAME}.${PACK_SUFIX}
+        wget ${LYFTP_SRC}/${SRC_NAME}.${PACK_SUFIX}
+        check_result "ERROR: download ${SRC_NAME} failure"
+    fi
+
+    rm -rf ${SRC_NAME}
+    tar -xzf ${SRC_NAME}.${PACK_SUFIX}
+
+    cd ${SRC_NAME}
+    patch -p1 < ../patch/${SRC_NAME}.patch
+
+    sed -i -e "s|.*CC = .*|CC=${CROSSTOOL}gcc|g" pppd/Makefile.linux
+    sed -i -e "s|^OPENSSL_INCLUDE_DIR=.*|OPENSSL_INCLUDE_DIR=${PREFIX_PATH}/../include|g" pppd/Makefile.linux
+    sed -i -e "s|.*-Wl,-E*|LDFLAGS += -L${PREFIX_PATH}/../lib -Wl,-E|g" pppd/Makefile.linux
+    sed -i -e "s|.*CC = .*|CC=${CROSSTOOL}gcc|g" chat/Makefile.linux
+
+    cd pppd 
+        export LDFLAGS=${LDFLAGS} && make CC="${CROSSTOOL}gcc " -f Makefile.linux && ${CROSSTOOL}strip pppd 
+        check_result "ERROR: compile ${SRC_NAME} pppd failure"
+        cp pppd ../../
+    cd -
+
+    cd  chat
+        make CC="${CROSSTOOL}gcc " -f Makefile.linux && ${CROSSTOOL}strip chat
+        check_result "ERROR: compile ${SRC_NAME} chat failure"
+        cp chat ../..
+    cd -
+
+    check_result "ERROR: compile ${SRC_NAME} failure"
+
+    cd ..
+
+    cp pppd chat ${PREFIX_PATH} 
+
+    cd -
+}
+
+
+export_cross
+
+compile_pppd
+
+
diff --git a/3rdparty/pppd/patch/ppp-2.4.7.patch b/3rdparty/pppd/patch/ppp-2.4.7.patch
new file mode 100644
index 0000000..27fa4e7
--- /dev/null
+++ b/3rdparty/pppd/patch/ppp-2.4.7.patch
@@ -0,0 +1,154 @@
+diff -Nuar ppp-2.4.7/chat/Makefile.linux ppp-2.4.7-fixed/chat/Makefile.linux
+--- ppp-2.4.7/chat/Makefile.linux	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/chat/Makefile.linux	2020-08-21 15:40:14.504792847 +0800
+@@ -21,7 +21,7 @@
+ 	$(CC) -o chat chat.o
+ 
+ chat.o:	chat.c
+-	$(CC) -c $(CFLAGS) -o chat.o chat.c
++	$(CC) -c $(CFLAGS) -static -o chat.o chat.c
+ 
+ install: chat
+ 	mkdir -p $(BINDIR) $(MANDIR)
+diff -Nuar ppp-2.4.7/pppd/auth.c ppp-2.4.7-fixed/pppd/auth.c
+--- ppp-2.4.7/pppd/auth.c	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/pppd/auth.c	2020-08-21 15:40:14.500792847 +0800
+@@ -1322,7 +1322,8 @@
+     int hadchap;
+ 
+     hadchap = -1;
+-    ao->neg_upap = !refuse_pap && (passwd[0] != 0 || get_pap_passwd(NULL));
++    /* modify by guowenxue, add don't set passwd support */
++    ao->neg_upap = !refuse_pap; // && (passwd[0] != 0 || get_pap_passwd(NULL));
+     ao->neg_chap = (!refuse_chap || !refuse_mschap || !refuse_mschap_v2)
+ 	&& (passwd[0] != 0 ||
+ 	    (hadchap = have_chap_secret(user, (explicit_remote? remote_name:
+diff -Nuar ppp-2.4.7/pppd/Makefile.linux ppp-2.4.7-fixed/pppd/Makefile.linux
+--- ppp-2.4.7/pppd/Makefile.linux	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/pppd/Makefile.linux	2020-08-21 15:40:14.504792847 +0800
+@@ -30,15 +30,15 @@
+ include .depend
+ endif
+ 
+-# CC = gcc
++CC=/opt/xtools/arm920t/bin/arm-linux-gcc
+ #
+ COPTS = -O2 -pipe -Wall -g
+-LIBS =
++LIBS = -lpthread
+ 
+-# Uncomment the next 2 lines to include support for Microsoft's
++# Uncomment the next line to include support for Microsoft's
+ # MS-CHAP authentication protocol.  Also, edit plugins/radius/Makefile.linux.
+ CHAPMS=y
+-USE_CRYPT=y
++#USE_CRYPT=y
+ # Don't use MSLANMAN unless you really know what you're doing.
+ #MSLANMAN=y
+ # Uncomment the next line to include support for MPPE.  CHAPMS (above) must
+@@ -79,6 +79,7 @@
+ MAXOCTETS=y
+ 
+ INCLUDE_DIRS= -I../include
++OPENSSL_INCLUDE_DIR=/home/guowenxue/fl2440/3rdparty/pppd/../install/bin/../include
+ 
+ COMPILE_FLAGS= -DHAVE_PATHS_H -DIPX_CHANGE -DHAVE_MMAP
+ 
+@@ -132,7 +133,8 @@
+ 
+ ifdef NEEDDES
+ ifndef USE_CRYPT
+-LIBS     += -ldes $(LIBS)
++CFLAGS   += -I$(OPENSSL_INCLUDE_DIR)
++LIBS     += -lcrypto -lpthread
+ else
+ CFLAGS   += -DUSE_CRYPT=1
+ endif
+diff -Nuar ppp-2.4.7/pppd/plugins/rp-pppoe/pppoe.h ppp-2.4.7-fixed/pppd/plugins/rp-pppoe/pppoe.h
+--- ppp-2.4.7/pppd/plugins/rp-pppoe/pppoe.h	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/pppd/plugins/rp-pppoe/pppoe.h	2020-08-21 15:40:14.500792847 +0800
+@@ -47,6 +47,8 @@
+ #include <sys/socket.h>
+ #endif
+ 
++#include <netinet/in.h>
++
+ /* Ugly header files on some Linux boxes... */
+ #if defined(HAVE_LINUX_IF_H)
+ #include <linux/if.h>
+@@ -84,8 +86,6 @@
+ #include <linux/if_ether.h>
+ #endif
+ 
+-#include <netinet/in.h>
+-
+ #ifdef HAVE_NETINET_IF_ETHER_H
+ #include <sys/types.h>
+ 
+diff -Nuar ppp-2.4.7/pppd/pppcrypt.c ppp-2.4.7-fixed/pppd/pppcrypt.c
+--- ppp-2.4.7/pppd/pppcrypt.c	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/pppd/pppcrypt.c	2020-08-21 15:40:14.500792847 +0800
+@@ -64,7 +64,7 @@
+ 	des_key[7] = Get7Bits(key, 49);
+ 
+ #ifndef USE_CRYPT
+-	des_set_odd_parity((des_cblock *)des_key);
++	DES_set_odd_parity((DES_cblock *)des_key);
+ #endif
+ }
+ 
+@@ -158,25 +158,25 @@
+ }
+ 
+ #else /* USE_CRYPT */
+-static des_key_schedule	key_schedule;
++static DES_key_schedule	key_schedule;
+ 
+ bool
+ DesSetkey(key)
+ u_char *key;
+ {
+-	des_cblock des_key;
++	DES_cblock des_key;
+ 	MakeKey(key, des_key);
+-	des_set_key(&des_key, key_schedule);
++	DES_set_key(&des_key, &key_schedule);
+ 	return (1);
+ }
+ 
+ bool
+-DesEncrypt(clear, key, cipher)
++DesEncrypt(clear, cipher)
+ u_char *clear;	/* IN  8 octets */
+ u_char *cipher;	/* OUT 8 octets */
+ {
+-	des_ecb_encrypt((des_cblock *)clear, (des_cblock *)cipher,
+-	    key_schedule, 1);
++	DES_ecb_encrypt((DES_cblock *)clear, (DES_cblock *)cipher,
++	    &key_schedule, 1);
+ 	return (1);
+ }
+ 
+@@ -185,8 +185,8 @@
+ u_char *cipher;	/* IN  8 octets */
+ u_char *clear;	/* OUT 8 octets */
+ {
+-	des_ecb_encrypt((des_cblock *)cipher, (des_cblock *)clear,
+-	    key_schedule, 0);
++	DES_ecb_encrypt((DES_cblock *)cipher, (DES_cblock *)clear,
++	    &key_schedule, 0);
+ 	return (1);
+ }
+ 
+diff -Nuar ppp-2.4.7/pppd/pppcrypt.h ppp-2.4.7-fixed/pppd/pppcrypt.h
+--- ppp-2.4.7/pppd/pppcrypt.h	2014-08-09 20:31:39.000000000 +0800
++++ ppp-2.4.7-fixed/pppd/pppcrypt.h	2020-08-21 15:42:19.676795248 +0800
+@@ -38,7 +38,7 @@
+ #endif
+ 
+ #ifndef USE_CRYPT
+-#include <des.h>
++#include <openssl/des.h>
+ #endif
+ 
+ extern bool	DesSetkey __P((u_char *));

--
Gitblit v1.9.1