Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2003
|
|
|
|
* Bill Paul <wpaul@windriver.com>. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _NTOSKRNL_VAR_H_
|
|
|
|
#define _NTOSKRNL_VAR_H_
|
|
|
|
|
2003-12-13 09:07:35 +00:00
|
|
|
/* Note: assumes x86 page size of 4K. */
|
|
|
|
#define PAGE_SHIFT 12
|
|
|
|
#define SPAN_PAGES(ptr, len) \
|
|
|
|
((uint32_t)((((uintptr_t)(ptr) & (PAGE_SIZE -1)) + \
|
|
|
|
(len) + (PAGE_SIZE - 1)) >> PAGE_SHIFT))
|
2003-12-23 04:08:22 +00:00
|
|
|
#define PAGE_ALIGN(ptr) \
|
|
|
|
((void *)((uintptr_t)(ptr) & ~(PAGE_SIZE - 1)))
|
|
|
|
#define BYTE_OFFSET(ptr) \
|
|
|
|
((uint32_t)((uintptr_t)(ptr) & (PAGE_SIZE - 1)))
|
|
|
|
#define MDL_INIT(b, baseva, len) \
|
|
|
|
(b)->nb_next = NULL; \
|
|
|
|
(b)->nb_size = (uint16_t)(sizeof(struct ndis_buffer) + \
|
|
|
|
(sizeof(uint32_t) * SPAN_PAGES((baseva), (len)))); \
|
|
|
|
(b)->nb_flags = 0; \
|
|
|
|
(b)->nb_startva = (void *)PAGE_ALIGN((baseva)); \
|
|
|
|
(b)->nb_byteoffset = BYTE_OFFSET((baseva)); \
|
|
|
|
(b)->nb_bytecount = (uint32_t)(len);
|
|
|
|
#define MDL_VA(b) \
|
|
|
|
((void *)((char *)((b)->nb_startva) + (b)->nb_byteoffset))
|
2003-12-13 09:07:35 +00:00
|
|
|
|
2004-01-19 20:45:27 +00:00
|
|
|
#define WDM_MAJOR 1
|
|
|
|
#define WDM_MINOR_WIN98 0x00
|
|
|
|
#define WDM_MINOR_WINME 0x05
|
|
|
|
#define WDM_MINOR_WIN2000 0x10
|
|
|
|
#define WDM_MINOR_WINXP 0x20
|
|
|
|
#define WDM_MINOR_WIN2003 0x30
|
|
|
|
|
2004-01-16 02:07:04 +00:00
|
|
|
/*-
|
|
|
|
* The ndis_kspin_lock type is called KSPIN_LOCK in MS-Windows.
|
|
|
|
* According to the Windows DDK header files, KSPIN_LOCK is defined like this:
|
|
|
|
* typedef ULONG_PTR KSPIN_LOCK;
|
|
|
|
*
|
|
|
|
* From basetsd.h (SDK, Feb. 2003):
|
|
|
|
* typedef [public] unsigned __int3264 ULONG_PTR, *PULONG_PTR;
|
|
|
|
* typedef unsigned __int64 ULONG_PTR, *PULONG_PTR;
|
|
|
|
* typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
|
|
|
|
*
|
|
|
|
* The keyword __int3264 specifies an integral type that has the following
|
|
|
|
* properties:
|
|
|
|
* + It is 32-bit on 32-bit platforms
|
|
|
|
* + It is 64-bit on 64-bit platforms
|
|
|
|
* + It is 32-bit on the wire for backward compatibility.
|
|
|
|
* It gets truncated on the sending side and extended appropriately
|
|
|
|
* (signed or unsigned) on the receiving side.
|
|
|
|
*
|
|
|
|
* Thus register_t seems the proper mapping onto FreeBSD for spin locks.
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef register_t kspin_lock;
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
|
|
|
|
struct slist_entry {
|
|
|
|
struct slist_entry *sl_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct slist_entry slist_entry;
|
|
|
|
|
|
|
|
union slist_header {
|
|
|
|
uint64_t slh_align;
|
|
|
|
struct {
|
|
|
|
struct slist_entry *slh_next;
|
|
|
|
uint16_t slh_depth;
|
|
|
|
uint16_t slh_seq;
|
|
|
|
} slh_list;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef union slist_header slist_header;
|
|
|
|
|
subr_ndis.c:
- fix ndis_time() so that it returns a time based on the proper
epoch (wacky though it may be)
- implement NdisInitializeString() and NdisFreeString(), and add
stub for NdisMRemoveMiniport()
ntoskrnl_var.h:
- add missing member to the general_lookaside struct (gl_listentry)
subr_ntoskrnl.c:
- Fix arguments to the interlocked push/pop routines: 'head' is an
slist_header *, not an slist_entry *
- Kludge up _fastcall support for the push/pop routines. The _fastcall
convention is similar to _stdcall, except the first two available
DWORD-sized arguments are passed in %ecx and %edx, respectively.
One kludge for this __attribute__ ((regparm(3))), however this
isn't entirely right, as it assumes %eax, %ecx and %edx will be
used (regparm(2) assumes %eax and %edx). Another kludge is to
declare the two fastcall-ed args as local register variables and
explicitly assign them to %ecx and %edx, but experimentation showed
that gcc would not guard %ecx and %edx against being clobbered.
Thus, I came up with a 3rd kludge, which is to use some inline
assembly of the form:
void *arg1;
void *arg2;
__asm__("movl %%ecx, %%ecx" : "=c" (arg1));
__asm__("movl %%edx, %%edx" : "=d" (arg2));
This lets gcc know that we're going to reference %ecx and %edx and
that it should make an effort not to let it get trampled. This wastes
an instruction (movl %reg, %reg is a no-op) but insures proper
behavior. It's possible there's a better way to do this though:
this is the first time I've used inline assembler in this fashion.
The above fixes to ntoskrnl_var.h an subr_ntoskrnl.c make lookaside
lists work for the two drivers I have that use them, one of which
is an NDIS 5.0 miniport and another which is 5.1.
2003-12-13 07:41:12 +00:00
|
|
|
struct list_entry {
|
|
|
|
struct list_entry *nle_flink;
|
|
|
|
struct list_entry *nle_blink;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct list_entry list_entry;
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
#define INIT_LIST_HEAD(l) \
|
|
|
|
l->nle_flink = l->nle_blink = l
|
|
|
|
|
|
|
|
#define REMOVE_LIST_ENTRY(e) \
|
|
|
|
do { \
|
|
|
|
list_entry *b; \
|
|
|
|
list_entry *f; \
|
|
|
|
\
|
|
|
|
f = e->nle_flink; \
|
|
|
|
b = e->nle_blink; \
|
|
|
|
b->nle_flink = f; \
|
|
|
|
f->nle_blink = b; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define REMOVE_LIST_HEAD(l) \
|
|
|
|
do { \
|
|
|
|
list_entry *f; \
|
|
|
|
list_entry *e; \
|
|
|
|
\
|
|
|
|
e = l->nle_flink; \
|
|
|
|
f = e->nle_flink; \
|
|
|
|
l->nle_flink = f; \
|
|
|
|
f->nle_blink = l; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define REMOVE_LIST_TAIL(l) \
|
|
|
|
do { \
|
|
|
|
list_entry *b; \
|
|
|
|
list_entry *e; \
|
|
|
|
\
|
|
|
|
e = l->nle_blink; \
|
|
|
|
b = e->nle_blink; \
|
|
|
|
l->nle_blink = b; \
|
|
|
|
b->nle_flink = l; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define INSERT_LIST_TAIL(l, e) \
|
|
|
|
do { \
|
|
|
|
list_entry *b; \
|
|
|
|
\
|
|
|
|
b = l->nle_blink; \
|
2004-02-16 02:50:03 +00:00
|
|
|
e->nle_flink = l; \
|
2004-02-07 06:44:13 +00:00
|
|
|
e->nle_blink = b; \
|
|
|
|
b->nle_flink = e; \
|
|
|
|
l->nle_blink = e; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
#define INSERT_LIST_HEAD(l, e) \
|
|
|
|
do { \
|
|
|
|
list_entry *f; \
|
|
|
|
\
|
|
|
|
f = l->nle_flink; \
|
|
|
|
e->nle_flink = f; \
|
|
|
|
e->nle_blink = l; \
|
|
|
|
f->nle_blink = e; \
|
|
|
|
l->nle_flink = e; \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
struct nt_dispatch_header {
|
|
|
|
uint8_t dh_type;
|
|
|
|
uint8_t dh_abs;
|
|
|
|
uint8_t dh_size;
|
|
|
|
uint8_t dh_inserted;
|
|
|
|
uint32_t dh_sigstate;
|
|
|
|
list_entry dh_waitlisthead;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct nt_dispatch_header nt_dispatch_header;
|
|
|
|
|
|
|
|
#define OTYPE_EVENT 0
|
|
|
|
#define OTYPE_MUTEX 1
|
|
|
|
#define OTYPE_THREAD 2
|
|
|
|
#define OTYPE_TIMER 3
|
|
|
|
|
|
|
|
/* Windows dispatcher levels. */
|
|
|
|
|
|
|
|
#define PASSIVE_LEVEL 0
|
|
|
|
#define LOW_LEVEL 0
|
|
|
|
#define APC_LEVEL 1
|
|
|
|
#define DISPATCH_LEVEL 2
|
|
|
|
#define PROFILE_LEVEL 27
|
|
|
|
#define CLOCK1_LEVEL 28
|
|
|
|
#define CLOCK2_LEVEL 28
|
|
|
|
#define IPI_LEVEL 29
|
|
|
|
#define POWER_LEVEL 30
|
|
|
|
#define HIGH_LEVEL 31
|
|
|
|
|
|
|
|
#define SYNC_LEVEL_UP DISPATCH_LEVEL
|
|
|
|
#define SYNC_LEVEL_MP (IPI_LEVEL - 1)
|
|
|
|
|
|
|
|
struct nt_objref {
|
|
|
|
nt_dispatch_header no_dh;
|
|
|
|
void *no_obj;
|
|
|
|
TAILQ_ENTRY(nt_objref) link;
|
|
|
|
};
|
|
|
|
|
|
|
|
TAILQ_HEAD(nt_objref_head, nt_objref);
|
|
|
|
|
|
|
|
typedef struct nt_objref nt_objref;
|
|
|
|
|
|
|
|
#define EVENT_TYPE_NOTIFY 0
|
|
|
|
#define EVENT_TYPE_SYNC 1
|
|
|
|
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
/*
|
|
|
|
* We need to use the timeout()/untimeout() API for ktimers
|
|
|
|
* since timers can be initialized, but not destroyed (so
|
|
|
|
* malloc()ing our own callout structures would mean a leak,
|
|
|
|
* since there'd be no way to free() them). This means we
|
|
|
|
* need to use struct callout_handle, which is really just a
|
|
|
|
* pointer. To make it easier to deal with, we use a union
|
|
|
|
* to overlay the callout_handle over the k_timerlistentry.
|
|
|
|
* The latter is a list_entry, which is two pointers, so
|
|
|
|
* there's enough space available to hide a callout_handle
|
|
|
|
* there.
|
|
|
|
*/
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
struct ktimer {
|
|
|
|
nt_dispatch_header k_header;
|
|
|
|
uint64_t k_duetime;
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
union {
|
|
|
|
list_entry k_timerlistentry;
|
|
|
|
struct callout_handle k_handle;
|
|
|
|
} u;
|
2004-02-07 06:44:13 +00:00
|
|
|
void *k_dpc;
|
|
|
|
uint32_t k_period;
|
|
|
|
};
|
|
|
|
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
#define k_timerlistentry u.k_timerlistentry
|
|
|
|
#define k_handle u.k_handle
|
|
|
|
|
|
|
|
typedef struct ktimer ktimer;
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
struct nt_kevent {
|
|
|
|
nt_dispatch_header k_header;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct nt_kevent nt_kevent;
|
|
|
|
|
|
|
|
/* Kernel defered procedure call (i.e. timer callback) */
|
|
|
|
|
|
|
|
struct kdpc;
|
|
|
|
typedef void (*kdpc_func)(struct kdpc *, void *, void *, void *);
|
|
|
|
|
|
|
|
struct kdpc {
|
|
|
|
uint16_t k_type;
|
|
|
|
uint8_t k_num;
|
|
|
|
uint8_t k_importance;
|
|
|
|
list_entry k_dpclistentry;
|
|
|
|
kdpc_func k_deferedfunc;
|
|
|
|
void *k_deferredctx;
|
|
|
|
void *k_sysarg1;
|
|
|
|
void *k_sysarg2;
|
|
|
|
uint32_t *k_lock;
|
|
|
|
};
|
|
|
|
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
typedef struct kdpc kdpc;
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
/*
|
|
|
|
* Note: the acquisition count is BSD-specific. The Microsoft
|
|
|
|
* documentation says that mutexes can be acquired recursively
|
|
|
|
* by a given thread, but that you must release the mutex as
|
|
|
|
* many times as you acquired it before it will be set to the
|
|
|
|
* signalled state (i.e. before any other threads waiting on
|
|
|
|
* the object will be woken up). However the Windows KMUTANT
|
|
|
|
* structure has no field for keeping track of the number of
|
|
|
|
* acquisitions, so we need to add one ourselves. As long as
|
|
|
|
* driver code treats the mutex as opaque, we should be ok.
|
|
|
|
*/
|
|
|
|
struct kmutant {
|
|
|
|
nt_dispatch_header km_header;
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
union {
|
|
|
|
list_entry km_listentry;
|
|
|
|
uint32_t km_acquirecnt;
|
|
|
|
} u;
|
2004-02-07 06:44:13 +00:00
|
|
|
void *km_ownerthread;
|
|
|
|
uint8_t km_abandoned;
|
|
|
|
uint8_t km_apcdisable;
|
|
|
|
};
|
|
|
|
|
- Some older Atheros drivers want KeInitializeTimer(), so implement it,
along with KeInitializeTimerEx(), KeSetTimer(), KeSetTimerEx(),
KeCancelTimer(), KeReadStateTimer() and KeInitializeDpc(). I don't
know for certain that these will make the Atheros driver happy since
I don't have the card/driver combo needed to test it, but these are
fairly independent so they shouldn't break anything else.
- Debugger() is present even in kernels without options DDB, so no
conditional compilation is necessary (pointed out by bde).
- Remove the extra km_acquirecnt member that I added to struct kmutant
and embed it within an unused portion of the structure instead, so that
we don't make the structure larger than it's defined to be in Windows.
I don't know what crack I was smoking when I decided it was ok to do
this, but it's worn off now.
2004-03-04 23:04:02 +00:00
|
|
|
#define km_listentry u.km_listentry
|
|
|
|
#define km_acquirecnt u.km_acquirecnt
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
typedef struct kmutant kmutant;
|
|
|
|
|
2004-02-16 02:50:03 +00:00
|
|
|
#define LOOKASIDE_DEPTH 256
|
|
|
|
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
struct general_lookaside {
|
|
|
|
slist_header gl_listhead;
|
|
|
|
uint16_t gl_depth;
|
|
|
|
uint16_t gl_maxdepth;
|
|
|
|
uint32_t gl_totallocs;
|
|
|
|
union {
|
|
|
|
uint32_t gl_allocmisses;
|
|
|
|
uint32_t gl_allochits;
|
|
|
|
} u_a;
|
|
|
|
uint32_t gl_totalfrees;
|
|
|
|
union {
|
|
|
|
uint32_t gl_freemisses;
|
|
|
|
uint32_t gl_freehits;
|
|
|
|
} u_m;
|
|
|
|
uint32_t gl_type;
|
|
|
|
uint32_t gl_tag;
|
|
|
|
uint32_t gl_size;
|
|
|
|
void *gl_allocfunc;
|
|
|
|
void *gl_freefunc;
|
subr_ndis.c:
- fix ndis_time() so that it returns a time based on the proper
epoch (wacky though it may be)
- implement NdisInitializeString() and NdisFreeString(), and add
stub for NdisMRemoveMiniport()
ntoskrnl_var.h:
- add missing member to the general_lookaside struct (gl_listentry)
subr_ntoskrnl.c:
- Fix arguments to the interlocked push/pop routines: 'head' is an
slist_header *, not an slist_entry *
- Kludge up _fastcall support for the push/pop routines. The _fastcall
convention is similar to _stdcall, except the first two available
DWORD-sized arguments are passed in %ecx and %edx, respectively.
One kludge for this __attribute__ ((regparm(3))), however this
isn't entirely right, as it assumes %eax, %ecx and %edx will be
used (regparm(2) assumes %eax and %edx). Another kludge is to
declare the two fastcall-ed args as local register variables and
explicitly assign them to %ecx and %edx, but experimentation showed
that gcc would not guard %ecx and %edx against being clobbered.
Thus, I came up with a 3rd kludge, which is to use some inline
assembly of the form:
void *arg1;
void *arg2;
__asm__("movl %%ecx, %%ecx" : "=c" (arg1));
__asm__("movl %%edx, %%edx" : "=d" (arg2));
This lets gcc know that we're going to reference %ecx and %edx and
that it should make an effort not to let it get trampled. This wastes
an instruction (movl %reg, %reg is a no-op) but insures proper
behavior. It's possible there's a better way to do this though:
this is the first time I've used inline assembler in this fashion.
The above fixes to ntoskrnl_var.h an subr_ntoskrnl.c make lookaside
lists work for the two drivers I have that use them, one of which
is an NDIS 5.0 miniport and another which is 5.1.
2003-12-13 07:41:12 +00:00
|
|
|
list_entry gl_listent;
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
uint32_t gl_lasttotallocs;
|
|
|
|
union {
|
|
|
|
uint32_t gl_lastallocmisses;
|
|
|
|
uint32_t gl_lastallochits;
|
|
|
|
} u_l;
|
|
|
|
uint32_t gl_rsvd[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct general_lookaside general_lookaside;
|
|
|
|
|
|
|
|
struct npaged_lookaside_list {
|
|
|
|
general_lookaside nll_l;
|
|
|
|
kspin_lock nll_obsoletelock;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct npaged_lookaside_list npaged_lookaside_list;
|
|
|
|
typedef struct npaged_lookaside_list paged_lookaside_list;
|
|
|
|
|
|
|
|
typedef void * (*lookaside_alloc_func)(uint32_t, size_t, uint32_t);
|
|
|
|
typedef void (*lookaside_free_func)(void *);
|
|
|
|
|
2004-02-07 06:44:13 +00:00
|
|
|
struct irp;
|
|
|
|
|
|
|
|
struct kdevice_qentry {
|
|
|
|
list_entry kqe_devlistent;
|
|
|
|
uint32_t kqe_sortkey;
|
|
|
|
uint8_t kqe_inserted;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct kdevice_qentry kdevice_qentry;
|
|
|
|
|
|
|
|
struct kdevice_queue {
|
|
|
|
uint16_t kq_type;
|
|
|
|
uint16_t kq_size;
|
|
|
|
list_entry kq_devlisthead;
|
|
|
|
kspin_lock kq_lock;
|
|
|
|
uint8_t kq_busy;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct kdevice_queue kdevice_queue;
|
|
|
|
|
|
|
|
struct wait_ctx_block {
|
|
|
|
kdevice_qentry wcb_waitqueue;
|
|
|
|
void *wcb_devfunc;
|
|
|
|
void *wcb_devctx;
|
|
|
|
uint32_t wcb_mapregcnt;
|
|
|
|
void *wcb_devobj;
|
|
|
|
void *wcb_curirp;
|
|
|
|
void *wcb_bufchaindpc;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct wait_ctx_block wait_ctx_block;
|
|
|
|
|
|
|
|
struct wait_block {
|
|
|
|
list_entry wb_waitlist;
|
|
|
|
void *wb_kthread;
|
|
|
|
nt_dispatch_header *wb_object;
|
|
|
|
struct wait_block *wb_next;
|
|
|
|
uint16_t wb_waitkey;
|
|
|
|
uint16_t wb_waittype;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct wait_block wait_block;
|
|
|
|
|
|
|
|
#define THREAD_WAIT_OBJECTS 3
|
|
|
|
#define MAX_WAIT_OBJECTS 64
|
|
|
|
|
|
|
|
#define WAITTYPE_ALL 0
|
|
|
|
#define WAITTYPE_ANY 1
|
|
|
|
|
|
|
|
struct thread_context {
|
|
|
|
void *tc_thrctx;
|
|
|
|
void *tc_thrfunc;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct thread_context thread_context;
|
|
|
|
|
|
|
|
struct device_object {
|
|
|
|
uint16_t do_type;
|
|
|
|
uint16_t do_size;
|
|
|
|
uint32_t do_refcnt;
|
|
|
|
struct device_object *do_drvobj;
|
|
|
|
struct device_object *do_nextdev;
|
|
|
|
struct device_object *do_attacheddev;
|
|
|
|
struct irp *do_currirp;
|
|
|
|
void *do_iotimer;
|
|
|
|
uint32_t do_flags;
|
|
|
|
uint32_t do_characteristics;
|
|
|
|
void *do_vpb;
|
|
|
|
void *do_devext;
|
|
|
|
uint8_t do_stacksize;
|
|
|
|
union {
|
|
|
|
list_entry do_listent;
|
|
|
|
wait_ctx_block do_wcb;
|
|
|
|
} queue;
|
|
|
|
uint32_t do_alignreq;
|
|
|
|
kdevice_queue do_devqueue;
|
|
|
|
struct kdpc do_dpc;
|
|
|
|
uint32_t do_activethreads;
|
|
|
|
void *do_securitydesc;
|
|
|
|
struct nt_kevent do_devlock;
|
|
|
|
uint16_t do_sectorsz;
|
|
|
|
uint16_t do_spare1;
|
|
|
|
void *do_devobj_ext;
|
|
|
|
void *do_rsvd;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct device_object device_object;
|
|
|
|
|
|
|
|
struct irp {
|
|
|
|
uint32_t i_dummy;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct irp irp;
|
|
|
|
|
|
|
|
typedef uint32_t (*driver_dispatch)(device_object *, irp *);
|
|
|
|
|
|
|
|
#define DEVPROP_DEVICE_DESCRIPTION 0x00000000
|
|
|
|
#define DEVPROP_HARDWARE_ID 0x00000001
|
|
|
|
#define DEVPROP_COMPATIBLE_IDS 0x00000002
|
|
|
|
#define DEVPROP_BOOTCONF 0x00000003
|
|
|
|
#define DEVPROP_BOOTCONF_TRANSLATED 0x00000004
|
|
|
|
#define DEVPROP_CLASS_NAME 0x00000005
|
|
|
|
#define DEVPROP_CLASS_GUID 0x00000006
|
|
|
|
#define DEVPROP_DRIVER_KEYNAME 0x00000007
|
|
|
|
#define DEVPROP_MANUFACTURER 0x00000008
|
|
|
|
#define DEVPROP_FRIENDLYNAME 0x00000009
|
|
|
|
#define DEVPROP_LOCATION_INFO 0x0000000A
|
|
|
|
#define DEVPROP_PHYSDEV_NAME 0x0000000B
|
|
|
|
#define DEVPROP_BUSTYPE_GUID 0x0000000C
|
|
|
|
#define DEVPROP_LEGACY_BUSTYPE 0x0000000D
|
|
|
|
#define DEVPROP_BUS_NUMBER 0x0000000E
|
|
|
|
#define DEVPROP_ENUMERATOR_NAME 0x0000000F
|
|
|
|
#define DEVPROP_ADDRESS 0x00000010
|
|
|
|
#define DEVPROP_UINUMBER 0x00000011
|
|
|
|
#define DEVPROP_INSTALL_STATE 0x00000012
|
|
|
|
#define DEVPROP_REMOVAL_POLICY 0x00000013
|
|
|
|
|
|
|
|
#define STATUS_SUCCESS 0x00000000
|
|
|
|
#define STATUS_USER_APC 0x000000C0
|
|
|
|
#define STATUS_KERNEL_APC 0x00000100
|
|
|
|
#define STATUS_ALERTED 0x00000101
|
|
|
|
#define STATUS_TIMEOUT 0x00000102
|
|
|
|
#define STATUS_INVALID_PARAMETER 0xC000000D
|
|
|
|
#define STATUS_INVALID_DEVICE_REQUEST 0xC0000010
|
|
|
|
#define STATUS_BUFFER_TOO_SMALL 0xC0000023
|
|
|
|
#define STATUS_MUTANT_NOT_OWNED 0xC0000046
|
|
|
|
#define STATUS_INVALID_PARAMETER_2 0xC00000F0
|
|
|
|
|
|
|
|
#define STATUS_WAIT_0 0x00000000
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
|
2004-03-22 00:41:41 +00:00
|
|
|
/*
|
|
|
|
* FreeBSD's kernel stack is 2 pages in size by default. The
|
|
|
|
* Windows stack is larger, so we need to give our threads more
|
|
|
|
* stack pages. 4 should be enough, we use 8 just to extra safe.
|
|
|
|
*/
|
|
|
|
#define NDIS_KSTACK_PAGES 8
|
|
|
|
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
extern image_patch_table ntoskrnl_functbl[];
|
2004-02-07 06:44:13 +00:00
|
|
|
extern struct mtx *ntoskrnl_dispatchlock;
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
|
|
|
|
__BEGIN_DECLS
|
|
|
|
extern int ntoskrnl_libinit(void);
|
|
|
|
extern int ntoskrnl_libfini(void);
|
- Rewrite the timer and event API routines in subr_ndis.c so that they
are actually layered on top of the KeTimer API in subr_ntoskrnl.c, just
as it is in Windows. This reduces code duplication and more closely
imitates the way things are done in Windows.
- Modify ndis_encode_parm() to deal with the case where we have
a registry key expressed as a hex value ("0x1") which is being
read via NdisReadConfiguration() as an int. Previously, we tried
to decode things like "0x1" with strtol() using a base of 10, which
would always yield 0. This is what was causing problems with the
Intel 2200BG Centrino 802.11g driver: the .inf file that comes
with it has a key called RadioEnable with a value of 0x1. We
incorrectly decoded this value to '0' when it was queried, hence
the driver thought we wanted the radio turned off.
- In if_ndis.c, most drivers don't accept NDIS_80211_AUTHMODE_AUTO,
but NDIS_80211_AUTHMODE_SHARED may not be right in some cases,
so for now always use NDIS_80211_AUTHMODE_OPEN.
NOTE: There is still one problem with the Intel 2200BG driver: it
happens that the kernel stack in Windows is larger than the kernel
stack in FreeBSD. The 2200BG driver sometimes eats up more than 2
pages of stack space, which can lead to a double fault panic.
For the moment, I got things to work by adding the following to
my kernel config file:
options KSTACK_PAGES=8
I'm pretty sure 8 is too big; I just picked this value out of a hat
as a test, and it happened to work, so I left it. 4 pages might be
enough. Unfortunately, I don't think you can dynamically give a
thread a larger stack, so I'm not sure how to handle this short of
putting a note in the man page about it and dealing with the flood
of mail from people who never read man pages.
2004-03-20 23:39:43 +00:00
|
|
|
__stdcall extern void ntoskrnl_init_dpc(kdpc *, void *, void *);
|
|
|
|
__stdcall extern void ntoskrnl_init_timer(ktimer *);
|
|
|
|
__stdcall extern void ntoskrnl_init_timer_ex(ktimer *, uint32_t);
|
|
|
|
__stdcall extern uint8_t ntoskrnl_set_timer(ktimer *, int64_t, kdpc *);
|
|
|
|
__stdcall extern uint8_t ntoskrnl_set_timer_ex(ktimer *, int64_t,
|
|
|
|
uint32_t, kdpc *);
|
|
|
|
__stdcall extern uint8_t ntoskrnl_cancel_timer(ktimer *);
|
|
|
|
__stdcall extern uint8_t ntoskrnl_read_timer(ktimer *);
|
|
|
|
__stdcall uint32_t ntoskrnl_waitforobj(nt_dispatch_header *, uint32_t,
|
|
|
|
uint32_t, uint8_t, int64_t *);
|
|
|
|
__stdcall void ntoskrnl_init_event(nt_kevent *, uint32_t, uint8_t);
|
|
|
|
__stdcall void ntoskrnl_clear_event(nt_kevent *);
|
|
|
|
__stdcall uint32_t ntoskrnl_read_event(nt_kevent *);
|
|
|
|
__stdcall uint32_t ntoskrnl_set_event(nt_kevent *, uint32_t, uint8_t);
|
|
|
|
__stdcall uint32_t ntoskrnl_reset_event(nt_kevent *);
|
Commit the first cut of Project Evil, also known as the NDISulator.
Yes, it's what you think it is. Yes, you should run away now.
This is a special compatibility module for allowing Windows NDIS
miniport network drivers to be used with FreeBSD/x86. This provides
_binary_ NDIS compatibility (not source): you can run NDIS driver
code, but you can't build it. There are three main parts:
sys/compat/ndis: the NDIS compat API, which provides binary
compatibility functions for many routines in NDIS.SYS, HAL.dll
and ntoskrnl.exe in Windows (these are the three modules that
most NDIS miniport drivers use). The compat module also contains
a small PE relocator/dynalinker which relocates the Windows .SYS
image and then patches in our native routines.
sys/dev/if_ndis: the if_ndis driver wrapper. This module makes
use of the ndis compat API and can be compiled with a specially
prepared binary image file (ndis_driver_data.h) containing the
Windows .SYS image and registry key information parsed out of the
accompanying .INF file. Once if_ndis.ko is built, it can be loaded
and unloaded just like a native FreeBSD kenrel module.
usr.sbin/ndiscvt: a special utility that converts foo.sys and foo.inf
into an ndis_driver_data.h file that can be compiled into if_ndis.o.
Contains an .inf file parser graciously provided by Matt Dodd (and
mercilessly hacked upon by me) that strips out device ID info and
registry key info from a .INF file and packages it up with a binary
image array. The ndiscvt(8) utility also does some manipulation of
the segments within the .sys file to make life easier for the kernel
loader. (Doing the manipulation here saves the kernel code from having
to move things around later, which would waste memory.)
ndiscvt is only built for the i386 arch. Only files.i386 has been
updated, and none of this is turned on in GENERIC. It should probably
work on pc98. I have no idea about amd64 or ia64 at this point.
This is still a work in progress. I estimate it's about %85 done, but
I want it under CVS control so I can track subsequent changes. It has
been tested with exactly three drivers: the LinkSys LNE100TX v4 driver
(Lne100v4.sys), the sample Intel 82559 driver from the Windows DDK
(e100bex.sys) and the Broadcom BCM43xx wireless driver (bcmwl5.sys). It
still needs to have a net80211 stuff added to it. To use it, you would
do something like this:
# cd /sys/modules/ndis
# make; make load
# cd /sys/modules/if_ndis
# ndiscvt -i /path/to/foo.inf -s /path/to/foo.sys -o ndis_driver_data.h
# make; make load
# sysctl -a | grep ndis
All registry keys are mapped to sysctl nodes. Sometimes drivers refer
to registry keys that aren't mentioned in foo.inf. If this happens,
the NDIS API module creates sysctl nodes for these keys on the fly so
you can tweak them.
An example usage of the Broadcom wireless driver would be:
# sysctl hw.ndis0.EnableAutoConnect=1
# sysctl hw.ndis0.SSID="MY_SSID"
# sysctl hw.ndis0.NetworkType=0 (0 for bss, 1 for adhoc)
# ifconfig ndis0 <my ipaddr> netmask 0xffffff00 up
Things to be done:
- get rid of debug messages
- add in ndis80211 support
- defer transmissions until after a status update with
NDIS_STATUS_CONNECTED occurs
- Create smarter lookaside list support
- Split off if_ndis_pci.c and if_ndis_pccard.c attachments
- Make sure PCMCIA support works
- Fix ndiscvt to properly parse PCMCIA device IDs from INF files
- write ndisapi.9 man page
2003-12-11 22:34:37 +00:00
|
|
|
__END_DECLS
|
|
|
|
|
|
|
|
#endif /* _NTOSKRNL_VAR_H_ */
|