Linux Audio

Check our new training course

Loading...
v5.9
  1/*
  2 *
  3 * Author	Karsten Keil <kkeil@novell.com>
  4 *
  5 * Copyright 2008  by Karsten Keil <kkeil@novell.com>
  6 *
  7 * This code is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
  9 * version 2.1 as published by the Free Software Foundation.
 10 *
 11 * This code is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU LESSER GENERAL PUBLIC LICENSE for more details.
 15 *
 16 */
 17
 18#ifndef mISDNIF_H
 19#define mISDNIF_H
 20
 21#include <stdarg.h>
 22#include <linux/types.h>
 23#include <linux/errno.h>
 24#include <linux/socket.h>
 25
 26/*
 27 * ABI Version 32 bit
 28 *
 29 * <8 bit> Major version
 30 *		- changed if any interface become backwards incompatible
 31 *
 32 * <8 bit> Minor version
 33 *              - changed if any interface is extended but backwards compatible
 34 *
 35 * <16 bit> Release number
 36 *              - should be incremented on every checkin
 37 */
 38#define	MISDN_MAJOR_VERSION	1
 39#define	MISDN_MINOR_VERSION	1
 40#define MISDN_RELEASE		29
 41
 42/* primitives for information exchange
 43 * generell format
 44 * <16  bit  0 >
 45 * <8  bit command>
 46 *    BIT 8 = 1 LAYER private
 47 *    BIT 7 = 1 answer
 48 *    BIT 6 = 1 DATA
 49 * <8  bit target layer mask>
 50 *
 51 * Layer = 00 is reserved for general commands
 52   Layer = 01  L2 -> HW
 53   Layer = 02  HW -> L2
 54   Layer = 04  L3 -> L2
 55   Layer = 08  L2 -> L3
 56 * Layer = FF is reserved for broadcast commands
 57 */
 58
 59#define MISDN_CMDMASK		0xff00
 60#define MISDN_LAYERMASK		0x00ff
 61
 62/* generell commands */
 63#define OPEN_CHANNEL		0x0100
 64#define CLOSE_CHANNEL		0x0200
 65#define CONTROL_CHANNEL		0x0300
 66#define CHECK_DATA		0x0400
 67
 68/* layer 2 -> layer 1 */
 69#define PH_ACTIVATE_REQ		0x0101
 70#define PH_DEACTIVATE_REQ	0x0201
 71#define PH_DATA_REQ		0x2001
 72#define MPH_ACTIVATE_REQ	0x0501
 73#define MPH_DEACTIVATE_REQ	0x0601
 74#define MPH_INFORMATION_REQ	0x0701
 75#define PH_CONTROL_REQ		0x0801
 76
 77/* layer 1 -> layer 2 */
 78#define PH_ACTIVATE_IND		0x0102
 79#define PH_ACTIVATE_CNF		0x4102
 80#define PH_DEACTIVATE_IND	0x0202
 81#define PH_DEACTIVATE_CNF	0x4202
 82#define PH_DATA_IND		0x2002
 83#define PH_DATA_E_IND		0x3002
 84#define MPH_ACTIVATE_IND	0x0502
 85#define MPH_DEACTIVATE_IND	0x0602
 86#define MPH_INFORMATION_IND	0x0702
 87#define PH_DATA_CNF		0x6002
 88#define PH_CONTROL_IND		0x0802
 89#define PH_CONTROL_CNF		0x4802
 90
 91/* layer 3 -> layer 2 */
 92#define DL_ESTABLISH_REQ	0x1004
 93#define DL_RELEASE_REQ		0x1104
 94#define DL_DATA_REQ		0x3004
 95#define DL_UNITDATA_REQ		0x3104
 96#define DL_INFORMATION_REQ	0x0004
 97
 98/* layer 2 -> layer 3 */
 99#define DL_ESTABLISH_IND	0x1008
