Пример #1
0
/**
 * Initialize all modules.
 */
void
lwip_init(void)
{
  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_IPV4
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
#if PPP_SUPPORT
  ppp_init();
#endif
 
#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
Пример #2
0
Файл: init.c Проект: ORCOS/ORCOS
 */
void lwip_init(void) {
    /* Sanity check user-configurable values */
    lwip_sanity_check();

    /* Modules initialization */
    stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
    mem_init();
    memp_init();
    pbuf_init(); netif_init();
#if LWIP_SOCKET
    lwip_socket_init();
#endif /* LWIP_SOCKET */
    ip4_init();
    ip6_init();
#if LWIP_ARP
    ethar_init();
#endif /* LWIP_ARP */
#if LWIP_RAW
    raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
    udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
    tcp_init();
#endif /* LWIP_TCP */
#if LWIP_SNMP
    snmp_init();
#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
    autoip_init();
#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
    igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
    dns_init();
#endif /* LWIP_DNS */
int main(void)
{
	SysInit();
	sys_init();
	mem_init();
	memp_init();
	pbuf_init();
	tcpip_init( NULL, NULL );
/* Start the tasks defined within this file/specific to this demo. */
	xTaskCreate( vGSM_GPRS_Task, "GSM_GPRS_TASK", 256 , NULL,tskIDLE_PRIORITY + 1 , NULL );
  xTaskCreate( vAmpmNetTestTask, "ampm net test", 128 , "\r\nThienhaiblue->",tskIDLE_PRIORITY + 1 , NULL );
	xTaskCreate( vAmpmNetTestTask1, "ampm net test1", 128 , "\r\nTony->",tskIDLE_PRIORITY + 1 , NULL );
	/* Start the scheduler. */
	vTaskStartScheduler();
	while(1)
	{
		
		
	}
	return 0;
}
Пример #4
0
int
_start(int argc,char** argv)
{
	sys_sem_t	Sema;
	int			iRet;

	dbgprintf("PS2IP: Module Loaded.\n");

	if ((iRet=RegisterLibraryEntries(&_exp_ps2ip))!=0)
	{
		printf("PS2IP: RegisterLibraryEntries returned: %d\n",iRet);
	}

	sys_init();
	mem_init();
	memp_init();
	pbuf_init();

	dbgprintf("PS2IP: sys_init, mem_init, memp_init, pbuf_init called\n");

	netif_init();

	dbgprintf("PS2IP: netif_init called\n");

	Sema=sys_sem_new(0);
	dbgprintf("PS2IP: Calling tcpip_init\n");
	tcpip_init(InitDone,&Sema);

	sys_arch_sem_wait(Sema,0);
	sys_sem_free(Sema);

	dbgprintf("PS2IP: tcpip_init called\n");

	AddLoopIF();
	InitTimer();

	dbgprintf("PS2IP: System Initialised\n");

	return	iRet; 
}
Пример #5
0
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
#ifdef PERF
  perf_init("/tmp/simhost.perf");
#endif /* PERF */
#if LWIP_STATS
  stats_init();
#endif /* STATS */
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();
#ifdef LWIP_TCPDUMP
  tcpdump_init();
#endif
  
  printf("System initialized.\n");
    
  sys_thread_new(main_thread, NULL, DEFAULT_THREAD_PRIO);
  pause();
  return 0;
}
Пример #6
0
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
#ifdef PERF
  perf_init("/tmp/simhost.perf");
#endif /* PERF */
#ifdef STATS
  stats_init();
#endif /* STATS */
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();

  tcpdump_init();

  
  printf("System initialized.\n");
    
  sys_thread_new((void *)(main_thread), NULL);
  pause();
  return 0;
}
Пример #7
0
int main()
{
	MP *mp=memp_init(1020);
	char *p[1000];
	for(int i=0;i<1000;i++)
	{
		for(int j=0;j<1000;j++)
			p[j]=(char *)memp_getblock(mp,j);
	
		for(int j=0;j<1000;j++)
		{
			if(p[j]!=NULL)
				memp_retblock(mp,p[j]);
		}
		
		printf("ok...\n");
		//system("pause");
	}
	system("pause");
	//memp_statistic(mp);
	memp_destory(mp);
	return 0;
}
void zot_network_task(cyg_addrword_t arg)
{
	sys_sem_t sem;

	sys_init();
	mem_init();
	memp_init();
	pbuf_init();
	
	sem = sys_sem_new(0);
	tcpip_init(tcpip_init_done, &sem);

#ifdef PRINT_DIAGNOSTIC
//	if( !diag_flag )
	if( 1 )
#endif
	{
		if(EEPROM_Data.PrintServerMode & PS_DHCP_ON)
		{

#ifdef LINKLOCAL_IP	
            #if defined(N716U2W) || defined(N716U2)
			if(EEPROM_Data.RENVEnable == 1)
            #endif
				Link_local_ip_init();	
#endif
			
			mib_DHCP_p->IPAddr = 0;
			mib_DHCP_p->SubnetMask = 0;
			mib_DHCP_p->GwyAddr = 0;
/*				
			memset( EEPROM_Data.BoxIPAddress, 0, 4);
			memset( EEPROM_Data.SubNetMask, 0, 4);
			memset( EEPROM_Data.GetwayAddress, 0, 4);
*/			
			//Create DHCP Thread
		    cyg_thread_create(DHCP_TASK_PRI,
		                  dhcp_init,
		                  0,
		                  "dhcp_init",
		                  (void *) (DHCP_Stack),
		                  DHCP_TASK_STACK_SIZE,
		                  &DHCP_TaskHdl,
		                  &DHCP_Task);
			
			//Start DHCP Thread
			cyg_thread_resume(DHCP_TaskHdl);

		}
#ifdef RENDEZVOUS
		else
		{
			ppause(3000);
			cyg_semaphore_post( &rendezvous_sem);
		}
#endif		
		
		
	}
	
	sys_sem_wait(sem);
	sys_sem_free(sem);
}
Пример #9
0
static void remaining_lwip_initialization(char *card_name, uint64_t queueid)
{
    nb = netbench_alloc("app", RECORDED_EVENTS_COUNT);
    //asq: connect to the NIC driver, before doing anything else
    idc_connect_to_driver(card_name, queueid);
    DEBUGPRINTPS("Connected to driver [%s]\n", card_name);
    stats_init();
    sys_init();
    DEBUGPRINTPS("remaining_lwip_init: allocating pbuf memory\n");
#ifdef CONFIG_QEMU_NETWORK
    printf("#### Networking with small amount of memory #####\n");
#endif // CONFIG_QEMU_NETWORK
    printf("#### [%u:%"PRIuDOMAINID":%s] [%s] [%d] MEM_SIZE[%d], "
            "PBUF_POOL_SIZE[%d], MEMP_MAX[%d],  RECEIVE_BUFFERS[%d] qid[%"PRIu64"]####\n",
       disp_get_core_id(), disp_get_domain_id(), disp_name(),
       MEM_CONF_LOC, is_ctl, MEM_SIZE, PBUF_POOL_SIZE, MEMP_MAX,
       RECEIVE_BUFFERS, queueid);

    memp_init();                // 0'st buffer

    DEBUGPRINTPS("remaining_lwip_init: allocating memory for sending\n");
    mem_init();                 // 1'th buffer
    DEBUGPRINTPS("remaining_lwip_init: done with memroy allocation\n");

    DEBUGPRINTPS("LWIP: lwip_starting\n");
    netif_init();
#if LWIP_SOCKET
    lwip_socket_init();
#endif                          /* LWIP_SOCKET */
    ip_init();
    DEBUGPRINTPS("r_lwip_init: done ip_init\n");
#if LWIP_ARP
    etharp_init();
#endif                          /* LWIP_ARP */
#if LWIP_RAW
    raw_init();
#endif                          /* LWIP_RAW */
#if LWIP_UDP
    udp_init();
    DEBUGPRINTPS("r_lwip_init: done udp_init\n");
#endif                          /* LWIP_UDP */
#if LWIP_TCP
    tcp_init();
    DEBUGPRINTPS("r_lwip_init: done tcp_init\n");
#endif                          /* LWIP_TCP */
#if LWIP_SNMP
    snmp_init();
    DEBUGPRINTPS("r_lwip_init: done snmp_init\n");
#endif                          /* LWIP_SNMP */
#if LWIP_AUTOIP
    autoip_init();
    DEBUGPRINTPS("r_lwip_init: done autoip_init\n");
#endif                          /* LWIP_AUTOIP */
#if LWIP_IGMP
    igmp_init();
    DEBUGPRINTPS("r_lwip_init: done igmp_init\n");
#endif                          /* LWIP_IGMP */
    DEBUGPRINTPS("r_lwip_init: done2 igmp_init\n");
#if LWIP_DNS
    DEBUGPRINTPS("r_lwip_init: starting DNS_init\n");
    dns_init();
    DEBUGPRINTPS("r_lwip_init: done DNS_init\n");
#endif                          /* LWIP_DNS */
    DEBUGPRINTPS("LWIP: lwip_started\n");
}
Пример #10
0
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void LwIP_Init(void)
{
  struct ip_addr ipaddr;
  //struct ip_addr netmask;
  //struct ip_addr gw;
  uint8_t macaddress[6]={0,0,0,0,0,1};

  /* Initializes the dynamic memory heap defined by MEM_SIZE.*/
  mem_init();

  /* Initializes the memory pools defined by MEMP_NUM_x.*/
  memp_init();


#if LWIP_DHCP
  ip_ipaddr.addr = 0;
  ip_netmask.addr = 0;
  ip_gw.addr = 0;

  /* Configure the board opeartin mode: Client/Server */  




#else
  //IP4_ADDR(&ipaddr, 200,200,2,95); // 10.1.1.8 //  200,200,2, 95 //
  //IP4_ADDR(&netmask, 255, 255, 255, 0);
  //IP4_ADDR(&gw, 10, 1, 1, 1); //10, 1,1, 1
#endif

  Set_MAC_Address(macaddress);

  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
            struct ip_addr *netmask, struct ip_addr *gw,
            void *state, err_t (* init)(struct netif *netif),
            err_t (* input)(struct pbuf *p, struct netif *netif))
    
   Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.

  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/
  netif_add(&netif, &ip_ipaddr, &ip_netmask, &ip_gw, NULL, &ethernetif_init, &ethernet_input);

  /*  Registers the default network interface.*/
  netif_set_default(&netif);


