summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/ConfigServer/src
diff options
context:
space:
mode:
authorFlorent Duchon2012-12-26 17:36:00 +0100
committerFlorent Duchon2013-02-13 21:21:12 +0100
commitb24866225a6301d3a663f874725e83c012dc25d3 (patch)
treeca527a2aab9abcdfbaf244c53ca63f0c531892b0 /digital/zigbit/bitcloud/stack/Components/ConfigServer/src
parent2ba279f4eb2f23fa08a7c13465d16ae6ba5d0f96 (diff)
digital/beacon: add bitcloud stack into common directory digital/zigbit
Diffstat (limited to 'digital/zigbit/bitcloud/stack/Components/ConfigServer/src')
-rw-r--r--digital/zigbit/bitcloud/stack/Components/ConfigServer/src/configServer.c244
-rw-r--r--digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csMem.c289
-rw-r--r--digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csPersistentMem.c221
3 files changed, 754 insertions, 0 deletions
diff --git a/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/configServer.c b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/configServer.c
new file mode 100644
index 00000000..104776a2
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/configServer.c
@@ -0,0 +1,244 @@
+/******************************************************************************
+ \file configServer.c
+
+ \brief
+ Configuration Server implementation
+
+ \author
+ Atmel Corporation: http://www.atmel.com \n
+ Support email: avr@atmel.com
+
+ Copyright (c) 2010 , Atmel Corporation. All rights reserved.
+ Licensed under Atmel's Limited License Agreement (BitCloudTM).
+
+ \internal
+ History:
+ 19.10.10 A. Razinkov - Created.
+******************************************************************************/
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <configServer.h>
+#include <macenvMem.h>
+#include <csSIB.h>
+#include <csDbg.h>
+#include <csBuffers.h>
+#ifdef _POWER_FAILURE_
+#include <pdsDataServer.h>
+#endif /* _POWER_FAILURE_ */
+#ifndef _MAC2_
+#include <zdoZib.h>
+#else
+#include <macenvPib.h>
+#endif
+
+/******************************************************************************
+ Definitions section
+******************************************************************************/
+#define IS_MEMORY_AREA(item) (0 == (item).size)
+
+/******************************************************************************
+ Types section
+******************************************************************************/
+typedef enum _CS_MemoryLocation_t
+{
+ CS_MEMORY_LOCATION_FLASH,
+ CS_MEMORY_LOCATION_RAM
+} CS_MemoryLocation_t;
+
+
+/******************************************************************************
+ External variables section
+******************************************************************************/
+extern PIB_t csPIB;
+extern SIB_t csSIB;
+#ifndef _MAC2_
+extern NIB_t csNIB;
+extern ZIB_t csZIB;
+#endif
+extern CS_MemoryItem_t PROGMEM_DECLARE(csMemoryItems[]);
+extern CS_StackBuffers_t stackBuffers;
+
+/******************************************************************************
+ Functions prototypes section
+******************************************************************************/
+static CS_MemoryItem_t csGetItem(CS_MemoryItemId_t itemId);
+static CS_MemoryLocation_t csGetItemLocation(CS_MemoryItemId_t itemId);
+
+/******************************************************************************
+ Implementation section
+******************************************************************************/
+/******************************************************************************
+\brief Configuration Server initialization
+******************************************************************************/
+void CS_Init(void)
+{
+ csSetToDefault();
+#ifdef _COMMISSIONING_
+ PDS_Init();
+#endif /* _COMMISSIONING_ */
+}
+
+/******************************************************************************
+\brief Gets the parameter specified by it's identifier
+
+\param[in] parameterId - ID of the parameter being read
+\param[out] parameterValue - pointer to the memory
+
+******************************************************************************/
+void CS_ReadParameter(CS_MemoryItemId_t parameterId, void *parameterValue)
+{
+ if (parameterValue)
+ {
+ CS_MemoryItem_t item = csGetItem(parameterId);
+
+ /* Read item value from memory it's placed. This is not valid for memory areas -
+ * use CS_GetMemory() instead */
+ if (CS_MEMORY_LOCATION_FLASH == csGetItemLocation(parameterId))
+ memcpy_P(parameterValue, item.value.flashValue, item.size);
+ else
+ memcpy(parameterValue, item.value.ramValue, item.size);
+ }
+}
+
+/******************************************************************************
+\brief Sets the parameter specified by it's identifier
+
+\param[in] parameterId - ID of the parameter being written
+\param[out] parameterValue - pointer to the parameter
+
+******************************************************************************/
+void CS_WriteParameter(CS_MemoryItemId_t parameterId, const void *parameterValue)
+{
+ if (parameterValue && (CS_MEMORY_LOCATION_RAM == csGetItemLocation(parameterId)))
+ {
+ CS_MemoryItem_t item = csGetItem(parameterId);
+
+ if (!IS_MEMORY_AREA(item))
+ memcpy(item.value.ramValue, parameterValue, item.size);
+ }
+}
+
+/******************************************************************************
+\brief Gets allocated memory specified by memory identifier
+
+\param[in] memoryId - memory area Id
+\param[out] memoryPtr - pointer to the memory
+
+******************************************************************************/
+void CS_GetMemory(CS_MemoryItemId_t memoryId, void **memoryPtr)
+{
+ CS_MemoryItem_t item = csGetItem(memoryId);
+
+ if (IS_MEMORY_AREA(item))
+ *((void **)memoryPtr) = item.value.ramValue;
+}
+
+/******************************************************************************
+\brief Set PDS default
+
+******************************************************************************/
+void CS_PdsDefaultValue(void)
+{
+ csPIB.macAttr.extAddr = CCPU_TO_LE64(CS_UID);
+ csSIB.csRfTxPower = CS_RF_TX_POWER;
+#ifndef _MAC2_
+ csSIB.csExtPANID = CCPU_TO_LE64(CS_EXT_PANID);
+ csZIB.channelMask = CS_CHANNEL_MASK;
+ csNIB.channelPage = CS_CHANNEL_PAGE;
+ csNIB.deviceType = CS_DEVICE_TYPE;
+ csSIB.csRxOnWhenIdle = (CS_DEVICE_TYPE == DEVICE_TYPE_END_DEVICE) ? CS_RX_ON_WHEN_IDLE : true;
+ csSIB.csComplexDescriptorAvailable = CS_COMPLEX_DESCRIPTOR_AVAILABLE;
+ csSIB.csUserDescriptorAvailable = CS_USER_DESCRIPTOR_AVAILABLE;
+ csSIB.csNwkPanid = CCPU_TO_LE16(CS_NWK_PANID);
+ csSIB.csNwkPredefinedPanid = CS_NWK_PREDEFINED_PANID,
+ csNIB.networkAddress = CCPU_TO_LE16(CS_NWK_ADDR);
+ csNIB.uniqueAddr = CS_NWK_UNIQUE_ADDR;
+ csSIB.csDtrWakeup = CS_DTR_WAKEUP;
+#if defined(_POWER_FAILURE_)
+ csNIB.parentNetworkAddress = CCPU_TO_LE16(0xFFFF);
+ csNIB.depth = 0;
+ csNIB.extendedPanId = CCPU_TO_LE64(CS_NWK_EXT_PANID);
+ csSIB.csNwkLogicalChannel = 0;
+ csSIB.csPowerFailure = CS_POWER_FAILURE;
+#endif /* _POWER_FAILURE_ */
+#if defined(_SECURITY_)
+ csAIB.trustCenterAddress = CCPU_TO_LE64(CS_APS_TRUST_CENTER_ADDRESS);
+ csSIB.csZdoSecurityStatus = CS_ZDO_SECURITY_STATUS;
+#endif /* _SECURITY_ */
+
+ /* Parameters not to store in EEPROM */
+ csNIB.maxNeighborRouteCost = CS_MAX_NEIGHBOR_ROUTE_COST;
+ csSIB.csNwkMaxLinkStatusFailures = CS_NWK_MAX_LINK_STATUS_FAILURES;
+ csSIB.csNwkEndDeviceMaxFailures = CS_NWK_END_DEVICE_MAX_FAILURES;
+#ifdef AT86RF212
+ csSIB.csLbtMode = CS_LBT_MODE;
+#endif /* AT86RF212 */
+#if defined(_SECURITY_)
+ csSIB.csSecurityOn = CS_SECURITY_ON;
+#endif /* _SECURITY_ */
+
+ /* Buffers cleaning */
+#if defined(_POWER_FAILURE_)
+ memset(&stackBuffers.csNeibTable, 0, CS_NEIB_TABLE_SIZE);
+ #if defined(_BINDING_) && (CS_APS_BINDING_TABLE_SIZE > 0)
+ memset(&stackBuffers.csApsBindingTable, 0, CS_APS_BINDING_TABLE_SIZE);
+ #endif /* _BINDING_ */
+ #if defined(_SECURITY_)
+ {
+ csNIB.securityIB.securityLevel = CS_SECURITY_LEVEL;
+ csNIB.securityIB.secureAllFrames = CS_SECURITY_ALL_FRAMES;
+ NWK_ResetSecurityIB(NWK_GetDefaultPowerFailureControl());
+ }
+ #endif /* _SECURITY_ */
+#endif /* _POWER_FAILURE_ */
+#if defined (_GROUP_TABLE_)
+ memset(&stackBuffers.csGroupTable, 0, CS_GROUP_TABLE_SIZE);
+#endif /* _GROUP_TABLE_ */
+#if defined(_SECURITY_)
+ #if defined(_TC_PERMISSION_TABLE_) && CS_MAX_TC_ALLOWED_DEVICES_AMOUNT > 0
+ memset(&stackBuffers.csTcDevicePermissionTable, 0, CS_MAX_TC_ALLOWED_DEVICES_AMOUNT);
+ #endif /* _TC_PERMISSION_TABLE_ */
+ #if defined _LINK_SECURITY_ && CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT > 0
+
+ memset(&stackBuffers.csApsKeyPairDescriptors, 0, CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT);
+ #endif /* _LINK_SECURITY_ */
+
+#endif /* _SECURITY_ */
+#endif /* _MAC2_ */
+}
+
+/******************************************************************************
+\brief Returns Configuration Server item by it's identifier
+
+\param[in] itemId - ID of the parameter
+
+\return - Configuration Server item
+******************************************************************************/
+static CS_MemoryItem_t csGetItem(CS_MemoryItemId_t itemId)
+{
+ CS_MemoryItem_t item;
+
+ /* Read item info from the FLASH */
+ memcpy_P(&item, &csMemoryItems[itemId], sizeof(CS_MemoryItem_t));
+ assert(item.value.flashValue, CS_CSGETITEM0);
+ return item;
+}
+
+/******************************************************************************
+\brief Returns the location where item placed
+
+\param[in] itemId - ID of the parameter
+
+\return - item location: FLASH or RAM
+******************************************************************************/
+static CS_MemoryLocation_t csGetItemLocation(CS_MemoryItemId_t itemId)
+{
+ if (CS_FLASH_PARAMETERS_START_ID < itemId)
+ return CS_MEMORY_LOCATION_FLASH;
+ else
+ return CS_MEMORY_LOCATION_RAM;
+}
+
+/* eof configServer.c */
diff --git a/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csMem.c b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csMem.c
new file mode 100644
index 00000000..c92061e6
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csMem.c
@@ -0,0 +1,289 @@
+/******************************************************************************
+ \file csMem.c
+
+ \brief
+ BitCloud information bases memory
+
+ \author
+ Atmel Corporation: http://www.atmel.com \n
+ Support email: avr@atmel.com
+
+ Copyright (c) 2010 , Atmel Corporation. All rights reserved.
+ Licensed under Atmel's Limited License Agreement (BitCloudTM).
+
+ \internal
+ History:
+ 21.10.10 A. Razinkov - Created.
+******************************************************************************/
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <csBuffers.h>
+#include <macenvMem.h>
+#ifndef _MAC2_
+#include <zdoZib.h>
+#endif
+#include <csSIB.h>
+#include <csDefaults.h>
+#include <configServer.h>
+
+/******************************************************************************
+ Global variables section
+******************************************************************************/
+
+/* BitCloud information bases allocation */
+PIB_t csPIB;
+#ifndef _MAC2_
+NIB_t csNIB;
+ZIB_t csZIB;
+AIB_t csAIB;
+#endif
+SIB_t csSIB;
+
+/* BitCloud memory buffers allocation */
+CS_StackBuffers_t stackBuffers;
+
+/* FLASH memory allocation to store read-only parameters */
+
+/* Default information bases item values */
+#ifndef _MAC2_
+NIB_t PROGMEM_DECLARE(defaultNIB) =
+{
+#if defined _SECURITY_
+ .securityIB = {
+ .securityLevel = CS_SECURITY_LEVEL,
+ .secureAllFrames = CS_SECURITY_ALL_FRAMES,
+ .keyAmount = CS_NWK_SECURITY_KEYS_AMOUNT,
+ .key = stackBuffers.csNwkSecKeys,
+ .counter = stackBuffers.csNwkSecCounters
+ },
+#endif
+ .deviceType = CS_DEVICE_TYPE,
+ .addrAlloc = CS_ADDRESS_ASSIGNMENT_METHOD,
+ .symLink = true,
+ .uniqueAddr = CS_NWK_UNIQUE_ADDR,
+ .stackProfile = CS_STACK_PROFILE,
+ .protocolVersion = CS_PROTOCOL_VERSION,
+ .maxDepth = CS_MAX_NETWORK_DEPTH,
+ .maxNeighborRouteCost = CS_MAX_NEIGHBOR_ROUTE_COST,
+ .channelPage = CS_CHANNEL_PAGE,
+ .logicalChannel = 0,
+ .networkAddress = CCPU_TO_LE16(CS_NWK_ADDR),
+ .panId = CCPU_TO_LE16(CS_NWK_PANID),
+ .extendedPanId = CCPU_TO_LE64(CS_NWK_EXT_PANID), /* uses as joined-to-network flag */
+ .maxRouters = CS_MAX_CHILDREN_ROUTER_AMOUNT,
+ .maxEndDevices = CS_MAX_CHILDREN_AMOUNT - CS_MAX_CHILDREN_ROUTER_AMOUNT
+};
+
+ZIB_t PROGMEM_DECLARE(defaultZIB) =
+{
+ .permitJoinDuration = CS_PERMIT_DURATION,
+ .channelMask = CS_CHANNEL_MASK,
+ .zdpResponseTimeout = CS_ZDP_RESPONSE_TIMEOUT,
+ .scanDuration = CS_SCAN_DURATION,
+};
+
+AIB_t PROGMEM_DECLARE(defaultAIB) =
+{
+ .nonMemberRadius = APS_AIB_NONMEMBER_RADIUS_DEFAULT_VALUE, /* See ZigBee spec r19, Table 2.24. */
+#ifdef _SECURITY_
+ .trustCenterAddress = CCPU_TO_LE64(CS_APS_TRUST_CENTER_ADDRESS),
+#endif /* _SECURITY_ */
+};
+#endif /* !_MAC2_*/
+
+SIB_t PROGMEM_DECLARE(defaultSIB) =
+{
+ /* MAC parameters */
+ .csMacTransactionTime = CS_MAC_TRANSACTION_TIME,
+ .csRfTxPower = CS_RF_TX_POWER,
+#ifdef AT86RF212
+ .csLbtMode = CS_LBT_MODE,
+#endif //AT86RF212
+#ifndef _MAC2_
+
+ /* NWK parameters */
+ .csNwkPanid = CCPU_TO_LE16(CS_NWK_PANID),
+ .csNwkUseMulticast = CS_NWK_USE_MULTICAST,
+ .csNwkMaxLinkStatusFailures = CS_NWK_MAX_LINK_STATUS_FAILURES,
+ .csNwkEndDeviceMaxFailures = CS_NWK_END_DEVICE_MAX_FAILURES,
+ .csNwkLogicalChannel = 0,
+ .csNwkPredefinedPanid = CS_NWK_PREDEFINED_PANID,
+#ifdef _NWK_CONCENTRATOR_
+ .csNwkConcentratorDiscoveryTime = NWK_CONCENTRATOR_DISCOVERY_TIME,
+#endif
+
+ /* ZDO parameters */
+ .csEndDeviceSleepPeriod = CS_END_DEVICE_SLEEP_PERIOD,
+ .csFfdSleepPeriod = CS_FFD_SLEEP_PERIOD,
+ .csRxOnWhenIdle = (CS_DEVICE_TYPE == DEVICE_TYPE_END_DEVICE) ? CS_RX_ON_WHEN_IDLE : true,
+ .csComplexDescriptorAvailable = CS_COMPLEX_DESCRIPTOR_AVAILABLE,
+ .csUserDescriptorAvailable = CS_USER_DESCRIPTOR_AVAILABLE,
+ .csUserDescriptor = {.FieldLength = ZDP_USER_DESC_FIELD_SIZE, .FieldName = "Atmel "},
+ .csIndirectPollRate = CS_INDIRECT_POLL_RATE,
+ .csZdoJoinAttempts = CS_ZDO_JOIN_ATTEMPTS,
+ .csZdoJoinInterval = CS_ZDO_JOIN_INTERVAL,
+ .csExtPANID = CCPU_TO_LE64(CS_EXT_PANID), /* user-defined PAN ID */
+#ifdef _TC_SWAPOUT_
+ .csZdoTcKeepAliveInterval = CS_ZDO_TC_KEEP_ALIVE_INTERVAL,
+#endif // _TC_SWAPOUT_
+
+ /* APS parameters */
+ .csApsMaxFrameRetries = CS_APS_MAX_FRAME_RETRIES,
+#ifdef _APS_FRAGMENTATION_
+ .csApsMaxTransmissionWindowSize = CS_APS_MAX_TRANSMISSION_WINDOW_SIZE,
+#endif /* _APS_FRAGMENTATION_ */
+
+ /* PDS parameters*/
+ .csDtrWakeup = CS_DTR_WAKEUP,
+
+ /* ZCL parameters */
+#ifdef _ZCL_
+ .csZclAttributeReportTimerInterval = CS_ZCL_ATTRIBUTE_REPORT_TIMER_INTERVAL,
+ #ifdef _OTAU_
+ .csOtauDefaultServerAddress = CS_ZCL_OTAU_DEFAULT_UPGRADE_SERVER_IEEE_ADDRESS,
+ .csOtauServerDiscoveryPeriod = CS_ZCL_OTAU_SERVER_DISCOVERY_PERIOD,
+ .csOtauServerPageRequestUsage = CS_ZCL_OTAU_IMAGE_PAGE_REQUEST_USAGE,
+ #endif /* _OTAU_ */
+#endif /* _ZCL_ */
+
+ /* Other parameters */
+#ifdef _COMMISSIONING_
+ .csPdsStoringInterval = CS_PDS_STORING_INTERVAL,
+ #ifdef _POWER_FAILURE_
+ .csPowerFailure = CS_POWER_FAILURE,
+ #endif /* _POWER_FAILURE_ */
+#endif /* _COMMISSIONING_ */
+
+ /* Security parameters */
+#ifdef _SECURITY_
+ .csSecurityOn = CS_SECURITY_ON,
+ .csZdoSecurityStatus = CS_ZDO_SECURITY_STATUS,
+#endif /* _SECURITY_ */
+#endif /* _MAC2_ */
+};
+
+#ifdef _SECURITY_
+uint8_t defaultKey[SECURITY_KEY_SIZE] = CS_NETWORK_KEY;
+#endif /* _SECURITY_ */
+
+CS_ReadOnlyItems_t PROGMEM_DECLARE(csReadOnlyItems) =
+{
+ /* MAC parameters */
+ .csMacFrameRxBufferSize = CS_MAC_FRAME_RX_BUFFER_SIZE,
+#ifdef _MAC_BAN_NODE_
+ .csMacBanTableSize = CS_BAN_TABLE_SIZE,
+#endif /* _MAC_BAN_NODE_ */
+
+ /* NWK parameters */
+#ifndef _MAC2_
+ .csNwkRouteCacheSize = CS_ROUTE_CACHE_SIZE,
+ .csNeibTableSize = CS_NEIB_TABLE_SIZE,
+ .csMacPanDescriptorAmount = CS_NEIB_TABLE_SIZE,
+ .csMaxChildrenAmount = CS_MAX_CHILDREN_AMOUNT,
+ .csMaxChildrenRouterAmount = CS_MAX_CHILDREN_ROUTER_AMOUNT,
+ .csMaxNetworkDepth = CS_MAX_NETWORK_DEPTH,
+ .csAddressAssignmentMethod = CS_ADDRESS_ASSIGNMENT_METHOD,
+ .csNwkBuffersAmount = CS_NWK_BUFFERS_AMOUNT,
+ .csJoinIndObjAmount = CS_JOIN_IND_OBJ_AMOUNT,
+ .csRouteTableSize = CS_ROUTE_TABLE_SIZE,
+ .csAddressMapTableSize = CS_ADDRESS_MAP_TABLE_SIZE,
+ .csRouteDiscoveryTableSize = CS_ROUTE_DISCOVERY_TABLE_SIZE,
+ .csNwkBttSize = CS_NWK_BTT_SIZE,
+#ifdef _GROUP_TABLE_
+ .csGroupTableSize = CS_GROUP_TABLE_SIZE,
+#endif /* _GROUP_TABLE_ */
+#ifdef _NWK_PASSIVE_ACK_
+ .csPassiveAckAmount = CS_NWK_PASSIVE_ACK_AMOUNT,
+#endif /* _NWK_PASSIVE_ACK_ */
+
+ /* APS parameters */
+ .csApsDataReqBuffersAmount = CS_APS_DATA_REQ_BUFFERS_AMOUNT,
+ .csApsAckFrameBuffesAmount = CS_APS_ACK_FRAME_BUFFERS_AMOUNT,
+ .csDuplicateRejectionTableSize = CS_DUPLICATE_REJECTION_TABLE_SIZE,
+#ifdef _BINDING_
+ .csApsBindingTableSize = CS_APS_BINDING_TABLE_SIZE,
+#endif /* _BINDING_ */
+#ifdef _APS_FRAGMENTATION_
+ .csApsMaxBlocksAmount = CS_APS_MAX_BLOCKS_AMOUNT,
+ .csApsBlockSize = CS_APS_BLOCK_SIZE,
+#endif /* _APS_FRAGMENTATION_ */
+
+#ifdef _ZCL_
+ .csZclMemoryBuffersAmount = CS_ZCL_MEMORY_BUFFERS_AMOUNT,
+ #ifdef _OTAU_
+ .csOtauDiscoveredServerAmount = CS_ZCL_OTAU_DISCOVERED_SERVER_AMOUNT,
+ .csOtauClientSessionAmount = CS_ZCL_OTAU_CLIENT_SESSION_AMOUNT,
+ .csOtauServerPageRequestResponseSpacing = CS_ZCL_OTAU_IMAGE_PAGE_REQUEST_RESPONSE_SPACING,
+ .csOtauServerPageSize = CS_ZCL_OTAU_IMAGE_PAGE_REQUEST_PAGE_SIZE,
+ .csOtauClientMissedBlocksBufferSize = CS_ZCL_OTAU_MISSED_BLOCKS_BUFFER_SIZE,
+ #endif /* _OTAU_ */
+#endif /* _ZCL_ */
+
+#ifdef _SECURITY_
+ .csApsSecurityTimeoutPeriod = CS_APS_SECURITY_TIMEOUT_PERIOD,
+#ifdef _TRUST_CENTRE_
+ .csMaxTcAuthenticProcessAmount = CS_MAX_TC_AUTHENTIC_PROCESS_AMOUNT,
+ #ifdef _TC_PERMISSION_TABLE_
+ .csMaxTcAllowedDevicesAmount = CS_MAX_TC_ALLOWED_DEVICES_AMOUNT,
+ #endif /* _TC_PERMISSION_TABLE_ */
+#endif /* _TRUST_CENTRE_ */
+#ifdef _LINK_SECURITY_
+ #ifdef _TRUST_CENTRE_
+ .csMaxTcEstablishKeyAmount = CS_MAX_TC_ESTABLISH_KEY_AMOUNT,
+ #endif /* _TRUST_CENTRE_ */
+ .csApsKeyPairDescriptorsAmount = CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT,
+#endif /* _LINK_SECURITY_ */
+#endif /* _SECURITY_ */
+ /* Other parameters */
+ .csStackVersion = CS_STACK_VERSION,
+ .csManufacturerCode = CCPU_TO_LE16(CS_MANUFACTURER_CODE),
+#endif /* !_MAC2_*/
+};
+
+/*
+ * \brief Configuration Server items information table stored in FLASH.
+ * Table record contains informaion about corresponding item displacement and size.
+ * Records are automatically sorted by item location and type
+ * (atomic parameter or memory region).
+ */
+#define SEPARATOR(id) {{NULL}, 0},
+#define DUMMY_MEMORY(id) {{NULL}, 0},
+#define FLASH_PARAMETER(id, addr) {{(const void FLASH_PTR*)&(addr)}, sizeof(addr)},
+#define RAM_PARAMETER(id, addr) {{(const void FLASH_PTR*)&(addr)}, sizeof(addr)},
+#define MEMORY_REGION(id, addr) {{(const void FLASH_PTR*)&(addr)}, 0},
+CS_MemoryItem_t PROGMEM_DECLARE(csMemoryItems[]) =
+{
+ #include "csParamTable.h"
+};
+#undef SEPARATOR
+#undef DUMMY_MEMORY
+#undef FLASH_PARAMETER
+#undef RAM_PARAMETER
+#undef MEMORY_REGION
+
+/******************************************************************************
+ Implementation section
+******************************************************************************/
+
+/******************************************************************************
+\brief Set Configuration Server memory to its default state
+******************************************************************************/
+void csSetToDefault(void)
+{
+ /* Restore information bases default values from FLASH */
+ memset(&csPIB, 0x00, sizeof(PIB_t));
+ csPIB.macAttr.extAddr = CCPU_TO_LE64(CS_UID);
+ csPIB.macAttr.maxFrameTransmissionTime = CS_MAX_FRAME_TRANSMISSION_TIME;
+
+#ifndef _MAC2_
+ memcpy_P(&csNIB, &defaultNIB, sizeof(NIB_t));
+ memcpy_P(&csZIB, &defaultZIB, sizeof(ZIB_t));
+ memcpy_P(&csAIB, &defaultAIB, sizeof(AIB_t));
+#endif
+ memcpy_P(&csSIB, &defaultSIB, sizeof(SIB_t));
+ memset(&stackBuffers, 0x00, sizeof(CS_StackBuffers_t));
+}
+
+/* eof csMem.c */
diff --git a/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csPersistentMem.c b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csPersistentMem.c
new file mode 100644
index 00000000..a6f5fb34
--- /dev/null
+++ b/digital/zigbit/bitcloud/stack/Components/ConfigServer/src/csPersistentMem.c
@@ -0,0 +1,221 @@
+/******************************************************************************
+ \file csPersistentMem.c
+
+ \brief
+ Configuration Server persistent memory to store in EEPROM
+
+ \author
+ Atmel Corporation: http://www.atmel.com \n
+ Support email: avr@atmel.com
+
+ Copyright (c) 2010 , Atmel Corporation. All rights reserved.
+ Licensed under Atmel's Limited License Agreement (BitCloudTM).
+
+ \internal
+ History:
+ 28.10.10 A. Razinkov - Created.
+******************************************************************************/
+
+/******************************************************************************
+ Includes section
+******************************************************************************/
+#include <csPersistentMem.h>
+#include <macenvMem.h>
+#ifndef _MAC2_
+#include <apsConfigServer.h>
+#include <nwkConfigServer.h>
+#endif
+#include <csSIB.h>
+#include <csBuffers.h>
+#ifndef _MAC2_
+#include <zdoZib.h>
+#endif
+
+/******************************************************************************
+ Defines section
+******************************************************************************/
+/* Macros used to define records in csPersistentMemTable table*/
+#define PERSISTREC(id, address) {address, RECORD_OFFSET(CS_PersistentDataOffsets_t, id)}
+#define RECORD_OFFSET(struct_type, field_name) (offsetof(struct_type, field_name) + SYSTEM_BASE_EEPROM_ADDRESS)
+
+#ifdef _COMMISSIONING_
+#define PERSISTENT_ITEMS_AMOUNT (ARRAY_SIZE(csPersistentMemTable))
+#define PERSISTENT_MEMORY_SIZE (sizeof(CS_PersistentDataOffsets_t))
+#else
+#define PERSISTENT_ITEMS_AMOUNT 0U
+#define PERSISTENT_MEMORY_SIZE 0U
+#endif /* _COMMISSIONING_ */
+
+/******************************************************************************
+ Types section
+******************************************************************************/
+/*
+ * Persistence module used to save some of ConfigServer items to EEPROM.
+ * Items to save enumerated in csPersistentMemTable, stored in FLASH.
+ * This table consists of CS_PersistantData_t records.
+ * Every record have 2 values: address (in RAM) of item to save and the offset - address in
+ * EEPROM, were item will be placed.
+ * Size of area occupied by item calculated by difference from offset of next item.
+ *
+ * Macros PERSISTREC(id, address) is used to mount records in csPersistentMemTable.
+ * It automatically calculates the offsets for each item with the help of RECORD_OFFSET macros.
+ * When all macroses gets expanded, code looks like this:
+ *
+ * typedef struct {
+ * uint8_t id1,
+ * uint16_t id2,
+ * ExtAddr_t id3
+ * } CS_PersistentDataOffsets_t ;
+ * csPersistentMemTable =
+ * {
+ * address1, __field_offset(CS_PersistentDataOffsets_t, id1),
+ * address2, __field_offset(CS_PersistentDataOffsets_t, id2),
+ * address3, __field_offset(CS_PersistentDataOffsets_t, id3),
+ * };
+ *
+ * Please pay attention: records in csPersistentMemTable must be in the same order and under
+ * the same features as defined in CS_PersistentDataOffsets_t offsets structure.
+ */
+
+/* CS_PersistentDataOffsets_t structure used to automatically calculate
+ * offsets for csPersistentMemTable.
+ * Variables of this structure never instantiated. */
+#ifdef _COMMISSIONING_
+BEGIN_PACK
+typedef struct PACK
+{
+ ExtAddr_t CS_UID_ID;
+ int8_t CS_RF_TX_POWER_ID;
+#ifndef _MAC2_
+ ExtPanId_t CS_EXT_PANID_ID;
+ uint32_t CS_CHANNEL_MASK_ID;
+ uint8_t CS_CHANNEL_PAGE_ID;
+ DeviceType_t CS_DEVICE_TYPE_ID;
+ bool CS_RX_ON_WHEN_IDLE_ID;
+ bool CS_COMPLEX_DESCRIPTOR_AVAILABLE_ID;
+ bool CS_USER_DESCRIPTOR_AVAILABLE_ID;
+ UserDescriptor_t CS_ZDP_USER_DESCRIPTOR_ID;
+ PanId_t CS_NWK_PANID_ID;
+ bool CS_NWK_PREDEFINED_PANID_ID;
+ ShortAddr_t CS_NWK_ADDR_ID;
+ bool CS_NWK_UNIQUE_ADDR_ID;
+ bool CS_DTR_WAKEUP_ID;
+#if defined(_POWER_FAILURE_)
+ ShortAddr_t CS_NWK_PARENT_ADDR_ID;
+ uint8_t CS_NWK_DEPTH_ID;
+ ExtPanId_t CS_NWK_EXT_PANID_ID;
+ uint8_t CS_NWK_LOGICAL_CHANNEL_ID;
+ uint8_t CS_POWER_FAILURE_ID;
+#endif /* _POWER_FAILURE_ */
+#if defined(_SECURITY_)
+ ExtAddr_t CS_APS_TRUST_CENTER_ADDRESS_ID;
+ uint8_t CS_ZDO_SECURITY_STATUS_ID;
+#endif /* _SECURITY_ */
+#if defined(_POWER_FAILURE_)
+ uint8_t CS_NEIB_TABLE_ID[CS_NEIB_TABLE_SIZE * sizeof(Neib_t)];
+ #if defined(_BINDING_) && (CS_APS_BINDING_TABLE_SIZE > 0)
+ ApsBindingEntry_t CS_APS_BINDING_TABLE_ID[CS_APS_BINDING_TABLE_SIZE];
+ #endif /* _BINDING_ */
+ #if defined(_SECURITY_)
+ NWK_SecurityIB_t CS_NWK_SECURITY_IB_ID;
+ NWK_SecurityKey_t CS_NWK_SECURITY_KEYS_ID[CS_NWK_SECURITY_KEYS_AMOUNT];
+ #endif /* _SECURITY_ */
+#endif /* _POWER_FAILURE_ */
+#if defined (_GROUP_TABLE_)
+ uint8_t CS_GROUP_TABLE_ID[(CS_GROUP_TABLE_SIZE * sizeof(NWK_GroupTableEntry_t))];
+#endif /* _GROUP_TABLE_ */
+#if defined(_SECURITY_)
+ #if defined(_TC_PERMISSION_TABLE_) && CS_MAX_TC_ALLOWED_DEVICES_AMOUNT > 0
+ uint8_t CS_TC_PERMISSION_TABLE_ID[sizeof(ExtAddr_t) * CS_MAX_TC_ALLOWED_DEVICES_AMOUNT];
+ #endif
+ #if defined _LINK_SECURITY_ && CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT > 0
+
+ uint8_t CS_APS_KEY_PAIR_DESCRIPTORS_ID[(CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT * sizeof(ApsKeyPairDescriptor_t))];
+ #endif
+#endif /* _SECURITY_ */
+#endif /* _MAC2_ */
+} CS_PersistentDataOffsets_t;
+END_PACK
+/******************************************************************************
+ External variables section
+******************************************************************************/
+extern SIB_t csSIB;
+extern NIB_t csNIB;
+extern ZIB_t csZIB;
+extern PIB_t csPIB;
+extern CS_StackBuffers_t stackBuffers;
+#ifdef _LINK_SECURITY_
+extern CS_ReadOnlyItems_t PROGMEM_DECLARE(csReadOnlyItems);
+#endif
+
+/******************************************************************************
+ Global variables section
+******************************************************************************/
+/* Table of Configuration Server persistent parameters, stored in FLASH.
+ * This table is used by Persist Data Server, which performs parameters storing
+ * and backuping from persistent memory.
+ * */
+PROGMEM_DECLARE(const CS_PersistantData_t csPersistentMemTable[]) =
+{
+ PERSISTREC(CS_UID_ID, &csPIB.macAttr.extAddr),
+ PERSISTREC(CS_RF_TX_POWER_ID, &csSIB.csRfTxPower),
+#ifndef _MAC2_
+ PERSISTREC(CS_EXT_PANID_ID, &csSIB.csExtPANID),
+ PERSISTREC(CS_CHANNEL_MASK_ID, &csZIB.channelMask),
+ PERSISTREC(CS_CHANNEL_PAGE_ID, &csNIB.channelPage),
+ PERSISTREC(CS_DEVICE_TYPE_ID, &csNIB.deviceType),
+ PERSISTREC(CS_RX_ON_WHEN_IDLE_ID, &csSIB.csRxOnWhenIdle),
+ PERSISTREC(CS_COMPLEX_DESCRIPTOR_AVAILABLE_ID, &csSIB.csComplexDescriptorAvailable),
+ PERSISTREC(CS_USER_DESCRIPTOR_AVAILABLE_ID, &csSIB.csUserDescriptorAvailable),
+ PERSISTREC(CS_ZDP_USER_DESCRIPTOR_ID, &csSIB.csUserDescriptor),
+ PERSISTREC(CS_NWK_PANID_ID, &csSIB.csNwkPanid),
+ PERSISTREC(CS_NWK_PREDEFINED_PANID_ID, &csSIB.csNwkPredefinedPanid),
+ PERSISTREC(CS_NWK_ADDR_ID, &csNIB.networkAddress),
+ PERSISTREC(CS_NWK_UNIQUE_ADDR_ID, &csNIB.uniqueAddr),
+ PERSISTREC(CS_DTR_WAKEUP_ID, &csSIB.csDtrWakeup),
+#if defined(_POWER_FAILURE_)
+ PERSISTREC(CS_NWK_PARENT_ADDR_ID, &csNIB.parentNetworkAddress),
+ PERSISTREC(CS_NWK_DEPTH_ID, &csNIB.depth),
+ PERSISTREC(CS_NWK_EXT_PANID_ID, &csNIB.extendedPanId),
+ PERSISTREC(CS_NWK_LOGICAL_CHANNEL_ID, &csSIB.csNwkLogicalChannel),
+ PERSISTREC(CS_POWER_FAILURE_ID, &csSIB.csPowerFailure),
+#endif /* _POWER_FAILURE_ */
+#if defined(_SECURITY_)
+ PERSISTREC(CS_APS_TRUST_CENTER_ADDRESS_ID, &csAIB.trustCenterAddress),
+ PERSISTREC(CS_ZDO_SECURITY_STATUS_ID, &csSIB.csZdoSecurityStatus),
+#endif /* _SECURITY_ */
+
+#if defined(_POWER_FAILURE_)
+ PERSISTREC(CS_NEIB_TABLE_ID, &stackBuffers.csNeibTable),
+ #if defined(_BINDING_) && (CS_APS_BINDING_TABLE_SIZE > 0)
+ PERSISTREC(CS_APS_BINDING_TABLE_ID, &stackBuffers.csApsBindingTable),
+ #endif /* _BINDING_ */
+ #if defined(_SECURITY_)
+ PERSISTREC(CS_NWK_SECURITY_IB_ID, &csNIB.securityIB),
+ PERSISTREC(CS_NWK_SECURITY_KEYS_ID, &stackBuffers.csNwkSecKeys),
+ #endif /* _SECURITY_ */
+#endif /* _POWER_FAILURE_ */
+#if defined (_GROUP_TABLE_)
+ PERSISTREC(CS_GROUP_TABLE_ID, &stackBuffers.csGroupTable),
+#endif /* _GROUP_TABLE_ */
+#if defined(_SECURITY_)
+ #if defined(_TC_PERMISSION_TABLE_) && CS_MAX_TC_ALLOWED_DEVICES_AMOUNT > 0
+ PERSISTREC(CS_TC_PERMISSION_TABLE_ID, &stackBuffers.csTcDevicePermissionTable),
+ #endif /* _TC_PERMISSION_TABLE_ */
+ #if defined _LINK_SECURITY_ && CS_APS_KEY_PAIR_DESCRIPTORS_AMOUNT > 0
+
+ PERSISTREC(CS_APS_KEY_PAIR_DESCRIPTORS_ID, &stackBuffers.csApsKeyPairDescriptors),
+ #endif /* _LINK_SECURITY_ */
+
+#endif /* _SECURITY_ */
+#endif /* _MAC2_ */
+};
+#endif /* _COMMISSIONING_ */
+
+/* Number of records in csPersistentMemTable*/
+const uint8_t csPersistentItemsAmount = PERSISTENT_ITEMS_AMOUNT;
+
+/* Total size of memory occupied by persistent parameters */
+const uint16_t csPersistentMemorySize = PERSISTENT_MEMORY_SIZE + SYSTEM_BASE_EEPROM_ADDRESS;
+
+/* eof csPersistentMem.c */