Linux Audio

Check our new training course

Embedded Linux Audio

Check our new training course
with Creative Commons CC-BY-SA
lecture materials

Bootlin logo

Elixir Cross Referencer

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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
/* net/atm/proc.c - ATM /proc interface */

/* Written 1995-1999 by Werner Almesberger, EPFL LRC/ICA */

/*
 * The mechanism used here isn't designed for speed but rather for convenience
 * of implementation. We only return one entry per read system call, so we can
 * be reasonably sure not to overrun the page and race conditions may lead to
 * the addition or omission of some lines but never to any corruption of a
 * line's internal structure.
 *
 * Making the whole thing slightly more efficient is left as an exercise to the
 * reader. (Suggestions: wrapper which loops to get several entries per system
 * call; or make --left slightly more clever to avoid O(n^2) characteristics.)
 * I find it fast enough on my unloaded 266 MHz Pentium 2 :-)
 */


#include <linux/config.h>
#include <linux/module.h> /* for EXPORT_SYMBOL */
#include <linux/string.h>
#include <linux/types.h>
#include <linux/mm.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/proc_fs.h>
#include <linux/errno.h>
#include <linux/atm.h>
#include <linux/atmdev.h>
#include <linux/netdevice.h>
#include <linux/atmclip.h>
#include <linux/atmarp.h>
#include <linux/if_arp.h>
#include <linux/init.h> /* for __init */
#include <asm/uaccess.h>
#include <asm/param.h> /* for HZ */
#include "resources.h"
#include "common.h" /* atm_proc_init prototype */
#include "signaling.h" /* to get sigd - ugly too */

#ifdef CONFIG_ATM_CLIP
#include <net/atmclip.h>
#include "ipcommon.h"
extern void clip_push(struct atm_vcc *vcc,struct sk_buff *skb);
#endif

#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
#include "lec.h"
#include "lec_arpc.h"
extern struct atm_lane_ops atm_lane_ops; /* in common.c */
#endif


static ssize_t proc_atm_read(struct file *file,char *buf,size_t count,
    loff_t *pos);


static struct file_operations proc_atm_operations = {
	NULL,			/* lseek */
	proc_atm_read,		/* read */
	NULL,			/* write */
	NULL,			/* readdir */
	NULL,			/* select */
	NULL,			/* ioctl */
	NULL,			/* mmap */
	NULL,			/* no special open code */
	NULL,			/* no special release */
	NULL			/* can't fsync */
};

struct inode_operations proc_atm_inode_operations = {
	&proc_atm_operations,	/* default ATM directory file-ops */
	NULL,			/* create */
	NULL,			/* 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 */
};


