[libllcp] Port to Windows

269 views
Skip to first unread message

Jiapeng Li

unread,
Dec 17, 2013, 9:47:12 AM12/17/13
to nfc-too...@googlegroups.com

---2013-12-8

I am developing a cross platform NFC GUI tool based on (libnfc libfreefare libllcp libndef and QT), 
have developed it for days, now the tool already has some premium functions like(read/write Mifare card, send and receive ndef with Android phone).
The GUI tool is developed under Ubuntu,  i want to port it to Windows. All the tools listed above are cross platform tools, 
except for libllcp.

To now, i've compiled and tested the libnfc and libfreefare under windows, it all works as expected, thanks all guys who contribute to these libraries.

Then, i want to compile libllcp under windows, after write several CMakefileLists, i compiled it through MinGW. 
Then i found that libllcp use the POSIX libraries pthreads and mqueue, searched it, only found pthreads-win32. 

What is the better way to make libllcp a coross platform tool? Any idea is appreciated.


----2013-12-17

So far, i have made the libllcp compiled without error, after add the mqueue source code¹, but unfortunately it does not work,

the mqueue source code function has some bugs. ^_^

The source code with modification (CMakeLists and some platform contrib codes, reference to the libnfc and libfreefare) is attached, it is messy. I compile this repo use MinGW 4.8 under windows 7.


Jiapeng

[1]. http://cygwin.com/ml/pthreads-win32/2000/msg00131.html

libllcp.7z

Romuald Conty

unread,
Dec 17, 2013, 10:08:27 AM12/17/13
to nfc-too...@googlegroups.com
Hi,

About libllcp port under Windows, IMHO we should remove mqueue from libllcp implementation and use sockets instead : sockets are crossplatform and widely used.

I talk last week about mqueue in libllcp with Romain Tartière, which is the author of the first implementation and from his point of view, it should not be hard to turn mqueue usage into sockets as mqueue usage is basic and threads already done in libllcp.

Nice job you've done ! And thanks for sharing your work at earlier stage, it really help volunteers developers to quick have something that -almost- work under Windows :)

Thanks!

Jiapeng Li

unread,
Dec 24, 2013, 8:10:57 AM12/24/13
to nfc-too...@googlegroups.com
Romauld,
I read the code of libllcp more, and trying to replace mqueue with socket, i noticed that in libllcp there are 2 mqueues between llc_link and mac layer, for each connection it needs 2 mqueues. That is say we can replace each 2 mqueues with a pair of socket. For linux, socket supports AF_LOCAL, and also socketpair() function can be used. For windows, from what i searched, it does not support AF_LOCAL, not support socketpair() neither.

Does this mean that we need open a new port every time when there is a new connection? If so, how to choose the port number (the mqueue is created by the thread id)?
Is there some functions on Windows which can make things easy?

Maybe, i misunderstood something, ^_^

Thank you.  

Jiapeng Li

unread,
Dec 26, 2013, 5:28:34 AM12/26/13
to nfc-too...@googlegroups.com
Romuald and all, 
After searched again, i found that Windows can distribute port automatically, when set sin_port = 0. The structure is like below.  
    union {
       struct sockaddr_in inaddr;
       struct sockaddr addr;
    } a;
    a.inaddr.sin_family = AF_INET;
    a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
    a.inaddr.sin_port = 0;   // port is distributed by kernel

Now the socket version of libllcp is available, Windows and Linux are both tested with the snep-client example. 
I have created a new branch which is named socket. It is located at https://code.google.com/p/libllcp/source/browse/?name=socket 
More testings needed.



Reply all
Reply to author
Forward
0 new messages