read remote supported features and check for SSP on new connections

This commit is contained in:
matthias.ringwald@gmail.com 2014-01-16 14:47:36 +00:00
parent f8fb5f6e47
commit afd4e962dc
4 changed files with 36 additions and 2 deletions

View File

@ -372,6 +372,7 @@ extern const hci_cmd_t hci_read_link_policy_settings;
extern const hci_cmd_t hci_read_link_supervision_timeout;
extern const hci_cmd_t hci_read_local_supported_features;
extern const hci_cmd_t hci_read_num_broadcast_retransmissions;
extern const hci_cmd_t hci_read_remote_supported_features_command;
extern const hci_cmd_t hci_reject_connection_request;
extern const hci_cmd_t hci_remote_name_request;
extern const hci_cmd_t hci_remote_name_request_cancel;

View File

@ -129,6 +129,7 @@ static hci_connection_t * create_connection_for_addr(bd_addr_t addr){
BD_ADDR_COPY(conn->address, addr);
conn->con_handle = 0xffff;
conn->authentication_flags = AUTH_FLAGS_NONE;
conn->bonding_flags = 0;
linked_item_set_user(&conn->timeout.item, conn);
conn->timeout.process = hci_connection_timeout_handler;
hci_connection_timestamp(conn);
@ -599,7 +600,8 @@ static void event_handler(uint8_t *packet, int size){
if (!packet[2]){
conn->state = OPEN;
conn->con_handle = READ_BT_16(packet, 3);
conn->bonding_flags = BONDING_REQUEST_REMOTE_FEATURES;
// restart timer
run_loop_set_timer(&conn->timeout, HCI_CONNECTION_TIMEOUT_MS);
run_loop_add_timer(&conn->timeout);
@ -620,6 +622,19 @@ static void event_handler(uint8_t *packet, int size){
}
break;
case HCI_EVENT_READ_REMOTE_SUPPORTED_FEATURES_COMPLETE:
handle = READ_BT_16(packet, 3);
conn = hci_connection_for_handle(handle);
if (!conn) break;
if (!packet[2]){
uint8_t * features = &packet[5];
if (features[6] & (1 << 3)){
conn->bonding_flags |= BONDING_REMOTE_SUPPORTS_SSP;
}
}
conn->bonding_flags |= BONDING_RECEIVED_REMOTE_FEATURES;
break;
case HCI_EVENT_LINK_KEY_REQUEST:
log_info("HCI_EVENT_LINK_KEY_REQUEST\n");
hci_add_connection_flags_for_flipped_bd_addr(&packet[2], RECV_LINK_KEY_REQUEST);
@ -1231,6 +1246,11 @@ void hci_run(){
connectionClearAuthenticationFlags(connection, SEND_USER_PASSKEY_REPLY);
return;
}
if (connection->bonding_flags & BONDING_REQUEST_REMOTE_FEATURES){
hci_send_cmd(&hci_read_remote_supported_features_command, connection->con_handle);
connection->bonding_flags &= ~BONDING_REQUEST_REMOTE_FEATURES;
}
}
switch (hci_stack.state){

View File

@ -227,6 +227,12 @@ typedef enum {
SENT_DISCONNECT
} CONNECTION_STATE;
typedef enum {
BONDING_REQUEST_REMOTE_FEATURES = 0x01,
BONDING_RECEIVED_REMOTE_FEATURES = 0x02,
BONDING_REMOTE_SUPPORTS_SSP = 0x04,
} bonding_flags_t;
typedef enum {
BLUETOOTH_OFF = 1,
BLUETOOTH_ON,
@ -243,9 +249,12 @@ typedef struct {
// module handle
hci_con_handle_t con_handle;
// state
// connection state
CONNECTION_STATE state;
// bonding
bonding_flags_t bonding_flags;
// errands
hci_authentication_flags_t authentication_flags;

View File

@ -248,6 +248,10 @@ const hci_cmd_t hci_remote_name_request_cancel = {
OPCODE(OGF_LINK_CONTROL, 0x1A), "B"
// BD_ADDR
};
const hci_cmd_t hci_read_remote_supported_features_command = {
OPCODE(OGF_LINK_CONTROL, 0x1B), "H"
// BD_ADDR
};
const hci_cmd_t hci_io_capability_request_reply = {
OPCODE(OGF_LINK_CONTROL, 0x2b), "B111"
// BD_ADDR, IO_Capability, OOB_Data_Present, Authentication_ Requirements