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