#if LWIP_DHCP
  /*  Creates a new DHCP client for this interface on the first call.
  Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
  the predefined regular intervals after starting the client.
  You can peek in the netif->dhcp struct for the actual DHCP status.*/
  dhcp_start(&netif);
#endif

  /*  When the netif is fully configured this function must be called.*/
  netif_set_up(&netif);

}
Пример #11
0
PACK_STRUCT_END
#ifdef PACK_STRUCT_USE_INCLUDES
#  include "arch/epstruct.h"
#endif
#define PACKED_STRUCT_TEST_EXPECTED_SIZE 5

#endif

/* Compile-time sanity checks for configuration errors.
 * These can be done independently of LWIP_DEBUG, without penalty.
 */
#ifndef BYTE_ORDER
  #error "BYTE_ORDER is not defined, you have to define it in your cc.h"
#endif
#if (!IP_SOF_BROADCAST && IP_SOF_BROADCAST_RECV)
  #error "If you want to use broadcast filter per pcb on recv operations, you have to define IP_SOF_BROADCAST=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_UDPLITE)
  #error "If you want to use UDP Lite, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_DHCP)
  #error "If you want to use DHCP, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_MULTICAST_TX_OPTIONS)
  #error "If you want to use IGMP/LWIP_MULTICAST_TX_OPTIONS, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if (!LWIP_UDP && LWIP_DNS)
  #error "If you want to use DNS, you have to define LWIP_UDP=1 in your lwipopts.h"
#endif
#if !MEMP_MEM_MALLOC /* MEMP_NUM_* checks are disabled when not using the pool allocator */
#if (LWIP_ARP && ARP_QUEUEING && (MEMP_NUM_ARP_QUEUE<=0))
  #error "If you want to use ARP Queueing, you have to define MEMP_NUM_ARP_QUEUE>=1 in your lwipopts.h"
#endif
#if (LWIP_RAW && (MEMP_NUM_RAW_PCB<=0))
  #error "If you want to use RAW, you have to define MEMP_NUM_RAW_PCB>=1 in your lwipopts.h"
#endif
#if (LWIP_UDP && (MEMP_NUM_UDP_PCB<=0))
  #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
#endif
#if (LWIP_TCP && (MEMP_NUM_TCP_PCB<=0))
  #error "If you want to use TCP, you have to define MEMP_NUM_TCP_PCB>=1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && (MEMP_NUM_IGMP_GROUP<=1))
  #error "If you want to use IGMP, you have to define MEMP_NUM_IGMP_GROUP>1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && !LWIP_MULTICAST_TX_OPTIONS)
  #error "If you want to use IGMP, you have to define LWIP_MULTICAST_TX_OPTIONS==1 in your lwipopts.h"
#endif
#if (LWIP_IGMP && !LWIP_IPV4)
  #error "IGMP needs LWIP_IPV4 enabled in your lwipopts.h"
#endif
#if (LWIP_MULTICAST_TX_OPTIONS && !LWIP_IPV4)
  #error "LWIP_MULTICAST_TX_OPTIONS needs LWIP_IPV4 enabled in your lwipopts.h"
#endif
#if ((LWIP_NETCONN || LWIP_SOCKET) && (MEMP_NUM_TCPIP_MSG_API<=0))
  #error "If you want to use Sequential API, you have to define MEMP_NUM_TCPIP_MSG_API>=1 in your lwipopts.h"
#endif
/* There must be sufficient timeouts, taking into account requirements of the subsystems. */
#if LWIP_TIMERS && (MEMP_NUM_SYS_TIMEOUT < (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)))
  #error "MEMP_NUM_SYS_TIMEOUT is too low to accomodate all required timeouts"
#endif
#if (IP_REASSEMBLY && (MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS))
  #error "MEMP_NUM_REASSDATA > IP_REASS_MAX_PBUFS doesn't make sense since each struct ip_reassdata must hold 2 pbufs at least!"
#endif
#endif /* !MEMP_MEM_MALLOC */
#if LWIP_WND_SCALE
#if (LWIP_TCP && (TCP_WND > 0xffffffff))
  #error "If you want to use TCP, TCP_WND must fit in an u32_t, so, you have to reduce it in your lwipopts.h"
#endif
#if (LWIP_TCP && LWIP_WND_SCALE && (TCP_RCV_SCALE > 14))
  #error "The maximum valid window scale value is 14!"
