Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +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 | #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 |
Matthias Urlichs | 8b6015f | 2008-08-12 10:12:09 +0200 | [diff] [blame] | 39 | #define MISDN_MINOR_VERSION 1 |
| 40 | #define MISDN_RELEASE 20 |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 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 |
Martin Bachem | 1f28fa19 | 2008-09-03 15:17:45 +0200 | [diff] [blame] | 83 | #define PH_DATA_E_IND 0x3002 |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 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 managment */ |
| 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 | |
| 157 | /* DSP_TONE_PATT_ON parameter */ |
| 158 | #define TONE_OFF 0x0000 |
| 159 | #define TONE_GERMAN_DIALTONE 0x0001 |
| 160 | #define TONE_GERMAN_OLDDIALTONE 0x0002 |
| 161 | #define TONE_AMERICAN_DIALTONE 0x0003 |
| 162 | #define TONE_GERMAN_DIALPBX 0x0004 |
| 163 | #define TONE_GERMAN_OLDDIALPBX 0x0005 |
| 164 | #define TONE_AMERICAN_DIALPBX 0x0006 |
| 165 | #define TONE_GERMAN_RINGING 0x0007 |
| 166 | #define TONE_GERMAN_OLDRINGING 0x0008 |
| 167 | #define TONE_AMERICAN_RINGPBX 0x000b |
| 168 | #define TONE_GERMAN_RINGPBX 0x000c |
| 169 | #define TONE_GERMAN_OLDRINGPBX 0x000d |
| 170 | #define TONE_AMERICAN_RINGING 0x000e |
| 171 | #define TONE_GERMAN_BUSY 0x000f |
| 172 | #define TONE_GERMAN_OLDBUSY 0x0010 |
| 173 | #define TONE_AMERICAN_BUSY 0x0011 |
| 174 | #define TONE_GERMAN_HANGUP 0x0012 |
| 175 | #define TONE_GERMAN_OLDHANGUP 0x0013 |
| 176 | #define TONE_AMERICAN_HANGUP 0x0014 |
| 177 | #define TONE_SPECIAL_INFO 0x0015 |
| 178 | #define TONE_GERMAN_GASSENBESETZT 0x0016 |
| 179 | #define TONE_GERMAN_AUFSCHALTTON 0x0016 |
| 180 | |
| 181 | /* MPH_INFORMATION_IND */ |
| 182 | #define L1_SIGNAL_LOS_OFF 0x0010 |
| 183 | #define L1_SIGNAL_LOS_ON 0x0011 |
| 184 | #define L1_SIGNAL_AIS_OFF 0x0012 |
| 185 | #define L1_SIGNAL_AIS_ON 0x0013 |
| 186 | #define L1_SIGNAL_RDI_OFF 0x0014 |
| 187 | #define L1_SIGNAL_RDI_ON 0x0015 |
| 188 | #define L1_SIGNAL_SLIP_RX 0x0020 |
| 189 | #define L1_SIGNAL_SLIP_TX 0x0021 |
| 190 | |
| 191 | /* |
| 192 | * protocol ids |
| 193 | * D channel 1-31 |
| 194 | * B channel 33 - 63 |
| 195 | */ |
| 196 | |
| 197 | #define ISDN_P_NONE 0 |
| 198 | #define ISDN_P_BASE 0 |
| 199 | #define ISDN_P_TE_S0 0x01 |
| 200 | #define ISDN_P_NT_S0 0x02 |
| 201 | #define ISDN_P_TE_E1 0x03 |
| 202 | #define ISDN_P_NT_E1 0x04 |
Martin Bachem | 02282ee | 2008-09-08 15:57:48 +0200 | [diff] [blame] | 203 | #define ISDN_P_TE_UP0 0x05 |
| 204 | #define ISDN_P_NT_UP0 0x06 |
| 205 | |
| 206 | #define IS_ISDN_P_TE(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_TE_E1) || \ |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 207 | (p == ISDN_P_TE_UP0) || (p == ISDN_P_LAPD_TE)) |
Martin Bachem | 02282ee | 2008-09-08 15:57:48 +0200 | [diff] [blame] | 208 | #define IS_ISDN_P_NT(p) ((p == ISDN_P_NT_S0) || (p == ISDN_P_NT_E1) || \ |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 209 | (p == ISDN_P_NT_UP0) || (p == ISDN_P_LAPD_NT)) |
Martin Bachem | 02282ee | 2008-09-08 15:57:48 +0200 | [diff] [blame] | 210 | #define IS_ISDN_P_S0(p) ((p == ISDN_P_TE_S0) || (p == ISDN_P_NT_S0)) |
| 211 | #define IS_ISDN_P_E1(p) ((p == ISDN_P_TE_E1) || (p == ISDN_P_NT_E1)) |
| 212 | #define IS_ISDN_P_UP0(p) ((p == ISDN_P_TE_UP0) || (p == ISDN_P_NT_UP0)) |
| 213 | |
| 214 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 215 | #define ISDN_P_LAPD_TE 0x10 |
| 216 | #define ISDN_P_LAPD_NT 0x11 |
| 217 | |
| 218 | #define ISDN_P_B_MASK 0x1f |
| 219 | #define ISDN_P_B_START 0x20 |
| 220 | |
| 221 | #define ISDN_P_B_RAW 0x21 |
| 222 | #define ISDN_P_B_HDLC 0x22 |
| 223 | #define ISDN_P_B_X75SLP 0x23 |
| 224 | #define ISDN_P_B_L2DTMF 0x24 |
| 225 | #define ISDN_P_B_L2DSP 0x25 |
| 226 | #define ISDN_P_B_L2DSPHDLC 0x26 |
| 227 | |
| 228 | #define OPTION_L2_PMX 1 |
| 229 | #define OPTION_L2_PTP 2 |
| 230 | #define OPTION_L2_FIXEDTEI 3 |
| 231 | #define OPTION_L2_CLEANUP 4 |
| 232 | |
| 233 | /* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */ |
| 234 | #define MISDN_MAX_IDLEN 20 |
| 235 | |
| 236 | struct mISDNhead { |
| 237 | unsigned int prim; |
| 238 | unsigned int id; |
| 239 | } __attribute__((packed)); |
| 240 | |
| 241 | #define MISDN_HEADER_LEN sizeof(struct mISDNhead) |
| 242 | #define MAX_DATA_SIZE 2048 |
| 243 | #define MAX_DATA_MEM (MAX_DATA_SIZE + MISDN_HEADER_LEN) |
| 244 | #define MAX_DFRAME_LEN 260 |
| 245 | |
| 246 | #define MISDN_ID_ADDR_MASK 0xFFFF |
| 247 | #define MISDN_ID_TEI_MASK 0xFF00 |
| 248 | #define MISDN_ID_SAPI_MASK 0x00FF |
| 249 | #define MISDN_ID_TEI_ANY 0x7F00 |
| 250 | |
| 251 | #define MISDN_ID_ANY 0xFFFF |
| 252 | #define MISDN_ID_NONE 0xFFFE |
| 253 | |
| 254 | #define GROUP_TEI 127 |
| 255 | #define TEI_SAPI 63 |
| 256 | #define CTRL_SAPI 0 |
| 257 | |
Karsten Keil | ff4cc1d | 2008-07-30 18:26:58 +0200 | [diff] [blame] | 258 | #define MISDN_MAX_CHANNEL 127 |
| 259 | #define MISDN_CHMAP_SIZE ((MISDN_MAX_CHANNEL + 1) >> 3) |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 260 | |
| 261 | #define SOL_MISDN 0 |
| 262 | |
| 263 | struct sockaddr_mISDN { |
| 264 | sa_family_t family; |
| 265 | unsigned char dev; |
| 266 | unsigned char channel; |
| 267 | unsigned char sapi; |
| 268 | unsigned char tei; |
| 269 | }; |
| 270 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 271 | struct mISDNversion { |
| 272 | unsigned char major; |
| 273 | unsigned char minor; |
| 274 | unsigned short release; |
| 275 | }; |
| 276 | |
| 277 | struct mISDN_devinfo { |
| 278 | u_int id; |
| 279 | u_int Dprotocols; |
| 280 | u_int Bprotocols; |
| 281 | u_int protocol; |
Karsten Keil | ff4cc1d | 2008-07-30 18:26:58 +0200 | [diff] [blame] | 282 | u_char channelmap[MISDN_CHMAP_SIZE]; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 283 | u_int nrbchan; |
| 284 | char name[MISDN_MAX_IDLEN]; |
| 285 | }; |
| 286 | |
Matthias Urlichs | 8b6015f | 2008-08-12 10:12:09 +0200 | [diff] [blame] | 287 | struct mISDN_devrename { |
| 288 | u_int id; |
| 289 | char name[MISDN_MAX_IDLEN]; /* new name */ |
| 290 | }; |
| 291 | |
Martin Bachem | 3f75e84 | 2008-11-04 14:11:22 +0100 | [diff] [blame] | 292 | /* MPH_INFORMATION_REQ payload */ |
| 293 | struct ph_info_ch { |
| 294 | __u32 protocol; |
| 295 | __u64 Flags; |
| 296 | }; |
| 297 | |
| 298 | struct ph_info_dch { |
| 299 | struct ph_info_ch ch; |
| 300 | __u16 state; |
| 301 | __u16 num_bch; |
| 302 | }; |
| 303 | |
| 304 | struct ph_info { |
| 305 | struct ph_info_dch dch; |
| 306 | struct ph_info_ch bch[]; |
| 307 | }; |
| 308 | |
Matthias Urlichs | 8b6015f | 2008-08-12 10:12:09 +0200 | [diff] [blame] | 309 | /* timer device ioctl */ |
| 310 | #define IMADDTIMER _IOR('I', 64, int) |
| 311 | #define IMDELTIMER _IOR('I', 65, int) |
| 312 | |
| 313 | /* socket ioctls */ |
| 314 | #define IMGETVERSION _IOR('I', 66, int) |
| 315 | #define IMGETCOUNT _IOR('I', 67, int) |
| 316 | #define IMGETDEVINFO _IOR('I', 68, int) |
| 317 | #define IMCTRLREQ _IOR('I', 69, int) |
| 318 | #define IMCLEAR_L2 _IOR('I', 70, int) |
| 319 | #define IMSETDEVNAME _IOR('I', 71, struct mISDN_devrename) |
| 320 | |
Karsten Keil | ff4cc1d | 2008-07-30 18:26:58 +0200 | [diff] [blame] | 321 | static inline int |
| 322 | test_channelmap(u_int nr, u_char *map) |
| 323 | { |
| 324 | if (nr <= MISDN_MAX_CHANNEL) |
| 325 | return map[nr >> 3] & (1 << (nr & 7)); |
| 326 | else |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static inline void |
| 331 | set_channelmap(u_int nr, u_char *map) |
| 332 | { |
| 333 | map[nr >> 3] |= (1 << (nr & 7)); |
| 334 | } |
| 335 | |
| 336 | static inline void |
| 337 | clear_channelmap(u_int nr, u_char *map) |
| 338 | { |
| 339 | map[nr >> 3] &= ~(1 << (nr & 7)); |
| 340 | } |
| 341 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 342 | /* CONTROL_CHANNEL parameters */ |
| 343 | #define MISDN_CTRL_GETOP 0x0000 |
| 344 | #define MISDN_CTRL_LOOP 0x0001 |
| 345 | #define MISDN_CTRL_CONNECT 0x0002 |
| 346 | #define MISDN_CTRL_DISCONNECT 0x0004 |
| 347 | #define MISDN_CTRL_PCMCONNECT 0x0010 |
| 348 | #define MISDN_CTRL_PCMDISCONNECT 0x0020 |
| 349 | #define MISDN_CTRL_SETPEER 0x0040 |
| 350 | #define MISDN_CTRL_UNSETPEER 0x0080 |
| 351 | #define MISDN_CTRL_RX_OFF 0x0100 |
Andreas Eversberg | 8dd2f36 | 2008-08-02 22:51:52 +0200 | [diff] [blame] | 352 | #define MISDN_CTRL_FILL_EMPTY 0x0200 |
Andreas Eversberg | 1b4d331 | 2008-09-14 12:30:18 +0200 | [diff] [blame] | 353 | #define MISDN_CTRL_GETPEER 0x0400 |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 354 | #define MISDN_CTRL_HW_FEATURES_OP 0x2000 |
| 355 | #define MISDN_CTRL_HW_FEATURES 0x2001 |
| 356 | #define MISDN_CTRL_HFC_OP 0x4000 |
| 357 | #define MISDN_CTRL_HFC_PCM_CONN 0x4001 |
| 358 | #define MISDN_CTRL_HFC_PCM_DISC 0x4002 |
| 359 | #define MISDN_CTRL_HFC_CONF_JOIN 0x4003 |
| 360 | #define MISDN_CTRL_HFC_CONF_SPLIT 0x4004 |
| 361 | #define MISDN_CTRL_HFC_RECEIVE_OFF 0x4005 |
| 362 | #define MISDN_CTRL_HFC_RECEIVE_ON 0x4006 |
| 363 | #define MISDN_CTRL_HFC_ECHOCAN_ON 0x4007 |
| 364 | #define MISDN_CTRL_HFC_ECHOCAN_OFF 0x4008 |
| 365 | |
| 366 | |
| 367 | /* socket options */ |
| 368 | #define MISDN_TIME_STAMP 0x0001 |
| 369 | |
| 370 | struct mISDN_ctrl_req { |
| 371 | int op; |
| 372 | int channel; |
| 373 | int p1; |
| 374 | int p2; |
| 375 | }; |
| 376 | |
| 377 | /* muxer options */ |
| 378 | #define MISDN_OPT_ALL 1 |
| 379 | #define MISDN_OPT_TEIMGR 2 |
| 380 | |
| 381 | #ifdef __KERNEL__ |
| 382 | #include <linux/list.h> |
| 383 | #include <linux/skbuff.h> |
| 384 | #include <linux/net.h> |
| 385 | #include <net/sock.h> |
| 386 | #include <linux/completion.h> |
| 387 | |
| 388 | #define DEBUG_CORE 0x000000ff |
| 389 | #define DEBUG_CORE_FUNC 0x00000002 |
| 390 | #define DEBUG_SOCKET 0x00000004 |
| 391 | #define DEBUG_MANAGER 0x00000008 |
| 392 | #define DEBUG_SEND_ERR 0x00000010 |
| 393 | #define DEBUG_MSG_THREAD 0x00000020 |
| 394 | #define DEBUG_QUEUE_FUNC 0x00000040 |
| 395 | #define DEBUG_L1 0x0000ff00 |
| 396 | #define DEBUG_L1_FSM 0x00000200 |
| 397 | #define DEBUG_L2 0x00ff0000 |
| 398 | #define DEBUG_L2_FSM 0x00020000 |
| 399 | #define DEBUG_L2_CTRL 0x00040000 |
| 400 | #define DEBUG_L2_RECV 0x00080000 |
| 401 | #define DEBUG_L2_TEI 0x00100000 |
| 402 | #define DEBUG_L2_TEIFSM 0x00200000 |
| 403 | #define DEBUG_TIMER 0x01000000 |
Andreas Eversberg | 3bd69ad | 2008-09-06 09:03:46 +0200 | [diff] [blame] | 404 | #define DEBUG_CLOCK 0x02000000 |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 405 | |
| 406 | #define mISDN_HEAD_P(s) ((struct mISDNhead *)&s->cb[0]) |
| 407 | #define mISDN_HEAD_PRIM(s) (((struct mISDNhead *)&s->cb[0])->prim) |
| 408 | #define mISDN_HEAD_ID(s) (((struct mISDNhead *)&s->cb[0])->id) |
| 409 | |
| 410 | /* socket states */ |
| 411 | #define MISDN_OPEN 1 |
| 412 | #define MISDN_BOUND 2 |
| 413 | #define MISDN_CLOSED 3 |
| 414 | |
| 415 | struct mISDNchannel; |
| 416 | struct mISDNdevice; |
| 417 | struct mISDNstack; |
Andreas Eversberg | 3bd69ad | 2008-09-06 09:03:46 +0200 | [diff] [blame] | 418 | struct mISDNclock; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 419 | |
| 420 | struct channel_req { |
| 421 | u_int protocol; |
| 422 | struct sockaddr_mISDN adr; |
| 423 | struct mISDNchannel *ch; |
| 424 | }; |
| 425 | |
| 426 | typedef int (ctrl_func_t)(struct mISDNchannel *, u_int, void *); |
| 427 | typedef int (send_func_t)(struct mISDNchannel *, struct sk_buff *); |
| 428 | typedef int (create_func_t)(struct channel_req *); |
| 429 | |
| 430 | struct Bprotocol { |
| 431 | struct list_head list; |
| 432 | char *name; |
| 433 | u_int Bprotocols; |
| 434 | create_func_t *create; |
| 435 | }; |
| 436 | |
| 437 | struct mISDNchannel { |
| 438 | struct list_head list; |
| 439 | u_int protocol; |
| 440 | u_int nr; |
| 441 | u_long opt; |
| 442 | u_int addr; |
| 443 | struct mISDNstack *st; |
| 444 | struct mISDNchannel *peer; |
| 445 | send_func_t *send; |
| 446 | send_func_t *recv; |
| 447 | ctrl_func_t *ctrl; |
| 448 | }; |
| 449 | |
| 450 | struct mISDN_sock_list { |
| 451 | struct hlist_head head; |
| 452 | rwlock_t lock; |
| 453 | }; |
| 454 | |
| 455 | struct mISDN_sock { |
| 456 | struct sock sk; |
| 457 | struct mISDNchannel ch; |
| 458 | u_int cmask; |
| 459 | struct mISDNdevice *dev; |
| 460 | }; |
| 461 | |
| 462 | |
| 463 | |
| 464 | struct mISDNdevice { |
| 465 | struct mISDNchannel D; |
| 466 | u_int id; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 467 | u_int Dprotocols; |
| 468 | u_int Bprotocols; |
| 469 | u_int nrbchan; |
Karsten Keil | ff4cc1d | 2008-07-30 18:26:58 +0200 | [diff] [blame] | 470 | u_char channelmap[MISDN_CHMAP_SIZE]; |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 471 | struct list_head bchannels; |
| 472 | struct mISDNchannel *teimgr; |
| 473 | struct device dev; |
| 474 | }; |
| 475 | |
| 476 | struct mISDNstack { |
| 477 | u_long status; |
| 478 | struct mISDNdevice *dev; |
| 479 | struct task_struct *thread; |
| 480 | struct completion *notify; |
| 481 | wait_queue_head_t workq; |
| 482 | struct sk_buff_head msgq; |
| 483 | struct list_head layer2; |
| 484 | struct mISDNchannel *layer1; |
| 485 | struct mISDNchannel own; |
| 486 | struct mutex lmutex; /* protect lists */ |
| 487 | struct mISDN_sock_list l1sock; |
| 488 | #ifdef MISDN_MSG_STATS |
| 489 | u_int msg_cnt; |
| 490 | u_int sleep_cnt; |
| 491 | u_int stopped_cnt; |
| 492 | #endif |
| 493 | }; |
| 494 | |
Andreas Eversberg | 3bd69ad | 2008-09-06 09:03:46 +0200 | [diff] [blame] | 495 | typedef int (clockctl_func_t)(void *, int); |
| 496 | |
| 497 | struct mISDNclock { |
| 498 | struct list_head list; |
| 499 | char name[64]; |
| 500 | int pri; |
| 501 | clockctl_func_t *ctl; |
| 502 | void *priv; |
| 503 | }; |
| 504 | |
Karsten Keil | ff4cc1d | 2008-07-30 18:26:58 +0200 | [diff] [blame] | 505 | /* global alloc/queue functions */ |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 506 | |
| 507 | static inline struct sk_buff * |
| 508 | mI_alloc_skb(unsigned int len, gfp_t gfp_mask) |
| 509 | { |
| 510 | struct sk_buff *skb; |
| 511 | |
| 512 | skb = alloc_skb(len + MISDN_HEADER_LEN, gfp_mask); |
| 513 | if (likely(skb)) |
| 514 | skb_reserve(skb, MISDN_HEADER_LEN); |
| 515 | return skb; |
| 516 | } |
| 517 | |
| 518 | static inline struct sk_buff * |
| 519 | _alloc_mISDN_skb(u_int prim, u_int id, u_int len, void *dp, gfp_t gfp_mask) |
| 520 | { |
| 521 | struct sk_buff *skb = mI_alloc_skb(len, gfp_mask); |
| 522 | struct mISDNhead *hh; |
| 523 | |
| 524 | if (!skb) |
| 525 | return NULL; |
| 526 | if (len) |
| 527 | memcpy(skb_put(skb, len), dp, len); |
| 528 | hh = mISDN_HEAD_P(skb); |
| 529 | hh->prim = prim; |
| 530 | hh->id = id; |
| 531 | return skb; |
| 532 | } |
| 533 | |
| 534 | static inline void |
| 535 | _queue_data(struct mISDNchannel *ch, u_int prim, |
| 536 | u_int id, u_int len, void *dp, gfp_t gfp_mask) |
| 537 | { |
| 538 | struct sk_buff *skb; |
| 539 | |
| 540 | if (!ch->peer) |
| 541 | return; |
| 542 | skb = _alloc_mISDN_skb(prim, id, len, dp, gfp_mask); |
| 543 | if (!skb) |
| 544 | return; |
| 545 | if (ch->recv(ch->peer, skb)) |
| 546 | dev_kfree_skb(skb); |
| 547 | } |
| 548 | |
| 549 | /* global register/unregister functions */ |
| 550 | |
Matthias Urlichs | b36b654 | 2008-08-16 00:09:24 +0200 | [diff] [blame] | 551 | extern int mISDN_register_device(struct mISDNdevice *, |
| 552 | struct device *parent, char *name); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 553 | extern void mISDN_unregister_device(struct mISDNdevice *); |
| 554 | extern int mISDN_register_Bprotocol(struct Bprotocol *); |
| 555 | extern void mISDN_unregister_Bprotocol(struct Bprotocol *); |
Andreas Eversberg | 3bd69ad | 2008-09-06 09:03:46 +0200 | [diff] [blame] | 556 | extern struct mISDNclock *mISDN_register_clock(char *, int, clockctl_func_t *, |
| 557 | void *); |
| 558 | extern void mISDN_unregister_clock(struct mISDNclock *); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 559 | |
Matthias Urlichs | b36b654 | 2008-08-16 00:09:24 +0200 | [diff] [blame] | 560 | static inline struct mISDNdevice *dev_to_mISDN(struct device *dev) |
| 561 | { |
Martin Bachem | 57de16e | 2008-10-26 13:30:09 +0100 | [diff] [blame] | 562 | if (dev) |
| 563 | return dev_get_drvdata(dev); |
| 564 | else |
| 565 | return NULL; |
Matthias Urlichs | b36b654 | 2008-08-16 00:09:24 +0200 | [diff] [blame] | 566 | } |
| 567 | |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 568 | extern void set_channel_address(struct mISDNchannel *, u_int, u_int); |
Andreas Eversberg | 3bd69ad | 2008-09-06 09:03:46 +0200 | [diff] [blame] | 569 | extern void mISDN_clock_update(struct mISDNclock *, int, struct timeval *); |
| 570 | extern unsigned short mISDN_clock_get(void); |
Karsten Keil | 1b2b03f | 2008-07-27 01:54:58 +0200 | [diff] [blame] | 571 | |
| 572 | #endif /* __KERNEL__ */ |
| 573 | #endif /* mISDNIF_H */ |