Commit 8cbb35f2 authored by schneider's avatar schneider

feat(sdk): Update evkit examples (0.2.1-11)

parent 2f58b603
......@@ -199,7 +199,6 @@ PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
......@@ -213,6 +212,7 @@ PROJ_CFLAGS+=-DINIT_BROADCASTER
# PROJ_CFLAGS+=-DINIT_CENTRAL
PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
PROJ_CFLAGS+=-DINIT_PHY
ENABLE_LL_TESTER?=#1
......
......@@ -90,16 +90,10 @@ static wsfBufPoolDesc_t mainPoolDesc[WSF_BUF_POOLS] =
/*! \brief Stack initialization for app. */
extern void StackInitBeacon(void);
/*************************************************************************************************/
void PalSysAssertTrap(void)
{
while(1) {}
}
/*************************************************************************************************/
void SysTick_Handler(void)
{
WsfTimerUpdate(1);
WsfTimerUpdate(WSF_MS_PER_TICK);
}
/*************************************************************************************************/
......
......@@ -43,6 +43,12 @@ ifeq "$(PROJECT)" ""
PROJECT=max32665
endif
# Build directory for image that peer will be udpated with
FW_UPDATE_DIR=../BLE_dats
# Firmware update files, do not rename
FW_UPDATE_BIN=fw_update.bin
# Specify the target processor
ifeq "$(TARGET)" ""
TARGET=MAX32665
......@@ -72,6 +78,7 @@ endif
# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
NDALIBS_DIR=../../../NDALibraries
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Firmware/$(TARGET_UC)/Libraries)
endif
......@@ -176,6 +183,30 @@ PROJ_CFLAGS+=-DCONSOLE_UART=$(CONSOLE_UART)
endif
endif
ifdef ENABLE_WDX
ifneq "$(ENABLE_WDX)" ""
ifneq "$(ENABLE_WDX)" "0"
PROJ_CFLAGS+=-DWDXC_INCLUDED=TRUE
PROJ_CFLAGS+=-DWDXS_INCLUDED=TRUE
# PROJ_CFLAGS+=-DWSF_TRACE_ENABLED=TRUE
# Include bin file for firmware update image
BINS+=${FW_UPDATE_BIN}
# Target for creating the fw_update bin file
${FW_UPDATE_BIN}:
$(MAKE) -C ${FW_UPDATE_DIR}
$(MAKE) -C ${FW_UPDATE_DIR} build/${PROJECT}.bin
@cp ${FW_UPDATE_DIR}/build/${PROJECT}.bin ${FW_UPDATE_BIN}
myclean:
@rm -f ${FW_UPDATE_BIN}
clean: myclean
endif
endif
endif
ifdef ENABLE_SDMA
ifneq "$(ENABLE_SDMA)" ""
ifeq "$(ENABLE_SDMA)" "0"
......@@ -214,7 +245,6 @@ PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE=TRUE
PROJ_CFLAGS+=-DWSF_ASSERT_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_TRACE_ENABLED=TRUE
# PROJ_CFLAGS+=-DLL_DBG_PIN_ENABLED=TRUE
PROJ_CFLAGS+=-DWSF_MS_PER_TICK=1
#--------------------
......@@ -228,6 +258,7 @@ PROJ_CFLAGS+=-DINIT_OBSERVER
PROJ_CFLAGS+=-DINIT_CENTRAL
# PROJ_CFLAGS+=-DINIT_PERIPHERAL
PROJ_CFLAGS+=-DINIT_ENCRYPTED
PROJ_CFLAGS+=-DINIT_PHY
ENABLE_LL_TESTER?=#1
......
......@@ -15,3 +15,6 @@ BTLE_APP_ENABLE_WHITELIST?=0
# Run link layer using SDMA.
ENABLE_SDMA?=0
# Enable file transfer profile
ENABLE_WDX?=0
......@@ -38,11 +38,20 @@
#include "app_ui.h"
#include "svc_core.h"
#include "svc_ch.h"
#include "hci_vs.h"
#include "gatt/gatt_api.h"
#include "wpc/wpc_api.h"
#include "datc/datc_api.h"
#include "util/calc128.h"
#include "gcr_regs.h"
#include "ll_defs.h"
#include "tmr_utils.h"
#if WDXC_INCLUDED == TRUE
#include "wsf_efs.h"
#include "wdxc/wdxc_api.h"
#include "wdx_defs.h"
#include "hash.h"
#endif /* WDXC_INCLUDED */
/**************************************************************************************************
Macros
......@@ -50,6 +59,37 @@ Macros
#define TEST_TIMER_IND 0x99
#if WDXC_INCLUDED == TRUE
/* Size of WDXC file discovery dataset */
#define DATC_WDXC_MAX_FILES 4
/*! WSF message event starting value */
#define DATC_MSG_START 0xA0
/*! Data rate timer period in seconds */
#define DATC_WDXS_DATA_RATE_TIMEOUT 4
/* Pointer for accessing the fw_update image*/
uint8_t *fileData;
extern uint32_t _binary_fw_update_bin_start;
extern uint32_t _binary_fw_update_bin_end;
extern uint32_t _binary_fw_update_bin_size;
#define FILE_SIZE (uint32_t)&_binary_fw_update_bin_size
#define BLOCK_OFFSET_INIT 0x0
#define BLOCK_SIZE 224
#define SHA256_BYTES (256/8)
char fileHashDigest[SHA256_BYTES];
/*! WSF message event enumeration */
enum
{
DATC_WDXS_DATA_RATE_TIMER_IND = DATC_MSG_START, /*! Data rate timer expired */
};
#endif /* WDXC_INCLUDED */
/**************************************************************************************************
Local Variables
**************************************************************************************************/
......@@ -63,6 +103,13 @@ struct
bool_t autoConnectSync; /*! TRUE if auto-connecting */
uint8_t discState[DM_CONN_MAX]; /*! Service discovery state */
uint8_t hdlListLen; /*! Cached handle list length */
uint8_t btnConnId; /*! The index of the connection ID for button presses */
#if WDXC_INCLUDED == TRUE
bool_t sendingFile[DM_CONN_MAX];
bool_t fileVerified[DM_CONN_MAX];
uint32_t blockOffset[DM_CONN_MAX];
wsfEfsFileInfo_t fileList[DM_CONN_MAX][DATC_WDXC_MAX_FILES]; /* Buffer to hold WDXC file list */
#endif /* WDXC_INCLUDED */
} datcCb;
/*! connection control block */
......@@ -206,7 +253,7 @@ static const hciConnSpec_t datcConnCfg =
0, /*! Connection latency */
600, /*! Supervision timeout in 10ms units */
0, /*! Minimum CE length, in 0.625 ms units */
16 /*! Maximum CE length, in 0.625 ms units */
0 /*! Maximum CE length, in 0.625 ms units */
};
/*! Configurable parameters for service and characteristic discovery */
......@@ -225,8 +272,12 @@ static const appCfg_t datcAppCfg =
static const attCfg_t datcAttCfg =
{
15, /* ATT server service discovery connection idle timeout in seconds */
300, /* desired ATT MTU */
ATT_MAX_TRANS_TIMEOUT, /* transaction timeout in seconds */
#if WDXC_INCLUDED == TRUE
241, /* desired ATT MTU */
#else
23, /* desired ATT MTU */
#endif /* WDXC_INCLUDED */
ATT_MAX_TRANS_TIMEOUT, /* transcation timeout in seconds */
4 /* number of queued prepare writes supported by server */
};
......@@ -246,6 +297,9 @@ enum
DATC_DISC_GATT_SVC, /*! GATT service */
DATC_DISC_GAP_SVC, /*! GAP service */
DATC_DISC_WP_SVC, /*! ARM Ltd. proprietary service */
#if WDXC_INCLUDED == TRUE
DATC_DISC_WDXC_SCV, /*! ARM Ltd. Wireless Data Exchange service */
#endif /* WDXC_INCLUDED */
DATC_DISC_SVC_MAX /*! Discovery complete */
};
......@@ -269,12 +323,20 @@ enum
#define DATC_DISC_GATT_START 0
#define DATC_DISC_GAP_START (DATC_DISC_GATT_START + GATT_HDL_LIST_LEN)
#define DATC_DISC_WP_START (DATC_DISC_GAP_START + GAP_HDL_LIST_LEN)
#if WDXC_INCLUDED == TRUE
#define DATC_DISC_WDXC_START (DATC_DISC_WP_START + WPC_P1_HDL_LIST_LEN)
#define DATC_DISC_HDL_LIST_LEN (DATC_DISC_WDXC_START + WDXC_HDL_LIST_LEN)
#else
#define DATC_DISC_HDL_LIST_LEN (DATC_DISC_WP_START + WPC_P1_HDL_LIST_LEN)
#endif /* WDXC_INCLUDED */
/*! Pointers into handle list for each service's handles */
static uint16_t *pDatcGattHdlList[DM_CONN_MAX];
static uint16_t *pDatcGapHdlList[DM_CONN_MAX];
static uint16_t *pDatcWpHdlList[DM_CONN_MAX];
#if WDXC_INCLUDED == TRUE
static uint16_t *pDatcWdxHdlList[DM_CONN_MAX];
#endif /* WDXC_INCLUDED */
/* LESC OOB configuration */
static dmSecLescOobCfg_t *datcOobCfg;
......@@ -301,6 +363,14 @@ static const attcDiscCfg_t datcDiscCfgList[] =
/* Write: Proprietary data service changed ccc descriptor */
{datcCccNtfVal, sizeof(datcCccNtfVal), (WPC_P1_NA_CCC_HDL_IDX + DATC_DISC_WP_START)},
#if WDXC_INCLUDED == TRUE
/* Write: WDXC ccc descriptors */
{datcCccNtfVal, sizeof(datcCccNtfVal), (WDXC_DC_CCC_HDL_IDX + DATC_DISC_WDXC_START)},
{datcCccNtfVal, sizeof(datcCccNtfVal), (WDXC_FTC_CCC_HDL_IDX + DATC_DISC_WDXC_START)},
{datcCccNtfVal, sizeof(datcCccNtfVal), (WDXC_FTD_CCC_HDL_IDX + DATC_DISC_WDXC_START)},
{datcCccNtfVal, sizeof(datcCccNtfVal), (WDXC_AU_CCC_HDL_IDX + DATC_DISC_WDXC_START)},
#endif /* WDXC_INCLUDED */
};
/* Characteristic configuration list length */
......@@ -655,12 +725,6 @@ static void datcExtScanReport(dmEvt_t *pMsg)
pMsg->extScanReport.directAddr[0]);
}
//printf(" priPhy %u,", pMsg->extScanReport.priPhy);
//printf(" secPhy %u,", pMsg->extScanReport.secPhy);
//printf(" advSid 0x%02x,", pMsg->extScanReport.advSid);
//printf(" txPower %i,", pMsg->extScanReport.txPower);
//printf(" perAdvInter %i,", pMsg->extScanReport.perAdvInter);
//printf(" directAddrType %x,", pMsg->extScanReport.directAddrType);
printf(" len %u, rssi %d, evtType %x, addrType %x", pMsg->extScanReport.len, pMsg->extScanReport.rssi, pMsg->extScanReport.eventType, pMsg->extScanReport.addrType);
/* search for the friendly name. */
......@@ -954,8 +1018,10 @@ static void datcClose(dmEvt_t *pMsg)
/*************************************************************************************************/
static void datcValueNtf(attEvt_t *pMsg)
{
#if WDXC_INCLUDED == FALSE
/* print the received data */
printf("%s\n", pMsg->pValue);
#endif /* WDXC_INCLUDED */
}
/*************************************************************************************************/
......@@ -1019,6 +1085,137 @@ static void datcDiscGapCmpl(dmConnId_t connId)
}
}
#if WDXC_INCLUDED == TRUE
/*************************************************************************************************/
/*!
* \brief WDXC File Transfer Data Callback.
*
* \param connId Connection ID.
* \param fileHdl Handle of the file.
* \param len length of pData in bytes.
* \param pData File data.
*
* \return None.
*/
/*************************************************************************************************/
static void datcWdxcFtdCallback(dmConnId_t connId, uint16_t fileHdl, uint16_t len, uint8_t *pData)
{
}
/*************************************************************************************************/
/*!
* \brief WDXC File Transfer Control Callback.
*
* \param connId Connection ID.
* \param op Control operation.
* \param status Status of operation.
*
* \return None.
*/
/*************************************************************************************************/
static void datcWdxcFtcCallback(dmConnId_t connId, uint16_t handle, uint8_t op, uint8_t status)
{
if(status != WDX_FTC_ST_SUCCESS) {
APP_TRACE_INFO1("Error with FTC Operation status: %d", status);
}
if (op == WDX_FTC_OP_PUT_RSP)
{
/* Start timer */
printf(">>> Starting file transfer <<<\n");
TMR_SW_Start(MXC_TMR1, NULL);
datcCb.sendingFile[connId - 1] = TRUE;
WdxcFtdSendBlock(connId, BLOCK_SIZE, (uint8_t*)&fileData[datcCb.blockOffset[connId - 1] - BLOCK_OFFSET_INIT]);
datcCb.blockOffset[connId - 1] += BLOCK_SIZE;
}
else if (op == WDX_FTC_OP_EOF)
{
if(handle == WDX_FLIST_HANDLE) {
/* File discovery complete */
printf(">>> File discovery complete <<<\n");
} else {
/* Stop timer, calculate time and Bps */
uint32_t usec = TMR_SW_Stop(MXC_TMR1);
printf(">>> File transfer complete %d us <<<\n", usec);
printf("file_size = %d usec = %d Bps = %d\n", FILE_SIZE, usec, ((FILE_SIZE*1000)/(usec / 1000)));
datcCb.sendingFile[connId - 1] = FALSE;
}
} else if (op == WDX_FTC_OP_VERIFY_RSP) {
printf(">>> Verify complete status: %d <<<\n", status);
datcCb.fileVerified[connId - 1] = TRUE;
}
}
#endif /* WDXC_INCLUDED */
/*************************************************************************************************/
/*!
* \brief Button press callback.
*
* \param btn Button press.
*
* \return None.
*/
/*************************************************************************************************/
static void datcBtnCback(uint8_t btn)
{
#if WDXC_INCLUDED == TRUE
dmConnId_t connIdList[DM_CONN_MAX];
uint8_t numConnections = AppConnOpenList(connIdList);
dmConnId_t connId = datcCb.btnConnId;
/* button actions when connected */
if (numConnections > 0)
{
switch (btn)
{
case APP_UI_BTN_2_MED:
if ((datcCb.discState[connId - 1] > DATC_DISC_WDXC_SCV) &&
(datcCb.sendingFile[connId - 1] == FALSE))
{
/* Start the WDXC data stream */
datcCb.blockOffset[connId - 1] = BLOCK_OFFSET_INIT;
WdxcFtcSendPutReq(connId, datcCb.fileList[connId - 1][0].handle, BLOCK_OFFSET_INIT, FILE_SIZE+SHA256_BYTES,
BLOCK_OFFSET_INIT+FILE_SIZE+SHA256_BYTES, 0);
}
break;
case APP_UI_BTN_2_SHORT:
if (datcCb.discState[connId - 1] > DATC_DISC_WDXC_SCV)
{
WdxcDiscoverFiles(connId, datcCb.fileList[connId - 1], DATC_WDXC_MAX_FILES);
}
break;
case APP_UI_BTN_2_LONG:
if (datcCb.discState[connId - 1] > DATC_DISC_WDXC_SCV)
{
/* Send verification request */
WdxcFtcSendVerifyFile(connId, datcCb.fileList[connId - 1][0].handle);
}
break;
case APP_UI_BTN_2_EX_LONG:
if (datcCb.fileVerified[connId - 1])
{
/* Send Disconnect and Reset request to apply firmware update */
WdxcDcSendDisconnectAndReset(connId);
datcCb.fileVerified[connId - 1] = FALSE;
}
break;
default:
break;
}
}
#endif /* WDXC_INCLUDED */
}
/*************************************************************************************************/
/*!
* \brief Discovery callback.
......@@ -1077,6 +1274,12 @@ static void datcDiscCback(dmConnId_t connId, uint8_t status)
/* discover proprietary data service */
WpcP1Discover(connId, pDatcWpHdlList[connId-1]);
}
#if WDXC_INCLUDED == TRUE
else if (datcCb.discState[connId-1] == DATC_DISC_WDXC_SCV)
{
WdxcWdxsDiscover(connId, pDatcWdxHdlList[connId-1]);
}
#endif /* WDXC_INCLUDED */
else
{
/* discovery complete */
......@@ -1088,6 +1291,9 @@ static void datcDiscCback(dmConnId_t connId, uint8_t status)
/* start configuration */
AppDiscConfigure(connId, APP_DISC_CFG_START, DATC_DISC_CFG_LIST_LEN,
(attcDiscCfg_t *) datcDiscCfgList, DATC_DISC_HDL_LIST_LEN, datcCb.hdlList[connId-1]);
/* Update the data length */
DmConnSetDataLen(connId, LL_MAX_DATA_LEN_ABS_MAX, LL_MAX_DATA_TIME_ABS_MAX_1M);
}
break;
......@@ -1155,30 +1361,40 @@ static void testTimerHandler(void)
{
datcSendData(testCb.connId);
DmConnReadRssi(testCb.connId);
HciVsGetConnStats();
}
if ((((testCb.counter - testCb.connectCount) % 10) == 0) &&
(testCb.connId != DM_CONN_ID_NONE) &&
(datcCb.discState[testCb.connId-1] == DATC_DISC_SVC_MAX))
{
if(testCb.phy == HCI_PHY_LE_2M_BIT) {
/* Change from 1M to 2M PHY */
testCb.phy = HCI_PHY_LE_1M_BIT;
} else if (testCb.phy == HCI_PHY_LE_1M_BIT) {
/* Change to the coded PHY if we're not using A1 */
if(MXC_GCR->revision != 0xA1) {
testCb.phy = HCI_PHY_LE_CODED_BIT;
#if WDXC_INCLUDED == TRUE
if(datcCb.sendingFile[testCb.connId-1] != TRUE) {
#endif
if(testCb.phy == HCI_PHY_LE_2M_BIT) {
/* Change from 1M to 2M PHY */
testCb.phy = HCI_PHY_LE_1M_BIT;
} else if (testCb.phy == HCI_PHY_LE_1M_BIT) {
/* Change to the coded PHY if we're not using A1 */
if(MXC_GCR->revision != 0xA1) {
testCb.phy = HCI_PHY_LE_CODED_BIT;
} else {
testCb.phy = HCI_PHY_LE_2M_BIT;
}
} else {
/* Change to 2M PHY */
testCb.phy = HCI_PHY_LE_2M_BIT;
}
} else {
/* Change to 2M PHY */
testCb.phy = HCI_PHY_LE_2M_BIT;
}
DmSetPhy(testCb.connId, 0, testCb.phy, testCb.phy, 0);
DmSetPhy(testCb.connId, 0, testCb.phy, testCb.phy, 0);
#if WDXC_INCLUDED == TRUE
}
#endif
}
WsfTimerStartMs(&testCb.timer, 1000);
......@@ -1204,7 +1420,50 @@ static void datcProcMsg(dmEvt_t *pMsg)
break;
case ATTC_WRITE_CMD_RSP:
{
#if WDXC_INCLUDED == TRUE
dmConnId_t connId = (dmConnId_t) pMsg->hdr.param;
if ((((attEvt_t *) pMsg)->hdr.status == ATT_SUCCESS) &&
(((attEvt_t *) pMsg)->handle == pDatcWdxHdlList[connId-1][WDXC_FTD_HDL_IDX])) {
if(datcCb.sendingFile[connId - 1] == TRUE) {
APP_TRACE_INFO1("blockOffset = 0x%x", datcCb.blockOffset[connId - 1]);
if(datcCb.blockOffset[connId - 1] >= FILE_SIZE) {
uint32_t blockSize;
if((datcCb.blockOffset[connId - 1] + BLOCK_SIZE) > (FILE_SIZE + SHA256_BYTES)) {
blockSize = FILE_SIZE + SHA256_BYTES - datcCb.blockOffset[connId - 1];
} else {
blockSize = BLOCK_SIZE;
}
/* Write the hash digest */
WdxcFtdSendBlock(connId, blockSize, (uint8_t*)&fileHashDigest[datcCb.blockOffset[connId - 1] - FILE_SIZE]);
datcCb.blockOffset[connId - 1] += blockSize;
} else {
uint32_t blockSize;
if((datcCb.blockOffset[connId - 1] + BLOCK_SIZE) > FILE_SIZE) {
blockSize = FILE_SIZE - datcCb.blockOffset[connId - 1];
} else {
blockSize = BLOCK_SIZE;
}
/* Keep writing the file */
WdxcFtdSendBlock(connId, blockSize, (uint8_t*)&fileData[datcCb.blockOffset[connId - 1] - BLOCK_OFFSET_INIT]);
datcCb.blockOffset[connId - 1] += blockSize;
}
}
}
#endif
break;
}
case ATTC_WRITE_RSP:
break;
case DM_RESET_CMPL_IND:
DmSecGenerateEccKeyReq();
......@@ -1383,6 +1642,7 @@ void DatcHandlerInit(wsfHandlerId_t handlerId)
/* set handle list length */
datcCb.hdlListLen = DATC_DISC_HDL_LIST_LEN;
datcCb.btnConnId = 1;
/* Set configuration pointers */
#ifdef BTLE_APP_USE_LEGACY_API
pAppMasterCfg = (appMasterCfg_t *) &datcMasterCfg;
......@@ -1401,6 +1661,26 @@ void DatcHandlerInit(wsfHandlerId_t handlerId)
/* Set IRK for the local device */
DmSecSetLocalIrk(localIrk);
#if WDXC_INCLUDED == TRUE
/* Set the pointer for the fw_update image */
fileData = (uint8_t*)&_binary_fw_update_bin_start;
/* Calculate the SHA256 digest */
/* Validate the image with SHA256, digest is last 256 bits of the file */
TPU_Hash_Reset();
TPU_Hash_Config(TPU_HASH_SHA256);
TPU_SHA((const char *)fileData, TPU_HASH_SHA256, FILE_SIZE, fileHashDigest);
TPU_Hash_Shutdown();
int i;
for(i = 0; i < DM_CONN_MAX; i++) {
datcCb.sendingFile[i] = FALSE;
datcCb.fileVerified[i] = FALSE;
datcCb.blockOffset[i] = BLOCK_OFFSET_INIT;
}
#endif
}
/*************************************************************************************************/
......@@ -1417,7 +1697,7 @@ void DatcHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
{
if (pMsg != NULL)
{
if (pMsg->event != TEST_TIMER_IND)
if ((pMsg->event != TEST_TIMER_IND) && (pMsg->event != ATTC_WRITE_RSP))
{
APP_TRACE_INFO2("Datc got evt 0x%x, param %u", pMsg->event, pMsg->param);
}
......@@ -1443,6 +1723,11 @@ void DatcHandler(wsfEventMask_t event, wsfMsgHdr_t *pMsg)
/* perform profile and user interface-related operations */
datcProcMsg((dmEvt_t *) pMsg);
#if WDXC_INCLUDED == TRUE