wifisim: Support the setting of the number of simulated WiFi interfaces.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
parent
f1a566f7f6
commit
e04aa9ac51
|
@ -745,4 +745,11 @@ config WIFI_SIM_CONFDIR
|
|||
BSS configuration will be accessed. This is a string and should not
|
||||
include any trailing '/'.
|
||||
|
||||
config WIFI_SIM_NUMBER
|
||||
int "Number of Simulated WiFi Device"
|
||||
default 0
|
||||
depends on DRIVERS_WIFI_SIM
|
||||
---help---
|
||||
The number of simulated wifi network devices.
|
||||
|
||||
endif # NETDEVICES
|
||||
|
|
|
@ -193,6 +193,10 @@ static const struct netdev_ops_s g_virtio_net_ops =
|
|||
virtio_net_txfree
|
||||
};
|
||||
|
||||
#ifdef CONFIG_DRIVERS_WIFI_SIM
|
||||
static uint8_t g_netdev_num = 0;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
@ -651,18 +655,27 @@ static int virtio_net_probe(FAR struct virtio_device *vdev)
|
|||
netdev->ops = &g_virtio_net_ops;
|
||||
|
||||
#ifdef CONFIG_DRIVERS_WIFI_SIM
|
||||
ret = wifi_sim_init(&priv->lower);
|
||||
if (ret < 0)
|
||||
/* If the WiFi interfaces has reached the setting value,
|
||||
* no more WiFi interfaces will be created.
|
||||
*/
|
||||
|
||||
if (g_netdev_num < CONFIG_WIFI_SIM_NUMBER)
|
||||
{
|
||||
goto err_with_virtqueues;
|
||||
ret = wifi_sim_init(&priv->lower);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto err_with_virtqueues;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Register the net deivce */
|
||||
|
||||
ret = netdev_lower_register(netdev,
|
||||
#ifdef CONFIG_DRIVERS_WIFI_SIM
|
||||
NET_LL_IEEE80211
|
||||
g_netdev_num++ < CONFIG_WIFI_SIM_NUMBER ?
|
||||
NET_LL_IEEE80211 : NET_LL_ETHERNET
|
||||
#else
|
||||
NET_LL_ETHERNET
|
||||
#endif
|
||||
|
@ -672,6 +685,7 @@ static int virtio_net_probe(FAR struct virtio_device *vdev)
|
|||
vrterr("netdev_lower_register failed, ret=%d\n", ret);
|
||||
#ifdef CONFIG_DRIVERS_WIFI_SIM
|
||||
wifi_sim_remove(&priv->lower);
|
||||
g_netdev_num--;
|
||||
#endif
|
||||
goto err_with_virtqueues;
|
||||
}
|
||||
|
@ -700,6 +714,7 @@ static void virtio_net_remove(FAR struct virtio_device *vdev)
|
|||
virtio_reset_device(vdev);
|
||||
virtio_delete_virtqueues(vdev);
|
||||
#ifdef CONFIG_DRIVERS_WIFI_SIM
|
||||
g_netdev_num--;
|
||||
wifi_sim_remove(&priv->lower);
|
||||
#endif
|
||||
kmm_free(priv);
|
||||
|
|
Loading…
Reference in New Issue