pax_global_header 0000666 0000000 0000000 00000000064 15156566070 0014525 g ustar 00root root 0000000 0000000 52 comment=fea9c0d9ecb5b8aecdf26554b26c1df6286526df
libssc/ 0000775 0000000 0000000 00000000000 15156566070 0012350 5 ustar 00root root 0000000 0000000 libssc/.gitmodules 0000664 0000000 0000000 00000000303 15156566070 0014521 0 ustar 00root root 0000000 0000000 [submodule "libqmi"]
path = libqmi
url = https://gitlab.freedesktop.org/mobile-broadband/libqmi.git
[submodule "mocking/qrtr"]
path = mocking/qrtr
url = https://github.com/linux-msm/qrtr.git
libssc/CHANGELOG.md 0000664 0000000 0000000 00000012252 15156566070 0014163 0 ustar 00root root 0000000 0000000 # Changelog
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
## [0.4.2] - 2026-03-18
### Fixed
- Tests are more reliable in CI/CD.
## [0.4.1] - 2026-03-01
### Changed
- Increased discovery timeout to 100s.
## [0.4.0] - 2026-01-11
### Improved
- Updated build instructions.
### Added
- Extract mount matrix and apply it for accelerometers.
### Fixed
- Cleaned up white space.
- Fixed 2 memory leaks caused.
- Properly close QMI client.
- Do not initialize variables if not needed.
- Do not check for `NULL` when not needed.
- Move Xiaomi Davinci struct to private header.
- Add symbol list to avoid exposing more symbols.
- Deprecation warning of protobuf-c tool.
- Do not run tests if `Q_IPCRTR protocol` is not available.
- Skip tests on ARMv7/armhf due to floating point problems with protobuf-c decoding.
- Fix printf formats for sensor UIDs.
- ABI of compass signal.
- Reworked synchronous handling.
## [0.3.0] - 2025-12-26
### Added
- Gyroscope sensor support.
- Vala bindings generation.
- GObject introspection generation.
### Fixed
- Thread symbol leaking into global scope.
### Changed
- Drop reporting threads as these are not necessary.
## [0.2.2] - 2025-02-21
### Fixed
- Load libqrtr on Debian correctly for mocking SSC.
- Use `g_assert_no_error` in tests.
- Let meson look for Python instead of specifying the binary name when mocking.
- Add `g_cond` for report threads to avoid race conditions.
## [0.2.1] - 2025-01-12
### Fixed
- Mocking Protobuf messages are now stored in the right directory.
- Mocking binary and data are now installed in the right directory.
## [0.2.0] - 2025-01-11
### Added
- Unittests for CI/CD.
- Mocking SSC DSP with ssc-server to emulate DSP on non-Qualcomm environments.
- Release instructions in RELEASE.md.
- Set `G_LOG_DOMAIN` during build to 'libssc' for easier debugging.
- Wait for DSP to become available during boot.
### Changed
- Reduced API surface. All private interfaces are now excluded from public usage.
- API is now solely exposed through `libssc.h`.
- Use proper GErrors instead of g\_warning for errors.
### Fixed
- Passing GTask in libssc-sensor was missing.
- Light sensor intensity is always positive, reject negative measurements.
- Proximity sensor will always output a measurement now when opened.
- Document availability sensor attribute and specify QMI header length.
- Path to protoc and protoc-c for compiling ProtoBuff messages.
- Public headers are now correctly installed.
- Sync API race conditions.
## [0.1.6] - 2024-06-08
### Fixed
- Ownership of GError is now properly performed when using GTasks.
- Handle access denied to address family AF\_QIPCRTR in lockdown mode.
- Fix verbose argument for enabling debug mode in ssccli.
- Race condition if the sensor is rapidly probed by opening and closing it.
## [0.1.5] - 2024-05-17
### Fixed
- Fixed LICENSE to properly indicate GPLv3.
- Add architecture diagram referenced in reverse engineering notes.
- Fix .so library name to avoid twice 'lib': liblibssc.so
### Added
- Timeout parameter for ssccli.
- Flush stdout after each sensor measurement in ssccli.
- Add support for proximity sensor of xiaomi-davinci (SM7150).
### Changed
- Expanded README with proper description and link to landing page.
- Added build instructions to README.
- Added custom domain for landing page in README.
## [0.1.4] - 2023-08-19
### Fixed
- Link with math library.
- Assert QMI client not NULL during sensor disposing.
### Added
- Define unknown type in QMI Report messages as Report Type.
### Changed
- Update to latest libqmi API changes.
- Search for sensors with a non-zero sample rate such as sensors on Pixel 3A.
## [0.1.3] - 2023-05-20
### Fixed
- Release QMI client before sensor disposing.
## [0.1.2] - 2023-05-20
### Fixed
- Segfault with unknown parameter.
- Segfault during sensor disposing.
## [0.1.1] - 2023-05-01
### Fixed
- Fix format-security warning.
## [0.1.0] - 2023-05-01
Initial release.
[0.1.0]: https://codeberg.org/DylanVanAssche/libssc/compare/01fe59f06aa107a556dd2cdf33e65fd6378eaf32...0.1.0
[0.1.1]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.0...0.1.1
[0.1.2]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.1...0.1.2
[0.1.3]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.2...0.1.3
[0.1.4]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.3...0.1.4
[0.1.5]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.4...0.1.5
[0.1.6]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.5...0.1.6
[0.2.0]: https://codeberg.org/DylanVanAssche/libssc/compare/0.1.6...v0.2.0
[0.2.1]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.2.0...v0.2.1
[0.2.2]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.2.1...v0.2.2
[0.3.0]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.2.2...v0.3.0
[0.4.0]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.3.0...v0.4.0
[0.4.1]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.4.0...v0.4.1
[0.4.2]: https://codeberg.org/DylanVanAssche/libssc/compare/v0.4.1...v0.4.2
libssc/LICENSE 0000664 0000000 0000000 00000104515 15156566070 0013363 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The GNU General Public License is a free, copyleft license for
software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
software for all its users. We, the Free Software Foundation, use the
GNU General Public License for most of our software; it applies also to
any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
To protect your rights, we need to prevent others from denying you
these rights or asking you to surrender the rights. Therefore, you have
certain responsibilities if you distribute copies of the software, or if
you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must pass on to the recipients the same
freedoms that you received. You must make sure that they, too, receive
or can get the source code. And you must show them these terms so they
know their rights.
Developers that use the GNU GPL protect your rights with two steps:
(1) assert copyright on the software, and (2) offer you this License
giving you legal permission to copy, distribute and/or modify it.
For the developers' and authors' protection, the GPL clearly explains
that there is no warranty for this free software. For both users' and
authors' sake, the GPL requires that modified versions be marked as
changed, so that their problems will not be attributed erroneously to
authors of previous versions.
Some devices are designed to deny users access to install or run
modified versions of the software inside them, although the manufacturer
can do so. This is fundamentally incompatible with the aim of
protecting users' freedom to change the software. The systematic
pattern of such abuse occurs in the area of products for individuals to
use, which is precisely where it is most unacceptable. Therefore, we
have designed this version of the GPL to prohibit the practice for those
products. If such problems arise substantially in other domains, we
stand ready to extend this provision to those domains in future versions
of the GPL, as needed to protect the freedom of users.
Finally, every program is threatened constantly by software patents.
States should not allow patents to restrict development and use of
software on general-purpose computers, but in those that do, we wish to
avoid the special danger that patents applied to a free program could
make it effectively proprietary. To prevent this, the GPL assures that
patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
TERMS AND CONDITIONS
0. Definitions.
"This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
"The Program" refers to any copyrightable work licensed under this
License. Each licensee is addressed as "you". "Licensees" and
"recipients" may be individuals or organizations.
To "modify" a work means to copy from or adapt all or part of the work
in a fashion requiring copyright permission, other than the making of an
exact copy. The resulting work is called a "modified version" of the
earlier work or a work "based on" the earlier work.
A "covered work" means either the unmodified Program or a work based
on the Program.
To "propagate" a work means to do anything with it that, without
permission, would make you directly or secondarily liable for
infringement under applicable copyright law, except executing it on a
computer or modifying a private copy. Propagation includes copying,
distribution (with or without modification), making available to the
public, and in some countries other activities as well.
To "convey" a work means any kind of propagation that enables other
parties to make or receive copies. Mere interaction with a user through
a computer network, with no transfer of a copy, is not conveying.
An interactive user interface displays "Appropriate Legal Notices"
to the extent that it includes a convenient and prominently visible
feature that (1) displays an appropriate copyright notice, and (2)
tells the user that there is no warranty for the work (except to the
extent that warranties are provided), that licensees may convey the
work under this License, and how to view a copy of this License. If
the interface presents a list of user commands or options, such as a
menu, a prominent item in the list meets this criterion.
1. Source Code.
The "source code" for a work means the preferred form of the work
for making modifications to it. "Object code" means any non-source
form of a work.
A "Standard Interface" means an interface that either is an official
standard defined by a recognized standards body, or, in the case of
interfaces specified for a particular programming language, one that
is widely used among developers working in that language.
The "System Libraries" of an executable work include anything, other
than the work as a whole, that (a) is included in the normal form of
packaging a Major Component, but which is not part of that Major
Component, and (b) serves only to enable use of the work with that
Major Component, or to implement a Standard Interface for which an
implementation is available to the public in source code form. A
"Major Component", in this context, means a major essential component
(kernel, window system, and so on) of the specific operating system
(if any) on which the executable work runs, or a compiler used to
produce the work, or an object code interpreter used to run it.
The "Corresponding Source" for a work in object code form means all
the source code needed to generate, install, and (for an executable
work) run the object code and to modify the work, including scripts to
control those activities. However, it does not include the work's
System Libraries, or general-purpose tools or generally available free
programs which are used unmodified in performing those activities but
which are not part of the work. For example, Corresponding Source
includes interface definition files associated with source files for
the work, and the source code for shared libraries and dynamically
linked subprograms that the work is specifically designed to require,
such as by intimate data communication or control flow between those
subprograms and other parts of the work.
The Corresponding Source need not include anything that users
can regenerate automatically from other parts of the Corresponding
Source.
The Corresponding Source for a work in source code form is that
same work.
2. Basic Permissions.
All rights granted under this License are granted for the term of
copyright on the Program, and are irrevocable provided the stated
conditions are met. This License explicitly affirms your unlimited
permission to run the unmodified Program. The output from running a
covered work is covered by this License only if the output, given its
content, constitutes a covered work. This License acknowledges your
rights of fair use or other equivalent, as provided by copyright law.
You may make, run and propagate covered works that you do not
convey, without conditions so long as your license otherwise remains
in force. You may convey covered works to others for the sole purpose
of having them make modifications exclusively for you, or provide you
with facilities for running those works, provided that you comply with
the terms of this License in conveying all material for which you do
not control copyright. Those thus making or running the covered works
for you must do so exclusively on your behalf, under your direction
and control, on terms that prohibit them from making any copies of
your copyrighted material outside their relationship with you.
Conveying under any other circumstances is permitted solely under
the conditions stated below. Sublicensing is not allowed; section 10
makes it unnecessary.
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
No covered work shall be deemed part of an effective technological
measure under any applicable law fulfilling obligations under article
11 of the WIPO copyright treaty adopted on 20 December 1996, or
similar laws prohibiting or restricting circumvention of such
measures.
When you convey a covered work, you waive any legal power to forbid
circumvention of technological measures to the extent such circumvention
is effected by exercising rights under this License with respect to
the covered work, and you disclaim any intention to limit operation or
modification of the work as a means of enforcing, against the work's
users, your or third parties' legal rights to forbid circumvention of
technological measures.
4. Conveying Verbatim Copies.
You may convey verbatim copies of the Program's source code as you
receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice;
keep intact all notices stating that this License and any
non-permissive terms added in accord with section 7 apply to the code;
keep intact all notices of the absence of any warranty; and give all
recipients a copy of this License along with the Program.
You may charge any price or no price for each copy that you convey,
and you may offer support or warranty protection for a fee.
5. Conveying Modified Source Versions.
You may convey a work based on the Program, or the modifications to
produce it from the Program, in the form of source code under the
terms of section 4, provided that you also meet all of these conditions:
a) The work must carry prominent notices stating that you modified
it, and giving a relevant date.
b) The work must carry prominent notices stating that it is
released under this License and any conditions added under section
7. This requirement modifies the requirement in section 4 to
"keep intact all notices".
c) You must license the entire work, as a whole, under this
License to anyone who comes into possession of a copy. This
License will therefore apply, along with any applicable section 7
additional terms, to the whole of the work, and all its parts,
regardless of how they are packaged. This License gives no
permission to license the work in any other way, but it does not
invalidate such permission if you have separately received it.
d) If the work has interactive user interfaces, each must display
Appropriate Legal Notices; however, if the Program has interactive
interfaces that do not display Appropriate Legal Notices, your
work need not make them do so.
A compilation of a covered work with other separate and independent
works, which are not by their nature extensions of the covered work,
and which are not combined with it such as to form a larger program,
in or on a volume of a storage or distribution medium, is called an
"aggregate" if the compilation and its resulting copyright are not
used to limit the access or legal rights of the compilation's users
beyond what the individual works permit. Inclusion of a covered work
in an aggregate does not cause this License to apply to the other
parts of the aggregate.
6. Conveying Non-Source Forms.
You may convey a covered work in object code form under the terms
of sections 4 and 5, provided that you also convey the
machine-readable Corresponding Source under the terms of this License,
in one of these ways:
a) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by the
Corresponding Source fixed on a durable physical medium
customarily used for software interchange.
b) Convey the object code in, or embodied in, a physical product
(including a physical distribution medium), accompanied by a
written offer, valid for at least three years and valid for as
long as you offer spare parts or customer support for that product
model, to give anyone who possesses the object code either (1) a
copy of the Corresponding Source for all the software in the
product that is covered by this License, on a durable physical
medium customarily used for software interchange, for a price no
more than your reasonable cost of physically performing this
conveying of source, or (2) access to copy the
Corresponding Source from a network server at no charge.
c) Convey individual copies of the object code with a copy of the
written offer to provide the Corresponding Source. This
alternative is allowed only occasionally and noncommercially, and
only if you received the object code with such an offer, in accord
with subsection 6b.
d) Convey the object code by offering access from a designated
place (gratis or for a charge), and offer equivalent access to the
Corresponding Source in the same way through the same place at no
further charge. You need not require recipients to copy the
Corresponding Source along with the object code. If the place to
copy the object code is a network server, the Corresponding Source
may be on a different server (operated by you or a third party)
that supports equivalent copying facilities, provided you maintain
clear directions next to the object code saying where to find the
Corresponding Source. Regardless of what server hosts the
Corresponding Source, you remain obligated to ensure that it is
available for as long as needed to satisfy these requirements.
e) Convey the object code using peer-to-peer transmission, provided
you inform other peers where the object code and Corresponding
Source of the work are being offered to the general public at no
charge under subsection 6d.
A separable portion of the object code, whose source code is excluded
from the Corresponding Source as a System Library, need not be
included in conveying the object code work.
A "User Product" is either (1) a "consumer product", which means any
tangible personal property which is normally used for personal, family,
or household purposes, or (2) anything designed or sold for incorporation
into a dwelling. In determining whether a product is a consumer product,
doubtful cases shall be resolved in favor of coverage. For a particular
product received by a particular user, "normally used" refers to a
typical or common use of that class of product, regardless of the status
of the particular user or of the way in which the particular user
actually uses, or expects or is expected to use, the product. A product
is a consumer product regardless of whether the product has substantial
commercial, industrial or non-consumer uses, unless such uses represent
the only significant mode of use of the product.
"Installation Information" for a User Product means any methods,
procedures, authorization keys, or other information required to install
and execute modified versions of a covered work in that User Product from
a modified version of its Corresponding Source. The information must
suffice to ensure that the continued functioning of the modified object
code is in no case prevented or interfered with solely because
modification has been made.
If you convey an object code work under this section in, or with, or
specifically for use in, a User Product, and the conveying occurs as
part of a transaction in which the right of possession and use of the
User Product is transferred to the recipient in perpetuity or for a
fixed term (regardless of how the transaction is characterized), the
Corresponding Source conveyed under this section must be accompanied
by the Installation Information. But this requirement does not apply
if neither you nor any third party retains the ability to install
modified object code on the User Product (for example, the work has
been installed in ROM).
The requirement to provide Installation Information does not include a
requirement to continue to provide support service, warranty, or updates
for a work that has been modified or installed by the recipient, or for
the User Product in which it has been modified or installed. Access to a
network may be denied when the modification itself materially and
adversely affects the operation of the network or violates the rules and
protocols for communication across the network.
Corresponding Source conveyed, and Installation Information provided,
in accord with this section must be in a format that is publicly
documented (and with an implementation available to the public in
source code form), and must require no special password or key for
unpacking, reading or copying.
7. Additional Terms.
"Additional permissions" are terms that supplement the terms of this
License by making exceptions from one or more of its conditions.
Additional permissions that are applicable to the entire Program shall
be treated as though they were included in this License, to the extent
that they are valid under applicable law. If additional permissions
apply only to part of the Program, that part may be used separately
under those permissions, but the entire Program remains governed by
this License without regard to the additional permissions.
When you convey a copy of a covered work, you may at your option
remove any additional permissions from that copy, or from any part of
it. (Additional permissions may be written to require their own
removal in certain cases when you modify the work.) You may place
additional permissions on material, added by you to a covered work,
for which you have or can give appropriate copyright permission.
Notwithstanding any other provision of this License, for material you
add to a covered work, you may (if authorized by the copyright holders of
that material) supplement the terms of this License with terms:
a) Disclaiming warranty or limiting liability differently from the
terms of sections 15 and 16 of this License; or
b) Requiring preservation of specified reasonable legal notices or
author attributions in that material or in the Appropriate Legal
Notices displayed by works containing it; or
c) Prohibiting misrepresentation of the origin of that material, or
requiring that modified versions of such material be marked in
reasonable ways as different from the original version; or
d) Limiting the use for publicity purposes of names of licensors or
authors of the material; or
e) Declining to grant rights under trademark law for use of some
trade names, trademarks, or service marks; or
f) Requiring indemnification of licensors and authors of that
material by anyone who conveys the material (or modified versions of
it) with contractual assumptions of liability to the recipient, for
any liability that these contractual assumptions directly impose on
those licensors and authors.
All other non-permissive additional terms are considered "further
restrictions" within the meaning of section 10. If the Program as you
received it, or any part of it, contains a notice stating that it is
governed by this License along with a term that is a further
restriction, you may remove that term. If a license document contains
a further restriction but permits relicensing or conveying under this
License, you may add to a covered work material governed by the terms
of that license document, provided that the further restriction does
not survive such relicensing or conveying.
If you add terms to a covered work in accord with this section, you
must place, in the relevant source files, a statement of the
additional terms that apply to those files, or a notice indicating
where to find the applicable terms.
Additional terms, permissive or non-permissive, may be stated in the
form of a separately written license, or stated as exceptions;
the above requirements apply either way.
8. Termination.
You may not propagate or modify a covered work except as expressly
provided under this License. Any attempt otherwise to propagate or
modify it is void, and will automatically terminate your rights under
this License (including any patent licenses granted under the third
paragraph of section 11).
However, if you cease all violation of this License, then your
license from a particular copyright holder is reinstated (a)
provisionally, unless and until the copyright holder explicitly and
finally terminates your license, and (b) permanently, if the copyright
holder fails to notify you of the violation by some reasonable means
prior to 60 days after the cessation.
Moreover, your license from a particular copyright holder is
reinstated permanently if the copyright holder notifies you of the
violation by some reasonable means, this is the first time you have
received notice of violation of this License (for any work) from that
copyright holder, and you cure the violation prior to 30 days after
your receipt of the notice.
Termination of your rights under this section does not terminate the
licenses of parties who have received copies or rights from you under
this License. If your rights have been terminated and not permanently
reinstated, you do not qualify to receive new licenses for the same
material under section 10.
9. Acceptance Not Required for Having Copies.
You are not required to accept this License in order to receive or
run a copy of the Program. Ancillary propagation of a covered work
occurring solely as a consequence of using peer-to-peer transmission
to receive a copy likewise does not require acceptance. However,
nothing other than this License grants you permission to propagate or
modify any covered work. These actions infringe copyright if you do
not accept this License. Therefore, by modifying or propagating a
covered work, you indicate your acceptance of this License to do so.
10. Automatic Licensing of Downstream Recipients.
Each time you convey a covered work, the recipient automatically
receives a license from the original licensors, to run, modify and
propagate that work, subject to this License. You are not responsible
for enforcing compliance by third parties with this License.
An "entity transaction" is a transaction transferring control of an
organization, or substantially all assets of one, or subdividing an
organization, or merging organizations. If propagation of a covered
work results from an entity transaction, each party to that
transaction who receives a copy of the work also receives whatever
licenses to the work the party's predecessor in interest had or could
give under the previous paragraph, plus a right to possession of the
Corresponding Source of the work from the predecessor in interest, if
the predecessor has it or can get it with reasonable efforts.
You may not impose any further restrictions on the exercise of the
rights granted or affirmed under this License. For example, you may
not impose a license fee, royalty, or other charge for exercise of
rights granted under this License, and you may not initiate litigation
(including a cross-claim or counterclaim in a lawsuit) alleging that
any patent claim is infringed by making, using, selling, offering for
sale, or importing the Program or any portion of it.
11. Patents.
A "contributor" is a copyright holder who authorizes use under this
License of the Program or a work on which the Program is based. The
work thus licensed is called the contributor's "contributor version".
A contributor's "essential patent claims" are all patent claims
owned or controlled by the contributor, whether already acquired or
hereafter acquired, that would be infringed by some manner, permitted
by this License, of making, using, or selling its contributor version,
but do not include claims that would be infringed only as a
consequence of further modification of the contributor version. For
purposes of this definition, "control" includes the right to grant
patent sublicenses in a manner consistent with the requirements of
this License.
Each contributor grants you a non-exclusive, worldwide, royalty-free
patent license under the contributor's essential patent claims, to
make, use, sell, offer for sale, import and otherwise run, modify and
propagate the contents of its contributor version.
In the following three paragraphs, a "patent license" is any express
agreement or commitment, however denominated, not to enforce a patent
(such as an express permission to practice a patent or covenant not to
sue for patent infringement). To "grant" such a patent license to a
party means to make such an agreement or commitment not to enforce a
patent against the party.
If you convey a covered work, knowingly relying on a patent license,
and the Corresponding Source of the work is not available for anyone
to copy, free of charge and under the terms of this License, through a
publicly available network server or other readily accessible means,
then you must either (1) cause the Corresponding Source to be so
available, or (2) arrange to deprive yourself of the benefit of the
patent license for this particular work, or (3) arrange, in a manner
consistent with the requirements of this License, to extend the patent
license to downstream recipients. "Knowingly relying" means you have
actual knowledge that, but for the patent license, your conveying the
covered work in a country, or your recipient's use of the covered work
in a country, would infringe one or more identifiable patents in that
country that you have reason to believe are valid.
If, pursuant to or in connection with a single transaction or
arrangement, you convey, or propagate by procuring conveyance of, a
covered work, and grant a patent license to some of the parties
receiving the covered work authorizing them to use, propagate, modify
or convey a specific copy of the covered work, then the patent license
you grant is automatically extended to all recipients of the covered
work and works based on it.
A patent license is "discriminatory" if it does not include within
the scope of its coverage, prohibits the exercise of, or is
conditioned on the non-exercise of one or more of the rights that are
specifically granted under this License. You may not convey a covered
work if you are a party to an arrangement with a third party that is
in the business of distributing software, under which you make payment
to the third party based on the extent of your activity of conveying
the work, and under which the third party grants, to any of the
parties who would receive the covered work from you, a discriminatory
patent license (a) in connection with copies of the covered work
conveyed by you (or copies made from those copies), or (b) primarily
for and in connection with specific products or compilations that
contain the covered work, unless you entered into that arrangement,
or that patent license was granted, prior to 28 March 2007.
Nothing in this License shall be construed as excluding or limiting
any implied license or other defenses to infringement that may
otherwise be available to you under applicable patent law.
12. No Surrender of Others' Freedom.
If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot convey a
covered work so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you may
not convey it at all. For example, if you agree to terms that obligate you
to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
but the special requirements of the GNU Affero General Public License,
section 13, concerning interaction through a network will apply to the
combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
Later license versions may give you additional or different
permissions. However, no additional obligations are imposed on any
author or copyright holder as a result of your choosing to follow a
later version.
15. Disclaimer of Warranty.
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
16. Limitation of Liability.
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
SUCH DAMAGES.
17. Interpretation of Sections 15 and 16.
If the disclaimer of warranty and limitation of liability provided
above cannot be given local legal effect according to their terms,
reviewing courts shall apply local law that most closely approximates
an absolute waiver of all civil liability in connection with the
Program, unless a warranty or assumption of liability accompanies a
copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Copyright (C)
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
.
libssc/README.md 0000664 0000000 0000000 00000004732 15156566070 0013635 0 ustar 00root root 0000000 0000000 # libssc
`libssc` is a library to expose the sensors managed by the Qualcomm Sensor Core
found in many Qualcomm System-on-Chips (SoCs) from 2018 and onwards.
Qualcomm SoCs feature a Sensor Lower Power Island (SLPI)
to offload sensors to a dedicated Digital Signal Processor (DSP)
for optimizing power consumption and reducing the tasks of the main CPU.
This way, the main CPU may enter full suspend while the DSP can detect proximity
from the proximity sensor and wake up the main CPU.
Direct access to the sensors is prohibited by the hypervisor,
thus the only way to access sensors on these SoCs is by talking
to the DSP managing these sensors.
Libssc performs this task and exposes the sensors as a GLib-based library
which allows seamless integration with the existing Linux ecosystem.
_Qualcomm, Sensor Low Power Island (SLPI), and Qualcomm Sensor Core are registed trademarks
of QUALCOMM Incorporated. Any rights therein are reserved to QUALCOMM Incorporated.
Any use by the libssc project is for referential purposes only and does not indicate any sponsorship,
endorsement or affiliation between QUALCOMM Incorporated and the libssc project._
## Documentation
General information about libssc, documentation, and other information can be found at
[https://libssc.dylanvanassche.be](https://libssc.dylanvanassche.be).
## Building
`libssc` uses the Meson build system with a minimal list of external dependencies:
- `libqmi >=1.33.4`
- `glib >= 2.56`
- `protobuf-c`
`libssc` tests requires an additional dependency to compile the ProtoBuf messages for simulating the DSP QMI responses:
- `protobuf`
- `python-gobject3`
- `qrtr-libs`
```
meson setup _build
meson compile -C _build
```
Tests can be executed with:
```
meson test -C _build
```
## Linking against libssc
Use `pkg-config` in your favorite build system to link against `libssc`.
The library is called `libssc`, in Meson it looks like this:
```
libssc_dep = dependency('libssc')
```
## Lockdown
Systemd features a lockdown feature to reduce access to resources for services.
If `libssc` is used in a service such as `iio-sensor-proxy`, make sure access to the address family `AF_QIPCRTR`
otherwise access to the QRTR bus is prohibited.
## Tests
Libssc has tests with and without the SSC mocking server to verify also the behavior
of libssc when the QMI service is not present.
## License
Available under the [GPLv3 license](./LICENSE).
Copyright (c) by libssc Authors (2022-2026)
libssc/RELEASE.md 0000664 0000000 0000000 00000000421 15156566070 0013747 0 ustar 00root root 0000000 0000000 # Release instructions
1. Update [CHANGELOG.md](CHANGELOG.md) with the latest changes
2. Update version tag in `meson.build`.
3. Update SSC Server version in `mocking/ssc-server`.
4. Tag an annotated release with semantic versioning: `git tag -s -m "libssc X.Y.Z" vX.Y.Z`
libssc/data/ 0000775 0000000 0000000 00000000000 15156566070 0013261 5 ustar 00root root 0000000 0000000 libssc/data/meson.build 0000664 0000000 0000000 00000003776 15156566070 0015440 0 ustar 00root root 0000000 0000000 # SPDX-License-Identifier: GPL-3.0-or-later
#
# libssc: Library to expose Qualcomm Sensor Core sensors
# Copyright (C) 2022-2026 Dylan Van Assche
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see .
#
msgs_inc = include_directories('.')
msgs = [
'common',
'sensor-suid',
'sensor-proximity',
'sensor-light',
'sensor-accelerometer',
'sensor-magnetometer',
'sensor-rotationvector',
'sensor-gyroscope',
]
sources_gen = []
headers_gen = []
python_gen = []
foreach m: msgs
name = 'ssc-' + m
# C
protobuf_c_gen = custom_target (
name + '_c',
input: name + '.proto',
output: [name + '.pb-c.c', name + '.pb-c.h'],
command: [protocc_tool, '--proto_path=@CURRENT_SOURCE_DIR@', '--c_out=@OUTDIR@', '@INPUT@'],
install: true,
install_dir: [false, libssc_glib_pkgincludedir]
)
sources_gen += protobuf_c_gen[0]
headers_gen += protobuf_c_gen[1]
# Python
python_name = 'ssc_' + m.replace('-', '_')
protobuf_python_gen = custom_target (
python_name + '_py',
input: name + '.proto',
output: [python_name + '_pb2.py'],
command: [protoc_tool, '-I=@CURRENT_SOURCE_DIR@', '--python_out=@OUTDIR@', '@INPUT@'],
install: true,
install_dir: [libssc_mocking_dir]
)
python_gen += protobuf_python_gen[0]
endforeach
generated_dep = declare_dependency(
sources: sources_gen + headers_gen + python_gen,
include_directories: includes,
dependencies: deps
)
deps += generated_dep
libssc/data/ssc-common.proto 0000664 0000000 0000000 00000010116 15156566070 0016423 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Each message has a sensor UID to specify which sensor
* should receive the message. UIDs are 128bit, but ProtoBuf
* is limited to 64bit values, thus they are split into uid_low
* and uid_high.
*/
message SscUid {
required fixed64 low = 1;
required fixed64 high = 2;
}
/*
* Client configuration
* @processor: a value from the SscProcessorType enum. Default APPS (1).
* @suspend_mode: a value from the SscSuspendType enum. Default WAKEUP (0).
* @no_wakeup_msg_ids: list of messages that do not cause a wakeup.
*/
message SscClientConfig {
required int32 processor = 1 [default = 1];
required int32 suspend_mode = 2 [default = 0];
}
/*
* Client request body
* @unknown: optional
* @msg: the actual sensor request, specific for each sensor.
* @is_passive: request is passive or not. Active triggers sensor activation.
*/
message SscClientRequestBody {
optional bytes unknown = 1;
optional bytes msg = 2;
optional bool is_passive = 3 [default = false];
}
/*
* Client request
* @uid: UID of the sensor.
* @msg_id: ID of the message.
* @config: configuration for the wakeups of the client.
* @request: request for the sensor
*/
message SscClientRequest {
required SscUid uid = 1;
required fixed32 msg_id = 2;
required SscClientConfig config = 3;
required SscClientRequestBody request = 4;
}
/*
* Client response body
* @msg_id: ID of the message.
* @timestamp: DSP internal timer, 19.2 MHz.
* @msg: the actual response of the sensor, sensor specific.
*/
message SscClientResponseBody {
required fixed32 msg_id = 1;
required fixed64 timestamp = 2;
required bytes msg = 3;
}
/*
* Client response
* @uid: UID of the sensor.
* @response: list of responses.
*/
message SscClientResponse {
required SscUid uid = 1;
repeated SscClientResponseBody response = 2;
}
/*
* Sensor attribute request
* @enable_updates: setting this property to true will enable updates for attributes.
*/
message SscAttrRequest {
optional bool enable_updates = 2;
}
/*
* Sensor attribute value array
* @element: element of the attribute value array.
*/
message SscAttrValueArray {
repeated SscAttrValue element = 1;
}
/*
* Sensor attribute value
* Depending on the attribute one of the optional values will be included.
* @a: attribute value array data.
* @s: string value data.
* @f: floating point value data.
* @i: integer value data.
* @b: boolean value data.
*/
message SscAttrValue {
optional SscAttrValueArray a = 1;
optional string s = 2;
optional float f = 3;
optional fixed64 i = 4;
optional bool b = 5;
}
/*
* Sensor attribute value array
* @v: element of the value array
*/
message SscAttrArrayValue {
repeated SscAttrValue v = 1;
}
/*
* Sensor attribute
* @id: Attribute ID.
* @value: Attribute value.
*/
message SscAttr {
required int32 id = 1;
required SscAttrArrayValue value_array = 2;
}
/*
* Sensor attribute response
* @attr: list of attributes for a sensor.
*/
message SscAttrResponse {
repeated SscAttr attr = 1;
}
/*
* Sensor enable config request
* @sample_rate: requested sample rate in Hz.
*/
message SscEnableConfigRequest {
required float sample_rate = 1;
}
/*
* Sensor config response
* @sample_rate: actual sample rate in Hz.
* @mode: the sensor's operation mode.
*/
message SscConfigResponse {
optional float sample_rate = 1;
optional string mode = 5;
}
libssc/data/ssc-sensor-accelerometer.proto 0000664 0000000 0000000 00000002154 15156566070 0021257 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Accelerometer Sensor specific response data.
* @acceleration: acceleration per axis in m/s²: X-axis [0], Y-axis [1], Z-axis [2].
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscAccelerometerResponse {
repeated float acceleration = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-gyroscope.proto 0000664 0000000 0000000 00000002152 15156566070 0020455 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2025 Vasiliy Doylov
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Gyroscope Sensor specific response data.
* @velocity: velocity per axis in m/s: X-axis [0], Y-axis [1], Z-axis [2].
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscGyroscopeResponse {
repeated float velocity = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-light.proto 0000664 0000000 0000000 00000002100 15156566070 0017543 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Light Sensor specific response data.
* @intensity: intensity in Lux [0] or raw sensor value [1].
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscLightResponse {
repeated float intensity = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-magnetometer.proto 0000664 0000000 0000000 00000002156 15156566070 0021136 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Magnetometer Sensor specific response data.
* @magnetic_field: magnetic field per axis in µT: X-axis [0], Y-axis [1], Z-axis [2].
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscMagnetometerResponse {
repeated float magnetic_field = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-proximity.proto 0000664 0000000 0000000 00000002750 15156566070 0020513 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Proximity Sensor specific response data.
* @near: in-proximity or not, NEAR = 1, FAR = 0.
* @distance: raw distance from sensor, vendor-specific.
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscProximityResponse {
required int32 near = 1;
required int32 distance = 2;
required int32 accuracy = 3;
}
/*
* Proximity Sensor specific response data, as seen on Xiaomi Mi 9T / Redmi K20 (xiaomi-davinci).
* @data: measurement data, a C struct as raw bytes.
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscProximityResponseDavinci {
repeated bytes data = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-rotationvector.proto 0000664 0000000 0000000 00000002174 15156566070 0021531 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
/*
* Rotationvector Sensor specific response data.
* @rotation: rotation per axis as quaternion: X-axis [0], Y-axis [1], Z-axis [2], W rotation angle [3]
* @accuracy: how reliable the value is [0, 3]. Higher is more accurate, 0 is unreliable.
*/
message SscRotationvectorResponse {
repeated float rotation = 1;
required int32 accuracy = 2;
}
libssc/data/ssc-sensor-suid.proto 0000664 0000000 0000000 00000003057 15156566070 0017414 0 ustar 00root root 0000000 0000000 /*
* libssc: Library to expose Qualcomm Sensor Core sensors
* Copyright (C) 2022-2026 Dylan Van Assche
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*/
syntax = "proto2";
import "ssc-common.proto";
/*
* SUID Sensor specific request data.
* @data_type: retrieve all sensors exposing the specified data type.
* An empty value will return all sensors.
* @enable_updates: setting this to true will enable updates
* for the specified data_type.
* @only_default_values: setting this to true will only return
* the default sensor for the data_type, even if multiple sensors expose it.
*/
message SscSuidRequest {
required string data_type = 1;
optional bool enable_updates = 2;
optional bool only_default_values = 3;
}
/*
* SUID Sensor specific response data.
* @data_type: the data_type for which the list of UIDs match.
* @uid: list of matching UIDs.
*/
message SscSuidResponse {
required string data_type = 1;
repeated SscUid uid = 2;
}
libssc/docs/ 0000775 0000000 0000000 00000000000 15156566070 0013300 5 ustar 00root root 0000000 0000000 libssc/docs/Qualcomm-Sensorcore-Docs.md 0000664 0000000 0000000 00000160136 15156566070 0020415 0 ustar 00root root 0000000 0000000 # Qualcomm SDM845 Snapdragon Sensorcore
The SDM845 and newer Qualcomm SoCs contain a Qualcomm Snapdragon Sensor Core (SSC) which exposes the device's sensors over QRTR to the main CPU. The SSC allows the main CPU to fully idle or suspend while the sensors are still running, for example: detect proximity and wake up the device. Moreover, it controls the sensors and sampling to maximize battery life when in use.
## Architecture
The SSC resides on the SPLI aDSP in the SDM845. Accessing the sensors directly is impossible, we have to communicate with the SSC. The SSC communicates to userspace through 2 daemons:

- **android.hardware.sensors** (@1.0-service on Oneplus 6, @2.0-service on SHIFT6mq)
- Exposes the sensors to Android.
- Sends and receives messages over QMI with a Protobuf payload.
- Waits until sscrpd is done before starting, achieved through init scripts.
- **sscrpd**
- FastRPC daemon which talks to the SSC.
- Reads various JSON configs from the persist partition which the SSC needs to control the sensors such as bus type (I2C, I3C, ...), bus address, etc.
- Only reads the JSON configs at boot, does not much do anything besides that.
## Communication
The SSC communicates, like any other Qualcomm device, over QMI (Qualcomm Message Interface) messages. However, QMI is only used here as a envelope for the actual data, which is encoded in [Google's Protocol Buffers (Protobuf)](https://developers.google.com/protocol-buffers/) which was discovered by analyzing the binary data from an strace dump and executing the strings command on the various sensor libraries on downstream. It became clear that the data at some point did not match anymore with the one from QMI, but required some kind of structure, so trial-and-error resulted in discovering Protobuf as encoding scheme. ProtoBuf compiles data structures in a binary format to optimize the data transfer and make sure that the encoding and decoding remains consistent when fields are added or removed.
QMI messages contain a predefined header and a set of [TLV (Type-Length-Value) structures](https://en.wikipedia.org/wiki/Type%E2%80%93length%E2%80%93value), therefore they always look like this (see [this blogpost](https://emainline.gitlab.io/2022/04/08/Unlocking_SSC_P2.html) for a detailed explanation):
**Header**
```
{
type: uint8,
txn_id: uint16,
msg_id: uint16,
msg_len: uint16
}
```
**TLVs**
```
{
type: uint8,
length: uint16,
value: length * uint8
}
```
Protobuf messages are compiled from a scheme defined in `*.proto` files. However, these files are not publicly available so we have to resort to reverse-engineering them. When we have a Protobuf message, we can give it to a tool such as [protobuf-inspector](https://github.com/mildsunrise/protobuf-inspector) to reveal their structure and content.
### Stracing the sensor HAL on downstream
[-emainline blogpost](https://emainline.gitlab.io/2022/04/08/Unlocking_SSC_P2.html) explains amazingly well already how to reveal the Qualcomm Sensorcore messages using strace. However, the Sensorcore on SDM845 is a newer version which does not use QMI messages for the payload, but protobuf instead. Luckily, the same instructions apply, just the part about decoding the messages differs:
1. Get an ADB shell with root permissions (only works on LineageOS builds!):
- `adb root # if necessary use sudo if adb complains about permissions`
- `adb shell`
2. Find the sensor HAL daemon PID: `ps -A | grep android.hardware.sensors`
3. Attach strace to it: `strace -p $PID -f -e trace=sendto,recvfrom -xx -s 1024`
- `sendto`, `recvfrom` shows all QMI messages being send to and received from the SSC
- `-f` tells strace to follow subprocesses
- `-xx` prints all strings as hexadecimal
- `-s 1024` to show the complete strings instead of only a part of it.
#### Boot Behavior
Stracing the startup of the daemon shows some useful information: it queries the SSC for all available sensors and subscribes to them. For each type of sensor data (proximity, gravity, etc.) it asks for the SSC registry (see further) if there's a sensor available. If so, the SSC returns the sensor IDs for all sensors providing this type of sensor data. These sensor IDs are used later on for performing operations.
#### Screen state behavior
Interesting is that the SSC sensors are not always enabled. If the screen is OFF, only a few sensors like the proximity sensor is enabled. When the screen is turned ON, other sensors like the accelerometer and gyroscope output data to the sensor HAL daemon.
#### Applications requiring specific sensors
Some sensors are specific to applications such a compass for navigation applications. These sensors are only enabled on-demand to save power.
### Stracing the sscrpcd daemon on downstream
The `sscrpcd` is a pain to strace, it only does it thing at boot so you need to make sure that the service fails somehow. This way, you can start it manually and strace the boot sequence.
1. Get an ADB shell with root permissions (only works on LineageOS builds!):
- `adb root # if necessary use sudo if adb complains about permissions`
- `adb remount # we need RW access`
- `adb shell`
2. Android is a pain with its read-only rootFS, you need to remount /vendor first since we want to modify the services there (adb remount doesn't cut it here completely): `mount -o rw,remount /vendor`
3. Open to `/vendor/etc/init/hw/init.qcom.rc` and change the service description for `sscrpcd` to (add `/bin/strace` which breaks startup, thanks SELinux, disabling the service the right way makes Android angry):
```
service vendor.sensors /bin/strace /vendor/bin/sscrpcd sensorspd
class early_hal
user system
group system wakelock
capabilities BLOCK_SUSPEND
writepid /dev/cpuset/system-background/tasks
```
4. Reboot, LineageOS will keep showing the load animation as it will try to start the service but fails horribly thanks to SELinux not being happy with our voodoo from above.
5. Run strace (needs a reboot each time you want to run it!):
- Everything interesting: `strace -f -s 2048 -e trace=recvfrom,sendto,file,desc,open,close /vendor/bin/sscrpcd 2>/cache/log.txt`
- `ioctl`s for FastRPC (fd 8 is the FastRPC one): `strace -f -s 2048 -e raw=ioctl -e trace=ioctl -e read=8 -e write=8 /vendor/bin/sscrpcd 2>/cache/log-ioctl.txt`
This took a few days to locate this daemon and getting an strace dump from it with useful data.
#### Boot behavior
Reads the some files and configs of the sensors in `/mnt/persist/vendor/` and `/vendor/etc/sensors` and execute FastRPC calls (`ioctl`) after accessing each file. Does not do anything besides that during its life cycle.
### PoC on mainline
Now that we pretty well known how the SSC talks with the sensor HAL daemon and `sscrpcd`, we should try to write a PoC to query the sensors like the sensor HAL daemon does on startup. The daemon can open a QRTR connection to the SSC and send/receive QMI messages. That's all!
### Decoding SSC messages
Analyzing the strace dumps revealed that QMI is only used as an envelope and the actual messages are Protobuf-only. We will first decode the QMI part and then decode all the Protobuf messages.
**Let's take the following message from an strace dump:**
```
[pid 6859] recvfrom(17, "\x04\x05\x00\x22\x00\x53\x00\x01\x08\x00\xa9\x19\x00\x00\x00\x00\x00\x00\x02\x45\x00\x43\x00\x0a\x12\x09\xab\xab\xab\xab\xab\xab\xab\xab\x11\xab\xab\xab\xab\xab\xab\xab\xab\x12\x2d\x0d\x00\x03\x00\x00\x11\x8a\xa3\x6a\x89\x3c\x35\x00\x00\x1a\x1d\x0a\x07\x67\x72\x61\x76\x69\x74\x79\x12\x12\x09\x2e\xf5\x5b\xf6\xc0\x98\x43\xa7\x11\xa5\xa6\x50\x68\x2d\x5a\xd4\xc5", 62024, MSG_DONTWAIT, {sa_family=AF_IB, sa_data="\x00\x00\x02\x00\x00\x00\x09\x00\x00\x00\x11\x00\x00\x00\x00\x00\x00\x00"}, [20]) = 90
```
#### QMI part
All Protobuf messages start with `\x0a\x12`, so everything before that is QMI:
```
04 05 00 22 00 53 00 01 08 00 a9 19 00 00 00 00 00 00 02 45 00 43 00
```
Thanks to a [-emainline blogpost](http://If we translate the QMI message using the TLV structure as explained [here](https://emainline.gitlab.io/2022/04/08/Unlocking_SSC_P2.html):), decoding the QMI part is straightforward. We need to extract the QMI header and all its TLVs:
**Header**
- `04` = QMI INDICATION (uint8)
- `05 00` = txn_id (uint16)
- `22 00` = msg_id (uint16)
- `53 00` = msg_length (uint16)
Header is 7 bytes long.
Here is the QMI message an indication. That means that the message doesn't expect a reply. Other possibilities are QMI REQUEST and QMI RESPONSE.
**TLV1**
- Type: `01`
- Length: `08 00`
- Value: `91 00 00 00 00 00 00 00`
The first TLV indicates the client ID of the QMI client.
**TLV2**
- Type: `02`
- Length: `45 00`
- Value: `43 00 0a 12 09 ab ab ab ab ab ab ab ab 11 ab ab ab ab ab ab ab ab 12 2d 0d 00 03 00 00 11 a2 9c d6 2c 4a 00 00 00 1a 1d 0a 07 67 72 61 76 69 74 79 12 12 09 2e f5 5b f6 c0 98 43 a7 11 a5 a6 50 68 2d 5a d4 c5`
The second TLV contains the actual Protobuf message. Interesting here is that the TLV's value contains 43 00 besides the actual Protobuf message (remember that they start with `0a 12`).
This field is 2 bytes long, the Protobuf data is 67 bytes, together 69 bytes which matches exactly the TLV's length (`45 00` = 69). So this probably specifies the length of the Protobuf message:
```
{
type: uint8,
length: uint16,
value: {
protobuf_length: uint8,
protobuf_msg: protobuf_length * uint8
}
}
```
Now that we can communicate with the SSC over QMI, we should have some content in our messages, that's where Protobuf comes in!
#### Protobuf part
The Protobuf payload of each QMI message is the actual content we need to decode. If we run the message from above through protobuf-inspector, we get the following:
```
printf "%b" "\x0a\x12\x09\xab\xab\xab\xab\xab\xab\xab\xab\x11\xab\xab\xab\xab\xab\xab
\xab\xab\x12\x2d\x0d\x00\x03\x00\x00\x11\xa2\x9c\xd6\x2c\x4a\x00\x00\x00\x1a\x1d\x0a\x07\x67\x72\x61\x76\x69\x74\x79\x
12\x12\x09\x2e\xf5\x5b\xf6\xc0\x98\x43\xa7\x11\xa5\xa6\x50\x68\x2d\x5a\xd4\xc5" | protobuf_inspector
root:
1 = message:
1 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 = message:
1 <32bit> = 0x00000300 / 768 / 1.07620e-42
2 <64bit> = 0x0000004A2CD69CA2 / 318579842210 / 1.5739936e-312
3 = message:
1 = "gravity"
2 = message:
1 <64bit> = 0xA74398C0F65BF52E / -6394099091401607890 / -1.5178000e-119
2 <64bit> = 0xC5D45A2D6850A6A5 / -4191626202104944987 / -2.5194872e+28
```
The binary data representing the QMI message was removed in the example above
so we only have the protobuf encoded data for the inspector.
The inspector identifies the structure and value types, sometimes by guessing.
However, it doesn't know what each field actually means.
Luckily, we can guess the meaning of each field by analyzing more strace dumps,
this resulted in the following structure after reverse-engineering:
```
{
unknown1: {
unknown1a: 64bit, # constant
unknown1b: 64bit # constant
},
unknown2: {
type: 32bit, # different numbers are given here but with a recurring pattern, so probably some enum
unknown2a: 64bit # increments in time, probably timestamp
data: {
sensor: string, # kind of data is specified as string, example: gravity, proximity, etc.
values: {
unknown2b: 64bit,
unknown2c: 64bit
}
}
}
}
```
This information can be put in `protobuf-inspector` by creating the following `protobuf_config.py` file:
```
# data blob
types = {
"root": {
1: ("header", "header"),
2: ("data", "data")
},
"header": {
1: ("64bit", "unknown1"),
2: ("64bit", "unknown1")
},
"data": {
1: ("32bit", "type"),
2: ("64bit", "timestamp"),
3: ("payload", "payload")
},
"payload": {
1: ("string", "type"),
2: ("measurements", "measurements")
},
"measurements": {
1: ("64bit", "unknown3"),
2: ("64bit", "unknown4")
}
}
```
Thanks to this scheme, `protobuf-inspector` can show a bit more information:
```
root:
1 header = header:
1 unknown1 = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 unknown1 = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 data = data:
1 type = 768
2 timestamp = 318579842210
3 payload = payload:
1 type = "gravity"
2 measurements = measurements:
1 unknown3 = 0xA74398C0F65BF52E / -6394099091401607890 / -1.5178000e-119
2 unknown4 = 0xC5D45A2D6850A6A5 / -4191626202104944987 / -2.5194872e+28
```
Given that we know this is a gravity data message, we would expect 3 data values: X, Y, Z since gravity sensors always report the gravity for the X, Y, Z.
Let's try some bruteforcing since the inspector is clearly wrong here with its guess.
Gravity is mostly provided as a floating point number, so we can try that one first:
```
root:
1 header = header:
1 unknown1 = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 unknown1 = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 data = data:
1 type = 768
2 timestamp = 318579842210
3 payload = payload:
1 type = "gravity"
2 measurements = measurements:
1 unknown3 = ERROR: Traceback...
2 <64bit> = 0xC5D45A2D6850A6A5 / -4191626202104944987 / -2.5194872e+28
```
After some trial-and-error, you need to re-evaluate your previous assumptions as you may have assumed something wrong.
Maybe this is not a data message, but another one? Given that the SSC needs to know how to operate a sensor given a request
from userspace, this might be a configuration message?
It is kinda hard to make any sense of the measurements message, we need to analyze other messages first to find more patterns.
## Example: Sensor properties message
We selected another random message that didn't look like the previous one for decoding and reverse-engineering.
We immediately see something similar between this message and the previous one, it has the same
kind of header and a data message with a type and timestamp. So we can assume this part is more or less correct.
Timestamp doesn't match any UNIX timestamp encoding, but in the end we don't need this value not really for our purposes.
```
root:
1 header = header:
1 unknown1 = 0xAF4002DC9CB83279 / -5818647572017302919 / -4.2198254e-81
2 unknown1 = 0x973615C0C0808FA3 / -7550823807632502877 / -7.3861769e-197
2 data = data:
1 type = 0x00000080 / 128 / 1.79366e-43
2 timestamp = 0x0000004A2E9097AA / 318608807850 / 1.5741367e-312
3 payload = payload:
1 = message:
1 = 0
2 = message:
1 = message:
2 = bytes (8)
0000 6C 73 6D 36 64 73 6D 00 lsm6dsm.
1 = message:
1 = 1
2 = message:
1 = message:
2 = bytes (8)
0000 53 54 4D 69 63 72 6F 00 STMicro.
1 = message:
1 = 4
2 = message:
1 = message:
4 <64bit> = 0x000000000002250A / 140554 / 6.9442903e-319
1 = message:
1 = 8
2 = message:
1 = message:
4 <64bit> = 0x0000000000000000 / 0 / 0.0000000
1 = message:
1 = 12
2 = message:
1 = message:
2 = bytes (4)
0000 4C 50 4D 00 LPM.
1 = message:
2 = bytes (7)
0000 4E 4F 52 4D 41 4C 00 NORMAL.
1 = message:
2 = "HIGH_PERF\x00"
1 = message:
1 = 15
2 = message:
1 = message:
4 <64bit> = 0x0000000000000008 / 8 / 3.9525252e-323
1 = message:
1 = 16
2 = message:
1 = message:
4 <64bit> = 0x0000000000000000 / 0 / 0.0000000
1 = message:
1 = 17
2 = message:
1 = message(5 = 0)
1 = message:
1 = 19
2 = message:
1 = message:
4 <64bit> = 0x0000000000000000 / 0 / 0.0000000
1 = message:
1 = 20
2 = message:
1 = message:
3 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
1 = message:
3 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
1 = message:
3 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
3 <32bit> = 0x00000000 / 0 / 0.00000
1 = message:
1 = 18
2 = message:
1 = message:
4 <64bit> = 0x0000000000000000 / 0 / 0.0000000
1 = message:
1 = 13
2 = message:
1 = message(5 = 0)
1 = message:
1 = 21
2 = message:
1 = message(5 = 1)
1 = message:
1 = 14
2 = message:
1 = message(5 = 0)
1 = message:
1 = 3
2 = message:
1 = message(5 = 1)
1 = message:
1 = 6
2 = message:
1 = message:
3 <32bit> = 0x3F800000 / 1065353216 / 1.00000
1 = message:
3 <32bit> = 0x40A00000 / 1084227584 / 5.00000
1 = message:
1 = 2
2 = message:
1 = message:
2 = "sensor_temperature\x00"
1 = message:
1 = 7
2 = message:
1 = message:
3 <32bit> = 0x3B7F9724 / 998217508 / 0.00390000
1 = message:
1 = 9
2 = message:
1 = message:
4 <64bit> = 0x0000000000000018 / 24 / 1.1857576e-322
1 = message:
4 <64bit> = 0x0000000000000046 / 70 / 3.4584595e-322
1 = message:
4 <64bit> = 0x00000000000000F0 / 240 / 1.1857576e-321
1 = message:
1 = 10
2 = message:
1 = message:
4 <64bit> = 0x0000000000000006 / 6 / 2.9643939e-323
1 = message:
1 = 5
2 = message:
1 = message:
2 = "sns_sensor_temperature.proto\x00"
1 = message:
1 = 22
2 = message:
1 = message:
4 <64bit> = 0x0000000000000003 / 3 / 1.4821969e-323
1 = message:
1 = 11
2 = message:
1 = message:
1 = message:
1 = message:
3 <32bit> = 0xC2200000 / -1038090240 / -40.0000
1 = message:
3 <32bit> = 0x42AA0000 / 1118437376 / 85.0000
1 = message:
1 = 23
2 = message:
1 = message:
3 <32bit> = 0x3B7F9724 / 998217508 / 0.00390000
1 = message:
1 = 24
2 = message:
1 = message:
1 = message:
1 = message:
3 <32bit> = 0xC2200000 / -1038090240 / -40.0000
1 = message:
3 <32bit> = 0x42AA0000 / 1118437376 / 85.0000
```
If we look at the other values, we can spot immediately some strings like `lsm6dsm` and `STMicro`.
Moreover, we also see some data specifying some kind of ranges, for example `-40.000` and `85.000`
which looks like the operating temperature range for a sensor. This sensor is a temperature sensor,
so it would make sense to know which temperature values can be considered valid and which not.
Since the name of the sensor is provided by a string, we can have a look at the datasheet.
Indeed, the [datasheet](https://www.st.com/resource/en/datasheet/lsm6dsm.pdf) confirms our hypothesis regarding the ranges, great!
Given that our hypothesis is confirmed, we can apply the same to other properties.
This message provides us a list of operating ranges and the current selected ranges of the sensor.
We also spot `LPM`, `NORMAL` and `HIGH_PERF` strings but they are not in the datasheet.
After checking similar messages, this comes back each time, for different sensor types which
may point to how the SSC operates the sensor. Given that the goal of the SSC is to offload and minimize
battery use, we can assume the following:
- `LPM` = Low Power Mode operation, probably in use when the device is sleeping
- `NORMAL` = Normal operation, probably when the device is in use
- `HIGH_PERF` = High accurate and performant operation, probably when the sensor data is really important like accelerometer data for navigation apps
Another interesting pattern is that each range message contains a `varint` with a number.
Given that these are various properties about a sensor, it is probably an enum where each number
matches a property like:
```
enum {
SENSOR_NAME = 0, # obvious: name of sensor as string
SENSOR_MANUFACTURER = 1, # obvious: name of manufacturer as string
SENSOR_DATATYPE = 2, # probably the sensor datatype as string
SENSOR_UNKNOWN1 = 3,
SENSOR_UNKNOWN2 = 4,
SENSOR_PROTOFILE = 5, # matches with SENSOR_DATATYPE, so probably right
SENSOR_UNKNOWN3 = 6,
SENSOR_UNKNOWN4 = 7,
SENSOR_UNKNOWN5 = 8,
SENSOR_UNKNOWN6 = 9,
SENSOR_UNKNOWN7 = 10,
SENSOR_OPERATING_RANGE = 11, # temperature sensor operates between -40 and 85 degrees Celsius according to datasheet
SENSOR_OPERATING_MODE = 12, # LPM/NORMAL/HIGH_PERF see higher
SENSOR_UNKNOWN8 = 13,
SENSOR_UNKNOWN9 = 14,
SENSOR_UNKNOWN10 = 15,
SENSOR_UNKNOWN11 = 16,
SENSOR_UNKNOWN12 = 17,
SENSOR_UNKNOWN13 = 18,
SENSOR_UNKNOWN14 = 19,
SENSOR_DEVICE_MOUNT_MATRIX = 20, # device orientation. Gyroscopes and accelerometers needs to specify how they are placed relative to the device orientation
SENSOR_UNKNOWN15 = 21,
SENSOR_UNKNOWN16 = 22,
SENSOR_UNKNOWN17 = 23, # same value as SENSOR_UNKNOWN4, maybe this is selected value? Since only one is available, we are not certain
SENSOR_SELECTED_RANGE = 24, # Available ranges are listed and one is current active
SENSOR_UNKNOWN18 = 25,
SENSOR_UNKNOWN19 = 26
}
```
Weird thing is this LSM6DSM is advertised as an always-on 3D accelerometer and 3D gyroscope, but provides temperature information?
Again, the datasheet is golden and specifies that the sensor has an embedded temperature sensor, probably for correcting the accelerometer and gyroscope data!
## Example: proximity sensor data
Since we still haven't found a data message, we ran strace a bit longer while turning off the screen.
Turning off the screen resulted in less noise in the strace dump, so it seems that the SSC suspends several sensors in that case.
However, not all of them are suspended. If you waive your hand over the phone you still get some messages.
The only sensor that can act on such events, is a proximity sensor, so it must be a data message!
**Protobuf dumps**
```
\x0a\x12\x09\x8c\x6c\xeb\x8f\x24\x49\x4e\xc3\x11\x85\x09\x5c\x1e\x01\xa4\xeb\x15\x12\x21\x0d\x03\x04\x00\x00\x11\x7e\xee\x0c\x60\x1f\x3d\x00\x00\x1a\x11\x0d\x00\x00\x80\x3f\x0d\x00\x00\xa8\x42\x0d\x00\x00\x00\x00\x10\x03
\x0a\x12\x09\x8c\x6c\xeb\x8f\x24\x49\x4e\xc3\x11\x85\x09\x5c\x1e\x01\xa4\xeb\x15\x12\x21\x0d\x03\x04\x00\x00\x11\x73\x08\xee\x61\x1f\x3d\x00\x00\x1a\x11\x0d\x00\x00\x00\x00\x0d\x00\x00\x0c\x42\x0d\x00\x00\x00\x00\x10\x03
\x0a\x12\x09\x8c\x6c\xeb\x8f\x24\x49\x4e\xc3\x11\x85\x09\x5c\x1e\x01\xa4\xeb\x15\x12\x21\x0d\x03\x04\x00\x00\x11\x09\x23\x62\x66\x1f\x3d\x00\x00\x1a\x11\x0d\x00\x00\x80\x3f\x0d\x00\x00\xac\x42\x0d\x00\x00\x00\x00\x10\x03
\x0a\x12\x09\x8c\x6c\xeb\x8f\x24\x49\x4e\xc3\x11\x85\x09\x5c\x1e\x01\xa4\xeb\x15\x12\x21\x0d\x03\x04\x00\x00\x11\x6c\x90\x52\x67\x1f\x3d\x00\x00\x1a\x11\x0d\x00\x00\x00\x00\x0d\x00\x00\x14\x42\x0d\x00\x00\x00\x00\x10\x03
```
This dump is extracted from our strace dump and contains 4 messages which can be decoded using protobuf-inspector:
```
root:
1 = message:
1 <64bit> = 0xC34E49248FEB6C8C / -4373477766747951988 / -1.7049341e+16
2 <64bit> = 0x15EBA4011E5C0985 / 1579536419034761605 / 4.4079947e-203
2 = message:
1 <32bit> = 0x00000403 / 1027 / 1.43913e-42
2 <64bit> = 0x00003D1F600CEE7E / 67204964740734 / 3.3203664e-310
3 = message:
1 <32bit> = 0x3F800000 / 1065353216 / 1.00000
1 <32bit> = 0x42A80000 / 1118306304 / 84.0000
1 <32bit> = 0x00000000 / 0 / 0.00000
2 = 3
root:
1 = message:
1 <64bit> = 0xC34E49248FEB6C8C / -4373477766747951988 / -1.7049341e+16
2 <64bit> = 0x15EBA4011E5C0985 / 1579536419034761605 / 4.4079947e-203
2 = message:
1 <32bit> = 0x00000403 / 1027 / 1.43913e-42
2 <64bit> = 0x00003D1F61EE0873 / 67204996270195 / 3.3203680e-310
3 = message:
1 <32bit> = 0x00000000 / 0 / 0.00000
1 <32bit> = 0x420C0000 / 1108082688 / 35.0000
1 <32bit> = 0x00000000 / 0 / 0.00000
2 = 3
root:
1 = message:
1 <64bit> = 0xC34E49248FEB6C8C / -4373477766747951988 / -1.7049341e+16
2 <64bit> = 0x15EBA4011E5C0985 / 1579536419034761605 / 4.4079947e-203
2 = message:
1 <32bit> = 0x00000403 / 1027 / 1.43913e-42
2 <64bit> = 0x00003D1F66622309 / 67205070988041 / 3.3203717e-310
3 = message:
1 <32bit> = 0x3F800000 / 1065353216 / 1.00000
1 <32bit> = 0x42AC0000 / 1118568448 / 86.0000
1 <32bit> = 0x00000000 / 0 / 0.00000
2 = 3
root:
1 = message:
1 <64bit> = 0xC34E49248FEB6C8C / -4373477766747951988 / -1.7049341e+16
2 <64bit> = 0x15EBA4011E5C0985 / 1579536419034761605 / 4.4079947e-203
2 = message:
1 <32bit> = 0x00000403 / 1027 / 1.43913e-42
2 <64bit> = 0x00003D1F6752906C / 67205086744684 / 3.3203725e-310
3 = message:
1 <32bit> = 0x00000000 / 0 / 0.00000
1 <32bit> = 0x42140000 / 1108606976 / 37.0000
1 <32bit> = 0x00000000 / 0 / 0.00000
2 = 3
```
Interesting! The header of the messages report different values than our gravity and temperature sensor from above.
Moreover, the type of the data message `1027` is also different, so this might be the enum value for reporting data values.
The other types from the previous examples are configuration messages.
Proximity is either near or not, so the first part of our data message reports either a `0` or `1` when the proximity sensor is covered or not by our hand.
```
{
SENSOR_PROXIMITY_FAR = 0,
SENSOR_PROXIMITY_NEAR = 1
}
```
The datasheet of the sensor indicates that is also an ambilight sensor.
The second value is probably the light intensity reported in [lux](https://en.wikipedia.org/wiki/Lux).
The third value is always `0`, so probably not in use.
The last value is always `3` and it seems to appear in more data messages as well,
this could be some kind of status regarding the provided data?
## Turning on display enables several sensors
Something we noticed is that turning on/off the device's display would trigger
some communication between the main CPU and the SSC.
After isolating these messages in the strace dump and running them through protobuf-inspector we could see the following:
```
root:
1 = message:
1 <64bit> = 0x8F4CA34817DEA0AE / -8120936498022408018 / -5.6292862e-235
2 <64bit> = 0x9C56C73BE530A0BD / -7181333495733509955 / -3.6838589e-172
2 = message:
1 <32bit> = 0x00000300 / 768 / 1.07620e-42
2 <64bit> = 0x00003D20B8E10173 / 67210750001523 / 3.3206523e-310
3 = message:
1 <32bit> = 0x41200000 / 1092616192 / 10.0000
3 = message:
0 = 0
0 = 0
0 = 1163262
4 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
5 = bytes (7)
0000 4E 4F 52 4D 41 4C 00 NORMAL.
6 = 245
8 = 1
root:
1 = message:
1 <64bit> = 0x8F4CA34817DEA0AE / -8120936498022408018 / -5.6292862e-235
2 <64bit> = 0x9C56C73BE530A0BD / -7181333495733509955 / -3.6838589e-172
2 = message:
1 <32bit> = 0x00000300 / 768 / 1.07620e-42
2 <64bit> = 0x00003D20B8E10961 / 67210750003553 / 3.3206523e-310
3 = message:
1 <32bit> = 0x41200000 / 1092616192 / 10.0000
3 = bytes (8)
0000 00 00 00 00 00 FF 7F 47 .......G
4 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
5 = bytes (7)
0000 4E 4F 52 4D 41 4C 00 NORMAL.
6 = 245
8 = 1
root:
1 = message:
1 <64bit> = 0x8F4CA34817DEA0AE / -8120936498022408018 / -5.6292862e-235
2 <64bit> = 0x9C56C73BE530A0BD / -7181333495733509955 / -3.6838589e-172
2 = message:
1 <32bit> = 0x00000300 / 768 / 1.07620e-42
2 <64bit> = 0x00003D20B8E59D18 / 67210750303512 / 3.3206523e-310
3 = message:
1 <32bit> = 0x41200000 / 1092616192 / 10.0000
3 = message:
0 = 0
0 = 0
0 = 1163262
4 <32bit> = 0x3DCCCCCD / 1036831949 / 0.100000
5 = bytes (7)
0000 4E 4F 52 4D 41 4C 00 NORMAL.
6 = 245
8 = 1
```
The header values are again different here from the previous examples.
We still don't know their meaning though.
The type here is `768` and the content of this message looks like setting the operating mode to `NORMAL`.
So we can be sure that the `768` value is an enum value for a control message:
```
{
MESSAGE_TYPE_PROPERTIES = 128,
MESSAGE_TYPE_CONFIG = 768,
MESSAGE_TYPE_DATA = 1027
}
```
A consequence of this is that our gravity example from the beginning was indeed a control message and not
a data message as we first assumed!
Some more messages appeared when turning on the display:
```
root:
1 = message:
1 <64bit> = 0x8F4CA34817DEA0AE / -8120936498022408018 / -5.6292862e-235
2 <64bit> = 0x9C56C73BE530A0BD / -7181333495733509955 / -3.6838589e-172
2 = message:
1 <32bit> = 0x00000401 / 1025 / 1.43633e-42
2 <64bit> = 0x00003D20B8F063CD / 67210751009741 / 3.3206523e-310
3 = message:
1 <32bit> = 0x00000000 / 0 / 0.00000
1 <32bit> = 0x3F800000 / 1065353216 / 1.00000
2 = 3
```
This looks like a data message as it has a similar structure as our data message above, but it has a slightly different type.
So maybe the `MESSAGE_TYPE_DATA` is a range [1025, 1027]?
However, it is not clear what the data represents since we don't know the origin sensor.
Yet another control message:
```
root:
1 = message:
1 <64bit> = 0x4043B5DABF1B397D / 4630744792980732285 / 39.420738
2 <64bit> = 0x61C572F2EDB31697 / 7045163579786598039 / 9.6497289e+162
2 = message:
1 <32bit> = 0x00000308 / 776 / 1.08741e-42
2 <64bit> = 0x00003D20B98C665B / 67210761234011 / 3.3206528e-310
3 = message(1 = 4)
```
This one configures a sensor to a certain mode `4`, but again not clear which sensor.
The `MESSAGE_TYPE_CONFIG` is probably also a range here: [768, 776].
Another message but with a unseen type:
```
root:
1 = message:
1 <64bit> = 0x4043B5DABF1B397D / 4630744792980732285 / 39.420738
2 <64bit> = 0x61C572F2EDB31697 / 7045163579786598039 / 9.6497289e+162
2 <32bit> = 0x00000202 / 514 / 7.20267e-43
3 = message(1 = 1, 2 = 0)
4 = message:
1 = message(1 = 0)
2 = 1
0 = 1
```
Since this message appears when turning on the display (which causes several sensors to go into NORMAL mode),
maybe this turns on a sensor which was turned off previously like a barometer (which is not useful in a lower power mode).
```
{
MESSAGE_TYPE_PROPERTIES = 128,
MESSAGE_TYPE_ENABLE = 514,
MESSAGE_TYPE_CONFIG = 768,
MESSAGE_TYPE_DATA = 1027
}
```
Remember that we had a data message a while back which we didn't know from which sensor it came?
Digging through some more dumps, make it appear several times when moving the device.
The data is always within a range of [0.0, 10.0] during movement. It is around 0.0 when standing still.
This data is probably from an accelerometer or gravity sensor as it reacts on movement!
Futhermore, the values of the header are always like this:
```
1 = message:
1 <64bit> = 0x8F4CA34817DEA0AE / -8120936498022408018 / -5.6292862e-235
2 <64bit> = 0x9C56C73BE530A0BD / -7181333495733509955 / -3.6838589e-172
```
Since the header matches each time for the same sensor, we can assume this is some kind of ID
of the sensor! Other sensors have different constant values to uniquely identify them.
If we look at some messages which are sent at the startup of the sensor daemon with strace, we can find these:
```
root:
1 = message:
1 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 <32bit> = 0x00000200 / 512 / 7.17465e-43
3 = message(1 = 1, 2 = 0)
4 = message:
2 = message:
1 = "proximity"
2 = 1
3 = 1
2 = 1
0 = 1
root:
1 = message:
1 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 <64bit> = 0xABABABABABABABAB / -6076574518398440533 / -2.5301707e-98
2 = message:
1 <32bit> = 0x00000300 / 768 / 1.07620e-42
2 <64bit> = 0x0000353C896529B6 / 58534119418294 / 2.8919698e-310
3 = message:
1 = "proximity"
2 = message:
1 <64bit> = 0x3732444D54736D61 / 3977316519841590625 / 8.1911186e-43
2 <64bit> = 0x5F5F584F52503532 / 6872308654097315122 / 2.5651075e+151
```
The sensor daemon requests the proximity sensor and gets a reply with some weird hexadecimal codes.
Believe it or not, they match the header of the next messages for that sensor, so that's how
the sensor ID is retrieved.
Protobuf only supports 32bit or 64bit values, to represent a 128bit values, you need to use 2 times 64bit values.
So the ID of the sensor here is probably a combination of 0x3732444D54736D61 + 0x5F5F584F52503532 = 5.F5F584F52\*10^31.
Since we don't know the protobuf file, we don't know the order of both 64bit values.
However, we don't need to know this as we would need to send them back in the same order anyway.
Message type 512 is to retrieve the sensor ID which is unknown at first and set to `0xABABABABABABABAB` until it is known.
```
{
MESSAGE_TYPE_PROPERTIES = 128,
MESSAGE_TYPE_SENSOR_ID = 512,
MESSAGE_TYPE_ENABLE = 514,
MESSAGE_TYPE_CONFIG = 768,
MESSAGE_TYPE_DATA = 1027
}
```
## More property messages
```
root:
1 = message:
1 <64bit> = 0xB641F37CF0373AD5 / -5313698367388828971 / -2.4565317e-47
2 <64bit> = 0xB1B5FB056EDEEDA6 / -5641326957458166362 / -3.1847811e-69
2 = message:
1 <32bit> = 0x00000080 / 128 / 1.79366e-43
2 <64bit> = 0x0000353C8AC5E1CB / 58534142534091 / 2.8919709e-310
3 = message:
1 = message:
1 = 0
2 = message:
1 = message:
2 = "TMD3725_RGB\x00"
1 = message:
1 = 1
2 = message:
1 = message:
2 = bytes (7)
0000 61 6D 73 20 41 47 00 ams AG.
1 = message:
1 = 2
2 = message:
1 = message:
2 = bytes (4)
0000 72 67 62 00 rgb.
1 = message:
1 = 4
2 = message:
1 = message:
4 <64bit> = 0x0000000000000100 / 256 / 1.2648081e-321
1 = message:
1 = 5
2 = message:
1 = message:
2 = "sns_rgb.proto\x00"
1 = message:
1 = 7
2 = message:
1