mISDNif.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. #ifndef mISDNIF_H
  18. #define mISDNIF_H
  19. #include <stdarg.h>
  20. #include <linux/types.h>
  21. #include <linux/errno.h>
  22. #include <linux/socket.h>
  23. /*
  24. * ABI Version 32 bit
  25. *
  26. * <8 bit> Major version
  27. * - changed if any interface become backwards incompatible
  28. *
  29. * <8 bit> Minor version
  30. * - changed if any interface is extended but backwards compatible
  31. *
  32. * <16 bit> Release number
  33. * - should be incremented on every checkin
  34. */
  35. #define MISDN_MAJOR_VERSION 1
  36. #define MISDN_MINOR_VERSION 0
  37. #define MISDN_RELEASE 18
  38. /* primitives for information exchange
  39. * generell format
  40. * <16 bit 0 >
  41. * <8 bit command>
  42. * BIT 8 = 1 LAYER private
  43. * BIT 7 = 1 answer
  44. * BIT 6 = 1 DATA
  45. * <8 bit target layer mask>
  46. *
  47. * Layer = 00 is reserved for general commands
  48. Layer = 01 L2 -> HW
  49. Layer = 02 HW -> L2
  50. Layer = 04 L3 -> L2
  51. Layer = 08 L2 -> L3
  52. * Layer = FF is reserved for broadcast commands
  53. */
  54. #define MISDN_CMDMASK 0xff00
  55. #define MISDN_LAYERMASK 0x00ff
  56. /* generell commands */
  57. #define OPEN_CHANNEL 0x0100
  58. #define CLOSE_CHANNEL 0x0200
  59. #define CONTROL_CHANNEL 0x0300
  60. #define CHECK_DATA 0x0400
  61. /* layer 2 -> layer 1 */
  62. #define PH_ACTIVATE_REQ 0x0101
  63. #define PH_DEACTIVATE_REQ 0x0201
  64. #define PH_DATA_REQ 0x2001
  65. #define MPH_ACTIVATE_REQ 0x0501
  66. #define MPH_DEACTIVATE_REQ 0x0601
  67. #define MPH_INFORMATION_REQ 0x0701
  68. #define PH_CONTROL_REQ 0x0801
  69. /* layer 1 -> layer 2 */
  70. #define PH_ACTIVATE_IND 0x0102
  71. #define PH_ACTIVATE_CNF 0x4102
  72. #define PH_DEACTIVATE_IND 0x0202
  73. #define PH_DEACTIVATE_CNF 0x4202
  74. #define PH_DATA_IND 0x2002
  75. #define MPH_ACTIVATE_IND 0x0502
  76. #define MPH_DEACTIVATE_IND 0x0602
  77. #define MPH_INFORMATION_IND 0x0702
  78. #define PH_DATA_CNF 0x6002
  79. #define PH_CONTROL_IND 0x0802
  80. #define PH_CONTROL_CNF 0x4802
  81. /* layer 3 -> layer 2 */
  82. #define DL_ESTABLISH_REQ 0x1004
  83. #define DL_RELEASE_REQ 0x1104
  84. #define DL_DATA_REQ 0x3004
  85. #define DL_UNITDATA_REQ 0x3104
  86. #define DL_INFORMATION_REQ 0x0004
  87. /* layer 2 -> layer 3 */
  88. #define DL_ESTABLISH_IND 0x1008
  89. #define DL_ESTABLISH_CNF 0x5008
  90. #define DL_RELEASE_IND 0x1108
  91. #define DL_RELEASE_CNF 0x5108
  92. #define DL_DATA_IND 0x3008
  93. #define DL_UNITDATA_IND 0x3108
  94. #define DL_INFORMATION_IND 0x0008
  95. /* intern layer 2 managment */
  96. #define MDL_ASSIGN_REQ 0x1804
  97. #define MDL_ASSIGN_IND 0x1904
  98. #define MDL_REMOVE_REQ 0x1A04
  99. #define MDL_REMOVE_IND 0x1B04
  100. #define MDL_STATUS_UP_IND 0x1C04
  101. #define MDL_STATUS_DOWN_IND 0x1D04
  102. #define MDL_STATUS_UI_IND 0x1E04
  103. #define MDL_ERROR_IND 0x1F04
  104. #define MDL_ERROR_RSP 0x5F04
  105. /* DL_INFORMATION_IND types */
  106. #define DL_INFO_L2_CONNECT 0x0001
  107. #define DL_INFO_L2_REMOVED 0x0002
  108. /* PH_CONTROL types */
  109. /* TOUCH TONE IS 0x20XX XX "0"..."9", "A","B","C","D","*","#" */
  110. #define DTMF_TONE_VAL 0x2000
  111. #define DTMF_TONE_MASK 0x007F
  112. #define DTMF_TONE_START 0x2100
  113. #define DTMF_TONE_STOP 0x2200
  114. #define DTMF_HFC_COEF 0x4000
  115. #define DSP_CONF_JOIN 0x2403
  116. #define DSP_CONF_SPLIT 0x2404
  117. #define DSP_RECEIVE_OFF 0x2405
  118. #define DSP_RECEIVE_ON 0x2406
  119. #define DSP_ECHO_ON 0x2407
  120. #define DSP_ECHO_OFF 0x2408
  121. #define DSP_MIX_ON 0x2409
  122. #define DSP_MIX_OFF 0x240a
  123. #define DSP_DELAY 0x240b
  124. #define DSP_JITTER 0x240c
  125. #define DSP_TXDATA_ON 0x240d
  126. #define DSP_TXDATA_OFF 0x240e
  127. #define DSP_TX_DEJITTER 0x240f
  128. #define DSP_TX_DEJ_OFF 0x2410
  129. #define DSP_TONE_PATT_ON 0x2411
  130. #define DSP_TONE_PATT_OFF 0x2412
  131. #define DSP_VOL_CHANGE_TX 0x2413
  132. #define DSP_VOL_CHANGE_RX 0x2414
  133. #define DSP_BF_ENABLE_KEY 0x2415
  134. #define DSP_BF_DISABLE 0x2416
  135. #define DSP_BF_ACCEPT 0x2416
  136. #define DSP_BF_REJECT 0x2417
  137. #define DSP_PIPELINE_CFG 0x2418
  138. #define HFC_VOL_CHANGE_TX 0x2601
  139. #define HFC_VOL_CHANGE_RX 0x2602
  140. #define HFC_SPL_LOOP_ON 0x2603
  141. #define HFC_SPL_LOOP_OFF 0x2604
  142. /* DSP_TONE_PATT_ON parameter */
  143. #define TONE_OFF 0x0000
  144. #define TONE_GERMAN_DIALTONE 0x0001
  145. #define TONE_GERMAN_OLDDIALTONE 0x0002
  146. #define TONE_AMERICAN_DIALTONE 0x0003
  147. #define TONE_GERMAN_DIALPBX 0x0004
  148. #define TONE_GERMAN_OLDDIALPBX 0x0005
  149. #define TONE_AMERICAN_DIALPBX 0x0006
  150. #define TONE_GERMAN_RINGING 0x0007
  151. #define TONE_GERMAN_OLDRINGING 0x0008
  152. #define TONE_AMERICAN_RINGPBX 0x000b
  153. #define TONE_GERMAN_RINGPBX 0x000c
  154. #define TONE_GERMAN_OLDRINGPBX 0x000d
  155. #define TONE_AMERICAN_RINGING 0x000e
  156. #define TONE_GERMAN_BUSY 0x000f
  157. #define TONE_GERMAN_OLDBUSY 0x0010
  158. #define TONE_AMERICAN_BUSY 0x0011
  159. #define TONE_GERMAN_HANGUP 0x0012
  160. #define TONE_GERMAN_OLDHANGUP 0x0013
  161. #define TONE_AMERICAN_HANGUP 0x0014
  162. #define TONE_SPECIAL_INFO 0x0015
  163. #define TONE_GERMAN_GASSENBESETZT 0x0016
  164. #define TONE_GERMAN_AUFSCHALTTON 0x0016
  165. /* MPH_INFORMATION_IND */
  166. #define L1_SIGNAL_LOS_OFF 0x0010
  167. #define L1_SIGNAL_LOS_ON 0x0011
  168. #define L1_SIGNAL_AIS_OFF 0x0012
  169. #define L1_SIGNAL_AIS_ON 0x0013
  170. #define L1_SIGNAL_RDI_OFF 0x0014
  171. #define L1_SIGNAL_RDI_ON 0x0015
  172. #define L1_SIGNAL_SLIP_RX 0x0020
  173. #define L1_SIGNAL_SLIP_TX 0x0021
  174. /*
  175. * protocol ids
  176. * D channel 1-31
  177. * B channel 33 - 63
  178. */
  179. #define ISDN_P_NONE 0
  180. #define ISDN_P_BASE 0
  181. #define ISDN_P_TE_S0 0x01
  182. #define ISDN_P_NT_S0 0x02
  183. #define ISDN_P_TE_E1 0x03
  184. #define ISDN_P_NT_E1 0x04
  185. #define ISDN_P_LAPD_TE 0x10
  186. #define ISDN_P_LAPD_NT 0x11
  187. #define ISDN_P_B_MASK 0x1f
  188. #define ISDN_P_B_START 0x20
  189. #define ISDN_P_B_RAW 0x21
  190. #define ISDN_P_B_HDLC 0x22
  191. #define ISDN_P_B_X75SLP 0x23
  192. #define ISDN_P_B_L2DTMF 0x24
  193. #define ISDN_P_B_L2DSP 0x25
  194. #define ISDN_P_B_L2DSPHDLC 0x26
  195. #define OPTION_L2_PMX 1
  196. #define OPTION_L2_PTP 2
  197. #define OPTION_L2_FIXEDTEI 3
  198. #define OPTION_L2_CLEANUP 4
  199. /* should be in sync with linux/kobject.h:KOBJ_NAME_LEN */
  200. #define MISDN_MAX_IDLEN 20
  201. struct mISDNhead {
  202. unsigned int prim;
  203. unsigned int id;
  204. } __attribute__((packed));
  205. #define MISDN_HEADER_LEN sizeof(struct mISDNhead)
  206. #define MAX_DATA_SIZE 2048
  207. #define MAX_DATA_MEM (MAX_DATA_SIZE + MISDN_HEADER_LEN)
  208. #define MAX_DFRAME_LEN 260
  209. #define MISDN_ID_ADDR_MASK 0xFFFF
  210. #define MISDN_ID_TEI_MASK 0xFF00
  211. #define MISDN_ID_SAPI_MASK 0x00FF
  212. #define MISDN_ID_TEI_ANY 0x7F00
  213. #define MISDN_ID_ANY 0xFFFF
  214. #define MISDN_ID_NONE 0xFFFE
  215. #define GROUP_TEI 127
  216. #define TEI_SAPI 63
  217. #define CTRL_SAPI 0
  218. #define MISDN_CHMAP_SIZE 4
  219. #define SOL_MISDN 0
  220. struct sockaddr_mISDN {
  221. sa_family_t family;
  222. unsigned char dev;
  223. unsigned char channel;
  224. unsigned char sapi;
  225. unsigned char tei;
  226. };
  227. /* timer device ioctl */
  228. #define IMADDTIMER _IOR('I', 64, int)
  229. #define IMDELTIMER _IOR('I', 65, int)
  230. /* socket ioctls */
  231. #define IMGETVERSION _IOR('I', 66, int)
  232. #define IMGETCOUNT _IOR('I', 67, int)
  233. #define IMGETDEVINFO _IOR('I', 68, int)
  234. #define IMCTRLREQ _IOR('I', 69, int)
  235. #define IMCLEAR_L2 _IOR('I', 70, int)
  236. struct mISDNversion {
  237. unsigned char major;
  238. unsigned char minor;
  239. unsigned short release;
  240. };
  241. struct mISDN_devinfo {
  242. u_int id;
  243. u_int Dprotocols;
  244. u_int Bprotocols;
  245. u_int protocol;
  246. u_long channelmap[MISDN_CHMAP_SIZE];
  247. u_int nrbchan;
  248. char name[MISDN_MAX_IDLEN];
  249. };
  250. /* CONTROL_CHANNEL parameters */
  251. #define MISDN_CTRL_GETOP 0x0000
  252. #define MISDN_CTRL_LOOP 0x0001
  253. #define MISDN_CTRL_CONNECT 0x0002
  254. #define MISDN_CTRL_DISCONNECT 0x0004
  255. #define MISDN_CTRL_PCMCONNECT 0x0010
  256. #define MISDN_CTRL_PCMDISCONNECT 0x0020
  257. #define MISDN_CTRL_SETPEER 0x0040
  258. #define MISDN_CTRL_UNSETPEER 0x0080
  259. #define MISDN_CTRL_RX_OFF 0x0100
  260. #define MISDN_CTRL_HW_FEATURES_OP 0x2000
  261. #define MISDN_CTRL_HW_FEATURES 0x2001
  262. #define MISDN_CTRL_HFC_OP 0x4000
  263. #define MISDN_CTRL_HFC_PCM_CONN 0x4001
  264. #define MISDN_CTRL_HFC_PCM_DISC 0x4002
  265. #define MISDN_CTRL_HFC_CONF_JOIN 0x4003
  266. #define MISDN_CTRL_HFC_CONF_SPLIT 0x4004
  267. #define MISDN_CTRL_HFC_RECEIVE_OFF 0x4005
  268. #define MISDN_CTRL_HFC_RECEIVE_ON 0x4006
  269. #define MISDN_CTRL_HFC_ECHOCAN_ON 0x4007
  270. #define MISDN_CTRL_HFC_ECHOCAN_OFF 0x4008
  271. /* socket options */
  272. #define MISDN_TIME_STAMP 0x0001
  273. struct mISDN_ctrl_req {
  274. int op;
  275. int channel;
  276. int p1;
  277. int p2;
  278. };
  279. /* muxer options */
  280. #define MISDN_OPT_ALL 1
  281. #define MISDN_OPT_TEIMGR 2
  282. #ifdef __KERNEL__
  283. #include <linux/list.h>
  284. #include <linux/skbuff.h>
  285. #include <linux/net.h>
  286. #include <net/sock.h>
  287. #include <linux/completion.h>
  288. #define DEBUG_CORE 0x000000ff
  289. #define DEBUG_CORE_FUNC 0x00000002
  290. #define DEBUG_SOCKET 0x00000004
  291. #define DEBUG_MANAGER 0x00000008
  292. #define DEBUG_SEND_ERR 0x00000010
  293. #define DEBUG_MSG_THREAD 0x00000020
  294. #define DEBUG_QUEUE_FUNC 0x00000040
  295. #define DEBUG_L1 0x0000ff00
  296. #define DEBUG_L1_FSM 0x00000200
  297. #define DEBUG_L2 0x00ff0000
  298. #define DEBUG_L2_FSM 0x00020000
  299. #define DEBUG_L2_CTRL 0x00040000
  300. #define DEBUG_L2_RECV 0x00080000
  301. #define DEBUG_L2_TEI 0x00100000
  302. #define DEBUG_L2_TEIFSM 0x00200000
  303. #define DEBUG_TIMER 0x01000000
  304. #define mISDN_HEAD_P(s) ((struct mISDNhead *)&s->cb[0])
  305. #define mISDN_HEAD_PRIM(s) (((struct mISDNhead *)&s->cb[0])->prim)
  306. #define mISDN_HEAD_ID(s) (((struct mISDNhead *)&s->cb[0])->id)
  307. /* socket states */
  308. #define MISDN_OPEN 1
  309. #define MISDN_BOUND 2
  310. #define MISDN_CLOSED 3
  311. struct mISDNchannel;
  312. struct mISDNdevice;
  313. struct mISDNstack;
  314. struct channel_req {
  315. u_int protocol;
  316. struct sockaddr_mISDN adr;
  317. struct mISDNchannel *ch;
  318. };
  319. typedef int (ctrl_func_t)(struct mISDNchannel *, u_int, void *);
  320. typedef int (send_func_t)(struct mISDNchannel *, struct sk_buff *);
  321. typedef int (create_func_t)(struct channel_req *);
  322. struct Bprotocol {
  323. struct list_head list;
  324. char *name;
  325. u_int Bprotocols;
  326. create_func_t *create;
  327. };
  328. struct mISDNchannel {
  329. struct list_head list;
  330. u_int protocol;
  331. u_int nr;
  332. u_long opt;
  333. u_int addr;
  334. struct mISDNstack *st;
  335. struct mISDNchannel *peer;
  336. send_func_t *send;
  337. send_func_t *recv;
  338. ctrl_func_t *ctrl;
  339. };
  340. struct mISDN_sock_list {
  341. struct hlist_head head;
  342. rwlock_t lock;
  343. };
  344. struct mISDN_sock {
  345. struct sock sk;
  346. struct mISDNchannel ch;
  347. u_int cmask;
  348. struct mISDNdevice *dev;
  349. };
  350. struct mISDNdevice {
  351. struct mISDNchannel D;
  352. u_int id;
  353. char name[MISDN_MAX_IDLEN];
  354. u_int Dprotocols;
  355. u_int Bprotocols;
  356. u_int nrbchan;
  357. u_long channelmap[MISDN_CHMAP_SIZE];
  358. struct list_head bchannels;
  359. struct mISDNchannel *teimgr;
  360. struct device dev;
  361. };
  362. struct mISDNstack {
  363. u_long status;
  364. struct mISDNdevice *dev;
  365. struct task_struct *thread;
  366. struct completion *notify;
  367. wait_queue_head_t workq;
  368. struct sk_buff_head msgq;
  369. struct list_head layer2;
  370. struct mISDNchannel *layer1;
  371. struct mISDNchannel own;
  372. struct mutex lmutex; /* protect lists */
  373. struct mISDN_sock_list l1sock;
  374. #ifdef MISDN_MSG_STATS
  375. u_int msg_cnt;
  376. u_int sleep_cnt;
  377. u_int stopped_cnt;
  378. #endif
  379. };
  380. /* global alloc/queue dunctions */
  381. static inline struct sk_buff *
  382. mI_alloc_skb(unsigned int len, gfp_t gfp_mask)
  383. {
  384. struct sk_buff *skb;
  385. skb = alloc_skb(len + MISDN_HEADER_LEN, gfp_mask);
  386. if (likely(skb))
  387. skb_reserve(skb, MISDN_HEADER_LEN);
  388. return skb;
  389. }
  390. static inline struct sk_buff *
  391. _alloc_mISDN_skb(u_int prim, u_int id, u_int len, void *dp, gfp_t gfp_mask)
  392. {
  393. struct sk_buff *skb = mI_alloc_skb(len, gfp_mask);
  394. struct mISDNhead *hh;
  395. if (!skb)
  396. return NULL;
  397. if (len)
  398. memcpy(skb_put(skb, len), dp, len);
  399. hh = mISDN_HEAD_P(skb);
  400. hh->prim = prim;
  401. hh->id = id;
  402. return skb;
  403. }
  404. static inline void
  405. _queue_data(struct mISDNchannel *ch, u_int prim,
  406. u_int id, u_int len, void *dp, gfp_t gfp_mask)
  407. {
  408. struct sk_buff *skb;
  409. if (!ch->peer)
  410. return;
  411. skb = _alloc_mISDN_skb(prim, id, len, dp, gfp_mask);
  412. if (!skb)
  413. return;
  414. if (ch->recv(ch->peer, skb))
  415. dev_kfree_skb(skb);
  416. }
  417. /* global register/unregister functions */
  418. extern int mISDN_register_device(struct mISDNdevice *, char *name);
  419. extern void mISDN_unregister_device(struct mISDNdevice *);
  420. extern int mISDN_register_Bprotocol(struct Bprotocol *);
  421. extern void mISDN_unregister_Bprotocol(struct Bprotocol *);
  422. extern void set_channel_address(struct mISDNchannel *, u_int, u_int);
  423. #endif /* __KERNEL__ */
  424. #endif /* mISDNIF_H */