Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

344 lines
9.8 KiB

  1. #include "prep.h"
  2. #include "oemint.h"
  3. #include "t30.h"
  4. #include "efaxcb.h"
  5. #include "debug.h"
  6. ///RSL
  7. #include "glbproto.h"
  8. # define MySleep(time) Sleep(time)
  9. /**--------------------------- Debugging ------------------------**/
  10. #define faxTlog(m) DEBUGMSG(ZONE_MAIN, m);
  11. #define FILEID FILEID_T30MAIN
  12. #ifdef DEBUG
  13. # define TIMESTAMP(str) \
  14. faxTlog((SZMOD "TIMESTAMP %lu %s--\r\n", (unsigned long) GetTickCount(), (LPSTR) (str)));
  15. #else // !DEBUG
  16. # define TIMESTAMP(str)
  17. #endif // !DEBUG
  18. BOOL
  19. T30Cl1Rx (
  20. PThrdGlbl pTG
  21. )
  22. {
  23. BOOL fOpen = 0, //CHKCHK - need to assign a value
  24. fImmediate = 1;
  25. USHORT uLine = 5, // LINE_NUM,
  26. uModem = 5; // MODEM_NUM;
  27. USHORT uRet1, uRet2, uFlags;
  28. HMODEM hModem;
  29. HLINE hLine;
  30. ET30ACTION actionInitial = actionNULL;
  31. BOOL RetCode = FALSE;
  32. // #ifndef SHIP_BUILD
  33. {
  34. SYSTEMTIME st;
  35. GetLocalTime(&st);
  36. RETAILMSG((SZMOD "------------- Answering at %02d:%02d:%02d on %02d/%02d/%02d ----------\r\n",
  37. st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  38. }
  39. // #endif
  40. TIMESTAMP("Answering")
  41. SignalStatusChange(pTG, FS_ANSWERED);
  42. // first get SEND_CAPS (before answering)
  43. if(!ProtGetBC(pTG, SEND_CAPS, TRUE)) // sleep until we get it
  44. {
  45. uRet1 = T30_CALLFAIL;
  46. uRet2 = 0; // need err value here
  47. goto done;
  48. }
  49. uFlags = NCULINK_RX;
  50. if(fOpen || fImmediate)
  51. {
  52. uFlags |= NCULINK_IMMEDIATE;
  53. faxTlog((SZMOD "IMMEDIATE ANSWER\r\n"));
  54. }
  55. // when MDDI is not defined, hLine==uLine and hModem==uModem
  56. // when MDDI is defined, if fOpen is TRUE, then also hLine==uLine and hModem==uModem
  57. hLine = (HLINE)uLine;
  58. hModem = (HMODEM)uModem;
  59. if((uRet2 = NCULink(pTG, hLine, hModem, 0, uFlags)) != CONNECT_OK)
  60. {
  61. uRet1 = T30_ANSWERFAIL;
  62. goto done;
  63. }
  64. #ifdef RICOHAI
  65. fUsingOEMProt = FALSE;
  66. BG_CHK(RICOHAI_MODE == RICOHAI_ENABLE);
  67. uRet2 = ModemConnectRx(pTG, hModem, (wOEMFlags & RICOHAI_ENABLE));
  68. if(uRet2 == CONNECT_ESCAPE)
  69. {
  70. fUsingOEMProt = TRUE;
  71. actionInitial = actionGONODE_F;
  72. }
  73. else if(uRet2 != CONNECT_OK)
  74. {
  75. uRet1 = T30_ANSWERFAIL;
  76. goto done;
  77. }
  78. #else
  79. #ifdef MDDI
  80. if((uRet2 = ModemConnectRx(pTG, hModem, 0)) != CONNECT_OK)
  81. {
  82. uRet1 = T30_ANSWERFAIL;
  83. goto done;
  84. }
  85. #endif //MDDI
  86. #endif //!RICOHAI
  87. // Protocol Dump
  88. RestartDump(pTG);
  89. #ifdef IFK
  90. // Call counter
  91. IFNvramSetCounterValue(RXCALL_COUNTER, 1, 0,
  92. (COUNTER_ADDVALUE|COUNTER_TIMESTAMP|PROCESS_CONTEXT));
  93. #endif
  94. uRet1 = T30MainBody(pTG, FALSE, actionInitial, hLine, hModem);
  95. BG_CHK(uRet1==T30_CALLDONE || uRet1==T30_CALLFAIL);
  96. uRet2 = 0;
  97. // Protocol Dump
  98. PrintDump(pTG);
  99. done:
  100. // #ifndef SHIP_BUILD
  101. {
  102. SYSTEMTIME st;
  103. GetLocalTime(&st);
  104. if(uRet1==T30_CALLDONE) {
  105. SignalStatusChange(pTG, FS_COMPLETED);
  106. RetCode = TRUE;
  107. RETAILMSG((SZMOD "------------ SUCCESSFUL RECV at %02d:%02d:%02d on %02d/%02d/%02d ------------\r\n",
  108. st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  109. }
  110. else if (pTG->StatusId == FS_NOT_FAX_CALL) {
  111. RetCode = FALSE;
  112. ERRMSG(("---------- DATA CALL attempt HANDOVER (0x%04x) at %02d:%02d:%02d on %02d/%02d/%02d -----------\r\n",
  113. MAKEWORD(uRet1, uRet2), st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  114. }
  115. else {
  116. if (!pTG->fFatalErrorWasSignaled) {
  117. pTG->fFatalErrorWasSignaled = 1;
  118. SignalStatusChange(pTG, FS_FATAL_ERROR);
  119. }
  120. RetCode = FALSE;
  121. ERRMSG(("---------- FAILED RECV (0x%04x) at %02d:%02d:%02d on %02d/%02d/%02d -----------\r\n",
  122. MAKEWORD(uRet1, uRet2), st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  123. }
  124. }
  125. // #endif
  126. ICommStatus(pTG, ((uRet1==T30_CALLDONE) ? T30STATR_SUCCESS : T30STATR_FAIL), 0, 0, 0);
  127. // Dont do this!! The Modem driver queues up commands for later execution, so the
  128. // DCN we just sent is probably in the queue. Doing a sync here causes that send
  129. // to be aborted, so the recvr never gets a DCN and thinks teh recv failed. This
  130. // is bug#6803
  131. // #ifdef MDDI
  132. // // sometimes modem gets confused & doesnt want to hangup? Cleanup its state
  133. // // Class1 modem driver doesnt need this. Only Ricohs
  134. // ModemSync(hModem, RESYNC_TIMEOUT1);
  135. // #endif
  136. NCULink(pTG, hLine, 0, 0, NCULINK_HANGUP);
  137. pTG->lEarliestDialTime = GetTickCount() + MIN_CALL_SEPERATION;
  138. #ifdef MDDI
  139. ModemClose(pTG, hModem);
  140. NCUReleaseLine(pTG, hLine);
  141. #endif //MDDI
  142. BG_CHK((uRet1 & 0xFF) == uRet1);
  143. BG_CHK((uRet2 & 0xFF) == uRet2);
  144. return (RetCode);
  145. }
  146. BOOL
  147. T30Cl1Tx (
  148. PThrdGlbl pTG,
  149. LPSTR szPhone
  150. )
  151. {
  152. BOOL fOpen = 0; //CHKCHK - need to assign a value
  153. USHORT uRet1, uRet2;
  154. ULONG ulTimeout;
  155. USHORT uLine = 5, // LINE_NUM,
  156. uModem = 5; // MODEM_NUM;
  157. HLINE hLine;
  158. HMODEM hModem;
  159. ET30ACTION actionInitial;
  160. WORD wFlags;
  161. BOOL RetCode = FALSE;
  162. // #ifndef SHIP_BUILD
  163. {
  164. SYSTEMTIME st;
  165. GetLocalTime(&st);
  166. RETAILMSG((SZMOD "------------ Calling <%s> at %02d:%02d:%02d on %02d/%02d/%02d ------------\r\n",
  167. (LPSTR)szPhone, st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  168. }
  169. // #endif
  170. // Ricoh doesnt like this to go over 60secs, so give ourselves some buffer here
  171. #define DIAL_TIMEOUT 58000L
  172. ulTimeout = DIAL_TIMEOUT;
  173. /**
  174. if((uLen = _fstrlen(szPhone)) > 7)
  175. ulTimeout += (((ULONG)(uLen - 7)) << 12); //mult by 4096
  176. **/
  177. // when MDDI is not defined, hLine==uLine and hModem==uModem
  178. // when MDDI is defined, if fOpen is TRUE, then also hLine==uLine and hModem==uModem
  179. hLine = (HLINE)uLine;
  180. hModem = (HMODEM)uModem;
  181. actionInitial = actionNULL;
  182. wFlags = 0;
  183. // for non-manual calls only, wait until a min. time has elapsed
  184. // since the last hangup. Beware of wraparound
  185. if(!fOpen && szPhone) //fOpen==on-hook-dial, szPhone=NULL: handset dial
  186. {
  187. DWORD lNow, lSleep = -1;
  188. lNow = GetTickCount();
  189. if(lNow < pTG->lEarliestDialTime)
  190. lSleep = pTG->lEarliestDialTime-lNow;
  191. faxTlog((SZMOD "Seperation: Now=%ld Earliest=%ld Seperation=%ld Sleep=%ld\r\n",
  192. lNow, pTG->lEarliestDialTime, (DWORD)(MIN_CALL_SEPERATION), lSleep ));
  193. if(lSleep <= MIN_CALL_SEPERATION)
  194. MySleep(lSleep);
  195. }
  196. SignalStatusChange(pTG, FS_DIALING);
  197. if(((uRet2 = NCULink(pTG, hLine, hModem, 0, NCULINK_TX)) != CONNECT_OK)
  198. || (szPhone ? ((uRet2 = NCUDial(pTG, hLine, szPhone)) != CONNECT_OK) : FALSE))
  199. {
  200. uRet1 = T30_DIALFAIL;
  201. goto done;
  202. }
  203. // Protocol Dump
  204. RestartDump(pTG);
  205. uRet1 = T30MainBody(pTG, TRUE, actionInitial, hLine, hModem);
  206. BG_CHK(uRet1==T30_CALLDONE || uRet1==T30_CALLFAIL);
  207. uRet2 = 0;
  208. #ifdef RICOHAI
  209. RicohAIEnd();
  210. #endif
  211. // Protocol Dump
  212. PrintDump(pTG);
  213. done:
  214. // #ifndef SHIP_BUILD
  215. {
  216. SYSTEMTIME st;
  217. GetLocalTime(&st);
  218. if(uRet1==T30_CALLDONE) {
  219. SignalStatusChange(pTG, FS_COMPLETED);
  220. RetCode = TRUE;
  221. RETAILMSG((SZMOD "------------ SUCCESSFUL SEND at %02d:%02d:%02d on %02d/%02d/%02d ------------\r\n",
  222. st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  223. }
  224. else {
  225. if (!pTG->fFatalErrorWasSignaled) {
  226. pTG->fFatalErrorWasSignaled = 1;
  227. SignalStatusChange(pTG, FS_FATAL_ERROR);
  228. }
  229. RetCode = FALSE;
  230. ERRMSG(("---------- FAILED SEND (0x%04x) at %02d:%02d:%02d on %02d/%02d/%02d -----------\r\n",
  231. MAKEWORD(uRet1, uRet2), st.wHour, st.wMinute, st.wSecond, st.wMonth, st.wDay, st.wYear));
  232. }
  233. }
  234. // #endif
  235. ICommStatus(pTG, ((uRet1==T30_CALLDONE) ? T30STATS_SUCCESS : T30STATS_FAIL), 0, 0, 0);
  236. // Dont do this!! The Modem driver queues up commands for later execution, so the
  237. // DCN we just sent is probably in the queue. Doing a sync here causes that send
  238. // to be aborted, so the recvr never gets a DCN and thinks teh recv failed. This
  239. // is bug#6803
  240. // #ifdef MDDI
  241. // // sometimes modem gets confused & doesnt want to hangup? Cleanup its state
  242. // // Class1 modem driver doesnt need this. Only Ricohs
  243. // ModemSync(hModem, RESYNC_TIMEOUT1);
  244. // #endif
  245. NCULink(pTG, hLine, 0, 0, NCULINK_HANGUP);
  246. pTG->lEarliestDialTime = GetTickCount() + MIN_CALL_SEPERATION;
  247. #ifdef MDDI
  248. ModemClose(pTG, hModem);
  249. NCUReleaseLine(pTG, hLine);
  250. #endif //MDDI
  251. BG_CHK((uRet1 & 0xFF) == uRet1);
  252. BG_CHK((uRet2 & 0xFF) == uRet2);
  253. return (RetCode);
  254. }