TI-OpenThread  1.08.02.01
Functions | Variables
CC1352P_4_LAUNCHXL/thread/doorlock_oad_secure/oad/oad.c File Reference
#include <openthread/config.h>
#include <openthread-core-config.h>
#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <openthread/tasklet.h>
#include <openthread/thread.h>
#include <openthread/coap.h>
#include <openthread/platform/logging.h>
#include <openthread/platform/uart.h>
#include <openthread/dataset.h>
#include "otsupport/otrtosapi.h"
#include "otsupport/otinstance.h"
#include "platform/nv/nvintf.h"
#include "platform/nv/nvocmp.h"
#include "ti_drivers_config.h"
#include "images.h"
#include "doorlock.h"
#include "utils/code_utils.h"
#include "disp_utils.h"
#include "otstack.h"
#include <ti/sysbios/knl/Event.h>
#include <ti/sysbios/BIOS.h>
#include <sched.h>
#include <pthread.h>
#include <ti/devices/DeviceFamily.h>
#include <DeviceFamily_constructPath(driverlib/sys_ctrl.h)>
#include <DeviceFamily_constructPath(driverlib/chipinfo.h)>
#include "oad.h"
#include "oad_image_header.h"
#include "oad_storage.h"
#include "flash_interface.h"
#include <ti/sysbios/knl/Queue.h>
+ Include dependency graph for CC1352P_4_LAUNCHXL/thread/doorlock_oad_secure/oad/oad.c:

Functions

void OAD_abort (void)
 Abort OAD module. More...
 
void oad_blockReqHandler (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)
 callback for CoAp img block request More...
 
static void oad_cancelTimer (timer_t timerID)
 
void oad_checkDLComplete (oad_imgBlockReq_t *oadImgBlockReq_p)
 Function to check the validity of the image when the DL is complete. More...
 
void OAD_close (void)
 Close the OAD module. More...
 
static void oad_configureRegistrationTimer (void)
 
static void oad_configureTimeoutTimer (uint32_t timeout)
 Configure the timer. More...
 
uint8_t oad_enqueueMsg (oadEvent_e event, void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otMessage *aResponseMsg)
 
void oad_getFwVersion (char *fwVersionStr)
 Function to build the firmware version string. More...
 
