Beispiel #1
0
void fapp_mem_cmd ( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t **argv )
{
    const struct fapp_mem_region *mem = fapp_mem_regions;
	const struct fapp_mem_region_reserved *region_reserved = fapp_mem_regions_reserved;

    FNET_COMP_UNUSED_ARG(desc);
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    /* Print memory types. */
	fnet_shell_println(desc, FAPP_MEM_HEADER, "Memory type");
	fnet_shell_println(desc, FAPP_MEM_DELIMITER);
	while(mem->description)
	{
	    fnet_shell_println(desc, MEM_STR, mem->description, mem->address,	
					        mem->address + mem->size - 1u);
	    mem++;
	}

    /* Print protected/reserved memory regions.*/
	fnet_shell_println(desc, FAPP_MEM_HEADER, "Reserved");
	fnet_shell_println(desc, FAPP_MEM_DELIMITER);
	while(region_reserved->description)
	{
	    fnet_shell_println(desc, MEM_STR, region_reserved->description, region_reserved->address,	
									region_reserved->address + region_reserved->size - 1u);
	    region_reserved++;
	}
    fnet_shell_println(desc, "");	

}
Beispiel #2
0
/************************************************************************
* NAME: fapp_fs_exit_cmd
*
* DESCRIPTION: Exit from the file explorer.
*************************************************************************/
static void fapp_fs_exit_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t **argv )
{
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    fnet_shell_switch(desc, FNET_NULL);
}
Beispiel #3
0
/************************************************************************
* NAME: fapp_fs_dir_cmd
*
* DESCRIPTION: Displays a list of files and subdirectories in a directory.
*************************************************************************/
static void fapp_fs_dir_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t **argv )
{
    struct fnet_fs_dirent ep;
    FNET_FS_DIR dir;
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    /* Open dir */
    dir = fnet_fs_opendir(fapp_fs_current_path);
 
    if (dir)
    {
        /* Print the dir content. */
        while ((fnet_fs_readdir (dir, &ep))==FNET_OK)
        {
            fnet_shell_println(desc, FAPP_FS_DIR_STR, (ep.d_type == DT_DIR)?"<DIR>":"<FILE>", ep.d_size, ep.d_name);
        }
            
        /* Close dir */
        fnet_fs_closedir(dir);    
    }
    else
    {
        fnet_shell_println(desc, FAPP_FS_DIR_ERR);
    }
}
Beispiel #4
0
void fapp_debug_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    FNET_COMP_UNUSED_ARG(desc);
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    /* Put here you debugging information.*/
#if 0
    fnet_fec_debug_mii_print_regs(fnet_netif_get_default());
#endif

#if 0
    {
        fnet_index_t    i = 0;
        fnet_ip6_addr_t addr_dns;
        fnet_uint8_t    ip_str[FNET_IP_ADDR_STR_SIZE]={0};
        
        while(fnet_netif_get_ip6_dns(fnet_netif_get_default(), i, &addr_dns ) == FNET_TRUE)
        {
            fnet_inet_ntop(AF_INET6, (fnet_uint8_t*)(&addr_dns), ip_str, sizeof(ip_str));
            fnet_shell_println(desc, "DNS[%d]=%s", i, ip_str);
            i++;
        }
    }
#endif

#if 0 /* Test ctacrypt library.*/
    extern void ctaocrypt_test(void);
    
    ctaocrypt_test();
#endif
}
Beispiel #5
0
static void fapp_info_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    fapp_info_print(desc);
}
Beispiel #6
0
static void fapp_reset_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    FNET_COMP_UNUSED_ARG(desc);
    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    fnet_release(); /* Release FNET stack (it's optional).*/
    
    fnet_cpu_reset();
}
void fnet_loop_output_ip6(struct fnet_netif *netif, fnet_ip6_addr_t *src_ip_addr,  fnet_ip6_addr_t *dest_ip_addr, fnet_netbuf_t* nb)
{
    FNET_COMP_UNUSED_ARG(dest_ip_addr);
    FNET_COMP_UNUSED_ARG(src_ip_addr);
 
    /* MTU check */
    if (nb->total_length <= netif->mtu)
        fnet_ip6_input(netif, nb);
    else
        fnet_netbuf_free_chain(nb);
}
Beispiel #8
0
static void fapp_stat_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    struct fnet_netif_statistics    statistics;
    fnet_netif_desc_t               netif = fnet_netif_get_default();  

    FNET_COMP_UNUSED_ARG(argc);
    FNET_COMP_UNUSED_ARG(argv);

    /* Print Packet statistics. */
    if(fnet_netif_get_statistics(netif, &statistics) == FNET_OK)
    {
        fnet_shell_println(desc, "\nPackets:");
        fnet_shell_println(desc, FAPP_SHELL_INFO_FORMAT_D, "TX Packets", statistics.tx_packet);
        fnet_shell_println(desc, FAPP_SHELL_INFO_FORMAT_D, "RX Packets", statistics.rx_packet);
    }

