static CommissioningState_t CheckNetwork(void) {
  emberAfDebugPrintln("DEBUG: Check Network state");
  EmberNetworkStatus nw_status = emberNetworkState();
  emberAfDebugPrintln("DEBUG: network state 0x%X", nw_status);
  if (nw_status == EMBER_JOINING_NETWORK ||
      nw_status == EMBER_LEAVING_NETWORK) {
    // Try to check again after 5 seconds
    emberEventControlSetDelayQS(StateMachineEvent,
                                SIMPLE_COMMISSIONING_NETWORK_RETRY_DELAY);

    return SC_EZ_START;
  }

  if (nw_status == EMBER_JOINED_NETWORK) {
    SetNextEvent(SC_EZEV_BCAST_IDENT_QUERY);
    // Send Permit Join broadcast to the current network
    // in case of ZED nothing will happen
    // TODO: Make this hadrcoded value as plugin's option
    emberAfPermitJoin(SIMPLE_COMMISSIONING_PERMIT_JOIN_TIME, TRUE);
  } else if (nw_status == EMBER_NO_NETWORK &&
             GetNetworkTries() < NETWORK_ACCESS_CONS_TRIES) {
    // Form or join available network
    SetNextEvent(SC_EZEV_FORM_JOIN_NETWORK);
  } else {
    SetNextEvent(SC_EZEV_NETWORK_FAILED);
  }

  // if the device is in the network continue commissioning
  // by sending Identify Query
  emberEventControlSetActive(StateMachineEvent);

  return SC_EZ_START;
}
Пример #2
0
EmberStatus emberAfPluginNetworkSteeringStart(void)
{
  EmberStatus status = EMBER_INVALID_CALL;

  if (emAfProIsCurrentNetwork()
      && (emAfPluginNetworkSteeringState
          == EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_NONE)) {
    if (emberAfNetworkState() == EMBER_NO_NETWORK) {
      emAfPluginNetworkSteeringState
        = EMBER_AF_PLUGIN_NETWORK_STEERING_STATE_SCAN_PRIMARY_INSTALL_CODE;

      // Stop any previous trust center link key update.
      emberAfPluginUpdateTcLinkKeyStop();

      status = stateMachineRun();
    } else {
      status = emberAfPermitJoin(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S,
                                 true); // Broadcast permit join?
    }
  }

  emberAfCorePrintln("%p: %p: 0x%X",
                     emAfNetworkSteeringPluginName,
                     "Start",
                     status);

  return status;
}
Пример #3
0
void emberAfPluginNetworkSteeringFinishSteeringEventHandler(void)
{
  EmberStatus status;

  emberEventControlSetInactive(finishSteeringEvent);

  if (emAfPluginNetworkSteeringStateVerifyTclk()) {
    // If we get here, then we have failed to verify the TCLK. Therefore,
    // we leave the network.
    emberAfPluginUpdateTcLinkKeyStop();
    emberLeaveNetwork();
    emberAfCorePrintln("%p: %p",
                       PLUGIN_NAME,
                       "Key verification failed. Leaving network");
    cleanupAndStop(EMBER_ERR_FATAL);
  } else if (emAfPluginNetworkSteeringStateUpdateTclk()) {
    // Start the process to update the TC link key. We will set another event
    // for the broadcast permit join.
    status = emberAfPluginUpdateTcLinkKeyStart();
    emberAfCorePrintln("%p: %p: 0x%X",
                       PLUGIN_NAME,
                       "Starting update trust center link key process",
                       status);
    if (status != EMBER_SUCCESS) {
      emberLeaveNetwork();
      cleanupAndStop(status);
    }
  } else {
    // Broadcast permit join to extend the network.
    // We are done!
    status = emberAfPermitJoin(EMBER_AF_PLUGIN_NETWORK_STEERING_COMMISSIONING_TIME_S,
                               true); // Broadcast permit join?
    emberAfCorePrintln("%p: %p: 0x%X",
                       PLUGIN_NAME,
                       "Broadcasting permit join",
                       status);
    cleanupAndStop(status);
  }
}