/*************************************************************************************************/ /*! * \file * * \brief Wireless Data Exchange profile implementation. * * Copyright (c) 2013-2018 Arm Ltd. * * Copyright (c) 2019 Packetcraft, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /*************************************************************************************************/ #include #include "wsf_types.h" #include "util/wstr.h" #include "wsf_trace.h" #include "wsf_assert.h" #include "wsf_efs.h" #include "wsf_os.h" #include "sec_api.h" #include "util/bstream.h" #include "svc_wdxs.h" #include "wdxs_api.h" #include "wdxs_main.h" #include "dm_api.h" #include "att_api.h" #include "app_api.h" /************************************************************************************************** Global Variables **************************************************************************************************/ /*! application control block */ wdxsCb_t wdxsCb; /************************************************************************************************** Macros **************************************************************************************************/ /*! RAM File Media Configuration */ #define WDXS_RAM_LOCATION ((uint32_t)WdxsRamBlock) #define WDXS_RAM_SIZE (WDX_FLIST_MAX_LEN + WDXS_APP_RAM_MEDIA_SIZE) #define WDXS_RAM_END (WDXS_RAM_LOCATION + WDXS_RAM_SIZE) /************************************************************************************************** Local Function Prototypes **************************************************************************************************/ static uint8_t WdxsRamErase(uint32_t address, uint32_t size); static uint8_t WdxsRamRead(uint8_t *pBuf, uint32_t address, uint32_t size); static uint8_t WdxsRamWrite(const uint8_t *pBuf, uint32_t address, uint32_t size); /************************************************************************************************** Function Prototypes **************************************************************************************************/ void WdxsAuSecComplete(secAes_t *pAes); /************************************************************************************************** Local Variables **************************************************************************************************/ /*! Reserve RAM for use by the RAM EFS Media */ static uint8_t WdxsRamBlock[WDXS_RAM_SIZE]; /*! EFS RAM Media Control Block */ static const wsfEfsMedia_t WDXS_RamMediaCtrl = { WDXS_RAM_LOCATION, WDXS_RAM_LOCATION + WDXS_RAM_SIZE, 1, NULL, WdxsRamErase, WdxsRamRead, WdxsRamWrite, NULL }; /*************************************************************************************************/ /*! * \brief Erase function for the EFS RAM media. * * \return none. * */ /*************************************************************************************************/ static uint8_t WdxsRamErase(uint32_t address, uint32_t size) { uint8_t *pMem = (uint8_t *) address; memset(pMem, 0xFF, size); return TRUE; } /*************************************************************************************************/ /*! * \brief Read function for the EFS RAM media. * * \return none. * */ /*************************************************************************************************/ static uint8_t WdxsRamRead(uint8_t *pBuf, uint32_t address, uint32_t size) { uint8_t *pMem = (uint8_t *) address; memcpy(pBuf, pMem, size); return TRUE; } /*************************************************************************************************/ /*! * \brief Write function for the EFS RAM media. * * \return none. * */ /*************************************************************************************************/ static uint8_t WdxsRamWrite(const uint8_t *pBuf, uint32_t address, uint32_t size) { uint8_t *pMem = (uint8_t *) address; memcpy(pMem, pBuf, size); return TRUE; } /*************************************************************************************************/ /*! * \brief Format file list information for the given file. * * \return none. */ /*************************************************************************************************/ static void wdxsFormatFileResource(uint8_t *pData, wsfEfsHandle_t handle) { UINT16_TO_BSTREAM(pData, handle); UINT8_TO_BSTREAM(pData, WsfEfsGetFileType(handle)); UINT8_TO_BSTREAM(pData, WsfEfsGetFilePermissions(handle) & WSF_EFS_REMOTE_PERMISSIONS_MASK); UINT32_TO_BSTREAM(pData, WsfEfsGetFileSize(handle)); WstrnCpy((char *)pData, WsfEfsGetFileName(handle), WSF_EFS_NAME_LEN); WstrnCpy((char *)pData+WSF_EFS_NAME_LEN, WsfEfsGetFileVersion(handle), WSF_EFS_VERSION_LEN); } /*************************************************************************************************/ /*! * \brief Create the file list. * * \return none. */ /*************************************************************************************************/ void WdxsUpdateListing(void) { uint8_t *pTmp; uint8_t header[WDX_FLIST_HDR_SIZE]; uint8_t record[WDX_FLIST_RECORD_SIZE]; uint32_t position = 0, totalSize = 0; uint32_t fileCount = 0; uint8_t i; position = WDX_FLIST_HDR_SIZE; for (i=0; ihdr.event) { case DM_CONN_CLOSE_IND: if (wdxsDcCb.doReset) { WdxsResetSystem(); } break; case DM_CONN_OPEN_IND: /* Initialize connection parameters */ wdxsCb.txReadyMask = WDXS_TX_MASK_READY_BIT; wdxsCb.ftInProgress = WDX_FTC_OP_NONE; wdxsCb.ftLen = 0; wdxsCb.ftOffset = 0; #if WDXS_AU_ENABLED == TRUE wdxsAuCb.authLevel = WDX_AU_LVL_NONE; wdxsAuCb.authState = WDXS_AU_STATE_UNAUTHORIZED; #endif /* WDXS_AU_ENABLED */ wdxsCb.connInterval = pEvt->connOpen.connInterval; wdxsCb.connLatency = pEvt->connOpen.connLatency; wdxsCb.supTimeout = pEvt->connOpen.supTimeout; wdxsCb.txPhy= HCI_PHY_LE_1M_BIT; wdxsCb.rxPhy = HCI_PHY_LE_1M_BIT; break; case DM_CONN_UPDATE_IND: if (pEvt->hdr.status == HCI_SUCCESS) { wdxsCb.connInterval = pEvt->connUpdate.connInterval; wdxsCb.connLatency = pEvt->connUpdate.connLatency; wdxsCb.supTimeout = pEvt->connUpdate.supTimeout; } wdxsDcUpdateConnParam((dmConnId_t) pEvt->hdr.param, pEvt->hdr.status); break; case DM_PHY_UPDATE_IND: if (pEvt->hdr.status == HCI_SUCCESS) { wdxsCb.txPhy = pEvt->phyUpdate.txPhy; wdxsCb.rxPhy = pEvt->phyUpdate.rxPhy; } wdxsDcUpdatePhy((dmConnId_t) pEvt->hdr.param, pEvt->hdr.status); break; default: break; } } /*************************************************************************************************/ /*! * \brief Called by application to notify the WDXS of ATT Events. * * \param pEvt Pointer to the ATT Event * * \return None. */ /*************************************************************************************************/ uint8_t WdxsAttCback(attEvt_t *pEvt) { if (pEvt->handle < WDXS_START_HDL || pEvt->handle > WDXS_END_HDL) { return FALSE; } APP_TRACE_INFO2("WDXS: AttHook handle=%d event=%d", pEvt->handle, pEvt->hdr.event); /* trigger tx data path on confirm */ if (pEvt->hdr.event == ATTS_HANDLE_VALUE_CNF && pEvt->hdr.status == ATT_SUCCESS) { wdxsCb.txReadyMask |= WDXS_TX_MASK_READY_BIT; WsfSetEvent(wdxsCb.handlerId, WDXS_EVT_TX_PATH); } return TRUE; } /*************************************************************************************************/ /*! * \brief Application handler init function called during system initialization. * * \param handlerID WSF handler ID. * * \return None. */ /*************************************************************************************************/ void WdxsHandlerInit(wsfHandlerId_t handlerId) { wsfEsfAttributes_t attr; APP_TRACE_INFO0("WDXS: WdxsHandlerInit"); /* Initialize the control block */ memset(&wdxsCb, 0, sizeof(wdxsCb)); wdxsCb.txReadyMask = WDXS_TX_MASK_READY_BIT; /* Store Handler ID */ wdxsCb.handlerId = handlerId; /* Initialize the device configuration control block */ memset(&wdxsDcCb, 0, sizeof(wdxsDcCb)); /* Register the WDXS Service */ SvcWdxsRegister(wdxsWriteCback); SvcWdxsAddGroup(); /* Initialize the embedded file system */ WsfEfsInit(); /* Register the RAM Media */ memset(WdxsRamBlock, 0xFF, sizeof(WdxsRamBlock)); WsfEfsRegisterMedia(&WDXS_RamMediaCtrl, WDX_RAM_MEDIA); /* Set attributes for the WDXS File List */ attr.type = WSF_EFS_FILE_TYPE_BULK; attr.permissions = WSF_EFS_LOCAL_PUT_PERMITTED | WSF_EFS_REMOTE_GET_PERMITTED; WstrnCpy(attr.name, "Listing", WSF_EFS_NAME_LEN); WstrnCpy(attr.version, "1.0", WSF_EFS_VERSION_LEN); /* Create a file in RAM to contain the list WDXS File List */ WsfEfsAddFile(WDX_FLIST_MAX_LEN, WDX_RAM_MEDIA, &attr, WSF_EFS_FILE_OFFSET_ANY); } /*************************************************************************************************/ /*! * \fn WdxsOtaMediaInit * * \brief Registers the platform dependent OTA Media with the Embedded File System (EFS) * * \param None * * \return None. */ /*************************************************************************************************/ void WdxsOtaMediaInit(void) { } /*************************************************************************************************/ /*! * \fn WdxsResetSystem * * \brief Resets the system. * * \param None * * \return None. */ /*************************************************************************************************/ void WdxsResetSystem(void) { } /*************************************************************************************************/ /*! * \fn WdxsFlashMediaInit * * \brief Registers the platform dependent Flash Media with the Embedded File System (EFS) * * \param None * * \return None. */ /*************************************************************************************************/ void WdxsFlashMediaInit(void) { }