Microchip® Advanced Software Framework

miwi_p2p_star.c File Reference

MiWi P2P & STAR Protocol Implementation.

Copyright (c) 2018 - 2022 Microchip Technology Inc. and its subsidiaries.

#include "system.h"
#include "miwi_config.h"
#include "miwi_config_p2p.h"
#include "miwi_p2p_star.h"
#include "mimac_at86rf.h"
#include "mimem.h"
#include "delay.h"
#include "pdsDataServer.h"
#include "wlPdsTaskManager.h"
#include "miqueue.h"
#include "string.h"

Data Structures

struct  _gEstConnection
 
struct  _gSearchConnection
 
struct  _resyncConnection
 
struct  _TxFrame_t
 
struct  _TxFrameEntry_t
 

Macros

#define CONNECTION_TABLE_LOST_MAX   2
 
#define DATA_TIMER_INTERVAL   100
 
#define MAX_LINK_STATUS_FAILURES   3
 
#define PROTOCOL_TIMER_INTERVAL   1000
 
#define RECEIVE_ON_WHEN_IDLE   0x01
 
#define SECURITY_INFO   0x00
 

Typedefs

typedef struct _gEstConnection gEstConnection_t
 
typedef struct _gSearchConnection gSearchConnection_t
 
typedef struct _resyncConnection resyncConnection_t
 
typedef struct _TxFrame_t TxFrame_t
 
typedef struct _TxFrameEntry_t TxFrameEntry_t
 

Functions

uint8_t AddConnection (uint8_t capacityInfo)
 
void appAckWaitDataCallback (uint8_t handle, miwi_status_t status, uint8_t *msgPointer)
 
static void CommandConfCallback (uint8_t msgConfHandle, miwi_status_t status, uint8_t *msgPointer)
 
static void connectionRespConfCallback (uint8_t msgConfHandle, miwi_status_t status, uint8_t *msgPointer)
 
static void connReqConfCallback (uint8_t msgConfHandle, miwi_status_t status, uint8_t *msgPointer)
 
static void dataTimerHandler (SYS_Timer_t *timer)
 
static uint8_t Find_Index (uint8_t *DestAddr)
 
static void findInActiveDevices (void)
 
static void frameParse (MAC_RECEIVED_PACKET *macRxPacket)
 
bool frameTransmit (INPUT bool Broadcast, API_UINT16_UNION DestinationPANID, INPUT uint8_t *DestinationAddress, INPUT bool isCommand, INPUT bool SecurityEnabled, INPUT uint8_t msgLen, INPUT uint8_t *msgPtr, INPUT uint8_t msghandle, INPUT bool ackReq, INPUT DataConf_callback_t ConfCallback)
 
static void frameTxCallback (uint8_t handle, miwi_status_t status, uint8_t *msgPointer)
 
static void handleLostConnection (void)
 
bool isSameAddress (INPUT uint8_t *Address1, INPUT uint8_t *Address2)
 
void macAckOnlyDataCallback (uint8_t handle, miwi_status_t status, uint8_t *msgPointer)
 
static void MiApp_BroadcastConnectionTable (void)
 
void MiApp_ConnectionMode (INPUT uint8_t Mode)
 
uint8_t MiApp_EstablishConnection (uint8_t Channel, uint8_t addr_len, uint8_t *addr, uint8_t Capability_info, connectionConf_callback_t ConfCallback)
 
bool MiApp_Get (miwi_params_t id, uint8_t *value)
 
miwi_status_t MiApp_ProtocolInit (defaultParametersRomOrRam_t *defaultRomOrRamParams, defaultParametersRamOnly_t *defaultRamOnlyParams)
 
void MiApp_RemoveConnection (INPUT uint8_t ConnectionIndex)
 
bool MiApp_ResetToFactoryNew (void)
 
bool MiApp_SendData (uint8_t addr_len, uint8_t *addr, uint8_t msglen, uint8_t *msgpointer, uint8_t msghandle, bool ackReq, bool secEnabled, DataConf_callback_t ConfCallback)
 
