initial commit
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// amdtp_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMDTP client.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AMDTP_API_H
|
||||
#define AMDTP_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpcStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpcStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpcHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpcHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpcHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpcHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
void AmdtpcScanStart(void);
|
||||
void AmdtpcScanStop(void);
|
||||
void AmdtpcConnOpen(uint8_t idx);
|
||||
void AmdtpcSendTestData(void);
|
||||
void AmdtpcSendTestDataStop(void);
|
||||
void AmdtpcRequestServerSend(void);
|
||||
void AmdtpcRequestServerSendStop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* AMDTP_API_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,113 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// amdtp_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMDTP service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AMDTP_API_H
|
||||
#define AMDTP_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef AMDTP_CONN_MAX
|
||||
#define AMDTP_CONN_MAX 1
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* AMDTP_API_H */
|
||||
@@ -0,0 +1,845 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// amdtp_main.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMDTP service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "smp_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_dis.h"
|
||||
#include "amdtp_api.h"
|
||||
#include "amdtps_api.h"
|
||||
#include "svc_amdtp.h"
|
||||
|
||||
#include "am_util.h"
|
||||
#include "gatt_api.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
#define MEASURE_THROUGHPUT
|
||||
|
||||
/*! WSF message event starting value */
|
||||
#define AMDTP_MSG_START 0xA0
|
||||
|
||||
/*! WSF message event enumeration */
|
||||
enum
|
||||
{
|
||||
AMDTP_TIMER_IND = AMDTP_MSG_START, /*! AMDTP tx timeout timer expired */
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
AMDTP_MEAS_TP_TIMER_IND,
|
||||
#endif
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Data Types
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Application message type */
|
||||
typedef union
|
||||
{
|
||||
wsfMsgHdr_t hdr;
|
||||
dmEvt_t dm;
|
||||
attsCccEvt_t ccc;
|
||||
attEvt_t att;
|
||||
} amdtpMsg_t;
|
||||
|
||||
static void amdtpClose(amdtpMsg_t *pMsg);
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t amdtpAdvCfg =
|
||||
{
|
||||
{60000, 0, 0}, /*! Advertising durations in ms */
|
||||
{ 800, 800, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t amdtpSlaveCfg =
|
||||
{
|
||||
AMDTP_CONN_MAX, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t amdtpSecCfg =
|
||||
{
|
||||
DM_AUTH_BOND_FLAG | DM_AUTH_SC_FLAG, /*! Authentication and bonding flags */
|
||||
0, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
FALSE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
/*! configurable parameters for AMDTP connection parameter update */
|
||||
static const appUpdateCfg_t amdtpUpdateCfg =
|
||||
{
|
||||
3000, /*! Connection idle period in ms before attempting
|
||||
connection parameter update; set to zero to disable */
|
||||
/* W/A: Apollo2-Blue has issues with interval 7.5ms */
|
||||
#if defined(AM_PART_APOLLO3) || defined(AM_PART_APOLLO3P)
|
||||
6, /*! 7.5ms */
|
||||
15, /*! 18.75ms */
|
||||
#else
|
||||
8,
|
||||
18,
|
||||
#endif
|
||||
0, /*! Connection latency */
|
||||
600, /*! Supervision timeout in 10ms units */
|
||||
5 /*! Number of update attempts before giving up */
|
||||
};
|
||||
|
||||
/*! SMP security parameter configuration */
|
||||
static const smpCfg_t amdtpSmpCfg =
|
||||
{
|
||||
3000, /*! 'Repeated attempts' timeout in msec */
|
||||
SMP_IO_NO_IN_NO_OUT, /*! I/O Capability */
|
||||
7, /*! Minimum encryption key length */
|
||||
16, /*! Maximum encryption key length */
|
||||
3, /*! Attempts to trigger 'repeated attempts' timeout */
|
||||
0, /*! Device authentication requirements */
|
||||
};
|
||||
|
||||
/*! AMDTPS configuration */
|
||||
static const AmdtpsCfg_t amdtpAmdtpsCfg =
|
||||
{
|
||||
0
|
||||
};
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! advertising data, discoverable mode */
|
||||
static const uint8_t amdtpAdvDataDisc[] =
|
||||
{
|
||||
/*! flags */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_FLAGS, /*! AD type */
|
||||
DM_FLAG_LE_GENERAL_DISC | /*! flags */
|
||||
DM_FLAG_LE_BREDR_NOT_SUP,
|
||||
|
||||
/*! tx power */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_TX_POWER, /*! AD type */
|
||||
0, /*! tx power */
|
||||
|
||||
/*! service UUID list */
|
||||
3, /*! length */
|
||||
DM_ADV_TYPE_16_UUID, /*! AD type */
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE),
|
||||
|
||||
17, /*! length */
|
||||
DM_ADV_TYPE_128_UUID, /*! AD type */
|
||||
ATT_UUID_AMDTP_SERVICE
|
||||
};
|
||||
|
||||
/*! scan data, discoverable mode */
|
||||
static const uint8_t amdtpScanDataDisc[] =
|
||||
{
|
||||
/*! device name */
|
||||
6, /*! length */
|
||||
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
|
||||
'A',
|
||||
'm',
|
||||
'd',
|
||||
't',
|
||||
'p'
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
AMDTP_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
AMDTP_AMDTPS_TX_CCC_IDX, /*! AMDTP service, tx characteristic */
|
||||
AMDTP_AMDTPS_RX_ACK_CCC_IDX, /*! AMDTP service, rx ack characteristic */
|
||||
AMDTP_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t amdtpCccSet[AMDTP_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* AMDTP_GATT_SC_CCC_IDX */
|
||||
{AMDTPS_TX_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* AMDTP_AMDTPS_TX_CCC_IDX */
|
||||
{AMDTPS_ACK_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE} /* AMDTP_AMDTPS_RX_ACK_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF handler ID */
|
||||
wsfHandlerId_t amdtpHandlerId;
|
||||
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
wsfTimer_t measTpTimer;
|
||||
int gTotalDataBytesRecev = 0;
|
||||
#endif
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpDmCback
|
||||
*
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
uint16_t len;
|
||||
|
||||
len = DmSizeOfEvt(pDmEvt);
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(len)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, len);
|
||||
WsfMsgSend(amdtpHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpAttCback
|
||||
*
|
||||
* \brief Application ATT callback.
|
||||
*
|
||||
* \param pEvt ATT callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpAttCback(attEvt_t *pEvt)
|
||||
{
|
||||
attEvt_t *pMsg;
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attEvt_t) + pEvt->valueLen)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attEvt_t));
|
||||
pMsg->pValue = (uint8_t *) (pMsg + 1);
|
||||
memcpy(pMsg->pValue, pEvt->pValue, pEvt->valueLen);
|
||||
WsfMsgSend(amdtpHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpCccCback
|
||||
*
|
||||
* \brief Application ATTS client characteristic configuration callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpCccCback(attsCccEvt_t *pEvt)
|
||||
{
|
||||
attsCccEvt_t *pMsg;
|
||||
appDbHdl_t dbHdl;
|
||||
|
||||
/* if CCC not set from initialization and there's a device record */
|
||||
if ((pEvt->handle != ATT_HANDLE_NONE) &&
|
||||
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE))
|
||||
{
|
||||
/* store value in device database */
|
||||
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
|
||||
}
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attsCccEvt_t));
|
||||
WsfMsgSend(amdtpHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
static bool sendDataContinuously = false;
|
||||
static uint32_t counter = 0;
|
||||
|
||||
static void AmdtpsSendTestData(void)
|
||||
{
|
||||
uint8_t data[1024] = {0};
|
||||
eAmdtpStatus_t status;
|
||||
|
||||
sendDataContinuously = true;
|
||||
*((uint32_t*)&(data[0])) = counter;
|
||||
|
||||
// status = AmdtpsSendPacket(AMDTP_PKT_TYPE_DATA, false, true, data, sizeof(data));
|
||||
status = AmdtpsSendPacket(AMDTP_PKT_TYPE_DATA, false, false, data, AttGetMtu(1) - 11); //fixme
|
||||
if (status != AMDTP_STATUS_SUCCESS)
|
||||
{
|
||||
APP_TRACE_INFO1("AmdtpsSendTestData() failed, status = %d\n", status);
|
||||
}
|
||||
else
|
||||
{
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpProcCccState
|
||||
*
|
||||
* \brief Process CCC state change.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
bool bPairingCompleted = false;
|
||||
static void amdtpProcCccState(amdtpMsg_t *pMsg)
|
||||
{
|
||||
APP_TRACE_INFO3("ccc state ind value:%d handle:%d idx:%d", pMsg->ccc.value, pMsg->ccc.handle, pMsg->ccc.idx);
|
||||
|
||||
/* AMDTPS TX CCC */
|
||||
if (pMsg->ccc.idx == AMDTP_AMDTPS_TX_CCC_IDX)
|
||||
{
|
||||
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
|
||||
{
|
||||
// notify enabled
|
||||
amdtps_start((dmConnId_t)pMsg->ccc.hdr.param, AMDTP_TIMER_IND, AMDTP_AMDTPS_TX_CCC_IDX);
|
||||
// AppSlaveSecurityeq(1);
|
||||
// if(bPairingCompleted == true)
|
||||
{
|
||||
#if defined(AMDTPS_TXTEST)
|
||||
counter = 0;
|
||||
AmdtpsSendTestData(); //fixme
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// notify disabled
|
||||
amdtpClose(pMsg);
|
||||
amdtps_stop((dmConnId_t)pMsg->ccc.hdr.param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpClose
|
||||
*
|
||||
* \brief Perform UI actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpClose(amdtpMsg_t *pMsg)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpSetup
|
||||
*
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpSetup(amdtpMsg_t *pMsg)
|
||||
{
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(amdtpAdvDataDisc), (uint8_t *) amdtpAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(amdtpScanDataDisc), (uint8_t *) amdtpScanDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, sizeof(amdtpAdvDataDisc), (uint8_t *) amdtpAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, sizeof(amdtpScanDataDisc), (uint8_t *) amdtpScanDataDisc);
|
||||
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpBtnCback
|
||||
*
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpBtnCback(uint8_t btn)
|
||||
{
|
||||
dmConnId_t connId;
|
||||
|
||||
/* button actions when connected */
|
||||
if ((connId = AppConnIsOpen()) != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_MED:
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_LONG:
|
||||
AppConnClose(connId);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* button actions when not connected */
|
||||
else
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* start or restart advertising */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_MED:
|
||||
/* enter discoverable and bondable mode mode */
|
||||
AppSetBondable(TRUE);
|
||||
AppAdvStart(APP_MODE_DISCOVERABLE);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_LONG:
|
||||
/* clear bonded device info and restart advertising */
|
||||
AppDbDeleteAllRecords();
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
static void showThroughput(void)
|
||||
{
|
||||
APP_TRACE_INFO1("throughput : %d Bytes/s\n", gTotalDataBytesRecev);
|
||||
gTotalDataBytesRecev = 0;
|
||||
WsfTimerStartSec(&measTpTimer, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amdtpProcMsg
|
||||
*
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amdtpProcMsg(amdtpMsg_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
switch(pMsg->hdr.event)
|
||||
{
|
||||
case AMDTP_TIMER_IND:
|
||||
amdtps_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
case AMDTP_MEAS_TP_TIMER_IND:
|
||||
showThroughput();
|
||||
break;
|
||||
#endif
|
||||
|
||||
case ATTS_HANDLE_VALUE_CNF:
|
||||
//APP_TRACE_INFO1("ATTS_HANDLE_VALUE_CNF, status = %d", pMsg->att.hdr.status);
|
||||
|
||||
amdtps_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
case ATTS_CCC_STATE_IND:
|
||||
amdtpProcCccState(pMsg);
|
||||
break;
|
||||
|
||||
case ATT_MTU_UPDATE_IND:
|
||||
APP_TRACE_INFO1("Negotiated MTU %d", ((attEvt_t *)pMsg)->mtu);
|
||||
break;
|
||||
|
||||
case DM_CONN_DATA_LEN_CHANGE_IND:
|
||||
APP_TRACE_INFO2("DM_CONN_DATA_LEN_CHANGE_IND, Tx=%d, Rx=%d", ((hciLeDataLenChangeEvt_t*)pMsg)->maxTxOctets, ((hciLeDataLenChangeEvt_t*)pMsg)->maxRxOctets);
|
||||
//AttcMtuReq((dmConnId_t)(pMsg->hdr.param), 480);//ATT_MAX_MTU);//83); //fixme
|
||||
break;
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
DmSecGenerateEccKeyReq();
|
||||
amdtpSetup(pMsg);
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
case DM_CONN_OPEN_IND:
|
||||
amdtps_proc_msg(&pMsg->hdr);
|
||||
// AttcMtuReq((dmConnId_t)(pMsg->hdr.param), ATT_MAX_MTU);//83); //fixme
|
||||
|
||||
// hciConnSpec_t connSpec;
|
||||
// connSpec.connIntervalMin = (7.5/1.25);
|
||||
// connSpec.connIntervalMax = (15/1.25);
|
||||
// connSpec.connLatency = 0;
|
||||
// connSpec.supTimeout = 200;
|
||||
// connSpec.minCeLen = 4;//0;
|
||||
// connSpec.maxCeLen = 8;//0xffff; //fixme
|
||||
// DmConnUpdate(1, &connSpec);
|
||||
|
||||
// PDU length, TX interval (0x148 ~ 0x848)
|
||||
//DmConnSetDataLen(1, 27, 0x148);
|
||||
DmConnSetDataLen(1, 251, 0x848);
|
||||
|
||||
// AppSlaveSecurityReq(1);
|
||||
uiEvent = APP_UI_CONN_OPEN;
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
amdtpClose(pMsg);
|
||||
amdtps_proc_msg(&pMsg->hdr);
|
||||
|
||||
APP_TRACE_INFO1("DM_CONN_CLOSE_IND, reason = 0x%x", pMsg->dm.connClose.reason);
|
||||
|
||||
uiEvent = APP_UI_CONN_CLOSE;
|
||||
break;
|
||||
|
||||
case DM_CONN_UPDATE_IND:
|
||||
amdtps_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_CMPL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
|
||||
uiEvent = APP_UI_SEC_PAIR_CMPL;
|
||||
|
||||
bPairingCompleted = true;
|
||||
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_FAIL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
|
||||
APP_TRACE_INFO1("DM_SEC_PAIR_FAIL_IND, status = 0x%x", pMsg->dm.pairCmpl.hdr.status);
|
||||
bPairingCompleted = false;
|
||||
|
||||
uiEvent = APP_UI_SEC_PAIR_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_AUTH_REQ_IND:
|
||||
AppHandlePasskey(&pMsg->dm.authReq);
|
||||
break;
|
||||
|
||||
case DM_SEC_ECC_KEY_IND:
|
||||
DmSecSetEccKey(&pMsg->dm.eccMsg.data.key);
|
||||
break;
|
||||
|
||||
case DM_SEC_COMPARE_IND:
|
||||
AppHandleNumericComparison(&pMsg->dm.cnfInd);
|
||||
break;
|
||||
|
||||
case DM_HW_ERROR_IND:
|
||||
uiEvent = APP_UI_HW_ERROR;
|
||||
break;
|
||||
case DM_VENDOR_SPEC_CMD_CMPL_IND:
|
||||
{
|
||||
#if defined(AM_PART_APOLLO) || defined(AM_PART_APOLLO2)
|
||||
|
||||
uint8_t *param_ptr = &pMsg->dm.vendorSpecCmdCmpl.param[0];
|
||||
|
||||
switch (pMsg->dm.vendorSpecCmdCmpl.opcode)
|
||||
{
|
||||
case 0xFC20: //read at address
|
||||
{
|
||||
uint32_t read_value;
|
||||
|
||||
BSTREAM_TO_UINT32(read_value, param_ptr);
|
||||
|
||||
APP_TRACE_INFO3("VSC 0x%0x complete status %x param %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status,
|
||||
read_value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
APP_TRACE_INFO2("VSC 0x%0x complete status %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
//
|
||||
//static void AmdtpsSendTestData(void)
|
||||
//{
|
||||
// static uint8_t counter = 0;
|
||||
// uint8_t data[236] = {0};
|
||||
// eAmdtpStatus_t status;
|
||||
//
|
||||
// sendDataContinuously = true;
|
||||
// data[1] = counter;
|
||||
// status = AmdtpsSendPacket(AMDTP_PKT_TYPE_DATA, false, true, data, sizeof(data));
|
||||
// if (status != AMDTP_STATUS_SUCCESS)
|
||||
// {
|
||||
// APP_TRACE_INFO1("AmdtpsSendTestData() failed, status = %d\n", status);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// counter++;
|
||||
// }
|
||||
//}
|
||||
|
||||
void amdtpDtpRecvCback(uint8_t * buf, uint16_t len)
|
||||
{
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
static bool measTpStarted = false;
|
||||
#endif
|
||||
#if 0
|
||||
// reception callback
|
||||
// print the received data
|
||||
APP_TRACE_INFO0("-----------AMDTP Received data--------------\n");
|
||||
APP_TRACE_INFO3("len = %d, buf[0] = %d, buf[1] = %d\n", len, buf[0], buf[1]);
|
||||
#endif
|
||||
if (buf[0] == 1)
|
||||
{
|
||||
APP_TRACE_INFO0("send test data\n");
|
||||
AmdtpsSendTestData();
|
||||
}
|
||||
else if (buf[0] == 2)
|
||||
{
|
||||
APP_TRACE_INFO0("send test data stop\n");
|
||||
sendDataContinuously = false;
|
||||
}
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
gTotalDataBytesRecev += len;
|
||||
if (!measTpStarted)
|
||||
{
|
||||
measTpStarted = true;
|
||||
WsfTimerStartSec(&measTpTimer, 1);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void amdtpDtpTransCback(eAmdtpStatus_t status)
|
||||
{
|
||||
// APP_TRACE_INFO1("amdtpDtpTransCback status = %d\n", status);
|
||||
if (status == AMDTP_STATUS_SUCCESS && sendDataContinuously)
|
||||
{
|
||||
AmdtpsSendTestData();
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("AmdtpHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
amdtpHandlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppAdvCfg = (appAdvCfg_t *) &amdtpAdvCfg;
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &amdtpSlaveCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &amdtpSecCfg;
|
||||
pAppUpdateCfg = (appUpdateCfg_t *) &amdtpUpdateCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
AppServerInit();
|
||||
/* Set stack configuration pointers */
|
||||
pSmpCfg = (smpCfg_t *) &amdtpSmpCfg;
|
||||
|
||||
/* initialize amdtp service server */
|
||||
amdtps_init(handlerId, (AmdtpsCfg_t *) &amdtpAmdtpsCfg, amdtpDtpRecvCback, amdtpDtpTransCback);
|
||||
|
||||
#ifdef MEASURE_THROUGHPUT
|
||||
measTpTimer.handlerId = handlerId;
|
||||
measTpTimer.msg.event = AMDTP_MEAS_TP_TIMER_IND;
|
||||
#endif
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpHandler
|
||||
*
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
// APP_TRACE_INFO1("Amdtp got evt %d", pMsg->event);
|
||||
|
||||
/* process ATT messages */
|
||||
if (pMsg->event >= ATT_CBACK_START && pMsg->event <= ATT_CBACK_END)
|
||||
{
|
||||
/* process server-related ATT messages */
|
||||
AppServerProcAttMsg(pMsg);
|
||||
}
|
||||
/* process DM messages */
|
||||
else if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
amdtpProcMsg((amdtpMsg_t *) pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmdtpStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmdtpStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(amdtpDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, amdtpDmCback);
|
||||
AttRegister(amdtpAttCback);
|
||||
AttConnRegister(AppServerConnCback);
|
||||
AttsCccRegister(AMDTP_NUM_CCC_IDX, (attsCccSet_t *) amdtpCccSet, amdtpCccCback);
|
||||
|
||||
/* Register for app framework callbacks */
|
||||
AppUiBtnRegister(amdtpBtnCback);
|
||||
|
||||
/* Initialize attribute server database */
|
||||
SvcCoreGattCbackRegister(GattReadCback, GattWriteCback);
|
||||
SvcCoreAddGroup();
|
||||
SvcDisAddGroup();
|
||||
SvcAmdtpsCbackRegister(NULL, amdtps_write_cback);
|
||||
SvcAmdtpsAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(AMDTP_GATT_SC_CCC_IDX);
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// amota_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMOTA service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef AMOTA_API_H
|
||||
#define AMOTA_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef AMOTA_CONN_MAX
|
||||
#define AMOTA_CONN_MAX 1
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* AMOTA_API_H */
|
||||
@@ -0,0 +1,693 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// amota_main.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMOTA service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_dis.h"
|
||||
#include "amota_api.h"
|
||||
#include "amotas_api.h"
|
||||
#include "svc_amotas.h"
|
||||
#include "gatt_api.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF message event starting value */
|
||||
#define AMOTA_MSG_START 0xA0
|
||||
|
||||
/*! WSF message event enumeration */
|
||||
enum
|
||||
{
|
||||
AMOTA_RESET_TIMER_IND = AMOTA_MSG_START, /*! AMOTA reset timer expired */
|
||||
AMOTA_DISCONNECT_TIMER_IND, /*! AMOTA disconnect timer expired */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Data Types
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Application message type */
|
||||
typedef union
|
||||
{
|
||||
wsfMsgHdr_t hdr;
|
||||
dmEvt_t dm;
|
||||
attsCccEvt_t ccc;
|
||||
attEvt_t att;
|
||||
} amotaMsg_t;
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t amotaAdvCfg =
|
||||
{
|
||||
{ 0, 0, 0}, /*! Advertising durations in ms */
|
||||
{ 800, 800, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t amotaSlaveCfg =
|
||||
{
|
||||
AMOTA_CONN_MAX, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t amotaSecCfg =
|
||||
{
|
||||
DM_AUTH_BOND_FLAG, /*! Authentication and bonding flags */
|
||||
0, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
FALSE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
/*! configurable parameters for AMOTA connection parameter update */
|
||||
static appUpdateCfg_t otaUpdateCfg =
|
||||
{
|
||||
0, /*! Connection idle period in ms before attempting
|
||||
connection parameter update; set to zero to disable */
|
||||
(15 / 1.25), /*! 15 ms */
|
||||
(30 / 1.25), /*! 30 ms */
|
||||
0, /*! Connection latency */
|
||||
(6000 / 10), /*! Supervision timeout in 10ms units */
|
||||
5 /*! Number of update attempts before giving up */
|
||||
};
|
||||
|
||||
/*! AMOTAS configuration */
|
||||
static const AmotasCfg_t amotasCfg =
|
||||
{
|
||||
0
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! advertising data, discoverable mode */
|
||||
static const uint8_t amotaAdvDataDisc[] =
|
||||
{
|
||||
/*! flags */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_FLAGS, /*! AD type */
|
||||
DM_FLAG_LE_GENERAL_DISC | /*! flags */
|
||||
DM_FLAG_LE_BREDR_NOT_SUP,
|
||||
|
||||
/*! tx power */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_TX_POWER, /*! AD type */
|
||||
0, /*! tx power */
|
||||
|
||||
/*! service UUID list */
|
||||
3, /*! length */
|
||||
DM_ADV_TYPE_16_UUID, /*! AD type */
|
||||
UINT16_TO_BYTES(ATT_UUID_DEVICE_INFO_SERVICE)
|
||||
};
|
||||
|
||||
/*! scan data, discoverable mode */
|
||||
static const uint8_t amotaScanDataDisc[] =
|
||||
{
|
||||
/*! device name */
|
||||
15, /*! length */
|
||||
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
|
||||
'a',
|
||||
'm',
|
||||
'b',
|
||||
'i',
|
||||
'q',
|
||||
'm',
|
||||
'i',
|
||||
'c',
|
||||
'r',
|
||||
'o',
|
||||
' ',
|
||||
'o',
|
||||
't',
|
||||
'a'
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
AMOTA_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
AMOTA_AMOTAS_TX_CCC_IDX, /*! AMOTA service, tx characteristic */
|
||||
AMOTA_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t amotaCccSet[AMOTA_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* AMOTA_GATT_SC_CCC_IDX */
|
||||
{AMOTAS_TX_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE} /* AMOTA_AMOTAS_TX_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF handler ID */
|
||||
wsfHandlerId_t amotaHandlerId;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaDmCback
|
||||
*
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(dmEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, sizeof(dmEvt_t));
|
||||
WsfMsgSend(amotaHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaAttCback
|
||||
*
|
||||
* \brief Application ATT callback.
|
||||
*
|
||||
* \param pEvt ATT callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaAttCback(attEvt_t *pEvt)
|
||||
{
|
||||
attEvt_t *pMsg;
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attEvt_t) + pEvt->valueLen)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attEvt_t));
|
||||
pMsg->pValue = (uint8_t *) (pMsg + 1);
|
||||
memcpy(pMsg->pValue, pEvt->pValue, pEvt->valueLen);
|
||||
WsfMsgSend(amotaHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaCccCback
|
||||
*
|
||||
* \brief Application ATTS client characteristic configuration callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaCccCback(attsCccEvt_t *pEvt)
|
||||
{
|
||||
attsCccEvt_t *pMsg;
|
||||
appDbHdl_t dbHdl;
|
||||
|
||||
/* if CCC not set from initialization and there's a device record */
|
||||
if ((pEvt->handle != ATT_HANDLE_NONE) &&
|
||||
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE))
|
||||
{
|
||||
/* store value in device database */
|
||||
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
|
||||
}
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attsCccEvt_t));
|
||||
WsfMsgSend(amotaHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaProcCccState
|
||||
*
|
||||
* \brief Process CCC state change.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaProcCccState(amotaMsg_t *pMsg)
|
||||
{
|
||||
APP_TRACE_INFO3("ccc state ind value:%d handle:%d idx:%d", pMsg->ccc.value, pMsg->ccc.handle, pMsg->ccc.idx);
|
||||
|
||||
/* handle heart rate measurement CCC */
|
||||
/* AMOTAS TX CCC */
|
||||
if (pMsg->ccc.idx == AMOTA_AMOTAS_TX_CCC_IDX)
|
||||
{
|
||||
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
|
||||
{
|
||||
// notify enabled
|
||||
amotas_start((dmConnId_t) pMsg->ccc.hdr.param,
|
||||
AMOTA_RESET_TIMER_IND, AMOTA_DISCONNECT_TIMER_IND,
|
||||
AMOTA_AMOTAS_TX_CCC_IDX);
|
||||
}
|
||||
else
|
||||
{
|
||||
// notify disabled
|
||||
amotas_stop((dmConnId_t) pMsg->ccc.hdr.param);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaClose
|
||||
*
|
||||
* \brief Perform UI actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaClose(amotaMsg_t *pMsg)
|
||||
{
|
||||
/* stop amotas */
|
||||
amotas_conn_close((dmConnId_t) pMsg->hdr.param);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaSetup
|
||||
*
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaSetup(amotaMsg_t *pMsg)
|
||||
{
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(amotaAdvDataDisc), (uint8_t *) amotaAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(amotaScanDataDisc), (uint8_t *) amotaScanDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL);
|
||||
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, 0, NULL);
|
||||
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaBtnCback
|
||||
*
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaBtnCback(uint8_t btn)
|
||||
{
|
||||
dmConnId_t connId;
|
||||
|
||||
/* button actions when connected */
|
||||
if ((connId = AppConnIsOpen()) != DM_CONN_ID_NONE)
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_MED:
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_LONG:
|
||||
AppConnClose(connId);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* button actions when not connected */
|
||||
else
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* start or restart advertising */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_MED:
|
||||
/* enter discoverable and bondable mode mode */
|
||||
AppSetBondable(TRUE);
|
||||
AppAdvStart(APP_MODE_DISCOVERABLE);
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_1_LONG:
|
||||
/* clear bonded device info and restart advertising */
|
||||
AppDbDeleteAllRecords();
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amotaProcMsg
|
||||
*
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amotaProcMsg(amotaMsg_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
switch(pMsg->hdr.event)
|
||||
{
|
||||
case AMOTA_RESET_TIMER_IND:
|
||||
case AMOTA_DISCONNECT_TIMER_IND:
|
||||
amotas_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
case ATTS_HANDLE_VALUE_CNF:
|
||||
break;
|
||||
|
||||
case ATTS_CCC_STATE_IND:
|
||||
amotaProcCccState(pMsg);
|
||||
break;
|
||||
|
||||
case ATT_MTU_UPDATE_IND:
|
||||
APP_TRACE_INFO1("Negotiated MTU %d", ((attEvt_t *)pMsg)->mtu);
|
||||
break;
|
||||
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
DmSecGenerateEccKeyReq();
|
||||
amotaSetup(pMsg);
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
break;
|
||||
|
||||
case DM_ADV_SET_START_IND:
|
||||
uiEvent = APP_UI_ADV_SET_START_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_SET_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_SET_STOP_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
case DM_CONN_OPEN_IND:
|
||||
amotas_proc_msg(&pMsg->hdr);
|
||||
uiEvent = APP_UI_CONN_OPEN;
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
{
|
||||
hciDisconnectCmplEvt_t *evt = (hciDisconnectCmplEvt_t*) pMsg;
|
||||
// uiEvent = APP_UI_CONN_CLOSE;
|
||||
APP_TRACE_INFO1(">>> Connection closed reason 0x%x <<<",
|
||||
evt->reason);
|
||||
amotaClose(pMsg);
|
||||
}
|
||||
break;
|
||||
|
||||
case DM_CONN_UPDATE_IND:
|
||||
amotas_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_CMPL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_CMPL;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_FAIL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_AUTH_REQ_IND:
|
||||
AppHandlePasskey(&pMsg->dm.authReq);
|
||||
break;
|
||||
|
||||
case DM_SEC_ECC_KEY_IND:
|
||||
DmSecSetEccKey(&pMsg->dm.eccMsg.data.key);
|
||||
break;
|
||||
|
||||
case DM_SEC_COMPARE_IND:
|
||||
AppHandleNumericComparison(&pMsg->dm.cnfInd);
|
||||
break;
|
||||
|
||||
case DM_PRIV_CLEAR_RES_LIST_IND:
|
||||
APP_TRACE_INFO1("Clear resolving list status 0x%02x", pMsg->hdr.status);
|
||||
break;
|
||||
|
||||
case DM_HW_ERROR_IND:
|
||||
uiEvent = APP_UI_HW_ERROR;
|
||||
break;
|
||||
case DM_VENDOR_SPEC_CMD_CMPL_IND:
|
||||
{
|
||||
#if defined(AM_PART_APOLLO) || defined(AM_PART_APOLLO2)
|
||||
|
||||
uint8_t *param_ptr = &pMsg->dm.vendorSpecCmdCmpl.param[0];
|
||||
|
||||
switch (pMsg->dm.vendorSpecCmdCmpl.opcode)
|
||||
{
|
||||
case 0xFC20: //read at address
|
||||
{
|
||||
uint32_t read_value;
|
||||
|
||||
BSTREAM_TO_UINT32(read_value, param_ptr);
|
||||
|
||||
APP_TRACE_INFO3("VSC 0x%0x complete status %x param %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status,
|
||||
read_value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
APP_TRACE_INFO2("VSC 0x%0x complete status %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("AmotaHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
amotaHandlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppAdvCfg = (appAdvCfg_t *) &amotaAdvCfg;
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &amotaSlaveCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &amotaSecCfg;
|
||||
pAppUpdateCfg = (appUpdateCfg_t *) &otaUpdateCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
AppServerInit();
|
||||
|
||||
/* initialize amota service server */
|
||||
amotas_init(handlerId, (AmotasCfg_t *) &amotasCfg);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaHandler
|
||||
*
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
// APP_TRACE_INFO1("Amota got evt %d", pMsg->event);
|
||||
|
||||
/* process ATT messages */
|
||||
if (pMsg->event >= ATT_CBACK_START && pMsg->event <= ATT_CBACK_END)
|
||||
{
|
||||
/* process server-related ATT messages */
|
||||
AppServerProcAttMsg(pMsg);
|
||||
}
|
||||
/* process DM messages */
|
||||
else if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
amotaProcMsg((amotaMsg_t *) pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmotaStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AmotaStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(amotaDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, amotaDmCback);
|
||||
AttRegister(amotaAttCback);
|
||||
AttConnRegister(AppServerConnCback);
|
||||
AttsCccRegister(AMOTA_NUM_CCC_IDX, (attsCccSet_t *) amotaCccSet, amotaCccCback);
|
||||
|
||||
/* Register for app framework callbacks */
|
||||
AppUiBtnRegister(amotaBtnCback);
|
||||
|
||||
/* Initialize attribute server database */
|
||||
SvcCoreGattCbackRegister(GattReadCback, GattWriteCback);
|
||||
SvcCoreAddGroup();
|
||||
SvcDisAddGroup();
|
||||
SvcAmotasCbackRegister(NULL, amotas_write_cback);
|
||||
SvcAmotasAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(AMOTA_GATT_SC_CCC_IDX);
|
||||
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// ancs_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of ANCSC.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef ANCS_API_H
|
||||
#define ANCS_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef ANCS_CONN_MAX
|
||||
#define ANCS_CONN_MAX 1
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AncsStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AncsStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AncsHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AncsHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AncsHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void AncsHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* ANCS_API_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,106 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// beaconscanner_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Beacon Scanner sample application interface
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
|
||||
#ifndef BEACONSCANNER_API_H
|
||||
#define BEACONSCANNER_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn BeaconScannerStart
|
||||
*
|
||||
* \brief Start Beacon Scan application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void BeaconScannerStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn BeaconScannerHandlerInit
|
||||
*
|
||||
* \brief Beacon Scan handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void BeaconScannerHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn BeaconScannerHandler
|
||||
*
|
||||
* \brief WSF event handler for Beacon Scan application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void BeaconScannerHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* BEACONSCANNER_API_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,109 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// ibeacon_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro iBeacon example
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef IBEACON_API_H
|
||||
#define IBEACON_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* IBEACON_API_H */
|
||||
@@ -0,0 +1,331 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// ibeacon_main.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of iBeacon.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_dis.h"
|
||||
#include "ibeacon_api.h"
|
||||
#include "gatt_api.h"
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF message event starting value */
|
||||
#define IBEACON_MSG_START 0xA0
|
||||
|
||||
/*! WSF message event enumeration */
|
||||
enum
|
||||
{
|
||||
IBEACON_TIMER_IND = IBEACON_MSG_START, /*! iBeacon reset timer expired */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Data Types
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Application message type */
|
||||
typedef union
|
||||
{
|
||||
wsfMsgHdr_t hdr;
|
||||
dmEvt_t dm;
|
||||
} ibeaconMsg_t;
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t ibeaconAdvCfg =
|
||||
{
|
||||
{60000, 0, 0}, /*! Advertising durations in ms */
|
||||
{ 800, 800, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t ibeaconSlaveCfg =
|
||||
{
|
||||
1, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t ibeaconSecCfg =
|
||||
{
|
||||
DM_AUTH_BOND_FLAG, /*! Authentication and bonding flags */
|
||||
0, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
FALSE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! advertising data, discoverable mode */
|
||||
static const uint8_t ibeaconAdvDataDisc[] =
|
||||
{
|
||||
/*! flags */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_FLAGS, /*! AD type */
|
||||
DM_FLAG_LE_GENERAL_DISC | /*! flags */
|
||||
DM_FLAG_LE_BREDR_NOT_SUP,
|
||||
|
||||
/*! Manufacturer specific data AD type */
|
||||
0x1A, /*! length */
|
||||
DM_ADV_TYPE_MANUFACTURER, /*! AD type */
|
||||
|
||||
0x4C, /*! Company ID[0] */
|
||||
0x00, /*! Company ID[1] */
|
||||
|
||||
0x02, /*! Device type, this has to be 0x02*/
|
||||
0x15, /*! Length of vendor advertising data. */
|
||||
|
||||
/*! Proximity UUID 16 bytes */
|
||||
0xe2, 0xc5, 0x6d, 0xb5,
|
||||
0xdf, 0xfb, 0x48, 0xd2,
|
||||
0xb0, 0x60, 0xd0, 0xf5,
|
||||
0xa7, 0x10, 0x96, 0xe0,
|
||||
|
||||
/*! Major 0xnnnn */
|
||||
0x00, 0x00,
|
||||
/*! Minor 0xnnnn */
|
||||
0x00, 0x00,
|
||||
|
||||
/*! Measured Power */
|
||||
0xc5
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF handler ID */
|
||||
wsfHandlerId_t iBeaconHandlerId;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconDmCback
|
||||
*
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void iBeaconDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(dmEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, sizeof(dmEvt_t));
|
||||
WsfMsgSend(iBeaconHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeacon Setup
|
||||
*
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void iBeaconSetup(ibeaconMsg_t *pMsg)
|
||||
{
|
||||
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(ibeaconAdvDataDisc), (uint8_t *) ibeaconAdvDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, 0, NULL);
|
||||
|
||||
// non-connectable advertising
|
||||
AppSetAdvType(DM_ADV_NONCONN_UNDIRECT);
|
||||
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_DISCOVERABLE);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconProcMsg
|
||||
*
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void iBeaconProcMsg(ibeaconMsg_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
switch(pMsg->hdr.event)
|
||||
{
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
DmSecGenerateEccKeyReq();
|
||||
iBeaconSetup(pMsg);
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("iBeaconHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
iBeaconHandlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppAdvCfg = (appAdvCfg_t *) &ibeaconAdvCfg;
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &ibeaconSlaveCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &ibeaconSecCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconHandler
|
||||
*
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
APP_TRACE_INFO1("iBeacon got evt %d", pMsg->event);
|
||||
|
||||
if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
iBeaconProcMsg((ibeaconMsg_t *) pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn iBeaconStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void iBeaconStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(iBeaconDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, iBeaconDmCback);
|
||||
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// prodtest_datc_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Proprietary data transfer client sample application.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \file prodtest_datc_api.h
|
||||
*
|
||||
* \brief Proprietary data transfer client sample application.
|
||||
*
|
||||
* $Date: 2016-12-28 16:12:14 -0600 (Wed, 28 Dec 2016) $
|
||||
* $Revision: 10805 $
|
||||
*
|
||||
* Copyright (c) 2012-2017 ARM Ltd., all rights reserved.
|
||||
* ARM Ltd. confidential and proprietary.
|
||||
*
|
||||
* IMPORTANT. Your use of this file is governed by a Software License Agreement
|
||||
* ("Agreement") that must be accepted in order to download or otherwise receive a
|
||||
* copy of this file. You may not use or copy this file for any purpose other than
|
||||
* as described in the Agreement. If you do not agree to all of the terms of the
|
||||
* Agreement do not use this file and delete all copies in your possession or control;
|
||||
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
|
||||
* to any use, copying or further distribution of this software.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
#ifndef DATC_API_H
|
||||
#define DATC_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatcStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatcStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatcHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatcHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatcHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatcHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* DATC_API_H */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,130 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// prodtest_dats_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Proprietary data transfer server sample application.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* file prodtest_dats_api.h
|
||||
*
|
||||
* brief Proprietary data transfer server sample application.
|
||||
*
|
||||
* $Date: 2016-12-28 16:12:14 -0600 (Wed, 28 Dec 2016) $
|
||||
* $Revision: 10805 $
|
||||
*
|
||||
* Copyright (c) 2012-2017 ARM Ltd., all rights reserved.
|
||||
* ARM Ltd. confidential and proprietary.
|
||||
*
|
||||
* IMPORTANT. Your use of this file is governed by a Software License Agreement
|
||||
* ("Agreement") that must be accepted in order to download or otherwise receive a
|
||||
* copy of this file. You may not use or copy this file for any purpose other than
|
||||
* as described in the Agreement. If you do not agree to all of the terms of the
|
||||
* Agreement do not use this file and delete all copies in your possession or control;
|
||||
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
|
||||
* to any use, copying or further distribution of this software.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
#ifndef DATS_API_H
|
||||
#define DATS_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef WDXS_INCLUDED
|
||||
#define WDXS_INCLUDED FALSE
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* DATS_API_H */
|
||||
@@ -0,0 +1,802 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// prodtest_dats_main.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Data transmitter sample application.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* file dats_main.c
|
||||
*
|
||||
* brief Data transmitter sample application.
|
||||
*
|
||||
* $Date: 2017-03-09 12:18:38 -0600 (Thu, 09 Mar 2017) $
|
||||
* $Revision: 11460 $
|
||||
*
|
||||
* Copyright (c) 2012-2017 ARM Ltd., all rights reserved.
|
||||
* ARM Ltd. confidential and proprietary.
|
||||
*
|
||||
* IMPORTANT. Your use of this file is governed by a Software License Agreement
|
||||
* ("Agreement") that must be accepted in order to download or otherwise receive a
|
||||
* copy of this file. You may not use or copy this file for any purpose other than
|
||||
* as described in the Agreement. If you do not agree to all of the terms of the
|
||||
* Agreement do not use this file and delete all copies in your possession or control;
|
||||
* if you do not have a copy of the Agreement, you must contact ARM Ltd. prior
|
||||
* to any use, copying or further distribution of this software.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "wsf_buf.h"
|
||||
#include "hci_api.h"
|
||||
#include "sec_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "smp_api.h"
|
||||
#include "att_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_wp.h"
|
||||
#include "calc128.h"
|
||||
#include "prodtest_dats_api.h"
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
#include "wsf_efs.h"
|
||||
#include "svc_wdxs.h"
|
||||
#include "wdxs_api.h"
|
||||
#include "wdxs_main.h"
|
||||
#include "wdxs_stream.h"
|
||||
#endif
|
||||
|
||||
#include "hci_apollo_config.h"
|
||||
#include "hci_drv_em9304.h"
|
||||
#include "gatt_api.h"
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
#if CS50_INCLUDED == TRUE
|
||||
|
||||
/* PHY Test Modes */
|
||||
#define DATS_PHY_1M 1
|
||||
#define DATS_PHY_2M 2
|
||||
#define DATS_PHY_CODED 3
|
||||
|
||||
#endif /* CS50_INCLUDED */
|
||||
|
||||
/*! Enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
WDXS_DC_CH_CCC_IDX, /*! WDXS DC service, service changed characteristic */
|
||||
WDXS_FTC_CH_CCC_IDX, /*! WDXS FTC service, service changed characteristic */
|
||||
WDXS_FTD_CH_CCC_IDX, /*! WDXS FTD service, service changed characteristic */
|
||||
WDXS_AU_CH_CCC_IDX, /*! WDXS AU service, service changed characteristic */
|
||||
#endif /* WDXS_INCLUDED */
|
||||
DATS_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
DATS_WP_DAT_CCC_IDX, /*! ARM Ltd. proprietary service, data transfer characteristic */
|
||||
DATS_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t datsAdvCfg =
|
||||
{
|
||||
{30000, 0, 0}, /*! Advertising durations in ms */
|
||||
{ 32, 32, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t datsSlaveCfg =
|
||||
{
|
||||
1, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t datsSecCfg =
|
||||
{
|
||||
0, /*! Authentication and bonding flags */
|
||||
DM_KEY_DIST_IRK, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK | DM_KEY_DIST_IRK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
FALSE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
/*! SMP security parameter configuration */
|
||||
static const smpCfg_t datsSmpCfg =
|
||||
{
|
||||
3000, /*! 'Repeated attempts' timeout in msec */
|
||||
SMP_IO_NO_IN_NO_OUT, /*! I/O Capability */
|
||||
7, /*! Minimum encryption key length */
|
||||
16, /*! Maximum encryption key length */
|
||||
1, /*! Attempts to trigger 'repeated attempts' timeout */
|
||||
0, /*! Device authentication requirements */
|
||||
64000, /*! Maximum repeated attempts timeout in msec */
|
||||
64000, /*! Time msec before attemptExp decreases */
|
||||
2 /*! Repeated attempts multiplier exponent */
|
||||
};
|
||||
|
||||
/*! configurable parameters for connection parameter update */
|
||||
static const appUpdateCfg_t datsUpdateCfg =
|
||||
{
|
||||
0, /*! Connection idle period in ms before attempting
|
||||
connection parameter update; set to zero to disable */
|
||||
640, /*! Minimum connection interval in 1.25ms units */
|
||||
800, /*! Maximum connection interval in 1.25ms units */
|
||||
3, /*! Connection latency */
|
||||
600, /*! Supervision timeout in 10ms units */
|
||||
5 /*! Number of update attempts before giving up */
|
||||
};
|
||||
|
||||
/*! ATT configurable parameters (increase MTU) */
|
||||
static const attCfg_t datsAttCfg =
|
||||
{
|
||||
15, /* ATT server service discovery connection idle timeout in seconds */
|
||||
241, /* desired ATT MTU */
|
||||
ATT_MAX_TRANS_TIMEOUT, /* transcation timeout in seconds */
|
||||
4 /* number of queued prepare writes supported by server */
|
||||
};
|
||||
|
||||
/*! local IRK */
|
||||
static uint8_t localIrk[] =
|
||||
{
|
||||
0x95, 0xC8, 0xEE, 0x6F, 0xC5, 0x0D, 0xEF, 0x93, 0x35, 0x4E, 0x7C, 0x57, 0x08, 0xE2, 0xA3, 0x85
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! advertising data, discoverable mode */
|
||||
static const uint8_t datsAdvDataDisc[] =
|
||||
{
|
||||
/*! flags */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_FLAGS, /*! AD type */
|
||||
DM_FLAG_LE_GENERAL_DISC | /*! flags */
|
||||
DM_FLAG_LE_BREDR_NOT_SUP,
|
||||
|
||||
/*! manufacturer specific data */
|
||||
3, /*! length */
|
||||
DM_ADV_TYPE_MANUFACTURER, /*! AD type */
|
||||
UINT16_TO_BYTES(HCI_ID_ARM) /*! company ID */
|
||||
};
|
||||
|
||||
/*! scan data, discoverable mode */
|
||||
static const uint8_t datsScanDataDisc[] =
|
||||
{
|
||||
/*! device name */
|
||||
8, /*! length */
|
||||
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
|
||||
'D',
|
||||
'a',
|
||||
't',
|
||||
'a',
|
||||
' ',
|
||||
'T',
|
||||
'X'
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t datsCccSet[DATS_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
{WDXS_DC_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* WDXS_DC_CH_CCC_IDX */
|
||||
{WDXS_FTC_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* WDXS_FTC_CH_CCC_IDX */
|
||||
{WDXS_FTD_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* WDXS_FTD_CH_CCC_IDX */
|
||||
{WDXS_AU_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* WDXS_AU_CH_CCC_IDX */
|
||||
#endif /* WDXS_INCLUDED */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* DATS_GATT_SC_CCC_IDX */
|
||||
{WP_DAT_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE} /* DATS_WP_DAT_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Local Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! application control block */
|
||||
static struct
|
||||
{
|
||||
wsfHandlerId_t handlerId; /* WSF handler ID */
|
||||
#if CS50_INCLUDED == TRUE
|
||||
uint8_t phyMode; /*! PHY Test Mode */
|
||||
#endif /* CS50_INCLUDED */
|
||||
} datsCb;
|
||||
|
||||
/* LESC OOB configuration */
|
||||
static dmSecLescOobCfg_t *datsOobCfg;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsSendData
|
||||
*
|
||||
* \brief Send notification containing data.
|
||||
*
|
||||
* \param connId DM connection ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsSendData(dmConnId_t connId)
|
||||
{
|
||||
uint8_t str[] = "hello.....from dats";
|
||||
|
||||
if (AttsCccEnabled(connId, DATS_WP_DAT_CCC_IDX))
|
||||
{
|
||||
/* send notification */
|
||||
AttsHandleValueNtf(connId, WP_DAT_HDL, sizeof(str), str);
|
||||
AttsHandleValueNtf(connId, WP_DAT_HDL, sizeof(str), str);
|
||||
AttsHandleValueNtf(connId, WP_DAT_HDL, sizeof(str), str);
|
||||
AttsHandleValueNtf(connId, WP_DAT_HDL, sizeof(str), str);
|
||||
AttsHandleValueNtf(connId, WP_DAT_HDL, sizeof(str), str);
|
||||
}
|
||||
}
|
||||
|
||||
static void datsSetup(dmEvt_t *pMsg);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsDmCback
|
||||
*
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
uint16_t len;
|
||||
|
||||
if (pDmEvt->hdr.event == DM_SEC_ECC_KEY_IND)
|
||||
{
|
||||
DmSecSetEccKey(&pDmEvt->eccMsg.data.key);
|
||||
|
||||
/* If the local device sends OOB data. */
|
||||
if (datsSecCfg.oob)
|
||||
{
|
||||
uint8_t oobLocalRandom[SMP_RAND_LEN];
|
||||
SecRand(oobLocalRandom, SMP_RAND_LEN);
|
||||
DmSecCalcOobReq(oobLocalRandom, pDmEvt->eccMsg.data.key.pubKey_x);
|
||||
}
|
||||
}
|
||||
else if (pDmEvt->hdr.event == DM_SEC_CALC_OOB_IND)
|
||||
{
|
||||
if (datsOobCfg == NULL)
|
||||
{
|
||||
datsOobCfg = WsfBufAlloc(sizeof(dmSecLescOobCfg_t));
|
||||
}
|
||||
|
||||
if (datsOobCfg)
|
||||
{
|
||||
Calc128Cpy(datsOobCfg->localConfirm, pDmEvt->oobCalcInd.confirm);
|
||||
Calc128Cpy(datsOobCfg->localRandom, pDmEvt->oobCalcInd.random);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
len = DmSizeOfEvt(pDmEvt);
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(len)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, len);
|
||||
WsfMsgSend(datsCb.handlerId, pMsg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsAttCback
|
||||
*
|
||||
* \brief Application ATT callback.
|
||||
*
|
||||
* \param pEvt ATT callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsAttCback(attEvt_t *pEvt)
|
||||
{
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
WdxsAttCback(pEvt);
|
||||
#endif /* WDXS_INCLUDED */
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsCccCback
|
||||
*
|
||||
* \brief Application ATTS client characteristic configuration callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsCccCback(attsCccEvt_t *pEvt)
|
||||
{
|
||||
appDbHdl_t dbHdl;
|
||||
|
||||
/* If CCC not set from initialization and there's a device record and currently bonded */
|
||||
if ((pEvt->handle != ATT_HANDLE_NONE) &&
|
||||
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE) &&
|
||||
AppCheckBonded((dmConnId_t)pEvt->hdr.param))
|
||||
{
|
||||
/* Store value in device database. */
|
||||
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsWpWriteCback
|
||||
*
|
||||
* \brief ATTS write callback for proprietary data service.
|
||||
*
|
||||
* \return ATT status.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
uint8_t datsWpWriteCback(dmConnId_t connId, uint16_t handle, uint8_t operation,
|
||||
uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr)
|
||||
{
|
||||
/* print received data */
|
||||
APP_TRACE_INFO0((const char*) pValue);
|
||||
|
||||
/* send back some data */
|
||||
datsSendData(connId);
|
||||
|
||||
return ATT_SUCCESS;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsSetup
|
||||
*
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsSetup(dmEvt_t *pMsg)
|
||||
{
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(datsAdvDataDisc), (uint8_t *) datsAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(datsScanDataDisc), (uint8_t *) datsScanDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, sizeof(datsAdvDataDisc), (uint8_t *) datsAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, sizeof(datsScanDataDisc), (uint8_t *) datsScanDataDisc);
|
||||
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsProcMsg
|
||||
*
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsProcMsg(dmEvt_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
switch(pMsg->hdr.event)
|
||||
{
|
||||
case ATT_MTU_UPDATE_IND:
|
||||
APP_TRACE_INFO1("Negotiated MTU %d", ((attEvt_t *)pMsg)->mtu);
|
||||
break;
|
||||
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
DmSecGenerateEccKeyReq();
|
||||
datsSetup(NULL);
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
HciVsEM_SetRfPowerLevelEx(TX_POWER_LEVEL_PLUS_0P4_dBm);
|
||||
break;
|
||||
|
||||
|
||||
case DM_ADV_SET_START_IND:
|
||||
uiEvent = APP_UI_ADV_SET_START_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_SET_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_SET_STOP_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
case DM_CONN_OPEN_IND:
|
||||
uiEvent = APP_UI_CONN_OPEN;
|
||||
#if CS50_INCLUDED == TRUE
|
||||
datsCb.phyMode = DATS_PHY_1M;
|
||||
#endif /* CS50_INCLUDED */
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
uiEvent = APP_UI_CONN_CLOSE;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_CMPL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_CMPL;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_FAIL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_AUTH_REQ_IND:
|
||||
|
||||
if (pMsg->authReq.oob)
|
||||
{
|
||||
dmConnId_t connId = (dmConnId_t) pMsg->hdr.param;
|
||||
|
||||
/* TODO: Perform OOB Exchange with the peer. */
|
||||
|
||||
|
||||
/* TODO: Fill datsOobCfg peerConfirm and peerRandom with value passed out of band */
|
||||
|
||||
if (datsOobCfg != NULL)
|
||||
{
|
||||
DmSecSetOob(connId, datsOobCfg);
|
||||
}
|
||||
|
||||
DmSecAuthRsp(connId, 0, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
AppHandlePasskey(&pMsg->authReq);
|
||||
}
|
||||
break;
|
||||
case DM_SEC_ECC_KEY_IND:
|
||||
DmSecSetEccKey(&pMsg->eccMsg.data.key);
|
||||
break;
|
||||
case DM_SEC_COMPARE_IND:
|
||||
AppHandleNumericComparison(&pMsg->cnfInd);
|
||||
break;
|
||||
|
||||
case DM_PRIV_CLEAR_RES_LIST_IND:
|
||||
APP_TRACE_INFO1("Clear resolving list status 0x%02x", pMsg->hdr.status);
|
||||
break;
|
||||
|
||||
case DM_HW_ERROR_IND:
|
||||
uiEvent = APP_UI_HW_ERROR;
|
||||
break;
|
||||
case DM_VENDOR_SPEC_CMD_CMPL_IND:
|
||||
{
|
||||
#if defined(AM_PART_APOLLO) || defined(AM_PART_APOLLO2)
|
||||
|
||||
uint8_t *param_ptr = &pMsg->vendorSpecCmdCmpl.param[0];
|
||||
|
||||
switch (pMsg->vendorSpecCmdCmpl.opcode)
|
||||
{
|
||||
case 0xFC20: //read at address
|
||||
{
|
||||
uint32_t read_value;
|
||||
|
||||
BSTREAM_TO_UINT32(read_value, param_ptr);
|
||||
|
||||
APP_TRACE_INFO3("VSC 0x%0x complete status %x param %x",
|
||||
pMsg->vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status,
|
||||
read_value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
APP_TRACE_INFO2("VSC 0x%0x complete status %x",
|
||||
pMsg->vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("DatsHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
datsCb.handlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &datsSlaveCfg;
|
||||
pAppAdvCfg = (appAdvCfg_t *) &datsAdvCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &datsSecCfg;
|
||||
pAppUpdateCfg = (appUpdateCfg_t *) &datsUpdateCfg;
|
||||
pSmpCfg = (smpCfg_t *) &datsSmpCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
|
||||
/* Set IRK for the local device */
|
||||
DmSecSetLocalIrk(localIrk);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsBtnCback
|
||||
*
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsBtnCback(uint8_t btn)
|
||||
{
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
static uint8_t waveform = WDXS_STREAM_WAVEFORM_SINE;
|
||||
#endif /* WDXS_INCLUDED */
|
||||
|
||||
#if CS50_INCLUDED == TRUE
|
||||
dmConnId_t connId;
|
||||
if ((connId = AppConnIsOpen()) != DM_CONN_ID_NONE)
|
||||
#else
|
||||
if (AppConnIsOpen() != DM_CONN_ID_NONE)
|
||||
#endif /* CS50_INCLUDED */
|
||||
{
|
||||
switch (btn)
|
||||
{
|
||||
#if CS50_INCLUDED == TRUE
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
|
||||
/* Toggle PHY Test Mode */
|
||||
if (datsCb.phyMode == DATS_PHY_1M)
|
||||
{
|
||||
APP_TRACE_INFO0("2 MBit TX and RX PHY Requested");
|
||||
DmSetPhy(connId, HCI_ALL_PHY_ALL_PREFERENCES, HCI_PHY_LE_2M_BIT, HCI_PHY_LE_2M_BIT, HCI_PHY_OPTIONS_NONE);
|
||||
}
|
||||
else if (datsCb.phyMode == DATS_PHY_2M)
|
||||
{
|
||||
APP_TRACE_INFO0("LE Coded TX and RX PHY Requested");
|
||||
DmSetPhy(connId, HCI_ALL_PHY_ALL_PREFERENCES, HCI_PHY_LE_CODED_BIT, HCI_PHY_LE_CODED_BIT, HCI_PHY_OPTIONS_NONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
APP_TRACE_INFO0("1 MBit TX and RX PHY Requested");
|
||||
DmSetPhy(connId, HCI_ALL_PHY_ALL_PREFERENCES, HCI_PHY_LE_1M_BIT, HCI_PHY_LE_1M_BIT, HCI_PHY_OPTIONS_NONE);
|
||||
}
|
||||
break;
|
||||
|
||||
#endif /* CS50_INCLUDED */
|
||||
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
/* Change stream waveform */
|
||||
waveform++;
|
||||
|
||||
if ( waveform > WDXS_STREAM_WAVEFORM_SAWTOOTH )
|
||||
{
|
||||
waveform = WDXS_STREAM_WAVEFORM_SINE;
|
||||
}
|
||||
|
||||
wdxsSetStreamWaveform(waveform);
|
||||
break;
|
||||
#endif /* WDXS_INCLUDED */
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn datsWsfBufDiagnostics
|
||||
*
|
||||
* \brief Callback for WSF buffer diagnostic messages.
|
||||
*
|
||||
* \param pInfo Diagnostics message
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void datsWsfBufDiagnostics(WsfBufDiag_t *pInfo)
|
||||
{
|
||||
if (pInfo->type == WSF_BUF_ALLOC_FAILED)
|
||||
{
|
||||
APP_TRACE_INFO2("Dats got WSF Buffer Allocation Failure - Task: %d Len: %d",
|
||||
pInfo->param.alloc.taskId, pInfo->param.alloc.len);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsHandler
|
||||
*
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
APP_TRACE_INFO1("Dats got evt %d", pMsg->event);
|
||||
|
||||
/* process ATT messages */
|
||||
if (pMsg->event >= ATT_CBACK_START && pMsg->event <= ATT_CBACK_END)
|
||||
{
|
||||
/* process server-related ATT messages */
|
||||
AppServerProcAttMsg(pMsg);
|
||||
}
|
||||
/* process DM messages */
|
||||
else if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
/* process WDXS-related messages */
|
||||
WdxsProcDmMsg((dmEvt_t*) pMsg);
|
||||
#endif /* WDXS_INCLUDED */
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
datsProcMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn DatsStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void DatsStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(datsDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, datsDmCback);
|
||||
AttRegister(datsAttCback);
|
||||
AttConnRegister(AppServerConnCback);
|
||||
AttsCccRegister(DATS_NUM_CCC_IDX, (attsCccSet_t *) datsCccSet, datsCccCback);
|
||||
|
||||
/* Initialize attribute server database */
|
||||
SvcCoreGattCbackRegister(GattReadCback, GattWriteCback);
|
||||
SvcCoreAddGroup();
|
||||
SvcWpCbackRegister(NULL, datsWpWriteCback);
|
||||
SvcWpAddGroup();
|
||||
|
||||
/* Register for app framework button callbacks */
|
||||
AppUiBtnRegister(datsBtnCback);
|
||||
|
||||
#if WDXS_INCLUDED == TRUE
|
||||
|
||||
/* Initialize the OTA File Media */
|
||||
WdxsOtaMediaInit();
|
||||
|
||||
/* Initialize the WDXS Stream */
|
||||
wdxsStreamInit();
|
||||
|
||||
/* Set the WDXS CCC Identifiers */
|
||||
WdxsSetCccIdx(WDXS_DC_CH_CCC_IDX, WDXS_AU_CH_CCC_IDX, WDXS_FTC_CH_CCC_IDX, WDXS_FTD_CH_CCC_IDX);
|
||||
|
||||
#endif /* WDXS_INCLUDED */
|
||||
|
||||
WsfBufDiagRegister(datsWsfBufDiagnostics);
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(DATS_GATT_SC_CCC_IDX);
|
||||
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,126 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// vole_api.h
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of AMDTP service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2018, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 1.2.12 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#ifndef VOLE_API_H
|
||||
#define VOLE_API_H
|
||||
|
||||
#include "wsf_os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
#ifndef VOLE_CONN_MAX
|
||||
#define VOLE_CONN_MAX 1
|
||||
#endif
|
||||
|
||||
/*! WSF message event starting value */
|
||||
#define VOLE_MSG_START 0xA0
|
||||
|
||||
/*! WSF message event enumeration */
|
||||
enum
|
||||
{
|
||||
AMOTA_TIMER_IND = VOLE_MSG_START,
|
||||
};
|
||||
|
||||
extern dmConnId_t g_AmaConnId;
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
Function Declarations
|
||||
**************************************************************************************************/
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn AmvosStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleStart(void);
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn VoleHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID for App.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleHandlerInit(wsfHandlerId_t handlerId);
|
||||
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn VoleHandler
|
||||
*
|
||||
* \brief WSF event handler for the application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg);
|
||||
void VoleBleSend(uint8_t * buf, uint32_t len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif /* VOLE_API_H */
|
||||
@@ -0,0 +1,867 @@
|
||||
// ****************************************************************************
|
||||
//
|
||||
// vole_main.c
|
||||
//! @file
|
||||
//!
|
||||
//! @brief Ambiq Micro's demonstration of Voice Over LE service.
|
||||
//!
|
||||
//! @{
|
||||
//
|
||||
// ****************************************************************************
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// Copyright (c) 2020, Ambiq Micro
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. Neither the name of the copyright holder nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from this
|
||||
// software without specific prior written permission.
|
||||
//
|
||||
// Third party software included in this distribution is subject to the
|
||||
// additional license terms as defined in the /docs/licenses directory.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
// This is part of revision 2.4.2 of the AmbiqSuite Development Package.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
#include "usr_include.h"
|
||||
|
||||
#include <string.h>
|
||||
#include "wsf_types.h"
|
||||
#include "bstream.h"
|
||||
#include "wsf_msg.h"
|
||||
#include "wsf_trace.h"
|
||||
#include "hci_api.h"
|
||||
#include "dm_api.h"
|
||||
#include "att_api.h"
|
||||
#include "smp_api.h"
|
||||
#include "app_api.h"
|
||||
#include "app_db.h"
|
||||
#include "app_ui.h"
|
||||
#include "app_hw.h"
|
||||
#include "svc_ch.h"
|
||||
#include "svc_core.h"
|
||||
#include "svc_dis.h"
|
||||
|
||||
#include "vole_api.h"
|
||||
#include "svc_amvole.h"
|
||||
#include "vole_common.h"
|
||||
#include "vole_board_config.h"
|
||||
|
||||
#include "am_util.h"
|
||||
#include "crc32.h"
|
||||
#include "am_app_KWD_AMA.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "voles_api.h"
|
||||
#include "gatt_api.h"
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
Macros
|
||||
**************************************************************************************************/
|
||||
|
||||
/**************************************************************************************************
|
||||
Data Types
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! Application message type */
|
||||
typedef union
|
||||
{
|
||||
wsfMsgHdr_t hdr;
|
||||
dmEvt_t dm;
|
||||
attsCccEvt_t ccc;
|
||||
attEvt_t att;
|
||||
} amvoleMsg_t;
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
Configurable Parameters
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! configurable parameters for advertising */
|
||||
static const appAdvCfg_t amvoleAdvCfg =
|
||||
{
|
||||
{60000, 0, 0}, /*! Advertising durations in ms */
|
||||
{ 800, 800, 0} /*! Advertising intervals in 0.625 ms units */
|
||||
};
|
||||
|
||||
/*! configurable parameters for slave */
|
||||
static const appSlaveCfg_t amvoleSlaveCfg =
|
||||
{
|
||||
VOLE_CONN_MAX, /*! Maximum connections */
|
||||
};
|
||||
|
||||
/*! configurable parameters for security */
|
||||
static const appSecCfg_t amvoleSecCfg =
|
||||
{
|
||||
DM_AUTH_BOND_FLAG | DM_AUTH_SC_FLAG, /*! Authentication and bonding flags */
|
||||
0, /*! Initiator key distribution flags */
|
||||
DM_KEY_DIST_LTK, /*! Responder key distribution flags */
|
||||
FALSE, /*! TRUE if Out-of-band pairing data is present */
|
||||
FALSE /*! TRUE to initiate security upon connection */
|
||||
};
|
||||
|
||||
|
||||
static const appUpdateCfg_t amvoleUpdateCfg =
|
||||
{
|
||||
1000, //3000, /*! Connection idle period in ms before attempting
|
||||
//connection parameter update; set to zero to disable */
|
||||
6, //6, /*! 7.5ms */
|
||||
12, //15, /*! 30ms */
|
||||
0, /*! Connection latency */
|
||||
400, //2000, //600, /*! Supervision timeout in 10ms units */
|
||||
5 /*! Number of update attempts before giving up */
|
||||
};
|
||||
|
||||
/*! SMP security parameter configuration */
|
||||
static const smpCfg_t amvoleSmpCfg =
|
||||
{
|
||||
3000, /*! 'Repeated attempts' timeout in msec */
|
||||
SMP_IO_NO_IN_NO_OUT, /*! I/O Capability */
|
||||
7, /*! Minimum encryption key length */
|
||||
16, /*! Maximum encryption key length */
|
||||
3, /*! Attempts to trigger 'repeated attempts' timeout */
|
||||
0, /*! Device authentication requirements */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Advertising Data
|
||||
**************************************************************************************************/
|
||||
|
||||
// RAM buffers to be used
|
||||
uint8_t amvoleAdvDataDisc[31];
|
||||
uint8_t amvoleScanDataDisc[31];
|
||||
|
||||
/*! advertising data, discoverable mode */
|
||||
static const uint8_t amvoleAdvDataDiscDefault[] =
|
||||
{
|
||||
/*! flags */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_FLAGS, /*! AD type */
|
||||
DM_FLAG_LE_GENERAL_DISC | /*! flags */
|
||||
DM_FLAG_LE_BREDR_NOT_SUP,
|
||||
|
||||
/*! tx power */
|
||||
2, /*! length */
|
||||
DM_ADV_TYPE_TX_POWER, /*! AD type */
|
||||
0, /*! tx power */
|
||||
|
||||
/*! service UUID list */
|
||||
17, /*! length */
|
||||
DM_ADV_TYPE_128_UUID, /*! AD type */
|
||||
ATT_UUID_VOLES_SERVICE
|
||||
};
|
||||
|
||||
/*! scan data, discoverable mode */
|
||||
static const uint8_t amvoleScanDataDiscDefault[] =
|
||||
{
|
||||
/*! device name */
|
||||
5, /*! length */
|
||||
DM_ADV_TYPE_LOCAL_NAME, /*! AD type */
|
||||
'V',
|
||||
'o',
|
||||
'L',
|
||||
'E'
|
||||
};
|
||||
|
||||
dmConnId_t g_AmaConnId = DM_CONN_ID_NONE;
|
||||
|
||||
bool_t g_start_voice_send = FALSE;
|
||||
|
||||
extern bool am_app_KWD_AMA_tx_ver_exchange_send(void);
|
||||
|
||||
// index is the starting point of the local name, local name only in advData
|
||||
static bool amvoleSetLocalName(uint8_t* pAdvData, uint8_t* pLocalName, uint8_t len, uint8_t index)
|
||||
{
|
||||
if (index + len + 1 > 31)
|
||||
{
|
||||
// max adv data is 31 byte long
|
||||
return false;
|
||||
}
|
||||
|
||||
// set parameter length
|
||||
pAdvData[index] = len + 1;
|
||||
// set parameter type
|
||||
pAdvData[index + 1] = DM_ADV_TYPE_LOCAL_NAME;
|
||||
|
||||
// set local name
|
||||
for ( uint8_t i = 0; i < len; i++ )
|
||||
{
|
||||
pAdvData[i + 2 + index] = pLocalName[i];
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void amvoleKwdSetDemoName(void)
|
||||
{
|
||||
uint8_t test_bdaddress[6];
|
||||
uint8_t ble_device_name[20] = "VOLES-"; //local name = device name
|
||||
uint8_t *pBda;
|
||||
uint8_t index = 6;
|
||||
|
||||
//fixme: read bd address and print out
|
||||
pBda = HciGetBdAddr();
|
||||
BdaCpy(test_bdaddress, pBda);
|
||||
|
||||
pBda = (uint8_t*)Bda2Str(test_bdaddress);
|
||||
APP_TRACE_INFO0("Local Device BD Address: ");
|
||||
APP_TRACE_INFO0(Bda2Str(test_bdaddress));
|
||||
APP_TRACE_INFO0("\n");
|
||||
|
||||
// build demo name here
|
||||
// 1st letter is board variant
|
||||
#if USE_MAYA
|
||||
ble_device_name[index++] = 'M';
|
||||
#elif USE_APOLLO2_QT
|
||||
ble_device_name[index++] = 'Q';
|
||||
#else
|
||||
ble_device_name[index++] = 'E';
|
||||
#endif
|
||||
|
||||
|
||||
// 3rd letter is wake-on-sound variant
|
||||
#if USE_WAKE_ON_SOUND
|
||||
ble_device_name[index++] = 'W';
|
||||
#else
|
||||
ble_device_name[index++] = 'A'; // A for always listening...
|
||||
#endif
|
||||
|
||||
|
||||
ble_device_name[index++] = '-';
|
||||
|
||||
ble_device_name[index++] = 'A';
|
||||
ble_device_name[index++] = 'M';
|
||||
ble_device_name[index++] = 'A';
|
||||
|
||||
// a hyphen...
|
||||
ble_device_name[index++] = '-';
|
||||
|
||||
// take the last 4 hex digit
|
||||
ble_device_name[index++] = pBda[8];
|
||||
ble_device_name[index++] = pBda[9];
|
||||
ble_device_name[index++] = pBda[10];
|
||||
ble_device_name[index++] = pBda[11];
|
||||
|
||||
// set local name here:
|
||||
amvoleSetLocalName(amvoleScanDataDisc, ble_device_name, index, 0);
|
||||
//SvcCoreSetDevName(ble_device_name, index);
|
||||
}
|
||||
|
||||
/**************************************************************************************************
|
||||
Client Characteristic Configuration Descriptors
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! enumeration of client characteristic configuration descriptors */
|
||||
enum
|
||||
{
|
||||
VOLES_GATT_SC_CCC_IDX, /*! GATT service, service changed characteristic */
|
||||
VOLES_TX_CCC_IDX, /*! AMDTP service, tx characteristic */
|
||||
VOLES_NUM_CCC_IDX
|
||||
};
|
||||
|
||||
/*! client characteristic configuration descriptors settings, indexed by above enumeration */
|
||||
static const attsCccSet_t amvoleCccSet[VOLES_NUM_CCC_IDX] =
|
||||
{
|
||||
/* cccd handle value range security level */
|
||||
{GATT_SC_CH_CCC_HDL, ATT_CLIENT_CFG_INDICATE, DM_SEC_LEVEL_NONE}, /* VOLES_GATT_SC_CCC_IDX */
|
||||
{VOLES_TX_CH_CCC_HDL, ATT_CLIENT_CFG_NOTIFY, DM_SEC_LEVEL_NONE}, /* VOLES_TX_CCC_IDX */
|
||||
};
|
||||
|
||||
/**************************************************************************************************
|
||||
Global Variables
|
||||
**************************************************************************************************/
|
||||
|
||||
/*! WSF handler ID */
|
||||
wsfHandlerId_t amvoleHandlerId;
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleDmCback
|
||||
*
|
||||
* \brief Application DM callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleDmCback(dmEvt_t *pDmEvt)
|
||||
{
|
||||
dmEvt_t *pMsg;
|
||||
uint16_t len;
|
||||
|
||||
len = DmSizeOfEvt(pDmEvt);
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(len)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pDmEvt, len);
|
||||
WsfMsgSend(amvoleHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
bool amvoleTxChannelIsAvailable(void)
|
||||
{
|
||||
return(DM_CONN_ID_NONE != AppConnIsOpen());
|
||||
}
|
||||
|
||||
void VoleBleSend(uint8_t * buf, uint32_t len)
|
||||
{
|
||||
if (amvoleTxChannelIsAvailable())
|
||||
{
|
||||
// simply tries to send notification
|
||||
AttsHandleValueNtf(g_AmaConnId, VOLES_TX_HDL, len, buf); // connId always group 0 since support only 1 connection.
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleAttCback
|
||||
*
|
||||
* \brief Application ATT callback.
|
||||
*
|
||||
* \param pEvt ATT callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleAttCback(attEvt_t *pEvt)
|
||||
{
|
||||
attEvt_t *pMsg;
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attEvt_t) + pEvt->valueLen)) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attEvt_t));
|
||||
pMsg->pValue = (uint8_t *) (pMsg + 1);
|
||||
memcpy(pMsg->pValue, pEvt->pValue, pEvt->valueLen);
|
||||
WsfMsgSend(amvoleHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleCccCback
|
||||
*
|
||||
* \brief Application ATTS client characteristic configuration callback.
|
||||
*
|
||||
* \param pDmEvt DM callback event
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleCccCback(attsCccEvt_t *pEvt)
|
||||
{
|
||||
attsCccEvt_t *pMsg;
|
||||
appDbHdl_t dbHdl;
|
||||
|
||||
/* if CCC not set from initialization and there's a device record */
|
||||
if ((pEvt->handle != ATT_HANDLE_NONE) &&
|
||||
((dbHdl = AppDbGetHdl((dmConnId_t) pEvt->hdr.param)) != APP_DB_HDL_NONE))
|
||||
{
|
||||
/* store value in device database */
|
||||
AppDbSetCccTblValue(dbHdl, pEvt->idx, pEvt->value);
|
||||
}
|
||||
|
||||
if ((pMsg = WsfMsgAlloc(sizeof(attsCccEvt_t))) != NULL)
|
||||
{
|
||||
memcpy(pMsg, pEvt, sizeof(attsCccEvt_t));
|
||||
WsfMsgSend(amvoleHandlerId, pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleProcCccState
|
||||
*
|
||||
* \brief Process CCC state change.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleProcCccState(amvoleMsg_t *pMsg)
|
||||
{
|
||||
APP_TRACE_INFO3("ccc state ind value:%d handle:%d idx:%d\n", pMsg->ccc.value, pMsg->ccc.handle, pMsg->ccc.idx);
|
||||
|
||||
/* VOLES TX CCC */
|
||||
if (pMsg->ccc.idx == VOLES_TX_CCC_IDX)
|
||||
{
|
||||
if (pMsg->ccc.value == ATT_CLIENT_CFG_NOTIFY)
|
||||
{
|
||||
// notify enabled
|
||||
g_AmaConnId = (dmConnId_t) pMsg->ccc.hdr.param;
|
||||
APP_TRACE_INFO1("connId : %d\r\n", pMsg->ccc.hdr.param);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_AmaConnId = DM_CONN_ID_NONE;
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleClose
|
||||
*
|
||||
* \brief Perform UI actions on connection close.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleClose(amvoleMsg_t *pMsg)
|
||||
{
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleSetup
|
||||
*
|
||||
* \brief Set up advertising and other procedures that need to be performed after
|
||||
* device reset.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleSetup(amvoleMsg_t *pMsg)
|
||||
{
|
||||
/* set advertising and scan response data for discoverable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_DISCOVERABLE, sizeof(amvoleAdvDataDisc), (uint8_t *) amvoleAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_DISCOVERABLE, sizeof(amvoleScanDataDisc), (uint8_t *) amvoleScanDataDisc);
|
||||
|
||||
/* set advertising and scan response data for connectable mode */
|
||||
AppAdvSetData(APP_ADV_DATA_CONNECTABLE, sizeof(amvoleAdvDataDisc), (uint8_t *) amvoleAdvDataDisc);
|
||||
AppAdvSetData(APP_SCAN_DATA_CONNECTABLE, sizeof(amvoleScanDataDisc), (uint8_t *) amvoleScanDataDisc);
|
||||
|
||||
AppSetBondable(TRUE);
|
||||
/* start advertising; automatically set connectable/discoverable mode and bondable mode */
|
||||
AppAdvStart(APP_MODE_AUTO_INIT);
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
//
|
||||
// LED task to indicate external events, such as heart beat and key word detected.
|
||||
//
|
||||
//*****************************************************************************
|
||||
|
||||
void am_app_led_on(void)
|
||||
{
|
||||
#if defined(AM_PART_APOLLO2)
|
||||
am_hal_gpio_out_bit_toggle(LED_D6);
|
||||
am_hal_gpio_out_bit_toggle(LED_D7);
|
||||
am_hal_gpio_out_bit_toggle(LED_D8);
|
||||
#endif // #if defined(AM_PART_APOLLO2)
|
||||
|
||||
#if defined(AM_PART_APOLLO3) || defined(AM_PART_APOLLO3P)
|
||||
#if USE_APOLLO3_BLUE_EVB
|
||||
am_hal_gpio_state_write(LED_D5, AM_HAL_GPIO_OUTPUT_TOGGLE);
|
||||
am_hal_gpio_state_write(LED_D6, AM_HAL_GPIO_OUTPUT_TOGGLE);
|
||||
am_hal_gpio_state_write(LED_D7, AM_HAL_GPIO_OUTPUT_TOGGLE);
|
||||
am_hal_gpio_state_write(LED_D8, AM_HAL_GPIO_OUTPUT_TOGGLE);
|
||||
|
||||
#endif // #if USE_APOLLO3_BLUE_EVB
|
||||
#endif //#if defined(AM_PART_APOLLO3)
|
||||
|
||||
}
|
||||
|
||||
void am_app_led_off(void)
|
||||
{
|
||||
#if defined(AM_PART_APOLLO2)
|
||||
am_hal_gpio_out_bit_clear(LED_D6);
|
||||
am_hal_gpio_out_bit_clear(LED_D7);
|
||||
am_hal_gpio_out_bit_clear(LED_D8);
|
||||
#endif
|
||||
|
||||
#if defined(AM_PART_APOLLO3) || defined(AM_PART_APOLLO3P)
|
||||
#if USE_APOLLO3_BLUE_EVB
|
||||
am_hal_gpio_state_write(LED_D5, AM_HAL_GPIO_OUTPUT_CLEAR);
|
||||
am_hal_gpio_state_write(LED_D6, AM_HAL_GPIO_OUTPUT_CLEAR);
|
||||
am_hal_gpio_state_write(LED_D7, AM_HAL_GPIO_OUTPUT_CLEAR);
|
||||
am_hal_gpio_state_write(LED_D8, AM_HAL_GPIO_OUTPUT_CLEAR);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleBtnCback
|
||||
*
|
||||
* \brief Button press callback.
|
||||
*
|
||||
* \param btn Button press.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleBtnCback(uint8_t btn)
|
||||
{
|
||||
dmConnId_t connId = AppConnIsOpen();
|
||||
|
||||
APP_TRACE_INFO2("button %d pressed, connection open:%d", btn, connId);
|
||||
|
||||
/* button actions when connected */
|
||||
if (connId != DM_CONN_ID_NONE)
|
||||
{
|
||||
APP_TRACE_INFO1("btn:%d", btn);
|
||||
switch (btn)
|
||||
{
|
||||
// transmit voice data using mSBC encode
|
||||
case APP_UI_BTN_1_SHORT:
|
||||
APP_TRACE_INFO0("start speech data send...");
|
||||
voles_set_codec_type(MSBC_CODEC_IN_USE);
|
||||
voles_init(amvoleHandlerId, MSBC_CODEC_IN_USE);
|
||||
am_app_KWD_AMA_start_speech_send();
|
||||
break;
|
||||
|
||||
case APP_UI_BTN_2_SHORT:
|
||||
voles_set_codec_type(OPUS_CODEC_IN_USE);
|
||||
voles_init(amvoleHandlerId, OPUS_CODEC_IN_USE);
|
||||
am_app_KWD_AMA_start_speech_send();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
uint8_t
|
||||
amvole_write_cback(dmConnId_t connId, uint16_t handle, uint8_t operation,
|
||||
uint16_t offset, uint16_t len, uint8_t *pValue, attsAttr_t *pAttr)
|
||||
{
|
||||
if (handle == VOLES_RX_HDL)
|
||||
{
|
||||
am_app_KWD_AMA_rx_handler(pValue, len);
|
||||
}
|
||||
return ATT_SUCCESS;
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn amvoleProcMsg
|
||||
*
|
||||
* \brief Process messages from the event handler.
|
||||
*
|
||||
* \param pMsg Pointer to message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
static void amvoleProcMsg(amvoleMsg_t *pMsg)
|
||||
{
|
||||
uint8_t uiEvent = APP_UI_NONE;
|
||||
|
||||
static uint8_t retry_cnt = 0;
|
||||
|
||||
switch(pMsg->hdr.event)
|
||||
{
|
||||
case ATTS_HANDLE_VALUE_CNF:
|
||||
|
||||
voles_proc_msg(&pMsg->hdr);
|
||||
|
||||
break;
|
||||
|
||||
case ATTS_CCC_STATE_IND:
|
||||
amvoleProcCccState(pMsg);
|
||||
if (pMsg->ccc.handle == VOLES_TX_CH_CCC_HDL)
|
||||
{
|
||||
am_app_KWD_AMA_tx_ver_exchange_send();
|
||||
}
|
||||
break;
|
||||
|
||||
case DM_RESET_CMPL_IND:
|
||||
AttsCalculateDbHash();
|
||||
DmSecGenerateEccKeyReq();
|
||||
amvoleSetup(pMsg);
|
||||
|
||||
#if USE_BLE_TX_POWER_SET
|
||||
HciVsEM_SetRfPowerLevelEx(TX_POWER_LEVEL_PLUS_6P2_dBm);
|
||||
#endif
|
||||
|
||||
uiEvent = APP_UI_RESET_CMPL;
|
||||
break;
|
||||
|
||||
case DM_ADV_SET_START_IND:
|
||||
uiEvent = APP_UI_ADV_SET_START_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_SET_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_SET_STOP_IND;
|
||||
break;
|
||||
|
||||
case DM_ADV_START_IND:
|
||||
uiEvent = APP_UI_ADV_START;
|
||||
break;
|
||||
|
||||
case DM_ADV_STOP_IND:
|
||||
uiEvent = APP_UI_ADV_STOP;
|
||||
break;
|
||||
|
||||
case DM_CONN_OPEN_IND:
|
||||
voles_proc_msg(&pMsg->hdr);
|
||||
DmConnSetDataLen(1, 251, 0x848);
|
||||
|
||||
uiEvent = APP_UI_CONN_OPEN;
|
||||
|
||||
retry_cnt = 0;
|
||||
|
||||
break;
|
||||
|
||||
case ATT_MTU_UPDATE_IND:
|
||||
if ( AttGetMtu(1) < BLE_MSBC_DATA_BUFFER_SIZE )
|
||||
{
|
||||
if (retry_cnt < 5)
|
||||
{
|
||||
retry_cnt++;
|
||||
AttcMtuReq(1, 247);
|
||||
}
|
||||
}
|
||||
|
||||
APP_TRACE_INFO2("ATT_MTU_UPDATE_IND AttGetMtu(), return = %d pMsg->att.mtu = %d\n", AttGetMtu(1), pMsg->att.mtu);
|
||||
break;
|
||||
|
||||
case DM_CONN_DATA_LEN_CHANGE_IND:
|
||||
am_util_debug_printf("DM_CONN_DATA_LEN_CHANGE_IND: status = %d, max RX len = %d, max TX len = %d \n", pMsg->dm.dataLenChange.hdr.status, pMsg->dm.dataLenChange.maxRxOctets, pMsg->dm.dataLenChange.maxTxOctets);
|
||||
break;
|
||||
|
||||
case DM_CONN_CLOSE_IND:
|
||||
APP_TRACE_INFO1("DM_CONN_CLOSE_IND reason = 0x%02x\n", pMsg->dm.connClose.reason);
|
||||
|
||||
amvoleClose(pMsg);
|
||||
uiEvent = APP_UI_CONN_CLOSE;
|
||||
|
||||
// AppAdvStart(APP_MODE_DISCOVERABLE);
|
||||
|
||||
g_AmaConnId = DM_CONN_ID_NONE;
|
||||
//g_eAmaStatus = VOS_AMA_INIT;
|
||||
break;
|
||||
|
||||
case DM_CONN_UPDATE_IND:
|
||||
voles_proc_msg(&pMsg->hdr);
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_CMPL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_CMPL;
|
||||
break;
|
||||
|
||||
case DM_SEC_PAIR_FAIL_IND:
|
||||
DmSecGenerateEccKeyReq();
|
||||
uiEvent = APP_UI_SEC_PAIR_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT;
|
||||
break;
|
||||
|
||||
case DM_SEC_ENCRYPT_FAIL_IND:
|
||||
uiEvent = APP_UI_SEC_ENCRYPT_FAIL;
|
||||
break;
|
||||
|
||||
case DM_SEC_AUTH_REQ_IND:
|
||||
AppHandlePasskey(&pMsg->dm.authReq);
|
||||
break;
|
||||
|
||||
case DM_SEC_ECC_KEY_IND:
|
||||
DmSecSetEccKey(&pMsg->dm.eccMsg.data.key);
|
||||
break;
|
||||
|
||||
case DM_SEC_COMPARE_IND:
|
||||
AppHandleNumericComparison(&pMsg->dm.cnfInd);
|
||||
break;
|
||||
|
||||
case DM_PRIV_CLEAR_RES_LIST_IND:
|
||||
APP_TRACE_INFO1("Clear resolving list status 0x%02x", pMsg->hdr.status);
|
||||
break;
|
||||
|
||||
case DM_HW_ERROR_IND:
|
||||
uiEvent = APP_UI_HW_ERROR;
|
||||
break;
|
||||
|
||||
case DM_VENDOR_SPEC_CMD_CMPL_IND:
|
||||
{
|
||||
#if defined(AM_PART_APOLLO) || defined(AM_PART_APOLLO2)
|
||||
|
||||
uint8_t *param_ptr = &pMsg->dm.vendorSpecCmdCmpl.param[0];
|
||||
|
||||
switch (pMsg->dm.vendorSpecCmdCmpl.opcode)
|
||||
{
|
||||
case 0xFC20: //read at address
|
||||
{
|
||||
uint32_t read_value;
|
||||
|
||||
BSTREAM_TO_UINT32(read_value, param_ptr);
|
||||
|
||||
APP_TRACE_INFO3("VSC 0x%0x complete status %x param %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status,
|
||||
read_value);
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
APP_TRACE_INFO2("VSC 0x%0x complete status %x",
|
||||
pMsg->dm.vendorSpecCmdCmpl.opcode,
|
||||
pMsg->hdr.status);
|
||||
break;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (uiEvent != APP_UI_NONE)
|
||||
{
|
||||
AppUiAction(uiEvent);
|
||||
}
|
||||
}
|
||||
|
||||
void amvoleStartSendVoiceData()
|
||||
{
|
||||
g_start_voice_send = TRUE;
|
||||
am_app_led_on();
|
||||
voles_transmit_voice_data();
|
||||
}
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn VoleHandlerInit
|
||||
*
|
||||
* \brief Application handler init function called during system initialization.
|
||||
*
|
||||
* \param handlerID WSF handler ID.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleHandlerInit(wsfHandlerId_t handlerId)
|
||||
{
|
||||
APP_TRACE_INFO0("VoleHandlerInit");
|
||||
|
||||
/* store handler ID */
|
||||
amvoleHandlerId = handlerId;
|
||||
|
||||
/* Set configuration pointers */
|
||||
pAppAdvCfg = (appAdvCfg_t *) &amvoleAdvCfg;
|
||||
pAppSlaveCfg = (appSlaveCfg_t *) &amvoleSlaveCfg;
|
||||
pAppSecCfg = (appSecCfg_t *) &amvoleSecCfg;
|
||||
pAppUpdateCfg = (appUpdateCfg_t *) &amvoleUpdateCfg;
|
||||
|
||||
/* Initialize application framework */
|
||||
AppSlaveInit();
|
||||
AppServerInit();
|
||||
|
||||
/* Set stack configuration pointers */
|
||||
pSmpCfg = (smpCfg_t *) &amvoleSmpCfg;
|
||||
//voles_init(handlerId);
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn VoleHandler
|
||||
*
|
||||
* \brief WSF event handler for application.
|
||||
*
|
||||
* \param event WSF event mask.
|
||||
* \param pMsg WSF message.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
|
||||
{
|
||||
if (pMsg != NULL)
|
||||
{
|
||||
APP_TRACE_INFO1("vole got evt 0x%x", pMsg->event);
|
||||
|
||||
/* process ATT messages */
|
||||
if (pMsg->event >= ATT_CBACK_START && pMsg->event <= ATT_CBACK_END)
|
||||
{
|
||||
/* process server-related ATT messages */
|
||||
AppServerProcAttMsg(pMsg);
|
||||
}
|
||||
/* process DM messages */
|
||||
else if (pMsg->event >= DM_CBACK_START && pMsg->event <= DM_CBACK_END)
|
||||
{
|
||||
/* process advertising and connection-related messages */
|
||||
AppSlaveProcDmMsg((dmEvt_t *) pMsg);
|
||||
|
||||
/* process security-related messages */
|
||||
AppSlaveSecProcDmMsg((dmEvt_t *) pMsg);
|
||||
}
|
||||
|
||||
/* perform profile and user interface-related operations */
|
||||
amvoleProcMsg((amvoleMsg_t *) pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
/*************************************************************************************************/
|
||||
/*!
|
||||
* \fn VoleStart
|
||||
*
|
||||
* \brief Start the application.
|
||||
*
|
||||
* \return None.
|
||||
*/
|
||||
/*************************************************************************************************/
|
||||
void VoleStart(void)
|
||||
{
|
||||
/* Register for stack callbacks */
|
||||
DmRegister(amvoleDmCback);
|
||||
DmConnRegister(DM_CLIENT_ID_APP, amvoleDmCback);
|
||||
AttRegister(amvoleAttCback);
|
||||
AttConnRegister(AppServerConnCback);
|
||||
AttsCccRegister(VOLES_NUM_CCC_IDX, (attsCccSet_t *) amvoleCccSet, amvoleCccCback);
|
||||
|
||||
/* Register for app framework callbacks */
|
||||
AppUiBtnRegister(amvoleBtnCback);
|
||||
|
||||
// set up adv data
|
||||
memcpy(amvoleAdvDataDisc, amvoleAdvDataDiscDefault, sizeof(amvoleAdvDataDiscDefault));
|
||||
memcpy(amvoleScanDataDisc, amvoleScanDataDiscDefault, sizeof(amvoleScanDataDiscDefault));
|
||||
|
||||
/* Initialize attribute server database */
|
||||
SvcCoreGattCbackRegister(GattReadCback, GattWriteCback);
|
||||
SvcCoreAddGroup();
|
||||
SvcDisAddGroup();
|
||||
SvcVolesCbackRegister(NULL, amvole_write_cback);
|
||||
SvcVolesAddGroup();
|
||||
|
||||
/* Set Service Changed CCCD index. */
|
||||
GattSetSvcChangedIdx(VOLES_GATT_SC_CCC_IDX);
|
||||
/* Reset the device */
|
||||
DmDevReset();
|
||||
}
|
||||
Reference in New Issue
Block a user