Merged revisions 67334 via svnmerge from
[asterisk/asterisk.git] / channels / misdn / portinfo.c
1
2
3 #include "isdn_lib.h"
4 #include "isdn_lib_intern.h"
5
6
7 /*
8  * global function to show all available isdn ports
9  */
10 void isdn_port_info(void)
11 {
12         int err;
13         int i, ii, p;
14         int useable, nt, pri;
15         unsigned char buff[1025];
16         iframe_t *frm = (iframe_t *)buff;
17         stack_info_t *stinf;
18         int device;
19
20         /* open mISDN */
21         if ((device = mISDN_open()) < 0)
22         {
23                 fprintf(stderr, "mISDN_open() failed: ret=%d errno=%d (%s) Check for mISDN modules and device.\n", device, errno, strerror(errno));
24                 exit(-1);
25         }
26
27         /* get number of stacks */
28         i = 1;
29         ii = mISDN_get_stack_count(device);
30         printf("\n");
31         if (ii <= 0)
32         {
33                 printf("Found no card. Please be sure to load card drivers.\n");
34         }
35
36         /* loop the number of cards and get their info */
37         while(i <= ii)
38         {
39                 err = mISDN_get_stack_info(device, i, buff, sizeof(buff));
40                 if (err <= 0)
41                 {
42                         fprintf(stderr, "mISDN_get_stack_info() failed: port=%d err=%d\n", i, err);
43                         break;
44                 }
45                 stinf = (stack_info_t *)&frm->data.p;
46
47                 nt = pri = 0;
48                 useable = 1;
49
50                 /* output the port info */
51                 printf("Port %2d: ", i);
52                 switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
53                 {
54                         case ISDN_PID_L0_TE_S0:
55                         printf("TE-mode BRI S/T interface line (for phone lines)");
56 #if 0
57                         if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_S0_HFC & ISDN_PID_FEATURE_MASK)
58                                 printf(" HFC multiport card");
59 #endif
60                         break;
61                         case ISDN_PID_L0_NT_S0:
62                         nt = 1;
63                         printf("NT-mode BRI S/T interface port (for phones)");
64 #if 0
65                         if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_S0_HFC & ISDN_PID_FEATURE_MASK)
66                                 printf(" HFC multiport card");
67 #endif
68                         break;
69                         case ISDN_PID_L0_TE_U:
70                         printf("TE-mode BRI U   interface line");
71                         break;
72                         case ISDN_PID_L0_NT_U:
73                         nt = 1;
74                         printf("NT-mode BRI U   interface port");
75                         break;
76                         case ISDN_PID_L0_TE_UP2:
77                         printf("TE-mode BRI Up2 interface line");
78                         break;
79                         case ISDN_PID_L0_NT_UP2:
80                         nt = 1;
81                         printf("NT-mode BRI Up2 interface port");
82                         break;
83                         case ISDN_PID_L0_TE_E1:
84                         pri = 1;
85                         printf("TE-mode PRI E1  interface line (for phone lines)");
86 #if 0
87                         if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_E1_HFC & ISDN_PID_FEATURE_MASK)
88                                 printf(" HFC-E1 card");
89 #endif
90                         break;
91                         case ISDN_PID_L0_NT_E1:
92                         nt = 1;
93                         pri = 1;
94                         printf("NT-mode PRI E1  interface port (for phones)");
95 #if 0
96                         if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_E1_HFC & ISDN_PID_FEATURE_MASK)
97                                 printf(" HFC-E1 card");
98 #endif
99                         break;
100                         default:
101                         useable = 0;
102                         printf("unknown type 0x%08x",stinf->pid.protocol[0]);
103                 }
104                 printf("\n");
105
106                 if (nt)
107                 {
108                         if (stinf->pid.protocol[1] == 0)
109                         {
110                                 useable = 0;
111                                 printf(" -> Missing layer 1 NT-mode protocol.\n");
112                         }
113                         p = 2;
114                         while(p <= MAX_LAYER_NR) {
115                                 if (stinf->pid.protocol[p])
116                                 {
117                                         useable = 0;
118                                         printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for NT lib.\n", p, stinf->pid.protocol[p]);
119                                 }
120                                 p++;
121                         }
122                         if (useable)
123                         {
124                                 if (pri)
125                                         printf(" -> Interface is Point-To-Point (PRI).\n");
126                                 else
127                                         printf(" -> Interface can be Poin-To-Point/Multipoint.\n");
128                         }
129                 } else
130                 {
131                         if (stinf->pid.protocol[1] == 0)
132                         {
133                                 useable = 0;
134                                 printf(" -> Missing layer 1 protocol.\n");
135                         }
136                         if (stinf->pid.protocol[2] == 0)
137                         {
138                                 useable = 0;
139                                 printf(" -> Missing layer 2 protocol.\n");
140                         }
141                         if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP)
142                         {
143                                 printf(" -> Interface is Poin-To-Point.\n");
144                         }
145                         if (stinf->pid.protocol[3] == 0)
146                         {
147                                 useable = 0;
148                                 printf(" -> Missing layer 3 protocol.\n");
149                         } else
150                         {
151                                 printf(" -> Protocol: ");
152                                 switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
153                                 {
154                                         case ISDN_PID_L3_DSS1USER:
155                                         printf("DSS1 (Euro ISDN)");
156                                         break;
157
158                                         default:
159                                         useable = 0;
160                                         printf("unknown protocol 0x%08x",stinf->pid.protocol[3]);
161                                 }
162                                 printf("\n");
163                         }
164                         p = 4;
165                         while(p <= MAX_LAYER_NR) {
166                                 if (stinf->pid.protocol[p])
167                                 {
168                                         useable = 0;
169                                         printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for TE lib.\n", p, stinf->pid.protocol[p]);
170                                 }
171                                 p++;
172                         }
173                         printf(" -> childcnt: %d\n",stinf->childcnt);
174                 }
175
176                 if (!useable)
177                         printf(" * Port NOT useable for PBX\n");
178
179                 printf("--------\n");
180
181                 i++;
182         }
183         printf("\n");
184
185         /* close mISDN */
186         if ((err = mISDN_close(device)))
187         {
188                 fprintf(stderr, "mISDN_close() failed: err=%d '%s'\n", err, strerror(err));
189                 exit(-1);
190         }
191 }
192
193
194 int main()
195 {
196   isdn_port_info();
197   return 0;
198 }