Skip to content

Commit

Permalink
Added address filter feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AnsheelaSahoo committed Aug 6, 2024
1 parent 40ef7d7 commit f0ad529
Show file tree
Hide file tree
Showing 11 changed files with 181 additions and 6 deletions.
2 changes: 2 additions & 0 deletions driver/software/MiWi/MiWi_Mesh/inc/miwi_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ typedef enum AppState_t {
APP_STATE_SLEEP,
APP_STATE_FREQUENCY_AGILITY,
APP_STATE_NOISE_DETECTION,
APP_ADD_ACCEPTED_ADDRESS
} AppState_t;

extern AppState_t appStates;
extern uint8_t channelCount;
extern uint8_t maxRSSI;
extern uint8_t deviceCountRem;
//extern bool deviceCanSleep;
extern SYS_TIME_HANDLE testtimehandle;
// *****************************************************************************
Expand Down
34 changes: 34 additions & 0 deletions driver/software/MiWi/MiWi_Mesh/src/miwi_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ static bool deviceCanSleep = false;
static STACK_API_Request apiReq;
uint8_t channelCount = 0U;
uint8_t maxRSSI;
uint8_t bloomFilterValue[BLOOM_FILTER_SIZE];
uint8_t maxNumDevices = MAX_NUMBER_OF_DEVICES_IN_NETWORK;
uint8_t acceptedDeviceCount = 0;
// Increase the number of devices that can join the network by changing the parameter "numDevices". Also add the device address, which can form a part of the network, in the array "acceptedDeviceAddress".
//This Address filtering feature is activated only by enabling the macor "ADDRESS_CHECK"
uint8_t const numDevices = 1;
uint64_t acceptedDeviceAddress [1] = {0x22665544332211AB};//{0x33665544332211AB, 0x22665544332211AB,0x55665544332211AB,0x66665544332211AB,0x77665544332211AB,0x88665544332211AB, 0x99665544332211AB, 0x44665544332211AB, 0x11555544332211AB,0x22555544332211AB};
uint8_t deviceCountRem = numDevices;
static uint8_t gOptimalChannel = 0xFFU;
static uint8_t minRSSI = 0xFFU;
// *****************************************************************************
Expand Down Expand Up @@ -460,9 +468,35 @@ void MiAPP_TaskHandler(APP_Msg_T *appState)
apiReq.paramSize = (uint8_t)sizeof(startNetworkReq_t);
apiReq.uApiID = (uint8_t)MIWI_START_NW;
MIWI_API_CALL((STACK_API_Request*)&apiReq);
APP_Msg_T appMsg;
APP_Msg_T *appState;
appState = &appMsg;
appStates = APP_ADD_ACCEPTED_ADDRESS;
appState->msgId = (uint8_t)APP_ADD_ACCEPTED_ADDRESS;
OSAL_QUEUE_Send(&appData.appQueue, appState, 0);
break;
}

case APP_ADD_ACCEPTED_ADDRESS:
{
if (deviceCountRem !=0)
{
if (!bloomFilterAutoJoin)
{
if (acceptedDeviceAddress[acceptedDeviceCount]!= 0)
{
bool addNewDevice = MiApp_Commissioning_AddNewDevice(acceptedDeviceAddress[acceptedDeviceCount], true);
if (addNewDevice == true);
{
deviceCountRem--;
acceptedDeviceCount++;
}
}
}
}
break;
}

