[PATCH] Use the p2p/hostap interface to send frames if moniter interface is not supported

Lin Ma linm
Tue May 31 16:04:10 PDT 2011


In case that monitor interface is not supported, we create a raw socket to send the frames

Signed-off-by: Lin Ma <linm at broadcom.com>
Signed-off-by: Ecco Park <eccopark at broadcom.com>
---
 src/drivers/driver_nl80211.c |   32 +++++++++++++++++++++++++++++---
 1 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/src/drivers/driver_nl80211.c b/src/drivers/driver_nl80211.c
old mode 100644
new mode 100755
index 9fa253e..d0c8765
--- a/src/drivers/driver_nl80211.c
+++ b/src/drivers/driver_nl80211.c
@@ -158,6 +158,7 @@ struct wpa_driver_nl80211_data {
 	int monitor_sock;
 	int monitor_ifidx;
 	int disable_11b_rates;
+	int raw_sock; /* socket for sending frame if monitor interface is not supported */
 
 	unsigned int pending_remain_on_chan:1;
 
@@ -1878,6 +1879,7 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 	struct netlink_config *cfg;
 	struct rfkill_config *rcfg;
 	struct i802_bss *bss;
+	struct sockaddr_ll ll;
 
 	drv = os_zalloc(sizeof(*drv));
 	if (drv == NULL)
@@ -1890,6 +1892,7 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 	drv->monitor_ifidx = -1;
 	drv->monitor_sock = -1;
 	drv->ioctl_sock = -1;
+	drv->raw_sock = -1;
 
 	if (wpa_driver_nl80211_init_nl(drv)) {
 		os_free(drv);
@@ -1931,6 +1934,18 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 
 	if (wpa_driver_nl80211_finish_drv_init(drv))
 		goto failed;
+	drv->raw_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
+	if (drv->raw_sock < 0) {
+		perror("socket(PF_INET,SOCK_DGRAM)");
+		goto failed;
+	}
+	memset(&ll, 0, sizeof(ll));
+	ll.sll_family = AF_PACKET;
+	ll.sll_ifindex = drv->ifindex;
+	if (bind(drv->raw_sock, (struct sockaddr *) &ll, sizeof(ll)) < 0) {
+		perror("raw socket bind");
+		goto failed;
+	}
 
 	if (drv->global)
 		dl_list_add(&drv->global->interfaces, &drv->list);
@@ -1940,6 +1955,8 @@ static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
 failed:
 	rfkill_deinit(drv->rfkill);
 	netlink_deinit(drv->netlink);
+	if (drv->raw_sock >= 0)
+		close(drv->raw_sock);
 	if (drv->ioctl_sock >= 0)
 		close(drv->ioctl_sock);
 
@@ -2188,6 +2205,8 @@ static void wpa_driver_nl80211_deinit(void *priv)
 
 	if (drv->ioctl_sock >= 0)
 		close(drv->ioctl_sock);
+	if (drv->raw_sock>= 0)
+		close(drv->raw_sock);
 
 	eloop_unregister_read_sock(nl_socket_get_fd(drv->nl_handle_event));
 	genl_family_put(drv->nl80211);
@@ -3635,7 +3654,10 @@ static int wpa_driver_nl80211_send_frame(struct wpa_driver_nl80211_data *drv,
 	if (encrypt)
 		rtap_hdr[8] |= IEEE80211_RADIOTAP_F_WEP;
 
-	res = sendmsg(drv->monitor_sock, &msg, 0);
+	if (drv->monitor_sock < 0)
+		res = sendmsg(drv->raw_sock, &msg, 0);
+	else
+		res = sendmsg(drv->monitor_sock, &msg, 0);
 	if (res < 0) {
 		wpa_printf(MSG_INFO, "nl80211: sendmsg: %s", strerror(errno));
 		return -1;
@@ -4972,8 +4994,10 @@ done:
 	if (!ret && nlmode == NL80211_IFTYPE_AP) {
 		/* Setup additional AP mode functionality if needed */
 		if (drv->monitor_ifidx < 0 &&
-		    nl80211_create_monitor_interface(drv))
-			return -1;
+		    nl80211_create_monitor_interface(drv)) {
+			if (drv->raw_sock < 0)
+				return -1;
+		}
 	} else if (!ret && nlmode != NL80211_IFTYPE_AP) {
 		/* Remove additional AP mode functionality */
 		nl80211_remove_monitor_interface(drv);
@@ -5773,6 +5797,8 @@ failed:
 	nl80211_remove_monitor_interface(drv);
 	rfkill_deinit(drv->rfkill);
 	netlink_deinit(drv->netlink);
+	if (drv->raw_sock>= 0)
+		close(drv->raw_sock);
 	if (drv->ioctl_sock >= 0)
 		close(drv->ioctl_sock);
 
-- 
1.7.1





More information about the Hostap mailing list