All of lore.kernel.org
 help / color / mirror / Atom feed
* [Bluez-devel] [PATCH] Bluetooth address specific device configuration
@ 2004-01-28 18:56 Fredrik Noring
  2004-01-28 19:24 ` Fredrik Noring
  2004-01-29  5:52 ` Marcel Holtmann
  0 siblings, 2 replies; 17+ messages in thread
From: Fredrik Noring @ 2004-01-28 18:56 UTC (permalink / raw)
  To: BlueZ Mailing List; +Cc: Edd Dumbill

[-- Attachment #1: Type: text/plain, Size: 475 bytes --]

Hi

Attached patch makes it possible to use a configuration in hcid.conf
for a device with a certain Bluetooth device address:

   options
   {
	# hcid options...
   }

   device
   {
	# Default device options...
   }

   device 00:11:22:33:44:55
   {
	# Device options for bdaddr 00:11:22:33:44:55...
   }

It's useful to do persistent device specific configurations, for example
setting unique and meaningful names. I've only done limited testing.

Any thoughts?

Fredrik


[-- Attachment #2: hcid-addr.patch --]
[-- Type: text/x-patch, Size: 9989 bytes --]

diff -Naur bluez-utils-2.4.orig/hcid/hcid.h bluez-utils-2.4/hcid/hcid.h
--- bluez-utils-2.4.orig/hcid/hcid.h	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/hcid.h	2004-01-28 17:59:44.000000000 +0100
@@ -45,7 +45,14 @@
 	uint16_t auth;
 	uint16_t encrypt;
 };   
-extern struct device_opts devi;
+extern struct device_opts default_device;
+extern struct device_opts *parser_device;
+
+struct device_list {
+	char *bdaddr;
+	struct device_list *next;
+	struct device_opts opts;
+};
 
 struct link_key {
 	bdaddr_t sba;
@@ -84,6 +91,9 @@
 
 int read_config(char *file);
 
+void unlink_device_opts(void);
+struct device_opts *allocate_device_opts(char *bdaddr);
+
 gboolean io_stack_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 
diff -Naur bluez-utils-2.4.orig/hcid/lexer.l bluez-utils-2.4/hcid/lexer.l
--- bluez-utils-2.4.orig/hcid/lexer.l	2002-06-24 04:38:01.000000000 +0200
+++ bluez-utils-2.4/hcid/lexer.l	2004-01-28 16:21:36.000000000 +0100
@@ -52,6 +52,8 @@
 fname		[A-Za-z0-9\_\.\-]+	
 path		(\/{fname})+
 string		\".*\"
+hextuple        [0-9a-zA-Z][0-9a-zA-Z]
+bdaddr          {hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}
 
 %x OPTION PARAM  
 
@@ -70,6 +72,11 @@
 	lineno++;
 }
 
+{bdaddr} {
+	yylval.str = yytext;
+	return BDADDR;
+}
+
 {hex} {
 	yylval.num = strtol(yytext, NULL, 16);
 	return NUM;
diff -Naur bluez-utils-2.4.orig/hcid/main.c bluez-utils-2.4/hcid/main.c
--- bluez-utils-2.4.orig/hcid/main.c	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/main.c	2004-01-28 19:19:46.000000000 +0100
@@ -50,7 +50,9 @@
 #include "lib.h"
 
 struct hcid_opts hcid;
-struct device_opts devi;
+struct device_opts default_device;
+struct device_opts *parser_device;
+static struct device_list *device_list = 0;
 
 static GMainLoop *event_loop;
 
@@ -64,11 +66,31 @@
 	printf("\thcid [-n not_daemon] [-f config file]\n");
 }
 
+static struct device_opts *get_device_opts(bdaddr_t *bdaddr)
+  /* Returns device options for the given BD Address or 0. */
+{
+	struct device_list *device;
+	char addr[18];
+
+	ba2str(bdaddr, addr);
+	for (device = device_list; device; device = device->next)
+		if(strcmp(addr, device->bdaddr) == 0)
+			return &device->opts;
+	return 0;
+}
+
 static void configure_device(int hdev)
 {
+        struct device_opts *device_opts = 0;
+	struct hci_dev_info di;
 	struct hci_dev_req dr;
 	int s;
 
+	uint16_t auth;
+	uint16_t encrypt;
+	uint32_t class;
+	char *name;
+
 	/* Do configuration in the separate process */
 	switch (fork()) {
 		case 0:
@@ -88,16 +110,20 @@
 	}
 
 	dr.dev_id  = hdev;
-
+	di.dev_id = hdev;
+	if(ioctl(s, HCIGETDEVINFO, (void*)&di) == 0)
+		device_opts = get_device_opts(&di.bdaddr);
+	
 	/* Set scan mode */
-	dr.dev_opt = devi.scan;
+	dr.dev_opt = device_opts ? device_opts->scan : default_device.scan;
 	if (ioctl(s, HCISETSCAN, (unsigned long)&dr) < 0) {
 		syslog(LOG_ERR, "Can't set scan mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
 	}
 
 	/* Set authentication */
-	if (devi.auth)
+	auth = device_opts ? device_opts->auth : default_device.auth;
+	if (auth)
 		dr.dev_opt = AUTH_ENABLED;
 	else
 		dr.dev_opt = AUTH_DISABLED;
@@ -108,7 +134,8 @@
 	}
 
 	/* Set encryption */
-	if (devi.encrypt)
+	encrypt = device_opts ? device_opts->encrypt : default_device.encrypt;
+	if (encrypt)
 		dr.dev_opt = ENCRYPT_P2P;
 	else
 		dr.dev_opt = ENCRYPT_DISABLED;
@@ -119,19 +146,21 @@
 	}
 
         /* Set device class */
-	if (devi.class) {
-		uint32_t class = htobl(devi.class);
+	class = device_opts ? device_opts->class : default_device.class;
+	if (class) {
+		uint32_t dev_class = htobl(class);
 		write_class_of_dev_cp cp;
                 
-		memcpy(cp.dev_class, &class, 3);
+		memcpy(cp.dev_class, &dev_class, 3);
 		hci_send_cmd(s, OGF_HOST_CTL, OCF_WRITE_CLASS_OF_DEV,
 			WRITE_CLASS_OF_DEV_CP_SIZE, (void *) &cp);
 	}
 
 	/* Set device name */
-	if (devi.name) {
+	name = device_opts ? device_opts->name : default_device.name;
+	if (name) {
 		change_local_name_cp cp;
-		expand_name(cp.name, devi.name, hdev);
+		expand_name(cp.name, name, hdev);
 
 		hci_send_cmd(s, OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME,
 			CHANGE_LOCAL_NAME_CP_SIZE, (void *) &cp);
@@ -142,9 +171,15 @@
 
 static void init_device(int hdev)
 {
+        struct device_opts *device_opts = 0;
+	struct hci_dev_info di;
 	struct hci_dev_req dr;
 	int s;
 
+	uint16_t pkt_type;
+	uint16_t link_mode;
+	uint16_t link_policy;
+
 	/* Do initialization in the separate process */
 	switch (fork()) {
 		case 0:
@@ -170,11 +205,15 @@
 		exit(1);
 	}
 
-	dr.dev_id  = hdev;
+	dr.dev_id = hdev;
+	di.dev_id = hdev;
+	if(ioctl(s, HCIGETDEVINFO, (void*)&di) == 0)
+		device_opts = get_device_opts(&di.bdaddr);
 
 	/* Set packet type */
-	if (devi.pkt_type) {
-		dr.dev_opt = devi.pkt_type;
+	pkt_type = device_opts ? device_opts->pkt_type : default_device.pkt_type;
+	if (pkt_type) {
+		dr.dev_opt = pkt_type;
 		if (ioctl(s, HCISETPTYPE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set packet type on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -182,8 +221,9 @@
 	}
 
 	/* Set link mode */
-	if (devi.link_mode) {
-		dr.dev_opt = devi.link_mode;
+	link_mode = device_opts ? device_opts->link_mode : default_device.link_mode;
+	if (link_mode) {
+		dr.dev_opt = link_mode;
 		if (ioctl(s, HCISETLINKMODE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -191,8 +231,9 @@
 	}
 
 	/* Set link policy */
-	if (devi.link_policy) {
-		dr.dev_opt = devi.link_policy;
+	link_policy = device_opts ? device_opts->link_policy : default_device.link_policy;
+	if (link_policy) {
+		dr.dev_opt = link_policy;
 		if (ioctl(s, HCISETLINKPOL, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link policy on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -236,15 +277,59 @@
 	free(dl);
 }
 
+static void init_device_defaults(struct device_opts *device_opts)
+{
+	device_opts->name        = 0;
+	device_opts->class       = 0;
+	device_opts->pkt_type    = 0;
+	device_opts->scan        = SCAN_PAGE | SCAN_INQUIRY;
+	device_opts->link_mode   = 0;
+	device_opts->link_policy = 0;
+	device_opts->auth        = 0;
+	device_opts->encrypt     = 0;
+}
+
 static void init_defaults(void)
 {
 	hcid.auto_init = 0;
 	hcid.security  = 0;
 
-	devi.pkt_type = 0;
-	devi.scan = SCAN_PAGE | SCAN_INQUIRY;
-	devi.auth = 0;
-	devi.encrypt = 0;
+	init_device_defaults(&default_device);
+}
+
+struct device_opts *allocate_device_opts(char *bdaddr)
+{
+	struct device_list *device;
+	
+	device = malloc(sizeof(struct device_list));
+	if (!device)
+	{
+		syslog(LOG_INFO, "Can't allocate devlist opts buffer. %s(%d)", 
+			strerror(errno), errno);
+		exit(1);
+	}
+	
+	device->bdaddr = bdaddr;
+	device->next = device_list;
+	device_list = device;
+
+	init_device_defaults(&device->opts);
+
+	return &device->opts;
+}
+
+void unlink_device_opts(void)
+{
+	struct device_list *device, *next;
+
+	for (device = device_list; device; device = next) {
+		free(device->bdaddr);
+		if(device->opts.name)
+			free(device->opts.name);
+		next = device->next;
+		free(device);
+	}
+	device_list = 0;
 }
 
 static void sig_usr1(int sig)
@@ -467,6 +552,8 @@
 	/* Start event processor */
 	g_main_run(event_loop);
 
+	unlink_device_opts();
+	
 	syslog(LOG_INFO, "Exit.");
 	return 0;
 }
diff -Naur bluez-utils-2.4.orig/hcid/parser.y bluez-utils-2.4/hcid/parser.y
--- bluez-utils-2.4.orig/hcid/parser.y	2002-08-20 20:42:12.000000000 +0200
+++ bluez-utils-2.4/hcid/parser.y	2004-01-28 19:26:19.000000000 +0100
@@ -61,18 +61,18 @@
 %token K_PINHELP
 %token K_YES K_NO
 
-%token <str> WORD PATH STRING LIST
+%token <str> WORD PATH STRING LIST BDADDR
 %token <num> NUM
 
 %type  <num> bool pkt_type link_mode link_policy sec_mode pair_mode
-%type  <str> dev_name
+%type  <str> dev_name bdaddr
 
 %%
 config: statement | config statement;
 statement: 
   K_OPTIONS hcid_options
  
-  | K_DEVICE device_options
+  | device device_options
 
   | WORD	{
 			cfg_error("Invalid statement '%s'", $1);
@@ -82,6 +82,16 @@
 		}
   ;
 
+device:
+    K_DEVICE		{
+				parser_device = &default_device;
+			}
+    
+    | K_DEVICE bdaddr	{
+				parser_device = allocate_device_opts($2);
+			}
+    ;
+
 hcid_options: '{' hcid_opts '}';
 hcid_opts: | hcid_opt ';' | error ';' | hcid_opts hcid_opt ';';
 hcid_opt: 
@@ -137,47 +147,47 @@
 device_opts: | device_opt ';' | error ';' | device_opts device_opt ';';
 device_opt:
   K_PTYPE pkt_type	{
-				devi.pkt_type = $2;
+				parser_device->pkt_type = $2;
 			}
 
   | K_LM link_mode	{
-				devi.link_mode = $2;
+				parser_device->link_mode = $2;
 			}
 
   | K_LP link_policy	{
-				devi.link_policy = $2;
+				parser_device->link_policy = $2;
 			}
 
   | K_NAME dev_name	{  
-				if (devi.name)
-					free(devi.name);
-				devi.name = $2;
+				if (parser_device->name)
+					free(parser_device->name);
+				parser_device->name = $2;
 			}
 
   | K_CLASS NUM		{
-				devi.class = $2;
+				parser_device->class = $2;
 			}
 
   | K_AUTH bool		{
-				devi.auth = $2;
+				parser_device->auth = $2;
 			}
 
   | K_ENCRYPT bool	{
-				devi.encrypt = $2;
+				parser_device->encrypt = $2;
 			}
 
   | K_ISCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_INQUIRY;
+					parser_device->scan |=  SCAN_INQUIRY;
 				else
-					devi.scan &= ~SCAN_INQUIRY;
+					parser_device->scan &= ~SCAN_INQUIRY;
 			}
 
   | K_PSCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_PAGE;
+					parser_device->scan |=  SCAN_PAGE;
 				else
-					devi.scan &= ~SCAN_PAGE;
+					parser_device->scan &= ~SCAN_PAGE;
 			}
 
   | WORD		{
@@ -196,6 +206,12 @@
 		}
   ;
 
+bdaddr:
+  BDADDR	{  
+			$$ = strdup($1);
+		}
+  ;
+
 pkt_type:
   WORD 	 	{
 			int opt;
@@ -274,6 +290,8 @@
 {
 	extern FILE *yyin;
 
+	unlink_device_opts();
+	
 	if( !(yyin = fopen(file,"r")) ){
 		syslog(LOG_ERR,"Can not open %s", file);
 		return -1;      

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-28 18:56 [Bluez-devel] [PATCH] Bluetooth address specific device configuration Fredrik Noring
@ 2004-01-28 19:24 ` Fredrik Noring
  2004-01-28 23:16   ` Achim Bohnet
  2004-01-29  5:52 ` Marcel Holtmann
  1 sibling, 1 reply; 17+ messages in thread
From: Fredrik Noring @ 2004-01-28 19:24 UTC (permalink / raw)
  To: BlueZ Mailing List; +Cc: Edd Dumbill

ons 2004-01-28 klockan 19.56 skrev Fredrik Noring:
>    device 00:11:22:33:44:55
>    {
> 	# Device options for bdaddr 00:11:22:33:44:55...
>    }

Btw., a variation on the theme is to allow:

   device hci0
   {
	# Device options for interface hci0...
   }

I don't know which one is most useful or if both should be allowed.

Fredrik




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-28 19:24 ` Fredrik Noring
@ 2004-01-28 23:16   ` Achim Bohnet
  2004-01-29 18:29     ` Fredrik Noring
  0 siblings, 1 reply; 17+ messages in thread
From: Achim Bohnet @ 2004-01-28 23:16 UTC (permalink / raw)
  To: BlueZ Mailing List

On Wednesday 28 January 2004 20:24, Fredrik Noring wrote:
> ons 2004-01-28 klockan 19.56 skrev Fredrik Noring:
> >    device 00:11:22:33:44:55
> >    {
> > 	# Device options for bdaddr 00:11:22:33:44:55...
> >    }
> 
> Btw., a variation on the theme is to allow:
> 
>    device hci0
>    {
> 	# Device options for interface hci0...
>    }
> 
> I don't know which one is most useful or if both should be allowed.

I've a laptop with buildin bt and an external bt stick.  It depends on the
order I switch internal one on or connect the stick what interface is
assigned to the same hardware.  If there is a need (no idea yet I'm
a bt newbie) for this feature selection by bdaddr is therefore useful
to support.  Selection by interface would be useless for me.

On the other hand if I ever take the another identical stick with me
by accident, bdaddr would be different  and the settings would not
apply without a notice.  Maybe a 

	device default
	{
	    complain loudly
	}

is useful ;)

Achim
> 
> Fredrik
> -------------------------------------------------------
> The SF.Net email is sponsored by EclipseCon 2004
> Premiere Conference on Open Tools Development and Integration
> See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
> http://www.eclipsecon.org/osdn
> _______________________________________________
> Bluez-devel mailing list
> Bluez-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/bluez-devel
> 
> 
> 

-- 
  To me vi is Zen.  To use vi is to practice zen. Every command is
  a koan. Profound to the user, unintelligible to the uninitiated.
  You discover truth everytime you use it.
                                      -- reddy@lion.austin.ibm.com



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-28 18:56 [Bluez-devel] [PATCH] Bluetooth address specific device configuration Fredrik Noring
  2004-01-28 19:24 ` Fredrik Noring
@ 2004-01-29  5:52 ` Marcel Holtmann
  2004-01-29 19:39   ` Fredrik Noring
  1 sibling, 1 reply; 17+ messages in thread
From: Marcel Holtmann @ 2004-01-29  5:52 UTC (permalink / raw)
  To: Fredrik Noring; +Cc: BlueZ Mailing List, Edd Dumbill

Hi Fredrik,

> Attached patch makes it possible to use a configuration in hcid.conf
> for a device with a certain Bluetooth device address:
> 
>    options
>    {
> 	# hcid options...
>    }
> 
>    device
>    {
> 	# Default device options...
>    }
> 
>    device 00:11:22:33:44:55
>    {
> 	# Device options for bdaddr 00:11:22:33:44:55...
>    }
> 
> It's useful to do persistent device specific configurations, for example
> setting unique and meaningful names. I've only done limited testing.

I like the idea (also the second one with hci0). Please send me a patch
that enables both possibilities. But be aware of that I don't even had
reviewed your first one, so this can take some time before I will apply
it.

Has anyone already tested this patch? Do it break some other stuff?

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* [Bluez-devel] [PATCH] Bluetooth address specific device configuration
@ 2004-01-29 10:38 Nosve
  2004-01-31 19:04 ` Marcel Holtmann
  0 siblings, 1 reply; 17+ messages in thread
From: Nosve @ 2004-01-29 10:38 UTC (permalink / raw)
  To: bluez-devel

BTW, hcid.conf with his options where is documented?



Fredrik Noring wrote:
> Hi
> 
> Attached patch makes it possible to use a configuration in hcid.conf
> for a device with a certain Bluetooth device address:

>   options
>   {
>	# hcid options...
>   }


-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-28 23:16   ` Achim Bohnet
@ 2004-01-29 18:29     ` Fredrik Noring
  0 siblings, 0 replies; 17+ messages in thread
From: Fredrik Noring @ 2004-01-29 18:29 UTC (permalink / raw)
  To: Achim Bohnet; +Cc: BlueZ Mailing List

Hi Achim,

tor 2004-01-29 klockan 00.16 skrev Achim Bohnet:
> I've a laptop with buildin bt and an external bt stick.  It depends on the
> order I switch internal one on or connect the stick what interface is
> assigned to the same hardware.  If there is a need (no idea yet I'm
> a bt newbie) for this feature selection by bdaddr is therefore useful
> to support.  Selection by interface would be useless for me.

I think combining all three possibilities is the best:

	device <bdaddr>
	{
		# This is the configuration for all
		# devices that have matching bdaddr:s.
	}

	device <hci interface>
	{
		# This is the configuration for all devices 
		# that have matching interfaces but no matching 
		# bdaddr.
	}

	device
	{
		# This is the configuration for all devices 
		# that don't match anything else: the default.
	}

This way one can mix and move devices around and hcid will do its
best to configure things properly.

Having a utility (e.g. config-bluetooth) managing all these
configurations simpifies things, of course.

> On the other hand if I ever take the another identical stick with me
> by accident, bdaddr would be different  and the settings would not
> apply without a notice.  Maybe a 
> 
> 	device default
> 	{
> 	    complain loudly
> 	}
> 
> is useful ;)

Well, simply having

	device
	{
		# Default configuration.
	}

already works today. :)

Fredrik




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-29  5:52 ` Marcel Holtmann
@ 2004-01-29 19:39   ` Fredrik Noring
  2004-01-29 19:58     ` Fredrik Noring
  0 siblings, 1 reply; 17+ messages in thread
From: Fredrik Noring @ 2004-01-29 19:39 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ Mailing List, Edd Dumbill

[-- Attachment #1: Type: text/plain, Size: 213 bytes --]

Marcel,

tor 2004-01-29 klockan 06.52 skrev Marcel Holtmann:
> I like the idea (also the second one with hci0). Please send me a patch
> that enables both possibilities.

Attached patch implements both.

Fredrik


[-- Attachment #2: hcid-device.patch --]
[-- Type: text/x-patch, Size: 9893 bytes --]

diff -Naur bluez-utils-2.4.orig/hcid/hcid.h bluez-utils-2.4/hcid/hcid.h
--- bluez-utils-2.4.orig/hcid/hcid.h	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/hcid.h	2004-01-29 20:30:36.000000000 +0100
@@ -45,7 +45,14 @@
 	uint16_t auth;
 	uint16_t encrypt;
 };   
-extern struct device_opts devi;
+extern struct device_opts default_device;
+extern struct device_opts *parser_device;
+
+struct device_list {
+	char *ref;                  /* hci interface or Bluetooth address */
+	struct device_list *next;
+	struct device_opts opts;
+};
 
 struct link_key {
 	bdaddr_t sba;
@@ -84,6 +91,9 @@
 
 int read_config(char *file);
 
+void free_device_opts(void);
+struct device_opts *allocate_device_opts(char *bdaddr);
+
 gboolean io_stack_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 
diff -Naur bluez-utils-2.4.orig/hcid/lexer.l bluez-utils-2.4/hcid/lexer.l
--- bluez-utils-2.4.orig/hcid/lexer.l	2002-06-24 04:38:01.000000000 +0200
+++ bluez-utils-2.4/hcid/lexer.l	2004-01-29 20:10:51.000000000 +0100
@@ -52,6 +52,9 @@
 fname		[A-Za-z0-9\_\.\-]+	
 path		(\/{fname})+
 string		\".*\"
+hci		hci[0-9]+
+hextuple	[0-9a-zA-Z][0-9a-zA-Z]
+bdaddr		{hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}
 
 %x OPTION PARAM  
 
@@ -70,6 +73,16 @@
 	lineno++;
 }
 
+{hci} {
+	yylval.str = yytext;
+	return HCI;
+}
+
+{bdaddr} {
+	yylval.str = yytext;
+	return BDADDR;
+}
+
 {hex} {
 	yylval.num = strtol(yytext, NULL, 16);
 	return NUM;
diff -Naur bluez-utils-2.4.orig/hcid/main.c bluez-utils-2.4/hcid/main.c
--- bluez-utils-2.4.orig/hcid/main.c	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/main.c	2004-01-29 20:30:42.000000000 +0100
@@ -50,7 +50,9 @@
 #include "lib.h"
 
 struct hcid_opts hcid;
-struct device_opts devi;
+struct device_opts default_device;
+struct device_opts *parser_device;
+static struct device_list *device_list = 0;
 
 static GMainLoop *event_loop;
 
@@ -64,8 +66,54 @@
 	printf("\thcid [-n not_daemon] [-f config file]\n");
 }
 
+static struct device_opts *get_device_ref_opts(char *ref)
+{
+	struct device_list *device;
+
+	for (device = device_list; device; device = device->next)
+		if(strcmp(ref, device->ref) == 0)
+			return &device->opts;
+	return 0;
+}
+
+static struct device_opts *get_bdaddr_device_opts(bdaddr_t *bdaddr)
+{
+	char addr[18];
+
+	ba2str(bdaddr, addr);
+	return get_device_ref_opts(addr);
+}
+
+static struct device_opts *get_hci_device_opts(int hdev)
+{
+	char ref[16];
+
+	sprintf(ref, "hci%d", hdev);
+	return get_device_ref_opts(ref);
+}
+
+static struct device_opts *get_device_opts(int sock, int hdev)
+{
+        struct device_opts *device_opts = 0;
+	struct hci_dev_info di;
+
+	di.dev_id = hdev;
+	if(ioctl(sock, HCIGETDEVINFO, (void*)&di) == 0)
+		/* First try to get BDADDR based settings... */
+		device_opts = get_bdaddr_device_opts(&di.bdaddr);
+	if(!device_opts)
+		/* ...then try hci interface based settings... */
+		device_opts = get_hci_device_opts(hdev);
+	if(!device_opts)
+		/* ...and last the default. */
+		device_opts = &default_device;
+	
+	return device_opts;
+}
+
 static void configure_device(int hdev)
 {
+	struct device_opts *device_opts = 0;
 	struct hci_dev_req dr;
 	int s;
 
@@ -88,16 +136,17 @@
 	}
 
 	dr.dev_id  = hdev;
+	device_opts = get_device_opts(s, hdev);
 
 	/* Set scan mode */
-	dr.dev_opt = devi.scan;
+	dr.dev_opt = device_opts->scan;
 	if (ioctl(s, HCISETSCAN, (unsigned long)&dr) < 0) {
 		syslog(LOG_ERR, "Can't set scan mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
 	}
 
 	/* Set authentication */
-	if (devi.auth)
+	if (device_opts->auth)
 		dr.dev_opt = AUTH_ENABLED;
 	else
 		dr.dev_opt = AUTH_DISABLED;
@@ -108,7 +157,7 @@
 	}
 
 	/* Set encryption */
-	if (devi.encrypt)
+	if (device_opts->encrypt)
 		dr.dev_opt = ENCRYPT_P2P;
 	else
 		dr.dev_opt = ENCRYPT_DISABLED;
@@ -119,8 +168,8 @@
 	}
 
         /* Set device class */
-	if (devi.class) {
-		uint32_t class = htobl(devi.class);
+	if (device_opts->class) {
+		uint32_t class = htobl(device_opts->class);
 		write_class_of_dev_cp cp;
                 
 		memcpy(cp.dev_class, &class, 3);
@@ -129,9 +178,9 @@
 	}
 
 	/* Set device name */
-	if (devi.name) {
+	if (device_opts->name) {
 		change_local_name_cp cp;
-		expand_name(cp.name, devi.name, hdev);
+		expand_name(cp.name, device_opts->name, hdev);
 
 		hci_send_cmd(s, OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME,
 			CHANGE_LOCAL_NAME_CP_SIZE, (void *) &cp);
@@ -142,6 +191,7 @@
 
 static void init_device(int hdev)
 {
+	struct device_opts *device_opts = 0;
 	struct hci_dev_req dr;
 	int s;
 
@@ -171,10 +221,11 @@
 	}
 
 	dr.dev_id  = hdev;
+	device_opts = get_device_opts(s, hdev);
 
 	/* Set packet type */
-	if (devi.pkt_type) {
-		dr.dev_opt = devi.pkt_type;
+	if (device_opts->pkt_type) {
+		dr.dev_opt = device_opts->pkt_type;
 		if (ioctl(s, HCISETPTYPE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set packet type on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -182,8 +233,8 @@
 	}
 
 	/* Set link mode */
-	if (devi.link_mode) {
-		dr.dev_opt = devi.link_mode;
+	if (device_opts->link_mode) {
+		dr.dev_opt = device_opts->link_mode;
 		if (ioctl(s, HCISETLINKMODE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -191,8 +242,8 @@
 	}
 
 	/* Set link policy */
-	if (devi.link_policy) {
-		dr.dev_opt = devi.link_policy;
+	if (device_opts->link_policy) {
+		dr.dev_opt = device_opts->link_policy;
 		if (ioctl(s, HCISETLINKPOL, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link policy on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -236,15 +287,58 @@
 	free(dl);
 }
 
+static void init_device_defaults(struct device_opts *device_opts)
+{
+	device_opts->name        = 0;
+	device_opts->class       = 0;
+	device_opts->pkt_type    = 0;
+	device_opts->scan        = SCAN_PAGE | SCAN_INQUIRY;
+	device_opts->link_mode   = 0;
+	device_opts->link_policy = 0;
+	device_opts->auth        = 0;
+	device_opts->encrypt     = 0;
+}
+
 static void init_defaults(void)
 {
 	hcid.auto_init = 0;
 	hcid.security  = 0;
 
-	devi.pkt_type = 0;
-	devi.scan = SCAN_PAGE | SCAN_INQUIRY;
-	devi.auth = 0;
-	devi.encrypt = 0;
+	init_device_defaults(&default_device);
+}
+
+struct device_opts *allocate_device_opts(char *ref)
+{
+	struct device_list *device;
+	
+	device = malloc(sizeof(struct device_list));
+	if (!device)
+	{
+		syslog(LOG_INFO, "Can't allocate devlist opts buffer. %s(%d)", 
+			strerror(errno), errno);
+		exit(1);
+	}
+	
+	device->ref = ref;
+	device->next = device_list;
+	device_list = device;
+
+	init_device_defaults(&device->opts);
+	return &device->opts;
+}
+
+void free_device_opts(void)
+{
+	struct device_list *device, *next;
+
+	for (device = device_list; device; device = next) {
+		free(device->ref);
+		if(device->opts.name)
+			free(device->opts.name);
+		next = device->next;
+		free(device);
+	}
+	device_list = 0;
 }
 
 static void sig_usr1(int sig)
@@ -467,6 +561,8 @@
 	/* Start event processor */
 	g_main_run(event_loop);
 
+	free_device_opts();
+	
 	syslog(LOG_INFO, "Exit.");
 	return 0;
 }
diff -Naur bluez-utils-2.4.orig/hcid/parser.y bluez-utils-2.4/hcid/parser.y
--- bluez-utils-2.4.orig/hcid/parser.y	2002-08-20 20:42:12.000000000 +0200
+++ bluez-utils-2.4/hcid/parser.y	2004-01-29 20:31:18.000000000 +0100
@@ -61,18 +61,18 @@
 %token K_PINHELP
 %token K_YES K_NO
 
-%token <str> WORD PATH STRING LIST
+%token <str> WORD PATH STRING LIST HCI BDADDR
 %token <num> NUM
 
 %type  <num> bool pkt_type link_mode link_policy sec_mode pair_mode
-%type  <str> dev_name
+%type  <str> dev_name hci bdaddr
 
 %%
 config: statement | config statement;
 statement: 
   K_OPTIONS hcid_options
  
-  | K_DEVICE device_options
+  | device device_options
 
   | WORD	{
 			cfg_error("Invalid statement '%s'", $1);
@@ -82,6 +82,20 @@
 		}
   ;
 
+device:
+    K_DEVICE		{
+				parser_device = &default_device;
+			}
+    
+    | K_DEVICE hci	{
+				parser_device = allocate_device_opts($2);
+			}
+    
+    | K_DEVICE bdaddr	{
+				parser_device = allocate_device_opts($2);
+			}
+    ;
+
 hcid_options: '{' hcid_opts '}';
 hcid_opts: | hcid_opt ';' | error ';' | hcid_opts hcid_opt ';';
 hcid_opt: 
@@ -137,47 +151,47 @@
 device_opts: | device_opt ';' | error ';' | device_opts device_opt ';';
 device_opt:
   K_PTYPE pkt_type	{
-				devi.pkt_type = $2;
+				parser_device->pkt_type = $2;
 			}
 
   | K_LM link_mode	{
-				devi.link_mode = $2;
+				parser_device->link_mode = $2;
 			}
 
   | K_LP link_policy	{
-				devi.link_policy = $2;
+				parser_device->link_policy = $2;
 			}
 
   | K_NAME dev_name	{  
-				if (devi.name)
-					free(devi.name);
-				devi.name = $2;
+				if (parser_device->name)
+					free(parser_device->name);
+				parser_device->name = $2;
 			}
 
   | K_CLASS NUM		{
-				devi.class = $2;
+				parser_device->class = $2;
 			}
 
   | K_AUTH bool		{
-				devi.auth = $2;
+				parser_device->auth = $2;
 			}
 
   | K_ENCRYPT bool	{
-				devi.encrypt = $2;
+				parser_device->encrypt = $2;
 			}
 
   | K_ISCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_INQUIRY;
+					parser_device->scan |=  SCAN_INQUIRY;
 				else
-					devi.scan &= ~SCAN_INQUIRY;
+					parser_device->scan &= ~SCAN_INQUIRY;
 			}
 
   | K_PSCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_PAGE;
+					parser_device->scan |=  SCAN_PAGE;
 				else
-					devi.scan &= ~SCAN_PAGE;
+					parser_device->scan &= ~SCAN_PAGE;
 			}
 
   | WORD		{
@@ -196,6 +210,18 @@
 		}
   ;
 
+hci:
+  HCI		{  
+			$$ = strdup($1);
+		}
+  ;
+
+bdaddr:
+  BDADDR	{  
+			$$ = strdup($1);
+		}
+  ;
+
 pkt_type:
   WORD 	 	{
 			int opt;
@@ -274,6 +300,8 @@
 {
 	extern FILE *yyin;
 
+	free_device_opts();
+	
 	if( !(yyin = fopen(file,"r")) ){
 		syslog(LOG_ERR,"Can not open %s", file);
 		return -1;      

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-29 19:39   ` Fredrik Noring
@ 2004-01-29 19:58     ` Fredrik Noring
  2004-01-31 15:30       ` Marcel Holtmann
  0 siblings, 1 reply; 17+ messages in thread
From: Fredrik Noring @ 2004-01-29 19:58 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ Mailing List, Edd Dumbill

[-- Attachment #1: Type: text/plain, Size: 156 bytes --]

Hi

tor 2004-01-29 klockan 20.39 skrev Fredrik Noring:
> Attached patch implements both.

The new version of the patch fixes a small memory leak.

Fredrik


[-- Attachment #2: hcid-device.patch --]
[-- Type: text/x-patch, Size: 9988 bytes --]

diff -Naur bluez-utils-2.4.orig/hcid/hcid.h bluez-utils-2.4/hcid/hcid.h
--- bluez-utils-2.4.orig/hcid/hcid.h	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/hcid.h	2004-01-29 20:30:36.000000000 +0100
@@ -45,7 +45,14 @@
 	uint16_t auth;
 	uint16_t encrypt;
 };   
-extern struct device_opts devi;
+extern struct device_opts default_device;
+extern struct device_opts *parser_device;
+
+struct device_list {
+	char *ref;                  /* hci interface or Bluetooth address */
+	struct device_list *next;
+	struct device_opts opts;
+};
 
 struct link_key {
 	bdaddr_t sba;
@@ -84,6 +91,9 @@
 
 int read_config(char *file);
 
+void free_device_opts(void);
+struct device_opts *allocate_device_opts(char *bdaddr);
+
 gboolean io_stack_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 gboolean io_security_event(GIOChannel *chan, GIOCondition cond, gpointer data);
 
diff -Naur bluez-utils-2.4.orig/hcid/lexer.l bluez-utils-2.4/hcid/lexer.l
--- bluez-utils-2.4.orig/hcid/lexer.l	2002-06-24 04:38:01.000000000 +0200
+++ bluez-utils-2.4/hcid/lexer.l	2004-01-29 20:10:51.000000000 +0100
@@ -52,6 +52,9 @@
 fname		[A-Za-z0-9\_\.\-]+	
 path		(\/{fname})+
 string		\".*\"
+hci		hci[0-9]+
+hextuple	[0-9a-zA-Z][0-9a-zA-Z]
+bdaddr		{hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}:{hextuple}
 
 %x OPTION PARAM  
 
@@ -70,6 +73,16 @@
 	lineno++;
 }
 
+{hci} {
+	yylval.str = yytext;
+	return HCI;
+}
+
+{bdaddr} {
+	yylval.str = yytext;
+	return BDADDR;
+}
+
 {hex} {
 	yylval.num = strtol(yytext, NULL, 16);
 	return NUM;
diff -Naur bluez-utils-2.4.orig/hcid/main.c bluez-utils-2.4/hcid/main.c
--- bluez-utils-2.4.orig/hcid/main.c	2003-03-08 00:10:30.000000000 +0100
+++ bluez-utils-2.4/hcid/main.c	2004-01-29 20:53:28.000000000 +0100
@@ -50,7 +50,9 @@
 #include "lib.h"
 
 struct hcid_opts hcid;
-struct device_opts devi;
+struct device_opts default_device;
+struct device_opts *parser_device;
+static struct device_list *device_list = 0;
 
 static GMainLoop *event_loop;
 
@@ -64,8 +66,54 @@
 	printf("\thcid [-n not_daemon] [-f config file]\n");
 }
 
+static struct device_opts *get_device_ref_opts(char *ref)
+{
+	struct device_list *device;
+
+	for (device = device_list; device; device = device->next)
+		if(strcmp(ref, device->ref) == 0)
+			return &device->opts;
+	return 0;
+}
+
+static struct device_opts *get_bdaddr_device_opts(bdaddr_t *bdaddr)
+{
+	char addr[18];
+
+	ba2str(bdaddr, addr);
+	return get_device_ref_opts(addr);
+}
+
+static struct device_opts *get_hci_device_opts(int hdev)
+{
+	char ref[16];
+
+	sprintf(ref, "hci%d", hdev);
+	return get_device_ref_opts(ref);
+}
+
+static struct device_opts *get_device_opts(int sock, int hdev)
+{
+        struct device_opts *device_opts = 0;
+	struct hci_dev_info di;
+
+	di.dev_id = hdev;
+	if(ioctl(sock, HCIGETDEVINFO, (void*)&di) == 0)
+		/* First try to get BDADDR based settings... */
+		device_opts = get_bdaddr_device_opts(&di.bdaddr);
+	if(!device_opts)
+		/* ...then try hci interface based settings... */
+		device_opts = get_hci_device_opts(hdev);
+	if(!device_opts)
+		/* ...and last the default. */
+		device_opts = &default_device;
+	
+	return device_opts;
+}
+
 static void configure_device(int hdev)
 {
+	struct device_opts *device_opts = 0;
 	struct hci_dev_req dr;
 	int s;
 
@@ -88,16 +136,17 @@
 	}
 
 	dr.dev_id  = hdev;
+	device_opts = get_device_opts(s, hdev);
 
 	/* Set scan mode */
-	dr.dev_opt = devi.scan;
+	dr.dev_opt = device_opts->scan;
 	if (ioctl(s, HCISETSCAN, (unsigned long)&dr) < 0) {
 		syslog(LOG_ERR, "Can't set scan mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
 	}
 
 	/* Set authentication */
-	if (devi.auth)
+	if (device_opts->auth)
 		dr.dev_opt = AUTH_ENABLED;
 	else
 		dr.dev_opt = AUTH_DISABLED;
@@ -108,7 +157,7 @@
 	}
 
 	/* Set encryption */
-	if (devi.encrypt)
+	if (device_opts->encrypt)
 		dr.dev_opt = ENCRYPT_P2P;
 	else
 		dr.dev_opt = ENCRYPT_DISABLED;
@@ -119,8 +168,8 @@
 	}
 
         /* Set device class */
-	if (devi.class) {
-		uint32_t class = htobl(devi.class);
+	if (device_opts->class) {
+		uint32_t class = htobl(device_opts->class);
 		write_class_of_dev_cp cp;
                 
 		memcpy(cp.dev_class, &class, 3);
@@ -129,9 +178,9 @@
 	}
 
 	/* Set device name */
-	if (devi.name) {
+	if (device_opts->name) {
 		change_local_name_cp cp;
-		expand_name(cp.name, devi.name, hdev);
+		expand_name(cp.name, device_opts->name, hdev);
 
 		hci_send_cmd(s, OGF_HOST_CTL, OCF_CHANGE_LOCAL_NAME,
 			CHANGE_LOCAL_NAME_CP_SIZE, (void *) &cp);
@@ -142,6 +191,7 @@
 
 static void init_device(int hdev)
 {
+	struct device_opts *device_opts = 0;
 	struct hci_dev_req dr;
 	int s;
 
@@ -171,10 +221,11 @@
 	}
 
 	dr.dev_id  = hdev;
+	device_opts = get_device_opts(s, hdev);
 
 	/* Set packet type */
-	if (devi.pkt_type) {
-		dr.dev_opt = devi.pkt_type;
+	if (device_opts->pkt_type) {
+		dr.dev_opt = device_opts->pkt_type;
 		if (ioctl(s, HCISETPTYPE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set packet type on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -182,8 +233,8 @@
 	}
 
 	/* Set link mode */
-	if (devi.link_mode) {
-		dr.dev_opt = devi.link_mode;
+	if (device_opts->link_mode) {
+		dr.dev_opt = device_opts->link_mode;
 		if (ioctl(s, HCISETLINKMODE, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link mode on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -191,8 +242,8 @@
 	}
 
 	/* Set link policy */
-	if (devi.link_policy) {
-		dr.dev_opt = devi.link_policy;
+	if (device_opts->link_policy) {
+		dr.dev_opt = device_opts->link_policy;
 		if (ioctl(s, HCISETLINKPOL, (unsigned long)&dr) < 0) {
 			syslog(LOG_ERR, "Can't set link policy on hci%d. %s(%d)\n", 
 				hdev, strerror(errno), errno);
@@ -236,15 +287,64 @@
 	free(dl);
 }
 
+static void init_device_defaults(struct device_opts *device_opts)
+{
+	device_opts->name        = 0;
+	device_opts->class       = 0;
+	device_opts->pkt_type    = 0;
+	device_opts->scan        = SCAN_PAGE | SCAN_INQUIRY;
+	device_opts->link_mode   = 0;
+	device_opts->link_policy = 0;
+	device_opts->auth        = 0;
+	device_opts->encrypt     = 0;
+}
+
 static void init_defaults(void)
 {
 	hcid.auto_init = 0;
 	hcid.security  = 0;
 
-	devi.pkt_type = 0;
-	devi.scan = SCAN_PAGE | SCAN_INQUIRY;
-	devi.auth = 0;
-	devi.encrypt = 0;
+	init_device_defaults(&default_device);
+}
+
+struct device_opts *allocate_device_opts(char *ref)
+{
+	struct device_list *device;
+	
+	device = malloc(sizeof(struct device_list));
+	if (!device)
+	{
+		syslog(LOG_INFO, "Can't allocate devlist opts buffer. %s(%d)", 
+			strerror(errno), errno);
+		exit(1);
+	}
+	
+	device->ref = ref;
+	device->next = device_list;
+	device_list = device;
+
+	init_device_defaults(&device->opts);
+	return &device->opts;
+}
+
+void free_device_opts(void)
+{
+	struct device_list *device, *next;
+
+	if(default_device.name)
+	{
+		free(default_device.name);
+		default_device.name = 0;
+	}
+	
+	for (device = device_list; device; device = next) {
+		free(device->ref);
+		if(device->opts.name)
+			free(device->opts.name);
+		next = device->next;
+		free(device);
+	}
+	device_list = 0;
 }
 
 static void sig_usr1(int sig)
@@ -467,6 +567,8 @@
 	/* Start event processor */
 	g_main_run(event_loop);
 
+	free_device_opts();
+	
 	syslog(LOG_INFO, "Exit.");
 	return 0;
 }
diff -Naur bluez-utils-2.4.orig/hcid/parser.y bluez-utils-2.4/hcid/parser.y
--- bluez-utils-2.4.orig/hcid/parser.y	2002-08-20 20:42:12.000000000 +0200
+++ bluez-utils-2.4/hcid/parser.y	2004-01-29 20:31:18.000000000 +0100
@@ -61,18 +61,18 @@
 %token K_PINHELP
 %token K_YES K_NO
 
-%token <str> WORD PATH STRING LIST
+%token <str> WORD PATH STRING LIST HCI BDADDR
 %token <num> NUM
 
 %type  <num> bool pkt_type link_mode link_policy sec_mode pair_mode
-%type  <str> dev_name
+%type  <str> dev_name hci bdaddr
 
 %%
 config: statement | config statement;
 statement: 
   K_OPTIONS hcid_options
  
-  | K_DEVICE device_options
+  | device device_options
 
   | WORD	{
 			cfg_error("Invalid statement '%s'", $1);
@@ -82,6 +82,20 @@
 		}
   ;
 
+device:
+    K_DEVICE		{
+				parser_device = &default_device;
+			}
+    
+    | K_DEVICE hci	{
+				parser_device = allocate_device_opts($2);
+			}
+    
+    | K_DEVICE bdaddr	{
+				parser_device = allocate_device_opts($2);
+			}
+    ;
+
 hcid_options: '{' hcid_opts '}';
 hcid_opts: | hcid_opt ';' | error ';' | hcid_opts hcid_opt ';';
 hcid_opt: 
@@ -137,47 +151,47 @@
 device_opts: | device_opt ';' | error ';' | device_opts device_opt ';';
 device_opt:
   K_PTYPE pkt_type	{
-				devi.pkt_type = $2;
+				parser_device->pkt_type = $2;
 			}
 
   | K_LM link_mode	{
-				devi.link_mode = $2;
+				parser_device->link_mode = $2;
 			}
 
   | K_LP link_policy	{
-				devi.link_policy = $2;
+				parser_device->link_policy = $2;
 			}
 
   | K_NAME dev_name	{  
-				if (devi.name)
-					free(devi.name);
-				devi.name = $2;
+				if (parser_device->name)
+					free(parser_device->name);
+				parser_device->name = $2;
 			}
 
   | K_CLASS NUM		{
-				devi.class = $2;
+				parser_device->class = $2;
 			}
 
   | K_AUTH bool		{
-				devi.auth = $2;
+				parser_device->auth = $2;
 			}
 
   | K_ENCRYPT bool	{
-				devi.encrypt = $2;
+				parser_device->encrypt = $2;
 			}
 
   | K_ISCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_INQUIRY;
+					parser_device->scan |=  SCAN_INQUIRY;
 				else
-					devi.scan &= ~SCAN_INQUIRY;
+					parser_device->scan &= ~SCAN_INQUIRY;
 			}
 
   | K_PSCAN bool	{
 				if ($2)
-					devi.scan |=  SCAN_PAGE;
+					parser_device->scan |=  SCAN_PAGE;
 				else
-					devi.scan &= ~SCAN_PAGE;
+					parser_device->scan &= ~SCAN_PAGE;
 			}
 
   | WORD		{
@@ -196,6 +210,18 @@
 		}
   ;
 
+hci:
+  HCI		{  
+			$$ = strdup($1);
+		}
+  ;
+
+bdaddr:
+  BDADDR	{  
+			$$ = strdup($1);
+		}
+  ;
+
 pkt_type:
   WORD 	 	{
 			int opt;
@@ -274,6 +300,8 @@
 {
 	extern FILE *yyin;
 
+	free_device_opts();
+	
 	if( !(yyin = fopen(file,"r")) ){
 		syslog(LOG_ERR,"Can not open %s", file);
 		return -1;      

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-29 19:58     ` Fredrik Noring
@ 2004-01-31 15:30       ` Marcel Holtmann
  2004-01-31 15:49         ` Fredrik Noring
  0 siblings, 1 reply; 17+ messages in thread
From: Marcel Holtmann @ 2004-01-31 15:30 UTC (permalink / raw)
  To: Fredrik Noring; +Cc: BlueZ Mailing List, Edd Dumbill

Hi Fredrik,

> > Attached patch implements both.
> 
> The new version of the patch fixes a small memory leak.

please also incorporate my coding style comments to this patch and
resend it. I think this patch is very useful and I want to apply it.

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-31 15:30       ` Marcel Holtmann
@ 2004-01-31 15:49         ` Fredrik Noring
  2004-01-31 15:59           ` Marcel Holtmann
  0 siblings, 1 reply; 17+ messages in thread
From: Fredrik Noring @ 2004-01-31 15:49 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ Mailing List, Edd Dumbill

Hi Marcel

lör 2004-01-31 klockan 16.30 skrev Marcel Holtmann:
> please also incorporate my coding style comments to this patch and
> resend it. I think this patch is very useful and I want to apply it.

As far as I can see there is only one misplaced space and two 
misplaced '{' characters in the entire patch, on lines 93, 312
and 331 in main.c. :)

Fredrik

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-31 15:49         ` Fredrik Noring
@ 2004-01-31 15:59           ` Marcel Holtmann
  2004-01-31 16:15             ` Fredrik Noring
  0 siblings, 1 reply; 17+ messages in thread
From: Marcel Holtmann @ 2004-01-31 15:59 UTC (permalink / raw)
  To: Fredrik Noring; +Cc: BlueZ Mailing List, Edd Dumbill

Hi Fredrik,

> As far as I can see there is only one misplaced space and two 
> misplaced '{' characters in the entire patch, on lines 93, 312
> and 331 in main.c. :)

I have seen more. Also misplaced comments ;)

One other thing.

static void init_device_defaults(struct device_opts *device_opts)
{
       device_opts->name        = 0;
       device_opts->class       = 0;
       device_opts->pkt_type    = 0;
       device_opts->scan        = SCAN_PAGE | SCAN_INQUIRY;
       device_opts->link_mode   = 0;
       device_opts->link_policy = 0;
       device_opts->auth        = 0;
       device_opts->encrypt     = 0;
}

This is too much and not needed, because we can use memset().

	memset(device_opts, 0, sizeof(*device_opts));
	device_opts->scan = SCAN_PAGE | SCAN_INQUIRY;

I know one function later it is used in the same style, but I don't like
it either. And of course in this case inlining the function is a good
idea.

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-31 15:59           ` Marcel Holtmann
@ 2004-01-31 16:15             ` Fredrik Noring
  2004-01-31 18:09               ` Marcel Holtmann
  0 siblings, 1 reply; 17+ messages in thread
From: Fredrik Noring @ 2004-01-31 16:15 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: BlueZ Mailing List

lör 2004-01-31 klockan 16.59 skrev Marcel Holtmann:
> I have seen more. Also misplaced comments ;)

The "char *ref" comment in hcid.h? I understand the kernel people you
referred to before use this type of comment as well. :)

The other three comments do not refer to the if:s but the code inside
each if. So I don't think these are misplaced either.

More places? That's the only comments I know of...

> This is too much and not needed, because we can use memset().

Sure.

> And of course in this case inlining the function is a good idea.

Why is that?

Fredrik

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-31 16:15             ` Fredrik Noring
@ 2004-01-31 18:09               ` Marcel Holtmann
  0 siblings, 0 replies; 17+ messages in thread
From: Marcel Holtmann @ 2004-01-31 18:09 UTC (permalink / raw)
  To: Fredrik Noring; +Cc: BlueZ Mailing List

Hi Fredrik,

> The "char *ref" comment in hcid.h? I understand the kernel people you
> referred to before use this type of comment as well. :)

no, this comment is correct.

> The other three comments do not refer to the if:s but the code inside
> each if. So I don't think these are misplaced either.

	/* First try to get BD_ADDR based settings ... */
	di.dev_id = hdev;
	if (!ioctl(sock, HCIGETDEVINFO, (void *) &di))
		device_opts = get_bdaddr_device_opts(&di.bdaddr);

	/* ... then try HCI based settings ... */
	if (!device_opts)
		device_opts = get_hci_device_opts(hdev);

	/* ... and last use the default settings. */
	if (!device_opts)               
		device_opts = &default_device;

Make it look like this. It is much more easier to read :)

> More places? That's the only comments I know of...

Not comments. Whitespaces and braces.

> > And of course in this case inlining the function is a good idea.
> 
> Why is that?

Short code that only init a structure can be inlined.

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-29 10:38 Nosve
@ 2004-01-31 19:04 ` Marcel Holtmann
  2004-02-03 13:32   ` Fredrik Noring
  0 siblings, 1 reply; 17+ messages in thread
From: Marcel Holtmann @ 2004-01-31 19:04 UTC (permalink / raw)
  To: Nosve; +Cc: BlueZ Mailing List

Hi Nosve,

> BTW, hcid.conf with his options where is documented?

would you apply for the job of writing the hcid.conf manpage?

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
@ 2004-02-01 19:20 nosve
  2004-02-01 23:27 ` Marcel Holtmann
  0 siblings, 1 reply; 17+ messages in thread
From: nosve @ 2004-02-01 19:20 UTC (permalink / raw)
  To: marcel; +Cc: bluez-devel

>>Hi Nosve,
>>
>>> BTW, hcid.conf with his options where is documented?=

>>
>>would you apply for the job of writing the hcid.conf manpage?
>>=

>>Regards
>>
>>Marcel
>>
>>
>>

Sure, why not! I have to start f=
rom parser.c ?

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-02-01 19:20 nosve
@ 2004-02-01 23:27 ` Marcel Holtmann
  0 siblings, 0 replies; 17+ messages in thread
From: Marcel Holtmann @ 2004-02-01 23:27 UTC (permalink / raw)
  To: nosve@libero.it; +Cc: BlueZ Mailing List

Hi Nosve,

> Sure, why not! I have to start from parser.c ?

the config file format is defined by parser.y and lexer.l

Regards

Marcel




-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [Bluez-devel] [PATCH] Bluetooth address specific device configuration
  2004-01-31 19:04 ` Marcel Holtmann
@ 2004-02-03 13:32   ` Fredrik Noring
  0 siblings, 0 replies; 17+ messages in thread
From: Fredrik Noring @ 2004-02-03 13:32 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: Nosve, BlueZ Mailing List

[-- Attachment #1: Type: text/plain, Size: 220 bytes --]

Hi Nosve and Marcel

Attached is a draft for a hcid.1 man page.

The hcid.conf format is slightly changed to make it more useful
and flexible but these changes are not implemented in hcid yet.

Please comment.

Fredrik


[-- Attachment #2: hcid.1 --]
[-- Type: text/x-troff-man, Size: 4388 bytes --]

.\" 
.\" hcid manual page.
.\" Copyright (C) 2004 Fredrik Noring
.\"
.TH hcid 1
.SH NAME
hcid \- Bluetooth interface daemon
.SH SYNOPSIS
.PP
.B hcid
hcid [-f=\fIfile\fP, \-\-config-file=\fIfile\fP] [-n, --no-daemon] [\-\-version]

.SH DESCRIPTION

\fIhcid\fP is the Bluetooth interface daemon. See
http://www.bluez.org/ for more information about Bluetooth for Linux.
The main purpose of \fIhcid\fP is to automatically configure Bluetooth
interfaces (hci0, hci1 ...). \fIhcid\fP also provides Bluetooth device
pairing services.

.SH OPTIONS
The following options are supported:
.TP
\fB-f\fP=\fIfile\fP, \fB--config-file\fP=\fIfile\fP
Use the given configuration file.
.TP
\fB-n\fP, \fB--no-daemon\fP
Do not fork as a daemon.
.TP
\fB--version\fP
Print the version of the daemon.

.SH CONFIGURATION FILE

The \fIhcid\fP configuration file is located in
\fB/etc/bluetooth/hcid.conf\fP. It consists of sections and
parameters. A section begins with the name of the section followed by
optional specifiers and the parameters inside curly brackets. Sections
contain parameters of the form:

.TP
\fIname\fP \fIvalue1\fP, \fIvalue2\fP, ... ;

.PP
Any character after a hash ('#') character is ignored until newline.
Whitespace is also ignored.

.SH SECTION DESCRIPTION

Sections can be one or more \fBdevice\fP sections. The following
optional specifiers are supported:

.TP
\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP\fB:\fP\fInn\fP

Parameters specified within this section will be applied to the device
with this \fIdevice address\fP.

.TP
\fBhci\fIn\fP

Parameters specified within this section will be applied to the device
with this \fIdevice interface\fP, unless that device is matched by a
\fIdevice address\fP section.

.TP
\fBdefault\fP

Parameters specified within this section will be applied to all
devices that do not match any other device section.

.TP
\fBglobal\fP

Parameters specified within this section will be applied to all device
sections where these are unspecified.

.PP

If no specifier is provided, the parameters are applied to the
\fBdefault\fP section.

.PP

The following parameters may be present in a \fBdevice\fP section\fB:\fP

.TP
\fBautoinit\fP = yes|no

Automatically initialize new devices. The default is \fBno\fP.

.TP
\fBauth\fP = yes|no

.TP
\fBclass\fP = 0x\fIhhh\FP

.TP
\fBencrypt\fP = yes|no

.TP
\fBiscan\fP = yes|no
.TP
\fBlm\fP = none|accept,master

.TP
\fBlp\fP = none|rswitch,hold,sniff,park

.TP
\fBname\fP = "\fIname\fP"

.TP
\fBpairing\fP = none|multi|once

.TP
\fBpin_helper\fP = \fIfile\fP

.TP
\fBpkt_type\fP = DH1,DM1,HV1

.TP
\fBpscan\fP = yes|no

.TP
\fBsecurity\fP = none|auto|user

.SH EXAMPLE
Example of \fBhcid.conf\fP file:

.nf
# These parameters are applied to all device sections unless
# specified in those sections.
device global {
	# Automatically initialize new devices
	autoinit yes;

	# Local device name
	#   %d - device id
	#   %h - host name
	name "%h";

	# Security Manager mode
	#   none - Security manager disabled
	#   auto - Use local PIN for incoming connections
	#   user - Always ask user for a PIN
	security auto;

	# Pairing mode
	#   none  - Pairing disabled
	#   multi - Allow pairing with already paired devices
	#   once  - Pair once and deny successive attempts
	pairing once;

	# PIN helper
	pin_helper /bin/bluepin;

	# Local device class
	class 0x100;

	# Default packet type
	#pkt_type DH1,DM1,HV1;

	# Inquiry and Page scan
	iscan enable; pscan enable;

	# Default link mode
	#   none   - no specific policy 
	#   accept - always accept incoming connections
	#   master - become master on incoming connections,
	#            deny role switch on outgoing connections
	#
	lm accept,master;
	#
	#lm accept;

	# Default link policy
	#   none    - no specific policy
	#   rswitch - allow role switch
	#   hold    - allow hold mode
	#   sniff   - allow sniff mode
	#   park    - allow park mode
	#
	#lp hold,sniff;
	#
	lp hold,sniff,park;

	# Authentication and Encryption
	# auth enable;
	# encrypt enable;
}

# Default parameters
device {
	pairing multi;
}

# Parameters for a device with address 00:11:22:33:44:55
device 00:11:22:33:44:55 {
	encrypt enable;
}

.SH FILES
.nf
/etc/bluetooth/hcid.conf
/etc/bluetooth/keytab
/etc/bluetooth/keytab.shadow

.SH AUTHORS
Written by Fredrik Noring and Maxim Krasnyansky.

.SH BUGS
Please send bug reports to <bluez-devel@bluez.org>.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2004-02-03 13:32 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-28 18:56 [Bluez-devel] [PATCH] Bluetooth address specific device configuration Fredrik Noring
2004-01-28 19:24 ` Fredrik Noring
2004-01-28 23:16   ` Achim Bohnet
2004-01-29 18:29     ` Fredrik Noring
2004-01-29  5:52 ` Marcel Holtmann
2004-01-29 19:39   ` Fredrik Noring
2004-01-29 19:58     ` Fredrik Noring
2004-01-31 15:30       ` Marcel Holtmann
2004-01-31 15:49         ` Fredrik Noring
2004-01-31 15:59           ` Marcel Holtmann
2004-01-31 16:15             ` Fredrik Noring
2004-01-31 18:09               ` Marcel Holtmann
  -- strict thread matches above, loose matches on Subject: below --
2004-01-29 10:38 Nosve
2004-01-31 19:04 ` Marcel Holtmann
2004-02-03 13:32   ` Fredrik Noring
2004-02-01 19:20 nosve
2004-02-01 23:27 ` Marcel Holtmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.