fasiintf.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /*+-------------------------------------------------------------------------
  2. fasiintf.c - FAS/i interface
  3. wht@wht.net
  4. Defined functions:
  5. display_fasi(fip)
  6. fasi_breaks_detected()
  7. fasi_line_errors()
  8. fasi_msr()
  9. fasi_rings_detected()
  10. icmd_fasi(narg, arg)
  11. ier_text(ier)
  12. lcr_text(lcr)
  13. mcr_text(mcr)
  14. msr_text(msr)
  15. pcmd_fasi(param)
  16. --------------------------------------------------------------------------*/
  17. /*+:EDITS:*/
  18. /*:04-26-2000-11:15-wht@bob-RELEASE 4.42 */
  19. /*:01-24-1997-02:37-wht@yuriatin-SOURCE RELEASE 4.00 */
  20. /*:09-11-1996-20:00-wht@yuriatin-3.48-major telnet,curses,structural overhaul */
  21. /*:11-23-1995-11:20-wht@kepler-source control 3.37 for tsx-11 */
  22. /*:11-14-1995-10:23-wht@kepler-3.37.80-source control point: SOCKETS */
  23. /*:05-04-1994-04:39-wht@n4hgf-ECU release 3.30 */
  24. /*:09-10-1992-13:59-wht@n4hgf-ECU release 3.20 */
  25. /*:08-22-1992-15:38-wht@n4hgf-ECU release 3.20 BETA */
  26. /*:07-25-1991-12:57-wht@n4hgf-ECU release 3.10 */
  27. /*:04-29-1991-18:52-wht@n4hgf-FAS/i 2.08.0 official release */
  28. /*:12-24-1990-00:51-wht-creation */
  29. #include "ecu.h"
  30. #if defined(FASI)
  31. #include "ecuerror.h"
  32. #include "esd.h"
  33. #if defined(NULL)
  34. #undef NULL
  35. #endif
  36. #include <local/fas.h>
  37. /*+-------------------------------------------------------------------------
  38. msr_text(msr)
  39. --------------------------------------------------------------------------*/
  40. char *
  41. msr_text(msr)
  42. uchar msr;
  43. {
  44. static char txt[50];
  45. txt[0] = '*';
  46. txt[1] = 0;
  47. if (!msr)
  48. {
  49. strcat(txt, "NULL*");
  50. return (txt);
  51. }
  52. if (msr & MS_CTS_DELTA)
  53. strcat(txt, "dCTS*");
  54. if (msr & MS_DSR_DELTA)
  55. strcat(txt, "dDSR*");
  56. if (msr & MS_RING_TEDGE)
  57. strcat(txt, "dRI*");
  58. if (msr & MS_DCD_DELTA)
  59. strcat(txt, "dDCD*");
  60. if (msr & MS_CTS_PRESENT)
  61. strcat(txt, "CTS*");
  62. if (msr & MS_DSR_PRESENT)
  63. strcat(txt, "DSR*");
  64. if (msr & MS_RING_PRESENT)
  65. strcat(txt, "RING*");
  66. if (msr & MS_DCD_PRESENT)
  67. strcat(txt, "DCD*");
  68. return (txt);
  69. } /* end of msr_text */
  70. /*+-------------------------------------------------------------------------
  71. mcr_text(mcr)
  72. --------------------------------------------------------------------------*/
  73. char *
  74. mcr_text(mcr)
  75. uchar mcr;
  76. {
  77. static char txt[32];
  78. txt[0] = '*';
  79. txt[1] = 0;
  80. if (!mcr)
  81. {
  82. strcat(txt, "NULL*");
  83. return (txt);
  84. }
  85. if (mcr & MC_SET_DTR)
  86. strcat(txt, "DTR*");
  87. if (mcr & MC_SET_RTS)
  88. strcat(txt, "RTS*");
  89. if (mcr & MC_SET_OUT1)
  90. strcat(txt, "OUT1*");
  91. if (mcr & MC_SET_OUT2)
  92. strcat(txt, "OUT2*");
  93. if (mcr & MC_SET_LOOPBACK)
  94. strcat(txt, "LOOPBACK*");
  95. return (txt);
  96. } /* end of mcr_text */
  97. /*+-------------------------------------------------------------------------
  98. lcr_text(lcr)
  99. --------------------------------------------------------------------------*/
  100. char *
  101. lcr_text(lcr)
  102. uchar lcr;
  103. {
  104. static char txt[64];
  105. sprintf(txt, "*%ddb*", (lcr & LC_WORDLEN_MASK) + 5);
  106. strcat(txt, (lcr & LC_STOPBITS_LONG) ? "2" : "1");
  107. strcat(txt, "sb*");
  108. if (lcr & LC_ENABLE_PARITY)
  109. {
  110. strcat(txt, "PARITY*");
  111. if (lcr & LC_STICK_PARITY)
  112. strcat(txt, (lcr & LC_EVEN_PARITY) ? "MARK*" : "SPACE*");
  113. else
  114. strcat(txt, (lcr & LC_EVEN_PARITY) ? "EVEN*" : "ODD*");
  115. }
  116. else
  117. strcat(txt, "NOPAR*");
  118. if (lcr & LC_SET_BREAK_LEVEL)
  119. strcat(txt, "SETBREAK*");
  120. if (lcr & LC_ENABLE_DIVISOR)
  121. strcat(txt, "ENABDIV*");
  122. return (txt);
  123. } /* end of lcr_text */
  124. /*+-------------------------------------------------------------------------
  125. ier_text(ier)
  126. --------------------------------------------------------------------------*/
  127. char *
  128. ier_text(ier)
  129. uchar ier;
  130. {
  131. static char txt[32];
  132. txt[0] = '*';
  133. txt[1] = 0;
  134. if (!ier)
  135. {
  136. strcat(txt, "NULL*");
  137. return (txt);
  138. }
  139. if (ier & IE_RECV_DATA_AVAILABLE)
  140. strcat(txt, "RDAV*");
  141. if (ier & IE_XMIT_HOLDING_BUFFER_EMPTY)
  142. strcat(txt, "TBMT*");
  143. if (ier & IE_LINE_STATUS)
  144. strcat(txt, "LS*");
  145. if (ier & IE_MODEM_STATUS)
  146. strcat(txt, "MS*");
  147. return (txt);
  148. } /* end of ier_text */
  149. /*+-------------------------------------------------------------------------
  150. display_fasi(fip)
  151. --------------------------------------------------------------------------*/
  152. void
  153. display_fasi(fip)
  154. struct fas_info *fip;
  155. {
  156. pprintf("base address: %04x irq=%u ", fip->port_0.addr, fip->vec);
  157. pputs("device is ");
  158. if (fip->device_flags.s & DF_DEVICE_IS_NS16550A)
  159. pputs("16550\n");
  160. else if (fip->device_flags.s & DF_DEVICE_IS_I82510)
  161. pputs("82510\n");
  162. else
  163. pputs("16450\n");
  164. pprintf("MSR=%s ", msr_text(fip->msr));
  165. pprintf("MCR=%s\n", mcr_text(fip->mcr));
  166. pprintf("LCR=%s ", lcr_text(fip->lcr));
  167. pprintf("IER=%s\n", ier_text(fip->ier));
  168. pprintf("recv ring cnt=%u ", fip->recv_ring_cnt);
  169. pprintf("xmit ring cnt=%u ", fip->xmit_ring_cnt);
  170. pprintf("xmit fifo size=%u\n", fip->xmit_fifo_size);
  171. pprintf("characters received =%12lu\n", fip->characters_received);
  172. pprintf("characters transmitted =%12lu\n", fip->characters_transmitted);
  173. pprintf("modem status events =%12lu\n", fip->modem_status_events);
  174. pprintf("overrun errors=%lu ", fip->overrun_errors);
  175. pprintf("framing errors=%lu ", fip->framing_errors);
  176. pprintf("parity errors=%lu\n", fip->parity_errors);
  177. pprintf("rings detected=%lu ", fip->rings_detected);
  178. pprintf("breaks detected=%lu\n", fip->breaks_detected);
  179. pprintf("xmtr flow off XON/XOFF=%lu RTS/CTS=%lu\n",
  180. fip->xmtr_sw_flow_count, fip->xmtr_hw_flow_count);
  181. pprintf("rcvr flow off XON/XOFF=%lu RTS/CTS=%lu\n",
  182. fip->rcvr_sw_flow_count, fip->rcvr_hw_flow_count);
  183. } /* end of display_fasi */
  184. /*+-------------------------------------------------------------------------
  185. fasi_msr() - return modem status register contents
  186. --------------------------------------------------------------------------*/
  187. uchar
  188. fasi_msr()
  189. {
  190. UINT32 ltmp = 0;
  191. return ((uchar) ioctl(shm->Liofd, FASIC_MCR, (char *)&ltmp));
  192. return (ltmp);
  193. } /* end of fasi_msr */
  194. /*+-------------------------------------------------------------------------
  195. fasi_line_errors() - return UART error count
  196. --------------------------------------------------------------------------*/
  197. UINT32
  198. fasi_line_errors()
  199. {
  200. struct fas_info finfo, *fip = &finfo;
  201. memset((char *)fip, 0, sizeof(*fip));
  202. if ((ioctl(shm->Liofd, FASIC_SIP, (char *)fip)) < 0)
  203. return (0);
  204. return (fip->parity_errors + fip->framing_errors + fip->overrun_errors);
  205. } /* end of fasi_line_errors */
  206. /*+-------------------------------------------------------------------------
  207. fasi_rings_detected() - return number of RI trailing edges
  208. --------------------------------------------------------------------------*/
  209. UINT32
  210. fasi_rings_detected()
  211. {
  212. struct fas_info finfo, *fip = &finfo;
  213. memset((char *)fip, 0, sizeof(*fip));
  214. if ((ioctl(shm->Liofd, FASIC_SIP, (char *)fip)) < 0)
  215. return (0);
  216. return (fip->rings_detected);
  217. } /* end of fasi_rings_detected */
  218. /*+-------------------------------------------------------------------------
  219. fasi_breaks_detected() - return number of BREAKs detected
  220. --------------------------------------------------------------------------*/
  221. UINT32
  222. fasi_breaks_detected()
  223. {
  224. struct fas_info finfo, *fip = &finfo;
  225. memset((char *)fip, 0, sizeof(*fip));
  226. if ((ioctl(shm->Liofd, FASIC_SIP, (char *)fip)) < 0)
  227. return (0);
  228. return (fip->breaks_detected);
  229. } /* end of fasi_breaks_detected */
  230. /*+-------------------------------------------------------------------------
  231. pcmd_fasi(param)
  232. fasi [-switches] <str-cmd>>
  233. where <str-cmd> is 'd[isplay]'
  234. or 'r[eset]'
  235. fasi 'd'
  236. fasi 'r'
  237. --------------------------------------------------------------------------*/
  238. int
  239. pcmd_fasi(param)
  240. ESD *param;
  241. {
  242. int erc;
  243. char switches[8];
  244. ESD *tesd = (ESD *) 0;
  245. struct fas_info finfo, *fip = &finfo;
  246. char ident_str[128];
  247. memset((char *)fip, 0, sizeof(*fip));
  248. get_switches(param, switches, sizeof(switches));
  249. if (!(tesd = esdalloc(64)))
  250. return (eNoMemory);
  251. if (!(erc = gstr(param, tesd, 1)))
  252. {
  253. skip_cmd_break(tesd);
  254. switch (to_lower(*(tesd->pb + tesd->index)))
  255. {
  256. case 'd': /* display */
  257. if ((ioctl(shm->Liofd, FASIC_SIP, (char *)fip)) < 0)
  258. {
  259. pperror("ioctl FASIC_SIP");
  260. erc = eFATAL_ALREADY;
  261. }
  262. else
  263. display_fasi(fip);
  264. if ((ioctl(shm->Liofd, FASIC_DVR_IDENT, ident_str)) < 0)
  265. {
  266. pperror("ioctl FASIC_DVR_IDENT");
  267. erc = eFATAL_ALREADY;
  268. }
  269. else
  270. pprintf("driver: '%s'\n", ident_str);
  271. if ((ioctl(shm->Liofd, FASIC_SPACE_IDENT, ident_str)) < 0)
  272. {
  273. pperror("ioctl FASIC_SPACE_IDENT");
  274. erc = eFATAL_ALREADY;
  275. }
  276. else
  277. pprintf("space.c: '%s'\n", ident_str);
  278. break;
  279. case 'r': /* reset */
  280. if ((ioctl(shm->Liofd, FASIC_RESET_STAT, (char *)0)) < 0)
  281. {
  282. pperror("ioctl FASIC_RESET_STAT");
  283. erc = eFATAL_ALREADY;
  284. }
  285. else if (proc_trace)
  286. pputs("statistics reset\n");
  287. break;
  288. default:
  289. pputs("invalid subcommand '");
  290. pputs(tesd->pb);
  291. pputs("'\n");
  292. erc = eFATAL_ALREADY;
  293. break;
  294. }
  295. }
  296. if (tesd)
  297. esdfree(tesd);
  298. return (erc);
  299. } /* end of pcmd_fasi */
  300. /*+-------------------------------------------------------------------------
  301. icmd_fasi(narg,arg)
  302. --------------------------------------------------------------------------*/
  303. void
  304. icmd_fasi(narg, arg)
  305. int narg;
  306. char **arg;
  307. {
  308. struct fas_info finfo, *fip = &finfo;
  309. char ident_str[128];
  310. memset((char *)fip, 0, sizeof(*fip));
  311. if ((narg > 1) && (to_lower(*arg[1]) == 'r'))
  312. {
  313. if ((ioctl(shm->Liofd, FASIC_RESET_STAT, (char *)0)) < 0)
  314. {
  315. pperror(" ioctl FASIC_RESET_STAT");
  316. return;
  317. }
  318. ff(se, " fasi statistics reset\r\n");
  319. }
  320. else
  321. {
  322. if ((ioctl(shm->Liofd, FASIC_SIP, (char *)fip)) < 0)
  323. {
  324. pperror(" ioctl FASIC_SIP");
  325. return;
  326. }
  327. ff(se, "\r\n");
  328. display_fasi(fip);
  329. if ((ioctl(shm->Liofd, FASIC_DVR_IDENT, ident_str)) < 0)
  330. pperror("ioctl FASIC_DVR_IDENT");
  331. else
  332. pprintf("driver: '%s'\n", ident_str);
  333. if ((ioctl(shm->Liofd, FASIC_SPACE_IDENT, ident_str)) < 0)
  334. pperror("ioctl FASIC_SPACE_IDENT");
  335. else
  336. pprintf("space.c: '%s'\n", ident_str);
  337. }
  338. } /* end of icmd_fasi */
  339. #endif /* FASI */
  340. /* vi: set tabstop=4 shiftwidth=4: */
  341. /* end of fasiintf.c */