mirror of
https://github.com/apache/nuttx.git
synced 2026-05-12 17:58:10 +08:00
xtensa/esp32: Support esp32 wireless ioctl cmd
This commit is contained in:
committed by
Alan Carvalho de Assis
parent
ca05ff5ffb
commit
f54aef9977
@@ -909,6 +909,12 @@ config ESP32_WIFI_CONNECT_TIMEOUT
|
||||
help
|
||||
Max waiting time of connecting to AP.
|
||||
|
||||
config ESP32_WIFI_SCAN_RESULT_SIZE
|
||||
int "Scan result buffer"
|
||||
default 4096
|
||||
help
|
||||
Maximum scan result buffer size.
|
||||
|
||||
config ESP32_WIFI_SAVE_PARAM
|
||||
bool "Save WiFi Parameters"
|
||||
default n
|
||||
|
||||
@@ -201,7 +201,7 @@ clean_context::
|
||||
|
||||
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include)
|
||||
INCLUDES += $(shell $(INCDIR) "$(CC)" $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)include$(DELIM)esp32)
|
||||
CHIP_CSRCS += esp32_wlan.c esp32_wifi_adapter.c
|
||||
CHIP_CSRCS += esp32_wlan.c esp32_wifi_utils.c esp32_wifi_adapter.c
|
||||
|
||||
EXTRA_LIBPATHS += -L $(ARCH_SRCDIR)$(DELIM)chip$(DELIM)esp-wireless-drivers-3rdparty$(DELIM)libs$(DELIM)esp32
|
||||
EXTRA_LIBS += -lcore -lrtc -lnet80211 -lpp -lsmartconfig -lcoexist -lespnow -lphy -lwpa_supplicant
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,120 @@
|
||||
/****************************************************************************
|
||||
* arch/xtensa/src/esp32/esp32_wifi_utils.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __ARCH_XTENSA_SRC_ESP32_ESP32_UTILS_H
|
||||
#define __ARCH_XTENSA_SRC_ESP32_ESP32_UTILS_H
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef __ASSEMBLY__
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_start_scan
|
||||
*
|
||||
* Description:
|
||||
* Scan all available APs.
|
||||
*
|
||||
* Input Parameters:
|
||||
* iwr - The argument of the ioctl cmd
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_start_scan(struct iwreq *iwr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_get_scan_results
|
||||
*
|
||||
* Description:
|
||||
* Get scan result
|
||||
*
|
||||
* Input Parameters:
|
||||
* req The argument of the ioctl cmd
|
||||
*
|
||||
* Returned Value:
|
||||
* OK on success (positive non-zero values are cmd-specific)
|
||||
* Negated errno returned on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_get_scan_results(struct iwreq *iwr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_scan_event_parse
|
||||
*
|
||||
* Description:
|
||||
* Parse scan information
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void esp_wifi_scan_event_parse(void);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: esp_wifi_scan_para
|
||||
*
|
||||
* Description:
|
||||
* Initialize ESP32 WiFi scan parameter.
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* OK is returned on success. Otherwise, a negated errno value is returned.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int esp_wifi_scan_init(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#undef EXTERN
|
||||
|
||||
#endif /* __ASSEMBLY__ */
|
||||
#endif /* __ARCH_XTENSA_SRC_ESP32_ESP32_UTILS_H */
|
||||
@@ -44,6 +44,8 @@
|
||||
#endif
|
||||
|
||||
#include "esp32_wlan.h"
|
||||
#include "esp32_wifi_utils.h"
|
||||
#include "esp32_wifi_adapter.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
@@ -111,19 +113,21 @@ struct wlan_pktbuf
|
||||
struct wlan_ops
|
||||
{
|
||||
int (*start)(void);
|
||||
|
||||
int (*send)(void *pdata, size_t n);
|
||||
|
||||
int (*ssid)(const uint8_t *pdata, uint8_t n);
|
||||
|
||||
int (*passwd)(const uint8_t *pdata, uint8_t n);
|
||||
|
||||
int (*essid)(struct iwreq *iwr, bool set);
|
||||
int (*bssid)(struct iwreq *iwr, bool set);
|
||||
int (*passwd)(struct iwreq *iwr, bool set);
|
||||
int (*mode)(struct iwreq *iwr, bool set);
|
||||
int (*auth)(struct iwreq *iwr, bool set);
|
||||
int (*freq)(struct iwreq *iwr, bool set);
|
||||
int (*bitrate)(struct iwreq *iwr, bool set);
|
||||
int (*txpower)(struct iwreq *iwr, bool set);
|
||||
int (*channel)(struct iwreq *iwr, bool set);
|
||||
int (*country)(struct iwreq *iwr, bool set);
|
||||
int (*rssi)(struct iwreq *iwr, bool set);
|
||||
int (*connect)(void);
|
||||
|
||||
int (*disconnect)(void);
|
||||
|
||||
int (*event)(pid_t pid, FAR struct sigevent *event);
|
||||
|
||||
int (*stop)(void);
|
||||
};
|
||||
|
||||
@@ -179,8 +183,17 @@ static const struct wlan_ops g_sta_ops =
|
||||
{
|
||||
.start = esp_wifi_sta_start,
|
||||
.send = esp_wifi_sta_send_data,
|
||||
.ssid = esp_wifi_sta_set_ssid,
|
||||
.passwd = esp_wifi_sta_set_password,
|
||||
.essid = esp_wifi_sta_essid,
|
||||
.bssid = esp_wifi_sta_bssid,
|
||||
.passwd = esp_wifi_sta_password,
|
||||
.mode = esp_wifi_sta_mode,
|
||||
.auth = esp_wifi_sta_auth,
|
||||
.freq = esp_wifi_sta_freq,
|
||||
.bitrate = esp_wifi_sta_bitrate,
|
||||
.txpower = esp_wifi_sta_txpower,
|
||||
.channel = esp_wifi_sta_channel,
|
||||
.country = esp_wifi_sta_country,
|
||||
.rssi = esp_wifi_sta_rssi,
|
||||
.connect = esp_wifi_sta_connect,
|
||||
.disconnect = esp_wifi_sta_disconnect,
|
||||
.event = esp_wifi_notify_subscribe,
|
||||
@@ -193,8 +206,17 @@ static const struct wlan_ops g_softap_ops =
|
||||
{
|
||||
.start = esp_wifi_softap_start,
|
||||
.send = esp_wifi_softap_send_data,
|
||||
.ssid = esp_wifi_softap_set_ssid,
|
||||
.passwd = esp_wifi_softap_set_password,
|
||||
.essid = esp_wifi_softap_essid,
|
||||
.bssid = esp_wifi_softap_bssid,
|
||||
.passwd = esp_wifi_softap_password,
|
||||
.mode = esp_wifi_softap_mode,
|
||||
.auth = esp_wifi_softap_auth,
|
||||
.freq = esp_wifi_softap_freq,
|
||||
.bitrate = esp_wifi_softap_bitrate,
|
||||
.txpower = esp_wifi_softap_txpower,
|
||||
.channel = esp_wifi_softap_channel,
|
||||
.country = esp_wifi_softap_country,
|
||||
.rssi = esp_wifi_softap_rssi,
|
||||
.connect = esp_wifi_softap_connect,
|
||||
.disconnect = esp_wifi_softap_disconnect,
|
||||
.event = esp_wifi_notify_subscribe,
|
||||
@@ -1477,54 +1499,136 @@ static int wlan_ioctl(FAR struct net_driver_s *dev,
|
||||
#endif
|
||||
|
||||
case SIOCSIWENCODEEXT:
|
||||
{
|
||||
struct iw_encode_ext *ext = iwr->u.encoding.pointer;
|
||||
ret = ops->passwd(ext->key, ext->key_len);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to set password\n");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIOCSIWESSID:
|
||||
{
|
||||
struct iw_point *essid = &iwr->u.essid;
|
||||
if (essid->length)
|
||||
{
|
||||
ret = ops->ssid(essid->pointer, essid->length);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to set SSID\n");
|
||||
break;
|
||||
}
|
||||
ret = ops->passwd(iwr, true);
|
||||
|
||||
ret = ops->connect();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to connect\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ops->disconnect();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to connect\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SIOCSIWMODE:
|
||||
ret = OK;
|
||||
|
||||
case SIOCGIWENCODEEXT:
|
||||
ret = ops->passwd(iwr, false);
|
||||
break;
|
||||
case SIOCSIWAUTH:
|
||||
ret = OK;
|
||||
|
||||
case SIOCSIWESSID:
|
||||
if ((iwr->u.essid.flags == IW_ESSID_ON) ||
|
||||
(iwr->u.essid.flags == IW_ESSID_DELAY_ON))
|
||||
{
|
||||
ret = ops->essid(iwr, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (iwr->u.essid.flags == IW_ESSID_ON)
|
||||
{
|
||||
ret = ops->connect();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ops->disconnect();
|
||||
}
|
||||
|
||||
break;
|
||||
case SIOCSIWFREQ:
|
||||
ret = OK;
|
||||
|
||||
case SIOCGIWESSID: /* Get ESSID */
|
||||
ret = ops->essid(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWAP: /* Set access point MAC addresses */
|
||||
if (iwr->u.ap_addr.sa_data[0] != 0 &&
|
||||
iwr->u.ap_addr.sa_data[1] != 0 &&
|
||||
iwr->u.ap_addr.sa_data[2] != 0)
|
||||
{
|
||||
ret = ops->bssid(iwr, true);
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to set BSSID\n");
|
||||
break;
|
||||
}
|
||||
|
||||
ret = ops->connect();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to connect\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = ops->disconnect();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Failed to connect\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case SIOCGIWAP: /* Get access point MAC addresses */
|
||||
ret = ops->bssid(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWSCAN:
|
||||
ret = esp_wifi_start_scan(iwr);
|
||||
break;
|
||||
|
||||
case SIOCGIWSCAN:
|
||||
ret = esp_wifi_get_scan_results(iwr);
|
||||
break;
|
||||
|
||||
case SIOCSIWCOUNTRY: /* Set country code */
|
||||
ret = ops->country(iwr, true);
|
||||
break;
|
||||
|
||||
case SIOCGIWSENS: /* Get sensitivity (dBm) */
|
||||
ret = ops->rssi(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWMODE: /* Set operation mode */
|
||||
ret = ops->mode(iwr, true);
|
||||
break;
|
||||
|
||||
case SIOCGIWMODE: /* Get operation mode */
|
||||
ret = ops->mode(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWAUTH: /* Set authentication mode params */
|
||||
ret = ops->auth(iwr, true);
|
||||
break;
|
||||
|
||||
case SIOCGIWAUTH: /* Get authentication mode params */
|
||||
ret = ops->auth(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWFREQ: /* Set channel/frequency (MHz) */
|
||||
ret = ops->freq(iwr, true);
|
||||
break;
|
||||
|
||||
case SIOCGIWFREQ: /* Get channel/frequency (MHz) */
|
||||
ret = ops->freq(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWRATE: /* Set default bit rate (Mbps) */
|
||||
wlwarn("WARNING: SIOCSIWRATE not implemented\n");
|
||||
ret = -ENOSYS;
|
||||
break;
|
||||
|
||||
case SIOCGIWRATE: /* Get default bit rate (Mbps) */
|
||||
ret = ops->bitrate(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCSIWTXPOW: /* Set transmit power (dBm) */
|
||||
ret = ops->txpower(iwr, true);
|
||||
break;
|
||||
|
||||
case SIOCGIWTXPOW: /* Get transmit power (dBm) */
|
||||
ret = ops->txpower(iwr, false);
|
||||
break;
|
||||
|
||||
case SIOCGIWRANGE: /* Get range of parameters */
|
||||
ret = ops->channel(iwr, false);
|
||||
break;
|
||||
|
||||
default:
|
||||
nerr("ERROR: Unrecognized IOCTL command: %d\n", cmd);
|
||||
ret = -ENOTTY; /* Special return value for this case */
|
||||
@@ -1747,6 +1851,13 @@ int esp32_wlan_sta_initialize(void)
|
||||
eth_mac[0], eth_mac[1], eth_mac[2],
|
||||
eth_mac[3], eth_mac[4], eth_mac[5]);
|
||||
|
||||
ret = esp_wifi_scan_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Initialize WiFi scan parameter error: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp32_net_initialize(ESP32_WLAN_STA_DEVNO, eth_mac, &g_sta_ops);
|
||||
if (ret < 0)
|
||||
{
|
||||
@@ -1807,6 +1918,13 @@ int esp32_wlan_softap_initialize(void)
|
||||
eth_mac[0], eth_mac[1], eth_mac[2],
|
||||
eth_mac[3], eth_mac[4], eth_mac[5]);
|
||||
|
||||
ret = esp_wifi_scan_init();
|
||||
if (ret < 0)
|
||||
{
|
||||
nerr("ERROR: Initialize WiFi scan parameter error: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = esp32_net_initialize(ESP32_WLAN_SOFTAP_DEVNO, eth_mac,
|
||||
&g_softap_ops);
|
||||
if (ret < 0)
|
||||
|
||||
@@ -43,7 +43,7 @@ CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=2
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NETDB_DNSCLIENT=y
|
||||
CONFIG_NETDEV_LATEINIT=y
|
||||
CONFIG_NETDEV_PHY_IOCTL=y
|
||||
|
||||
@@ -32,6 +32,7 @@ CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
|
||||
@@ -31,6 +31,7 @@ CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
|
||||
@@ -32,6 +32,7 @@ CONFIG_HAVE_CXX=y
|
||||
CONFIG_HAVE_CXXINITIALIZE=y
|
||||
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_MAX_TASKS=16
|
||||
CONFIG_MM_REGIONS=3
|
||||
CONFIG_NAME_MAX=48
|
||||
|
||||
@@ -268,6 +268,12 @@
|
||||
|
||||
#define IW_MAX_FREQUENCIES 32 /* Max. frequencies in struct iw_range */
|
||||
|
||||
/* ESSID flags */
|
||||
|
||||
#define IW_ESSID_OFF 0 /* Disconnect with access point */
|
||||
#define IW_ESSID_ON 1 /* Connect with access point */
|
||||
#define IW_ESSID_DELAY_ON 2 /* Delay the connection behavior of essid */
|
||||
|
||||
/* Transmit Power flags available */
|
||||
|
||||
#define IW_TXPOW_TYPE 0x00ff /* Type of value */
|
||||
|
||||
Reference in New Issue
Block a user