1hostapd and Wi-Fi Protected Setup (WPS)
2=======================================
3
4This document describes how the WPS implementation in hostapd can be
5configured and how an external component on an AP (e.g., web UI) is
6used to enable enrollment of client devices.
7
8
9Introduction to WPS
10-------------------
11
12Wi-Fi Protected Setup (WPS) is a mechanism for easy configuration of a
13wireless network. It allows automated generation of random keys (WPA
14passphrase/PSK) and configuration of an access point and client
15devices. WPS includes number of methods for setting up connections
16with PIN method and push-button configuration (PBC) being the most
17commonly deployed options.
18
19While WPS can enable more home networks to use encryption in the
20wireless network, it should be noted that the use of the PIN and
21especially PBC mechanisms for authenticating the initial key setup is
22not very secure. As such, use of WPS may not be suitable for
23environments that require secure network access without chance for
24allowing outsiders to gain access during the setup phase.
25
26WPS uses following terms to describe the entities participating in the
27network setup:
28- access point: the WLAN access point
29- Registrar: a device that control a network and can authorize
30  addition of new devices); this may be either in the AP ("internal
31  Registrar") or in an external device, e.g., a laptop, ("external
32  Registrar")
33- Enrollee: a device that is being authorized to use the network
34
35It should also be noted that the AP and a client device may change
36roles (i.e., AP acts as an Enrollee and client device as a Registrar)
37when WPS is used to configure the access point.
38
39
40More information about WPS is available from Wi-Fi Alliance:
41http://www.wi-fi.org/wifi-protected-setup
42
43
44hostapd implementation
45----------------------
46
47hostapd includes an optional WPS component that can be used as an
48internal WPS Registrar to manage addition of new WPS enabled clients
49to the network. In addition, WPS Enrollee functionality in hostapd can
50be used to allow external WPS Registrars to configure the access
51point, e.g., for initial network setup. In addition, hostapd can proxy a
52WPS registration between a wireless Enrollee and an external Registrar
53(e.g., Microsoft Vista or Atheros JumpStart) with UPnP.
54
55
56hostapd configuration
57---------------------
58
59WPS is an optional component that needs to be enabled in hostapd build
60configuration (.config). Here is an example configuration that
61includes WPS support and uses madwifi driver interface:
62
63CONFIG_DRIVER_MADWIFI=y
64CFLAGS += -I/usr/src/madwifi-0.9.3
65CONFIG_WPS=y
66CONFIG_WPS_UPNP=y
67
68Following parameter can be used to enable support for NFC config method:
69
70CONFIG_WPS_NFC=y
71
72
73Following section shows an example runtime configuration
74(hostapd.conf) that enables WPS:
75
76# Configure the driver and network interface
77driver=madwifi
78interface=ath0
79
80# WPA2-Personal configuration for the AP
81ssid=wps-test
82wpa=2
83wpa_key_mgmt=WPA-PSK
84wpa_pairwise=CCMP
85# Default WPA passphrase for legacy (non-WPS) clients
86wpa_passphrase=12345678
87# Enable random per-device PSK generation for WPS clients
88# Please note that the file has to exists for hostapd to start (i.e., create an
89# empty file as a starting point).
90wpa_psk_file=/etc/hostapd.psk
91
92# Enable control interface for PBC/PIN entry
93ctrl_interface=/var/run/hostapd
94
95# Enable internal EAP server for EAP-WSC (part of Wi-Fi Protected Setup)
96eap_server=1
97
98# WPS configuration (AP configured, do not allow external WPS Registrars)
99wps_state=2
100ap_setup_locked=1
101# If UUID is not configured, it will be generated based on local MAC address.
102uuid=87654321-9abc-def0-1234-56789abc0000
103wps_pin_requests=/var/run/hostapd.pin-req
104device_name=Wireless AP
105manufacturer=Company
106model_name=WAP
107model_number=123
108serial_number=12345
109device_type=6-0050F204-1
110os_version=01020300
111config_methods=label display push_button keypad
112
113# if external Registrars are allowed, UPnP support could be added:
114#upnp_iface=br0
115#friendly_name=WPS Access Point
116
117
118External operations
119-------------------
120
121WPS requires either a device PIN code (usually, 8-digit number) or a
122pushbutton event (for PBC) to allow a new WPS Enrollee to join the
123network. hostapd uses the control interface as an input channel for
124these events.
125
126The PIN value used in the commands must be processed by an UI to
127remove non-digit characters and potentially, to verify the checksum
128digit. "hostapd_cli wps_check_pin <PIN>" can be used to do such
129processing. It returns FAIL if the PIN is invalid, or FAIL-CHECKSUM if
130the checksum digit is incorrect, or the processed PIN (non-digit
131characters removed) if the PIN is valid.
132
133When a client device (WPS Enrollee) connects to hostapd (WPS
134Registrar) in order to start PIN mode negotiation for WPS, an
135identifier (Enrollee UUID) is sent. hostapd will need to be configured
136with a device password (PIN) for this Enrollee. This is an operation
137that requires user interaction (assuming there are no pre-configured
138PINs on the AP for a set of Enrollee).
139
140The PIN request with information about the device is appended to the
141wps_pin_requests file (/var/run/hostapd.pin-req in this example). In
142addition, hostapd control interface event is sent as a notification of
143a new device. The AP could use, e.g., a web UI for showing active
144Enrollees to the user and request a PIN for an Enrollee.
145
146The PIN request file has one line for every Enrollee that connected to
147the AP, but for which there was no PIN. Following information is
148provided for each Enrollee (separated with tabulators):
149- timestamp (seconds from 1970-01-01)
150- Enrollee UUID
151- MAC address
152- Device name
153- Manufacturer
154- Model Name
155- Model Number
156- Serial Number
157- Device category
158
159Example line in the /var/run/hostapd.pin-req file:
1601200188391	53b63a98-d29e-4457-a2ed-094d7e6a669c	Intel(R) Centrino(R)	Intel Corporation	Intel(R) Centrino(R)	-	-	1-0050F204-1
161
162Control interface data:
163WPS-PIN-NEEDED [UUID-E|MAC Address|Device Name|Manufacturer|Model Name|Model Number|Serial Number|Device Category]
164For example:
165<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]
166
167When the user enters a PIN for a pending Enrollee, e.g., on the web
168UI), hostapd needs to be notified of the new PIN over the control
169interface. This can be done either by using the UNIX domain socket
170-based control interface directly (src/common/wpa_ctrl.c provides
171helper functions for using the interface) or by calling hostapd_cli.
172
173Example command to add a PIN (12345670) for an Enrollee:
174
175hostapd_cli wps_pin 53b63a98-d29e-4457-a2ed-094d7e6a669c 12345670
176
177If the UUID-E is not available (e.g., Enrollee waits for the Registrar
178to be selected before connecting), wildcard UUID may be used to allow
179the PIN to be used once with any UUID:
180
181hostapd_cli wps_pin any 12345670
182
183To reduce likelihood of PIN being used with other devices or of
184forgetting an active PIN available for potential attackers, expiration
185time in seconds can be set for the new PIN (value 0 indicates no
186expiration):
187
188hostapd_cli wps_pin any 12345670 300
189
190If the MAC address of the enrollee is known, it should be configured
191to allow the AP to advertise list of authorized enrollees:
192
193hostapd_cli wps_pin 53b63a98-d29e-4457-a2ed-094d7e6a669c \
194	12345670 300 00:11:22:33:44:55
195
196
197After this, the Enrollee can connect to the AP again and complete WPS
198negotiation. At that point, a new, random WPA PSK is generated for the
199client device and the client can then use that key to connect to the
200AP to access the network.
201
202
203If the AP includes a pushbutton, WPS PBC mode can be used. It is
204enabled by pushing a button on both the AP and the client at about the
205same time (2 minute window). hostapd needs to be notified about the AP
206button pushed event over the control interface, e.g., by calling
207hostapd_cli:
208
209hostapd_cli wps_pbc
210
211At this point, the client has two minutes to complete WPS negotiation
212which will generate a new WPA PSK in the same way as the PIN method
213described above.
214
215
216When an external Registrar is used, the AP can act as an Enrollee and
217use its AP PIN. A static AP PIN (e.g., one one a label in the AP
218device) can be configured in hostapd.conf (ap_pin parameter). A more
219secure option is to use hostapd_cli wps_ap_pin command to enable the
220AP PIN only based on user action (and even better security by using a
221random AP PIN for each session, i.e., by using "wps_ap_pin random"
222command with a timeout value). Following commands are available for
223managing the dynamic AP PIN operations:
224
225hostapd_cli wps_ap_pin disable
226- disable AP PIN (i.e., do not allow external Registrars to use it to
227  learn the current AP settings or to reconfigure the AP)
228
229hostapd_cli wps_ap_pin random [timeout]
230- generate a random AP PIN and enable it
231- if the optional timeout parameter is given, the AP PIN will be enabled
232  for the specified number of seconds
233
234hostapd_cli wps_ap_pin get
235- fetch the current AP PIN
236
237hostapd_cli wps_ap_pin set <PIN> [timeout]
238- set the AP PIN and enable it
239- if the optional timeout parameter is given, the AP PIN will be enabled
240  for the specified number of seconds
241
242hostapd_cli get_config
243- display the current configuration
244
245hostapd_cli wps_config <new SSID> <auth> <encr> <new key>
246examples:
247  hostapd_cli wps_config testing WPA2PSK CCMP 12345678
248  hostapd_cli wps_config "no security" OPEN NONE ""
249
250<auth> must be one of the following: OPEN WPAPSK WPA2PSK
251<encr> must be one of the following: NONE WEP TKIP CCMP
252
253
254Credential generation and configuration changes
255-----------------------------------------------
256
257By default, hostapd generates credentials for Enrollees and processing
258AP configuration updates internally. However, it is possible to
259control these operations from external programs, if desired.
260
261The internal credential generation can be disabled with
262skip_cred_build=1 option in the configuration. extra_cred option will
263then need to be used to provide pre-configured Credential attribute(s)
264for hostapd to use. The exact data from this binary file will be sent,
265i.e., it will have to include valid WPS attributes. extra_cred can
266also be used to add additional networks if the Registrar is used to
267configure credentials for multiple networks.
268
269Processing of received configuration updates can be disabled with
270wps_cred_processing=1 option. When this is used, an external program
271is responsible for creating hostapd configuration files and processing
272configuration updates based on messages received from hostapd over
273control interface. This will also include the initial configuration on
274first successful registration if the AP is initially set in
275unconfigured state.
276
277Following control interface messages are sent out for external programs:
278
279WPS-REG-SUCCESS <Enrollee MAC address <UUID-E>
280For example:
281<2>WPS-REG-SUCCESS 02:66:a0:ee:17:27 2b7093f1-d6fb-5108-adbb-bea66bb87333
282
283This can be used to trigger change from unconfigured to configured
284state (random configuration based on the first successful WPS
285registration). In addition, this can be used to update AP UI about the
286status of WPS registration progress.
287
288
289WPS-NEW-AP-SETTINGS <hexdump of AP Setup attributes>
290For example:
291<2>WPS-NEW-AP-SETTINGS 10260001011045000c6a6b6d2d7770732d74657374100300020020100f00020008102700403065346230343536633236366665306433396164313535346131663462663731323433376163666462376633393965353466316631623032306164343438623510200006024231cede15101e000844
292
293This can be used to update the externally stored AP configuration and
294then update hostapd configuration (followed by restarting of hostapd).
295
296
297WPS with NFC
298------------
299
300WPS can be used with NFC-based configuration method. An NFC tag
301containing a password token from the Enrollee can be used to
302authenticate the connection instead of the PIN. In addition, an NFC tag
303with a configuration token can be used to transfer AP settings without
304going through the WPS protocol.
305
306When the AP acts as an Enrollee, a local NFC tag with a password token
307can be used by touching the NFC interface of an external Registrar. The
308wps_nfc_token command is used to manage use of the NFC password token
309from the AP. "wps_nfc_token enable" enables the use of the AP's NFC
310password token (in place of AP PIN) and "wps_nfc_token disable" disables
311the NFC password token.
312
313The NFC password token that is either pre-configured in the
314configuration file (wps_nfc_dev_pw_id, wps_nfc_dh_pubkey,
315wps_nfc_dh_privkey, wps_nfc_dev_pw) or generated dynamically with
316"wps_nfc_token <WPS|NDEF>" command. The nfc_pw_token tool from
317wpa_supplicant can be used to generate NFC password tokens during
318manufacturing (each AP needs to have its own random keys).
319
320The "wps_nfc_config_token <WPS/NDEF>" command can be used to build an
321NFC configuration token. The output value from this command is a hexdump
322of the current AP configuration (WPS parameter requests this to include
323only the WPS attributes; NDEF parameter requests additional NDEF
324encapsulation to be included). This data needs to be written to an NFC
325tag with an external program. Once written, the NFC configuration token
326can be used to touch an NFC interface on a station to provision the
327credentials needed to access the network.
328
329When the NFC device on the AP reads an NFC tag with a MIME media type
330"application/vnd.wfa.wsc", the NDEF message payload (with or without
331NDEF encapsulation) can be delivered to hostapd using the
332following hostapd_cli command:
333
334wps_nfc_tag_read <hexdump of payload>
335
336If the NFC tag contains a password token, the token is added to the
337internal Registrar. This allows station Enrollee from which the password
338token was received to run through WPS protocol to provision the
339credential.
340
341"nfc_get_handover_sel <NDEF> <WPS>" command can be used to build the
342contents of a Handover Select Message for connection handover when this
343does not depend on the contents of the Handover Request Message. The
344first argument selects the format of the output data and the second
345argument selects which type of connection handover is requested (WPS =
346Wi-Fi handover as specified in WSC 2.0).
347
348"nfc_report_handover <INIT/RESP> WPS <carrier from handover request>
349<carrier from handover select>" is used to report completed NFC
350connection handover. The first parameter indicates whether the local
351device initiated or responded to the connection handover and the carrier
352records are the selected carrier from the handover request and select
353messages as a hexdump.
354