Lines Matching refs:hdlc
40 void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, u32 features) in isdnhdlc_rcv_init() argument
42 memset(hdlc, 0, sizeof(struct isdnhdlc_vars)); in isdnhdlc_rcv_init()
43 hdlc->state = HDLC_GET_DATA; in isdnhdlc_rcv_init()
45 hdlc->do_adapt56 = 1; in isdnhdlc_rcv_init()
47 hdlc->do_bitreverse = 1; in isdnhdlc_rcv_init()
51 void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, u32 features) in isdnhdlc_out_init() argument
53 memset(hdlc, 0, sizeof(struct isdnhdlc_vars)); in isdnhdlc_out_init()
55 hdlc->dchannel = 1; in isdnhdlc_out_init()
56 hdlc->state = HDLC_SEND_FIRST_FLAG; in isdnhdlc_out_init()
58 hdlc->dchannel = 0; in isdnhdlc_out_init()
59 hdlc->state = HDLC_SEND_FAST_FLAG; in isdnhdlc_out_init()
60 hdlc->ffvalue = 0x7e; in isdnhdlc_out_init()
62 hdlc->cbin = 0x7e; in isdnhdlc_out_init()
64 hdlc->do_adapt56 = 1; in isdnhdlc_out_init()
65 hdlc->state = HDLC_SENDFLAG_B0; in isdnhdlc_out_init()
67 hdlc->data_bits = 8; in isdnhdlc_out_init()
69 hdlc->do_bitreverse = 1; in isdnhdlc_out_init()
74 check_frame(struct isdnhdlc_vars *hdlc) in check_frame() argument
78 if (hdlc->dstpos < 2) /* too small - framing error */ in check_frame()
80 else if (hdlc->crc != 0xf0b8) /* crc error */ in check_frame()
84 hdlc->dstpos -= 2; in check_frame()
86 status = hdlc->dstpos; in check_frame()
118 int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen, in isdnhdlc_decode() argument
162 if (hdlc->bit_shift == 0) { in isdnhdlc_decode()
164 if (hdlc->do_bitreverse == 0) in isdnhdlc_decode()
165 hdlc->cbin = bitrev8(*src++); in isdnhdlc_decode()
167 hdlc->cbin = *src++; in isdnhdlc_decode()
169 hdlc->bit_shift = 8; in isdnhdlc_decode()
170 if (hdlc->do_adapt56) in isdnhdlc_decode()
171 hdlc->bit_shift--; in isdnhdlc_decode()
174 switch (hdlc->state) { in isdnhdlc_decode()
178 if (hdlc->cbin == 0xff) { in isdnhdlc_decode()
179 hdlc->bit_shift = 0; in isdnhdlc_decode()
182 hdlc->state = HDLC_GET_FLAG_B0; in isdnhdlc_decode()
183 hdlc->hdlc_bits1 = 0; in isdnhdlc_decode()
184 hdlc->bit_shift = 8; in isdnhdlc_decode()
187 if (!(hdlc->cbin & 0x80)) { in isdnhdlc_decode()
188 hdlc->state = HDLC_GETFLAG_B1A6; in isdnhdlc_decode()
189 hdlc->hdlc_bits1 = 0; in isdnhdlc_decode()
191 if ((!hdlc->do_adapt56) && in isdnhdlc_decode()
192 (++hdlc->hdlc_bits1 >= 8) && in isdnhdlc_decode()
193 (hdlc->bit_shift == 1)) in isdnhdlc_decode()
194 hdlc->state = HDLC_FAST_IDLE; in isdnhdlc_decode()
196 hdlc->cbin <<= 1; in isdnhdlc_decode()
197 hdlc->bit_shift--; in isdnhdlc_decode()
200 if (hdlc->cbin & 0x80) { in isdnhdlc_decode()
201 hdlc->hdlc_bits1++; in isdnhdlc_decode()
202 if (hdlc->hdlc_bits1 == 6) in isdnhdlc_decode()
203 hdlc->state = HDLC_GETFLAG_B7; in isdnhdlc_decode()
205 hdlc->hdlc_bits1 = 0; in isdnhdlc_decode()
206 hdlc->cbin <<= 1; in isdnhdlc_decode()
207 hdlc->bit_shift--; in isdnhdlc_decode()
210 if (hdlc->cbin & 0x80) { in isdnhdlc_decode()
211 hdlc->state = HDLC_GET_FLAG_B0; in isdnhdlc_decode()
213 hdlc->state = HDLC_GET_DATA; in isdnhdlc_decode()
214 hdlc->crc = 0xffff; in isdnhdlc_decode()
215 hdlc->shift_reg = 0; in isdnhdlc_decode()
216 hdlc->hdlc_bits1 = 0; in isdnhdlc_decode()
217 hdlc->data_bits = 0; in isdnhdlc_decode()
218 hdlc->data_received = 0; in isdnhdlc_decode()
220 hdlc->cbin <<= 1; in isdnhdlc_decode()
221 hdlc->bit_shift--; in isdnhdlc_decode()
224 if (hdlc->cbin & 0x80) { in isdnhdlc_decode()
225 hdlc->hdlc_bits1++; in isdnhdlc_decode()
226 switch (hdlc->hdlc_bits1) { in isdnhdlc_decode()
230 if (hdlc->data_received) in isdnhdlc_decode()
233 if (!hdlc->do_adapt56) { in isdnhdlc_decode()
234 if (hdlc->cbin == fast_abort in isdnhdlc_decode()
235 [hdlc->bit_shift + 1]) { in isdnhdlc_decode()
236 hdlc->state = in isdnhdlc_decode()
238 hdlc->bit_shift = 1; in isdnhdlc_decode()
242 hdlc->state = HDLC_GET_FLAG_B0; in isdnhdlc_decode()
245 hdlc->shift_reg >>= 1; in isdnhdlc_decode()
246 hdlc->shift_reg |= 0x80; in isdnhdlc_decode()
247 hdlc->data_bits++; in isdnhdlc_decode()
251 switch (hdlc->hdlc_bits1) { in isdnhdlc_decode()
255 if (hdlc->data_received) in isdnhdlc_decode()
256 status = check_frame(hdlc); in isdnhdlc_decode()
257 hdlc->crc = 0xffff; in isdnhdlc_decode()
258 hdlc->shift_reg = 0; in isdnhdlc_decode()
259 hdlc->data_bits = 0; in isdnhdlc_decode()
260 if (!hdlc->do_adapt56) in isdnhdlc_decode()
261 handle_fast_flag(hdlc); in isdnhdlc_decode()
263 hdlc->state = HDLC_GET_DATA; in isdnhdlc_decode()
264 hdlc->data_received = 0; in isdnhdlc_decode()
268 hdlc->shift_reg >>= 1; in isdnhdlc_decode()
269 hdlc->data_bits++; in isdnhdlc_decode()
272 hdlc->hdlc_bits1 = 0; in isdnhdlc_decode()
275 hdlc->dstpos = 0; in isdnhdlc_decode()
277 hdlc->cbin <<= 1; in isdnhdlc_decode()
278 hdlc->bit_shift--; in isdnhdlc_decode()
281 if (hdlc->data_bits == 8) { in isdnhdlc_decode()
282 hdlc->data_bits = 0; in isdnhdlc_decode()
283 hdlc->data_received = 1; in isdnhdlc_decode()
284 hdlc->crc = crc_ccitt_byte(hdlc->crc, in isdnhdlc_decode()
285 hdlc->shift_reg); in isdnhdlc_decode()
288 if (hdlc->dstpos < dsize) in isdnhdlc_decode()
289 dst[hdlc->dstpos++] = hdlc->shift_reg; in isdnhdlc_decode()
293 hdlc->dstpos = 0; in isdnhdlc_decode()
296 hdlc->cbin <<= 1; in isdnhdlc_decode()
297 hdlc->bit_shift--; in isdnhdlc_decode()
300 if (hdlc->cbin == hdlc->ffvalue) { in isdnhdlc_decode()
301 hdlc->bit_shift = 0; in isdnhdlc_decode()
304 if (hdlc->cbin == 0xff) { in isdnhdlc_decode()
305 hdlc->state = HDLC_FAST_IDLE; in isdnhdlc_decode()
306 hdlc->bit_shift = 0; in isdnhdlc_decode()
307 } else if (hdlc->ffbit_shift == 8) { in isdnhdlc_decode()
308 hdlc->state = HDLC_GETFLAG_B7; in isdnhdlc_decode()
311 handle_abort(hdlc); in isdnhdlc_decode()
341 int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen, in isdnhdlc_encode() argument
353 if ((slen == 1) && (hdlc->state == HDLC_SEND_FAST_FLAG)) in isdnhdlc_encode()
354 hdlc->state = HDLC_SENDFLAG_ONE; in isdnhdlc_encode()
356 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
357 if (slen && !hdlc->do_closing) { in isdnhdlc_encode()
358 hdlc->shift_reg = *src++; in isdnhdlc_encode()
362 hdlc->do_closing = 1; in isdnhdlc_encode()
363 hdlc->bit_shift = 8; in isdnhdlc_encode()
365 if (hdlc->state == HDLC_SEND_DATA) { in isdnhdlc_encode()
366 if (hdlc->data_received) { in isdnhdlc_encode()
367 hdlc->state = HDLC_SEND_CRC1; in isdnhdlc_encode()
368 hdlc->crc ^= 0xffff; in isdnhdlc_encode()
369 hdlc->bit_shift = 8; in isdnhdlc_encode()
370 hdlc->shift_reg = in isdnhdlc_encode()
371 hdlc->crc & 0xff; in isdnhdlc_encode()
372 } else if (!hdlc->do_adapt56) in isdnhdlc_encode()
373 hdlc->state = in isdnhdlc_encode()
376 hdlc->state = in isdnhdlc_encode()
383 switch (hdlc->state) { in isdnhdlc_encode()
389 hdlc->do_closing = 0; in isdnhdlc_encode()
392 if (hdlc->do_bitreverse == 0) in isdnhdlc_encode()
393 *dst++ = bitrev8(hdlc->ffvalue); in isdnhdlc_encode()
395 *dst++ = hdlc->ffvalue; in isdnhdlc_encode()
402 if (hdlc->bit_shift == 8) { in isdnhdlc_encode()
403 hdlc->cbin = hdlc->ffvalue >> in isdnhdlc_encode()
404 (8 - hdlc->data_bits); in isdnhdlc_encode()
405 hdlc->state = HDLC_SEND_DATA; in isdnhdlc_encode()
406 hdlc->crc = 0xffff; in isdnhdlc_encode()
407 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
408 hdlc->data_received = 1; in isdnhdlc_encode()
412 hdlc->do_closing = 0; in isdnhdlc_encode()
413 hdlc->cbin <<= 1; in isdnhdlc_encode()
414 hdlc->data_bits++; in isdnhdlc_encode()
415 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
416 hdlc->state = HDLC_SENDFLAG_B1A6; in isdnhdlc_encode()
419 hdlc->cbin <<= 1; in isdnhdlc_encode()
420 hdlc->data_bits++; in isdnhdlc_encode()
421 hdlc->cbin++; in isdnhdlc_encode()
422 if (++hdlc->hdlc_bits1 == 6) in isdnhdlc_encode()
423 hdlc->state = HDLC_SENDFLAG_B7; in isdnhdlc_encode()
426 hdlc->cbin <<= 1; in isdnhdlc_encode()
427 hdlc->data_bits++; in isdnhdlc_encode()
429 hdlc->state = HDLC_SENDFLAG_B0; in isdnhdlc_encode()
432 if (hdlc->bit_shift == 8) { in isdnhdlc_encode()
433 hdlc->state = HDLC_SEND_DATA; in isdnhdlc_encode()
434 hdlc->crc = 0xffff; in isdnhdlc_encode()
435 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
436 hdlc->data_received = 1; in isdnhdlc_encode()
440 hdlc->data_received = 1; in isdnhdlc_encode()
441 if (hdlc->data_bits == 8) { in isdnhdlc_encode()
442 hdlc->state = HDLC_SEND_DATA; in isdnhdlc_encode()
443 hdlc->crc = 0xffff; in isdnhdlc_encode()
444 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
447 hdlc->cbin <<= 1; in isdnhdlc_encode()
448 hdlc->data_bits++; in isdnhdlc_encode()
449 if (hdlc->shift_reg & 0x01) in isdnhdlc_encode()
450 hdlc->cbin++; in isdnhdlc_encode()
451 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
452 hdlc->bit_shift--; in isdnhdlc_encode()
453 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
454 hdlc->state = HDLC_SEND_DATA; in isdnhdlc_encode()
455 hdlc->crc = 0xffff; in isdnhdlc_encode()
456 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
460 hdlc->cbin <<= 1; in isdnhdlc_encode()
461 hdlc->data_bits++; in isdnhdlc_encode()
462 if (hdlc->hdlc_bits1 == 5) { in isdnhdlc_encode()
463 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
466 if (hdlc->bit_shift == 8) in isdnhdlc_encode()
467 hdlc->crc = crc_ccitt_byte(hdlc->crc, in isdnhdlc_encode()
468 hdlc->shift_reg); in isdnhdlc_encode()
469 if (hdlc->shift_reg & 0x01) { in isdnhdlc_encode()
470 hdlc->hdlc_bits1++; in isdnhdlc_encode()
471 hdlc->cbin++; in isdnhdlc_encode()
472 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
473 hdlc->bit_shift--; in isdnhdlc_encode()
475 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
476 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
477 hdlc->bit_shift--; in isdnhdlc_encode()
481 hdlc->cbin <<= 1; in isdnhdlc_encode()
482 hdlc->data_bits++; in isdnhdlc_encode()
483 if (hdlc->hdlc_bits1 == 5) { in isdnhdlc_encode()
484 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
487 if (hdlc->shift_reg & 0x01) { in isdnhdlc_encode()
488 hdlc->hdlc_bits1++; in isdnhdlc_encode()
489 hdlc->cbin++; in isdnhdlc_encode()
490 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
491 hdlc->bit_shift--; in isdnhdlc_encode()
493 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
494 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
495 hdlc->bit_shift--; in isdnhdlc_encode()
497 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
498 hdlc->shift_reg = (hdlc->crc >> 8); in isdnhdlc_encode()
499 hdlc->state = HDLC_SEND_CRC2; in isdnhdlc_encode()
500 hdlc->bit_shift = 8; in isdnhdlc_encode()
504 hdlc->cbin <<= 1; in isdnhdlc_encode()
505 hdlc->data_bits++; in isdnhdlc_encode()
506 if (hdlc->hdlc_bits1 == 5) { in isdnhdlc_encode()
507 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
510 if (hdlc->shift_reg & 0x01) { in isdnhdlc_encode()
511 hdlc->hdlc_bits1++; in isdnhdlc_encode()
512 hdlc->cbin++; in isdnhdlc_encode()
513 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
514 hdlc->bit_shift--; in isdnhdlc_encode()
516 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
517 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
518 hdlc->bit_shift--; in isdnhdlc_encode()
520 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
521 hdlc->shift_reg = 0x7e; in isdnhdlc_encode()
522 hdlc->state = HDLC_SEND_CLOSING_FLAG; in isdnhdlc_encode()
523 hdlc->bit_shift = 8; in isdnhdlc_encode()
527 hdlc->cbin <<= 1; in isdnhdlc_encode()
528 hdlc->data_bits++; in isdnhdlc_encode()
529 if (hdlc->hdlc_bits1 == 5) { in isdnhdlc_encode()
530 hdlc->hdlc_bits1 = 0; in isdnhdlc_encode()
533 if (hdlc->shift_reg & 0x01) in isdnhdlc_encode()
534 hdlc->cbin++; in isdnhdlc_encode()
535 hdlc->shift_reg >>= 1; in isdnhdlc_encode()
536 hdlc->bit_shift--; in isdnhdlc_encode()
537 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
538 hdlc->ffvalue = in isdnhdlc_encode()
539 xfast_flag_value[hdlc->data_bits]; in isdnhdlc_encode()
540 if (hdlc->dchannel) { in isdnhdlc_encode()
541 hdlc->ffvalue = 0x7e; in isdnhdlc_encode()
542 hdlc->state = HDLC_SEND_IDLE1; in isdnhdlc_encode()
543 hdlc->bit_shift = 8-hdlc->data_bits; in isdnhdlc_encode()
544 if (hdlc->bit_shift == 0) in isdnhdlc_encode()
545 hdlc->state = in isdnhdlc_encode()
548 if (!hdlc->do_adapt56) { in isdnhdlc_encode()
549 hdlc->state = in isdnhdlc_encode()
551 hdlc->data_received = 0; in isdnhdlc_encode()
553 hdlc->state = HDLC_SENDFLAG_B0; in isdnhdlc_encode()
554 hdlc->data_received = 0; in isdnhdlc_encode()
563 hdlc->do_closing = 0; in isdnhdlc_encode()
564 hdlc->cbin <<= 1; in isdnhdlc_encode()
565 hdlc->cbin++; in isdnhdlc_encode()
566 hdlc->data_bits++; in isdnhdlc_encode()
567 hdlc->bit_shift--; in isdnhdlc_encode()
568 if (hdlc->bit_shift == 0) { in isdnhdlc_encode()
569 hdlc->state = HDLC_SEND_FAST_IDLE; in isdnhdlc_encode()
570 hdlc->bit_shift = 0; in isdnhdlc_encode()
574 hdlc->do_closing = 0; in isdnhdlc_encode()
575 hdlc->cbin = 0xff; in isdnhdlc_encode()
576 hdlc->data_bits = 8; in isdnhdlc_encode()
577 if (hdlc->bit_shift == 8) { in isdnhdlc_encode()
578 hdlc->cbin = 0x7e; in isdnhdlc_encode()
579 hdlc->state = HDLC_SEND_FIRST_FLAG; in isdnhdlc_encode()
582 if (hdlc->do_bitreverse == 0) in isdnhdlc_encode()
583 *dst++ = bitrev8(hdlc->cbin); in isdnhdlc_encode()
585 *dst++ = hdlc->cbin; in isdnhdlc_encode()
586 hdlc->bit_shift = 0; in isdnhdlc_encode()
587 hdlc->data_bits = 0; in isdnhdlc_encode()
595 if (hdlc->do_adapt56) { in isdnhdlc_encode()
596 if (hdlc->data_bits == 7) { in isdnhdlc_encode()
597 hdlc->cbin <<= 1; in isdnhdlc_encode()
598 hdlc->cbin++; in isdnhdlc_encode()
599 hdlc->data_bits++; in isdnhdlc_encode()
602 if (hdlc->data_bits == 8) { in isdnhdlc_encode()
604 if (hdlc->do_bitreverse == 0) in isdnhdlc_encode()
605 *dst++ = bitrev8(hdlc->cbin); in isdnhdlc_encode()
607 *dst++ = hdlc->cbin; in isdnhdlc_encode()
608 hdlc->data_bits = 0; in isdnhdlc_encode()