capiutil.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. char *capi_cmsg2str(_cmsg * cmsg);
  156. char *capi_message2str(__u8 * msg);
  157. /*-----------------------------------------------------------------------*/
  158. static inline void capi_cmsg_answer(_cmsg * cmsg)
  159. {
  160. cmsg->Subcommand |= 0x01;
  161. }
  162. /*-----------------------------------------------------------------------*/
  163. static inline void capi_fill_CONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  164. __u32 adr,
  165. _cstruct NCPI)
  166. {
  167. capi_cmsg_header(cmsg, ApplId, 0x82, 0x80, Messagenumber, adr);
  168. cmsg->NCPI = NCPI;
  169. }
  170. static inline void capi_fill_FACILITY_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  171. __u32 adr,
  172. __u16 FacilitySelector,
  173. _cstruct FacilityRequestParameter)
  174. {
  175. capi_cmsg_header(cmsg, ApplId, 0x80, 0x80, Messagenumber, adr);
  176. cmsg->FacilitySelector = FacilitySelector;
  177. cmsg->FacilityRequestParameter = FacilityRequestParameter;
  178. }
  179. static inline void capi_fill_INFO_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  180. __u32 adr,
  181. _cstruct CalledPartyNumber,
  182. _cstruct BChannelinformation,
  183. _cstruct Keypadfacility,
  184. _cstruct Useruserdata,
  185. _cstruct Facilitydataarray)
  186. {
  187. capi_cmsg_header(cmsg, ApplId, 0x08, 0x80, Messagenumber, adr);
  188. cmsg->CalledPartyNumber = CalledPartyNumber;
  189. cmsg->BChannelinformation = BChannelinformation;
  190. cmsg->Keypadfacility = Keypadfacility;
  191. cmsg->Useruserdata = Useruserdata;
  192. cmsg->Facilitydataarray = Facilitydataarray;
  193. }
  194. static inline void capi_fill_LISTEN_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  195. __u32 adr,
  196. __u32 InfoMask,
  197. __u32 CIPmask,
  198. __u32 CIPmask2,
  199. _cstruct CallingPartyNumber,
  200. _cstruct CallingPartySubaddress)
  201. {
  202. capi_cmsg_header(cmsg, ApplId, 0x05, 0x80, Messagenumber, adr);
  203. cmsg->InfoMask = InfoMask;
  204. cmsg->CIPmask = CIPmask;
  205. cmsg->CIPmask2 = CIPmask2;
  206. cmsg->CallingPartyNumber = CallingPartyNumber;
  207. cmsg->CallingPartySubaddress = CallingPartySubaddress;
  208. }
  209. static inline void capi_fill_ALERT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  210. __u32 adr,
  211. _cstruct BChannelinformation,
  212. _cstruct Keypadfacility,
  213. _cstruct Useruserdata,
  214. _cstruct Facilitydataarray)
  215. {
  216. capi_cmsg_header(cmsg, ApplId, 0x01, 0x80, Messagenumber, adr);
  217. cmsg->BChannelinformation = BChannelinformation;
  218. cmsg->Keypadfacility = Keypadfacility;
  219. cmsg->Useruserdata = Useruserdata;
  220. cmsg->Facilitydataarray = Facilitydataarray;
  221. }
  222. static inline void capi_fill_CONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  223. __u32 adr,
  224. __u16 CIPValue,
  225. _cstruct CalledPartyNumber,
  226. _cstruct CallingPartyNumber,
  227. _cstruct CalledPartySubaddress,
  228. _cstruct CallingPartySubaddress,
  229. __u16 B1protocol,
  230. __u16 B2protocol,
  231. __u16 B3protocol,
  232. _cstruct B1configuration,
  233. _cstruct B2configuration,
  234. _cstruct B3configuration,
  235. _cstruct BC,
  236. _cstruct LLC,
  237. _cstruct HLC,
  238. _cstruct BChannelinformation,
  239. _cstruct Keypadfacility,
  240. _cstruct Useruserdata,
  241. _cstruct Facilitydataarray)
  242. {
  243. capi_cmsg_header(cmsg, ApplId, 0x02, 0x80, Messagenumber, adr);
  244. cmsg->CIPValue = CIPValue;
  245. cmsg->CalledPartyNumber = CalledPartyNumber;
  246. cmsg->CallingPartyNumber = CallingPartyNumber;
  247. cmsg->CalledPartySubaddress = CalledPartySubaddress;
  248. cmsg->CallingPartySubaddress = CallingPartySubaddress;
  249. cmsg->B1protocol = B1protocol;
  250. cmsg->B2protocol = B2protocol;
  251. cmsg->B3protocol = B3protocol;
  252. cmsg->B1configuration = B1configuration;
  253. cmsg->B2configuration = B2configuration;
  254. cmsg->B3configuration = B3configuration;
  255. cmsg->BC = BC;
  256. cmsg->LLC = LLC;
  257. cmsg->HLC = HLC;
  258. cmsg->BChannelinformation = BChannelinformation;
  259. cmsg->Keypadfacility = Keypadfacility;
  260. cmsg->Useruserdata = Useruserdata;
  261. cmsg->Facilitydataarray = Facilitydataarray;
  262. }
  263. static inline void capi_fill_DATA_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  264. __u32 adr,
  265. __u32 Data,
  266. __u16 DataLength,
  267. __u16 DataHandle,
  268. __u16 Flags)
  269. {
  270. capi_cmsg_header(cmsg, ApplId, 0x86, 0x80, Messagenumber, adr);
  271. cmsg->Data = Data;
  272. cmsg->DataLength = DataLength;
  273. cmsg->DataHandle = DataHandle;
  274. cmsg->Flags = Flags;
  275. }
  276. static inline void capi_fill_DISCONNECT_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  277. __u32 adr,
  278. _cstruct BChannelinformation,
  279. _cstruct Keypadfacility,
  280. _cstruct Useruserdata,
  281. _cstruct Facilitydataarray)
  282. {
  283. capi_cmsg_header(cmsg, ApplId, 0x04, 0x80, Messagenumber, adr);
  284. cmsg->BChannelinformation = BChannelinformation;
  285. cmsg->Keypadfacility = Keypadfacility;
  286. cmsg->Useruserdata = Useruserdata;
  287. cmsg->Facilitydataarray = Facilitydataarray;
  288. }
  289. static inline void capi_fill_DISCONNECT_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  290. __u32 adr,
  291. _cstruct NCPI)
  292. {
  293. capi_cmsg_header(cmsg, ApplId, 0x84, 0x80, Messagenumber, adr);
  294. cmsg->NCPI = NCPI;
  295. }
  296. static inline void capi_fill_MANUFACTURER_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  297. __u32 adr,
  298. __u32 ManuID,
  299. __u32 Class,
  300. __u32 Function,
  301. _cstruct ManuData)
  302. {
  303. capi_cmsg_header(cmsg, ApplId, 0xff, 0x80, Messagenumber, adr);
  304. cmsg->ManuID = ManuID;
  305. cmsg->Class = Class;
  306. cmsg->Function = Function;
  307. cmsg->ManuData = ManuData;
  308. }
  309. static inline void capi_fill_RESET_B3_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  310. __u32 adr,
  311. _cstruct NCPI)
  312. {
  313. capi_cmsg_header(cmsg, ApplId, 0x87, 0x80, Messagenumber, adr);
  314. cmsg->NCPI = NCPI;
  315. }
  316. static inline void capi_fill_SELECT_B_PROTOCOL_REQ(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  317. __u32 adr,
  318. __u16 B1protocol,
  319. __u16 B2protocol,
  320. __u16 B3protocol,
  321. _cstruct B1configuration,
  322. _cstruct B2configuration,
  323. _cstruct B3configuration)
  324. {
  325. capi_cmsg_header(cmsg, ApplId, 0x41, 0x80, Messagenumber, adr);
  326. cmsg->B1protocol = B1protocol;
  327. cmsg->B2protocol = B2protocol;
  328. cmsg->B3protocol = B3protocol;
  329. cmsg->B1configuration = B1configuration;
  330. cmsg->B2configuration = B2configuration;
  331. cmsg->B3configuration = B3configuration;
  332. }
  333. static inline void capi_fill_CONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  334. __u32 adr,
  335. __u16 Reject,
  336. __u16 B1protocol,
  337. __u16 B2protocol,
  338. __u16 B3protocol,
  339. _cstruct B1configuration,
  340. _cstruct B2configuration,
  341. _cstruct B3configuration,
  342. _cstruct ConnectedNumber,
  343. _cstruct ConnectedSubaddress,
  344. _cstruct LLC,
  345. _cstruct BChannelinformation,
  346. _cstruct Keypadfacility,
  347. _cstruct Useruserdata,
  348. _cstruct Facilitydataarray)
  349. {
  350. capi_cmsg_header(cmsg, ApplId, 0x02, 0x83, Messagenumber, adr);
  351. cmsg->Reject = Reject;
  352. cmsg->B1protocol = B1protocol;
  353. cmsg->B2protocol = B2protocol;
  354. cmsg->B3protocol = B3protocol;
  355. cmsg->B1configuration = B1configuration;
  356. cmsg->B2configuration = B2configuration;
  357. cmsg->B3configuration = B3configuration;
  358. cmsg->ConnectedNumber = ConnectedNumber;
  359. cmsg->ConnectedSubaddress = ConnectedSubaddress;
  360. cmsg->LLC = LLC;
  361. cmsg->BChannelinformation = BChannelinformation;
  362. cmsg->Keypadfacility = Keypadfacility;
  363. cmsg->Useruserdata = Useruserdata;
  364. cmsg->Facilitydataarray = Facilitydataarray;
  365. }
  366. static inline void capi_fill_CONNECT_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  367. __u32 adr)
  368. {
  369. capi_cmsg_header(cmsg, ApplId, 0x03, 0x83, Messagenumber, adr);
  370. }
  371. static inline void capi_fill_CONNECT_B3_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  372. __u32 adr)
  373. {
  374. capi_cmsg_header(cmsg, ApplId, 0x83, 0x83, Messagenumber, adr);
  375. }
  376. static inline void capi_fill_CONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  377. __u32 adr,
  378. __u16 Reject,
  379. _cstruct NCPI)
  380. {
  381. capi_cmsg_header(cmsg, ApplId, 0x82, 0x83, Messagenumber, adr);
  382. cmsg->Reject = Reject;
  383. cmsg->NCPI = NCPI;
  384. }
  385. static inline void capi_fill_CONNECT_B3_T90_ACTIVE_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  386. __u32 adr)
  387. {
  388. capi_cmsg_header(cmsg, ApplId, 0x88, 0x83, Messagenumber, adr);
  389. }
  390. static inline void capi_fill_DATA_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  391. __u32 adr,
  392. __u16 DataHandle)
  393. {
  394. capi_cmsg_header(cmsg, ApplId, 0x86, 0x83, Messagenumber, adr);
  395. cmsg->DataHandle = DataHandle;
  396. }
  397. static inline void capi_fill_DISCONNECT_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  398. __u32 adr)
  399. {
  400. capi_cmsg_header(cmsg, ApplId, 0x84, 0x83, Messagenumber, adr);
  401. }
  402. static inline void capi_fill_DISCONNECT_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  403. __u32 adr)
  404. {
  405. capi_cmsg_header(cmsg, ApplId, 0x04, 0x83, Messagenumber, adr);
  406. }
  407. static inline void capi_fill_FACILITY_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  408. __u32 adr,
  409. __u16 FacilitySelector)
  410. {
  411. capi_cmsg_header(cmsg, ApplId, 0x80, 0x83, Messagenumber, adr);
  412. cmsg->FacilitySelector = FacilitySelector;
  413. }
  414. static inline void capi_fill_INFO_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  415. __u32 adr)
  416. {
  417. capi_cmsg_header(cmsg, ApplId, 0x08, 0x83, Messagenumber, adr);
  418. }
  419. static inline void capi_fill_MANUFACTURER_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  420. __u32 adr,
  421. __u32 ManuID,
  422. __u32 Class,
  423. __u32 Function,
  424. _cstruct ManuData)
  425. {
  426. capi_cmsg_header(cmsg, ApplId, 0xff, 0x83, Messagenumber, adr);
  427. cmsg->ManuID = ManuID;
  428. cmsg->Class = Class;
  429. cmsg->Function = Function;
  430. cmsg->ManuData = ManuData;
  431. }
  432. static inline void capi_fill_RESET_B3_RESP(_cmsg * cmsg, __u16 ApplId, __u16 Messagenumber,
  433. __u32 adr)
  434. {
  435. capi_cmsg_header(cmsg, ApplId, 0x87, 0x83, Messagenumber, adr);
  436. }
  437. #endif /* __CAPIUTIL_H__ */