AzureMXChip/MXCHIPAZ3166/core/lib/netxduo/samples/demo_netx_nat.c
void    tx_application_define(void *first_unused_memory)
{

UINT     status;
UCHAR    *pointer;
    
    /* Initialize the NetX system. */
    nx_system_initialize();
    
    /* Setup the pointer to unallocated memory.  */
    pointer =  (UCHAR *) first_unused_memory;
                          
    /* Create the main thread.  */
    tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,  
                     pointer, DEMO_STACK_SIZE, 
                     4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
    pointer =  pointer + DEMO_STACK_SIZE;    

    /* Create NAT packet pool. */   
    status =  nx_packet_pool_create(&nat_packet_pool, "NAT Packet Pool", 
                                    NX_NAT_PACKET_SIZE, pointer, 
                                    NX_NAT_PACKET_POOL_SIZE);

    /* Update pointer to unallocated (free) memory. */
    pointer = pointer + NX_NAT_PACKET_POOL_SIZE;    

    /* Check status.  */
    if (status)
        return;
                            
    /* Create IP instances for NAT server (global network) */
    status = nx_ip_create(&nat_ip, "NAT IP Instance", NX_NAT_EXTERNAL_IPADR, NX_NAT_EXTERNAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);

    /* Update pointer to unallocated (free) memory. */
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;

    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }
                 
    /* Set the private interface(private network).  */
    status += nx_ip_interface_attach(&nat_ip, "Private Interface", NX_NAT_LOCAL_IPADR, NX_NAT_LOCAL_NETMASK, _nx_ram_network_driver);
             
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }                
                                     
    /* Create IP instances for Local network IP instance */
    status = nx_ip_create(&local_ip, "Local IP Instance", NX_NAT_LOCAL_HOST1, NX_NAT_LOCAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);

    /* Update pointer to unallocated (free) memory. */
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;

    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }
                  
    /* Create IP instances for external network IP instance */
    status = nx_ip_create(&external_ip, "External IP Instance", NX_NAT_EXTERNAL_HOST, NX_NAT_EXTERNAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);

    /* Update pointer to unallocated (free) memory. */
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;

    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }

    /* Set the global network gateway for NAT IP instance.  */
    status = nx_ip_gateway_address_set(&nat_ip, NX_NAT_EXTERNAL_GATEWAY);
                       
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }                     
    
    /* Set the global network gateway for Local IP instance.  */
    status = nx_ip_gateway_address_set(&local_ip, NX_NAT_LOCAL_GATEWAY);
                       
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }                     
    
    /* Set the global network gateway for External IP instance.  */
    status = nx_ip_gateway_address_set(&external_ip, NX_NAT_EXTERNAL_GATEWAY);
                       
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }                     

    
    /* Enable ARP and supply ARP cache memory for NAT IP isntance. */
    status =  nx_arp_enable(&nat_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
                         
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }           
    
    /* Update pointer to unallocated (free) memory. */
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;
                                              
    /* Enable ARP and supply ARP cache memory for Local IP isntance. */
    status =  nx_arp_enable(&local_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
                         
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }           
    
    /* Update pointer to unallocated (free) memory. */
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;
                                             
    /* Enable ARP and supply ARP cache memory for External IP isntance. */
    status =  nx_arp_enable(&external_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
                         
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }           
    
    /* Update pointer to unallocated (free) memory. */
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;

    /* Enable ICMP. */
    nx_icmp_enable(&nat_ip);   
    nx_icmp_enable(&local_ip);   
    nx_icmp_enable(&external_ip);    
                                    
    /* Create a NetX NAT server and cache with a global interface index.  */
    status =  nx_nat_create(&nat_server, &nat_ip, 0, pointer, NX_NAT_ENTRY_CACHE_SIZE);
                             
    /* Check status.  */
    if (status)
    {
        error_counter++;
        return;
    }           

    /* Update pointer to unallocated (free) memory. */
    pointer = pointer + NX_NAT_ENTRY_CACHE_SIZE;                
}
/* Define what the initial system looks like.  */
Define what the initial system looks like.
Define what the initial system looks like .
void    tx_application_define(void *first_unused_memory)
{
UINT     status;
UCHAR    *pointer;
    nx_system_initialize();
    pointer =  (UCHAR *) first_unused_memory;
    tx_thread_create(&ntest_0, "thread 0", ntest_0_entry, 0,  
                     pointer, DEMO_STACK_SIZE, 
                     4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
    pointer =  pointer + DEMO_STACK_SIZE;    
    status =  nx_packet_pool_create(&nat_packet_pool, "NAT Packet Pool", 
                                    NX_NAT_PACKET_SIZE, pointer, 
                                    NX_NAT_PACKET_POOL_SIZE);
    pointer = pointer + NX_NAT_PACKET_POOL_SIZE;    
    if (status)
        return;
    status = nx_ip_create(&nat_ip, "NAT IP Instance", NX_NAT_EXTERNAL_IPADR, NX_NAT_EXTERNAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;
    if (status)
    {
        error_counter++;
        return;
    }
    status += nx_ip_interface_attach(&nat_ip, "Private Interface", NX_NAT_LOCAL_IPADR, NX_NAT_LOCAL_NETMASK, _nx_ram_network_driver);
    if (status)
    {
        error_counter++;
        return;
    }                
    status = nx_ip_create(&local_ip, "Local IP Instance", NX_NAT_LOCAL_HOST1, NX_NAT_LOCAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;
    if (status)
    {
        error_counter++;
        return;
    }
    status = nx_ip_create(&external_ip, "External IP Instance", NX_NAT_EXTERNAL_HOST, NX_NAT_EXTERNAL_NETMASK, 
                          &nat_packet_pool, _nx_ram_network_driver, pointer, 
                          NX_NAT_IP_THREAD_STACK_SIZE, NX_NAT_IP_THREAD_PRIORITY);
    pointer =  pointer + NX_NAT_IP_THREAD_STACK_SIZE;
    if (status)
    {
        error_counter++;
        return;
    }
    status = nx_ip_gateway_address_set(&nat_ip, NX_NAT_EXTERNAL_GATEWAY);
    if (status)
    {
        error_counter++;
        return;
    }                     
    status = nx_ip_gateway_address_set(&local_ip, NX_NAT_LOCAL_GATEWAY);
    if (status)
    {
        error_counter++;
        return;
    }                     
    status = nx_ip_gateway_address_set(&external_ip, NX_NAT_EXTERNAL_GATEWAY);
    if (status)
    {
        error_counter++;
        return;
    }                     
    status =  nx_arp_enable(&nat_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
    if (status)
    {
        error_counter++;
        return;
    }           
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;
    status =  nx_arp_enable(&local_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
    if (status)
    {
        error_counter++;
        return;
    }           
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;
    status =  nx_arp_enable(&external_ip, (void **) pointer, 
                            NX_NAT_ARP_CACHE_SIZE);
    if (status)
    {
        error_counter++;
        return;
    }           
    pointer = pointer + NX_NAT_ARP_CACHE_SIZE;
    nx_icmp_enable(&nat_ip);   
    nx_icmp_enable(&local_ip);   
    nx_icmp_enable(&external_ip);    
    status =  nx_nat_create(&nat_server, &nat_ip, 0, pointer, NX_NAT_ENTRY_CACHE_SIZE);
    if (status)
    {
        error_counter++;
        return;
    }           
    pointer = pointer + NX_NAT_ENTRY_CACHE_SIZE;                
}
void tx_application_define ( void * first_unused_memory ) { UINT status ; UCHAR * pointer ; nx_system_initialize ( ) ; pointer = ( UCHAR * ) first_unused_memory ; tx_thread_create ( & ntest_0 , " " , ntest_0_entry , 0 , pointer , DEMO_STACK_SIZE , 4 , 4 , TX_NO_TIME_SLICE , TX_AUTO_START ) ; pointer = pointer + DEMO_STACK_SIZE ; status = nx_packet_pool_create ( & nat_packet_pool , " " , NX_NAT_PACKET_SIZE , pointer , NX_NAT_PACKET_POOL_SIZE ) ; pointer = pointer + NX_NAT_PACKET_POOL_SIZE ; if ( status ) return ; status = nx_ip_create ( & nat_ip , " " , NX_NAT_EXTERNAL_IPADR , NX_NAT_EXTERNAL_NETMASK , & nat_packet_pool , _nx_ram_network_driver , pointer , NX_NAT_IP_THREAD_STACK_SIZE , NX_NAT_IP_THREAD_PRIORITY ) ; pointer = pointer + NX_NAT_IP_THREAD_STACK_SIZE ; if ( status ) { error_counter ++ ; return ; } status += nx_ip_interface_attach ( & nat_ip , " " , NX_NAT_LOCAL_IPADR , NX_NAT_LOCAL_NETMASK , _nx_ram_network_driver ) ; if ( status ) { error_counter ++ ; return ; } status = nx_ip_create ( & local_ip , " " , NX_NAT_LOCAL_HOST1 , NX_NAT_LOCAL_NETMASK , & nat_packet_pool , _nx_ram_network_driver , pointer , NX_NAT_IP_THREAD_STACK_SIZE , NX_NAT_IP_THREAD_PRIORITY ) ; pointer = pointer + NX_NAT_IP_THREAD_STACK_SIZE ; if ( status ) { error_counter ++ ; return ; } status = nx_ip_create ( & external_ip , " " , NX_NAT_EXTERNAL_HOST , NX_NAT_EXTERNAL_NETMASK , & nat_packet_pool , _nx_ram_network_driver , pointer , NX_NAT_IP_THREAD_STACK_SIZE , NX_NAT_IP_THREAD_PRIORITY ) ; pointer = pointer + NX_NAT_IP_THREAD_STACK_SIZE ; if ( status ) { error_counter ++ ; return ; } status = nx_ip_gateway_address_set ( & nat_ip , NX_NAT_EXTERNAL_GATEWAY ) ; if ( status ) { error_counter ++ ; return ; } status = nx_ip_gateway_address_set ( & local_ip , NX_NAT_LOCAL_GATEWAY ) ; if ( status ) { error_counter ++ ; return ; } status = nx_ip_gateway_address_set ( & external_ip , NX_NAT_EXTERNAL_GATEWAY ) ; if ( status ) { error_counter ++ ; return ; } status = nx_arp_enable ( & nat_ip , ( void * * ) pointer , NX_NAT_ARP_CACHE_SIZE ) ; if ( status ) { error_counter ++ ; return ; } pointer = pointer + NX_NAT_ARP_CACHE_SIZE ; status = nx_arp_enable ( & local_ip , ( void * * ) pointer , NX_NAT_ARP_CACHE_SIZE ) ; if ( status ) { error_counter ++ ; return ; } pointer = pointer + NX_NAT_ARP_CACHE_SIZE ; status = nx_arp_enable ( & external_ip , ( void * * ) pointer , NX_NAT_ARP_CACHE_SIZE ) ; if ( status ) { error_counter ++ ; return ; } pointer = pointer + NX_NAT_ARP_CACHE_SIZE ; nx_icmp_enable ( & nat_ip ) ; nx_icmp_enable ( & local_ip ) ; nx_icmp_enable ( & external_ip ) ; status = nx_nat_create ( & nat_server , & nat_ip , 0 , pointer , NX_NAT_ENTRY_CACHE_SIZE ) ; if ( status ) { error_counter ++ ; return ; } pointer = pointer + NX_NAT_ENTRY_CACHE_SIZE ; }
Define what the initial system looks like.
Define what the initial system looks like .
/* Initialize the NetX system. */ /* Setup the pointer to unallocated memory.  */ /* Create the main thread.  */ /* Create NAT packet pool. */ /* Update pointer to unallocated (free) memory. */ /* Check status.  */ /* Create IP instances for NAT server (global network) */ /* Update pointer to unallocated (free) memory. */ /* Check status.  */ /* Set the private interface(private network).  */ /* Check status.  */ /* Create IP instances for Local network IP instance */ /* Update pointer to unallocated (free) memory. */ /* Check status.  */ /* Create IP instances for external network IP instance */ /* Update pointer to unallocated (free) memory. */ /* Check status.  */ /* Set the global network gateway for NAT IP instance.  */ /* Check status.  */ /* Set the global network gateway for Local IP instance.  */ /* Check status.  */ /* Set the global network gateway for External IP instance.  */ /* Check status.  */ /* Enable ARP and supply ARP cache memory for NAT IP isntance. */ /* Check status.  */ /* Update pointer to unallocated (free) memory. */ /* Enable ARP and supply ARP cache memory for Local IP isntance. */ /* Check status.  */ /* Update pointer to unallocated (free) memory. */ /* Enable ARP and supply ARP cache memory for External IP isntance. */ /* Check status.  */ /* Update pointer to unallocated (free) memory. */ /* Enable ICMP. */ /* Create a NetX NAT server and cache with a global interface index.  */ /* Check status.  */ /* Update pointer to unallocated (free) memory. */