wps_i.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /*
  2. * Wi-Fi Protected Setup - internal definitions
  3. * Copyright (c) 2008-2012, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef WPS_I_H
  9. #define WPS_I_H
  10. #include "wps.h"
  11. #include "wps_attr_parse.h"
  12. struct wps_nfc_pw_token;
  13. /**
  14. * struct wps_data - WPS registration protocol data
  15. *
  16. * This data is stored at the EAP-WSC server/peer method and it is kept for a
  17. * single registration protocol run.
  18. */
  19. struct wps_data {
  20. /**
  21. * wps - Pointer to long term WPS context
  22. */
  23. struct wps_context *wps;
  24. /**
  25. * registrar - Whether this end is a Registrar
  26. */
  27. int registrar;
  28. /**
  29. * er - Whether the local end is an external registrar
  30. */
  31. int er;
  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. struct wpabuf *last_msg;
  58. u8 *dev_password;
  59. size_t dev_password_len;
  60. u16 dev_pw_id;
  61. int pbc;
  62. u8 *alt_dev_password;
  63. size_t alt_dev_password_len;
  64. u16 alt_dev_pw_id;
  65. /**
  66. * request_type - Request Type attribute from (Re)AssocReq
  67. */
  68. u8 request_type;
  69. /**
  70. * encr_type - Available encryption types
  71. */
  72. u16 encr_type;
  73. /**
  74. * auth_type - Available authentication types
  75. */
  76. u16 auth_type;
  77. u8 *new_psk;
  78. size_t new_psk_len;
  79. int wps_pin_revealed;
  80. struct wps_credential cred;
  81. struct wps_device_data peer_dev;
  82. /**
  83. * config_error - Configuration Error value to be used in NACK
  84. */
  85. u16 config_error;
  86. u16 error_indication;
  87. int ext_reg;
  88. int int_reg;
  89. struct wps_credential *new_ap_settings;
  90. void *dh_ctx;
  91. void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred);
  92. void *ap_settings_cb_ctx;
  93. struct wps_credential *use_cred;
  94. int use_psk_key;
  95. u8 p2p_dev_addr[ETH_ALEN]; /* P2P Device Address of the client or
  96. * 00:00:00:00:00:00 if not a P2p client */
  97. int pbc_in_m1;
  98. struct wps_nfc_pw_token *nfc_pw_token;
  99. };
  100. /* wps_common.c */
  101. void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
  102. const char *label, u8 *res, size_t res_len);
  103. int wps_derive_keys(struct wps_data *wps);
  104. void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
  105. size_t dev_passwd_len);
  106. struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
  107. size_t encr_len);
  108. void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg,
  109. u16 config_error, u16 error_indication, const u8 *mac_addr);
  110. void wps_success_event(struct wps_context *wps, const u8 *mac_addr);
  111. void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part,
  112. const u8 *mac_addr);
  113. void wps_pbc_overlap_event(struct wps_context *wps);
  114. void wps_pbc_timeout_event(struct wps_context *wps);
  115. void wps_pbc_active_event(struct wps_context *wps);
  116. void wps_pbc_disable_event(struct wps_context *wps);
  117. struct wpabuf * wps_build_wsc_ack(struct wps_data *wps);
  118. struct wpabuf * wps_build_wsc_nack(struct wps_data *wps);
  119. /* wps_attr_build.c */
  120. int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
  121. int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
  122. int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type);
  123. int wps_build_config_methods(struct wpabuf *msg, u16 methods);
  124. int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
  125. int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
  126. int wps_build_config_error(struct wpabuf *msg, u16 err);
  127. int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
  128. int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
  129. int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
  130. struct wpabuf *plain);
  131. int wps_build_version(struct wpabuf *msg);
  132. int wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll,
  133. const u8 *auth_macs, size_t auth_macs_count);
  134. int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
  135. int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
  136. int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
  137. int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
  138. int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
  139. int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
  140. int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
  141. int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
  142. const struct wpabuf *pubkey, const u8 *dev_pw,
  143. size_t dev_pw_len);
  144. struct wpabuf * wps_ie_encapsulate(struct wpabuf *data);
  145. int wps_build_mac_addr(struct wpabuf *msg, const u8 *addr);
  146. /* wps_attr_process.c */
  147. int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
  148. const struct wpabuf *msg);
  149. int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
  150. const u8 *key_wrap_auth);
  151. int wps_process_cred(struct wps_parse_attr *attr,
  152. struct wps_credential *cred);
  153. int wps_process_ap_settings(struct wps_parse_attr *attr,
  154. struct wps_credential *cred);
  155. /* wps_enrollee.c */
  156. struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
  157. enum wsc_op_code *op_code);
  158. enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
  159. enum wsc_op_code op_code,
  160. const struct wpabuf *msg);
  161. /* wps_registrar.c */
  162. struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
  163. enum wsc_op_code *op_code);
  164. enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
  165. enum wsc_op_code op_code,
  166. const struct wpabuf *msg);
  167. int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
  168. int wps_device_store(struct wps_registrar *reg,
  169. struct wps_device_data *dev, const u8 *uuid);
  170. void wps_registrar_selected_registrar_changed(struct wps_registrar *reg,
  171. u16 dev_pw_id);
  172. const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count);
  173. int wps_registrar_pbc_overlap(struct wps_registrar *reg,
  174. const u8 *addr, const u8 *uuid_e);
  175. void wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg,
  176. struct wps_nfc_pw_token *token);
  177. #endif /* WPS_I_H */