#endif
#if (LWIP_TCP && (TCP_WND > (0xFFFFU << TCP_RCV_SCALE)))
  #error "TCP_WND is bigger than the configured LWIP_WND_SCALE allows!"
#endif
#if (LWIP_TCP && ((TCP_WND >> TCP_RCV_SCALE) == 0))
  #error "TCP_WND is too small for the configured LWIP_WND_SCALE (results in zero window)!"
#endif
#else /* LWIP_WND_SCALE */
#if (LWIP_TCP && (TCP_WND > 0xffff))
  #error "If you want to use TCP, TCP_WND must fit in an u16_t, so, you have to reduce it in your lwipopts.h (or enable window scaling)"
#endif
#endif /* LWIP_WND_SCALE */
#if (LWIP_TCP && (TCP_SND_QUEUELEN > 0xffff))
  #error "If you want to use TCP, TCP_SND_QUEUELEN must fit in an u16_t, so, you have to reduce it in your lwipopts.h"
#endif
#if (LWIP_TCP && (TCP_SND_QUEUELEN < 2))
  #error "TCP_SND_QUEUELEN must be at least 2 for no-copy TCP writes to work"
#endif
#if (LWIP_TCP && ((TCP_MAXRTX > 12) || (TCP_SYNMAXRTX > 12)))
  #error "If you want to use TCP, TCP_MAXRTX and TCP_SYNMAXRTX must less or equal to 12 (due to tcp_backoff table), so, you have to reduce them in your lwipopts.h"
#endif
#if (LWIP_TCP && TCP_LISTEN_BACKLOG && ((TCP_DEFAULT_LISTEN_BACKLOG < 0) || (TCP_DEFAULT_LISTEN_BACKLOG > 0xff)))
  #error "If you want to use TCP backlog, TCP_DEFAULT_LISTEN_BACKLOG must fit into an u8_t"
#endif
#if (LWIP_NETIF_API && (NO_SYS==1))
  #error "If you want to use NETIF API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
#if ((LWIP_SOCKET || LWIP_NETCONN) && (NO_SYS==1))
  #error "If you want to use Sequential API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
#if (LWIP_PPP_API && (NO_SYS==1))
  #error "If you want to use PPP API, you have to define NO_SYS=0 in your lwipopts.h"
#endif
#if (LWIP_PPP_API && (PPP_SUPPORT==0))
  #error "If you want to use PPP API, you have to enable PPP_SUPPORT in your lwipopts.h"
#endif
#if (((!LWIP_DHCP) || (!LWIP_AUTOIP)) && LWIP_DHCP_AUTOIP_COOP)
  #error "If you want to use DHCP/AUTOIP cooperation mode, you have to define LWIP_DHCP=1 and LWIP_AUTOIP=1 in your lwipopts.h"
#endif
#if (((!LWIP_DHCP) || (!LWIP_ARP)) && DHCP_DOES_ARP_CHECK)
  #error "If you want to use DHCP ARP checking, you have to define LWIP_DHCP=1 and LWIP_ARP=1 in your lwipopts.h"
#endif
#if (!LWIP_ARP && LWIP_AUTOIP)
  #error "If you want to use AUTOIP, you have to define LWIP_ARP=1 in your lwipopts.h"
#endif
#if (LWIP_TCP && ((LWIP_EVENT_API && LWIP_CALLBACK_API) || (!LWIP_EVENT_API && !LWIP_CALLBACK_API)))
  #error "One and exactly one of LWIP_EVENT_API and LWIP_CALLBACK_API has to be enabled in your lwipopts.h"
#endif
#if (MEM_LIBC_MALLOC && MEM_USE_POOLS)
  #error "MEM_LIBC_MALLOC and MEM_USE_POOLS may not both be simultaneously enabled in your lwipopts.h"
#endif
#if (MEM_USE_POOLS && !MEMP_USE_CUSTOM_POOLS)
  #error "MEM_USE_POOLS requires custom pools (MEMP_USE_CUSTOM_POOLS) to be enabled in your lwipopts.h"
#endif
#if (PBUF_POOL_BUFSIZE <= MEM_ALIGNMENT)
  #error "PBUF_POOL_BUFSIZE must be greater than MEM_ALIGNMENT or the offset may take the full first pbuf"
#endif
#if (DNS_LOCAL_HOSTLIST && !DNS_LOCAL_HOSTLIST_IS_DYNAMIC && !(defined(DNS_LOCAL_HOSTLIST_INIT)))
  #error "you have to define define DNS_LOCAL_HOSTLIST_INIT {{'host1', 0x123}, {'host2', 0x234}} to initialize DNS_LOCAL_HOSTLIST"
#endif
#if PPP_SUPPORT && !PPPOS_SUPPORT && !PPPOE_SUPPORT && !PPPOL2TP_SUPPORT
  #error "PPP_SUPPORT needs at least one of PPPOS_SUPPORT, PPPOE_SUPPORT or PPPOL2TP_SUPPORT turned on"
#endif
#if PPP_SUPPORT && !PPP_IPV4_SUPPORT && !PPP_IPV6_SUPPORT
  #error "PPP_SUPPORT needs PPP_IPV4_SUPPORT and/or PPP_IPV6_SUPPORT turned on"
#endif
#if PPP_SUPPORT && PPP_IPV4_SUPPORT && !LWIP_IPV4
  #error "PPP_IPV4_SUPPORT needs LWIP_IPV4 turned on"
#endif
#if PPP_SUPPORT && PPP_IPV6_SUPPORT && !LWIP_IPV6
  #error "PPP_IPV6_SUPPORT needs LWIP_IPV6 turned on"
#endif
#if !LWIP_ETHERNET && (LWIP_ARP || PPPOE_SUPPORT)
  #error "LWIP_ETHERNET needs to be turned on for LWIP_ARP or PPPOE_SUPPORT"
#endif
#if (LWIP_IGMP || LWIP_IPV6) && !defined(LWIP_RAND)
  #error "When using IGMP or IPv6, LWIP_RAND() needs to be defined to a random-function returning an u32_t random value (in arch/cc.h)"
#endif
#if LWIP_TCPIP_CORE_LOCKING_INPUT && !LWIP_TCPIP_CORE_LOCKING
  #error "When using LWIP_TCPIP_CORE_LOCKING_INPUT, LWIP_TCPIP_CORE_LOCKING must be enabled, too"
#endif
#if LWIP_TCP && LWIP_NETIF_TX_SINGLE_PBUF && !TCP_OVERSIZE
  #error "LWIP_NETIF_TX_SINGLE_PBUF needs TCP_OVERSIZE enabled to create single-pbuf TCP packets"
#endif
#if LWIP_NETCONN && LWIP_TCP
#if NETCONN_COPY != TCP_WRITE_FLAG_COPY
  #error "NETCONN_COPY != TCP_WRITE_FLAG_COPY"
#endif
#if NETCONN_MORE != TCP_WRITE_FLAG_MORE
  #error "NETCONN_MORE != TCP_WRITE_FLAG_MORE"
#endif
#endif /* LWIP_NETCONN && LWIP_TCP */
#if LWIP_SOCKET
/* Check that the SO_* socket options and SOF_* lwIP-internal flags match */
#if SO_REUSEADDR != SOF_REUSEADDR
  #error "WARNING: SO_REUSEADDR != SOF_REUSEADDR"
