use cp instead of $(CP), because bzImage might be a symlink
[openwrt.git] / package / hostapd / patches / 003-use-nl80211-for-keys.patch
1 ---
2 hostapd/driver_devicescape.c | 93 ++++++++++++++++++++++++++++++-------------
3 1 file changed, 67 insertions(+), 26 deletions(-)
4
5 --- hostap.orig/hostapd/driver_devicescape.c 2007-11-09 13:41:12.000000000 +0100
6 +++ hostap/hostapd/driver_devicescape.c 2007-11-09 13:41:13.000000000 +0100
7 @@ -150,38 +150,79 @@ static int i802_set_encryption(const cha
8 size_t key_len, int txkey)
9 {
10 struct i802_driver_data *drv = priv;
11 - struct prism2_hostapd_param *param;
12 - u8 *buf;
13 - size_t blen;
14 - int ret = 0;
15 + struct nl_msg *msg;
16 + int ret = -1;
17 + int err = 0;
18
19 - blen = sizeof(*param) + key_len;
20 - buf = os_zalloc(blen);
21 - if (buf == NULL)
22 - return -1;
23 + msg = nlmsg_alloc();
24 + if (!msg)
25 + goto out;
26
27 - param = (struct prism2_hostapd_param *) buf;
28 - param->cmd = PRISM2_SET_ENCRYPTION;
29 - if (addr == NULL)
30 - memset(param->sta_addr, 0xff, ETH_ALEN);
31 - else
32 - memcpy(param->sta_addr, addr, ETH_ALEN);
33 - os_strlcpy((char *) param->u.crypt.alg, alg,
34 - HOSTAP_CRYPT_ALG_NAME_LEN);
35 - param->u.crypt.flags = txkey ? HOSTAP_CRYPT_FLAG_SET_TX_KEY : 0;
36 - param->u.crypt.idx = idx;
37 - param->u.crypt.key_len = key_len;
38 - memcpy(param->u.crypt.key, key, key_len);
39 + if (strcmp(alg, "none") == 0) {
40 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
41 + 0, NL80211_CMD_DEL_KEY, 0);
42 + } else {
43 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
44 + 0, NL80211_CMD_NEW_KEY, 0);
45 + NLA_PUT(msg, NL80211_ATTR_KEY_DATA, key_len, key);
46 + if (strcmp(alg, "WEP") == 0) {
47 + if (key_len == 5)
48 + NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
49 + 0x000FAC01);
50 + else
51 + NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER,
52 + 0x000FAC05);
53 + } else if (strcmp(alg, "TKIP") == 0)
54 + NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC02);
55 + else if (strcmp(alg, "CCMP") == 0)
56 + NLA_PUT_U32(msg, NL80211_ATTR_KEY_CIPHER, 0x000FAC04);
57 + else
58 + goto out;
59 + }
60
61 - if (hostapd_ioctl_iface(iface, drv, param, blen) && errno != ENOENT) {
62 - printf("%s: Failed to set encryption to alg '%s' addr " MACSTR
63 - " errno=%d\n",
64 - iface, alg, MAC2STR(param->sta_addr), errno);
65 - ret = -1;
66 + if (addr)
67 + NLA_PUT(msg, NL80211_ATTR_MAC, ETH_ALEN, addr);
68 + NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
69 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
70 +
71 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
72 + (err = nl_wait_for_ack(drv->nl_handle)) < 0) {
73 + if (err != -ENOENT) {
74 + err = 0;
75 + goto out;
76 + }
77 }
78
79 - free(buf);
80 + if (!txkey) {
81 + ret = 0;
82 + goto out;
83 + }
84 +
85 + nlmsg_free(msg);
86 +
87 + msg = nlmsg_alloc();
88 + if (!msg)
89 + goto out;
90
91 + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0,
92 + 0, NL80211_CMD_SET_KEY, 0);
93 + NLA_PUT_U8(msg, NL80211_ATTR_KEY_IDX, idx);
94 + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, if_nametoindex(iface));
95 + NLA_PUT_FLAG(msg, NL80211_ATTR_KEY_DEFAULT);
96 +
97 + if (nl_send_auto_complete(drv->nl_handle, msg) < 0 ||
98 + (err = nl_wait_for_ack(drv->nl_handle)) < 0) {
99 + if (err != -ENOENT) {
100 + err = 0;
101 + goto out;
102 + }
103 + }
104 +
105 + ret = 0;
106 +
107 + out:
108 + nla_put_failure:
109 + nlmsg_free(msg);
110 return ret;
111 }
112
This page took 0.055424 seconds and 5 git commands to generate.