Merge branch 'feature/refactor_wifi_apis' into 'refactor'

feat(wifi): Refactor wifi APIs according to IDF

See merge request sdk/ESP8266_RTOS_SDK!235
This commit is contained in:
Wu Jian Gang
2018-06-25 20:12:22 +08:00
28 changed files with 1834 additions and 1796 deletions

View File

@ -0,0 +1,182 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_EVENT_H__
#define __ESP_EVENT_H__
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_wifi_types.h"
#include "lwip/ip_addr.h"
#include "tcpip_adapter.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
SYSTEM_EVENT_WIFI_READY = 0, /**< ESP8266 WiFi ready */
SYSTEM_EVENT_SCAN_DONE, /**< ESP8266 finish scanning AP */
SYSTEM_EVENT_STA_START, /**< ESP8266 station start */
SYSTEM_EVENT_STA_STOP, /**< ESP8266 station stop */
SYSTEM_EVENT_STA_CONNECTED, /**< ESP8266 station connected to AP */
SYSTEM_EVENT_STA_DISCONNECTED, /**< ESP8266 station disconnected from AP */
SYSTEM_EVENT_STA_AUTHMODE_CHANGE, /**< the auth mode of AP connected by ESP8266 station changed */
SYSTEM_EVENT_STA_GOT_IP, /**< ESP8266 station got IP from connected AP */
SYSTEM_EVENT_STA_LOST_IP, /**< ESP8266 station lost IP and the IP is reset to 0 */
SYSTEM_EVENT_STA_WPS_ER_SUCCESS, /**< ESP8266 station wps succeeds in enrollee mode */
SYSTEM_EVENT_STA_WPS_ER_FAILED, /**< ESP8266 station wps fails in enrollee mode */
SYSTEM_EVENT_STA_WPS_ER_TIMEOUT, /**< ESP8266 station wps timeout in enrollee mode */
SYSTEM_EVENT_STA_WPS_ER_PIN, /**< ESP8266 station wps pin code in enrollee mode */
SYSTEM_EVENT_AP_START, /**< ESP8266 soft-AP start */
SYSTEM_EVENT_AP_STOP, /**< ESP8266 soft-AP stop */
SYSTEM_EVENT_AP_STACONNECTED, /**< a station connected to ESP8266 soft-AP */
SYSTEM_EVENT_AP_STADISCONNECTED, /**< a station disconnected from ESP8266 soft-AP */
SYSTEM_EVENT_AP_PROBEREQRECVED, /**< Receive probe request packet in soft-AP interface */
SYSTEM_EVENT_GOT_IP6, /**< ESP8266 station or ap or ethernet interface v6IP addr is preferred */
SYSTEM_EVENT_ETH_START, /**< ESP8266 ethernet start */
SYSTEM_EVENT_ETH_STOP, /**< ESP8266 ethernet stop */
SYSTEM_EVENT_ETH_CONNECTED, /**< ESP8266 ethernet phy link up */
SYSTEM_EVENT_ETH_DISCONNECTED, /**< ESP8266 ethernet phy link down */
SYSTEM_EVENT_ETH_GOT_IP, /**< ESP8266 ethernet got IP from connected AP */
SYSTEM_EVENT_MAX
} system_event_id_t;
/* add this macro define for compatible with old IDF version */
#ifndef SYSTEM_EVENT_AP_STA_GOT_IP6
#define SYSTEM_EVENT_AP_STA_GOT_IP6 SYSTEM_EVENT_GOT_IP6
#endif
typedef enum {
WPS_FAIL_REASON_NORMAL = 0, /**< ESP8266 WPS normal fail reason */
WPS_FAIL_REASON_RECV_M2D, /**< ESP8266 WPS receive M2D frame */
WPS_FAIL_REASON_MAX
}system_event_sta_wps_fail_reason_t;
typedef struct {
uint32_t status; /**< status of scanning APs */
uint8_t number;
uint8_t scan_id;
} system_event_sta_scan_done_t;
typedef struct {
uint8_t ssid[32]; /**< SSID of connected AP */
uint8_t ssid_len; /**< SSID length of connected AP */
uint8_t bssid[6]; /**< BSSID of connected AP*/
uint8_t channel; /**< channel of connected AP*/
wifi_auth_mode_t authmode;
} system_event_sta_connected_t;
typedef struct {
uint8_t ssid[32]; /**< SSID of disconnected AP */
uint8_t ssid_len; /**< SSID length of disconnected AP */
uint8_t bssid[6]; /**< BSSID of disconnected AP */
uint8_t reason; /**< reason of disconnection */
} system_event_sta_disconnected_t;
typedef struct {
wifi_auth_mode_t old_mode; /**< the old auth mode of AP */
wifi_auth_mode_t new_mode; /**< the new auth mode of AP */
} system_event_sta_authmode_change_t;
typedef struct {
tcpip_adapter_ip_info_t ip_info;
bool ip_changed;
} system_event_sta_got_ip_t;
typedef struct {
uint8_t pin_code[8]; /**< PIN code of station in enrollee mode */
} system_event_sta_wps_er_pin_t;
typedef struct {
tcpip_adapter_if_t if_index;
tcpip_adapter_ip6_info_t ip6_info;
} system_event_got_ip6_t;
typedef struct {
uint8_t mac[6]; /**< MAC address of the station connected to ESP8266 soft-AP */
uint8_t aid; /**< the aid that ESP8266 soft-AP gives to the station connected to */
} system_event_ap_staconnected_t;
typedef struct {
uint8_t mac[6]; /**< MAC address of the station disconnects to ESP8266 soft-AP */
uint8_t aid; /**< the aid that ESP8266 soft-AP gave to the station disconnects to */
} system_event_ap_stadisconnected_t;
typedef struct {
int rssi; /**< Received probe request signal strength */
uint8_t mac[6]; /**< MAC address of the station which send probe request */
} system_event_ap_probe_req_rx_t;
typedef union {
system_event_sta_connected_t connected; /**< ESP8266 station connected to AP */
system_event_sta_disconnected_t disconnected; /**< ESP8266 station disconnected to AP */
system_event_sta_scan_done_t scan_done; /**< ESP8266 station scan (APs) done */
system_event_sta_authmode_change_t auth_change; /**< the auth mode of AP ESP8266 station connected to changed */
system_event_sta_got_ip_t got_ip; /**< ESP8266 station got IP, first time got IP or when IP is changed */
system_event_sta_wps_er_pin_t sta_er_pin; /**< ESP8266 station WPS enrollee mode PIN code received */
system_event_sta_wps_fail_reason_t sta_er_fail_reason;/**< ESP8266 station WPS enrollee mode failed reason code received */
system_event_ap_staconnected_t sta_connected; /**< a station connected to ESP8266 soft-AP */
system_event_ap_stadisconnected_t sta_disconnected; /**< a station disconnected to ESP8266 soft-AP */
system_event_ap_probe_req_rx_t ap_probereqrecved; /**< ESP8266 soft-AP receive probe request packet */
system_event_got_ip6_t got_ip6; /**< ESP8266 station or ap or ethernet ipv6 addr state change to preferred */
} system_event_info_t;
typedef struct {
system_event_id_t event_id; /**< event ID */
system_event_info_t event_info; /**< event information */
} system_event_t;
typedef esp_err_t (*system_event_handler_t)(system_event_t *event);
/**
* @brief Send a event to event task
*
* @attention 1. Other task/modules, such as the TCPIP module, can call this API to send an event to event task
*
* @param system_event_t * event : event
*
* @return ESP_OK : succeed
* @return others : fail
*/
esp_err_t esp_event_send(system_event_t *event);
/**
* @brief Default event handler for system events
*
* This function performs default handling of system events.
* When using esp_event_loop APIs, it is called automatically before invoking the user-provided
* callback function.
*
* Applications which implement a custom event loop must call this function
* as part of event processing.
*
* @param event pointer to event to be handled
* @return ESP_OK if an event was handled successfully
*/
esp_err_t esp_event_process_default(system_event_t *event);
/**
* @brief Install default event handlers for Wi-Fi interfaces (station and AP)
*
*/
void esp_event_set_default_wifi_handlers();
#ifdef __cplusplus
}
#endif
#endif /* __ESP_EVENT_H__ */

View File

