4 *Copyright (C) 2010 Beceem Communications, Inc.
6 *This program is free software: you can redistribute it and/or modify
7 *it under the terms of the GNU General Public License version 2 as
8 *published by the Free Software Foundation.
10 *This program is distributed in the hope that it will be useful,but
11 *WITHOUT ANY WARRANTY; without even the implied warranty of
12 *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 *See the GNU General Public License for more details.
15 *You should have received a copy of the GNU General Public License
16 *along with this program. If not, write to the Free Software Foundation, Inc.,
17 *51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**********************************************************************
22 * This file contains the routines for handling ARP PACKETS
23 ***********************************************************************/
27 #define ARP_PKT_SIZE 60
29 /* =========================================================================
30 * Function - reply_to_arp_request()
32 * Description - When this host tries to broadcast ARP request packet through
33 * the virtual interface (veth0), reply directly to upper layer.
34 * This function allocates a new skb for ARP reply packet,
35 * fills in the fields of the packet and then sends it to
38 * Parameters - skb: Pointer to sk_buff structure of the ARP request pkt.
41 * =========================================================================*/
44 reply_to_arp_request(struct sk_buff
*skb
)
46 PMINI_ADAPTER Adapter
;
47 struct ArpHeader
*pArpHdr
= NULL
;
48 struct ethhdr
*pethhdr
= NULL
;
50 /* Check for valid skb */
53 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_PRINTK
, 0, 0, "Invalid skb: Cannot reply to ARP request\n");
58 Adapter
= GET_BCM_ADAPTER(skb
->dev
);
59 /* Print the ARP Request Packet */
60 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, ARP_RESP
, DBG_LVL_ALL
, "ARP Packet Dump :");
61 BCM_DEBUG_PRINT_BUFFER(Adapter
,DBG_TYPE_TX
, ARP_RESP
, DBG_LVL_ALL
, (PUCHAR
)(skb
->data
), skb
->len
);
64 * Extract the Ethernet Header and Arp Payload including Header
66 pethhdr
= (struct ethhdr
*)skb
->data
;
67 pArpHdr
= (struct ArpHeader
*)(skb
->data
+ETH_HLEN
);
69 if(Adapter
->bETHCSEnabled
)
71 if(memcmp(pethhdr
->h_source
, Adapter
->dev
->dev_addr
, ETH_ALEN
))
78 // Set the Ethernet Header First.
79 memcpy(pethhdr
->h_dest
, pethhdr
->h_source
, ETH_ALEN
);
80 if(!memcmp(pethhdr
->h_source
, Adapter
->dev
->dev_addr
, ETH_ALEN
))
82 pethhdr
->h_source
[5]++;
85 /* Set the reply to ARP Reply */
86 pArpHdr
->arp
.ar_op
= ntohs(ARPOP_REPLY
);
88 /* Set the HW Address properly */
89 memcpy(pArpHdr
->ar_sha
, pethhdr
->h_source
, ETH_ALEN
);
90 memcpy(pArpHdr
->ar_tha
, pethhdr
->h_dest
, ETH_ALEN
);
92 // Swapping the IP Adddress
93 memcpy(uiIPHdr
,pArpHdr
->ar_sip
,4);
94 memcpy(pArpHdr
->ar_sip
,pArpHdr
->ar_tip
,4);
95 memcpy(pArpHdr
->ar_tip
,uiIPHdr
,4);
97 /* Print the ARP Reply Packet */
99 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, ARP_RESP
, DBG_LVL_ALL
, "ARP REPLY PACKET: ");
101 /* Send the Packet to upper layer */
102 BCM_DEBUG_PRINT_BUFFER(Adapter
,DBG_TYPE_TX
, ARP_RESP
, DBG_LVL_ALL
, (PUCHAR
)(skb
->data
), skb
->len
);
104 skb
->protocol
= eth_type_trans(skb
,skb
->dev
);
105 skb
->pkt_type
= PACKET_HOST
;
107 // skb->mac.raw=skb->data+LEADER_SIZE;
108 skb_set_mac_header (skb
, LEADER_SIZE
);
110 BCM_DEBUG_PRINT(Adapter
,DBG_TYPE_TX
, ARP_RESP
, DBG_LVL_ALL
, "<=============\n");