WPS ER: Add preliminary PBC support
[libeap.git] / src / wps / wps.h
index 9d723fe..14c6c58 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Wi-Fi Protected Setup
- * Copyright (c) 2007-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2007-2009, Jouni Malinen <j@w1.fi>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
@@ -21,6 +21,7 @@
  * enum wsc_op_code - EAP-WSC OP-Code values
  */
 enum wsc_op_code {
+       WSC_UPnP = 0 /* No OP Code in UPnP transport */,
        WSC_Start = 0x01,
        WSC_ACK = 0x02,
        WSC_NACK = 0x03,
@@ -30,6 +31,8 @@ enum wsc_op_code {
 };
 
 struct wps_registrar;
+struct upnp_wps_device_sm;
+struct wps_er;
 
 /**
  * struct wps_credential - WPS Credential
@@ -41,6 +44,9 @@ struct wps_registrar;
  * @key: Key
  * @key_len: Key length in octets
  * @mac_addr: MAC address of the peer
+ * @cred_attr: Unparsed Credential attribute data (used only in cred_cb());
+ *     this may be %NULL, if not used
+ * @cred_attr_len: Length of cred_attr in octets
  */
 struct wps_credential {
        u8 ssid[32];
@@ -51,6 +57,8 @@ struct wps_credential {
        u8 key[64];
        size_t key_len;
        u8 mac_addr[ETH_ALEN];
+       const u8 *cred_attr;
+       size_t cred_attr_len;
 };
 
 /**
@@ -81,6 +89,17 @@ struct wps_device_data {
        u8 rf_bands;
 };
 
+struct oob_conf_data {
+       enum {
+               OOB_METHOD_UNKNOWN = 0,
+               OOB_METHOD_DEV_PWD_E,
+               OOB_METHOD_DEV_PWD_R,
+               OOB_METHOD_CRED,
+       } oob_method;
+       struct wpabuf *dev_password;
+       struct wpabuf *pubkey_hash;
+};
+
 /**
  * struct wps_config - WPS configuration for a single registration protocol run
  */
@@ -91,11 +110,9 @@ struct wps_config {
        struct wps_context *wps;
 
        /**
-        * registrar - Pointer to WPS registrar data from wps_registrar_init()
-        * This is only used if the local end is Registrar; set to %NULL for
-        * Enrollee.
+        * registrar - Whether this end is a Registrar
         */
-       struct wps_registrar *registrar;
+       int registrar;
 
        /**
         * pin - Enrollee Device Password (%NULL for Registrar or PBC)
@@ -116,6 +133,21 @@ struct wps_config {
         * assoc_wps_ie: (Re)AssocReq WPS IE (in AP; %NULL if not AP)
         */
        const struct wpabuf *assoc_wps_ie;
+
+       /**
+        * new_ap_settings - New AP settings (%NULL if not used)
+        *
+        * This parameter provides new AP settings when using a wireless
+        * stations as a Registrar to configure the AP. %NULL means that AP
+        * will not be reconfigured, i.e., the station will only learn the
+        * current AP settings by using AP PIN.
+        */
+       const struct wps_credential *new_ap_settings;
+
+       /**
+        * peer_addr: MAC address of the peer in AP; %NULL if not AP
+        */
+       const u8 *peer_addr;
 };
 
 struct wps_data * wps_init(const struct wps_config *cfg);
@@ -139,7 +171,13 @@ enum wps_process_res {
        /**
         * WPS_FAILURE - Processing failed
         */
-       WPS_FAILURE
+       WPS_FAILURE,
+
+       /**
+        * WPS_PENDING - Processing continues, but waiting for an external
+        *      event (e.g., UPnP message from an external Registrar)
+        */
+       WPS_PENDING
 };
 enum wps_process_res wps_process_msg(struct wps_data *wps,
                                     enum wsc_op_code op_code,
@@ -203,9 +241,81 @@ struct wps_registrar_config {
                              const struct wps_device_data *dev);
 
        /**
+        * reg_success_cb - Callback for reporting successful registration
+        * @ctx: Higher layer context data (cb_ctx)
+        * @mac_addr: MAC address of the Enrollee
+        * @uuid_e: UUID-E of the Enrollee
+        *
+        * This callback is called whenever an Enrollee completes registration
+        * successfully.
+        */
+       void (*reg_success_cb)(void *ctx, const u8 *mac_addr,
+                              const u8 *uuid_e);
+
+       /**
+        * set_sel_reg_cb - Callback for reporting selected registrar changes
+        * @ctx: Higher layer context data (cb_ctx)
+        * @sel_reg: Whether the Registrar is selected
+        * @dev_passwd_id: Device Password ID to indicate with method or
+        *      specific password the Registrar intends to use
+        * @sel_reg_config_methods: Bit field of active config methods
+        *
+        * This callback is called whenever the Selected Registrar state
+        * changes (e.g., a new PIN becomes available or PBC is invoked). This
+        * callback is only used by External Registrar implementation;
+        * set_ie_cb() is used by AP implementation in similar caes, but it
+        * provides the full WPS IE data instead of just the minimal Registrar
+        * state information.
+        */
+       void (*set_sel_reg_cb)(void *ctx, int sel_reg, u16 dev_passwd_id,
+                              u16 sel_reg_config_methods);
+
+       /**
         * cb_ctx: Higher layer context data for Registrar callbacks
         */
        void *cb_ctx;
+
+       /**
+        * skip_cred_build: Do not build credential
+        *
+        * This option can be used to disable internal code that builds
+        * Credential attribute into M8 based on the current network
+        * configuration and Enrollee capabilities. The extra_cred data will
+        * then be used as the Credential(s).
+        */
+       int skip_cred_build;
+
+       /**
+        * extra_cred: Additional Credential attribute(s)
+        *
+        * This optional data (set to %NULL to disable) can be used to add
+        * Credential attribute(s) for other networks into M8. If
+        * skip_cred_build is set, this will also override the automatically
+        * generated Credential attribute.
+        */
+       const u8 *extra_cred;
+
+       /**
+        * extra_cred_len: Length of extra_cred in octets
+        */
+       size_t extra_cred_len;
+
+       /**
+        * disable_auto_conf - Disable auto-configuration on first registration
+        *
+        * By default, the AP that is started in not configured state will
+        * generate a random PSK and move to configured state when the first
+        * registration protocol run is completed successfully. This option can
+        * be used to disable this functionality and leave it up to an external
+        * program to take care of configuration. This requires the extra_cred
+        * to be set with a suitable Credential and skip_cred_build being used.
+        */
+       int disable_auto_conf;
+
+       /**
+        * static_wep_only - Whether the BSS supports only static WEP
+        */
+       int static_wep_only;
 };
 
 
@@ -226,7 +336,42 @@ enum wps_event {
        /**
         * WPS_EV_SUCCESS - Registration succeeded
         */
-       WPS_EV_SUCCESS
+       WPS_EV_SUCCESS,
+
+       /**
+        * WPS_EV_PWD_AUTH_FAIL - Password authentication failed
+        */
+       WPS_EV_PWD_AUTH_FAIL,
+
+       /**
+        * WPS_EV_PBC_OVERLAP - PBC session overlap detected
+        */
+       WPS_EV_PBC_OVERLAP,
+
+       /**
+        * WPS_EV_PBC_TIMEOUT - PBC walktime expired before protocol run start
+        */
+       WPS_EV_PBC_TIMEOUT,
+
+       /**
+        * WPS_EV_ER_AP_ADD - ER: AP added
+        */
+       WPS_EV_ER_AP_ADD,
+
+       /**
+        * WPS_EV_ER_AP_REMOVE - ER: AP removed
+        */
+       WPS_EV_ER_AP_REMOVE,
+
+       /**
+        * WPS_EV_ER_ENROLLEE_ADD - ER: Enrollee added
+        */
+       WPS_EV_ER_ENROLLEE_ADD,
+
+       /**
+        * WPS_EV_ER_ENROLLEE_REMOVE - ER: Enrollee removed
+        */
+       WPS_EV_ER_ENROLLEE_REMOVE
 };
 
 /**
@@ -260,6 +405,52 @@ union wps_event_data {
        struct wps_event_fail {
                int msg;
        } fail;
+
+       struct wps_event_pwd_auth_fail {
+               int enrollee;
+               int part;
+       } pwd_auth_fail;
+
+       struct wps_event_er_ap {
+               const u8 *uuid;
+               const char *friendly_name;
+               const char *manufacturer;
+               const char *manufacturer_url;
+               const char *model_description;
+               const char *model_name;
+               const char *model_number;
+               const char *model_url;
+               const char *serial_number;
+               const char *upc;
+       } ap;
+
+       struct wps_event_er_enrollee {
+               const u8 *uuid;
+               const u8 *mac_addr;
+               int m1_received;
+               u16 config_methods;
+               u16 dev_passwd_id;
+               const u8 *pri_dev_type;
+               const char *dev_name;
+               const char *manufacturer;
+               const char *model_name;
+               const char *model_number;
+               const char *serial_number;
+       } enrollee;
+};
+
+/**
+ * struct upnp_pending_message - Pending PutWLANResponse messages
+ * @next: Pointer to next pending message or %NULL
+ * @addr: NewWLANEventMAC
+ * @msg: NewMessage
+ * @type: Message Type
+ */
+struct upnp_pending_message {
+       struct upnp_pending_message *next;
+       u8 addr[ETH_ALEN];
+       struct wpabuf *msg;
+       enum wps_msg_type type;
 };
 
 /**
@@ -314,6 +505,31 @@ struct wps_context {
        struct wps_device_data dev;
 
        /**
+        * oob_conf - OOB Config data
+        */
+       struct oob_conf_data oob_conf;
+
+       /**
+        * oob_dev_pw_id - OOB Device password id
+        */
+       u16 oob_dev_pw_id;
+
+       /**
+        * dh_ctx - Context data for Diffie-Hellman operation
+        */
+       void *dh_ctx;
+
+       /**
+        * dh_privkey - Diffie-Hellman private key
+        */
+       struct wpabuf *dh_privkey;
+
+       /**
+        * dh_pubkey_oob - Diffie-Hellman public key
+        */
+       struct wpabuf *dh_pubkey;
+
+       /**
         * config_methods - Enabled configuration methods
         *
         * Bit field of WPS_CONFIG_*
@@ -345,6 +561,44 @@ struct wps_context {
        size_t network_key_len;
 
        /**
+        * ap_settings - AP Settings override for M7 (only used at AP)
+        *
+        * If %NULL, AP Settings attributes will be generated based on the
+        * current network configuration.
+        */
+       u8 *ap_settings;
+
+       /**
+        * ap_settings_len - Length of ap_settings in octets
+        */
+       size_t ap_settings_len;
+
+       /**
+        * friendly_name - Friendly Name (required for UPnP)
+        */
+       char *friendly_name;
+
+       /**
+        * manufacturer_url - Manufacturer URL (optional for UPnP)
+        */
+       char *manufacturer_url;
+
+       /**
+        * model_description - Model Description (recommended for UPnP)
+        */
+       char *model_description;
+
+       /**
+        * model_url - Model URL (optional for UPnP)
+        */
+       char *model_url;
+
+       /**
+        * upc - Universal Product Code (optional for UPnP)
+        */
+       char *upc;
+
+       /**
         * cred_cb - Callback to notify that new Credentials were received
         * @ctx: Higher layer context data (cb_ctx)
         * @cred: The received Credential
@@ -365,23 +619,63 @@ struct wps_context {
         * cb_ctx: Higher layer context data for callbacks
         */
        void *cb_ctx;
+
+       struct upnp_wps_device_sm *wps_upnp;
+
+       /* Pending messages from UPnP PutWLANResponse */
+       struct upnp_pending_message *upnp_msgs;
 };
 
+struct oob_device_data {
+       char *device_name;
+       char *device_path;
+       void * (*init_func)(struct wps_context *, struct oob_device_data *,
+                           int);
+       struct wpabuf * (*read_func)(void *);
+       int (*write_func)(void *, struct wpabuf *);
+       void (*deinit_func)(void *);
+};
+
+struct oob_nfc_device_data {
+       int (*init_func)(char *);
+       void * (*read_func)(size_t *);
+       int (*write_func)(void *, size_t);
+       void (*deinit_func)(void);
+};
 
 struct wps_registrar *
 wps_registrar_init(struct wps_context *wps,
                   const struct wps_registrar_config *cfg);
 void wps_registrar_deinit(struct wps_registrar *reg);
 int wps_registrar_add_pin(struct wps_registrar *reg, const u8 *uuid,
-                         const u8 *pin, size_t pin_len);
+                         const u8 *pin, size_t pin_len, int timeout);
 int wps_registrar_invalidate_pin(struct wps_registrar *reg, const u8 *uuid);
 int wps_registrar_unlock_pin(struct wps_registrar *reg, const u8 *uuid);
 int wps_registrar_button_pushed(struct wps_registrar *reg);
 void wps_registrar_probe_req_rx(struct wps_registrar *reg, const u8 *addr,
                                const struct wpabuf *wps_data);
