Contiki 2.5
convergence_layer.h
Go to the documentation of this file.
1 /**
2  * \addtogroup agent
3  * @{
4  */
5 
6 /**
7  * \defgroup cl IEEE 802.15.4 Convergence Layer
8  *
9  * @{
10  */
11 
12 /**
13  * \file
14  * \brief IEEE 802.15.4 Convergence Layer Implementation
15  * \author Georg von Zengen <vonzeng@ibr.cs.tu-bs.de>
16  * \author Wolf-Bastian Poettner <poettner@ibr.cs.tu-bs.de>
17  */
18 
19 #ifndef CONVERGENCE_LAYER_H
20 #define CONVERGENCE_LAYER_H
21 
22 #include "contiki.h"
23 #include "rimeaddr.h"
24 #include "process.h"
25 #include "mmem.h"
26 
27 /**
28  * How many outgoing bundles can we queue?
29  */
30 #define CONVERGENCE_LAYER_QUEUE 10
31 
32 /**
33  * How many queue slots remain free for internal use?
34  */
35 #define CONVERGENCE_LAYER_QUEUE_FREE (0.2 * CONVERGENCE_LAYER_QUEUE)
36 
37 /**
38  * How often shall we retransmit bundles before we notify routing
39  */
40 #define CONVERGENCE_LAYER_RETRIES 4
41 
42 /**
43  * How often shell we retry to transmit, if it has not been transmitted at all?
44  */
45 #define CONVERGENCE_LAYER_FAILED_RETRIES 15
46 
47 /**
48  * How long shall we wait for an app-layer ACK or NACK? [in seconds]
49  */
50 #define CONVERGENCE_LAYER_TIMEOUT 5
51 
52 /**
53  * How long shell we wait before retransmitting an app-layer ACK or NACK? [in seconds]
54  */
55 #define CONVERGENCE_LAYER_RETRANSMIT_TIMEOUT 0.5
56 
57 /**
58  * How often shall we retransmit?
59  */
60 #define CONVERGENCE_LAYER_RETRANSMIT_TRIES (CONVERGENCE_LAYER_TIMEOUT / CONVERGENCE_LAYER_RETRANSMIT_TIMEOUT)
61 
62 /**
63  * Bundle queue flags
64  */
65 #define CONVERGENCE_LAYER_QUEUE_ACTIVE 0x01
66 #define CONVERGENCE_LAYER_QUEUE_IN_TRANSIT 0x02
67 #define CONVERGENCE_LAYER_QUEUE_ACK_PEND 0x04
68 #define CONVERGENCE_LAYER_QUEUE_DONE 0x08
69 #define CONVERGENCE_LAYER_QUEUE_FAIL 0x10
70 #define CONVERGENCE_LAYER_QUEUE_ACK 0x20
71 #define CONVERGENCE_LAYER_QUEUE_NACK 0x40
72 
73 /**
74  * CL COMPAT VALUES
75  */
76 #define CONVERGENCE_LAYER_COMPAT 0x00
77 
78 /**
79  * CL Header Types
80  */
81 #define CONVERGENCE_LAYER_TYPE_DATA 0x10
82 #define CONVERGENCE_LAYER_TYPE_DISCOVERY 0x20
83 #define CONVERGENCE_LAYER_TYPE_ACK 0x30
84 #define CONVERGENCE_LAYER_TYPE_NACK 0x00
85 
86 /**
87  * CL Packet Flags
88  */
89 #define CONVERGENCE_LAYER_FLAGS_FIRST 0x02
90 #define CONVERGENCE_LAYER_FLAGS_LAST 0x01
91 
92 /**
93  * CL Field Masks
94  */
95 #define CONVERGENCE_LAYER_MASK_COMPAT 0xC0
96 #define CONVERGENCE_LAYER_MASK_TYPE 0x30
97 #define CONVERGENCE_LAYER_MASK_SEQNO 0x0C
98 #define CONVERGENCE_LAYER_MASK_FLAGS 0x03
99 
100 /**
101  * CL Callback Status
102  */
103 #define CONVERGENCE_LAYER_STATUS_OK 0x01
104 #define CONVERGENCE_LAYER_STATUS_NOACK 0x02
105 #define CONVERGENCE_LAYER_STATUS_NOSEND 0x04
106 #define CONVERGENCE_LAYER_STATUS_FATAL 0x08
107 
108 /**
109  * CL Priority Values
110  */
111 #define CONVERGENCE_LAYER_PRIORITY_NORMAL 0x01
112 #define CONVERGENCE_LAYER_PRIORITY_HIGH 0x02
113 
114 #define CONVERGENCE_LAYER_VALID_FLAG 0x7a03ab12UL
115 
116 /**
117  * Maximum payload length of one outgoing frame
118  */
119 #define CONVERGENCE_LAYER_MAX_LENGTH 115
120 
121 /**
122  * Convergence Layer Process
123  */
124 PROCESS_NAME(convergence_layer_process);
125 
126 /**
127  * Bundle Queue Entry
128  */
130  struct transmit_ticket_t * next;
131 
132  uint8_t flags;
133  uint8_t tries;
134  uint8_t failed_tries;
135  rimeaddr_t neighbour;
136  uint32_t bundle_number;
137  uint8_t sequence_number;
138  clock_time_t timestamp;
139 
140  struct mmem * bundle;
141 };
142 
143 int convergence_layer_init(void);
144 
145 struct transmit_ticket_t * convergence_layer_get_transmit_ticket(void);
146 int convergence_layer_free_transmit_ticket(struct transmit_ticket_t * ticket);
147 
148 int convergence_layer_enqueue_bundle(struct transmit_ticket_t * ticket);
149 int convergence_layer_send_discovery(uint8_t * payload, uint8_t length, rimeaddr_t * neighbour);
150 
151 int convergence_layer_incoming_frame(rimeaddr_t * source, uint8_t * payload, uint8_t length, packetbuf_attr_t rssi);
152 int convergence_layer_status(void * pointer, uint8_t status);
153 
154 int convergence_layer_delete_bundle(uint32_t bundle_number);
155 
156 int convergence_layer_neighbour_down(rimeaddr_t * neighbour);
157 
158 #endif /* CONVERGENCE_LAYER */
159 
160 /** @} */
161 /** @} */