bool MiApp_Set (miwi_params_t id, uint8_t *value)
 
bool MiApp_StartConnection (uint8_t Mode, uint8_t ScanDuration, uint32_t ChannelMap, connectionConf_callback_t ConfCallback)
 
bool MiApp_SubscribeDataIndicationCallback (PacketIndCallback_t callback)
 
bool MiApp_SubscribeLinkFailureCallback (LinkFailureCallback_t callback)
 
bool MiApp_SubscribeReConnectionCallback (ReconnectionCallback_t callback)
 
void P2PTasks (void)
 
static bool parseConnectionTable (uint8_t *payload, uint8_t payloadSize)
 
static void protocolTimerHandler (SYS_Timer_t *timer)
 
static void protocolTimerInit (void)
 
static void removeConnection (uint8_t index)
 
static miwi_status_t sendConnectionRequest (void)
 
static void sendLinkStatus (void)
 
static void startCompleteProcedure (bool timeronly)
 
static void startLinkStatusTimer (void)
 
static void store_connection_tb (uint8_t *payload, uint8_t payloadSize)
 
uint8_t Total_Connections (void)
 

Variables

MiQueue_t appAckWaitDataQueue
 
uint8_t backupChannel = 0xFF
 
uint8_t conn_size = 0
 
uint8_t connectionTbLostCount = 0
 
uint16_t connectionTimeInterval = 0
 
uint8_t ConnMode = DISABLE_ALL_CONN
 
uint8_t currentChannel = 0xFF
 
static SYS_Timer_t dataTimer
 
END_DEVICES_Unique_Short_Address END_DEVICES_Short_Address [CONNECTION_SIZE]
 
uint8_t end_nodes = 0
 
MiQueue_t frameTxQueue
 
gEstConnection_t gEstConnectionInfo
 
gSearchConnection_t gSearchConnectionInfo
 
MiQueue_t indirectFrameQueue
 
static MIWI_TICK lastTxFrameTick
 
uint8_t LatestConnection
 
LinkFailureCallback_t linkFailureCallback
 
MiQueue_t macAckOnlyFrameQueue
 
MAC_RECEIVED_PACKET MACRxPacket
 
defaultParametersRamOnly_tmiwiDefaultRamOnlyParams
 
defaultParametersRomOrRam_tmiwiDefaultRomOrRamParams
 
uint8_t myConnectionIndex_in_PanCo
 
uint8_t MyindexinPC
 
uint8_t myLongAddress [MY_ADDRESS_LENGTH] = {EUI_0,EUI_1,EUI_2,EUI_3, EUI_4, EUI_5,EUI_6,EUI_7}
 
API_UINT16_UNION myPANID
 
uint8_t P2PCapacityInfo = RECEIVE_ON_WHEN_IDLE | SECURITY_INFO
 
p2pStarState_t p2pStarCurrentState = INITIAL_STATE
 
volatile P2P_STATUS P2PStatus
 
PacketIndCallback_t pktRxcallback = NULL
 
static SYS_Timer_t protocolTimer
 
ReconnectionCallback_t reconnectionCallback
 
resyncConnection_t resyncInfo
 
DeviceRole_t role
 
RECEIVED_MESSAGE rxMessage
 
TxFrame_tsentFrame
 
static uint32_t transaction_duration_us = 0
 
bool txCallbackReceived = true
 

#define CONNECTION_TABLE_LOST_MAX   2

Referenced by handleLostConnection().

#define DATA_TIMER_INTERVAL   100

Referenced by protocolTimerInit().

#define MAX_LINK_STATUS_FAILURES   3
#define PROTOCOL_TIMER_INTERVAL   1000

Referenced by protocolTimerInit().

#define RECEIVE_ON_WHEN_IDLE   0x01
#define SECURITY_INFO   0x00

typedef struct _TxFrame_t TxFrame_t

uint8_t AddConnection ( uint8_t  capacityInfo)

Referenced by frameParse().

