rfcomm patch to startup an executable at connection
Hi Marcel,
Here is the patch we talked about,
This was the original thread : http://sourceforge.net/mailarchive/message.php?msg_id=36194832
It 's an option to make rfcomm kind of persitent.
It can be used like this :
rfcomm --raw watch 0 20 cat {}
or rfcomm --raw listen 0 20 cat {}
Now, you can connect from another computer like this "rfcomm --raw connect 0 <addr> 20" and any incoming rfcomm data will be displayed. Typing "echo test >> /dev/rfcomm0" on client will display test on the other computer.
When the client disconnect :
- The "rfcomm listen" will exit
- The "rfcomm watch" will restart listening with the same parameters.
Regards,
Frederic.
? Doxyfile
? Makefile
? Makefile.in
? aclocal.m4
? autom4te.cache
? bluezutils.kdevelop
? bluezutils.kdevelop.pcs
? bluezutils.kdevses
? config.guess
? config.h
? config.h.in
? config.log
? config.status
? config.sub
? configure
? debug
? depcomp
? install-sh
? libtool
? ltmain.sh
? missing
? stamp-h.in
? stamp-h1
? alsa/.deps
? alsa/.libs
? alsa/Makefile
? alsa/Makefile.in
? alsa/libasound_module_pcm_a2dp.la
? alsa/libasound_module_pcm_headset.la
? alsa/pcm_a2dp.lo
? alsa/pcm_headset.lo
? alsa/sbc.lo
? audio/.deps
? audio/.libs
? audio/Makefile
? audio/Makefile.in
? audio/bt.audiod
? common/.deps
? common/.libs
? common/Makefile
? common/Makefile.in
? common/test_textfile
? cups/.deps
? cups/.libs
? cups/Makefile
? cups/Makefile.in
? cups/bluetooth
? daemon/.deps
? daemon/.libs
? daemon/Makefile
? daemon/Makefile.in
? daemon/bluetoothd
? daemon/bt.echod
? daemon/service-agent-glue.h
? dund/.deps
? dund/.libs
? dund/Makefile
? dund/Makefile.in
? dund/dund
? fuse/.deps
? fuse/Makefile
? fuse/Makefile.in
? hcid/.deps
? hcid/.libs
? hcid/Makefile
? hcid/Makefile.in
? hcid/auth-agent
? hcid/hcid
? hcid/lexer.c
? hcid/parser.c
? hcid/parser.h
? hcid/passkey-agent
? hcid/service-agent
? hidd/.deps
? hidd/.libs
? hidd/Makefile
? hidd/Makefile.in
? hidd/hidd
? input/.deps
? input/.libs
? input/Makefile
? input/Makefile.in
? input/bt.inputd
? network/.deps
? network/.libs
? network/Makefile
? network/Makefile.in
? network/bt.networkd
? pand/.deps
? pand/.libs
? pand/Makefile
? pand/Makefile.in
? pand/pand
? rfcomm/.deps
? rfcomm/.libs
? rfcomm/Makefile
? rfcomm/Makefile.in
? rfcomm/cvs
? rfcomm/lexer.c
? rfcomm/main.c.modified
? rfcomm/main.patch
? rfcomm/parser.c
? rfcomm/parser.h
? rfcomm/rfcomm
? scripts/Makefile
? scripts/Makefile.in
? sdpd/.deps
? sdpd/.libs
? sdpd/Makefile
? sdpd/Makefile.in
? sdpd/sdpd
? test/.deps
? test/.libs
? test/Makefile
? test/Makefile.in
? test/attest
? test/bdaddr
? test/hciemu
? test/hstest
? test/l2test
? test/rctest
? test/scotest
? test/sttest
? tools/.deps
? tools/.libs
? tools/Makefile
? tools/Makefile.in
? tools/ciptool
? tools/hciattach
? tools/hciconfig
? tools/hcisecfilter
? tools/hcitool
? tools/l2ping
? tools/ppporc
? tools/sdptool
Index: rfcomm/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/rfcomm/main.c,v
retrieving revision 1.23
main.c +71 -5
@@ -40,6 +40,7 @@#include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> +#include <sys/wait.h> #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h>
@@ -257,6 +258,53 @@return 0 ; } +static void run_cmdline (struct pollfd *p,sigset_t * sigs,char *devname,int argc,char ** argv) +{ +int i =0 ; +pid_t pid, child; +struct timespec ts; +int status =0 ; +char ** cmdargv =malloc ((argc+1 )*sizeof (char *)); + +if (!cmdargv) +return ; + +for (i=0 ; i<argc; i++) { + cmdargv[i] = (strcmp (argv[i],"{}" )==0 )?devname:argv[i]; + } + cmdargv[i] =NULL ; + + pid =fork (); + +switch (pid) { +case 0 : + i =execvp (cmdargv[0 ], cmdargv); +fprintf (stderr,"Couldn't execute command %s (errno=%d:%s)\n" , cmdargv[0 ], errno,strerror (errno)); +break ; +case -1 : +fprintf (stderr,"Couldn't fork to execute command %s\n" , cmdargv[0 ]); +break ; +default : +while (1 ) { + child =waitpid (-1 , &status,WNOHANG ); +if (child == pid || (child <0 && errno !=EAGAIN )) +break ; + + p->revents =0 ; + ts.tv_sec =0 ; + ts.tv_nsec =200 ; +if (ppoll (p,1 , &ts, sigs) || __io_canceled) { +kill (pid,SIGTERM ); +waitpid (pid, &status,0 ); +break ; + } + } +break ; + } + +free (cmdargv); +} +static void cmd_connect (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) {struct sockaddr_rc laddr, raddr;
@@ -520,17 +568,34 @@ p.fd = fd; p.events =POLLERR |POLLHUP ; -while (!__io_canceled) { - p.revents =0 ; -if (ppoll (&p,1 ,NULL , &sigs) >0 ) -break ; +if (argc <=2 ) { +while (!__io_canceled) { + p.revents =0 ; +if (ppoll (&p,1 ,NULL , &sigs) >0 ) +break ; + } + }else { +run_cmdline (&p, &sigs, devname, argc-2 , argv+2 ); } +// Reset signal handlers + sa.sa_handler =NULL ; +sigaction (SIGTERM , &sa,NULL ); +sigaction (SIGINT , &sa,NULL ); +printf ("Disconnected\n" );close (fd); } +static void cmd_watch (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) +{ +while (!__io_canceled) { +cmd_listen (ctl, dev, bdaddr, argc, argv); +usleep (10 *1000 ); + } +} +static void cmd_create (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) {if (strcmp (argv[0 ],"all" ) ==0 )
@@ -573,7 +638,8 @@ { "release", "unbind", cmd_release, "<dev>", "Release device" }, { "show", "info", cmd_show, "<dev>", "Show device" }, { "connect", "conn", cmd_connect, "<dev> <bdaddr> [channel]", "Connect device" }, - { "listen", "server", cmd_listen, "<dev> [channel]", "Listen" }, + { "listen", "server", cmd_listen, "<dev> [channel [cmd]]", "Listen" }, + { "watch", "watch", cmd_watch, "<dev> [channel [cmd]]", "Watch" }, { NULL, NULL, NULL, 0, 0 } };
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Marcel Holtmann
maintainerHi Frederic,
Quoted 5 lines
Here is the patch we talked about,
This was the original thread :
http://sourceforge.net/mailarchive/message.php?msg_id=36194832It 's an option to make rfcomm kind of persitent.
can you please fix up your usage (or lack of) whitespaces. I like to keep all code in sync with the coding style.
Regards
Marcel
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Done
Quoted 18 lines · Marcel Holtmann
Hi Frederic,
Quoted 5 lines
Here is the patch we talked about,
This was the original thread : http://sourceforge.net/mailarchive/message.php?msg_id=36194832It 's an option to make rfcomm kind of persitent.
can you please fix up your usage (or lack of) whitespaces. I like to keep all code in sync with the coding style.
Regards
Marcel
Quoted 10 lines
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
? Doxyfile
? Makefile
? Makefile.in
? aclocal.m4
? autom4te.cache
? bluezutils.kdevelop
? bluezutils.kdevelop.pcs
? bluezutils.kdevses
? config.guess
? config.h
? config.h.in
? config.log
? config.status
? config.sub
? configure
? debug
? depcomp
? install-sh
? libtool
? ltmain.sh
? missing
? stamp-h.in
? stamp-h1
? alsa/.deps
? alsa/.libs
? alsa/Makefile
? alsa/Makefile.in
? alsa/libasound_module_pcm_a2dp.la
? alsa/libasound_module_pcm_headset.la
? alsa/pcm_a2dp.lo
? alsa/pcm_headset.lo
? alsa/sbc.lo
? audio/.deps
? audio/.libs
? audio/Makefile
? audio/Makefile.in
? audio/bt.audiod
? common/.deps
? common/.libs
? common/Makefile
? common/Makefile.in
? common/test_textfile
? cups/.deps
? cups/.libs
? cups/Makefile
? cups/Makefile.in
? cups/bluetooth
? daemon/.deps
? daemon/.libs
? daemon/Makefile
? daemon/Makefile.in
? daemon/bluetoothd
? daemon/bt.echod
? daemon/service-agent-glue.h
? dund/.deps
? dund/.libs
? dund/Makefile
? dund/Makefile.in
? dund/dund
? fuse/.deps
? fuse/Makefile
? fuse/Makefile.in
? hcid/.deps
? hcid/.libs
? hcid/Makefile
? hcid/Makefile.in
? hcid/auth-agent
? hcid/hcid
? hcid/lexer.c
? hcid/parser.c
? hcid/parser.h
? hcid/passkey-agent
? hcid/service-agent
? hidd/.deps
? hidd/.libs
? hidd/Makefile
? hidd/Makefile.in
? hidd/hidd
? input/.deps
? input/.libs
? input/Makefile
? input/Makefile.in
? input/bt.inputd
? network/.deps
? network/.libs
? network/Makefile
? network/Makefile.in
? network/bt.networkd
? pand/.deps
? pand/.libs
? pand/Makefile
? pand/Makefile.in
? pand/pand
? rfcomm/.deps
? rfcomm/.libs
? rfcomm/Makefile
? rfcomm/Makefile.in
? rfcomm/cvs
? rfcomm/lexer.c
? rfcomm/main.c.modified
? rfcomm/main.patch
? rfcomm/mainx.c
? rfcomm/parser.c
? rfcomm/parser.h
? rfcomm/rfcomm
? scripts/Makefile
? scripts/Makefile.in
? sdpd/.deps
? sdpd/.libs
? sdpd/Makefile
? sdpd/Makefile.in
? sdpd/sdpd
? test/.deps
? test/.libs
? test/Makefile
? test/Makefile.in
? test/attest
? test/bdaddr
? test/hciemu
? test/hstest
? test/l2test
? test/rctest
? test/scotest
? test/sttest
? tools/.deps
? tools/.libs
? tools/Makefile
? tools/Makefile.in
? tools/ciptool
? tools/hciattach
? tools/hciconfig
? tools/hcisecfilter
? tools/hcitool
? tools/l2ping
? tools/ppporc
? tools/sdptool
Index: rfcomm/main.c
===================================================================
RCS file: /cvsroot/bluez/utils/rfcomm/main.c,v
retrieving revision 1.23
main.c +70 -5
@@ -40,6 +40,7 @@#include <sys/param.h> #include <sys/ioctl.h> #include <sys/socket.h> +#include <sys/wait.h> #include <bluetooth/bluetooth.h> #include <bluetooth/hci.h>
@@ -257,6 +258,53 @@return 0 ; } +static void run_cmdline (struct pollfd *p,sigset_t * sigs,char *devname,int argc,char **argv) +{ +int i =0 ; +pid_t pid, child; +struct timespec ts; +int status =0 ; +char **cmdargv =malloc ((argc +1 ) *sizeof (char *)); + +if (!cmdargv) +return ; + +for (i =0 ; i < argc; i++) { + cmdargv[i] = (strcmp (argv[i],"{}" ) ==0 ) ? devname : argv[i]; + } + cmdargv[i] =NULL ; + + pid =fork (); + +switch (pid) { +case 0 : + i =execvp (cmdargv[0 ], cmdargv); +fprintf (stderr,"Couldn't execute command %s (errno=%d:%s)\n" , cmdargv[0 ], errno,strerror (errno)); +break ; +case -1 : +fprintf (stderr,"Couldn't fork to execute command %s\n" , cmdargv[0 ]); +break ; +default : +while (1 ) { + child =waitpid (-1 , &status,WNOHANG ); +if (child == pid || (child <0 && errno !=EAGAIN )) +break ; + + p->revents =0 ; + ts.tv_sec =0 ; + ts.tv_nsec =200 ; +if (ppoll (p,1 , &ts, sigs) || __io_canceled) { +kill (pid,SIGTERM ); +waitpid (pid, &status,0 ); +break ; + } + } +break ; + } + +free (cmdargv); +} +static void cmd_connect (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) {struct sockaddr_rc laddr, raddr;
@@ -520,17 +568,33 @@ p.fd = fd; p.events =POLLERR |POLLHUP ; -while (!__io_canceled) { - p.revents =0 ; -if (ppoll (&p,1 ,NULL , &sigs) >0 ) -break ; +if (argc <=2 ) { +while (!__io_canceled) { + p.revents =0 ; +if (ppoll (&p,1 ,NULL , &sigs) >0 ) +break ; + } + }else { +run_cmdline (&p, &sigs, devname, argc -2 , argv +2 ); } + sa.sa_handler =NULL ; +sigaction (SIGTERM , &sa,NULL ); +sigaction (SIGINT , &sa,NULL ); +printf ("Disconnected\n" );close (fd); } +static void cmd_watch (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) +{ +while (!__io_canceled) { +cmd_listen (ctl, dev, bdaddr, argc, argv); +usleep (10000 ); + } +} +static void cmd_create (int ctl,int dev,bdaddr_t *bdaddr,int argc,char **argv) {if (strcmp (argv[0 ],"all" ) ==0 )
@@ -573,7 +637,8 @@ { "release", "unbind", cmd_release, "<dev>", "Release device" }, { "show", "info", cmd_show, "<dev>", "Show device" }, { "connect", "conn", cmd_connect, "<dev> <bdaddr> [channel]", "Connect device" }, - { "listen", "server", cmd_listen, "<dev> [channel]", "Listen" }, + { "listen", "server", cmd_listen, "<dev> [channel [cmd]]", "Listen" }, + { "watch", "watch", cmd_watch, "<dev> [channel [cmd]]", "Watch" }, { NULL, NULL, NULL, 0, 0 } };
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi Frederic,
The patch is now in the CVS. Could you provide a patch to the manual page (rfcomm.1) too?
Johan
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
Hi,
Attached is a proposal for the manpage.
It looks like this:
listen <dev> [channel] [cmd]
Listen on a specified RFCOMM channel for incoming connections. If no channel is specified, it will use the channel number 1, but a channel must be specified before cmd. If cmd is given, it will be executed as soon as a client connects. When the child process terminates or the client disconnect, the command will terminate. Occurences of {} in cmd will be replaced by the name of the device used by the connection. This command can be termi‐ nated with the key sequence CTRL-C.
watch <dev> [channel] [cmd]
Watch is identical to listen except that when the child process terminates or the client disconnect, the command will restart listening with the same parameters.
Frederic
Quoted 7 lines · Johan Hedberg
Hi Frederic,
The patch is now in the CVS. Could you provide a patch to the manual page (rfcomm.1) too?
Johan
Quoted 10 lines
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel
? Doxyfile
? Makefile
? Makefile.in
? aclocal.m4
? autom4te.cache
? bluezutils.kdevelop
? bluezutils.kdevelop.pcs
? bluezutils.kdevses
? config.guess
? config.h
? config.h.in
? config.log
? config.status
? config.sub
? configure
? debug
? depcomp
? install-sh
? libtool
? ltmain.sh
? missing
? stamp-h.in
? stamp-h1
? alsa/.deps
? alsa/.libs
? alsa/Makefile
? alsa/Makefile.in
? alsa/libasound_module_pcm_a2dp.la
? alsa/libasound_module_pcm_headset.la
? alsa/pcm_a2dp.lo
? alsa/pcm_headset.lo
? alsa/sbc.lo
? audio/.deps
? audio/.libs
? audio/Makefile
? audio/Makefile.in
? audio/bt.audiod
? common/.deps
? common/.libs
? common/Makefile
? common/Makefile.in
? common/test_textfile
? cups/.deps
? cups/.libs
? cups/Makefile
? cups/Makefile.in
? cups/bluetooth
? daemon/.deps
? daemon/.libs
? daemon/Makefile
? daemon/Makefile.in
? daemon/bluetoothd
? daemon/bt.echod
? daemon/service-agent-glue.h
? dund/.deps
? dund/.libs
? dund/Makefile
? dund/Makefile.in
? dund/dund
? fuse/.deps
? fuse/Makefile
? fuse/Makefile.in
? hcid/.deps
? hcid/.libs
? hcid/Makefile
? hcid/Makefile.in
? hcid/auth-agent
? hcid/hcid
? hcid/lexer.c
? hcid/parser.c
? hcid/parser.h
? hcid/passkey-agent
? hcid/service-agent
? hidd/.deps
? hidd/.libs
? hidd/Makefile
? hidd/Makefile.in
? hidd/hidd
? input/.deps
? input/.libs
? input/Makefile
? input/Makefile.in
? input/bt.inputd
? network/.deps
? network/.libs
? network/Makefile
? network/Makefile.in
? network/bt.networkd
? pand/.deps
? pand/.libs
? pand/Makefile
? pand/Makefile.in
? pand/pand
? rfcomm/.deps
? rfcomm/.libs
? rfcomm/Makefile
? rfcomm/Makefile.in
? rfcomm/cvs
? rfcomm/lexer.c
? rfcomm/main.c.modified
? rfcomm/main.patch
? rfcomm/mainx.c
? rfcomm/parser.c
? rfcomm/parser.h
? rfcomm/rfcomm
? scripts/Makefile
? scripts/Makefile.in
? sdpd/.deps
? sdpd/.libs
? sdpd/Makefile
? sdpd/Makefile.in
? sdpd/sdpd
? sync/.deps
? sync/Makefile
? sync/Makefile.in
? test/.deps
? test/.libs
? test/Makefile
? test/Makefile.in
? test/attest
? test/bdaddr
? test/hciemu
? test/hstest
? test/l2test
? test/rctest
? test/scotest
? test/sttest
? tools/.deps
? tools/.libs
? tools/Makefile
? tools/Makefile.in
? tools/ciptool
? tools/hciattach
? tools/hciconfig
? tools/hcisecfilter
? tools/hcitool
? tools/l2ping
? tools/ppporc
? tools/sdptool
Index: rfcomm/rfcomm.1
===================================================================
RCS file: /cvsroot/bluez/utils/rfcomm/rfcomm.1,v
retrieving revision 1.5
rfcomm.1 +15 -3
@@ -70,10 +70,22 @@ tries to read the data from the config file. This command can be terminated with the key sequence CTRL-C. .TP -.BI listen " <dev> [channel]" +.BI listen " <dev> [channel] [cmd]" Listen on a specified RFCOMM channel for incoming connections. -If no channel is specified, it will use the channel number 1. -This command can be terminated with the key sequence CTRL-C. +If no channel is specified, it will use the channel number 1, but +a channel must be specified before cmd. If cmd is given, it will be +executed as soon as a client connects. When the child process +terminates or the client disconnect, the command will terminate. +Occurences of {} in cmd will be replaced by the name of the device +used by the connection. This command can be terminated with the key +sequence CTRL-C. +.TP +.BI watch " <dev> [channel] [cmd]" +Watch is identical to +.B listen +except that when the child process terminates or the client +disconnect, the command will restart listening with the same +parameters. .TP .BI bind " <dev> [bdaddr] [channel]" This binds the RFCOMM device to a remote Bluetooth device. The
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel