141 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			141 lines
		
	
	
		
			4.5 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 __PLC_CONN_LESS_H
							 | 
						||
| 
								 | 
							
								#define __PLC_CONN_LESS_H
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* os shim includes */
							 | 
						||
| 
								 | 
							
								#include "os_types.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#include "iot_config.h"
							 | 
						||
| 
								 | 
							
								#include "iot_utils_api.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								extern "C" {
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_APP_PORT              0x11
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_APP_ID_CONFIG_ACK     0xFF02
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define the priority of configuring ack messages */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_CONFIG_ACK_PRIO       3
							 | 
						||
| 
								 | 
							
								/* define the retry cnt of configuring ack messages */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_CONFIG_ACK_RETRY_CNT  5
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* defining function code */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_FN_CTRL               10
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_FN_DATA_TRANS         11
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* defining the minimum duration of configuring connectionless mode,
							 | 
						||
| 
								 | 
							
								 * uint is 1s.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_MODE_DUR_MIN          30
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* defining the duration of clearing msdu cache in connectionless mode,
							 | 
						||
| 
								 | 
							
								 * uint is 1ms.
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_MODE_CLEAR_MSDU_DUR   (5 * 60 * 1000)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* define target device type ID */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_TARGET_ID_CCO     0
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_TARGET_ID_STA     1
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* defining target device type identifier mask */
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_TARGET_ID_MSK_CCO (1 << PLC_CONN_LESS_TARGET_ID_CCO)
							 | 
						||
| 
								 | 
							
								#define PLC_CONN_LESS_TARGET_ID_MSK_STA (1 << PLC_CONN_LESS_TARGET_ID_STA)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* pack for the structures in the whole file */
							 | 
						||
| 
								 | 
							
								#pragma pack(push)  /* save the pack status */
							 | 
						||
| 
								 | 
							
								#pragma pack(1)     /* 1 byte align */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* connectionless data packet header */
							 | 
						||
| 
								 | 
							
								typedef struct _plc_conn_less_hdr {
							 | 
						||
| 
								 | 
							
								    /* source address */
							 | 
						||
| 
								 | 
							
								    uint8_t     src_mac[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* destination address */
							 | 
						||
| 
								 | 
							
								    uint8_t     dst_mac[IOT_MAC_ADDR_LEN];
							 | 
						||
| 
								 | 
							
								    /* function code */
							 | 
						||
| 
								 | 
							
								    uint16_t    fn      :4,
							 | 
						||
| 
								 | 
							
								    /* payload length */
							 | 
						||
| 
								 | 
							
								                len     :12;
							 | 
						||
| 
								 | 
							
								    /* payload label */
							 | 
						||
| 
								 | 
							
								    uint8_t     data[0];
							 | 
						||
| 
								 | 
							
								} plc_conn_less_hdr_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _plc_conn_less_ext_config {
							 | 
						||
| 
								 | 
							
								    /* flag to mark if rf_option and rf_channel config is available */
							 | 
						||
| 
								 | 
							
								    uint8_t     rf_valid            :1,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if rf_tx_power config is available */
							 | 
						||
| 
								 | 
							
								                rf_power_valid      :1,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if hplc_tx_power config is available */
							 | 
						||
| 
								 | 
							
								                hplc_power_valid    :1,
							 | 
						||
| 
								 | 
							
								    /* rf tx only for app */
							 | 
						||
| 
								 | 
							
								                rf_tx_only          :1,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                rsvd1               :4;
							 | 
						||
| 
								 | 
							
								    /* rf option, see IOT_PLC_RF_OPTION_XX */
							 | 
						||
| 
								 | 
							
								    uint8_t     rf_option;
							 | 
						||
| 
								 | 
							
								    /* rf channel, see IOT_PLC_OPTION1_CHANNEL_ID_XX */
							 | 
						||
| 
								 | 
							
								    uint8_t     rf_channel;
							 | 
						||
| 
								 | 
							
								    /* tx power of rf, unit is 1 dbm */
							 | 
						||
| 
								 | 
							
								    int8_t      rf_tx_power;
							 | 
						||
| 
								 | 
							
								    /* tx power of hplc, unit is 1 dbuv */
							 | 
						||
| 
								 | 
							
								    uint8_t     hplc_tx_power;
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								    uint8_t     rsvd2[5];
							 | 
						||
| 
								 | 
							
								} plc_conn_less_ext_config_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								typedef struct _plc_conn_less_mode_config {
							 | 
						||
| 
								 | 
							
								    /* band ID to be configured, see BEACON_FREQ_BAND_ID_XXX */
							 | 
						||
| 
								 | 
							
								    uint8_t     band_id;
							 | 
						||
| 
								 | 
							
								    /* configuring effective duration, uint is 1s */
							 | 
						||
| 
								 | 
							
								    uint8_t     dur;
							 | 
						||
| 
								 | 
							
								    /* the target device ID group that needs to respond to this command.
							 | 
						||
| 
								 | 
							
								     * see PLC_CONN_LESS_TARGET_ID_MSK_XXX.
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								    uint32_t    target_id_mask      :2,
							 | 
						||
| 
								 | 
							
								    /* reserved for future */
							 | 
						||
| 
								 | 
							
								                reserved            :29,
							 | 
						||
| 
								 | 
							
								    /* flag to mark if ext config is enabled.
							 | 
						||
| 
								 | 
							
								     * 1 means enable, 0 means disable
							 | 
						||
| 
								 | 
							
								     */
							 | 
						||
| 
								 | 
							
								                ext_cfg_en          :1;
							 | 
						||
| 
								 | 
							
								    /* ext configuration */
							 | 
						||
| 
								 | 
							
								    plc_conn_less_ext_config_t ext_cfg[0];
							 | 
						||
| 
								 | 
							
								} plc_conn_less_mode_config_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* connectionless application protocol frame header */
							 | 
						||
| 
								 | 
							
								typedef struct _plc_conn_less_app_hdr {
							 | 
						||
| 
								 | 
							
								    uint8_t     port;
							 | 
						||
| 
								 | 
							
								    uint16_t    id;
							 | 
						||
| 
								 | 
							
								    uint8_t     data[0];
							 | 
						||
| 
								 | 
							
								} plc_conn_less_app_hdr_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/* configuration acknowledgement message */
							 | 
						||
| 
								 | 
							
								typedef struct _plc_conn_less_app_config_ack {
							 | 
						||
| 
								 | 
							
								    /* current working band ID */
							 | 
						||
| 
								 | 
							
								    uint8_t band_id;
							 | 
						||
| 
								 | 
							
								} plc_conn_less_app_config_ack_t;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#pragma pack(pop)
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#ifdef __cplusplus
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								#endif
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#endif
							 |