⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 protocol.c

📁 Vitual Ring Routing 管你知不知道
💻 C
📖 第 1 页 / 共 4 页
字号:
                Case5GhzChannel(37);
                Case5GhzChannel(38);
                Case5GhzChannel(39);
                Case5GhzChannel(40);
                Case5GhzChannel(41);
                Case5GhzChannel(42);
                Case5GhzChannel(43);
                Case5GhzChannel(44);
                Case5GhzChannel(45);
                Case5GhzChannel(46);
                Case5GhzChannel(47);
                Case5GhzChannel(48);
                Case5GhzChannel(49);
                Case5GhzChannel(50);
                Case5GhzChannel(51);
                Case5GhzChannel(52);
                Case5GhzChannel(53);
                Case5GhzChannel(54);
                Case5GhzChannel(55);
                Case5GhzChannel(56);
                Case5GhzChannel(57);
                Case5GhzChannel(58);
                Case5GhzChannel(59);
                Case5GhzChannel(60);
                Case5GhzChannel(61);
                Case5GhzChannel(62);
                Case5GhzChannel(63);
                Case5GhzChannel(64);
                // gregos: start non-std 802.11a frequency range.
                Case5GhzChannel(65);
                Case5GhzChannel(66);
                Case5GhzChannel(67);
                Case5GhzChannel(68);
                Case5GhzChannel(69);
                Case5GhzChannel(70);
                Case5GhzChannel(71);
                Case5GhzChannel(72);
                Case5GhzChannel(73);
                Case5GhzChannel(74);
                Case5GhzChannel(75);
                Case5GhzChannel(76);
                Case5GhzChannel(77);
                Case5GhzChannel(78);
                Case5GhzChannel(79);
                Case5GhzChannel(80);
                Case5GhzChannel(81);
                Case5GhzChannel(82);
                Case5GhzChannel(83);
                Case5GhzChannel(84);
                Case5GhzChannel(85);
                Case5GhzChannel(86);
                Case5GhzChannel(87);
                Case5GhzChannel(88);
                Case5GhzChannel(89);
                Case5GhzChannel(90);
                Case5GhzChannel(91);
                Case5GhzChannel(92);
                Case5GhzChannel(93);
                Case5GhzChannel(94);
                Case5GhzChannel(95);
                Case5GhzChannel(96);
                Case5GhzChannel(97);
                Case5GhzChannel(98);
                Case5GhzChannel(99);
                Case5GhzChannel(100);
                Case5GhzChannel(101);
                Case5GhzChannel(102);
                Case5GhzChannel(103);
                Case5GhzChannel(104);
                Case5GhzChannel(105);
                Case5GhzChannel(106);
                Case5GhzChannel(107);
                Case5GhzChannel(108);
                Case5GhzChannel(109);
                Case5GhzChannel(110);
                Case5GhzChannel(111);
                Case5GhzChannel(112);
                Case5GhzChannel(113);
                Case5GhzChannel(114);
                Case5GhzChannel(115);
                Case5GhzChannel(116);
                Case5GhzChannel(117);
                Case5GhzChannel(118);
                Case5GhzChannel(119);
                Case5GhzChannel(120);
                Case5GhzChannel(121);
                Case5GhzChannel(122);
                Case5GhzChannel(123);
                Case5GhzChannel(124);
                Case5GhzChannel(125);
                Case5GhzChannel(126);
                Case5GhzChannel(127);
                Case5GhzChannel(128);
                Case5GhzChannel(129);
                Case5GhzChannel(130);
                Case5GhzChannel(131);
                Case5GhzChannel(132);
                Case5GhzChannel(133);
                Case5GhzChannel(134);
                Case5GhzChannel(135);
                Case5GhzChannel(136);
                Case5GhzChannel(137);
                Case5GhzChannel(138);
                Case5GhzChannel(139);
                Case5GhzChannel(140);
                Case5GhzChannel(141);
                Case5GhzChannel(142);
                Case5GhzChannel(143);
                Case5GhzChannel(144);
                Case5GhzChannel(145);
                Case5GhzChannel(146);
                Case5GhzChannel(147);
                Case5GhzChannel(148);
                // gregos: end non-std 802.11a frequency range.
                Case5GhzChannel(149);
                Case5GhzChannel(150);
                Case5GhzChannel(151);
                Case5GhzChannel(152);
                Case5GhzChannel(153);
                Case5GhzChannel(154);
                Case5GhzChannel(155);
                Case5GhzChannel(156);
                Case5GhzChannel(157);
                Case5GhzChannel(158);
                Case5GhzChannel(159);
                Case5GhzChannel(160);
                Case5GhzChannel(161);
                Case5GhzChannel(162);
                Case5GhzChannel(163);
                Case5GhzChannel(164);
                Case5GhzChannel(165);
            }
        }
    }

    ExReleaseFastMutex(&PA->Mutex);
}

