File: isdn_net.h

package info (click to toggle)
misdn-user 0.0.0%2Bcvs20041018-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 876 kB
  • ctags: 2,455
  • sloc: ansic: 19,247; makefile: 225
file content (291 lines) | stat: -rw-r--r-- 6,727 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#ifndef ISDN_NET_H
#define ISDN_NET_H

#include <stdlib.h>
#include <errno.h>
#include <pthread.h>
#include <semaphore.h>
#include "mISDNlib.h"
#include "isdn_msg.h"
#include "isdn_debug.h"
#include "ibuffer.h"

#define MSN_LEN		32
#define	SUBADR_LEN	24
#define UUS_LEN		256
#define FAC_LEN		132
#ifndef mISDN_FRAME_MIN
#define mISDN_FRAME_MIN	8
#endif

typedef struct _layer2		layer2_t;
typedef struct _layer3		layer3_t;
typedef struct _layer4		layer4_t;
typedef struct _bchannel	bchannel_t;
typedef struct _mISDNif		mISDNif_t;
typedef struct _mISDNinstance	mISDNinstance_t;
typedef struct _net_stack	net_stack_t;
typedef struct _manager		manager_t;
typedef struct _nr_list		nr_list_t;
typedef int (*ifunc_t)(net_stack_t *, msg_t *);
typedef int (*bfunc_t)(void *, void *);
typedef int (*afunc_t)(manager_t *, int, void *);


#define	MAX_BDATA_SIZE	2048

struct _bchannel {
	sem_t			work;
	msg_queue_t		workq;
	pthread_t		tid;
	manager_t		*manager;
	void			*app;
	int			channel;
	pthread_mutex_t		lock;
	int			cstate;
	int			bstate;
	int			l3id;
	int			b_addr;
	int			Flags;
	int			ttime;
	nr_list_t		*usednr;
	int			l1_prot;
	unsigned char		bc[8];
	unsigned char		uu[UUS_LEN];
	unsigned char		fac[FAC_LEN];
	unsigned char		nr[MSN_LEN];
	unsigned char		msn[MSN_LEN];
	unsigned char		clisub[SUBADR_LEN];
	unsigned char		cldsub[SUBADR_LEN];
	int			cause_loc;
	int			cause_val;
	unsigned char		display[84];
	msg_t			*smsg;
	ibuffer_t		*rbuf;
	ibuffer_t		*sbuf;
	int			rrid;
	int			rsid;
};

struct _manager	{
	manager_t		*prev;
	manager_t		*next;
	bchannel_t		bc[2];
	nr_list_t		*nrlist;
	net_stack_t		*nst;
	bfunc_t			man2stack;
	afunc_t			application;
	afunc_t			app_bc;
	pthread_t		tid;
	sem_t			work;
	msg_queue_t		workq;
};

#define PR_APP_CHECK_NR		1
#define PR_APP_ICALL		2
#define PR_APP_OCHANNEL		3
#define PR_APP_OCALL		4
#define PR_APP_ALERT		5
#define PR_APP_CONNECT		6
#define PR_APP_HANGUP		7
#define PR_APP_CLEAR		8
#define PR_APP_USERUSER		9
#define PR_APP_FACILITY		10
#define PR_APP_OPEN_RECFILES	11
#define PR_APP_CLOSE_RECFILES	12

#define FLG_NST_READER_ABORT	1
#define FLG_NST_TERMINATION	2

struct _net_stack {
	int			device;
	int			cardnr;
	int			d_stid;
	int			l0_id;
	int			l1_id;
	int			l2_id;
	msg_t			*phd_down_msg;
	layer2_t		*layer2;
	layer3_t		*layer3;
	ifunc_t			l1_l2;
	ifunc_t			l2_l3;
	ifunc_t			l3_l2;
	ifunc_t			manager_l3;
	bfunc_t			l3_manager;
	manager_t		*manager;
	msg_queue_t		down_queue;
	msg_queue_t		rqueue;
	msg_queue_t		wqueue;
	sem_t			work;
	pthread_mutex_t		lock;
	pthread_t		reader;
	int			b_stid[2];
	int			b_addr[2];
	int			bcid[2];
	u_long			flag;
	struct _itimer		*tlist;
	void			*l2fsm;
	void			*teifsm;
};

struct _nr_list {
	nr_list_t		*prev;
	nr_list_t		*next;
	unsigned char		len;
	unsigned char		nr[MSN_LEN];
	unsigned char		name[64];
	int			typ;
	int			flags;
};

#define NR_TYPE_INTERN		1
#define NR_TYPE_AUDIO		2
#define NR_TYPE_VOIP		3

typedef struct _itimer {
	struct _itimer		*prev;
	struct _itimer		*next;
	net_stack_t		*nst;
	int			id;
	int			expires;
	u_long			Flags;
	unsigned long		data;
	int			(*function)(unsigned long);
} itimer_t;

#define FLG_TIMER_RUNING	1

