Skip to contentSkip to conversation

Change BT_XXXXXX_RSP messages structure

PATCH New Fabien Chevalier 1 participant 1 message Dec 4, 2007 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Change BT_XXXXXX_RSP messages structure

Hi Luiz,

The attached patch groups the error field in a specific header for all the BT_XXXXXX_RSP messages.
It makes sending such BT_XXXXXX_RSP messages much simpler, by being able to send a simple bt_audio_rsp_msg_header_t structure in the error path, when all the other fields are left to NULL.

As usual, comments are welcomed !!

Cheers,

Fabien

pcm_bluetooth.c +24 -22
Index: pcm_bluetooth.c
===================================================================
@@ -332,8 +332,8 @@
 	char c = 'w';
 	char buf[BT_AUDIO_IPC_PACKET_SIZE];
 	struct bt_streamstart_req *start_req = (void*) buf;
-	struct bt_streamstart_rsp *start_rsp = (void*) buf;
-	struct bt_datafd_ind *datafd_ind = (void*) buf;
+	bt_audio_rsp_msg_header_t *rsp_hdr = (void*) buf;
+	struct bt_streamfd_ind *streamfd_ind = (void*) buf;
 	uint32_t period_count = io->buffer_size / io->period_size;
 	int opt_name, err;
 	struct timeval t = { 0, period_count };
@@ -368,19 +368,19 @@
 	if (err < 0)
 		return err;
 
