1
0
Fork 0

ADDED - NET_CHECKSUM_DEBUG output

MODIF - nicInit can now return -1 if it failed to initialize the nic
MODIF - All debuging output disabled in this build!
FIXED - Bug in NIC debug print definition

git-svn-id: svn+ssh://oldsvn/home/mlalondesvn/svn/Ethduino@4 b05466c9-153a-0410-ad00-ea1d4d8a27b5
master
mlalondesvn 17 years ago
parent 87e0115d23
commit 27a2de3439

@ -60,8 +60,10 @@ void arpSetAddress(struct netEthAddr* myeth, uint32_t myip)
void arpArpIn(unsigned int len, struct netEthArpHeader* packet)
{
#ifdef ARP_DEBUG
SPrint("Received ARP Request\r\n");
arpPrintHeader( &packet->arp );
SPrint("Received ARP Request\r\n");
#if NET_DEBUG > 3
arpPrintHeader( &packet->arp );
#endif
#endif
// for now, we just reply to requests
@ -86,8 +88,10 @@ void arpArpIn(unsigned int len, struct netEthArpHeader* packet)
packet->eth.src = ArpMyAddr.ethaddr;
#ifdef ARP_DEBUG
SPrint("Sending ARP Reply\r\n");
arpPrintHeader( &packet->arp );
SPrint("Sending ARP Reply\r\n");
#if NET_DEBUG > 3
arpPrintHeader( &packet->arp );
#endif
#endif
// send reply!
@ -206,12 +210,16 @@ void arpPrintHeader(struct netArpHeader* packet)
else
SPrint("UNKNOWN");
Serial.println();
// print source hardware address
SPrint("SrcHwAddr : "); netPrintEthAddr(&packet->shwaddr); Serial.println();
// print source protocol address
SPrint("SrcProtoAddr: "); netPrintIPAddr(HTONL(packet->sipaddr)); Serial.println();
// print target hardware address
SPrint("DstHwAddr : "); netPrintEthAddr(&packet->dhwaddr); Serial.println();
// print target protocol address
SPrint("DstProtoAddr: "); netPrintIPAddr(HTONL(packet->dipaddr)); Serial.println();
}

@ -43,15 +43,15 @@
#include "net.h"
#ifndef ARP_TABLE_SIZE
#define ARP_TABLE_SIZE 8
#define ARP_TABLE_SIZE 4
#endif
#ifndef ARP_CACHE_TIME_TO_LIVE
#define ARP_CACHE_TIME_TO_LIVE 100
#endif
#define ARP_DEBUG
#define ARP_DEBUG_PRINT
// #define ARP_DEBUG
// #define ARP_DEBUG_PRINT
/*! Initialize ARP system.

@ -51,9 +51,9 @@
u08 Enc28j60Bank;
u16 NextPacketPtr;
void nicInit(void)
char nicInit(void)
{
enc28j60Init();
return enc28j60Init();
}
void nicSend(unsigned int len, unsigned char* packet)
@ -90,7 +90,7 @@ void nicSetMacAddress(uint8_t* macaddr)
enc28j60Write(MAADR0, *macaddr++);
}
#ifdef NET_DEBUG || NIC_DEBUG
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
void nicRegDump(void)
{
enc28j60RegDump();
@ -297,7 +297,7 @@ void enc28j60PhyWrite(uint8_t address, uint16_t data)
while(enc28j60Read(MISTAT) & MISTAT_BUSY);
}
void enc28j60Init(void)
char enc28j60Init(void)
{
/**
* Enable ENC28J560 Control ports
@ -347,17 +347,23 @@ void enc28j60Init(void)
#endif
#ifdef ENC28J60_LAMPS_MODE
#ifdef DEBUG_ENC_INIT
SPrintln("Custom lamps");
#endif
enc28j60PhyWrite(PHLCON, ENC28J60_LAMPS_MODE);
#else
// Errata #9 correction
if (enc28j60Read(MACON3) & MACON3_FULDPX)
{
#ifdef DEBUG_ENC_INIT
SPrintln("Full duplex lamps");
#endif
enc28j60PhyWrite(PHLCON, PHLCON_DEFAULT);
} else {
#ifdef DEBUG_ENC_INIT
SPrintln("Half duplex lamps");
#endif
enc28j60PhyWrite(PHLCON, PHLCON_DEFAULT_HD);
}
#endif
@ -480,6 +486,7 @@ void enc28j60Init(void)
// setup duplex ----------------------
*/
return 0;
}
#define ETHERNET_MIN_PACKET_LENGTH 0x3C
@ -628,7 +635,7 @@ void enc28j60ReceiveOverflowRecover(void)
// recovery completed
}
#ifdef NET_DEBUG || NIC_DEBUG
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
#define SPrint_D(str) SPrint(str); delayMicroseconds(100);
void enc28j60RegDump(void)