#if FNET_CFG_IP6
    {
        fnet_index_t                        i;
        fnet_netif_ip6_prefix_t             ip6_prefix;
        fnet_netif_ip6_neighbor_cache_t     ip6_neighbor_cache;
        fnet_char_t                                numaddr[FNET_IP6_ADDR_STR_SIZE];
        fnet_char_t                                mac_str[FNET_MAC_ADDR_STR_SIZE];

        /* Print content of IPv6 Prefix List. */
        fnet_shell_println(desc, "\nIPv6 Prefix List:");
        for(i=0U; fnet_netif_get_ip6_prefix(netif, i, &ip6_prefix) == FNET_TRUE; i++)
        {
            fnet_shell_println(desc,"   [%d] %s/%d\n", i, 
                                fnet_inet_ntop(AF_INET6, &ip6_prefix.prefix, numaddr, sizeof(numaddr)), ip6_prefix.prefix_length);
        }     

        /* Print content of IPv6 Neighbor Cache. */
        for(i=0U; fnet_netif_get_ip6_neighbor_cache(netif, i, &ip6_neighbor_cache) == FNET_TRUE; i++)
        {
            if(i == 0U)
            {
                fnet_shell_println(desc, "\nIPv6 Neighbor Cache:");
            }
            fnet_shell_println(desc,"   [%d] %s = %s (%s)\n", i, 
                                fnet_inet_ntop(AF_INET6, &ip6_neighbor_cache.ip_addr, numaddr, sizeof(numaddr)), 
                                fnet_mac_to_str(ip6_neighbor_cache.ll_addr, mac_str),
                                (ip6_neighbor_cache.is_router == FNET_TRUE) ? "router" : "host");
        }    
    }
