void syslog_flush (void) { #ifdef ETHERNET_SUPPORT if (! syslog_conn || uip_check_cache (&syslog_conn->ripaddr)) return; /* ARP cache not ready, don't send request here (would flood, wait for poll event). */ #endif /* ETHERNET_SUPPORT */ uip_slen = 0; uip_appdata = uip_sappdata = uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN; for (uint8_t i = 0; i < SYSLOG_CALLBACKS; i++) if (syslog_callbacks[i].callback != NULL) { syslog_callbacks[i].callback(syslog_callbacks[i].data); syslog_callbacks[i].callback = NULL; break; } if (! uip_slen) return; uip_udp_conn = syslog_conn; uip_process (UIP_UDP_SEND_CONN); router_output (); uip_slen = 0; }
void ntp_send_packet(void) { /* hardcode for LLH len of 14 bytes (i.e. ethernet frame), this is not suitable for tunneling! */ struct ntp_packet *pkt = (void *) &uip_buf[14 + UIP_IPUDPH_LEN]; uip_slen = sizeof(struct ntp_packet); memset(pkt, 0, uip_slen); pkt->li_vn_mode = 0xe3; /* Clock not synchronized, Version 4, Client Mode */ pkt->ppoll = 12; /* About an hour */ pkt->precision = 0xfa; /* 0.015625 seconds */ pkt->rootdelay = HTONL(0x10000); /* 1 second */ pkt->rootdispersion = HTONL(0x10000); /* 1 second */ /* push the packet out ... */ uip_udp_conn = ntp_conn; uip_process(UIP_UDP_SEND_CONN); #ifdef DEBUG_NTP debug_printf("NTP: send packet\n"); #endif router_output(); uip_slen = 0; }
void syslog_flush (void) { /* FIXME: use perhaps router to determine target Stack */ uip_stack_set_active(STACK_ENC); if (syslog_check_cache ()) return; /* ARP cache not ready, don't send request here (would flood, wait for poll event). */ uip_slen = 0; uip_appdata = uip_sappdata = uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN; for (uint8_t i = 0; i < SYSLOG_CALLBACKS; i++) if (syslog_callbacks[i].callback != NULL) { syslog_callbacks[i].callback(syslog_callbacks[i].data); syslog_callbacks[i].callback = NULL; break; } if (! uip_slen) return; uip_udp_conn = syslog_conn; uip_process (UIP_UDP_SEND_CONN); router_output (); uip_slen = 0; }
void uecmd_sender_net_main(void) { if (uip_newdata()) { if(ucallback) { ucallback(uip_appdata, uip_len); } send_data = NULL; } if (send_data) { resend_counter --; if (!resend_counter) { if(ucallback) { ucallback(NULL, 0); } send_data = NULL; return; } uint8_t len = strlen_P(send_data); memcpy_P(uip_appdata, send_data, len); uip_slen = len; /* build a new connection on the stack */ ecmd_conn->rport = HTONS(2701); uip_udp_conn = ecmd_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); } }
/*---------------------------------------------------------------------------*/ 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 */ }
int _kernel_net_uip_recv(desc_t desc_r,desc_t desc_w){ if(desc_r<0 || desc_w<0) return -1; uip_len = g_pf_net_recv_ip_packet(desc_r,uip_buf, sizeof(uip_buf)); if(uip_len > 0) { #if defined(USE_IF_ETHERNET) if(__eth_hdr->type == htons(UIP_ETHTYPE_IP)) { uip_arp_ipin(); uip_process(UIP_DATA); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { uip_arp_out(); g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } } else if(__eth_hdr->type == htons(UIP_ETHTYPE_ARP)) { uip_arp_arpin(); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } } #elif defined(USE_IF_SLIP) uip_process(UIP_DATA); /* If the above function invocation resulted in data that should be sent out on the network, the global variable uip_len is set to a value > 0. */ if(uip_len > 0) { g_pf_net_send_ip_packet(desc_w,uip_buf,uip_len); uip_len=0; } #endif } return 0; }
asmlinkage void sys_uip_periodic_k(unsigned long conn_index) { /* uip_periodic(conn_index); return; */ uip_conn = &uip_conns[conn_index]; spark_uip_flags = UIP_TIMER; uip_process(); }
asmlinkage void sys_uip_udp_periodic_k(unsigned long conn_index) { //#if UIP_UDP // uip_udp_periodic(conn_index); //#endif #if UIP_UDP uip_udp_conn = &uip_udp_conns[conn_index]; spark_uip_flags = UIP_UDP_TIMER; uip_process(); #endif return; }
void udpstella_net_main(void) { if (!uip_newdata ()) return; uip_slen = 0; uint16_t len = uip_len; uint8_t buffer[uip_len]; memcpy(buffer, uip_appdata, uip_len); struct udpstella_packet* packet = (struct udpstella_packet*)buffer; uint8_t* answer = uip_appdata; while (len>=sizeof(struct udpstella_packet)) { if (packet->type == STELLA_GETALL) { answer[0] = 's'; answer[1] = 't'; answer[2] = 'e'; answer[3] = 'l'; answer[4] = 'l'; answer[5] = 'a'; answer[6] = (uint8_t)STELLA_CHANNELS; for (uint8_t c=0;c<STELLA_CHANNELS;++c) { answer[7+c] = stella_brightness[c]; } uip_slen += STELLA_CHANNELS+6; answer += STELLA_CHANNELS+6; } else { stella_setValue(packet->type, packet->channel, packet->value); } packet++; len-=sizeof(struct udpstella_packet); } if (uip_slen == 0) return; /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(UDP_STELLA_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void uecmd_net_main() { if (!uip_newdata()) return; char *p = (char *) uip_appdata; /* This may be 1-2 chars too big in case there is a \r or \n, but it saves us a counting loop */ char cmd[uip_datalen() + 1]; char *dp = cmd; /* Copy over into temporary buffer, remove \r \n if present, add \0 */ while (p < (char *) uip_appdata + uip_datalen()) { if (*p == '\r' || *p == '\n') break; *dp++ = *p++; } *dp = 0; uip_slen = 0; while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN) { int16_t len = ecmd_parse_command(cmd, ((char *) uip_appdata) + uip_slen, (UIP_BUFSIZE - UIP_IPUDPH_LEN) - uip_slen); uint8_t real_len = len; if (!is_ECMD_FINAL(len)) { /* what about the errors ? */ /* convert ECMD_AGAIN back to ECMD_FINAL */ real_len = (uint8_t) ECMD_AGAIN(len); } uip_slen += real_len + 1; ((char *) uip_appdata)[uip_slen - 1] = '\n'; if (real_len == len || len == 0) break; } /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(ECMD_UDP_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
static void artnet_send(const uip_ipaddr_t *dest, uint16_t len) { uip_udp_conn_t artnet_conn; uip_ipaddr_copy(&(artnet_conn.ripaddr), dest); artnet_conn.rport = HTONS(artnet_port); artnet_conn.lport = HTONS(artnet_port); uip_udp_conn = &artnet_conn; uip_slen = len; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
static void artnet_send(uint16_t len) { uip_udp_conn_t artnet_conn; artnet_conn.ripaddr[0] = uip_hostaddr[0] | ~uip_netmask[0]; artnet_conn.ripaddr[1] = uip_hostaddr[1] | ~uip_netmask[1]; artnet_conn.rport = HTONS(artnet_port); artnet_conn.lport = HTONS(artnet_port); uip_udp_conn = &artnet_conn; uip_slen = len; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void uecmd_net_main() { if (!uip_newdata ()) return; char *p = (char *)uip_appdata; /* Add \0 to the data and remove \n from the data */ do { if (*p == '\r' || *p == '\n') { break; } } while ( ++p <= ((char *)uip_appdata + uip_datalen())); /* Parse the Data */ *p = 0; char cmd[p - (char *)uip_appdata]; strncpy(cmd, uip_appdata, p - (char *)uip_appdata + 1); uip_slen = 0; while (uip_slen < UIP_BUFSIZE - UIP_IPUDPH_LEN) { int16_t len = ecmd_parse_command(cmd, ((char *)uip_appdata) + uip_slen, (UIP_BUFSIZE - UIP_IPUDPH_LEN) - uip_slen); uint8_t real_len = len; if (!is_ECMD_FINAL(len)) { /* what about the errors ? */ /* convert ECMD_AGAIN back to ECMD_FINAL */ real_len = (uint8_t) ECMD_AGAIN(len); } uip_slen += real_len + 1; ((char *)uip_appdata)[uip_slen - 1] = '\n'; if (real_len == len || len == 0) break; } /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(ECMD_UDP_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void rfm12_process(void) { uip_len = rfm12_rxfinish(); if (!uip_len) return; #ifdef ROUTER_SUPPORT #ifdef RFM12_RAW_SUPPORT if (rfm12_raw_conn->rport) { /* rfm12 raw capturing active, forward in udp/ip encapsulated form, * thusly don't push to the stack. */ /* FIXME This way we cannot accept rfm12_raw requests from anything * but ethernet. This shalt be improved somewhen. */ uip_stack_set_active(STACK_ENC); memmove(uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN, rfm12_data, uip_len); uip_slen = uip_len; uip_udp_conn = rfm12_raw_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_buf_unlock(); rfm12_rxstart(); return; } #endif /* RFM12_RAW_SUPPORT */ /* uip_input expects the number of bytes including the LLH. */ uip_len = uip_len + RFM12_BRIDGE_OFFSET + RFM12_LLH_LEN; #endif /* not ROUTER_SUPPORT */ rfm12_rxstart(); router_input(STACK_RFM12); if (uip_len == 0) { uip_buf_unlock(); return; /* The stack didn't generate any data * that has to be sent back. */ } /* Application has generated output, send it out. */ router_output(); }
void openvpn_txstart (void) { /* uip_len is shared between both stacks. uip_process (from the inner stack) has set it to the amount of data to be tunnelled (including TCP, etc. headers). */ if (! uip_len) return; /* no data to be sent out. */ openvpn_process_out (); if (! uip_len) return; uip_process (UIP_UDP_SEND_CONN); router_output (); }
void ntp_sendpacket() { if(eth_debug) { DC('n'); DC('s'); ntp_func(0); } if(ntp_conn == 0) return; uip_udp_conn = ntp_conn; fill_packet((ntp_packet_t*)uip_appdata); uip_send(uip_appdata, sizeof(ntp_packet_t)); uip_process(UIP_UDP_SEND_CONN); uip_arp_out(); network_send(); }
void ntp_send_packet(void) { #ifdef DNS_SUPPORT if (++ntp_tries >= 5) { #ifdef DEBUG_NTP debug_printf("NTP ntp_send_packet: re-init after %d unsuccessful tries\n", ntp_tries); #endif ntp_init(); return; } #endif if (ntp_conn == NULL || ntp_conn->ripaddr == NULL) { #ifdef DEBUG_NTP debug_printf("NTP ntp_send_packet: skip send, ntp not initialized\n"); #endif return; } /* LLH len defined in UIP depending on stacks (i.e. 14 for ethernet frame), may be already suitable for tunneling! */ struct ntp_packet *pkt = (void *) &uip_buf[UIP_LLH_LEN + UIP_IPUDPH_LEN]; uip_slen = sizeof(struct ntp_packet); memset(pkt, 0, uip_slen); pkt->li_vn_mode = 0xe3; /* Clock not synchronized, Version 4, Client Mode */ pkt->ppoll = 12; /* About an hour */ pkt->precision = 0xfa; /* 0.015625 seconds */ pkt->rootdelay = HTONL(0x10000); /* 1 second */ pkt->rootdispersion = HTONL(0x10000); /* 1 second */ /* push the packet out ... */ uip_udp_conn = ntp_conn; uip_process(UIP_UDP_SEND_CONN); #ifdef DEBUG_NTP debug_printf("NTP: send packet\n"); #endif router_output(); uip_slen = 0; }
void i2c_slave_core_newdata(void) { struct i2c_slave_request_t *REQ = uip_appdata; uip_udp_conn_t return_conn; //if ( uip_datalen() == 1 && REQ->type == 0) uip_ipaddr_copy(return_conn.ripaddr, BUF->srcipaddr); return_conn.rport = BUF->srcport; return_conn.lport = HTONS(I2C_SLAVE_PORT); uip_send (&STATS, sizeof(struct i2c_slave_connection_state_t)); uip_udp_conn = &return_conn; /* Send immediately */ uip_process(UIP_UDP_SEND_CONN); fill_llh_and_transmit(); uip_slen = 0; SLAVE.kommando = 0; }
/* * Send an UDP packet * * code mostly taken from syslog source */ void rc5_udp_send(void) { if (udpconn == NULL) return; #ifdef ETHERNET_SUPPORT if (uip_check_cache(&udpconn->ripaddr)) return; #endif uip_slen = 0; /* this code is possibly unnecessary - need to be tested * copied from syslog code */ uip_appdata = uip_sappdata = uip_buf + UIP_IPUDPH_LEN + UIP_LLH_LEN; #ifdef RC5_SUPPORT_COUNTERS /* copy counters to udp buffer */ memcpy(uip_appdata, &rc5_global.cnt, sizeof(rc5_global.cnt)); #else /* create udp string */ char str[10]; snprintf(str, 10, "%u;%02u;%02u\n", rc5_global.received_command.toggle_bit, rc5_global.received_command.address, rc5_global.received_command.code); memcpy(uip_appdata, str, strlen(str)); #endif #ifdef RC5_SUPPORT_COUNTERS uip_udp_send(rc5_global.bitcount); #else uip_udp_send(strlen(str)); #endif uip_udp_conn = udpconn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 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_BUFSIZE: len); uip_process(UIP_UDP_SEND_CONN); #if UIP_CONF_IPV6 tcpip_ipv6_output(); #else if(uip_len > 0) { tcpip_output(); } #endif } uip_slen = 0; #endif /* UIP_UDP */ }
static void dc3840_net_main (void) { if (!uip_newdata ()) return; uip_udp_conn_t dc3840_conn; #define BUF ((struct uip_udpip_hdr *) (uip_appdata - UIP_IPUDPH_LEN)) uip_ipaddr_copy(dc3840_conn.ripaddr, BUF->srcipaddr); dc3840_conn.rport = BUF->srcport; dc3840_conn.lport = HTONS(DC3840_PORT); uip_udp_conn = &dc3840_conn; uint16_t offset = atoi (uip_appdata); dc3840_get_data (uip_appdata, offset, 512); uip_slen = 512; uip_process (UIP_UDP_SEND_CONN); router_output (); uip_slen = 0; /* No reply. */ }
void udpio_net_main(void) { if (!uip_newdata ()) return; uip_slen = 0; uint16_t len = uip_len; uint8_t buffer[uip_len]; memcpy(buffer, uip_appdata, uip_len); struct udpio_packet* packet = (struct udpio_packet*)buffer; uint8_t* answer = uip_appdata; while (len>=sizeof(struct udpio_packet)) { /* Get values */ if (packet->port == 255) { answer[0] = 'p'; answer[1] = 'i'; answer[2] = 'n'; answer[3] = 's'; answer[4] = PORTA; answer[5] = PORTB; answer[6] = PORTC; answer[7] = PORTD; uip_slen += 8; answer += 8; } /* Set port to "pins" value */ else if (packet->nstate == 2) { if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, packet->pins); } /* Enables pins */ else if (packet->nstate == 1) { if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, vport[packet->port].read_port(packet->port) | packet->pins); } /* Disables pins */ else if (packet->nstate == 0) { if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, vport[packet->port].read_port(packet->port) & ~(uint8_t)packet->pins); } packet++; len-=sizeof(struct udpio_packet); } if (uip_slen == 0) return; /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(UDP_IO_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void udpio_net_main(void) { uint8_t* answer = uip_appdata; uint8_t i; uip_ipaddr_t nullip; uip_ipaddr(&nullip, 0,0,0,0); if (uip_newdata ()) { // No new data: We will compare pins instead for (i=0;i<ALLOWED_CLIENTS;++i) { if(uip_ipaddr_cmp(&(clients[i].address), &nullip)) continue; // found address of calling client in clients: compare pins now if (vport[clients[i].pinport].read_port(clients[i].pinport) ^ clients[i].last_pin_state) { // update last pin state clients[i].last_pin_state = vport[clients[i].pinport].read_port(clients[i].pinport) & clients[i].pinmask; // send changes answer[0] = 'p'; answer[1] = 'i'; answer[2] = 'n'; answer[3] = 'c'; answer[4] = clients[i].pinport; answer[5] = clients[i].last_pin_state; uip_slen += 6; answer += 6; uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = HTONS(UDP_IO_PORT); // send packages to clients at the udp io module port echo_conn.lport = HTONS(UDP_IO_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; } } // No new data, return now return; } uip_slen = 0; uint16_t len = uip_len; uint8_t buffer[uip_len]; memcpy(buffer, uip_appdata, uip_len); struct udpio_packet* packet = (struct udpio_packet*)buffer; while (len>=sizeof(struct udpio_packet)) { switch(packet->mode) { case udpIOOnlyDisable: if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, vport[packet->port].read_port(packet->port) & ~(uint8_t)packet->pinmask); break; case udpIOOnlyEnable: if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, vport[packet->port].read_port(packet->port) | packet->pinmask); break; case udpIOEnableAndDisable: if (packet->port > IO_HARD_PORTS) break; vport[packet->port].write_port(packet->port, packet->pinmask); break; case udpIOGetAllPortPins: answer[0] = 'p'; answer[1] = 'i'; answer[2] = 'n'; answer[3] = 's'; answer[4] = PORTA; answer[5] = PORTB; answer[6] = PORTC; answer[7] = PORTD; uip_slen += 8; answer += 8; break; case udpIORegisterClientForPortChanges: // look for a not used entry in the array for (;i<ALLOWED_CLIENTS;++i) { if(uip_ipaddr_cmp(&(clients[i].address), nullip)) // found empty entry break; } // override last array entry if no free entry available if (i==ALLOWED_CLIENTS) i = ALLOWED_CLIENTS-1; // create entry with ip adress of the calling client, the ioport to observe, the pinmask and the current port state uip_ipaddr_copy(&(clients[i].address), BUF->srcipaddr); clients[i].pinport = packet->port; clients[i].pinmask = packet->pinmask; clients[i].last_pin_state = vport[packet->port].read_port(packet->port) & clients[i].pinmask; break; case udpIOUnRegisterClientForPortChanges: for (i=0;i<ALLOWED_CLIENTS;++i) { if(uip_ipaddr_cmp(&(clients[i].address), &(BUF->srcipaddr))) // found address of calling client in clients: remove it now uip_ipaddr(&(clients[i].address), 0,0,0,0); } break; default: break; }; packet++; len-=sizeof(struct udpio_packet); } if (uip_slen == 0) return; /* Sent data out */ uip_udp_conn_t echo_conn; uip_ipaddr_copy(echo_conn.ripaddr, BUF->srcipaddr); echo_conn.rport = BUF->srcport; echo_conn.lport = HTONS(UDP_IO_PORT); uip_udp_conn = &echo_conn; uip_process(UIP_UDP_SEND_CONN); router_output(); uip_slen = 0; }
void UIPUDP::uip_callback(uip_udp_appstate_t *s) { if (appdata_t *data = (appdata_t *)s->user) { if (uip_newdata()) { data->rport = ntohs(UDPBUF->srcport); data->ripaddr = ip_addr_uip(UDPBUF->srcipaddr); memhandle *packet = &data->packets_in[0]; uint8_t i = 0; do { if (*packet == NOBLOCK) { *packet = UIPEthernet.network.allocBlock(ntohs(UDPBUF->udplen)-UIP_UDPH_LEN); //if we are unable to allocate memory the packet is dropped. udp doesn't guarantee packet delivery if (*packet != NOBLOCK) { //discard Linklevel and IP and udp-header and any trailing bytes: UIPEthernet.network.copyPacket(*packet,0,UIPEthernet.in_packet,UIP_UDP_PHYH_LEN,UIPEthernet.network.blockSize(*packet)); #ifdef UIPETHERNET_DEBUG_UDP Serial.print("udp, uip_newdata received packet: "); Serial.print(*packet); Serial.print(", slot: "); Serial.print(i); Serial.print(", size: "); Serial.println(UIPEthernet.network.blockSize(*packet)); #endif break; } } packet++; i++; } while (i < UIP_UDP_NUMPACKETS); } if (uip_poll() && data->send) { //set uip_slen (uip private) by calling uip_udp_send #ifdef UIPETHERNET_DEBUG_UDP Serial.print("udp, uip_poll preparing packet to send: "); Serial.print(data->packet_out); Serial.print(", size: "); Serial.println(UIPEthernet.network.blockSize(data->packet_out)); #endif UIPEthernet.uip_packet = data->packet_out; data->packet_out = NOBLOCK; UIPEthernet.uip_hdrlen = UIP_UDP_PHYH_LEN; UIPEthernet.packetstate |= UIPETHERNET_SENDPACKET; uip_udp_send(data->out_pos - (UIP_OUTPACKETOFFSET + UIP_UDP_PHYH_LEN)); uip_process(UIP_UDP_SEND_CONN); //generate udp + ip headers uip_arp_out(); //add arp if (uip_len == UIP_ARPHDRSIZE) { UIPEthernet.packetstate &= ~UIPETHERNET_SENDPACKET; #ifdef UIPETHERNET_DEBUG_UDP Serial.println("udp, uip_poll results in ARP-packet"); #endif } else //arp found ethaddr for ip (otherwise packet is replaced by arp-request) { data->send = false; #ifdef UIPETHERNET_DEBUG_UDP Serial.print("udp, uip_packet to send: "); Serial.println(UIPEthernet.uip_packet); #endif } } } }
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; }