18dbcf02cSchristoshostapd and Wi-Fi Protected Setup (WPS) 28dbcf02cSchristos======================================= 38dbcf02cSchristos 48dbcf02cSchristosThis document describes how the WPS implementation in hostapd can be 58dbcf02cSchristosconfigured and how an external component on an AP (e.g., web UI) is 68dbcf02cSchristosused to enable enrollment of client devices. 78dbcf02cSchristos 88dbcf02cSchristos 98dbcf02cSchristosIntroduction to WPS 108dbcf02cSchristos------------------- 118dbcf02cSchristos 128dbcf02cSchristosWi-Fi Protected Setup (WPS) is a mechanism for easy configuration of a 138dbcf02cSchristoswireless network. It allows automated generation of random keys (WPA 148dbcf02cSchristospassphrase/PSK) and configuration of an access point and client 158dbcf02cSchristosdevices. WPS includes number of methods for setting up connections 168dbcf02cSchristoswith PIN method and push-button configuration (PBC) being the most 178dbcf02cSchristoscommonly deployed options. 188dbcf02cSchristos 198dbcf02cSchristosWhile WPS can enable more home networks to use encryption in the 208dbcf02cSchristoswireless network, it should be noted that the use of the PIN and 218dbcf02cSchristosespecially PBC mechanisms for authenticating the initial key setup is 228dbcf02cSchristosnot very secure. As such, use of WPS may not be suitable for 238dbcf02cSchristosenvironments that require secure network access without chance for 248dbcf02cSchristosallowing outsiders to gain access during the setup phase. 258dbcf02cSchristos 268dbcf02cSchristosWPS uses following terms to describe the entities participating in the 278dbcf02cSchristosnetwork setup: 288dbcf02cSchristos- access point: the WLAN access point 298dbcf02cSchristos- Registrar: a device that control a network and can authorize 308dbcf02cSchristos addition of new devices); this may be either in the AP ("internal 318dbcf02cSchristos Registrar") or in an external device, e.g., a laptop, ("external 328dbcf02cSchristos Registrar") 338dbcf02cSchristos- Enrollee: a device that is being authorized to use the network 348dbcf02cSchristos 358dbcf02cSchristosIt should also be noted that the AP and a client device may change 368dbcf02cSchristosroles (i.e., AP acts as an Enrollee and client device as a Registrar) 378dbcf02cSchristoswhen WPS is used to configure the access point. 388dbcf02cSchristos 398dbcf02cSchristos 408dbcf02cSchristosMore information about WPS is available from Wi-Fi Alliance: 418dbcf02cSchristoshttp://www.wi-fi.org/wifi-protected-setup 428dbcf02cSchristos 438dbcf02cSchristos 448dbcf02cSchristoshostapd implementation 458dbcf02cSchristos---------------------- 468dbcf02cSchristos 478dbcf02cSchristoshostapd includes an optional WPS component that can be used as an 488dbcf02cSchristosinternal WPS Registrar to manage addition of new WPS enabled clients 498dbcf02cSchristosto the network. In addition, WPS Enrollee functionality in hostapd can 508dbcf02cSchristosbe used to allow external WPS Registrars to configure the access 518dbcf02cSchristospoint, e.g., for initial network setup. In addition, hostapd can proxy a 528dbcf02cSchristosWPS registration between a wireless Enrollee and an external Registrar 538dbcf02cSchristos(e.g., Microsoft Vista or Atheros JumpStart) with UPnP. 548dbcf02cSchristos 558dbcf02cSchristos 568dbcf02cSchristoshostapd configuration 578dbcf02cSchristos--------------------- 588dbcf02cSchristos 598dbcf02cSchristosWPS is an optional component that needs to be enabled in hostapd build 608dbcf02cSchristosconfiguration (.config). Here is an example configuration that 61*bb610346Schristosincludes WPS support and uses nl80211 driver interface: 628dbcf02cSchristos 63*bb610346SchristosCONFIG_DRIVER_NL80211=y 648dbcf02cSchristosCONFIG_WPS=y 658dbcf02cSchristosCONFIG_WPS_UPNP=y 668dbcf02cSchristos 67e604d861SchristosFollowing parameter can be used to enable support for NFC config method: 68e604d861Schristos 69e604d861SchristosCONFIG_WPS_NFC=y 70e604d861Schristos 718dbcf02cSchristos 728dbcf02cSchristosFollowing section shows an example runtime configuration 738dbcf02cSchristos(hostapd.conf) that enables WPS: 748dbcf02cSchristos 758dbcf02cSchristos# Configure the driver and network interface 76*bb610346Schristosdriver=nl80211 77*bb610346Schristosinterface=wlan0 788dbcf02cSchristos 798dbcf02cSchristos# WPA2-Personal configuration for the AP 808dbcf02cSchristosssid=wps-test 818dbcf02cSchristoswpa=2 828dbcf02cSchristoswpa_key_mgmt=WPA-PSK 838dbcf02cSchristoswpa_pairwise=CCMP 848dbcf02cSchristos# Default WPA passphrase for legacy (non-WPS) clients 858dbcf02cSchristoswpa_passphrase=12345678 868dbcf02cSchristos# Enable random per-device PSK generation for WPS clients 878dbcf02cSchristos# Please note that the file has to exists for hostapd to start (i.e., create an 888dbcf02cSchristos# empty file as a starting point). 898dbcf02cSchristoswpa_psk_file=/etc/hostapd.psk 908dbcf02cSchristos 918dbcf02cSchristos# Enable control interface for PBC/PIN entry 928dbcf02cSchristosctrl_interface=/var/run/hostapd 938dbcf02cSchristos 948dbcf02cSchristos# Enable internal EAP server for EAP-WSC (part of Wi-Fi Protected Setup) 958dbcf02cSchristoseap_server=1 968dbcf02cSchristos 978dbcf02cSchristos# WPS configuration (AP configured, do not allow external WPS Registrars) 988dbcf02cSchristoswps_state=2 998dbcf02cSchristosap_setup_locked=1 1008dbcf02cSchristos# If UUID is not configured, it will be generated based on local MAC address. 1018dbcf02cSchristosuuid=87654321-9abc-def0-1234-56789abc0000 1028dbcf02cSchristoswps_pin_requests=/var/run/hostapd.pin-req 1038dbcf02cSchristosdevice_name=Wireless AP 1048dbcf02cSchristosmanufacturer=Company 1058dbcf02cSchristosmodel_name=WAP 1068dbcf02cSchristosmodel_number=123 1078dbcf02cSchristosserial_number=12345 1088dbcf02cSchristosdevice_type=6-0050F204-1 1098dbcf02cSchristosos_version=01020300 1108dbcf02cSchristosconfig_methods=label display push_button keypad 1118dbcf02cSchristos 1128dbcf02cSchristos# if external Registrars are allowed, UPnP support could be added: 1138dbcf02cSchristos#upnp_iface=br0 1148dbcf02cSchristos#friendly_name=WPS Access Point 1158dbcf02cSchristos 1168dbcf02cSchristos 1178dbcf02cSchristosExternal operations 1188dbcf02cSchristos------------------- 1198dbcf02cSchristos 1208dbcf02cSchristosWPS requires either a device PIN code (usually, 8-digit number) or a 1218dbcf02cSchristospushbutton event (for PBC) to allow a new WPS Enrollee to join the 1228dbcf02cSchristosnetwork. hostapd uses the control interface as an input channel for 1238dbcf02cSchristosthese events. 1248dbcf02cSchristos 125111b9fd8SchristosThe PIN value used in the commands must be processed by an UI to 126111b9fd8Schristosremove non-digit characters and potentially, to verify the checksum 127111b9fd8Schristosdigit. "hostapd_cli wps_check_pin <PIN>" can be used to do such 128111b9fd8Schristosprocessing. It returns FAIL if the PIN is invalid, or FAIL-CHECKSUM if 129111b9fd8Schristosthe checksum digit is incorrect, or the processed PIN (non-digit 130111b9fd8Schristoscharacters removed) if the PIN is valid. 131111b9fd8Schristos 1328dbcf02cSchristosWhen a client device (WPS Enrollee) connects to hostapd (WPS 1338dbcf02cSchristosRegistrar) in order to start PIN mode negotiation for WPS, an 1348dbcf02cSchristosidentifier (Enrollee UUID) is sent. hostapd will need to be configured 1358dbcf02cSchristoswith a device password (PIN) for this Enrollee. This is an operation 1368dbcf02cSchristosthat requires user interaction (assuming there are no pre-configured 1378dbcf02cSchristosPINs on the AP for a set of Enrollee). 1388dbcf02cSchristos 1398dbcf02cSchristosThe PIN request with information about the device is appended to the 1408dbcf02cSchristoswps_pin_requests file (/var/run/hostapd.pin-req in this example). In 1418dbcf02cSchristosaddition, hostapd control interface event is sent as a notification of 1428dbcf02cSchristosa new device. The AP could use, e.g., a web UI for showing active 1438dbcf02cSchristosEnrollees to the user and request a PIN for an Enrollee. 1448dbcf02cSchristos 1458dbcf02cSchristosThe PIN request file has one line for every Enrollee that connected to 1468dbcf02cSchristosthe AP, but for which there was no PIN. Following information is 1478dbcf02cSchristosprovided for each Enrollee (separated with tabulators): 1488dbcf02cSchristos- timestamp (seconds from 1970-01-01) 1498dbcf02cSchristos- Enrollee UUID 1508dbcf02cSchristos- MAC address 1518dbcf02cSchristos- Device name 1528dbcf02cSchristos- Manufacturer 1538dbcf02cSchristos- Model Name 1548dbcf02cSchristos- Model Number 1558dbcf02cSchristos- Serial Number 1568dbcf02cSchristos- Device category 1578dbcf02cSchristos 1588dbcf02cSchristosExample line in the /var/run/hostapd.pin-req file: 1598dbcf02cSchristos1200188391 53b63a98-d29e-4457-a2ed-094d7e6a669c Intel(R) Centrino(R) Intel Corporation Intel(R) Centrino(R) - - 1-0050F204-1 1608dbcf02cSchristos 1618dbcf02cSchristosControl interface data: 1628dbcf02cSchristosWPS-PIN-NEEDED [UUID-E|MAC Address|Device Name|Manufacturer|Model Name|Model Number|Serial Number|Device Category] 1638dbcf02cSchristosFor example: 1648dbcf02cSchristos<2>WPS-PIN-NEEDED [53b63a98-d29e-4457-a2ed-094d7e6a669c|02:12:34:56:78:9a|Device|Manuf|Model|Model Number|Serial Number|1-0050F204-1] 1658dbcf02cSchristos 1668dbcf02cSchristosWhen the user enters a PIN for a pending Enrollee, e.g., on the web 1678dbcf02cSchristosUI), hostapd needs to be notified of the new PIN over the control 1688dbcf02cSchristosinterface. This can be done either by using the UNIX domain socket 1698dbcf02cSchristos-based control interface directly (src/common/wpa_ctrl.c provides 1708dbcf02cSchristoshelper functions for using the interface) or by calling hostapd_cli. 1718dbcf02cSchristos 1728dbcf02cSchristosExample command to add a PIN (12345670) for an Enrollee: 1738dbcf02cSchristos 1748dbcf02cSchristoshostapd_cli wps_pin 53b63a98-d29e-4457-a2ed-094d7e6a669c 12345670 1758dbcf02cSchristos 1768dbcf02cSchristosIf the UUID-E is not available (e.g., Enrollee waits for the Registrar 1778dbcf02cSchristosto be selected before connecting), wildcard UUID may be used to allow 1788dbcf02cSchristosthe PIN to be used once with any UUID: 1798dbcf02cSchristos 1808dbcf02cSchristoshostapd_cli wps_pin any 12345670 1818dbcf02cSchristos 1828dbcf02cSchristosTo reduce likelihood of PIN being used with other devices or of 1838dbcf02cSchristosforgetting an active PIN available for potential attackers, expiration 184111b9fd8Schristostime in seconds can be set for the new PIN (value 0 indicates no 185111b9fd8Schristosexpiration): 1868dbcf02cSchristos 1878dbcf02cSchristoshostapd_cli wps_pin any 12345670 300 1888dbcf02cSchristos 189111b9fd8SchristosIf the MAC address of the enrollee is known, it should be configured 190111b9fd8Schristosto allow the AP to advertise list of authorized enrollees: 191111b9fd8Schristos 192111b9fd8Schristoshostapd_cli wps_pin 53b63a98-d29e-4457-a2ed-094d7e6a669c \ 193111b9fd8Schristos 12345670 300 00:11:22:33:44:55 194111b9fd8Schristos 1958dbcf02cSchristos 1968dbcf02cSchristosAfter this, the Enrollee can connect to the AP again and complete WPS 1978dbcf02cSchristosnegotiation. At that point, a new, random WPA PSK is generated for the 1988dbcf02cSchristosclient device and the client can then use that key to connect to the 1998dbcf02cSchristosAP to access the network. 2008dbcf02cSchristos 2018dbcf02cSchristos 2028dbcf02cSchristosIf the AP includes a pushbutton, WPS PBC mode can be used. It is 2038dbcf02cSchristosenabled by pushing a button on both the AP and the client at about the 2048dbcf02cSchristossame time (2 minute window). hostapd needs to be notified about the AP 2058dbcf02cSchristosbutton pushed event over the control interface, e.g., by calling 2068dbcf02cSchristoshostapd_cli: 2078dbcf02cSchristos 2088dbcf02cSchristoshostapd_cli wps_pbc 2098dbcf02cSchristos 2108dbcf02cSchristosAt this point, the client has two minutes to complete WPS negotiation 2118dbcf02cSchristoswhich will generate a new WPA PSK in the same way as the PIN method 2128dbcf02cSchristosdescribed above. 2138dbcf02cSchristos 2148dbcf02cSchristos 215e6e4448bSchristosWhen an external Registrar is used, the AP can act as an Enrollee and 216e6e4448bSchristosuse its AP PIN. A static AP PIN (e.g., one one a label in the AP 217e6e4448bSchristosdevice) can be configured in hostapd.conf (ap_pin parameter). A more 218e6e4448bSchristossecure option is to use hostapd_cli wps_ap_pin command to enable the 219e6e4448bSchristosAP PIN only based on user action (and even better security by using a 220e6e4448bSchristosrandom AP PIN for each session, i.e., by using "wps_ap_pin random" 221e6e4448bSchristoscommand with a timeout value). Following commands are available for 222e6e4448bSchristosmanaging the dynamic AP PIN operations: 223e6e4448bSchristos 224e6e4448bSchristoshostapd_cli wps_ap_pin disable 225e6e4448bSchristos- disable AP PIN (i.e., do not allow external Registrars to use it to 226e6e4448bSchristos learn the current AP settings or to reconfigure the AP) 227e6e4448bSchristos 228e6e4448bSchristoshostapd_cli wps_ap_pin random [timeout] 229e6e4448bSchristos- generate a random AP PIN and enable it 230e6e4448bSchristos- if the optional timeout parameter is given, the AP PIN will be enabled 231e6e4448bSchristos for the specified number of seconds 232e6e4448bSchristos 233e6e4448bSchristoshostapd_cli wps_ap_pin get 234e6e4448bSchristos- fetch the current AP PIN 235e6e4448bSchristos 236e6e4448bSchristoshostapd_cli wps_ap_pin set <PIN> [timeout] 237e6e4448bSchristos- set the AP PIN and enable it 238e6e4448bSchristos- if the optional timeout parameter is given, the AP PIN will be enabled 239e6e4448bSchristos for the specified number of seconds 240e6e4448bSchristos 241111b9fd8Schristoshostapd_cli get_config 242111b9fd8Schristos- display the current configuration 243111b9fd8Schristos 244111b9fd8Schristoshostapd_cli wps_config <new SSID> <auth> <encr> <new key> 245111b9fd8Schristosexamples: 246111b9fd8Schristos hostapd_cli wps_config testing WPA2PSK CCMP 12345678 247111b9fd8Schristos hostapd_cli wps_config "no security" OPEN NONE "" 248111b9fd8Schristos 249111b9fd8Schristos<auth> must be one of the following: OPEN WPAPSK WPA2PSK 250111b9fd8Schristos<encr> must be one of the following: NONE WEP TKIP CCMP 251111b9fd8Schristos 252e6e4448bSchristos 2538dbcf02cSchristosCredential generation and configuration changes 2548dbcf02cSchristos----------------------------------------------- 2558dbcf02cSchristos 2568dbcf02cSchristosBy default, hostapd generates credentials for Enrollees and processing 2578dbcf02cSchristosAP configuration updates internally. However, it is possible to 2588dbcf02cSchristoscontrol these operations from external programs, if desired. 2598dbcf02cSchristos 2608dbcf02cSchristosThe internal credential generation can be disabled with 2618dbcf02cSchristosskip_cred_build=1 option in the configuration. extra_cred option will 2628dbcf02cSchristosthen need to be used to provide pre-configured Credential attribute(s) 2638dbcf02cSchristosfor hostapd to use. The exact data from this binary file will be sent, 2648dbcf02cSchristosi.e., it will have to include valid WPS attributes. extra_cred can 2658dbcf02cSchristosalso be used to add additional networks if the Registrar is used to 2668dbcf02cSchristosconfigure credentials for multiple networks. 2678dbcf02cSchristos 2688dbcf02cSchristosProcessing of received configuration updates can be disabled with 2698dbcf02cSchristoswps_cred_processing=1 option. When this is used, an external program 2708dbcf02cSchristosis responsible for creating hostapd configuration files and processing 2718dbcf02cSchristosconfiguration updates based on messages received from hostapd over 2728dbcf02cSchristoscontrol interface. This will also include the initial configuration on 2738dbcf02cSchristosfirst successful registration if the AP is initially set in 2748dbcf02cSchristosunconfigured state. 2758dbcf02cSchristos 2768dbcf02cSchristosFollowing control interface messages are sent out for external programs: 2778dbcf02cSchristos 2788dbcf02cSchristosWPS-REG-SUCCESS <Enrollee MAC address <UUID-E> 2798dbcf02cSchristosFor example: 2808dbcf02cSchristos<2>WPS-REG-SUCCESS 02:66:a0:ee:17:27 2b7093f1-d6fb-5108-adbb-bea66bb87333 2818dbcf02cSchristos 282111b9fd8SchristosThis can be used to trigger change from unconfigured to configured 2838dbcf02cSchristosstate (random configuration based on the first successful WPS 2848dbcf02cSchristosregistration). In addition, this can be used to update AP UI about the 2858dbcf02cSchristosstatus of WPS registration progress. 2868dbcf02cSchristos 2878dbcf02cSchristos 2888dbcf02cSchristosWPS-NEW-AP-SETTINGS <hexdump of AP Setup attributes> 2898dbcf02cSchristosFor example: 2908dbcf02cSchristos<2>WPS-NEW-AP-SETTINGS 10260001011045000c6a6b6d2d7770732d74657374100300020020100f00020008102700403065346230343536633236366665306433396164313535346131663462663731323433376163666462376633393965353466316631623032306164343438623510200006024231cede15101e000844 2918dbcf02cSchristos 2928dbcf02cSchristosThis can be used to update the externally stored AP configuration and 2938dbcf02cSchristosthen update hostapd configuration (followed by restarting of hostapd). 294e604d861Schristos 295e604d861Schristos 296e604d861SchristosWPS with NFC 297e604d861Schristos------------ 298e604d861Schristos 299e604d861SchristosWPS can be used with NFC-based configuration method. An NFC tag 300e604d861Schristoscontaining a password token from the Enrollee can be used to 301e604d861Schristosauthenticate the connection instead of the PIN. In addition, an NFC tag 302e604d861Schristoswith a configuration token can be used to transfer AP settings without 303e604d861Schristosgoing through the WPS protocol. 304e604d861Schristos 305e604d861SchristosWhen the AP acts as an Enrollee, a local NFC tag with a password token 306e604d861Schristoscan be used by touching the NFC interface of an external Registrar. The 307e604d861Schristoswps_nfc_token command is used to manage use of the NFC password token 308e604d861Schristosfrom the AP. "wps_nfc_token enable" enables the use of the AP's NFC 309e604d861Schristospassword token (in place of AP PIN) and "wps_nfc_token disable" disables 310e604d861Schristosthe NFC password token. 311e604d861Schristos 312e604d861SchristosThe NFC password token that is either pre-configured in the 313e604d861Schristosconfiguration file (wps_nfc_dev_pw_id, wps_nfc_dh_pubkey, 314e604d861Schristoswps_nfc_dh_privkey, wps_nfc_dev_pw) or generated dynamically with 315e604d861Schristos"wps_nfc_token <WPS|NDEF>" command. The nfc_pw_token tool from 316e604d861Schristoswpa_supplicant can be used to generate NFC password tokens during 317e604d861Schristosmanufacturing (each AP needs to have its own random keys). 318e604d861Schristos 319e604d861SchristosThe "wps_nfc_config_token <WPS/NDEF>" command can be used to build an 320e604d861SchristosNFC configuration token. The output value from this command is a hexdump 321e604d861Schristosof the current AP configuration (WPS parameter requests this to include 322e604d861Schristosonly the WPS attributes; NDEF parameter requests additional NDEF 323e604d861Schristosencapsulation to be included). This data needs to be written to an NFC 324e604d861Schristostag with an external program. Once written, the NFC configuration token 325e604d861Schristoscan be used to touch an NFC interface on a station to provision the 326e604d861Schristoscredentials needed to access the network. 327e604d861Schristos 328e604d861SchristosWhen the NFC device on the AP reads an NFC tag with a MIME media type 329e604d861Schristos"application/vnd.wfa.wsc", the NDEF message payload (with or without 330e604d861SchristosNDEF encapsulation) can be delivered to hostapd using the 331e604d861Schristosfollowing hostapd_cli command: 332e604d861Schristos 333e604d861Schristoswps_nfc_tag_read <hexdump of payload> 334e604d861Schristos 335e604d861SchristosIf the NFC tag contains a password token, the token is added to the 336e604d861Schristosinternal Registrar. This allows station Enrollee from which the password 337e604d861Schristostoken was received to run through WPS protocol to provision the 338e604d861Schristoscredential. 3393c260e60Schristos 3403c260e60Schristos"nfc_get_handover_sel <NDEF> <WPS>" command can be used to build the 3413c260e60Schristoscontents of a Handover Select Message for connection handover when this 3423c260e60Schristosdoes not depend on the contents of the Handover Request Message. The 3433c260e60Schristosfirst argument selects the format of the output data and the second 3443c260e60Schristosargument selects which type of connection handover is requested (WPS = 3453c260e60SchristosWi-Fi handover as specified in WSC 2.0). 3463c260e60Schristos 3473c260e60Schristos"nfc_report_handover <INIT/RESP> WPS <carrier from handover request> 3483c260e60Schristos<carrier from handover select>" is used to report completed NFC 3493c260e60Schristosconnection handover. The first parameter indicates whether the local 3503c260e60Schristosdevice initiated or responded to the connection handover and the carrier 3513c260e60Schristosrecords are the selected carrier from the handover request and select 3523c260e60Schristosmessages as a hexdump. 353