From: "Carlos Guimarães" <asc2.cemg@gmail.com>
To: linux-wireless@vger.kernel.org
Subject: Sending L2 frames
Date: Sun, 20 Mar 2011 02:44:01 +0000 [thread overview]
Message-ID: <4D8569F1.40900@gmail.com> (raw)
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;
}
reply other threads:[~2011-03-20 2:44 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D8569F1.40900@gmail.com \
--to=asc2.cemg@gmail.com \
--cc=linux-wireless@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.