From 46a6e7cab8d70c922129b1d7ce38d577e5e0f445 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Sat, 6 Nov 2010 18:45:02 +0000
Subject: ndiswrapper: recompile for new kernel .36 ref #574 ref #647

---
 abs/core/ndiswrapper/PKGBUILD                      |  25 +++--
 abs/core/ndiswrapper/kernel-2.6.27.patch           | 116 ---------------------
 abs/core/ndiswrapper/kernel-2.6.35.patch           |  98 +++++++++++++++++
 abs/core/ndiswrapper/kernel-2.6.36.patch           |  27 +++++
 .../ndiswrapper/ndiswrapper-CVE-2008-4395.patch    |  86 ---------------
 abs/core/ndiswrapper/ndiswrapper.install           |   6 +-
 6 files changed, 143 insertions(+), 215 deletions(-)
 delete mode 100644 abs/core/ndiswrapper/kernel-2.6.27.patch
 create mode 100644 abs/core/ndiswrapper/kernel-2.6.35.patch
 create mode 100644 abs/core/ndiswrapper/kernel-2.6.36.patch
 delete mode 100644 abs/core/ndiswrapper/ndiswrapper-CVE-2008-4395.patch

diff --git a/abs/core/ndiswrapper/PKGBUILD b/abs/core/ndiswrapper/PKGBUILD
index b6662fb..f99c158 100644
--- a/abs/core/ndiswrapper/PKGBUILD
+++ b/abs/core/ndiswrapper/PKGBUILD
@@ -1,25 +1,27 @@
-#$Id: PKGBUILD 80412 2010-05-17 07:56:55Z tpowa $
+#$Id: PKGBUILD 96979 2010-10-25 20:35:44Z tpowa $
 #Maintainer: Tobias Powalowski <tpowa@archlinux.org>
 
 pkgname=ndiswrapper
-_kernver=2.6.34-LinHES
+_kernver=2.6.36-LinHES
 pkgver=1.56
-pkgrel=3
+pkgrel=6
 pkgdesc="Module for NDIS (Windows Network Drivers) drivers supplied by vendors. For stock arch 2.6 kernel."
 license=('GPL')
 arch=(i686 x86_64)
 url="http://ndiswrapper.sourceforge.net"
 install="ndiswrapper.install"
