HDLCDRV(9)

πŸ“¦
version 1.1.0 Β· 2 versions
  • 1.1.0 Β· alpine 3.24, debian bookworm, debian trixie, nixos 26.05, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 1.0.4 Β· fedora 43, fedora 44
, in alpine 3.24, debian bookworm, debian trixie, nixos 26.05, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– HDLCDRV(9) πŸ’–

okay so bestie, welcome to the manual page for hdlcdrv β€” the HDLC amateur (AX.25) packet radio network driver, and yes we're doing this properly, from the Kernel Reference Guide, no cap. Grab a snack, this one's a whole vibe πŸ“


✨ NAME ✨

hdlcdrv β€” the HDLC amateur (AX.25) packet radio network driver. that's it, that's the name, and honestly it ate πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <linux/hdlcdrv.h>

linux/drivers/net/hdlcdrv.c

extern inline void hdlcdrv_putbits(struct hdlcdrv_state * s, unsigned
int bits);

extern inline unsigned int hdlcdrv_getbits(struct hdlcdrv_state * s);

extern inline void hdlcdrv_channelbit(struct hdlcdrv_state * s, unsigned
int bit);

extern inline void hdlcdrv_setdcd(struct hdlcdrv_state * s , int dcd);

extern inline int hdlcdrv_ptt(struct hdlcdrv_state * s);

void hdlcdrv_receiver(struct device *, struct hdlcdrv_state *);

void hdlcdrv_transmitter(struct device *, struct hdlcdrv_state *);

void hdlcdrv_arbitrate(struct device *, struct hdlcdrv_state *);

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);

int hdlcdrv_unregister_hdlcdrv(struct device * dev);

like, look at all those little functions. iconic. πŸ‘‘


🌸 DESCRIPTION 🌸

so the whole point of this driver is that it eases the implementation of simple AX.25 packet radio modems where the software is the one doing the HDLC encoding and decoding. examples of such modems include the baycom family and the soundcard modems β€” iykyk πŸŽ€

this driver gives you a standard Linux network driver interface. and the wild part? it can even be compiled if Kernel AX.25 is not enabled in the Linux configuration. that means this driver can be used even for userland AX.25 stacks such as Wampes or TNOS, with a little help from the net2kiss utility. slay. ✨

🫢 important: this driver does not access any hardware. it is the responsibility of an additional hardware driver β€” such as baycom or soundmodem β€” to access the hardware and derive the bitstream to feed into this driver. division of labor, main character energy.

🧚 the state struct

the hardware driver should store its state in a structure of the following form:

struct hwdrv_state {
     struct hdlc_state hdrv;

     ... the drivers private state
};

a pointer to this structure will be stored in dev->priv. noted. πŸ’œ

πŸŽ€ the functions, one by one

hdlcdrv_register_hdlcdrv registers a hardware driver to the hdlc driver. dev points to storage for the device structure β€” which must be provided by the hardware driver, but gets initialized by this function call. ops provides information about the hardware driver and its calls. privsize should be sizeof(struct hwdrv_state). ifname specifies the name the interface should get. baseaddr, irq and dma are simply stored in the device structure. after this function succeeds, the interface is registered with the kernel. it is not running, however β€” you gotta do that yourself with ifconfig ifname up. πŸ”₯

hdlcdrv_unregister_hdlcdrv shuts the interface down and unregisters it with the kernel. bye bestie πŸ‘‹

hdlcdrv_putbits delivers 16 received bits for processing to the HDLC driver. this routine merely stores them in a buffer and does not process them. it is thus fast and can be called with interrupts off. the least significant bit should be the first one received. ⭐

hdlcdrv_getbits requests 16 bits from the driver for transmission. the least significant bit should be transmitted first. this routine takes them from a buffer and is therefore fast. it can be called with interrupts off. πŸ¦‹

hdlcdrv_channelbit puts a single bit into a buffer, which can be displayed with sethdlc -s. it is intended for driver debugging purposes. πŸ™ˆ

hdlcdrv_setdcd informs the HDLC driver about the channel state (i.e. if the hardware driver detected a data carrier). this information is used in the channel access algorithm β€” i.e. it prevents the driver from transmitting on a half duplex channel if there is already a transmitter on air. courtesy, we love to see it πŸ’…

hdlcdrv_ptt should be called by the hardware driver to determine if it should start or stop transmitting. the hardware driver does not need to worry about keyup delays β€” this is done by the HDLC driver. we handle that for you, bestie 🫢

