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