wps_i.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Wi-Fi Protected Setup - internal definitions
  3. * Copyright (c) 2008, Jouni Malinen <j@w1.fi>
  4. *
  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.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. */
  14. #ifndef WPS_I_H
  15. #define WPS_I_H
  16. #include "wps.h"
  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. */
  23. struct wps_data {
  24. /**
  25. * wps - Pointer to long term WPS context
  26. */
  27. struct wps_context *wps;
  28. /**
  29. * registrar - Whether this end is a Registrar
  30. */
  31. int registrar;
  32. enum {
  33. /* Enrollee states */
  34. SEND_M1, RECV_M2, SEND_M3, RECV_M4, SEND_M5, RECV_M6, SEND_M7,
  35. RECV_M8, RECEIVED_M2D, WPS_MSG_DONE, RECV_ACK, WPS_FINISHED,
  36. SEND_WSC_NACK,
  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
  40. } state;
  41. u8 uuid_e[WPS_UUID_LEN];
  42. u8 uuid_r[WPS_UUID_LEN];
  43. u8 mac_addr_e[ETH_ALEN];
  44. u8 nonce_e[WPS_NONCE_LEN];
  45. u8 nonce_r[WPS_NONCE_LEN];
  46. u8 psk1[WPS_PSK_LEN];
  47. u8 psk2[WPS_PSK_LEN];
  48. u8 snonce[2 * WPS_SECRET_NONCE_LEN];
  49. u8 peer_hash1[WPS_HASH_LEN];
  50. u8 peer_hash2[WPS_HASH_LEN];
  51. struct wpabuf *dh_privkey;
  52. struct wpabuf *dh_pubkey_e;
  53. struct wpabuf *dh_pubkey_r;
  54. u8 authkey[WPS_AUTHKEY_LEN];
  55. u8 keywrapkey[WPS_KEYWRAPKEY_LEN];
  56. u8 emsk[WPS_EMSK_LEN];
  57. u8 mgmt_auth_key[WPS_MGMTAUTHKEY_LEN];
  58. u8 mgmt_auth_key_id[WPS_MGMT_KEY_ID_LEN];
  59. u8 mgmt_enc_key[WPS_MGMTENCKEY_LEN];
  60. u8 mgmt_enc_key_id[WPS_MGMT_KEY_ID_LEN];
  61. struct wpabuf *last_msg;
  62. u8 *dev_password;
  63. size_t dev_password_len;
  64. u16 dev_pw_id;
  65. int pbc;
  66. /**
  67. * request_type - Request Type attribute from (Re)AssocReq
  68. */
  69. u8 request_type;
  70. /**
  71. * encr_type - Available encryption types
  72. */
  73. u16 encr_type;
  74. /**
  75. * auth_type - Available authentication types
  76. */
  77. u16 auth_type;
  78. u8 *new_psk;
  79. size_t new_psk_len;
  80. int wps_pin_revealed;
  81. struct wps_credential cred;
  82. struct wps_device_data peer_dev;
  83. /**
  84. * config_error - Configuration Error value to be used in NACK
  85. */
  86. u16 config_error;
  87. int ext_reg;
  88. };
  89. struct wps_parse_attr {
  90. /* fixed length fields */
  91. const u8 *version; /* 1 octet */
  92. const u8 *msg_type; /* 1 octet */
  93. const u8 *enrollee_nonce; /* WPS_NONCE_LEN (16) octets */
  94. const u8 *registrar_nonce; /* WPS_NONCE_LEN (16) octets */
  95. const u8 *uuid_r; /* WPS_UUID_LEN (16) octets */
  96. const u8 *uuid_e; /* WPS_UUID_LEN (16) octets */
  97. const u8 *auth_type_flags; /* 2 octets */
  98. const u8 *encr_type_flags; /* 2 octets */
  99. const u8 *conn_type_flags; /* 1 octet */
  100. const u8 *config_methods; /* 2 octets */
  101. const u8 *sel_reg_config_methods; /* 2 octets */
  102. const u8 *primary_dev_type; /* 8 octets */
  103. const u8 *rf_bands; /* 1 octet */
  104. const u8 *assoc_state; /* 2 octets */
  105. const u8 *config_error; /* 2 octets */
  106. const u8 *dev_password_id; /* 2 octets */
  107. const u8 *oob_dev_password; /* WPS_OOB_DEVICE_PASSWORD_ATTR_LEN (54)
  108. * octets */
  109. const u8 *os_version; /* 4 octets */
  110. const u8 *wps_state; /* 1 octet */
  111. const u8 *authenticator; /* WPS_AUTHENTICATOR_LEN (8) octets */
  112. const u8 *r_hash1; /* WPS_HASH_LEN (32) octets */
  113. const u8 *r_hash2; /* WPS_HASH_LEN (32) octets */
  114. const u8 *e_hash1; /* WPS_HASH_LEN (32) octets */
  115. const u8 *e_hash2; /* WPS_HASH_LEN (32) octets */
  116. const u8 *r_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
  117. const u8 *r_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
  118. const u8 *e_snonce1; /* WPS_SECRET_NONCE_LEN (16) octets */
  119. const u8 *e_snonce2; /* WPS_SECRET_NONCE_LEN (16) octets */
  120. const u8 *key_wrap_auth; /* WPS_KWA_LEN (8) octets */
  121. const u8 *auth_type; /* 2 octets */
  122. const u8 *encr_type; /* 2 octets */
  123. const u8 *network_idx; /* 1 octet */
  124. const u8 *network_key_idx; /* 1 octet */
  125. const u8 *mac_addr; /* ETH_ALEN (6) octets */
  126. const u8 *key_prov_auto; /* 1 octet (Bool) */
  127. const u8 *dot1x_enabled; /* 1 octet (Bool) */
  128. const u8 *selected_registrar; /* 1 octet (Bool) */
  129. const u8 *request_type; /* 1 octet */
  130. const u8 *response_type; /* 1 octet */
  131. /* variable length fields */
  132. const u8 *manufacturer;
  133. size_t manufacturer_len;
  134. const u8 *model_name;
  135. size_t model_name_len;
  136. const u8 *model_number;
  137. size_t model_number_len;
  138. const u8 *serial_number;
  139. size_t serial_number_len;
  140. const u8 *dev_name;
  141. size_t dev_name_len;
  142. const u8 *public_key;
  143. size_t public_key_len;
  144. const u8 *encr_settings;
  145. size_t encr_settings_len;
  146. const u8 *ssid; /* <= 32 octets */
  147. size_t ssid_len;
  148. const u8 *network_key; /* <= 64 octets */
  149. size_t network_key_len;
  150. const u8 *eap_type; /* <= 8 octets */
  151. size_t eap_type_len;
  152. const u8 *eap_identity; /* <= 64 octets */
  153. size_t eap_identity_len;
  154. /* attributes that can occur multiple times */
  155. #define MAX_CRED_COUNT 10
  156. const u8 *cred[MAX_CRED_COUNT];
  157. size_t cred_len[MAX_CRED_COUNT];
  158. size_t num_cred;
  159. };
  160. /* wps_common.c */
  161. void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
  162. const char *label, u8 *res, size_t res_len);
  163. int wps_derive_keys(struct wps_data *wps);
  164. int wps_derive_mgmt_keys(struct wps_data *wps);
  165. void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
  166. size_t dev_passwd_len);
  167. struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
  168. size_t encr_len);
  169. void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg);
  170. void wps_success_event(struct wps_context *wps);
  171. void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part);
  172. extern struct oob_device_data oob_ufd_device_data;
  173. extern struct oob_device_data oob_nfc_device_data;
  174. extern struct oob_nfc_device_data oob_nfc_pn531_device_data;
  175. /* wps_attr_parse.c */
  176. int wps_parse_msg(const struct wpabuf *msg, struct wps_parse_attr *attr);
  177. /* wps_attr_build.c */
  178. int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
  179. int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
  180. int wps_build_config_methods(struct wpabuf *msg, u16 methods);
  181. int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
  182. int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
  183. int wps_build_config_error(struct wpabuf *msg, u16 err);
  184. int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
  185. int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
  186. int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
  187. struct wpabuf *plain);
  188. int wps_build_version(struct wpabuf *msg);
  189. int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
  190. int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
  191. int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
  192. int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
  193. int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
  194. int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
  195. int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
  196. int wps_build_oob_dev_password(struct wpabuf *msg, struct wps_context *wps);
  197. /* wps_attr_process.c */
  198. int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
  199. const struct wpabuf *msg);
  200. int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
  201. const u8 *key_wrap_auth);
  202. int wps_process_cred(struct wps_parse_attr *attr,
  203. struct wps_credential *cred);
  204. int wps_process_ap_settings(struct wps_parse_attr *attr,
  205. struct wps_credential *cred);
  206. /* wps_enrollee.c */
  207. struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
  208. enum wsc_op_code *op_code);
  209. enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
  210. enum wsc_op_code op_code,
  211. const struct wpabuf *msg);
  212. /* wps_registrar.c */
  213. struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
  214. enum wsc_op_code *op_code);
  215. enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
  216. enum wsc_op_code op_code,
  217. const struct wpabuf *msg);
  218. int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
  219. /* ndef.c */
  220. struct wpabuf * ndef_parse_wifi(struct wpabuf *buf);
  221. struct wpabuf * ndef_build_wifi(struct wpabuf *buf);
  222. static inline int wps_version_supported(const u8 *version)
  223. {
  224. /* Require major version match, but allow minor version differences */
  225. return version && (*version & 0xf0) == (WPS_VERSION & 0xf0);
  226. }
  227. #endif /* WPS_I_H */