19 #include <linux/export.h>
26 static inline int muststuff(
unsigned char c)
49 static unsigned cmd_loop(
unsigned numbytes,
struct inbuf_t *
inbuf)
54 unsigned procbytes = 0;
57 while (procbytes < numbytes) {
63 if (cbytes == 0 && cs->
respdata[0] ==
'\r') {
121 static unsigned lock_loop(
unsigned numbytes,
struct inbuf_t *inbuf)
123 unsigned char *src = inbuf->
data + inbuf->
head;
138 static unsigned hdlc_loop(
unsigned numbytes,
struct inbuf_t *inbuf)
145 unsigned char *src = inbuf->
data + inbuf->
head;
146 unsigned procbytes = 0;
152 inputstate &= ~INS_byte_stuff;
156 while (procbytes < numbytes) {
162 inputstate &= ~INS_DLE_char;
172 if (procbytes >= numbytes) {
181 if (inputstate & INS_DLE_char) {
183 inputstate &= ~INS_DLE_char;
184 }
else if (cs->
dle ||
193 #ifdef CONFIG_GIGASET_DEBUG
201 "7e----------------------------");
207 }
else if (skb->
len < 2) {
210 "short frame (%d)\n",
217 "Checksum failed, %u bytes corrupted!\n",
223 __skb_trim(skb, skb->
len - 2);
228 inputstate &= ~INS_have_data;
229 skb = gigaset_new_rx_skb(bcs);
232 #ifdef CONFIG_GIGASET_DEBUG
238 skb = gigaset_new_rx_skb(bcs);
244 #ifdef CONFIG_GIGASET_DEBUG
245 }
else if (muststuff(c)) {
252 #ifdef CONFIG_GIGASET_DEBUG
253 if (!(inputstate & INS_have_data)) {
267 *__skb_put(skb, 1) =
c;
268 fcs = crc_ccitt_byte(fcs, c);
285 static unsigned iraw_loop(
unsigned numbytes,
struct inbuf_t *inbuf)
291 unsigned char *src = inbuf->
data + inbuf->
head;
292 unsigned procbytes = 0;
297 gigaset_new_rx_skb(bcs);
301 while (procbytes < numbytes && skb->len < bcs->rx_bufsize) {
306 if (inputstate & INS_DLE_char) {
308 inputstate &= ~INS_DLE_char;
318 *__skb_put(skb, 1) = bitrev8(c);
322 if (inputstate & INS_have_data) {
324 inputstate &= ~INS_have_data;
325 gigaset_new_rx_skb(bcs);
338 static void handle_dle(
struct inbuf_t *inbuf)
370 "received <DLE>X in command mode\n");
377 "received <DLE>. without <DLE>X\n");
389 "received <DLE><DLE> not in DLE mode\n");
392 dev_notice(cs->
dev,
"received <DLE><%02x>\n",
410 unsigned numbytes, procbytes;
414 while (inbuf->
head != inbuf->
tail) {
419 numbytes = (inbuf->
head > inbuf->
tail ?
428 procbytes = lock_loop(numbytes, inbuf);
430 procbytes = cmd_loop(numbytes, inbuf);
432 procbytes = hdlc_loop(numbytes, inbuf);
434 procbytes = iraw_loop(numbytes, inbuf);
435 inbuf->
head += procbytes;
465 unsigned int stuf_cnt;
474 fcs = crc_ccitt_byte(fcs, *cp++);
482 hdlc_skb = dev_alloc_skb(skb->
len + stuf_cnt + 6 + skb->
mac_len);
489 skb_reset_mac_header(hdlc_skb);
490 skb_reserve(hdlc_skb, skb->
mac_len);
491 memcpy(skb_mac_header(hdlc_skb), skb_mac_header(skb), skb->
mac_len);
499 if (muststuff(*skb->
data)) {
514 c = ((fcs >> 8) & 0x00ff);
546 iraw_skb = dev_alloc_skb(2 * skb->
len + skb->
mac_len);
553 skb_reset_mac_header(iraw_skb);
554 skb_reserve(iraw_skb, skb->
mac_len);
555 memcpy(skb_mac_header(iraw_skb), skb_mac_header(skb), skb->
mac_len);
588 unsigned len = skb->
len;
592 skb = HDLC_Encode(skb);
594 skb = iraw_encode(skb);
597 "unable to allocate memory for encoding!\n");
605 spin_unlock_irqrestore(&cs->
lock, flags);