net: wifi: Move Wi-Fi ops to a separate struct
Decouple interface and Wi-Fi APIs, Wi-Fi APIs are common independent of Wi-Fi offload or implemented natively (This is preparation for introducing Native Wi-Fi). Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
This commit is contained in:
parent
1ddc41e7dd
commit
a132487fec
|
@ -624,18 +624,22 @@ static int esp32_wifi_dev_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const struct net_wifi_mgmt_offload esp32_api = {
|
||||
.wifi_iface.iface_api.init = esp32_wifi_init,
|
||||
.wifi_iface.send = esp32_wifi_send,
|
||||
static const struct wifi_mgmt_ops esp32_wifi_mgmt = {
|
||||
.scan = esp32_wifi_scan,
|
||||
.connect = esp32_wifi_connect,
|
||||
.disconnect = esp32_wifi_disconnect,
|
||||
.ap_enable = esp32_wifi_ap_enable,
|
||||
.ap_disable = esp32_wifi_ap_disable,
|
||||
.iface_status = esp32_wifi_status,
|
||||
#if defined(CONFIG_NET_STATISTICS_WIFI)
|
||||
.get_stats = esp32_wifi_stats,
|
||||
#endif
|
||||
.scan = esp32_wifi_scan,
|
||||
.connect = esp32_wifi_connect,
|
||||
.disconnect = esp32_wifi_disconnect,
|
||||
.ap_enable = esp32_wifi_ap_enable,
|
||||
.ap_disable = esp32_wifi_ap_disable,
|
||||
.iface_status = esp32_wifi_status,
|
||||
.get_stats = esp32_wifi_stats,
|
||||
#endif
|
||||
};
|
||||
|
||||
static const struct net_wifi_mgmt_offload esp32_api = {
|
||||
.wifi_iface.iface_api.init = esp32_wifi_init,
|
||||
.wifi_iface.send = esp32_wifi_send,
|
||||
.wifi_mgmt_api = &esp32_wifi_mgmt,
|
||||
};
|
||||
|
||||
NET_DEVICE_DT_INST_DEFINE(0,
|
||||
|
|
|
@ -1246,15 +1246,20 @@ static enum offloaded_net_if_types esp_offload_get_type(void)
|
|||
{
|
||||
return L2_OFFLOADED_NET_IF_TYPE_WIFI;
|
||||
}
|
||||
|
||||
static const struct wifi_mgmt_ops esp_mgmt_ops = {
|
||||
.scan = esp_mgmt_scan,
|
||||
.connect = esp_mgmt_connect,
|
||||
.disconnect = esp_mgmt_disconnect,
|
||||
.ap_enable = esp_mgmt_ap_enable,
|
||||
.ap_disable = esp_mgmt_ap_disable,
|
||||
.iface_status = esp_mgmt_iface_status,
|
||||
};
|
||||
|
||||
static const struct net_wifi_mgmt_offload esp_api = {
|
||||
.wifi_iface.iface_api.init = esp_iface_init,
|
||||
.wifi_iface.get_type = esp_offload_get_type,
|
||||
.scan = esp_mgmt_scan,
|
||||
.connect = esp_mgmt_connect,
|
||||
.disconnect = esp_mgmt_disconnect,
|
||||
.ap_enable = esp_mgmt_ap_enable,
|
||||
.ap_disable = esp_mgmt_ap_disable,
|
||||
.iface_status = esp_mgmt_iface_status,
|
||||
.wifi_iface.get_type = esp_offload_get_type,
|
||||
.wifi_mgmt_api = &esp_mgmt_ops,
|
||||
};
|
||||
|
||||
static int esp_init(const struct device *dev);
|
||||
|
|
|
@ -786,15 +786,19 @@ static enum offloaded_net_if_types eswifi_get_type(void)
|
|||
return L2_OFFLOADED_NET_IF_TYPE_WIFI;
|
||||
}
|
||||
|
||||
static const struct wifi_mgmt_ops eswifi_mgmt_api = {
|
||||
.scan = eswifi_mgmt_scan,
|
||||
.connect = eswifi_mgmt_connect,
|
||||
.disconnect = eswifi_mgmt_disconnect,
|
||||
.ap_enable = eswifi_mgmt_ap_enable,
|
||||
.ap_disable = eswifi_mgmt_ap_disable,
|
||||
.iface_status = eswifi_mgmt_iface_status,
|
||||
};
|
||||
|
||||
static const struct net_wifi_mgmt_offload eswifi_offload_api = {
|
||||
.wifi_iface.iface_api.init = eswifi_iface_init,
|
||||
.wifi_iface.get_type = eswifi_get_type,
|
||||
.scan = eswifi_mgmt_scan,
|
||||
.connect = eswifi_mgmt_connect,
|
||||
.disconnect = eswifi_mgmt_disconnect,
|
||||
.ap_enable = eswifi_mgmt_ap_enable,
|
||||
.ap_disable = eswifi_mgmt_ap_disable,
|
||||
.iface_status = eswifi_mgmt_iface_status,
|
||||
.wifi_iface.get_type = eswifi_get_type,
|
||||
.wifi_mgmt_api = &eswifi_mgmt_api,
|
||||
};
|
||||
|
||||
NET_DEVICE_DT_INST_OFFLOAD_DEFINE(0, eswifi_init, NULL,
|
||||
|
|
|
@ -272,12 +272,16 @@ static enum offloaded_net_if_types simplelink_get_type(void)
|
|||
return L2_OFFLOADED_NET_IF_TYPE_WIFI;
|
||||
}
|
||||
|
||||
static const struct wifi_mgmt_ops simplelink_mgmt = {
|
||||
.scan = simplelink_mgmt_scan,
|
||||
.connect = simplelink_mgmt_connect,
|
||||
.disconnect = simplelink_mgmt_disconnect,
|
||||
};
|
||||
|
||||
static const struct net_wifi_mgmt_offload simplelink_api = {
|
||||
.wifi_iface.iface_api.init = simplelink_iface_init,
|
||||
.wifi_iface.get_type = simplelink_get_type,
|
||||
.scan = simplelink_mgmt_scan,
|
||||
.connect = simplelink_mgmt_connect,
|
||||
.disconnect = simplelink_mgmt_disconnect,
|
||||
.wifi_iface.get_type = simplelink_get_type,
|
||||
.wifi_mgmt_api = &simplelink_mgmt,
|
||||
};
|
||||
|
||||
static int simplelink_init(const struct device *dev)
|
||||
|
|
|
@ -1108,14 +1108,17 @@ static enum offloaded_net_if_types winc1500_get_wifi_type(void)
|
|||
return L2_OFFLOADED_NET_IF_TYPE_WIFI;
|
||||
}
|
||||
|
||||
static const struct wifi_mgmt_ops winc1500_mgmt_ops = {
|
||||
.scan = winc1500_mgmt_scan,
|
||||
.connect = winc1500_mgmt_connect,
|
||||
.disconnect = winc1500_mgmt_disconnect,
|
||||
.ap_enable = winc1500_mgmt_ap_enable,
|
||||
.ap_disable = winc1500_mgmt_ap_disable,
|
||||
};
|
||||
static const struct net_wifi_mgmt_offload winc1500_api = {
|
||||
.wifi_iface.iface_api.init = winc1500_iface_init,
|
||||
.wifi_iface.get_type = winc1500_get_wifi_type,
|
||||
.scan = winc1500_mgmt_scan,
|
||||
.connect = winc1500_mgmt_connect,
|
||||
.disconnect = winc1500_mgmt_disconnect,
|
||||
.ap_enable = winc1500_mgmt_ap_enable,
|
||||
.ap_disable = winc1500_mgmt_ap_disable,
|
||||
.wifi_iface.get_type = winc1500_get_wifi_type,
|
||||
.wifi_mgmt_api = &winc1500_mgmt_ops,
|
||||
};
|
||||
|
||||
static int winc1500_init(const struct device *dev)
|
||||
|
|
|
@ -314,19 +314,7 @@ typedef void (*scan_result_cb_t)(struct net_if *iface, int status,
|
|||
typedef void (*raw_scan_result_cb_t)(struct net_if *iface, int status,
|
||||
struct wifi_raw_scan_result *entry);
|
||||
#endif /* CONFIG_WIFI_MGMT_RAW_SCAN_RESULTS */
|
||||
struct net_wifi_mgmt_offload {
|
||||
/**
|
||||
* Mandatory to get in first position.
|
||||
* A network device should indeed provide a pointer on such
|
||||
* net_if_api structure. So we make current structure pointer
|
||||
* that can be casted to a net_if_api structure pointer.
|
||||
*/
|
||||
#ifdef CONFIG_WIFI_USE_NATIVE_NETWORKING
|
||||
struct ethernet_api wifi_iface;
|
||||
#else
|
||||
struct offloaded_if_api wifi_iface;
|
||||
#endif
|
||||
|
||||
struct wifi_mgmt_ops {
|
||||
/* cb parameter is the cb that should be called for each
|
||||
* result by the driver. The wifi mgmt part will take care of
|
||||
* raising the necessary event etc...
|
||||
|
@ -350,6 +338,21 @@ struct net_wifi_mgmt_offload {
|
|||
int (*reg_domain)(const struct device *dev, struct wifi_reg_domain *reg_domain);
|
||||
};
|
||||
|
||||
struct net_wifi_mgmt_offload {
|
||||
/**
|
||||
* Mandatory to get in first position.
|
||||
* A network device should indeed provide a pointer on such
|
||||
* net_if_api structure. So we make current structure pointer
|
||||
* that can be casted to a net_if_api structure pointer.
|
||||
*/
|
||||
#ifdef CONFIG_WIFI_USE_NATIVE_NETWORKING
|
||||
struct ethernet_api wifi_iface;
|
||||
#else
|
||||
struct offloaded_if_api wifi_iface;
|
||||
#endif
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api;
|
||||
};
|
||||
|
||||
/* Make sure that the network interface API is properly setup inside
|
||||
* Wifi mgmt offload API struct (it is the first one).
|
||||
*/
|
||||
|
|
|
@ -12,6 +12,15 @@ LOG_MODULE_REGISTER(net_wifi_mgmt, CONFIG_NET_L2_WIFI_MGMT_LOG_LEVEL);
|
|||
#include <zephyr/net/net_core.h>
|
||||
#include <zephyr/net/net_if.h>
|
||||
#include <zephyr/net/wifi_mgmt.h>
|
||||
#include <zephyr/net/wifi_native.h>
|
||||
static const struct wifi_mgmt_ops *const get_wifi_api(struct net_if *iface)
|
||||
{
|
||||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
|
||||
return off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
}
|
||||
|
||||
static int wifi_connect(uint32_t mgmt_request, struct net_if *iface,
|
||||
void *data, size_t len)
|
||||
|
@ -21,8 +30,9 @@ static int wifi_connect(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
|
||||
if (off_api == NULL || off_api->connect == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->connect == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -49,7 +59,7 @@ static int wifi_connect(uint32_t mgmt_request, struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return off_api->connect(dev, params);
|
||||
return wifi_mgmt_api->connect(dev, params);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CONNECT, wifi_connect);
|
||||
|
@ -82,11 +92,10 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
|
|||
void *data, size_t len)
|
||||
{
|
||||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
struct wifi_scan_params *params = data;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
|
||||
if (off_api == NULL || off_api->scan == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->scan == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -96,24 +105,24 @@ static int wifi_scan(uint32_t mgmt_request, struct net_if *iface,
|
|||
#endif
|
||||
}
|
||||
|
||||
return off_api->scan(dev, params, scan_result_cb);
|
||||
return wifi_mgmt_api->scan(dev, params, scan_result_cb);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_SCAN, wifi_scan);
|
||||
|
||||
|
||||
static int wifi_disconnect(uint32_t mgmt_request, struct net_if *iface,
|
||||
void *data, size_t len)
|
||||
{
|
||||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
|
||||
if (off_api == NULL || off_api->disconnect == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->disconnect == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return off_api->disconnect(dev);
|
||||
return wifi_mgmt_api->disconnect(dev);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_DISCONNECT, wifi_disconnect);
|
||||
|
@ -148,12 +157,13 @@ static int wifi_ap_enable(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
|
||||
if (off_api == NULL || off_api->ap_enable == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->ap_enable == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return off_api->ap_enable(dev, params);
|
||||
return wifi_mgmt_api->ap_enable(dev, params);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_ENABLE, wifi_ap_enable);
|
||||
|
@ -164,12 +174,13 @@ static int wifi_ap_disable(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
|
||||
if (off_api == NULL || off_api->ap_enable == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->ap_enable == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return off_api->ap_disable(dev);
|
||||
return wifi_mgmt_api->ap_disable(dev);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_AP_DISABLE, wifi_ap_disable);
|
||||
|
@ -180,9 +191,10 @@ static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct wifi_iface_status *status = data;
|
||||
|
||||
if (off_api == NULL || off_api->iface_status == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->iface_status == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -190,7 +202,7 @@ static int wifi_iface_status(uint32_t mgmt_request, struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return off_api->iface_status(dev, status);
|
||||
return wifi_mgmt_api->iface_status(dev, status);
|
||||
}
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_IFACE_STATUS, wifi_iface_status);
|
||||
|
||||
|
@ -209,9 +221,10 @@ static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct net_stats_wifi *stats = data;
|
||||
|
||||
if (off_api == NULL || off_api->get_stats == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->get_stats == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -219,7 +232,7 @@ static int wifi_iface_stats(uint32_t mgmt_request, struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return off_api->get_stats(dev, stats);
|
||||
return wifi_mgmt_api->get_stats(dev, stats);
|
||||
}
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI, wifi_iface_stats);
|
||||
#endif /* CONFIG_NET_STATISTICS_WIFI */
|
||||
|
@ -230,10 +243,11 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct wifi_ps_params *ps_params = data;
|
||||
struct wifi_iface_status info = { 0 };
|
||||
|
||||
if (off_api == NULL || off_api->set_power_save == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_power_save == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -263,7 +277,7 @@ static int wifi_set_power_save(uint32_t mgmt_request, struct net_if *iface,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return off_api->set_power_save(dev, ps_params);
|
||||
return wifi_mgmt_api->set_power_save(dev, ps_params);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS, wifi_set_power_save);
|
||||
|
@ -274,9 +288,10 @@ static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *ifac
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct wifi_ps_config *ps_config = data;
|
||||
|
||||
if (off_api == NULL || off_api->get_power_save_config == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->get_power_save_config == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -284,7 +299,7 @@ static int wifi_get_power_save_config(uint32_t mgmt_request, struct net_if *ifac
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return off_api->get_power_save_config(dev, ps_config);
|
||||
return wifi_mgmt_api->get_power_save_config(dev, ps_config);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_PS_CONFIG, wifi_get_power_save_config);
|
||||
|
@ -295,10 +310,11 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct wifi_twt_params *twt_params = data;
|
||||
struct wifi_iface_status info = { 0 };
|
||||
|
||||
if (off_api == NULL || off_api->set_twt == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->set_twt == NULL) {
|
||||
twt_params->fail_reason =
|
||||
WIFI_TWT_FAIL_OPERATION_NOT_SUPPORTED;
|
||||
return -ENOTSUP;
|
||||
|
@ -345,7 +361,7 @@ static int wifi_set_twt(uint32_t mgmt_request, struct net_if *iface,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
return off_api->set_twt(dev, twt_params);
|
||||
return wifi_mgmt_api->set_twt(dev, twt_params);
|
||||
fail:
|
||||
return -ENOEXEC;
|
||||
|
||||
|
@ -366,9 +382,10 @@ static int wifi_reg_domain(uint32_t mgmt_request, struct net_if *iface,
|
|||
const struct device *dev = net_if_get_device(iface);
|
||||
struct net_wifi_mgmt_offload *off_api =
|
||||
(struct net_wifi_mgmt_offload *) dev->api;
|
||||
const struct wifi_mgmt_ops *const wifi_mgmt_api = off_api ? off_api->wifi_mgmt_api : NULL;
|
||||
struct wifi_reg_domain *reg_domain = data;
|
||||
|
||||
if (off_api == NULL || off_api->reg_domain == NULL) {
|
||||
if (wifi_mgmt_api == NULL || wifi_mgmt_api->reg_domain == NULL) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
@ -376,7 +393,7 @@ static int wifi_reg_domain(uint32_t mgmt_request, struct net_if *iface,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
return off_api->reg_domain(dev, reg_domain);
|
||||
return wifi_mgmt_api->reg_domain(dev, reg_domain);
|
||||
}
|
||||
|
||||
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_REG_DOMAIN, wifi_reg_domain);
|
||||
|
|
Loading…
Reference in a new issue