pygments.rb 0.5.2 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lexers +0 -0
- data/lib/pygments/version.rb +1 -1
- data/test/test_pygments.rb +1 -1
- data/vendor/custom_lexers/github.py +15 -9
- data/vendor/pygments-main/AUTHORS +12 -2
- data/vendor/pygments-main/CHANGES +52 -2
- data/vendor/pygments-main/REVISION +1 -1
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +52 -0
- data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +67 -44
- data/vendor/pygments-main/pygmentize +1 -1
- data/vendor/pygments-main/pygments/filters/__init__.py +2 -2
- data/vendor/pygments-main/pygments/formatter.py +3 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +11 -0
- data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +2880 -3124
- data/vendor/pygments-main/pygments/lexers/_mapping.py +30 -20
- data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +1 -1
- data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +206 -20
- data/vendor/pygments-main/pygments/lexers/agile.py +378 -5
- data/vendor/pygments-main/pygments/lexers/asm.py +2 -2
- data/vendor/pygments-main/pygments/lexers/compiled.py +235 -8
- data/vendor/pygments-main/pygments/lexers/dotnet.py +88 -47
- data/vendor/pygments-main/pygments/lexers/functional.py +195 -62
- data/vendor/pygments-main/pygments/lexers/github.py +15 -9
- data/vendor/pygments-main/pygments/lexers/jvm.py +14 -11
- data/vendor/pygments-main/pygments/lexers/math.py +284 -18
- data/vendor/pygments-main/pygments/lexers/other.py +132 -21
- data/vendor/pygments-main/pygments/lexers/shell.py +29 -15
- data/vendor/pygments-main/pygments/lexers/sql.py +1 -1
- data/vendor/pygments-main/pygments/lexers/templates.py +8 -8
- data/vendor/pygments-main/pygments/lexers/text.py +59 -9
- data/vendor/pygments-main/pygments/lexers/web.py +832 -210
- data/vendor/pygments-main/pygments/modeline.py +40 -0
- data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
- data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
- data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
- data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
- data/vendor/pygments-main/tests/examplefiles/example.ceylon +29 -10
- data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
- data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
- data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
- data/vendor/pygments-main/tests/examplefiles/example.stan +86 -75
- data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +40 -30
- data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +7 -0
- data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
- data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
- data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
- data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
- data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
- data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
- data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +16 -0
- data/vendor/pygments-main/tests/test_basic_api.py +3 -3
- data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
- metadata +21 -2
@@ -0,0 +1,66 @@
|
|
1
|
+
|
2
|
+
function Get-CommandDefinitionHtml {
|
3
|
+
|
4
|
+
# this tells powershell to allow advanced features,
|
5
|
+
# like the [validatenotnullorempty()] attribute below.
|
6
|
+
[CmdletBinding()]
|
7
|
+
param(
|
8
|
+
[ValidateNotNullOrEmpty()]
|
9
|
+
[string]$name
|
10
|
+
)
|
11
|
+
|
12
|
+
$command = get-command $name
|
13
|
+
|
14
|
+
# Look mom! I'm a cmdlet!
|
15
|
+
$PSCmdlet.WriteVerbose("Dumping HTML for " + $command)
|
16
|
+
|
17
|
+
@"
|
18
|
+
<html>
|
19
|
+
<head>
|
20
|
+
<title>$($command.name)</title>
|
21
|
+
</head>
|
22
|
+
<body>
|
23
|
+
<table border="1">
|
24
|
+
$(
|
25
|
+
$command.parametersets | % {
|
26
|
+
@"
|
27
|
+
|
28
|
+
<tr>
|
29
|
+
<td>$($_.name)</td>
|
30
|
+
<td>
|
31
|
+
<table border="1">
|
32
|
+
<tr>
|
33
|
+
<th colspan="8">Parameters</th>
|
34
|
+
|
35
|
+
$(
|
36
|
+
$count = 0
|
37
|
+
$_.parameters | % {
|
38
|
+
if (0 -eq ($count % 8)) {
|
39
|
+
@'
|
40
|
+
</tr>
|
41
|
+
<tr>
|
42
|
+
'@
|
43
|
+
}
|
44
|
+
@"
|
45
|
+
<td>$($_.name)</td>
|
46
|
+
"@
|
47
|
+
$count++
|
48
|
+
}
|
49
|
+
)
|
50
|
+
</tr>
|
51
|
+
</table>
|
52
|
+
</td>
|
53
|
+
</tr>
|
54
|
+
"@
|
55
|
+
}
|
56
|
+
)
|
57
|
+
</table>
|
58
|
+
</body>
|
59
|
+
</html>
|
60
|
+
"@
|
61
|
+
}
|
62
|
+
|
63
|
+
Get-CommandDefinitionHtml get-item > out.html
|
64
|
+
|
65
|
+
# show in browser
|
66
|
+
invoke-item out.html
|
@@ -0,0 +1,104 @@
|
|
1
|
+
/*
|
2
|
+
* "Copyright (c) 2008-2011 The Regents of the University of California.
|
3
|
+
* All rights reserved."
|
4
|
+
*
|
5
|
+
* Permission to use, copy, modify, and distribute this software and its
|
6
|
+
* documentation for any purpose, without fee, and without written agreement is
|
7
|
+
* hereby granted, provided that the above copyright notice, the following
|
8
|
+
* two paragraphs and the author appear in all copies of this software.
|
9
|
+
*
|
10
|
+
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
11
|
+
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
12
|
+
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
13
|
+
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
*
|
15
|
+
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
16
|
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
17
|
+
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
18
|
+
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
19
|
+
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
|
20
|
+
*
|
21
|
+
*/
|
22
|
+
|
23
|
+
/**
|
24
|
+
*
|
25
|
+
*
|
26
|
+
*/
|
27
|
+
#include "IPDispatch.h"
|
28
|
+
#include "BlipStatistics.h"
|
29
|
+
|
30
|
+
configuration IPDispatchC {
|
31
|
+
provides {
|
32
|
+
interface SplitControl;
|
33
|
+
interface IPLower;
|
34
|
+
interface BlipStatistics<ip_statistics_t>;
|
35
|
+
}
|
36
|
+
} implementation {
|
37
|
+
|
38
|
+
components MainC;
|
39
|
+
components NoLedsC as LedsC;
|
40
|
+
|
41
|
+
/* IPDispatchP wiring -- fragment rassembly and lib6lowpan bindings */
|
42
|
+
components IPDispatchP;
|
43
|
+
components CC2420RadioC as MessageC;
|
44
|
+
components ReadLqiC;
|
45
|
+
components new TimerMilliC();
|
46
|
+
|
47
|
+
SplitControl = IPDispatchP.SplitControl;
|
48
|
+
IPLower = IPDispatchP;
|
49
|
+
BlipStatistics = IPDispatchP;
|
50
|
+
|
51
|
+
IPDispatchP.Boot -> MainC;
|
52
|
+
/* #else */
|
53
|
+
/* components ResourceSendP; */
|
54
|
+
/* ResourceSendP.SubSend -> MessageC; */
|
55
|
+
/* ResourceSendP.Resource -> MessageC.SendResource[unique("RADIO_SEND_RESOURCE")]; */
|
56
|
+
/* IPDispatchP.Ieee154Send -> ResourceSendP.Ieee154Send; */
|
57
|
+
/* #endif */
|
58
|
+
IPDispatchP.RadioControl -> MessageC;
|
59
|
+
|
60
|
+
IPDispatchP.BarePacket -> MessageC.BarePacket;
|
61
|
+
IPDispatchP.Ieee154Send -> MessageC.BareSend;
|
62
|
+
IPDispatchP.Ieee154Receive -> MessageC.BareReceive;
|
63
|
+
|
64
|
+
#ifdef LOW_POWER_LISTENING
|
65
|
+
IPDispatchP.LowPowerListening -> MessageC;
|
66
|
+
#endif
|
67
|
+
MainC.SoftwareInit -> IPDispatchP.Init;
|
68
|
+
|
69
|
+
IPDispatchP.PacketLink -> MessageC;
|
70
|
+
IPDispatchP.ReadLqi -> ReadLqiC;
|
71
|
+
IPDispatchP.Leds -> LedsC;
|
72
|
+
IPDispatchP.ExpireTimer -> TimerMilliC;
|
73
|
+
|
74
|
+
components new PoolC(message_t, N_FRAGMENTS) as FragPool;
|
75
|
+
components new PoolC(struct send_entry, N_FRAGMENTS) as SendEntryPool;
|
76
|
+
components new QueueC(struct send_entry *, N_FRAGMENTS);
|
77
|
+
components new PoolC(struct send_info, N_CONCURRENT_SENDS) as SendInfoPool;
|
78
|
+
|
79
|
+
IPDispatchP.FragPool -> FragPool;
|
80
|
+
IPDispatchP.SendEntryPool -> SendEntryPool;
|
81
|
+
IPDispatchP.SendInfoPool -> SendInfoPool;
|
82
|
+
IPDispatchP.SendQueue -> QueueC;
|
83
|
+
|
84
|
+
components IPNeighborDiscoveryP;
|
85
|
+
IPDispatchP.NeighborDiscovery -> IPNeighborDiscoveryP;
|
86
|
+
|
87
|
+
/* components ICMPResponderC; */
|
88
|
+
/* #ifdef BLIP_MULTICAST */
|
89
|
+
/* components MulticastP; */
|
90
|
+
/* components new TrickleTimerMilliC(2, 30, 2, 1); */
|
91
|
+
/* IP = MulticastP.IP; */
|
92
|
+
|
93
|
+
/* MainC.SoftwareInit -> MulticastP.Init; */
|
94
|
+
/* MulticastP.MulticastRx -> IPDispatchP.Multicast; */
|
95
|
+
/* MulticastP.HopHeader -> IPExtensionP.HopByHopExt[0]; */
|
96
|
+
/* MulticastP.TrickleTimer -> TrickleTimerMilliC.TrickleTimer[0]; */
|
97
|
+
/* MulticastP.IPExtensions -> IPDispatchP; */
|
98
|
+
/* #endif */
|
99
|
+
|
100
|
+
#ifdef DELUGE
|
101
|
+
components NWProgC;
|
102
|
+
#endif
|
103
|
+
|
104
|
+
}
|
@@ -0,0 +1,671 @@
|
|
1
|
+
/*
|
2
|
+
* "Copyright (c) 2008 The Regents of the University of California.
|
3
|
+
* All rights reserved."
|
4
|
+
*
|
5
|
+
* Permission to use, copy, modify, and distribute this software and its
|
6
|
+
* documentation for any purpose, without fee, and without written agreement is
|
7
|
+
* hereby granted, provided that the above copyright notice, the following
|
8
|
+
* two paragraphs and the author appear in all copies of this software.
|
9
|
+
*
|
10
|
+
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
11
|
+
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
12
|
+
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
13
|
+
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
14
|
+
*
|
15
|
+
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
16
|
+
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
17
|
+
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
18
|
+
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
19
|
+
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
|
20
|
+
*
|
21
|
+
*/
|
22
|
+
|
23
|
+
#include <lib6lowpan/blip-tinyos-includes.h>
|
24
|
+
#include <lib6lowpan/6lowpan.h>
|
25
|
+
#include <lib6lowpan/lib6lowpan.h>
|
26
|
+
#include <lib6lowpan/ip.h>
|
27
|
+
#include <lib6lowpan/in_cksum.h>
|
28
|
+
#include <lib6lowpan/ip_malloc.h>
|
29
|
+
|
30
|
+
#include "blip_printf.h"
|
31
|
+
#include "IPDispatch.h"
|
32
|
+
#include "BlipStatistics.h"
|
33
|
+
#include "table.h"
|
34
|
+
|
35
|
+
/*
|
36
|
+
* Provides IP layer reception to applications on motes.
|
37
|
+
*
|
38
|
+
* @author Stephen Dawson-Haggerty <stevedh@cs.berkeley.edu>
|
39
|
+
*/
|
40
|
+
|
41
|
+
module IPDispatchP {
|
42
|
+
provides {
|
43
|
+
interface SplitControl;
|
44
|
+
// interface for protocols not requiring special hand-holding
|
45
|
+
interface IPLower;
|
46
|
+
|
47
|
+
interface BlipStatistics<ip_statistics_t>;
|
48
|
+
|
49
|
+
}
|
50
|
+
uses {
|
51
|
+
interface Boot;
|
52
|
+
|
53
|
+
|
54
|
+
/* link-layer wiring */
|
55
|
+
interface SplitControl as RadioControl;
|
56
|
+
|
57
|
+
interface Packet as BarePacket;
|
58
|
+
interface Send as Ieee154Send;
|
59
|
+
interface Receive as Ieee154Receive;
|
60
|
+
|
61
|
+
/* context lookup */
|
62
|
+
interface NeighborDiscovery;
|
63
|
+
|
64
|
+
interface ReadLqi;
|
65
|
+
interface PacketLink;
|
66
|
+
interface LowPowerListening;
|
67
|
+
|
68
|
+
/* buffers for outgoing fragments */
|
69
|
+
interface Pool<message_t> as FragPool;
|
70
|
+
interface Pool<struct send_info> as SendInfoPool;
|
71
|
+
interface Pool<struct send_entry> as SendEntryPool;
|
72
|
+
interface Queue<struct send_entry *> as SendQueue;
|
73
|
+
|
74
|
+
/* expire reconstruction */
|
75
|
+
interface Timer<TMilli> as ExpireTimer;
|
76
|
+
|
77
|
+
interface Leds;
|
78
|
+
|
79
|
+
}
|
80
|
+
provides interface Init;
|
81
|
+
} implementation {
|
82
|
+
|
83
|
+
#define HAVE_LOWPAN_EXTERN_MATCH_CONTEXT
|
84
|
+
int lowpan_extern_read_context(struct in6_addr *addr, int context) {
|
85
|
+
return call NeighborDiscovery.getContext(context, addr);
|
86
|
+
}
|
87
|
+
|
88
|
+
int lowpan_extern_match_context(struct in6_addr *addr, uint8_t *ctx_id) {
|
89
|
+
return call NeighborDiscovery.matchContext(addr, ctx_id);
|
90
|
+
}
|
91
|
+
|
92
|
+
// generally including source files like this is a no-no. I'm doing
|
93
|
+
// this in the hope that the optimizer will do a better job when
|
94
|
+
// they're part of a component.
|
95
|
+
#include <lib6lowpan/ieee154_header.c>
|
96
|
+
#include <lib6lowpan/lib6lowpan.c>
|
97
|
+
#include <lib6lowpan/lib6lowpan_4944.c>
|
98
|
+
#include <lib6lowpan/lib6lowpan_frag.c>
|
99
|
+
|
100
|
+
enum {
|
101
|
+
S_RUNNING,
|
102
|
+
S_STOPPED,
|
103
|
+
S_STOPPING,
|
104
|
+
};
|
105
|
+
uint8_t state = S_STOPPED;
|
106
|
+
bool radioBusy;
|
107
|
+
uint8_t current_local_label = 0;
|
108
|
+
ip_statistics_t stats;
|
109
|
+
|
110
|
+
// this in theory could be arbitrarily large; however, it needs to
|
111
|
+
// be large enough to hold all active reconstructions, and any tags
|
112
|
+
// which we are dropping. It's important to keep dropped tags
|
113
|
+
// around for a while, or else there are pathological situations
|
114
|
+
// where you continually allocate buffers for packets which will
|
115
|
+
// never complete.
|
116
|
+
|
117
|
+
////////////////////////////////////////
|
118
|
+
//
|
119
|
+
//
|
120
|
+
|
121
|
+
table_t recon_cache;
|
122
|
+
|
123
|
+
// table of packets we are currently receiving fragments from, that
|
124
|
+
// are destined to us
|
125
|
+
struct lowpan_reconstruct recon_data[N_RECONSTRUCTIONS];
|
126
|
+
|
127
|
+
//
|
128
|
+
//
|
129
|
+
////////////////////////////////////////
|
130
|
+
|
131
|
+
// task void sendTask();
|
132
|
+
|
133
|
+
void reconstruct_clear(void *ent) {
|
134
|
+
struct lowpan_reconstruct *recon = (struct lowpan_reconstruct *)ent;
|
135
|
+
memclr((uint8_t *)&recon->r_meta, sizeof(struct ip6_metadata));
|
136
|
+
recon->r_timeout = T_UNUSED;
|
137
|
+
recon->r_buf = NULL;
|
138
|
+
}
|
139
|
+
|
140
|
+
struct send_info *getSendInfo() {
|
141
|
+
struct send_info *ret = call SendInfoPool.get();
|
142
|
+
if (ret == NULL) return ret;
|
143
|
+
ret->_refcount = 1;
|
144
|
+
ret->upper_data = NULL;
|
145
|
+
ret->failed = FALSE;
|
146
|
+
ret->link_transmissions = 0;
|
147
|
+
ret->link_fragments = 0;
|
148
|
+
ret->link_fragment_attempts = 0;
|
149
|
+
return ret;
|
150
|
+
}
|
151
|
+
#define SENDINFO_INCR(X) ((X)->_refcount)++
|
152
|
+
void SENDINFO_DECR(struct send_info *si) {
|
153
|
+
if (--(si->_refcount) == 0) {
|
154
|
+
call SendInfoPool.put(si);
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
command error_t SplitControl.start() {
|
159
|
+
return call RadioControl.start();
|
160
|
+
}
|
161
|
+
|
162
|
+
command error_t SplitControl.stop() {
|
163
|
+
if (!radioBusy) {
|
164
|
+
state = S_STOPPED;
|
165
|
+
return call RadioControl.stop();
|
166
|
+
} else {
|
167
|
+
// if there's a packet in the radio, wait for it to exit before
|
168
|
+
// stopping
|
169
|
+
state = S_STOPPING;
|
170
|
+
return SUCCESS;
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
event void RadioControl.startDone(error_t error) {
|
175
|
+
#ifdef LPL_SLEEP_INTERVAL
|
176
|
+
call LowPowerListening.setLocalWakeupInterval(LPL_SLEEP_INTERVAL);
|
177
|
+
#endif
|
178
|
+
|
179
|
+
if (error == SUCCESS) {
|
180
|
+
call Leds.led2Toggle();
|
181
|
+
call ExpireTimer.startPeriodic(FRAG_EXPIRE_TIME);
|
182
|
+
state = S_RUNNING;
|
183
|
+
radioBusy = FALSE;
|
184
|
+
}
|
185
|
+
|
186
|
+
signal SplitControl.startDone(error);
|
187
|
+
}
|
188
|
+
|
189
|
+
event void RadioControl.stopDone(error_t error) {
|
190
|
+
signal SplitControl.stopDone(error);
|
191
|
+
}
|
192
|
+
|
193
|
+
command error_t Init.init() {
|
194
|
+
// ip_malloc_init needs to be in init, not booted, because
|
195
|
+
// context for coap is initialised in init
|
196
|
+
ip_malloc_init();
|
197
|
+
return SUCCESS;
|
198
|
+
}
|
199
|
+
|
200
|
+
event void Boot.booted() {
|
201
|
+
call BlipStatistics.clear();
|
202
|
+
|
203
|
+
/* set up our reconstruction cache */
|
204
|
+
table_init(&recon_cache, recon_data, sizeof(struct lowpan_reconstruct), N_RECONSTRUCTIONS);
|
205
|
+
table_map(&recon_cache, reconstruct_clear);
|
206
|
+
|
207
|
+
call SplitControl.start();
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* Receive-side code.
|
212
|
+
*/
|
213
|
+
void deliver(struct lowpan_reconstruct *recon) {
|
214
|
+
struct ip6_hdr *iph = (struct ip6_hdr *)recon->r_buf;
|
215
|
+
|
216
|
+
// printf("deliver [%i]: ", recon->r_bytes_rcvd);
|
217
|
+
// printf_buf(recon->r_buf, recon->r_bytes_rcvd);
|
218
|
+
|
219
|
+
/* the payload length field is always compressed, have to put it back here */
|
220
|
+
iph->ip6_plen = htons(recon->r_bytes_rcvd - sizeof(struct ip6_hdr));
|
221
|
+
signal IPLower.recv(iph, (void *)(iph + 1), &recon->r_meta);
|
222
|
+
|
223
|
+
// printf("ip_free(%p)\n", recon->r_buf);
|
224
|
+
ip_free(recon->r_buf);
|
225
|
+
recon->r_timeout = T_UNUSED;
|
226
|
+
recon->r_buf = NULL;
|
227
|
+
}
|
228
|
+
|
229
|
+
/*
|
230
|
+
* Bulletproof recovery logic is very important to make sure we
|
231
|
+
* don't get wedged with no free buffers.
|
232
|
+
*
|
233
|
+
* The table is managed as follows:
|
234
|
+
* - unused entries are marked T_UNUSED
|
235
|
+
* - entries which
|
236
|
+
* o have a buffer allocated
|
237
|
+
* o have had a fragment reception before we fired
|
238
|
+
* are marked T_ACTIVE
|
239
|
+
* - entries which have not had a fragment reception during the last timer period
|
240
|
+
* and were active are marked T_ZOMBIE
|
241
|
+
* - zombie receptions are deleted: their buffer is freed and table entry marked unused.
|
242
|
+
* - when a fragment is dropped, it is entered into the table as T_FAILED1.
|
243
|
+
* no buffer is allocated
|
244
|
+
* - when the timer fires, T_FAILED1 entries are aged to T_FAILED2.
|
245
|
+
* - T_FAILED2 entries are deleted. Incomming fragments with tags
|
246
|
+
* that are marked either FAILED1 or FAILED2 are dropped; this
|
247
|
+
* prevents us from allocating a buffer for a packet which we
|
248
|
+
* have already dropped fragments from.
|
249
|
+
*
|
250
|
+
*/
|
251
|
+
void reconstruct_age(void *elt) {
|
252
|
+
struct lowpan_reconstruct *recon = (struct lowpan_reconstruct *)elt;
|
253
|
+
if (recon->r_timeout != T_UNUSED)
|
254
|
+
printf("recon src: 0x%x tag: 0x%x buf: %p recvd: %i/%i\n",
|
255
|
+
recon->r_source_key, recon->r_tag, recon->r_buf,
|
256
|
+
recon->r_bytes_rcvd, recon->r_size);
|
257
|
+
switch (recon->r_timeout) {
|
258
|
+
case T_ACTIVE:
|
259
|
+
recon->r_timeout = T_ZOMBIE; break; // age existing receptions
|
260
|
+
case T_FAILED1:
|
261
|
+
recon->r_timeout = T_FAILED2; break; // age existing receptions
|
262
|
+
case T_ZOMBIE:
|
263
|
+
case T_FAILED2:
|
264
|
+
// deallocate the space for reconstruction
|
265
|
+
printf("timing out buffer: src: %i tag: %i\n", recon->r_source_key, recon->r_tag);
|
266
|
+
if (recon->r_buf != NULL) {
|
267
|
+
printf("ip_free(%p)\n", recon->r_buf);
|
268
|
+
ip_free(recon->r_buf);
|
269
|
+
}
|
270
|
+
recon->r_timeout = T_UNUSED;
|
271
|
+
recon->r_buf = NULL;
|
272
|
+
break;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
|
276
|
+
void ip_print_heap() {
|
277
|
+
#ifdef PRINTFUART_ENABLED
|
278
|
+
bndrt_t *cur = (bndrt_t *)heap;
|
279
|
+
while (((uint8_t *)cur) - heap < IP_MALLOC_HEAP_SIZE) {
|
280
|
+
printf ("heap region start: %p length: %u used: %u\n",
|
281
|
+
cur, (*cur & IP_MALLOC_LEN), (*cur & IP_MALLOC_INUSE) >> 15);
|
282
|
+
cur = (bndrt_t *)(((uint8_t *)cur) + ((*cur) & IP_MALLOC_LEN));
|
283
|
+
}
|
284
|
+
#endif
|
285
|
+
}
|
286
|
+
|
287
|
+
event void ExpireTimer.fired() {
|
288
|
+
table_map(&recon_cache, reconstruct_age);
|
289
|
+
|
290
|
+
|
291
|
+
printf("Frag pool size: %i\n", call FragPool.size());
|
292
|
+
printf("SendInfo pool size: %i\n", call SendInfoPool.size());
|
293
|
+
printf("SendEntry pool size: %i\n", call SendEntryPool.size());
|
294
|
+
printf("Forward queue length: %i\n", call SendQueue.size());
|
295
|
+
ip_print_heap();
|
296
|
+
printfflush();
|
297
|
+
}
|
298
|
+
|
299
|
+
/*
|
300
|
+
* allocate a structure for recording information about incomming fragments.
|
301
|
+
*/
|
302
|
+
|
303
|
+
struct lowpan_reconstruct *get_reconstruct(uint16_t key, uint16_t tag) {
|
304
|
+
struct lowpan_reconstruct *ret = NULL;
|
305
|
+
int i;
|
306
|
+
|
307
|
+
// printf("get_reconstruct: %x %i\n", key, tag);
|
308
|
+
|
309
|
+
for (i = 0; i < N_RECONSTRUCTIONS; i++) {
|
310
|
+
struct lowpan_reconstruct *recon = (struct lowpan_reconstruct *)&recon_data[i];
|
311
|
+
|
312
|
+
if (recon->r_tag == tag &&
|
313
|
+
recon->r_source_key == key) {
|
314
|
+
|
315
|
+
if (recon->r_timeout > T_UNUSED) {
|
316
|
+
recon->r_timeout = T_ACTIVE;
|
317
|
+
ret = recon;
|
318
|
+
goto done;
|
319
|
+
|
320
|
+
} else if (recon->r_timeout < T_UNUSED) {
|
321
|
+
// if we have already tried and failed to get a buffer, we
|
322
|
+
// need to drop remaining fragments.
|
323
|
+
ret = NULL;
|
324
|
+
goto done;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
if (recon->r_timeout == T_UNUSED)
|
328
|
+
ret = recon;
|
329
|
+
}
|
330
|
+
done:
|
331
|
+
// printf("got%p\n", ret);
|
332
|
+
return ret;
|
333
|
+
}
|
334
|
+
|
335
|
+
event message_t *Ieee154Receive.receive(message_t *msg, void *msg_payload, uint8_t len) {
|
336
|
+
struct packed_lowmsg lowmsg;
|
337
|
+
struct ieee154_frame_addr frame_address;
|
338
|
+
uint8_t *buf = msg_payload;
|
339
|
+
|
340
|
+
// printf(" -- RECEIVE -- len : %i\n", len);
|
341
|
+
|
342
|
+
BLIP_STATS_INCR(stats.rx_total);
|
343
|
+
|
344
|
+
/* unpack the 802.15.4 address fields */
|
345
|
+
buf = unpack_ieee154_hdr(msg_payload, &frame_address);
|
346
|
+
len -= buf - (uint8_t *)msg_payload;
|
347
|
+
|
348
|
+
/* unpack and 6lowpan headers */
|
349
|
+
lowmsg.data = buf;
|
350
|
+
lowmsg.len = len;
|
351
|
+
lowmsg.headers = getHeaderBitmap(&lowmsg);
|
352
|
+
if (lowmsg.headers == LOWMSG_NALP) {
|
353
|
+
goto fail;
|
354
|
+
}
|
355
|
+
|
356
|
+
if (hasFrag1Header(&lowmsg) || hasFragNHeader(&lowmsg)) {
|
357
|
+
// start reassembly
|
358
|
+
int rv;
|
359
|
+
struct lowpan_reconstruct *recon;
|
360
|
+
uint16_t tag, source_key;
|
361
|
+
|
362
|
+
source_key = ieee154_hashaddr(&frame_address.ieee_src);
|
363
|
+
getFragDgramTag(&lowmsg, &tag);
|
364
|
+
recon = get_reconstruct(source_key, tag);
|
365
|
+
if (!recon) {
|
366
|
+
goto fail;
|
367
|
+
}
|
368
|
+
|
369
|
+
/* fill in metadata: on fragmented packets, it applies to the
|
370
|
+
first fragment only */
|
371
|
+
memcpy(&recon->r_meta.sender, &frame_address.ieee_src,
|
372
|
+
sizeof(ieee154_addr_t));
|
373
|
+
recon->r_meta.lqi = call ReadLqi.readLqi(msg);
|
374
|
+
recon->r_meta.rssi = call ReadLqi.readRssi(msg);
|
375
|
+
|
376
|
+
if (hasFrag1Header(&lowmsg)) {
|
377
|
+
if (recon->r_buf != NULL) goto fail;
|
378
|
+
rv = lowpan_recon_start(&frame_address, recon, buf, len);
|
379
|
+
} else {
|
380
|
+
rv = lowpan_recon_add(recon, buf, len);
|
381
|
+
}
|
382
|
+
|
383
|
+
if (rv < 0) {
|
384
|
+
recon->r_timeout = T_FAILED1;
|
385
|
+
goto fail;
|
386
|
+
} else {
|
387
|
+
// printf("start recon buf: %p\n", recon->r_buf);
|
388
|
+
recon->r_timeout = T_ACTIVE;
|
389
|
+
recon->r_source_key = source_key;
|
390
|
+
recon->r_tag = tag;
|
391
|
+
}
|
392
|
+
|
393
|
+
if (recon->r_size == recon->r_bytes_rcvd) {
|
394
|
+
deliver(recon);
|
395
|
+
}
|
396
|
+
|
397
|
+
} else {
|
398
|
+
/* no fragmentation, just deliver it */
|
399
|
+
int rv;
|
400
|
+
struct lowpan_reconstruct recon;
|
401
|
+
|
402
|
+
/* fill in metadata */
|
403
|
+
memcpy(&recon.r_meta.sender, &frame_address.ieee_src,
|
404
|
+
sizeof(ieee154_addr_t));
|
405
|
+
recon.r_meta.lqi = call ReadLqi.readLqi(msg);
|
406
|
+
recon.r_meta.rssi = call ReadLqi.readRssi(msg);
|
407
|
+
|
408
|
+
buf = getLowpanPayload(&lowmsg);
|
409
|
+
if ((rv = lowpan_recon_start(&frame_address, &recon, buf, len)) < 0) {
|
410
|
+
goto fail;
|
411
|
+
}
|
412
|
+
|
413
|
+
if (recon.r_size == recon.r_bytes_rcvd) {
|
414
|
+
deliver(&recon);
|
415
|
+
} else {
|
416
|
+
// printf("ip_free(%p)\n", recon.r_buf);
|
417
|
+
ip_free(recon.r_buf);
|
418
|
+
}
|
419
|
+
}
|
420
|
+
goto done;
|
421
|
+
fail:
|
422
|
+
BLIP_STATS_INCR(stats.rx_drop);
|
423
|
+
done:
|
424
|
+
return msg;
|
425
|
+
}
|
426
|
+
|
427
|
+
|
428
|
+
/*
|
429
|
+
* Send-side functionality
|
430
|
+
*/
|
431
|
+
task void sendTask() {
|
432
|
+
struct send_entry *s_entry;
|
433
|
+
|
434
|
+
// printf("sendTask() - sending\n");
|
435
|
+
|
436
|
+
if (radioBusy || state != S_RUNNING) return;
|
437
|
+
if (call SendQueue.empty()) return;
|
438
|
+
// this does not dequeue
|
439
|
+
s_entry = call SendQueue.head();
|
440
|
+
|
441
|
+
#ifdef LPL_SLEEP_INTERVAL
|
442
|
+
call LowPowerListening.setRemoteWakeupInterval(s_entry->msg,
|
443
|
+
call LowPowerListening.getLocalWakeupInterval());
|
444
|
+
#endif
|
445
|
+
|
446
|
+
if (s_entry->info->failed) {
|
447
|
+
dbg("Drops", "drops: sendTask: dropping failed fragment\n");
|
448
|
+
goto fail;
|
449
|
+
}
|
450
|
+
|
451
|
+
if ((call Ieee154Send.send(s_entry->msg,
|
452
|
+
call BarePacket.payloadLength(s_entry->msg))) != SUCCESS) {
|
453
|
+
dbg("Drops", "drops: sendTask: send failed\n");
|
454
|
+
goto fail;
|
455
|
+
} else {
|
456
|
+
radioBusy = TRUE;
|
457
|
+
}
|
458
|
+
|
459
|
+
return;
|
460
|
+
fail:
|
461
|
+
printf("SEND FAIL\n");
|
462
|
+
post sendTask();
|
463
|
+
BLIP_STATS_INCR(stats.tx_drop);
|
464
|
+
|
465
|
+
// deallocate the memory associated with this request.
|
466
|
+
// other fragments associated with this packet will get dropped.
|
467
|
+
s_entry->info->failed = TRUE;
|
468
|
+
SENDINFO_DECR(s_entry->info);
|
469
|
+
call FragPool.put(s_entry->msg);
|
470
|
+
call SendEntryPool.put(s_entry);
|
471
|
+
call SendQueue.dequeue();
|
472
|
+
}
|
473
|
+
|
474
|
+
|
475
|
+
/*
|
476
|
+
* it will pack the message into the fragment pool and enqueue
|
477
|
+
* those fragments for sending
|
478
|
+
*
|
479
|
+
* it will set
|
480
|
+
* - payload length
|
481
|
+
* - version, traffic class and flow label
|
482
|
+
*
|
483
|
+
* the source and destination IP addresses must be set by higher
|
484
|
+
* layers.
|
485
|
+
*/
|
486
|
+
command error_t IPLower.send(struct ieee154_frame_addr *frame_addr,
|
487
|
+
struct ip6_packet *msg,
|
488
|
+
void *data) {
|
489
|
+
struct lowpan_ctx ctx;
|
490
|
+
struct send_info *s_info;
|
491
|
+
struct send_entry *s_entry;
|
492
|
+
message_t *outgoing;
|
493
|
+
|
494
|
+
int frag_len = 1;
|
495
|
+
error_t rc = SUCCESS;
|
496
|
+
|
497
|
+
if (state != S_RUNNING) {
|
498
|
+
return EOFF;
|
499
|
+
}
|
500
|
+
|
501
|
+
/* set version to 6 in case upper layers forgot */
|
502
|
+
msg->ip6_hdr.ip6_vfc &= ~IPV6_VERSION_MASK;
|
503
|
+
msg->ip6_hdr.ip6_vfc |= IPV6_VERSION;
|
504
|
+
|
505
|
+
ctx.tag = current_local_label++;
|
506
|
+
ctx.offset = 0;
|
507
|
+
|
508
|
+
s_info = getSendInfo();
|
509
|
+
if (s_info == NULL) {
|
510
|
+
rc = ERETRY;
|
511
|
+
goto cleanup_outer;
|
512
|
+
}
|
513
|
+
s_info->upper_data = data;
|
514
|
+
|
515
|
+
while (frag_len > 0) {
|
516
|
+
s_entry = call SendEntryPool.get();
|
517
|
+
outgoing = call FragPool.get();
|
518
|
+
|
519
|
+
if (s_entry == NULL || outgoing == NULL) {
|
520
|
+
if (s_entry != NULL)
|
521
|
+
call SendEntryPool.put(s_entry);
|
522
|
+
if (outgoing != NULL)
|
523
|
+
call FragPool.put(outgoing);
|
524
|
+
// this will cause any fragments we have already enqueued to
|
525
|
+
// be dropped by the send task.
|
526
|
+
s_info->failed = TRUE;
|
527
|
+
printf("drops: IP send: no fragments\n");
|
528
|
+
rc = ERETRY;
|
529
|
+
goto done;
|
530
|
+
}
|
531
|
+
|
532
|
+
call BarePacket.clear(outgoing);
|
533
|
+
frag_len = lowpan_frag_get(call Ieee154Send.getPayload(outgoing, 0),
|
534
|
+
call BarePacket.maxPayloadLength(),
|
535
|
+
msg,
|
536
|
+
frame_addr,
|
537
|
+
&ctx);
|
538
|
+
if (frag_len < 0) {
|
539
|
+
printf(" get frag error: %i\n", frag_len);
|
540
|
+
}
|
541
|
+
|
542
|
+
printf("fragment length: %i offset: %i\n", frag_len, ctx.offset);
|
543
|
+
call BarePacket.setPayloadLength(outgoing, frag_len);
|
544
|
+
|
545
|
+
if (frag_len <= 0) {
|
546
|
+
call FragPool.put(outgoing);
|
547
|
+
call SendEntryPool.put(s_entry);
|
548
|
+
goto done;
|
549
|
+
}
|
550
|
+
|
551
|
+
if (call SendQueue.enqueue(s_entry) != SUCCESS) {
|
552
|
+
BLIP_STATS_INCR(stats.encfail);
|
553
|
+
s_info->failed = TRUE;
|
554
|
+
printf("drops: IP send: enqueue failed\n");
|
555
|
+
goto done;
|
556
|
+
}
|
557
|
+
|
558
|
+
s_info->link_fragments++;
|
559
|
+
s_entry->msg = outgoing;
|
560
|
+
s_entry->info = s_info;
|
561
|
+
|
562
|
+
/* configure the L2 */
|
563
|
+
if (frame_addr->ieee_dst.ieee_mode == IEEE154_ADDR_SHORT &&
|
564
|
+
frame_addr->ieee_dst.i_saddr == IEEE154_BROADCAST_ADDR) {
|
565
|
+
call PacketLink.setRetries(s_entry->msg, 0);
|
566
|
+
} else {
|
567
|
+
call PacketLink.setRetries(s_entry->msg, BLIP_L2_RETRIES);
|
568
|
+
}
|
569
|
+
call PacketLink.setRetryDelay(s_entry->msg, BLIP_L2_DELAY);
|
570
|
+
|
571
|
+
SENDINFO_INCR(s_info);}
|
572
|
+
|
573
|
+
// printf("got %i frags\n", s_info->link_fragments);
|
574
|
+
done:
|
575
|
+
BLIP_STATS_INCR(stats.sent);
|
576
|
+
SENDINFO_DECR(s_info);
|
577
|
+
post sendTask();
|
578
|
+
cleanup_outer:
|
579
|
+
return rc;
|
580
|
+
}
|
581
|
+
|
582
|
+
event void Ieee154Send.sendDone(message_t *msg, error_t error) {
|
583
|
+
struct send_entry *s_entry = call SendQueue.head();
|
584
|
+
|
585
|
+
radioBusy = FALSE;
|
586
|
+
|
587
|
+
// printf("sendDone: %p %i\n", msg, error);
|
588
|
+
|
589
|
+
if (state == S_STOPPING) {
|
590
|
+
call RadioControl.stop();
|
591
|
+
state = S_STOPPED;
|
592
|
+
goto done;
|
593
|
+
}
|
594
|
+
|
595
|
+
s_entry->info->link_transmissions += (call PacketLink.getRetries(msg));
|
596
|
+
s_entry->info->link_fragment_attempts++;
|
597
|
+
|
598
|
+
if (!call PacketLink.wasDelivered(msg)) {
|
599
|
+
printf("sendDone: was not delivered! (%i tries)\n",
|
600
|
+
call PacketLink.getRetries(msg));
|
601
|
+
s_entry->info->failed = TRUE;
|
602
|
+
signal IPLower.sendDone(s_entry->info);
|
603
|
+
/* if (s_entry->info->policy.dest[0] != 0xffff) */
|
604
|
+
/* dbg("Drops", "drops: sendDone: frag was not delivered\n"); */
|
605
|
+
// need to check for broadcast frames
|
606
|
+
// BLIP_STATS_INCR(stats.tx_drop);
|
607
|
+
} else if (s_entry->info->link_fragment_attempts ==
|
608
|
+
s_entry->info->link_fragments) {
|
609
|
+
signal IPLower.sendDone(s_entry->info);
|
610
|
+
}
|
611
|
+
|
612
|
+
done:
|
613
|
+
// kill off any pending fragments
|
614
|
+
SENDINFO_DECR(s_entry->info);
|
615
|
+
call FragPool.put(s_entry->msg);
|
616
|
+
call SendEntryPool.put(s_entry);
|
617
|
+
call SendQueue.dequeue();
|
618
|
+
|
619
|
+
post sendTask();
|
620
|
+
}
|
621
|
+
|
622
|
+
#if 0
|
623
|
+
command struct tlv_hdr *IPExtensions.findTlv(struct ip6_ext *ext, uint8_t tlv_val) {
|
624
|
+
int len = ext->len - sizeof(struct ip6_ext);
|
625
|
+
struct tlv_hdr *tlv = (struct tlv_hdr *)(ext + 1);
|
626
|
+
while (len > 0) {
|
627
|
+
if (tlv->type == tlv_val) return tlv;
|
628
|
+
if (tlv->len == 0) return NULL;
|
629
|
+
tlv = (struct tlv_hdr *)(((uint8_t *)tlv) + tlv->len);
|
630
|
+
len -= tlv->len;
|
631
|
+
}
|
632
|
+
return NULL;
|
633
|
+
}
|
634
|
+
#endif
|
635
|
+
|
636
|
+
|
637
|
+
/*
|
638
|
+
* BlipStatistics interface
|
639
|
+
*/
|
640
|
+
command void BlipStatistics.get(ip_statistics_t *statistics) {
|
641
|
+
#ifdef BLIP_STATS_IP_MEM
|
642
|
+
stats.fragpool = call FragPool.size();
|
643
|
+
stats.sendinfo = call SendInfoPool.size();
|
644
|
+
stats.sendentry= call SendEntryPool.size();
|
645
|
+
stats.sndqueue = call SendQueue.size();
|
646
|
+
stats.heapfree = ip_malloc_freespace();
|
647
|
+
printf("frag: %i sendinfo: %i sendentry: %i sendqueue: %i heap: %i\n",
|
648
|
+
stats.fragpool,
|
649
|
+
stats.sendinfo,
|
650
|
+
stats.sendentry,
|
651
|
+
stats.sndqueue,
|
652
|
+
stats.heapfree);
|
653
|
+
#endif
|
654
|
+
memcpy(statistics, &stats, sizeof(ip_statistics_t));
|
655
|
+
|
656
|
+
}
|
657
|
+
|
658
|
+
command void BlipStatistics.clear() {
|
659
|
+
memclr((uint8_t *)&stats, sizeof(ip_statistics_t));
|
660
|
+
}
|
661
|
+
|
662
|
+
/* default event void IP.recv[uint8_t nxt_hdr](struct ip6_hdr *iph, */
|
663
|
+
/* void *payload, */
|
664
|
+
/* struct ip_metadata *meta) { */
|
665
|
+
/* } */
|
666
|
+
|
667
|
+
/* default event void Multicast.recv[uint8_t scope](struct ip6_hdr *iph, */
|
668
|
+
/* void *payload, */
|
669
|
+
/* struct ip_metadata *meta) { */
|
670
|
+
/* } */
|
671
|
+
}
|