answer HCI_EVENT_IO_USER_CONFIRMATION_REQUEST and HCI_EVENT_USER_PASSKEY_REQUEST if ssp_auto_accpet is set, provide hci_ssp_set.. API

This commit is contained in:
matthias.ringwald@gmail.com 2013-09-01 20:01:30 +00:00
parent 1d6b20ae69
commit dbe1a7904e
2 changed files with 79 additions and 25 deletions

View File

@ -564,7 +564,19 @@ static void event_handler(uint8_t *packet, int size){
case HCI_EVENT_IO_CAPABILITY_REQUEST: case HCI_EVENT_IO_CAPABILITY_REQUEST:
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_IO_CAPABILITIES_REQUEST); hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_IO_CAPABILITIES_REQUEST);
if (hci_stack.ssp_io_capability == SSP_IO_CAPABILITY_UNKNOWN) break; if (hci_stack.ssp_io_capability == SSP_IO_CAPABILITY_UNKNOWN) break;
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SENT_IO_CAPABILITIES_REPLY); hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_IO_CAPABILITIES_REPLY);
break;
case HCI_EVENT_USER_CONFIRMATION_REQUEST:
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_USER_CONFIRM_REQUEST);
if (!hci_stack.ssp_auto_accept) break;
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_USER_CONFIRM_REPLY);
break;
case HCI_EVENT_USER_PASSKEY_REQUEST:
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_USER_PASSKEY_REQUEST);
if (!hci_stack.ssp_auto_accept) break;
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], SEND_USER_PASSKEY_REPLY);
break; break;
#ifndef EMBEDDED #ifndef EMBEDDED
@ -1056,30 +1068,27 @@ void hci_run(){
uint8_t reason = hci_stack.decline_reason; uint8_t reason = hci_stack.decline_reason;
hci_stack.decline_reason = 0; hci_stack.decline_reason = 0;
hci_send_cmd(&hci_reject_connection_request, hci_stack.decline_addr, reason); hci_send_cmd(&hci_reject_connection_request, hci_stack.decline_addr, reason);
return;
} }
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
// send scan enable // send scan enable
if (hci_stack.state == HCI_STATE_WORKING && hci_stack.new_scan_enable_value != 0xff){ if (hci_stack.state == HCI_STATE_WORKING && hci_stack.new_scan_enable_value != 0xff){
hci_send_cmd(&hci_write_scan_enable, hci_stack.new_scan_enable_value); hci_send_cmd(&hci_write_scan_enable, hci_stack.new_scan_enable_value);
hci_stack.new_scan_enable_value = 0xff; hci_stack.new_scan_enable_value = 0xff;
return;
} }
// send pending HCI commands // send pending HCI commands
for (it = (linked_item_t *) hci_stack.connections; it ; it = it->next){ for (it = (linked_item_t *) hci_stack.connections; it ; it = it->next){
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
connection = (hci_connection_t *) it; connection = (hci_connection_t *) it;
if (connection->state == RECEIVED_CONNECTION_REQUEST){ if (connection->state == RECEIVED_CONNECTION_REQUEST){
log_info("sending hci_accept_connection_request\n"); log_info("sending hci_accept_connection_request\n");
hci_send_cmd(&hci_accept_connection_request, connection->address, 1); hci_send_cmd(&hci_accept_connection_request, connection->address, 1);
connection->state = ACCEPTED_CONNECTION_REQUEST; connection->state = ACCEPTED_CONNECTION_REQUEST;
return;
} }
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
if (connection->authentication_flags & HANDLE_LINK_KEY_REQUEST){ if (connection->authentication_flags & HANDLE_LINK_KEY_REQUEST){
link_key_t link_key; link_key_t link_key;
@ -1090,18 +1099,28 @@ void hci_run(){
hci_send_cmd(&hci_link_key_request_negative_reply, connection->address); hci_send_cmd(&hci_link_key_request_negative_reply, connection->address);
} }
connectionClearAuthenticationFlags(connection, HANDLE_LINK_KEY_REQUEST); connectionClearAuthenticationFlags(connection, HANDLE_LINK_KEY_REQUEST);
return;
} }
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return; if (connection->authentication_flags & SEND_IO_CAPABILITIES_REPLY){
hci_send_cmd(&hci_io_capability_request_reply, &connection->address, hci_stack.ssp_io_capability, NULL, hci_stack.ssp_authentication_requirement);
connectionClearAuthenticationFlags(connection, SEND_IO_CAPABILITIES_REPLY);
return;
}
if (connection->authentication_flags & SENT_IO_CAPABILITIES_REPLY){ if (connection->authentication_flags & SEND_USER_CONFIRM_REPLY){
hci_send_cmd(&hci_io_capability_request_reply, hci_stack.ssp_io_capability, NULL, hci_stack.ssp_authentication_requirement); hci_send_cmd(&hci_user_confirmation_request_reply, &connection->address);
connectionClearAuthenticationFlags(connection, SENT_IO_CAPABILITIES_REPLY); connectionClearAuthenticationFlags(connection, SEND_USER_CONFIRM_REPLY);
return;
}
if (connection->authentication_flags & SEND_USER_PASSKEY_REPLY){
hci_send_cmd(&hci_user_passkey_request_reply, &connection->address, 000000);
connectionClearAuthenticationFlags(connection, SEND_USER_PASSKEY_REPLY);
return;
} }
} }
if (!hci_can_send_packet_now(HCI_COMMAND_DATA_PACKET)) return;
switch (hci_stack.state){ switch (hci_stack.state){
case HCI_STATE_INITIALIZING: case HCI_STATE_INITIALIZING:
// log_info("hci_init: substate %u\n", hci_stack.substate); // log_info("hci_init: substate %u\n", hci_stack.substate);
@ -1337,6 +1356,26 @@ int hci_send_cmd_packet(uint8_t *packet, int size){
return hci_stack.hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size); return hci_stack.hci_transport->send_packet(HCI_COMMAND_DATA_PACKET, packet, size);
} }
// Configure Secure Simple Pairing
// enable will enable SSP during init
void hci_ssp_set_enable(int enable){
hci_stack.ssp_enable = enable;
}
// if set, BTstack will respond to io capability request using authentication requirement
void hci_ssp_set_io_capability(int io_capability){
hci_stack.ssp_io_capability = io_capability;
}
void hci_ssp_set_authentication_requirement(int authentication_requirement){
hci_stack.ssp_authentication_requirement = authentication_requirement;
}
// if set, BTstack will confirm a numberic comparion and enter '000000' if requested
void hci_ssp_set_auto_accept(int auto_accept){
hci_stack.ssp_auto_accept = auto_accept;
}
/** /**
* pre: numcmds >= 0 - it's allowed to send a command to the controller * pre: numcmds >= 0 - it's allowed to send a command to the controller
*/ */

