Commit Graph

69 Commits

Author SHA1 Message Date
Eric Caruso
3c60eb7e0e cfg, lookup, ns: avoid using __progname
The __progname symbol is a GNU extension and thus not portable,
but basename (from libgen.h) and argv[0] can be used portably
instead.

(qrtr-lookup already used argv[0] but did not apply basename, so
do that for consisntency.)

Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
2018-05-01 11:41:34 -07:00
Eric Caruso
366003c923 lookup: alphabetize includes
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
2018-05-01 11:41:34 -07:00
Eric Caruso
43723b6424 ns: alphabetize includes
Signed-off-by: Eric Caruso <ejcaruso@chromium.org>
2018-05-01 11:41:34 -07:00
Eric Caruso
b0f8857615 qmi: remove unused include
This include provides err, errx, etc. but it looks like all
error logging in qmi.c is done with fprintf, so there's no
reason to include it.

Change-Id: I4f4a71323a55fca981ef8df994fe624a590e3802
2018-04-27 16:28:19 -07:00
Bjorn Andersson
7d9a2e7df9 ns: Add argument to stay in foreground
When running in Android we want to keep qrtr-ns in the foreground, so
that init's service handler can keep track of it. Add the -f flag to
skip the fork().

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-19 18:13:34 -07:00
Bjorn Andersson
bd51b700ba ns: Allow qrtr-ns to configure node id
Instead of calling qrtr-cfg separately to configure the local address
just pass this as an argument to qrtr-ns, allowing us to run a single
command to instantiate qrtr.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-19 18:07:18 -07:00
Bjorn Andersson
3d819eecb2 cfg: Trigger kernel module autoloading
By opening a socket before attempting to configure the address we
trigger kernel module loading, if qrtr is compiled as such.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-04-19 18:02:00 -07:00
Ben Chan
539c83dc5b libqrtr: define AF_QIPCRTR if it isn't defined in libc header
Definition of AF_QIPCRTR was introduced in glibc in the following
commit and is only available since glibc 2.25 or later.

https://sourceware.org/git/?p=glibc.git;a=commit;h=acaff9b658720e4c887f4e44e6f28962d6f372d3

This patch modifies libqrtr.h to define AF_QIPCRTR if it isn't defined
in libc header, which allows compilation of libqrtr on a system with an
older version of glibc. The compiled libqrtr can still be used on a
system with kernel 4.7 or later with the QIPCRTR support.

Signed-off-by: Ben Chan <benchan@chromium.org>
2018-03-29 08:48:55 -07:00
Bjorn Andersson
9c126920c9 Makefile: Add lib to include path of qrtr-cfg
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-03-05 22:03:18 -08:00
Bjorn Andersson
dbffdd0193 libqrtr: Remove depricated functions
Post-QMI clean up of old interfaces and some duplicated definitions.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-01 02:06:57 +00:00
Bjorn Andersson
183d33d238 libqrtr: Rename libqrtr.c for the purpose of symmetry
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-02-01 01:51:39 +00:00
Bjorn Andersson
70b6f4900d qmi: Introduce QMI encoder/decoder helpers
The QMI functions can be used to deal with QMI-encoded data in
qrtr_packet objects. The structure-description is the same element-info
arrays as is used in the upstream Linux kernel.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-31 21:07:45 +00:00
Bjorn Andersson
17c4c1038e qrtr: Drop container.h
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-31 21:07:39 +00:00
Bjorn Andersson
99390f90ae libqrtr: Add qrtr_decode() operation
The qrtr_decode() takes a buffer of data and returns a decoded qrtr
packet object, this will either contain control data or a reference to
the message data.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-31 21:07:39 +00:00
Bjorn Andersson
0ec649d4e6 qrtr: Backport future qrtr.h uapi
The uapi qrtr.h is extended with additional types and constants. Drop
the local qrtr.h to use the one from linux-headers and extend it
conditionally while we're waiting for the updated file.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2018-01-31 05:53:49 +00:00
Bjorn Andersson
b65e63045f libqrtr: Don't enforce server port to be bound
When sending a new_server message to the qrtr-ns the node and port in
the packet is ignored (to not allow clients spoofing the information),
so there's no reason to have this artificial check in the
qrtr_new_server() implementation either.