#else
case (uint8_t)APP_STATE_CONNECT_NETWORK:
{
Expand Down
13 changes: 13 additions & 0 deletions driver/software/MiWi/MiWi_Mesh/src/miwi_mesh_commissioning.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ static uint8_t initiateNetworkBloomUpdate(void);
#if defined(PAN_COORDINATOR)
static uint8_t NumOfCommnDevices = 0;
#endif
#ifndef ADDRESS_CHECK
bool bloomFilterAutoJoin = true;
#else
bool bloomFilterAutoJoin = false;
#endif

/************************ Function Definitions **********************************/

Expand Down Expand Up @@ -282,6 +286,15 @@ static void commandConfcb(uint8_t handle, miwi_status_t status, uint8_t* msgPoin
(void)handle;
(void)status;
(void)msgPointer;
if (!bloomFilterAutoJoin)
{
APP_Msg_T appMsg;
APP_Msg_T *appState;
appState = &appMsg;
appStates = APP_ADD_ACCEPTED_ADDRESS;
appState->msgId = (uint8_t)APP_ADD_ACCEPTED_ADDRESS;
OSAL_QUEUE_Send(&appData.appQueue, appState, 0);
}
}

/************************************************************************************
Expand Down
7 changes: 1 addition & 6 deletions driver/software/MiWi/MiWi_Mesh/src/miwi_mesh_join.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ uint16_t myParentShortAddress = 0xFFFFU;
static bool connectionPermit = false;
static uint8_t endDeviceCapacityPercent = 0U;
static uint8_t SleepEndDeviceCapacityPercent = 0U;
uint8_t bloomFilterValue[BLOOM_FILTER_SIZE];
//uint8_t bloomFilterValue[BLOOM_FILTER_SIZE];
uint8_t backupChannel = 0U;
#ifndef PAN_COORDINATOR
uint8_t edLinkFailureAttempts;
Expand Down Expand Up @@ -474,11 +474,6 @@ bool MiApp_StartConnection(uint8_t Mode, uint8_t ScanDuration, uint32_t ChannelM
/* Store scan duration */
gChannelMap = ChannelMap;

/* bloom filter feature*/
if (!bloomFilterAutoJoin)
{
MiApp_Commissioning_AddNewDevice(0x11665544332211AB, true); //0x11665544332211AB is ieee address which can be modified for bloom filter enable
}

switch(Mode)
{
Expand Down
4 changes: 4 additions & 0 deletions driver/software/MiWi/MiWi_P2P/inc/miwi_p2p_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,8 @@ extern uint8_t optimalChannel;
#endif
bool isSameAddress(uint8_t *Address1, uint8_t *Address2);

void addAcceptedDeviceAddr(uint64_t *acceptedAddr);
uint64_t convert_to_64bit(uint8_t* memory_location);
bool checkDevAddr(uint8_t* addressToCheck);

#endif //__MIWI_P2P_STAR_H_
3 changes: 3 additions & 0 deletions driver/software/MiWi/MiWi_P2P/src/miwi_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ uint8_t myChannel = 26U;
recommendation from Data Sheet for European band (ie.,Channel 0)*/
#endif


uint64_t devicesToBeAccepted[CONNECTION_SIZE] = {0x33665544332211AB,0x22665544332211AB,0x44665544332211AB,0,0};
/*********************************************************************
* Function: bool freezer_feature(void)
*
Expand Down Expand Up @@ -293,6 +295,7 @@ bool Initialize_Demo(bool freezer_enable)
DemoOutput_Channel(myChannel, 0U);

startNetwork = false;
addAcceptedDeviceAddr(devicesToBeAccepted);

/* Try to establish a new connection with peer device by broadcast Connection Request */
return MiApp_EstablishConnection(myChannel, 2U, (uint8_t*)&broadcastAddr, 0U, Connection_Confirm);
Expand Down
55 changes: 55 additions & 0 deletions driver/software/MiWi/MiWi_P2P/src/miwi_p2p_star.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ typedef struct _TxFrame_t
buffer_t* pMemClr;
} __attribute__((packed, aligned(1)))TxFrame_t;

typedef struct
{
uint64_t deviceAddress;
} AcceptedDeviceTable_t;

/********************* Global and Static Variables *************************************/
static DataConf_callback_t sentFrameCb;
uint8_t busyLock = 0;
Expand Down Expand Up @@ -236,6 +241,12 @@ PacketIndCallback_t pktRxcallback = NULL;
#if defined(ENABLE_SECURITY)
API_UINT32_UNION IncomingFrameCounter[CONNECTION_SIZE]; // If authentication is used, IncomingFrameCounter can prevent replay attack
#endif
#if defined (ADDRESS_CHECK)
bool filterDeviceAddress = true;
#else
bool filterDeviceAddress = false;
#endif
AcceptedDeviceTable_t acceptedDevTable[CONNECTION_SIZE];
/************************************** Function Prototypes****************************************************/
bool frameTransmit(bool Broadcast,API_UINT16_UNION DestinationPANID, uint8_t *DestinationAddress, bool isCommand, bool SecurityEnabled,
uint8_t msgLen, uint8_t* msgPtr, uint8_t msghandle, bool ackReq, DataConf_callback_t ConfCallback, buffer_t* memClrPtr);
Expand Down Expand Up @@ -287,6 +298,45 @@ static void StartChannelHopping(void);
static void channelHopCmdCallback(uint8_t msgConfHandle, miwi_status_t status, uint8_t* msgPointer);
#endif
/********************* Function Definitions *******************************************/
void addAcceptedDeviceAddr(uint64_t *acceptedAddr)
{
if (filterDeviceAddress)
{
for (uint8_t i = 0; i<CONNECTION_SIZE; i++)
{
//if (acceptedAddr[i]!=0)
acceptedDevTable[i].deviceAddress = acceptedAddr[i];
}
}
}

uint64_t convert_to_64bit(uint8_t* memory_location)
{
uint64_t result = 0;
for (uint8_t i = 0; i < 8; i++)
{
result |= ((uint64_t)memory_location[7-i]) << (8 * (7 - i));
}
return result;
}

bool checkDevAddr(uint8_t* addressToCheck)
{
if (filterDeviceAddress)
{
uint64_t addr = convert_to_64bit(addressToCheck);
for (uint8_t i=0; i<CONNECTION_SIZE; i++)
{
if (addr == acceptedDevTable[i].deviceAddress)
{
return true;
}
}
return false;
}
return true;
}

miwi_status_t MiApp_ProtocolInit(defaultParametersRomOrRam_t *defaultRomOrRamParams,
defaultParametersRamOnly_t *defaultRamOnlyParams)
{
Expand Down Expand Up @@ -2106,6 +2156,11 @@ void frameParse(MAC_RECEIVED_PACKET *macRxPacket)
else
#endif
{
bool addrPresent = checkDevAddr(MACRxPacket.SourceAddress);
if (!addrPresent)
{
return;
}
/* Request accepted, try to add the requesting device into P2P Connection Entry */
status = AddConnection(rxMessage.Payload[2]);
}
Expand Down
3 changes: 3 additions & 0 deletions driver/software/MiWi/MiWi_Star/inc/miwi_p2p_star.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,4 +234,7 @@ extern uint8_t optimalChannel;
#endif
bool isSameAddress(uint8_t *Address1, uint8_t *Address2);

void addAcceptedDeviceAddr(uint64_t *acceptedAddr);
uint64_t convert_to_64bit(uint8_t* memory_location);
bool checkDevAddr(uint8_t* addressToCheck);
#endif //__MIWI_P2P_STAR_H_
4 changes: 4 additions & 0 deletions driver/software/MiWi/MiWi_Star/src/miwi_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ uint8_t myChannel = 26U;
recommendation from Data Sheet for European band (ie.,Channel 0)*/
#endif


uint64_t devicesToBeAccepted[CONNECTION_SIZE] = {0x33665544332211AB,0x22665544332211AB,0x44665544332211AB,0,0};
/*********************************************************************
* Function: bool freezer_feature(void)
*
Expand Down Expand Up @@ -298,6 +300,8 @@ bool Initialize_Demo(bool freezer_enable)
DemoOutput_Channel(myChannel, 0U);

startNetwork = false;

addAcceptedDeviceAddr(devicesToBeAccepted);

/* Try to establish a new connection with peer device by broadcast Connection Request */
return MiApp_EstablishConnection(myChannel, 2U, (uint8_t*)&broadcastAddr, 0U, Connection_Confirm);
Expand Down
58 changes: 58 additions & 0 deletions driver/software/MiWi/MiWi_Star/src/miwi_p2p_star.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ typedef struct _TxFrame_t
buffer_t* pMemClr;
} __attribute__((packed, aligned(1)))TxFrame_t;


typedef struct
{
uint64_t deviceAddress;
} AcceptedDeviceTable_t;

/********************* Global and Static Variables *************************************/
static DataConf_callback_t sentFrameCb;
uint8_t busyLock = 0U;
Expand Down Expand Up @@ -240,6 +246,13 @@ PacketIndCallback_t pktRxcallback = NULL;
#if defined(ENABLE_SECURITY)
API_UINT32_UNION IncomingFrameCounter[CONNECTION_SIZE]; // If authentication is used, IncomingFrameCounter can prevent replay attack
#endif

#if defined (ADDRESS_CHECK)
bool filterDeviceAddress = true;
#else
bool filterDeviceAddress = false;
#endif
AcceptedDeviceTable_t acceptedDevTable[CONNECTION_SIZE];
/************************************** Function Prototypes****************************************************/
bool frameTransmit(bool Broadcast,API_UINT16_UNION DestinationPANID, uint8_t *DestinationAddress, bool isCommand, bool SecurityEnabled,
uint8_t msgLen, uint8_t* msgPtr, uint8_t msghandle, bool ackReq, DataConf_callback_t ConfCallback, buffer_t* memClrPtr);
Expand Down Expand Up @@ -296,6 +309,46 @@ static void channelHopCmdCallback(uint8_t msgConfHandle, miwi_status_t status, u
//extern uint8_t ConnMode;
//extern uint8_t LatestConnection;
//extern CONNECTION_ENTRY connectionTable[CONNECTION_SIZE];
void addAcceptedDeviceAddr(uint64_t *acceptedAddr)
{
if (filterDeviceAddress)
{
for (uint8_t i = 0; i<CONNECTION_SIZE; i++)
{
//if (acceptedAddr[i]!=0)
acceptedDevTable[i].deviceAddress = acceptedAddr[i];
}
}
}

uint64_t convert_to_64bit(uint8_t* memory_location)
{
uint64_t result = 0;
for (uint8_t i = 0; i < 8; i++)
{
result |= ((uint64_t)memory_location[7-i]) << (8 * (7 - i));
}
return result;
}

bool checkDevAddr(uint8_t* addressToCheck)
{
if (filterDeviceAddress)
{
uint64_t addr = convert_to_64bit(addressToCheck);
for (uint8_t i=0; i<CONNECTION_SIZE; i++)
{
if (addr == acceptedDevTable[i].deviceAddress)
{
return true;
}
}
return false;
}
return true;
}


/********************* Function Definitions *******************************************/
miwi_status_t MiApp_ProtocolInit(defaultParametersRomOrRam_t *defaultRomOrRamParams,
defaultParametersRamOnly_t *defaultRamOnlyParams)
Expand Down Expand Up @@ -2138,6 +2191,11 @@ void frameParse(MAC_RECEIVED_PACKET *macRxPacket)
else
#endif
{
bool addrPresent = checkDevAddr(MACRxPacket.SourceAddress);
if (!addrPresent)
{
return;
}
/* Request accepted, try to add the requesting device into P2P Connection Entry */
status = AddConnection(rxMessage.Payload[2]);
}
Expand Down
4 changes: 4 additions & 0 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ With MiWi, application developers can switch between RF transceivers and wireles
The three layers are linked together by MiMAC and MiApp interfaces. The Application layer uses MiApp interfaces to communicate to the protocol layer. In the protocol layer, there are implementations of MiWi Mesh, MiWi P2P, MiWi Star wireless communication protocols.
The drivers for WBZ451 and other Standalone Microchip RF transceivers (AT86RF233, AT86RF212B, AT86RF215) are called by protocol layers via MiMAC interfaces.

## New Features

- Introduced Address Filtering fearute during network formation, activated by enabling the macro ADDRESS_CHECK.

## Known Issues / Limitations

- OTAU is not supported.
Expand Down

0 comments on commit f0ad529

Please sign in to comment.