Commit 8db89644 authored by 尹佳钦's avatar 尹佳钦

add kk_test.c

parent cd1c0c55
#include "kk_test.h"
static void kk_rpc_send_message(cJSON *data,char *method,EmberEUI64 mac)
{
static uint16_t msgid;
cJSON *item = rpc_cJSON_CreateObject();
char msgIdString[10];
sprintf(msgIdString,"%d",++msgid);
rpc_cJSON_AddStringToObject(item, "msgId",msgIdString);
rpc_cJSON_AddStringToObject(item, "version", KK_IPC_VERSION);
if(mac!=NULL){
rpc_cJSON_AddMACToObject(item,mac);
}
rpc_cJSON_AddStringToObject(item, "method",method);
rpc_cJSON_AddItemToObject(item, "params", data);
char* p = rpc_cJSON_Print(item);
emberAfAppPrintln("send json:\n%s\n",p);
free(p);
jrpc_send_msg(item);
}
void kk_rpc_report_devices(cJSON *data,EmberEUI64 mac)
{
kk_rpc_send_message(data,KK_REPORT_DEVICE_JOINED_METHOD,mac);
}
void kk_rpc_report_status(cJSON *data,EmberEUI64 mac)
{
kk_rpc_send_message(data,KK_REPORT_ATTRIBUTE_METHOD,mac);
}
typedef struct{
EmberEUI64 mac;
uint8_t AppVersion;
uint8_t deviceType;
uint8_t deviceCode;
uint8_t productType;
uint8_t productCode;
}kk_report_device_s;
void kk_rpc_reportDevices(kk_report_device_s device)
{
cJSON* devicesJson;
devicesJson = rpc_cJSON_CreateObject();
rpc_cJSON_AddAppVersionToObject(devicesJson,device.AppVersion);
rpc_cJSON_AddStringToObject(devicesJson, "deviceType","1");
rpc_cJSON_AddStringToObject(devicesJson, "deviceCode","2");
rpc_cJSON_AddStringToObject(devicesJson, "productType","3");
rpc_cJSON_AddStringToObject(devicesJson, "productCode","4");
kk_rpc_report_devices(devicesJson,device.mac);
}
bool kk_rpc_report_LightStatus(EmberEUI64 mac,bool LightStatus)
{
cJSON* root;
root = rpc_cJSON_CreateObject();
if(LightStatus==true){
rpc_cJSON_AddStringToObject(root, "LightStatus","1");
}else{
rpc_cJSON_AddStringToObject(root, "LightStatus","0");
}
kk_rpc_report_status(root,mac);
}
cJSON *rpc_Control(jrpc_context * ctx, cJSON *params, cJSON *id)
{
rpc_nwk_info_s info;
EmberStatus status;
if(params == NULL){
emberAfCorePrintln("\r\nparams == NULL\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else{
cJSON *mac_item= rpc_cJSON_GetObjectItem(params, "mac");
cJSON *LightStatus_item = rpc_cJSON_GetObjectItem(params, "LightStatus");
uint8_t LightStatus = rpc_get_u8(LightStatus_item->valuestring);
uint8_t mac[EUI64_SIZE];
bool flag= rpc_get_mac(mac_item->valuestring,mac);
emberAfCorePrintBuffer(mac,EUI64_SIZE,true);
for(int i=0;i<EUI64_SIZE;i++){
emberAfCorePrintln("i=%d,val=%02x",i,mac[i]);
}
EmberNodeId node = emberAfDeviceTableGetNodeIdFromEui64(mac);
if(node==0xffff){
emberAfCorePrintln("\r\n not find device!\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
emberAfCorePrintln("\r\nnode=0x%02X,LightStatus=%d\r\n",node,LightStatus);
if(flag){
EmberStatus status;
if(LightStatus==1){
status = zclOnOff_On(node,1);
emberAfCorePrintln("\r\nzclOnOff_On\r\n" );
}else if(LightStatus==0){
status = zclOnOff_Off(node,1);
emberAfCorePrintln("\r\nzclOnOff_Off\r\n" );
}else{
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
}else{
emberAfCorePrintln("\r\n22222\r\n" );
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return rpc_cJSON_CreateNumber(status);
}
error_return:
return rpc_cJSON_CreateNull();
}
cJSON *rpc_nwkPermitJoin(jrpc_context * ctx, cJSON * params, cJSON *id)
{
cJSON * OpenOrClose;
EmberStatus status;
uint8_t isEnable;
if(params == NULL){
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}else if(params->type == cJSON_Object){
OpenOrClose = rpc_cJSON_GetObjectItem(params, "NetChannelState");
}else{
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
isEnable = rpc_get_u8(OpenOrClose->valuestring);
if(isEnable == 0){
status = nwkPermitJoinCMD(FALSE);
emberAfCorePrintln("Disable Permit join\r\n");
}else if(isEnable == 1){
status = nwkPermitJoinCMD(TRUE);
emberAfCorePrintln("Enable Permit join 180s\r\n");
}else{
emberAfCorePrintln("item type error[%d]\r\n",OpenOrClose->type);
set_json_error_type(ctx,JRPC_INVALID_PARAMS,MSG_INVALID_PARAMS);
goto error_return;
}
return rpc_cJSON_CreateNumber(status);
error_return:
return rpc_cJSON_CreateNull();
}
void emberAfPluginDeviceTableNewDeviceCallback(EmberEUI64 nodeEui64)
{
uint16_t deviceTableIndex = emberAfDeviceTableGetFirstIndexFromEui64(nodeEui64);
if(deviceTableIndex == 0xffff){
kk_print_info("not find item!");
return ;
}
//EmberAfPluginDeviceTableEntry *deviceTable = emberAfDeviceTablePointer();
//cJSON* nodeJson = rpc_reportDeviceState("joined",deviceTable[deviceTableIndex].eui64);
//rpc_printfJSON("joined",nodeJson);
//rpc_send_message(nodeJson,"device joined");
//rpc_add_device(deviceTable[deviceTableIndex].nodeId);
kk_report_device_s device;
//device.mac = nodeEui64;
device.AppVersion = 0x10;
memcpy(device.mac,nodeEui64,EUI64_SIZE);
kk_rpc_reportDevices(device);
}
...@@ -505,20 +505,21 @@ static void publishMqttDeviceStateChange(EmberEUI64 eui64, ...@@ -505,20 +505,21 @@ static void publishMqttDeviceStateChange(EmberEUI64 eui64,
cJSON_AddStringToObject(stateChangeJson, "eui64", euiString); cJSON_AddStringToObject(stateChangeJson, "eui64", euiString);
cJSON_AddIntegerToObject(stateChangeJson, "deviceState", state); cJSON_AddIntegerToObject(stateChangeJson, "deviceState", state);
publishMqttTopic("devicestatechange", stateChangeJson); publishMqttTopic("devicestatechange", stateChangeJson);
} }
static void publishMqttDeviceJoined(EmberEUI64 eui64) static void publishMqttDeviceJoined(EmberEUI64 eui64)
{ {
//This function call breaks simulation test, mask it out //This function call breaks simulation test, mask it out
//at this point as Mqtt messages are actually not included //at this point as Mqtt messages are actually not included
//in simluation test. It works normally with the real devices. //in simluation test. It works normally with the real devices.
#ifndef EMBER_TEST #ifndef EMBER_TEST
uint16_t deviceTableIndex; uint16_t deviceTableIndex;
cJSON* nodeJson; cJSON* nodeJson;
deviceTableIndex = emberAfDeviceTableGetFirstIndexFromEui64(eui64); deviceTableIndex = emberAfDeviceTableGetFirstIndexFromEui64(eui64);
nodeJson = buildNodeJson(deviceTableIndex); nodeJson = buildNodeJson(deviceTableIndex);
publishMqttTopic("devicejoined", nodeJson); publishMqttTopic("devicejoined", nodeJson);
#endif //EMBER_TEST #endif //EMBER_TEST
} }
...@@ -1260,28 +1261,10 @@ void emberAfPluginOtaServerUpdateStartedCallback(uint16_t manufacturerId, ...@@ -1260,28 +1261,10 @@ void emberAfPluginOtaServerUpdateStartedCallback(uint16_t manufacturerId,
&firmwareVersion); &firmwareVersion);
} }
void emberAfPluginDeviceTableNewDeviceCallback(EmberEUI64 nodeEui64)
{
publishMqttDeviceJoined(nodeEui64);
}
void emberAfPluginDeviceTableDeviceLeftCallback(EmberEUI64 nodeEui64)
{
publishMqttDeviceLeft(nodeEui64);
}
void emberAfPluginDeviceTableRejoinDeviceCallback(EmberEUI64 nodeEui64)
{
publishMqttDeviceJoined(nodeEui64);
}
void emberAfPluginDeviceTableStateChangeCallback(EmberNodeId nodeId,
uint8_t state)
{
EmberEUI64 nodeEui64;
emberAfDeviceTableGetEui64FromNodeId(nodeId, nodeEui64);
publishMqttDeviceStateChange(nodeEui64, state);
}
void emberAfPluginDeviceTableClearedCallback(void) void emberAfPluginDeviceTableClearedCallback(void)
{ {
...@@ -1702,6 +1685,8 @@ void emberAfPluginGatewayRelayMqttStateUpdateEventHandler(void) ...@@ -1702,6 +1685,8 @@ void emberAfPluginGatewayRelayMqttStateUpdateEventHandler(void)
publishMqttSettings(); publishMqttSettings();
publishMqttRelays(); publishMqttRelays();
publishMqttDevices(); publishMqttDevices();
extern void rpc_reportDevices(void);
rpc_reportDevices();
} }
void emberAfPluginGatewayRelayMqttProcessCommandEventHandler(void) void emberAfPluginGatewayRelayMqttProcessCommandEventHandler(void)
......
...@@ -111,10 +111,10 @@ void emberAfPluginNetworkSteeringStartCommand(void) ...@@ -111,10 +111,10 @@ void emberAfPluginNetworkSteeringStartCommand(void)
void emberAfPluginNetworkSteeringStopCommand(void) void emberAfPluginNetworkSteeringStopCommand(void)
{ {
emberAfCorePrintln("%p: %p: 0x%X", emberAfCorePrintln("%p: %p: 0x%X",
emAfNetworkSteeringPluginName, emAfNetworkSteeringPluginName,
"Stop", "Stop",
emberAfPluginNetworkSteeringStop()); emberAfPluginNetworkSteeringStop());
} }
#endif /* #endif /*
......
...@@ -27,10 +27,10 @@ uint8_t emAfPluginNetworkSteeringGetMaxPossiblePanIds(void) ...@@ -27,10 +27,10 @@ uint8_t emAfPluginNetworkSteeringGetMaxPossiblePanIds(void)
void emAfPluginNetworkSteeringClearStoredPanIds(void) void emAfPluginNetworkSteeringClearStoredPanIds(void)
{ {
if (storedNetworks != EMBER_NULL_MESSAGE_BUFFER) { if (storedNetworks != EMBER_NULL_MESSAGE_BUFFER) {
emberReleaseMessageBuffer(storedNetworks); emberReleaseMessageBuffer(storedNetworks);
storedNetworks = EMBER_NULL_MESSAGE_BUFFER; storedNetworks = EMBER_NULL_MESSAGE_BUFFER;
} }
} }
uint16_t* emAfPluginNetworkSteeringGetStoredPanIdPointer(uint8_t index) uint16_t* emAfPluginNetworkSteeringGetStoredPanIdPointer(uint8_t index)
......
...@@ -50,12 +50,12 @@ ...@@ -50,12 +50,12 @@
// Globals // Globals
#if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK) #if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK)
#define EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK \ #define EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK \
(BIT32(11) | BIT32(14)) (BIT32(11) | BIT32(14))
#endif #endif
#if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION) #if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION)
#define EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION 5 #define EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION 5
#endif #endif
#if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S) #if !defined(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S)
...@@ -69,12 +69,12 @@ ...@@ -69,12 +69,12 @@
#endif #endif
PGM_P emAfPluginNetworkSteeringStateNames[] = { PGM_P emAfPluginNetworkSteeringStateNames[] = {
"None", "None",
// These next two states are only run if explicitly configured to do so // These next two states are only run if explicitly configured to do so
// See emAfPluginNetworkSteeringSetConfiguredKey() // See emAfPluginNetworkSteeringSetConfiguredKey()
"Scan Primary Channels and use Configured Key", "Scan Primary Channels and use Configured Key",
"Scan Secondary Channels and use Configured Key", "Scan Secondary Channels and use Configured Key",
"Scan Primary Channels and use Install Code", "Scan Primary Channels and use Install Code",
"Scan Secondary Channels and use Install Code", "Scan Secondary Channels and use Install Code",
"Scan Primary Channels and Use Centralized Key", "Scan Primary Channels and Use Centralized Key",
"Scan Secondary Channels and Use Centralized Key", "Scan Secondary Channels and Use Centralized Key",
...@@ -83,10 +83,10 @@ PGM_P emAfPluginNetworkSteeringStateNames[] = { ...@@ -83,10 +83,10 @@ PGM_P emAfPluginNetworkSteeringStateNames[] = {
}; };
#define LAST_JOINING_STATE \ #define LAST_JOINING_STATE \
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_DISTRIBUTED EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_DISTRIBUTED
EmberAfPluginNetworkSteeringJoiningState emAfPluginNetworkSteeringState EmberAfPluginNetworkSteeringJoiningState emAfPluginNetworkSteeringState
= EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE; = EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE;
PGM uint8_t emAfNetworkSteeringPluginName[] = "NWK Steering"; PGM uint8_t emAfNetworkSteeringPluginName[] = "NWK Steering";
#define PLUGIN_NAME emAfNetworkSteeringPluginName #define PLUGIN_NAME emAfNetworkSteeringPluginName
...@@ -107,8 +107,8 @@ PGM uint8_t emAfNetworkSteeringPluginName[] = "NWK Steering"; ...@@ -107,8 +107,8 @@ PGM uint8_t emAfNetworkSteeringPluginName[] = "NWK Steering";
#define REQUIRED_STACK_PROFILE 2 #define REQUIRED_STACK_PROFILE 2
static const EmberKeyData defaultLinkKey = { static const EmberKeyData defaultLinkKey = {
{ 0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C, { 0x5A, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6C,
0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 } 0x6C, 0x69, 0x61, 0x6E, 0x63, 0x65, 0x30, 0x39 }
}; };
static const EmberKeyData distributedTestKey = { static const EmberKeyData distributedTestKey = {
{ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, { 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
...@@ -121,8 +121,8 @@ static bool gFilterByExtendedPanId = false; ...@@ -121,8 +121,8 @@ static bool gFilterByExtendedPanId = false;
static uint8_t gExtendedPanIdToFilterOn[8]; static uint8_t gExtendedPanIdToFilterOn[8];
static bool gUseConfiguredKey = false; static bool gUseConfiguredKey = false;
static EmberKeyData gConfiguredKey = { static EmberKeyData gConfiguredKey = {
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
}; };
static bool printedMaxPanIdsWarning = false; static bool printedMaxPanIdsWarning = false;
...@@ -132,9 +132,9 @@ uint8_t emAfPluginNetworkSteeringCurrentChannel; ...@@ -132,9 +132,9 @@ uint8_t emAfPluginNetworkSteeringCurrentChannel;
// We make these into variables so that they can be changed at run time. // We make these into variables so that they can be changed at run time.
// This is very useful for unit and interop tests. // This is very useful for unit and interop tests.
uint32_t emAfPluginNetworkSteeringPrimaryChannelMask uint32_t emAfPluginNetworkSteeringPrimaryChannelMask
= EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK; = EMBER_AF_PLUGIN_NETWORK_STEERING_CHANNEL_MASK;
uint32_t emAfPluginNetworkSteeringSecondaryChannelMask uint32_t emAfPluginNetworkSteeringSecondaryChannelMask
= SECONDARY_CHANNEL_MASK; = SECONDARY_CHANNEL_MASK;
uint8_t emAfPluginNetworkSteeringTotalBeacons = 0; uint8_t emAfPluginNetworkSteeringTotalBeacons = 0;
uint8_t emAfPluginNetworkSteeringJoinAttempts = 0; uint8_t emAfPluginNetworkSteeringJoinAttempts = 0;
...@@ -217,9 +217,9 @@ static bool addPanIdCandidate(uint16_t panId) ...@@ -217,9 +217,9 @@ static bool addPanIdCandidate(uint16_t panId)
static void clearPanIdCandidates(void) static void clearPanIdCandidates(void)
{ {
printedMaxPanIdsWarning = false; printedMaxPanIdsWarning = false;
emAfPluginNetworkSteeringClearStoredPanIds(); emAfPluginNetworkSteeringClearStoredPanIds();
emAfPluginNetworkSteeringPanIdIndex = 0; emAfPluginNetworkSteeringPanIdIndex = 0;
} }
static uint16_t getNextCandidate(void) static uint16_t getNextCandidate(void)
...@@ -237,30 +237,30 @@ static uint16_t getNextCandidate(void) ...@@ -237,30 +237,30 @@ static uint16_t getNextCandidate(void)
void gotoNextChannel(void) void gotoNextChannel(void)
{ {
EmberAfPluginScanDispatchScanData scanData; EmberAfPluginScanDispatchScanData scanData;
EmberStatus status; EmberStatus status;
emAfPluginNetworkSteeringCurrentChannel = getNextChannel(); emAfPluginNetworkSteeringCurrentChannel = getNextChannel();
if (emAfPluginNetworkSteeringCurrentChannel == 0) { if (emAfPluginNetworkSteeringCurrentChannel == 0) {
debugPrintln("No more channels"); emberAfCorePrintln("No more channels");
tryNextMethod(); tryNextMethod();
return; return;
} }
clearPanIdCandidates(); clearPanIdCandidates();
scanData.scanType = EMBER_ACTIVE_SCAN; scanData.scanType = EMBER_ACTIVE_SCAN;
scanData.channelMask = BIT32(emAfPluginNetworkSteeringCurrentChannel); scanData.channelMask = BIT32(emAfPluginNetworkSteeringCurrentChannel);
scanData.duration = EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION; scanData.duration = EMBER_AF_PLUGIN_NETWORK_STEERING_SCAN_DURATION;
scanData.handler = scanResultsHandler; scanData.handler = scanResultsHandler;
status = emberAfPluginScanDispatchScheduleScan(&scanData); status = emberAfPluginScanDispatchScheduleScan(&scanData);
if (EMBER_SUCCESS != status) { if (EMBER_SUCCESS != status) {
emberAfCorePrintln("Error: %p start scan failed: 0x%X", PLUGIN_NAME, status); emberAfCorePrintln("Error: %p start scan failed: 0x%X", PLUGIN_NAME, status);
cleanupAndStop(status); cleanupAndStop(status);
} else { } else {
emberAfCorePrintln("Starting scan on channel %d", emberAfCorePrintln("Starting scan on channel %d",
emAfPluginNetworkSteeringCurrentChannel); emAfPluginNetworkSteeringCurrentChannel);
} }
} }
void tryToJoinNetwork(void) void tryToJoinNetwork(void)
...@@ -296,10 +296,10 @@ void tryToJoinNetwork(void) ...@@ -296,10 +296,10 @@ void tryToJoinNetwork(void)
//Description: Generates a random number between 10000-40000. //Description: Generates a random number between 10000-40000.
static uint32_t jitterTimeDelayMs() static uint32_t jitterTimeDelayMs()
{ {
uint16_t seed; uint16_t seed;
halStackSeedRandom((uint32_t)&seed); halStackSeedRandom((uint32_t)&seed);
uint32_t jitterDelayMs = (halCommonGetRandom() % (UPDATE_TC_LINK_KEY_JITTER_MAX_MS - UPDATE_TC_LINK_KEY_JITTER_MIN_MS + 1)) + UPDATE_TC_LINK_KEY_JITTER_MIN_MS; uint32_t jitterDelayMs = (halCommonGetRandom() % (UPDATE_TC_LINK_KEY_JITTER_MAX_MS - UPDATE_TC_LINK_KEY_JITTER_MIN_MS + 1)) + UPDATE_TC_LINK_KEY_JITTER_MIN_MS;
return jitterDelayMs; return jitterDelayMs;
} }
void emberAfPluginNetworkSteeringStackStatusCallback(EmberStatus status) void emberAfPluginNetworkSteeringStackStatusCallback(EmberStatus status)
...@@ -331,21 +331,21 @@ void emberAfPluginNetworkSteeringStackStatusCallback(EmberStatus status) ...@@ -331,21 +331,21 @@ void emberAfPluginNetworkSteeringStackStatusCallback(EmberStatus status)
// Returns true if the key value is equal to defaultLinkKey // Returns true if the key value is equal to defaultLinkKey
bool emIsWellKnownKey(EmberKeyData key) bool emIsWellKnownKey(EmberKeyData key)
{ {
for (uint8_t i = 0; i < EMBER_ENCRYPTION_KEY_SIZE; i++) { for (uint8_t i = 0; i < EMBER_ENCRYPTION_KEY_SIZE; i++) {
if (key.contents[i] != defaultLinkKey.contents[i]) { if (key.contents[i] != defaultLinkKey.contents[i]) {
return false; return false;
} }
} }
return true; return true;
} }
static void scanCompleteCallback(uint8_t channel, EmberStatus status) static void scanCompleteCallback(uint8_t channel, EmberStatus status)
{ {
if (status != EMBER_SUCCESS) { if (status != EMBER_SUCCESS) {
emberAfCorePrintln("Error: Scan complete handler returned 0x%X", status); emberAfCorePrintln("Error: Scan complete handler returned 0x%X", status);
cleanupAndStop(status); cleanupAndStop(status);
return; return;
} }
// EMAPPFWKV2-1462 - make sure we didn't cleanupAndStop() above. // EMAPPFWKV2-1462 - make sure we didn't cleanupAndStop() above.
if (emAfPluginNetworkSteeringState if (emAfPluginNetworkSteeringState
...@@ -365,23 +365,23 @@ static void networkFoundCallback(EmberZigbeeNetwork *networkFound, ...@@ -365,23 +365,23 @@ static void networkFoundCallback(EmberZigbeeNetwork *networkFound,
return; return;
} }
debugPrint("%p nwk found ch: %d, panID 0x%2X, xpan: ", emberAfCorePrintln("%p nwk found ch: %d, panID 0x%2X, xpan: ",
PLUGIN_NAME, PLUGIN_NAME,
networkFound->channel, networkFound->channel,
networkFound->panId); networkFound->panId);
debugExec(emberAfPrintBigEndianEui64(networkFound->extendedPanId)); debugExec(emberAfPrintBigEndianEui64(networkFound->extendedPanId));
// If we were told to filter by extended PAN ID, do so now // If we were told to filter by extended PAN ID, do so now
if (gFilterByExtendedPanId) { if (gFilterByExtendedPanId) {
if (0 != MEMCOMPARE(networkFound->extendedPanId, if (0 != MEMCOMPARE(networkFound->extendedPanId,
gExtendedPanIdToFilterOn, gExtendedPanIdToFilterOn,
COUNTOF(gExtendedPanIdToFilterOn))) { COUNTOF(gExtendedPanIdToFilterOn))) {
debugPrint(". Skipping since we are looking for xpan: "); emberAfCorePrint(". Skipping since we are looking for xpan: ");
debugExec(emberAfPrintBigEndianEui64(gExtendedPanIdToFilterOn)); debugExec(emberAfPrintBigEndianEui64(gExtendedPanIdToFilterOn));
debugPrintln(""); emberAfCorePrint("");
return; return;
} }
} }
debugPrintln(""); debugPrintln("");
...@@ -395,10 +395,10 @@ static void networkFoundCallback(EmberZigbeeNetwork *networkFound, ...@@ -395,10 +395,10 @@ static void networkFoundCallback(EmberZigbeeNetwork *networkFound,
HIDDEN void scanResultsHandler(EmberAfPluginScanDispatchScanResults *results) HIDDEN void scanResultsHandler(EmberAfPluginScanDispatchScanResults *results)
{ {
if (emberAfPluginScanDispatchScanResultsAreComplete(results) if (emberAfPluginScanDispatchScanResultsAreComplete(results)
|| emberAfPluginScanDispatchScanResultsAreFailure(results)) { || emberAfPluginScanDispatchScanResultsAreFailure(results)) {
scanCompleteCallback(results->channel, results->status); scanCompleteCallback(results->channel, results->status);
} else { } else {
networkFoundCallback(results->network, networkFoundCallback(results->network,
results->lqi, results->lqi,
results->rssi); results->rssi);
...@@ -407,87 +407,86 @@ HIDDEN void scanResultsHandler(EmberAfPluginScanDispatchScanResults *results) ...@@ -407,87 +407,86 @@ HIDDEN void scanResultsHandler(EmberAfPluginScanDispatchScanResults *results)
static EmberStatus tryNextMethod(void) static EmberStatus tryNextMethod(void)
{ {
emAfPluginNetworkSteeringState++; emAfPluginNetworkSteeringState++;
if (emAfPluginNetworkSteeringState > LAST_JOINING_STATE) { if (emAfPluginNetworkSteeringState > LAST_JOINING_STATE) {
EmberStatus status = (emAfPluginNetworkSteeringTotalBeacons > 0 EmberStatus status = (emAfPluginNetworkSteeringTotalBeacons > 0
? EMBER_JOIN_FAILED ? EMBER_JOIN_FAILED
: EMBER_NO_BEACONS); : EMBER_NO_BEACONS);
cleanupAndStop(status); cleanupAndStop(status);
return status; return status;
} }
return stateMachineRun(); return stateMachineRun();
} }
static void cleanupAndStop(EmberStatus status) static void cleanupAndStop(EmberStatus status)
{ {
emberAfCorePrintln("%p Stop. Cleaning up.", PLUGIN_NAME); emberAfCorePrintln("%p Stop. Cleaning up.", PLUGIN_NAME);
emberAfPluginNetworkSteeringCompleteCallback(status, emberAfPluginNetworkSteeringCompleteCallback(status,
emAfPluginNetworkSteeringTotalBeacons, emAfPluginNetworkSteeringTotalBeacons,
emAfPluginNetworkSteeringJoinAttempts, emAfPluginNetworkSteeringJoinAttempts,
emAfPluginNetworkSteeringState); emAfPluginNetworkSteeringState);
emAfPluginNetworkSteeringClearStoredPanIds(); emAfPluginNetworkSteeringClearStoredPanIds();
emAfPluginNetworkSteeringState = EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE; emAfPluginNetworkSteeringState = EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE;
emAfPluginNetworkSteeringPanIdIndex = 0; emAfPluginNetworkSteeringPanIdIndex = 0;
emAfPluginNetworkSteeringJoinAttempts = 0; emAfPluginNetworkSteeringJoinAttempts = 0;
emAfPluginNetworkSteeringTotalBeacons = 0; emAfPluginNetworkSteeringTotalBeacons = 0;
} }
static uint8_t getNextChannel(void) static uint8_t getNextChannel(void)
{ {
if (emAfPluginNetworkSteeringCurrentChannel == 0) { if (emAfPluginNetworkSteeringCurrentChannel == 0) {
emAfPluginNetworkSteeringCurrentChannel = (halCommonGetRandom() & 0x0F) emAfPluginNetworkSteeringCurrentChannel = (halCommonGetRandom() & 0x0F)
+ EMBER_MIN_802_15_4_CHANNEL_NUMBER; + EMBER_MIN_802_15_4_CHANNEL_NUMBER;
debugPrintln("Randomly choosing a starting channel %d.", emAfPluginNetworkSteeringCurrentChannel); emberAfCorePrintln("Randomly choosing a starting channel %d.", emAfPluginNetworkSteeringCurrentChannel);
} else { } else {
emAfPluginNetworkSteeringCurrentChannel++; emAfPluginNetworkSteeringCurrentChannel++;
} }
while (currentChannelMask != 0) { while (currentChannelMask != 0) {
if (BIT32(emAfPluginNetworkSteeringCurrentChannel) & currentChannelMask) { if (BIT32(emAfPluginNetworkSteeringCurrentChannel) & currentChannelMask) {
currentChannelMask &= ~(BIT32(emAfPluginNetworkSteeringCurrentChannel)); currentChannelMask &= ~(BIT32(emAfPluginNetworkSteeringCurrentChannel));
return emAfPluginNetworkSteeringCurrentChannel; return emAfPluginNetworkSteeringCurrentChannel;
} }
emAfPluginNetworkSteeringCurrentChannel++; emAfPluginNetworkSteeringCurrentChannel++;
if (emAfPluginNetworkSteeringCurrentChannel > EMBER_MAX_802_15_4_CHANNEL_NUMBER) { if (emAfPluginNetworkSteeringCurrentChannel > EMBER_MAX_802_15_4_CHANNEL_NUMBER) {
emAfPluginNetworkSteeringCurrentChannel = EMBER_MIN_802_15_4_CHANNEL_NUMBER; emAfPluginNetworkSteeringCurrentChannel = EMBER_MIN_802_15_4_CHANNEL_NUMBER;
} }
} }
return 0; return 0;
} }
static EmberStatus stateMachineRun(void) static EmberStatus stateMachineRun(void)
{ {
EmberStatus status = EMBER_SUCCESS; EmberStatus status = EMBER_SUCCESS;
emberAfCorePrintln("%p State: %p", emberAfCorePrintln("%p State: %p",
PLUGIN_NAME, PLUGIN_NAME,
emAfPluginNetworkSteeringStateNames[emAfPluginNetworkSteeringState]); emAfPluginNetworkSteeringStateNames[emAfPluginNetworkSteeringState]);
if ((status = setupSecurity()) != EMBER_SUCCESS) { if ((status = setupSecurity()) != EMBER_SUCCESS) {
emberAfCorePrintln("Error: %p could not setup security: 0x%X", emberAfCorePrintln("Error: %p could not setup security: 0x%X",
PLUGIN_NAME, PLUGIN_NAME,
status); status);
return tryNextMethod(); return tryNextMethod();
} }
switch (emAfPluginNetworkSteeringState) {
switch (emAfPluginNetworkSteeringState) { case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED:
case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED: case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE:
case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE: case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED:
case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED: case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_DISTRIBUTED:
case EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_DISTRIBUTED: currentChannelMask = emAfPluginNetworkSteeringPrimaryChannelMask;
currentChannelMask = emAfPluginNetworkSteeringPrimaryChannelMask; break;
break; default:
default: currentChannelMask = emAfPluginNetworkSteeringSecondaryChannelMask;
currentChannelMask = emAfPluginNetworkSteeringSecondaryChannelMask; break;
break; }
}
emberAfCorePrintln("Channel Mask: 0x%4X", currentChannelMask);
debugPrintln("Channel Mask: 0x%4X", currentChannelMask); gotoNextChannel();
gotoNextChannel(); return status;
return status;
} }
static EmberStatus setupSecurity(void) static EmberStatus setupSecurity(void)
{ {
EmberStatus status; EmberStatus status;
EmberInitialSecurityState state; EmberInitialSecurityState state;
EmberExtendedSecurityBitmask extended; EmberExtendedSecurityBitmask extended;
...@@ -535,42 +534,42 @@ static EmberStatus setupSecurity(void) ...@@ -535,42 +534,42 @@ static EmberStatus setupSecurity(void)
EmberStatus emberAfPluginNetworkSteeringStart(void) EmberStatus emberAfPluginNetworkSteeringStart(void)
{ {
EmberStatus status = EMBER_INVALID_CALL; EmberStatus status = EMBER_INVALID_CALL;
if (emAfProIsCurrentNetwork() if(emAfProIsCurrentNetwork()
&& (emAfPluginNetworkSteeringState && (emAfPluginNetworkSteeringState
== EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE)) { == EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE)) {
if (emberAfNetworkState() == EMBER_NO_NETWORK) { if (emberAfNetworkState() == EMBER_NO_NETWORK) {
emAfPluginNetworkSteeringState = gUseConfiguredKey emAfPluginNetworkSteeringState = gUseConfiguredKey
? EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED ? EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED
: EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE; : EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE;
// Stop any previous trust center link key update. // Stop any previous trust center link key update.
emberAfPluginUpdateTcLinkKeyStop(); emberAfPluginUpdateTcLinkKeyStop();
status = stateMachineRun(); status = stateMachineRun();
} else { } else {
status = emberAfPermitJoin(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S, status = emberAfPermitJoin(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S,
true); // Broadcast permit join? true); // Broadcast permit join?
} }
} }
emberAfCorePrintln("%p: %p: 0x%X", emberAfCorePrintln("%p: %p: 0x%X",
emAfNetworkSteeringPluginName, emAfNetworkSteeringPluginName,
"Start", "Start",
status); status);
return status; return status;
} }
EmberStatus emberAfPluginNetworkSteeringStop(void) EmberStatus emberAfPluginNetworkSteeringStop(void)
{ {
if (emAfPluginNetworkSteeringState if (emAfPluginNetworkSteeringState
== EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE) { == EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE) {
return EMBER_INVALID_CALL; return EMBER_INVALID_CALL;
} }
cleanupAndStop(EMBER_JOIN_FAILED); cleanupAndStop(EMBER_JOIN_FAILED);
return EMBER_SUCCESS; return EMBER_SUCCESS;
} }
// ============================================================================= // =============================================================================
...@@ -649,36 +648,36 @@ bool emberAfPluginUpdateTcLinkKeyStatusCallback(EmberKeyStatus keyStatus) ...@@ -649,36 +648,36 @@ bool emberAfPluginUpdateTcLinkKeyStatusCallback(EmberKeyStatus keyStatus)
void emAfPluginNetworkSteeringSetChannelMask(uint32_t mask, bool secondaryMask) void emAfPluginNetworkSteeringSetChannelMask(uint32_t mask, bool secondaryMask)
{ {
if (secondaryMask) { if (secondaryMask) {
emAfPluginNetworkSteeringSecondaryChannelMask = mask; emAfPluginNetworkSteeringSecondaryChannelMask = mask;
} else { } else {
emAfPluginNetworkSteeringPrimaryChannelMask = mask; emAfPluginNetworkSteeringPrimaryChannelMask = mask;
} }
} }
void emAfPluginNetworkSteeringSetExtendedPanIdFilter(uint8_t* extendedPanId, void emAfPluginNetworkSteeringSetExtendedPanIdFilter(uint8_t* extendedPanId,
bool turnFilterOn) bool turnFilterOn)
{ {
if (!extendedPanId) { if (!extendedPanId) {
return; return;
} }
MEMCOPY(gExtendedPanIdToFilterOn, MEMCOPY(gExtendedPanIdToFilterOn,
extendedPanId, extendedPanId,
COUNTOF(gExtendedPanIdToFilterOn)); COUNTOF(gExtendedPanIdToFilterOn));
gFilterByExtendedPanId = turnFilterOn; gFilterByExtendedPanId = turnFilterOn;
} }
void emAfPluginNetworkSteeringSetConfiguredKey(uint8_t *key, void emAfPluginNetworkSteeringSetConfiguredKey(uint8_t *key,
bool useConfiguredKey) bool useConfiguredKey)
{ {
if (!key) { if (!key) {
return; return;
} }
MEMCOPY(gConfiguredKey.contents, key, EMBER_ENCRYPTION_KEY_SIZE); MEMCOPY(gConfiguredKey.contents, key, EMBER_ENCRYPTION_KEY_SIZE);
gUseConfiguredKey = useConfiguredKey; gUseConfiguredKey = useConfiguredKey;
} }
void emAfPluginNetworkSteeringCleanup(EmberStatus status) void emAfPluginNetworkSteeringCleanup(EmberStatus status)
{ {
cleanupAndStop(status); cleanupAndStop(status);
} }
...@@ -12,7 +12,7 @@ extern PGM uint8_t emAfNetworkSteeringPluginName[]; ...@@ -12,7 +12,7 @@ extern PGM uint8_t emAfNetworkSteeringPluginName[];
// Types // Types
enum { enum {
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE = 0x00, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE = 0x00,
// These next two states are only run if explicitly configured to do so // These next two states are only run if explicitly configured to do so
// See emAfPluginNetworkSteeringSetConfiguredKey() // See emAfPluginNetworkSteeringSetConfiguredKey()
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED = 0x01, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CONFIGURED = 0x01,
...@@ -22,8 +22,8 @@ enum { ...@@ -22,8 +22,8 @@ enum {
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED = 0x05, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_CENTRALIZED = 0x05,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_CENTRALIZED = 0x06, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_CENTRALIZED = 0x06,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_DISTRIBUTED = 0x07, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_DISTRIBUTED = 0x07,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_DISTRIBUTED = 0x08, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_SECONDARY_DISTRIBUTED = 0x08,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_FINISHED = 0x09, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_FINISHED = 0x09,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_UPDATE_TCLK = 0x10, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_UPDATE_TCLK = 0x10,
EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_VERIFY_TCLK = 0x20, EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_VERIFY_TCLK = 0x20,
......
...@@ -65,11 +65,11 @@ EmberStatus emberAfPluginUpdateTcLinkKeyStart(void) ...@@ -65,11 +65,11 @@ EmberStatus emberAfPluginUpdateTcLinkKeyStart(void)
bool emberAfPluginUpdateTcLinkKeyStop(void) bool emberAfPluginUpdateTcLinkKeyStop(void)
{ {
uint8_t oldState = state; uint8_t oldState = state;
state = STATE_NONE; state = STATE_NONE;
return (oldState != STATE_NONE); return (oldState != STATE_NONE);
} }
void emberAfPluginUpdateTcLinkKeySetDelay(uint32_t delayMs) void emberAfPluginUpdateTcLinkKeySetDelay(uint32_t delayMs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment