summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/NWK/include/private/nwkPacket.h
blob: f93f21ed6d4ffd0494e0c96b67d1e821f7329f49 (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
/**************************************************************************//**
  \file nwkPacket.h

  \brief Interface of the network packet manager.

  \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:
    2009-07-06 M. Gekk - Created.
   Last change:
    $Id: nwkPacket.h 17448 2011-06-09 13:53:59Z ataradov $
 ******************************************************************************/
#if !defined _NWK_PACKET_H
#define _NWK_PACKET_H

/******************************************************************************
                               Includes section
 ******************************************************************************/
#include <nwkConfig.h>
#include <queue.h>
#include <mac.h>
#include <nwkCommon.h>
#include <nwkRx.h>
#include <nwkTx.h>

/******************************************************************************
                                Types section
 ******************************************************************************/
/** Type of network packet. */
typedef enum _NwkPacketType_t
{
  NWK_UNKNOWN_PACKET = 0x0,
  /** Command packet from NWK component. */
  NWK_OUTPUT_COMMAND_PACKET = 0x1,
  /** Command packet from MAC-layer. */
  NWK_INPUT_COMMAND_PACKET = 0x2,
  /** Data packet from MAC-layer. */
  NWK_INPUT_DATA_PACKET = 0x3,
  /** Transit packet from MAC-layer. */
  NWK_TRANSIT_PACKET = 0x4,
  /** Loopback transmission from APS-layer. */
  NWK_LOOPBACK_PACKET = 0x5,
  /** Data packet from an external layer. */
  NWK_EXTERN_PACKET = 0x6,
  NWK_BUFFER_TYPE_LAST
} NwkPacketType_t;

/** Network packet type. */
typedef struct _NwkPacket_t
{
  /** Network packet type. */
  NwkPacketType_t type;
  TOP_GUARD
  uint8_t macHeader[MAC_MSDU_OFFSET];
  uint8_t macPayload[MAC_MAX_MSDU_SIZE];
#if (MAC_AFFIX_LENGTH - MAC_MSDU_OFFSET)
  uint8_t macFooter[MAC_AFFIX_LENGTH - MAC_MSDU_OFFSET];
#endif
  BOTTOM_GUARD
  union
  {
    /** Service information for incoming packet from MAC-layer. */
    NwkInputPacket_t in;
    /** Service information for outgoing packet from NWK-layer. */
    NwkOutputPacket_t out;
#if defined _NWK_ALLOCATOR_
    /** Service information for outgoing packet from an upper-layer. */
    NwkExternPacket_t ext;
#endif /* _NWK_ALLOCATOR_ */
  } pkt;
} NwkPacket_t;

/** Internal variables of the network packet manager. */
typedef struct _NwkPacketManager_t
{
  /** Array of network packets. */
  NwkPacket_t *pkt;
  /** Total amount of network packets. */
  uint8_t amount;
  /** Queue of external packet allocation requests. */
  QueueDescriptor_t queue;
} NwkPacketManager_t;

/******************************************************************************
                               Prototypes section
 ******************************************************************************/
/**************************************************************************//**
  \brief Allocate a free memory space for an input packet with type.

  \param[in] type - type of packet.
  \param[in] length - needed packet length.
  \return Pointer to input packet or NULL.
 ******************************************************************************/
NWK_PRIVATE NwkInputPacket_t* nwkAllocInputPacket(const NwkPacketType_t type, 
  const NwkLength_t length);

/**************************************************************************//**
  \brief Free an input packet.

  \param[in] inPkt - pointer to an input packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkFreeInputPacket(NwkInputPacket_t *const inPkt);

/**************************************************************************//**
  \brief Allocate a free memory space for an output.

  \param[in] type - type of output packet.
  \return Pointer to output packet or NULL.
 ******************************************************************************/
NWK_PRIVATE NwkOutputPacket_t* nwkAllocOutputPacket(const NwkPacketType_t type);

/**************************************************************************//**
  \brief Free an output packet.

  \param[in] outPkt - pointer to an output packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE void nwkFreeOutputPacket(NwkOutputPacket_t *const outPkt);

/**************************************************************************//**
  \brief Reset the network packet manager.
 ******************************************************************************/
NWK_PRIVATE void nwkResetPacketManager(void);

#if defined NWK_ROUTING_CAPACITY
/**************************************************************************//**
  \brief To transform an input packet to the output packet.

  \param[in] inPkt - pointer to an input packet.
  \return None.
 ******************************************************************************/
NWK_PRIVATE
NwkOutputPacket_t* nwkTransformInToOutPacket(NwkInputPacket_t *const inPkt);
#endif /* NWK_ROUTING_CAPACITY */

#if defined _NWK_ALLOCATOR_
/**************************************************************************//**
  \brief Process an incoming request to allocate memory for NWK_DataReq.
 ******************************************************************************/
NWK_PRIVATE void nwkAllocDataReqTaskHandler(void);

#else 
#define nwkAllocDataReqTaskHandler NULL
#endif /* _NWK_ALLOCATOR_ */
#endif /* _NWK_PACKET_H */
/** eof nwkPacket.h */