/***************** 嵌入式代码开发*************/
/* 更多例程:https://iot666.blog.csdn.net/ */
/* 技术咨询:https://yotill.taobao.com/ */
/* 网盘下载:http://doc.yotill.com/ */
/****** Powered by YOTILL,IOT Solution *******/
////////////////////////////////////////////////////////
/**************************************************************************************************
Filename: gapbondmgr.c
Revised: $Date: 2011-02-24 15:46:53 -0800 (Thu, 24 Feb 2011) $
Revision: $Revision: 10 $
Description: GAP peripheral profile manages bonded connections
Copyright 2011-2013 Texas Instruments Incorporated. All rights reserved.
IMPORTANT: Your use of this Software is limited to those specific rights
granted under the terms of a software license agreement between the user
who downloaded the software, his/her employer (which must be your employer)
and Texas Instruments Incorporated (the "License"). You may not use this
Software unless you agree to abide by the terms of the License. The License
limits your use, and you acknowledge, that the Software may not be modified,
copied or distributed unless embedded on a Texas Instruments microcontroller
or used solely and exclusively in conjunction with a Texas Instruments radio
frequency transceiver, which is integrated into your product. Other than for
the foregoing purpose, you may not use, reproduce, copy, prepare derivative
works of, modify, distribute, perform, display or sell this Software and/or
its documentation for any purpose.
YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
PROVIDED 揂S IS� WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
(INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
Should you have any questions regarding your right to use this Software,
contact Texas Instruments Incorporated at www.TI.com.
**************************************************************************************************/
#if ( HOST_CONFIG & ( CENTRAL_CFG | PERIPHERAL_CFG ) )
/*********************************************************************
* INCLUDES
*/
#include "bcomdef.h"
#include "OSAL.h"
#include "osal_snv.h"
#include "gap.h"
#include "linkdb.h"
#include "gatt.h"
#include "gatt_uuid.h"
#include "hci.h"
#include "gattservapp.h"
#include "gapgattserver.h"
#include "gapbondmgr.h"
/*********************************************************************
* MACROS
*/
/*********************************************************************
* CONSTANTS
*/
// Task event types
#define GAP_BOND_SYNC_CC_EVT 0x0001 // Sync char config
// Once NV usage reaches this percentage threshold, NV compaction gets triggered.
#define NV_COMPACT_THRESHOLD 80
// Bonded State Flags
#define GAP_BONDED_STATE_AUTHENTICATED 0x0001
#define GAP_BONDED_STATE_SERVICE_CHANGED 0x0002
/**
* GAP Bond Manager NV layout
*
* The NV definitions:
* BLE_NVID_GAP_BOND_START - starting NV ID
* GAP_BONDINGS_MAX - Maximum number of bonding allowed (10 is max for number of NV IDs allocated in bcomdef.h).
*
* A single bonding entry consists of 6 components (NV items):
* Bond Record - defined as gapBondRec_t and uses GAP_BOND_REC_ID_OFFSET for an NV ID
* local LTK Info - defined as gapBondLTK_t and uses GAP_BOND_LOCAL_LTK_OFFSET for an NV ID
* device LTK Info - defined as gapBondLTK_t and uses GAP_BOND_DEV_LTK_OFFSET for an NV ID
* device IRK - defined as "uint8 devIRK[KEYLEN]" and uses GAP_BOND_DEV_IRK_OFFSET for an NV ID
* device CSRK - defined as "uint8 devCSRK[KEYLEN]" and uses GAP_BOND_DEV_CSRK_OFFSET for an NV ID
* device Sign Counter - defined as a uint32 and uses GAP_BOND_DEV_SIGN_COUNTER_OFFSET for an NV ID
*
* When the device is initialized for the first time, all (GAP_BONDINGS_MAX) NV items are created and
* initialized to all 0xFF's. A bonding record of all 0xFF's indicates that the bonding record is empty
* and free to use.
*
* The calculation for each bonding records NV IDs:
* mainRecordNvID = ((bondIdx * GAP_BOND_REC_IDS) + BLE_NVID_GAP_BOND_START)
* localLTKNvID = (((bondIdx * GAP_BOND_REC_IDS) + GAP_BOND_LOCAL_LTK_OFFSET) + BLE_NVID_GAP_BOND_START)
*
*/
#define GAP_BOND_REC_ID_OFFSET 0 //!< NV ID for the main bonding record
#define GAP_BOND_LOCAL_LTK_OFFSET 1 //!< NV ID for the bonding record's local LTK information
#define GAP_BOND_DEV_LTK_OFFSET 2 //!< NV ID for the bonding records' device LTK information
#define GAP_BOND_DEV_IRK_OFFSET 3 //!< NV ID for the bonding records' device IRK
#define GAP_BOND_DEV_CSRK_OFFSET 4 //!< NV ID for the bonding records' device CSRK
#define GAP_BOND_DEV_SIGN_COUNTER_OFFSET 5 //!< NV ID for the bonding records' device Sign Counter
#define GAP_BOND_REC_IDS 6
// Macros to calculate the index/offset in to NV space
#define calcNvID(Idx, offset) (((((Idx) * GAP_BOND_REC_IDS) + (offset))) + BLE_NVID_GAP_BOND_START)
#define mainRecordNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_REC_ID_OFFSET))
#define localLTKNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_LOCAL_LTK_OFFSET))
#define devLTKNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_DEV_LTK_OFFSET))
#define devIRKNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_DEV_IRK_OFFSET))
#define devCSRKNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_DEV_CSRK_OFFSET))
#define devSignCounterNvID(bondIdx) (calcNvID((bondIdx), GAP_BOND_DEV_SIGN_COUNTER_OFFSET))
// Macros to calculate the GATT index/offset in to NV space
#define gattCfgNvID(Idx) ((Idx) + BLE_NVID_GATT_CFG_START)
// Key Size Limits
#define MIN_ENC_KEYSIZE 7 //!< Minimum number of bytes for the encryption key
#define MAX_ENC_KEYSIZE 16 //!< Maximum number of bytes for the encryption key
/*********************************************************************
* TYPEDEFS
*/
// Structure of NV data for the connected device's encryption information
typedef struct
{
uint8 LTK[KEYLEN]; // Long Term Key (LTK)
uint16 div; //lint -e754 // LTK eDiv
uint8 rand[B_RANDOM_NUM_SIZE]; // LTK random number
uint8 keySize; // LTK key size
} gapBondLTK_t;
// Structure of NV data for the connected device's address information
typedef struct
{
uint8 publicAddr[B_ADDR_LEN]; // Master's address
uint8 reconnectAddr[B_ADDR_LEN]; // Privacy Reconnection Address
uint16 stateFlags; // State flags: SM_AUTH_STATE_AUTHENTICATED & SM_AUTH_STATE_BONDING
} gapBondRec_t;
// Structure of NV data for the connected device's characteristic configuration
typedef struct
{
uint16 attrHandle; // attribute handle
uint8 value; // attribute value for this device
} gapBondCharCfg_t;
/*********************************************************************
* GLOBAL VARIABLES
*/
/*********************************************************************
* EXTERNAL VARIABLES
*/
/*******
没有合适的资源?快使用搜索试试~ 我知道了~
BLE蓝牙单片机CC2540、CC2541带OSAL操作系统的例程-蓝牙从机广播数据长度和数值的修改.zip
共338个文件
h:145个
c:124个
lib:19个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 115 浏览量
2024-12-18
20:33:25
上传
评论
收藏 8.69MB ZIP 举报
温馨提示
1、嵌入式物联网单片机项目开发例程,简单、方便、好用,节省开发时间。 2、代码使用IAR软件开发,当前在CC2540/CC2541上运行,如果是其他型号芯片,请自行调整。 3、软件下载时,请注意接上硬件,并确认烧录器连接正常。 4、有偿指导v:wulianjishu666; 5、如果接入其他传感器,请查看账号发布的其他资料。 6、单片机与模块的接线,在代码当中均有定义,请自行对照。 7、若硬件有差异,请根据自身情况调整代码,程序仅供参考学习。 8、代码有注释说明,请耐心阅读。
资源推荐
资源详情
资源评论
收起资源包目录
BLE蓝牙单片机CC2540、CC2541带OSAL操作系统的例程-蓝牙从机广播数据长度和数值的修改.zip (338个子文件)
BLE读写器(无源码通用工具).apk 47KB
cc254x_ubl_pp.bat 4KB
SimpleBLEPeripheral.cspy.bat 1KB
SimpleBLEPeripheral.cspy.bat 1KB
gapbondmgr.c 64KB
gapperiphbondmgr.c 45KB
hal_lcd.c 41KB
hal_lcd.c 41KB
hiddev.c 39KB
peripheral.c 38KB
_hal_uart_dma.c 34KB
_hal_uart_dma.c 34KB
_hal_uart_spi.c 34KB
_hal_uart_spi.c 34KB
OSAL.c 33KB
peripheralBroadcaster.c 32KB
hidkbmservice.c 32KB
simpleBLEPeripheral.c 28KB
hal_motion.c 25KB
runningservice.c 25KB
cyclingservice.c 25KB
osal_snv.c 25KB
hidkbdservice.c 24KB
thermometerservice.c 24KB
usb_standard_requests.c 23KB
hal_key.c 23KB
simpleGATTprofile.c 22KB
hal_sleep.c 22KB
hal_sleep.c 22KB
hal_sleep.c 22KB
hal_key.c 22KB
OSAL_Memory.c 22KB
oad_target.c 22KB
hal_sleep.c 21KB
accelerometer.c 21KB
glucservice.c 21KB
battservice.c 19KB
_hal_uart_isr.c 19KB
_hal_uart_isr.c 19KB
devinfoservice.c 19KB
hal_i2c.c 19KB
central.c 19KB
proxreporter.c 19KB
magnetometerservice.c 19KB
bpservice.c 19KB
barometerservice.c 19KB
broadcaster.c 18KB
accelerometerservice.c 18KB
OSAL_Timers.c 17KB
hal_accel.c 17KB
hal_gyro.c 16KB
hal_led.c 16KB
hal_led.c 16KB
irtempservice.c 16KB
hal_led.c 16KB
humidityservice.c 16KB
gyroservice.c 16KB
testservice.c 16KB
heartrateservice.c 16KB
hal_keys.c 15KB
hal_gyro.c 15KB
scanparamservice.c 15KB
simplekeys.c 13KB
hal_aes.c 13KB
hal_aes.c 13KB
hal_aes.c 13KB
hal_aes.c 13KB
hal_bar.c 12KB
hal_irtemp.c 12KB
usb_descriptor_parser.c 12KB
usb_framework.c 12KB
usb_framework.c 12KB
hal_drivers.c 12KB
npi.c 11KB
hal_uart.c 11KB
hal_uart.c 11KB
_hal_uart_usb.c 11KB
hal_acc.c 11KB
hal_mag.c 11KB
usb_class_requests.c 11KB
osal_cbtimer.c 11KB
OnBoard.c 10KB
OSAL_ClockBLE.c 10KB
hal_humi.c 10KB
hal_i2c.c 10KB
hal_assert.c 10KB
hal_key.c 10KB
gatt_uuid.c 10KB
usb_descriptor_parser.c 9KB
hal_adc.c 9KB
hal_adc.c 9KB
observer.c 9KB
osal_bufmgr.c 9KB
hal_drivers.c 9KB
hal_buzzer.c 9KB
hal_sensor.c 7KB
usb_cdc_hooks.c 7KB
gap.c 7KB
OSAL_PwrMgr.c 7KB
hal_flash.c 7KB
共 338 条
- 1
- 2
- 3
- 4
资源评论
边缘计算网关定制开发
- 粉丝: 3250
- 资源: 937
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功