//* ProtocolMediaConnect
//
//  Called as a work-item on a system thread,
//  after NDIS indicates a media-connect event.
//
void
ProtocolMediaConnect(
    DEVICE_OBJECT *DeviceObject,
    void *Context)
{
    ProtocolMediaConnectContext *PMCC =
        (ProtocolMediaConnectContext *) Context;
    PIO_WORKITEM Item = PMCC->Item;
    ProtocolAdapter *PA = PMCC->PA;

    UNREFERENCED_PARAMETER(DeviceObject);

    IoFreeWorkItem(Item);
    ExFreePool(PMCC);

    ProtocolQueryRadioConfiguration(PA);
}

//* ProtocolStatus
//
//  Called by NDIS when some sort of status change occurs.
//  We can take action depending on the type of status.
//
//  Called at DPC level.
//
void
ProtocolStatus(
    NDIS_HANDLE Handle,   // Binding handle.
    NDIS_STATUS GStatus,  // General status type which caused the call.
    void *Status,         // Pointer to buffer of status specific info.
    uint StatusSize)      // Size of the above status buffer.
{
    ProtocolAdapter *PA = (ProtocolAdapter *)Handle;

    UNREFERENCED_PARAMETER(Status);
    UNREFERENCED_PARAMETER(StatusSize);

    KdPrint(("VRR!ProtocolStatus(VA %p PA %p GStatus %x)\n",
             PA->VirtualAdapter, PA, GStatus));

    if (GStatus == NDIS_STATUS_MEDIA_CONNECT) {
        ProtocolMediaConnectContext *PMCC;
        PIO_WORKITEM Item;

        //
        // We can not use ProtocolRequestHelper at DPC level.
        // So we queue a work-item for a system thread.
        //

        PMCC = ExAllocatePool(NonPagedPool, sizeof *PMCC);
        if (PMCC == NULL)
            return;

        Item = IoAllocateWorkItem(PA->VirtualAdapter->DeviceObject);
        if (Item == NULL) {
            ExFreePool(PMCC);
            return;
        }

        PMCC->Item = Item;
        PMCC->PA = PA;

        IoQueueWorkItem(Item, ProtocolMediaConnect, DelayedWorkQueue, PMCC);
    }
}

//* ProtocolStatusComplete
//
//  Called by NDIS after a status event.
//
void
ProtocolStatusComplete(
    NDIS_HANDLE Handle)  // Binding handle.
{
    UNREFERENCED_PARAMETER(Handle);
}

//* ProtocolReturnPacket
//
//  Returns when we have finished processing a packet
//  from ProtocolReceivePacket.
//
void
ProtocolReturnPacket(
    ProtocolAdapter *PA,
    NDIS_PACKET *Packet)
{
    NdisReturnPackets(&Packet, 1);
    InterlockedDecrement((PLONG)&PA->CountRecvOutstanding);
}

//* ProtocolReceivePacket
//
//  Called by NDIS when data arrives from L2 driver.
//  Note that older NDIS drivers are likely to call ProtocolReceive to
//  indicate data arrival instead of this routine.
//
//  Returns the number of references we hold to Packet upon return.
//
int
ProtocolReceivePacket(
    NDIS_HANDLE Handle,   // Binding handle.
    PNDIS_PACKET Packet)  // Packet descriptor for incoming packet.
{
    ProtocolAdapter *PA = (ProtocolAdapter *)Handle;
    NDIS_BUFFER *Buffer;
    void *Address;
    uint Length;
    EtherHeader UNALIGNED *Ether;
    uint UNALIGNED *Code;

    //
    // Find out about the packet we've been handed.
    //
    Buffer = NdisFirstBuffer(Packet);
    NdisQueryBuffer(Buffer, &Address, &Length);

    if (Length < sizeof *Ether + sizeof *Code) {
        //
        // Header data too small to contain an Ethernet header + Code.
        //
        KdPrint(("VRR!ProtocolReceivePacket(VA %p PA %p): Length %u\n",
                 PA->VirtualAdapter, PA, Length));
        return 0;
    }

    Ether = (EtherHeader UNALIGNED *) Address;
    Code = (uint UNALIGNED *) (Ether + 1);

    if ((Ether->Type != ETYPE_MSFT) ||
        (*Code != VRR_CODE))
        return 0;

    InterlockedIncrement((PLONG)&PA->PacketsReceived);
    InterlockedIncrementHighWater((PLONG)&PA->CountRecvOutstanding,
                                  (PLONG)&PA->MaxRecvOutstanding);

    MiniportReceivePacket(PA->VirtualAdapter, PA,
                          Packet, ProtocolReturnPacket);
    return 1;
}

