1  /*
2   * Copyright (c) 2011-2020, The Linux Foundation. All rights reserved.
3   *
4   * Permission to use, copy, modify, and/or distribute this software for any
5   * purpose with or without fee is hereby granted, provided that the above
6   * copyright notice and this permission notice appear in all copies.
7   *
8   * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9   * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10   * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11   * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12   * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13   * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14   * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15   */
16  
17  #include <wlan_hdd_main.h>
18  #include <wlan_hdd_sysfs.h>
19  #include <wlan_hdd_sysfs_pkt_log.h>
20  #include "osif_sync.h"
21  
22  #define MAX_USER_COMMAND_SIZE_PKT_LOG_CMD 4
23  
__hdd_sysfs_pkt_log_cmd_store(struct hdd_context * hdd_ctx,const char * buf,size_t count)24  static ssize_t __hdd_sysfs_pkt_log_cmd_store(struct hdd_context *hdd_ctx,
25  					     const char *buf, size_t count)
26  {
27  	char buf_local[MAX_USER_COMMAND_SIZE_PKT_LOG_CMD + 1];
28  	char *sptr, *token;
29  	uint32_t val1, val2;
30  	int ret;
31  
32  	hdd_enter();
33  
34  	if (!wlan_hdd_validate_modules_state(hdd_ctx))
35  		return -EINVAL;
36  
37  	ret = hdd_sysfs_validate_and_copy_buf(buf_local, sizeof(buf_local),
38  					      buf, count);
39  	if (ret)
40  		return -EINVAL;
41  
42  	sptr = buf_local;
43  	/* Get val1 */
44  	token = strsep(&sptr, " ");
45  	if (!token)
46  		return -EINVAL;
47  	if (kstrtou32(token, 0, &val1))
48  		return -EINVAL;
49  
50  	sptr = buf_local;
51  	/* Get val2 */
52  	token = strsep(&sptr, " ");
53  	if (!token)
54  		return -EINVAL;
55  	if (kstrtou32(token, 0, &val2))
56  		return -EINVAL;
57  
58  	ret = hdd_process_pktlog_command(hdd_ctx, val1, val2);
59  
60  	hdd_exit();
61  	return count;
62  }
63  
hdd_sysfs_pkt_log_cmd_store(struct kobject * kobj,struct kobj_attribute * attr,const char * buf,size_t count)64  static ssize_t hdd_sysfs_pkt_log_cmd_store(struct kobject *kobj,
65  					   struct kobj_attribute *attr,
66  					   const char *buf,
67  					   size_t count)
68  {
69  	struct osif_psoc_sync *psoc_sync;
70  	struct hdd_context *hdd_ctx = cds_get_context(QDF_MODULE_ID_HDD);
71  	ssize_t err_size;
72  
73  	if (wlan_hdd_validate_context(hdd_ctx))
74  		return 0;
75  
76  	err_size = osif_psoc_sync_op_start(wiphy_dev(hdd_ctx->wiphy),
77  					   &psoc_sync);
78  	if (err_size)
79  		return err_size;
80  
81  	err_size = __hdd_sysfs_pkt_log_cmd_store(hdd_ctx, buf, count);
82  
83  	osif_psoc_sync_op_stop(psoc_sync);
84  	return err_size;
85  }
86  
87  static struct kobj_attribute pktlog_attribute =
88  	__ATTR(pktlog, 0220, NULL,
89  	       hdd_sysfs_pkt_log_cmd_store);
90  
hdd_sysfs_pktlog_create(struct kobject * driver_kobject)91  void hdd_sysfs_pktlog_create(struct kobject *driver_kobject)
92  {
93  	if (sysfs_create_file(driver_kobject, &pktlog_attribute.attr))
94  		hdd_err("Failed to create pktlog sysfs entry");
95  }
96  
hdd_sysfs_pktlog_destroy(struct kobject * driver_kobject)97  void hdd_sysfs_pktlog_destroy(struct kobject *driver_kobject)
98  {
99  	sysfs_remove_file(driver_kobject, &pktlog_attribute.attr);
100  }
101