Sat Aug 6 00:39:31 2011

Asterisk developer's documentation


portinfo.c

Go to the documentation of this file.
00001 
00002 
00003 #include "isdn_lib.h"
00004 #include "isdn_lib_intern.h"
00005 
00006 
00007 /*
00008  * global function to show all available isdn ports
00009  */
00010 void isdn_port_info(void)
00011 {
00012    int err;
00013    int i, ii, p;
00014    int useable, nt, pri;
00015    unsigned char buff[1025];
00016    iframe_t *frm = (iframe_t *)buff;
00017    stack_info_t *stinf;
00018    int device;
00019 
00020    /* open mISDN */
00021    if ((device = mISDN_open()) < 0)
00022    {
00023       fprintf(stderr, "mISDN_open() failed: ret=%d errno=%d (%s) Check for mISDN modules and device.\n", device, errno, strerror(errno));
00024       exit(-1);
00025    }
00026 
00027    /* get number of stacks */
00028    i = 1;
00029    ii = mISDN_get_stack_count(device);
00030    printf("\n");
00031    if (ii <= 0)
00032    {
00033       printf("Found no card. Please be sure to load card drivers.\n");
00034    }
00035 
00036    /* loop the number of cards and get their info */
00037    while(i <= ii)
00038    {
00039       err = mISDN_get_stack_info(device, i, buff, sizeof(buff));
00040       if (err <= 0)
00041       {
00042          fprintf(stderr, "mISDN_get_stack_info() failed: port=%d err=%d\n", i, err);
00043          break;
00044       }
00045       stinf = (stack_info_t *)&frm->data.p;
00046 
00047       nt = pri = 0;
00048       useable = 1;
00049 
00050       /* output the port info */
00051       printf("Port %2d: ", i);
00052       switch(stinf->pid.protocol[0] & ~ISDN_PID_FEATURE_MASK)
00053       {
00054          case ISDN_PID_L0_TE_S0:
00055          printf("TE-mode BRI S/T interface line (for phone lines)");
00056 #if 0
00057          if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_S0_HFC & ISDN_PID_FEATURE_MASK)
00058             printf(" HFC multiport card");
00059 #endif
00060          break;
00061          case ISDN_PID_L0_NT_S0:
00062          nt = 1;
00063          printf("NT-mode BRI S/T interface port (for phones)");
00064 #if 0
00065          if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_S0_HFC & ISDN_PID_FEATURE_MASK)
00066             printf(" HFC multiport card");
00067 #endif
00068          break;
00069          case ISDN_PID_L0_TE_U:
00070          printf("TE-mode BRI U   interface line");
00071          break;
00072          case ISDN_PID_L0_NT_U:
00073          nt = 1;
00074          printf("NT-mode BRI U   interface port");
00075          break;
00076          case ISDN_PID_L0_TE_UP2:
00077          printf("TE-mode BRI Up2 interface line");
00078          break;
00079          case ISDN_PID_L0_NT_UP2:
00080          nt = 1;
00081          printf("NT-mode BRI Up2 interface port");
00082          break;
00083          case ISDN_PID_L0_TE_E1:
00084          pri = 1;
00085          printf("TE-mode PRI E1  interface line (for phone lines)");
00086 #if 0
00087          if (stinf->pid.protocol[0] & ISDN_PID_L0_TE_E1_HFC & ISDN_PID_FEATURE_MASK)
00088             printf(" HFC-E1 card");
00089 #endif
00090          break;
00091          case ISDN_PID_L0_NT_E1:
00092          nt = 1;
00093          pri = 1;
00094          printf("NT-mode PRI E1  interface port (for phones)");
00095 #if 0
00096          if (stinf->pid.protocol[0] & ISDN_PID_L0_NT_E1_HFC & ISDN_PID_FEATURE_MASK)
00097             printf(" HFC-E1 card");
00098 #endif
00099          break;
00100          default:
00101          useable = 0;
00102          printf("unknown type 0x%08x",stinf->pid.protocol[0]);
00103       }
00104       printf("\n");
00105 
00106       if (nt)
00107       {
00108          if (stinf->pid.protocol[1] == 0)
00109          {
00110             useable = 0;
00111             printf(" -> Missing layer 1 NT-mode protocol.\n");
00112          }
00113          p = 2;
00114          while(p <= MAX_LAYER_NR) {
00115             if (stinf->pid.protocol[p])
00116             {
00117                useable = 0;
00118                printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for NT lib.\n", p, stinf->pid.protocol[p]);
00119             }
00120             p++;
00121          }
00122          if (useable)
00123          {
00124             if (pri)
00125                printf(" -> Interface is Point-To-Point (PRI).\n");
00126             else
00127                printf(" -> Interface can be Poin-To-Point/Multipoint.\n");
00128          }
00129       } else
00130       {
00131          if (stinf->pid.protocol[1] == 0)
00132          {
00133             useable = 0;
00134             printf(" -> Missing layer 1 protocol.\n");
00135          }
00136          if (stinf->pid.protocol[2] == 0)
00137          {
00138             useable = 0;
00139             printf(" -> Missing layer 2 protocol.\n");
00140          }
00141          if (stinf->pid.protocol[2] & ISDN_PID_L2_DF_PTP)
00142          {
00143             printf(" -> Interface is Poin-To-Point.\n");
00144          }
00145          if (stinf->pid.protocol[3] == 0)
00146          {
00147             useable = 0;
00148             printf(" -> Missing layer 3 protocol.\n");
00149          } else
00150          {
00151             printf(" -> Protocol: ");
00152             switch(stinf->pid.protocol[3] & ~ISDN_PID_FEATURE_MASK)
00153             {
00154                case ISDN_PID_L3_DSS1USER:
00155                printf("DSS1 (Euro ISDN)");
00156                break;
00157 
00158                default:
00159                useable = 0;
00160                printf("unknown protocol 0x%08x",stinf->pid.protocol[3]);
00161             }
00162             printf("\n");
00163          }
00164          p = 4;
00165          while(p <= MAX_LAYER_NR) {
00166             if (stinf->pid.protocol[p])
00167             {
00168                useable = 0;
00169                printf(" -> Layer %d protocol 0x%08x is detected, but not allowed for TE lib.\n", p, stinf->pid.protocol[p]);
00170             }
00171             p++;
00172          }
00173          printf(" -> childcnt: %d\n",stinf->childcnt);
00174       }
00175 
00176       if (!useable)
00177          printf(" * Port NOT useable for PBX\n");
00178 
00179       printf("--------\n");
00180 
00181       i++;
00182    }
00183    printf("\n");
00184 
00185    /* close mISDN */
00186    if ((err = mISDN_close(device)))
00187    {
00188       fprintf(stderr, "mISDN_close() failed: err=%d '%s'\n", err, strerror(err));
00189       exit(-1);
00190    }
00191 }
00192 
00193 
00194 int main()
00195 {
00196   isdn_port_info();
00197   return 0;
00198 }

Generated on Sat Aug 6 00:39:31 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7