hdlcdrv_receiver actually processes the received bits delivered by hdlcdrv_putbits. it should be called with interrupts on. it guards itself against reentrance problems. self-aware queen πŸ‘‘

hdlcdrv_transmitter actually prepares the bits to be transmitted. it should be called with interrupts on. it guards itself against reentrance problems. same energy πŸ’–

hdlcdrv_arbitrate does the channel access algorithm (p-persistent CSMA). it should be called once every 10ms. note that the hardware driver must set the hdrv.par.bitrate field prior to starting operation so that hdlcdrv can calculate the transmitter keyup delay correctly. don't skip this step fr fr 😭


πŸ”₯ HARDWARE DRIVER ENTRY POINTS πŸ”₯

the hardware driver should provide the following information to the HDLC driver:

struct hdlcdrv_ops {
     const char *drvname;
     const char *drvinfo;
     int (*open)(struct device *);
     int (*close)(struct device *);
     int (*ioctl)(struct device *, struct ifreq *, int);
};

drvname and drvinfo are just for informational purposes. cute, low-key decorative 🌈

the following routines receive a pointer to the device structure, where they may find the io address, irq and dma channels:

  • open β€” must be provided. it is called during ifconfig ifname up and should check for the hardware, grab it and initialize it. it usually installs an interrupt handler which then gets invoked by the hardware. glow up moment ✨
  • close β€” must be provided. it is called during ifconfig ifname down and should undo all actions done by open, i.e. release io regions and irqs. cleanup era 🧹
  • ioctl β€” may be provided to implement device specific ioctl's. optional icon πŸ’…

πŸ‘‘ IOCTL CALLS πŸ‘‘

the driver only responds to SIOCDEVPRIVATE. parameters are passed from and to the driver using the following struct:

struct hdlcdrv_ioctl {
     int cmd;
     union {
          struct hdlcdrv_params mp;
          struct hdlcdrv_channel_params cp;
          struct hdlcdrv_channel_state cs;
          unsigned int calibrate;
          unsigned char bits;
     } data;
};

so here's the tea: since the 16 private ioctl request numbers for network drivers were not enough, the driver implements its own sub request number with cmd. the following numbers are implemented:

  • HDLCDRVCTL_GETMODEMPAR β€” returns the IO parameters of the modem in data.mp. this includes the io address, irq, eventually dma, and ports to output a PTT signal. πŸ“‘
  • HDLCDRVCTL_SETMODEMPAR β€” sets the modem parameters. only superuser can do this. parameters can only be changed if the interface is not running (i.e. down). no sneaky edits mid-flight πŸ™ˆ
  • HDLCDRVCTL_GETCHANNELPAR β€” returns the channel access parameters. πŸ’œ
  • HDLCDRVCTL_SETCHANNELPAR β€” sets the channel access parameters. only superuser can do this. they may also be changed using the kissparms command if using kernel AX.25, or the param command of *NOS. πŸŽ€
  • HDLCDRVCTL_GETSTAT β€” statistics and status information, such as if a carrier is detected on the channel and if the interface is currently transmitting. the vibe check command fr 🌸
  • HDLCDRVCTL_CALIBRATE β€” instructs the driver to transmit a calibration pattern for the specified number of seconds. ⏱️
  • HDLCDRVCTL_GETSAMPLES β€” returns the bits delivered by the hardware driver with hdlcdrv_channelbit. the bits are returned 8 at a time with the least significant bit the first one. this command may not be available, depending on debugging settings. πŸ™ˆ
  • HDLCDRVCTL_GETBITS β€” returns the bits delivered by the hardware driver to the HDLC decoder. the bits are returned 8 at a time with the least significant bit the first one. this command may not be available, depending on debugging settings. ⭐

🫢 SEE ALSO 🫢

baycom (9), soundmodem (9), sethdlc (8), linux/drivers/net/hdlcdrv.c, β€” go read those next bestie, they're all part of the same little ecosystem πŸ’–


πŸ’œ AUTHOR πŸ’œ

hdlcdrv was written by Thomas Sailer, HB9JNX/AE4WA, (t.sailer@alumni.ethz.ch). legend behavior, honestly πŸ‘‘


and that's the whole page!! you made it to the end bestie, so proud πŸ¦‹βœ¨ this was Linux 2.1.x, dated 27 April 2008 β€” mwah, bye, go key up a transmitter responsibly πŸ’…πŸŽ€