AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT _nx_dhcpv6_add_iana_status(NX_DHCPV6_SERVER *dhcpv6_server_ptr, NX_DHCPV6_SERVER_IANA_STATUS *iana_status_ptr, UCHAR *buffer_ptr, UINT *index)
{

ULONG   message_word;
USHORT  message_short;
UINT    available_payload;
UINT    message_length;


    /* Compute the available payload in the packet buffer. */
    available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - 
                        NX_IPv6_UDP_PACKET - *index;

    /* Check if the status option will fit in the packet buffer. */
    if (available_payload < (UINT)(iana_status_ptr -> nx_option_length + 4)) 
    {

        /* Hmmm... not enough! Can't do it. */
        return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD;
    }

    /* Clear memory to make the message header. */
    memset(&message_word, 0, sizeof(ULONG));

    /* Compile the header for the status option. */
    message_word = (ULONG)(iana_status_ptr -> nx_op_code << 16);
    message_word |= (iana_status_ptr -> nx_option_length);

    /* Adjust for endianness. */
    NX_CHANGE_ULONG_ENDIAN(message_word);

    /* Copy the word to packet buffer. */
    memcpy(buffer_ptr + *index, &message_word, sizeof(UINT)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(UINT);

    memset(&message_word, 0, sizeof(ULONG));

    /* Set up the status option code. */
    message_short = iana_status_ptr -> nx_status_code;

    /* Adjust for endianness. */
    NX_CHANGE_USHORT_ENDIAN(message_short);

    /* Set up the DUID option. */
    memcpy(buffer_ptr + *index, &message_short, sizeof(USHORT)); /* Use case of memcpy is verified. */
    *index += (ULONG)sizeof(USHORT);

    message_length = iana_status_ptr -> nx_option_length - (ULONG)(sizeof(USHORT));
    memcpy(buffer_ptr + *index, &iana_status_ptr -> nx_status_message[0], message_length); /* Use case of memcpy is verified. */

    *index += message_length;

    /* No need to swap the last byte. */
    return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_add_iana_status                          PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function adds the IANA status option to the server response    */
/*    packet using the input IANA status option.                          */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    dhcpv6_server_ptr                 Pointer to DHCPV6 server instance */
/*    iana_status_ptr                   Pointer to IANA status option     */
/*    buffer_ptr                        Pointer to response packet buffer */
/*    index                             Location into buffer to write data*/
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                        Successful completion status      */
/*    NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD                               */
/*                                      Buffer to small for IA option     */
/*  CALLS                                                                 */
/*                                                                        */
/*    memset                            Clears specified area of memory   */
/*    memcpy                            Copies specified area of memory   */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    _nx_dhcpv6_server_add_iana        Add IANA status to server response*/
/*                                                                        */
/*  RELEASE HISTORY                                                       */
/*                                                                        */
/*    DATE              NAME                      DESCRIPTION             */
/*                                                                        */
/*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
/*  09-30-2020     Yuxin Zhou               Modified comment(s), and      */
/*                                            verified memcpy use cases,  */
/*                                            resulting in version 6.1    */
/*                                                                        */
/**************************************************************************/
FUNCTION                                               RELEASE

_nx_dhcpv6_add_iana_status                          PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function adds the IANA status option to the server response
packet using the input IANA status option.

INPUT

dhcpv6_server_ptr                 Pointer to DHCPV6 server instance
iana_status_ptr                   Pointer to IANA status option
buffer_ptr                        Pointer to response packet buffer
index                             Location into buffer to write data

OUTPUT

NX_SUCCESS                        Successful completion status
NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD
Buffer to small for IA option
CALLS

memset                            Clears specified area of memory
memcpy                            Copies specified area of memory

CALLED BY

_nx_dhcpv6_server_add_iana        Add IANA status to server response

RELEASE HISTORY

DATE              NAME                      DESCRIPTION

05-19-2020     Yuxin Zhou               Initial Version 6.0
09-30-2020     Yuxin Zhou               Modified comment(s), and
verified memcpy use cases,
resulting in version 6.1
FUNCTION RELEASE _nx_dhcpv6_add_iana_status PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function adds the IANA status option to the server response packet using the input IANA status option . INPUT dhcpv6_server_ptr Pointer to DHCPV6 server instance iana_status_ptr Pointer to IANA status option buffer_ptr Pointer to response packet buffer index Location into buffer to write data OUTPUT NX_SUCCESS Successful completion status NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD Buffer to small for IA option CALLS memset Clears specified area of memory memcpy Copies specified area of memory CALLED BY _nx_dhcpv6_server_add_iana Add IANA status to server response RELEASE HISTORY DATE NAME DESCRIPTION 05 - 19 - 2020 Yuxin Zhou Initial Version 6 . 0 09 - 30 - 2020 Yuxin Zhou Modified comment ( s ) and verified memcpy use cases resulting in version 6 . 1
UINT _nx_dhcpv6_add_iana_status(NX_DHCPV6_SERVER *dhcpv6_server_ptr, NX_DHCPV6_SERVER_IANA_STATUS *iana_status_ptr, UCHAR *buffer_ptr, UINT *index)
{
ULONG   message_word;
USHORT  message_short;
UINT    available_payload;
UINT    message_length;
    available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - 
                        NX_IPv6_UDP_PACKET - *index;
    if (available_payload < (UINT)(iana_status_ptr -> nx_option_length + 4)) 
    {
        return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD;
    }
    memset(&message_word, 0, sizeof(ULONG));
    message_word = (ULONG)(iana_status_ptr -> nx_op_code << 16);
    message_word |= (iana_status_ptr -> nx_option_length);
    NX_CHANGE_ULONG_ENDIAN(message_word);
    memcpy(buffer_ptr + *index, &message_word, sizeof(UINT)); 
    *index += (ULONG)sizeof(UINT);
    memset(&message_word, 0, sizeof(ULONG));
    message_short = iana_status_ptr -> nx_status_code;
    NX_CHANGE_USHORT_ENDIAN(message_short);
    memcpy(buffer_ptr + *index, &message_short, sizeof(USHORT)); 
    *index += (ULONG)sizeof(USHORT);
    message_length = iana_status_ptr -> nx_option_length - (ULONG)(sizeof(USHORT));
    memcpy(buffer_ptr + *index, &iana_status_ptr -> nx_status_message[0], message_length); 
    *index += message_length;
    return NX_SUCCESS;
}
UINT _nx_dhcpv6_add_iana_status ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , NX_DHCPV6_SERVER_IANA_STATUS * iana_status_ptr , UCHAR * buffer_ptr , UINT * index ) { ULONG message_word ; USHORT message_short ; UINT available_payload ; UINT message_length ; available_payload = dhcpv6_server_ptr -> nx_dhcpv6_packet_pool_ptr -> nx_packet_pool_payload_size - NX_IPv6_UDP_PACKET - * index ; if ( available_payload < ( UINT ) ( iana_status_ptr -> nx_option_length + 4 ) ) { return NX_DHCPV6_INSUFFICIENT_PACKET_PAYLOAD ; } memset ( & message_word , 0 , sizeof ( ULONG ) ) ; message_word = ( ULONG ) ( iana_status_ptr -> nx_op_code << 16 ) ; message_word |= ( iana_status_ptr -> nx_option_length ) ; NX_CHANGE_ULONG_ENDIAN ( message_word ) ; memcpy ( buffer_ptr + * index , & message_word , sizeof ( UINT ) ) ; * index += ( ULONG ) sizeof ( UINT ) ; memset ( & message_word , 0 , sizeof ( ULONG ) ) ; message_short = iana_status_ptr -> nx_status_code ; NX_CHANGE_USHORT_ENDIAN ( message_short ) ; memcpy ( buffer_ptr + * index , & message_short , sizeof ( USHORT ) ) ; * index += ( ULONG ) sizeof ( USHORT ) ; message_length = iana_status_ptr -> nx_option_length - ( ULONG ) ( sizeof ( USHORT ) ) ; memcpy ( buffer_ptr + * index , & iana_status_ptr -> nx_status_message [ 0 ] , message_length ) ; * index += message_length ; return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Compute the available payload in the packet buffer. */ /* Check if the status option will fit in the packet buffer. */ /* Hmmm... not enough! Can't do it. */ /* Clear memory to make the message header. */ /* Compile the header for the status option. */ /* Adjust for endianness. */ /* Copy the word to packet buffer. */ /* Use case of memcpy is verified. */ /* Set up the status option code. */ /* Adjust for endianness. */ /* Set up the DUID option. */ /* Use case of memcpy is verified. */ /* Use case of memcpy is verified. */ /* No need to swap the last byte. */