Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | /********************************************************************* * * Filename: irproc.c * Version: * Description: Various entries in the /proc file system * Status: Experimental. * Author: Thomas Davis, <ratbert@radiks.net> * Created at: Sat Feb 21 21:33:24 1998 * Modified at: Thu Feb 11 15:23:23 1999 * Modified by: Dag Brattli <dagb@cs.uit.no> * * Copyright (c) 1998, Thomas Davis, <ratbert@radiks.net>, * All Rights Reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or (at your option) any later version. * * I, Thomas Davis, provide no warranty for any of this software. * This material is provided "AS-IS" and at no charge. * * Portions lifted from the linux/fs/procfs/ files. * ********************************************************************/ #include <linux/miscdevice.h> #include <linux/proc_fs.h> #include <net/irda/irmod.h> #include <net/irda/irlap.h> #include <net/irda/irlmp.h> static int proc_irda_lookup(struct inode * dir, struct dentry *dentry); static int proc_irda_readdir(struct file *filp, void *dirent, filldir_t filldir); extern int irda_device_proc_read(char *buf, char **start, off_t offset, int len, int unused); extern int irlap_proc_read(char *buf, char **start, off_t offset, int len, int unused); extern int irlmp_proc_read(char *buf, char **start, off_t offset, int len, int unused); extern int irttp_proc_read(char *buf, char **start, off_t offset, int len, int unused); extern int irias_proc_read(char *buf, char **start, off_t offset, int len, int unused); static int proc_discovery_read(char *buf, char **start, off_t offset, int len, int unused); enum irda_directory_inos { PROC_IRDA_LAP = 1, PROC_IRDA_LMP, PROC_IRDA_TTP, PROC_IRDA_LPT, PROC_IRDA_COMM, PROC_IRDA_IRDA_DEVICE, PROC_IRDA_IRIAS }; static struct file_operations proc_irda_dir_operations = { NULL, /* lseek - default */ NULL, /* read - bad */ NULL, /* write - bad */ proc_irda_readdir, /* readdir */ NULL, /* select - default */ NULL, /* ioctl - default */ NULL, /* mmap */ NULL, /* no special open code */ NULL, /* no special release code */ NULL /* can't fsync */ }; /* * proc directories can do almost nothing.. */ struct inode_operations proc_irda_dir_inode_operations = { &proc_irda_dir_operations, /* default net directory file-ops */ NULL, /* create */ proc_irda_lookup, NULL, /* link */ NULL, /* unlink */ NULL, /* symlink */ NULL, /* mkdir */ NULL, /* rmdir */ NULL, /* mknod */ NULL, /* rename */ NULL, /* readlink */ NULL, /* follow_link */ NULL, /* readpage */ NULL, /* writepage */ NULL, /* bmap */ NULL, /* truncate */ NULL /* permission */ }; struct proc_dir_entry proc_irda = { 0, 4, "irda", S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0, 0, &proc_irda_dir_inode_operations, NULL, NULL, NULL, NULL, NULL }; #if 0 struct proc_dir_entry proc_lpt = { 0, 3, "lpt", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &irlpt_proc_read /* get_info */, }; #endif struct proc_dir_entry proc_discovery = { 0, 9, "discovery", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &proc_discovery_read /* get_info */, }; struct proc_dir_entry proc_irda_device = { 0, 11, "irda_device", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL, &irda_device_proc_read, }; struct proc_dir_entry proc_ttp = { 0, 5, "irttp", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &irttp_proc_read /* get_info */, }; struct proc_dir_entry proc_lmp = { 0, 5, "irlmp", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &irlmp_proc_read /* get_info */, }; struct proc_dir_entry proc_lap = { 0, 5, "irlap", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &irlap_proc_read /* get_info */, }; struct proc_dir_entry proc_ias = { 0, 5, "irias", S_IFREG | S_IRUGO, 1, 0, 0, 0, NULL /* ops -- default to array */, &irias_proc_read /* get_info */, }; /* * Function proc_delete_dentry (dentry) * * Copy of proc/root.c because this function is invisible to the irda * module * */ static void proc_delete_dentry(struct dentry * dentry) { d_drop(dentry); } static struct dentry_operations proc_dentry_operations = { NULL, /* revalidate */ NULL, /* d_hash */ NULL, /* d_compare */ proc_delete_dentry /* d_delete(struct dentry *) */ }; /* * Function irda_proc_register (void) * * Register irda entry in /proc file system * */ void irda_proc_register(void) { proc_net_register(&proc_irda); proc_irda.fill_inode = &irda_proc_modcount; proc_register(&proc_irda, &proc_lap); proc_register(&proc_irda, &proc_lmp); proc_register(&proc_irda, &proc_ttp); proc_register(&proc_irda, &proc_ias); proc_register(&proc_irda, &proc_irda_device); proc_register(&proc_irda, &proc_discovery); } /* * Function irda_proc_unregister (void) * * Unregister irda entry in /proc file system * */ void irda_proc_unregister(void) { proc_unregister(&proc_irda, proc_discovery.low_ino); proc_unregister(&proc_irda, proc_irda_device.low_ino); proc_unregister(&proc_irda, proc_ias.low_ino); proc_unregister(&proc_irda, proc_ttp.low_ino); proc_unregister(&proc_irda, proc_lmp.low_ino); proc_unregister(&proc_irda, proc_lap.low_ino); proc_unregister(proc_net, proc_irda.low_ino); } /* * Function proc_irda_lookup (dir, dentry) * * This is a copy of proc_lookup from the linux-2.2.x kernel * */ int proc_irda_lookup(struct inode * dir, struct dentry *dentry) { struct inode *inode; struct proc_dir_entry * de; int error; error = -ENOTDIR; if (!dir || !S_ISDIR(dir->i_mode)) goto out; error = -ENOENT; inode = NULL; de = (struct proc_dir_entry *) dir->u.generic_ip; if (de) { for (de = de->subdir; de ; de = de->next) { if (!de || !de->low_ino) continue; if (de->namelen != dentry->d_name.len) continue; if (!memcmp(dentry->d_name.name, de->name, de->namelen)) { int ino = de->low_ino | (dir->i_ino & ~(0xffff)); error = -EINVAL; inode = proc_get_inode(dir->i_sb, ino, de); break; } } } if (inode) { dentry->d_op = &proc_dentry_operations; d_add(dentry, inode); error = 0; } out: return error; } /* * Function proc_irda_readdir (filp, dirent, filldir) * * This is a copy from linux/fs/proc because the function is invisible * to the irda module * */ static int proc_irda_readdir(struct file *filp, void *dirent, filldir_t filldir) { struct proc_dir_entry * de; unsigned int ino; int i; struct inode *inode = filp->f_dentry->d_inode; if (!inode || !S_ISDIR(inode->i_mode)) return -ENOTDIR; ino = inode->i_ino; de = (struct proc_dir_entry *) inode->u.generic_ip; if (!de) return -EINVAL; i = filp->f_pos; switch (i) { case 0: if (filldir(dirent, ".", 1, i, ino) < 0) return 0; i++; filp->f_pos++; /* fall through */ case 1: if (filldir(dirent, "..", 2, i, de->parent->low_ino) < 0) return 0; i++; filp->f_pos++; /* fall through */ default: ino &= ~0xffff; de = de->subdir; i -= 2; for (;;) { if (!de) return 1; if (!i) break; de = de->next; i--; } do { if (filldir(dirent, de->name, de->namelen, filp->f_pos, ino | de->low_ino) < 0) return 0; filp->f_pos++; de = de->next; } while (de); } return 1; } /* * Function proc_discovery_read (buf, start, offset, len, unused) * * Print discovery information in /proc file system * */ int proc_discovery_read(char *buf, char **start, off_t offset, int len, int unused) { DISCOVERY *discovery; struct lap_cb *lap; unsigned long flags; if ( !irlmp) return len; len = sprintf(buf, "IrLMP: Discovery log:\n\n"); save_flags(flags); cli(); lap = ( struct lap_cb *) hashbin_get_first( irlmp->links); while( lap != NULL) { ASSERT( lap->magic == LMP_LAP_MAGIC, return 0;); len += sprintf( buf+len, "Link saddr=0x%08x\n", lap->saddr); discovery = ( DISCOVERY *) hashbin_get_first( lap->cachelog); while ( discovery != NULL) { len += sprintf( buf+len, " name: %s,", discovery->info); len += sprintf( buf+len, " hint: "); if ( discovery->hint[0] & HINT_PNP) len += sprintf( buf+len, "PnP Compatible "); if ( discovery->hint[0] & HINT_PDA) len += sprintf( buf+len, "PDA/Palmtop "); if ( discovery->hint[0] & HINT_COMPUTER) len += sprintf( buf+len, "Computer "); if ( discovery->hint[0] & HINT_PRINTER) len += sprintf( buf+len, "Printer "); if ( discovery->hint[0] & HINT_MODEM) len += sprintf( buf+len, "Modem "); if ( discovery->hint[0] & HINT_FAX) len += sprintf( buf+len, "Fax "); if ( discovery->hint[0] & HINT_LAN) len += sprintf( buf+len, "LAN Access"); if ( discovery->hint[1] & HINT_TELEPHONY) len += sprintf( buf+len, "Telephony "); if ( discovery->hint[1] & HINT_FILE_SERVER) len += sprintf( buf+len, "File Server "); if ( discovery->hint[1] & HINT_COMM) len += sprintf( buf+len, "IrCOMM "); if ( discovery->hint[1] & HINT_OBEX) len += sprintf( buf+len, "IrOBEX "); len += sprintf( buf+len, ", daddr: 0x%08x\n", discovery->daddr); len += sprintf( buf+len, "\n"); discovery = ( DISCOVERY *) hashbin_get_next( lap->cachelog); } lap = ( struct lap_cb *) hashbin_get_next( irlmp->links); } restore_flags(flags); return len; } |