// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
int
UIPUDP::endPacket()
{
  if (_uip_udp_conn && appdata.packet_out != NOBLOCK)
    {
      appdata.send = true;
      Enc28J60Network::resizeBlock(appdata.packet_out,0,appdata.out_pos);
      uip_udp_periodic_conn(_uip_udp_conn);
      if (uip_len > 0)
        {
          _send(&appdata);
          return 1;
        }
    }
  return 0;
}
예제 #2
0
파일: UIPUdp.cpp 프로젝트: 12019/libraries
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
int
UIPUDP::endPacket()
{
  if (_uip_udp_conn && appdata.packet_out != NOBLOCK)
    {
      appdata.send = true;
      UIPEthernet.network.resizeBlock(appdata.packet_out,0,appdata.out_pos);
      uip_udp_periodic_conn(_uip_udp_conn);
      if (uip_len > 0)
        {
          UIPEthernet.network_send();
          return 1;
        }
    }
  return 0;
}
예제 #3
0
/*
 *  Initialize network communication
 */
void
rc5_net_init(void)
{
  /* retrieve IP address from configure script */
  set_CONF_RC5_SERVER(&addr);

  /* init an UDP connection */
  udpconn = uip_udp_new(&addr, HTONS(RC5_UDPPORT), rc5_udp_recv);
  if (udpconn != NULL)
  {
    uip_udp_periodic_conn(udpconn);
    uip_udp_bind(udpconn, HTONS(RC5_UDPPORT));
#ifdef DEBUG_RC5
    debug_printf("RC5: UDP enabled!\n");
#endif
  }
  else
  {
#ifdef DEBUG_RC5
    debug_printf("RC5: UDP not enabled!\n");
#endif
  }
}
예제 #4
0
파일: tcpip.c 프로젝트: kenog/contiki-inga
/*---------------------------------------------------------------------------*/
static void
eventhandler(process_event_t ev, process_data_t data)
{
#if UIP_TCP
    static unsigned char i;
    register struct listenport *l;
#endif /*UIP_TCP*/
    struct process *p;

    switch(ev) {
    case PROCESS_EVENT_EXITED:
        /* This is the event we get if a process has exited. We go through
           the TCP/IP tables to see if this process had any open
           connections or listening TCP ports. If so, we'll close those
           connections. */

        p = (struct process *)data;
#if UIP_TCP
        l = s.listenports;
        for(i = 0; i < UIP_LISTENPORTS; ++i) {
            if(l->p == p) {
                uip_unlisten(l->port);
                l->port = 0;
                l->p = PROCESS_NONE;
            }
            ++l;
        }

        {
            struct uip_conn *cptr;

            for(cptr = &uip_conns[0]; cptr < &uip_conns[UIP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->appstate.p = PROCESS_NONE;
                    cptr->tcpstateflags = UIP_CLOSED;
                }
            }
        }
#endif /* UIP_TCP */
#if UIP_UDP
        {
            struct uip_udp_conn *cptr;

            for(cptr = &uip_udp_conns[0];
                    cptr < &uip_udp_conns[UIP_UDP_CONNS]; ++cptr) {
                if(cptr->appstate.p == p) {
                    cptr->lport = 0;
                }
            }
        }
#endif /* UIP_UDP */
        break;

    case PROCESS_EVENT_TIMER:
        /* We get this event if one of our timers have expired. */
    {
        /* Check the clock so see if we should call the periodic uIP
           processing. */
        if(data == &periodic &&
                etimer_expired(&periodic)) {
#if UIP_TCP
            for(i = 0; i < UIP_CONNS; ++i) {
                if(uip_conn_active(i)) {
                    /* Only restart the timer if there are active
                       connections. */
                    etimer_restart(&periodic);
                    uip_periodic(i);
#if UIP_CONF_IPV6
                    tcpip_ipv6_output();
#else
                    if(uip_len > 0) {
                        PRINTF("tcpip_output from periodic len %d\n", uip_len);
                        tcpip_output();
                        PRINTF("tcpip_output after periodic len %d\n", uip_len);
                    }
#endif /* UIP_CONF_IPV6 */
                }
            }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
            uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
        }

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(data == &uip_reass_timer &&
                etimer_expired(&uip_reass_timer)) {
            uip_reass_over();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(data == &uip_ds6_timer_rs &&
                etimer_expired(&uip_ds6_timer_rs)) {
            uip_ds6_send_rs();
            tcpip_ipv6_output();
        }
#endif /* !UIP_CONF_ROUTER */
        if(data == &uip_ds6_timer_periodic &&
                etimer_expired(&uip_ds6_timer_periodic)) {
            uip_ds6_periodic();
            tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6 */
    }
    break;

#if UIP_TCP
    case TCP_POLL:
        if(data != NULL) {
            uip_poll_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else /* UIP_CONF_IPV6 */
            if(uip_len > 0) {
                PRINTF("tcpip_output from tcp poll len %d\n", uip_len);
                tcpip_output();
            }
#endif /* UIP_CONF_IPV6 */
            /* Start the periodic polling, if it isn't already active. */
            start_periodic_tcp_timer();
        }
        break;
#endif /* UIP_TCP */
#if UIP_UDP
    case UDP_POLL:
        if(data != NULL) {
            uip_udp_periodic_conn(data);
#if UIP_CONF_IPV6
            tcpip_ipv6_output();
#else
            if(uip_len > 0) {
                tcpip_output();
            }
#endif /* UIP_UDP */
        }
        break;
#endif /* UIP_UDP */

    case PACKET_INPUT:
        packet_input();
        break;
    };
}
예제 #5
0
파일: tcpip.c 프로젝트: kamejoko80/emb6
/*---------------------------------------------------------------------------*/
static void
eventhandler(c_event_t ev, p_data_t data)
{
#if UIP_TCP
  static unsigned char i;
//  register struct listenport *l;
#endif /*UIP_TCP*/

  switch(ev) {
    case EVENT_TYPE_TIMER_EXP:
      /* We get this event if one of our timers have expired. */
      {
        /* Check the clock so see if we should call the periodic uIP
           processing. */
        if(data == &periodic &&
           etimer_expired(&periodic)) {
#if UIP_TCP
          for(i = 0; i < UIP_CONNS; ++i) {
            if(uip_conn_active(i)) {
              /* Only restart the timer if there are active
                 connections. */
              etimer_restart(&periodic);
              uip_periodic(i);
#if NETSTACK_CONF_WITH_IPV6
              tcpip_ipv6_output();
#else
              if(uip_len > 0) {
		PRINTF("tcpip_output from periodic len %d\n\r", uip_len);
                tcpip_output();
		PRINTF("tcpip_output after periodic len %d\n\r", uip_len);
              }
#endif /* NETSTACK_CONF_WITH_IPV6 */
            }
          }
#endif /* UIP_TCP */
#if UIP_CONF_IP_FORWARD
          uip_fw_periodic();
#endif /* UIP_CONF_IP_FORWARD */
        }
        
#if NETSTACK_CONF_WITH_IPV6
#if UIP_CONF_IPV6_REASSEMBLY
        /*
         * check the timer for reassembly
         */
        if(data == &uip_reass_timer &&
           etimer_expired(&uip_reass_timer)) {
          uip_reass_over();
          tcpip_ipv6_output();
        }
#endif /* UIP_CONF_IPV6_REASSEMBLY */
        /*
         * check the different timers for neighbor discovery and
         * stateless autoconfiguration
         */
        /*if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }*/
#if !UIP_CONF_ROUTER
        if(data == &uip_ds6_timer_rs &&
           etimer_expired(&uip_ds6_timer_rs)) {
          uip_ds6_send_rs();
          tcpip_ipv6_output();
        }
#endif /* !UIP_CONF_ROUTER */
        if(data == &uip_ds6_timer_periodic &&
           etimer_expired(&uip_ds6_timer_periodic)) {
          uip_ds6_periodic();
          tcpip_ipv6_output();
        }
#endif /* NETSTACK_CONF_WITH_IPV6 */
      }
      break;
	 
#if UIP_TCP
    case EVENT_TYPE_TCP_POLL:
      if(data != NULL) {
        uip_poll_conn(data);
#if NETSTACK_CONF_WITH_IPV6
        tcpip_ipv6_output();
#else /* NETSTACK_CONF_WITH_IPV6 */
        if(uip_len > 0) {
        	PRINTF("tcpip_output from tcp poll len %d\n\r", uip_len);
        	tcpip_output();
        }
#endif /* NETSTACK_CONF_WITH_IPV6 */
        /* Start the periodic polling, if it isn't already active. */
        start_periodic_tcp_timer();
      }
      break;
#endif /* UIP_TCP */
#if UIP_UDP
    case EVENT_TYPE_UDP_POLL:
      if(data != NULL) {
        uip_udp_periodic_conn(data);
#if NETSTACK_CONF_WITH_IPV6
        tcpip_ipv6_output();
#else
        if(uip_len > 0) {
          tcpip_output();
        }
#endif /* UIP_UDP */
      }
      break;
#endif /* UIP_UDP */

    case EVENT_TYPE_PCK_INPUT:
      packet_input();
      break;
  };
}