void CommandConfCallback ( uint8_t  msgConfHandle,
miwi_status_t  status,
uint8_t *  msgPointer 
)
static
static void connectionRespConfCallback ( uint8_t  msgConfHandle,
miwi_status_t  status,
uint8_t *  msgPointer 
)
static
static uint8_t Find_Index ( uint8_t *  DestAddr)
static
static void findInActiveDevices ( void  )
static

Referenced by protocolTimerHandler().

void frameParse ( MAC_RECEIVED_PACKET macRxPacket)
static

References _DataFrame_t::ackReq, _gSearchConnection::activeScanResultIndex, AddConnection(), ADDITIONAL_NODE_ID_SIZE, ALREADY_EXISTS, appAckWaitDataCallback(), MAC_RECEIVED_PACKET::bits, RECEIVED_MESSAGE::bits, _DataFrame_t::broadcast, callback, CMD_CHANNEL_HOPPING, CMD_DATA_TO_ENDDEV_SUCCESS, CMD_FORWRD_PACKET, CMD_IAM_ALIVE, CMD_MAC_DATA_REQUEST, CMD_P2P_ACTIVE_SCAN_REQUEST, CMD_P2P_ACTIVE_SCAN_RESPONSE, CMD_P2P_CONNECTION_REMOVAL_REQUEST, CMD_P2P_CONNECTION_REMOVAL_RESPONSE, CMD_P2P_CONNECTION_REQUEST, CMD_P2P_CONNECTION_RESPONSE, CMD_SHARE_CONNECTION_TABLE, CommandConfCallback(), _resyncConnection::confCallback, _DataFrame_t::confCallback, CONNECTION_SIZE, connectionRespConfCallback(), _gEstConnection::connectionRetries, ConnMode, currentChannel, _P2PStarDataFrame_t::dataFrame, _DataFrame_t::destAddress, ENABLE_ACTIVE_SCAN_RSP, ENABLE_PREV_CONN, END_DEVICE, end_nodes, ESTABLISHING_NETWORK, FAILURE, Find_Index(), MAC_RECEIVED_PACKET::flags, RECEIVED_MESSAGE::flags, frameTransmit(), _DataFrame_t::fromEDToED, i, IEEE_802_15_4, IN_NETWORK_STATE, INDIRECT_MESSAGE_TIMEOUT, isSameAddress(), LatestConnection, LONG_ADDR_LEN, MAC_RECEIVED_PACKET::LQIValue, macAckOnlyDataCallback(), MiApp_CB_AllowConnection, MiMAC_SetAltAddress(), MiMem_Alloc(), MiMem_Free(), MiMem_PercentageOfFreeBuffers(), miQueueAppend(), miQueueRemove(), MIWI_ALL_MEMORY_MEM_ID, _DataFrame_t::msg, _DataFrame_t::msghandle, _DataFrame_t::msgLength, MY_ADDRESS_LENGTH, myConnectionIndex_in_PanCo, MyindexinPC, NULL, P2PCapacityInfo, p2pStarCurrentState, PACKET_TYPE_COMMAND, PACKETLEN_P2P_ACTIVE_SCAN_RESPONSE, PACKETLEN_P2P_CONNECTION_REMOVAL_RESPONSE, RECEIVED_MESSAGE::PacketLQI, RECEIVED_MESSAGE::PacketRSSI, PAN_COORD, parseConnectionTable(), MAC_RECEIVED_PACKET::Payload, RECEIVED_MESSAGE::Payload, MAC_RECEIVED_PACKET::PayloadLen, RECEIVED_MESSAGE::PayloadSize, PDS_Store(), pktRxcallback, RESYNC_IN_PROGRESS, _resyncConnection::resyncTimes, RFD_WAKEUP_INTERVAL, role, MAC_RECEIVED_PACKET::RSSIValue, _DataFrame_t::secEnabled, MiQueue::size, MAC_RECEIVED_PACKET::SourceAddress, RECEIVED_MESSAGE::SourceAddress, RECEIVED_MESSAGE::SourcePANID, startLinkStatusTimer(), _gEstConnection::status, STATUS_ACTIVE_SCAN, STATUS_ENTRY_NOT_EXIST, STATUS_EXISTS, STATUS_NOT_PERMITTED, STATUS_NOT_SAME_PAN, STATUS_SUCCESS, store_connection_tb(), SUCCESS, _DataFrame_t::timeout, TX_BUFFER_SIZE, API_UINT16_UNION::Val, MAC_RECEIVED_PACKET::Val, and RECEIVED_MESSAGE::Val.