#define FLG_BC_USE		0x00000001
#define FLG_BC_SENT_CID		0x00000002
#define FLG_BC_CALL_ORGINATE	0x00000004
#define FLG_BC_PROGRESS		0x00000008
#define	FLG_BC_APPLICATION	0x00000010
#define FLG_BC_TONE_DIAL	0x00000100
#define FLG_BC_TONE_BUSY	0x00000200
#define FLG_BC_TONE_ALERT	0x00000400
#define FLG_BC_TONE_SILENCE	0x00000800
#define FLG_BC_TONE_NONE	0x00000000
#define FLG_BC_TONE		0x00000F00
#define FLG_BC_RECORD		0x00010000
#define FLG_BC_RECORDING	0x00020000
#define FLG_BC_RAWDEVICE	0x01000000
#define FLG_BC_KEEP_SEND	0x02000000
#define FLG_BC_TERMINATE	0x08000000

#define MSG_L1_PRIM		0x010000
#define MSG_L2_PRIM		0x020000
#define MSG_L3_PRIM		0x030000

extern	int		do_net_stack_setup(net_stack_t *);
extern	int		do_net_stack_cleanup(net_stack_t  *nst);
extern	void		*do_netthread(void *);
extern	int		term_netstack(net_stack_t *nst);

extern	int		init_manager(manager_t **mlist, afunc_t application);
extern	int		cleanup_manager(manager_t *mgr);

extern	int		write_dmsg(net_stack_t *, msg_t *);
extern	int		phd_conf(net_stack_t *, iframe_t *, msg_t *);

extern	int		init_timer(itimer_t *, net_stack_t  *);
extern	int		add_timer(itimer_t *);
extern	int		del_timer(itimer_t *);
extern	int		remove_timer(itimer_t *it);
extern	int		timer_pending(itimer_t *);

extern	u_char		*findie(u_char *, int, u_char, int);
extern	u_char		*find_and_copy_ie(u_char *, int, u_char, int, msg_t *);
extern	void		display_NR_IE(u_char *, char *, char *);

extern	int		match_nr(manager_t *mgr, unsigned char *nx, nr_list_t **nrx);

/* interface msg help routines */

static inline void mISDN_newhead(u_int prim, int dinfo, msg_t *msg)
{
	mISDN_head_t *hh = (mISDN_head_t *)msg->data;

	hh->prim = prim;
	hh->dinfo = dinfo;
}

static inline int if_newhead(void *arg, ifunc_t func, u_int prim, int dinfo,
	msg_t *msg)
{
	if (!msg)
		return(-ENXIO);
	mISDN_newhead(prim, dinfo, msg);
	return(func((net_stack_t *)arg, msg));
}

static inline void mISDN_addhead(u_int prim, int dinfo, msg_t *msg)
{
	mISDN_head_t *hh = (mISDN_head_t *)msg_push(msg, mISDN_HEADER_LEN);

	hh->prim = prim;
	hh->dinfo = dinfo;
}


static inline int if_addhead(void *arg, ifunc_t func, u_int prim, int dinfo,
	msg_t *msg)
{
	if (!msg)
		return(-ENXIO);
	mISDN_addhead(prim, dinfo, msg);
	return(func((net_stack_t *)arg, msg));
}


static inline msg_t *create_link_msg(u_int prim, int dinfo,
	int len, void *arg, int reserve)
{
	msg_t	*msg;

	if (!(msg = alloc_msg(len + mISDN_HEADER_LEN + reserve))) {
		wprint("%s: no msg size %d+%d+%d\n", __FUNCTION__,
			len, mISDN_HEADER_LEN, reserve);
		return(NULL);
	} else
		msg_reserve(msg, reserve + mISDN_HEADER_LEN);
	if (len)
		memcpy(msg_put(msg, len), arg, len);
	mISDN_addhead(prim, dinfo, msg);
	return(msg);
}

static inline int if_link(void *farg, ifunc_t func, u_int prim, int dinfo, int len,
	void *arg, int reserve)
{
	msg_t	*msg;
	int	err;

	if (!(msg = create_link_msg(prim, dinfo, len, arg, reserve)))
		return(-ENOMEM);
	err = func((net_stack_t *)farg, msg);
	if (err)
		free_msg(msg);
	return(err);
}

static inline msg_t *prep_l3data_msg(u_int prim, int dinfo, int ssize, int dsize, msg_t *old)
{
	if (!old) {
		old = alloc_msg(ssize + dsize + mISDN_HEADER_LEN + DEFAULT_HEADROOM);
		if (!old) {
			wprint("%s: no msg size %d+%d+%d\n", __FUNCTION__,
				ssize, dsize, mISDN_HEADER_LEN + DEFAULT_HEADROOM);
			return(NULL);
		}
	} else {
		old->data = old->head + DEFAULT_HEADROOM;
		old->tail = old->data;
		old->len = 0;
	}
	memset(msg_put(old, ssize + mISDN_HEADER_LEN), 0,
		ssize + mISDN_HEADER_LEN);
	mISDN_newhead(prim, dinfo, old);
	return(old);
}

#endif