AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/addons/dhcp/nxd_dhcpv6_server.c
UINT    _nx_dhcpv6_set_server_duid(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT duid_type, UINT hardware_type, 
                                      ULONG mac_address_msw, ULONG mac_address_lsw, ULONG time)
{

NX_DHCPV6_SVR_DUID  *duid_ptr;


    duid_ptr = &dhcpv6_server_ptr -> nx_dhcpv6_server_duid;

    /* Initialize the DUID to null. */
    memset(duid_ptr, 0, sizeof(NX_DHCPV6_SVR_DUID));

    /* Assign the DUID op code. */
    duid_ptr -> nx_op_code = NX_DHCPV6_OP_DUID_SERVER;

    /* Set the DUID type. */
    duid_ptr -> nx_duid_type = (USHORT)duid_type;

    /* Set the DUID data for a non vendor DUID. */
    if (duid_ptr -> nx_duid_type != NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED)
    {

        /* Server has a valid link local address.  Add this to the server DUID fields
           if not a vendor assigned DUID type. */
        duid_ptr-> nx_link_layer_address_msw = (USHORT)mac_address_msw;
        duid_ptr -> nx_link_layer_address_lsw =  mac_address_lsw;
    
        /* Set the hardware type. */
        duid_ptr -> nx_hardware_type = (USHORT)hardware_type;
    }
    else
    {
        /* This is a private vendor DUID with private vendor ID. */
        duid_ptr -> nx_duid_enterprise_number = NX_DHCPV6_SERVER_DUID_VENDOR_PRIVATE_ID;

        /* Check that the server vendor ID size. */
        if (sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID) > NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_LENGTH)
        {
            return NX_DHCPV6_INVALID_VENDOR_DATA;
        }

        memcpy(&duid_ptr -> nx_duid_private_identifier[0], NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID, sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID)); /* Use case of memcpy is verified. */
    }

    /* Now set the server DUID length. This will depend on DUID type. */
    if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY)
    {

        /* Set the length to include the duid type, hardware type, msw and lsw fields. */
        duid_ptr -> nx_option_length = 3 * sizeof(USHORT) + sizeof(ULONG);
    }
    else if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME)
    {

        /* Set the length to include the duid type, hardware type, time, and msw and lsw fields. */
        duid_ptr -> nx_option_length = 3 * sizeof(USHORT) + 2 * sizeof(ULONG);

        /* Set the DUID time. */
        duid_ptr -> nx_duid_time = time;

    }
    else if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED)
    {

        /* Set the length to include the duid type, hardware type, enterprise number and 
           variable length private identifier. */
        duid_ptr -> nx_option_length = sizeof(USHORT) + sizeof(ULONG) + sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID);
    }
    else
    {

        /* Undefined or unknown DUID type.  Return error status. */
        return NX_DHCPV6_BAD_SERVER_DUID;
    }

     return NX_SUCCESS;
}
/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_dhcpv6_set_server_duid                          PORTABLE C      */
/*                                                           6.1          */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function creates the server DUID with the input data.          */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    dhcpv6_server_ptr                 Pointer to DHCPv6 server instance */
/*    duid_type                         Type of DUID, e.g. LL or LLT      */
/*    hardware_type                     Network hardware type e.g IEEE 802*/
/*    mac_address_msw                   Mac address most significant bit  */
/*    mac_address_lsw                   Mac address least significant bit */
/*    time                              Time data for link layer DUIDs    */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                              Actual completion status        */
/*    NX_SUCCESS                          Successful completion status    */
/*    NX_DHCPV6_BAD_SERVER_DUID           Unknown or invalid DUID type    */
/*    NX_DHCPV6_INVALID_VENDOR_DATA       Invalid Vendor ID supplied      */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    memset                            Clear specified area of memory    */
/*    memcpy                            Copy data to specified location   */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application Code                                                    */
/*                                                                        */
/*  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_set_server_duid                          PORTABLE C
6.1
AUTHOR

Yuxin Zhou, Microsoft Corporation

DESCRIPTION

This function creates the server DUID with the input data.

INPUT

dhcpv6_server_ptr                 Pointer to DHCPv6 server instance
duid_type                         Type of DUID, e.g. LL or LLT
hardware_type                     Network hardware type e.g IEEE 802
mac_address_msw                   Mac address most significant bit
mac_address_lsw                   Mac address least significant bit
time                              Time data for link layer DUIDs

OUTPUT

status                              Actual completion status
NX_SUCCESS                          Successful completion status
NX_DHCPV6_BAD_SERVER_DUID           Unknown or invalid DUID type
NX_DHCPV6_INVALID_VENDOR_DATA       Invalid Vendor ID supplied

CALLS

memset                            Clear specified area of memory
memcpy                            Copy data to specified location

CALLED BY

Application Code

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_set_server_duid PORTABLE C 6 . 1 AUTHOR Yuxin Zhou Microsoft Corporation DESCRIPTION This function creates the server DUID with the input data . INPUT dhcpv6_server_ptr Pointer to DHCPv6 server instance duid_type Type of DUID e . g . LL or LLT hardware_type Network hardware type e . g IEEE 802 mac_address_msw Mac address most significant bit mac_address_lsw Mac address least significant bit time Time data for link layer DUIDs OUTPUT status Actual completion status NX_SUCCESS Successful completion status NX_DHCPV6_BAD_SERVER_DUID Unknown or invalid DUID type NX_DHCPV6_INVALID_VENDOR_DATA Invalid Vendor ID supplied CALLS memset Clear specified area of memory memcpy Copy data to specified location CALLED BY Application Code 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_set_server_duid(NX_DHCPV6_SERVER *dhcpv6_server_ptr, UINT duid_type, UINT hardware_type, 
                                      ULONG mac_address_msw, ULONG mac_address_lsw, ULONG time)
{
NX_DHCPV6_SVR_DUID  *duid_ptr;
    duid_ptr = &dhcpv6_server_ptr -> nx_dhcpv6_server_duid;
    memset(duid_ptr, 0, sizeof(NX_DHCPV6_SVR_DUID));
    duid_ptr -> nx_op_code = NX_DHCPV6_OP_DUID_SERVER;
    duid_ptr -> nx_duid_type = (USHORT)duid_type;
    if (duid_ptr -> nx_duid_type != NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED)
    {
        duid_ptr-> nx_link_layer_address_msw = (USHORT)mac_address_msw;
        duid_ptr -> nx_link_layer_address_lsw =  mac_address_lsw;
        duid_ptr -> nx_hardware_type = (USHORT)hardware_type;
    }
    else
    {
        duid_ptr -> nx_duid_enterprise_number = NX_DHCPV6_SERVER_DUID_VENDOR_PRIVATE_ID;
        if (sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID) > NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_LENGTH)
        {
            return NX_DHCPV6_INVALID_VENDOR_DATA;
        }
        memcpy(&duid_ptr -> nx_duid_private_identifier[0], NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID, sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID)); 
    }
    if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY)
    {
        duid_ptr -> nx_option_length = 3 * sizeof(USHORT) + sizeof(ULONG);
    }
    else if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME)
    {
        duid_ptr -> nx_option_length = 3 * sizeof(USHORT) + 2 * sizeof(ULONG);
        duid_ptr -> nx_duid_time = time;
    }
    else if (duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED)
    {
        duid_ptr -> nx_option_length = sizeof(USHORT) + sizeof(ULONG) + sizeof(NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID);
    }
    else
    {
        return NX_DHCPV6_BAD_SERVER_DUID;
    }
     return NX_SUCCESS;
}
UINT _nx_dhcpv6_set_server_duid ( NX_DHCPV6_SERVER * dhcpv6_server_ptr , UINT duid_type , UINT hardware_type , ULONG mac_address_msw , ULONG mac_address_lsw , ULONG time ) { NX_DHCPV6_SVR_DUID * duid_ptr ; duid_ptr = & dhcpv6_server_ptr -> nx_dhcpv6_server_duid ; memset ( duid_ptr , 0 , sizeof ( NX_DHCPV6_SVR_DUID ) ) ; duid_ptr -> nx_op_code = NX_DHCPV6_OP_DUID_SERVER ; duid_ptr -> nx_duid_type = ( USHORT ) duid_type ; if ( duid_ptr -> nx_duid_type != NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED ) { duid_ptr -> nx_link_layer_address_msw = ( USHORT ) mac_address_msw ; duid_ptr -> nx_link_layer_address_lsw = mac_address_lsw ; duid_ptr -> nx_hardware_type = ( USHORT ) hardware_type ; } else { duid_ptr -> nx_duid_enterprise_number = NX_DHCPV6_SERVER_DUID_VENDOR_PRIVATE_ID ; if ( sizeof ( NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID ) > NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_LENGTH ) { return NX_DHCPV6_INVALID_VENDOR_DATA ; } memcpy ( & duid_ptr -> nx_duid_private_identifier [ 0 ] , NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID , sizeof ( NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID ) ) ; } if ( duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_ONLY ) { duid_ptr -> nx_option_length = 3 * sizeof ( USHORT ) + sizeof ( ULONG ) ; } else if ( duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_LINK_TIME ) { duid_ptr -> nx_option_length = 3 * sizeof ( USHORT ) + 2 * sizeof ( ULONG ) ; duid_ptr -> nx_duid_time = time ; } else if ( duid_ptr -> nx_duid_type == NX_DHCPV6_SERVER_DUID_TYPE_VENDOR_ASSIGNED ) { duid_ptr -> nx_option_length = sizeof ( USHORT ) + sizeof ( ULONG ) + sizeof ( NX_DHCPV6_SERVER_DUID_VENDOR_ASSIGNED_ID ) ; } else { return NX_DHCPV6_BAD_SERVER_DUID ; } return NX_SUCCESS ; }
FUNCTION                                               RELEASE
FUNCTION RELEASE
/* Initialize the DUID to null. */ /* Assign the DUID op code. */ /* Set the DUID type. */ /* Set the DUID data for a non vendor DUID. */ /* Server has a valid link local address.  Add this to the server DUID fields
           if not a vendor assigned DUID type. */ /* Set the hardware type. */ /* This is a private vendor DUID with private vendor ID. */ /* Check that the server vendor ID size. */ /* Use case of memcpy is verified. */ /* Now set the server DUID length. This will depend on DUID type. */ /* Set the length to include the duid type, hardware type, msw and lsw fields. */ /* Set the length to include the duid type, hardware type, time, and msw and lsw fields. */ /* Set the DUID time. */ /* Set the length to include the duid type, hardware type, enterprise number and 
           variable length private identifier. */ /* Undefined or unknown DUID type.  Return error status. */