merge 64-bit fixes from Fernando Lucas Rodriguez <fernando_lr@terra.es>
[debian/gcpegg] / global.h
1 /* PROGRAM:     eggsh
2  * FILE:        $Header: /home/egg/src/RCS/global.h,v 1.5 1999/02/28 20:10:29 ghn Exp $
3  * PURPOSE:     Declare global types, constants, and variables
4  * AUTHOR:      Greg Nelson
5  * DATE:        98-04-12
6  *
7  * REVISED:
8  * $Log: global.h,v $
9  * Revision 1.5  1999/02/28 20:10:29  ghn
10  * Version 5.1: Added netmask field for egg.
11  *
12  * Revision 1.4  1998/12/31 22:11:05  ghn
13  *  Rev 5 code: includes multi-reg support, HTML, etc.
14  *
15  * Revision 1.3  1998/08/01 18:51:25  ghn
16  * Added John's byte-order-independence changes.
17  *
18  * Revision 1.2  1998/08/01 17:08:20  ghn
19  * Added upcmd and dncmd for DND.
20  *
21  * Revision 1.1  1998/07/21 11:37:56  ghn
22  * Initial revision
23  *
24  * Copyright 1998 - Greg Nelson
25  * Redistributable under the terms of the GNU Public Licence (GPL)
26  */
27
28 #ifndef _GLOBAL_H
29
30 #include <netinet/in.h>
31
32 #include "byteorder.h"          /* Build byte-order independent version */
33
34 /* Good for i386, but be careful... */
35 /*
36 #ifdef linux
37 #include <sys/types.h>
38  typedef __u8  byte;
39  typedef __u8  uint8;
40  typedef __u16 uint16;
41  typedef __u32 uint32;
42  typedef __s8  int8;
43  typedef __s16 int16;
44  typedef __s32 int32;
45 #else
46  typedef unsigned char byte;
47  typedef unsigned char uint8;
48  typedef unsigned ushort uint16;
49  typedef unsigned uint uint32;
50  typedef char int8;
51  typedef short int16;
52  typedef int int32;
53 #endif
54 */
55
56 #include <stdint.h>
57 typedef uint8_t byte;
58 typedef uint8_t uint8;
59 typedef uint16_t uint16;
60 typedef uint32_t uint32;
61 typedef int8_t int8;
62 typedef int16_t int16;
63 typedef int32_t int32;
64
65 /* Some fixed assumptions:
66    Trial type is always bitsum.
67    Bit spacing method does not need to be communicated, since we'll
68      choose something at compile time. 
69    Record size ranges from one to MAXSAMP_REC trials, which are assumed to
70      be evenly spaced starting at timestamp.
71    Records always begin on round seconds divisible by sec_rec, which
72      can range from one to MAXSEC_REC.
73 */
74
75 /* Some adjustable assumptions: */
76
77 #define MINBITS         32      /* Minimum bits per trial */
78 #define MAXBITS         253     /* Maximum bits per trial */
79 #define MAXSAMP_REC     10      /* Maximum samples/record */
80 #define MAXSEC_REC      3000    /* Maximum seconds/record */    
81
82 #define SEC_PKT         60      /* Desired number of seconds per packet */
83 #define MAXREC_PKT      60      /* Maximum number of records per packet
84                                    For 1-second records (typ) this is 1 min */
85
86 #define EGG_MISSING_DATA 254    /* Value used to represent missing data in trials array. */
87
88 #if MAXBITS < 256
89 typedef uint8 trial;
90 #else
91 #error "Can't represent MAXBITS in a byte value."
92 #endif
93
94 #if MAXBITS >= EGG_MISSING_DATA
95 #error "MAXBITS is >= EGG_MISSING_DATA: ambiguous trial data possible."
96 #endif
97
98 typedef struct eggrec {
99   uint32 timestamp;     /* Seconds since the epoch (19700101000000Z) */
100   trial trials[MAXSAMP_REC]; /* Trial values */
101 } EggRec;               /* Normally 16 bytes total */
102
103 /* Make sure type field of packet is non-zero so that CRC works. */
104
105 typedef struct genpacket {
106   uint16 type;
107   uint16 pktsize;
108 } GenPacket;
109
110 #define DATA_PACKET     0x0101
111 typedef struct eggheader {
112   uint16 type;          /* type */
113   uint16 pktsize;       /* Number of bytes in packet */
114   uint16 eggid;         /* Identifying number for device */
115   uint16 samp_rec;      /* Number of samples per record */
116   uint16 sec_rec;       /* Number of seconds per record */
117   uint16 rec_pkt;       /* Number of records per packet */
118   trial trialsz;        /* Number of bits per trial */
119   uint16 numrec;        /* Number of valid records */
120 } EggHeader;
121
122 #define REQ_PACKET      0x0202
123 typedef struct reqpacket {
124   uint16 type;          /* type */
125   uint16 pktsize;       /* Number of bytes in packet */
126   uint16 eggid;         /* Identifying number for device */
127   uint32 starttm;       /* Time for first record to send */
128   uint16 cksum;         /* No data, checksum goes inside */
129 } ReqPacket;
130
131 #define AWAKE_PACKET    0x0303
132 typedef struct awakepacket {
133   uint16 type;          /* type */
134   uint16 pktsize;       /* Number of bytes in packet */
135   uint16 eggid;         /* Identifying number for device */
136   uint32 nowtm;         /* Egg's identification of "now" (zulu) */
137   uint16 cksum;         /* No data, checksum goes inside */
138 } AwakePacket;
139
140 #define SETTINGS_PACKET 0x0404
141 typedef struct setpacket {
142   uint16 type;          /* type */
143   uint16 pktsize;       /* Number of bytes in packet */
144   uint16 eggid;         /* Identifying number for device */
145   uint32 nowtm;         /* Egg's identification of "now" (zulu) */
146   uint16 samp_rec;      /* Number of samples per record */
147   uint16 sec_rec;       /* Number of seconds per record */
148   uint16 rec_pkt;       /* Number of records per packet */
149   trial trialsz;        /* Number of bits per trial */
150   uint16 cksum;         /* No data, checksum goes inside */
151 } SettingsPacket;
152
153 /*  An EggCarton is the in-memory representation of a data
154     packet.  Fields in it are thus in host byte order,
155     being translated, as appropriate, when transferred
156     to and from a DATA_PACKET by Packetize() and
157     Unpacketize().  */
158
159 typedef struct eggpkt {
160   EggHeader hdr;        /* Header (type = DATA_PACKET) */
161   EggRec records[MAXREC_PKT];
162 } EggCarton;
163
164 typedef struct collect {
165   EggHeader opts;
166   EggRec data;
167   uint16 sampct;                /* Count of completed samples in rec */
168   int32 dd;                     /* Device handle */
169 } CollectRecord;
170
171 #define CONN_PERM       0
172 #define CONN_DND        1
173
174 typedef struct eggentry {
175   char *name;
176   int16 id;
177   struct sockaddr_in ipaddr;
178   int16 netmask;        /* Number of significant bits, default 32. */
179   char *primbasket;
180   int16 conntype;
181   int16 connival;       /* Connect interval in minutes */
182   uint32 lastupd;       /* Zulutime of last update received */
183   int16 setup;          /* Does setup match config file? */
184   char *upcmd;          /* Command to bring net up (req if conntype == DND) */
185   char *dncmd;          /* Command to bring net down */
186   char *url;            /* URL describing basket or NULL */
187 } EggEntry;
188
189 typedef struct basketentry {
190   char *name;
191   struct sockaddr_in ipaddr;
192 } BasketEntry;
193
194 #define MAX_EGGS        100
195 #define MAX_BASKETS     5
196
197 extern EggEntry eggtable[MAX_EGGS];
198 extern BasketEntry baskettable[MAX_BASKETS];
199 extern short numeggs, numbaskets;
200 extern EggHeader protocol;
201
202 extern char *pgmname;   /* For error messages to announce program name */
203
204 #define TRUE    -1
205 #define FALSE   0
206
207 #define _GLOBAL_H
208 #endif /* _GLOBAL_H */