Using low level Z-Way C API

Discussions about RaZberry - Z-Wave board for Raspberry computer
Post Reply
misha_shch
Posts: 7
Joined: 07 Oct 2015 11:15

Using low level Z-Way C API

Post by misha_shch »

Hi,

I'm trying to compile a test tool to check the usage of low level Z-Way C API. Code sample was downloaded from
http://razberry.zwave.me/index.php?id=15 particulaly this one
http://razberry.zwave.me/fileadmin/z-way-test.tgz

Compiling main.c from this sample succeeds but the program does nothing (nothing shown on screen and no process running). Debugin with GDB gives "Signal received: SIGILL (Illegal instruction)" error. If I check the process which causes the problem it is OPENSSL_cleanse().
Razberry itself is working fine, there are several devices configured in it.

I'm using NetBeans with remote compiling in Raspberry. I've already updated all system libraries and added them to linker.
Has anybody tried to compile this sample on Raspberry? Is there any special requirement for library version or whatever? Any hint is appreciated.

The output of compiling is below:
"/usr/bin/make" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory '/root/.netbeans/remote/10.136.151.15/home7-Windows-x86/G/NetBean-projects/ZwaveApplication_test2'
"/usr/bin/make" -f nbproject/Makefile-Debug.mk dist/Debug/GNU-Linux-x86/zwaveapplication_test2
make[2]: Entering directory '/root/.netbeans/remote/10.136.151.15/home7-Windows-x86/G/NetBean-projects/ZwaveApplication_test2'
mkdir -p build/Debug/GNU-Linux-x86
rm -f "build/Debug/GNU-Linux-x86/main.o.d"
gcc -c -g -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.c
mkdir -p dist/Debug/GNU-Linux-x86
gcc -o dist/Debug/GNU-Linux-x86/zwaveapplication_test2 build/Debug/GNU-Linux-x86/main.o -L/usr/lib/libzway/ -lzway -lzcommons -L/usr/lib/arm-linux-gnueabihf/ -lpthread -lxml2 -lz -lm -lcrypto -larchive
make[2]: Leaving directory '/root/.netbeans/remote/10.136.151.15/home7-Windows-x86/G/NetBean-projects/ZwaveApplication_test2'
make[1]: Leaving directory '/root/.netbeans/remote/10.136.151.15/home7-Windows-x86/G/NetBean-projects/ZwaveApplication_test2'

Best regards,
Mike
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Using low level Z-Way C API

Post by pofs »

Z-way itself never calls OPENSSL_cleance(), so it must be some internal call inside OpenSSL library. Can you please show the entire stack trace and openssl version?
misha_shch
Posts: 7
Joined: 07 Oct 2015 11:15

Re: Using low level Z-Way C API

Post by misha_shch »

Here is the output of Disassembly window after SIGILL error message (Discard and Pause option):

OPENSSL_cleanse()
OPENSSL_cleanse+0: mrc\t15, 0, r0, cr9, cr13, {0}
OPENSSL_cleanse+0: bx\tlr
OPENSSL_cleanse+0: ldrex\tr2, [r0]
OPENSSL_cleanse+0: add\tr3, r2, r1
OPENSSL_cleanse+0: strex\tr2, r3, [r0]
OPENSSL_cleanse+0: cmp\tr2, #0
OPENSSL_cleanse+0: bne\t0xb6c0f610
OPENSSL_cleanse+0: mov\tr0, r3
OPENSSL_cleanse+0: bx\tlr
OPENSSL_cleanse+0: eor\tr12, r12, r12
OPENSSL_cleanse+4: cmp\tr1, #7
OPENSSL_cleanse+8: subcs\tr1, r1, #4
OPENSSL_cleanse+12: bcs\t0xb6c0f654 <OPENSSL_cleanse+40>
OPENSSL_cleanse+16: cmp\tr1, #0
OPENSSL_cleanse+20: beq\t0xb6c0f67c <OPENSSL_cleanse+80>
OPENSSL_cleanse+24: strb\tr12, [r0], #1
OPENSSL_cleanse+28: subs\tr1, r1, #1
OPENSSL_cleanse+32: bhi\t0xb6c0f644 <OPENSSL_cleanse+24>
OPENSSL_cleanse+36: b\t0xb6c0f67c <OPENSSL_cleanse+80>
OPENSSL_cleanse+40: tst\tr0, #3
OPENSSL_cleanse+44: beq\t0xb6c0f668 <OPENSSL_cleanse+60>
OPENSSL_cleanse+48: strb\tr12, [r0], #1
OPENSSL_cleanse+52: sub\tr1, r1, #1
OPENSSL_cleanse+56: b\t0xb6c0f654 <OPENSSL_cleanse+40>
OPENSSL_cleanse+60: str\tr12, [r0], #4

Call stack is not very informative. At least for me :) Please see attached screenshot file.

$ aptitude show openssl
Package: openssl
State: installed
Automatically installed: no
Version: 1.0.1e-2+rvt+deb7u17
Priority: optional
Section: utils
Maintainer: Debian OpenSSL Team <pkg-openssl-devel@lists.alioth.debian.org>
Architecture: armhf
Uncompressed Size: 985 k
Depends: libc6 (>= 2.13-28), libssl1.0.0 (>= 1.0.1e-2+deb7u5), zlib1g (>=
1:1.1.4)
Suggests: ca-certificates
Description: Secure Socket Layer (SSL) binary and related cryptographic tools
This package contains the openssl binary and related tools.

It is part of the OpenSSL implementation of SSL.

You need it to perform certain cryptographic actions like:
* Creation of RSA, DH and DSA key parameters;
* Creation of X.509 certificates, CSRs and CRLs;
* Calculation of message digests;
* Encryption and decryption with ciphers;
* SSL/TLS client and server tests;
* Handling of S/MIME signed or encrypted mail.
Attachments
stack.jpg
stack.jpg (154.83 KiB) Viewed 10740 times
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Using low level Z-Way C API

Post by pofs »

I've googled a bit, and found https://bugs.launchpad.net/raspbian/+bug/1154042:
Afaict openssl probes the capabilities of the user's CPU by trying to do things and trapping the illegal instruction errors. So a couple of sigills during startup is normal. When using a debugger in order to find the real failure in your application you must continue past the startup sigills.
So just continue debugging and see if it works.
misha_shch
Posts: 7
Joined: 07 Oct 2015 11:15

Re: Using low level Z-Way C API

Post by misha_shch »

Thanks a lot. This is really the issue. BTW, there is a reference to some library version with the fix. Do you know which one is it and where can I download it?

Now I proceed with debuging. Unfortunately still need some help:
1. Controller initialisation fails with error "InvalidConfig = -21, // Error reading configuration and translation files"
Where are these "configuration and translation files"? I'm using "/dev/ttyAMA0" as this is a Razberry card but not a USB stick.
2. There is no output on screen although according to program the log is directed to stdout. Also stderr is empty. I assume to see "Failed to init ZWay" according to program logic.
pofs
Posts: 688
Joined: 25 Mar 2011 19:03

Re: Using low level Z-Way C API

Post by pofs »

Invalid config means there's no config or translations directory at the current path. The program uses relative paths to locate these directories, but debugger may start at wrong path. Fix the gdb startup directory or specify absolute paths to zway_init().
misha_shch
Posts: 7
Joined: 07 Oct 2015 11:15

Re: Using low level Z-Way C API

Post by misha_shch »

Great! Now it works. Thank you for the help.

BTW, maybe it would be usefull to document such specifics. Because it is not described even in library files (.h).
Post Reply