mac80211: add support for multiple wiphys behind a single device
The device path will be the same for the first phy. For all subsequent phys, the path gets an extra +1, +2, ... Move the code for converting path to phy and vice versa to a separate library script shared by config detection code and the netifd wireless handler script Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
		| @@ -546,6 +546,7 @@ endef | |||||||
| define KernelPackage/cfg80211/install | define KernelPackage/cfg80211/install | ||||||
| 	$(INSTALL_DIR) $(1)/lib/wifi $(1)/lib/netifd/wireless | 	$(INSTALL_DIR) $(1)/lib/wifi $(1)/lib/netifd/wireless | ||||||
| 	$(INSTALL_DATA) ./files/lib/wifi/mac80211.sh $(1)/lib/wifi | 	$(INSTALL_DATA) ./files/lib/wifi/mac80211.sh $(1)/lib/wifi | ||||||
|  | 	$(INSTALL_DATA) ./files/lib/netifd/mac80211.sh $(1)/lib/netifd | ||||||
| 	$(INSTALL_BIN) ./files/lib/netifd/wireless/mac80211.sh $(1)/lib/netifd/wireless | 	$(INSTALL_BIN) ./files/lib/netifd/wireless/mac80211.sh $(1)/lib/netifd/wireless | ||||||
| 	$(INSTALL_DIR) $(1)/etc/hotplug.d/ieee80211 | 	$(INSTALL_DIR) $(1)/etc/hotplug.d/ieee80211 | ||||||
| 	$(INSTALL_DATA) ./files/mac80211.hotplug $(1)/etc/hotplug.d/ieee80211/10-wifi-detect | 	$(INSTALL_DATA) ./files/mac80211.hotplug $(1)/etc/hotplug.d/ieee80211/10-wifi-detect | ||||||
|   | |||||||
							
								
								
									
										36
									
								
								package/kernel/mac80211/files/lib/netifd/mac80211.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								package/kernel/mac80211/files/lib/netifd/mac80211.sh
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,36 @@ | |||||||
|  | mac80211_phy_to_path() { | ||||||
|  | 	local phy="$1" | ||||||
|  |  | ||||||
|  | 	[ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${phy} ] || return | ||||||
|  |  | ||||||
|  | 	local path="$(readlink -f /sys/class/ieee80211/${phy}/device)" | ||||||
|  | 	[ -n "$path" ] || return | ||||||
|  |  | ||||||
|  | 	path="${path##/sys/devices/}" | ||||||
|  | 	case "$path" in | ||||||
|  | 		platform*/pci*) path="${path##platform/}";; | ||||||
|  | 	esac | ||||||
|  |  | ||||||
|  | 	local p | ||||||
|  | 	local seq="" | ||||||
|  | 	for p in $(ls /sys/class/ieee80211/$phy/device/ieee80211); do | ||||||
|  | 		[ "$p" = "$phy" ] && { | ||||||
|  | 			echo "$path${seq:++$seq}" | ||||||
|  | 			break | ||||||
|  | 		} | ||||||
|  |  | ||||||
|  | 		seq=$((${seq:-0} + 1)) | ||||||
|  | 	done | ||||||
|  | } | ||||||
|  |  | ||||||
|  | mac80211_path_to_phy() { | ||||||
|  | 	local path="$1" | ||||||
|  |  | ||||||
|  | 	local p | ||||||
|  | 	for p in $(ls /sys/class/ieee80211); do | ||||||
|  | 		local cur="$(mac80211_phy_to_path "$p")" | ||||||
|  | 		case "$cur" in | ||||||
|  | 			*$path) echo "$p"; return;; | ||||||
|  | 		esac | ||||||
|  | 	done | ||||||
|  | } | ||||||
| @@ -1,6 +1,7 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
| . /lib/netifd/netifd-wireless.sh | . /lib/netifd/netifd-wireless.sh | ||||||
| . /lib/netifd/hostapd.sh | . /lib/netifd/hostapd.sh | ||||||
|  | . /lib/netifd/mac80211.sh | ||||||
|  |  | ||||||
| init_wireless_driver "$@" | init_wireless_driver "$@" | ||||||
|  |  | ||||||
| @@ -407,11 +408,8 @@ mac80211_generate_mac() { | |||||||
| find_phy() { | find_phy() { | ||||||
| 	[ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0 | 	[ -n "$phy" -a -d /sys/class/ieee80211/$phy ] && return 0 | ||||||
| 	[ -n "$path" ] && { | 	[ -n "$path" ] && { | ||||||
| 		for phy in $(ls /sys/class/ieee80211 2>/dev/null); do | 		phy="$(mac80211_path_to_phy "$path")" | ||||||
| 			case "$(readlink -f /sys/class/ieee80211/$phy/device)" in | 		[ -n "$phy" ] && return 0 | ||||||
| 				*$path) return 0;; |  | ||||||
| 			esac |  | ||||||
| 		done |  | ||||||
| 	} | 	} | ||||||
| 	[ -n "$macaddr" ] && { | 	[ -n "$macaddr" ] && { | ||||||
| 		for phy in $(ls /sys/class/ieee80211 2>/dev/null); do | 		for phy in $(ls /sys/class/ieee80211 2>/dev/null); do | ||||||
| @@ -740,6 +738,9 @@ mac80211_interface_cleanup() { | |||||||
| 	local phy="$1" | 	local phy="$1" | ||||||
|  |  | ||||||
| 	for wdev in $(list_phy_interfaces "$phy"); do | 	for wdev in $(list_phy_interfaces "$phy"); do | ||||||
|  | 		local wdev_phy="$(readlink /sys/class/net/${wdev}/phy80211)" | ||||||
|  | 		wdev_phy="$(basename "$wdev_phy")" | ||||||
|  | 		[ -n "$wdev_phy" -a "$wdev_phy" != "$phy" ] && continue | ||||||
| 		ip link set dev "$wdev" down 2>/dev/null | 		ip link set dev "$wdev" down 2>/dev/null | ||||||
| 		iw dev "$wdev" del | 		iw dev "$wdev" del | ||||||
| 	done | 	done | ||||||
|   | |||||||
| @@ -1,4 +1,6 @@ | |||||||
| #!/bin/sh | #!/bin/sh | ||||||
|  | . /lib/netifd/mac80211.sh | ||||||
|  |  | ||||||
| append DRIVERS "mac80211" | append DRIVERS "mac80211" | ||||||
|  |  | ||||||
| lookup_phy() { | lookup_phy() { | ||||||
| @@ -9,11 +11,8 @@ lookup_phy() { | |||||||
| 	local devpath | 	local devpath | ||||||
| 	config_get devpath "$device" path | 	config_get devpath "$device" path | ||||||
| 	[ -n "$devpath" ] && { | 	[ -n "$devpath" ] && { | ||||||
| 		for phy in $(ls /sys/class/ieee80211 2>/dev/null); do | 		phy="$(mac80211_path_to_phy "$devpath")" | ||||||
| 			case "$(readlink -f /sys/class/ieee80211/$phy/device)" in | 		[ -n "$phy" ] && return | ||||||
| 				*$devpath) return;; |  | ||||||
| 			esac |  | ||||||
| 		done |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')" | 	local macaddr="$(config_get "$device" macaddr | tr 'A-Z' 'a-z')" | ||||||
| @@ -91,16 +90,8 @@ detect_mac80211() { | |||||||
|  |  | ||||||
| 		[ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode" | 		[ -n "$htmode" ] && ht_capab="set wireless.radio${devidx}.htmode=$htmode" | ||||||
|  |  | ||||||
| 		if [ -x /usr/bin/readlink -a -h /sys/class/ieee80211/${dev} ]; then | 		path="$(mac80211_phy_to_path "$dev")" | ||||||
| 			path="$(readlink -f /sys/class/ieee80211/${dev}/device)" |  | ||||||
| 		else |  | ||||||
| 			path="" |  | ||||||
| 		fi |  | ||||||
| 		if [ -n "$path" ]; then | 		if [ -n "$path" ]; then | ||||||
| 			path="${path##/sys/devices/}" |  | ||||||
| 			case "$path" in |  | ||||||
| 				platform*/pci*) path="${path##platform/}";; |  | ||||||
| 			esac |  | ||||||
| 			dev_id="set wireless.radio${devidx}.path='$path'" | 			dev_id="set wireless.radio${devidx}.path='$path'" | ||||||
| 		else | 		else | ||||||
| 			dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)" | 			dev_id="set wireless.radio${devidx}.macaddr=$(cat /sys/class/ieee80211/${dev}/macaddress)" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Felix Fietkau
					Felix Fietkau