Beispiel #1
0
/*---------------------------------------------------------------------------*/
void
uip_udp_packet_send(struct uip_udp_conn *c, const void *data, int len)
{
#if UIP_UDP
  if(data != NULL) {
    uip_udp_conn = c;
    uip_slen = len;
    memcpy(&uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN], data,
           len > UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN?
           UIP_BUFSIZE - UIP_LLH_LEN - UIP_IPUDPH_LEN: len);
    uip_process(UIP_UDP_SEND_CONN);

#if UIP_CONF_IPV6_MULTICAST
  /* Let the multicast engine process the datagram before we send it */
  if(uip_is_addr_mcast_routable(&uip_udp_conn->ripaddr)) {
    UIP_MCAST6.out();
  }
#endif /* UIP_IPV6_MULTICAST */

#if UIP_CONF_IPV6
    tcpip_ipv6_output();
#else
    if(uip_len > 0) {
      tcpip_output();
    }
#endif
  }
  uip_slen = 0;
#endif /* UIP_UDP */
}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
void
uip_ds6_select_src(uip_ipaddr_t *src, uip_ipaddr_t *dst)
{
  uint8_t best = 0;             /* number of bit in common with best match */
  uint8_t n = 0;
  uip_ds6_addr_t *matchaddr = NULL;

  if(!uip_is_addr_link_local(dst) && !uip_is_addr_mcast(dst)) {
    /* find longest match */
    for(locaddr = uip_ds6_if.addr_list;
        locaddr < uip_ds6_if.addr_list + UIP_DS6_ADDR_NB; locaddr++) {
      /* Only preferred global (not link-local) addresses */
      if(locaddr->isused && locaddr->state == ADDR_PREFERRED &&
         !uip_is_addr_link_local(&locaddr->ipaddr)) {
        n = get_match_length(dst, &locaddr->ipaddr);
        if(n >= best) {
          best = n;
          matchaddr = locaddr;
        }
      }
    }
#if UIP_IPV6_MULTICAST
  } else if(uip_is_addr_mcast_routable(dst)) {
    matchaddr = uip_ds6_get_global(ADDR_PREFERRED);
#endif
  } else {
    matchaddr = uip_ds6_get_link_local(ADDR_PREFERRED);
  }

  /* use the :: (unspecified address) as source if no match found */
  if(matchaddr == NULL) {
    uip_create_unspecified(src);
  } else {
    uip_ipaddr_copy(src, &matchaddr->ipaddr);
  }
}
Beispiel #3
0
smcp_status_t
smcp_plat_outbound_finish(smcp_t self,const uint8_t* data_ptr, coap_size_t data_len, int flags)
{
	SMCP_EMBEDDED_SELF_HOOK;
	smcp_status_t ret = SMCP_STATUS_FAILURE;

	assert(uip_udp_conn == self->plat.udp_conn);

	uip_slen = data_len;

	require_action(uip_slen<SMCP_MAX_PACKET_LENGTH, bail, ret = SMCP_STATUS_MESSAGE_TOO_BIG);

	if (data_ptr != uip_sappdata) {
		memmove(
			uip_sappdata,
			data_ptr,
			uip_slen
		);
		data_ptr = (const uint8_t*)uip_sappdata;
	}

#if 0
	// TODO: For some reason this isn't working anymore. Investigate.
	if(self->is_responding) {
		// We are responding, let uIP handle preparing the packet.
	} else
#endif

	{	// Here we explicitly tickle UIP to send the packet.

		// Change the remote IP address temporarily.
		uip_ipaddr_copy(&uip_udp_conn->ripaddr, &self->plat.sockaddr_remote.smcp_addr);
		smcp_get_current_instance()->plat.udp_conn->rport = self->plat.sockaddr_remote.smcp_port;

		uip_process(UIP_UDP_SEND_CONN);

#if UIP_CONF_IPV6_MULTICAST
		/* Let the multicast engine process the datagram before we send it */
		if (uip_is_addr_mcast_routable(&uip_udp_conn->ripaddr)) {
			UIP_MCAST6.out();
		}
#endif /* UIP_IPV6_MULTICAST */

		// TODO: This next part is somewhat contiki-ish. Abstract somehow?
#if UIP_CONF_IPV6
		tcpip_ipv6_output();
#else
		tcpip_output();
#endif

		// Since we just sent out packet, we need to zero out uip_slen
		// to prevent uIP from trying to send out a packet.
		uip_slen = 0;

		// Make our remote address unspecified again, so that we can continue
		// to receive traffic.
		memset(&smcp_get_current_instance()->plat.udp_conn->ripaddr, 0, sizeof(uip_ipaddr_t));
		smcp_get_current_instance()->plat.udp_conn->rport = 0;
	}

	ret = SMCP_STATUS_OK;
bail:
	return ret;
}