capiutil.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  1. /* $Id: capiutil.c,v 1.13.6.4 2001/09/23 22:24:33 kai Exp $
  2. *
  3. * CAPI 2.0 convert capi message to capi message struct
  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. #include <linux/module.h>
  13. #include <linux/string.h>
  14. #include <linux/ctype.h>
  15. #include <linux/stddef.h>
  16. #include <linux/kernel.h>
  17. #include <linux/mm.h>
  18. #include <linux/init.h>
  19. #include <linux/config.h>
  20. #include <linux/isdn/capiutil.h>
  21. /* from CAPI2.0 DDK AVM Berlin GmbH */
  22. #ifndef CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON
  23. char *capi_info2str(u16 reason)
  24. {
  25. return "..";
  26. }
  27. #else
  28. char *capi_info2str(u16 reason)
  29. {
  30. switch (reason) {
  31. /*-- informative values (corresponding message was processed) -----*/
  32. case 0x0001:
  33. return "NCPI not supported by current protocol, NCPI ignored";
  34. case 0x0002:
  35. return "Flags not supported by current protocol, flags ignored";
  36. case 0x0003:
  37. return "Alert already sent by another application";
  38. /*-- error information concerning CAPI_REGISTER -----*/
  39. case 0x1001:
  40. return "Too many applications";
  41. case 0x1002:
  42. return "Logical block size too small, must be at least 128 Bytes";
  43. case 0x1003:
  44. return "Buffer exceeds 64 kByte";
  45. case 0x1004:
  46. return "Message buffer size too small, must be at least 1024 Bytes";
  47. case 0x1005:
  48. return "Max. number of logical connections not supported";
  49. case 0x1006:
  50. return "Reserved";
  51. case 0x1007:
  52. return "The message could not be accepted because of an internal busy condition";
  53. case 0x1008:
  54. return "OS resource error (no memory ?)";
  55. case 0x1009:
  56. return "CAPI not installed";
  57. case 0x100A:
  58. return "Controller does not support external equipment";
  59. case 0x100B:
  60. return "Controller does only support external equipment";
  61. /*-- error information concerning message exchange functions -----*/
  62. case 0x1101:
  63. return "Illegal application number";
  64. case 0x1102:
  65. return "Illegal command or subcommand or message length less than 12 bytes";
  66. case 0x1103:
  67. return "The message could not be accepted because of a queue full condition !! The error code does not imply that CAPI cannot receive messages directed to another controller, PLCI or NCCI";
  68. case 0x1104:
  69. return "Queue is empty";
  70. case 0x1105:
  71. return "Queue overflow, a message was lost !! This indicates a configuration error. The only recovery from this error is to perform a CAPI_RELEASE";
  72. case 0x1106:
  73. return "Unknown notification parameter";
  74. case 0x1107:
  75. return "The Message could not be accepted because of an internal busy condition";
  76. case 0x1108:
  77. return "OS Resource error (no memory ?)";
  78. case 0x1109:
  79. return "CAPI not installed";
  80. case 0x110A:
  81. return "Controller does not support external equipment";
  82. case 0x110B:
  83. return "Controller does only support external equipment";
  84. /*-- error information concerning resource / coding problems -----*/
  85. case 0x2001:
  86. return "Message not supported in current state";
  87. case 0x2002:
  88. return "Illegal Controller / PLCI / NCCI";
  89. case 0x2003:
  90. return "Out of PLCI";
  91. case 0x2004:
  92. return "Out of NCCI";
  93. case 0x2005:
  94. return "Out of LISTEN";
  95. case 0x2006:
  96. return "Out of FAX resources (protocol T.30)";
  97. case 0x2007:
  98. return "Illegal message parameter coding";
  99. /*-- error information concerning requested services -----*/
  100. case 0x3001:
  101. return "B1 protocol not supported";
  102. case 0x3002:
  103. return "B2 protocol not supported";
  104. case 0x3003:
  105. return "B3 protocol not supported";
  106. case 0x3004:
  107. return "B1 protocol parameter not supported";
  108. case 0x3005:
  109. return "B2 protocol parameter not supported";
  110. case 0x3006:
  111. return "B3 protocol parameter not supported";
  112. case 0x3007:
  113. return "B protocol combination not supported";
  114. case 0x3008:
  115. return "NCPI not supported";
  116. case 0x3009:
  117. return "CIP Value unknown";
  118. case 0x300A:
  119. return "Flags not supported (reserved bits)";
  120. case 0x300B:
  121. return "Facility not supported";
  122. case 0x300C:
  123. return "Data length not supported by current protocol";
  124. case 0x300D:
  125. return "Reset procedure not supported by current protocol";
  126. /*-- informations about the clearing of a physical connection -----*/
  127. case 0x3301:
  128. return "Protocol error layer 1 (broken line or B-channel removed by signalling protocol)";
  129. case 0x3302:
  130. return "Protocol error layer 2";
  131. case 0x3303:
  132. return "Protocol error layer 3";
  133. case 0x3304:
  134. return "Another application got that call";
  135. /*-- T.30 specific reasons -----*/
  136. case 0x3311:
  137. return "Connecting not successful (remote station is no FAX G3 machine)";
  138. case 0x3312:
  139. return "Connecting not successful (training error)";
  140. case 0x3313:
  141. return "Disconnected before transfer (remote station does not support transfer mode, e.g. resolution)";
  142. case 0x3314:
  143. return "Disconnected during transfer (remote abort)";
  144. case 0x3315:
  145. return "Disconnected during transfer (remote procedure error, e.g. unsuccessful repetition of T.30 commands)";
  146. case 0x3316:
  147. return "Disconnected during transfer (local tx data underrun)";
  148. case 0x3317:
  149. return "Disconnected during transfer (local rx data overflow)";
  150. case 0x3318:
  151. return "Disconnected during transfer (local abort)";
  152. case 0x3319:
  153. return "Illegal parameter coding (e.g. SFF coding error)";
  154. /*-- disconnect causes from the network according to ETS 300 102-1/Q.931 -----*/
  155. case 0x3481: return "Unallocated (unassigned) number";
  156. case 0x3482: return "No route to specified transit network";
  157. case 0x3483: return "No route to destination";
  158. case 0x3486: return "Channel unacceptable";
  159. case 0x3487:
  160. return "Call awarded and being delivered in an established channel";
  161. case 0x3490: return "Normal call clearing";
  162. case 0x3491: return "User busy";
  163. case 0x3492: return "No user responding";
  164. case 0x3493: return "No answer from user (user alerted)";
  165. case 0x3495: return "Call rejected";
  166. case 0x3496: return "Number changed";
  167. case 0x349A: return "Non-selected user clearing";
  168. case 0x349B: return "Destination out of order";
  169. case 0x349C: return "Invalid number format";
  170. case 0x349D: return "Facility rejected";
  171. case 0x349E: return "Response to STATUS ENQUIRY";
  172. case 0x349F: return "Normal, unspecified";
  173. case 0x34A2: return "No circuit / channel available";
  174. case 0x34A6: return "Network out of order";
  175. case 0x34A9: return "Temporary failure";
  176. case 0x34AA: return "Switching equipment congestion";
  177. case 0x34AB: return "Access information discarded";
  178. case 0x34AC: return "Requested circuit / channel not available";
  179. case 0x34AF: return "Resources unavailable, unspecified";
  180. case 0x34B1: return "Quality of service unavailable";
  181. case 0x34B2: return "Requested facility not subscribed";
  182. case 0x34B9: return "Bearer capability not authorized";
  183. case 0x34BA: return "Bearer capability not presently available";
  184. case 0x34BF: return "Service or option not available, unspecified";
  185. case 0x34C1: return "Bearer capability not implemented";
  186. case 0x34C2: return "Channel type not implemented";
  187. case 0x34C5: return "Requested facility not implemented";
  188. case 0x34C6: return "Only restricted digital information bearer capability is available";
  189. case 0x34CF: return "Service or option not implemented, unspecified";
  190. case 0x34D1: return "Invalid call reference value";
  191. case 0x34D2: return "Identified channel does not exist";
  192. case 0x34D3: return "A suspended call exists, but this call identity does not";
  193. case 0x34D4: return "Call identity in use";
  194. case 0x34D5: return "No call suspended";
  195. case 0x34D6: return "Call having the requested call identity has been cleared";
  196. case 0x34D8: return "Incompatible destination";
  197. case 0x34DB: return "Invalid transit network selection";
  198. case 0x34DF: return "Invalid message, unspecified";
  199. case 0x34E0: return "Mandatory information element is missing";
  200. case 0x34E1: return "Message type non-existent or not implemented";
  201. case 0x34E2: return "Message not compatible with call state or message type non-existent or not implemented";
  202. case 0x34E3: return "Information element non-existent or not implemented";
  203. case 0x34E4: return "Invalid information element contents";
  204. case 0x34E5: return "Message not compatible with call state";
  205. case 0x34E6: return "Recovery on timer expiry";
  206. case 0x34EF: return "Protocol error, unspecified";
  207. case 0x34FF: return "Interworking, unspecified";
  208. default: return "No additional information";
  209. }
  210. }
  211. #endif
  212. typedef struct {
  213. int typ;
  214. size_t off;
  215. } _cdef;
  216. #define _CBYTE 1
  217. #define _CWORD 2
  218. #define _CDWORD 3
  219. #define _CSTRUCT 4
  220. #define _CMSTRUCT 5
  221. #define _CEND 6
  222. static _cdef cdef[] =
  223. {
  224. /*00 */
  225. {_CEND},
  226. /*01 */
  227. {_CEND},
  228. /*02 */
  229. {_CEND},
  230. /*03 */
  231. {_CDWORD, offsetof(_cmsg, adr.adrController)},
  232. /*04 */
  233. {_CMSTRUCT, offsetof(_cmsg, AdditionalInfo)},
  234. /*05 */
  235. {_CSTRUCT, offsetof(_cmsg, B1configuration)},
  236. /*06 */
  237. {_CWORD, offsetof(_cmsg, B1protocol)},
  238. /*07 */
  239. {_CSTRUCT, offsetof(_cmsg, B2configuration)},
  240. /*08 */
  241. {_CWORD, offsetof(_cmsg, B2protocol)},
  242. /*09 */
  243. {_CSTRUCT, offsetof(_cmsg, B3configuration)},
  244. /*0a */
  245. {_CWORD, offsetof(_cmsg, B3protocol)},
  246. /*0b */
  247. {_CSTRUCT, offsetof(_cmsg, BC)},
  248. /*0c */
  249. {_CSTRUCT, offsetof(_cmsg, BChannelinformation)},
  250. /*0d */
  251. {_CMSTRUCT, offsetof(_cmsg, BProtocol)},
  252. /*0e */
  253. {_CSTRUCT, offsetof(_cmsg, CalledPartyNumber)},
  254. /*0f */
  255. {_CSTRUCT, offsetof(_cmsg, CalledPartySubaddress)},
  256. /*10 */
  257. {_CSTRUCT, offsetof(_cmsg, CallingPartyNumber)},
  258. /*11 */
  259. {_CSTRUCT, offsetof(_cmsg, CallingPartySubaddress)},
  260. /*12 */
  261. {_CDWORD, offsetof(_cmsg, CIPmask)},
  262. /*13 */
  263. {_CDWORD, offsetof(_cmsg, CIPmask2)},
  264. /*14 */
  265. {_CWORD, offsetof(_cmsg, CIPValue)},
  266. /*15 */
  267. {_CDWORD, offsetof(_cmsg, Class)},
  268. /*16 */
  269. {_CSTRUCT, offsetof(_cmsg, ConnectedNumber)},
  270. /*17 */
  271. {_CSTRUCT, offsetof(_cmsg, ConnectedSubaddress)},
  272. /*18 */
  273. {_CDWORD, offsetof(_cmsg, Data)},
  274. /*19 */
  275. {_CWORD, offsetof(_cmsg, DataHandle)},
  276. /*1a */
  277. {_CWORD, offsetof(_cmsg, DataLength)},
  278. /*1b */
  279. {_CSTRUCT, offsetof(_cmsg, FacilityConfirmationParameter)},
  280. /*1c */
  281. {_CSTRUCT, offsetof(_cmsg, Facilitydataarray)},
  282. /*1d */
  283. {_CSTRUCT, offsetof(_cmsg, FacilityIndicationParameter)},
  284. /*1e */
  285. {_CSTRUCT, offsetof(_cmsg, FacilityRequestParameter)},
  286. /*1f */
  287. {_CWORD, offsetof(_cmsg, FacilitySelector)},
  288. /*20 */
  289. {_CWORD, offsetof(_cmsg, Flags)},
  290. /*21 */
  291. {_CDWORD, offsetof(_cmsg, Function)},
  292. /*22 */
  293. {_CSTRUCT, offsetof(_cmsg, HLC)},
  294. /*23 */
  295. {_CWORD, offsetof(_cmsg, Info)},
  296. /*24 */
  297. {_CSTRUCT, offsetof(_cmsg, InfoElement)},
  298. /*25 */
  299. {_CDWORD, offsetof(_cmsg, InfoMask)},
  300. /*26 */
  301. {_CWORD, offsetof(_cmsg, InfoNumber)},
  302. /*27 */
  303. {_CSTRUCT, offsetof(_cmsg, Keypadfacility)},
  304. /*28 */
  305. {_CSTRUCT, offsetof(_cmsg, LLC)},
  306. /*29 */
  307. {_CSTRUCT, offsetof(_cmsg, ManuData)},
  308. /*2a */
  309. {_CDWORD, offsetof(_cmsg, ManuID)},
  310. /*2b */
  311. {_CSTRUCT, offsetof(_cmsg, NCPI)},
  312. /*2c */
  313. {_CWORD, offsetof(_cmsg, Reason)},
  314. /*2d */
  315. {_CWORD, offsetof(_cmsg, Reason_B3)},
  316. /*2e */
  317. {_CWORD, offsetof(_cmsg, Reject)},
  318. /*2f */
  319. {_CSTRUCT, offsetof(_cmsg, Useruserdata)}
  320. };
  321. static unsigned char *cpars[] =
  322. {
  323. /* ALERT_REQ */ [0x01] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
  324. /* CONNECT_REQ */ [0x02] = "\x03\x14\x0e\x10\x0f\x11\x0d\x06\x08\x0a\x05\x07\x09\x01\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
  325. /* DISCONNECT_REQ */ [0x04] = "\x03\x04\x0c\x27\x2f\x1c\x01\x01",
  326. /* LISTEN_REQ */ [0x05] = "\x03\x25\x12\x13\x10\x11\x01",
  327. /* INFO_REQ */ [0x08] = "\x03\x0e\x04\x0c\x27\x2f\x1c\x01\x01",
  328. /* FACILITY_REQ */ [0x09] = "\x03\x1f\x1e\x01",
  329. /* SELECT_B_PROTOCOL_REQ */ [0x0a] = "\x03\x0d\x06\x08\x0a\x05\x07\x09\x01\x01",
  330. /* CONNECT_B3_REQ */ [0x0b] = "\x03\x2b\x01",
  331. /* DISCONNECT_B3_REQ */ [0x0d] = "\x03\x2b\x01",
  332. /* DATA_B3_REQ */ [0x0f] = "\x03\x18\x1a\x19\x20\x01",
  333. /* RESET_B3_REQ */ [0x10] = "\x03\x2b\x01",
  334. /* ALERT_CONF */ [0x13] = "\x03\x23\x01",
  335. /* CONNECT_CONF */ [0x14] = "\x03\x23\x01",
  336. /* DISCONNECT_CONF */ [0x16] = "\x03\x23\x01",
  337. /* LISTEN_CONF */ [0x17] = "\x03\x23\x01",
  338. /* MANUFACTURER_REQ */ [0x18] = "\x03\x2a\x15\x21\x29\x01",
  339. /* INFO_CONF */ [0x1a] = "\x03\x23\x01",
  340. /* FACILITY_CONF */ [0x1b] = "\x03\x23\x1f\x1b\x01",
  341. /* SELECT_B_PROTOCOL_CONF */ [0x1c] = "\x03\x23\x01",
  342. /* CONNECT_B3_CONF */ [0x1d] = "\x03\x23\x01",
  343. /* DISCONNECT_B3_CONF */ [0x1f] = "\x03\x23\x01",
  344. /* DATA_B3_CONF */ [0x21] = "\x03\x19\x23\x01",
  345. /* RESET_B3_CONF */ [0x22] = "\x03\x23\x01",
  346. /* CONNECT_IND */ [0x26] = "\x03\x14\x0e\x10\x0f\x11\x0b\x28\x22\x04\x0c\x27\x2f\x1c\x01\x01",
  347. /* CONNECT_ACTIVE_IND */ [0x27] = "\x03\x16\x17\x28\x01",
  348. /* DISCONNECT_IND */ [0x28] = "\x03\x2c\x01",
  349. /* MANUFACTURER_CONF */ [0x2a] = "\x03\x2a\x15\x21\x29\x01",
  350. /* INFO_IND */ [0x2c] = "\x03\x26\x24\x01",
  351. /* FACILITY_IND */ [0x2d] = "\x03\x1f\x1d\x01",
  352. /* CONNECT_B3_IND */ [0x2f] = "\x03\x2b\x01",
  353. /* CONNECT_B3_ACTIVE_IND */ [0x30] = "\x03\x2b\x01",
  354. /* DISCONNECT_B3_IND */ [0x31] = "\x03\x2d\x2b\x01",
  355. /* DATA_B3_IND */ [0x33] = "\x03\x18\x1a\x19\x20\x01",
  356. /* RESET_B3_IND */ [0x34] = "\x03\x2b\x01",
  357. /* CONNECT_B3_T90_ACTIVE_IND */ [0x35] = "\x03\x2b\x01",
  358. /* CONNECT_RESP */ [0x38] = "\x03\x2e\x0d\x06\x08\x0a\x05\x07\x09\x01\x16\x17\x28\x04\x0c\x27\x2f\x1c\x01\x01",
  359. /* CONNECT_ACTIVE_RESP */ [0x39] = "\x03\x01",
  360. /* DISCONNECT_RESP */ [0x3a] = "\x03\x01",
  361. /* MANUFACTURER_IND */ [0x3c] = "\x03\x2a\x15\x21\x29\x01",
  362. /* INFO_RESP */ [0x3e] = "\x03\x01",
  363. /* FACILITY_RESP */ [0x3f] = "\x03\x1f\x01",
  364. /* CONNECT_B3_RESP */ [0x41] = "\x03\x2e\x2b\x01",
  365. /* CONNECT_B3_ACTIVE_RESP */ [0x42] = "\x03\x01",
  366. /* DISCONNECT_B3_RESP */ [0x43] = "\x03\x01",
  367. /* DATA_B3_RESP */ [0x45] = "\x03\x19\x01",
  368. /* RESET_B3_RESP */ [0x46] = "\x03\x01",
  369. /* CONNECT_B3_T90_ACTIVE_RESP */ [0x47] = "\x03\x01",
  370. /* MANUFACTURER_RESP */ [0x4e] = "\x03\x2a\x15\x21\x29\x01",
  371. };
  372. /*-------------------------------------------------------*/
  373. #define byteTLcpy(x,y) *(u8 *)(x)=*(u8 *)(y);
  374. #define wordTLcpy(x,y) *(u16 *)(x)=*(u16 *)(y);
  375. #define dwordTLcpy(x,y) memcpy(x,y,4);
  376. #define structTLcpy(x,y,l) memcpy (x,y,l)
  377. #define structTLcpyovl(x,y,l) memmove (x,y,l)
  378. #define byteTRcpy(x,y) *(u8 *)(y)=*(u8 *)(x);
  379. #define wordTRcpy(x,y) *(u16 *)(y)=*(u16 *)(x);
  380. #define dwordTRcpy(x,y) memcpy(y,x,4);
  381. #define structTRcpy(x,y,l) memcpy (y,x,l)
  382. #define structTRcpyovl(x,y,l) memmove (y,x,l)
  383. /*-------------------------------------------------------*/
  384. static unsigned command_2_index(unsigned c, unsigned sc)
  385. {
  386. if (c & 0x80)
  387. c = 0x9 + (c & 0x0f);
  388. else if (c <= 0x0f);
  389. else if (c == 0x41)
  390. c = 0x9 + 0x1;
  391. else if (c == 0xff)
  392. c = 0x00;
  393. return (sc & 3) * (0x9 + 0x9) + c;
  394. }
  395. /*-------------------------------------------------------*/
  396. #define TYP (cdef[cmsg->par[cmsg->p]].typ)
  397. #define OFF (((u8 *)cmsg)+cdef[cmsg->par[cmsg->p]].off)
  398. static void jumpcstruct(_cmsg * cmsg)
  399. {
  400. unsigned layer;
  401. for (cmsg->p++, layer = 1; layer;) {
  402. /* $$$$$ assert (cmsg->p); */
  403. cmsg->p++;
  404. switch (TYP) {
  405. case _CMSTRUCT:
  406. layer++;
  407. break;
  408. case _CEND:
  409. layer--;
  410. break;
  411. }
  412. }
  413. }
  414. /*-------------------------------------------------------*/
  415. static void pars_2_message(_cmsg * cmsg)
  416. {
  417. for (; TYP != _CEND; cmsg->p++) {
  418. switch (TYP) {
  419. case _CBYTE:
  420. byteTLcpy(cmsg->m + cmsg->l, OFF);
  421. cmsg->l++;
  422. break;
  423. case _CWORD:
  424. wordTLcpy(cmsg->m + cmsg->l, OFF);
  425. cmsg->l += 2;
  426. break;
  427. case _CDWORD:
  428. dwordTLcpy(cmsg->m + cmsg->l, OFF);
  429. cmsg->l += 4;
  430. break;
  431. case _CSTRUCT:
  432. if (*(u8 **) OFF == 0) {
  433. *(cmsg->m + cmsg->l) = '\0';
  434. cmsg->l++;
  435. } else if (**(_cstruct *) OFF != 0xff) {
  436. structTLcpy(cmsg->m + cmsg->l, *(_cstruct *) OFF, 1 + **(_cstruct *) OFF);
  437. cmsg->l += 1 + **(_cstruct *) OFF;
  438. } else {
  439. _cstruct s = *(_cstruct *) OFF;
  440. structTLcpy(cmsg->m + cmsg->l, s, 3 + *(u16 *) (s + 1));
  441. cmsg->l += 3 + *(u16 *) (s + 1);
  442. }
  443. break;
  444. case _CMSTRUCT:
  445. /*----- Metastruktur 0 -----*/
  446. if (*(_cmstruct *) OFF == CAPI_DEFAULT) {
  447. *(cmsg->m + cmsg->l) = '\0';
  448. cmsg->l++;
  449. jumpcstruct(cmsg);
  450. }
  451. /*----- Metastruktur wird composed -----*/
  452. else {
  453. unsigned _l = cmsg->l;
  454. unsigned _ls;
  455. cmsg->l++;
  456. cmsg->p++;
  457. pars_2_message(cmsg);
  458. _ls = cmsg->l - _l - 1;
  459. if (_ls < 255)
  460. (cmsg->m + _l)[0] = (u8) _ls;
  461. else {
  462. structTLcpyovl(cmsg->m + _l + 3, cmsg->m + _l + 1, _ls);
  463. (cmsg->m + _l)[0] = 0xff;
  464. wordTLcpy(cmsg->m + _l + 1, &_ls);
  465. }
  466. }
  467. break;
  468. }
  469. }
  470. }
  471. /*-------------------------------------------------------*/
  472. unsigned capi_cmsg2message(_cmsg * cmsg, u8 * msg)
  473. {
  474. cmsg->m = msg;
  475. cmsg->l = 8;
  476. cmsg->p = 0;
  477. cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
  478. pars_2_message(cmsg);
  479. wordTLcpy(msg + 0, &cmsg->l);
  480. byteTLcpy(cmsg->m + 4, &cmsg->Command);
  481. byteTLcpy(cmsg->m + 5, &cmsg->Subcommand);
  482. wordTLcpy(cmsg->m + 2, &cmsg->ApplId);
  483. wordTLcpy(cmsg->m + 6, &cmsg->Messagenumber);
  484. return 0;
  485. }
  486. /*-------------------------------------------------------*/
  487. static void message_2_pars(_cmsg * cmsg)
  488. {
  489. for (; TYP != _CEND; cmsg->p++) {
  490. switch (TYP) {
  491. case _CBYTE:
  492. byteTRcpy(cmsg->m + cmsg->l, OFF);
  493. cmsg->l++;
  494. break;
  495. case _CWORD:
  496. wordTRcpy(cmsg->m + cmsg->l, OFF);
  497. cmsg->l += 2;
  498. break;
  499. case _CDWORD:
  500. dwordTRcpy(cmsg->m + cmsg->l, OFF);
  501. cmsg->l += 4;
  502. break;
  503. case _CSTRUCT:
  504. *(u8 **) OFF = cmsg->m + cmsg->l;
  505. if (cmsg->m[cmsg->l] != 0xff)
  506. cmsg->l += 1 + cmsg->m[cmsg->l];
  507. else
  508. cmsg->l += 3 + *(u16 *) (cmsg->m + cmsg->l + 1);
  509. break;
  510. case _CMSTRUCT:
  511. /*----- Metastruktur 0 -----*/
  512. if (cmsg->m[cmsg->l] == '\0') {
  513. *(_cmstruct *) OFF = CAPI_DEFAULT;
  514. cmsg->l++;
  515. jumpcstruct(cmsg);
  516. } else {
  517. unsigned _l = cmsg->l;
  518. *(_cmstruct *) OFF = CAPI_COMPOSE;
  519. cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
  520. cmsg->p++;
  521. message_2_pars(cmsg);
  522. }
  523. break;
  524. }
  525. }
  526. }
  527. /*-------------------------------------------------------*/
  528. unsigned capi_message2cmsg(_cmsg * cmsg, u8 * msg)
  529. {
  530. memset(cmsg, 0, sizeof(_cmsg));
  531. cmsg->m = msg;
  532. cmsg->l = 8;
  533. cmsg->p = 0;
  534. byteTRcpy(cmsg->m + 4, &cmsg->Command);
  535. byteTRcpy(cmsg->m + 5, &cmsg->Subcommand);
  536. cmsg->par = cpars[command_2_index(cmsg->Command, cmsg->Subcommand)];
  537. message_2_pars(cmsg);
  538. wordTRcpy(msg + 0, &cmsg->l);
  539. wordTRcpy(cmsg->m + 2, &cmsg->ApplId);
  540. wordTRcpy(cmsg->m + 6, &cmsg->Messagenumber);
  541. return 0;
  542. }
  543. /*-------------------------------------------------------*/
  544. unsigned capi_cmsg_header(_cmsg * cmsg, u16 _ApplId,
  545. u8 _Command, u8 _Subcommand,
  546. u16 _Messagenumber, u32 _Controller)
  547. {
  548. memset(cmsg, 0, sizeof(_cmsg));
  549. cmsg->ApplId = _ApplId;
  550. cmsg->Command = _Command;
  551. cmsg->Subcommand = _Subcommand;
  552. cmsg->Messagenumber = _Messagenumber;
  553. cmsg->adr.adrController = _Controller;
  554. return 0;
  555. }
  556. /*-------------------------------------------------------*/
  557. static char *mnames[] =
  558. {
  559. [0x01] = "ALERT_REQ",
  560. [0x02] = "CONNECT_REQ",
  561. [0x04] = "DISCONNECT_REQ",
  562. [0x05] = "LISTEN_REQ",
  563. [0x08] = "INFO_REQ",
  564. [0x09] = "FACILITY_REQ",
  565. [0x0a] = "SELECT_B_PROTOCOL_REQ",
  566. [0x0b] = "CONNECT_B3_REQ",
  567. [0x0d] = "DISCONNECT_B3_REQ",
  568. [0x0f] = "DATA_B3_REQ",
  569. [0x10] = "RESET_B3_REQ",
  570. [0x13] = "ALERT_CONF",
  571. [0x14] = "CONNECT_CONF",
  572. [0x16] = "DISCONNECT_CONF",
  573. [0x17] = "LISTEN_CONF",
  574. [0x18] = "MANUFACTURER_REQ",
  575. [0x1a] = "INFO_CONF",
  576. [0x1b] = "FACILITY_CONF",
  577. [0x1c] = "SELECT_B_PROTOCOL_CONF",
  578. [0x1d] = "CONNECT_B3_CONF",
  579. [0x1f] = "DISCONNECT_B3_CONF",
  580. [0x21] = "DATA_B3_CONF",
  581. [0x22] = "RESET_B3_CONF",
  582. [0x26] = "CONNECT_IND",
  583. [0x27] = "CONNECT_ACTIVE_IND",
  584. [0x28] = "DISCONNECT_IND",
  585. [0x2a] = "MANUFACTURER_CONF",
  586. [0x2c] = "INFO_IND",
  587. [0x2d] = "FACILITY_IND",
  588. [0x2f] = "CONNECT_B3_IND",
  589. [0x30] = "CONNECT_B3_ACTIVE_IND",
  590. [0x31] = "DISCONNECT_B3_IND",
  591. [0x33] = "DATA_B3_IND",
  592. [0x34] = "RESET_B3_IND",
  593. [0x35] = "CONNECT_B3_T90_ACTIVE_IND",
  594. [0x38] = "CONNECT_RESP",
  595. [0x39] = "CONNECT_ACTIVE_RESP",
  596. [0x3a] = "DISCONNECT_RESP",
  597. [0x3c] = "MANUFACTURER_IND",
  598. [0x3e] = "INFO_RESP",
  599. [0x3f] = "FACILITY_RESP",
  600. [0x41] = "CONNECT_B3_RESP",
  601. [0x42] = "CONNECT_B3_ACTIVE_RESP",
  602. [0x43] = "DISCONNECT_B3_RESP",
  603. [0x45] = "DATA_B3_RESP",
  604. [0x46] = "RESET_B3_RESP",
  605. [0x47] = "CONNECT_B3_T90_ACTIVE_RESP",
  606. [0x4e] = "MANUFACTURER_RESP"
  607. };
  608. char *capi_cmd2str(u8 cmd, u8 subcmd)
  609. {
  610. return mnames[command_2_index(cmd, subcmd)];
  611. }
  612. /*-------------------------------------------------------*/
  613. /*-------------------------------------------------------*/
  614. static char *pnames[] =
  615. {
  616. /*00 */ NULL,
  617. /*01 */ NULL,
  618. /*02 */ NULL,
  619. /*03 */ "Controller/PLCI/NCCI",
  620. /*04 */ "AdditionalInfo",
  621. /*05 */ "B1configuration",
  622. /*06 */ "B1protocol",
  623. /*07 */ "B2configuration",
  624. /*08 */ "B2protocol",
  625. /*09 */ "B3configuration",
  626. /*0a */ "B3protocol",
  627. /*0b */ "BC",
  628. /*0c */ "BChannelinformation",
  629. /*0d */ "BProtocol",
  630. /*0e */ "CalledPartyNumber",
  631. /*0f */ "CalledPartySubaddress",
  632. /*10 */ "CallingPartyNumber",
  633. /*11 */ "CallingPartySubaddress",
  634. /*12 */ "CIPmask",
  635. /*13 */ "CIPmask2",
  636. /*14 */ "CIPValue",
  637. /*15 */ "Class",
  638. /*16 */ "ConnectedNumber",
  639. /*17 */ "ConnectedSubaddress",
  640. /*18 */ "Data32",
  641. /*19 */ "DataHandle",
  642. /*1a */ "DataLength",
  643. /*1b */ "FacilityConfirmationParameter",
  644. /*1c */ "Facilitydataarray",
  645. /*1d */ "FacilityIndicationParameter",
  646. /*1e */ "FacilityRequestParameter",
  647. /*1f */ "FacilitySelector",
  648. /*20 */ "Flags",
  649. /*21 */ "Function",
  650. /*22 */ "HLC",
  651. /*23 */ "Info",
  652. /*24 */ "InfoElement",
  653. /*25 */ "InfoMask",
  654. /*26 */ "InfoNumber",
  655. /*27 */ "Keypadfacility",
  656. /*28 */ "LLC",
  657. /*29 */ "ManuData",
  658. /*2a */ "ManuID",
  659. /*2b */ "NCPI",
  660. /*2c */ "Reason",
  661. /*2d */ "Reason_B3",
  662. /*2e */ "Reject",
  663. /*2f */ "Useruserdata"
  664. };
  665. static char buf[8192];
  666. static char *p = NULL;
  667. #include <stdarg.h>
  668. /*-------------------------------------------------------*/
  669. static void bufprint(char *fmt,...)
  670. {
  671. va_list f;
  672. va_start(f, fmt);
  673. vsprintf(p, fmt, f);
  674. va_end(f);
  675. p += strlen(p);
  676. }
  677. static void printstructlen(u8 * m, unsigned len)
  678. {
  679. unsigned hex = 0;
  680. for (; len; len--, m++)
  681. if (isalnum(*m) || *m == ' ') {
  682. if (hex)
  683. bufprint(">");
  684. bufprint("%c", *m);
  685. hex = 0;
  686. } else {
  687. if (!hex)
  688. bufprint("<%02x", *m);
  689. else
  690. bufprint(" %02x", *m);
  691. hex = 1;
  692. }
  693. if (hex)
  694. bufprint(">");
  695. }
  696. static void printstruct(u8 * m)
  697. {
  698. unsigned len;
  699. if (m[0] != 0xff) {
  700. len = m[0];
  701. m += 1;
  702. } else {
  703. len = ((u16 *) (m + 1))[0];
  704. m += 3;
  705. }
  706. printstructlen(m, len);
  707. }
  708. /*-------------------------------------------------------*/
  709. #define NAME (pnames[cmsg->par[cmsg->p]])
  710. static void protocol_message_2_pars(_cmsg * cmsg, int level)
  711. {
  712. for (; TYP != _CEND; cmsg->p++) {
  713. int slen = 29 + 3 - level;
  714. int i;
  715. bufprint(" ");
  716. for (i = 0; i < level - 1; i++)
  717. bufprint(" ");
  718. switch (TYP) {
  719. case _CBYTE:
  720. bufprint("%-*s = 0x%x\n", slen, NAME, *(u8 *) (cmsg->m + cmsg->l));
  721. cmsg->l++;
  722. break;
  723. case _CWORD:
  724. bufprint("%-*s = 0x%x\n", slen, NAME, *(u16 *) (cmsg->m + cmsg->l));
  725. cmsg->l += 2;
  726. break;
  727. case _CDWORD:
  728. bufprint("%-*s = 0x%lx\n", slen, NAME, *(u32 *) (cmsg->m + cmsg->l));
  729. cmsg->l += 4;
  730. break;
  731. case _CSTRUCT:
  732. bufprint("%-*s = ", slen, NAME);
  733. if (cmsg->m[cmsg->l] == '\0')
  734. bufprint("default");
  735. else
  736. printstruct(cmsg->m + cmsg->l);
  737. bufprint("\n");
  738. if (cmsg->m[cmsg->l] != 0xff)
  739. cmsg->l += 1 + cmsg->m[cmsg->l];
  740. else
  741. cmsg->l += 3 + *(u16 *) (cmsg->m + cmsg->l + 1);
  742. break;
  743. case _CMSTRUCT:
  744. /*----- Metastruktur 0 -----*/
  745. if (cmsg->m[cmsg->l] == '\0') {
  746. bufprint("%-*s = default\n", slen, NAME);
  747. cmsg->l++;
  748. jumpcstruct(cmsg);
  749. } else {
  750. char *name = NAME;
  751. unsigned _l = cmsg->l;
  752. bufprint("%-*s\n", slen, name);
  753. cmsg->l = (cmsg->m + _l)[0] == 255 ? cmsg->l + 3 : cmsg->l + 1;
  754. cmsg->p++;
  755. protocol_message_2_pars(cmsg, level + 1);
  756. }
  757. break;
  758. }
  759. }
  760. }
  761. /*-------------------------------------------------------*/
  762. char *capi_message2str(u8 * msg)
  763. {
  764. _cmsg cmsg;
  765. p = buf;
  766. p[0] = 0;
  767. cmsg.m = msg;
  768. cmsg.l = 8;
  769. cmsg.p = 0;
  770. byteTRcpy(cmsg.m + 4, &cmsg.Command);
  771. byteTRcpy(cmsg.m + 5, &cmsg.Subcommand);
  772. cmsg.par = cpars[command_2_index(cmsg.Command, cmsg.Subcommand)];
  773. bufprint("%-26s ID=%03d #0x%04x LEN=%04d\n",
  774. mnames[command_2_index(cmsg.Command, cmsg.Subcommand)],
  775. ((unsigned short *) msg)[1],
  776. ((unsigned short *) msg)[3],
  777. ((unsigned short *) msg)[0]);
  778. protocol_message_2_pars(&cmsg, 1);
  779. return buf;
  780. }
  781. char *capi_cmsg2str(_cmsg * cmsg)
  782. {
  783. p = buf;
  784. p[0] = 0;
  785. cmsg->l = 8;
  786. cmsg->p = 0;
  787. bufprint("%s ID=%03d #0x%04x LEN=%04d\n",
  788. mnames[command_2_index(cmsg->Command, cmsg->Subcommand)],
  789. ((u16 *) cmsg->m)[1],
  790. ((u16 *) cmsg->m)[3],
  791. ((u16 *) cmsg->m)[0]);
  792. protocol_message_2_pars(cmsg, 1);
  793. return buf;
  794. }
  795. EXPORT_SYMBOL(capi_cmsg2message);
  796. EXPORT_SYMBOL(capi_message2cmsg);
  797. EXPORT_SYMBOL(capi_cmsg_header);
  798. EXPORT_SYMBOL(capi_cmd2str);
  799. EXPORT_SYMBOL(capi_cmsg2str);
  800. EXPORT_SYMBOL(capi_message2str);
  801. EXPORT_SYMBOL(capi_info2str);