summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cups/hcrp.c7
-rw-r--r--hidd/main.c25
-rw-r--r--pand/main.c17
-rw-r--r--sdpd/main.c1
-rw-r--r--test/hstest.c6
-rw-r--r--test/l2test.c2
-rw-r--r--tools/ciptool.c5
7 files changed, 50 insertions, 13 deletions
diff --git a/cups/hcrp.c b/cups/hcrp.c
index f69800a7..75171524 100644
--- a/cups/hcrp.c
+++ b/cups/hcrp.c
@@ -187,9 +187,9 @@ int hcrp_print(bdaddr_t *src, bdaddr_t *dst, unsigned short ctrl_psm, unsigned s
return 1;
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, src);
- addr.l2_psm = 0;
if (bind(ctrl_sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("ERROR: Can't bind socket");
@@ -197,6 +197,7 @@ int hcrp_print(bdaddr_t *src, bdaddr_t *dst, unsigned short ctrl_psm, unsigned s
return 1;
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, dst);
addr.l2_psm = htobs(ctrl_psm);
@@ -213,9 +214,9 @@ int hcrp_print(bdaddr_t *src, bdaddr_t *dst, unsigned short ctrl_psm, unsigned s
return 1;
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, src);
- addr.l2_psm = 0;
if (bind(data_sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
perror("ERROR: Can't bind socket");
@@ -224,6 +225,7 @@ int hcrp_print(bdaddr_t *src, bdaddr_t *dst, unsigned short ctrl_psm, unsigned s
return 1;
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, dst);
addr.l2_psm = htobs(data_psm);
@@ -235,6 +237,7 @@ int hcrp_print(bdaddr_t *src, bdaddr_t *dst, unsigned short ctrl_psm, unsigned s
return 1;
}
+ memset(&opts, 0, sizeof(opts));
size = sizeof(opts);
if (getsockopt(data_sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, &size) < 0) {
diff --git a/hidd/main.c b/hidd/main.c
index 1ad39e0f..84d94b78 100644
--- a/hidd/main.c
+++ b/hidd/main.c
@@ -72,21 +72,23 @@ static int l2cap_connect(bdaddr_t *src, bdaddr_t *dst, unsigned short psm)
if ((sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0)
return -1;
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, src);
- addr.l2_psm = 0;
if (bind(sk, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
close(sk);
return -1;
}
+ memset(&opts, 0, sizeof(opts));
opts.imtu = HIDP_DEFAULT_MTU;
opts.omtu = HIDP_DEFAULT_MTU;
opts.flush_to = 0xffff;
setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, sizeof(opts));
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, dst);
addr.l2_psm = htobs(psm);
@@ -108,6 +110,7 @@ static int l2cap_listen(const bdaddr_t *bdaddr, unsigned short psm, int lm, int
if ((sk = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)) < 0)
return -1;
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, bdaddr);
addr.l2_psm = htobs(psm);
@@ -119,6 +122,7 @@ static int l2cap_listen(const bdaddr_t *bdaddr, unsigned short psm, int lm, int
setsockopt(sk, SOL_L2CAP, L2CAP_LM, &lm, sizeof(lm));
+ memset(&opts, 0, sizeof(opts));
opts.imtu = HIDP_DEFAULT_MTU;
opts.omtu = HIDP_DEFAULT_MTU;
opts.flush_to = 0xffff;
@@ -258,8 +262,23 @@ static int create_device(int ctl, int csk, int isk, uint8_t subclass, int nosdp,
err = get_hid_device_info(&src, &dst, &req);
if (err < 0)
goto error;
- } else
- req.subclass = 0xc0;
+ } else {
+ struct l2cap_conninfo conn;
+ socklen_t size;
+ uint8_t class[3];
+
+ memset(&conn, 0, sizeof(conn));
+ size = sizeof(conn);
+ if (getsockopt(csk, SOL_L2CAP, L2CAP_CONNINFO, &conn, &size) < 0)
+ memset(class, 0, 3);
+ else
+ memcpy(class, conn.dev_class, 3);
+
+ if (class[1] == 0x25 && (class[2] == 0x00 || class[2] == 0x01))
+ req.subclass = class[0];
+ else
+ req.subclass = 0xc0;
+ }
if (subclass != 0x00)
req.subclass = subclass;
diff --git a/pand/main.c b/pand/main.c
index e7fcb875..2090f9f8 100644
--- a/pand/main.c
+++ b/pand/main.c
@@ -139,9 +139,10 @@ static int do_listen(void)
return -1;
}
+ memset(&l2a, 0, sizeof(l2a));
l2a.l2_family = AF_BLUETOOTH;
- l2a.l2_psm = htobs(BNEP_PSM);
- l2a.l2_bdaddr = src_addr;
+ bacpy(&l2a.l2_bdaddr, &src_addr);
+ l2a.l2_psm = htobs(BNEP_PSM);
if (bind(sk, (struct sockaddr *) &l2a, sizeof(l2a))) {
syslog(LOG_ERR, "Bind failed. %s(%d)", strerror(errno), errno);
@@ -149,6 +150,7 @@ static int do_listen(void)
}
/* Setup L2CAP options according to BNEP spec */
+ memset(&l2o, 0, sizeof(l2o));
olen = sizeof(l2o);
if (getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &olen) < 0) {
syslog(LOG_ERR, "Failed to get L2CAP options. %s(%d)",
@@ -272,23 +274,24 @@ static int create_connection(char *dst, bdaddr_t *bdaddr)
}
/* Setup L2CAP options according to BNEP spec */
+ memset(&l2o, 0, sizeof(l2o));
olen = sizeof(l2o);
getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, &olen);
l2o.imtu = l2o.omtu = BNEP_MTU;
setsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &l2o, sizeof(l2o));
+ memset(&l2a, 0, sizeof(l2a));
l2a.l2_family = AF_BLUETOOTH;
-
- /* Set local address */
- l2a.l2_psm = 0;
- l2a.l2_bdaddr = src_addr;
+ bacpy(&l2a.l2_bdaddr, &src_addr);
if (bind(sk, (struct sockaddr *) &l2a, sizeof(l2a)))
syslog(LOG_ERR, "Bind failed. %s(%d)",
strerror(errno), errno);
+ memset(&l2a, 0, sizeof(l2a));
+ l2a.l2_family = AF_BLUETOOTH;
+ bacpy(&l2a.l2_bdaddr, bdaddr);
l2a.l2_psm = htobs(BNEP_PSM);
- l2a.l2_bdaddr = *bdaddr;
if (!connect(sk, (struct sockaddr *) &l2a, sizeof(l2a)) &&
!bnep_create_connection(sk, role, service, netdev)) {
diff --git a/sdpd/main.c b/sdpd/main.c
index 0efc7d50..eb59a6fa 100644
--- a/sdpd/main.c
+++ b/sdpd/main.c
@@ -318,6 +318,7 @@ static inline void handle_request(int sk, char *data, int len)
if (sa.l2_family == AF_BLUETOOTH) {
struct l2cap_options lo;
+ memset(&lo, 0, sizeof(lo));
size = sizeof(lo);
getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &lo, &size);
req.bdaddr = sa.l2_bdaddr;
diff --git a/test/hstest.c b/test/hstest.c
index 98428b68..f269621c 100644
--- a/test/hstest.c
+++ b/test/hstest.c
@@ -98,6 +98,7 @@ static int sco_connect(bdaddr_t *src, bdaddr_t *dst, uint16_t *handle, uint16_t
memset(&addr, 0, sizeof(addr));
addr.sco_family = AF_BLUETOOTH;
bacpy(&addr.sco_bdaddr, src);
+
if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
close(s);
return -1;
@@ -106,18 +107,23 @@ static int sco_connect(bdaddr_t *src, bdaddr_t *dst, uint16_t *handle, uint16_t
memset(&addr, 0, sizeof(addr));
addr.sco_family = AF_BLUETOOTH;
bacpy(&addr.sco_bdaddr, dst);
+
if (connect(s, (struct sockaddr *)&addr, sizeof(addr)) < 0 ){
close(s);
return -1;
}
+ memset(&conn, 0, sizeof(conn));
size = sizeof(conn);
+
if (getsockopt(s, SOL_SCO, SCO_CONNINFO, &conn, &size) < 0) {
close(s);
return -1;
}
+ memset(&opts, 0, sizeof(opts));
size = sizeof(opts);
+
if (getsockopt(s, SOL_SCO, SCO_OPTIONS, &opts, &size) < 0) {
close(s);
return -1;
diff --git a/test/l2test.c b/test/l2test.c
index eedf4b70..627d37f1 100644
--- a/test/l2test.c
+++ b/test/l2test.c
@@ -192,6 +192,7 @@ int do_connect(char *svr)
}
/* Get default options */
+ memset(&opts, 0, sizeof(opts));
opt = sizeof(opts);
if (getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0) {
syslog(LOG_ERR, "Can't get default L2CAP options. %s(%d)", strerror(errno), errno);
@@ -236,6 +237,7 @@ int do_connect(char *svr)
return -1;
}
+ memset(&opts, 0, sizeof(opts));
opt = sizeof(opts);
if (getsockopt(s, SOL_L2CAP, L2CAP_OPTIONS, &opts, &opt) < 0) {
syslog(LOG_ERR, "Can't get L2CAP options. %s(%d)", strerror(errno), errno);
diff --git a/tools/ciptool.c b/tools/ciptool.c
index d0b6625d..7c952cf4 100644
--- a/tools/ciptool.c
+++ b/tools/ciptool.c
@@ -146,9 +146,9 @@ static int do_connect(int ctl, int dev_id, bdaddr_t *src, bdaddr_t *dst, unsigne
exit(1);
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, src);
- addr.l2_psm = 0;
if (bind(sk, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
perror("Can't bind L2CAP socket");
@@ -156,7 +156,9 @@ static int do_connect(int ctl, int dev_id, bdaddr_t *src, bdaddr_t *dst, unsigne
exit(1);
}
+ memset(&opts, 0, sizeof(opts));
size = sizeof(opts);
+
if (getsockopt(sk, SOL_L2CAP, L2CAP_OPTIONS, &opts, &size) < 0) {
perror("Can't get L2CAP options");
close(sk);
@@ -173,6 +175,7 @@ static int do_connect(int ctl, int dev_id, bdaddr_t *src, bdaddr_t *dst, unsigne
exit(1);
}
+ memset(&addr, 0, sizeof(addr));
addr.l2_family = AF_BLUETOOTH;
bacpy(&addr.l2_bdaddr, dst);
addr.l2_psm = htobs(psm);