2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
5 * PURPOSE: Local Area Network media routines
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * CSH 01/08-2000 Created
13 UINT TransferDataCalled
= 0;
14 UINT TransferDataCompleteCalled
= 0;
15 UINT LanReceiveWorkerCalled
= 0;
16 BOOLEAN LanReceiveWorkerBusy
= FALSE
;
18 #define CCS_ROOT L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet"
19 #define TCPIP_GUID L"{4D36E972-E325-11CE-BFC1-08002BE10318}"
21 #define NGFP(_Packet) \
24 ULONG _ContigSize, _TotalSize; \
25 PNDIS_BUFFER _NdisBuffer; \
27 TI_DbgPrint(MID_TRACE,("Checking Packet %x\n", _Packet)); \
28 NdisGetFirstBufferFromPacket(_Packet, \
33 TI_DbgPrint(MID_TRACE,("NdisBuffer: %x\n", _NdisBuffer)); \
34 TI_DbgPrint(MID_TRACE,("Header : %x\n", _Header)); \
35 TI_DbgPrint(MID_TRACE,("ContigSize: %x\n", _ContigSize)); \
36 TI_DbgPrint(MID_TRACE,("TotalSize : %x\n", _TotalSize)); \
39 typedef struct _LAN_WQ_ITEM
{
43 UINT BytesTransferred
;
44 } LAN_WQ_ITEM
, *PLAN_WQ_ITEM
;
46 NDIS_HANDLE NdisProtocolHandle
= (NDIS_HANDLE
)NULL
;
47 BOOLEAN ProtocolRegistered
= FALSE
;
48 LIST_ENTRY AdapterListHead
;
49 KSPIN_LOCK AdapterListLock
;
53 NDIS_REQUEST_TYPE Type
,
58 * FUNCTION: Send a request to NDIS
60 * Adapter = Pointer to a LAN_ADAPTER structure
61 * Type = Type of request (Set or Query)
62 * OID = Value to be set/queried for
63 * Buffer = Pointer to a buffer to use
64 * Length = Number of bytes in Buffer
70 NDIS_STATUS NdisStatus
;
72 Request
.RequestType
= Type
;
73 if (Type
== NdisRequestSetInformation
) {
74 Request
.DATA
.SET_INFORMATION
.Oid
= OID
;
75 Request
.DATA
.SET_INFORMATION
.InformationBuffer
= Buffer
;
76 Request
.DATA
.SET_INFORMATION
.InformationBufferLength
= Length
;
78 Request
.DATA
.QUERY_INFORMATION
.Oid
= OID
;
79 Request
.DATA
.QUERY_INFORMATION
.InformationBuffer
= Buffer
;
80 Request
.DATA
.QUERY_INFORMATION
.InformationBufferLength
= Length
;
83 if (Adapter
->State
!= LAN_STATE_RESETTING
) {
84 NdisRequest(&NdisStatus
, Adapter
->NdisHandle
, &Request
);
86 NdisStatus
= NDIS_STATUS_NOT_ACCEPTED
;
89 /* Wait for NDIS to complete the request */
90 if (NdisStatus
== NDIS_STATUS_PENDING
) {
91 KeWaitForSingleObject(&Adapter
->Event
,
96 NdisStatus
= Adapter
->NdisStatus
;
104 PLAN_ADAPTER Adapter
)
106 * FUNCTION: Frees memory for a LAN_ADAPTER structure
108 * Adapter = Pointer to LAN_ADAPTER structure to free
115 NTSTATUS TcpipLanGetDwordOid
116 ( PIP_INTERFACE Interface
,
119 /* Get maximum frame size */
120 if( Interface
->Context
) {
121 return NDISCall((PLAN_ADAPTER
)Interface
->Context
,
122 NdisRequestQueryInformation
,
126 } else switch( Oid
) { /* Loopback Case */
127 case OID_GEN_HARDWARE_STATUS
:
128 *Result
= NdisHardwareStatusReady
;
129 return STATUS_SUCCESS
;
132 return STATUS_INVALID_PARAMETER
;
137 VOID NTAPI
ProtocolOpenAdapterComplete(
138 NDIS_HANDLE BindingContext
,
140 NDIS_STATUS OpenErrorStatus
)
142 * FUNCTION: Called by NDIS to complete opening of an adapter
144 * BindingContext = Pointer to a device context (LAN_ADAPTER)
145 * Status = Status of the operation
146 * OpenErrorStatus = Additional status information
149 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
151 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
153 Adapter
->NdisStatus
= Status
;
155 KeSetEvent(&Adapter
->Event
, 0, FALSE
);
159 VOID NTAPI
ProtocolCloseAdapterComplete(
160 NDIS_HANDLE BindingContext
,
163 * FUNCTION: Called by NDIS to complete closing an adapter
165 * BindingContext = Pointer to a device context (LAN_ADAPTER)
166 * Status = Status of the operation
169 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
171 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
173 Adapter
->NdisStatus
= Status
;
175 KeSetEvent(&Adapter
->Event
, 0, FALSE
);
179 VOID NTAPI
ProtocolResetComplete(
180 NDIS_HANDLE BindingContext
,
183 * FUNCTION: Called by NDIS to complete resetting an adapter
185 * BindingContext = Pointer to a device context (LAN_ADAPTER)
186 * Status = Status of the operation
189 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
191 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
193 Adapter
->NdisStatus
= Status
;
195 KeSetEvent(&Adapter
->Event
, 0, FALSE
);
199 VOID NTAPI
ProtocolRequestComplete(
200 NDIS_HANDLE BindingContext
,
201 PNDIS_REQUEST NdisRequest
,
204 * FUNCTION: Called by NDIS to complete a request
206 * BindingContext = Pointer to a device context (LAN_ADAPTER)
207 * NdisRequest = Pointer to an object describing the request
208 * Status = Status of the operation
211 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
213 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
215 /* Save status of request and signal an event */
216 Adapter
->NdisStatus
= Status
;
218 KeSetEvent(&Adapter
->Event
, 0, FALSE
);
222 VOID NTAPI
ProtocolSendComplete(
223 NDIS_HANDLE BindingContext
,
227 * FUNCTION: Called by NDIS to complete sending process
229 * BindingContext = Pointer to a device context (LAN_ADAPTER)
230 * Packet = Pointer to a packet descriptor
231 * Status = Status of the operation
234 FreeNdisPacket(Packet
);
237 VOID
LanReceiveWorker( PVOID Context
) {
239 PLAN_WQ_ITEM WorkItem
= (PLAN_WQ_ITEM
)Context
;
241 PLAN_ADAPTER Adapter
;
242 UINT BytesTransferred
;
243 PNDIS_BUFFER NdisBuffer
;
246 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
248 Packet
= WorkItem
->Packet
;
249 Adapter
= WorkItem
->Adapter
;
250 BytesTransferred
= WorkItem
->BytesTransferred
;
252 exFreePool(WorkItem
);
254 IPInitializePacket(&IPPacket
, 0);
256 IPPacket
.NdisPacket
= Packet
;
258 NdisGetFirstBufferFromPacket(Packet
,
261 &IPPacket
.ContigSize
,
262 &IPPacket
.TotalSize
);
264 IPPacket
.ContigSize
= IPPacket
.TotalSize
= BytesTransferred
;
265 /* Determine which upper layer protocol that should receive
266 this packet and pass it to the correct receive handler */
268 TI_DbgPrint(MID_TRACE
,
269 ("ContigSize: %d, TotalSize: %d, BytesTransferred: %d\n",
270 IPPacket
.ContigSize
, IPPacket
.TotalSize
,
273 PacketType
= PC(IPPacket
.NdisPacket
)->PacketType
;
274 IPPacket
.Position
= 0;
278 ("Ether Type = %x ContigSize = %d Total = %d\n",
279 PacketType
, IPPacket
.ContigSize
, IPPacket
.TotalSize
));
281 switch (PacketType
) {
284 TI_DbgPrint(MID_TRACE
,("Received IP Packet\n"));
285 IPReceive(Adapter
->Context
, &IPPacket
);
288 TI_DbgPrint(MID_TRACE
,("Received ARP Packet\n"));
289 ARPReceive(Adapter
->Context
, &IPPacket
);
291 IPPacket
.Free(&IPPacket
);
295 FreeNdisPacket( Packet
);
298 VOID
LanSubmitReceiveWork(
299 NDIS_HANDLE BindingContext
,
302 UINT BytesTransferred
) {
303 PLAN_WQ_ITEM WQItem
= exAllocatePool(NonPagedPool
, sizeof(LAN_WQ_ITEM
));
304 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
306 TI_DbgPrint(DEBUG_DATALINK
,("called\n"));
310 WQItem
->Packet
= Packet
;
311 WQItem
->Adapter
= Adapter
;
312 WQItem
->BytesTransferred
= BytesTransferred
;
314 if (!ChewCreate( LanReceiveWorker
, WQItem
))
318 VOID NTAPI
ProtocolTransferDataComplete(
319 NDIS_HANDLE BindingContext
,
322 UINT BytesTransferred
)
324 * FUNCTION: Called by NDIS to complete reception of data
326 * BindingContext = Pointer to a device context (LAN_ADAPTER)
327 * Packet = Pointer to a packet descriptor
328 * Status = Status of the operation
329 * BytesTransferred = Number of bytes transferred
331 * If the packet was successfully received, determine the protocol
332 * type and pass it to the correct receive handler
335 ASSERT(KeGetCurrentIrql() == DISPATCH_LEVEL
);
337 TI_DbgPrint(DEBUG_DATALINK
,("called\n"));
339 TransferDataCompleteCalled
++;
340 ASSERT(TransferDataCompleteCalled
<= TransferDataCalled
);
342 if( Status
!= NDIS_STATUS_SUCCESS
) return;
344 LanSubmitReceiveWork( BindingContext
, Packet
, Status
, BytesTransferred
);
347 NDIS_STATUS NTAPI
ProtocolReceive(
348 NDIS_HANDLE BindingContext
,
349 NDIS_HANDLE MacReceiveContext
,
351 UINT HeaderBufferSize
,
352 PVOID LookaheadBuffer
,
353 UINT LookaheadBufferSize
,
356 * FUNCTION: Called by NDIS when a packet has been received on the physical link
358 * BindingContext = Pointer to a device context (LAN_ADAPTER)
359 * MacReceiveContext = Handle used by underlying NIC driver
360 * HeaderBuffer = Pointer to a buffer containing the packet header
361 * HeaderBufferSize = Number of bytes in HeaderBuffer
362 * LookaheadBuffer = Pointer to a buffer containing buffered packet data
363 * LookaheadBufferSize = Size of LookaheadBuffer. May be less than asked for
364 * PacketSize = Overall size of the packet (not including header)
366 * Status of operation
370 UINT PacketType
, BytesTransferred
;
374 NDIS_STATUS NdisStatus
;
375 PNDIS_PACKET NdisPacket
;
376 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)BindingContext
;
377 PETH_HEADER EHeader
= (PETH_HEADER
)HeaderBuffer
;
379 TI_DbgPrint(DEBUG_DATALINK
, ("Called. (packetsize %d)\n",PacketSize
));
381 if (Adapter
->State
!= LAN_STATE_STARTED
) {
382 TI_DbgPrint(DEBUG_DATALINK
, ("Adapter is stopped.\n"));
383 return NDIS_STATUS_NOT_ACCEPTED
;
386 if (HeaderBufferSize
< Adapter
->HeaderSize
) {
387 TI_DbgPrint(DEBUG_DATALINK
, ("Runt frame received.\n"));
388 return NDIS_STATUS_NOT_ACCEPTED
;
391 if (Adapter
->Media
== NdisMedium802_3
) {
392 /* Ethernet and IEEE 802.3 frames can be destinguished by
393 looking at the IEEE 802.3 length field. This field is
394 less than or equal to 1500 for a valid IEEE 802.3 frame
395 and larger than 1500 is it's a valid EtherType value.
396 See RFC 1122, section 2.3.3 for more information */
397 /* FIXME: Test for Ethernet and IEEE 802.3 frame */
398 if (((EType
= EHeader
->EType
) != ETYPE_IPv4
) && (EType
!= ETYPE_ARP
)) {
399 TI_DbgPrint(DEBUG_DATALINK
, ("Not IP or ARP frame. EtherType (0x%X).\n", EType
));
400 return NDIS_STATUS_NOT_ACCEPTED
;
402 /* We use EtherType constants to destinguish packet types */
405 TI_DbgPrint(MIN_TRACE
, ("Unsupported media.\n"));
406 /* FIXME: Support other medias */
407 return NDIS_STATUS_NOT_ACCEPTED
;
410 /* Get a transfer data packet */
412 TI_DbgPrint(DEBUG_DATALINK
, ("Adapter: %x (MTU %d)\n",
413 Adapter
, Adapter
->MTU
));
415 NdisStatus
= AllocatePacketWithBuffer( &NdisPacket
, NULL
,
417 if( NdisStatus
!= NDIS_STATUS_SUCCESS
) {
418 return NDIS_STATUS_NOT_ACCEPTED
;
421 PC(NdisPacket
)->PacketType
= PacketType
;
423 TI_DbgPrint(DEBUG_DATALINK
, ("pretransfer LookaheadBufferSize %d packsize %d\n",LookaheadBufferSize
,PacketSize
));
425 GetDataPtr( NdisPacket
, 0, &BufferData
, &temp
);
427 IPPacket
.NdisPacket
= NdisPacket
;
428 IPPacket
.Position
= 0;
430 TransferDataCalled
++;
432 if (LookaheadBufferSize
== PacketSize
)
434 /* Optimized code path for packets that are fully contained in
435 * the lookahead buffer. */
436 NdisCopyLookaheadData(BufferData
,
439 Adapter
->MacOptions
);
443 NdisTransferData(&NdisStatus
, Adapter
->NdisHandle
,
444 MacReceiveContext
, 0, PacketSize
,
445 NdisPacket
, &BytesTransferred
);
447 TI_DbgPrint(DEBUG_DATALINK
, ("Calling complete\n"));
449 if (NdisStatus
!= NDIS_STATUS_PENDING
)
450 ProtocolTransferDataComplete(BindingContext
,
455 TI_DbgPrint(DEBUG_DATALINK
, ("leaving\n"));
457 return NDIS_STATUS_SUCCESS
;
461 VOID NTAPI
ProtocolReceiveComplete(
462 NDIS_HANDLE BindingContext
)
464 * FUNCTION: Called by NDIS when we're done receiving data
466 * BindingContext = Pointer to a device context (LAN_ADAPTER)
469 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
473 VOID NTAPI
ProtocolStatus(
474 NDIS_HANDLE BindingContext
,
475 NDIS_STATUS GeneralStatus
,
477 UINT StatusBufferSize
)
479 * FUNCTION: Called by NDIS when the underlying driver has changed state
481 * BindingContext = Pointer to a device context (LAN_ADAPTER)
482 * GeneralStatus = A general status code
483 * StatusBuffer = Pointer to a buffer with medium-specific data
484 * StatusBufferSize = Number of bytes in StatusBuffer
487 PLAN_ADAPTER Adapter
= BindingContext
;
489 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
491 switch(GeneralStatus
)
493 case NDIS_STATUS_MEDIA_CONNECT
:
494 DbgPrint("NDIS_STATUS_MEDIA_CONNECT\n");
497 case NDIS_STATUS_MEDIA_DISCONNECT
:
498 DbgPrint("NDIS_STATUS_MEDIA_DISCONNECT\n");
501 case NDIS_STATUS_RESET_START
:
502 Adapter
->State
= LAN_STATE_RESETTING
;
505 case NDIS_STATUS_RESET_END
:
506 Adapter
->State
= LAN_STATE_STARTED
;
510 DbgPrint("Unhandled status: %x", GeneralStatus
);
517 NDIS_HANDLE NdisBindingContext
,
518 PNET_PNP_EVENT PnPEvent
)
520 switch(PnPEvent
->NetEvent
)
522 case NetEventSetPower
:
523 DbgPrint("Device transitioned to power state %ld\n", PnPEvent
->Buffer
);
524 return NDIS_STATUS_SUCCESS
;
526 case NetEventQueryPower
:
527 DbgPrint("Device wants to go into power state %ld\n", PnPEvent
->Buffer
);
528 return NDIS_STATUS_SUCCESS
;
530 case NetEventQueryRemoveDevice
:
531 DbgPrint("Device is about to be removed\n");
532 return NDIS_STATUS_SUCCESS
;
534 case NetEventCancelRemoveDevice
:
535 DbgPrint("Device removal cancelled\n");
536 return NDIS_STATUS_SUCCESS
;
539 DbgPrint("Unhandled event type: %ld\n", PnPEvent
->NetEvent
);
540 return NDIS_STATUS_SUCCESS
;
544 VOID NTAPI
ProtocolStatusComplete(
545 NDIS_HANDLE NdisBindingContext
)
547 * FUNCTION: Called by NDIS when a status-change has occurred
549 * BindingContext = Pointer to a device context (LAN_ADAPTER)
552 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
555 VOID NTAPI
ProtocolBindAdapter(
556 OUT PNDIS_STATUS Status
,
557 IN NDIS_HANDLE BindContext
,
558 IN PNDIS_STRING DeviceName
,
559 IN PVOID SystemSpecific1
,
560 IN PVOID SystemSpecific2
)
562 * FUNCTION: Called by NDIS during NdisRegisterProtocol to set up initial
563 * bindings, and periodically thereafer as new adapters come online
565 * Status: Return value to NDIS
566 * BindContext: Handle provided by NDIS to track pending binding operations
567 * DeviceName: Name of the miniport device to bind to
568 * SystemSpecific1: Pointer to a registry path with protocol-specific configuration information
569 * SystemSpecific2: Unused & must not be touched
572 /* XXX confirm that this is still true, or re-word the following comment */
573 /* we get to ignore BindContext because we will never pend an operation with NDIS */
574 TI_DbgPrint(DEBUG_DATALINK
, ("Called with registry path %wZ for %wZ\n", SystemSpecific1
, DeviceName
));
575 *Status
= LANRegisterAdapter(DeviceName
, SystemSpecific1
);
581 PNDIS_PACKET NdisPacket
,
586 * FUNCTION: Transmits a packet
588 * Context = Pointer to context information (LAN_ADAPTER)
589 * NdisPacket = Pointer to NDIS packet to send
590 * Offset = Offset in packet where data starts
591 * LinkAddress = Pointer to link address of destination (NULL = broadcast)
592 * Type = LAN protocol type (LAN_PROTO_*)
595 NDIS_STATUS NdisStatus
;
599 PLAN_ADAPTER Adapter
= (PLAN_ADAPTER
)Context
;
601 PNDIS_PACKET XmitPacket
;
603 TI_DbgPrint(DEBUG_DATALINK
,
604 ("Called( NdisPacket %x, Offset %d, Adapter %x )\n",
605 NdisPacket
, Offset
, Adapter
));
607 if (Adapter
->State
!= LAN_STATE_STARTED
) {
608 (*PC(NdisPacket
)->DLComplete
)(PC(NdisPacket
)->Context
, NdisPacket
, NDIS_STATUS_NOT_ACCEPTED
);
612 TI_DbgPrint(DEBUG_DATALINK
,
613 ("Adapter Address [%02x %02x %02x %02x %02x %02x]\n",
614 Adapter
->HWAddress
[0] & 0xff,
615 Adapter
->HWAddress
[1] & 0xff,
616 Adapter
->HWAddress
[2] & 0xff,
617 Adapter
->HWAddress
[3] & 0xff,
618 Adapter
->HWAddress
[4] & 0xff,
619 Adapter
->HWAddress
[5] & 0xff));
621 GetDataPtr( NdisPacket
, 0, &OldData
, &OldSize
);
623 NdisStatus
= AllocatePacketWithBuffer(&XmitPacket
, NULL
, OldSize
+ Adapter
->HeaderSize
);
624 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
625 (*PC(NdisPacket
)->DLComplete
)(PC(NdisPacket
)->Context
, NdisPacket
, NDIS_STATUS_RESOURCES
);
629 GetDataPtr(XmitPacket
, 0, &Data
, &Size
);
631 RtlCopyMemory(Data
+ Adapter
->HeaderSize
, OldData
, OldSize
);
633 (*PC(NdisPacket
)->DLComplete
)(PC(NdisPacket
)->Context
, NdisPacket
, NDIS_STATUS_SUCCESS
);
635 switch (Adapter
->Media
) {
636 case NdisMedium802_3
:
637 EHeader
= (PETH_HEADER
)Data
;
640 /* Unicast address */
641 RtlCopyMemory(EHeader
->DstAddr
, LinkAddress
, IEEE_802_ADDR_LENGTH
);
643 /* Broadcast address */
644 RtlFillMemory(EHeader
->DstAddr
, IEEE_802_ADDR_LENGTH
, 0xFF);
647 RtlCopyMemory(EHeader
->SrcAddr
, Adapter
->HWAddress
, IEEE_802_ADDR_LENGTH
);
651 EHeader
->EType
= ETYPE_IPv4
;
654 EHeader
->EType
= ETYPE_ARP
;
657 EHeader
->EType
= ETYPE_IPv6
;
666 /* FIXME: Support other medias */
670 TI_DbgPrint( MID_TRACE
, ("LinkAddress: %x\n", LinkAddress
));
674 ("Link Address [%02x %02x %02x %02x %02x %02x]\n",
675 ((PCHAR
)LinkAddress
)[0] & 0xff,
676 ((PCHAR
)LinkAddress
)[1] & 0xff,
677 ((PCHAR
)LinkAddress
)[2] & 0xff,
678 ((PCHAR
)LinkAddress
)[3] & 0xff,
679 ((PCHAR
)LinkAddress
)[4] & 0xff,
680 ((PCHAR
)LinkAddress
)[5] & 0xff));
683 if (Adapter
->MTU
< Size
) {
684 /* This is NOT a pointer. MSDN explicitly says so. */
685 NDIS_PER_PACKET_INFO_FROM_PACKET(NdisPacket
,
686 TcpLargeSendPacketInfo
) = (PVOID
)((ULONG
)Adapter
->MTU
);
689 TcpipAcquireSpinLock( &Adapter
->Lock
, &OldIrql
);
690 TI_DbgPrint(MID_TRACE
, ("NdisSend\n"));
691 NdisSend(&NdisStatus
, Adapter
->NdisHandle
, XmitPacket
);
692 TI_DbgPrint(MID_TRACE
, ("NdisSend %s\n",
693 NdisStatus
== NDIS_STATUS_PENDING
?
694 "Pending" : "Complete"));
695 TcpipReleaseSpinLock( &Adapter
->Lock
, OldIrql
);
697 /* I had a talk with vizzini: these really ought to be here.
698 * we're supposed to see these completed by ndis *only* when
699 * status_pending is returned. Note that this is different from
700 * the situation with IRPs. */
701 if (NdisStatus
!= NDIS_STATUS_PENDING
)
702 ProtocolSendComplete((NDIS_HANDLE
)Context
, XmitPacket
, NdisStatus
);
706 OpenRegistryKey( PNDIS_STRING RegistryPath
, PHANDLE RegHandle
) {
707 OBJECT_ATTRIBUTES Attributes
;
710 InitializeObjectAttributes(&Attributes
, RegistryPath
, OBJ_CASE_INSENSITIVE
, 0, 0);
711 Status
= ZwOpenKey(RegHandle
, KEY_ALL_ACCESS
, &Attributes
);
715 static NTSTATUS
ReadStringFromRegistry( HANDLE RegHandle
,
716 PWCHAR RegistryValue
,
717 PUNICODE_STRING String
) {
718 UNICODE_STRING ValueName
;
719 UNICODE_STRING UnicodeString
;
723 PKEY_VALUE_PARTIAL_INFORMATION Information
= (PKEY_VALUE_PARTIAL_INFORMATION
)buf
;
725 RtlInitUnicodeString(&ValueName
, RegistryValue
);
727 ZwQueryValueKey(RegHandle
,
729 KeyValuePartialInformation
,
734 if (!NT_SUCCESS(Status
))
736 /* IP address is stored as a REG_MULTI_SZ - we only pay attention to the first one though */
737 TI_DbgPrint(MIN_TRACE
, ("Information DataLength: 0x%x\n", Information
->DataLength
));
739 UnicodeString
.Buffer
= (PWCHAR
)&Information
->Data
;
740 UnicodeString
.Length
= Information
->DataLength
- sizeof(WCHAR
);
741 UnicodeString
.MaximumLength
= Information
->DataLength
;
744 (PWCHAR
)ExAllocatePool( NonPagedPool
,
745 UnicodeString
.MaximumLength
+ sizeof(WCHAR
) );
747 if( !String
->Buffer
) return STATUS_NO_MEMORY
;
749 String
->MaximumLength
= UnicodeString
.MaximumLength
;
750 RtlCopyUnicodeString( String
, &UnicodeString
);
752 return STATUS_SUCCESS
;
756 * Utility to copy and append two unicode strings.
758 * IN OUT PUNICODE_STRING ResultFirst -> First string and result
759 * IN PUNICODE_STRING Second -> Second string to append
760 * IN BOOL Deallocate -> TRUE: Deallocate First string before
766 NTSTATUS NTAPI
AppendUnicodeString(PUNICODE_STRING ResultFirst
,
767 PUNICODE_STRING Second
,
768 BOOLEAN Deallocate
) {
770 UNICODE_STRING Ustr
= *ResultFirst
;
771 PWSTR new_string
= ExAllocatePoolWithTag
773 (ResultFirst
->Length
+ Second
->Length
+ sizeof(WCHAR
)), TAG_STRING
);
775 return STATUS_NO_MEMORY
;
777 memcpy( new_string
, ResultFirst
->Buffer
, ResultFirst
->Length
);
778 memcpy( new_string
+ ResultFirst
->Length
/ sizeof(WCHAR
),
779 Second
->Buffer
, Second
->Length
);
780 if( Deallocate
) RtlFreeUnicodeString(ResultFirst
);
781 ResultFirst
->Length
= Ustr
.Length
+ Second
->Length
;
782 ResultFirst
->MaximumLength
= ResultFirst
->Length
;
783 new_string
[ResultFirst
->Length
/ sizeof(WCHAR
)] = 0;
784 Status
= RtlCreateUnicodeString(ResultFirst
,new_string
) ?
785 STATUS_SUCCESS
: STATUS_NO_MEMORY
;
786 ExFreePool(new_string
);
790 static NTSTATUS
CheckForDeviceDesc( PUNICODE_STRING EnumKeyName
,
791 PUNICODE_STRING TargetKeyName
,
792 PUNICODE_STRING Name
,
793 PUNICODE_STRING DeviceDesc
) {
794 UNICODE_STRING RootDevice
= { 0, 0, NULL
}, LinkageKeyName
= { 0, 0, NULL
};
795 UNICODE_STRING DescKeyName
= { 0, 0, NULL
}, Linkage
= { 0, 0, NULL
};
796 UNICODE_STRING BackSlash
= { 0, 0, NULL
};
797 HANDLE DescKey
= NULL
, LinkageKey
= NULL
;
800 TI_DbgPrint(DEBUG_DATALINK
,("EnumKeyName %wZ\n", EnumKeyName
));
802 RtlInitUnicodeString(&BackSlash
, L
"\\");
803 RtlInitUnicodeString(&Linkage
, L
"\\Linkage");
805 RtlInitUnicodeString(&DescKeyName
, L
"");
806 AppendUnicodeString( &DescKeyName
, EnumKeyName
, FALSE
);
807 AppendUnicodeString( &DescKeyName
, &BackSlash
, TRUE
);
808 AppendUnicodeString( &DescKeyName
, TargetKeyName
, TRUE
);
810 RtlInitUnicodeString(&LinkageKeyName
, L
"");
811 AppendUnicodeString( &LinkageKeyName
, &DescKeyName
, FALSE
);
812 AppendUnicodeString( &LinkageKeyName
, &Linkage
, TRUE
);
814 Status
= OpenRegistryKey( &LinkageKeyName
, &LinkageKey
);
815 if( !NT_SUCCESS(Status
) ) goto cleanup
;
817 Status
= ReadStringFromRegistry( LinkageKey
, L
"RootDevice", &RootDevice
);
818 if( !NT_SUCCESS(Status
) ) goto cleanup
;
820 if( RtlCompareUnicodeString( &RootDevice
, Name
, TRUE
) == 0 ) {
821 Status
= OpenRegistryKey( &DescKeyName
, &DescKey
);
822 if( !NT_SUCCESS(Status
) ) goto cleanup
;
824 Status
= ReadStringFromRegistry( DescKey
, L
"DriverDesc", DeviceDesc
);
825 if( !NT_SUCCESS(Status
) ) goto cleanup
;
827 TI_DbgPrint(DEBUG_DATALINK
,("ADAPTER DESC: %wZ\n", DeviceDesc
));
828 } else Status
= STATUS_UNSUCCESSFUL
;
831 RtlFreeUnicodeString( &RootDevice
);
832 RtlFreeUnicodeString( &LinkageKeyName
);
833 RtlFreeUnicodeString( &DescKeyName
);
834 if( LinkageKey
) NtClose( LinkageKey
);
835 if( DescKey
) NtClose( DescKey
);
837 TI_DbgPrint(DEBUG_DATALINK
,("Returning %x\n", Status
));
842 static NTSTATUS
FindDeviceDescForAdapter( PUNICODE_STRING Name
,
843 PUNICODE_STRING DeviceDesc
) {
844 UNICODE_STRING EnumKeyName
, TargetKeyName
;
848 KEY_BASIC_INFORMATION
*Kbio
=
849 ExAllocatePool(NonPagedPool
, sizeof(KEY_BASIC_INFORMATION
));
850 ULONG KbioLength
= sizeof(KEY_BASIC_INFORMATION
), ResultLength
;
852 RtlInitUnicodeString( DeviceDesc
, NULL
);
854 if( !Kbio
) return STATUS_INSUFFICIENT_RESOURCES
;
857 (&EnumKeyName
, CCS_ROOT L
"\\Control\\Class\\" TCPIP_GUID
);
859 Status
= OpenRegistryKey( &EnumKeyName
, &EnumKey
);
861 if( !NT_SUCCESS(Status
) ) {
862 TI_DbgPrint(DEBUG_DATALINK
,("Couldn't open Enum key %wZ: %x\n",
863 &EnumKeyName
, Status
));
868 for( i
= 0; NT_SUCCESS(Status
); i
++ ) {
869 Status
= ZwEnumerateKey( EnumKey
, i
, KeyBasicInformation
,
870 Kbio
, KbioLength
, &ResultLength
);
872 if( Status
== STATUS_BUFFER_TOO_SMALL
|| Status
== STATUS_BUFFER_OVERFLOW
) {
874 KbioLength
= ResultLength
;
875 Kbio
= ExAllocatePool( NonPagedPool
, KbioLength
);
877 TI_DbgPrint(DEBUG_DATALINK
,("Failed to allocate memory\n"));
879 return STATUS_NO_MEMORY
;
882 Status
= ZwEnumerateKey( EnumKey
, i
, KeyBasicInformation
,
883 Kbio
, KbioLength
, &ResultLength
);
885 if( !NT_SUCCESS(Status
) ) {
886 TI_DbgPrint(DEBUG_DATALINK
,("Couldn't enum key child %d\n", i
));
893 if( NT_SUCCESS(Status
) ) {
894 TargetKeyName
.Length
= TargetKeyName
.MaximumLength
=
896 TargetKeyName
.Buffer
= Kbio
->Name
;
898 Status
= CheckForDeviceDesc
899 ( &EnumKeyName
, &TargetKeyName
, Name
, DeviceDesc
);
900 if( NT_SUCCESS(Status
) ) {
904 } else Status
= STATUS_SUCCESS
;
910 return STATUS_UNSUCCESSFUL
;
913 VOID
GetName( PUNICODE_STRING RegistryKey
,
914 PUNICODE_STRING OutName
) {
916 UNICODE_STRING PartialRegistryKey
;
918 PartialRegistryKey
.Buffer
=
919 RegistryKey
->Buffer
+ wcslen(CCS_ROOT L
"\\Services\\");
920 Ptr
= PartialRegistryKey
.Buffer
;
922 while( *Ptr
!= L
'\\' &&
923 ((PCHAR
)Ptr
) < ((PCHAR
)RegistryKey
->Buffer
) + RegistryKey
->Length
)
926 PartialRegistryKey
.Length
= PartialRegistryKey
.MaximumLength
=
927 (Ptr
- PartialRegistryKey
.Buffer
) * sizeof(WCHAR
);
929 RtlInitUnicodeString( OutName
, L
"" );
930 AppendUnicodeString( OutName
, &PartialRegistryKey
, FALSE
);
934 PLAN_ADAPTER Adapter
,
935 PNDIS_STRING RegistryPath
)
937 * FUNCTION: Binds a LAN adapter to IP layer
939 * Adapter = Pointer to LAN_ADAPTER structure
941 * We set the lookahead buffer size, set the packet filter and
942 * bind the adapter to IP layer
946 NDIS_STATUS NdisStatus
;
947 LLIP_BIND_INFO BindInfo
;
948 IP_ADDRESS DefaultMask
;
949 ULONG Lookahead
= LOOKAHEAD_SIZE
;
952 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
954 Adapter
->State
= LAN_STATE_OPENING
;
956 NdisStatus
= NDISCall(Adapter
,
957 NdisRequestSetInformation
,
958 OID_GEN_CURRENT_LOOKAHEAD
,
961 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
962 TI_DbgPrint(DEBUG_DATALINK
, ("Could not set lookahead buffer size (0x%X).\n", NdisStatus
));
966 /* Bind the adapter to IP layer */
967 BindInfo
.Context
= Adapter
;
968 BindInfo
.HeaderSize
= Adapter
->HeaderSize
;
969 BindInfo
.MinFrameSize
= Adapter
->MinFrameSize
;
970 BindInfo
.MTU
= Adapter
->MTU
;
971 BindInfo
.Address
= (PUCHAR
)&Adapter
->HWAddress
;
972 BindInfo
.AddressLength
= Adapter
->HWAddressLength
;
973 BindInfo
.Transmit
= LANTransmit
;
975 IF
= IPCreateInterface(&BindInfo
);
978 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
983 * Query per-adapter configuration from the registry
984 * In case anyone is curious: there *is* an Ndis configuration api
985 * for this sort of thing, but it doesn't really support things like
986 * REG_MULTI_SZ very well, and there is a note in the DDK that says that
987 * protocol drivers developed for win2k and above just use the native
988 * services (ZwOpenKey, etc).
991 GetName( RegistryPath
, &IF
->Name
);
993 Status
= FindDeviceDescForAdapter( &IF
->Name
, &IF
->Description
);
994 if (!NT_SUCCESS(Status
)) {
995 TI_DbgPrint(MIN_TRACE
, ("Failed to get device description.\n"));
996 IPDestroyInterface(IF
);
1000 TI_DbgPrint(DEBUG_DATALINK
,("Adapter Description: %wZ\n",
1003 AddrInitIPv4(&DefaultMask
, 0);
1005 IF
->Unicast
= DefaultMask
;
1006 IF
->Netmask
= DefaultMask
;
1008 IF
->Broadcast
.Type
= IP_ADDRESS_V4
;
1009 IF
->Broadcast
.Address
.IPv4Address
=
1010 IF
->Unicast
.Address
.IPv4Address
|
1011 ~IF
->Netmask
.Address
.IPv4Address
;
1013 TI_DbgPrint(DEBUG_DATALINK
,("BCAST(IF) %s\n", A2S(&IF
->Broadcast
)));
1015 /* Get maximum link speed */
1016 NdisStatus
= NDISCall(Adapter
,
1017 NdisRequestQueryInformation
,
1022 if( !NT_SUCCESS(NdisStatus
) )
1023 IF
->Speed
= IP_DEFAULT_LINK_SPEED
;
1025 /* Register interface with IP layer */
1026 IPRegisterInterface(IF
);
1028 /* Set packet filter so we can send and receive packets */
1029 NdisStatus
= NDISCall(Adapter
,
1030 NdisRequestSetInformation
,
1031 OID_GEN_CURRENT_PACKET_FILTER
,
1032 &Adapter
->PacketFilter
,
1035 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1036 TI_DbgPrint(DEBUG_DATALINK
, ("Could not set packet filter (0x%X).\n", NdisStatus
));
1037 IPUnregisterInterface(IF
);
1038 IPDestroyInterface(IF
);
1042 Adapter
->Context
= IF
;
1043 Adapter
->State
= LAN_STATE_STARTED
;
1049 PLAN_ADAPTER Adapter
)
1051 * FUNCTION: Unbinds a LAN adapter from IP layer
1053 * Adapter = Pointer to LAN_ADAPTER structure
1056 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
1058 if (Adapter
->State
== LAN_STATE_STARTED
) {
1059 PIP_INTERFACE IF
= Adapter
->Context
;
1061 IPUnregisterInterface(IF
);
1063 IPDestroyInterface(IF
);
1068 NDIS_STATUS
LANRegisterAdapter(
1069 PNDIS_STRING AdapterName
,
1070 PNDIS_STRING RegistryPath
)
1072 * FUNCTION: Registers protocol with an NDIS adapter
1074 * AdapterName = Pointer to string with name of adapter to register
1075 * Adapter = Address of pointer to a LAN_ADAPTER structure
1077 * Status of operation
1081 NDIS_STATUS NdisStatus
;
1082 NDIS_STATUS OpenStatus
;
1084 NDIS_MEDIUM MediaArray
[MAX_MEDIA
];
1088 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
1090 IF
= exAllocatePool(NonPagedPool
, sizeof(LAN_ADAPTER
));
1092 TI_DbgPrint(MIN_TRACE
, ("Insufficient resources.\n"));
1093 return NDIS_STATUS_RESOURCES
;
1096 RtlZeroMemory(IF
, sizeof(LAN_ADAPTER
));
1098 /* Put adapter in stopped state */
1099 IF
->State
= LAN_STATE_STOPPED
;
1101 /* Initialize protecting spin lock */
1102 KeInitializeSpinLock(&IF
->Lock
);
1104 KeInitializeEvent(&IF
->Event
, SynchronizationEvent
, FALSE
);
1106 /* Initialize array with media IDs we support */
1107 MediaArray
[MEDIA_ETH
] = NdisMedium802_3
;
1109 TI_DbgPrint(DEBUG_DATALINK
,("opening adapter %wZ\n", AdapterName
));
1110 /* Open the adapter. */
1111 NdisOpenAdapter(&NdisStatus
,
1123 /* Wait until the adapter is opened */
1124 if (NdisStatus
== NDIS_STATUS_PENDING
)
1125 KeWaitForSingleObject(&IF
->Event
, UserRequest
, KernelMode
, FALSE
, NULL
);
1126 else if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1127 TI_DbgPrint(DEBUG_DATALINK
,("denying adapter %wZ\n", AdapterName
));
1132 IF
->Media
= MediaArray
[MediaIndex
];
1134 /* Fill LAN_ADAPTER structure with some adapter specific information */
1135 switch (IF
->Media
) {
1136 case NdisMedium802_3
:
1137 IF
->HWAddressLength
= IEEE_802_ADDR_LENGTH
;
1138 IF
->BCastMask
= BCAST_ETH_MASK
;
1139 IF
->BCastCheck
= BCAST_ETH_CHECK
;
1140 IF
->BCastOffset
= BCAST_ETH_OFFSET
;
1141 IF
->HeaderSize
= sizeof(ETH_HEADER
);
1142 IF
->MinFrameSize
= 60;
1143 AddressOID
= OID_802_3_CURRENT_ADDRESS
;
1145 NDIS_PACKET_TYPE_BROADCAST
|
1146 NDIS_PACKET_TYPE_DIRECTED
|
1147 NDIS_PACKET_TYPE_MULTICAST
;
1151 /* Unsupported media */
1152 TI_DbgPrint(MIN_TRACE
, ("Unsupported media.\n"));
1154 return NDIS_STATUS_NOT_SUPPORTED
;
1157 /* Get maximum frame size */
1158 NdisStatus
= NDISCall(IF
,
1159 NdisRequestQueryInformation
,
1160 OID_GEN_MAXIMUM_FRAME_SIZE
,
1163 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1164 TI_DbgPrint(DEBUG_DATALINK
,("denying adapter %wZ (NDISCall)\n", AdapterName
));
1169 /* Get maximum packet size */
1170 NdisStatus
= NDISCall(IF
,
1171 NdisRequestQueryInformation
,
1172 OID_GEN_MAXIMUM_TOTAL_SIZE
,
1175 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1176 TI_DbgPrint(MIN_TRACE
, ("Query for maximum packet size failed.\n"));
1181 /* Get maximum number of packets we can pass to NdisSend(Packets) at one time */
1182 NdisStatus
= NDISCall(IF
,
1183 NdisRequestQueryInformation
,
1184 OID_GEN_MAXIMUM_SEND_PACKETS
,
1185 &IF
->MaxSendPackets
,
1187 if (NdisStatus
!= NDIS_STATUS_SUCCESS
)
1188 /* Legacy NIC drivers may not support this query, if it fails we
1189 assume it can send at least one packet per call to NdisSend(Packets) */
1190 IF
->MaxSendPackets
= 1;
1192 /* Get current hardware address */
1193 NdisStatus
= NDISCall(IF
,
1194 NdisRequestQueryInformation
,
1197 IF
->HWAddressLength
);
1198 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1199 TI_DbgPrint(MIN_TRACE
, ("Query for current hardware address failed.\n"));
1204 /* Get maximum link speed */
1205 NdisStatus
= NDISCall(IF
,
1206 NdisRequestQueryInformation
,
1210 if (NdisStatus
!= NDIS_STATUS_SUCCESS
) {
1211 TI_DbgPrint(MIN_TRACE
, ("Query for maximum link speed failed.\n"));
1216 /* Convert returned link speed to bps (it is in 100bps increments) */
1217 IF
->Speed
= Speed
* 100L;
1219 /* Bind adapter to IP layer */
1220 if( !BindAdapter(IF
, RegistryPath
) ) {
1221 TI_DbgPrint(DEBUG_DATALINK
,("denying adapter %wZ (BindAdapter)\n", AdapterName
));
1223 return NDIS_STATUS_NOT_ACCEPTED
;
1226 /* Add adapter to the adapter list */
1227 ExInterlockedInsertTailList(&AdapterListHead
,
1231 TI_DbgPrint(DEBUG_DATALINK
, ("Leaving.\n"));
1233 return NDIS_STATUS_SUCCESS
;
1237 NDIS_STATUS
LANUnregisterAdapter(
1238 PLAN_ADAPTER Adapter
)
1240 * FUNCTION: Unregisters protocol with NDIS adapter
1242 * Adapter = Pointer to a LAN_ADAPTER structure
1244 * Status of operation
1248 NDIS_HANDLE NdisHandle
;
1249 NDIS_STATUS NdisStatus
= NDIS_STATUS_SUCCESS
;
1251 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
1253 /* Unlink the adapter from the list */
1254 RemoveEntryList(&Adapter
->ListEntry
);
1256 /* Unbind adapter from IP layer */
1257 UnbindAdapter(Adapter
);
1259 TcpipAcquireSpinLock(&Adapter
->Lock
, &OldIrql
);
1260 NdisHandle
= Adapter
->NdisHandle
;
1262 Adapter
->NdisHandle
= NULL
;
1263 TcpipReleaseSpinLock(&Adapter
->Lock
, OldIrql
);
1265 NdisCloseAdapter(&NdisStatus
, NdisHandle
);
1266 if (NdisStatus
== NDIS_STATUS_PENDING
) {
1267 TcpipWaitForSingleObject(&Adapter
->Event
,
1272 NdisStatus
= Adapter
->NdisStatus
;
1275 TcpipReleaseSpinLock(&Adapter
->Lock
, OldIrql
);
1277 FreeAdapter(Adapter
);
1284 LANUnregisterProtocol(VOID
)
1286 * FUNCTION: Unregisters this protocol driver with NDIS
1287 * NOTES: Does not care wether we are already registered
1290 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
1292 if (ProtocolRegistered
) {
1293 NDIS_STATUS NdisStatus
;
1294 PLIST_ENTRY CurrentEntry
;
1295 PLIST_ENTRY NextEntry
;
1296 PLAN_ADAPTER Current
;
1299 TcpipAcquireSpinLock(&AdapterListLock
, &OldIrql
);
1301 /* Search the list and remove every adapter we find */
1302 CurrentEntry
= AdapterListHead
.Flink
;
1303 while (CurrentEntry
!= &AdapterListHead
) {
1304 NextEntry
= CurrentEntry
->Flink
;
1305 Current
= CONTAINING_RECORD(CurrentEntry
, LAN_ADAPTER
, ListEntry
);
1307 LANUnregisterAdapter(Current
);
1308 CurrentEntry
= NextEntry
;
1311 TcpipReleaseSpinLock(&AdapterListLock
, OldIrql
);
1313 NdisDeregisterProtocol(&NdisStatus
, NdisProtocolHandle
);
1314 ProtocolRegistered
= FALSE
;
1320 ProtocolUnbindAdapter(
1321 PNDIS_STATUS Status
,
1322 NDIS_HANDLE ProtocolBindingContext
,
1323 NDIS_HANDLE UnbindContext
)
1325 /* We don't pend any unbinding so we can just ignore UnbindContext */
1326 *Status
= LANUnregisterAdapter((PLAN_ADAPTER
)ProtocolBindingContext
);
1329 NTSTATUS
LANRegisterProtocol(
1332 * FUNCTION: Registers this protocol driver with NDIS
1334 * Name = Name of this protocol driver
1336 * Status of operation
1339 NDIS_STATUS NdisStatus
;
1340 NDIS_PROTOCOL_CHARACTERISTICS ProtChars
;
1342 TI_DbgPrint(DEBUG_DATALINK
, ("Called.\n"));
1344 InitializeListHead(&AdapterListHead
);
1345 KeInitializeSpinLock(&AdapterListLock
);
1347 /* Set up protocol characteristics */
1348 RtlZeroMemory(&ProtChars
, sizeof(NDIS_PROTOCOL_CHARACTERISTICS
));
1349 ProtChars
.MajorNdisVersion
= NDIS_VERSION_MAJOR
;
1350 ProtChars
.MinorNdisVersion
= NDIS_VERSION_MINOR
;
1351 ProtChars
.Name
.Length
= Name
->Length
;
1352 ProtChars
.Name
.Buffer
= Name
->Buffer
;
1353 ProtChars
.Name
.MaximumLength
= Name
->MaximumLength
;
1354 ProtChars
.OpenAdapterCompleteHandler
= ProtocolOpenAdapterComplete
;
1355 ProtChars
.CloseAdapterCompleteHandler
= ProtocolCloseAdapterComplete
;
1356 ProtChars
.ResetCompleteHandler
= ProtocolResetComplete
;
1357 ProtChars
.RequestCompleteHandler
= ProtocolRequestComplete
;
1358 ProtChars
.SendCompleteHandler
= ProtocolSendComplete
;
1359 ProtChars
.TransferDataCompleteHandler
= ProtocolTransferDataComplete
;
1360 ProtChars
.ReceiveHandler
= ProtocolReceive
;
1361 ProtChars
.ReceiveCompleteHandler
= ProtocolReceiveComplete
;
1362 ProtChars
.StatusHandler
= ProtocolStatus
;
1363 ProtChars
.StatusCompleteHandler
= ProtocolStatusComplete
;
1364 ProtChars
.BindAdapterHandler
= ProtocolBindAdapter
;
1365 ProtChars
.PnPEventHandler
= ProtocolPnPEvent
;
1366 ProtChars
.UnbindAdapterHandler
= ProtocolUnbindAdapter
;
1367 ProtChars
.UnloadHandler
= LANUnregisterProtocol
;
1369 /* Try to register protocol */
1370 NdisRegisterProtocol(&NdisStatus
,
1371 &NdisProtocolHandle
,
1373 sizeof(NDIS_PROTOCOL_CHARACTERISTICS
));
1374 if (NdisStatus
!= NDIS_STATUS_SUCCESS
)
1376 TI_DbgPrint(DEBUG_DATALINK
, ("NdisRegisterProtocol failed, status 0x%x\n", NdisStatus
));
1377 return (NTSTATUS
)NdisStatus
;
1380 ProtocolRegistered
= TRUE
;
1382 return STATUS_SUCCESS
;