wps.h
Go to the documentation of this file.
00001 /*
00002  * Wi-Fi Protected Setup
00003  * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  */
00014 
00015 #ifndef WPS_H
00016 #define WPS_H
00017 
00018 #include "wps_defs.h"
00019 
00023 enum wsc_op_code {
00024         WSC_UPnP = 0 /* No OP Code in UPnP transport */,
00025         WSC_Start = 0x01,
00026         WSC_ACK = 0x02,
00027         WSC_NACK = 0x03,
00028         WSC_MSG = 0x04,
00029         WSC_Done = 0x05,
00030         WSC_FRAG_ACK = 0x06
00031 };
00032 
00033 struct wps_registrar;
00034 struct upnp_wps_device_sm;
00035 struct wps_er;
00036 
00051 struct wps_credential {
00052         u8 ssid[32];
00053         size_t ssid_len;
00054         u16 auth_type;
00055         u16 encr_type;
00056         u8 key_idx;
00057         u8 key[64];
00058         size_t key_len;
00059         u8 mac_addr[ETH_ALEN];
00060         const u8 *cred_attr;
00061         size_t cred_attr_len;
00062 };
00063 
00064 #define WPS_DEV_TYPE_LEN 8
00065 #define WPS_DEV_TYPE_BUFSIZE 21
00066 
00079 struct wps_device_data {
00080         u8 mac_addr[ETH_ALEN];
00081         char *device_name;
00082         char *manufacturer;
00083         char *model_name;
00084         char *model_number;
00085         char *serial_number;
00086         u8 pri_dev_type[WPS_DEV_TYPE_LEN];
00087         u32 os_version;
00088         u8 rf_bands;
00089 };
00090 
00091 struct oob_conf_data {
00092         enum {
00093                 OOB_METHOD_UNKNOWN = 0,
00094                 OOB_METHOD_DEV_PWD_E,
00095                 OOB_METHOD_DEV_PWD_R,
00096                 OOB_METHOD_CRED,
00097         } oob_method;
00098         struct wpabuf *dev_password;
00099         struct wpabuf *pubkey_hash;
00100 };
00101 
00105 struct wps_config {
00109         struct wps_context *wps;
00110 
00114         int registrar;
00115 
00119         const u8 *pin;
00120 
00124         size_t pin_len;
00125 
00129         int pbc;
00130 
00134         const struct wpabuf *assoc_wps_ie;
00135 
00144         const struct wps_credential *new_ap_settings;
00145 
00149         const u8 *peer_addr;
00150 
00158         int use_psk_key;
00159 };
00160 
00161 struct wps_data * wps_init(const struct wps_config *cfg);
00162 
00163 void wps_deinit(struct wps_data *data);
00164 
00168 enum wps_process_res {
00172         WPS_DONE,
00173 
00177         WPS_CONTINUE,
00178 
00182         WPS_FAILURE,
00183 
00188         WPS_PENDING
00189 };
00190 enum wps_process_res wps_process_msg(struct wps_data *wps,
00191                                      enum wsc_op_code op_code,
00192                                      const struct wpabuf *msg);
00193 
00194 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
00195 
00196 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
00197 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
00198 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
00199 
00200 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
00201 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
00202                                        const u8 *uuid,
00203                                        enum wps_request_type req_type);
00204 
00205 
00209 struct wps_registrar_config {
00220         int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
00221                           size_t psk_len);
00222 
00234         int (*set_ie_cb)(void *ctx, struct wpabuf *beacon_ie,
00235                          struct wpabuf *probe_resp_ie);
00236 
00247         void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
00248                               const struct wps_device_data *dev);
00249 
00259         void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
00260                                const u8 *uuid_e);
00261 
00277         void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
00278                                u16 sel_reg_config_methods);
00279 
00291         void (*enrollee_seen_cb)(void *ctx, const u8 *addr, const u8 *uuid_e,
00292                                  const u8 *pri_dev_type, u16 config_methods,
00293                                  u16 dev_password_id, u8 request_type,
00294                                  const char *dev_name);
00295 
00299         void *cb_ctx;
00300 
00309         int skip_cred_build;
00310 
00319         const u8 *extra_cred;
00320 
00324         size_t extra_cred_len;
00325 
00336         int disable_auto_conf;
00337 
00341         int static_wep_only;
00342 };
00343 
00344 
00348 enum wps_event {
00352         WPS_EV_M2D,
00353 
00357         WPS_EV_FAIL,
00358 
00362         WPS_EV_SUCCESS,
00363 
00367         WPS_EV_PWD_AUTH_FAIL,
00368 
00372         WPS_EV_PBC_OVERLAP,
00373 
00377         WPS_EV_PBC_TIMEOUT,
00378 
00382         WPS_EV_ER_AP_ADD,
00383 
00387         WPS_EV_ER_AP_REMOVE,
00388 
00392         WPS_EV_ER_ENROLLEE_ADD,
00393 
00397         WPS_EV_ER_ENROLLEE_REMOVE
00398 };
00399 
00403 union wps_event_data {
00407         struct wps_event_m2d {
00408                 u16 config_methods;
00409                 const u8 *manufacturer;
00410                 size_t manufacturer_len;
00411                 const u8 *model_name;
00412                 size_t model_name_len;
00413                 const u8 *model_number;
00414                 size_t model_number_len;
00415                 const u8 *serial_number;
00416                 size_t serial_number_len;
00417                 const u8 *dev_name;
00418                 size_t dev_name_len;
00419                 const u8 *primary_dev_type; /* 8 octets */
00420                 u16 config_error;
00421                 u16 dev_password_id;
00422         } m2d;
00423 
00428         struct wps_event_fail {
00429                 int msg;
00430         } fail;
00431 
00432         struct wps_event_pwd_auth_fail {
00433                 int enrollee;
00434                 int part;
00435         } pwd_auth_fail;
00436 
00437         struct wps_event_er_ap {
00438                 const u8 *uuid;
00439                 const u8 *mac_addr;
00440                 const char *friendly_name;
00441                 const char *manufacturer;
00442                 const char *manufacturer_url;
00443                 const char *model_description;
00444                 const char *model_name;
00445                 const char *model_number;
00446                 const char *model_url;
00447                 const char *serial_number;
00448                 const char *upc;
00449                 const u8 *pri_dev_type;
00450                 u8 wps_state;
00451         } ap;
00452 
00453         struct wps_event_er_enrollee {
00454                 const u8 *uuid;
00455                 const u8 *mac_addr;
00456                 int m1_received;
00457                 u16 config_methods;
00458                 u16 dev_passwd_id;
00459                 const u8 *pri_dev_type;
00460                 const char *dev_name;
00461                 const char *manufacturer;
00462                 const char *model_name;
00463                 const char *model_number;
00464                 const char *serial_number;
00465         } enrollee;
00466 };
00467 
00475 struct upnp_pending_message {
00476         struct upnp_pending_message *next;
00477         u8 addr[ETH_ALEN];
00478         struct wpabuf *msg;
00479         enum wps_msg_type type;
00480 };
00481 
00488 struct wps_context {
00492         int ap;
00493 
00497         struct wps_registrar *registrar;
00498 
00502         enum wps_state wps_state;
00503 
00507         int ap_setup_locked;
00508 
00512         u8 uuid[16];
00513 
00521         u8 ssid[32];
00522 
00526         size_t ssid_len;
00527 
00531         struct wps_device_data dev;
00532 
00536         struct oob_conf_data oob_conf;
00537 
00541         u16 oob_dev_pw_id;
00542 
00546         void *dh_ctx;
00547 
00551         struct wpabuf *dh_privkey;
00552 
00556         struct wpabuf *dh_pubkey;
00557 
00563         u16 config_methods;
00564 
00568         u16 encr_types;
00569 
00573         u16 auth_types;
00574 
00590         u8 *network_key;
00591 
00595         size_t network_key_len;
00596 
00603         u8 psk[32];
00604 
00608         int psk_set;
00609 
00616         u8 *ap_settings;
00617 
00621         size_t ap_settings_len;
00622 
00626         char *friendly_name;
00627 
00631         char *manufacturer_url;
00632 
00636         char *model_description;
00637 
00641         char *model_url;
00642 
00646         char *upc;
00647 
00654         int (*cred_cb)(void *ctx, const struct wps_credential *cred);
00655 
00662         void (*event_cb)(void *ctx, enum wps_event event,
00663                          union wps_event_data *data);
00664 
00668         void *cb_ctx;
00669 
00670         struct upnp_wps_device_sm *wps_upnp;
00671 
00672         /* Pending messages from UPnP PutWLANResponse */
00673         struct upnp_pending_message *upnp_msgs;
00674 };
00675 
00676 struct oob_device_data {
00677         char *device_name;
00678         char *device_path;
00679         void * (*init_func)(struct wps_context *, struct oob_device_data *,
00680                             int);
00681         struct wpabuf * (*read_func)(void *);
00682         int (*write_func)(void *, struct wpabuf *);
00683         void (*deinit_func)(void *);
00684 };
00685 
00686 struct oob_nfc_device_data {
00687         int (*init_func)(char *);
00688         void * (*read_func)(size_t *);
00689         int (*write_func)(void *, size_t);
00690         void (*deinit_func)(void);
00691 };
00692 
00693 struct wps_registrar *
00694 wps_registrar_init(struct wps_context *wps,
00695                    const struct wps_registrar_config *cfg);
00696 void wps_registrar_deinit(struct wps_registrar *reg);
00697 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
00698                           const u8 *pin, size_t pin_len, int timeout);
00699 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
00700 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
00701 int wps_registrar_button_pushed(struct wps_registrar *reg);
00702 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
00703                                 const struct wpabuf *wps_data);
00704 int wps_registrar_update_ie(struct wps_registrar *reg);
00705 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
00706                            char *buf, size_t buflen);
00707 
00708 unsigned int wps_pin_checksum(unsigned int pin);
00709 unsigned int wps_pin_valid(unsigned int pin);
00710 unsigned int wps_generate_pin(void);
00711 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
00712 
00713 struct oob_device_data * wps_get_oob_device(char *device_type);
00714 struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
00715 int wps_get_oob_method(char *method);
00716 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
00717                     int registrar);
00718 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
00719 
00720 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname);
00721 void wps_er_refresh(struct wps_er *er);
00722 void wps_er_deinit(struct wps_er *er, void (*cb)(void *ctx), void *ctx);
00723 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
00724                         u16 sel_reg_config_methods);
00725 int wps_er_pbc(struct wps_er *er, const u8 *uuid);
00726 int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
00727                  size_t pin_len);
00728 
00729 int wps_dev_type_str2bin(const char *str, u8 dev_type[WPS_DEV_TYPE_LEN]);
00730 char * wps_dev_type_bin2str(const u8 dev_type[WPS_DEV_TYPE_LEN], char *buf,
00731                             size_t buf_len);
00732 void uuid_gen_mac_addr(const u8 *mac_addr, u8 *uuid);
00733 u16 wps_config_methods_str2bin(const char *str);
00734 
00735 #endif /* WPS_H */


wpa_supplicant_node
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Jan 2 2014 11:25:15