l3ni1.c 79 KB

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