Example #1
0
static err_t PacketSend (struct pbuf *p)
{
	struct pbuf *q = NULL;
	unsigned int templen = 0;

	for(q = p;q!=NULL;q = q->next)
	{
		memcpy(&MySendbuf[templen],q->payload,q->len);	 //将pbuf中的数据拷贝到全局数组MyDatabuf中
		templen += 	q->len ;

		if(templen > 1500 || templen > p->tot_len)	 	//有效性校验,防止数据溢出
		{
			LWIP_PLATFORM_DIAG(("PacketSend: error,tmplen=%"U32_F",tot_len=%"U32_F"\n\t", templen, p->tot_len));
			return ERR_BUF;
		}
	}
	
	//拷贝完毕,下面进行数据的发送工作
	if(templen == p->tot_len)
	{
		enc28j60PacketSend(templen, MySendbuf);		   //调用网卡发送函数
		return ERR_OK; 
	}
	
	LWIP_PLATFORM_DIAG(("PacketSend: length mismatch ,tmplen=%"U32_F",tot_len=%"U32_F"\n\t", templen, p->tot_len));
	return ERR_BUF;
}
Example #2
0
void
stats_display_mem(struct stats_mem *mem, char *name)
{
  LWIP_PLATFORM_DIAG(("\nMEM %s\n\t", name));
  LWIP_PLATFORM_DIAG(("avail: %"U32_F"\n\t", (u32_t)mem->avail)); 
  LWIP_PLATFORM_DIAG(("used: %"U32_F"\n\t", (u32_t)mem->used)); 
  LWIP_PLATFORM_DIAG(("max: %"U32_F"\n\t", (u32_t)mem->max)); 
  LWIP_PLATFORM_DIAG(("err: %"U32_F"\n", (u32_t)mem->err));
}
Example #3
0
VOID stats_display_mem(struct stats_mem *mem, INT8 *name)
{
#if 0
	LWIP_PLATFORM_DIAG(("\n MEM %s\n\t", name));
	LWIP_PLATFORM_DIAG(("avail: 0x%x\n\t", mem->avail));
	LWIP_PLATFORM_DIAG(("used: 0x%x\n\t", mem->used));
	LWIP_PLATFORM_DIAG(("max: 0x%x\n\t", mem->max));
	LWIP_PLATFORM_DIAG(("err: 0x%x\n", mem->err));
#endif
}
Example #4
0
void
stats_display_igmp(struct stats_igmp *igmp)
{
  LWIP_PLATFORM_DIAG(("\nIGMP\n\t"));
  LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr)); 
  LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr)); 
  LWIP_PLATFORM_DIAG(("v1_rxed: %"STAT_COUNTER_F"\n\t", igmp->v1_rxed)); 
  LWIP_PLATFORM_DIAG(("join_sent: %"STAT_COUNTER_F"\n\t", igmp->join_sent)); 
  LWIP_PLATFORM_DIAG(("leave_sent: %"STAT_COUNTER_F"\n\t", igmp->leave_sent)); 
  LWIP_PLATFORM_DIAG(("unicast_query: %"STAT_COUNTER_F"\n\t", igmp->unicast_query)); 
  LWIP_PLATFORM_DIAG(("report_sent: %"STAT_COUNTER_F"\n\t", igmp->report_sent)); 
  LWIP_PLATFORM_DIAG(("report_rxed: %"STAT_COUNTER_F"\n\t", igmp->report_rxed)); 
  LWIP_PLATFORM_DIAG(("group_query_rxed: %"STAT_COUNTER_F"\n", igmp->group_query_rxed));
}
Example #5
0
void
stats_display_sys(struct stats_sys *sys)
{
  LWIP_PLATFORM_DIAG(("\nSYS\n\t"));
  LWIP_PLATFORM_DIAG(("sem.used:  %"U32_F"\n\t", (u32_t)sys->sem.used)); 
  LWIP_PLATFORM_DIAG(("sem.max:   %"U32_F"\n\t", (u32_t)sys->sem.max)); 
  LWIP_PLATFORM_DIAG(("sem.err:   %"U32_F"\n\t", (u32_t)sys->sem.err)); 
  LWIP_PLATFORM_DIAG(("mutex.used: %"U32_F"\n\t", (u32_t)sys->mutex.used)); 
  LWIP_PLATFORM_DIAG(("mutex.max:  %"U32_F"\n\t", (u32_t)sys->mutex.max)); 
  LWIP_PLATFORM_DIAG(("mutex.err:  %"U32_F"\n\t", (u32_t)sys->mutex.err)); 
  LWIP_PLATFORM_DIAG(("mbox.used:  %"U32_F"\n\t", (u32_t)sys->mbox.used)); 
  LWIP_PLATFORM_DIAG(("mbox.max:   %"U32_F"\n\t", (u32_t)sys->mbox.max)); 
  LWIP_PLATFORM_DIAG(("mbox.err:   %"U32_F"\n\t", (u32_t)sys->mbox.err)); 
}
Example #6
0
struct pbuf *PacketReceive(struct netif *netif)
{
	struct pbuf *p = NULL;	
	unsigned int recvlen = 0;
	unsigned int i = 0;
	struct pbuf *q = NULL;
    
