Search code examples
linuxlinux-device-driverraspberry-pi2hostapd

Unable to authenticate using HostAPD


I have a raspberry PI 2 and have configured HOSTAPD and udhcpd to work as a hot spot. The first issue i faced was the driver. THe WiFi adapter i purchased was a Realtek chip set. This is now solved by following this post. https://www.raspberrypi.org/forums/view ... hp?t=62371

Now the second issue i faced is WPA2 authentication. If i set hostapd for open\no authentication it works like a charm. If i set authentication, i am unable to connect. Andriod devices circle around connecting, iPhone comes back with incorrect password - even thought i am typing correct password.

Below is the config in hostapd.conf and log from hostapd --ddK /etc/hostapd/hostapd.conf

interface=wlan0
#driver=
ssid=<removed>
hw_mode=g
channel=1
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=<removed>
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

#log
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2


pi@raspberrypi ~ $ sudo hostapd -ddK /etc/hostapd/hostapd.conf
random: Trying to read entropy from /dev/random
Configuration file: /etc/hostapd/hostapd.conf
nl80211: interface wlan0 in phy phy0
rfkill: initial event: idx=0 type=1 op=0 soft=0 hard=0
nl80211: Using driver-based off-channel TX
nl80211: Add own interface ifindex 3
nl80211: Set mode ifindex 3 iftype 3 (AP)
nl80211: Create interface iftype 6 (MONITOR)
nl80211: New interface mon.wlan0 created: ifindex=6
nl80211: Add own interface ifindex 6
BSS count 1, BSSID mask 00:00:00:00:00:00 (0 bits)
nl80211: Regulatory information - country=00
nl80211: 2402-2472 @ 40 MHz
nl80211: 2457-2482 @ 20 MHz
nl80211: 2474-2494 @ 20 MHz
nl80211: 5170-5250 @ 80 MHz
nl80211: 5250-5330 @ 80 MHz
nl80211: 5490-5730 @ 160 MHz
nl80211: 5735-5835 @ 80 MHz
nl80211: 57240-63720 @ 2160 MHz
nl80211: Added 802.11b mode based on 802.11g information
Allowed channel: mode=1 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=1 chan=11 freq=2462 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=1 freq=2412 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=2 freq=2417 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=3 freq=2422 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=4 freq=2427 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=5 freq=2432 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=6 freq=2437 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=7 freq=2442 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=8 freq=2447 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=9 freq=2452 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=10 freq=2457 MHz max_tx_power=20 dBm
Allowed channel: mode=0 chan=11 freq=2462 MHz max_tx_power=20 dBm
Completing interface initialization
Mode: IEEE 802.11g  Channel: 1  Frequency: 2412 MHz
nl80211: Set freq 2412 (ht_enabled=0 sec_channel_offset=0)
RATE[0] rate=10 flags=0x1
RATE[1] rate=20 flags=0x1
RATE[2] rate=55 flags=0x1
RATE[3] rate=110 flags=0x1
RATE[4] rate=60 flags=0x0
RATE[5] rate=90 flags=0x0
RATE[6] rate=120 flags=0x0
RATE[7] rate=180 flags=0x0
RATE[8] rate=240 flags=0x0
RATE[9] rate=360 flags=0x0
RATE[10] rate=480 flags=0x0
RATE[11] rate=540 flags=0x0
Flushing old station entries
Deauthenticate all stations
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=(nil) key_idx=0 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=(nil) key_idx=1 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=(nil) key_idx=2 set_tx=0 seq_len=0 key_len=0
wpa_driver_nl80211_set_key: ifindex=3 alg=0 addr=(nil) key_idx=3 set_tx=0 seq_len=0 key_len=0
Using interface wlan0 with hwaddr 40:a5:ef:07:b4:0e and ssid 'kid'
Deriving WPA PSK based on passphrase
SSID - hexdump_ascii(len=3):
     6b 69 64                                          <removed>             
PSK (ASCII passphrase) - hexdump_ascii(len=8):
     4b 69 64 31 32 33 34 35                           <removed>       
PSK (from passphrase) - hexdump(len=32): eb f3 9f 60 48 03 d8 c2 6d 29 b5 34 1f 22 fe cd 02 ff 43 6e 7e 35 88 d9 41 49 42 27 26 c5 08 ad
random: Got 16/20 bytes from /dev/random
random: Only 16/20 bytes of strong random data available from /dev/random
random: Not enough entropy pool available for secure operations
WPA: Not enough entropy in random pool for secure operations - update keys later when the first station connects
Get randomness: len=32 entropy=0
GMK - hexdump(len=32): 8b 1b 05 6b 6c a3 27 3b 7d 4c 8d 08 75 c0 94 2e e9 ad cd 06 90 6b c3 8f 10 74 96 6e 07 a7 44 b7
Get randomness: len=32 entropy=0
Key Counter - hexdump(len=32): 8d 5d 7d 92 d4 6c 8b 56 cd f2 10 a6 4a ba 4f c9 96 1d 93 28 db d2 3b 1d e2 a2 74 02 c8 41 cf 26
WPA: Delay group state machine start until Beacon frames have been configured
VLAN: vlan_set_name_type(name_type=2)
nl80211: Set beacon (beacon_set=0)
WPA: Start group state machine to set initial keys
WPA: group state machine entering state GTK_INIT (VLAN-ID 0)
Get randomness: len=16 entropy=0
GTK - hexdump(len=16): ba 94 df 43 2f 11 50 e1 86 45 25 87 fb 9a f3 b8
WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)
wpa_driver_nl80211_set_key: ifindex=3 alg=3 addr=0x890c8 key_idx=1 set_tx=1 seq_len=0 key_len=16
   broadcast key
