1 /*
2 * Copyright (c) 2011-2020 The Linux Foundation. All rights reserved.
3 * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 /**
19 * DOC: wlan_hdd_sysfs_wowl_del_ptrn.c
20 *
21 * implementation for creating sysfs file wowl_del_ptrn
22 */
23
24 #include <wlan_hdd_includes.h>
25 #include <wlan_hdd_sysfs.h>
26 #include "osif_vdev_sync.h"
27 #include "wlan_hdd_wowl.h"
28 #include <wlan_hdd_sysfs_wowl_del_ptrn.h>
29
30 static ssize_t
__hdd_sysfs_wowl_del_ptrn_store(struct net_device * net_dev,char const * buf,size_t count)31 __hdd_sysfs_wowl_del_ptrn_store(struct net_device *net_dev,
32 char const *buf,
33 size_t count)
34 {
35 struct hdd_adapter *adapter = netdev_priv(net_dev);
36 struct hdd_context *hdd_ctx;
37 char *buf_local = NULL;
38 int ret;
39
40 if (hdd_validate_adapter(adapter))
41 return -EINVAL;
42
43 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
44 ret = wlan_hdd_validate_context(hdd_ctx);
45 if (ret)
46 return ret;
47
48 if (!wlan_hdd_validate_modules_state(hdd_ctx))
49 return -EINVAL;
50
51 if (count > MAX_CMD_INPUT)
52 return -EINVAL;
53
54 buf_local = (char *)qdf_mem_malloc(sizeof(char) * count);
55 if (!buf_local)
56 return -EINVAL;
57
58 strlcpy(buf_local, buf, count);
59
60 buf_local[count - 1] = '\0';
61
62 hdd_debug("wowl_del_ptrn: count %zu buf_local:(%s)",
63 count, buf_local);
64
65 if (!hdd_del_wowl_ptrn(adapter, buf_local)) {
66 hdd_err_rl("Failed to delete wowl ptrn");
67 qdf_mem_free(buf_local);
68 return -EINVAL;
69 }
70
71 qdf_mem_free(buf_local);
72 return count;
73 }
74
75 static ssize_t
hdd_sysfs_wowl_del_ptrn_store(struct device * dev,struct device_attribute * attr,char const * buf,size_t count)76 hdd_sysfs_wowl_del_ptrn_store(struct device *dev,
77 struct device_attribute *attr,
78 char const *buf, size_t count)
79 {
80 struct net_device *net_dev = container_of(dev, struct net_device, dev);
81 struct osif_vdev_sync *vdev_sync;
82 ssize_t err_size;
83
84 err_size = osif_vdev_sync_op_start(net_dev, &vdev_sync);
85 if (err_size)
86 return err_size;
87
88 err_size = __hdd_sysfs_wowl_del_ptrn_store(net_dev, buf, count);
89
90 osif_vdev_sync_op_stop(vdev_sync);
91
92 return err_size;
93 }
94
95 static DEVICE_ATTR(wowl_del_ptrn, 0220,
96 NULL, hdd_sysfs_wowl_del_ptrn_store);
97
hdd_sysfs_wowl_del_ptrn_create(struct hdd_adapter * adapter)98 int hdd_sysfs_wowl_del_ptrn_create(struct hdd_adapter *adapter)
99 {
100 int error;
101
102 error = device_create_file(&adapter->dev->dev,
103 &dev_attr_wowl_del_ptrn);
104 if (error)
105 hdd_err("could not create wowl_del_ptrn sysfs file");
106
107 return error;
108 }
109
hdd_sysfs_wowl_del_ptrn_destroy(struct hdd_adapter * adapter)110 void hdd_sysfs_wowl_del_ptrn_destroy(struct hdd_adapter *adapter)
111 {
112 device_remove_file(&adapter->dev->dev, &dev_attr_wowl_del_ptrn);
113 }
114