Referenced by P2PTasks().

static void frameTxCallback ( uint8_t  handle,
miwi_status_t  status,
uint8_t *  msgPointer 
)
static
bool isSameAddress ( INPUT uint8_t *  Address1,
INPUT uint8_t *  Address2 
)
static void MiApp_BroadcastConnectionTable ( void  )
static
void MiApp_ConnectionMode ( INPUT uint8_t  Mode)
bool MiApp_Get ( miwi_params_t  id,
uint8_t *  value 
)
void MiApp_RemoveConnection ( INPUT uint8_t  ConnectionIndex)
bool MiApp_ResetToFactoryNew ( void  )

References PDS_DeleteAll().

Referenced by APP_TaskHandler().

bool MiApp_SubscribeDataIndicationCallback ( PacketIndCallback_t  callback)

References callback, NULL, and pktRxcallback.

Referenced by appInit(), Initialize_Demo(), and main().

bool MiApp_SubscribeLinkFailureCallback ( LinkFailureCallback_t  callback)

References callback, linkFailureCallback, and NULL.

Referenced by appInit(), and Initialize_Demo().

bool MiApp_SubscribeReConnectionCallback ( ReconnectionCallback_t  callback)

References callback, NULL, and reconnectionCallback.

Referenced by wsndemo_init().

static bool parseConnectionTable ( uint8_t *  payload,
uint8_t  payloadSize 
)
static

References i, and TX_BUFFER_SIZE.

Referenced by frameParse().

static void sendLinkStatus ( void  )
static

Referenced by protocolTimerHandler().

static void startLinkStatusTimer ( void  )
static

Referenced by frameParse(), and MiApp_ProtocolInit().

static void store_connection_tb ( uint8_t *  payload,
uint8_t  payloadSize 
)
static
uint8_t Total_Connections ( void  )

References CONNECTION_SIZE, and i.

Referenced by run_p2p_demo(), and run_star_demo().

MiQueue_t appAckWaitDataQueue
uint8_t backupChannel = 0xFF
uint8_t conn_size = 0
uint8_t connectionTbLostCount = 0

Referenced by handleLostConnection().

uint16_t connectionTimeInterval = 0
SYS_Timer_t dataTimer
static

Referenced by run_star_demo().

uint8_t end_nodes = 0
MiQueue_t frameTxQueue
gEstConnection_t gEstConnectionInfo
gSearchConnection_t gSearchConnectionInfo
MiQueue_t indirectFrameQueue
MIWI_TICK lastTxFrameTick
static
uint8_t LatestConnection

Referenced by frameParse().

MiQueue_t macAckOnlyFrameQueue
MAC_RECEIVED_PACKET MACRxPacket

Referenced by MiMAC_ReceivedPacket().

defaultParametersRamOnly_t* miwiDefaultRamOnlyParams
defaultParametersRomOrRam_t* miwiDefaultRomOrRamParams
uint8_t myConnectionIndex_in_PanCo

Referenced by frameParse(), and run_star_demo().

uint8_t MyindexinPC

Referenced by frameParse().

volatile P2P_STATUS P2PStatus
SYS_Timer_t protocolTimer
static
resyncConnection_t resyncInfo
TxFrame_t* sentFrame
uint32_t transaction_duration_us = 0
static

Referenced by P2PTasks().

bool txCallbackReceived = true

Referenced by frameTxCallback(), and P2PTasks().