#endif
#if SO_KEEPALIVE != SOF_KEEPALIVE
  #error "WARNING: SO_KEEPALIVE != SOF_KEEPALIVE"
#endif
#if SO_BROADCAST != SOF_BROADCAST
  #error "WARNING: SO_BROADCAST != SOF_BROADCAST"
#endif
#endif /* LWIP_SOCKET */


/* Compile-time checks for deprecated options.
 */
#ifdef MEMP_NUM_TCPIP_MSG
  #error "MEMP_NUM_TCPIP_MSG option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef TCP_REXMIT_DEBUG
  #error "TCP_REXMIT_DEBUG option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef RAW_STATS
  #error "RAW_STATS option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef ETHARP_QUEUE_FIRST
  #error "ETHARP_QUEUE_FIRST option is deprecated. Remove it from your lwipopts.h."
#endif
#ifdef ETHARP_ALWAYS_INSERT
  #error "ETHARP_ALWAYS_INSERT option is deprecated. Remove it from your lwipopts.h."
#endif
#if !NO_SYS && LWIP_TCPIP_CORE_LOCKING && LWIP_COMPAT_MUTEX && !defined(LWIP_COMPAT_MUTEX_ALLOWED)
  #error "LWIP_COMPAT_MUTEX cannot prevent priority inversion. It is recommended to implement priority-aware mutexes. (Define LWIP_COMPAT_MUTEX_ALLOWED to disable this error.)"
#endif

#ifndef LWIP_DISABLE_TCP_SANITY_CHECKS
#define LWIP_DISABLE_TCP_SANITY_CHECKS  0
#endif
#ifndef LWIP_DISABLE_MEMP_SANITY_CHECKS
#define LWIP_DISABLE_MEMP_SANITY_CHECKS 0
#endif

/* MEMP sanity checks */
#if MEMP_MEM_MALLOC
#if !LWIP_DISABLE_MEMP_SANITY_CHECKS
#if LWIP_NETCONN || LWIP_SOCKET
#if !MEMP_NUM_NETCONN && LWIP_SOCKET
#error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN cannot be 0 when using sockets!"
#endif
#else /* MEMP_MEM_MALLOC */
#if MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB)
#error "lwip_sanity_check: WARNING: MEMP_NUM_NETCONN should be less than the sum of MEMP_NUM_{TCP,RAW,UDP}_PCB+MEMP_NUM_TCP_PCB_LISTEN. If you know what you are doing, define LWIP_DISABLE_MEMP_SANITY_CHECKS to 1 to disable this error."
#endif
#endif /* LWIP_NETCONN || LWIP_SOCKET */
#endif /* !LWIP_DISABLE_MEMP_SANITY_CHECKS */
#if MEM_USE_POOLS
#error "MEMP_MEM_MALLOC and MEM_USE_POOLS cannot be enabled at the same time"
#endif
#ifdef LWIP_HOOK_MEMP_AVAILABLE
#error "LWIP_HOOK_MEMP_AVAILABLE doesn't make sense with MEMP_MEM_MALLOC"
#endif
#endif /* MEMP_MEM_MALLOC */

/* TCP sanity checks */
#if !LWIP_DISABLE_TCP_SANITY_CHECKS
#if LWIP_TCP
#if !MEMP_MEM_MALLOC && (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
  #error "lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SND_BUF < (2 * TCP_MSS)
  #error "lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF / TCP_MSS))
  #error "lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SNDLOWAT >= TCP_SND_BUF
  #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_SNDLOWAT >= (0xFFFF - (4 * TCP_MSS))
  #error "lwip_sanity_check: WARNING: TCP_SNDLOWAT must at least be 4*MSS below u16_t overflow!"
#endif
#if TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN
  #error "lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (PBUF_POOL_BUFSIZE <= (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))
  #error "lwip_sanity_check: WARNING: PBUF_POOL_BUFSIZE does not provide enough space for protocol headers. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if !MEMP_MEM_MALLOC && PBUF_POOL_SIZE && (TCP_WND > (PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - (PBUF_LINK_ENCAPSULATION_HLEN + PBUF_LINK_HLEN + PBUF_IP_HLEN + PBUF_TRANSPORT_HLEN))))
  #error "lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE * (PBUF_POOL_BUFSIZE - protocol headers). If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#if TCP_WND < TCP_MSS
  #error "lwip_sanity_check: WARNING: TCP_WND is smaller than MSS. If you know what you are doing, define LWIP_DISABLE_TCP_SANITY_CHECKS to 1 to disable this error."
#endif
#endif /* LWIP_TCP */
#endif /* !LWIP_DISABLE_TCP_SANITY_CHECKS */

/**
 * @ingroup lwip_nosys
 * Initialize all modules.
 * Use this in NO_SYS mode. Use tcpip_init() otherwise.
 */
void
lwip_init(void)
{
#ifndef LWIP_SKIP_PACKING_CHECK
  LWIP_ASSERT("Struct packing not implemented correctly. Check your lwIP port.", sizeof(struct packed_struct_test) == PACKED_STRUCT_TEST_EXPECTED_SIZE);
#endif

  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
#if LWIP_IPV4
  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */
#endif /* LWIP_IPV4 */
#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */
#if LWIP_TCP
  tcp_init();
#endif /* LWIP_TCP */
#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
#if PPP_SUPPORT
  ppp_init();
#endif
 
#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
Пример #12
0
/**
  * @brief  Initializes the lwIP stack
  * @param  None
  * @retval None
  */
void LwIP_Init(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;
  uint8_t macaddress[6]={0,0,0,0,0,1};

  /* Initializes the dynamic memory heap defined by MEM_SIZE.*/
  mem_init();

  /* Initializes the memory pools defined by MEMP_NUM_x.*/
  memp_init();


#if LWIP_DHCP
  ipaddr.addr = 0;
  netmask.addr = 0;
  gw.addr = 0;

  /* Configure the board opeartin mode: Client/Server */  
  LCD_DisplayStringLine(Line5, "  Keep Key button   ");
  LCD_DisplayStringLine(Line6, "pressed to activate ");
  LCD_DisplayStringLine(Line7, "     the server     ");

  Delay(KEY_DELAY);
  
  if(!STM_EVAL_PBGetState(Button_KEY))
  {	
	Server = SELECTED;
	
	LCD_DisplayStringLine(Line5, "                    ");
	LCD_DisplayStringLine(Line6, "  Server selected   ");	
	LCD_DisplayStringLine(Line7, "                    ");
	Delay(LCD_DELAY);
  }
  else
  {
    macaddress[5]=CLIENTMAC6;
	
	Server = NOT_SELECTED;
	
	LCD_DisplayStringLine(Line5, "                    ");
	LCD_DisplayStringLine(Line6, "  Client selected   ");	
	LCD_DisplayStringLine(Line7, "                    ");
	Delay(LCD_DELAY);
  }

#else
  IP4_ADDR(&ipaddr, 192, 168, 0, 8);
  IP4_ADDR(&netmask, 255, 255, 255, 0);
  IP4_ADDR(&gw, 192, 168, 0, 1);
#endif

  Set_MAC_Address(macaddress);

  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
            struct ip_addr *netmask, struct ip_addr *gw,
            void *state, err_t (* init)(struct netif *netif),
            err_t (* input)(struct pbuf *p, struct netif *netif))
    
   Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.

  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/
  netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

  /*  Registers the default network interface.*/
  netif_set_default(&netif);


#if LWIP_DHCP
  /*  Creates a new DHCP client for this interface on the first call.
  Note: you must call dhcp_fine_tmr() and dhcp_coarse_tmr() at
  the predefined regular intervals after starting the client.
  You can peek in the netif->dhcp struct for the actual DHCP status.*/
  dhcp_start(&netif);
#endif

  /*  When the netif is fully configured this function must be called.*/
  netif_set_up(&netif);

}
Пример #13
0
/*-----------------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
  struct phybusif_cb *cb;
  struct timeval tcptv, bttv, now;
  struct timezone tz;
  u8_t btiptmr = 0;
  
#ifdef PERF
  perf_init("/tmp/minimal.perf");
#endif /* PERF */
#ifdef STATS
  stats_init();
