1

I have an an embedded Linux ARM board, where an application opens the /dev/spidev1.0 device and constantly talks through with another MCU. Now, if I I try to look at what exchanges (that's what I'd need), doing a hexdump /dev/spidev1.0 shows something in the beginning but causes the application to crash. The app is very sensitive and I think it crashes because the app uses and it can't be used for viewing simultaneously.

Would there be a way to create an alias, or something like a mirror of this device if I write some extra code/driver? Or is there no chance for me to sniff the traffic like that (in software) ?

Rewrote:

int ioctl(int fd, unsigned long request, struct spi_ioc_transfer *xfer)

But, gcc output the following error:

myioctl.c:6:5: error: conflicting types for ‘ioctl’ In file included from myioctl.c:1:0: /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include/s‌​ys/ioctl.h:41:12: note: previous declaration of ‘ioctl’ was here

Any help how the original definition:

/* Perform the I/O control operation specified by REQUEST on FD.
   One argument may follow; its presence and type depend on REQUEST.
   Return value depends on REQUEST.  Usually -1 indicates error.  */

extern int ioctl (int __fd, unsigned long int __request, ...) __THROW;

could be overridden.

1 Answer 1

2

If this Linux distribution does support LD_PRELOAD you can easily use this feature to override opening/closing/reading/writing/ioctl-ing functions to this specific device. See here for very basic tutorial: http://www.catonmat.net/blog/simple-ld-preload-tutorial/

This will not require writing driver and pretty usable approach. IN addition you can try to use strace utility to trace all IO system calls which will obviously include the accesses to your device.

4
  • Thanks! I have been using strace, however: The app is relying heavily on IPC communications and it is sensitive to debugging by attaching to the process. So by attaching directly with strace -p, it crashes in a while. While if I stop it and start it with strace, it relies on an IPC channel hookup which doesn't work properly if it is just started by hand. Many thanks for the LD_PRELOAD. Is it also possible to display variables? What I would really need is to printf some vars. I read this too beforehand. codeproject.com/Articles/33340/…
    – amgnet
    Jul 17, 2016 at 9:02
  • Using LD_PRELOAD requires you to write .so library which intercepts specific calls to library functions (read/write/open and probably ioctl in your case). You definitely can call printf like functions inside your implementation.
    – w s
    Jul 17, 2016 at 9:47
  • Just a little bit more help on overriding the ioctl call in a .so. The definition in the ioctl.h is extern int ioctl (int __fd, unsigned long int __request, ...) __THROW; So there is that optional parameter, which is the one called to actually receive or send data. Rewrote: int ioctl(int fd, unsigned long request, struct spi_ioc_transfer *xfer), gcc says: myioctl.c:6:5: error: conflicting types for ‘ioctl’ In file included from myioctl.c:1:0: /usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/include/sys/ioctl.h:41:12: note: previous declaration of ‘ioctl’ was here
    – amgnet
    Jul 19, 2016 at 11:54
  • I'm not pretty sure that I understand the question, but I found the example that will probably suit your needs: github.com/poliva/ldpreloadhook
    – w s
    Jul 19, 2016 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.