Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /********************************************************************* |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 2 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Filename: discovery.c |
| 4 | * Version: 0.1 |
| 5 | * Description: Routines for handling discoveries at the IrLMP layer |
| 6 | * Status: Experimental. |
| 7 | * Author: Dag Brattli <dagb@cs.uit.no> |
| 8 | * Created at: Tue Apr 6 15:33:50 1999 |
| 9 | * Modified at: Sat Oct 9 17:11:31 1999 |
| 10 | * Modified by: Dag Brattli <dagb@cs.uit.no> |
| 11 | * Modified at: Fri May 28 3:11 CST 1999 |
| 12 | * Modified by: Horst von Brand <vonbrand@sleipnir.valparaiso.cl> |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Copyright (c) 1999 Dag Brattli, All Rights Reserved. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 15 | * |
| 16 | * This program is free software; you can redistribute it and/or |
| 17 | * modify it under the terms of the GNU General Public License as |
| 18 | * published by the Free Software Foundation; either version 2 of |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * the License, or (at your option) any later version. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 20 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | * MA 02111-1307 USA |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 30 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | ********************************************************************/ |
| 32 | |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/socket.h> |
Al Viro | d7fe0f2 | 2006-12-03 23:15:30 -0500 | [diff] [blame] | 35 | #include <linux/fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #include <linux/seq_file.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 37 | #include <linux/slab.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 38 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | #include <net/irda/irda.h> |
| 41 | #include <net/irda/irlmp.h> |
| 42 | |
| 43 | #include <net/irda/discovery.h> |
| 44 | |
Graf Yang | 3322238 | 2008-05-13 23:25:57 -0700 | [diff] [blame] | 45 | #include <asm/unaligned.h> |
| 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | /* |
| 48 | * Function irlmp_add_discovery (cachelog, discovery) |
| 49 | * |
| 50 | * Add a new discovery to the cachelog, and remove any old discoveries |
| 51 | * from the same device |
| 52 | * |
| 53 | * Note : we try to preserve the time this device was *first* discovered |
| 54 | * (as opposed to the time of last discovery used for cleanup). This is |
| 55 | * used by clients waiting for discovery events to tell if the device |
| 56 | * discovered is "new" or just the same old one. They can't rely there |
| 57 | * on a binary flag (new/old), because not all discovery events are |
| 58 | * propagated to them, and they might not always listen, so they would |
| 59 | * miss some new devices popping up... |
| 60 | * Jean II |
| 61 | */ |
| 62 | void irlmp_add_discovery(hashbin_t *cachelog, discovery_t *new) |
| 63 | { |
| 64 | discovery_t *discovery, *node; |
| 65 | unsigned long flags; |
| 66 | |
| 67 | /* Set time of first discovery if node is new (see below) */ |
| 68 | new->firststamp = new->timestamp; |
| 69 | |
| 70 | spin_lock_irqsave(&cachelog->hb_spinlock, flags); |
| 71 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 72 | /* |
| 73 | * Remove all discoveries of devices that has previously been |
| 74 | * discovered on the same link with the same name (info), or the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | * same daddr. We do this since some devices (mostly PDAs) change |
| 76 | * their device address between every discovery. |
| 77 | */ |
| 78 | discovery = (discovery_t *) hashbin_get_first(cachelog); |
| 79 | while (discovery != NULL ) { |
| 80 | node = discovery; |
| 81 | |
| 82 | /* Be sure to stay one item ahead */ |
| 83 | discovery = (discovery_t *) hashbin_get_next(cachelog); |
| 84 | |
| 85 | if ((node->data.saddr == new->data.saddr) && |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 86 | ((node->data.daddr == new->data.daddr) || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | (strcmp(node->data.info, new->data.info) == 0))) |
| 88 | { |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 89 | /* This discovery is a previous discovery |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * from the same device, so just remove it |
| 91 | */ |
| 92 | hashbin_remove_this(cachelog, (irda_queue_t *) node); |
| 93 | /* Check if hints bits are unchanged */ |
Graf Yang | 3322238 | 2008-05-13 23:25:57 -0700 | [diff] [blame] | 94 | if (get_unaligned((__u16 *)node->data.hints) == get_unaligned((__u16 *)new->data.hints)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | /* Set time of first discovery for this node */ |
| 96 | new->firststamp = node->firststamp; |
| 97 | kfree(node); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | /* Insert the new and updated version */ |
| 102 | hashbin_insert(cachelog, (irda_queue_t *) new, new->data.daddr, NULL); |
| 103 | |
| 104 | spin_unlock_irqrestore(&cachelog->hb_spinlock, flags); |
| 105 | } |
| 106 | |
| 107 | /* |
| 108 | * Function irlmp_add_discovery_log (cachelog, log) |
| 109 | * |
| 110 | * Merge a disovery log into the cachelog. |
| 111 | * |
| 112 | */ |
| 113 | void irlmp_add_discovery_log(hashbin_t *cachelog, hashbin_t *log) |
| 114 | { |
| 115 | discovery_t *discovery; |
| 116 | |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 117 | IRDA_DEBUG(4, "%s()\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
| 119 | /* |
| 120 | * If log is missing this means that IrLAP was unable to perform the |
| 121 | * discovery, so restart discovery again with just the half timeout |
| 122 | * of the normal one. |
| 123 | */ |
| 124 | /* Well... It means that there was nobody out there - Jean II */ |
| 125 | if (log == NULL) { |
| 126 | /* irlmp_start_discovery_timer(irlmp, 150); */ |
| 127 | return; |
| 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Locking : we are the only owner of this discovery log, so |
| 132 | * no need to lock it. |
| 133 | * We just need to lock the global log in irlmp_add_discovery(). |
| 134 | */ |
| 135 | discovery = (discovery_t *) hashbin_remove_first(log); |
| 136 | while (discovery != NULL) { |
| 137 | irlmp_add_discovery(cachelog, discovery); |
| 138 | |
| 139 | discovery = (discovery_t *) hashbin_remove_first(log); |
| 140 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | /* Delete the now empty log */ |
| 143 | hashbin_delete(log, (FREE_FUNC) kfree); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * Function irlmp_expire_discoveries (log, saddr, force) |
| 148 | * |
| 149 | * Go through all discoveries and expire all that has stayed too long |
| 150 | * |
| 151 | * Note : this assume that IrLAP won't change its saddr, which |
| 152 | * currently is a valid assumption... |
| 153 | */ |
| 154 | void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force) |
| 155 | { |
| 156 | discovery_t * discovery; |
| 157 | discovery_t * curr; |
| 158 | unsigned long flags; |
| 159 | discinfo_t * buffer = NULL; |
| 160 | int n; /* Size of the full log */ |
| 161 | int i = 0; /* How many we expired */ |
| 162 | |
| 163 | IRDA_ASSERT(log != NULL, return;); |
Harvey Harrison | 0dc4787 | 2008-03-05 20:47:47 -0800 | [diff] [blame] | 164 | IRDA_DEBUG(4, "%s()\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | |
| 166 | spin_lock_irqsave(&log->hb_spinlock, flags); |
| 167 | |
| 168 | discovery = (discovery_t *) hashbin_get_first(log); |
| 169 | while (discovery != NULL) { |
| 170 | /* Be sure to be one item ahead */ |
| 171 | curr = discovery; |
| 172 | discovery = (discovery_t *) hashbin_get_next(log); |
| 173 | |
| 174 | /* Test if it's time to expire this discovery */ |
| 175 | if ((curr->data.saddr == saddr) && |
| 176 | (force || |
| 177 | ((jiffies - curr->timestamp) > DISCOVERY_EXPIRE_TIMEOUT))) |
| 178 | { |
| 179 | /* Create buffer as needed. |
| 180 | * As this function get called a lot and most time |
| 181 | * we don't have anything to put in the log (we are |
| 182 | * quite picky), we can save a lot of overhead |
| 183 | * by not calling kmalloc. Jean II */ |
| 184 | if(buffer == NULL) { |
| 185 | /* Create the client specific buffer */ |
| 186 | n = HASHBIN_GET_SIZE(log); |
| 187 | buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC); |
| 188 | if (buffer == NULL) { |
| 189 | spin_unlock_irqrestore(&log->hb_spinlock, flags); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | } |
| 194 | |
| 195 | /* Copy discovery information */ |
| 196 | memcpy(&(buffer[i]), &(curr->data), |
| 197 | sizeof(discinfo_t)); |
| 198 | i++; |
| 199 | |
| 200 | /* Remove it from the log */ |
| 201 | curr = hashbin_remove_this(log, (irda_queue_t *) curr); |
Jesper Juhl | a51482b | 2005-11-08 09:41:34 -0800 | [diff] [blame] | 202 | kfree(curr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | } |
| 205 | |
| 206 | /* Drop the spinlock before calling the higher layers, as |
| 207 | * we can't guarantee they won't call us back and create a |
| 208 | * deadlock. We will work on our own private data, so we |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 209 | * don't care to be interrupted. - Jean II */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | spin_unlock_irqrestore(&log->hb_spinlock, flags); |
| 211 | |
| 212 | if(buffer == NULL) |
| 213 | return; |
| 214 | |
| 215 | /* Tell IrLMP and registered clients about it */ |
| 216 | irlmp_discovery_expiry(buffer, i); |
| 217 | |
| 218 | /* Free up our buffer */ |
| 219 | kfree(buffer); |
| 220 | } |
| 221 | |
| 222 | #if 0 |
| 223 | /* |
| 224 | * Function irlmp_dump_discoveries (log) |
| 225 | * |
| 226 | * Print out all discoveries in log |
| 227 | * |
| 228 | */ |
| 229 | void irlmp_dump_discoveries(hashbin_t *log) |
| 230 | { |
| 231 | discovery_t *discovery; |
| 232 | |
| 233 | IRDA_ASSERT(log != NULL, return;); |
| 234 | |
| 235 | discovery = (discovery_t *) hashbin_get_first(log); |
| 236 | while (discovery != NULL) { |
| 237 | IRDA_DEBUG(0, "Discovery:\n"); |
| 238 | IRDA_DEBUG(0, " daddr=%08x\n", discovery->data.daddr); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 239 | IRDA_DEBUG(0, " saddr=%08x\n", discovery->data.saddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | IRDA_DEBUG(0, " nickname=%s\n", discovery->data.info); |
| 241 | |
| 242 | discovery = (discovery_t *) hashbin_get_next(log); |
| 243 | } |
| 244 | } |
| 245 | #endif |
| 246 | |
| 247 | /* |
| 248 | * Function irlmp_copy_discoveries (log, pn, mask) |
| 249 | * |
| 250 | * Copy all discoveries in a buffer |
| 251 | * |
| 252 | * This function implement a safe way for lmp clients to access the |
| 253 | * discovery log. The basic problem is that we don't want the log |
| 254 | * to change (add/remove) while the client is reading it. If the |
| 255 | * lmp client manipulate directly the hashbin, he is sure to get |
| 256 | * into troubles... |
| 257 | * The idea is that we copy all the current discovery log in a buffer |
| 258 | * which is specific to the client and pass this copy to him. As we |
| 259 | * do this operation with the spinlock grabbed, we are safe... |
| 260 | * Note : we don't want those clients to grab the spinlock, because |
| 261 | * we have no control on how long they will hold it... |
| 262 | * Note : we choose to copy the log in "struct irda_device_info" to |
| 263 | * save space... |
| 264 | * Note : the client must kfree himself() the log... |
| 265 | * Jean II |
| 266 | */ |
| 267 | struct irda_device_info *irlmp_copy_discoveries(hashbin_t *log, int *pn, |
| 268 | __u16 mask, int old_entries) |
| 269 | { |
| 270 | discovery_t * discovery; |
| 271 | unsigned long flags; |
| 272 | discinfo_t * buffer = NULL; |
| 273 | int j_timeout = (sysctl_discovery_timeout * HZ); |
| 274 | int n; /* Size of the full log */ |
| 275 | int i = 0; /* How many we picked */ |
| 276 | |
| 277 | IRDA_ASSERT(pn != NULL, return NULL;); |
| 278 | IRDA_ASSERT(log != NULL, return NULL;); |
| 279 | |
| 280 | /* Save spin lock */ |
| 281 | spin_lock_irqsave(&log->hb_spinlock, flags); |
| 282 | |
| 283 | discovery = (discovery_t *) hashbin_get_first(log); |
| 284 | while (discovery != NULL) { |
| 285 | /* Mask out the ones we don't want : |
| 286 | * We want to match the discovery mask, and to get only |
| 287 | * the most recent one (unless we want old ones) */ |
Graf Yang | 3322238 | 2008-05-13 23:25:57 -0700 | [diff] [blame] | 288 | if ((get_unaligned((__u16 *)discovery->data.hints) & mask) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | ((old_entries) || |
Graf Yang | 3322238 | 2008-05-13 23:25:57 -0700 | [diff] [blame] | 290 | ((jiffies - discovery->firststamp) < j_timeout))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | /* Create buffer as needed. |
| 292 | * As this function get called a lot and most time |
| 293 | * we don't have anything to put in the log (we are |
| 294 | * quite picky), we can save a lot of overhead |
| 295 | * by not calling kmalloc. Jean II */ |
| 296 | if(buffer == NULL) { |
| 297 | /* Create the client specific buffer */ |
| 298 | n = HASHBIN_GET_SIZE(log); |
| 299 | buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC); |
| 300 | if (buffer == NULL) { |
| 301 | spin_unlock_irqrestore(&log->hb_spinlock, flags); |
| 302 | return NULL; |
| 303 | } |
| 304 | |
| 305 | } |
| 306 | |
| 307 | /* Copy discovery information */ |
| 308 | memcpy(&(buffer[i]), &(discovery->data), |
| 309 | sizeof(discinfo_t)); |
| 310 | i++; |
| 311 | } |
| 312 | discovery = (discovery_t *) hashbin_get_next(log); |
| 313 | } |
| 314 | |
| 315 | spin_unlock_irqrestore(&log->hb_spinlock, flags); |
| 316 | |
| 317 | /* Get the actual number of device in the buffer and return */ |
| 318 | *pn = i; |
Eric Dumazet | a02cec2 | 2010-09-22 20:43:57 +0000 | [diff] [blame] | 319 | return buffer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } |
| 321 | |
| 322 | #ifdef CONFIG_PROC_FS |
| 323 | static inline discovery_t *discovery_seq_idx(loff_t pos) |
| 324 | |
| 325 | { |
| 326 | discovery_t *discovery; |
| 327 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 328 | for (discovery = (discovery_t *) hashbin_get_first(irlmp->cachelog); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | discovery != NULL; |
| 330 | discovery = (discovery_t *) hashbin_get_next(irlmp->cachelog)) { |
| 331 | if (pos-- == 0) |
| 332 | break; |
| 333 | } |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 334 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | return discovery; |
| 336 | } |
| 337 | |
| 338 | static void *discovery_seq_start(struct seq_file *seq, loff_t *pos) |
| 339 | { |
| 340 | spin_lock_irq(&irlmp->cachelog->hb_spinlock); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 341 | return *pos ? discovery_seq_idx(*pos - 1) : SEQ_START_TOKEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static void *discovery_seq_next(struct seq_file *seq, void *v, loff_t *pos) |
| 345 | { |
| 346 | ++*pos; |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 347 | return (v == SEQ_START_TOKEN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | ? (void *) hashbin_get_first(irlmp->cachelog) |
| 349 | : (void *) hashbin_get_next(irlmp->cachelog); |
| 350 | } |
| 351 | |
| 352 | static void discovery_seq_stop(struct seq_file *seq, void *v) |
| 353 | { |
| 354 | spin_unlock_irq(&irlmp->cachelog->hb_spinlock); |
| 355 | } |
| 356 | |
| 357 | static int discovery_seq_show(struct seq_file *seq, void *v) |
| 358 | { |
| 359 | if (v == SEQ_START_TOKEN) |
| 360 | seq_puts(seq, "IrLMP: Discovery log:\n\n"); |
| 361 | else { |
| 362 | const discovery_t *discovery = v; |
| 363 | |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 364 | seq_printf(seq, "nickname: %s, hint: 0x%02x%02x", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | discovery->data.info, |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 366 | discovery->data.hints[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | discovery->data.hints[1]); |
| 368 | #if 0 |
| 369 | if ( discovery->data.hints[0] & HINT_PNP) |
| 370 | seq_puts(seq, "PnP Compatible "); |
| 371 | if ( discovery->data.hints[0] & HINT_PDA) |
| 372 | seq_puts(seq, "PDA/Palmtop "); |
| 373 | if ( discovery->data.hints[0] & HINT_COMPUTER) |
| 374 | seq_puts(seq, "Computer "); |
| 375 | if ( discovery->data.hints[0] & HINT_PRINTER) |
| 376 | seq_puts(seq, "Printer "); |
| 377 | if ( discovery->data.hints[0] & HINT_MODEM) |
| 378 | seq_puts(seq, "Modem "); |
| 379 | if ( discovery->data.hints[0] & HINT_FAX) |
| 380 | seq_puts(seq, "Fax "); |
| 381 | if ( discovery->data.hints[0] & HINT_LAN) |
| 382 | seq_puts(seq, "LAN Access "); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | if ( discovery->data.hints[1] & HINT_TELEPHONY) |
| 385 | seq_puts(seq, "Telephony "); |
| 386 | if ( discovery->data.hints[1] & HINT_FILE_SERVER) |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 387 | seq_puts(seq, "File Server "); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | if ( discovery->data.hints[1] & HINT_COMM) |
| 389 | seq_puts(seq, "IrCOMM "); |
| 390 | if ( discovery->data.hints[1] & HINT_OBEX) |
| 391 | seq_puts(seq, "IrOBEX "); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 392 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | seq_printf(seq,", saddr: 0x%08x, daddr: 0x%08x\n\n", |
| 394 | discovery->data.saddr, |
| 395 | discovery->data.daddr); |
YOSHIFUJI Hideaki | 6819bc2 | 2007-02-09 23:24:53 +0900 | [diff] [blame] | 396 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | seq_putc(seq, '\n'); |
| 398 | } |
| 399 | return 0; |
| 400 | } |
| 401 | |
Philippe De Muyter | 56b3d97 | 2007-07-10 23:07:31 -0700 | [diff] [blame] | 402 | static const struct seq_operations discovery_seq_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | .start = discovery_seq_start, |
| 404 | .next = discovery_seq_next, |
| 405 | .stop = discovery_seq_stop, |
| 406 | .show = discovery_seq_show, |
| 407 | }; |
| 408 | |
| 409 | static int discovery_seq_open(struct inode *inode, struct file *file) |
| 410 | { |
| 411 | IRDA_ASSERT(irlmp != NULL, return -EINVAL;); |
| 412 | |
| 413 | return seq_open(file, &discovery_seq_ops); |
| 414 | } |
| 415 | |
Arjan van de Ven | 9a32144 | 2007-02-12 00:55:35 -0800 | [diff] [blame] | 416 | const struct file_operations discovery_seq_fops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | .owner = THIS_MODULE, |
| 418 | .open = discovery_seq_open, |
| 419 | .read = seq_read, |
| 420 | .llseek = seq_lseek, |
| 421 | .release = seq_release, |
| 422 | }; |
| 423 | #endif |