@ -0,0 +1,81 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_EVENT_LOOP_H__
#define __ESP_EVENT_LOOP_H__
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_event.h"
#include "freertos/FreeRTOS.h"
#include "freertos/queue.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Application specified event callback function
*
* @param void *ctx : reserved for user
* @param system_event_t *event : event type defined in this file
*
* @return ESP_OK : succeed
* @return others : fail
*/
typedef esp_err_t (*system_event_cb_t)(void *ctx, system_event_t *event);
/**
* @brief Initialize event loop
* Create the event handler and task
*
* @param system_event_cb_t cb : application specified event callback, it can be modified by call esp_event_set_cb
* @param void *ctx : reserved for user
*
* @return ESP_OK : succeed
* @return others : fail
*/
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx);
/**
* @brief Set application specified event callback function
*
* @attention 1. If cb is NULL, means application don't need to handle
* If cb is not NULL, it will be call when an event is received, after the default event callback is completed
*
* @param system_event_cb_t cb : callback
* @param void *ctx : reserved for user
*
* @return system_event_cb_t : old callback
*/
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx);
/**
* @brief Get the queue used by event loop
*
* @attention : currently this API is used to initialize "q" parameter
* of wifi_init structure.
*
* @return QueueHandle_t : event queue handle
*/
QueueHandle_t esp_event_loop_get_queue(void);
#ifdef __cplusplus
}
#endif
#endif /* __ESP_EVENT_LOOP_H__ */

View File

@ -0,0 +1,36 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_INTERFACE_H__
#define __ESP_INTERFACE_H__
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
ESP_IF_WIFI_STA = 0, /**< ESP8266 station interface */
ESP_IF_WIFI_AP, /**< ESP8266 soft-AP interface */
ESP_IF_MAX
} esp_interface_t;
#ifdef __cplusplus
}
#endif
#endif /* __ESP_INTERFACE_TYPES_H__ */

View File

