3 * Author Karsten Keil <kkeil@novell.com>
5 * Copyright 2008 by Karsten Keil <kkeil@novell.com>
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.
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.
21 #include <linux/types.h>
22 #include <linux/errno.h>
23 #include <linux/socket.h>
28 * <8 bit> Major version
29 * - changed if any interface become backwards incompatible
31 * <8 bit> Minor version
32 * - changed if any interface is extended but backwards compatible
34 * <16 bit> Release number
35 * - should be incremented on every checkin
37 #define MISDN_MAJOR_VERSION 1
38 #define MISDN_MINOR_VERSION 1
39 #define MISDN_RELEASE 29
41 /* primitives for information exchange
45 * BIT 8 = 1 LAYER private
48 * <8 bit target layer mask>
50 * Layer = 00 is reserved for general commands
55 * Layer = FF is reserved for broadcast commands
58 #define MISDN_CMDMASK 0xff00
59 #define MISDN_LAYERMASK 0x00ff
61 /* generell commands */
62 #define OPEN_CHANNEL 0x0100
63 #define CLOSE_CHANNEL 0x0200
64 #define CONTROL_CHANNEL 0x0300
65 #define CHECK_DATA 0x0400
67 /* layer 2 -> layer 1 */
68 #define PH_ACTIVATE_REQ 0x0101
69 #define PH_DEACTIVATE_REQ 0x0201
70 #define PH_DATA_REQ 0x2001
71 #define MPH_ACTIVATE_REQ 0x0501
72 #define MPH_DEACTIVATE_REQ 0x0601
73 #define MPH_INFORMATION_REQ 0x0701
74 #define PH_CONTROL_REQ 0x0801
76 /* layer 1 -> layer 2 */
77 #define PH_ACTIVATE_IND 0x0102
78 #define PH_ACTIVATE_CNF 0x4102
79 #define PH_DEACTIVATE_IND 0x0202
80 #define PH_DEACTIVATE_CNF 0x4202
81 #define PH_DATA_IND 0x2002
82 #define PH_DATA_E_IND 0x3002
83 #define MPH_ACTIVATE_IND 0x0502
84 #define MPH_DEACTIVATE_IND 0x0602
85 #define MPH_INFORMATION_IND 0x0702
86 #define PH_DATA_CNF 0x6002
87 #define PH_CONTROL_IND 0x0802
88 #define PH_CONTROL_CNF 0x4802
90 /* layer 3 -> layer 2 */
91 #define DL_ESTABLISH_REQ 0x1004
92 #define DL_RELEASE_REQ 0x1104
93 #define DL_DATA_REQ 0x3004
94 #define DL_UNITDATA_REQ 0x3104
95 #define DL_INFORMATION_REQ 0x0004
97 /* layer 2 -> layer 3 */
98 #define DL_ESTABLISH_IND 0x1008
99 #define DL_ESTABLISH_CNF 0x5008
100 #define DL_RELEASE_IND 0x1108
101 #define DL_RELEASE_CNF 0x5108
102 #define DL_DATA_IND 0x3008
103 #define DL_UNITDATA_IND 0x3108
104 #define DL_INFORMATION_IND 0x0008
106 /* intern layer 2 management */
107 #define MDL_ASSIGN_REQ 0x1804
108 #define MDL_ASSIGN_IND 0x1904
109 #define MDL_REMOVE_REQ 0x1A04
110 #define MDL_REMOVE_IND 0x1B04
111 #define MDL_STATUS_UP_IND 0x1C04
112 #define MDL_STATUS_DOWN_IND 0x1D04
113 #define MDL_STATUS_UI_IND 0x1E04
114 #define MDL_ERROR_IND 0x1F04
115 #define MDL_ERROR_RSP 0x5F04
118 #define DL_TIMER200_IND 0x7004
119 #define DL_TIMER203_IND 0x7304
120 #define DL_INTERN_MSG 0x7804
122 /* DL_INFORMATION_IND types */
123 #define DL_INFO_L2_CONNECT 0x0001
124 #define DL_INFO_L2_REMOVED 0x0002
126 /* PH_CONTROL types */
127 /* TOUCH TONE IS 0x20XX XX "0"..."9", "A","B","C","D","*","#" */
128 #define DTMF_TONE_VAL 0x2000
129 #define DTMF_TONE_MASK 0x007F
130 #define DTMF_TONE_START 0x2100
131 #define DTMF_TONE_STOP 0x2200
132 #define DTMF_HFC_COEF 0x4000
133 #define DSP_CONF_JOIN 0x2403
134 #define DSP_CONF_SPLIT 0x2404
135 #define DSP_RECEIVE_OFF 0x2405
136 #define DSP_RECEIVE_ON 0x2406
137 #define DSP_ECHO_ON 0x2407
138 #define DSP_ECHO_OFF 0x2408
139 #define DSP_MIX_ON 0x2409
140 #define DSP_MIX_OFF 0x240a
141 #define DSP_DELAY 0x240b
142 #define DSP_JITTER 0x240c
143 #define DSP_TXDATA_ON 0x240d
144 #define DSP_TXDATA_OFF 0x240e
145 #define DSP_TX_DEJITTER 0x240f
146 #define DSP_TX_DEJ_OFF 0x2410
147 #define DSP_TONE_PATT_ON 0x2411
148 #define DSP_TONE_PATT_OFF 0x2412
149 #define DSP_VOL_CHANGE_TX 0x2413
150 #define DSP_VOL_CHANGE_RX 0x2414
151 #define DSP_BF_ENABLE_KEY 0x2415
152 #define DSP_BF_DISABLE 0x2416
153 #define DSP_BF_ACCEPT 0x2416
154 #define DSP_BF_REJECT 0x2417
155 #define DSP_PIPELINE_CFG 0x2418
156 #define HFC_VOL_CHANGE_TX 0x2601
157 #define HFC_VOL_CHANGE_RX 0x2602
158 #define HFC_SPL_LOOP_ON 0x2603
159 #define HFC_SPL_LOOP_OFF 0x2604
160 /* for T30 FAX and analog modem */
161 #define HW_MOD_FRM 0x4000
162 #define HW_MOD_FRH 0x4001
163 #define HW_MOD_FTM 0x4002
164 #define HW_MOD_FTH 0x4003
165 #define HW_MOD_FTS 0x4004
166 #define HW_MOD_CONNECT 0x4010
167 #define HW_MOD_OK 0x4011
168 #define HW_MOD_NOCARR 0x4012
169 #define HW_MOD_FCERROR 0x4013
170 #define HW_MOD_READY 0x4014
171 #define HW_MOD_LASTDATA 0x4015
173 /* DSP_TONE_PATT_ON parameter */
174 #define TONE_OFF 0x0000
175 #define TONE_GERMAN_DIALTONE 0x0001
176 #define TONE_GERMAN_OLDDIALTONE 0x0002
177 #define TONE_AMERICAN_DIALTONE 0x0003
178 #define TONE_GERMAN_DIALPBX 0x0004
179 #define TONE_GERMAN_OLDDIALPBX 0x0005
180 #define TONE_AMERICAN_DIALPBX 0x0006
181 #define TONE_GERMAN_RINGING 0x0007
182 #define TONE_GERMAN_OLDRINGING 0x0008
183 #define TONE_AMERICAN_RINGPBX 0x000b
184 #define TONE_GERMAN_RINGPBX 0x000c
185 #define TONE_GERMAN_OLDRINGPBX 0x000d
186 #define TONE_AMERICAN_RINGING 0x000e
187 #define TONE_GERMAN_BUSY 0x000f
188 #define TONE_GERMAN_OLDBUSY 0x0010
189 #define TONE_AMERICAN_BUSY 0x0011
190 #define TONE_GERMAN_HANGUP 0x0012
191 #define TONE_GERMAN_OLDHANGUP 0x0013
192 #define TONE_AMERICAN_HANGUP 0x0014
193 #define TONE_SPECIAL_INFO 0x0015
194 #define TONE_GERMAN_GASSENBESETZT 0x0016
195 #define TONE_GERMAN_AUFSCHALTTON 0x0016
197 /* MPH_INFORMATION_IND */
198 #define L1_SIGNAL_LOS_OFF 0x0010
199 #define L1_SIGNAL_LOS_ON 0x0011
200 #define L1_SIGNAL_AIS_OFF 0x0012
201 #define L1_SIGNAL_AIS_ON 0x0013
202 #define L1_SIGNAL_RDI_OFF 0x0014
203 #define L1_SIGNAL_RDI_ON 0x0015
204 #define L1_SIGNAL_SLIP_RX 0x0020
205 #define L1_SIGNAL_SLIP_TX 0x0021
213 #define ISDN_P_NONE 0
214 #define ISDN_P_BASE 0
215 #define ISDN_P_TE_S0 0x01
216 #define ISDN_P_NT_S0 0x02
217 #define ISDN_P_TE_E1 0x03
218 #define ISDN_P_NT_E1 0x04
219 #define ISDN_P_TE_UP0 0x05
220 #define ISDN_P_NT_UP0 0x06
222 #define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \
223 (p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE))
224 #define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \
225 (p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT))
226 #define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0))
227 #define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1))
228 #define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0))
231 #define ISDN_P_LAPD_TE 0x10
232 #define ISDN_P_LAPD_NT 0x11
234 #define ISDN_P_B_MASK 0x1f
235 #define ISDN_P_B_START 0x20
237 #define ISDN_P_B_RAW 0x21
238 #define ISDN_P_B_HDLC 0x22
239 #define ISDN_P_B_X75SLP 0x23
240 #define ISDN_P_B_L2DTMF 0x24
241 #define ISDN_P_B_L2DSP 0x25
242 #define ISDN_P_B_L2DSPHDLC 0x26
243 #define ISDN_P_B_T30_FAX 0x27
244 #define ISDN_P_B_MODEM_ASYNC 0x28
246 #define OPTION_L2_PMX 1
247 #define OPTION_L2_PTP 2
248 #define OPTION_L2_FIXEDTEI 3
249 #define OPTION_L2_CLEANUP 4
250 #define OPTION_L1_HOLD 5
252 /* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */
253 #define MISDN_MAX_IDLEN 20
260 #define MISDN_HEADER_LEN sizeof(struct mISDNhead)
261 #define MAX_DATA_SIZE 2048
262 #define MAX_DATA_MEM (MAX_DATA_SIZE + MISDN_HEADER_LEN)
263 #define MAX_DFRAME_LEN 260
265 #define MISDN_ID_ADDR_MASK 0xFFFF
266 #define MISDN_ID_TEI_MASK 0xFF00
267 #define MISDN_ID_SAPI_MASK 0x00FF
268 #define MISDN_ID_TEI_ANY 0x7F00
270 #define MISDN_ID_ANY 0xFFFF
271 #define MISDN_ID_NONE 0xFFFE
273 #define GROUP_TEI 127
277 #define MISDN_MAX_CHANNEL 127
278 #define MISDN_CHMAP_SIZE ((MISDN_MAX_CHANNEL + 1) >> 3)
282 struct sockaddr_mISDN {
285 unsigned char channel;
290 struct mISDNversion {
293 unsigned short release;
296 struct mISDN_devinfo {
301 u_char channelmap[MISDN_CHMAP_SIZE];
303 char name[MISDN_MAX_IDLEN];
306 struct mISDN_devrename {
308 char name[MISDN_MAX_IDLEN]; /* new name */
311 /* MPH_INFORMATION_REQ payload */
318 struct ph_info_ch ch;
324 struct ph_info_dch dch;
325 struct ph_info_ch bch[];
328 /* timer device ioctl */
329 #define IMADDTIMER _IOR('I', 64, int)
330 #define IMDELTIMER _IOR('I', 65, int)
333 #define IMGETVERSION _IOR('I', 66, int)
334 #define IMGETCOUNT _IOR('I', 67, int)
335 #define IMGETDEVINFO _IOR('I', 68, int)
336 #define IMCTRLREQ _IOR('I', 69, int)
337 #define IMCLEAR_L2 _IOR('I', 70, int)
338 #define IMSETDEVNAME _IOR('I', 71, struct mISDN_devrename)
339 #define IMHOLD_L1 _IOR('I', 72, int)
342 test_channelmap(u_int nr, u_char *map)
344 if (nr <= MISDN_MAX_CHANNEL)
345 return map[nr >> 3] & (1 << (nr & 7));
351 set_channelmap(u_int nr, u_char *map)
353 map[nr >> 3] |= (1 << (nr & 7));
357 clear_channelmap(u_int nr, u_char *map)
359 map[nr >> 3] &= ~(1 << (nr & 7));
362 /* CONTROL_CHANNEL parameters */
363 #define MISDN_CTRL_GETOP 0x0000
364 #define MISDN_CTRL_LOOP 0x0001
365 #define MISDN_CTRL_CONNECT 0x0002
366 #define MISDN_CTRL_DISCONNECT 0x0004
367 #define MISDN_CTRL_RX_BUFFER 0x0008
368 #define MISDN_CTRL_PCMCONNECT 0x0010
369 #define MISDN_CTRL_PCMDISCONNECT 0x0020
370 #define MISDN_CTRL_SETPEER 0x0040
371 #define MISDN_CTRL_UNSETPEER 0x0080
372 #define MISDN_CTRL_RX_OFF 0x0100
373 #define MISDN_CTRL_FILL_EMPTY 0x0200
374 #define MISDN_CTRL_GETPEER 0x0400
375 #define MISDN_CTRL_L1_TIMER3 0x0800
376 #define MISDN_CTRL_HW_FEATURES_OP 0x2000
377 #define MISDN_CTRL_HW_FEATURES 0x2001
378 #define MISDN_CTRL_HFC_OP 0x4000
379 #define MISDN_CTRL_HFC_PCM_CONN 0x4001
380 #define MISDN_CTRL_HFC_PCM_DISC 0x4002
381 #define MISDN_CTRL_HFC_CONF_JOIN 0x4003
382 #define MISDN_CTRL_HFC_CONF_SPLIT 0x4004
383 #define MISDN_CTRL_HFC_RECEIVE_OFF 0x4005
384 #define MISDN_CTRL_HFC_RECEIVE_ON 0x4006
385 #define MISDN_CTRL_HFC_ECHOCAN_ON 0x4007
386 #define MISDN_CTRL_HFC_ECHOCAN_OFF 0x4008
387 #define MISDN_CTRL_HFC_WD_INIT 0x4009
388 #define MISDN_CTRL_HFC_WD_RESET 0x400A
390 /* special RX buffer value for MISDN_CTRL_RX_BUFFER request.p1 is the minimum
391 * buffer size request.p2 the maximum. Using MISDN_CTRL_RX_SIZE_IGNORE will
392 * not change the value, but still read back the actual stetting.
394 #define MISDN_CTRL_RX_SIZE_IGNORE -1
397 #define MISDN_TIME_STAMP 0x0001
399 struct mISDN_ctrl_req {
407 #define MISDN_OPT_ALL 1
408 #define MISDN_OPT_TEIMGR 2
411 #include <linux/list.h>
412 #include <linux/skbuff.h>
413 #include <linux/net.h>
414 #include <net/sock.h>
415 #include <linux/completion.h>
417 #define DEBUG_CORE 0x000000ff
418 #define DEBUG_CORE_FUNC 0x00000002
419 #define DEBUG_SOCKET 0x00000004
420 #define DEBUG_MANAGER 0x00000008
421 #define DEBUG_SEND_ERR 0x00000010
422 #define DEBUG_MSG_THREAD 0x00000020
423 #define DEBUG_QUEUE_FUNC 0x00000040
424 #define DEBUG_L1 0x0000ff00
425 #define DEBUG_L1_FSM 0x00000200
426 #define DEBUG_L2 0x00ff0000
427 #define DEBUG_L2_FSM 0x00020000
428 #define DEBUG_L2_CTRL 0x00040000
429 #define DEBUG_L2_RECV 0x00080000
430 #define DEBUG_L2_TEI 0x00100000
431 #define DEBUG_L2_TEIFSM 0x00200000
432 #define DEBUG_TIMER 0x01000000
433 #define DEBUG_CLOCK 0x02000000
435 #define mISDN_HEAD_P(s) ((struct mISDNhead *)&s->cb[0])
436 #define mISDN_HEAD_PRIM(s) (((struct mISDNhead *)&s->cb[0])->prim)
437 #define mISDN_HEAD_ID(s) (((struct mISDNhead *)&s->cb[0])->id)
441 #define MISDN_BOUND 2
442 #define MISDN_CLOSED 3
451 struct sockaddr_mISDN adr;
452 struct mISDNchannel *ch;
455 typedef int (ctrl_func_t)(struct mISDNchannel *, u_int, void *);
456 typedef int (send_func_t)(struct mISDNchannel *, struct sk_buff *);
457 typedef int (create_func_t)(struct channel_req *);
460 struct list_head list;
463 create_func_t *create;
466 struct mISDNchannel {
467 struct list_head list;
472 struct mISDNstack *st;
473 struct mISDNchannel *peer;
479 struct mISDN_sock_list {
480 struct hlist_head head;
486 struct mISDNchannel ch;
488 struct mISDNdevice *dev;
494 struct mISDNchannel D;
499 u_char channelmap[MISDN_CHMAP_SIZE];
500 struct list_head bchannels;
501 struct mISDNchannel *teimgr;
507 struct mISDNdevice *dev;
508 struct task_struct *thread;
509 struct completion *notify;
510 wait_queue_head_t workq;
511 struct sk_buff_head msgq;
512 struct list_head layer2;
513 struct mISDNchannel *layer1;
514 struct mISDNchannel own;
515 struct mutex lmutex; /* protect lists */
516 struct mISDN_sock_list l1sock;
517 #ifdef MISDN_MSG_STATS
524 typedef int (clockctl_func_t)(void *, int);
527 struct list_head list;
530 clockctl_func_t *ctl;
534 /* global alloc/queue functions */
536 static inline struct sk_buff *
537 mI_alloc_skb(unsigned int len, gfp_t gfp_mask)
541 skb = alloc_skb(len + MISDN_HEADER_LEN, gfp_mask);
543 skb_reserve(skb, MISDN_HEADER_LEN);
547 static inline struct sk_buff *
548 _alloc_mISDN_skb(u_int prim, u_int id, u_int len, void *dp, gfp_t gfp_mask)
550 struct sk_buff *skb = mI_alloc_skb(len, gfp_mask);
551 struct mISDNhead *hh;
556 skb_put_data(skb, dp, len);
557 hh = mISDN_HEAD_P(skb);
564 _queue_data(struct mISDNchannel *ch, u_int prim,
565 u_int id, u_int len, void *dp, gfp_t gfp_mask)
571 skb = _alloc_mISDN_skb(prim, id, len, dp, gfp_mask);
574 if (ch->recv(ch->peer, skb))
578 /* global register/unregister functions */
580 extern int mISDN_register_device(struct mISDNdevice *,
581 struct device *parent, char *name);
582 extern void mISDN_unregister_device(struct mISDNdevice *);
583 extern int mISDN_register_Bprotocol(struct Bprotocol *);
584 extern void mISDN_unregister_Bprotocol(struct Bprotocol *);
585 extern struct mISDNclock *mISDN_register_clock(char *, int, clockctl_func_t *,
587 extern void mISDN_unregister_clock(struct mISDNclock *);
589 static inline struct mISDNdevice *dev_to_mISDN(struct device *dev)
592 return dev_get_drvdata(dev);
597 extern void set_channel_address(struct mISDNchannel *, u_int, u_int);
598 extern void mISDN_clock_update(struct mISDNclock *, int, ktime_t *);
599 extern unsigned short mISDN_clock_get(void);
600 extern const char *mISDNDevName4ch(struct mISDNchannel *);
602 #endif /* __KERNEL__ */
603 #endif /* mISDNIF_H */