l3dss1.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228
  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. skb_put_data(skb, 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. skb_put_data(skb, 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. skb_put_data(skb, 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. skb_put_data(skb, 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. /* fall through */
  1130. case 'P':
  1131. channel |= 0x80;
  1132. teln++;
  1133. if (*teln == '1')
  1134. channel |= 0x01;
  1135. else
  1136. channel |= 0x02;
  1137. break;
  1138. case 'R':
  1139. screen = 0xA0;
  1140. break;
  1141. case 'D':
  1142. screen = 0x80;
  1143. break;
  1144. default:
  1145. if (pc->debug & L3_DEB_WARN)
  1146. l3_debug(pc->st, "Wrong MSN Code");
  1147. break;
  1148. }
  1149. teln++;
  1150. }
  1151. }
  1152. if (channel) {
  1153. *p++ = IE_CHANNEL_ID;
  1154. *p++ = 1;
  1155. *p++ = channel;
  1156. }
  1157. msn = pc->para.setup.eazmsn;
  1158. sub = NULL;
  1159. sp = msn;
  1160. while (*sp) {
  1161. if ('.' == *sp) {
  1162. sub = sp;
  1163. *sp = 0;
  1164. } else
  1165. sp++;
  1166. }
  1167. if (*msn) {
  1168. *p++ = IE_CALLING_PN;
  1169. *p++ = strlen(msn) + (screen ? 2 : 1);
  1170. /* Classify as AnyPref. */
  1171. if (screen) {
  1172. *p++ = 0x01; /* Ext = '0'B, Type = '000'B, Plan = '0001'B. */
  1173. *p++ = screen;
  1174. } else
  1175. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1176. while (*msn)
  1177. *p++ = *msn++ & 0x7f;
  1178. }
  1179. if (sub) {
  1180. *sub++ = '.';
  1181. *p++ = IE_CALLING_SUB;
  1182. *p++ = strlen(sub) + 2;
  1183. *p++ = 0x80; /* NSAP coded */
  1184. *p++ = 0x50; /* local IDI format */
  1185. while (*sub)
  1186. *p++ = *sub++ & 0x7f;
  1187. }
  1188. sub = NULL;
  1189. sp = teln;
  1190. while (*sp) {
  1191. if ('.' == *sp) {
  1192. sub = sp;
  1193. *sp = 0;
  1194. } else
  1195. sp++;
  1196. }
  1197. if (!send_keypad) {
  1198. *p++ = IE_CALLED_PN;
  1199. *p++ = strlen(teln) + 1;
  1200. /* Classify as AnyPref. */
  1201. *p++ = 0x81; /* Ext = '1'B, Type = '000'B, Plan = '0001'B. */
  1202. while (*teln)
  1203. *p++ = *teln++ & 0x7f;
  1204. if (sub) {
  1205. *sub++ = '.';
  1206. *p++ = IE_CALLED_SUB;
  1207. *p++ = strlen(sub) + 2;
  1208. *p++ = 0x80; /* NSAP coded */
  1209. *p++ = 0x50; /* local IDI format */
  1210. while (*sub)
  1211. *p++ = *sub++ & 0x7f;
  1212. }
  1213. }
  1214. #ifdef EXT_BEARER_CAPS
  1215. if ((pc->para.setup.si2 >= 160) && (pc->para.setup.si2 <= 175)) { // sync. Bitratenadaption, V.110/X.30
  1216. *p++ = IE_LLC;
  1217. *p++ = 0x04;
  1218. *p++ = 0x88;
  1219. *p++ = 0x90;
  1220. *p++ = 0x21;
  1221. *p++ = EncodeSyncParams(pc->para.setup.si2 - 160, 0x80);
  1222. } else if ((pc->para.setup.si2 >= 176) && (pc->para.setup.si2 <= 191)) { // sync. Bitratenadaption, V.120
  1223. *p++ = IE_LLC;
  1224. *p++ = 0x05;
  1225. *p++ = 0x88;
  1226. *p++ = 0x90;
  1227. *p++ = 0x28;
  1228. *p++ = EncodeSyncParams(pc->para.setup.si2 - 176, 0);
  1229. *p++ = 0x82;
  1230. } else if (pc->para.setup.si2 >= 192) { // async. Bitratenadaption, V.110/X.30
  1231. *p++ = IE_LLC;
  1232. *p++ = 0x06;
  1233. *p++ = 0x88;
  1234. *p++ = 0x90;
  1235. *p++ = 0x21;
  1236. p = EncodeASyncParams(p, pc->para.setup.si2 - 192);
  1237. #ifndef CONFIG_HISAX_NO_LLC
  1238. } else {
  1239. switch (pc->para.setup.si1) {
  1240. case 1: /* Telephony */
  1241. *p++ = IE_LLC;
  1242. *p++ = 0x3; /* Length */
  1243. *p++ = 0x90; /* Coding Std. CCITT, 3.1 kHz audio */
  1244. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1245. *p++ = 0xa3; /* A-Law Audio */
  1246. break;
  1247. case 5: /* Datatransmission 64k, BTX */
  1248. case 7: /* Datatransmission 64k */
  1249. default:
  1250. *p++ = IE_LLC;
  1251. *p++ = 0x2; /* Length */
  1252. *p++ = 0x88; /* Coding Std. CCITT, unrestr. dig. Inform. */
  1253. *p++ = 0x90; /* Circuit-Mode 64kbps */
  1254. break;
  1255. }
  1256. #endif
  1257. }
  1258. #endif
  1259. l = p - tmp;
  1260. if (!(skb = l3_alloc_skb(l)))
  1261. return;
  1262. skb_put_data(skb, tmp, l);
  1263. L3DelTimer(&pc->timer);
  1264. L3AddTimer(&pc->timer, T303, CC_T303);
  1265. newl3state(pc, 1);
  1266. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1267. }
  1268. static void
  1269. l3dss1_call_proc(struct l3_process *pc, u_char pr, void *arg)
  1270. {
  1271. struct sk_buff *skb = arg;
  1272. int id, ret;
  1273. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1274. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1275. if (pc->debug & L3_DEB_WARN)
  1276. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1277. pc->para.cause = 100;
  1278. l3dss1_status_send(pc, pr, NULL);
  1279. return;
  1280. }
  1281. pc->para.bchannel = id;
  1282. } else if (1 == pc->state) {
  1283. if (pc->debug & L3_DEB_WARN)
  1284. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1285. if (id == -1)
  1286. pc->para.cause = 96;
  1287. else
  1288. pc->para.cause = 100;
  1289. l3dss1_status_send(pc, pr, NULL);
  1290. return;
  1291. }
  1292. /* Now we are on none mandatory IEs */
  1293. ret = check_infoelements(pc, skb, ie_CALL_PROCEEDING);
  1294. if (ERR_IE_COMPREHENSION == ret) {
  1295. l3dss1_std_ie_err(pc, ret);
  1296. return;
  1297. }
  1298. L3DelTimer(&pc->timer);
  1299. newl3state(pc, 3);
  1300. L3AddTimer(&pc->timer, T310, CC_T310);
  1301. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1302. l3dss1_std_ie_err(pc, ret);
  1303. pc->st->l3.l3l4(pc->st, CC_PROCEEDING | INDICATION, pc);
  1304. }
  1305. static void
  1306. l3dss1_setup_ack(struct l3_process *pc, u_char pr, void *arg)
  1307. {
  1308. struct sk_buff *skb = arg;
  1309. int id, ret;
  1310. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1311. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  1312. if (pc->debug & L3_DEB_WARN)
  1313. l3_debug(pc->st, "setup answer with wrong chid %x", id);
  1314. pc->para.cause = 100;
  1315. l3dss1_status_send(pc, pr, NULL);
  1316. return;
  1317. }
  1318. pc->para.bchannel = id;
  1319. } else {
  1320. if (pc->debug & L3_DEB_WARN)
  1321. l3_debug(pc->st, "setup answer wrong chid (ret %d)", id);
  1322. if (id == -1)
  1323. pc->para.cause = 96;
  1324. else
  1325. pc->para.cause = 100;
  1326. l3dss1_status_send(pc, pr, NULL);
  1327. return;
  1328. }
  1329. /* Now we are on none mandatory IEs */
  1330. ret = check_infoelements(pc, skb, ie_SETUP_ACKNOWLEDGE);
  1331. if (ERR_IE_COMPREHENSION == ret) {
  1332. l3dss1_std_ie_err(pc, ret);
  1333. return;
  1334. }
  1335. L3DelTimer(&pc->timer);
  1336. newl3state(pc, 2);
  1337. L3AddTimer(&pc->timer, T304, CC_T304);
  1338. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  1339. l3dss1_std_ie_err(pc, ret);
  1340. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1341. }
  1342. static void
  1343. l3dss1_disconnect(struct l3_process *pc, u_char pr, void *arg)
  1344. {
  1345. struct sk_buff *skb = arg;
  1346. u_char *p;
  1347. int ret;
  1348. u_char cause = 0;
  1349. StopAllL3Timer(pc);
  1350. if ((ret = l3dss1_get_cause(pc, skb))) {
  1351. if (pc->debug & L3_DEB_WARN)
  1352. l3_debug(pc->st, "DISC get_cause ret(%d)", ret);
  1353. if (ret < 0)
  1354. cause = 96;
  1355. else if (ret > 0)
  1356. cause = 100;
  1357. }
  1358. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  1359. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1360. ret = check_infoelements(pc, skb, ie_DISCONNECT);
  1361. if (ERR_IE_COMPREHENSION == ret)
  1362. cause = 96;
  1363. else if ((!cause) && (ERR_IE_UNRECOGNIZED == ret))
  1364. cause = 99;
  1365. ret = pc->state;
  1366. newl3state(pc, 12);
  1367. if (cause)
  1368. newl3state(pc, 19);
  1369. if (11 != ret)
  1370. pc->st->l3.l3l4(pc->st, CC_DISCONNECT | INDICATION, pc);
  1371. else if (!cause)
  1372. l3dss1_release_req(pc, pr, NULL);
  1373. if (cause) {
  1374. l3dss1_message_cause(pc, MT_RELEASE, cause);
  1375. L3AddTimer(&pc->timer, T308, CC_T308_1);
  1376. }
  1377. }
  1378. static void
  1379. l3dss1_connect(struct l3_process *pc, u_char pr, void *arg)
  1380. {
  1381. struct sk_buff *skb = arg;
  1382. int ret;
  1383. ret = check_infoelements(pc, skb, ie_CONNECT);
  1384. if (ERR_IE_COMPREHENSION == ret) {
  1385. l3dss1_std_ie_err(pc, ret);
  1386. return;
  1387. }
  1388. L3DelTimer(&pc->timer); /* T310 */
  1389. newl3state(pc, 10);
  1390. pc->para.chargeinfo = 0;
  1391. /* here should inserted COLP handling KKe */
  1392. if (ret)
  1393. l3dss1_std_ie_err(pc, ret);
  1394. pc->st->l3.l3l4(pc->st, CC_SETUP | CONFIRM, pc);
  1395. }
  1396. static void
  1397. l3dss1_alerting(struct l3_process *pc, u_char pr, void *arg)
  1398. {
  1399. struct sk_buff *skb = arg;
  1400. int ret;
  1401. ret = check_infoelements(pc, skb, ie_ALERTING);
  1402. if (ERR_IE_COMPREHENSION == ret) {
  1403. l3dss1_std_ie_err(pc, ret);
  1404. return;
  1405. }
  1406. L3DelTimer(&pc->timer); /* T304 */
  1407. newl3state(pc, 4);
  1408. if (ret)
  1409. l3dss1_std_ie_err(pc, ret);
  1410. pc->st->l3.l3l4(pc->st, CC_ALERTING | INDICATION, pc);
  1411. }
  1412. static void
  1413. l3dss1_setup(struct l3_process *pc, u_char pr, void *arg)
  1414. {
  1415. u_char *p;
  1416. int bcfound = 0;
  1417. char tmp[80];
  1418. struct sk_buff *skb = arg;
  1419. int id;
  1420. int err = 0;
  1421. /*
  1422. * Bearer Capabilities
  1423. */
  1424. p = skb->data;
  1425. /* only the first occurrence 'll be detected ! */
  1426. if ((p = findie(p, skb->len, 0x04, 0))) {
  1427. if ((p[1] < 2) || (p[1] > 11))
  1428. err = 1;
  1429. else {
  1430. pc->para.setup.si2 = 0;
  1431. switch (p[2] & 0x7f) {
  1432. case 0x00: /* Speech */
  1433. case 0x10: /* 3.1 Khz audio */
  1434. pc->para.setup.si1 = 1;
  1435. break;
  1436. case 0x08: /* Unrestricted digital information */
  1437. pc->para.setup.si1 = 7;
  1438. /* JIM, 05.11.97 I wanna set service indicator 2 */
  1439. #ifdef EXT_BEARER_CAPS
  1440. pc->para.setup.si2 = DecodeSI2(skb);
  1441. #endif
  1442. break;
  1443. case 0x09: /* Restricted digital information */
  1444. pc->para.setup.si1 = 2;
  1445. break;
  1446. case 0x11:
  1447. /* Unrestr. digital information with
  1448. * tones/announcements ( or 7 kHz audio
  1449. */
  1450. pc->para.setup.si1 = 3;
  1451. break;
  1452. case 0x18: /* Video */
  1453. pc->para.setup.si1 = 4;
  1454. break;
  1455. default:
  1456. err = 2;
  1457. break;
  1458. }
  1459. switch (p[3] & 0x7f) {
  1460. case 0x40: /* packed mode */
  1461. pc->para.setup.si1 = 8;
  1462. break;
  1463. case 0x10: /* 64 kbit */
  1464. case 0x11: /* 2*64 kbit */
  1465. case 0x13: /* 384 kbit */
  1466. case 0x15: /* 1536 kbit */
  1467. case 0x17: /* 1920 kbit */
  1468. pc->para.moderate = p[3] & 0x7f;
  1469. break;
  1470. default:
  1471. err = 3;
  1472. break;
  1473. }
  1474. }
  1475. if (pc->debug & L3_DEB_SI)
  1476. l3_debug(pc->st, "SI=%d, AI=%d",
  1477. pc->para.setup.si1, pc->para.setup.si2);
  1478. if (err) {
  1479. if (pc->debug & L3_DEB_WARN)
  1480. l3_debug(pc->st, "setup with wrong bearer(l=%d:%x,%x)",
  1481. p[1], p[2], p[3]);
  1482. pc->para.cause = 100;
  1483. l3dss1_msg_without_setup(pc, pr, NULL);
  1484. return;
  1485. }
  1486. } else {
  1487. if (pc->debug & L3_DEB_WARN)
  1488. l3_debug(pc->st, "setup without bearer capabilities");
  1489. /* ETS 300-104 1.3.3 */
  1490. pc->para.cause = 96;
  1491. l3dss1_msg_without_setup(pc, pr, NULL);
  1492. return;
  1493. }
  1494. /*
  1495. * Channel Identification
  1496. */
  1497. if ((id = l3dss1_get_channel_id(pc, skb)) >= 0) {
  1498. if ((pc->para.bchannel = id)) {
  1499. if ((3 == id) && (0x10 == pc->para.moderate)) {
  1500. if (pc->debug & L3_DEB_WARN)
  1501. l3_debug(pc->st, "setup with wrong chid %x",
  1502. id);
  1503. pc->para.cause = 100;
  1504. l3dss1_msg_without_setup(pc, pr, NULL);
  1505. return;
  1506. }
  1507. bcfound++;
  1508. } else
  1509. { if (pc->debug & L3_DEB_WARN)
  1510. l3_debug(pc->st, "setup without bchannel, call waiting");
  1511. bcfound++;
  1512. }
  1513. } else {
  1514. if (pc->debug & L3_DEB_WARN)
  1515. l3_debug(pc->st, "setup with wrong chid ret %d", id);
  1516. if (id == -1)
  1517. pc->para.cause = 96;
  1518. else
  1519. pc->para.cause = 100;
  1520. l3dss1_msg_without_setup(pc, pr, NULL);
  1521. return;
  1522. }
  1523. /* Now we are on none mandatory IEs */
  1524. err = check_infoelements(pc, skb, ie_SETUP);
  1525. if (ERR_IE_COMPREHENSION == err) {
  1526. pc->para.cause = 96;
  1527. l3dss1_msg_without_setup(pc, pr, NULL);
  1528. return;
  1529. }
  1530. p = skb->data;
  1531. if ((p = findie(p, skb->len, 0x70, 0)))
  1532. iecpy(pc->para.setup.eazmsn, p, 1);
  1533. else
  1534. pc->para.setup.eazmsn[0] = 0;
  1535. p = skb->data;
  1536. if ((p = findie(p, skb->len, 0x71, 0))) {
  1537. /* Called party subaddress */
  1538. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1539. tmp[0] = '.';
  1540. iecpy(&tmp[1], p, 2);
  1541. strcat(pc->para.setup.eazmsn, tmp);
  1542. } else if (pc->debug & L3_DEB_WARN)
  1543. l3_debug(pc->st, "wrong called subaddress");
  1544. }
  1545. p = skb->data;
  1546. if ((p = findie(p, skb->len, 0x6c, 0))) {
  1547. pc->para.setup.plan = p[2];
  1548. if (p[2] & 0x80) {
  1549. iecpy(pc->para.setup.phone, p, 1);
  1550. pc->para.setup.screen = 0;
  1551. } else {
  1552. iecpy(pc->para.setup.phone, p, 2);
  1553. pc->para.setup.screen = p[3];
  1554. }
  1555. } else {
  1556. pc->para.setup.phone[0] = 0;
  1557. pc->para.setup.plan = 0;
  1558. pc->para.setup.screen = 0;
  1559. }
  1560. p = skb->data;
  1561. if ((p = findie(p, skb->len, 0x6d, 0))) {
  1562. /* Calling party subaddress */
  1563. if ((p[1] >= 2) && (p[2] == 0x80) && (p[3] == 0x50)) {
  1564. tmp[0] = '.';
  1565. iecpy(&tmp[1], p, 2);
  1566. strcat(pc->para.setup.phone, tmp);
  1567. } else if (pc->debug & L3_DEB_WARN)
  1568. l3_debug(pc->st, "wrong calling subaddress");
  1569. }
  1570. newl3state(pc, 6);
  1571. if (err) /* STATUS for none mandatory IE errors after actions are taken */
  1572. l3dss1_std_ie_err(pc, err);
  1573. pc->st->l3.l3l4(pc->st, CC_SETUP | INDICATION, pc);
  1574. }
  1575. static void
  1576. l3dss1_reset(struct l3_process *pc, u_char pr, void *arg)
  1577. {
  1578. dss1_release_l3_process(pc);
  1579. }
  1580. static void
  1581. l3dss1_disconnect_req(struct l3_process *pc, u_char pr, void *arg)
  1582. {
  1583. struct sk_buff *skb;
  1584. u_char tmp[16 + 40];
  1585. u_char *p = tmp;
  1586. int l;
  1587. u_char cause = 16;
  1588. if (pc->para.cause != NO_CAUSE)
  1589. cause = pc->para.cause;
  1590. StopAllL3Timer(pc);
  1591. MsgHead(p, pc->callref, MT_DISCONNECT);
  1592. *p++ = IE_CAUSE;
  1593. *p++ = 0x2;
  1594. *p++ = 0x80;
  1595. *p++ = cause | 0x80;
  1596. if (pc->prot.dss1.uus1_data[0])
  1597. { *p++ = IE_USER_USER; /* UUS info element */
  1598. *p++ = strlen(pc->prot.dss1.uus1_data) + 1;
  1599. *p++ = 0x04; /* IA5 chars */
  1600. strcpy(p, pc->prot.dss1.uus1_data);
  1601. p += strlen(pc->prot.dss1.uus1_data);
  1602. pc->prot.dss1.uus1_data[0] = '\0';
  1603. }
  1604. l = p - tmp;
  1605. if (!(skb = l3_alloc_skb(l)))
  1606. return;
  1607. skb_put_data(skb, tmp, l);
  1608. newl3state(pc, 11);
  1609. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1610. L3AddTimer(&pc->timer, T305, CC_T305);
  1611. }
  1612. static void
  1613. l3dss1_setup_rsp(struct l3_process *pc, u_char pr,
  1614. void *arg)
  1615. {
  1616. if (!pc->para.bchannel)
  1617. { if (pc->debug & L3_DEB_WARN)
  1618. l3_debug(pc->st, "D-chan connect for waiting call");
  1619. l3dss1_disconnect_req(pc, pr, arg);
  1620. return;
  1621. }
  1622. newl3state(pc, 8);
  1623. l3dss1_message(pc, MT_CONNECT);
  1624. L3DelTimer(&pc->timer);
  1625. L3AddTimer(&pc->timer, T313, CC_T313);
  1626. }
  1627. static void
  1628. l3dss1_connect_ack(struct l3_process *pc, u_char pr, void *arg)
  1629. {
  1630. struct sk_buff *skb = arg;
  1631. int ret;
  1632. ret = check_infoelements(pc, skb, ie_CONNECT_ACKNOWLEDGE);
  1633. if (ERR_IE_COMPREHENSION == ret) {
  1634. l3dss1_std_ie_err(pc, ret);
  1635. return;
  1636. }
  1637. newl3state(pc, 10);
  1638. L3DelTimer(&pc->timer);
  1639. if (ret)
  1640. l3dss1_std_ie_err(pc, ret);
  1641. pc->st->l3.l3l4(pc->st, CC_SETUP_COMPL | INDICATION, pc);
  1642. }
  1643. static void
  1644. l3dss1_reject_req(struct l3_process *pc, u_char pr, void *arg)
  1645. {
  1646. struct sk_buff *skb;
  1647. u_char tmp[16];
  1648. u_char *p = tmp;
  1649. int l;
  1650. u_char cause = 21;
  1651. if (pc->para.cause != NO_CAUSE)
  1652. cause = pc->para.cause;
  1653. MsgHead(p, pc->callref, MT_RELEASE_COMPLETE);
  1654. *p++ = IE_CAUSE;
  1655. *p++ = 0x2;
  1656. *p++ = 0x80;
  1657. *p++ = cause | 0x80;
  1658. l = p - tmp;
  1659. if (!(skb = l3_alloc_skb(l)))
  1660. return;
  1661. skb_put_data(skb, tmp, l);
  1662. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1663. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1664. newl3state(pc, 0);
  1665. dss1_release_l3_process(pc);
  1666. }
  1667. static void
  1668. l3dss1_release(struct l3_process *pc, u_char pr, void *arg)
  1669. {
  1670. struct sk_buff *skb = arg;
  1671. u_char *p;
  1672. int ret, cause = 0;
  1673. StopAllL3Timer(pc);
  1674. if ((ret = l3dss1_get_cause(pc, skb)) > 0) {
  1675. if (pc->debug & L3_DEB_WARN)
  1676. l3_debug(pc->st, "REL get_cause ret(%d)", ret);
  1677. } else if (ret < 0)
  1678. pc->para.cause = NO_CAUSE;
  1679. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  1680. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  1681. }
  1682. if ((ret < 0) && (pc->state != 11))
  1683. cause = 96;
  1684. else if (ret > 0)
  1685. cause = 100;
  1686. ret = check_infoelements(pc, skb, ie_RELEASE);
  1687. if (ERR_IE_COMPREHENSION == ret)
  1688. cause = 96;
  1689. else if ((ERR_IE_UNRECOGNIZED == ret) && (!cause))
  1690. cause = 99;
  1691. if (cause)
  1692. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, cause);
  1693. else
  1694. l3dss1_message(pc, MT_RELEASE_COMPLETE);
  1695. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  1696. newl3state(pc, 0);
  1697. dss1_release_l3_process(pc);
  1698. }
  1699. static void
  1700. l3dss1_alert_req(struct l3_process *pc, u_char pr,
  1701. void *arg)
  1702. {
  1703. newl3state(pc, 7);
  1704. if (!pc->prot.dss1.uus1_data[0])
  1705. l3dss1_message(pc, MT_ALERTING);
  1706. else
  1707. l3dss1_msg_with_uus(pc, MT_ALERTING);
  1708. }
  1709. static void
  1710. l3dss1_proceed_req(struct l3_process *pc, u_char pr,
  1711. void *arg)
  1712. {
  1713. newl3state(pc, 9);
  1714. l3dss1_message(pc, MT_CALL_PROCEEDING);
  1715. pc->st->l3.l3l4(pc->st, CC_PROCEED_SEND | INDICATION, pc);
  1716. }
  1717. static void
  1718. l3dss1_setup_ack_req(struct l3_process *pc, u_char pr,
  1719. void *arg)
  1720. {
  1721. newl3state(pc, 25);
  1722. L3DelTimer(&pc->timer);
  1723. L3AddTimer(&pc->timer, T302, CC_T302);
  1724. l3dss1_message(pc, MT_SETUP_ACKNOWLEDGE);
  1725. }
  1726. /********************************************/
  1727. /* deliver a incoming display message to HL */
  1728. /********************************************/
  1729. static void
  1730. l3dss1_deliver_display(struct l3_process *pc, int pr, u_char *infp)
  1731. { u_char len;
  1732. isdn_ctrl ic;
  1733. struct IsdnCardState *cs;
  1734. char *p;
  1735. if (*infp++ != IE_DISPLAY) return;
  1736. if ((len = *infp++) > 80) return; /* total length <= 82 */
  1737. if (!pc->chan) return;
  1738. p = ic.parm.display;
  1739. while (len--)
  1740. *p++ = *infp++;
  1741. *p = '\0';
  1742. ic.command = ISDN_STAT_DISPLAY;
  1743. cs = pc->st->l1.hardware;
  1744. ic.driver = cs->myid;
  1745. ic.arg = pc->chan->chan;
  1746. cs->iif.statcallb(&ic);
  1747. } /* l3dss1_deliver_display */
  1748. static void
  1749. l3dss1_progress(struct l3_process *pc, u_char pr, void *arg)
  1750. {
  1751. struct sk_buff *skb = arg;
  1752. int err = 0;
  1753. u_char *p;
  1754. if ((p = findie(skb->data, skb->len, IE_PROGRESS, 0))) {
  1755. if (p[1] != 2) {
  1756. err = 1;
  1757. pc->para.cause = 100;
  1758. } else if (!(p[2] & 0x70)) {
  1759. switch (p[2]) {
  1760. case 0x80:
  1761. case 0x81:
  1762. case 0x82:
  1763. case 0x84:
  1764. case 0x85:
  1765. case 0x87:
  1766. case 0x8a:
  1767. switch (p[3]) {
  1768. case 0x81:
  1769. case 0x82:
  1770. case 0x83:
  1771. case 0x84:
  1772. case 0x88:
  1773. break;
  1774. default:
  1775. err = 2;
  1776. pc->para.cause = 100;
  1777. break;
  1778. }
  1779. break;
  1780. default:
  1781. err = 3;
  1782. pc->para.cause = 100;
  1783. break;
  1784. }
  1785. }
  1786. } else {
  1787. pc->para.cause = 96;
  1788. err = 4;
  1789. }
  1790. if (err) {
  1791. if (pc->debug & L3_DEB_WARN)
  1792. l3_debug(pc->st, "progress error %d", err);
  1793. l3dss1_status_send(pc, pr, NULL);
  1794. return;
  1795. }
  1796. /* Now we are on none mandatory IEs */
  1797. err = check_infoelements(pc, skb, ie_PROGRESS);
  1798. if (err)
  1799. l3dss1_std_ie_err(pc, err);
  1800. if (ERR_IE_COMPREHENSION != err)
  1801. pc->st->l3.l3l4(pc->st, CC_PROGRESS | INDICATION, pc);
  1802. }
  1803. static void
  1804. l3dss1_notify(struct l3_process *pc, u_char pr, void *arg)
  1805. {
  1806. struct sk_buff *skb = arg;
  1807. int err = 0;
  1808. u_char *p;
  1809. if ((p = findie(skb->data, skb->len, IE_NOTIFY, 0))) {
  1810. if (p[1] != 1) {
  1811. err = 1;
  1812. pc->para.cause = 100;
  1813. } else {
  1814. switch (p[2]) {
  1815. case 0x80:
  1816. case 0x81:
  1817. case 0x82:
  1818. break;
  1819. default:
  1820. pc->para.cause = 100;
  1821. err = 2;
  1822. break;
  1823. }
  1824. }
  1825. } else {
  1826. pc->para.cause = 96;
  1827. err = 3;
  1828. }
  1829. if (err) {
  1830. if (pc->debug & L3_DEB_WARN)
  1831. l3_debug(pc->st, "notify error %d", err);
  1832. l3dss1_status_send(pc, pr, NULL);
  1833. return;
  1834. }
  1835. /* Now we are on none mandatory IEs */
  1836. err = check_infoelements(pc, skb, ie_NOTIFY);
  1837. if (err)
  1838. l3dss1_std_ie_err(pc, err);
  1839. if (ERR_IE_COMPREHENSION != err)
  1840. pc->st->l3.l3l4(pc->st, CC_NOTIFY | INDICATION, pc);
  1841. }
  1842. static void
  1843. l3dss1_status_enq(struct l3_process *pc, u_char pr, void *arg)
  1844. {
  1845. int ret;
  1846. struct sk_buff *skb = arg;
  1847. ret = check_infoelements(pc, skb, ie_STATUS_ENQUIRY);
  1848. l3dss1_std_ie_err(pc, ret);
  1849. pc->para.cause = 30; /* response to STATUS_ENQUIRY */
  1850. l3dss1_status_send(pc, pr, NULL);
  1851. }
  1852. static void
  1853. l3dss1_information(struct l3_process *pc, u_char pr, void *arg)
  1854. {
  1855. int ret;
  1856. struct sk_buff *skb = arg;
  1857. u_char *p;
  1858. char tmp[32];
  1859. ret = check_infoelements(pc, skb, ie_INFORMATION);
  1860. if (ret)
  1861. l3dss1_std_ie_err(pc, ret);
  1862. if (pc->state == 25) { /* overlap receiving */
  1863. L3DelTimer(&pc->timer);
  1864. p = skb->data;
  1865. if ((p = findie(p, skb->len, 0x70, 0))) {
  1866. iecpy(tmp, p, 1);
  1867. strcat(pc->para.setup.eazmsn, tmp);
  1868. pc->st->l3.l3l4(pc->st, CC_MORE_INFO | INDICATION, pc);
  1869. }
  1870. L3AddTimer(&pc->timer, T302, CC_T302);
  1871. }
  1872. }
  1873. /******************************/
  1874. /* handle deflection requests */
  1875. /******************************/
  1876. static void l3dss1_redir_req(struct l3_process *pc, u_char pr, void *arg)
  1877. {
  1878. struct sk_buff *skb;
  1879. u_char tmp[128];
  1880. u_char *p = tmp;
  1881. u_char *subp;
  1882. u_char len_phone = 0;
  1883. u_char len_sub = 0;
  1884. int l;
  1885. strcpy(pc->prot.dss1.uus1_data, pc->chan->setup.eazmsn); /* copy uus element if available */
  1886. if (!pc->chan->setup.phone[0])
  1887. { pc->para.cause = -1;
  1888. l3dss1_disconnect_req(pc, pr, arg); /* disconnect immediately */
  1889. return;
  1890. } /* only uus */
  1891. if (pc->prot.dss1.invoke_id)
  1892. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  1893. if (!(pc->prot.dss1.invoke_id = new_invoke_id(pc->st)))
  1894. return;
  1895. MsgHead(p, pc->callref, MT_FACILITY);
  1896. for (subp = pc->chan->setup.phone; (*subp) && (*subp != '.'); subp++) len_phone++; /* len of phone number */
  1897. if (*subp++ == '.') len_sub = strlen(subp) + 2; /* length including info subaddress element */
  1898. *p++ = 0x1c; /* Facility info element */
  1899. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3 + 3; /* length of element */
  1900. *p++ = 0x91; /* remote operations protocol */
  1901. *p++ = 0xa1; /* invoke component */
  1902. *p++ = len_phone + len_sub + 2 + 2 + 8 + 3; /* length of data */
  1903. *p++ = 0x02; /* invoke id tag, integer */
  1904. *p++ = 0x01; /* length */
  1905. *p++ = pc->prot.dss1.invoke_id; /* invoke id */
  1906. *p++ = 0x02; /* operation value tag, integer */
  1907. *p++ = 0x01; /* length */
  1908. *p++ = 0x0D; /* Call Deflect */
  1909. *p++ = 0x30; /* sequence phone number */
  1910. *p++ = len_phone + 2 + 2 + 3 + len_sub; /* length */
  1911. *p++ = 0x30; /* Deflected to UserNumber */
  1912. *p++ = len_phone + 2 + len_sub; /* length */
  1913. *p++ = 0x80; /* NumberDigits */
  1914. *p++ = len_phone; /* length */
  1915. for (l = 0; l < len_phone; l++)
  1916. *p++ = pc->chan->setup.phone[l];
  1917. if (len_sub)
  1918. { *p++ = 0x04; /* called party subaddress */
  1919. *p++ = len_sub - 2;
  1920. while (*subp) *p++ = *subp++;
  1921. }
  1922. *p++ = 0x01; /* screening identifier */
  1923. *p++ = 0x01;
  1924. *p++ = pc->chan->setup.screen;
  1925. l = p - tmp;
  1926. if (!(skb = l3_alloc_skb(l))) return;
  1927. skb_put_data(skb, tmp, l);
  1928. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  1929. } /* l3dss1_redir_req */
  1930. /********************************************/
  1931. /* handle deflection request in early state */
  1932. /********************************************/
  1933. static void l3dss1_redir_req_early(struct l3_process *pc, u_char pr, void *arg)
  1934. {
  1935. l3dss1_proceed_req(pc, pr, arg);
  1936. l3dss1_redir_req(pc, pr, arg);
  1937. } /* l3dss1_redir_req_early */
  1938. /***********************************************/
  1939. /* handle special commands for this protocol. */
  1940. /* Examples are call independent services like */
  1941. /* remote operations with dummy callref. */
  1942. /***********************************************/
  1943. static int l3dss1_cmd_global(struct PStack *st, isdn_ctrl *ic)
  1944. { u_char id;
  1945. u_char temp[265];
  1946. u_char *p = temp;
  1947. int i, l, proc_len;
  1948. struct sk_buff *skb;
  1949. struct l3_process *pc = NULL;
  1950. switch (ic->arg)
  1951. { case DSS1_CMD_INVOKE:
  1952. if (ic->parm.dss1_io.datalen < 0) return (-2); /* invalid parameter */
  1953. for (proc_len = 1, i = ic->parm.dss1_io.proc >> 8; i; i++)
  1954. i = i >> 8; /* add one byte */
  1955. l = ic->parm.dss1_io.datalen + proc_len + 8; /* length excluding ie header */
  1956. if (l > 255)
  1957. return (-2); /* too long */
  1958. if (!(id = new_invoke_id(st)))
  1959. return (0); /* first get a invoke id -> return if no available */
  1960. i = -1;
  1961. MsgHead(p, i, MT_FACILITY); /* build message head */
  1962. *p++ = 0x1C; /* Facility IE */
  1963. *p++ = l; /* length of ie */
  1964. *p++ = 0x91; /* remote operations */
  1965. *p++ = 0xA1; /* invoke */
  1966. *p++ = l - 3; /* length of invoke */
  1967. *p++ = 0x02; /* invoke id tag */
  1968. *p++ = 0x01; /* length is 1 */
  1969. *p++ = id; /* invoke id */
  1970. *p++ = 0x02; /* operation */
  1971. *p++ = proc_len; /* length of operation */
  1972. for (i = proc_len; i; i--)
  1973. *p++ = (ic->parm.dss1_io.proc >> (i - 1)) & 0xFF;
  1974. memcpy(p, ic->parm.dss1_io.data, ic->parm.dss1_io.datalen); /* copy data */
  1975. l = (p - temp) + ic->parm.dss1_io.datalen; /* total length */
  1976. if (ic->parm.dss1_io.timeout > 0)
  1977. if (!(pc = dss1_new_l3_process(st, -1)))
  1978. { free_invoke_id(st, id);
  1979. return (-2);
  1980. }
  1981. pc->prot.dss1.ll_id = ic->parm.dss1_io.ll_id; /* remember id */
  1982. pc->prot.dss1.proc = ic->parm.dss1_io.proc; /* and procedure */
  1983. if (!(skb = l3_alloc_skb(l)))
  1984. { free_invoke_id(st, id);
  1985. if (pc) dss1_release_l3_process(pc);
  1986. return (-2);
  1987. }
  1988. skb_put_data(skb, temp, l);
  1989. if (pc)
  1990. { pc->prot.dss1.invoke_id = id; /* remember id */
  1991. L3AddTimer(&pc->timer, ic->parm.dss1_io.timeout, CC_TDSS1_IO | REQUEST);
  1992. }
  1993. l3_msg(st, DL_DATA | REQUEST, skb);
  1994. ic->parm.dss1_io.hl_id = id; /* return id */
  1995. return (0);
  1996. case DSS1_CMD_INVOKE_ABORT:
  1997. if ((pc = l3dss1_search_dummy_proc(st, ic->parm.dss1_io.hl_id)))
  1998. { L3DelTimer(&pc->timer); /* remove timer */
  1999. dss1_release_l3_process(pc);
  2000. return (0);
  2001. }
  2002. else
  2003. { l3_debug(st, "l3dss1_cmd_global abort unknown id");
  2004. return (-2);
  2005. }
  2006. break;
  2007. default:
  2008. l3_debug(st, "l3dss1_cmd_global unknown cmd 0x%lx", ic->arg);
  2009. return (-1);
  2010. } /* switch ic-> arg */
  2011. return (-1);
  2012. } /* l3dss1_cmd_global */
  2013. static void
  2014. l3dss1_io_timer(struct l3_process *pc)
  2015. { isdn_ctrl ic;
  2016. struct IsdnCardState *cs = pc->st->l1.hardware;
  2017. L3DelTimer(&pc->timer); /* remove timer */
  2018. ic.driver = cs->myid;
  2019. ic.command = ISDN_STAT_PROT;
  2020. ic.arg = DSS1_STAT_INVOKE_ERR;
  2021. ic.parm.dss1_io.hl_id = pc->prot.dss1.invoke_id;
  2022. ic.parm.dss1_io.ll_id = pc->prot.dss1.ll_id;
  2023. ic.parm.dss1_io.proc = pc->prot.dss1.proc;
  2024. ic.parm.dss1_io.timeout = -1;
  2025. ic.parm.dss1_io.datalen = 0;
  2026. ic.parm.dss1_io.data = NULL;
  2027. free_invoke_id(pc->st, pc->prot.dss1.invoke_id);
  2028. pc->prot.dss1.invoke_id = 0; /* reset id */
  2029. cs->iif.statcallb(&ic);
  2030. dss1_release_l3_process(pc);
  2031. } /* l3dss1_io_timer */
  2032. static void
  2033. l3dss1_release_ind(struct l3_process *pc, u_char pr, void *arg)
  2034. {
  2035. u_char *p;
  2036. struct sk_buff *skb = arg;
  2037. int callState = 0;
  2038. p = skb->data;
  2039. if ((p = findie(p, skb->len, IE_CALL_STATE, 0))) {
  2040. p++;
  2041. if (1 == *p++)
  2042. callState = *p;
  2043. }
  2044. if (callState == 0) {
  2045. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1... and 16.1
  2046. * set down layer 3 without sending any message
  2047. */
  2048. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2049. newl3state(pc, 0);
  2050. dss1_release_l3_process(pc);
  2051. } else {
  2052. pc->st->l3.l3l4(pc->st, CC_IGNORE | INDICATION, pc);
  2053. }
  2054. }
  2055. static void
  2056. l3dss1_dummy(struct l3_process *pc, u_char pr, void *arg)
  2057. {
  2058. }
  2059. static void
  2060. l3dss1_t302(struct l3_process *pc, u_char pr, void *arg)
  2061. {
  2062. L3DelTimer(&pc->timer);
  2063. pc->para.loc = 0;
  2064. pc->para.cause = 28; /* invalid number */
  2065. l3dss1_disconnect_req(pc, pr, NULL);
  2066. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2067. }
  2068. static void
  2069. l3dss1_t303(struct l3_process *pc, u_char pr, void *arg)
  2070. {
  2071. if (pc->N303 > 0) {
  2072. pc->N303--;
  2073. L3DelTimer(&pc->timer);
  2074. l3dss1_setup_req(pc, pr, arg);
  2075. } else {
  2076. L3DelTimer(&pc->timer);
  2077. l3dss1_message_cause(pc, MT_RELEASE_COMPLETE, 102);
  2078. pc->st->l3.l3l4(pc->st, CC_NOSETUP_RSP, pc);
  2079. dss1_release_l3_process(pc);
  2080. }
  2081. }
  2082. static void
  2083. l3dss1_t304(struct l3_process *pc, u_char pr, void *arg)
  2084. {
  2085. L3DelTimer(&pc->timer);
  2086. pc->para.loc = 0;
  2087. pc->para.cause = 102;
  2088. l3dss1_disconnect_req(pc, pr, NULL);
  2089. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2090. }
  2091. static void
  2092. l3dss1_t305(struct l3_process *pc, u_char pr, void *arg)
  2093. {
  2094. u_char tmp[16];
  2095. u_char *p = tmp;
  2096. int l;
  2097. struct sk_buff *skb;
  2098. u_char cause = 16;
  2099. L3DelTimer(&pc->timer);
  2100. if (pc->para.cause != NO_CAUSE)
  2101. cause = pc->para.cause;
  2102. MsgHead(p, pc->callref, MT_RELEASE);
  2103. *p++ = IE_CAUSE;
  2104. *p++ = 0x2;
  2105. *p++ = 0x80;
  2106. *p++ = cause | 0x80;
  2107. l = p - tmp;
  2108. if (!(skb = l3_alloc_skb(l)))
  2109. return;
  2110. skb_put_data(skb, tmp, l);
  2111. newl3state(pc, 19);
  2112. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2113. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2114. }
  2115. static void
  2116. l3dss1_t310(struct l3_process *pc, u_char pr, void *arg)
  2117. {
  2118. L3DelTimer(&pc->timer);
  2119. pc->para.loc = 0;
  2120. pc->para.cause = 102;
  2121. l3dss1_disconnect_req(pc, pr, NULL);
  2122. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2123. }
  2124. static void
  2125. l3dss1_t313(struct l3_process *pc, u_char pr, void *arg)
  2126. {
  2127. L3DelTimer(&pc->timer);
  2128. pc->para.loc = 0;
  2129. pc->para.cause = 102;
  2130. l3dss1_disconnect_req(pc, pr, NULL);
  2131. pc->st->l3.l3l4(pc->st, CC_CONNECT_ERR, pc);
  2132. }
  2133. static void
  2134. l3dss1_t308_1(struct l3_process *pc, u_char pr, void *arg)
  2135. {
  2136. newl3state(pc, 19);
  2137. L3DelTimer(&pc->timer);
  2138. l3dss1_message(pc, MT_RELEASE);
  2139. L3AddTimer(&pc->timer, T308, CC_T308_2);
  2140. }
  2141. static void
  2142. l3dss1_t308_2(struct l3_process *pc, u_char pr, void *arg)
  2143. {
  2144. L3DelTimer(&pc->timer);
  2145. pc->st->l3.l3l4(pc->st, CC_RELEASE_ERR, pc);
  2146. dss1_release_l3_process(pc);
  2147. }
  2148. static void
  2149. l3dss1_t318(struct l3_process *pc, u_char pr, void *arg)
  2150. {
  2151. L3DelTimer(&pc->timer);
  2152. pc->para.cause = 102; /* Timer expiry */
  2153. pc->para.loc = 0; /* local */
  2154. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2155. newl3state(pc, 19);
  2156. l3dss1_message(pc, MT_RELEASE);
  2157. L3AddTimer(&pc->timer, T308, CC_T308_1);
  2158. }
  2159. static void
  2160. l3dss1_t319(struct l3_process *pc, u_char pr, void *arg)
  2161. {
  2162. L3DelTimer(&pc->timer);
  2163. pc->para.cause = 102; /* Timer expiry */
  2164. pc->para.loc = 0; /* local */
  2165. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2166. newl3state(pc, 10);
  2167. }
  2168. static void
  2169. l3dss1_restart(struct l3_process *pc, u_char pr, void *arg)
  2170. {
  2171. L3DelTimer(&pc->timer);
  2172. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2173. dss1_release_l3_process(pc);
  2174. }
  2175. static void
  2176. l3dss1_status(struct l3_process *pc, u_char pr, void *arg)
  2177. {
  2178. u_char *p;
  2179. struct sk_buff *skb = arg;
  2180. int ret;
  2181. u_char cause = 0, callState = 0;
  2182. if ((ret = l3dss1_get_cause(pc, skb))) {
  2183. if (pc->debug & L3_DEB_WARN)
  2184. l3_debug(pc->st, "STATUS get_cause ret(%d)", ret);
  2185. if (ret < 0)
  2186. cause = 96;
  2187. else if (ret > 0)
  2188. cause = 100;
  2189. }
  2190. if ((p = findie(skb->data, skb->len, IE_CALL_STATE, 0))) {
  2191. p++;
  2192. if (1 == *p++) {
  2193. callState = *p;
  2194. if (!ie_in_set(pc, *p, l3_valid_states))
  2195. cause = 100;
  2196. } else
  2197. cause = 100;
  2198. } else
  2199. cause = 96;
  2200. if (!cause) { /* no error before */
  2201. ret = check_infoelements(pc, skb, ie_STATUS);
  2202. if (ERR_IE_COMPREHENSION == ret)
  2203. cause = 96;
  2204. else if (ERR_IE_UNRECOGNIZED == ret)
  2205. cause = 99;
  2206. }
  2207. if (cause) {
  2208. u_char tmp;
  2209. if (pc->debug & L3_DEB_WARN)
  2210. l3_debug(pc->st, "STATUS error(%d/%d)", ret, cause);
  2211. tmp = pc->para.cause;
  2212. pc->para.cause = cause;
  2213. l3dss1_status_send(pc, 0, NULL);
  2214. if (cause == 99)
  2215. pc->para.cause = tmp;
  2216. else
  2217. return;
  2218. }
  2219. cause = pc->para.cause;
  2220. if (((cause & 0x7f) == 111) && (callState == 0)) {
  2221. /* ETS 300-104 7.6.1, 8.6.1, 10.6.1...
  2222. * if received MT_STATUS with cause == 111 and call
  2223. * state == 0, then we must set down layer 3
  2224. */
  2225. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2226. newl3state(pc, 0);
  2227. dss1_release_l3_process(pc);
  2228. }
  2229. }
  2230. static void
  2231. l3dss1_facility(struct l3_process *pc, u_char pr, void *arg)
  2232. {
  2233. struct sk_buff *skb = arg;
  2234. int ret;
  2235. ret = check_infoelements(pc, skb, ie_FACILITY);
  2236. l3dss1_std_ie_err(pc, ret);
  2237. {
  2238. u_char *p;
  2239. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0)))
  2240. l3dss1_parse_facility(pc->st, pc, pc->callref, p);
  2241. }
  2242. }
  2243. static void
  2244. l3dss1_suspend_req(struct l3_process *pc, u_char pr, void *arg)
  2245. {
  2246. struct sk_buff *skb;
  2247. u_char tmp[32];
  2248. u_char *p = tmp;
  2249. u_char i, l;
  2250. u_char *msg = pc->chan->setup.phone;
  2251. MsgHead(p, pc->callref, MT_SUSPEND);
  2252. l = *msg++;
  2253. if (l && (l <= 10)) { /* Max length 10 octets */
  2254. *p++ = IE_CALL_ID;
  2255. *p++ = l;
  2256. for (i = 0; i < l; i++)
  2257. *p++ = *msg++;
  2258. } else if (l) {
  2259. l3_debug(pc->st, "SUS wrong CALL_ID len %d", l);
  2260. return;
  2261. }
  2262. l = p - tmp;
  2263. if (!(skb = l3_alloc_skb(l)))
  2264. return;
  2265. skb_put_data(skb, tmp, l);
  2266. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2267. newl3state(pc, 15);
  2268. L3AddTimer(&pc->timer, T319, CC_T319);
  2269. }
  2270. static void
  2271. l3dss1_suspend_ack(struct l3_process *pc, u_char pr, void *arg)
  2272. {
  2273. struct sk_buff *skb = arg;
  2274. int ret;
  2275. L3DelTimer(&pc->timer);
  2276. newl3state(pc, 0);
  2277. pc->para.cause = NO_CAUSE;
  2278. pc->st->l3.l3l4(pc->st, CC_SUSPEND | CONFIRM, pc);
  2279. /* We don't handle suspend_ack for IE errors now */
  2280. if ((ret = check_infoelements(pc, skb, ie_SUSPEND_ACKNOWLEDGE)))
  2281. if (pc->debug & L3_DEB_WARN)
  2282. l3_debug(pc->st, "SUSPACK check ie(%d)", ret);
  2283. dss1_release_l3_process(pc);
  2284. }
  2285. static void
  2286. l3dss1_suspend_rej(struct l3_process *pc, u_char pr, void *arg)
  2287. {
  2288. struct sk_buff *skb = arg;
  2289. int ret;
  2290. if ((ret = l3dss1_get_cause(pc, skb))) {
  2291. if (pc->debug & L3_DEB_WARN)
  2292. l3_debug(pc->st, "SUSP_REJ get_cause ret(%d)", ret);
  2293. if (ret < 0)
  2294. pc->para.cause = 96;
  2295. else
  2296. pc->para.cause = 100;
  2297. l3dss1_status_send(pc, pr, NULL);
  2298. return;
  2299. }
  2300. ret = check_infoelements(pc, skb, ie_SUSPEND_REJECT);
  2301. if (ERR_IE_COMPREHENSION == ret) {
  2302. l3dss1_std_ie_err(pc, ret);
  2303. return;
  2304. }
  2305. L3DelTimer(&pc->timer);
  2306. pc->st->l3.l3l4(pc->st, CC_SUSPEND_ERR, pc);
  2307. newl3state(pc, 10);
  2308. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2309. l3dss1_std_ie_err(pc, ret);
  2310. }
  2311. static void
  2312. l3dss1_resume_req(struct l3_process *pc, u_char pr, void *arg)
  2313. {
  2314. struct sk_buff *skb;
  2315. u_char tmp[32];
  2316. u_char *p = tmp;
  2317. u_char i, l;
  2318. u_char *msg = pc->para.setup.phone;
  2319. MsgHead(p, pc->callref, MT_RESUME);
  2320. l = *msg++;
  2321. if (l && (l <= 10)) { /* Max length 10 octets */
  2322. *p++ = IE_CALL_ID;
  2323. *p++ = l;
  2324. for (i = 0; i < l; i++)
  2325. *p++ = *msg++;
  2326. } else if (l) {
  2327. l3_debug(pc->st, "RES wrong CALL_ID len %d", l);
  2328. return;
  2329. }
  2330. l = p - tmp;
  2331. if (!(skb = l3_alloc_skb(l)))
  2332. return;
  2333. skb_put_data(skb, tmp, l);
  2334. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2335. newl3state(pc, 17);
  2336. L3AddTimer(&pc->timer, T318, CC_T318);
  2337. }
  2338. static void
  2339. l3dss1_resume_ack(struct l3_process *pc, u_char pr, void *arg)
  2340. {
  2341. struct sk_buff *skb = arg;
  2342. int id, ret;
  2343. if ((id = l3dss1_get_channel_id(pc, skb)) > 0) {
  2344. if ((0 == id) || ((3 == id) && (0x10 == pc->para.moderate))) {
  2345. if (pc->debug & L3_DEB_WARN)
  2346. l3_debug(pc->st, "resume ack with wrong chid %x", id);
  2347. pc->para.cause = 100;
  2348. l3dss1_status_send(pc, pr, NULL);
  2349. return;
  2350. }
  2351. pc->para.bchannel = id;
  2352. } else if (1 == pc->state) {
  2353. if (pc->debug & L3_DEB_WARN)
  2354. l3_debug(pc->st, "resume ack without chid (ret %d)", id);
  2355. pc->para.cause = 96;
  2356. l3dss1_status_send(pc, pr, NULL);
  2357. return;
  2358. }
  2359. ret = check_infoelements(pc, skb, ie_RESUME_ACKNOWLEDGE);
  2360. if (ERR_IE_COMPREHENSION == ret) {
  2361. l3dss1_std_ie_err(pc, ret);
  2362. return;
  2363. }
  2364. L3DelTimer(&pc->timer);
  2365. pc->st->l3.l3l4(pc->st, CC_RESUME | CONFIRM, pc);
  2366. newl3state(pc, 10);
  2367. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2368. l3dss1_std_ie_err(pc, ret);
  2369. }
  2370. static void
  2371. l3dss1_resume_rej(struct l3_process *pc, u_char pr, void *arg)
  2372. {
  2373. struct sk_buff *skb = arg;
  2374. int ret;
  2375. if ((ret = l3dss1_get_cause(pc, skb))) {
  2376. if (pc->debug & L3_DEB_WARN)
  2377. l3_debug(pc->st, "RES_REJ get_cause ret(%d)", ret);
  2378. if (ret < 0)
  2379. pc->para.cause = 96;
  2380. else
  2381. pc->para.cause = 100;
  2382. l3dss1_status_send(pc, pr, NULL);
  2383. return;
  2384. }
  2385. ret = check_infoelements(pc, skb, ie_RESUME_REJECT);
  2386. if (ERR_IE_COMPREHENSION == ret) {
  2387. l3dss1_std_ie_err(pc, ret);
  2388. return;
  2389. }
  2390. L3DelTimer(&pc->timer);
  2391. pc->st->l3.l3l4(pc->st, CC_RESUME_ERR, pc);
  2392. newl3state(pc, 0);
  2393. if (ret) /* STATUS for none mandatory IE errors after actions are taken */
  2394. l3dss1_std_ie_err(pc, ret);
  2395. dss1_release_l3_process(pc);
  2396. }
  2397. static void
  2398. l3dss1_global_restart(struct l3_process *pc, u_char pr, void *arg)
  2399. {
  2400. u_char tmp[32];
  2401. u_char *p;
  2402. u_char ri, ch = 0, chan = 0;
  2403. int l;
  2404. struct sk_buff *skb = arg;
  2405. struct l3_process *up;
  2406. newl3state(pc, 2);
  2407. L3DelTimer(&pc->timer);
  2408. p = skb->data;
  2409. if ((p = findie(p, skb->len, IE_RESTART_IND, 0))) {
  2410. ri = p[2];
  2411. l3_debug(pc->st, "Restart %x", ri);
  2412. } else {
  2413. l3_debug(pc->st, "Restart without restart IE");
  2414. ri = 0x86;
  2415. }
  2416. p = skb->data;
  2417. if ((p = findie(p, skb->len, IE_CHANNEL_ID, 0))) {
  2418. chan = p[2] & 3;
  2419. ch = p[2];
  2420. if (pc->st->l3.debug)
  2421. l3_debug(pc->st, "Restart for channel %d", chan);
  2422. }
  2423. newl3state(pc, 2);
  2424. up = pc->st->l3.proc;
  2425. while (up) {
  2426. if ((ri & 7) == 7)
  2427. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2428. else if (up->para.bchannel == chan)
  2429. up->st->lli.l4l3(up->st, CC_RESTART | REQUEST, up);
  2430. up = up->next;
  2431. }
  2432. p = tmp;
  2433. MsgHead(p, pc->callref, MT_RESTART_ACKNOWLEDGE);
  2434. if (chan) {
  2435. *p++ = IE_CHANNEL_ID;
  2436. *p++ = 1;
  2437. *p++ = ch | 0x80;
  2438. }
  2439. *p++ = 0x79; /* RESTART Ind */
  2440. *p++ = 1;
  2441. *p++ = ri;
  2442. l = p - tmp;
  2443. if (!(skb = l3_alloc_skb(l)))
  2444. return;
  2445. skb_put_data(skb, tmp, l);
  2446. newl3state(pc, 0);
  2447. l3_msg(pc->st, DL_DATA | REQUEST, skb);
  2448. }
  2449. static void
  2450. l3dss1_dl_reset(struct l3_process *pc, u_char pr, void *arg)
  2451. {
  2452. pc->para.cause = 0x29; /* Temporary failure */
  2453. pc->para.loc = 0;
  2454. l3dss1_disconnect_req(pc, pr, NULL);
  2455. pc->st->l3.l3l4(pc->st, CC_SETUP_ERR, pc);
  2456. }
  2457. static void
  2458. l3dss1_dl_release(struct l3_process *pc, u_char pr, void *arg)
  2459. {
  2460. newl3state(pc, 0);
  2461. pc->para.cause = 0x1b; /* Destination out of order */
  2462. pc->para.loc = 0;
  2463. pc->st->l3.l3l4(pc->st, CC_RELEASE | INDICATION, pc);
  2464. release_l3_process(pc);
  2465. }
  2466. static void
  2467. l3dss1_dl_reestablish(struct l3_process *pc, u_char pr, void *arg)
  2468. {
  2469. L3DelTimer(&pc->timer);
  2470. L3AddTimer(&pc->timer, T309, CC_T309);
  2471. l3_msg(pc->st, DL_ESTABLISH | REQUEST, NULL);
  2472. }
  2473. static void
  2474. l3dss1_dl_reest_status(struct l3_process *pc, u_char pr, void *arg)
  2475. {
  2476. L3DelTimer(&pc->timer);
  2477. pc->para.cause = 0x1F; /* normal, unspecified */
  2478. l3dss1_status_send(pc, 0, NULL);
  2479. }
  2480. /* *INDENT-OFF* */
  2481. static struct stateentry downstatelist[] =
  2482. {
  2483. {SBIT(0),
  2484. CC_SETUP | REQUEST, l3dss1_setup_req},
  2485. {SBIT(0),
  2486. CC_RESUME | REQUEST, l3dss1_resume_req},
  2487. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(25),
  2488. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2489. {SBIT(12),
  2490. CC_RELEASE | REQUEST, l3dss1_release_req},
  2491. {ALL_STATES,
  2492. CC_RESTART | REQUEST, l3dss1_restart},
  2493. {SBIT(6) | SBIT(25),
  2494. CC_IGNORE | REQUEST, l3dss1_reset},
  2495. {SBIT(6) | SBIT(25),
  2496. CC_REJECT | REQUEST, l3dss1_reject_req},
  2497. {SBIT(6) | SBIT(25),
  2498. CC_PROCEED_SEND | REQUEST, l3dss1_proceed_req},
  2499. {SBIT(6),
  2500. CC_MORE_INFO | REQUEST, l3dss1_setup_ack_req},
  2501. {SBIT(25),
  2502. CC_MORE_INFO | REQUEST, l3dss1_dummy},
  2503. {SBIT(6) | SBIT(9) | SBIT(25),
  2504. CC_ALERTING | REQUEST, l3dss1_alert_req},
  2505. {SBIT(6) | SBIT(7) | SBIT(9) | SBIT(25),
  2506. CC_SETUP | RESPONSE, l3dss1_setup_rsp},
  2507. {SBIT(10),
  2508. CC_SUSPEND | REQUEST, l3dss1_suspend_req},
  2509. {SBIT(7) | SBIT(9) | SBIT(25),
  2510. CC_REDIR | REQUEST, l3dss1_redir_req},
  2511. {SBIT(6),
  2512. CC_REDIR | REQUEST, l3dss1_redir_req_early},
  2513. {SBIT(9) | SBIT(25),
  2514. CC_DISCONNECT | REQUEST, l3dss1_disconnect_req},
  2515. {SBIT(25),
  2516. CC_T302, l3dss1_t302},
  2517. {SBIT(1),
  2518. CC_T303, l3dss1_t303},
  2519. {SBIT(2),
  2520. CC_T304, l3dss1_t304},
  2521. {SBIT(3),
  2522. CC_T310, l3dss1_t310},
  2523. {SBIT(8),
  2524. CC_T313, l3dss1_t313},
  2525. {SBIT(11),
  2526. CC_T305, l3dss1_t305},
  2527. {SBIT(15),
  2528. CC_T319, l3dss1_t319},
  2529. {SBIT(17),
  2530. CC_T318, l3dss1_t318},
  2531. {SBIT(19),
  2532. CC_T308_1, l3dss1_t308_1},
  2533. {SBIT(19),
  2534. CC_T308_2, l3dss1_t308_2},
  2535. {SBIT(10),
  2536. CC_T309, l3dss1_dl_release},
  2537. };
  2538. static struct stateentry datastatelist[] =
  2539. {
  2540. {ALL_STATES,
  2541. MT_STATUS_ENQUIRY, l3dss1_status_enq},
  2542. {ALL_STATES,
  2543. MT_FACILITY, l3dss1_facility},
  2544. {SBIT(19),
  2545. MT_STATUS, l3dss1_release_ind},
  2546. {ALL_STATES,
  2547. MT_STATUS, l3dss1_status},
  2548. {SBIT(0),
  2549. MT_SETUP, l3dss1_setup},
  2550. {SBIT(6) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(12) |
  2551. SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2552. MT_SETUP, l3dss1_dummy},
  2553. {SBIT(1) | SBIT(2),
  2554. MT_CALL_PROCEEDING, l3dss1_call_proc},
  2555. {SBIT(1),
  2556. MT_SETUP_ACKNOWLEDGE, l3dss1_setup_ack},
  2557. {SBIT(2) | SBIT(3),
  2558. MT_ALERTING, l3dss1_alerting},
  2559. {SBIT(2) | SBIT(3),
  2560. MT_PROGRESS, l3dss1_progress},
  2561. {SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) |
  2562. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2563. MT_INFORMATION, l3dss1_information},
  2564. {SBIT(10) | SBIT(11) | SBIT(15),
  2565. MT_NOTIFY, l3dss1_notify},
  2566. {SBIT(0) | SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(10) |
  2567. SBIT(11) | SBIT(12) | SBIT(15) | SBIT(17) | SBIT(19) | SBIT(25),
  2568. MT_RELEASE_COMPLETE, l3dss1_release_cmpl},
  2569. {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),
  2570. MT_RELEASE, l3dss1_release},
  2571. {SBIT(19), MT_RELEASE, l3dss1_release_ind},
  2572. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4) | SBIT(7) | SBIT(8) | SBIT(9) | SBIT(10) | SBIT(11) | SBIT(15) | SBIT(17) | SBIT(25),
  2573. MT_DISCONNECT, l3dss1_disconnect},
  2574. {SBIT(19),
  2575. MT_DISCONNECT, l3dss1_dummy},
  2576. {SBIT(1) | SBIT(2) | SBIT(3) | SBIT(4),
  2577. MT_CONNECT, l3dss1_connect},
  2578. {SBIT(8),
  2579. MT_CONNECT_ACKNOWLEDGE, l3dss1_connect_ack},
  2580. {SBIT(15),
  2581. MT_SUSPEND_ACKNOWLEDGE, l3dss1_suspend_ack},
  2582. {SBIT(15),
  2583. MT_SUSPEND_REJECT, l3dss1_suspend_rej},
  2584. {SBIT(17),
  2585. MT_RESUME_ACKNOWLEDGE, l3dss1_resume_ack},
  2586. {SBIT(17),
  2587. MT_RESUME_REJECT, l3dss1_resume_rej},
  2588. };
  2589. static struct stateentry globalmes_list[] =
  2590. {
  2591. {ALL_STATES,
  2592. MT_STATUS, l3dss1_status},
  2593. {SBIT(0),
  2594. MT_RESTART, l3dss1_global_restart},
  2595. /* {SBIT(1),
  2596. MT_RESTART_ACKNOWLEDGE, l3dss1_restart_ack},
  2597. */
  2598. };
  2599. static struct stateentry manstatelist[] =
  2600. {
  2601. {SBIT(2),
  2602. DL_ESTABLISH | INDICATION, l3dss1_dl_reset},
  2603. {SBIT(10),
  2604. DL_ESTABLISH | CONFIRM, l3dss1_dl_reest_status},
  2605. {SBIT(10),
  2606. DL_RELEASE | INDICATION, l3dss1_dl_reestablish},
  2607. {ALL_STATES,
  2608. DL_RELEASE | INDICATION, l3dss1_dl_release},
  2609. };
  2610. /* *INDENT-ON* */
  2611. static void
  2612. global_handler(struct PStack *st, int mt, struct sk_buff *skb)
  2613. {
  2614. u_char tmp[16];
  2615. u_char *p = tmp;
  2616. int l;
  2617. int i;
  2618. struct l3_process *proc = st->l3.global;
  2619. proc->callref = skb->data[2]; /* cr flag */
  2620. for (i = 0; i < ARRAY_SIZE(globalmes_list); i++)
  2621. if ((mt == globalmes_list[i].primitive) &&
  2622. ((1 << proc->state) & globalmes_list[i].state))
  2623. break;
  2624. if (i == ARRAY_SIZE(globalmes_list)) {
  2625. if (st->l3.debug & L3_DEB_STATE) {
  2626. l3_debug(st, "dss1 global state %d mt %x unhandled",
  2627. proc->state, mt);
  2628. }
  2629. MsgHead(p, proc->callref, MT_STATUS);
  2630. *p++ = IE_CAUSE;
  2631. *p++ = 0x2;
  2632. *p++ = 0x80;
  2633. *p++ = 81 | 0x80; /* invalid cr */
  2634. *p++ = 0x14; /* CallState */
  2635. *p++ = 0x1;
  2636. *p++ = proc->state & 0x3f;
  2637. l = p - tmp;
  2638. if (!(skb = l3_alloc_skb(l)))
  2639. return;
  2640. skb_put_data(skb, tmp, l);
  2641. l3_msg(proc->st, DL_DATA | REQUEST, skb);
  2642. } else {
  2643. if (st->l3.debug & L3_DEB_STATE) {
  2644. l3_debug(st, "dss1 global %d mt %x",
  2645. proc->state, mt);
  2646. }
  2647. globalmes_list[i].rout(proc, mt, skb);
  2648. }
  2649. }
  2650. static void
  2651. dss1up(struct PStack *st, int pr, void *arg)
  2652. {
  2653. int i, mt, cr, callState;
  2654. char *ptr;
  2655. u_char *p;
  2656. struct sk_buff *skb = arg;
  2657. struct l3_process *proc;
  2658. switch (pr) {
  2659. case (DL_DATA | INDICATION):
  2660. case (DL_UNIT_DATA | INDICATION):
  2661. break;
  2662. case (DL_ESTABLISH | CONFIRM):
  2663. case (DL_ESTABLISH | INDICATION):
  2664. case (DL_RELEASE | INDICATION):
  2665. case (DL_RELEASE | CONFIRM):
  2666. l3_msg(st, pr, arg);
  2667. return;
  2668. break;
  2669. default:
  2670. printk(KERN_ERR "HiSax dss1up unknown pr=%04x\n", pr);
  2671. return;
  2672. }
  2673. if (skb->len < 3) {
  2674. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2675. dev_kfree_skb(skb);
  2676. return;
  2677. }
  2678. if (skb->data[0] != PROTO_DIS_EURO) {
  2679. if (st->l3.debug & L3_DEB_PROTERR) {
  2680. l3_debug(st, "dss1up%sunexpected discriminator %x message len %d",
  2681. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2682. skb->data[0], skb->len);
  2683. }
  2684. dev_kfree_skb(skb);
  2685. return;
  2686. }
  2687. cr = getcallref(skb->data);
  2688. if (skb->len < ((skb->data[1] & 0x0f) + 3)) {
  2689. l3_debug(st, "dss1up frame too short(%d)", skb->len);
  2690. dev_kfree_skb(skb);
  2691. return;
  2692. }
  2693. mt = skb->data[skb->data[1] + 2];
  2694. if (st->l3.debug & L3_DEB_STATE)
  2695. l3_debug(st, "dss1up cr %d", cr);
  2696. if (cr == -2) { /* wrong Callref */
  2697. if (st->l3.debug & L3_DEB_WARN)
  2698. l3_debug(st, "dss1up wrong Callref");
  2699. dev_kfree_skb(skb);
  2700. return;
  2701. } else if (cr == -1) { /* Dummy Callref */
  2702. if (mt == MT_FACILITY)
  2703. if ((p = findie(skb->data, skb->len, IE_FACILITY, 0))) {
  2704. l3dss1_parse_facility(st, NULL,
  2705. (pr == (DL_DATA | INDICATION)) ? -1 : -2, p);
  2706. dev_kfree_skb(skb);
  2707. return;
  2708. }
  2709. if (st->l3.debug & L3_DEB_WARN)
  2710. l3_debug(st, "dss1up dummy Callref (no facility msg or ie)");
  2711. dev_kfree_skb(skb);
  2712. return;
  2713. } else if ((((skb->data[1] & 0x0f) == 1) && (0 == (cr & 0x7f))) ||
  2714. (((skb->data[1] & 0x0f) == 2) && (0 == (cr & 0x7fff)))) { /* Global CallRef */
  2715. if (st->l3.debug & L3_DEB_STATE)
  2716. l3_debug(st, "dss1up Global CallRef");
  2717. global_handler(st, mt, skb);
  2718. dev_kfree_skb(skb);
  2719. return;
  2720. } else if (!(proc = getl3proc(st, cr))) {
  2721. /* No transaction process exist, that means no call with
  2722. * this callreference is active
  2723. */
  2724. if (mt == MT_SETUP) {
  2725. /* Setup creates a new transaction process */
  2726. if (skb->data[2] & 0x80) {
  2727. /* Setup with wrong CREF flag */
  2728. if (st->l3.debug & L3_DEB_STATE)
  2729. l3_debug(st, "dss1up wrong CRef flag");
  2730. dev_kfree_skb(skb);
  2731. return;
  2732. }
  2733. if (!(proc = dss1_new_l3_process(st, cr))) {
  2734. /* May be to answer with RELEASE_COMPLETE and
  2735. * CAUSE 0x2f "Resource unavailable", but this
  2736. * need a new_l3_process too ... arghh
  2737. */
  2738. dev_kfree_skb(skb);
  2739. return;
  2740. }
  2741. } else if (mt == MT_STATUS) {
  2742. if ((ptr = findie(skb->data, skb->len, IE_CAUSE, 0)) != NULL) {
  2743. ptr++;
  2744. if (*ptr++ == 2)
  2745. ptr++;
  2746. }
  2747. callState = 0;
  2748. if ((ptr = findie(skb->data, skb->len, IE_CALL_STATE, 0)) != NULL) {
  2749. ptr++;
  2750. if (*ptr++ == 2)
  2751. ptr++;
  2752. callState = *ptr;
  2753. }
  2754. /* ETS 300-104 part 2.4.1
  2755. * if setup has not been made and a message type
  2756. * MT_STATUS is received with call state == 0,
  2757. * we must send nothing
  2758. */
  2759. if (callState != 0) {
  2760. /* ETS 300-104 part 2.4.2
  2761. * if setup has not been made and a message type
  2762. * MT_STATUS is received with call state != 0,
  2763. * we must send MT_RELEASE_COMPLETE cause 101
  2764. */
  2765. if ((proc = dss1_new_l3_process(st, cr))) {
  2766. proc->para.cause = 101;
  2767. l3dss1_msg_without_setup(proc, 0, NULL);
  2768. }
  2769. }
  2770. dev_kfree_skb(skb);
  2771. return;
  2772. } else if (mt == MT_RELEASE_COMPLETE) {
  2773. dev_kfree_skb(skb);
  2774. return;
  2775. } else {
  2776. /* ETS 300-104 part 2
  2777. * if setup has not been made and a message type
  2778. * (except MT_SETUP and RELEASE_COMPLETE) is received,
  2779. * we must send MT_RELEASE_COMPLETE cause 81 */
  2780. dev_kfree_skb(skb);
  2781. if ((proc = dss1_new_l3_process(st, cr))) {
  2782. proc->para.cause = 81;
  2783. l3dss1_msg_without_setup(proc, 0, NULL);
  2784. }
  2785. return;
  2786. }
  2787. }
  2788. if (l3dss1_check_messagetype_validity(proc, mt, skb)) {
  2789. dev_kfree_skb(skb);
  2790. return;
  2791. }
  2792. if ((p = findie(skb->data, skb->len, IE_DISPLAY, 0)) != NULL)
  2793. l3dss1_deliver_display(proc, pr, p); /* Display IE included */
  2794. for (i = 0; i < ARRAY_SIZE(datastatelist); i++)
  2795. if ((mt == datastatelist[i].primitive) &&
  2796. ((1 << proc->state) & datastatelist[i].state))
  2797. break;
  2798. if (i == ARRAY_SIZE(datastatelist)) {
  2799. if (st->l3.debug & L3_DEB_STATE) {
  2800. l3_debug(st, "dss1up%sstate %d mt %#x unhandled",
  2801. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2802. proc->state, mt);
  2803. }
  2804. if ((MT_RELEASE_COMPLETE != mt) && (MT_RELEASE != mt)) {
  2805. proc->para.cause = 101;
  2806. l3dss1_status_send(proc, pr, skb);
  2807. }
  2808. } else {
  2809. if (st->l3.debug & L3_DEB_STATE) {
  2810. l3_debug(st, "dss1up%sstate %d mt %x",
  2811. (pr == (DL_DATA | INDICATION)) ? " " : "(broadcast) ",
  2812. proc->state, mt);
  2813. }
  2814. datastatelist[i].rout(proc, pr, skb);
  2815. }
  2816. dev_kfree_skb(skb);
  2817. return;
  2818. }
  2819. static void
  2820. dss1down(struct PStack *st, int pr, void *arg)
  2821. {
  2822. int i, cr;
  2823. struct l3_process *proc;
  2824. struct Channel *chan;
  2825. if ((DL_ESTABLISH | REQUEST) == pr) {
  2826. l3_msg(st, pr, NULL);
  2827. return;
  2828. } else if (((CC_SETUP | REQUEST) == pr) || ((CC_RESUME | REQUEST) == pr)) {
  2829. chan = arg;
  2830. cr = newcallref();
  2831. cr |= 0x80;
  2832. if ((proc = dss1_new_l3_process(st, cr))) {
  2833. proc->chan = chan;
  2834. chan->proc = proc;
  2835. memcpy(&proc->para.setup, &chan->setup, sizeof(setup_parm));
  2836. proc->callref = cr;
  2837. }
  2838. } else {
  2839. proc = arg;
  2840. }
  2841. if (!proc) {
  2842. printk(KERN_ERR "HiSax dss1down without proc pr=%04x\n", pr);
  2843. return;
  2844. }
  2845. if (pr == (CC_TDSS1_IO | REQUEST)) {
  2846. l3dss1_io_timer(proc); /* timer expires */
  2847. return;
  2848. }
  2849. for (i = 0; i < ARRAY_SIZE(downstatelist); i++)
  2850. if ((pr == downstatelist[i].primitive) &&
  2851. ((1 << proc->state) & downstatelist[i].state))
  2852. break;
  2853. if (i == ARRAY_SIZE(downstatelist)) {
  2854. if (st->l3.debug & L3_DEB_STATE) {
  2855. l3_debug(st, "dss1down state %d prim %#x unhandled",
  2856. proc->state, pr);
  2857. }
  2858. } else {
  2859. if (st->l3.debug & L3_DEB_STATE) {
  2860. l3_debug(st, "dss1down state %d prim %#x",
  2861. proc->state, pr);
  2862. }
  2863. downstatelist[i].rout(proc, pr, arg);
  2864. }
  2865. }
  2866. static void
  2867. dss1man(struct PStack *st, int pr, void *arg)
  2868. {
  2869. int i;
  2870. struct l3_process *proc = arg;
  2871. if (!proc) {
  2872. printk(KERN_ERR "HiSax dss1man without proc pr=%04x\n", pr);
  2873. return;
  2874. }
  2875. for (i = 0; i < ARRAY_SIZE(manstatelist); i++)
  2876. if ((pr == manstatelist[i].primitive) &&
  2877. ((1 << proc->state) & manstatelist[i].state))
  2878. break;
  2879. if (i == ARRAY_SIZE(manstatelist)) {
  2880. if (st->l3.debug & L3_DEB_STATE) {
  2881. l3_debug(st, "cr %d dss1man state %d prim %#x unhandled",
  2882. proc->callref & 0x7f, proc->state, pr);
  2883. }
  2884. } else {
  2885. if (st->l3.debug & L3_DEB_STATE) {
  2886. l3_debug(st, "cr %d dss1man state %d prim %#x",
  2887. proc->callref & 0x7f, proc->state, pr);
  2888. }
  2889. manstatelist[i].rout(proc, pr, arg);
  2890. }
  2891. }
  2892. void
  2893. setstack_dss1(struct PStack *st)
  2894. {
  2895. char tmp[64];
  2896. int i;
  2897. st->lli.l4l3 = dss1down;
  2898. st->lli.l4l3_proto = l3dss1_cmd_global;
  2899. st->l2.l2l3 = dss1up;
  2900. st->l3.l3ml3 = dss1man;
  2901. st->l3.N303 = 1;
  2902. st->prot.dss1.last_invoke_id = 0;
  2903. st->prot.dss1.invoke_used[0] = 1; /* Bit 0 must always be set to 1 */
  2904. i = 1;
  2905. while (i < 32)
  2906. st->prot.dss1.invoke_used[i++] = 0;
  2907. if (!(st->l3.global = kmalloc(sizeof(struct l3_process), GFP_ATOMIC))) {
  2908. printk(KERN_ERR "HiSax can't get memory for dss1 global CR\n");
  2909. } else {
  2910. st->l3.global->state = 0;
  2911. st->l3.global->callref = 0;
  2912. st->l3.global->next = NULL;
  2913. st->l3.global->debug = L3_DEB_WARN;
  2914. st->l3.global->st = st;
  2915. st->l3.global->N303 = 1;
  2916. st->l3.global->prot.dss1.invoke_id = 0;
  2917. L3InitTimer(st->l3.global, &st->l3.global->timer);
  2918. }
  2919. strcpy(tmp, dss1_revision);
  2920. printk(KERN_INFO "HiSax: DSS1 Rev. %s\n", HiSax_getrev(tmp));
  2921. }