1 // SPDX-License-Identifier: GPL-2.0 2 /* /proc routines for Host AP driver */ 3 4 #include <linux/types.h> 5 #include <linux/proc_fs.h> 6 #include <linux/export.h> 7 #include <net/lib80211.h> 8 9 #include "hostap_wlan.h" 10 #include "hostap.h" 11 12 #define PROC_LIMIT (PAGE_SIZE - 80) 13 14 15 #ifndef PRISM2_NO_PROCFS_DEBUG 16 static int prism2_debug_proc_show(struct seq_file *m, void *v) 17 { 18 local_info_t *local = m->private; 19 int i; 20 21 seq_printf(m, "next_txfid=%d next_alloc=%d\n", 22 local->next_txfid, local->next_alloc); 23 for (i = 0; i < PRISM2_TXFID_COUNT; i++) 24 seq_printf(m, "FID: tx=%04X intransmit=%04X\n", 25 local->txfid[i], local->intransmitfid[i]); 26 seq_printf(m, "FW TX rate control: %d\n", local->fw_tx_rate_control); 27 seq_printf(m, "beacon_int=%d\n", local->beacon_int); 28 seq_printf(m, "dtim_period=%d\n", local->dtim_period); 29 seq_printf(m, "wds_max_connections=%d\n", local->wds_max_connections); 30 seq_printf(m, "dev_enabled=%d\n", local->dev_enabled); 31 seq_printf(m, "sw_tick_stuck=%d\n", local->sw_tick_stuck); 32 for (i = 0; i < WEP_KEYS; i++) { 33 if (local->crypt_info.crypt[i] && 34 local->crypt_info.crypt[i]->ops) { 35 seq_printf(m, "crypt[%d]=%s\n", i, 36 local->crypt_info.crypt[i]->ops->name); 37 } 38 } 39 seq_printf(m, "pri_only=%d\n", local->pri_only); 40 seq_printf(m, "pci=%d\n", local->func->hw_type == HOSTAP_HW_PCI); 41 seq_printf(m, "sram_type=%d\n", local->sram_type); 42 seq_printf(m, "no_pri=%d\n", local->no_pri); 43 44 return 0; 45 } 46 #endif /* PRISM2_NO_PROCFS_DEBUG */ 47 48 49 static int prism2_stats_proc_show(struct seq_file *m, void *v) 50 { 51 local_info_t *local = m->private; 52 struct comm_tallies_sums *sums = &local->comm_tallies; 53 54 seq_printf(m, "TxUnicastFrames=%u\n", sums->tx_unicast_frames); 55 seq_printf(m, "TxMulticastframes=%u\n", sums->tx_multicast_frames); 56 seq_printf(m, "TxFragments=%u\n", sums->tx_fragments); 57 seq_printf(m, "TxUnicastOctets=%u\n", sums->tx_unicast_octets); 58 seq_printf(m, "TxMulticastOctets=%u\n", sums->tx_multicast_octets); 59 seq_printf(m, "TxDeferredTransmissions=%u\n", 60 sums->tx_deferred_transmissions); 61 seq_printf(m, "TxSingleRetryFrames=%u\n", sums->tx_single_retry_frames); 62 seq_printf(m, "TxMultipleRetryFrames=%u\n", 63 sums->tx_multiple_retry_frames); 64 seq_printf(m, "TxRetryLimitExceeded=%u\n", 65 sums->tx_retry_limit_exceeded); 66 seq_printf(m, "TxDiscards=%u\n", sums->tx_discards); 67 seq_printf(m, "RxUnicastFrames=%u\n", sums->rx_unicast_frames); 68 seq_printf(m, "RxMulticastFrames=%u\n", sums->rx_multicast_frames); 69 seq_printf(m, "RxFragments=%u\n", sums->rx_fragments); 70 seq_printf(m, "RxUnicastOctets=%u\n", sums->rx_unicast_octets); 71 seq_printf(m, "RxMulticastOctets=%u\n", sums->rx_multicast_octets); 72 seq_printf(m, "RxFCSErrors=%u\n", sums->rx_fcs_errors); 73 seq_printf(m, "RxDiscardsNoBuffer=%u\n", sums->rx_discards_no_buffer); 74 seq_printf(m, "TxDiscardsWrongSA=%u\n", sums->tx_discards_wrong_sa); 75 seq_printf(m, "RxDiscardsWEPUndecryptable=%u\n", 76 sums->rx_discards_wep_undecryptable); 77 seq_printf(m, "RxMessageInMsgFragments=%u\n", 78 sums->rx_message_in_msg_fragments); 79 seq_printf(m, "RxMessageInBadMsgFragments=%u\n", 80 sums->rx_message_in_bad_msg_fragments); 81 /* FIX: this may grow too long for one page(?) */ 82 83 return 0; 84 } 85 86 static int prism2_wds_proc_show(struct seq_file *m, void *v) 87 { 88 struct list_head *ptr = v; 89 struct hostap_interface *iface; 90 91 iface = list_entry(ptr, struct hostap_interface, list); 92 if (iface->type == HOSTAP_INTERFACE_WDS) 93 seq_printf(m, "%s\t%pM\n", 94 iface->dev->name, iface->u.wds.remote_addr); 95 return 0; 96 } 97 98 static void *prism2_wds_proc_start(struct seq_file *m, loff_t *_pos) 99 { 100 local_info_t *local = PDE_DATA(file_inode(m->file)); 101 read_lock_bh(&local->iface_lock); 102 return seq_list_start(&local->hostap_interfaces, *_pos); 103 } 104 105 static void *prism2_wds_proc_next(struct seq_file *m, void *v, loff_t *_pos) 106 { 107 local_info_t *local = PDE_DATA(file_inode(m->file)); 108 return seq_list_next(v, &local->hostap_interfaces, _pos); 109 } 110 111 static void prism2_wds_proc_stop(struct seq_file *m, void *v) 112 { 113 local_info_t *local = PDE_DATA(file_inode(m->file)); 114 read_unlock_bh(&local->iface_lock); 115 } 116 117 static const struct seq_operations prism2_wds_proc_seqops = { 118 .start = prism2_wds_proc_start, 119 .next = prism2_wds_proc_next, 120 .stop = prism2_wds_proc_stop, 121 .show = prism2_wds_proc_show, 122 }; 123 124 static int prism2_bss_list_proc_show(struct seq_file *m, void *v) 125 { 126 local_info_t *local = PDE_DATA(file_inode(m->file)); 127 struct list_head *ptr = v; 128 struct hostap_bss_info *bss; 129 130 if (ptr == &local->bss_list) { 131 seq_printf(m, "#BSSID\tlast_update\tcount\tcapab_info\tSSID(txt)\t" 132 "SSID(hex)\tWPA IE\n"); 133 return 0; 134 } 135 136 bss = list_entry(ptr, struct hostap_bss_info, list); 137 seq_printf(m, "%pM\t%lu\t%u\t0x%x\t", 138 bss->bssid, bss->last_update, 139 bss->count, bss->capab_info); 140 141 seq_printf(m, "%*pE", (int)bss->ssid_len, bss->ssid); 142 143 seq_putc(m, '\t'); 144 seq_printf(m, "%*phN", (int)bss->ssid_len, bss->ssid); 145 seq_putc(m, '\t'); 146 seq_printf(m, "%*phN", (int)bss->wpa_ie_len, bss->wpa_ie); 147 seq_putc(m, '\n'); 148 return 0; 149 } 150 151 static void *prism2_bss_list_proc_start(struct seq_file *m, loff_t *_pos) 152 { 153 local_info_t *local = PDE_DATA(file_inode(m->file)); 154 spin_lock_bh(&local->lock); 155 return seq_list_start_head(&local->bss_list, *_pos); 156 } 157 158 static void *prism2_bss_list_proc_next(struct seq_file *m, void *v, loff_t *_pos) 159 { 160 local_info_t *local = PDE_DATA(file_inode(m->file)); 161 return seq_list_next(v, &local->bss_list, _pos); 162 } 163 164 static void prism2_bss_list_proc_stop(struct seq_file *m, void *v) 165 { 166 local_info_t *local = PDE_DATA(file_inode(m->file)); 167 spin_unlock_bh(&local->lock); 168 } 169 170 static const struct seq_operations prism2_bss_list_proc_seqops = { 171 .start = prism2_bss_list_proc_start, 172 .next = prism2_bss_list_proc_next, 173 .stop = prism2_bss_list_proc_stop, 174 .show = prism2_bss_list_proc_show, 175 }; 176 177 static int prism2_crypt_proc_show(struct seq_file *m, void *v) 178 { 179 local_info_t *local = m->private; 180 int i; 181 182 seq_printf(m, "tx_keyidx=%d\n", local->crypt_info.tx_keyidx); 183 for (i = 0; i < WEP_KEYS; i++) { 184 if (local->crypt_info.crypt[i] && 185 local->crypt_info.crypt[i]->ops && 186 local->crypt_info.crypt[i]->ops->print_stats) { 187 local->crypt_info.crypt[i]->ops->print_stats( 188 m, local->crypt_info.crypt[i]->priv); 189 } 190 } 191 return 0; 192 } 193 194 static ssize_t prism2_pda_proc_read(struct file *file, char __user *buf, 195 size_t count, loff_t *_pos) 196 { 197 local_info_t *local = PDE_DATA(file_inode(file)); 198 size_t off; 199 200 if (local->pda == NULL || *_pos >= PRISM2_PDA_SIZE) 201 return 0; 202 203 off = *_pos; 204 if (count > PRISM2_PDA_SIZE - off) 205 count = PRISM2_PDA_SIZE - off; 206 if (copy_to_user(buf, local->pda + off, count) != 0) 207 return -EFAULT; 208 *_pos += count; 209 return count; 210 } 211 212 static const struct file_operations prism2_pda_proc_fops = { 213 .read = prism2_pda_proc_read, 214 .llseek = generic_file_llseek, 215 }; 216 217 218 static ssize_t prism2_aux_dump_proc_no_read(struct file *file, char __user *buf, 219 size_t bufsize, loff_t *_pos) 220 { 221 return 0; 222 } 223 224 static const struct file_operations prism2_aux_dump_proc_fops = { 225 .read = prism2_aux_dump_proc_no_read, 226 }; 227 228 229 #ifdef PRISM2_IO_DEBUG 230 static int prism2_io_debug_proc_read(char *page, char **start, off_t off, 231 int count, int *eof, void *data) 232 { 233 local_info_t *local = (local_info_t *) data; 234 int head = local->io_debug_head; 235 int start_bytes, left, copy, copied; 236 237 if (off + count > PRISM2_IO_DEBUG_SIZE * 4) { 238 *eof = 1; 239 if (off >= PRISM2_IO_DEBUG_SIZE * 4) 240 return 0; 241 count = PRISM2_IO_DEBUG_SIZE * 4 - off; 242 } 243 244 copied = 0; 245 start_bytes = (PRISM2_IO_DEBUG_SIZE - head) * 4; 246 left = count; 247 248 if (off < start_bytes) { 249 copy = start_bytes - off; 250 if (copy > count) 251 copy = count; 252 memcpy(page, ((u8 *) &local->io_debug[head]) + off, copy); 253 left -= copy; 254 if (left > 0) 255 memcpy(&page[copy], local->io_debug, left); 256 } else { 257 memcpy(page, ((u8 *) local->io_debug) + (off - start_bytes), 258 left); 259 } 260 261 *start = page; 262 263 return count; 264 } 265 #endif /* PRISM2_IO_DEBUG */ 266 267 268 #ifndef PRISM2_NO_STATION_MODES 269 static int prism2_scan_results_proc_show(struct seq_file *m, void *v) 270 { 271 local_info_t *local = PDE_DATA(file_inode(m->file)); 272 unsigned long entry; 273 int i, len; 274 struct hfa384x_hostscan_result *scanres; 275 u8 *p; 276 277 if (v == SEQ_START_TOKEN) { 278 seq_printf(m, 279 "CHID ANL SL BcnInt Capab Rate BSSID ATIM SupRates SSID\n"); 280 return 0; 281 } 282 283 entry = (unsigned long)v - 2; 284 scanres = &local->last_scan_results[entry]; 285 286 seq_printf(m, "%d %d %d %d 0x%02x %d %pM %d ", 287 le16_to_cpu(scanres->chid), 288 (s16) le16_to_cpu(scanres->anl), 289 (s16) le16_to_cpu(scanres->sl), 290 le16_to_cpu(scanres->beacon_interval), 291 le16_to_cpu(scanres->capability), 292 le16_to_cpu(scanres->rate), 293 scanres->bssid, 294 le16_to_cpu(scanres->atim)); 295 296 p = scanres->sup_rates; 297 for (i = 0; i < sizeof(scanres->sup_rates); i++) { 298 if (p[i] == 0) 299 break; 300 seq_printf(m, "<%02x>", p[i]); 301 } 302 seq_putc(m, ' '); 303 304 p = scanres->ssid; 305 len = le16_to_cpu(scanres->ssid_len); 306 if (len > 32) 307 len = 32; 308 for (i = 0; i < len; i++) { 309 unsigned char c = p[i]; 310 if (c >= 32 && c < 127) 311 seq_putc(m, c); 312 else 313 seq_printf(m, "<%02x>", c); 314 } 315 seq_putc(m, '\n'); 316 return 0; 317 } 318 319 static void *prism2_scan_results_proc_start(struct seq_file *m, loff_t *_pos) 320 { 321 local_info_t *local = PDE_DATA(file_inode(m->file)); 322 spin_lock_bh(&local->lock); 323 324 /* We have a header (pos 0) + N results to show (pos 1...N) */ 325 if (*_pos > local->last_scan_results_count) 326 return NULL; 327 return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */ 328 } 329 330 static void *prism2_scan_results_proc_next(struct seq_file *m, void *v, loff_t *_pos) 331 { 332 local_info_t *local = PDE_DATA(file_inode(m->file)); 333 334 ++*_pos; 335 if (*_pos > local->last_scan_results_count) 336 return NULL; 337 return (void *)(unsigned long)(*_pos + 1); /* 0 would be EOF */ 338 } 339 340 static void prism2_scan_results_proc_stop(struct seq_file *m, void *v) 341 { 342 local_info_t *local = PDE_DATA(file_inode(m->file)); 343 spin_unlock_bh(&local->lock); 344 } 345 346 static const struct seq_operations prism2_scan_results_proc_seqops = { 347 .start = prism2_scan_results_proc_start, 348 .next = prism2_scan_results_proc_next, 349 .stop = prism2_scan_results_proc_stop, 350 .show = prism2_scan_results_proc_show, 351 }; 352 #endif /* PRISM2_NO_STATION_MODES */ 353 354 355 void hostap_init_proc(local_info_t *local) 356 { 357 local->proc = NULL; 358 359 if (hostap_proc == NULL) { 360 printk(KERN_WARNING "%s: hostap proc directory not created\n", 361 local->dev->name); 362 return; 363 } 364 365 local->proc = proc_mkdir(local->ddev->name, hostap_proc); 366 if (local->proc == NULL) { 367 printk(KERN_INFO "/proc/net/hostap/%s creation failed\n", 368 local->ddev->name); 369 return; 370 } 371 372 #ifndef PRISM2_NO_PROCFS_DEBUG 373 proc_create_single_data("debug", 0, local->proc, 374 prism2_debug_proc_show, local); 375 #endif /* PRISM2_NO_PROCFS_DEBUG */ 376 proc_create_single_data("stats", 0, local->proc, prism2_stats_proc_show, 377 local); 378 proc_create_seq_data("wds", 0, local->proc, 379 &prism2_wds_proc_seqops, local); 380 proc_create_data("pda", 0, local->proc, 381 &prism2_pda_proc_fops, local); 382 proc_create_data("aux_dump", 0, local->proc, 383 local->func->read_aux_fops ?: &prism2_aux_dump_proc_fops, 384 local); 385 proc_create_seq_data("bss_list", 0, local->proc, 386 &prism2_bss_list_proc_seqops, local); 387 proc_create_single_data("crypt", 0, local->proc, prism2_crypt_proc_show, 388 local); 389 #ifdef PRISM2_IO_DEBUG 390 proc_create_single_data("io_debug", 0, local->proc, 391 prism2_debug_proc_show, local); 392 #endif /* PRISM2_IO_DEBUG */ 393 #ifndef PRISM2_NO_STATION_MODES 394 proc_create_seq_data("scan_results", 0, local->proc, 395 &prism2_scan_results_proc_seqops, local); 396 #endif /* PRISM2_NO_STATION_MODES */ 397 } 398 399 400 void hostap_remove_proc(local_info_t *local) 401 { 402 proc_remove(local->proc); 403 } 404 405 406 EXPORT_SYMBOL(hostap_init_proc); 407 EXPORT_SYMBOL(hostap_remove_proc); 408