diff options
author | Felix Fietkau <nbd@openwrt.org> | 2010-10-23 23:39:54 +0000 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2010-10-23 23:39:54 +0000 |
commit | f0a8a11ddfa2d58d9907b07bd537f6ba9e266c71 (patch) | |
tree | ac36be085b9943adcec164d07c4a8f88868d34cd /package | |
parent | 580f1fe5825d817e97ba7aaab5e6d5a432a3f48c (diff) | |
download | master-187ad058-f0a8a11ddfa2d58d9907b07bd537f6ba9e266c71.tar.gz master-187ad058-f0a8a11ddfa2d58d9907b07bd537f6ba9e266c71.tar.bz2 master-187ad058-f0a8a11ddfa2d58d9907b07bd537f6ba9e266c71.zip |
hostapd/mac80211: implement support for AP+STA
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@23602 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package')
-rw-r--r-- | package/hostapd/Makefile | 2 | ||||
-rw-r--r-- | package/hostapd/files/wpa_supplicant.sh | 3 | ||||
-rw-r--r-- | package/hostapd/patches/450-reload_settings.patch | 13 | ||||
-rw-r--r-- | package/hostapd/patches/451-nl80211_del_beacon_bss.patch | 63 | ||||
-rw-r--r-- | package/hostapd/patches/452-ctrl_iface_reload.patch | 96 | ||||
-rw-r--r-- | package/hostapd/patches/453-ap_sta_support.patch | 208 | ||||
-rw-r--r-- | package/mac80211/files/lib/wifi/mac80211.sh | 4 |
7 files changed, 386 insertions, 3 deletions
diff --git a/package/hostapd/Makefile b/package/hostapd/Makefile index 5bcaba9458..172e89b259 100644 --- a/package/hostapd/Makefile +++ b/package/hostapd/Makefile @@ -239,7 +239,7 @@ endef define Build/Compile/wpad echo ` \ $(call Build/RunMake,hostapd,-s MULTICALL=1 dump_cflags); \ - $(call Build/RunMake,wpa_supplicant,-s dump_cflags) | \ + $(call Build/RunMake,wpa_supplicant,-s MULTICALL=1 dump_cflags) | \ sed -e 's,-n ,,g' -e 's,$(TARGET_CFLAGS),,' \ ` > $(PKG_BUILD_DIR)/.cflags $(call Build/RunMake,hostapd, \ diff --git a/package/hostapd/files/wpa_supplicant.sh b/package/hostapd/files/wpa_supplicant.sh index 28d5d20565..515fa6c0da 100644 --- a/package/hostapd/files/wpa_supplicant.sh +++ b/package/hostapd/files/wpa_supplicant.sh @@ -2,6 +2,7 @@ wpa_supplicant_setup_vif() { local vif="$1" local driver="$2" local key="$key" + local options="$3" # wpa_supplicant should use wext for mac80211 cards [ "$driver" = "mac80211" ] && driver='wext' @@ -133,5 +134,5 @@ network={ } EOF [ -z "$proto" -a "$key_mgmt" != "NONE" ] || \ - wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf + wpa_supplicant ${bridge:+ -b $bridge} -B -P "/var/run/wifi-${ifname}.pid" -D ${driver:-wext} -i "$ifname" -c /var/run/wpa_supplicant-$ifname.conf $options } diff --git a/package/hostapd/patches/450-reload_settings.patch b/package/hostapd/patches/450-reload_settings.patch new file mode 100644 index 0000000000..5f226124c3 --- /dev/null +++ b/package/hostapd/patches/450-reload_settings.patch @@ -0,0 +1,13 @@ +--- a/src/ap/hostapd.c ++++ b/src/ap/hostapd.c +@@ -112,6 +112,10 @@ int hostapd_reload_config(struct hostapd + oldconf = hapd->iconf; + iface->conf = newconf; + ++ iface->freq = hostapd_hw_get_freq(hapd, hapd->iconf->channel); ++ if (iface->current_mode) ++ hostapd_prepare_rates(hapd, iface->current_mode); ++ + for (j = 0; j < iface->num_bss; j++) { + hapd = iface->bss[j]; + hapd->iconf = newconf; diff --git a/package/hostapd/patches/451-nl80211_del_beacon_bss.patch b/package/hostapd/patches/451-nl80211_del_beacon_bss.patch new file mode 100644 index 0000000000..b23acc6f01 --- /dev/null +++ b/package/hostapd/patches/451-nl80211_del_beacon_bss.patch @@ -0,0 +1,63 @@ +--- a/src/drivers/driver_nl80211.c ++++ b/src/drivers/driver_nl80211.c +@@ -1604,23 +1604,41 @@ wpa_driver_nl80211_finish_drv_init(struc + } + + +-static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) ++static int wpa_driver_nl80211_del_bss_beacon(struct i802_bss *bss) + { ++ struct wpa_driver_nl80211_data *drv = bss->drv; + struct nl_msg *msg; + ++ bss->beacon_set = 0; ++ + msg = nlmsg_alloc(); + if (!msg) + return -ENOMEM; + + genlmsg_put(msg, 0, 0, genl_family_get_id(drv->nl80211), 0, + 0, NL80211_CMD_DEL_BEACON, 0); +- NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, drv->ifindex); ++ NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); + + return send_and_recv_msgs(drv, msg, NULL, NULL); + nla_put_failure: ++ nlmsg_free(msg); + return -ENOBUFS; + } + ++static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) ++{ ++ struct i802_bss *bss; ++ ++ for (bss = &drv->first_bss; bss; bss = bss->next) ++ wpa_driver_nl80211_del_bss_beacon(bss); ++} ++ ++static int wpa_driver_nl80211_stop_ap(void *priv) ++{ ++ struct i802_bss *bss = priv; ++ ++ wpa_driver_nl80211_del_beacon(bss->drv); ++} + + /** + * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface +@@ -5512,4 +5530,5 @@ const struct wpa_driver_ops wpa_driver_n + .send_ft_action = nl80211_send_ft_action, + .signal_monitor = nl80211_signal_monitor, + .send_frame = nl80211_send_frame, ++ .stop_ap = wpa_driver_nl80211_stop_ap, + }; +--- a/src/drivers/driver.h ++++ b/src/drivers/driver.h +@@ -1774,6 +1774,8 @@ struct wpa_driver_ops { + */ + int (*send_frame)(void *priv, const u8 *data, size_t data_len, + int encrypt); ++ ++ int (*stop_ap)(void *priv); + }; + + diff --git a/package/hostapd/patches/452-ctrl_iface_reload.patch b/package/hostapd/patches/452-ctrl_iface_reload.patch new file mode 100644 index 0000000000..e07ab6d440 --- /dev/null +++ b/package/hostapd/patches/452-ctrl_iface_reload.patch @@ -0,0 +1,96 @@ +--- a/hostapd/ctrl_iface.c ++++ b/hostapd/ctrl_iface.c +@@ -35,6 +35,7 @@ + #include "ap/wps_hostapd.h" + #include "ap/ctrl_iface_ap.h" + #include "ctrl_iface.h" ++#include "config_file.h" + + + struct wpa_ctrl_dst { +@@ -45,6 +46,7 @@ struct wpa_ctrl_dst { + int errors; + }; + ++static char *reload_opts = NULL; + + static void hostapd_ctrl_iface_send(struct hostapd_data *hapd, int level, + const char *buf, size_t len); +@@ -315,6 +317,66 @@ static int hostapd_ctrl_iface_wps_oob(st + #endif /* CONFIG_WPS_OOB */ + #endif /* CONFIG_WPS */ + ++static int hostapd_ctrl_iface_set_down(struct hostapd_data *hapd) ++{ ++ if (hapd->driver->stop_ap) ++ hapd->driver->stop_ap(hapd->drv_priv); ++ return 0; ++} ++ ++static char *get_option(char *opt, char *str) ++{ ++ int len = strlen(str); ++ ++ if (!strncmp(opt, str, len)) ++ return opt + len; ++ else ++ return NULL; ++} ++ ++static struct hostapd_config *hostapd_ctrl_iface_config_read(const char *fname) ++{ ++ struct hostapd_config *conf; ++ char *opt, *val; ++ ++ conf = hostapd_config_read(fname); ++ if (!conf) ++ return NULL; ++ ++ for (opt = strtok(reload_opts, " "); ++ opt; ++ opt = strtok(NULL, " ")) { ++ ++ if ((val = get_option(opt, "channel="))) ++ conf->channel = atoi(val); ++ else if ((val = get_option(opt, "ht_capab="))) ++ conf->ht_capab = atoi(val); ++ else if ((val = get_option(opt, "ht_capab_mask="))) ++ conf->ht_capab &= atoi(val); ++ else if ((val = get_option(opt, "sec_chan="))) ++ conf->secondary_channel = atoi(val); ++ else if ((val = get_option(opt, "hwmode="))) ++ conf->hw_mode = atoi(val); ++ else if ((val = get_option(opt, "ieee80211n="))) ++ conf->ieee80211n = atoi(val); ++ else ++ break; ++ } ++ ++ return conf; ++} ++ ++static int hostapd_ctrl_iface_reload(struct hostapd_data *hapd, char *txt) ++{ ++ struct hostapd_iface *iface = hapd->iface; ++ ++ iface->config_read_cb = hostapd_ctrl_iface_config_read; ++ reload_opts = txt; ++ ++ hostapd_reload_config(iface); ++ ++ iface->config_read_cb = hostapd_config_read; ++} + + static void hostapd_ctrl_iface_receive(int sock, void *eloop_ctx, + void *sock_ctx) +@@ -379,6 +441,10 @@ static void hostapd_ctrl_iface_receive(i + reply_len += res; + } + #endif /* CONFIG_NO_RADIUS */ ++ } else if (os_strcmp(buf, "DOWN") == 0) { ++ hostapd_ctrl_iface_set_down(hapd); ++ } else if (os_strncmp(buf, "RELOAD ", 7) == 0) { ++ hostapd_ctrl_iface_reload(hapd, buf + 7); + } else if (os_strcmp(buf, "STA-FIRST") == 0) { + reply_len = hostapd_ctrl_iface_sta_first(hapd, reply, + reply_size); diff --git a/package/hostapd/patches/453-ap_sta_support.patch b/package/hostapd/patches/453-ap_sta_support.patch new file mode 100644 index 0000000000..02b09bf542 --- /dev/null +++ b/package/hostapd/patches/453-ap_sta_support.patch @@ -0,0 +1,208 @@ +--- a/wpa_supplicant/wpa_supplicant_i.h ++++ b/wpa_supplicant/wpa_supplicant_i.h +@@ -98,6 +98,8 @@ struct wpa_interface { + * receiving of EAPOL frames from an additional interface. + */ + const char *bridge_ifname; ++ ++ const char *hostapd_ctrl; + }; + + /** +@@ -316,6 +318,8 @@ struct wpa_supplicant { + #endif /* CONFIG_CTRL_IFACE_DBUS_NEW */ + char bridge_ifname[16]; + ++ struct wpa_ctrl *hostapd; ++ + char *confname; + struct wpa_config *conf; + int countermeasures; +--- a/wpa_supplicant/Makefile ++++ b/wpa_supplicant/Makefile +@@ -51,6 +51,11 @@ OBJS_p += ../src/utils/wpa_debug.o + OBJS_p += ../src/utils/wpabuf.o + OBJS_c = wpa_cli.o ../src/common/wpa_ctrl.o + ++ifdef MULTICALL ++OBJS += ../src/common/wpa_ctrl.o ++CFLAGS += -DMULTICALL ++endif ++ + -include .config + -include $(if $(MULTICALL),../hostapd/.config) + +--- a/wpa_supplicant/wpa_supplicant.c ++++ b/wpa_supplicant/wpa_supplicant.c +@@ -120,6 +120,58 @@ extern int wpa_debug_show_keys; + extern int wpa_debug_timestamp; + extern struct wpa_driver_ops *wpa_drivers[]; + ++#ifdef MULTICALL ++static int hostapd_stop(struct wpa_supplicant *wpa_s) ++{ ++ const char *cmd = "DOWN"; ++ char buf[256]; ++ int len = sizeof(buf); ++ ++ if (wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL) < 0) { ++ wpa_printf(MSG_ERROR, "\nFailed to stop hostapd AP interfaces\n"); ++ return -1; ++ } ++ return 0; ++} ++ ++static int hostapd_reload(struct wpa_supplicant *wpa_s, struct wpa_bss *bss) ++{ ++ char *cmd = NULL; ++ char buf[256]; ++ int len = sizeof(buf); ++ int channel, hw_mode; ++ int ret; ++ ++ if (!bss) ++ return; ++ ++ if (bss->freq < 4000) { ++ hw_mode = HOSTAPD_MODE_IEEE80211G; ++ channel = (bss->freq - 2407) / 5; ++ } else { ++ hw_mode = HOSTAPD_MODE_IEEE80211A; ++ channel = (bss->freq - 5000) / 5; ++ } ++ ++ if (asprintf(&cmd, "RELOAD channel=%d sec_chan=0 hw_mode=%d ht_capab_mask=%d ieee80211n=%d", ++ channel, hw_mode, bss->ht_capab, !!bss->ht_capab) < 0) { ++ fprintf(stderr, "ASPRINTF FAILED\n"); ++ exit(1); ++ return -1; ++ } ++ ++ wpa_printf(MSG_ERROR, "\n\n-------- RUN COMMAND: %s\n\n", cmd); ++ ret = wpa_ctrl_request(wpa_s->hostapd, cmd, os_strlen(cmd), buf, &len, NULL); ++ free(cmd); ++ ++ if (ret < 0) { ++ wpa_printf(MSG_ERROR, "\nFailed to reload hostapd AP interfaces\n"); ++ return -1; ++ } ++ return 0; ++} ++#endif ++ + /* Configure default/group WEP keys for static WEP */ + int wpa_set_wep_keys(struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid) + { +@@ -548,6 +600,10 @@ void wpa_supplicant_set_state(struct wpa + #ifndef IEEE8021X_EAPOL + wpa_drv_set_supp_port(wpa_s, 1); + #endif ++#ifdef MULTICALL ++ if (wpa_s->hostapd) ++ hostapd_reload(wpa_s, wpa_s->current_bss); ++#endif + } else if (state == WPA_DISCONNECTED || state == WPA_ASSOCIATING || + state == WPA_ASSOCIATED) { + wpa_s->new_connection = 1; +@@ -1957,6 +2013,21 @@ static int wpa_supplicant_init_iface(str + os_strlcpy(wpa_s->bridge_ifname, iface->bridge_ifname, + sizeof(wpa_s->bridge_ifname)); + } ++#ifdef MULTICALL ++ if (iface->hostapd_ctrl) { ++ char *cmd = "DOWN"; ++ char buf[256]; ++ int len = sizeof(buf); ++ ++ wpa_s->hostapd = wpa_ctrl_open(iface->hostapd_ctrl); ++ if (!wpa_s->hostapd) { ++ wpa_printf(MSG_ERROR, "\nFailed to connect to hostapd\n"); ++ return -1; ++ } ++ if (hostapd_stop(wpa_s) < 0) ++ return -1; ++ } ++#endif + + /* RSNA Supplicant Key Management - INITIALIZE */ + eapol_sm_notify_portEnabled(wpa_s->eapol, FALSE); +--- a/wpa_supplicant/bss.c ++++ b/wpa_supplicant/bss.c +@@ -17,6 +17,7 @@ + #include "utils/common.h" + #include "utils/eloop.h" + #include "common/ieee802_11_defs.h" ++#include "common/ieee802_11_common.h" + #include "drivers/driver.h" + #include "wpa_supplicant_i.h" + #include "config.h" +@@ -89,6 +90,8 @@ struct wpa_bss * wpa_bss_get(struct wpa_ + + static void wpa_bss_copy_res(struct wpa_bss *dst, struct wpa_scan_res *src) + { ++ struct ieee80211_ht_capabilities *capab; ++ struct ieee802_11_elems elems; + os_time_t usec; + + dst->flags = src->flags; +@@ -101,6 +104,12 @@ static void wpa_bss_copy_res(struct wpa_ + dst->level = src->level; + dst->tsf = src->tsf; + ++ memset(&elems, 0, sizeof(elems)); ++ ieee802_11_parse_elems((u8 *) (src + 1), src->ie_len, &elems, 0); ++ capab = (struct ieee80211_ht_capabilities *) elems.ht_capabilities; ++ if (capab) ++ dst->ht_capab = le_to_host16(capab->ht_capabilities_info); ++ + os_get_time(&dst->last_update); + dst->last_update.sec -= src->age / 1000; + usec = (src->age % 1000) * 1000; +--- a/wpa_supplicant/bss.h ++++ b/wpa_supplicant/bss.h +@@ -56,6 +56,7 @@ struct wpa_bss { + unsigned int flags; + u8 bssid[ETH_ALEN]; + u8 ssid[32]; ++ u16 ht_capab; + size_t ssid_len; + int freq; + u16 beacon_int; +--- a/wpa_supplicant/main.c ++++ b/wpa_supplicant/main.c +@@ -31,7 +31,7 @@ static void usage(void) + "usage:\n" + " wpa_supplicant [-BddhKLqqstuvW] [-P<pid file>] " + "[-g<global ctrl>] \\\n" +- " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] " ++ " -i<ifname> -c<config file> [-C<ctrl>] [-D<driver>] [-H<hostapd path>]" + "[-p<driver_param>] \\\n" + " [-b<br_ifname>] [-f<debug file>] \\\n" + " [-o<override driver>] [-O<override ctrl>] \\\n" +@@ -67,6 +67,7 @@ static void usage(void) + #endif /* CONFIG_DEBUG_SYSLOG */ + printf(" -t = include timestamp in debug messages\n" + " -h = show this help text\n" ++ " -H = connect to a hostapd instance to manage state changes\n" + " -L = show license (GPL and BSD)\n" + " -o = override driver parameter for new interfaces\n" + " -O = override ctrl_interface parameter for new interfaces\n" +@@ -143,7 +144,7 @@ int main(int argc, char *argv[]) + wpa_supplicant_fd_workaround(); + + for (;;) { +- c = getopt(argc, argv, "b:Bc:C:D:df:g:hi:KLNo:O:p:P:qstuvW"); ++ c = getopt(argc, argv, "b:Bc:C:D:df:g:hH:i:KLNo:O:p:P:qstuvW"); + if (c < 0) + break; + switch (c) { +@@ -184,6 +185,9 @@ int main(int argc, char *argv[]) + usage(); + exitcode = 0; + goto out; ++ case 'H': ++ iface->hostapd_ctrl = optarg; ++ break; + case 'i': + iface->ifname = optarg; + break; diff --git a/package/mac80211/files/lib/wifi/mac80211.sh b/package/mac80211/files/lib/wifi/mac80211.sh index a00cdee1be..67884238fd 100644 --- a/package/mac80211/files/lib/wifi/mac80211.sh +++ b/package/mac80211/files/lib/wifi/mac80211.sh @@ -222,6 +222,7 @@ enable_mac80211() { local macidx=0 local apidx=0 fixed="" + local hostapd_ctrl="" [ -n "$country" ] && iw reg set "$country" [ "$channel" = "auto" -o "$channel" = "0" ] || { @@ -344,6 +345,7 @@ enable_mac80211() { config_get mode "$vif" mode config_get ifname "$vif" ifname [ "$mode" = "ap" ] || continue + hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd-$phy/$ifname}" mac80211_start_vif "$vif" "$ifname" done } @@ -364,7 +366,7 @@ enable_mac80211() { ;; sta) if eval "type wpa_supplicant_setup_vif" 2>/dev/null >/dev/null; then - wpa_supplicant_setup_vif "$vif" nl80211 || { + wpa_supplicant_setup_vif "$vif" nl80211 "${hostapd_ctrl:+-H $hostapd_ctrl}" || { echo "enable_mac80211($device): Failed to set up wpa_supplicant for interface $ifname" >&2 # make sure this wifi interface won't accidentally stay open without encryption ifconfig "$ifname" down |