l3dss1.c 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226
  1. /* $Id: l3dss1.c,v 2.32.2.3 2004/01/13 14:31:25 keil Exp $
  2. *
  3. * EURO/DSS1 D-channel protocol
  4. *
  5. * German 1TR6 D-channel protocol
  6. *
  7. * Author Karsten Keil
  8. * based on the teles driver from Jan den Ouden
  9. * Copyright by Karsten Keil <keil@isdn4linux.de>
  10. *
  11. * This software may be used and distributed according to the terms
  12. * of the GNU General Public License, incorporated herein by reference.
  13. *
  14. * For changes and modifications please read
  15. * Documentation/isdn/HiSax.cert
  16. *
  17. * Thanks to Jan den Ouden
  18. * Fritz Elfert
  19. *
  20. */
  21. #include "hisax.h"
  22. #include "isdnl3.h"
  23. #include "l3dss1.h"
  24. #include <linux/ctype.h>
  25. #include <linux/slab.h>
  26. extern char *HiSax_getrev(const char *revision);
  27. static const char *dss1_revision = "$Revision: 2.32.2.3 $";
  28. #define EXT_BEARER_CAPS 1
  29. #define MsgHead(ptr, cref, mty) \
  30. *ptr++ = 0x8; \
  31. if (cref == -1) { \
  32. *ptr++ = 0x0; \
  33. } else { \
  34. *ptr++ = 0x1; \
  35. *ptr++ = cref^0x80; \
  36. } \
  37. *ptr++ = mty
  38. /**********************************************/
  39. /* get a new invoke id for remote operations. */
  40. /* Only a return value != 0 is valid */
  41. /**********************************************/
  42. static unsigned char new_invoke_id(struct PStack *p)
  43. {
  44. unsigned char retval;
  45. int i;
  46. i = 32; /* maximum search depth */
  47. retval = p->prot.dss1.last_invoke_id + 1; /* try new id */
  48. while ((i) && (p->prot.dss1.invoke_used[retval >> 3] == 0xFF)) {
  49. p->prot.dss1.last_invoke_id = (retval & 0xF8) + 8;
  50. i--;
  51. }
  52. if (i) {
  53. while (p->prot.dss1.invoke_used[retval >> 3] & (1 << (retval & 7)))
  54. retval++;
  55. } else
  56. retval = 0;
  57. p->prot.dss1.last_invoke_id = retval;
  58. p->prot.dss1.invoke_used[retval >> 3] |= (1 << (retval & 7));
  59. return (retval);
  60. } /* new_invoke_id */
  61. /*************************/
  62. /* free a used invoke id */
  63. /*************************/
  64. static void free_invoke_id(struct PStack *p, unsigned char id)
  65. {
  66. if (!id) return; /* 0 = invalid value */
  67. p->prot.dss1.invoke_used[id >> 3] &= ~(1 << (id & 7));
  68. } /* free_invoke_id */
  69. /**********************************************************/
  70. /* create a new l3 process and fill in dss1 specific data */
  71. /**********************************************************/
  72. static struct l3_process
  73. *dss1_new_l3_process(struct PStack *st, int cr)
  74. { struct l3_process *proc;
  75. if (!(proc = new_l3_process(st, cr)))
  76. return (NULL);
  77. proc->prot.dss1.invoke_id = 0;
  78. proc->prot.dss1.remote_operation = 0;
  79. proc->prot.dss1.uus1_data[0] = '\0';
  80. return (proc);
  81. } /* dss1_new_l3_process */
  82. /************************************************/
  83. /* free a l3 process and all dss1 specific data */
  84. /************************************************/
  85. static void
  86. dss1_release_l3_process(struct l3_process *p)
  87. {
  88. free_invoke_id(p->st, p->prot.dss1.invoke_id);
  89. release_l3_process(p);
  90. } /* dss1_release_l3_process */
  91. /********************************************************/
  92. /* search a process with invoke id id and dummy callref */
  93. /********************************************************/
  94. static struct l3_process *
  95. l3dss1_search_dummy_proc(struct PStack *st, int id)
  96. { struct l3_process *pc = st->l3.proc; /* start of processes */
  97. if (!id) return (NULL);
  98. while (pc)
  99. { if ((pc->callref == -1) && (pc->prot.dss1.invoke_id == id))
  100. return (pc);
  101. pc = pc->next;
  102. }
  103. return (NULL);
  104. } /* l3dss1_search_dummy_proc */
  105. /*******************************************************************/
  106. /* called when a facility message with a dummy callref is received */
  107. /* and a return result is delivered. id specifies the invoke id. */
  108. /*******************************************************************/
  109. static void
  110. l3dss1_dummy_return_result(struct PStack *st, int id, u_char *p, u_char nlen)
  111. { isdn_ctrl ic;
  112. struct IsdnCardState *cs;
  113. struct l3_process *pc = NULL;
  114. if ((pc = l3dss1_search_dummy_proc(st, id)))
  115. { L3DelTimer(&pc->timer); /* remove timer */
  116. cs = pc->st->l1.hardware;
  117. ic.driver = cs->myid;
  118. ic.command = ISDN_STAT_PROT;
  119. ic.arg = DSS1_STAT_INVOKE_RES;
  120. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  121. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  122. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  123. ic.parm.dss1_io.timeout = 0;
  124. ic.parm.dss1_io.datalen = nlen;
  125. ic.parm.dss1_io.data = p;
  126. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  127. pc->prot.dss1.invoke_id = 0; /* reset id */
  128. cs->iif.statcallb(&ic);
  129. dss1_release_l3_process(pc);
  130. }
  131. else
  132. l3_debug(st, "dummy return result id=0x%x result len=%d", id, nlen);
  133. } /* l3dss1_dummy_return_result */
  134. /*******************************************************************/
  135. /* called when a facility message with a dummy callref is received */
  136. /* and a return error is delivered. id specifies the invoke id. */
  137. /*******************************************************************/
  138. static void
  139. l3dss1_dummy_error_return(struct PStack *st, int id, ulong error)
  140. { isdn_ctrl ic;
  141. struct IsdnCardState *cs;
  142. struct l3_process *pc = NULL;
  143. if ((pc = l3dss1_search_dummy_proc(st, id)))
  144. { L3DelTimer(&pc->timer); /* remove timer */
  145. cs = pc->st->l1.hardware;
  146. ic.driver = cs->myid;
  147. ic.command = ISDN_STAT_PROT;
  148. ic.arg = DSS1_STAT_INVOKE_ERR;
  149. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  150. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  151. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  152. ic.parm.dss1_io.timeout = error;
  153. ic.parm.dss1_io.datalen = 0;
  154. ic.parm.dss1_io.data = NULL;
  155. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  156. pc->prot.dss1.invoke_id = 0; /* reset id */
  157. cs->iif.statcallb(&ic);
  158. dss1_release_l3_process(pc);
  159. }
  160. else
  161. l3_debug(st, "dummy return error id=0x%x error=0x%lx", id, error);
  162. } /* l3dss1_error_return */
  163. /*******************************************************************/
  164. /* called when a facility message with a dummy callref is received */
  165. /* and a invoke is delivered. id specifies the invoke id. */
  166. /*******************************************************************/
  167. static void
  168. l3dss1_dummy_invoke(struct PStack *st, int cr, int id,
  169. int ident, u_char *p, u_char nlen)
  170. { isdn_ctrl ic;
  171. struct IsdnCardState *cs;
  172. l3_debug(st, "dummy invoke %s id=0x%x ident=0x%x datalen=%d",
  173. (cr == -1) ? "local" : "broadcast", id, ident, nlen);
  174. if (cr >= -1) return; /* ignore local data */
  175. cs = st->l1.hardware;
  176. ic.driver = cs->myid;
  177. ic.command = ISDN_STAT_PROT;
  178. ic.arg = DSS1_STAT_INVOKE_BRD;
  179. ic.parm.dss1_io.hl_id = id;
  180. ic.parm.dss1_io.ll_id = 0;
  181. ic.parm.dss1_io.proc = ident;
  182. ic.parm.dss1_io.timeout = 0;
  183. ic.parm.dss1_io.datalen = nlen;
  184. ic.parm.dss1_io.data = p;
  185. cs->iif.statcallb(&ic);
  186. } /* l3dss1_dummy_invoke */
  187. static void
  188. l3dss1_parse_facility(struct PStack *st, struct l3_process *pc,
  189. int cr, u_char *p)
  190. {
  191. int qd_len = 0;
  192. unsigned char nlen = 0, ilen, cp_tag;
  193. int ident, id;
  194. ulong err_ret;
  195. if (pc)
  196. st = pc->st; /* valid Stack */
  197. else
  198. if ((!st) || (cr >= 0)) return; /* neither pc nor st specified */
  199. p++;
  200. qd_len = *p++;
  201. if (qd_len == 0) {
  202. l3_debug(st, "qd_len == 0");
  203. return;
  204. }
  205. if ((*p & 0x1F) != 0x11) { /* Service discriminator, supplementary service */
  206. l3_debug(st, "supplementary service != 0x11");
  207. return;
  208. }
  209. while (qd_len > 0 && !(*p & 0x80)) { /* extension ? */
  210. p++;
  211. qd_len--;
  212. }
  213. if (qd_len < 2) {
  214. l3_debug(st, "qd_len < 2");
  215. return;
  216. }
  217. p++;
  218. qd_len--;
  219. if ((*p & 0xE0) != 0xA0) { /* class and form */
  220. l3_debug(st, "class and form != 0xA0");
  221. return;
  222. }
  223. cp_tag = *p & 0x1F; /* remember tag value */
  224. p++;
  225. qd_len--;
  226. if (qd_len < 1)
  227. { l3_debug(st, "qd_len < 1");
  228. return;
  229. }
  230. if (*p & 0x80)
  231. { /* length format indefinite or limited */
  232. nlen = *p++ & 0x7F; /* number of len bytes or indefinite */
  233. if ((qd_len-- < ((!nlen) ? 3 : (1 + nlen))) ||
  234. (nlen > 1))
  235. { l3_debug(st, "length format error or not implemented");
  236. return;
  237. }
  238. if (nlen == 1)
  239. { nlen = *p++; /* complete length */
  240. qd_len--;
  241. }
  242. else
  243. { qd_len -= 2; /* trailing null bytes */
  244. if ((*(p + qd_len)) || (*(p + qd_len + 1)))
  245. { l3_debug(st, "length format indefinite error");
  246. return;
  247. }
  248. nlen = qd_len;
  249. }
  250. }
  251. else
  252. { nlen = *p++;
  253. qd_len--;
  254. }
  255. if (qd_len < nlen)
  256. { l3_debug(st, "qd_len < nlen");
  257. return;
  258. }
  259. qd_len -= nlen;
  260. if (nlen < 2)
  261. { l3_debug(st, "nlen < 2");
  262. return;
  263. }
  264. if (*p != 0x02)
  265. { /* invoke identifier tag */
  266. l3_debug(st, "invoke identifier tag !=0x02");
  267. return;
  268. }
  269. p++;
  270. nlen--;
  271. if (*p & 0x80)
  272. { /* length format */
  273. l3_debug(st, "invoke id length format 2");
  274. return;
  275. }
  276. ilen = *p++;
  277. nlen--;
  278. if (ilen > nlen || ilen == 0)
  279. { l3_debug(st, "ilen > nlen || ilen == 0");
  280. return;
  281. }
  282. nlen -= ilen;
  283. id = 0;
  284. while (ilen > 0)
  285. { id = (id << 8) | (*p++ & 0xFF); /* invoke identifier */
  286. ilen--;
  287. }
  288. switch (cp_tag) { /* component tag */
  289. case 1: /* invoke */
  290. if (nlen < 2) {
  291. l3_debug(st, "nlen < 2 22");
  292. return;
  293. }
  294. if (*p != 0x02) { /* operation value */
  295. l3_debug(st, "operation value !=0x02");
  296. return;
  297. }
  298. p++;
  299. nlen--;
  300. ilen = *p++;
  301. nlen--;
  302. if (ilen > nlen || ilen == 0) {
  303. l3_debug(st, "ilen > nlen || ilen == 0 22");
  304. return;
  305. }
  306. nlen -= ilen;
  307. ident = 0;
  308. while (ilen > 0) {
  309. ident = (ident << 8) | (*p++ & 0xFF);
  310. ilen--;
  311. }
  312. if (!pc)
  313. { l3dss1_dummy_invoke(st, cr, id, ident, p, nlen);
  314. return;
  315. }
  316. #ifdef CONFIG_DE_AOC
  317. {
  318. #define FOO1(s, a, b) \
  319. while (nlen > 1) { \
  320. int ilen = p[1]; \
  321. if (nlen < ilen + 2) { \
  322. l3_debug(st, "FOO1 nlen < ilen+2"); \
  323. return; \
  324. } \
  325. nlen -= ilen + 2; \
  326. if ((*p & 0xFF) == (a)) { \
  327. int nlen = ilen; \
  328. p += 2; \
  329. b; \
  330. } else { \
  331. p += ilen + 2; \
  332. } \
  333. }
  334. switch (ident) {
  335. case 0x22: /* during */
  336. FOO1("1A", 0x30, FOO1("1C", 0xA1, FOO1("1D", 0x30, FOO1("1E", 0x02, ( {
  337. ident = 0;
  338. nlen = (nlen) ? nlen : 0; /* Make gcc happy */
  339. while (ilen > 0) {
  340. ident = (ident << 8) | *p++;
  341. ilen--;
  342. }
  343. if (ident > pc->para.chargeinfo) {
  344. pc->para.chargeinfo = ident;
  345. st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
  346. }
  347. if (st->l3.debug & L3_DEB_CHARGE) {
  348. if (*(p + 2) == 0) {
  349. l3_debug(st, "charging info during %d", pc->para.chargeinfo);
  350. }
  351. else {
  352. l3_debug(st, "charging info final %d", pc->para.chargeinfo);
  353. }
  354. }
  355. }
  356. )))))
  357. break;
  358. case 0x24: /* final */
  359. FOO1("2A", 0x30, FOO1("2B", 0x30, FOO1("2C", 0xA1, FOO1("2D", 0x30, FOO1("2E", 0x02, ( {
  360. ident = 0;
  361. nlen = (nlen) ? nlen : 0; /* Make gcc happy */
  362. while (ilen > 0) {
  363. ident = (ident << 8) | *p++;
  364. ilen--;
  365. }
  366. if (ident > pc->para.chargeinfo) {
  367. pc->para.chargeinfo = ident;
  368. st->l3.l3l4(st, CC_CHARGE | INDICATION, pc);
  369. }
  370. if (st->l3.debug & L3_DEB_CHARGE) {
  371. l3_debug(st, "charging info final %d", pc->para.chargeinfo);
  372. }
  373. }
  374. ))))))
  375. break;
  376. default:
  377. l3_debug(st, "invoke break invalid ident %02x", ident);
  378. break;
  379. }
  380. #undef FOO1
  381. }
  382. #else /* not CONFIG_DE_AOC */
  383. l3_debug(st, "invoke break");
  384. #endif /* not CONFIG_DE_AOC */
  385. break;
  386. case 2: /* return result */
  387. /* if no process available handle separately */
  388. if (!pc)
  389. { if (cr == -1)
  390. l3dss1_dummy_return_result(st, id, p, nlen);
  391. return;
  392. }
  393. if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
  394. { /* Diversion successful */
  395. free_invoke_id(st, pc->prot.dss1.invoke_id);
  396. pc->prot.dss1.remote_result = 0; /* success */
  397. pc->prot.dss1.invoke_id = 0;
  398. pc->redir_result = pc->prot.dss1.remote_result;
  399. st->l3.l3l4(st, CC_REDIR | INDICATION, pc); } /* Diversion successful */
  400. else
  401. l3_debug(st, "return error unknown identifier");
  402. break;
  403. case 3: /* return error */
  404. err_ret = 0;
  405. if (nlen < 2)
  406. { l3_debug(st, "return error nlen < 2");
  407. return;
  408. }
  409. if (*p != 0x02)
  410. { /* result tag */
  411. l3_debug(st, "invoke error tag !=0x02");
  412. return;
  413. }
  414. p++;
  415. nlen--;
  416. if (*p > 4)
  417. { /* length format */
  418. l3_debug(st, "invoke return errlen > 4 ");
  419. return;
  420. }
  421. ilen = *p++;
  422. nlen--;
  423. if (ilen > nlen || ilen == 0)
  424. { l3_debug(st, "error return ilen > nlen || ilen == 0");
  425. return;
  426. }
  427. nlen -= ilen;
  428. while (ilen > 0)
  429. { err_ret = (err_ret << 8) | (*p++ & 0xFF); /* error value */
  430. ilen--;
  431. }
  432. /* if no process available handle separately */
  433. if (!pc)
  434. { if (cr == -1)
  435. l3dss1_dummy_error_return(st, id, err_ret);
  436. return;
  437. }
  438. if ((pc->prot.dss1.invoke_id) && (pc->prot.dss1.invoke_id == id))
  439. { /* Deflection error */
  440. free_invoke_id(st, pc->prot.dss1.invoke_id);
  441. pc->prot.dss1.remote_result = err_ret; /* result */
  442. pc->prot.dss1.invoke_id = 0;
  443. pc->redir_result = pc->prot.dss1.remote_result;
  444. st->l3.l3l4(st, CC_REDIR | INDICATION, pc);
  445. } /* Deflection error */
  446. else
  447. l3_debug(st, "return result unknown identifier");
  448. break;
  449. default:
  450. l3_debug(st, "facility default break tag=0x%02x", cp_tag);
  451. break;
  452. }
  453. }
  454. static void
  455. l3dss1_message(struct l3_process *pc, u_char mt)
  456. {
  457. struct sk_buff *skb;
  458. u_char *p;
  459. if (!(skb = l3_alloc_skb(4)))
  460. return;
  461. p = skb_put(skb, 4);
  462. MsgHead(p, pc->callref, mt);
  463. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  464. }
  465. static void
  466. l3dss1_message_cause(struct l3_process *pc, u_char mt, u_char cause)
  467. {
  468. struct sk_buff *skb;
  469. u_char tmp[16];
  470. u_char *p = tmp;
  471. int l;
  472. MsgHead(p, pc->callref, mt);
  473. *p++ = IE_CAUSE;
  474. *p++ = 0x2;
  475. *p++ = 0x80;
  476. *p++ = cause | 0x80;
  477. l = p - tmp;
  478. if (!(skb = l3_alloc_skb(l)))
  479. return;
  480. memcpy(skb_put(skb, l), tmp, l);
  481. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  482. }
  483. static void
  484. l3dss1_status_send(struct l3_process *pc, u_char pr, void *arg)
  485. {
  486. u_char tmp[16];
  487. u_char *p = tmp;
  488. int l;
  489. struct sk_buff *skb;
  490. MsgHead(p, pc->callref, MT_STATUS);
  491. *p++ = IE_CAUSE;
  492. *p++ = 0x2;
  493. *p++ = 0x80;
  494. *p++ = pc->para.cause | 0x80;
  495. *p++ = IE_CALL_STATE;
  496. *p++ = 0x1;
  497. *p++ = pc->state & 0x3f;
  498. l = p - tmp;
  499. if (!(skb = l3_alloc_skb(l)))
  500. return;
  501. memcpy(skb_put(skb, l), tmp, l);
  502. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  503. }
  504. static void
  505. l3dss1_msg_without_setup(struct l3_process *pc, u_char pr, void *arg)
  506. {
  507. /* This routine is called if here was no SETUP made (checks in dss1up and in
  508. * l3dss1_setup) and a RELEASE_COMPLETE have to be sent with an error code
  509. * MT_STATUS_ENQUIRE in the NULL state is handled too
  510. */
  511. u_char tmp[16];
  512. u_char *p = tmp;
  513. int l;
  514. struct sk_buff *skb;
  515. switch (pc->para.cause) {
  516. case 81: /* invalid callreference */
  517. case 88: /* incomp destination */
  518. case 96: /* mandory IE missing */
  519. case 100: /* invalid IE contents */
  520. case 101: /* incompatible Callstate */
  521. MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
  522. *p++ = IE_CAUSE;
  523. *p++ = 0x2;
  524. *p++ = 0x80;
  525. *p++ = pc->para.cause | 0x80;
  526. break;
  527. default:
  528. printk(KERN_ERR "HiSax l3dss1_msg_without_setup wrong cause %d\n",
  529. pc->para.cause);
  530. return;
  531. }
  532. l = p - tmp;
  533. if (!(skb = l3_alloc_skb(l)))
  534. return;
  535. memcpy(skb_put(skb, l), tmp, l);
  536. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  537. dss1_release_l3_process(pc);
  538. }
  539. static int ie_ALERTING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  540. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_HLC,
  541. IE_USER_USER, -1};
  542. static int ie_CALL_PROCEEDING[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  543. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_HLC, -1};
  544. static int ie_CONNECT[] = {IE_BEARER, IE_CHANNEL_ID | IE_MANDATORY_1,
  545. IE_FACILITY, IE_PROGRESS, IE_DISPLAY, IE_DATE, IE_SIGNAL,
  546. IE_CONNECT_PN, IE_CONNECT_SUB, IE_LLC, IE_HLC, IE_USER_USER, -1};
  547. static int ie_CONNECT_ACKNOWLEDGE[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_SIGNAL, -1};
  548. static int ie_DISCONNECT[] = {IE_CAUSE | IE_MANDATORY, IE_FACILITY,
  549. IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
  550. static int ie_INFORMATION[] = {IE_COMPLETE, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL,
  551. IE_CALLED_PN, -1};
  552. static int ie_NOTIFY[] = {IE_BEARER, IE_NOTIFY | IE_MANDATORY, IE_DISPLAY, -1};
  553. static int ie_PROGRESS[] = {IE_BEARER, IE_CAUSE, IE_FACILITY, IE_PROGRESS |
  554. IE_MANDATORY, IE_DISPLAY, IE_HLC, IE_USER_USER, -1};
  555. static int ie_RELEASE[] = {IE_CAUSE | IE_MANDATORY_1, IE_FACILITY, IE_DISPLAY,
  556. IE_SIGNAL, IE_USER_USER, -1};
  557. /* a RELEASE_COMPLETE with errors don't require special actions
  558. static int ie_RELEASE_COMPLETE[] = {IE_CAUSE | IE_MANDATORY_1, IE_DISPLAY, IE_SIGNAL, IE_USER_USER, -1};
  559. */
  560. static int ie_RESUME_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
  561. IE_DISPLAY, -1};
  562. static int ie_RESUME_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  563. static int ie_SETUP[] = {IE_COMPLETE, IE_BEARER | IE_MANDATORY,
  564. IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY, IE_PROGRESS,
  565. IE_NET_FAC, IE_DISPLAY, IE_KEYPAD, IE_SIGNAL, IE_CALLING_PN,
  566. IE_CALLING_SUB, IE_CALLED_PN, IE_CALLED_SUB, IE_REDIR_NR,
  567. IE_LLC, IE_HLC, IE_USER_USER, -1};
  568. static int ie_SETUP_ACKNOWLEDGE[] = {IE_CHANNEL_ID | IE_MANDATORY, IE_FACILITY,
  569. IE_PROGRESS, IE_DISPLAY, IE_SIGNAL, -1};
  570. static int ie_STATUS[] = {IE_CAUSE | IE_MANDATORY, IE_CALL_STATE |
  571. IE_MANDATORY, IE_DISPLAY, -1};
  572. static int ie_STATUS_ENQUIRY[] = {IE_DISPLAY, -1};
  573. static int ie_SUSPEND_ACKNOWLEDGE[] = {IE_DISPLAY, IE_FACILITY, -1};
  574. static int ie_SUSPEND_REJECT[] = {IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  575. /* not used
  576. * static int ie_CONGESTION_CONTROL[] = {IE_CONGESTION | IE_MANDATORY,
  577. * IE_CAUSE | IE_MANDATORY, IE_DISPLAY, -1};
  578. * static int ie_USER_INFORMATION[] = {IE_MORE_DATA, IE_USER_USER | IE_MANDATORY, -1};
  579. * static int ie_RESTART[] = {IE_CHANNEL_ID, IE_DISPLAY, IE_RESTART_IND |
  580. * IE_MANDATORY, -1};
  581. */
  582. static int ie_FACILITY[] = {IE_FACILITY | IE_MANDATORY, IE_DISPLAY, -1};
  583. static int comp_required[] = {1, 2, 3, 5, 6, 7, 9, 10, 11, 14, 15, -1};
  584. static int l3_valid_states[] = {0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 15, 17, 19, 25, -1};
  585. struct ie_len {
  586. int ie;
  587. int len;
  588. };
  589. static
  590. struct ie_len max_ie_len[] = {
  591. {IE_SEGMENT, 4},
  592. {IE_BEARER, 12},
  593. {IE_CAUSE, 32},
  594. {IE_CALL_ID, 10},
  595. {IE_CALL_STATE, 3},
  596. {IE_CHANNEL_ID, 34},
  597. {IE_FACILITY, 255},
  598. {IE_PROGRESS, 4},
  599. {IE_NET_FAC, 255},
  600. {IE_NOTIFY, 3},
  601. {IE_DISPLAY, 82},
  602. {IE_DATE, 8},
  603. {IE_KEYPAD, 34},
  604. {IE_SIGNAL, 3},
  605. {IE_INFORATE, 6},
  606. {IE_E2E_TDELAY, 11},
  607. {IE_TDELAY_SEL, 5},
  608. {IE_PACK_BINPARA, 3},
  609. {IE_PACK_WINSIZE, 4},
  610. {IE_PACK_SIZE, 4},
  611. {IE_CUG, 7},
  612. {IE_REV_CHARGE, 3},
  613. {IE_CALLING_PN, 24},
  614. {IE_CALLING_SUB, 23},
  615. {IE_CALLED_PN, 24},
  616. {IE_CALLED_SUB, 23},
  617. {IE_REDIR_NR, 255},
  618. {IE_TRANS_SEL, 255},
  619. {IE_RESTART_IND, 3},
  620. {IE_LLC, 18},
  621. {IE_HLC, 5},
  622. {IE_USER_USER, 131},
  623. {-1, 0},
  624. };
  625. static int
  626. getmax_ie_len(u_char ie) {
  627. int i = 0;
  628. while (max_ie_len[i].ie != -1) {
  629. if (max_ie_len[i].ie == ie)
  630. return (max_ie_len[i].len);
  631. i++;
  632. }
  633. return (255);
  634. }
  635. static int
  636. ie_in_set(struct l3_process *pc, u_char ie, int *checklist) {
  637. int ret = 1;
  638. while (*checklist != -1) {
  639. if ((*checklist & 0xff) == ie) {
  640. if (ie & 0x80)
  641. return (-ret);
  642. else
  643. return (ret);
  644. }
  645. ret++;
  646. checklist++;
  647. }
  648. return (0);
  649. }
  650. static int
  651. check_infoelements(struct l3_process *pc, struct sk_buff *skb, int *checklist)
  652. {
  653. int *cl = checklist;
  654. u_char mt;
  655. u_char *p, ie;
  656. int l, newpos, oldpos;
  657. int err_seq = 0, err_len = 0, err_compr = 0, err_ureg = 0;
  658. u_char codeset = 0;
  659. u_char old_codeset = 0;
  660. u_char codelock = 1;
  661. p = skb->data;
  662. /* skip cr */
  663. p++;
  664. l = (*p++) & 0xf;
  665. p += l;
  666. mt = *p++;
  667. oldpos = 0;
  668. while ((p - skb->data) < skb->len) {
  669. if ((*p & 0xf0) == 0x90) { /* shift codeset */
  670. old_codeset = codeset;
  671. codeset = *p & 7;
  672. if (*p & 0x08)
  673. codelock = 0;
  674. else
  675. codelock = 1;
  676. if (pc->debug & L3_DEB_CHECK)
  677. l3_debug(pc->st, "check IE shift%scodeset %d->%d",
  678. codelock ? " locking " : " ", old_codeset, codeset);
  679. p++;
  680. continue;
  681. }
  682. if (!codeset) { /* only codeset 0 */
  683. if ((newpos = ie_in_set(pc, *p, cl))) {
  684. if (newpos > 0) {
  685. if (newpos < oldpos)
  686. err_seq++;
  687. else
  688. oldpos = newpos;
  689. }
  690. } else {
  691. if (ie_in_set(pc, *p, comp_required))
  692. err_compr++;
  693. else
  694. err_ureg++;
  695. }
  696. }
  697. ie = *p++;
  698. if (ie & 0x80) {
  699. l = 1;
  700. } else {
  701. l = *p++;
  702. p += l;
  703. l += 2;
  704. }
  705. if (!codeset && (l > getmax_ie_len(ie)))
  706. err_len++;
  707. if (!codelock) {
  708. if (pc->debug & L3_DEB_CHECK)
  709. l3_debug(pc->st, "check IE shift back codeset %d->%d",
  710. codeset, old_codeset);
  711. codeset = old_codeset;
  712. codelock = 1;
  713. }
  714. }
  715. if (err_compr | err_ureg | err_len | err_seq) {
  716. if (pc->debug & L3_DEB_CHECK)
  717. l3_debug(pc->st, "check IE MT(%x) %d/%d/%d/%d",
  718. mt, err_compr, err_ureg, err_len, err_seq);
  719. if (err_compr)
  720. return (ERR_IE_COMPREHENSION);
  721. if (err_ureg)
  722. return (ERR_IE_UNRECOGNIZED);
  723. if (err_len)
  724. return (ERR_IE_LENGTH);
  725. if (err_seq)
  726. return (ERR_IE_SEQUENCE);
  727. }
  728. return (0);
  729. }
  730. /* verify if a message type exists and contain no IE error */
  731. static int
  732. l3dss1_check_messagetype_validity(struct l3_process *pc, int mt, void *arg)
  733. {
  734. switch (mt) {
  735. case MT_ALERTING:
  736. case MT_CALL_PROCEEDING:
  737. case MT_CONNECT:
  738. case MT_CONNECT_ACKNOWLEDGE:
  739. case MT_DISCONNECT:
  740. case MT_INFORMATION:
  741. case MT_FACILITY:
  742. case MT_NOTIFY:
  743. case MT_PROGRESS:
  744. case MT_RELEASE:
  745. case MT_RELEASE_COMPLETE:
  746. case MT_SETUP:
  747. case MT_SETUP_ACKNOWLEDGE:
  748. case MT_RESUME_ACKNOWLEDGE:
  749. case MT_RESUME_REJECT:
  750. case MT_SUSPEND_ACKNOWLEDGE:
  751. case MT_SUSPEND_REJECT:
  752. case MT_USER_INFORMATION:
  753. case MT_RESTART:
  754. case MT_RESTART_ACKNOWLEDGE:
  755. case MT_CONGESTION_CONTROL:
  756. case MT_STATUS:
  757. case MT_STATUS_ENQUIRY:
  758. if (pc->debug & L3_DEB_CHECK)
  759. l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) OK", mt);
  760. break;
  761. case MT_RESUME: /* RESUME only in user->net */
  762. case MT_SUSPEND: /* SUSPEND only in user->net */
  763. default:
  764. if (pc->debug & (L3_DEB_CHECK | L3_DEB_WARN))
  765. l3_debug(pc->st, "l3dss1_check_messagetype_validity mt(%x) fail", mt);
  766. pc->para.cause = 97;
  767. l3dss1_status_send(pc, 0, NULL);
  768. return (1);
  769. }
  770. return (0);
  771. }
  772. static void
  773. l3dss1_std_ie_err(struct l3_process *pc, int ret) {
  774. if (pc->debug & L3_DEB_CHECK)
  775. l3_debug(pc->st, "check_infoelements ret %d", ret);
  776. switch (ret) {
  777. case 0:
  778. break;
  779. case ERR_IE_COMPREHENSION:
  780. pc->para.cause = 96;
  781. l3dss1_status_send(pc, 0, NULL);
  782. break;
  783. case ERR_IE_UNRECOGNIZED:
  784. pc->para.cause = 99;
  785. l3dss1_status_send(pc, 0, NULL);
  786. break;
  787. case ERR_IE_LENGTH:
  788. pc->para.cause = 100;
  789. l3dss1_status_send(pc, 0, NULL);
  790. break;
  791. case ERR_IE_SEQUENCE:
  792. default:
  793. break;
  794. }
  795. }
  796. static int
  797. l3dss1_get_channel_id(struct l3_process *pc, struct sk_buff *skb) {
  798. u_char *p;
  799. p = skb->data;
  800. if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
  801. p++;
  802. if (*p != 1) { /* len for BRI = 1 */
  803. if (pc->debug & L3_DEB_WARN)
  804. l3_debug(pc->st, "wrong chid len %d", *p);
  805. return (-2);
  806. }
  807. p++;
  808. if (*p & 0x60) { /* only base rate interface */
  809. if (pc->debug & L3_DEB_WARN)
  810. l3_debug(pc->st, "wrong chid %x", *p);
  811. return (-3);
  812. }
  813. return (*p & 0x3);
  814. } else
  815. return (-1);
  816. }
  817. static int
  818. l3dss1_get_cause(struct l3_process *pc, struct sk_buff *skb) {
  819. u_char l, i = 0;
  820. u_char *p;
  821. p = skb->data;
  822. pc->para.cause = 31;
  823. pc->para.loc = 0;
  824. if ((p = findie(p, skb->len, IE_CAUSE, 0))) {
  825. p++;
  826. l = *p++;
  827. if (l > 30)
  828. return (1);
  829. if (l) {
  830. pc->para.loc = *p++;
  831. l--;
  832. } else {
  833. return (2);
  834. }
  835. if (l && !(pc->para.loc & 0x80)) {
  836. l--;
  837. p++; /* skip recommendation */
  838. }
  839. if (l) {
  840. pc->para.cause = *p++;
  841. l--;
  842. if (!(pc->para.cause & 0x80))
  843. return (3);
  844. } else
  845. return (4);
  846. while (l && (i < 6)) {
  847. pc->para.diag[i++] = *p++;
  848. l--;
  849. }
  850. } else
  851. return (-1);
  852. return (0);
  853. }
  854. static void
  855. l3dss1_msg_with_uus(struct l3_process *pc, u_char cmd)
  856. {
  857. struct sk_buff *skb;
  858. u_char tmp[16 + 40];
  859. u_char *p = tmp;
  860. int l;
  861. MsgHead(p, pc->callref, cmd);
  862. if (pc->prot.dss1.uus1_data[0])
  863. { *p++ = IE_USER_USER; /* UUS info element */
  864. *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
  865. *p++ = 0x04; /* IA5 chars */
  866. strcpy(p, pc->prot.dss1.uus1_data);
  867. p += strlen(pc->prot.dss1.uus1_data);
  868. pc->prot.dss1.uus1_data[0] = '\0';
  869. }
  870. l = p - tmp;
  871. if (!(skb = l3_alloc_skb(l)))
  872. return;
  873. memcpy(skb_put(skb, l), tmp, l);
  874. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  875. } /* l3dss1_msg_with_uus */
  876. static void
  877. l3dss1_release_req(struct l3_process *pc, u_char pr, void *arg)
  878. {
  879. StopAllL3Timer(pc);
  880. newl3state(pc, 19);
  881. if (!pc->prot.dss1.uus1_data[0])
  882. l3dss1_message(pc, MT_RELEASE);
  883. else
  884. l3dss1_msg_with_uus(pc, MT_RELEASE);
  885. L3AddTimer(&pc->timer, T308, CC_T308_1);
  886. }
  887. static void
  888. l3dss1_release_cmpl(struct l3_process *pc, u_char pr, void *arg)
  889. {
  890. struct sk_buff *skb = arg;
  891. int ret;
  892. if ((ret = l3dss1_get_cause(pc, skb)) > 0) {
  893. if (pc->debug & L3_DEB_WARN)
  894. l3_debug(pc->st, "RELCMPL get_cause ret(%d)", ret);
  895. } else if (ret < 0)
  896. pc->para.cause = NO_CAUSE;
  897. StopAllL3Timer(pc);
  898. newl3state(pc, 0);
  899. pc->st->l3.l3l4(pc->st, CC_RELEASE | CONFIRM, pc);
  900. dss1_release_l3_process(pc);
  901. }
  902. #ifdef EXT_BEARER_CAPS
  903. static u_char *
  904. EncodeASyncParams(u_char *p, u_char si2)
  905. { // 7c 06 88 90 21 42 00 bb
  906. p[0] = 0;
  907. p[1] = 0x40; // Intermediate rate: 16 kbit/s jj 2000.02.19
  908. p[2] = 0x80;
  909. if (si2 & 32) // 7 data bits
  910. p[2] += 16;
  911. else // 8 data bits
  912. p[2] += 24;
  913. if (si2 & 16) // 2 stop bits
  914. p[2] += 96;
  915. else // 1 stop bit
  916. p[2] += 32;
  917. if (si2 & 8) // even parity
  918. p[2] += 2;
  919. else // no parity
  920. p[2] += 3;
  921. switch (si2 & 0x07) {
  922. case 0:
  923. p[0] = 66; // 1200 bit/s
  924. break;
  925. case 1:
  926. p[0] = 88; // 1200/75 bit/s
  927. break;
  928. case 2:
  929. p[0] = 87; // 75/1200 bit/s
  930. break;
  931. case 3:
  932. p[0] = 67; // 2400 bit/s
  933. break;
  934. case 4:
  935. p[0] = 69; // 4800 bit/s
  936. break;
  937. case 5:
  938. p[0] = 72; // 9600 bit/s
  939. break;
  940. case 6:
  941. p[0] = 73; // 14400 bit/s
  942. break;
  943. case 7:
  944. p[0] = 75; // 19200 bit/s
  945. break;
  946. }
  947. return p + 3;
  948. }
  949. static u_char
  950. EncodeSyncParams(u_char si2, u_char ai)
  951. {
  952. switch (si2) {
  953. case 0:
  954. return ai + 2; // 1200 bit/s
  955. case 1:
  956. return ai + 24; // 1200/75 bit/s
  957. case 2:
  958. return ai + 23; // 75/1200 bit/s
  959. case 3:
  960. return ai + 3; // 2400 bit/s
  961. case 4:
  962. return ai + 5; // 4800 bit/s
  963. case 5:
  964. return ai + 8; // 9600 bit/s
  965. case 6:
  966. return ai + 9; // 14400 bit/s
  967. case 7:
  968. return ai + 11; // 19200 bit/s
  969. case 8:
  970. return ai + 14; // 48000 bit/s
  971. case 9:
  972. return ai + 15; // 56000 bit/s
  973. case 15:
  974. return ai + 40; // negotiate bit/s
  975. default:
  976. break;
  977. }
  978. return ai;
  979. }
  980. static u_char
  981. DecodeASyncParams(u_char si2, u_char *p)
  982. {
  983. u_char info;
  984. switch (p[5]) {
  985. case 66: // 1200 bit/s
  986. break; // si2 don't change
  987. case 88: // 1200/75 bit/s
  988. si2 += 1;
  989. break;
  990. case 87: // 75/1200 bit/s
  991. si2 += 2;
  992. break;
  993. case 67: // 2400 bit/s
  994. si2 += 3;
  995. break;
  996. case 69: // 4800 bit/s
  997. si2 += 4;
  998. break;
  999. case 72: // 9600 bit/s
  1000. si2 += 5;
  1001. break;
  1002. case 73: // 14400 bit/s
  1003. si2 += 6;
  1004. break;
  1005. case 75: // 19200 bit/s
  1006. si2 += 7;
  1007. break;
  1008. }
  1009. info = p[7] & 0x7f;
  1010. if ((info & 16) && (!(info & 8))) // 7 data bits
  1011. si2 += 32; // else 8 data bits
  1012. if ((info & 96) == 96) // 2 stop bits
  1013. si2 += 16; // else 1 stop bit
  1014. if ((info & 2) && (!(info & 1))) // even parity
  1015. si2 += 8; // else no parity
  1016. return si2;
  1017. }
  1018. static u_char
  1019. DecodeSyncParams(u_char si2, u_char info)
  1020. {
  1021. info &= 0x7f;
  1022. switch (info) {
  1023. case 40: // bit/s negotiation failed ai := 165 not 175!
  1024. return si2 + 15;
  1025. case 15: // 56000 bit/s failed, ai := 0 not 169 !
  1026. return si2 + 9;
  1027. case 14: // 48000 bit/s
  1028. return si2 + 8;
  1029. case 11: // 19200 bit/s
  1030. return si2 + 7;
  1031. case 9: // 14400 bit/s
  1032. return si2 + 6;
  1033. case 8: // 9600 bit/s
  1034. return si2 + 5;
  1035. case 5: // 4800 bit/s
  1036. return si2 + 4;
  1037. case 3: // 2400 bit/s
  1038. return si2 + 3;
  1039. case 23: // 75/1200 bit/s
  1040. return si2 + 2;
  1041. case 24: // 1200/75 bit/s
  1042. return si2 + 1;
  1043. default: // 1200 bit/s
  1044. return si2;
  1045. }
  1046. }
  1047. static u_char
  1048. DecodeSI2(struct sk_buff *skb)
  1049. {
  1050. u_char *p; //, *pend=skb->data + skb->len;
  1051. if ((p = findie(skb->data, skb->len, 0x7c, 0))) {
  1052. switch (p[4] & 0x0f) {
  1053. case 0x01:
  1054. if (p[1] == 0x04) // sync. Bitratenadaption
  1055. return DecodeSyncParams(160, p[5]); // V.110/X.30
  1056. else if (p[1] == 0x06) // async. Bitratenadaption
  1057. return DecodeASyncParams(192, p); // V.110/X.30
  1058. break;
  1059. case 0x08: // if (p[5] == 0x02) // sync. Bitratenadaption
  1060. if (p[1] > 3)
  1061. return DecodeSyncParams(176, p[5]); // V.120
  1062. break;
  1063. }
  1064. }
  1065. return 0;
  1066. }
  1067. #endif
  1068. static void
  1069. l3dss1_setup_req(struct l3_process *pc, u_char pr,
  1070. void *arg)
  1071. {
  1072. struct sk_buff *skb;
  1073. u_char tmp[128];
  1074. u_char *p = tmp;
  1075. u_char channel = 0;
  1076. u_char send_keypad;
  1077. u_char screen = 0x80;
  1078. u_char *teln;
  1079. u_char *msn;
  1080. u_char *sub;
  1081. u_char *sp;
  1082. int l;
  1083. MsgHead(p, pc->callref, MT_SETUP);
  1084. teln = pc->para.setup.phone;
  1085. #ifndef CONFIG_HISAX_NO_KEYPAD
  1086. send_keypad = (strchr(teln, '*') || strchr(teln, '#')) ? 1 : 0;
  1087. #else
  1088. send_keypad = 0;
  1089. #endif
  1090. #ifndef CONFIG_HISAX_NO_SENDCOMPLETE
  1091. if (!send_keypad)
  1092. *p++ = 0xa1; /* complete indicator */
  1093. #endif
  1094. /*
  1095. * Set Bearer Capability, Map info from 1TR6-convention to EDSS1
  1096. */
  1097. switch (pc->para.setup.si1) {
  1098. case 1: /* Telephony */
  1099. *p++ = IE_BEARER;
  1100. *p++ = 0x3; /* Length */
  1101. *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
  1102. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1103. *p++ = 0xa3; /* A-Law Audio */
  1104. break;
  1105. case 5: /* Datatransmission 64k, BTX */
  1106. case 7: /* Datatransmission 64k */
  1107. default:
  1108. *p++ = IE_BEARER;
  1109. *p++ = 0x2; /* Length */
  1110. *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
  1111. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1112. break;
  1113. }
  1114. if (send_keypad) {
  1115. *p++ = IE_KEYPAD;
  1116. *p++ = strlen(teln);
  1117. while (*teln)
  1118. *p++ = (*teln++) & 0x7F;
  1119. }
  1120. /*
  1121. * What about info2? Mapping to High-Layer-Compatibility?
  1122. */
  1123. if ((*teln) && (!send_keypad)) {
  1124. /* parse number for special things */
  1125. if (!isdigit(*teln)) {
  1126. switch (0x5f & *teln) {
  1127. case 'C':
  1128. channel = 0x08;
  1129. case 'P':
  1130. channel |= 0x80;
  1131. teln++;
  1132. if (*teln == '1')
  1133. channel |= 0x01;
  1134. else
  1135. channel |= 0x02;
  1136. break;
  1137. case 'R':
  1138. screen = 0xA0;
  1139. break;
  1140. case 'D':
  1141. screen = 0x80;
  1142. break;
  1143. default:
  1144. if (pc->debug & L3_DEB_WARN)
  1145. l3_debug(pc->st, "Wrong MSN Code");
  1146. break;
  1147. }
  1148. teln++;
  1149. }
  1150. }
  1151. if (channel) {
  1152. *p++ = IE_CHANNEL_ID;
  1153. *p++ = 1;
  1154. *p++ = channel;
  1155. }
  1156. msn = pc->para.setup.eazmsn;
  1157. sub = NULL;
  1158. sp = msn;
  1159. while (*sp) {
  1160. if ('.' == *sp) {
  1161. sub = sp;
  1162. *sp = 0;
  1163. } else
  1164. sp++;
  1165. }
  1166. if (*msn) {
  1167. *p++ = IE_CALLING_PN;
  1168. *p++ = strlen(msn) + (screen ? 2 : 1);
  1169. /* Classify as AnyPref. */
  1170. if (screen) {
  1171. *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
  1172. *p++ = screen;
  1173. } else
  1174. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1175. while (*msn)
  1176. *p++ = *msn++ & 0x7f;
  1177. }
  1178. if (sub) {
  1179. *sub++ = '.';
  1180. *p++ = IE_CALLING_SUB;
  1181. *p++ = strlen(sub) + 2;
  1182. *p++ = 0x80; /* NSAP coded */
  1183. *p++ = 0x50; /* local IDI format */
  1184. while (*sub)
  1185. *p++ = *sub++ & 0x7f;
  1186. }
  1187. sub = NULL;
  1188. sp = teln;
  1189. while (*sp) {
  1190. if ('.' == *sp) {
  1191. sub = sp;
  1192. *sp = 0;
  1193. } else
  1194. sp++;
  1195. }
  1196. if (!send_keypad) {
  1197. *p++ = IE_CALLED_PN;
  1198. *p++ = strlen(teln) + 1;
  1199. /* Classify as AnyPref. */
  1200. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1201. while (*teln)
  1202. *p++ = *teln++ & 0x7f;
  1203. if (sub) {
  1204. *sub++ = '.';
  1205. *p++ = IE_CALLED_SUB;
  1206. *p++ = strlen(sub) + 2;
  1207. *p++ = 0x80; /* NSAP coded */
  1208. *p++ = 0x50; /* local IDI format */
  1209. while (*sub)
  1210. *p++ = *sub++ & 0x7f;
  1211. }
  1212. }
  1213. #ifdef EXT_BEARER_CAPS
  1214. if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
  1215. *p++ = IE_LLC;
  1216. *p++ = 0x04;
  1217. *p++ = 0x88;
  1218. *p++ = 0x90;
  1219. *p++ = 0x21;
  1220. *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
  1221. } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
  1222. *p++ = IE_LLC;
  1223. *p++ = 0x05;
  1224. *p++ = 0x88;
  1225. *p++ = 0x90;
  1226. *p++ = 0x28;
  1227. *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
  1228. *p++ = 0x82;
  1229. } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
  1230. *p++ = IE_LLC;
  1231. *p++ = 0x06;
  1232. *p++ = 0x88;
  1233. *p++ = 0x90;
  1234. *p++ = 0x21;
  1235. p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
  1236. #ifndef CONFIG_HISAX_NO_LLC
  1237. } else {
  1238. switch (pc->para.setup.si1) {
  1239. case 1: /* Telephony */
  1240. *p++ = IE_LLC;
  1241. *p++ = 0x3; /* Length */
  1242. *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
  1243. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1244. *p++ = 0xa3; /* A-Law Audio */
  1245. break;
  1246. case 5: /* Datatransmission 64k, BTX */
  1247. case 7: /* Datatransmission 64k */
  1248. default:
  1249. *p++ = IE_LLC;
  1250. *p++ = 0x2; /* Length */
  1251. *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
  1252. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1253. break;
  1254. }
  1255. #endif
  1256. }
  1257. #endif
  1258. l = p - tmp;
  1259. if (!(skb = l3_alloc_skb(l)))
  1260. return;
  1261. memcpy(skb_put(skb, l), tmp, l);
  1262. L3DelTimer(&pc->timer);
  1263. L3AddTimer(&pc->timer, T303, CC_T303);
  1264. newl3state(pc, 1);
  1265. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1266. }
  1267. static void
  1268. l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg)
  1269. {
  1270. struct sk_buff *skb = arg;
  1271. int id, ret;
  1272. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1273. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1274. if (pc->debug & L3_DEB_WARN)
  1275. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1276. pc->para.cause = 100;
  1277. l3dss1_status_send(pc, pr, NULL);
  1278. return;
  1279. }
  1280. pc->para.bchannel = id;
  1281. } else if (1 == pc->state) {
  1282. if (pc->debug & L3_DEB_WARN)
  1283. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1284. if (id == -1)
  1285. pc->para.cause = 96;
  1286. else
  1287. pc->para.cause = 100;
  1288. l3dss1_status_send(pc, pr, NULL);
  1289. return;
  1290. }
  1291. /* Now we are on none mandatory IEs */
  1292. ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
  1293. if (ERR_IE_COMPREHENSION == ret) {
  1294. l3dss1_std_ie_err(pc, ret);
  1295. return;
  1296. }
  1297. L3DelTimer(&pc->timer);
  1298. newl3state(pc, 3);
  1299. L3AddTimer(&pc->timer, T310, CC_T310);
  1300. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1301. l3dss1_std_ie_err(pc, ret);
  1302. pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
  1303. }
  1304. static void
  1305. l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
  1306. {
  1307. struct sk_buff *skb = arg;
  1308. int id, ret;
  1309. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1310. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1311. if (pc->debug & L3_DEB_WARN)
  1312. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1313. pc->para.cause = 100;
  1314. l3dss1_status_send(pc, pr, NULL);
  1315. return;
  1316. }
  1317. pc->para.bchannel = id;
  1318. } else {
  1319. if (pc->debug & L3_DEB_WARN)
  1320. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1321. if (id == -1)
  1322. pc->para.cause = 96;
  1323. else
  1324. pc->para.cause = 100;
  1325. l3dss1_status_send(pc, pr, NULL);
  1326. return;
  1327. }
  1328. /* Now we are on none mandatory IEs */
  1329. ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
  1330. if (ERR_IE_COMPREHENSION == ret) {
  1331. l3dss1_std_ie_err(pc, ret);
  1332. return;
  1333. }
  1334. L3DelTimer(&pc->timer);
  1335. newl3state(pc, 2);
  1336. L3AddTimer(&pc->timer, T304, CC_T304);
  1337. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1338. l3dss1_std_ie_err(pc, ret);
  1339. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1340. }
  1341. static void
  1342. l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg)
  1343. {
  1344. struct sk_buff *skb = arg;
  1345. u_char *p;
  1346. int ret;
  1347. u_char cause = 0;
  1348. StopAllL3Timer(pc);
  1349. if ((ret = l3dss1_get_cause(pc, skb))) {
  1350. if (pc->debug & L3_DEB_WARN)
  1351. l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
  1352. if (ret < 0)
  1353. cause = 96;
  1354. else if (ret > 0)
  1355. cause = 100;
  1356. }
  1357. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  1358. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1359. ret = check_infoelements(pc, skb, ie_DISCONNECT);
  1360. if (ERR_IE_COMPREHENSION == ret)
  1361. cause = 96;
  1362. else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
  1363. cause = 99;
  1364. ret = pc->state;
  1365. newl3state(pc, 12);
  1366. if (cause)
  1367. newl3state(pc, 19);
  1368. if (11 != ret)
  1369. pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
  1370. else if (!cause)
  1371. l3dss1_release_req(pc, pr, NULL);
  1372. if (cause) {
  1373. l3dss1_message_cause(pc, MT_RELEASE, cause);
  1374. L3AddTimer(&pc->timer, T308, CC_T308_1);
  1375. }
  1376. }
  1377. static void
  1378. l3dss1_connect(struct l3_process *pc, u_char pr, void *arg)
  1379. {
  1380. struct sk_buff *skb = arg;
  1381. int ret;
  1382. ret = check_infoelements(pc, skb, ie_CONNECT);
  1383. if (ERR_IE_COMPREHENSION == ret) {
  1384. l3dss1_std_ie_err(pc, ret);
  1385. return;
  1386. }
  1387. L3DelTimer(&pc->timer); /* T310 */
  1388. newl3state(pc, 10);
  1389. pc->para.chargeinfo = 0;
  1390. /* here should inserted COLP handling KKe */
  1391. if (ret)
  1392. l3dss1_std_ie_err(pc, ret);
  1393. pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
  1394. }
  1395. static void
  1396. l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg)
  1397. {
  1398. struct sk_buff *skb = arg;
  1399. int ret;
  1400. ret = check_infoelements(pc, skb, ie_ALERTING);
  1401. if (ERR_IE_COMPREHENSION == ret) {
  1402. l3dss1_std_ie_err(pc, ret);
  1403. return;
  1404. }
  1405. L3DelTimer(&pc->timer); /* T304 */
  1406. newl3state(pc, 4);
  1407. if (ret)
  1408. l3dss1_std_ie_err(pc, ret);
  1409. pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
  1410. }
  1411. static void
  1412. l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
  1413. {
  1414. u_char *p;
  1415. int bcfound = 0;
  1416. char tmp[80];
  1417. struct sk_buff *skb = arg;
  1418. int id;
  1419. int err = 0;
  1420. /*
  1421. * Bearer Capabilities
  1422. */
  1423. p = skb->data;
  1424. /* only the first occurrence 'll be detected ! */
  1425. if ((p = findie(p, skb->len, 0x04, 0))) {
  1426. if ((p[1] < 2) || (p[1] > 11))
  1427. err = 1;
  1428. else {
  1429. pc->para.setup.si2 = 0;
  1430. switch (p[2] & 0x7f) {
  1431. case 0x00: /* Speech */
  1432. case 0x10: /* 3.1 Khz audio */
  1433. pc->para.setup.si1 = 1;
  1434. break;
  1435. case 0x08: /* Unrestricted digital information */
  1436. pc->para.setup.si1 = 7;
  1437. /* JIM, 05.11.97 I wanna set service indicator 2 */
  1438. #ifdef EXT_BEARER_CAPS
  1439. pc->para.setup.si2 = DecodeSI2(skb);
  1440. #endif
  1441. break;
  1442. case 0x09: /* Restricted digital information */
  1443. pc->para.setup.si1 = 2;
  1444. break;
  1445. case 0x11:
  1446. /* Unrestr. digital information with
  1447. * tones/announcements ( or 7 kHz audio
  1448. */
  1449. pc->para.setup.si1 = 3;
  1450. break;
  1451. case 0x18: /* Video */
  1452. pc->para.setup.si1 = 4;
  1453. break;
  1454. default:
  1455. err = 2;
  1456. break;
  1457. }
  1458. switch (p[3] & 0x7f) {
  1459. case 0x40: /* packed mode */
  1460. pc->para.setup.si1 = 8;
  1461. break;
  1462. case 0x10: /* 64 kbit */
  1463. case 0x11: /* 2*64 kbit */
  1464. case 0x13: /* 384 kbit */
  1465. case 0x15: /* 1536 kbit */
  1466. case 0x17: /* 1920 kbit */
  1467. pc->para.moderate = p[3] & 0x7f;
  1468. break;
  1469. default:
  1470. err = 3;
  1471. break;
  1472. }
  1473. }
  1474. if (pc->debug & L3_DEB_SI)
  1475. l3_debug(pc->st, "SI=%d, AI=%d",
  1476. pc->para.setup.si1, pc->para.setup.si2);
  1477. if (err) {
  1478. if (pc->debug & L3_DEB_WARN)
  1479. l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
  1480. p[1], p[2], p[3]);
  1481. pc->para.cause = 100;
  1482. l3dss1_msg_without_setup(pc, pr, NULL);
  1483. return;
  1484. }
  1485. } else {
  1486. if (pc->debug & L3_DEB_WARN)
  1487. l3_debug(pc->st, "setup without bearer capabilities");
  1488. /* ETS 300-104 1.3.3 */
  1489. pc->para.cause = 96;
  1490. l3dss1_msg_without_setup(pc, pr, NULL);
  1491. return;
  1492. }
  1493. /*
  1494. * Channel Identification
  1495. */
  1496. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1497. if ((pc->para.bchannel = id)) {
  1498. if ((3 == id) && (0x10 == pc->para.moderate)) {
  1499. if (pc->debug & L3_DEB_WARN)
  1500. l3_debug(pc->st, "setup with wrong chid %x",
  1501. id);
  1502. pc->para.cause = 100;
  1503. l3dss1_msg_without_setup(pc, pr, NULL);
  1504. return;
  1505. }
  1506. bcfound++;
  1507. } else
  1508. { if (pc->debug & L3_DEB_WARN)
  1509. l3_debug(pc->st, "setup without bchannel, call waiting");
  1510. bcfound++;
  1511. }
  1512. } else {
  1513. if (pc->debug & L3_DEB_WARN)
  1514. l3_debug(pc->st, "setup with wrong chid ret %d", id);
  1515. if (id == -1)
  1516. pc->para.cause = 96;
  1517. else
  1518. pc->para.cause = 100;
  1519. l3dss1_msg_without_setup(pc, pr, NULL);
  1520. return;
  1521. }
  1522. /* Now we are on none mandatory IEs */
  1523. err = check_infoelements(pc, skb, ie_SETUP);
  1524. if (ERR_IE_COMPREHENSION == err) {
  1525. pc->para.cause = 96;
  1526. l3dss1_msg_without_setup(pc, pr, NULL);
  1527. return;
  1528. }
  1529. p = skb->data;
  1530. if ((p = findie(p, skb->len, 0x70, 0)))
  1531. iecpy(pc->para.setup.eazmsn, p, 1);
  1532. else
  1533. pc->para.setup.eazmsn[0] = 0;
  1534. p = skb->data;
  1535. if ((p = findie(p, skb->len, 0x71, 0))) {
  1536. /* Called party subaddress */
  1537. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1538. tmp[0] = '.';
  1539. iecpy(&tmp[1], p, 2);
  1540. strcat(pc->para.setup.eazmsn, tmp);
  1541. } else if (pc->debug & L3_DEB_WARN)
  1542. l3_debug(pc->st, "wrong called subaddress");
  1543. }
  1544. p = skb->data;
  1545. if ((p = findie(p, skb->len, 0x6c, 0))) {
  1546. pc->para.setup.plan = p[2];
  1547. if (p[2] & 0x80) {
  1548. iecpy(pc->para.setup.phone, p, 1);
  1549. pc->para.setup.screen = 0;
  1550. } else {
  1551. iecpy(pc->para.setup.phone, p, 2);
  1552. pc->para.setup.screen = p[3];
  1553. }
  1554. } else {
  1555. pc->para.setup.phone[0] = 0;
  1556. pc->para.setup.plan = 0;
  1557. pc->para.setup.screen = 0;
  1558. }
  1559. p = skb->data;
  1560. if ((p = findie(p, skb->len, 0x6d, 0))) {
  1561. /* Calling party subaddress */
  1562. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1563. tmp[0] = '.';
  1564. iecpy(&tmp[1], p, 2);
  1565. strcat(pc->para.setup.phone, tmp);
  1566. } else if (pc->debug & L3_DEB_WARN)
  1567. l3_debug(pc->st, "wrong calling subaddress");
  1568. }
  1569. newl3state(pc, 6);
  1570. if (err) /* STATUS for none mandatory IE errors after actions are taken */
  1571. l3dss1_std_ie_err(pc, err);
  1572. pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
  1573. }
  1574. static void
  1575. l3dss1_reset(struct l3_process *pc, u_char pr, void *arg)
  1576. {
  1577. dss1_release_l3_process(pc);
  1578. }
  1579. static void
  1580. l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
  1581. {
  1582. struct sk_buff *skb;
  1583. u_char tmp[16 + 40];
  1584. u_char *p = tmp;
  1585. int l;
  1586. u_char cause = 16;
  1587. if (pc->para.cause != NO_CAUSE)
  1588. cause = pc->para.cause;
  1589. StopAllL3Timer(pc);
  1590. MsgHead(p, pc->callref, MT_DISCONNECT);
  1591. *p++ = IE_CAUSE;
  1592. *p++ = 0x2;
  1593. *p++ = 0x80;
  1594. *p++ = cause | 0x80;
  1595. if (pc->prot.dss1.uus1_data[0])
  1596. { *p++ = IE_USER_USER; /* UUS info element */
  1597. *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
  1598. *p++ = 0x04; /* IA5 chars */
  1599. strcpy(p, pc->prot.dss1.uus1_data);
  1600. p += strlen(pc->prot.dss1.uus1_data);
  1601. pc->prot.dss1.uus1_data[0] = '\0';
  1602. }
  1603. l = p - tmp;
  1604. if (!(skb = l3_alloc_skb(l)))
  1605. return;
  1606. memcpy(skb_put(skb, l), tmp, l);
  1607. newl3state(pc, 11);
  1608. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1609. L3AddTimer(&pc->timer, T305, CC_T305);
  1610. }
  1611. static void
  1612. l3dss1_setup_rsp(struct l3_process *pc, u_char pr,
  1613. void *arg)
  1614. {
  1615. if (!pc->para.bchannel)
  1616. { if (pc->debug & L3_DEB_WARN)
  1617. l3_debug(pc->st, "D-chan connect for waiting call");
  1618. l3dss1_disconnect_req(pc, pr, arg);
  1619. return;
  1620. }
  1621. newl3state(pc, 8);
  1622. l3dss1_message(pc, MT_CONNECT);
  1623. L3DelTimer(&pc->timer);
  1624. L3AddTimer(&pc->timer, T313, CC_T313);
  1625. }
  1626. static void
  1627. l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
  1628. {
  1629. struct sk_buff *skb = arg;
  1630. int ret;
  1631. ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
  1632. if (ERR_IE_COMPREHENSION == ret) {
  1633. l3dss1_std_ie_err(pc, ret);
  1634. return;
  1635. }
  1636. newl3state(pc, 10);
  1637. L3DelTimer(&pc->timer);
  1638. if (ret)
  1639. l3dss1_std_ie_err(pc, ret);
  1640. pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
  1641. }
  1642. static void
  1643. l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg)
  1644. {
  1645. struct sk_buff *skb;
  1646. u_char tmp[16];
  1647. u_char *p = tmp;
  1648. int l;
  1649. u_char cause = 21;
  1650. if (pc->para.cause != NO_CAUSE)
  1651. cause = pc->para.cause;
  1652. MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
  1653. *p++ = IE_CAUSE;
  1654. *p++ = 0x2;
  1655. *p++ = 0x80;
  1656. *p++ = cause | 0x80;
  1657. l = p - tmp;
  1658. if (!(skb = l3_alloc_skb(l)))
  1659. return;
  1660. memcpy(skb_put(skb, l), tmp, l);
  1661. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1662. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1663. newl3state(pc, 0);
  1664. dss1_release_l3_process(pc);
  1665. }
  1666. static void
  1667. l3dss1_release(struct l3_process *pc, u_char pr, void *arg)
  1668. {
  1669. struct sk_buff *skb = arg;
  1670. u_char *p;
  1671. int ret, cause = 0;
  1672. StopAllL3Timer(pc);
  1673. if ((ret = l3dss1_get_cause(pc, skb)) > 0) {
  1674. if (pc->debug & L3_DEB_WARN)
  1675. l3_debug(pc->st, "REL get_cause ret(%d)", ret);
  1676. } else if (ret < 0)
  1677. pc->para.cause = NO_CAUSE;
  1678. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  1679. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1680. }
  1681. if ((ret < 0) && (pc->state != 11))
  1682. cause = 96;
  1683. else if (ret > 0)
  1684. cause = 100;
  1685. ret = check_infoelements(pc, skb, ie_RELEASE);
  1686. if (ERR_IE_COMPREHENSION == ret)
  1687. cause = 96;
  1688. else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
  1689. cause = 99;
  1690. if (cause)
  1691. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
  1692. else
  1693. l3dss1_message(pc, MT_RELEASE_COMPLETE);
  1694. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1695. newl3state(pc, 0);
  1696. dss1_release_l3_process(pc);
  1697. }
  1698. static void
  1699. l3dss1_alert_req(struct l3_process *pc, u_char pr,
  1700. void *arg)
  1701. {
  1702. newl3state(pc, 7);
  1703. if (!pc->prot.dss1.uus1_data[0])
  1704. l3dss1_message(pc, MT_ALERTING);
  1705. else
  1706. l3dss1_msg_with_uus(pc, MT_ALERTING);
  1707. }
  1708. static void
  1709. l3dss1_proceed_req(struct l3_process *pc, u_char pr,
  1710. void *arg)
  1711. {
  1712. newl3state(pc, 9);
  1713. l3dss1_message(pc, MT_CALL_PROCEEDING);
  1714. pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
  1715. }
  1716. static void
  1717. l3dss1_setup_ack_req(struct l3_process *pc, u_char pr,
  1718. void *arg)
  1719. {
  1720. newl3state(pc, 25);
  1721. L3DelTimer(&pc->timer);
  1722. L3AddTimer(&pc->timer, T302, CC_T302);
  1723. l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
  1724. }
  1725. /********************************************/
  1726. /* deliver a incoming display message to HL */
  1727. /********************************************/
  1728. static void
  1729. l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
  1730. { u_char len;
  1731. isdn_ctrl ic;
  1732. struct IsdnCardState *cs;
  1733. char *p;
  1734. if (*infp++ != IE_DISPLAY) return;
  1735. if ((len = *infp++) > 80) return; /* total length <= 82 */
  1736. if (!pc->chan) return;
  1737. p = ic.parm.display;
  1738. while (len--)
  1739. *p++ = *infp++;
  1740. *p = '\0';
  1741. ic.command = ISDN_STAT_DISPLAY;
  1742. cs = pc->st->l1.hardware;
  1743. ic.driver = cs->myid;
  1744. ic.arg = pc->chan->chan;
  1745. cs->iif.statcallb(&ic);
  1746. } /* l3dss1_deliver_display */
  1747. static void
  1748. l3dss1_progress(struct l3_process *pc, u_char pr, void *arg)
  1749. {
  1750. struct sk_buff *skb = arg;
  1751. int err = 0;
  1752. u_char *p;
  1753. if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
  1754. if (p[1] != 2) {
  1755. err = 1;
  1756. pc->para.cause = 100;
  1757. } else if (!(p[2] & 0x70)) {
  1758. switch (p[2]) {
  1759. case 0x80:
  1760. case 0x81:
  1761. case 0x82:
  1762. case 0x84:
  1763. case 0x85:
  1764. case 0x87:
  1765. case 0x8a:
  1766. switch (p[3]) {
  1767. case 0x81:
  1768. case 0x82:
  1769. case 0x83:
  1770. case 0x84:
  1771. case 0x88:
  1772. break;
  1773. default:
  1774. err = 2;
  1775. pc->para.cause = 100;
  1776. break;
  1777. }
  1778. break;
  1779. default:
  1780. err = 3;
  1781. pc->para.cause = 100;
  1782. break;
  1783. }
  1784. }
  1785. } else {
  1786. pc->para.cause = 96;
  1787. err = 4;
  1788. }
  1789. if (err) {
  1790. if (pc->debug & L3_DEB_WARN)
  1791. l3_debug(pc->st, "progress error %d", err);
  1792. l3dss1_status_send(pc, pr, NULL);
  1793. return;
  1794. }
  1795. /* Now we are on none mandatory IEs */
  1796. err = check_infoelements(pc, skb, ie_PROGRESS);
  1797. if (err)
  1798. l3dss1_std_ie_err(pc, err);
  1799. if (ERR_IE_COMPREHENSION != err)
  1800. pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
  1801. }
  1802. static void
  1803. l3dss1_notify(struct l3_process *pc, u_char pr, void *arg)
  1804. {
  1805. struct sk_buff *skb = arg;
  1806. int err = 0;
  1807. u_char *p;
  1808. if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
  1809. if (p[1] != 1) {
  1810. err = 1;
  1811. pc->para.cause = 100;
  1812. } else {
  1813. switch (p[2]) {
  1814. case 0x80:
  1815. case 0x81:
  1816. case 0x82:
  1817. break;
  1818. default:
  1819. pc->para.cause = 100;
  1820. err = 2;
  1821. break;
  1822. }
  1823. }
  1824. } else {
  1825. pc->para.cause = 96;
  1826. err = 3;
  1827. }
  1828. if (err) {
  1829. if (pc->debug & L3_DEB_WARN)
  1830. l3_debug(pc->st, "notify error %d", err);
  1831. l3dss1_status_send(pc, pr, NULL);
  1832. return;
  1833. }
  1834. /* Now we are on none mandatory IEs */
  1835. err = check_infoelements(pc, skb, ie_NOTIFY);
  1836. if (err)
  1837. l3dss1_std_ie_err(pc, err);
  1838. if (ERR_IE_COMPREHENSION != err)
  1839. pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
  1840. }
  1841. static void
  1842. l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg)
  1843. {
  1844. int ret;
  1845. struct sk_buff *skb = arg;
  1846. ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
  1847. l3dss1_std_ie_err(pc, ret);
  1848. pc->para.cause = 30; /* response to STATUS_ENQUIRY */
  1849. l3dss1_status_send(pc, pr, NULL);
  1850. }
  1851. static void
  1852. l3dss1_information(struct l3_process *pc, u_char pr, void *arg)
  1853. {
  1854. int ret;
  1855. struct sk_buff *skb = arg;
  1856. u_char *p;
  1857. char tmp[32];
  1858. ret = check_infoelements(pc, skb, ie_INFORMATION);
  1859. if (ret)
  1860. l3dss1_std_ie_err(pc, ret);
  1861. if (pc->state == 25) { /* overlap receiving */
  1862. L3DelTimer(&pc->timer);
  1863. p = skb->data;
  1864. if ((p = findie(p, skb->len, 0x70, 0))) {
  1865. iecpy(tmp, p, 1);
  1866. strcat(pc->para.setup.eazmsn, tmp);
  1867. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1868. }
  1869. L3AddTimer(&pc->timer, T302, CC_T302);
  1870. }
  1871. }
  1872. /******************************/
  1873. /* handle deflection requests */
  1874. /******************************/
  1875. static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg)
  1876. {
  1877. struct sk_buff *skb;
  1878. u_char tmp[128];
  1879. u_char *p = tmp;
  1880. u_char *subp;
  1881. u_char len_phone = 0;
  1882. u_char len_sub = 0;
  1883. int l;
  1884. strcpy(pc->prot.dss1.uus1_data, pc->chan->setup.eazmsn); /* copy uus element if available */
  1885. if (!pc->chan->setup.phone[0])
  1886. { pc->para.cause = -1;
  1887. l3dss1_disconnect_req(pc, pr, arg); /* disconnect immediately */
  1888. return;
  1889. } /* only uus */
  1890. if (pc->prot.dss1.invoke_id)
  1891. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  1892. if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
  1893. return;
  1894. MsgHead(p, pc->callref, MT_FACILITY);
  1895. for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
  1896. if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
  1897. *p++ = 0x1c; /* Facility info element */
  1898. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
  1899. *p++ = 0x91; /* remote operations protocol */
  1900. *p++ = 0xa1; /* invoke component */
  1901. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
  1902. *p++ = 0x02; /* invoke id tag, integer */
  1903. *p++ = 0x01; /* length */
  1904. *p++ = pc->prot.dss1.invoke_id; /* invoke id */
  1905. *p++ = 0x02; /* operation value tag, integer */
  1906. *p++ = 0x01; /* length */
  1907. *p++ = 0x0D; /* Call Deflect */
  1908. *p++ = 0x30; /* sequence phone number */
  1909. *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
  1910. *p++ = 0x30; /* Deflected to UserNumber */
  1911. *p++ = len_phone + 2 + len_sub; /* length */
  1912. *p++ = 0x80; /* NumberDigits */
  1913. *p++ = len_phone; /* length */
  1914. for (l = 0; l < len_phone; l++)
  1915. *p++ = pc->chan->setup.phone[l];
  1916. if (len_sub)
  1917. { *p++ = 0x04; /* called party subaddress */
  1918. *p++ = len_sub - 2;
  1919. while (*subp) *p++ = *subp++;
  1920. }
  1921. *p++ = 0x01; /* screening identifier */
  1922. *p++ = 0x01;
  1923. *p++ = pc->chan->setup.screen;
  1924. l = p - tmp;
  1925. if (!(skb = l3_alloc_skb(l))) return;
  1926. memcpy(skb_put(skb, l), tmp, l);
  1927. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1928. } /* l3dss1_redir_req */
  1929. /********************************************/
  1930. /* handle deflection request in early state */
  1931. /********************************************/
  1932. static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
  1933. {
  1934. l3dss1_proceed_req(pc, pr, arg);
  1935. l3dss1_redir_req(pc, pr, arg);
  1936. } /* l3dss1_redir_req_early */
  1937. /***********************************************/
  1938. /* handle special commands for this protocol. */
  1939. /* Examples are call independent services like */
  1940. /* remote operations with dummy callref. */
  1941. /***********************************************/
  1942. static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
  1943. { u_char id;
  1944. u_char temp[265];
  1945. u_char *p = temp;
  1946. int i, l, proc_len;
  1947. struct sk_buff *skb;
  1948. struct l3_process *pc = NULL;
  1949. switch (ic->arg)
  1950. { case DSS1_CMD_INVOKE:
  1951. if (ic->parm.dss1_io.datalen < 0) return (-2); /* invalid parameter */
  1952. for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
  1953. i = i >> 8; /* add one byte */
  1954. l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
  1955. if (l > 255)
  1956. return (-2); /* too long */
  1957. if (!(id = new_invoke_id(st)))
  1958. return (0); /* first get a invoke id -> return if no available */
  1959. i = -1;
  1960. MsgHead(p, i, MT_FACILITY); /* build message head */
  1961. *p++ = 0x1C; /* Facility IE */
  1962. *p++ = l; /* length of ie */
  1963. *p++ = 0x91; /* remote operations */
  1964. *p++ = 0xA1; /* invoke */
  1965. *p++ = l - 3; /* length of invoke */
  1966. *p++ = 0x02; /* invoke id tag */
  1967. *p++ = 0x01; /* length is 1 */
  1968. *p++ = id; /* invoke id */
  1969. *p++ = 0x02; /* operation */
  1970. *p++ = proc_len; /* length of operation */
  1971. for (i = proc_len; i; i--)
  1972. *p++ = (ic->parm.dss1_io.proc >> (i - 1)) & 0xFF;
  1973. memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
  1974. l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
  1975. if (ic->parm.dss1_io.timeout > 0)
  1976. if (!(pc = dss1_new_l3_process(st, -1)))
  1977. { free_invoke_id(st, id);
  1978. return (-2);
  1979. }
  1980. pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
  1981. pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
  1982. if (!(skb = l3_alloc_skb(l)))
  1983. { free_invoke_id(st, id);
  1984. if (pc) dss1_release_l3_process(pc);
  1985. return (-2);
  1986. }
  1987. memcpy(skb_put(skb, l), temp, l);
  1988. if (pc)
  1989. { pc->prot.dss1.invoke_id = id; /* remember id */
  1990. L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
  1991. }
  1992. l3_msg(st, DL_DATA | REQUEST, skb);
  1993. ic->parm.dss1_io.hl_id = id; /* return id */
  1994. return (0);
  1995. case DSS1_CMD_INVOKE_ABORT:
  1996. if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
  1997. { L3DelTimer(&pc->timer); /* remove timer */
  1998. dss1_release_l3_process(pc);
  1999. return (0);
  2000. }
  2001. else
  2002. { l3_debug(st, "l3dss1_cmd_global abort unknown id");
  2003. return (-2);
  2004. }
  2005. break;
  2006. default:
  2007. l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
  2008. return (-1);
  2009. } /* switch ic-> arg */
  2010. return (-1);
  2011. } /* l3dss1_cmd_global */
  2012. static void
  2013. l3dss1_io_timer(struct l3_process *pc)
  2014. { isdn_ctrl ic;
  2015. struct IsdnCardState *cs = pc->st->l1.hardware;
  2016. L3DelTimer(&pc->timer); /* remove timer */
  2017. ic.driver = cs->myid;
  2018. ic.command = ISDN_STAT_PROT;
  2019. ic.arg = DSS1_STAT_INVOKE_ERR;
  2020. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  2021. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  2022. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  2023. ic.parm.dss1_io.timeout = -1;
  2024. ic.parm.dss1_io.datalen = 0;
  2025. ic.parm.dss1_io.data = NULL;
  2026. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  2027. pc->prot.dss1.invoke_id = 0; /* reset id */
  2028. cs->iif.statcallb(&ic);
  2029. dss1_release_l3_process(pc);
  2030. } /* l3dss1_io_timer */
  2031. static void
  2032. l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg)
  2033. {
  2034. u_char *p;
  2035. struct sk_buff *skb = arg;
  2036. int callState = 0;
  2037. p = skb->data;
  2038. if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
  2039. p++;
  2040. if (1 == *p++)
  2041. callState = *p;
  2042. }
  2043. if (callState == 0) {
  2044. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
  2045. * set down layer 3 without sending any message
  2046. */
  2047. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2048. newl3state(pc, 0);
  2049. dss1_release_l3_process(pc);
  2050. } else {
  2051. pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
  2052. }
  2053. }
  2054. static void
  2055. l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg)
  2056. {
  2057. }
  2058. static void
  2059. l3dss1_t302(struct l3_process *pc, u_char pr, void *arg)
  2060. {
  2061. L3DelTimer(&pc->timer);
  2062. pc->para.loc = 0;
  2063. pc->para.cause = 28; /* invalid number */
  2064. l3dss1_disconnect_req(pc, pr, NULL);
  2065. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2066. }
  2067. static void
  2068. l3dss1_t303(struct l3_process *pc, u_char pr, void *arg)
  2069. {
  2070. if (pc->N303 > 0) {
  2071. pc->N303--;
  2072. L3DelTimer(&pc->timer);
  2073. l3dss1_setup_req(pc, pr, arg);
  2074. } else {
  2075. L3DelTimer(&pc->timer);
  2076. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
  2077. pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
  2078. dss1_release_l3_process(pc);
  2079. }
  2080. }
  2081. static void
  2082. l3dss1_t304(struct l3_process *pc, u_char pr, void *arg)
  2083. {
  2084. L3DelTimer(&pc->timer);
  2085. pc->para.loc = 0;
  2086. pc->para.cause = 102;
  2087. l3dss1_disconnect_req(pc, pr, NULL);
  2088. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2089. }
  2090. static void
  2091. l3dss1_t305(struct l3_process *pc, u_char pr, void *arg)
  2092. {
  2093. u_char tmp[16];
  2094. u_char *p = tmp;
  2095. int l;
  2096. struct sk_buff *skb;
  2097. u_char cause = 16;
  2098. L3DelTimer(&pc->timer);
  2099. if (pc->para.cause != NO_CAUSE)
  2100. cause = pc->para.cause;
  2101. MsgHead(p, pc->callref, MT_RELEASE);
  2102. *p++ = IE_CAUSE;
  2103. *p++ = 0x2;
  2104. *p++ = 0x80;
  2105. *p++ = cause | 0x80;
  2106. l = p - tmp;
  2107. if (!(skb = l3_alloc_skb(l)))
  2108. return;
  2109. memcpy(skb_put(skb, l), tmp, l);
  2110. newl3state(pc, 19);
  2111. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2112. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2113. }
  2114. static void
  2115. l3dss1_t310(struct l3_process *pc, u_char pr, void *arg)
  2116. {
  2117. L3DelTimer(&pc->timer);
  2118. pc->para.loc = 0;
  2119. pc->para.cause = 102;
  2120. l3dss1_disconnect_req(pc, pr, NULL);
  2121. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2122. }
  2123. static void
  2124. l3dss1_t313(struct l3_process *pc, u_char pr, void *arg)
  2125. {
  2126. L3DelTimer(&pc->timer);
  2127. pc->para.loc = 0;
  2128. pc->para.cause = 102;
  2129. l3dss1_disconnect_req(pc, pr, NULL);
  2130. pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
  2131. }
  2132. static void
  2133. l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg)
  2134. {
  2135. newl3state(pc, 19);
  2136. L3DelTimer(&pc->timer);
  2137. l3dss1_message(pc, MT_RELEASE);
  2138. L3AddTimer(&pc->timer, T308, CC_T308_2);
  2139. }
  2140. static void
  2141. l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg)
  2142. {
  2143. L3DelTimer(&pc->timer);
  2144. pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
  2145. dss1_release_l3_process(pc);
  2146. }
  2147. static void
  2148. l3dss1_t318(struct l3_process *pc, u_char pr, void *arg)
  2149. {
  2150. L3DelTimer(&pc->timer);
  2151. pc->para.cause = 102; /* Timer expiry */
  2152. pc->para.loc = 0; /* local */
  2153. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2154. newl3state(pc, 19);
  2155. l3dss1_message(pc, MT_RELEASE);
  2156. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2157. }
  2158. static void
  2159. l3dss1_t319(struct l3_process *pc, u_char pr, void *arg)
  2160. {
  2161. L3DelTimer(&pc->timer);
  2162. pc->para.cause = 102; /* Timer expiry */
  2163. pc->para.loc = 0; /* local */
  2164. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2165. newl3state(pc, 10);
  2166. }
  2167. static void
  2168. l3dss1_restart(struct l3_process *pc, u_char pr, void *arg)
  2169. {
  2170. L3DelTimer(&pc->timer);
  2171. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2172. dss1_release_l3_process(pc);
  2173. }
  2174. static void
  2175. l3dss1_status(struct l3_process *pc, u_char pr, void *arg)
  2176. {
  2177. u_char *p;
  2178. struct sk_buff *skb = arg;
  2179. int ret;
  2180. u_char cause = 0, callState = 0;
  2181. if ((ret = l3dss1_get_cause(pc, skb))) {
  2182. if (pc->debug & L3_DEB_WARN)
  2183. l3_debug(pc->st, "STATUS get_cause ret(%d)", ret);
  2184. if (ret < 0)
  2185. cause = 96;
  2186. else if (ret > 0)
  2187. cause = 100;
  2188. }
  2189. if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
  2190. p++;
  2191. if (1 == *p++) {
  2192. callState = *p;
  2193. if (!ie_in_set(pc, *p, l3_valid_states))
  2194. cause = 100;
  2195. } else
  2196. cause = 100;
  2197. } else
  2198. cause = 96;
  2199. if (!cause) { /* no error before */
  2200. ret = check_infoelements(pc, skb, ie_STATUS);
  2201. if (ERR_IE_COMPREHENSION == ret)
  2202. cause = 96;
  2203. else if (ERR_IE_UNRECOGNIZED == ret)
  2204. cause = 99;
  2205. }
  2206. if (cause) {
  2207. u_char tmp;
  2208. if (pc->debug & L3_DEB_WARN)
  2209. l3_debug(pc->st, "STATUS error(%d/%d)", ret, cause);
  2210. tmp = pc->para.cause;
  2211. pc->para.cause = cause;
  2212. l3dss1_status_send(pc, 0, NULL);
  2213. if (cause == 99)
  2214. pc->para.cause = tmp;
  2215. else
  2216. return;
  2217. }
  2218. cause = pc->para.cause;
  2219. if (((cause & 0x7f) == 111) && (callState == 0)) {
  2220. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
  2221. * if received MT_STATUS with cause == 111 and call
  2222. * state == 0, then we must set down layer 3
  2223. */
  2224. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2225. newl3state(pc, 0);
  2226. dss1_release_l3_process(pc);
  2227. }
  2228. }
  2229. static void
  2230. l3dss1_facility(struct l3_process *pc, u_char pr, void *arg)
  2231. {
  2232. struct sk_buff *skb = arg;
  2233. int ret;
  2234. ret = check_infoelements(pc, skb, ie_FACILITY);
  2235. l3dss1_std_ie_err(pc, ret);
  2236. {
  2237. u_char *p;
  2238. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  2239. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  2240. }
  2241. }
  2242. static void
  2243. l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
  2244. {
  2245. struct sk_buff *skb;
  2246. u_char tmp[32];
  2247. u_char *p = tmp;
  2248. u_char i, l;
  2249. u_char *msg = pc->chan->setup.phone;
  2250. MsgHead(p, pc->callref, MT_SUSPEND);
  2251. l = *msg++;
  2252. if (l && (l <= 10)) { /* Max length 10 octets */
  2253. *p++ = IE_CALL_ID;
  2254. *p++ = l;
  2255. for (i = 0; i < l; i++)
  2256. *p++ = *msg++;
  2257. } else if (l) {
  2258. l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
  2259. return;
  2260. }
  2261. l = p - tmp;
  2262. if (!(skb = l3_alloc_skb(l)))
  2263. return;
  2264. memcpy(skb_put(skb, l), tmp, l);
  2265. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2266. newl3state(pc, 15);
  2267. L3AddTimer(&pc->timer, T319, CC_T319);
  2268. }
  2269. static void
  2270. l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
  2271. {
  2272. struct sk_buff *skb = arg;
  2273. int ret;
  2274. L3DelTimer(&pc->timer);
  2275. newl3state(pc, 0);
  2276. pc->para.cause = NO_CAUSE;
  2277. pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
  2278. /* We don't handle suspend_ack for IE errors now */
  2279. if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
  2280. if (pc->debug & L3_DEB_WARN)
  2281. l3_debug(pc->st, "SUSPACK check ie(%d)", ret);
  2282. dss1_release_l3_process(pc);
  2283. }
  2284. static void
  2285. l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
  2286. {
  2287. struct sk_buff *skb = arg;
  2288. int ret;
  2289. if ((ret = l3dss1_get_cause(pc, skb))) {
  2290. if (pc->debug & L3_DEB_WARN)
  2291. l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)", ret);
  2292. if (ret < 0)
  2293. pc->para.cause = 96;
  2294. else
  2295. pc->para.cause = 100;
  2296. l3dss1_status_send(pc, pr, NULL);
  2297. return;
  2298. }
  2299. ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
  2300. if (ERR_IE_COMPREHENSION == ret) {
  2301. l3dss1_std_ie_err(pc, ret);
  2302. return;
  2303. }
  2304. L3DelTimer(&pc->timer);
  2305. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2306. newl3state(pc, 10);
  2307. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2308. l3dss1_std_ie_err(pc, ret);
  2309. }
  2310. static void
  2311. l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg)
  2312. {
  2313. struct sk_buff *skb;
  2314. u_char tmp[32];
  2315. u_char *p = tmp;
  2316. u_char i, l;
  2317. u_char *msg = pc->para.setup.phone;
  2318. MsgHead(p, pc->callref, MT_RESUME);
  2319. l = *msg++;
  2320. if (l && (l <= 10)) { /* Max length 10 octets */
  2321. *p++ = IE_CALL_ID;
  2322. *p++ = l;
  2323. for (i = 0; i < l; i++)
  2324. *p++ = *msg++;
  2325. } else if (l) {
  2326. l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
  2327. return;
  2328. }
  2329. l = p - tmp;
  2330. if (!(skb = l3_alloc_skb(l)))
  2331. return;
  2332. memcpy(skb_put(skb, l), tmp, l);
  2333. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2334. newl3state(pc, 17);
  2335. L3AddTimer(&pc->timer, T318, CC_T318);
  2336. }
  2337. static void
  2338. l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
  2339. {
  2340. struct sk_buff *skb = arg;
  2341. int id, ret;
  2342. if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
  2343. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  2344. if (pc->debug & L3_DEB_WARN)
  2345. l3_debug(pc->st, "resume ack with wrong chid %x", id);
  2346. pc->para.cause = 100;
  2347. l3dss1_status_send(pc, pr, NULL);
  2348. return;
  2349. }
  2350. pc->para.bchannel = id;
  2351. } else if (1 == pc->state) {
  2352. if (pc->debug & L3_DEB_WARN)
  2353. l3_debug(pc->st, "resume ack without chid (ret %d)", id);
  2354. pc->para.cause = 96;
  2355. l3dss1_status_send(pc, pr, NULL);
  2356. return;
  2357. }
  2358. ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
  2359. if (ERR_IE_COMPREHENSION == ret) {
  2360. l3dss1_std_ie_err(pc, ret);
  2361. return;
  2362. }
  2363. L3DelTimer(&pc->timer);
  2364. pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
  2365. newl3state(pc, 10);
  2366. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2367. l3dss1_std_ie_err(pc, ret);
  2368. }
  2369. static void
  2370. l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
  2371. {
  2372. struct sk_buff *skb = arg;
  2373. int ret;
  2374. if ((ret = l3dss1_get_cause(pc, skb))) {
  2375. if (pc->debug & L3_DEB_WARN)
  2376. l3_debug(pc->st, "RES_REJ get_cause ret(%d)", ret);
  2377. if (ret < 0)
  2378. pc->para.cause = 96;
  2379. else
  2380. pc->para.cause = 100;
  2381. l3dss1_status_send(pc, pr, NULL);
  2382. return;
  2383. }
  2384. ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
  2385. if (ERR_IE_COMPREHENSION == ret) {
  2386. l3dss1_std_ie_err(pc, ret);
  2387. return;
  2388. }
  2389. L3DelTimer(&pc->timer);
  2390. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2391. newl3state(pc, 0);
  2392. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2393. l3dss1_std_ie_err(pc, ret);
  2394. dss1_release_l3_process(pc);
  2395. }
  2396. static void
  2397. l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg)
  2398. {
  2399. u_char tmp[32];
  2400. u_char *p;
  2401. u_char ri, ch = 0, chan = 0;
  2402. int l;
  2403. struct sk_buff *skb = arg;
  2404. struct l3_process *up;
  2405. newl3state(pc, 2);
  2406. L3DelTimer(&pc->timer);
  2407. p = skb->data;
  2408. if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
  2409. ri = p[2];
  2410. l3_debug(pc->st, "Restart %x", ri);
  2411. } else {
  2412. l3_debug(pc->st, "Restart without restart IE");
  2413. ri = 0x86;
  2414. }
  2415. p = skb->data;
  2416. if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
  2417. chan = p[2] & 3;
  2418. ch = p[2];
  2419. if (pc->st->l3.debug)
  2420. l3_debug(pc->st, "Restart for channel %d", chan);
  2421. }
  2422. newl3state(pc, 2);
  2423. up = pc->st->l3.proc;
  2424. while (up) {
  2425. if ((ri & 7) == 7)
  2426. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2427. else if (up->para.bchannel == chan)
  2428. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2429. up = up->next;
  2430. }
  2431. p = tmp;
  2432. MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
  2433. if (chan) {
  2434. *p++ = IE_CHANNEL_ID;
  2435. *p++ = 1;
  2436. *p++ = ch | 0x80;
  2437. }
  2438. *p++ = 0x79; /* RESTART Ind */
  2439. *p++ = 1;
  2440. *p++ = ri;
  2441. l = p - tmp;
  2442. if (!(skb = l3_alloc_skb(l)))
  2443. return;
  2444. memcpy(skb_put(skb, l), tmp, l);
  2445. newl3state(pc, 0);
  2446. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2447. }
  2448. static void
  2449. l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
  2450. {
  2451. pc->para.cause = 0x29; /* Temporary failure */
  2452. pc->para.loc = 0;
  2453. l3dss1_disconnect_req(pc, pr, NULL);
  2454. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2455. }
  2456. static void
  2457. l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg)
  2458. {
  2459. newl3state(pc, 0);
  2460. pc->para.cause = 0x1b; /* Destination out of order */
  2461. pc->para.loc = 0;
  2462. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2463. release_l3_process(pc);
  2464. }
  2465. static void
  2466. l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
  2467. {
  2468. L3DelTimer(&pc->timer);
  2469. L3AddTimer(&pc->timer, T309, CC_T309);
  2470. l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
  2471. }
  2472. static void
  2473. l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
  2474. {
  2475. L3DelTimer(&pc->timer);
  2476. pc->para.cause = 0x1F; /* normal, unspecified */
  2477. l3dss1_status_send(pc, 0, NULL);
  2478. }
  2479. /* *INDENT-OFF* */
  2480. static struct stateentry downstatelist[] =
  2481. {
  2482. {SBIT(0),
  2483. CC_SETUP | REQUEST, l3dss1_setup_req},
  2484. {SBIT(0),
  2485. CC_RESUME | REQUEST, l3dss1_resume_req},
  2486. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
  2487. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2488. {SBIT(12),
  2489. CC_RELEASE | REQUEST, l3dss1_release_req},
  2490. {ALL_STATES,
  2491. CC_RESTART | REQUEST, l3dss1_restart},
  2492. {SBIT(6) | SBIT(25),
  2493. CC_IGNORE | REQUEST, l3dss1_reset},
  2494. {SBIT(6) | SBIT(25),
  2495. CC_REJECT | REQUEST, l3dss1_reject_req},
  2496. {SBIT(6) | SBIT(25),
  2497. CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
  2498. {SBIT(6),
  2499. CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
  2500. {SBIT(25),
  2501. CC_MORE_INFO | REQUEST, l3dss1_dummy},
  2502. {SBIT(6) | SBIT(9) | SBIT(25),
  2503. CC_ALERTING | REQUEST, l3dss1_alert_req},
  2504. {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
  2505. CC_SETUP | RESPONSE, l3dss1_setup_rsp},
  2506. {SBIT(10),
  2507. CC_SUSPEND | REQUEST, l3dss1_suspend_req},
  2508. {SBIT(7) | SBIT(9) | SBIT(25),
  2509. CC_REDIR | REQUEST, l3dss1_redir_req},
  2510. {SBIT(6),
  2511. CC_REDIR | REQUEST, l3dss1_redir_req_early},
  2512. {SBIT(9) | SBIT(25),
  2513. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2514. {SBIT(25),
  2515. CC_T302, l3dss1_t302},
  2516. {SBIT(1),
  2517. CC_T303, l3dss1_t303},
  2518. {SBIT(2),
  2519. CC_T304, l3dss1_t304},
  2520. {SBIT(3),
  2521. CC_T310, l3dss1_t310},
  2522. {SBIT(8),
  2523. CC_T313, l3dss1_t313},
  2524. {SBIT(11),
  2525. CC_T305, l3dss1_t305},
  2526. {SBIT(15),
  2527. CC_T319, l3dss1_t319},
  2528. {SBIT(17),
  2529. CC_T318, l3dss1_t318},
  2530. {SBIT(19),
  2531. CC_T308_1, l3dss1_t308_1},
  2532. {SBIT(19),
  2533. CC_T308_2, l3dss1_t308_2},
  2534. {SBIT(10),
  2535. CC_T309, l3dss1_dl_release},
  2536. };
  2537. static struct stateentry datastatelist[] =
  2538. {
  2539. {ALL_STATES,
  2540. MT_STATUS_ENQUIRY, l3dss1_status_enq},
  2541. {ALL_STATES,
  2542. MT_FACILITY, l3dss1_facility},
  2543. {SBIT(19),
  2544. MT_STATUS, l3dss1_release_ind},
  2545. {ALL_STATES,
  2546. MT_STATUS, l3dss1_status},
  2547. {SBIT(0),
  2548. MT_SETUP, l3dss1_setup},
  2549. {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
  2550. SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2551. MT_SETUP, l3dss1_dummy},
  2552. {SBIT(1) | SBIT(2),
  2553. MT_CALL_PROCEEDING, l3dss1_call_proc},
  2554. {SBIT(1),
  2555. MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
  2556. {SBIT(2) | SBIT(3),
  2557. MT_ALERTING, l3dss1_alerting},
  2558. {SBIT(2) | SBIT(3),
  2559. MT_PROGRESS, l3dss1_progress},
  2560. {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
  2561. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2562. MT_INFORMATION, l3dss1_information},
  2563. {SBIT(10) | SBIT(11) | SBIT(15),
  2564. MT_NOTIFY, l3dss1_notify},
  2565. {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
  2566. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2567. MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
  2568. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(25),
  2569. MT_RELEASE, l3dss1_release},
  2570. {SBIT(19), MT_RELEASE, l3dss1_release_ind},
  2571. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
  2572. MT_DISCONNECT, l3dss1_disconnect},
  2573. {SBIT(19),
  2574. MT_DISCONNECT, l3dss1_dummy},
  2575. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
  2576. MT_CONNECT, l3dss1_connect},
  2577. {SBIT(8),
  2578. MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
  2579. {SBIT(15),
  2580. MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
  2581. {SBIT(15),
  2582. MT_SUSPEND_REJECT, l3dss1_suspend_rej},
  2583. {SBIT(17),
  2584. MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
  2585. {SBIT(17),
  2586. MT_RESUME_REJECT, l3dss1_resume_rej},
  2587. };
  2588. static struct stateentry globalmes_list[] =
  2589. {
  2590. {ALL_STATES,
  2591. MT_STATUS, l3dss1_status},
  2592. {SBIT(0),
  2593. MT_RESTART, l3dss1_global_restart},
  2594. /* {SBIT(1),
  2595. MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
  2596. */
  2597. };
  2598. static struct stateentry manstatelist[] =
  2599. {
  2600. {SBIT(2),
  2601. DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
  2602. {SBIT(10),
  2603. DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
  2604. {SBIT(10),
  2605. DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
  2606. {ALL_STATES,
  2607. DL_RELEASE | INDICATION, l3dss1_dl_release},
  2608. };
  2609. /* *INDENT-ON* */
  2610. static void
  2611. global_handler(struct PStack *st, int mt, struct sk_buff *skb)
  2612. {
  2613. u_char tmp[16];
  2614. u_char *p = tmp;
  2615. int l;
  2616. int i;
  2617. struct l3_process *proc = st->l3.global;
  2618. proc->callref = skb->data[2]; /* cr flag */
  2619. for (i = 0; i < ARRAY_SIZE(globalmes_list); i++)
  2620. if ((mt == globalmes_list[i].primitive) &&
  2621. ((1 << proc->state) & globalmes_list[i].state))
  2622. break;
  2623. if (i == ARRAY_SIZE(globalmes_list)) {
  2624. if (st->l3.debug & L3_DEB_STATE) {
  2625. l3_debug(st, "dss1 global state %d mt %x unhandled",
  2626. proc->state, mt);
  2627. }
  2628. MsgHead(p, proc->callref, MT_STATUS);
  2629. *p++ = IE_CAUSE;
  2630. *p++ = 0x2;
  2631. *p++ = 0x80;
  2632. *p++ = 81 | 0x80; /* invalid cr */
  2633. *p++ = 0x14; /* CallState */
  2634. *p++ = 0x1;
  2635. *p++ = proc->state & 0x3f;
  2636. l = p - tmp;
  2637. if (!(skb = l3_alloc_skb(l)))
  2638. return;
  2639. memcpy(skb_put(skb, l), tmp, l);
  2640. l3_msg(proc->st, DL_DATA | REQUEST, skb);
  2641. } else {
  2642. if (st->l3.debug & L3_DEB_STATE) {
  2643. l3_debug(st, "dss1 global %d mt %x",
  2644. proc->state, mt);
  2645. }
  2646. globalmes_list[i].rout(proc, mt, skb);
  2647. }
  2648. }
  2649. static void
  2650. dss1up(struct PStack *st, int pr, void *arg)
  2651. {
  2652. int i, mt, cr, callState;
  2653. char *ptr;
  2654. u_char *p;
  2655. struct sk_buff *skb = arg;
  2656. struct l3_process *proc;
  2657. switch (pr) {
  2658. case (DL_DATA | INDICATION):
  2659. case (DL_UNIT_DATA | INDICATION):
  2660. break;
  2661. case (DL_ESTABLISH | CONFIRM):
  2662. case (DL_ESTABLISH | INDICATION):
  2663. case (DL_RELEASE | INDICATION):
  2664. case (DL_RELEASE | CONFIRM):
  2665. l3_msg(st, pr, arg);
  2666. return;
  2667. break;
  2668. default:
  2669. printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
  2670. return;
  2671. }
  2672. if (skb->len < 3) {
  2673. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2674. dev_kfree_skb(skb);
  2675. return;
  2676. }
  2677. if (skb->data[0] != PROTO_DIS_EURO) {
  2678. if (st->l3.debug & L3_DEB_PROTERR) {
  2679. l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
  2680. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2681. skb->data[0], skb->len);
  2682. }
  2683. dev_kfree_skb(skb);
  2684. return;
  2685. }
  2686. cr = getcallref(skb->data);
  2687. if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
  2688. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2689. dev_kfree_skb(skb);
  2690. return;
  2691. }
  2692. mt = skb->data[skb->data[1] + 2];
  2693. if (st->l3.debug & L3_DEB_STATE)
  2694. l3_debug(st, "dss1up cr %d", cr);
  2695. if (cr == -2) { /* wrong Callref */
  2696. if (st->l3.debug & L3_DEB_WARN)
  2697. l3_debug(st, "dss1up wrong Callref");
  2698. dev_kfree_skb(skb);
  2699. return;
  2700. } else if (cr == -1) { /* Dummy Callref */
  2701. if (mt == MT_FACILITY)
  2702. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  2703. l3dss1_parse_facility(st, NULL,
  2704. (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
  2705. dev_kfree_skb(skb);
  2706. return;
  2707. }
  2708. if (st->l3.debug & L3_DEB_WARN)
  2709. l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
  2710. dev_kfree_skb(skb);
  2711. return;
  2712. } else if ((((skb->data[1] & 0x0f) == 1) && (0 == (cr & 0x7f))) ||
  2713. (((skb->data[1] & 0x0f) == 2) && (0 == (cr & 0x7fff)))) { /* Global CallRef */
  2714. if (st->l3.debug & L3_DEB_STATE)
  2715. l3_debug(st, "dss1up Global CallRef");
  2716. global_handler(st, mt, skb);
  2717. dev_kfree_skb(skb);
  2718. return;
  2719. } else if (!(proc = getl3proc(st, cr))) {
  2720. /* No transaction process exist, that means no call with
  2721. * this callreference is active
  2722. */
  2723. if (mt == MT_SETUP) {
  2724. /* Setup creates a new transaction process */
  2725. if (skb->data[2] & 0x80) {
  2726. /* Setup with wrong CREF flag */
  2727. if (st->l3.debug & L3_DEB_STATE)
  2728. l3_debug(st, "dss1up wrong CRef flag");
  2729. dev_kfree_skb(skb);
  2730. return;
  2731. }
  2732. if (!(proc = dss1_new_l3_process(st, cr))) {
  2733. /* May be to answer with RELEASE_COMPLETE and
  2734. * CAUSE 0x2f "Resource unavailable", but this
  2735. * need a new_l3_process too ... arghh
  2736. */
  2737. dev_kfree_skb(skb);
  2738. return;
  2739. }
  2740. } else if (mt == MT_STATUS) {
  2741. if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
  2742. ptr++;
  2743. if (*ptr++ == 2)
  2744. ptr++;
  2745. }
  2746. callState = 0;
  2747. if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
  2748. ptr++;
  2749. if (*ptr++ == 2)
  2750. ptr++;
  2751. callState = *ptr;
  2752. }
  2753. /* ETS 300-104 part 2.4.1
  2754. * if setup has not been made and a message type
  2755. * MT_STATUS is received with call state == 0,
  2756. * we must send nothing
  2757. */
  2758. if (callState != 0) {
  2759. /* ETS 300-104 part 2.4.2
  2760. * if setup has not been made and a message type
  2761. * MT_STATUS is received with call state != 0,
  2762. * we must send MT_RELEASE_COMPLETE cause 101
  2763. */
  2764. if ((proc = dss1_new_l3_process(st, cr))) {
  2765. proc->para.cause = 101;
  2766. l3dss1_msg_without_setup(proc, 0, NULL);
  2767. }
  2768. }
  2769. dev_kfree_skb(skb);
  2770. return;
  2771. } else if (mt == MT_RELEASE_COMPLETE) {
  2772. dev_kfree_skb(skb);
  2773. return;
  2774. } else {
  2775. /* ETS 300-104 part 2
  2776. * if setup has not been made and a message type
  2777. * (except MT_SETUP and RELEASE_COMPLETE) is received,
  2778. * we must send MT_RELEASE_COMPLETE cause 81 */
  2779. dev_kfree_skb(skb);
  2780. if ((proc = dss1_new_l3_process(st, cr))) {
  2781. proc->para.cause = 81;
  2782. l3dss1_msg_without_setup(proc, 0, NULL);
  2783. }
  2784. return;
  2785. }
  2786. }
  2787. if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
  2788. dev_kfree_skb(skb);
  2789. return;
  2790. }
  2791. if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
  2792. l3dss1_deliver_display(proc, pr, p); /* Display IE included */
  2793. for (i = 0; i < ARRAY_SIZE(datastatelist); i++)
  2794. if ((mt == datastatelist[i].primitive) &&
  2795. ((1 << proc->state) & datastatelist[i].state))
  2796. break;
  2797. if (i == ARRAY_SIZE(datastatelist)) {
  2798. if (st->l3.debug & L3_DEB_STATE) {
  2799. l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
  2800. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2801. proc->state, mt);
  2802. }
  2803. if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
  2804. proc->para.cause = 101;
  2805. l3dss1_status_send(proc, pr, skb);
  2806. }
  2807. } else {
  2808. if (st->l3.debug & L3_DEB_STATE) {
  2809. l3_debug(st, "dss1up%sstate %d mt %x",
  2810. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2811. proc->state, mt);
  2812. }
  2813. datastatelist[i].rout(proc, pr, skb);
  2814. }
  2815. dev_kfree_skb(skb);
  2816. return;
  2817. }
  2818. static void
  2819. dss1down(struct PStack *st, int pr, void *arg)
  2820. {
  2821. int i, cr;
  2822. struct l3_process *proc;
  2823. struct Channel *chan;
  2824. if ((DL_ESTABLISH | REQUEST) == pr) {
  2825. l3_msg(st, pr, NULL);
  2826. return;
  2827. } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
  2828. chan = arg;
  2829. cr = newcallref();
  2830. cr |= 0x80;
  2831. if ((proc = dss1_new_l3_process(st, cr))) {
  2832. proc->chan = chan;
  2833. chan->proc = proc;
  2834. memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
  2835. proc->callref = cr;
  2836. }
  2837. } else {
  2838. proc = arg;
  2839. }
  2840. if (!proc) {
  2841. printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
  2842. return;
  2843. }
  2844. if (pr == (CC_TDSS1_IO | REQUEST)) {
  2845. l3dss1_io_timer(proc); /* timer expires */
  2846. return;
  2847. }
  2848. for (i = 0; i < ARRAY_SIZE(downstatelist); i++)
  2849. if ((pr == downstatelist[i].primitive) &&
  2850. ((1 << proc->state) & downstatelist[i].state))
  2851. break;
  2852. if (i == ARRAY_SIZE(downstatelist)) {
  2853. if (st->l3.debug & L3_DEB_STATE) {
  2854. l3_debug(st, "dss1down state %d prim %#x unhandled",
  2855. proc->state, pr);
  2856. }
  2857. } else {
  2858. if (st->l3.debug & L3_DEB_STATE) {
  2859. l3_debug(st, "dss1down state %d prim %#x",
  2860. proc->state, pr);
  2861. }
  2862. downstatelist[i].rout(proc, pr, arg);
  2863. }
  2864. }
  2865. static void
  2866. dss1man(struct PStack *st, int pr, void *arg)
  2867. {
  2868. int i;
  2869. struct l3_process *proc = arg;
  2870. if (!proc) {
  2871. printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
  2872. return;
  2873. }
  2874. for (i = 0; i < ARRAY_SIZE(manstatelist); i++)
  2875. if ((pr == manstatelist[i].primitive) &&
  2876. ((1 << proc->state) & manstatelist[i].state))
  2877. break;
  2878. if (i == ARRAY_SIZE(manstatelist)) {
  2879. if (st->l3.debug & L3_DEB_STATE) {
  2880. l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
  2881. proc->callref & 0x7f, proc->state, pr);
  2882. }
  2883. } else {
  2884. if (st->l3.debug & L3_DEB_STATE) {
  2885. l3_debug(st, "cr %d dss1man state %d prim %#x",
  2886. proc->callref & 0x7f, proc->state, pr);
  2887. }
  2888. manstatelist[i].rout(proc, pr, arg);
  2889. }
  2890. }
  2891. void
  2892. setstack_dss1(struct PStack *st)
  2893. {
  2894. char tmp[64];
  2895. int i;
  2896. st->lli.l4l3 = dss1down;
  2897. st->lli.l4l3_proto = l3dss1_cmd_global;
  2898. st->l2.l2l3 = dss1up;
  2899. st->l3.l3ml3 = dss1man;
  2900. st->l3.N303 = 1;
  2901. st->prot.dss1.last_invoke_id = 0;
  2902. st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
  2903. i = 1;
  2904. while (i < 32)
  2905. st->prot.dss1.invoke_used[i++] = 0;
  2906. if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
  2907. printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
  2908. } else {
  2909. st->l3.global->state = 0;
  2910. st->l3.global->callref = 0;
  2911. st->l3.global->next = NULL;
  2912. st->l3.global->debug = L3_DEB_WARN;
  2913. st->l3.global->st = st;
  2914. st->l3.global->N303 = 1;
  2915. st->l3.global->prot.dss1.invoke_id = 0;
  2916. L3InitTimer(st->l3.global, &st->l3.global->timer);
  2917. }
  2918. strcpy(tmp, dss1_revision);
  2919. printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));
  2920. }