1 /* 2 * Copyright (c) 2017-2018, 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 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef _WLAN_HDD_SYSFS_H_ 21 #define _WLAN_HDD_SYSFS_H_ 22 23 /** 24 * struct hdd_sysfs_print_ctx - keeps track of sysfs buffer printing 25 * @buf: pointer to sysfs char buffer 26 * @idx: current position in char buffer 27 * @new_line: if set true, newline will be added at end of each print 28 */ 29 struct hdd_sysfs_print_ctx { 30 char *buf; 31 int idx; 32 bool new_line; 33 }; 34 35 #ifdef WLAN_SYSFS 36 37 #define MAX_SYSFS_USER_COMMAND_SIZE_LENGTH (32) 38 #define MAX_CMD_INPUT (512) 39 40 /** 41 * hdd_sysfs_validate_and_copy_buf() - validate sysfs input buf and copy into 42 * destination buffer 43 * @dest_buf: pointer to destination buffer where data should be copied 44 * @dest_buf_size: size of destination buffer 45 * @src_buf: pointer to constant sysfs source buffer 46 * @src_buf_size: size of source buffer 47 * 48 * Return: 0 for success and error code for failure 49 */ 50 int 51 hdd_sysfs_validate_and_copy_buf(char *dest_buf, size_t dest_buf_size, 52 char const *src_buf, size_t src_buf_size); 53 54 /** 55 * hdd_create_sysfs_files() - create sysfs files 56 * @hdd_ctx: pointer to hdd context 57 * 58 * Return: none 59 */ 60 void hdd_create_sysfs_files(struct hdd_context *hdd_ctx); 61 62 /** 63 * hdd_destroy_sysfs_files() - destroy sysfs files 64 * 65 * Return: none 66 */ 67 void hdd_destroy_sysfs_files(void); 68 69 /** 70 * hdd_create_adapter_sysfs_files - create adapter sysfs files 71 * @adapter: pointer to adapter 72 * 73 * Return: none 74 */ 75 void hdd_create_adapter_sysfs_files(struct hdd_adapter *adapter); 76 77 /** 78 * hdd_destroy_adapter_sysfs_files - destroy adapter sysfs files 79 * @adapter: pointer to adapter 80 * 81 * Return: none 82 */ 83 void hdd_destroy_adapter_sysfs_files(struct hdd_adapter *adapter); 84 85 /** 86 * hdd_create_wifi_feature_interface_sysfs_file - Create wifi feature interface 87 * sysfs file 88 * 89 * Return: none 90 */ 91 void hdd_create_wifi_feature_interface_sysfs_file(void); 92 93 /** 94 * hdd_destroy_wifi_feature_interface_sysfs_file - Destroy wifi feature 95 * interface sysfs file 96 * 97 * Return: none 98 */ 99 void hdd_destroy_wifi_feature_interface_sysfs_file(void); 100 101 /** 102 * hdd_sysfs_create_wifi_root_obj() - create wifi root kobj 103 * 104 * Return: none 105 */ 106 void hdd_sysfs_create_wifi_root_obj(void); 107 108 /** 109 * hdd_sysfs_destroy_wifi_root_obj() - Destroy wifi root kobj 110 * 111 * Return: none 112 */ 113 void hdd_sysfs_destroy_wifi_root_obj(void); 114 115 /* 116 * hdd_sysfs_print() - print to sysfs char buffer 117 * @ctx: pointer to struct hdd_sysfs_print_ctx 118 * @fmt: string format 119 * 120 * To use this function, create a hdd_sysfs_print_ctx variable, set 121 * idx to 0, set buf to the outbuffer and set new_line to true or false. 122 * Pass this context struct to every function call. 123 * Using this function will then write the data to the outbuffer and 124 * increment the counter. 125 * 126 * The context pointer is void to be compatible with qdf_abstract_print, 127 * to allow for abstract printing. 128 * 129 * Return: Number of characters written 130 */ 131 int hdd_sysfs_print(void *ctx, const char *fmt, ...); 132 133 #else 134 static inline int hdd_sysfs_validate_and_copy_buf(char * dest_buf,size_t dest_buf_size,char const * src_buf,size_t src_buf_size)135 hdd_sysfs_validate_and_copy_buf(char *dest_buf, size_t dest_buf_size, 136 char const *src_buf, size_t src_buf_size) 137 { 138 return -EPERM; 139 } 140 hdd_create_sysfs_files(struct hdd_context * hdd_ctx)141 static inline void hdd_create_sysfs_files(struct hdd_context *hdd_ctx) 142 { 143 } 144 hdd_destroy_sysfs_files(void)145 static inline void hdd_destroy_sysfs_files(void) 146 { 147 } 148 hdd_create_adapter_sysfs_files(struct hdd_adapter * adapter)149 static inline void hdd_create_adapter_sysfs_files(struct hdd_adapter *adapter) 150 { 151 } 152 hdd_destroy_adapter_sysfs_files(struct hdd_adapter * adapter)153 static inline void hdd_destroy_adapter_sysfs_files(struct hdd_adapter *adapter) 154 { 155 } 156 hdd_create_wifi_feature_interface_sysfs_file(void)157 static inline void hdd_create_wifi_feature_interface_sysfs_file(void) 158 { 159 } 160 hdd_destroy_wifi_feature_interface_sysfs_file(void)161 static inline void hdd_destroy_wifi_feature_interface_sysfs_file(void) 162 { 163 } 164 hdd_sysfs_create_wifi_root_obj(void)165 static inline void hdd_sysfs_create_wifi_root_obj(void) 166 { 167 } 168 hdd_sysfs_destroy_wifi_root_obj(void)169 static inline void hdd_sysfs_destroy_wifi_root_obj(void) 170 { 171 } 172 173 #endif /* End of WLAN SYSFS*/ 174 175 #endif /* End of _WLAN_HDD_SYSFS_H_ */ 176