2 * Wi-Fi Protected Setup
3 * Copyright (c) 2007-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.
29 struct wps_credential {
37 u8 mac_addr[ETH_ALEN];
40 struct wps_device_data {
41 u8 mac_addr[ETH_ALEN];
51 u8 rf_bands; /* WPS_RF_* */
56 struct wps_context *wps;
57 struct wps_registrar *registrar; /* NULL for Enrollee */
58 const u8 *enrollee_mac_addr; /* NULL for Registrar */
59 const u8 *pin; /* Enrollee Device Password (NULL for Registrar or PBC)
62 const u8 *uuid; /* 128-bit Enrollee UUID (NULL for Registrar) */
64 const struct wpabuf *assoc_wps_ie; /* (Re)AssocReq WPS IE (in AP) */
67 struct wps_data * wps_init(const struct wps_config *cfg);
69 void wps_deinit(struct wps_data *data);
71 enum wps_process_res {
72 WPS_DONE, WPS_CONTINUE, WPS_FAILURE, WPS_PENDING
74 enum wps_process_res wps_process_msg(struct wps_data *wps, u8 op_code,
75 const struct wpabuf *msg);
77 struct wpabuf * wps_get_msg(struct wps_data *wps, u8 *op_code);
79 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
80 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
81 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
82 struct wpabuf * wps_build_assoc_req_ie(u8 req_type);
83 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
84 const u8 *uuid, u8 req_type);
87 struct wps_registrar_config {
88 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
90 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
91 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
92 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
93 const struct wps_device_data *dev);
103 union wps_event_data {
104 struct wps_event_m2d {
106 const u8 *manufacturer;
107 size_t manufacturer_len;
108 const u8 *model_name;
109 size_t model_name_len;
110 const u8 *model_number;
111 size_t model_number_len;
112 const u8 *serial_number;
113 size_t serial_number_len;
116 const u8 *primary_dev_type; /* 8 octets */
120 struct wps_event_fail {
121 int msg; /* enum wps_msg_type */
126 * struct wps_context - Long term WPS context data
128 * This data is stored at the higher layer Authenticator or Supplicant data
129 * structures and it is maintained over multiple registration protocol runs.
133 struct wps_registrar *registrar;
139 struct wps_device_data dev;
140 u16 config_methods; /* bit field of WPS_CONFIG_* */
141 u16 encr_types; /* bit field of WPS_ENCR_* */
142 u16 auth_types; /* bit field of WPS_AUTH_* */
143 u8 *network_key; /* or NULL to generate per-device PSK */
144 size_t network_key_len;
146 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
147 void (*event_cb)(void *ctx, enum wps_event event,
148 union wps_event_data *data);
153 struct wps_registrar *
154 wps_registrar_init(struct wps_context *wps,
155 const struct wps_registrar_config *cfg);
156 void wps_registrar_deinit(struct wps_registrar *reg);
157 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
158 const u8 *pin, size_t pin_len);
159 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
160 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
161 int wps_registrar_button_pushed(struct wps_registrar *reg);
162 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
163 const struct wpabuf *wps_data);
165 unsigned int wps_pin_checksum(unsigned int pin);
166 unsigned int wps_pin_valid(unsigned int pin);
167 unsigned int wps_generate_pin(void);