100#define DL_ESTABLISH_CNF	0x5008
101#define DL_RELEASE_IND		0x1108
102#define DL_RELEASE_CNF		0x5108
103#define DL_DATA_IND		0x3008
104#define DL_UNITDATA_IND		0x3108
105#define DL_INFORMATION_IND	0x0008
106
107/* intern layer 2 management */
108#define MDL_ASSIGN_REQ		0x1804
109#define MDL_ASSIGN_IND		0x1904
110#define MDL_REMOVE_REQ		0x1A04
111#define MDL_REMOVE_IND		0x1B04
112#define MDL_STATUS_UP_IND	0x1C04
113#define MDL_STATUS_DOWN_IND	0x1D04
114#define MDL_STATUS_UI_IND	0x1E04
115#define MDL_ERROR_IND		0x1F04
116#define MDL_ERROR_RSP		0x5F04
117
118/* intern layer 2 */
119#define DL_TIMER200_IND		0x7004
120#define DL_TIMER203_IND		0x7304
121#define DL_INTERN_MSG		0x7804
122
123/* DL_INFORMATION_IND types */
124#define DL_INFO_L2_CONNECT	0x0001
125#define DL_INFO_L2_REMOVED	0x0002
126
127/* PH_CONTROL types */
128/* TOUCH TONE IS 0x20XX  XX "0"..."9", "A","B","C","D","*","#" */
129#define DTMF_TONE_VAL		0x2000
130#define DTMF_TONE_MASK		0x007F
131#define DTMF_TONE_START		0x2100
132#define DTMF_TONE_STOP		0x2200
133#define DTMF_HFC_COEF		0x4000
134#define DSP_CONF_JOIN		0x2403
135#define DSP_CONF_SPLIT		0x2404
136#define DSP_RECEIVE_OFF		0x2405
137#define DSP_RECEIVE_ON		0x2406
138#define DSP_ECHO_ON		0x2407
139#define DSP_ECHO_OFF		0x2408
140#define DSP_MIX_ON		0x2409
141#define DSP_MIX_OFF		0x240a
142#define DSP_DELAY		0x240b
143#define DSP_JITTER		0x240c
144#define DSP_TXDATA_ON		0x240d
145#define DSP_TXDATA_OFF		0x240e
146#define DSP_TX_DEJITTER		0x240f
147#define DSP_TX_DEJ_OFF		0x2410
148#define DSP_TONE_PATT_ON	0x2411
149#define DSP_TONE_PATT_OFF	0x2412
150#define DSP_VOL_CHANGE_TX	0x2413
151#define DSP_VOL_CHANGE_RX	0x2414
152#define DSP_BF_ENABLE_KEY	0x2415
153#define DSP_BF_DISABLE		0x2416
154#define DSP_BF_ACCEPT		0x2416
155#define DSP_BF_REJECT		0x2417
156#define DSP_PIPELINE_CFG	0x2418
157#define HFC_VOL_CHANGE_TX	0x2601
158#define HFC_VOL_CHANGE_RX	0x2602
159#define HFC_SPL_LOOP_ON		0x2603
160#define HFC_SPL_LOOP_OFF	0x2604
161/* for T30 FAX and analog modem */
162#define HW_MOD_FRM		0x4000
163#define HW_MOD_FRH		0x4001
164#define HW_MOD_FTM		0x4002
165#define HW_MOD_FTH		0x4003
166#define HW_MOD_FTS		0x4004
167#define HW_MOD_CONNECT		0x4010
168#define HW_MOD_OK		0x4011
169#define HW_MOD_NOCARR		0x4012
170#define HW_MOD_FCERROR		0x4013
171#define HW_MOD_READY		0x4014
172#define HW_MOD_LASTDATA		0x4015
173
174/* DSP_TONE_PATT_ON parameter */
175#define TONE_OFF			0x0000
176#define TONE_GERMAN_DIALTONE		0x0001
177#define TONE_GERMAN_OLDDIALTONE		0x0002
178#define TONE_AMERICAN_DIALTONE		0x0003
179#define TONE_GERMAN_DIALPBX		0x0004
180#define TONE_GERMAN_OLDDIALPBX		0x0005
181#define TONE_AMERICAN_DIALPBX		0x0006
182#define TONE_GERMAN_RINGING		0x0007
183#define TONE_GERMAN_OLDRINGING		0x0008
184#define TONE_AMERICAN_RINGPBX		0x000b
185#define TONE_GERMAN_RINGPBX		0x000c
186#define TONE_GERMAN_OLDRINGPBX		0x000d
187#define TONE_AMERICAN_RINGING		0x000e
188#define TONE_GERMAN_BUSY		0x000f
189#define TONE_GERMAN_OLDBUSY		0x0010
190#define TONE_AMERICAN_BUSY		0x0011
191#define TONE_GERMAN_HANGUP		0x0012
192#define TONE_GERMAN_OLDHANGUP		0x0013
193#define TONE_AMERICAN_HANGUP		0x0014
194#define TONE_SPECIAL_INFO		0x0015
195#define TONE_GERMAN_GASSENBESETZT	0x0016
196#define TONE_GERMAN_AUFSCHALTTON	0x0016
197
198/* MPH_INFORMATION_IND */
199#define L1_SIGNAL_LOS_OFF	0x0010
200#define L1_SIGNAL_LOS_ON	0x0011
201#define L1_SIGNAL_AIS_OFF	0x0012
202#define L1_SIGNAL_AIS_ON	0x0013
203#define L1_SIGNAL_RDI_OFF	0x0014
204#define L1_SIGNAL_RDI_ON	0x0015
205#define L1_SIGNAL_SLIP_RX	0x0020
206#define L1_SIGNAL_SLIP_TX	0x0021
207
208/*
209 * protocol ids
210 * D channel 1-31
211 * B channel 33 - 63
212 */
213
214#define ISDN_P_NONE		0
215#define ISDN_P_BASE		0
216#define ISDN_P_TE_S0		0x01
217#define ISDN_P_NT_S0  		0x02
218#define ISDN_P_TE_E1		0x03
219#define ISDN_P_NT_E1  		0x04
220#define ISDN_P_TE_UP0		0x05
221#define ISDN_P_NT_UP0		0x06
222
223#define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \
224				(p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE))
225#define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \
226				(p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT))
227#define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0))
228#define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1))
229#define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0))
230
231
232#define ISDN_P_LAPD_TE		0x10
233#define	ISDN_P_LAPD_NT		0x11
234
235#define ISDN_P_B_MASK		0x1f
236#define ISDN_P_B_START		0x20
237
238#define ISDN_P_B_RAW		0x21
239#define ISDN_P_B_HDLC		0x22
240#define ISDN_P_B_X75SLP		0x23
241#define ISDN_P_B_L2DTMF		0x24
242#define ISDN_P_B_L2DSP		0x25
243#define ISDN_P_B_L2DSPHDLC	0x26
244#define ISDN_P_B_T30_FAX	0x27
245#define ISDN_P_B_MODEM_ASYNC	0x28
246
247#define OPTION_L2_PMX		1
248#define OPTION_L2_PTP		2
249#define OPTION_L2_FIXEDTEI	3
250#define OPTION_L2_CLEANUP	4
251#define OPTION_L1_HOLD		5
252
253/* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */
254#define MISDN_MAX_IDLEN		20
255
256struct mISDNhead {
257	unsigned int	prim;
258	unsigned int	id;
259}  __packed;
260
261#define MISDN_HEADER_LEN	sizeof(struct mISDNhead)
262#define MAX_DATA_SIZE		2048
263#define MAX_DATA_MEM		(MAX_DATA_SIZE + MISDN_HEADER_LEN)
264#define MAX_DFRAME_LEN		260
265
266#define MISDN_ID_ADDR_MASK	0xFFFF
267#define MISDN_ID_TEI_MASK	0xFF00
268#define MISDN_ID_SAPI_MASK	0x00FF
269#define MISDN_ID_TEI_ANY	0x7F00
270
271#define MISDN_ID_ANY		0xFFFF
272#define MISDN_ID_NONE		0xFFFE
273
274#define GROUP_TEI		127
275#define TEI_SAPI		63
276#define CTRL_SAPI		0
277
278#define MISDN_MAX_CHANNEL	127
279#define MISDN_CHMAP_SIZE	((MISDN_MAX_CHANNEL + 1) >> 3)
280
281#define SOL_MISDN	0
282
283struct sockaddr_mISDN {
284	sa_family_t    family;
285	unsigned char	dev;
286	unsigned char	channel;
287	unsigned char	sapi;
288	unsigned char	tei;
289};
290
291struct mISDNversion {
292	unsigned char	major;
293	unsigned char	minor;
294	unsigned short	release;
295};
296
297struct mISDN_devinfo {
298	u_int			id;
299	u_int			Dprotocols;
300	u_int			Bprotocols;
301	u_int			protocol;
302	u_char			channelmap[MISDN_CHMAP_SIZE];
303	u_int			nrbchan;
304	char			name[MISDN_MAX_IDLEN];
305};
306
307struct mISDN_devrename {
308	u_int			id;
309	char			name[MISDN_MAX_IDLEN]; /* new name */
310};
311
312/* MPH_INFORMATION_REQ payload */
313struct ph_info_ch {
314	__u32 protocol;
315	__u64 Flags;
316};
317
318struct ph_info_dch {
319	struct ph_info_ch ch;
320	__u16 state;
321	__u16 num_bch;
322};
323
324struct ph_info {
325	struct ph_info_dch dch;
326	struct ph_info_ch  bch[];
327};
328
329/* timer device ioctl */
330#define IMADDTIMER	_IOR('I', 64, int)
331#define IMDELTIMER	_IOR('I', 65, int)
332
333/* socket ioctls */
334#define	IMGETVERSION	_IOR('I', 66, int)
335#define	IMGETCOUNT	_IOR('I', 67, int)
336#define IMGETDEVINFO	_IOR('I', 68, int)
337#define IMCTRLREQ	_IOR('I', 69, int)
338#define IMCLEAR_L2	_IOR('I', 70, int)
339#define IMSETDEVNAME	_IOR('I', 71, struct mISDN_devrename)
340#define IMHOLD_L1	_IOR('I', 72, int)
341
342static inline int
343test_channelmap(u_int nr, u_char *map)
344{
345	if (nr <= MISDN_MAX_CHANNEL)
346		return map[nr >> 3] & (1 << (nr & 7));
347	else
348		return 0;
349}
350
351static inline void
352set_channelmap(u_int nr, u_char *map)
353{
354	map[nr >> 3] |= (1 << (nr & 7));
355}
356
357static inline void
358clear_channelmap(u_int nr, u_char *map)
359{
360	map[nr >> 3] &= ~(1 << (nr & 7));
361}
362
363/* CONTROL_CHANNEL parameters */
364#define MISDN_CTRL_GETOP		0x0000
365#define MISDN_CTRL_LOOP			0x0001
366#define MISDN_CTRL_CONNECT		0x0002
367#define MISDN_CTRL_DISCONNECT		0x0004
368#define MISDN_CTRL_RX_BUFFER		0x0008
369#define MISDN_CTRL_PCMCONNECT		0x0010
370#define MISDN_CTRL_PCMDISCONNECT	0x0020
371#define MISDN_CTRL_SETPEER		0x0040
372#define MISDN_CTRL_UNSETPEER		0x0080
373#define MISDN_CTRL_RX_OFF		0x0100
374#define MISDN_CTRL_FILL_EMPTY		0x0200
375#define MISDN_CTRL_GETPEER		0x0400
376#define MISDN_CTRL_L1_TIMER3		0x0800
377#define MISDN_CTRL_HW_FEATURES_OP	0x2000
378#define MISDN_CTRL_HW_FEATURES		0x2001
379#define MISDN_CTRL_HFC_OP		0x4000
380#define MISDN_CTRL_HFC_PCM_CONN		0x4001
381#define MISDN_CTRL_HFC_PCM_DISC		0x4002
382#define MISDN_CTRL_HFC_CONF_JOIN	0x4003
383#define MISDN_CTRL_HFC_CONF_SPLIT	0x4004
384#define MISDN_CTRL_HFC_RECEIVE_OFF	0x4005
385#define MISDN_CTRL_HFC_RECEIVE_ON	0x4006
386#define MISDN_CTRL_HFC_ECHOCAN_ON 	0x4007
387#define MISDN_CTRL_HFC_ECHOCAN_OFF 	0x4008
388#define MISDN_CTRL_HFC_WD_INIT		0x4009
389#define MISDN_CTRL_HFC_WD_RESET		0x400A
390
391/* special RX buffer value for MISDN_CTRL_RX_BUFFER request.p1 is the minimum
392 * buffer size request.p2 the maximum. Using  MISDN_CTRL_RX_SIZE_IGNORE will
393 * not change the value, but still read back the actual stetting.
394 */
395#define MISDN_CTRL_RX_SIZE_IGNORE	-1
396
397/* socket options */
398#define MISDN_TIME_STAMP		0x0001
399
400struct mISDN_ctrl_req {
401	int		op;
402	int		channel;
403	int		p1;
404	int		p2;
405};
406
407/* muxer options */
408#define MISDN_OPT_ALL		1
409#define MISDN_OPT_TEIMGR	2
410
411#ifdef __KERNEL__
412#include <linux/list.h>
413#include <linux/skbuff.h>
414#include <linux/net.h>
415#include <net/sock.h>
416#include <linux/completion.h>
417
418#define DEBUG_CORE		0x000000ff
419#define DEBUG_CORE_FUNC		0x00000002
420#define DEBUG_SOCKET		0x00000004
421#define DEBUG_MANAGER		0x00000008
422#define DEBUG_SEND_ERR		0x00000010
423#define DEBUG_MSG_THREAD	0x00000020
424#define DEBUG_QUEUE_FUNC	0x00000040
425#define DEBUG_L1		0x0000ff00
426#define DEBUG_L1_FSM		0x00000200
427#define DEBUG_L2		0x00ff0000
428#define DEBUG_L2_FSM		0x00020000
429#define DEBUG_L2_CTRL		0x00040000
430#define DEBUG_L2_RECV		0x00080000
431#define DEBUG_L2_TEI		0x00100000
432#define DEBUG_L2_TEIFSM		0x00200000
433#define DEBUG_TIMER		0x01000000
434#define DEBUG_CLOCK		0x02000000
435
436#define mISDN_HEAD_P(s)		((struct mISDNhead *)&s->cb[0])
437#define mISDN_HEAD_PRIM(s)	(((struct mISDNhead *)&s->cb[0])->prim)
438#define mISDN_HEAD_ID(s)	(((struct mISDNhead *)&s->cb[0])->id)
439
440/* socket states */
441#define MISDN_OPEN	1
442#define MISDN_BOUND	2
443#define MISDN_CLOSED	3
444
445struct mISDNchannel;
446struct mISDNdevice;
447struct mISDNstack;
448struct mISDNclock;
449
450struct channel_req {
451	u_int			protocol;
452	struct sockaddr_mISDN	adr;
453	struct mISDNchannel	*ch;
454};
455
456typedef	int	(ctrl_func_t)(struct mISDNchannel *, u_int, void *);
457typedef	int	(send_func_t)(struct mISDNchannel *, struct sk_buff *);
458typedef int	(create_func_t)(struct channel_req *);
459
460struct Bprotocol {
461	struct list_head	list;
462	char			*name;
463	u_int			Bprotocols;
464	create_func_t		*create;
465};
466
467struct mISDNchannel {
468	struct list_head	list;
469	u_int			protocol;
470	u_int			nr;
471	u_long			opt;
472	u_int			addr;
473	struct mISDNstack	*st;
474	struct mISDNchannel	*peer;
475	send_func_t		*send;
476	send_func_t		*recv;
477	ctrl_func_t		*ctrl;
478};
479
480struct mISDN_sock_list {
481	struct hlist_head	head;
482	rwlock_t		lock;
483};
484
485struct mISDN_sock {
486	struct sock		sk;
487	struct mISDNchannel	ch;
488	u_int			cmask;
489	struct mISDNdevice	*dev;
490};
491
492
493
494struct mISDNdevice {
495	struct mISDNchannel	D;
496	u_int			id;
497	u_int			Dprotocols;
498	u_int			Bprotocols;
499	u_int			nrbchan;
500	u_char			channelmap[MISDN_CHMAP_SIZE];
501	struct list_head	bchannels;
502	struct mISDNchannel	*teimgr;
503	struct device		dev;
504};
505
506struct mISDNstack {
507	u_long			status;
508	struct mISDNdevice	*dev;
509	struct task_struct	*thread;
510	struct completion	*notify;
511	wait_queue_head_t	workq;
512	struct sk_buff_head	msgq;
513	struct list_head	layer2;
514	struct mISDNchannel	*layer1;
515	struct mISDNchannel	own;
516	struct mutex		lmutex; /* protect lists */
517	struct mISDN_sock_list	l1sock;
518#ifdef MISDN_MSG_STATS
519	u_int			msg_cnt;
520	u_int			sleep_cnt;
521	u_int			stopped_cnt;
522#endif
523};
524
525typedef	int	(clockctl_func_t)(void *, int);
526
527struct	mISDNclock {
528	struct list_head	list;
529	char			name[64];
530	int			pri;
531	clockctl_func_t		*ctl;
532	void			*priv;
533};
534
535/* global alloc/queue functions */
536
537static inline struct sk_buff *
538mI_alloc_skb(unsigned int len, gfp_t gfp_mask)
539{
540	struct sk_buff	*skb;
541
542	skb = alloc_skb(len + MISDN_HEADER_LEN, gfp_mask);
543	if (likely(skb))
544		skb_reserve(skb, MISDN_HEADER_LEN);
545	return skb;
546}
547
548static inline struct sk_buff *
549_alloc_mISDN_skb(u_int prim, u_int id, u_int len, void *dp, gfp_t gfp_mask)
550{
551	struct sk_buff	*skb = mI_alloc_skb(len, gfp_mask);
552	struct mISDNhead *hh;
553
554	if (!skb)
555		return NULL;
556	if (len)
557		skb_put_data(skb, dp, len);
558	hh = mISDN_HEAD_P(skb);
559	hh->prim = prim;
560	hh->id = id;
561	return skb;
562}
563
564static inline void
565_queue_data(struct mISDNchannel *ch, u_int prim,
566    u_int id, u_int len, void *dp, gfp_t gfp_mask)
567{
568	struct sk_buff		*skb;
569
570	if (!ch->peer)
571		return;
572	skb = _alloc_mISDN_skb(prim, id, len, dp, gfp_mask);
573	if (!skb)
574		return;
575	if (ch->recv(ch->peer, skb))
576		dev_kfree_skb(skb);
577}
578
579/* global register/unregister functions */
580
581extern int	mISDN_register_device(struct mISDNdevice *,
582					struct device *parent, char *name);
583extern void	mISDN_unregister_device(struct mISDNdevice *);
584extern int	mISDN_register_Bprotocol(struct Bprotocol *);
585extern void	mISDN_unregister_Bprotocol(struct Bprotocol *);
586extern struct mISDNclock *mISDN_register_clock(char *, int, clockctl_func_t *,
587						void *);
588extern void	mISDN_unregister_clock(struct mISDNclock *);
589
590static inline struct mISDNdevice *dev_to_mISDN(struct device *dev)
591{
592	if (dev)
593		return dev_get_drvdata(dev);
594	else
595		return NULL;
596}
597
598extern void	set_channel_address(struct mISDNchannel *, u_int, u_int);
599extern void	mISDN_clock_update(struct mISDNclock *, int, ktime_t *);
600extern unsigned short mISDN_clock_get(void);
601extern const char *mISDNDevName4ch(struct mISDNchannel *);
602
603#endif /* __KERNEL__ */
604#endif /* mISDNIF_H */
v3.1
  1/*
  2 *
  3 * Author	Karsten Keil <kkeil@novell.com>
  4 *
  5 * Copyright 2008  by Karsten Keil <kkeil@novell.com>
  6 *
  7 * This code is free software; you can redistribute it and/or modify
  8 * it under the terms of the GNU LESSER GENERAL PUBLIC LICENSE
  9 * version 2.1 as published by the Free Software Foundation.
 10 *
 11 * This code is distributed in the hope that it will be useful,
 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14 * GNU LESSER GENERAL PUBLIC LICENSE for more details.
 15 *
 16 */
 17
 18#ifndef mISDNIF_H
 19#define mISDNIF_H
 20
 21#include <stdarg.h>
 22#include <linux/types.h>
 23#include <linux/errno.h>
 24#include <linux/socket.h>
 25
 26/*
 27 * ABI Version 32 bit
 28 *
 29 * <8 bit> Major version
 30 *		- changed if any interface become backwards incompatible
 31 *
 32 * <8 bit> Minor version
 33 *              - changed if any interface is extended but backwards compatible
 34 *
 35 * <16 bit> Release number
 36 *              - should be incremented on every checkin
 37 */
 38#define	MISDN_MAJOR_VERSION	1
 39#define	MISDN_MINOR_VERSION	1
 40#define MISDN_RELEASE		21
 41
 42/* primitives for information exchange
 43 * generell format
 44 * <16  bit  0 >
 45 * <8  bit command>
 46 *    BIT 8 = 1 LAYER private
 47 *    BIT 7 = 1 answer
 48 *    BIT 6 = 1 DATA
 49 * <8  bit target layer mask>
 50 *
 51 * Layer = 00 is reserved for general commands
 52   Layer = 01  L2 -> HW
 53   Layer = 02  HW -> L2
 54   Layer = 04  L3 -> L2
 55   Layer = 08  L2 -> L3
 56 * Layer = FF is reserved for broadcast commands
 57 */
 58
 59#define MISDN_CMDMASK		0xff00
 60#define MISDN_LAYERMASK		0x00ff
 61
 62/* generell commands */
 63#define OPEN_CHANNEL		0x0100
 64#define CLOSE_CHANNEL		0x0200
 65#define CONTROL_CHANNEL		0x0300
 66#define CHECK_DATA		0x0400
 67
 68/* layer 2 -> layer 1 */
 69#define PH_ACTIVATE_REQ		0x0101
 70#define PH_DEACTIVATE_REQ	0x0201
 71#define PH_DATA_REQ		0x2001
 72#define MPH_ACTIVATE_REQ	0x0501
 73#define MPH_DEACTIVATE_REQ	0x0601
 74#define MPH_INFORMATION_REQ	0x0701
 75#define PH_CONTROL_REQ		0x0801
 76
 77/* layer 1 -> layer 2 */
 78#define PH_ACTIVATE_IND		0x0102
 79#define PH_ACTIVATE_CNF		0x4102
 80#define PH_DEACTIVATE_IND	0x0202
 81#define PH_DEACTIVATE_CNF	0x4202
 82#define PH_DATA_IND		0x2002
 83#define PH_DATA_E_IND		0x3002
 84#define MPH_ACTIVATE_IND	0x0502
 85#define MPH_DEACTIVATE_IND	0x0602
 86#define MPH_INFORMATION_IND	0x0702
 87#define PH_DATA_CNF		0x6002
 88#define PH_CONTROL_IND		0x0802
 89#define PH_CONTROL_CNF		0x4802
 90
 91/* layer 3 -> layer 2 */
 92#define DL_ESTABLISH_REQ	0x1004
 93#define DL_RELEASE_REQ		0x1104
 94#define DL_DATA_REQ		0x3004
 95#define DL_UNITDATA_REQ		0x3104
 96#define DL_INFORMATION_REQ	0x0004
 97
 98/* layer 2 -> layer 3 */
 99#define DL_ESTABLISH_IND	0x1008
