Skip to content

Commit cf721a5

Browse files
Frédéric DalleauJohan Hedberg
Frédéric Dalleau
authored and
Johan Hedberg
committed
btio: Add option for SCO voice setting
1 parent c594291 commit cf721a5

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

btio/btio.c

+20-4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ struct set_opts {
7878
uint8_t mode;
7979
int flushable;
8080
uint32_t priority;
81+
uint16_t voice;
8182
};
8283

8384
struct connect {
@@ -723,13 +724,14 @@ static int sco_connect(int sock, const bdaddr_t *dst)
723724
return 0;
724725
}
725726

726-
static gboolean sco_set(int sock, uint16_t mtu, GError **err)
727+
static gboolean sco_set(int sock, uint16_t mtu, uint16_t voice, GError **err)
727728
{
728729
struct sco_options sco_opt;
730+
struct bt_voice bt_voice;
729731
socklen_t len;
730732

731733
if (!mtu)
732-
return TRUE;
734+
goto voice;
733735

734736
len = sizeof(sco_opt);
735737
memset(&sco_opt, 0, len);
@@ -745,6 +747,17 @@ static gboolean sco_set(int sock, uint16_t mtu, GError **err)
745747
return FALSE;
746748
}
747749

750+
voice:
751+
if (!voice)
752+
return TRUE;
753+
754+
bt_voice.setting = voice;
755+
if (setsockopt(sock, SOL_BLUETOOTH, BT_VOICE, &bt_voice,
756+
sizeof(bt_voice)) < 0) {
757+
ERROR_FAILED(err, "setsockopt(BT_VOICE)", errno);
758+
return FALSE;
759+
}
760+
748761
return TRUE;
749762
}
750763

@@ -832,6 +845,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
832845
case BT_IO_OPT_PRIORITY:
833846
opts->priority = va_arg(args, int);
834847
break;
848+
case BT_IO_OPT_VOICE:
849+
opts->voice = va_arg(args, int);
850+
break;
835851
default:
836852
g_set_error(err, BT_IO_ERROR, EINVAL,
837853
"Unknown option %d", opt);
@@ -1310,7 +1326,7 @@ gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...)
13101326
case BT_IO_RFCOMM:
13111327
return rfcomm_set(sock, opts.sec_level, opts.master, err);
13121328
case BT_IO_SCO:
1313-
return sco_set(sock, opts.mtu, err);
1329+
return sco_set(sock, opts.mtu, opts.voice, err);
13141330
default:
13151331
g_set_error(err, BT_IO_ERROR, EINVAL,
13161332
"Unknown BtIO type %d", type);
@@ -1377,7 +1393,7 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts,
13771393
}
13781394
if (sco_bind(sock, &opts->src, err) < 0)
13791395
goto failed;
1380-
if (!sco_set(sock, opts->mtu, err))
1396+
if (!sco_set(sock, opts->mtu, opts->voice, err))
13811397
goto failed;
13821398
break;
13831399
default:

btio/btio.h

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef enum {
5555
BT_IO_OPT_MODE,
5656
BT_IO_OPT_FLUSHABLE,
5757
BT_IO_OPT_PRIORITY,
58+
BT_IO_OPT_VOICE,
5859
} BtIOOption;
5960

6061
typedef enum {

0 commit comments

Comments
 (0)