Files
kunlun/plc/halmac/inc/beacon.h

222 lines
7.2 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 BEACON_H
#define BEACON_H
/* os shim includes */
#include "os_types_api.h"
#include "mac_bcm_api.h"
#include "plc_fr.h"
#include "iot_pkt_api.h"
#include "os_lock.h"
#include "iot_errno.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct _mac_beacon_cco_ctx_t {
uint8_t started;
/* current beacon period start ntb 64bit version */
uint64_t curr_start_ntb64;
/* next beacon period start ntb 64bit version */
uint64_t next_start_ntb64;
/* current beacon period count */
uint32_t curr_bp_cnt;
} mac_beacon_cco_ctx_t;
typedef struct _mac_beacon_sta_ctx_t {
/* flag to mark if sta role device ntb sync up with preferred cco before
* joining the network is done.
*/
uint8_t ntb_sync_done :1,
/* flag to mark if sw ntb sync enabled for each beacon period */
force_sw_sync :1,
/* flag to mark if reuse previous beacon period time slot allowed */
allow_reuse_ts :1,
/* flag phase a tx enable */
phase_a_tx :1,
/* flag phase b tx enable */
phase_b_tx :1,
/* flag phase c tx enable */
phase_c_tx :1,
/* flag to mark if discovery beacon send with non cco node info */
bc_d_with_non :1,
/* reserved for future */
rsvd :1;
} mac_beacon_sta_ctx_t;
typedef struct _sg_mac_bc_info {
mac_bc_fp_t payload_header;
mac_bc_sta_cap_t sta_cap;
mac_bc_rt_param_t route_param;
mac_bc_simple_param_t simple_param;
} sg_mac_bc_info_t;
typedef struct _spg_mac_bc_info {
mac_bc_fp_spg_t payload_header;
mac_bc_sta_cap_spg_t sta_cap;
mac_bc_rt_param_spg_t route_param;
mac_bc_simple_param_spg_t simple_param;
} spg_mac_bc_info_t;
typedef struct _mac_beacon_ctx_t {
uint8_t inited;
uint8_t nid_inited;
/* valid bcn entries in entry_sort */
uint8_t entry_sort_cnt;
void *ref_vdev_ptr;
/* beacon packet buffer */
iot_pkt_t* mac_beacon_buffer[PLC_PHASE_CNT];
/* enable only when rf is supported */
iot_pkt_t* mac_bcn_rf_buffer;
iot_pkt_t* unknown_entry;
/* tx desc for the beacon */
void *bcn_mpdu_start_desc;
mac_bc_fc_t fc;
mac_bc_freq_chg_t freq_chg;
mac_bc_rf_channel_chg_t rf_chg;
mac_bc_rf_route_t rf_route;
mac_bc_time_slot_t time_slot;
mac_bc_meter_t meter;
mac_bc_fb_detect_t fb_detect;
mac_bc_rtc_t rtc;
mac_bc_vendor_spec_t vendor;
#if IOT_HTBUS_EN
/* htbus beacon info descriptor */
mac_bc_htbus_time_slot_t ts_htbus;
mac_bc_htbus_user_data_t ud_htbus;
mac_bc_htbus_fp_t fp_htbus;
#endif /* IOT_HTBUS_EN */
union {
sg_mac_bc_info_t sg_uniq_bc_str;
spg_mac_bc_info_t spg_uniq_bc_str;
};
/* which component should be contained in the next beacon send */
uint8_t beacon_component_enable[MAC_BC_ENTRY_MAX];
#ifdef PLC_SUPPORT_CCO_ROLE
/* cco role only context */
mac_beacon_cco_ctx_t cco;
#endif /* PLC_SUPPORT_CCO_ROLE */
mac_beacon_sta_ctx_t sta;
/* the flag for detect beacon */
uint32_t is_tx_detect;
/* bcn entries fill order */
uint8_t entry_sort[MAC_BCN_SORT_MAX_CNT];
} mac_beacon_ctx_t;
/* init the beacon struct */
uint32_t mac_beacon_init(mac_beacon_ctx_t *mac_beacon, void* vdev_ptr);
/* @brief beacon payload to send, it would add some FC or PB info into the
* iot_pkt_t and to form an Beacon MPDU.
* @param proto: proto.
* @param proto_bandid: proto bandid.
* @param mac_beacon: beacon context pointer, from which beacon to fill
* @param bcn_buf: the buf of beacon to fill
*
* @return
* number of beacon sent in this request
*/
uint8_t mac_beacon_tx(uint32_t proto, uint32_t proto_bandid,
mac_beacon_ctx_t *mac_beacon, iot_pkt_t* bcn_buf);
/* reset the beacon ctx */
uint32_t mac_beacon_reset(mac_beacon_ctx_t *mac_beacon);
/*
* mac_beacon_rx() - mac layer beacon rx callback
* @proto: current protocol type. see PLC_PROTO_TYPE_XXX
* @vdev_ptr: mac vdev context for the rx
* @buf: pointer to buffer of the rx-ed beacon
*
* return:
* ERR_OK -- for success case
* ERR_INVAL -- error
*/
uint32_t mac_beacon_rx(uint8_t proto, void* vdev_ptr, iot_pkt_t* buf);
/*
* @brief update beacon payload to be broadcast by mac.
* this function is similar to mac_update_beacon
* but can only be called inside mac context.
* @param pdev_id: mac pdev id of the device to be updated
* @param vdev_id: mac vdev id of the device to be updated
* @param ent: beacon entries to be updated
* @param tx_cnt: return beacon tx count of this update
*
* @return:
* 0 -- for success case
* othersie -- error code
*/
uint32_t mac_update_beacon_internal(uint8_t pdev_id, uint8_t vdev_id,
mac_bc_update_t *ent, uint8_t *tx_cnt);
#if (PLC_SUPPORT_CCO_ROLE)
/*
* mac_start_beacon_internal() - start sending beacon. this function is similar
* to mac_start_beacon but can only be called
* inside mac context.
* @pdev_id: mac pdev id of the device to start sending beacon
* @vdev_id: mac vdev id of the device to start sending beacon
*
* return:
* 0 -- for success case
* othersie -- error code
*/
uint32_t mac_start_beacon_internal(uint8_t pdev_id, uint8_t vdev_id);
/*
* mac_stop_beacon_internal() - stop sending beacon. this function is similar
* to mac_stop_beacon but can only be called
* inside mac context.
* @pdev_id: mac pdev id of the device to stop sending beacon
* @vdev_id: mac vdev id of the device to stop sending beacon
*
* return:
* 0 -- for success case
* othersie -- error code
*/
uint32_t mac_stop_beacon_internal(uint8_t pdev_id, uint8_t vdev_id);
#else /* PLC_SUPPORT_CCO_ROLE */
#define mac_start_beacon_internal(pdev_id, vdev_id) IOT_ASSERT(0)
#define mac_stop_beacon_internal(pdev_id, vdev_id) IOT_ASSERT(0)
#endif /* PLC_SUPPORT_CCO_ROLE */
/**
* @brief calculate beacon the biggest csma phase duration
* @param bcn_ctx: beacon ctxt
* @param biggest_phase:
* 0: ALL, 1:A, 2:B, 3: C
* @return: ERR_OK for success; ERR_INVAL for param error
*/
uint32_t mac_beacon_cal_biggest_csma_phase(mac_beacon_ctx_t *bcn_ctx,
uint8_t *biggest_phase);
#ifdef __cplusplus
}
#endif
#endif // !BEACON_H