Skip to content

Commit

Permalink
Merge pull request #840 from germanferrero/new-align-screen
Browse files Browse the repository at this point in the history
New align screen
  • Loading branch information
germanferrero committed Feb 12, 2021
2 parents 5398a91 + bdf661b commit 26a5504
Show file tree
Hide file tree
Showing 14 changed files with 235 additions and 202 deletions.
1 change: 0 additions & 1 deletion libremesh.sdk.config
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ CONFIG_PACKAGE_ubus-lime-fbw=m
CONFIG_PACKAGE_ubus-lime-grondrouting=m
CONFIG_PACKAGE_ubus-lime-location=m
CONFIG_PACKAGE_ubus-lime-metrics=m
CONFIG_PACKAGE_ubus-lime-openairview=m
CONFIG_PACKAGE_ubus-lime-utils=m
CONFIG_PACKAGE_watchping=m
CONFIG_PACKAGE_bmx7-auto-gw-mode=m
Expand Down
8 changes: 4 additions & 4 deletions packages/lime-app/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@
include $(TOPDIR)/rules.mk

PKG_NAME:=lime-app
PKG_VERSION:=v0.2.10
PKG_VERSION:=v0.2.15
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_HASH:=0d1de42ecbe43a959dc912878ae1545cc8b355565d31775e10891fde84a8cf91
PKG_HASH:=a7dff34069bee261c718b69417da32d3d569c5d277799d73436e3c9306c01fa3
PKG_SOURCE_URL:=https://github.com/libremesh/lime-app/releases/download/$(PKG_VERSION)

include $(INCLUDE_DIR)/package.mk

define Package/$(PKG_NAME)
CATEGORY:=LibreMesh
TITLE:=LimeApp
MAINTAINER:=Marcos Gutierrez <gmarcos@altermundi.net>
MAINTAINER:=German Ferrero <germanferrero@altermundi.net>
URL:=http://github.com/libremesh/lime-app
DEPENDS:=+rpcd +uhttpd +uhttpd-mod-ubus +uhttpd-mod-lua \
+ubus-lime-location +ubus-lime-metrics +ubus-lime-utils \
+ubus-lime-openairview +ubus-lime-grondrouting
+rpcd-mod-iwinfo +ubus-lime-grondrouting
PKGARCH:=all
endef

Expand Down
14 changes: 14 additions & 0 deletions packages/lime-app/files/usr/share/rpcd/acl.d/iwinfo.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"lime-app": {
"read": {
"ubus": {
"iwinfo": [ "assoclist" ]
}
},
"write": {
"ubus": {
"iwinfo": [ "assoclist" ]
}
}
}
}
17 changes: 17 additions & 0 deletions packages/lime-system/files/usr/lib/lua/lime/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -526,4 +526,21 @@ function utils.write_obj_store(datafile, data)
end
end

function utils.get_ifnames()
local ifnames = {}
for ifname in fs.dir("/sys/class/net/") do
table.insert(ifnames, ifname)
end
return ifnames
end

function utils.is_valid_mac(string)
local string = string:match("%w%w:%w%w:%w%w:%w%w:%w%w:%w%w")
if string then
return true
else
return false
end
end

return utils
1 change: 0 additions & 1 deletion packages/lime-system/tests/test_lime_utils.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local utils = require 'lime.utils'
local test_utils = require 'tests.utils'

local uci = nil