100#define DL_ESTABLISH_CNF	0x5008
101#define DL_RELEASE_IND		0x1108
102#define DL_RELEASE_CNF		0x5108
103#define DL_DATA_IND		0x3008
104#define DL_UNITDATA_IND		0x3108
105#define DL_INFORMATION_IND	0x0008
106
107/* intern layer 2 management */
108#define MDL_ASSIGN_REQ		0x1804
109#define MDL_ASSIGN_IND		0x1904
110#define MDL_REMOVE_REQ		0x1A04
111#define MDL_REMOVE_IND		0x1B04
112#define MDL_STATUS_UP_IND	0x1C04
113#define MDL_STATUS_DOWN_IND	0x1D04
114#define MDL_STATUS_UI_IND	0x1E04
115#define MDL_ERROR_IND		0x1F04
116#define MDL_ERROR_RSP		0x5F04
117
 
 
 
 
 
118/* DL_INFORMATION_IND types */
119#define DL_INFO_L2_CONNECT	0x0001
120#define DL_INFO_L2_REMOVED	0x0002
121
122/* PH_CONTROL types */
123/* TOUCH TONE IS 0x20XX  XX "0"..."9", "A","B","C","D","*","#" */
124#define DTMF_TONE_VAL		0x2000
125#define DTMF_TONE_MASK		0x007F
126#define DTMF_TONE_START		0x2100
127#define DTMF_TONE_STOP		0x2200
128#define DTMF_HFC_COEF		0x4000
129#define DSP_CONF_JOIN		0x2403
130#define DSP_CONF_SPLIT		0x2404
131#define DSP_RECEIVE_OFF		0x2405
132#define DSP_RECEIVE_ON		0x2406
133#define DSP_ECHO_ON		0x2407
134#define DSP_ECHO_OFF		0x2408
135#define DSP_MIX_ON		0x2409
136#define DSP_MIX_OFF		0x240a
137#define DSP_DELAY		0x240b
138#define DSP_JITTER		0x240c
139#define DSP_TXDATA_ON		0x240d
140#define DSP_TXDATA_OFF		0x240e
141#define DSP_TX_DEJITTER		0x240f
142#define DSP_TX_DEJ_OFF		0x2410
143#define DSP_TONE_PATT_ON	0x2411
144#define DSP_TONE_PATT_OFF	0x2412
145#define DSP_VOL_CHANGE_TX	0x2413
146#define DSP_VOL_CHANGE_RX	0x2414
147#define DSP_BF_ENABLE_KEY	0x2415
148#define DSP_BF_DISABLE		0x2416
149#define DSP_BF_ACCEPT		0x2416
150#define DSP_BF_REJECT		0x2417
151#define DSP_PIPELINE_CFG	0x2418
152#define HFC_VOL_CHANGE_TX	0x2601
153#define HFC_VOL_CHANGE_RX	0x2602
154#define HFC_SPL_LOOP_ON		0x2603
155#define HFC_SPL_LOOP_OFF	0x2604
156/* for T30 FAX and analog modem */
157#define HW_MOD_FRM		0x4000
158#define HW_MOD_FRH		0x4001
159#define HW_MOD_FTM		0x4002
160#define HW_MOD_FTH		0x4003
161#define HW_MOD_FTS		0x4004
162#define HW_MOD_CONNECT		0x4010
163#define HW_MOD_OK		0x4011
164#define HW_MOD_NOCARR		0x4012
165#define HW_MOD_FCERROR		0x4013
166#define HW_MOD_READY		0x4014
167#define HW_MOD_LASTDATA		0x4015
168
169/* DSP_TONE_PATT_ON parameter */
170#define TONE_OFF			0x0000
171#define TONE_GERMAN_DIALTONE		0x0001
172#define TONE_GERMAN_OLDDIALTONE		0x0002
173#define TONE_AMERICAN_DIALTONE		0x0003
174#define TONE_GERMAN_DIALPBX		0x0004
175#define TONE_GERMAN_OLDDIALPBX		0x0005
176#define TONE_AMERICAN_DIALPBX		0x0006
177#define TONE_GERMAN_RINGING		0x0007
178#define TONE_GERMAN_OLDRINGING		0x0008
179#define TONE_AMERICAN_RINGPBX		0x000b
180#define TONE_GERMAN_RINGPBX		0x000c
181#define TONE_GERMAN_OLDRINGPBX		0x000d
182#define TONE_AMERICAN_RINGING		0x000e
183#define TONE_GERMAN_BUSY		0x000f
184#define TONE_GERMAN_OLDBUSY		0x0010
185#define TONE_AMERICAN_BUSY		0x0011
186#define TONE_GERMAN_HANGUP		0x0012
187#define TONE_GERMAN_OLDHANGUP		0x0013
188#define TONE_AMERICAN_HANGUP		0x0014
189#define TONE_SPECIAL_INFO		0x0015
190#define TONE_GERMAN_GASSENBESETZT	0x0016
191#define TONE_GERMAN_AUFSCHALTTON	0x0016
192
193/* MPH_INFORMATION_IND */
194#define L1_SIGNAL_LOS_OFF	0x0010
195#define L1_SIGNAL_LOS_ON	0x0011
196#define L1_SIGNAL_AIS_OFF	0x0012
197#define L1_SIGNAL_AIS_ON	0x0013
198#define L1_SIGNAL_RDI_OFF	0x0014
199#define L1_SIGNAL_RDI_ON	0x0015
200#define L1_SIGNAL_SLIP_RX	0x0020
201#define L1_SIGNAL_SLIP_TX	0x0021
202
203/*
204 * protocol ids
205 * D channel 1-31
206 * B channel 33 - 63
207 */
208
209#define ISDN_P_NONE		0
210#define ISDN_P_BASE		0
211#define ISDN_P_TE_S0		0x01
212#define ISDN_P_NT_S0  		0x02
213#define ISDN_P_TE_E1		0x03
214#define ISDN_P_NT_E1  		0x04
215#define ISDN_P_TE_UP0		0x05
216#define ISDN_P_NT_UP0		0x06
217
218#define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \
219				(p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE))
220#define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \
221				(p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT))
222#define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0))
223#define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1))
224#define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0))
225
226
227#define ISDN_P_LAPD_TE		0x10
228#define	ISDN_P_LAPD_NT		0x11
229
230#define ISDN_P_B_MASK		0x1f
231#define ISDN_P_B_START		0x20
232
233#define ISDN_P_B_RAW		0x21
234#define ISDN_P_B_HDLC		0x22
235#define ISDN_P_B_X75SLP		0x23
236#define ISDN_P_B_L2DTMF		0x24
237#define ISDN_P_B_L2DSP		0x25
238#define ISDN_P_B_L2DSPHDLC	0x26
239#define ISDN_P_B_T30_FAX	0x27
240#define ISDN_P_B_MODEM_ASYNC	0x28
241
242#define OPTION_L2_PMX		1
243#define OPTION_L2_PTP		2
244#define OPTION_L2_FIXEDTEI	3
245#define OPTION_L2_CLEANUP	4
246#define OPTION_L1_HOLD		5
247
248/* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */
249#define MISDN_MAX_IDLEN		20
250
251struct mISDNhead {
252	unsigned int	prim;
253	unsigned int	id;
254}  __packed;
255
256#define MISDN_HEADER_LEN	sizeof(struct mISDNhead)
257#define MAX_DATA_SIZE		2048
258#define MAX_DATA_MEM		(MAX_DATA_SIZE + MISDN_HEADER_LEN)
259#define MAX_DFRAME_LEN		260
260
261#define MISDN_ID_ADDR_MASK	0xFFFF
262#define MISDN_ID_TEI_MASK	0xFF00
263#define MISDN_ID_SAPI_MASK	0x00FF
264#define MISDN_ID_TEI_ANY	0x7F00
265
266#define MISDN_ID_ANY		0xFFFF
267#define MISDN_ID_NONE		0xFFFE
268
269#define GROUP_TEI		127
270#define TEI_SAPI		63
271#define CTRL_SAPI		0
272
273#define MISDN_MAX_CHANNEL	127
274#define MISDN_CHMAP_SIZE	((MISDN_MAX_CHANNEL + 1) >> 3)
275
276#define SOL_MISDN	0
277
278struct sockaddr_mISDN {
279	sa_family_t    family;
280	unsigned char	dev;
281	unsigned char	channel;
282	unsigned char	sapi;
283	unsigned char	tei;
284};
285
286struct mISDNversion {
287	unsigned char	major;
288	unsigned char	minor;
289	unsigned short	release;
290};
291
292struct mISDN_devinfo {
293	u_int			id;
294	u_int			Dprotocols;
295	u_int			Bprotocols;
296	u_int			protocol;
297	u_char			channelmap[MISDN_CHMAP_SIZE];
298	u_int			nrbchan;
299	char			name[MISDN_MAX_IDLEN];
300};
301
302struct mISDN_devrename {
303	u_int			id;
304	char			name[MISDN_MAX_IDLEN]; /* new name */
305};
306
307/* MPH_INFORMATION_REQ payload */
308struct ph_info_ch {
309	__u32 protocol;
310	__u64 Flags;
311};
312
313struct ph_info_dch {
314	struct ph_info_ch ch;
315	__u16 state;
316	__u16 num_bch;
317};
318
319struct ph_info {
320	struct ph_info_dch dch;
321	struct ph_info_ch  bch[];
322};
323
324/* timer device ioctl */
325#define IMADDTIMER	_IOR('I', 64, int)
326#define IMDELTIMER	_IOR('I', 65, int)
327
328/* socket ioctls */
329#define	IMGETVERSION	_IOR('I', 66, int)
330#define	IMGETCOUNT	_IOR('I', 67, int)
331#define IMGETDEVINFO	_IOR('I', 68, int)
332#define IMCTRLREQ	_IOR('I', 69, int)
333#define IMCLEAR_L2	_IOR('I', 70, int)
334#define IMSETDEVNAME	_IOR('I', 71, struct mISDN_devrename)
335#define IMHOLD_L1	_IOR('I', 72, int)
336
337static inline int
338test_channelmap(u_int nr, u_char *map)
339{
340	if (nr <= MISDN_MAX_CHANNEL)
341		return map[nr >> 3] & (1 << (nr & 7));
342	else
343		return 0;
344}
345
346static inline void
347set_channelmap(u_int nr, u_char *map)
348{
349	map[nr >> 3] |= (1 << (nr & 7));
350}
351
352static inline void
353clear_channelmap(u_int nr, u_char *map)
354{
355	map[nr >> 3] &= ~(1 << (nr & 7));
356}
357
358/* CONTROL_CHANNEL parameters */
359#define MISDN_CTRL_GETOP		0x0000
360#define MISDN_CTRL_LOOP			0x0001
361#define MISDN_CTRL_CONNECT		0x0002
362#define MISDN_CTRL_DISCONNECT		0x0004
 
