-
Notifications
You must be signed in to change notification settings - Fork 0
/
Deluge.h
166 lines (146 loc) · 5.1 KB
/
Deluge.h
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
// $Id: Deluge.h,v 1.25 2005/08/18 04:41:01 jwhui Exp $
/* tab:2
*
*
* "Copyright (c) 2000-2005 The Regents of the University of California.
* All rights reserved.
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose, without fee, and without written agreement is
* hereby granted, provided that the above copyright notice, the following
* two paragraphs and the author appear in all copies of this software.
*
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
*
*/
/**
* @author Jonathan Hui <[email protected]>
*/
#ifndef __DELUGE_H__
#define __DELUGE_H__
#include "DelugeMetadata.h"
#include "TOSBoot.h"
#include "pr.h"
#ifndef PLATFORM_PC
#include "Bcast.h"
#endif
#ifndef DELUGE_NUM_IMAGES
#define DELUGE_NUM_IMAGES 3
#endif
#ifndef PLATFORM_PC
#define LOSS_RATE call Bcast.getLoss()
#else
#define LOSS_RATE 0
#endif
#define PKT_LOSS(msg) do { if ((call Random.rand()%100)<(LOSS_RATE)) return (msg); } while (0)
enum {
DELUGE_VERSION = 2,
DELUGE_MAX_ADV_PERIOD_LOG2 = 22,
DELUGE_NUM_NEWDATA_ADVS_REQUIRED = 2,
DELUGE_NUM_MIN_ADV_PERIODS = 2,
DELUGE_MAX_NUM_REQ_TRIES = 1,
DELUGE_REBOOT_DELAY = 4,
DELUGE_FAILED_SEND_DELAY = 16,
DELUGE_MIN_DELAY = 16,
DELUGE_BYTES_PER_PAGE = 1104,// it's predetermined value
DELUGE_PKT_PAYLOAD_SIZE = 92,//100,
DELUGE_PKTS_PER_PAGE = (DELUGE_BYTES_PER_PAGE+DELUGE_PKT_PAYLOAD_SIZE-1)/DELUGE_PKT_PAYLOAD_SIZE,
DELUGE_BYTES_LAST_PKT = DELUGE_BYTES_PER_PAGE % DELUGE_PKT_PAYLOAD_SIZE,
DELUGE_DATA_OFFSET = 128,
DELUGE_IDENT_SIZE = 128,
DELUGE_INVALID_ADDR = (0x7fffffffL),
DELUGE_MAX_REQ_DELAY = (0x1L << (DELUGE_MIN_ADV_PERIOD_LOG2-1)), // 256
DELUGE_NACK_TIMEOUT = (DELUGE_MAX_REQ_DELAY >> 0x1),
//DELUGE_BYTES_PER_PAGE = (DELUGE_PKTS_PER_PAGE*DELUGE_PKT_PAYLOAD_SIZE),
// for the last page, we may not need to fill all the bits to complete. it must be a predetermined value
DELUGE_PKT_BITVEC_SIZE = (((DELUGE_PKTS_PER_PAGE-1) / 8) + 1),
DELUGE_MAX_IMAGE_SIZE = (128L*1024L),
DELUGE_MAX_PAGES = 96,//modified
DELUGE_CRC_SIZE = sizeof(uint16_t),
DELUGE_CRC_BLOCK_SIZE = DELUGE_MAX_PAGES*DELUGE_CRC_SIZE,
DELUGE_GOLDEN_IMAGE_NUM = 0x0,
DELUGE_INVALID_VNUM = -1,
DELUGE_INVALID_IMGNUM = 0xff,
DELUGE_INVALID_PKTNUM = 0xff,
DELUGE_INVALID_PGNUM = 0xff,
};
// we add these
#define DELUGE_BYTES_LAST_PAGE(imgsize) (imgsize%DELUGE_BYTES_PER_PAGE)
#define DELUGE_PKTS_LAST_PAGE(imgsize) ( (DELUGE_BYTES_LAST_PAGE(imgsize)+DELUGE_PKT_PAYLOAD_SIZE-1)/DELUGE_PKT_PAYLOAD_SIZE )
#define DELUGE_BYTES_LAST_PKT_LAST_PAGE (DELUGE_BYTES_LAST_PAGE(imgsize)%DELUGE_PKT_PAYLOAD_SIZE)
#include "Storage.h"
struct deluge_image_t {
imgnum_t imageNum;
volume_id_t volumeId;
};
typedef struct DelugeAdvTimer {
uint32_t timer : 32;
uint8_t periodLog2 : 8;
bool overheard : 1;
uint8_t newAdvs : 7;
} DelugeAdvTimer;
typedef struct DelugeNodeDesc {
imgvnum_t vNum;
uint32_t uid;
imgnum_t imgNum;
uint8_t reserved;
uint16_t crc;
} DelugeNodeDesc;
enum {
DELUGE_VOLUME_ID_0 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 2
DELUGE_VOLUME_ID_1 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 3
DELUGE_VOLUME_ID_2 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 4
DELUGE_VOLUME_ID_3 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 5
DELUGE_VOLUME_ID_4 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 6
DELUGE_VOLUME_ID_5 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 7
DELUGE_VOLUME_ID_6 = unique("StorageManager"),
#if DELUGE_NUM_IMAGES >= 8
DELUGE_VOLUME_ID_7 = unique("StorageManager"),
#endif
#endif
#endif
#endif
#endif
#endif
#endif
};
static const struct deluge_image_t DELUGE_IMAGES[DELUGE_NUM_IMAGES] = {
{ DELUGE_VOLUME_ID_0, 0xDF },
#if DELUGE_NUM_IMAGES >= 2
{ DELUGE_VOLUME_ID_1, 0xD0 },
#if DELUGE_NUM_IMAGES >= 3
{ DELUGE_VOLUME_ID_2, 0xD1 },
#if DELUGE_NUM_IMAGES >= 4
{ DELUGE_VOLUME_ID_3, 0xD2 },
#if DELUGE_NUM_IMAGES >= 5
{ DELUGE_VOLUME_ID_4, 0xD3 },
#if DELUGE_NUM_IMAGES >= 6
{ DELUGE_VOLUME_ID_5, 0xD4 },
#if DELUGE_NUM_IMAGES >= 7
{ DELUGE_VOLUME_ID_6, 0xD5 },
#if DELUGE_NUM_IMAGES >= 8
{ DELUGE_VOLUME_ID_7, 0xD6 },
#endif
#endif
#endif
#endif
#endif
#endif
#endif
};
#endif