mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
acda125e8b
# Conflicts: # components/bt/bluedroid/profiles/core/bt_prf_sys_main.c # components/bt/bluedroid/profiles/core/bt_prf_task.c # components/bt/bluedroid/profiles/core/include/bt_prf_sys.h # components/bt/bluedroid/profiles/core/include/bt_prf_task.h # components/bt/bluedroid/profiles/esp/include/wx_airsync_prf.h # components/bt/bluedroid/profiles/esp/wechat_AirSync/wx_airsync_prf.c # components/bt/bluedroid/stack/btm/btm_sec.c
109 lines
2.7 KiB
C
109 lines
2.7 KiB
C
/**
|
|
****************************************************************************************
|
|
*
|
|
* @file bt_app_sec.c
|
|
*
|
|
* @brief Application entry point
|
|
*
|
|
* Copyright (C) Espressif 2016
|
|
* Created by Yulong at 2016/10/13
|
|
*
|
|
*
|
|
****************************************************************************************
|
|
*/
|
|
|
|
#include "bt_app_sec.h"
|
|
#include <stdlib.h> // standard library
|
|
#include <string.h>
|
|
|
|
|
|
|
|
extern void srand (unsigned int seed);
|
|
extern int random (void);
|
|
|
|
/// Application Security Environment Structure
|
|
tAPP_SEC_ENV app_sec_env;
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function app_ble_sec_gen_tk
|
|
**
|
|
** Description This function is called to generate the ble tk
|
|
**
|
|
** Returns the generate tk value
|
|
**
|
|
*******************************************************************************/
|
|
UINT32 app_ble_sec_gen_tk(void)
|
|
{
|
|
// Generate a PIN Code (Between 100000 and 999999)
|
|
return (100000 + (random()%900000));
|
|
}
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function app_ble_sec_gen_ltk
|
|
**
|
|
** Description This function is called to generate the ble ltk
|
|
**
|
|
** Returns NULL
|
|
**
|
|
*******************************************************************************/
|
|
void app_ble_sec_gen_ltk(UINT8 key_size)
|
|
{
|
|
// Counter
|
|
UINT8 i;
|
|
app_sec_env.key_size = key_size;
|
|
|
|
// Randomly generate the LTK and the Random Number
|
|
for (i = 0; i < RAND_NB_LEN; i++)
|
|
{
|
|
app_sec_env.rand_nb.nb[i] = random()%256;
|
|
}
|
|
|
|
// Randomly generate the end of the LTK
|
|
for (i = 0; i < SEC_KEY_LEN; i++)
|
|
{
|
|
app_sec_env.ltk.key[i] = (((key_size) < (16 - i)) ? 0 : random()%256);
|
|
}
|
|
|
|
// Randomly generate the EDIV
|
|
app_sec_env.ediv = random()%65536;
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function app_ble_sec_init
|
|
**
|
|
** Description This function is init the security env and function
|
|
**
|
|
** Returns NULL
|
|
**
|
|
*******************************************************************************/
|
|
void app_ble_sec_init()
|
|
{
|
|
// Reset Security Environment
|
|
memset(&app_sec_env, 0, sizeof(app_sec_env));
|
|
}
|
|
|
|
|
|
/*******************************************************************************
|
|
**
|
|
** Function app_ble_security_start
|
|
**
|
|
** Description This function is called by the slave when the seurity start
|
|
**
|
|
** Returns NULL
|
|
**
|
|
*******************************************************************************/
|
|
void app_ble_security_start(void)
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|