@ -302,7 +302,8 @@ uint16_t enc28j60PhyRead(uint8_t address);
void enc28j60PhyWrite(uint8_t address, uint16_t data);
//! initialize the ethernet interface for transmit/receive
void enc28j60Init(void);
/// \return -1 if there was a problem initializing the NIC, otherwise the value is undefined
char enc28j60Init(void);
//! Packet transmit function.
/// Sends a packet on the network. It is assumed that the packet is headed by a valid ethernet header.
@ -323,7 +324,9 @@ unsigned int enc28j60PacketReceive(unsigned int maxlen, unsigned char* packet);
void enc28j60ReceiveOverflowRecover(void);
//! formatted print of important ENC28J60 registers
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
void enc28j60RegDump(void);
#endif
// ! Hard reset function
void enc28j60hardReset(void);

@ -54,8 +54,16 @@ void icmpEchoRequest(icmpip_hdr* packet)
packet->icmp.type = ICMP_TYPE_ECHOREPLY;
// recalculate checksum
packet->icmp.icmpchksum = 0;
packet->icmp.icmpchksum = ipChecksum((netIpHeader*)&packet->icmp, htons(packet->ip.len)-IP_HEADER_LEN);
packet->icmp.icmpchksum = 0x0000;
packet->icmp.icmpchksum = ipChecksum((netIpHeader*)&packet->icmp, htons(packet->ip.len)-sizeof(netIpHeader));
#ifdef NET_CHECKSUM_DEBUG
SPrintln(" ");
SPrint("ICMP Checksum: 0x");
Serial.print((uint16_t)htons(packet->icmp.icmpchksum), HEX);
SPrint(" 0x");
Serial.println((uint16_t)HTONS(packet->icmp.icmpchksum), HEX);
#endif
// return to sender
tempIp = packet->ip.destipaddr;

@ -87,6 +87,11 @@ void ipSend(uint32_t dstIp, uint8_t protocol, uint16_t len, uint8_t* data)
// DO THIS ONLY AFTER ALL CHANGES HAVE BEEN MADE TO IP HEADER
ethIpHeader->ip.ipchksum = netChecksum(&ethIpHeader->ip, IP_HEADER_LEN);
#ifdef NET_CHECKSUM_DEBUG
SPrint("IP Header Checksum: ");
Serial.println((uint16_t)ethIpHeader->ip.ipchksum, HEX);
#endif
// add ethernet routing
// check if we need to send to gateway
if( (dstIp & IpMyConfig.netmask) == (IpMyConfig.ip & IpMyConfig.netmask) )
@ -130,10 +135,12 @@ void udpSend(uint32_t dstIp, uint16_t dstPort, uint16_t len, uint8_t* data)
len += UDP_HEADER_LEN;
// fill UDP header
udpHeader->destport = HTONS(dstPort);
udpHeader->srcport = HTONS(dstPort);
udpHeader->udplen = htons(len);
udpHeader->udpchksum = 0;
udpHeader->destport = HTONS(dstPort);
udpHeader->srcport = HTONS(dstPort);
udpHeader->udplen = htons(len);
udpHeader->udpchksum = 0x000;
//udpHeader->udpchksum = ipChecksum((netUdpHeader*)&udpHeader, htons(udpHeader->ip.len)-UDP_HEADER_LEN);
#if NET_DEBUG > 6
debugPrintHexTable(UDP_HEADER_LEN, (uint8_t*)udpHeader);

@ -26,7 +26,7 @@
// Network options
#define IPADDRESS IPDOT(192l,168l,0l,126l)
#define NETMASK IPDOT(255l,255l,0l,0l)
#define GATEWAY IPDOT(192l,168l,255l,255l)
#define GATEWAY IPDOT(192l,168l,0l,01l)
#define ETHADDR0 0xCC /*'78'*/
#define ETHADDR1 0x00 /*'53'*/