static void oad_handleFwvServer (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 Callback function registered with the Coap server for resource "oad/fwv". More...
 
static void oad_handleNtfServer (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo)
 Callback function registered with the Coap server for resource "oad/ntf". More...
 
uint8_t oad_infoGet (void *p, uint16_t len, uint8_t idx)
 Get OAD NVs. More...
 
uint8_t oad_infoSet (void *p, uint16_t len, uint8_t idx)
 Set OAD NVs. More...
 
void oad_lastImgBlockReq (oad_targetReceive_t *oadWriteEvt, oad_imgBlockReq_t *oadImgBlock_p)
 sends the next block request. More...
 
void OAD_open (void)
 Initialize OAD module. More...
 
void OAD_pause (void)
 Pause OAD module, if valid DL in prog. More...
 
void OAD_processCtrlEvents (appEvent_e event)
 A function to process the OAD periodic ctrl events. More...
 
void oad_processDLComplete (void)
 
void oad_processFwVersion (oad_targetReceive_t *oadWriteEvt)
 Function to send firmware version msg. More...
 
void oad_processImgBlockReq (oad_targetReceive_t *oadWriteEvt, oad_imgBlockReq_t *oadImgBlock_p)
 sends the next block request. More...
 
static uint8_t oad_processNtf (oad_targetReceive_t *oadWriteEvt, oad_imgBlockReq_t *oadImgBlock_p)
 Function to process notification request message and send a response. More...
 
void OAD_processQueue (void)
 A function to process the OAD events. More...
 
void oad_regReqHandler (void *aContext, otMessage *aMessage, const otMessageInfo *aMessageInfo, otError aResult)
 callback for CoAp Registration request More...
 
static void oad_regTimeoutCB (union sigval val)
 Callback function periodic registration timer event. More...
 
void OAD_resume (void)
 Resume OAD module. More...
 
void oad_sendRegMsg (void)
 Function to send broadcast register msg. More...
 
void oad_sendReqMsg (oad_targetReceive_t *oadWriteEvt, otCoapType coapType, otCoapCode coapCode, const char *uriPath, otCoapResponseHandler handler)
 Function to send CoAP request message. More...
 
void oad_sendRspMsg (oad_targetReceive_t *oadWriteEvt, uint8_t *pData, uint16_t len)
 Function to send broadcast register msg. More...
 
void oad_settingsNVInit (void)
 
static otError oad_setupCoapServer (otInstance *aInstance, otCoapResource *oadResource)
 sets up the application coap server. More...
 
static void oad_startTimer (uint32_t timeout, timer_t timerID)
 
void oad_storage_resume (uint16_t *blockNum)
 
static void oad_timeoutCB (union sigval val)
 Callback function registered with the Coap server. Processes the coap request from the clients. More...
 
uint8_t oad_writeImgBlock (oad_targetReceive_t *oadWriteEvt, oad_imgBlockReq_t *oadImgBlock_p)
 write the received img Block to ext. flash More...
 

Variables

static Queue_Handle hOadQ
 
static otCoapResource oadFwvResource
 
oad_imgBlockReq_t oadImgBlock
 
static otCoapResource oadNtfResource
 
static Queue_Struct oadQ
 
static timer_t oadRegTimerID
 
static timer_t oadTimeoutTimerID
 
uint16_t peerPort = OT_DEFAULT_COAP_PORT
 
static NVINTF_nvFuncts_t sNvoctpOADFps = { 0 }
 

Function Documentation

§ oad_setupCoapServer()

static otError oad_setupCoapServer ( otInstance *  aInstance,
otCoapResource *  oadResource 
)
static

sets up the application coap server.

Parameters
aInstanceA pointer to the OT instance
oadResourcePointer to OAD Resource
Returns
OT_ERROR_NONE if successful, else error code

References OtRtosApi_lock(), and OtRtosApi_unlock().

Referenced by OAD_open().

§ oad_configureTimeoutTimer()

static void oad_configureTimeoutTimer ( uint32_t  timeout)
static

Configure the timer.

Parameters
timeouttime in milliseconds.
Returns
None

References oad_timeoutCB(), and oadTimeoutTimerID.

Referenced by OAD_open().

§ oad_timeoutCB()

static void oad_timeoutCB ( union sigval  val)
static

Callback function registered with the Coap server. Processes the coap request from the clients.

Parameters
valargument passed by the clock if set up.
Returns
None

References OAD_abort(), and OtInstance_get().

Referenced by oad_configureTimeoutTimer().

§ oad_regTimeoutCB()

static void oad_regTimeoutCB ( union sigval  val)
static

Callback function periodic registration timer event.

Parameters
valArgument passed by the clock if set up.
Returns
None

References app_postEvt(), and OAD_CtrlRegEvt.

Referenced by oad_configureRegistrationTimer().

§ oad_settingsNVInit()

void oad_settingsNVInit ( void  )

References NVOCMP_loadApiPtrsExt().

Referenced by OAD_open().

§ oad_configureRegistrationTimer()

static void oad_configureRegistrationTimer ( void  )
static

References oad_regTimeoutCB(), and oadRegTimerID.

Referenced by OAD_open().

§ oad_startTimer()

static void oad_startTimer ( uint32_t  timeout,
timer_t  timerID 
)
static

§ oad_cancelTimer()

static void oad_cancelTimer ( timer_t  timerID)
static

References DISPUTILS_SERIALPRINTF.

Referenced by OAD_processQueue(), and OAD_resume().

§ oad_enqueueMsg()

uint8_t oad_enqueueMsg ( oadEvent_e  event,
void *  aContext,
otMessage *  aMessage,
const otMessageInfo *  aMessageInfo,
otMessage *  aResponseMsg 
)

§ oad_handleNtfServer()

static void oad_handleNtfServer ( void *  aContext,
otMessage *  aMessage,
const otMessageInfo *  aMessageInfo 
)
static

Callback function registered with the Coap server for resource "oad/ntf".

Parameters
aContextA pointer to the context information.
aMessageA pointer to the message.
aMessageInfoA pointer to the message info.
Returns
None

References DISPUTILS_SERIALPRINTF, OAD_abort(), oad_enqueueMsg(), oad_evtNtf, OAD_NO_RESOURCES, and OAD_SUCCESS.

Referenced by OAD_open().

§ oad_handleFwvServer()

static void oad_handleFwvServer ( void *  aContext,
otMessage *  aMessage,
const otMessageInfo *  aMessageInfo 
)
static

Callback function registered with the Coap server for resource "oad/fwv".

Parameters
aContextA pointer to the context information.
aMessageA pointer to the message.
aMessageInfoA pointer to the message info.
Returns
None

References DISPUTILS_SERIALPRINTF, OAD_abort(), oad_enqueueMsg(), oad_evtFwVersionReq, OAD_NO_RESOURCES, and OAD_SUCCESS.

Referenced by OAD_open().

§ oad_sendRspMsg()

void oad_sendRspMsg ( oad_targetReceive_t oadWriteEvt,
uint8_t *  pData,
uint16_t  len 
)

Function to send broadcast register msg.

Parameters
oadWriteEvtPointer to receive data
pDataPointer to response msg
lenLength of response msg
Returns
None

References oad_targetReceive_t::messageInfo, oad_srcAddrInfo_t::mPeerAddr, oad_srcAddrInfo_t::mPeerPort, OtInstance_get(), OtRtosApi_lock(), OtRtosApi_unlock(), and oad_targetReceive_t::responseMsg.

Referenced by oad_processFwVersion(), and oad_processNtf().

§ oad_getFwVersion()

void oad_getFwVersion ( char *  fwVersionStr)

Function to build the firmware version string.

Parameters
fwVersionStrpointer to fw version req. data
Returns
None

References img_common_header::bimVer, img_header_single_app::h, oad_image_header, and img_common_header::softVer.

Referenced by oad_processFwVersion(), and oad_sendRegMsg().

§ oad_processFwVersion()

void oad_processFwVersion ( oad_targetReceive_t oadWriteEvt)

Function to send firmware version msg.

Parameters
oadWriteEvtPointer to fw version req. Data
Returns
None

References oad_getFwVersion(), and oad_sendRspMsg().

Referenced by OAD_processQueue().

§ oad_sendReqMsg()

void oad_sendReqMsg ( oad_targetReceive_t oadWriteEvt,
otCoapType  coapType,
otCoapCode  coapCode,
const char *  uriPath,
otCoapResponseHandler  handler 
)

Function to send CoAP request message.

Parameters
oadWriteEvtPointer to msg information
coapTypeType of the CoAP message; POST, PUT, GET, DEL
coapCodeReturn code of the CoAP message
uriPathCoAP resource path name
handlerCallback function for the msg
Returns
None

References DEFAULT_COAP_HEADER_TOKEN_LEN, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::len, oad_targetReceive_t::messageInfo, oad_srcAddrInfo_t::mPeerAddr, oad_srcAddrInfo_t::mPeerPort, oad_targetReceive_t::msg, OtInstance_get(), OtRtosApi_lock(), and OtRtosApi_unlock().

Referenced by oad_lastImgBlockReq(), oad_processImgBlockReq(), and oad_sendRegMsg().

§ oad_regReqHandler()

void oad_regReqHandler ( void *  aContext,
otMessage *  aMessage,
const otMessageInfo *  aMessageInfo,
otError  aResult 
)

callback for CoAp Registration request

Parameters
aContextA pointer to the context information.
aMessageA pointer to the message.
aMessageInfoA pointer to the message info.
aResultStatus of the msg. sent
Returns
None

References DISPUTILS_SERIALPRINTF, OAD_REG_INIT_TIME, OAD_REG_KEEPALIVE_TIME, OAD_resume(), oad_startTimer(), and oadRegTimerID.

Referenced by oad_sendRegMsg().

§ oad_sendRegMsg()

void oad_sendRegMsg ( void  )

§ oad_processNtf()

static uint8_t oad_processNtf ( oad_targetReceive_t oadWriteEvt,
oad_imgBlockReq_t oadImgBlock_p 
)
static

Function to process notification request message and send a response.

Parameters
oadWriteEvtA pointer to the OAD receive event
oadImgBlock_pPointer to the OAD image block
Returns
status = OAD_IMG_REJECTED/ACCEPTED

References oad_imgBlockReq_t::blkNum, DISPUTILS_SERIALPRINTF, oad_imgBlockReq_t::img_id, oad_imgNtfRsp_t::imgId, oad_targetReceive_t::messageInfo, oad_targetReceive_t::msg, oad_infoSet(), oad_sendRspMsg(), OADStorage_imgIdentifyWrite(), OADStorage_init(), oad_imgNtfRsp_t::status, and oad_imgBlockReq_t::totalBlocks.

Referenced by OAD_processQueue().

§ oad_blockReqHandler()

void oad_blockReqHandler ( void *  aContext,
otMessage *  aMessage,
const otMessageInfo *  aMessageInfo,
otError  aResult 
)

callback for CoAp img block request

Parameters
aContextA pointer to the context information.
aMessageA pointer to the message.
aMessageInfoA pointer to the message info.
aResultStatus of the msg. sent
Returns
None

References DISPUTILS_SERIALPRINTF, OAD_abort(), OAD_DELAY_TIMEOUT, oad_enqueueMsg(), oad_evtImgBlockReq, OAD_pause(), OAD_REG_INIT_TIME, oad_startTimer(), OAD_SUCCESS, oadRegTimerID, and oadTimeoutTimerID.

Referenced by oad_processImgBlockReq().

§ oad_checkDLComplete()

void oad_checkDLComplete ( oad_imgBlockReq_t oadImgBlockReq_p)

Function to check the validity of the image when the DL is complete.

Parameters
oadImgBlockReq_pA pointer to oadImgBlockReq struct
Returns
None

References DISPUTILS_SERIALPRINTF, OAD_abort(), OAD_close(), and OADStorage_imgFinalise().

Referenced by OAD_processQueue().

§ oad_writeImgBlock()

uint8_t oad_writeImgBlock ( oad_targetReceive_t oadWriteEvt,
oad_imgBlockReq_t oadImgBlock_p 
)

write the received img Block to ext. flash

Parameters
oadWriteEvtA pointer to the received event
oadImgBlock_pPointer to imgBlockReq struct
Returns
status (flash write success/failure)

References oad_imgBlockReq_t::blkNum, oad_imgBlockRsp_t::data, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::msg, oad_infoSet(), and OADStorage_imgBlockWrite().

Referenced by OAD_processQueue().

§ oad_processImgBlockReq()

void oad_processImgBlockReq ( oad_targetReceive_t oadWriteEvt,
oad_imgBlockReq_t oadImgBlock_p 
)

sends the next block request.

Parameters
oadWriteEvtA pointer to the OAD Rx event
oadImgBlock_pA pointer to the OAD image block info
Returns
None

References oad_imgBlockReq_t::blkNum, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::len, oad_targetReceive_t::msg, oad_blockReqHandler(), OAD_IMG_URI, and oad_sendReqMsg().

Referenced by OAD_processQueue().

§ oad_lastImgBlockReq()

void oad_lastImgBlockReq ( oad_targetReceive_t oadWriteEvt,
oad_imgBlockReq_t oadImgBlock_p 
)

sends the next block request.

Parameters
oadWriteEvtA pointer to the OAD Rx event
oadImgBlock_pA pointer to the OAD image block info
Returns
None

References oad_imgBlockReq_t::blkNum, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::len, oad_targetReceive_t::msg, OAD_IMG_URI, and oad_sendReqMsg().

Referenced by OAD_processQueue().

§ oad_processDLComplete()

void oad_processDLComplete ( void  )

§ oad_infoSet()

uint8_t oad_infoSet ( void *  p,
uint16_t  len,
uint8_t  idx 
)

Set OAD NVs.

Parameters
pA pointer to the NV data
lenlen of the NV
idxsub_id of OAD NV
Returns
status (NV write success/failure)

References NV_OAD_ID, NVINTF_SYSID_APP, nvintf_itemid_t::systemID, and nvintf_nvfuncts_t::writeItem.

Referenced by OAD_close(), oad_processNtf(), and oad_writeImgBlock().

§ oad_infoGet()

uint8_t oad_infoGet ( void *  p,
uint16_t  len,
uint8_t  idx 
)

Get OAD NVs.

Parameters
pA pointer to the NV data
lenlen of the NV
idxsub_id of OAD NV
Returns
status (NV read success/failure)

References NV_OAD_ID, NVINTF_SYSID_APP, nvintf_nvfuncts_t::readItem, and nvintf_itemid_t::systemID.

Referenced by OAD_pause(), and OAD_resume().

§ oad_storage_resume()

void oad_storage_resume ( uint16_t *  blockNum)

§ OAD_open()

void OAD_open ( void  )

§ OAD_close()

void OAD_close ( void  )

Close the OAD module.

Returns
None

References oad_imgBlockReq_t::blkNum, oad_infoSet(), OADStorage_close(), and oad_imgBlockReq_t::totalBlocks.

Referenced by OAD_abort(), and oad_checkDLComplete().

§ OAD_abort()

void OAD_abort ( void  )

§ OAD_pause()

void OAD_pause ( void  )

Pause OAD module, if valid DL in prog.

Returns
None

References DISPUTILS_SERIALPRINTF, and oad_infoGet().

Referenced by oad_blockReqHandler().

§ OAD_resume()

void OAD_resume ( void  )

§ OAD_processCtrlEvents()

void OAD_processCtrlEvents ( appEvent_e  event)

A function to process the OAD periodic ctrl events.

Returns
None

References OAD_CtrlRegEvt, and oad_sendRegMsg().

§ OAD_processQueue()

void OAD_processQueue ( void  )

Variable Documentation

§ oadNtfResource

otCoapResource oadNtfResource
static

Referenced by OAD_open().

§ oadFwvResource

otCoapResource oadFwvResource
static

Referenced by OAD_open().

§ oadTimeoutTimerID

timer_t oadTimeoutTimerID
static

§ oadRegTimerID

timer_t oadRegTimerID
static

§ oadQ

Queue_Struct oadQ
static

Referenced by OAD_open().

§ hOadQ

Queue_Handle hOadQ
static

§ oadImgBlock

oad_imgBlockReq_t oadImgBlock

§ peerPort

uint16_t peerPort = OT_DEFAULT_COAP_PORT

§ sNvoctpOADFps

NVINTF_nvFuncts_t sNvoctpOADFps = { 0 }
static
© Copyright 1995-2020, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale