# hostapd awkward problem: WiFi network "vanishes".



## pflynn (Mar 11, 2013)

Hi, 

I have a simple WiFi access point running 9.1-RELEASE (amd64). The WiFi interface is an USB dongle based on the RT3070 chipset. Everything works fine, except for one detail: the WiFi network seems to "vanish" when I boot the access point. But this only happens on the first boot (after I turn on the machine). I posted a video on youtube showing what I can see:

*FreeBSD hostapd awkward problem: WiFi network "vanishes".*
http://www.youtube.com/watch?v=FezGL-M7AUM&feature=youtu.be

The video shows my Android mobile running the WiFi Analizer app while I'm turning on my access point. First, there are only some networks from the neighborhood that are not important but are shown by the app. At 00:25, we can see my network showing up (pink curve), named "wormhole". There is an asterisk to the right of the network name meaning that it is an open (not encrypted) network. This is, I think, just after the rc system scripts finish running the basic setup for my wifi interface:

/etc/rc.conf

```
wlans_run0="wlan0"
create_args_wlan0="wlanmode hostap"
ifconfig_wlan0="inet 192.168.1.1 netmask 255.255.255.0 ssid wormhole"
```

Until now, I think that everything is OK. But at 00:45, the problem shows up: the network simply "vanishes". We can see that the signal curve shrinks until it completely vanishes. I think that it happens exactly when hostapd(8) starts:

/etc/rc.conf

```
hostapd_enable="YES"
```

/etc/hostapd.conf

```
interface=wlan0
ctrl_interface=/var/run/hostapd
ctrl_interface_group=wheel
logger_syslog=-1
logger_syslog_level=4
debug=4
ssid=wormhole
wpa=2
wpa_passphrase=test
wpa_key_mgmt=WPA-PSK
wpa_pairwise=CCMP TKIP
```

Awkward is that, after boot, I can bring the wifi network up just stopping and restarting hostapd(8):


```
# /etc/rc.d/hostapd stop
# /etc/rc.d/hostapd start
```

