l3dss1.c 81 KB

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