Search Linux Wireless

Sending L2 frames

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi,

I'm trying to send a 802.11 MGMT Action Frame using nl80211. However, it always give me the error: *ERROR: -107 : Transport endpoint is not connected*. Everything seems right to me and I have no more ideas of what could be happening.

Another strange thing is that after the error I can not connect again with the nl80211 until I restart the program.

Thanks,
Carlos Guimarães

Next is the code I'm using to send the frame:

int send_action_frame(const char *interface, unsigned int freq,
                 const uint8 *dst, const uint8 *src,
                 const uint8 *bssid,
                 const uint8 *data, size_t data_len)
{
    struct nl_sock *nl_handle = NULL;
    struct nl_cache *nl_cache = NULL;
    struct genl_family *nl80211 = NULL;
    struct nl_msg *msg;
    int ret = -1;
    uint8 *buf;
    struct ieee80211_hdr *hdr;
    uint64 cookie;

    log(1, "nl80211: Send Action frame (ifindex=", interface,")");

    buf = (uint8 *)calloc(24 + data_len, sizeof(uint8));
    if (buf == NULL)
        return ret;
    memcpy(buf + 24, data, data_len);
    hdr = (struct ieee80211_hdr *) buf;
    hdr->frame_control = (0 << 2) | (13 << 4);
    uint8* addr = (uint8 *)calloc(6, sizeof(uint8));
    void *addr_bg = addr;
    memset(addr, 0, 1); addr++;
    memset(addr, 20, 1); addr++;
    memset(addr, 108, 1); addr++;
    memset(addr, 76, 1); addr++;
    memset(addr, 192, 1); addr++;
    memset(addr, 196, 1); addr++;


    memcpy(hdr->addr1, addr_bg, 6);
    memcpy(hdr->addr2, addr_bg, 6);
//    memcpy(hdr->addr2, "\x00\x24\x17\xa1\x38\x2a", 6);
    memcpy(hdr->addr3, addr_bg, 6);

    if (connect(interface,
                         (void **) &nl_handle,
                         (void **) &nl_cache,
                         (void **) &nl80211) < 0) {
        return -1;
    }
log(1, "nl80211: connect");
    msg = nlmsg_alloc();
    if (!msg) {
        disconnect(nl_handle);
        free(buf);
        return -1;
    }

    genlmsg_put(msg, 0, 0, genl_family_get_id(nl80211), 0, 0,
            NL80211_CMD_ACTION, 0);

    NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(interface));
    NLA_PUT_U32(msg, NL80211_ATTR_WIPHY_FREQ, freq);
    NLA_PUT(msg, NL80211_ATTR_FRAME, 24 + data_len, buf);
log(1, "nl80211: message a enviar");
    cookie = 0;
    ret = send_and_receive(nl_handle, msg, cookie_handler, &cookie);
    log(1, "nl80211: enviada");
//    ret = send_and_receive(nl_handle, msg, NULL, NULL);
    msg = NULL;
    if (ret) {
        log(1, "nl80211: Action command failed: ret=%d "
               "(%s)", ret, strerror(-ret));
        goto nla_put_failure;
    }
    log(1, "nl80211: Action TX command accepted; "
           "cookie 0x%llx", (long long unsigned int) cookie);

    ret = 0;

nla_put_failure:
            log(1, "failure: ", ret);
    free(buf);
    buf = NULL;
    disconnect(nl_handle);
    return ret;
}
--
To unsubscribe from this list: send the line "unsubscribe linux-wireless" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Host AP]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Linux Kernel]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux