### this file is sourced not run
PKGVER=2.6
PKGBUILD=1
PKGARCH=x86_64

# source: james
TARBALL=hostapd-$PKGVER.tar.gz
MD5SUM=eaa56dce9bd8f1d195eb62596eab34c7
SRC_URL=http://w1.fi/releases/$TARBALL
BUNDLE=

SLACKREQ='libnl openssl'
SLACKDESC="hostapd-rtl: hostapd-rtl $PKGVER (hostapd for realtek wifi)
hostapd-rtl: 
hostapd-rtl: This is a special patched version of hostapd built to work with 
hostapd-rtl: certain realtek wifi chips. 8188eu/8188ee/8192 is known to work. 
hostapd-rtl: For this to work, you need to use realtek original driver; 
hostapd-rtl: not the one included in the Linux kernel.
hostapd-rtl: This also contains drivers for others chips, but it is not known
hostapd-rtl: how well they behave with this version of hostapd.
hostapd-rtl: 
hostapd-rtl: https://github.com/pritambaral/hostapd-rtl871xdrv
hostapd-rtl: http://w1.fi/hostapd/  
"

### default pkg_download
### prepare
pkg_prepare() {
	pkg_prepare_default &&
	cd tmp/hostapd* &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0001-hostapd-Avoid-key-reinstallation-in-FT-handshake.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0002-Prevent-reinstallation-of-an-already-in-use-group-ke.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0003-Extend-protection-of-GTK-IGTK-reinstallation-of-WNM-.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0004-Prevent-installation-of-an-all-zero-TK.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0005-Fix-PTK-rekeying-to-generate-a-new-ANonce.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0006-TDLS-Reject-TPK-TK-reconfiguration.patch &&
	# This one's for wpa_supplicant...
	#patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0007-WNM-Ignore-WNM-Sleep-Mode-Response-without-pending-r.patch &&
	patch -Np1 -i $CHROOT_DIR/tmp/pkg/rebased-v2.6-0008-FT-Do-not-allow-multiple-Reassociation-Response-fram.patch
}
### default pkg_package
### build
pkg_build() {
	# apply patch
	cd /tmp/hostapd* &&
	patch -Np1 -i /tmp/pkg/hostapd-rtl*/rtlxdrv.patch &&
	
	# build
	cd /tmp/hostapd*/hostapd &&
	
	# our config is defconfig + wired, LIBNL32, radius server, 80211n, and fully dynamic vlan
	cp defconfig .config &&
	sed -i -e '
		s/#CONFIG_DRIVER_WIRED/CONFIG_DRIVER_WIRED/;
		s/#CONFIG_LIBNL32/CONFIG_LIBNL32/;
		s/#CONFIG_RADIUS_SERVER/CONFIG_RADIUS_SERVER/;
		s/#CONFIG_IEEE80211N/CONFIG_IEEE80211N/;
		s/#CONFIG_FULL_DYNAMIC_VLAN/CONFIG_FULL_DYNAMIC_VLAN/;
		' .config &&
	echo "CONFIG_DRIVER_RTW=y" >> .config && # add support for rtl871xdrv
	
	make $MAKEFLAGS &&
	install -m755 hostapd /usr/sbin/hostapd-rtl &&
	install -m755 hostapd_cli /usr/bin/hostapd-rtl_cli &&
	install -m644 hostapd.8 /usr/share/man/man8/hostapd-rtl.8 &&
	install -m644 hostapd_cli.1 /usr/share/man/man1/hostapd-rtl_cli.1 &&
	
	mkdir -p /usr/share/hostapd-rtl/samples &&
	cp README /usr/share/hostapd-rtl &&
	cp hostapd.accept hostapd.conf hostapd.deny hostapd.eap_user \
	   hostapd.radius_clients hostapd.vlan hostapd.wpa_psk wired.conf \
	   /usr/share/hostapd-rtl/samples &&
	 
	install -m644 /tmp/pkg/hostapd-rtl871xdrv.conf /usr/share/hostapd-rtl/samples/ &&
	pkg_build_slackdesc
}


