123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417 |
- #include <linux/string.h>
- #include <linux/socket.h>
- #include <linux/fs.h>
- #include <linux/seq_file.h>
- #include <linux/slab.h>
- #include <linux/export.h>
- #include <net/irda/irda.h>
- #include <net/irda/irlmp.h>
- #include <net/irda/discovery.h>
- #include <asm/unaligned.h>
- void irlmp_add_discovery(hashbin_t *cachelog, discovery_t *new)
- {
- discovery_t *discovery, *node;
- unsigned long flags;
-
- new->firststamp = new->timestamp;
- spin_lock_irqsave(&cachelog->hb_spinlock, flags);
-
- discovery = (discovery_t *) hashbin_get_first(cachelog);
- while (discovery != NULL ) {
- node = discovery;
-
- discovery = (discovery_t *) hashbin_get_next(cachelog);
- if ((node->data.saddr == new->data.saddr) &&
- ((node->data.daddr == new->data.daddr) ||
- (strcmp(node->data.info, new->data.info) == 0)))
- {
-
- hashbin_remove_this(cachelog, (irda_queue_t *) node);
-
- if (get_unaligned((__u16 *)node->data.hints) == get_unaligned((__u16 *)new->data.hints))
-
- new->firststamp = node->firststamp;
- kfree(node);
- }
- }
-
- hashbin_insert(cachelog, (irda_queue_t *) new, new->data.daddr, NULL);
- spin_unlock_irqrestore(&cachelog->hb_spinlock, flags);
- }
- void irlmp_add_discovery_log(hashbin_t *cachelog, hashbin_t *log)
- {
- discovery_t *discovery;
-
-
- if (log == NULL) {
-
- return;
- }
-
- discovery = (discovery_t *) hashbin_remove_first(log);
- while (discovery != NULL) {
- irlmp_add_discovery(cachelog, discovery);
- discovery = (discovery_t *) hashbin_remove_first(log);
- }
-
- hashbin_delete(log, (FREE_FUNC) kfree);
- }
- void irlmp_expire_discoveries(hashbin_t *log, __u32 saddr, int force)
- {
- discovery_t * discovery;
- discovery_t * curr;
- unsigned long flags;
- discinfo_t * buffer = NULL;
- int n;
- int i = 0;
- IRDA_ASSERT(log != NULL, return;);
- spin_lock_irqsave(&log->hb_spinlock, flags);
- discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
-
- curr = discovery;
- discovery = (discovery_t *) hashbin_get_next(log);
-
- if ((curr->data.saddr == saddr) &&
- (force ||
- ((jiffies - curr->timestamp) > DISCOVERY_EXPIRE_TIMEOUT)))
- {
-
- if(buffer == NULL) {
-
- n = HASHBIN_GET_SIZE(log);
- buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC);
- if (buffer == NULL) {
- spin_unlock_irqrestore(&log->hb_spinlock, flags);
- return;
- }
- }
-
- memcpy(&(buffer[i]), &(curr->data),
- sizeof(discinfo_t));
- i++;
-
- curr = hashbin_remove_this(log, (irda_queue_t *) curr);
- kfree(curr);
- }
- }
-
- spin_unlock_irqrestore(&log->hb_spinlock, flags);
- if(buffer == NULL)
- return;
-
- irlmp_discovery_expiry(buffer, i);
-
- kfree(buffer);
- }
- #if 0
- void irlmp_dump_discoveries(hashbin_t *log)
- {
- discovery_t *discovery;
- IRDA_ASSERT(log != NULL, return;);
- discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
- pr_debug("Discovery:\n");
- pr_debug(" daddr=%08x\n", discovery->data.daddr);
- pr_debug(" saddr=%08x\n", discovery->data.saddr);
- pr_debug(" nickname=%s\n", discovery->data.info);
- discovery = (discovery_t *) hashbin_get_next(log);
- }
- }
- #endif
- struct irda_device_info *irlmp_copy_discoveries(hashbin_t *log, int *pn,
- __u16 mask, int old_entries)
- {
- discovery_t * discovery;
- unsigned long flags;
- discinfo_t * buffer = NULL;
- int j_timeout = (sysctl_discovery_timeout * HZ);
- int n;
- int i = 0;
- IRDA_ASSERT(pn != NULL, return NULL;);
- IRDA_ASSERT(log != NULL, return NULL;);
-
- spin_lock_irqsave(&log->hb_spinlock, flags);
- discovery = (discovery_t *) hashbin_get_first(log);
- while (discovery != NULL) {
-
- if ((get_unaligned((__u16 *)discovery->data.hints) & mask) &&
- ((old_entries) ||
- ((jiffies - discovery->firststamp) < j_timeout))) {
-
- if(buffer == NULL) {
-
- n = HASHBIN_GET_SIZE(log);
- buffer = kmalloc(n * sizeof(struct irda_device_info), GFP_ATOMIC);
- if (buffer == NULL) {
- spin_unlock_irqrestore(&log->hb_spinlock, flags);
- return NULL;
- }
- }
-
- memcpy(&(buffer[i]), &(discovery->data),
- sizeof(discinfo_t));
- i++;
- }
- discovery = (discovery_t *) hashbin_get_next(log);
- }
- spin_unlock_irqrestore(&log->hb_spinlock, flags);
-
- *pn = i;
- return buffer;
- }
- #ifdef CONFIG_PROC_FS
- static inline discovery_t *discovery_seq_idx(loff_t pos)
- {
- discovery_t *discovery;
- for (discovery = (discovery_t *) hashbin_get_first(irlmp->cachelog);
- discovery != NULL;
- discovery = (discovery_t *) hashbin_get_next(irlmp->cachelog)) {
- if (pos-- == 0)
- break;
- }
- return discovery;
- }
- static void *discovery_seq_start(struct seq_file *seq, loff_t *pos)
- {
- spin_lock_irq(&irlmp->cachelog->hb_spinlock);
- return *pos ? discovery_seq_idx(*pos - 1) : SEQ_START_TOKEN;
- }
- static void *discovery_seq_next(struct seq_file *seq, void *v, loff_t *pos)
- {
- ++*pos;
- return (v == SEQ_START_TOKEN)
- ? (void *) hashbin_get_first(irlmp->cachelog)
- : (void *) hashbin_get_next(irlmp->cachelog);
- }
- static void discovery_seq_stop(struct seq_file *seq, void *v)
- {
- spin_unlock_irq(&irlmp->cachelog->hb_spinlock);
- }
- static int discovery_seq_show(struct seq_file *seq, void *v)
- {
- if (v == SEQ_START_TOKEN)
- seq_puts(seq, "IrLMP: Discovery log:\n\n");
- else {
- const discovery_t *discovery = v;
- seq_printf(seq, "nickname: %s, hint: 0x%02x%02x",
- discovery->data.info,
- discovery->data.hints[0],
- discovery->data.hints[1]);
- #if 0
- if ( discovery->data.hints[0] & HINT_PNP)
- seq_puts(seq, "PnP Compatible ");
- if ( discovery->data.hints[0] & HINT_PDA)
- seq_puts(seq, "PDA/Palmtop ");
- if ( discovery->data.hints[0] & HINT_COMPUTER)
- seq_puts(seq, "Computer ");
- if ( discovery->data.hints[0] & HINT_PRINTER)
- seq_puts(seq, "Printer ");
- if ( discovery->data.hints[0] & HINT_MODEM)
- seq_puts(seq, "Modem ");
- if ( discovery->data.hints[0] & HINT_FAX)
- seq_puts(seq, "Fax ");
- if ( discovery->data.hints[0] & HINT_LAN)
- seq_puts(seq, "LAN Access ");
- if ( discovery->data.hints[1] & HINT_TELEPHONY)
- seq_puts(seq, "Telephony ");
- if ( discovery->data.hints[1] & HINT_FILE_SERVER)
- seq_puts(seq, "File Server ");
- if ( discovery->data.hints[1] & HINT_COMM)
- seq_puts(seq, "IrCOMM ");
- if ( discovery->data.hints[1] & HINT_OBEX)
- seq_puts(seq, "IrOBEX ");
- #endif
- seq_printf(seq,", saddr: 0x%08x, daddr: 0x%08x\n\n",
- discovery->data.saddr,
- discovery->data.daddr);
- seq_putc(seq, '\n');
- }
- return 0;
- }
- static const struct seq_operations discovery_seq_ops = {
- .start = discovery_seq_start,
- .next = discovery_seq_next,
- .stop = discovery_seq_stop,
- .show = discovery_seq_show,
- };
- static int discovery_seq_open(struct inode *inode, struct file *file)
- {
- IRDA_ASSERT(irlmp != NULL, return -EINVAL;);
- return seq_open(file, &discovery_seq_ops);
- }
- const struct file_operations discovery_seq_fops = {
- .owner = THIS_MODULE,
- .open = discovery_seq_open,
- .read = seq_read,
- .llseek = seq_lseek,
- .release = seq_release,
- };
- #endif
|