@ -1,294 +0,0 @@
/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_SOFTAP_H__
#define __ESP_SOFTAP_H__
#include <stdint.h>
#include <stdbool.h>
#include <sys/queue.h>
#include "esp_wifi.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup WiFi_APIs WiFi Related APIs
* @brief WiFi APIs
*/
/** @addtogroup WiFi_APIs
* @{
*/
/** \defgroup SoftAP_APIs SoftAP APIs
* @brief ESP8266 Soft-AP APIs
* @attention To call APIs related to ESP8266 soft-AP has to enable soft-AP mode first (wifi_set_opmode)
*/
/** @addtogroup SoftAP_APIs
* @{
*/
struct softap_config {
uint8_t ssid[32]; /**< SSID of ESP8266 soft-AP */
uint8_t password[64]; /**< Password of ESP8266 soft-AP */
uint8_t ssid_len; /**< Length of SSID. If softap_config.ssid_len==0, check the SSID until there is a termination character; otherwise, set the SSID length according to softap_config.ssid_len. */
uint8_t channel; /**< Channel of ESP8266 soft-AP */
AUTH_MODE authmode; /**< Auth mode of ESP8266 soft-AP. Do not support AUTH_WEP in soft-AP mode */
uint8_t ssid_hidden; /**< Broadcast SSID or not, default 0, broadcast the SSID */
uint8_t max_connection; /**< Max number of stations allowed to connect in, default 4, max 4 */
uint16_t beacon_interval; /**< Beacon interval, 100 ~ 60000 ms, default 100 */
};
struct station_info {
STAILQ_ENTRY(station_info) next; /**< Information of next AP */
uint8_t bssid[6]; /**< BSSID of AP */
struct ip4_addr ip; /**< IP address of AP */
};
/**
* @brief Get the current configuration of the ESP8266 WiFi soft-AP
*
* @param struct softap_config *config : ESP8266 soft-AP configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_get_config(struct softap_config *config);
/**
* @brief Get the configuration of the ESP8266 WiFi soft-AP saved in the flash
*
* @param struct softap_config *config : ESP8266 soft-AP configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_get_config_default(struct softap_config *config);
/**
* @brief Set the configuration of the WiFi soft-AP and save it to the Flash.
*
* @attention 1. This configuration will be saved in flash system parameter area if changed
* @attention 2. The ESP8266 is limited to only one channel, so when in the soft-AP+station mode,
* the soft-AP will adjust its channel automatically to be the same as
* the channel of the ESP8266 station.
*
* @param struct softap_config *config : ESP8266 soft-AP configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_set_config(struct softap_config *config);
/**
* @brief Set the configuration of the WiFi soft-AP; the configuration will
* not be saved to the Flash.
*
* @attention The ESP8266 is limited to only one channel, so when in the soft-AP+station mode,
* the soft-AP will adjust its channel automatically to be the same as
* the channel of the ESP8266 station.
*
* @param struct softap_config *config : ESP8266 soft-AP configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_set_config_current(struct softap_config *config);
/**
* @brief Get the number of stations connected to the ESP8266 soft-AP.
*
* @attention The ESP8266 is limited to only one channel, so when in the soft-AP+station mode,
* the soft-AP will adjust its channel automatically to be the same as
* the channel of the ESP8266 station.
*
* @param null
*
* @return the number of stations connected to the ESP8266 soft-AP
*/
uint8_t wifi_softap_get_station_num(void);
/**
* @brief Get the information of stations connected to the ESP8266 soft-AP,
* including MAC and IP.
*
* @attention wifi_softap_get_station_info depends on DHCP, it can only
* be used when DHCP is enabled, so it can not get the static IP.
*
* @param null
*
* @return struct station_info* : station information structure
*/
struct station_info *wifi_softap_get_station_info(void);
/**
* @brief Free the space occupied by station_info when wifi_softap_get_station_info is called.
*
* @attention The ESP8266 is limited to only one channel, so when in the soft-AP+station mode,
* the soft-AP will adjust its channel automatically to be the same as
* the channel of the ESP8266 station.
*
* @param null
*
* @return null
*/
void wifi_softap_free_station_info(void);
/**
* @brief Enable the ESP8266 soft-AP DHCP server.
*
* @attention 1. The DHCP is enabled by default.
* @attention 2. The DHCP and the static IP related API (wifi_set_ip_info) influence
* each other, if the DHCP is enabled, the static IP will be disabled;
* if the static IP is enabled, the DHCP will be disabled.
* It depends on the latest configuration.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_dhcps_start(void);
/**
* @brief Disable the ESP8266 soft-AP DHCP server. The DHCP is enabled by default.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_dhcps_stop(void);
/**
* @brief Get the ESP8266 soft-AP DHCP server status.
*
* @param null
*
* @return enum dhcp_status
*/
enum dhcp_status wifi_softap_dhcps_status(void);
/**
* @brief Query the IP range that can be got from the ESP8266 soft-AP DHCP server.
*
* @attention This API can only be called during ESP8266 soft-AP DHCP server enabled.
*
* @param struct dhcps_lease *please : IP range of the ESP8266 soft-AP DHCP server.
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_get_dhcps_lease(struct dhcps_lease *please);
/**
* @brief Set the IP range of the ESP8266 soft-AP DHCP server.
*
* @attention 1. The IP range should be in the same sub-net with the ESP8266
* soft-AP IP address.
* @attention 2. This API should only be called when the DHCP server is disabled
* (wifi_softap_dhcps_stop).
* @attention 3. This configuration will only take effect the next time when the
* DHCP server is enabled (wifi_softap_dhcps_start).
* - If the DHCP server is disabled again, this API should be called to set the IP range.
* - Otherwise, when the DHCP server is enabled later, the default IP range will be used.
*
* @param struct dhcps_lease *please : IP range of the ESP8266 soft-AP DHCP server.
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_set_dhcps_lease(struct dhcps_lease *please);
/**
* @brief Get ESP8266 soft-AP DHCP server lease time.
*
* @attention This API can only be called during ESP8266 soft-AP DHCP server enabled.
*
* @param null
*
* @return lease time, uint: minute.
*/
uint32_t wifi_softap_get_dhcps_lease_time(void);
/**
* @brief Set ESP8266 soft-AP DHCP server lease time, default is 120 minutes.
*
* @attention This API can only be called during ESP8266 soft-AP DHCP server enabled.
*
* @param uint32 minute : lease time, uint: minute, range:[1, 2880].
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_set_dhcps_lease_time(uint32_t minute);
/**
* @brief Reset ESP8266 soft-AP DHCP server lease time which is 120 minutes by default.
*
* @attention This API can only be called during ESP8266 soft-AP DHCP server enabled.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_reset_dhcps_lease_time(void);
/**
* @brief Set the ESP8266 soft-AP DHCP server option.
*
* Example:
* <pre>
* uint8 mode = 0;
* wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &mode);
* </pre>
*
* @param uint8 level : OFFER_ROUTER, set the router option.
* @param void* optarg :
* - bit0, 0 disable the router information;
* - bit0, 1 enable the router information.
*
* @return true : succeed
* @return false : fail
*/
bool wifi_softap_set_dhcps_offer_option(uint8_t level, void *optarg);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,443 +0,0 @@
/*
* ESPRSSIF MIT License
*
* Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
*
* Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP8266 only, in which case,
* it is free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or
* substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
#ifndef __ESP_STA_H__
#define __ESP_STA_H__
#include <stdbool.h>
#include <stdint.h>
#include <sys/queue.h>
#include "esp_wifi.h"
#ifdef __cplusplus
extern "C" {
#endif
/** \defgroup WiFi_APIs WiFi Related APIs
* @brief WiFi APIs
*/
/** @addtogroup WiFi_APIs
* @{
*/
/** \defgroup Station_APIs Station APIs
* @brief ESP8266 station APIs
* @attention To call APIs related to ESP8266 station has to enable station mode
* first (wifi_set_opmode)
*/
/** @addtogroup Station_APIs
* @{
*/
struct station_config {
uint8_t ssid[32]; /**< SSID of target AP*/
uint8_t password[64]; /**< password of target AP*/
uint8_t bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
uint8_t bssid[6]; /**< MAC address of target AP*/
};
/**
* @brief Get the current configuration of the ESP8266 WiFi station.
*
* @param struct station_config *config : ESP8266 station configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_get_config(struct station_config *config);
/**
* @brief Get the configuration parameters saved in the Flash of the ESP8266 WiFi station.
*
* @param struct station_config *config : ESP8266 station configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_get_config_default(struct station_config *config);
/**
* @brief Set the configuration of the ESP8266 station and save it to the Flash.
*
* @attention 1. This API can be called only when the ESP8266 station is enabled.
* @attention 2. If wifi_station_set_config is called in user_init , there is no
* need to call wifi_station_connect.
* The ESP8266 station will automatically connect to the AP (router)
* after the system initialization. Otherwise, wifi_station_connect should be called.
* @attention 3. Generally, station_config.bssid_set needs to be 0; and it needs
* to be 1 only when users need to check the MAC address of the AP.
* @attention 4. This configuration will be saved in the Flash system parameter area if changed.
*
* @param struct station_config *config : ESP8266 station configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_set_config(struct station_config *config);
/**
* @brief Set the configuration of the ESP8266 station. And the configuration
* will not be saved to the Flash.
*
* @attention 1. This API can be called only when the ESP8266 station is enabled.
* @attention 2. If wifi_station_set_config_current is called in user_init , there
* is no need to call wifi_station_connect.
* The ESP8266 station will automatically connect to the AP (router)
* after the system initialization. Otherwise, wifi_station_connect
* should be called.
* @attention 3. Generally, station_config.bssid_set needs to be 0; and it needs
* to be 1 only when users need to check the MAC address of the AP.
*
* @param struct station_config *config : ESP8266 station configuration
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_set_config_current(struct station_config *config);
/**
* @brief Connect the ESP8266 WiFi station to the AP.
*
* @attention 1. This API should be called when the ESP8266 station is enabled,
* and the system initialization is completed. Do not call this API in user_init.
* @attention 2. If the ESP8266 is connected to an AP, call wifi_station_disconnect to disconnect.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_connect(void);
/**
* @brief Disconnect the ESP8266 WiFi station from the AP.
*
* @attention This API should be called when the ESP8266 station is enabled,
* and the system initialization is completed. Do not call this API in user_init.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_disconnect(void);
typedef enum {
WIFI_SCAN_TYPE_ACTIVE = 0, /**< active scan */
WIFI_SCAN_TYPE_PASSIVE, /**< passive scan */
} wifi_scan_type_t;
/** @brief Range of active scan times per channel */
typedef struct {
uint32_t min; /**< minimum active scan time per channel, units: millisecond */
uint32_t max; /**< maximum active scan time per channel, units: millisecond, values above 1500ms may
cause station to disconnect from AP and are not recommended. */
} wifi_active_scan_time_t;
/** @brief Aggregate of active & passive scan time per channel */
typedef union {
wifi_active_scan_time_t active; /**< active scan time per channel, units: millisecond. */
uint32_t passive; /**< passive scan time per channel, units: millisecond, values above 1500ms may
cause station to disconnect from AP and are not recommended. */
} wifi_scan_time_t;
struct scan_config {
uint8_t *ssid; /**< SSID of AP */
uint8_t *bssid; /**< MAC address of AP */
uint8_t channel; /**< channel, scan the specific channel */
uint8_t show_hidden; /**< enable to scan AP whose SSID is hidden */
wifi_scan_type_t scan_type; /**< scan type, active or passive */
wifi_scan_time_t scan_time; /**< scan time per channel */
};
typedef enum {
CIPHER_NONE = 0, /**< the cipher type is none */
CIPHER_WEP40, /**< the cipher type is WEP40 */
CIPHER_WEP104, /**< the cipher type is WEP104 */
CIPHER_TKIP, /**< the cipher type is TKIP */
CIPHER_CCMP, /**< the cipher type is CCMP */
CIPHER_TKIP_CCMP, /**< the cipher type is TKIP and CCMP */
CIPHER_UNKNOWN, /**< the cipher type is unknown */
} CIPHER_TYPE;
struct bss_info {
STAILQ_ENTRY(bss_info) next; /**< information of next AP */
uint8_t bssid[6]; /**< MAC address of AP */
uint8_t ssid[32]; /**< SSID of AP */
uint8_t ssid_len; /**< SSID length */
uint8_t channel; /**< channel of AP */
int8_t rssi; /**< single strength of AP */
AUTH_MODE authmode; /**< authmode of AP */
uint8_t is_hidden; /**< SSID of current AP is hidden or not. */
int16_t freq_offset; /**< frequency offset */
int16_t freqcal_val;
uint8_t *esp_mesh_ie;
CIPHER_TYPE pairwise_cipher; /**< pairwise cipher of AP */
CIPHER_TYPE group_cipher; /**< group cipher of AP */
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
uint32_t wps:1; /**< bit: 3 flag to identify if WPS is supported or not */
uint32_t reserved:28; /**< bit: 4..31 reserved */
};
typedef enum {
OK = 0,
FAIL,
PENDING,
BUSY,
CANCEL,
} STATUS;
/**
* @brief Callback function for wifi_station_scan.
*
* @param void *arg : information of APs that are found; save them as linked list;
* refer to struct bss_info
* @param STATUS status : status of scanning
*
* @return null
*/
typedef void (* scan_done_cb_t)(void *arg, STATUS status);
/**
* @brief Scan all available APs.
*
* @attention This API should be called when the ESP8266 station is enabled, and
* the system initialization is completed. Do not call this API in user_init.
*
* @param struct scan_config *config : configuration of scanning
* @param struct scan_done_cb_t cb : callback of scanning
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb);
/**
* @brief Check if the ESP8266 station will connect to the recorded AP automatically
* when the power is on.
*
* @param null
*
* @return true : connect to the AP automatically
* @return false : not connect to the AP automatically
*/
bool wifi_station_get_auto_connect(void);
/**
* @brief Set whether the ESP8266 station will connect to the recorded AP
* automatically when the power is on. It will do so by default.
*
* @attention 1. If this API is called in user_init, it is effective immediately
* after the power is on. If it is called in other places, it will
* be effective the next time when the power is on.
* @attention 2. This configuration will be saved in Flash system parameter area if changed.
*
* @param bool set : If it will automatically connect to the AP when the power is on
* - true : it will connect automatically
* - false: it will not connect automatically
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_set_auto_connect(bool set);
/**
* @brief Check whether the ESP8266 station will reconnect to the AP after disconnection.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_get_reconnect_policy(void);
/**
* @brief Set whether the ESP8266 station will reconnect to the AP after disconnection.
* It will do so by default.
*
* @attention If users want to call this API, it is suggested that users call this API in user_init.
*
* @param bool set : if it's true, it will enable reconnection; if it's false,
* it will disable reconnection.
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_set_reconnect_policy(bool set);
typedef enum {
STATION_IDLE = 0, /**< ESP8266 station idle */
STATION_CONNECTING, /**< ESP8266 station is connecting to AP*/
STATION_WRONG_PASSWORD, /**< the password is wrong*/
STATION_NO_AP_FOUND, /**< ESP8266 station can not find the target AP*/
STATION_CONNECT_FAIL, /**< ESP8266 station fail to connect to AP*/
STATION_GOT_IP /**< ESP8266 station got IP address from AP*/
} STATION_STATUS;
/**
* @brief Get the connection status of the ESP8266 WiFi station.
*
* @param null
*
* @return the status of connection
*/
STATION_STATUS wifi_station_get_connect_status(void);
/**
* @brief Get the information of APs (5 at most) recorded by ESP8266 station.
*
* @param struct station_config config[] : information of the APs, the array size should be 5.
*
* @return The number of APs recorded.
*/
uint8_t wifi_station_get_current_ap_id(void);
/**
* @brief Switch the ESP8266 station connection to a recorded AP.
*
* @param uint8_t new_ap_id : AP's record id, start counting from 0.
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_ap_change(uint8_t current_ap_id);
/**
* @brief Set the number of APs that can be recorded in the ESP8266 station.
* When the ESP8266 station is connected to an AP, the SSID and password
* of the AP will be recorded.
*
* @attention This configuration will be saved in the Flash system parameter area if changed.
*
* @param uint8_t ap_number : the number of APs that can be recorded (MAX: 5)
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_ap_number_set(uint8_t ap_number);
/**
* @brief Get the information of APs (5 at most) recorded by ESP8266 station.
*
* Example:
* <pre>
* struct station_config config[5];
* nt i = wifi_station_get_ap_info(config);
* </pre>
*
* @param struct station_config config[] : information of the APs, the array size should be 5.
*
* @return The number of APs recorded.
*/
uint8_t wifi_station_get_ap_info(struct station_config config[]);
/**
* @brief Get rssi of the AP which ESP8266 station connected to.
*
* @param null
*
* @return 31 : fail, invalid value.
* @return others : succeed, value of rssi. In general, rssi value < 10
*/
int8_t wifi_station_get_rssi(void);
/**
* @brief Enable the ESP8266 station DHCP client.
*
* @attention 1. The DHCP is enabled by default.
* @attention 2. The DHCP and the static IP API ((wifi_set_ip_info)) influence each other,
* and if the DHCP is enabled, the static IP will be disabled;
* if the static IP is enabled, the DHCP will be disabled.
* It depends on the latest configuration.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_dhcpc_start(void);
/**
* @brief Disable the ESP8266 station DHCP client.
*
* @attention 1. The DHCP is enabled by default.
* @attention 2. The DHCP and the static IP API ((wifi_set_ip_info)) influence each other,
* and if the DHCP is enabled, the static IP will be disabled;
* if the static IP is enabled, the DHCP will be disabled.
* It depends on the latest configuration.
*
* @param null
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_dhcpc_stop(void);
/**
* @brief Get the ESP8266 station DHCP client status.
*
* @param null
*
* @return enum dhcp_status
*/
enum dhcp_status wifi_station_dhcpc_status(void);
/**
* @brief Set ESP8266 station DHCP hostname.
*
* @param char *name : hostname of ESP8266 station
*
* @return true : succeed
* @return false : fail
*/
bool wifi_station_set_hostname(char *name);
/**
* @brief Get ESP8266 station DHCP hostname.
*
* @param null
*
* @return the hostname of ESP8266 station
*/
char* wifi_station_get_hostname(void);
/**
* @}
*/
/**
* @}
*/
#ifdef __cplusplus
}
#endif
#endif

