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