Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a0bc90f9 authored by Jacky Cheung's avatar Jacky Cheung
Browse files

DO NOT MERGE ANYWHERE SMP: Delay authorization complete.

Delay authorization complete during Bond Pending state in SMP.
Instead of automatically advancing the Bond Pending state, create
a 500ms window to allow the slave to stop pairing by sending over
the Pairing Failed command during the Bond Pending state.

BUG: 28475887
Change-Id: I164e8312fdf9170d0f36caf404fc42e293ed5d79
parent 087527c5
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -517,6 +517,12 @@ static void btu_l2cap_alarm_process(TIMER_LIST_ENT *p_tle) {
      l2c_process_timeout (p_tle);
      l2c_process_timeout (p_tle);
      break;
      break;


#if (defined(SMP_INCLUDED) && SMP_INCLUDED == TRUE)
    case BTU_TTYPE_SMP_DELAYED_AUTH:
      smp_delayed_auth_complete_timeout(p_tle);
      break;
#endif

    default:
    default:
      break;
      break;
  }
  }
+1 −0
Original line number Original line Diff line number Diff line
@@ -160,6 +160,7 @@ typedef void (*tBTU_EVENT_CALLBACK)(BT_HDR *p_hdr);




#define BTU_TTYPE_UCD_TO                            108
#define BTU_TTYPE_UCD_TO                            108
#define BTU_TTYPE_SMP_DELAYED_AUTH                  109


/* This is the inquiry response information held by BTU, and available
/* This is the inquiry response information held by BTU, and available
** to applications.
** to applications.
+24 −2
Original line number Original line Diff line number Diff line
@@ -517,6 +517,12 @@ void smp_proc_pair_fail(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
{
{
    SMP_TRACE_DEBUG("%s", __func__);
    SMP_TRACE_DEBUG("%s", __func__);
    p_cb->status = *(UINT8 *)p_data;
    p_cb->status = *(UINT8 *)p_data;

    /* Cancel pending auth complete timer if set */
    if (p_cb->delayed_auth_timer_enabled) {
        btu_stop_quick_timer(&p_cb->delayed_auth_timer_ent);
        p_cb->delayed_auth_timer_enabled = FALSE;
    }
}
}


/*******************************************************************************
/*******************************************************************************
@@ -1269,12 +1275,28 @@ void smp_key_distribution(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
            }
            }


            if (p_cb->total_tx_unacked == 0)
            if (p_cb->total_tx_unacked == 0)
                smp_sm_event(p_cb, SMP_AUTH_CMPL_EVT, &reason);
            {
            else
                /*
                 * Instead of declaring authorization complete immediately,
                 * delay the event from being sent until 500ms later.
                 * This allows the slave to send over Pairing Failed if the
                 * last key is rejected.  During this waiting window, the
                 * state should remain in SMP_STATE_BOND_PENDING.
                 */
                if (!p_cb->delayed_auth_timer_enabled)
                {
                    SMP_TRACE_DEBUG("%s delaying auth complete.", __func__);
                    btu_start_quick_timer(&p_cb->delayed_auth_timer_ent,
                                          BTU_TTYPE_SMP_DELAYED_AUTH,
                                          SMP_DELAYED_AUTH_TOUT);
                    p_cb->delayed_auth_timer_enabled = TRUE;
                }
            } else {
                p_cb->wait_for_authorization_complete = TRUE;
                p_cb->wait_for_authorization_complete = TRUE;
            }
            }
        }
        }
    }
    }
}


/*******************************************************************************
/*******************************************************************************
** Function         smp_decide_association_model
** Function         smp_decide_association_model
+4 −0
Original line number Original line Diff line number Diff line
@@ -51,6 +51,7 @@ typedef UINT8 tSMP_ASSO_MODEL;
#endif
#endif


#define SMP_WAIT_FOR_RSP_TOUT           30
#define SMP_WAIT_FOR_RSP_TOUT           30
#define SMP_DELAYED_AUTH_TOUT           5   /* 500ms delay before authorization complete */


#define SMP_OPCODE_INIT                   0x04
#define SMP_OPCODE_INIT                   0x04


@@ -339,6 +340,8 @@ typedef struct
    UINT8           rcvd_cmd_len;
    UINT8           rcvd_cmd_len;
    UINT16          total_tx_unacked;
    UINT16          total_tx_unacked;
    BOOLEAN         wait_for_authorization_complete;
    BOOLEAN         wait_for_authorization_complete;
    BOOLEAN         delayed_auth_timer_enabled;  /* TRUE if delayed_auth_timer_ent is started */
    TIMER_LIST_ENT  delayed_auth_timer_ent;      /* timer to delay auth complete */
}tSMP_CB;
}tSMP_CB;


/* Server Action functions are of this type */
/* Server Action functions are of this type */
@@ -480,6 +483,7 @@ extern void smp_proc_pairing_cmpl(tSMP_CB *p_cb);
extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey);
extern void smp_convert_string_to_tk(BT_OCTET16 tk, UINT32 passkey);
extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 * p_data);
extern void smp_mask_enc_key(UINT8 loc_enc_size, UINT8 * p_data);
extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle);
extern void smp_rsp_timeout(TIMER_LIST_ENT *p_tle);
extern void smp_delayed_auth_complete_timeout(TIMER_LIST_ENT *p_tle);
extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b);
extern void smp_xor_128(BT_OCTET16 a, BT_OCTET16 b);
extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
extern BOOLEAN smp_encrypt_data (UINT8 *key, UINT8 key_len,
                                 UINT8 *plain_text, UINT8 pt_len,
                                 UINT8 *plain_text, UINT8 pt_len,
+1 −1
Original line number Original line Diff line number Diff line
@@ -240,7 +240,7 @@ static const UINT8 smp_master_entry_map[][SMP_STATE_MAX] =
/* PAIR_RSP             */{ 0,    0,     0,      1,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    0,     0   },
/* PAIR_RSP             */{ 0,    0,     0,      1,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    0,     0   },
/* CONFIRM              */{ 0,    0,     0,      0,     0,   1,    0,   0,      0,      0,    0,    0,      0,     0,     0,    0,     0   },
/* CONFIRM              */{ 0,    0,     0,      0,     0,   1,    0,   0,      0,      0,    0,    0,      0,     0,     0,    0,     0   },
/* RAND                 */{ 0,    0,     0,      0,     0,   0,    1,   0,      0,      0,    1,    0,      0,     0,     0,    0,     0   },
/* RAND                 */{ 0,    0,     0,      0,     0,   0,    1,   0,      0,      0,    1,    0,      0,     0,     0,    0,     0   },
/* PAIR_FAIL            */{ 0,    0x81,  0,      0x81,  0x81,0x81, 0x81,0x81,   0x81,   0x81, 0x81, 0x81,   0x81,  0x81,  0,    0,     0   },
/* PAIR_FAIL            */{ 0,    0x81,  0,      0x81,  0x81,0x81, 0x81,0x81,   0x81,   0x81, 0x81, 0x81,   0x81,  0x81,  0,    0x81,  0   },
/* ENC_INFO             */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    1,     0   },
/* ENC_INFO             */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    1,     0   },
/* MASTER_ID            */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    4,     0   },
/* MASTER_ID            */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    4,     0   },
/* ID_INFO              */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    2,     0   },
/* ID_INFO              */{ 0,    0,     0,      0,     0,   0,    0,   0,      0,      0,    0,    0,      0,     0,     0,    2,     0   },
Loading