#endif

}
Beispiel #9
0
/************************************************************************
* NAME: fapp_http_cgi_stdata_handle
*
* DESCRIPTION:
*************************************************************************/
static int fapp_http_cgi_stdata_handle(char * query, long *cookie)
{
    unsigned long time, t_hour, t_min, t_sec;
	struct fnet_netif_statistics statistics;

    FNET_COMP_UNUSED_ARG(query);
    
	/* Get Time. */    
	time = fnet_timer_ticks();
	t_hour = time/FNET_TIMER_TICK_IN_HOUR;
	t_min  = (time%FNET_TIMER_TICK_IN_HOUR)/FNET_TIMER_TICK_IN_MIN;
	t_sec  = (time%FNET_TIMER_TICK_IN_MIN)/FNET_TIMER_TICK_IN_SEC;
	
	/* Get statistics. */
    fnet_memset_zero( &statistics, sizeof(struct fnet_netif_statistics) );
    fnet_netif_get_statistics(fapp_default_netif, &statistics);

	/* Write to the temprorary buffer. */
    fnet_snprintf(fapp_http_cgi_buffer, sizeof(fapp_http_cgi_buffer), "({\"time\":\"%02d:%02d:%02d\",\"tx\":%d,\"rx\":%d})", 
                             t_hour, t_min, t_sec, statistics.tx_packet, statistics.rx_packet);

    *cookie = (long)fapp_http_cgi_buffer; /* Save fapp_http_cgi_buffer as cookie.*/
                                 
    return FNET_OK;
}
Beispiel #10
0
/************************************************************************
* NAME: fnet_eth_drain
*
* DESCRIPTION: This function tries to free not critical parts
*              of memory in the Ethernet driver.
*************************************************************************/
void fnet_eth_drain(fnet_netif_t *netif)
{
#if FNET_CFG_IP4
    fnet_arp_drain(netif);
#else
    FNET_COMP_UNUSED_ARG(netif);
#endif /* FNET_CFG_IP4 */
}
Beispiel #11
0
/************************************************************************
* NAME: fapp_http_cgi_post_handle
*
* DESCRIPTION:
*************************************************************************/
static int fapp_http_cgi_post_handle(char * query, long *cookie)
{
    FNET_COMP_UNUSED_ARG(query);

    *cookie = (long)fapp_http_post_buffer; /* Save fapp_http_post_buffer as cookie.*/                        
    
    return FNET_OK;
}
Beispiel #12
0
/************************************************************************
* NAME: fapp_dhcp_handler_discover
*
* DESCRIPTION: Event handler on new IP from DHCP client. 
************************************************************************/
static void fapp_dhcp_handler_discover(fnet_dhcp_desc_t dhcp_desc, fnet_netif_desc_t netif, void *shl_desc )
{
    fnet_shell_desc_t desc = (fnet_shell_desc_t) shl_desc;

    FNET_COMP_UNUSED_ARG(netif);
    FNET_COMP_UNUSED_ARG(dhcp_desc);
    
    if(fapp_dhcp_discover_counter == 0)
    {
        fnet_shell_unblock((fnet_shell_desc_t)shl_desc);
        fapp_dhcp_on_ctrlc((fnet_shell_desc_t)shl_desc); /* Cancel DHCP.*/
    }
    else
    {
        fapp_dhcp_discover_counter--;
        fnet_shell_println(desc, FAPP_DHCP_DISCOVER_STR);
    }
}
/************************************************************************
* NAME: fnet_eth_change_addr_notify
*
* DESCRIPTION:  This function is called on IP address change.
*               It issues a gratuitous ARP request.
*************************************************************************/
void fnet_eth_change_addr_notify(fnet_netif_t *netif)
{
#if FNET_CFG_IP4
fnet_printf("ETH - Change IP4 to: %x\n", netif->ip4_addr.address);

    if(netif->ip4_addr.address)
    	fnet_arp_request(netif, netif->ip4_addr.address); /* Gratuitous ARP request.*/
#else
    FNET_COMP_UNUSED_ARG(netif);
#endif /* FNET_CFG_IP4 */   
}
Beispiel #14
0
/************************************************************************
* NAME: fapp_boot
*
* DESCRIPTION: 
************************************************************************/
static void fapp_boot(fnet_shell_desc_t desc)
{
/* Bootloader. */
#if FAPP_CFG_BOOTLOADER  

    /* The bootloader wait some time for a key over a serial connection.*/
    /* The wait time is given by the boot_delay parameter.*/
    fnet_time_t delay;

    const struct boot_mode *mode;

    mode = fapp_boot_mode_by_index (fapp_params_boot_config.mode);    
        

    if(mode->handler)
    {
        delay = fapp_params_boot_config.delay;
        
        fnet_shell_printf(desc, FAPP_BOOT_STR, mode->name, delay);

        while(delay > 0u)
        {
            delay--;
            if( fnet_shell_getchar(desc) != FNET_ERR)
            {
                break;
            }
                
            fnet_timer_delay(FNET_TIMER_TICK_IN_SEC); /* 1 sec. delay. */
            fnet_shell_printf(desc, "\b\b\b\b %3d", delay);
        }
       
        fnet_shell_println(desc, "");
       
        if(delay == 0u)
        {
            /* Auto-start*/
            mode->handler(desc);
        }
    }
    else
#endif    
    {
        /* Default startup script. */
        #if FAPP_CFG_STARTUP_SCRIPT_ENABLED
            fnet_shell_println(desc, "Startup script: %s", FAPP_CFG_STARTUP_SCRIPT);
            fnet_shell_script(desc, FAPP_CFG_STARTUP_SCRIPT );
        #endif
    }
    
    FNET_COMP_UNUSED_ARG(desc);
}
Beispiel #15
0
/************************************************************************
* NAME: fnet_eth_change_addr_notify
*
* DESCRIPTION:  This function is called on IP address change.
*               It issues a gratuitous ARP request.
*************************************************************************/
void fnet_eth_change_addr_notify(fnet_netif_t *netif)
{
#if FNET_CFG_IP4
    if(netif->ip4_addr.address)
    {
        fnet_arp_send_request( (fnet_netif_desc_t) netif, netif->ip4_addr.address ); /* Gratuitous ARP request.*/
        /* When talking about gratuitous ARP, the packets are actually special ARP request packets,
           not ARP reply packets as one would perhaps expect. Some reasons for this are explained in RFC 5227.*/
    }
#else
    FNET_COMP_UNUSED_ARG(netif);
#endif /* FNET_CFG_IP4 */
}
Beispiel #16
0
/************************************************************************
* NAME: fapp_http_cmd
*
* DESCRIPTION: Run HTTP server.
*************************************************************************/
void fapp_http_cmd( fnet_shell_desc_t desc, int argc, char ** argv )
{
    struct fnet_http_params params;
    fnet_http_desc_t http_desc;

    FNET_COMP_UNUSED_ARG(desc);

    if(argc == 1) /* By default is "init".*/
    {
        fnet_memset_zero(&params, sizeof(struct fnet_http_params));
        
        params.root_path = FAPP_HTTP_MOUNT_NAME;    /* Root directory path */
        params.index_path = FAPP_HTTP_INDEX_FILE;   /* Index file path, relative to the root_path */
    #if FNET_CFG_HTTP_SSI
        params.ssi_table = fapp_ssi_table;
    #endif
    #if FNET_CFG_HTTP_CGI            
        params.cgi_table = fapp_cgi_table;
    #endif        
    #if FNET_CFG_HTTP_AUTHENTICATION_BASIC
        params.auth_table = fapp_auth_table;
    #endif  
    #if FNET_CFG_HTTP_POST
        params.post_table = fapp_post_table;
    #endif       

        /* Enable HTTP server */
        http_desc = fnet_http_init(&params);
        if(http_desc != FNET_ERR)
        {
            fnet_shell_println(desc, FAPP_DELIMITER_STR);
            fnet_shell_println(desc, " HTTP server started.");
            fapp_netif_addr_print(desc, AF_SUPPORTED, fapp_default_netif, FNET_FALSE);
            fnet_shell_println(desc, FAPP_DELIMITER_STR);
            
            fapp_http_desc = http_desc;
        }
        else
        {
            fnet_shell_println(desc, FAPP_INIT_ERR, "HTTP");
        }
    }
    else if(argc == 2 && fnet_strcasecmp(&FAPP_COMMAND_RELEASE[0], argv[1]) == 0) /* [release] */
    {
        fapp_http_release();
    }
    else
    {
        fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1]);
    }
}
Beispiel #17
0
void fnet_loop_output_ip4(fnet_netif_t *netif, fnet_ip4_addr_t dest_ip_addr, fnet_netbuf_t* nb)
{
    FNET_COMP_UNUSED_ARG(dest_ip_addr);
    
    fnet_isr_lock();
    
    /* MTU check */
    if (nb->total_length <= netif->mtu)
        fnet_ip_input(netif, nb);
    else
        fnet_netbuf_free_chain(nb);
        
    fnet_isr_unlock();
}
Beispiel #18
0
/************************************************************************
* NAME: fapp_dhcp_callback_discover
*
* DESCRIPTION: Event handler callback on new IP from DHCP client.
************************************************************************/
static void fapp_dhcp_callback_discover(fnet_dhcp_desc_t dhcp_desc, fnet_netif_desc_t netif, void *shl_desc )
{
    fnet_shell_desc_t desc = (fnet_shell_desc_t) shl_desc;

    FNET_COMP_UNUSED_ARG(netif);
    FNET_COMP_UNUSED_ARG(dhcp_desc);

    if(fapp_dhcp_discover_counter == 0)
    {
        fnet_shell_unblock((fnet_shell_desc_t)shl_desc);
        fapp_dhcp_on_ctrlc((fnet_shell_desc_t)shl_desc); /* Cancel DHCP.*/
        
        if(fapp_dhcp_autoip == FNET_TRUE)
        {
            fnet_shell_script(desc, "autoip");
        }
    }
    else
    {
        fapp_dhcp_discover_counter--;
        fnet_shell_println(desc, FAPP_DHCP_DISCOVER_STR);
    }
}
Beispiel #19
0
static void fapp_unbind_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    fnet_netif_desc_t   netif = fnet_netif_get_default();
    fnet_ip6_addr_t     addr;
    
    FNET_COMP_UNUSED_ARG(argc);
    
    if(fnet_inet_pton(AF_INET6, argv[1], &addr, sizeof(addr)) == FNET_OK)
    {
        fnet_netif_unbind_ip6_addr(netif, &addr);
    }
    else
    {
        fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1]);
    }
}
Beispiel #20
0
/************************************************************************
* NAME: fnet_mld_query_receive
*
* DESCRIPTION: Handles received Multicast Listener Query message.
*************************************************************************/
void fnet_mld_query_receive(fnet_netif_t *netif, fnet_ip6_addr_t *src_ip, fnet_ip6_addr_t *dest_ip, fnet_netbuf_t *nb, fnet_netbuf_t *ip6_nb)
{

    fnet_mld_header_t               *mld_packet = nb->data_ptr;
    fnet_size_t                     mld_packet_size = nb->total_length;
    fnet_ip6_header_t               *ip6_packet = (fnet_ip6_header_t *)ip6_nb->data_ptr;

    FNET_COMP_UNUSED_ARG(dest_ip);

    /************************************************************
    * Validation of MLD Query Message.
    *************************************************************/
    if(
        (mld_packet_size < sizeof(fnet_mld_header_t))
        /* Validation RFC2710.*/
        ||(ip6_packet->hop_limit != FNET_MLD_HOP_LIMIT)     /* The IP Hop Limit field has a value of 1.*/
        || !FNET_IP6_ADDR_IS_LINKLOCAL(src_ip)              /* MUST be the link-local address.*/
    )
    {
        goto DROP;
    }

    /* [RFC2710] The Multicast Address field in the MLD
     * message must contain either zero (a General Query) or a valid
     * multicast address (a Multicast- Address-Specific Query).*/
    if(FNET_IP6_ADDR_IS_MULTICAST(&mld_packet->multicast_addr))
    {
        /* [RFC2710] A Multicast-Address-Specific
         * Query applies to a single multicast address on the interface from
         * which the Query is received. */
        if(fnet_ip6_multicast_find_entry(netif, &mld_packet->multicast_addr))
            fnet_mld_join(netif, &mld_packet->multicast_addr);
    }
    else if(FNET_IP6_ADDR_EQUAL(&fnet_ip6_addr_any, &mld_packet->multicast_addr))
    {
        /* [RFC2710] General Query applies to all multicast addresses on the interface
         * from which the Query is received. */
        fnet_mld_report_all(netif);
    }
    else
    {}

DROP:
    fnet_netbuf_free_chain(ip6_nb);
    fnet_netbuf_free_chain(nb);
}
Beispiel #21
0
/************************************************************************
* NAME: fapp_mem_erase_cmd
*
* DESCRIPTION:  
************************************************************************/
void fapp_mem_erase_cmd ( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
	fnet_uint32_t   address;
	fnet_size_t     size;
	fnet_char_t     *p;
	fnet_return_t   result;

    FNET_COMP_UNUSED_ARG(desc);
	
	fnet_shell_println(desc, "Erasing...");
	
	if (argc == 3u)
	{
		address = fnet_strtoul(argv[1],&p,16u);
		if ((address == 0u) && (p == argv[1]))
        {
            fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1] );     
            return;
        }
        
        size = fnet_strtoul(argv[2],&p,10u);
		if ((size == 0u) && (p == argv[2]))
        {
            fnet_shell_println(desc, FAPP_PARAM_ERR, argv[2] );     
            return;
        }
        
        result = fapp_mem_erase( (void *)address, size);
        if( result == FNET_OK)
        {
            fnet_shell_println(desc, FAPP_MEM_ERASE_ERASED, address, address+size-1u );
        }
        else
        {
            fnet_shell_println(desc, FAPP_MEM_ERASE_FAILED, address, address+size-1u );
        }
    }
    else if ((argc == 2u) && (fnet_strcasecmp(FAPP_MEM_ERASE_ALL, argv[1]) == 0)) /* Erase all */
    {
        fapp_mem_erase_all(desc);
    }
    else
    {
        fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1]);
    }
}
/************************************************************************
* NAME: fnet_cpu_isr_install
*
* DESCRIPTION: 
*************************************************************************/
int fnet_cpu_isr_install(unsigned int vector_number, unsigned int priority)
{
    int result;
    unsigned long *irq_vec;


    irq_vec = (unsigned long *)(FNET_CFG_CPU_VECTOR_TABLE)+vector_number;
    	
    if(*irq_vec != (unsigned long)FNET_ISR_HANDLER)
    { /* It's not installed yet.*/
        *irq_vec = (unsigned long) FNET_ISR_HANDLER;
    }

    if(*irq_vec == (unsigned long) FNET_ISR_HANDLER)
    {
#if !FNET_CFG_MCF_V1 /* No for MCF Ver.1 */
        /* Set priority. */
        {
            /* Enable interrupt at ColdFire SIM */
            int irq_number; /* The irq number NOT the vector number.*/
            int div;
            
            irq_number = (int) (vector_number - 0x40); 
            div = irq_number/32;
            if((div >= 0) && (div < 2)) /* So far only upto 64 irq_number (INTC0). TBD*/
            {
                /* Set interrupt level.*/
                FNET_MCF_INTC0_ICR(irq_number) = (fnet_uint8)FNET_MCF_INTC0_ICRn_IL(priority) | FNET_MCF_INTC0_ICRn_IP(7);
                /* Clear mask all interrupts.*/
                FNET_MCF_INTC0_IMRL &= ~FNET_MCF_INTC0_IMRL_MASKALL;
                /* Unmask proper interrupt.*/
                FNET_MCF_INTC0_IMR(div) &= (~FNET_MCF_INTC0_IMR_INT_MASK(irq_number));
            }
        }
#else
    FNET_COMP_UNUSED_ARG(priority);        
#endif /* !FNET_CFG_MCF_V1 */
        result = FNET_OK;
    }
    else
        result = FNET_ERR;
   
   return result;     
}
Beispiel #23
0
/************************************************************************
* NAME: fnet_timer_handler_bottom
*
* DESCRIPTION: Handles timer interrupts 
*              
*************************************************************************/
void fnet_timer_handler_bottom(void *cookie)
{
    struct fnet_net_timer *timer = fnet_tl_head;
    
    FNET_COMP_UNUSED_ARG(cookie);
    
    while(timer)
    {
        if(fnet_timer_get_interval(timer->timer_cnt, fnet_current_time) >= timer->timer_rv)
        {
            timer->timer_cnt = fnet_current_time;

            if(timer->handler)
                timer->handler(timer->cookie);
        }

        timer = timer->next;
    }
}
Beispiel #24
0
/************************************************************************
* NAME: fapp_mem_erase_cmd
*
* DESCRIPTION:  
************************************************************************/
void fapp_mem_erase_cmd ( fnet_shell_desc_t desc, int argc, char ** argv )
{
	unsigned long address;
	unsigned long size;
	char *p;
	int result;

    FNET_COMP_UNUSED_ARG(desc);
	
	fnet_shell_println(desc, "Erasing...");
	
	if (argc == 3)
	{
		address = fnet_strtoul(argv[1],&p,16);
		if ((address == 0) && (p == argv[1]))
        {
            fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1] );     
            return;
        }
        
        size = fnet_strtoul(argv[2],&p,10);
		if ((size == 0) && (p == argv[2]))
        {
            fnet_shell_println(desc, FAPP_PARAM_ERR, argv[2] );     
            return;
        }
        
        result = fapp_mem_erase( (void *)address, size);
        if( result == FNET_OK)
            fnet_shell_println(desc, FAPP_MEM_ERASE_ERASED, address, address+size-1 );
        else
            fnet_shell_println(desc, FAPP_MEM_ERASE_FAILED, address, address+size-1 );
        
    }
    else if ((argc == 2) && fnet_strcasecmp(FAPP_MEM_ERASE_ALL, argv[1]) == 0) /* Erase all */
    {
        fapp_mem_erase_all(desc);
    }
    else
    {
        fnet_shell_println(desc, FAPP_PARAM_ERR, argv[1]);
    }
}
Beispiel #25
0
/************************************************************************
* NAME: fapp_http_cgi_graph_handle
*
* DESCRIPTION:
*************************************************************************/
static int fapp_http_cgi_graph_handle(char * query, long *cookie)
{
    int q1= (int)fapp_http_cgi_rand();
    int q2= (int)fapp_http_cgi_rand();
    int q3= (int)fapp_http_cgi_rand();
    int q4= (int)fapp_http_cgi_rand();
    int q5= (int)fapp_http_cgi_rand();

    FNET_COMP_UNUSED_ARG(query);

	/* Wrie to the temprorary buffer. */
    fnet_snprintf(fapp_http_cgi_buffer, sizeof(fapp_http_cgi_buffer), 
                        "({\"q1\":%d,\"q2\":%d,\"q3\":%d,\"q4\":%d,\"q5\":%d})", 
                        q1, q2, q3, q4, q5);

    *cookie = (long)fapp_http_cgi_buffer; /* Save fapp_http_cgi_buffer as cookie.*/                        
    
    return FNET_OK;
}
/************************************************************************
* NAME: fnet_netif_get_by_ip4_addr
*
* DESCRIPTION: Returns a network interface given its IPv4 address.
*************************************************************************/
fnet_netif_desc_t fnet_netif_get_by_ip4_addr( fnet_ip4_addr_t addr )
{
    fnet_netif_desc_t result = (fnet_netif_desc_t)FNET_NULL;

#if FNET_CFG_IP4
    fnet_netif_t *netif;
    
    fnet_os_mutex_lock();
    for (netif = fnet_netif_list; netif != 0; netif = netif->next)
    {
        if(addr == netif->ip4_addr.address)
        {
            result = (fnet_netif_desc_t)netif;
            break;
        }
    }
    fnet_os_mutex_unlock();
#else
    FNET_COMP_UNUSED_ARG(addr);
#endif /* FNET_CFG_IP4 */

    return result;
}
Beispiel #27
0
/************************************************************************
* NAME: fapp_fs_view_cmd
*
* DESCRIPTION: 
*************************************************************************/
static void fapp_fs_view_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    FNET_FS_FILE    file;
    fnet_char_t    *path = argv[1];
    fnet_char_t    *path_end;
    fnet_size_t     size_cd = fnet_strlen (fapp_fs_current_path);
    fnet_size_t     size_path;
    fnet_char_t    splitter[] = {FNET_FS_SPLITTER,'\0'};
    fnet_uint8_t    data;
    struct          fnet_fs_dirent dirent;    

    FNET_COMP_UNUSED_ARG(desc);
    FNET_COMP_UNUSED_ARG(argc);
        
	if (*path != FNET_FS_SPLITTER) /* Realative path.*/
	{
	    /* Add splitter if not yet.*/
	    if(fapp_fs_current_path[size_cd-1U] != FNET_FS_SPLITTER) 
        {
	        fnet_strncat( &fapp_fs_current_path[0], splitter, FAPP_FS_DIR_PATH_MAX);
        }
	        
	    fnet_strncat( &fapp_fs_current_path[0], path, FAPP_FS_DIR_PATH_MAX);
	    path = fapp_fs_current_path; 
	}    
    else /* Full path. */
    {
        /* Strip possible repetitive leading slashes. */
        while ((path[0] == FNET_FS_SPLITTER) && (path[1] == FNET_FS_SPLITTER)) 
        {
            path++;	        
        }
    }
    
    /* Strip possible ending slashes. */
    if((size_path = fnet_strlen(path)) > 0U)
    {
        path_end = &path[size_path-1U]; 
        while(*path_end == FNET_FS_SPLITTER)
        {
            *path_end = '\0';
            path_end--;	        
        }
    }
    
    /* Open file. */
    file = fnet_fs_fopen(path,"r");
    
    if (file)
    {
        /* Print file info.*/
        fnet_fs_finfo (file, &dirent);
        
        fnet_shell_println(desc, FAPP_FS_DIR_STR, "Content of:", dirent.d_size, dirent.d_name);
        
        while(fnet_fs_fread(&data, sizeof(data), file))
        {
            fnet_shell_putchar(desc, data);
        }
                  
        /* Close file. */    
        fnet_fs_fclose(file);                  
    }
    else
    {
        fnet_shell_println(desc, FAPP_FS_VIEW_ERR, argv[1]);
    }
    
    /* Restore cur path. */
    fapp_fs_current_path[size_cd] = '\0'; 
                 
}
Beispiel #28
0
/************************************************************************
* NAME: fapp_fs_cd_cmd
*
* DESCRIPTION: Change the current directory.
*************************************************************************/
static void fapp_fs_cd_cmd( fnet_shell_desc_t desc, fnet_index_t argc, fnet_char_t ** argv )
{
    FNET_FS_DIR     dir;
    fnet_char_t    *path = argv[1];
    fnet_char_t    *path_end;
    fnet_size_t     size_cd = fnet_strlen (fapp_fs_current_path);
    fnet_size_t     size_path;
    fnet_char_t    splitter[] = {FNET_FS_SPLITTER,'\0'};    

    FNET_COMP_UNUSED_ARG(argc);
        
	if (*path != FNET_FS_SPLITTER) /* Realative path.*/
	{
	    /* Add splitter if not yet.*/
	    if(fapp_fs_current_path[size_cd-1U] != FNET_FS_SPLITTER) 
        {
	        fnet_strncat( &fapp_fs_current_path[0], splitter, FAPP_FS_DIR_PATH_MAX);
        }
	        
	    fnet_strncat( &fapp_fs_current_path[0], path, FAPP_FS_DIR_PATH_MAX);
	    path = fapp_fs_current_path; 
	}    
    else /* Full path. */
    {
        /* Strip possible repetitive leading slashes. */
        while ((path[0] == FNET_FS_SPLITTER) && (path[1] == FNET_FS_SPLITTER))
        {
            path++;	        
        }
    }
    
    /* Strip possible ending slashes. */
    if((size_path = fnet_strlen(path)) > 0U)
    {
        path_end = &path[size_path - 1U]; 
        while(*path_end == FNET_FS_SPLITTER)
        {
            *path_end = '\0';
            path_end--;	        
        }
    }
    
    /* Open dir. */
    dir = fnet_fs_opendir(path);
    
    if (dir)
    {
        /* Update cur path. */
        fnet_strncpy( &fapp_fs_current_path[0], path, FAPP_FS_DIR_PATH_MAX);
        if(fapp_fs_current_path[0] == '\0') /* root dir */
        {
            fnet_strncat( &fapp_fs_current_path[0], splitter, FAPP_FS_DIR_PATH_MAX);
        }
    
        /* Change shell prompt. */
        fnet_sprintf( FAPP_FS_PROMPT_STR, "%s%s%s", 
                  &FAPP_FS_PROMPT_STR_HEADER[0],
                  &fapp_fs_current_path[0],
                  &FAPP_FS_PROMPT_STR_TRAILER[0]);
                  
        /* Close dir. */    
        fnet_fs_closedir(dir);                  
    }
    else
    {
        /* Restore cur path. */
        fapp_fs_current_path[size_cd] = '\0'; 
        fnet_shell_println(desc, FAPP_FS_CD_ERR, argv[1]);
    }
                 
}
/************************************************************************
* NAME: fnet_igmp_input
*
* DESCRIPTION: IGMP input function.
*************************************************************************/
static void fnet_igmp_input( fnet_netif_t *netif, fnet_ip4_addr_t src_ip, fnet_ip4_addr_t dest_ip, fnet_netbuf_t *nb, fnet_netbuf_t *ip4_nb)
{
    fnet_igmp_header_t *hdr;
    fnet_netbuf_t *tmp_nb;
    int i;
    
    FNET_COMP_UNUSED_ARG(dest_ip);
    FNET_COMP_UNUSED_ARG(src_ip);
    
    fnet_netbuf_free_chain(ip4_nb);

    if((netif != 0) && (nb != 0) )
    {
        /* The header must reside in contiguous area of memory. */
        if((tmp_nb = fnet_netbuf_pullup(nb, sizeof(fnet_igmp_header_t))) == 0) 
        {
            goto DISCARD;
        }

        nb = tmp_nb;

        hdr = nb->data_ptr;
        
        /* RFC2236 To be valid, the Query message
         * must be at least 8 octets long, have a correct IGMP
         * checksum.
         */
        if(fnet_checksum(nb, (int)nb->total_length)  )
        {
            goto DISCARD;
        }
        
        fnet_igmp_trace("RX", hdr); 

        /**************************
        * IGMP QUERY Processing
        **************************/     
        if(hdr->type == IGMP_HEADER_TYPE_QUERY)
        {
            /* RFC2236: The group address in the IGMP header must either be zero (a General
             * Query) or a valid multicast group address (a Group-Specific Query).
             * A General Query applies to all memberships on the interface from
             * which the Query is received. A Group-Specific Query applies to
             * membership in a single group on the interface from which the Query
             * is received. Queries are ignored for memberships in the Non-Member
             * state.
             */
            if(hdr->group_addr == 0)
            /* General Query */
            {
                 /* Find all joined-groups for this interface.*/
                for(i=0; i < FNET_CFG_MULTICAST_MAX; i++)
                {
                    if((fnet_ip_multicast_list[i].user_counter > 0) && (fnet_ip_multicast_list[i].netif == netif))
                    {
                        /* Send report.*/
                        fnet_igmp_join(netif, fnet_ip_multicast_list[i].group_addr );
                    }
                }
            }
        #if FNET_CFG_IGMP_VERSION == 2                    
            else if(FNET_IP4_ADDR_IS_MULTICAST(hdr->group_addr))
            /* A Group-Specific Query.*/ 
            {
                /* Find specific group.*/
                for(i=0; i < FNET_CFG_MULTICAST_MAX; i++)
                {
                    if((fnet_ip_multicast_list[i].user_counter > 0) && (fnet_ip_multicast_list[i].netif == netif) && (fnet_ip_multicast_list[i].group_addr == hdr->group_addr))
                    {
                        /* Send report.*/
                        fnet_igmp_join(netif, fnet_ip_multicast_list[i].group_addr );
                        break;
                    }
                }
            }
        #endif /* FNET_CFG_IGMP_VERSION */                
            /* esle wrong */
        }
        /************************
         * Ignore others
         ************************/
    }

DISCARD:
    fnet_netbuf_free_chain(nb);
}
Beispiel #30
0
/************************************************************************
* NAME: fnet_eth_phy_init
*
* DESCRIPTION: Ethernet Physical Transceiver initialization and/or reset.
*************************************************************************/
void fnet_eth_phy_init(fnet_fec_if_t *ethif)
{
    FNET_COMP_UNUSED_ARG(ethif);
}