+int wps_registrar_update_ie(struct wps_registrar *reg);
+int wps_registrar_set_selected_registrar(struct wps_registrar *reg,
+                                        const struct wpabuf *msg);
+int wps_registrar_get_info(struct wps_registrar *reg, const u8 *addr,
+                          char *buf, size_t buflen);
 
 unsigned int wps_pin_checksum(unsigned int pin);
 unsigned int wps_pin_valid(unsigned int pin);
 unsigned int wps_generate_pin(void);
+void wps_free_pending_msgs(struct upnp_pending_message *msgs);
+
+struct oob_device_data * wps_get_oob_device(char *device_type);
+struct oob_nfc_device_data * wps_get_oob_nfc_device(char *device_name);
+int wps_get_oob_method(char *method);
+int wps_process_oob(struct wps_context *wps, struct oob_device_data *oob_dev,
+                   int registrar);
+int wps_attr_text(struct wpabuf *data, char *buf, char *end);
+
+struct wps_er * wps_er_init(struct wps_context *wps, const char *ifname);
+void wps_er_deinit(struct wps_er *er);
+void wps_er_set_sel_reg(struct wps_er *er, int sel_reg, u16 dev_passwd_id,
+                       u16 sel_reg_config_methods);
+int wps_er_pbc(struct wps_er *er, const u8 *uuid);
 
 #endif /* WPS_H */