398 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			398 lines
		
	
	
		
			13 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_CLI_HOST_UPGRADE_INTERNAL_H
 | ||
|  | #define IOT_CLI_HOST_UPGRADE_INTERNAL_H
 | ||
|  | 
 | ||
|  | /* os shim includes */ | ||
|  | #include "os_types.h"
 | ||
|  | #include "os_utils_api.h"
 | ||
|  | 
 | ||
|  | #include "iot_version_api.h"
 | ||
|  | 
 | ||
|  | #include "upgrade.h"
 | ||
|  | #include "iot_plc_led_api.h"
 | ||
|  | 
 | ||
|  | #include "iot_cli_host_interface.h"
 | ||
|  | #include "iot_plc_msg_cco_api.h"
 | ||
|  | #include "iot_cli_msg.h"
 | ||
|  | #include "iot_errno.h"
 | ||
|  | #include "iot_config.h"
 | ||
|  | #include "iot_crc.h"
 | ||
|  | #include "iot_io.h"
 | ||
|  | #include "iot_cli_common.h"
 | ||
|  | #include "iot_cli_upgrade.h"
 | ||
|  | #include "iot_cli_host_interface.h"
 | ||
|  | #include "iot_cli_host_upgrade.h"
 | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | extern "C" { | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #define IOT_SG_UPGRADE_MAX_FW_SIZE          ((444 + 64) * 1024)
 | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_print_block_info - print block info | ||
|  |  * @param data:       upgrade data pointer | ||
|  |  */ | ||
|  | void cli_upgrade_print_block_info(iot_plc_upgrade_data_dl_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_print_mac_info - print mac address | ||
|  |  * @param mac:        mac pointer | ||
|  |  */ | ||
|  | void cli_upgrade_print_mac_info(uint8_t *mac); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_type_check - check upgrade type | ||
|  |  * @param data:       upgrade data pointer | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_type_check(iot_plc_upgrade_start_dl_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_block_blank_check - check if upgrade block blank | ||
|  |  * @param file_type:    file type | ||
|  |  * @param block_index:  block index | ||
|  |  * @return 0            - not blank | ||
|  |  * @return 1            - blank | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_block_blank_check(uint8_t file_type, uint16_t block_index); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_pco_start - pco start upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_pco_start(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_data_check - check crc and block index | ||
|  |  * @param data:       upgrade data pointer | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_data_check(uint16_t block_cnt, uint16_t *block_idx_array, | ||
|  |     uint16_t *block_size_array, uint8_t *data, uint8_t file_type); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_initialize_latest_block - initialize latest block | ||
|  |  * info | ||
|  |  */ | ||
|  | void cli_remote_upgrade_initialize_latest_block(); | ||
|  | 
 | ||
|  | void cli_remote_upgrade_sta_initialize( | ||
|  |     uint8_t upgrade_type, uint16_t block_size, uint16_t remote_block_size, | ||
|  |     uint32_t fw_size, uint32_t pib_size, uint32_t cus_size, | ||
|  |     uint32_t fw_checksum, uint32_t pib_checksum, uint32_t cus_checksum, | ||
|  |     uint16_t time_window, uint16_t remote_block_cnt); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_info_initialize - initialize upgrade info | ||
|  |  * @param data:       upgrade data pointer | ||
|  |  */ | ||
|  | void cli_upgrade_info_initialize(iot_plc_upgrade_start_dl_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_flash_info_initialize - initialize flash info | ||
|  |  * @param data:       upgrade data pointer | ||
|  |  * @return result:    0 - successful, 1 - fail | ||
|  |  */ | ||
|  | uint32_t cli_upgrade_flash_info_initialize(uint16_t block_size, | ||
|  |     uint32_t fw_size, uint16_t pib_size, uint16_t cus_size, uint32_t upgrade_id, | ||
|  |     uint32_t fw_checksum, uint32_t pib_checksum, uint32_t cus_checksum, | ||
|  |     uint32_t fw_version); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_read_data_from_buffer - read data from buffer | ||
|  |  * @param file_type:    file type, see UPGRADE_DATA_TYPE_XXX | ||
|  |  * @param offset:       offset of the data | ||
|  |  * @param data:         read data pointer | ||
|  |  * @param data_len:     read data len | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_read_data_from_buffer(uint8_t file_type, uint32_t offset, | ||
|  |     uint8_t *data, uint16_t data_len); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_read_data_from_flash - read data from flash | ||
|  |  * @param file_type:    file type, see UPGRADE_DATA_TYPE_XXX | ||
|  |  * @param offset:       offset of the data | ||
|  |  * @param data:         read data pointer | ||
|  |  * @param data_len:     read data len | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_read_data_from_flash(uint8_t file_type, uint32_t offset, | ||
|  |     uint8_t *data, uint16_t data_len); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_write_data_to_buffer - write data to buffer | ||
|  |  * @param file_type:       file type, see UPGRADE_DATA_TYPE_XXX | ||
|  |  * @param block_cnt:       block count | ||
|  |  * @param block_idx_array: block idx array | ||
|  |  * @param block_size_array:block size array | ||
|  |  * @param data:            data of upgrade file | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_write_data_to_buffer(uint8_t file_type, uint16_t block_cnt, | ||
|  |     uint16_t *block_idx_array, uint16_t *block_size_array, uint8_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_write_data_to_flash - write data to flash | ||
|  |  * @param file_type:       file type, see UPGRADE_DATA_TYPE_XXX | ||
|  |  * @param block_cnt:       block count | ||
|  |  * @param block_idx_array: block idx array | ||
|  |  * @param block_size_array:block size array | ||
|  |  * @param data:            data of upgrade file | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint8_t cli_upgrade_write_data_to_flash(uint8_t file_type, uint16_t block_cnt, | ||
|  |     uint16_t *block_idx_array, uint16_t *block_size_array, uint8_t *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_write_data_to_flash_cache_init - init flash for cache | ||
|  |  *                      upgrade file. | ||
|  |  * @param upgrade_id:   upgrade id | ||
|  |  * @param fw_size:      fw size. | ||
|  |  * @param cus_size      cus_size. | ||
|  |  * @param block_size:   block size | ||
|  |  * @return 0          - for success case | ||
|  |  * @return otherwise  - error code | ||
|  |  */ | ||
|  | uint32_t cli_upgrade_write_data_to_flash_cache_init(uint32_t upgrade_id, | ||
|  |     uint32_t fw_size, uint32_t cus_sise, uint32_t block_size); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_start_sub_nodes - pco start sub nodes to upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_start_sub_nodes(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_send_data() -  cco/pco send cli upgrade data; | ||
|  |  * @param send_type: plc send type, see IOT_PLC_MSG_TYPE_XXX; | ||
|  |  * @param retry_cnt: plc retry count; | ||
|  |  * @param dst: dest mac address; | ||
|  |  * @param upgrade_id: upgrade id; | ||
|  |  * @param file_type: file type, see - UPGRADE_DATA_TYPE_XXX; | ||
|  |  * @param control_byte: control byte, see - UPGRADE_REMOTE_ALL_XXX; | ||
|  |  * @param block_size: block size; | ||
|  |  * @param block_idx_array: block idx array; | ||
|  |  * @param block_cnt: block count; | ||
|  |  * @param fwd_type: fwd type, see - UPGRADE_DATA_FORWARD_XXX. | ||
|  |  * @param bcast_tx_done_func upgrade bcast tx done callback. | ||
|  |  */ | ||
|  | void cli_remote_upgrade_send_data(uint8_t send_type, uint8_t retry_cnt, | ||
|  |     uint8_t *dst, uint32_t upgrade_id, uint8_t file_type, uint8_t control_byte, | ||
|  |     uint16_t block_size, uint16_t* block_idx_array, uint16_t block_cnt, | ||
|  |     uint8_t fwd_type, iot_pkt_free_func_t bcast_tx_done_func); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_check_data_recv_done - check if upgrade data recv done | ||
|  |  * @param file_type:  file type | ||
|  |  * @return true       - for recv done case | ||
|  |  * @return false      - for undone case | ||
|  |  */ | ||
|  | bool_t cli_upgrade_check_data_recv_done(uint8_t file_type); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_send_stop_rpt_notify - cco send stop report upgrade | ||
|  |  *                     result command to target pco/sta | ||
|  |  * @param dest_mac: mac of dest sta | ||
|  |  */ | ||
|  | void cli_remote_upgrade_send_stop_rpt_notify(uint8_t *dest_mac); | ||
|  | 
 | ||
|  | /**
 | ||
|  | * @brief cli_remote_upgrade_send_start_notify - cco send start notify to sta | ||
|  | * @param send_type: send type | ||
|  | * @param sta_mac: mac of sta to send | ||
|  | * @param dest_mac: mac of dest sta | ||
|  | * @param phase_flag: node send start cmd phase | ||
|  | */ | ||
|  | void cli_remote_upgrade_send_start_notify(uint8_t send_type, | ||
|  |     uint8_t *sta_mac, uint8_t *dest_mac, uint8_t phase_flag); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_is_unicast_to_broadcast - check is unicast to broadcast | ||
|  |  *                    download upgrade data. | ||
|  |  * @param data:       upgrade data pointer. | ||
|  |  * @return ERR_OK - is unicast to broadcast, others is not. | ||
|  |  */ | ||
|  | uint32_t cli_upgrade_is_unicast_to_broadcast( | ||
|  |     iot_plc_upgrade_remote_data_dl *data); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_calculate_time_window - calculate time window | ||
|  |  */ | ||
|  | uint16_t cli_remote_upgrade_calculate_time_window(uint16_t sub_node_cnt); | ||
|  | 
 | ||
|  | #if PLC_SUPPORT_CCO_ROLE
 | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_broadcast_start_sta_list - cco  broadcast start | ||
|  |  *                    to sta list. | ||
|  |  * @param first: first send start upgrade cmd flag. | ||
|  |  * @retval: ERR_OK - send ok, other continue pls. | ||
|  |  */ | ||
|  | uint32_t cli_remote_upgrade_broadcast_start_sta_list(bool_t first); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_buffer_initialize - cco initialize fw data buffer | ||
|  |  */ | ||
|  | void cli_upgrade_buffer_initialize(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_cco_broadcast_data - cco start broadcast data | ||
|  |  * @param first:      - if the first block | ||
|  |  */ | ||
|  | void cli_remote_upgrade_cco_broadcast_data(bool_t first); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_start - cco start upgrade sta | ||
|  |  */ | ||
|  | void cli_remote_upgrade_all_sta_start(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_sta_list_start - send upgrade start to sta | ||
|  |  */ | ||
|  | void cli_remote_upgrade_sta_list_start(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_destroy_buffer - cco destroy buffer for | ||
|  |  * remote upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_destroy_buffer(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_add_dest_info - add dest to dest_info | ||
|  |  * @param data:       mac pointer | ||
|  |  */ | ||
|  | iot_plc_upgrade_dest_desc_t *cli_upgrade_add_dest_info(uint8_t *mac); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_add_upgrade_list_dest_info - add dest to dest_info and | ||
|  |  *                    upgrade list dest info | ||
|  |  * @param node_mac:   list mac pointer | ||
|  |  * @param node_cnt:   list size | ||
|  |  * @param is_renew:   1 - clean upgrade list node, then add node to upgrade list | ||
|  |  *                    0 - continue add node to upgrade list. | ||
|  |  * @retval: add mac dest info total count. | ||
|  |  */ | ||
|  | uint16_t cli_upgrade_add_upgrade_list_dest_info( | ||
|  |     uint8_t *node_mac, uint16_t node_cnt, uint8_t is_renew); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_init_dest_info - cco init dest info for | ||
|  |  * remote upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_init_dest_info(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_destroy_dest_info - cco destroy dest info for | ||
|  |  * remote upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_destroy_dest_info(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_dest_info_reset - reset dest info upgrade param, | ||
|  |  * when begin cli upgrade. | ||
|  |  */ | ||
|  | void cli_remote_upgrade_dest_info_reset(); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_coo_stop - cco stop remote upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_coo_stop(); | ||
|  | #endif
 | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_get_next_block - get next block | ||
|  |  * @param file_type: file type | ||
|  |  * @param block_index: block index | ||
|  |  */ | ||
|  | bool_t cli_remote_upgrade_get_next_block(uint32_t file_type, | ||
|  |     uint32_t block_index); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_sta_send_upgrade_result - sta send result info | ||
|  |  * @param send_type:  send type | ||
|  |  * @param src_mac:  src mac | ||
|  |  * @param dst_mac:  dst mac | ||
|  |  * @param error_code:  error_code value | ||
|  |  */ | ||
|  | void cli_upgrade_sta_send_upgrade_result(uint8_t send_type, | ||
|  |     uint8_t *src_mac, uint8_t *dst_mac, uint8_t error_code); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_upgrade_sta_send_progress - sta send progress info | ||
|  |  * @param src_mac:  src mac | ||
|  |  * @param dst_mac:  dst mac | ||
|  |  * @param progress_value:  progress value | ||
|  |  */ | ||
|  | void cli_upgrade_sta_send_progress(uint8_t *src_mac, uint8_t *dst_mac, | ||
|  |     uint8_t progress_value); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_sta_send_request_data - sta request data from cco | ||
|  |  * @param phase3:   phase3 flag | ||
|  |  */ | ||
|  | void cli_remote_upgrade_sta_send_request_data(bool_t phase3); | ||
|  | 
 | ||
|  | /**
 | ||
|  |  * @brief cli_remote_upgrade_sta_complete - check if completed | ||
|  |  */ | ||
|  | void cli_remote_upgrade_sta_complete(); | ||
|  | 
 | ||
|  | /*
 | ||
|  |  * @brief cli_remote_upgrade_sta_stop - sta stop remote upgrade | ||
|  |  */ | ||
|  | void cli_remote_upgrade_sta_stop(); | ||
|  | 
 | ||
|  | /*
 | ||
|  |  * @brief cli_upgrade_send_stop_ack - send stop ack to plc manager | ||
|  |  * @param dest:       dest mac pointer | ||
|  |  * @param error_code: error code from sta | ||
|  |  */ | ||
|  | void cli_upgrade_send_stop_ack(uint8_t * mac, uint16_t error_code); | ||
|  | 
 | ||
|  | /*
 | ||
|  |  * @brief cli_upgrade_send_reset_ack - send reset ack to plc manager | ||
|  |  * @param dest:       dest mac pointer | ||
|  |  * @param error_code: error code from sta | ||
|  |  */ | ||
|  | void cli_upgrade_send_reset_ack(uint8_t * mac, uint16_t error_code); | ||
|  | 
 | ||
|  | /*
 | ||
|  |  * @brief cli_upgrade_reset_timer - reset upgrade timer | ||
|  |  * @param start:      1 - restart upgrade timer, 0 - not reset upgrade timer. | ||
|  |  * @param time_window: restart upgrade time window. | ||
|  |  */ | ||
|  | void cli_upgrade_reset_timer(uint8_t start, uint32_t time_window); | ||
|  | 
 | ||
|  | /*
 | ||
|  |  * @brief cli_remote_upgrade_bcast_tx_done_callback - bcast tx callback | ||
|  |  * @param param:      callback param. | ||
|  |  * @param state:      callback pkt state see IOT_PKT_STATE_XXX. | ||
|  |  */ | ||
|  | void cli_remote_upgrade_bcast_tx_done_callback(void *param, uint8_t state); | ||
|  | 
 | ||
|  | #ifdef __cplusplus
 | ||
|  | } | ||
|  | #endif
 | ||
|  | 
 | ||
|  | #endif
 |