#endif /* STATS */

  mem_init();
  memp_init();
  pbuf_init(); 
  netif_init();
  ip_init();
  //udp_init();
  tcp_init();
  printf("TCP/IP initialized.\n");
  lwbt_memp_init();
  phybusif_init();
  if(hci_init() != ERR_OK) {
    printf("HCI initialization failed!");
    exit(-1);
  }
  l2cap_init();
  sdp_init();
  rfcomm_init();
  ppp_init();
  printf("Bluetooth initialized.\n");

  //echo_init();
  httpd_init();
  printf("Applications started.\n");

  cb = malloc(sizeof(struct phybusif_cb));
  phybusif_reset(cb);

  gettimeofday(&bttv, &tz); /* Initialize Bluetooth timer (1s) */
  gettimeofday(&tcptv, &tz); /* Initialize TCP timer (TCP_TMR_INTERVAL) */

  /* Host controller initialization for DTs according to LAN access point (LAP) and dial up networking (DUN) profile */
  bt_ip_start(NULL);

  while(1) {
    phybusif_input(cb); /* Check for input */

    gettimeofday(&now, &tz); /* Get current time */

    /* Check if TCP timer  should be called */
    if((now.tv_sec - tcptv.tv_sec) * 1000000 + (now.tv_usec - tcptv.tv_usec) >= TCP_TMR_INTERVAL * 1000) {
      gettimeofday(&tcptv, &tz); /* Reset TCP timer */
      tcp_tmr();
    }

    /* Check if Bluetooth and NAT timers should be called */ 
    if((now.tv_sec - bttv.tv_sec) * 1000000 + (now.tv_usec - bttv.tv_usec) >= 1000000) {
      gettimeofday(&bttv, &tz); /* Restart Bluetooth timer */
      l2cap_tmr();
      rfcomm_tmr();
      ppp_tmr();
      nat_tmr();
      if(++btiptmr == 240) { /* Akes server special */
	bt_ip_tmr();
	btiptmr = 0;
      }
    }
  }
  
  return 0;
}
Пример #14
0
void lwip_init(u8_t* lwip_memory){
  sys_sem_t sem;

	extern u8_t** ADI_TOOLS_ram_ptr;
	extern u32_t  ADI_TOOLS_ram_len;
	extern u8_t** ADI_TOOLS_memp_ptr;
	extern u32_t  ADI_TOOLS_memp_len;
        extern u8_t** ADI_TOOLS_pbuf_pool_ptr;
        extern u32_t  ADI_TOOLS_pbuf_pool_len;
	
	// caller must ensure that the area of memory supplied as 'lwip_memory'
	// is at least as long as the sum of the 'len' values
	*ADI_TOOLS_ram_ptr       = lwip_memory;
	*ADI_TOOLS_memp_ptr      = lwip_memory
                                     + ADI_TOOLS_ram_len;
       
  stats_init();
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
  
  sys_sem_new(&sem,0);
  tcpip_init(tcpip_init_done, &sem);
  sys_sem_wait(&sem);
  sys_sem_free(&sem);
  
#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */

  ip_init();
#if LWIP_ARP
  etharp_init();
#endif /* LWIP_ARP */

#if LWIP_RAW
  raw_init();
#endif /* LWIP_RAW */

#if LWIP_UDP
  udp_init();
#endif /* LWIP_UDP */

#if LWIP_TCP
  //tcp_init();
#endif /* LWIP_TCP */

#if LWIP_AUTOIP
  autoip_init();
#endif /* LWIP_AUTOIP */

#if LWIP_IGMP
  igmp_init();
#endif /* LWIP_IGMP */

#if LWIP_DNS
  dns_init();
#endif /* LWIP_DNS */
}
Пример #15
0
/********
 * MAIN *
 ********/
void main()
{
#ifdef SIMULATOR
	struct ip_addr dump_ipaddr, dump_netmask, dump_gw;
#else
	struct ip_addr eth_ipaddr, eth_netmask, eth_gw;
#endif
	struct ip_addr ipsec_ipaddr, ipsec_netmask, ipsec_gw;
	unsigned int i;


	serinit();							/* init serial port					*/

	printf("lwIP - IPsec Dynamic SAD/SPD configuration demo (compiled %s at %s)\n", __DATE__, __TIME__);
	printf("CVS ID: $Id: main.c,v 1.8 2003/12/12 14:36:33 schec2 Exp $\n\n");


	/* initialize lwIP */
	etharp_init();
	mem_init();
	memp_init();
	pbuf_init(); 
	netif_init();
	ip_init();
	udp_init();
	tcp_init();
	printf("TCP/IP initialized.\n");

#ifdef SIMULATOR
	/* configure dummy device */
	IP4_ADDR(&dump_ipaddr, 192,168,1,3);
	IP4_ADDR(&dump_netmask, 255,255,255,0);
	IP4_ADDR(&dump_gw, 192,168,1,1);

	/* configure IPsec device */
	IP4_ADDR(&ipsec_ipaddr, 192,168,1,3);
	IP4_ADDR(&ipsec_netmask, 255,255,255,0);
	IP4_ADDR(&ipsec_gw, 192,168,1,1);
#endif

#ifdef MCB167NET
	/* configure Ethernet device */
	IP4_ADDR(&eth_ipaddr, 192,168,1,3);
	IP4_ADDR(&eth_netmask, 255,255,255,0);
	IP4_ADDR(&eth_gw, 192,168,1,1);

	/* configure IPsec device */
	IP4_ADDR(&ipsec_ipaddr, 192,168,1,3);
	IP4_ADDR(&ipsec_netmask, 255,255,255,0);
	IP4_ADDR(&ipsec_gw, 192,168,1,1);
#endif

#ifdef PHYCORE167HSE
	/* configure Ethernet device */
	IP4_ADDR(&eth_ipaddr, 192,168,1,4);
	IP4_ADDR(&eth_netmask, 255,255,255,0);
	IP4_ADDR(&eth_gw, 192,168,1,1);

	/* configure IPsec device */
	IP4_ADDR(&ipsec_ipaddr, 192,168,1,4);
	IP4_ADDR(&ipsec_netmask, 255,255,255,0);
	IP4_ADDR(&ipsec_gw, 192,168,1,1);
#endif


	/* Initialize the physical device first (so that ethif->next will point *
	 * to ipsecif). The IPsec device will process the packets and pass them *
	 * upper to the IP layer (using ip_input)                               *
	 * If the simulator is used, dumpdev will replace cs8900.               */
#ifdef SIMULATOR
	printf("Setting up dp0...");
	dumpif = netif_add(&dump_ipaddr, &dump_netmask, &dump_gw, NULL,  dumpdev_init, ipsecdev_input);
	printf("OK\n");

	printf("Setting up is0...");
	ipsecif = netif_add(&ipsec_ipaddr, &ipsec_netmask, &ipsec_gw, NULL,  ipsecdev_init, ip_input);
	printf("OK\n");
#else
	printf("Setting up et0...");
	ethif = netif_add(&eth_ipaddr, &eth_netmask, &eth_gw, NULL,  cs8900if_init, ipsecdev_input);
	printf("OK\n");

	printf("Setting up is0...");
	ipsecif = netif_add(&ipsec_ipaddr, &ipsec_netmask, &ipsec_gw, NULL,  ipsecdev_init, ip_input);
	printf("OK\n");
#endif

	/* configure IPsec tunnel */
#ifdef PHYCORE167HSE
	ipsec_set_tunnel("192.168.1.4", "192.168.1.5");
#else
	ipsec_set_tunnel("192.168.1.3", "192.168.1.5");
#endif

	/* set the IPsec interface "is0" as default interface for lwIP */
	netif_set_default(ipsecif);			/* use ipsec interface by default	*/


	/* start custom applications here */
	dumpwebpage_init();					/* start dumpwebpage 				*/
 	netconfig_init();					/* start dynamic network confiuratio*/

	printf("Applications started.\n");
	DP2  = 0x00FF;						/* configure the status LED on Port2*/
	ODP2 = 0x0000;

	while(1)
	{
		P2 = ~P2;						/* blink LED 						*/

		for (i = 0; i < 50000; i++)  
		{       	
    		_nop_(); _nop_();			/* delay or use this time for the   */
			_nop_(); _nop_();			/* application						*/
			_nop_(); _nop_();
			if((i % 250) == 0) 
			{							/* periodically call to the     	*/
#ifdef SIMULATOR
      			dumpdev_service(dumpif);/* dump device driver (polling mode)*/
#else
      			cs8900if_service(ethif);/* CS8900 driver (polling mode) 	*/
#endif
				tcp_tmr();				/* poll TCP timer					*/
    		}


		}
  	}

}
Пример #16
0
/**
 * Perform Sanity check of user-configurable values, and initialize all modules.
 */
