* [Bluez-devel] [patch] check connection before connecting
@ 2008-01-28 18:57 Frédéric Dalleau
2008-01-29 16:30 ` Frédéric Dalleau
0 siblings, 1 reply; 2+ messages in thread
From: Frédéric Dalleau @ 2008-01-28 18:57 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 429 bytes --]
For review only,
This patch checks that a device is already connected before trying to
connect. If no device is connected, opening the alsa plugin will fail
instead of forcing connection to default device (which is blocking).
This behavior can be enabled or disabled thanks to an option in .asoundrc.
pcm.bt {
type bluetooth
check_conn "yes"
}
It poorly tested now and mainly targeted for comments.
BR,
Frédéric
[-- Attachment #2: check_conn.patch --]
[-- Type: text/x-patch, Size: 5323 bytes --]
diff --git a/audio/ipc.c b/audio/ipc.c
index 0592064..195f40f 100644
--- a/audio/ipc.c
+++ b/audio/ipc.c
@@ -38,6 +38,8 @@ static const char *strmsg[] = {
"BT_CONTROL_RSP",
"BT_CONTROL_IND",
"BT_STREAMFD_IND",
+ "BT_ISCONNECTED_REQ",
+ "BT_ISCONNECTED_RSP",
};
int bt_audio_service_open()
diff --git a/audio/ipc.h b/audio/ipc.h
index 3768dcf..1e83cbe 100644
--- a/audio/ipc.h
+++ b/audio/ipc.h
@@ -107,6 +107,9 @@ typedef struct {
#define BT_STREAMFD_IND 13
+#define BT_ISCONNECTED_REQ 14
+#define BT_ISCONNECTED_RSP 15
+
/* BT_GETCAPABILITIES_REQ */
#define BT_CAPABILITIES_TRANSPORT_A2DP 0
@@ -229,6 +232,16 @@ struct bt_streamfd_ind {
bt_audio_msg_header_t h;
} __attribute__ ((packed));
+/* BT_ISCONNECTED_REQ */
+struct bt_isconnected_req {
+ bt_audio_msg_header_t h;
+} __attribute__ ((packed));
+
+/* BT_ISCONNECTED_RSP */
+struct bt_isconnected_rsp {
+ bt_audio_rsp_msg_header_t rsp_h;
+} __attribute__ ((packed));
+
/* BT_STREAMSTOP_REQ */
struct bt_streamstop_req {
bt_audio_msg_header_t h;
diff --git a/audio/manager.h b/audio/manager.h
index e740a52..ca23fad 100644
--- a/audio/manager.h
+++ b/audio/manager.h
@@ -42,6 +42,7 @@ void audio_exit(void);
uint32_t add_service_record(DBusConnection *conn, sdp_buf_t *buf);
int remove_service_record(DBusConnection *conn, uint32_t rec_id);
gboolean server_is_enabled(uint16_t svc);
+struct device *manager_get_connected_device(void);
struct device *manager_find_device(bdaddr_t *bda, const char *interface,
gboolean connected);
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index a04f18c..a1ed9a0 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -122,6 +122,7 @@ struct bluetooth_alsa_config {
int has_block_length;
uint8_t bitpool; /* A2DP only */
int has_bitpool;
+ int check_conn; /* A2DP only */
};
struct bluetooth_data {
@@ -1268,7 +1269,7 @@ static int bluetooth_parse_config(snd_config_t *conf,
struct bluetooth_alsa_config *bt_config)
{
snd_config_iterator_t i, next;
- const char *addr, *pref;
+ const char *addr, *pref, *check;
const char *mode, *allocation, *rate, *subbands, *blocks, *bitpool;
memset(bt_config, 0, sizeof(struct bluetooth_alsa_config));
@@ -1283,6 +1284,17 @@ static int bluetooth_parse_config(snd_config_t *conf,
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
continue;
+ if (strcmp(id, "check_conn") == 0) {
+ if (snd_config_get_string(n, &check) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+
+ if (strcmp(check, "yes") == 0)
+ bt_config->check_conn = 1;
+ continue;
+ }
+
if (strcmp(id, "device") == 0 || strcmp(id, "bdaddr") == 0) {
if (snd_config_get_string(n, &addr) < 0) {
SNDERR("Invalid type for %s", id);
@@ -1477,6 +1489,7 @@ static int bluetooth_init(struct bluetooth_data *data, snd_pcm_stream_t stream,
bt_audio_rsp_msg_header_t *rsp_hdr = (void*) buf;
struct bt_getcapabilities_req *getcaps_req = (void*) buf;
struct bt_getcapabilities_rsp *getcaps_rsp = (void*) buf;
+ struct bt_isconnected_req *isconnected_req = (void*) buf;
memset(data, 0, sizeof(struct bluetooth_data));
@@ -1512,6 +1525,26 @@ static int bluetooth_init(struct bluetooth_data *data, snd_pcm_stream_t stream,
goto failed;
}
+ /* send isconnected */
+ if(alsa_conf->check_conn) {
+ memset(isconnected_req, 0, BT_AUDIO_IPC_PACKET_SIZE);
+ isconnected_req->h.msg_type = BT_ISCONNECTED_REQ;
+
+ err = audioservice_send(data->server.fd, &isconnected_req->h);
+ if (err < 0)
+ goto failed;
+
+ err = audioservice_expect(data->server.fd, &rsp_hdr->msg_h,
+ BT_ISCONNECTED_RSP);
+ if (err < 0)
+ goto failed;
+
+ if(rsp_hdr->posix_errno != 0) {
+ return -rsp_hdr->posix_errno;
+ }
+ }
+
+ /* send getcapabilities */
memset(getcaps_req, 0, BT_AUDIO_IPC_PACKET_SIZE);
getcaps_req->h.msg_type = BT_GETCAPABILITIES_REQ;
strncpy(getcaps_req->device, alsa_conf->device, 18);
diff --git a/audio/unix.c b/audio/unix.c
index d71c420..cf33618 100644
--- a/audio/unix.c
+++ b/audio/unix.c
@@ -909,6 +909,34 @@ failed:
unix_ipc_error(client, BT_STREAMSTART_REQ, EIO);
}
+
+static void handle_isconnected_req(struct unix_client *client,
+ struct bt_streamstart_req *req)
+{
+ /* FIXME: really implement that */
+ char buf[BT_AUDIO_IPC_PACKET_SIZE];
+ struct bt_setconfiguration_rsp *rsp = (void *) buf;
+
+ debug("%s", __FUNCTION__);
+
+ if (!manager_get_connected_device())
+ goto failed;
+
+ debug("%s connected", __FUNCTION__);
+
+ memset(buf, 0, sizeof(buf));
+ rsp->rsp_h.msg_h.msg_type = BT_ISCONNECTED_RSP;
+ rsp->rsp_h.posix_errno = 0;
+
+ unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
+
+ return;
+
+failed:
+ debug("%s not connected", __FUNCTION__);
+ unix_ipc_error(client, BT_ISCONNECTED_RSP, ENOTCONN);
+}
+
static void handle_streamstop_req(struct unix_client *client,
struct bt_streamstop_req *req)
{
@@ -997,6 +1025,10 @@ static gboolean client_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
handle_streamstart_req(client,
(struct bt_streamstart_req *) msghdr);
break;
+ case BT_ISCONNECTED_REQ:
+ handle_isconnected_req(client,
+ (struct bt_streamstart_req *) msghdr);
+ break;
case BT_STREAMSTOP_REQ:
handle_streamstop_req(client,
(struct bt_streamstop_req *) msghdr);
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [Bluez-devel] [patch] check connection before connecting
2008-01-28 18:57 [Bluez-devel] [patch] check connection before connecting Frédéric Dalleau
@ 2008-01-29 16:30 ` Frédéric Dalleau
0 siblings, 0 replies; 2+ messages in thread
From: Frédéric Dalleau @ 2008-01-29 16:30 UTC (permalink / raw)
To: BlueZ development
[-- Attachment #1: Type: text/plain, Size: 424 bytes --]
Hi,
>
> This patch checks that a device is already connected before trying to
> connect. If no device is connected, opening the alsa plugin will fail
> instead of forcing connection to default device (which is blocking).
> This behavior can be enabled or disabled thanks to an option in
> .asoundrc.
Updated version, with the mods we talked about on #bluez.
pcm.bt {
type bluetooth
autoconnect "yes"
}
Frédéric
[-- Attachment #2: autoconnect.patch --]
[-- Type: text/x-patch, Size: 2592 bytes --]
diff --git a/audio/ipc.h b/audio/ipc.h
index 3768dcf..68509e1 100644
--- a/audio/ipc.h
+++ b/audio/ipc.h
@@ -117,10 +117,13 @@ typedef struct {
#define BT_CAPABILITIES_ACCESS_MODE_WRITE 2
#define BT_CAPABILITIES_ACCESS_MODE_READWRITE 3
+#define BT_CAPABILITIES_AUTOCONNECT 1
+
struct bt_getcapabilities_req {
bt_audio_msg_header_t h;
char device[18]; /* Address of the remote Device */
uint8_t transport; /* Requested transport */
+ uint8_t flags; /* Requested flags */
} __attribute__ ((packed));
/* BT_GETCAPABILITIES_RSP */
diff --git a/audio/pcm_bluetooth.c b/audio/pcm_bluetooth.c
index a04f18c..9a523d2 100644
--- a/audio/pcm_bluetooth.c
+++ b/audio/pcm_bluetooth.c
@@ -122,6 +122,7 @@ struct bluetooth_alsa_config {
int has_block_length;
uint8_t bitpool; /* A2DP only */
int has_bitpool;
+ int autoconnect;
};
struct bluetooth_data {
@@ -1268,7 +1269,7 @@ static int bluetooth_parse_config(snd_config_t *conf,
struct bluetooth_alsa_config *bt_config)
{
snd_config_iterator_t i, next;
- const char *addr, *pref;
+ const char *addr, *pref, *autoconnect;
const char *mode, *allocation, *rate, *subbands, *blocks, *bitpool;
memset(bt_config, 0, sizeof(struct bluetooth_alsa_config));
@@ -1283,6 +1284,17 @@ static int bluetooth_parse_config(snd_config_t *conf,
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
continue;
+ if (strcmp(id, "autoconnect") == 0) {
+ if (snd_config_get_string(n, &autoconnect) < 0) {
+ SNDERR("Invalid type for %s", id);
+ return -EINVAL;
+ }
+
+ if (strcmp(autoconnect, "yes") == 0)
+ bt_config->autoconnect = 1;
+ continue;
+ }
+
if (strcmp(id, "device") == 0 || strcmp(id, "bdaddr") == 0) {
if (snd_config_get_string(n, &addr) < 0) {
SNDERR("Invalid type for %s", id);
@@ -1514,6 +1526,9 @@ static int bluetooth_init(struct bluetooth_data *data, snd_pcm_stream_t stream,
memset(getcaps_req, 0, BT_AUDIO_IPC_PACKET_SIZE);
getcaps_req->h.msg_type = BT_GETCAPABILITIES_REQ;
+ getcaps_req->flags = 0;
+ if (alsa_conf->autoconnect)
+ getcaps_req->flags |= BT_CAPABILITIES_AUTOCONNECT;
strncpy(getcaps_req->device, alsa_conf->device, 18);
if (alsa_conf->has_transport)
getcaps_req->transport = alsa_conf->transport;
diff --git a/audio/unix.c b/audio/unix.c
index d71c420..934d534 100644
--- a/audio/unix.c
+++ b/audio/unix.c
@@ -779,6 +779,9 @@ static void handle_getcapabilities_req(struct unix_client *client,
if (!dev)
goto failed;
+ if (!req->flags & BT_CAPABILITIES_AUTOCONNECT)
+ goto failed;
+
start_discovery(dev, client);
return;
[-- Attachment #3: Type: text/plain, Size: 228 bytes --]
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
[-- Attachment #4: Type: text/plain, Size: 164 bytes --]
_______________________________________________
Bluez-devel mailing list
Bluez-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bluez-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-01-29 16:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-01-28 18:57 [Bluez-devel] [patch] check connection before connecting Frédéric Dalleau
2008-01-29 16:30 ` Frédéric Dalleau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox