From 1169f479669a618940aa67e7249beb51ed574841 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 31 Oct 2013 02:55:53 +0000 Subject: [PATCH] android: Add support for handling pin reply command --- android/adapter.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/android/adapter.c b/android/adapter.c index 23ad97485..808d617d8 100644 --- a/android/adapter.c +++ b/android/adapter.c @@ -751,6 +751,49 @@ static bool cancel_bond(void *buf, uint16_t len) NULL) > 0; } +static uint8_t pin_reply(void *buf, uint16_t len) +{ + struct hal_cmd_pin_reply *cmd = buf; + bdaddr_t bdaddr; + char addr[18]; + + android2bdaddr(cmd->bdaddr, &bdaddr); + ba2str(&bdaddr, addr); + + DBG("%s accept %u pin_len %u", addr, cmd->accept, cmd->pin_len); + + if (!cmd->accept && cmd->pin_len) + return HAL_STATUS_INVALID; + + if (cmd->accept) { + struct mgmt_cp_pin_code_reply rp; + + memset(&rp, 0, sizeof(rp)); + + bacpy(&rp.addr.bdaddr, &bdaddr); + rp.addr.type = BDADDR_BREDR; + rp.pin_len = cmd->pin_len; + memcpy(rp.pin_code, cmd->pin_code, rp.pin_len); + + if (mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_REPLY, + adapter->index, sizeof(rp), &rp, + NULL, NULL, NULL) == 0) + return HAL_STATUS_FAILED; + } else { + struct mgmt_cp_pin_code_neg_reply rp; + + bacpy(&rp.addr.bdaddr, &bdaddr); + rp.addr.type = BDADDR_BREDR; + + if (mgmt_reply(adapter->mgmt, MGMT_OP_PIN_CODE_NEG_REPLY, + adapter->index, sizeof(rp), &rp, + NULL, NULL, NULL) == 0) + return HAL_STATUS_FAILED; + } + + return HAL_STATUS_SUCCESS; +} + void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, uint16_t len) { @@ -797,6 +840,12 @@ void bt_adapter_handle_cmd(GIOChannel *io, uint8_t opcode, void *buf, if (!cancel_bond(buf, len)) goto error; + break; + case HAL_OP_PIN_REPLY: + status = pin_reply(buf, len); + if (status != HAL_STATUS_SUCCESS) + goto error; + break; default: DBG("Unhandled command, opcode 0x%x", opcode); -- 2.47.3