diff --git a/ffho/ffho-openwrt-migration-tools/Makefile b/ffho/ffho-openwrt-migration-tools/Makefile index 6297656abf27379041d6d2d157ce56f42e26f6c4..a68733b38df1d886ddb0d6e4d113c27603a5809e 100644 --- a/ffho/ffho-openwrt-migration-tools/Makefile +++ b/ffho/ffho-openwrt-migration-tools/Makefile @@ -35,30 +35,11 @@ define Build/Compile endef define Package/ffho-openwrt-migration-tools/preinst -#!/bin/sh -cd "$${IPKG_INSTROOT}/lib/netifd/wireless/" -if [ -f "mac80211.sh" ] ; then - /bin/rm "./mac80211.sh" -fi -cd "$${IPKG_INSTROOT}/lib/netifd/" -if [ -f "hostapd.sh" ] ; then - /bin/rm "./hostapd.sh" -fi -cd "$${IPKG_INSTROOT}/lib/wifi/" -if [ -f "mac80211.sh" ] ; then - /bin/rm "./mac80211.sh" -fi -exit 0 endef define Package/ffho-openwrt-migration-tools/install $(INSTALL_DIR) $(1)/etc/uci-defaults/ - $(INSTALL_DIR) $(1)/lib/netifd/wireless/ - $(INSTALL_DIR) $(1)/lib/wifi/ $(INSTALL_BIN) ./files/etc/uci-defaults/40-wireless-config-hwmode-fix $(1)/etc/uci-defaults/ - $(INSTALL_BIN) ./files/lib/netifd/wireless/mac80211.sh $(1)/lib/netifd/wireless/ - $(CP) ./files/lib/netifd/hostapd.sh $(1)/lib/netifd/ - $(CP) ./files/lib/wifi/mac80211.sh $(1)/lib/wifi/ endef $(eval $(call BuildPackage,ffho-openwrt-migration-tools)) diff --git a/ffho/ffho-openwrt-migration-tools/files/lib/netifd/hostapd.sh b/ffho/ffho-openwrt-migration-tools/files/lib/netifd/hostapd.sh deleted file mode 100644 index 3a64689428d5a3bc529ea89adc7a215c7cc2c543..0000000000000000000000000000000000000000 --- a/ffho/ffho-openwrt-migration-tools/files/lib/netifd/hostapd.sh +++ /dev/null @@ -1,646 +0,0 @@ -wpa_supplicant_add_rate() { - local var="$1" - local val="$(($2 / 1000))" - local sub="$((($2 / 100) % 10))" - append $var "$val" "," - [ $sub -gt 0 ] && append $var "." -} - -hostapd_add_rate() { - local var="$1" - local val="$(($2 / 100))" - append $var "$val" " " -} - -hostapd_append_wep_key() { - local var="$1" - - wep_keyidx=0 - set_default key 1 - case "$key" in - [1234]) - for idx in 1 2 3 4; do - local zidx - zidx=$(($idx - 1)) - json_get_var ckey "key${idx}" - [ -n "$ckey" ] && \ - append $var "wep_key${zidx}=$(prepare_key_wep "$ckey")" "$N$T" - done - wep_keyidx=$((key - 1)) - ;; - *) - append $var "wep_key0=$(prepare_key_wep "$key")" "$N$T" - ;; - esac -} - -hostapd_add_log_config() { - config_add_boolean \ - log_80211 \ - log_8021x \ - log_radius \ - log_wpa \ - log_driver \ - log_iapp \ - log_mlme - - config_add_int log_level -} - -hostapd_common_add_device_config() { - config_add_array basic_rate - config_add_array supported_rates - - config_add_string country - config_add_boolean country_ie doth - config_add_string require_mode - - hostapd_add_log_config -} - -hostapd_prepare_device_config() { - local config="$1" - local driver="$2" - - local base="${config%%.conf}" - local base_cfg= - - json_get_vars country country_ie beacon_int doth require_mode - - hostapd_set_log_options base_cfg - - set_default country_ie 1 - set_default doth 1 - - [ -n "$country" ] && { - append base_cfg "country_code=$country" "$N" - - [ "$country_ie" -gt 0 ] && append base_cfg "ieee80211d=1" "$N" - [ "$hwmode" = "a" -a "$doth" -gt 0 ] && append base_cfg "ieee80211h=1" "$N" - } - [ -n "$hwmode" ] && append base_cfg "hw_mode=$hwmode" "$N" - - local brlist= br - json_get_values basic_rate_list basic_rate - for br in $basic_rate_list; do - hostapd_add_rate brlist "$br" - done - case "$require_mode" in - g) brlist="60 120 240" ;; - n) append base_cfg "require_ht=1" "$N";; - ac) append base_cfg "require_vht=1" "$N";; - esac - - local rlist= r - json_get_values rate_list supported_rates - for r in $rate_list; do - hostapd_add_rate rlist "$r" - done - - [ -n "$rlist" ] && append base_cfg "supported_rates=$rlist" "$N" - [ -n "$brlist" ] && append base_cfg "basic_rates=$brlist" "$N" - [ -n "$beacon_int" ] && append base_cfg "beacon_int=$beacon_int" "$N" - - cat > "$config" <<EOF -driver=$driver -$base_cfg -EOF -} - -hostapd_common_add_bss_config() { - config_add_string 'bssid:macaddr' 'ssid:string' - config_add_boolean wds wmm uapsd hidden - - config_add_int maxassoc max_inactivity - config_add_boolean disassoc_low_ack isolate short_preamble - - config_add_int \ - wep_rekey eap_reauth_period \ - wpa_group_rekey wpa_pair_rekey wpa_master_rekey - - config_add_boolean rsn_preauth auth_cache - config_add_int ieee80211w - - config_add_string 'auth_server:host' 'server:host' - config_add_string auth_secret - config_add_int 'auth_port:port' 'port:port' - - config_add_string acct_server - config_add_string acct_secret - config_add_int acct_port - - config_add_string dae_client - config_add_string dae_secret - config_add_int dae_port - - config_add_string nasid - config_add_string ownip - config_add_string iapp_interface - config_add_string eap_type ca_cert client_cert identity auth priv_key priv_key_pwd - - config_add_int dynamic_vlan vlan_naming - config_add_string vlan_tagged_interface vlan_bridge - - config_add_string 'key1:wepkey' 'key2:wepkey' 'key3:wepkey' 'key4:wepkey' 'password:wpakey' - - config_add_string wpa_psk_file - - config_add_boolean wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 - config_add_string wps_device_type wps_device_name wps_manufacturer wps_pin - - config_add_int ieee80211w_max_timeout ieee80211w_retry_timeout - - config_add_string macfilter 'macfile:file' - config_add_array 'maclist:list(macaddr)' - - config_add_array bssid_blacklist - config_add_array bssid_whitelist - - config_add_int mcast_rate - config_add_array basic_rate - config_add_array supported_rates -} - -hostapd_set_bss_options() { - local var="$1" - local phy="$2" - local vif="$3" - - wireless_vif_parse_encryption - - local bss_conf - local wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey - - json_get_vars \ - wep_rekey wpa_group_rekey wpa_pair_rekey wpa_master_rekey \ - maxassoc max_inactivity disassoc_low_ack isolate auth_cache \ - wps_pushbutton wps_label ext_registrar wps_pbc_in_m1 \ - wps_device_type wps_device_name wps_manufacturer wps_pin \ - macfilter ssid wmm uapsd hidden short_preamble rsn_preauth \ - iapp_interface - - set_default isolate 0 - set_default maxassoc 0 - set_default max_inactivity 0 - set_default short_preamble 1 - set_default disassoc_low_ack 1 - set_default hidden 0 - set_default wmm 1 - set_default uapsd 1 - - append bss_conf "ctrl_interface=/var/run/hostapd" - if [ "$isolate" -gt 0 ]; then - append bss_conf "ap_isolate=$isolate" "$N" - fi - if [ "$maxassoc" -gt 0 ]; then - append bss_conf "max_num_sta=$maxassoc" "$N" - fi - if [ "$max_inactivity" -gt 0 ]; then - append bss_conf "ap_max_inactivity=$max_inactivity" "$N" - fi - - append bss_conf "disassoc_low_ack=$disassoc_low_ack" "$N" - append bss_conf "preamble=$short_preamble" "$N" - append bss_conf "wmm_enabled=$wmm" "$N" - append bss_conf "ignore_broadcast_ssid=$hidden" "$N" - append bss_conf "uapsd_advertisement_enabled=$uapsd" "$N" - - [ "$wpa" -gt 0 ] && { - [ -n "$wpa_group_rekey" ] && append bss_conf "wpa_group_rekey=$wpa_group_rekey" "$N" - [ -n "$wpa_pair_rekey" ] && append bss_conf "wpa_ptk_rekey=$wpa_pair_rekey" "$N" - [ -n "$wpa_master_rekey" ] && append bss_conf "wpa_gmk_rekey=$wpa_master_rekey" "$N" - } - - case "$auth_type" in - none) - wps_possible=1 - # Here we make the assumption that if we're in open mode - # with WPS enabled, we got to be in unconfigured state. - wps_not_configured=1 - ;; - psk) - json_get_vars key wpa_psk_file - if [ ${#key} -lt 8 ]; then - wireless_setup_vif_failed INVALID_WPA_PSK - return 1 - elif [ ${#key} -eq 64 ]; then - append bss_conf "wpa_psk=$key" "$N" - else - append bss_conf "wpa_passphrase=$key" "$N" - fi - [ -n "$wpa_psk_file" ] && { - [ -e "$wpa_psk_file" ] || touch "$wpa_psk_file" - append bss_conf "wpa_psk_file=$wpa_psk_file" "$N" - } - wps_possible=1 - ;; - eap) - json_get_vars \ - auth_server auth_secret auth_port \ - acct_server acct_secret acct_port \ - dae_client dae_secret dae_port \ - nasid ownip \ - eap_reauth_period dynamic_vlan \ - vlan_naming vlan_tagged_interface \ - vlan_bridge - - # legacy compatibility - [ -n "$auth_server" ] || json_get_var auth_server server - [ -n "$auth_port" ] || json_get_var auth_port port - [ -n "$auth_secret" ] || json_get_var auth_secret key - - set_default auth_port 1812 - set_default acct_port 1813 - set_default dae_port 3799 - - set_default vlan_naming 1 - - append bss_conf "auth_server_addr=$auth_server" "$N" - append bss_conf "auth_server_port=$auth_port" "$N" - append bss_conf "auth_server_shared_secret=$auth_secret" "$N" - - [ -n "$acct_server" ] && { - append bss_conf "acct_server_addr=$acct_server" "$N" - append bss_conf "acct_server_port=$acct_port" "$N" - [ -n "$acct_secret" ] && \ - append bss_conf "acct_server_shared_secret=$acct_secret" "$N" - } - - [ -n "$eap_reauth_period" ] && append bss_conf "eap_reauth_period=$eap_reauth_period" "$N" - - [ -n "$dae_client" -a -n "$dae_secret" ] && { - append bss_conf "radius_das_port=$dae_port" "$N" - append bss_conf "radius_das_client=$dae_client $dae_secret" "$N" - } - - append bss_conf "nas_identifier=$nasid" "$N" - [ -n "$ownip" ] && append bss_conf "own_ip_addr=$ownip" "$N" - append bss_conf "eapol_key_index_workaround=1" "$N" - append bss_conf "ieee8021x=1" "$N" - append bss_conf "wpa_key_mgmt=WPA-EAP" "$N" - - [ -n "$dynamic_vlan" ] && { - append bss_conf "dynamic_vlan=$dynamic_vlan" "$N" - append bss_conf "vlan_naming=$vlan_naming" "$N" - [ -n "$vlan_bridge" ] && \ - append bss_conf "vlan_bridge=$vlan_bridge" "$N" - [ -n "$vlan_tagged_interface" ] && \ - append bss_conf "vlan_tagged_interface=$vlan_tagged_interface" "$N" - } - ;; - wep) - local wep_keyidx=0 - json_get_vars key - hostapd_append_wep_key bss_conf - append bss_conf "wep_default_key=$wep_keyidx" "$N" - [ -n "$wep_rekey" ] && append bss_conf "wep_rekey_period=$wep_rekey" "$N" - ;; - esac - - local auth_algs=$((($auth_mode_shared << 1) | $auth_mode_open)) - append bss_conf "auth_algs=${auth_algs:-1}" "$N" - append bss_conf "wpa=$wpa" "$N" - [ -n "$wpa_pairwise" ] && append bss_conf "wpa_pairwise=$wpa_pairwise" "$N" - - set_default wps_pushbutton 0 - set_default wps_label 0 - set_default wps_pbc_in_m1 0 - - config_methods= - [ "$wps_pushbutton" -gt 0 ] && append config_methods push_button - [ "$wps_label" -gt 0 ] && append config_methods label - - [ -n "$wps_possible" -a -n "$config_methods" ] && { - set_default ext_registrar 0 - set_default wps_device_type "6-0050F204-1" - set_default wps_device_name "OpenWrt AP" - set_default wps_manufacturer "openwrt.org" - - wps_state=2 - [ -n "$wps_configured" ] && wps_state=1 - - [ "$ext_registrar" -gt 0 -a -n "$network_bridge" ] && append bss_conf "upnp_iface=$network_bridge" "$N" - - append bss_conf "eap_server=1" "$N" - [ -n "$wps_pin" ] && append bss_conf "ap_pin=$wps_pin" "$N" - append bss_conf "wps_state=$wps_state" "$N" - append bss_conf "ap_setup_locked=0" "$N" - append bss_conf "device_type=$wps_device_type" "$N" - append bss_conf "device_name=$wps_device_name" "$N" - append bss_conf "manufacturer=$wps_manufacturer" "$N" - append bss_conf "config_methods=$config_methods" "$N" - [ "$wps_pbc_in_m1" -gt 0 ] && append bss_conf "pbc_in_m1=$wps_pbc_in_m1" "$N" - } - - append bss_conf "ssid=$ssid" "$N" - [ -n "$network_bridge" ] && append bss_conf "bridge=$network_bridge" "$N" - [ -n "$iapp_interface" ] && { - iapp_interface="$(uci_get_state network "$iapp_interface" ifname "$iapp_interface")" - [ -n "$iapp_interface" ] && append bss_conf "iapp_interface=$iapp_interface" "$N" - } - - if [ "$wpa" -ge "2" ]; then - if [ -n "$network_bridge" -a "$rsn_preauth" = 1 ]; then - set_default auth_cache 1 - append bss_conf "rsn_preauth=1" "$N" - append bss_conf "rsn_preauth_interfaces=$network_bridge" "$N" - else - set_default auth_cache 0 - fi - - append bss_conf "okc=$auth_cache" "$N" - [ "$auth_cache" = 0 ] && append bss_conf "disable_pmksa_caching=1" "$N" - - # RSN -> allow management frame protection - json_get_var ieee80211w ieee80211w - case "$ieee80211w" in - [012]) - json_get_vars ieee80211w_max_timeout ieee80211w_retry_timeout - append bss_conf "ieee80211w=$ieee80211w" "$N" - [ "$ieee80211w" -gt "0" ] && { - [ -n "$ieee80211w_max_timeout" ] && \ - append bss_conf "assoc_sa_query_max_timeout=$ieee80211w_max_timeout" "$N" - [ -n "$ieee80211w_retry_timeout" ] && \ - append bss_conf "assoc_sa_query_retry_timeout=$ieee80211w_retry_timeout" "$N" - } - ;; - esac - fi - - _macfile="/var/run/hostapd-$ifname.maclist" - case "$macfilter" in - allow) - append bss_conf "macaddr_acl=1" "$N" - append bss_conf "accept_mac_file=$_macfile" "$N" - ;; - deny) - append bss_conf "macaddr_acl=0" "$N" - append bss_conf "deny_mac_file=$_macfile" "$N" - ;; - *) - _macfile="" - ;; - esac - - [ -n "$_macfile" ] && { - json_get_vars macfile - json_get_values maclist maclist - - rm -f "$_macfile" - ( - for mac in $maclist; do - echo "$mac" - done - [ -n "$macfile" -a -f "$macfile" ] && cat "$macfile" - ) > "$_macfile" - } - - append "$var" "$bss_conf" "$N" - return 0 -} - -hostapd_set_log_options() { - local var="$1" - - local log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme - json_get_vars log_level log_80211 log_8021x log_radius log_wpa log_driver log_iapp log_mlme - - set_default log_level 2 - set_default log_80211 1 - set_default log_8021x 1 - set_default log_radius 1 - set_default log_wpa 1 - set_default log_driver 1 - set_default log_iapp 1 - set_default log_mlme 1 - - local log_mask=$(( \ - ($log_80211 << 0) | \ - ($log_8021x << 1) | \ - ($log_radius << 2) | \ - ($log_wpa << 3) | \ - ($log_driver << 4) | \ - ($log_iapp << 5) | \ - ($log_mlme << 6) \ - )) - - append "$var" "logger_syslog=$log_mask" "$N" - append "$var" "logger_syslog_level=$log_level" "$N" - append "$var" "logger_stdout=$log_mask" "$N" - append "$var" "logger_stdout_level=$log_level" "$N" - - return 0 -} - -_wpa_supplicant_common() { - local ifname="$1" - - _rpath="/var/run/wpa_supplicant" - _config="${_rpath}-$ifname.conf" -} - -wpa_supplicant_teardown_interface() { - _wpa_supplicant_common "$1" - rm -rf "$_rpath/$1" "$_config" -} - -wpa_supplicant_prepare_interface() { - local ifname="$1" - _w_driver="$2" - - _wpa_supplicant_common "$1" - - json_get_vars mode wds - - [ -n "$network_bridge" ] && { - fail= - case "$mode" in - adhoc) - fail=1 - ;; - sta) - [ "$wds" = 1 ] || fail=1 - ;; - esac - - [ -n "$fail" ] && { - wireless_setup_vif_failed BRIDGE_NOT_ALLOWED - return 1 - } - } - - local ap_scan= - - _w_mode="$mode" - _w_modestr= - - [[ "$mode" = adhoc ]] && { - ap_scan="ap_scan=2" - - _w_modestr="mode=1" - } - - wpa_supplicant_teardown_interface "$ifname" - cat > "$_config" <<EOF -$ap_scan -EOF - return 0 -} - -wpa_supplicant_add_network() { - local ifname="$1" - - _wpa_supplicant_common "$1" - wireless_vif_parse_encryption - - json_get_vars \ - ssid bssid key \ - basic_rate mcast_rate \ - ieee80211w - - local key_mgmt='NONE' - local enc_str= - local network_data= - local T=" " - - local wpa_key_mgmt="WPA-PSK" - local scan_ssid="1" - local freq - - [[ "$_w_mode" = "adhoc" ]] && { - append network_data "mode=1" "$N$T" - [ -n "$channel" ] && { - freq="$(get_freq "$phy" "$channel")" - append network_data "fixed_freq=1" "$N$T" - append network_data "frequency=$freq" "$N$T" - } - - scan_ssid=0 - - [ "$_w_driver" = "nl80211" ] || wpa_key_mgmt="WPA-NONE" - } - - [[ "$_w_mode" = adhoc ]] && append network_data "$_w_modestr" "$N$T" - - case "$auth_type" in - none) ;; - wep) - local wep_keyidx=0 - hostapd_append_wep_key network_data - append network_data "wep_tx_keyidx=$wep_keyidx" "$N$T" - ;; - psk) - local passphrase - - key_mgmt="$wpa_key_mgmt" - if [ ${#key} -eq 64 ]; then - passphrase="psk=${key}" - else - passphrase="psk=\"${key}\"" - fi - append network_data "$passphrase" "$N$T" - ;; - eap) - key_mgmt='WPA-EAP' - - json_get_vars eap_type identity ca_cert - [ -n "$ca_cert" ] && append network_data "ca_cert=\"$ca_cert\"" "$N$T" - [ -n "$identity" ] && append network_data "identity=\"$identity\"" "$N$T" - case "$eap_type" in - tls) - json_get_vars client_cert priv_key priv_key_pwd - append network_data "client_cert=\"$client_cert\"" "$N$T" - append network_data "private_key=\"$priv_key\"" "$N$T" - append network_data "private_key_passwd=\"$priv_key_pwd\"" "$N$T" - ;; - peap|ttls) - json_get_vars auth password - set_default auth MSCHAPV2 - append network_data "phase2=\"$auth\"" "$N$T" - append network_data "password=\"$password\"" "$N$T" - ;; - esac - append network_data "eap=$(echo $eap_type | tr 'a-z' 'A-Z')" "$N$T" - ;; - esac - - case "$wpa" in - 1) - append network_data "proto=WPA" "$N$T" - ;; - 2) - append network_data "proto=RSN" "$N$T" - ;; - esac - - case "$ieee80211w" in - [012]) - [ "$wpa" -ge 2 ] && append network_data "ieee80211w=$ieee80211w" "$N$T" - ;; - esac - - local beacon_int brates mrate - [ -n "$bssid" ] && append network_data "bssid=$bssid" "$N$T" - [ -n "$beacon_int" ] && append network_data "beacon_int=$beacon_int" "$N$T" - - local bssid_blacklist bssid_whitelist - json_get_values bssid_blacklist bssid_blacklist - json_get_values bssid_whitelist bssid_whitelist - - [ -n "$bssid_blacklist" ] && append network_data "bssid_blacklist=$bssid_blacklist" "$N$T" - [ -n "$bssid_whitelist" ] && append network_data "bssid_whitelist=$bssid_whitelist" "$N$T" - - [ -n "$basic_rate" ] && { - local br rate_list= - for br in $basic_rate; do - wpa_supplicant_add_rate rate_list "$br" - done - [ -n "$rate_list" ] && append network_data "rates=$rate_list" "$N$T" - } - - [ -n "$mcast_rate" ] && { - local mc_rate= - wpa_supplicant_add_rate mc_rate "$mcast_rate" - append network_data "mcast_rate=$mc_rate" "$N$T" - } - - local ht_str - [[ "$_w_mode" = adhoc ]] || ibss_htmode= - [ -n "$ibss_htmode" ] && append network_data "htmode=$ibss_htmode" "$N$T" - - cat >> "$_config" <<EOF -network={ - scan_ssid=$scan_ssid - ssid="$ssid" - key_mgmt=$key_mgmt - $network_data -} -EOF - return 0 -} - -wpa_supplicant_run() { - local ifname="$1"; shift - - _wpa_supplicant_common "$ifname" - - /usr/sbin/wpa_supplicant -B \ - ${network_bridge:+-b $network_bridge} \ - -P "/var/run/wpa_supplicant-${ifname}.pid" \ - -D ${_w_driver:-wext} \ - -i "$ifname" \ - -c "$_config" \ - -C "$_rpath" \ - "$@" - - ret="$?" - wireless_add_process "$(cat "/var/run/wpa_supplicant-${ifname}.pid")" /usr/sbin/wpa_supplicant 1 - - [ "$ret" != 0 ] && wireless_setup_vif_failed WPA_SUPPLICANT_FAILED - - return $ret -} - -hostapd_common_cleanup() { - killall hostapd wpa_supplicant meshd-nl80211 -} diff --git a/ffho/ffho-openwrt-migration-tools/files/lib/netifd/wireless/mac80211.sh b/ffho/ffho-openwrt-migration-tools/files/lib/netifd/wireless/mac80211.sh deleted file mode 100755 index c7935b567fcbccae54c1bc45e03ca4920f069d0e..0000000000000000000000000000000000000000 --- a/ffho/ffho-openwrt-migration-tools/files/lib/netifd/wireless/mac80211.sh +++ /dev/null @@ -1,737 +0,0 @@ -#!/bin/sh -. /lib/netifd/netifd-wireless.sh -. /lib/netifd/hostapd.sh - -init_wireless_driver "$@" - -MP_CONFIG_INT="mesh_retry_timeout mesh_confirm_timeout mesh_holding_timeout mesh_max_peer_links - mesh_max_retries mesh_ttl mesh_element_ttl mesh_hwmp_max_preq_retries - mesh_path_refresh_time mesh_min_discovery_timeout mesh_hwmp_active_path_timeout - mesh_hwmp_preq_min_interval mesh_hwmp_net_diameter_traversal_time mesh_hwmp_rootmode - mesh_hwmp_rann_interval mesh_gate_announcements mesh_sync_offset_max_neighor - mesh_rssi_threshold mesh_hwmp_active_path_to_root_timeout mesh_hwmp_root_interval - mesh_hwmp_confirmation_interval mesh_awake_window mesh_plink_timeout" -MP_CONFIG_BOOL="mesh_auto_open_plinks mesh_fwding" -MP_CONFIG_STRING="mesh_power_mode" - -drv_mac80211_init_device_config() { - hostapd_common_add_device_config - - config_add_string path phy 'macaddr:macaddr' - config_add_string hwmode - config_add_int beacon_int chanbw frag rts - config_add_int rxantenna txantenna antenna_gain txpower distance - config_add_boolean noscan - config_add_array ht_capab - config_add_boolean \ - rxldpc \ - short_gi_80 \ - short_gi_160 \ - tx_stbc_2by1 \ - su_beamformer \ - su_beamformee \ - mu_beamformer \ - mu_beamformee \ - vht_txop_ps \ - htc_vht \ - rx_antenna_pattern \ - tx_antenna_pattern - config_add_int vht_max_a_mpdu_len_exp vht_max_mpdu vht_link_adapt vht160 rx_stbc tx_stbc - config_add_boolean \ - ldpc \ - greenfield \ - short_gi_20 \ - short_gi_40 \ - dsss_cck_40 -} - -drv_mac80211_init_iface_config() { - hostapd_common_add_bss_config - - config_add_string 'macaddr:macaddr' ifname - - config_add_boolean wds powersave - config_add_int maxassoc - config_add_int max_listen_int - config_add_int dtim_period - - # mesh - config_add_string mesh_id - config_add_int $MP_CONFIG_INT - config_add_boolean $MP_CONFIG_BOOL - config_add_string $MP_CONFIG_STRING -} - -mac80211_add_capabilities() { - local __var="$1"; shift - local __mask="$1"; shift - local __out= oifs - - oifs="$IFS" - IFS=: - for capab in "$@"; do - set -- $capab - - [ "$(($4))" -gt 0 ] || continue - [ "$(($__mask & $2))" -eq "$((${3:-$2}))" ] || continue - __out="$__out[$1]" - done - IFS="$oifs" - - export -n -- "$__var=$__out" -} - -mac80211_hostapd_setup_base() { - local phy="$1" - - json_select config - - [ "$auto_channel" -gt 0 ] && channel=acs_survey - - json_get_vars noscan - json_get_values ht_capab_list ht_capab - - ieee80211n=1 - ht_capab= - case "$htmode" in - VHT20|HT20) ;; - HT40*|VHT40|VHT80|VHT160) - case "$hwmode" in - a) - case "$(( ($channel / 4) % 2 ))" in - 1) ht_capab="[HT40+]";; - 0) ht_capab="[HT40-]";; - esac - ;; - *) - case "$htmode" in - HT40+) ht_capab="[HT40+]";; - HT40-) ht_capab="[HT40-]";; - *) - if [ "$channel" -lt 7 ]; then - ht_capab="[HT40+]" - else - ht_capab="[HT40-]" - fi - ;; - esac - ;; - esac - [ "$auto_channel" -gt 0 ] && ht_capab="[HT40+]" - ;; - *) ieee80211n= ;; - esac - - [ -n "$ieee80211n" ] && { - append base_cfg "ieee80211n=1" "$N" - - json_get_vars \ - ldpc:1 \ - greenfield:0 \ - short_gi_20:1 \ - short_gi_40:1 \ - tx_stbc:1 \ - rx_stbc:3 \ - dsss_cck_40:1 - - ht_cap_mask=0 - for cap in $(iw phy "$phy" info | grep 'Capabilities:' | cut -d: -f2); do - ht_cap_mask="$(($ht_cap_mask | $cap))" - done - - cap_rx_stbc=$((($ht_cap_mask >> 8) & 3)) - [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc" - ht_cap_mask="$(( ($ht_cap_mask & ~(0x300)) | ($cap_rx_stbc << 8) ))" - - mac80211_add_capabilities ht_capab_flags $ht_cap_mask \ - LDPC:0x1::$ldpc \ - GF:0x10::$greenfield \ - SHORT-GI-20:0x20::$short_gi_20 \ - SHORT-GI-40:0x40::$short_gi_40 \ - TX-STBC:0x80::$tx_stbc \ - RX-STBC1:0x300:0x100:1 \ - RX-STBC12:0x300:0x200:1 \ - RX-STBC123:0x300:0x300:1 \ - DSSS_CCK-40:0x1000::$dsss_cck_40 - - ht_capab="$ht_capab$ht_capab_flags" - [ -n "$ht_capab" ] && append base_cfg "ht_capab=$ht_capab" "$N" - } - - # 802.11ac - enable_ac=0 - idx="$channel" - case "$htmode" in - VHT20) enable_ac=1;; - VHT40) - case "$(( ($channel / 4) % 2 ))" in - 1) idx=$(($channel + 2));; - 0) idx=$(($channel - 2));; - esac - enable_ac=1 - append base_cfg "vht_oper_chwidth=0" "$N" - append base_cfg "vht_oper_centr_freq_seg0_idx=$idx" "$N" - ;; - VHT80) - case "$(( ($channel / 4) % 4 ))" in - 1) idx=$(($channel + 6));; - 2) idx=$(($channel + 2));; - 3) idx=$(($channel - 2));; - 0) idx=$(($channel - 6));; - esac - enable_ac=1 - append base_cfg "vht_oper_chwidth=1" "$N" - append base_cfg "vht_oper_centr_freq_seg0_idx=$idx" "$N" - ;; - VHT160) - case "$channel" in - 36|40|44|48|52|56|60|64) idx=50;; - 100|104|108|112|116|120|124|128) idx=114;; - esac - enable_ac=1 - append base_cfg "vht_oper_chwidth=2" "$N" - append base_cfg "vht_oper_centr_freq_seg0_idx=$idx" "$N" - ;; - esac - - if [ "$enable_ac" != "0" ]; then - json_get_vars \ - rxldpc:1 \ - short_gi_80:1 \ - short_gi_160:1 \ - tx_stbc_2by1:1 \ - su_beamformer:1 \ - su_beamformee:1 \ - mu_beamformer:1 \ - mu_beamformee:1 \ - vht_txop_ps:1 \ - htc_vht:1 \ - rx_antenna_pattern:1 \ - tx_antenna_pattern:1 \ - vht_max_a_mpdu_len_exp:7 \ - vht_max_mpdu:11454 \ - rx_stbc:4 \ - tx_stbc:4 \ - vht_link_adapt:3 \ - vht160:2 - - append base_cfg "ieee80211ac=1" "$N" - vht_cap=0 - for cap in $(iw phy "$phy" info | awk -F "[()]" '/VHT Capabilities/ { print $2 }'); do - vht_cap="$(($vht_cap | $cap))" - done - - cap_rx_stbc=$((($vht_cap >> 8) & 7)) - [ "$rx_stbc" -lt "$cap_rx_stbc" ] && cap_rx_stbc="$rx_stbc" - ht_cap_mask="$(( ($vht_cap & ~(0x700)) | ($cap_rx_stbc << 8) ))" - - mac80211_add_capabilities vht_capab $vht_cap \ - RXLDPC:0x10::$rxldpc \ - SHORT-GI-80:0x20::$short_gi_80 \ - SHORT-GI-160:0x40::$short_gi_160 \ - TX-STBC-2BY1:0x80::$tx_stbc \ - SU-BEAMFORMER:0x800::$su_beamformer \ - SU-BEAMFORMEE:0x1000::$su_beamformee \ - MU-BEAMFORMER:0x80000::$mu_beamformer \ - MU-BEAMFORMEE:0x100000::$mu_beamformee \ - VHT-TXOP-PS:0x200000::$vht_txop_ps \ - HTC-VHT:0x400000::$htc_vht \ - RX-ANTENNA-PATTERN:0x10000000::$rx_antenna_pattern \ - TX-ANTENNA-PATTERN:0x20000000::$tx_antenna_pattern \ - RX-STBC1:0x700:0x100:1 \ - RX-STBC12:0x700:0x200:1 \ - RX-STBC123:0x700:0x300:1 \ - RX-STBC1234:0x700:0x400:1 \ - - # supported Channel widths - vht160_hw=0 - [ "$(($vht_cap & 12))" -eq 4 -a 1 -le "$vht160" ] && \ - vht160_hw=1 - [ "$(($vht_cap & 12))" -eq 8 -a 2 -le "$vht160" ] && \ - vht160_hw=2 - [ "$vht160_hw" = 1 ] && vht_capab="$vht_capab[VHT160]" - [ "$vht160_hw" = 2 ] && vht_capab="$vht_capab[VHT160-80PLUS80]" - - # maximum MPDU length - vht_max_mpdu_hw=3895 - [ "$(($vht_cap & 3))" -ge 1 -a 7991 -le "$vht_max_mpdu" ] && \ - vht_max_mpdu_hw=7991 - [ "$(($vht_cap & 3))" -ge 2 -a 11454 -le "$vht_max_mpdu" ] && \ - vht_max_mpdu_hw=11454 - [ "$vht_max_mpdu_hw" != 3895 ] && \ - vht_capab="$vht_capab[MAX-MPDU-$vht_max_mpdu_hw]" - - # maximum A-MPDU length exponent - vht_max_a_mpdu_len_exp_hw=0 - [ "$(($vht_cap & 58720256))" -ge 8388608 -a 1 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=1 - [ "$(($vht_cap & 58720256))" -ge 16777216 -a 2 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=2 - [ "$(($vht_cap & 58720256))" -ge 25165824 -a 3 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=3 - [ "$(($vht_cap & 58720256))" -ge 33554432 -a 4 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=4 - [ "$(($vht_cap & 58720256))" -ge 41943040 -a 5 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=5 - [ "$(($vht_cap & 58720256))" -ge 50331648 -a 6 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=6 - [ "$(($vht_cap & 58720256))" -ge 58720256 -a 7 -le "$vht_max_a_mpdu_len_exp" ] && \ - vht_max_a_mpdu_len_exp_hw=7 - vht_capab="$vht_capab[MAX-A-MPDU-LEN-EXP$vht_max_a_mpdu_len_exp_hw]" - - # whether or not the STA supports link adaptation using VHT variant - vht_link_adapt_hw=0 - [ "$(($vht_cap & 201326592))" -ge 134217728 -a 2 -le "$vht_link_adapt" ] && \ - vht_link_adapt_hw=2 - [ "$(($vht_cap & 201326592))" -ge 201326592 -a 3 -le "$vht_link_adapt" ] && \ - vht_link_adapt_hw=3 - [ "$vht_link_adapt_hw" != 0 ] && \ - vht_capab="$vht_capab[VHT-LINK-ADAPT-$vht_link_adapt_hw]" - - [ -n "$vht_capab" ] && append base_cfg "vht_capab=$vht_capab" "$N" - fi - - hostapd_prepare_device_config "$hostapd_conf_file" nl80211 - cat >> "$hostapd_conf_file" <<EOF -${channel:+channel=$channel} -${noscan:+noscan=$noscan} -$base_cfg - -EOF - json_select .. -} - -mac80211_hostapd_setup_bss() { - local phy="$1" - local ifname="$2" - local macaddr="$3" - local type="$4" - - hostapd_cfg= - append hostapd_cfg "$type=$ifname" "$N" - - hostapd_set_bss_options hostapd_cfg "$vif" || return 1 - json_get_vars wds dtim_period max_listen_int - - set_default wds 0 - - [ "$wds" -gt 0 ] && append hostapd_cfg "wds_sta=1" "$N" - [ "$staidx" -gt 0 ] && append hostapd_cfg "start_disabled=1" "$N" - - cat >> /var/run/hostapd-$phy.conf <<EOF -$hostapd_cfg -bssid=$macaddr -${dtim_period:+dtim_period=$dtim_period} -${max_listen_int:+max_listen_interval=$max_listen_int} -EOF -} - -mac80211_get_addr() { - local phy="$1" - local idx="$(($2 + 1))" - - head -n $(($macidx + 1)) /sys/class/ieee80211/${phy}/addresses | tail -n1 -} - -mac80211_generate_mac() { - local phy="$1" - local id="${macidx:-0}" - - local ref="$(cat /sys/class/ieee80211/${phy}/macaddress)" - local mask="$(cat /sys/class/ieee80211/${phy}/address_mask)" - - [ "$mask" = "00:00:00:00:00:00" ] && { - mask="ff:ff:ff:ff:ff:ff"; - - [ "$(wc -l < /sys/class/ieee80211/${phy}/addresses)" -gt 1 ] && { - addr="$(mac80211_get_addr "$phy" "$id")" - [ -n "$addr" ] && { - echo "$addr" - return - } - } - } - - local oIFS="$IFS"; IFS=":"; set -- $mask; IFS="$oIFS" - - local mask1=$1 - local mask6=$6 - - local oIFS="$IFS"; IFS=":"; set -- $ref; IFS="$oIFS" - - macidx=$(($id + 1)) - [ "$((0x$mask1))" -gt 0 ] && { - b1="0x$1" - [ "$id" -gt 0 ] && \ - b1=$(($b1 ^ ((($id - 1) << 2) | 0x2))) - printf "%02x:%s:%s:%s:%s:%s" $b1 $2 $3 $4 $5 $6 - return - } - - [ "$((0x$mask6))" -lt 255 ] && { - printf "%s:%s:%s:%s:%s:%02x" $1 $2 $3 $4 $5 $(( 0x$6 ^ $id )) - return - } - - off2=$(( (0x$6 + $id) / 0x100 )) - printf "%s:%s:%s:%s:%02x:%02x" \ - $1 $2 $3 $4 \ - $(( (0x$5 + $off2) % 0x100 )) \ - $(( (0x$6 + $id) % 0x100 )) -} - -find_phy() { - [ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0 - [ -n "$path" ] && { - for phy in /sys/devices/$path/ieee80211/phy*; do - [ -e "$phy" ] && { - phy="${phy##*/}" - return 0 - } - done - } - [ -n "$macaddr" ] && { - for phy in $(ls /sys/class/ieee80211 2>/dev/null); do - grep -i -q "$macaddr" "/sys/class/ieee80211/${phy}/macaddress" && return 0 - done - } - return 1 -} - -mac80211_check_ap() { - has_ap=1 -} - -mac80211_prepare_vif() { - json_select config - - json_get_vars ifname mode ssid wds powersave macaddr - - [ -n "$ifname" ] || ifname="wlan${phy#phy}${if_idx:+-$if_idx}" - if_idx=$((${if_idx:-0} + 1)) - - set_default wds 0 - set_default powersave 0 - - json_select .. - - [ -n "$macaddr" ] || { - macaddr="$(mac80211_generate_mac $phy)" - macidx="$(($macidx + 1))" - } - - json_add_object data - json_add_string ifname "$ifname" - json_close_object - json_select config - - # It is far easier to delete and create the desired interface - case "$mode" in - adhoc) - iw phy "$phy" interface add "$ifname" type adhoc - ;; - ap) - # Hostapd will handle recreating the interface and - # subsequent virtual APs belonging to the same PHY - if [ -n "$hostapd_ctrl" ]; then - type=bss - else - type=interface - fi - - mac80211_hostapd_setup_bss "$phy" "$ifname" "$macaddr" "$type" || return - - [ -n "$hostapd_ctrl" ] || { - iw phy "$phy" interface add "$ifname" type managed - hostapd_ctrl="${hostapd_ctrl:-/var/run/hostapd/$ifname}" - } - ;; - mesh) - json_get_vars key mesh_id - if [ -n "$key" ]; then - iw phy "$phy" interface add "$ifname" type mp - else - iw phy "$phy" interface add "$ifname" type mp mesh_id "$mesh_id" - fi - ;; - monitor) - iw phy "$phy" interface add "$ifname" type monitor - ;; - sta) - local wdsflag= - staidx="$(($staidx + 1))" - [ "$wds" -gt 0 ] && wdsflag="4addr on" - iw phy "$phy" interface add "$ifname" type managed $wdsflag - [ "$powersave" -gt 0 ] && powersave="on" || powersave="off" - iw "$ifname" set power_save "$powersave" - ;; - esac - - case "$mode" in - monitor|mesh) - [ "$auto_channel" -gt 0 ] || iw dev "$ifname" set channel "$channel" $htmode - ;; - esac - - if [ "$mode" != "ap" ]; then - # ALL ap functionality will be passed to hostapd - # All interfaces must have unique mac addresses - # which can either be explicitly set in the device - # section, or automatically generated - ifconfig "$ifname" hw ether "$macaddr" - fi - - json_select .. -} - -mac80211_setup_supplicant() { - wpa_supplicant_prepare_interface "$ifname" nl80211 || return 1 - wpa_supplicant_add_network "$ifname" - wpa_supplicant_run "$ifname" ${hostapd_ctrl:+-H $hostapd_ctrl} -} - -mac80211_setup_adhoc() { - json_get_vars bssid ssid key mcast_rate - - keyspec= - [ "$auth_type" = "wep" ] && { - set_default key 1 - case "$key" in - [1234]) - local idx - for idx in 1 2 3 4; do - json_get_var ikey "key$idx" - - [ -n "$ikey" ] && { - ikey="$(($idx - 1)):$(prepare_key_wep "$ikey")" - [ $idx -eq $key ] && ikey="d:$ikey" - append keyspec "$ikey" - } - done - ;; - *) - append keyspec "d:0:$(prepare_key_wep "$key")" - ;; - esac - } - - brstr= - for br in $basic_rate_list; do - wpa_supplicant_add_rate brstr "$br" - done - - mcval= - [ -n "$mcast_rate" ] && wpa_supplicant_add_rate mcval "$mcast_rate" - - case "$htmode" in - VHT20|HT20) ibss_htmode=HT20;; - HT40*|VHT40|VHT80|VHT160) - case "$hwmode" in - a) - case "$(( ($channel / 4) % 2 ))" in - 1) ibss_htmode="HT40+" ;; - 0) ibss_htmode="HT40-";; - esac - ;; - *) - case "$htmode" in - HT40+) ibss_htmode="HT40+";; - HT40-) ibss_htmode="HT40-";; - *) - if [ "$channel" -lt 7 ]; then - ibss_htmode="HT40+" - else - ibss_htmode="HT40-" - fi - ;; - esac - ;; - esac - [ "$auto_channel" -gt 0 ] && ibss_htmode="HT40+" - ;; - *) ibss_htmode="" ;; - esac - - iw dev "$ifname" ibss join "$ssid" $freq $ibss_htmode fixed-freq $bssid \ - ${beacon_int:+beacon-interval $beacon_int} \ - ${brstr:+basic-rates $brstr} \ - ${mcval:+mcast-rate $mcval} \ - ${keyspec:+keys $keyspec} -} - -mac80211_setup_vif() { - local name="$1" - local failed - - json_select data - json_get_vars ifname - json_select .. - - json_select config - json_get_vars mode - json_get_var vif_txpower txpower - - ifconfig "$ifname" up || { - wireless_setup_vif_failed IFUP_ERROR - json_select .. - return - } - - set_default vif_txpower "$txpower" - [ -z "$vif_txpower" ] || iw dev "$ifname" set txpower fixed "${vif_txpower%%.*}00" - - case "$mode" in - mesh) - for var in $MP_CONFIG_INT $MP_CONFIG_BOOL $MP_CONFIG_STRING; do - json_get_var mp_val "$var" - [ -n "$mp_val" ] && iw dev "$ifname" set mesh_param "$var" "$mp_val" - done - - # authsae - json_get_vars key - if [ -n "$key" ]; then - if [ -e "/lib/wifi/authsae.sh" ]; then - . /lib/wifi/authsae.sh - authsae_start_interface || failed=1 - else - wireless_setup_vif_failed AUTHSAE_NOT_INSTALLED - json_select .. - return - fi - fi - ;; - adhoc) - wireless_vif_parse_encryption - if [ "$wpa" -gt 0 -o "$auto_channel" -gt 0 ]; then - mac80211_setup_supplicant || failed=1 - else - mac80211_setup_adhoc - fi - ;; - sta) - mac80211_setup_supplicant || failed=1 - ;; - esac - - json_select .. - [ -n "$failed" ] || wireless_add_vif "$name" "$ifname" -} - -get_freq() { - local phy="$1" - local chan="$2" - iw "$phy" info | grep -E -m1 "(\* ${chan:-....} MHz${chan:+|\\[$chan\\]})" | grep MHz | awk '{print $2}' -} - -mac80211_interface_cleanup() { - local phy="$1" - - for wdev in $(list_phy_interfaces "$phy"); do - ifconfig "$wdev" down 2>/dev/null - iw dev "$wdev" del - done -} - -drv_mac80211_cleanup() { - hostapd_common_cleanup -} - -drv_mac80211_setup() { - json_select config - json_get_vars \ - phy macaddr path \ - country chanbw distance \ - txpower antenna_gain \ - rxantenna txantenna \ - frag rts beacon_int htmode - json_get_values basic_rate_list basic_rate - json_select .. - - find_phy || { - echo "Could not find PHY for device '$1'" - wireless_set_retry 0 - return 1 - } - - wireless_set_data phy="$phy" - mac80211_interface_cleanup "$phy" - - # convert channel to frequency - [ "$auto_channel" -gt 0 ] || freq="$(get_freq "$phy" "$channel")" - - [ -n "$country" ] && { - iw reg get | grep -q "^country $country:" || { - iw reg set "$country" - sleep 1 - } - } - - hostapd_conf_file="/var/run/hostapd-$phy.conf" - - no_ap=1 - macidx=0 - staidx=0 - - [ -n "$chanbw" ] && { - for file in /sys/kernel/debug/ieee80211/$phy/ath9k/chanbw /sys/kernel/debug/ieee80211/$phy/ath5k/bwmode; do - [ -f "$file" ] && echo "$chanbw" > "$file" - done - } - - set_default rxantenna all - set_default txantenna all - set_default distance 0 - set_default antenna_gain 0 - - iw phy "$phy" set antenna $txantenna $rxantenna >/dev/null 2>&1 - iw phy "$phy" set antenna_gain $antenna_gain - iw phy "$phy" set distance "$distance" - - [ -n "$frag" ] && iw phy "$phy" set frag "${frag%%.*}" - [ -n "$rts" ] && iw phy "$phy" set rts "${rts%%.*}" - - has_ap= - hostapd_ctrl= - for_each_interface "ap" mac80211_check_ap - - rm -f "$hostapd_conf_file" - [ -n "$has_ap" ] && mac80211_hostapd_setup_base "$phy" - - for_each_interface "sta adhoc mesh monitor" mac80211_prepare_vif - for_each_interface "ap" mac80211_prepare_vif - - [ -n "$hostapd_ctrl" ] && { - /usr/sbin/hostapd -P /var/run/wifi-$phy.pid -B "$hostapd_conf_file" - ret="$?" - wireless_add_process "$(cat /var/run/wifi-$phy.pid)" "/usr/sbin/hostapd" 1 - [ "$ret" != 0 ] && { - wireless_setup_failed HOSTAPD_START_FAILED - return - } - } - - for_each_interface "ap sta adhoc mesh monitor" mac80211_setup_vif - - wireless_set_up -} - -list_phy_interfaces() { - local phy="$1" - if [ -d "/sys/class/ieee80211/${phy}/device/net" ]; then - ls "/sys/class/ieee80211/${phy}/device/net" 2>/dev/null; - else - ls "/sys/class/ieee80211/${phy}/device" 2>/dev/null | grep net: | sed -e 's,net:,,g' - fi -} - -drv_mac80211_teardown() { - wireless_process_kill_all - - json_select data - json_get_vars phy - json_select .. - - mac80211_interface_cleanup "$phy" -} - -add_driver mac80211 diff --git a/ffho/ffho-openwrt-migration-tools/files/lib/wifi/mac80211.sh b/ffho/ffho-openwrt-migration-tools/files/lib/wifi/mac80211.sh deleted file mode 100644 index f6e1c26d19571cdcc83d1ddf367b178188eeabaa..0000000000000000000000000000000000000000 --- a/ffho/ffho-openwrt-migration-tools/files/lib/wifi/mac80211.sh +++ /dev/null @@ -1,112 +0,0 @@ -#!/bin/sh -append DRIVERS "mac80211" - -lookup_phy() { - [ -n "$phy" ] && { - [ -d /sys/class/ieee80211/$phy ] && return - } - - local devpath - config_get devpath "$device" path - [ -n "$devpath" ] && { - for _phy in /sys/devices/$devpath/ieee80211/phy*; do - [ -e "$_phy" ] && { - phy="${_phy##*/}" - return - } - done - } - - local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')" - [ -n "$macaddr" ] && { - for _phy in $(ls /sys/class/ieee80211 2>/dev/null); do - [ "$macaddr" = "$(cat /sys/class/ieee80211/${_phy}/macaddress)" ] || continue - phy="$_phy" - return - done - } - phy= - return -} - -find_mac80211_phy() { - local device="$1" - - config_get phy "$device" phy - lookup_phy - [ -n "$phy" -a -d "/sys/class/ieee80211/$phy" ] || { - echo "PHY for wifi device $1 not found" - return 1 - } - config_set "$device" phy "$phy" - - config_get macaddr "$device" macaddr - [ -z "$macaddr" ] && { - config_set "$device" macaddr "$(cat /sys/class/ieee80211/${phy}/macaddress)" - } - - return 0 -} - -check_mac80211_device() { - config_get phy "$1" phy - [ -z "$phy" ] && { - find_mac80211_phy "$1" >/dev/null || return 0 - config_get phy "$1" phy - } - [ "$phy" = "$dev" ] && found=1 -} - -detect_mac80211() { - devidx=0 - config_load wireless - while :; do - config_get type "radio$devidx" type - [ -n "$type" ] || break - devidx=$(($devidx + 1)) - done - for dev in $(ls /sys/class/ieee80211); do - found=0 - config_foreach check_mac80211_device wifi-device - [ "$found" -gt 0 ] && continue - - mode_band="g" - channel="11" - htmode="" - ht_capab="" - - iw phy "$dev" info | grep -q 'Capabilities:' && htmode=HT20 - iw phy "$dev" info | grep -q '2412 MHz' || { mode_band="a"; channel="36"; } - - vht_cap=$(iw phy "$dev" info | grep -c 'VHT Capabilities') - [ "$vht_cap" -gt 0 ] && { - mode_band="a"; - channel="36" - htmode="VHT80" - } - - [ -n $htmode ] && append ht_capab " option htmode $htmode" "$N" - - if [ -x /usr/bin/readlink ]; then - path="$(readlink -f /sys/class/ieee80211/${dev}/device)" - path="${path##/sys/devices/}" - dev_id=" option path '$path'" - else - dev_id=" option macaddr $(cat /sys/class/ieee80211/${dev}/macaddress)" - fi - - cat <<EOF -config wifi-device radio$devidx - option type mac80211 - option channel ${channel} - option hwmode 11${mode_band} -$dev_id -$ht_capab - # REMOVE THIS LINE TO ENABLE WIFI: - option disabled 1 - -EOF - devidx=$(($devidx + 1)) - done -} -