Files
kunlun/plc/inc/mme/plc_mme_assoc.h

613 lines
21 KiB
C
Raw Normal View History

2024-09-28 14:24:04 +08:00
/****************************************************************************
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_MME_ASSOC_H
#define PLC_MME_ASSOC_H
/* os shim includes */
#include "os_types_api.h"
/* plc includes */
#include "plc_fr.h"
#include "plc_mme.h"
#include "plc_mme_auth.h"
#include "plc_utils.h"
#include "plc_protocol.h"
/* common includes */
#include "iot_utils_api.h"
#ifdef __cplusplus
extern "C" {
#endif
/* pack for the structures in the whole file */
#pragma pack(push) /* save the pack status */
#pragma pack(1) /* 1 byte align */
/* route information */
typedef struct _route_info {
/* directly connected STA count */
uint16_t dc_sta_cnt;
/* directly connected proxy count */
uint16_t dc_proxy_cnt;
/* size of the route table */
uint16_t route_table_size;
uint16_t reserved;
/* variable length route table */
uint8_t rt_table[0];
} route_info_t;
typedef struct _sta_info {
/* mac address of the STA */
uint8_t mac_addr[IOT_MAC_ADDR_LEN];
/* TEI assigned to the STA */
uint16_t tei :12,
rsvd :2,
/* assigned sta logical phase */
l_phase :2;
} sta_info_t;
/* Associate result codes */
/* associate / re-associate successfully */
#define ASSOC_SUCCESS 0x00
#define RE_ASSOC_SUCCESS 0x0A
/* associate failed codes */
#define AF_STA_NOT_IN_WHITELIST 0x01
#define AF_STA_IN_BLACKLIST 0x02
#define AF_STA_EXCEED_MAX_COUNT 0x03
#define AF_WHITELIST_NOT_SET 0x04
#define AF_PROXY_EXCEED_MAX_COUNT 0x05
#define AF_SUB_STA_EXCEED_MAX_COUNT 0x06
#define AF_DUPLICATE_MAC 0x08
#define AF_TOPO_LEVEL_EXCEED_MAX_COUNT 0x09
#define AF_SUB_STA_AS_PROXY 0x0B
#define AF_LOOP_EXIST_IN_TOPO 0x0C
#define AF_UNKNOWN_CCO_ERROR 0x0D
#define AF_PROXY_EXCEED_MAX_COUNT_RF 0x0E
/* IEEE1901 associate result codes */
/* associate, re-associate successfully */
#define I1901_ASSOC_SUCCESS 0x00
#define I1901_RE_ASSOC_SUCCESS 0x08
/* associate failed codes */
#define I1901_AF_STA_NOT_IN_WHITELIST 0x01
#define I1901_AF_STA_EXCEED_MAX_COUNT 0x02
#define I1901_AF_WHITELIST_NOT_SET 0x03
#define I1901_AF_PROXY_EXCEED_MAX_COUNT 0x04
#define I1901_AF_SUB_STA_EXCEED_MAX_COUNT 0x05
#define I1901_AF_DUPLICATE_MAC 0x06
#define I1901_AF_TOPO_LEVEL_EXCEED_MAX_COUNT 0x07
#define I1901_AF_SUB_STA_AS_PROXY 0x09
#define I1901_AF_LOOP_EXIST_IN_TOPO 0x0A
#define I1901_AF_UNKNOWN_CCO_ERROR 0x0B
/* max STA count of gather assoc request */
#define GATHER_ASSOC_REQ_CNT_MAX 16
/* boot version definition */
/* normal boot up */
#define SYSTEM_BOOT_REASON_NORMAL 0x00
/* power down reboot */
#define SYSTEM_BOOT_REASON_CUT_POWER 0x01
/* watch dog reboot */
#define SYSTEM_BOOT_REASON_WATCH_DOG 0x02
/* abnormal pointer exception reboot */
#define SYSTEM_BOOT_REASON_POINTER_ERR 0x03
#define CHIP_ID_SERIAL_NUM_LEN 5
#define CHIP_ID_CRC_LEN 8
/* vendor specific info in assoc request, must be 18 bytes length */
typedef struct _mme_vendor_info {
/* build version info */
uint32_t build_ver;
/* zero-cross ntb */
uint32_t zc_ntb;
union {
/* vendor info param, the same as the following field */
uint32_t info_param;
struct {
/* flag to mark if tsfm info is valid */
uint32_t tsfm_valid :1,
/* last network selection start reason */
start_reason :6,
/* firmware version type, 0 - release, 1 - debug */
ver_type :1,
/* layout definition */
mtd_type :4,
/* flag to mark if psram enabled */
psram_enable :1,
/* flag to mark if zc edge is falling */
zc_edge_is_falling :1,
/* flag to mark if support large number of directly
* connected sub-sta
*/
sub_sta_large :1,
/* reserved for future */
rsvd :1,
/* mark to make sure CCO and STA are belong to same vendor */
vendor_mark :16;
};
};
union {
/* tsfm address info */
uint8_t tsfm_addr[IOT_MAC_ADDR_LEN];
/* CRC MME */
struct {
/* reserved for future */
uint8_t rsvd2[4];
/* crc16 */
uint16_t crc16;
};
};
} mme_vendor_info_t;
typedef struct _mme_ver_info {
/* see SYSTEM_BOOT_REASON_XXX */
uint8_t boot_reason;
/* boot version */
uint8_t boot_ver;
/* software version */
uint16_t sw_ver;
/* software build time */
uint16_t build_time_y :7,
build_time_m :4,
build_time_d :5;
/* module vendor ID */
uint16_t vendor_id;
/* chip ID */
uint16_t chip_id;
} mme_ver_info_t;
/* chip id information */
typedef struct _mme_chip_id_t {
uint8_t check_code[CHIP_ID_CRC_LEN];
uint8_t dev_code[CHIP_ID_SERIAL_NUM_LEN];
uint16_t chip_mode;
uint16_t vendor;
/* device bandwidth type, see PLC_DEV_BAND_TYPE_XXX */
uint8_t dev_type;
uint8_t hd4_3;
uint8_t hd4_2;
uint8_t hd4_1;/* fixed value: 0x01C1FB */
uint8_t hd3; /* fixed value: 0x9C */
uint8_t hd2; /* fixed value: 0x02 */
uint8_t hd1; /* fixed value: 0x01 */
} mme_chip_id_t;
/* Associate Request MME */
typedef struct _mme_assoc_req {
/* mac address of the station that initiated the assoc request */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* candidate proxy list */
pco_link_info_t proxy[CANDIDATE_PROXY_COUNT];
/* estimated power line phase */
uint8_t phase_1 :2;
uint8_t phase_2 :2;
uint8_t phase_3 :2;
uint8_t reserved_1 :2;
/* device type. see PLC_DEV_TYPE_XXX */
uint8_t device_type;
/* mac address type. see PLC_MAC_ADDR_TYPE_XXX */
uint8_t mac_addr_type;
/* device communication type, see PLC_DEV_COMM_TYPE_XXX */
uint8_t comm_type :2,
reserved_2 :6;
/* station association random number */
uint32_t random;
/* vendor specific info */
mme_vendor_info_t vendor_info;
/* version info */
mme_ver_info_t ver_info;
/* hardware reset count */
uint16_t hard_reset_cnt;
/* software reset count */
uint16_t soft_reset_cnt;
/* proxy type. must be 0 */
uint8_t proxy_type;
/* this 2 bytes reserved in spec, extend it for private spec.
* simple pair passcode value. Only same passcode CCO and STA can be
* associated.
*/
uint16_t passcode;
/* reserved for future */
uint8_t reserved_3;
/* peer to peer sequence number */
uint32_t p2p_sn;
#if (!SUPPORT_IEEE_1901)
/* management id to identify each chip */
mme_chip_id_t manage_id;
/* following mme_assoc_req_ext_t if the state grid encryption
* authentication is supported
*/
#endif
} mme_assoc_req_t;
/* Associate Request EXT MME */
typedef struct _mme_assoc_req_ext {
/* station mac address encrypted with cmk, and IV vector is the first 12
* bytes in mme_assoc_req_t
*/
uint8_t cmk_mac[MME_ENCRYPT_CMK_LEN];
} mme_assoc_req_ext_t;
/* sub direct sta structure */
typedef struct _sub_d_sta_t {
/* tei of sta */
uint16_t tei :12,
/* link type between station and proxy, see PLC_LINK_TYPE_XXX */
link :1,
/* reserved for future */
rsvd :3;
} sub_d_sta_t;
/* proxy information */
typedef struct _proxy_info {
/* tei of directly connected proxy */
uint16_t dc_proxy :12,
/* link type between station and proxy, see PLC_LINK_TYPE_XXX */
link :1,
rsvd :3;
/* count of sub STA under this proxy */
uint16_t sub_sta_cnt;
/* TEIs of sub STAs under this proxy */
tei_t sub_sta_tei[0];
} proxy_info_t;
/* Associate Confirm MME */
typedef struct _mme_assoc_cnf {
/* mac address of the station that this assoc conf for */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* mac address of CCo */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* result of the associate request */
uint8_t result;
/* level info */
uint8_t sta_level;
/* TEI assigned to the requesting STA */
uint16_t sta_tei :12,
/* link type between station and proxy, see PLC_LINK_TYPE_XXX */
link :1,
/* hplc frequency band, see BEACON_FREQ_BAND_ID_XXX */
freq_band :2,
rsvd1 :1;
/* TEI of the appointed the PCO */
uint16_t proxy_tei :12,
rsvd2 :4;
/* packet count fragmented into */
uint8_t packet_cnt;
/* packet sequence number */
uint8_t packet_sn;
/* random number as the one in assoc request */
uint32_t random;
/* time interval for next assoc request. unit is 1ms */
uint32_t re_assoc_time;
/* same as the p2p_sn in assoc request */
uint32_t p2p_sn;
/* path number for route entry update */
uint32_t path_number;
union {
struct {
/* reserve for future */
uint8_t rsvd3;
/* join check code */
uint16_t join_check_code;
/* reserve for future */
uint8_t rsvd4;
};
struct {
/* this 4 bytes reserved in spec, extend it for private spec */
uint16_t rsvd5 :12,
/* assigned sta logical phase */
l_phase :2,
/* flag to mark if pco change nack supported.
* see PLC_SUPPORT_PROXY_CHG_NACK for more info.
*/
pco_chg_nack:1,
/* flag to mark if the sta is in white list */
in_wl :1;
union {
/* mark to make sure CCO and STA are belong to same vendor */
uint16_t vendor_mark;
/* crc16 for CRC MME */
uint16_t crc16;
};
};
};
/* route info */
route_info_t route_info;
/* following mme_assoc_cnf_ext_t if the state grid encryption
* authentication is supported
*/
} mme_assoc_cnf_t;
/* Associate Confirm EXT MME */
typedef struct _mme_assoc_cnf_ext {
/* communication encryption key encrypted with cmk, and IV vector is
* the first 12 bytes in mme_assoc_cnf_t or mme_assoc_gather_ind_t
*/
uint8_t cek[MME_ENCRYPT_CEK_LEN];
/* communication encryption key sequence */
uint8_t cek_seq :2,
/* reserved for future */
rsvd :6;
/* cek remaining valid time, unit is 10s */
uint16_t cek_left_dur;
} mme_assoc_cnf_ext_t;
/* Associate Gather Indicate MME */
typedef struct _mme_assoc_gather_ind {
/* result of the assoc request. must be 0 */
uint8_t result;
/* level info */
uint8_t sta_level;
/* mac address of CCo */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* TEI of the appointed PCO */
uint16_t proxy :12,
/* hplc frequency band, see BEACON_FREQ_BAND_ID_XXX */
freq_band :2,
rsvd1 :2;
/* this 1 byte is reserved in spec, extend it for private spec */
/* flag to mark if pco change nack supported.
* see PLC_SUPPORT_PROXY_CHG_NACK for more info.
*/
uint8_t pco_chg_nack :1,
rsvd2 :7;
/* STA count in gather indication packet */
uint8_t sta_cnt;
union {
struct {
/* reserve for future */
uint8_t rsvd3;
/* join check code */
uint16_t join_check_code;
/* reserve for future */
uint8_t rsvd4;
};
struct {
/* this 4 bytes reserved in spec, extend it for private spec */
/* in white list flag bitmap for each sta in the sta_info */
uint8_t in_wl_bm[2];
union {
/* mark to make sure CCO and STA are belong to same vendor */
uint16_t vendor_mark;
/* crc16 for CRC MME */
uint16_t crc16;
};
};
};
/* station info */
sta_info_t sta_info[0];
/* following mme_assoc_cnf_ext_t if the state grid encryption
* authentication is supported
*/
} mme_assoc_gather_ind_t;
/* Associate Request MME */
typedef struct _spg_mme_assoc_req {
/* station mac address */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* candidate proxy list */
tei_t proxy[CANDIDATE_PROXY_COUNT];
/* estimated power line phase */
uint8_t phase_1;
uint8_t phase_2;
uint8_t phase_3;
/* device type, see PLC_DEV_TYPE_XXXX */
uint8_t device_type;
/* this 2 bytes reserved in spec, extend it for private spec.
* simple pair passcode value. Only same passcode CCO and STA can be
* associated.
*/
uint16_t passcode;
/* mac address_type, see PLC_MAC_ADDR_TYPE_XXXX */
uint8_t mac_addr_type;
/* device communication type, see PLC_DEV_COMM_TYPE_XXX */
uint8_t comm_type : 2,
/* candidate proxy 0 link type */
cand_pco_link0 : 1,
/* candidate proxy 1 link type */
cand_pco_link1 : 1,
/* candidate proxy 2 link type */
cand_pco_link2 : 1,
/* candidate proxy 3 link type */
cand_pco_link3 : 1,
/* candidate proxy 4 link type */
cand_pco_link4 : 1,
/* reserved for future */
reserved_1 : 1;
/* random number retrieved when first power on */
uint32_t random;
/* vendor specific info */
mme_vendor_info_t vendor_info;
/* version info */
mme_ver_info_t ver_info;
/* hardware reset count */
uint16_t hard_reset_cnt;
/* software reset count */
uint16_t soft_reset_cnt;
/* proxy type. must be 2 */
uint8_t proxy_type;
/* network sequence number */
uint8_t network_sn;
/* reserved according to spec */
uint8_t reserved_2 : 1,
/* mme version */
mm_ver : 4,
/* reserved according to spec */
reserved_3 : 3;
/* sta working freq band identification, 0 - support band 0/1, 1 - support
* band 0/1/2.
*/
uint8_t fb_ident : 2,
/* reserved according to spec */
reserved_4 : 6;
/* peer to peer sequence number */
uint32_t p2p_sn;
} spg_mme_assoc_req_t;
/* Associate Confirm MME */
typedef struct _spg_mme_assoc_cnf {
/* mac address of the station that this assoc conf for */
uint8_t mac[IOT_MAC_ADDR_LEN];
/* result of the associate request */
uint8_t result;
/* STA level */
uint8_t sta_level;
/* TEI assigned to the requesting STA */
tei_t sta_tei;
/* TEI of the appointed the PCO */
tei_t proxy_tei;
/* packet count fragmented into */
uint8_t packet_cnt;
/* packet sequence number */
uint8_t packet_sn;
/* last packet fragmented flag */
uint8_t last_packet_flag;
/* link type between station and proxy, see PLC_LINK_TYPE_XXX */
uint8_t link :1,
/* hplc frequency band, see BEACON_FREQ_BAND_ID_XXX */
freq_band :2,
/* reserved for future */
rsvd1 :5;
/* random number as the one in assoc request */
uint32_t random;
/* time interval for next assoc request. unit is 1ms */
uint32_t re_assoc_time;
/* same as the p2p_sn in assoc request */
uint32_t p2p_sn;
/* path number for route entry update */
uint32_t path_number;
/* network sequence number */
uint8_t network_sn;
/* mme version */
uint8_t mm_ver :4,
/* flag to mark if assoc index message should be sent on detection band,
* 0 - working band, 1 - detection band
*/
fb_detect_flag :1,
resv3 :1,
/* flag to mark if pco change nack supported.
* see PLC_SUPPORT_PROXY_CHG_NACK for more info.
*/
pco_chg_nack:1,
/* flag to mark if the sta is in white list */
in_wl :1;
/* this 2 bytes reserved in spec, extend it for private spec */
/* mark to make sure CCO and STA are belong to same vendor */
uint16_t vendor_mark;
/* route info */
route_info_t route_info;
} spg_mme_assoc_cnf_t;
/* Associate Indicate MME */
typedef struct _spg_mme_assoc_ind {
/* result of the associate request */
uint8_t result;
/* STA level */
uint8_t sta_level;
/* mac address of the station that this assoc indicate for */
uint8_t sta_mac[IOT_MAC_ADDR_LEN];
/* mac address of CCo */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* TEI assigned to the requesting STA */
tei_t sta;
/* TEI of the appointed the PCO */
tei_t proxy;
/* link type between station and proxy, see PLC_LINK_TYPE_XXX */
uint8_t link :1,
/* hplc frequency band, see BEACON_FREQ_BAND_ID_XXX */
freq_band :2,
/* reserved for future */
rsvd1 :5;
uint8_t rsvd2[2];
/* packet sequence number */
uint8_t packet_sn;
/* packet count fragmented into */
uint8_t packet_cnt;
/* last packet fragmented flag */
uint8_t last_packet_flag;
/* random number as the one in assoc request */
uint32_t random;
uint8_t rsvd3[17];
/* network sequence number */
uint8_t network_sn;
uint16_t rsvd4;
/* time interval for next assoc request. unit is 1ms */
uint32_t re_assoc_time;
/* same as the p2p_sn in assoc request */
uint32_t p2p_sn;
uint32_t rsvd5[1];
/* this 4 bytes reserved in spec, extend it for private spec */
uint32_t rsvd6 :14,
/* flag to mark if pco change nack supported.
* see PLC_SUPPORT_PROXY_CHG_NACK for more info.
*/
pco_chg_nack :1,
/* flag to mark if the sta is in white list */
in_wl :1,
/* mark to make sure CCO and STA are belong to same vendor */
vendor_mark :16;
/* route info */
route_info_t route_info;
} spg_mme_assoc_ind_t;
/* Associate Gather Indicate MME */
typedef struct _spg_mme_assoc_gather_ind {
/* result of the assoc request, set to 0. */
uint8_t result;
/* sta level */
uint8_t sta_level;
/* mac address of CCo */
uint8_t cco_mac[IOT_MAC_ADDR_LEN];
/* TEI of the STA assigned as the PCO */
tei_t proxy;
/* network sequence number */
uint8_t network_sn;
/* STA count in gather indication packet */
uint8_t sta_cnt;
/* hplc frequency band, see BEACON_FREQ_BAND_ID_XXX */
uint8_t freq_band :2,
/* reserved for future */
rsvd1 :6;
/* reserved according to spec */
uint8_t rsvd2[10];
/* flag to mark if pco change nack supported.
* see PLC_SUPPORT_PROXY_CHG_NACK for more info.
*/
uint8_t pco_chg_nack :1,
rsvd3 :7;
/* this 4 bytes reserved in spec, extend it for private spec */
/* in white list flag bitmap for each sta in the sta_info */
uint8_t in_wl_bm[2];
/* mark to make sure CCO and STA are belong to same vendor */
uint16_t vendor_mark;
/* station info list */
sta_info_t sta_info[0];
} spg_mme_assoc_gather_ind_t;
#pragma pack(pop) // restore the pack status
#ifdef __cplusplus
}
#endif
#endif /* PLC_MME_ASSOC_H */