Skip to content

Commit

Permalink
Implement a packet filter to "subscribe" to all multicast groups
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed May 3, 2024
1 parent 6033307 commit b3d2ef2
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ncp-uart-hw/.cproject

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions src/ncp-uart-hw/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,25 @@

#include PLATFORM_HEADER
#include "ember.h"
#include "ember-types.h"
#include "ezsp-enum.h"

#include "stack/include/message.h"


enum CUSTOM_EZSP_CMD {
XNCP_CMD_GET_PROTOCOL_VERSION_REQ = 0x0000,
XNCP_CMD_GET_PROTOCOL_VERSION_RSP = 0x8000,
XNCP_CMD_GET_SUPPORTED_FEATURES_REQ = 0x0001,
XNCP_CMD_GET_SUPPORTED_FEATURES_RSP = 0x8001,
};


#define XNCP_PROTOCOL_VERSION (0x00000001)

#define XNCP_FEATURE_MEMBER_OF_ALL_GROUPS (0b00000000000000000000000000000001)
#define XNCP_SUPPORTED_FEATURES (XNCP_FEATURE_MEMBER_OF_ALL_GROUPS)


//----------------------
// Implemented Callbacks
Expand All @@ -36,3 +55,74 @@ void emberAfRadioNeedsCalibratingCallback(void)
void emberAfMainInitCallback(void)
{
}

/** @brief Packet filter callback
*
* Filters and/or mutates incoming packets. Currently used only for wildcard multicast
* group membership.
*/
EmberPacketAction emberAfIncomingPacketFilterCallback(EmberZigbeePacketType packetType,
uint8_t* packetData,
uint8_t* size_p,
void* data)
{
if ((packetType == EMBER_ZIGBEE_PACKET_TYPE_APS_COMMAND) && (*size_p >= 3)) {
uint8_t deliveryMode = (packetData[0] & 0b00001100) >> 2;

// Ensure we automatically "join" every multicast group
if (deliveryMode == 0x03) {
// Take ownership over the first entry and continuously rewrite it
EmberMulticastTableEntry *tableEntry = &(sl_zigbee_get_multicast_table()[0]);

tableEntry->endpoint = 1;
tableEntry->multicastId = (packetData[2] >> 8) | (packetData[1] >> 0);
tableEntry->networkIndex = 0;
}
}

return EMBER_ACCEPT_PACKET;
}


EmberStatus emberAfPluginXncpIncomingCustomFrameCallback(uint8_t messageLength,
uint8_t *messagePayload,
uint8_t *replyPayloadLength,
uint8_t *replyPayload) {
*replyPayloadLength = 0;

if (messageLength < 2) {
return EMBER_BAD_ARGUMENT;
}

uint16_t command_id = ((messagePayload[0]) << 0) | ((messagePayload[1]) << 8);

switch (command_id) {
case XNCP_CMD_GET_PROTOCOL_VERSION_REQ:
*replyPayloadLength += 2;
replyPayload[0] = (uint8_t)((XNCP_CMD_GET_PROTOCOL_VERSION_RSP >> 0) & 0xFF);
replyPayload[1] = (uint8_t)((XNCP_CMD_GET_PROTOCOL_VERSION_RSP >> 8) & 0xFF);

*replyPayloadLength += 4;
replyPayload[2] = (uint8_t)((XNCP_PROTOCOL_VERSION >> 0) & 0xFF);
replyPayload[3] = (uint8_t)((XNCP_PROTOCOL_VERSION >> 8) & 0xFF);
replyPayload[4] = (uint8_t)((XNCP_PROTOCOL_VERSION >> 16) & 0xFF);
replyPayload[5] = (uint8_t)((XNCP_PROTOCOL_VERSION >> 24) & 0xFF);
break;

case XNCP_CMD_GET_SUPPORTED_FEATURES_REQ:
*replyPayloadLength += 2;
replyPayload[0] = (uint8_t)((XNCP_CMD_GET_SUPPORTED_FEATURES_RSP >> 0) & 0xFF);
replyPayload[1] = (uint8_t)((XNCP_CMD_GET_SUPPORTED_FEATURES_RSP >> 8) & 0xFF);

*replyPayloadLength += 4;
replyPayload[2] = (uint8_t)((XNCP_SUPPORTED_FEATURES >> 0) & 0xFF);
replyPayload[3] = (uint8_t)((XNCP_SUPPORTED_FEATURES >> 8) & 0xFF);
replyPayload[4] = (uint8_t)((XNCP_SUPPORTED_FEATURES >> 16) & 0xFF);
replyPayload[5] = (uint8_t)((XNCP_SUPPORTED_FEATURES >> 24) & 0xFF);
break;
default:
return EMBER_BAD_ARGUMENT;
}

return EMBER_SUCCESS;
}
78 changes: 78 additions & 0 deletions src/ncp-uart-hw/config/packet-handoff-config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/***************************************************************************//**
* @brief Zigbee Packet Handoff component configuration header.
*\n*******************************************************************************
* # License
* <b>Copyright 2020 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/

// <<< Use Configuration Wizard in Context Menu >>>

// <h>Zigbee Packet Handoff configuration

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ALL_PACKETS> Handoff All Packets
// <i> Default: TRUE
// <i> Allow all packets
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ALL_PACKETS 1

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_RAW_MAC> Handoff Raw Mac
// <i> Default: FALSE
// <i> Allow raw mac
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_RAW_MAC 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_MAC_COMMAND> Handoff Mac Commands
// <i> Default: FALSE
// <i> Allow mac command
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_MAC_COMMAND 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_NETWORK_DATA> Handoff Network Data
// <i> Default: FALSE
// <i> Allow network data
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_NETWORK_DATA 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_NETWORK_COMMAND> Handoff Network Commands
// <i> Default: FALSE
// <i> Allow network command
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_NETWORK_COMMAND 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_APS_DATA> Handoff APS Data
// <i> Default: FALSE
// <i> Allow aps data
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_APS_DATA 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_APS_COMMAND> Handoff APS Commands
// <i> Default: FALSE
// <i> Allow aps command
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_APS_COMMAND 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ZDO> Handoff ZDO Commands
// <i> Default: FALSE
// <i> Allow zdo
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ZDO 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ZCL> Handoff ZCL Commands
// <i> Default: FALSE
// <i> Allow zcl
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_ZCL 0

// <q EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_BEACON> Handoff Beacons
// <i> Default: FALSE
// <i> Allow beacon
#define EMBER_AF_PLUGIN_PACKET_HANDOFF_ALLOW_BEACON 0

// <o PACKET_HANDOFF_BUFFER_SIZE> Packet Handoff Buffer Size <128-512>
// <i> Default: 256
// <i> Handoff buffer size
#define PACKET_HANDOFF_BUFFER_SIZE 256

// </h>

// <<< end of configuration section >>>
2 changes: 2 additions & 0 deletions src/ncp-uart-hw/ncp-uart-hw.slcp
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ component:
- {id: zigbee_gp}
- {id: zigbee_mfglib}
- {id: zigbee_ncp_uart_hardware}
- {id: zigbee_packet_handoff}
- {id: zigbee_pro_stack}
- {id: zigbee_r22_support}
- {id: zigbee_security_link_keys}
- {id: zigbee_source_route}
- {id: zigbee_token_interface}
- {id: zigbee_xncp}
- {id: zigbee_zll}
define:
- {name: EMBER_CUSTOM_MAC_FILTER_TABLE_SIZE, value: '15'}
Expand Down

0 comments on commit b3d2ef2

Please sign in to comment.