#define ENTRY(name) static struct proc_dir_entry atm_proc_entry_##name = \
    { 0, sizeof(#name)-1, #name, S_IFREG | S_IRUGO, 1, 0, 0, 0, \
    &proc_atm_inode_operations, NULL }
#define REG(name) if (!error) error = proc_register(&atm_proc_root, \
    &atm_proc_entry_##name)
#define INO(name) (atm_proc_entry_##name.low_ino)


ENTRY(devices);
ENTRY(pvc);
ENTRY(svc);
#ifdef CONFIG_ATM_CLIP
ENTRY(arp);
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
ENTRY(lec);
#endif


static int atm_header(ino_t ino,char *buf)
{
	if (ino == INO(devices))
		return sprintf(buf,"Itf Type    ESI/\"MAC\"addr "
		    "AAL(TX,err,RX,err,drop) ...\n");
	if (ino == INO(pvc))
		return sprintf(buf,"Itf VPI VCI   AAL RX(PCR,Class) "
		    "TX(PCR,Class)\n");
	if (ino == INO(svc))
		return sprintf(buf,"Itf VPI VCI   State      Remote\n");
#ifdef CONFIG_ATM_CLIP
	if (ino == INO(arp))
		return sprintf(buf,"IPitf TypeEncp Idle IP address      "
		    "ATM address\n");
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
	if (ino == INO(lec))
		return sprintf(buf,"Itf  MAC          ATM destination"
		    "                          Status            Flags "
		    "VPI/VCI Recv VPI/VCI\n");
#endif
	return -EINVAL;
}


static void add_stats(char *buf,const char *aal,
  const struct atm_aal_stats *stats)
{
	sprintf(strchr(buf,0),"%s ( %ld %ld %ld %ld %ld )",aal,stats->tx,
	    stats->tx_err,stats->rx,stats->rx_err,stats->rx_drop);
}


static void dev_info(const struct atm_dev *dev,char *buf)
{
	int off,i;

	off = sprintf(buf,"%3d %-8s",dev->number,dev->type);
	for (i = 0; i < ESI_LEN; i++)
		off += sprintf(buf+off,"%02x",dev->esi[i]);
	strcat(buf,"  ");
	add_stats(buf,"0",&dev->stats.aal0);
	strcat(buf,"  ");
	add_stats(buf,"5",&dev->stats.aal5);
	strcat(buf,"\n");
}


#ifdef CONFIG_ATM_CLIP


static int svc_addr(char *buf,struct sockaddr_atmsvc *addr)
{
	static int code[] = { 1,2,10,6,1,0 };
	static int e164[] = { 1,8,4,6,1,0 };
	int *fields;
	int len,i,j,pos;

	len = 0;
	if (*addr->sas_addr.pub) {
		strcpy(buf,addr->sas_addr.pub);
		len = strlen(addr->sas_addr.pub);
		buf += len;
		if (*addr->sas_addr.pub) {
			*buf += '+';
			len++;
		}
	}
	else if (!*addr->sas_addr.prv) {
			strcpy(buf,"(none)");
			return strlen(buf);
		}
	if (*addr->sas_addr.prv) {
		len += 44;
		pos = 0;
		fields = *addr->sas_addr.prv == ATM_AFI_E164 ? e164 : code;
		for (i = 0; fields[i]; i++) {
			for (j = fields[i]; j; j--) {
				sprintf(buf,"%02X",addr->sas_addr.prv[pos++]);
				buf += 2;
			}
			if (fields[i+1]) *buf++ = '.';
		}
	}
	return len;
}


static void atmarp_info(struct net_device *dev,struct atmarp_entry *entry,
    struct clip_vcc *clip_vcc,char *buf)
{
	unsigned char *ip;
	int svc,off,ip_len;

	svc = !clip_vcc || clip_vcc->vcc->family == AF_ATMSVC;
	off = sprintf(buf,"%-6s%-4s%-4s%5ld ",dev->name,svc ? "SVC" : "PVC",
	    !clip_vcc || clip_vcc->encap ? "LLC" : "NULL",
	    (jiffies-(clip_vcc ? clip_vcc->last_use : entry->neigh->used))/
	    HZ);
	ip = (unsigned char *) &entry->ip;
	ip_len = sprintf(buf+off,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);
	off += ip_len;
	while (ip_len++ < 16) buf[off++] = ' ';
	if (!clip_vcc)
		if (time_before(jiffies, entry->expires))
			strcpy(buf+off,"(resolving)\n");
		else sprintf(buf+off,"(expired, ref %d)\n",
			    atomic_read(&entry->neigh->refcnt));
	else if (!svc)
			sprintf(buf+off,"%d.%d.%d\n",clip_vcc->vcc->dev->number,
			    clip_vcc->vcc->vpi,clip_vcc->vcc->vci);
		else {
			off += svc_addr(buf+off,&clip_vcc->vcc->remote);
			strcpy(buf+off,"\n");
		}
}


#endif


static void pvc_info(struct atm_vcc *vcc,char *buf)
{
	static const char *class_name[] = { "off","UBR","CBR","VBR","ABR" };
	static const char *aal_name[] = {
		"---",	"1",	"2",	"3/4",	/*  0- 3 */
		"???",	"5",	"???",	"???",	/*  4- 7 */
		"???",	"???",	"???",	"???",	/*  8-11 */
		"???",	"0",	"???",	"???"};	/* 12-15 */
	int off;

	off = sprintf(buf,"%3d %3d %5d %-3s %7d %-5s %7d %-6s",
	    vcc->dev->number,vcc->vpi,vcc->vci,
	    vcc->qos.aal >= sizeof(aal_name)/sizeof(aal_name[0]) ? "err" :
	    aal_name[vcc->qos.aal],vcc->qos.rxtp.min_pcr,
	    class_name[vcc->qos.rxtp.traffic_class],vcc->qos.txtp.min_pcr,
	    class_name[vcc->qos.txtp.traffic_class]);
#ifdef CONFIG_ATM_CLIP
	if (vcc->push == clip_push) {
		struct clip_vcc *clip_vcc = CLIP_VCC(vcc);
		struct net_device *dev;

		dev = clip_vcc->entry ? clip_vcc->entry->neigh->dev : NULL;
		off += sprintf(buf+off,"CLIP, Itf:%s, Encap:",
		    dev ? dev->name : "none?");
		if (clip_vcc->encap) off += sprintf(buf+off,"LLC/SNAP");
		else off += sprintf(buf+off,"None");
	}
#endif
	strcpy(buf+off,"\n");
}


static const char *vcc_state(struct atm_vcc *vcc)
{
	static const char *map[] = { ATM_VS2TXT_MAP };

	return map[ATM_VF2VS(vcc->flags)];
}


static void svc_info(struct atm_vcc *vcc,char *buf)
{
	char *here;
	int i;

	if (!vcc->dev) sprintf(buf,"Unassigned    ");
	else sprintf(buf,"%3d %3d %5d ",vcc->dev->number,vcc->vpi,vcc->vci);
	here = strchr(buf,0);
	here += sprintf(here,"%-10s ",vcc_state(vcc));
	here += sprintf(here,"%s%s",vcc->remote.sas_addr.pub,
	    *vcc->remote.sas_addr.pub && *vcc->remote.sas_addr.prv ? "+" : "");
	if (*vcc->remote.sas_addr.prv)
		for (i = 0; i < ATM_ESA_LEN; i++)
			here += sprintf(here,"%02x",
			    vcc->remote.sas_addr.prv[i]);
	strcat(here,"\n");
}


#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)

static char*
lec_arp_get_status_string(unsigned char status)
{
  switch(status) {
  case ESI_UNKNOWN:
    return "ESI_UNKNOWN       ";
  case ESI_ARP_PENDING:
    return "ESI_ARP_PENDING   ";
  case ESI_VC_PENDING:
    return "ESI_VC_PENDING    ";
  case ESI_FLUSH_PENDING:
    return "ESI_FLUSH_PENDING ";
  case ESI_FORWARD_DIRECT:
    return "ESI_FORWARD_DIRECT";
  default:
    return "<Unknown>         ";
  }
}

static void 
lec_info(struct lec_arp_table *entry, char *buf)
{
        int j, offset=0;
        

        for(j=0;j<ETH_ALEN;j++) {
                offset+=sprintf(buf+offset,"%2.2x",0xff&entry->mac_addr[j]);
        }
        offset+=sprintf(buf+offset, " ");
        for(j=0;j<ATM_ESA_LEN;j++) {
                offset+=sprintf(buf+offset,"%2.2x",0xff&entry->atm_addr[j]);
        }
        offset+=sprintf(buf+offset, " %s %4.4x",
                        lec_arp_get_status_string(entry->status),
                        entry->flags&0xffff);
        if (entry->vcc) {
                offset+=sprintf(buf+offset, "%3d %3d ", entry->vcc->vpi, 
                                entry->vcc->vci);                
        } else
                offset+=sprintf(buf+offset, "        ");
        if (entry->recv_vcc) {
                offset+=sprintf(buf+offset, "     %3d %3d", 
                                entry->recv_vcc->vpi, entry->recv_vcc->vci);
        }

        sprintf(buf+offset,"\n");
}

#endif


/*
 * FIXME: it isn't safe to walk the VCC list without turning off interrupts.
 * What is really needed is some lock on the devices. Ditto for ATMARP.
 */

static int atm_info(ino_t ino,loff_t *pos,char *buf)
{
	struct atm_dev *dev;
	struct atm_vcc *vcc;
	int left;

	if (ino == INO(devices)) {
		left = *pos-1;
		for (dev = atm_devs; dev && left; dev = dev->next) left--;
		if (!dev) return 0;
		dev_info(dev,buf);
		return strlen(buf);
	}
	if (ino == INO(pvc)) {
		left = *pos-1;
		for (dev = atm_devs; dev; dev = dev->next)
			for (vcc = dev->vccs; vcc; vcc = vcc->next)
				if (vcc->family == PF_ATMPVC &&
				    vcc->dev && !left--) {
					pvc_info(vcc,buf);
					return strlen(buf);
				}
		return 0;
	}
	if (ino == INO(svc)) {
		left = *pos-1;
		for (dev = atm_devs; dev; dev = dev->next)
			for (vcc = dev->vccs; vcc; vcc = vcc->next)
				if (vcc->family == PF_ATMSVC && !left--) {
					svc_info(vcc,buf);
					return strlen(buf);
				}
		for (vcc = nodev_vccs; vcc; vcc = vcc->next)
			if (vcc->family == PF_ATMSVC && !left--) {
				svc_info(vcc,buf);
				return strlen(buf);
			}
		return 0;
	}
#ifdef CONFIG_ATM_CLIP
	if (ino == INO(arp)) {
		struct neighbour *n;
		int i,count;

		count = *pos;
		read_lock_bh(&clip_tbl.lock);
		for (i = 0; i <= NEIGH_HASHMASK; i++)
			for (n = clip_tbl.hash_buckets[i]; n; n = n->next) {
				struct atmarp_entry *entry = NEIGH2ENTRY(n);
				struct clip_vcc *vcc;

				if (!entry->vccs) {
					if (--count) continue;
					atmarp_info(n->dev,entry,NULL,buf);
					read_unlock_bh(&clip_tbl.lock);
					return strlen(buf);
				}
				for (vcc = entry->vccs; vcc;
				    vcc = vcc->next) {
					if (--count) continue;
					atmarp_info(n->dev,entry,vcc,buf);
					read_unlock_bh(&clip_tbl.lock);
					return strlen(buf);
				}
			}
		read_unlock_bh(&clip_tbl.lock);
		return 0;
	}
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
	if (ino == INO(lec)) {
		struct lec_priv *priv;
		struct lec_arp_table *entry;
		int i, count, d, e;
		struct net_device **dev_lec;

		if (atm_lane_ops.get_lecs == NULL)
			return 0; /* the lane module is not there yet */
		else
			dev_lec = atm_lane_ops.get_lecs();

		count = *pos;
		for(d=0;d<MAX_LEC_ITF;d++) {
			if (!dev_lec[d] || !(priv =
			    (struct lec_priv *) dev_lec[d]->priv)) continue;
			for(i=0;i<LEC_ARP_TABLE_SIZE;i++) {
				entry = priv->lec_arp_tables[i];
				for(;entry;entry=entry->next) {
					if (--count) continue;
					e=sprintf(buf,"%s ",
					    dev_lec[d]->name);
					lec_info(entry,buf+e);
					return strlen(buf);
				}
			}
			for(entry=priv->lec_arp_empty_ones; entry;
			    entry=entry->next) {
				if (--count) continue;
				e=sprintf(buf,"%s ",dev_lec[d]->name);
				lec_info(entry, buf+e);
				return strlen(buf);
			}
			for(entry=priv->lec_no_forward; entry;
			    entry=entry->next) {
				if (--count) continue;
				e=sprintf(buf,"%s ",dev_lec[d]->name);
				lec_info(entry, buf+e);
				return strlen(buf);
			}
			for(entry=priv->mcast_fwds; entry;
			    entry=entry->next) {
				if (--count) continue;
				e=sprintf(buf,"%s ",dev_lec[d]->name);
				lec_info(entry, buf+e);
				return strlen(buf);
			}
		}
		return 0;
	}
#endif
	return -EINVAL;
}


static ssize_t proc_atm_read(struct file *file,char *buf,size_t count,
    loff_t *pos)
{
	struct atm_dev *dev;
	unsigned long page;
	int ino = file->f_dentry->d_inode->i_ino;
	int length;

	if (count < 0) return -EINVAL;
	page = get_free_page(GFP_KERNEL);
	if (!page) return -ENOMEM;
	for (dev = atm_devs; dev; dev = dev->next)
		if (dev->ops->proc_read && dev->proc_entry->low_ino == ino)
			break;
	if (dev) length = dev->ops->proc_read(dev,pos,(char *) page);
	else if (*pos) length = atm_info(ino,pos,(char *) page);
		else length = atm_header(ino,(char *) page);
	if (length > count) length = -EINVAL;
	if (length >= 0) {
		if (copy_to_user(buf,(char *) page,length)) length = -EFAULT;
		(*pos)++;
	}
	free_page(page);
	return length;
}


struct proc_dir_entry atm_proc_root = { 0, 3, "atm",
    S_IFDIR | S_IRUGO | S_IXUGO, 2, 0, 0, 0, &proc_dir_inode_operations,
    NULL, NULL, NULL, NULL, NULL };


EXPORT_SYMBOL(atm_proc_root);


int atm_proc_dev_register(struct atm_dev *dev)
{
	ENTRY(template);
	int digits,num;
	int error;

	error = -ENOMEM;
	digits = 0;
	for (num = dev->number; num; num /= 10) digits++;
	if (!digits) digits++;
	dev->proc_entry = kmalloc(sizeof(*dev->proc_entry),GFP_KERNEL);
	if (!dev->proc_entry) goto fail0;
	dev->proc_name = kmalloc(strlen(dev->type)+digits+2,GFP_KERNEL);
	if (!dev->proc_name) goto fail1;
	*dev->proc_entry = atm_proc_entry_template;
	dev->proc_entry->name = dev->proc_name;
	dev->proc_entry->namelen = sprintf(dev->proc_name,"%s:%d",dev->type,
	    dev->number);
	error = proc_register(&atm_proc_root,dev->proc_entry);
	if (!error) return 0;
	kfree(dev->proc_name);
fail1:
	kfree(dev->proc_entry);
fail0:
	return error;
}


void atm_proc_dev_deregister(struct atm_dev *dev)
{
	proc_unregister(&atm_proc_root,dev->proc_entry->low_ino);
	kfree(dev->proc_entry);
	kfree(dev->proc_name);
}


int __init atm_proc_init(void)
{
	int error;

	error = proc_register(&proc_root,&atm_proc_root);
	REG(devices);
	REG(pvc);
	REG(svc);
#ifdef CONFIG_ATM_CLIP
	REG(arp);
#endif
#if defined(CONFIG_ATM_LANE) || defined(CONFIG_ATM_LANE_MODULE)
	REG(lec);
#endif
	return error;
}