File diff suppressed because it is too large Load Diff

View File

@ -22,6 +22,9 @@
extern "C" {
#endif
#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000001
#define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF
#define OSI_FUNCS_TIME_BLOCKING 0xffffffff
#define OSI_QUEUE_SEND_FRONT 0
@ -33,6 +36,7 @@ extern "C" {
#define OSI_MALLOC_CAP_DMA (1 << 3)
typedef struct {
int32_t version;
uint32_t (*enter_critical)(void);
void (*exit_critical)(uint32_t tmp);
@ -87,6 +91,21 @@ typedef struct {
void (*srand)(uint32_t seed);
int32_t (*rand)(void);
int32_t (* nvs_set_i8)(uint32_t handle, const char* key, int8_t value);
int32_t (* nvs_get_i8)(uint32_t handle, const char* key, int8_t* out_value);
int32_t (* nvs_set_u8)(uint32_t handle, const char* key, uint8_t value);
int32_t (* nvs_get_u8)(uint32_t handle, const char* key, uint8_t* out_value);
int32_t (* nvs_set_u16)(uint32_t handle, const char* key, uint16_t value);
int32_t (* nvs_get_u16)(uint32_t handle, const char* key, uint16_t* out_value);
int32_t (* nvs_open)(const char* name, uint32_t open_mode, uint32_t *out_handle);
void (* nvs_close)(uint32_t handle);
int32_t (* nvs_commit)(uint32_t handle);
int32_t (* nvs_set_blob)(uint32_t handle, const char* key, const void* value, size_t length);
int32_t (* nvs_get_blob)(uint32_t handle, const char* key, void* out_value, size_t* length);
int32_t (* nvs_erase_key)(uint32_t handle, const char* key);
int32_t magic;
} wifi_osi_funcs_t;
#ifdef __cplusplus

View File

@ -0,0 +1,369 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef __ESP_WIFI_TYPES_H__
#define __ESP_WIFI_TYPES_H__
#include <stdint.h>
#include <stdbool.h>
#include "esp_err.h"
#include "esp_interface.h"
#include "queue.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
WIFI_MODE_NULL = 0, /**< null mode */
WIFI_MODE_STA, /**< WiFi station mode */
WIFI_MODE_AP, /**< WiFi soft-AP mode */
WIFI_MODE_APSTA, /**< WiFi station + soft-AP mode */
WIFI_MODE_MAX
} wifi_mode_t;
typedef esp_interface_t wifi_interface_t;
#define WIFI_IF_STA ESP_IF_WIFI_STA
#define WIFI_IF_AP ESP_IF_WIFI_AP
typedef enum {
WIFI_COUNTRY_POLICY_AUTO, /**< Country policy is auto, use the country info of AP to which the station is connected */
WIFI_COUNTRY_POLICY_MANUAL, /**< Country policy is manual, always use the configured country info */
} wifi_country_policy_t;
/** @brief Structure describing WiFi country-based regional restrictions. */
typedef struct {
char cc[3]; /**< country code string */
uint8_t schan; /**< start channel */
uint8_t nchan; /**< total channel number */
int8_t max_tx_power; /**< maximum tx power */
wifi_country_policy_t policy; /**< country policy */
} wifi_country_t;
typedef enum {
WIFI_AUTH_OPEN = 0, /**< authenticate mode : open */
WIFI_AUTH_WEP, /**< authenticate mode : WEP */
WIFI_AUTH_WPA_PSK, /**< authenticate mode : WPA_PSK */
WIFI_AUTH_WPA2_PSK, /**< authenticate mode : WPA2_PSK */
WIFI_AUTH_WPA_WPA2_PSK, /**< authenticate mode : WPA_WPA2_PSK */
WIFI_AUTH_WPA2_ENTERPRISE, /**< authenticate mode : WPA2_ENTERPRISE */
WIFI_AUTH_MAX
} wifi_auth_mode_t;
typedef enum {
WIFI_REASON_UNSPECIFIED = 1,
WIFI_REASON_AUTH_EXPIRE = 2,
WIFI_REASON_AUTH_LEAVE = 3,
WIFI_REASON_ASSOC_EXPIRE = 4,
WIFI_REASON_ASSOC_TOOMANY = 5,
WIFI_REASON_NOT_AUTHED = 6,
WIFI_REASON_NOT_ASSOCED = 7,
WIFI_REASON_ASSOC_LEAVE = 8,
WIFI_REASON_ASSOC_NOT_AUTHED = 9,
WIFI_REASON_DISASSOC_PWRCAP_BAD = 10,
WIFI_REASON_DISASSOC_SUPCHAN_BAD = 11,
WIFI_REASON_IE_INVALID = 13,
WIFI_REASON_MIC_FAILURE = 14,
WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
WIFI_REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
WIFI_REASON_IE_IN_4WAY_DIFFERS = 17,
WIFI_REASON_GROUP_CIPHER_INVALID = 18,
WIFI_REASON_PAIRWISE_CIPHER_INVALID = 19,
WIFI_REASON_AKMP_INVALID = 20,
WIFI_REASON_UNSUPP_RSN_IE_VERSION = 21,
WIFI_REASON_INVALID_RSN_IE_CAP = 22,
WIFI_REASON_802_1X_AUTH_FAILED = 23,
WIFI_REASON_CIPHER_SUITE_REJECTED = 24,
WIFI_REASON_BEACON_TIMEOUT = 200,
WIFI_REASON_NO_AP_FOUND = 201,
WIFI_REASON_AUTH_FAIL = 202,
WIFI_REASON_ASSOC_FAIL = 203,
WIFI_REASON_HANDSHAKE_TIMEOUT = 204,
} wifi_err_reason_t;
typedef enum {
WIFI_SECOND_CHAN_NONE = 0, /**< the channel width is HT20 */
WIFI_SECOND_CHAN_ABOVE, /**< the channel width is HT40 and the second channel is above the primary channel */
WIFI_SECOND_CHAN_BELOW, /**< the channel width is HT40 and the second channel is below the primary channel */
} wifi_second_chan_t;
typedef enum {
WIFI_SCAN_TYPE_ACTIVE = 0, /**< active scan */
WIFI_SCAN_TYPE_PASSIVE, /**< passive scan */
} wifi_scan_type_t;
/** @brief Range of active scan times per channel */
typedef struct {
uint32_t min; /**< minimum active scan time per channel, units: millisecond */
uint32_t max; /**< maximum active scan time per channel, units: millisecond, values above 1500ms may
cause station to disconnect from AP and are not recommended. */
} wifi_active_scan_time_t;
/** @brief Aggregate of active & passive scan time per channel */
typedef union {
wifi_active_scan_time_t active; /**< active scan time per channel, units: millisecond. */
uint32_t passive; /**< passive scan time per channel, units: millisecond, values above 1500ms may
cause station to disconnect from AP and are not recommended. */
} wifi_scan_time_t;
/** @brief Parameters for an SSID scan. */
typedef struct {
uint8_t *ssid; /**< SSID of AP */
uint8_t *bssid; /**< MAC address of AP */
uint8_t channel; /**< channel, scan the specific channel */
bool show_hidden; /**< enable to scan AP whose SSID is hidden */
wifi_scan_type_t scan_type; /**< scan type, active or passive */
wifi_scan_time_t scan_time; /**< scan time per channel */
} wifi_scan_config_t;
typedef enum {
WIFI_CIPHER_TYPE_NONE = 0, /**< the cipher type is none */
WIFI_CIPHER_TYPE_WEP40, /**< the cipher type is WEP40 */
WIFI_CIPHER_TYPE_WEP104, /**< the cipher type is WEP104 */
WIFI_CIPHER_TYPE_TKIP, /**< the cipher type is TKIP */
WIFI_CIPHER_TYPE_CCMP, /**< the cipher type is CCMP */
WIFI_CIPHER_TYPE_TKIP_CCMP, /**< the cipher type is TKIP and CCMP */
WIFI_CIPHER_TYPE_UNKNOWN, /**< the cipher type is unknown */
} wifi_cipher_type_t;
typedef enum {
WIFI_ANT_ANT0, /**< WiFi antenna 0 */
WIFI_ANT_ANT1, /**< WiFi antenna 1 */
WIFI_ANT_MAX, /**< Invalid WiFi antenna */
} wifi_ant_t;
/** @brief Description of an WiFi AP */
typedef struct {
uint8_t bssid[6]; /**< MAC address of AP */
uint8_t ssid[33]; /**< SSID of AP */
uint8_t primary; /**< channel of AP */
wifi_second_chan_t second; /**< secondary channel of AP */
int8_t rssi; /**< signal strength of AP */
wifi_auth_mode_t authmode; /**< authmode of AP */
wifi_cipher_type_t pairwise_cipher; /**< pairwise cipher of AP */
wifi_cipher_type_t group_cipher; /**< group cipher of AP */
wifi_ant_t ant; /**< antenna used to receive beacon from AP */
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */
uint32_t wps:1; /**< bit: 4 flag to identify if WPS is supported or not */
uint32_t reserved:27; /**< bit: 5..31 reserved */
wifi_country_t country; /**< country information of AP */
} wifi_ap_record_t;
typedef enum {
WIFI_FAST_SCAN = 0, /**< Do fast scan, scan will end after find SSID match AP */
WIFI_ALL_CHANNEL_SCAN, /**< All channel scan, scan will end after scan all the channel */
}wifi_scan_method_t;
typedef enum {
WIFI_CONNECT_AP_BY_SIGNAL = 0, /**< Sort match AP in scan list by RSSI */
WIFI_CONNECT_AP_BY_SECURITY, /**< Sort match AP in scan list by security mode */
}wifi_sort_method_t;
/** @brief Structure describing parameters for a WiFi fast scan */
typedef struct {
int8_t rssi; /**< The minimum rssi to accept in the fast scan mode */
wifi_auth_mode_t authmode; /**< The weakest authmode to accept in the fast scan mode */
}wifi_fast_scan_threshold_t;
typedef enum {
WIFI_PS_NONE, /**< No power save */
WIFI_PS_MIN_MODEM, /**< Minimum modem power saving. In this mode, station wakes up to receive beacon every DTIM period */
WIFI_PS_MAX_MODEM, /**< Maximum modem power saving. In this mode, interval to receive beacons is determined by the listen_interval parameter in wifi_sta_config_t */
} wifi_ps_type_t;
#define WIFI_PS_MODEM WIFI_PS_MIN_MODEM /**< @deprecated Use WIFI_PS_MIN_MODEM or WIFI_PS_MAX_MODEM instead */
#define WIFI_PROTOCOL_11B 1
#define WIFI_PROTOCOL_11G 2
#define WIFI_PROTOCOL_11N 4
#define WIFI_PROTOCOL_LR 8
typedef enum {
WIFI_BW_HT20 = 1, /* Bandwidth is HT20 */
WIFI_BW_HT40, /* Bandwidth is HT40 */
} wifi_bandwidth_t;
/** @brief Soft-AP configuration settings for the ESP8266 */
typedef struct {
uint8_t ssid[32]; /**< SSID of ESP8266 soft-AP */
uint8_t password[64]; /**< Password of ESP8266 soft-AP */
uint8_t ssid_len; /**< Length of SSID. If softap_config.ssid_len==0, check the SSID until there is a termination character; otherwise, set the SSID length according to softap_config.ssid_len. */
uint8_t channel; /**< Channel of ESP8266 soft-AP */
wifi_auth_mode_t authmode; /**< Auth mode of ESP8266 soft-AP. Do not support AUTH_WEP in soft-AP mode */
uint8_t ssid_hidden; /**< Broadcast SSID or not, default 0, broadcast the SSID */
uint8_t max_connection; /**< Max number of stations allowed to connect in, default 4, max 4 */
uint16_t beacon_interval; /**< Beacon interval, 100 ~ 60000 ms, default 100 ms */
} wifi_ap_config_t;
/** @brief STA configuration settings for the ESP8266 */
typedef struct {
uint8_t ssid[32]; /**< SSID of target AP*/
uint8_t password[64]; /**< password of target AP*/
wifi_scan_method_t scan_method; /**< do all channel scan or fast scan */
bool bssid_set; /**< whether set MAC address of target AP or not. Generally, station_config.bssid_set needs to be 0; and it needs to be 1 only when users need to check the MAC address of the AP.*/
uint8_t bssid[6]; /**< MAC address of target AP*/
uint8_t channel; /**< channel of target AP. Set to 1~13 to scan starting from the specified channel before connecting to AP. If the channel of AP is unknown, set it to 0.*/
uint16_t listen_interval; /**< Listen interval for ESP8266 station to receive beacon when WIFI_PS_MAX_MODEM is set. Units: AP beacon intervals. Defaults to 3 if set to 0. */
wifi_sort_method_t sort_method; /**< sort the connect AP in the list by rssi or security mode */
wifi_fast_scan_threshold_t threshold; /**< When scan_method is set to WIFI_FAST_SCAN, only APs which have an auth mode that is more secure than the selected auth mode and a signal stronger than the minimum RSSI will be used. */
} wifi_sta_config_t;
/** @brief Configuration data for ESP8266 AP or STA.
*
* The usage of this union (for ap or sta configuration) is determined by the accompanying
* interface argument passed to esp_wifi_set_config() or esp_wifi_get_config()
*
*/
typedef union {
wifi_ap_config_t ap; /**< configuration of AP */
wifi_sta_config_t sta; /**< configuration of STA */
} wifi_config_t;
/** @brief Description of STA associated with AP */
typedef struct {
uint8_t mac[6]; /**< mac address */
uint32_t phy_11b:1; /**< bit: 0 flag to identify if 11b mode is enabled or not */
uint32_t phy_11g:1; /**< bit: 1 flag to identify if 11g mode is enabled or not */
uint32_t phy_11n:1; /**< bit: 2 flag to identify if 11n mode is enabled or not */
uint32_t phy_lr:1; /**< bit: 3 flag to identify if low rate is enabled or not */
uint32_t reserved:28; /**< bit: 4..31 reserved */
} wifi_sta_info_t;
#define ESP_WIFI_MAX_CONN_NUM (10) /**< max number of stations which can connect to ESP8266 soft-AP */
/** @brief List of stations associated with the ESP8266 Soft-AP */
typedef struct {
wifi_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM]; /**< station list */
int num; /**< number of stations in the list (other entries are invalid) */
} wifi_sta_list_t;
typedef enum {
WIFI_STORAGE_FLASH, /**< all configuration will strore in both memory and flash */
WIFI_STORAGE_RAM, /**< all configuration will only store in the memory */
} wifi_storage_t;
/**
* @brief Vendor Information Element type
*
* Determines the frame type that the IE will be associated with.
*/
typedef enum {
WIFI_VND_IE_TYPE_BEACON,
WIFI_VND_IE_TYPE_PROBE_REQ,
WIFI_VND_IE_TYPE_PROBE_RESP,
WIFI_VND_IE_TYPE_ASSOC_REQ,
WIFI_VND_IE_TYPE_ASSOC_RESP,
} wifi_vendor_ie_type_t;
/**
* @brief Vendor Information Element index
*
* Each IE type can have up to two associated vendor ID elements.
*/
typedef enum {
WIFI_VND_IE_ID_0,
WIFI_VND_IE_ID_1,
} wifi_vendor_ie_id_t;
#define WIFI_VENDOR_IE_ELEMENT_ID 0xDD
/**
* @brief Vendor Information Element header
*
* The first bytes of the Information Element will match this header. Payload follows.
*/
typedef struct {
uint8_t element_id; /**< Should be set to WIFI_VENDOR_IE_ELEMENT_ID (0xDD) */
uint8_t length; /**< Length of all bytes in the element data following this field. Minimum 4. */
uint8_t vendor_oui[3]; /**< Vendor identifier (OUI). */
uint8_t vendor_oui_type; /**< Vendor-specific OUI type. */
uint8_t payload[0]; /**< Payload. Length is equal to value in 'length' field, minus 4. */
} vendor_ie_data_t;
/** @brief Received packet radio metadata header, this is the common header at the beginning of all promiscuous mode RX callback buffers */
typedef struct {
signed rssi:8; /**< signal intensity of packet */
unsigned rate:5; /**< data rate */
unsigned :1; /**< reserve */
unsigned sig_mode:2; /**< 0:is not 11n packet; 1:is 11n packet */
unsigned :16; /**< reserve */
unsigned mcs:7; /**< if is 11n packet, shows the modulation(range from 0 to 76) */
unsigned cwb:1; /**< if is 11n packet, shows if is HT40 packet or not */
unsigned :16; /**< reserve */
unsigned smoothing:1; /**< reserve */
unsigned not_sounding:1; /**< reserve */
unsigned :1; /**< reserve */
unsigned aggregation:1; /**< Aggregation */
unsigned stbc:2; /**< STBC */
unsigned fec_coding:1; /**< Flag is set for 11n packets which are LDPC */
unsigned sgi:1; /**< SGI */
unsigned noise_floor:8; /**< noise floor */
unsigned ampdu_cnt:8; /**< ampdu cnt */
unsigned channel:4; /**< which channel this packet in */
unsigned :12; /**< reserve */
unsigned timestamp:32; /**< timestamp */
unsigned :32; /**< reserve */
unsigned :32; /**< reserve */
unsigned sig_len:12; /**< length of packet */
unsigned :12; /**< reserve */
unsigned rx_state:8; /**< rx state */
} wifi_pkt_rx_ctrl_t;
/** @brief Payload passed to 'buf' parameter of promiscuous mode RX callback.
*/
typedef struct {
wifi_pkt_rx_ctrl_t rx_ctrl; /**< metadata header */
uint8_t payload[0]; /**< Data or management payload. Length of payload is described by rx_ctrl.sig_len. Type of content determined by packet type argument of callback. */
} wifi_promiscuous_pkt_t;
/**
* @brief Promiscuous frame type
*
* Passed to promiscuous mode RX callback to indicate the type of parameter in the buffer.
*
*/
typedef enum {
WIFI_PKT_MGMT, /**< Management frame, indicates 'buf' argument is wifi_promiscuous_pkt_t */
WIFI_PKT_DATA, /**< Data frame, indiciates 'buf' argument is wifi_promiscuous_pkt_t */
WIFI_PKT_MISC, /**< Other type, such as MIMO etc. 'buf' argument is wifi_promiscuous_pkt_t but the payload is zero length. */
} wifi_promiscuous_pkt_type_t;
#define WIFI_PROMIS_FILTER_MASK_ALL (0xFFFFFFFF) /**< filter all packets */
#define WIFI_PROMIS_FILTER_MASK_MGMT (1) /**< filter the packets with type of WIFI_PKT_MGMT */
#define WIFI_PROMIS_FILTER_MASK_DATA (1<<1) /**< filter the packets with type of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_MISC (1<<2) /**< filter the packets with type of WIFI_PKT_MISC */
#define WIFI_PROMIS_FILTER_MASK_DATA_MPDU (1<<3) /**< filter the MPDU which is a kind of WIFI_PKT_DATA */
#define WIFI_PROMIS_FILTER_MASK_DATA_AMPDU (1<<4) /**< filter the AMPDU which is a kind of WIFI_PKT_DATA */
/** @brief Mask for filtering different packet types in promiscuous mode. */
typedef struct {
uint32_t filter_mask; /**< OR of one or more filter values WIFI_PROMIS_FILTER_* */
} wifi_promiscuous_filter_t;
#define WIFI_EVENT_MASK_ALL (0xFFFFFFFF) /**< mask all WiFi events */
#define WIFI_EVENT_MASK_NONE (0) /**< mask none of the WiFi events */
#define WIFI_EVENT_MASK_AP_PROBEREQRECVED (BIT(0)) /**< mask SYSTEM_EVENT_AP_PROBEREQRECVED event */
#ifdef __cplusplus
}
#endif
#endif /* __ESP_WIFI_TYPES_H__ */

