This is needed for the upcoming TFTP server implementation.
This also simplifies PingHandler() and fixes rxhand_f documentation.
Signed-off-by: Luca Ceresoli <luca.ceresoli@comelit.it>
Cc: Wolfgang Denk <wd@denx.de>
Acked-by: Detlev Zundel <dzu@denx.de>
static const char *output_packet; /* used by first send udp */
static int output_packet_len = 0;
-static void nc_wait_arp_handler (uchar * pkt, unsigned dest, unsigned src,
+static void nc_wait_arp_handler(uchar *pkt, unsigned dest,
+ IPaddr_t sip, unsigned src,
unsigned len)
{
NetState = NETLOOP_SUCCESS; /* got arp reply - quit net loop */
}
-static void nc_handler (uchar * pkt, unsigned dest, unsigned src,
+static void nc_handler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
unsigned len)
{
if (input_size)
typedef ulong IPaddr_t;
-/*
- * The current receive packet handler. Called with a pointer to the
- * application packet, and a protocol type (PORT_BOOTPC or PORT_TFTP).
- * All other packets are dealt with without calling the handler.
+/**
+ * An incoming packet handler.
+ * @param pkt pointer to the application packet
+ * @param dport destination UDP port
+ * @param sip source IP address
+ * @param sport source UDP port
+ * @param len packet length
*/
-typedef void rxhand_f(uchar *, unsigned, unsigned, unsigned);
+typedef void rxhand_f(uchar *pkt, unsigned dport,
+ IPaddr_t sip, unsigned sport,
+ unsigned len);
/*
* A timeout handler. Called after time interval has expired.
dhcp_state_t dhcp_state = INIT;
unsigned long dhcp_leasetime = 0;
IPaddr_t NetDHCPServerIP = 0;
-static void DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len);
+static void DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len);
/* For Debug */
#if 0
* Handle a BOOTP received packet.
*/
static void
-BootpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+BootpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
Bootp_t *bp;
char *s;
* Handle DHCP received packets.
*/
static void
-DhcpHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+DhcpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
Bootp_t *bp = (Bootp_t *)pkt;
}
static void
-DnsHandler(uchar *pkt, unsigned dest, unsigned src, unsigned len)
+DnsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
{
struct header *header;
const unsigned char *p, *e, *s;
}
static void
-startAgainHandler(uchar * pkt, unsigned dest, unsigned src, unsigned len)
+startAgainHandler(uchar *pkt, unsigned dest, IPaddr_t sip,
+ unsigned src, unsigned len)
{
/* Totally ignore the packet */
}
}
static void
-PingHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+PingHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
- IPaddr_t tmp;
- volatile IP_t *ip = (volatile IP_t *)pkt;
-
- tmp = NetReadIP((void *)&ip->ip_src);
- if (tmp != NetPingIP)
+ if (sip != NetPingIP)
return;
NetState = NETLOOP_SUCCESS;
}
static void
-CDPDummyHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+CDPDummyHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
/* nothing */
}
IP_t *ip;
ARP_t *arp;
IPaddr_t tmp;
+ IPaddr_t src_ip;
int x;
uchar *pkt;
#if defined(CONFIG_CMD_CDP)
memcpy(NetArpWaitPacketMAC, &arp->ar_data[0], 6);
#ifdef CONFIG_NETCONSOLE
- (*packetHandler)(0,0,0,0);
+ (*packetHandler)(0, 0, 0, 0, 0);
#endif
/* modify header, and transmit it */
memcpy(((Ethernet_t *)NetArpWaitTxPacket)->et_dest, NetArpWaitPacketMAC, 6);
NetCopyIP(&NetServerIP, &arp->ar_data[ 6]);
memcpy (NetServerEther, &arp->ar_data[ 0], 6);
- (*packetHandler)(0,0,0,0);
+ (*packetHandler)(0, 0, 0, 0, 0);
}
break;
#endif
#endif
return;
}
+ /* Read source IP address for later use */
+ src_ip = NetReadIP(&ip->ip_src);
/*
* The function returns the unchanged packet if it's not
* a fragment, and either the complete packet or NULL if
* IP header OK. Pass the packet to the current handler.
*/
/* XXX point to ip packet */
- (*packetHandler)((uchar *)ip, 0, 0, 0);
+ (*packetHandler)((uchar *)ip, 0, src_ip, 0, 0);
return;
case ICMP_ECHO_REQUEST:
- debug("Got ICMP ECHO REQUEST, return %d bytes \n",
- ETHER_HDR_SIZE + len);
+ debug("Got ICMP ECHO REQUEST, "
+ "return %d bytes\n",
+ ETHER_HDR_SIZE + len);
memcpy (&et->et_dest[0], &et->et_src[0], 6);
memcpy (&et->et_src[ 0], NetOurEther, 6);
*/
(*packetHandler)((uchar *)ip +IP_HDR_SIZE,
ntohs(ip->udp_dst),
+ src_ip,
ntohs(ip->udp_src),
ntohs(ip->udp_len) - 8);
break;
}
static void
-NfsHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
+NfsHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src, unsigned len)
{
int rlen;
* Handle a RARP received packet.
*/
static void
-RarpHandler(uchar * dummi0, unsigned dummi1, unsigned dummi2, unsigned dummi3)
+RarpHandler(uchar *dummi0, unsigned dummi1, IPaddr_t sip, unsigned dummi2,
+ unsigned dummi3)
{
char *s;
debug("Got good RARP\n");
}
static void
-SntpHandler (uchar *pkt, unsigned dest, unsigned src, unsigned len)
+SntpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
struct sntp_pkt_t *rpktp = (struct sntp_pkt_t *)pkt;
struct rtc_time tm;
static void
-TftpHandler (uchar * pkt, unsigned dest, unsigned src, unsigned len)
+TftpHandler(uchar *pkt, unsigned dest, IPaddr_t sip, unsigned src,
+ unsigned len)
{
ushort proto;
ushort *s;