void
ICACHE_FLASH_ATTR lwip_init(void)
{
  /* Sanity check user-configurable values */
  lwip_sanity_check();

  /* Modules initialization */
  stats_init();
#if !NO_SYS
  sys_init();
#endif /* !NO_SYS */
#if 0
  mem_init(&_bss_end);
#endif
  memp_init();

  pbuf_init();

  netif_init();

#if LWIP_SOCKET
  lwip_socket_init();
#endif /* LWIP_SOCKET */
  ip_init();

#if LWIP_ARP
  etharp_init();

#endif /* LWIP_ARP */
#if LWIP_RAW
  raw_init();

#endif /* LWIP_RAW */
#if LWIP_UDP
  udp_init();

#endif /* LWIP_UDP */
#if LWIP_TCP
  MEMP_NUM_TCP_PCB = 5;
  tcp_init();

#endif /* LWIP_TCP */
#if LWIP_SNMP
  snmp_init();

#endif /* LWIP_SNMP */
#if LWIP_AUTOIP
  autoip_init();

#endif /* LWIP_AUTOIP */
#if LWIP_IGMP
  igmp_init();

#endif /* LWIP_IGMP */
#if LWIP_DNS
  dns_init();

#endif /* LWIP_DNS */

#if LWIP_TIMERS
  sys_timeouts_init();
#endif /* LWIP_TIMERS */
}
Пример #17
0
/**
* @brief  Initializes the lwIP stack
* @param  None
* @retval None
*/
void LwIP_Init(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;
	#ifndef USE_DHCP
	  uint8_t iptab[4] = {0};
	  uint8_t iptxt[20];
	#endif
  
  /* Initializes the dynamic memory heap defined by MEM_SIZE.*/
  mem_init();
  
  /* Initializes the memory pools defined by MEMP_NUM_x.*/
  memp_init();
  
	#ifdef USE_DHCP
	  ipaddr.addr = 0;
	  netmask.addr = 0;
	  gw.addr = 0;
	#else
	  IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
	  IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
	  IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
	#endif
  
  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
  struct ip_addr *netmask, struct ip_addr *gw,
  void *state, err_t (* init)(struct netif *netif),
  err_t (* input)(struct pbuf *p, struct netif *netif))

  Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.

  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

  /*  Registers the default network interface.*/
  netif_set_default(&gnetif);

//  if (EthStatus == (ETH_INIT_FLAG | ETH_LINK_FLAG))
//  {
    /* Set Ethernet link flag */
    gnetif.flags |= NETIF_FLAG_LINK_UP;

    /* When the netif is fully configured this function must be called */
    netif_set_up(&gnetif);

	#ifdef USE_DHCP
		DHCP_state = DHCP_START;
	#endif /* USE_DHCP */
//  }
//  else
//  {
//    /* When the netif link is down this function must be called */
//    netif_set_down(&gnetif);
//
//#ifdef USE_DHCP
//    DHCP_state = DHCP_LINK_DOWN;
//#endif /* USE_DHCP */
//  }
//
//  /* Set the link callback function, this function is called on change of link status*/
//  netif_set_link_callback(&gnetif, ETH_link_callback);
}
Пример #18
0
struct netif * LwIP_Init()
{
  uint8_t macaddress[6] = ETH_MAC_ADDR;
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;

  /* Create isr for ethernet interrupt */
  TaskType tid;
  tid = Os_Arc_CreateIsr(Eth_Isr,3/*prio*/,"Eth"); \
  Irq_AttachIsr2(tid,NULL,ETH_IRQn); \

  /* Configure ethernet */
   Ethernet_Configuration();

#if NO_SYS
#if (MEM_LIBC_MALLOC==0)  
  mem_init();
#endif
#if (MEMP_MEM_MALLOC==0)  
  memp_init();
#endif
#else
  pre_sys_init();
  tcpip_init(tcpip_init_done, NULL);
  uint32 lockcnt = 0;
  while(tcpip_initialized == FALSE){
  	 lockcnt++;
  	 SLEEP(0);
  };
#endif

#if LWIP_DHCP
  ipaddr.addr = 0;
  netmask.addr = 0;
  gw.addr = 0;
#else
  GET_BOOT_IPADDR;
  GET_BOOT_NETMASK;
  GET_BOOT_GW;
#endif

  Set_MAC_Address(macaddress);

  /* Add network interface to the netif_list */
  netif_add(&netif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &tcpip_input);

  /*  Registers the default network interface.*/
  netif_set_default(&netif);

#if LWIP_DHCP
  /* start dhcp search */
  dhcp_start(&netif);
#else
  netif_set_addr(&netif, &ipaddr , &netmask, &gw);
#endif

  /* netif is configured */
  netif_set_up(&netif);

  EnableEthDMAIrq();

  netbios_init();

  return &netif;
}
Пример #19
0
/**
 * @brief LWIP handling thread.
 *
 * @param[in] p pointer to a @p lwipthread_opts structure or @p NULL
 * @return The function does not return.
 */
