00001
00016 #ifndef WPS_H
00017 #define WPS_H
00018
00019 #include "wps_defs.h"
00020
00024 enum wsc_op_code {
00025 WSC_UPnP = 0 ,
00026 WSC_Start = 0x01,
00027 WSC_ACK = 0x02,
00028 WSC_NACK = 0x03,
00029 WSC_MSG = 0x04,
00030 WSC_Done = 0x05,
00031 WSC_FRAG_ACK = 0x06
00032 };
00033
00034 struct wps_registrar;
00035 struct upnp_wps_device_sm;
00036 struct wps_er;
00037
00053 struct wps_credential {
00054 u8 ssid[32];
00055 size_t ssid_len;
00056 u16 auth_type;
00057 u16 encr_type;
00058 u8 key_idx;
00059 u8 key[64];
00060 size_t key_len;
00061 u8 mac_addr[ETH_ALEN];
00062 const u8 *cred_attr;
00063 size_t cred_attr_len;
00064 };
00065
00081 struct wps_device_data {
00082 u8 mac_addr[ETH_ALEN];
00083 char *device_name;
00084 char *manufacturer;
00085 char *model_name;
00086 char *model_number;
00087 char *serial_number;
00088 u16 categ;
00089 u32 oui;
00090 u16 sub_categ;
00091 u32 os_version;
00092 u8 rf_bands;
00093 };
00094
00095 struct oob_conf_data {
00096 enum {
00097 OOB_METHOD_UNKNOWN = 0,
00098 OOB_METHOD_DEV_PWD_E,
00099 OOB_METHOD_DEV_PWD_R,
00100 OOB_METHOD_CRED,
00101 } oob_method;
00102 struct wpabuf *dev_password;
00103 struct wpabuf *pubkey_hash;
00104 };
00105
00110 struct wps_config {
00115 struct wps_context *wps;
00116
00121 int registrar;
00122
00127 const u8 *pin;
00128
00133 size_t pin_len;
00134
00139 int pbc;
00140
00144 const struct wpabuf *assoc_wps_ie;
00145
00155 const struct wps_credential *new_ap_settings;
00156
00160 const u8 *peer_addr;
00161 };
00162
00163 struct wps_data * wps_init(const struct wps_config *cfg);
00164
00165 void wps_deinit(struct wps_data *data);
00166
00170 enum wps_process_res {
00175 WPS_DONE,
00176
00181 WPS_CONTINUE,
00182
00187 WPS_FAILURE,
00188
00194 WPS_PENDING
00195 };
00196 enum wps_process_res wps_process_msg(struct wps_data *wps,
00197 enum wsc_op_code op_code,
00198 const struct wpabuf *msg);
00199
00200 struct wpabuf * wps_get_msg(struct wps_data *wps, enum wsc_op_code *op_code);
00201
00202 int wps_is_selected_pbc_registrar(const struct wpabuf *msg);
00203 int wps_is_selected_pin_registrar(const struct wpabuf *msg);
00204 const u8 * wps_get_uuid_e(const struct wpabuf *msg);
00205
00206 struct wpabuf * wps_build_assoc_req_ie(enum wps_request_type req_type);
00207 struct wpabuf * wps_build_probe_req_ie(int pbc, struct wps_device_data *dev,
00208 const u8 *uuid,
00209 enum wps_request_type req_type);
00210
00211
00216 struct wps_registrar_config {
00228 int (*new_psk_cb)(void *ctx, const u8 *mac_addr, const u8 *psk,
00229 size_t psk_len);
00230
00244 int (*set_ie_cb)(void *ctx, const u8 *beacon_ie, size_t beacon_ie_len,
00245 const u8 *probe_resp_ie, size_t probe_resp_ie_len);
00246
00258 void (*pin_needed_cb)(void *ctx, const u8 *uuid_e,
00259 const struct wps_device_data *dev);
00260
00271 void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
00272 const u8 *uuid_e);
00273
00290 void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
00291 u16 sel_reg_config_methods);
00292
00296 void *cb_ctx;
00297
00306 int skip_cred_build;
00307
00316 const u8 *extra_cred;
00317
00321 size_t extra_cred_len;
00322
00334 int disable_auto_conf;
00335
00340 int static_wep_only;
00341 };
00342
00343
00347 enum wps_event {
00352 WPS_EV_M2D,
00353
00358 WPS_EV_FAIL,
00359
00364 WPS_EV_SUCCESS,
00365
00370 WPS_EV_PWD_AUTH_FAIL,
00371
00376 WPS_EV_PBC_OVERLAP,
00377
00382 WPS_EV_PBC_TIMEOUT,
00383
00388 WPS_EV_ER_AP_ADD,
00389
00394 WPS_EV_ER_AP_REMOVE,
00395
00400 WPS_EV_ER_ENROLLEE_ADD,
00401
00406 WPS_EV_ER_ENROLLEE_REMOVE
00407 };
00408
00412 union wps_event_data {
00417 struct wps_event_m2d {
00418 u16 config_methods;
00419 const u8 *manufacturer;
00420 size_t manufacturer_len;
00421 const u8 *model_name;
00422 size_t model_name_len;
00423 const u8 *model_number;
00424 size_t model_number_len;
00425 const u8 *serial_number;
00426 size_t serial_number_len;
00427 const u8 *dev_name;
00428 size_t dev_name_len;
00429 const u8 *primary_dev_type;
00430 u16 config_error;
00431 u16 dev_password_id;
00432 } m2d;
00433
00439 struct wps_event_fail {
00440 int msg;
00441 } fail;
00442
00443 struct wps_event_pwd_auth_fail {
00444 int enrollee;
00445 int part;
00446 } pwd_auth_fail;
00447
00448 struct wps_event_er_ap {
00449 const u8 *uuid;
00450 const u8 *mac_addr;
00451 const char *friendly_name;
00452 const char *manufacturer;
00453 const char *manufacturer_url;
00454 const char *model_description;
00455 const char *model_name;
00456 const char *model_number;
00457 const char *model_url;
00458 const char *serial_number;
00459 const char *upc;
00460 const u8 *pri_dev_type;
00461 u8 wps_state;
00462 } ap;
00463
00464 struct wps_event_er_enrollee {
00465 const u8 *uuid;
00466 const u8 *mac_addr;
00467 int m1_received;
00468 u16 config_methods;
00469 u16 dev_passwd_id;
00470 const u8 *pri_dev_type;
00471 const char *dev_name;
00472 const char *manufacturer;
00473 const char *model_name;
00474 const char *model_number;
00475 const char *serial_number;
00476 } enrollee;
00477 };
00478
00487 struct upnp_pending_message {
00488 struct upnp_pending_message *next;
00489 u8 addr[ETH_ALEN];
00490 struct wpabuf *msg;
00491 enum wps_msg_type type;
00492 };
00493
00501 struct wps_context {
00506 int ap;
00507
00512 struct wps_registrar *registrar;
00513
00518 enum wps_state wps_state;
00519
00524 int ap_setup_locked;
00525
00530 u8 uuid[16];
00531
00540 u8 ssid[32];
00541
00546 size_t ssid_len;
00547
00552 struct wps_device_data dev;
00553
00558 struct oob_conf_data oob_conf;
00559
00564 u16 oob_dev_pw_id;
00565
00570 void *dh_ctx;
00571
00576 struct wpabuf *dh_privkey;
00577
00582 struct wpabuf *dh_pubkey;
00583
00590 u16 config_methods;
00591
00596 u16 encr_types;
00597
00602 u16 auth_types;
00603
00612 u8 *network_key;
00613
00618 size_t network_key_len;
00619
00627 u8 *ap_settings;
00628
00633 size_t ap_settings_len;
00634
00639 char *friendly_name;
00640
00645 char *manufacturer_url;
00646
00651 char *model_description;
00652
00657 char *model_url;
00658
00663 char *upc;
00664
00672 int (*cred_cb)(void *ctx, const struct wps_credential *cred);
00673
00681 void (*event_cb)(void *ctx, enum wps_event event,
00682 union wps_event_data *data);
00683
00687 void *cb_ctx;
00688
00689 struct upnp_wps_device_sm *wps_upnp;
00690
00691
00692 struct upnp_pending_message *upnp_msgs;
00693 };
00694
00695 struct oob_device_data {
00696 char *device_name;
00697 char *device_path;
00698 void * (*init_func)(struct wps_context *, struct oob_device_data *,
00699 int);
00700 struct wpabuf * (*read_func)(void *);
00701 int (*write_func)(void *, struct wpabuf *);
00702 void (*deinit_func)(void *);
00703 };
00704
00705 struct oob_nfc_device_data {
00706 int (*init_func)(char *);
00707 void * (*read_func)(size_t *);
00708 int (*write_func)(void *, size_t);
00709 void (*deinit_func)(void);
00710 };
00711
00712 struct wps_registrar *
00713 wps_registrar_init(struct wps_context *wps,
00714 const struct wps_registrar_config *cfg);
00715 void wps_registrar_deinit(struct wps_registrar *reg);
00716 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
00717 const u8 *pin, size_t pin_len, int timeout);
00718 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
00719 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
00720 int wps_registrar_button_pushed(struct wps_registrar *reg);
00721 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
00722 const struct wpabuf *wps_data);
00723 int wps_registrar_update_ie(struct wps_registrar *reg);
00724 int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
00725 const struct wpabuf *msg);
00726 int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
00727 char *buf, size_t buflen);
00728
00729 unsigned int wps_pin_checksum(unsigned int pin);
00730 unsigned int wps_pin_valid(unsigned int pin);
00731 unsigned int wps_generate_pin(void);
00732 void wps_free_pending_msgs(struct upnp_pending_message *msgs);
00733
00734 struct oob_device_data * wps_get_oob_device(char *device_type);
00735 struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
00736 int wps_get_oob_method(char *method);
00737 int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
00738 int registrar);
00739 int wps_attr_text(struct wpabuf *data, char *buf, char *end);
00740
00741 struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname);
00742 void wps_er_refresh(struct wps_er *er);
00743 void wps_er_deinit(struct wps_er *er);
00744 void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
00745 u16 sel_reg_config_methods);
00746 int wps_er_pbc(struct wps_er *er, const u8 *uuid);
00747 int wps_er_learn(struct wps_er *er, const u8 *uuid, const u8 *pin,
00748 size_t pin_len);
00749
00750 #endif
00751