summaryrefslogtreecommitdiff
path: root/digital/beacon/src/Bitcloud_stack/Components/APS/include/private/apsBinding.h
blob: e89d02b039bd0ae90affa5a0aefd4fe62644de25 (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/**************************************************************************//**
  \file  apsBinding.h

  \brief Private interface of APS binding.

  \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:
    2010-10-05 Max Gekk - Created.
   Last change:
    $Id: apsBinding.h 17448 2011-06-09 13:53:59Z ataradov $
 ******************************************************************************/
#if !defined _APS_BINDING_H
#define _APS_BINDING_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <appFramework.h>
#include <aps.h>
#include <apsmeBind.h>
#include <apsMemoryManager.h>

#if defined _BINDING_
/******************************************************************************
                              Define(s) section
 ******************************************************************************/
#define ACTIVE_BINDING_ENTRY_STATUS APS_INVALID_BINDING_STATUS
#define ACTIVATE_BINDING_ENTRY(entry) \
  (entry)->confirm.status = ACTIVE_BINDING_ENTRY_STATUS

/******************************************************************************
                                Types section
 ******************************************************************************/
/** Size of the binding table. */
typedef uint8_t ApsBindingTableSize_t;
/** Type of a binding table index. */
typedef ApsBindingTableSize_t ApsBindIndex_t;

/** Type of the binding table. */
typedef struct _ApsBindingTable_t
{
  /* Total amount of binding entries. */
  ApsBindingTableSize_t  size;
  /* Array of binding entries. */
  ApsBindingEntry_t  *entry;
} ApsBindingTable_t;

/******************************************************************************
                              Prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief Reset the binding table and initialize it.

  \param[in] powerFailureControl - stack restoring after power failure control bitfield;
                                  affects on initialization procedure.
  \return None.
 ******************************************************************************/
APS_PRIVATE void apsResetBindingTable(const NWK_PowerFailureControl_t powerFailureControl);

/**************************************************************************//**
  \brief Allocate a place in the binding table for new entry.

  \param[in] req - pointer to request's parameters: source and destination
                   addresses, cluster identifier and etc. See APS_BindReq_t.
  \return Pointer to new binding entry or NULL.
 ******************************************************************************/
APS_PRIVATE ApsBindingEntry_t* apsAllocBindingEntry(APS_BindReq_t *const req);

/**************************************************************************//**
  \brief Free allocated binding entry.

  \param[in] entry - pointer to valid entry in the binding table.

  \return None.
 ******************************************************************************/
APS_PRIVATE void apsFreeBindingEntry(ApsBindingEntry_t *const entry);

/**************************************************************************//**
  \brief Get pointer to next binding entry.

  \code Example:
    ApsBindingEntry_t *entry = NULL;

    while (NULL != (entry = apsNextBind(entry, cluster, endpoint, addr)))
    {
      if (APS_GROUP_ADDRES == entry->dstAddrMode)
        if (dstGroup == entry->dst.group)
          // send message to group
      ...
    }
  \endcode

  \param[in] entry - pointer to previous binding entry
                     or NULL if it's initial call.
  \param[in] clusterId - cluster identifier of next bind link.
  \param[in] endpoint - endpoint number of next binding entry.
  \param[in] extAddr - pointer to source IEEE address of next entry.

  \return if next binding entry is found then return valid entry pointer
          otherwise return NULL.
 ******************************************************************************/
APS_PRIVATE ApsBindingEntry_t* apsNextBind(ApsBindingEntry_t *entry,
  const ClusterId_t clusterId, const Endpoint_t endpoint,
  const ExtAddr_t *const extAddr);

/**************************************************************************//**
  \brief Find entry by bind request in the binding table.

    This function initializes the status field to APS_SUCCESS_STATUS
   if entry is found otherwise it writes APS_INVALID_PAREMETER_STATUS.

  \param[in] req - bind or unbind request's parameters.
  \parap[in] errorStatus - return this status if an entry is not found.

  \return Pointer to an entry in the binding table or NULL.
 ******************************************************************************/
APS_PRIVATE ApsBindingEntry_t* apsFindBindingEntry(APS_BindReq_t *const req, 
  const APS_Status_t errorStatus);

/**************************************************************************//**
  \brief Is APS already bound or not?

    It always writes APS_SUCCESS_STATUS to the status field
   of APSME-BIND.confirm.

  \param[in] req - bind or unbind request's parameters.

  \return true is APS is not bound with given parameters otherwise false.
 ******************************************************************************/
APS_PRIVATE bool apsIsNotBound(APS_BindReq_t *const req);

/**************************************************************************//**
  \brief Copy binding information to the binding table.

  \param[in] entry - pointer to an entry in the binding table.
  \param[in] req - pointer to bind request's parameters.

  \return None.
 ******************************************************************************/
APS_PRIVATE void apsCopyBindingInfo(ApsBindingEntry_t *const entry,
  APS_BindReq_t *const req);

/**************************************************************************//**
  \brief Check binding to any group from given source endpoint.

  \param[in] clusterId - cluster identifier of group binding link
  \param[in] srcEndpoint - source endpoint of group binding link.

  \return true if group bind link is found otherwise return false.
 ******************************************************************************/
APS_PRIVATE bool apsIsBoundToAnyGroup(const ClusterId_t clusterId,
  const Endpoint_t srcEndpoint);

/**************************************************************************//**
  \brief Find bind link and try to send to bound devices.

  \param[in] apsDataReq - pointer to initial APSDE-DATA.request's parameters.
  \param[in] buffer - allocated buffer for internal transmission parameters.

  \return APS_SUCCESS_STATUS if transmission is successfully.
 ******************************************************************************/
APS_PRIVATE APS_Status_t apsProcessIndirectDataReq(APS_DataReq_t *const apsDataReq,
  ApsDataBuffer_t *const buffer);

/**************************************************************************//**
  \brief Find next bound device and try to send to it.

  \param[in] apsDataReq - pointer to initial APSDE-DATA.request's parameters.
  \param[in] buffer - allocated buffer for internal transmission parameters.

  \return APS_SUCCESS_STATUS if transmission is successfully.
 ******************************************************************************/
APS_PRIVATE APS_Status_t apsSendToNextBoundDevice(APS_DataReq_t *const apsDataReq,
  ApsDataBuffer_t *const buffer);

#endif /* _BINDING_ */
#endif /* _APS_BINDING_H */
/** eof apsBinding.h */