Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ISDN: Clean up isdnhdlc code

Clean up isdnhdlc to meet current code standard.
Remove hint to already removed bit reversal table.

Signed-off-by: Karsten Keil <keil@b1-systems.de>

+231 -203
+194 -172
drivers/isdn/i4l/isdnhdlc.c
··· 1 1 /* 2 2 * isdnhdlc.c -- General purpose ISDN HDLC decoder. 3 3 * 4 - *Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de> 5 - * 2001 Frode Isaksen <fisaksen@bewan.com> 6 - * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> 4 + * Copyright (C) 5 + * 2002 Wolfgang Mües <wolfgang@iksw-muees.de> 6 + * 2001 Frode Isaksen <fisaksen@bewan.com> 7 + * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> 7 8 * 8 - * This program is free software; you can redistribute it and/or modify 9 - * it under the terms of the GNU General Public License as published by 10 - * the Free Software Foundation; either version 2 of the License, or 11 - * (at your option) any later version. 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License as published by 11 + * the Free Software Foundation; either version 2 of the License, or 12 + * (at your option) any later version. 12 13 * 13 - * This program is distributed in the hope that it will be useful, 14 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 - * GNU General Public License for more details. 14 + * This program is distributed in the hope that it will be useful, 15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 + * GNU General Public License for more details. 17 18 * 18 - * You should have received a copy of the GNU General Public License 19 - * along with this program; if not, write to the Free Software 20 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 + * You should have received a copy of the GNU General Public License 20 + * along with this program; if not, write to the Free Software 21 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 21 22 */ 22 23 23 24 #include <linux/module.h> ··· 37 36 /*-------------------------------------------------------------------*/ 38 37 39 38 enum { 40 - HDLC_FAST_IDLE,HDLC_GET_FLAG_B0,HDLC_GETFLAG_B1A6,HDLC_GETFLAG_B7, 41 - HDLC_GET_DATA,HDLC_FAST_FLAG 39 + HDLC_FAST_IDLE, HDLC_GET_FLAG_B0, HDLC_GETFLAG_B1A6, HDLC_GETFLAG_B7, 40 + HDLC_GET_DATA, HDLC_FAST_FLAG 42 41 }; 43 42 44 43 enum { 45 - HDLC_SEND_DATA,HDLC_SEND_CRC1,HDLC_SEND_FAST_FLAG, 46 - HDLC_SEND_FIRST_FLAG,HDLC_SEND_CRC2,HDLC_SEND_CLOSING_FLAG, 47 - HDLC_SEND_IDLE1,HDLC_SEND_FAST_IDLE,HDLC_SENDFLAG_B0, 48 - HDLC_SENDFLAG_B1A6,HDLC_SENDFLAG_B7,STOPPED 44 + HDLC_SEND_DATA, HDLC_SEND_CRC1, HDLC_SEND_FAST_FLAG, 45 + HDLC_SEND_FIRST_FLAG, HDLC_SEND_CRC2, HDLC_SEND_CLOSING_FLAG, 46 + HDLC_SEND_IDLE1, HDLC_SEND_FAST_IDLE, HDLC_SENDFLAG_B0, 47 + HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, STOPPED 49 48 }; 50 49 51 - void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56) 50 + void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56) 52 51 { 53 - hdlc->bit_shift = 0; 52 + hdlc->bit_shift = 0; 54 53 hdlc->hdlc_bits1 = 0; 55 54 hdlc->data_bits = 0; 56 55 hdlc->ffbit_shift = 0; ··· 64 63 hdlc->ffvalue = 0; 65 64 hdlc->dstpos = 0; 66 65 } 66 + EXPORT_SYMBOL(isdnhdlc_out_init); 67 67 68 - void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc, int is_d_channel, int do_adapt56) 68 + void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel, 69 + int do_adapt56) 69 70 { 70 - hdlc->bit_shift = 0; 71 + hdlc->bit_shift = 0; 71 72 hdlc->hdlc_bits1 = 0; 72 73 hdlc->data_bits = 0; 73 74 hdlc->ffbit_shift = 0; ··· 86 83 } 87 84 hdlc->cbin = 0x7e; 88 85 hdlc->bit_shift = 0; 89 - if(do_adapt56){ 86 + if (do_adapt56) { 90 87 hdlc->do_adapt56 = 1; 91 88 hdlc->data_bits = 0; 92 89 hdlc->state = HDLC_SENDFLAG_B0; ··· 95 92 hdlc->data_bits = 8; 96 93 } 97 94 hdlc->shift_reg = 0; 95 + } 96 + EXPORT_SYMBOL(isdnhdlc_rcv_init); 97 + 98 + static int 99 + check_frame(struct isdnhdlc_vars *hdlc) 100 + { 101 + int status; 102 + 103 + if (hdlc->dstpos < 2) /* too small - framing error */ 104 + status = -HDLC_FRAMING_ERROR; 105 + else if (hdlc->crc != 0xf0b8) /* crc error */ 106 + status = -HDLC_CRC_ERROR; 107 + else { 108 + /* remove CRC */ 109 + hdlc->dstpos -= 2; 110 + /* good frame */ 111 + status = hdlc->dstpos; 112 + } 113 + return status; 98 114 } 99 115 100 116 /* ··· 143 121 returns - number of decoded bytes in the destination buffer and status 144 122 flag. 145 123 */ 146 - int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, 147 - int slen, int *count, unsigned char *dst, int dsize) 124 + int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen, 125 + int *count, u8 *dst, int dsize) 148 126 { 149 - int status=0; 127 + int status = 0; 150 128 151 - static const unsigned char fast_flag[]={ 152 - 0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f 129 + static const unsigned char fast_flag[] = { 130 + 0x00, 0x00, 0x00, 0x20, 0x30, 0x38, 0x3c, 0x3e, 0x3f 153 131 }; 154 132 155 - static const unsigned char fast_flag_value[]={ 156 - 0x00,0x7e,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f 133 + static const unsigned char fast_flag_value[] = { 134 + 0x00, 0x7e, 0xfc, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3f 157 135 }; 158 136 159 - static const unsigned char fast_abort[]={ 160 - 0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff 137 + static const unsigned char fast_abort[] = { 138 + 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff 161 139 }; 140 + 141 + #define handle_fast_flag(h) \ 142 + do {\ 143 + if (h->cbin == fast_flag[h->bit_shift]) {\ 144 + h->ffvalue = fast_flag_value[h->bit_shift];\ 145 + h->state = HDLC_FAST_FLAG;\ 146 + h->ffbit_shift = h->bit_shift;\ 147 + h->bit_shift = 1;\ 148 + } else {\ 149 + h->state = HDLC_GET_DATA;\ 150 + h->data_received = 0;\ 151 + } \ 152 + } while (0) 153 + 154 + #define handle_abort(h) \ 155 + do {\ 156 + h->shift_reg = fast_abort[h->ffbit_shift - 1];\ 157 + h->hdlc_bits1 = h->ffbit_shift - 2;\ 158 + if (h->hdlc_bits1 < 0)\ 159 + h->hdlc_bits1 = 0;\ 160 + h->data_bits = h->ffbit_shift - 1;\ 161 + h->state = HDLC_GET_DATA;\ 162 + h->data_received = 0;\ 163 + } while (0) 162 164 163 165 *count = slen; 164 166 165 - while(slen > 0){ 166 - if(hdlc->bit_shift==0){ 167 + while (slen > 0) { 168 + if (hdlc->bit_shift == 0) { 167 169 hdlc->cbin = *src++; 168 170 slen--; 169 171 hdlc->bit_shift = 8; 170 - if(hdlc->do_adapt56){ 171 - hdlc->bit_shift --; 172 - } 172 + if (hdlc->do_adapt56) 173 + hdlc->bit_shift--; 173 174 } 174 175 175 - switch(hdlc->state){ 176 + switch (hdlc->state) { 176 177 case STOPPED: 177 178 return 0; 178 179 case HDLC_FAST_IDLE: 179 - if(hdlc->cbin == 0xff){ 180 + if (hdlc->cbin == 0xff) { 180 181 hdlc->bit_shift = 0; 181 182 break; 182 183 } ··· 208 163 hdlc->bit_shift = 8; 209 164 break; 210 165 case HDLC_GET_FLAG_B0: 211 - if(!(hdlc->cbin & 0x80)) { 166 + if (!(hdlc->cbin & 0x80)) { 212 167 hdlc->state = HDLC_GETFLAG_B1A6; 213 168 hdlc->hdlc_bits1 = 0; 214 169 } else { 215 - if(!hdlc->do_adapt56){ 216 - if(++hdlc->hdlc_bits1 >=8 ) if(hdlc->bit_shift==1) 170 + if ((!hdlc->do_adapt56) && 171 + (++hdlc->hdlc_bits1 >= 8) && 172 + (hdlc->bit_shift == 1)) 217 173 hdlc->state = HDLC_FAST_IDLE; 218 - } 219 174 } 220 - hdlc->cbin<<=1; 221 - hdlc->bit_shift --; 175 + hdlc->cbin <<= 1; 176 + hdlc->bit_shift--; 222 177 break; 223 178 case HDLC_GETFLAG_B1A6: 224 - if(hdlc->cbin & 0x80){ 179 + if (hdlc->cbin & 0x80) { 225 180 hdlc->hdlc_bits1++; 226 - if(hdlc->hdlc_bits1==6){ 181 + if (hdlc->hdlc_bits1 == 6) 227 182 hdlc->state = HDLC_GETFLAG_B7; 228 - } 229 - } else { 183 + } else 230 184 hdlc->hdlc_bits1 = 0; 231 - } 232 - hdlc->cbin<<=1; 233 - hdlc->bit_shift --; 185 + hdlc->cbin <<= 1; 186 + hdlc->bit_shift--; 234 187 break; 235 188 case HDLC_GETFLAG_B7: 236 - if(hdlc->cbin & 0x80) { 189 + if (hdlc->cbin & 0x80) { 237 190 hdlc->state = HDLC_GET_FLAG_B0; 238 191 } else { 239 192 hdlc->state = HDLC_GET_DATA; ··· 241 198 hdlc->data_bits = 0; 242 199 hdlc->data_received = 0; 243 200 } 244 - hdlc->cbin<<=1; 245 - hdlc->bit_shift --; 201 + hdlc->cbin <<= 1; 202 + hdlc->bit_shift--; 246 203 break; 247 204 case HDLC_GET_DATA: 248 - if(hdlc->cbin & 0x80){ 205 + if (hdlc->cbin & 0x80) { 249 206 hdlc->hdlc_bits1++; 250 - switch(hdlc->hdlc_bits1){ 207 + switch (hdlc->hdlc_bits1) { 251 208 case 6: 252 209 break; 253 210 case 7: 254 - if(hdlc->data_received) { 255 - // bad frame 211 + if (hdlc->data_received) 212 + /* bad frame */ 256 213 status = -HDLC_FRAMING_ERROR; 257 - } 258 - if(!hdlc->do_adapt56){ 259 - if(hdlc->cbin==fast_abort[hdlc->bit_shift+1]){ 260 - hdlc->state = HDLC_FAST_IDLE; 261 - hdlc->bit_shift=1; 214 + if (!hdlc->do_adapt56) { 215 + if (hdlc->cbin == fast_abort 216 + [hdlc->bit_shift + 1]) { 217 + hdlc->state = 218 + HDLC_FAST_IDLE; 219 + hdlc->bit_shift = 1; 262 220 break; 263 221 } 264 - } else { 222 + } else 265 223 hdlc->state = HDLC_GET_FLAG_B0; 266 - } 267 224 break; 268 225 default: 269 - hdlc->shift_reg>>=1; 226 + hdlc->shift_reg >>= 1; 270 227 hdlc->shift_reg |= 0x80; 271 228 hdlc->data_bits++; 272 229 break; 273 230 } 274 231 } else { 275 - switch(hdlc->hdlc_bits1){ 232 + switch (hdlc->hdlc_bits1) { 276 233 case 5: 277 234 break; 278 235 case 6: 279 - if(hdlc->data_received){ 280 - if (hdlc->dstpos < 2) { 281 - status = -HDLC_FRAMING_ERROR; 282 - } else if (hdlc->crc != 0xf0b8){ 283 - // crc error 284 - status = -HDLC_CRC_ERROR; 285 - } else { 286 - // remove CRC 287 - hdlc->dstpos -= 2; 288 - // good frame 289 - status = hdlc->dstpos; 290 - } 291 - } 236 + if (hdlc->data_received) 237 + status = check_frame(hdlc); 292 238 hdlc->crc = 0xffff; 293 239 hdlc->shift_reg = 0; 294 240 hdlc->data_bits = 0; 295 - if(!hdlc->do_adapt56){ 296 - if(hdlc->cbin==fast_flag[hdlc->bit_shift]){ 297 - hdlc->ffvalue = fast_flag_value[hdlc->bit_shift]; 298 - hdlc->state = HDLC_FAST_FLAG; 299 - hdlc->ffbit_shift = hdlc->bit_shift; 300 - hdlc->bit_shift = 1; 301 - } else { 302 - hdlc->state = HDLC_GET_DATA; 303 - hdlc->data_received = 0; 304 - } 305 - } else { 241 + if (!hdlc->do_adapt56) 242 + handle_fast_flag(hdlc); 243 + else { 306 244 hdlc->state = HDLC_GET_DATA; 307 245 hdlc->data_received = 0; 308 246 } 309 247 break; 310 248 default: 311 - hdlc->shift_reg>>=1; 249 + hdlc->shift_reg >>= 1; 312 250 hdlc->data_bits++; 313 251 break; 314 252 } ··· 302 278 hdlc->bit_shift--; 303 279 return status; 304 280 } 305 - if(hdlc->data_bits==8){ 281 + if (hdlc->data_bits == 8) { 306 282 hdlc->data_bits = 0; 307 283 hdlc->data_received = 1; 308 - hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg); 284 + hdlc->crc = crc_ccitt_byte(hdlc->crc, 285 + hdlc->shift_reg); 309 286 310 - // good byte received 311 - if (hdlc->dstpos < dsize) { 287 + /* good byte received */ 288 + if (hdlc->dstpos < dsize) 312 289 dst[hdlc->dstpos++] = hdlc->shift_reg; 313 - } else { 314 - // frame too long 290 + else { 291 + /* frame too long */ 315 292 status = -HDLC_LENGTH_ERROR; 316 293 hdlc->dstpos = 0; 317 294 } ··· 321 296 hdlc->bit_shift--; 322 297 break; 323 298 case HDLC_FAST_FLAG: 324 - if(hdlc->cbin==hdlc->ffvalue){ 299 + if (hdlc->cbin == hdlc->ffvalue) { 325 300 hdlc->bit_shift = 0; 326 301 break; 327 302 } else { 328 - if(hdlc->cbin == 0xff){ 303 + if (hdlc->cbin == 0xff) { 329 304 hdlc->state = HDLC_FAST_IDLE; 330 - hdlc->bit_shift=0; 331 - } else if(hdlc->ffbit_shift==8){ 305 + hdlc->bit_shift = 0; 306 + } else if (hdlc->ffbit_shift == 8) { 332 307 hdlc->state = HDLC_GETFLAG_B7; 333 308 break; 334 - } else { 335 - hdlc->shift_reg = fast_abort[hdlc->ffbit_shift-1]; 336 - hdlc->hdlc_bits1 = hdlc->ffbit_shift-2; 337 - if(hdlc->hdlc_bits1<0)hdlc->hdlc_bits1 = 0; 338 - hdlc->data_bits = hdlc->ffbit_shift-1; 339 - hdlc->state = HDLC_GET_DATA; 340 - hdlc->data_received = 0; 341 - } 309 + } else 310 + handle_abort(hdlc); 342 311 } 343 312 break; 344 313 default: ··· 342 323 *count -= slen; 343 324 return 0; 344 325 } 345 - 326 + EXPORT_SYMBOL(isdnhdlc_decode); 346 327 /* 347 328 isdnhdlc_encode - encodes HDLC frames to a transparent bit stream. 348 329 ··· 362 343 dsize - destination buffer size 363 344 returns - number of encoded bytes in the destination buffer 364 345 */ 365 - int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src, 366 - unsigned short slen, int *count, 367 - unsigned char *dst, int dsize) 346 + int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen, 347 + int *count, u8 *dst, int dsize) 368 348 { 369 349 static const unsigned char xfast_flag_value[] = { 370 - 0x7e,0x3f,0x9f,0xcf,0xe7,0xf3,0xf9,0xfc,0x7e 350 + 0x7e, 0x3f, 0x9f, 0xcf, 0xe7, 0xf3, 0xf9, 0xfc, 0x7e 371 351 }; 372 352 373 353 int len = 0; ··· 374 356 *count = slen; 375 357 376 358 while (dsize > 0) { 377 - if(hdlc->bit_shift==0){ 378 - if(slen && !hdlc->do_closing){ 359 + if (hdlc->bit_shift == 0) { 360 + if (slen && !hdlc->do_closing) { 379 361 hdlc->shift_reg = *src++; 380 362 slen--; 381 363 if (slen == 0) 382 - hdlc->do_closing = 1; /* closing sequence, CRC + flag(s) */ 364 + /* closing sequence, CRC + flag(s) */ 365 + hdlc->do_closing = 1; 383 366 hdlc->bit_shift = 8; 384 367 } else { 385 - if(hdlc->state == HDLC_SEND_DATA){ 386 - if(hdlc->data_received){ 368 + if (hdlc->state == HDLC_SEND_DATA) { 369 + if (hdlc->data_received) { 387 370 hdlc->state = HDLC_SEND_CRC1; 388 371 hdlc->crc ^= 0xffff; 389 372 hdlc->bit_shift = 8; 390 - hdlc->shift_reg = hdlc->crc & 0xff; 391 - } else if(!hdlc->do_adapt56){ 392 - hdlc->state = HDLC_SEND_FAST_FLAG; 393 - } else { 394 - hdlc->state = HDLC_SENDFLAG_B0; 395 - } 373 + hdlc->shift_reg = 374 + hdlc->crc & 0xff; 375 + } else if (!hdlc->do_adapt56) 376 + hdlc->state = 377 + HDLC_SEND_FAST_FLAG; 378 + else 379 + hdlc->state = 380 + HDLC_SENDFLAG_B0; 396 381 } 397 382 398 383 } 399 384 } 400 385 401 - switch(hdlc->state){ 386 + switch (hdlc->state) { 402 387 case STOPPED: 403 388 while (dsize--) 404 389 *dst++ = 0xff; ··· 409 388 return dsize; 410 389 case HDLC_SEND_FAST_FLAG: 411 390 hdlc->do_closing = 0; 412 - if(slen == 0){ 391 + if (slen == 0) { 413 392 *dst++ = hdlc->ffvalue; 414 393 len++; 415 394 dsize--; 416 395 break; 417 396 } 418 - if(hdlc->bit_shift==8){ 419 - hdlc->cbin = hdlc->ffvalue>>(8-hdlc->data_bits); 397 + if (hdlc->bit_shift == 8) { 398 + hdlc->cbin = hdlc->ffvalue >> 399 + (8 - hdlc->data_bits); 420 400 hdlc->state = HDLC_SEND_DATA; 421 401 hdlc->crc = 0xffff; 422 402 hdlc->hdlc_bits1 = 0; ··· 435 413 hdlc->cbin <<= 1; 436 414 hdlc->data_bits++; 437 415 hdlc->cbin++; 438 - if(++hdlc->hdlc_bits1 == 6) 416 + if (++hdlc->hdlc_bits1 == 6) 439 417 hdlc->state = HDLC_SENDFLAG_B7; 440 418 break; 441 419 case HDLC_SENDFLAG_B7: 442 420 hdlc->cbin <<= 1; 443 421 hdlc->data_bits++; 444 - if(slen == 0){ 422 + if (slen == 0) { 445 423 hdlc->state = HDLC_SENDFLAG_B0; 446 424 break; 447 425 } 448 - if(hdlc->bit_shift==8){ 426 + if (hdlc->bit_shift == 8) { 449 427 hdlc->state = HDLC_SEND_DATA; 450 428 hdlc->crc = 0xffff; 451 429 hdlc->hdlc_bits1 = 0; ··· 454 432 break; 455 433 case HDLC_SEND_FIRST_FLAG: 456 434 hdlc->data_received = 1; 457 - if(hdlc->data_bits==8){ 435 + if (hdlc->data_bits == 8) { 458 436 hdlc->state = HDLC_SEND_DATA; 459 437 hdlc->crc = 0xffff; 460 438 hdlc->hdlc_bits1 = 0; ··· 462 440 } 463 441 hdlc->cbin <<= 1; 464 442 hdlc->data_bits++; 465 - if(hdlc->shift_reg & 0x01) 443 + if (hdlc->shift_reg & 0x01) 466 444 hdlc->cbin++; 467 445 hdlc->shift_reg >>= 1; 468 446 hdlc->bit_shift--; 469 - if(hdlc->bit_shift==0){ 447 + if (hdlc->bit_shift == 0) { 470 448 hdlc->state = HDLC_SEND_DATA; 471 449 hdlc->crc = 0xffff; 472 450 hdlc->hdlc_bits1 = 0; ··· 475 453 case HDLC_SEND_DATA: 476 454 hdlc->cbin <<= 1; 477 455 hdlc->data_bits++; 478 - if(hdlc->hdlc_bits1 == 5){ 456 + if (hdlc->hdlc_bits1 == 5) { 479 457 hdlc->hdlc_bits1 = 0; 480 458 break; 481 459 } 482 - if(hdlc->bit_shift==8){ 483 - hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg); 484 - } 485 - if(hdlc->shift_reg & 0x01){ 460 + if (hdlc->bit_shift == 8) 461 + hdlc->crc = crc_ccitt_byte(hdlc->crc, 462 + hdlc->shift_reg); 463 + if (hdlc->shift_reg & 0x01) { 486 464 hdlc->hdlc_bits1++; 487 465 hdlc->cbin++; 488 466 hdlc->shift_reg >>= 1; ··· 496 474 case HDLC_SEND_CRC1: 497 475 hdlc->cbin <<= 1; 498 476 hdlc->data_bits++; 499 - if(hdlc->hdlc_bits1 == 5){ 477 + if (hdlc->hdlc_bits1 == 5) { 500 478 hdlc->hdlc_bits1 = 0; 501 479 break; 502 480 } 503 - if(hdlc->shift_reg & 0x01){ 481 + if (hdlc->shift_reg & 0x01) { 504 482 hdlc->hdlc_bits1++; 505 483 hdlc->cbin++; 506 484 hdlc->shift_reg >>= 1; ··· 510 488 hdlc->shift_reg >>= 1; 511 489 hdlc->bit_shift--; 512 490 } 513 - if(hdlc->bit_shift==0){ 491 + if (hdlc->bit_shift == 0) { 514 492 hdlc->shift_reg = (hdlc->crc >> 8); 515 493 hdlc->state = HDLC_SEND_CRC2; 516 494 hdlc->bit_shift = 8; ··· 519 497 case HDLC_SEND_CRC2: 520 498 hdlc->cbin <<= 1; 521 499 hdlc->data_bits++; 522 - if(hdlc->hdlc_bits1 == 5){ 500 + if (hdlc->hdlc_bits1 == 5) { 523 501 hdlc->hdlc_bits1 = 0; 524 502 break; 525 503 } 526 - if(hdlc->shift_reg & 0x01){ 504 + if (hdlc->shift_reg & 0x01) { 527 505 hdlc->hdlc_bits1++; 528 506 hdlc->cbin++; 529 507 hdlc->shift_reg >>= 1; ··· 533 511 hdlc->shift_reg >>= 1; 534 512 hdlc->bit_shift--; 535 513 } 536 - if(hdlc->bit_shift==0){ 514 + if (hdlc->bit_shift == 0) { 537 515 hdlc->shift_reg = 0x7e; 538 516 hdlc->state = HDLC_SEND_CLOSING_FLAG; 539 517 hdlc->bit_shift = 8; ··· 542 520 case HDLC_SEND_CLOSING_FLAG: 543 521 hdlc->cbin <<= 1; 544 522 hdlc->data_bits++; 545 - if(hdlc->hdlc_bits1 == 5){ 523 + if (hdlc->hdlc_bits1 == 5) { 546 524 hdlc->hdlc_bits1 = 0; 547 525 break; 548 526 } 549 - if(hdlc->shift_reg & 0x01){ 527 + if (hdlc->shift_reg & 0x01) 550 528 hdlc->cbin++; 551 - } 552 529 hdlc->shift_reg >>= 1; 553 530 hdlc->bit_shift--; 554 - if(hdlc->bit_shift==0){ 555 - hdlc->ffvalue = xfast_flag_value[hdlc->data_bits]; 556 - if(hdlc->dchannel){ 531 + if (hdlc->bit_shift == 0) { 532 + hdlc->ffvalue = 533 + xfast_flag_value[hdlc->data_bits]; 534 + if (hdlc->dchannel) { 557 535 hdlc->ffvalue = 0x7e; 558 536 hdlc->state = HDLC_SEND_IDLE1; 559 537 hdlc->bit_shift = 8-hdlc->data_bits; 560 - if(hdlc->bit_shift==0) 561 - hdlc->state = HDLC_SEND_FAST_IDLE; 538 + if (hdlc->bit_shift == 0) 539 + hdlc->state = 540 + HDLC_SEND_FAST_IDLE; 562 541 } else { 563 - if(!hdlc->do_adapt56){ 564 - hdlc->state = HDLC_SEND_FAST_FLAG; 542 + if (!hdlc->do_adapt56) { 543 + hdlc->state = 544 + HDLC_SEND_FAST_FLAG; 565 545 hdlc->data_received = 0; 566 546 } else { 567 547 hdlc->state = HDLC_SENDFLAG_B0; 568 548 hdlc->data_received = 0; 569 549 } 570 - // Finished with this frame, send flags 571 - if (dsize > 1) dsize = 1; 550 + /* Finished this frame, send flags */ 551 + if (dsize > 1) 552 + dsize = 1; 572 553 } 573 554 } 574 555 break; ··· 581 556 hdlc->cbin++; 582 557 hdlc->data_bits++; 583 558 hdlc->bit_shift--; 584 - if(hdlc->bit_shift==0){ 559 + if (hdlc->bit_shift == 0) { 585 560 hdlc->state = HDLC_SEND_FAST_IDLE; 586 561 hdlc->bit_shift = 0; 587 562 } ··· 590 565 hdlc->do_closing = 0; 591 566 hdlc->cbin = 0xff; 592 567 hdlc->data_bits = 8; 593 - if(hdlc->bit_shift == 8){ 568 + if (hdlc->bit_shift == 8) { 594 569 hdlc->cbin = 0x7e; 595 570 hdlc->state = HDLC_SEND_FIRST_FLAG; 596 571 } else { 597 572 *dst++ = hdlc->cbin; 598 - hdlc->bit_shift = hdlc->data_bits = 0; 573 + hdlc->bit_shift = 0; 574 + hdlc->data_bits = 0; 599 575 len++; 600 576 dsize = 0; 601 577 } ··· 604 578 default: 605 579 break; 606 580 } 607 - if(hdlc->do_adapt56){ 608 - if(hdlc->data_bits==7){ 581 + if (hdlc->do_adapt56) { 582 + if (hdlc->data_bits == 7) { 609 583 hdlc->cbin <<= 1; 610 584 hdlc->cbin++; 611 585 hdlc->data_bits++; 612 586 } 613 587 } 614 - if(hdlc->data_bits==8){ 588 + if (hdlc->data_bits == 8) { 615 589 *dst++ = hdlc->cbin; 616 590 hdlc->data_bits = 0; 617 591 len++; ··· 622 596 623 597 return len; 624 598 } 625 - 626 - EXPORT_SYMBOL(isdnhdlc_rcv_init); 627 - EXPORT_SYMBOL(isdnhdlc_decode); 628 - EXPORT_SYMBOL(isdnhdlc_out_init); 629 599 EXPORT_SYMBOL(isdnhdlc_encode);
+37 -31
include/linux/isdn/hdlc.h
··· 1 1 /* 2 - * isdnhdlc.h -- General purpose ISDN HDLC decoder. 2 + * hdlc.h -- General purpose ISDN HDLC decoder. 3 3 * 4 4 * Implementation of a HDLC decoder/encoder in software. 5 5 * Neccessary because some ISDN devices don't have HDLC 6 - * controllers. Also included: a bit reversal table. 6 + * controllers. 7 7 * 8 - *Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de> 9 - * 2001 Frode Isaksen <fisaksen@bewan.com> 10 - * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> 8 + * Copyright (C) 9 + * 2002 Wolfgang Mües <wolfgang@iksw-muees.de> 10 + * 2001 Frode Isaksen <fisaksen@bewan.com> 11 + * 2001 Kai Germaschewski <kai.germaschewski@gmx.de> 11 12 * 12 - * This program is free software; you can redistribute it and/or modify 13 - * it under the terms of the GNU General Public License as published by 14 - * the Free Software Foundation; either version 2 of the License, or 15 - * (at your option) any later version. 13 + * This program is free software; you can redistribute it and/or modify 14 + * it under the terms of the GNU General Public License as published by 15 + * the Free Software Foundation; either version 2 of the License, or 16 + * (at your option) any later version. 16 17 * 17 - * This program is distributed in the hope that it will be useful, 18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 - * GNU General Public License for more details. 18 + * This program is distributed in the hope that it will be useful, 19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 + * GNU General Public License for more details. 21 22 * 22 - * You should have received a copy of the GNU General Public License 23 - * along with this program; if not, write to the Free Software 24 - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 + * You should have received a copy of the GNU General Public License 24 + * along with this program; if not, write to the Free Software 25 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 26 */ 26 27 27 28 #ifndef __ISDNHDLC_H__ ··· 32 31 int bit_shift; 33 32 int hdlc_bits1; 34 33 int data_bits; 35 - int ffbit_shift; // encoding only 34 + int ffbit_shift; /* encoding only */ 36 35 int state; 37 36 int dstpos; 38 37 39 - unsigned short crc; 38 + u16 crc; 40 39 41 - unsigned char cbin; 42 - unsigned char shift_reg; 43 - unsigned char ffvalue; 40 + u8 cbin; 41 + u8 shift_reg; 42 + u8 ffvalue; 44 43 45 - unsigned int data_received:1; // set if transferring data 46 - unsigned int dchannel:1; // set if D channel (send idle instead of flags) 47 - unsigned int do_adapt56:1; // set if 56K adaptation 48 - unsigned int do_closing:1; // set if in closing phase (need to send CRC + flag 44 + /* set if transferring data */ 45 + u32 data_received:1; 46 + /* set if D channel (send idle instead of flags) */ 47 + u32 dchannel:1; 48 + /* set if 56K adaptation */ 49 + u32 do_adapt56:1; 50 + /* set if in closing phase (need to send CRC + flag) */ 51 + u32 do_closing:1; 49 52 }; 50 53 51 54 ··· 62 57 #define HDLC_CRC_ERROR 2 63 58 #define HDLC_LENGTH_ERROR 3 64 59 65 - extern void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56); 60 + extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56); 66 61 67 - extern int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, int slen,int *count, 68 - unsigned char *dst, int dsize); 62 + extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, 63 + int slen, int *count, u8 *dst, int dsize); 69 64 70 - extern void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc,int is_d_channel,int do_adapt56); 65 + extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel, 66 + int do_adapt56); 71 67 72 - extern int isdnhdlc_encode (struct isdnhdlc_vars *hdlc,const unsigned char *src,unsigned short slen,int *count, 73 - unsigned char *dst,int dsize); 68 + extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, 69 + u16 slen, int *count, u8 *dst, int dsize); 74 70 75 71 #endif /* __ISDNHDLC_H__ */