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.

372 lines
10 KiB

  1. /*++
  2. Copyright(c) 1998,99 Microsoft Corporation
  3. Module Name:
  4. univ.c
  5. Abstract:
  6. Windows Load Balancing Service (WLBS)
  7. Driver - global variables
  8. Author:
  9. kyrilf
  10. --*/
  11. #include <stdlib.h>
  12. #include <ndis.h>
  13. #include "univ.h"
  14. #include "wlbsparm.h"
  15. /* GLOBALS */
  16. /* The global teaming list spin lock. */
  17. NDIS_SPIN_LOCK univ_bda_teaming_lock;
  18. // UNIV_ADAPTER univ_adapters [CVY_MAX_ADAPTERS]; // ###### ramkrish
  19. WCHAR empty_str [] = L"";
  20. UNIV_IOCTL_HDLR univ_ioctl_hdlr = NULL;
  21. PVOID univ_driver_ptr = NULL;
  22. NDIS_HANDLE univ_driver_handle = NULL;
  23. NDIS_HANDLE univ_wrapper_handle = NULL;
  24. NDIS_HANDLE univ_prot_handle = NULL;
  25. NDIS_HANDLE univ_ctxt_handle = NULL;
  26. // ###### ramkrish ULONG univ_convoy_enabled;
  27. // ###### ramkrish ULONG univ_bound = FALSE;
  28. // ###### ramkrish ULONG univ_announced = FALSE;
  29. NDIS_SPIN_LOCK univ_bind_lock;
  30. ULONG univ_changing_ip = 0;
  31. // ###### ramkrish ULONG univ_inited = FALSE;
  32. NDIS_HANDLE univ_device_handle = NULL;
  33. PDEVICE_OBJECT univ_device_object = NULL;
  34. NDIS_PHYSICAL_ADDRESS univ_max_addr = NDIS_PHYSICAL_ADDRESS_CONST (-1,-1);
  35. NDIS_MEDIUM univ_medium_array [UNIV_NUM_MEDIUMS] = UNIV_MEDIUMS;
  36. // ###### ramkrish ULONG univ_params_valid = FALSE;
  37. // ###### ramkrish CVY_PARAMS univ_params;
  38. PWCHAR univ_reg_path = NULL;
  39. ULONG univ_reg_path_len = 0;
  40. // ###### ramkrish ULONG univ_optimized_frags = FALSE;
  41. NDIS_OID univ_oids [UNIV_NUM_OIDS] =
  42. { OID_GEN_SUPPORTED_LIST,
  43. OID_GEN_HARDWARE_STATUS,
  44. OID_GEN_MEDIA_SUPPORTED,
  45. OID_GEN_MEDIA_IN_USE,
  46. OID_GEN_MAXIMUM_LOOKAHEAD,
  47. OID_GEN_MAXIMUM_FRAME_SIZE,
  48. OID_GEN_LINK_SPEED,
  49. OID_GEN_TRANSMIT_BUFFER_SPACE,
  50. OID_GEN_RECEIVE_BUFFER_SPACE,
  51. OID_GEN_TRANSMIT_BLOCK_SIZE,
  52. OID_GEN_RECEIVE_BLOCK_SIZE,
  53. OID_GEN_VENDOR_ID,
  54. OID_GEN_VENDOR_DESCRIPTION,
  55. OID_GEN_CURRENT_PACKET_FILTER,
  56. OID_GEN_CURRENT_LOOKAHEAD,
  57. OID_GEN_DRIVER_VERSION,
  58. OID_GEN_MAXIMUM_TOTAL_SIZE,
  59. OID_GEN_PROTOCOL_OPTIONS,
  60. OID_GEN_MAC_OPTIONS,
  61. OID_GEN_MEDIA_CONNECT_STATUS,
  62. OID_GEN_MAXIMUM_SEND_PACKETS,
  63. OID_GEN_VENDOR_DRIVER_VERSION,
  64. OID_GEN_XMIT_OK,
  65. OID_GEN_RCV_OK,
  66. OID_GEN_XMIT_ERROR,
  67. OID_GEN_RCV_ERROR,
  68. OID_GEN_RCV_NO_BUFFER,
  69. OID_GEN_DIRECTED_BYTES_XMIT,
  70. OID_GEN_DIRECTED_FRAMES_XMIT,
  71. OID_GEN_MULTICAST_BYTES_XMIT,
  72. OID_GEN_MULTICAST_FRAMES_XMIT,
  73. OID_GEN_BROADCAST_BYTES_XMIT,
  74. OID_GEN_BROADCAST_FRAMES_XMIT,
  75. OID_GEN_DIRECTED_BYTES_RCV,
  76. OID_GEN_DIRECTED_FRAMES_RCV,
  77. OID_GEN_MULTICAST_BYTES_RCV,
  78. OID_GEN_MULTICAST_FRAMES_RCV,
  79. OID_GEN_BROADCAST_BYTES_RCV,
  80. OID_GEN_BROADCAST_FRAMES_RCV,
  81. OID_GEN_RCV_CRC_ERROR,
  82. OID_GEN_TRANSMIT_QUEUE_LENGTH,
  83. OID_802_3_PERMANENT_ADDRESS,
  84. OID_802_3_CURRENT_ADDRESS,
  85. OID_802_3_MULTICAST_LIST,
  86. OID_802_3_MAXIMUM_LIST_SIZE,
  87. OID_802_3_MAC_OPTIONS,
  88. OID_802_3_RCV_ERROR_ALIGNMENT,
  89. OID_802_3_XMIT_ONE_COLLISION,
  90. OID_802_3_XMIT_MORE_COLLISIONS,
  91. OID_802_3_XMIT_DEFERRED,
  92. OID_802_3_XMIT_MAX_COLLISIONS,
  93. OID_802_3_RCV_OVERRUN,
  94. OID_802_3_XMIT_UNDERRUN,
  95. OID_802_3_XMIT_HEARTBEAT_FAILURE,
  96. OID_802_3_XMIT_TIMES_CRS_LOST,
  97. OID_802_3_XMIT_LATE_COLLISIONS };
  98. /* PROCEDURES */
  99. VOID Univ_ndis_string_alloc (
  100. PNDIS_STRING string,
  101. PCHAR src)
  102. {
  103. PWCHAR tmp;
  104. /* allocate enough space for the string */
  105. string -> Length = strlen (src) * sizeof (WCHAR);
  106. string -> MaximumLength = string -> Length + sizeof (WCHAR);
  107. NdisAllocateMemoryWithTag (& (string -> Buffer), string -> MaximumLength,
  108. UNIV_POOL_TAG);
  109. if (string -> Buffer == NULL)
  110. {
  111. string -> Length = 0;
  112. string -> MaximumLength = 0;
  113. return;
  114. }
  115. /* copy characters */
  116. tmp = string -> Buffer;
  117. while (* src != '\0')
  118. {
  119. * tmp = (WCHAR) (* src);
  120. src ++;
  121. tmp ++;
  122. }
  123. * tmp = UNICODE_NULL;
  124. } /* end Univ_ndis_string_free */
  125. VOID Univ_ndis_string_free (
  126. PNDIS_STRING string)
  127. {
  128. if (string -> Buffer == NULL)
  129. return;
  130. /* free memory */
  131. NdisFreeMemory (string -> Buffer, string -> MaximumLength, 0);
  132. string -> Length = 0;
  133. string -> MaximumLength = 0;
  134. } /* end Univ_ndis_string_free */
  135. VOID Univ_ansi_string_alloc (
  136. PANSI_STRING string,
  137. PWCHAR src)
  138. {
  139. PCHAR tmp;
  140. PWCHAR wtmp;
  141. USHORT len;
  142. /* compute length of the string in characters */
  143. wtmp = src;
  144. len = 0;
  145. while (* wtmp != UNICODE_NULL)
  146. {
  147. len ++;
  148. wtmp ++;
  149. }
  150. /* allocate enough space for the string */
  151. string -> Length = len;
  152. string -> MaximumLength = len + sizeof (CHAR);
  153. NdisAllocateMemoryWithTag (& (string -> Buffer), string -> MaximumLength,
  154. UNIV_POOL_TAG);
  155. if (string -> Buffer == NULL)
  156. {
  157. string -> Length = 0;
  158. string -> MaximumLength = 0;
  159. return;
  160. }
  161. /* copy characters */
  162. tmp = string -> Buffer;
  163. while (* src != '\0')
  164. {
  165. * tmp = (CHAR) (* src);
  166. src ++;
  167. tmp ++;
  168. }
  169. * tmp = 0;
  170. } /* end Univ_ansi_string_free */
  171. VOID Univ_ansi_string_free (
  172. PANSI_STRING string)
  173. {
  174. if (string == NULL)
  175. return;
  176. /* free memory */
  177. NdisFreeMemory (string -> Buffer, string -> MaximumLength, 0);
  178. string -> Length = 0;
  179. string -> MaximumLength = 0;
  180. } /* end Univ_ansi_string_free */
  181. ULONG Univ_str_to_ulong (
  182. PULONG retp,
  183. PWCHAR start_ptr,
  184. PWCHAR * end_ptr,
  185. ULONG width,
  186. ULONG base)
  187. {
  188. PWCHAR ptr;
  189. WCHAR c;
  190. ULONG number = 0;
  191. ULONG val, pos = 0;
  192. /* check base */
  193. if (base != 2 && base != 8 && base != 10 && base != 16)
  194. {
  195. if (end_ptr != NULL)
  196. * end_ptr = start_ptr;
  197. return FALSE;
  198. }
  199. /* skip space */
  200. ptr = start_ptr;
  201. number = 0;
  202. while (* ptr == 0x20)
  203. ptr ++;
  204. /* extract digits and build the number */
  205. while (pos < width)
  206. {
  207. c = * ptr;
  208. if (0x30 <= c && c <= 0x39)
  209. val = c - 0x30;
  210. else if (0x41 <= c && c <= 0x46)
  211. val = c - 0x41 + 0xa;
  212. else if (0x61 <= c && c <= 0x66)
  213. val = c - 0x61 + 0xa;
  214. else
  215. break;
  216. if (val >= base)
  217. break;
  218. number = number * base + val;
  219. ptr ++;
  220. pos ++;
  221. }
  222. /* makre sure we extracted something */
  223. if (pos == 0)
  224. {
  225. ptr = start_ptr;
  226. * retp = 0;
  227. return FALSE;
  228. }
  229. /* return resulting number */
  230. if (end_ptr != NULL)
  231. * end_ptr = ptr;
  232. * retp = number;
  233. return TRUE;
  234. } /* end Univ_str_to_ulong */
  235. PWCHAR Univ_ulong_to_str (
  236. ULONG val,
  237. PWCHAR buf,
  238. ULONG base)
  239. {
  240. ULONG dig;
  241. PWCHAR p, sav;
  242. WCHAR tmp;
  243. /* check base */
  244. if (base != 2 && base != 8 && base != 10 && base != 16)
  245. {
  246. buf [0] = 0;
  247. return buf;
  248. }
  249. /* extract digits from the number and output to string */
  250. p = buf;
  251. do
  252. {
  253. /* get next digit */
  254. dig = (ULONG) (val % base);
  255. val /= base;
  256. /* convert to ascii and store */
  257. if (dig > 9)
  258. * p = (CHAR) (dig - 10 + L'a');
  259. else
  260. * p = (CHAR) (dig + L'0');
  261. p ++;
  262. }
  263. while (val > 0);
  264. * p = 0;
  265. sav = p;
  266. /* swap the characters, since operation above creates inverted string */
  267. p --;
  268. do
  269. {
  270. tmp = * p;
  271. * p = * buf;
  272. * buf = tmp;
  273. p --; buf ++;
  274. }
  275. while (buf < p); /* repeat until halfway */
  276. return sav;
  277. } /* end Univ_ulong_to_str */