how to change the src mac address of the packet at l2_packet_linux.c

d' Ani anirbande at
Thu Apr 9 00:52:59 EDT 2009

Hi all

Setup:      PC1-------AP-----------STA----------PC2
            eth0     br0           br0         eth0   
                   eth0+ath0     eth0+ath0   

Invocation: wpa_supplicant -Dmadwifi -iath0 -bbr0 -c/etc/wpa_cupplicant.conf

Background: I wanted to achieve association with AP with a mac address of PC2 not with STA, thus rendering STA invisible to the AP. Things working fine till here. Can ping all nodes adding ebtables and iptables rules.

Goal: Want to run WPA-PSK/WPA2-PSK for the authentication AP----STA. hostap/wpa_supplicant should be running on AP/STA (wpa_supplicant not to run on PC2 although STA has associated with PC2 mac).

Problem:  Now 4 way handshake fails to happen. As the wpa_supplicant sends 2 out of 4 message it sends it with own mac and i guess the hostapd rejects it as it associated with PC2 mac. i am using l2_packet_linux.c for layer two send. 

What i have done: modified the l2_packet send as follows. As well as i have enabled the l2->l2_hdr = 1 to include layer 2 header in l2_packet_init (my changes in blue)

Question: Am i correct in my implementation. i can't still get the handshake going. Hostapd -dd shows
eth0: <PC2 MAC> WPA: sending 1/4 msg of 4 way handshake
eth0: <PC2 MAC> EAPOL-Key timeout

int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
           const u8 *buf, size_t len)
        int ret;
        struct l2_ethhdr *eth;
        uint8_t src[ETH_ALEN] = {0x00, 0x13, 0x20, 0x5b, 0x40, 0xaa};// PC2 addr
        size_t mlen = sizeof(*eth) + len;
        eth = os_malloc(mlen);
        if (!eth) return -1;
        os_memset(&eth, 0, sizeof(eth));
        os_memcpy(eth->h_dest, dst_addr, ETH_ALEN);
        os_memcpy(eth->h_source, src, ETH_ALEN);
        eth->h_proto = host_to_be16(proto);
        os_memcpy(eth + 1, buf, len);
        ret = send(l2->fd, buf, mlen, 0);
        if (ret < 0) perror("l2_packet_send - error pramod ");
        return ret;
#if 0
    int ret;
    if (l2 == NULL)
        return -1;
    if (l2->l2_hdr) {
        ret = send(l2->fd, buf, len, 0);
        wpa_printf(MSG_DEBUG, "pramod  sending using send l2->l2_hdr=%d", l2->l2_hdr);
        if (ret < 0)
            perror("l2_packet_send - send 55");
    } else {
        struct sockaddr_ll ll;
        os_memset(&ll, 0, sizeof(ll));
        ll.sll_family = AF_PACKET;
        ll.sll_ifindex = l2->ifindex;
        ll.sll_protocol = htons(proto);
        ll.sll_halen = ETH_ALEN;
        os_memcpy(ll.sll_addr, dst_addr, ETH_ALEN);
        ret = sendto(l2->fd, buf, len, 0, (struct sockaddr *) &ll,
        wpa_printf(MSG_DEBUG, "pramod  sending using sendto l2->l2_hdr=%d", l2->l2_hdr);
        if (ret < 0)
            perror("l2_packet_send - sendto");
    return ret;

Finally: if i am filling src dest proto of the ETH header is linux going to fill the CRC checksum? Is the is another way to implement this easily so that i can send the packets on the socket using my changed SRC mac address.

Anirban De
Yahoo: anirbande
Skype: anirbande
Gtalk : ade.sxc

      Add more friends to your messenger and enjoy! Go to
-------------- next part --------------
An HTML attachment was scrubbed...

More information about the HostAP mailing list