capiutil.c 25 KB

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