Skip to content

Commit

Permalink
[nrf fromlist] net: wifi: Move Wi-Fi ops to a separate struct
Browse files Browse the repository at this point in the history
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).

Upstream-Pr: zephyrproject-rtos/zephyr#59249

Signed-off-by: Chaitanya Tata <Chaitanya.Tata@nordicsemi.no>
  • Loading branch information
krish2718 authored and nordicjm committed Jul 5, 2023
1 parent 7d0f172 commit f1d9984
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 72 deletions.
24 changes: 14 additions & 10 deletions drivers/wifi/esp32/src/esp_wifi_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -624,18 +624,22 @@ static int esp32_wifi_dev_init(const struct device *dev)
return 0;
}

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
};

static const struct net_wifi_mgmt_offload esp32_api = {
.wifi_iface.iface_api.init = esp32_wifi_init,
.wifi_iface.iface_api.init = esp32_wifi_init,
.wifi_iface.send = esp32_wifi_send,
#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,
.wifi_mgmt_api = &esp32_wifi_mgmt,
};

NET_DEVICE_DT_INST_DEFINE(0,
Expand Down
19 changes: 12 additions & 7 deletions drivers/wifi/esp_at/esp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1223,15 +1223,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);
Expand Down
18 changes: 11 additions & 7 deletions drivers/wifi/eswifi/eswifi_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions drivers/wifi/simplelink/simplelink.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 9 additions & 6 deletions drivers/wifi/winc1500/wifi_winc1500.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 16 additions & 13 deletions include/zephyr/net/wifi_mgmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand All @@ -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).
*/
Expand Down
Loading

0 comments on commit f1d9984

Please sign in to comment.