# RTL8187SE HowTo



## rstrcogburn (Sep 8, 2010)

I recently switched from linux on my MSI Wind U100.  As a lot of you already know, the RTL8187SE wlan mini pci card is not supported.  Ndis comes to the rescue.  The only problem is that the module built will kldload fine, but not at boot in /boot/loader.conf.  Here is a little howto on getting it up and working with FreeBSD 8.1 and ndis.

For the module you'll need you're windows driver from Realtek and your FreeBSD kernel source tree in /usr/src/sys.

(DRIVER)
http://www.realtek.com.tw/downloads...n=4&DownTypeID=3&GetDown=false&Downloads=true

(HOWTO INSTALL KERNEL SOURCE TREE)
http://www.freebsd.org/doc/handbook/kernelconfig-building.html
^first box

(BUILDING AND INSTALLING THE MODULE)

Now unzip and cd into RTL8187SE/WinXP

1) First build your driver


```
%ndisgen net8187Se.inf rtl8187Se.sys
| ENTER THROUGH PROMPTS
```

Now you'll have a "rtl8187Se_sys.ko" which is your kernel module.  You'll need to add it to /boot/modules for easy loading.


```
%su
| ENTER PASSWORD
#cp rtl8187SE_sys.ko /boot/modules
#exit
|^if not proceeding to next section
```

You are setup to kldload your module now which makes for rudimentary support.  It's better to set it up for load on boot, but will cause the kernel to panic with this particular driver and ndis.  To overcome this deficiency we will create a rc.d script that will load at boot time after the card is initialized and ready for the module.

(AUTO-LOADING THE MODULE AT BOOT)

First we will create the scripts needed for our rc.d script.


```
%su
| ENTER PASSWORD
| THE FOLLOWING IS ALL ONE COMMAND TO SECOND __EOF__
#cat > /usr/local/etc/ndis.load << __EOF__
#!/bin/sh
 
# load ndis modules

kldload rtl8187Se_sys

exit 0
__EOF__

#chmod +x /usr/local/etc/ndis.load

| THE FOLLOWING IS ALL ONE COMMAND TO SECOND __EOF__
#cat > /usr/local/etc/ndis.unload << __EOF__
#!/bin/sh
 
# unload ndis modules

kldunload rtl8187Se_sys

exit 0
__EOF__

#chmod +x /usr/local/etc/ndis.unload
```

Last thing to do is creat the ndis rc.d script in /usr/local/etc/rc.d/


```
| THE FOLLOWING IS ALL ONE COMMAND TO SECOND __EOF__
#cat > /usr/local/etc/rc.d/ndis << __EOF__
#!/bin/sh
#
#

# PROVIDE: ndis
# REQUIRE: DAEMON
# BEFORE:  LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="ndis"
start_cmd="ndis_start"
stop_cmd="ndis_stop"

ndis_start()
{
	if [ -f /usr/local/etc/ndis.load ]; then
		echo -n 'Loading ndis modules:'
		. /usr/local/etc/ndis.load
		echo '.'
	fi
}

ndis_stop()
{
	if [ -f /usr/local/etc/ndis.unload ]; then
		echo -n 'Unloading ndis modules:'
		. /usr/local/etc/ndis.unload
		echo '.'
	fi
}

load_rc_config $name
run_rc_command "$1"
__EOF__

#chmod +x /usr/local/etc/rc.d/ndis
#exit
or
#reboot
^ if wanting to try out the autoloading
```

Now you are setup to use your RTL8187SE wlan device.  I reccomend reading the wireless section of the handbook if you are uncertain.  Remember any ath0 or similar snippets will be ndis0 instead since it is an ndis based module not atheros or the like.  Hope you are as successful as I've been and feel free to ask questions.


----------



## lme@ (Sep 8, 2010)

Thank you, but I don't like the idea of putting executables in [/usr/local]/etc.
Why don't you just use

```
kldload rtl8187Se_sys
```
 in _ndis_start()_?


----------



## rstrcogburn (Sep 8, 2010)

You're absolutely right.  You could just add kldload rtl8187Se_sys the ndis_start() and kldunload rtl8187Se_sys to ndis_stop().

I'm still learning FreeBSD and best practices.  Being a linux user since 04 I have a long way to go.  I'm welcome to any suggestions and improvements.  I'll do an edit, soon to the little HowTo if this would be a cleaner approach.  Note, my original setup is just a clone of /etc/rc.d/local.


----------



## rstrcogburn (Sep 8, 2010)

(EDIT: AUTO-LOADING THE MODULE AT BOOT)


```
%su
| ENTER PASSWORD
| THE FOLLOWING IS ALL ONE COMMAND TO SECOND __EOF__
#cat > /usr/local/etc/rc.d/ndis << __EOF__
#!/bin/sh
#
# /etc/rc.d/ndis,v 1.0.0.0.0.0 2010/09/08 10:20:00 rstrcogburn 
#

# PROVIDE: local
# REQUIRE: DAEMON
# BEFORE:  LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

name="ndis"
start_cmd="ndis_start"
stop_cmd="ndis_stop"

ndis_start()
{
	if [ -f /boot/modules/rtl8187Se_sys.ko ]; then
		echo -n 'Loading ndis modules:'
		kldload rtl8187Se_sys
		echo '.'
	fi
}

ndis_stop()
{
	if [ -f /boot/modules/rtl8187Se_sys.ko ]; then
		echo -n 'Unloading ndis modules:'
		kldunload rtl8187Se_sys
		echo '.'
	fi
}

load_rc_config $name
run_rc_command "$1"
__EOF__

#chmod +x /usr/local/etc/rc.d/ndis
#exit
or
#reboot
^ if wanting to try out the autoloading
```

After lme@'s reccomndendations I've edited the /usr/local/etc/rc.d/ndis script to not depend on the /usr/local/etc/ndis.load & /usr/local etc/ndis.unload scripts because it is no best practices to have executable scripts in your /usr/local/etc folder.

For first time users of this Howto you can substitute this section for the one above.  If you've already done the Howto, you can simply do this section again because it will overwrite /usr/local/etc/rc.d/ndis automatically.  Remove the /usr/local/etc/ndis.load & /usr/local etc/ndis.unload as root and you'll be good to go!


----------



## aepd (Sep 13, 2010)

There's already a much simpler system in place just for this.

In /etc/start_if.ndis0:

```
mod="rtl8187Se_sys"

if ! kldstat -n $mod >/dev/null 2>&1; then
	kldload -q $mod
fi
```

Add to /etc/rc.conf:

```
network_interfaces="ndis0"
wlans_ndis0="wlan0"
ifconfig_wlan0="WPA DHCP up"
```


----------



## rstrcogburn (Sep 13, 2010)

thanx, just what I was needing!


----------



## aepd (Sep 14, 2010)

Apparently /etc/rc.subr has a better function for this:

```
echo "load_kld -m 'pci/ndis_rtl8187Se_sys' 'rtl8187Se_sys'" > \
	/etc/start_if.ndis0
```


----------

