Skip to content

Commit 1b2b03f

Browse files
author
Karsten Keil
committed
Add mISDN core files
Add mISDN core files Signed-off-by: Karsten Keil <[email protected]>
1 parent 04578dd commit 1b2b03f

File tree

17 files changed

+7515
-0
lines changed

17 files changed

+7515
-0
lines changed

drivers/isdn/mISDN/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# modularer ISDN driver
3+
#
4+
5+
menuconfig MISDN
6+
tristate "Modular ISDN driver"
7+
help
8+
Enable support for the modular ISDN driver.
9+

drivers/isdn/mISDN/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#
2+
# Makefile for the modular ISDN driver
3+
#
4+
5+
obj-$(CONFIG_MISDN) += mISDN_core.o
6+
7+
# multi objects
8+
9+
mISDN_core-objs := core.o fsm.o socket.o hwchannel.o stack.o layer1.o layer2.o tei.o timerdev.o

drivers/isdn/mISDN/core.c

Lines changed: 244 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
/*
2+
* Copyright 2008 by Karsten Keil <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
*/
14+
15+
#include <linux/types.h>
16+
#include <linux/stddef.h>
17+
#include <linux/module.h>
18+
#include <linux/spinlock.h>
19+
#include <linux/mISDNif.h>
20+
#include "core.h"
21+
22+
static u_int debug;
23+
24+
MODULE_AUTHOR("Karsten Keil");
25+
MODULE_LICENSE("GPL");
26+
module_param(debug, uint, S_IRUGO | S_IWUSR);
27+
28+
static LIST_HEAD(devices);
29+
DEFINE_RWLOCK(device_lock);
30+
static u64 device_ids;
31+
#define MAX_DEVICE_ID 63
32+
33+
static LIST_HEAD(Bprotocols);
34+
DEFINE_RWLOCK(bp_lock);
35+
36+
struct mISDNdevice
37+
*get_mdevice(u_int id)
38+
{
39+
struct mISDNdevice *dev;
40+
41+
read_lock(&device_lock);
42+
list_for_each_entry(dev, &devices, D.list)
43+
if (dev->id == id) {
44+
read_unlock(&device_lock);
45+
return dev;
46+
}
47+
read_unlock(&device_lock);
48+
return NULL;
49+
}
50+
51+
int
52+
get_mdevice_count(void)
53+
{
54+
struct mISDNdevice *dev;
55+
int cnt = 0;
56+
57+
read_lock(&device_lock);
58+
list_for_each_entry(dev, &devices, D.list)
59+
cnt++;
60+
read_unlock(&device_lock);
61+
return cnt;
62+
}
63+
64+
static int
65+
get_free_devid(void)
66+
{
67+
u_int i;
68+
69+
for (i = 0; i <= MAX_DEVICE_ID; i++)
70+
if (!test_and_set_bit(i, (u_long *)&device_ids))
71+
return i;
72+
return -1;
73+
}
74+
75+
int
76+
mISDN_register_device(struct mISDNdevice *dev, char *name)
77+
{
78+
u_long flags;
79+
int err;
80+
81+
dev->id = get_free_devid();
82+
if (dev->id < 0)
83+
return -EBUSY;
84+
if (name && name[0])
85+
strcpy(dev->name, name);
86+
else
87+
sprintf(dev->name, "mISDN%d", dev->id);
88+
if (debug & DEBUG_CORE)
89+
printk(KERN_DEBUG "mISDN_register %s %d\n",
90+
dev->name, dev->id);
91+
err = create_stack(dev);
92+
if (err)
93+
return err;
94+
write_lock_irqsave(&device_lock, flags);
95+
list_add_tail(&dev->D.list, &devices);
96+
write_unlock_irqrestore(&device_lock, flags);
97+
return 0;
98+
}
99+
EXPORT_SYMBOL(mISDN_register_device);
100+
101+
void
102+
mISDN_unregister_device(struct mISDNdevice *dev) {
103+
u_long flags;
104+
105+
if (debug & DEBUG_CORE)
106+
printk(KERN_DEBUG "mISDN_unregister %s %d\n",
107+
dev->name, dev->id);
108+
write_lock_irqsave(&device_lock, flags);
109+
list_del(&dev->D.list);
110+
write_unlock_irqrestore(&device_lock, flags);
111+
test_and_clear_bit(dev->id, (u_long *)&device_ids);
112+
delete_stack(dev);
113+
}
114+
EXPORT_SYMBOL(mISDN_unregister_device);
115+
116+
u_int
117+
get_all_Bprotocols(void)
118+
{
119+
struct Bprotocol *bp;
120+
u_int m = 0;
121+
122+
read_lock(&bp_lock);
123+
list_for_each_entry(bp, &Bprotocols, list)
124+
m |= bp->Bprotocols;
125+
read_unlock(&bp_lock);
126+
return m;
127+
}
128+
129+
struct Bprotocol *
130+
get_Bprotocol4mask(u_int m)
131+
{
132+
struct Bprotocol *bp;
133+
134+
read_lock(&bp_lock);
135+
list_for_each_entry(bp, &Bprotocols, list)
136+
if (bp->Bprotocols & m) {
137+
read_unlock(&bp_lock);
138+
return bp;
139+
}
140+
read_unlock(&bp_lock);
141+
return NULL;
142+
}
143+
144+
struct Bprotocol *
145+
get_Bprotocol4id(u_int id)
146+
{
147+
u_int m;
148+
149+
if (id < ISDN_P_B_START || id > 63) {
150+
printk(KERN_WARNING "%s id not in range %d\n",
151+
__func__, id);
152+
return NULL;
153+
}
154+
m = 1 << (id & ISDN_P_B_MASK);
155+
return get_Bprotocol4mask(m);
156+
}
157+
158+
int
159+
mISDN_register_Bprotocol(struct Bprotocol *bp)
160+
{
161+
u_long flags;
162+
struct Bprotocol *old;
163+
164+
if (debug & DEBUG_CORE)
165+
printk(KERN_DEBUG "%s: %s/%x\n", __func__,
166+
bp->name, bp->Bprotocols);
167+
old = get_Bprotocol4mask(bp->Bprotocols);
168+
if (old) {
169+
printk(KERN_WARNING
170+
"register duplicate protocol old %s/%x new %s/%x\n",
171+
old->name, old->Bprotocols, bp->name, bp->Bprotocols);
172+
return -EBUSY;
173+
}
174+
write_lock_irqsave(&bp_lock, flags);
175+
list_add_tail(&bp->list, &Bprotocols);
176+
write_unlock_irqrestore(&bp_lock, flags);
177+
return 0;
178+
}
179+
EXPORT_SYMBOL(mISDN_register_Bprotocol);
180+
181+
void
182+
mISDN_unregister_Bprotocol(struct Bprotocol *bp)
183+
{
184+
u_long flags;
185+
186+
if (debug & DEBUG_CORE)
187+
printk(KERN_DEBUG "%s: %s/%x\n", __func__, bp->name,
188+
bp->Bprotocols);
189+
write_lock_irqsave(&bp_lock, flags);
190+
list_del(&bp->list);
191+
write_unlock_irqrestore(&bp_lock, flags);
192+
}
193+
EXPORT_SYMBOL(mISDN_unregister_Bprotocol);
194+
195+
int
196+
mISDNInit(void)
197+
{
198+
int err;
199+
200+
printk(KERN_INFO "Modular ISDN core version %d.%d.%d\n",
201+
MISDN_MAJOR_VERSION, MISDN_MINOR_VERSION, MISDN_RELEASE);
202+
mISDN_initstack(&debug);
203+
err = mISDN_inittimer(&debug);
204+
if (err)
205+
goto error;
206+
err = l1_init(&debug);
207+
if (err) {
208+
mISDN_timer_cleanup();
209+
goto error;
210+
}
211+
err = Isdnl2_Init(&debug);
212+
if (err) {
213+
mISDN_timer_cleanup();
214+
l1_cleanup();
215+
goto error;
216+
}
217+
err = misdn_sock_init(&debug);
218+
if (err) {
219+
mISDN_timer_cleanup();
220+
l1_cleanup();
221+
Isdnl2_cleanup();
222+
}
223+
error:
224+
return err;
225+
}
226+
227+
void mISDN_cleanup(void)
228+
{
229+
misdn_sock_cleanup();
230+
mISDN_timer_cleanup();
231+
l1_cleanup();
232+
Isdnl2_cleanup();
233+
234+
if (!list_empty(&devices))
235+
printk(KERN_ERR "%s devices still registered\n", __func__);
236+
237+
if (!list_empty(&Bprotocols))
238+
printk(KERN_ERR "%s Bprotocols still registered\n", __func__);
239+
printk(KERN_DEBUG "mISDNcore unloaded\n");
240+
}
241+
242+
module_init(mISDNInit);
243+
module_exit(mISDN_cleanup);
244+