View File

@ -1,11 +1,10 @@
gwen:
crypto: 0181338
espnow: 0181338
core: fddcd95
minic: 5fc5b4f
net80211: fd9b17b
pp: 0181338
crypto: 137694e
espnow: 137694e
core: 137694e
net80211: 137694e
pp: 137694e
pwm: 0181338
smartconfig:9ec59b5
wpa: 0181338
wps: 0181338
wpa: 137694e
wps: 137694e

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,44 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "esp_libc.h"
#include "esp_system.h"
#include "esp_wifi.h"
#include "esp_socket.h"
#include "net/sockio.h"
/**
* @brief Init WiFi
* Alloc resource for WiFi driver, such as WiFi control structure, RX/TX buffer,
* WiFi NVS structure etc, this WiFi also start WiFi task
*
* @attention 1. This API must be called before all other WiFi API can be called
* @attention 2. Always use WIFI_INIT_CONFIG_DEFAULT macro to init the config to default values, this can
* guarantee all the fields got correct value when more fields are added into wifi_init_config_t
* in future release. If you want to set your owner initial values, overwrite the default values
* which are set by WIFI_INIT_CONFIG_DEFAULT, please be notified that the field 'magic' of
* wifi_init_config_t should always be WIFI_INIT_CONFIG_MAGIC!
*
* @param config pointer to WiFi init configuration structure; can point to a temporary variable.
*
* @return
* - ESP_OK: succeed
* - ESP_ERR_NO_MEM: out of memory
* - others: refer to error code esp_err.h
*/
esp_err_t esp_wifi_init(const wifi_init_config_t *config)
{
esp_event_set_default_wifi_handlers();
return esp_wifi_init_internal(config);
}

