]> granicus.if.org Git - esp-idf/commitdiff
1. Add wps event processing.
authorXia Xiao Tian <xxt@201608-4.(none)>
Wed, 9 Nov 2016 09:27:12 +0000 (17:27 +0800)
committerXia Xiao Tian <xxt@201608-4.(none)>
Wed, 9 Nov 2016 09:27:12 +0000 (17:27 +0800)
2. Change wps API return type and value.

components/esp32/event_default_handlers.c
components/esp32/include/esp_event.h
components/esp32/include/esp_wps.h

index a2bb3ccea3e9837a8cce2566a1df3df1609f3bd8..497c4371635e529b0ad6574b5c458bdf15331e0b 100644 (file)
@@ -67,6 +67,10 @@ static system_event_handle_t g_system_event_handle_table[] = {
     {SYSTEM_EVENT_STA_DISCONNECTED,    system_event_sta_disconnected_handle_default},
     {SYSTEM_EVENT_STA_AUTHMODE_CHANGE, NULL},
     {SYSTEM_EVENT_STA_GOT_IP,          system_event_sta_got_ip_default},
+    {SYSTEM_EVENT_STA_WPS_ER_SUCCESS,  NULL},
+    {SYSTEM_EVENT_STA_WPS_ER_FAILED,   NULL},
+    {SYSTEM_EVENT_STA_WPS_ER_TIMEOUT,  NULL},
+    {SYSTEM_EVENT_STA_WPS_ER_PIN,      NULL},
     {SYSTEM_EVENT_AP_START,            system_event_ap_start_handle_default},
     {SYSTEM_EVENT_AP_STOP,             system_event_ap_stop_handle_default},
     {SYSTEM_EVENT_AP_STACONNECTED,     NULL},
@@ -221,6 +225,22 @@ static esp_err_t esp_system_event_debug(system_event_t *event)
             IP2STR(&got_ip->ip_info.gw));
         break;
     }
