Commit Graph

18 Commits

Author SHA1 Message Date
Oliver Smith 1741372556 treewide: remove FSF address
Remove the paragraph about writing to the Free Software Foundation's
mailing address. The FSF has changed addresses in the past, and may do
so again. In 2021 this is not useful, let's rather have a bit less
boilerplate at the start of source files.

Change-Id: I73be012c01c0108fb6951dbff91d50eb19b40c51
2021-12-14 12:52:04 +00:00
Harald Welte d90ae30caa mobile: Use osmo_fd_setup() in script_lua.c
Change-Id: Ib6f97b9b8f3af63b81b92071b7fdb1fd55da89a5
2020-10-21 11:56:43 +00:00
Harald Welte 508d8523c0 Use OSMO_FD_* instead of deprecated BSC_FD_*
Change-Id: Ibf64b18288b9109927035f650d6ef7ad9f15d688
2020-10-18 22:43:05 +02:00
Martin Hauke 1f7a2ab5d3 Fix common misspellings and typos
Change-Id: I962b42871693f33b1054d43d195817e9cd84bb64
2019-10-17 08:07:39 +00:00
Holger Hans Peter Freyther b4bd78a8ee lua: Add a sentinel for the fd function table
Change-Id: I4fe2fd6584a453a951361e1b67fb986583b176be
2019-04-27 10:15:28 +01:00
Holger Hans Peter Freyther b429447168 lua: Expose API to trigger a network reselection
Same as the "network search" VTY command but implemented as primitive
and exposed to LUA.

Change-Id: I096233a2ca9dd7daa358cebed0523cb8c0dbf593
2018-09-16 13:51:29 +00:00
Holger Hans Peter Freyther 90a9ac410c Allow lua code to register a fd for reading with the runtime
To have bi-directional communication we can pass credentials to the
registry server and now we can register a callback when the registry
is sending data to us.

The callback needs to return if the fd should continue to be selected
as I found no way to push the userdata as parameter on the stack. Lua
code will look like:

  local host, port = "www.osmocom.org", 80
  local tcp = socket.tcp()
  tcp:connect(host, port);
  tcp:send("GET / HTTP/1.0\r\n\r\n");
  local cb = function()
    local s, status, partial = tcp:receive()
    print(s)
    if status == 'closed' then
     tcp:close()
     return 0
    end
    return 1
  end
  local foo = osmo.register_fd(tcp:getfd(), cb)

Change-Id: I8254bdda1df2f8fe0a5eac894b931e7de5b426df
2018-08-24 10:35:21 +00:00
Holger Hans Peter Freyther 4a466f5007 Forget about the callback after use and cancellation
Don't try to unref something else after we have given up our
spot in the table.

Change-Id: I4e8db297e816d3d07a46147d5d3bdc0e8fae6c9a
2018-08-24 10:34:02 +00:00
Holger Hans Peter Freyther ce772ce338 lua: Add API to enable passing credentials
This can be useful to have bidirectional communication between the
mobile lua script an external control script.

Change-Id: Ib4a5eef611f524f5d21cb6a7f4eace22b8ba60d0
2018-06-17 19:22:57 +01:00
Holger Hans Peter Freyther 8b9d3170ff mobile: Fix memory leak when not using a LUA script
The primitives are still allocated and dispatched but there was
no script handler to delete them. Change the ownership to delete
it at the end of the dispatch.

Change-Id: I510af13bcbb46f73a0a289f26a4921cc90bd986a
Fixes: OS#2925
2018-02-23 08:43:21 +00:00
Holger Hans Peter Freyther ceb0875f1a mobile: Properly close the primitive interface on reload
When reloading a script go through script_lua_close. Get the
primitive first. Then destruct the lua environment which will
lead to GC (e.g. cancellation of timers) and then delete the
primitive code.

Change-Id: I5bb4fa9e7c5010f3ad50b258dcb14956eea8822a
2017-12-27 10:50:14 +08:00
Holger Hans Peter Freyther a8130aba91 mobile: Send SMS through the primitive interface
Make this symmetric and send the SMS through the primitive
interface. Construct and copy the sms into the prim, store
the SCA in the prim as well. In 04.11 we see we can store
2*10 digits in the destination address and a NUL.

Change-Id: I91d7537f4f6ce5ba00218c58f3456947ec7bc662
2017-12-27 10:07:17 +08:00
Holger Hans Peter Freyther 238df986b9 mobile: Return the name of the configured "MS"
In lua osmo.ms():name() will print the name/number of the MS. This
can be used by scripting code to use in events and then be analyzed.

Change-Id: I881d3e87daa19f4e6f4f5bd30fe95906129e60ef
2017-12-03 22:01:50 +00:00
Holger Hans Peter Freyther a0fc36f859 mobile: Simplify code and check the cb ref in load_cb
Change parameters and check if the cb_ref is valid or not.

Change-Id: I74fbcd7e853e24b1225ecc4c19304134b8467c9b
2017-12-03 18:36:19 +00:00
Holger Hans Peter Freyther edb65f915f mobile: Use new LOGPSRCC macro to print multiple values
We need continuation to avoid printing the logging category
again. E.g. when print(one, two, three) is called.

Change-Id: Id8491fa949768f170a8c74ab554cb1166afda1b7
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 50869b9146 mobile: Create "ms" singleton for struct osmocom_ms
Make the MS the script is associated with accessible to lua. Provide
access to IMSI and IMEI. The IMSI might not be available at the given
time and just return an empty string.

Example lua usage:

 print(osmo.ms():imsi());
 print(osmo.ms():imei());
 print(osmo.ms():shutdown_state())
 print(osmo.ms():started())

 function ms_started_cb(started)
	print("MS started", started)
 end

 function ms_shutdown_cb(old_state, new_state)
	print("MS shutdown", old_state, "->", new_state)
 end

 function sms_cb(sms, cause, valid)
	print("SMS data cb", sms, cause, valid)
	for i, v in pairs(sms) do
		print(i, v)
	end
 end
 function mm_cb(new_state, new_substate, old_substate)
	if new_state == 19 and new_substate == 1 then
		osmo.ms():sms_send_simple("1234", "21321324", "fooooooo", 23)
	end
 end
 local cbs = {
	Started=ms_started_cb,
	Shutdown=ms_shutdown_cb,
	Sms=sms_cb,
	Mm=mm_cb
 }

 timer = osmo.timeout(20, function()
    print("Timeout occurred after 20s")
 end)

 osmo.ms():register(cbs)

 # Can fail. Best to wait for state changes...
 print(osmo.ms().start())
 print(osmo.ms().stop(true))

Change-Id: Ia3ace33d6ba4e904b1ff8e271a02d67777334a58
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 44c19326f3 mobile: Add osmo.timeout for lua code to have timeouts
Allow to callback into lua code after a user configured timeout. Make
it only work on seconds (truncate double to int).

Change-Id: I355d2f8d15aeaa13abb1c5e4a8e0c958e5faf7f3
2017-12-03 12:58:53 +00:00
Holger Hans Peter Freyther 4080e622b7 mobile: Add initial support for scripting support
Right now the script will be executed once it is loaded. Make sure
to write it into the config file last. Expose various log commands
for logging. Jump through some hoops and get the filename and line
number from lua.

Change-Id: I456f6b6b5e1a14ed6c8cb0dcc5140093d3c61ef6
2017-12-03 12:58:53 +00:00