wps_i.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. u8 peer_pubkey_hash[WPS_OOB_PUBKEY_HASH_LEN];
  66. int peer_pubkey_hash_set;
  67. /**
  68. * request_type - Request Type attribute from (Re)AssocReq
  69. */
  70. u8 request_type;
  71. /**
  72. * encr_type - Available encryption types
  73. */
  74. u16 encr_type;
  75. /**
  76. * auth_type - Available authentication types
  77. */
  78. u16 auth_type;
  79. u8 *new_psk;
  80. size_t new_psk_len;
  81. int wps_pin_revealed;
  82. struct wps_credential cred;
  83. struct wps_device_data peer_dev;
  84. /**
  85. * config_error - Configuration Error value to be used in NACK
  86. */
  87. u16 config_error;
  88. u16 error_indication;
  89. int ext_reg;
  90. int int_reg;
  91. struct wps_credential *new_ap_settings;
  92. void *dh_ctx;
  93. void (*ap_settings_cb)(void *ctx, const struct wps_credential *cred);
  94. void *ap_settings_cb_ctx;
  95. struct wps_credential *use_cred;
  96. int use_psk_key;
  97. u8 p2p_dev_addr[ETH_ALEN]; /* P2P Device Address of the client or
  98. * 00:00:00:00:00:00 if not a P2p client */
  99. int pbc_in_m1;
  100. struct wps_nfc_pw_token *nfc_pw_token;
  101. };
  102. /* wps_common.c */
  103. void wps_kdf(const u8 *key, const u8 *label_prefix, size_t label_prefix_len,
  104. const char *label, u8 *res, size_t res_len);
  105. int wps_derive_keys(struct wps_data *wps);
  106. void wps_derive_psk(struct wps_data *wps, const u8 *dev_passwd,
  107. size_t dev_passwd_len);
  108. struct wpabuf * wps_decrypt_encr_settings(struct wps_data *wps, const u8 *encr,
  109. size_t encr_len);
  110. void wps_fail_event(struct wps_context *wps, enum wps_msg_type msg,
  111. u16 config_error, u16 error_indication, const u8 *mac_addr);
  112. void wps_success_event(struct wps_context *wps, const u8 *mac_addr);
  113. void wps_pwd_auth_fail_event(struct wps_context *wps, int enrollee, int part,
  114. const u8 *mac_addr);
  115. void wps_pbc_overlap_event(struct wps_context *wps);
  116. void wps_pbc_timeout_event(struct wps_context *wps);
  117. void wps_pbc_active_event(struct wps_context *wps);
  118. void wps_pbc_disable_event(struct wps_context *wps);
  119. struct wpabuf * wps_build_wsc_ack(struct wps_data *wps);
  120. struct wpabuf * wps_build_wsc_nack(struct wps_data *wps);
  121. /* wps_attr_build.c */
  122. int wps_build_public_key(struct wps_data *wps, struct wpabuf *msg);
  123. int wps_build_req_type(struct wpabuf *msg, enum wps_request_type type);
  124. int wps_build_resp_type(struct wpabuf *msg, enum wps_response_type type);
  125. int wps_build_config_methods(struct wpabuf *msg, u16 methods);
  126. int wps_build_uuid_e(struct wpabuf *msg, const u8 *uuid);
  127. int wps_build_dev_password_id(struct wpabuf *msg, u16 id);
  128. int wps_build_config_error(struct wpabuf *msg, u16 err);
  129. int wps_build_authenticator(struct wps_data *wps, struct wpabuf *msg);
  130. int wps_build_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg);
  131. int wps_build_encr_settings(struct wps_data *wps, struct wpabuf *msg,
  132. struct wpabuf *plain);
  133. int wps_build_version(struct wpabuf *msg);
  134. int wps_build_wfa_ext(struct wpabuf *msg, int req_to_enroll,
  135. const u8 *auth_macs, size_t auth_macs_count);
  136. int wps_build_msg_type(struct wpabuf *msg, enum wps_msg_type msg_type);
  137. int wps_build_enrollee_nonce(struct wps_data *wps, struct wpabuf *msg);
  138. int wps_build_registrar_nonce(struct wps_data *wps, struct wpabuf *msg);
  139. int wps_build_auth_type_flags(struct wps_data *wps, struct wpabuf *msg);
  140. int wps_build_encr_type_flags(struct wps_data *wps, struct wpabuf *msg);
  141. int wps_build_conn_type_flags(struct wps_data *wps, struct wpabuf *msg);
  142. int wps_build_assoc_state(struct wps_data *wps, struct wpabuf *msg);
  143. int wps_build_oob_dev_pw(struct wpabuf *msg, u16 dev_pw_id,
  144. const struct wpabuf *pubkey, const u8 *dev_pw,
  145. size_t dev_pw_len);
  146. struct wpabuf * wps_ie_encapsulate(struct wpabuf *data);
  147. int wps_build_mac_addr(struct wpabuf *msg, const u8 *addr);
  148. int wps_build_rf_bands_attr(struct wpabuf *msg, u8 rf_bands);
  149. int wps_build_ap_channel(struct wpabuf *msg, u16 ap_channel);
  150. /* wps_attr_process.c */
  151. int wps_process_authenticator(struct wps_data *wps, const u8 *authenticator,
  152. const struct wpabuf *msg);
  153. int wps_process_key_wrap_auth(struct wps_data *wps, struct wpabuf *msg,
  154. const u8 *key_wrap_auth);
  155. int wps_process_cred(struct wps_parse_attr *attr,
  156. struct wps_credential *cred);
  157. int wps_process_ap_settings(struct wps_parse_attr *attr,
  158. struct wps_credential *cred);
  159. /* wps_enrollee.c */
  160. struct wpabuf * wps_enrollee_get_msg(struct wps_data *wps,
  161. enum wsc_op_code *op_code);
  162. enum wps_process_res wps_enrollee_process_msg(struct wps_data *wps,
  163. enum wsc_op_code op_code,
  164. const struct wpabuf *msg);
  165. /* wps_registrar.c */
  166. struct wpabuf * wps_registrar_get_msg(struct wps_data *wps,
  167. enum wsc_op_code *op_code);
  168. enum wps_process_res wps_registrar_process_msg(struct wps_data *wps,
  169. enum wsc_op_code op_code,
  170. const struct wpabuf *msg);
  171. int wps_build_cred(struct wps_data *wps, struct wpabuf *msg);
  172. int wps_device_store(struct wps_registrar *reg,
  173. struct wps_device_data *dev, const u8 *uuid);
  174. void wps_registrar_selected_registrar_changed(struct wps_registrar *reg,
  175. u16 dev_pw_id);
  176. const u8 * wps_authorized_macs(struct wps_registrar *reg, size_t *count);
  177. int wps_registrar_pbc_overlap(struct wps_registrar *reg,
  178. const u8 *addr, const u8 *uuid_e);
  179. void wps_registrar_remove_nfc_pw_token(struct wps_registrar *reg,
  180. struct wps_nfc_pw_token *token);
  181. #endif /* WPS_I_H */