//* ProtocolCloseAdapter
//
//  Closes our connection to NDIS and frees the adapter.
//  The adapter has already been removed
//  from the MiniportAdapter->PhysicalAdapters list.
//
//  Called from thread context, with no locks held.
//
void
ProtocolCloseAdapter(ProtocolAdapter *PA)
{
    NDIS_STATUS Status;

    KdPrint(("VRR!ProtocolCloseAdapter(VA %p PA %p)\n",
             PA->VirtualAdapter, PA));

    //
    // Initialize an event in case NdisCloseAdapter completes
    // asynchronously via ProtocolCloseAdapterComplete.
    //
    KeInitializeEvent(&PA->Event, SynchronizationEvent, FALSE);

    //
    // Close the connection to NDIS.
    //
    // NB: We must not use the Handle after we call NdisCloseAdapter.
    //
    NdisCloseAdapter(&Status, PA->Handle);

    //
    // Wait for the close to complete.
    //
    if (Status == NDIS_STATUS_PENDING) {
        (void) KeWaitForSingleObject(&PA->Event,
                                     UserRequest, KernelMode,
                                     FALSE, NULL);
        Status = PA->Status;
    }

    KdPrint(("VRR!NdisCloseAdapter(VA %p PA %p) -> %x\n",
             PA->VirtualAdapter, PA, Status));

    NdisFreeBufferPool(PA->BufferPool);
    NdisFreePacketPool(PA->PacketPool);
    ExFreePool(PA);
}

//* ProtocolOpenRegKey
//
//  Given an adapter, opens the registry key that holds
//  persistent configuration information for the adapter.
//
//  Callable from thread context, not DPC context.
//
NTSTATUS
ProtocolOpenRegKey(
    ProtocolAdapter *PA,
    OpenRegKeyAction Action,
    OUT HANDLE *RegKey)
{
    MiniportAdapter *VA = PA->VirtualAdapter;
    UNICODE_STRING GuidName;
    HANDLE DeviceKey;
    HANDLE ParamsKey;
    HANDLE AdaptersKey;
    NTSTATUS Status;

    PAGED_CODE();

    //
    // Open our configuration information in the registry.
    //
    Status = IoOpenDeviceRegistryKey(VA->PhysicalDeviceObject,
                                     PLUGPLAY_REGKEY_DRIVER,
                                     GENERIC_READ,
                                     &DeviceKey);
    if (! NT_SUCCESS(Status)) {
        KdPrint(("VRR!IoOpenDeviceRegistryKey -> %x\n", Status));
        return Status;
    }

    Status = OpenRegKey(&ParamsKey, DeviceKey,
                        L"Parameters",
                        ((Action == OpenRegKeyCreate) ?
                         OpenRegKeyCreate : OpenRegKeyRead));
    ZwClose(DeviceKey);
    if (! NT_SUCCESS(Status))
        return Status;

    Status = OpenRegKey(&AdaptersKey, ParamsKey,
                        L"Adapters",
                        ((Action == OpenRegKeyCreate) ?
                         OpenRegKeyCreate : OpenRegKeyRead));
    ZwClose(ParamsKey);
    if (! NT_SUCCESS(Status))
        return Status;

    //
    // Convert the guid to string form.
    //
    Status = RtlStringFromGUID(&PA->Guid, &GuidName);
    if (! NT_SUCCESS(Status)) {
        ZwClose(AdaptersKey);
        return Status;
    }

    //
    // It will be null-terminated.
    //
    VRRASSERT(GuidName.MaximumLength == GuidName.Length + sizeof(WCHAR));
    VRRASSERT(((WCHAR *)GuidName.Buffer)[GuidName.Length/sizeof(WCHAR)] == UNICODE_NULL);

    Status = OpenRegKey(RegKey, AdaptersKey,
                        (WCHAR *)GuidName.Buffer, Action);

    RtlFreeUnicodeString(&GuidName);
    ZwClose(AdaptersKey);
    return Status;
}

//* ProtocolInitAdapter
//
//  Initializes a physical adapter from the registry.
//
void
ProtocolInitAdapter(ProtocolAdapter *PA)
{
    VRR_CONTROL_PHYSICAL_ADAPTER Control;
    HANDLE Key;
    NTSTATUS Status;

    PAGED_CODE();

    //
    // Open our configuration information in the registry.
    //
    Status = ProtocolOpenRegKey(PA, OpenRegKeyCreate, &Key);
    if (! NT_SUCCESS(Status)) {
        KdPrint(("VRR:ProtocolOpenRegKey: %x\n", Status));
        return;
    }

    VRR_INIT_CONTROL_PHYSICAL_ADAPTER(&Control);

    //
    // Read configuration parameters.
    //
    (void) GetRegDWORDValue(Key, L"ReceiveOnly", (PULONG)&Control.ReceiveOnly);
    (void) GetRegDWORDValue(Key, L"Channel", (PULONG)&Control.Channel);
    (void) GetRegDWORDValue(Key, L"Bandwidth", (PULONG)&Control.Bandwidth);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -