This commit is contained in:
moyuhai
2026-06-11 13:04:09 +08:00
commit 966451d245
2022 changed files with 513671 additions and 0 deletions
+286
View File
@@ -0,0 +1,286 @@
/**
****************************************************************************************
*
* @file em_map_bt.h
*
* @brief Mapping of the different descriptors in the exchange memory
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef EM_MAP_BT_H_
#define EM_MAP_BT_H_
/**
****************************************************************************************
* @addtogroup EM Exchange Memory
* @ingroup CONTROLLER
* @brief Mapping of the different descriptors in the exchange memory
*
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h"
#include <stdint.h> // integer
#include "_reg_em_bt_cs.h"
#include "_reg_em_bt_rxdesc.h"
#include "_reg_em_bt_txdesc.h"
/// Null pointer in EM offset space
#define EM_PTR_NULL (0x0000)
/*
* CONTROL STRUCTURES
****************************************************************************************
*/
/**
* Control Structures area definition
*
* - ACL (N)
* - INQ
* - ISCAN
* - Active slave broadcast
* - Sync train
* - Sync scan
* - Connectionless slave broadcast TX
* - Connectionless slave broadcast RX
*/
#define EM_BT_CS_OFFSET (CO_ALIGN4_HI(EM_BT_OFFSET))
#define EM_BT_CS_NB (MAX_NB_ACTIVE_ACL+5+2*CSB_SUPPORT)
#define EM_BT_CS_END (EM_BT_CS_OFFSET + EM_BT_CS_NB * REG_EM_BT_CS_SIZE)
/**
* Control Structures indexes definition
*/
#define EM_BT_CS_ACL_INDEX(acl) (acl)
#define EM_BT_CS_IDX_TO_LID(idx) (idx)
#define EM_BT_CS_INQ_INDEX (MAX_NB_ACTIVE_ACL)
#define EM_BT_CS_ISCAN_INDEX (EM_BT_CS_INQ_INDEX + 1)
#define EM_BT_CS_ACT_BCST_INDEX (EM_BT_CS_ISCAN_INDEX + 1)
#define EM_BT_CS_STRAIN_INDEX (EM_BT_CS_ACT_BCST_INDEX + 1)
#define EM_BT_CS_SSCAN_INDEX (EM_BT_CS_STRAIN_INDEX + 1)
#define EM_BT_CS_CSB_TX_INDEX (EM_BT_CS_SSCAN_INDEX + 1)
#define EM_BT_CS_CSB_RX_INDEX (EM_BT_CS_CSB_TX_INDEX + 1)
#define EM_BT_CS_INDEX_MAX (EM_BT_CS_CSB_RX_INDEX + 1)
/**
* Frame Format
* Bluetooth state and device activity used for frequency selection and TDD frame format. See section 3.5 for further details
* Note this field is automatically updated by the RW-BT Core when changing from Page to Master Page Response mode.
* - 0000x: Do not use. -
* - 00010: Master connect. Master device
* - 00011: Slave connect. Slave device
* - 00100: Page. Initiator device
* - 00101: Page scan. Responder device
* - 00110: Master page response. -
* - 00111: Slave page response. -
* - 01000: Inquiry. Initiator device
* - 01001: Inquiry response Responder device
* - 01010: Do not use. -
* - 01011: Do not use. -
* - 011xx: Do not use. -
* - 10xxx: Do not use. -
* - 11000: Master Broadcast Master device
* - 11001: Broadcast Scan Slave device
* - 11010: Master Access window. Master device
* - 11011: Slave Access window 1. Slave device
* - 11100: Slave Access window 2. Slave device
* - 11101: Do not use. -
* - 1111x: Do not use -
*/
#define EM_BT_CS_FMT_MST_CONNECT 0x02
#define EM_BT_CS_FMT_SLV_CONNECT 0x03
#define EM_BT_CS_FMT_PAGE 0x04
#define EM_BT_CS_FMT_PAGE_SCAN 0x05
#define EM_BT_CS_FMT_MST_PAGE_RSP 0x06
#define EM_BT_CS_FMT_SLV_PAGE_RSP 0x07
#define EM_BT_CS_FMT_INQUIRY 0x08
#define EM_BT_CS_FMT_INQ_RSP 0x09
#define EM_BT_CS_FMT_MST_BCST 0x18
#define EM_BT_CS_FMT_BCST_SCAN 0x19
#define EM_BT_CS_FMT_MST_ACC_WIN 0x1A
#define EM_BT_CS_FMT_SLV_ACC_WIN1 0x1B
#define EM_BT_CS_FMT_SLV_ACC_WIN2 0x1C
/// Maximum value of RXWINSZ field (8191)
#define EM_BT_CS_RXWINSZ_MAX ((1 << 13)-1)
/// Maximum value of MAXFRMTIME field (8191)
#define EM_BT_CS_MAXFRMTIME_MAX ((1 << 13)-1)
/*
* RX DESCRIPTORS
****************************************************************************************
*/
/**
* RX Descriptors area definition
*/
#define EM_BT_RXDESC_OFFSET (CO_ALIGN4_HI(EM_BT_CS_END))
#define EM_BT_RXDESC_NB (BT_RXDESC_NB)
#define EM_BT_RXDESC_END (EM_BT_RXDESC_OFFSET + EM_BT_RXDESC_NB * REG_EM_BT_RXDESC_SIZE)
/*
* TX DESCRIPTORS
****************************************************************************************
*/
/**
* TX Descriptors area definition
*
* - ACL (2xN)
* - Active slave broadcast
* - FHS
* - EIR
* - Sync train packet
* - Connectionless slave broadcast
*/
#define EM_BT_TXDESC_OFFSET (CO_ALIGN4_HI(EM_BT_RXDESC_END))
#define EM_BT_TXDESC_NB (2*MAX_NB_ACTIVE_ACL + 4 + CSB_SUPPORT)
#define EM_BT_TXDESC_END (EM_BT_TXDESC_OFFSET + EM_BT_TXDESC_NB * REG_EM_BT_TXDESC_SIZE)
#define EM_BT_TXDESC_ACL_INDEX(acl, tog) (2*acl + tog)
#define EM_BT_TXDESC_ACT_BCST_INDEX (2*MAX_NB_ACTIVE_ACL)
#define EM_BT_TXDESC_ISCANFHS_INDEX (EM_BT_TXDESC_ACT_BCST_INDEX + 1)
#define EM_BT_TXDESC_EIR_INDEX (EM_BT_TXDESC_ISCANFHS_INDEX + 1)
#define EM_BT_TXDESC_STP_INDEX (EM_BT_TXDESC_EIR_INDEX + 1)
#define EM_BT_TXDESC_CSB_INDEX (EM_BT_TXDESC_STP_INDEX + 1)
/*
* LMP RX BUFFERS
****************************************************************************************
*/
/// LMP RX buffers area definition
#define EM_BT_LMPRXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_TXDESC_END))
#define EM_BT_LMPRXBUF_NB (EM_BT_RXDESC_NB)
#define EM_BT_LMPRXBUF_SIZE (20)
#define EM_BT_LMPRXBUF_END (EM_BT_LMPRXBUF_OFFSET + EM_BT_LMPRXBUF_NB * EM_BT_LMPRXBUF_SIZE)
/*
* LMP TX BUFFERS
****************************************************************************************
*/
/// LMP TX buffers area definition
#define EM_BT_LMPTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_LMPRXBUF_END))
#define EM_BT_LMPTXBUF_NB (BT_LMP_BUF_NB_TX)
#define EM_BT_LMPTXBUF_SIZE (24)
#define EM_BT_LMPTXBUF_END (EM_BT_LMPTXBUF_OFFSET + EM_BT_LMPTXBUF_NB * EM_BT_LMPTXBUF_SIZE)
/*
* ISCAN FHS TX BUFFER
****************************************************************************************
*/
/// ISCAN FHS TX buffer area definition
#define EM_BT_ISCANFHSTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_LMPTXBUF_END))
#define EM_BT_ISCANFHSTXBUF_SIZE (20)
#define EM_BT_ISCANFHSTXBUF_END (EM_BT_ISCANFHSTXBUF_OFFSET + EM_BT_ISCANFHSTXBUF_SIZE)
/*
* PAGE FHS TX BUFFER
****************************************************************************************
*/
/// PAGE FHS TX buffer area definition
#define EM_BT_PAGEFHSTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_ISCANFHSTXBUF_END))
#define EM_BT_PAGEFHSTXBUF_SIZE (20)
#define EM_BT_PAGEFHSTXBUF_END (EM_BT_PAGEFHSTXBUF_OFFSET + EM_BT_PAGEFHSTXBUF_SIZE)
/*
* EIR TX BUFFER
****************************************************************************************
*/
/// EIR TX buffer area definition
#define EM_BT_EIRTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_PAGEFHSTXBUF_END))
#define EM_BT_EIRTXBUF_SIZE (240)
#define EM_BT_EIRTXBUF_END (EM_BT_EIRTXBUF_OFFSET + EM_BT_EIRTXBUF_SIZE)
/*
* SAM SUBMAP BUFFER
****************************************************************************************
*/
/// SAM SUBMAP (Local) buffer area definition
#define EM_BT_LOCAL_SAM_SUBMAP_OFFSET (CO_ALIGN4_HI(EM_BT_EIRTXBUF_END))
#define EM_BT_LOCAL_SAM_SUBMAP_SIZE (SAM_TYPE0_SUBMAP_LEN)
#define EM_BT_LOCAL_SAM_SUBMAP_END (EM_BT_LOCAL_SAM_SUBMAP_OFFSET + EM_BT_LOCAL_SAM_SUBMAP_SIZE)
/// SAM MAP (Peer) buffer area definition
#define EM_BT_PEER_SAM_MAP_OFFSET (CO_ALIGN4_HI(EM_BT_LOCAL_SAM_SUBMAP_END))
#define EM_BT_PEER_SAM_MAP_OFF(acl) (EM_BT_PEER_SAM_MAP_OFFSET + (acl * RW_PEER_SAM_MAP_MAX_LEN))
#define EM_BT_PEER_SAM_MAP_SIZE (MAX_NB_ACTIVE_ACL * RW_PEER_SAM_MAP_MAX_LEN) // HW restriction
#define EM_BT_PEER_SAM_MAP_END (EM_BT_PEER_SAM_MAP_OFFSET + EM_BT_PEER_SAM_MAP_SIZE)
/*
* STP TX BUFFER
****************************************************************************************
*/
/// Sync Train Packet TX buffer area definition
#define EM_BT_STPTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_PEER_SAM_MAP_END))
#define EM_BT_STPTXBUF_SIZE (28)
#define EM_BT_STPTXBUF_END (EM_BT_STPTXBUF_OFFSET + EM_BT_STPTXBUF_SIZE)
/*
* ACL RX BUFFERS
****************************************************************************************
*/
/// ACL RX buffers area definition
#define EM_BT_ACLRXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_STPTXBUF_END))
#define EM_BT_ACLRXBUF_NB (ACL_DATA_BUF_NB_RX)
#define EM_BT_ACLRXBUF_SIZE (1028)
#define EM_BT_ACLRXBUF_END (EM_BT_ACLRXBUF_OFFSET + EM_BT_ACLRXBUF_NB * EM_BT_ACLRXBUF_SIZE)
/*
* ACL TX BUFFERS
****************************************************************************************
*/
/// ACL TX buffers area definition
#define EM_BT_ACLTXBUF_OFFSET (CO_ALIGN4_HI(EM_BT_ACLRXBUF_END))
#define EM_BT_ACLTXBUF_NB (ACL_DATA_BUF_NB_TX)
#define EM_BT_ACLTXBUF_SIZE (1028)
#define EM_BT_ACLTXBUF_END (EM_BT_ACLTXBUF_OFFSET + EM_BT_ACLTXBUF_NB * EM_BT_ACLTXBUF_SIZE)
/*
* AUDIO RX BUFFERS
****************************************************************************************
*/
/// AUDIO buffers area definition
#define EM_BT_AUDIOBUF_OFFSET (CO_ALIGN4_HI(EM_BT_ACLTXBUF_END))
#define EM_BT_AUDIOBUF_NB (MAX_NB_SYNC)
#define EM_BT_AUDIOBUF_SIZE (2*1080) // (4*1080) !!! Maximum configuration (2 x eSCO-3EV5) not possible on Bubble
#define EM_BT_AUDIOBUF_END (EM_BT_AUDIOBUF_OFFSET + EM_BT_AUDIOBUF_NB * EM_BT_AUDIOBUF_SIZE)
#define EM_BT_AUDIOBUF_OFF(sco) (EM_BT_AUDIOBUF_OFFSET + (sco * EM_BT_AUDIOBUF_SIZE))
/*
* END
****************************************************************************************
*/
#define EM_BT_END (EM_BT_AUDIOBUF_END)
/// @} EM
#endif // EM_MAP_BT_H_
+70
View File
@@ -0,0 +1,70 @@
/**
****************************************************************************************
*
* @file rwbt.h
*
* @brief RWBT interrupt definitions
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef _RW_BT_H_
#define _RW_BT_H_
/**
****************************************************************************************
* @addtogroup ROOT
* @brief Entry points of the BT stack
*
* This module contains the primitives that allow an application accessing and running the
* BT protocol stack.
*
*
* @{
****************************************************************************************
*/
#include <stdint.h> // standard integer definitions
#include <stdbool.h> // standard boolean definitions
#include "rwip_config.h" // stack configuration
#include "arch.h"
/*
* FUNCTION DECLARATION
*****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initializes the RW BT SW.
*
****************************************************************************************
*/
void rwbt_init(void);
/**
****************************************************************************************
* @brief Reset the RW BT SW.
*
****************************************************************************************
*/
void rwbt_reset(void);
/**
****************************************************************************************
* @brief The RWBT core interrupt handler.
*
* Handles both the clock interrupt and the Rx Packet interrupt (when activated)
* In the case of a clock interrupt, check if there are active links and which one
* has the highest priority.
*
****************************************************************************************
*/
__BTIRQ void rwbt_isr(void);
///@} ROOT
#endif // _RW_BT_H_
+245
View File
@@ -0,0 +1,245 @@
/**
****************************************************************************************
*
* @file rwbt_config.h
*
* @brief Configuration of the BT protocol stack (max number of supported connections,
* type of partitioning, etc.)
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef RWBT_CONFIG_H_
#define RWBT_CONFIG_H_
/**
****************************************************************************************
* @addtogroup ROOT
* @{
*
* @name RWBT Stack Configuration
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
/*
* DEFINES
****************************************************************************************
*/
/******************************************************************************************/
/* -------------------------- GENERAL SETUP --------------------------------------*/
/******************************************************************************************/
/// Maximum number of ACL links
#define MAX_NB_ACTIVE_ACL CFG_CON_ACL
/// BT Heap size
#define BT_HEAP_MSG_SIZE (256 + 256 * MAX_NB_ACTIVE_ACL)
#define BT_HEAP_ENV_SIZE (1024 + 1024 * MAX_NB_ACTIVE_ACL)
/// Number of BT tasks
#define BT_TASK_SIZE 4
/// Number of RX descriptors
#define BT_RXDESC_NB (4)
/// Number of RX/TX ACL data buffers
#define ACL_DATA_BUF_NB_RX (BT_RXDESC_NB + 2)
#define ACL_DATA_BUF_NB_TX (MAX_NB_ACTIVE_ACL + 2)
/// Guard space reserved for HCI header in ACL RX buffers
#define ACL_RX_BUF_HEADER_SPACE (HCI_ACL_HDR_LEN + 1)
/// Number of TX LMP buffers
#if (MAX_NB_ACTIVE_ACL > 3)
#define BT_LMP_BUF_NB_TX (2*MAX_NB_ACTIVE_ACL)
#else // (MAX_NB_ACTIVE_ACL > 3)
#define BT_LMP_BUF_NB_TX (7)
#endif // (MAX_NB_ACTIVE_ACL > 3)
/// Maximum ACL Data Packet Size
#define ACL_DATA_BUF_SIZE DH5_3_PACKET_SIZE
/// Normal Rx window size
#define NORMAL_WIN_SIZE 26
/// Range of key size supported by the FW
#define ENC_KEY_SIZE_MAX 16
#define ENC_KEY_SIZE_MIN 7
#define ENC_KEY_SIZE_MASK 0xFFFF
/// Inquiry response TX power (the value code depends on radio used)
#define INQ_RSP_TX_PWR rwip_rf.txpwr_max
/// Size of the inquiry result filtering list
#define INQ_FILT_LEN 10
/******************************************************************************************/
/* -------------------------- SYNC SETUP ------------------------------------------*/
/******************************************************************************************/
/// Maximum number of Synchronous connections (0 to 2)
#define MAX_NB_SYNC CFG_CON_SCO
/// Flag indicating if debug mode is activated or not
#if defined (CFG_VOHCI) && (MAX_NB_SYNC > 0)
#define VOICE_OVER_HCI 1
#else
#define VOICE_OVER_HCI 0
#endif // defined (CFG_VOHCI) && (MAX_NB_SYNC > 0)
#if VOICE_OVER_HCI
/// Number of Synchronous TX buffers used for one VoHCI link
#define SYNC_TX_BUF_NB 4
/// Number of Synchronous RX buffers used for one VoHCI link
#define SYNC_RX_BUF_NB 3
/// Guard space reserved for HCI header in Sync RX buffers
#define SYNC_RX_BUF_HEADER_SPACE (HCI_SYNC_HDR_LEN + 1)
#endif //(VOICE_OVER_HCI)
/// Synchronous link negotiation number of retries
#define SYNC_NEGO_TRY 1
/******************************************************************************************/
/* ------------------------- FIRMWARE SETUP ---------------------------------------*/
/******************************************************************************************/
///Number of HCI Event filter
#define HCI_FILTER_NB 0x5
/*
* Test mode option to be able to enter test mode as defined
* in part I1: BT Test Mode, of the BT specification.
*/
/// Test mode support
#define TEST_MODE 1
/******************************************************************************************/
/* ------------------------- COEXISTENCE SETUP ------------------------------------*/
/******************************************************************************************/
/// WLAN Coexistence
#define RW_BT_WLAN_COEX RW_WLAN_COEX
///WLAN test mode
#define RW_BT_WLAN_COEX_TEST RW_WLAN_COEX_TEST
/// MWS Coexistence
#define RW_BT_MWS_COEX RW_MWS_COEX
///WLAN test mode
#define RW_BT_MWS_COEX_TEST RW_MWS_COEX_TEST
///To let the HW using the default values set in the registers
#define RW_BT_PTI_PRIO_AUTO 31
/// Coexistence Packet traffic information - Index Definitions
enum rwbt_pti_config_idx
{
BT_PTI_PAGERES_IDX ,
BT_PTI_MCONPEND_IDX ,
BT_PTI_PSCANRES_IDX ,
BT_PTI_SCONPEND_IDX ,
BT_PTI_MSSWITCH_IDX ,
BT_PTI_SNIFFANC_IDX ,
BT_PTI_BEACON_IDX ,
BT_PTI_SNIFFATT_IDX ,
BT_PTI_ACCWIN_IDX ,
BT_PTI_POLLINT_IDX ,
BT_PTI_PAGE_IDX ,
BT_PTI_PSCAN_IDX ,
BT_PTI_INQ_IDX ,
BT_PTI_INQSCAN_IDX ,
BT_PTI_INQRES_IDX ,
BT_PTI_SCORSVD_IDX ,
BT_PTI_SCORETX_IDX ,
BT_PTI_ACLTX_IDX ,
BT_PTI_ACLRETX_IDX ,
BT_PTI_LMPTX_IDX ,
BT_PTI_BCAST_IDX ,
BT_PTI_CONNECT_IDX ,
BT_PTI_IDX_MAX
};
/******************************************************************************************/
/* ------------------------- AFH SETUP ------------------------------------*/
/******************************************************************************************/
/// Minimum classification interval requested to slave devices (in slots) (2 secs)
#define BT_AFH_CH_CLASS_INT_MIN 0x0C80
/// Maximum classification interval requested to slave devices (in slots) (4 secs)
#define BT_AFH_CH_CLASS_INT_MAX 0x1900
/// AFH update period (in sec)
#define BT_AFH_UPDATE_PERIOD 4
/// Maximum duration without receiving a packet before considering a channel quality unknown (in slots) (2 secs)
#define BT_AFH_ASSESS_VALID_TO 0x1900
/// Maximum duration without receiving a packet before reintroducing a channel to the map (in slots) (20 secs)
#define BT_AFH_REASSESS_TO 0x7D00
/// Maximum counter value for channel assessment
#define BT_AFH_ASSESS_COUNT_MAX 4
/// Counter threshold to consider a channel good
#define BT_AFH_ASSESS_COUNT_THR_GOOD 2
/// Counter threshold to consider a channel bad
#define BT_AFH_ASSESS_COUNT_THR_BAD -2
/// Minimum counter value for channel assessment
#define BT_AFH_ASSESS_COUNT_MIN -4
/******************************************************************************************/
/* -------------------------- CSB SETUP ----------------------------------------*/
/******************************************************************************************/
/// Support of Connectionless Slave Broadcast
#if defined (CFG_CSB)
#define CSB_SUPPORT 1
#else
#define CSB_SUPPORT 0
#endif // defined (CFG_CSB)
/******************************************************************************************/
/* -------------------------- PCA SETUP ----------------------------------------*/
/******************************************************************************************/
/// Support of Piconet Clock Adjust
#if defined (CFG_PCA)
#define PCA_SUPPORT 1
#else
#define PCA_SUPPORT 0
#endif // defined (CFG_PCA)
/// PCA update period (in sec)
#define BT_PCA_UPDATE_PERIOD 30
/// PCA request clk_adj_slots in addition to clk_adj_us: enable=1, disable=0
#define BT_PCA_CLK_ADJ_SLOTS 0 // No mandate to request a clk_adj_slots currently - for test only
/******************************************************************************************/
/* ------------------------ CONNECTION HANDLE ----------------------------------------*/
/******************************************************************************************/
/// Bit set for BT ACL connection handles
#define BT_ACL_CONHDL_BIT (0x80)
#define BT_ACL_CONHDL_MIN (BT_ACL_CONHDL_BIT)
#define BT_ACL_CONHDL_MAX (BT_ACL_CONHDL_BIT + MAX_NB_ACTIVE_ACL - 1)
/// Bit set for BT SCO connection handles
#define BT_SYNC_CONHDL_OFF (8)
#define BT_SYNC_CONHDL_MSK (((1 << MAX_NB_SYNC) - 1) << BT_SYNC_CONHDL_OFF)
#define BT_SYNC_CONHDL_BIT(sco_link_id) ((sco_link_id + 1) << BT_SYNC_CONHDL_OFF)
#define BT_SYNC_CONHDL_LID(sco_conhdl) ((sco_conhdl >> BT_SYNC_CONHDL_OFF) - 1)
#define BT_SYNC_CONHDL(link_id, sco_link_id) (BT_ACL_CONHDL_MIN + link_id + BT_SYNC_CONHDL_BIT(sco_link_id))
/// @} BT Stack Configuration
/// @} ROOT
#endif //RWBT_CONFIG_H_
Binary file not shown.
Binary file not shown.
+263
View File
@@ -0,0 +1,263 @@
/**
****************************************************************************************
*
* @file bt_util_buf.h
*
* @brief Main API file for the BT EM buffer management system
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef BT_UTIL_BUF_H_
#define BT_UTIL_BUF_H_
/**
****************************************************************************************
* @defgroup BT_UTIL_BUF BT EM buffer management system
* @ingroup ROOT
* @brief BT EM buffer management system
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdint.h> // standard integer
#include "co_list.h" // common list definition
/*
* DEFINES
****************************************************************************************
*/
/// ACL data: handle and data length decoding
#define BT_EM_ACL_DATA_LEN_LSB (0)
#define BT_EM_ACL_DATA_LEN_MASK (0x03FF)
/// Packet boundary flag
#define BT_EM_ACL_PBF_LSB (12)
#define BT_EM_ACL_PBF_MASK (0x3000)
/// Broadcast flag
#define BT_EM_ACL_BF_LSB (14)
#define BT_EM_ACL_BF_MASK (0xC000)
/*
* STRUCTURE DEFINITION
****************************************************************************************
*/
/// EM LMP buffer element
struct bt_em_lmp_buf_elt
{
/// List header
struct co_list_hdr hdr;
/// EM buffer pointer
uint16_t buf_ptr;
/// Data length
uint8_t length;
};
/// EM ACL buffer element
struct bt_em_acl_buf_elt
{
/// List header
struct co_list_hdr hdr;
/// L2CAP packet start timestamp (in BT half-slots)
uint32_t l2cap_start_ts;
/// EM buffer pointer
uint16_t buf_ptr;
/// Data length + Data Flags (PBF + BF)
uint16_t data_len_flags;
};
#if VOICE_OVER_HCI
/// EM Sync buffer element
struct bt_em_sync_buf_elt
{
/// List header
struct co_list_hdr hdr;
/// EM buffer pointer
uint16_t buf_ptr;
/// Data length
uint8_t data_len;
/// Packet status flags
uint8_t packet_status_flag;
/// Synchronous link identifier
uint8_t sync_link_id;
};
#endif // VOICE_OVER_HCI
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize BT EM buffers management system
*
* @param[in] reset True: reset during operations | False: power-on reset
****************************************************************************************
*/
void bt_util_buf_init(bool reset);
/**
****************************************************************************************
* @brief Allocate a LMP TX buffer
*
* @return Pointer to LMP TX buffer, NULL if no buffer available
****************************************************************************************
*/
struct bt_em_lmp_buf_elt* bt_util_buf_lmp_tx_alloc(void);
/**
****************************************************************************************
* @brief Free a LMP TX buffer
*
* @param[in] buf Pointer to LMP TX buffer
****************************************************************************************
*/
void bt_util_buf_lmp_tx_free(uint16_t buf);
/**
****************************************************************************************
* @brief Allocate a ACL RX buffer
*
* @return Pointer to ACL RX buffer, NULL if no buffer available
****************************************************************************************
*/
struct bt_em_acl_buf_elt* bt_util_buf_acl_rx_alloc(void);
/**
****************************************************************************************
* @brief Free a ACL RX buffer
*
* @param[in] buf Pointer to ACL RX buffer
****************************************************************************************
*/
void bt_util_buf_acl_rx_free(uint16_t buf);
/**
****************************************************************************************
* @brief Allocate a ACL TX buffer
*
* @return Pointer to ACL TX buffer, NULL if no buffer available
****************************************************************************************
*/
uint16_t bt_util_buf_acl_tx_alloc(void);
/**
****************************************************************************************
* @brief Retrieve TX buffer Element
*
* @return Pointer to ACL TX buffer element
****************************************************************************************
*/
struct bt_em_acl_buf_elt* bt_util_buf_acl_tx_elt_get(uint16_t buf);
/**
****************************************************************************************
* @brief Free a ACL TX buffer
*
* @param[in] buf Pointer to ACL TX buffer
****************************************************************************************
*/
void bt_util_buf_acl_tx_free(uint16_t buf);
#if VOICE_OVER_HCI
/**
****************************************************************************************
* @brief Initialize synchronous buffer allocation system
*
* @param[in] sync_id Synchronous link identifier
* @param[in] tx_buf_nb Number of synchronous TX buffers
* @param[in] tx_buf_size Size of synchronous TX buffers (data payload only)
* @param[in] rx_buf_nb Number of synchronous RX buffers
* @param[in] rx_buf_size Size of synchronous RX buffers (including HCI header and data payload)
*
* @return Pointer to Sync RX buffer, NULL if no buffer available
****************************************************************************************
*/
void bt_util_buf_sync_init(uint8_t sync_id, uint8_t tx_buf_nb, uint8_t tx_buf_size, uint8_t rx_buf_nb, uint8_t rx_buf_size);
/**
****************************************************************************************
* @brief Clear synchronous buffer allocation system
*
* @param[in] sync_id Synchronous link identifier
*
* @return Pointer to Sync RX buffer, NULL if no buffer available
****************************************************************************************
*/
void bt_util_buf_sync_clear(uint8_t sync_id);
/**
****************************************************************************************
* @brief Allocate a Sync TX buffer
*
* @param[in] sync_id Synchronous link identifier
* @param[in] size Size of the buffer
*
* @return Pointer to Sync TX buffer, NULL if no buffer available
****************************************************************************************
*/
uint16_t bt_util_buf_sync_tx_alloc(uint8_t sync_id, uint8_t size);
/**
****************************************************************************************
* @brief Retrieve TX buffer Element
*
* @param[in] sync_id Synchronous link identifier
*
* @return Pointer to Sync TX buffer element
****************************************************************************************
*/
struct bt_em_sync_buf_elt* bt_util_buf_sync_tx_elt_get(uint8_t sync_id, uint16_t buf);
/**
****************************************************************************************
* @brief Free a Sync TX buffer
*
* @param[in] sync_id Synchronous link identifier
* @param[in] buf Pointer to Sync TX buffer
****************************************************************************************
*/
void bt_util_buf_sync_tx_free(uint8_t sync_id, uint16_t buf);
/**
****************************************************************************************
* @brief Allocate a Sync RX buffer
*
* @param[in] sync_id Synchronous link identifier
* @param[in] size Size of the buffer
*
* @return Pointer to Sync RX buffer, NULL if no buffer available
****************************************************************************************
*/
struct bt_em_sync_buf_elt* bt_util_buf_sync_rx_alloc(uint8_t sync_id, uint8_t size);
/**
****************************************************************************************
* @brief Free a Sync RX buffer
*
* @param[in] sync_id Synchronous link identifier
* @param[in] buf Pointer to Sync RX buffer
****************************************************************************************
*/
void bt_util_buf_sync_rx_free(uint8_t sync_id, uint16_t buf);
#endif // VOICE_OVER_HCI
/// @} BT_UTIL_BUF
#endif // BT_UTIL_BUF_H_
+124
View File
@@ -0,0 +1,124 @@
/**
****************************************************************************************
*
* @file bt_util_key.h
*
* @brief link manager key management
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef BT_UTIL_KEY_H_
#define BT_UTIL_KEY_H_
/**
****************************************************************************************
* @defgroup LMKEY Link Keys
* @ingroup LM
* @brief LM module for link key management.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "co_bt.h" // BT standard definitions
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Processes E1 algorithm for Authentication
*
* @param[in] Key Key Vector[16]
* @param[in] BdAddr BdAddr[6]
* @param[in] Random Random Vector[16]
* @param[out] Sres SRES Vector[4]
* @param[out] Aco ACIO Vector[12]
*
****************************************************************************************
*/
void E1(struct ltk Key, struct bd_addr BdAddr, struct ltk Random, struct sres_nb *Sres, struct aco *Aco);
/**
****************************************************************************************
* @brief Processes E21 algorithm for Authentication
*
* @param[in] Random Random Vector[16]
* @param[in] BdAddr BdAddr[6]
* @param[out] Key Result Vector[16]
*
****************************************************************************************
*/
void E21(struct ltk Random, struct bd_addr BdAddr, struct ltk *Key);
/**
****************************************************************************************
* @brief Processes E22 algorithm for Authentication
*
* @param[in] Random Random Vector[16]
* @param[in] BdAddr BdAddr[6]
* @param[in] Pin PIN Vector[1..16]
* @param[in] PinLen PIN length (1..16)
* @param[out] KeyOut Result Vector[16]
*
****************************************************************************************
*/
void E22(struct ltk Random, struct bd_addr BdAddr, struct pin_code Pin, uint8_t PinLen, struct ltk *KeyOut);
/**
****************************************************************************************
* @brief Processes E3 algorithm for Authentication
*
* @param[in] Key Key Vector[16]
* @param[in] Cof COF[12]
* @param[in] Random Random Vector[16]
* @param[out] KeyOut Result Vector[16]
*
****************************************************************************************
*/
void E3(struct ltk Key, struct aco Cof, struct ltk Random, struct ltk *KeyOut);
/**
****************************************************************************************
* @brief Encryption : Processes K'c Key for encryption
*
* @param[in] Random Random Vector[16]
* @param[in] BdAddr BdAddr[6]
* @param[out] KPrimC K'c Vector (Result)
*
****************************************************************************************
*/
void KPrimC(struct ltk Kc, uint8_t length, struct ltk *KPrimC);
/**
****************************************************************************************
* @brief Xor of 2 Vectors
*
* @param[in] VectorIn1 Input Vector1 [16]
* @param[in] VectorIn2 Input Vector2 [16]
* @param[out] VectorOut Result Vector[16]
*
****************************************************************************************
*/
void XorKey(struct ltk VectorIn1, struct ltk VectorIn2, struct ltk *VectorOut);
/**
****************************************************************************************
* @brief This function is used to get a random vector.
*
* @param[out] Vector Random Vector
*
****************************************************************************************
*/
void LM_MakeRandVec(struct ltk *Vector);
///@} LMKEY
#endif // BT_UTIL_KEY_H_
+103
View File
@@ -0,0 +1,103 @@
/**
****************************************************************************************
*
* @file bt_util_lmp.h
*
* @brief Main API file for the Link Manager Protocol
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef BT_UTIL_LMP_H_
#define BT_UTIL_LMP_H_
/**
****************************************************************************************
* @defgroup BT_UTIL_LMP Link Manager Protocol
* @ingroup ROOT
* @brief Link Manager Protocol
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdint.h> // standard integer
/*
* DEFINES
****************************************************************************************
*/
/// Maximum size of LMP unpacked parameters
#define LMP_MAX_UNPACKED_SIZE (LMP_MAX_PDU_SIZE+10)
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
/// Status returned by generic packer-unpacker
enum LMP_PACK_STATUS
{
LMP_PACK_OK,
LMP_PACK_OVERFLOW,
LMP_PACK_WRONG_FORMAT,
LMP_PACK_INVALID_SIZE,
LMP_PACK_UNKNOWN,
};
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Check if LMP packet is allowed at connection establishment
*
* @param[in] opcode LMP opcode
* @param[in] ext_opcode LMP extended opcode (if applicable)
*
* @return True if allowed, false otherwise
****************************************************************************************
*/
bool lmp_estab_allowed(uint8_t opcode, uint8_t ext_opcode);
/**
****************************************************************************************
* @brief Pack LMP packet
*
* @param[inout] buf Buffer containing parameters
* @param[inout] p_len Pointer on parameters length
*
* @return Status of the packing operation
****************************************************************************************
*/
uint8_t lmp_pack(uint8_t* buf, uint8_t* p_len);
/**
****************************************************************************************
* @brief Unpack LMP packet
*
* @param[in] in Buffer containing packed parameters
* @param[out] out Buffer containing unpacked parameters
* @param[inout] p_len Pointer on parameters length
*
* @return Status of the unpacking operation
****************************************************************************************
*/
uint8_t lmp_unpack(uint8_t* out, uint8_t* in, uint8_t* p_len);
/// @} BT_UTIL_LMP
#endif // BT_UTIL_LMP_H_
+558
View File
@@ -0,0 +1,558 @@
/**
****************************************************************************************
*
* @file bt_util_sp.h
*
* @brief Link Manager simple pairing
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef BT_UTIL_SP_H_
#define BT_UTIL_SP_H_
/**
****************************************************************************************
* @defgroup BTUTILSP SP Computation
* @ingroup LM
* @brief LM module for simple pairing algorithms and mathematical computations.
* @{
****************************************************************************************
*/
#include <stdint.h>
#include "co_bt.h"
/*
* DEFINES
****************************************************************************************
*/
#define LM_OPER_SUCCESS 0x00
#define LM_OPER_PENDING 0x01
#define LM_OPER_FAILED 0x02
#define LM_SP_WORD_BITS4 16
#define LM_SP_WORD_MASK2 0xffffffff
#define LM_SP_WORD_MASK2l 0x0000ffff
#define LM_SP_WORD_MASK2h1 0xffff8000
#define LM_SP_WORD_MASK2h 0xffff0000
#define LM_SP_WORD_TBIT 0x80000000
#define LM_SPLBITS(a) ((a) & LM_SP_WORD_MASK2l)
#define LM_SPHBITS(a) (((a) >> LM_SP_WORD_BITS4)& LM_SP_WORD_MASK2l)
#define LM_SPL2HBITS(a) (((a) << LM_SP_WORD_BITS4)& LM_SP_WORD_MASK2)
#define LM_SP_NUM_192_SIGN_BIT 0x80000000
#define LM_SP_NUM_192_BYTES 0x06
#define LM_SP_NUM_192_BITS 32
#define LM_SP_TYPE_NUM_192 1
#define LM_SP_TYPE_NUM_384 2
#define LM_SP_WNAF_WINDOW 0x03
#define LM_SP_WNAF_MSB_BIT (1<<LM_SP_WNAF_WINDOW)
#define LM_SP_WNAF_NEXT_DIGIT_BIT (LM_SP_WNAF_MSB_BIT<<1)
#define LM_SP_WNAF_DIGIT_MASK (LM_SP_WNAF_NEXT_DIGIT_BIT-1)
#define LM_SP_P192_PRE_COMP_POINTS 4
/*
* NEW TYPE
* ***************************************************************************************
*/
typedef uint8_t u_int8;
typedef uint32_t u_int32;
/// Simple pairing 192
typedef struct _lm_sp_num_192_
{
uint32_t Neg;
uint32_t Number[6];
}
lm_sp_num_192;
/// Simple pairing 384
typedef struct _lm_sp_num_384_
{
uint32_t Neg;
uint32_t Number[12];
}
lm_sp_num_384;
/// Simple pairing P192
typedef struct _lm_sp_p192_point_
{
lm_sp_num_192 X;
lm_sp_num_192 Y;
lm_sp_num_192 Z;
}
lm_sp_p192_point;
/// Simple pairing P256
typedef struct _lm_sp_p256_point_
{
uint8_t X[32];
uint8_t Y[32];
}
lm_sp_p256_point;
/// P-192 curve data
typedef struct _lm_sp_p192_group_data_
{
lm_sp_p192_point G;
lm_sp_num_192 A;
}
lm_sp_p192_group_data;
/// Simple pairing P192 Computation Global Data
typedef struct _lm_sp_p192_comp_global_data_
{
lm_sp_p192_point Pre_comp[LM_SP_P192_PRE_COMP_POINTS];
lm_sp_p192_point RemotePublicKey;
lm_sp_p192_point DH_Key;
signed char wnaf[196];
uint32_t wnaf_len;
uint8_t Loop_ctr;
uint8_t Result_at_infinity;
uint8_t Result_inverted;
}
lm_sp_p192_comp_global_data;
/// Simple pairing P256 Computation Global Data
typedef struct _lm_sp_p256_comp_global_data_
{
lm_sp_p256_point RemotePublicKey;
lm_sp_p256_point DH_Key;
}
lm_sp_p256_comp_global_data;
/*
* FUNCTION DECLARATION
* ***************************************************************************************
*/
/**
****************************************************************************************
* @brief This function calculates the SHA hash for the given input block.
*
* @param[in] Input_Message The pointer to the message block for which hash is to be calculated
* @param[in] SHA_256_Hash Hash Value calculated
* @param[in] Length Length of the Input block
****************************************************************************************
*/
void lm_sp_sha256_calculate(uint8_t* Input_Message, uint32_t* SHA_256_Hash, uint32_t Length);
/**
****************************************************************************************
* @brief This function checks if the input is zero
*
* @param[in] a The input
* @param[in] Type Type of the input
*
* @return non zero if number is zero else returns 0
*
****************************************************************************************
*/
int lm_n_is_zero(void* a, uint32_t type);
/**
****************************************************************************************
* @brief This function stores the one on a given number.
*
* @param[in] a The input
* @param[in] Type Type of the input
****************************************************************************************
*/
void lm_sp_n_one(void* a, uint32_t type);
/**
****************************************************************************************
* @brief This function returns converts the number into naf form with window
* size of 4
*
* @param[in] wnaf returns wnaf form
* @param[in] input the input num to be converted
* @param[in] ret_len the length of the wnaf form number
*
* @return non zero on success and vice versa
*
****************************************************************************************
*/
int lm_sp_n192_convert_wnaf(signed char *r, lm_sp_num_192 *scalar, uint32_t *ret_len);
/**
****************************************************************************************
* @brief This function sets the input point to infinity
*
* @param[in] p Input
*
* @return non zero on success and vice versa
*
****************************************************************************************
*/
int lm_sp_p192_point_to_inf(lm_sp_p192_point *p);
/**
****************************************************************************************
* @brief This function converts the coordinate system from jacobian to affine
*
* @param[in] p Input
*
* @return non zero on success and vice versa
*
****************************************************************************************
*/
int lm_sp_p192_point_jacobian_to_affine(lm_sp_p192_point *points);
/**
****************************************************************************************
* @brief This function is used to convert the points from jacobian to affine
*
* @param[in] point The array of points to be converted from Jacobian to affine
*
* @return non zero on success and vice versa
*
****************************************************************************************
*/
int lm_sp_p192_points_jacobian_to_affine(lm_sp_p192_point *points);
/**
****************************************************************************************
* @brief This function is used to precompute the points needed for scalar mul
*
* @param[in] r The array for P192 pre computation
*
* @return non zero on success and vice versa
****************************************************************************************
*/
int lm_sp_pre_compute_points(lm_sp_p192_point *r);
/**
****************************************************************************************
* @brief This function doubles the given p192 point
*
* @param[in] r The result after point doubling
* @param[in] a The point to be doubled
*
* @return non zero on success and vice versa
****************************************************************************************
*/
int lm_sp_p192_dbl(lm_sp_p192_point *r, lm_sp_p192_point *a);
/**
****************************************************************************************
* @brief This function adds two p192 point
*
* @param[in] r The result after point addition
* @param[in] a The point to be added
* @param[in] b The point to be added
*
* @return non zero on success and vice versa
****************************************************************************************
*/
int lm_sp_p192_add(lm_sp_p192_point *r, lm_sp_p192_point *a, lm_sp_p192_point *b);
/**
****************************************************************************************
* @brief This function inverts the input p192 point
*
* @param[in] p Input
*
* @return non zero on success and vice versa
****************************************************************************************
*/
int lm_sp_p192_invert(lm_sp_p192_point *p);
/**
****************************************************************************************
* @brief This function generates a 16-bytes random number
*
* @param[out] number Pointer to random number buffer
****************************************************************************************
*/
void lm_generate_rand_16bytes(struct byte16* number);
/**
****************************************************************************************
* @brief This function is used to calculate the F1 Value.
*
* @param[in] LocRandN Pointer to ltk structure local random number
* @param[in] Commitment Pointer to ltk structure commitment value
* @param[in] Number Numerical value
* @param[in] Role Device role
* @param[in] lm_sp_p192_dhkey_data Buffer with SP informations
****************************************************************************************
*/
void lm_f1(struct byte16* LocRandN, struct byte16* Commitment, uint8_t Number, uint8_t Role, lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data);
/**
****************************************************************************************
* @brief This function is used to calculate the F1 Value for OOB.
*
* @param[in] Nonce Pointer to ltk structure nonce value
* @param[in] Commitment Pointer to ltk structure commitment value
* @param[in] Number Numerical value
* @param[in] IsPublicKeyLocal Check if local public key
* @param[in] lm_sp_p192_dhkey_data Buffer with SP informations
****************************************************************************************
*/
void lm_oob_f1(struct byte16* Nonce, struct byte16* Commitment, uint8_t Number,
uint8_t IsPublicKeyLocal, lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data);
/**
****************************************************************************************
* @brief This function is the G function.
*
* @param[in] Na Pointer to ltk structure Na
* @param[in] Nb Pointer to ltk structure Nb
* @param[in] Role Role
* @param[in] lm_sp_p192_dhkey_data Buffer with SP informations
* @param[in] UserConfirmNum User confirmation number
****************************************************************************************
*/
void lm_g(struct byte16* Na, struct byte16* Nb, uint8_t Role, lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data, uint32_t* UserConfirmNum);
/**
****************************************************************************************
* @brief This function is used to calculate the F3 Value.
*
* @param[in] N1 N1 16-byte length value
* @param[in] N2 N2 16-byte length value
* @param[in] R Randomizer
* @param[in] IOCAP IO capability
* @param[in] B BD address
* @param[in] lm_sp_p192_dhkey_data Buffer with SP informations
* @param[in] CheckValue Value check
*
* @return Status
****************************************************************************************
*/
void lm_f3(struct byte16* N1, struct byte16* N2, struct randomizer* R,
struct io_capability IOCAP, struct bd_addr* A, struct bd_addr* B,
lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data, struct byte16* CheckValue);
/**
****************************************************************************************
* @brief This function is used to calculate the F2 Value.
*
* @param[in] N1 N1 16-byte length value
* @param[in] N2 N2 16-byte length value
* @param[in] A BD address A
* @param[in] B BD address B
* @param[in] lm_sp_p192_dhkey_data Buffer with SP informations
* @param[in] LinkKey Link key LTK structure
****************************************************************************************
*/
void lm_f2(struct byte16* N1, struct byte16* N2, struct bd_addr* A, struct bd_addr* B,
lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data, struct ltk* LinkKey);
/**
****************************************************************************************
* @brief Initialize Diffie Hellman key calculation
*
* @param[in] lm_sp_p192_dhkey_data Data structure for key calculation
* @param[in] public_key_valid True: public key is valid, False: public key uncertain
*
* @return Status
*
****************************************************************************************
*/
uint8_t lm_dhkey_calc_init(lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data, bool public_key_valid);
/**
****************************************************************************************
* @brief This function compares DHkeys.
*
* @param[in] BufferIndex Buffer index for sp
*
* @return Status
*
****************************************************************************************
*/
uint8_t lm_dhkey_compare(lm_sp_p192_comp_global_data* lm_sp_p192_dhkey_data);
/**
****************************************************************************************
* @brief This function is used to calculate the F1 Value for P-256.
*
* @param[in] U pointer to 32 byte value U (see BT Spec)
* @param[in] V pointer to 32 byte value V (see BT Spec)
* @param[in] X pointer to 16 byte value X (see BT Spec)
* @param[in] Z pointer to single byte Z (see BT Spec)
*
* @param[out] Output pointer to 16 byte result (see BT Spec)
*
****************************************************************************************
*/
void F1_256(const u_int8 *U,const u_int8 *V,const u_int8 *X,const u_int8 *Z,u_int8* OutPut);
/**
****************************************************************************************
* @brief This function is used to calculate the G value for P-256.
*
* g(U, V, X, Y) = SHA-256 (U || V || X || Y) / 2e32
*
* @param[in] U pointer to 32 byte value U (see BT Spec)
* @param[in] V pointer to 32 byte value V (see BT Spec)
* @param[in] X pointer to 16 byte value X (see BT Spec)
* @param[in] Y pointer to 16 byte value Y (see BT Spec)
*
* @param[out] Output pointer to 4 byte result (see BT Spec)
****************************************************************************************
*/
void G_256(const u_int8 *U,const u_int8 *V,const u_int8 *X,const u_int8 *Y,u_int32* OutPut);
/**
****************************************************************************************
* @brief This function is used to calculate the F2 value for P-256.
*
* @param[in] W pointer to 32 byte value W (see BT Spec)
* @param[in] N1 pointer to 16 byte value N1 (see BT Spec)
* @param[in] N2 pointer to 16 byte value N2 (see BT Spec)
* @param[in] KeyId pointer to 4 Byte KeyId(see BT Spec)
* @param[in] A1 pointer to 6 Address value A1 (see BT Spec)
* @param[in] A2 pointer to 6 Address value A2 (see BT Spec)
*
* @param[out] Output pointer to 16 byte result (see BT Spec)
****************************************************************************************
*/
void F2_256(const u_int8 *W,const u_int8 *N1, const u_int8 *N2, const u_int8 *KeyId, const u_int8 *A1, const u_int8 *A2,u_int8* OutPut);
/**
****************************************************************************************
* @brief This function is used to calculate the F3 value for P-256.
*
* @param[in] W pointer to 32 byte value W (see BT Spec)
* @param[in] N1 pointer to 16 byte value N1 (see BT Spec)
* @param[in] N2 pointer to 16 byte value N2 (see BT Spec)
* @param[in] R1 pointer to 16 byte value R1 (see BT Spec)
* @param[in] IOcap pointer to 4 Byte IO Capabilities (see BT Spec)
* @param[in] A1 pointer to 6 Address value A1 (see BT Spec)
* @param[in] A2 pointer to 6 Address value A2 (see BT Spec)
*
* @param[out] Output pointer to 16 byte result (see BT Spec)
****************************************************************************************
*/
void F3_256(const u_int8 *W,const u_int8 *N1,const u_int8 *N2,const u_int8 *R, const u_int8 *IOcap,const u_int8 *A1,const u_int8 *A2, u_int8* OutPut);
/**
****************************************************************************************
* @brief This function is used to calculate the H3 value for P-256.
* The AES encryption key is generated using H3.
*
* h3(W, keyID, A1, A2, ACO) = HMAC-SHA-256T(KeyID || A1 || A2 || ACO) / 2^128
*
* @param[in] T pointer to the 128 bit Bluetooth Link Key derived from f2
* @param[in] A1 pointer to 6 Byte BD_ADDR of the master.
* @param[in] A2 pointer to 6 Byte BD_ADDR of the slave.
* @param[in] ACO pointer to 8 byte ACO output from h5
*
* @param[out] pResult pointer to 16 byte result (see BT Spec)
****************************************************************************************
*/
u_int8* H3(const u_int8* T,const u_int8* A1, const u_int8* A2, const u_int8* ACO, u_int8* pResult);
/**
****************************************************************************************
* @brief This function is used to calculate the H4 value for P-256.
* H4 determines the Device Authentication Key
*
* h4(W, keyID, A1, A2) = HMAC-SHA-256T(KeyID || A1 || A2) / 2^128
*
* @param[in] T pointer to the 128 bit Bluetooth Link Key.
* @param[in] A1 pointer to 6 Byte BD_ADDR of the master.
* @param[in] A2 pointer to 6 Byte BD_ADDR of the slave.
*
* @param[out] pResult pointer to 16 byte result (see BT Spec)
*
* NOTE :- The KeyId is fixed and thus not passed as a parameter.
****************************************************************************************
*/
u_int8* H4(const u_int8* T,const u_int8* A1, const u_int8* A2, u_int8* pResult);
/**
****************************************************************************************
* @brief This function is used to calculate the H5 value for P-256.
* H5 if used for the SRES and ACO calculation. The R1 and R2 are the AU_RANDs of the
* Master and Slave (AU_RANDs and AU_RANDm)
*
* h5(W, R1, R2) = HMAC-SHA-256T( R1 || R2) / 2^128
*
* @param[in] W pointer to the 16 Byte Device Authentication Key.
* @param[in] R1 pointer to 16 Byte AU_RAND.
* @param[in] R2 pointer to 16 Byte AU_RAND.
*
* @param[out] pResult pointer to 16 byte result (see BT Spec)
*
****************************************************************************************
*/
u_int8* H5(const u_int8* W,const u_int8* R_1,const u_int8* R_2, u_int8* pResult);
/**
****************************************************************************************
* @brief This is the HMAC funtion used my most of the SSP Crypto functions.
*
* HMACk(m) = h((K|opad)||h((K|ipad)||m))
* where h is a cryptographic hash function, K is a secret key padded to the
* right with extra zeros to the block size of a the hash function.
*
* @param[in] Key pointer to the Key.
* @param[in] Key_Len length of the Key in BITs .
* @param[in] message pointer to the Message.
* @param[in] message_len length of the message in BITs .
*
* returns :- a pointer to the 32 Byte HMAC output.
*
* NOTE :- The pointer to the HMAC output is actually a pointer to a static array.
*
****************************************************************************************
*/
u_int8* HMAC(const u_int8* Key,const int Key_Len,const u_int8 *message,int message_len);
/**
****************************************************************************************
* @brief This is a message concatenation function.
*
* This function is rather STUPID - and should be removed/deprecated. Simpler to replace
* with memcpy
*
* @param[in] Message1 pointer to the first message.
* @param[in] Message1_Len length of the first message in BITs .
* @param[in] Message2 pointer to the second message.
* @param[in] Message2_Len length of the second message in BITs .
*
* @param[out] newConcatBuffer pointer to concatenated result
*
* returns :- a pointer to the 32 Byte HMAC output.
*
* NOTE :- This function should be removed..
*
****************************************************************************************
*/
u_int32 hashConcat(const u_int8* Message1,u_int32 Message1_Len,const u_int8* Message2, u_int32 Message2_Len,u_int8* newConcatBuffer);
/**
****************************************************************************************
* @brief This is the SHA-256 function.
*
* This function determines HASH for a given message.
*
* @param[in] Message pointer to the message to be hashed
* @param[in] MessageLengthInBits length of the message in BITs.
*
* @param[out] Hash pointer to 32 byte resultant hash
*
* returns :- Length in Bits of the Hash (fixed at 256).
*
****************************************************************************************
*/
u_int32 SHA_256(u_int8* Message,u_int32 MessageLengthInBits,u_int8* Hash);
///@} BTUTILSP
#endif // BT_UTIL_SP_H_
+355
View File
@@ -0,0 +1,355 @@
/**
****************************************************************************************
*
* @file lb.h
*
* @brief Main API file for the Link Broadcaster
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef LB_H_
#define LB_H_
/**
****************************************************************************************
* @defgroup LB Link Broadcaster
* @ingroup ROOT
* @brief BT Lower Layers
*
* The CONTROLLER contains the modules allowing the physical link establishment,
* maintenance and management.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_task.h" // Task definitions
#include "ke_task.h" // kernel task definitions
/*
* MESSAGES
****************************************************************************************
*/
/// Message API of the LB task
/*@TRACE*/
enum lb_msg_id
{
LB_MSG_ID_FIRST = TASK_FIRST_MSG(TASK_ID_LB),
/*
* ************** Msg LC -> LB****************
*/
LB_MST_KEY_CFM,
LB_ENC_RESTART_CFM,
LB_ENC_START_IND,
LB_ENC_STOP_IND,
/*
* ************** Msg LD -> LB****************
*/
LB_ACL_TX_CFM,
LB_CSB_TX_END_IND,
LB_CSB_RX_IND,
LB_CSB_RX_END_IND,
LB_AFH_UPDATE_IND,
LB_AFH_REPORT_TO,
LB_SSCAN_END_IND,
LB_STRAIN_END_IND,
#if PCA_SUPPORT
LB_LOCAL_PCA_REQ,
LB_PCA_END_IND,
LB_PCA_SSCAN_START_REQ,
#if RW_BT_MWS_COEX
LB_PCA_MONITOR_INTV_TO,
#endif //RW_BT_MWS_COEX
/*
* ************** Msg LB->LB****************
*/
LB_PCA_TX_INTV_TO,
#endif //PCA_SUPPORT
};
/// LB master key confirmation
/*@TRACE*/
struct lb_mst_key_cfm
{
///Status
uint8_t status;
///Encryption mode
uint8_t enc_mode;
///Key size mask
uint16_t key_sz_msk;
};
/// LB encryption restart confirmation
/*@TRACE*/
struct lb_enc_restart_cfm
{
///Status
uint8_t status;
};
/// LB encryption start indication
/*@TRACE*/
struct lb_enc_start_ind
{
///Key flag
uint8_t key_flag;
};
/// LB ACL transmission confirmation structure
/*@TRACE*/
struct lb_acl_tx_cfm
{
/// EM buffer containing PDU
uint16_t em_buf;
};
/// LB CSB TX end indication
/*@TRACE*/
struct lb_csb_tx_end_ind
{
/// BD_ADDR
struct bd_addr bd_addr;
/// LT_ADDR
uint8_t lt_addr;
};
/// LB CST RX indication
/*@TRACE*/
struct lb_csb_rx_ind
{
/// CLK when CSB data was received
uint32_t clk;
/// (CLKNslave - CLK) modulo 2^28
uint32_t offset;
/// BD_ADDR
struct bd_addr bd_addr;
/// LT_ADDR
uint8_t lt_addr;
/// receive status
uint8_t rx_status;
/// PDU length
uint16_t length;
/// PDU (packed)
uint8_t pdu[__ARRAY_EMPTY];
};
/// LB CSB RX end indication
/*@TRACE*/
struct lb_csb_rx_end_ind
{
/// BD_ADDR
struct bd_addr bd_addr;
/// LT_ADDR
uint8_t lt_addr;
};
/// LB CSB AFH update indication
/*@TRACE*/
struct lb_afh_update_ind
{
/// AFH_Channel_Map
struct chnl_map afh_ch_map;
};
/// LB CSB AFH report timeout
/*@TRACE*/
struct lb_afh_report_to
{
/// BD_ADDR
struct bd_addr bd_addr;
};
#if PCA_SUPPORT
/// LB PCA local adjustment request structure
/*@TRACE*/
struct lb_local_pca_req
{
/// Clock adjusted us
int16_t clk_adj_us;
/// Clock adjusted slots
uint8_t clk_adj_slots;
/// Clock adjusted period (slots)
uint8_t clk_adj_period;
};
/// LM PCA adjustment complete indication structure
/*@TRACE*/
struct lb_pca_end_ind
{
/// Status
uint8_t status;
};
/// LB Sync Scan start request for PCA recovery mode
/*@TRACE*/
struct lb_pca_sscan_start_req
{
/// Link identifier
uint8_t link_id;
/// Status
uint8_t status;
};
#endif //PCA_SUPPORT
/// LB Sync Scan end indication
/*@TRACE*/
struct lb_sscan_end_ind
{
/// Status
uint8_t status;
/// BD_ADDR
struct bd_addr bd_addr;
/// Clock_Offset (28 bits) - (CLKNslave - CLK) modulo 2^28
uint32_t clock_offset;
#if PCA_SUPPORT
/// Bit offset (CLKNslave - CLK) modulo 2^28
int16_t bit_offset;
#endif // PCA_SUPPORT
/// AFH_Channel_Map
struct chnl_map afh_ch_map;
/// LT_ADDR
uint8_t lt_addr;
/// Next_Broadcast_Instant (28 bits)
uint32_t next_bcst_instant;
/// Connectionless_Slave_Broadcast_Interval (in slots)
uint16_t csb_int;
/// Service_Data
uint8_t service_data;
///Coarse clock adjust use
bool coarse_clk_adj;
};
/// LB Sync Train end indication
/*@TRACE*/
struct lb_strain_end_ind
{
///Status
uint8_t status;
///Coarse clock adjust use
bool coarse_clk_adj;
};
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialization of the BT LB task
*
* This function initializes the the LB task, as well as the environment of the LB
****************************************************************************************
*/
void lb_init(void);
/**
****************************************************************************************
* @brief Reset the BT LB task
****************************************************************************************
*/
void lb_reset(void);
/**
****************************************************************************************
* @brief Get num broadcast retransmissions
****************************************************************************************
*/
uint8_t lb_util_get_nb_broadcast(void);
/**
****************************************************************************************
* @brief Set num broadcast retransmissions
****************************************************************************************
*/
void lb_util_set_nb_broadcast(uint8_t num_bcst_ret);
/**
****************************************************************************************
* @brief Get reserved lt_addr
****************************************************************************************
*/
uint8_t lb_util_get_res_lt_addr(void);
/**
****************************************************************************************
* @brief Get CSB mode (active/inactive)
****************************************************************************************
*/
bool lb_util_get_csb_mode(void);
#if PCA_SUPPORT
/**
****************************************************************************************
* @brief Generic handler for a PCA request on a Master device
*
* @param[in] clk_adj_us. Request intraslot adjustment
* @param[in] clk_adj_slots. Request interslot adjustment
* @param[in] clk_adj_period. Period associated with interslot adjustment
* @param[in] tr_id. Transaction ID of the request.
* @return status as a result of processing the request.
****************************************************************************************
*/
uint8_t lb_master_clk_adj_req_handler(int16_t clk_adj_us, uint8_t clk_adj_slots, uint8_t clk_adj_period, uint8_t tr_id);
/**
****************************************************************************************
* @brief This function is used to clear a PCA clk_adj_ack pending flag/count.
*
****************************************************************************************
*/
void lb_clk_adj_ack(uint8_t clk_adj_id, uint8_t link_id);
#endif //PCA_SUPPORT
/**
****************************************************************************************
* @brief This function read the current master key.
*
* @param[out] MasterKey Master key with LTK size
****************************************************************************************
*/
void LM_GetMasterKey(struct ltk *MasterKey);
/**
****************************************************************************************
* @brief This function read the current master key random.
*
* @param[out] MasterRand Master key random
****************************************************************************************
*/
void LM_GetMasterKeyRand(struct ltk *MasterRand);
/**
****************************************************************************************
* @brief This function read the current Random vector for broadcast encryption.
*
* @param[out] MasterRand Random Vector
****************************************************************************************
*/
void LM_GetMasterEncRand(struct ltk *MasterRand);
/**
****************************************************************************************
* @brief This function read Broadcast Encryption Key Size.
*
* @return Encryption Key Size
****************************************************************************************
*/
uint8_t LM_GetMasterEncKeySize(void);
/// @} LB
#endif // LB_H_
+286
View File
@@ -0,0 +1,286 @@
/**
****************************************************************************************
*
* @file lb.h
*
* @brief Link Broadcaster internal definition
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef LB_INT_H_
#define LB_INT_H_
#include "rwbt_config.h"
/**
****************************************************************************************
* @addtogroup LB Link Broadcaster
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdint.h> // standard integer
#include <stdbool.h> // standard boolean
/*
* DEFINES
****************************************************************************************
*/
/// Maximum number of instances of the LB task
#define LB_IDX_MAX 1
/// Default number broadcast retransmissions
#define LB_DEFAULT_NBC 2
/// As default CSB lt_addr is not reserved - invalid value 0 denotes this
#define LB_CSB_LT_ADDR_NOT_RESERVED 0
/// LMP message instant offset, where a specific clock instant is required (in slots)
#define LB_CLK_ADJ_CLK_TX_INSTANT_OFFSET 10
/// Minimum offset to perform a coarse clock adjust
#define LB_PCA_MIN_CC_ADJ_US 40
/*
* ENUMERATIONS
****************************************************************************************
*/
/// Possible states of the LB task
enum LB_STATE
{
/// FREE state
LB_IDLE,
/// WAIT MASTER KEY CFM state message handlers.
LB_WAIT_MASTER_KEY_CFM,
/// WAIT RESTART ENC CFM state message handlers.
LB_WAIT_RESTART_ENC_CFM,
// Number of states.
LB_STATE_MAX
};
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
#if PCA_SUPPORT
/// LC PCA coase clock adjustment Structure
struct lb_pca_tag
{
/// transaction ID
uint8_t tr_id;
/// aggregate coarse clock adjustment period
uint8_t frame_period;
/// coarse clock adjustment event id
uint8_t clk_adj_id;
/// coarse clock adjustment instant (in 625us BT slots)
uint32_t clk_adj_instant;
/// coarse clock adjustment us offset
int16_t clk_adj_us;
/// coarse clock adjustment slot offset
uint8_t clk_adj_slots;
/// coarse clock adjustment mode
uint8_t clk_adj_mode;
/// coarse clock adjustment PDU instant
uint32_t clk_adj_clk;
/// clock_adj instant pending
bool instant_pending;
/// number of pending LMP_clk_adj_ack responses
uint8_t pending_clk_adj_acks;
/// clk_adj_ack idx flags - one per slave
uint16_t clk_adj_ack_flags;
/// link id recovery with sscan
uint8_t sscan_link_id;
};
#endif // PCA_SUPPORT
///LB master key environment structure
struct master_key
{
/// encryption key size mask
uint16_t enc_key_size_msk;
/// encryption mode
uint8_t enc_mode;
/// status
uint8_t status;
/// in use boolean
bool in_use;
};
/// LB environment structure
struct lb_env_tag
{
#if CSB_SUPPORT
/// reserved lt_addr for CSB
uint8_t res_lt_addr;
/// max packet size for CSB data
uint16_t csb_max_pkt_size;
/// CSB mode active flag
bool csb_mode_enabled;
/// CSB interval (in half-slots)
uint16_t csb_interval;
/// CSB offset (in half-slots)
uint16_t csb_offset;
/// CSB buffer pointer
uint16_t buf_ptr;
/// CSB buffer size
uint16_t csb_buf_data_len;
/// Sync Train service data
uint8_t service_data;
#endif // CSB_SUPPORT
#if CSB_SUPPORT || PCA_SUPPORT
/// Sync Train timeout
uint32_t sync_train_to;
/// Sync Train interval
uint32_t sync_train_intv;
/// Synchronization_scanTO (in slots)
uint16_t sync_scan_to;
/// Sync_Scan_Window (in slots)
uint16_t sync_scan_win;
/// Sync_Scan_Interval (in slots)
uint16_t sync_scan_int;
#endif // CSB_SUPPORT || PCA_SUPPORT
/// Active channel Map for CSB
struct chnl_map ch_map;
/// nb of piconet broadcast acl
uint16_t nb_pic_acl;
/// connection handle
uint16_t conhdl;
/// act handle
uint16_t act_hdl;
/// piconet handle
uint16_t pic_hdl;
/// process id count
uint16_t pid_lc_cnt;
/// nb broadcast retransmissions
uint8_t num_bcst_ret;
#if PCA_SUPPORT
/// Piconet clock adjust data structure
struct lb_pca_tag pca;
#endif // PCA_SUPPORT
/// master key
struct master_key mstkey[MAX_NB_ACTIVE_ACL];
/// bd address
uint8_t lid;
/// new key flag
uint8_t new_key_flag;
/// master key request flag
bool mst_key_req;
/// encryption broadcast
bool enc_brcst;
/// master key
struct ltk LM_MasterKey;
/// master random key
struct ltk LM_MasterKeyRand;
/// master encryption key
struct ltk LM_MasterEncRand;
/// master encryption key size
uint8_t LM_MasterEncKeySize;
};
/*
* GLOBAL VARIABLE DEFINITION
*****************************************************************************************
*/
/// LB task descriptor
extern const struct ke_task_desc TASK_DESC_LB;
/// LB task message handlers table
extern const struct ke_state_handler lb_default_handler;
/// LB task state
extern ke_state_t lb_state[LB_IDX_MAX];
/// LB environment variable
extern struct lb_env_tag lb_env;
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Handle the master key creation.
*
* This function create the master key and send the request over every pid LC
****************************************************************************************
*/
void lb_mst_key(void);
/**
****************************************************************************************
* @brief Handle the master key creation completion.
*
* This function create the master key and send the request over every pid LC
****************************************************************************************
*/
void lb_mst_key_cmp(uint8_t status, uint16_t conhdl, uint8_t new_key_flag);
/**
****************************************************************************************
* @brief Restart encryption
*
* @param[in] conhdl Connection handle
****************************************************************************************
*/
void lb_mst_key_restart_enc(uint16_t conhdl);
/**
****************************************************************************************
* @brief This function start Active Broadcast Encryption link.
****************************************************************************************
*/
void lb_mst_start_act_bcst_enc(void);
/**
****************************************************************************************
* @brief This function Stop Active Broadcast Encryption.
****************************************************************************************
*/
void lb_mst_stop_act_bcst_enc(void);
#if PCA_SUPPORT
/**
****************************************************************************************
* @brief Functions dedicated to send broadcast LMP
*
* @param[in] clk_adj_instant Instant.
* @param[in] clk_adj_id Clock Adjust ID.
* @param[in] clk_adj_us Adjustment us
* @param[in] clk_adj_slots Adjustment slots
* @param[in] clk_adj_mode Mode.
* @param[in] clk_adj_clk Current clock
* @param[in] tr_id Transaction ID
* *****************************************************************************************
*/
void lb_send_pdu_clk_adj(uint32_t clk_adj_instant, uint8_t clk_adj_id, int16_t clk_adj_us, uint8_t clk_adj_slots, uint8_t clk_adj_mode, uint32_t clk_adj_clk, uint8_t tr_id);
#endif //PCA_SUPPORT
/// @} LB
#endif // LB_INT_H_
+528
View File
@@ -0,0 +1,528 @@
/**
****************************************************************************************
*
* @file lc.h
*
* @brief Main API file for the Link Controller
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef LC_H_
#define LC_H_
/**
****************************************************************************************
* @defgroup LC Link Controller
* @ingroup ROOT
* @brief BT Lower Layers
*
* The CONTROLLER contains the modules allowing the physical link establishment,
* maintenance and management.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_task.h" // Task definitions
#include "ke_task.h" // kernel task definitions
#include "co_bt.h"
/*
* DEFINES
****************************************************************************************
*/
/// No connection handle
#define NO_CON_HDL 65535
/// No TID
#define NO_TID_FREE NO_CON_HDL
/*
* ENUMERATION DEFINITIONS
****************************************************************************************
*/
/// Message API of the LC task
enum LC_CON_REASON
{
LC_MASTER_CON,
LC_SLAVE_CON,
LC_REM_NAME,
};
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
///Key status
enum
{
KEY_ABSENT = 0,
KEY_PRESENT,
KEY_PENDING,
};
///Pin Status
enum{
PIN_ABSENT = 0,
PIN_PRESENT,
};
/*
* MESSAGES
****************************************************************************************
*/
/// Message API of the LC task
/*@TRACE*/
enum lc_msg_id
{
LC_MSG_ID_MSG_FIRST = TASK_FIRST_MSG(TASK_ID_LC),
/*
* ************** Msg LC->LC****************
*/
LC_LMP_RX,
LC_SYNC_IND,
LC_COMPUTE_DHKEY,
LC_ECC_RESULT_IND,
LC_LMP_RSP_TO,
LC_CON_ACCEPT_TO,
LC_AFH_REPORT_TO,
LC_AFH_UPDATE_IND,
LC_AUTH_PAYL_NEARLY_TO,
LC_AUTH_PAYL_REAL_TO,
LC_LMP_RSP_TO_FLOW_SPEC,
LC_OP_LOC_SWITCH_REQ,
LC_OP_LOC_SNIFF_REQ,
LC_OP_LOC_UNSNIFF_REQ,
#if MAX_NB_SYNC
LC_OP_LOC_SYNC_CON_REQ,
#endif // MAX_NB_SYNC
LC_SAM_SUBMAP_UPDATE_IND,
LC_SAM_MAP_UPDATE_IND,
/*
* ************** Msg LB->LC****************
*/
LC_MST_KEY_REQ,
#if PCA_SUPPORT
LC_PCA_SSCAN_CLK_IND,
#endif // PCA_SUPPORT
/*
* ************** Msg LMP****************
*/
LC_OP_FEAT_IND,
LC_OP_VERS_IND,
LC_OP_CLKOFF_IND,
LC_OP_TIMACC_IND,
LC_OP_PT_IND,
#if RW_BT_MWS_COEX
LC_OP_SAM_IND,
LC_OP_SAM_CFM,
#endif //RW_BT_MWS_COEX
LC_OP_HL_CNX_IND,
LC_OP_HL_CNX_CONT_IND,
LC_OP_AUTH_IND,
LC_OP_ENC_IND,
LC_OP_EPR_IND,
LC_OP_SET_CMP_IND,
LC_OP_NAME_REQ_IND,
LC_OP_SSRNEGO_IND,
LC_OP_QOS_IND,
LC_OP_DETACH_IND,
LC_AUTH_STG1_RANDN,
LC_QUERY_HOST_EXP_IND,
/*
* ************** Msg LD->LC****************
*/
LC_LMP_RX_IND,
LC_LMP_TX_CFM,
LC_ACL_RX_IND,
LC_ACL_RX_MIC_ERR_IND,
LC_ACL_TX_CFM,
LC_ACL_DISC_IND,
LC_RSW_END_IND,
LC_RSW_SLOT_OFFSET_IND,
LC_PWR_INCR_IND,
LC_PWR_DECR_IND,
LC_PWR_MAX_IND,
LC_SSR_INST_IND,
LC_SNIFF_OFFSET_UPD_IND,
LC_SCO_OFFSET_UPD_IND,
#if VOICE_OVER_HCI
LC_SYNC_RX_IND,
LC_SYNC_TX_CFM,
#endif //VOICE_OVER_HCI
#if PCA_SUPPORT
LC_LOCAL_PCA_REQ,
LC_PCA_SSCAN_START_REQ,
#endif // PCA_SUPPORT
LC_MWS_PATTERN_IND,
};
/*
* ************** API LD->LC ****************
*/
/// LC LMP reception indication structure
/*@TRACE*/
struct lc_lmp_rx_ind
{
/// PDU length
uint8_t length;
/// PDU (packed)
uint8_t pdu[__ARRAY_EMPTY];
};
/// LC LMP reception structure
/*@TRACE*/
struct lc_lmp_rx
{
/// PDU (unpacked)
uint8_t pdu[1];
};
/// LC LMP transmission confirmation structure
/*@TRACE*/
struct lc_lmp_tx_cfm
{
/// EM buffer containing PDU
uint16_t em_buf;
};
/// LC ACL reception indication structure
/*@TRACE*/
struct lc_acl_rx_ind
{
/// EM buffer containing PDU
uint16_t em_buf;
/// Data length + Data Flags (PBF + BF)
uint16_t data_len_flags;
};
/// LC ACL transmission confirmation structure
/*@TRACE*/
struct lc_acl_tx_cfm
{
/// Indicated whether buffer has been successfully transmitted (False) or flushed (True)
bool flushed;
};
/// LC Role Switch end indication structure
/*@TRACE*/
struct lc_rsw_end_ind
{
/// Status
uint8_t status;
};
/// LC sniff offset update indication structure
/*@TRACE*/
struct lc_sniff_offset_upd_ind
{
/// Sniff offset in half-slots
uint16_t sniff_offset;
};
/// LC SCO offset update indication structure
/*@TRACE*/
struct lc_sco_offset_upd_ind
{
/// SCO link id
uint8_t sco_link_id;
/// SCO offset in slots
uint16_t sco_offset;
};
#if VOICE_OVER_HCI
/// LC SYNC reception indication structure
/*@TRACE*/
struct lc_sync_rx_ind
{
/// EM buffer containing PDU
uint16_t em_buf;
/// Data length
uint8_t data_len;
/// Packet status flag
uint8_t packet_status_flag;
/// Synchronous link identifier
uint8_t sync_link_id;
};
/// LC SYNC transmission confirmation structure
/*@TRACE*/
struct lc_sync_tx_cfm
{
/// Synchronous link identifier
uint8_t sync_link_id;
};
#endif //VOICE_OVER_HCI
#if PCA_SUPPORT
/// LC PCA local adjustment request structure
/*@TRACE*/
struct lc_local_pca_req
{
/// Clock adjusted us
int16_t clk_adj_us;
/// Clock adjusted slots
uint8_t clk_adj_slots;
/// Clock adjusted period (slots)
uint8_t clk_adj_period;
};
/// LC Sync Scan start request for PCA recovery mode
/*@TRACE*/
struct lc_pca_sscan_start_req
{
/// Scan Window
uint16_t scan_window;
/// Scan Interval
uint16_t scan_interval;
/// Scan Timeout
uint32_t scan_timeout;
};
#endif // PCA_SUPPORT
/*
* ************** API LB->LC ****************
*/
///LC master key request message structure
/*@TRACE*/
struct lc_mst_key_req
{
///New key flag
uint8_t new_key_flag;
};
#if PCA_SUPPORT
///LB indicates clock recovery data to LC
/*@TRACE*/
struct lc_pca_sscan_clk_ind
{
/// Clock_Offset (28 bits) - (CLKNslave - CLK) modulo 2^28
uint32_t clock_offset;
/// Bit offset (CLKNslave - CLK) modulo 2^28
int16_t bit_offset;
/// BD_ADDR
struct bd_addr bd_addr;
};
#endif // PCA_SUPPORT
/*
* ************** API LC->LC ****************
*/
/// Setup synchronous connection message structure
/*@TRACE*/
struct lc_op_loc_sniff_req
{
/// Maximum interval (in slots)
uint16_t max_int;
/// Minimum interval (in slots)
uint16_t min_int;
/// Attempts (number of receive slots) (in slots)
uint16_t attempt;
/// Timeout (number of receive slots) (in slots)
uint16_t timeout;
};
#if MAX_NB_SYNC
/// Setup synchronous connection message structure
/*@TRACE*/
struct lc_op_loc_sync_con_req
{
/// Connection handle
uint16_t conhdl;
/// Indicate if the incoming HCI command is HCI_Setup_Sync_Con or HCI_Enhanced_Setup_Sync_Con
bool old_style;
/// Indicate if the procedure is initiated by the host (true) or not (false)
bool host_initiated;
};
#endif // MAX_NB_SYNC
/// LC SAM Submap update indication structure
struct lc_sam_submap_update_ind
{
/// Update mode
uint8_t update_mode;
/// Submap
uint8_t submap[SAM_TYPE0_SUBMAP_LEN];
/// num Tx slots
uint16_t n_tx_slots;
/// num Rx slots
uint16_t n_rx_slots;
};
/// LC SAM Map update indication structure
struct lc_sam_map_update_ind
{
/// SAM Pattern Index
uint8_t pattern_index;
/// Tsam-sm (slots)
uint8_t t_sam_sm;
/// Nsam-sm (slots)
uint8_t n_sam_sm;
/// SAM Submaps
struct sam_submaps submaps;
};
/// LC MWS Pattern index update indication strucutre
struct lc_mws_pattern_ind
{
/// Active pattern index
uint8_t pattern_index;
/// Interval
//uint16_t interval;
/// Time when pattern will be activated
rwip_time_t time;
/// Tsam - length of SAM pattern (slots)
uint16_t t_sam;
/// Tsam_sm = length of SAM submaps (slots)
uint8_t t_sam_sm;
/// Number of TX slots in this pattern
uint16_t n_tx_slots;
/// Number of RX slots in this pattern
uint16_t n_rx_slots;
/// Number of external submaps in this pattern
uint8_t n_ex_sm;
};
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialization of the BT LC task
*
* This function initializes the LC task, as well as the environment of the LC
****************************************************************************************
*/
void lc_init(void);
/**
****************************************************************************************
* @brief Reset the BT LC task
****************************************************************************************
*/
void lc_reset(void);
/**
****************************************************************************************
* @brief Start an LC task instance
*
* This function starts an LC task instance for a connection establishment or name
* request.
*
* @param[in] link_id Link identifier
* @param[in] reason Purpose of the connection (0: Master | 1: Slave | 2: Rem Name)
* @param[in] bd_addr Peer device bd_addr
* @param[in] pkt_type ACL packet types (master links only)
* @param[in] switch_en Indicates whether role switch is enabled or not (master links only)
* @param[in] class_of_dev Peer device Class of Device (slave links only)
* @param[in] link_pol_stg Default link policy settings
* @param[in] slave_timing_info_ptr Slave timing information pointer (slave links only)
****************************************************************************************
*/
void lc_start(uint8_t link_id, uint8_t reason, struct bd_addr bd_addr, uint16_t pkt_type, uint8_t switch_en, struct devclass class_of_dev, uint8_t link_pol_stg, void* slave_timing_info_ptr);
/**
****************************************************************************************
* @brief LC util to get max packet size - used external to LC
*
* @param[in] pkt_type ACL packet types
*
* @return max packet size
****************************************************************************************
*/
uint16_t lc_util_get_max_packet_size(uint16_t PacketType);
/**
****************************************************************************************
* @brief This function is used to compute the number of slot required.
*
* @param[in] PacketType Packet type
*
* @return Nb of computed slot of the packet type.
****************************************************************************************
*/
uint8_t LM_MaxSlot(uint16_t PacketType);
#if PCA_SUPPORT
/**
****************************************************************************************
* @brief This function prepares all slaves in advance of an LMP_clk_adj.
*
* @return status as a result of processing the request.
****************************************************************************************
*/
uint8_t lc_prepare_all_slaves_for_clk_adj(void);
/**
****************************************************************************************
* @brief This function notifies all slaves of clk_adj procedure completion.
*
****************************************************************************************
*/
void lc_notify_all_slaves_clk_adj_complete(void);
#endif // PCA_SUPPORT
/**
****************************************************************************************
* @brief This function checks if all connected support secure connections.
*
* @return True: secure connection supported by all slaves / False otherwise
****************************************************************************************
*/
bool lc_check_all_slaves_support_sec_con(void);
#if (MAX_NB_SYNC > 0)
/**
****************************************************************************************
* @brief This function returns the number of synchronous links.
*
* @return number of synchronous links present.
*
****************************************************************************************
*/
uint8_t lm_get_nb_sync_link(void);
/**
****************************************************************************************
* @brief This function returns the minimum synchronous link interval.
*
* @return minimum synchronous link interval, else 0xFF if no synchronous links are present.
*
****************************************************************************************
*/
uint8_t lm_get_min_sync_intv(void);
#endif //(MAX_NB_SYNC > 0)
/// @} LC
#endif // LC_H_
File diff suppressed because it is too large Load Diff
+90
View File
@@ -0,0 +1,90 @@
/**
****************************************************************************************
*
* @file lc_lmppdu.h
*
* @brief LM LMP PDU packing and unpacking utilities header file.
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LM_LMPPDU_H_
#define LM_LMPPDU_H_
/**
****************************************************************************************
* @defgroup LMLMPPDU LMP PDUs
* @ingroup LM
* @brief LM module for LMP PDU packing and unpacking.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
/*
* FUNCTION DECLARATIONS
* ***************************************************************************************
*/
/**
******************************************************************************************
* @brief Function called to pack and send an LMP PDU.
*
* @param param Pointer to the param part of the ke_msg used to create the PDU structure
* and packet.
*
* @return Length of PDU.
******************************************************************************************
*/
void lc_send_lmp(uint8_t link_id, void *param);
//Functions dedicated to send a LMP
void lc_send_pdu_acc(uint8_t lid,uint8_t opcode,uint8_t tr_id);
void lc_send_pdu_acc_ext4(uint8_t lid,uint8_t opcode,uint8_t tr_id);
void lc_send_pdu_not_acc(uint8_t lid,uint8_t opcode,uint8_t reason,uint8_t tr_id);
void lc_send_pdu_not_acc_ext4(uint8_t lid,uint8_t opcode,uint8_t reason,uint8_t tr_id);
void lc_send_pdu_au_rand(uint8_t lid,struct ltk* random,uint8_t tr_id);
void lc_send_pdu_in_rand(uint8_t lid,struct ltk* random,uint8_t tr_id);
void lc_send_pdu_comb_key(uint8_t lid,struct ltk* random,uint8_t tr_id);
void lc_send_pdu_max_slot(uint8_t lid,uint8_t max_slot,uint8_t tr_id);
void lc_send_pdu_max_slot_req(uint8_t lid,uint8_t max_slot,uint8_t tr_id);
void lc_send_pdu_encaps_payl(uint8_t lid,struct byte16* data,uint8_t tr_id);
void lc_send_pdu_encaps_head(uint8_t idx, uint8_t tr_id, uint8_t maj_type, uint8_t min_type, uint8_t payl_len);
void lc_send_pdu_clk_adj_ack(uint8_t idx, uint8_t clk_adj_id, uint8_t tr_id);
void lc_send_pdu_clk_adj_req(uint8_t idx, uint16_t clk_adj_us, uint8_t clk_adj_slots, uint8_t clk_adj_period, uint8_t tr_id);
void lc_send_pdu_sam_define_map(uint8_t idx, uint8_t sam_index, uint8_t t_sam_sm, uint8_t n_sam_sm, const uint8_t* p_submaps, uint8_t tr_id);
void lc_send_pdu_sam_set_type0(uint8_t idx, uint8_t update_mode, const uint8_t* p_submap, uint8_t tr_id);
void lc_send_pdu_sam_switch(uint8_t idx, uint8_t sam_index, uint8_t flags, uint8_t d_sam, uint32_t instant, uint8_t tr_id);
void lc_send_pdu_ptt_req(uint8_t lid,uint8_t ptt,uint8_t tr_id);
void lc_send_pdu_sp_nb(uint8_t lid,struct byte16* data,uint8_t tr_id);
void lc_send_pdu_sp_cfm(uint8_t lid,struct byte16* data,uint8_t tr_id);
void lc_send_pdu_sres(uint8_t lid,struct sres_nb* data,uint8_t tr_id);
void lc_send_pdu_sco_lk_req(uint8_t lid);
void lc_send_pdu_sco_lk_rem_req(uint8_t lid, uint8_t handle, uint8_t reason,uint8_t tr_id);
void lc_send_pdu_esco_lk_req(uint8_t lid);
void lc_send_pdu_esco_lk_rem_req(uint8_t lid, uint8_t handle, uint8_t reason,uint8_t tr_id);
void lc_send_pdu_auto_rate(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_lsto(uint8_t lid,uint16_t timeout,uint8_t role);
void lc_send_pdu_enc_key_sz_req(uint8_t lid,uint8_t key_size,uint8_t tr_id);
void lc_send_pdu_feats_ext_req(uint8_t lid, uint8_t page, uint8_t tr_id);
void lc_send_pdu_io_cap_res(uint8_t lid);
void lc_send_pdu_num_comp_fail(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_pause_enc_aes_req(uint8_t idx, uint8_t tr_id, struct byte16* random);
void lc_send_pdu_paus_enc_req(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_resu_enc_req(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_setup_cmp(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_qos_req(uint8_t lid,uint8_t nb_bcst, uint16_t poll_int,uint8_t tr_id);
void lc_send_pdu_slot_off(uint8_t lid, uint16_t slot_off,uint8_t tr_id);
void lc_send_pdu_vers_req(uint8_t lid, uint8_t role);
void lc_send_pdu_dhkey_chk(uint8_t lid,struct ltk* dhkey,uint8_t tr_id);
void lc_send_pdu_feats_res(uint8_t lid,uint8_t tr_id);
void lc_send_pdu_set_afh(uint8_t lid,uint32_t instant,uint8_t mode,uint8_t tr_id);
void lc_send_pdu_tim_acc(uint8_t idx,uint8_t tr_id);
/// @} LMLMPPDU
#endif //LM_LMPPDU_H_
+194
View File
@@ -0,0 +1,194 @@
/**
****************************************************************************************
*
* @file lc_sco.h
*
* @brief Definitions for LC SCO procedures
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LC_SCO_H_
#define LC_SCO_H_
/**
****************************************************************************************
* @defgroup LCSCO Synchronous Connection Oriented connection
* @ingroup LC
* @brief Responsible for handling SCO procedures.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // stack configuration
#if (MAX_NB_SYNC > 0)
#include <stdint.h> // integer
#include <stdbool.h> // boolean
#include "ke_task.h" // kernel task
/*
* CONSTANT DEFINITIONS
****************************************************************************************
*/
/*
* STRUCTURE DEFINITIONS
****************************************************************************************
*/
/// Structure for (e)SCO parameters
struct lc_sco_air_params_tag
{
///Transaction ID
uint8_t tr_id;
/// eSCO handle
uint8_t esco_hdl;
/// eSCo LT Address
uint8_t esco_lt_addr;
/// Timing control flags
uint8_t flags;
/// Dsco or Desco (in slots)
uint8_t d_esco;
/// Interval (in slots)
uint8_t t_esco;
/// Retransmission window size (in slots)
uint8_t w_esco;
/// Packet M->S type
uint8_t m2s_pkt_type;
/// Packet S->M type
uint8_t s2m_pkt_type;
/// Packet M->S length for eSCO link (in bytes)
uint16_t m2s_pkt_len;
/// Packet S->M length for eSCO link (in bytes)
uint16_t s2m_pkt_len;
/// Air Mode
uint8_t air_mode;
/// Negotiation state
uint8_t nego_state;
};
/// Structure for Host synchronous parameters
struct lc_sco_host_params_tag
{
uint32_t tx_bw; // Transmit Bandwidth (in B/sec)
uint32_t rx_bw; // Receive Bandwidth (in B/sec)
uint8_t tx_cod_fmt[5]; // Transmit Coding Format
uint8_t rx_cod_fmt[5]; // Receive Coding Format
uint16_t tx_cod_fr_sz; // Transmit Codec Frame Size (in B)
uint16_t rx_cod_fr_sz; // Receive Codec Frame Size (in B)
uint32_t in_bw; // Input Bandwidth (in B/sec)
uint32_t out_bw; // Output Bandwidth (in B/sec)
uint8_t in_cod_fmt[5]; // Input Coding Format
uint8_t out_cod_fmt[5]; // Output Coding Format
uint16_t in_cod_data_sz; // Input Coded Data Size (in bits)
uint16_t out_cod_data_sz; // Output Coded Data Size (in bits)
uint8_t in_data_fmt; // Input PCM Data Format
uint8_t out_data_fmt; // Output PCM Data Format
uint8_t in_msb_pos; // Input PCM Sample Payload MSB Position (in bits)
uint8_t out_msb_pos; // Output PCM Sample Payload MSB Position (in bits)
uint8_t in_data_path; // Input Data Path (VoHCI / PCM / Other ...)
uint8_t out_data_path; // Output Data Path
uint8_t in_tr_unit_sz; // Input Transport Unit Size (in bits)
uint8_t out_tr_unit_sz; // Output Transport Unit Size (in bits)
uint16_t max_lat; // Max Latency (in ms)
uint16_t packet_type; // Packet Type (HV1 / HV2 / HV3 / EV3 / EV4 / EV5 / 2EV3 / 3EV3 / 2EV5 / 3EV5)
uint8_t retx_eff; // Retransmission Effort (No, opt power, opt quality, don't care)
};
/*
* FUNCTIONS DECLARATION
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialize the LC_SCO module
****************************************************************************************
*/
void lc_sco_init(void);
/**
****************************************************************************************
* @brief Reset LC_SCO module
****************************************************************************************
*/
void lc_sco_reset(void);
/**
****************************************************************************************
* @brief Detach all SCO connections on a ACL link
*
* This function starts the disconnection of all SCO links on a ACL connection.
*
* When the full disconnection procedure is requested, each disconnection procedure
* loops to this function to restart the next disconnection until no more SCO on the ACL
* is present.
*
* Host is NOT notified for each SCO link disconnection.
*
* param[in] pid Process identifier (task / instance)
* param[in] reason Detach reason (error code)
*
* return status
****************************************************************************************
*/
uint8_t lc_sco_detach(ke_task_id_t pid, uint8_t reason);
/**
****************************************************************************************
* @brief Release all SCO connections on a ACL link
*
* This function releases all SCO links on a ACL connection, without notification to the
* peer device. However, Host is notified for each SCO link disconnection.
*
* param[in] pid Process identifier (task / instance)
* param[in] reason Detach reason (error code)
****************************************************************************************
*/
void lc_sco_release(ke_task_id_t pid, uint8_t reason);
uint8_t lc_sco_host_request(ke_task_id_t pid, bool old_style, bool host_initiated, uint16_t conhdl, struct lc_sco_host_params_tag * p_host_params);
uint8_t lc_sco_host_accept(ke_task_id_t pid, bool old_style, bool very_old_style, struct lc_sco_host_params_tag * p_host_params);
void lc_sco_host_reject(ke_task_id_t pid, bool very_old_style, uint8_t status);
uint8_t lc_sco_host_request_disc(ke_task_id_t pid, uint16_t conhdl, uint8_t reason);
void lc_sco_peer_request(ke_task_id_t pid, uint8_t req_type, struct lc_sco_air_params_tag * p_peer_params);
void lc_sco_peer_accept(ke_task_id_t pid);
void lc_sco_peer_reject(ke_task_id_t pid, uint8_t reason);
void lc_sco_peer_request_disc(ke_task_id_t pid, uint8_t req_type, uint8_t scohdl, uint8_t reason);
void lc_sco_peer_accept_disc(ke_task_id_t pid);
void lc_sco_peer_reject_disc(ke_task_id_t pid, uint8_t reason);
void lc_sco_baseband_ack(ke_task_id_t pid, uint8_t lmp_opcode);
void lc_sco_timeout(ke_task_id_t pid);
/**
****************************************************************************************
* @brief This function is used to update the SCO offset.
*
* @param[in] sync_linkid SCO link ID
* @param[in] sco_offset SCO offset in slots
*
* @return True if SCO link present
****************************************************************************************
*/
void lc_sco_offset_update(uint8_t sync_linkid, uint16_t sco_offset);
#endif // (MAX_NB_SYNC > 0)
/// @} LCSCO
#endif // LC_SCO_H_
+111
View File
@@ -0,0 +1,111 @@
/**
****************************************************************************************
*
* @file lm_lowpow.h
*
* @brief Link Manager Utilities functions
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LM_LOWPOW_H_
#define LM_LOWPOW_H_
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // stack configuration
#include <stdint.h> // integer
#include <stdbool.h> // boolean
/**
****************************************************************************************
* @defgroup LMLOWPOW Low Power Functions
* @ingroup LM
* @brief LM module for low power mode management (sniff, hold, park).
* @{
****************************************************************************************
*/
/// Commands for Sniff
#define SNIFF_HL_REQ 0
#define SNIFF_PEER_REQ 1
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initializes Sniff block.
****************************************************************************************
*/
void lc_sniff_init(bool reset);
/**
****************************************************************************************
* @brief Clear sniff parameters of a specific link
****************************************************************************************
*/
void lc_sniff_clear(uint8_t link_id);
/**
****************************************************************************************
* @brief Get sniff interval and subrate
* @param[in] link_id Link identifier
* @param[out] interval Sniff interval (in slots)
* @param[out] max_subrate Maximum sniff subrate (in number of sniff events, 0 if no subrating)
****************************************************************************************
*/
void lc_sniff_interval_get(uint8_t link_id, uint16_t * interval, uint8_t * max_subrate);
/**
****************************************************************************************
* @brief This function is used to update the sniff offset
*
* @param[in] link_id Link identifier
* @param[in] sniff_offset Sniff offset in half-slots
****************************************************************************************
*/
void lc_sniff_offset_update(uint8_t link_id, uint16_t sniff_offset);
void lc_sniff_host_request(ke_task_id_t pid, uint16_t max_int, uint16_t min_int, uint16_t attempt, uint16_t timeout);
void lc_sniff_peer_request(ke_task_id_t pid, uint8_t flags, uint16_t d_sniff, uint16_t t_sniff, uint16_t sniff_attempt, uint16_t sniff_to);
void lc_sniff_peer_accept(ke_task_id_t pid);
void lc_sniff_peer_reject(ke_task_id_t pid, uint8_t reason);
void lc_sniff_baseband_ack(ke_task_id_t pid, uint8_t lmp_opcode);
void lc_sniff_timeout(ke_task_id_t pid);
/**
****************************************************************************************
* @brief Unsniff link
*
* This function initiating an unsniff LMP procedure.
*
* param[in] pid Process identifier (task / instance)
****************************************************************************************
*/
void lc_sniff_unsniff(ke_task_id_t pid);
void lc_sniff_unsniff_peer_request(ke_task_id_t pid);
void lc_sniff_unsniff_peer_accept(ke_task_id_t pid);
void lc_sniff_unsniff_peer_reject(ke_task_id_t pid, uint8_t reason);
void lc_sniff_ssr_nego(ke_task_id_t pid);
void lc_sniff_ssr_host_request(ke_task_id_t pid, uint16_t max_lat, uint16_t min_rem_to, uint16_t min_loc_to);
void lc_sniff_ssr_peer_request(ke_task_id_t pid, uint8_t max_subrate, uint16_t min_to, uint32_t instant);
void lc_sniff_ssr_peer_response(ke_task_id_t pid, uint8_t max_subrate, uint16_t min_to, uint32_t instant);
void lc_sniff_ssr_peer_reject(ke_task_id_t pid, uint8_t reason);
void lc_sniff_ssr_baseband_ack(ke_task_id_t pid);
void lc_sniff_ssr_instant(ke_task_id_t pid);
///@} LMLOWPOW
#endif // LM_LMLOWPOW_H_
+229
View File
@@ -0,0 +1,229 @@
/**
****************************************************************************************
*
* @file lc_util.h
*
* @brief LC Util API
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LC_UTIL_H_
#define LC_UTIL_H_
/**
****************************************************************************************
* @addtogroup LCUTIL Link Controller
* @ingroup CONTROLLER
* @brief Link Layer Controller utility
*
* Declaration of the API functions to be called by other layers
*
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdint.h> // integer
#include <stdbool.h> // bool
#include "co_bt.h"
#include "ke_msg.h" // kernel timer definition
/*
* DEFINES
****************************************************************************************
*/
/*
* CONSTANT DEFINITIONS
****************************************************************************************
*/
#define QOS_HL_REQ 0
#define QOS_PEER_REQ 1
#define QOS_PEER_FORCE 2
#define QOS_PEER_REJECT 3
/*
* MACRO DEFINITIONS
****************************************************************************************
*/
/*
* STRUCTURE DEFINITIONS
****************************************************************************************
*/
/*
* FUNCTIONS DECLARATION
****************************************************************************************
*/
/**
****************************************************************************************
* @brief This function is used to compute the resulting ACL packet types.
*
* @param[in] PreferredPacketType Preferred packet type
* @param[in] CurrentPacketType Current packet type in use
* @param[in] KeepCurrent Boolean to keep the current packet type
*
* @return PacketType
****************************************************************************************
*/
uint16_t LM_ComputePacketType(uint16_t PreferredPacketType, uint16_t CurrentPacketType, bool KeepCurrent);
/**
****************************************************************************************
* @brief This function is used to check which ACL packet types are allowed.
*
* @param[in] PacketType ACL packet type
* @param[in] RemoteCapability Remote device capability
*
* @return PacketType
****************************************************************************************
*/
uint16_t LM_UpdateAclPacketType(uint16_t PacketType, uint8_t RemoteCapability);
/**
****************************************************************************************
* @brief This function is used to check which EDR ACL packet types are allowed.
*
* @param[in] PacketType Requested Packet type
* @param[in] RemoteCapabilityByte3 Capability of Remote device
* @param[in] RemoteCapabilityByte4 Capability of Remote device
* @param[in] RemoteCapabilityByte5 Capability of Remote device
*
* @return PossiblePacketType
****************************************************************************************
*/
uint16_t LM_UpdateAclEdrPacketType(uint16_t PacketType,
uint8_t RemoteCapabilityByte3,
uint8_t RemoteCapabilityByte4,
uint8_t RemoteCapabilityByte5);
/**
****************************************************************************************
* @brief This function is used to removed ACL packet type.
*
* @param[out] ReqPacketType Possible packet type
* @param[in] Slot Packet slot (1, 3, 5)
****************************************************************************************
*/
void LM_SuppressAclPacket(uint16_t *ReqPacketType, uint8_t Slot);
/**
****************************************************************************************
* @brief This function is used to retrieve the Quality of Service information
* linked with the connection handle.
*
* @param[in] Role Device role connection
* @param[out] ServiceType Type of service
* @param[out] TokenRate Token rate
* @param[out] PeakBandwidth Bandwidth peak
* @param[out] Latency Latency
* @param[out] DelayVariation Variation
* @param[out] PollInterval Polling interval. Should be even value.
* @param[in] PacketType Type of packet
* @param[in] Request Request type (HL, PEER, FORCE, REJECT)
*
* @return Status
****************************************************************************************
*/
uint8_t LM_GetQoSParam(uint8_t Role, uint8_t *ServiceType,
uint32_t *TokenRate, uint32_t *PeakBandwidth, uint32_t *Latency,
uint32_t *DelayVariation, uint16_t *PollInterval,
uint16_t PacketType, uint8_t Request);
/**
****************************************************************************************
* @brief This function make a COF from a BD_ADDR.
*
* @param[in] BdAddr BD Address
* @param[out] Aco ACO value
****************************************************************************************
*/
void LM_MakeCof(struct bd_addr BdAddr, struct aco *Aco);
/**
****************************************************************************************
* @brief This function is used to check all the EDR features available.
*
* @param[in] RequestFeatures Feature table
*
* @return True if found, False otherwise.
****************************************************************************************
*/
bool LM_CheckEdrFeatureRequest(uint16_t RequestFeatures);
/**
****************************************************************************************
* @brief This function is used to get a feature.
*
* @param[in] FeaturesPtr Feature table
* @param[in] Feature Feature to extract
*
* @return 0 (not found) or 1 (found)
****************************************************************************************
*/
uint16_t LM_GetFeature(struct features *FeaturesPtr, uint8_t Feature);
/**
****************************************************************************************
* @brief This function is used to check if a link key is stored.
*
* @param[in] p_bd_addr BD Address to search
* @param[out] Key Link key
*
* @return Boolean, True if key found, False otherwise
****************************************************************************************
*/
bool lm_look_for_stored_link_key(struct bd_addr *p_bd_addr, struct ltk *Key);
/**
****************************************************************************************
* @brief Converts the Preferred Rate into TX packet type for
* the corresponding link ID.
*
* @param[in] PreferredRate Preferred Rate for the link
* @param[in] pkt_type_table 0: 1MBPS / 1: 2-3MBPS
*
* @return Preferred Packet types
****************************************************************************************
*/
uint16_t lc_util_convert_pref_rate_to_packet_type(uint8_t PreferredRate, uint8_t pkt_type_table);
/**
****************************************************************************************
* @brief Converts the maxslot into TX packet type
*
* @param[in] maxslot Maximum number of slots
*
* @return Possible Packet types
****************************************************************************************
*/
uint16_t lc_util_convert_maxslot_to_packet_type(uint8_t maxslot);
#if MAX_NB_SYNC
/**
****************************************************************************************
* @brief This function is used to get the common packet types
*
* @param[in] SyncPacketType Original packets type (SCO and/or eSCO)
* @param[in] *RemoteFeaturesPtr Pointer on Remote features
*
* @return Common packet types (bit mask)
****************************************************************************************
*/
uint16_t lm_get_common_pkt_types(uint16_t SyncPacketType, struct features *RemoteFeaturesPtr);
#endif // MAX_NB_SYNC
/// @} LC
#endif // LC_UTIL_H_
+194
View File
@@ -0,0 +1,194 @@
/**
****************************************************************************************
*
* @file lm_sco.h
*
* @brief Link Manager synchronous link functions
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LM_SCO_H_
#define LM_SCO_H_
/**
****************************************************************************************
* @defgroup LMSCO SCO Functions
* @ingroup LM
* @brief LM module for synchronous functions.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // stack configuration
#if (MAX_NB_SYNC > 0)
#include "lc_sco.h"
/*
* DEFINITION
* ***************************************************************************************
*/
/// Commands for synchronous link
#define SYNC_HL_REQ 0
#define SYNC_PEER_REQ 1
#define SYNC_HL_RSP 2
#define SYNC_PEER_RSP 3
#define SYNC_HL_MODIF 4
#define SYNC_PEER_MODIF 5
#define SYNC_UPDATE 6
/*
* FUNCTION DECLARATIONS
* ***************************************************************************************
*/
/**
****************************************************************************************
* @brief This function is used to initialize LM Sco Data.
****************************************************************************************
*/
void lm_init_sync(void);
/**
****************************************************************************************
* @brief This function is used to reset LM Sco Data.
****************************************************************************************
*/
void lm_reset_sync(void);
/**
****************************************************************************************
* @brief This function is used to check and store informations about a SCO link.
*
* @param[in] sco_link_id Synchronous link ID
* @param[in] RemoteFeatures Remote device features
* @param[in] Role Master or Slave
* @param[in] SyncType SCO or eSCO
* @param[in] SyncLtAddr Synchronous link LT address
* @param[out] *SyncHdl Synchronous link handle
* @param[in] SyncTxBw TX bandwidth
* @param[in] SyncRxBw RX bandwidth
* @param[in] SyncLat Maximum allowed Latency
* @param[in] SyncVoice Voice settings
* @param[in] SyncAirMode Air Mode
* @param[in] SyncReTx Retransmission effort
* @param[in] SyncPacketType Allowed packet types
* @param[out] sco_params SCO parameters
* @param[in] Request Request originator
*
* @return Status
****************************************************************************************
*/
uint8_t lm_add_sync(uint8_t sco_link_id, struct features *RemoteFeatures,
uint8_t LinkId, uint8_t Role, uint8_t *SyncType,
uint32_t SyncTxBw, uint32_t SyncRxBw, uint16_t SyncLat, uint16_t VoiceSetting,
uint8_t SyncReTx, uint16_t SyncPacketType,
struct lc_sco_air_params_tag * sco_params, uint8_t Request);
/**
****************************************************************************************
* @brief This function is used to check if a Sync link can be modified.
*
* @param[in] sco_link_id Synchronous link ID
* @param[in] SyncType SCO or eSCO
* @param[in] SyncTxBw TX bandwidth
* @param[in] SyncRxBw RX bandwidth
* @param[in] SyncLat Maximum allowed Latency
* @param[in] SyncVoice Voice settings
* @param[in] SyncReTx Retransmission effort
* @param[in] SyncPacketType Allowed packet types
* @param[out] sco_params SCO parameters
* @param[in] Request Request type
*
* @return Status
*
****************************************************************************************
*/
uint8_t lm_modif_sync(uint8_t sco_link_id, uint8_t SyncType,
uint32_t SyncTxBw, uint32_t SyncRxBw, uint16_t SyncLat,
uint16_t SyncVoice, uint8_t SyncReTx, uint16_t SyncPacketType,
struct lc_sco_air_params_tag * sco_params, uint8_t Request);
/**
****************************************************************************************
* @brief This function is used to check the Accept Sync connection parameters.
*
* @param[in] sco_link_id Synchronous link ID
* @param[in] SyncTxBw TX bandwidth
* @param[in] SyncRxBw RX bandwidth
* @param[in] SyncLat Maximum allowed Latency
* @param[in] SyncVoice Voice settings
* @param[in] SyncReTx Retransmission effort
* @param[in] SyncPacketType Allowed packet types
* @param[out] sco_params SCO parameters
*
* @return Status
*
****************************************************************************************
*/
uint8_t lm_check_sync_hl_rsp(uint8_t sco_link_id, uint32_t SyncTxBw, uint32_t SyncRxBw,
uint16_t SyncLat, uint16_t SyncVoice, uint8_t SyncReTx, uint16_t SyncPacketType,
struct lc_sco_air_params_tag * sco_params);
/**
****************************************************************************************
* @brief This function is used to remove stored synchronous link information.
*
* @param[in] sco_link_id Synchronous link ID
****************************************************************************************
*/
void lm_remove_sync(uint8_t sco_link_id);
/**
****************************************************************************************
* @brief This function is used to Restore parameters for a synchronous link.
*
* @param[in] sco_link_id Synchronous link ID
* @param[out] sco_params SCO parameters
* @param[in] Request Request type
*
* @return Status
****************************************************************************************
*/
uint8_t lm_get_sync_param(uint8_t sco_link_id, struct lc_sco_air_params_tag * sco_params, uint8_t Request);
/**
****************************************************************************************
* @brief This function is used to get the Sync Handle of a Sync link.
*
* @param[in] sco_link_id Synchronous link ID
*
* @return Synchronous link handle
****************************************************************************************
*/
uint8_t lm_get_synchdl(uint8_t sco_link_id);
/**
****************************************************************************************
* @brief This function is used to check if an ACL link has at least 1 synchronous link.
*
* @param[in] sco_link_id Synchronous link ID
* @param[in] type Check SCO or eSCO specifically (ACL_TYPE if the type does not matter)
*
* @return True if SCO link present
****************************************************************************************
*/
bool lm_look_for_sync(uint8_t link_id, uint8_t type);
/**************************************************************************************
* @brief Indicate the end of a SCO negotiation
**************************************************************************************/
void lm_sco_nego_end(void);
#endif //(MAX_NB_SYNC > 0)
///@} LMSCO
#endif // LM_SCO_H_
File diff suppressed because it is too large Load Diff
+328
View File
@@ -0,0 +1,328 @@
/**
****************************************************************************************
*
* @file ld_int.h
*
* @brief LD Internal API
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LD_INT_H_
#define LD_INT_H_
/**
****************************************************************************************
* @addtogroup LD
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // stack configuration
#include <stdint.h> // integer
#include <stdbool.h> // boolean
#include "ld.h"
/*
* CONSTANT DEFINITIONS
****************************************************************************************
*/
/// BCH size
#define LD_BCH_SIZE 8
/// Set an ACL link as active
#define LD_ACT_ACL_SET(field, link_id) (field |= (1<<(link_id)))
/// Clear an ACL link from active links
#define LD_ACT_ACL_CLEAR(field, link_id) (field &= ~(1<<(link_id)))
/// Set a SCO link as active
#define LD_ACT_SCO_SET(field, sco_link_id, link_id) \
field = (((field) & ~(0xFF << (8*(sco_link_id+1)))) | (0x80 + link_id) << (8*(sco_link_id+1)));
/// Clear a SCO link from active links
#define LD_ACT_SCO_CLEAR(field, sco_link_id) (field &= ~(0xFF << (8*(sco_link_id+1))))
/// Allocate an event with an associated data structure
#define LD_ALLOC_EVT(data_struct) (struct data_struct *) ke_malloc(sizeof(struct data_struct), KE_MEM_ENV);
/// Initialize memory of an event and an associated data structure
#define LD_INIT_EVT(evt, data_struct) memset(evt , 0, sizeof(struct data_struct));
/// Index for DM1 packet type (used in both BR and EDR)
#define DM1_IDX 0
/// Basic Rate packet types indexes (classified by packet size)
#define DH1_IDX 1
#define DM3_IDX 2
#define DH3_IDX 3
#define DM5_IDX 4
#define DH5_IDX 5
#define BR_IDX_MAX 6
/// Enhanced Data Rate packet types indexes (classified by packet size)
#define DH1_2_IDX 1
#define DH1_3_IDX 2
#define DH3_2_IDX 3
#define DH3_3_IDX 4
#define DH5_2_IDX 5
#define DH5_3_IDX 6
#define EDR_IDX_MAX 7
/*
* ENUMERATION DEFINITIONS
****************************************************************************************
*/
/// Activity type
enum LD_ACT_TYPE
{
LD_ACT_TYPE_ACL,
LD_ACT_TYPE_SCO,
};
/// Active mode
enum LD_ACT_MODE
{
LD_ACT_MODE_OFF,
LD_ACT_MODE_ON,
};
/*
* STRUCTURE DEFINITIONS
****************************************************************************************
*/
/// LD environment structure
struct ld_env_tag
{
/// Local BD_ADDR
struct bd_addr local_bd_addr;
/**
* Class of Device
*
* 0xXXXXXX Class of Device for the device.
*/
struct devclass class_of_dev;
/// Channel assessment data
struct ld_afh_ch_assess_data afh_ch_assess;
#if MAX_NB_SYNC
/// Bit field for PCM setting (used when creating an audio link)
uint8_t pcm_settings[8];
#endif //MAX_NB_SYNC
/// Bit field indicating the active links
///
/// 34 30 ... 24 23 22 ... 16 15 14 ... 8 7 6 ... 0
/// +----+-----------------------+----+-----------------------+----+-----------------------+----+---------------------------+
/// | 0/1| link_id for SCO2 | 0/1| link_id for SCO1 | 0/1| link_id for SCO0 | | ACL[i] is active |
/// +----+-----------------------+----+-----------------------+----+-----------------------+----+---------------------------+
///
uint32_t active_links;
/// Local BCH
uint8_t local_bch[LD_BCH_SIZE];
/// Current RX descriptor index [0:N-1]
uint8_t curr_rxdesc_index;
/// Tx path delay
uint8_t tx_path_delay;
/// Rx path delay
uint8_t rx_path_delay;
/// Expected sync position in us, which incorporates the Rx path delay
uint8_t exp_sync_pos;
/// Maximum value of the local clock drift
uint8_t local_drift;
/// Maximum value of the local clock jitter
uint8_t local_jitter;
/// Maximum value of the local active clock drift
uint8_t local_drift_active;
#if (RW_BT_MWS_COEX)
/// MWS external frame duration (us)
uint16_t mws_ext_fr_duration;
/// MWS external frame sync assert offset (us)
int16_t mws_ext_fr_offset;
/// active MWS pattern index [0-2, 0xFF=disabled]
uint8_t mws_index;
#endif //RW_BT_MWS_COEX
};
#if RW_BT_MWS_COEX
/// MWS pattern update information
typedef struct
{
/// MWS pattern index (0-2, 0xFF=disabled)
uint8_t pattern_index;
/// slot offset (activation time) (slots)
uint8_t slot_offset;
} ld_mwsifstat_t;
#endif //RW_BT_MWS_COEX
/*
* VARIABLE DECLARATION
*****************************************************************************************
*/
/// Basic Rate packet types table (classified by packet size)
extern const uint8_t ld_acl_br_types[BR_IDX_MAX];
/// Basic Rate packet sizes table (classified by packet size)
extern const uint16_t ld_acl_br_sizes[BR_IDX_MAX];
/// Enhanced Data Rate packet types table (classified by packet size)
extern const uint8_t ld_acl_edr_types[EDR_IDX_MAX];
/// Enhanced Data Rate packet sizes table (classified by packet size)
extern const uint16_t ld_acl_edr_sizes[EDR_IDX_MAX];
/// LD environment variable
extern struct ld_env_tag ld_env;
/*
* FUNCTIONS DECLARATION
****************************************************************************************
*/
#if RW_BT_MWS_COEX
/**
****************************************************************************************
* @brief Get the active MWS index
*
* @return Pattern index (0-2, 0xFF=disabled) and activation offset (@see ld_mwsifstat_t)
*
*****************************************************************************************
*/
ld_mwsifstat_t ld_mws_pattern_index_get(void);
/**
****************************************************************************************
* @brief Get the inactivity MWS duration
*
* @return uint8_t Inactivity duration (0:none, 1-30: val*5ms, 31:infinite)
*
*****************************************************************************************
*/
uint8_t ld_mws_inactivity_duration_get(void);
/**
****************************************************************************************
* @brief Build Xi scan mask for MWS COEX generically based on the specified uap_lap.
*
* @param[in] mwscoex_xi_scan_mask Xi mask to build.
* @param[in] uap_lap UAP/LAP for building Xi mask.
* ****************************************************************************************
*/
void ld_mwscoex_xi_scan_mask_build(uint32_t *mwscoex_xi_scan_mask, uint32_t uap_lap);
#endif // RW_BT_MWS_COEX
/**
****************************************************************************************
* @brief Assess a RF channel
*
* @param[in] channel Channel index
* @param[in] rx_ok True: reception is correct | False: reception is corrupted
* @param[in] timestamp Timestamp of the assessment (in half-slots)
*
* @return status 0: success | 1-255: error
****************************************************************************************
*/
void ld_channel_assess(uint8_t channel, bool rx_ok, uint32_t timestamp);
/**
****************************************************************************************
* @brief Free current RX descriptor
****************************************************************************************
*/
void ld_rxdesc_free(void);
/**
****************************************************************************************
* @brief Check if the current RX descriptor is consumed by a given activity
*
* @param[in] label representing the activity (as indicated in the CS)
*
* @return True if current RX descriptor is consumed by the activity identified by label
****************************************************************************************
*/
bool ld_rxdesc_check(uint8_t label);
/**
****************************************************************************************
* @brief Indicate active mode
*
* @param[in] type 0:ACL | 1:SCO
* @param[in] link_id ACL link ID
* @param[in] sco_link_id SCO link ID
* @param[in] mode 0: inactive | 1: active
****************************************************************************************
*/
void ld_active_mode_set(uint8_t type, uint8_t link_id, uint8_t sco_link_id, uint8_t mode);
/**
****************************************************************************************
* @brief Check if an ACL link is active, or a SCO is present on this ACL
*
* @param[in] link_id ACL link ID
*
* @return True if ACL link is active, or a SCO is present on this ACL
****************************************************************************************
*/
bool ld_active_link_check(uint8_t link_id);
void ld_inq_init(void);
void ld_inq_reset(void);
void ld_iscan_init(void);
void ld_iscan_reset(void);
void ld_page_init(void);
void ld_page_reset(void);
void ld_pscan_init(void);
void ld_pscan_reset(void);
void ld_acl_init(void);
void ld_acl_reset(void);
void ld_bcst_acl_init(void);
void ld_bcst_acl_reset(void);
#if CSB_SUPPORT || PCA_SUPPORT
void ld_sscan_init(void);
void ld_sscan_reset(void);
void ld_strain_init(void);
void ld_strain_reset(void);
#endif // CSB_SUPPORT || PCA_SUPPORT
#if CSB_SUPPORT
void ld_csb_tx_init(void);
void ld_csb_tx_reset(void);
void ld_csb_rx_init(void);
void ld_csb_rx_reset(void);
#endif // CSB_SUPPORT
#if PCA_SUPPORT
void ld_pca_init(void);
void ld_pca_reset(void);
#endif // PCA_SUPPORT
/// @} LD
#endif // LD_INT_H_
+219
View File
@@ -0,0 +1,219 @@
/**
****************************************************************************************
*
* @file ld_util.h
*
* @brief LD Util API
*
* Copyright (C) RivieraWaves 2009-2015
*
*
****************************************************************************************
*/
#ifndef LD_UTIL_H_
#define LD_UTIL_H_
/**
****************************************************************************************
* @addtogroup LD
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip_config.h" // stack configuration
#include <stdint.h> // integer
#include "co_bt.h" // BT standard definitions
/*
* CONSTANT DEFINITIONS
****************************************************************************************
*/
/// Undefined BT clock value
#define LD_CLOCK_UNDEF 0xFFFFFFFF
/**
* Margin between 2 ACL frames (in us)
*
* The chosen value is based on the packets duration and the time needed by the system to close and start a frame.
*
* Remaining guard band after Poll/Null : 499us
* Remaining guard band after max DM1 packet : 199us
*
* Time used by system after frame (Power Down / CS+Desc update) : 50
* Time used by system after frame (Power Up / CS+Desc fetch) : 50
*/
#define LD_ACL_INTERFRAME_MARGIN (120)
/**
* Margin after eSCO frame (in us)
*/
#define LD_SCO_INTERFRAME_MARGIN (80)
/**
* Margin after inquiry frames (in us)
*
* The chosen value is based on last frame duration and the time needed by the system to close and start a frame.
*
* Remaining guard band after last ID packet missed reception : 250us
*
* Time used by system after frame (Power Down / CS+Desc update) : 50
* Time used by system after frame (Power Up / CS+Desc fetch) : 50
*/
#define LD_INQ_INTERFRAME_MARGIN (200)
#define LD_PAGE_INTERFRAME_MARGIN (200)
/**
* Margin after scan frames (in us)
*
* The chosen value is based on last frame duration and the time needed by the anticipated prefetch abort mechanism
* to abort the scan. The prefetch abort delay is configured to the register.
*
* Just consider half-slot for enabling interlacing acitivites with high bit offset
*/
#define LD_SCAN_INTERFRAME_MARGIN (SLOT_SIZE - LD_ACL_INTERFRAME_MARGIN + 1)
/*
* MACRO DEFINITIONS
****************************************************************************************
*/
/*
* STRUCTURE DEFINITIONS
****************************************************************************************
*/
/*
* VARIABLE DEFINITIONS
****************************************************************************************
*/
/// Table for synchronization train channels
extern const uint8_t ld_sync_train_channels[SYNC_TRAIN_CHANNEL_NB];
/*
* FUNCTIONS DECLARATION
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Unpack FHS packet
*
* @param[in] fhs_buf_ptr Pointer to the FHS payload buffer (in EM)
* @param[out] bch_ptr Pointer to BCH
* @param[out] bd_addr BD Address
* @param[out] class_dev Class Of Device
* @param[out] lt_addr LT Address
* @param[out] clk_frm Clock (in 1.25ms BT frame)
* @param[out] page_scan_rep_mode Page Scan Repetition Mode (R0, R1, R2)
****************************************************************************************
*/
void ld_util_fhs_unpk(uint16_t fhs_buf_ptr, uint8_t* bch_ptr, struct bd_addr* bd_addr, struct devclass* class_of_dev, uint8_t* lt_addr, uint32_t* clk_frm, uint8_t* page_scan_rep_mode);
/**
****************************************************************************************
* @brief Generate a BCH code from LAP.
*
* The lap pointer must point on a table :
* Msb Lsb
* lap[0] = a7..a0
* lap[1] = a15..a7
* lap[2] = a23..a16
* The bch result is stored in :
* Msb Lsb
* bch[0] = a7..a0
* bch[1] = a15..a8
* bch[2] = a23..a16
* bch[3] = a31..a24
* bch[4] = a39..a32
* bch[5] = a47..a40
* bch[6] = a55..a48
* bch[7] = a63..a56
*
* @param[in] lap Input LAP Vector[3]
* @param[out] bch Output BCH [8]
*
****************************************************************************************
*/
void ld_util_bch_create(uint8_t *lap, uint8_t *bch);
/**
****************************************************************************************
* @brief Pack FHS packet
*
* @param[in] fhs_buf_ptr Pointer to the FHS payload buffer (in EM)
* @param[in] bch_ptr Pointer to BCH
* @param[in] eir Value indicating whether EIR is available or not
* @param[in] sr Scan repetition
* @param[in] bd_addr BD Address
* @param[in] class_of_dev Class Of Device
* @param[in] lt_addr LT Address
* @param[in] page_scan_mode Page scan mode
****************************************************************************************
*/
void ld_util_fhs_pk(uint16_t fhs_buf_ptr, uint8_t* bch_ptr, uint8_t eir, uint8_t sr, struct bd_addr* bd_addr, struct devclass* class_of_dev, uint8_t lt_addr, uint8_t page_scan_mode);
/**
****************************************************************************************
* @brief Set the active AFH Map
*
* @param[in] chnl_map AFH map
****************************************************************************************
*/
void ld_util_active_master_afh_map_set(struct chnl_map* ch_map);
/**
****************************************************************************************
* @brief Get the active AFH Map
*
* @param[out] chnl_map AFH map
****************************************************************************************
*/
struct chnl_map* ld_util_active_master_afh_map_get(void);
/**
****************************************************************************************
* @brief Unpack sync train packet
*
* @param[in] buf_ptr Pointer to the STP payload buffer (in EM)
* @param[out] clk_hs Current piconet clock (CLK) (in half slots)
* @param[out] future_csb_inst Future Connectionless Slave Broadcast Instant
* @param[out] afh_ch_map The current AFH_Channel_Map used for the PBD logical link
* @param[out] mst_bd_addr Master BD Address
* @param[out] csb_intv CSB interval (in slots)
* @param[out] csb_lt_addr The LT_ADDR reserved for the CSB logical transport
* @param[out] svc_data Defined by the service using the Connectionless Slave Broadcast feature
****************************************************************************************
*/
void ld_util_stp_unpk(uint16_t buf_ptr, uint32_t* clk_hs, uint32_t* future_csb_inst, struct chnl_map* afh_ch_map, struct bd_addr* mst_bd_addr, uint16_t* csb_intv, uint8_t* csb_lt_addr, uint8_t* svc_data);
/**
****************************************************************************************
* @brief Pack sync train packet
*
* @param[in] buf_ptr Pointer to the STP payload buffer (in EM)
* @param[out] clk_hs Current piconet clock (CLK) (in half slots)
* @param[out] future_csb_inst Future Connectionless Slave Broadcast Instant (in slots)
* @param[out] afh_ch_map The current AFH_Channel_Map used for the PBD logical link
* @param[out] mst_bd_addr Master BD Address
* @param[out] csb_intv CSB interval (in slots)
* @param[out] csb_lt_addr The LT_ADDR reserved for the CSB logical transport
* @param[out] svc_data Defined by the service using the Connectionless Slave Broadcast feature
****************************************************************************************
*/
void ld_util_stp_pk(uint16_t buf_ptr, uint32_t clk_hs, uint32_t future_csb_inst, struct chnl_map* afh_ch_map, struct bd_addr* mst_bd_addr, uint16_t csb_intv, uint8_t csb_lt_addr, uint8_t svc_data);
/// @} LD
#endif // LD_UTIL_H_
+552
View File
@@ -0,0 +1,552 @@
/**
****************************************************************************************
*
* @file lm.h
*
* @brief Main API file for the Link manager
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef LM_H_
#define LM_H_
/**
****************************************************************************************
* @defgroup LM Link Manager
* @ingroup ROOT
* @brief BT Lower Layers
*
* The CONTROLLER contains the modules allowing the physical link establishment,
* maintenance and management.
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include "rwip.h" // Type definitions
#include "rwip_task.h" // Task definitions
#include "ke_task.h" // kernel task definitions
#include "co_bt.h" // BT standard definitions
#include "ld.h" // link driver definitions
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
/*
* MESSAGES
****************************************************************************************
*/
/// Message API of the LM task
/*@TRACE*/
enum lm_msg_id
{
LM_MSG_ID_FIRST = TASK_FIRST_MSG(TASK_ID_LM),
/*
* ************** Msg LD->LM****************
*/
LM_INQ_RES_IND,
LM_INQ_END_IND,
LM_PAGE_END_IND,
LM_PAGE_SCAN_END_IND,
#if CSB_SUPPORT
LM_PAGE_RESP_TO_IND,
#endif //CSB_SUPPORT
#if RW_BT_MWS_COEX
LM_SAM_CONFIG_REQ,
LM_MWS_PATTERN_IND,
#endif // RW_BT_MWS_COEX
/*
* ************** Msg LM->LM****************
*/
LM_AFH_TO,
LM_ECC_RESULT_IND,
};
/*
* ************** API LD->LM ****************
*/
/// Inquiry result indication structure
/*@TRACE*/
struct lm_inq_res_ind
{
/// BdAddr
struct bd_addr bd_addr;
/// Page Scan Repetition Mode
uint8_t page_scan_rep_mode;
/// Class of device
struct devclass class_of_dev;
/// Clock Offset | Bit 15 Reserved | Bits 14-0: Bits 16-2 of CLKNslave-CLK
uint16_t clk_off;
/// RSSi
uint8_t rssi;
/// EIR bit in FHS packet
bool fhs_eir_bit;
/// Extended inquiry response length
uint8_t eir_len;
/// Extended inquiry response data
uint8_t eir_data[__ARRAY_EMPTY];
};
/// Page end indication structure
/*@TRACE*/
struct lm_page_end_ind
{
/// Link identifier
uint8_t link_id;
/// Status (BT error code)
uint8_t status;
};
/// Page scan end indication structure
/*@TRACE*/
struct lm_page_scan_end_ind
{
/// Link identifier
uint8_t link_id;
/// Peer BdAddr
struct bd_addr peer_bd_addr;
// Peer Class of Device
struct devclass class_of_dev;
// Slave timing information
struct ld_slave_timing_info slave_timing_info;
};
#if PCA_SUPPORT
/// LM MWS pattern activation or change indication
/*@TRACE*/
struct lm_mws_pattern_ind
{
/// Active pattern index
uint8_t pattern_index;
/// Time when pattern will be activated
rwip_time_t time;
};
#endif // PCA_SUPPORT
#if RW_BT_MWS_COEX
/// LM SAM configuration request for new connection
/*@TRACE*/
struct lm_sam_config_req
{
/// Link identifier
uint8_t link_id;
/// Submap available
bool submap_av;
/// Patterns available
bool pattern_av[SAM_INDEX_MAX];
};
#endif //RW_BT_MWS_COEX
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/**
****************************************************************************************
* @brief Initialization of the BT LM task
*
* This function initializes the the LM task, as well as the environment of the LM
*
* @param[in] reset True: reset | False: init
****************************************************************************************
*/
void lm_init(bool reset);
/**
****************************************************************************************
* @brief This function is used to allocate an LT address
*
* @return 0x00: No LT address found | 0x01-0x07: Allocated LT address
****************************************************************************************
*/
uint8_t lm_lt_addr_alloc(void);
/**
****************************************************************************************
* @brief This function is used to reserve an LT address
*
* @param[in] lt_addr LT address
****************************************************************************************
*/
bool lm_lt_addr_reserve(uint8_t lt_addr);
/**
****************************************************************************************
* @brief This function is used to free a LT address
*
* @param[in] lt_addr LT address
****************************************************************************************
*/
void lm_lt_addr_free(uint8_t lt_addr);
/**
****************************************************************************************
* @brief Returns the number of slave and/or master link(s).
*
* @param[in] AclFlag Flag to tell if we need to return the number
* of master and/or slave links.
*
* @return Nb of slave and/or master link(s).
*
****************************************************************************************
*/
uint8_t lm_get_nb_acl(uint8_t acl_flag);
/**
****************************************************************************************
* @brief This function indicates a Role Switch starts.
*
* @param[in] link_id Link Identifier
* @param[out] lt_addr LT Address allocated for new Slave (Slave->Master switch only)
*
* @return True if role switch is allowed, False otherwise
****************************************************************************************
*/
bool lm_role_switch_start(uint8_t link_id, uint8_t* lt_addr);
/**
****************************************************************************************
* @brief This function indicates a Role Switch is finished.
*
* @param[in] link_id Link Identifier
* @param[in] success Status of Role Switch
****************************************************************************************
*/
void lm_role_switch_finished(uint8_t link_id, bool success);
/**
****************************************************************************************
* @brief Return device internal supported features.
*
* @param[in] page_nb Page feature
* @param[out] page_nb_max Maximum page number
* @param[out] feats Feature structure
****************************************************************************************
*/
void lm_read_features(uint8_t page_nb, uint8_t *page_nb_max, struct features *feats);
/**
****************************************************************************************
* @brief This function handles ACL link disconnection.
*
* @param[in] link_id Link Identifier
*
****************************************************************************************
*/
void lm_acl_disc(uint8_t link_id);
/**
****************************************************************************************
* @brief This function indicates if authentication is enabled or not
*
* @return True if authentication is enabled, False otherwise
****************************************************************************************
*/
bool lm_get_auth_en(void);
/**
****************************************************************************************
* @brief This function indicates if simple pairing is enabled or not
*
* @return True if simple pairing is enabled, False otherwise
****************************************************************************************
*/
bool lm_get_sp_en(void);
/**
****************************************************************************************
* @brief This function indicates if Host supports secure connections
*
* @return True if secure connections is supported by Host, False otherwise
****************************************************************************************
*/
bool lm_get_sec_con_host_supp(void);
/**
****************************************************************************************
* @brief This function is used to Get the PIN Type.
*
* @return PINType
****************************************************************************************
*/
uint8_t LM_GetPINType(void);
/**
****************************************************************************************
* @brief This function is used to Get Connection Accept Timeout.
*
* @return Connection accept timeout
*
****************************************************************************************
*/
uint16_t LM_GetConnectionAcceptTimeout(void);
/**
****************************************************************************************
* @brief This function is used to extract a segment of the local name.
*
* @param[out] NameSeg Name segment
* @param[in] NameOffset Offset of the name
* @param[out] NameLen Length of the name
*
****************************************************************************************
*/
void LM_GetLocalNameSeg(struct name_vect *NameSeg, uint8_t NameOffset, uint8_t* NameLen);
/**
****************************************************************************************
* @brief This function is used to get the loopback mode.
*
* @return loop back mode
****************************************************************************************
*/
uint8_t lm_get_loopback_mode(void);
/**
****************************************************************************************
* @brief This function returns the public key
* @param[out] PublicKey Pointer on the public key data
****************************************************************************************
*/
void lm_get_pub_key_192(uint8_t* PublicKey);
/**
****************************************************************************************
* @brief This function returns the private key
* @param[out] PrivateKey Pointer on the private key data
****************************************************************************************
*/
void lm_get_priv_key_192(uint8_t* PrivateKey);
/**
****************************************************************************************
* @brief This function returns the public key
* @param[out] PublicKey Pointer on the public key data
****************************************************************************************
*/
void lm_get_pub_key_256(uint8_t* PublicKey);
/**
****************************************************************************************
* @brief This function returns the private key
* @param[out] PrivateKey Pointer on the private key data
****************************************************************************************
*/
void lm_get_priv_key_256(uint8_t* PrivateKey);
/**
****************************************************************************************
* @brief This function gets the local OOB data
*
* @param[in] R Randomizer value
* @param[out] C Hash value
****************************************************************************************
*/
void lm_get_oob_local_data_192(struct randomizer* R, struct hash* C);
/**
****************************************************************************************
* @brief This function gets the local OOB data
*
* @param[in] R Randomizer value
* @param[out] C Hash value
****************************************************************************************
*/
void lm_get_oob_local_data_256(struct randomizer* R, struct hash* C);
/**
****************************************************************************************
* @brief This function is used to Get the commitment for OOB algorithm.
*
* @param[out] A Output parameter (randomizer) where commitment will be copied
* @param[in] IOCAP IO capability
****************************************************************************************
*/
void lm_get_oob_local_commit(struct randomizer* A, struct io_capability IOCAP);
/**
****************************************************************************************
* @brief This function is used to read the simple pairing debug mode.
*
* @return Simple pairing debug mode
****************************************************************************************
*/
uint8_t lm_sp_debug_mode_get(void);
/**
****************************************************************************************
* @brief This function is used to check if a key is a debug one.
*
* @return True if key is equal to the debug key / False otherwise
****************************************************************************************
*/
bool lm_debug_key_compare_192(uint8_t* X, uint8_t* Y);
/**
****************************************************************************************
* @brief This function is used to check if a key is a debug one.
*
* @return True if key is equal to the debug key / False otherwise
****************************************************************************************
*/
bool lm_debug_key_compare_256(uint8_t* pub_key);
/**
****************************************************************************************
* @brief This function is used to check if device under test mode is enabled
*
* @return True if device under test mode is enabled
****************************************************************************************
*/
bool lm_dut_mode_en_get(void);
/**
****************************************************************************************
* @brief This function is used to check if channel assessment is enabled
*
* @return True if channel assessment is enabled
****************************************************************************************
*/
bool lm_afh_ch_ass_en_get(void);
/**
****************************************************************************************
* @brief This function is used to check if synchronous flow control is enabled
*
* @return True if synchronous flow control is enabled
****************************************************************************************
*/
bool lm_sync_flow_ctrl_en_get(void);
/**
****************************************************************************************
* @brief This function is used to get the Host channel classification
*
* @return Pointer to Host channel classification
****************************************************************************************
*/
struct chnl_map* lm_afh_host_ch_class_get(void);
/**
****************************************************************************************
* @brief This function is used to set the channel classification from a peer device
*
* @param[in] link_id Link Identifier
* @param[in] ch_class Peer's channel classification
****************************************************************************************
*/
void lm_afh_peer_ch_class_set(uint8_t link_id, struct chnl_map* ch_class);
/**
****************************************************************************************
* @brief This function is used to get the master channel map
*
* @return Pointer to master channel map
****************************************************************************************
*/
struct chnl_map* lm_afh_master_ch_map_get(void);
/**
****************************************************************************************
* @brief Activates the AFH timer if not already active
*
****************************************************************************************
*/
void lm_afh_activate_timer(void);
/**
****************************************************************************************
* @brief This function is used to check if a link_id is in connected state
*
****************************************************************************************
*/
bool lm_is_acl_con(uint8_t link_id);
/**
****************************************************************************************
* @brief This function is used to check if a link_id is in connected state & role
*
****************************************************************************************
*/
bool lm_is_acl_con_role(uint8_t link_id, uint8_t role);
/**
****************************************************************************************
* @brief This function is used to get the local page scan repetition mode
*
* @return Page scan repetition mode
****************************************************************************************
*/
uint8_t lm_page_scan_rep_mode_get(void);
#if RW_BT_MWS_COEX
/**
****************************************************************************************
* @brief This function is used to return whether PCA external Frame is configured.
*
****************************************************************************************
*/
bool lm_local_ext_fr_configured(void);
#endif //RW_BT_MWS_COEX
/**
****************************************************************************************
* @brief This function returns the number of Rx slots in the SAM submap to period T.
*
****************************************************************************************
*/
uint8_t lm_sam_submap_rx_slots_get(uint8_t t_sam_sm);
/**
****************************************************************************************
* @brief This function returns the number of Tx slots in the SAM submap to period T.
*
****************************************************************************************
*/
uint8_t lm_sam_submap_tx_slots_get(uint8_t t_sam_sm);
/**
****************************************************************************************
* @brief This function returns the locally configured SAM submap0
*
****************************************************************************************
*/
uint8_t* lm_sam_submap0_get(void);
/**
****************************************************************************************
* @brief This function returns the locally configured SAM pattern of specified index
*
****************************************************************************************
*/
uint8_t* lm_sam_pattern_get(uint8_t pattern_idx);
#if (MAX_NB_SYNC > 0)
/**
****************************************************************************************
* @brief This function is used to check if an (e)SCO link can be moved autonomously by the controller
*
****************************************************************************************
*/
bool lm_sco_move_en(void);
#endif //(MAX_NB_SYNC > 0)
/// @} LM
#endif // LM_H_
+552
View File
@@ -0,0 +1,552 @@
/**
****************************************************************************************
*
* @file lm.h
*
* @brief Link manager internal definition
*
* Copyright (C) RivieraWaves 2009-2015
*
****************************************************************************************
*/
#ifndef LM_INT_H_
#define LM_INT_H_
/**
****************************************************************************************
* @addtogroup LM Link Manager
* @{
****************************************************************************************
*/
/*
* INCLUDE FILES
****************************************************************************************
*/
#include <stdint.h> // standard integer
#include <stdbool.h> // standard boolean
/*
* DEFINES
****************************************************************************************
*/
/// Maximum number of instances of the LM task
#define LM_IDX_MAX 1
/*
* ENUMERATIONS
****************************************************************************************
*/
/// States of a link
enum LM_LINK_STATE
{
LM_FREE,
LM_PAGE,
LM_PAGE_STOPPING,
LM_PAGE_SCAN,
LM_PAGE_SCAN_STOPPING,
LM_CONNECTED,
LM_SWITCH,
};
/// Possible states of the LM task
enum LM_STATE
{
LM_IDLE,
};
/// Inquiry states
enum LM_INQ_STATE
{
LM_INQ_OFF,
LM_INQ_NORMAL,
LM_INQ_PERIODIC,
};
/*
* TYPE DEFINITIONS
****************************************************************************************
*/
/// Structure for HCI configuration parameters (non-connection oriented)
struct lm_hci_cfg_params
{
/**
* Scan Enable
*
* 0x00 No Scans enabled.
* 0x01 Inquiry Scan enabled. Page Scan always disabled.
* 0x02 Inquiry Scan disabled. Page Scan enabled.
* 0x03 Inquiry Scan enabled. Page Scan enabled.
* 0x04-0xFF Reserved [0x04 limited page scan removed]
*/
uint8_t scan_en;
/**
* Inquiry Scan Interval
*
* Size: 2 Octets
* Range: 0x0012 to 0x1000; only even values are valid
* Default: 0x1000
* Mandatory Range: 0x0012 to 0x1000
* Time = N * 0.625 msec
* Time Range: 11.25 to 2560 msec
* Time Default: 2.56 sec
*/
uint16_t inq_scan_intv;
/**
* Inquiry Scan Window
*
* Size: 2 Octets
* Range: 0x0011 to 0x1000
* Default: 0x0012
* Mandatory Range: 0x0011 to Inquiry Scan Interval
* Time = N * 0.625 msec
* Time Range: 10.625 msec to 2560 msec
* Time Default: 11.25 msec
*/
uint16_t inq_scan_win;
/**
* Inquiry Scan Type
*
* 0x00 Mandatory: Standard Scan (default)
* 0x01 Optional: Interlaced Scan
* 0x02-0xFF Reserved
*/
uint8_t inq_scan_type;
/**
* Inquiry Mode
*
* 0x00 Standard Inquiry Result event format
* 0x01 Inquiry Result format with RSSI
* 0x02 Inquiry Result with RSSI format or Extended Inquiry Result format
* 0x03-0xFF Reserved
*/
uint8_t inq_mode;
/**
* Page Timeout
*
* Size: 2 Octets
* Range: 0x0001 to 0xFFFF
* Default: 0x2000
* Mandatory Range: 0x0016 to 0xFFFF
* Time = N * 0.625 msec
* Time Range: 0.625 msec to 40.9 sec
* Time Default: 5.12 sec
*/
uint16_t page_to;
/**
* Connection Accept Timeout
*
* Size: 2 Octets
* Range: 0x0001 to 0xB540
* Default: 0x1F40
* Mandatory Range: 0x00A0 to 0xB540
* Time = N * 0.625 msec
* Time Range: 0.625 msec to 29 sec
* Time Default: BR/EDR 5 sec
*/
uint16_t con_accept_to;
/**
* Page Scan Interval
*
* Size: 2 Octets
* Range: 0x0012 to 0x1000; only even values are valid
* Default: 0x0800
* Mandatory Range: 0x0012 to 0x1000
* Time = N * 0.625 msec
* Time Range: 11.25 msec to 2560 msec
* Time Default: 1.28 sec
*/
uint16_t page_scan_intv;
/**
* Page Scan Window
*
* Size: 2 Octets
* Range: 0x0011 to 0x1000
* Default: 0x0012
* Mandatory Range: 0x0011 to Page Scan Interval
* Time = N * 0.625 msec
* Time Range: 10.625 msec to Page Scan Interval
* Time Default: 11.25 msec
*/
uint16_t page_scan_win;
/**
* Page scan repetition mode (depends on page scan window and interval)
* 0x00 R0
* 0x01 R1
* 0x02 R2
* 0x03 0xFF Reserved.
*/
uint8_t page_scan_rep_mode;
/**
* Page Scan Type
*
* 0x00 Mandatory: Standard Scan (default)
* 0x01 Optional: Interlaced Scan
* 0x02-0xFF Reserved
*/
uint8_t page_scan_type;
/**
* Voice Setting
*
* 00XXXXXXXX Input Coding: Linear
* 01XXXXXXXX Input Coding: u-law Input Coding
* 10XXXXXXXX Input Coding: A-law Input Coding
* 11XXXXXXXX Reserved for future use
* XX00XXXXXX Input Data Format: 1's complement
* XX01XXXXXX Input Data Format: 2's complement
* XX10XXXXXX Input Data Format: Sign-Magnitude
* XX11XXXXXX Input Data Format: Unsigned
* XXXX0XXXXX Input Sample Size: 8-bit (only for linear PCM)
* XXXX1XXXXX Input Sample Size: 16-bit (only for linear PCM)
* XXXXXnnnXX Linear_PCM_Bit_Pos: # bit positions that MSB of sample is away from starting at MSB (only for Linear PCM).
* XXXXXXXX00 Air Coding Format: CVSD
* XXXXXXXX01 Air Coding Format: u-law
* XXXXXXXX10 Air Coding Format: A-law
* XXXXXXXX11 Air Coding Format: Transparent Data
*/
uint16_t voice_stg;
/**
* Pin Type
*
* 0x00 Variable PIN.
* 0x01 Fixed PIN.
*/
uint8_t pin_type;
/**
* Authentication Enable
*
* 0x00 Authentication not required.
* 0x01 Authentication required for all connections.
*/
uint8_t auth_en;
/**
* Extended Page Timeout
*
* Range: 0x0000 to 0xFFFF Default: 0x0000
* Mandatory Range: 0x0000 to 0xFFFF Time = N * 0.625 msec
* Time Range: 0 to 40.9 sec
* Time Default: 0 sec
*/
uint16_t ext_page_to;
/**
* Extended Inquiry Length
*
* Range: 0x0000 to 0xFFFF Default: 0x0000
* Mandatory Range: 0x0000 to 0xFFFF Time = N * 0.625 msec
* Time Range: 0 to 40.9 sec
* Time Default: 0 sec
*/
uint16_t ext_inq_len;
/**
* Inquiry TX power level
*
* Range: 70 <= N <= 20
* Units: dBm
*/
int8_t inq_tx_pwr_lvl;
/**
* IAC_LAP
*
* LAPs used to create the IAC which is currently in use by the local BR/EDR
* Controller to simultaneously listen for during an Inquiry Scan.
*
* Range: 0x9E8B00-0x9E8B3F
*
* Note: only 1 IAC LAP supported (can scan only 1 simultaneously due to correlator limitations)
*/
struct lap iac_lap;
/**
* Link Policy Settings (Default value used for new connections)
*
* 0x0000 Disable All LM Modes Default
* 0x0001 Enable Role switch.
* 0x0002 Enable Hold Mode.
* 0x0004 Enable Sniff Mode.
* 0x0008 Enable Park State.
* 0x00100x8000 Reserved for future use.
*/
uint16_t link_pol_stg;
/**
* Simple Pairing Mode
*
* 0x00 Simple Pairing not set (default)
* 0x01 Simple pairing enabled
* 0x02 - 0xFF Reserved for future use
*/
uint8_t sp_mode;
/**
* Secure Connections Host Support
* 0x00 Secure_Conections_Host_Support is disabled. Host does not support Secure Connections (default)
* 0x01 Secure_Connections_Host_Support is enabled. Host supports Secure Connections
* 0x02 0xFF Reserved
*/
uint8_t sec_con_host_supp;
/**
* LE SUPPORTED HOST
*
* 0x00 LE Supported (Host) disabled (default)
* 0x01 LE Supported (Host) enabled
* 0x02 0xFF Reserved
*/
uint8_t le_supported_host;
/**
* SIMULTANEOUS LE HOST
*
* 0x00 Simultaneous LE and BR/EDR to Same Device Capable (Host) disabled (default). This value shall be ignored.
* 0x01 0xFF Reserved
*/
uint8_t simultaneous_le_host;
/**
* Loopback mode
*
* 0x00 No Loopback mode enabled (default).
* 0x01 Enable Local Loopback.
* 0x02 Enable Remote Loopback. (Not Supported by AMPs)
* 0x03-0xFF Reserved for future use.
*/
uint8_t loopback_mode;
/**
* Simple pairing debug mode
*
* 0x00 Simple Pairing debug mode disabled (default)
* 0x01 Simple pairing debug mode enabled
* 0x02 - 0xFF Reserved for future use
*/
uint8_t sp_debug_mode;
/**
* Erroneous Data reporting
*
* 0x00 Erroneous Data reporting disabled (default).
* 0x01 Erroneous data reporting enabled.
* 0x02 - 0xFF Reserved.
*/
uint8_t err_data_rep;
/**
* Enable device under test mode
*/
bool dut_mode_en;
/**
* Enable channel assessment
*/
bool ch_ass_en;
/**
* Synchronous flow control enable
*/
bool sync_flow_ctrl_en;
};
/// AFH parameters structure
struct lm_afh_tag
{
/// Channel classification from Host
struct chnl_map host_ch_class;
/// Channel classification from peers
struct chnl_map peer_ch_class[MAX_NB_ACTIVE_ACL];
/// Master channel map (map used for all master links with AFH enabled)
struct chnl_map master_ch_map;
/// AFH state
uint8_t active;
};
struct lm_sam_pattern
{
///Tsam-sm (slots)
uint8_t t_sam_sm;
///Nsam-sm
uint8_t n_sam_sm;
///SAM Submaps
struct sam_submaps submaps;
///Num slots available for tx
uint16_t n_tx_slots;
///Num slots available for rx
uint16_t n_rx_slots;
///Nsam_sm defined by submap
uint8_t n_ex_sm;
};
/// Slot availability map parameters structure
struct lm_sam_info_tag
{
/// type0 submap
uint8_t type0submap[SAM_TYPE0_SUBMAP_LEN];
/// defined patterns
struct lm_sam_pattern pattern[SAM_INDEX_MAX];
/// submap frame length (slots)
uint8_t frame_len;
/// frame offset (us)
int16_t frame_offset;
/// active index
uint8_t active_index;
};
/// Inquiry procedure parameters structure
struct lm_inq_tag
{
/// Flag indicating periodic inquiry mode
bool periodic;
};
/// State for all connections
struct lm_con_info
{
/// Peer BD Address
struct bd_addr bd_addr;
/// State
uint8_t state;
/// Role (0x00: MASTER / 0x01: SLAVE)
uint8_t role;
/// LT Address (Valid only for master ACL links)
uint8_t lt_addr;
};
/// Inquiry duplicate filtering information structure
struct inq_dup_filt_info
{
/// Inquiry result filtering list
struct bd_addr dev[INQ_FILT_LEN];
/// Current position in the table for placing the next BD address
uint8_t curr_pos;
};
/// LM environment structure
struct lm_env_tag
{
/// Pointer to HCI_Create_Con_Cmd associated to the ongoing Page procedure
const struct hci_create_con_cmd* create_con_cmd;
/// Pointer to HCI_Remote_Name_Req associated to the ongoing Page procedure
const struct hci_rem_name_req_cmd* rem_name_req_cmd;
/// Pointer to HCI_Trunc_Page_Cmd associated to the ongoing Page procedure
const struct hci_trunc_page_cmd* trunc_page_cmd;
/// HCI configuration parameters (non-connection oriented)
struct lm_hci_cfg_params hci;
/// State for all connections
struct lm_con_info con_info[MAX_NB_ACTIVE_ACL];
/// LT Address bitmap
uint8_t lt_addr_bitmap;
/// Local name
char* local_name;
/// Inquiry state (Off, Normal, Periodic)
uint8_t inq_state;
/// Private key 192
uint32_t priv_key_192[PRIV_KEY_192_LEN/4];
/// Public key 192
uint32_t pub_key_192[PUB_KEY_192_LEN/4];
/// Private key 256
uint8_t priv_key_256[PRIV_KEY_256_LEN];
/// Public key 256
uint8_t pub_key_256[PUB_KEY_256_LEN];
/// OOB data r
struct randomizer oob_r;
/// OOB data c
struct hash oob_c;
/// AFH parameters
struct lm_afh_tag afh;
#if RW_BT_MWS_COEX
/// MWS External frame configuration set
bool local_ext_fr_config;
#endif //RW_BT_MWS_COEX
/// SAM parameters (local)
struct lm_sam_info_tag sam_info;
/// Inquiry result filtering list
struct inq_dup_filt_info inq_filt;
#if (MAX_NB_SYNC > 0)
/// SCO move enable
bool sco_move_en;
#endif //(MAX_NB_SYNC > 0)
/// Enable channel assessment usage when building channel maps
bool ch_ass_en;
};
/*
* GLOBAL VARIABLE DECLARATIONS
*****************************************************************************************
*/
/// LM task descriptor
extern const struct ke_task_desc TASK_DESC_LM;
/// LM task message handlers table
extern const struct ke_state_handler lm_default_handler;
/// LM task state
extern ke_state_t lm_state[LM_IDX_MAX];
/// LM environment variable
extern struct lm_env_tag lm_env;
/// LM local supported features
extern uint8_t const lm_local_supp_feats[FEATURE_PAGE_MAX][FEATS_LEN];
/*
* FUNCTION DECLARATIONS
****************************************************************************************
*/
/// @} LM
#endif // LM_INT_H_