Pablo Neira Ayuso | 0ba77d5 | 2011-06-05 18:32:44 +0200 | [diff] [blame] | 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 | #ifdef linux |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/errno.h> |
| 25 | #include <linux/socket.h> |
| 26 | #else |
| 27 | #include <sys/types.h> |
| 28 | #include <sys/errno.h> |
| 29 | #include <sys/socket.h> |
| 30 | #endif |
| 31 | |
| 32 | /* |
| 33 | * ABI Version 32 bit |
| 34 | * |
| 35 | * <8 bit> Major version |
| 36 | * - changed if any interface become backwards incompatible |
| 37 | * |
| 38 | * <8 bit> Minor version |
| 39 | * - changed if any interface is extended but backwards compatible |
| 40 | * |
| 41 | * <16 bit> Release number |
| 42 | * - should be incremented on every checkin |
| 43 | */ |
| 44 | #define MISDN_MAJOR_VERSION 1 |
| 45 | #define MISDN_MINOR_VERSION 1 |
| 46 | #define MISDN_RELEASE 20 |
| 47 | |
| 48 | /* primitives for information exchange |
| 49 | * generell format |
| 50 | * <16 bit 0 > |
| 51 | * <8 bit command> |
| 52 | * BIT 8 = 1 LAYER private |
| 53 | * BIT 7 = 1 answer |
| 54 | * BIT 6 = 1 DATA |
| 55 | * <8 bit target layer mask> |
| 56 | * |
| 57 | * Layer = 00 is reserved for general commands |
| 58 | Layer = 01 L2 -> HW |
| 59 | Layer = 02 HW -> L2 |
| 60 | Layer = 04 L3 -> L2 |
| 61 | Layer = 08 L2 -> L3 |
| 62 | * Layer = FF is reserved for broadcast commands |
| 63 | */ |
| 64 | |
| 65 | #define MISDN_CMDMASK 0xff00 |
| 66 | #define MISDN_LAYERMASK 0x00ff |
| 67 | |
| 68 | /* generell commands */ |
| 69 | #define OPEN_CHANNEL 0x0100 |
| 70 | #define CLOSE_CHANNEL 0x0200 |
| 71 | #define CONTROL_CHANNEL 0x0300 |
| 72 | #define CHECK_DATA 0x0400 |
| 73 | |
| 74 | /* layer 2 -> layer 1 */ |
| 75 | #define PH_ACTIVATE_REQ 0x0101 |
| 76 | #define PH_DEACTIVATE_REQ 0x0201 |
| 77 | #define PH_DATA_REQ 0x2001 |
| 78 | #define MPH_ACTIVATE_REQ 0x0501 |
| 79 | #define MPH_DEACTIVATE_REQ 0x0601 |
| 80 | #define MPH_INFORMATION_REQ 0x0701 |
| 81 | #define PH_CONTROL_REQ 0x0801 |
| 82 | |
| 83 | /* layer 1 -> layer 2 */ |
| 84 | #define PH_ACTIVATE_IND 0x0102 |
| 85 | #define PH_ACTIVATE_CNF 0x4102 |
| 86 | #define PH_DEACTIVATE_IND 0x0202 |
| 87 | #define PH_DEACTIVATE_CNF 0x4202 |
| 88 | #define PH_DATA_IND 0x2002 |
| 89 | #define PH_DATA_E_IND 0x3002 |
| 90 | #define MPH_ACTIVATE_IND 0x0502 |
| 91 | #define MPH_DEACTIVATE_IND 0x0602 |
| 92 | #define MPH_INFORMATION_IND 0x0702 |
| 93 | #define PH_DATA_CNF 0x6002 |
| 94 | #define PH_CONTROL_IND 0x0802 |
| 95 | #define PH_CONTROL_CNF 0x4802 |
| 96 | |
| 97 | /* layer 3 -> layer 2 */ |
| 98 | #define DL_ESTABLISH_REQ 0x1004 |
| 99 | #define DL_RELEASE_REQ 0x1104 |
| 100 | #define DL_DATA_REQ 0x3004 |
| 101 | #define DL_UNITDATA_REQ 0x3104 |
| 102 | #define DL_INFORMATION_REQ 0x0004 |
| 103 | |
| 104 | /* layer 2 -> layer 3 */ |
| 105 | #define DL_ESTABLISH_IND 0x1008 |
| 106 | #define DL_ESTABLISH_CNF 0x5008 |
| 107 | #define DL_RELEASE_IND 0x1108 |
| 108 | #define DL_RELEASE_CNF 0x5108 |
| 109 | #define DL_DATA_IND 0x3008 |
| 110 | #define DL_UNITDATA_IND 0x3108 |
| 111 | #define DL_INFORMATION_IND 0x0008 |
| 112 | |
| 113 | /* intern layer 2 managment */ |
| 114 | #define MDL_ASSIGN_REQ 0x1804 |
| 115 | #define MDL_ASSIGN_IND 0x1904 |
| 116 | #define MDL_REMOVE_REQ 0x1A04 |
| 117 | #define MDL_REMOVE_IND 0x1B04 |
| 118 | #define MDL_STATUS_UP_IND 0x1C04 |
| 119 | #define MDL_STATUS_DOWN_IND 0x1D04 |
| 120 | #define MDL_STATUS_UI_IND 0x1E04 |
| 121 | #define MDL_ERROR_IND 0x1F04 |
| 122 | #define MDL_ERROR_RSP 0x5F04 |
| 123 | |
| 124 | /* DL_INFORMATION_IND types */ |
| 125 | #define DL_INFO_L2_CONNECT 0x0001 |
| 126 | #define DL_INFO_L2_REMOVED 0x0002 |
| 127 | |
| 128 | /* PH_CONTROL types */ |
| 129 | /* TOUCH TONE IS 0x20XX XX "0"..."9", "A","B","C","D","*","#" */ |
| 130 | #define DTMF_TONE_VAL 0x2000 |
| 131 | #define DTMF_TONE_MASK 0x007F |
| 132 | #define DTMF_TONE_START 0x2100 |
| 133 | #define DTMF_TONE_STOP 0x2200 |
| 134 | #define DTMF_HFC_COEF 0x4000 |
| 135 | #define DSP_CONF_JOIN 0x2403 |
| 136 | #define DSP_CONF_SPLIT 0x2404 |
| 137 | #define DSP_RECEIVE_OFF 0x2405 |
| 138 | #define DSP_RECEIVE_ON 0x2406 |
| 139 | #define DSP_ECHO_ON 0x2407 |
| 140 | #define DSP_ECHO_OFF 0x2408 |
| 141 | #define DSP_MIX_ON 0x2409 |
| 142 | #define DSP_MIX_OFF 0x240a |
| 143 | #define DSP_DELAY 0x240b |
| 144 | #define DSP_JITTER 0x240c |
| 145 | #define DSP_TXDATA_ON 0x240d |
| 146 | #define DSP_TXDATA_OFF 0x240e |
| 147 | #define DSP_TX_DEJITTER 0x240f |
| 148 | #define DSP_TX_DEJ_OFF 0x2410 |
| 149 | #define DSP_TONE_PATT_ON 0x2411 |
| 150 | #define DSP_TONE_PATT_OFF 0x2412 |
| 151 | #define DSP_VOL_CHANGE_TX 0x2413 |
| 152 | #define DSP_VOL_CHANGE_RX 0x2414 |
| 153 | #define DSP_BF_ENABLE_KEY 0x2415 |
| 154 | #define DSP_BF_DISABLE 0x2416 |
| 155 | #define DSP_BF_ACCEPT 0x2416 |
| 156 | #define DSP_BF_REJECT 0x2417 |
| 157 | #define DSP_PIPELINE_CFG 0x2418 |
| 158 | #define HFC_VOL_CHANGE_TX 0x2601 |
| 159 | #define HFC_VOL_CHANGE_RX 0x2602 |
| 160 | #define HFC_SPL_LOOP_ON 0x2603 |
| 161 | #define HFC_SPL_LOOP_OFF 0x2604 |
| 162 | |
| 163 | /* DSP_TONE_PATT_ON parameter */ |
| 164 | #define TONE_OFF 0x0000 |
| 165 | #define TONE_GERMAN_DIALTONE 0x0001 |
| 166 | #define TONE_GERMAN_OLDDIALTONE 0x0002 |
| 167 | #define TONE_AMERICAN_DIALTONE 0x0003 |
| 168 | #define TONE_GERMAN_DIALPBX 0x0004 |
| 169 | #define TONE_GERMAN_OLDDIALPBX 0x0005 |
| 170 | #define TONE_AMERICAN_DIALPBX 0x0006 |
| 171 | #define TONE_GERMAN_RINGING 0x0007 |
| 172 | #define TONE_GERMAN_OLDRINGING 0x0008 |
| 173 | #define TONE_AMERICAN_RINGPBX 0x000b |
| 174 | #define TONE_GERMAN_RINGPBX 0x000c |
| 175 | #define TONE_GERMAN_OLDRINGPBX 0x000d |
| 176 | #define TONE_AMERICAN_RINGING 0x000e |
| 177 | #define TONE_GERMAN_BUSY 0x000f |
| 178 | #define TONE_GERMAN_OLDBUSY 0x0010 |
| 179 | #define TONE_AMERICAN_BUSY 0x0011 |
| 180 | #define TONE_GERMAN_HANGUP 0x0012 |
| 181 | #define TONE_GERMAN_OLDHANGUP 0x0013 |
| 182 | #define TONE_AMERICAN_HANGUP 0x0014 |
| 183 | #define TONE_SPECIAL_INFO 0x0015 |
| 184 | #define TONE_GERMAN_GASSENBESETZT 0x0016 |
| 185 | #define TONE_GERMAN_AUFSCHALTTON 0x0016 |
| 186 | |
| 187 | /* MPH_INFORMATION_IND */ |
| 188 | #define L1_SIGNAL_LOS_OFF 0x0010 |
| 189 | #define L1_SIGNAL_LOS_ON 0x0011 |
| 190 | #define L1_SIGNAL_AIS_OFF 0x0012 |
| 191 | #define L1_SIGNAL_AIS_ON 0x0013 |
| 192 | #define L1_SIGNAL_RDI_OFF 0x0014 |
| 193 | #define L1_SIGNAL_RDI_ON 0x0015 |
| 194 | #define L1_SIGNAL_SLIP_RX 0x0020 |
| 195 | #define L1_SIGNAL_SLIP_TX 0x0021 |
| 196 | |
| 197 | /* |
| 198 | * protocol ids |
| 199 | * D channel 1-31 |
| 200 | * B channel 33 - 63 |
| 201 | */ |
| 202 | |
| 203 | #define ISDN_P_NONE 0 |
| 204 | #define ISDN_P_BASE 0 |
| 205 | #define ISDN_P_TE_S0 0x01 |
| 206 | #define ISDN_P_NT_S0 0x02 |
| 207 | #define ISDN_P_TE_E1 0x03 |
| 208 | #define ISDN_P_NT_E1 0x04 |
| 209 | #define ISDN_P_TE_UP0 0x05 |
| 210 | #define ISDN_P_NT_UP0 0x06 |
| 211 | |
| 212 | #define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \ |
| 213 | (p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE)) |
| 214 | #define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \ |
| 215 | (p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT)) |
| 216 | #define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0)) |
| 217 | #define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1)) |
| 218 | #define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0)) |
| 219 | |
| 220 | |
| 221 | #define ISDN_P_LAPD_TE 0x10 |
| 222 | #define ISDN_P_LAPD_NT 0x11 |
| 223 | |
| 224 | #define ISDN_P_B_MASK 0x1f |
| 225 | #define ISDN_P_B_START 0x20 |
| 226 | |
| 227 | #define ISDN_P_B_RAW 0x21 |
| 228 | #define ISDN_P_B_HDLC 0x22 |
| 229 | #define ISDN_P_B_X75SLP 0x23 |
| 230 | #define ISDN_P_B_L2DTMF 0x24 |
| 231 | #define ISDN_P_B_L2DSP 0x25 |
| 232 | #define ISDN_P_B_L2DSPHDLC 0x26 |
| 233 | |
| 234 | #define OPTION_L2_PMX 1 |
| 235 | #define OPTION_L2_PTP 2 |
| 236 | #define OPTION_L2_FIXEDTEI 3 |
| 237 | #define OPTION_L2_CLEANUP 4 |
| 238 | |
| 239 | /* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */ |
| 240 | #define MISDN_MAX_IDLEN 20 |
| 241 | |
| 242 | struct mISDNhead { |
| 243 | unsigned int prim; |
| 244 | unsigned int id; |
| 245 | } __attribute__((packed)); |
| 246 | |
| 247 | #define MISDN_HEADER_LEN sizeof(struct mISDNhead) |
| 248 | #define MAX_DATA_SIZE 2048 |
| 249 | #define MAX_DATA_MEM (MAX_DATA_SIZE + MISDN_HEADER_LEN) |
| 250 | #define MAX_DFRAME_LEN 260 |
| 251 | |
| 252 | #define MISDN_ID_ADDR_MASK 0xFFFF |
| 253 | #define MISDN_ID_TEI_MASK 0xFF00 |
| 254 | #define MISDN_ID_SAPI_MASK 0x00FF |
| 255 | #define MISDN_ID_TEI_ANY 0x7F00 |
| 256 | |
| 257 | #define MISDN_ID_ANY 0xFFFF |
| 258 | #define MISDN_ID_NONE 0xFFFE |
| 259 | |
| 260 | #define GROUP_TEI 127 |
| 261 | #define TEI_SAPI 63 |
| 262 | #define CTRL_SAPI 0 |
| 263 | |
| 264 | #define MISDN_MAX_CHANNEL 127 |
| 265 | #define MISDN_CHMAP_SIZE ((MISDN_MAX_CHANNEL + 1) >> 3) |
| 266 | |
| 267 | #define SOL_MISDN 0 |
| 268 | |
| 269 | struct sockaddr_mISDN { |
| 270 | sa_family_t family; |
| 271 | unsigned char dev; |
| 272 | unsigned char channel; |
| 273 | unsigned char sapi; |
| 274 | unsigned char tei; |
| 275 | }; |
| 276 | |
| 277 | struct mISDNversion { |
| 278 | unsigned char major; |
| 279 | unsigned char minor; |
| 280 | unsigned short release; |
| 281 | }; |
| 282 | |
| 283 | #define MAX_DEVICE_ID 63 |
| 284 | |
| 285 | struct mISDN_devinfo { |
| 286 | u_int id; |
| 287 | u_int Dprotocols; |
| 288 | u_int Bprotocols; |
| 289 | u_int protocol; |
| 290 | u_char channelmap[MISDN_CHMAP_SIZE]; |
| 291 | u_int nrbchan; |
| 292 | char name[MISDN_MAX_IDLEN]; |
| 293 | }; |
| 294 | |
| 295 | struct mISDN_devrename { |
| 296 | u_int id; |
| 297 | char name[MISDN_MAX_IDLEN]; |
| 298 | }; |
| 299 | |
| 300 | struct ph_info_ch { |
| 301 | int32_t protocol; |
| 302 | int64_t Flags; |
| 303 | }; |
| 304 | |
| 305 | struct ph_info_dch { |
| 306 | struct ph_info_ch ch; |
| 307 | int16_t state; |
| 308 | int16_t num_bch; |
| 309 | }; |
| 310 | |
| 311 | struct ph_info { |
| 312 | struct ph_info_dch dch; |
| 313 | struct ph_info_ch bch[]; |
| 314 | }; |
| 315 | |
| 316 | /* timer device ioctl */ |
| 317 | #define IMADDTIMER _IOR('I', 64, int) |
| 318 | #define IMDELTIMER _IOR('I', 65, int) |
| 319 | /* socket ioctls */ |
| 320 | #define IMGETVERSION _IOR('I', 66, int) |
| 321 | #define IMGETCOUNT _IOR('I', 67, int) |
| 322 | #define IMGETDEVINFO _IOR('I', 68, int) |
| 323 | #define IMCTRLREQ _IOR('I', 69, int) |
| 324 | #define IMCLEAR_L2 _IOR('I', 70, int) |
| 325 | #define IMSETDEVNAME _IOR('I', 71, struct mISDN_devrename) |
| 326 | |
| 327 | static inline int |
| 328 | test_channelmap(u_int nr, u_char *map) |
| 329 | { |
| 330 | if (nr <= MISDN_MAX_CHANNEL) |
| 331 | return map[nr >> 3] & (1 << (nr & 7)); |
| 332 | else |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | static inline void |
| 337 | set_channelmap(u_int nr, u_char *map) |
| 338 | { |
| 339 | map[nr >> 3] |= (1 << (nr & 7)); |
| 340 | } |
| 341 | |
| 342 | static inline void |
| 343 | clear_channelmap(u_int nr, u_char *map) |
| 344 | { |
| 345 | map[nr >> 3] &= ~(1 << (nr & 7)); |
| 346 | } |
| 347 | |
| 348 | /* CONTROL_CHANNEL parameters */ |
| 349 | #define MISDN_CTRL_GETOP 0x0000 |
| 350 | #define MISDN_CTRL_LOOP 0x0001 |
| 351 | #define MISDN_CTRL_CONNECT 0x0002 |
| 352 | #define MISDN_CTRL_DISCONNECT 0x0004 |
| 353 | #define MISDN_CTRL_PCMCONNECT 0x0010 |
| 354 | #define MISDN_CTRL_PCMDISCONNECT 0x0020 |
| 355 | #define MISDN_CTRL_SETPEER 0x0040 |
| 356 | #define MISDN_CTRL_UNSETPEER 0x0080 |
| 357 | #define MISDN_CTRL_RX_OFF 0x0100 |
| 358 | #define MISDN_CTRL_FILL_EMPTY 0x0200 |
| 359 | #define MISDN_CTRL_GETPEER 0x0400 |
| 360 | #define MISDN_CTRL_HW_FEATURES_OP 0x2000 |
| 361 | #define MISDN_CTRL_HW_FEATURES 0x2001 |
| 362 | #define MISDN_CTRL_HFC_OP 0x4000 |
| 363 | #define MISDN_CTRL_HFC_PCM_CONN 0x4001 |
| 364 | #define MISDN_CTRL_HFC_PCM_DISC 0x4002 |
| 365 | #define MISDN_CTRL_HFC_CONF_JOIN 0x4003 |
| 366 | #define MISDN_CTRL_HFC_CONF_SPLIT 0x4004 |
| 367 | #define MISDN_CTRL_HFC_RECEIVE_OFF 0x4005 |
| 368 | #define MISDN_CTRL_HFC_RECEIVE_ON 0x4006 |
| 369 | #define MISDN_CTRL_HFC_ECHOCAN_ON 0x4007 |
| 370 | #define MISDN_CTRL_HFC_ECHOCAN_OFF 0x4008 |
| 371 | |
| 372 | |
| 373 | /* socket options */ |
| 374 | #define MISDN_TIME_STAMP 0x0001 |
| 375 | |
| 376 | struct mISDN_ctrl_req { |
| 377 | int op; |
| 378 | int channel; |
| 379 | int p1; |
| 380 | int p2; |
| 381 | }; |
| 382 | |
| 383 | /* muxer options */ |
| 384 | #define MISDN_OPT_ALL 1 |
| 385 | #define MISDN_OPT_TEIMGR 2 |
| 386 | |
| 387 | #endif /* mISDNIF_H */ |