The socket will be bound to a port automatically when the new_server
message is sent out.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-09 10:22:28 -08:00
Bjorn Andersson
7c35e025d9 lookup: Add DIAG service
Add the DIAG service, as mentioned in msm-4.4

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-11-02 21:30:38 -07:00
Bjorn Andersson
a6f9b18bd9 qrtr-ns: Sanity check origin of messages
Restrict the origin of certain messages to limit the ability of clients
to inject invalid data in the service registry.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-10-30 23:00:58 -07:00
Bjorn Andersson
be5ed574af qrtr-ns: Move DEL_SERVER logic to server_del
When a server is disappearing, either from a DEL_SERVER, BYE or
DEL_CLIENT message the same messages needs to be sent; to local
observers and through broadcasts to remote nodes.

So move the logic from the DEL_SERVER command handler to server_del, in
order to invoke this regardless of reason for the server's
disappearance.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-10-30 22:48:24 -07:00
Bjorn Andersson
dfae11b03a libqrtr: Don't require socket to be bound for lookup
There's no reason to require that the socket to be bound to a specific
port in order to register a lookup, the transmission of the lookup
request will autobind the socket to a port for us.

Also drop the node and port from the payload, as qrtr-ns will register
the lookup on the source sq, rather than the passed port.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-10-30 21:38:47 -07:00
Bjorn Andersson
86747d0fcc qrtr-ns: Propagate the node in BYE
As we propagate the BYE to local listeners we have to also pass the
information on which node is down, so use the typical "node" field for
this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-10-30 21:33:22 -07:00
Bjorn Andersson
411616148f lookup: Extend service name table
A number of services are mentioned in the Qualcomm downstream kernels,
add these to the list of known names to improve the output.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-30 11:53:52 -07:00
Bjorn Andersson
c1fb6f0bd0 lookup: Report service, version and instance separate
Instead of reporting "service" as id:instance split the "instance" in version
and instance and present the three entities separately.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-08-14 12:11:27 -07:00
Bjorn Andersson
ba500a4d3d lib: Fix endian handling and add new/del server
Fix up the handling of endian translation and add support for decoding
new and del server messages.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
v0.3
2017-06-07 10:00:28 -07:00
Bjorn Andersson
0a2f2111f7 ns: Replace lookup result with new and del server messages
Instead of having a custom lookup result, just pass new and delete
server messages - allowing clients to receive notifications about dying
services as well, without having to extend the lookup result message.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-07 10:00:28 -07:00
Bjorn Andersson
577328a8ab lib: Add helpers for handling control messages
The two added functions can be used by an application to check if a
sockaddr is from the control port and for parsing the control messages
that is passed to registered clients.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-07 10:00:28 -07:00
Bjorn Andersson
b804dcae1b cfg: Request and check return value
Request the return value of the operation from the kernel and check if
it's an error, to inform the user about e.g. not having sufficient
permission.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
v0.2
2017-06-06 22:15:33 -07:00
Bjorn Andersson
0b9959552e ns: Cleanup socket creation
Now that we only have one socket we can clean up the socket creation
code further.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:51:09 -07:00
Bjorn Andersson
a4aa8250c1 ns: Rename context socket
Now that we only have one socket for our context we can simplify the
name of the struct member.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:50:55 -07:00
Bjorn Andersson
0bc03abb43 ns: Remove the ns service
Now that we have moved all operations to the control socket we can
remove the ns handler. The query function in the library is racy, as
there might be non-response messages in our incoming buffer when we
start reading, so this is dropped too - rather than just being
translated to the new interface.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:50:54 -07:00
Bjorn Andersson
f775838736 lookup: Transition to using control port
Convert qrtr-lookup to use the control port for queries, allowing us to
drop the ns service altogether.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:49:31 -07:00
Bjorn Andersson
326aad23ae ns: Introduce lookup registration
Introduce a subscription based lookup model, in order for a client to be
able to listen to a future spawning service. The client can register any
number of queries with the ns and the ns will post lookup-results as
services are registred.