View File

@ -22,6 +22,8 @@
#include "freertos/semphr.h"
#include "freertos/timers.h"
#include "nvs.h"
#if defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NORMAL) || defined(CONFIG_NEWLIB_LIBRARY_LEVEL_NANO)
#include "esp_newlib.h"
#endif
@ -42,7 +44,6 @@ static void *task_create_wrapper(void *task_func, const char *name, uint32_t sta
{
portBASE_TYPE ret;
xTaskHandle handle;
ret = xTaskCreate(task_func, name, stack_depth, param, prio, &handle);
return ret == pdPASS ? handle : NULL;
@ -311,6 +312,8 @@ static int32_t rand_wrapper(void)
}
wifi_osi_funcs_t s_wifi_osi_funcs = {
.version = ESP_WIFI_OS_ADAPTER_VERSION,
.enter_critical = enter_critical_wrapper,
.exit_critical = exit_critical_wrapper,
@ -365,4 +368,19 @@ wifi_osi_funcs_t s_wifi_osi_funcs = {
.srand = srand_wrapper,
.rand = rand_wrapper,
};
.nvs_set_i8 = nvs_set_i8,
.nvs_get_i8 = nvs_get_i8,
.nvs_set_u8 = nvs_set_u8,
.nvs_get_u8 = nvs_get_u8,
.nvs_set_u16 = nvs_set_u16,
.nvs_get_u16 = nvs_get_u16,
.nvs_open = nvs_open,
.nvs_close = nvs_close,
.nvs_commit = nvs_commit,
.nvs_set_blob = nvs_set_blob,
.nvs_get_blob = nvs_get_blob,
.nvs_erase_key = nvs_erase_key,
.magic = ESP_WIFI_OS_ADAPTER_MAGIC,
};

View File

@ -0,0 +1,121 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "esp_err.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_system.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/semphr.h"
#include "tcpip_adapter.h"
#include "esp_log.h"
static const char* TAG = "event";
typedef esp_err_t (*system_event_handler_t)(system_event_t *e);
static esp_err_t system_event_ap_start_handle_default(system_event_t *event);
static esp_err_t system_event_ap_stop_handle_default(system_event_t *event);
static esp_err_t system_event_sta_start_handle_default(system_event_t *event);
static esp_err_t system_event_sta_stop_handle_default(system_event_t *event);
static esp_err_t system_event_sta_connected_handle_default(system_event_t *event);
static esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event);
static esp_err_t system_event_sta_got_ip_default(system_event_t *event);
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event);
/* Default event handler functions
Any entry in this table which is disabled by config will have a NULL handler.
*/
static system_event_handler_t default_event_handlers[SYSTEM_EVENT_MAX] = { 0 };
static esp_err_t system_event_sta_got_ip_default(system_event_t *event)
{
return ESP_OK;
}
static esp_err_t system_event_sta_lost_ip_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_ap_start_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_ap_stop_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_sta_start_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_sta_stop_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_sta_connected_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t system_event_sta_disconnected_handle_default(system_event_t *event)
{
return ESP_OK;
}
esp_err_t esp_event_process_default(system_event_t *event)
{
if (event == NULL) {
return ESP_FAIL;
}
if ((event->event_id < SYSTEM_EVENT_MAX)) {
if (default_event_handlers[event->event_id] != NULL) {
default_event_handlers[event->event_id](event);
}
} else {
return ESP_FAIL;
}
return ESP_OK;
}
void esp_event_set_default_wifi_handlers()
{
default_event_handlers[SYSTEM_EVENT_STA_START] = system_event_sta_start_handle_default;
default_event_handlers[SYSTEM_EVENT_STA_STOP] = system_event_sta_stop_handle_default;
default_event_handlers[SYSTEM_EVENT_STA_CONNECTED] = system_event_sta_connected_handle_default;
default_event_handlers[SYSTEM_EVENT_STA_DISCONNECTED] = system_event_sta_disconnected_handle_default;
default_event_handlers[SYSTEM_EVENT_STA_GOT_IP] = system_event_sta_got_ip_default;
default_event_handlers[SYSTEM_EVENT_STA_LOST_IP] = system_event_sta_lost_ip_default;
default_event_handlers[SYSTEM_EVENT_AP_START] = system_event_ap_start_handle_default;
default_event_handlers[SYSTEM_EVENT_AP_STOP] = system_event_ap_stop_handle_default;
}

