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>
60 #include <asm/uaccess.h>
62 #include <linux/crc-ccitt.h>
64 /* --------------------------------------------------------------------- */
67 * The name of the card. Is used for messages and in the requests for
68 * io regions, irqs and dma channels
71 static char ax25_bcast
[AX25_ADDR_LEN
] =
72 {'Q' << 1, 'S' << 1, 'T' << 1, ' ' << 1, ' ' << 1, ' ' << 1, '0' << 1};
73 static char ax25_nocall
[AX25_ADDR_LEN
] =
74 {'L' << 1, 'I' << 1, 'N' << 1, 'U' << 1, 'X' << 1, ' ' << 1, '1' << 1};
76 /* --------------------------------------------------------------------- */
80 /* --------------------------------------------------------------------- */
82 #define PARAM_TXDELAY 1
83 #define PARAM_PERSIST 2
84 #define PARAM_SLOTTIME 3
85 #define PARAM_TXTAIL 4
86 #define PARAM_FULLDUP 5
87 #define PARAM_HARDWARE 6
88 #define PARAM_RETURN 255
90 /* --------------------------------------------------------------------- */
92 * the CRC routines are stolen from WAMPES
97 /*---------------------------------------------------------------------------*/
99 static inline void append_crc_ccitt(unsigned char *buffer
, int len
)
101 unsigned int crc
= crc_ccitt(0xffff, buffer
, len
) ^ 0xffff;
103 *buffer
++ = crc
>> 8;
106 /*---------------------------------------------------------------------------*/
108 static inline int check_crc_ccitt(const unsigned char *buf
, int cnt
)
110 return (crc_ccitt(0xffff, buf
, cnt
) & 0xffff) == 0xf0b8;
113 /*---------------------------------------------------------------------------*/
116 static int calc_crc_ccitt(const unsigned char *buf
, int cnt
)
118 unsigned int crc
= 0xffff;
120 for (; cnt
> 0; cnt
--)
121 crc
= (crc
>> 8) ^ crc_ccitt_table
[(crc
^ *buf
++) & 0xff];
123 return (crc
& 0xffff);
127 /* ---------------------------------------------------------------------- */
129 #define tenms_to_2flags(s,tenms) ((tenms * s->par.bitrate) / 100 / 16)
131 /* ---------------------------------------------------------------------- */
136 static int hdlc_rx_add_bytes(struct hdlcdrv_state
*s
, unsigned int bits
,
141 while (s
->hdlcrx
.rx_state
&& num
>= 8) {
142 if (s
->hdlcrx
.len
>= sizeof(s
->hdlcrx
.buffer
)) {
143 s
->hdlcrx
.rx_state
= 0;
146 *s
->hdlcrx
.bp
++ = bits
>> (32-num
);
154 static void hdlc_rx_flag(struct net_device
*dev
, struct hdlcdrv_state
*s
)
160 if (s
->hdlcrx
.len
< 4)
162 if (!check_crc_ccitt(s
->hdlcrx
.buffer
, s
->hdlcrx
.len
))
164 pkt_len
= s
->hdlcrx
.len
- 2 + 1; /* KISS kludge */
165 if (!(skb
= dev_alloc_skb(pkt_len
))) {
166 printk("%s: memory squeeze, dropping packet\n", dev
->name
);
167 s
->stats
.rx_dropped
++;
170 cp
= skb_put(skb
, pkt_len
);
171 *cp
++ = 0; /* KISS kludge */
172 memcpy(cp
, s
->hdlcrx
.buffer
, pkt_len
- 1);
173 skb
->protocol
= ax25_type_trans(skb
, dev
);
175 dev
->last_rx
= jiffies
;
176 s
->stats
.rx_packets
++;
179 void hdlcdrv_receiver(struct net_device
*dev
, struct hdlcdrv_state
*s
)
182 unsigned int mask1
, mask2
, mask3
, mask4
, mask5
, mask6
, word
;
184 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
186 if (test_and_set_bit(0, &s
->hdlcrx
.in_hdlc_rx
))
189 while (!hdlcdrv_hbuf_empty(&s
->hdlcrx
.hbuf
)) {
190 word
= hdlcdrv_hbuf_get(&s
->hdlcrx
.hbuf
);
193 hdlcdrv_add_bitbuffer_word(&s
->bitbuf_hdlc
, word
);
194 #endif /* HDLCDRV_DEBUG */
195 s
->hdlcrx
.bitstream
>>= 16;
196 s
->hdlcrx
.bitstream
|= word
<< 16;
197 s
->hdlcrx
.bitbuf
>>= 16;
198 s
->hdlcrx
.bitbuf
|= word
<< 16;
199 s
->hdlcrx
.numbits
+= 16;
200 for(i
= 15, mask1
= 0x1fc00, mask2
= 0x1fe00, mask3
= 0x0fc00,
201 mask4
= 0x1f800, mask5
= 0xf800, mask6
= 0xffff;
203 i
--, mask1
<<= 1, mask2
<<= 1, mask3
<<= 1, mask4
<<= 1,
204 mask5
<<= 1, mask6
= (mask6
<< 1) | 1) {
205 if ((s
->hdlcrx
.bitstream
& mask1
) == mask1
)
206 s
->hdlcrx
.rx_state
= 0; /* abort received */
207 else if ((s
->hdlcrx
.bitstream
& mask2
) == mask3
) {
209 if (s
->hdlcrx
.rx_state
) {
210 hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
214 hdlc_rx_flag(dev
, s
);
217 s
->hdlcrx
.bp
= s
->hdlcrx
.buffer
;
218 s
->hdlcrx
.rx_state
= 1;
219 s
->hdlcrx
.numbits
= i
;
220 } else if ((s
->hdlcrx
.bitstream
& mask4
) == mask5
) {
223 s
->hdlcrx
.bitbuf
= (s
->hdlcrx
.bitbuf
& (~mask6
)) |
224 ((s
->hdlcrx
.bitbuf
& mask6
) << 1);
227 s
->hdlcrx
.numbits
-= hdlc_rx_add_bytes(s
, s
->hdlcrx
.bitbuf
,
230 clear_bit(0, &s
->hdlcrx
.in_hdlc_rx
);
233 /* ---------------------------------------------------------------------- */
235 static inline void do_kiss_params(struct hdlcdrv_state
*s
,
236 unsigned char *data
, unsigned long len
)
240 #define PKP(a,b) printk(KERN_INFO "hdlcdrv.c: channel params: " a "\n", b)
241 #else /* KISS_VERBOSE */
243 #endif /* KISS_VERBOSE */
249 s
->ch_params
.tx_delay
= data
[1];
250 PKP("TX delay = %ums", 10 * s
->ch_params
.tx_delay
);
253 s
->ch_params
.ppersist
= data
[1];
254 PKP("p persistence = %u", s
->ch_params
.ppersist
);
257 s
->ch_params
.slottime
= data
[1];
258 PKP("slot time = %ums", s
->ch_params
.slottime
);
261 s
->ch_params
.tx_tail
= data
[1];
262 PKP("TX tail = %ums", s
->ch_params
.tx_tail
);
265 s
->ch_params
.fulldup
= !!data
[1];
266 PKP("%s duplex", s
->ch_params
.fulldup
? "full" : "half");
274 /* ---------------------------------------------------------------------- */
276 void hdlcdrv_transmitter(struct net_device
*dev
, struct hdlcdrv_state
*s
)
278 unsigned int mask1
, mask2
, mask3
;
283 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
)
285 if (test_and_set_bit(0, &s
->hdlctx
.in_hdlc_tx
))
288 if (s
->hdlctx
.numbits
>= 16) {
289 if (hdlcdrv_hbuf_full(&s
->hdlctx
.hbuf
)) {
290 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
293 hdlcdrv_hbuf_put(&s
->hdlctx
.hbuf
, s
->hdlctx
.bitbuf
);
294 s
->hdlctx
.bitbuf
>>= 16;
295 s
->hdlctx
.numbits
-= 16;
297 switch (s
->hdlctx
.tx_state
) {
299 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
303 if (s
->hdlctx
.numflags
) {
304 s
->hdlctx
.numflags
--;
306 0x7e7e << s
->hdlctx
.numbits
;
307 s
->hdlctx
.numbits
+= 16;
310 if (s
->hdlctx
.tx_state
== 1) {
311 clear_bit(0, &s
->hdlctx
.in_hdlc_tx
);
314 if (!(skb
= s
->skb
)) {
315 int flgs
= tenms_to_2flags(s
, s
->ch_params
.tx_tail
);
318 s
->hdlctx
.tx_state
= 1;
319 s
->hdlctx
.numflags
= flgs
;
323 netif_wake_queue(dev
);
324 pkt_len
= skb
->len
-1; /* strip KISS byte */
325 if (pkt_len
>= HDLCDRV_MAXFLEN
|| pkt_len
< 2) {
326 s
->hdlctx
.tx_state
= 0;
327 s
->hdlctx
.numflags
= 1;
328 dev_kfree_skb_irq(skb
);
331 memcpy(s
->hdlctx
.buffer
, skb
->data
+1, pkt_len
);
332 dev_kfree_skb_irq(skb
);
333 s
->hdlctx
.bp
= s
->hdlctx
.buffer
;
334 append_crc_ccitt(s
->hdlctx
.buffer
, pkt_len
);
335 s
->hdlctx
.len
= pkt_len
+2; /* the appended CRC */
336 s
->hdlctx
.tx_state
= 2;
337 s
->hdlctx
.bitstream
= 0;
338 s
->stats
.tx_packets
++;
341 if (!s
->hdlctx
.len
) {
342 s
->hdlctx
.tx_state
= 0;
343 s
->hdlctx
.numflags
= 1;
347 s
->hdlctx
.bitbuf
|= *s
->hdlctx
.bp
<<
349 s
->hdlctx
.bitstream
>>= 8;
350 s
->hdlctx
.bitstream
|= (*s
->hdlctx
.bp
++) << 16;
353 mask3
= 0xffffffff >> (31-s
->hdlctx
.numbits
);
354 s
->hdlctx
.numbits
+= 8;
355 for(i
= 0; i
< 8; i
++, mask1
<<= 1, mask2
<<= 1,
356 mask3
= (mask3
<< 1) | 1) {
357 if ((s
->hdlctx
.bitstream
& mask1
) != mask1
)
359 s
->hdlctx
.bitstream
&= ~mask2
;
361 (s
->hdlctx
.bitbuf
& mask3
) |
365 mask3
= (mask3
<< 1) | 1;
372 /* ---------------------------------------------------------------------- */
374 static void start_tx(struct net_device
*dev
, struct hdlcdrv_state
*s
)
376 s
->hdlctx
.tx_state
= 0;
377 s
->hdlctx
.numflags
= tenms_to_2flags(s
, s
->ch_params
.tx_delay
);
378 s
->hdlctx
.bitbuf
= s
->hdlctx
.bitstream
= s
->hdlctx
.numbits
= 0;
379 hdlcdrv_transmitter(dev
, s
);
384 /* ---------------------------------------------------------------------- */
386 static unsigned short random_seed
;
388 static inline unsigned short random_num(void)
390 random_seed
= 28629 * random_seed
+ 157;
394 /* ---------------------------------------------------------------------- */
396 void hdlcdrv_arbitrate(struct net_device
*dev
, struct hdlcdrv_state
*s
)
398 if (!s
|| s
->magic
!= HDLCDRV_MAGIC
|| s
->hdlctx
.ptt
|| !s
->skb
)
400 if (s
->ch_params
.fulldup
) {
405 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
408 if ((--s
->hdlctx
.slotcnt
) > 0)
410 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
411 if ((random_num() % 256) > s
->ch_params
.ppersist
)
416 /* --------------------------------------------------------------------- */
418 * ===================== network driver interface =========================
421 static int hdlcdrv_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
423 struct hdlcdrv_state
*sm
= netdev_priv(dev
);
425 if (skb
->data
[0] != 0) {
426 do_kiss_params(sm
, skb
->data
, skb
->len
);
432 netif_stop_queue(dev
);
437 /* --------------------------------------------------------------------- */
439 static int hdlcdrv_set_mac_address(struct net_device
*dev
, void *addr
)
441 struct sockaddr
*sa
= (struct sockaddr
*)addr
;
443 /* addr is an AX.25 shifted ASCII mac address */
444 memcpy(dev
->dev_addr
, sa
->sa_data
, dev
->addr_len
);
448 /* --------------------------------------------------------------------- */
450 static struct net_device_stats
*hdlcdrv_get_stats(struct net_device
*dev
)
452 struct hdlcdrv_state
*sm
= netdev_priv(dev
);
455 * Get the current statistics. This may be called with the
456 * card open or closed.
461 /* --------------------------------------------------------------------- */
463 * Open/initialize the board. This is called (in the current kernel)
464 * sometime after booting when the 'ifconfig' program is run.
466 * This routine should set everything up anew at each open, even
467 * registers that "should" only need to be set once at boot, so that
468 * there is non-reboot way to recover if something goes wrong.
471 static int hdlcdrv_open(struct net_device
*dev
)
473 struct hdlcdrv_state
*s
= netdev_priv(dev
);
476 if (!s
->ops
|| !s
->ops
->open
)
480 * initialise some variables
483 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
484 s
->hdlcrx
.in_hdlc_rx
= 0;
485 s
->hdlcrx
.rx_state
= 0;
487 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
488 s
->hdlctx
.in_hdlc_tx
= 0;
489 s
->hdlctx
.tx_state
= 1;
490 s
->hdlctx
.numflags
= 0;
491 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
493 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
494 s
->hdlctx
.calibrate
= 0;
496 i
= s
->ops
->open(dev
);
499 netif_start_queue(dev
);
503 /* --------------------------------------------------------------------- */
505 * The inverse routine to hdlcdrv_open().
508 static int hdlcdrv_close(struct net_device
*dev
)
510 struct hdlcdrv_state
*s
= netdev_priv(dev
);
513 netif_stop_queue(dev
);
515 if (s
->ops
&& s
->ops
->close
)
516 i
= s
->ops
->close(dev
);
518 dev_kfree_skb(s
->skb
);
524 /* --------------------------------------------------------------------- */
526 static int hdlcdrv_ioctl(struct net_device
*dev
, struct ifreq
*ifr
, int cmd
)
528 struct hdlcdrv_state
*s
= netdev_priv(dev
);
529 struct hdlcdrv_ioctl bi
;
531 if (cmd
!= SIOCDEVPRIVATE
) {
532 if (s
->ops
&& s
->ops
->ioctl
)
533 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
536 if (copy_from_user(&bi
, ifr
->ifr_data
, sizeof(bi
)))
541 if (s
->ops
&& s
->ops
->ioctl
)
542 return s
->ops
->ioctl(dev
, ifr
, &bi
, cmd
);
545 case HDLCDRVCTL_GETCHANNELPAR
:
546 bi
.data
.cp
.tx_delay
= s
->ch_params
.tx_delay
;
547 bi
.data
.cp
.tx_tail
= s
->ch_params
.tx_tail
;
548 bi
.data
.cp
.slottime
= s
->ch_params
.slottime
;
549 bi
.data
.cp
.ppersist
= s
->ch_params
.ppersist
;
550 bi
.data
.cp
.fulldup
= s
->ch_params
.fulldup
;
553 case HDLCDRVCTL_SETCHANNELPAR
:
554 if (!capable(CAP_NET_ADMIN
))
556 s
->ch_params
.tx_delay
= bi
.data
.cp
.tx_delay
;
557 s
->ch_params
.tx_tail
= bi
.data
.cp
.tx_tail
;
558 s
->ch_params
.slottime
= bi
.data
.cp
.slottime
;
559 s
->ch_params
.ppersist
= bi
.data
.cp
.ppersist
;
560 s
->ch_params
.fulldup
= bi
.data
.cp
.fulldup
;
561 s
->hdlctx
.slotcnt
= 1;
564 case HDLCDRVCTL_GETMODEMPAR
:
565 bi
.data
.mp
.iobase
= dev
->base_addr
;
566 bi
.data
.mp
.irq
= dev
->irq
;
567 bi
.data
.mp
.dma
= dev
->dma
;
568 bi
.data
.mp
.dma2
= s
->ptt_out
.dma2
;
569 bi
.data
.mp
.seriobase
= s
->ptt_out
.seriobase
;
570 bi
.data
.mp
.pariobase
= s
->ptt_out
.pariobase
;
571 bi
.data
.mp
.midiiobase
= s
->ptt_out
.midiiobase
;
574 case HDLCDRVCTL_SETMODEMPAR
:
575 if ((!capable(CAP_SYS_RAWIO
)) || netif_running(dev
))
577 dev
->base_addr
= bi
.data
.mp
.iobase
;
578 dev
->irq
= bi
.data
.mp
.irq
;
579 dev
->dma
= bi
.data
.mp
.dma
;
580 s
->ptt_out
.dma2
= bi
.data
.mp
.dma2
;
581 s
->ptt_out
.seriobase
= bi
.data
.mp
.seriobase
;
582 s
->ptt_out
.pariobase
= bi
.data
.mp
.pariobase
;
583 s
->ptt_out
.midiiobase
= bi
.data
.mp
.midiiobase
;
586 case HDLCDRVCTL_GETSTAT
:
587 bi
.data
.cs
.ptt
= hdlcdrv_ptt(s
);
588 bi
.data
.cs
.dcd
= s
->hdlcrx
.dcd
;
589 bi
.data
.cs
.ptt_keyed
= s
->ptt_keyed
;
590 bi
.data
.cs
.tx_packets
= s
->stats
.tx_packets
;
591 bi
.data
.cs
.tx_errors
= s
->stats
.tx_errors
;
592 bi
.data
.cs
.rx_packets
= s
->stats
.rx_packets
;
593 bi
.data
.cs
.rx_errors
= s
->stats
.rx_errors
;
596 case HDLCDRVCTL_OLDGETSTAT
:
597 bi
.data
.ocs
.ptt
= hdlcdrv_ptt(s
);
598 bi
.data
.ocs
.dcd
= s
->hdlcrx
.dcd
;
599 bi
.data
.ocs
.ptt_keyed
= s
->ptt_keyed
;
602 case HDLCDRVCTL_CALIBRATE
:
603 if(!capable(CAP_SYS_RAWIO
))
605 s
->hdlctx
.calibrate
= bi
.data
.calibrate
* s
->par
.bitrate
/ 16;
608 case HDLCDRVCTL_GETSAMPLES
:
609 #ifndef HDLCDRV_DEBUG
611 #else /* HDLCDRV_DEBUG */
612 if (s
->bitbuf_channel
.rd
== s
->bitbuf_channel
.wr
)
615 s
->bitbuf_channel
.buffer
[s
->bitbuf_channel
.rd
];
616 s
->bitbuf_channel
.rd
= (s
->bitbuf_channel
.rd
+1) %
617 sizeof(s
->bitbuf_channel
.buffer
);
619 #endif /* HDLCDRV_DEBUG */
621 case HDLCDRVCTL_GETBITS
:
622 #ifndef HDLCDRV_DEBUG
624 #else /* HDLCDRV_DEBUG */
625 if (s
->bitbuf_hdlc
.rd
== s
->bitbuf_hdlc
.wr
)
628 s
->bitbuf_hdlc
.buffer
[s
->bitbuf_hdlc
.rd
];
629 s
->bitbuf_hdlc
.rd
= (s
->bitbuf_hdlc
.rd
+1) %
630 sizeof(s
->bitbuf_hdlc
.buffer
);
632 #endif /* HDLCDRV_DEBUG */
634 case HDLCDRVCTL_DRIVERNAME
:
635 if (s
->ops
&& s
->ops
->drvname
) {
636 strncpy(bi
.data
.drivername
, s
->ops
->drvname
,
637 sizeof(bi
.data
.drivername
));
640 bi
.data
.drivername
[0] = '\0';
644 if (copy_to_user(ifr
->ifr_data
, &bi
, sizeof(bi
)))
650 /* --------------------------------------------------------------------- */
653 * Initialize fields in hdlcdrv
655 static void hdlcdrv_setup(struct net_device
*dev
)
657 static const struct hdlcdrv_channel_params dflt_ch_params
= {
660 struct hdlcdrv_state
*s
= netdev_priv(dev
);
663 * initialize the hdlcdrv_state struct
665 s
->ch_params
= dflt_ch_params
;
668 spin_lock_init(&s
->hdlcrx
.hbuf
.lock
);
669 s
->hdlcrx
.hbuf
.rd
= s
->hdlcrx
.hbuf
.wr
= 0;
670 s
->hdlcrx
.in_hdlc_rx
= 0;
671 s
->hdlcrx
.rx_state
= 0;
673 spin_lock_init(&s
->hdlctx
.hbuf
.lock
);
674 s
->hdlctx
.hbuf
.rd
= s
->hdlctx
.hbuf
.wr
= 0;
675 s
->hdlctx
.in_hdlc_tx
= 0;
676 s
->hdlctx
.tx_state
= 1;
677 s
->hdlctx
.numflags
= 0;
678 s
->hdlctx
.bitstream
= s
->hdlctx
.bitbuf
= s
->hdlctx
.numbits
= 0;
680 s
->hdlctx
.slotcnt
= s
->ch_params
.slottime
;
681 s
->hdlctx
.calibrate
= 0;
684 s
->bitbuf_channel
.rd
= s
->bitbuf_channel
.wr
= 0;
685 s
->bitbuf_channel
.shreg
= 0x80;
687 s
->bitbuf_hdlc
.rd
= s
->bitbuf_hdlc
.wr
= 0;
688 s
->bitbuf_hdlc
.shreg
= 0x80;
689 #endif /* HDLCDRV_DEBUG */
692 * initialize the device struct
694 dev
->open
= hdlcdrv_open
;
695 dev
->stop
= hdlcdrv_close
;
696 dev
->do_ioctl
= hdlcdrv_ioctl
;
697 dev
->hard_start_xmit
= hdlcdrv_send_packet
;
698 dev
->get_stats
= hdlcdrv_get_stats
;
700 /* Fill in the fields of the device structure */
704 dev
->hard_header
= ax25_hard_header
;
705 dev
->rebuild_header
= ax25_rebuild_header
;
706 dev
->set_mac_address
= hdlcdrv_set_mac_address
;
708 dev
->type
= ARPHRD_AX25
; /* AF_AX25 device */
709 dev
->hard_header_len
= AX25_MAX_HEADER_LEN
+ AX25_BPQ_HEADER_LEN
;
710 dev
->mtu
= AX25_DEF_PACLEN
; /* eth_mtu is the default */
711 dev
->addr_len
= AX25_ADDR_LEN
; /* sizeof an ax.25 address */
712 memcpy(dev
->broadcast
, ax25_bcast
, AX25_ADDR_LEN
);
713 memcpy(dev
->dev_addr
, ax25_nocall
, AX25_ADDR_LEN
);
714 dev
->tx_queue_len
= 16;
717 /* --------------------------------------------------------------------- */
718 struct net_device
*hdlcdrv_register(const struct hdlcdrv_ops
*ops
,
719 unsigned int privsize
, const char *ifname
,
720 unsigned int baseaddr
, unsigned int irq
,
723 struct net_device
*dev
;
724 struct hdlcdrv_state
*s
;
729 if (privsize
< sizeof(struct hdlcdrv_state
))
730 privsize
= sizeof(struct hdlcdrv_state
);
732 dev
= alloc_netdev(privsize
, ifname
, hdlcdrv_setup
);
734 return ERR_PTR(-ENOMEM
);
737 * initialize part of the hdlcdrv_state struct
739 s
= netdev_priv(dev
);
740 s
->magic
= HDLCDRV_MAGIC
;
742 dev
->base_addr
= baseaddr
;
746 err
= register_netdev(dev
);
748 printk(KERN_WARNING
"hdlcdrv: cannot register net "
749 "device %s\n", dev
->name
);
756 /* --------------------------------------------------------------------- */
758 void hdlcdrv_unregister(struct net_device
*dev
)
760 struct hdlcdrv_state
*s
= netdev_priv(dev
);
762 BUG_ON(s
->magic
!= HDLCDRV_MAGIC
);
764 if (s
->opened
&& s
->ops
->close
)
766 unregister_netdev(dev
);
771 /* --------------------------------------------------------------------- */
773 EXPORT_SYMBOL(hdlcdrv_receiver
);
774 EXPORT_SYMBOL(hdlcdrv_transmitter
);
775 EXPORT_SYMBOL(hdlcdrv_arbitrate
);
776 EXPORT_SYMBOL(hdlcdrv_register
);
777 EXPORT_SYMBOL(hdlcdrv_unregister
);
779 /* --------------------------------------------------------------------- */
781 static int __init
hdlcdrv_init_driver(void)
783 printk(KERN_INFO
"hdlcdrv: (C) 1996-2000 Thomas Sailer HB9JNX/AE4WA\n");
784 printk(KERN_INFO
"hdlcdrv: version 0.8 compiled " __TIME__
" " __DATE__
"\n");
788 /* --------------------------------------------------------------------- */
790 static void __exit
hdlcdrv_cleanup_driver(void)
792 printk(KERN_INFO
"hdlcdrv: cleanup\n");
795 /* --------------------------------------------------------------------- */
797 MODULE_AUTHOR("Thomas M. Sailer, sailer@ife.ee.ethz.ch, hb9jnx@hb9w.che.eu");
798 MODULE_DESCRIPTION("Packet Radio network interface HDLC encoder/decoder");
799 MODULE_LICENSE("GPL");
800 module_init(hdlcdrv_init_driver
);
801 module_exit(hdlcdrv_cleanup_driver
);
803 /* --------------------------------------------------------------------- */