···11/*22 * isdnhdlc.c -- General purpose ISDN HDLC decoder.33 *44- *Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de>55- * 2001 Frode Isaksen <fisaksen@bewan.com>66- * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>44+ * Copyright (C)55+ * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>66+ * 2001 Frode Isaksen <fisaksen@bewan.com>77+ * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>78 *88- * This program is free software; you can redistribute it and/or modify99- * it under the terms of the GNU General Public License as published by1010- * the Free Software Foundation; either version 2 of the License, or1111- * (at your option) any later version.99+ * This program is free software; you can redistribute it and/or modify1010+ * it under the terms of the GNU General Public License as published by1111+ * the Free Software Foundation; either version 2 of the License, or1212+ * (at your option) any later version.1213 *1313- * This program is distributed in the hope that it will be useful,1414- * but WITHOUT ANY WARRANTY; without even the implied warranty of1515- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1616- * GNU General Public License for more details.1414+ * This program is distributed in the hope that it will be useful,1515+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1616+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1717+ * GNU General Public License for more details.1718 *1818- * You should have received a copy of the GNU General Public License1919- * along with this program; if not, write to the Free Software2020- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.1919+ * You should have received a copy of the GNU General Public License2020+ * along with this program; if not, write to the Free Software2121+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.2122 */22232324#include <linux/module.h>···3736/*-------------------------------------------------------------------*/38373938enum {4040- HDLC_FAST_IDLE,HDLC_GET_FLAG_B0,HDLC_GETFLAG_B1A6,HDLC_GETFLAG_B7,4141- HDLC_GET_DATA,HDLC_FAST_FLAG3939+ HDLC_FAST_IDLE, HDLC_GET_FLAG_B0, HDLC_GETFLAG_B1A6, HDLC_GETFLAG_B7,4040+ HDLC_GET_DATA, HDLC_FAST_FLAG4241};43424443enum {4545- HDLC_SEND_DATA,HDLC_SEND_CRC1,HDLC_SEND_FAST_FLAG,4646- HDLC_SEND_FIRST_FLAG,HDLC_SEND_CRC2,HDLC_SEND_CLOSING_FLAG,4747- HDLC_SEND_IDLE1,HDLC_SEND_FAST_IDLE,HDLC_SENDFLAG_B0,4848- HDLC_SENDFLAG_B1A6,HDLC_SENDFLAG_B7,STOPPED4444+ HDLC_SEND_DATA, HDLC_SEND_CRC1, HDLC_SEND_FAST_FLAG,4545+ HDLC_SEND_FIRST_FLAG, HDLC_SEND_CRC2, HDLC_SEND_CLOSING_FLAG,4646+ HDLC_SEND_IDLE1, HDLC_SEND_FAST_IDLE, HDLC_SENDFLAG_B0,4747+ HDLC_SENDFLAG_B1A6, HDLC_SENDFLAG_B7, STOPPED4948};50495151-void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56)5050+void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56)5251{5353- hdlc->bit_shift = 0;5252+ hdlc->bit_shift = 0;5453 hdlc->hdlc_bits1 = 0;5554 hdlc->data_bits = 0;5655 hdlc->ffbit_shift = 0;···6463 hdlc->ffvalue = 0;6564 hdlc->dstpos = 0;6665}6666+EXPORT_SYMBOL(isdnhdlc_out_init);67676868-void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc, int is_d_channel, int do_adapt56)6868+void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,6969+ int do_adapt56)6970{7070- hdlc->bit_shift = 0;7171+ hdlc->bit_shift = 0;7172 hdlc->hdlc_bits1 = 0;7273 hdlc->data_bits = 0;7374 hdlc->ffbit_shift = 0;···8683 }8784 hdlc->cbin = 0x7e;8885 hdlc->bit_shift = 0;8989- if(do_adapt56){8686+ if (do_adapt56) {9087 hdlc->do_adapt56 = 1;9188 hdlc->data_bits = 0;9289 hdlc->state = HDLC_SENDFLAG_B0;···9592 hdlc->data_bits = 8;9693 }9794 hdlc->shift_reg = 0;9595+}9696+EXPORT_SYMBOL(isdnhdlc_rcv_init);9797+9898+static int9999+check_frame(struct isdnhdlc_vars *hdlc)100100+{101101+ int status;102102+103103+ if (hdlc->dstpos < 2) /* too small - framing error */104104+ status = -HDLC_FRAMING_ERROR;105105+ else if (hdlc->crc != 0xf0b8) /* crc error */106106+ status = -HDLC_CRC_ERROR;107107+ else {108108+ /* remove CRC */109109+ hdlc->dstpos -= 2;110110+ /* good frame */111111+ status = hdlc->dstpos;112112+ }113113+ return status;98114}99115100116/*···143121 returns - number of decoded bytes in the destination buffer and status144122 flag.145123 */146146-int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src,147147- int slen, int *count, unsigned char *dst, int dsize)124124+int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src, int slen,125125+ int *count, u8 *dst, int dsize)148126{149149- int status=0;127127+ int status = 0;150128151151- static const unsigned char fast_flag[]={152152- 0x00,0x00,0x00,0x20,0x30,0x38,0x3c,0x3e,0x3f129129+ static const unsigned char fast_flag[] = {130130+ 0x00, 0x00, 0x00, 0x20, 0x30, 0x38, 0x3c, 0x3e, 0x3f153131 };154132155155- static const unsigned char fast_flag_value[]={156156- 0x00,0x7e,0xfc,0xf9,0xf3,0xe7,0xcf,0x9f,0x3f133133+ static const unsigned char fast_flag_value[] = {134134+ 0x00, 0x7e, 0xfc, 0xf9, 0xf3, 0xe7, 0xcf, 0x9f, 0x3f157135 };158136159159- static const unsigned char fast_abort[]={160160- 0x00,0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff137137+ static const unsigned char fast_abort[] = {138138+ 0x00, 0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff161139 };140140+141141+#define handle_fast_flag(h) \142142+ do {\143143+ if (h->cbin == fast_flag[h->bit_shift]) {\144144+ h->ffvalue = fast_flag_value[h->bit_shift];\145145+ h->state = HDLC_FAST_FLAG;\146146+ h->ffbit_shift = h->bit_shift;\147147+ h->bit_shift = 1;\148148+ } else {\149149+ h->state = HDLC_GET_DATA;\150150+ h->data_received = 0;\151151+ } \152152+ } while (0)153153+154154+#define handle_abort(h) \155155+ do {\156156+ h->shift_reg = fast_abort[h->ffbit_shift - 1];\157157+ h->hdlc_bits1 = h->ffbit_shift - 2;\158158+ if (h->hdlc_bits1 < 0)\159159+ h->hdlc_bits1 = 0;\160160+ h->data_bits = h->ffbit_shift - 1;\161161+ h->state = HDLC_GET_DATA;\162162+ h->data_received = 0;\163163+ } while (0)162164163165 *count = slen;164166165165- while(slen > 0){166166- if(hdlc->bit_shift==0){167167+ while (slen > 0) {168168+ if (hdlc->bit_shift == 0) {167169 hdlc->cbin = *src++;168170 slen--;169171 hdlc->bit_shift = 8;170170- if(hdlc->do_adapt56){171171- hdlc->bit_shift --;172172- }172172+ if (hdlc->do_adapt56)173173+ hdlc->bit_shift--;173174 }174175175175- switch(hdlc->state){176176+ switch (hdlc->state) {176177 case STOPPED:177178 return 0;178179 case HDLC_FAST_IDLE:179179- if(hdlc->cbin == 0xff){180180+ if (hdlc->cbin == 0xff) {180181 hdlc->bit_shift = 0;181182 break;182183 }···208163 hdlc->bit_shift = 8;209164 break;210165 case HDLC_GET_FLAG_B0:211211- if(!(hdlc->cbin & 0x80)) {166166+ if (!(hdlc->cbin & 0x80)) {212167 hdlc->state = HDLC_GETFLAG_B1A6;213168 hdlc->hdlc_bits1 = 0;214169 } else {215215- if(!hdlc->do_adapt56){216216- if(++hdlc->hdlc_bits1 >=8 ) if(hdlc->bit_shift==1)170170+ if ((!hdlc->do_adapt56) &&171171+ (++hdlc->hdlc_bits1 >= 8) &&172172+ (hdlc->bit_shift == 1))217173 hdlc->state = HDLC_FAST_IDLE;218218- }219174 }220220- hdlc->cbin<<=1;221221- hdlc->bit_shift --;175175+ hdlc->cbin <<= 1;176176+ hdlc->bit_shift--;222177 break;223178 case HDLC_GETFLAG_B1A6:224224- if(hdlc->cbin & 0x80){179179+ if (hdlc->cbin & 0x80) {225180 hdlc->hdlc_bits1++;226226- if(hdlc->hdlc_bits1==6){181181+ if (hdlc->hdlc_bits1 == 6)227182 hdlc->state = HDLC_GETFLAG_B7;228228- }229229- } else {183183+ } else230184 hdlc->hdlc_bits1 = 0;231231- }232232- hdlc->cbin<<=1;233233- hdlc->bit_shift --;185185+ hdlc->cbin <<= 1;186186+ hdlc->bit_shift--;234187 break;235188 case HDLC_GETFLAG_B7:236236- if(hdlc->cbin & 0x80) {189189+ if (hdlc->cbin & 0x80) {237190 hdlc->state = HDLC_GET_FLAG_B0;238191 } else {239192 hdlc->state = HDLC_GET_DATA;···241198 hdlc->data_bits = 0;242199 hdlc->data_received = 0;243200 }244244- hdlc->cbin<<=1;245245- hdlc->bit_shift --;201201+ hdlc->cbin <<= 1;202202+ hdlc->bit_shift--;246203 break;247204 case HDLC_GET_DATA:248248- if(hdlc->cbin & 0x80){205205+ if (hdlc->cbin & 0x80) {249206 hdlc->hdlc_bits1++;250250- switch(hdlc->hdlc_bits1){207207+ switch (hdlc->hdlc_bits1) {251208 case 6:252209 break;253210 case 7:254254- if(hdlc->data_received) {255255- // bad frame211211+ if (hdlc->data_received)212212+ /* bad frame */256213 status = -HDLC_FRAMING_ERROR;257257- }258258- if(!hdlc->do_adapt56){259259- if(hdlc->cbin==fast_abort[hdlc->bit_shift+1]){260260- hdlc->state = HDLC_FAST_IDLE;261261- hdlc->bit_shift=1;214214+ if (!hdlc->do_adapt56) {215215+ if (hdlc->cbin == fast_abort216216+ [hdlc->bit_shift + 1]) {217217+ hdlc->state =218218+ HDLC_FAST_IDLE;219219+ hdlc->bit_shift = 1;262220 break;263221 }264264- } else {222222+ } else265223 hdlc->state = HDLC_GET_FLAG_B0;266266- }267224 break;268225 default:269269- hdlc->shift_reg>>=1;226226+ hdlc->shift_reg >>= 1;270227 hdlc->shift_reg |= 0x80;271228 hdlc->data_bits++;272229 break;273230 }274231 } else {275275- switch(hdlc->hdlc_bits1){232232+ switch (hdlc->hdlc_bits1) {276233 case 5:277234 break;278235 case 6:279279- if(hdlc->data_received){280280- if (hdlc->dstpos < 2) {281281- status = -HDLC_FRAMING_ERROR;282282- } else if (hdlc->crc != 0xf0b8){283283- // crc error284284- status = -HDLC_CRC_ERROR;285285- } else {286286- // remove CRC287287- hdlc->dstpos -= 2;288288- // good frame289289- status = hdlc->dstpos;290290- }291291- }236236+ if (hdlc->data_received)237237+ status = check_frame(hdlc);292238 hdlc->crc = 0xffff;293239 hdlc->shift_reg = 0;294240 hdlc->data_bits = 0;295295- if(!hdlc->do_adapt56){296296- if(hdlc->cbin==fast_flag[hdlc->bit_shift]){297297- hdlc->ffvalue = fast_flag_value[hdlc->bit_shift];298298- hdlc->state = HDLC_FAST_FLAG;299299- hdlc->ffbit_shift = hdlc->bit_shift;300300- hdlc->bit_shift = 1;301301- } else {302302- hdlc->state = HDLC_GET_DATA;303303- hdlc->data_received = 0;304304- }305305- } else {241241+ if (!hdlc->do_adapt56)242242+ handle_fast_flag(hdlc);243243+ else {306244 hdlc->state = HDLC_GET_DATA;307245 hdlc->data_received = 0;308246 }309247 break;310248 default:311311- hdlc->shift_reg>>=1;249249+ hdlc->shift_reg >>= 1;312250 hdlc->data_bits++;313251 break;314252 }···302278 hdlc->bit_shift--;303279 return status;304280 }305305- if(hdlc->data_bits==8){281281+ if (hdlc->data_bits == 8) {306282 hdlc->data_bits = 0;307283 hdlc->data_received = 1;308308- hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg);284284+ hdlc->crc = crc_ccitt_byte(hdlc->crc,285285+ hdlc->shift_reg);309286310310- // good byte received311311- if (hdlc->dstpos < dsize) {287287+ /* good byte received */288288+ if (hdlc->dstpos < dsize)312289 dst[hdlc->dstpos++] = hdlc->shift_reg;313313- } else {314314- // frame too long290290+ else {291291+ /* frame too long */315292 status = -HDLC_LENGTH_ERROR;316293 hdlc->dstpos = 0;317294 }···321296 hdlc->bit_shift--;322297 break;323298 case HDLC_FAST_FLAG:324324- if(hdlc->cbin==hdlc->ffvalue){299299+ if (hdlc->cbin == hdlc->ffvalue) {325300 hdlc->bit_shift = 0;326301 break;327302 } else {328328- if(hdlc->cbin == 0xff){303303+ if (hdlc->cbin == 0xff) {329304 hdlc->state = HDLC_FAST_IDLE;330330- hdlc->bit_shift=0;331331- } else if(hdlc->ffbit_shift==8){305305+ hdlc->bit_shift = 0;306306+ } else if (hdlc->ffbit_shift == 8) {332307 hdlc->state = HDLC_GETFLAG_B7;333308 break;334334- } else {335335- hdlc->shift_reg = fast_abort[hdlc->ffbit_shift-1];336336- hdlc->hdlc_bits1 = hdlc->ffbit_shift-2;337337- if(hdlc->hdlc_bits1<0)hdlc->hdlc_bits1 = 0;338338- hdlc->data_bits = hdlc->ffbit_shift-1;339339- hdlc->state = HDLC_GET_DATA;340340- hdlc->data_received = 0;341341- }309309+ } else310310+ handle_abort(hdlc);342311 }343312 break;344313 default:···342323 *count -= slen;343324 return 0;344325}345345-326326+EXPORT_SYMBOL(isdnhdlc_decode);346327/*347328 isdnhdlc_encode - encodes HDLC frames to a transparent bit stream.348329···362343 dsize - destination buffer size363344 returns - number of encoded bytes in the destination buffer364345*/365365-int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const unsigned char *src,366366- unsigned short slen, int *count,367367- unsigned char *dst, int dsize)346346+int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src, u16 slen,347347+ int *count, u8 *dst, int dsize)368348{369349 static const unsigned char xfast_flag_value[] = {370370- 0x7e,0x3f,0x9f,0xcf,0xe7,0xf3,0xf9,0xfc,0x7e350350+ 0x7e, 0x3f, 0x9f, 0xcf, 0xe7, 0xf3, 0xf9, 0xfc, 0x7e371351 };372352373353 int len = 0;···374356 *count = slen;375357376358 while (dsize > 0) {377377- if(hdlc->bit_shift==0){378378- if(slen && !hdlc->do_closing){359359+ if (hdlc->bit_shift == 0) {360360+ if (slen && !hdlc->do_closing) {379361 hdlc->shift_reg = *src++;380362 slen--;381363 if (slen == 0)382382- hdlc->do_closing = 1; /* closing sequence, CRC + flag(s) */364364+ /* closing sequence, CRC + flag(s) */365365+ hdlc->do_closing = 1;383366 hdlc->bit_shift = 8;384367 } else {385385- if(hdlc->state == HDLC_SEND_DATA){386386- if(hdlc->data_received){368368+ if (hdlc->state == HDLC_SEND_DATA) {369369+ if (hdlc->data_received) {387370 hdlc->state = HDLC_SEND_CRC1;388371 hdlc->crc ^= 0xffff;389372 hdlc->bit_shift = 8;390390- hdlc->shift_reg = hdlc->crc & 0xff;391391- } else if(!hdlc->do_adapt56){392392- hdlc->state = HDLC_SEND_FAST_FLAG;393393- } else {394394- hdlc->state = HDLC_SENDFLAG_B0;395395- }373373+ hdlc->shift_reg =374374+ hdlc->crc & 0xff;375375+ } else if (!hdlc->do_adapt56)376376+ hdlc->state =377377+ HDLC_SEND_FAST_FLAG;378378+ else379379+ hdlc->state =380380+ HDLC_SENDFLAG_B0;396381 }397382398383 }399384 }400385401401- switch(hdlc->state){386386+ switch (hdlc->state) {402387 case STOPPED:403388 while (dsize--)404389 *dst++ = 0xff;···409388 return dsize;410389 case HDLC_SEND_FAST_FLAG:411390 hdlc->do_closing = 0;412412- if(slen == 0){391391+ if (slen == 0) {413392 *dst++ = hdlc->ffvalue;414393 len++;415394 dsize--;416395 break;417396 }418418- if(hdlc->bit_shift==8){419419- hdlc->cbin = hdlc->ffvalue>>(8-hdlc->data_bits);397397+ if (hdlc->bit_shift == 8) {398398+ hdlc->cbin = hdlc->ffvalue >>399399+ (8 - hdlc->data_bits);420400 hdlc->state = HDLC_SEND_DATA;421401 hdlc->crc = 0xffff;422402 hdlc->hdlc_bits1 = 0;···435413 hdlc->cbin <<= 1;436414 hdlc->data_bits++;437415 hdlc->cbin++;438438- if(++hdlc->hdlc_bits1 == 6)416416+ if (++hdlc->hdlc_bits1 == 6)439417 hdlc->state = HDLC_SENDFLAG_B7;440418 break;441419 case HDLC_SENDFLAG_B7:442420 hdlc->cbin <<= 1;443421 hdlc->data_bits++;444444- if(slen == 0){422422+ if (slen == 0) {445423 hdlc->state = HDLC_SENDFLAG_B0;446424 break;447425 }448448- if(hdlc->bit_shift==8){426426+ if (hdlc->bit_shift == 8) {449427 hdlc->state = HDLC_SEND_DATA;450428 hdlc->crc = 0xffff;451429 hdlc->hdlc_bits1 = 0;···454432 break;455433 case HDLC_SEND_FIRST_FLAG:456434 hdlc->data_received = 1;457457- if(hdlc->data_bits==8){435435+ if (hdlc->data_bits == 8) {458436 hdlc->state = HDLC_SEND_DATA;459437 hdlc->crc = 0xffff;460438 hdlc->hdlc_bits1 = 0;···462440 }463441 hdlc->cbin <<= 1;464442 hdlc->data_bits++;465465- if(hdlc->shift_reg & 0x01)443443+ if (hdlc->shift_reg & 0x01)466444 hdlc->cbin++;467445 hdlc->shift_reg >>= 1;468446 hdlc->bit_shift--;469469- if(hdlc->bit_shift==0){447447+ if (hdlc->bit_shift == 0) {470448 hdlc->state = HDLC_SEND_DATA;471449 hdlc->crc = 0xffff;472450 hdlc->hdlc_bits1 = 0;···475453 case HDLC_SEND_DATA:476454 hdlc->cbin <<= 1;477455 hdlc->data_bits++;478478- if(hdlc->hdlc_bits1 == 5){456456+ if (hdlc->hdlc_bits1 == 5) {479457 hdlc->hdlc_bits1 = 0;480458 break;481459 }482482- if(hdlc->bit_shift==8){483483- hdlc->crc = crc_ccitt_byte(hdlc->crc, hdlc->shift_reg);484484- }485485- if(hdlc->shift_reg & 0x01){460460+ if (hdlc->bit_shift == 8)461461+ hdlc->crc = crc_ccitt_byte(hdlc->crc,462462+ hdlc->shift_reg);463463+ if (hdlc->shift_reg & 0x01) {486464 hdlc->hdlc_bits1++;487465 hdlc->cbin++;488466 hdlc->shift_reg >>= 1;···496474 case HDLC_SEND_CRC1:497475 hdlc->cbin <<= 1;498476 hdlc->data_bits++;499499- if(hdlc->hdlc_bits1 == 5){477477+ if (hdlc->hdlc_bits1 == 5) {500478 hdlc->hdlc_bits1 = 0;501479 break;502480 }503503- if(hdlc->shift_reg & 0x01){481481+ if (hdlc->shift_reg & 0x01) {504482 hdlc->hdlc_bits1++;505483 hdlc->cbin++;506484 hdlc->shift_reg >>= 1;···510488 hdlc->shift_reg >>= 1;511489 hdlc->bit_shift--;512490 }513513- if(hdlc->bit_shift==0){491491+ if (hdlc->bit_shift == 0) {514492 hdlc->shift_reg = (hdlc->crc >> 8);515493 hdlc->state = HDLC_SEND_CRC2;516494 hdlc->bit_shift = 8;···519497 case HDLC_SEND_CRC2:520498 hdlc->cbin <<= 1;521499 hdlc->data_bits++;522522- if(hdlc->hdlc_bits1 == 5){500500+ if (hdlc->hdlc_bits1 == 5) {523501 hdlc->hdlc_bits1 = 0;524502 break;525503 }526526- if(hdlc->shift_reg & 0x01){504504+ if (hdlc->shift_reg & 0x01) {527505 hdlc->hdlc_bits1++;528506 hdlc->cbin++;529507 hdlc->shift_reg >>= 1;···533511 hdlc->shift_reg >>= 1;534512 hdlc->bit_shift--;535513 }536536- if(hdlc->bit_shift==0){514514+ if (hdlc->bit_shift == 0) {537515 hdlc->shift_reg = 0x7e;538516 hdlc->state = HDLC_SEND_CLOSING_FLAG;539517 hdlc->bit_shift = 8;···542520 case HDLC_SEND_CLOSING_FLAG:543521 hdlc->cbin <<= 1;544522 hdlc->data_bits++;545545- if(hdlc->hdlc_bits1 == 5){523523+ if (hdlc->hdlc_bits1 == 5) {546524 hdlc->hdlc_bits1 = 0;547525 break;548526 }549549- if(hdlc->shift_reg & 0x01){527527+ if (hdlc->shift_reg & 0x01)550528 hdlc->cbin++;551551- }552529 hdlc->shift_reg >>= 1;553530 hdlc->bit_shift--;554554- if(hdlc->bit_shift==0){555555- hdlc->ffvalue = xfast_flag_value[hdlc->data_bits];556556- if(hdlc->dchannel){531531+ if (hdlc->bit_shift == 0) {532532+ hdlc->ffvalue =533533+ xfast_flag_value[hdlc->data_bits];534534+ if (hdlc->dchannel) {557535 hdlc->ffvalue = 0x7e;558536 hdlc->state = HDLC_SEND_IDLE1;559537 hdlc->bit_shift = 8-hdlc->data_bits;560560- if(hdlc->bit_shift==0)561561- hdlc->state = HDLC_SEND_FAST_IDLE;538538+ if (hdlc->bit_shift == 0)539539+ hdlc->state =540540+ HDLC_SEND_FAST_IDLE;562541 } else {563563- if(!hdlc->do_adapt56){564564- hdlc->state = HDLC_SEND_FAST_FLAG;542542+ if (!hdlc->do_adapt56) {543543+ hdlc->state =544544+ HDLC_SEND_FAST_FLAG;565545 hdlc->data_received = 0;566546 } else {567547 hdlc->state = HDLC_SENDFLAG_B0;568548 hdlc->data_received = 0;569549 }570570- // Finished with this frame, send flags571571- if (dsize > 1) dsize = 1;550550+ /* Finished this frame, send flags */551551+ if (dsize > 1)552552+ dsize = 1;572553 }573554 }574555 break;···581556 hdlc->cbin++;582557 hdlc->data_bits++;583558 hdlc->bit_shift--;584584- if(hdlc->bit_shift==0){559559+ if (hdlc->bit_shift == 0) {585560 hdlc->state = HDLC_SEND_FAST_IDLE;586561 hdlc->bit_shift = 0;587562 }···590565 hdlc->do_closing = 0;591566 hdlc->cbin = 0xff;592567 hdlc->data_bits = 8;593593- if(hdlc->bit_shift == 8){568568+ if (hdlc->bit_shift == 8) {594569 hdlc->cbin = 0x7e;595570 hdlc->state = HDLC_SEND_FIRST_FLAG;596571 } else {597572 *dst++ = hdlc->cbin;598598- hdlc->bit_shift = hdlc->data_bits = 0;573573+ hdlc->bit_shift = 0;574574+ hdlc->data_bits = 0;599575 len++;600576 dsize = 0;601577 }···604578 default:605579 break;606580 }607607- if(hdlc->do_adapt56){608608- if(hdlc->data_bits==7){581581+ if (hdlc->do_adapt56) {582582+ if (hdlc->data_bits == 7) {609583 hdlc->cbin <<= 1;610584 hdlc->cbin++;611585 hdlc->data_bits++;612586 }613587 }614614- if(hdlc->data_bits==8){588588+ if (hdlc->data_bits == 8) {615589 *dst++ = hdlc->cbin;616590 hdlc->data_bits = 0;617591 len++;···622596623597 return len;624598}625625-626626-EXPORT_SYMBOL(isdnhdlc_rcv_init);627627-EXPORT_SYMBOL(isdnhdlc_decode);628628-EXPORT_SYMBOL(isdnhdlc_out_init);629599EXPORT_SYMBOL(isdnhdlc_encode);
+37-31
include/linux/isdn/hdlc.h
···11/*22- * isdnhdlc.h -- General purpose ISDN HDLC decoder.22+ * hdlc.h -- General purpose ISDN HDLC decoder.33 *44 * Implementation of a HDLC decoder/encoder in software.55 * Neccessary because some ISDN devices don't have HDLC66- * controllers. Also included: a bit reversal table.66+ * controllers.77 *88- *Copyright (C) 2002 Wolfgang Mües <wolfgang@iksw-muees.de>99- * 2001 Frode Isaksen <fisaksen@bewan.com>1010- * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>88+ * Copyright (C)99+ * 2002 Wolfgang Mües <wolfgang@iksw-muees.de>1010+ * 2001 Frode Isaksen <fisaksen@bewan.com>1111+ * 2001 Kai Germaschewski <kai.germaschewski@gmx.de>1112 *1212- * This program is free software; you can redistribute it and/or modify1313- * it under the terms of the GNU General Public License as published by1414- * the Free Software Foundation; either version 2 of the License, or1515- * (at your option) any later version.1313+ * This program is free software; you can redistribute it and/or modify1414+ * it under the terms of the GNU General Public License as published by1515+ * the Free Software Foundation; either version 2 of the License, or1616+ * (at your option) any later version.1617 *1717- * This program is distributed in the hope that it will be useful,1818- * but WITHOUT ANY WARRANTY; without even the implied warranty of1919- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the2020- * GNU General Public License for more details.1818+ * This program is distributed in the hope that it will be useful,1919+ * but WITHOUT ANY WARRANTY; without even the implied warranty of2020+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the2121+ * GNU General Public License for more details.2122 *2222- * You should have received a copy of the GNU General Public License2323- * along with this program; if not, write to the Free Software2424- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.2323+ * You should have received a copy of the GNU General Public License2424+ * along with this program; if not, write to the Free Software2525+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.2526 */26272728#ifndef __ISDNHDLC_H__···3231 int bit_shift;3332 int hdlc_bits1;3433 int data_bits;3535- int ffbit_shift; // encoding only3434+ int ffbit_shift; /* encoding only */3635 int state;3736 int dstpos;38373939- unsigned short crc;3838+ u16 crc;40394141- unsigned char cbin;4242- unsigned char shift_reg;4343- unsigned char ffvalue;4040+ u8 cbin;4141+ u8 shift_reg;4242+ u8 ffvalue;44434545- unsigned int data_received:1; // set if transferring data4646- unsigned int dchannel:1; // set if D channel (send idle instead of flags)4747- unsigned int do_adapt56:1; // set if 56K adaptation4848- unsigned int do_closing:1; // set if in closing phase (need to send CRC + flag4444+ /* set if transferring data */4545+ u32 data_received:1;4646+ /* set if D channel (send idle instead of flags) */4747+ u32 dchannel:1;4848+ /* set if 56K adaptation */4949+ u32 do_adapt56:1;5050+ /* set if in closing phase (need to send CRC + flag) */5151+ u32 do_closing:1;4952};50535154···6257#define HDLC_CRC_ERROR 26358#define HDLC_LENGTH_ERROR 364596565-extern void isdnhdlc_rcv_init (struct isdnhdlc_vars *hdlc, int do_adapt56);6060+extern void isdnhdlc_rcv_init(struct isdnhdlc_vars *hdlc, int do_adapt56);66616767-extern int isdnhdlc_decode (struct isdnhdlc_vars *hdlc, const unsigned char *src, int slen,int *count,6868- unsigned char *dst, int dsize);6262+extern int isdnhdlc_decode(struct isdnhdlc_vars *hdlc, const u8 *src,6363+ int slen, int *count, u8 *dst, int dsize);69647070-extern void isdnhdlc_out_init (struct isdnhdlc_vars *hdlc,int is_d_channel,int do_adapt56);6565+extern void isdnhdlc_out_init(struct isdnhdlc_vars *hdlc, int is_d_channel,6666+ int do_adapt56);71677272-extern int isdnhdlc_encode (struct isdnhdlc_vars *hdlc,const unsigned char *src,unsigned short slen,int *count,7373- unsigned char *dst,int dsize);6868+extern int isdnhdlc_encode(struct isdnhdlc_vars *hdlc, const u8 *src,6969+ u16 slen, int *count, u8 *dst, int dsize);74707571#endif /* __ISDNHDLC_H__ */