added debug output

This commit is contained in:
Markus Fröschle
2013-12-24 16:40:23 +00:00
parent 8df0994eca
commit a08ac74feb
4 changed files with 315 additions and 299 deletions

View File

@@ -73,28 +73,11 @@ typedef struct
/********************************************************************/ /********************************************************************/
void extern void ip_handler(NIF *nif, NBUF *nbf);
ip_handler (NIF *, NBUF *); uint16_t ip_chksum(uint16_t *data, int num);
extern int ip_send(NIF *nif, uint8_t *dest_addr, uint8_t *src_addr, uint8_t protocol, NBUF *nbf);
uint16_t extern void ip_init(IP_INFO *, IP_ADDR_P, IP_ADDR_P, IP_ADDR_P);
ip_chksum (uint16_t *, int); extern uint8_t *ip_get_myip(IP_INFO *);
extern uint8_t *ip_resolve_route(NIF *, IP_ADDR_P);
int
ip_send (NIF *,
uint8_t *, /* destination IP */
uint8_t *, /* source IP */
uint8_t, /* protocol */
NBUF * /* buffer descriptor */);
void
ip_init (IP_INFO *, IP_ADDR_P, IP_ADDR_P, IP_ADDR_P);
uint8_t *
ip_get_myip (IP_INFO *);
uint8_t *
ip_resolve_route (NIF *, IP_ADDR_P);
/********************************************************************/
#endif /* _IP_H */ #endif /* _IP_H */

View File

@@ -50,6 +50,7 @@ void bootp_request(NIF *nif, uint8_t *pa)
p->yi_addr = 0x0; p->yi_addr = 0x0;
p->gi_addr = 0x0; p->gi_addr = 0x0;
connection.nif = nif;
addr = &nif->hwa[0]; addr = &nif->hwa[0];
for (i = 0; i < 6; i++) for (i = 0; i < 6; i++)
p->ch_addr[i] = addr[i]; p->ch_addr[i] = addr[i];

View File