View File

@ -0,0 +1,111 @@
// Copyright 2018 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "esp_err.h"
#include "esp_wifi.h"
#include "esp_event.h"
#include "esp_event_loop.h"
#include "esp_wifi_osi.h"
#include "esp_log.h"
#include "sdkconfig.h"
static const char* TAG = "event";
static bool s_event_init_flag = false;
static system_event_cb_t s_event_handler_cb = NULL;
static void *s_event_ctx = NULL;
static void *s_event_queue = NULL;
static esp_err_t esp_event_post_to_user(system_event_t *event)
{
if (s_event_handler_cb) {
return (*s_event_handler_cb)(s_event_ctx, event);
}
return ESP_OK;
}
system_event_cb_t esp_event_loop_set_cb(system_event_cb_t cb, void *ctx)
{
system_event_cb_t old_cb = s_event_handler_cb;
s_event_handler_cb = cb;
s_event_ctx = ctx;
return old_cb;
}
esp_err_t esp_event_send(system_event_t *event)
{
if (s_event_queue == NULL) {
ESP_LOGE(TAG, "Event loop not initialized via esp_event_loop_init, but esp_event_send called");
return ESP_ERR_INVALID_STATE;
}
portBASE_TYPE ret = wifi_queue_send(s_event_queue, event, 0, 1);
if (ret != pdPASS) {
if (event) {
ESP_LOGE(TAG, "e=%d f", event->event_id);
} else {
ESP_LOGE(TAG, "e null");
}
return ESP_FAIL;
}
return ESP_OK;
}
static void esp_event_loop_task(void *pvParameters)
{
while (1) {
system_event_t evt;
if (wifi_queue_recv(s_event_queue, &evt, OSI_FUNCS_TIME_BLOCKING) == pdPASS) {
esp_err_t ret = esp_event_process_default(&evt);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "default event handler failed!");
}
ret = esp_event_post_to_user(&evt);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "post event to user fail!");
}
} else {
ESP_LOGE(TAG, "esp_event_loop_task end");
}
}
}
QueueHandle_t esp_event_loop_get_queue(void)
{
return s_event_queue;
}
esp_err_t esp_event_loop_init(system_event_cb_t cb, void *ctx)
{
if (s_event_init_flag) {
return ESP_FAIL;
}
s_event_handler_cb = cb;
s_event_ctx = ctx;
s_event_queue = wifi_queue_create(32, sizeof(system_event_t));
if(s_event_queue == NULL)
return ESP_ERR_NO_MEM;
if(wifi_task_create(esp_event_loop_task, "esp_event_loop_task", 2048, NULL, 2) == NULL) {
return ESP_ERR_NO_MEM;
}
s_event_handler_cb = cb;
s_event_ctx = ctx;
s_event_init_flag = true;
return ESP_OK;
}

View File

@ -17,6 +17,7 @@
#include "esp8266/eagle_soc.h"
#include "esp8266/ets_sys.h"
#include "esp_err.h"
/*
* @brief output xtensa register value map when crash
@ -55,3 +56,10 @@ void IRAM_ATTR panicHandler(void *frame)
*/
while (1);
}
void _esp_error_check_failed(esp_err_t rc, const char *file, int line, const char *function, const char *expression)
{
printf("ESP_ERROR_CHECK failed: esp_err_t 0x%x at %p\n", rc, __builtin_return_address(0));
printf("file: \"%s\" line %d\nfunc: %s\nexpression: %s\n", file, line, function, expression);
abort();
}

View File

