aboutsummaryrefslogtreecommitdiffstats
path: root/openbsc/contrib/gprs/gprs-verify-nu.lua
blob: e44fdd16f9b76cd4140c09ac37fb36745a0f6dbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
-- This script verifies that the N(U) is increasing...
--
do
	local nu_state_src = {}

	local function init_listener()
		-- handle the port as NS over IP
		local udp_port_table = DissectorTable.get("udp.port")
		local gprs_ns_dis = Dissector.get("gprs_ns")
		udp_port_table:add(23000,gprs_ns_dis)

		-- we want to look here...
		local llc_sapi_get = Field.new("llcgprs.sapib")
		local llc_nu_get = Field.new("llcgprs.nu")
		local bssgp_tlli_get = Field.new("bssgp.tlli")

		local tap = Listener.new("ip", "udp.port == 23000")
		function tap.packet(pinfo,tvb,ip)
			local llc_sapi = llc_sapi_get()
			local llc_nu = llc_nu_get()
			local bssgp_tlli = bssgp_tlli_get()

			if not llc_sapi or not llc_nu or not bssgp_tlli then
				return
			end

			local ip_src = tostring(ip.ip_src)
			local bssgp_tlli = tostring(bssgp_tlli)
			local llc_nu = tostring(llc_nu)
			local llc_sapi = tostring(llc_sapi)

			local src_key = ip_src .. "-" .. bssgp_tlli .. "-" .. llc_sapi
			local last_nu = nu_state_src[src_key]
			if not last_nu then
				-- print("Establishing mapping for " .. src_key)
				nu_state_src[src_key] = llc_nu
				return
			end

			local function tohex(number)
				return string.format("0x%x", tonumber(number))
			end

			nu_state_src[src_key] = llc_nu
			if tonumber(last_nu) + 1 ~= tonumber(llc_nu) then
				print("JUMP in N(U) on TLLI " .. tohex(bssgp_tlli) .. " and SAPI: " .. llc_sapi .. " src: " .. ip_src)
				print("\t last: " .. last_nu .. " now: " .. llc_nu)
			end
		end

		function tap.draw()
		end

		function tap.reset()
		end
	end
	init_listener()
end