@@ -11,6 +11,13 @@
#include <stddef.h> #include <stddef.h>
#define IP_DEBUG
#if defined(IP_DEBUG)
#define dbg(format, arg...) do { xprintf("DEBUG: " format "\r\n", ##arg); } while (0)
#else
#define dbg(format, arg...) do { ; } while (0)
#endif
void ip_init(IP_INFO *info, IP_ADDR_P myip, IP_ADDR_P gateway, IP_ADDR_P netmask) void ip_init(IP_INFO *info, IP_ADDR_P myip, IP_ADDR_P gateway, IP_ADDR_P netmask)
{ {
int index; int index;
@@ -35,6 +42,7 @@ uint8_t *ip_get_myip(IP_INFO *info)
{ {
return (uint8_t *) &info->myip[0]; return (uint8_t *) &info->myip[0];
} }
dbg("%s: info is NULL!\n\t", __FUNCTION__);
return 0; return 0;
} }
@@ -59,10 +67,17 @@ uint8_t *ip_resolve_route(NIF *nif, IP_ADDR_P destip)
*/ */
IP_INFO *info; IP_INFO *info;
IP_ADDR mask, result; IP_ADDR mask, result;
IP_ADDR bc = { 255, 255, 255, 255 };
int i; int i;
info = nif_get_protocol_info(nif, ETH_FRM_IP); info = nif_get_protocol_info(nif, ETH_FRM_IP);
if (memcmp(destip, bc) == 0)
{
dbg("%s: destip is broadcast address, no gateway needed\r\n", __FUNCTION__);
return destip;
}
/* create mask for local IP */ /* create mask for local IP */
for (i = 0; i < sizeof(IP_ADDR); i++) for (i = 0; i < sizeof(IP_ADDR); i++)
{ {
@@ -153,42 +168,46 @@ int ip_send(NIF *nif, uint8_t *dest, uint8_t *src, uint8_t protocol, NBUF *pNbuf
route = ip_resolve_route(nif, dest); route = ip_resolve_route(nif, dest);
if (route == NULL) if (route == NULL)
{ {
xprintf("Unable to locate %d.%d.%d.%d\n", dbg("Unable to locate %d.%d.%d.%d\n",
dest[0], dest[1], dest[2], dest[3]); dest[0], dest[1], dest[2], dest[3]);
return 0; return 0;
} }
} }
else else
{
route = bc; route = bc;
dbg("%s: route = broadcast\r\n", __FUNCTION__);
dbg("%s: nif = %p\r\n", __FUNCTION__, nif);
dbg("%s: nif->send = %p\n\t", __FUNCTION__, nif->send);
}
return nif->send(nif, route, &nif->hwa[0], ETH_FRM_IP, pNbuf); return nif->send(nif, route, &nif->hwa[0], ETH_FRM_IP, pNbuf);
} }
#if defined(DEBUG_PRINT) #if defined(DEBUG_PRINT)
void void dump_ip_frame(ip_frame_hdr *ipframe)
dump_ip_frame (ip_frame_hdr *ipframe)
{ {
printf("Version: %02X\n", ((ipframe->version_ihl & 0x00f0) >> 4)); xprintf("Version: %02X\n", ((ipframe->version_ihl & 0x00f0) >> 4));
printf("IHL: %02X\n", ipframe->version_ihl & 0x000f); xprintf("IHL: %02X\n", ipframe->version_ihl & 0x000f);
printf("Service: %02X\n", ipframe->service_type); xprintf("Service: %02X\n", ipframe->service_type);
printf("Length: %04X\n", ipframe->total_length); xprintf("Length: %04X\n", ipframe->total_length);
printf("Ident: %04X\n", ipframe->identification); xprintf("Ident: %04X\n", ipframe->identification);
printf("Flags: %02X\n", ((ipframe->flags_frag_offset & 0xC000) >> 14)); xprintf("Flags: %02X\n", ((ipframe->flags_frag_offset & 0xC000) >> 14));
printf("Frag: %04X\n", ipframe->flags_frag_offset & 0x3FFF); xprintf("Frag: %04X\n", ipframe->flags_frag_offset & 0x3FFF);
printf("TTL: %02X\n", ipframe->ttl); xprintf("TTL: %02X\n", ipframe->ttl);
printf("Protocol: %02X\n", ipframe->protocol); xprintf("Protocol: %02X\n", ipframe->protocol);
printf("Chksum: %04X\n", ipframe->checksum); xprintf("Chksum: %04X\n", ipframe->checksum);
printf("Source : %d.%d.%d.%d\n", xprintf("Source : %d.%d.%d.%d\n",
ipframe->source_addr[0], ipframe->source_addr[0],
ipframe->source_addr[1], ipframe->source_addr[1],
ipframe->source_addr[2], ipframe->source_addr[2],
ipframe->source_addr[3]); ipframe->source_addr[3]);
printf("Dest : %d.%d.%d.%d\n", xprintf("Dest : %d.%d.%d.%d\n",
ipframe->dest_addr[0], ipframe->dest_addr[0],
ipframe->dest_addr[1], ipframe->dest_addr[1],
ipframe->dest_addr[2], ipframe->dest_addr[2],
ipframe->dest_addr[3]); ipframe->dest_addr[3]);
printf("Options: %08X\n", ipframe->options); xprintf("Options: %08X\n", ipframe->options);
} }
#endif #endif

View File

@@ -11,6 +11,13 @@
#include "net.h" #include "net.h"
#include <stddef.h> #include <stddef.h>
#define UDP_DEBUG
#if defined(UDP_DEBUG)
#define dbg(format, arg...) do { xprintf("DEBUG: " format "\r\n", ##arg); } while (0)
#else
#define dbg(format, arg...) do { ; } while (0)
#endif
typedef struct typedef struct
{ {
uint16_t port; uint16_t port;
@@ -99,6 +106,12 @@ uint16_t udp_obtain_free_port(void)
int udp_send(NIF *nif, uint8_t *dest, int sport, int dport, NBUF *pNbuf) int udp_send(NIF *nif, uint8_t *dest, int sport, int dport, NBUF *pNbuf)
{ {
if (nif == NULL)
{
dbg("%s: nif is NULL\r\n", __FUNCTION__);
return 0;
}
/* /*
* This function takes data and creates a UDP frame and * This function takes data and creates a UDP frame and
* passes it onto the IP layer * passes it onto the IP layer