blob: 9f4e0dc7a57f4de637e66530922868dac9ca608c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
/**
*********************************************************************************************************
* Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
**********************************************************************************************************
* @file ota_service.h
* @brief
* @details
* @author hunter_shuai
* @date 14-July-2015
* @version v1.0.0
******************************************************************************
* @attention
* <h2><center>© COPYRIGHT 2015 Realtek Semiconductor Corporation</center></h2>
******************************************************************************
*/
#ifndef _OTA_SERVICE_H_
#define _OTA_SERVICE_H_
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include "profile_server.h"
#include "dfu_api.h"
/** @brief Demo Profile service related UUIDs. */
#define GATT_UUID_CHAR_OTA 0xFFD1 //1
#define GATT_UUID_CHAR_MAC 0xFFD2 //2
#define GATT_UUID_CHAR_PATCH 0xFFD3 //3
#define GATT_UUID_CHAR_APP_VERSION 0xFFD4 //4
#define GATT_UUID_CHAR_PATCH_EXTENSION 0xFFD5 //5
#define GATT_UUID_CHAR_TEST_MODE 0xFFD8 //6
#define GATT_UUID_CHAR_DEVICE_INFO 0xFFF1 //7
#define GATT_UUID_CHAR_IMAGE_COUNT_TO_UPDATE 0xFFF2 //8
#define GATT_UUID_CHAR_IMAGE_VERSION0 0xFFE0 //mandatory when OTA version >= 1
#define GATT_UUID_CHAR_IMAGE_VERSION1 0xFFE1
#define GATT_UUID_CHAR_IMAGE_VERSION2 0xFFE2
#define GATT_UUID_CHAR_PROTOCOL_TYPE 0xFFF3
/** @brief Index of each characteristic in Demo Profile service database. */
#define BLE_SERVICE_CHAR_OTA_INDEX 0x02 /**< attr write */
#define BLE_SERVICE_CHAR_MAC_ADDRESS_INDEX 0x04 /**< attr read */
#define BLE_SERVICE_CHAR_PATCH_INDEX 0x06 /**< attr read */
#define BLE_SERVICE_CHAR_APP_VERSION_INDEX 0x08 /**< attr read */
#define BLE_SERVICE_CHAR_PATCH_EXTENSION_INDEX 0x0a /**< attr read */
#define BLE_SERVICE_CHAR_TEST_MODE_INDEX 0x0c /**< attr write */
#define BLE_SERVICE_CHAR_DEVICE_INFO_INDEX 0x0e /**< attr read */
#define BLE_SERVICE_CHAR_IMAGE_COUNT_INDEX 0x10 /**< attr write */
#define BLE_SERVICE_CHAR_IMAGE_VERSION0_INDEX 0x12 /**< attr read */
#define BLE_SERVICE_CHAR_IMAGE_VERSION1_INDEX 0x14 /**< attr read */
#define BLE_SERVICE_CHAR_IMAGE_VERSION2_INDEX 0x16 /**< attr read */
#define BLE_SERVICE_CHAR_PROTOCOL_TYPE_INDEX 0x18 /**< attr read */
/** @brief OTA Read callback data type definition.*/
#define OTA_READ_CHAR_MAC_ADDRESS_INDEX 0x01
#define OTA_READ_CHAR_PATCH_INDEX 0x02
#define OTA_READ_CHAR_APP_VERSION_INDEX 0x03
#define OTA_READ_CHAR_PATCH_EXTENSION_INDEX 0x04
#define OTA_READ_CHAR_DEVICE_INFO_INDEX 0x05
#define OTA_READ_CHAR_IMAGE_VERSION_INDEX 0x06
#define OTA_READ_CHAR_PROTOCOL_TYPE_INDEX 0x07
/** @brief OTA Write callback data type definition.*/
#define OTA_WRITE_CHAR_VAL 0x01 /**< switch ota mode write opcode */
#define OTA_VALUE_ENTER 0x01 /**< switch ota mode write value */
/** @brief OTA Write callback data type definition.*/
#define OTA_WRITE_TEST_MODE_CHAR_VAL 0x02 /**< test mode write opcode */
/** @brief OTA Write callback data type definition.*/
#define OTA_WRITE_IMAGE_COUNT_VAL 0x02 /**< image count write opcode */
#define OTA_VALUE_IMAGE_COUNT_APP_ONLY 0x01
#define OTA_VALUE_IMAGE_COUNT_PATCH_ONLY 0x02
#define OTA_VALUE_IMAGE_COUNT_APP_AND_PATCH 0x03
#define OTA_CHAR_IMAGE_COUNT_LEN 5
#define CHAR2SHORT(p) (((*(p)) & 0xff) + ((*((p)+1)) << 8))
typedef struct _T_DFU_DEVICE_INFO
{
uint8_t ic_type;
uint8_t ota_version;
uint8_t secure_version;
T_OTA_MODE ota_mode;
uint16_t max_buffer_size;
uint8_t temp_bank_size; //Unit:4K, 0x00:No Limitation of OTA Temp Buffer Size,Only available when Updating Multi Image at a time is supported.
uint8_t rsvd;
uint32_t img_indicator;
} T_DFU_DEVICE_INFO, * P_DFU_DEVICE_INFO;
typedef struct _T_OTA_UPDATE_IMAGE_INFO
{
uint8_t image_count;
uint16_t update_patch_version;
uint16_t update_app_version;
} T_OTA_UPDATE_IMAGE_INFO;
typedef struct _T_OTA_WRITE_MSG
{
uint8_t opcode;
union
{
uint8_t value;
T_OTA_UPDATE_IMAGE_INFO update_image_info;
} u;
} T_OTA_WRITE_MSG;
typedef union _T_OTA_UPSTREAM_MSG_DATA
{
uint8_t notification_indification_index;
uint8_t read_value_index;
T_OTA_WRITE_MSG write;
} T_OTA_UPSTREAM_MSG_DATA;
/**
* @brief OTA servic data struct for notification data to application.
*
* OTA service data to inform application.
*/
typedef struct _T_OTA_CALLBACK_DATA
{
T_SERVICE_CALLBACK_TYPE msg_type; /**< @brief EventId defined upper */
T_OTA_UPSTREAM_MSG_DATA msg_data;
} T_OTA_CALLBACK_DATA;
extern uint8_t ota_add_service(void *pFunc);
#ifdef __cplusplus
}
#endif
#endif
|