linux/drivers/isdn/mISDN/l1oip_core.c

// SPDX-License-Identifier: GPL-2.0-or-later
/*

 * l1oip.c  low level driver for tunneling layer 1 over IP
 *
 * NOTE: It is not compatible with TDMoIP nor "ISDN over IP".
 *
 * Author	Andreas Eversberg ([email protected])
 */

/* module parameters:
 * type:
 Value 1	= BRI
 Value 2	= PRI
 Value 3 = BRI (multi channel frame, not supported yet)
 Value 4 = PRI (multi channel frame, not supported yet)
 A multi channel frame reduces overhead to a single frame for all
 b-channels, but increases delay.
 (NOTE: Multi channel frames are not implemented yet.)

 * codec:
 Value 0 = transparent (default)
 Value 1 = transfer ALAW
 Value 2 = transfer ULAW
 Value 3 = transfer generic 4 bit compression.

 * ulaw:
 0 = we use a-Law (default)
 1 = we use u-Law

 * limit:
 limitation of B-channels to control bandwidth (1...126)
 BRI: 1 or 2
 PRI: 1-30, 31-126 (126, because dchannel ist not counted here)
 Also limited ressources are used for stack, resulting in less channels.
 It is possible to have more channels than 30 in PRI mode, this must
 be supported by the application.

 * ip:
 byte representation of remote ip address (127.0.0.1 -> 127,0,0,1)
 If not given or four 0, no remote address is set.
 For multiple interfaces, concat ip addresses. (127,0,0,1,127,0,0,1)

 * port:
 port number (local interface)
 If not given or 0, port 931 is used for fist instance, 932 for next...
 For multiple interfaces, different ports must be given.

 * remoteport:
 port number (remote interface)
 If not given or 0, remote port equals local port
 For multiple interfaces on equal sites, different ports must be given.

 * ondemand:
 0 = fixed (always transmit packets, even when remote side timed out)
 1 = on demand (only transmit packets, when remote side is detected)
 the default is 0
 NOTE: ID must also be set for on demand.

 * id:
 optional value to identify frames. This value must be equal on both
 peers and should be random. If omitted or 0, no ID is transmitted.

 * debug:
 NOTE: only one debug value must be given for all cards
 enable debugging (see l1oip.h for debug options)


 Special mISDN controls:

 op = MISDN_CTRL_SETPEER*
 p1 = bytes 0-3 : remote IP address in network order (left element first)
 p2 = bytes 1-2 : remote port in network order (high byte first)
 optional:
 p2 = bytes 3-4 : local port in network order (high byte first)

 op = MISDN_CTRL_UNSETPEER*

 * Use l1oipctrl for comfortable setting or removing ip address.
 (Layer 1 Over IP CTRL)


 L1oIP-Protocol
 --------------

 Frame Header:

 7 6 5 4 3 2 1 0
 +---------------+
 |Ver|T|I|Coding |
 +---------------+
 |  ID byte 3 *  |
 +---------------+
 |  ID byte 2 *  |
 +---------------+
 |  ID byte 1 *  |
 +---------------+
 |  ID byte 0 *  |
 +---------------+
 |M|   Channel   |
 +---------------+
 |    Length *   |
 +---------------+
 | Time Base MSB |
 +---------------+
 | Time Base LSB |
 +---------------+
 | Data....	|

 ...

 |               |
 +---------------+
 |M|   Channel   |
 +---------------+
 |    Length *   |
 +---------------+
 | Time Base MSB |
 +---------------+
 | Time Base LSB |
 +---------------+
 | Data....	|

 ...


 * Only included in some cases.

 - Ver = Version
 If version is missmatch, the frame must be ignored.

 - T = Type of interface
 Must be 0 for S0 or 1 for E1.

 - I = Id present
 If bit is set, four ID bytes are included in frame.

 - ID = Connection ID
 Additional ID to prevent Denial of Service attacs. Also it prevents hijacking
 connections with dynamic IP. The ID should be random and must not be 0.

 - Coding = Type of codec
 Must be 0 for no transcoding. Also for D-channel and other HDLC frames.
 1 and 2 are reserved for explicitly use of a-LAW or u-LAW codec.
 3 is used for generic table compressor.

 - M = More channels to come. If this flag is 1, the following byte contains
 the length of the channel data. After the data block, the next channel will
 be defined. The flag for the last channel block (or if only one channel is
 transmitted), must be 0 and no length is given.

 - Channel = Channel number
 0 reserved
 1-3 channel data for S0 (3 is D-channel)
 1-31 channel data for E1 (16 is D-channel)
 32-127 channel data for extended E1 (16 is D-channel)

 - The length is used if the M-flag is 1. It is used to find the next channel
 inside frame.
 NOTE: A value of 0 equals 256 bytes of data.
 -> For larger data blocks, a single frame must be used.
 -> For larger streams, a single frame or multiple blocks with same channel ID
 must be used.

 - Time Base = Timestamp of first sample in frame
 The "Time Base" is used to rearange packets and to detect packet loss.
 The 16 bits are sent in network order (MSB first) and count 1/8000 th of a
 second. This causes a wrap around each 8,192 seconds. There is no requirement
 for the initial "Time Base", but 0 should be used for the first packet.
 In case of HDLC data, this timestamp counts the packet or byte number.


 Two Timers:

 After initialisation, a timer of 15 seconds is started. Whenever a packet is
 transmitted, the timer is reset to 15 seconds again. If the timer expires, an
 empty packet is transmitted. This keep the connection alive.

 When a valid packet is received, a timer 65 seconds is started. The interface
 become ACTIVE. If the timer expires, the interface becomes INACTIVE.


 Dynamic IP handling:

 To allow dynamic IP, the ID must be non 0. In this case, any packet with the
 correct port number and ID will be accepted. If the remote side changes its IP
 the new IP is used for all transmitted packets until it changes again.


 On Demand:

 If the ondemand parameter is given, the remote IP is set to 0 on timeout.
 This will stop keepalive traffic to remote. If the remote is online again,
 traffic will continue to the remote address. This is useful for road warriors.
 This feature only works with ID set, otherwhise it is highly unsecure.


 Socket and Thread
 -----------------

 The complete socket opening and closing is done by a thread.
 When the thread opened a socket, the hc->socket descriptor is set. Whenever a
 packet shall be sent to the socket, the hc->socket must be checked whether not
 NULL. To prevent change in socket descriptor, the hc->socket_lock must be used.
 To change the socket, a recall of l1oip_socket_open() will safely kill the
 socket process and create a new one.

*/