-depends=("ndiswrapper-utils=$pkgver" 'kernel26>=2.6.34' 'kernel26<2.6.35')
-makedepends=('kernel26-headers>=2.6.34' 'kernel26-headers<2.6.35')
-source=(http://downloads.sourceforge.net/sourceforge/ndiswrapper/ndiswrapper-$pkgver.tar.gz)
-md5sums=('1431f7ed5f8e92e752d330bbb3aed333')
-
+depends=("ndiswrapper-utils=$pkgver" 'kernel26>=2.6.36' 'kernel26<2.6.37')
+makedepends=('kernel26-headers>=2.6.36' 'kernel26-headers<2.6.37')
+source=(http://downloads.sourceforge.net/sourceforge/ndiswrapper/ndiswrapper-$pkgver.tar.gz
+        kernel-2.6.35.patch
+        kernel-2.6.36.patch)
 build()
 {
   cd $srcdir/ndiswrapper-$pkgver/driver
-  make KVERS=$_kernver || return 1
-  make DESTDIR=$pkgdir KVERS=$_kernver install || return 1
+  patch -Np2 -i $startdir/kernel-2.6.35.patch
+  patch -Np2 -i $startdir/kernel-2.6.36.patch
+  make KVERS=$_kernver
+  make DESTDIR=$pkgdir KVERS=$_kernver install
   rm $pkgdir/lib/modules/$_kernver/modules.* #wtf?
 
   sed -i -e "s/KERNEL_VERSION='.*'/KERNEL_VERSION='${_kernver}'/" $startdir/*.install
@@ -29,3 +31,6 @@ build()
   rm -r $pkgdir/lib/modules/$_kernver/misc/
 }
 
+md5sums=('1431f7ed5f8e92e752d330bbb3aed333'
+         '0a03d613b1fd545a75c5dd1a7c2aaec4'
+         'cc16ed13449f17e90865df688b180b2c')
diff --git a/abs/core/ndiswrapper/kernel-2.6.27.patch b/abs/core/ndiswrapper/kernel-2.6.27.patch
deleted file mode 100644
index 522dfe9..0000000
--- a/abs/core/ndiswrapper/kernel-2.6.27.patch
+++ /dev/null
@@ -1,116 +0,0 @@
-diff -aur driver.old/iw_ndis.c driver/iw_ndis.c
---- driver.old/iw_ndis.c	2008-08-04 21:10:16.000000000 +0200
-+++ driver/iw_ndis.c	2008-08-04 21:30:12.000000000 +0200
-@@ -1015,7 +1015,7 @@
- 	return 0;
- }
- 
--static char *ndis_translate_scan(struct net_device *dev, char *event,
-+static char *ndis_translate_scan(struct net_device *dev, struct iw_request_info *info, char *event,
- 				 char *end_buf, void *item)
- {
- 	struct iw_event iwe;
-@@ -1034,7 +1034,7 @@
- 	iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
- 	iwe.len = IW_EV_ADDR_LEN;
- 	memcpy(iwe.u.ap_addr.sa_data, bssid->mac, ETH_ALEN);
--	event = iwe_stream_add_event(event, end_buf, &iwe, IW_EV_ADDR_LEN);
-+	event = iwe_stream_add_event(info, event, end_buf, &iwe, IW_EV_ADDR_LEN);
- 
- 	/* add essid */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1044,13 +1044,13 @@
- 		iwe.u.data.length = IW_ESSID_MAX_SIZE;
- 	iwe.u.data.flags = 1;
- 	iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
--	event = iwe_stream_add_point(event, end_buf, &iwe, bssid->ssid.essid);
-+	event = iwe_stream_add_point(info, event, end_buf, &iwe, bssid->ssid.essid);
- 
- 	/* add protocol name */
- 	memset(&iwe, 0, sizeof(iwe));
- 	iwe.cmd = SIOCGIWNAME;
- 	strncpy(iwe.u.name, network_type_to_name(bssid->net_type), IFNAMSIZ);
--	event = iwe_stream_add_event(event, end_buf, &iwe, IW_EV_CHAR_LEN);
-+	event = iwe_stream_add_event(info, event, end_buf, &iwe, IW_EV_CHAR_LEN);
- 
- 	/* add mode */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1061,7 +1061,7 @@
- 		iwe.u.mode = IW_MODE_INFRA;
- 	else // if (bssid->mode == Ndis802_11AutoUnknown)
- 		iwe.u.mode = IW_MODE_AUTO;
--	event = iwe_stream_add_event(event, end_buf, &iwe, IW_EV_UINT_LEN);
-+	event = iwe_stream_add_event(info, event, end_buf, &iwe, IW_EV_UINT_LEN);
- 
- 	/* add freq */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1076,7 +1076,7 @@
- 	/* convert from kHz to Hz */
- 	iwe.u.freq.e += 3;
- 	iwe.len = IW_EV_FREQ_LEN;
--	event = iwe_stream_add_event(event, end_buf, &iwe, IW_EV_FREQ_LEN);
-+	event = iwe_stream_add_event(info, event, end_buf, &iwe, IW_EV_FREQ_LEN);
- 
- 	/* add qual */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1090,7 +1090,7 @@
- 	iwe.u.qual.noise = WL_NOISE;
- 	iwe.u.qual.qual  = i;
- 	iwe.len = IW_EV_QUAL_LEN;
--	event = iwe_stream_add_event(event, end_buf, &iwe, IW_EV_QUAL_LEN);
-+	event = iwe_stream_add_event(info, event, end_buf, &iwe, IW_EV_QUAL_LEN);
- 
- 	/* add key info */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1101,7 +1101,7 @@
- 		iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
- 	iwe.u.data.length = 0;
- 	iwe.len = IW_EV_POINT_LEN;
--	event = iwe_stream_add_point(event, end_buf, &iwe, bssid->ssid.essid);
-+	event = iwe_stream_add_point(info, event, end_buf, &iwe, bssid->ssid.essid);
- 
- 	/* add rate */
- 	memset(&iwe, 0, sizeof(iwe));
-@@ -1115,7 +1115,7 @@
- 		if (bssid->rates[i] & 0x7f) {
- 			iwe.u.bitrate.value = ((bssid->rates[i] & 0x7f) *
- 					       500000);
--			current_val = iwe_stream_add_value(event, current_val,
-+			current_val = iwe_stream_add_value(info, event, current_val,
- 							   end_buf, &iwe,
- 							   IW_EV_PARAM_LEN);
- 		}
-@@ -1128,13 +1128,13 @@
- 	iwe.cmd = IWEVCUSTOM;
- 	sprintf(buf, "bcn_int=%d", bssid->config.beacon_period);
- 	iwe.u.data.length = strlen(buf);
--	event = iwe_stream_add_point(event, end_buf, &iwe, buf);
-+	event = iwe_stream_add_point(info, event, end_buf, &iwe, buf);
- 
- 	memset(&iwe, 0, sizeof(iwe));
- 	iwe.cmd = IWEVCUSTOM;
- 	sprintf(buf, "atim=%u", bssid->config.atim_window);
- 	iwe.u.data.length = strlen(buf);
--	event = iwe_stream_add_point(event, end_buf, &iwe, buf);
-+	event = iwe_stream_add_point(info, event, end_buf, &iwe, buf);
- 
- 	TRACE2("%d, %u", bssid->length, (unsigned int)sizeof(*bssid));
- 	if (bssid->length > sizeof(*bssid)) {
-@@ -1155,7 +1155,7 @@
- 				memset(&iwe, 0, sizeof(iwe));
- 				iwe.cmd = IWEVGENIE;
- 				iwe.u.data.length = ielen;
--				event = iwe_stream_add_point(event, end_buf,
-+				event = iwe_stream_add_point(info, event, end_buf,
- 							     &iwe, iep);
- 			}
- 			iep += ielen;
-@@ -1236,7 +1236,7 @@
- 	TRACE2("%d", bssid_list->num_items);
- 	cur_item = &bssid_list->bssid[0];
- 	for (i = 0; i < bssid_list->num_items; i++) {
--		event = ndis_translate_scan(dev, event,
-+		event = ndis_translate_scan(dev, info, event,
- 					    extra + IW_SCAN_MAX_DATA, cur_item);
- 		cur_item = (struct ndis_wlan_bssid *)((char *)cur_item +
- 						      cur_item->length);    
diff --git a/abs/core/ndiswrapper/kernel-2.6.35.patch b/abs/core/ndiswrapper/kernel-2.6.35.patch
new file mode 100644
index 0000000..1cfdab2
--- /dev/null
+++ b/abs/core/ndiswrapper/kernel-2.6.35.patch
@@ -0,0 +1,98 @@
+diff -uNr ndiswrapper-1.56.old/driver/usb.c ndiswrapper-1.56/driver/usb.c
+--- ndiswrapper-1.56.old/driver/usb.c	2010-02-10 18:09:32.000000000 -0800
++++ ndiswrapper-1.56/driver/usb.c	2010-07-25 02:29:25.442145846 -0700
+@@ -191,9 +191,15 @@
+ 	if (wrap_urb->flags & WRAP_URB_COPY_BUFFER) {
+ 		USBTRACE("freeing DMA buffer for URB: %p %p",
+ 			 urb, urb->transfer_buffer);
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
+ 		usb_buffer_free(IRP_WRAP_DEVICE(irp)->usb.udev,
++                                urb->transfer_buffer_length,
++                                urb->transfer_buffer, urb->transfer_dma);
++#else
++		usb_free_coherent(IRP_WRAP_DEVICE(irp)->usb.udev,
+ 				urb->transfer_buffer_length,
+ 				urb->transfer_buffer, urb->transfer_dma);
++#endif
+ 	}
+ 	if (urb->setup_packet)
+ 		kfree(urb->setup_packet);
+@@ -303,9 +309,16 @@
+ 			       || PageHighMem(virt_to_page(buf))
+ #endif
+ 		    )) {
++
++#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
+ 		urb->transfer_buffer =
+-			usb_buffer_alloc(wd->usb.udev, buf_len, alloc_flags,
++                        usb_buffer_alloc(wd->usb.udev, buf_len, alloc_flags,
++                                         &urb->transfer_dma);
++#else
++		urb->transfer_buffer =
++			usb_alloc_coherent(wd->usb.udev, buf_len, alloc_flags,
+ 					 &urb->transfer_dma);
++#endif
+ 		if (!urb->transfer_buffer) {
+ 			WARNING("couldn't allocate dma buf");
+ 			IoAcquireCancelSpinLock(&irp->cancel_irql);
+diff -uNr ndiswrapper-1.56.old/driver/wrapndis.c ndiswrapper-1.56/driver/wrapndis.c
+--- ndiswrapper-1.56.old/driver/wrapndis.c	2010-02-10 18:09:32.000000000 -0800
++++ ndiswrapper-1.56/driver/wrapndis.c	2010-07-25 02:06:13.184631757 -0700
+@@ -936,6 +936,10 @@
+ 	EXIT2(return);
+ }
+ 
++#ifndef netdev_mc_count
++#define netdev_mc_count(net_dev) net_dev->mc_count
++#endif
++
+ static void set_multicast_list(struct ndis_device *wnd)
+ {
+ 	struct net_device *net_dev;
+@@ -950,20 +954,26 @@
+ 		packet_filter |= NDIS_PACKET_TYPE_PROMISCUOUS |
+ 			NDIS_PACKET_TYPE_ALL_LOCAL;
+ 	} else if (net_dev->flags & IFF_ALLMULTI ||
+-		   net_dev->mc_count > wnd->multicast_size) {
++		   netdev_mc_count(net_dev) > wnd->multicast_size) {
+ 		packet_filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
+ 		TRACE2("0x%08x", packet_filter);
+-	} else if (net_dev->mc_count > 0) {
++	} else if (netdev_mc_count(net_dev) > 0) {
+ 		int i, size;
+ 		char *buf;
++#ifndef netdev_for_each_mc_addr
+ 		struct dev_mc_list *mclist;
+-		size = min(wnd->multicast_size, net_dev->mc_count);
+-		TRACE2("%d, %d", wnd->multicast_size, net_dev->mc_count);
++#else
++		struct netdev_hw_addr *mclist;
++#endif
++
++		size = min(wnd->multicast_size, netdev_mc_count(net_dev));
++		TRACE2("%d, %d", wnd->multicast_size, netdev_mc_count(net_dev));
+ 		buf = kmalloc(size * ETH_ALEN, GFP_KERNEL);
+ 		if (!buf) {
+ 			WARNING("couldn't allocate memory");
+ 			EXIT2(return);
+ 		}
++#ifndef netdev_for_each_mc_addr
+ 		mclist = net_dev->mc_list;
+ 		for (i = 0; i < size && mclist; mclist = mclist->next) {
+ 			if (mclist->dmi_addrlen != ETH_ALEN)
+@@ -972,6 +982,15 @@
+ 			TRACE2(MACSTRSEP, MAC2STR(mclist->dmi_addr));
+ 			i++;
+ 		}
++#else
++		i = 0;
++		netdev_for_each_mc_addr(mclist, net_dev){
++                        memcpy(buf + i++ * ETH_ALEN,
++                               mclist->addr, ETH_ALEN);
++                        TRACE2(MACSTRSEP, MAC2STR(mclist->addr));
++
++		}
++#endif
+ 		res = mp_set(wnd, OID_802_3_MULTICAST_LIST, buf, i * ETH_ALEN);
+ 		if (res == NDIS_STATUS_SUCCESS && i > 0)
+ 			packet_filter |= NDIS_PACKET_TYPE_MULTICAST;
diff --git a/abs/core/ndiswrapper/kernel-2.6.36.patch b/abs/core/ndiswrapper/kernel-2.6.36.patch
new file mode 100644
index 0000000..63de303
--- /dev/null
+++ b/abs/core/ndiswrapper/kernel-2.6.36.patch
@@ -0,0 +1,27 @@
+--- ndiswrapper-1.56.orig/driver/loader.c	2010-02-11 03:09:32.000000000 +0100
++++ ndiswrapper-1.56/driver/loader.c	2010-10-24 01:38:13.000000000 +0200
+@@ -750,13 +750,13 @@
+ }
+ 
+ /* called with loader_mutex is down */
+-static int wrapper_ioctl(struct inode *inode, struct file *file,
++static long wrapper_unlocked_ioctl(struct file *file,
+ 			 unsigned int cmd, unsigned long arg)
+ {
+ 	struct load_driver *load_driver;
+ 	struct load_device load_device;
+ 	struct load_driver_file load_bin_file;
+-	int ret;
++	long ret;
+ 	void __user *addr = (void __user *)arg;
+ 
+ 	ENTER1("cmd: %u", cmd);
+@@ -831,7 +831,7 @@
+ 
+ static struct file_operations wrapper_fops = {
+ 	.owner          = THIS_MODULE,
+-	.ioctl		= wrapper_ioctl,
++	.unlocked_ioctl	= wrapper_unlocked_ioctl,
+ 	.release	= wrapper_ioctl_release,
+ };
+ 
diff --git a/abs/core/ndiswrapper/ndiswrapper-CVE-2008-4395.patch b/abs/core/ndiswrapper/ndiswrapper-CVE-2008-4395.patch
deleted file mode 100644
index 53682e0..0000000
--- a/abs/core/ndiswrapper/ndiswrapper-CVE-2008-4395.patch
+++ /dev/null
@@ -1,86 +0,0 @@
-diff --git a/ubuntu/ndiswrapper/iw_ndis.c b/ubuntu/ndiswrapper/iw_ndis.c
-index b114ef6..01d3751 100644
---- a/ubuntu/ndiswrapper/iw_ndis.c
-+++ b/ubuntu/ndiswrapper/iw_ndis.c
-@@ -47,12 +47,7 @@ int set_essid(struct ndis_device *wnd, const char *ssid, int ssid_len)
- 	req.length = ssid_len;
- 	if (ssid_len)
- 		memcpy(&req.essid, ssid, ssid_len);
--	DBG_BLOCK(2) {
--		char buf[NDIS_ESSID_MAX_SIZE+1];
--		memcpy(buf, ssid, ssid_len);
--		buf[ssid_len] = 0;
--		TRACE2("ssid = '%s'", buf);
--	}
-+	TRACE2("ssid = '%.*s'", ssid_len, ssid);
- 
- 	res = mp_set(wnd, OID_802_11_SSID, &req, sizeof(req));
- 	if (res) {
-@@ -125,7 +120,6 @@ static int iw_get_essid(struct net_device *dev, struct iw_request_info *info,
- 		EXIT2(return -EOPNOTSUPP);
- 	}
- 	memcpy(extra, req.essid, req.length);
--	extra[req.length] = 0;
- 	if (req.length > 0)
- 		wrqu->essid.flags  = 1;
- 	else
-@@ -1000,7 +994,7 @@ static int iw_set_nick(struct net_device *dev, struct iw_request_info *info,
- 
- 	if (wrqu->data.length > IW_ESSID_MAX_SIZE || wrqu->data.length <= 0)
- 		return -EINVAL;
--	memset(wnd->nick, 0, sizeof(wnd->nick));
-+	wnd->nick_len = wrqu->data.length;
- 	memcpy(wnd->nick, extra, wrqu->data.length);
- 	return 0;
- }
-@@ -1010,7 +1004,7 @@ static int iw_get_nick(struct net_device *dev, struct iw_request_info *info,
- {
- 	struct ndis_device *wnd = netdev_priv(dev);
- 
--	wrqu->data.length = strlen(wnd->nick);
-+	wrqu->data.length = wnd->nick_len;
- 	memcpy(extra, wnd->nick, wrqu->data.length);
- 	return 0;
- }
-diff --git a/ubuntu/ndiswrapper/ndis.h b/ubuntu/ndiswrapper/ndis.h
-index 27ba99e..65d6b0b 100644
---- a/ubuntu/ndiswrapper/ndis.h
-+++ b/ubuntu/ndiswrapper/ndis.h
-@@ -878,6 +878,7 @@ struct ndis_device {
- 	unsigned long scan_timestamp;
- 	struct encr_info encr_info;
- 	char nick[IW_ESSID_MAX_SIZE];
-+	size_t nick_len;
- 	struct ndis_essid essid;
- 	struct auth_encr_capa capa;
- 	enum ndis_infrastructure_mode infrastructure_mode;
-diff --git a/ubuntu/ndiswrapper/proc.c b/ubuntu/ndiswrapper/proc.c
-index fd5f433..6feff23 100644
---- a/ubuntu/ndiswrapper/proc.c
-+++ b/ubuntu/ndiswrapper/proc.c
-@@ -97,10 +97,8 @@ static int procfs_read_ndis_encr(char *page, char **start, off_t off,
- 	p += sprintf(p, "\n");
- 
- 	res = mp_query(wnd, OID_802_11_SSID, &essid, sizeof(essid));
--	if (!res) {
--		essid.essid[essid.length] = '\0';
--		p += sprintf(p, "essid=%s\n", essid.essid);
--	}
-+	if (!res)
-+		p += sprintf(p, "essid=%.*s\n", essid.length, essid.essid);
- 	res = mp_query_int(wnd, OID_802_11_ENCRYPTION_STATUS, &encr_status);
- 	if (!res) {
- 		typeof(&wnd->encr_info.keys[0]) tx_key;
-diff --git a/ubuntu/ndiswrapper/wrapndis.c b/ubuntu/ndiswrapper/wrapndis.c
-index f6e5d46..35ef1cd 100644
---- a/ubuntu/ndiswrapper/wrapndis.c
-+++ b/ubuntu/ndiswrapper/wrapndis.c
-@@ -2028,7 +2028,7 @@ static wstdcall NTSTATUS NdisAddDevice(struct driver_object *drv_obj,
- 	wnd->attributes = 0;
- 	wnd->dma_map_count = 0;
- 	wnd->dma_map_addr = NULL;
--	wnd->nick[0] = 0;
-+	wnd->nick_len = 0;
- 	init_timer(&wnd->hangcheck_timer);
- 	wnd->scan_timestamp = 0;
- 	init_timer(&wnd->iw_stats_timer);
diff --git a/abs/core/ndiswrapper/ndiswrapper.install b/abs/core/ndiswrapper/ndiswrapper.install
index fafe580..57eca02 100644
--- a/abs/core/ndiswrapper/ndiswrapper.install
+++ b/abs/core/ndiswrapper/ndiswrapper.install
@@ -2,7 +2,7 @@
 post_install()
 {
   ndiswrapper -m
-  KERNEL_VERSION='2.6.34-LinHES'
+  KERNEL_VERSION='2.6.36-LinHES'
   depmod -ae $KERNEL_VERSION > /dev/null 2>&1 
 }
 
@@ -11,13 +11,13 @@ post_install()
 post_upgrade()
 {
   ndiswrapper -m
-  KERNEL_VERSION='2.6.34-LinHES'
+  KERNEL_VERSION='2.6.36-LinHES'
   depmod -ae $KERNEL_VERSION > /dev/null 2>&1 
 }
 
 # arg 1:  the old package version
 post_remove()
 {
-  KERNEL_VERSION='2.6.34-LinHES'
+  KERNEL_VERSION='2.6.36-LinHES'
   depmod -ae $KERNEL_VERSION > /dev/null 2>&1
 }
-- 
cgit v0.12

