2 * Wi-Fi Protected Setup - internal definitions
3 * Copyright (c) 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.
22 * struct wps_data - WPS registration protocol data
24 * This data is stored at the EAP-WSC server/peer method and it is kept for a
25 * single registration protocol run.
29 struct wps_context *wps;
30 struct wps_registrar *registrar;
33 SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
34 RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
37 /* Registrar states */
38 RECV_M1, SEND_M2, RECV_M3, SEND_M4, RECV_M5, SEND_M6,
39 RECV_M7, SEND_M8, RECV_DONE, SEND_M2D, RECV_M2D_ACK
42 u8 uuid_e[WPS_UUID_LEN];
43 u8 uuid_r[WPS_UUID_LEN];
44 u8 mac_addr_e[ETH_ALEN];
45 u8 nonce_e[WPS_NONCE_LEN];
46 u8 nonce_r[WPS_NONCE_LEN];
49 u8 snonce[2 * WPS_SECRET_NONCE_LEN];
50 u8 peer_hash1[WPS_HASH_LEN];
51 u8 peer_hash2[WPS_HASH_LEN];
53 struct wpabuf *dh_privkey;
54 struct wpabuf *dh_pubkey_e;
55 struct wpabuf *dh_pubkey_r;
56 u8 authkey[WPS_AUTHKEY_LEN];
57 u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
58 u8 emsk[WPS_EMSK_LEN];
59 u8 mgmt_auth_key[WPS_MGMTAUTHKEY_LEN];
60 u8 mgmt_auth_key_id[WPS_MGMT_KEY_ID_LEN];
61 u8 mgmt_enc_key[WPS_MGMTENCKEY_LEN];
62 u8 mgmt_enc_key_id[WPS_MGMT_KEY_ID_LEN];
64 struct wpabuf *last_msg;
67 size_t dev_password_len;
70 u8 request_type; /* Request Type attribute from (Re)AssocReq */
72 u16 encr_type; /* available encryption types */
73 u16 auth_type; /* available authentication types */
79 struct wps_credential cred;
81 struct wps_device_data peer_dev;
85 struct wps_parse_attr {
86 /* fixed length fields */
87 const u8 *version; /* 1 octet */
88 const u8 *msg_type; /* 1 octet */
89 const u8 *enrollee_nonce; /* WPS_NONCE_LEN (16) octets */
90 const u8 *registrar_nonce; /* WPS_NONCE_LEN (16) octets */
91 const u8 *uuid_r; /* WPS_UUID_LEN (16) octets */
92 const u8 *uuid_e; /* WPS_UUID_LEN (16) octets */
93 const u8 *auth_type_flags; /* 2 octets */
94 const u8 *encr_type_flags; /* 2 octets */
95 const u8 *conn_type_flags; /* 1 octet */
96 const u8 *config_methods; /* 2 octets */
97 const u8 *sel_reg_config_methods; /* 2 octets */
98 const u8 *primary_dev_type; /* 8 octets */
99 const u8 *rf_bands; /* 1 octet */
100 const u8 *assoc_state; /* 2 octets */
101 const u8 *config_error; /* 2 octets */
102 const u8 *dev_password_id; /* 2 octets */
103 const u8 *os_version; /* 4 octets */
104 const u8 *wps_state; /* 1 octet */
105 const u8 *authenticator; /* WPS_AUTHENTICATOR_LEN (8) octets */
106 const u8 *r_hash1; /* WPS_HASH_LEN (32) octets */
107 const u8 *r_hash2; /* WPS_HASH_LEN (32) octets */
108 const u8 *e_hash1; /* WPS_HASH_LEN (32) octets */
109 const u8 *e_hash2; /* WPS_HASH_LEN (32) octets */
110 const u8 *r_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
111 const u8 *r_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
112 const u8 *e_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
113 const u8 *e_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
114 const u8 *key_wrap_auth; /* WPS_KWA_LEN (8) octets */
115 const u8 *auth_type; /* 2 octets */
116 const u8 *encr_type; /* 2 octets */
117 const u8 *network_idx; /* 1 octet */
118 const u8 *network_key_idx; /* 1 octet */
119 const u8 *mac_addr; /* ETH_ALEN (6) octets */
120 const u8 *key_prov_auto; /* 1 octet (Bool) */
121 const u8 *dot1x_enabled; /* 1 octet (Bool) */
122 const u8 *selected_registrar; /* 1 octet (Bool) */
123 const u8 *request_type; /* 1 octet */
124 const u8 *response_type; /* 1 octet */
126 /* variable length fields */
127 const u8 *manufacturer;
128 size_t manufacturer_len;
129 const u8 *model_name;
130 size_t model_name_len;
131 const u8 *model_number;
132 size_t model_number_len;
133 const u8 *serial_number;
134 size_t serial_number_len;
137 const u8 *public_key;
138 size_t public_key_len;
139 const u8 *encr_settings;
140 size_t encr_settings_len;
141 const u8 *ssid; /* <= 32 octets */
143 const u8 *network_key; /* <= 64 octets */
144 size_t network_key_len;
145 const u8 *eap_type; /* <= 8 octets */
147 const u8 *eap_identity; /* <= 64 octets */
148 size_t eap_identity_len;
150 /* attributes that can occur multiple times */
151 #define MAX_CRED_COUNT 10
152 const u8 *cred[MAX_CRED_COUNT];
153 size_t cred_len[MAX_CRED_COUNT];
158 int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr);
159 void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
160 const char *label, u8 *res, size_t res_len);
161 int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
162 int wps_derive_keys(struct wps_data *wps);
163 int wps_derive_mgmt_keys(struct wps_data *wps);
164 int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
165 int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
166 const struct wpabuf *msg);
167 void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
168 size_t dev_passwd_len);
169 struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
171 int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
172 const u8 *key_wrap_auth);
173 int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
174 int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
175 struct wpabuf *plain);
176 int wps_build_version(struct wpabuf *msg);
177 int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
178 int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
179 int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
180 int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
181 int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
182 int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
183 int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
184 int wps_process_cred(struct wps_parse_attr *attr,
185 struct wps_credential *cred);
186 int wps_process_ap_settings(struct wps_parse_attr *attr,
187 struct wps_credential *cred);
190 struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps, u8 *op_code);
191 enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps, u8 op_code,
192 const struct wpabuf *msg);
194 /* wps_registrar.c */
195 struct wpabuf * wps_registrar_get_msg(struct wps_data *wps, u8 *op_code);
196 enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
198 const struct wpabuf *msg);