describe('LiMe Utils tests #limeutils', function()
Expand Down
40 changes: 40 additions & 0 deletions packages/shared-state-bat_hosts/files/usr/lib/lua/bat-hosts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
local shared_state = require("shared-state")
local utils = require("lime.utils")

local bat_hosts = {}

function bat_hosts.bathost_deserialize(hostname_plus_iface)
local partial_hostname = hostname_plus_iface
local iface
for _, ifname in ipairs(utils.get_ifnames()) do
local serialized_ifname = string.gsub(ifname, "%W", "_")
serialized_ifname = utils.literalize(serialized_ifname)
local replaced_hostname = hostname_plus_iface:gsub("_"..serialized_ifname, "")
-- hostname don't have underscores see utils.is_valid_hostname
replaced_hostname = replaced_hostname:gsub("_", "-")
if #replaced_hostname < #partial_hostname then
partial_hostname = replaced_hostname
iface = ifname
end
end
return partial_hostname, iface
end

function bat_hosts.get_bathost(mac, outgoing_iface)
local sharedState = shared_state.SharedState:new('bat-hosts')
local bathosts = sharedState:get()
local bathost = bathosts[mac:lower()]
if bathost == nil and outgoing_iface then
local ipv6ll = utils.mac2ipv6linklocal(mac) .. "%" .. outgoing_iface
sharedState:sync({ ipv6ll })
bathosts = sharedState:get()
bathost = bathosts[mac:lower()]
end
if bathost == nil then
return
end
local hostname, iface = bat_hosts.bathost_deserialize(bathost.data)
return { hostname = hostname, iface = iface }
end

return bat_hosts
55 changes: 55 additions & 0 deletions packages/shared-state-bat_hosts/files/usr/libexec/rpcd/bat-hosts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env lua
--[[
Copyright (C) 2013-2020 LibreMesh.org
This is free software, licensed under the GNU AFFERO GENERAL PUBLIC LICENSE Version 3
Copyright 2020 German Ferrero <germanferrero@altermundi.net>
]]--

local ubus = require "ubus"
local json = require 'luci.jsonc'
local utils = require 'lime.utils'
local bat_hosts = require 'bat-hosts'

local conn = ubus.connect()
if not conn then
error("Failed to connect to ubus")
end

local function get_bathost(msg)
if not msg.mac or not utils.is_valid_mac(msg.mac) then
utils.printJson({ status = "error", message = "invalid mac" })
return
end

if msg.outgoing_iface and not utils.has_value(utils.get_ifnames(), msg.outgoing_iface) then
utils.printJson({ status = "error", message = "invalid outgoing interface" })
return
end
local bathost = bat_hosts.get_bathost(msg.mac, msg.outgoing_iface)
local result = {}
if bathost.hostname ~= nil then
result.status = "ok"
result.bathost = bathost
else
result.status = "error"
result.error = "Couldn't retrieve hostname"
end
utils.printJson(result)
end

local methods = {
get_bathost = { mac = 'value', outgoing_iface = 'value'}
}

if arg[1] == 'list' then
utils.printJson(methods)
end

if arg[1] == 'call' then
local msg = utils.rpcd_readline() or '{}'
msg = json.parse(msg)
if arg[2] == 'get_bathost' then get_bathost(msg)
else utils.printJson({ error = "Method not found" })
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"lime-app": {
"description": "lime-app public access",
"read": {
"ubus": {
"bat-hosts": [ "*" ]
}
},
"write": {
"ubus": {
"bat-hosts": [ "*" ]
}
}
}
}
36 changes: 36 additions & 0 deletions packages/shared-state-bat_hosts/tests/test_bat_hosts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
local bat_hosts = require('bat-hosts')
local utils = require('lime.utils')
local test_utils = require('tests.utils')
local shared_state = require('shared-state')

it('test get_bathost #bathost', function()
shared_state.DATA_DIR = test_utils.setup_test_dir()
local sharedState = shared_state.SharedState:new('bat-hosts')
sharedState:insert({
["02:95:39:ab:cd:00"] = "LiMe_abcd00_wlan1_mesh",
["52:00:00:ab:cd:a0"] = "LiMe_abcd01_wlan2_mesh_17",
["d6:67:58:8e:cd:92"] = "LiMe_abcd02_wlan0_adhoc_29",
["12:00:00:00:00:00"] = "LiMe_abcd03_wlan1_adhoc"
})
local ifaces = {'wlan1-mesh', 'wlan2-mesh', 'wlan2-mesh_17', 'wlan0-adhoc_29', 'wlan1-adhoc'}
stub(utils, "get_ifnames", function () return ifaces end)
assert.is.same({hostname='LiMe-abcd00', iface='wlan1-mesh'}, bat_hosts.get_bathost('02:95:39:ab:cd:00'))
assert.is.same({hostname='LiMe-abcd01', iface='wlan2-mesh_17'}, bat_hosts.get_bathost('52:00:00:ab:cd:a0'))
assert.is.same({hostname='LiMe-abcd02', iface='wlan0-adhoc_29'}, bat_hosts.get_bathost('d6:67:58:8e:cd:92'))
assert.is.same({hostname='LiMe-abcd03', iface='wlan1-adhoc'}, bat_hosts.get_bathost('12:00:00:00:00:00'))
local ipv6ll = utils.mac2ipv6linklocal('52:00:00:ab:cd:00') .. '%wlan1-mesh'
local dataTypeOfSync = nil
local urlsOfSync = nil
local function syncMock (self, urls)
dataTypeOfSync = self.dataType
urlsOfSync = urls
self:insert({['52:00:00:ab:cd:00'] = "Lime_abcd04_wlan1_mesh"})
end
stub(shared_state.SharedState, "sync", syncMock)
local bathost = bat_hosts.get_bathost('52:00:00:ab:cd:00', 'wlan1-mesh')
assert.is.same(urlsOfSync, { ipv6ll })
assert.is.equal(dataTypeOfSync, 'bat-hosts')
assert.is.same({hostname='Lime-abcd04', iface='wlan1-mesh'}, bathost)
assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00', 'wlan1'))
assert.is_nil(bat_hosts.get_bathost('00:aa:bb:cc:dd:00'))
end)
34 changes: 34 additions & 0 deletions packages/shared-state-bat_hosts/tests/test_ubus_bat_hosts.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
local bat_hosts = require "bat-hosts"
local test_utils = require "tests.utils"