View File

@ -196,18 +196,22 @@ extern "C" {
* Connection State * Connection State
*/ */
typedef enum { typedef enum {
AUTH_FLAGS_NONE = 0x00, AUTH_FLAGS_NONE = 0x0000,
RECV_LINK_KEY_REQUEST = 0x01, RECV_LINK_KEY_REQUEST = 0x0001,
HANDLE_LINK_KEY_REQUEST = 0x02, HANDLE_LINK_KEY_REQUEST = 0x0002,
SENT_LINK_KEY_REPLY = 0x04, SENT_LINK_KEY_REPLY = 0x0004,
SENT_LINK_KEY_NEGATIVE_REQUEST = 0x08, SENT_LINK_KEY_NEGATIVE_REQUEST = 0x0008,
RECV_LINK_KEY_NOTIFICATION = 0x10, RECV_LINK_KEY_NOTIFICATION = 0x0010,
RECV_PIN_CODE_REQUEST = 0x20, RECV_PIN_CODE_REQUEST = 0x0020,
SENT_PIN_CODE_REPLY = 0x40, SENT_PIN_CODE_REPLY = 0x0040,
SENT_PIN_CODE_NEGATIVE_REPLY = 0x80, SENT_PIN_CODE_NEGATIVE_REPLY = 0x0080,
// SSP // SSP
RECV_IO_CAPABILITIES_REQUEST = 0x100; RECV_IO_CAPABILITIES_REQUEST = 0x0100,
SENT_IO_CAPABILITIES_REPLY = 0x200; SEND_IO_CAPABILITIES_REPLY = 0x0200,
RECV_USER_CONFIRM_REQUEST = 0x0400,
SEND_USER_CONFIRM_REPLY = 0x0800,
RECV_USER_PASSKEY_REQUEST = 0x1000,
SEND_USER_PASSKEY_REPLY = 0x2000,
} hci_authentication_flags_t; } hci_authentication_flags_t;
typedef enum { typedef enum {
@ -378,7 +382,7 @@ int hci_power_control(HCI_POWER_MODE mode);
// Allows to control if device is discoverable. OFF by default. // Allows to control if device is discoverable. OFF by default.
void hci_discoverable_control(uint8_t enable); void hci_discoverable_control(uint8_t enable);
// Creates and sends hci command packets based on a template and // Creates and sends HCI command packets based on a template and
// a list of parameters. Will return error if outgoing data buffer // a list of parameters. Will return error if outgoing data buffer
// is occupied. // is occupied.
int hci_send_cmd(const hci_cmd_t *cmd, ...); int hci_send_cmd(const hci_cmd_t *cmd, ...);
@ -386,6 +390,17 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...);
// Deletes link key for remote device with baseband address. // Deletes link key for remote device with baseband address.
void hci_drop_link_key_for_bd_addr(bd_addr_t *addr); void hci_drop_link_key_for_bd_addr(bd_addr_t *addr);
// Configure Secure Simple Pairing
// enable will enable SSP during init
void hci_ssp_set_enable(int enable);
// if set, BTstack will respond to io capability request using authentication requirement
void hci_ssp_set_io_capability(int ssp_io_capability);
void hci_ssp_set_authentication_requirement(int authentication_requirement);
// if set, BTstack will confirm a numberic comparion and enter '000000' if requested
void hci_ssp_set_auto_accept(int auto_accept);
#if defined __cplusplus #if defined __cplusplus
} }