length = expected_length ? expected_length : BT_SUGGESTED_BUFFER_SIZE;
+ if (length < sizeof(bt_audio_error_t))
+ length = sizeof(bt_audio_error_t);
+
pa_log_debug("Trying to receive message from audio service...");
r = recv(fd, msg, length, 0);
pa_log_debug("Received %s <- %s",
pa_strnull(bt_audio_strtype(msg->type)),
pa_strnull(bt_audio_strname(msg->name)));
+
return 0;
}
return -1;
}
-static int service_expect(int fd, bt_audio_msg_header_t *rsp, uint8_t expected_name, size_t expected_length) {
+static ssize_t service_expect(int fd, bt_audio_msg_header_t *rsp, uint8_t expected_name, size_t expected_length) {
int r;
pa_assert(fd >= 0);
if ((r = service_recv(fd, rsp, expected_length)) < 0)
return r;
- if (rsp->name != expected_name) {
- pa_log_error("Bogus message %s received while %s was expected",
- pa_strnull(bt_audio_strname(rsp->name)),
- pa_strnull(bt_audio_strname(expected_name)));
- return -1;
- }
+ if (rsp->type != BT_RESPONSE || rsp->name != expected_name) {
- if (rsp->type == BT_ERROR) {
- bt_audio_error_t *error = (bt_audio_error_t *) rsp;
- pa_log_error("%s failed: %s", pa_strnull(bt_audio_strname(rsp->name)), pa_cstrerror(error->posix_errno));
+ if (rsp->type == BT_ERROR && rsp->length == sizeof(bt_audio_error_t))
+ pa_log_error("Received error condition: %s", pa_cstrerror(((bt_audio_error_t*) rsp)->posix_errno));
+ else
+ pa_log_error("Bogus message %s received while %s was expected",
+ pa_strnull(bt_audio_strname(rsp->name)),
+ pa_strnull(bt_audio_strname(expected_name)));
return -1;
}
union {
struct bt_get_capabilities_req getcaps_req;
struct bt_get_capabilities_rsp getcaps_rsp;
+ bt_audio_error_t error;
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg;
union {
struct bt_set_configuration_req setconf_req;
struct bt_set_configuration_rsp setconf_rsp;
+ bt_audio_error_t error;
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg;
struct bt_start_stream_req start_req;
struct bt_start_stream_rsp start_rsp;
struct bt_new_stream_ind streamfd_ind;
+ bt_audio_error_t error;
uint8_t buf[BT_SUGGESTED_BUFFER_SIZE];
} msg;