msg_t lwip_thread(void *p) {
  EvTimer evt;
  EventListener el0, el1;
  struct ip_addr ip, gateway, netmask;
  static struct netif thisif;
  static const MACConfig mac_config = {thisif.hwaddr};

  chRegSetThreadName("lwipthread");

  /* Initializes the thing.*/
  sys_init();
  mem_init();
  memp_init();
  pbuf_init();
  netif_init();
  ip_init();
  tcpip_init(NULL, NULL);

  /* TCP/IP parameters, runtime or compile time.*/
  if (p) {
    struct lwipthread_opts *opts = p;
    unsigned i;

    for (i = 0; i < 6; i++)
      thisif.hwaddr[i] = opts->macaddress[i];
    ip.addr = opts->address;
    gateway.addr = opts->gateway;
    netmask.addr = opts->netmask;
  }
  else {
    thisif.hwaddr[0] = LWIP_ETHADDR_0;
    thisif.hwaddr[1] = LWIP_ETHADDR_1;
    thisif.hwaddr[2] = LWIP_ETHADDR_2;
    thisif.hwaddr[3] = LWIP_ETHADDR_3;
    thisif.hwaddr[4] = LWIP_ETHADDR_4;
    thisif.hwaddr[5] = LWIP_ETHADDR_5;
    LWIP_IPADDR(&ip);
    LWIP_GATEWAY(&gateway);
    LWIP_NETMASK(&netmask);
  }
  macStart(&ETHD1, &mac_config);
  netif_add(&thisif, &ip, &netmask, &gateway, NULL, ethernetif_init, tcpip_input);

  netif_set_default(&thisif);
  netif_set_up(&thisif);

  /* Setup event sources.*/
  evtInit(&evt, S2ST(5));
  evtStart(&evt);
  chEvtRegisterMask(&evt.et_es, &el0, PERIODIC_TIMER_ID);
  chEvtRegisterMask(macGetReceiveEventSource(&ETHD1), &el1, FRAME_RECEIVED_ID);
  chEvtAddEvents(PERIODIC_TIMER_ID | FRAME_RECEIVED_ID);

  /* Goes to the final priority after initialization.*/
  chThdSetPriority(LWIP_THREAD_PRIORITY);

  while (TRUE) {
    eventmask_t mask = chEvtWaitAny(ALL_EVENTS);
    if (mask & PERIODIC_TIMER_ID) {
      bool_t current_link_status = macPollLinkStatus(&ETHD1);
      if (current_link_status != netif_is_link_up(&thisif)) {
        if (current_link_status)
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                     &thisif, 0);
        else
          tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                     &thisif, 0);
      }
    }
    if (mask & FRAME_RECEIVED_ID) {
      struct pbuf *p;
      while ((p = low_level_input(&thisif)) != NULL) {
        struct eth_hdr *ethhdr = p->payload;
        switch (htons(ethhdr->type)) {
        /* IP or ARP packet? */
        case ETHTYPE_IP:
        case ETHTYPE_ARP:
#if PPPOE_SUPPORT
        /* PPPoE packet? */
        case ETHTYPE_PPPOEDISC:
        case ETHTYPE_PPPOE:
#endif /* PPPOE_SUPPORT */
          /* full packet send to tcpip_thread to process */
          if (thisif.input(p, &thisif) == ERR_OK)
            break;
          LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));
        default:
          pbuf_free(p);
        }
      }
    }
  }
  return 0;
}
Пример #20
0
static int sef_cb_init_fresh(__unused int type, __unused sef_init_info_t *info)
{
	int err;
	unsigned int hz;

	nic_init_all();
	inet_read_conf();

	/* init lwip library */
	stats_init();
	sys_init();
	mem_init();
	memp_init();
	pbuf_init();

	hz = sys_hz();

	arp_ticks = ARP_TMR_INTERVAL / (1000 / hz);
	tcp_fticks = TCP_FAST_INTERVAL / (1000 / hz);
	tcp_sticks = TCP_SLOW_INTERVAL / (1000 / hz);

	etharp_init();
	
	set_timer(&arp_tmr, arp_ticks, arp_watchdog, 0);
	set_timer(&tcp_ftmr, tcp_fticks, tcp_fwatchdog, 0);
	set_timer(&tcp_stmr, tcp_sticks, tcp_swatchdog, 0);
	
	netif_init();
	netif_lo = netif_find(__UNCONST("lo0"));

	/* Read configuration. */
#if 0
	nw_conf();

	/* Get a random number */
	timerand= 1;
	fd = open(RANDOM_DEV_NAME, O_RDONLY | O_NONBLOCK);
	if (fd != -1)
	{
		err= read(fd, randbits, sizeof(randbits));
		if (err == sizeof(randbits))
			timerand= 0;
		else
		{
			printf("inet: unable to read random data from %s: %s\n",
				RANDOM_DEV_NAME, err == -1 ? strerror(errno) :
				err == 0 ? "EOF" : "not enough data");
		}
		close(fd);
	}
	else
	{
		printf("inet: unable to open random device %s: %s\n",
				RANDOM_DEV_NAME, strerror(errno));
	}
	if (timerand)
	{
		printf("inet: using current time for random-number seed\n");
		err= gettimeofday(&tv, NULL);
		if (err == -1)
		{
			printf("sysutime failed: %s\n", strerror(errno));
			exit(1);
		}
		memcpy(randbits, &tv, sizeof(tv));
	}
	init_rand256(randbits);
#endif

	/* Subscribe to driver events for network drivers. */
	if ((err = ds_subscribe("drv\\.net\\..*",
					DSF_INITIAL | DSF_OVERWRITE)) != OK)
		panic(("inet: can't subscribe to driver events"));

	/* Announce we are up. LWIP announces its presence to VFS just like
	 * any other character driver.
	 */
	chardriver_announce();

	return(OK);
}
Пример #21
0
/*-----------------------------------------------------------------------------------*/
void 
maintask(void)
{
  struct phybusif_cb *cb;
  CLKBLK ks_clk *tmr;
  u8_t bt_timer = 0;
  u16_t http_timer = 0;
  u16_t dma0bsz = TCR0+1; /* DMA 0 Buf size */
  u8_t bt_ip_timer = 0;

  mem_init();
  memp_init();
  pbuf_init(); 
  netif_init();
  ip_init();
  tcp_init();
  sio_print("TCP/IP initialized.\n");
  
  lwbt_memp_init();
  phybusif_init();
  if(hci_init() != ERR_OK) {
    sio_print("HCI initialization failed!");
  }
  l2cap_init();
  sdp_init();
  rfcomm_init();
  ppp_init();
  
  sio_print("Bluetooth initialized.\n");

  httpd_init();
  sio_print("Applications started.\n");

  cb = mem_malloc(sizeof(struct phybusif_cb));
  cb->dmabuf = get_dm0ichars();
  phybusif_reset(cb);
  
  tmr = KS_alloc_timer();
  if(tmr == 0) {
    sio_print("tmr==0!\n");
  }
  KS_start_timer(tmr, (TICKS)0, (TICKS)100/CLKTICK, TIMERSEM); /* TCP timer ticks every 100ms */

  /* Reset Bluetooth module */
  PD7.0 = 1; /* Enable output */
  sio_print("Reseting BT module\n");
  P7.0 = 1; /* Stop reset */
  
  KS_delay(SELFTASK,(TICKS)4000/CLKTICK); /* Wait for bluetooth module to init */

  /* Control application initialisation */
  bt_ip_start();

  while(1) {
    dma_input(cb, dma0bsz); /* Check for input */

    /* Handle timers */
    if(KS_inqsema(TIMERSEM) == SEMA_DONE) {
      KS_wait(TIMERSEM);
      tcp_tmr();
      ++bt_timer;
      if(bt_timer == 10) {
        l2cap_tmr();
        rfcomm_tmr();
        ppp_tmr();
        bt_timer = 0;
        ++bt_ip_timer;
        if(bt_ip_timer == 240) {
          bt_ip_tmr();
          bt_ip_timer = 0;
        } 
      }
      
    }
  }
}
Пример #22
0
void LwIP_Init(void)
{
	struct ip_addr ipaddr;
	struct ip_addr netmask;
	struct ip_addr gw;
#ifndef USE_DHCP
	uint8_t iptab[4] = {0};
	uint8_t iptxt[20];
#endif
	/* Initializes the dynamic memory heap defined by MEM_SIZE.*/
	mem_init();
  
	/* Initializes the memory pools defined by MEMP_NUM_x.*/
	memp_init();
  
#ifdef USE_DHCP
	ipaddr.addr = 0;
	netmask.addr = 0;
	gw.addr = 0;
	dds
#else

	printf("Baca konfigurasi ...");
	struct t_env *s_en = baca_env();
	if (s_en == 0)
	{
		printf("%s(): Baca ENV ERROR\r\n", __FUNCTION__);	
		while(1);
	}
	printf("...OK\r\n");
	printf("IP address : %d.%d.%d.%d\r\n", s_en->IP0, s_en->IP1, s_en->IP2, s_en->IP3);
	
	/* mestinya disini jika deteksi jumper, bisa diset hardcoded IP nya */
	//s_en->IP0 = 192;
	//s_en->IP1 = 168;
	//s_en->IP2 = 1;
	//s_en->IP3 = 240;
	
	printf("IP address : %d.%d.%d.%d\r\n", s_en->IP0, s_en->IP1, s_en->IP2, s_en->IP3);
	
	IP4_ADDR(&ipaddr, s_en->IP0, s_en->IP1, s_en->IP2, s_en->IP3);
	IP4_ADDR(&netmask, s_en->NET_MASK0, s_en->NET_MASK1, s_en->NET_MASK2, s_en->NET_MASK3);
	IP4_ADDR(&gw, s_en->GW0, s_en->GW1, s_en->GW2, s_en->GW3);	
#endif  
  
	  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
	  struct ip_addr *netmask, struct ip_addr *gw,
	  void *state, err_t (* init)(struct netif *netif),
	  err_t (* input)(struct pbuf *p, struct netif *netif))

	  Adds your network interface to the netif_list. Allocate a struct
	  netif and pass a pointer to this structure as the first argument.
	  Give pointers to cleared ip_addr structures when using DHCP,
	  or fill them with sane numbers otherwise. The state pointer may be NULL.

	  The init function pointer must point to a initialization function for
	  your ethernet netif interface. The following code illustrates it's use.*/
	 netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

	 /*  Registers the default network interface.*/
	 netif_set_default(&gnetif);

