Browse code

added variable to-rag part to mitigate dropping TM-owned ACKs

Jiri Kuthan authored on 26/05/2002 17:53:21
Showing 4 changed files
... ...
@@ -5,6 +5,8 @@
5 5
  */
6 6
 
7 7
 #include <stdio.h>
8
+#include "str.h"
9
+#include "ut.h"
8 10
 #include "crc.h"
9 11
 
10 12
 #define OK 0
... ...
@@ -179,6 +181,46 @@ unsigned short int crc_16_tab[] = { /* CRC polynomial 0xA001 */
179 179
 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040,
180 180
 };
181 181
 
182
+unsigned short crcitt_string( char *s, int len )
183
+{
184
+	register unsigned short ccitt;
185
+	
186
+	ccitt = 0xFFFF;
187
+
188
+	while( len ) {
189
+		ccitt = UPDCIT(*s, ccitt);
190
+		s++; len--;
191
+	}
192
+	return ~ccitt;
193
+}
194
+
195
+void crcitt_string_array( char *dst, str src[], int size )
196
+{
197
+	register int i;
198
+	register unsigned short ccitt;
199
+	register char *c;
200
+	register int len;
201
+	int str_len;
202
+
203
+	ccitt = 0xFFFF;
204
+	str_len=CRC16_LEN;
205
+	for (i=0; i<size; i++ ) {
206
+		c=src[i].s;
207
+		len=src[i].len;
208
+		while(len) {
209
+			ccitt = UPDCIT( *c, ccitt );
210
+			c++;len--;
211
+		}
212
+	}
213
+	ccitt = ~ccitt;
214
+	if (int2reverse_hex( &dst, &str_len, ccitt )==-1) {
215
+		/* bug ... printed ccitt value longer than CRC32_LEN */
216
+		LOG(L_CRIT, "ERROR: crcitt_string_array: string conversion incomplete\n");
217
+	}
218
+}
219
+		
220
+				
221
+
182 222
 int crc32file (char *name)
183 223
 {
184 224
 	register FILE *fin;
... ...
@@ -3,9 +3,14 @@
3 3
 #ifndef _CRC_H_
4 4
 #define _CRC_H_
5 5
 
6
+#define CRC16_LEN	4
7
+
6 8
 extern unsigned long int crc_32_tab[];
7 9
 extern unsigned short int ccitt_tab[];
8 10
 extern unsigned short int crc_16_tab[];
9 11
 
12
+unsigned short crcitt_string( char *s, int len );
13
+void crcitt_string_array( char *dst, str src[], int size );
14
+
10 15
 #endif
11 16
 
... ...
@@ -60,44 +60,6 @@
60 60
 	)==0 )
61 61
 
62 62
 
63
-static int reverse_hex2int( char *c, int len )
64
-{
65
-	char *pc;
66
-	int r;
67
-	char mychar;
68
-
69
-	r=0;
70
-	for (pc=c+len-1; len>0; pc--, len--) {
71
-		r <<= 4 ;
72
-		mychar=*pc;
73
-		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
74
-		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
75
-		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
76
-		else return -1;
77
-	}
78
-	return r;
79
-}
80
-
81
-inline static int int2reverse_hex( char **c, int *size, int nr )
82
-{
83
-	unsigned short digit;
84
-
85
-	if (*size && nr==0) {
86
-		**c = '0';
87
-		(*c)++;
88
-		(*size)--;
89
-		return 1;
90
-	}
91
-
92
-	while (*size && nr ) {
93
-		digit = nr & 0xf ;
94
-		**c= digit >= 10 ? digit + 'a' - 10 : digit + '0';
95
-		nr >>= 4;
96
-		(*c)++;
97
-		(*size)--;
98
-	}
99
-	return nr ? -1 /* number not processed; too little space */ : 1;
100
-}
101 63
 
102 64
 /* function returns:
103 65
  *      -1 - transaction wasn't found
... ...
@@ -156,5 +156,44 @@ static inline char* q_memchr(char* p, int c, unsigned int size)
156 156
 }
157 157
 	
158 158
 
159
+static int reverse_hex2int( char *c, int len )
160
+{
161
+	char *pc;
162
+	int r;
163
+	char mychar;
164
+
165
+	r=0;
166
+	for (pc=c+len-1; len>0; pc--, len--) {
167
+		r <<= 4 ;
168
+		mychar=*pc;
169
+		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
170
+		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
171
+		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
172
+		else return -1;
173
+	}
174
+	return r;
175
+}
176
+
177
+inline static int int2reverse_hex( char **c, int *size, int nr )
178
+{
179
+	unsigned short digit;
180
+
181
+	if (*size && nr==0) {
182
+		**c = '0';
183
+		(*c)++;
184
+		(*size)--;
185
+		return 1;
186
+	}
187
+
188
+	while (*size && nr ) {
189
+		digit = nr & 0xf ;
190
+		**c= digit >= 10 ? digit + 'a' - 10 : digit + '0';
191
+		nr >>= 4;
192
+		(*c)++;
193
+		(*size)--;
194
+	}
195
+	return nr ? -1 /* number not processed; too little space */ : 1;
196
+}
197
+
159 198
 
160 199
 #endif