base-files: add function to get mac as text from flash
Add a function to get a mac stored as text from flash. The octets of
the mac address need to be separated by any separator supported by
macaddr_canonicalize().
Signed-off-by: Dmitry Tunin <hanipouspilot@gmail.com>
Signed-off-by: Mathias Kresin <dev@kresin.me>
(backported from dfee452713)
			
			
This commit is contained in:
		 Mathias Kresin
					Mathias Kresin
				
			
				
					committed by
					
						 Jo-Philipp Wich
						Jo-Philipp Wich
					
				
			
			
				
	
			
			
			 Jo-Philipp Wich
						Jo-Philipp Wich
					
				
			
						parent
						
							54278dfa69
						
					
				
				
					commit
					d93bd72a98
				
			| @@ -38,6 +38,29 @@ mtd_get_mac_ascii() { | |||||||
| 	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" | 	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | mtd_get_mac_text() { | ||||||
|  | 	local mtdname=$1 | ||||||
|  | 	local offset=$2 | ||||||
|  | 	local part | ||||||
|  | 	local mac_dirty | ||||||
|  |  | ||||||
|  | 	part=$(find_mtd_part "$mtdname") | ||||||
|  | 	if [ -z "$part" ]; then | ||||||
|  | 		echo "mtd_get_mac_text: partition $mtdname not found!" >&2 | ||||||
|  | 		return | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	if [ -z "$offset" ]; then | ||||||
|  | 		echo "mtd_get_mac_text: offset missing!" >&2 | ||||||
|  | 		return | ||||||
|  | 	fi | ||||||
|  |  | ||||||
|  | 	mac_dirty=$(dd if="$part" bs=1 skip="$offset" count=17 2>/dev/null) | ||||||
|  |  | ||||||
|  | 	# "canonicalize" mac | ||||||
|  | 	[ -n "$mac_dirty" ] && macaddr_canonicalize "$mac_dirty" | ||||||
|  | } | ||||||
|  |  | ||||||
| mtd_get_mac_binary() { | mtd_get_mac_binary() { | ||||||
| 	local mtdname="$1" | 	local mtdname="$1" | ||||||
| 	local offset="$2" | 	local offset="$2" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user