aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc
Commit message (Collapse)AuthorAgeFilesLines
* python tests: use python3Denis 'GNUtoo' Carikli2022-08-251-1/+1
| | | | | | | | | | | | | Using python instead of python3 has several issues: - Distributions and users can choose python2 as their default python interpreter. For users this can be done by making a symlink in /usr/local for instance. - Guix doesn't have python but has python3 in the PATH. Changing to python3 makes tests work for Guix system users that use the scripts/manifest.scm file with guix shell / guix environment. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* tests: open_android_modem_partition: cleanup after creating fileDenis 'GNUtoo' Carikli2022-08-251-1/+78
| | | | | | | Without that fix, the file being created isn't deleted at the end of the test, so over time the leftover files accumulate in /tmp. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* utils: network_iface_{up,down}: fix truncated character arrayDenis 'GNUtoo' Carikli2022-08-251-2/+2
| | | | | | | | | | | In the netdevice(7) manual we have a character array of a fixed size: struct ifreq { char ifr_name[IFNAMSIZ]; /* Interface name */ [...] }; so we don't need a terminating null byte ('\0'). Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* autotools: ship python test programsDenis 'GNUtoo' Carikli2022-07-261-0/+2
| | | | | | | | | | | | | | Without that fix, we don't ship any of the python test programs: $ make dist $ tar tf libsamsung-ipc-0.7.0.tar.xz | grep "\.py$" so 'make check' fail with the following error when building from a tarball: make[4]: Leaving directory '/tmp/libsamsung-ipc/libsamsung-ipc-0.7.0/samsung-ipc/tests' fatal: making test-suite.log: failed to create libsamsung-ipc-test.trs fatal: making test-suite.log: failed to create libsamsung-ipc-test.log Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* gprs: ipc_gprs_pdp_context_request_set_setup: fix truncated stringsDenis 'GNUtoo' Carikli2022-07-261-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without that fix, when compiling libsamsung-ipc with --enable-strict-cflags, we have the following error: gprs.c: In function 'ipc_gprs_pdp_context_request_set_setup': gprs.c:59:17: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] 59 | strncpy((char *) data->username, username, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 60 | sizeof(data->username)); | ~~~~~~~~~~~~~~~~~~~~~~~ gprs.c:61:17: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation] 61 | strncpy((char *) data->password, password, | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 62 | sizeof(data->password)); | ~~~~~~~~~~~~~~~~~~~~~~~ It comes from the fact that the size of the username and password fields are fixed (to 32) in include/gprs.h: struct ipc_gprs_pdp_context_request_set_data { unsigned char enable; unsigned char cid; unsigned char magic1[4]; unsigned char username[32]; unsigned char password[32]; unsigned char unknown[32]; unsigned char magic2; } __attribute__((__packed__)); The issue is that in ipc_gprs_pdp_context_request_set_setup we had the following code: int ipc_gprs_pdp_context_request_set_setup( struct ipc_gprs_pdp_context_request_set_data *data, unsigned char enable, unsigned char cid, const char *username, const char *password) { [...] strncpy((char *) data->username, username, sizeof(data->username)); strncpy((char *) data->password, password, sizeof(data->password)); [...] return 0; } And in the strcpy(3) manual we have: The strncpy() function is similar, except that at most n bytes of src are copied. Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated. So if we have a username and/or password of 32 or more characters, the copied data will not be null terminated hence the warning. Since username and passwords fields are character array and not strings, and that the field is padded with zeros anyway we can use memcpy instead. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* gprs: ipc_gprs_define_pdp_context_setup: fix truncated stringDenis 'GNUtoo' Carikli2022-07-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Without that fix, when compiling libsamsung-ipc with --enable-strict-cflags, we have the following error: gprs.c: In function 'ipc_gprs_define_pdp_context_setup': gprs.c:38:9: error: 'strncpy' specified bound 124 equals destination size [-Werror=stringop-truncation] 38 | strncpy((char *) data->apn, apn, sizeof(data->apn)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ It comes from the fact that the size of data->apn is fixed (to 124) in include/gprs.h: struct ipc_gprs_define_pdp_context_data { unsigned char enable; unsigned char cid; unsigned char magic; unsigned char apn[124]; } __attribute__((__packed__)); The issue is that in ipc_gprs_define_pdp_context_setup we had the following code: int ipc_gprs_define_pdp_context_setup( struct ipc_gprs_define_pdp_context_data *data, unsigned char enable, unsigned char cid, const char *apn) { [...] strncpy((char *) data->apn, apn, sizeof(data->apn)); [...] return 0; } And in the strcpy(3) manual we have: The strncpy() function is similar, except that at most n bytes of src are copied. Warning: If there is no null byte among the first n bytes of src, the string placed in dest will not be null-terminated. So if we have an apn of 124 or more characters, the copied data will not be null terminated hence the warning. Since apn is a character array and not a string, and that the field is padded with zeros anyway we can use memcpy instead. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* configure.ac: Add an option to use scripts/guix.scm's strict CFLAGSDenis 'GNUtoo' Carikli2022-07-222-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The CFLAGS that are in the %common-strict-cflags in scripts/guix.scm have been validated with both GCC and CLANG and they are useful to find potential issues in the code or code that won't compile on Android. However while the scripts/guix.scm script is really useful to test commits once they are ready, it is less convenient to use it when fixing issues in commits that are still being worked on. This is because it is not as fast as building libsamsung-ipc directly because: - it requires a clean source directory to work (this can be done with make distclean) so we can't reuse the current build output - libsamsung-ipc source code is copied and built 5 times (in different configurations) As for the implementation, AM_CFLAGS was used instead of appending to the default CFLAGS as CFLAGS is meant to be a variable for users. The effect is that both are independent, so if users don't want strict CFLAGS, they would need to not use --enable-strict-cflags. And it was implemented as a shell script to at the same time: - Enable to have comments, and good formating of the flags. - Enable to share the cflags between guix.scm and the autotools. - Keep the complexity low to keep it working in most situations. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* modems: xmm626: xmm626_kernel_smdk4412_fmt_recv: order headers alphabeticallyDenis 'GNUtoo' Carikli2022-06-261-3/+5
| | | | | | This helps avoiding including twice the same header by accident. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_kernel_smdk4412_gprs_get_iface: handle asprintf errorsDenis 'GNUtoo' Carikli2022-06-261-1/+7
| | | | | | | | | | | | | | | Without that fix we have the following warning: CC modems/xmm626/xmm626_kernel_smdk4412.lo ../../../samsung-ipc/modems/xmm626/xmm626_kernel_smdk4412.c: In function 'xmm626_kernel_smdk4412_gprs_get_iface': ../../../samsung-ipc/modems/xmm626/xmm626_kernel_smdk4412.c:589:9: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result] 589 | asprintf(&iface, "%s%d", XMM626_[...]_IFACE_PREFIX, cid - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC modems/xmm626/xmm626_mipi.lo Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* aries_gprs_get_iface: handle asprintf errorsDenis 'GNUtoo' Carikli2022-06-261-1/+6
| | | | | | | | | | | | | Without that fix we have the following warning: ../../../samsung-ipc/devices/aries/aries.c: In function 'aries_gprs_get_iface': ../../../samsung-ipc/devices/aries/aries.c:826:9: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result] 826 | asprintf(&iface, "%s%d", ARIES_GPRS_IFACE_PREFIX, cid - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* crespo_gprs_get_iface: handle asprintf errorsDenis 'GNUtoo' Carikli2022-06-261-1/+6
| | | | | | | | | | | | | Without that fix we have the following warning: ../../../samsung-ipc/devices/crespo/crespo.c: In function 'crespo_gprs_get_iface': ../../../samsung-ipc/devices/crespo/crespo.c:587:9: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result] 587 | asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, cid - 1); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* crespo_gprs_get_iface_single: handle asprintf errorsDenis 'GNUtoo' Carikli2022-06-261-4/+8
| | | | | | | | | | | | | Without that fix we have the following warning: ../../../samsung-ipc/devices/crespo/crespo.c: In function 'crespo_gprs_get_iface_single': ../../../samsung-ipc/devices/crespo/crespo.c:562:9: warning: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Wunused-result] 562 | asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, 0); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* partitions: android: test: remplace touch shell commandDenis 'GNUtoo' Carikli2022-06-261-4/+21
| | | | | | | | | | | | | | | Without that fix, we have the following warning: ../../../../samsung-ipc/tests/partitions/android.c: In function ‘create_dummy_modem_image’: [...] ../../../../samsung-ipc/tests/partitions/android.c:53:9: warning: ignoring return value of ‘system’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 53 | system("touch /tmp/libsamsung-ipc.[...]/modem.img"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CCLD libsamsung-ipc-test Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* partitions: android: test: remplace mkdir shell commandDenis 'GNUtoo' Carikli2022-06-261-2/+24
| | | | | | | | | | | | | | Without that fix, we have the following warning: CC partitions/android.o ../../../../samsung-ipc/tests/partitions/android.c: In function ‘create_dummy_modem_image’: ../../../../samsung-ipc/tests/partitions/android.c:52:9: warning: ignoring return value of ‘system’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 52 | system("mkdir -p /tmp/libsamsung-ipc.55f4731d2e11e85bd889/"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Autotools: Add --enable-samsung-ipc-device=[DEVICE] optionDenis 'GNUtoo' Carikli2022-06-261-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | In the Android.mk we have the following: ifneq ($(TARGET_DEVICE),) libsamsung_local_cflags += -DIPC_DEVICE_NAME=\"$(ipc_device_name)\" endif # ifneq ($(TARGET_DEVICE),) This makes libsamsung-ipc assume that it runs on a specific device. It can for instance be useful to test libsamsung-ipc on a device very similar to one that is already supported, or during development. The issue is that, with autotools and without this patch, this feature is not easy to use as to force the i9300 device we would have to run configure in this way: ./configure CFLAGS='-DIPC_DEVICE_NAME=\"i9300\"' And we had no feedback that could indicate if it worked or not. Note that even now, the only feedback we have is the output of ./configure because the autodetection of the device is done in ipc_device_detect. And ipc_device_detect is called by ipc_transport_client_create which setups the ipc_client struct. And without a valid ipc_client struct, we cannot use ipc_client_log, so we can't print in ipc_device_detect. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Autotools: add support for Valgrind for checksDenis 'GNUtoo' Carikli2022-05-232-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This enables contributors to run Valgrind when running 'make check' for instance before sending patches. The --enable-valgrind option was used instead of using --enable-checking=valgrind like GCC uses as the code for that is much easier to get right. As Valgrind is very slow, I had to increase the timeouts in the ipc-modem tests. For now I settled on 60 seconds to have some margin for machines or setups that are potentially slower than the one I use. For the guix.scm, with Guix 1.3.0, Valgrind needs the ld.so .symtab to work, so as Valgrind doesn't know where to find them, so we had to use --extra-debuginfo-path for that. This is also why we pass '-v' to valgrind as it prints message explaining the issue when it doesn't find the required symbols. And we also needed a trick mentioned in the Guix mailing list[1] to find the right path for the debug information as the glibc being used by packages isn't exported publicly. [1]https://lists.gnu.org/archive/html/help-guix/2022-03/msg00036.html The proper fix will be merged in the next Guix release (merging it now is not possible since it would require to rebuild everything, and that is only possible with new releases). A temporary workaround with 4d1a88312cbebb10d47905d6d023953ac85bcd04 (gnu: valgrind: Allow ld.so symbols to be found.) was also merged in the current Guix so it is possible to get it with guix pull, but here it's probably better to stick with a workaround in the guix.scm for now as this also enables to use older guix revisions for testing. Thanks to the people on #guix on Liberachat for helping me to solve this Valgrind issue. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Makefile.am: move -ggdb and -O0 CFLAGS to configure.acDenis 'GNUtoo' Carikli2022-05-232-2/+2
| | | | | | | This makes sure that all the program and libraries being built have the same obtimization level and debug CFLAGS. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Makefile.am: Unify leading whitespaces in definitionsDenis 'GNUtoo' Carikli2022-05-231-4/+4
| | | | | | | | | In the definitions of all the other part of this Makefile.am and in all other Makefile.am, the leading whitespaces are tabs. This makes sure that AM_CFLAGS also use leading tabs. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* partitions: android: silence compiler warningDenis 'GNUtoo' Carikli2022-03-281-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Without that fix, when building the 'libsamsung-ipc' package through scripts/guix.scm, we have the following warning: CC partitions/android/android.lo partitions/android/android.c: In function ‘open_android_modem_partition_by_name’: partitions/android/android.c:87:3: warning: ‘strncpy’ specified bound depends on the length of the source argument [-Wstringop-overflow=] 87 | strncpy(path, partitions_dirnames[i], | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 88 | strlen(partitions_dirnames[i])); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CC partitions/toc/toc.lo CCLD libsamsung-ipc.la The warning is hamless because: - The source (partitions_dirnames[i]) is hardcoded. - The desitination buffer size was allocated more space than the length of partitions_dirnames[i]. However it's good to silence non problematic warnings in order to better detect really serious issues. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: ipc_group_string: fix unknown group caseDenis 'GNUtoo' Carikli2022-03-281-1/+1
| | | | | | | | This was introduced by the commit 5a643dd89e2636cea19d9642c3a205d2d20250ec (ipc_utils: add ipc_group_string) Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* tests: libsamsung-ipc-test: fix test with out of tree buildsDenis 'GNUtoo' Carikli2022-01-241-5/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running the tests in an out of tree build directory (here in scripts/src/), without that fix, we have the following error in src/samsung-ipc/tests/test-suite.log when running 'make check': ============================================================ libsamsung-ipc 0.7.0: samsung-ipc/tests/test-suite.log ============================================================ # TOTAL: 1 # PASS: 0 # SKIP: 0 # XFAIL: 0 # FAIL: 1 # XPASS: 0 # ERROR: 0 .. contents:: :depth: 2 FAIL: libsamsung-ipc-test ========================= Traceback (most recent call last): File "[...]/scripts/src/samsung-ipc/tests/../../../../samsung-ipc/tests/libsamsung-ipc-test.py", line 54, in <module> main() File "[...]/scripts/src/samsung-ipc/tests/../../../../samsung-ipc/tests/libsamsung-ipc-test.py", line 50, in main tests = libsamsung_ipc_test() File "[...]/scripts/src/samsung-ipc/tests/../../../../samsung-ipc/tests/libsamsung-ipc-test.py", line 33, in __init__ self.run = sh.Command(srcdir + os.sep + "libsamsung-ipc-test") File "/usr/lib/python3.9/site-packages/sh.py", line 1342, in __init__ raise CommandNotFound(path) sh.CommandNotFound: ../../../../samsung-ipc/tests/libsamsung-ipc-test FAIL libsamsung-ipc-test.py (exit status: 1) Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* tests: python: unify string quotes as per PEP 8Denis 'GNUtoo' Carikli2022-01-241-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Having a code style makes the code easier to read. As for which code style to use, the code style defined by the PEP 8 [1] is used in the python standard library and in the main Python distribution. Its official nature (it's standardized by python) probably makes it the most well known and used code style adopted by python programmers. In it we have a section about string quotes: String Quotes ------------- In Python, single-quoted strings and double-quoted strings are the same. This PEP does not make a recommendation for this. Pick a rule and stick to it. When a string contains single or double quote characters, however, use the other one to avoid backslashes in the string. It improves readability. For triple-quoted strings, always use double quote characters to be consistent with the docstring convention in PEP 257. Since "if __name__ == '__main__':" is widely used, we choose to use the single quotes. [1]https://www.python.org/dev/peps/pep-0008/ Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Add ipc_client_type_stringDenis 'GNUtoo' Carikli2021-09-011-0/+20
| | | | | | | | | | | | | | | | | | | | | | | | | | | When working on applications using libsamsung-ipc, we sometimes have functions that have an ipc client type argument and that work for all 3 ipc client types, or want to refactorize the code to do that in order to make the code more clean and generic. However in these cases, these functions often needed to output some error message or tell users what is going on through logging prints, and the code ends up being way cleaner if there is a generic function to get the name of the ipc client type. In many cases it makes sense not to use the full IPC_CLIENT_TYPE_<type> name but only the <name> type in these messages, so because it's easier to add IPC_CLIENT_TYPE_ to the <type> than removing it, it makes sense to only return the string associated to the type (like "FMT", "RFS" or "DUMMY". The least significant number of the library version was also bumped as we are adding a new function, but the applications that were built against older libsamsung-ipc revisions should still work. However applications that depends on this ipc_client_type_string will not work with previous versions of libsamsung-ipc. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Move string functions in their own fileDenis 'GNUtoo' Carikli2021-09-013-366/+390
| | | | | | | | | | | There are already 4 string functions and combined together, they already take more than 300 lines, so it makes sense to move them in a separate file. In addition, it will also clarify in which files new string functions are supposed to be added in. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* partitions: android: Add open_android_modem_partition_by_nameDenis 'GNUtoo' Carikli2021-03-042-0/+65
| | | | Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Partitions: android: add tests for open_android_modem_partitionDenis 'GNUtoo' Carikli2021-03-045-0/+361
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Libraries typically have a public API and some internal implementation of that API. In libsamsung-ipc, the public API is defined in the include/ directory from the top directory. When compiling and installing libsamsung-ipc, that include/ directory is installed as well. Anything that is not defined in include/ is not part of that public API. However here we need to precisely test functions that are not part of that public API: The open_android_modem_partition function being tested here is only used by the herolte device, and that device doesn't have a battery that is easily replaceable, so most Replicant contributors will not want to get that device. As currently all the non static symbols of libsamsung-ipc are exported and that open_android_modem_partition isn't static, we can simply link to libsamsung-ipc for now and use its internal headers to access the functions to test. If at some point, libsamsung-ipc only exports the symbols defined in include/ we would need to find other ways to run such tests, for instance by using test frameworks that take care of that or by compiling libsamsung-ipc source code into the test programs. Some of the code of the libsamsung-ipc-test utility was adapted from code from the nv_data-md5 utility (which is currently in tools/). Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: move Android partition handling in its own directoryDenis 'GNUtoo' Carikli2021-03-034-25/+87
| | | | | | | This code could also be useful for other devices and in any cases it's not device specific. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: move TOC handling in its own directoryDenis 'GNUtoo' Carikli2021-02-285-32/+91
| | | | | | This could enable other devices to use the TOC handling functions. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc/Makefile.am: split it in subdirectoriesDenis 'GNUtoo' Carikli2021-02-283-36/+43
| | | | | | | | | The samsung-ipc/Makefile.am became pretty big. Because of that, it's It's better to split it to have one Makefile.am per subdirectory. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Initial support for herolte (Samsung Galaxy S7 GSM).Tony Garnock-Jones2021-02-225-0/+712
| | | | | | | | | | | | | | | | | | | | | | | | | | A previous version of this patch was tested on the herolte, however since then, several light functional changes were introduced. With the previous patch, it was possible to boot the modem and it was probably possible to send message to, and receive messages from the modem. For the TARGET_DEVICE we use in our Android.mk, In the Android.mk of android_device_samsung_herolte[1] we have: ifneq ($(filter herolte, $(TARGET_DEVICE)),) include $(call all-makefiles-under,$(LOCAL_PATH)) endif so we can safely assume that the TARGET_DEVICE is herolte. [1]https://github.com/LineageOS/android_device_samsung_herolte Signed-off-by: Tony Garnock-Jones <tonyg@leastfixedpoint.com> GNUtoo: rebased, code cleanup, more debug prints, commit message content but not its summary. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc/utils: add data_read and data_writeDenis 'GNUtoo' Carikli2021-02-161-0/+43
| | | | | | | | | | | | | | These wrappers are meant to handle the case where read or writes handles a smaller number of bytes than requested. This way that handling doesn't need to be duplicated everywhere in libsamsung-ipc. Having access to the ipc_client struct could enable future logging of read and writes without having to change any of the code already using data_read and data_write. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* ipc_utils: add ipc_group_stringDenis 'GNUtoo' Carikli2021-02-011-0/+50
| | | | | | | | | | | | | While ipc_group_string is not used by libsamsung-ipc (yet), it's still a good idea to add it as tools and applications using libsamsung-ipc can then use it to display the group of a command. It's also a better idea to have it in libsamsung-ipc than in each tool using it as libsamsung-ipc centralizes the knowledge about the samsung-ipc protocol, so if new groups appear at some point, the ipc_group_string function could be updated along the way. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* ipc_nv_data_md5_calculate: handle size mismatch betterreplicant-6.0-0004-rc4Denis 'GNUtoo' Carikli2020-12-032-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently libsamsung-ipc assumes that the size of nv_data.bin files are always 0x200000. While it's supposed to be the case for all the devices we support, it is still a good idea to make sure that a meaningful error message is reported to the users of nv_data-md5. For instance if we created an empty file of 1 kB with the following command: $ ddrescue -s 1k /dev/zero zero.img and that we used nv_data-md5 on it: $ ./tools/nv_data-md5 zero.img [ipc] file_data_read: Error: rc < 0 [ipc] ipc_nv_data_md5_calculate failed: data is NULL Calculating nv_data backup md5 failed we had a completely meaningless error message. With this patch the error message looks like that instead: $ ./tools/nv_data-md5 zero.img [ipc] ipc_nv_data_md5_calculate: Checking zero.img size failed: requested size: 2097152, file size: 1000 Calculating nv_data backup md5 failed Here users have at least a fighting chance of being able to understand what is going wrong. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: rfs: fix incorrect sign comparison for md5 file lengthJoonas Kylmälä2020-12-031-3/+5
| | | | | | | | | | | | | | | | | | When compiling with warnings (-Werror -W -Wall -Wunused -Wunused-function) enabled we get: rfs.c: In function ‘ipc_nv_data_md5_path_check’: rfs.c:115:17: error: comparison of integer expressions of different signedness: ‘__off_t’ {aka ‘long int’} and ‘long unsigned int’ [-Werror=sign-compare] if (st.st_size < 2 * sizeof(char) * MD5_DIGEST_LENGTH) { ^ This simplifies the comparison by making sure we have exactly 32 bytes (2*MD5_DIGEST_LENGTH, i.e. md5 digest in ascii) in the file we read the MD5 digest from. Signed-off-by: Joonas Kylmälä <joonas.kylmala@iki.fi> Tested-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org> Acked-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Cosmetic: sort #includes alphabetically in ipc_devices.hTony Garnock-Jones2020-11-261-4/+4
| | | | | | Signed-off-by: Tony Garnock-Jones <tonyg@leastfixedpoint.com> GNUtoo: rebased on top of libsamsung-ipc master Acked-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* libsamsung-ipc: improve board drivers print (issue #2150)Belgin Stirbu2020-11-234-50/+164
| | | | | | | | | | | | | | | | | | | | These are the functions and their corresponding error messages: xmm626_kernel_smdk4412_power -> "Powering on/off the modem failed" xmm626_kernel_smdk4412_hci_power -> "Powering on/off the HCI bus failed" xmm626_kernel_smdk4412_link_control_enable -> "Enabling/Disabling the modem link failed" xmm626_kernel_smdk4412_link_control_active -> "Activating/Deactivating the modem link failed" Signed-off-by: Belgin Stirbu <belginstirbu@hotmail.com> Acked-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc/utils: file_data_write: return more precise errorsDenis 'GNUtoo' Carikli2020-11-031-6/+8
| | | | | | | | | | | | | file_data_write uses open and lseek, and both can fail. In that case, it would be a good idea to be able for the caller of file_data_write to be able to retrieve the cause of the error. To do that here, we used the same way than write uses to pass on the information to the caller: On success, the number of bytes written is returned. On error, -1 is returned, and errno is set to indicate the cause of the error. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc/utils: Add file_data_sizeDenis 'GNUtoo' Carikli2020-11-031-0/+41
| | | | Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* Makefile.am: Fix xmm626_modem_if.h pathDenis 'GNUtoo' Carikli2020-09-211-1/+1
| | | | | | | | | | | According to this commit: 86d3646 modems: xmm626: includes: add xmm626 prefix 86d3646e6c2dfad59c97aa39e944d97f4b3feed5 the samsung-ipc/modems/xmm626/modem.h was renamed to samsung-ipc/modems/xmm626/xmm626_modem_if.h, however I forgot to update the Makefile.am. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: utils.c: file_data_{read,write}: report open errorDenis 'GNUtoo' Carikli2020-09-211-3/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | Mounting the EFS on your local computer can result in user id and permissions mismatch because the /etc/fstab doesn't always match the user ids used by Android. For instance here's the GT-N7000 EFS on my laptop: $ ls -l [...]/nv_data.bin -rwx------ 1 1001 1001 2097152 1 janv. 2000 [...]/nv_data.bin When using nv_data-md5 on it we have: $ ./tools/nv_data-md5 [...]/nv_data.bin [ipc] file_data_read: Error: fd: -1 [ipc] ipc_nv_data_md5_calculate failed: data is NULL Calculating nv_data backup md5 failed The error was too cryptic, and I ended up having to dig into the source code to understand what was going on. With this patch we now have an error message that is easier to understand: $ ./tools/nv_data-md5 [...]/nv_data.bin [ipc] file_data_read open failed with error 13: Permission denied [ipc] ipc_nv_data_md5_calculate failed: data is NULL Calculating nv_data backup md5 failed Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc/utils: reorder includesDenis 'GNUtoo' Carikli2020-09-211-7/+10
| | | | | | | | | | | | | | | | | | | This reorders includes alphabetically and groups them together: - C standard library includes of depth 1 are grouped together - "System" libraries of depth > 1 age grouped together - The (lib)samsung-ipc include(s) is/are grouped together We also need to keep the inclusion of sys/socket.h before linux/netlink.h in order to prevent the following compilation error on Replicant 4.2: bionic/libc/kernel/common/linux/netlink.h:52:2: error: unknown type name 'sa_family_t' While Replicant 4.2 is not really maintained anymore, it is still being used for testing libsamsung-ipc on devices that are not supported anymore by more recent Replicant versions, so we need to keep libsamsung-ipc and libsamsung-ril working on it. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* sec: fix SIM not found due to typo while switch to Linux code styleDenis 'GNUtoo' Carikli2020-09-151-1/+1
| | | | | | | | | | | | The bug being fixed in this commit was introduced in the following commit: b98a418 samsung-ipc: sec: switch to Linux code style b98a4188db6350794e8e7139065d71a25314e18c With that bug, on Replicant 6.0 0004 RC2, the SIM card is not found anymore, but some modem functionality still worked like getting the IMEI through the settings. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_hsic_ack_read: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-4/+5
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_mipi_ack_read: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-6/+7
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_hsic_modem_command_send: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-13/+17
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_mipi_modem_command_send: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-12/+15
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_mipi_modem_data_send: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-5/+7
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* xmm626_hsic_modem_data_send: pass the ipc_client structDenis 'GNUtoo' Carikli2020-07-241-4/+6
| | | | | | | | | This enables to use logging inside the callbacks. At this point the ipc_client struct is already available, so it is safe to do that. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: make #include relative to samsung-ipc/Denis 'GNUtoo' Carikli2020-07-2218-48/+45
| | | | | | | | | | | | | | This has several advantages: - It makes the header context more obvious: #include "xmm626.h" could mislead people into thinking that the xmm626.h header is in the same directory than the file using that directive, while it is instead in another location. This in turn could make people suppose that there is a "xmm626.h" header specific to the galaxys2 driver. Instead the #include "modems/xmm616/xmm616.h" directive is much more clear. - We can have two headers with the same filename. Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
* samsung-ipc: use #include "file" instead of #include <file> when relevantDenis 'GNUtoo' Carikli2020-07-2113-17/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The way <> and "" are included are implementation defined according to the C18 standard[1]: A preprocessing directive of the form # include < h-char-sequence > new-line searches a sequence of implementation-defined places for a header identified uniquely by the specified sequence between the < and > delimiters, and causes the replacement of that directive by the entire contents of the header. How the places are specified or the header identified is implementation-defined. A preprocessing directive of the form # include " q-char-sequence " new-line causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters. The named source file is searched for in an implementation-defined manner. If this search is not supported, or if the search fails, the directive is reprocessed as if it read And the GCC documentation has the following on #include directives[2]: Both user and system header files are included using the preprocessing directive ‘#include’. It has two variants: #include <file> This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the -I option (see Invocation). #include "file" This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. You can prepend directories to the list of quote directories with the -iquote option. References: ----------- [1]The standard doesn't seem to be available for free, but the draft can be downloaded from the following URL: https://web.archive.org/web/20181230041359if_/http://www.open-std.org/jtc1/sc22/wg14/www/abq/c17_updated_proposed_fdis.pdf [2]https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>