#define L1OIP_VERSION

#include <linux/module.h>
#include <linux/delay.h>
#include <linux/mISDNif.h>
#include <linux/mISDNhw.h>
#include <linux/mISDNdsp.h>
#include <linux/init.h>
#include <linux/in.h>
#include <linux/inet.h>
#include <linux/workqueue.h>
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/sched/signal.h>

#include <net/sock.h>
#include "core.h"
#include "l1oip.h"

static const char *l1oip_revision =;

static int l1oip_cnt;
static DEFINE_SPINLOCK(l1oip_lock);
static LIST_HEAD(l1oip_ilist);

#define MAX_CARDS
static u_int type[MAX_CARDS];
static u_int codec[MAX_CARDS];
static u_int ip[MAX_CARDS * 4];
static u_int port[MAX_CARDS];
static u_int remoteport[MAX_CARDS];
static u_int ondemand[MAX_CARDS];
static u_int limit[MAX_CARDS];
static u_int id[MAX_CARDS];
static int debug;
static int ulaw;

MODULE_AUTHOR();
MODULE_DESCRIPTION();
MODULE_LICENSE();
module_param_array();
module_param_array();
module_param_array();
module_param_array();
module_param_array();
module_param_array();
module_param_array();
module_param_array();
module_param(ulaw, uint, S_IRUGO | S_IWUSR);
module_param(debug, uint, S_IRUGO | S_IWUSR);

/*
 * send a frame via socket, if open and restart timer
 */
static int
l1oip_socket_send(struct l1oip *hc, u8 localcodec, u8 channel, u32 chanmask,
		  u16 timebase, u8 *buf, int len)
{}


/*
 * receive channel data from socket
 */
static void
l1oip_socket_recv(struct l1oip *hc, u8 remotecodec, u8 channel, u16 timebase,
		  u8 *buf, int len)
{}


/*
 * parse frame and extract channel data
 */
static void
l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len)
{}


/*
 * socket stuff
 */
static int
l1oip_socket_thread(void *data)
{}

static void
l1oip_socket_close(struct l1oip *hc)
{}

static int
l1oip_socket_open(struct l1oip *hc)
{}


static void
l1oip_send_bh(struct work_struct *work)
{}


/*
 * timer stuff
 */
static void
l1oip_keepalive(struct timer_list *t)
{}

static void
l1oip_timeout(struct timer_list *t)
{}


/*
 * message handling
 */
static int
handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
{}

static int
channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
{}

static int
open_dchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
{}

static int
open_bchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
{}

static int
l1oip_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
{}

static int
handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
{}

static int
channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
{}

static int
l1oip_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
{}


/*
 * cleanup module and stack
 */
static void
release_card(struct l1oip *hc)
{}

static void
l1oip_cleanup(void)
{}


/*
 * module and stack init
 */
static int
init_card(struct l1oip *hc, int pri, int bundle)
{}

static int __init
l1oip_init(void)
{}

module_init();
module_exit(l1oip_cleanup);