#if 1
	//if (EthStatus == (ETH_INIT_FLAG | ETH_LINK_FLAG))
	{
		/* Set Ethernet link flag */
		gnetif.flags |= NETIF_FLAG_LINK_UP;

		/* When the netif is fully configured this function must be called */
		netif_set_up(&gnetif);

#ifdef USE_DHCP
		DHCP_state = DHCP_START;
#else
#ifdef USE_LCD

/*
    iptab[0] = IP_ADDR3;
    iptab[1] = IP_ADDR2;
    iptab[2] = IP_ADDR1;
    iptab[3] = IP_ADDR0;
    sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]); 
*/
    //LCD_DisplayStringLine(Line8, (uint8_t*)"  Static IP address   ");
    //LCD_DisplayStringLine(Line9, iptxt);
#endif
#endif /* USE_DHCP */
	}
#if 0
	else
	{
Пример #23
0
/**
* @brief  Initializes the lwIP stack
* @param  None
* @retval None
*/
void LwIP_Init(void)
{
  struct ip_addr ipaddr;
  struct ip_addr netmask;
  struct ip_addr gw;
#ifndef USE_DHCP
  uint8_t iptab[4] = {0};
  uint8_t iptxt[20];
#endif
  
  /* Initializes the dynamic memory heap defined by MEM_SIZE.*/
  mem_init();
  
  /* Initializes the memory pools defined by MEMP_NUM_x.*/
  memp_init();
  
#ifdef USE_DHCP
  ipaddr.addr = 0;
  netmask.addr = 0;
  gw.addr = 0;
#else
  IP4_ADDR(&ipaddr, IP_ADDR0, IP_ADDR1, IP_ADDR2, IP_ADDR3);
  IP4_ADDR(&netmask, NETMASK_ADDR0, NETMASK_ADDR1 , NETMASK_ADDR2, NETMASK_ADDR3);
  IP4_ADDR(&gw, GW_ADDR0, GW_ADDR1, GW_ADDR2, GW_ADDR3);
#endif  

  /* - netif_add(struct netif *netif, struct ip_addr *ipaddr,
  struct ip_addr *netmask, struct ip_addr *gw,
  void *state, err_t (* init)(struct netif *netif),
  err_t (* input)(struct pbuf *p, struct netif *netif))

  Adds your network interface to the netif_list. Allocate a struct
  netif and pass a pointer to this structure as the first argument.
  Give pointers to cleared ip_addr structures when using DHCP,
  or fill them with sane numbers otherwise. The state pointer may be NULL.

  The init function pointer must point to a initialization function for
  your ethernet netif interface. The following code illustrates it's use.*/
  netif_add(&gnetif, &ipaddr, &netmask, &gw, NULL, &ethernetif_init, &ethernet_input);

  /*  Registers the default network interface.*/
  netif_set_default(&gnetif);

  if (EthStatus == (ETH_INIT_FLAG | ETH_LINK_FLAG))
  { 
    /* Set Ethernet link flag */
    gnetif.flags |= NETIF_FLAG_LINK_UP;

    /* When the netif is fully configured this function must be called.*/
    netif_set_up(&gnetif);
#ifdef USE_DHCP
    DHCP_state = DHCP_START;
#else
#ifdef USE_LCD

    iptab[0] = IP_ADDR3;
    iptab[1] = IP_ADDR2;
    iptab[2] = IP_ADDR1;
    iptab[3] = IP_ADDR0;

    sprintf((char*)iptxt, "  %d.%d.%d.%d", iptab[3], iptab[2], iptab[1], iptab[0]);

    LCD_DisplayStringLine(Line8, (uint8_t*)"  Static IP address   ");
    LCD_DisplayStringLine(Line9, iptxt);
#endif
#endif /* USE_DHCP */
  }
  else
  {
    /*  When the netif link is down this function must be called.*/
    netif_set_down(&gnetif);
#ifdef USE_DHCP
    DHCP_state = DHCP_LINK_DOWN;
#endif /* USE_DHCP */
    /* Set the LCD Text Color */
//    LCD_SetTextColor(Red);

    /* Display message on the LCD */
//    LCD_DisplayStringLine(Line5, (uint8_t*)"  Network Cable is  ");
//    LCD_DisplayStringLine(Line6, (uint8_t*)"    not connected   ");

    /* Set the LCD Text Color */
//    LCD_SetTextColor(White);
  }

  /* Set the link callback function, this function is called on change of link status*/
  netif_set_link_callback(&gnetif, ETH_link_callback);
}