Sometimes I need to stop/start hostapd(8) just one time, sometimes twice. It is also awkward that after the first boot (when I can't see my network), ifconfig(8) output for wlan0 and run0 are exactly the same as the output when everything is working fine (when I can see the network). Same for hostapd(8) logs. I don't think it is a firmware loading problem, because the system can configure the wifi network, the problem starts only after hostapd(8) starts. Would like to know if anyone has seem something like this.


----------



## pflynn (Mar 14, 2013)

Hi, I noticed something. The problem occurs whenever I remove/insert my Ralink USB Wifi dongle and then hostapd starts immediately or after a short period of time (say, less than 1 minute) after the run0 and wlan0 interfaces are properly configured by the system. So, if I insert the dongle and start hostapd:

`# hostapd -dd /etc/hostapd.conf`

then I have the following output:


```
Configuration file: /etc/hostapd.conf
ctrl_interface_group=0 (from group name 'wheel')
Line 6: DEPRECATED: 'debug' configuration variable is not used anymore
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
Completing interface initialization
Flushing old station entries
Deauthenticate all stations
bsd_set_privacy: enabled=0
bsd_set_key: alg=0 addr=0x0 key_idx=0 set_tx=1 seq_len=0 key_len=0
bsd_del_key: key_idx=0
bsd_set_key: alg=0 addr=0x0 key_idx=1 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=1
bsd_set_key: alg=0 addr=0x0 key_idx=2 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=2
bsd_set_key: alg=0 addr=0x0 key_idx=3 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=3
Using interface wlan0 with hwaddr 00:c0:ca:6d:64:93 and ssid 'wormhole'
Deriving WPA PSK based on passphrase
SSID - hexdump_ascii(len=8):
     77 6f 72 6d 68 6f 6c 65                           wormhole        
PSK (ASCII passphrase) - hexdump_ascii(len=11): [REMOVED]
PSK (from passphrase) - hexdump(len=32): [REMOVED]
bsd_set_ieee8021x: enabled=1
bsd_configure_wpa: enable WPA= 0x2
WPA: group state machine entering state GTK_INIT (VLAN-ID 0)
GMK - hexdump(len=32): [REMOVED]
GTK - hexdump(len=32): [REMOVED]
WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)
bsd_set_key: alg=2 addr=0x0 key_idx=1 set_tx=1 seq_len=0 key_len=32
bsd_set_privacy: enabled=1
bsd_set_opt_ie: set WPA+RSN ie (len 26)
wlan0: Setup of interface done.
Discard routing message to if#180 (not for us 13)

Discard routing message to if#0 (not for us 13)
```

But, if after pluging the dongle, I wait some time (say, 2 minutes) and then I start hostapd:

`# hostapd -dd /etc/hostapd.conf`

then the problem does not occur and hostapd ouput a few more information:


```
Configuration file: /etc/hostapd.conf
ctrl_interface_group=0 (from group name 'wheel')
Line 6: DEPRECATED: 'debug' configuration variable is not used anymore
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
Completing interface initialization
Flushing old station entries
Deauthenticate all stations
bsd_set_privacy: enabled=0
bsd_set_key: alg=0 addr=0x0 key_idx=0 set_tx=1 seq_len=0 key_len=0
bsd_del_key: key_idx=0
bsd_set_key: alg=0 addr=0x0 key_idx=1 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=1
bsd_set_key: alg=0 addr=0x0 key_idx=2 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=2
bsd_set_key: alg=0 addr=0x0 key_idx=3 set_tx=0 seq_len=0 key_len=0
bsd_del_key: key_idx=3
Using interface wlan0 with hwaddr 00:c0:ca:6d:64:93 and ssid 'wormhole'
Deriving WPA PSK based on passphrase
SSID - hexdump_ascii(len=8):
     77 6f 72 6d 68 6f 6c 65                           wormhole        
PSK (ASCII passphrase) - hexdump_ascii(len=11): [REMOVED]
PSK (from passphrase) - hexdump(len=32): [REMOVED]
bsd_set_ieee8021x: enabled=1
bsd_configure_wpa: enable WPA= 0x2
WPA: group state machine entering state GTK_INIT (VLAN-ID 0)
GMK - hexdump(len=32): [REMOVED]
GTK - hexdump(len=32): [REMOVED]
WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)
bsd_set_key: alg=2 addr=0x0 key_idx=1 set_tx=1 seq_len=0 key_len=32
bsd_set_privacy: enabled=1
bsd_set_opt_ie: set WPA+RSN ie (len 26)
wlan0: Setup of interface done.
Discard routing message to if#180 (not for us 13)

Discard routing message to if#0 (not for us 13)

[color="Red"]wlan0: STA b4:07:f9:f1:4d:bc IEEE 802.11: associated
STA included RSN IE in (Re)AssocReq
  New STA
wlan0: STA b4:07:f9:f1:4d:bc WPA: event 1 notification
bsd_set_key: alg=0 addr=0x8014ac550 key_idx=0 set_tx=1 seq_len=0 key_len=0
bsd_del_key: addr=b4:07:f9:f1:4d:bc
wlan0: STA b4:07:f9:f1:4d:bc WPA: start authentication
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state INITIALIZE
bsd_set_key: alg=0 addr=0x8014ac550 key_idx=0 set_tx=1 seq_len=0 key_len=0
bsd_del_key: addr=b4:07:f9:f1:4d:bc
wlan0: STA b4:07:f9:f1:4d:bc IEEE 802.1X: unauthorizing port
WPA: b4:07:f9:f1:4d:bc WPA_PTK_GROUP entering state IDLE
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state AUTHENTICATION
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state AUTHENTICATION2
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state INITPSK
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state PTKSTART
wlan0: STA b4:07:f9:f1:4d:bc WPA: sending 1/4 msg of 4-Way Handshake
WPA: Send EAPOL(version=2 secure=0 mic=0 ack=1 install=0 pairwise=8 kde_len=0 keyidx=0 encr=0)
TX EAPOL - hexdump(len=99): 02 03 00 5f 02 00 8a 00 10 00 00 00 00 00 00 00 01 89 80 28 bd bb 63 14 34 27 7a 4f cd fd a8 9b 2a 1f ab c8 a4 99 99 b1 76 fd 46 a0 81 8d 9b 15 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
IEEE 802.1X: 121 bytes from b4:07:f9:f1:4d:bc
   IEEE 802.1X: version=1 type=3 length=117
wlan0: STA b4:07:f9:f1:4d:bc WPA: received EAPOL-Key frame (2/4 Pairwise)
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state PTKCALCNEGOTIATING
WPA: PTK derivation - A1=00:c0:ca:6d:64:93 A2=b4:07:f9:f1:4d:bc
WPA: PMK - hexdump(len=32): [REMOVED]
WPA: PTK - hexdump(len=48): [REMOVED]
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state PTKCALCNEGOTIATING2
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state PTKINITNEGOTIATING
bsd_get_seqnum: addr=00:00:00:00:00:00 idx=1
wlan0: STA b4:07:f9:f1:4d:bc WPA: sending 3/4 msg of 4-Way Handshake
WPA: Send EAPOL(version=2 secure=1 mic=1 ack=1 install=1 pairwise=8 kde_len=66 keyidx=1 encr=1)
Plaintext EAPOL-Key Key Data - hexdump(len=80): [REMOVED]
TX EAPOL - hexdump(len=179): 02 03 00 af 02 13 ca 00 10 00 00 00 00 00 00 00 02 89 80 28 bd bb 63 14 34 27 7a 4f cd fd a8 9b 2a 1f ab c8 a4 99 99 b1 76 fd 46 a0 81 8d 9b 15 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 e4 e2 e6 0c 5b a8 54 08 1a 55 3e dc 7c 9c 39 21 00 50 61 dc ef 0a 96 1a 40 97 2b 04 b5 c0 f6 7c a9 92 c6 01 1f 03 5b 48 01 28 1e ba fa 20 36 45 65 7f 8f a8 3c 1e c9 bd c5 0f c5 b3 7a 39 ce e5 dd 0e 21 0b b6 30 2e cd e4 3e 0e 3d 2c 3b f8 20 18 fc c9 8a 7a aa 79 7f c9 e7 e9 7b 45 2c ea 15 3c 68
IEEE 802.1X: 99 bytes from b4:07:f9:f1:4d:bc
   IEEE 802.1X: version=1 type=3 length=95
wlan0: STA b4:07:f9:f1:4d:bc WPA: received EAPOL-Key frame (4/4 Pairwise)
WPA: b4:07:f9:f1:4d:bc WPA_PTK entering state PTKINITDONE
bsd_set_key: alg=3 addr=0x8014ac550 key_idx=0 set_tx=1 seq_len=0 key_len=16
AP-STA-CONNECTED b4:07:f9:f1:4d:bc
wlan0: STA b4:07:f9:f1:4d:bc IEEE 802.1X: authorizing port
wlan0: STA b4:07:f9:f1:4d:bc RADIUS: starting accounting session 51424C3E-00000000
bsd_sta_clear_stats: addr=b4:07:f9:f1:4d:bc
wlan0: STA b4:07:f9:f1:4d:bc WPA: pairwise key handshake completed (RSN)[/color]
```

I marked the text output in red where it seems to be different from the first output.

That is it. I will keep trying to figure out what is going on.


----------



## geshuni (Apr 19, 2013)

Have you figured out what is wrong? Because I am running Debian on my home server, and I also have the same problem with my hostapd. Thank you in advance for this thread!


----------



## pflynn (Apr 20, 2013)

No, not yet . But I found that it does not happen with all Ralink 3070 devices. I have a second USB WiFi dongle that does not have this problem. It just works. It is a WN-160 Wireless USB that I bought for my PopCorn Hour Media Center. The device that has the problem is a AWUS036NEH, from Alpha Network. What is the manufacturer and model of your device?


----------