@ -18,7 +18,7 @@
#include "esp_libc.h"
#include "esp_misc.h"
#include "esp_softap.h"
#include "esp_wifi.h"
#include "sdkconfig.h"
#include "lwip/inet.h"
@ -186,9 +186,9 @@ static u8_t* add_offer_options(u8_t* optptr)
*optptr++ = ip4_addr4(&ipadd);
if (dhcps_router_enabled(offer)) {
struct ip_info if_ip;
bzero(&if_ip, sizeof(struct ip_info));
wifi_get_ip_info(SOFTAP_IF, &if_ip);
tcpip_adapter_ip_info_t if_ip;
bzero(&if_ip, sizeof(tcpip_adapter_ip_info_t));
wifi_get_ip_info(ESP_IF_WIFI_AP, &if_ip);
*optptr++ = DHCP_OPTION_ROUTER;
*optptr++ = 4;
@ -971,7 +971,7 @@ static void wifi_softap_init_dhcps_lease(u32_t ip)
// printf("start_ip = 0x%x, end_ip = 0x%x\n",dhcps_lease.start_ip, dhcps_lease.end_ip);
}
///////////////////////////////////////////////////////////////////////////////////
void dhcps_start(struct ip_info* info)
void dhcps_start(tcpip_adapter_ip_info_t* info)
{
if (pcb_dhcps != NULL) {
udp_remove(pcb_dhcps);
@ -1022,14 +1022,15 @@ void dhcps_stop(void)
bool wifi_softap_set_dhcps_lease(struct dhcps_lease* please)
{
struct ip_info info;
tcpip_adapter_ip_info_t info;
u32_t softap_ip = 0;
u32_t start_ip = 0;
u32_t end_ip = 0;
u8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE || opmode == NULL_MODE) {
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_NULL) {
return false;
}
@ -1038,8 +1039,8 @@ bool wifi_softap_set_dhcps_lease(struct dhcps_lease* please)
}
if (please->enable) {
bzero(&info, sizeof(struct ip_info));
wifi_get_ip_info(SOFTAP_IF, &info);
bzero(&info, sizeof(tcpip_adapter_ip_info_t));
wifi_get_ip_info(ESP_IF_WIFI_AP, &info);
softap_ip = htonl(info.ip.addr);
start_ip = htonl(please->start_ip.addr);
end_ip = htonl(please->end_ip.addr);
@ -1082,9 +1083,10 @@ bool wifi_softap_set_dhcps_lease(struct dhcps_lease* please)
*******************************************************************************/
bool wifi_softap_get_dhcps_lease(struct dhcps_lease* please)
{
u8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE || opmode == NULL_MODE) {
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_NULL) {
return false;
}
@ -1193,9 +1195,10 @@ bool wifi_softap_set_dhcps_offer_option(u8_t level, void* optarg)
bool wifi_softap_set_dhcps_lease_time(u32_t minute)
{
u8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE || opmode == NULL_MODE) {
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_NULL) {
return false;
}
@ -1213,9 +1216,10 @@ bool wifi_softap_set_dhcps_lease_time(u32_t minute)
bool wifi_softap_reset_dhcps_lease_time(void)
{
u8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE || opmode == NULL_MODE) {
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_NULL) {
return false;
}

View File

@ -83,7 +83,7 @@ extern u32_t dhcps_lease_time;
#define dhcps_router_enabled(offer) ((offer & OFFER_ROUTER) != 0)
void dhcps_start(struct ip_info* info);
void dhcps_start(tcpip_adapter_ip_info_t* info);
void dhcps_stop(void);
#endif

View File

@ -264,25 +264,16 @@ int8_t ethernetif_init(struct netif* netif)
/* set MAC hardware address */
if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
wifi_get_macaddr(TCPIP_ADAPTER_IF_STA, mac);
esp_wifi_get_mac(TCPIP_ADAPTER_IF_STA, mac);
} else {
wifi_get_macaddr(TCPIP_ADAPTER_IF_AP, mac);
esp_wifi_set_mac(TCPIP_ADAPTER_IF_AP, mac);
}
memcpy(netif->hwaddr, mac, NETIF_MAX_HWADDR_LEN);
#if LWIP_NETIF_HOSTNAME
if (wifi_get_netif(TCPIP_ADAPTER_IF_STA) == TCPIP_ADAPTER_IF_STA) {
if (default_hostname == 1) {
wifi_station_set_default_hostname(netif->hwaddr);
}
/* Initialize interface hostname */
netif->hostname = hostname;
} else {
netif->hostname = NULL;
}
netif->hostname = "lwip";
#endif /* LWIP_NETIF_HOSTNAME */

View File

@ -20,6 +20,7 @@
#include "esp8266/eagle_soc.h"
#include "esp8266/uart_register.h"
#include "FreeRTOS.h"
#include "esp_log.h"
#define PANIC_UART 0
@ -126,3 +127,9 @@ void _exit(int status)
{
while (1);
}
void abort(void)
{
ESP_LOGE("ABORT","Error found and abort!");
while(1);
}

View File

@ -472,7 +472,7 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const void *src, size_t si
size = (size / 4 + 1) * 4;
}
if (IS_FLASH(src)) {
if (IS_FLASH(src) || ((size_t)src) & 0x3) {
tmp = wifi_malloc(size, OSI_MALLOC_CAP_32BIT);
if (!tmp) {
return ESP_ERR_NO_MEM;
@ -499,7 +499,7 @@ esp_err_t IRAM_ATTR spi_flash_write(size_t dest_addr, const void *src, size_t si
FLASH_INTR_UNLOCK(c_tmp);
if (IS_FLASH(src))
if (IS_FLASH(src) || ((size_t)src) & 0x3)
wifi_free(tmp);
spi_debug("%d\n", system_get_time());

View File

@ -35,6 +35,16 @@
*
*/
typedef struct {
ip4_addr_t ip;
ip4_addr_t netmask;
ip4_addr_t gw;
} tcpip_adapter_ip_info_t;
typedef struct {
ip6_addr_t ip;
} tcpip_adapter_ip6_info_t;
typedef enum {
TCPIP_ADAPTER_IF_STA = 0, /**< ESP8266 station interface */
TCPIP_ADAPTER_IF_AP, /**< ESP8266 soft-AP interface */
@ -58,5 +68,11 @@ bool default_hostname;
#define TCPIP_ATAPTER_LOG(str, ...)
#endif
/**
* @brief Initialize tcpip adapter
*
* This will initialize TCPIP stack inside.
*/
void tcpip_adapter_init(void);
#endif /* _TCPIP_ADAPTER_H_ */

View File

@ -47,7 +47,12 @@ static os_timer_t* get_ip_timer;
static uint8_t dhcp_fail_time;
static bool dhcps_flag = true;
static bool dhcpc_flag = true;
static struct ip_info esp_ip[TCPIP_ADAPTER_IF_MAX];
static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
void tcpip_adapter_init(void)
{
//TODO:add tcpip init function.
}
void esp_wifi_station_dhcpc_event(uint8_t netif_index)
{
@ -78,8 +83,6 @@ static void tcpip_adapter_dhcpc_done()
os_timer_setfn(get_ip_timer, tcpip_adapter_dhcpc_done, NULL);
os_timer_arm(get_ip_timer, 200, 1);
} else {
extern void wifi_station_dhcpc_event();
wifi_station_dhcpc_event();
TCPIP_ATAPTER_LOG("ERROR dhcp get ip error\n");
free(get_ip_timer);
}
@ -268,9 +271,10 @@ void tcpip_adapter_start(uint8_t netif_index, bool authed)
netif_set_default(esp_netif[netif_index]);
}
uint8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE) {
if (opmode == WIFI_MODE_STA) {
netif_set_default(esp_netif[netif_index]);
}
}
@ -303,7 +307,7 @@ void tcpip_adapter_stop(uint8_t netif_index)
esp_netif[netif_index] = NULL;
}
bool wifi_set_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
bool wifi_set_ip_info(wifi_interface_t netif_index, tcpip_adapter_ip_info_t* if_ip)
{
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
@ -315,7 +319,7 @@ bool wifi_set_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
return true;
}
bool wifi_get_ip_info(WIFI_INTERFACE netif_index, struct ip_info* if_ip)
bool wifi_get_ip_info(wifi_interface_t netif_index, tcpip_adapter_ip_info_t* if_ip)
{
if (!TCPIP_ADAPTER_IF_VALID((uint8_t)netif_index)) {
TCPIP_ATAPTER_LOG("ERROR bad netif index:%d\n", netif_index);
@ -374,20 +378,20 @@ bool wifi_get_ipinfo_v6(uint8_t netif_index, uint8_t ip_index, ip6_addr_t* ipv6)
bool wifi_softap_dhcps_start(void)
{
uint8_t opmode = NULL_MODE;
wifi_mode_t opmode = WIFI_MODE_NULL;
TCPIP_ATAPTER_LOG("start softap dhcps\n");
taskENTER_CRITICAL();
opmode = wifi_get_opmode();
esp_wifi_get_mode(&opmode);
if ((opmode == STATION_MODE) || (opmode == NULL_MODE)) {
if ((opmode == WIFI_MODE_STA) || (opmode == WIFI_MODE_NULL)) {
taskEXIT_CRITICAL();
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
return false;
}
if (dhcps_flag == false) {
struct ip_info ipinfo;
wifi_get_ip_info(SOFTAP_IF, &ipinfo);
tcpip_adapter_ip_info_t ipinfo;
wifi_get_ip_info(ESP_IF_WIFI_AP, &ipinfo);
TCPIP_ATAPTER_LOG("start softap dhcpserver\n");
dhcps_start(&ipinfo);
}
@ -425,11 +429,11 @@ void tcpip_adapter_sta_leave()
bool wifi_softap_dhcps_stop()
{
uint8_t opmode = NULL_MODE;
wifi_mode_t opmode = WIFI_MODE_NULL;
taskENTER_CRITICAL();
opmode = wifi_get_opmode();
esp_wifi_get_mode(&opmode);
if ((opmode == STATION_MODE) || (opmode == NULL_MODE)) {
if ((opmode == WIFI_MODE_STA) || (opmode == WIFI_MODE_NULL)) {
taskEXIT_CRITICAL();
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi softap before start dhcp server\n");
return false;
@ -448,12 +452,12 @@ bool wifi_softap_dhcps_stop()
bool wifi_station_dhcpc_start(void)
{
uint8_t opmode = NULL_MODE;
wifi_mode_t opmode = WIFI_MODE_NULL;
err_t ret;
taskENTER_CRITICAL();
opmode = wifi_get_opmode();
esp_wifi_get_mode(&opmode);
if ((opmode == SOFTAP_MODE) || (opmode == NULL_MODE)) {
if ((opmode == WIFI_MODE_AP) || (opmode == WIFI_MODE_NULL)) {
taskEXIT_CRITICAL();
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before start dhcp client\n");
return false;
@ -487,11 +491,11 @@ bool wifi_station_dhcpc_start(void)
bool wifi_station_dhcpc_stop()
{
uint8_t opmode = NULL_MODE;
wifi_mode_t opmode = WIFI_MODE_NULL;
taskENTER_CRITICAL();
opmode = wifi_get_opmode();
esp_wifi_get_mode(&opmode);
if ((opmode == SOFTAP_MODE) || (opmode == NULL_MODE)) {
if ((opmode == WIFI_MODE_AP) || (opmode == WIFI_MODE_NULL)) {
taskEXIT_CRITICAL();
TCPIP_ATAPTER_LOG("ERROR you shoud enable wifi station mode before stop dhcp client\n");
return false;
@ -559,9 +563,10 @@ bool wifi_station_set_hostname(char* name)
return false;
}
uint8_t opmode = wifi_get_opmode();
wifi_mode_t opmode;
esp_wifi_get_mode(&opmode);
if (opmode == STATION_MODE || opmode == STATIONAP_MODE) {
if (opmode == WIFI_MODE_STA || opmode == WIFI_MODE_AP) {
default_hostname = 0;
if (hostname != NULL) {