215 lines
8.0 KiB
C
215 lines
8.0 KiB
C
/****************************************************************************
|
|
|
|
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
|
|
|
|
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
|
|
be copied by any method or incorporated into another program without
|
|
the express written consent of Aerospace C.Power. This Information or any portion
|
|
thereof remains the property of Aerospace C.Power. The Information contained herein
|
|
is believed to be accurate and Aerospace C.Power assumes no responsibility or
|
|
liability for its use in any way and conveys no license or title under
|
|
any patent or copyright and makes no representation or warranty that this
|
|
Information is free from patent or copyright infringement.
|
|
|
|
****************************************************************************/
|
|
#ifndef IOT_SG_STA_UPGRADE_H
|
|
#define IOT_SG_STA_UPGRADE_H
|
|
|
|
#include "proto_gw_app.h"
|
|
#include "os_timer_api.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* STA upgrade state */
|
|
#define IOT_SG_STA_UPGRADE_ST_INVALID 0
|
|
#define IOT_SG_STA_UPGRADE_ST_IDLE 1
|
|
#define IOT_SG_STA_UPGRADE_ST_RECEIVE 2
|
|
#define IOT_SG_STA_UPGRADE_ST_RECV_DONE 3
|
|
#define IOT_SG_STA_UPGRADE_ST_EXECUTE 4
|
|
#define IOT_SG_STA_UPGRADE_ST_TRAIL_RUN 5
|
|
|
|
/* upgrade exit reason code */
|
|
/* upgrade exit, reason: normal */
|
|
#define IOT_SG_STA_UPGRADE_EXIT_NORMAL (0)
|
|
/* upgrade exit, reason: upgrade file mismatch */
|
|
#define IOT_SG_STA_UPGRADE_EXIT_MISMATCH (1)
|
|
/* upgrade exit, reason: recv stop cmd */
|
|
#define IOT_SG_STA_UPGRADE_EXIT_STOP_CMD (2)
|
|
/* upgrade exit, reason: join new nid */
|
|
#define IOT_SG_STA_UPGRADE_EXIT_NID_CHANGE (3)
|
|
/* upgrade exit, reason: same version */
|
|
#define IOT_SG_STA_UPGRADE_EXIT_SAME_VER (4)
|
|
|
|
/* if query block count equal to this value, it means query all blocks. */
|
|
#define IOT_SG_STA_QUERY_ALL_BLOCK 0xFFFF
|
|
|
|
/* max block size supported for upgrading */
|
|
#define IOT_SG_UPGRADE_MAX_BLOCK_SIZE 400
|
|
|
|
/* define active sta upgrade session type */
|
|
/* invalid session type */
|
|
#define IOT_SG_STA_UPGRADE_SESSION_TYPE_INVALID (0)
|
|
/* session type is gw app proto */
|
|
#define IOT_SG_STA_UPGRADE_SESSION_TYPE_GW (1)
|
|
/* session type is nw app proto */
|
|
#define IOT_SG_STA_UPGRADE_SESSION_TYPE_NW (2)
|
|
/* session type is 645 proto */
|
|
#define IOT_SG_STA_UPGRADE_SESSION_TYPE_645 (3)
|
|
/* session type is driver */
|
|
#define IOT_SG_STA_UPGRADE_SESSION_TYPE_DRV (4)
|
|
|
|
/* defines driver upgrade tm windows unit: hour */
|
|
#define IOT_SG_STA_DRV_UPGRADE_WINDOWS (24)
|
|
|
|
/* define sta file segment upgrade action */
|
|
#define IOT_SG_STA_SEG_UPGRADE_ACTION_STOP (0)
|
|
#define IOT_SG_STA_SEG_UPGRADE_ACTION_UPGRADE (1)
|
|
|
|
/**
|
|
* @brief: upgrade timer time out callback function
|
|
* @param time_id: id of the timer
|
|
* @param arg: argument for the timer callback method
|
|
*/
|
|
void iot_sg_sta_upgrade_func(timer_id_t timer_id, void *arg);
|
|
|
|
/**
|
|
* @brief: init sta upgrading module
|
|
*/
|
|
void iot_sg_sta_upgrade_init();
|
|
|
|
/**
|
|
* @brief: handle start upgrading command from CCo
|
|
* @param id: id of the upgrade session
|
|
* @param window: upgrading window in minute
|
|
* @param block_size: size of each upgrading data block
|
|
* @param file_size: size of the upgrading file
|
|
* @param block_cnt: file total block count
|
|
* @param file_crc: crc of the whole upgrading file
|
|
* @param rsp_flag: 1 - response, 0 - don't response
|
|
* @param session_type: start upgrade session proto type,
|
|
* see - IOT_SG_STA_UPGRADE_SESSION_TYPE_XXX
|
|
* @retval: IOT_PLC_UPGRADE_OK if succeed. other value defined by
|
|
* IOT_PLC_UPGRADE_XXX for failed case.
|
|
*/
|
|
uint32_t iot_sg_sta_handle_start_upgrade(uint32_t id, uint16_t window,
|
|
uint16_t block_size, uint32_t file_size, uint16_t block_cnt,
|
|
uint32_t file_crc, uint8_t rsp_flag, uint8_t session_type);
|
|
|
|
/**
|
|
* @brief: handle upgrade execute command from CCo
|
|
* @param id: upgrading session id
|
|
* @param reset_delay: seconds to delay after receiving the execute command
|
|
* @param trail_run_dur: trail run duration, in minutes. 0 means no trail run.
|
|
* @param rsp_flag: 1 - response, 0 - don't response
|
|
*/
|
|
void iot_sg_sta_handle_upgrade_execute(uint32_t id, uint16_t reset_dur,
|
|
uint32_t trail_run_dur, uint8_t rsp_flag);
|
|
|
|
/**
|
|
* @brief: handle stop upgrade command from CCo
|
|
* @param id: id of the upgrade session in stop command from CCo
|
|
* @param rsp_flag: 1 - response, 0 - don't response
|
|
*/
|
|
void iot_sg_sta_handle_stop_upgrade(uint32_t id, uint8_t rsp_flag);
|
|
|
|
/**
|
|
* @brief: handle upgrading data form CCo. It always consumes the iot_pkt.
|
|
* @param id: id of the upgrade session
|
|
* @param block_size: size of each upgrading data block
|
|
* @param seq: sn of the data block
|
|
* @param data: buffer containing upgrade data from CCo
|
|
* @param pkt: pkt containing data. data pointer to buf in this pkt.
|
|
* @param rsp_flag: 1 - response, 0 - don't response
|
|
* @retval: IOT_PLC_UPGRADE_OK if succeed. other value defined by
|
|
* IOT_PLC_UPGRADE_XXX for failed case.
|
|
*/
|
|
uint32_t iot_sg_sta_handle_upgrade_data(uint32_t id, uint16_t block_size,
|
|
uint32_t seq, uint8_t *data, iot_pkt_t *pkt, uint8_t rsp_flag);
|
|
|
|
/**
|
|
* @brief: send local broadcast when upgrading file data in it
|
|
* @param id: id of the upgrade session
|
|
* @param seq: sequence number of the data block
|
|
* @param data: buffer containing upgrade data from CCo
|
|
* @param len: length of data in the buffer, it's also the block_size
|
|
*/
|
|
void iot_sg_sta_gw_upgrade_local_bcast(uint32_t id, uint32_t seq,
|
|
uint8_t* data, uint16_t len);
|
|
|
|
/**
|
|
* @brief: handle upgrade timer event
|
|
*/
|
|
void iot_sg_sta_upgrade_timer_handler();
|
|
|
|
/**
|
|
* @brief: handle query upgrading status command from CCo
|
|
* @param id: id of the upgrade session
|
|
* @param start_seq: start sn of block to query
|
|
* @param cn: count of blocks to query
|
|
* @param session_type: query upgrade status session proto type,
|
|
* see - IOT_SG_STA_UPGRADE_SESSION_TYPE_XXX
|
|
*/
|
|
void iot_sg_sta_handle_upgrade_query_status(uint32_t id, uint32_t start_seq,
|
|
uint16_t cnt, uint8_t session_type);
|
|
|
|
/**
|
|
* @brief: handle STA leaving message.
|
|
*/
|
|
void iot_sg_sta_upgrade_on_leave();
|
|
|
|
/**
|
|
* @brief: handle STA join message.
|
|
* @param new_nw_joined: if STA joined a new network. new CCo addr, new nid
|
|
or new network_sn indicates a new network.
|
|
*/
|
|
void iot_sg_sta_upgrade_on_join(uint32_t new_nw_joined);
|
|
|
|
/**
|
|
* @brief: check if STA received all data blocks for upgrading
|
|
* @retval: 1 if all block of the upgrading file are received.
|
|
* 0 if not all blocks are received.
|
|
*/
|
|
uint32_t iot_sg_sta_recv_all_block();
|
|
|
|
/**
|
|
* @brief: query sta upgrade file block bitmap
|
|
* @param start_seq: query start block sequence number.
|
|
* @param cnt: query block count.
|
|
* @param iot_pkt_t: malloc the bitmap pkt, this bitmap of parts start_seq to
|
|
* (start_seq + cnt) from the original bitmap.
|
|
*/
|
|
iot_pkt_t *iot_sg_sta_get_recv_bitmap(uint32_t start_seq, uint16_t cnt);
|
|
|
|
/**
|
|
* @brief: sta handle file segment upgrade.
|
|
* @param action: upgrade action, see IOT_SG_STA_SEG_UPGRADE_ACTION_XXX.
|
|
* @param session_type: upgrade session type,
|
|
* see IOT_SG_STA_UPGRADE_SESSION_TYPE_XXX.
|
|
* @param seg_index: index of the file segment.
|
|
* @param total_seg_cnt: file segment toatl count.
|
|
* @param seg_data: file segment data.
|
|
* @param seg_len: file segment data len.
|
|
* @param allow_skip: flag to allow skip upgrade.
|
|
* @param window: upgrading window in minute
|
|
* @return: ERR_OK - for success case.
|
|
* @return: ERR_INVAL - for failed case.
|
|
*/
|
|
uint32_t iot_sg_sta_upgrade_handle_file_segment(uint8_t action,
|
|
uint8_t session_type, uint16_t seg_index, uint16_t total_seg_cnt,
|
|
uint8_t *seg_data, uint16_t seg_len, uint8_t allow_skip, uint16_t window);
|
|
|
|
/**
|
|
* @brief: clear upgrade info and status
|
|
* @param upgrade_id: upgrade id
|
|
* @param cancel_commit: flag indicating if cancel ongoing commit
|
|
*/
|
|
void iot_sg_sta_upgrade_clear(uint32_t upgrade_id, uint32_t cancel_commit);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* IOT_SG_STA_UPGRADE_H */
|