1e5b75505Sopenharmony_ci/*
2e5b75505Sopenharmony_ci * Wi-Fi Protected Setup - internal definitions
3e5b75505Sopenharmony_ci * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
4e5b75505Sopenharmony_ci *
5e5b75505Sopenharmony_ci * This software may be distributed under the terms of the BSD license.
6e5b75505Sopenharmony_ci * See README for more details.
7e5b75505Sopenharmony_ci */
8e5b75505Sopenharmony_ci
9e5b75505Sopenharmony_ci#ifndef WPS_I_H
10e5b75505Sopenharmony_ci#define WPS_I_H
11e5b75505Sopenharmony_ci
12e5b75505Sopenharmony_ci#include "wps.h"
13e5b75505Sopenharmony_ci#include "wps_attr_parse.h"
14e5b75505Sopenharmony_ci
15e5b75505Sopenharmony_cistruct wps_nfc_pw_token;
16e5b75505Sopenharmony_ci
17e5b75505Sopenharmony_ci/**
18e5b75505Sopenharmony_ci * struct wps_data - WPS registration protocol data
19e5b75505Sopenharmony_ci *
20e5b75505Sopenharmony_ci * This data is stored at the EAP-WSC server/peer method and it is kept for a
21e5b75505Sopenharmony_ci * single registration protocol run.
22e5b75505Sopenharmony_ci */
23e5b75505Sopenharmony_cistruct wps_data {
24e5b75505Sopenharmony_ci	/**
25e5b75505Sopenharmony_ci	 * wps - Pointer to long term WPS context
26e5b75505Sopenharmony_ci	 */
27e5b75505Sopenharmony_ci	struct wps_context *wps;
28e5b75505Sopenharmony_ci
29e5b75505Sopenharmony_ci	/**
30e5b75505Sopenharmony_ci	 * registrar - Whether this end is a Registrar
31e5b75505Sopenharmony_ci	 */
32e5b75505Sopenharmony_ci	int registrar;
33e5b75505Sopenharmony_ci
34e5b75505Sopenharmony_ci	/**
35e5b75505Sopenharmony_ci	 * er - Whether the local end is an external registrar
36e5b75505Sopenharmony_ci	 */
37e5b75505Sopenharmony_ci	int er;
38e5b75505Sopenharmony_ci
39e5b75505Sopenharmony_ci	enum {
40e5b75505Sopenharmony_ci		/* Enrollee states */
41e5b75505Sopenharmony_ci		SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
42e5b75505Sopenharmony_ci		RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
43e5b75505Sopenharmony_ci		SEND_WSC_NACK,
44e5b75505Sopenharmony_ci
45e5b75505Sopenharmony_ci		/* Registrar states */
46e5b75505Sopenharmony_ci		RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6,
47e5b75505Sopenharmony_ci		RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK
48e5b75505Sopenharmony_ci	} state;
49e5b75505Sopenharmony_ci
50e5b75505Sopenharmony_ci	u8 uuid_e[WPS_UUID_LEN];
51e5b75505Sopenharmony_ci	u8 uuid_r[WPS_UUID_LEN];
52e5b75505Sopenharmony_ci	u8 mac_addr_e[ETH_ALEN];
53e5b75505Sopenharmony_ci	u8 nonce_e[WPS_NONCE_LEN];
54e5b75505Sopenharmony_ci	u8 nonce_r[WPS_NONCE_LEN];
55e5b75505Sopenharmony_ci	u8 psk1[WPS_PSK_LEN];
56e5b75505Sopenharmony_ci	u8 psk2[WPS_PSK_LEN];
57e5b75505Sopenharmony_ci	u8 snonce[2 * WPS_SECRET_NONCE_LEN];
58e5b75505Sopenharmony_ci	u8 peer_hash1[WPS_HASH_LEN];
59e5b75505Sopenharmony_ci	u8 peer_hash2[WPS_HASH_LEN];
60e5b75505Sopenharmony_ci
61e5b75505Sopenharmony_ci	struct wpabuf *dh_privkey;
62e5b75505Sopenharmony_ci	struct wpabuf *dh_pubkey_e;
63e5b75505Sopenharmony_ci	struct wpabuf *dh_pubkey_r;
64e5b75505Sopenharmony_ci	u8 authkey[WPS_AUTHKEY_LEN];
65e5b75505Sopenharmony_ci	u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
66e5b75505Sopenharmony_ci	u8 emsk[WPS_EMSK_LEN];
67e5b75505Sopenharmony_ci
68e5b75505Sopenharmony_ci	struct wpabuf *last_msg;
69e5b75505Sopenharmony_ci
70e5b75505Sopenharmony_ci	u8 *dev_password;
71e5b75505Sopenharmony_ci	size_t dev_password_len;
72e5b75505Sopenharmony_ci	u16 dev_pw_id;
73e5b75505Sopenharmony_ci	int pbc;
74e5b75505Sopenharmony_ci	u8 *alt_dev_password;
75e5b75505Sopenharmony_ci	size_t alt_dev_password_len;
76e5b75505Sopenharmony_ci	u16 alt_dev_pw_id;
77e5b75505Sopenharmony_ci
78e5b75505Sopenharmony_ci	u8 peer_pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN];
79e5b75505Sopenharmony_ci	int peer_pubkey_hash_set;
80e5b75505Sopenharmony_ci
81e5b75505Sopenharmony_ci	/**
82e5b75505Sopenharmony_ci	 * request_type - Request Type attribute from (Re)AssocReq
83e5b75505Sopenharmony_ci	 */
84e5b75505Sopenharmony_ci	u8 request_type;
85e5b75505Sopenharmony_ci
86e5b75505Sopenharmony_ci	/**
87e5b75505Sopenharmony_ci	 * encr_type - Available encryption types
88e5b75505Sopenharmony_ci	 */
89e5b75505Sopenharmony_ci	u16 encr_type;
90e5b75505Sopenharmony_ci
91e5b75505Sopenharmony_ci	/**
92e5b75505Sopenharmony_ci	 * auth_type - Available authentication types
93e5b75505Sopenharmony_ci	 */
94e5b75505Sopenharmony_ci	u16 auth_type;
95e5b75505Sopenharmony_ci
96e5b75505Sopenharmony_ci	u8 *new_psk;
97e5b75505Sopenharmony_ci	size_t new_psk_len;
98e5b75505Sopenharmony_ci
99e5b75505Sopenharmony_ci	int wps_pin_revealed;
100e5b75505Sopenharmony_ci	struct wps_credential cred;
101e5b75505Sopenharmony_ci
102e5b75505Sopenharmony_ci	struct wps_device_data peer_dev;
103e5b75505Sopenharmony_ci
104e5b75505Sopenharmony_ci	/**
105e5b75505Sopenharmony_ci	 * config_error - Configuration Error value to be used in NACK
106e5b75505Sopenharmony_ci	 */
107e5b75505Sopenharmony_ci	u16 config_error;
108e5b75505Sopenharmony_ci	u16 error_indication;
109e5b75505Sopenharmony_ci
110e5b75505Sopenharmony_ci	int ext_reg;
111e5b75505Sopenharmony_ci	int int_reg;
112e5b75505Sopenharmony_ci
113e5b75505Sopenharmony_ci	struct wps_credential *new_ap_settings;
114e5b75505Sopenharmony_ci
115e5b75505Sopenharmony_ci	void *dh_ctx;
116e5b75505Sopenharmony_ci
117e5b75505Sopenharmony_ci	void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred);
118e5b75505Sopenharmony_ci	void *ap_settings_cb_ctx;
119e5b75505Sopenharmony_ci
120e5b75505Sopenharmony_ci	struct wps_credential *use_cred;
121e5b75505Sopenharmony_ci
122e5b75505Sopenharmony_ci	int use_psk_key;
123e5b75505Sopenharmony_ci	u8 p2p_dev_addr[ETH_ALEN]; /* P2P Device Address of the client or
124e5b75505Sopenharmony_ci				    * 00:00:00:00:00:00 if not a P2p client */
125e5b75505Sopenharmony_ci	int pbc_in_m1;
126e5b75505Sopenharmony_ci
127e5b75505Sopenharmony_ci	struct wps_nfc_pw_token *nfc_pw_token;
128e5b75505Sopenharmony_ci
129e5b75505Sopenharmony_ci	int multi_ap_backhaul_sta;
130e5b75505Sopenharmony_ci};
131e5b75505Sopenharmony_ci
132e5b75505Sopenharmony_ci
133e5b75505Sopenharmony_ci/* wps_common.c */
134e5b75505Sopenharmony_civoid wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
135e5b75505Sopenharmony_ci	     const char *label, u8 *res, size_t res_len);
136e5b75505Sopenharmony_ciint wps_derive_keys(struct wps_data *wps);
137e5b75505Sopenharmony_ciint wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
138e5b75505Sopenharmony_ci		   size_t dev_passwd_len);
139e5b75505Sopenharmony_cistruct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
140e5b75505Sopenharmony_ci					  size_t encr_len);
141e5b75505Sopenharmony_civoid wps_fail_event(struct wps_context *wps, enum wps_msg_type msg,
142e5b75505Sopenharmony_ci		    u16 config_error, u16 error_indication, const u8 *mac_addr);
143e5b75505Sopenharmony_civoid wps_success_event(struct wps_context *wps, const u8 *mac_addr);
144e5b75505Sopenharmony_civoid wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part,
145e5b75505Sopenharmony_ci			     const u8 *mac_addr);
146e5b75505Sopenharmony_civoid wps_pbc_overlap_event(struct wps_context *wps);
147e5b75505Sopenharmony_civoid wps_pbc_timeout_event(struct wps_context *wps);
148e5b75505Sopenharmony_civoid wps_pbc_active_event(struct wps_context *wps);
149e5b75505Sopenharmony_civoid wps_pbc_disable_event(struct wps_context *wps);
150e5b75505Sopenharmony_ci
151e5b75505Sopenharmony_cistruct wpabuf * wps_build_wsc_ack(struct wps_data *wps);
152e5b75505Sopenharmony_cistruct wpabuf * wps_build_wsc_nack(struct wps_data *wps);
153e5b75505Sopenharmony_ci
154e5b75505Sopenharmony_ci/* wps_attr_build.c */
155e5b75505Sopenharmony_ciint wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
156e5b75505Sopenharmony_ciint wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
157e5b75505Sopenharmony_ciint wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type);
158e5b75505Sopenharmony_ciint wps_build_config_methods(struct wpabuf *msg, u16 methods);
159e5b75505Sopenharmony_ciint wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
160e5b75505Sopenharmony_ciint wps_build_dev_password_id(struct wpabuf *msg, u16 id);
161e5b75505Sopenharmony_ciint wps_build_config_error(struct wpabuf *msg, u16 err);
162e5b75505Sopenharmony_ciint wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
163e5b75505Sopenharmony_ciint wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
164e5b75505Sopenharmony_ciint wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
165e5b75505Sopenharmony_ci			    struct wpabuf *plain);
166e5b75505Sopenharmony_ciint wps_build_version(struct wpabuf *msg);
167e5b75505Sopenharmony_ciint wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll,
168e5b75505Sopenharmony_ci		      const u8 *auth_macs, size_t auth_macs_count,
169e5b75505Sopenharmony_ci		      u8 multi_ap_subelem);
170e5b75505Sopenharmony_ciint wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
171e5b75505Sopenharmony_ciint wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
172e5b75505Sopenharmony_ciint wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
173e5b75505Sopenharmony_ciint wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
174e5b75505Sopenharmony_ciint wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
175e5b75505Sopenharmony_ciint wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
176e5b75505Sopenharmony_ciint wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
177e5b75505Sopenharmony_ciint wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
178e5b75505Sopenharmony_ci			 const struct wpabuf *pubkey, const u8 *dev_pw,
179e5b75505Sopenharmony_ci			 size_t dev_pw_len);
180e5b75505Sopenharmony_cistruct wpabuf * wps_ie_encapsulate(struct wpabuf *data);
181e5b75505Sopenharmony_ciint wps_build_mac_addr(struct wpabuf *msg, const u8 *addr);
182e5b75505Sopenharmony_ciint wps_build_rf_bands_attr(struct wpabuf *msg, u8 rf_bands);
183e5b75505Sopenharmony_ciint wps_build_ap_channel(struct wpabuf *msg, u16 ap_channel);
184e5b75505Sopenharmony_ci
185e5b75505Sopenharmony_ci/* wps_attr_process.c */
186e5b75505Sopenharmony_ciint wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
187e5b75505Sopenharmony_ci			      const struct wpabuf *msg);
188e5b75505Sopenharmony_ciint wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
189e5b75505Sopenharmony_ci			      const u8 *key_wrap_auth);
190e5b75505Sopenharmony_ciint wps_process_cred(struct wps_parse_attr *attr,
191e5b75505Sopenharmony_ci		     struct wps_credential *cred);
192e5b75505Sopenharmony_ciint wps_process_ap_settings(struct wps_parse_attr *attr,
193e5b75505Sopenharmony_ci			    struct wps_credential *cred);
194e5b75505Sopenharmony_ci
195e5b75505Sopenharmony_ci/* wps_enrollee.c */
196e5b75505Sopenharmony_cistruct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
197e5b75505Sopenharmony_ci				     enum wsc_op_code *op_code);
198e5b75505Sopenharmony_cienum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
199e5b75505Sopenharmony_ci					      enum wsc_op_code op_code,
200e5b75505Sopenharmony_ci					      const struct wpabuf *msg);
201e5b75505Sopenharmony_ci
202e5b75505Sopenharmony_ci/* wps_registrar.c */
203e5b75505Sopenharmony_cistruct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
204e5b75505Sopenharmony_ci				      enum wsc_op_code *op_code);
205e5b75505Sopenharmony_cienum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
206e5b75505Sopenharmony_ci					       enum wsc_op_code op_code,
207e5b75505Sopenharmony_ci					       const struct wpabuf *msg);
208e5b75505Sopenharmony_ciint wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
209e5b75505Sopenharmony_ciint wps_device_store(struct wps_registrar *reg,
210e5b75505Sopenharmony_ci		     struct wps_device_data *dev, const u8 *uuid);
211e5b75505Sopenharmony_civoid wps_registrar_selected_registrar_changed(struct wps_registrar *reg,
212e5b75505Sopenharmony_ci					      u16 dev_pw_id);
213e5b75505Sopenharmony_ciconst u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count);
214e5b75505Sopenharmony_ciint wps_registrar_pbc_overlap(struct wps_registrar *reg,
215e5b75505Sopenharmony_ci			      const u8 *addr, const u8 *uuid_e);
216e5b75505Sopenharmony_civoid wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg,
217e5b75505Sopenharmony_ci				       struct wps_nfc_pw_token *token);
218e5b75505Sopenharmony_ciint wps_cb_new_psk(struct wps_registrar *reg, const u8 *mac_addr,
219e5b75505Sopenharmony_ci		   const u8 *p2p_dev_addr, const u8 *psk, size_t psk_len);
220e5b75505Sopenharmony_ci
221e5b75505Sopenharmony_ci#endif /* WPS_I_H */
222