-	err = audioservice_expect(data->server.fd, &start_rsp->h,
+	err = audioservice_expect(data->server.fd, &rsp_hdr->msg_h,
 					BT_STREAMSTART_RSP);
 	if (err < 0)
 		return err;
 
-	if (start_rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		SNDERR("BT_START failed : %s(%d)",
-					strerror(start_rsp->posix_errno),
-					start_rsp->posix_errno);
-		return -start_rsp->posix_errno;
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
+		return -rsp_hdr->posix_errno;
 	}
 
-	err = audioservice_expect(data->server.fd, &datafd_ind->h,
+	err = audioservice_expect(data->server.fd, &streamfd_ind->h,
 					BT_STREAMFD_IND);
 	if (err < 0)
 		return err;
@@ -542,6 +542,7 @@
 	struct bluetooth_data *data = io->private_data;
 	struct bluetooth_a2dp *a2dp = &data->a2dp;
 	char buf[BT_AUDIO_IPC_PACKET_SIZE];
+	bt_audio_rsp_msg_header_t *rsp_hdr = (void*) buf;
 	struct bt_setconfiguration_req *setconf_req = (void*) buf;
 	struct bt_setconfiguration_rsp *setconf_rsp = (void*) buf;
 	unsigned int rate, channels;
@@ -573,16 +574,16 @@
 	if (err < 0)
 		return err;
 
-	err = audioservice_expect(data->server.fd, &setconf_rsp->h,
+	err = audioservice_expect(data->server.fd, &rsp_hdr->msg_h,
 					BT_SETCONFIGURATION_RSP);
 	if (err < 0)
 		return err;
 
-	if (setconf_rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		SNDERR("BT_SETCONFIGURATION failed : %s(%d)",
-					strerror(setconf_rsp->posix_errno),
-					setconf_rsp->posix_errno);
-		return -setconf_rsp->posix_errno;
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
+		return -rsp_hdr->posix_errno;
 	}
 
 	data->transport = setconf_rsp->transport;
@@ -1399,16 +1400,16 @@
 	return err;
 }
 
-static int audioservice_expect(int sk, bt_audio_msg_header_t *outmsg,
+static int audioservice_expect(int sk, bt_audio_msg_header_t *rsp_hdr,
 				int expected_type)
 {
-	int err = audioservice_recv(sk, outmsg);
+	int err = audioservice_recv(sk, rsp_hdr);
 	if (err == 0) {
-		if (outmsg->msg_type != expected_type) {
+		if (rsp_hdr->msg_type != expected_type) {
 			err = -EINVAL;
 			SNDERR("Bogus message %s received while "
 					"%s was expected",
-					bt_audio_strmsg(outmsg->msg_type),
+					bt_audio_strmsg(rsp_hdr->msg_type),
 					bt_audio_strmsg(expected_type));
 		}
 	}
@@ -1421,6 +1422,7 @@
 	int sk, err;
 	struct bluetooth_alsa_config *alsa_conf = &data->alsa_config;
 	char buf[BT_AUDIO_IPC_PACKET_SIZE];
+	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;
 
@@ -1474,15 +1476,15 @@
 	if (err < 0)
 		goto failed;
 
-	err = audioservice_expect(data->server.fd, &getcaps_rsp->h, BT_GETCAPABILITIES_RSP);
+	err = audioservice_expect(data->server.fd, &rsp_hdr->msg_h, BT_GETCAPABILITIES_RSP);
 	if (err < 0)
 		goto failed;
 
-	if (getcaps_rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		SNDERR("BT_GETCAPABILITIES failed : %s(%d)",
-					strerror(getcaps_rsp->posix_errno),
-					getcaps_rsp->posix_errno);
-		return -getcaps_rsp->posix_errno;
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
+		return -rsp_hdr->posix_errno;
 	}
 
 	data->transport = getcaps_rsp->transport;
ipc.h +22 -21

88 lines not on this page · raw message

unix.c +20 -20
Index: unix.c
===================================================================
@@ -161,13 +161,13 @@
 static void unix_ipc_error(struct unix_client *client, int type, int err)
 {
 	char buf[BT_AUDIO_IPC_PACKET_SIZE];
-	struct bt_getcapabilities_rsp *rsp = (void *) buf;
+	bt_audio_rsp_msg_header_t *rsp_hdr = (void *) buf;
 
 	memset(buf, 0, sizeof(buf));
-	rsp->h.msg_type = type;
-	rsp->posix_errno = err;
+	rsp_hdr->msg_h.msg_type = type;
+	rsp_hdr->posix_errno = err;
 
-	unix_ipc_sendmsg(client, &rsp->h);
+	unix_ipc_sendmsg(client, &rsp_hdr->msg_h);
 }
 
 static service_type_t select_service(struct device *dev, const char *interface)
@@ -304,13 +304,13 @@
 
 	memset(buf, 0, sizeof(buf));
 
-	rsp->h.msg_type = BT_SETCONFIGURATION_RSP;
+	rsp->rsp_h.msg_h.msg_type = BT_SETCONFIGURATION_RSP;
 	rsp->transport  = BT_CAPABILITIES_TRANSPORT_SCO;
 	rsp->access_mode = client->access_mode;
 
 	client->data_fd = headset_get_sco_fd(dev);
 
-	unix_ipc_sendmsg(client, &rsp->h);
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 }
 
 static void a2dp_discovery_complete(struct avdtp *session, GSList *seps,
@@ -330,7 +330,7 @@
 	memset(buf, 0, sizeof(buf));
 	client->req_id = 0;
 
-	rsp->h.msg_type = BT_GETCAPABILITIES_RSP;
+	rsp->rsp_h.msg_h.msg_type = BT_GETCAPABILITIES_RSP;
 	rsp->transport = BT_CAPABILITIES_TRANSPORT_A2DP;
 
 	for (l = seps; l; l = g_slist_next(l)) {
@@ -361,7 +361,7 @@
 		rsp->sbc_capabilities.max_bitpool = sbc_cap->max_bitpool;
 	}
 
-	unix_ipc_sendmsg(client, &rsp->h);
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 
 	return;
 
@@ -406,14 +406,14 @@
 		goto failed;
 	}
 
-	rsp->h.msg_type = BT_SETCONFIGURATION_RSP;
+	rsp->rsp_h.msg_h.msg_type = BT_SETCONFIGURATION_RSP;
 	rsp->transport = BT_CAPABILITIES_TRANSPORT_A2DP;
 	client->access_mode = BT_CAPABILITIES_ACCESS_MODE_WRITE;
 	rsp->access_mode = client->access_mode;
 	/* FIXME: Use imtu when fd_opt is CFG_FD_OPT_READ */
 	rsp->link_mtu = omtu;
 
-	unix_ipc_sendmsg(client, &rsp->h);
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 
 	client->cb_id = avdtp_stream_add_cb(session, stream,
 						stream_state_changed, client);
@@ -441,13 +441,13 @@
 	struct unix_client *client = user_data;
 	char buf[BT_AUDIO_IPC_PACKET_SIZE];
 	struct bt_streamstart_rsp *rsp = (void *) buf;
-	struct bt_datafd_ind *ind = (void *) buf;
+	struct bt_streamfd_ind *ind = (void *) buf;
 	struct a2dp_data *a2dp = &client->d.a2dp;
 
 	memset(buf, 0, sizeof(buf));
-	rsp->h.msg_type = BT_STREAMSTART_RSP;
-	rsp->posix_errno = 0;
-	unix_ipc_sendmsg(client, &rsp->h);
+	rsp->rsp_h.msg_h.msg_type = BT_STREAMSTART_RSP;
+	rsp->rsp_h.posix_errno = 0;
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 
 	memset(buf, 0, sizeof(buf));
 	ind->h.msg_type = BT_STREAMFD_IND;
@@ -487,9 +487,9 @@
 		goto failed;
 
 	memset(buf, 0, sizeof(buf));
-	rsp->h.msg_type = BT_STREAMSTOP_RSP;
-	rsp->posix_errno = 0;
-	unix_ipc_sendmsg(client, &rsp->h);
+	rsp->rsp_h.msg_h.msg_type = BT_STREAMSTOP_RSP;
+	rsp->rsp_h.posix_errno = 0;
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 
 	return;
 
@@ -863,10 +863,10 @@
 	struct bt_setconfiguration_rsp *rsp = (void *) buf;
 
 	memset(buf, 0, sizeof(buf));
-	rsp->h.msg_type = BT_CONTROL_RSP;
-	rsp->posix_errno = 0;
+	rsp->rsp_h.msg_h.msg_type = BT_CONTROL_RSP;
+	rsp->rsp_h.posix_errno = 0;
 
-	unix_ipc_sendmsg(client, &rsp->h);
+	unix_ipc_sendmsg(client, &rsp->rsp_h.msg_h);
 }
 
 static gboolean client_cb(GIOChannel *chan, GIOCondition cond, gpointer data)
gsta2dpsink.c +16 -14
Index: gsta2dpsink.c
===================================================================
@@ -582,6 +582,7 @@
 {
 	gchar *buf[BT_AUDIO_IPC_PACKET_SIZE];
 	struct bt_getcapabilities_req *req = (void *) buf;
+	bt_audio_rsp_msg_header_t *rsp_hdr = (void *) buf;
 	struct bt_getcapabilities_rsp *rsp = (void *) buf;
 	GIOError io_error;
 
@@ -595,17 +596,17 @@
 		GST_ERROR_OBJECT(self, "Error while asking device caps");
 	}
 
-	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp->h,
+	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp_hdr->msg_h,
 			BT_GETCAPABILITIES_RSP);
 	if (io_error != G_IO_ERROR_NONE) {
 		GST_ERROR_OBJECT(self, "Error while getting device caps");
 		return FALSE;
 	}
 
-	if (rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		GST_ERROR_OBJECT(self, "BT_GETCAPABILITIES failed : %s(%d)",
-					strerror(rsp->posix_errno),
-					rsp->posix_errno);
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
 		return FALSE;
 	}
 
@@ -660,8 +661,8 @@
 {
 	gchar buf[BT_AUDIO_IPC_PACKET_SIZE];
 	struct bt_streamstart_req *req = (void *) buf;
-	struct bt_streamstart_rsp *rsp = (void *) buf;
-	struct bt_datafd_ind *ind = (void*) buf;
+	bt_audio_rsp_msg_header_t *rsp_hdr = (void *) buf;
+	struct bt_streamfd_ind *ind = (void*) buf;
 	GIOError io_error;
 
 	GST_DEBUG_OBJECT(self, "stream start");
@@ -678,17 +679,17 @@
 
 	GST_DEBUG_OBJECT(self, "stream start packet sent");
 
-	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp->h,
+	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp_hdr->msg_h,
 			BT_STREAMSTART_RSP);
 	if (io_error != G_IO_ERROR_NONE) {
 		GST_ERROR_OBJECT(self, "Error while stream start confirmation");
 		return FALSE;
 	}
 
-	if (rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		GST_ERROR_OBJECT(self, "BT_STREAMSTART_RSP failed : %s(%d)",
-					strerror(rsp->posix_errno),
-					rsp->posix_errno);
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
 		return FALSE;
 	}
 
@@ -711,6 +712,7 @@
 {
 	gchar buf[BT_AUDIO_IPC_PACKET_SIZE];
 	struct bt_setconfiguration_req *req = (void *) buf;
+	bt_audio_rsp_msg_header_t *rsp_hdr  = (void *) buf;
 	struct bt_setconfiguration_rsp *rsp = (void *) buf;
 	gboolean ret;
 	GIOError io_error;
@@ -737,17 +739,17 @@
 
 	GST_DEBUG_OBJECT(self, "configuration packet sent");
 
-	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp->h,
+	io_error = gst_a2dp_sink_audioservice_expect(self, &rsp_hdr->msg_h,
 			BT_SETCONFIGURATION_RSP);
 	if (io_error != G_IO_ERROR_NONE) {
 		GST_ERROR_OBJECT(self, "Error while receiving device confirmation");
 		return FALSE;
 	}
 
-	if (rsp->posix_errno != 0) {
+	if (rsp_hdr->posix_errno != 0) {
 		GST_ERROR_OBJECT(self, "BT_SETCONFIGURATION_RSP failed : %s(%d)",
-					strerror(rsp->posix_errno),
-					rsp->posix_errno);
+					strerror(rsp_hdr->posix_errno),
+					rsp_hdr->posix_errno);
 		return FALSE;
 	}
 
ctl_bluetooth.c +7 -7
Index: ctl_bluetooth.c
===================================================================
@@ -164,24 +164,24 @@
 		return  -errno;
 	}
 
-	type = bt_audio_strmsg(ctl_rsp->h.msg_type);
+	type = bt_audio_strmsg(ctl_rsp->rsp_h.msg_h.msg_type);
 	if (!type) {
 		SNDERR("Bogus message type %d "
 				"received from audio service",
-				ctl_rsp->h.msg_type);
+				ctl_rsp->rsp_h.msg_h.msg_type);
 		return -EINVAL;
 	}
 
-	if (ctl_rsp->h.msg_type != BT_CONTROL_RSP) {
+	if (ctl_rsp->rsp_h.msg_h.msg_type != BT_CONTROL_RSP) {
 		SNDERR("Unexpected message %s received", type);
 		return -EINVAL;
 	}
 
-	if (ctl_rsp->posix_errno != 0) {
+	if (ctl_rsp->rsp_h.posix_errno != 0) {
 		SNDERR("BT_CONTROL failed : %s (%d)",
-					strerror(ctl_rsp->posix_errno),
-					ctl_rsp->posix_errno);
-		return -ctl_rsp->posix_errno;
+					strerror(ctl_rsp->rsp_h.posix_errno),
+					ctl_rsp->rsp_h.posix_errno);
+		return -ctl_rsp->rsp_h.posix_errno;
 	}
 
 	return 0;

begin:vcard
fn:Fabien CHEVALIER
n:CHEVALIER;Fabien
org:SILICOM
adr:;;4 rue de Jouanet; RENNES ATALANTE;;35700;FRANCE email;internet:[email protected] title:Software & Studies Engineer tel;work:+33 (0) 2 99 84 17 17
version:2.1
end:vcard

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4

_______________________________________________
Bluez-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bluez-devel