aboutsummaryrefslogtreecommitdiffstats
path: root/channels/misdn/portinfo.c
blob: 6d5f2154d61797ad6c4323be539e213cada648d8 (plain)
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
/*! \file 
 * \brief Interface to mISDN - port info
 * \author Christian Richter <crich@beronet.com>
 */


#include "isdn_lib.h"
#include "isdn_lib_intern.h"


/*
 * global function to show all available isdn ports
 */
void isdn_port_info(void)
{
	int err;
	int i, ii, p;
	int useable, nt, pri;
	unsigned char buff[1025];
	iframe_t *frm = (iframe_t *)buff;
	stack_info_t *stinf;
	int device;

	/* open mISDN */
	if ((device = mISDN_open()) < 0)
	{
		fprintf(stderr, "mISDN_open() failed: ret=%d errno=%d (%s) Check for mISDN modules and device.\n", device, errno, strerror(errno));
		exit(-1);
	}

	/* get number of stacks */
	i = 1;
	ii = mISDN_get_stack_count(device);
	printf("\n");
	if (ii <= 0)
	{
		printf("Found no card. Please be sure to load card drivers.\n");
	}

	/* loop the number of cards and get their info */
	while(i <= ii)
	{
		err = mISDN_get_stack_info(device, i, buff, sizeof(buff));
		if (err <= 0)
		{
			fprintf(stderr, "mISDN_get_stack_info() failed: port=%d err=%d\n", i, err);
			break;
		}
		stinf = (stack_info_t *)&frm->data.p;

		nt = pri = 0;
		useable = 1;

		/* output the port info */
		printf("Port %2d: ", i);
		switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
		{
			case ISDN_PID_L0_TE_S0:
			printf("TE-mode BRI S/T interface line (for phone lines)");
#if 0
			if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_S0_HFC & ISDN_PID_FEATURE_MASK)
				printf(" HFC multiport card");
#endif
			break;
			case ISDN_PID_L0_NT_S0:
			nt = 1;
			printf("NT-mode BRI S/T interface port (for phones)");
#if 0
			if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_S0_HFC & ISDN_PID_FEATURE_MASK)
				printf(" HFC multiport card");
#endif
			break;
			case ISDN_PID_L0_TE_U:
			printf("TE-mode BRI U   interface line");
			break;
			case ISDN_PID_L0_NT_U:
			nt = 1;
			printf("NT-mode BRI U   interface port");
			break;
			case ISDN_PID_L0_TE_UP2:
			printf("TE-mode BRI Up2 interface line");
			break;
			case ISDN_PID_L0_NT_UP2:
			nt = 1;
			printf("NT-mode BRI Up2 interface port");
			break;
			case ISDN_PID_L0_TE_E1:
			pri = 1;
			printf("TE-mode PRI E1  interface line (for phone lines)");
#if 0
			if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_E1_HFC & ISDN_PID_FEATURE_MASK)
				printf(" HFC-E1 card");
#endif
			break;
			case ISDN_PID_L0_NT_E1:
			nt = 1;
			pri = 1;
			printf("NT-mode PRI E1  interface port (for phones)");
#if 0
			if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_E1_HFC & ISDN_PID_FEATURE_MASK)
				printf(" HFC-E1 card");
#endif
			break;
			default:
			useable = 0;
			printf("unknown type 0x%08x",stinf->pid.protocol[0]);
		}
		printf("\n");

		if (nt)
		{
			if (stinf->pid.protocol[1] == 0)
			{
				useable = 0;
				printf(" -> Missing layer 1 NT-mode protocol.\n");
			}
			p = 2;
			while(p <= MAX_LAYER_NR) {
				if (stinf->pid.protocol[p])
				{
					useable = 0;
					printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for NT lib.\n", p, stinf->pid.protocol[p]);
				}
				p++;
			}
			if (useable)
			{
				if (pri)
					printf(" -> Interface is Point-To-Point (PRI).\n");
				else
					printf(" -> Interface can be Poin-To-Point/Multipoint.\n");
			}
		} else
		{
			if (stinf->pid.protocol[1] == 0)
			{
				useable = 0;
				printf(" -> Missing layer 1 protocol.\n");
			}
			if (stinf->pid.protocol[2] == 0)
			{
				useable = 0;
				printf(" -> Missing layer 2 protocol.\n");
			}
			if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP)
			{
				printf(" -> Interface is Poin-To-Point.\n");
			}
			if (stinf->pid.protocol[3] == 0)
			{
				useable = 0;
				printf(" -> Missing layer 3 protocol.\n");
			} else
			{
				printf(" -> Protocol: ");
				switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
				{
					case ISDN_PID_L3_DSS1USER:
					printf("DSS1 (Euro ISDN)");
					break;

					default:
					useable = 0;
					printf("unknown protocol 0x%08x",stinf->pid.protocol[3]);
				}
				printf("\n");
			}
			p = 4;
			while(p <= MAX_LAYER_NR) {
				if (stinf->pid.protocol[p])
				{
					useable = 0;
					printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for TE lib.\n", p, stinf->pid.protocol[p]);
				}
				p++;
			}
			printf(" -> childcnt: %d\n",stinf->childcnt);
		}

		if (!useable)
			printf(" * Port NOT useable for PBX\n");

		printf("--------\n");

		i++;
	}
	printf("\n");

	/* close mISDN */
	if ((err = mISDN_close(device)))
	{
		fprintf(stderr, "mISDN_close() failed: err=%d '%s'\n", err, strerror(err));
		exit(-1);
	}
}


int main()
{
  isdn_port_info();
  return 0;
}