capiutil.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522
  1. /* $Id: capiutil.h,v 1.5.6.2 2001/09/23 22:24:33 kai Exp $
  2. *
  3. * CAPI 2.0 defines & types
  4. *
  5. * From CAPI 2.0 Development Kit AVM 1995 (msg.c)
  6. * Rewritten for Linux 1996 by Carsten Paeth <calle@calle.de>
  7. *
  8. * This software may be used and distributed according to the terms
  9. * of the GNU General Public License, incorporated herein by reference.
  10. *
  11. */
  12. #ifndef __CAPIUTIL_H__
  13. #define __CAPIUTIL_H__
  14. #include <asm/types.h>
  15. #define CAPIMSG_BASELEN 8
  16. #define CAPIMSG_U8(m, off) (m[off])
  17. #define CAPIMSG_U16(m, off) (m[off]|(m[(off)+1]<<8))
  18. #define CAPIMSG_U32(m, off) (m[off]|(m[(off)+1]<<8)|(m[(off)+2]<<16)|(m[(off)+3]<<24))
  19. #define CAPIMSG_LEN(m) CAPIMSG_U16(m,0)
  20. #define CAPIMSG_APPID(m) CAPIMSG_U16(m,2)
  21. #define CAPIMSG_COMMAND(m) CAPIMSG_U8(m,4)
  22. #define CAPIMSG_SUBCOMMAND(m) CAPIMSG_U8(m,5)
  23. #define CAPIMSG_CMD(m) (((m[4])<<8)|(m[5]))
  24. #define CAPIMSG_MSGID(m) CAPIMSG_U16(m,6)
  25. #define CAPIMSG_CONTROLLER(m) (m[8] & 0x7f)
  26. #define CAPIMSG_CONTROL(m) CAPIMSG_U32(m, 8)
  27. #define CAPIMSG_NCCI(m) CAPIMSG_CONTROL(m)
  28. #define CAPIMSG_DATALEN(m) CAPIMSG_U16(m,16) /* DATA_B3_REQ */
  29. static inline void capimsg_setu8(void *m, int off, __u8 val)
  30. {
  31. ((__u8 *)m)[off] = val;
  32. }
  33. static inline void capimsg_setu16(void *m, int off, __u16 val)
  34. {
  35. ((__u8 *)m)[off] = val & 0xff;
  36. ((__u8 *)m)[off+1] = (val >> 8) & 0xff;
  37. }
  38. static inline void capimsg_setu32(void *m, int off, __u32 val)
  39. {
  40. ((__u8 *)m)[off] = val & 0xff;
  41. ((__u8 *)m)[off+1] = (val >> 8) & 0xff;
  42. ((__u8 *)m)[off+2] = (val >> 16) & 0xff;
  43. ((__u8 *)m)[off+3] = (val >> 24) & 0xff;
  44. }
  45. #define CAPIMSG_SETLEN(m, len) capimsg_setu16(m, 0, len)
  46. #define CAPIMSG_SETAPPID(m, applid) capimsg_setu16(m, 2, applid)
  47. #define CAPIMSG_SETCOMMAND(m,cmd) capimsg_setu8(m, 4, cmd)
  48. #define CAPIMSG_SETSUBCOMMAND(m, cmd) capimsg_setu8(m, 5, cmd)
  49. #define CAPIMSG_SETMSGID(m, msgid) capimsg_setu16(m, 6, msgid)
  50. #define CAPIMSG_SETCONTROL(m, contr) capimsg_setu32(m, 8, contr)
  51. #define CAPIMSG_SETDATALEN(m, len) capimsg_setu16(m, 16, len)
  52. /*----- basic-type definitions -----*/
  53. typedef __u8 *_cstruct;
  54. typedef enum {
  55. CAPI_COMPOSE,
  56. CAPI_DEFAULT
  57. } _cmstruct;
  58. /*
  59. The _cmsg structure contains all possible CAPI 2.0 parameter.
  60. All parameters are stored here first. The function CAPI_CMSG_2_MESSAGE
  61. assembles the parameter and builds CAPI2.0 conform messages.
  62. CAPI_MESSAGE_2_CMSG disassembles CAPI 2.0 messages and stores the
  63. parameter in the _cmsg structure
  64. */
  65. typedef struct {
  66. /* Header */
  67. __u16 ApplId;
  68. __u8 Command;
  69. __u8 Subcommand;
  70. __u16 Messagenumber;
  71. /* Parameter */
  72. union {
  73. __u32 adrController;
  74. __u32 adrPLCI;
  75. __u32 adrNCCI;
  76. } adr;
  77. _cmstruct AdditionalInfo;
  78. _cstruct B1configuration;
  79. __u16 B1protocol;
  80. _cstruct B2configuration;
  81. __u16 B2protocol;
  82. _cstruct B3configuration;
  83. __u16 B3protocol;
  84. _cstruct BC;
  85. _cstruct BChannelinformation;
  86. _cmstruct BProtocol;
  87. _cstruct CalledPartyNumber;
  88. _cstruct CalledPartySubaddress;
  89. _cstruct CallingPartyNumber;
  90. _cstruct CallingPartySubaddress;
  91. __u32 CIPmask;
  92. __u32 CIPmask2;
  93. __u16 CIPValue;
  94. __u32 Class;
  95. _cstruct ConnectedNumber;
  96. _cstruct ConnectedSubaddress;
  97. __u32 Data;
  98. __u16 DataHandle;
  99. __u16 DataLength;
  100. _cstruct FacilityConfirmationParameter;
  101. _cstruct Facilitydataarray;
  102. _cstruct FacilityIndicationParameter;
  103. _cstruct FacilityRequestParameter;
  104. __u16 FacilitySelector;
  105. __u16 Flags;
  106. __u32 Function;
  107. _cstruct HLC;
  108. __u16 Info;
  109. _cstruct InfoElement;
  110. __u32 InfoMask;
  111. __u16 InfoNumber;
  112. _cstruct Keypadfacility;
  113. _cstruct LLC;
  114. _cstruct ManuData;
  115. __u32 ManuID;
  116. _cstruct NCPI;
  117. __u16 Reason;
  118. __u16 Reason_B3;
  119. __u16 Reject;
  120. _cstruct Useruserdata;
  121. /* intern */
  122. unsigned l, p;
  123. unsigned char *par;
  124. __u8 *m;
  125. /* buffer to construct message */
  126. __u8 buf[180];
  127. } _cmsg;
  128. /*
  129. * capi_cmsg2message() assembles the parameter from _cmsg to a CAPI 2.0
  130. * conform message
  131. */
  132. unsigned capi_cmsg2message(_cmsg * cmsg, __u8 * msg);
  133. /*
  134. * capi_message2cmsg disassembles a CAPI message an writes the parameter
  135. * into _cmsg for easy access
  136. */
  137. unsigned capi_message2cmsg(_cmsg * cmsg, __u8 * msg);
  138. /*
  139. * capi_cmsg_header() fills the _cmsg structure with default values, so only
  140. * parameter with non default values must be changed before sending the
  141. * message.
  142. */
  143. unsigned capi_cmsg_header(_cmsg * cmsg, __u16 _ApplId,
  144. __u8 _Command, __u8 _Subcommand,
  145. __u16 _Messagenumber, __u32 _Controller);
  146. /*
  147. * capi_info2str generated a readable string for Capi2.0 reasons.
  148. */
  149. char *capi_info2str(__u16 reason);
  150. /*-----------------------------------------------------------------------*/
  151. /*
  152. * Debugging / Tracing functions
  153. */
  154. char *capi_cmd2str(__u8 cmd, __u8 subcmd);
  155. typedef struct {
  156. u_char *buf;
  157. u_char *p;
  158. size_t size;
  159. size_t pos;
  160. } _cdebbuf;
  161. #define CDEBUG_SIZE 1024
  162. #define CDEBUG_GSIZE 4096
  163. void cdebbuf_free(_cdebbuf *cdb);
  164. int cdebug_init(void);
  165. void cdebug_exit(void);
  166. _cdebbuf *capi_cmsg2str(_cmsg *cmsg);
  167. _cdebbuf *capi_message2str(__u8 *msg);
  168. /*-----------------------------------------------------------------------*/
  169. static inline void capi_cmsg_answer(_cmsg * cmsg)
  170. {
  171. cmsg->Subcommand |= 0x01;
  172. }
  173. /*-----------------------------------------------------------------------*/
  174. static inline void capi_fill_CONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  175. __u32 adr,
  176. _cstruct NCPI)
  177. {
  178. capi_cmsg_header(cmsg, ApplId, 0x82, 0x80, Messagenumber, adr);
  179. cmsg->NCPI = NCPI;
  180. }
  181. static inline void capi_fill_FACILITY_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  182. __u32 adr,
  183. __u16 FacilitySelector,
  184. _cstruct FacilityRequestParameter)
  185. {
  186. capi_cmsg_header(cmsg, ApplId, 0x80, 0x80, Messagenumber, adr);
  187. cmsg->FacilitySelector = FacilitySelector;
  188. cmsg->FacilityRequestParameter = FacilityRequestParameter;
  189. }
  190. static inline void capi_fill_INFO_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  191. __u32 adr,
  192. _cstruct CalledPartyNumber,
  193. _cstruct BChannelinformation,
  194. _cstruct Keypadfacility,
  195. _cstruct Useruserdata,
  196. _cstruct Facilitydataarray)
  197. {
  198. capi_cmsg_header(cmsg, ApplId, 0x08, 0x80, Messagenumber, adr);
  199. cmsg->CalledPartyNumber = CalledPartyNumber;
  200. cmsg->BChannelinformation = BChannelinformation;
  201. cmsg->Keypadfacility = Keypadfacility;
  202. cmsg->Useruserdata = Useruserdata;
  203. cmsg->Facilitydataarray = Facilitydataarray;
  204. }
  205. static inline void capi_fill_LISTEN_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  206. __u32 adr,
  207. __u32 InfoMask,
  208. __u32 CIPmask,
  209. __u32 CIPmask2,
  210. _cstruct CallingPartyNumber,
  211. _cstruct CallingPartySubaddress)
  212. {
  213. capi_cmsg_header(cmsg, ApplId, 0x05, 0x80, Messagenumber, adr);
  214. cmsg->InfoMask = InfoMask;
  215. cmsg->CIPmask = CIPmask;
  216. cmsg->CIPmask2 = CIPmask2;
  217. cmsg->CallingPartyNumber = CallingPartyNumber;
  218. cmsg->CallingPartySubaddress = CallingPartySubaddress;
  219. }
  220. static inline void capi_fill_ALERT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  221. __u32 adr,
  222. _cstruct BChannelinformation,
  223. _cstruct Keypadfacility,
  224. _cstruct Useruserdata,
  225. _cstruct Facilitydataarray)
  226. {
  227. capi_cmsg_header(cmsg, ApplId, 0x01, 0x80, Messagenumber, adr);
  228. cmsg->BChannelinformation = BChannelinformation;
  229. cmsg->Keypadfacility = Keypadfacility;
  230. cmsg->Useruserdata = Useruserdata;
  231. cmsg->Facilitydataarray = Facilitydataarray;
  232. }
  233. static inline void capi_fill_CONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  234. __u32 adr,
  235. __u16 CIPValue,
  236. _cstruct CalledPartyNumber,
  237. _cstruct CallingPartyNumber,
  238. _cstruct CalledPartySubaddress,
  239. _cstruct CallingPartySubaddress,
  240. __u16 B1protocol,
  241. __u16 B2protocol,
  242. __u16 B3protocol,
  243. _cstruct B1configuration,
  244. _cstruct B2configuration,
  245. _cstruct B3configuration,
  246. _cstruct BC,
  247. _cstruct LLC,
  248. _cstruct HLC,
  249. _cstruct BChannelinformation,
  250. _cstruct Keypadfacility,
  251. _cstruct Useruserdata,
  252. _cstruct Facilitydataarray)
  253. {
  254. capi_cmsg_header(cmsg, ApplId, 0x02, 0x80, Messagenumber, adr);
  255. cmsg->CIPValue = CIPValue;
  256. cmsg->CalledPartyNumber = CalledPartyNumber;
  257. cmsg->CallingPartyNumber = CallingPartyNumber;
  258. cmsg->CalledPartySubaddress = CalledPartySubaddress;
  259. cmsg->CallingPartySubaddress = CallingPartySubaddress;
  260. cmsg->B1protocol = B1protocol;
  261. cmsg->B2protocol = B2protocol;
  262. cmsg->B3protocol = B3protocol;
  263. cmsg->B1configuration = B1configuration;
  264. cmsg->B2configuration = B2configuration;
  265. cmsg->B3configuration = B3configuration;
  266. cmsg->BC = BC;
  267. cmsg->LLC = LLC;
  268. cmsg->HLC = HLC;
  269. cmsg->BChannelinformation = BChannelinformation;
  270. cmsg->Keypadfacility = Keypadfacility;
  271. cmsg->Useruserdata = Useruserdata;
  272. cmsg->Facilitydataarray = Facilitydataarray;
  273. }
  274. static inline void capi_fill_DATA_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  275. __u32 adr,
  276. __u32 Data,
  277. __u16 DataLength,
  278. __u16 DataHandle,
  279. __u16 Flags)
  280. {
  281. capi_cmsg_header(cmsg, ApplId, 0x86, 0x80, Messagenumber, adr);
  282. cmsg->Data = Data;
  283. cmsg->DataLength = DataLength;
  284. cmsg->DataHandle = DataHandle;
  285. cmsg->Flags = Flags;
  286. }
  287. static inline void capi_fill_DISCONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  288. __u32 adr,
  289. _cstruct BChannelinformation,
  290. _cstruct Keypadfacility,
  291. _cstruct Useruserdata,
  292. _cstruct Facilitydataarray)
  293. {
  294. capi_cmsg_header(cmsg, ApplId, 0x04, 0x80, Messagenumber, adr);
  295. cmsg->BChannelinformation = BChannelinformation;
  296. cmsg->Keypadfacility = Keypadfacility;
  297. cmsg->Useruserdata = Useruserdata;
  298. cmsg->Facilitydataarray = Facilitydataarray;
  299. }
  300. static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  301. __u32 adr,
  302. _cstruct NCPI)
  303. {
  304. capi_cmsg_header(cmsg, ApplId, 0x84, 0x80, Messagenumber, adr);
  305. cmsg->NCPI = NCPI;
  306. }
  307. static inline void capi_fill_MANUFACTURER_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  308. __u32 adr,
  309. __u32 ManuID,
  310. __u32 Class,
  311. __u32 Function,
  312. _cstruct ManuData)
  313. {
  314. capi_cmsg_header(cmsg, ApplId, 0xff, 0x80, Messagenumber, adr);
  315. cmsg->ManuID = ManuID;
  316. cmsg->Class = Class;
  317. cmsg->Function = Function;
  318. cmsg->ManuData = ManuData;
  319. }
  320. static inline void capi_fill_RESET_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  321. __u32 adr,
  322. _cstruct NCPI)
  323. {
  324. capi_cmsg_header(cmsg, ApplId, 0x87, 0x80, Messagenumber, adr);
  325. cmsg->NCPI = NCPI;
  326. }
  327. static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  328. __u32 adr,
  329. __u16 B1protocol,
  330. __u16 B2protocol,
  331. __u16 B3protocol,
  332. _cstruct B1configuration,
  333. _cstruct B2configuration,
  334. _cstruct B3configuration)
  335. {
  336. capi_cmsg_header(cmsg, ApplId, 0x41, 0x80, Messagenumber, adr);
  337. cmsg->B1protocol = B1protocol;
  338. cmsg->B2protocol = B2protocol;
  339. cmsg->B3protocol = B3protocol;
  340. cmsg->B1configuration = B1configuration;
  341. cmsg->B2configuration = B2configuration;
  342. cmsg->B3configuration = B3configuration;
  343. }
  344. static inline void capi_fill_CONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  345. __u32 adr,
  346. __u16 Reject,
  347. __u16 B1protocol,
  348. __u16 B2protocol,
  349. __u16 B3protocol,
  350. _cstruct B1configuration,
  351. _cstruct B2configuration,
  352. _cstruct B3configuration,
  353. _cstruct ConnectedNumber,
  354. _cstruct ConnectedSubaddress,
  355. _cstruct LLC,
  356. _cstruct BChannelinformation,
  357. _cstruct Keypadfacility,
  358. _cstruct Useruserdata,
  359. _cstruct Facilitydataarray)
  360. {
  361. capi_cmsg_header(cmsg, ApplId, 0x02, 0x83, Messagenumber, adr);
  362. cmsg->Reject = Reject;
  363. cmsg->B1protocol = B1protocol;
  364. cmsg->B2protocol = B2protocol;
  365. cmsg->B3protocol = B3protocol;
  366. cmsg->B1configuration = B1configuration;
  367. cmsg->B2configuration = B2configuration;
  368. cmsg->B3configuration = B3configuration;
  369. cmsg->ConnectedNumber = ConnectedNumber;
  370. cmsg->ConnectedSubaddress = ConnectedSubaddress;
  371. cmsg->LLC = LLC;
  372. cmsg->BChannelinformation = BChannelinformation;
  373. cmsg->Keypadfacility = Keypadfacility;
  374. cmsg->Useruserdata = Useruserdata;
  375. cmsg->Facilitydataarray = Facilitydataarray;
  376. }
  377. static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  378. __u32 adr)
  379. {
  380. capi_cmsg_header(cmsg, ApplId, 0x03, 0x83, Messagenumber, adr);
  381. }
  382. static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  383. __u32 adr)
  384. {
  385. capi_cmsg_header(cmsg, ApplId, 0x83, 0x83, Messagenumber, adr);
  386. }
  387. static inline void capi_fill_CONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  388. __u32 adr,
  389. __u16 Reject,
  390. _cstruct NCPI)
  391. {
  392. capi_cmsg_header(cmsg, ApplId, 0x82, 0x83, Messagenumber, adr);
  393. cmsg->Reject = Reject;
  394. cmsg->NCPI = NCPI;
  395. }
  396. static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  397. __u32 adr)
  398. {
  399. capi_cmsg_header(cmsg, ApplId, 0x88, 0x83, Messagenumber, adr);
  400. }
  401. static inline void capi_fill_DATA_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  402. __u32 adr,
  403. __u16 DataHandle)
  404. {
  405. capi_cmsg_header(cmsg, ApplId, 0x86, 0x83, Messagenumber, adr);
  406. cmsg->DataHandle = DataHandle;
  407. }
  408. static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  409. __u32 adr)
  410. {
  411. capi_cmsg_header(cmsg, ApplId, 0x84, 0x83, Messagenumber, adr);
  412. }
  413. static inline void capi_fill_DISCONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  414. __u32 adr)
  415. {
  416. capi_cmsg_header(cmsg, ApplId, 0x04, 0x83, Messagenumber, adr);
  417. }
  418. static inline void capi_fill_FACILITY_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  419. __u32 adr,
  420. __u16 FacilitySelector)
  421. {
  422. capi_cmsg_header(cmsg, ApplId, 0x80, 0x83, Messagenumber, adr);
  423. cmsg->FacilitySelector = FacilitySelector;
  424. }
  425. static inline void capi_fill_INFO_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  426. __u32 adr)
  427. {
  428. capi_cmsg_header(cmsg, ApplId, 0x08, 0x83, Messagenumber, adr);
  429. }
  430. static inline void capi_fill_MANUFACTURER_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  431. __u32 adr,
  432. __u32 ManuID,
  433. __u32 Class,
  434. __u32 Function,
  435. _cstruct ManuData)
  436. {
  437. capi_cmsg_header(cmsg, ApplId, 0xff, 0x83, Messagenumber, adr);
  438. cmsg->ManuID = ManuID;
  439. cmsg->Class = Class;
  440. cmsg->Function = Function;
  441. cmsg->ManuData = ManuData;
  442. }
  443. static inline void capi_fill_RESET_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  444. __u32 adr)
  445. {
  446. capi_cmsg_header(cmsg, ApplId, 0x87, 0x83, Messagenumber, adr);
  447. }
  448. #endif /* __CAPIUTIL_H__ */