* [PATCH BlueZ 2/6] attrib: Remove all the usages of ATT_MAX_MTU
From: Vinicius Costa Gomes @ 2012-10-10 23:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
In-Reply-To: <1349912103-663-1-git-send-email-vinicius.gomes@openbossa.org>
This "define" was bogus for two reasons: 1. There's no concept
of maximum MTU in the ATT level; 2. It was used as a maximum attribute
value length.
---
attrib/gatttool.c | 2 +-
attrib/interactive.c | 2 +-
profiles/alert/server.c | 11 ++++++-----
src/attrib-server.c | 3 ++-
4 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/attrib/gatttool.c b/attrib/gatttool.c
index 16cce0c..252064d 100644
--- a/attrib/gatttool.c
+++ b/attrib/gatttool.c
@@ -227,7 +227,7 @@ static gboolean characteristics(gpointer user_data)
static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[plen];
ssize_t vlen;
int i;
diff --git a/attrib/interactive.c b/attrib/interactive.c
index b41a7bb..716e675 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -309,7 +309,7 @@ static void char_desc_cb(guint8 status, const guint8 *pdu, guint16 plen,
static void char_read_cb(guint8 status, const guint8 *pdu, guint16 plen,
gpointer user_data)
{
- uint8_t value[ATT_MAX_MTU];
+ uint8_t value[plen];
ssize_t vlen;
int i;
diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index 77de704..761a24b 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -353,24 +353,25 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
struct notify_data *nd = cb->notify_data;
enum notify_type type = nd->type;
struct alert_adapter *al_adapter = nd->al_adapter;
- uint8_t pdu[ATT_MAX_MTU];
- size_t len = 0;
+ size_t len;
+ uint8_t *pdu = g_attrib_get_buffer(attrib, &len);
+
switch (type) {
case NOTIFY_RINGER_SETTING:
len = enc_notification(al_adapter->hnd_value[type],
&ringer_setting, sizeof(ringer_setting),
- pdu, sizeof(pdu));
+ pdu, len);
break;
case NOTIFY_ALERT_STATUS:
len = enc_notification(al_adapter->hnd_value[type],
&alert_status, sizeof(alert_status),
- pdu, sizeof(pdu));
+ pdu, len);
break;
case NOTIFY_NEW_ALERT:
case NOTIFY_UNREAD_ALERT:
len = enc_notification(al_adapter->hnd_value[type],
- nd->value, nd->len, pdu, sizeof(pdu));
+ nd->value, nd->len, pdu, len);
break;
default:
DBG("Unknown type, could not send notification");
diff --git a/src/attrib-server.c b/src/attrib-server.c
index 76a32af..ec4ecc3 100644
--- a/src/attrib-server.c
+++ b/src/attrib-server.c
@@ -907,11 +907,12 @@ static void channel_handler(const uint8_t *ipdu, uint16_t len,
gpointer user_data)
{
struct gatt_channel *channel = user_data;
- uint8_t opdu[channel->mtu], value[ATT_MAX_MTU];
+ uint8_t opdu[channel->mtu];
uint16_t length, start, end, mtu, offset;
bt_uuid_t uuid;
uint8_t status = 0;
size_t vlen;
+ uint8_t *value = g_attrib_get_buffer(channel->attrib, &vlen);
DBG("op 0x%02x", ipdu[0]);
--
1.7.12.3
^ permalink raw reply related
* [PATCH BlueZ 1/6] gattrib: Fix ignoring the error message when write fails
From: Vinicius Costa Gomes @ 2012-10-10 23:34 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Vinicius Costa Gomes
If an error happens during writing to the socket, we should complain
that it failed.
---
attrib/gattrib.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/attrib/gattrib.c b/attrib/gattrib.c
index 6f6942f..0806101 100644
--- a/attrib/gattrib.c
+++ b/attrib/gattrib.c
@@ -313,8 +313,14 @@ static gboolean can_write_data(GIOChannel *io, GIOCondition cond,
iostat = g_io_channel_write_chars(io, (gchar *) cmd->pdu, cmd->len,
&len, &gerr);
- if (iostat != G_IO_STATUS_NORMAL)
+ if (iostat != G_IO_STATUS_NORMAL) {
+ if (gerr) {
+ error("%s", gerr->message);
+ g_error_free(gerr);
+ }
+
return FALSE;
+ }
if (cmd->expected == 0) {
g_queue_pop_head(queue);
--
1.7.12.3
^ permalink raw reply related
* Problem pairing wiimote device via bluetooth
From: Jebb Stewart @ 2012-10-10 22:34 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <CAA5m=uDQaKsBLnA1iFnU1TaA-pqUb4pAsmK9jWtMkhT9AWB25Q@mail.gmail.com>
I have an issue where I receive a kernel panic/trace messages if I
re-pair a wiimote immediately after turning the wiimote off. Whatever
is causing this problem also disables bluetooth on my system and
requires a system reboot to regain functionality.
Normally if you turn off the wiimote, eventually the /sys/devices/
.... /bluetooth/hci0/hci0:xx directory will disappear after some time.
However if you immediately re-pair the wiimote before this directory
is removed you receive the kernel trace message and bluetooth enters a
stuck state. I cannot restart the bluetooth daemon once I encounter
this problem. A system reboot is required to use a wiimote again.
The wiimote was originally paired with my Ubuntu system using the red
sync button on the back. I usually just hit the A button to activate
and re-pair the wiimote. I am running Ubuntu 12.04 64bit with
3.3.6-030306-generic kernel. I do see same problem with the default
3.2.0-29-generic kernel as well. I see similar issues if I try to pair
two different wiimotes at the same time.
Output from the syslog is below, any ideas or hints would be appreciated?
Re-pairing wiimote:
Oct 10 15:37:04 milhouse kernel: [515242.335386] wiimote
0005:057E:0306.0016: Device removed
Oct 10 15:37:06 milhouse kernel: [515244.336046] power_supply
wiimote_battery: driver failed to report `capacity' property: -5
Oct 10 15:37:09 milhouse kernel: [515247.013332] ------------[ cut
here ]------------
Oct 10 15:37:09 milhouse kernel: [515247.013341] WARNING: at
/home/apw/COD/linux/fs/sysfs/dir.c:481 sysfs_add_one+0xc1/0xf0()
Oct 10 15:37:09 milhouse kernel: [515247.013344] Hardware name:
Precision WorkStation T3400
Oct 10 15:37:09 milhouse kernel: [515247.013346] sysfs: cannot create
duplicate filename
'/devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.0/bluetooth/hci0/hci0:11'
Oct 10 15:37:09 milhouse kernel: [515247.013348] Modules linked in:
ipt_MASQUERADE iptable_filter iptable_nat nf_nat nf_conntrack_ipv4
nf_conntrack nf_defrag_ipv4 ip_tables x_tables bridge stp hidp rfcomm
snd_hda_codec_analog bnep nfsd nfs lockd fscache auth_rpcgss nfs_acl
sunrpc snd_hda_intel snd_hda_codec snd_hwdep snd_pcm snd_seq_midi
snd_rawmidi snd_seq_midi_event snd_seq snd_timer snd_seq_device
nvidia(PO) snd option usb_wwan usbserial soundcore joydev hid_wiimote
x38_edac ff_memless snd_page_alloc btusb bluetooth psmouse mac_hid
dcdbas edac_core ppdev serio_raw parport_pc lp parport usbhid hid tg3
Oct 10 15:37:09 milhouse kernel: [515247.013395] Pid: 8876, comm:
kworker/u:0 Tainted: P O 3.3.6-030306-generic #201205121335
Oct 10 15:37:09 milhouse kernel: [515247.013397] Call Trace:
Oct 10 15:37:09 milhouse kernel: [515247.013403] []
warn_slowpath_common+0x7f/0xc0
Oct 10 15:37:09 milhouse kernel: [515247.013405] [] warn_slowpath_fmt+0x46/0x50
Oct 10 15:37:09 milhouse kernel: [515247.013408] [] sysfs_add_one+0xc1/0xf0
Oct 10 15:37:09 milhouse kernel: [515247.013411] [] create_dir+0x81/0xd0
Oct 10 15:37:09 milhouse kernel: [515247.013413] [] sysfs_create_dir+0x7d/0xd0
Oct 10 15:37:09 milhouse kernel: [515247.013418] []
kobject_add_internal+0xb7/0x200
Oct 10 15:37:09 milhouse kernel: [515247.013420] [] kobject_add_varg+0x38/0x60
Oct 10 15:37:09 milhouse kernel: [515247.013422] [] kobject_add+0x44/0x70
Oct 10 15:37:09 milhouse kernel: [515247.013426] [] ?
kmem_cache_alloc_trace+0xc4/0x120
Oct 10 15:37:09 milhouse kernel: [515247.013430] [] device_add+0xd0/0x520
Oct 10 15:37:09 milhouse kernel: [515247.013432] [] ?
device_private_init+0x5b/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013441] []
hci_conn_add_sysfs+0x4f/0xe0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013447] []
hci_event_packet+0x18f2/0x2510 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013451] [] ?
default_wake_function+0x12/0x20
Oct 10 15:37:09 milhouse kernel: [515247.013454] [] ? pollwake+0x56/0x60
Oct 10 15:37:09 milhouse kernel: [515247.013456] [] ? try_to_wake_up+0x2d0/0x2d0
Oct 10 15:37:09 milhouse kernel: [515247.013459] [] ? __wake_up_common+0x59/0x90
Oct 10 15:37:09 milhouse kernel: [515247.013462] [] ?
__wake_up_sync_key+0x5e/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013465] [] ?
sock_def_readable+0x3e/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013468] [] ?
sock_queue_rcv_skb+0x140/0x1d0
Oct 10 15:37:09 milhouse kernel: [515247.013474] [] ?
hci_send_to_sock+0xed/0x1d0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013480] []
hci_rx_work+0x253/0x2c0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013483] [] ?
finish_task_switch+0x53/0x100
Oct 10 15:37:09 milhouse kernel: [515247.013486] [] ? __schedule+0x3e9/0x700
Oct 10 15:37:09 milhouse kernel: [515247.013492] [] ?
hci_cmd_work+0x110/0x110 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013495] [] process_one_work+0x12b/0x470
Oct 10 15:37:09 milhouse kernel: [515247.013498] [] worker_thread+0x176/0x420
Oct 10 15:37:09 milhouse kernel: [515247.013501] [] ? manage_workers+0x120/0x120
Oct 10 15:37:09 milhouse kernel: [515247.013504] [] kthread+0x9e/0xb0
Oct 10 15:37:09 milhouse kernel: [515247.013507] []
kernel_thread_helper+0x4/0x10
Oct 10 15:37:09 milhouse kernel: [515247.013509] [] ?
kthread_freezable_should_stop+0x70/0x70
Oct 10 15:37:09 milhouse kernel: [515247.013511] [] ? gs_change+0x13/0x13
Oct 10 15:37:09 milhouse kernel: [515247.013513] ---[ end trace
7d71005368e8477a ]---
Oct 10 15:37:09 milhouse kernel: [515247.013516] kobject_add_internal
failed for hci0:11 with -EEXIST, don't try to register things with the
same name in the same directory.
Oct 10 15:37:09 milhouse kernel: [515247.013519] Pid: 8876, comm:
kworker/u:0 Tainted: P W O 3.3.6-030306-generic #201205121335
Oct 10 15:37:09 milhouse kernel: [515247.013521] Call Trace:
Oct 10 15:37:09 milhouse kernel: [515247.013524] []
kobject_add_internal+0x15d/0x200
Oct 10 15:37:09 milhouse kernel: [515247.013526] [] kobject_add_varg+0x38/0x60
Oct 10 15:37:09 milhouse kernel: [515247.013528] [] kobject_add+0x44/0x70
Oct 10 15:37:09 milhouse kernel: [515247.013531] [] ?
kmem_cache_alloc_trace+0xc4/0x120
Oct 10 15:37:09 milhouse kernel: [515247.013533] [] device_add+0xd0/0x520
Oct 10 15:37:09 milhouse kernel: [515247.013535] [] ?
device_private_init+0x5b/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013541] []
hci_conn_add_sysfs+0x4f/0xe0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013547] []
hci_event_packet+0x18f2/0x2510 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013549] [] ?
default_wake_function+0x12/0x20
Oct 10 15:37:09 milhouse kernel: [515247.013551] [] ? pollwake+0x56/0x60
Oct 10 15:37:09 milhouse kernel: [515247.013553] [] ? try_to_wake_up+0x2d0/0x2d0
Oct 10 15:37:09 milhouse kernel: [515247.013556] [] ? __wake_up_common+0x59/0x90
Oct 10 15:37:09 milhouse kernel: [515247.013558] [] ?
__wake_up_sync_key+0x5e/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013560] [] ?
sock_def_readable+0x3e/0x80
Oct 10 15:37:09 milhouse kernel: [515247.013562] [] ?
sock_queue_rcv_skb+0x140/0x1d0
Oct 10 15:37:09 milhouse kernel: [515247.013568] [] ?
hci_send_to_sock+0xed/0x1d0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013574] []
hci_rx_work+0x253/0x2c0 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013576] [] ?
finish_task_switch+0x53/0x100
Oct 10 15:37:09 milhouse kernel: [515247.013578] [] ? __schedule+0x3e9/0x700
Oct 10 15:37:09 milhouse kernel: [515247.013584] [] ?
hci_cmd_work+0x110/0x110 [bluetooth]
Oct 10 15:37:09 milhouse kernel: [515247.013586] [] process_one_work+0x12b/0x470
Oct 10 15:37:09 milhouse kernel: [515247.013589] [] worker_thread+0x176/0x420
Oct 10 15:37:09 milhouse kernel: [515247.013592] [] ? manage_workers+0x120/0x120
Oct 10 15:37:09 milhouse kernel: [515247.013594] [] kthread+0x9e/0xb0
Oct 10 15:37:09 milhouse kernel: [515247.013596] []
kernel_thread_helper+0x4/0x10
Oct 10 15:37:09 milhouse kernel: [515247.013599] [] ?
kthread_freezable_should_stop+0x70/0x70
Oct 10 15:37:09 milhouse kernel: [515247.013601] [] ? gs_change+0x13/0x13
Oct 10 15:37:09 milhouse kernel: [515247.013604] Bluetooth: Failed to
register connection device
Output attempting to pair to wiimotes:
Oct 10 15:50:52 milhouse kernel: [ 302.472392] wiimote
0005:057E:0306.0005: unknown main item tag 0x0
Oct 10 15:50:52 milhouse kernel: [ 302.472636] wiimote
0005:057E:0306.0005: hidraw4: BLUETOOTH HID v3a.16 Gamepad [Nintendo
RVL-CNT-01] on 00:0A:3A:7E:3E:0A
Oct 10 15:50:52 milhouse kernel: [ 302.472676] input: Nintendo Wii
Remote Accelerometer as
/devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.0/bluetooth/hci0/hci0:12/0005:057E:0306.0005/input/input10
Oct 10 15:50:52 milhouse kernel: [ 302.474275] input: Nintendo Wii
Remote IR as /devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.0/bluetooth/hci0/hci0:12/0005:057E:0306.0005/input/input11
Oct 10 15:50:52 milhouse kernel: [ 302.474431] input: Nintendo Wii
Remote as /devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.0/bluetooth/hci0/hci0:12/0005:057E:0306.0005/input/input12
Oct 10 15:50:52 milhouse kernel: [ 302.474494] ------------[ cut here
]------------
Oct 10 15:50:52 milhouse kernel: [ 302.474501] WARNING: at
/home/apw/COD/linux/fs/sysfs/dir.c:481 sysfs_add_one+0xc1/0xf0()
Oct 10 15:50:52 milhouse kernel: [ 302.474503] Hardware name:
Precision WorkStation T3400
Oct 10 15:50:52 milhouse kernel: [ 302.474504] sysfs: cannot create
duplicate filename '/class/power_supply/wiimote_battery'
Oct 10 15:50:52 milhouse kernel: [ 302.474505] Modules linked in:
ipt_MASQUERADE iptable_filter iptable_nat nf_nat nf_conntrack_ipv4
nf_conntrack nf_defrag_ipv4 ip_tables x_tables bridge stp hidp nfsd
nfs lockd fscache auth_rpcgss bnep nfs_acl rfcomm sunrpc
snd_hda_codec_analog option usb_wwan nvidia(PO) snd_hda_intel
snd_hda_codec usbserial snd_hwdep hid_wiimote snd_pcm joydev
snd_seq_midi ff_memless ppdev psmouse snd_rawmidi snd_seq_midi_event
snd_seq snd_timer snd_seq_device snd dcdbas parport_pc mac_hid
serio_raw soundcore snd_page_alloc x38_edac edac_core btusb bluetooth
lp parport usbhid hid tg3
Oct 10 15:50:52 milhouse kernel: [ 302.474546] Pid: 850, comm:
bluetoothd Tainted: P O 3.3.6-030306-generic #201205121335
Oct 10 15:50:52 milhouse kernel: [ 302.474548] Call Trace:
Oct 10 15:50:52 milhouse kernel: [ 302.474553] [] warn_slowpath_common+0x7f/0xc0
Oct 10 15:50:52 milhouse kernel: [ 302.474556] [] warn_slowpath_fmt+0x46/0x50
Oct 10 15:50:52 milhouse kernel: [ 302.474558] [] sysfs_add_one+0xc1/0xf0
Oct 10 15:50:52 milhouse kernel: [ 302.474561] []
sysfs_do_create_link+0x13b/0x210
Oct 10 15:50:52 milhouse kernel: [ 302.474563] [] sysfs_create_link+0x13/0x20
Oct 10 15:50:52 milhouse kernel: [ 302.474567] [] device_add+0x347/0x520
Oct 10 15:50:52 milhouse kernel: [ 302.474570] []
power_supply_register+0x100/0x140
Oct 10 15:50:52 milhouse kernel: [ 302.474576] []
wiimote_hid_probe+0x1ee/0x320 [hid_wiimote]
Oct 10 15:50:52 milhouse kernel: [ 302.474582] []
hid_device_probe+0xb5/0x130 [hid]
Oct 10 15:50:52 milhouse kernel: [ 302.474586] [] really_probe+0x68/0x190
Oct 10 15:50:52 milhouse kernel: [ 302.474588] [] driver_probe_device+0x45/0x70
Oct 10 15:50:52 milhouse kernel: [ 302.474591] [] ? __driver_attach+0xa0/0xa0
Oct 10 15:50:52 milhouse kernel: [ 302.474594] [] __device_attach+0x53/0x60
Oct 10 15:50:52 milhouse kernel: [ 302.474596] [] bus_for_each_drv+0x68/0x90
Oct 10 15:50:52 milhouse kernel: [ 302.474598] [] device_attach+0xa7/0xc0
Oct 10 15:50:52 milhouse kernel: [ 302.474601] [] bus_probe_device+0x98/0xc0
Oct 10 15:50:52 milhouse kernel: [ 302.474603] [] device_add+0x3c9/0x520
Oct 10 15:50:52 milhouse kernel: [ 302.474608] []
hid_add_device+0x7f/0x200 [hid]
Oct 10 15:50:52 milhouse kernel: [ 302.474611] []
hidp_add_connection+0x3a4/0x6b0 [hidp]
Oct 10 15:50:52 milhouse kernel: [ 302.474614] [] ? wake_up_bit+0x40/0x40
Oct 10 15:50:52 milhouse kernel: [ 302.474617] [] ? security_capable+0x18/0x20
Oct 10 15:50:52 milhouse kernel: [ 302.474620] []
hidp_sock_ioctl+0x1e3/0x2d0 [hidp]
Oct 10 15:50:52 milhouse kernel: [ 302.474623] [] ? security_sk_alloc+0x16/0x20
Oct 10 15:50:52 milhouse kernel: [ 302.474626] [] ? sk_prot_alloc+0x80/0x190
Oct 10 15:50:52 milhouse kernel: [ 302.474630] [] ?
kmem_cache_alloc_trace+0xc4/0x120
Oct 10 15:50:52 milhouse kernel: [ 302.474633] [] ?
apparmor_file_alloc_security+0x2c/0x60
Oct 10 15:50:52 milhouse kernel: [ 302.474636] [] sock_do_ioctl+0x30/0x60
Oct 10 15:50:52 milhouse kernel: [ 302.474639] [] sock_ioctl+0x79/0x2b0
Oct 10 15:50:52 milhouse kernel: [ 302.474641] [] ? sock_alloc_file+0xaf/0x130
Oct 10 15:50:52 milhouse kernel: [ 302.474644] [] do_vfs_ioctl+0x99/0x330
Oct 10 15:50:52 milhouse kernel: [ 302.474646] [] sys_ioctl+0xa1/0xb0
Oct 10 15:50:52 milhouse kernel: [ 302.474650] [] system_call_fastpath+0x16/0x1b
Oct 10 15:50:52 milhouse kernel: [ 302.474652] ---[ end trace
eb8fce2a9b482316 ]---
Oct 10 15:50:53 milhouse kernel: [ 303.472029] power_supply
wiimote_battery: driver failed to report `capacity' property: -5
Oct 10 15:50:53 milhouse kernel: [ 303.472039] wiimote
0005:057E:0306.0005: Cannot register battery device
Oct 10 15:50:53 milhouse kernel: [ 303.475556] wiimote: probe of
0005:057E:0306.0005 failed with error -17
^ permalink raw reply
* Re: [PATCH v3 01/10] doc: Add settings storage documentation
From: Johan Hedberg @ 2012-10-10 18:41 UTC (permalink / raw)
To: Marcel Holtmann; +Cc: Frédéric Danis, linux-bluetooth
In-Reply-To: <1349890310.27233.140.camel@aeonflux>
Hi Marcel,
On Wed, Oct 10, 2012, Marcel Holtmann wrote:
> > + ./keys
>
> Not sure that I want the keys separated. That seems like a waste.
Agreed. Same file seems good.
> > + ./attribute_db
> > + ./<remote device address>/
> > + ./settings
> > + ./keys
> > + ./attribute_db
> > + ...
>
> Why did we want directories for remote devices again? Can we not just
> put all in one big file with the name of the remote address?
For profile-specific storage this could be convenient (when removing the
device we just remove the entire directory and the core daemon doesn't
need to care about profiles details). OTOH the core needs to either way
provide some API so the plugins know to write to the right location
(be it a single file for the entire device or a single directory for the
device).
> > +Adapter directory files
> > +=======================
> > +
> > +Settings file contains 1 [General] group with adapter info:
> > + [General]
> > + Name=
> > + Class=0x000000
> > + Pairable=<true|false>
> > + PairableTimeout=0
> > + DiscoverableTimeout=0
> > + Mode=<off|connectable|discoverable>
> > + OnMode=<connectable|discoverable>
>
> Actually with management interface now being used, we can be a bit
> smarter here. The mode can be programmed even if the controller is not
> powered.
>
> So this might be better as Discoverable, Connectable, Pairable and
> Powered boolean options.
>
> Also Pairable has no timeout in the kernel API anymore. Do we still need
> this?
We do have it currently as a documented adapter D-Bus property so that'd
need to be removed too. I don't personally have a great need for this
but I could imagine some device manufacturers deciding to have something
like this (especially those with very simple UI's with a single button
or so).
> > +The attribute_db file is a list of handles (group name) with UUID and Value as
> > +keys, for example:
> > + [0x0001]
> > + UUID=00002800-0000-1000-8000-00805f9b34fb
> > + Value=0018
> > +
> > + [0x0004]
> > + UUID=00002803-0000-1000-8000-00805f9b34fb
> > + Value=020600002A
> > +
> > + [0x0006]
> > + UUID=00002a00-0000-1000-8000-00805f9b34fb
> > + Value=4578616D706C6520446576696365
>
> Is this our primary key, the handle?
Yep, the reasoning was that you can easily have multiple
profiles/services with the same UUID with GATT, so the UUID is no good
as a unique identifier (not that GLib even supports multiple groups with
the same name - it merges their content together to a single logical
group).
> > +Names file contains 1 [Names] group with device address as key:
> > + [Names]
> > + <nn:nn:nn:nn:nn:nn>=device name a
> > + <mm:mm:mm:mm:mm:mm>=device name b
>
> I am not sure this is the best idea this way. Maybe just creating files
> for each address we ever see is a better idea. Details like LastSeen
> could be useful for unpaired devices.
So instead of a cache file we'd have a cache directory? I'd be fine with
that.
> > + Features=0000000000000000
> > + AddressType=<BR/EDR|LE>
> > + LEAddressType=<public|random>
>
> That is not needed. It is encoded in the address itself.
Not quite true. You cannot distinguish between public and random. But
once you do know that it's random you *can* figure out what kind of
random it is from the two most significant bits of the address.
What we discussed on #bluez was that this could simply be a reference to
what address is indicated by the directory (or filename, if that's what
we go with) for the device storage, e.g. AddressType=<static|public> and
for private resolvable addresses (for which we'd have the public address
in storage) we'd need to check if we have any IRK's to know if we need
to look for a private address to connect to them. Additionally we could
have a SupportedTechnologies list like "BR/EDR,LE", "LE", etc (feel free
to suggest a better name if you want).
Johan
^ permalink raw reply
* Re: [PATCH 4/4] Bluetooth: Use __constant modifier for RFCOMM PSM
From: Marcel Holtmann @ 2012-10-10 17:48 UTC (permalink / raw)
To: Syam Sidhardhan; +Cc: linux-bluetooth
In-Reply-To: <1349887169-20880-4-git-send-email-s.syam@samsung.com>
Hi Syam,
> Since the RFCOMM_PSM is constant, __constant_cpu_to_le16() is
> the right go here.
>
> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
> ---
> net/bluetooth/rfcomm/core.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 3/4] Bluetooth: Use __constant modifier for L2CAP SMP CID
From: Marcel Holtmann @ 2012-10-10 17:48 UTC (permalink / raw)
To: Syam Sidhardhan; +Cc: linux-bluetooth
In-Reply-To: <1349887169-20880-3-git-send-email-s.syam@samsung.com>
Hi Syam,
> Since the L2CAP_CID_SMP is constant, __constant_cpu_to_le16() is
> the right go here.
>
> Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
> ---
> net/bluetooth/smp.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Acked-by: Marcel Holtmann <marcel@holtmann.org>
Regards
Marcel
^ permalink raw reply
* Re: [PATCH 1/4] Bluetooth: Fix L2CAP PSM bind issue
From: Marcel Holtmann @ 2012-10-10 17:47 UTC (permalink / raw)
To: Syam Sidhardhan; +Cc: linux-bluetooth
In-Reply-To: <1349887169-20880-1-git-send-email-s.syam@samsung.com>
Hi Syam,
> Problem: If we bind a particular PSM with source address as BDADDR_ANY,
> then we are able to bind the same PSM with adapter address(or any other
> address), which is incorrect.
why is this incorrect? Explain that to me.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 08/10] adapter: Read mode in storage at init
From: Marcel Holtmann @ 2012-10-10 17:46 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-9-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> src/adapter.c | 61 ++++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 34 insertions(+), 27 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index 40df4a1..85c5da9 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -118,6 +118,8 @@ struct service_auth {
> struct btd_adapter_config {
> char *name;
> uint8_t class[3];
> + uint8_t mode;
> + uint8_t on_mode;
> };
here you have to do the real hard work to map this to proper modes
within management interface.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 05/10] adapter: Move pairable read to load_config()
From: Marcel Holtmann @ 2012-10-10 17:44 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-6-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> src/adapter.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index 93dc0fb..357b717 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -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;
maybe you change this later altogether, but the multiple reads here are
bad.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 04/10] adapter: Read device class in storage at init
From: Marcel Holtmann @ 2012-10-10 17:43 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-5-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> src/adapter.c | 21 ++++++++++++---------
> 1 file changed, 12 insertions(+), 9 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index 8b9af28..93dc0fb 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -117,6 +117,7 @@ struct service_auth {
>
> struct btd_adapter_config {
> char *name;
> + uint8_t class[3];
> };
same as the other one. Directly in btd_adapter if you ask me.
>
> 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);
Is this still needed this way. Should not just say, store_adapter_info
or something alike.
>
> 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];
> }
Actually this is no longer read_class, this would be get_major_minor.
>
> 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);
> + }
> }
I really want to open the file once and read it all at once. Multiple
reads seem to be wrong.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 03/10] adaptername: Retrieve config name from adapter
From: Marcel Holtmann @ 2012-10-10 17:38 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-4-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> Retrieve saved config name using adapter_get_config_name() instead
> of reading it from storage file.
> ---
> plugins/adaptername.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/plugins/adaptername.c b/plugins/adaptername.c
> index f58fb0f..46dbbe8 100644
> --- a/plugins/adaptername.c
> +++ b/plugins/adaptername.c
> @@ -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;
> + }
fair enough, you are using it here. And even why you have this as a
separate config. However this is a bit messed up.
If we have a name configured we should use that. Only a not configured
system should allow a name change here. And reading a main_opts.name
from a plugin is also bad. This needs some further investigation.
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 02/10] adapter: Read name in storage at init
From: Marcel Holtmann @ 2012-10-10 17:34 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-3-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> src/adapter.c | 34 ++++++++++++++++++++++++++++++++++
> src/adapter.h | 1 +
> 2 files changed, 35 insertions(+)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index ad8ee06..8b9af28 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -115,6 +115,10 @@ struct service_auth {
> struct agent *agent; /* NULL for queued auths */
> };
>
> +struct btd_adapter_config {
> + char *name;
> +};
> +
why are we bothering we a separate config here? I think that should be
just put into btd_adapter.
> 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;
> +}
> +
Who is the user of this. And why not just return const char *.
> 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)
> diff --git a/src/adapter.h b/src/adapter.h
> index b5bff10..b575c1b 100644
> --- a/src/adapter.h
> +++ b/src/adapter.h
> @@ -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);
Regards
Marcel
^ permalink raw reply
* Re: [PATCH v3 01/10] doc: Add settings storage documentation
From: Marcel Holtmann @ 2012-10-10 17:31 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
In-Reply-To: <1349878219-14359-2-git-send-email-frederic.danis@linux.intel.com>
Hi Fred,
> doc/settings-storage.txt | 102 ++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 102 insertions(+)
> create mode 100644 doc/settings-storage.txt
>
> diff --git a/doc/settings-storage.txt b/doc/settings-storage.txt
> new file mode 100644
> index 0000000..51d2220
> --- /dev/null
> +++ b/doc/settings-storage.txt
> @@ -0,0 +1,102 @@
> +Information related to local adapters and remote devices are stored in storage
> +directory (default: /var/lib/bluetooth).
> +Files are in ini-file format.
> +
> +There is one directory per adapter, named by its bluetooth address, which
> +contains:
> + - a settings file for the local adapter
> + - an attribute_db file containing attributes of supported LE services
> + - names file containing names of all devices already seen
> + - one directory per remote device, named by remote device address, which
> + contains:
> + - a settings file
> + - a key file accessible only by root
> + - an attribute_db file containing attributes of remote LE services
> +
> +So the directory structure should be:
> + /var/lib/bluetooth/<adapter address>/
> + ./settings
> + ./attribute_db
not sure this is a good name.
> + ./names
Lets call this one "cache". Since we could throw it away and it will be
just rediscovered. And we can also stuff other cacheable details in
there.
> + ./<remote device address>/
> + ./settings
Besides the Alias, are they really settings. You can not configure much
anyway.
> + ./keys
Not sure that I want the keys separated. That seems like a waste.
> + ./attribute_db
> + ./<remote device address>/
> + ./settings
> + ./keys
> + ./attribute_db
> + ...
Why did we want directories for remote devices again? Can we not just
put all in one big file with the name of the remote address?
> +
> +Adapter directory files
> +=======================
> +
> +Settings file contains 1 [General] group with adapter info:
> + [General]
> + Name=
> + Class=0x000000
> + Pairable=<true|false>
> + PairableTimeout=0
> + DiscoverableTimeout=0
> + Mode=<off|connectable|discoverable>
> + OnMode=<connectable|discoverable>
Actually with management interface now being used, we can be a bit
smarter here. The mode can be programmed even if the controller is not
powered.
So this might be better as Discoverable, Connectable, Pairable and
Powered boolean options.
Also Pairable has no timeout in the kernel API anymore. Do we still need
this?
> +The attribute_db file is a list of handles (group name) with UUID and Value as
> +keys, for example:
> + [0x0001]
> + UUID=00002800-0000-1000-8000-00805f9b34fb
> + Value=0018
> +
> + [0x0004]
> + UUID=00002803-0000-1000-8000-00805f9b34fb
> + Value=020600002A
> +
> + [0x0006]
> + UUID=00002a00-0000-1000-8000-00805f9b34fb
> + Value=4578616D706C6520446576696365
Is this our primary key, the handle?
> +
> +Names file contains 1 [Names] group with device address as key:
> + [Names]
> + <nn:nn:nn:nn:nn:nn>=device name a
> + <mm:mm:mm:mm:mm:mm>=device name b
I am not sure this is the best idea this way. Maybe just creating files
for each address we ever see is a better idea. Details like LastSeen
could be useful for unpaired devices.
> +
> +Device directory files
> +======================
> +
> +Remote device settings file will include a [General] group with device infos
> +and a [DeviceID] group with related infos:
> + [General]
> + Alias=
> + Class=0x000000
> + Manufacturer=0
> + LmpVersion=
> + LmpSubversion=
Take these 3 our. We were just storing them for statistic purposes.
> + Features=0000000000000000
> + AddressType=<BR/EDR|LE>
> + LEAddressType=<public|random>
That is not needed. It is encoded in the address itself.
> + LastSeen=yyyy-mm-dd hh:mm:ss GMT
> + LastUsed=yyyy-mm-dd hh:mm:ss GMT
> + Trusted=<true|false>
> + Profiles=<128 bits UUID of profile 1>;<128 bits UUID of profile 2>;...
> +
> + [DeviceID]
> + Assigner=0
This is called Source.
> + Vendor=0
> + Product=0
> + Version=0
> +
> +Keys file includes informations related to link key or long term link key:
> + [LinkKey]
> + Key=
> + Type=0
> + PINLength=0
> +
> + [LongTermKey]
> + Key=
> + Authenticated=<true|false>
> + EncSize=0
> + EDiv=0
> + Rand=0
Can be both in the same file about the device information.
> +
> +The attribute_db file is a list of handles (group name) with UUID and Value as
> +keys (cf. attribute_db in adapter directory).
Regards
Marcel
^ permalink raw reply
* [PATCH 4/4] Bluetooth: Use __constant modifier for RFCOMM PSM
From: Syam Sidhardhan @ 2012-10-10 16:39 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349887169-20880-1-git-send-email-s.syam@samsung.com>
Since the RFCOMM_PSM is constant, __constant_cpu_to_le16() is
the right go here.
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
net/bluetooth/rfcomm/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/rfcomm/core.c b/net/bluetooth/rfcomm/core.c
index fb1d83d..201fdf7 100644
--- a/net/bluetooth/rfcomm/core.c
+++ b/net/bluetooth/rfcomm/core.c
@@ -709,7 +709,7 @@ static struct rfcomm_session *rfcomm_session_create(bdaddr_t *src,
bacpy(&addr.l2_bdaddr, dst);
addr.l2_family = AF_BLUETOOTH;
- addr.l2_psm = cpu_to_le16(RFCOMM_PSM);
+ addr.l2_psm = __constant_cpu_to_le16(RFCOMM_PSM);
addr.l2_cid = 0;
*err = kernel_connect(sock, (struct sockaddr *) &addr, sizeof(addr), O_NONBLOCK);
if (*err == 0 || *err == -EINPROGRESS)
@@ -1987,7 +1987,7 @@ static int rfcomm_add_listener(bdaddr_t *ba)
/* Bind socket */
bacpy(&addr.l2_bdaddr, ba);
addr.l2_family = AF_BLUETOOTH;
- addr.l2_psm = cpu_to_le16(RFCOMM_PSM);
+ addr.l2_psm = __constant_cpu_to_le16(RFCOMM_PSM);
addr.l2_cid = 0;
err = kernel_bind(sock, (struct sockaddr *) &addr, sizeof(addr));
if (err < 0) {
--
1.7.9.5
^ permalink raw reply related
* [PATCH 3/4] Bluetooth: Use __constant modifier for L2CAP SMP CID
From: Syam Sidhardhan @ 2012-10-10 16:39 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349887169-20880-1-git-send-email-s.syam@samsung.com>
Since the L2CAP_CID_SMP is constant, __constant_cpu_to_le16() is
the right go here.
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
net/bluetooth/smp.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index 8c225ef..9b54fea 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -165,7 +165,7 @@ static struct sk_buff *smp_build_cmd(struct l2cap_conn *conn, u8 code,
lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
lh->len = cpu_to_le16(sizeof(code) + dlen);
- lh->cid = cpu_to_le16(L2CAP_CID_SMP);
+ lh->cid = __constant_cpu_to_le16(L2CAP_CID_SMP);
memcpy(skb_put(skb, sizeof(code)), &code, sizeof(code));
--
1.7.9.5
^ permalink raw reply related
* [PATCH 2/4] Bluetooth: Fix RFCOMM bind issue
From: Syam Sidhardhan @ 2012-10-10 16:39 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349887169-20880-1-git-send-email-s.syam@samsung.com>
Problem: If we bind a particular RFCOMM channel with source address as
BDADDR_ANY, then we are able to bind the same RFCOMM channel with the
adapter address, which is incorrect.
Solution: Add check for comparing the stored source address and
given source address against BDADDR_ANY, so that irrespective of
BADADDR_ANY or any adapter address, a particular RFCOMM channel will
be allowed to bind only once.
Details:
Here given the steps to reproduce this issue:
Bind to a RFCOMM channel without the device address.
-sh-4.1# rctest -w -P 5
rctest[2920]: Waiting for connection on channel 5 ...
In another terminal, bind to same RFCOMM channel with a device address
-sh-4.1# rctest -w -P 5 -i hci0
rctest[2922]: Waiting for connection on channel 5 ...
Here we can see the binding is successful for both cases for the same
RFCOMM channel. After this fix, the binding for a particular RFCOMM
channel is allowed only once.
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
net/bluetooth/rfcomm/sock.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
index 867a065..4add776 100644
--- a/net/bluetooth/rfcomm/sock.c
+++ b/net/bluetooth/rfcomm/sock.c
@@ -110,8 +110,16 @@ static struct sock *__rfcomm_get_sock_by_addr(u8 channel, bdaddr_t *src)
struct hlist_node *node;
sk_for_each(sk, node, &rfcomm_sk_list.head) {
- if (rfcomm_pi(sk)->channel == channel &&
- !bacmp(&bt_sk(sk)->src, src))
+ if (rfcomm_pi(sk)->channel != channel)
+ continue;
+
+ /* Exact match */
+ if (!bacmp(&bt_sk(sk)->src, src))
+ break;
+
+ /* BDADDR_ANY match */
+ if (!bacmp(&bt_sk(sk)->src, BDADDR_ANY) ||
+ !bacmp(src, BDADDR_ANY))
break;
}
--
1.7.9.5
^ permalink raw reply related
* [PATCH 1/4] Bluetooth: Fix L2CAP PSM bind issue
From: Syam Sidhardhan @ 2012-10-10 16:39 UTC (permalink / raw)
To: linux-bluetooth
Problem: If we bind a particular PSM with source address as BDADDR_ANY,
then we are able to bind the same PSM with adapter address(or any other
address), which is incorrect.
Solution: Added check for comparing the stored source address and
given source address against BDADDR_ANY, so that irrespective of
BADADDR_ANY or any adapter address, a particular PSM will be allowed
to bind only once.
Details: After successful binding, both the PSM and the source device
address are stored in a global list. Before binding to a new PSM, the
old PSM and the source address from the gobal list are compared against
the new PSM and source device address for make the PSM binding unique.
Before this fix, If we pass the different device addresses, for the same
PSM, both the binding are successful. Further an incoming connection to
that particular PSM goes to incorrect profile (first binded). This PSM
binding issues can be easily reproducible using the l2test utility as
shown below.
Bind to a PSM without the device address
-sh-4.1# l2test -w -P 4097
l2test[2792]: Waiting for connection on psm 4097 ...
In another terminal, bind to same PSM with device address
-sh-4.1# l2test -w -P 4097 -i hci0
l2test[2787]: Waiting for connection on psm 4097 ...
Here we can see the binding is successful for both cases for the same
PSM. After this fix the binding for a particular PSM is allowed only
once.
Signed-off-by: Syam Sidhardhan <s.syam@samsung.com>
---
This patch resolves the HDP incoming connection issue when Obexd is
running in background. Both uses dynamic PSM range. Obex over l2cap
bind with source address as BDADDR_ANY and HDP binds with source address
as the adapter address. Both bindings for the same PSM are getting
success.
net/bluetooth/l2cap_core.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index d42cdb1..ace7cd8 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -113,7 +113,16 @@ static struct l2cap_chan *__l2cap_global_chan_by_addr(__le16 psm, bdaddr_t *src)
struct l2cap_chan *c;
list_for_each_entry(c, &chan_list, global_l) {
- if (c->sport == psm && !bacmp(&bt_sk(c->sk)->src, src))
+ if (c->sport != psm)
+ continue;
+
+ /* Exact match */
+ if (!bacmp(&bt_sk(c->sk)->src, src))
+ return c;
+
+ /* BDADDR_ANY match */
+ if (!bacmp(&bt_sk(c->sk)->src, BDADDR_ANY) ||
+ !bacmp(src, BDADDR_ANY))
return c;
}
return NULL;
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 10/10] TODO: Add entry to remove storage convertion function
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
TODO | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/TODO b/TODO
index 384d428..c6787cc 100644
--- a/TODO
+++ b/TODO
@@ -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
=======
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 09/10] adapter: Move saved config to ini-file format
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
Read and write config file in ini-file format.
If the file can not be loaded, try to convert legacy configuration.
---
src/adapter.c | 206 ++++++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 174 insertions(+), 32 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 85c5da9..6b4197c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -33,6 +33,7 @@
#include <stdlib.h>
#include <stdbool.h>
#include <sys/ioctl.h>
+#include <sys/file.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/uuid.h>
@@ -84,6 +85,8 @@
#define OFF_TIMER 3
+#define SETTINGS_PATH STORAGEDIR "/%s/settings"
+
static GSList *adapter_drivers = NULL;
enum session_req_type {
@@ -224,6 +227,54 @@ static uint8_t get_mode(const char *mode)
return MODE_UNKNOWN;
}
+static void write_config(struct btd_adapter *adapter)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char address[18];
+ char *str;
+ gsize length = 0;
+
+ key_file = g_key_file_new();
+
+ g_key_file_set_string(key_file, "General", "Name",
+ adapter->config.name);
+
+ str = g_strdup_printf("0x%2.2x%2.2x%2.2x", adapter->config.class[2],
+ adapter->config.class[1],
+ adapter->config.class[0]);
+ g_key_file_set_string(key_file, "General", "Class", str);
+ g_free(str);
+
+ g_key_file_set_boolean(key_file, "General", "Pairable",
+ adapter->pairable);
+
+ if (adapter->pairable_timeout != main_opts.pairto)
+ g_key_file_set_integer(key_file, "General", "PairableTimeout",
+ adapter->pairable_timeout);
+
+ if (adapter->discov_timeout != main_opts.discovto)
+ g_key_file_set_integer(key_file, "General",
+ "DiscoverableTimeout",
+ adapter->discov_timeout);
+
+ g_key_file_set_string(key_file, "General", "Mode",
+ mode2str(adapter->config.mode));
+ g_key_file_set_string(key_file, "General", "OnMode",
+ mode2str(adapter->config.on_mode));
+
+ ba2str(&adapter->bdaddr, address);
+ snprintf(filename, PATH_MAX, SETTINGS_PATH, address);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ str = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, str, length, NULL);
+ g_free(str);
+
+ g_key_file_free(key_file);
+}
+
static struct session_req *session_ref(struct session_req *req)
{
req->refcount++;
@@ -293,7 +344,6 @@ static struct session_req *find_session_by_msg(GSList *list, const DBusMessage *
static int set_mode(struct btd_adapter *adapter, uint8_t new_mode)
{
int err;
- const char *modestr;
if (adapter->pending_mode != NULL)
return -EALREADY;
@@ -329,10 +379,9 @@ done:
if (new_mode != MODE_OFF)
adapter->config.on_mode = new_mode;
- modestr = mode2str(new_mode);
- write_device_mode(&adapter->bdaddr, modestr);
+ write_config(adapter);
- DBG("%s", modestr);
+ DBG("%s", mode2str(new_mode));
return 0;
}
@@ -475,7 +524,7 @@ void btd_adapter_pairable_changed(struct btd_adapter *adapter,
{
adapter->pairable = pairable;
- write_device_pairable(&adapter->bdaddr, pairable);
+ write_config(adapter);
g_dbus_emit_property_changed(btd_get_dbus_connection(), adapter->path,
ADAPTER_INTERFACE, "Pairable");
@@ -692,7 +741,7 @@ static void set_discoverable_timeout(struct btd_adapter *adapter,
adapter->discov_timeout = timeout;
- write_discoverable_timeout(&adapter->bdaddr, timeout);
+ write_config(adapter);
g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
"DiscoverableTimeout");
@@ -712,7 +761,7 @@ static void set_pairable_timeout(struct btd_adapter *adapter,
adapter->pairable_timeout = timeout;
- write_pairable_timeout(&adapter->bdaddr, timeout);
+ write_config(adapter);
g_dbus_emit_property_changed(conn, adapter->path, ADAPTER_INTERFACE,
"PairableTimeout");
@@ -732,7 +781,7 @@ void btd_adapter_class_changed(struct btd_adapter *adapter, uint8_t *new_class)
adapter->config.class[1] = new_class[1];
adapter->config.class[2] = new_class[2];
- write_local_class(&adapter->bdaddr, new_class);
+ write_config(adapter);
adapter->dev_class = class;
@@ -792,7 +841,7 @@ int adapter_set_name(struct btd_adapter *adapter, const char *name)
g_free(adapter->config.name);
adapter->config.name = g_strdup(maxname);
- write_local_name(&adapter->bdaddr, maxname);
+ write_config(adapter);
return 0;
}
@@ -2479,17 +2528,15 @@ static void set_mode_complete(struct btd_adapter *adapter)
{
DBusConnection *conn = btd_get_dbus_connection();
struct session_req *pending;
- 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);
+ write_config(adapter);
- DBG("%s", modestr);
+ DBG("%s", mode2str(adapter->mode));
if (adapter->mode == MODE_OFF) {
g_slist_free_full(adapter->mode_sessions, session_free);
@@ -2656,56 +2703,151 @@ void btd_adapter_unref(struct btd_adapter *adapter)
g_free(path);
}
-static void load_config(struct btd_adapter *adapter)
+static void convert_config(struct btd_adapter *adapter, const char *filename,
+ GKeyFile *key_file)
{
- char name[MAX_NAME_LENGTH + 1];
char address[18];
- char mode[14];
+ char str[MAX_NAME_LENGTH + 1];
+ char config_path[PATH_MAX + 1];
+ char *converted;
+ uint8_t class[3];
+ gboolean flag;
int timeout;
+ char *data;
+ gsize length = 0;
+
+ ba2str(&adapter->bdaddr, address);
+ snprintf(config_path, PATH_MAX, STORAGEDIR "/%s/config", address);
+
+ converted = textfile_get(config_path, "converted");
+ if (converted) {
+ if (strcmp(converted, "yes") == 0) {
+ DBG("Legacy config file already converted");
+ return;
+ }
+
+ g_free(converted);
+ }
+
+ if (read_local_name(&adapter->bdaddr, str) == 0)
+ g_key_file_set_string(key_file, "General", "Name", str);
+
+ if (read_local_class(&adapter->bdaddr, class) == 0) {
+ sprintf(str, "0x%2.2x%2.2x%2.2x", class[2], class[1], class[0]);
+ g_key_file_set_string(key_file, "General", "Class", str);
+ }
+
+ if (read_device_pairable(&adapter->bdaddr, &flag) == 0)
+ g_key_file_set_boolean(key_file, "General", "Pairable", flag);
+
+ if (read_pairable_timeout(address, &timeout) == 0)
+ g_key_file_set_integer(key_file, "General",
+ "PairableTimeout", timeout);
+
+ if (read_discoverable_timeout(address, &timeout) == 0)
+ g_key_file_set_integer(key_file, "General",
+ "DiscoverableTimeout", timeout);
+
+ if (read_device_mode(address, str, sizeof(str)) == 0)
+ g_key_file_set_string(key_file, "General", "Mode", str);
+
+ if (read_on_mode(address, str, sizeof(str)) == 0)
+ g_key_file_set_string(key_file, "General", "OnMode", str);
+
+ create_file(filename, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+
+ data = g_key_file_to_data(key_file, &length, NULL);
+ g_file_set_contents(filename, data, length, NULL);
+ g_free(data);
+
+ textfile_put(config_path, "converted", "yes");
+}
+
+static void load_config(struct btd_adapter *adapter)
+{
+ GKeyFile *key_file;
+ char filename[PATH_MAX + 1];
+ char address[18];
+ char *str;
+ GError *gerr = NULL;
ba2str(&adapter->bdaddr, address);
+ key_file = g_key_file_new();
+
+ snprintf(filename, PATH_MAX, SETTINGS_PATH, address);
+
+ if (!g_key_file_load_from_file(key_file, filename, 0, NULL))
+ convert_config(adapter, filename, key_file);
+
/* Get name */
- if (read_local_name(&adapter->bdaddr, name) < 0)
- adapter->config.name = NULL;
- else
- adapter->config.name = g_strdup(name);
+ adapter->config.name = g_key_file_get_string(key_file, "General",
+ "Name", NULL);
/* Get class */
- if (read_local_class(&adapter->bdaddr, adapter->config.class) < 0) {
+ str = g_key_file_get_string(key_file, "General", "Class", NULL);
+ if (str) {
+ char tmp[3];
+ int i;
+ uint8_t *class = adapter->config.class;
+
+ memset(tmp, 0, sizeof(tmp));
+ for (i = 0; i < 3; i++) {
+ memcpy(tmp, str + (i * 2) + 2, 2);
+ class[2 - i] = (uint8_t) strtol(tmp, NULL, 16);
+ }
+ } else {
uint32_t class = htobl(main_opts.class);
memcpy(adapter->config.class, &class, 3);
}
+ g_free(str);
/* Get pairable mode */
- if (read_device_pairable(&adapter->bdaddr, &adapter->pairable) < 0)
+ adapter->pairable = g_key_file_get_boolean(key_file, "General",
+ "Pairable", &gerr);
+ if (gerr) {
adapter->pairable = TRUE;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get pairable timeout */
- if (read_pairable_timeout(address, &timeout) < 0)
+ adapter->pairable_timeout = g_key_file_get_integer(key_file, "General",
+ "PairableTimeout", &gerr);
+ if (gerr) {
adapter->pairable_timeout = main_opts.pairto;
- else
- adapter->pairable_timeout = timeout;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get discoverable timeout */
- if (read_discoverable_timeout(address, &timeout) < 0)
+ adapter->discov_timeout = g_key_file_get_integer(key_file, "General",
+ "DiscoverableTimeout", &gerr);
+ if (gerr) {
adapter->discov_timeout = main_opts.discovto;
- else
- adapter->discov_timeout = timeout;
+ g_error_free(gerr);
+ gerr = NULL;
+ }
/* Get mode */
+ str = g_key_file_get_string(key_file, "General", "Mode", NULL);
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 if (str)
+ adapter->config.mode = get_mode(str);
else
adapter->config.mode = main_opts.mode;
+ g_free(str);
/* Get on mode */
- if (read_on_mode(address, mode, sizeof(mode)) == 0)
- adapter->config.on_mode = get_mode(mode);
+ str = g_key_file_get_string(key_file, "General", "OnMode", NULL);
+ if (str)
+ adapter->config.on_mode = get_mode(str);
else
adapter->config.on_mode = MODE_CONNECTABLE;
+ g_free(str);
+
+ g_key_file_free(key_file);
}
gboolean adapter_init(struct btd_adapter *adapter, gboolean up)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 08/10] adapter: Read mode in storage at init
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 61 ++++++++++++++++++++++++++++++++-------------------------
1 file changed, 34 insertions(+), 27 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 40df4a1..85c5da9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 07/10] adapter: Read discoverable timeout in storage at init
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 19 +++++++------------
1 file changed, 7 insertions(+), 12 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index b869d81..40df4a1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 06/10] adapter: Read pairable timeout in storage at init
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 357b717..b869d81 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 05/10] adapter: Move pairable read to load_config()
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 93dc0fb..357b717 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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);
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 04/10] adapter: Read device class in storage at init
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
---
src/adapter.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 8b9af28..93dc0fb 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -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)
--
1.7.9.5
^ permalink raw reply related
* [PATCH v4 03/10] adaptername: Retrieve config name from adapter
From: Frédéric Danis @ 2012-10-10 16:23 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1349886211-18920-1-git-send-email-frederic.danis@linux.intel.com>
Retrieve saved config name using adapter_get_config_name() instead
of reading it from storage file.
---
plugins/adaptername.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/plugins/adaptername.c b/plugins/adaptername.c
index f58fb0f..46dbbe8 100644
--- a/plugins/adaptername.c
+++ b/plugins/adaptername.c
@@ -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);
--
1.7.9.5
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox