summaryrefslogtreecommitdiff
path: root/package/hostapd/patches/003-use-nl80211-for-beacons.patch
blob: 34fa841d61c9e845b046bd4699847e5ecda999b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
---
 hostapd/driver_devicescape.c |  111 +++++++++++++++++++++++++++++++------------
 1 file changed, 82 insertions(+), 29 deletions(-)

--- hostap.orig/hostapd/driver_devicescape.c	2007-11-09 13:41:13.000000000 +0100
+++ hostap/hostapd/driver_devicescape.c	2007-11-09 13:41:13.000000000 +0100
@@ -68,6 +68,8 @@ struct i802_driver_data {
 	struct nl_handle *nl_handle;
 	struct nl_cache *nl_cache;
 	struct genl_family *nl80211;
+	int dtim_period;
+	unsigned int beacon_set:1;
 };
 
 
@@ -908,37 +910,44 @@ static int i802_bss_remove(void *priv, c
 }
 
 
-static int i802_set_beacon(const char *ifname, void *priv,
+static int i802_set_beacon(const char *iface, void *priv,
 			   u8 *head, size_t head_len,
 			   u8 *tail, size_t tail_len)
 {
 	struct i802_driver_data *drv = priv;
-	struct prism2_hostapd_param *param;
-	int len, ret = 0;
+	struct nl_msg *msg;
+	u8 cmd = NL80211_CMD_NEW_BEACON;
+	int ret = -1;
 
-	param = os_zalloc(sizeof(*param) + head_len + tail_len);
-	if (param == NULL) {
-		printf("Failed to alloc memory for beacon ioctl\n");
-		return -1;
-	}
-	len = (&param->u.beacon.data[0] - (u8 *) param) + head_len + tail_len;
-	param->cmd = PRISM2_HOSTAPD_SET_BEACON;
-	param->u.beacon.head_len = head_len;
-	param->u.beacon.tail_len = tail_len;
-	memcpy(&param->u.beacon.data[0], head, head_len);
-	memcpy(&param->u.beacon.data[0] + head_len, tail, tail_len);
-
-	if (len < (int) sizeof(*param))
-		len = sizeof(*param);
-	if (hostapd_ioctl_iface(ifname, drv, param, len)) {
-		printf("Could not set beacon data to kernel driver.\n");
-		printf("ifname='%s' head=%p head_len=%d tail=%p tail_len=%d "
-		       "cmd=%d\n",
-		       ifname, head, head_len, tail, tail_len, param->cmd);
-		ret = -1;
-	}
+	msg = nlmsg_alloc();
+	if (!msg)
+		goto out;
 
-	free(param);
+	if (drv->beacon_set)
+		cmd = NL80211_CMD_SET_BEACON;
+
+	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
+		    0, cmd, 0);
+	NLA_PUT(msg, NL80211_ATTR_BEACON_HEAD, head_len, head);
+	NLA_PUT(msg, NL80211_ATTR_BEACON_TAIL, tail_len, tail);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
+	NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, 1000);
+
+	if (!drv->dtim_period)
+		drv->dtim_period = 2;
+	NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
+
+	if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
+	    nl_wait_for_ack(drv->nl_handle) < 0)
+		goto out;
+
+	ret = 0;
+
+	drv->beacon_set = 1;
+
+ out:
+ nla_put_failure:
+	nlmsg_free(msg);
 	return ret;
 }
 
@@ -985,15 +994,59 @@ static int i802_set_internal_bridge(void
 static int i802_set_beacon_int(void *priv, int value)
 {
 	struct i802_driver_data *drv = priv;
-	return hostap_ioctl_prism2param(drv, PRISM2_PARAM_BEACON_INT, value);
+	struct nl_msg *msg;
+	int ret = -1;
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		goto out;
+
+	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
+		    0, NL80211_CMD_SET_BEACON, 0);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(drv->iface));
+
+	NLA_PUT_U32(msg, NL80211_ATTR_BEACON_INTERVAL, value);
+
+	if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
+	    nl_wait_for_ack(drv->nl_handle) < 0)
+		goto out;
+
+	ret = 0;
+
+ out:
+ nla_put_failure:
+	nlmsg_free(msg);
+	return ret;
 }
 
 
-static int i802_set_dtim_period(const char *ifname, void *priv, int value)
+static int i802_set_dtim_period(const char *iface, void *priv, int value)
 {
 	struct i802_driver_data *drv = priv;
-	return hostap_ioctl_prism2param_iface(ifname, drv,
-					      PRISM2_PARAM_DTIM_PERIOD, value);
+	struct nl_msg *msg;
+	int ret = -1;
+
+	msg = nlmsg_alloc();
+	if (!msg)
+		goto out;
+
+	genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
+		    0, NL80211_CMD_SET_BEACON, 0);
+	NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
+
+	drv->dtim_period = value;
+	NLA_PUT_U32(msg, NL80211_ATTR_DTIM_PERIOD, drv->dtim_period);
+
+	if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
+	    nl_wait_for_ack(drv->nl_handle) < 0)
+		goto out;
+
+	ret = 0;
+
+ out:
+ nla_put_failure:
+	nlmsg_free(msg);
+	return ret;
 }