Move adapter config file to ini-file format
v2 cover Move adapter config file to ini-file format
Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/settings in ini-file format for BlueZ 5.
If this file does not exist, we try to convert legacy config file to it.
Access to variables during run-time is performed in adapter structure which is populated by loading saved configuration during initialization.
First 6 patches remove access to config file from run-time. Last patch move to ini-file format style (load, save and convert).
Frédéric Danis (7):
adapter: Read name in storage at init
adapter: Read device class in storage at init
adapter: Move pairable read to load_config()
adapter: Read pairable timeout in storage at init
adapter: Read discoverable timeout in storage at init
adapter: Read mode in storage at init
adapter: Move saved config to ini-file format
TODO | 6 + plugins/adaptername.c | 9 +- src/adapter.c | 330 ++++++++++++++++++++++++++++++++++++++----------- src/adapter.h | 1 + 4 files changed, 268 insertions(+), 78 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/7 adapter: Read name in storage at init
--- plugins/adaptername.c | 9 ++++++--- src/adapter.c | 34 ++++++++++++++++++++++++++++++++++ src/adapter.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-)
plugins/adaptername.c +6 -3
@@ -198,7 +198,8 @@ static void set_pretty_name(struct btd_adapter *adapter,static int adaptername_probe (struct btd_adapter *adapter) {int current_id; -char name[MAX_NAME_LENGTH +1 ]; +char *name; +char str[MAX_NAME_LENGTH +1 ];char *pretty_hostname; pretty_hostname =read_pretty_host_name ();
@@ -211,8 +212,10 @@ static int adaptername_probe(struct btd_adapter *adapter)adapter_set_allow_name_changes (adapter, TRUE); current_id =adapter_get_dev_id (adapter); -if (read_local_name (adapter_get_address (adapter), name) <0 ) -expand_name (name,MAX_NAME_LENGTH , main_opts.name, current_id); +if (adapter_get_config_name (adapter, &name) <0 ) { +expand_name (str,MAX_NAME_LENGTH , main_opts.name, current_id); + name = str; + }DBG ("Setting name '%s' for device 'hci%d'" , name, current_id);adapter_set_name (adapter, name);
src/adapter.c +34 -0
@@ -115,6 +115,10 @@ struct service_auth {struct agent *agent;/* NULL for queued auths */ }; +struct btd_adapter_config { +char *name; +}; +struct btd_adapter {uint16_t dev_id;gboolean up;
@@ -155,6 +159,8 @@ struct btd_adapter {gboolean pairable;/* pairable state */ gboolean initialized; +struct btd_adapter_config config; +gboolean off_requested;/* DEVDOWN ioctl was called */ gint ref;
@@ -780,11 +786,24 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name) adapter->name =g_strdup (maxname); } +g_free (adapter->config.name); + adapter->config.name =g_strdup (maxname); +write_local_name (&adapter->bdaddr, maxname);return 0 ; } +int adapter_get_config_name (struct btd_adapter *adapter,char **name) +{ +if (adapter->config.name ==NULL ) +return -EINVAL ; + + *name = adapter->config.name; + +return 0 ; +} +static void set_name (struct btd_adapter *adapter,const char *name,GDBusPendingPropertySet id) {
@@ -2665,6 +2684,18 @@ void btd_adapter_unref(struct btd_adapter *adapter)g_free (path); } +static void load_config (struct btd_adapter *adapter) +{ +char name[MAX_NAME_LENGTH +1 ]; + +/* Get name */ +if (read_local_name (&adapter->bdaddr, name) <0 ) + adapter->config.name =NULL ; +else + adapter->config.name =g_strdup (name); + +} +gboolean adapter_init (struct btd_adapter *adapter,gboolean up) { adapter->up = up;
@@ -2684,6 +2715,7 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)if (main_opts.gatt_enabled)btd_adapter_gatt_server_start (adapter); +load_config (adapter);load_drivers (adapter);btd_profile_foreach (probe_profile, adapter);clear_blocked (adapter);
@@ -2752,6 +2784,8 @@ void adapter_remove(struct btd_adapter *adapter)/* Return adapter to down state if it was not up on init */ if (!adapter->already_up && adapter->up)mgmt_set_powered (adapter->dev_id, FALSE); + +g_free (adapter->config.name); }uint16_t adapter_get_dev_id (struct btd_adapter *adapter)
src/adapter.h +1 -0
@@ -133,6 +133,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter,void adapter_emit_device_found (struct btd_adapter *adapter,struct remote_dev_info *dev);void adapter_mode_changed (struct btd_adapter *adapter,uint8_t scan_mode); +int adapter_get_config_name (struct btd_adapter *adapter,char **name);int adapter_set_name (struct btd_adapter *adapter,const char *name);void adapter_name_changed (struct btd_adapter *adapter,const char *name);void adapter_service_insert (struct btd_adapter *adapter,void *rec);
Signature · 1 line
1.7.9.5
PATCH v2 2/7 adapter: Read device class in storage at init
In reply to Frédéric Danis--- src/adapter.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
src/adapter.c +12 -9
@@ -117,6 +117,7 @@ struct service_auth {struct btd_adapter_config {char *name; +uint8_t class[3 ]; };struct btd_adapter {
@@ -729,6 +730,10 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)if (class == adapter->dev_class)return ; + adapter->config.class[0 ] = new_class[0 ]; + adapter->config.class[1 ] = new_class[1 ]; + adapter->config.class[2 ] = new_class[2 ]; +write_local_class (&adapter->bdaddr, new_class); adapter->dev_class = class;
@@ -2353,15 +2358,8 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,void btd_adapter_read_class (struct btd_adapter *adapter,uint8_t *major,uint8_t *minor) { -uint8_t cls[3 ]; - -if (read_local_class (&adapter->bdaddr, cls) <0 ) { -uint32_t class =htobl (main_opts.class); -memcpy (cls, &class,3 ); - } - - *major = cls[1 ]; - *minor = cls[0 ]; + *major = adapter->config.class[1 ]; + *minor = adapter->config.class[0 ]; }uint32_t btd_adapter_get_class (struct btd_adapter *adapter)
@@ -2694,6 +2692,11 @@ static void load_config(struct btd_adapter *adapter)else adapter->config.name =g_strdup (name); +/* Get class */ +if (read_local_class (&adapter->bdaddr, adapter->config.class) <0 ) { +uint32_t class =htobl (main_opts.class); +memcpy (adapter->config.class, &class,3 ); + } }gboolean adapter_init (struct btd_adapter *adapter,gboolean up)
Signature · 1 line
1.7.9.5
PATCH v2 3/7 adapter: Move pairable read to load_config()
In reply to Frédéric Danis--- src/adapter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
src/adapter.c +4 -4
@@ -2697,6 +2697,10 @@ static void load_config(struct btd_adapter *adapter)uint32_t class =htobl (main_opts.class);memcpy (adapter->config.class, &class,3 ); } + +/* Get pairable mode */ +if (read_device_pairable (&adapter->bdaddr, &adapter->pairable) <0 ) + adapter->pairable = TRUE; }gboolean adapter_init (struct btd_adapter *adapter,gboolean up)
@@ -2724,10 +2728,6 @@ gboolean adapter_init(struct btd_adapter *adapter, gboolean up)clear_blocked (adapter);load_devices (adapter); -/* Set pairable mode */ -if (read_device_pairable (&adapter->bdaddr, &adapter->pairable) <0 ) - adapter->pairable = TRUE; -/* retrieve the active connections: address the scenario where * the are active connections before the daemon've started */ load_connections (adapter);
Signature · 1 line
1.7.9.5
PATCH v2 4/7 adapter: Read pairable timeout in storage at init
In reply to Frédéric Danis--- src/adapter.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
src/adapter.c +10 -11
@@ -2278,16 +2278,6 @@ static int get_discoverable_timeout(const char *src)return main_opts.discovto; } -static int get_pairable_timeout (const char *src) -{ -int timeout; - -if (read_pairable_timeout (src, &timeout) ==0 ) -return timeout; - -return main_opts.pairto; -} -static void set_auto_connect (gpointer data,gpointer user_data) {struct btd_device *device = data;
@@ -2432,7 +2422,6 @@ void btd_adapter_start(struct btd_adapter *adapter) adapter->off_requested = FALSE; adapter->up = TRUE; adapter->discov_timeout =get_discoverable_timeout (address); - adapter->pairable_timeout =get_pairable_timeout (address); adapter->off_timer =0 ;if (adapter->scan_mode &SCAN_INQUIRY )
@@ -2685,6 +2674,10 @@ void btd_adapter_unref(struct btd_adapter *adapter)static void load_config (struct btd_adapter *adapter) {char name[MAX_NAME_LENGTH +1 ]; +char address[18 ]; +int timeout; + +ba2str (&adapter->bdaddr, address);/* Get name */ if (read_local_name (&adapter->bdaddr, name) <0 )
@@ -2701,6 +2694,12 @@ static void load_config(struct btd_adapter *adapter)/* Get pairable mode */ if (read_device_pairable (&adapter->bdaddr, &adapter->pairable) <0 ) adapter->pairable = TRUE; + +/* Get pairable timeout */ +if (read_pairable_timeout (address, &timeout) <0 ) + adapter->pairable_timeout = main_opts.pairto; +else + adapter->pairable_timeout = timeout; }gboolean adapter_init (struct btd_adapter *adapter,gboolean up)
Signature · 1 line
1.7.9.5
PATCH v2 5/7 adapter: Read discoverable timeout in storage at init
In reply to Frédéric Danis--- src/adapter.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
src/adapter.c +7 -12
@@ -2268,16 +2268,6 @@ static void load_connections(struct btd_adapter *adapter)g_slist_free_full (conns, g_free); } -static int get_discoverable_timeout (const char *src) -{ -int timeout; - -if (read_discoverable_timeout (src, &timeout) ==0 ) -return timeout; - -return main_opts.discovto; -} -static void set_auto_connect (gpointer data,gpointer user_data) {struct btd_device *device = data;
@@ -2339,7 +2329,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode, *on_mode =get_mode (&adapter->bdaddr,"on" );if (discoverable_timeout) - *discoverable_timeout =get_discoverable_timeout (address); + *discoverable_timeout = adapter->discov_timeout;if (pairable) *pairable = adapter->pairable;
@@ -2421,7 +2411,6 @@ void btd_adapter_start(struct btd_adapter *adapter) adapter->dev_class =0 ; adapter->off_requested = FALSE; adapter->up = TRUE; - adapter->discov_timeout =get_discoverable_timeout (address); adapter->off_timer =0 ;if (adapter->scan_mode &SCAN_INQUIRY )
@@ -2700,6 +2689,12 @@ static void load_config(struct btd_adapter *adapter) adapter->pairable_timeout = main_opts.pairto; else adapter->pairable_timeout = timeout; + +/* Get discoverable timeout */ +if (read_discoverable_timeout (address, &timeout) <0 ) + adapter->discov_timeout = main_opts.discovto; +else + adapter->discov_timeout = timeout; }gboolean adapter_init (struct btd_adapter *adapter,gboolean up)
Signature · 1 line
1.7.9.5
PATCH v2 6/7 adapter: Read mode in storage at init
In reply to Frédéric Danis--- src/adapter.c | 61 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 34 insertions(+), 27 deletions(-)
src/adapter.c +34 -27
@@ -118,6 +118,8 @@ struct service_auth {struct btd_adapter_config {char *name;uint8_t class[3 ]; +uint8_t mode; +uint8_t on_mode; };struct btd_adapter {
@@ -210,7 +212,7 @@ static const char *mode2str(uint8_t mode) } } -static uint8_t get_mode (const bdaddr_t *bdaddr,const char *mode) +static uint8_t get_mode (const char *mode) {if (strcasecmp ("off" , mode) ==0 )return MODE_OFF ;
@@ -218,15 +220,7 @@ static uint8_t get_mode(const bdaddr_t *bdaddr, const char *mode)return MODE_CONNECTABLE ; else if (strcasecmp("discoverable", mode) == 0)return MODE_DISCOVERABLE ; - else if (strcasecmp("on", mode) == 0) { -char onmode[14 ], srcaddr[18 ]; - -ba2str (bdaddr, srcaddr); -if (read_on_mode (srcaddr, onmode,sizeof (onmode)) <0 ) -return MODE_CONNECTABLE ; - -return get_mode (bdaddr, onmode); - } else + else return MODE_UNKNOWN; }
@@ -331,6 +325,10 @@ static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)return err; done: + adapter->config.mode = new_mode; +if (new_mode !=MODE_OFF ) + adapter->config.on_mode = new_mode; + modestr =mode2str (new_mode);write_device_mode (&adapter->bdaddr, modestr);
@@ -390,7 +388,7 @@ static void set_powered(struct btd_adapter *adapter, gboolean powered,int err;if (powered) { - mode =get_mode (&adapter->bdaddr,"on" ); + mode = adapter->config.on_mode;return set_discoverable (adapter, mode ==MODE_DISCOVERABLE , id); }
@@ -1403,7 +1401,7 @@ static DBusMessage *request_session(DBusConnection *conn,if (!adapter->mode_sessions) adapter->global_mode = adapter->mode; - new_mode =get_mode (&adapter->bdaddr,"on" ); + new_mode = adapter->config.on_mode; req =find_session (adapter->mode_sessions, sender);if (req) {
@@ -2312,21 +2310,15 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,uint16_t *discoverable_timeout, gboolean *pairable) { - char str[14], address[18]; + char address[18];ba2str (&adapter->bdaddr, address); -if (mode) { -if (main_opts.remember_powered == FALSE) - *mode = main_opts.mode; -else if (read_device_mode (address, str,sizeof (str)) ==0 ) - *mode =get_mode (&adapter->bdaddr, str); -else - *mode = main_opts.mode; - } +if (mode) + *mode = adapter->config.mode;if (on_mode) - *on_mode =get_mode (&adapter->bdaddr,"on" ); + *on_mode = adapter->config.on_mode;if (discoverable_timeout) *discoverable_timeout = adapter->discov_timeout;
@@ -2490,6 +2482,10 @@ static void set_mode_complete(struct btd_adapter *adapter)const char *modestr;int err; + adapter->config.mode = adapter->mode; +if (adapter->mode !=MODE_OFF ) + adapter->config.on_mode = adapter->mode; + modestr =mode2str (adapter->mode);write_device_mode (&adapter->bdaddr, modestr);
@@ -2664,6 +2660,7 @@ static void load_config(struct btd_adapter *adapter) {char name[MAX_NAME_LENGTH +1 ];char address[18 ]; +char mode[14 ];int timeout;ba2str (&adapter->bdaddr, address);
@@ -2695,6 +2692,20 @@ static void load_config(struct btd_adapter *adapter) adapter->discov_timeout = main_opts.discovto; else adapter->discov_timeout = timeout; + +/* Get mode */ +if (main_opts.remember_powered == FALSE) + adapter->config.mode = main_opts.mode; +else if (read_device_mode (address, mode,sizeof (mode)) ==0 ) + adapter->config.mode =get_mode (mode); +else + adapter->config.mode = main_opts.mode; + +/* Get on mode */ +if (read_on_mode (address, mode,sizeof (mode)) ==0 ) + adapter->config.on_mode =get_mode (mode); +else + adapter->config.on_mode =MODE_CONNECTABLE ; }gboolean adapter_init (struct btd_adapter *adapter,gboolean up)
@@ -3601,17 +3612,13 @@ gboolean adapter_powering_down(struct btd_adapter *adapter)int btd_adapter_restore_powered (struct btd_adapter *adapter) { -char mode[14 ], address[18 ]; -if (!main_opts.remember_powered)return -EINVAL ;if (adapter->up)return 0 ; -ba2str (&adapter->bdaddr, address); -if (read_device_mode (address, mode,sizeof (mode)) ==0 && -g_str_equal (mode,"off" )) +if (adapter->config.mode ==MODE_OFF )return 0 ;return mgmt_set_powered (adapter->dev_id, TRUE);
Signature · 1 line
1.7.9.5
PATCH v2 7/7 adapter: Move saved config to ini-file format
In reply to Frédéric DanisRead and write config file in ini-file format.
If the file can not be loaded, try to convert legacy configuration.
--- TODO | 6 ++ src/adapter.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 180 insertions(+), 32 deletions(-)
TODO +6 -0
@@ -30,6 +30,12 @@ General Priority: Low Complexity: C1 +- Function in src/adapter.c to convert old storage files to new ini-file format + should be removed 6-8 months after first BlueZ 5 release. + + Priority: Low + Complexity: C1 + BlueZ 5 =======
src/adapter.c +174 -32
317 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Marcel Holtmann
maintainerRe: [PATCH v2 1/7] adapter: Read name in storage at init
In reply to Frédéric DanisHi Fred,
Quoted 5 lines
--- plugins/adaptername.c | 9 ++++++--- src/adapter.c | 34 ++++++++++++++++++++++++++++++++++ src/adapter.h | 1 + 3 files changed, 41 insertions(+), 3 deletions(-)
split this into two, one for the core, one for the plugin.
Regards
Marcel
Marcel Holtmann
maintainerRe: [PATCH v2 7/7] adapter: Move saved config to ini-file format
In reply to Frédéric DanisHi Fred,
Quoted 6 lines
Read and write config file in ini-file format.
If the file can not be loaded, try to convert legacy configuration.--- TODO | 6 ++ src/adapter.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 180 insertions(+), 32 deletions(-)
split these also into two, one for the core and one for the TODO file.
Regards
Marcel
Marcel Holtmann
maintainerHi Fred,
Quoted 8 lines
Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/settings in ini-file format for BlueZ 5.
If this file does not exist, we try to convert legacy config file to it.Access to variables during run-time is performed in adapter structure which is populated by loading saved configuration during initialization.
First 6 patches remove access to config file from run-time. Last patch move to ini-file format style (load, save and convert).
I am fine with the first 6 patches (7 in the end). Lets have Johan a second look at it.
For the actual change to the new format, can you first create a document describing the new format. Something like doc/settings-storage.txt or similar (if anyone can think of a better name).
Regards
Marcel
Hi Marcel,
Quoted 3 lines · Marcel Holtmann
For the actual change to the new format, can you first create a document describing the new format. Something like
doc/settings-storage.txtor similar (if anyone can think of a better name).
Would be interesting to update ./src/bluetoothd.8.in as well, or simply drop the description for config storage files?
Regards,
Signature · 3 lines
Anderson Lizardo Instituto Nokia de Tecnologia - INdT Manaus - Brazil
Hi,
Quoted 9 lines · On Wednesday 10 of October 2012 13:37:33 Anderson Lizardo wrote:
Hi Marcel,
Quoted 3 lines · Marcel Holtmann
For the actual change to the new format, can you first create a document describing the new format. Something like
doc/settings-storage.txtor similar (if anyone can think of a better name).Would be interesting to update ./src/bluetoothd.8.in as well, or simply drop the description for config storage files?
I don't think man page should contain such information as description of data stored by bluetoothd. This is a private daemon data that is not suppose to be modified by hand.
Instead, it should contain comprehensive information about configuration files located in /etc/bluetooth and note about location and purpose of data files. (opposite to what is now in bluetoothd manual..)
By comprehensive I mean not necessarily full description of every option possible (this could be located in separate manual or in example config files as it is now) but clear description of what each file is responsible for, when and how it is parsed etc.
Signature · 2 lines
BR Szymon Janc
Hi Marcel,
Quoted 11 lines · Marcel Holtmann
Quoted 8 lines
Adapter saved configuration will be saved to /var/lib/bluetooth/<adapter address>/settings in ini-file format for BlueZ 5.
If this file does not exist, we try to convert legacy config file to it.Access to variables during run-time is performed in adapter structure which is populated by loading saved configuration during initialization.
First 6 patches remove access to config file from run-time. Last patch move to ini-file format style (load, save and convert).
I am fine with the first 6 patches (7 in the end). Lets have Johan a second look at it.
Looks all pretty good to me.
Johan