aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/i4l/isdn_bsdcomp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/isdn/i4l/isdn_bsdcomp.c')
-rw-r--r--drivers/isdn/i4l/isdn_bsdcomp.c374
1 files changed, 187 insertions, 187 deletions
diff --git a/drivers/isdn/i4l/isdn_bsdcomp.c b/drivers/isdn/i4l/isdn_bsdcomp.c
index aa0b6a6f5ef4..7f3c54d40474 100644
--- a/drivers/isdn/i4l/isdn_bsdcomp.c
+++ b/drivers/isdn/i4l/isdn_bsdcomp.c
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9/* 9/*
10 * Update: The Berkeley copyright was changed, and the change 10 * Update: The Berkeley copyright was changed, and the change
11 * is retroactive to all "true" BSD software (ie everything 11 * is retroactive to all "true" BSD software (ie everything
12 * from UCB as opposed to other peoples code that just carried 12 * from UCB as opposed to other peoples code that just carried
13 * the same license). The new copyright doesn't clash with the 13 * the same license). The new copyright doesn't clash with the
@@ -121,7 +121,7 @@ struct bsd_db {
121 unsigned char maxbits; /* maximum bits/code */ 121 unsigned char maxbits; /* maximum bits/code */
122 unsigned char debug; /* non-zero if debug desired */ 122 unsigned char debug; /* non-zero if debug desired */
123 unsigned char unit; /* ppp unit number */ 123 unsigned char unit; /* ppp unit number */
124 u16 seqno; /* sequence # of next packet */ 124 u16 seqno; /* sequence # of next packet */
125 unsigned int mru; /* size of receive (decompress) bufr */ 125 unsigned int mru; /* size of receive (decompress) bufr */
126 unsigned int maxmaxcode; /* largest valid code */ 126 unsigned int maxmaxcode; /* largest valid code */
127 unsigned int max_ent; /* largest code in use */ 127 unsigned int max_ent; /* largest code in use */
@@ -157,16 +157,16 @@ struct bsd_db {
157#define MAXCODE(b) ((1 << (b)) - 1) 157#define MAXCODE(b) ((1 << (b)) - 1)
158#define BADCODEM1 MAXCODE(MAX_BSD_BITS) 158#define BADCODEM1 MAXCODE(MAX_BSD_BITS)
159 159
160#define BSD_HASH(prefix,suffix,hshift) ((((unsigned long)(suffix))<<(hshift)) \ 160#define BSD_HASH(prefix, suffix, hshift) ((((unsigned long)(suffix)) << (hshift)) \
161 ^ (unsigned long)(prefix)) 161 ^ (unsigned long)(prefix))
162#define BSD_KEY(prefix,suffix) ((((unsigned long)(suffix)) << 16) \ 162#define BSD_KEY(prefix, suffix) ((((unsigned long)(suffix)) << 16) \
163 + (unsigned long)(prefix)) 163 + (unsigned long)(prefix))
164 164
165#define CHECK_GAP 10000 /* Ratio check interval */ 165#define CHECK_GAP 10000 /* Ratio check interval */
166 166
167#define RATIO_SCALE_LOG 8 167#define RATIO_SCALE_LOG 8
168#define RATIO_SCALE (1<<RATIO_SCALE_LOG) 168#define RATIO_SCALE (1 << RATIO_SCALE_LOG)
169#define RATIO_MAX (0x7fffffff>>RATIO_SCALE_LOG) 169#define RATIO_MAX (0x7fffffff >> RATIO_SCALE_LOG)
170 170
171/* 171/*
172 * clear the dictionary 172 * clear the dictionary
@@ -175,7 +175,7 @@ struct bsd_db {
175static void bsd_clear(struct bsd_db *db) 175static void bsd_clear(struct bsd_db *db)
176{ 176{
177 db->clear_count++; 177 db->clear_count++;
178 db->max_ent = FIRST-1; 178 db->max_ent = FIRST - 1;
179 db->n_bits = BSD_INIT_BITS; 179 db->n_bits = BSD_INIT_BITS;
180 db->bytes_out = 0; 180 db->bytes_out = 0;
181 db->in_count = 0; 181 db->in_count = 0;
@@ -197,56 +197,56 @@ static void bsd_clear(struct bsd_db *db)
197 * the absence of CLEAR codes (while packets are incompressible), they 197 * the absence of CLEAR codes (while packets are incompressible), they
198 * must compute the same ratio. 198 * must compute the same ratio.
199 */ 199 */
200static int bsd_check (struct bsd_db *db) /* 1=output CLEAR */ 200static int bsd_check(struct bsd_db *db) /* 1=output CLEAR */
201{ 201{
202 unsigned int new_ratio; 202 unsigned int new_ratio;
203 203
204 if (db->in_count >= db->checkpoint) 204 if (db->in_count >= db->checkpoint)
205 { 205 {
206 /* age the ratio by limiting the size of the counts */ 206 /* age the ratio by limiting the size of the counts */
207 if (db->in_count >= RATIO_MAX || db->bytes_out >= RATIO_MAX) 207 if (db->in_count >= RATIO_MAX || db->bytes_out >= RATIO_MAX)
208 { 208 {
209 db->in_count -= (db->in_count >> 2); 209 db->in_count -= (db->in_count >> 2);
210 db->bytes_out -= (db->bytes_out >> 2); 210 db->bytes_out -= (db->bytes_out >> 2);
211 } 211 }
212 212
213 db->checkpoint = db->in_count + CHECK_GAP; 213 db->checkpoint = db->in_count + CHECK_GAP;
214 214
215 if (db->max_ent >= db->maxmaxcode) 215 if (db->max_ent >= db->maxmaxcode)
216 { 216 {
217 /* Reset the dictionary only if the ratio is worse, 217 /* Reset the dictionary only if the ratio is worse,
218 * or if it looks as if it has been poisoned 218 * or if it looks as if it has been poisoned
219 * by incompressible data. 219 * by incompressible data.
220 * 220 *
221 * This does not overflow, because 221 * This does not overflow, because
222 * db->in_count <= RATIO_MAX. 222 * db->in_count <= RATIO_MAX.
223 */ 223 */
224 224
225 new_ratio = db->in_count << RATIO_SCALE_LOG; 225 new_ratio = db->in_count << RATIO_SCALE_LOG;
226 if (db->bytes_out != 0) 226 if (db->bytes_out != 0)
227 { 227 {
228 new_ratio /= db->bytes_out; 228 new_ratio /= db->bytes_out;
229 } 229 }
230 230
231 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) 231 if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE)
232 { 232 {
233 bsd_clear (db); 233 bsd_clear(db);
234 return 1; 234 return 1;
235 } 235 }
236 db->ratio = new_ratio; 236 db->ratio = new_ratio;
237 } 237 }
238 } 238 }
239 return 0; 239 return 0;
240} 240}
241 241
242/* 242/*
243 * Return statistics. 243 * Return statistics.
244 */ 244 */
245 245
246static void bsd_stats (void *state, struct compstat *stats) 246static void bsd_stats(void *state, struct compstat *stats)
247{ 247{
248 struct bsd_db *db = (struct bsd_db *) state; 248 struct bsd_db *db = (struct bsd_db *) state;
249 249
250 stats->unc_bytes = db->uncomp_bytes; 250 stats->unc_bytes = db->uncomp_bytes;
251 stats->unc_packets = db->uncomp_count; 251 stats->unc_packets = db->uncomp_count;
252 stats->comp_bytes = db->comp_bytes; 252 stats->comp_bytes = db->comp_bytes;
@@ -260,9 +260,9 @@ static void bsd_stats (void *state, struct compstat *stats)
260/* 260/*
261 * Reset state, as on a CCP ResetReq. 261 * Reset state, as on a CCP ResetReq.
262 */ 262 */
263static void bsd_reset (void *state,unsigned char code, unsigned char id, 263static void bsd_reset(void *state, unsigned char code, unsigned char id,
264 unsigned char *data, unsigned len, 264 unsigned char *data, unsigned len,
265 struct isdn_ppp_resetparams *rsparm) 265 struct isdn_ppp_resetparams *rsparm)
266{ 266{
267 struct bsd_db *db = (struct bsd_db *) state; 267 struct bsd_db *db = (struct bsd_db *) state;
268 268
@@ -274,7 +274,7 @@ static void bsd_reset (void *state,unsigned char code, unsigned char id,
274/* 274/*
275 * Release the compression structure 275 * Release the compression structure
276 */ 276 */
277static void bsd_free (void *state) 277static void bsd_free(void *state)
278{ 278{
279 struct bsd_db *db = (struct bsd_db *) state; 279 struct bsd_db *db = (struct bsd_db *) state;
280 280
@@ -302,7 +302,7 @@ static void bsd_free (void *state)
302/* 302/*
303 * Allocate space for a (de) compressor. 303 * Allocate space for a (de) compressor.
304 */ 304 */
305static void *bsd_alloc (struct isdn_ppp_comp_data *data) 305static void *bsd_alloc(struct isdn_ppp_comp_data *data)
306{ 306{
307 int bits; 307 int bits;
308 unsigned int hsize, hshift, maxmaxcode; 308 unsigned int hsize, hshift, maxmaxcode;
@@ -310,27 +310,27 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
310 int decomp; 310 int decomp;
311 311
312 static unsigned int htab[][2] = { 312 static unsigned int htab[][2] = {
313 { 5003 , 4 } , { 5003 , 4 } , { 5003 , 4 } , { 5003 , 4 } , 313 { 5003 , 4 } , { 5003 , 4 } , { 5003 , 4 } , { 5003 , 4 } ,
314 { 9001 , 5 } , { 18013 , 6 } , { 35023 , 7 } , { 69001 , 8 } 314 { 9001 , 5 } , { 18013 , 6 } , { 35023 , 7 } , { 69001 , 8 }
315 }; 315 };
316 316
317 if (data->optlen != 1 || data->num != CI_BSD_COMPRESS 317 if (data->optlen != 1 || data->num != CI_BSD_COMPRESS
318 || BSD_VERSION(data->options[0]) != BSD_CURRENT_VERSION) 318 || BSD_VERSION(data->options[0]) != BSD_CURRENT_VERSION)
319 return NULL; 319 return NULL;
320 320
321 bits = BSD_NBITS(data->options[0]); 321 bits = BSD_NBITS(data->options[0]);
322 322
323 if(bits < 9 || bits > 15) 323 if (bits < 9 || bits > 15)
324 return NULL; 324 return NULL;
325 325
326 hsize = htab[bits-9][0]; 326 hsize = htab[bits - 9][0];
327 hshift = htab[bits-9][1]; 327 hshift = htab[bits - 9][1];
328 328
329 /* 329 /*
330 * Allocate the main control structure for this instance. 330 * Allocate the main control structure for this instance.
331 */ 331 */
332 maxmaxcode = MAXCODE(bits); 332 maxmaxcode = MAXCODE(bits);
333 db = kzalloc (sizeof (struct bsd_db),GFP_KERNEL); 333 db = kzalloc(sizeof(struct bsd_db), GFP_KERNEL);
334 if (!db) 334 if (!db)
335 return NULL; 335 return NULL;
336 336
@@ -343,7 +343,7 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
343 */ 343 */
344 db->dict = vmalloc(hsize * sizeof(struct bsd_dict)); 344 db->dict = vmalloc(hsize * sizeof(struct bsd_dict));
345 if (!db->dict) { 345 if (!db->dict) {
346 bsd_free (db); 346 bsd_free(db);
347 return NULL; 347 return NULL;
348 } 348 }
349 349
@@ -356,7 +356,7 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
356 else { 356 else {
357 db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0])); 357 db->lens = vmalloc((maxmaxcode + 1) * sizeof(db->lens[0]));
358 if (!db->lens) { 358 if (!db->lens) {
359 bsd_free (db); 359 bsd_free(db);
360 return (NULL); 360 return (NULL);
361 } 361 }
362 } 362 }
@@ -364,41 +364,41 @@ static void *bsd_alloc (struct isdn_ppp_comp_data *data)
364 /* 364 /*
365 * Initialize the data information for the compression code 365 * Initialize the data information for the compression code
366 */ 366 */
367 db->totlen = sizeof (struct bsd_db) + (sizeof (struct bsd_dict) * hsize); 367 db->totlen = sizeof(struct bsd_db) + (sizeof(struct bsd_dict) * hsize);
368 db->hsize = hsize; 368 db->hsize = hsize;
369 db->hshift = hshift; 369 db->hshift = hshift;
370 db->maxmaxcode = maxmaxcode; 370 db->maxmaxcode = maxmaxcode;
371 db->maxbits = bits; 371 db->maxbits = bits;
372 372
373 return (void *) db; 373 return (void *)db;
374} 374}
375 375
376/* 376/*
377 * Initialize the database. 377 * Initialize the database.
378 */ 378 */
379static int bsd_init (void *state, struct isdn_ppp_comp_data *data, int unit, int debug) 379static int bsd_init(void *state, struct isdn_ppp_comp_data *data, int unit, int debug)
380{ 380{
381 struct bsd_db *db = state; 381 struct bsd_db *db = state;
382 int indx; 382 int indx;
383 int decomp; 383 int decomp;
384 384
385 if(!state || !data) { 385 if (!state || !data) {
386 printk(KERN_ERR "isdn_bsd_init: [%d] ERR, state %lx data %lx\n",unit,(long)state,(long)data); 386 printk(KERN_ERR "isdn_bsd_init: [%d] ERR, state %lx data %lx\n", unit, (long)state, (long)data);
387 return 0; 387 return 0;
388 } 388 }
389 389
390 decomp = db->xmit ? 0 : 1; 390 decomp = db->xmit ? 0 : 1;
391 391
392 if (data->optlen != 1 || data->num != CI_BSD_COMPRESS 392 if (data->optlen != 1 || data->num != CI_BSD_COMPRESS
393 || (BSD_VERSION(data->options[0]) != BSD_CURRENT_VERSION) 393 || (BSD_VERSION(data->options[0]) != BSD_CURRENT_VERSION)
394 || (BSD_NBITS(data->options[0]) != db->maxbits) 394 || (BSD_NBITS(data->options[0]) != db->maxbits)
395 || (decomp && db->lens == NULL)) { 395 || (decomp && db->lens == NULL)) {
396 printk(KERN_ERR "isdn_bsd: %d %d %d %d %lx\n",data->optlen,data->num,data->options[0],decomp,(unsigned long)db->lens); 396 printk(KERN_ERR "isdn_bsd: %d %d %d %d %lx\n", data->optlen, data->num, data->options[0], decomp, (unsigned long)db->lens);
397 return 0; 397 return 0;
398 } 398 }
399 399
400 if (decomp) 400 if (decomp)
401 for(indx=LAST;indx>=0;indx--) 401 for (indx = LAST; indx >= 0; indx--)
402 db->lens[indx] = 1; 402 db->lens[indx] = 1;
403 403
404 indx = db->hsize; 404 indx = db->hsize;
@@ -411,9 +411,9 @@ static int bsd_init (void *state, struct isdn_ppp_comp_data *data, int unit, int
411 db->mru = 0; 411 db->mru = 0;
412 412
413 db->debug = 1; 413 db->debug = 1;
414 414
415 bsd_reset(db,0,0,NULL,0,NULL); 415 bsd_reset(db, 0, 0, NULL, 0, NULL);
416 416
417 return 1; 417 return 1;
418} 418}
419 419
@@ -421,37 +421,37 @@ static int bsd_init (void *state, struct isdn_ppp_comp_data *data, int unit, int
421 * Obtain pointers to the various structures in the compression tables 421 * Obtain pointers to the various structures in the compression tables
422 */ 422 */
423 423
424#define dict_ptrx(p,idx) &(p->dict[idx]) 424#define dict_ptrx(p, idx) &(p->dict[idx])
425#define lens_ptrx(p,idx) &(p->lens[idx]) 425#define lens_ptrx(p, idx) &(p->lens[idx])
426 426
427#ifdef DEBUG 427#ifdef DEBUG
428static unsigned short *lens_ptr(struct bsd_db *db, int idx) 428static unsigned short *lens_ptr(struct bsd_db *db, int idx)
429{ 429{
430 if ((unsigned int) idx > (unsigned int) db->maxmaxcode) { 430 if ((unsigned int) idx > (unsigned int) db->maxmaxcode) {
431 printk (KERN_DEBUG "<9>ppp: lens_ptr(%d) > max\n", idx); 431 printk(KERN_DEBUG "<9>ppp: lens_ptr(%d) > max\n", idx);
432 idx = 0; 432 idx = 0;
433 } 433 }
434 return lens_ptrx (db, idx); 434 return lens_ptrx(db, idx);
435} 435}
436 436
437static struct bsd_dict *dict_ptr(struct bsd_db *db, int idx) 437static struct bsd_dict *dict_ptr(struct bsd_db *db, int idx)
438{ 438{
439 if ((unsigned int) idx >= (unsigned int) db->hsize) { 439 if ((unsigned int) idx >= (unsigned int) db->hsize) {
440 printk (KERN_DEBUG "<9>ppp: dict_ptr(%d) > max\n", idx); 440 printk(KERN_DEBUG "<9>ppp: dict_ptr(%d) > max\n", idx);
441 idx = 0; 441 idx = 0;
442 } 442 }
443 return dict_ptrx (db, idx); 443 return dict_ptrx(db, idx);
444} 444}
445 445
446#else 446#else
447#define lens_ptr(db,idx) lens_ptrx(db,idx) 447#define lens_ptr(db, idx) lens_ptrx(db, idx)
448#define dict_ptr(db,idx) dict_ptrx(db,idx) 448#define dict_ptr(db, idx) dict_ptrx(db, idx)
449#endif 449#endif
450 450
451/* 451/*
452 * compress a packet 452 * compress a packet
453 */ 453 */
454static int bsd_compress (void *state, struct sk_buff *skb_in, struct sk_buff *skb_out,int proto) 454static int bsd_compress(void *state, struct sk_buff *skb_in, struct sk_buff *skb_out, int proto)
455{ 455{
456 struct bsd_db *db; 456 struct bsd_db *db;
457 int hshift; 457 int hshift;
@@ -463,31 +463,31 @@ static int bsd_compress (void *state, struct sk_buff *skb_in, struct sk_buff *sk
463 unsigned long fcode; 463 unsigned long fcode;
464 struct bsd_dict *dictp; 464 struct bsd_dict *dictp;
465 unsigned char c; 465 unsigned char c;
466 int hval,disp,ilen,mxcode; 466 int hval, disp, ilen, mxcode;
467 unsigned char *rptr = skb_in->data; 467 unsigned char *rptr = skb_in->data;
468 int isize = skb_in->len; 468 int isize = skb_in->len;
469 469
470#define OUTPUT(ent) \ 470#define OUTPUT(ent) \
471 { \ 471 { \
472 bitno -= n_bits; \ 472 bitno -= n_bits; \
473 accm |= ((ent) << bitno); \ 473 accm |= ((ent) << bitno); \
474 do { \ 474 do { \
475 if(skb_out && skb_tailroom(skb_out) > 0) \ 475 if (skb_out && skb_tailroom(skb_out) > 0) \
476 *(skb_put(skb_out,1)) = (unsigned char) (accm>>24); \ 476 *(skb_put(skb_out, 1)) = (unsigned char)(accm >> 24); \
477 accm <<= 8; \ 477 accm <<= 8; \
478 bitno += 8; \ 478 bitno += 8; \
479 } while (bitno <= 24); \ 479 } while (bitno <= 24); \
480 } 480 }
481 481
482 /* 482 /*
483 * If the protocol is not in the range we're interested in, 483 * If the protocol is not in the range we're interested in,
484 * just return without compressing the packet. If it is, 484 * just return without compressing the packet. If it is,
485 * the protocol becomes the first byte to compress. 485 * the protocol becomes the first byte to compress.
486 */ 486 */
487 printk(KERN_DEBUG "bsd_compress called with %x\n",proto); 487 printk(KERN_DEBUG "bsd_compress called with %x\n", proto);
488 488
489 ent = proto; 489 ent = proto;
490 if (proto < 0x21 || proto > 0xf9 || !(proto & 0x1) ) 490 if (proto < 0x21 || proto > 0xf9 || !(proto & 0x1))
491 return 0; 491 return 0;
492 492
493 db = (struct bsd_db *) state; 493 db = (struct bsd_db *) state;
@@ -496,25 +496,25 @@ static int bsd_compress (void *state, struct sk_buff *skb_in, struct sk_buff *sk
496 n_bits = db->n_bits; 496 n_bits = db->n_bits;
497 bitno = 32; 497 bitno = 32;
498 accm = 0; 498 accm = 0;
499 mxcode = MAXCODE (n_bits); 499 mxcode = MAXCODE(n_bits);
500 500
501 /* This is the PPP header information */ 501 /* This is the PPP header information */
502 if(skb_out && skb_tailroom(skb_out) >= 2) { 502 if (skb_out && skb_tailroom(skb_out) >= 2) {
503 char *v = skb_put(skb_out,2); 503 char *v = skb_put(skb_out, 2);
504 /* we only push our own data on the header, 504 /* we only push our own data on the header,
505 AC,PC and protos is pushed by caller */ 505 AC,PC and protos is pushed by caller */
506 v[0] = db->seqno >> 8; 506 v[0] = db->seqno >> 8;
507 v[1] = db->seqno; 507 v[1] = db->seqno;
508 } 508 }
509 509
510 ilen = ++isize; /* This is off by one, but that is what is in draft! */ 510 ilen = ++isize; /* This is off by one, but that is what is in draft! */
511 511
512 while (--ilen > 0) { 512 while (--ilen > 0) {
513 c = *rptr++; 513 c = *rptr++;
514 fcode = BSD_KEY (ent, c); 514 fcode = BSD_KEY(ent, c);
515 hval = BSD_HASH (ent, c, hshift); 515 hval = BSD_HASH(ent, c, hshift);
516 dictp = dict_ptr (db, hval); 516 dictp = dict_ptr(db, hval);
517 517
518 /* Validate and then check the entry. */ 518 /* Validate and then check the entry. */
519 if (dictp->codem1 >= max_ent) 519 if (dictp->codem1 >= max_ent)
520 goto nomatch; 520 goto nomatch;
@@ -523,7 +523,7 @@ static int bsd_compress (void *state, struct sk_buff *skb_in, struct sk_buff *sk
523 ent = dictp->codem1 + 1; 523 ent = dictp->codem1 + 1;
524 continue; /* found (prefix,suffix) */ 524 continue; /* found (prefix,suffix) */
525 } 525 }
526 526
527 /* continue probing until a match or invalid entry */ 527 /* continue probing until a match or invalid entry */
528 disp = (hval == 0) ? 1 : hval; 528 disp = (hval == 0) ? 1 : hval;
529 529
@@ -531,17 +531,17 @@ static int bsd_compress (void *state, struct sk_buff *skb_in, struct sk_buff *sk
531 hval += disp; 531 hval += disp;
532 if (hval >= db->hsize) 532 if (hval >= db->hsize)
533 hval -= db->hsize; 533 hval -= db->hsize;
534 dictp = dict_ptr (db, hval); 534 dictp = dict_ptr(db, hval);
535 if (dictp->codem1 >= max_ent) 535 if (dictp->codem1 >= max_ent)
536 goto nomatch; 536 goto nomatch;
537 } while (dictp->fcode != fcode); 537 } while (dictp->fcode != fcode);
538 538
539 ent = dictp->codem1 + 1; /* finally found (prefix,suffix) */ 539 ent = dictp->codem1 + 1; /* finally found (prefix,suffix) */
540 continue; 540 continue;
541 541
542nomatch: 542 nomatch:
543 OUTPUT(ent); /* output the prefix */ 543 OUTPUT(ent); /* output the prefix */
544 544
545 /* code -> hashtable */ 545 /* code -> hashtable */
546 if (max_ent < db->maxmaxcode) { 546 if (max_ent < db->maxmaxcode) {
547 struct bsd_dict *dictp2; 547 struct bsd_dict *dictp2;
@@ -551,16 +551,16 @@ nomatch:
551 /* expand code size if needed */ 551 /* expand code size if needed */
552 if (max_ent >= mxcode) { 552 if (max_ent >= mxcode) {
553 db->n_bits = ++n_bits; 553 db->n_bits = ++n_bits;
554 mxcode = MAXCODE (n_bits); 554 mxcode = MAXCODE(n_bits);
555 } 555 }
556 556
557 /* 557 /*
558 * Invalidate old hash table entry using 558 * Invalidate old hash table entry using
559 * this code, and then take it over. 559 * this code, and then take it over.
560 */ 560 */
561 dictp2 = dict_ptr (db, max_ent + 1); 561 dictp2 = dict_ptr(db, max_ent + 1);
562 indx = dictp2->cptr; 562 indx = dictp2->cptr;
563 dictp3 = dict_ptr (db, indx); 563 dictp3 = dict_ptr(db, indx);
564 564
565 if (dictp3->codem1 == max_ent) 565 if (dictp3->codem1 == max_ent)
566 dictp3->codem1 = BADCODEM1; 566 dictp3->codem1 = BADCODEM1;
@@ -571,17 +571,17 @@ nomatch:
571 db->max_ent = ++max_ent; 571 db->max_ent = ++max_ent;
572 572
573 if (db->lens) { 573 if (db->lens) {
574 unsigned short *len1 = lens_ptr (db, max_ent); 574 unsigned short *len1 = lens_ptr(db, max_ent);
575 unsigned short *len2 = lens_ptr (db, ent); 575 unsigned short *len2 = lens_ptr(db, ent);
576 *len1 = *len2 + 1; 576 *len1 = *len2 + 1;
577 } 577 }
578 } 578 }
579 ent = c; 579 ent = c;
580 } 580 }
581 581
582 OUTPUT(ent); /* output the last code */ 582 OUTPUT(ent); /* output the last code */
583 583
584 if(skb_out) 584 if (skb_out)
585 db->bytes_out += skb_out->len; /* Do not count bytes from here */ 585 db->bytes_out += skb_out->len; /* Do not count bytes from here */
586 db->uncomp_bytes += isize; 586 db->uncomp_bytes += isize;
587 db->in_count += isize; 587 db->in_count += isize;
@@ -596,15 +596,15 @@ nomatch:
596 */ 596 */
597 597
598 if (bsd_check(db)) 598 if (bsd_check(db))
599 OUTPUT (CLEAR); 599 OUTPUT(CLEAR);
600 600
601 /* 601 /*
602 * Pad dribble bits of last code with ones. 602 * Pad dribble bits of last code with ones.
603 * Do not emit a completely useless byte of ones. 603 * Do not emit a completely useless byte of ones.
604 */ 604 */
605 if (bitno < 32 && skb_out && skb_tailroom(skb_out) > 0) 605 if (bitno < 32 && skb_out && skb_tailroom(skb_out) > 0)
606 *(skb_put(skb_out,1)) = (unsigned char) ((accm | (0xff << (bitno-8))) >> 24); 606 *(skb_put(skb_out, 1)) = (unsigned char)((accm | (0xff << (bitno - 8))) >> 24);
607 607
608 /* 608 /*
609 * Increase code size if we would have without the packet 609 * Increase code size if we would have without the packet
610 * boundary because the decompressor will do so. 610 * boundary because the decompressor will do so.
@@ -613,7 +613,7 @@ nomatch:
613 db->n_bits++; 613 db->n_bits++;
614 614
615 /* If output length is too large then this is an incompressible frame. */ 615 /* If output length is too large then this is an incompressible frame. */
616 if (!skb_out || (skb_out && skb_out->len >= skb_in->len) ) { 616 if (!skb_out || (skb_out && skb_out->len >= skb_in->len)) {
617 ++db->incomp_count; 617 ++db->incomp_count;
618 db->incomp_bytes += isize; 618 db->incomp_bytes += isize;
619 return 0; 619 return 0;
@@ -631,16 +631,16 @@ nomatch:
631 * Update the "BSD Compress" dictionary on the receiver for 631 * Update the "BSD Compress" dictionary on the receiver for
632 * incompressible data by pretending to compress the incoming data. 632 * incompressible data by pretending to compress the incoming data.
633 */ 633 */
634static void bsd_incomp (void *state, struct sk_buff *skb_in,int proto) 634static void bsd_incomp(void *state, struct sk_buff *skb_in, int proto)
635{ 635{
636 bsd_compress (state, skb_in, NULL, proto); 636 bsd_compress(state, skb_in, NULL, proto);
637} 637}
638 638
639/* 639/*
640 * Decompress "BSD Compress". 640 * Decompress "BSD Compress".
641 */ 641 */
642static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *skb_out, 642static int bsd_decompress(void *state, struct sk_buff *skb_in, struct sk_buff *skb_out,
643 struct isdn_ppp_resetparams *rsparm) 643 struct isdn_ppp_resetparams *rsparm)
644{ 644{
645 struct bsd_db *db; 645 struct bsd_db *db;
646 unsigned int max_ent; 646 unsigned int max_ent;
@@ -653,7 +653,7 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
653 unsigned int incode; 653 unsigned int incode;
654 unsigned int oldcode; 654 unsigned int oldcode;
655 unsigned int finchar; 655 unsigned int finchar;
656 unsigned char *p,*ibuf; 656 unsigned char *p, *ibuf;
657 int ilen; 657 int ilen;
658 int codelen; 658 int codelen;
659 int extra; 659 int extra;
@@ -667,20 +667,20 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
667 667
668 printk(KERN_DEBUG "bsd_decompress called\n"); 668 printk(KERN_DEBUG "bsd_decompress called\n");
669 669
670 if(!skb_in || !skb_out) { 670 if (!skb_in || !skb_out) {
671 printk(KERN_ERR "bsd_decompress called with NULL parameter\n"); 671 printk(KERN_ERR "bsd_decompress called with NULL parameter\n");
672 return DECOMP_ERROR; 672 return DECOMP_ERROR;
673 } 673 }
674 674
675 /* 675 /*
676 * Get the sequence number. 676 * Get the sequence number.
677 */ 677 */
678 if( (p = skb_pull(skb_in,2)) == NULL) { 678 if ((p = skb_pull(skb_in, 2)) == NULL) {
679 return DECOMP_ERROR; 679 return DECOMP_ERROR;
680 } 680 }
681 p-=2; 681 p -= 2;
682 seq = (p[0] << 8) + p[1]; 682 seq = (p[0] << 8) + p[1];
683 ilen = skb_in->len; 683 ilen = skb_in->len;
684 ibuf = skb_in->data; 684 ibuf = skb_in->data;
685 685
686 /* 686 /*
@@ -690,7 +690,7 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
690 if (seq != db->seqno) { 690 if (seq != db->seqno) {
691 if (db->debug) { 691 if (db->debug) {
692 printk(KERN_DEBUG "bsd_decomp%d: bad sequence # %d, expected %d\n", 692 printk(KERN_DEBUG "bsd_decomp%d: bad sequence # %d, expected %d\n",
693 db->unit, seq, db->seqno - 1); 693 db->unit, seq, db->seqno - 1);
694 } 694 }
695 return DECOMP_ERROR; 695 return DECOMP_ERROR;
696 } 696 }
@@ -698,11 +698,11 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
698 ++db->seqno; 698 ++db->seqno;
699 db->bytes_out += ilen; 699 db->bytes_out += ilen;
700 700
701 if(skb_tailroom(skb_out) > 0) 701 if (skb_tailroom(skb_out) > 0)
702 *(skb_put(skb_out,1)) = 0; 702 *(skb_put(skb_out, 1)) = 0;
703 else 703 else
704 return DECOMP_ERR_NOMEM; 704 return DECOMP_ERR_NOMEM;
705 705
706 oldcode = CLEAR; 706 oldcode = CLEAR;
707 707
708 /* 708 /*
@@ -734,7 +734,7 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
734 /* 734 /*
735 * The dictionary must only be cleared at the end of a packet. 735 * The dictionary must only be cleared at the end of a packet.
736 */ 736 */
737 737
738 if (incode == CLEAR) { 738 if (incode == CLEAR) {
739 if (ilen > 0) { 739 if (ilen > 0) {
740 if (db->debug) 740 if (db->debug)
@@ -746,16 +746,16 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
746 } 746 }
747 747
748 if ((incode > max_ent + 2) || (incode > db->maxmaxcode) 748 if ((incode > max_ent + 2) || (incode > db->maxmaxcode)
749 || (incode > max_ent && oldcode == CLEAR)) { 749 || (incode > max_ent && oldcode == CLEAR)) {
750 if (db->debug) { 750 if (db->debug) {
751 printk(KERN_DEBUG "bsd_decomp%d: bad code 0x%x oldcode=0x%x ", 751 printk(KERN_DEBUG "bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
752 db->unit, incode, oldcode); 752 db->unit, incode, oldcode);
753 printk(KERN_DEBUG "max_ent=0x%x skb->Len=%d seqno=%d\n", 753 printk(KERN_DEBUG "max_ent=0x%x skb->Len=%d seqno=%d\n",
754 max_ent, skb_out->len, db->seqno); 754 max_ent, skb_out->len, db->seqno);
755 } 755 }
756 return DECOMP_FATALERROR; /* probably a bug */ 756 return DECOMP_FATALERROR; /* probably a bug */
757 } 757 }
758 758
759 /* Special case for KwKwK string. */ 759 /* Special case for KwKwK string. */
760 if (incode > max_ent) { 760 if (incode > max_ent) {
761 finchar = oldcode; 761 finchar = oldcode;
@@ -765,13 +765,13 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
765 extra = 0; 765 extra = 0;
766 } 766 }
767 767
768 codelen = *(lens_ptr (db, finchar)); 768 codelen = *(lens_ptr(db, finchar));
769 if( skb_tailroom(skb_out) < codelen + extra) { 769 if (skb_tailroom(skb_out) < codelen + extra) {
770 if (db->debug) { 770 if (db->debug) {
771 printk(KERN_DEBUG "bsd_decomp%d: ran out of mru\n", db->unit); 771 printk(KERN_DEBUG "bsd_decomp%d: ran out of mru\n", db->unit);
772#ifdef DEBUG 772#ifdef DEBUG
773 printk(KERN_DEBUG " len=%d, finchar=0x%x, codelen=%d,skblen=%d\n", 773 printk(KERN_DEBUG " len=%d, finchar=0x%x, codelen=%d,skblen=%d\n",
774 ilen, finchar, codelen, skb_out->len); 774 ilen, finchar, codelen, skb_out->len);
775#endif 775#endif
776 } 776 }
777 return DECOMP_FATALERROR; 777 return DECOMP_FATALERROR;
@@ -781,21 +781,21 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
781 * Decode this code and install it in the decompressed buffer. 781 * Decode this code and install it in the decompressed buffer.
782 */ 782 */
783 783
784 p = skb_put(skb_out,codelen); 784 p = skb_put(skb_out, codelen);
785 p += codelen; 785 p += codelen;
786 while (finchar > LAST) { 786 while (finchar > LAST) {
787 struct bsd_dict *dictp2 = dict_ptr (db, finchar); 787 struct bsd_dict *dictp2 = dict_ptr(db, finchar);
788 788
789 dictp = dict_ptr (db, dictp2->cptr); 789 dictp = dict_ptr(db, dictp2->cptr);
790 790
791#ifdef DEBUG 791#ifdef DEBUG
792 if (--codelen <= 0 || dictp->codem1 != finchar-1) { 792 if (--codelen <= 0 || dictp->codem1 != finchar - 1) {
793 if (codelen <= 0) { 793 if (codelen <= 0) {
794 printk(KERN_ERR "bsd_decomp%d: fell off end of chain ", db->unit); 794 printk(KERN_ERR "bsd_decomp%d: fell off end of chain ", db->unit);
795 printk(KERN_ERR "0x%x at 0x%x by 0x%x, max_ent=0x%x\n", incode, finchar, dictp2->cptr, max_ent); 795 printk(KERN_ERR "0x%x at 0x%x by 0x%x, max_ent=0x%x\n", incode, finchar, dictp2->cptr, max_ent);
796 } else { 796 } else {
797 if (dictp->codem1 != finchar-1) { 797 if (dictp->codem1 != finchar - 1) {
798 printk(KERN_ERR "bsd_decomp%d: bad code chain 0x%x finchar=0x%x ",db->unit, incode, finchar); 798 printk(KERN_ERR "bsd_decomp%d: bad code chain 0x%x finchar=0x%x ", db->unit, incode, finchar);
799 printk(KERN_ERR "oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode, dictp2->cptr, dictp->codem1); 799 printk(KERN_ERR "oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode, dictp2->cptr, dictp->codem1);
800 } 800 }
801 } 801 }
@@ -810,15 +810,15 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
810 } 810 }
811 } 811 }
812 *--p = finchar; 812 *--p = finchar;
813 813
814#ifdef DEBUG 814#ifdef DEBUG
815 if (--codelen != 0) 815 if (--codelen != 0)
816 printk(KERN_ERR "bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n", db->unit, codelen, incode, max_ent); 816 printk(KERN_ERR "bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n", db->unit, codelen, incode, max_ent);
817#endif 817#endif
818 818
819 if (extra) /* the KwKwK case again */ 819 if (extra) /* the KwKwK case again */
820 *(skb_put(skb_out,1)) = finchar; 820 *(skb_put(skb_out, 1)) = finchar;
821 821
822 /* 822 /*
823 * If not first code in a packet, and 823 * If not first code in a packet, and
824 * if not out of code space, then allocate a new code. 824 * if not out of code space, then allocate a new code.
@@ -828,14 +828,14 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
828 */ 828 */
829 if (oldcode != CLEAR && max_ent < db->maxmaxcode) { 829 if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
830 struct bsd_dict *dictp2, *dictp3; 830 struct bsd_dict *dictp2, *dictp3;
831 u16 *lens1, *lens2; 831 u16 *lens1, *lens2;
832 unsigned long fcode; 832 unsigned long fcode;
833 int hval, disp, indx; 833 int hval, disp, indx;
834 834
835 fcode = BSD_KEY(oldcode,finchar); 835 fcode = BSD_KEY(oldcode, finchar);
836 hval = BSD_HASH(oldcode,finchar,db->hshift); 836 hval = BSD_HASH(oldcode, finchar, db->hshift);
837 dictp = dict_ptr (db, hval); 837 dictp = dict_ptr(db, hval);
838 838
839 /* look for a free hash table entry */ 839 /* look for a free hash table entry */
840 if (dictp->codem1 < max_ent) { 840 if (dictp->codem1 < max_ent) {
841 disp = (hval == 0) ? 1 : hval; 841 disp = (hval == 0) ? 1 : hval;
@@ -843,18 +843,18 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
843 hval += disp; 843 hval += disp;
844 if (hval >= db->hsize) 844 if (hval >= db->hsize)
845 hval -= db->hsize; 845 hval -= db->hsize;
846 dictp = dict_ptr (db, hval); 846 dictp = dict_ptr(db, hval);
847 } while (dictp->codem1 < max_ent); 847 } while (dictp->codem1 < max_ent);
848 } 848 }
849 849
850 /* 850 /*
851 * Invalidate previous hash table entry 851 * Invalidate previous hash table entry
852 * assigned this code, and then take it over 852 * assigned this code, and then take it over
853 */ 853 */
854 854
855 dictp2 = dict_ptr (db, max_ent + 1); 855 dictp2 = dict_ptr(db, max_ent + 1);
856 indx = dictp2->cptr; 856 indx = dictp2->cptr;
857 dictp3 = dict_ptr (db, indx); 857 dictp3 = dict_ptr(db, indx);
858 858
859 if (dictp3->codem1 == max_ent) 859 if (dictp3->codem1 == max_ent)
860 dictp3->codem1 = BADCODEM1; 860 dictp3->codem1 = BADCODEM1;
@@ -865,10 +865,10 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
865 db->max_ent = ++max_ent; 865 db->max_ent = ++max_ent;
866 866
867 /* Update the length of this string. */ 867 /* Update the length of this string. */
868 lens1 = lens_ptr (db, max_ent); 868 lens1 = lens_ptr(db, max_ent);
869 lens2 = lens_ptr (db, oldcode); 869 lens2 = lens_ptr(db, oldcode);
870 *lens1 = *lens2 + 1; 870 *lens1 = *lens2 + 1;
871 871
872 /* Expand code size if needed. */ 872 /* Expand code size if needed. */
873 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) { 873 if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
874 db->n_bits = ++n_bits; 874 db->n_bits = ++n_bits;
@@ -886,7 +886,7 @@ static int bsd_decompress (void *state, struct sk_buff *skb_in, struct sk_buff *
886 if (bsd_check(db)) { 886 if (bsd_check(db)) {
887 if (db->debug) 887 if (db->debug)
888 printk(KERN_DEBUG "bsd_decomp%d: peer should have cleared dictionary on %d\n", 888 printk(KERN_DEBUG "bsd_decomp%d: peer should have cleared dictionary on %d\n",
889 db->unit, db->seqno - 1); 889 db->unit, db->seqno - 1);
890 } 890 }
891 return skb_out->len; 891 return skb_out->len;
892} 892}
@@ -914,15 +914,15 @@ static struct isdn_ppp_compressor ippp_bsd_compress = {
914 914
915static int __init isdn_bsdcomp_init(void) 915static int __init isdn_bsdcomp_init(void)
916{ 916{
917 int answer = isdn_ppp_register_compressor (&ippp_bsd_compress); 917 int answer = isdn_ppp_register_compressor(&ippp_bsd_compress);
918 if (answer == 0) 918 if (answer == 0)
919 printk (KERN_INFO "PPP BSD Compression module registered\n"); 919 printk(KERN_INFO "PPP BSD Compression module registered\n");
920 return answer; 920 return answer;
921} 921}
922 922
923static void __exit isdn_bsdcomp_exit(void) 923static void __exit isdn_bsdcomp_exit(void)
924{ 924{
925 isdn_ppp_unregister_compressor (&ippp_bsd_compress); 925 isdn_ppp_unregister_compressor(&ippp_bsd_compress);
926} 926}
927 927
928module_init(isdn_bsdcomp_init); 928module_init(isdn_bsdcomp_init);