363#define MISDN_CTRL_PCMCONNECT		0x0010
364#define MISDN_CTRL_PCMDISCONNECT	0x0020
365#define MISDN_CTRL_SETPEER		0x0040
366#define MISDN_CTRL_UNSETPEER		0x0080
367#define MISDN_CTRL_RX_OFF		0x0100
368#define MISDN_CTRL_FILL_EMPTY		0x0200
369#define MISDN_CTRL_GETPEER		0x0400
 
370#define MISDN_CTRL_HW_FEATURES_OP	0x2000
371#define MISDN_CTRL_HW_FEATURES		0x2001
372#define MISDN_CTRL_HFC_OP		0x4000
373#define MISDN_CTRL_HFC_PCM_CONN		0x4001
374#define MISDN_CTRL_HFC_PCM_DISC		0x4002
375#define MISDN_CTRL_HFC_CONF_JOIN	0x4003
376#define MISDN_CTRL_HFC_CONF_SPLIT	0x4004
377#define MISDN_CTRL_HFC_RECEIVE_OFF	0x4005
378#define MISDN_CTRL_HFC_RECEIVE_ON	0x4006
379#define MISDN_CTRL_HFC_ECHOCAN_ON 	0x4007
380#define MISDN_CTRL_HFC_ECHOCAN_OFF 	0x4008
381#define MISDN_CTRL_HFC_WD_INIT		0x4009
382#define MISDN_CTRL_HFC_WD_RESET		0x400A
383
 
 
 
 
 
 
384/* socket options */
385#define MISDN_TIME_STAMP		0x0001
386
387struct mISDN_ctrl_req {
388	int		op;
389	int		channel;
390	int		p1;
391	int		p2;
392};
393
394/* muxer options */
395#define MISDN_OPT_ALL		1
396#define MISDN_OPT_TEIMGR	2
397
398#ifdef __KERNEL__
399#include <linux/list.h>
400#include <linux/skbuff.h>
401#include <linux/net.h>
402#include <net/sock.h>
403#include <linux/completion.h>
404
405#define DEBUG_CORE		0x000000ff
406#define DEBUG_CORE_FUNC		0x00000002
407#define DEBUG_SOCKET		0x00000004
408#define DEBUG_MANAGER		0x00000008
409#define DEBUG_SEND_ERR		0x00000010
410#define DEBUG_MSG_THREAD	0x00000020
411#define DEBUG_QUEUE_FUNC	0x00000040
412#define DEBUG_L1		0x0000ff00
413#define DEBUG_L1_FSM		0x00000200
414#define DEBUG_L2		0x00ff0000
415#define DEBUG_L2_FSM		0x00020000
416#define DEBUG_L2_CTRL		0x00040000
417#define DEBUG_L2_RECV		0x00080000
418#define DEBUG_L2_TEI		0x00100000
419#define DEBUG_L2_TEIFSM		0x00200000
420#define DEBUG_TIMER		0x01000000
421#define DEBUG_CLOCK		0x02000000
422
423#define mISDN_HEAD_P(s)		((struct mISDNhead *)&s->cb[0])
424#define mISDN_HEAD_PRIM(s)	(((struct mISDNhead *)&s->cb[0])->prim)
425#define mISDN_HEAD_ID(s)	(((struct mISDNhead *)&s->cb[0])->id)
426
427/* socket states */
428#define MISDN_OPEN	1
429#define MISDN_BOUND	2
430#define MISDN_CLOSED	3
431
432struct mISDNchannel;
433struct mISDNdevice;
434struct mISDNstack;
435struct mISDNclock;
436
437struct channel_req {
438	u_int			protocol;
439	struct sockaddr_mISDN	adr;
440	struct mISDNchannel	*ch;
441};
442
443typedef	int	(ctrl_func_t)(struct mISDNchannel *, u_int, void *);
444typedef	int	(send_func_t)(struct mISDNchannel *, struct sk_buff *);
445typedef int	(create_func_t)(struct channel_req *);
446
447struct Bprotocol {
448	struct list_head	list;
449	char			*name;
450	u_int			Bprotocols;
451	create_func_t		*create;
452};
453
454struct mISDNchannel {
455	struct list_head	list;
456	u_int			protocol;
457	u_int			nr;
458	u_long			opt;
459	u_int			addr;
460	struct mISDNstack	*st;
461	struct mISDNchannel	*peer;
462	send_func_t		*send;
463	send_func_t		*recv;
464	ctrl_func_t		*ctrl;
465};
466
467struct mISDN_sock_list {
468	struct hlist_head	head;
469	rwlock_t		lock;
470};
471
472struct mISDN_sock {
473	struct sock		sk;
474	struct mISDNchannel	ch;
475	u_int			cmask;
476	struct mISDNdevice	*dev;
477};
478
479
480
481struct mISDNdevice {
482	struct mISDNchannel	D;
483	u_int			id;
484	u_int			Dprotocols;
485	u_int			Bprotocols;
486	u_int			nrbchan;
487	u_char			channelmap[MISDN_CHMAP_SIZE];
488	struct list_head	bchannels;
489	struct mISDNchannel	*teimgr;
490	struct device		dev;
491};
492
493struct mISDNstack {
494	u_long			status;
495	struct mISDNdevice	*dev;
496	struct task_struct	*thread;
497	struct completion	*notify;
498	wait_queue_head_t	workq;
499	struct sk_buff_head	msgq;
500	struct list_head	layer2;
501	struct mISDNchannel	*layer1;
502	struct mISDNchannel	own;
503	struct mutex		lmutex; /* protect lists */
504	struct mISDN_sock_list	l1sock;
505#ifdef MISDN_MSG_STATS
506	u_int			msg_cnt;
507	u_int			sleep_cnt;
508	u_int			stopped_cnt;
509#endif
510};
511
512typedef	int	(clockctl_func_t)(void *, int);
513
514struct	mISDNclock {
515	struct list_head	list;
516	char			name[64];
517	int			pri;
518	clockctl_func_t		*ctl;
519	void			*priv;
520};
521
522/* global alloc/queue functions */
523
524static inline struct sk_buff *
525mI_alloc_skb(unsigned int len, gfp_t gfp_mask)
526{
527	struct sk_buff	*skb;
528
529	skb = alloc_skb(len + MISDN_HEADER_LEN, gfp_mask);
530	if (likely(skb))
531		skb_reserve(skb, MISDN_HEADER_LEN);
532	return skb;
533}
534
535static inline struct sk_buff *
536_alloc_mISDN_skb(u_int prim, u_int id, u_int len, void *dp, gfp_t gfp_mask)
537{
538	struct sk_buff	*skb = mI_alloc_skb(len, gfp_mask);
539	struct mISDNhead *hh;
540
541	if (!skb)
542		return NULL;
543	if (len)
544		memcpy(skb_put(skb, len), dp, len);
545	hh = mISDN_HEAD_P(skb);
546	hh->prim = prim;
547	hh->id = id;
548	return skb;
549}
550
551static inline void
552_queue_data(struct mISDNchannel *ch, u_int prim,
553    u_int id, u_int len, void *dp, gfp_t gfp_mask)
554{
555	struct sk_buff		*skb;
556
557	if (!ch->peer)
558		return;
559	skb = _alloc_mISDN_skb(prim, id, len, dp, gfp_mask);
560	if (!skb)
561		return;
562	if (ch->recv(ch->peer, skb))
563		dev_kfree_skb(skb);
564}
565
566/* global register/unregister functions */
567
568extern int	mISDN_register_device(struct mISDNdevice *,
569					struct device *parent, char *name);
570extern void	mISDN_unregister_device(struct mISDNdevice *);
571extern int	mISDN_register_Bprotocol(struct Bprotocol *);
572extern void	mISDN_unregister_Bprotocol(struct Bprotocol *);
573extern struct mISDNclock *mISDN_register_clock(char *, int, clockctl_func_t *,
574						void *);
575extern void	mISDN_unregister_clock(struct mISDNclock *);
576
577static inline struct mISDNdevice *dev_to_mISDN(struct device *dev)
578{
579	if (dev)
580		return dev_get_drvdata(dev);
581	else
582		return NULL;
583}
584
585extern void	set_channel_address(struct mISDNchannel *, u_int, u_int);
586extern void	mISDN_clock_update(struct mISDNclock *, int, struct timeval *);
587extern unsigned short mISDN_clock_get(void);
 
588
589#endif /* __KERNEL__ */
590#endif /* mISDNIF_H */