| 1 |
.\" Copyright 1996 Thomas Sailer ([email protected]) |
| 2 |
.\" May be distributed under the GNU General Public License |
| 3 |
.\" " |
| 4 |
.TH HDLCDRV 9 "27 April 2008" "Linux 2.1.x" "Kernel Reference Guide" |
| 5 |
.SH NAME |
| 6 |
hdlcdrv \- HDLC amateur (AX.25) packet radio network driver |
| 7 |
.SH SYNOPSIS |
| 8 |
|
| 9 |
.B #include <linux/hdlcdrv.h> |
| 10 |
|
| 11 |
.B linux/drivers/net/hdlcdrv.c |
| 12 |
|
| 13 |
.BI "extern inline void hdlcdrv_putbits(struct hdlcdrv_state * " s ", unsigned int " bits ");" |
| 14 |
|
| 15 |
.BI "extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state * " s ");" |
| 16 |
|
| 17 |
.BI "extern inline void hdlcdrv_channelbit(struct hdlcdrv_state * " s ", unsigned int " bit ");" |
| 18 |
|
| 19 |
.BI "extern inline void hdlcdrv_setdcd(struct hdlcdrv_state * " s " , int " dcd ");" |
| 20 |
|
| 21 |
.BI "extern inline int hdlcdrv_ptt(struct hdlcdrv_state * " s ");" |
| 22 |
|
| 23 |
.BI "void hdlcdrv_receiver(struct device *, struct hdlcdrv_state *);" |
| 24 |
|
| 25 |
.BI "void hdlcdrv_transmitter(struct device *, struct hdlcdrv_state *);" |
| 26 |
|
| 27 |
.BI "void hdlcdrv_arbitrate(struct device *, struct hdlcdrv_state *);" |
| 28 |
|
| 29 |
.BI "int hdlcdrv_register_hdlcdrv(struct device * " dev ", struct hdlcdrv_ops * " ops ", unsigned int " privsize ", char * " ifname ", unsigned int " baseaddr " , unsigned int " irq ", unsigned int " dma "); |
| 30 |
|
| 31 |
.BI "int hdlcdrv_unregister_hdlcdrv(struct device * " dev ");" |
| 32 |
|
| 33 |
.SH DESCRIPTION |
| 34 |
This driver should ease the implementation of simple AX.25 packet radio |
| 35 |
modems where the software is responsible for the HDLC encoding and decoding. |
| 36 |
Examples of such modems include the \fIbaycom\fP family and the |
| 37 |
\fIsoundcard\fP modems. |
| 38 |
|
| 39 |
This driver provides a standard Linux network driver interface. |
| 40 |
It can even be compiled if Kernel AX.25 is not enabled in the Linux |
| 41 |
configuration. This allows this driver to be used even for userland |
| 42 |
AX.25 stacks such as \fIWampes\fP or \fITNOS\fP, with the help of |
| 43 |
the \fInet2kiss\fP utility. |
| 44 |
|
| 45 |
This driver does not access any hardware; it is the responsibility of |
| 46 |
an additional hardware driver such as \fIbaycom\fP or \fIsoundmodem\fP |
| 47 |
to access the hardware and derive the bitstream to feed into this |
| 48 |
driver. |
| 49 |
|
| 50 |
The hardware driver should store its state in a structure of the |
| 51 |
following form: |
| 52 |
|
| 53 |
.nf |
| 54 |
struct hwdrv_state { |
| 55 |
struct hdlc_state \fIhdrv\fP; |
| 56 |
|
| 57 |
... the drivers private state |
| 58 |
}; |
| 59 |
.fi |
| 60 |
|
| 61 |
A pointer to this structure will be stored in \fIdev->priv\fP. |
| 62 |
|
| 63 |
\fBhdlcdrv_register_hdlcdrv\fP registers a hardware driver to the |
| 64 |
hdlc driver. \fIdev\fP points to storage for the \fIdevice\fP structure, |
| 65 |
which must be provided by the hardware driver, but gets initialized by |
| 66 |
this function call. \fIops\fP provides information about the hardware driver |
| 67 |
and its calls. \fIprivsize\fP should be \fIsizeof(struct\ hwdrv_state)\fP. |
| 68 |
\fIifname\fP specifies the name the interface should get. \fIbaseaddr\fP, |
| 69 |
\fIirq\fP and \fIdma\fP are simply stored in the \fIdevice\fP structure. |
| 70 |
After this function succeeds, the interface is registered with the kernel. |
| 71 |
It is not running, however, this must be done with |
| 72 |
\fBifconfig\ \fP\fIifname\fP\fB\ up\fP. |
| 73 |
|
| 74 |
\fBhdlcdrv_unregister_hdlcdrv\fP shuts the interface down and unregisters |
| 75 |
it with the kernel. |
| 76 |
|
| 77 |
\fBhdlcdrv_putbits\fP delivers 16 received bits for processing to the HDLC |
| 78 |
driver. This routine merely stores them in a buffer and does not process them. |
| 79 |
It is thus fast and can be called with interrupts off. The least significant |
| 80 |
bit should be the first one received. |
| 81 |
|
| 82 |
\fBhdlcdrv_getbits\fP requests 16 bits from the driver for transmission. |
| 83 |
The least significant bit should be transmitted first. This routine takes |
| 84 |
them from a buffer and is therefore fast. It can be called with interrupts |
| 85 |
off. |
| 86 |
|
| 87 |
\fBhdlcdrv_channelbit\fP puts a single bit into a buffer, which can be |
| 88 |
displayed with \fBsethdlc\ \-s\fP. It is intended for driver debugging |
| 89 |
purposes. |
| 90 |
|
| 91 |
\fBhdlcdrv_setdcd\fP informs the HDLC driver about the channel state |
| 92 |
(i.e. if the hardware driver detected a data carrier). This information |
| 93 |
is used in the channel access algorithm, i.e. it prevents the driver |
| 94 |
from transmitting on a half duplex channel if there is already a |
| 95 |
transmitter on air. |
| 96 |
|
| 97 |
\fBhdlcdrv_ptt\fP should be called by the hardware driver to determine |
| 98 |
if it should start or stop transmitting. The hardware driver does not |
| 99 |
need to worry about keyup delays. This is done by the HDLC driver. |
| 100 |
|
| 101 |
\fBhdlcdrv_receiver\fP actually processes the received bits delivered |
| 102 |
by \fBhdlcdrv_putbits\fP. It should be called with interrupts on. |
| 103 |
It guards itself against reentrance problems. |
| 104 |
|
| 105 |
\fBhdlcdrv_transmitter\fP actually prepares the bits to be transmitted. |
| 106 |
It should be called with interrupts on. It guards itself against |
| 107 |
reentrance problems. |
| 108 |
|
| 109 |
\fBhdlcdrv_arbitrate\fP does the channel access algorithm |
| 110 |
(p-persistent CSMA). It should be called once every 10ms. Note that the |
| 111 |
hardware driver \fBmust\fP set the \fIhdrv.par.bitrate\fP field prior |
| 112 |
to starting operation so that \fBhdlcdrv\fP can calculate the transmitter |
| 113 |
keyup delay correctly. |
| 114 |
|
| 115 |
.SH "HARDWARE DRIVER ENTRY POINTS" |
| 116 |
The hardware driver should provide the following information to |
| 117 |
the HDLC driver: |
| 118 |
|
| 119 |
.nf |
| 120 |
struct hdlcdrv_ops { |
| 121 |
const char *\fIdrvname\fP; |
| 122 |
const char *\fIdrvinfo\fP; |
| 123 |
int (*\fIopen\fP)(struct device *); |
| 124 |
int (*\fIclose\fP)(struct device *); |
| 125 |
int (*\fIioctl\fP)(struct device *, struct ifreq *, int); |
| 126 |
}; |
| 127 |
.fi |
| 128 |
|
| 129 |
\fBdrvname\fP and \fBdrvinfo\fP are just for informational purposes. |
| 130 |
|
| 131 |
The following routines receive a pointer to the \fIdevice\fP structure, |
| 132 |
where they may find the io address, irq and dma channels. |
| 133 |
|
| 134 |
\fBopen\fP must be provided. It is called during |
| 135 |
\fBifconfig\ \fP\fIifname\fP\fB\ up\fP and should check for the hardware, |
| 136 |
grab it and initialize it. It usually installs an interrupt handler |
| 137 |
which then gets invoked by the hardware. |
| 138 |
|
| 139 |
\fBclose\fP must be provided. It is called during |
| 140 |
\fBifconfig\ \fP\fIifname\fP\fB\ down\fP and should undo all actions done |
| 141 |
by \fBopen\fP, i.e. release io regions and irqs. |
| 142 |
|
| 143 |
\fBioctl\fP may be provided to implement device specific ioctl's. |
| 144 |
|
| 145 |
.SH "IOCTL CALLS" |
| 146 |
|
| 147 |
The driver only responds to \fISIOCDEVPRIVATE\fP. Parameters are passed |
| 148 |
from and to the driver using the following struct: |
| 149 |
|
| 150 |
.nf |
| 151 |
struct hdlcdrv_ioctl { |
| 152 |
int cmd; |
| 153 |
union { |
| 154 |
struct hdlcdrv_params mp; |
| 155 |
struct hdlcdrv_channel_params cp; |
| 156 |
struct hdlcdrv_channel_state cs; |
| 157 |
unsigned int calibrate; |
| 158 |
unsigned char bits; |
| 159 |
} data; |
| 160 |
}; |
| 161 |
.fi |
| 162 |
|
| 163 |
Since the 16 private \fIioctl\ request\fP numbers for network drivers |
| 164 |
were not enough, the driver implements its own \fIsub\ request\fP number |
| 165 |
with \fIcmd\fP. The following numbers are implemented: |
| 166 |
|
| 167 |
.TP |
| 168 |
.B HDLCDRVCTL_GETMODEMPAR |
| 169 |
returns the IO parameters of the modem in \fIdata.mp\fP. This includes |
| 170 |
the io address, irq, eventually dma, and ports to output a PTT signal. |
| 171 |
|
| 172 |
.TP |
| 173 |
.B HDLCDRVCTL_SETMODEMPAR |
| 174 |
sets the modem parameters. Only superuser can do this. Parameters |
| 175 |
can only be changed if the interface is not running (i.e. down). |
| 176 |
|
| 177 |
.TP |
| 178 |
.B HDLCDRVCTL_GETCHANNELPAR |
| 179 |
returns the channel access parameters. |
| 180 |
|
| 181 |
.TP |
| 182 |
.B HDLCDRVCTL_SETCHANNELPAR |
| 183 |
sets the channel access parameters. Only superuser can do this. |
| 184 |
They may also be changed using the \fBkissparms\fP command if using |
| 185 |
kernel AX.25 or the \fBparam\fP command of \fB*NOS\fP. |
| 186 |
|
| 187 |
.TP |
| 188 |
.B HDLCDRVCTL_GETSTAT |
| 189 |
statistics and status information, such as if a carrier is detected |
| 190 |
on the channel and if the interface is currently transmitting. |
| 191 |
|
| 192 |
.TP |
| 193 |
.B HDLCDRVCTL_CALIBRATE |
| 194 |
instructs the driver to transmit a calibration pattern for the |
| 195 |
specified number of seconds. |
| 196 |
|
| 197 |
.TP |
| 198 |
.B HDLCDRVCTL_GETSAMPLES |
| 199 |
returns the bits delivered by the hardware driver with |
| 200 |
\fIhdlcdrv_channelbit\fP. The bits are returned 8 at a time |
| 201 |
with the least significant bit the first one. This command may not be |
| 202 |
available, depending on debugging settings. |
| 203 |
|
| 204 |
.TP |
| 205 |
.B HDLCDRVCTL_GETBITS |
| 206 |
returns the bits delivered by the hardware driver to the HDLC decoder. |
| 207 |
The bits are returned 8 at a time with the least significant bit the |
| 208 |
first one. This command may not be available, depending on debugging |
| 209 |
settings. |
| 210 |
|
| 211 |
.SH "SEE ALSO" |
| 212 |
.BR baycom "\ (9), " soundmodem "\ (9), " sethdlc "\ (8), " |
| 213 |
linux/drivers/net/hdlcdrv.c, |
| 214 |
|
| 215 |
.SH AUTHOR |
| 216 |
hdlcdrv was written by Thomas Sailer, HB9JNX/AE4WA, ([email protected]). |