ota_common.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /******************************************************************************
  2. Filename: ota_common.h
  3. Revised: $Date: 2011-07-15 18:31:00 -0700 (Fri, 15 Jul 2011) $
  4. Revision: $Revision: 26808 $
  5. Description: This file contains code common to the OTA server,
  6. client, and dongle.
  7. Copyright 2010-2011 Texas Instruments Incorporated. All rights reserved.
  8. IMPORTANT: Your use of this Software is limited to those specific rights
  9. granted under the terms of a software license agreement between the user
  10. who downloaded the software, his/her employer (which must be your employer)
  11. and Texas Instruments Incorporated (the "License"). You may not use this
  12. Software unless you agree to abide by the terms of the License. The License
  13. limits your use, and you acknowledge, that the Software may not be modified,
  14. copied or distributed unless embedded on a Texas Instruments microcontroller
  15. or used solely and exclusively in conjunction with a Texas Instruments radio
  16. frequency transceiver, which is integrated into your product. Other than for
  17. the foregoing purpose, you may not use, reproduce, copy, prepare derivative
  18. works of, modify, distribute, perform, display or sell this Software and/or
  19. its documentation for any purpose.
  20. YOU FURTHER ACKNOWLEDGE AND AGREE THAT THE SOFTWARE AND DOCUMENTATION ARE
  21. PROVIDED “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  22. INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY, TITLE,
  23. NON-INFRINGEMENT AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL
  24. TEXAS INSTRUMENTS OR ITS LICENSORS BE LIABLE OR OBLIGATED UNDER CONTRACT,
  25. NEGLIGENCE, STRICT LIABILITY, CONTRIBUTION, BREACH OF WARRANTY, OR OTHER
  26. LEGAL EQUITABLE THEORY ANY DIRECT OR INDIRECT DAMAGES OR EXPENSES
  27. INCLUDING BUT NOT LIMITED TO ANY INCIDENTAL, SPECIAL, INDIRECT, PUNITIVE
  28. OR CONSEQUENTIAL DAMAGES, LOST PROFITS OR LOST DATA, COST OF PROCUREMENT
  29. OF SUBSTITUTE GOODS, TECHNOLOGY, SERVICES, OR ANY CLAIMS BY THIRD PARTIES
  30. (INCLUDING BUT NOT LIMITED TO ANY DEFENSE THEREOF), OR OTHER SIMILAR COSTS.
  31. Should you have any questions regarding your right to use this Software,
  32. contact Texas Instruments Incorporated at www.TI.com.
  33. ******************************************************************************/
  34. #ifndef OTA_COMMON_H
  35. #define OTA_COMMON_H
  36. #if !defined HAL_OTA_BOOT_CODE
  37. #include "af.h"
  38. #endif
  39. // Endpoint for SYS App messages
  40. #define OTA_SYSAPP_ENDPOINT 20
  41. #define OTA_APP_MAX_ATTRIBUTES 7
  42. // SYS App message format byte positions
  43. #define MT_APP_ENDPOINT_POS 0
  44. #define MT_APP_COMMAND_POS 1
  45. #define MT_APP_DATA_POS 2
  46. // SYS APP Commands for dongle communication with OTA Console
  47. #define OTA_APP_READ_ATTRIBUTE_REQ 0
  48. #define OTA_APP_IMAGE_NOTIFY_REQ 1
  49. #define OTA_APP_DISCOVERY_REQ 2
  50. #define OTA_APP_JOIN_REQ 3
  51. #define OTA_APP_LEAVE_REQ 4
  52. #define OTA_APP_READ_ATTRIBUTE_IND 0x80
  53. #define OTA_APP_IMAGE_NOTIFY_RSP 0x81
  54. #define OTA_APP_DEVICE_IND 0x82
  55. #define OTA_APP_JOIN_IND 0x83
  56. #define OTA_APP_ENDPOINT_IND 0x85
  57. #define OTA_APP_DONGLE_IND 0x8A
  58. // Sys App Message Lengths
  59. #define OTA_APP_READ_ATTRIBUTE_REQ_LEN (8 + OTA_APP_MAX_ATTRIBUTES*2)
  60. #define OTA_APP_IMAGE_NOTIFY_REQ_LEN 15
  61. #define OTA_APP_DISCOVERY_REQ_LEN 2
  62. #define OTA_APP_JOIN_REQ_LEN 5
  63. #define OTA_APP_LEAVE_REQ_LEN 2
  64. #define OTA_APP_READ_ATTRIBUTE_IND_LEN 21
  65. #define OTA_APP_IMAGE_NOTIFY_RSP_LEN 16
  66. #define OTA_APP_DEVICE_IND_LEN 6
  67. #define OTA_APP_JOIN_IND_LEN 4
  68. #define OTA_APP_ENDPOINT_IND_LEN 7
  69. #define OTA_INVALID_ID 0xFF
  70. // OTA Header constants
  71. #define OTA_HDR_MAGIC_NUMBER 0x0BEEF11E
  72. #define OTA_HDR_BLOCK_SIZE 128
  73. #define OTA_HDR_STACK_VERSION 2
  74. #define OTA_HDR_HEADER_VERSION 0x0100
  75. #define OTA_HDR_FIELD_CTRL 0
  76. #define OTA_HEADER_LEN_MIN 56
  77. #define OTA_HEADER_LEN_MAX 69
  78. #define OTA_HEADER_LEN_MIN_ECDSA 166
  79. #define OTA_HEADER_STR_LEN 32
  80. #define OTA_HEADER_IMAGE_SIZE_POS 52
  81. // OTA_HEADER_FILE_ID_POS is needed for windows tools
  82. #define OTA_HEADER_FILE_ID_POS 10
  83. #define OTA_FC_SCV_PRESENT (0x1 << 0)
  84. #define OTA_FC_DSF_PRESENT (0x1 << 1)
  85. #define OTA_FC_HWV_PRESENT (0x1 << 2)
  86. #define OTA_SUB_ELEMENT_HDR_LEN 6
  87. #define OTA_UPGRADE_IMAGE_TAG_ID 0
  88. #define OTA_ECDSA_SIGNATURE_TAG_ID 1
  89. #define OTA_EDCSA_CERTIFICATE_TAG_ID 2
  90. // MT_OtaGeImage options
  91. #define MT_OTA_HW_VER_PRESENT_OPTION 0x01
  92. #define MT_OTA_QUERY_SPECIFIC_OPTION 0x02
  93. // MT OTA Status Indication Types
  94. #define MT_OTA_DL_COMPLETE 0
  95. typedef struct
  96. {
  97. uint16 manufacturer;
  98. uint16 type;
  99. uint32 version;
  100. } zclOTA_FileID_t;
  101. typedef struct
  102. {
  103. uint16 tag;
  104. uint32 length;
  105. } OTA_SubElementHdr_t;
  106. typedef struct
  107. {
  108. uint32 magicNumber;
  109. uint16 headerVersion;
  110. uint16 headerLength;
  111. uint16 fieldControl;
  112. zclOTA_FileID_t fileId;
  113. uint16 stackVersion;
  114. uint8 headerString[OTA_HEADER_STR_LEN];
  115. uint32 imageSize;
  116. uint8 secCredentialVer;
  117. uint8 destIEEE[8];
  118. uint16 minHwVer;
  119. uint16 maxHwVer;
  120. } OTA_ImageHeader_t;
  121. #ifdef __cplusplus
  122. extern "C"
  123. {
  124. #endif
  125. extern uint8 *OTA_WriteHeader(OTA_ImageHeader_t *pHdr, uint8 *pBuf);
  126. extern uint8 *OTA_ParseHeader(OTA_ImageHeader_t *pHdr, uint8 *pBuf);
  127. extern void OTA_GetFileName(char *pName, zclOTA_FileID_t *pFileId, char *text);
  128. extern void OTA_SplitFileName(char *pName, zclOTA_FileID_t *pFileId);
  129. extern uint8 *OTA_StreamToFileId(zclOTA_FileID_t *pFileId, uint8 *pStream);
  130. extern uint8 *OTA_FileIdToStream(zclOTA_FileID_t *pFileId, uint8 *pStream);
  131. #if !defined HAL_OTA_BOOT_CODE
  132. extern uint8 *OTA_AfAddrToStream(afAddrType_t *pAddr, uint8 *pStream);
  133. extern uint8 *OTA_StreamToAfAddr(afAddrType_t *pAddr, uint8 *pStream);
  134. #endif
  135. #ifdef __cplusplus
  136. }
  137. #endif
  138. #endif // OTA_COMMON_H