portinfo.c 4.4 KB

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