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/module.h>
46 #include <linux/types.h>
47 #include <linux/net.h>
50 #include <linux/slab.h>
51 #include <linux/errno.h>
52 #include <linux/init.h>
53 #include <linux/bitops.h>
55 #include <linux/netdevice.h>
56 #include <linux/if_arp.h>
57 #include <linux/skbuff.h>
58 #include <linux/hdlcdrv.h>
59 #include <linux/random.h>
61 #include <asm/uaccess.h>
63 #include <linux/crc-ccitt.h>
65 /* --------------------------------------------------------------------- */
69 /* --------------------------------------------------------------------- */
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
79 /* --------------------------------------------------------------------- */
81 * the CRC routines are stolen from WAMPES
86 /*---------------------------------------------------------------------------*/
88 static inline void append_crc_ccitt(unsigned char *buffer
, int len
)
90 unsigned int crc
= crc_ccitt(0xffff, buffer
, len
) ^ 0xffff;
96 /*---------------------------------------------------------------------------*/
98 static inline int check_crc_ccitt(const unsigned char *buf
, int cnt
)
100 return (crc_ccitt(0xffff, buf
, cnt
) & 0xffff) == 0xf0b8;
103 /*---------------------------------------------------------------------------*/
106 static int calc_crc_ccitt(const unsigned char *buf
, int cnt
)
108 unsigned int crc
= 0xffff;
110 for (; cnt
> 0; cnt
--)
111 crc
= (crc
>> 8) ^ crc_ccitt_table
[(crc
^ *buf
++) & 0xff];
113 return (crc
& 0xffff);
117 /* ---------------------------------------------------------------------- */
119 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16)
121 /* ---------------------------------------------------------------------- */
126 static int hdlc_rx_add_bytes(struct hdlcdrv_state
*s
, unsigned int bits
,
131 while (s
->hdlcrx
.rx_state
&& num
>= 8) {
132 if (s
->hdlcrx
.len
>= sizeof(s
->hdlcrx
.buffer
)) {
133 s
->hdlcrx
.rx_state
= 0;
136 *s
->hdlcrx
.bp
++ = bits
>> (32-num
);
144 static void hdlc_rx_flag(struct net_device
*dev
, struct hdlcdrv_state
*s
)
150 if (s
->hdlcrx
.len
< 4)
152 if (!check_crc_ccitt(s
->hdlcrx
.buffer
, s
->hdlcrx
.len
))
154 pkt_len
= s
->hdlcrx
.len
- 2 + 1; /* KISS kludge */
155 if (!(skb
= dev_alloc_skb(pkt_len
))) {
156 printk("%s: memory squeeze, dropping packet\n", dev
->name
);
157 s
->stats
.rx_dropped
++;
160 cp
= skb_put(skb
, pkt_len
);
161 *cp
++ = 0; /* KISS kludge */
162 memcpy(cp
, s
->hdlcrx
.buffer
, pkt_len
- 1);
163 skb
->protocol
= ax25_type_trans(skb
, dev
);
165 dev
->last_rx
= jiffies
;
166 s
->stats
.rx_packets
++;
169 void hdlcdrv_receiver(struct net_device
*dev
, struct hdlcdrv_state
*s
)
172 unsigned int mask1
, mask2
, mask3
, mask4
, mask5
, mask6
, word
;
174 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
176 if (test_and_set_bit(0, &s
->hdlcrx
.in_hdlc_rx
))
179 while (!hdlcdrv_hbuf_empty(&s
->hdlcrx
.hbuf
)) {
180 word
= hdlcdrv_hbuf_get(&s
->hdlcrx
.hbuf
);
183 hdlcdrv_add_bitbuffer_word(&s
->bitbuf_hdlc
, word
);
184 #endif /* HDLCDRV_DEBUG */
185 s
->hdlcrx
.bitstream
>>= 16;
186 s
->hdlcrx
.bitstream
|= word
<< 16;
187 s
->hdlcrx
.bitbuf
>>= 16;
188 s
->hdlcrx
.bitbuf
|= word
<< 16;
189 s
->hdlcrx
.numbits
+= 16;
190 for(i
= 15, mask1
= 0x1fc00, mask2
= 0x1fe00, mask3
= 0x0fc00,
191 mask4
= 0x1f800, mask5
= 0xf800, mask6
= 0xffff;
193 i
--, mask1
<<= 1, mask2
<<= 1, mask3
<<= 1, mask4
<<= 1,
194 mask5
<<= 1, mask6
= (mask6
<< 1) | 1) {
195 if ((s
->hdlcrx
.bitstream
& mask1
) == mask1
)
196 s
->hdlcrx
.rx_state
= 0; /* abort received */
197 else if ((s
->hdlcrx
.bitstream
& mask2
) == mask3
) {
199 if (s
->hdlcrx
.rx_state
) {
200 hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
204 hdlc_rx_flag(dev
, s
);
207 s
->hdlcrx
.bp
= s
->hdlcrx
.buffer
;
208 s
->hdlcrx
.rx_state
= 1;
209 s
->hdlcrx
.numbits
= i
;
210 } else if ((s
->hdlcrx
.bitstream
& mask4
) == mask5
) {
213 s
->hdlcrx
.bitbuf
= (s
->hdlcrx
.bitbuf
& (~mask6
)) |
214 ((s
->hdlcrx
.bitbuf
& mask6
) << 1);
217 s
->hdlcrx
.numbits
-= hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
,
220 clear_bit(0, &s
->hdlcrx
.in_hdlc_rx
);
223 /* ---------------------------------------------------------------------- */
225 static inline void do_kiss_params(struct hdlcdrv_state
*s
,
226 unsigned char *data
, unsigned long len
)
230 #define PKP(a,b) printk(KERN_INFO "hdlcdrv.c: channel params: " a "\n", b)
231 #else /* KISS_VERBOSE */
233 #endif /* KISS_VERBOSE */
239 s
->ch_params
.tx_delay
= data
[1];
240 PKP("TX delay = %ums", 10 * s
->ch_params
.tx_delay
);
243 s
->ch_params
.ppersist
= data
[1];
244 PKP("p persistence = %u", s
->ch_params
.ppersist
);
247 s
->ch_params
.slottime
= data
[1];
248 PKP("slot time = %ums", s
->ch_params
.slottime
);
251 s
->ch_params
.tx_tail
= data
[1];
252 PKP("TX tail = %ums", s
->ch_params
.tx_tail
);
255 s
->ch_params
.fulldup
= !!data
[1];
256 PKP("%s duplex", s
->ch_params
.fulldup
? "full" : "half");
264 /* ---------------------------------------------------------------------- */
266 void hdlcdrv_transmitter(struct net_device
*dev
, struct hdlcdrv_state
*s
)
268 unsigned int mask1
, mask2
, mask3
;
273 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
275 if (test_and_set_bit(0, &s
->hdlctx
.in_hdlc_tx
))
278 if (s
->hdlctx
.numbits
>= 16) {
279 if (hdlcdrv_hbuf_full(&s
->hdlctx
.hbuf
)) {
280 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
283 hdlcdrv_hbuf_put(&s
->hdlctx
.hbuf
, s
->hdlctx
.bitbuf
);
284 s
->hdlctx
.bitbuf
>>= 16;
285 s
->hdlctx
.numbits
-= 16;
287 switch (s
->hdlctx
.tx_state
) {
289 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
293 if (s
->hdlctx
.numflags
) {
294 s
->hdlctx
.numflags
--;
296 0x7e7e << s
->hdlctx
.numbits
;
297 s
->hdlctx
.numbits
+= 16;
300 if (s
->hdlctx
.tx_state
== 1) {
301 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
304 if (!(skb
= s
->skb
)) {
305 int flgs
= tenms_to_2flags(s
, s
->ch_params
.tx_tail
);
308 s
->hdlctx
.tx_state
= 1;
309 s
->hdlctx
.numflags
= flgs
;
313 netif_wake_queue(dev
);
314 pkt_len
= skb
->len
-1; /* strip KISS byte */
315 if (pkt_len
>= HDLCDRV_MAXFLEN
|| pkt_len
< 2) {
316 s
->hdlctx
.tx_state
= 0;
317 s
->hdlctx
.numflags
= 1;
318 dev_kfree_skb_irq(skb
);
321 skb_copy_from_linear_data_offset(skb
, 1,
324 dev_kfree_skb_irq(skb
);
325 s
->hdlctx
.bp
= s
->hdlctx
.buffer
;
326 append_crc_ccitt(s
->hdlctx
.buffer
, pkt_len
);
327 s
->hdlctx
.len
= pkt_len
+2; /* the appended CRC */
328 s
->hdlctx
.tx_state
= 2;
329 s
->hdlctx
.bitstream
= 0;
330 s
->stats
.tx_packets
++;
333 if (!s
->hdlctx
.len
) {
334 s
->hdlctx
.tx_state
= 0;
335 s
->hdlctx
.numflags
= 1;
339 s
->hdlctx
.bitbuf
|= *s
->hdlctx
.bp
<<
341 s
->hdlctx
.bitstream
>>= 8;
342 s
->hdlctx
.bitstream
|= (*s
->hdlctx
.bp
++) << 16;
345 mask3
= 0xffffffff >> (31-s
->hdlctx
.numbits
);
346 s
->hdlctx
.numbits
+= 8;
347 for(i
= 0; i
< 8; i
++, mask1
<<= 1, mask2
<<= 1,
348 mask3
= (mask3
<< 1) | 1) {
349 if ((s
->hdlctx
.bitstream
& mask1
) != mask1
)
351 s
->hdlctx
.bitstream
&= ~mask2
;
353 (s
->hdlctx
.bitbuf
& mask3
) |
357 mask3
= (mask3
<< 1) | 1;
364 /* ---------------------------------------------------------------------- */
366 static void start_tx(struct net_device
*dev
, struct hdlcdrv_state
*s
)
368 s
->hdlctx
.tx_state
= 0;
369 s
->hdlctx
.numflags
= tenms_to_2flags(s
, s
->ch_params
.tx_delay
);
370 s
->hdlctx
.bitbuf
= s
->hdlctx
.bitstream
= s
->hdlctx
.numbits
= 0;
371 hdlcdrv_transmitter(dev
, s
);
376 /* ---------------------------------------------------------------------- */
378 void hdlcdrv_arbitrate(struct net_device
*dev
, struct hdlcdrv_state
*s
)
380 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
|| s
->hdlctx
.ptt
|| !s
->skb
)
382 if (s
->ch_params
.fulldup
) {
387 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
390 if ((--s
->hdlctx
.slotcnt
) > 0)
392 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
393 if ((random32() % 256) > s
->ch_params
.ppersist
)
398 /* --------------------------------------------------------------------- */
400 * ===================== network driver interface =========================
403 static int hdlcdrv_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
405 struct hdlcdrv_state
*sm
= netdev_priv(dev
);
407 if (skb
->data
[0] != 0) {
408 do_kiss_params(sm
, skb
->data
, skb
->len
);
414 netif_stop_queue(dev
);
419 /* --------------------------------------------------------------------- */
421 static int hdlcdrv_set_mac_address(struct net_device
*dev
, void *addr
)
423 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
425 /* addr is an AX.25 shifted ASCII mac address */
426 memcpy(dev
->dev_addr
, sa
->sa_data
, dev
->addr_len
);
430 /* --------------------------------------------------------------------- */
432 static struct net_device_stats
*hdlcdrv_get_stats(struct net_device
*dev
)
434 struct hdlcdrv_state
*sm
= netdev_priv(dev
);
437 * Get the current statistics. This may be called with the
438 * card open or closed.
443 /* --------------------------------------------------------------------- */
445 * Open/initialize the board. This is called (in the current kernel)
446 * sometime after booting when the 'ifconfig' program is run.
448 * This routine should set everything up anew at each open, even
449 * registers that "should" only need to be set once at boot, so that
450 * there is non-reboot way to recover if something goes wrong.
453 static int hdlcdrv_open(struct net_device
*dev
)
455 struct hdlcdrv_state
*s
= netdev_priv(dev
);
458 if (!s
->ops
|| !s
->ops
->open
)
462 * initialise some variables
465 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
466 s
->hdlcrx
.in_hdlc_rx
= 0;
467 s
->hdlcrx
.rx_state
= 0;
469 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
470 s
->hdlctx
.in_hdlc_tx
= 0;
471 s
->hdlctx
.tx_state
= 1;
472 s
->hdlctx
.numflags
= 0;
473 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
475 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
476 s
->hdlctx
.calibrate
= 0;
478 i
= s
->ops
->open(dev
);
481 netif_start_queue(dev
);
485 /* --------------------------------------------------------------------- */
487 * The inverse routine to hdlcdrv_open().
490 static int hdlcdrv_close(struct net_device
*dev
)
492 struct hdlcdrv_state
*s
= netdev_priv(dev
);
495 netif_stop_queue(dev
);
497 if (s
->ops
&& s
->ops
->close
)
498 i
= s
->ops
->close(dev
);
500 dev_kfree_skb(s
->skb
);
506 /* --------------------------------------------------------------------- */
508 static int hdlcdrv_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
510 struct hdlcdrv_state
*s
= netdev_priv(dev
);
511 struct hdlcdrv_ioctl bi
;
513 if (cmd
!= SIOCDEVPRIVATE
) {
514 if (s
->ops
&& s
->ops
->ioctl
)
515 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
518 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
523 if (s
->ops
&& s
->ops
->ioctl
)
524 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
527 case HDLCDRVCTL_GETCHANNELPAR
:
528 bi
.data
.cp
.tx_delay
= s
->ch_params
.tx_delay
;
529 bi
.data
.cp
.tx_tail
= s
->ch_params
.tx_tail
;
530 bi
.data
.cp
.slottime
= s
->ch_params
.slottime
;
531 bi
.data
.cp
.ppersist
= s
->ch_params
.ppersist
;
532 bi
.data
.cp
.fulldup
= s
->ch_params
.fulldup
;
535 case HDLCDRVCTL_SETCHANNELPAR
:
536 if (!capable(CAP_NET_ADMIN
))
538 s
->ch_params
.tx_delay
= bi
.data
.cp
.tx_delay
;
539 s
->ch_params
.tx_tail
= bi
.data
.cp
.tx_tail
;
540 s
->ch_params
.slottime
= bi
.data
.cp
.slottime
;
541 s
->ch_params
.ppersist
= bi
.data
.cp
.ppersist
;
542 s
->ch_params
.fulldup
= bi
.data
.cp
.fulldup
;
543 s
->hdlctx
.slotcnt
= 1;
546 case HDLCDRVCTL_GETMODEMPAR
:
547 bi
.data
.mp
.iobase
= dev
->base_addr
;
548 bi
.data
.mp
.irq
= dev
->irq
;
549 bi
.data
.mp
.dma
= dev
->dma
;
550 bi
.data
.mp
.dma2
= s
->ptt_out
.dma2
;
551 bi
.data
.mp
.seriobase
= s
->ptt_out
.seriobase
;
552 bi
.data
.mp
.pariobase
= s
->ptt_out
.pariobase
;
553 bi
.data
.mp
.midiiobase
= s
->ptt_out
.midiiobase
;
556 case HDLCDRVCTL_SETMODEMPAR
:
557 if ((!capable(CAP_SYS_RAWIO
)) || netif_running(dev
))
559 dev
->base_addr
= bi
.data
.mp
.iobase
;
560 dev
->irq
= bi
.data
.mp
.irq
;
561 dev
->dma
= bi
.data
.mp
.dma
;
562 s
->ptt_out
.dma2
= bi
.data
.mp
.dma2
;
563 s
->ptt_out
.seriobase
= bi
.data
.mp
.seriobase
;
564 s
->ptt_out
.pariobase
= bi
.data
.mp
.pariobase
;
565 s
->ptt_out
.midiiobase
= bi
.data
.mp
.midiiobase
;
568 case HDLCDRVCTL_GETSTAT
:
569 bi
.data
.cs
.ptt
= hdlcdrv_ptt(s
);
570 bi
.data
.cs
.dcd
= s
->hdlcrx
.dcd
;
571 bi
.data
.cs
.ptt_keyed
= s
->ptt_keyed
;
572 bi
.data
.cs
.tx_packets
= s
->stats
.tx_packets
;
573 bi
.data
.cs
.tx_errors
= s
->stats
.tx_errors
;
574 bi
.data
.cs
.rx_packets
= s
->stats
.rx_packets
;
575 bi
.data
.cs
.rx_errors
= s
->stats
.rx_errors
;
578 case HDLCDRVCTL_OLDGETSTAT
:
579 bi
.data
.ocs
.ptt
= hdlcdrv_ptt(s
);
580 bi
.data
.ocs
.dcd
= s
->hdlcrx
.dcd
;
581 bi
.data
.ocs
.ptt_keyed
= s
->ptt_keyed
;
584 case HDLCDRVCTL_CALIBRATE
:
585 if(!capable(CAP_SYS_RAWIO
))
587 s
->hdlctx
.calibrate
= bi
.data
.calibrate
* s
->par
.bitrate
/ 16;
590 case HDLCDRVCTL_GETSAMPLES
:
591 #ifndef HDLCDRV_DEBUG
593 #else /* HDLCDRV_DEBUG */
594 if (s
->bitbuf_channel
.rd
== s
->bitbuf_channel
.wr
)
597 s
->bitbuf_channel
.buffer
[s
->bitbuf_channel
.rd
];
598 s
->bitbuf_channel
.rd
= (s
->bitbuf_channel
.rd
+1) %
599 sizeof(s
->bitbuf_channel
.buffer
);
601 #endif /* HDLCDRV_DEBUG */
603 case HDLCDRVCTL_GETBITS
:
604 #ifndef HDLCDRV_DEBUG
606 #else /* HDLCDRV_DEBUG */
607 if (s
->bitbuf_hdlc
.rd
== s
->bitbuf_hdlc
.wr
)
610 s
->bitbuf_hdlc
.buffer
[s
->bitbuf_hdlc
.rd
];
611 s
->bitbuf_hdlc
.rd
= (s
->bitbuf_hdlc
.rd
+1) %
612 sizeof(s
->bitbuf_hdlc
.buffer
);
614 #endif /* HDLCDRV_DEBUG */
616 case HDLCDRVCTL_DRIVERNAME
:
617 if (s
->ops
&& s
->ops
->drvname
) {
618 strncpy(bi
.data
.drivername
, s
->ops
->drvname
,
619 sizeof(bi
.data
.drivername
));
622 bi
.data
.drivername
[0] = '\0';
626 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
632 /* --------------------------------------------------------------------- */
635 * Initialize fields in hdlcdrv
637 static void hdlcdrv_setup(struct net_device
*dev
)
639 static const struct hdlcdrv_channel_params dflt_ch_params
= {
642 struct hdlcdrv_state
*s
= netdev_priv(dev
);
645 * initialize the hdlcdrv_state struct
647 s
->ch_params
= dflt_ch_params
;
650 spin_lock_init(&s
->hdlcrx
.hbuf
.lock
);
651 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
652 s
->hdlcrx
.in_hdlc_rx
= 0;
653 s
->hdlcrx
.rx_state
= 0;
655 spin_lock_init(&s
->hdlctx
.hbuf
.lock
);
656 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
657 s
->hdlctx
.in_hdlc_tx
= 0;
658 s
->hdlctx
.tx_state
= 1;
659 s
->hdlctx
.numflags
= 0;
660 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
662 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
663 s
->hdlctx
.calibrate
= 0;
666 s
->bitbuf_channel
.rd
= s
->bitbuf_channel
.wr
= 0;
667 s
->bitbuf_channel
.shreg
= 0x80;
669 s
->bitbuf_hdlc
.rd
= s
->bitbuf_hdlc
.wr
= 0;
670 s
->bitbuf_hdlc
.shreg
= 0x80;
671 #endif /* HDLCDRV_DEBUG */
674 * initialize the device struct
676 dev
->open
= hdlcdrv_open
;
677 dev
->stop
= hdlcdrv_close
;
678 dev
->do_ioctl
= hdlcdrv_ioctl
;
679 dev
->hard_start_xmit
= hdlcdrv_send_packet
;
680 dev
->get_stats
= hdlcdrv_get_stats
;
682 /* Fill in the fields of the device structure */
686 dev
->header_ops
= &ax25_header_ops
;
687 dev
->set_mac_address
= hdlcdrv_set_mac_address
;
689 dev
->type
= ARPHRD_AX25
; /* AF_AX25 device */
690 dev
->hard_header_len
= AX25_MAX_HEADER_LEN
+ AX25_BPQ_HEADER_LEN
;
691 dev
->mtu
= AX25_DEF_PACLEN
; /* eth_mtu is the default */
692 dev
->addr_len
= AX25_ADDR_LEN
; /* sizeof an ax.25 address */
693 memcpy(dev
->broadcast
, &ax25_bcast
, AX25_ADDR_LEN
);
694 memcpy(dev
->dev_addr
, &ax25_defaddr
, AX25_ADDR_LEN
);
695 dev
->tx_queue_len
= 16;
698 /* --------------------------------------------------------------------- */
699 struct net_device
*hdlcdrv_register(const struct hdlcdrv_ops
*ops
,
700 unsigned int privsize
, const char *ifname
,
701 unsigned int baseaddr
, unsigned int irq
,
704 struct net_device
*dev
;
705 struct hdlcdrv_state
*s
;
710 if (privsize
< sizeof(struct hdlcdrv_state
))
711 privsize
= sizeof(struct hdlcdrv_state
);
713 dev
= alloc_netdev(privsize
, ifname
, hdlcdrv_setup
);
715 return ERR_PTR(-ENOMEM
);
718 * initialize part of the hdlcdrv_state struct
720 s
= netdev_priv(dev
);
721 s
->magic
= HDLCDRV_MAGIC
;
723 dev
->base_addr
= baseaddr
;
727 err
= register_netdev(dev
);
729 printk(KERN_WARNING
"hdlcdrv: cannot register net "
730 "device %s\n", dev
->name
);
737 /* --------------------------------------------------------------------- */
739 void hdlcdrv_unregister(struct net_device
*dev
)
741 struct hdlcdrv_state
*s
= netdev_priv(dev
);
743 BUG_ON(s
->magic
!= HDLCDRV_MAGIC
);
745 if (s
->opened
&& s
->ops
->close
)
747 unregister_netdev(dev
);
752 /* --------------------------------------------------------------------- */
754 EXPORT_SYMBOL(hdlcdrv_receiver
);
755 EXPORT_SYMBOL(hdlcdrv_transmitter
);
756 EXPORT_SYMBOL(hdlcdrv_arbitrate
);
757 EXPORT_SYMBOL(hdlcdrv_register
);
758 EXPORT_SYMBOL(hdlcdrv_unregister
);
760 /* --------------------------------------------------------------------- */
762 static int __init
hdlcdrv_init_driver(void)
764 printk(KERN_INFO
"hdlcdrv: (C) 1996-2000 Thomas Sailer HB9JNX/AE4WA\n");
765 printk(KERN_INFO
"hdlcdrv: version 0.8 compiled " __TIME__
" " __DATE__
"\n");
769 /* --------------------------------------------------------------------- */
771 static void __exit
hdlcdrv_cleanup_driver(void)
773 printk(KERN_INFO
"hdlcdrv: cleanup\n");
776 /* --------------------------------------------------------------------- */
778 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
779 MODULE_DESCRIPTION("Packet Radio network interface HDLC encoder/decoder");
780 MODULE_LICENSE("GPL");
781 module_init(hdlcdrv_init_driver
);
782 module_exit(hdlcdrv_cleanup_driver
);
784 /* --------------------------------------------------------------------- */