USB comms: part 4 towards @micolous PR #463#607
Conversation
pwpiwi
commented
May 15, 2018
- make uart_communication() static in comms.c
- move receiver thread creation and respective mutexes to comms.c
- add mutex and signal for tx buffer
- use comms.c for flasher as well
- remove comm functions from client/proxmark3.h
- this completes isolating all USB communication related functions in comms.c
* make uart_communication() static in comms.c * move receiver thread creation and respective mutexes to comms.c * add mutex and signal for tx buffer * use comms.c for flasher as well * remove comm functions from client/proxmark3.h * this completes isolating all USB communication related functions in comms.c
|
@micolous: you will find most changes familiar because your PR #463 was the starting point. However, I moved even more stuff into comms.c and solved the flasher timing regression differently. From my perspective this was just a refactoring. Please have a look if this fulfills the requirements for your Android port as well. |
|
OK, let me try to point the Android code at this branch and see how cleanly this goes. Thanks for pushing this forward! |
|
I wrote a patch which makes AndProx use this different API as an experiment. I also wrote some test cases with Mockito to build a virtual PM3 device which can be served from Java-land. I notice that bool OpenProxmarkAndroid(JNIEnv* env, JavaVM* vm, jobject nsw) {
serial_port* sp = uart_open_android(env, vm, nsw);
return OpenProxmark((char *)sp, /* waitCOMPort */ false, /* timeout */ 0, /* flash_mode */ false);
}
serial_port uart_open(const char* pcPortName) {
return (serial_port)pcPortName;
}This workaround leaves pointers to my I still need to pass multiple Java object references into However when Even if I did pass around references to USB device paths, this would run afoul of SELinux policies on most Android devices. I'd also be concerned about actually breaking something on rooted devices. I worked around this and got a working build with your branch by removing the If that This would be useful on non-Android platforms as well, because then tests can be written that simulate PM3 hardware interaction. |
|
The general idea was to have a comms.c for each Operating System (or use You made a good point regarding |
* make storeCommand() and getCommand() static in comms.c * don't assume a port to be defined by a name. Change parameter in OpenProxmark() to void*
|
I never intended for The intent of the changes in the first place was to pull all the communication related functionality away from Having the full startup process there is better than what I had. Also, serial_port uart_open_android(JNIEnv* env, JavaVM* vm, jobject nsw)
{
serial_port_android* sp = malloc(sizeof(serial_port_android));
sp->javaVM = vm;
sp->nativeSerialWrapper = (*env)->NewGlobalRef(env, nsw);
return sp;
}It already has a working connection at this point, and there's very little that needs to be done from the C side of things aside from getting an exclusive reference for it. There's no "setup" at all. ;) I'd really like an I wrote PR #611 which should address an issue with Initialise these explicitly to NULL. Make this assign a local variable instead. Move those into a new method, Wrap this in And then at the end of the function (out of the if-block), add: serial_port_name = NULL;
sp = NULL;That should be sufficient to decouple the serial port from being an actual file. I think we should still figure out why |
|
Partly included your proposals into last commit. From here I would add reconnections and try to eliminate |
|
Yup, ignore #611, I'll have a look over this when I've got a clearer head. Thanks! |
|
That latest version addresses the unlink issue for non-Linux POSIX platforms, and the intent of my other PR about the NULLs. However, it still assumes I see why you want to put this function here -- it is communication code that is common to PM3 usages. My intent here is not to burden PM3 with Android-specific code, but to give it some nicely shaped interfaces that it can fit in to. I should be able to ship an Android client with approximately 0 modifications to PM3's core code, and PM3 should be able to ship with no Android-specific code.
What I think would be best is if I write a patch based on this one that incorporates the change that I'm actually looking for. |
- StartProxmark split from OpenProxmark, to make it easier to start up the USB communication thread and set the serial port, without also have PM3 try to open the serial port for us. This is useful when PM3 doesn't have a path to a real device, such as with tests with a simulated device, and on Android). - OpenProxmark now doesn't mutate global state until it has finished. - CloseProxmark now puts PM3 in offline mode, and clears global state. - CloseProxmark now checks for a non-null serial_port before calling uart_close, to avoid unintentional double-free'ing serial_port. - main now calls CloseProxmark once.
|
micolous@4d59ec2 contains my extra suggested changes (branch: pwpiwi-607-fix).
The double PS: I also changed |
- StartProxmark split from OpenProxmark, to make it easier to start up the USB communication thread and set the serial port, without also have PM3 try to open the serial port for us. This is useful when PM3 doesn't have a path to a real device, such as with tests with a simulated device, and on Android). - OpenProxmark now doesn't mutate global state until it has finished. - CloseProxmark now puts PM3 in offline mode, and clears global state. - CloseProxmark now checks for a non-null serial_port before calling uart_close, to avoid unintentional double-free'ing serial_port. - main now calls CloseProxmark once.
- StartProxmark split from OpenProxmark, to make it easier to start up the USB communication thread and set the serial port, without also have PM3 try to open the serial port for us. This is useful when PM3 doesn't have a path to a real device, such as with tests with a simulated device, and on Android). - OpenProxmark now doesn't mutate global state until it has finished. - CloseProxmark now puts PM3 in offline mode, and clears global state. - CloseProxmark now checks for a non-null serial_port before calling uart_close, to avoid unintentional double-free'ing serial_port. - main now calls CloseProxmark once.