|
From: Peter K. <pk...@us...> - 2001-04-27 18:33:23
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btconfig.c 1.1 1.2=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Always read the configuration file (can be disabled with -f /dev/null).
Command line options override the configuration file.
The diff of the modified file(s):
--- btconfig.c 2001/04/27 14:41:23 1.1
+++ btconfig.c 2001/04/27 18:33:23 1.2
@@ -1,7 +1,7 @@
/*
* btconfig.c -- Configures BT driver from options or config file
*
- * Copyright (C) 2000, 2001 Axis Communications AB
+ * Copyright (C) 2001 Axis Communications AB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -37,6 +37,8 @@
*
*/
=20
+/****************** INCLUDE FILES SECTION ********************************=
***/
+
#include <stdio.h>
#include <syslog.h>
#include <string.h>
@@ -60,13 +62,10 @@
#include "bt_conf.h"
#include "bt_misc.h"
=20=20=20=20=20
-/*=20
- * Syntax : btconfig [--force_msswitch <0/1> --wrscan_enable <mode>=20
- * --name <name> --file <filename>]
- */
-
/****************** CONSTANT AND MACRO SECTION ***************************=
***/
=20
+#define D(x) //x
+
#ifndef FALSE
#define FALSE (0)
#endif
@@ -79,122 +78,148 @@
#define DOMAIN_NAME_LENGTH 100
#define BUF_MAXSIZE 300
=20
-#define PRE " ("
-#define POST ")"
+#define CONF_FILE "/etc/bt.conf"
=20
-#define D(x) //x
+/****************** TYPE DEFINITION SECTION ******************************=
***/
=20
/****************** LOCAL FUNCTION DECLARATION SECTION *******************=
***/
=20
+static void show_usage(void);
+
/* File parsing functions */
static int parse_file(char *filename);
static int parse_line(char* line, char** field, char** value);
static int configure_field(const char* field, const char* value);
=20
-/*************************************************************************=
**/
+/****************** GLOBAL VARIABLE DECLARATION SECTION ******************=
***/
=20
+/****************** LOCAL VARIABLE DECLARATION SECTION *******************=
***/
+
static int option_index =3D 0;
-static char bt_name[248];
+static char bt_name[MAX_BTNAME_LEN+1];
static char ip_addr[32] =3D "0.0.0.0";
static char ip_name[HOST_NAME_LENGTH + DOMAIN_NAME_LENGTH] =3D "";
static char ip_addrname[36 + HOST_NAME_LENGTH + DOMAIN_NAME_LENGTH] =3D "";
=20
-static int var_add_ip =3D TRUE;
-static int var_add_host_name =3D TRUE;
+static int var_add_ip =3D FALSE;
+static int var_add_host_name =3D FALSE;
+static int var_write_scan_enable =3D -1; /* not yet set */
static int var_force_ms_switch =3D -1; /* not yet set */
static int var_set_local_name =3D 0;
=20
/* long option list */
static struct option long_options[] =3D
{
- {"file", 1, NULL, 'f'}, /* read options from file */
- {"force_msswitch", 1, NULL, 'm'}, /* force m/s switch as server */
+ { "file", 1, NULL, 'f' }, /* config file name */
+ { "help", 1, NULL, 'h' }, /* show help */
+ { "force-msswitch", 1, NULL, 'm' }, /* force m/s switch as server */
{"name", 1, NULL, 'n'}, /* set BT friendly name */
- {"wrscan_enable", 1, NULL, 'w'}, /* sets write scan enable */
+ { "wrscan-enable", 1, NULL, 'w' }, /* sets write scan enable */
{0, 0, 0, 0}
};
=20
-/*************************************************************************=
*/
+/****************** FUNCTION DEFINITION SECTION **************************=
***/
=20
void
-show_menu()
+show_usage(void)
{
- printf("\nWrong syntax or missing parameters\n");
- printf("Syntax : ./btconfig [--force_msswitch <0/1> --wrscan_enable <mod=
e> ");
- printf("--name <name> --file <filename>]\n");
+ printf("Syntax: btconfig [--force-msswitch (0|1)] [--wrscan-enable <mode=
>] [--name <name>] [--file <config file>]\n");
}
=20
int
main(int argc, char **argv)
{
int bt_cfd, opt;
-=20=20
- /* Print header if called via http */
- if (getenv("REQUEST_METHOD") !=3D NULL)
- {
- printf("Content-type: text/plain\r\n\r\n");
- }
-
- /* Open BT control tty */
- bt_cfd =3D bt_openctrl();
-
- /* Wait until stack is initiated */
- while (!bt_isinitiated())
- sleep(1);
-
- if (argc < 2)
- show_menu();
-=20=20
- /* Now parse options, if using both options and file the last argument=
=20
- overrides any earlier options */
+ int opt_write_scan_enable =3D -1;
+ int opt_force_ms_switch =3D -1;
+ char *opt_name =3D NULL;
+ char *opt_config_file =3D CONF_FILE;
=20
-#define OPTIONS_STRING "f:m:n:w:"=20=20
+ /* Parse command line options */
=20=20=20
- while ((opt =3D getopt_long(argc, argv, OPTIONS_STRING,=20
+ while ((opt =3D getopt_long(argc, argv, "f:hm:n:w:",
long_options, &option_index)) !=3D -1)
{
switch (opt)
{
+ case 'f':
+ opt_config_file =3D optarg;
+ break;
+
+ case 'h':
+ show_usage();
+ exit(0);
+
case 'm':
- /* Force a master slave switch as server */
- var_force_ms_switch =3D atoi(optarg);
+ /* Force a master/slave switch as server */
+ opt_force_ms_switch =3D atoi(optarg);
break;
=20
case 'n':
/* Set BT friendly name */
- var_set_local_name =3D 1;
- strncpy(bt_name, optarg, strlen(optarg));
+ opt_name =3D optarg;
break;
=20=20=20=20=20=20=20
case 'w':
/* Set write scan enable */
- bt_write_scan_enable(bt_cfd, atoi(optarg));
- break;
-
- case 'f':
- /* Read options from file */
- parse_file(optarg);=20=20
+ opt_write_scan_enable =3D atoi(optarg);
break;
=20
default:
-=20=20=20=20=20=20
break;
}
}
=20=20=20
+ parse_file(opt_config_file);
+
+ /* Command line arguments override the configuration file */
+
+ if (opt_name)
+ {
+ strncpy(bt_name, opt_name, MAX_BTNAME_LEN);
+ bt_name[MAX_BTNAME_LEN] =3D 0;
+ var_set_local_name =3D 1;
+ }
+=20=20
+ if (opt_write_scan_enable >=3D 0)
+ var_write_scan_enable =3D opt_write_scan_enable;
+
+ if (opt_force_ms_switch >=3D 0)
+ var_force_ms_switch =3D opt_force_ms_switch;
+
+ /* Configure the stack according to the options specified */
+=20=20
+ if (var_set_local_name ||
+ var_write_scan_enable >=3D 0 ||
+ var_force_ms_switch >=3D 0)
+ {
+ /* Wait until stack is initiated */
+ while (!bt_isinitiated())
+ sleep(1);
+
+ /* Open BT control tty */
+ if ((bt_cfd =3D bt_openctrl()) >=3D 0)
+ {
/* Configure BT local name */
if (var_set_local_name)
bt_set_local_name(bt_cfd, bt_name);
=20=20=20
+ /* Configure Write Scan Enable */
+ if (var_write_scan_enable >=3D 0)
+ bt_write_scan_enable(bt_cfd, var_write_scan_enable);
+
/* Configure Force M/S switch */
if (var_force_ms_switch >=3D 0)
bt_force_msswitch_as_server(bt_cfd, var_force_ms_switch);
=20
close(bt_cfd);
+ }
+ }
+
exit(0);
}
=20
-/*******************************************************************/
+/*************************************************************************=
*/
/*=20
* File parsing functions=20
*/=20
@@ -206,8 +231,7 @@
=20=20=20
if (!(f =3D fopen(filename, "r")))
{
- perror("fopen");=20=20=20=20
- exit(1);
+ return TRUE;
}
=20=20=20
syslog(LOG_INFO, __FUNCTION__": Opened %s file ok", filename);
@@ -227,23 +251,25 @@
}
}
=20
+ fclose(f);
+
/* Name handling */
- strcpy(ip_addrname, PRE);
+ if (*ip_addr || *ip_name)
+ {
+ strcpy(ip_addrname, " (");
strcat(ip_addrname, ip_addr);
- if (strlen(ip_name))
+ if (*ip_name)
{
- if (strlen(ip_addrname) > strlen(PRE)) {
+ if (*ip_addr) {
strcat(ip_addrname, ", ");
}
strcat(ip_addrname, ip_name);
}
- strcat(ip_addrname, POST);
+ strcat(ip_addrname, ")");
=20
- if (strlen(ip_addrname) > (strlen(PRE) + strlen(POST)))
- {
if ((strlen(bt_name) + strlen(ip_addrname)) > MAX_BTNAME_LEN)
{
- D(syslog(LOG_INFO, __FUNCTION__": Name to long, trunkating"));
+ D(syslog(LOG_INFO, __FUNCTION__": Name to long, truncating"));
strcpy(bt_name + MAX_BTNAME_LEN - strlen(ip_addrname), ip_addrname);
}
else
@@ -255,10 +281,6 @@
D(syslog(LOG_INFO, __FUNCTION__": Final name is (%d): %s\n",
strlen(bt_name), bt_name));
=20
- fclose(f);
-
- var_set_local_name =3D 1;
-=20=20
return TRUE;
} /* parse_file */
=20
@@ -333,7 +355,6 @@
int
configure_field(const char* field, const char* value)
{
-=20=20
if (!strcasecmp(field, "DeviceName"))
{
if (strlen(value) <=3D MAX_BTNAME_LEN)
@@ -349,6 +370,8 @@
syslog(LOG_INFO, ": Name to long, truncating to (%d): %s",
(int)strlen(bt_name), bt_name);
}
+
+ var_set_local_name =3D 1;
}
else if (!strcasecmp(field, "AddIP"))
{
@@ -402,10 +425,11 @@
else if (!strcasecmp(field, "ForceMSSwitch"))=20=20
{
var_force_ms_switch =3D !strcasecmp(value, "yes");
- D(syslog(LOG_INFO, __FUNCTION__ ": Force M/S switch : %s", value));
+ D(syslog(LOG_INFO, __FUNCTION__ ": Force M/S switch: %s",
+ (var_force_ms_switch ? "yes" : "no")));
}
=20=20=20
return TRUE;
} /* configure_field */
=20
-/***************************************************************/
+/****************** END OF FILE btconfig.c *******************************=
***/
|
|
From: Peter K. <pk...@us...> - 2001-06-08 10:17:25
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btconfig.c 1.3 1.4=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
* Marked a debug message as such.
The diff of the modified file(s):
--- btconfig.c 2001/05/14 11:09:22 1.3
+++ btconfig.c 2001/06/08 10:17:24 1.4
@@ -237,7 +237,7 @@
return TRUE;
}
=20=20=20
- syslog(LOG_INFO, __FUNCTION__": Opened %s file ok", filename);
+ D(syslog(LOG_INFO, __FUNCTION__": Opened config file '%s'", filename));
=20
while (fgets(buf, BUF_MAXSIZE, f))
{
|
|
From: Olov H. <ol...@us...> - 2001-07-10 13:01:36
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btconfig.c 1.4 1.5=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Added support for max number of BT connections
The diff of the modified file(s):
--- btconfig.c 2001/06/08 10:17:24 1.4
+++ btconfig.c 2001/07/10 13:01:35 1.5
@@ -77,6 +77,8 @@
#define HOST_NAME_LENGTH 100
#define DOMAIN_NAME_LENGTH 100
#define BUF_MAXSIZE 300
+#define MIN_CONNECTIONS 0
+#define MAX_CONNECTIONS 7
=20
#define CONF_FILE "/etc/bt.conf"
=20
@@ -106,6 +108,7 @@
static int var_write_scan_enable =3D -1; /* not yet set */
static int var_force_ms_switch =3D -1; /* not yet set */
static int var_set_local_name =3D 0;
+static int var_max_connections =3D -1; /* not yet set */
=20
/* long option list */
static struct option long_options[] =3D
@@ -115,6 +118,7 @@
{ "force-msswitch", 1, NULL, 'm' }, /* force m/s switch as server */
{ "name", 1, NULL, 'n' }, /* set BT friendly name */
{ "wrscan-enable", 1, NULL, 'w' }, /* sets write scan enable */
+ { "max-connections",1, NULL, 'c' }, /* sets max simultatious connection=
s */
{ 0, 0, 0, 0 }
};
=20
@@ -123,7 +127,7 @@
void
show_usage(void)
{
- printf("Syntax: btconfig [--force-msswitch (0|1)] [--wrscan-enable <mode=
>] [--name <name>] [--file <config file>]\n");
+ printf("Syntax: btconfig [--force-msswitch (0|1)] [--wrscan-enable <mode=
>] [--name <name>] [--file <config file>] [--max-connections (0-7)] \n");
}
=20
int
@@ -132,12 +136,14 @@
int bt_cfd, opt;
int opt_write_scan_enable =3D -1;
int opt_force_ms_switch =3D -1;
+ int opt_max_connections =3D -1;
+=20=20
char *opt_name =3D NULL;
char *opt_config_file =3D CONF_FILE;
=20
/* Parse command line options */
=20
- while ((opt =3D getopt_long(argc, argv, "f:hm:n:w:",
+ while ((opt =3D getopt_long(argc, argv, "f:hm:n:w:c:",
long_options, &option_index)) !=3D -1)
{
switch (opt)
@@ -165,6 +171,11 @@
opt_write_scan_enable =3D atoi(optarg);
break;
=20
+ case 'c':
+ /* Set max connections */
+ opt_max_connections =3D atoi(optarg);
+ break;
+=20=20=20=20=20=20
default:
break;
}
@@ -187,11 +198,15 @@
if (opt_force_ms_switch >=3D 0)
var_force_ms_switch =3D opt_force_ms_switch;
=20
+ if (opt_max_connections >=3D0)
+ var_max_connections =3D opt_max_connections;
+=20=20
/* Configure the stack according to the options specified */
=20=20=20
if (var_set_local_name ||
var_write_scan_enable >=3D 0 ||
- var_force_ms_switch >=3D 0)
+ var_force_ms_switch >=3D 0 ||
+ var_max_connections >=3D0)
{
/* Open BT ctrl device */=20=20
if ((bt_cfd =3D bt_openctrl()) < 0)
@@ -216,6 +231,14 @@
if (var_force_ms_switch >=3D 0)
bt_force_msswitch_as_server(bt_cfd, var_force_ms_switch);
=20
+ /* Configure Max BT connections */
+ if (var_max_connections >=3D MIN_CONNECTIONS && var_max_connections <=
=3D MAX_CONNECTIONS )
+ {
+ syslog(LOG_INFO, __FUNCTION__": Setting Max BT connections to %d",va=
r_max_connections);
+ bt_set_max_conections(bt_cfd, var_max_connections);
+ }
+ else
+ syslog(LOG_INFO, __FUNCTION__": Max BT connections, %d, out of range=
!",var_max_connections);
close(bt_cfd);
}
=20
@@ -430,6 +453,12 @@
var_force_ms_switch =3D !strcasecmp(value, "yes");
D(syslog(LOG_INFO, __FUNCTION__ ": Force M/S switch: %s",
(var_force_ms_switch ? "yes" : "no")));
+ }
+=20=20
+ else if (!strcasecmp(field, "MaxBTConnections"))=20=20
+ {=20
+ var_max_connections =3D atoi(value);
+ D(syslog(LOG_INFO, __FUNCTION__ ": Maximum BT connections: %s",value));
}
=20=20=20
return TRUE;
|
|
From: Peter K. <pk...@us...> - 2001-09-10 12:01:19
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btconfig.c 1.6 1.7=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Cleaned up setting of max number of connections.
The diff of the modified file(s):
--- btconfig.c 2001/09/10 09:41:50 1.6
+++ btconfig.c 2001/09/10 12:01:18 1.7
@@ -77,8 +77,6 @@
#define HOST_NAME_LENGTH 100
#define DOMAIN_NAME_LENGTH 100
#define BUF_MAXSIZE 300
-#define MIN_CONNECTIONS 0
-#define MAX_CONNECTIONS 7
=20
#define CONF_FILE "/etc/bt.conf"
=20
@@ -232,13 +230,9 @@
bt_force_msswitch_as_server(bt_cfd, var_force_ms_switch);
=20
/* Configure Max BT connections */
- if (var_max_connections >=3D MIN_CONNECTIONS && var_max_connections <=
=3D MAX_CONNECTIONS )
- {
- syslog(LOG_INFO, __FUNCTION__": Setting Max BT connections to %d",va=
r_max_connections);
+ if (var_max_connections >=3D 0)
bt_set_max_conections(bt_cfd, var_max_connections);
- }
- else
- syslog(LOG_INFO, __FUNCTION__": Max BT connections, %d, out of range=
!",var_max_connections);
+
close(bt_cfd);
}
=20
@@ -454,7 +448,6 @@
D(syslog(LOG_INFO, __FUNCTION__ ": Force M/S switch: %s",
(var_force_ms_switch ? "yes" : "no")));
}
-=20=20
else if (!strcasecmp(field, "MaxBTConnections"))=20=20
{=20
var_max_connections =3D atoi(value);
|
|
From: Peter K. <pk...@us...> - 2001-10-10 16:33:22
|
The following file was modified in apps/bluetooth/experimental:
Name Old version New version Comment
---- ----------- ----------- -------
btconfig.c 1.8 1.9=20=20=20=20=20=20=20=20=20=20=20=20=20
The accompanying log:
Change MaxPower to MaxTransmitPower.
The diff of the modified file(s):
--- btconfig.c 2001/10/10 16:22:10 1.8
+++ btconfig.c 2001/10/10 16:33:21 1.9
@@ -459,10 +459,10 @@
var_max_connections =3D atoi(value);
D(syslog(LOG_INFO, __FUNCTION__ ": Maximum BT connections: %s", value)=
);
}
- else if (!strcasecmp(field, "MaxPower"))
+ else if (!strcasecmp(field, "MaxTransmitPower"))
{=20
var_max_power =3D atoi(value);
- D(syslog(LOG_INFO, __FUNCTION__ ": Maximum power: %s", value));
+ D(syslog(LOG_INFO, __FUNCTION__ ": Maximum transmit power: %s", value)=
);
}
=20=20=20
return TRUE;
|
|
From: Peter K. <pk...@us...> - 2001-10-12 07:37:40
|
The following file was modified in apps/bluetooth/experimental: Name Old version New version Comment ---- ----------- ----------- ------- btconfig.c 1.9 1.10=20=20=20=20=20=20=20=20=20=20=20=20 The accompanying log: Added inclusion of limits.h The diff of the modified file(s): --- btconfig.c 2001/10/10 16:33:21 1.9 +++ btconfig.c 2001/10/12 07:37:39 1.10 @@ -56,6 +56,7 @@ #include <ctype.h> #include <arpa/inet.h> #include <net/if.h> +#include <limits.h> =20 #include "btd.h" #include "bt_if.h" |