+    case SYSTEM_EVENT_STA_WPS_ER_SUCCESS: {
+        ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_SUCCESS");
+        break;
+    }
+    case SYSTEM_EVENT_STA_WPS_ER_FAILED: {
+        ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_FAILED");
+        break;
+    }
+    case SYSTEM_EVENT_STA_WPS_ER_TIMEOUT: {
+        ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_TIMEOUT");
+        break;
+    }
+    case SYSTEM_EVENT_STA_WPS_ER_PIN: {
+        ESP_LOGD(TAG, "SYSTEM_EVENT_STA_WPS_ER_PIN");
+        break;
+    }
     case SYSTEM_EVENT_AP_START: {
         ESP_LOGD(TAG, "SYSTEM_EVENT_AP_START");
         break;
index 0ca4ca90ba84d62e035517e6d5d45a01f68cdb1b..481c5effd5ede511c5a204f987a7782d5cfd056d 100644 (file)
@@ -35,6 +35,10 @@ typedef enum {
     SYSTEM_EVENT_STA_DISCONNECTED,         /**< ESP32 station disconnected from AP */
     SYSTEM_EVENT_STA_AUTHMODE_CHANGE,      /**< the auth mode of AP connected by ESP32 station changed */
     SYSTEM_EVENT_STA_GOT_IP,               /**< ESP32 station got IP from connected AP */
+    SYSTEM_EVENT_STA_WPS_ER_SUCCESS,       /**< ESP32 station wps succeeds in enrollee mode */
+    SYSTEM_EVENT_STA_WPS_ER_FAILED,        /**< ESP32 station wps fails in enrollee mode */
+    SYSTEM_EVENT_STA_WPS_ER_TIMEOUT,       /**< ESP32 station wps timeout in enrollee mode */
+    SYSTEM_EVENT_STA_WPS_ER_PIN,           /**< ESP32 station wps pin code in enrollee mode */
     SYSTEM_EVENT_AP_START,                 /**< ESP32 soft-AP start */
     SYSTEM_EVENT_AP_STOP,                  /**< ESP32 soft-AP stop */
     SYSTEM_EVENT_AP_STACONNECTED,          /**< a station connected to ESP32 soft-AP */
@@ -73,6 +77,10 @@ typedef struct {
     tcpip_adapter_ip_info_t ip_info;
 } system_event_sta_got_ip_t;
 
+typedef struct {
+    uint8_t pin_code;         /**< PIN code of station in enrollee mode */
+}system_event_sta_wps_er_pin_t;
+
 typedef struct {
     uint8_t mac[6];           /**< MAC address of the station connected to ESP32 soft-AP */
     uint8_t aid;              /**< the aid that ESP32 soft-AP gives to the station connected to  */
@@ -94,6 +102,7 @@ typedef union {
     system_event_sta_scan_done_t               scan_done;          /**< ESP32 station scan (APs) done */
     system_event_sta_authmode_change_t         auth_change;        /**< the auth mode of AP ESP32 station connected to changed */
     system_event_sta_got_ip_t                  got_ip;             /**< ESP32 station got IP */
+    system_event_sta_wps_er_pin_t              sta_er_pin;
     system_event_ap_staconnected_t             sta_connected;      /**< a station connected to ESP32 soft-AP */
     system_event_ap_stadisconnected_t          sta_disconnected;   /**< a station disconnected to ESP32 soft-AP */
     system_event_ap_probe_req_rx_t             ap_probereqrecved;  /**< ESP32 soft-AP receive probe request packet */
index 1588d36191d38242ef426620c869e7b7603fda8f..2ea7e194bbd9584b4ac67bf66c695234791d196b 100644 (file)
@@ -16,6 +16,7 @@
 #define __ESP_WPS_H__
 
 #include <stdbool.h>
+#include "esp_err.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -40,43 +41,43 @@ extern "C" {
   * @{
   */
 
+#define ESP_ERR_WIFI_REGISTRAR   (ESP_ERR_WIFI_BASE + 51)  /*!< WPS registrar is not supported */
+#define ESP_ERR_WIFI_WPS_TYPE    (ESP_ERR_WIFI_BASE + 52)  /*!< WPS type error */
+#define ESP_ERR_WIFI_WPS_SM      (ESP_ERR_WIFI_BASE + 53)  /*!< WPS state machine is not initialized */
+
 typedef enum wps_type {
     WPS_TYPE_DISABLE = 0,
     WPS_TYPE_PBC,
     WPS_TYPE_PIN,
-    WPS_TYPE_DISPLAY,
     WPS_TYPE_MAX,
-} WPS_TYPE_t;
-
-enum wps_cb_status {
-    WPS_CB_ST_SUCCESS = 0,     /**< WPS succeed */
-    WPS_CB_ST_FAILED,          /**< WPS fail */
-    WPS_CB_ST_TIMEOUT,         /**< WPS timeout, fail */
-    WPS_CB_ST_WEP,             /**< WPS failed because that WEP is not supported */
-    WPS_CB_ST_SCAN_ERR,        /**< can not find the target WPS AP */
-};
+} wps_type_t;
 
 /**
   * @brief     Enable Wi-Fi WPS function.
   *
   * @attention WPS can only be used when ESP32 station is enabled.
   *
-  * @param     WPS_TYPE_t wps_type : WPS type, so far only WPS_TYPE_PBC and WPS_TYPE_PIN is supported
+  * @param     wps_type_t wps_type : WPS type, so far only WPS_TYPE_PBC and WPS_TYPE_PIN is supported
   *
-  * @return    true  : succeed
-  * @return    false : fail
+  * @return    
+  *          - ESP_OK : succeed
+  *          - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
+  *          - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
+  *          - ESP_ERR_WIFI_WPS_SM : wps state machine is not initialized
+  *          - ESP_ERR_WIFI_FAIL : wps initialization fails
   */
-bool esp_wifi_wps_enable(WPS_TYPE_t wps_type);
+esp_err_t esp_wifi_wps_enable(wps_type_t wps_type);
 
 /**
   * @brief  Disable Wi-Fi WPS function and release resource it taken.
   *
   * @param  null
   *
-  * @return true  : succeed
-  * @return false : fail
+  * @return    
+  *          - ESP_OK : succeed
+  *          - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
   */
-bool esp_wifi_wps_disable(void);
+esp_err_t esp_wifi_wps_disable(void);
 
 /**
   * @brief     WPS starts to work.
@@ -85,36 +86,14 @@ bool esp_wifi_wps_disable(void);
   *
   * @param     null
   *
-  * @return    true  : WPS starts to work successfully, but does not mean WPS succeed.
-  * @return    false : fail
-  */
-bool esp_wifi_wps_start(void);
-
-/**
-  * @brief  WPS callback.
-  *
-  * @param  int status : status of WPS, enum wps_cb_status.
-  *    -  If parameter status == WPS_CB_ST_SUCCESS in WPS callback, it means WPS got AP's
-  *       information, user can call wifi_wps_disable to disable WPS and release resource,
-  *       then call wifi_station_connect to connect to target AP.
-  *    -  Otherwise, it means that WPS fail, user can create a timer to retry WPS by
-  *       wifi_wps_start after a while, or call wifi_wps_disable to disable WPS and release resource.
-  *
-  * @return null
-  */
-typedef void (*wps_st_cb_t)(int status);
-
-/**
-  * @brief     Set WPS callback.
-  *
-  * @attention WPS can only be used when ESP32 station is enabled.
-  *
-  * @param     wps_st_cb_t cb : callback.
-  *
-  * @return    true  : WPS starts to work successfully, but does not mean WPS succeed.
-  * @return    false : fail
+  * @return    
+  *          - ESP_OK : succeed
+  *          - ESP_ERR_WIFI_WPS_TYPE : wps type is invalid
+  *          - ESP_ERR_WIFI_WPS_MODE : wifi is not in station mode or sniffer mode is on
+  *          - ESP_ERR_WIFI_WPS_SM : wps state machine is not initialized
+  *          - ESP_ERR_WIFI_FAIL : wps initialization fails
   */
-bool esp_wifi_set_wps_cb(wps_st_cb_t cb);
+esp_err_t esp_wifi_wps_start(void);
 
 /**
   * @}