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.

503 lines
23 KiB

  1. /***************************************************************************
  2. Name : AWNSFINT.H
  3. Comment : INTERNAL-ONLY Definitions of BC and NSF related structs
  4. Copyright (c) 1993 Microsoft Corp.
  5. Revision Log
  6. Date Name Description
  7. -------- ----- ---------------------------------------------------------
  8. 08/28/93 arulm Modifying aftering adding encryption
  9. ***************************************************************************/
  10. #ifndef _AWNSFINT_H
  11. #define _AWNSFINT_H
  12. #include <awnsfcor.h>
  13. #include <fr.h>
  14. /***********************************************************************
  15. * *
  16. * NOTICE: This file has to be ANSI compilable, under GCC on UNIX *
  17. * and other ANSI compiles. Be sure to use no MS C specific features *
  18. * In particular, don't use // for comments!!!! *
  19. * *
  20. ***********************************************************************/
  21. #pragma pack(2) /* ensure portable packing (i.e. 2 or more) */
  22. /* these sizes should remain constant across all platforms */
  23. #define GRPSIZE_STD 5
  24. #define GRPSIZE_IMAGE 6
  25. #define GRPSIZE_POLLCAPS 5
  26. #define GRPSIZE_NSS 3
  27. #define GRPSIZE_FAX 12
  28. #define BCEXTRA_TEXTID 64 /** space for one 60-byte Text ID **/
  29. #define BCEXTRA_POLL 128 /** space for reasonable poll requests **/
  30. #define BCEXTRA_HUGE 640 /** space for everything, probably.... **/
  31. #define MAXNSCPOLLREQ 5
  32. #ifndef NOCHALL
  33. # define POLL_CHALLENGE_LEN 10
  34. #endif
  35. #ifdef PORTABLE /* ANSI C */
  36. typedef struct { BYTE b[GRPSIZE_STD]; } BCSTD;
  37. typedef struct { BYTE b[GRPSIZE_IMAGE]; } BCIMAGE;
  38. typedef struct { BYTE b[GRPSIZE_POLLCAPS]; } BCPOLLCAPS;
  39. typedef struct { BYTE b[GRPSIZE_NSS]; } BCNSS;
  40. typedef struct { BYTE b[GRPSIZE_FAX]; } BCFAX;
  41. typedef struct
  42. {
  43. BCTYPE bctype;
  44. WORD wBCSize;
  45. WORD wBCVer;
  46. WORD wBCSig;
  47. WORD wTotalSize; /** total size of header + associated var len strings **/
  48. BCSTD Std;
  49. BCIMAGE Image;
  50. BCPOLLCAPS PollCaps;
  51. BCNSS NSS;
  52. BCFAX Fax;
  53. WORD wTextEncoding; /** char set code see above **/
  54. WORD wTextIdLen; /** length of text id **/
  55. WORD wszTextId; /** offset from start of struct to zero-term szTextId **/
  56. WORD wMachineIdLen; /** size of Machine Id (not zero-terminated) **/
  57. WORD wrgbMachineId; /** offset from start of struct to zero-term szNumId **/
  58. /* WORD wszNumId; */ /** offset from start of struct to zero-term szNumId **/
  59. WORD wszRecipSubAddr; /* offset from start of struct to zero-term SUB frame */
  60. WORD wRecipSubAddrLen; /* length of SUB frame */
  61. WORD wNumPollReq; /** number of SEPPWDOFF structs i.e. size of following array **/
  62. WORD rgwPollReq[MAXNSCPOLLREQ]; /** array of offsets to POLLREQ structures **/
  63. #ifndef NOCHALL
  64. WORD wChallengeLen; /** length of challenge string **/
  65. WORD wChallenge; /** offset to challenge string **/
  66. #endif
  67. BYTE b[BCEXTRA_HUGE];
  68. DWORD Guard;
  69. }
  70. BCwithHUGE, FAR* LPBC, NEAR* NPBC;
  71. #define BC_SIZE (sizeof(BCwithHUGE)-BCEXTRA_HUGE-sizeof(DWORD))
  72. #else /* Microsoft C only */
  73. /********
  74. @doc EXTERNAL DATATYPES OEMNSF
  75. @types BCFAX | Fax Capabilities Group
  76. @field BOOL | fPublicPoll | Blind/Public poll availability/request
  77. @field DWORD | AwRes | Resolution Capabilities or Mode. See <t STD_RESOLUTIONS> for values.
  78. @field WORD | Encoding | Encoding Capabilities or Mode. See <t STD_DATA_TYPES>
  79. @field WORD | PageWidth | Page Width Capabilities or Mode. See <t FAX_PAGE_WIDTHS>
  80. @field WORD | PageLength | Page Length Capabilities or Mode. See <t FAX_PAGE_LENGTHS>
  81. ********/
  82. typedef struct
  83. {
  84. ///////// This structure is not transmitted /////////
  85. WORD fPublicPoll;
  86. //2bytes
  87. DWORD AwRes; /* One or more of the AWRES_ #defines */
  88. WORD Encoding; /* One or more of MH_DATA/MR_DATA/MMR_DATA */
  89. WORD PageWidth; /* One of the WIDTH_ #defines (these are not bitflags!) */
  90. WORD PageLength; /* One of the LENGTH_ #defines (these are not bitflags!) */
  91. //12 bytes
  92. }
  93. BCFAX, far* LPBCFAX, near* NPBCFAX;
  94. /********
  95. @doc EXTERNAL DATATYPES OEMNSF
  96. @types BC | Basic Capabilities structure corresponding
  97. to sent or received NSF, NSS or NSC frames.
  98. @field BCTYPE | bctype | Type of BC structure. Must always be set. See <t BCTYPE> for values.
  99. @field WORD | wBCSize| Size of this (fixed size) AWBC struct. Must always be set.
  100. @field WORD | wBCVer | Version. Currently set it to VER_AWFXPROT100.
  101. @field WORD | wBCSig | Set to VER_AWFXPROT100.
  102. @field BCSTD | Std | Standard Capability group. See <t BCSTD> for details.
  103. @field BCIMAGE | Image | Image Capability group. See <t BCIMAGE> for details.
  104. @field BCPOLLCAPS | PollCaps | PollCaps Capability group. See <t BCPOLLCAPS> for details.
  105. @field BCNSS | NSS | NSS Capability group. See <t BCNSS> for details.
  106. @field BCFAX | Fax | Fax Capability group. See <t BCFAX> for details.
  107. @field WORD | wTextEncoding | Character-Set code used in TextId
  108. @field WORD | wTextIdLen | Length of TextId in bytes
  109. @field WORD | wszTextId | Offset from start of struct to zero-term szTextId
  110. @field WORD | wMachineIdLen | Length of MachineId in bytes (not zero-terminated)
  111. @field WORD | wrgbMachineId | Offset from start of struct to MachineId.
  112. @field WORD | wszRecipSubAddr | Offset from start of struct to zero-term SubAddress.
  113. @field WORD | wRecipSubAddrLen | Length of SubAddress.
  114. |
  115. @field WORD | wNumPollReq | Number of valid PollReqs in the following array. Cannot exceed MAXNSCPOLLREQ.
  116. @field WORD | rgwPollReq[] | Array of offsets (from start of struct) to POLLREQ structures.
  117. |
  118. @field WORD | wChallengeLen | Length of the Password-Challenge string
  119. @field WORD | wChallenge | Offset (from start of struct) to Challenge string
  120. @xref <t BCTYPE>
  121. ********/
  122. typedef struct
  123. {
  124. BCTYPE bctype; // must always be set. One of the enum values above
  125. WORD wBCSize; // size of this (fixed size) BC struct, must be set
  126. WORD wBCVer; // if using this header file, set it to VER_AWFXPROT100
  127. WORD wBCSig; // if using this header file, set it to VER_AWFXPROT100
  128. WORD wTotalSize; // total size of header + associated var len strings
  129. BCSTD Std;
  130. BCIMAGE Image;
  131. BCPOLLCAPS PollCaps;
  132. BCNSS NSS;
  133. BCFAX Fax; // for internal use _only_
  134. WORD wTextEncoding; // char set code
  135. WORD wTextIdLen; // length of text id
  136. WORD wszTextId; // offset from start of struct to zero-term szTextId
  137. WORD wMachineIdLen; // size of Machine Id (not zero-terminated)
  138. WORD wrgbMachineId; // offset from start of struct to zero-term szNumId
  139. // WORD wszNumId; // offset from start of struct to zero-term szNumId
  140. WORD wszRecipSubAddr; // offset from start of struct to zero-term SUB frame
  141. WORD wRecipSubAddrLen; // length of SUB frame
  142. WORD wNumPollReq; // size of following array
  143. WORD rgwPollReq[MAXNSCPOLLREQ]; // array of offsets to POLLREQ structures
  144. #ifndef NOCHALL
  145. WORD wChallengeLen; // length of challenge string
  146. WORD wChallenge; // offset to challenge string
  147. #endif //!NOCHALL
  148. }
  149. BC, far* LPBC, near* NPBC;
  150. #define BC_SIZE sizeof(BC)
  151. //#ifndef __cplusplus
  152. typedef struct
  153. {
  154. #ifndef __cplusplus
  155. BC;
  156. #else
  157. BC bc;
  158. #endif //!__cplusplus
  159. BYTE b[BCEXTRA_TEXTID];
  160. DWORD Guard;
  161. }
  162. BCwithTEXT;
  163. typedef struct
  164. {
  165. #ifndef __cplusplus
  166. BC;
  167. #else
  168. BC bc;
  169. #endif //!__cplusplus
  170. BYTE b[BCEXTRA_POLL];
  171. DWORD Guard;
  172. }
  173. BCwithPOLL;
  174. typedef struct
  175. {
  176. #ifndef __cplusplus
  177. BC;
  178. #else
  179. BC bc;
  180. #endif //!__cplusplus
  181. BYTE b[BCEXTRA_HUGE];
  182. DWORD Guard;
  183. }
  184. BCwithHUGE;
  185. //#endif //!__cplusplus
  186. /**------------------- ACK struct ----------------**/
  187. typedef struct
  188. {
  189. BCTYPE bctype; // must always be set. One of SEND_ACK or SEND_DISCONNECT
  190. WORD wACKSize; // size of this (fixed size) ACK struct, must be set
  191. WORD wACKVer; // if using this header file, set it to VER_AWFXPROT100
  192. WORD wACKSig; // if using this header file, set it to VER_AWFXPROT100
  193. BOOL fAck;
  194. }
  195. ACK, far* LPACK;
  196. #endif /** PORTABLE **/
  197. #define AppendToBCLen(lpbc, uMax, lpb, uLen, wOff, wLen) \
  198. { USHORT uCopy; \
  199. LPBYTE lpbTo; \
  200. BG_CHK((lpbc) && (uMax) && (lpb) && (uLen)); \
  201. BG_CHK((lpbc)->wTotalSize >= sizeof(BC)); \
  202. if((lpbc)->wTotalSize+1 < (uMax)) \
  203. { \
  204. uCopy = min((uLen), (uMax)-1-(lpbc)->wTotalSize); \
  205. BG_CHK(uCopy == (uLen)); \
  206. lpbTo = ((LPBYTE)(lpbc))+(lpbc)->wTotalSize; \
  207. _fmemcpy(lpbTo, (lpb), uCopy); \
  208. lpbTo[uCopy] = 0; \
  209. (lpbc)->wOff = (lpbc)->wTotalSize; \
  210. (lpbc)->wLen = uCopy; \
  211. (lpbc)->wTotalSize += uCopy+1; \
  212. } \
  213. BG_CHK((lpbc)->wTotalSize <= uMax); \
  214. }
  215. #define AppendToBCOff(lpbc, uMax, lpb, uLen, wOff) \
  216. { USHORT uCopy; \
  217. LPBYTE lpbTo; \
  218. BG_CHK((lpbc) && (uMax) && (lpb) && (uLen)); \
  219. BG_CHK((lpbc)->wTotalSize >= sizeof(BC)); \
  220. if((lpbc)->wTotalSize+1 < (uMax)) \
  221. { \
  222. uCopy = min((uLen), (uMax)-1-(lpbc)->wTotalSize); \
  223. BG_CHK(uCopy == (uLen)); \
  224. lpbTo = ((LPBYTE)(lpbc))+(lpbc)->wTotalSize; \
  225. _fmemcpy(lpbTo, (lpb), uCopy); \
  226. lpbTo[uCopy] = 0; \
  227. (lpbc)->wOff = (lpbc)->wTotalSize; \
  228. (lpbc)->wTotalSize += uCopy+1; \
  229. } \
  230. BG_CHK((lpbc)->wTotalSize <= uMax); \
  231. }
  232. #define AppendToBC(lpbc, uMax, lpb, uLen) \
  233. { USHORT uCopy; \
  234. LPBYTE lpbTo; \
  235. BG_CHK((lpbc) && (uMax) && (lpb) && (uLen)); \
  236. BG_CHK((lpbc)->wTotalSize >= sizeof(BC)); \
  237. if((lpbc)->wTotalSize+1 < (uMax)) \
  238. { \
  239. uCopy = min((uLen), (uMax)-1-(lpbc)->wTotalSize); \
  240. BG_CHK(uCopy == (uLen)); \
  241. lpbTo = ((LPBYTE)(lpbc))+(lpbc)->wTotalSize; \
  242. _fmemcpy(lpbTo, (lpb), uCopy); \
  243. lpbTo[uCopy] = 0; \
  244. (lpbc)->wTotalSize += uCopy+1; \
  245. } \
  246. BG_CHK((lpbc)->wTotalSize <= uMax); \
  247. }
  248. #define InitBC(lpbc, uSize, t) \
  249. { \
  250. _fmemset((lpbc), 0, (uSize)); \
  251. (lpbc)->bctype = (t); \
  252. (lpbc)->wBCSize = sizeof(BC); \
  253. (lpbc)->wBCVer = VER_AWFXPROT100; \
  254. (lpbc)->wBCSig = VER_AWFXPROT100; \
  255. (lpbc)->wTotalSize = sizeof(BC); \
  256. }
  257. #define GetTextId(lpbc, lpbOut, uMax) \
  258. BG_CHK((lpbOut) && (lpbc) && (uMax)); \
  259. ((LPBYTE)(lpbOut))[0] = 0; \
  260. if( (lpbc)->wTextIdLen && (lpbc)->wszTextId && \
  261. (lpbc)->wszTextId < (lpbc)->wTotalSize && \
  262. (lpbc)->wszTextId+(lpbc)->wTextIdLen <= (lpbc)->wTotalSize) \
  263. { \
  264. USHORT uLen; \
  265. uLen = min(((uMax)-1), (lpbc)->wTextIdLen); \
  266. _fmemcpy((lpbOut), (((LPBYTE)(lpbc)) + (lpbc)->wszTextId), uLen); \
  267. ((LPBYTE)(lpbOut))[uLen] = 0; \
  268. }
  269. #define PutTextId(lpbc, uMax, lpbIn, uLen, enc) \
  270. if(uLen) { AppendToBCLen(lpbc, uMax, lpbIn, uLen, wszTextId, wTextIdLen);\
  271. (lpbc)->wTextEncoding = (enc); }
  272. #define HasTextId(lpbc) ((lpbc)->wTextIdLen && (lpbc)->wszTextId)
  273. #define PutRecipSubAddr(lpbc, uMax, lpbIn, uLen) \
  274. if(uLen) { AppendToBCLen(lpbc, uMax, lpbIn, uLen, wszRecipSubAddr, wRecipSubAddrLen); }
  275. #define GetRecipSubAddr(lpbc, lpbOut, uMax) \
  276. BG_CHK((lpbOut) && (lpbc) && (uMax)); \
  277. ((LPBYTE)(lpbOut))[0] = 0; \
  278. if( (lpbc)->wRecipSubAddrLen && (lpbc)->wszRecipSubAddr && \
  279. (lpbc)->wszRecipSubAddr < (lpbc)->wTotalSize && \
  280. (lpbc)->wszRecipSubAddr+(lpbc)->wRecipSubAddrLen <= (lpbc)->wTotalSize) \
  281. { \
  282. USHORT uLen; \
  283. uLen = min(((uMax)-1), (lpbc)->wRecipSubAddrLen); \
  284. _fmemcpy((lpbOut), (((LPBYTE)(lpbc)) + (lpbc)->wszRecipSubAddr), uLen); \
  285. ((LPBYTE)(lpbOut))[uLen] = 0; \
  286. }
  287. #define HasRecipSubAddr(lpbc) ((lpbc)->wRecipSubAddrLen && (lpbc)->wszRecipSubAddr)
  288. /* returns FALSE (and doesnt caopy anything) if destination is too small */
  289. #define CopyBC(lpbcOut, wMaxOut, lpbcIn) \
  290. ( (wMaxOut < lpbcIn->wTotalSize) ? FALSE : \
  291. (_fmemcpy(lpbcOut, lpbcIn, lpbcIn->wTotalSize), TRUE) )
  292. /** not for general use **/
  293. /** #define DeleteTextId(lpbc) ((lpbc)->wszTextId=(lpbc)->wTextIdLen=(lpbc)->wTextEncoding=0) **/
  294. #define OffToNP(npbc, off) (((npbc)->off) ? (((NPBYTE)(npbc)) + ((npbc)->off)) : NULL)
  295. #define OffToLP(lpbc, off) (((lpbc)->off) ? (((LPBYTE)(lpbc)) + ((lpbc)->off)) : NULL)
  296. #define OFF_CHK(lpbc, off) BG_CHK((lpbc)->off >= sizeof(BC) && (lpbc)->off <= (lpbc)->wTotalSize)
  297. #if defined(IFBGPROC) || defined(IFFGPROC)
  298. # define EXPORTBC _export WINAPI
  299. #else
  300. # define EXPORTBC
  301. #endif
  302. /***************************************************************************
  303. @doc INTERNAL
  304. @api WORD | NSxtoBC | Called to parse received Microsoft At Work NSx
  305. frames and fill in a BC structure.
  306. @parm IFR | ifr | This must be set to ifrNSF for parsing Capabilities
  307. (NSF/DIS) and to ifrNSS for parsing Mode/Parameters (NSS/DCS)
  308. @parm LPFR[] | rglpfr | [in] Pointer to array of LPFR pointers which
  309. point to FR structures that contain the received frame(s).
  310. @parm WORD | wNumFrame | [in] Number of received frames i.e. length of
  311. the above array of pointers
  312. @parm LPBC | lpbcOut | [out] Pointer to output BC struct
  313. @parm WORD | wBCSize | [in] size of the above AWBC struct.
  314. @rdesc Returns AWERROR_OK on success, otherwise one of the other
  315. AWERROR_ values.
  316. @xref <t IFR> <t FR> <t BC>
  317. ***************************************************************************/
  318. /***************************************************************************
  319. @doc INTERNAL
  320. @api WORD | BCtoNSx | Called to create Microsoft At Work NSx frames
  321. from a BC struct
  322. @parm IFR | ifr | This must be set to ifrNSF for creating Capabilities
  323. (NSF/DIS) and to ifrNSS for creating Mode/Parameters (NSS/DCS)
  324. @parm LPBC | lpbcIn | [in] Pointer to input BC struct.
  325. @parm LPBYTE | lpbOut | [out] Pointer to space where the NSx frames
  326. will be created. On successful return this will point to an array
  327. of *lpwNumFrame pointers to FR structures, (i.e. on return the
  328. start of this buffer contains an LPFR[] array that is *lpwNumFrame
  329. items long). The pointers point to the actual (variable-length)
  330. FR stuctures which are placed in the buffer following this
  331. array of pointers.
  332. @parm WORD | wMaxOut | [in] Length of the above buffer. It is
  333. reccomended that this be at least 256 bytes long
  334. @parm LPWORD | lpwNumFrame | [out] Number of NSx frames created. Also
  335. length of the LPFR[] array created in the supplied buffer.
  336. @rdesc Returns AWERROR_OK on success, otherwise one of the other
  337. AWERROR_ values.
  338. @xref <t IFR> <t FR> <t BC>
  339. ***************************************************************************/
  340. #if defined(IFBGPROC) || defined(IFFGPROC)
  341. // internal APIs only!
  342. /***************************************************************************
  343. @doc INTERNAL
  344. @api WORD | DIStoBCFAX | Parses a DIS into a BCFAX
  345. @parm LPBYTE | lpbDIS | [in] Pointer to DIS (FIF part only)
  346. @parm WORD | wLenDIS | [in] length of DIS
  347. @parm LPBCFAX | lpbcfax | [out] Pointer to BCFAX struct to be filled in
  348. @parm WORD | wLenBCFAX | [in] length of BCFAX struct
  349. @rdesc Returns length of BCFAX filled in on success. 0 on failure
  350. @comm **NOTE**: Be sure to call this function _after_ calling NSxtoBC,
  351. because NSxtoBC zeros out the entire BC struct, _including_ the
  352. BCFAX part, so if the order were reversed, the data parsed from
  353. the DIS would be lost.
  354. @xref <t IFR> <t BCFAX>
  355. ***************************************************************************/
  356. WORD EXPORTBC DIStoBCFAX(IFR ifr, LPBYTE lpbDIS, WORD wLenDIS, LPBCFAX lpbcfax, WORD wLenBCFAX);
  357. /***************************************************************************
  358. @doc INTERNAL
  359. @api WORD | BCFAXtoDIS | Creates a DIS from a BCFAX
  360. @parm LPBCFAX | lpbcfax | [in] Pointer to BCFAX struct
  361. @parm WORD | wLenBCFAX | [in] length of BCFAX struct
  362. @parm LPBYTE | lpbDIS | [out] Pointer to space for DIS (FIF part only).
  363. Note: This API does _not_ create an FR struct!!
  364. @parm WORD | wLenDIS | [in] length of buffer provided for DIS
  365. @rdesc Returns length of DIS created on success. 0 on failure
  366. @xref <t IFR> <t BCFAX>
  367. ***************************************************************************/
  368. WORD EXPORTBC BCFAXtoDIS(IFR ifr, LPBCFAX lpbcfax, WORD wLenBCFAX, LPBYTE lpbDIS, WORD wLenDIS);
  369. #endif /* IFBGPROC || IFFGPROC */
  370. #pragma pack()
  371. #endif /** _AWNSFINT_H **/