Leaked source code of windows server 2003
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.

324 lines
12 KiB

  1. /*****************************************************************************
  2. *
  3. * Copyright (c) 1995 Microsoft Corporation
  4. *
  5. * File: irlap.h
  6. *
  7. * Description: IRLAP Protocol and control block definitions
  8. *
  9. * Author: mbert
  10. *
  11. * Date: 4/15/95
  12. *
  13. */
  14. #define UNICODE_CHAR_SET 0xFF
  15. #define IRLAP_MEDIA_SENSE_TIME 500
  16. #define IRLAP_SLOT_TIMEOUT 50
  17. #define IRLAP_DSCV_SENSE_TIME 110
  18. #define IRLAP_FAST_POLL_TIME 10
  19. #define IRLAP_FAST_POLL_COUNT 10
  20. // XID Format
  21. #define IRLAP_XID_DSCV_FORMAT_ID 0x01
  22. #define IRLAP_XID_NEGPARMS_FORMAT_ID 0x02
  23. typedef struct
  24. {
  25. UCHAR SrcAddr[IRDA_DEV_ADDR_LEN];
  26. UCHAR DestAddr[IRDA_DEV_ADDR_LEN];
  27. UCHAR NoOfSlots:2;
  28. UCHAR GenNewAddr:1;
  29. UCHAR Reserved:5;
  30. UCHAR SlotNo;
  31. UCHAR Version;
  32. UCHAR FirstDscvInfoByte;
  33. } IRLAP_XID_DSCV_FORMAT;
  34. // Frame Reject Format
  35. typedef struct
  36. {
  37. UCHAR CntlField;
  38. UCHAR Fill1:1;
  39. UCHAR Vs:3;
  40. UCHAR CRBit:1;
  41. UCHAR Vr:3;
  42. UCHAR W:1;
  43. UCHAR X:1;
  44. UCHAR Y:1;
  45. UCHAR Z:1;
  46. UCHAR Fill2:4;
  47. } IRLAP_FRMR_FORMAT;
  48. // SNRM Frame Format
  49. typedef struct
  50. {
  51. UCHAR SrcAddr[IRDA_DEV_ADDR_LEN];
  52. UCHAR DestAddr[IRDA_DEV_ADDR_LEN];
  53. UCHAR ConnAddr; // actually shifted for CRBit !!
  54. UCHAR FirstQosByte;
  55. } IRLAP_SNRM_FORMAT;
  56. // UA Frame Format
  57. typedef struct
  58. {
  59. UCHAR SrcAddr[IRDA_DEV_ADDR_LEN];
  60. UCHAR DestAddr[IRDA_DEV_ADDR_LEN];
  61. UCHAR FirstQosByte;
  62. } IRLAP_UA_FORMAT;
  63. #define IRLAP_MAX_TX_MSG_LIST_LEN 8
  64. #define IRLAP_MAX_DATA_SIZE 4096
  65. #define IRLAP_MAX_SLOTS 16
  66. #define IRLAP_CONTENTION_BAUD 9600
  67. #define IRLAP_CONTENTION_DATA_SIZE 64
  68. #define IRLAP_CONTENTION_MAX_TAT 500
  69. #define IRLAP_CONTENTION_BOFS 10
  70. #define IRLAP_CONTENTION_WIN_SIZE 1
  71. // Default Qos if not found in registry
  72. #define IRLAP_DEFAULT_DATASIZE (DATA_SIZE_64 | DATA_SIZE_128 | \
  73. DATA_SIZE_256 | DATA_SIZE_512 | \
  74. DATA_SIZE_1024| DATA_SIZE_2048)
  75. #define IRLAP_DEFAULT_WINDOWSIZE (FRAMES_1 | FRAMES_2 | FRAMES_3 | \
  76. FRAMES_4 | FRAMES_5 | FRAMES_6 | \
  77. FRAMES_7)
  78. #define IRLAP_DEFAULT_MAXTAT (MAX_TAT_500)
  79. #define IRLAP_DEFAULT_SLOTS 6
  80. #define IRLAP_DEFAULT_HINTCHARSET 0x8425ff // computer, IrCOMM, Obex, and telephony
  81. #define IRLAP_DEFAULT_DISCONNECTTIME DISC_TIME_12 | DISC_TIME_8 | DISC_TIME_3
  82. // Macros for extracting various fields
  83. #define IRLAP_GET_ADDR(addr) (addr >> 1)
  84. #define IRLAP_GET_CRBIT(addr) (addr & 1)
  85. #define IRLAP_GET_PFBIT(cntl) ((cntl >>4) & 1)
  86. #define IRLAP_GET_UCNTL(cntl) (cntl & 0xEF)
  87. #define IRLAP_GET_SCNTL(cntl) (cntl & 0x0F)
  88. #define IRLAP_FRAME_TYPE(cntl) (cntl & 0x01 ? (cntl & 3) : 0)
  89. #define IRLAP_GET_NR(cntl) ((cntl & 0xE0) >> 5)
  90. #define IRLAP_GET_NS(cntl) ((cntl & 0xE) >> 1)
  91. // IRLAP constants
  92. #define IRLAP_BROADCAST_CONN_ADDR 0x7F
  93. #define IRLAP_END_DSCV_SLOT_NO 0xFF
  94. #define IRLAP_CMD 1
  95. #define IRLAP_RSP 0
  96. #define IRLAP_PFBIT_SET 1
  97. #define IRLAP_PFBIT_CLEAR 0
  98. #define IRLAP_GEN_NEW_ADDR 1
  99. #define IRLAP_NO_NEW_ADDR 0
  100. // Macro for creating Number of Slots of Discovery Flags Field of XID Format
  101. // if S(Slots) <= 1 return 0, <= 6 return 1, <= 8 return 2, else return 3
  102. #define IRLAP_SLOT_FLAG(S) (S <= 1 ? 0 : (S <= 6 ? 1 : (S <= 8 ? 2 : 3)))
  103. int _inline IRLAP_RAND(int Min, int Max)
  104. {
  105. LARGE_INTEGER li;
  106. KeQueryTickCount(&li);
  107. return ((li.LowPart % (Max+1-Min)) + Min);
  108. }
  109. // Backoff time is a random time between 0.5 and 1.5 times the time to
  110. // send a SNRM. _SNRM_TIME() is actually half (1000ms/2) time to send
  111. // SNRM_LEN of characters at 9600 (9600/10 bits per char).
  112. #define _SNRM_LEN 32
  113. #define _SNRM_TIME() (_SNRM_LEN*500/960)
  114. #define IRLAP_BACKOFF_TIME() IRLAP_RAND(_SNRM_TIME(), 3*_SNRM_TIME())
  115. #define QOS_PI_BAUD 0x01
  116. #define QOS_PI_MAX_TAT 0x82
  117. #define QOS_PI_DATA_SZ 0x83
  118. #define QOS_PI_WIN_SZ 0x84
  119. #define QOS_PI_BOFS 0x85
  120. #define QOS_PI_MIN_TAT 0x86
  121. #define QOS_PI_DISC_THRESH 0x08
  122. #define IRLAP_I_FRAME 0x00
  123. #define IRLAP_S_FRAME 0x01
  124. #define IRLAP_U_FRAME 0x03
  125. // Unnumbered Frame types with P/F bit set to 0
  126. #define IRLAP_UI 0x03
  127. #define IRLAP_XID_CMD 0x2f
  128. #define IRLAP_TEST 0xe3
  129. #define IRLAP_SNRM 0x83
  130. #define IRLAP_RNRM 0x83
  131. #define IRLAP_DISC 0x43
  132. #define IRLAP_RD 0x43
  133. #define IRLAP_UA 0x63
  134. #define IRLAP_FRMR 0x87
  135. #define IRLAP_DM 0x0f
  136. #define IRLAP_XID_RSP 0xaf
  137. // Supervisory Frames
  138. #define IRLAP_RR 0x01
  139. #define IRLAP_RNR 0x05
  140. #define IRLAP_REJ 0x09
  141. #define IRLAP_SREJ 0x0d
  142. #define _MAKE_ADDR(Addr, CRBit) ((Addr << 1) + (CRBit & 1))
  143. #define _MAKE_UCNTL(Cntl, PFBit) (Cntl + ((PFBit & 1)<< 4))
  144. #define _MAKE_SCNTL(Cntl, PFBit, Nr) (Cntl + ((PFBit & 1)<< 4) + (Nr <<5))
  145. #define IRLAP_CB_SIG 0x7f2a364bUL
  146. // IRLAP Control Block
  147. typedef struct
  148. {
  149. IRDA_MSG *pMsg[IRLAP_MOD];
  150. UINT Start;
  151. UINT End;
  152. #ifdef TEMPERAMENTAL_SERIAL_DRIVER
  153. int FCS[IRLAP_MOD];
  154. #endif
  155. } IRLAP_WINDOW;
  156. typedef enum
  157. {
  158. PRIMARY,
  159. SECONDARY
  160. } IRLAP_STN_TYPE;
  161. typedef enum // KEEP IN SYNC with IRLAP_StateStr in irlaplog.c
  162. {
  163. NDM, // Normal Disconnect Mode
  164. DSCV_MEDIA_SENSE, // Discovery Media Sense (Before Discovery)
  165. DSCV_QUERY, // Discovery Query (Discovery initiated)
  166. DSCV_REPLY, // Discovery Reply (Received DSCV XID cmd from Remote)
  167. CONN_MEDIA_SENSE, // Connect Media Sense (Before connection estab)
  168. SNRM_SENT, // SNRM sent - waiting for UA or DM from Remote
  169. BACKOFF_WAIT, // Waiting random backoff before sending next SNRM
  170. SNRM_RECEIVED, // SNRM rcvd - waiting for response from upper layer
  171. P_XMIT, // Primary transmit
  172. P_RECV, // Primary receive
  173. P_DISCONNECT_PEND, // Upper layer request disconnect while in P_RECV
  174. P_CLOSE, // Sent DISC, waiting for response
  175. S_NRM, // Secondary Normal Response Mode XMIT/RECV
  176. S_DISCONNECT_PEND, // Upper layer request disconnect while in S_NRM
  177. S_ERROR, // Waiting for PF bit then send a FRMR
  178. S_CLOSE, // Requested disconnect (RD) waiting for DISC command
  179. } IRLAP_STATE;
  180. typedef struct IrlapControlBlock
  181. {
  182. IRLAP_STATE State;
  183. IRDA_DEVICE LocalDevice;
  184. IRDA_DEVICE RemoteDevice;
  185. PIRDA_LINK_CB pIrdaLinkCb;
  186. IRDA_QOS_PARMS LocalQos; // QOS from LMP
  187. IRDA_QOS_PARMS RemoteQos; // QOS of remote taken from SNRM/UA
  188. IRDA_QOS_PARMS NegotiatedQos; // Union of remote and local QOS
  189. int Baud; // Type 0 negotiation parm
  190. int DisconnectTime;// Type 0 negotiation parm
  191. int ThresholdTime; // Type 0 negotiotion parm
  192. int LocalMaxTAT; // Type 1 negotiation parm
  193. int LocalDataSize; // Type 1 negotiation parm
  194. int LocalWinSize; // Type 1 negotiation parm
  195. int LocalNumBOFS; // Type 1 negotiation parm
  196. int RemoteMaxTAT; // Type 1 negotiation parm
  197. int RemoteDataSize;// Type 1 negotiation parm
  198. int RemoteWinSize; // Type 1 negotiation parm
  199. int RemoteNumBOFS; // Type 1 negotiation parm
  200. int RemoteMinTAT; // Type 1 negotiation parm
  201. IRLAP_STN_TYPE StationType; // PRIMARY or SECONDARY
  202. int ConnAddr; // Connection Address
  203. int SNRMConnAddr; // Connection address contained in SNRM
  204. // save it until CONNECT_RESP is received
  205. int CRBit; // Primary = 1, Secondary = 0
  206. int RespSlot; // Secondary. Slot to respond in
  207. int SlotCnt; // Primary. Current slot number
  208. int MaxSlot; // Maximum slots to send in Dscv
  209. int RemoteMaxSlot; // Number of Dscv's remote will send
  210. LIST_ENTRY DevList; // Discovered device list
  211. UINT Vs; // send state variable
  212. UINT Vr; // receive state variable
  213. IRLAP_WINDOW RxWin; // Holds out of sequence rxd frames
  214. IRLAP_WINDOW TxWin; // Holds unacked txd frames
  215. LIST_ENTRY TxMsgList; // DATA_REQ, UDATA_REQ queued here
  216. LIST_ENTRY ExTxMsgList; // Expidited DATA_REQ, UDATA_REQ queued here
  217. int RetryCnt; // Count of number of retrans of DSCV,SNRM
  218. int N1; // const# retries before sending status up
  219. int N2; // const# retries before disconnecting
  220. int N3; // const# of connection retries
  221. int FastPollCount;
  222. IRDA_TIMER SlotTimer;
  223. IRDA_TIMER QueryTimer;
  224. IRDA_TIMER PollTimer;
  225. IRDA_TIMER FinalTimer;
  226. IRDA_TIMER WDogTimer;
  227. IRDA_TIMER BackoffTimer;
  228. IRDA_TIMER StatusTimer;
  229. int WDogExpCnt; // Count of WDog expirations
  230. int StatusSent; // Status ind has been sent
  231. int StatusFlags;
  232. int FTimerExpCnt;
  233. int RetranCnt;
  234. IRLAP_FRMR_FORMAT Frmr;
  235. BOOLEAN GenNewAddr; // Flag indicating whether to set new addr
  236. BOOLEAN DscvRespSent; // Secondary. Sent XID Discv response
  237. BOOLEAN RemoteBusy; // Remote has sent a RNR
  238. BOOLEAN LocalBusy; // Local busy condition, we sent RNR
  239. BOOLEAN ClrLocalBusy; // Send RR
  240. BOOLEAN LocalDiscReq; // why 2ndary got DISC
  241. BOOLEAN ConnAfterClose;// Conn req while in p_close
  242. BOOLEAN DscvAfterClose;// Dscv_req while in p_close
  243. BOOLEAN NoResponse; // Final/WD timer exp'd, used with RetryCnt
  244. BOOLEAN MonitorLink;
  245. #if 1 //DBG
  246. int DelayedConf;
  247. int ActCnt[16];
  248. int NestedEvent;
  249. #endif
  250. } IRLAP_CB, *PIRLAP_CB;
  251. #define LINE_CAPACITY(icb) (icb->RemoteWinSize * \
  252. (icb->RemoteDataSize + \
  253. 6+icb->RemoteNumBOFS))
  254. UCHAR *BuildNegParms(UCHAR *pBuf, IRDA_QOS_PARMS *pQos);
  255. void StoreULAddr(UCHAR Addr[], ULONG ULAddr);
  256. UCHAR *Format_SNRM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
  257. UCHAR SAddr[], UCHAR DAddr[], int CAddr,
  258. IRDA_QOS_PARMS *pQos);
  259. UCHAR *Format_DISC(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit);
  260. UCHAR *Format_UI(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit);
  261. UCHAR *Format_DscvXID(IRDA_MSG *pMsg, int ConnAddr, int CRBit, int PFBit,
  262. IRLAP_XID_DSCV_FORMAT *pXidFormat, CHAR DscvInfo[],
  263. int Len);
  264. UCHAR *Format_TEST(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
  265. UCHAR SAddr[], UCHAR DAddr[]);
  266. UCHAR *Format_RNRM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit);
  267. UCHAR *Format_UA(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
  268. UCHAR SAddr[], UCHAR DAddr[], IRDA_QOS_PARMS *pQos);
  269. UCHAR *Format_FRMR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit,
  270. IRLAP_FRMR_FORMAT *pFormat);
  271. UCHAR *Format_DM(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit);
  272. UCHAR *Format_RD(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit);
  273. UCHAR *Format_RR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr);
  274. UCHAR *Format_RNR(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr);
  275. UCHAR *Format_REJ(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr);
  276. UCHAR *Format_SREJ(IRDA_MSG *pMsg, int Addr, int CRBit, int PFBit, int Nr);
  277. UCHAR * Format_I(IRDA_MSG *pMsg, int Addr, int CRBit,
  278. int PFBit, int Nr, int Ns);
  279. int GetMyDevAddr(BOOLEAN New);