@ -112,18 +112,22 @@ void serviceLocal(void)
sbi(ENC28J60_CONTROL_PORT, ENC28J60_CONTROL_CS);
break;
*/
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
case 'a' :
arpPrintTable();
break;
case 'd':
nicRegDump();
break;
#endif
case 'i':
nicInit();
break;
/*
case 'p':
break;
*/
case 'n': // Netstack init
netstackInit(IPADDRESS, NETMASK, GATEWAY);
break;
@ -137,7 +141,7 @@ void serviceLocal(void)
Serial.println((byte)(enc28j60Read(EREVID)), BIN);
break;
case 'p':
case 'c':
SPrintln("IP Configs");
SPrint("IP:");
Serial.println(ipGetConfig()->ip);
@ -168,14 +172,19 @@ void serviceLocal(void)
case '?':
SPrintln("Usage:");
#ifdef NET_DEBUG
SPrintln("(a) Print ARP table");
#endif
SPrintln("(b) Reboot NIC");
SPrintln("(c) Print IP configuration");
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
SPrintln("(d) Dump nic registers");
#endif
SPrintln("(i) Nic initialization");
SPrintln("(n) Netstack initialization");
SPrintln("(b) Reboot NIC");
SPrintln("(v) Display NIC revision");
SPrintln("(p) Print IP configuration");
//SPrintln("(p) Ping a remote machine");
SPrintln("(u) Send UDP packet");
SPrintln("(v) Display NIC revision");
SPrintln("(?) Print this help");
break;

@ -63,39 +63,14 @@ static uint16_t generateChecksum(uint16_t sum, netIpHeader *data, uint16_t len)
uint16_t ipChecksum(netIpHeader *data, uint16_t len)
{
return htons(generateChecksum(0, (netIpHeader *)data, len));
return htons(generateChecksum(0, data, len));
}
uint16_t netChecksum(netIpHeader *data, uint16_t len)
{
uint16_t sum;
sum = generateChecksum(0, &data[len], len);
SPrintln("uip_ipchksum: sum 0x");
Serial.println((long int)sum, HEX);
return (sum == 0) ? 0xffff : htons(sum);
/* register uint32_t sum = 0;
for (;;) {
if (len < 2)
break;
//sum += *((uint16_t *)data)++;
sum += *((uint16_t *)data);
data+=2;
len -= 2;
}
if (len)
sum += *(uint8_t *) data;
while ((len = (uint16_t) (sum >> 16)) != 0)
sum = (uint16_t) sum + len;
#if NET_DEBUG > 6
Serial.print("Checksum: ");
Serial.println((uint16_t) ~sum, HEX);
#endif
return (uint16_t) ~sum;
*/
}
void netPrintEthAddr(struct netEthAddr* ethaddr)

@ -26,7 +26,10 @@
#ifndef NET_H
#define NET_H
#define NET_DEBUG 7
// #define NET_DEBUG 7
//#define NET_CHECKSUM_DEBUG
#include "avrlibdefs.h"
#include "avrlibtypes.h"

@ -44,7 +44,7 @@
#include "ip.h"
#include "nic.h"
#define NETSTACK_DEBUG
// #define NETSTACK_DEBUG
/// NET_BUFFERSIZE is the common receive/process/transmit buffer.
/// - You may override the default NET_BUFFERSIZE by defining an alternate value in global.h.

@ -27,7 +27,7 @@
#ifndef NIC_H
#define NIC_H
#define NIC_DEBUG
// #define NIC_DEBUG
#include <inttypes.h>
@ -36,7 +36,8 @@
/// the network interface ready to handle \c nicSend() and \c nicPoll() requests.
/// \note For some hardware, this command will take a non-negligible amount of
/// time (1-2 seconds).
void nicInit(void);
/// \return -1 if there was a problem initializing the NIC, otherwise the value is undefined
char nicInit(void);
//! Send packet on network interface.
/// Function accepts the length (in bytes) of the data to be sent, and a pointer
@ -67,7 +68,9 @@ void nicSetMacAddress(uint8_t* macaddr);
//! Print network interface hardware registers.
/// Prints a formatted list of names and values of NIC registers for debugging
/// purposes.
#if defined(NET_DEBUG) || defined(NIC_DEBUG)
void nicRegDump(void);
#endif
//! PHY Chip hard reset function
void nicHardReset(void);

Loading…
Cancel
Save