![]() |
![]() |
TI-OpenThread
1.08.02.01
|
#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>
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 } |
|
static |
sets up the application coap server.
aInstance | A pointer to the OT instance |
oadResource | Pointer to OAD Resource |
References OtRtosApi_lock(), and OtRtosApi_unlock().
Referenced by OAD_open().
|
static |
Configure the timer.
timeout | time in milliseconds. |
References oad_timeoutCB(), and oadTimeoutTimerID.
Referenced by OAD_open().
|
static |
Callback function registered with the Coap server. Processes the coap request from the clients.
val | argument passed by the clock if set up. |
References OAD_abort(), and OtInstance_get().
Referenced by oad_configureTimeoutTimer().
|
static |
Callback function periodic registration timer event.
val | Argument passed by the clock if set up. |
References app_postEvt(), and OAD_CtrlRegEvt.
Referenced by oad_configureRegistrationTimer().
void oad_settingsNVInit | ( | void | ) |
References NVOCMP_loadApiPtrsExt().
Referenced by OAD_open().
|
static |
References oad_regTimeoutCB(), and oadRegTimerID.
Referenced by OAD_open().
|
static |
References DISPUTILS_SERIALPRINTF.
Referenced by OAD_abort(), oad_blockReqHandler(), and oad_regReqHandler().
|
static |
References DISPUTILS_SERIALPRINTF.
Referenced by OAD_processQueue(), and OAD_resume().
uint8_t oad_enqueueMsg | ( | oadEvent_e | event, |
void * | aContext, | ||
otMessage * | aMessage, | ||
const otMessageInfo * | aMessageInfo, | ||
otMessage * | aResponseMsg | ||
) |
References app_postEvt(), oad_targetReceive_t::event, hOadQ, oad_targetReceive_t::len, oad_targetReceive_t::messageInfo, oad_srcAddrInfo_t::mPeerAddr, oad_srcAddrInfo_t::mPeerPort, oad_targetReceive_t::msg, OAD_NO_RESOURCES, OAD_queueEvt, OAD_SUCCESS, and oad_targetReceive_t::responseMsg.
Referenced by oad_blockReqHandler(), oad_handleFwvServer(), and oad_handleNtfServer().
|
static |
Callback function registered with the Coap server for resource "oad/ntf".
aContext | A pointer to the context information. |
aMessage | A pointer to the message. |
aMessageInfo | A pointer to the message info. |
References DISPUTILS_SERIALPRINTF, OAD_abort(), oad_enqueueMsg(), oad_evtNtf, OAD_NO_RESOURCES, and OAD_SUCCESS.
Referenced by OAD_open().
|
static |
Callback function registered with the Coap server for resource "oad/fwv".
aContext | A pointer to the context information. |
aMessage | A pointer to the message. |
aMessageInfo | A pointer to the message info. |
References DISPUTILS_SERIALPRINTF, OAD_abort(), oad_enqueueMsg(), oad_evtFwVersionReq, OAD_NO_RESOURCES, and OAD_SUCCESS.
Referenced by OAD_open().
void oad_sendRspMsg | ( | oad_targetReceive_t * | oadWriteEvt, |
uint8_t * | pData, | ||
uint16_t | len | ||
) |
Function to send broadcast register msg.
oadWriteEvt | Pointer to receive data |
pData | Pointer to response msg |
len | Length of response msg |
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().
void oad_getFwVersion | ( | char * | fwVersionStr | ) |
Function to build the firmware version string.
fwVersionStr | pointer to fw version req. data |
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().
void oad_processFwVersion | ( | oad_targetReceive_t * | oadWriteEvt | ) |
Function to send firmware version msg.
oadWriteEvt | Pointer to fw version req. Data |
References oad_getFwVersion(), and oad_sendRspMsg().
Referenced by OAD_processQueue().
void oad_sendReqMsg | ( | oad_targetReceive_t * | oadWriteEvt, |
otCoapType | coapType, | ||
otCoapCode | coapCode, | ||
const char * | uriPath, | ||
otCoapResponseHandler | handler | ||
) |
Function to send CoAP request message.
oadWriteEvt | Pointer to msg information |
coapType | Type of the CoAP message; POST, PUT, GET, DEL |
coapCode | Return code of the CoAP message |
uriPath | CoAP resource path name |
handler | Callback function for the msg |
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().
void oad_regReqHandler | ( | void * | aContext, |
otMessage * | aMessage, | ||
const otMessageInfo * | aMessageInfo, | ||
otError | aResult | ||
) |
callback for CoAp Registration request
aContext | A pointer to the context information. |
aMessage | A pointer to the message. |
aMessageInfo | A pointer to the message info. |
aResult | Status of the msg. sent |
References DISPUTILS_SERIALPRINTF, OAD_REG_INIT_TIME, OAD_REG_KEEPALIVE_TIME, OAD_resume(), oad_startTimer(), and oadRegTimerID.
Referenced by oad_sendRegMsg().
void oad_sendRegMsg | ( | void | ) |
Function to send broadcast register msg.
References DISPUTILS_SERIALPRINTF, oad_regMsg_t::fwVerStr, img_header_single_app::h, oad_regMsg_t::imgID, img_common_header::imgID, oad_regMsg_t::ipAddr, oad_targetReceive_t::len, oad_targetReceive_t::messageInfo, oad_srcAddrInfo_t::mPeerAddr, oad_srcAddrInfo_t::mPeerPort, oad_targetReceive_t::msg, oad_getFwVersion(), oad_image_header, OAD_REG_URI, oad_regReqHandler(), oad_sendReqMsg(), OtInstance_get(), OtRtosApi_lock(), OtRtosApi_unlock(), and oad_regMsg_t::platformType.
Referenced by OAD_open(), and OAD_processCtrlEvents().
|
static |
Function to process notification request message and send a response.
oadWriteEvt | A pointer to the OAD receive event |
oadImgBlock_p | Pointer to the OAD image block |
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().
void oad_blockReqHandler | ( | void * | aContext, |
otMessage * | aMessage, | ||
const otMessageInfo * | aMessageInfo, | ||
otError | aResult | ||
) |
callback for CoAp img block request
aContext | A pointer to the context information. |
aMessage | A pointer to the message. |
aMessageInfo | A pointer to the message info. |
aResult | Status of the msg. sent |
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().
void oad_checkDLComplete | ( | oad_imgBlockReq_t * | oadImgBlockReq_p | ) |
Function to check the validity of the image when the DL is complete.
oadImgBlockReq_p | A pointer to oadImgBlockReq struct |
References DISPUTILS_SERIALPRINTF, OAD_abort(), OAD_close(), and OADStorage_imgFinalise().
Referenced by OAD_processQueue().
uint8_t oad_writeImgBlock | ( | oad_targetReceive_t * | oadWriteEvt, |
oad_imgBlockReq_t * | oadImgBlock_p | ||
) |
write the received img Block to ext. flash
oadWriteEvt | A pointer to the received event |
oadImgBlock_p | Pointer to imgBlockReq struct |
References oad_imgBlockReq_t::blkNum, oad_imgBlockRsp_t::data, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::msg, oad_infoSet(), and OADStorage_imgBlockWrite().
Referenced by OAD_processQueue().
void oad_processImgBlockReq | ( | oad_targetReceive_t * | oadWriteEvt, |
oad_imgBlockReq_t * | oadImgBlock_p | ||
) |
sends the next block request.
oadWriteEvt | A pointer to the OAD Rx event |
oadImgBlock_p | A pointer to the OAD image block info |
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().
void oad_lastImgBlockReq | ( | oad_targetReceive_t * | oadWriteEvt, |
oad_imgBlockReq_t * | oadImgBlock_p | ||
) |
sends the next block request.
oadWriteEvt | A pointer to the OAD Rx event |
oadImgBlock_p | A pointer to the OAD image block info |
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().
void oad_processDLComplete | ( | void | ) |
uint8_t oad_infoSet | ( | void * | p, |
uint16_t | len, | ||
uint8_t | idx | ||
) |
Set OAD NVs.
p | A pointer to the NV data |
len | len of the NV |
idx | sub_id of OAD NV |
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().
uint8_t oad_infoGet | ( | void * | p, |
uint16_t | len, | ||
uint8_t | idx | ||
) |
Get OAD NVs.
p | A pointer to the NV data |
len | len of the NV |
idx | sub_id of OAD NV |
References NV_OAD_ID, NVINTF_SYSID_APP, nvintf_nvfuncts_t::readItem, and nvintf_itemid_t::systemID.
Referenced by OAD_pause(), and OAD_resume().
void oad_storage_resume | ( | uint16_t * | blockNum | ) |
References EFL_PAGE_SIZE, OADStorage_BLOCK_SIZE, and OADStorage_eraseImgPage().
Referenced by OAD_resume().
void OAD_open | ( | void | ) |
Initialize OAD module.
References hasExternalFlash(), hOadQ, oad_configureRegistrationTimer(), oad_configureTimeoutTimer(), OAD_DELAY_TIMEOUT, OAD_FWV_URI, oad_handleFwvServer(), oad_handleNtfServer(), OAD_NTF_URI, oad_sendRegMsg(), oad_settingsNVInit(), oad_setupCoapServer(), OAD_USER_CFG_FACTORY_IMG, oadFwvResource, oadNtfResource, oadQ, OADStorage_checkFactoryImage(), OADStorage_createFactoryImageBackup(), OADStorage_getFactoryImage(), and OtInstance_get().
void OAD_close | ( | void | ) |
Close the OAD module.
References oad_imgBlockReq_t::blkNum, oad_infoSet(), OADStorage_close(), and oad_imgBlockReq_t::totalBlocks.
Referenced by OAD_abort(), and oad_checkDLComplete().
void OAD_abort | ( | void | ) |
Abort OAD module.
References DISPUTILS_SERIALPRINTF, OAD_close(), OAD_REG_INIT_TIME, oad_startTimer(), and oadRegTimerID.
Referenced by oad_blockReqHandler(), oad_checkDLComplete(), oad_handleFwvServer(), oad_handleNtfServer(), OAD_processQueue(), and oad_timeoutCB().
void OAD_pause | ( | void | ) |
Pause OAD module, if valid DL in prog.
References DISPUTILS_SERIALPRINTF, and oad_infoGet().
Referenced by oad_blockReqHandler().
void OAD_resume | ( | void | ) |
Resume OAD module.
References app_postEvt(), oad_imgBlockReq_t::blkNum, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::event, hOadQ, oad_imgBlockReq_t::img_id, oad_imgNtfReq_t::imgHdr, oad_imgNtfReq_t::imgId, oad_targetReceive_t::messageInfo, oad_cancelTimer(), oad_evtDLResume, oad_infoGet(), OAD_queueEvt, oad_storage_resume(), oadRegTimerID, OADStorage_imgIdentifyWrite(), OADStorage_init(), oadTimeoutTimerID, and oad_imgBlockReq_t::totalBlocks.
Referenced by oad_regReqHandler().
void OAD_processCtrlEvents | ( | appEvent_e | event | ) |
A function to process the OAD periodic ctrl events.
References OAD_CtrlRegEvt, and oad_sendRegMsg().
void OAD_processQueue | ( | void | ) |
A function to process the OAD events.
References oad_imgBlockReq_t::blkNum, oad_imgBlockRsp_t::blkNum, DISPUTILS_SERIALPRINTF, oad_targetReceive_t::event, hOadQ, oad_targetReceive_t::msg, OAD_abort(), oad_cancelTimer(), oad_checkDLComplete(), oad_evtDLComplete, oad_evtDLResume, oad_evtFwVersionReq, oad_evtImgBlockReq, oad_evtNtf, oad_lastImgBlockReq(), oad_processFwVersion(), oad_processImgBlockReq(), oad_processNtf(), oad_writeImgBlock(), oadRegTimerID, and oad_imgBlockReq_t::totalBlocks.
|
static |
Referenced by OAD_open().
|
static |
Referenced by OAD_open().
|
static |
Referenced by oad_blockReqHandler(), oad_configureTimeoutTimer(), and OAD_resume().
|
static |
Referenced by OAD_abort(), oad_blockReqHandler(), oad_configureRegistrationTimer(), OAD_processQueue(), oad_regReqHandler(), and OAD_resume().
|
static |
Referenced by OAD_open().
|
static |
Referenced by oad_enqueueMsg(), OAD_open(), OAD_processQueue(), and OAD_resume().
oad_imgBlockReq_t oadImgBlock |
uint16_t peerPort = OT_DEFAULT_COAP_PORT |
|
static |