123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- /**************************************************************************************************
- Filename: MT_OTA.c
- Revised: $Date: 2010-09-24 08:53:00 -0700 (Fri, 24 Sep 2010) $
- Revision: $Revision: 23900 $
- Description: MonitorTest functions for the ZCL OTA Upgrade.
- Copyright 2004-2007 Texas Instruments Incorporated. All rights reserved.
- IMPORTANT: Your use of this Software is limited to those specific rights
- granted under the terms of a software license agreement between the user
- who downloaded the software, his/her employer (which must be your employer)
- and Texas Instruments Incorporated (the "License"). You may not use this
- Software unless you agree to abide by the terms of the License. The License
- limits your use, and you acknowledge, that the Software may not be modified,
- copied or distributed unless embedded on a Texas Instruments microcontroller
- or used solely and exclusively in conjunction with a Texas Instruments radio
- frequency transceiver, which is integrated into your product. Other than for
- the foregoing purpose, you may not use, reproduce, copy, prepare derivative
- works of, modify, distribute, perform, display or sell this Software and/or
- its documentation for any purpose.
- YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
- PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
- INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
- NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
- TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
- NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
- LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
- INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
- OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
- OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
- (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
- Should you have any questions regarding your right to use this Software,
- contact Texas Instruments Incorporated at www.TI.com.
- **************************************************************************************************/
- #ifdef MT_OTA_FUNC
- /**************************************************************************************************
- * INCLUDES
- **************************************************************************************************/
- #include "ZComDef.h"
- #include "OSAL.h"
- #include "MT.h"
- #include "MT_OTA.h"
- #if !defined( WIN32 )
- #include "OnBoard.h"
- #endif
- /**************************************************************************************************
- * CONSTANTS
- **************************************************************************************************/
- /**************************************************************************************************
- * GLOBAL VARIABLES
- **************************************************************************************************/
- uint8 OTA_Task = 0xFF;
- /**************************************************************************************************
- * LOCAL VARIABLES
- **************************************************************************************************/
- /**************************************************************************************************
- * LOCAL FUNCTIONS
- **************************************************************************************************/
- /***************************************************************************************************
- * @fn MT_OtaRegister
- *
- * @brief Called to set the task to receive callbacks from the MT OTA.
- *
- * @param taskId - task identifier
- *
- * @return void
- ***************************************************************************************************/
- void MT_OtaRegister(uint8 taskId)
- {
- OTA_Task = taskId;
- }
- /***************************************************************************************************
- * @fn MT_OtaCommandProcessing
- *
- * @brief Process all the MT OTA commands that are issued by the OTA Console tool
- *
- * @param pBuf - pointer to the msg buffer
- *
- * | LEN | CMD0 | CMD1 | DATA |
- * | 1 | 1 | 1 | 0-255 |
- *
- * @return status
- ***************************************************************************************************/
- uint8 MT_OtaCommandProcessing(uint8* pBuf)
- {
- uint8 status = MT_RPC_SUCCESS;
- uint8 len;
- OTA_MtMsg_t *pMsg;
- uint8 cmd = pBuf[MT_RPC_POS_CMD1];
- if (cmd == MT_OTA_FILE_READ_RSP || cmd == MT_OTA_NEXT_IMG_RSP)
- {
- // Forward the message to the task
- if (OTA_Task != 0xff)
- {
- len = pBuf[MT_RPC_POS_LEN];
- pMsg = (OTA_MtMsg_t*) osal_msg_allocate(len + sizeof(OTA_MtMsg_t));
-
- if (pMsg)
- {
- pMsg->hdr.event = MT_SYS_OTA_MSG;
- pMsg->cmd = cmd;
-
- osal_memcpy(pMsg->data, &pBuf[MT_RPC_POS_DAT0], len);
- osal_msg_send(OTA_Task, (uint8*) pMsg);
- }
- }
- }
- else
- {
- status = MT_RPC_ERR_COMMAND_ID;
- }
- return status;
- }
- /***************************************************************************************************
- * @fn MT_OtaFileReadReq
- *
- * @brief Requests a block of a file be read from the remote.
- *
- * @param pAddr - The addres of the device requsting the data
- * @param pFileId - Teh id of the image to read from
- * @param len - Amount of data to read (must be smaller than the max MT message payload len)
- * @param offset - The offset into the image to start reading from
- *
- * @return status
- ***************************************************************************************************/
- uint8 MT_OtaFileReadReq(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint8 len, uint32 offset)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
- // Check if the requested length is longer than the RX receive buffer
- if (len + MT_OTA_FILE_READ_RSP_LEN + SPI_0DATA_MSG_LEN > MT_UART_RX_BUFF_MAX)
- return 0;
-
- // Get length
- msgLen = MT_OTA_FILE_READ_REQ_LEN;
-
- // Allocate a buffer
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
- /* build header */
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_FILE_READ_REQ;
-
- // Add the file ID
- p = OTA_FileIdToStream(pFileId, p);
- // Add the device address
- p = OTA_AfAddrToStream(pAddr, p);
- // File ofset to read from
- *p++ = BREAK_UINT32(offset, 0);
- *p++ = BREAK_UINT32(offset, 1);
- *p++ = BREAK_UINT32(offset, 2);
- *p++ = BREAK_UINT32(offset, 3);
- *p = len;
-
- // Send command to server
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- /***************************************************************************************************
- * @fn MT_OtaGetImage
- *
- * @brief Requests the next OTA image for a given device.
- *
- * @param pAddr - Address of the device requesting the image
- * @param pFileId - The file ID of the image currently on the device
- * @param hwVer - The hardware version of the device (optional)
- * @param ieee - The IEEE address of the device (optional)
- * @param options - The get image options
- *
- * @return Status
- *
- ***************************************************************************************************/
- uint8 MT_OtaGetImage(afAddrType_t *pAddr, zclOTA_FileID_t *pFileId, uint16 hwVer,
- uint8 *ieee, uint8 options)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
- // Get length
- msgLen = MT_OTA_GET_IMG_MSG_LEN;
-
- // Allocate a buffer
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
- // build header
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_NEXT_IMG_REQ;
-
- // Add the file ID
- p = OTA_FileIdToStream(pFileId, p);
- // Add the device address
- p = OTA_AfAddrToStream(pAddr, p);
- // Add the options
- *p++ = options;
- // Add the hardware ID (optional)
- *p++ = LO_UINT16(hwVer);
- *p = HI_UINT16(hwVer);
-
- if (ieee)
- osal_memcpy(p, ieee, Z_EXTADDR_LEN);
-
- // Send command to server
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- /***************************************************************************************************
- * @fn MT_OtaGetImage
- *
- * @brief Requests the next OTA image for a given device.
- *
- * @param shortAddr - Short Address of the device the status relates to
- * @param type - The type of status being reported
- * @param status - The status value
- * @param optional - Optional type specific additional information
- *
- * @return status
- *
- ***************************************************************************************************/
- uint8 MT_OtaSendStatus(uint16 shortAddr, uint8 type, uint8 status, uint8 optional)
- {
- uint8 msgLen;
- uint8 *pBuf;
- uint8 *p;
- // Get length
- msgLen = 7;
-
- // Allocate a buffer
- if ((p = pBuf = MT_TransportAlloc(0, msgLen)) != NULL)
- {
- // build header
- *p++ = msgLen;
- *p++ = (uint8) MT_RPC_CMD_AREQ | (uint8) MT_RPC_SYS_OTA;
- *p++ = MT_OTA_STATUS_IND;
-
- // Add message parameters
- *p++ = LO_UINT16(_NIB.nwkPanId);
- *p++ = HI_UINT16(_NIB.nwkPanId);
- *p++ = LO_UINT16(shortAddr);
- *p++ = HI_UINT16(shortAddr);
- *p++ = type;
- *p++ = status;
- *p = optional;
-
- // Send command to server
- MT_TransportSend(pBuf);
-
- return ZSuccess;
- }
-
- return ZMemError;
- }
- #endif // MT_OTA_FUNC
|