LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Wireless Networking (https://www.linuxquestions.org/questions/linux-wireless-networking-41/)
-   -   how-to register ndiswrapper with modules.pcimap (https://www.linuxquestions.org/questions/linux-wireless-networking-41/how-to-register-ndiswrapper-with-modules-pcimap-360483/)

esl537 09-05-2005 02:14 PM

how-to register ndiswrapper with modules.pcimap
 
the following is a success story. hopefully, it will provide some useful information to other users.

------------------------------------------------

history:
in an earlier message that i worte back in late august, i had talked about how i got ndiswrapper and wpa_supplicant to load either at boot time or at run time by issuing the "ifup" command as root. but what i really wanted to do was get ndiswrapper, wpa_supplicant, and my smc2835w pcmcia card up and running just by inserting the card at run time (after logging in). that is, i'm lazy- i didn't want to have to issue the ifup command as root at run time.

this is what i did to get it to work.

-----------------------------------------------

as i talked about in that aforementioned post, the key is to register ndiswrapper with the kernel's pcimap, a file called modules.pcimap. under my system, this file is rewritten at bootup and so a manual edit is not feasible. through all my internet searches, i concluded that the only way to make this happen was to hack the ndiswrapper source code. but how? well, i pretty much used the prism54 source code from prism54.org as a template. this is what i added to the loader.c file:

static const struct pci_device_id pci_id_table[] = {
{
PCI_ANY_ID, PCI_ANY_ID,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, PCI_ANY_ID},

{
0, 0, 0, 0, 0, 0, 0}
};

/* register the device with the Hotplug facilities of the kernel */
MODULE_DEVICE_TABLE(pci, pci_id_table);

would you believe that it just comes down to a few lines of code? yeah, but these few lines took me like a week to figure out. 99% of the work is in the last 1% of the problem....?

after a compile and an install, i found this new entry in my modules.pcimap file:
# pci module vendor device subvendor subdevice class class_mask driver_data
ndiswrapper 0xffffffff 0xffffffff 0xffffffff 0xffffffff 0x00000000 0x00000000 0xffffffff

by comparison, this is what you might find if you installed prism54:
# pci module vendor device subvendor subdevice class class_mask driver_data
prism54 0x00001260 0x00003877 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0000ab80
prism54 0x00001260 0x00003890 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0000abc0
prism54 0x000010b7 0x00006001 0xffffffff 0xffffffff 0x00000000 0x00000000 0x0000ac00

as you can see, all of the "PCI_ANY_ID" macros allow ndiswrapper to be associated with any wireless card whereas the prism54 module has a more strict definition with what cards it is associated with. this is fair b/c ndiswrapper is supposed to work with many cards (b/c it uses winXP drivers) whereas prism54 should only work with prism-type cards.

the last entry of "0's" is needed to tell the mapping process that there are no more entries to map. and the MODULE_DEVICE_TABLE is the macro that sends the info to the kernel for mapping. or at least this is how i view it.

are we done yet? no not quite. the last part was taken from:
http://www.hpl.hp.com/personal/Jean_...ux/HOTPLUG.txt

reading this document is very helpful. it says that:
1] when a card is inserted, a hotplug event is generated. all the source code hacking i just gave gets the kernel to use this hotplug event to load ndiswrapper.

2] when ndiswrapper is loaded, a network event is generated. the last thing we want to do is get the kernel to use this network event to bring the card up. that is, loading the ndiswrapper module does not bring the card up completely, especially if you use WPA like i do.

this is what i had to do to accomplish [2]
added/changed /etc/default/hotplug file:
# NET_AGENT_POLICY
# - from http://www.hpl.hp.com/personal/Jean_...ux/HOTPLUG.txt
NET_AGENT_POLICY=hotplug

added to /etc/network/interfaces file:
mapping hotplug
script grep
map wlan0

so my full interfaces file looks like:
iface wlan0 inet dhcp
mapping hotplug
script grep
map wlan0

in addition, i already had the following in my if-pre-up scripts:
case $IFACE in
wlan0)
/usr/bin/wpa_supplicant -Bw -iwlan0 -c/etc/wpa_supplicant.conf -Dndiswrapper
/bin/sleep 10
esac

and that completes everything. so now when my card is inserted, ndiswrapper is loaded and ifup is called on wlan0. but before ifup is executed, if-pre-up executes and brings up WPA. awesome! with just one insert of the card, everything is up and running, just like i wanted it.

hope this helps someone!

Hangdog42 09-06-2005 07:09 AM

First off, major congrats on figuring this out. That was a ton of good work. Second, have you submitted this to the ndiswrapper folks? They might be interested in including it in their project.


All times are GMT -5. The time now is 12:10 AM.