]>
git.ipfire.org Git - thirdparty/hostap.git/blob - src/wps/wps.c
2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
19 #include "wps_dev_attr.h"
22 struct wps_data
* wps_init(const struct wps_config
*cfg
)
24 struct wps_data
*data
= os_zalloc(sizeof(*data
));
27 data
->authenticator
= cfg
->authenticator
;
29 data
->registrar
= cfg
->registrar
;
30 if (cfg
->enrollee_mac_addr
)
31 os_memcpy(data
->mac_addr_e
, cfg
->enrollee_mac_addr
, ETH_ALEN
);
33 os_memcpy(cfg
->registrar
? data
->uuid_r
: data
->uuid_e
,
34 cfg
->uuid
, WPS_UUID_LEN
);
37 data
->dev_pw_id
= DEV_PW_DEFAULT
;
38 data
->dev_password
= os_malloc(cfg
->pin_len
);
39 if (data
->dev_password
== NULL
) {
43 os_memcpy(data
->dev_password
, cfg
->pin
, cfg
->pin_len
);
44 data
->dev_password_len
= cfg
->pin_len
;
49 /* Use special PIN '00000000' for PBC */
50 data
->dev_pw_id
= DEV_PW_PUSHBUTTON
;
51 os_free(data
->dev_password
);
52 data
->dev_password
= os_malloc(8);
53 if (data
->dev_password
== NULL
) {
57 os_memset(data
->dev_password
, '0', 8);
58 data
->dev_password_len
= 8;
61 data
->state
= data
->registrar
? RECV_M1
: SEND_M1
;
63 if (cfg
->assoc_wps_ie
) {
64 struct wps_parse_attr attr
;
65 wpa_hexdump_buf(MSG_DEBUG
, "WPS: WPS IE from (Re)AssocReq",
67 if (wps_parse_msg(cfg
->assoc_wps_ie
, &attr
) < 0) {
68 wpa_printf(MSG_DEBUG
, "WPS: Failed to parse WPS IE "
70 } else if (attr
.request_type
== NULL
) {
71 wpa_printf(MSG_DEBUG
, "WPS: No Request Type attribute "
72 "in (Re)AssocReq WPS IE");
74 wpa_printf(MSG_DEBUG
, "WPS: Request Type (from WPS IE "
75 "in (Re)AssocReq WPS IE): %d",
77 data
->request_type
= *attr
.request_type
;
85 void wps_deinit(struct wps_data
*data
)
87 if (data
->wps_pin_revealed
) {
88 wpa_printf(MSG_DEBUG
, "WPS: Full PIN information revealed and "
89 "negotiation failed");
91 wps_registrar_invalidate_pin(data
->registrar
,
93 } else if (data
->registrar
)
94 wps_registrar_unlock_pin(data
->registrar
, data
->uuid_e
);
96 wpabuf_free(data
->dh_privkey
);
97 wpabuf_free(data
->dh_pubkey_e
);
98 wpabuf_free(data
->dh_pubkey_r
);
99 wpabuf_free(data
->last_msg
);
100 os_free(data
->dev_password
);
101 os_free(data
->new_psk
);
102 wps_device_data_free(&data
->peer_dev
);
107 enum wps_process_res
wps_process_msg(struct wps_data
*wps
, u8 op_code
,
108 const struct wpabuf
*msg
)
111 return wps_registrar_process_msg(wps
, op_code
, msg
);
113 return wps_enrollee_process_msg(wps
, op_code
, msg
);
117 struct wpabuf
* wps_get_msg(struct wps_data
*wps
, u8
*op_code
)
120 return wps_registrar_get_msg(wps
, op_code
);
122 return wps_enrollee_get_msg(wps
, op_code
);
126 int wps_is_selected_pbc_registrar(const u8
*buf
, size_t len
)
128 struct wps_parse_attr attr
;
131 wpabuf_set(&msg
, buf
, len
);
132 if (wps_parse_msg(&msg
, &attr
) < 0 ||
133 !attr
.selected_registrar
|| *attr
.selected_registrar
== 0 ||
134 !attr
.sel_reg_config_methods
||
135 !(WPA_GET_BE16(attr
.sel_reg_config_methods
) &
136 WPS_CONFIG_PUSHBUTTON
) ||
137 !attr
.dev_password_id
||
138 WPA_GET_BE16(attr
.dev_password_id
) != DEV_PW_PUSHBUTTON
)
145 int wps_is_selected_pin_registrar(const u8
*buf
, size_t len
)
147 struct wps_parse_attr attr
;
150 wpabuf_set(&msg
, buf
, len
);
151 if (wps_parse_msg(&msg
, &attr
) < 0 ||
152 !attr
.selected_registrar
|| *attr
.selected_registrar
== 0 ||
153 !attr
.sel_reg_config_methods
||
154 !(WPA_GET_BE16(attr
.sel_reg_config_methods
) &
155 (WPS_CONFIG_LABEL
| WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
)) ||
156 !attr
.dev_password_id
||
157 WPA_GET_BE16(attr
.dev_password_id
) == DEV_PW_PUSHBUTTON
)
164 const u8
* wps_get_uuid_e(const u8
*buf
, size_t len
)
166 struct wps_parse_attr attr
;
169 wpabuf_set(&msg
, buf
, len
);
170 if (wps_parse_msg(&msg
, &attr
) < 0)