isdn_msg_parser.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769
  1. /*
  2. * Chan_Misdn -- Channel Driver for Asterisk
  3. *
  4. * Interface to mISDN
  5. *
  6. * Copyright (C) 2004, Christian Richter
  7. *
  8. * Christian Richter <crich@beronet.com>
  9. *
  10. * This program is free software, distributed under the terms of
  11. * the GNU General Public License
  12. */
  13. /*! \file
  14. * \brief Interface to mISDN - message parser
  15. * \author Christian Richter <crich@beronet.com>
  16. */
  17. /*** MODULEINFO
  18. <support_level>extended</support_level>
  19. ***/
  20. #include "isdn_lib_intern.h"
  21. #include "isdn_lib.h"
  22. #include "ie.c"
  23. /*!
  24. * \internal
  25. * \brief Build the name, number, name/number display message string
  26. *
  27. * \param display Display buffer to fill in
  28. * \param display_length Length of the display buffer to fill in
  29. * \param display_format Display format enumeration
  30. * \param name Name string to use
  31. * \param number Number string to use
  32. *
  33. * \return Nothing
  34. */
  35. static void build_display_str(char *display, size_t display_length, int display_format, const char *name, const char *number)
  36. {
  37. display[0] = 0;
  38. switch (display_format) {
  39. default:
  40. case 0: /* none */
  41. break;
  42. case 1: /* name */
  43. snprintf(display, display_length, "%s", name);
  44. break;
  45. case 2: /* number */
  46. snprintf(display, display_length, "%s", number);
  47. break;
  48. case 3: /* both */
  49. if (name[0] || number[0]) {
  50. snprintf(display, display_length, "\"%s\" <%s>", name, number);
  51. }
  52. break;
  53. }
  54. }
  55. /*!
  56. * \internal
  57. * \brief Encode the Facility IE and put it into the message structure.
  58. *
  59. * \param ntmode Where the encoded facility was put when in NT mode.
  60. * \param msg General message structure
  61. * \param fac Data to encode into the facility ie.
  62. * \param nt TRUE if in NT mode.
  63. *
  64. * \return Nothing
  65. */
  66. static void enc_ie_facility(unsigned char **ntmode, msg_t *msg, struct FacParm *fac, int nt)
  67. {
  68. int len;
  69. Q931_info_t *qi;
  70. unsigned char *p;
  71. unsigned char buf[256];
  72. len = encodeFac(buf, fac);
  73. if (len <= 0) {
  74. /*
  75. * mISDN does not know how to build the requested facility structure
  76. * Clear facility information
  77. */
  78. fac->Function = Fac_None;
  79. return;
  80. }
  81. p = msg_put(msg, len);
  82. if (nt) {
  83. *ntmode = p + 1;
  84. } else {
  85. qi = (Q931_info_t *) (msg->data + mISDN_HEADER_LEN);
  86. qi->QI_ELEMENT(facility) = p - (unsigned char *) qi - sizeof(Q931_info_t);
  87. }
  88. memcpy(p, buf, len);
  89. /* Clear facility information */
  90. fac->Function = Fac_None;
  91. }
  92. /*!
  93. * \internal
  94. * \brief Decode the Facility IE.
  95. *
  96. * \param p Encoded facility ie data to decode. (NT mode)
  97. * \param qi Encoded facility ie data to decode. (TE mode)
  98. * \param fac Where to put the decoded facility ie data if it is available.
  99. * \param nt TRUE if in NT mode.
  100. * \param bc Associated B channel
  101. *
  102. * \return Nothing
  103. */
  104. static void dec_ie_facility(unsigned char *p, Q931_info_t *qi, struct FacParm *fac, int nt, struct misdn_bchannel *bc)
  105. {
  106. fac->Function = Fac_None;
  107. if (!nt) {
  108. p = NULL;
  109. if (qi->QI_ELEMENT(facility)) {
  110. p = (unsigned char *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
  111. }
  112. }
  113. if (!p) {
  114. return;
  115. }
  116. if (decodeFac(p, fac)) {
  117. cb_log(3, bc->port, "Decoding facility ie failed! Unrecognized facility message?\n");
  118. }
  119. }
  120. static void set_channel(struct misdn_bchannel *bc, int channel)
  121. {
  122. cb_log(3,bc->port,"set_channel: bc->channel:%d channel:%d\n", bc->channel, channel);
  123. if (channel==0xff) {
  124. /* any channel */
  125. channel=-1;
  126. }
  127. /* ALERT: is that everytime true ? */
  128. if (channel > 0 && bc->nt ) {
  129. if (bc->channel && ( bc->channel != 0xff) ) {
  130. cb_log(0,bc->port,"We already have a channel (%d)\n", bc->channel);
  131. } else {
  132. bc->channel = channel;
  133. cb_event(EVENT_NEW_CHANNEL,bc,NULL);
  134. }
  135. }
  136. if (channel > 0 && !bc->nt ) {
  137. bc->channel = channel;
  138. cb_event(EVENT_NEW_CHANNEL,bc,NULL);
  139. }
  140. }
  141. static void parse_proceeding (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  142. {
  143. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  144. CALL_PROCEEDING_t *proceeding = (CALL_PROCEEDING_t *) (msg->data + HEADER_LEN);
  145. //struct misdn_stack *stack=get_stack_by_bc(bc);
  146. {
  147. int exclusive, channel;
  148. dec_ie_channel_id(proceeding->CHANNEL_ID, (Q931_info_t *)proceeding, &exclusive, &channel, nt,bc);
  149. set_channel(bc,channel);
  150. }
  151. dec_ie_progress(proceeding->PROGRESS, (Q931_info_t *)proceeding, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  152. dec_ie_facility(proceeding->FACILITY, (Q931_info_t *) proceeding, &bc->fac_in, nt, bc);
  153. /* dec_ie_redir_dn */
  154. #ifdef DEBUG
  155. printf("Parsing PROCEEDING Msg\n");
  156. #endif
  157. }
  158. static msg_t *build_proceeding (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  159. {
  160. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  161. CALL_PROCEEDING_t *proceeding;
  162. msg_t *msg =(msg_t*)create_l3msg(CC_PROCEEDING | REQUEST, MT_CALL_PROCEEDING, bc?bc->l3_id:-1, sizeof(CALL_PROCEEDING_t) ,nt);
  163. proceeding=(CALL_PROCEEDING_t*)((msg->data+HEADER_LEN));
  164. enc_ie_channel_id(&proceeding->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
  165. if (nt)
  166. enc_ie_progress(&proceeding->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
  167. if (bc->fac_out.Function != Fac_None) {
  168. enc_ie_facility(&proceeding->FACILITY, msg, &bc->fac_out, nt);
  169. }
  170. /* enc_ie_redir_dn */
  171. #ifdef DEBUG
  172. printf("Building PROCEEDING Msg\n");
  173. #endif
  174. return msg;
  175. }
  176. static void parse_alerting (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  177. {
  178. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  179. ALERTING_t *alerting = (ALERTING_t *) (msg->data + HEADER_LEN);
  180. //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
  181. dec_ie_facility(alerting->FACILITY, (Q931_info_t *) alerting, &bc->fac_in, nt, bc);
  182. /* dec_ie_redir_dn */
  183. dec_ie_progress(alerting->PROGRESS, (Q931_info_t *)alerting, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  184. #ifdef DEBUG
  185. printf("Parsing ALERTING Msg\n");
  186. #endif
  187. }
  188. static msg_t *build_alerting (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  189. {
  190. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  191. ALERTING_t *alerting;
  192. msg_t *msg =(msg_t*)create_l3msg(CC_ALERTING | REQUEST, MT_ALERTING, bc?bc->l3_id:-1, sizeof(ALERTING_t) ,nt);
  193. alerting=(ALERTING_t*)((msg->data+HEADER_LEN));
  194. enc_ie_channel_id(&alerting->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
  195. if (nt)
  196. enc_ie_progress(&alerting->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
  197. if (bc->fac_out.Function != Fac_None) {
  198. enc_ie_facility(&alerting->FACILITY, msg, &bc->fac_out, nt);
  199. }
  200. /* enc_ie_redir_dn */
  201. #ifdef DEBUG
  202. printf("Building ALERTING Msg\n");
  203. #endif
  204. return msg;
  205. }
  206. static void parse_progress (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  207. {
  208. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  209. PROGRESS_t *progress = (PROGRESS_t *) (msg->data + HEADER_LEN);
  210. //Q931_info_t *qi=(Q931_info_t*)(msg->data+HEADER_LEN);
  211. dec_ie_progress(progress->PROGRESS, (Q931_info_t *)progress, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  212. dec_ie_facility(progress->FACILITY, (Q931_info_t *) progress, &bc->fac_in, nt, bc);
  213. #ifdef DEBUG
  214. printf("Parsing PROGRESS Msg\n");
  215. #endif
  216. }
  217. static msg_t *build_progress (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  218. {
  219. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  220. PROGRESS_t *progress;
  221. msg_t *msg =(msg_t*)create_l3msg(CC_PROGRESS | REQUEST, MT_PROGRESS, bc?bc->l3_id:-1, sizeof(PROGRESS_t) ,nt);
  222. progress=(PROGRESS_t*)((msg->data+HEADER_LEN));
  223. enc_ie_progress(&progress->PROGRESS, msg, 0, nt ? 1 : 5, 8, nt, bc);
  224. if (bc->fac_out.Function != Fac_None) {
  225. enc_ie_facility(&progress->FACILITY, msg, &bc->fac_out, nt);
  226. }
  227. #ifdef DEBUG
  228. printf("Building PROGRESS Msg\n");
  229. #endif
  230. return msg;
  231. }
  232. #if defined(AST_MISDN_ENHANCEMENTS)
  233. /*!
  234. * \internal
  235. * \brief Extract the SETUP message's BC, HLC, and LLC encoded ie contents.
  236. *
  237. * \param setup Indexed setup message contents
  238. * \param nt TRUE if in NT mode.
  239. * \param bc Associated B channel
  240. *
  241. * \return Nothing
  242. */
  243. static void extract_setup_Bc_Hlc_Llc(SETUP_t *setup, int nt, struct misdn_bchannel *bc)
  244. {
  245. __u8 *p;
  246. Q931_info_t *qi;
  247. qi = (Q931_info_t *) setup;
  248. /* Extract Bearer Capability */
  249. if (nt) {
  250. p = (__u8 *) setup->BEARER;
  251. } else {
  252. if (qi->QI_ELEMENT(bearer_capability)) {
  253. p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(bearer_capability) + 1;
  254. } else {
  255. p = NULL;
  256. }
  257. }
  258. if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Bc.Contents) < *p) {
  259. bc->setup_bc_hlc_llc.Bc.Length = 0;
  260. } else {
  261. bc->setup_bc_hlc_llc.Bc.Length = *p;
  262. memcpy(bc->setup_bc_hlc_llc.Bc.Contents, p + 1, *p);
  263. }
  264. /* Extract Low Layer Compatibility */
  265. if (nt) {
  266. p = (__u8 *) setup->LLC;
  267. } else {
  268. if (qi->QI_ELEMENT(llc)) {
  269. p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(llc) + 1;
  270. } else {
  271. p = NULL;
  272. }
  273. }
  274. if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Llc.Contents) < *p) {
  275. bc->setup_bc_hlc_llc.Llc.Length = 0;
  276. } else {
  277. bc->setup_bc_hlc_llc.Llc.Length = *p;
  278. memcpy(bc->setup_bc_hlc_llc.Llc.Contents, p + 1, *p);
  279. }
  280. /* Extract High Layer Compatibility */
  281. if (nt) {
  282. p = (__u8 *) setup->HLC;
  283. } else {
  284. if (qi->QI_ELEMENT(hlc)) {
  285. p = (__u8 *) qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(hlc) + 1;
  286. } else {
  287. p = NULL;
  288. }
  289. }
  290. if (!p || *p == 0 || sizeof(bc->setup_bc_hlc_llc.Hlc.Contents) < *p) {
  291. bc->setup_bc_hlc_llc.Hlc.Length = 0;
  292. } else {
  293. bc->setup_bc_hlc_llc.Hlc.Length = *p;
  294. memcpy(bc->setup_bc_hlc_llc.Hlc.Contents, p + 1, *p);
  295. }
  296. }
  297. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  298. static void parse_setup (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  299. {
  300. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  301. SETUP_t *setup = (SETUP_t *) (msg->data + HEADER_LEN);
  302. Q931_info_t *qi = (Q931_info_t *) (msg->data + HEADER_LEN);
  303. int type;
  304. int plan;
  305. int present;
  306. int screen;
  307. int reason;
  308. #ifdef DEBUG
  309. printf("Parsing SETUP Msg\n");
  310. #endif
  311. dec_ie_calling_pn(setup->CALLING_PN, qi, &type, &plan, &present, &screen, bc->caller.number, sizeof(bc->caller.number), nt, bc);
  312. bc->caller.number_type = type;
  313. bc->caller.number_plan = plan;
  314. switch (present) {
  315. default:
  316. case 0:
  317. bc->caller.presentation = 0; /* presentation allowed */
  318. break;
  319. case 1:
  320. bc->caller.presentation = 1; /* presentation restricted */
  321. break;
  322. case 2:
  323. bc->caller.presentation = 2; /* Number not available */
  324. break;
  325. }
  326. if (0 <= screen) {
  327. bc->caller.screening = screen;
  328. } else {
  329. bc->caller.screening = 0; /* Unscreened */
  330. }
  331. dec_ie_facility(setup->FACILITY, (Q931_info_t *) setup, &bc->fac_in, nt, bc);
  332. dec_ie_called_pn(setup->CALLED_PN, (Q931_info_t *) setup, &type, &plan, bc->dialed.number, sizeof(bc->dialed.number), nt, bc);
  333. bc->dialed.number_type = type;
  334. bc->dialed.number_plan = plan;
  335. dec_ie_keypad(setup->KEYPAD, (Q931_info_t *) setup, bc->keypad, sizeof(bc->keypad), nt, bc);
  336. dec_ie_complete(setup->COMPLETE, (Q931_info_t *) setup, &bc->sending_complete, nt, bc);
  337. dec_ie_redir_nr(setup->REDIR_NR, (Q931_info_t *) setup, &type, &plan, &present, &screen, &reason, bc->redirecting.from.number, sizeof(bc->redirecting.from.number), nt, bc);
  338. bc->redirecting.from.number_type = type;
  339. bc->redirecting.from.number_plan = plan;
  340. switch (present) {
  341. default:
  342. case 0:
  343. bc->redirecting.from.presentation = 0; /* presentation allowed */
  344. break;
  345. case 1:
  346. bc->redirecting.from.presentation = 1; /* presentation restricted */
  347. break;
  348. case 2:
  349. bc->redirecting.from.presentation = 2; /* Number not available */
  350. break;
  351. }
  352. if (0 <= screen) {
  353. bc->redirecting.from.screening = screen;
  354. } else {
  355. bc->redirecting.from.screening = 0; /* Unscreened */
  356. }
  357. if (0 <= reason) {
  358. bc->redirecting.reason = reason;
  359. } else {
  360. bc->redirecting.reason = mISDN_REDIRECTING_REASON_UNKNOWN;
  361. }
  362. {
  363. int coding, capability, mode, rate, multi, user, async, urate, stopbits, dbits, parity;
  364. dec_ie_bearer(setup->BEARER, (Q931_info_t *)setup, &coding, &capability, &mode, &rate, &multi, &user, &async, &urate, &stopbits, &dbits, &parity, nt,bc);
  365. switch (capability) {
  366. case -1: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
  367. break;
  368. case 0: bc->capability=INFO_CAPABILITY_SPEECH;
  369. break;
  370. case 18: bc->capability=INFO_CAPABILITY_VIDEO;
  371. break;
  372. case 8: bc->capability=INFO_CAPABILITY_DIGITAL_UNRESTRICTED;
  373. bc->user1 = user;
  374. bc->urate = urate;
  375. bc->rate = rate;
  376. bc->mode = mode;
  377. break;
  378. case 9: bc->capability=INFO_CAPABILITY_DIGITAL_RESTRICTED;
  379. break;
  380. default:
  381. break;
  382. }
  383. switch(user) {
  384. case 2:
  385. bc->law=INFO_CODEC_ULAW;
  386. break;
  387. case 3:
  388. bc->law=INFO_CODEC_ALAW;
  389. break;
  390. default:
  391. bc->law=INFO_CODEC_ALAW;
  392. }
  393. bc->capability=capability;
  394. }
  395. {
  396. int exclusive, channel;
  397. dec_ie_channel_id(setup->CHANNEL_ID, (Q931_info_t *)setup, &exclusive, &channel, nt,bc);
  398. set_channel(bc,channel);
  399. }
  400. {
  401. int protocol ;
  402. dec_ie_useruser(setup->USER_USER, (Q931_info_t *)setup, &protocol, bc->uu, &bc->uulen, nt,bc);
  403. if (bc->uulen) cb_log(1, bc->port, "USERUSERINFO:%s\n", bc->uu);
  404. else
  405. cb_log(1, bc->port, "NO USERUSERINFO\n");
  406. }
  407. dec_ie_progress(setup->PROGRESS, (Q931_info_t *)setup, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  408. #if defined(AST_MISDN_ENHANCEMENTS)
  409. extract_setup_Bc_Hlc_Llc(setup, nt, bc);
  410. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  411. }
  412. #define ANY_CHANNEL 0xff /* IE attribute for 'any channel' */
  413. static msg_t *build_setup (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  414. {
  415. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  416. SETUP_t *setup;
  417. msg_t *msg =(msg_t*)create_l3msg(CC_SETUP | REQUEST, MT_SETUP, bc?bc->l3_id:-1, sizeof(SETUP_t) ,nt);
  418. int is_ptp;
  419. enum FacFunction fac_type;
  420. setup=(SETUP_t*)((msg->data+HEADER_LEN));
  421. if (bc->channel == 0 || bc->channel == ANY_CHANNEL || bc->channel==-1)
  422. enc_ie_channel_id(&setup->CHANNEL_ID, msg, 0, bc->channel, nt,bc);
  423. else
  424. enc_ie_channel_id(&setup->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
  425. fac_type = bc->fac_out.Function;
  426. if (fac_type != Fac_None) {
  427. enc_ie_facility(&setup->FACILITY, msg, &bc->fac_out, nt);
  428. }
  429. enc_ie_calling_pn(&setup->CALLING_PN, msg, bc->caller.number_type, bc->caller.number_plan,
  430. bc->caller.presentation, bc->caller.screening, bc->caller.number, nt, bc);
  431. if (bc->dialed.number[0]) {
  432. enc_ie_called_pn(&setup->CALLED_PN, msg, bc->dialed.number_type, bc->dialed.number_plan, bc->dialed.number, nt, bc);
  433. }
  434. switch (bc->outgoing_colp) {
  435. case 0:/* pass */
  436. case 1:/* restricted */
  437. is_ptp = misdn_lib_is_ptp(bc->port);
  438. if (bc->redirecting.from.number[0]
  439. && ((!is_ptp && nt)
  440. || (is_ptp
  441. #if defined(AST_MISDN_ENHANCEMENTS)
  442. /*
  443. * There is no need to send out this ie when we are also sending
  444. * a Fac_DivertingLegInformation2 as well. The
  445. * Fac_DivertingLegInformation2 supercedes the information in
  446. * this ie.
  447. */
  448. && fac_type != Fac_DivertingLegInformation2
  449. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  450. ))) {
  451. #if 1
  452. /* ETSI and Q.952 do not define the screening field */
  453. enc_ie_redir_nr(&setup->REDIR_NR, msg, bc->redirecting.from.number_type,
  454. bc->redirecting.from.number_plan, bc->redirecting.from.presentation, 0,
  455. bc->redirecting.reason, bc->redirecting.from.number, nt, bc);
  456. #else
  457. /* Q.931 defines the screening field */
  458. enc_ie_redir_nr(&setup->REDIR_NR, msg, bc->redirecting.from.number_type,
  459. bc->redirecting.from.number_plan, bc->redirecting.from.presentation,
  460. bc->redirecting.from.screening, bc->redirecting.reason,
  461. bc->redirecting.from.number, nt, bc);
  462. #endif
  463. }
  464. break;
  465. default:
  466. break;
  467. }
  468. if (bc->keypad[0]) {
  469. enc_ie_keypad(&setup->KEYPAD, msg, bc->keypad, nt,bc);
  470. }
  471. if (*bc->display) {
  472. enc_ie_display(&setup->DISPLAY, msg, bc->display, nt, bc);
  473. } else if (nt && bc->caller.presentation == 0) {
  474. char display[sizeof(bc->display)];
  475. /* Presentation is allowed */
  476. build_display_str(display, sizeof(display), bc->display_setup, bc->caller.name, bc->caller.number);
  477. if (display[0]) {
  478. enc_ie_display(&setup->DISPLAY, msg, display, nt, bc);
  479. }
  480. }
  481. {
  482. int coding = 0;
  483. int capability;
  484. int mode = 0; /* 2 for packet! */
  485. int user;
  486. int rate = 0x10;
  487. switch (bc->law) {
  488. case INFO_CODEC_ULAW: user=2;
  489. break;
  490. case INFO_CODEC_ALAW: user=3;
  491. break;
  492. default:
  493. user=3;
  494. }
  495. switch (bc->capability) {
  496. case INFO_CAPABILITY_SPEECH: capability = 0;
  497. break;
  498. case INFO_CAPABILITY_DIGITAL_UNRESTRICTED: capability = 8;
  499. user=-1;
  500. mode=bc->mode;
  501. rate=bc->rate;
  502. break;
  503. case INFO_CAPABILITY_DIGITAL_RESTRICTED: capability = 9;
  504. user=-1;
  505. break;
  506. default:
  507. capability=bc->capability;
  508. }
  509. enc_ie_bearer(&setup->BEARER, msg, coding, capability, mode, rate, -1, user, nt,bc);
  510. }
  511. if (bc->sending_complete) {
  512. enc_ie_complete(&setup->COMPLETE,msg, bc->sending_complete, nt, bc);
  513. }
  514. if (bc->uulen) {
  515. int protocol=4;
  516. enc_ie_useruser(&setup->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
  517. cb_log(1, bc->port, "ENCODING USERUSERINFO:%s\n", bc->uu);
  518. }
  519. #if defined(AST_MISDN_ENHANCEMENTS)
  520. extract_setup_Bc_Hlc_Llc(setup, nt, bc);
  521. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  522. #ifdef DEBUG
  523. printf("Building SETUP Msg\n");
  524. #endif
  525. return msg;
  526. }
  527. static void parse_connect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  528. {
  529. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  530. CONNECT_t *connect = (CONNECT_t *) (msg->data + HEADER_LEN);
  531. int type;
  532. int plan;
  533. int pres;
  534. int screen;
  535. bc->ces = connect->ces;
  536. dec_ie_progress(connect->PROGRESS, (Q931_info_t *)connect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  537. dec_ie_connected_pn(connect->CONNECT_PN, (Q931_info_t *) connect, &type, &plan,
  538. &pres, &screen, bc->connected.number, sizeof(bc->connected.number), nt, bc);
  539. bc->connected.number_type = type;
  540. bc->connected.number_plan = plan;
  541. switch (pres) {
  542. default:
  543. case 0:
  544. bc->connected.presentation = 0; /* presentation allowed */
  545. break;
  546. case 1:
  547. bc->connected.presentation = 1; /* presentation restricted */
  548. break;
  549. case 2:
  550. bc->connected.presentation = 2; /* Number not available */
  551. break;
  552. }
  553. if (0 <= screen) {
  554. bc->connected.screening = screen;
  555. } else {
  556. bc->connected.screening = 0; /* Unscreened */
  557. }
  558. dec_ie_facility(connect->FACILITY, (Q931_info_t *) connect, &bc->fac_in, nt, bc);
  559. /*
  560. cb_log(1,bc->port,"CONNETED PN: %s cpn_dialplan:%d\n", connected_pn, type);
  561. */
  562. #ifdef DEBUG
  563. printf("Parsing CONNECT Msg\n");
  564. #endif
  565. }
  566. static msg_t *build_connect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  567. {
  568. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  569. CONNECT_t *connect;
  570. msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | REQUEST, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_t) ,nt);
  571. cb_log(6,bc->port,"BUILD_CONNECT: bc:%p bc->l3id:%d, nt:%d\n",bc,bc->l3_id,nt);
  572. connect=(CONNECT_t*)((msg->data+HEADER_LEN));
  573. if (nt) {
  574. time_t now;
  575. time(&now);
  576. enc_ie_date(&connect->DATE, msg, now, nt,bc);
  577. }
  578. switch (bc->outgoing_colp) {
  579. case 0:/* pass */
  580. case 1:/* restricted */
  581. enc_ie_connected_pn(&connect->CONNECT_PN, msg, bc->connected.number_type,
  582. bc->connected.number_plan, bc->connected.presentation,
  583. bc->connected.screening, bc->connected.number, nt, bc);
  584. break;
  585. default:
  586. break;
  587. }
  588. if (nt && bc->connected.presentation == 0) {
  589. char display[sizeof(bc->display)];
  590. /* Presentation is allowed */
  591. build_display_str(display, sizeof(display), bc->display_connected, bc->connected.name, bc->connected.number);
  592. if (display[0]) {
  593. enc_ie_display(&connect->DISPLAY, msg, display, nt, bc);
  594. }
  595. }
  596. if (bc->fac_out.Function != Fac_None) {
  597. enc_ie_facility(&connect->FACILITY, msg, &bc->fac_out, nt);
  598. }
  599. #ifdef DEBUG
  600. printf("Building CONNECT Msg\n");
  601. #endif
  602. return msg;
  603. }
  604. static void parse_setup_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  605. {
  606. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  607. SETUP_ACKNOWLEDGE_t *setup_acknowledge = (SETUP_ACKNOWLEDGE_t *) (msg->data + HEADER_LEN);
  608. {
  609. int exclusive, channel;
  610. dec_ie_channel_id(setup_acknowledge->CHANNEL_ID, (Q931_info_t *)setup_acknowledge, &exclusive, &channel, nt,bc);
  611. set_channel(bc, channel);
  612. }
  613. dec_ie_progress(setup_acknowledge->PROGRESS, (Q931_info_t *)setup_acknowledge, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  614. dec_ie_facility(setup_acknowledge->FACILITY, (Q931_info_t *) setup_acknowledge, &bc->fac_in, nt, bc);
  615. #ifdef DEBUG
  616. printf("Parsing SETUP_ACKNOWLEDGE Msg\n");
  617. #endif
  618. }
  619. static msg_t *build_setup_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  620. {
  621. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  622. SETUP_ACKNOWLEDGE_t *setup_acknowledge;
  623. msg_t *msg =(msg_t*)create_l3msg(CC_SETUP_ACKNOWLEDGE | REQUEST, MT_SETUP_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SETUP_ACKNOWLEDGE_t) ,nt);
  624. setup_acknowledge=(SETUP_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
  625. enc_ie_channel_id(&setup_acknowledge->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
  626. if (nt)
  627. enc_ie_progress(&setup_acknowledge->PROGRESS, msg, 0, nt?1:5, 8, nt,bc);
  628. if (bc->fac_out.Function != Fac_None) {
  629. enc_ie_facility(&setup_acknowledge->FACILITY, msg, &bc->fac_out, nt);
  630. }
  631. #ifdef DEBUG
  632. printf("Building SETUP_ACKNOWLEDGE Msg\n");
  633. #endif
  634. return msg;
  635. }
  636. static void parse_connect_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  637. {
  638. #ifdef DEBUG
  639. printf("Parsing CONNECT_ACKNOWLEDGE Msg\n");
  640. #endif
  641. }
  642. static msg_t *build_connect_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  643. {
  644. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  645. CONNECT_ACKNOWLEDGE_t *connect_acknowledge;
  646. msg_t *msg =(msg_t*)create_l3msg(CC_CONNECT | RESPONSE, MT_CONNECT, bc?bc->l3_id:-1, sizeof(CONNECT_ACKNOWLEDGE_t) ,nt);
  647. connect_acknowledge=(CONNECT_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
  648. enc_ie_channel_id(&connect_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
  649. #ifdef DEBUG
  650. printf("Building CONNECT_ACKNOWLEDGE Msg\n");
  651. #endif
  652. return msg;
  653. }
  654. static void parse_user_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  655. {
  656. #ifdef DEBUG
  657. printf("Parsing USER_INFORMATION Msg\n");
  658. #endif
  659. }
  660. static msg_t *build_user_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  661. {
  662. msg_t *msg =(msg_t*)create_l3msg(CC_USER_INFORMATION | REQUEST, MT_USER_INFORMATION, bc?bc->l3_id:-1, sizeof(USER_INFORMATION_t) ,nt);
  663. #ifdef DEBUG
  664. printf("Building USER_INFORMATION Msg\n");
  665. #endif
  666. return msg;
  667. }
  668. static void parse_suspend_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  669. {
  670. #ifdef DEBUG
  671. printf("Parsing SUSPEND_REJECT Msg\n");
  672. #endif
  673. }
  674. static msg_t *build_suspend_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  675. {
  676. msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_REJECT | REQUEST, MT_SUSPEND_REJECT, bc?bc->l3_id:-1, sizeof(SUSPEND_REJECT_t) ,nt);
  677. #ifdef DEBUG
  678. printf("Building SUSPEND_REJECT Msg\n");
  679. #endif
  680. return msg;
  681. }
  682. static void parse_resume_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  683. {
  684. #ifdef DEBUG
  685. printf("Parsing RESUME_REJECT Msg\n");
  686. #endif
  687. }
  688. static msg_t *build_resume_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  689. {
  690. msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_REJECT | REQUEST, MT_RESUME_REJECT, bc?bc->l3_id:-1, sizeof(RESUME_REJECT_t) ,nt);
  691. #ifdef DEBUG
  692. printf("Building RESUME_REJECT Msg\n");
  693. #endif
  694. return msg;
  695. }
  696. static void parse_hold (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  697. {
  698. #ifdef DEBUG
  699. printf("Parsing HOLD Msg\n");
  700. #endif
  701. }
  702. static msg_t *build_hold (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  703. {
  704. msg_t *msg =(msg_t*)create_l3msg(CC_HOLD | REQUEST, MT_HOLD, bc?bc->l3_id:-1, sizeof(HOLD_t) ,nt);
  705. #ifdef DEBUG
  706. printf("Building HOLD Msg\n");
  707. #endif
  708. return msg;
  709. }
  710. static void parse_suspend (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  711. {
  712. #ifdef DEBUG
  713. printf("Parsing SUSPEND Msg\n");
  714. #endif
  715. }
  716. static msg_t *build_suspend (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  717. {
  718. msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND | REQUEST, MT_SUSPEND, bc?bc->l3_id:-1, sizeof(SUSPEND_t) ,nt);
  719. #ifdef DEBUG
  720. printf("Building SUSPEND Msg\n");
  721. #endif
  722. return msg;
  723. }
  724. static void parse_resume (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  725. {
  726. #ifdef DEBUG
  727. printf("Parsing RESUME Msg\n");
  728. #endif
  729. }
  730. static msg_t *build_resume (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  731. {
  732. msg_t *msg =(msg_t*)create_l3msg(CC_RESUME | REQUEST, MT_RESUME, bc?bc->l3_id:-1, sizeof(RESUME_t) ,nt);
  733. #ifdef DEBUG
  734. printf("Building RESUME Msg\n");
  735. #endif
  736. return msg;
  737. }
  738. static void parse_hold_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  739. {
  740. #ifdef DEBUG
  741. printf("Parsing HOLD_ACKNOWLEDGE Msg\n");
  742. #endif
  743. }
  744. static msg_t *build_hold_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  745. {
  746. msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_ACKNOWLEDGE | REQUEST, MT_HOLD_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(HOLD_ACKNOWLEDGE_t) ,nt);
  747. #ifdef DEBUG
  748. printf("Building HOLD_ACKNOWLEDGE Msg\n");
  749. #endif
  750. return msg;
  751. }
  752. static void parse_suspend_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  753. {
  754. #ifdef DEBUG
  755. printf("Parsing SUSPEND_ACKNOWLEDGE Msg\n");
  756. #endif
  757. }
  758. static msg_t *build_suspend_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  759. {
  760. msg_t *msg =(msg_t*)create_l3msg(CC_SUSPEND_ACKNOWLEDGE | REQUEST, MT_SUSPEND_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(SUSPEND_ACKNOWLEDGE_t) ,nt);
  761. #ifdef DEBUG
  762. printf("Building SUSPEND_ACKNOWLEDGE Msg\n");
  763. #endif
  764. return msg;
  765. }
  766. static void parse_resume_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  767. {
  768. #ifdef DEBUG
  769. printf("Parsing RESUME_ACKNOWLEDGE Msg\n");
  770. #endif
  771. }
  772. static msg_t *build_resume_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  773. {
  774. msg_t *msg =(msg_t*)create_l3msg(CC_RESUME_ACKNOWLEDGE | REQUEST, MT_RESUME_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RESUME_ACKNOWLEDGE_t) ,nt);
  775. #ifdef DEBUG
  776. printf("Building RESUME_ACKNOWLEDGE Msg\n");
  777. #endif
  778. return msg;
  779. }
  780. static void parse_hold_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  781. {
  782. #ifdef DEBUG
  783. printf("Parsing HOLD_REJECT Msg\n");
  784. #endif
  785. }
  786. static msg_t *build_hold_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  787. {
  788. msg_t *msg =(msg_t*)create_l3msg(CC_HOLD_REJECT | REQUEST, MT_HOLD_REJECT, bc?bc->l3_id:-1, sizeof(HOLD_REJECT_t) ,nt);
  789. #ifdef DEBUG
  790. printf("Building HOLD_REJECT Msg\n");
  791. #endif
  792. return msg;
  793. }
  794. static void parse_retrieve (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  795. {
  796. #ifdef DEBUG
  797. printf("Parsing RETRIEVE Msg\n");
  798. #endif
  799. }
  800. static msg_t *build_retrieve (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  801. {
  802. msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE | REQUEST, MT_RETRIEVE, bc?bc->l3_id:-1, sizeof(RETRIEVE_t) ,nt);
  803. #ifdef DEBUG
  804. printf("Building RETRIEVE Msg\n");
  805. #endif
  806. return msg;
  807. }
  808. static void parse_retrieve_acknowledge (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  809. {
  810. #ifdef DEBUG
  811. printf("Parsing RETRIEVE_ACKNOWLEDGE Msg\n");
  812. #endif
  813. }
  814. static msg_t *build_retrieve_acknowledge (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  815. {
  816. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  817. RETRIEVE_ACKNOWLEDGE_t *retrieve_acknowledge;
  818. msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_ACKNOWLEDGE | REQUEST, MT_RETRIEVE_ACKNOWLEDGE, bc?bc->l3_id:-1, sizeof(RETRIEVE_ACKNOWLEDGE_t) ,nt);
  819. retrieve_acknowledge=(RETRIEVE_ACKNOWLEDGE_t*)((msg->data+HEADER_LEN));
  820. enc_ie_channel_id(&retrieve_acknowledge->CHANNEL_ID, msg, 1, bc->channel, nt,bc);
  821. #ifdef DEBUG
  822. printf("Building RETRIEVE_ACKNOWLEDGE Msg\n");
  823. #endif
  824. return msg;
  825. }
  826. static void parse_retrieve_reject (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  827. {
  828. #ifdef DEBUG
  829. printf("Parsing RETRIEVE_REJECT Msg\n");
  830. #endif
  831. }
  832. static msg_t *build_retrieve_reject (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  833. {
  834. msg_t *msg =(msg_t*)create_l3msg(CC_RETRIEVE_REJECT | REQUEST, MT_RETRIEVE_REJECT, bc?bc->l3_id:-1, sizeof(RETRIEVE_REJECT_t) ,nt);
  835. #ifdef DEBUG
  836. printf("Building RETRIEVE_REJECT Msg\n");
  837. #endif
  838. return msg;
  839. }
  840. static void parse_disconnect (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  841. {
  842. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  843. DISCONNECT_t *disconnect = (DISCONNECT_t *) (msg->data + HEADER_LEN);
  844. int location;
  845. int cause;
  846. dec_ie_cause(disconnect->CAUSE, (Q931_info_t *)(disconnect), &location, &cause, nt,bc);
  847. if (cause>0) bc->cause=cause;
  848. dec_ie_facility(disconnect->FACILITY, (Q931_info_t *) disconnect, &bc->fac_in, nt, bc);
  849. dec_ie_progress(disconnect->PROGRESS, (Q931_info_t *)disconnect, &bc->progress_coding, &bc->progress_location, &bc->progress_indicator, nt, bc);
  850. #ifdef DEBUG
  851. printf("Parsing DISCONNECT Msg\n");
  852. #endif
  853. }
  854. static msg_t *build_disconnect (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  855. {
  856. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  857. DISCONNECT_t *disconnect;
  858. msg_t *msg =(msg_t*)create_l3msg(CC_DISCONNECT | REQUEST, MT_DISCONNECT, bc?bc->l3_id:-1, sizeof(DISCONNECT_t) ,nt);
  859. disconnect=(DISCONNECT_t*)((msg->data+HEADER_LEN));
  860. enc_ie_cause(&disconnect->CAUSE, msg, (nt)?1:0, bc->out_cause,nt,bc);
  861. if (nt) {
  862. enc_ie_progress(&disconnect->PROGRESS, msg, 0, nt ? 1 : 5, 8, nt, bc);
  863. }
  864. if (bc->fac_out.Function != Fac_None) {
  865. enc_ie_facility(&disconnect->FACILITY, msg, &bc->fac_out, nt);
  866. }
  867. if (bc->uulen) {
  868. int protocol=4;
  869. enc_ie_useruser(&disconnect->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
  870. cb_log(1, bc->port, "ENCODING USERUSERINFO:%s\n", bc->uu);
  871. }
  872. #ifdef DEBUG
  873. printf("Building DISCONNECT Msg\n");
  874. #endif
  875. return msg;
  876. }
  877. static void parse_restart (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  878. {
  879. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  880. RESTART_t *restart = (RESTART_t *) (msg->data + HEADER_LEN);
  881. struct misdn_stack *stack=get_stack_by_bc(bc);
  882. #ifdef DEBUG
  883. printf("Parsing RESTART Msg\n");
  884. #endif
  885. {
  886. int exclusive;
  887. dec_ie_channel_id(restart->CHANNEL_ID, (Q931_info_t *)restart, &exclusive, &bc->restart_channel, nt,bc);
  888. cb_log(3, stack->port, "CC_RESTART Request on channel:%d on this port.\n", bc->restart_channel);
  889. }
  890. }
  891. static msg_t *build_restart (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  892. {
  893. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  894. RESTART_t *restart;
  895. msg_t *msg =(msg_t*)create_l3msg(CC_RESTART | REQUEST, MT_RESTART, bc?bc->l3_id:-1, sizeof(RESTART_t) ,nt);
  896. restart=(RESTART_t*)((msg->data+HEADER_LEN));
  897. #ifdef DEBUG
  898. printf("Building RESTART Msg\n");
  899. #endif
  900. if (bc->channel > 0) {
  901. enc_ie_channel_id(&restart->CHANNEL_ID, msg, 1,bc->channel, nt,bc);
  902. enc_ie_restart_ind(&restart->RESTART_IND, msg, 0x80, nt, bc);
  903. } else {
  904. enc_ie_restart_ind(&restart->RESTART_IND, msg, 0x87, nt, bc);
  905. }
  906. cb_log(0,bc->port, "Restarting channel %d\n", bc->channel);
  907. return msg;
  908. }
  909. static void parse_release (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  910. {
  911. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  912. RELEASE_t *release = (RELEASE_t *) (msg->data + HEADER_LEN);
  913. int location;
  914. int cause;
  915. dec_ie_cause(release->CAUSE, (Q931_info_t *)(release), &location, &cause, nt,bc);
  916. if (cause>0) bc->cause=cause;
  917. dec_ie_facility(release->FACILITY, (Q931_info_t *) release, &bc->fac_in, nt, bc);
  918. #ifdef DEBUG
  919. printf("Parsing RELEASE Msg\n");
  920. #endif
  921. }
  922. static msg_t *build_release (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  923. {
  924. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  925. RELEASE_t *release;
  926. msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE | REQUEST, MT_RELEASE, bc?bc->l3_id:-1, sizeof(RELEASE_t) ,nt);
  927. release=(RELEASE_t*)((msg->data+HEADER_LEN));
  928. if (bc->out_cause>= 0)
  929. enc_ie_cause(&release->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
  930. if (bc->fac_out.Function != Fac_None) {
  931. enc_ie_facility(&release->FACILITY, msg, &bc->fac_out, nt);
  932. }
  933. if (bc->uulen) {
  934. int protocol=4;
  935. enc_ie_useruser(&release->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
  936. cb_log(1, bc->port, "ENCODING USERUSERINFO:%s\n", bc->uu);
  937. }
  938. #ifdef DEBUG
  939. printf("Building RELEASE Msg\n");
  940. #endif
  941. return msg;
  942. }
  943. static void parse_release_complete (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  944. {
  945. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  946. RELEASE_COMPLETE_t *release_complete = (RELEASE_COMPLETE_t *) (msg->data + HEADER_LEN);
  947. int location;
  948. int cause;
  949. iframe_t *frm = (iframe_t*) msg->data;
  950. struct misdn_stack *stack=get_stack_by_bc(bc);
  951. mISDNuser_head_t *hh;
  952. hh=(mISDNuser_head_t*)msg->data;
  953. /*hh=(mISDN_head_t*)msg->data;
  954. mISDN_head_t *hh;*/
  955. if (nt) {
  956. if (hh->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
  957. cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [NT] \n");
  958. return;
  959. }
  960. } else {
  961. if (frm->prim == (CC_RELEASE_COMPLETE|CONFIRM)) {
  962. cb_log(0, stack->port, "CC_RELEASE_COMPLETE|CONFIRM [TE] \n");
  963. return;
  964. }
  965. }
  966. dec_ie_cause(release_complete->CAUSE, (Q931_info_t *)(release_complete), &location, &cause, nt,bc);
  967. if (cause>0) bc->cause=cause;
  968. dec_ie_facility(release_complete->FACILITY, (Q931_info_t *) release_complete, &bc->fac_in, nt, bc);
  969. #ifdef DEBUG
  970. printf("Parsing RELEASE_COMPLETE Msg\n");
  971. #endif
  972. }
  973. static msg_t *build_release_complete (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  974. {
  975. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  976. RELEASE_COMPLETE_t *release_complete;
  977. msg_t *msg =(msg_t*)create_l3msg(CC_RELEASE_COMPLETE | REQUEST, MT_RELEASE_COMPLETE, bc?bc->l3_id:-1, sizeof(RELEASE_COMPLETE_t) ,nt);
  978. release_complete=(RELEASE_COMPLETE_t*)((msg->data+HEADER_LEN));
  979. enc_ie_cause(&release_complete->CAUSE, msg, nt?1:0, bc->out_cause, nt,bc);
  980. if (bc->fac_out.Function != Fac_None) {
  981. enc_ie_facility(&release_complete->FACILITY, msg, &bc->fac_out, nt);
  982. }
  983. if (bc->uulen) {
  984. int protocol=4;
  985. enc_ie_useruser(&release_complete->USER_USER, msg, protocol, bc->uu, bc->uulen, nt,bc);
  986. cb_log(1, bc->port, "ENCODING USERUSERINFO:%s\n", bc->uu);
  987. }
  988. #ifdef DEBUG
  989. printf("Building RELEASE_COMPLETE Msg\n");
  990. #endif
  991. return msg;
  992. }
  993. static void parse_facility (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  994. {
  995. int HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
  996. FACILITY_t *facility = (FACILITY_t*)(msg->data+HEADER_LEN);
  997. Q931_info_t *qi = (Q931_info_t*)(msg->data+HEADER_LEN);
  998. unsigned char *p = NULL;
  999. #if defined(AST_MISDN_ENHANCEMENTS)
  1000. int description_code;
  1001. int type;
  1002. int plan;
  1003. int present;
  1004. char number[sizeof(bc->redirecting.to.number)];
  1005. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1006. #ifdef DEBUG
  1007. printf("Parsing FACILITY Msg\n");
  1008. #endif
  1009. bc->fac_in.Function = Fac_None;
  1010. if (!bc->nt) {
  1011. if (qi->QI_ELEMENT(facility))
  1012. p = (unsigned char *)qi + sizeof(Q931_info_t) + qi->QI_ELEMENT(facility) + 1;
  1013. } else {
  1014. p = facility->FACILITY;
  1015. }
  1016. if (!p)
  1017. return;
  1018. if (decodeFac(p, &bc->fac_in)) {
  1019. cb_log(3, bc->port, "Decoding facility ie failed! Unrecognized facility message?\n");
  1020. }
  1021. #if defined(AST_MISDN_ENHANCEMENTS)
  1022. dec_ie_notify(facility->NOTIFY, qi, &description_code, nt, bc);
  1023. if (description_code < 0) {
  1024. bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
  1025. } else {
  1026. bc->notify_description_code = description_code;
  1027. }
  1028. dec_ie_redir_dn(facility->REDIR_DN, qi, &type, &plan, &present, number, sizeof(number), nt, bc);
  1029. if (0 <= type) {
  1030. bc->redirecting.to_changed = 1;
  1031. bc->redirecting.to.number_type = type;
  1032. bc->redirecting.to.number_plan = plan;
  1033. switch (present) {
  1034. default:
  1035. case 0:
  1036. bc->redirecting.to.presentation = 0; /* presentation allowed */
  1037. break;
  1038. case 1:
  1039. bc->redirecting.to.presentation = 1; /* presentation restricted */
  1040. break;
  1041. case 2:
  1042. bc->redirecting.to.presentation = 2; /* Number not available */
  1043. break;
  1044. }
  1045. bc->redirecting.to.screening = 0; /* Unscreened */
  1046. strcpy(bc->redirecting.to.number, number);
  1047. }
  1048. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1049. }
  1050. static msg_t *build_facility (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1051. {
  1052. int len;
  1053. int HEADER_LEN;
  1054. unsigned char *ie_fac;
  1055. unsigned char fac_tmp[256];
  1056. msg_t *msg;
  1057. FACILITY_t *facility;
  1058. Q931_info_t *qi;
  1059. #ifdef DEBUG
  1060. printf("Building FACILITY Msg\n");
  1061. #endif
  1062. len = encodeFac(fac_tmp, &(bc->fac_out));
  1063. if (len <= 0) {
  1064. /*
  1065. * mISDN does not know how to build the requested facility structure
  1066. * Clear facility information
  1067. */
  1068. bc->fac_out.Function = Fac_None;
  1069. #if defined(AST_MISDN_ENHANCEMENTS)
  1070. /* Clear other one shot information. */
  1071. bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
  1072. bc->redirecting.to_changed = 0;
  1073. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1074. return NULL;
  1075. }
  1076. msg = (msg_t *) create_l3msg(CC_FACILITY | REQUEST, MT_FACILITY, bc ? bc->l3_id : -1, sizeof(FACILITY_t), nt);
  1077. HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
  1078. facility = (FACILITY_t *) (msg->data + HEADER_LEN);
  1079. ie_fac = msg_put(msg, len);
  1080. if (bc->nt) {
  1081. facility->FACILITY = ie_fac + 1;
  1082. } else {
  1083. qi = (Q931_info_t *)(msg->data + mISDN_HEADER_LEN);
  1084. qi->QI_ELEMENT(facility) = ie_fac - (unsigned char *)qi - sizeof(Q931_info_t);
  1085. }
  1086. memcpy(ie_fac, fac_tmp, len);
  1087. /* Clear facility information */
  1088. bc->fac_out.Function = Fac_None;
  1089. if (*bc->display) {
  1090. #ifdef DEBUG
  1091. printf("Sending %s as Display\n", bc->display);
  1092. #endif
  1093. enc_ie_display(&facility->DISPLAY, msg, bc->display, nt,bc);
  1094. }
  1095. #if defined(AST_MISDN_ENHANCEMENTS)
  1096. if (bc->notify_description_code != mISDN_NOTIFY_CODE_INVALID) {
  1097. enc_ie_notify(&facility->NOTIFY, msg, bc->notify_description_code, nt, bc);
  1098. bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
  1099. }
  1100. if (bc->redirecting.to_changed) {
  1101. bc->redirecting.to_changed = 0;
  1102. switch (bc->outgoing_colp) {
  1103. case 0:/* pass */
  1104. case 1:/* restricted */
  1105. enc_ie_redir_dn(&facility->REDIR_DN, msg, bc->redirecting.to.number_type,
  1106. bc->redirecting.to.number_plan, bc->redirecting.to.presentation,
  1107. bc->redirecting.to.number, nt, bc);
  1108. break;
  1109. default:
  1110. break;
  1111. }
  1112. }
  1113. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1114. return msg;
  1115. }
  1116. #if defined(AST_MISDN_ENHANCEMENTS)
  1117. /*!
  1118. * \internal
  1119. * \brief Parse a received REGISTER message
  1120. *
  1121. * \param msgs Search table entry that called us.
  1122. * \param msg Received message contents
  1123. * \param bc Associated B channel
  1124. * \param nt TRUE if in NT mode.
  1125. *
  1126. * \return Nothing
  1127. */
  1128. static void parse_register(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1129. {
  1130. int HEADER_LEN;
  1131. REGISTER_t *reg;
  1132. HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
  1133. reg = (REGISTER_t *) (msg->data + HEADER_LEN);
  1134. /*
  1135. * A facility ie is optional.
  1136. * The peer may just be establishing a connection to send
  1137. * messages later.
  1138. */
  1139. dec_ie_facility(reg->FACILITY, (Q931_info_t *) reg, &bc->fac_in, nt, bc);
  1140. }
  1141. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1142. #if defined(AST_MISDN_ENHANCEMENTS)
  1143. /*!
  1144. * \internal
  1145. * \brief Construct a REGISTER message
  1146. *
  1147. * \param msgs Search table entry that called us.
  1148. * \param bc Associated B channel
  1149. * \param nt TRUE if in NT mode.
  1150. *
  1151. * \return Allocated built message
  1152. */
  1153. static msg_t *build_register(struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1154. {
  1155. int HEADER_LEN;
  1156. REGISTER_t *reg;
  1157. msg_t *msg;
  1158. msg = (msg_t *) create_l3msg(CC_REGISTER | REQUEST, MT_REGISTER, bc ? bc->l3_id : -1, sizeof(REGISTER_t), nt);
  1159. HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
  1160. reg = (REGISTER_t *) (msg->data + HEADER_LEN);
  1161. if (bc->fac_out.Function != Fac_None) {
  1162. enc_ie_facility(&reg->FACILITY, msg, &bc->fac_out, nt);
  1163. }
  1164. return msg;
  1165. }
  1166. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1167. static void parse_notify (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1168. {
  1169. int HEADER_LEN = nt ? mISDNUSER_HEAD_SIZE : mISDN_HEADER_LEN;
  1170. NOTIFY_t *notify = (NOTIFY_t *) (msg->data + HEADER_LEN);
  1171. int description_code;
  1172. int type;
  1173. int plan;
  1174. int present;
  1175. char number[sizeof(bc->redirecting.to.number)];
  1176. #ifdef DEBUG
  1177. printf("Parsing NOTIFY Msg\n");
  1178. #endif
  1179. dec_ie_notify(notify->NOTIFY, (Q931_info_t *) notify, &description_code, nt, bc);
  1180. if (description_code < 0) {
  1181. bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
  1182. } else {
  1183. bc->notify_description_code = description_code;
  1184. }
  1185. dec_ie_redir_dn(notify->REDIR_DN, (Q931_info_t *) notify, &type, &plan, &present, number, sizeof(number), nt, bc);
  1186. if (0 <= type) {
  1187. bc->redirecting.to_changed = 1;
  1188. bc->redirecting.to.number_type = type;
  1189. bc->redirecting.to.number_plan = plan;
  1190. switch (present) {
  1191. default:
  1192. case 0:
  1193. bc->redirecting.to.presentation = 0; /* presentation allowed */
  1194. break;
  1195. case 1:
  1196. bc->redirecting.to.presentation = 1; /* presentation restricted */
  1197. break;
  1198. case 2:
  1199. bc->redirecting.to.presentation = 2; /* Number not available */
  1200. break;
  1201. }
  1202. bc->redirecting.to.screening = 0; /* Unscreened */
  1203. strcpy(bc->redirecting.to.number, number);
  1204. }
  1205. }
  1206. static msg_t *build_notify (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1207. {
  1208. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  1209. NOTIFY_t *notify;
  1210. msg_t *msg =(msg_t*)create_l3msg(CC_NOTIFY | REQUEST, MT_NOTIFY, bc?bc->l3_id:-1, sizeof(NOTIFY_t) ,nt);
  1211. #ifdef DEBUG
  1212. printf("Building NOTIFY Msg\n");
  1213. #endif
  1214. notify = (NOTIFY_t *) (msg->data + HEADER_LEN);
  1215. enc_ie_notify(&notify->NOTIFY, msg, bc->notify_description_code, nt, bc);
  1216. bc->notify_description_code = mISDN_NOTIFY_CODE_INVALID;
  1217. if (bc->redirecting.to_changed) {
  1218. bc->redirecting.to_changed = 0;
  1219. switch (bc->outgoing_colp) {
  1220. case 0:/* pass */
  1221. case 1:/* restricted */
  1222. enc_ie_redir_dn(&notify->REDIR_DN, msg, bc->redirecting.to.number_type,
  1223. bc->redirecting.to.number_plan, bc->redirecting.to.presentation,
  1224. bc->redirecting.to.number, nt, bc);
  1225. break;
  1226. default:
  1227. break;
  1228. }
  1229. }
  1230. return msg;
  1231. }
  1232. static void parse_status_enquiry (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1233. {
  1234. #ifdef DEBUG
  1235. printf("Parsing STATUS_ENQUIRY Msg\n");
  1236. #endif
  1237. }
  1238. static msg_t *build_status_enquiry (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1239. {
  1240. msg_t *msg =(msg_t*)create_l3msg(CC_STATUS_ENQUIRY | REQUEST, MT_STATUS_ENQUIRY, bc?bc->l3_id:-1, sizeof(STATUS_ENQUIRY_t) ,nt);
  1241. #ifdef DEBUG
  1242. printf("Building STATUS_ENQUIRY Msg\n");
  1243. #endif
  1244. return msg;
  1245. }
  1246. static void parse_information (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1247. {
  1248. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  1249. INFORMATION_t *information = (INFORMATION_t *) (msg->data + HEADER_LEN);
  1250. int type, plan;
  1251. dec_ie_called_pn(information->CALLED_PN, (Q931_info_t *) information, &type, &plan, bc->info_dad, sizeof(bc->info_dad), nt, bc);
  1252. dec_ie_keypad(information->KEYPAD, (Q931_info_t *) information, bc->keypad, sizeof(bc->keypad), nt, bc);
  1253. #ifdef DEBUG
  1254. printf("Parsing INFORMATION Msg\n");
  1255. #endif
  1256. }
  1257. static msg_t *build_information (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1258. {
  1259. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  1260. INFORMATION_t *information;
  1261. msg_t *msg =(msg_t*)create_l3msg(CC_INFORMATION | REQUEST, MT_INFORMATION, bc?bc->l3_id:-1, sizeof(INFORMATION_t) ,nt);
  1262. information=(INFORMATION_t*)((msg->data+HEADER_LEN));
  1263. enc_ie_called_pn(&information->CALLED_PN, msg, 0, 1, bc->info_dad, nt,bc);
  1264. {
  1265. if (*bc->display) {
  1266. #ifdef DEBUG
  1267. printf("Sending %s as Display\n", bc->display);
  1268. #endif
  1269. enc_ie_display(&information->DISPLAY, msg, bc->display, nt,bc);
  1270. }
  1271. }
  1272. #ifdef DEBUG
  1273. printf("Building INFORMATION Msg\n");
  1274. #endif
  1275. return msg;
  1276. }
  1277. static void parse_status (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1278. {
  1279. int HEADER_LEN = nt?mISDNUSER_HEAD_SIZE:mISDN_HEADER_LEN;
  1280. STATUS_t *status = (STATUS_t *) (msg->data + HEADER_LEN);
  1281. int location;
  1282. int cause;
  1283. dec_ie_cause(status->CAUSE, (Q931_info_t *)(status), &location, &cause, nt,bc);
  1284. if (cause>0) bc->cause=cause;
  1285. #ifdef DEBUG
  1286. printf("Parsing STATUS Msg\n");
  1287. #endif
  1288. }
  1289. static msg_t *build_status (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1290. {
  1291. msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
  1292. #ifdef DEBUG
  1293. printf("Building STATUS Msg\n");
  1294. #endif
  1295. return msg;
  1296. }
  1297. static void parse_timeout (struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1298. {
  1299. #ifdef DEBUG
  1300. printf("Parsing STATUS Msg\n");
  1301. #endif
  1302. }
  1303. static msg_t *build_timeout (struct isdn_msg msgs[], struct misdn_bchannel *bc, int nt)
  1304. {
  1305. msg_t *msg =(msg_t*)create_l3msg(CC_STATUS | REQUEST, MT_STATUS, bc?bc->l3_id:-1, sizeof(STATUS_t) ,nt);
  1306. #ifdef DEBUG
  1307. printf("Building STATUS Msg\n");
  1308. #endif
  1309. return msg;
  1310. }
  1311. /************************************/
  1312. /** Msg Array **/
  1313. struct isdn_msg msgs_g[] = {
  1314. /* *INDENT-OFF* */
  1315. /* misdn_msg, event, msg_parser, msg_builder, info */
  1316. { CC_PROCEEDING, EVENT_PROCEEDING, parse_proceeding, build_proceeding, "PROCEEDING" },
  1317. { CC_ALERTING, EVENT_ALERTING, parse_alerting, build_alerting, "ALERTING" },
  1318. { CC_PROGRESS, EVENT_PROGRESS, parse_progress, build_progress, "PROGRESS" },
  1319. { CC_SETUP, EVENT_SETUP, parse_setup, build_setup, "SETUP" },
  1320. #if defined(AST_MISDN_ENHANCEMENTS)
  1321. { CC_REGISTER, EVENT_REGISTER, parse_register, build_register, "REGISTER" },
  1322. #endif /* defined(AST_MISDN_ENHANCEMENTS) */
  1323. { CC_CONNECT, EVENT_CONNECT, parse_connect, build_connect, "CONNECT" },
  1324. { CC_SETUP_ACKNOWLEDGE, EVENT_SETUP_ACKNOWLEDGE, parse_setup_acknowledge, build_setup_acknowledge, "SETUP_ACKNOWLEDGE" },
  1325. { CC_CONNECT_ACKNOWLEDGE, EVENT_CONNECT_ACKNOWLEDGE, parse_connect_acknowledge, build_connect_acknowledge, "CONNECT_ACKNOWLEDGE " },
  1326. { CC_USER_INFORMATION, EVENT_USER_INFORMATION, parse_user_information, build_user_information, "USER_INFORMATION" },
  1327. { CC_SUSPEND_REJECT, EVENT_SUSPEND_REJECT, parse_suspend_reject, build_suspend_reject, "SUSPEND_REJECT" },
  1328. { CC_RESUME_REJECT, EVENT_RESUME_REJECT, parse_resume_reject, build_resume_reject, "RESUME_REJECT" },
  1329. { CC_HOLD, EVENT_HOLD, parse_hold, build_hold, "HOLD" },
  1330. { CC_SUSPEND, EVENT_SUSPEND, parse_suspend, build_suspend, "SUSPEND" },
  1331. { CC_RESUME, EVENT_RESUME, parse_resume, build_resume, "RESUME" },
  1332. { CC_HOLD_ACKNOWLEDGE, EVENT_HOLD_ACKNOWLEDGE, parse_hold_acknowledge, build_hold_acknowledge, "HOLD_ACKNOWLEDGE" },
  1333. { CC_SUSPEND_ACKNOWLEDGE, EVENT_SUSPEND_ACKNOWLEDGE, parse_suspend_acknowledge, build_suspend_acknowledge, "SUSPEND_ACKNOWLEDGE" },
  1334. { CC_RESUME_ACKNOWLEDGE, EVENT_RESUME_ACKNOWLEDGE, parse_resume_acknowledge, build_resume_acknowledge, "RESUME_ACKNOWLEDGE" },
  1335. { CC_HOLD_REJECT, EVENT_HOLD_REJECT, parse_hold_reject, build_hold_reject, "HOLD_REJECT" },
  1336. { CC_RETRIEVE, EVENT_RETRIEVE, parse_retrieve, build_retrieve, "RETRIEVE" },
  1337. { CC_RETRIEVE_ACKNOWLEDGE, EVENT_RETRIEVE_ACKNOWLEDGE, parse_retrieve_acknowledge, build_retrieve_acknowledge, "RETRIEVE_ACKNOWLEDGE" },
  1338. { CC_RETRIEVE_REJECT, EVENT_RETRIEVE_REJECT, parse_retrieve_reject, build_retrieve_reject, "RETRIEVE_REJECT" },
  1339. { CC_DISCONNECT, EVENT_DISCONNECT, parse_disconnect, build_disconnect, "DISCONNECT" },
  1340. { CC_RESTART, EVENT_RESTART, parse_restart, build_restart, "RESTART" },
  1341. { CC_RELEASE, EVENT_RELEASE, parse_release, build_release, "RELEASE" },
  1342. { CC_RELEASE_COMPLETE, EVENT_RELEASE_COMPLETE, parse_release_complete, build_release_complete, "RELEASE_COMPLETE" },
  1343. { CC_FACILITY, EVENT_FACILITY, parse_facility, build_facility, "FACILITY" },
  1344. { CC_NOTIFY, EVENT_NOTIFY, parse_notify, build_notify, "NOTIFY" },
  1345. { CC_STATUS_ENQUIRY, EVENT_STATUS_ENQUIRY, parse_status_enquiry, build_status_enquiry, "STATUS_ENQUIRY" },
  1346. { CC_INFORMATION, EVENT_INFORMATION, parse_information, build_information, "INFORMATION" },
  1347. { CC_STATUS, EVENT_STATUS, parse_status, build_status, "STATUS" },
  1348. { CC_TIMEOUT, EVENT_TIMEOUT, parse_timeout, build_timeout, "TIMEOUT" },
  1349. { 0, 0, NULL, NULL, NULL }
  1350. /* *INDENT-ON* */
  1351. };
  1352. #define msgs_max (sizeof(msgs_g)/sizeof(struct isdn_msg))
  1353. /** INTERFACE FCTS ***/
  1354. int isdn_msg_get_index(struct isdn_msg msgs[], msg_t *msg, int nt)
  1355. {
  1356. int i;
  1357. if (nt){
  1358. mISDNuser_head_t *hh = (mISDNuser_head_t*)msg->data;
  1359. for (i=0; i< msgs_max -1; i++) {
  1360. if ( (hh->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
  1361. }
  1362. } else {
  1363. iframe_t *frm = (iframe_t*)msg->data;
  1364. for (i=0; i< msgs_max -1; i++)
  1365. if ( (frm->prim&COMMAND_MASK)==(msgs[i].misdn_msg&COMMAND_MASK)) return i;
  1366. }
  1367. return -1;
  1368. }
  1369. int isdn_msg_get_index_by_event(struct isdn_msg msgs[], enum event_e event, int nt)
  1370. {
  1371. int i;
  1372. for (i=0; i< msgs_max; i++)
  1373. if ( event == msgs[i].event) return i;
  1374. cb_log(10,0, "get_index: event not found!\n");
  1375. return -1;
  1376. }
  1377. enum event_e isdn_msg_get_event(struct isdn_msg msgs[], msg_t *msg, int nt)
  1378. {
  1379. int i=isdn_msg_get_index(msgs, msg, nt);
  1380. if(i>=0) return msgs[i].event;
  1381. return EVENT_UNKNOWN;
  1382. }
  1383. char * isdn_msg_get_info(struct isdn_msg msgs[], msg_t *msg, int nt)
  1384. {
  1385. int i=isdn_msg_get_index(msgs, msg, nt);
  1386. if(i>=0) return msgs[i].info;
  1387. return NULL;
  1388. }
  1389. char EVENT_CLEAN_INFO[] = "CLEAN_UP";
  1390. char EVENT_DTMF_TONE_INFO[] = "DTMF_TONE";
  1391. char EVENT_NEW_L3ID_INFO[] = "NEW_L3ID";
  1392. char EVENT_NEW_BC_INFO[] = "NEW_BC";
  1393. char EVENT_PORT_ALARM_INFO[] = "ALARM";
  1394. char EVENT_NEW_CHANNEL_INFO[] = "NEW_CHANNEL";
  1395. char EVENT_BCHAN_DATA_INFO[] = "BCHAN_DATA";
  1396. char EVENT_BCHAN_ACTIVATED_INFO[] = "BCHAN_ACTIVATED";
  1397. char EVENT_TONE_GENERATE_INFO[] = "TONE_GENERATE";
  1398. char EVENT_BCHAN_ERROR_INFO[] = "BCHAN_ERROR";
  1399. char * isdn_get_info(struct isdn_msg msgs[], enum event_e event, int nt)
  1400. {
  1401. int i=isdn_msg_get_index_by_event(msgs, event, nt);
  1402. if(i>=0) return msgs[i].info;
  1403. if (event == EVENT_CLEANUP) return EVENT_CLEAN_INFO;
  1404. if (event == EVENT_DTMF_TONE) return EVENT_DTMF_TONE_INFO;
  1405. if (event == EVENT_NEW_L3ID) return EVENT_NEW_L3ID_INFO;
  1406. if (event == EVENT_NEW_BC) return EVENT_NEW_BC_INFO;
  1407. if (event == EVENT_NEW_CHANNEL) return EVENT_NEW_CHANNEL_INFO;
  1408. if (event == EVENT_BCHAN_DATA) return EVENT_BCHAN_DATA_INFO;
  1409. if (event == EVENT_BCHAN_ACTIVATED) return EVENT_BCHAN_ACTIVATED_INFO;
  1410. if (event == EVENT_TONE_GENERATE) return EVENT_TONE_GENERATE_INFO;
  1411. if (event == EVENT_PORT_ALARM) return EVENT_PORT_ALARM_INFO;
  1412. if (event == EVENT_BCHAN_ERROR) return EVENT_BCHAN_ERROR_INFO;
  1413. return NULL;
  1414. }
  1415. int isdn_msg_parse_event(struct isdn_msg msgs[], msg_t *msg, struct misdn_bchannel *bc, int nt)
  1416. {
  1417. int i=isdn_msg_get_index(msgs, msg, nt);
  1418. if(i<0) return -1;
  1419. msgs[i].msg_parser(msgs, msg, bc, nt);
  1420. return 0;
  1421. }
  1422. msg_t * isdn_msg_build_event(struct isdn_msg msgs[], struct misdn_bchannel *bc, enum event_e event, int nt)
  1423. {
  1424. int i=isdn_msg_get_index_by_event(msgs, event, nt);
  1425. if(i<0) return NULL;
  1426. return msgs[i].msg_builder(msgs, bc, nt);
  1427. }