1 /*****************************************************************************/
4 * hdlcdrv.c -- HDLC packet radio network driver.
6 * Copyright (C) 1996-2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
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.
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.
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.
22 * Please note that the GPL allows you to use the driver, NOT the radio.
23 * In order to use the radio, you need a license from the communications
24 * authority of your country.
26 * The driver was derived from Donald Beckers skeleton.c
27 * Written 1993-94 by Donald Becker.
30 * 0.1 21.09.1996 Started
31 * 18.10.1996 Changed to new user space access routines
32 * (copy_{to,from}_user)
33 * 0.2 21.11.1996 various small changes
34 * 0.3 03.03.1997 fixed (hopefully) IP not working with ax.25 as a module
35 * 0.4 16.04.1997 init code/data tagged
36 * 0.5 30.07.1997 made HDLC buffers bigger (solves a problem with the
38 * 0.6 05.04.1998 add spinlocks
39 * 0.7 03.08.1999 removed some old compatibility cruft
40 * 0.8 12.02.2000 adapted to softnet driver interface
43 /*****************************************************************************/
45 #include <linux/config.h>
46 #include <linux/module.h>
47 #include <linux/types.h>
48 #include <linux/net.h>
51 #include <linux/slab.h>
52 #include <linux/errno.h>
53 #include <linux/init.h>
54 #include <asm/bitops.h>
55 #include <asm/uaccess.h>
57 #include <linux/netdevice.h>
58 #include <linux/if_arp.h>
59 #include <linux/etherdevice.h>
60 #include <linux/skbuff.h>
61 #include <linux/hdlcdrv.h>
62 /* prototypes for ax25_encapsulate and ax25_rebuild_header */
65 /* make genksyms happy */
67 #include <linux/udp.h>
68 #include <linux/tcp.h>
69 #include <linux/crc-ccitt.h>
71 /* --------------------------------------------------------------------- */
74 * The name of the card. Is used for messages and in the requests for
75 * io regions, irqs and dma channels
78 static char ax25_bcast
[AX25_ADDR_LEN
] =
79 {'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
80 static char ax25_nocall
[AX25_ADDR_LEN
] =
81 {'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
83 /* --------------------------------------------------------------------- */
87 /* --------------------------------------------------------------------- */
89 #define PARAM_TXDELAY 1
90 #define PARAM_PERSIST 2
91 #define PARAM_SLOTTIME 3
92 #define PARAM_TXTAIL 4
93 #define PARAM_FULLDUP 5
94 #define PARAM_HARDWARE 6
95 #define PARAM_RETURN 255
97 /* --------------------------------------------------------------------- */
99 * the CRC routines are stolen from WAMPES
104 /*---------------------------------------------------------------------------*/
106 static inline void append_crc_ccitt(unsigned char *buffer
, int len
)
108 unsigned int crc
= crc_ccitt(0xffff, buffer
, len
) ^ 0xffff;
110 *buffer
++ = crc
>> 8;
113 /*---------------------------------------------------------------------------*/
115 static inline int check_crc_ccitt(const unsigned char *buf
, int cnt
)
117 return (crc_ccitt(0xffff, buf
, cnt
) & 0xffff) == 0xf0b8;
120 /*---------------------------------------------------------------------------*/
123 static int calc_crc_ccitt(const unsigned char *buf
, int cnt
)
125 unsigned int crc
= 0xffff;
127 for (; cnt
> 0; cnt
--)
128 crc
= (crc
>> 8) ^ crc_ccitt_table
[(crc
^ *buf
++) & 0xff];
130 return (crc
& 0xffff);
134 /* ---------------------------------------------------------------------- */
136 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16)
138 /* ---------------------------------------------------------------------- */
143 static int hdlc_rx_add_bytes(struct hdlcdrv_state
*s
, unsigned int bits
,
148 while (s
->hdlcrx
.rx_state
&& num
>= 8) {
149 if (s
->hdlcrx
.len
>= sizeof(s
->hdlcrx
.buffer
)) {
150 s
->hdlcrx
.rx_state
= 0;
153 *s
->hdlcrx
.bp
++ = bits
>> (32-num
);
161 static void hdlc_rx_flag(struct net_device
*dev
, struct hdlcdrv_state
*s
)
167 if (s
->hdlcrx
.len
< 4)
169 if (!check_crc_ccitt(s
->hdlcrx
.buffer
, s
->hdlcrx
.len
))
171 pkt_len
= s
->hdlcrx
.len
- 2 + 1; /* KISS kludge */
172 if (!(skb
= dev_alloc_skb(pkt_len
))) {
173 printk("%s: memory squeeze, dropping packet\n", dev
->name
);
174 s
->stats
.rx_dropped
++;
178 cp
= skb_put(skb
, pkt_len
);
179 *cp
++ = 0; /* KISS kludge */
180 memcpy(cp
, s
->hdlcrx
.buffer
, pkt_len
- 1);
181 skb
->protocol
= htons(ETH_P_AX25
);
182 skb
->mac
.raw
= skb
->data
;
184 dev
->last_rx
= jiffies
;
185 s
->stats
.rx_packets
++;
188 void hdlcdrv_receiver(struct net_device
*dev
, struct hdlcdrv_state
*s
)
191 unsigned int mask1
, mask2
, mask3
, mask4
, mask5
, mask6
, word
;
193 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
195 if (test_and_set_bit(0, &s
->hdlcrx
.in_hdlc_rx
))
198 while (!hdlcdrv_hbuf_empty(&s
->hdlcrx
.hbuf
)) {
199 word
= hdlcdrv_hbuf_get(&s
->hdlcrx
.hbuf
);
202 hdlcdrv_add_bitbuffer_word(&s
->bitbuf_hdlc
, word
);
203 #endif /* HDLCDRV_DEBUG */
204 s
->hdlcrx
.bitstream
>>= 16;
205 s
->hdlcrx
.bitstream
|= word
<< 16;
206 s
->hdlcrx
.bitbuf
>>= 16;
207 s
->hdlcrx
.bitbuf
|= word
<< 16;
208 s
->hdlcrx
.numbits
+= 16;
209 for(i
= 15, mask1
= 0x1fc00, mask2
= 0x1fe00, mask3
= 0x0fc00,
210 mask4
= 0x1f800, mask5
= 0xf800, mask6
= 0xffff;
212 i
--, mask1
<<= 1, mask2
<<= 1, mask3
<<= 1, mask4
<<= 1,
213 mask5
<<= 1, mask6
= (mask6
<< 1) | 1) {
214 if ((s
->hdlcrx
.bitstream
& mask1
) == mask1
)
215 s
->hdlcrx
.rx_state
= 0; /* abort received */
216 else if ((s
->hdlcrx
.bitstream
& mask2
) == mask3
) {
218 if (s
->hdlcrx
.rx_state
) {
219 hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
223 hdlc_rx_flag(dev
, s
);
226 s
->hdlcrx
.bp
= s
->hdlcrx
.buffer
;
227 s
->hdlcrx
.rx_state
= 1;
228 s
->hdlcrx
.numbits
= i
;
229 } else if ((s
->hdlcrx
.bitstream
& mask4
) == mask5
) {
232 s
->hdlcrx
.bitbuf
= (s
->hdlcrx
.bitbuf
& (~mask6
)) |
233 ((s
->hdlcrx
.bitbuf
& mask6
) << 1);
236 s
->hdlcrx
.numbits
-= hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
,
239 clear_bit(0, &s
->hdlcrx
.in_hdlc_rx
);
242 /* ---------------------------------------------------------------------- */
244 static inline void do_kiss_params(struct hdlcdrv_state
*s
,
245 unsigned char *data
, unsigned long len
)
249 #define PKP(a,b) printk(KERN_INFO "hdlcdrv.c: channel params: " a "\n", b)
250 #else /* KISS_VERBOSE */
252 #endif /* KISS_VERBOSE */
258 s
->ch_params
.tx_delay
= data
[1];
259 PKP("TX delay = %ums", 10 * s
->ch_params
.tx_delay
);
262 s
->ch_params
.ppersist
= data
[1];
263 PKP("p persistence = %u", s
->ch_params
.ppersist
);
266 s
->ch_params
.slottime
= data
[1];
267 PKP("slot time = %ums", s
->ch_params
.slottime
);
270 s
->ch_params
.tx_tail
= data
[1];
271 PKP("TX tail = %ums", s
->ch_params
.tx_tail
);
274 s
->ch_params
.fulldup
= !!data
[1];
275 PKP("%s duplex", s
->ch_params
.fulldup
? "full" : "half");
283 /* ---------------------------------------------------------------------- */
285 void hdlcdrv_transmitter(struct net_device
*dev
, struct hdlcdrv_state
*s
)
287 unsigned int mask1
, mask2
, mask3
;
292 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
294 if (test_and_set_bit(0, &s
->hdlctx
.in_hdlc_tx
))
297 if (s
->hdlctx
.numbits
>= 16) {
298 if (hdlcdrv_hbuf_full(&s
->hdlctx
.hbuf
)) {
299 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
302 hdlcdrv_hbuf_put(&s
->hdlctx
.hbuf
, s
->hdlctx
.bitbuf
);
303 s
->hdlctx
.bitbuf
>>= 16;
304 s
->hdlctx
.numbits
-= 16;
306 switch (s
->hdlctx
.tx_state
) {
308 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
312 if (s
->hdlctx
.numflags
) {
313 s
->hdlctx
.numflags
--;
315 0x7e7e << s
->hdlctx
.numbits
;
316 s
->hdlctx
.numbits
+= 16;
319 if (s
->hdlctx
.tx_state
== 1) {
320 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
323 if (!(skb
= s
->skb
)) {
324 int flgs
= tenms_to_2flags(s
, s
->ch_params
.tx_tail
);
327 s
->hdlctx
.tx_state
= 1;
328 s
->hdlctx
.numflags
= flgs
;
332 netif_wake_queue(dev
);
333 pkt_len
= skb
->len
-1; /* strip KISS byte */
334 if (pkt_len
>= HDLCDRV_MAXFLEN
|| pkt_len
< 2) {
335 s
->hdlctx
.tx_state
= 0;
336 s
->hdlctx
.numflags
= 1;
337 dev_kfree_skb_irq(skb
);
340 memcpy(s
->hdlctx
.buffer
, skb
->data
+1, pkt_len
);
341 dev_kfree_skb_irq(skb
);
342 s
->hdlctx
.bp
= s
->hdlctx
.buffer
;
343 append_crc_ccitt(s
->hdlctx
.buffer
, pkt_len
);
344 s
->hdlctx
.len
= pkt_len
+2; /* the appended CRC */
345 s
->hdlctx
.tx_state
= 2;
346 s
->hdlctx
.bitstream
= 0;
347 s
->stats
.tx_packets
++;
350 if (!s
->hdlctx
.len
) {
351 s
->hdlctx
.tx_state
= 0;
352 s
->hdlctx
.numflags
= 1;
356 s
->hdlctx
.bitbuf
|= *s
->hdlctx
.bp
<<
358 s
->hdlctx
.bitstream
>>= 8;
359 s
->hdlctx
.bitstream
|= (*s
->hdlctx
.bp
++) << 16;
362 mask3
= 0xffffffff >> (31-s
->hdlctx
.numbits
);
363 s
->hdlctx
.numbits
+= 8;
364 for(i
= 0; i
< 8; i
++, mask1
<<= 1, mask2
<<= 1,
365 mask3
= (mask3
<< 1) | 1) {
366 if ((s
->hdlctx
.bitstream
& mask1
) != mask1
)
368 s
->hdlctx
.bitstream
&= ~mask2
;
370 (s
->hdlctx
.bitbuf
& mask3
) |
374 mask3
= (mask3
<< 1) | 1;
381 /* ---------------------------------------------------------------------- */
383 static void start_tx(struct net_device
*dev
, struct hdlcdrv_state
*s
)
385 s
->hdlctx
.tx_state
= 0;
386 s
->hdlctx
.numflags
= tenms_to_2flags(s
, s
->ch_params
.tx_delay
);
387 s
->hdlctx
.bitbuf
= s
->hdlctx
.bitstream
= s
->hdlctx
.numbits
= 0;
388 hdlcdrv_transmitter(dev
, s
);
393 /* ---------------------------------------------------------------------- */
395 static unsigned short random_seed
;
397 static inline unsigned short random_num(void)
399 random_seed
= 28629 * random_seed
+ 157;
403 /* ---------------------------------------------------------------------- */
405 void hdlcdrv_arbitrate(struct net_device
*dev
, struct hdlcdrv_state
*s
)
407 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
|| s
->hdlctx
.ptt
|| !s
->skb
)
409 if (s
->ch_params
.fulldup
) {
414 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
417 if ((--s
->hdlctx
.slotcnt
) > 0)
419 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
420 if ((random_num() % 256) > s
->ch_params
.ppersist
)
425 /* --------------------------------------------------------------------- */
427 * ===================== network driver interface =========================
430 static inline int hdlcdrv_paranoia_check(struct net_device
*dev
,
433 if (!dev
|| !dev
->priv
||
434 ((struct hdlcdrv_state
*)dev
->priv
)->magic
!= HDLCDRV_MAGIC
) {
435 printk(KERN_ERR
"hdlcdrv: bad magic number for hdlcdrv_state "
436 "struct in routine %s\n", routine
);
442 /* --------------------------------------------------------------------- */
444 static int hdlcdrv_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
446 struct hdlcdrv_state
*sm
;
448 if (hdlcdrv_paranoia_check(dev
, "hdlcdrv_send_packet"))
450 sm
= (struct hdlcdrv_state
*)dev
->priv
;
451 if (skb
->data
[0] != 0) {
452 do_kiss_params(sm
, skb
->data
, skb
->len
);
458 netif_stop_queue(dev
);
463 /* --------------------------------------------------------------------- */
465 static int hdlcdrv_set_mac_address(struct net_device
*dev
, void *addr
)
467 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
469 /* addr is an AX.25 shifted ASCII mac address */
470 memcpy(dev
->dev_addr
, sa
->sa_data
, dev
->addr_len
);
474 /* --------------------------------------------------------------------- */
476 static struct net_device_stats
*hdlcdrv_get_stats(struct net_device
*dev
)
478 struct hdlcdrv_state
*sm
;
480 if (hdlcdrv_paranoia_check(dev
, "hdlcdrv_get_stats"))
482 sm
= (struct hdlcdrv_state
*)dev
->priv
;
484 * Get the current statistics. This may be called with the
485 * card open or closed.
490 /* --------------------------------------------------------------------- */
492 * Open/initialize the board. This is called (in the current kernel)
493 * sometime after booting when the 'ifconfig' program is run.
495 * This routine should set everything up anew at each open, even
496 * registers that "should" only need to be set once at boot, so that
497 * there is non-reboot way to recover if something goes wrong.
500 static int hdlcdrv_open(struct net_device
*dev
)
502 struct hdlcdrv_state
*s
;
505 if (hdlcdrv_paranoia_check(dev
, "hdlcdrv_open"))
507 s
= (struct hdlcdrv_state
*)dev
->priv
;
509 if (!s
->ops
|| !s
->ops
->open
)
513 * initialise some variables
516 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
517 s
->hdlcrx
.in_hdlc_rx
= 0;
518 s
->hdlcrx
.rx_state
= 0;
520 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
521 s
->hdlctx
.in_hdlc_tx
= 0;
522 s
->hdlctx
.tx_state
= 1;
523 s
->hdlctx
.numflags
= 0;
524 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
526 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
527 s
->hdlctx
.calibrate
= 0;
529 i
= s
->ops
->open(dev
);
532 netif_start_queue(dev
);
536 /* --------------------------------------------------------------------- */
538 * The inverse routine to hdlcdrv_open().
541 static int hdlcdrv_close(struct net_device
*dev
)
543 struct hdlcdrv_state
*s
;
546 if (hdlcdrv_paranoia_check(dev
, "hdlcdrv_close"))
548 s
= (struct hdlcdrv_state
*)dev
->priv
;
550 netif_stop_queue(dev
);
552 if (s
->ops
&& s
->ops
->close
)
553 i
= s
->ops
->close(dev
);
555 dev_kfree_skb(s
->skb
);
561 /* --------------------------------------------------------------------- */
563 static int hdlcdrv_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
565 struct hdlcdrv_state
*s
;
566 struct hdlcdrv_ioctl bi
;
568 if (hdlcdrv_paranoia_check(dev
, "hdlcdrv_ioctl"))
570 s
= (struct hdlcdrv_state
*)dev
->priv
;
572 if (cmd
!= SIOCDEVPRIVATE
) {
573 if (s
->ops
&& s
->ops
->ioctl
)
574 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
577 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
582 if (s
->ops
&& s
->ops
->ioctl
)
583 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
586 case HDLCDRVCTL_GETCHANNELPAR
:
587 bi
.data
.cp
.tx_delay
= s
->ch_params
.tx_delay
;
588 bi
.data
.cp
.tx_tail
= s
->ch_params
.tx_tail
;
589 bi
.data
.cp
.slottime
= s
->ch_params
.slottime
;
590 bi
.data
.cp
.ppersist
= s
->ch_params
.ppersist
;
591 bi
.data
.cp
.fulldup
= s
->ch_params
.fulldup
;
594 case HDLCDRVCTL_SETCHANNELPAR
:
595 if (!capable(CAP_NET_ADMIN
))
597 s
->ch_params
.tx_delay
= bi
.data
.cp
.tx_delay
;
598 s
->ch_params
.tx_tail
= bi
.data
.cp
.tx_tail
;
599 s
->ch_params
.slottime
= bi
.data
.cp
.slottime
;
600 s
->ch_params
.ppersist
= bi
.data
.cp
.ppersist
;
601 s
->ch_params
.fulldup
= bi
.data
.cp
.fulldup
;
602 s
->hdlctx
.slotcnt
= 1;
605 case HDLCDRVCTL_GETMODEMPAR
:
606 bi
.data
.mp
.iobase
= dev
->base_addr
;
607 bi
.data
.mp
.irq
= dev
->irq
;
608 bi
.data
.mp
.dma
= dev
->dma
;
609 bi
.data
.mp
.dma2
= s
->ptt_out
.dma2
;
610 bi
.data
.mp
.seriobase
= s
->ptt_out
.seriobase
;
611 bi
.data
.mp
.pariobase
= s
->ptt_out
.pariobase
;
612 bi
.data
.mp
.midiiobase
= s
->ptt_out
.midiiobase
;
615 case HDLCDRVCTL_SETMODEMPAR
:
616 if ((!capable(CAP_SYS_RAWIO
)) || netif_running(dev
))
618 dev
->base_addr
= bi
.data
.mp
.iobase
;
619 dev
->irq
= bi
.data
.mp
.irq
;
620 dev
->dma
= bi
.data
.mp
.dma
;
621 s
->ptt_out
.dma2
= bi
.data
.mp
.dma2
;
622 s
->ptt_out
.seriobase
= bi
.data
.mp
.seriobase
;
623 s
->ptt_out
.pariobase
= bi
.data
.mp
.pariobase
;
624 s
->ptt_out
.midiiobase
= bi
.data
.mp
.midiiobase
;
627 case HDLCDRVCTL_GETSTAT
:
628 bi
.data
.cs
.ptt
= hdlcdrv_ptt(s
);
629 bi
.data
.cs
.dcd
= s
->hdlcrx
.dcd
;
630 bi
.data
.cs
.ptt_keyed
= s
->ptt_keyed
;
631 bi
.data
.cs
.tx_packets
= s
->stats
.tx_packets
;
632 bi
.data
.cs
.tx_errors
= s
->stats
.tx_errors
;
633 bi
.data
.cs
.rx_packets
= s
->stats
.rx_packets
;
634 bi
.data
.cs
.rx_errors
= s
->stats
.rx_errors
;
637 case HDLCDRVCTL_OLDGETSTAT
:
638 bi
.data
.ocs
.ptt
= hdlcdrv_ptt(s
);
639 bi
.data
.ocs
.dcd
= s
->hdlcrx
.dcd
;
640 bi
.data
.ocs
.ptt_keyed
= s
->ptt_keyed
;
643 case HDLCDRVCTL_CALIBRATE
:
644 if(!capable(CAP_SYS_RAWIO
))
646 s
->hdlctx
.calibrate
= bi
.data
.calibrate
* s
->par
.bitrate
/ 16;
649 case HDLCDRVCTL_GETSAMPLES
:
650 #ifndef HDLCDRV_DEBUG
652 #else /* HDLCDRV_DEBUG */
653 if (s
->bitbuf_channel
.rd
== s
->bitbuf_channel
.wr
)
656 s
->bitbuf_channel
.buffer
[s
->bitbuf_channel
.rd
];
657 s
->bitbuf_channel
.rd
= (s
->bitbuf_channel
.rd
+1) %
658 sizeof(s
->bitbuf_channel
.buffer
);
660 #endif /* HDLCDRV_DEBUG */
662 case HDLCDRVCTL_GETBITS
:
663 #ifndef HDLCDRV_DEBUG
665 #else /* HDLCDRV_DEBUG */
666 if (s
->bitbuf_hdlc
.rd
== s
->bitbuf_hdlc
.wr
)
669 s
->bitbuf_hdlc
.buffer
[s
->bitbuf_hdlc
.rd
];
670 s
->bitbuf_hdlc
.rd
= (s
->bitbuf_hdlc
.rd
+1) %
671 sizeof(s
->bitbuf_hdlc
.buffer
);
673 #endif /* HDLCDRV_DEBUG */
675 case HDLCDRVCTL_DRIVERNAME
:
676 if (s
->ops
&& s
->ops
->drvname
) {
677 strncpy(bi
.data
.drivername
, s
->ops
->drvname
,
678 sizeof(bi
.data
.drivername
));
681 bi
.data
.drivername
[0] = '\0';
685 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
691 /* --------------------------------------------------------------------- */
694 * Initialize fields in hdlcdrv
696 static void hdlcdrv_setup(struct net_device
*dev
)
698 static const struct hdlcdrv_channel_params dflt_ch_params
= {
701 struct hdlcdrv_state
*s
= dev
->priv
;
704 * initialize the hdlcdrv_state struct
706 s
->ch_params
= dflt_ch_params
;
709 spin_lock_init(&s
->hdlcrx
.hbuf
.lock
);
710 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
711 s
->hdlcrx
.in_hdlc_rx
= 0;
712 s
->hdlcrx
.rx_state
= 0;
714 spin_lock_init(&s
->hdlctx
.hbuf
.lock
);
715 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
716 s
->hdlctx
.in_hdlc_tx
= 0;
717 s
->hdlctx
.tx_state
= 1;
718 s
->hdlctx
.numflags
= 0;
719 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
721 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
722 s
->hdlctx
.calibrate
= 0;
725 s
->bitbuf_channel
.rd
= s
->bitbuf_channel
.wr
= 0;
726 s
->bitbuf_channel
.shreg
= 0x80;
728 s
->bitbuf_hdlc
.rd
= s
->bitbuf_hdlc
.wr
= 0;
729 s
->bitbuf_hdlc
.shreg
= 0x80;
730 #endif /* HDLCDRV_DEBUG */
733 * initialize the device struct
735 dev
->open
= hdlcdrv_open
;
736 dev
->stop
= hdlcdrv_close
;
737 dev
->do_ioctl
= hdlcdrv_ioctl
;
738 dev
->hard_start_xmit
= hdlcdrv_send_packet
;
739 dev
->get_stats
= hdlcdrv_get_stats
;
741 /* Fill in the fields of the device structure */
745 #if defined(CONFIG_AX25) || defined(CONFIG_AX25_MODULE)
746 dev
->hard_header
= ax25_encapsulate
;
747 dev
->rebuild_header
= ax25_rebuild_header
;
748 #else /* CONFIG_AX25 || CONFIG_AX25_MODULE */
749 dev
->hard_header
= NULL
;
750 dev
->rebuild_header
= NULL
;
751 #endif /* CONFIG_AX25 || CONFIG_AX25_MODULE */
752 dev
->set_mac_address
= hdlcdrv_set_mac_address
;
754 dev
->type
= ARPHRD_AX25
; /* AF_AX25 device */
755 dev
->hard_header_len
= AX25_MAX_HEADER_LEN
+ AX25_BPQ_HEADER_LEN
;
756 dev
->mtu
= AX25_DEF_PACLEN
; /* eth_mtu is the default */
757 dev
->addr_len
= AX25_ADDR_LEN
; /* sizeof an ax.25 address */
758 memcpy(dev
->broadcast
, ax25_bcast
, AX25_ADDR_LEN
);
759 memcpy(dev
->dev_addr
, ax25_nocall
, AX25_ADDR_LEN
);
760 dev
->tx_queue_len
= 16;
763 /* --------------------------------------------------------------------- */
764 struct net_device
*hdlcdrv_register(const struct hdlcdrv_ops
*ops
,
765 unsigned int privsize
, const char *ifname
,
766 unsigned int baseaddr
, unsigned int irq
,
769 struct net_device
*dev
;
770 struct hdlcdrv_state
*s
;
775 if (privsize
< sizeof(struct hdlcdrv_state
))
776 privsize
= sizeof(struct hdlcdrv_state
);
778 dev
= alloc_netdev(privsize
, ifname
, hdlcdrv_setup
);
780 return ERR_PTR(-ENOMEM
);
783 * initialize part of the hdlcdrv_state struct
786 s
->magic
= HDLCDRV_MAGIC
;
788 dev
->base_addr
= baseaddr
;
792 err
= register_netdev(dev
);
794 printk(KERN_WARNING
"hdlcdrv: cannot register net "
795 "device %s\n", dev
->name
);
802 /* --------------------------------------------------------------------- */
804 void hdlcdrv_unregister(struct net_device
*dev
)
806 struct hdlcdrv_state
*s
= dev
->priv
;
808 BUG_ON(s
->magic
!= HDLCDRV_MAGIC
);
810 if (s
->opened
&& s
->ops
->close
)
812 unregister_netdev(dev
);
817 /* --------------------------------------------------------------------- */
819 EXPORT_SYMBOL(hdlcdrv_receiver
);
820 EXPORT_SYMBOL(hdlcdrv_transmitter
);
821 EXPORT_SYMBOL(hdlcdrv_arbitrate
);
822 EXPORT_SYMBOL(hdlcdrv_register
);
823 EXPORT_SYMBOL(hdlcdrv_unregister
);
825 /* --------------------------------------------------------------------- */
827 static int __init
hdlcdrv_init_driver(void)
829 printk(KERN_INFO
"hdlcdrv: (C) 1996-2000 Thomas Sailer HB9JNX/AE4WA\n");
830 printk(KERN_INFO
"hdlcdrv: version 0.8 compiled " __TIME__
" " __DATE__
"\n");
834 /* --------------------------------------------------------------------- */
836 static void __exit
hdlcdrv_cleanup_driver(void)
838 printk(KERN_INFO
"hdlcdrv: cleanup\n");
841 /* --------------------------------------------------------------------- */
843 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
844 MODULE_DESCRIPTION("Packet Radio network interface HDLC encoder/decoder");
845 MODULE_LICENSE("GPL");
846 module_init(hdlcdrv_init_driver
);
847 module_exit(hdlcdrv_cleanup_driver
);
849 /* --------------------------------------------------------------------- */