added debug output
This commit is contained in:
29
include/ip.h
29
include/ip.h
@@ -73,28 +73,11 @@ typedef struct
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
void
|
||||
ip_handler (NIF *, NBUF *);
|
||||
|
||||
uint16_t
|
||||
ip_chksum (uint16_t *, int);
|
||||
|
||||
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);
|
||||
|
||||
/********************************************************************/
|
||||
extern void ip_handler(NIF *nif, NBUF *nbf);
|
||||
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);
|
||||
extern void ip_init(IP_INFO *, IP_ADDR_P, IP_ADDR_P, IP_ADDR_P);
|
||||
extern uint8_t *ip_get_myip(IP_INFO *);
|
||||
extern uint8_t *ip_resolve_route(NIF *, IP_ADDR_P);
|
||||
|
||||
#endif /* _IP_H */
|
||||
|
||||
@@ -50,6 +50,7 @@ void bootp_request(NIF *nif, uint8_t *pa)
|
||||
p->yi_addr = 0x0;
|
||||
p->gi_addr = 0x0;
|
||||
|
||||
connection.nif = nif;
|
||||
addr = &nif->hwa[0];
|
||||
for (i = 0; i < 6; i++)
|
||||
p->ch_addr[i] = addr[i];
|
||||
|
||||
53
net/ip.c
53
net/ip.c
@@ -11,6 +11,13 @@
|
||||
#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)
|
||||
{
|
||||
int index;
|
||||
@@ -35,6 +42,7 @@ uint8_t *ip_get_myip(IP_INFO *info)
|
||||
{
|
||||
return (uint8_t *) &info->myip[0];
|
||||
}
|
||||
dbg("%s: info is NULL!\n\t", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,10 +67,17 @@ uint8_t *ip_resolve_route(NIF *nif, IP_ADDR_P destip)
|
||||
*/
|
||||
IP_INFO *info;
|
||||
IP_ADDR mask, result;
|
||||
IP_ADDR bc = { 255, 255, 255, 255 };
|
||||
int i;
|
||||
|
||||
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 */
|
||||
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);
|
||||
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]);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
#if defined(DEBUG_PRINT)
|
||||
void
|
||||
dump_ip_frame (ip_frame_hdr *ipframe)
|
||||
void dump_ip_frame(ip_frame_hdr *ipframe)
|
||||
{
|
||||
printf("Version: %02X\n", ((ipframe->version_ihl & 0x00f0) >> 4));
|
||||
printf("IHL: %02X\n", ipframe->version_ihl & 0x000f);
|
||||
printf("Service: %02X\n", ipframe->service_type);
|
||||
printf("Length: %04X\n", ipframe->total_length);
|
||||
printf("Ident: %04X\n", ipframe->identification);
|
||||
printf("Flags: %02X\n", ((ipframe->flags_frag_offset & 0xC000) >> 14));
|
||||
printf("Frag: %04X\n", ipframe->flags_frag_offset & 0x3FFF);
|
||||
printf("TTL: %02X\n", ipframe->ttl);
|
||||
printf("Protocol: %02X\n", ipframe->protocol);
|
||||
printf("Chksum: %04X\n", ipframe->checksum);
|
||||
printf("Source : %d.%d.%d.%d\n",
|
||||
xprintf("Version: %02X\n", ((ipframe->version_ihl & 0x00f0) >> 4));
|
||||
xprintf("IHL: %02X\n", ipframe->version_ihl & 0x000f);
|
||||
xprintf("Service: %02X\n", ipframe->service_type);
|
||||
xprintf("Length: %04X\n", ipframe->total_length);
|
||||
xprintf("Ident: %04X\n", ipframe->identification);
|
||||
xprintf("Flags: %02X\n", ((ipframe->flags_frag_offset & 0xC000) >> 14));
|
||||
xprintf("Frag: %04X\n", ipframe->flags_frag_offset & 0x3FFF);
|
||||
xprintf("TTL: %02X\n", ipframe->ttl);
|
||||
xprintf("Protocol: %02X\n", ipframe->protocol);
|
||||
xprintf("Chksum: %04X\n", ipframe->checksum);
|
||||
xprintf("Source : %d.%d.%d.%d\n",
|
||||
ipframe->source_addr[0],
|
||||
ipframe->source_addr[1],
|
||||
ipframe->source_addr[2],
|
||||
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[1],
|
||||
ipframe->dest_addr[2],
|
||||
ipframe->dest_addr[3]);
|
||||
printf("Options: %08X\n", ipframe->options);
|
||||
xprintf("Options: %08X\n", ipframe->options);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -261,7 +280,7 @@ void ip_handler(NIF *nif, NBUF *pNbuf)
|
||||
*/
|
||||
ip_frame_hdr *ipframe;
|
||||
|
||||
ipframe = (ip_frame_hdr *)&pNbuf->data[pNbuf->offset];
|
||||
ipframe = (ip_frame_hdr *) &pNbuf->data[pNbuf->offset];
|
||||
|
||||
/*
|
||||
* Verify valid IP header and destination IP
|
||||
|
||||
13
net/udp.c
13
net/udp.c
@@ -11,6 +11,13 @@
|
||||
#include "net.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
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (nif == NULL)
|
||||
{
|
||||
dbg("%s: nif is NULL\r\n", __FUNCTION__);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function takes data and creates a UDP frame and
|
||||
* passes it onto the IP layer
|
||||
|
||||
Reference in New Issue
Block a user