As a special case the list of lookup-results that is sent out as a
result of the registration of a new lookup will be finished by an empty
lookup response, allowing tools like qrtr-lookup to terminate as the
entire list of currently registed services is received.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:49:30 -07:00
Bjorn Andersson
e377bc8e84 lib: Replace qrtr_publish() and qrtr_bye() implementations
Replace the implementation of the two library functions with calls to
the new APIs, so that we can remove the server-side implementation of
the previous messages.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:47:00 -07:00
Bjorn Andersson
b4393f4515 ns: Handle BYE control message
The BYE control message signals that a node is gone, drop all services
from our register and propagate this message to all local servies - to
allow them to clean up any resources associated with potential remote
clients.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-07 04:46:42 +00:00
Bjorn Andersson
032b2443b3 ns: Make del_client always propagate del_client
Following the downstream kernel we should propagate a del_client to all
local services as the dying socket might have acted - or once acted - as
a client as well.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:44:59 -07:00
Bjorn Andersson
765aa8d57f ns: Implement DEL_CLIENT
Upon receiving a DEL_CLIENT some local or remote client has been
disconnected. If this is a local server we remove the server from the
lists and announce the removal to the remotes. Otherwise we need to
inform local servers that one of their clients might be gone, so we
propagate a DEL_SERVER message to all locally registered services.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:43:45 -07:00
Bjorn Andersson
ff29fb17a3 lib: Provide new API for clients to register services
Add a new set of operations to libqrtr for sending registration events
to the control service, rather than using the nameservice port.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 21:16:54 -07:00
Bjorn Andersson
35db849ec9 ns: Move qrtr_ctrl_cmd struct to ns.h
Move the qrtr_ctrl_cmd struct to the shared header file, order to
facilitate sending control messages directly from the library.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 12:39:43 -07:00
Bjorn Andersson
533edf89f5 ns: Cleanup debug and error prints
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-06 12:38:39 -07:00
Bjorn Andersson
fa0ef1f6e8 ns: Advertise new and removed services
Advertise services as we register and unregister them locally.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-05 21:33:40 -07:00
Bjorn Andersson
8241755aad make: Link non-static
Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-05 21:32:55 -07:00
Bjorn Andersson
ccbf77b784 ns: Add static bcast_sq to context
A number of operations broadcasts messages, so store a static
broadcast socketaddr in the context to facilitate this.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-05 17:17:51 -07:00
Bjorn Andersson
7330b7ae54 ns: Store local node id in context
Store the local node id in the "context, rather than requesting the
local node id from the kernel every time we need it.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-05 14:01:34 -07:00
Bjorn Andersson
bea2306313 ns: Refactore control message handling
Refactor the control message handling to facilitate further development.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-06-05 12:44:21 -07:00
Bjorn Andersson
307507642b ns: Extract NS message handling into separate functions
Extract NS message handling in order to clean up the switch statement.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-05-31 23:00:42 -07:00
Bjorn Andersson
2485ba680e ns: Track services per node
In order to easily shoot down all services when a remote node goes away,
or list all local services when announcing inject a "node" layer above
the services map.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-05-31 23:38:58 +00:00
Bjorn Andersson
05194b078a qrtr: Hide build warning
With newer kernels AF_QIPCRTR is already defined in the system header
files, so don't define it unconditionaly.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-05-31 15:22:55 -07:00
Bjorn Andersson
30eeff5d57 qrtr: ns: Don't broadcast reset command
The kernel will broadcast the presence of the qrtr-ns to all locally
opened sockets and any remote sockets will be notified through other
means; so drop the reset notification.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-05-30 21:47:24 -07:00
Bjorn Andersson
0c269e3f04 qrtr-lookup: Make output easier to read
Format the output in nice columns to make things easier to read.

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-05-01 20:31:13 -07:00
Bjorn Andersson
7d216fe3fb qrtr-cfg: Add to .gitignore
Add the qrtr-cfg to .gitignore

Signed-off-by: Bjorn Andersson <bjorn.andersson@linaro.org>
2017-03-27 23:22:15 -07:00