local test_file_name = "packages/shared-state-bat_hosts/files/usr/libexec/rpcd/bat-hosts"
local ubus_bat_hosts = test_utils.load_lua_file_as_function(test_file_name)

local rpcd_call = test_utils.rpcd_call

describe('ubus-bat-hosts tests #ubusbathosts', function()
it('test get_bathost', function()
stub(bat_hosts, "get_bathost",
function() return { hostname = 'lime', iface = 'wlan1-mesh' } end
)
local response = rpcd_call(ubus_bat_hosts, {'call', 'get_bathost'}, '{}')
assert.is.equal("error", response.status)
assert.is.equal("invalid mac", response.message)
local response = rpcd_call(ubus_bat_hosts,
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00"}')
assert.is.equal("ok", response.status)
assert.is.same({ hostname = 'lime', iface = 'wlan1-mesh' }, response.bathost)


stub(utils, "get_ifnames", function() return {'wlan1-mesh'} end)
local response = rpcd_call(ubus_bat_hosts,
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00", "outgoing_iface":"foo"}')
assert.is.equal("error", response.status)
assert.is.equal("invalid outgoing interface", response.message)

local response = rpcd_call(ubus_bat_hosts,
{'call', 'get_bathost'}, '{"mac":"02:95:39:ab:cd:00", "outgoing_iface":"wlan1-mesh"}')
assert.is.equal("ok", response.status)
assert.is.same({ hostname = 'lime', iface = 'wlan1-mesh' }, response.bathost)
end)
end)
45 changes: 0 additions & 45 deletions packages/ubus-lime-openairview/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

| Path | Procedure | Signature | Description |
| ---------------- | ------------------ | ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| lime-openairview | get_interfaces | {} | Get list of adhoc interfaces |
| lime-openairview | get_stations | {device:STRING} | List of stations transmitting on the same frequency as the selected device/interface. |
| lime-openairview | get_iface_stations | {iface:STRING} | List of stations attached to the interface. |
| lime-openairview | get_station_signal | {station_mac:STRING, iface:STRING} | Get the signal level with which an interface sees a particular device |
| lime-openairview | spectral_scan | {device:STRING, spectrum:STRING} | Get the fft-eval scan results. specturm can by: 2ghz, 5ghz or current. "current" means scan only the channel on which the interface is set. This will work only if fft-eval is installed |

## Examples
Expand All @@ -16,46 +12,5 @@ If the openairview was never established, return the openairview of the communit

```
'lime-openairview' @4bd5f4f5
"get_interfaces":{"no_params":"Integer"}
"get_stations":{"device":"String"}
"get_iface_stations":{"iface":"String"}
"get_station_signal":{"station_mac":"String","iface":"String"}
"spectral_scan":{"device":"String","spectrum":"String"}
```

### ubus call lime-openairview get_interfaces

```json
{
"interfaces": ["wlan1-adhoc", "wlan0-adhoc"]
}
```

### ubus call lime-openairview get_stations '{"device":"wlan1-adhoc"}'

```json
{
"stations": [
{
"station_mac": "A0:F3:C1:86:31:35",
"station_hostname": "herradura_wlan1-adhoc",
"attributes": {
"inactive": 16870,
"channel": 112,
"signal": "-82"
},
"link_type": "wifi"
},
{
"station_mac": "A0:F3:C1:86:32:11",
"station_hostname": "marisa_wlan1-adhoc",
"attributes": {
"inactive": 10,
"channel": 112,
"signal": "-74"
},
"link_type": "wifi"
}
]
}
```

0 comments on commit 26a5504

Please sign in to comment.