Bluetooth: SMP: Send pairing failed on unexpected PDU

If unexpected PDU is recevied it is better to reply with Pairing
Failed and abort pairing then just silently ingore such PDU as
pairing will most likely fail anyway.

Change-Id: I3c67a6997a5e8d33b1e97cb955981a52baf38d02
Signed-off-by: Szymon Janc <ext.szymon.janc@tieto.com>
This commit is contained in:
Szymon Janc 2016-07-04 13:53:45 +02:00 committed by Johan Hedberg
commit bccc1bf0e1

View file

@ -2556,22 +2556,23 @@ static void bt_smp_recv(struct bt_l2cap_chan *chan, struct net_buf *buf)
if (hdr->code >= ARRAY_SIZE(handlers) || !handlers[hdr->code].func) {
BT_WARN("Unhandled SMP code 0x%02x", hdr->code);
err = BT_SMP_ERR_CMD_NOTSUPP;
} else {
if (!atomic_test_and_clear_bit(&smp->allowed_cmds, hdr->code)) {
BT_WARN("Unexpected SMP code 0x%02x", hdr->code);
return;
}
if (buf->len != handlers[hdr->code].expect_len) {
BT_ERR("Invalid len %u for code 0x%02x", buf->len,
hdr->code);
err = BT_SMP_ERR_INVALID_PARAMS;
} else {
err = handlers[hdr->code].func(smp, buf);
}
smp_error(smp, BT_SMP_ERR_CMD_NOTSUPP);
return;
}
if (!atomic_test_and_clear_bit(&smp->allowed_cmds, hdr->code)) {
BT_WARN("Unexpected SMP code 0x%02x", hdr->code);
smp_error(smp, BT_SMP_ERR_UNSPECIFIED);
return;
}
if (buf->len != handlers[hdr->code].expect_len) {
BT_ERR("Invalid len %u for code 0x%02x", buf->len, hdr->code);
smp_error(smp, BT_SMP_ERR_INVALID_PARAMS);
return;
}
err = handlers[hdr->code].func(smp, buf);
if (err) {
smp_error(smp, err);
}