Upgrade UIP-library to latest. Recommend Arduino IDE 1.5.7 when compiling EtherentGateway sketch.

This commit is contained in:
Henrik Ekblad
2014-09-16 22:17:07 +02:00
parent 27885fad9b
commit 26129b06a9
51 changed files with 594 additions and 3805 deletions
+60 -37
View File
@@ -25,6 +25,8 @@
#include "HardwareSerial.h"
#endif
#include "UIPUdp.h"
extern "C"
{
#include "utility/uip-conf.h"
@@ -35,18 +37,24 @@ extern "C"
#define ETH_HDR ((struct uip_eth_hdr *)&uip_buf[0])
memhandle UIPEthernetClass::in_packet(NOBLOCK);
memhandle UIPEthernetClass::uip_packet(NOBLOCK);
uint8_t UIPEthernetClass::uip_hdrlen(0);
uint8_t UIPEthernetClass::packetstate(0);
IPAddress UIPEthernetClass::_dnsServerAddress;
DhcpClass* UIPEthernetClass::_dhcp(NULL);
struct uip_timer UIPEthernetClass::periodic_timer;
// Because uIP isn't encapsulated within a class we have to use global
// variables, so we can only have one TCP/IP stack per program.
UIPEthernetClass::UIPEthernetClass() :
in_packet(NOBLOCK),
uip_packet(NOBLOCK),
uip_hdrlen(0),
packetstate(0),
_dhcp(NULL)
UIPEthernetClass::UIPEthernetClass()
{
}
#if UIP_UDP
int
UIPEthernetClass::begin(const uint8_t* mac)
{
@@ -66,6 +74,7 @@ UIPEthernetClass::begin(const uint8_t* mac)
}
return ret;
}
#endif
void
UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip)
@@ -100,6 +109,7 @@ UIPEthernetClass::begin(const uint8_t* mac, IPAddress ip, IPAddress dns, IPAddre
int UIPEthernetClass::maintain(){
tick();
int rc = DHCP_CHECK_NONE;
#if UIP_UDP
if(_dhcp != NULL){
//we have a pointer to dhcp, use it
rc = _dhcp->checkLease();
@@ -118,6 +128,7 @@ int UIPEthernetClass::maintain(){
}
}
return rc;
#endif
}
IPAddress UIPEthernetClass::localIP()
@@ -154,7 +165,7 @@ UIPEthernetClass::tick()
{
if (in_packet == NOBLOCK)
{
in_packet = network.receivePacket();
in_packet = Enc28J60Network::receivePacket();
#ifdef UIPETHERNET_DEBUG
if (in_packet != NOBLOCK)
{
@@ -166,10 +177,10 @@ UIPEthernetClass::tick()
if (in_packet != NOBLOCK)
{
packetstate = UIPETHERNET_FREEPACKET;
uip_len = network.blockSize(in_packet);
uip_len = Enc28J60Network::blockSize(in_packet);
if (uip_len > 0)
{
network.readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
Enc28J60Network::readPacket(in_packet,0,(uint8_t*)uip_buf,UIP_BUFSIZE);
if (ETH_HDR ->type == HTONS(UIP_ETHTYPE_IP))
{
uip_packet = in_packet;
@@ -204,7 +215,7 @@ UIPEthernetClass::tick()
Serial.print(F("freeing packet: "));
Serial.println(in_packet);
#endif
network.freePacket();
Enc28J60Network::freePacket();
in_packet = NOBLOCK;
}
}
@@ -216,7 +227,7 @@ UIPEthernetClass::tick()
{
uip_periodic(i);
// If the above function invocation resulted in data that
// should be sent out on the network, the global variable
// should be sent out on the Enc28J60Network, the global variable
// uip_len is set to a value > 0.
if (uip_len > 0)
{
@@ -230,11 +241,11 @@ UIPEthernetClass::tick()
{
uip_udp_periodic(i);
// If the above function invocation resulted in data that
// should be sent out on the network, the global variable
// should be sent out on the Enc28J60Network, the global variable
// uip_len is set to a value > 0. */
if (uip_len > 0)
{
network_send();
UIPUDP::_send((uip_udp_userdata_t *)(uip_udp_conns[i].appstate));
}
}
#endif /* UIP_UDP */
@@ -246,41 +257,42 @@ boolean UIPEthernetClass::network_send()
if (packetstate & UIPETHERNET_SENDPACKET)
{
#ifdef UIPETHERNET_DEBUG
Serial.print(F("network_send uip_packet: "));
Serial.print(F("Enc28J60Network_send uip_packet: "));
Serial.print(uip_packet);
Serial.print(F(", hdrlen: "));
Serial.println(uip_hdrlen);
#endif
network.writePacket(uip_packet,0,uip_buf,uip_hdrlen);
Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_hdrlen);
goto sendandfree;
}
uip_packet = network.allocBlock(uip_len);
uip_packet = Enc28J60Network::allocBlock(uip_len);
if (uip_packet != NOBLOCK)
{
#ifdef UIPETHERNET_DEBUG
Serial.print(F("network_send uip_buf (uip_len): "));
Serial.print(F("Enc28J60Network_send uip_buf (uip_len): "));
Serial.print(uip_len);
Serial.print(F(", packet: "));
Serial.println(uip_packet);
#endif
network.writePacket(uip_packet,0,uip_buf,uip_len);
Enc28J60Network::writePacket(uip_packet,0,uip_buf,uip_len);
goto sendandfree;
}
return false;
sendandfree:
network.sendPacket(uip_packet);
network.freeBlock(uip_packet);
Enc28J60Network::sendPacket(uip_packet);
Enc28J60Network::freeBlock(uip_packet);
uip_packet = NOBLOCK;
return true;
}
void UIPEthernetClass::init(const uint8_t* mac) {
uip_timer_set(&this->periodic_timer, CLOCK_SECOND / 4);
uip_timer_set(&periodic_timer, CLOCK_SECOND / 4);
network.init((uint8_t*)mac);
Enc28J60Network::init((uint8_t*)mac);
uip_seteth_addr(mac);
uip_init();
uip_arp_init();
}
void UIPEthernetClass::configure(IPAddress ip, IPAddress dns, IPAddress gateway, IPAddress subnet) {
@@ -345,7 +357,11 @@ UIPEthernetClass::ipchksum(void)
/*---------------------------------------------------------------------------*/
uint16_t
#if UIP_UDP
UIPEthernetClass::upper_layer_chksum(uint8_t proto)
#else
uip_tcpchksum(void)
#endif
{
uint16_t upper_layer_len;
uint16_t sum;
@@ -359,27 +375,34 @@ UIPEthernetClass::upper_layer_chksum(uint8_t proto)
/* First sum pseudoheader. */
/* IP protocol and length fields. This addition cannot carry. */
#if UIP_UDP
sum = upper_layer_len + proto;
#else
sum = upper_layer_len + UIP_PROTO_TCP;
#endif
/* Sum IP source and destination addresses. */
sum = chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));
sum = UIPEthernetClass::chksum(sum, (u8_t *)&BUF->srcipaddr[0], 2 * sizeof(uip_ipaddr_t));
uint8_t upper_layer_memlen;
#if UIP_UDP
switch(proto)
{
case UIP_PROTO_ICMP:
case UIP_PROTO_ICMP6:
upper_layer_memlen = upper_layer_len;
break;
case UIP_PROTO_TCP:
upper_layer_memlen = (BUF->tcpoffset >> 4) << 2;
break;
#if UIP_UDP
case UIP_PROTO_UDP:
// case UIP_PROTO_ICMP:
// case UIP_PROTO_ICMP6:
// upper_layer_memlen = upper_layer_len;
// break;
case UIP_PROTO_UDP:
upper_layer_memlen = UIP_UDPH_LEN;
break;
default:
// case UIP_PROTO_TCP:
#endif
upper_layer_memlen = (BUF->tcpoffset >> 4) << 2;
#if UIP_UDP
break;
}
sum = chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_memlen);
#endif
sum = UIPEthernetClass::chksum(sum, &uip_buf[UIP_IPH_LEN + UIP_LLH_LEN], upper_layer_memlen);
#ifdef UIPETHERNET_DEBUG_CHKSUM
Serial.print(F("chksum uip_buf["));
Serial.print(UIP_IPH_LEN + UIP_LLH_LEN);
@@ -390,9 +413,9 @@ UIPEthernetClass::upper_layer_chksum(uint8_t proto)
#endif
if (upper_layer_memlen < upper_layer_len)
{
sum = network.chksum(
sum = Enc28J60Network::chksum(
sum,
uip_packet,
UIPEthernetClass::uip_packet,
UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen,
upper_layer_len - upper_layer_memlen
);
@@ -403,7 +426,7 @@ UIPEthernetClass::upper_layer_chksum(uint8_t proto)
Serial.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_memlen);
Serial.print(F("-"));
Serial.print(UIP_IPH_LEN + UIP_LLH_LEN + upper_layer_len);
Serial.print(F"]: "));
Serial.print(F("]: "));
Serial.println(htons(sum),HEX);
#endif
}
@@ -416,6 +439,7 @@ uip_ipchksum(void)
return UIPEthernet.ipchksum();
}
#if UIP_UDP
uint16_t
uip_tcpchksum(void)
{
@@ -423,7 +447,6 @@ uip_tcpchksum(void)
return sum;
}
#if UIP_UDP
uint16_t
uip_udpchksum(void)
{