|
From: Peter K. <pk...@us...> - 2001-06-08 09:56:38
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btinit.c 1.9 1.10=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Synchronised with btd.c
The diff of the modified file(s):
--- btinit.c 2001/05/31 12:38:54 1.9
+++ btinit.c 2001/06/08 09:56:37 1.10
@@ -53,7 +53,7 @@
Sets which uart device that will be used by the stack
default: ttyS0
=20=20=20
- -n, --local-name
+ -n, --local-name <prefix>
prefix used for the local bluetooth device name
default: nothing
=20=20=20
@@ -61,6 +61,10 @@
reset bluetooth hardware before use
default: no reset
=20=20=20
+ -i, --initial-speed <speed>
+ sets initial uart speed
+ default: 115200 baud
+
-s, --speed <speed>
sets uart speed
9600, 19200, 38400, 57600, 115200, 230400, 460800
@@ -69,27 +73,21 @@
e.g
./bti --reset --speed 460800 --physdev /dev/ttyS0 --local-name OpenBT
=20
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - =
- */
=20
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <sys/wait.h>
-#include <sys/time.h>
-#include <fcntl.h>
-#include <time.h>
#include <stdio.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <termios.h>
#include <stdlib.h>
#include <string.h>
-#include <syslog.h>
+#include <unistd.h>
#include <errno.h>
-#include <stdarg.h>
+#include <fcntl.h>
#include <signal.h>
+#include <syslog.h>
#include <getopt.h>
#include <setjmp.h>
+#include <termios.h>
+#include <sys/ioctl.h>
+#include <sys/wait.h>
=20
#include "btd.h"
#include "bt_conf.h"
@@ -97,6 +95,8 @@
#include "bt_misc.h"
#include "bt_if.h"
=20
+#define D(x) //x
+
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
/* General BTD stuff */
=20
@@ -116,6 +116,7 @@
/* long option list */
static struct option long_options[] =3D
{
+ {"initial-speed", 1, NULL, 'i'}, /* initial uart speed */
{"physdev", 1, NULL, 'u'}, /* phys device used from stack */
{"local-name", 1, NULL, 'n'}, /* set local bluetooth name */
{"reset", 1, NULL, 'R'}, /* reset BT HW */
@@ -138,7 +139,7 @@
int opt;
int bt_disc =3D N_BT;
=20
- syslog(LOG_INFO, "Bluetooth daemon starting\n");
+ syslog(LOG_INFO, "Bluetooth daemon starting");
=20
if (atexit(btd_cleanup) < 0)
{
@@ -155,30 +156,30 @@
case 'i':
/* uart device */
init_hw_speed =3D atoi(optarg);
- syslog(LOG_INFO, "init_hw_speed %d baud\n", init_hw_speed);
+ D(syslog(LOG_INFO, "init_hw_speed %d baud", init_hw_speed));
break;
=20
case 'n':
- printf("setting local name to %s\n", optarg);
+ D(syslog(LOG_INFO, "setting local name to %s", optarg));
strncpy(local_name, optarg, LOCAL_NAME_LENGTH);
local_name[LOCAL_NAME_LENGTH] =3D '\0';
break;
=20
case 'R':
/* try to reset the hardware */
- printf("reset HW\n");
+ D(syslog(LOG_INFO, "reset HW"));
do_reset =3D 1;
break;
=20
case 's':
/* speed */
- printf("phys dev running at %s\n", optarg);
+ D(syslog(LOG_INFO, "phys dev running at %s", optarg));
speedstr =3D optarg;
break;
=20
case 'u':
/* uart device */
- printf("phys dev : %s\n", optarg);
+ D(syslog(LOG_INFO, "phys dev: %s", optarg));
physdev =3D optarg;
break;
=20
@@ -190,23 +191,19 @@
/* Set restart point */
if (sigsetjmp(jmpbuffer, 1) !=3D 0)
{
- syslog(LOG_INFO, "restart...\n\n\n\n");
+ syslog(LOG_INFO, "Restart...");
+ sleep(1);
}
=20
init();
=20
- /* Hardreset of BT hardware */
- if (do_reset)
- reset_hw();
-
if ((phys_fd =3D open(physdev, O_RDWR | O_NOCTTY)) < 0)
{
- perror("could not open phys dev\n");
+ perror("Could not open phys dev");
exit(1);
}
=20
- /* Set default speed */
-
+ /* Sets initial HW baudrate */
if (init_hw_speed !=3D 0)
fd_setup(phys_fd, init_hw_speed, USE_FLOW_CTRL, hw_vendor() =3D=3D HW_=
CSR_BCSP);
else
@@ -217,6 +214,12 @@
=20=20=20
bt_cfd =3D bt_openctrl();
=20
+ tcflush(phys_fd, TCIOFLUSH);
+
+ /* Hardreset of BT hardware */
+ if (do_reset)
+ reset_hw();
+
init_stack(bt_cfd, atoi(speedstr));
=20
if (do_hwinit)
@@ -225,8 +228,7 @@
/* All initialized and ready to accept connections in other BT apps */
=20
while (1)
- sleep(1);
-
+ sleep(100);
} /* main */
=20
/* =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D */
@@ -237,30 +239,26 @@
{
struct sigaction act;
=20
- syslog(LOG_INFO, "Initiating signal handler\n");
+ D(syslog(LOG_INFO, "Initiating signal handler"));
act.sa_handler =3D sighandler;
sigemptyset(&act.sa_mask);
act.sa_flags =3D 0;
- sigaction(SIGUSR1, &act, 0);
- sigaction(SIGTERM, &act, 0);
- /* other sigs ? */
+ sigaction(SIGUSR1, &act, 0); /* Restart application */
+ sigaction(SIGTERM, &act, 0); /* Terminate application */
}
=20
static void
sighandler(int sig)
{
- printf("Sighandler : %d\n", sig);
+ D(syslog(LOG_INFO, "Sighandler got signal: %d", sig));
=20
- /* Restart stack on SIGUSR1 */
if (sig =3D=3D SIGUSR1)
{
- syslog(LOG_INFO, "Restart stack\n");
-=20=20=20=20
+ /* Shutdown all and restart */
btd_cleanup();
-=20
siglongjmp(jmpbuffer, 1);
}
- if (sig =3D=3D SIGTERM)
+ else if (sig =3D=3D SIGTERM)
{
exit(0);
}
@@ -285,13 +283,12 @@
static void
btd_cleanup(void)
{
- printf("btd_cleanup : Shutting down stack and terminating childs\n");
- syslog(LOG_INFO, "btd_cleanup\n");
+ D(syslog(LOG_INFO, __FUNCTION__));
btd_killchilds();
=20
- syslog(LOG_INFO, "shutdown_stack\n");
+ printf("Shutting down Bluetooth stack\n");
shutdown_stack(bt_cfd);
- syslog(LOG_INFO, "shutdown_stack done\n");
+ printf("Bluetooth stack shut down\n");
=20
if (bt_cfd !=3D -1)
{
@@ -317,10 +314,9 @@
static void
btd_killchilds(void)
{
- syslog(LOG_INFO, "btd_killchilds\n");
if (sdpsrv_pid > 0)
{
- syslog(LOG_INFO, "Killing SDP server\n");
+ D(syslog(LOG_INFO, "Killing SDP server"));
kill(sdpsrv_pid, SIGTERM);
=20=20=20=20=20
if (waitpid(sdpsrv_pid, NULL, 0) < 0)
|