	recvlen = enc28j60PacketReceive(1500, MyRecvbuf);

	if(!recvlen)	       //接收数据长度为0,直接返回空
	{
	    return NULL;
	}
	
	//申请内核pbuf空间,为RAM类型
	p = pbuf_alloc(PBUF_RAW, recvlen, PBUF_RAM);
	
	if(!p)			       //申请失败,则返回空
	{
	    LWIP_PLATFORM_DIAG(("PacketReceive: pbuf_alloc fail ,len=%"U32_F"\n\t", recvlen));
		return NULL;
	 }
    //申请成功,拷贝数据到pbuf中
	q = p;
		
	while(q != NULL)
	{   
		memcpy(q->payload,&MyRecvbuf[i],q->len);
		i += q->len;
		q = q->next;
		if(i >= recvlen)  break;
	}
		
	return p;
}
void LwipNetInterface::ipStackInitDone(void *pData) {

	LwipNetInterface* lwipInterface;

	lwipInterface = (LwipNetInterface*) pData;

	LWIP_PLATFORM_DIAG(("TCP/IP stack init done\n"));

	LWIP_PLATFORM_DIAG(("netif= %p\n", &lwipInterface->netif));

	netif_set_default(
			netif_add(&lwipInterface->netif, &lwipInterface->ipaddr,
					&lwipInterface->netmask, &lwipInterface->gateway, NULL,
					tapif_init, tcpip_input));

	LWIP_PLATFORM_DIAG(("Signaling semaphore\n"));
	sys_sem_signal(&lwipInterface->syncSem);

}
void LwipNetInterface::initInterface(void) {

	LWIP_PLATFORM_DIAG(("Interface initialization\n"));

	if (sys_sem_new(&this->syncSem, 0) != ERR_OK) {
		LWIP_ASSERT("failed to create semaphore", 0);
	}
	tcpip_init(this->ipStackInitDone, this);
	sys_sem_wait(&this->syncSem);
	sys_sem_free(&this->syncSem);
}
Example #9
0
void
stats_display_pbuf(struct stats_pbuf *pbuf)
{
  LWIP_PLATFORM_DIAG(("\nPBUF\n\t"));
  LWIP_PLATFORM_DIAG(("avail: %"S16_F"\n\t", pbuf->avail)); 
  LWIP_PLATFORM_DIAG(("used: %"S16_F"\n\t", pbuf->used)); 
  LWIP_PLATFORM_DIAG(("max: %"S16_F"\n\t", pbuf->max)); 
  LWIP_PLATFORM_DIAG(("err: %"S16_F"\n\t", pbuf->err)); 
  LWIP_PLATFORM_DIAG(("alloc_locked: %"S16_F"\n\t", pbuf->alloc_locked)); 
  LWIP_PLATFORM_DIAG(("refresh_locked: %"S16_F"\n", pbuf->refresh_locked)); 
}
Example #10
0
VOID stats_display_pbuf(struct stats_pbuf *pbuf)
{
#if 0
	LWIP_PLATFORM_DIAG(("\nPBUF\n\t"));
	LWIP_PLATFORM_DIAG(("avail: 0x%x\n\t", pbuf->avail));
	LWIP_PLATFORM_DIAG(("used: 0x%x\n\t", pbuf->used));
	LWIP_PLATFORM_DIAG(("max: 0x%x\n\t", pbuf->max));
	LWIP_PLATFORM_DIAG(("err: 0x%x\n\t", pbuf->err));
	LWIP_PLATFORM_DIAG(("alloc_locked: 0x%x\n\t", pbuf->alloc_locked));
	LWIP_PLATFORM_DIAG(("refresh_locked: 0x%x\n", pbuf->refresh_locked));
#endif
}
/*!
 * @brief Main function
 */
