From 59a4e4b2b7ecb167b9736cbf38fccc7720b2a10a Mon Sep 17 00:00:00 2001 From: armink Date: Fri, 18 Jan 2019 20:41:39 +0800 Subject: [PATCH] [DeviceDriver][wlan] Add device ops to wlan. --- components/drivers/wlan/wlan_dev.c | 19 ++++++++++++++++++- components/drivers/wlan/wlan_lwip.c | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/components/drivers/wlan/wlan_dev.c b/components/drivers/wlan/wlan_dev.c index 0beac52aae..eac1d0f975 100644 --- a/components/drivers/wlan/wlan_dev.c +++ b/components/drivers/wlan/wlan_dev.c @@ -754,6 +754,18 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args) return err; } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops wlan_ops = +{ + _rt_wlan_dev_init, + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + _rt_wlan_dev_control +}; +#endif + rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, const struct rt_wlan_dev_ops *ops, rt_uint32_t flag, void *user_data) { rt_err_t err = RT_EOK; @@ -765,13 +777,18 @@ rt_err_t rt_wlan_dev_register(struct rt_wlan_device *wlan, const char *name, con } rt_memset(wlan, 0, sizeof(struct rt_wlan_device)); - + +#ifdef RT_USING_DEVICE_OPS + wlan->device.ops = &wlan_ops; +#else wlan->device.init = _rt_wlan_dev_init; wlan->device.open = RT_NULL; wlan->device.close = RT_NULL; wlan->device.read = RT_NULL; wlan->device.write = RT_NULL; wlan->device.control = _rt_wlan_dev_control; +#endif + wlan->device.user_data = RT_NULL; wlan->device.type = RT_Device_Class_NetIf; diff --git a/components/drivers/wlan/wlan_lwip.c b/components/drivers/wlan/wlan_lwip.c index ec6ca23845..2f8bcefd0d 100644 --- a/components/drivers/wlan/wlan_lwip.c +++ b/components/drivers/wlan/wlan_lwip.c @@ -372,6 +372,18 @@ static rt_err_t rt_wlan_lwip_protocol_send(rt_device_t device, struct pbuf *p) #endif } +#ifdef RT_USING_DEVICE_OPS +const static struct rt_device_ops wlan_lwip_ops = +{ + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + RT_NULL, + rt_wlan_lwip_protocol_control +}; +#endif + static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot *prot, struct rt_wlan_device *wlan) { struct eth_device *eth = RT_NULL; @@ -417,12 +429,18 @@ static struct rt_wlan_prot *rt_wlan_lwip_protocol_register(struct rt_wlan_prot * rt_memset(lwip_prot, 0, sizeof(struct lwip_prot_des)); eth = &lwip_prot->eth; + +#ifdef RT_USING_DEVICE_OPS + eth->parent.ops = &wlan_lwip_ops; +#else eth->parent.init = RT_NULL; eth->parent.open = RT_NULL; eth->parent.close = RT_NULL; eth->parent.read = RT_NULL; eth->parent.write = RT_NULL; eth->parent.control = rt_wlan_lwip_protocol_control; +#endif + eth->parent.user_data = wlan; eth->eth_rx = RT_NULL; eth->eth_tx = rt_wlan_lwip_protocol_send;