wps.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Wi-Fi Protected Setup
  3. * Copyright (c) 2007-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_H
  15. #define WPS_H
  16. enum wsc_op_code {
  17. WSC_Start = 0x01,
  18. WSC_ACK = 0x02,
  19. WSC_NACK = 0x03,
  20. WSC_MSG = 0x04,
  21. WSC_Done = 0x05,
  22. WSC_FRAG_ACK = 0x06
  23. };
  24. struct wps_registrar;
  25. struct wps_credential {
  26. u8 ssid[32];
  27. size_t ssid_len;
  28. u16 auth_type;
  29. u16 encr_type;
  30. u8 key_idx;
  31. u8 key[64];
  32. size_t key_len;
  33. u8 mac_addr[ETH_ALEN];
  34. };
  35. struct wps_config {
  36. int authenticator;
  37. struct wps_context *wps;
  38. struct wps_registrar *registrar; /* NULL for Enrollee */
  39. const u8 *enrollee_mac_addr; /* NULL for Registrar */
  40. const u8 *pin; /* Enrollee Device Password (NULL for Registrar or PBC)
  41. */
  42. size_t pin_len;
  43. const u8 *uuid; /* 128-bit Enrollee UUID (NULL for Registrar) */
  44. int pbc;
  45. const struct wpabuf *assoc_wps_ie; /* (Re)AssocReq WPS IE (in AP) */
  46. };
  47. struct wps_data * wps_init(const struct wps_config *cfg);
  48. void wps_deinit(struct wps_data *data);
  49. enum wps_process_res {
  50. WPS_DONE, WPS_CONTINUE, WPS_FAILURE, WPS_PENDING
  51. };
  52. enum wps_process_res wps_process_msg(struct wps_data *wps, u8 op_code,
  53. const struct wpabuf *msg);
  54. struct wpabuf * wps_get_msg(struct wps_data *wps, u8 *op_code);
  55. int wps_is_selected_pbc_registrar(const u8 *buf, size_t len);
  56. int wps_is_selected_pin_registrar(const u8 *buf, size_t len);
  57. const u8 * wps_get_uuid_e(const u8 *buf, size_t len);
  58. struct wps_device_data {
  59. u8 mac_addr[ETH_ALEN];
  60. char *device_name;
  61. char *manufacturer;
  62. char *model_name;
  63. char *model_number;
  64. char *serial_number;
  65. u16 categ;
  66. u32 oui;
  67. u16 sub_categ;
  68. u32 os_version;
  69. };
  70. struct wps_registrar_config {
  71. int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
  72. size_t psk_len);
  73. int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
  74. const u8 *probe_resp_ie, size_t probe_resp_ie_len);
  75. void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
  76. const struct wps_device_data *dev);
  77. void *cb_ctx;
  78. };
  79. /**
  80. * struct wps_context - Long term WPS context data
  81. *
  82. * This data is stored at the higher layer Authenticator or Supplicant data
  83. * structures and it is maintained over multiple registration protocol runs.
  84. */
  85. struct wps_context {
  86. int ap;
  87. struct wps_registrar *registrar;
  88. int wps_state;
  89. int ap_setup_locked;
  90. u8 uuid[16];
  91. u8 ssid[32];
  92. size_t ssid_len;
  93. struct wps_device_data dev;
  94. u16 config_methods; /* bit field of WPS_CONFIG_* */
  95. u16 encr_types; /* bit field of WPS_ENCR_* */
  96. u16 auth_types; /* bit field of WPS_AUTH_* */
  97. u8 *network_key; /* or NULL to generate per-device PSK */
  98. size_t network_key_len;
  99. int (*cred_cb)(void *ctx, const struct wps_credential *cred);
  100. void *cb_ctx;
  101. };
  102. struct wps_registrar *
  103. wps_registrar_init(struct wps_context *wps,
  104. const struct wps_registrar_config *cfg);
  105. void wps_registrar_deinit(struct wps_registrar *reg);
  106. int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
  107. const u8 *pin, size_t pin_len);
  108. int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
  109. int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
  110. int wps_registrar_button_pushed(struct wps_registrar *reg);
  111. void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
  112. const struct wpabuf *wps_data);
  113. struct wpabuf * wps_build_assoc_req_ie(void);
  114. struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
  115. const u8 *uuid);
  116. #endif /* WPS_H */