summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/ZCL/include/zclZllIB.h
blob: f3904c0e60a23d088a0a2677d1608f02bda9f291 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**************************************************************************//**
  \file zclZllIB.h

  \brief
    ZLL Information Base interface.

  \author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

  \internal
    History:
    18.03.10 A. Taradov - Created.
******************************************************************************/
#ifndef _ZCLZLLIB_H
#define	_ZCLZLLIB_H

/******************************************************************************
                    Includes section
******************************************************************************/
#include <types.h>
#include <aps.h>
#include <zclZllFrameFormat.h>
#include <zclZllIB.h>

/******************************************************************************
                        Definitions section
******************************************************************************/

/******************************************************************************
                    Types section
******************************************************************************/

// Device Information Table entry
typedef struct _DitEntry_t
{
  uint64_t ieee;
  uint8_t  ep;
  uint16_t profileId;
  uint16_t deviceId;
  uint8_t  version;
  uint8_t  groupIds;
  uint8_t  sort;
} ZCL_ZllDitEntry_t;

typedef struct _ZCL_ZllDevice_t
{
  uint8_t     factoryNew;
  uint8_t     channel;
  PanId_t     panId;
  ExtPanId_t  extPanId;
  ShortAddr_t nwkAddr;
  ExtAddr_t   extAddr;
  ShortAddr_t freeNwkAddressRangeBegin;
  ShortAddr_t freeNwkAddressRangeEnd;
  uint16_t    freeGroupIdRangeBegin;
  uint16_t    freeGroupIdRangeEnd;
  uint16_t    groupIdsBegin;
  uint16_t    groupIdsEnd;
  uint8_t     nwkKey[SECURITY_KEY_SIZE];
} ZCL_ZllDevice_t;

typedef struct _ZCL_ZllIb_t
{
  ZCL_ZllDevice_t     device;
  ZclZllZigBeeInfo_t  zigBeeInfo;
  ZclZllInfo_t        zllInfo;
  ZCL_ZllDitEntry_t   *dit;
  uint8_t             ditSize;
  uint8_t             numberSubDevices;
  uint8_t             totalGroupIds;
  MAC_CapabilityInf_t capabilityInf;
  uint8_t             *appData;
  uint16_t            appDataSize;
} ZCL_ZllIb_t;

/******************************************************************************
                        Global variables
******************************************************************************/
extern ZCL_ZllIb_t zclZllIB;

/******************************************************************************
                        Prototypes section
******************************************************************************/

/**************************************************************************//**
\brief Initialize Information Base and restore ZLL parameters and
application data

This function is invoked by the ZCL_ZllReset() function and therefore should
not be called by the user directly.

The function restores ZLL parameters and application data from EEPROM and sets
the restored network and stack parameters in Configuration Server as well.
******************************************************************************/
void ZCL_ZllIbReset(void);

/**************************************************************************//**
\brief Set application data that should be saved and restored

This function specifies the memory which is used to store and restore 
application data. The data will be saved in EEPROM when the ZCL_ZllIbSave() 
function is called, and restored when ZCL_ZllIbReset() or ZCL_ZllReset() 
functions are called (ZCL_ZllReset() invokes ZCL_ZllIbReset()).

This function should be called before ZCL_ZllIbReset() or ZCL_ZllReset() to
specify the memory to which application data will be restored.

Application data may be any abstract data. However, keeping network and
stack parameters in application data is unnecunnecessary, because they are
maintained by ZLL.

\param[in] data - application data
\param[in] button - button number
******************************************************************************/
void ZCL_ZllIbSetAppData(uint8_t *data, uint16_t size);

/**************************************************************************//**
\brief Save ZLL parameters and application data in EEPROM

The functions saves ZLL parameters and application data in EEPROM so that
they can be restored after device is reset. ZLL parameters are stored inside
the stack in the instance of the ZCL_ZllDevice_t type. This function should
be called each time after the application data is modofied.
******************************************************************************/
void ZCL_ZllIbSave(void);

/**************************************************************************//**
\brief Reset ZLL parameters to factory new settings and store them into EEPROM
******************************************************************************/
void ZCL_ZllIbResetToFactoryNew(void);

/**************************************************************************//**
\brief Set Device Information Table

Device Information Table contains entries desribing logical device type 
implemented on the device. However, most frequently the table has only one entry.
Since the table stores static information about application functionality, it is
not writtern into EEPROM, but is typically configured each time the application
starts.

The following example shows how to fill a table with a single entry:

\code
\\Global definition of the Device Information table
ZCL_ZllDitEntry_t deviceInfoTable[DEVICE_INFO_TABLE_ENTRIES];
...
CS_ReadParameter(CS_UID_ID, &deviceInfoTable[0].ieee); //Read extended address from the Configuration Server
deviceInfoTable[0].ep        = APP_ENDPOINT_COLOR_SCENE_REMOTE;
deviceInfoTable[0].profileId = APP_PROFILE_ID;
deviceInfoTable[0].deviceId  = APP_DEVICE_ID;
deviceInfoTable[0].version   = APP_VERSION;
deviceInfoTable[0].groupIds  = APP_GROUP_IDS; //The number of group IDs
deviceInfoTable[0].sort      = 0;
ZCL_ZllIbSetDeviceInfoTable(deviceInfoTable, 1);
\endcode

Note that all constants starting with APP_ should be defined by the
application.

\param[in] dit - pointer to the Device Information table
\param[in] size - number of entries in the table
******************************************************************************/
void ZCL_ZllIbSetDeviceInfoTable(ZCL_ZllDitEntry_t dit[], uint8_t size);

#endif // _ZCLZLLIB_H

// eof zclZllIB.h