]>
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
->wps_cred_cb
= cfg
->wps_cred_cb
;
62 data
->cb_ctx
= cfg
->cb_ctx
;
64 data
->state
= data
->registrar
? RECV_M1
: SEND_M1
;
70 void wps_deinit(struct wps_data
*data
)
72 if (data
->wps_pin_revealed
) {
73 wpa_printf(MSG_DEBUG
, "WPS: Full PIN information revealed and "
74 "negotiation failed");
76 wps_registrar_invalidate_pin(data
->registrar
,
78 } else if (data
->registrar
)
79 wps_registrar_unlock_pin(data
->registrar
, data
->uuid_e
);
81 wpabuf_free(data
->dh_privkey
);
82 wpabuf_free(data
->dh_pubkey_e
);
83 wpabuf_free(data
->dh_pubkey_r
);
84 wpabuf_free(data
->last_msg
);
85 os_free(data
->dev_password
);
86 os_free(data
->new_psk
);
87 wps_device_data_free(&data
->peer_dev
);
92 enum wps_process_res
wps_process_msg(struct wps_data
*wps
, u8 op_code
,
93 const struct wpabuf
*msg
)
96 return wps_registrar_process_msg(wps
, op_code
, msg
);
98 return wps_enrollee_process_msg(wps
, op_code
, msg
);
102 struct wpabuf
* wps_get_msg(struct wps_data
*wps
, u8
*op_code
)
105 return wps_registrar_get_msg(wps
, op_code
);
107 return wps_enrollee_get_msg(wps
, op_code
);
111 int wps_is_selected_pbc_registrar(const u8
*buf
, size_t len
)
113 struct wps_parse_attr attr
;
116 wpabuf_set(&msg
, buf
, len
);
117 if (wps_parse_msg(&msg
, &attr
) < 0 ||
118 !attr
.selected_registrar
|| *attr
.selected_registrar
== 0 ||
119 !attr
.sel_reg_config_methods
||
120 !(WPA_GET_BE16(attr
.sel_reg_config_methods
) &
121 WPS_CONFIG_PUSHBUTTON
) ||
122 !attr
.dev_password_id
||
123 WPA_GET_BE16(attr
.dev_password_id
) != DEV_PW_PUSHBUTTON
)
130 int wps_is_selected_pin_registrar(const u8
*buf
, size_t len
)
132 struct wps_parse_attr attr
;
135 wpabuf_set(&msg
, buf
, len
);
136 if (wps_parse_msg(&msg
, &attr
) < 0 ||
137 !attr
.selected_registrar
|| *attr
.selected_registrar
== 0 ||
138 !attr
.sel_reg_config_methods
||
139 !(WPA_GET_BE16(attr
.sel_reg_config_methods
) &
140 (WPS_CONFIG_LABEL
| WPS_CONFIG_DISPLAY
| WPS_CONFIG_KEYPAD
)) ||
141 !attr
.dev_password_id
||
142 WPA_GET_BE16(attr
.dev_password_id
) == DEV_PW_PUSHBUTTON
)
149 const u8
* wps_get_uuid_e(const u8
*buf
, size_t len
)
151 struct wps_parse_attr attr
;
154 wpabuf_set(&msg
, buf
, len
);
155 if (wps_parse_msg(&msg
, &attr
) < 0)