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.

491 lines
16 KiB

  1. /***************************************************************************
  2. Name : PROTHELP.C
  3. Comment : Protocol Initialization & helper functions
  4. Functions: (see Prototypes just below)
  5. Copyright (c) 1993 Microsoft Corp.
  6. Revision Log
  7. Date Name Description
  8. -------- ----- ---------------------------------------------------------
  9. ***************************************************************************/
  10. #include "prep.h"
  11. #include "efaxcb.h"
  12. #include "protocol.h"
  13. ///RSL
  14. #include "glbproto.h"
  15. #define faxTlog(m) DEBUGMSG(ZONE_PROTAPI, m)
  16. #define FILEID FILEID_PROTAPI
  17. BOOL WINAPI ET30ProtOpen(PThrdGlbl pTG, BOOL fCaller)
  18. {
  19. (MyDebugPrint(pTG, LOG_ALL, "In ProtocolOpen\r\n"));
  20. BG_CHK(sizeof(DIS) == 8);
  21. if(!pTG->ProtInst.fInUse)
  22. {
  23. memset(&pTG->ProtInst, 0, sizeof(PROT));
  24. pTG->ProtInst.RecvCaps.wTotalSize =
  25. pTG->ProtInst.RecvParams.wTotalSize =
  26. pTG->ProtInst.RecvPollReq.wTotalSize = sizeof(BC);
  27. pTG->ProtInst.SendCaps.wTotalSize =
  28. pTG->ProtInst.SendParams.wTotalSize =
  29. pTG->ProtInst.SendPollReq.wTotalSize = sizeof(BC);
  30. pTG->ProtInst.RecvCapsGuard =
  31. pTG->ProtInst.RecvParamsGuard =
  32. pTG->ProtInst.RecvPollReqGuard = 0xA55A5AA5L;
  33. pTG->ProtInst.SendCapsGuard =
  34. pTG->ProtInst.SendParamsGuard =
  35. pTG->ProtInst.SendPollReqGuard = 0xA55A5AA5L;
  36. pTG->ProtInst.fInUse = TRUE;
  37. _fmemset(&pTG->ProtParams, 0, sizeof(pTG->ProtParams));
  38. # ifdef OEMNSF
  39. wLenOEMID = 0;
  40. wOEMFlags = 0;
  41. fUsingOEMProt = 0;
  42. if(lpfnOEMStartCall)
  43. wOEMFlags = lpfnOEMStartCall(fCaller, &wLenOEMID, rgbOEMID);
  44. if(wLenOEMID > 4) wLenOEMID = 4;
  45. # endif //OEMNSF
  46. return TRUE;
  47. }
  48. else
  49. {
  50. BG_CHK(FALSE);
  51. return FALSE;
  52. }
  53. }
  54. BOOL WINAPI ET30ProtClose(PThrdGlbl pTG)
  55. {
  56. (MyDebugPrint(pTG, LOG_ALL, "In ProtocolClose\r\n"));
  57. pTG->ProtInst.fInUse = FALSE;
  58. BG_CHK(pTG->ProtInst.RecvCapsGuard == 0xA55A5AA5L);
  59. BG_CHK(pTG->ProtInst.RecvParamsGuard == 0xA55A5AA5L);
  60. BG_CHK(pTG->ProtInst.RecvPollReqGuard == 0xA55A5AA5L);
  61. BG_CHK(pTG->ProtInst.SendCapsGuard == 0xA55A5AA5L);
  62. BG_CHK(pTG->ProtInst.SendParamsGuard == 0xA55A5AA5L);
  63. BG_CHK(pTG->ProtInst.SendPollReqGuard == 0xA55A5AA5L);
  64. #ifdef DEBUG
  65. (MyDebugPrint(pTG, LOG_ALL, "Sending Caps & Params\r\n"));
  66. if(pTG->ProtInst.fRecvCapsGot) D_PrintBC((LPBC)&pTG->ProtInst.RecvCaps, 0, 0);
  67. if(pTG->ProtInst.fllRecvCapsGot) D_PrintBC(0, "RecvCaps", &pTG->ProtInst.llRecvCaps);
  68. if(pTG->ProtInst.fllSendParamsInited) D_PrintBC(0, "Send Negot Position", &pTG->ProtInst.llSendParams);
  69. if(pTG->ProtInst.fSendParamsInited) D_PrintBC((LPBC)&pTG->ProtInst.SendParams, 0, 0);
  70. if(pTG->ProtInst.fllNegotiated) D_PrintBC(0, "SendParams", &pTG->ProtInst.llNegot);
  71. (MyDebugPrint(pTG, LOG_ALL, "Receiving Caps & Params\r\n"));
  72. if(pTG->ProtInst.fSendCapsInited) D_PrintBC((LPBC)&pTG->ProtInst.SendCaps, 0, 0);
  73. if(pTG->ProtInst.fllSendCapsInited) D_PrintBC(0, "SendCaps", &pTG->ProtInst.llSendCaps);
  74. if(pTG->ProtInst.fRecvParamsGot) D_PrintBC((LPBC)&pTG->ProtInst.RecvParams, 0, 0);
  75. if(pTG->ProtInst.fllRecvParamsGot) D_PrintBC(0, "RecvParams", &pTG->ProtInst.llRecvParams);
  76. (MyDebugPrint(pTG, LOG_ALL, "Polling Caps & Params\r\n"));
  77. if(pTG->ProtInst.fSendPollReqInited) D_PrintBC((LPBC)&pTG->ProtInst.SendPollReq, 0, 0);
  78. if(pTG->ProtInst.fRecvPollReqGot) D_PrintBC((LPBC)&pTG->ProtInst.RecvPollReq, 0, 0);
  79. #endif //DEBUG
  80. #ifdef OEMNSF
  81. if(wOEMFlags && lpfnOEMEndCall)
  82. {
  83. lpfnOEMEndCall();
  84. wOEMFlags = 0;
  85. }
  86. #endif
  87. return TRUE;
  88. }
  89. BOOL ProtGetBC(PThrdGlbl pTG, BCTYPE bctype, BOOL fSleep)
  90. {
  91. LPBC lpbc;
  92. USHORT uSpace;
  93. (MyDebugPrint(pTG, LOG_ALL, "In ProtGetBC: bctype=%d\r\n", bctype));
  94. lpbc = ICommGetBC(pTG, bctype, fSleep);
  95. if(lpbc)
  96. {
  97. BG_CHK(lpbc->wTotalSize >= sizeof(BC));
  98. switch(bctype)
  99. {
  100. case SEND_CAPS:
  101. BG_CHK(lpbc->bctype == SEND_CAPS);
  102. uSpace = sizeof(pTG->ProtInst.SendCaps);
  103. if(lpbc->wTotalSize > uSpace)
  104. goto nospace;
  105. _fmemcpy(&pTG->ProtInst.SendCaps, lpbc, lpbc->wTotalSize);
  106. pTG->ProtInst.fSendCapsInited = TRUE;
  107. break;
  108. case SEND_PARAMS:
  109. if(lpbc->bctype == SEND_PARAMS)
  110. {
  111. uSpace = sizeof(pTG->ProtInst.SendParams);
  112. if(lpbc->wTotalSize > uSpace)
  113. goto nospace;
  114. _fmemcpy(&pTG->ProtInst.SendParams, lpbc, lpbc->wTotalSize);
  115. pTG->ProtInst.fSendParamsInited = TRUE;
  116. }
  117. else if(lpbc->bctype == SEND_POLLREQ)
  118. {
  119. uSpace = sizeof(pTG->ProtInst.SendPollReq);
  120. if(lpbc->wTotalSize > uSpace)
  121. goto nospace;
  122. _fmemcpy(&pTG->ProtInst.SendPollReq, lpbc, lpbc->wTotalSize);
  123. pTG->ProtInst.fSendPollReqInited = TRUE;
  124. }
  125. else
  126. {
  127. // RSL BUGBUG
  128. // RSL BG_CHK(FALSE);
  129. // RSL goto error;
  130. uSpace = sizeof(pTG->ProtInst.SendParams);
  131. if(lpbc->wTotalSize > uSpace)
  132. goto nospace;
  133. // _fmemcpy(&pTG->ProtInst.SendParams, lpbc, lpbc->wTotalSize);
  134. pTG->ProtInst.fSendParamsInited = TRUE;
  135. }
  136. break;
  137. default:
  138. BG_CHK(FALSE);
  139. goto error;
  140. break;
  141. }
  142. return TRUE;
  143. }
  144. else
  145. {
  146. BG_CHK(fSleep);
  147. (MyDebugPrint(pTG, LOG_ALL, "Ex ProtGetBC: bctype=%d --> FAILED\r\n", bctype));
  148. return FALSE;
  149. }
  150. nospace:
  151. (MyDebugPrint(pTG, LOG_ERR, "<<ERROR>> BC too big size=%d space=%d\r\n", lpbc->wTotalSize, uSpace));
  152. error:
  153. MyDebugPrint(pTG, LOG_ALL, "ATTENTION: ProtGetBC pTG->ProtInst.fAbort = TRUE\n");
  154. pTG->ProtInst.fAbort = TRUE;
  155. return FALSE;
  156. }
  157. #define SetupLL(npll, B, M, E, f64) \
  158. (((npll)->Baud=(BYTE)(B)), ((npll)->MinScan=(BYTE)(M)), ((npll)->fECM=(BYTE)(E)), ((npll)->fECM64=(BYTE)(f64)))
  159. BOOL WINAPI ET30ProtSetProtParams(PThrdGlbl pTG, LPPROTPARAMS lp, USHORT uSendSpeeds, USHORT uRecvSpeeds)
  160. {
  161. BG_CHK(uRecvSpeeds && uSendSpeeds);
  162. BG_CHK((uRecvSpeeds & ~BAUD_MASK) == 0);
  163. BG_CHK((uSendSpeeds & ~BAUD_MASK) == 0);
  164. BG_CHK(lp->uSize >= sizeof(pTG->ProtParams));
  165. _fmemcpy(&pTG->ProtParams, lp, min(sizeof(pTG->ProtParams), lp->uSize));
  166. // Hardware params
  167. SetupLL(&(pTG->ProtInst.llSendCaps), uRecvSpeeds, lp->uMinScan,
  168. !lp->DisableRecvECM, (lp->DisableRecvECM ? 0 : lp->Recv64ByteECM));
  169. pTG->ProtInst.fllSendCapsInited = TRUE;
  170. SetupLL(&(pTG->ProtInst.llSendParams), uSendSpeeds, MINSCAN_0_0_0,
  171. !lp->DisableSendECM, (lp->DisableSendECM ? 0 : lp->Send64ByteECM));
  172. pTG->ProtInst.fllSendParamsInited = TRUE;
  173. /*****
  174. pTG->ProtInst.llSendCaps.Baud = uRecvSpeeds;
  175. pTG->ProtInst.llSendCaps.MinScan = uMinScan;
  176. pTG->ProtInst.llSendParams.Baud = uSendSpeeds;
  177. pTG->ProtInst.llSendParams.MinScan = MINSCAN_0_0_0;
  178. ******/
  179. pTG->ProtInst.fHWCapsInited = TRUE;
  180. if(lp->HighestSendSpeed && lp->HighestSendSpeed != 0xFFFF)
  181. pTG->ProtInst.HighestSendSpeed = lp->HighestSendSpeed;
  182. else
  183. pTG->ProtInst.HighestSendSpeed = 0;
  184. if(lp->LowestSendSpeed && lp->LowestSendSpeed != 0xFFFF)
  185. pTG->ProtInst.LowestSendSpeed = lp->LowestSendSpeed;
  186. else
  187. pTG->ProtInst.LowestSendSpeed = 0;
  188. (MyDebugPrint(pTG, LOG_ALL, "Done with HW caps (recv, send)\r\n"));
  189. // OK to print -- not online
  190. D_PrintBC(0, "Recv HWCaps", &(pTG->ProtInst.llSendCaps));
  191. D_PrintBC(0, "Send HWCaps", &(pTG->ProtInst.llSendParams));
  192. (MyDebugPrint(pTG, LOG_ALL, "Highest=%d Lowest=%d\r\n", pTG->ProtInst.HighestSendSpeed, pTG->ProtInst.LowestSendSpeed));
  193. return TRUE;
  194. }
  195. void GetRecvPageAck(PThrdGlbl pTG)
  196. {
  197. USHORT uRet;
  198. pTG->ProtInst.fPageOK = 0;
  199. switch(uRet = ICommGetRecvPageAck(pTG, TRUE))
  200. {
  201. case 0:
  202. case 1: pTG->ProtInst.fPageOK = uRet;
  203. break;
  204. default:
  205. MyDebugPrint(pTG, LOG_ALL, "ATTENTION: GetRecvPageAck pTG->ProtInst.fAbort = TRUE\n");
  206. pTG->ProtInst.fAbort = TRUE;
  207. BG_CHK(FALSE);
  208. break;
  209. }
  210. (MyDebugPrint(pTG, LOG_ALL, "GetPageAck-->%d\r\n", uRet));
  211. }
  212. void WINAPI ET30ProtAbort(PThrdGlbl pTG, BOOL fEnable)
  213. {
  214. // bug#696 -- sometimes on aborts this gets called with fEnable==0
  215. // even after ET30ProtClose has been called. This is harmless so
  216. // don't BG_CHK. But it must _not_ be called with fEnable==TRUE
  217. // if pTG->ProtInst.fInUse is 0, i.e. we're not inited
  218. BG_CHK(fEnable ? pTG->ProtInst.fInUse : TRUE);
  219. // ICommFailureCode already set
  220. MyDebugPrint(pTG, LOG_ALL, "ATTENTION: ET30ProtAbort pTG->ProtInst.fAbort=%d\n", fEnable);
  221. pTG->ProtInst.fAbort = fEnable;
  222. }
  223. DWORD_PTR ProtExtFunction(PThrdGlbl pTG, USHORT uFunction)
  224. {
  225. NPPROT npProt = &pTG->ProtInst;
  226. BG_CHK(pTG->ProtInst.fInUse);
  227. switch(uFunction)
  228. {
  229. case GET_SEND_MOD: BG_CHK(npProt->fllNegotiated);
  230. return npProt->llNegot.Baud;
  231. case GET_RECV_MOD: BG_CHK(npProt->fllRecvParamsGot);
  232. return npProt->llRecvParams.Baud;
  233. case GET_ECM_FRAMESIZE: BG_CHK(npProt->fllNegotiated);
  234. return (npProt->llNegot.fECM64 ? 6 : 8);
  235. case GET_PPR_FIF: BG_CHK(npProt->fRecvdPPR);
  236. return (ULONG_PTR)((LPBYTE)npProt->bRemotePPR);
  237. case GET_WHATNEXT: return (ULONG_PTR)((LPWHATNEXTPROC)WhatNext);
  238. case GET_MINBYTESPERLINE: BG_CHK(npProt->fllNegotiated);
  239. return MinScanToBytesPerLine(pTG, npProt->llNegot.MinScan, npProt->llNegot.Baud);
  240. case RECEIVING_ECM: if(!npProt->fllRecvParamsGot)
  241. {
  242. (MyDebugPrint(pTG, LOG_ALL, "<<WARNING>> No RecvParams--assuming non-ECM\r\n"));
  243. return FALSE;
  244. }
  245. else
  246. return npProt->llRecvParams.fECM;
  247. case GET_RECV_ECM_FRAMESIZE:BG_CHK(npProt->fllRecvParamsGot);
  248. return (npProt->llRecvParams.fECM64 ? 6 : 8);
  249. case GET_RECVECMFRAMECOUNT: BG_CHK(npProt->fRecvdPPS);
  250. BG_CHK(npProt->uFramesInThisBlock);
  251. BG_CHK(npProt->uFramesInThisBlock <= 256);
  252. return (DWORD)(npProt->uFramesInThisBlock);
  253. case GET_PPS: return *((DWORD*)(npProt->bRemotePPS));
  254. case RESET_RECVECMFRAMECOUNT: npProt->uFramesInThisBlock=0;
  255. return 0;
  256. case RESET_RECVPAGEACK: npProt->fPageOK=FALSE;
  257. return 0;
  258. case GET_SEND_ENCODING: BG_CHK(npProt->fSendParamsInited);
  259. return npProt->SendParams.Fax.Encoding;
  260. case GET_RECV_ENCODING: BG_CHK(npProt->fRecvParamsGot);
  261. return npProt->RecvParams.Fax.Encoding;
  262. default: BG_CHK(FALSE); return 0;
  263. }
  264. }
  265. #ifdef DEBUG
  266. char* szBCTYPE[] = {
  267. "NONE",
  268. "SEND_CAPS",
  269. "RECV_CAPS",
  270. "SEND_PARAMS",
  271. "RECV_PARAMS",
  272. "SEND_POLLREQ",
  273. "RECV_POLLREQ"
  274. };
  275. void D_PrintBC(LPBC lpbc, LPSTR szll, LPLLPARAMS lpll)
  276. {
  277. int i;
  278. if(lpbc)
  279. {
  280. faxTlog((SZMOD "%s: Std: l=%d n=%d vMsg=%d fBin=%d fIn=%d vSec=%d vCmpr=%d OS=%d vFl=%d\r\n",
  281. (LPSTR)(szBCTYPE[lpbc->bctype]), lpbc->Std.GroupLength, lpbc->Std.GroupNum,
  282. lpbc->Std.vMsgProtocol, lpbc->Std.fBinaryData, lpbc->Std.fInwardRouting,
  283. lpbc->Std.vSecurity, lpbc->Std.vMsgCompress, lpbc->Std.OperatingSys,
  284. lpbc->Std.vShortFlags));
  285. faxTlog((SZMOD " vInt=%d Dspd=%x Dlnk=%x Fax: fPol=%d Res=%x Enc=%x Wid=%x Len=%x\r\n",
  286. lpbc->Std.vInteractive, lpbc->Std.DataSpeed, lpbc->Std.DataLink,
  287. lpbc->Fax.fPublicPoll,
  288. (WORD)lpbc->Fax.AwRes, lpbc->Fax.Encoding, lpbc->Fax.PageWidth,
  289. lpbc->Fax.PageLength));
  290. faxTlog((SZMOD " TextID: Code=%d Len=%d Id=%s\r\n",
  291. lpbc->wTextEncoding, lpbc->wTextIdLen, (LPSTR)(lpbc->wszTextId ? OffToLP(lpbc, wszTextId) : "none") ));
  292. // faxTlog((SZMOD " NumID: Id=%s\r\n",
  293. // (LPSTR)(lpbc->wszNumId ? OffToLP(lpbc, wszNumId) : "none") ));
  294. faxTlog((SZMOD " NSS: l=%d n=%d vMsg=%d vInter=%d\r\n",
  295. lpbc->NSS.GroupLength, lpbc->NSS.GroupNum,
  296. lpbc->NSS.vMsgProtocol, lpbc->NSS.vInteractive));
  297. faxTlog((SZMOD " Image: len=%d num=%d Poll: len=%d num=%d fHi=%d fLo=%d\r\n",
  298. lpbc->Image.GroupLength, lpbc->Image.GroupNum,
  299. lpbc->PollCaps.GroupLength, lpbc->PollCaps.GroupNum,
  300. lpbc->PollCaps.fHighSpeedPoll, lpbc->PollCaps.fLowSpeedPoll));
  301. #ifdef NOCHALL
  302. faxTlog((SZMOD " PollReq: num=%d\r\n", lpbc->wNumPollReq));
  303. #else
  304. faxTlog((SZMOD " PollReq: num=%d ChallLen=%d\r\n",
  305. lpbc->wNumPollReq, lpbc->wChallengeLen));
  306. #endif
  307. for(i=0; i<(int)lpbc->wNumPollReq && i<MAXNSCPOLLREQ; i++)
  308. {
  309. LPBCPOLLREQ lp = (LPBCPOLLREQ)OffToLP(lpbc, rgwPollReq[i]);
  310. faxTlog((SZMOD " PollReq[%d]: len=%d num=%d fRet=%d type=%d Title=%s\r\n",
  311. i, lp->GroupLength, lp->GroupNum, lp->fReturnControl, lp->PollType,
  312. (LPSTR)(lp->b) ));
  313. }
  314. }
  315. if(lpll)
  316. {
  317. BG_CHK(szll);
  318. faxTlog((SZMOD "%s: Baud=%x MinScan=%x ECM=%d 64=%d\r\n", (LPSTR)szll,
  319. lpll->Baud, lpll->MinScan, lpll->fECM, lpll->fECM64));
  320. }
  321. }
  322. #endif