aboutsummaryrefslogtreecommitdiff
path: root/inc/bluetooth/profile/client/ota_client.h
blob: 78758878a3477e4be94e1e566df871d3a1325532 (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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
/**
*****************************************************************************************
*     Copyright(c) 2015, Realtek Semiconductor Corporation. All rights reserved.
*****************************************************************************************
  * @file     ota_client.h
  * @brief    Head file for using ota service Client.
  * @details  Data structs and external functions declaration.
  * @author
  * @date
  * @version
  * *************************************************************************************
  */

/* Define to prevent recursive inclusion */
#ifndef _OTA_CLIENT_H_
#define _OTA_CLIENT_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Add Includes here */
#include "profile_client.h"
#include "dfu_api.h"

/** @defgroup OTA_Client OTA Service Client
  * @{
  */

/*============================================================================*
*                         Macros
*============================================================================*/
/** @addtogroup OTA_Client_Exported_Macros OTA Client Exported Macros
 * @brief
 * @{
 */
/** @defgroup OTA UUIDs
 * @brief ota BLE Profile UUID definitions
 * @{
 */
#define GATT_UUID_OTA_SERVICE 0x12, 0xA2, 0x4D, 0x2E, 0xFE, 0x14, 0x48, 0x8e, 0x93, 0xD2, 0x17, 0x3C, 0xFF, 0xD0, 0x00, 0x00

#define GATT_UUID_OTA_PROFILE

#define GATT_UUID_CHAR_OTA                          0xFFD1    //1, write
#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, write

#define GATT_UUID_CHAR_DEVICE_INFO                  0xFFF1    //7
#define GATT_UUID_CHAR_IMAGE_COUNT_TO_UPDATE        0xFFF2    //8, write
#define GATT_UUID_CHAR_IMAGE_VERSION                0xFFE0
/** @} End of OTA_UUIDs */


#define OTA_WRITE_OTA_CMD_CHAR_VAL                  0x01
#define OTA_WRITE_TEST_MODE_CHAR_VAL                0x02
#define OTA_WRITE_OTA_IMG_COUNTER_CHAR_VAL          0x03


/** @brief  Define links number. range: 0-4 */
#define OTA_MAX_LINKS           4
/** End of OTA_Client_Exported_Macros * @} */

/*============================================================================*
 *                         Types
 *============================================================================*/
/** @defgroup OTA_Client_Exported_Types OTA Client Exported Types
  * @brief
  * @{
  */
/** @brief OTA client device info*/
typedef struct _T_OTA_DEVICE_INFO
{
    uint8_t ictype;
    uint8_t ota_version;
    uint8_t secure_version;
    T_OTA_MODE ota_mode;

    uint16_t max_buffer_size;
    uint16_t rsvd;

    uint32_t img_indicator;
} T_OTA_DEVICE_INFO, *P_OTA_DEVICE_INFO;

/** @brief OTA client handle type*/
typedef enum
{
    HDL_OTA_SRV_START,           //!< start handle of battery service
    HDL_OTA_SRV_END,             //!< end handle of battery service
    HDL_OTA_CMD,                 //!< OTA CMD characteristic value handle
    HDL_OTA_DEVICE_MAC,
    HDL_OTA_PATCH_VER,
    HDL_OTA_APP_VER,
    HDL_OTA_PATCH_EXT_VER,
    HDL_OTA_TEST_MODE,           //!< OTA test mode characteristic handle
    HDL_OTA_DEVICE_INFO,
    HDL_OTA_IMG_COUNTER,         //!<OTA IMAGE COUNT TO UPDATE characteristic handle
    HDL_OTA_IMG_VER,
    HDL_OTA_CACHE_LEN            //!< handle cache length
} T_OTA_HANDLE_TYPE;

/** @brief OTA client discovery state*/
typedef enum
{
    DISC_OTA_IDLE,
    DISC_OTA_START,
    DISC_OTA_DONE,
    DISC_OTA_FAILED
} T_OTA_DISC_STATE;

/** @brief OTA client read type*/
typedef enum
{
    OTA_READ_DEVICE_MAC,
    OTA_READ_PATCH_VER,
    OTA_READ_APP_VER,
    OTA_READ_PATCH_EXT_VER,
    OTA_READ_DEVICE_INFO,
    OTA_READ_IMG_VER
} T_OTA_READ_TYPE;

/** @brief OTA client read data */
typedef struct
{
    uint16_t value_size;
    uint8_t *p_value;
} T_OTA_READ_DATA;

/** @brief OTA client read result*/
typedef struct
{
    T_OTA_READ_TYPE type;
    T_OTA_READ_DATA data;
    uint16_t cause;
} T_OTA_READ_RESULT;

/** @brief OTA client write type*/
typedef enum
{
    OTA_WRITE_CMD,
    OTA_WRITE_TEST_MODE,
    OTA_WRITE_IMG_COUNTER
} T_OTA_WRITE_TYPE;

/** @brief OTA client write result*/
typedef struct
{
    T_OTA_WRITE_TYPE type;
    uint16_t cause;
} T_OTA_WRITE_RESULT;

/** @brief OTA client callback type*/
typedef enum
{
    OTA_CLIENT_CB_TYPE_DISC_STATE,          //!< Discovery procedure state, done or pending.
    OTA_CLIENT_CB_TYPE_READ_RESULT,         //!< Read request's result data, responsed from server.
    OTA_CLIENT_CB_TYPE_WRITE_RESULT,        //!< Write request result, success or fail.
    OTA_CLIENT_CB_TYPE_INVALID              //!< Invalid callback type, no practical usage.
} T_OTA_CLIENT_CB_TYPE;

/** @brief OTA client callback content*/
typedef union
{
    T_OTA_DISC_STATE disc_state;
    T_OTA_READ_RESULT read_result;
    T_OTA_WRITE_RESULT write_result;
} T_OTA_CLIENT_CB_CONTENT;

/** @brief OTA client callback data*/
typedef struct
{
    T_OTA_CLIENT_CB_TYPE     cb_type;
    T_OTA_CLIENT_CB_CONTENT  cb_content;
} T_OTA_CLIENT_CB_DATA;
/** End of OTA_Client_Exported_Types * @} */


/*============================================================================*
 *                         Functions
 *============================================================================*/
/** @defgroup OTA_Client_Exported_Functions OTA Client Exported Functions
  * @{
  */
/**
  * @brief  Used by application, to read data from server by using handles.
  * @param[in]  conn_id connection ID.
  * @param[in]  read_type one of characteristic that has the readable property.
  * @retval true send request to upper stack success.
  * @retval false send request to upper stack failed.
  */
bool ota_client_read_by_handle(uint8_t conn_id, T_OTA_READ_TYPE read_type);

/**
  * @brief  Used by application, to get handle cache.
  * @param[in]  conn_id connection ID.
  * @param[in]  p_hdl_cache pointer of the handle cache table
  * @param[in]  len the length of handle cache table
  * @retval true success.
  * @retval false failed.
  */
bool ota_client_get_hdl_cache(uint8_t conn_id, uint16_t *p_hdl_cache, uint8_t len);

/**
  * @brief  Used by application, to set handle cache.
  * @param[in]  conn_id connection ID.
  * @param[in]  p_hdl_cache pointer of the handle cache table
  * @param[in]  len the length of handle cache table
  * @retval true success.
  * @retval false failed.
  */
bool ota_client_set_hdl_cache(uint8_t conn_id, uint16_t *p_hdl_cache, uint8_t len);

/**
  * @brief  Used by application, to write ota cmd write Characteristic.
  * @param[in]  conn_id connection ID.
  * @param[in]  length  write data length
  * @param[in]  p_value point the value to write
  * @param[in]  type    write type.
  * @retval true send request to upper stack success.
  * @retval false send request to upper stack failed.
  */
bool ota_client_write_char(uint8_t conn_id, T_OTA_WRITE_TYPE write_type);

/**
  * @brief  ota client connect target device.
  * @param  p_le_scan_info: filtered scan info
  */
void ota_client_connect_device(T_LE_SCAN_INFO *p_le_scan_info);
/**
  * @brief  Used by application, to start the discovery procedure of OTA server.
  * @param[in]  conn_id connection ID.
  * @retval true send request to upper stack success.
  * @retval false send request to upper stack failed.
  */
bool ota_client_start_discovery(uint8_t conn_id);

/**
  * @brief  add OTA client to application.
  * @param  appCB: pointer of app callback function to handle specific client module data.
  * @retval Client ID of the specific client module.
  */
T_CLIENT_ID ota_add_client(P_FUN_GENERAL_APP_CB app_cb, uint8_t link_num);
/** @} End of OTA_Client_Exported_Functions */

/** @} End of OTA_Client */

#ifdef __cplusplus
}
#endif

#endif  /* _OTA_CLIENT_H_ */