45 #include <linux/capability.h>
46 #include <linux/module.h>
47 #include <linux/types.h>
48 #include <linux/net.h>
51 #include <linux/errno.h>
53 #include <linux/bitops.h>
55 #include <linux/netdevice.h>
56 #include <linux/if_arp.h>
58 #include <linux/hdlcdrv.h>
59 #include <linux/random.h>
61 #include <asm/uaccess.h>
71 #define PARAM_TXDELAY 1
72 #define PARAM_PERSIST 2
73 #define PARAM_SLOTTIME 3
74 #define PARAM_TXTAIL 4
75 #define PARAM_FULLDUP 5
76 #define PARAM_HARDWARE 6
77 #define PARAM_RETURN 255
88 static inline void append_crc_ccitt(
unsigned char *
buffer,
int len)
90 unsigned int crc =
crc_ccitt(0xffff, buffer, len) ^ 0xffff;
98 static inline int check_crc_ccitt(
const unsigned char *
buf,
int cnt)
100 return (
crc_ccitt(0xffff, buf, cnt) & 0xffff) == 0xf0b8;
106 static int calc_crc_ccitt(
const unsigned char *buf,
int cnt)
108 unsigned int crc = 0xffff;
110 for (; cnt > 0; cnt--)
119 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16)
131 while (s->
hdlcrx.rx_state && num >= 8) {
136 *s->
hdlcrx.bp++ = bits >> (32-num);
154 pkt_len = s->
hdlcrx.len - 2 + 1;
155 if (!(skb = dev_alloc_skb(pkt_len))) {
156 printk(
"%s: memory squeeze, dropping packet\n", dev->
name);
157 dev->
stats.rx_dropped++;
163 skb->
protocol = ax25_type_trans(skb, dev);
165 dev->
stats.rx_packets++;
171 unsigned int mask1, mask2, mask3, mask4, mask5, mask6,
word;
178 while (!hdlcdrv_hbuf_empty(&s->
hdlcrx.hbuf)) {
179 word = hdlcdrv_hbuf_get(&s->
hdlcrx.hbuf);
184 s->
hdlcrx.bitstream >>= 16;
185 s->
hdlcrx.bitstream |= word << 16;
187 s->
hdlcrx.bitbuf |= word << 16;
189 for(i = 15, mask1 = 0x1fc00, mask2 = 0x1fe00, mask3 = 0x0fc00,
190 mask4 = 0x1f800, mask5 = 0xf800, mask6 = 0xffff;
192 i--, mask1 <<= 1, mask2 <<= 1, mask3 <<= 1, mask4 <<= 1,
193 mask5 <<= 1, mask6 = (mask6 << 1) | 1) {
194 if ((s->
hdlcrx.bitstream & mask1) == mask1)
196 else if ((s->
hdlcrx.bitstream & mask2) == mask3) {
199 hdlc_rx_add_bytes(s, s->
hdlcrx.bitbuf
203 hdlc_rx_flag(dev, s);
209 }
else if ((s->
hdlcrx.bitstream & mask4) == mask5) {
213 ((s->
hdlcrx.bitbuf & mask6) << 1);
216 s->
hdlcrx.numbits -= hdlc_rx_add_bytes(s, s->
hdlcrx.bitbuf,
225 unsigned char *
data,
unsigned long len)
229 #define PKP(a,b) printk(KERN_INFO "hdlcdrv.c: channel params: " a "\n", b)
255 PKP(
"%s duplex", s->
ch_params.fulldup ?
"full" :
"half");
267 unsigned int mask1, mask2, mask3;
277 if (s->
hdlctx.numbits >= 16) {
278 if (hdlcdrv_hbuf_full(&s->
hdlctx.hbuf)) {
286 switch (s->
hdlctx.tx_state) {
295 0x7e7e << s->
hdlctx.numbits;
299 if (s->
hdlctx.tx_state == 1) {
303 if (!(skb = s->
skb)) {
308 s->
hdlctx.numflags = flgs;
312 netif_wake_queue(dev);
313 pkt_len = skb->
len-1;
320 skb_copy_from_linear_data_offset(skb, 1,
325 append_crc_ccitt(s->
hdlctx.buffer, pkt_len);
326 s->
hdlctx.len = pkt_len+2;
329 dev->
stats.tx_packets++;
340 s->
hdlctx.bitstream >>= 8;
344 mask3 = 0xffffffff >> (31-s->
hdlctx.numbits);
346 for(i = 0; i < 8; i++, mask1 <<= 1, mask2 <<= 1,
347 mask3 = (mask3 << 1) | 1) {
348 if ((s->
hdlctx.bitstream & mask1) != mask1)
350 s->
hdlctx.bitstream &= ~mask2;
352 (s->
hdlctx.bitbuf & mask3) |
356 mask3 = (mask3 << 1) | 1;
389 if ((--s->
hdlctx.slotcnt) > 0)
407 if (skb->
data[0] != 0) {
408 do_kiss_params(sm, skb->
data, skb->
len);
414 netif_stop_queue(dev);
421 static int hdlcdrv_set_mac_address(
struct net_device *dev,
void *
addr)
440 static int hdlcdrv_open(
struct net_device *dev)
445 if (!s->
ops || !s->
ops->open)
465 i = s->
ops->open(dev);
468 netif_start_queue(dev);
477 static int hdlcdrv_close(
struct net_device *dev)
482 netif_stop_queue(dev);
484 if (s->
ops && s->
ops->close)
485 i = s->
ops->close(dev);
487 dev_kfree_skb(s->
skb);
501 if (s->
ops && s->
ops->ioctl)
502 return s->
ops->ioctl(dev, ifr, &
bi, cmd);
510 if (s->
ops && s->
ops->ioctl)
511 return s->
ops->ioctl(dev, ifr, &
bi, cmd);
535 bi.data.mp.irq = dev->
irq;
536 bi.data.mp.dma = dev->
dma;
538 bi.data.mp.seriobase = s->
ptt_out.seriobase;
539 bi.data.mp.pariobase = s->
ptt_out.pariobase;
540 bi.data.mp.midiiobase = s->
ptt_out.midiiobase;
547 dev->
irq =
bi.data.mp.irq;
548 dev->
dma =
bi.data.mp.dma;
550 s->
ptt_out.seriobase =
bi.data.mp.seriobase;
551 s->
ptt_out.pariobase =
bi.data.mp.pariobase;
552 s->
ptt_out.midiiobase =
bi.data.mp.midiiobase;
556 bi.data.cs.ptt = hdlcdrv_ptt(s);
559 bi.data.cs.tx_packets = dev->
stats.tx_packets;
560 bi.data.cs.tx_errors = dev->
stats.tx_errors;
561 bi.data.cs.rx_packets = dev->
stats.rx_packets;
562 bi.data.cs.rx_errors = dev->
stats.rx_errors;
566 bi.data.ocs.ptt = hdlcdrv_ptt(s);
574 s->
hdlctx.calibrate =
bi.data.calibrate * s->
par.bitrate / 16;
578 #ifndef HDLCDRV_DEBUG
591 #ifndef HDLCDRV_DEBUG
604 if (s->
ops && s->
ops->drvname) {
606 sizeof(
bi.data.drivername));
609 bi.data.drivername[0] =
'\0';
622 .ndo_open = hdlcdrv_open,
623 .ndo_stop = hdlcdrv_close,
624 .ndo_start_xmit = hdlcdrv_send_packet,
626 .ndo_set_mac_address = hdlcdrv_set_mac_address,
632 static void hdlcdrv_setup(
struct net_device *dev)
687 unsigned int privsize,
const char *ifname,
688 unsigned int baseaddr,
unsigned int irq,
707 s = netdev_priv(dev);
717 "device %s\n", dev->
name);
749 static int __init hdlcdrv_init_driver(
void)
751 printk(
KERN_INFO "hdlcdrv: (C) 1996-2000 Thomas Sailer HB9JNX/AE4WA\n");
758 static void __exit hdlcdrv_cleanup_driver(
void)