drivers/isdn/mISDN/core.h

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright 2008 by Karsten Keil <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License version 2 as
6+
* published by the Free Software Foundation.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*
13+
*/
14+
15+
#ifndef mISDN_CORE_H
16+
#define mISDN_CORE_H
17+
18+
extern struct mISDNdevice *get_mdevice(u_int);
19+
extern int get_mdevice_count(void);
20+
21+
/* stack status flag */
22+
#define mISDN_STACK_ACTION_MASK 0x0000ffff
23+
#define mISDN_STACK_COMMAND_MASK 0x000f0000
24+
#define mISDN_STACK_STATUS_MASK 0xfff00000
25+
/* action bits 0-15 */
26+
#define mISDN_STACK_WORK 0
27+
#define mISDN_STACK_SETUP 1
28+
#define mISDN_STACK_CLEARING 2
29+
#define mISDN_STACK_RESTART 3
30+
#define mISDN_STACK_WAKEUP 4
31+
#define mISDN_STACK_ABORT 15
32+
/* command bits 16-19 */
33+
#define mISDN_STACK_STOPPED 16
34+
#define mISDN_STACK_INIT 17
35+
#define mISDN_STACK_THREADSTART 18
36+
/* status bits 20-31 */
37+
#define mISDN_STACK_BCHANNEL 20
38+
#define mISDN_STACK_ACTIVE 29
39+
#define mISDN_STACK_RUNNING 30
40+
#define mISDN_STACK_KILLED 31
41+
42+
43+
/* manager options */
44+
#define MGR_OPT_USER 24
45+
#define MGR_OPT_NETWORK 25
46+
47+
extern int connect_Bstack(struct mISDNdevice *, struct mISDNchannel *,
48+
u_int, struct sockaddr_mISDN *);
49+
extern int connect_layer1(struct mISDNdevice *, struct mISDNchannel *,
50+
u_int, struct sockaddr_mISDN *);
51+
extern int create_l2entity(struct mISDNdevice *, struct mISDNchannel *,
52+
u_int, struct sockaddr_mISDN *);
53+
54+
extern int create_stack(struct mISDNdevice *);
55+
extern int create_teimanager(struct mISDNdevice *);
56+
extern void delete_teimanager(struct mISDNchannel *);
57+
extern void delete_channel(struct mISDNchannel *);
58+
extern void delete_stack(struct mISDNdevice *);
59+
extern void mISDN_initstack(u_int *);
60+
extern int misdn_sock_init(u_int *);
61+
extern void misdn_sock_cleanup(void);
62+
extern void add_layer2(struct mISDNchannel *, struct mISDNstack *);
63+
extern void __add_layer2(struct mISDNchannel *, struct mISDNstack *);
64+
65+
extern u_int get_all_Bprotocols(void);
66+
struct Bprotocol *get_Bprotocol4mask(u_int);
67+
struct Bprotocol *get_Bprotocol4id(u_int);
68+
69+
extern int mISDN_inittimer(u_int *);
70+
extern void mISDN_timer_cleanup(void);
71+
72+
extern int l1_init(u_int *);
73+
extern void l1_cleanup(void);
74+
extern int Isdnl2_Init(u_int *);
75+
extern void Isdnl2_cleanup(void);
76+
77+
#endif

0 commit comments

Comments
 (0)