int main(void)
{
    ip_addr_t fsl_netif0_ipaddr, fsl_netif0_netmask, fsl_netif0_gw;

    MPU_Type *base = MPU;
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();
    /* Disable MPU. */
    base->CESR &= ~MPU_CESR_VLD_MASK;

    LWIP_DEBUGF(UDPECHO_DBG, ("TCP/IP initializing...\r\n"));
    tcpip_init(NULL, NULL);
    LWIP_DEBUGF(UDPECHO_DBG, ("TCP/IP initialized.\r\n"));

    IP4_ADDR(&fsl_netif0_ipaddr, configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3);
    IP4_ADDR(&fsl_netif0_netmask, configNET_MASK0, configNET_MASK1, configNET_MASK2, configNET_MASK3);
    IP4_ADDR(&fsl_netif0_gw, configGW_ADDR0, configGW_ADDR1, configGW_ADDR2, configGW_ADDR3);
    netif_add(&fsl_netif0, &fsl_netif0_ipaddr, &fsl_netif0_netmask, &fsl_netif0_gw, NULL, ethernetif_init, tcpip_input);
    netif_set_default(&fsl_netif0);

    LWIP_PLATFORM_DIAG(("\r\n************************************************"));
    LWIP_PLATFORM_DIAG((" UDP Echo example"));
    LWIP_PLATFORM_DIAG(("************************************************"));
    LWIP_PLATFORM_DIAG((" IPv4 Address     : %u.%u.%u.%u", ((u8_t *)&fsl_netif0_ipaddr)[0],
                        ((u8_t *)&fsl_netif0_ipaddr)[1], ((u8_t *)&fsl_netif0_ipaddr)[2],
                        ((u8_t *)&fsl_netif0_ipaddr)[3]));
    LWIP_PLATFORM_DIAG((" IPv4 Subnet mask : %u.%u.%u.%u", ((u8_t *)&fsl_netif0_netmask)[0],
                        ((u8_t *)&fsl_netif0_netmask)[1], ((u8_t *)&fsl_netif0_netmask)[2],
                        ((u8_t *)&fsl_netif0_netmask)[3]));
    LWIP_PLATFORM_DIAG((" IPv4 Gateway     : %u.%u.%u.%u", ((u8_t *)&fsl_netif0_gw)[0], ((u8_t *)&fsl_netif0_gw)[1],
                        ((u8_t *)&fsl_netif0_gw)[2], ((u8_t *)&fsl_netif0_gw)[3]));
    LWIP_PLATFORM_DIAG(("************************************************"));

    udp_echo_init();
    /* should not reach this statement */
    for (;;)
        ;
}
Example #12
0
static void
lwip_sanity_check(void)
{
  /* Warnings */
#if LWIP_NETCONN
  if (MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB))
    LWIP_PLATFORM_DIAG(("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\n"));
#endif /* LWIP_NETCONN */
#if LWIP_TCP
  if (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN\n"));
  if (TCP_SND_BUF < 2 * TCP_MSS)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly\n"));
  if (TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF/TCP_MSS)))
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work\n"));
  if (TCP_SNDLOWAT > TCP_SND_BUF)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than or equal to TCP_SND_BUF.\n"));
  if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE))
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n"));
  if (TCP_WND < TCP_MSS)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
