Windows System Software -- Consulting, Training, Development -- Unique Expertise, Guaranteed Results

Home NTDEV
Before Posting...
Please check out the Community Guidelines in the Announcements and Administration Category.

More Info on Driver Writing and Debugging


The free OSR Learning Library has more than 50 articles on a wide variety of topics about writing and debugging device drivers and Minifilters. From introductory level to advanced. All the articles have been recently reviewed and updated, and are written using the clear and definitive style you've come to expect from OSR over the years.


Check out The OSR Learning Library at: https://www.osr.com/osr-learning-library/


NdisGetDataBuffer - Storage Parameter

Rami_Reddy_VangaRami_Reddy_Vanga Member Posts: 18
I retrieve the Buffer into storage parameter, If I do some modifications on the retrieved buffer, will that reflect in the NB associated with this buffer.

Here is what I am trying to do.

currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

packetData = (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
total_nb_length,
TAG,
HighPoolPriority);

if (packetData == NULL)
{
break;
}

bufferAddress = NdisGetDataBuffer(currNB, total_nb_length, packetData, 1, 0);

if (bufferAddress == NULL)
{
break;
}

packetData[total_nb_length - 1] = 10 // Example Sequence Number.

NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);

Comments

  • Jan_BottorffJan_Bottorff Member - All Emails Posts: 471
    It may or may not be changing the original NB buffer memory. NdisGetDataBuffer is documented as returning a pointer to the original buffer if it's contiguous, but copying to your supplied buffer if it's multiple fragments.

    Jan

    ________________________________
    From: [email protected] on behalf of [email protected]
    Sent: Tuesday, February 7, 2017 4:59:40 AM
    To: Windows System Software Devs Interest List
    Subject: [ntdev] NdisGetDataBuffer - Storage Parameter

    I retrieve the Buffer into storage parameter, If I do some modifications on the retrieved buffer, will that reflect in the NB associated with this buffer.

    Here is what I am trying to do.

    currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
    total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

    packetData = (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
    total_nb_length,
    TAG,
    HighPoolPriority);

    if (packetData == NULL)
    {
    break;
    }

    bufferAddress = NdisGetDataBuffer(currNB, total_nb_length, packetData, 1, 0);

    if (bufferAddress == NULL)
    {
    break;
    }

    packetData[total_nb_length - 1] = 10 // Example Sequence Number.

    NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);


    ---
    NTDEV is sponsored by OSR

    Visit the list online at:

    MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
    Details at

    To unsubscribe, visit the List Server section of OSR Online at
  • Rami_Reddy_VangaRami_Reddy_Vanga Member Posts: 18
    Thanks Jan, I will retrieve the buffer using NdisGetDataBuffer, and do modifications on the buffer as needed, and create a new NBL like mentioned below. Let me know if the approach is right path.

    currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
    total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

    packetData =
    (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
    total_nb_length,
    TAG,
    HighPoolPriority);

    if (packetData == NULL)
    {
    break;
    }

    bufferAddress = NdisGetDataBuffer(currNB, total_nb_length,
    packetData, 1, 0);

    if (bufferAddress == NULL)
    {
    break;
    }

    packetData[total_nb_length - 1] = 10 // Example Sequence
    Number.

    // Allocate Memory for MDL
    MDL= NdisAllocateMdl(pAdapt->SendBufferPoolHandle,
    packetData,
    total_nb_length);

    if (MDL== NULL)
    {
    return;
    }

    // No Chained MDL's
    MDL->Next = NULL;

    NBL= NdisAllocateNetBufferAndNetBufferList(pAdapt->SendPacketPoolHandle,
    0,
    0,
    MDL,
    0,
    total_nb_length);

    NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);
  • Jan_BottorffJan_Bottorff Member - All Emails Posts: 471
    Nope, not correct. Read what I previously said about the value returned by NdisGetDataBuffer. Your buffer MIGHT not have been used at all.

    Jan

    ________________________________
    From: [email protected] on behalf of [email protected]
    Sent: Tuesday, February 7, 2017 9:16:15 PM
    To: Windows System Software Devs Interest List
    Subject: RE:[ntdev] NdisGetDataBuffer - Storage Parameter

    Thanks Jan, I will retrieve the buffer using NdisGetDataBuffer, and do modifications on the buffer as needed, and create a new NBL like mentioned below. Let me know if the approach is right path.

    currNB = NET_BUFFER_LIST_FIRST_NB(NBL);
    total_nb_length = NET_BUFFER_DATA_LENGTH(currNB);

    packetData =
    (PUCHAR)NdisAllocateMemoryWithTagPriority(pAdapt->FilterHandle,
    total_nb_length,
    TAG,
    HighPoolPriority);

    if (packetData == NULL)
    {
    break;
    }

    bufferAddress = NdisGetDataBuffer(currNB, total_nb_length,
    packetData, 1, 0);

    if (bufferAddress == NULL)
    {
    break;
    }

    packetData[total_nb_length - 1] = 10 // Example Sequence
    Number.

    // Allocate Memory for MDL
    MDL= NdisAllocateMdl(pAdapt->SendBufferPoolHandle,
    packetData,
    total_nb_length);

    if (MDL== NULL)
    {
    return;
    }

    // No Chained MDL's
    MDL->Next = NULL;

    NBL= NdisAllocateNetBufferAndNetBufferList(pAdapt->SendPacketPoolHandle,
    0,
    0,
    MDL,
    0,
    total_nb_length);

    NdisFSendNetBufferLists(pAdapt->FilterHandle, NBL, portNumber, sendFlags);


    ---
    NTDEV is sponsored by OSR

    Visit the list online at:

    MONTHLY seminars on crash dump analysis, WDF, Windows internals and software drivers!
    Details at

    To unsubscribe, visit the List Server section of OSR Online at
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Upcoming OSR Seminars
OSR has suspended in-person seminars due to the Covid-19 outbreak. But, don't miss your training! Attend via the internet instead!
Kernel Debugging 30 Mar 2020 OSR Seminar Space
Developing Minifilters 15 Jun 2020 LIVE ONLINE
Writing WDF Drivers 22 June 2020 LIVE ONLINE
Internals & Software Drivers 28 Sept 2020 Dulles, VA