1  /*
2   * Copyright (c) 2023 Qualcomm Innovation Center, Inc. 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_includes.h>
18  #include "osif_psoc_sync.h"
19  #include <wlan_hdd_sysfs.h>
20  #include <wlan_hdd_sysfs_log_buffer.h>
21  #include <wlan_hdd_ioctl.h>
22  
hdd_sysfs_log_buffer_show(struct kobject * kobj,struct kobj_attribute * attr,char * buf)23  static ssize_t hdd_sysfs_log_buffer_show(struct kobject *kobj,
24  					 struct kobj_attribute *attr,
25  					 char *buf)
26  {
27  	struct hdd_sysfs_print_ctx ctx;
28  
29  	ctx.buf = buf;
30  	ctx.idx = 0;
31  	ctx.new_line = true;
32  	hdd_dump_log_buffer(&ctx, &hdd_sysfs_print);
33  	return ctx.idx;
34  }
35  
36  static struct kobj_attribute log_buffer_attribute =
37  	__ATTR(log_buffer, 0440, hdd_sysfs_log_buffer_show,
38  	       NULL);
39  
hdd_sysfs_log_buffer_create(struct kobject * driver_kobject)40  int hdd_sysfs_log_buffer_create(struct kobject *driver_kobject)
41  {
42  	int error;
43  
44  	if (!driver_kobject) {
45  		hdd_err("could not get driver kobject!");
46  		return -EINVAL;
47  	}
48  
49  	error = sysfs_create_file(driver_kobject,
50  				  &log_buffer_attribute.attr);
51  	if (error)
52  		hdd_err("could not create log_buffer sysfs file");
53  
54  	return error;
55  }
56  
57  void
hdd_sysfs_log_buffer_destroy(struct kobject * driver_kobject)58  hdd_sysfs_log_buffer_destroy(struct kobject *driver_kobject)
59  {
60  	if (!driver_kobject) {
61  		hdd_err("could not get driver kobject!");
62  		return;
63  	}
64  	sysfs_remove_file(driver_kobject, &log_buffer_attribute.attr);
65  }
66