예제 #1
0
/* -----------------------------------------------------------------------------
 *
 * -------------------------------------------------------------------------- */
static void uip_xtcpd_handle_poll(xtcpd_state_t *s)
{
 if (s->s.ack_request) {
   uip_flags |= UIP_NEWDATA;
   uip_slen = 0;
   s->s.ack_request = 0;
 }

  if (s->s.abort_request) {
    /* ----------------------------------- */
    if (uip_udpconnection()) {
      uip_udp_conn->lport = 0;
      xtcpd_event(XTCP_CLOSED, s);
    } else {
      uip_abort();
    }
    s->s.abort_request = 0;
  } else if (s->s.close_request) {
    /* ----------------------------------- */
    if (uip_udpconnection()) {
      uip_udp_conn->lport = 0;
      xtcpd_event(XTCP_CLOSED, s);
    }
    else
      uip_close();
    s->s.close_request = 0;
  } else if (s->s.connect_request) {
      /* ----------------------------------- */
      if (uip_udpconnection()) {
      init_xtcpd_state(s,
                       XTCP_PROTOCOL_UDP,
                       *((xtcp_ipaddr_t *) (&uip_udp_conn->ripaddr)),
                       uip_udp_conn->lport,
                       uip_udp_conn->rport,
                       uip_udp_conn);
      xtcpd_event(XTCP_NEW_CONNECTION, s);
      s->s.connect_request = 0;
    }
  } else if (s->s.send_request) {
     /* ----------------------------------- */
    int len;
    if (s->linknum != -1) {
      len = do_xtcpd_send(xtcp_cons.links[s->linknum],
                       XTCP_REQUEST_DATA,
                       s,
                       uip_appdata,
                       uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
      uip_send(uip_appdata, len);
    }
    s->s.send_request--;
  } else if (s->s.poll_interval != 0 &&
           timer_expired(&(s->s.tmr))){
    /* ----------------------------------- */
    xtcpd_event(XTCP_POLL, s);
    timer_set(&(s->s.tmr), s->s.poll_interval);
  }
}
예제 #2
0
파일: uip_xtcp.c 프로젝트: aritec/sc_xtcp
void uip_xtcpd_handle_poll(xtcpd_state_t *s)
{
    if (s->s.abort_request) {
        if (uip_udpconnection()) {
            uip_udp_conn->lport = 0;
            xtcpd_event(XTCP_CLOSED, s);
        }
        else
            uip_abort();
        s->s.abort_request = 0;
    }
    else if (s->s.close_request) {
        if (uip_udpconnection()) {
            uip_udp_conn->lport = 0;
            xtcpd_event(XTCP_CLOSED, s);
        }
        else
            uip_close();
        s->s.close_request = 0;
    }
    else if (s->s.connect_request) {
        if (uip_udpconnection()) {
            xtcpd_init_state(s,
                             XTCP_PROTOCOL_UDP,
                             (unsigned char *) uip_udp_conn->ripaddr,
                             uip_udp_conn->lport,
                             uip_udp_conn->rport,
                             uip_udp_conn);
            xtcpd_event(XTCP_NEW_CONNECTION, s);
            s->s.connect_request = 0;
        }
    }
    else if (s->s.send_request) {
        int len;
        if (s->linknum != -1) {
            xtcpd_service_clients_until_ready(s->linknum, xtcp_links, xtcp_num);
            len = xtcpd_send(xtcp_links[s->linknum],
                             XTCP_REQUEST_DATA,
                             s,
                             uip_appdata,
                             uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
            uip_send(uip_appdata, len);
        }
        s->s.send_request--;
    }
    else if (s->s.poll_interval != 0 &&
             timer_expired(&(s->s.tmr)))
    {
        xtcpd_event(XTCP_POLL, s);
        timer_set(&(s->s.tmr), s->s.poll_interval);
    }
}
예제 #3
0
/*---------------------------------------------------------------------*/
static void
uipcall(void *state)
{
  if(uip_udpconnection()) {
    recv_udpthread(&s.recv_udpthread_pt);
    send_udpthread(&s.udpthread_pt);
  } else {
    if(uip_conn->lport == HTONS(CODEPROP_DATA_PORT)) {
      if(uip_connected()) {

	if(state == NULL) {
	  s.addr = 0;
	  s.count = 0;
	  PT_INIT(&s.tcpthread_pt);
	  process_poll(&codeprop_process);
	  tcp_markconn(uip_conn, &s);
/* 	  process_post(PROCESS_BROADCAST, codeprop_event_quit, */
/* 		       (process_data_t)NULL); */
	} else {
	  PRINTF(("codeprop: uip_connected() and state != NULL\n"));
	  uip_abort();
	}
      }
      recv_tcpthread(&s.tcpthread_pt);


      if(uip_closed() || uip_aborted() || uip_timedout()) {
	PRINTF(("codeprop: connection down\n"));
	tcp_markconn(uip_conn, NULL);
      }
    }
  }
}
예제 #4
0
void xtcp_process_incoming_packet(chanend mac_tx)
{
	if (BUF->type == htons(UIP_ETHTYPE_IP)) {
		uip_arp_ipin();
		uip_input();
		if (uip_len > 0) {
			if (uip_udpconnection()
				&& (TCPBUF->proto != UIP_PROTO_ICMP)
				&& (TCPBUF->proto != UIP_PROTO_IGMP))
				uip_arp_out( uip_udp_conn);
			else
				uip_arp_out( NULL);
			xtcp_tx_buffer(mac_tx);
		}
	} else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
		uip_arp_arpin();

		if (uip_len > 0) {
			xtcp_tx_buffer(mac_tx);
		}
		for (int i = 0; i < UIP_UDP_CONNS; i++) {
			uip_udp_arp_event(i);
			if (uip_len > 0) {
				uip_arp_out(&uip_udp_conns[i]);
				xtcp_tx_buffer(mac_tx);
			}
		}
	}
}
예제 #5
0
smcp_status_t
smcp_plat_process(smcp_t self) {
	SMCP_EMBEDDED_SELF_HOOK;

	if (!uip_udpconnection()) {
		goto bail;
	}

	if (uip_udp_conn != smcp_plat_get_udp_conn(smcp)) {
		goto bail;
	}

	if(uip_newdata()) {
		memcpy(&self->plat.sockaddr_remote.smcp_addr,&UIP_IP_BUF->srcipaddr,sizeof(smcp_addr_t));
		self->plat.sockaddr_remote.smcp_port = UIP_UDP_BUF->srcport;

		memcpy(&self->plat.sockaddr_local.smcp_addr,&UIP_IP_BUF->destipaddr,sizeof(smcp_addr_t));
		self->plat.sockaddr_local.smcp_port = UIP_UDP_BUF->destport;

		smcp_plat_set_session_type(SMCP_SESSION_TYPE_UDP);

		smcp_inbound_packet_process(smcp, uip_appdata, uip_datalen(), 0);
	} else if(uip_poll()) {
		smcp_set_current_instance(self);
		smcp_handle_timers(self);
	}

bail:
	smcp_set_current_instance(NULL);
	self->is_responding = false;

	return 0;
}
예제 #6
0
/* -----------------------------------------------------------------------------
 *
 * -------------------------------------------------------------------------- */
static int do_xtcpd_send(chanend c,
                  xtcp_event_type_t event,
                  xtcpd_state_t *s,
                  unsigned char data[],
                  int mss)
{
  int len;
#ifdef XTCP_ENABLE_PARTIAL_PACKET_ACK
  int outstanding=0;
  if (!uip_udpconnection()) {
    if (!s->s.accepts_partial_ack && uip_conn->len > 1)
      return 0;

    outstanding = uip_conn->len;
    if (outstanding == 1)
      outstanding = 0;
    s->conn.outstanding = outstanding;

  }
#endif

  xtcpd_service_clients_until_ready(s->linknum, xtcp_cons.links, xtcp_cons.nr);
  len = xtcpd_send(c,event,s,data,mss);

#ifdef XTCP_ENABLE_PARTIAL_PACKET_ACK
  if (!uip_udpconnection()) {
    if (outstanding != 0 &&
        len > outstanding) {
      len = len - outstanding;
      memmove((char *) uip_appdata,
              &((char *)uip_appdata)[outstanding],
              len);
    }
    else if (outstanding > 0) {
      len = 0;
    }
  }
#endif
  return len;
}
예제 #7
0
/* -----------------------------------------------------------------------------
 * \brief      Deliver an incoming packet to the TCP/IP stack
 *
 *             This function is called by theServer to
 *             deliver an incoming packet to the TCP/IP stack. The
 *             incoming packet must be present in the uip_buf buffer,
 *             and the length of the packet must be in the global
 *             uip_len variable.
 * -------------------------------------------------------------------------- */
void xtcpip_input(chanend mac_tx)
{
/*_______________*/
#if UIP_CONF_IPV4 /* ORIGINAL_XMOS */
	if (BUF->type == htons(UIP_ETHTYPE_IP)) {
		uip_arp_ipin();
		uip_input();
		if (uip_len > 0) {
			if (uip_udpconnection()
				&& (TCPBUF->proto != UIP_PROTO_ICMP)
				&& (TCPBUF->proto != UIP_PROTO_IGMP))
				uip_arp_out( uip_udp_conn);
			else
				uip_arp_out( NULL);
			xtcp_tx_buffer(mac_tx);
		}
	} else if (BUF->type == htons(UIP_ETHTYPE_ARP)) {
		uip_arp_arpin();

		if (uip_len > 0) {
			xtcp_tx_buffer(mac_tx);
		}
		for (int i = 0; i < UIP_UDP_CONNS; i++) {
			uip_udp_arp_event(i);
			if (uip_len > 0) {
				uip_arp_out(&uip_udp_conns[i]);
				xtcp_tx_buffer(mac_tx);
			}
		}
	}
#endif /* UIP_CONF_IPV4 ORIGINAL_XMOS */
/*_______________*/
	/* contiki tcpip.c */
#if UIP_CONF_IP_FORWARD
  if(uip_len > 0) {
    tcpip_is_forwarding = 1;
    if(uip_fw_forward() == UIP_FW_LOCAL) {
      tcpip_is_forwarding = 0;
      check_for_tcp_syn();
      uip_input();
      if(uip_len > 0) {
#if UIP_CONF_TCP_SPLIT
        uip_split_output(mac_tx);
#else /* UIP_CONF_TCP_SPLIT */
#if UIP_CONF_IPV6
        xtcpip_ipv6_output(mac_tx);
#else
	PRINTF("tcpip packet_input forward output len %d\n", uip_len);
        xtcpip_output(mac_tx);
#endif
#endif /* UIP_CONF_TCP_SPLIT */
      }
    }
    tcpip_is_forwarding = 0;
  }
#else /* UIP_CONF_IP_FORWARD */
  if(uip_len > 0) {
    uip_input();
    if(uip_len > 0) {
#if UIP_CONF_TCP_SPLIT
      uip_split_output(mac_tx);
#else /* UIP_CONF_TCP_SPLIT */
#if UIP_CONF_IPV6
      xtcpip_ipv6_output(mac_tx);
#else
      PRINTF("tcpip packet_input output len %d\n", uip_len);
      tcpip_output();
#endif
#endif /* UIP_CONF_TCP_SPLIT */
    }
  }
#endif /* UIP_CONF_IP_FORWARD */
}
예제 #8
0
/* -----------------------------------------------------------------------------
 * xtcpd_appcall
 *
 * this function is called, when a package comes in for an upper layer
 * application.
 * -------------------------------------------------------------------------- */
void
xtcpd_appcall(void)
{
  xtcpd_state_t *s;

  /* --------------- DHCP (v4)  --------------- */
  if (uip_udpconnection() &&
      (uip_udp_conn->lport == HTONS(DHCPC_CLIENT_PORT) ||
       uip_udp_conn->lport == HTONS(DHCPC_SERVER_PORT))) {
#if UIP_USE_DHCP
    dhcpc_appcall();
#endif
    return;
  }

  /* --------- set up a new connection  ---------- */
  if (uip_udpconnection()){
    s = (xtcpd_state_t *) &(uip_udp_conn->appstate);
    if (uip_newdata()) {
    	// Set remote port to upper layer state
      s->conn.remote_port = HTONS(UDPBUF->srcport);
      uip_ipaddr_copy(s->conn.remote_addr.u8, BUF->srcipaddr.u8);
    }
  } else if (uip_conn == NULL) {
      // dodgy uip_conn
      return;
  } else {
    s = (xtcpd_state_t *) &(uip_conn->appstate);
  }

  /* ------ passing new connection event up to the upper xtcp layer  ---- */
  if (uip_connected()) {
    if (!uip_udpconnection()) {
      init_xtcpd_state(s,
                       XTCP_PROTOCOL_TCP,
                       *((xtcp_ipaddr_t *) (&uip_conn->ripaddr)),
                       uip_conn->lport,
                       uip_conn->rport,
                       uip_conn);
      xtcpd_event(XTCP_NEW_CONNECTION, s);
    } else {
      init_xtcpd_state(s,
                       XTCP_PROTOCOL_UDP,
                       *((xtcp_ipaddr_t *) (&uip_udp_conn->ripaddr)),
                       uip_udp_conn->lport,
                       uip_udp_conn->rport,
                       uip_udp_conn);
      xtcpd_event(XTCP_NEW_CONNECTION, s);
    }
  }

  /* --------------- new data event to deliver  --------------- */
  if (uip_newdata() && uip_len > 0) {
    if (s->linknum != -1) {
      xtcpd_service_clients_until_ready(s->linknum, xtcp_cons.links, xtcp_cons.nr);
      xtcpd_recv(xtcp_cons.links, s->linknum, xtcp_cons.nr,
                 s,
                 uip_appdata,
                 uip_datalen());
      if (!uip_udpconnection() && s->s.ack_recv_mode) {
        uip_stop();
      }
    }
  } else if (uip_aborted()) {
    xtcpd_event(XTCP_ABORTED, s);
    return;
  } else if (uip_timedout()) {
    xtcpd_event(XTCP_TIMED_OUT, s);
    return;
  }

  /* ------------ passing acknowleg event to upper layer  ------------- */
  if (uip_acked()) {
    int len;
    if (s->linknum != -1) {
      len =
        do_xtcpd_send(xtcp_cons.links[s->linknum],
                      XTCP_SENT_DATA,
                      s,
                      uip_appdata,
                      uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());

      uip_send(uip_appdata, len);
    }
  }

  /* -------------- retransmit the last package  -------------- */
  if (uip_rexmit()) {
    int len;
    if (s->linknum != -1) {
      xtcpd_service_clients_until_ready(s->linknum, xtcp_cons.links, xtcp_cons.nr);
#ifdef XTCP_ENABLE_PARTIAL_PACKET_ACK
      s->conn.outstanding = 0;
#endif
      len = xtcpd_send(xtcp_cons.links[s->linknum],
                       XTCP_RESEND_DATA,
                       s,
                       uip_appdata,
                       uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
      if (len != 0)
        uip_send(uip_appdata, len);
    }
  }

  /* --------------- poll a connection --------------- */
  if (uip_poll()) {
    uip_xtcpd_handle_poll(s);
  }

#if XTCP_ENABLE_PUSH_FLAG_NOTIFICATION
  if (uip_tcp_push()) {
    xtcpd_event(XTCP_PUSH_DATA, s);
  }
#endif

  /* ------------- connection close event  ------------ */
  if (uip_closed()) {
    if (!s->s.closed){
      s->s.closed = 1;

      xtcpd_event(XTCP_CLOSED, s);
    }
    return;
  }

}
예제 #9
0
파일: uip_xtcp.c 프로젝트: aritec/sc_xtcp
void
xtcpd_appcall(void)
{
    xtcpd_state_t *s;

    if (uip_udpconnection() &&
            (uip_udp_conn->lport == HTONS(DHCPC_CLIENT_PORT) ||
             uip_udp_conn->lport == HTONS(DHCPC_SERVER_PORT))) {
#if UIP_USE_DHCP
        dhcpc_appcall();
#endif
        return;
    }

    if (uip_udpconnection()) {
        s = (xtcpd_state_t *) &(uip_udp_conn->appstate);
        if (uip_newdata()) {
            s->conn.remote_port = HTONS(UDPBUF->srcport);
            uip_ipaddr_copy(s->conn.remote_addr, BUF->srcipaddr);
        }
    }
    else if (uip_conn == NULL) {
        // dodgy uip_conn
        return;
    }
    else
        s = (xtcpd_state_t *) &(uip_conn->appstate);




    //  if (!uip_udpconnection() && uip_connected()) {
    if (uip_connected()) {
        if (!uip_udpconnection()) {
            xtcpd_init_state(s,
                             XTCP_PROTOCOL_TCP,
                             (unsigned char *) uip_conn->ripaddr,
                             uip_conn->lport,
                             uip_conn->rport,
                             uip_conn);
            xtcpd_event(XTCP_NEW_CONNECTION, s);
        }
        else {
            xtcpd_init_state(s,
                             XTCP_PROTOCOL_UDP,
                             (unsigned char *) uip_udp_conn->ripaddr,
                             uip_udp_conn->lport,
                             uip_udp_conn->rport,
                             uip_udp_conn);
            xtcpd_event(XTCP_NEW_CONNECTION, s);

        }
    }

    if (uip_acked()) {
        int len;
        if (s->linknum != -1) {
            xtcpd_service_clients_until_ready(s->linknum, xtcp_links, xtcp_num);
            len = xtcpd_send(xtcp_links[s->linknum],
                             XTCP_SENT_DATA,
                             s,
                             uip_appdata,
                             uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
            if (len != 0)
                uip_send(uip_appdata, len);
        }
    }


    if (uip_newdata() && uip_len > 0) {
        if (s->linknum != -1) {
            if (!uip_udpconnection() && s->s.ack_recv_mode) {
                uip_stop();
            }
            xtcpd_service_clients_until_ready(s->linknum, xtcp_links, xtcp_num);

            xtcpd_recv(xtcp_links, s->linknum, xtcp_num,
                       s,
                       uip_appdata,
                       uip_datalen());
        }

    }

    else if (uip_aborted()) {
        xtcpd_event(XTCP_ABORTED, s);
        return;
    }
    else if (uip_timedout()) {
        xtcpd_event(XTCP_TIMED_OUT, s);
        return;
    }

    if (uip_rexmit()) {
        int len;
        if (s->linknum != -1) {
            xtcpd_service_clients_until_ready(s->linknum, xtcp_links, xtcp_num);
            len = xtcpd_send(xtcp_links[s->linknum],
                             XTCP_RESEND_DATA,
                             s,
                             uip_appdata,
                             uip_udpconnection() ? XTCP_CLIENT_BUF_SIZE : uip_mss());
            if (len != 0)
                uip_send(uip_appdata, len);
        }
    }

    if (uip_poll()) {
        uip_xtcpd_handle_poll(s);
    }

    if (uip_closed()) {
        if (!s->s.closed) {
            s->s.closed = 1;

            xtcpd_event(XTCP_CLOSED, s);
        }
        return;
    }

}