#endif /* LWIP_TCP */
}
Example #13
0
void
stats_display_proto(struct stats_proto *proto, char *name)
{
  LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", proto->xmit)); 
  LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", proto->recv)); 
  LWIP_PLATFORM_DIAG(("fw: %"STAT_COUNTER_F"\n\t", proto->fw)); 
  LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", proto->drop)); 
  LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", proto->chkerr)); 
  LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", proto->lenerr)); 
  LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", proto->memerr)); 
  LWIP_PLATFORM_DIAG(("rterr: %"STAT_COUNTER_F"\n\t", proto->rterr)); 
  LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", proto->proterr)); 
  LWIP_PLATFORM_DIAG(("opterr: %"STAT_COUNTER_F"\n\t", proto->opterr)); 
  LWIP_PLATFORM_DIAG(("err: %"STAT_COUNTER_F"\n\t", proto->err)); 
  LWIP_PLATFORM_DIAG(("cachehit: %"STAT_COUNTER_F"\n", proto->cachehit)); 
}
Example #14
0
static void
lwip_sanity_check(void)
{
  /* Warnings */
#if LWIP_NETCONN
  if (MEMP_NUM_NETCONN > (MEMP_NUM_TCP_PCB+MEMP_NUM_TCP_PCB_LISTEN+MEMP_NUM_UDP_PCB+MEMP_NUM_RAW_PCB))
    LWIP_PLATFORM_DIAG(("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\n"));
#endif /* LWIP_NETCONN */
#if LWIP_TCP
  if (MEMP_NUM_TCP_SEG < TCP_SND_QUEUELEN)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: MEMP_NUM_TCP_SEG should be at least as big as TCP_SND_QUEUELEN\n"));
  if (TCP_SND_BUF < 2 * TCP_MSS)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_BUF must be at least as much as (2 * TCP_MSS) for things to work smoothly\n"));
  if (TCP_SND_QUEUELEN < (2 * (TCP_SND_BUF/TCP_MSS)))
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SND_QUEUELEN must be at least as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work\n"));
  if (TCP_SNDLOWAT >= TCP_SND_BUF)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDLOWAT must be less than TCP_SND_BUF.\n"));
  if (TCP_SNDQUEUELOWAT >= TCP_SND_QUEUELEN)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_SNDQUEUELOWAT must be less than TCP_SND_QUEUELEN.\n"));
  if (TCP_WND > (PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE))
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is larger than space provided by PBUF_POOL_SIZE*PBUF_POOL_BUFSIZE\n"));
  if (TCP_WND < TCP_MSS)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: TCP_WND is smaller than MSS\n"));
#endif /* LWIP_TCP */
#if LWIP_SOCKET
  /* Check that the SO_* socket options and SOF_* lwIP-internal flags match */
  if (SO_ACCEPTCONN != SOF_ACCEPTCONN)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_ACCEPTCONN != SOF_ACCEPTCONN\n"));
  if (SO_REUSEADDR != SOF_REUSEADDR)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_REUSEADDR != SOF_REUSEADDR\n"));
  if (SO_KEEPALIVE != SOF_KEEPALIVE)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_KEEPALIVE != SOF_KEEPALIVE\n"));
  if (SO_BROADCAST != SOF_BROADCAST)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_BROADCAST != SOF_BROADCAST\n"));
  if (SO_LINGER != SOF_LINGER)
    LWIP_PLATFORM_DIAG(("lwip_sanity_check: WARNING: SO_LINGER != SOF_LINGER\n"));
#endif /* LWIP_SOCKET */
}
Example #15
0
void
stats_display_igmp(struct stats_igmp *igmp, const char *name)
{
  LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
  LWIP_PLATFORM_DIAG(("xmit: %"STAT_COUNTER_F"\n\t", igmp->xmit));
  LWIP_PLATFORM_DIAG(("recv: %"STAT_COUNTER_F"\n\t", igmp->recv));
  LWIP_PLATFORM_DIAG(("drop: %"STAT_COUNTER_F"\n\t", igmp->drop));
  LWIP_PLATFORM_DIAG(("chkerr: %"STAT_COUNTER_F"\n\t", igmp->chkerr));
  LWIP_PLATFORM_DIAG(("lenerr: %"STAT_COUNTER_F"\n\t", igmp->lenerr));
  LWIP_PLATFORM_DIAG(("memerr: %"STAT_COUNTER_F"\n\t", igmp->memerr));
  LWIP_PLATFORM_DIAG(("proterr: %"STAT_COUNTER_F"\n\t", igmp->proterr));
  LWIP_PLATFORM_DIAG(("rx_v1: %"STAT_COUNTER_F"\n\t", igmp->rx_v1));
  LWIP_PLATFORM_DIAG(("rx_group: %"STAT_COUNTER_F"\n\t", igmp->rx_group));
  LWIP_PLATFORM_DIAG(("rx_general: %"STAT_COUNTER_F"\n\t", igmp->rx_general));
  LWIP_PLATFORM_DIAG(("rx_report: %"STAT_COUNTER_F"\n\t", igmp->rx_report));
  LWIP_PLATFORM_DIAG(("tx_join: %"STAT_COUNTER_F"\n\t", igmp->tx_join));
  LWIP_PLATFORM_DIAG(("tx_leave: %"STAT_COUNTER_F"\n\t", igmp->tx_leave));
  LWIP_PLATFORM_DIAG(("tx_report: %"STAT_COUNTER_F"\n\t", igmp->tx_report));
}
Example #16
0
VOID stats_display_proto(struct stats_proto *proto, INT8 *name)
{
#if 0
	LWIP_PLATFORM_DIAG(("\n%s\n\t", name));
	LWIP_PLATFORM_DIAG(("xmit: 0x%x\n\t", proto->xmit));
	LWIP_PLATFORM_DIAG(("rexmit: 0x%x\n\t", proto->rexmit));
	LWIP_PLATFORM_DIAG(("recv: 0x%x\n\t", proto->recv));
	LWIP_PLATFORM_DIAG(("fw: 0x%x\n\t", proto->fw));
	LWIP_PLATFORM_DIAG(("drop: 0x%x\n\t", proto->drop));
	LWIP_PLATFORM_DIAG(("chkerr: 0x%x\n\t", proto->chkerr));
	LWIP_PLATFORM_DIAG(("lenerr: 0x%x\n\t", proto->lenerr));
	LWIP_PLATFORM_DIAG(("memerr: 0x%x\n\t", proto->memerr));
	LWIP_PLATFORM_DIAG(("rterr: 0x%x\n\t", proto->rterr));
	LWIP_PLATFORM_DIAG(("proterr: 0x%x\n\t", proto->proterr));
	LWIP_PLATFORM_DIAG(("opterr: 0x%x\n\t", proto->opterr));
	LWIP_PLATFORM_DIAG(("err: 0x%x\n\t", proto->err));
	LWIP_PLATFORM_DIAG(("cachehit: 0x%x\n", proto->cachehit));
#endif	
}