mirror of https://github.com/labapart/gattlib
bluez/btio: Added option BT_IO_OPT_TIMEOUT
parent
36ff478c3e
commit
ee58e4cb64
|
@ -65,6 +65,7 @@ struct set_opts {
|
||||||
uint8_t mode;
|
uint8_t mode;
|
||||||
int flushable;
|
int flushable;
|
||||||
uint32_t priority;
|
uint32_t priority;
|
||||||
|
int timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct connect {
|
struct connect {
|
||||||
|
@ -172,11 +173,27 @@ static int l2cap_bind(int sock, const bdaddr_t *src, uint16_t psm,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int l2cap_connect(int sock, const bdaddr_t *dst, uint8_t dst_type,
|
static int l2cap_connect(int sock, const bdaddr_t *dst, uint8_t dst_type,
|
||||||
uint16_t psm, uint16_t cid)
|
uint16_t psm, uint16_t cid, uint16_t timeout)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
struct sockaddr_l2 addr;
|
struct sockaddr_l2 addr;
|
||||||
|
|
||||||
|
if (timeout > 0) {
|
||||||
|
struct timeval timeout;
|
||||||
|
timeout.tv_sec = 2;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
|
if (setsockopt (sock, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
|
||||||
|
fprintf(stderr, "l2cap_connect: Failed to setsockopt for receive timeout.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setsockopt (sock, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(timeout)) < 0) {
|
||||||
|
fprintf(stderr, "l2cap_connect: Failed to setsockopt for sending timeout.\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
addr.l2_family = AF_BLUETOOTH;
|
addr.l2_family = AF_BLUETOOTH;
|
||||||
bacpy(&addr.l2_bdaddr, dst);
|
bacpy(&addr.l2_bdaddr, dst);
|
||||||
|
@ -599,6 +616,7 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
|
||||||
opts->flushable = -1;
|
opts->flushable = -1;
|
||||||
opts->priority = 0;
|
opts->priority = 0;
|
||||||
opts->dst_type = BDADDR_BREDR;
|
opts->dst_type = BDADDR_BREDR;
|
||||||
|
opts->timeout = 0;
|
||||||
|
|
||||||
while (opt != BT_IO_OPT_INVALID) {
|
while (opt != BT_IO_OPT_INVALID) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
|
@ -660,6 +678,9 @@ static gboolean parse_set_opts(struct set_opts *opts, GError **err,
|
||||||
case BT_IO_OPT_PRIORITY:
|
case BT_IO_OPT_PRIORITY:
|
||||||
opts->priority = va_arg(args, int);
|
opts->priority = va_arg(args, int);
|
||||||
break;
|
break;
|
||||||
|
case BT_IO_OPT_TIMEOUT:
|
||||||
|
opts->timeout = va_arg(args, int);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
|
g_set_error(err, BT_IO_ERROR, BT_IO_ERROR_INVALID_ARGS,
|
||||||
"Unknown option %d", opt);
|
"Unknown option %d", opt);
|
||||||
|
@ -1245,12 +1266,12 @@ GIOChannel *bt_io_connect(BtIOType type, BtIOConnect connect,
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case BT_IO_L2RAW:
|
case BT_IO_L2RAW:
|
||||||
err = l2cap_connect(sock, &opts.dst, opts.dst_type, 0,
|
err = l2cap_connect(sock, &opts.dst, opts.dst_type, 0,
|
||||||
opts.cid);
|
opts.cid, opts.timeout);
|
||||||
break;
|
break;
|
||||||
case BT_IO_L2CAP:
|
case BT_IO_L2CAP:
|
||||||
case BT_IO_L2ERTM:
|
case BT_IO_L2ERTM:
|
||||||
err = l2cap_connect(sock, &opts.dst, opts.dst_type,
|
err = l2cap_connect(sock, &opts.dst, opts.dst_type,
|
||||||
opts.psm, opts.cid);
|
opts.psm, opts.cid, opts.timeout);
|
||||||
break;
|
break;
|
||||||
case BT_IO_RFCOMM:
|
case BT_IO_RFCOMM:
|
||||||
err = rfcomm_connect(sock, &opts.dst, opts.channel);
|
err = rfcomm_connect(sock, &opts.dst, opts.channel);
|
||||||
|
|
|
@ -70,6 +70,7 @@ typedef enum {
|
||||||
BT_IO_OPT_MODE,
|
BT_IO_OPT_MODE,
|
||||||
BT_IO_OPT_FLUSHABLE,
|
BT_IO_OPT_FLUSHABLE,
|
||||||
BT_IO_OPT_PRIORITY,
|
BT_IO_OPT_PRIORITY,
|
||||||
|
BT_IO_OPT_TIMEOUT
|
||||||
} BtIOOption;
|
} BtIOOption;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -207,6 +207,7 @@ static gatt_connection_t *initialize_gattlib_connection(const gchar *src, const
|
||||||
BT_IO_OPT_DEST_TYPE, dest_type,
|
BT_IO_OPT_DEST_TYPE, dest_type,
|
||||||
BT_IO_OPT_CID, ATT_CID,
|
BT_IO_OPT_CID, ATT_CID,
|
||||||
BT_IO_OPT_SEC_LEVEL, sec_level,
|
BT_IO_OPT_SEC_LEVEL, sec_level,
|
||||||
|
BT_IO_OPT_TIMEOUT, 2,
|
||||||
BT_IO_OPT_INVALID);
|
BT_IO_OPT_INVALID);
|
||||||
else
|
else
|
||||||
conn->io = bt_io_connect(BT_IO_L2CAP, io_connect_cb, io_connect_arg, NULL, &err,
|
conn->io = bt_io_connect(BT_IO_L2CAP, io_connect_cb, io_connect_arg, NULL, &err,
|
||||||
|
@ -215,6 +216,7 @@ static gatt_connection_t *initialize_gattlib_connection(const gchar *src, const
|
||||||
BT_IO_OPT_PSM, psm,
|
BT_IO_OPT_PSM, psm,
|
||||||
BT_IO_OPT_IMTU, mtu,
|
BT_IO_OPT_IMTU, mtu,
|
||||||
BT_IO_OPT_SEC_LEVEL, sec_level,
|
BT_IO_OPT_SEC_LEVEL, sec_level,
|
||||||
|
BT_IO_OPT_TIMEOUT, 2,
|
||||||
BT_IO_OPT_INVALID);
|
BT_IO_OPT_INVALID);
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
Loading…
Reference in New Issue