Skip to content

Commit

Permalink
lime-system: add wireless.get_phy_mac
Browse files Browse the repository at this point in the history
  • Loading branch information
frank95 committed Aug 10, 2014
1 parent 8ca6b9a commit 80bafcc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/lime-proto-batadv/src/batadv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ function batadv.setup_interface(ifname, args)
-- We use 000049 Unicast MAC prefix reserved by Apricot Ltd
-- We change the 7nt bit to 1 to give it locally administered meaning
-- Then use it as the new mac address prefix "02:00:49"
if ifname:match("^eth") or ifname:match("^wlan%d+"..wireless.ifnameModeSeparator.."ap") then
local vlanMacAddr = network.get_mac(ifname)
local vlanMacAddr = nil
if ifname:match("^eth") then
vlanMacAddr = network.get_mac(ifname)
elseif ifname:match("^wlan%d+"..wireless.ifnameModeSeparator.."ap") then
vlanMacAddr = wireless.get_phy_mac("phy"..ifname:match("%d+"))
end
if vlanMacAddr then
vlanMacAddr[1] = "02"
vlanMacAddr[2] = "00"
vlanMacAddr[3] = "49"
Expand Down
3 changes: 2 additions & 1 deletion packages/lime-system/files/usr/lib/lua/lime/network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ network.protoVlanSeparator="_"


function network.get_mac(ifname)
local mac = assert(fs.readfile("/sys/class/net/"..ifname.."/address")):gsub("\n","")
local path = "/sys/class/net/"..ifname.."/address"
local mac = assert(fs.readfile(path), "network.get_mac(...) failed reading: "..path):gsub("\n","")
return utils.split(mac, ":")
end

Expand Down
7 changes: 7 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/wireless.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
local config = require("lime.config")
local network = require("lime.network")
local libuci = require("uci")
local fs = require("nixio.fs")

wireless = {}

wireless.modeParamsSeparator=":"
wireless.limeIfNamePrefix="lm_"
wireless.ifnameModeSeparator="_"

function wireless.get_phy_mac(phy)
local path = "/sys/class/ieee80211/"..phy.."/macaddress"
local mac = assert(fs.readfile(path), "wireless.get_phy_mac(..) failed reading: "..path):gsub("\n","")
return utils.split(mac, ":")
end

function wireless.clean()
print("Clearing wireless config...")
local uci = libuci:cursor()
Expand Down

0 comments on commit 80bafcc

Please sign in to comment.