2008-07-26 18:02:10 -06:00
|
|
|
/*
|
|
|
|
|
|
|
|
* 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 (jolly@eversberg.eu)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* module parameters:
|
|
|
|
* type:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.)
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* codec:
|
2012-02-19 20:52:38 -07:00
|
|
|
Value 0 = transparent (default)
|
|
|
|
Value 1 = transfer ALAW
|
|
|
|
Value 2 = transfer ULAW
|
|
|
|
Value 3 = transfer generic 4 bit compression.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* ulaw:
|
2012-02-19 20:52:38 -07:00
|
|
|
0 = we use a-Law (default)
|
|
|
|
1 = we use u-Law
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* limit:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* ip:
|
2012-02-19 20:52:38 -07:00
|
|
|
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)
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* port:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* remoteport:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* ondemand:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* id:
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
* debug:
|
2012-02-19 20:52:38 -07:00
|
|
|
NOTE: only one debug value must be given for all cards
|
|
|
|
enable debugging (see l1oip.h for debug options)
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
Special mISDN controls:
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
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.
|
2012-02-19 20:52:38 -07:00
|
|
|
(Layer 1 Over IP CTRL)
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
L1oIP-Protocol
|
|
|
|
--------------
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
Frame Header:
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
7 6 5 4 3 2 1 0
|
2012-02-19 20:52:38 -07:00
|
|
|
+---------------+
|
|
|
|
|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.
|
2008-07-26 18:02:10 -06:00
|
|
|
1 and 2 are reserved for explicitly use of a-LAW or u-LAW codec.
|
|
|
|
3 is used for generic table compressor.
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
- 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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
- 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)
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
- 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.
|
2008-07-26 18:02:10 -06:00
|
|
|
-> For larger data blocks, a single frame must be used.
|
|
|
|
-> For larger streams, a single frame or multiple blocks with same channel ID
|
2012-02-19 20:52:38 -07:00
|
|
|
must be used.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
- 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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
Two Timers:
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
When a valid packet is received, a timer 65 seconds is started. The interface
|
|
|
|
become ACTIVE. If the timer expires, the interface becomes INACTIVE.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
Dynamic IP handling:
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
On Demand:
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
Socket and Thread
|
|
|
|
-----------------
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
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 wheter 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.
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define L1OIP_VERSION 0 /* 0...3 */
|
|
|
|
|
|
|
|
#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 cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2017-02-08 10:51:30 -07:00
|
|
|
#include <linux/sched/signal.h>
|
|
|
|
|
2008-07-26 18:02:10 -06:00
|
|
|
#include <net/sock.h>
|
|
|
|
#include "core.h"
|
|
|
|
#include "l1oip.h"
|
|
|
|
|
|
|
|
static const char *l1oip_revision = "2.00";
|
|
|
|
|
|
|
|
static int l1oip_cnt;
|
|
|
|
static spinlock_t l1oip_lock;
|
|
|
|
static struct list_head l1oip_ilist;
|
|
|
|
|
|
|
|
#define MAX_CARDS 16
|
|
|
|
static u_int type[MAX_CARDS];
|
|
|
|
static u_int codec[MAX_CARDS];
|
2012-02-19 20:52:38 -07:00
|
|
|
static u_int ip[MAX_CARDS * 4];
|
2008-07-26 18:02:10 -06:00
|
|
|
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("Andreas Eversberg");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
module_param_array(type, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(codec, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(ip, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(port, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(remoteport, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(ondemand, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(limit, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
module_param_array(id, uint, NULL, S_IRUGO | S_IWUSR);
|
|
|
|
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,
|
2012-02-19 20:52:38 -07:00
|
|
|
u16 timebase, u8 *buf, int len)
|
2008-07-26 18:02:10 -06:00
|
|
|
{
|
|
|
|
u8 *p;
|
2012-02-19 20:52:38 -07:00
|
|
|
u8 frame[len + 32];
|
2008-07-26 18:02:10 -06:00
|
|
|
struct socket *socket = NULL;
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: sending data to socket (len = %d)\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
p = frame;
|
|
|
|
|
|
|
|
/* restart timer */
|
2014-05-21 14:08:48 -06:00
|
|
|
if (time_before(hc->keep_tl.expires, jiffies + 5 * HZ))
|
|
|
|
mod_timer(&hc->keep_tl, jiffies + L1OIP_KEEPALIVE * HZ);
|
|
|
|
else
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->keep_tl.expires = jiffies + L1OIP_KEEPALIVE * HZ;
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: resetting timer\n", __func__);
|
|
|
|
|
|
|
|
/* drop if we have no remote ip or port */
|
|
|
|
if (!hc->sin_remote.sin_addr.s_addr || !hc->sin_remote.sin_port) {
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: dropping frame, because remote "
|
2012-02-19 20:52:38 -07:00
|
|
|
"IP is not set.\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* assemble frame */
|
2012-02-19 20:52:38 -07:00
|
|
|
*p++ = (L1OIP_VERSION << 6) /* version and coding */
|
|
|
|
| (hc->pri ? 0x20 : 0x00) /* type */
|
|
|
|
| (hc->id ? 0x10 : 0x00) /* id */
|
|
|
|
| localcodec;
|
2008-07-26 18:02:10 -06:00
|
|
|
if (hc->id) {
|
2012-02-19 20:52:38 -07:00
|
|
|
*p++ = hc->id >> 24; /* id */
|
|
|
|
*p++ = hc->id >> 16;
|
|
|
|
*p++ = hc->id >> 8;
|
2008-07-26 18:02:10 -06:00
|
|
|
*p++ = hc->id;
|
|
|
|
}
|
2012-10-24 22:30:52 -06:00
|
|
|
*p++ = 0x00 + channel; /* m-flag, channel */
|
2012-02-19 20:52:38 -07:00
|
|
|
*p++ = timebase >> 8; /* time base */
|
2008-07-26 18:02:10 -06:00
|
|
|
*p++ = timebase;
|
|
|
|
|
|
|
|
if (buf && len) { /* add data to frame */
|
|
|
|
if (localcodec == 1 && ulaw)
|
|
|
|
l1oip_ulaw_to_alaw(buf, len, p);
|
|
|
|
else if (localcodec == 2 && !ulaw)
|
|
|
|
l1oip_alaw_to_ulaw(buf, len, p);
|
|
|
|
else if (localcodec == 3)
|
|
|
|
len = l1oip_law_to_4bit(buf, len, p,
|
2012-02-19 20:52:38 -07:00
|
|
|
&hc->chan[channel].codecstate);
|
2008-07-26 18:02:10 -06:00
|
|
|
else
|
|
|
|
memcpy(p, buf, len);
|
|
|
|
}
|
|
|
|
len += p - frame;
|
|
|
|
|
|
|
|
/* check for socket in safe condition */
|
|
|
|
spin_lock(&hc->socket_lock);
|
|
|
|
if (!hc->socket) {
|
|
|
|
spin_unlock(&hc->socket_lock);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* seize socket */
|
|
|
|
socket = hc->socket;
|
|
|
|
hc->socket = NULL;
|
|
|
|
spin_unlock(&hc->socket_lock);
|
|
|
|
/* send packet */
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: sending packet to socket (len "
|
2012-02-19 20:52:38 -07:00
|
|
|
"= %d)\n", __func__, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->sendiov.iov_base = frame;
|
|
|
|
hc->sendiov.iov_len = len;
|
2009-05-22 05:04:57 -06:00
|
|
|
len = kernel_sendmsg(socket, &hc->sendmsg, &hc->sendiov, 1, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
/* give socket back */
|
|
|
|
hc->socket = socket; /* no locking required */
|
|
|
|
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* receive channel data from socket
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
l1oip_socket_recv(struct l1oip *hc, u8 remotecodec, u8 channel, u16 timebase,
|
2012-02-19 20:52:38 -07:00
|
|
|
u8 *buf, int len)
|
2008-07-26 18:02:10 -06:00
|
|
|
{
|
|
|
|
struct sk_buff *nskb;
|
|
|
|
struct bchannel *bch;
|
|
|
|
struct dchannel *dch;
|
|
|
|
u8 *p;
|
|
|
|
u32 rx_counter;
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: received empty keepalive data, "
|
2012-02-19 20:52:38 -07:00
|
|
|
"ignoring\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: received data, sending to mISDN (%d)\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
if (channel < 1 || channel > 127) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - channel %d out of "
|
2012-02-19 20:52:38 -07:00
|
|
|
"range\n", __func__, channel);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dch = hc->chan[channel].dch;
|
|
|
|
bch = hc->chan[channel].bch;
|
|
|
|
if (!dch && !bch) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - channel %d not in "
|
2012-02-19 20:52:38 -07:00
|
|
|
"stack\n", __func__, channel);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* prepare message */
|
2012-02-19 20:52:38 -07:00
|
|
|
nskb = mI_alloc_skb((remotecodec == 3) ? (len << 1) : len, GFP_ATOMIC);
|
2008-07-26 18:02:10 -06:00
|
|
|
if (!nskb) {
|
|
|
|
printk(KERN_ERR "%s: No mem for skb.\n", __func__);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-19 20:52:38 -07:00
|
|
|
p = skb_put(nskb, (remotecodec == 3) ? (len << 1) : len);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
if (remotecodec == 1 && ulaw)
|
|
|
|
l1oip_alaw_to_ulaw(buf, len, p);
|
|
|
|
else if (remotecodec == 2 && !ulaw)
|
|
|
|
l1oip_ulaw_to_alaw(buf, len, p);
|
|
|
|
else if (remotecodec == 3)
|
|
|
|
len = l1oip_4bit_to_law(buf, len, p);
|
|
|
|
else
|
|
|
|
memcpy(p, buf, len);
|
|
|
|
|
|
|
|
/* send message up */
|
|
|
|
if (dch && len >= 2) {
|
|
|
|
dch->rx_skb = nskb;
|
|
|
|
recv_Dchannel(dch);
|
|
|
|
}
|
|
|
|
if (bch) {
|
|
|
|
/* expand 16 bit sequence number to 32 bit sequence number */
|
|
|
|
rx_counter = hc->chan[channel].rx_counter;
|
|
|
|
if (((s16)(timebase - rx_counter)) >= 0) {
|
|
|
|
/* time has changed forward */
|
|
|
|
if (timebase >= (rx_counter & 0xffff))
|
|
|
|
rx_counter =
|
|
|
|
(rx_counter & 0xffff0000) | timebase;
|
|
|
|
else
|
2012-02-19 20:52:38 -07:00
|
|
|
rx_counter = ((rx_counter & 0xffff0000) + 0x10000)
|
2008-07-26 18:02:10 -06:00
|
|
|
| timebase;
|
|
|
|
} else {
|
|
|
|
/* time has changed backwards */
|
|
|
|
if (timebase < (rx_counter & 0xffff))
|
|
|
|
rx_counter =
|
|
|
|
(rx_counter & 0xffff0000) | timebase;
|
|
|
|
else
|
2012-02-19 20:52:38 -07:00
|
|
|
rx_counter = ((rx_counter & 0xffff0000) - 0x10000)
|
2008-07-26 18:02:10 -06:00
|
|
|
| timebase;
|
|
|
|
}
|
|
|
|
hc->chan[channel].rx_counter = rx_counter;
|
|
|
|
|
|
|
|
#ifdef REORDER_DEBUG
|
|
|
|
if (hc->chan[channel].disorder_flag) {
|
2017-11-03 10:52:45 -06:00
|
|
|
swap(hc->chan[channel].disorder_skb, nskb);
|
|
|
|
swap(hc->chan[channel].disorder_cnt, rx_counter);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
hc->chan[channel].disorder_flag ^= 1;
|
|
|
|
if (nskb)
|
|
|
|
#endif
|
2009-05-22 05:04:56 -06:00
|
|
|
queue_ch_frame(&bch->ch, PH_DATA_IND, rx_counter, nskb);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* parse frame and extract channel data
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
l1oip_socket_parse(struct l1oip *hc, struct sockaddr_in *sin, u8 *buf, int len)
|
|
|
|
{
|
2008-12-12 22:17:38 -07:00
|
|
|
u32 packet_id;
|
2008-07-26 18:02:10 -06:00
|
|
|
u8 channel;
|
|
|
|
u8 remotecodec;
|
|
|
|
u16 timebase;
|
|
|
|
int m, mlen;
|
|
|
|
int len_start = len; /* initial frame length */
|
|
|
|
struct dchannel *dch = hc->chan[hc->d_idx].dch;
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: received frame, parsing... (%d)\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2010-01-29 00:57:49 -07:00
|
|
|
/* check length */
|
2012-02-19 20:52:38 -07:00
|
|
|
if (len < 1 + 1 + 2) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - length %d below "
|
2012-02-19 20:52:38 -07:00
|
|
|
"4 bytes\n", __func__, len);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check version */
|
2012-02-19 20:52:38 -07:00
|
|
|
if (((*buf) >> 6) != L1OIP_VERSION) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - unknown version %d\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, buf[0]>>6);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check type */
|
2012-02-19 20:52:38 -07:00
|
|
|
if (((*buf) & 0x20) && !hc->pri) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - received E1 packet "
|
2012-02-19 20:52:38 -07:00
|
|
|
"on S0 interface\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
2012-02-19 20:52:38 -07:00
|
|
|
if (!((*buf) & 0x20) && hc->pri) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - received S0 packet "
|
2012-02-19 20:52:38 -07:00
|
|
|
"on E1 interface\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get id flag */
|
2012-02-19 20:52:38 -07:00
|
|
|
packet_id = (*buf >> 4) & 1;
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
/* check coding */
|
|
|
|
remotecodec = (*buf) & 0x0f;
|
|
|
|
if (remotecodec > 3) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - remotecodec %d "
|
2012-02-19 20:52:38 -07:00
|
|
|
"unsupported\n", __func__, remotecodec);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
buf++;
|
|
|
|
len--;
|
|
|
|
|
2008-12-12 22:17:38 -07:00
|
|
|
/* check packet_id */
|
|
|
|
if (packet_id) {
|
2008-07-26 18:02:10 -06:00
|
|
|
if (!hc->id) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet has id "
|
2012-02-19 20:52:38 -07:00
|
|
|
"0x%x, but we have not\n", __func__, packet_id);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (len < 4) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet too "
|
2012-02-19 20:52:38 -07:00
|
|
|
"short for ID value\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
2008-12-12 22:17:38 -07:00
|
|
|
packet_id = (*buf++) << 24;
|
|
|
|
packet_id += (*buf++) << 16;
|
|
|
|
packet_id += (*buf++) << 8;
|
|
|
|
packet_id += (*buf++);
|
2008-07-26 18:02:10 -06:00
|
|
|
len -= 4;
|
|
|
|
|
2008-12-12 22:17:38 -07:00
|
|
|
if (packet_id != hc->id) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - ID mismatch, "
|
2012-02-19 20:52:38 -07:00
|
|
|
"got 0x%x, we 0x%x\n",
|
|
|
|
__func__, packet_id, hc->id);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (hc->id) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet has no "
|
2012-02-19 20:52:38 -07:00
|
|
|
"ID, but we have\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
multiframe:
|
|
|
|
if (len < 1) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet too short, "
|
2012-02-19 20:52:38 -07:00
|
|
|
"channel expected at position %d.\n",
|
|
|
|
__func__, len-len_start + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get channel and multiframe flag */
|
2012-02-19 20:52:38 -07:00
|
|
|
channel = *buf & 0x7f;
|
2008-07-26 18:02:10 -06:00
|
|
|
m = *buf >> 7;
|
|
|
|
buf++;
|
|
|
|
len--;
|
|
|
|
|
|
|
|
/* check length on multiframe */
|
|
|
|
if (m) {
|
|
|
|
if (len < 1) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet too "
|
2012-02-19 20:52:38 -07:00
|
|
|
"short, length expected at position %d.\n",
|
|
|
|
__func__, len_start - len - 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mlen = *buf++;
|
|
|
|
len--;
|
|
|
|
if (mlen == 0)
|
|
|
|
mlen = 256;
|
2012-02-19 20:52:38 -07:00
|
|
|
if (len < mlen + 3) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - length %d at "
|
2012-02-19 20:52:38 -07:00
|
|
|
"position %d exceeds total length %d.\n",
|
|
|
|
__func__, mlen, len_start-len - 1, len_start);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
2012-02-19 20:52:38 -07:00
|
|
|
if (len == mlen + 3) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "%s: packet error - length %d at "
|
2012-02-19 20:52:38 -07:00
|
|
|
"position %d will not allow additional "
|
|
|
|
"packet.\n",
|
|
|
|
__func__, mlen, len_start-len + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
2012-02-19 20:52:38 -07:00
|
|
|
mlen = len - 2; /* single frame, subtract timebase */
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
if (len < 2) {
|
|
|
|
printk(KERN_WARNING "%s: packet error - packet too short, time "
|
2012-02-19 20:52:38 -07:00
|
|
|
"base expected at position %d.\n",
|
|
|
|
__func__, len-len_start + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get time base */
|
|
|
|
timebase = (*buf++) << 8;
|
|
|
|
timebase |= (*buf++);
|
|
|
|
len -= 2;
|
|
|
|
|
|
|
|
/* if inactive, we send up a PH_ACTIVATE and activate */
|
|
|
|
if (!test_bit(FLG_ACTIVE, &dch->Flags)) {
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: interface become active due to "
|
2012-02-19 20:52:38 -07:00
|
|
|
"received packet\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
test_and_set_bit(FLG_ACTIVE, &dch->Flags);
|
|
|
|
_queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY, 0,
|
2012-02-19 20:52:38 -07:00
|
|
|
NULL, GFP_ATOMIC);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* distribute packet */
|
|
|
|
l1oip_socket_recv(hc, remotecodec, channel, timebase, buf, mlen);
|
|
|
|
buf += mlen;
|
|
|
|
len -= mlen;
|
|
|
|
|
|
|
|
/* multiframe */
|
|
|
|
if (m)
|
|
|
|
goto multiframe;
|
|
|
|
|
|
|
|
/* restart timer */
|
2014-05-21 14:08:47 -06:00
|
|
|
if (time_before(hc->timeout_tl.expires, jiffies + 5 * HZ) || !hc->timeout_on) {
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->timeout_on = 1;
|
2014-05-21 14:08:48 -06:00
|
|
|
mod_timer(&hc->timeout_tl, jiffies + L1OIP_TIMEOUT * HZ);
|
2008-07-26 18:02:10 -06:00
|
|
|
} else /* only adjust timer */
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->timeout_tl.expires = jiffies + L1OIP_TIMEOUT * HZ;
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
/* if ip or source port changes */
|
|
|
|
if ((hc->sin_remote.sin_addr.s_addr != sin->sin_addr.s_addr)
|
2012-02-19 20:52:38 -07:00
|
|
|
|| (hc->sin_remote.sin_port != sin->sin_port)) {
|
2008-07-26 18:02:10 -06:00
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: remote address changes from "
|
2012-02-19 20:52:38 -07:00
|
|
|
"0x%08x to 0x%08x (port %d to %d)\n", __func__,
|
|
|
|
ntohl(hc->sin_remote.sin_addr.s_addr),
|
|
|
|
ntohl(sin->sin_addr.s_addr),
|
|
|
|
ntohs(hc->sin_remote.sin_port),
|
|
|
|
ntohs(sin->sin_port));
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->sin_remote.sin_addr.s_addr = sin->sin_addr.s_addr;
|
|
|
|
hc->sin_remote.sin_port = sin->sin_port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* socket stuff
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
l1oip_socket_thread(void *data)
|
|
|
|
{
|
|
|
|
struct l1oip *hc = (struct l1oip *)data;
|
|
|
|
int ret = 0;
|
|
|
|
struct sockaddr_in sin_rx;
|
2017-09-20 18:11:00 -06:00
|
|
|
struct kvec iov;
|
|
|
|
struct msghdr msg = {.msg_name = &sin_rx,
|
|
|
|
.msg_namelen = sizeof(sin_rx)};
|
2009-05-22 05:04:51 -06:00
|
|
|
unsigned char *recvbuf;
|
|
|
|
size_t recvbuf_size = 1500;
|
2008-07-26 18:02:10 -06:00
|
|
|
int recvlen;
|
|
|
|
struct socket *socket = NULL;
|
2009-12-18 21:30:11 -07:00
|
|
|
DECLARE_COMPLETION_ONSTACK(wait);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
2009-05-22 05:04:51 -06:00
|
|
|
/* allocate buffer memory */
|
|
|
|
recvbuf = kmalloc(recvbuf_size, GFP_KERNEL);
|
|
|
|
if (!recvbuf) {
|
|
|
|
printk(KERN_ERR "%s: Failed to alloc recvbuf.\n", __func__);
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2017-09-20 18:11:00 -06:00
|
|
|
iov.iov_base = recvbuf;
|
|
|
|
iov.iov_len = recvbuf_size;
|
|
|
|
|
2008-07-26 18:02:10 -06:00
|
|
|
/* make daemon */
|
|
|
|
allow_signal(SIGTERM);
|
|
|
|
|
|
|
|
/* create socket */
|
|
|
|
if (sock_create(PF_INET, SOCK_DGRAM, IPPROTO_UDP, &socket)) {
|
|
|
|
printk(KERN_ERR "%s: Failed to create socket.\n", __func__);
|
2009-05-22 05:04:51 -06:00
|
|
|
ret = -EIO;
|
|
|
|
goto fail;
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set incoming address */
|
|
|
|
hc->sin_local.sin_family = AF_INET;
|
|
|
|
hc->sin_local.sin_addr.s_addr = INADDR_ANY;
|
|
|
|
hc->sin_local.sin_port = htons((unsigned short)hc->localport);
|
|
|
|
|
|
|
|
/* set outgoing address */
|
|
|
|
hc->sin_remote.sin_family = AF_INET;
|
|
|
|
hc->sin_remote.sin_addr.s_addr = htonl(hc->remoteip);
|
|
|
|
hc->sin_remote.sin_port = htons((unsigned short)hc->remoteport);
|
|
|
|
|
2012-12-27 09:33:02 -07:00
|
|
|
/* bind to incoming port */
|
2008-07-26 18:02:10 -06:00
|
|
|
if (socket->ops->bind(socket, (struct sockaddr *)&hc->sin_local,
|
2012-02-19 20:52:38 -07:00
|
|
|
sizeof(hc->sin_local))) {
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_ERR "%s: Failed to bind socket to port %d.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, hc->localport);
|
2008-07-26 18:02:10 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check sk */
|
|
|
|
if (socket->sk == NULL) {
|
|
|
|
printk(KERN_ERR "%s: socket->sk == NULL\n", __func__);
|
|
|
|
ret = -EIO;
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* build send message */
|
|
|
|
hc->sendmsg.msg_name = &hc->sin_remote;
|
|
|
|
hc->sendmsg.msg_namelen = sizeof(hc->sin_remote);
|
|
|
|
hc->sendmsg.msg_control = NULL;
|
|
|
|
hc->sendmsg.msg_controllen = 0;
|
|
|
|
|
|
|
|
/* give away socket */
|
|
|
|
spin_lock(&hc->socket_lock);
|
|
|
|
hc->socket = socket;
|
|
|
|
spin_unlock(&hc->socket_lock);
|
|
|
|
|
|
|
|
/* read loop */
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: socket created and open\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
while (!signal_pending(current)) {
|
2017-09-20 18:11:00 -06:00
|
|
|
iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1,
|
|
|
|
recvbuf_size);
|
|
|
|
recvlen = sock_recvmsg(socket, &msg, 0);
|
2008-07-26 18:02:10 -06:00
|
|
|
if (recvlen > 0) {
|
|
|
|
l1oip_socket_parse(hc, &sin_rx, recvbuf, recvlen);
|
|
|
|
} else {
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
2009-05-22 05:04:56 -06:00
|
|
|
printk(KERN_WARNING
|
2012-02-19 20:52:38 -07:00
|
|
|
"%s: broken pipe on socket\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get socket back, check first if in use, maybe by send function */
|
|
|
|
spin_lock(&hc->socket_lock);
|
|
|
|
/* if hc->socket is NULL, it is in use until it is given back */
|
|
|
|
while (!hc->socket) {
|
|
|
|
spin_unlock(&hc->socket_lock);
|
2012-02-19 20:52:38 -07:00
|
|
|
schedule_timeout(HZ / 10);
|
2008-07-26 18:02:10 -06:00
|
|
|
spin_lock(&hc->socket_lock);
|
|
|
|
}
|
|
|
|
hc->socket = NULL;
|
|
|
|
spin_unlock(&hc->socket_lock);
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: socket thread terminating\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
fail:
|
2009-05-22 05:04:51 -06:00
|
|
|
/* free recvbuf */
|
|
|
|
kfree(recvbuf);
|
|
|
|
|
2008-07-26 18:02:10 -06:00
|
|
|
/* close socket */
|
|
|
|
if (socket)
|
|
|
|
sock_release(socket);
|
|
|
|
|
|
|
|
/* if we got killed, signal completion */
|
|
|
|
complete(&hc->socket_complete);
|
|
|
|
hc->socket_thread = NULL; /* show termination of thread */
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: socket thread terminated\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
l1oip_socket_close(struct l1oip *hc)
|
|
|
|
{
|
2008-09-14 04:30:18 -06:00
|
|
|
struct dchannel *dch = hc->chan[hc->d_idx].dch;
|
|
|
|
|
2008-07-26 18:02:10 -06:00
|
|
|
/* kill thread */
|
|
|
|
if (hc->socket_thread) {
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: socket thread exists, "
|
2012-02-19 20:52:38 -07:00
|
|
|
"killing...\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
send_sig(SIGTERM, hc->socket_thread, 0);
|
|
|
|
wait_for_completion(&hc->socket_complete);
|
|
|
|
}
|
2008-09-14 04:30:18 -06:00
|
|
|
|
|
|
|
/* if active, we send up a PH_DEACTIVATE and deactivate */
|
|
|
|
if (test_bit(FLG_ACTIVE, &dch->Flags)) {
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-09-14 04:30:18 -06:00
|
|
|
printk(KERN_DEBUG "%s: interface become deactivated "
|
2012-02-19 20:52:38 -07:00
|
|
|
"due to timeout\n", __func__);
|
2008-09-14 04:30:18 -06:00
|
|
|
test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
|
|
|
|
_queue_data(&dch->dev.D, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
|
2012-02-19 20:52:38 -07:00
|
|
|
NULL, GFP_ATOMIC);
|
2008-09-14 04:30:18 -06:00
|
|
|
}
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
l1oip_socket_open(struct l1oip *hc)
|
|
|
|
{
|
|
|
|
/* in case of reopen, we need to close first */
|
|
|
|
l1oip_socket_close(hc);
|
|
|
|
|
|
|
|
init_completion(&hc->socket_complete);
|
|
|
|
|
|
|
|
/* create receive process */
|
|
|
|
hc->socket_thread = kthread_run(l1oip_socket_thread, hc, "l1oip_%s",
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->name);
|
2008-07-26 18:02:10 -06:00
|
|
|
if (IS_ERR(hc->socket_thread)) {
|
|
|
|
int err = PTR_ERR(hc->socket_thread);
|
|
|
|
printk(KERN_ERR "%s: Failed (%d) to create socket process.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, err);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->socket_thread = NULL;
|
|
|
|
sock_release(hc->socket);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: socket thread created\n", __func__);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
l1oip_send_bh(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct l1oip *hc = container_of(work, struct l1oip, workq);
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: keepalive timer expired, sending empty "
|
2012-02-19 20:52:38 -07:00
|
|
|
"frame on dchannel\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
/* send an empty l1oip frame at D-channel */
|
|
|
|
l1oip_socket_send(hc, 0, hc->d_idx, 0, 0, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* timer stuff
|
|
|
|
*/
|
|
|
|
static void
|
2017-10-16 18:29:14 -06:00
|
|
|
l1oip_keepalive(struct timer_list *t)
|
2008-07-26 18:02:10 -06:00
|
|
|
{
|
2017-10-16 18:29:14 -06:00
|
|
|
struct l1oip *hc = from_timer(hc, t, keep_tl);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
schedule_work(&hc->workq);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-16 18:29:14 -06:00
|
|
|
l1oip_timeout(struct timer_list *t)
|
2008-07-26 18:02:10 -06:00
|
|
|
{
|
2017-10-16 18:29:14 -06:00
|
|
|
struct l1oip *hc = from_timer(hc, t,
|
|
|
|
timeout_tl);
|
2008-07-26 18:02:10 -06:00
|
|
|
struct dchannel *dch = hc->chan[hc->d_idx].dch;
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: timeout timer expired, turn layer one "
|
2012-02-19 20:52:38 -07:00
|
|
|
"down.\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
hc->timeout_on = 0; /* state that timer must be initialized next time */
|
|
|
|
|
|
|
|
/* if timeout, we send up a PH_DEACTIVATE and deactivate */
|
|
|
|
if (test_bit(FLG_ACTIVE, &dch->Flags)) {
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: interface become deactivated "
|
2012-02-19 20:52:38 -07:00
|
|
|
"due to timeout\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
test_and_clear_bit(FLG_ACTIVE, &dch->Flags);
|
|
|
|
_queue_data(&dch->dev.D, PH_DEACTIVATE_IND, MISDN_ID_ANY, 0,
|
2012-02-19 20:52:38 -07:00
|
|
|
NULL, GFP_ATOMIC);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* if we have ondemand set, we remove ip address */
|
|
|
|
if (hc->ondemand) {
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: on demand causes ip address to "
|
2012-02-19 20:52:38 -07:00
|
|
|
"be removed\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->sin_remote.sin_addr.s_addr = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* message handling
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
handle_dmsg(struct mISDNchannel *ch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
|
|
|
|
struct dchannel *dch = container_of(dev, struct dchannel, dev);
|
|
|
|
struct l1oip *hc = dch->hw;
|
|
|
|
struct mISDNhead *hh = mISDN_HEAD_P(skb);
|
|
|
|
int ret = -EINVAL;
|
|
|
|
int l, ll;
|
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
switch (hh->prim) {
|
|
|
|
case PH_DATA_REQ:
|
|
|
|
if (skb->len < 1) {
|
|
|
|
printk(KERN_WARNING "%s: skb too small\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (skb->len > MAX_DFRAME_LEN_L1 || skb->len > L1OIP_MAX_LEN) {
|
|
|
|
printk(KERN_WARNING "%s: skb too large\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* send frame */
|
|
|
|
p = skb->data;
|
|
|
|
l = skb->len;
|
|
|
|
while (l) {
|
2009-05-22 05:04:56 -06:00
|
|
|
ll = (l < L1OIP_MAX_PERFRAME) ? l : L1OIP_MAX_PERFRAME;
|
2008-07-26 18:02:10 -06:00
|
|
|
l1oip_socket_send(hc, 0, dch->slot, 0,
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->chan[dch->slot].tx_counter++, p, ll);
|
2008-07-26 18:02:10 -06:00
|
|
|
p += ll;
|
|
|
|
l -= ll;
|
|
|
|
}
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
case PH_ACTIVATE_REQ:
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: PH_ACTIVATE channel %d (1..%d)\n"
|
2012-02-19 20:52:38 -07:00
|
|
|
, __func__, dch->slot, hc->b_num + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
skb_trim(skb, 0);
|
|
|
|
if (test_bit(FLG_ACTIVE, &dch->Flags))
|
|
|
|
queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
|
|
|
|
else
|
|
|
|
queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
case PH_DEACTIVATE_REQ:
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: PH_DEACTIVATE channel %d "
|
2012-02-19 20:52:38 -07:00
|
|
|
"(1..%d)\n", __func__, dch->slot,
|
|
|
|
hc->b_num + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
skb_trim(skb, 0);
|
|
|
|
if (test_bit(FLG_ACTIVE, &dch->Flags))
|
|
|
|
queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
|
|
|
|
else
|
|
|
|
queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
channel_dctrl(struct dchannel *dch, struct mISDN_ctrl_req *cq)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct l1oip *hc = dch->hw;
|
|
|
|
|
|
|
|
switch (cq->op) {
|
|
|
|
case MISDN_CTRL_GETOP:
|
2008-09-14 04:30:18 -06:00
|
|
|
cq->op = MISDN_CTRL_SETPEER | MISDN_CTRL_UNSETPEER
|
|
|
|
| MISDN_CTRL_GETPEER;
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
case MISDN_CTRL_SETPEER:
|
|
|
|
hc->remoteip = (u32)cq->p1;
|
|
|
|
hc->remoteport = cq->p2 & 0xffff;
|
|
|
|
hc->localport = cq->p2 >> 16;
|
|
|
|
if (!hc->remoteport)
|
|
|
|
hc->remoteport = hc->localport;
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: got new ip address from user "
|
2012-02-19 20:52:38 -07:00
|
|
|
"space.\n", __func__);
|
2010-08-05 04:29:19 -06:00
|
|
|
l1oip_socket_open(hc);
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
case MISDN_CTRL_UNSETPEER:
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: removing ip address.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->remoteip = 0;
|
|
|
|
l1oip_socket_open(hc);
|
|
|
|
break;
|
2008-09-14 04:30:18 -06:00
|
|
|
case MISDN_CTRL_GETPEER:
|
|
|
|
if (debug & DEBUG_L1OIP_SOCKET)
|
|
|
|
printk(KERN_DEBUG "%s: getting ip address.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-09-20 05:43:28 -06:00
|
|
|
cq->p1 = hc->remoteip;
|
2008-09-14 04:30:18 -06:00
|
|
|
cq->p2 = hc->remoteport | (hc->localport << 16);
|
|
|
|
break;
|
2008-07-26 18:02:10 -06:00
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "%s: unknown Op %x\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cq->op);
|
2008-07-26 18:02:10 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
open_dchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
|
|
|
|
{
|
|
|
|
if (debug & DEBUG_HW_OPEN)
|
|
|
|
printk(KERN_DEBUG "%s: dev(%d) open from %p\n", __func__,
|
2012-02-19 20:52:38 -07:00
|
|
|
dch->dev.id, __builtin_return_address(0));
|
2008-07-26 18:02:10 -06:00
|
|
|
if (rq->protocol == ISDN_P_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
if ((dch->dev.D.protocol != ISDN_P_NONE) &&
|
|
|
|
(dch->dev.D.protocol != rq->protocol)) {
|
|
|
|
if (debug & DEBUG_HW_OPEN)
|
|
|
|
printk(KERN_WARNING "%s: change protocol %x to %x\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, dch->dev.D.protocol, rq->protocol);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
if (dch->dev.D.protocol != rq->protocol)
|
|
|
|
dch->dev.D.protocol = rq->protocol;
|
|
|
|
|
|
|
|
if (test_bit(FLG_ACTIVE, &dch->Flags)) {
|
|
|
|
_queue_data(&dch->dev.D, PH_ACTIVATE_IND, MISDN_ID_ANY,
|
2012-02-19 20:52:38 -07:00
|
|
|
0, NULL, GFP_KERNEL);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
rq->ch = &dch->dev.D;
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
|
|
printk(KERN_WARNING "%s:cannot get module\n", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
open_bchannel(struct l1oip *hc, struct dchannel *dch, struct channel_req *rq)
|
|
|
|
{
|
|
|
|
struct bchannel *bch;
|
|
|
|
int ch;
|
|
|
|
|
2008-07-30 10:26:58 -06:00
|
|
|
if (!test_channelmap(rq->adr.channel, dch->dev.channelmap))
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
if (rq->protocol == ISDN_P_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
ch = rq->adr.channel; /* BRI: 1=B1 2=B2 PRI: 1..15,17.. */
|
|
|
|
bch = hc->chan[ch].bch;
|
|
|
|
if (!bch) {
|
|
|
|
printk(KERN_ERR "%s:internal error ch %d has no bch\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, ch);
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (test_and_set_bit(FLG_OPEN, &bch->Flags))
|
|
|
|
return -EBUSY; /* b-channel can be only open once */
|
|
|
|
bch->ch.protocol = rq->protocol;
|
|
|
|
rq->ch = &bch->ch;
|
|
|
|
if (!try_module_get(THIS_MODULE))
|
|
|
|
printk(KERN_WARNING "%s:cannot get module\n", __func__);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
l1oip_dctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct mISDNdevice *dev = container_of(ch, struct mISDNdevice, D);
|
|
|
|
struct dchannel *dch = container_of(dev, struct dchannel, dev);
|
|
|
|
struct l1oip *hc = dch->hw;
|
|
|
|
struct channel_req *rq;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (dch->debug & DEBUG_HW)
|
|
|
|
printk(KERN_DEBUG "%s: cmd:%x %p\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cmd, arg);
|
2008-07-26 18:02:10 -06:00
|
|
|
switch (cmd) {
|
|
|
|
case OPEN_CHANNEL:
|
|
|
|
rq = arg;
|
|
|
|
switch (rq->protocol) {
|
|
|
|
case ISDN_P_TE_S0:
|
|
|
|
case ISDN_P_NT_S0:
|
|
|
|
if (hc->pri) {
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = open_dchannel(hc, dch, rq);
|
|
|
|
break;
|
|
|
|
case ISDN_P_TE_E1:
|
|
|
|
case ISDN_P_NT_E1:
|
|
|
|
if (!hc->pri) {
|
|
|
|
err = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
err = open_dchannel(hc, dch, rq);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = open_bchannel(hc, dch, rq);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CLOSE_CHANNEL:
|
|
|
|
if (debug & DEBUG_HW_OPEN)
|
|
|
|
printk(KERN_DEBUG "%s: dev(%d) close from %p\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, dch->dev.id,
|
|
|
|
__builtin_return_address(0));
|
2008-07-26 18:02:10 -06:00
|
|
|
module_put(THIS_MODULE);
|
|
|
|
break;
|
|
|
|
case CONTROL_CHANNEL:
|
|
|
|
err = channel_dctrl(dch, arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (dch->debug & DEBUG_HW)
|
|
|
|
printk(KERN_DEBUG "%s: unknown command %x\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cmd);
|
2008-07-26 18:02:10 -06:00
|
|
|
err = -EINVAL;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
handle_bmsg(struct mISDNchannel *ch, struct sk_buff *skb)
|
|
|
|
{
|
|
|
|
struct bchannel *bch = container_of(ch, struct bchannel, ch);
|
|
|
|
struct l1oip *hc = bch->hw;
|
|
|
|
int ret = -EINVAL;
|
|
|
|
struct mISDNhead *hh = mISDN_HEAD_P(skb);
|
2012-01-26 21:24:55 -07:00
|
|
|
int l, ll;
|
2008-07-26 18:02:10 -06:00
|
|
|
unsigned char *p;
|
|
|
|
|
|
|
|
switch (hh->prim) {
|
|
|
|
case PH_DATA_REQ:
|
|
|
|
if (skb->len <= 0) {
|
|
|
|
printk(KERN_WARNING "%s: skb too small\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (skb->len > MAX_DFRAME_LEN_L1 || skb->len > L1OIP_MAX_LEN) {
|
|
|
|
printk(KERN_WARNING "%s: skb too large\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* check for AIS / ulaw-silence */
|
|
|
|
l = skb->len;
|
2012-01-26 21:24:55 -07:00
|
|
|
if (!memchr_inv(skb->data, 0xff, l)) {
|
2008-07-26 18:02:10 -06:00
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: got AIS, not sending, "
|
2012-02-19 20:52:38 -07:00
|
|
|
"but counting\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->chan[bch->slot].tx_counter += l;
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/* check for silence */
|
|
|
|
l = skb->len;
|
2012-01-26 21:24:55 -07:00
|
|
|
if (!memchr_inv(skb->data, 0x2a, l)) {
|
2008-07-26 18:02:10 -06:00
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: got silence, not sending"
|
2012-02-19 20:52:38 -07:00
|
|
|
", but counting\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->chan[bch->slot].tx_counter += l;
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* send frame */
|
|
|
|
p = skb->data;
|
|
|
|
l = skb->len;
|
|
|
|
while (l) {
|
2009-05-22 05:04:56 -06:00
|
|
|
ll = (l < L1OIP_MAX_PERFRAME) ? l : L1OIP_MAX_PERFRAME;
|
2008-07-26 18:02:10 -06:00
|
|
|
l1oip_socket_send(hc, hc->codec, bch->slot, 0,
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->chan[bch->slot].tx_counter, p, ll);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->chan[bch->slot].tx_counter += ll;
|
|
|
|
p += ll;
|
|
|
|
l -= ll;
|
|
|
|
}
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_DATA_CNF, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
case PH_ACTIVATE_REQ:
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: PH_ACTIVATE channel %d (1..%d)\n"
|
2012-02-19 20:52:38 -07:00
|
|
|
, __func__, bch->slot, hc->b_num + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->chan[bch->slot].codecstate = 0;
|
|
|
|
test_and_set_bit(FLG_ACTIVE, &bch->Flags);
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_ACTIVATE_IND, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
case PH_DEACTIVATE_REQ:
|
2012-02-19 20:52:38 -07:00
|
|
|
if (debug & (DEBUG_L1OIP_MSG | DEBUG_L1OIP_SOCKET))
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_DEBUG "%s: PH_DEACTIVATE channel %d "
|
2012-02-19 20:52:38 -07:00
|
|
|
"(1..%d)\n", __func__, bch->slot,
|
|
|
|
hc->b_num + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
|
|
|
|
skb_trim(skb, 0);
|
|
|
|
queue_ch_frame(ch, PH_DEACTIVATE_IND, hh->id, skb);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!ret)
|
|
|
|
dev_kfree_skb(skb);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
channel_bctrl(struct bchannel *bch, struct mISDN_ctrl_req *cq)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
struct dsp_features *features =
|
|
|
|
(struct dsp_features *)(*((u_long *)&cq->p1));
|
|
|
|
|
|
|
|
switch (cq->op) {
|
|
|
|
case MISDN_CTRL_GETOP:
|
|
|
|
cq->op = MISDN_CTRL_HW_FEATURES_OP;
|
|
|
|
break;
|
|
|
|
case MISDN_CTRL_HW_FEATURES: /* fill features structure */
|
|
|
|
if (debug & DEBUG_L1OIP_MSG)
|
|
|
|
printk(KERN_DEBUG "%s: HW_FEATURE request\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
/* create confirm */
|
|
|
|
features->unclocked = 1;
|
|
|
|
features->unordered = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "%s: unknown Op %x\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cq->op);
|
2008-07-26 18:02:10 -06:00
|
|
|
ret = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
l1oip_bctrl(struct mISDNchannel *ch, u_int cmd, void *arg)
|
|
|
|
{
|
|
|
|
struct bchannel *bch = container_of(ch, struct bchannel, ch);
|
|
|
|
int err = -EINVAL;
|
|
|
|
|
|
|
|
if (bch->debug & DEBUG_HW)
|
|
|
|
printk(KERN_DEBUG "%s: cmd:%x %p\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cmd, arg);
|
2008-07-26 18:02:10 -06:00
|
|
|
switch (cmd) {
|
|
|
|
case CLOSE_CHANNEL:
|
|
|
|
test_and_clear_bit(FLG_OPEN, &bch->Flags);
|
|
|
|
test_and_clear_bit(FLG_ACTIVE, &bch->Flags);
|
|
|
|
ch->protocol = ISDN_P_NONE;
|
|
|
|
ch->peer = NULL;
|
|
|
|
module_put(THIS_MODULE);
|
|
|
|
err = 0;
|
|
|
|
break;
|
|
|
|
case CONTROL_CHANNEL:
|
|
|
|
err = channel_bctrl(bch, arg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_WARNING "%s: unknown prim(%x)\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, cmd);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cleanup module and stack
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
release_card(struct l1oip *hc)
|
|
|
|
{
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
if (timer_pending(&hc->keep_tl))
|
|
|
|
del_timer(&hc->keep_tl);
|
|
|
|
|
|
|
|
if (timer_pending(&hc->timeout_tl))
|
|
|
|
del_timer(&hc->timeout_tl);
|
|
|
|
|
2010-12-24 07:59:07 -07:00
|
|
|
cancel_work_sync(&hc->workq);
|
|
|
|
|
2008-07-26 18:02:10 -06:00
|
|
|
if (hc->socket_thread)
|
|
|
|
l1oip_socket_close(hc);
|
|
|
|
|
|
|
|
if (hc->registered && hc->chan[hc->d_idx].dch)
|
|
|
|
mISDN_unregister_device(&hc->chan[hc->d_idx].dch->dev);
|
|
|
|
for (ch = 0; ch < 128; ch++) {
|
|
|
|
if (hc->chan[ch].dch) {
|
|
|
|
mISDN_freedchannel(hc->chan[ch].dch);
|
|
|
|
kfree(hc->chan[ch].dch);
|
|
|
|
}
|
|
|
|
if (hc->chan[ch].bch) {
|
|
|
|
mISDN_freebchannel(hc->chan[ch].bch);
|
|
|
|
kfree(hc->chan[ch].bch);
|
|
|
|
#ifdef REORDER_DEBUG
|
|
|
|
if (hc->chan[ch].disorder_skb)
|
|
|
|
dev_kfree_skb(hc->chan[ch].disorder_skb);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock(&l1oip_lock);
|
|
|
|
list_del(&hc->list);
|
|
|
|
spin_unlock(&l1oip_lock);
|
|
|
|
|
|
|
|
kfree(hc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
l1oip_cleanup(void)
|
|
|
|
{
|
|
|
|
struct l1oip *hc, *next;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(hc, next, &l1oip_ilist, list)
|
|
|
|
release_card(hc);
|
|
|
|
|
|
|
|
l1oip_4bit_free();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* module and stack init
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
init_card(struct l1oip *hc, int pri, int bundle)
|
|
|
|
{
|
|
|
|
struct dchannel *dch;
|
|
|
|
struct bchannel *bch;
|
|
|
|
int ret;
|
|
|
|
int i, ch;
|
|
|
|
|
|
|
|
spin_lock_init(&hc->socket_lock);
|
|
|
|
hc->idx = l1oip_cnt;
|
|
|
|
hc->pri = pri;
|
2009-05-22 05:04:56 -06:00
|
|
|
hc->d_idx = pri ? 16 : 3;
|
|
|
|
hc->b_num = pri ? 30 : 2;
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->bundle = bundle;
|
|
|
|
if (hc->pri)
|
|
|
|
sprintf(hc->name, "l1oip-e1.%d", l1oip_cnt + 1);
|
|
|
|
else
|
|
|
|
sprintf(hc->name, "l1oip-s0.%d", l1oip_cnt + 1);
|
|
|
|
|
|
|
|
switch (codec[l1oip_cnt]) {
|
|
|
|
case 0: /* as is */
|
|
|
|
case 1: /* alaw */
|
|
|
|
case 2: /* ulaw */
|
|
|
|
case 3: /* 4bit */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Codec(%d) not supported.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
codec[l1oip_cnt]);
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
hc->codec = codec[l1oip_cnt];
|
|
|
|
if (debug & DEBUG_L1OIP_INIT)
|
|
|
|
printk(KERN_DEBUG "%s: using codec %d\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, hc->codec);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
if (id[l1oip_cnt] == 0) {
|
|
|
|
printk(KERN_WARNING "Warning: No 'id' value given or "
|
2012-02-19 20:52:38 -07:00
|
|
|
"0, this is highly unsecure. Please use 32 "
|
2014-11-05 06:26:48 -07:00
|
|
|
"bit random number 0x...\n");
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
hc->id = id[l1oip_cnt];
|
|
|
|
if (debug & DEBUG_L1OIP_INIT)
|
|
|
|
printk(KERN_DEBUG "%s: using id 0x%x\n", __func__, hc->id);
|
|
|
|
|
|
|
|
hc->ondemand = ondemand[l1oip_cnt];
|
|
|
|
if (hc->ondemand && !hc->id) {
|
|
|
|
printk(KERN_ERR "%s: ondemand option only allowed in "
|
2012-02-19 20:52:38 -07:00
|
|
|
"conjunction with non 0 ID\n", __func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (limit[l1oip_cnt])
|
|
|
|
hc->b_num = limit[l1oip_cnt];
|
|
|
|
if (!pri && hc->b_num > 2) {
|
|
|
|
printk(KERN_ERR "Maximum limit for BRI interface is 2 "
|
2012-02-19 20:52:38 -07:00
|
|
|
"channels.\n");
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (pri && hc->b_num > 126) {
|
|
|
|
printk(KERN_ERR "Maximum limit for PRI interface is 126 "
|
2012-02-19 20:52:38 -07:00
|
|
|
"channels.\n");
|
2008-07-26 18:02:10 -06:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
if (pri && hc->b_num > 30) {
|
|
|
|
printk(KERN_WARNING "Maximum limit for BRI interface is 30 "
|
2012-02-19 20:52:38 -07:00
|
|
|
"channels.\n");
|
2008-07-26 18:02:10 -06:00
|
|
|
printk(KERN_WARNING "Your selection of %d channels must be "
|
2012-02-19 20:52:38 -07:00
|
|
|
"supported by application.\n", hc->limit);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
|
|
|
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->remoteip = ip[l1oip_cnt << 2] << 24
|
|
|
|
| ip[(l1oip_cnt << 2) + 1] << 16
|
|
|
|
| ip[(l1oip_cnt << 2) + 2] << 8
|
|
|
|
| ip[(l1oip_cnt << 2) + 3];
|
|
|
|
hc->localport = port[l1oip_cnt]?:(L1OIP_DEFAULTPORT + l1oip_cnt);
|
2008-07-26 18:02:10 -06:00
|
|
|
if (remoteport[l1oip_cnt])
|
|
|
|
hc->remoteport = remoteport[l1oip_cnt];
|
|
|
|
else
|
|
|
|
hc->remoteport = hc->localport;
|
|
|
|
if (debug & DEBUG_L1OIP_INIT)
|
|
|
|
printk(KERN_DEBUG "%s: using local port %d remote ip "
|
2012-02-19 20:52:38 -07:00
|
|
|
"%d.%d.%d.%d port %d ondemand %d\n", __func__,
|
|
|
|
hc->localport, hc->remoteip >> 24,
|
|
|
|
(hc->remoteip >> 16) & 0xff,
|
|
|
|
(hc->remoteip >> 8) & 0xff, hc->remoteip & 0xff,
|
|
|
|
hc->remoteport, hc->ondemand);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
dch = kzalloc(sizeof(struct dchannel), GFP_KERNEL);
|
|
|
|
if (!dch)
|
|
|
|
return -ENOMEM;
|
|
|
|
dch->debug = debug;
|
|
|
|
mISDN_initdchannel(dch, MAX_DFRAME_LEN_L1, NULL);
|
|
|
|
dch->hw = hc;
|
|
|
|
if (pri)
|
|
|
|
dch->dev.Dprotocols = (1 << ISDN_P_TE_E1) | (1 << ISDN_P_NT_E1);
|
|
|
|
else
|
|
|
|
dch->dev.Dprotocols = (1 << ISDN_P_TE_S0) | (1 << ISDN_P_NT_S0);
|
|
|
|
dch->dev.Bprotocols = (1 << (ISDN_P_B_RAW & ISDN_P_B_MASK)) |
|
2012-02-19 20:52:38 -07:00
|
|
|
(1 << (ISDN_P_B_HDLC & ISDN_P_B_MASK));
|
2008-07-26 18:02:10 -06:00
|
|
|
dch->dev.D.send = handle_dmsg;
|
|
|
|
dch->dev.D.ctrl = l1oip_dctrl;
|
|
|
|
dch->dev.nrbchan = hc->b_num;
|
|
|
|
dch->slot = hc->d_idx;
|
|
|
|
hc->chan[hc->d_idx].dch = dch;
|
|
|
|
i = 1;
|
|
|
|
for (ch = 0; ch < dch->dev.nrbchan; ch++) {
|
|
|
|
if (ch == 15)
|
|
|
|
i++;
|
|
|
|
bch = kzalloc(sizeof(struct bchannel), GFP_KERNEL);
|
|
|
|
if (!bch) {
|
|
|
|
printk(KERN_ERR "%s: no memory for bchannel\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__);
|
2008-07-26 18:02:10 -06:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
bch->nr = i + ch;
|
|
|
|
bch->slot = i + ch;
|
|
|
|
bch->debug = debug;
|
2012-05-15 17:51:06 -06:00
|
|
|
mISDN_initbchannel(bch, MAX_DATA_MEM, 0);
|
2008-07-26 18:02:10 -06:00
|
|
|
bch->hw = hc;
|
|
|
|
bch->ch.send = handle_bmsg;
|
|
|
|
bch->ch.ctrl = l1oip_bctrl;
|
|
|
|
bch->ch.nr = i + ch;
|
|
|
|
list_add(&bch->ch.list, &dch->dev.bchannels);
|
|
|
|
hc->chan[i + ch].bch = bch;
|
2008-07-30 10:26:58 -06:00
|
|
|
set_channelmap(bch->nr, dch->dev.channelmap);
|
2008-07-26 18:02:10 -06:00
|
|
|
}
|
2008-08-15 16:09:24 -06:00
|
|
|
/* TODO: create a parent device for this driver */
|
|
|
|
ret = mISDN_register_device(&dch->dev, NULL, hc->name);
|
2008-07-26 18:02:10 -06:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
hc->registered = 1;
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_INIT)
|
|
|
|
printk(KERN_DEBUG "%s: Setting up network card(%d)\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, l1oip_cnt + 1);
|
2008-07-26 18:02:10 -06:00
|
|
|
ret = l1oip_socket_open(hc);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-10-16 18:29:14 -06:00
|
|
|
timer_setup(&hc->keep_tl, l1oip_keepalive, 0);
|
2012-02-19 20:52:38 -07:00
|
|
|
hc->keep_tl.expires = jiffies + 2 * HZ; /* two seconds first time */
|
2008-07-26 18:02:10 -06:00
|
|
|
add_timer(&hc->keep_tl);
|
|
|
|
|
2017-10-16 18:29:14 -06:00
|
|
|
timer_setup(&hc->timeout_tl, l1oip_timeout, 0);
|
2008-07-26 18:02:10 -06:00
|
|
|
hc->timeout_on = 0; /* state that we have timer off */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init
|
|
|
|
l1oip_init(void)
|
|
|
|
{
|
|
|
|
int pri, bundle;
|
|
|
|
struct l1oip *hc;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
printk(KERN_INFO "mISDN: Layer-1-over-IP driver Rev. %s\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
l1oip_revision);
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
INIT_LIST_HEAD(&l1oip_ilist);
|
|
|
|
spin_lock_init(&l1oip_lock);
|
|
|
|
|
|
|
|
if (l1oip_4bit_alloc(ulaw))
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
l1oip_cnt = 0;
|
2009-07-30 21:43:59 -06:00
|
|
|
while (l1oip_cnt < MAX_CARDS && type[l1oip_cnt]) {
|
2008-07-26 18:02:10 -06:00
|
|
|
switch (type[l1oip_cnt] & 0xff) {
|
|
|
|
case 1:
|
|
|
|
pri = 0;
|
|
|
|
bundle = 0;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
pri = 1;
|
|
|
|
bundle = 0;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
pri = 0;
|
|
|
|
bundle = 1;
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
pri = 1;
|
|
|
|
bundle = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "Card type(%d) not supported.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
type[l1oip_cnt] & 0xff);
|
2008-07-26 18:02:10 -06:00
|
|
|
l1oip_cleanup();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (debug & DEBUG_L1OIP_INIT)
|
|
|
|
printk(KERN_DEBUG "%s: interface %d is %s with %s.\n",
|
2012-02-19 20:52:38 -07:00
|
|
|
__func__, l1oip_cnt, pri ? "PRI" : "BRI",
|
|
|
|
bundle ? "bundled IP packet for all B-channels" :
|
|
|
|
"separate IP packets for every B-channel");
|
2008-07-26 18:02:10 -06:00
|
|
|
|
|
|
|
hc = kzalloc(sizeof(struct l1oip), GFP_ATOMIC);
|
|
|
|
if (!hc) {
|
|
|
|
printk(KERN_ERR "No kmem for L1-over-IP driver.\n");
|
|
|
|
l1oip_cleanup();
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
INIT_WORK(&hc->workq, (void *)l1oip_send_bh);
|
|
|
|
|
|
|
|
spin_lock(&l1oip_lock);
|
|
|
|
list_add_tail(&hc->list, &l1oip_ilist);
|
|
|
|
spin_unlock(&l1oip_lock);
|
|
|
|
|
|
|
|
ret = init_card(hc, pri, bundle);
|
|
|
|
if (ret) {
|
|
|
|
l1oip_cleanup();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
l1oip_cnt++;
|
|
|
|
}
|
|
|
|
printk(KERN_INFO "%d virtual devices registered\n", l1oip_cnt);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(l1oip_init);
|
|
|
|
module_exit(l1oip_cleanup);
|