Developing lightweight computation at the DSG edge

qmpinfo.lua 1.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/lua

iwinfo = require "iwinfo"

qmpinfo = {}

function qmpinfo.get_modes(dev)
	local iw = iwinfo[iwinfo.type(dev)]
	local ma = "" -- modes avaiable
	return iw.hwmodelist(dev)
	
end

function qmpinfo.get_channels(dev)
	local iw = iwinfo[iwinfo.type(dev)]

	local freqs = iw.freqlist(dev) --freqs list
	local c -- current channel
	local nc = 0 -- next channel
	local pc = 0 -- previous channel
	local clist = {} -- output channel list
	local adhoc
23
24
	local ht40_support = qmpinfo.get_modes(dev).n
	
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71

	for i,f in ipairs(freqs) do
		c = f.channel
		ch = {}
		ch.channel = c
		ch.ht40p = false
		ch.ht40m = false
		ch.adhoc = false

		-- 2.4Ghz band
		if c < 15 then
			if c < 4 then 
				ch.ht40p = true
				ch.adhoc = true 
			
			elseif c < 10 then 
				ch.ht40m = true  
				ch.ht40p = true
				ch.adhoc = true
			else 
				ch.ht40m = true
				ch.adhoc = true
			end
		  
		-- 5Ghz band
		elseif c > 14 then
			if #freqs == i then nc = nil
			else nc = freqs[i+1].channel
			end

			if i == 1 then pc = nil
			else pc = freqs[i-1].channel
			end

			if nc ~= nil and nc-c == 4 then 
				ch.ht40p = true 
			end
	
			if pc ~= nil and c-pc == 4 then
				ch.ht40m = true
			end

			adhoc = os.execute("iw list | grep \"no IBSS\" | grep -v disabled | grep -q " .. f.mhz .. " 2>/dev/null")
			if adhoc ~= 0 then
				ch.adhoc = true
			end
		end
72
73
74
75
76
77
78

		-- If the device does not support ht40, both vars (+/-) are false
		if not ht40_support then
			ch.ht40p = false
			ch.ht40m = false
		end

79
		table.insert(clist,ch)
80

81
82
83
84
85
	end	
	return clist
end

return qmpinfo