wpa_driver_nl80211_set_operstate: operstate 0->1 (UP)
netlink: Operstate: linkmode=-1, operstate=6
Failed to set TX queue parameters for queue 0.
Failed to set TX queue parameters for queue 1.
Failed to set TX queue parameters for queue 2.
Failed to set TX queue parameters for queue 3.
wlan0: Setup of interface done.
random: Got 4/4 bytes from /dev/random
RTM_NEWLINK: operstate=1 ifi_flags=0x1002 ()
nl80211: Ignore interface down event since interface wlan0 is up
RTM_NEWLINK: operstate=1 ifi_flags=0x1002 ()
nl80211: Ignore interface down event since interface mon.wlan0 is up
RTM_NEWLINK: operstate=1 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
RTM_NEWLINK, IFLA_IFNAME: Interface 'mon.wlan0' added
Unknown event 5
RTM_NEWLINK: operstate=1 ifi_flags=0x1003 ([UP])
RTM_NEWLINK, IFLA_IFNAME: Interface 'wlan0' added
nl80211: if_removed already cleared - ignore event
RTM_NEWLINK: operstate=1 ifi_flags=0x11043 ([UP][RUNNING][LOWER_UP])
RTM_NEWLINK, IFLA_IFNAME: Interface 'wlan0' added
nl80211: if_removed already cleared - ignore event
VLAN: vlan_newlink(wlan0)
nl80211: Event message available
nl80211: New station <iphone MAC address>
nl80211: Event message available
nl80211: Delete station <iphone MAC address>
wlan0: WPA rekeying GTK
WPA: group state machine entering state SETKEYS (VLAN-ID 0)
Get randomness: len=16 entropy=0
GTK - hexdump(len=16): 06 b2 b8 05 a7 b6 a6 03 81 1b a4 9a 01 bb 8c 29
wpa_group_setkeys: GKeyDoneStations=0
WPA: group state machine entering state SETKEYSDONE (VLAN-ID 0)
wpa_driver_nl80211_set_key: ifindex=3 alg=3 addr=0x890c8 key_idx=2 set_tx=1 seq_len=0 key_len=16
   broadcast key
^CSignal 2 received - terminating
Flushing old station entries
Deauthenticate all stations
nl80211: Remove interface ifindex=6
netlink: Operstate: linkmode=0, operstate=6
nl80211: Set mode ifindex 3 iftype 2 (STATION)

I have tried uninstall and reinstall hostapd


Solution

  • I didn't see a DHCP server mentioned - this is a critical piece of infrastructure for setting up a wireless network with hostapd. More information is provided below the line break on setting up a DHCP server. Before covering that, though, here are a few links with more general information. All links are to charlesreid1.com/wiki. I used them to document my process for setting up the Raspberry Pi as a wireless access point. All pages are referring to using the Raspberry Pi to create a wifi network/access point:

    Below is some information on setting up a DHCP server specifically, in case that's the issue with setting up your Raspberry Pi as a wireless AP.


    Set up a DHCP server by editing /etc/dhcp/dhcp.conf.

    First, add the word "authoritative", which indicates this is the authoritative DHCP on the network. (You should see some comments and lines already filled out in the DHCP config file that is installed onto the Raspberry Pi by default):

      # If this DHCP server is the official DHCP server for the local
      # network, the authoritative directive should be uncommented.
      authoritative;
    

    Uncomment authoritative.

    Then add a block in the DHCP config file to set up the IP address assignment/configuration. I'm using the IP subnet 192.168.42.X on my home network.

      subnet 192.168.42.0 netmask 255.255.255.0 {
        range 192.168.42.10 192.168.42.50;
        option broadcast-address 192.168.42.255;
        option routers 192.168.42.1;
        default-lease-time 600;
        max-lease-time 7200;
        option domain-name "local";
        option domain-name-servers 8.8.8.8, 8.8.4.4;
      }
    

    You don't need all those options, but give it a try.

    Next you'll need to tell the DHCP server which interface to use, so you can edit /etc/default/isc-dhcp-server and update the INTERFACES section to point to your specific interface:

    INTERFACES="wlan0"
    

    Now you'll need to update your network interface so it knows not to try and look for an IP address. Bring the interface down,

    $ sudo ifdown wlan0
    

    Then edit /etc/network/interfaces and manually specify the Pi's IP address to be the gateway address (again I'm using 192.168.42.X schema but you can use any that you'd like, as long as it matches the DHCP config file mentioned above):

    allow-hotplug wlan0
    
    iface wlan0 inet static
        address 192.168.42.1
        netmask 255.255.255.0
    

    The last step is then editing your hostapd.conf file, which you've already done. Here's what it looks like with WPA2 enabled (looks like you've already got this part figured out and working though):

    interface=wlan0
    driver=<insert driver here>
    ssid=<insert SSID here>
    hw_mode=g
    channel=6
    macaddr_acl=0
    auth_algs=1
    ignore_broadcast_ssid=0
    wpa=2
    wpa_passphrase=<insert passphrase here>
    wpa_key_mgmt=WPA-PSK
    wpa_pairwise=TKIP
    rsn_pairwise=CCMP
    

    Hope some of this information can be of use... happy hacking!