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